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