Committer:
apm_litoral
Date:
Tue Apr 10 03:33:49 2012 +0000
Revision:
0:ea1b1135bb4e

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
apm_litoral 0:ea1b1135bb4e 1 /* mbed GraphicsDisplay Display Library Base Class
apm_litoral 0:ea1b1135bb4e 2 * Copyright (c) 2007-2009 sford
apm_litoral 0:ea1b1135bb4e 3 * Released under the MIT License: http://mbed.org/license/mit
apm_litoral 0:ea1b1135bb4e 4 */
apm_litoral 0:ea1b1135bb4e 5
apm_litoral 0:ea1b1135bb4e 6 #include "GraphicsDisplay.h"
apm_litoral 0:ea1b1135bb4e 7
apm_litoral 0:ea1b1135bb4e 8 const unsigned char FONT8x8[97][8] = {
apm_litoral 0:ea1b1135bb4e 9 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char
apm_litoral 0:ea1b1135bb4e 10 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20
apm_litoral 0:ea1b1135bb4e 11 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // !
apm_litoral 0:ea1b1135bb4e 12 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // "
apm_litoral 0:ea1b1135bb4e 13 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // #
apm_litoral 0:ea1b1135bb4e 14 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $
apm_litoral 0:ea1b1135bb4e 15 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // %
apm_litoral 0:ea1b1135bb4e 16 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // &
apm_litoral 0:ea1b1135bb4e 17 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // '
apm_litoral 0:ea1b1135bb4e 18 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // (
apm_litoral 0:ea1b1135bb4e 19 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // )
apm_litoral 0:ea1b1135bb4e 20 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // *
apm_litoral 0:ea1b1135bb4e 21 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // +
apm_litoral 0:ea1b1135bb4e 22 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // ,
apm_litoral 0:ea1b1135bb4e 23 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // -
apm_litoral 0:ea1b1135bb4e 24 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // .
apm_litoral 0:ea1b1135bb4e 25 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash)
apm_litoral 0:ea1b1135bb4e 26 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30
apm_litoral 0:ea1b1135bb4e 27 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1
apm_litoral 0:ea1b1135bb4e 28 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2
apm_litoral 0:ea1b1135bb4e 29 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3
apm_litoral 0:ea1b1135bb4e 30 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4
apm_litoral 0:ea1b1135bb4e 31 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5
apm_litoral 0:ea1b1135bb4e 32 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6
apm_litoral 0:ea1b1135bb4e 33 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7
apm_litoral 0:ea1b1135bb4e 34 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8
apm_litoral 0:ea1b1135bb4e 35 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9
apm_litoral 0:ea1b1135bb4e 36 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // :
apm_litoral 0:ea1b1135bb4e 37 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ;
apm_litoral 0:ea1b1135bb4e 38 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // <
apm_litoral 0:ea1b1135bb4e 39 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // =
apm_litoral 0:ea1b1135bb4e 40 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // >
apm_litoral 0:ea1b1135bb4e 41 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ?
apm_litoral 0:ea1b1135bb4e 42 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40
apm_litoral 0:ea1b1135bb4e 43 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A
apm_litoral 0:ea1b1135bb4e 44 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B
apm_litoral 0:ea1b1135bb4e 45 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C
apm_litoral 0:ea1b1135bb4e 46 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D
apm_litoral 0:ea1b1135bb4e 47 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E
apm_litoral 0:ea1b1135bb4e 48 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F
apm_litoral 0:ea1b1135bb4e 49 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G
apm_litoral 0:ea1b1135bb4e 50 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H
apm_litoral 0:ea1b1135bb4e 51 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I
apm_litoral 0:ea1b1135bb4e 52 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J
apm_litoral 0:ea1b1135bb4e 53 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K
apm_litoral 0:ea1b1135bb4e 54 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L
apm_litoral 0:ea1b1135bb4e 55 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M
apm_litoral 0:ea1b1135bb4e 56 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N
apm_litoral 0:ea1b1135bb4e 57 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O
apm_litoral 0:ea1b1135bb4e 58 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50
apm_litoral 0:ea1b1135bb4e 59 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q
apm_litoral 0:ea1b1135bb4e 60 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R
apm_litoral 0:ea1b1135bb4e 61 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S
apm_litoral 0:ea1b1135bb4e 62 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T
apm_litoral 0:ea1b1135bb4e 63 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U
apm_litoral 0:ea1b1135bb4e 64 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V
apm_litoral 0:ea1b1135bb4e 65 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W
apm_litoral 0:ea1b1135bb4e 66 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X
apm_litoral 0:ea1b1135bb4e 67 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y
apm_litoral 0:ea1b1135bb4e 68 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z
apm_litoral 0:ea1b1135bb4e 69 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [
apm_litoral 0:ea1b1135bb4e 70 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash)
apm_litoral 0:ea1b1135bb4e 71 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ]
apm_litoral 0:ea1b1135bb4e 72 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^
apm_litoral 0:ea1b1135bb4e 73 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _
apm_litoral 0:ea1b1135bb4e 74 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60
apm_litoral 0:ea1b1135bb4e 75 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a
apm_litoral 0:ea1b1135bb4e 76 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b
apm_litoral 0:ea1b1135bb4e 77 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c
apm_litoral 0:ea1b1135bb4e 78 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d
apm_litoral 0:ea1b1135bb4e 79 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e
apm_litoral 0:ea1b1135bb4e 80 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f
apm_litoral 0:ea1b1135bb4e 81 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g
apm_litoral 0:ea1b1135bb4e 82 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h
apm_litoral 0:ea1b1135bb4e 83 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i
apm_litoral 0:ea1b1135bb4e 84 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j
apm_litoral 0:ea1b1135bb4e 85 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k
apm_litoral 0:ea1b1135bb4e 86 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l
apm_litoral 0:ea1b1135bb4e 87 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m
apm_litoral 0:ea1b1135bb4e 88 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n
apm_litoral 0:ea1b1135bb4e 89 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o
apm_litoral 0:ea1b1135bb4e 90 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p
apm_litoral 0:ea1b1135bb4e 91 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q
apm_litoral 0:ea1b1135bb4e 92 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r
apm_litoral 0:ea1b1135bb4e 93 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s
apm_litoral 0:ea1b1135bb4e 94 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t
apm_litoral 0:ea1b1135bb4e 95 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u
apm_litoral 0:ea1b1135bb4e 96 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v
apm_litoral 0:ea1b1135bb4e 97 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w
apm_litoral 0:ea1b1135bb4e 98 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x
apm_litoral 0:ea1b1135bb4e 99 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y
apm_litoral 0:ea1b1135bb4e 100 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z
apm_litoral 0:ea1b1135bb4e 101 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // {
apm_litoral 0:ea1b1135bb4e 102 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // |
apm_litoral 0:ea1b1135bb4e 103 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // }
apm_litoral 0:ea1b1135bb4e 104 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~
apm_litoral 0:ea1b1135bb4e 105 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL
apm_litoral 0:ea1b1135bb4e 106
apm_litoral 0:ea1b1135bb4e 107 GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) {
apm_litoral 0:ea1b1135bb4e 108 foreground(0xFFFF);
apm_litoral 0:ea1b1135bb4e 109 background(0x0000);
apm_litoral 0:ea1b1135bb4e 110 }
apm_litoral 0:ea1b1135bb4e 111
apm_litoral 0:ea1b1135bb4e 112 void GraphicsDisplay::character(int column, int row, int value) {
apm_litoral 0:ea1b1135bb4e 113 blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
apm_litoral 0:ea1b1135bb4e 114 }
apm_litoral 0:ea1b1135bb4e 115
apm_litoral 0:ea1b1135bb4e 116 void GraphicsDisplay::window(int x, int y, int w, int h) {
apm_litoral 0:ea1b1135bb4e 117 // current pixel location
apm_litoral 0:ea1b1135bb4e 118 _x = x;
apm_litoral 0:ea1b1135bb4e 119 _y = y;
apm_litoral 0:ea1b1135bb4e 120 // window settings
apm_litoral 0:ea1b1135bb4e 121 _x1 = x;
apm_litoral 0:ea1b1135bb4e 122 _x2 = x + w - 1;
apm_litoral 0:ea1b1135bb4e 123 _y1 = y;
apm_litoral 0:ea1b1135bb4e 124 _y2 = y + h - 1;
apm_litoral 0:ea1b1135bb4e 125 }
apm_litoral 0:ea1b1135bb4e 126
apm_litoral 0:ea1b1135bb4e 127 void GraphicsDisplay::putp(int colour) {
apm_litoral 0:ea1b1135bb4e 128 // put pixel at current pixel location
apm_litoral 0:ea1b1135bb4e 129 pixel(_x, _y, colour);
apm_litoral 0:ea1b1135bb4e 130 // update pixel location based on window settings
apm_litoral 0:ea1b1135bb4e 131 _x++;
apm_litoral 0:ea1b1135bb4e 132 if(_x > _x2) {
apm_litoral 0:ea1b1135bb4e 133 _x = _x1;
apm_litoral 0:ea1b1135bb4e 134 _y++;
apm_litoral 0:ea1b1135bb4e 135 if(_y > _y2) {
apm_litoral 0:ea1b1135bb4e 136 _y = _y1;
apm_litoral 0:ea1b1135bb4e 137 }
apm_litoral 0:ea1b1135bb4e 138 }
apm_litoral 0:ea1b1135bb4e 139 }
apm_litoral 0:ea1b1135bb4e 140
apm_litoral 0:ea1b1135bb4e 141 void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) {
apm_litoral 0:ea1b1135bb4e 142 window(x, y, w, h);
apm_litoral 0:ea1b1135bb4e 143 for(int i=0; i<w*h; i++) {
apm_litoral 0:ea1b1135bb4e 144 putp(colour);
apm_litoral 0:ea1b1135bb4e 145 }
apm_litoral 0:ea1b1135bb4e 146 }
apm_litoral 0:ea1b1135bb4e 147
apm_litoral 0:ea1b1135bb4e 148 void GraphicsDisplay::cls() {
apm_litoral 0:ea1b1135bb4e 149 fill(0, 0, width(), height(), _background);
apm_litoral 0:ea1b1135bb4e 150 }
apm_litoral 0:ea1b1135bb4e 151
apm_litoral 0:ea1b1135bb4e 152 void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) {
apm_litoral 0:ea1b1135bb4e 153 window(x, y, w, h);
apm_litoral 0:ea1b1135bb4e 154 for(int i=0; i<w*h; i++) {
apm_litoral 0:ea1b1135bb4e 155 putp(colour[i]);
apm_litoral 0:ea1b1135bb4e 156 }
apm_litoral 0:ea1b1135bb4e 157 }
apm_litoral 0:ea1b1135bb4e 158
apm_litoral 0:ea1b1135bb4e 159 void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
apm_litoral 0:ea1b1135bb4e 160 window(x, y, w, h);
apm_litoral 0:ea1b1135bb4e 161 for(int i = 0; i < w*h; i++) {
apm_litoral 0:ea1b1135bb4e 162 char byte = colour[i >> 3];
apm_litoral 0:ea1b1135bb4e 163 int offset = i & 0x7;
apm_litoral 0:ea1b1135bb4e 164 int c = ((byte << offset) & 0x80) ? _foreground : _background;
apm_litoral 0:ea1b1135bb4e 165 putp(c);
apm_litoral 0:ea1b1135bb4e 166 }
apm_litoral 0:ea1b1135bb4e 167 }
apm_litoral 0:ea1b1135bb4e 168
apm_litoral 0:ea1b1135bb4e 169 int GraphicsDisplay::columns() {
apm_litoral 0:ea1b1135bb4e 170 return width() / 8;
apm_litoral 0:ea1b1135bb4e 171 }
apm_litoral 0:ea1b1135bb4e 172
apm_litoral 0:ea1b1135bb4e 173 int GraphicsDisplay::rows() {
apm_litoral 0:ea1b1135bb4e 174 return height() / 8;
apm_litoral 0:ea1b1135bb4e 175 }
apm_litoral 0:ea1b1135bb4e 176