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