gameboy printer
Fork of HelloWorld by
main.cpp@8:82f64c4b9904, 2017-12-22 (annotated)
- Committer:
- spinal
- Date:
- Fri Dec 22 20:42:41 2017 +0000
- Revision:
- 8:82f64c4b9904
- Parent:
- 5:c4a0391b43ac
- Child:
- 9:f5dbcf0d30ba
bgprinter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
spinal | 8:82f64c4b9904 | 1 | // this might be better... |
spinal | 8:82f64c4b9904 | 2 | // https://github.com/davedarko/GBPrinter |
spinal | 8:82f64c4b9904 | 3 | // https://github.com/davedarko/GBPrinter/blob/master/examples/GBPrinter/GBPrinter.ino |
spinal | 8:82f64c4b9904 | 4 | |
Pokitto | 0:2d2a3994d55d | 5 | #include "Pokitto.h" |
spinal | 8:82f64c4b9904 | 6 | Pokitto::Core mygame; |
spinal | 8:82f64c4b9904 | 7 | |
spinal | 8:82f64c4b9904 | 8 | uint8_t hadl[640] = { |
spinal | 8:82f64c4b9904 | 9 | 0xEF, 0xFF, 0xF7, 0xF7, 0xE7, 0xB7, 0xC3, 0xC3, 0xF1, 0xE1, 0xFA, 0xFA, 0xFC, 0xFC, 0xFC, 0xFC, 0xFE, 0xFF, 0xFD, 0xFD, 0xFC, 0xFC, 0xF8, 0xF8, 0xF1, 0xB0, 0x0B, 0x0B, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xBF, 0xBF, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7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1, 0xC8, 0xC8, 0x08, 0x08, 0x9F, 0x9F, 0xDF, 0xDF, 0xBF, 0xBF, 0xDF, 0xFF, 0x5F, 0x5F, 0x1F, 0x1F, 0x27, 0x27, 0xA1, 0xA1, 0xF2, 0xF2, 0xF7, 0xF7, 0xFB, 0xFB, |
spinal | 8:82f64c4b9904 | 10 | }; |
spinal | 8:82f64c4b9904 | 11 | |
spinal | 8:82f64c4b9904 | 12 | char respond[] = {0, 0}; //The 2 byte response we always get |
spinal | 8:82f64c4b9904 | 13 | |
spinal | 8:82f64c4b9904 | 14 | DigitalInOut datClk(P0_11); |
spinal | 8:82f64c4b9904 | 15 | DigitalInOut datIn(P0_17); |
spinal | 8:82f64c4b9904 | 16 | DigitalInOut datOut(P0_13); |
spinal | 8:82f64c4b9904 | 17 | |
spinal | 8:82f64c4b9904 | 18 | unsigned short checksum = 0; |
spinal | 8:82f64c4b9904 | 19 | int whichChar = 0; |
spinal | 8:82f64c4b9904 | 20 | |
spinal | 8:82f64c4b9904 | 21 | void sendByte(unsigned char byteToSend) { |
Pokitto | 0:2d2a3994d55d | 22 | |
spinal | 8:82f64c4b9904 | 23 | checksum += byteToSend; //Always build this, even if not used |
spinal | 8:82f64c4b9904 | 24 | for (int x = 0 ; x < 8 ; x++) { |
spinal | 8:82f64c4b9904 | 25 | if (byteToSend & B10000000) { |
spinal | 8:82f64c4b9904 | 26 | datOut = 1; // data high |
spinal | 8:82f64c4b9904 | 27 | } else { |
spinal | 8:82f64c4b9904 | 28 | datOut = 0; // data low |
spinal | 8:82f64c4b9904 | 29 | } |
spinal | 8:82f64c4b9904 | 30 | datClk = 0; // clock low |
spinal | 8:82f64c4b9904 | 31 | wait_us(55); |
spinal | 8:82f64c4b9904 | 32 | datClk = 1; // clock high |
spinal | 8:82f64c4b9904 | 33 | byteToSend <<= 1; |
spinal | 8:82f64c4b9904 | 34 | wait_us(55); |
spinal | 8:82f64c4b9904 | 35 | } |
spinal | 8:82f64c4b9904 | 36 | datOut = 0; // test... |
spinal | 8:82f64c4b9904 | 37 | wait_us(200); |
spinal | 8:82f64c4b9904 | 38 | } |
spinal | 8:82f64c4b9904 | 39 | |
spinal | 8:82f64c4b9904 | 40 | |
spinal | 8:82f64c4b9904 | 41 | void getResponse() { |
spinal | 8:82f64c4b9904 | 42 | respond[0] = 0; |
spinal | 8:82f64c4b9904 | 43 | respond[1] = 0; |
spinal | 8:82f64c4b9904 | 44 | |
spinal | 8:82f64c4b9904 | 45 | for (int xx = 0 ; xx < 2 ; xx++) { |
spinal | 8:82f64c4b9904 | 46 | for (int x = 0 ; x < 8 ; x++) { |
spinal | 8:82f64c4b9904 | 47 | respond[xx] <<= 1; //Shift to the left making room for next bit. DO this first so we don't lose the last one |
spinal | 8:82f64c4b9904 | 48 | datClk = 0; |
spinal | 8:82f64c4b9904 | 49 | wait_us(25); |
spinal | 8:82f64c4b9904 | 50 | if(datIn){ |
spinal | 8:82f64c4b9904 | 51 | respond[xx] |= 1; //Set it |
spinal | 8:82f64c4b9904 | 52 | } |
spinal | 8:82f64c4b9904 | 53 | wait_us(25); |
spinal | 8:82f64c4b9904 | 54 | datClk = 1; |
spinal | 8:82f64c4b9904 | 55 | wait_us(55); |
spinal | 8:82f64c4b9904 | 56 | } |
spinal | 8:82f64c4b9904 | 57 | wait_us(200); |
spinal | 8:82f64c4b9904 | 58 | } |
spinal | 8:82f64c4b9904 | 59 | } |
spinal | 8:82f64c4b9904 | 60 | |
spinal | 8:82f64c4b9904 | 61 | void sendChecksum() { |
spinal | 8:82f64c4b9904 | 62 | unsigned short lineChecksum = checksum; //Grab the state of checksum so we don't change it while sending |
spinal | 8:82f64c4b9904 | 63 | sendByte(lineChecksum & 0xFF); //Send checksum low byte |
spinal | 8:82f64c4b9904 | 64 | sendByte(lineChecksum >> 8); //Send checksum high byte |
spinal | 8:82f64c4b9904 | 65 | getResponse(); |
spinal | 8:82f64c4b9904 | 66 | } |
spinal | 8:82f64c4b9904 | 67 | |
Pokitto | 0:2d2a3994d55d | 68 | |
Pokitto | 0:2d2a3994d55d | 69 | int main () { |
Pokitto | 0:2d2a3994d55d | 70 | mygame.begin(); |
spinal | 8:82f64c4b9904 | 71 | |
spinal | 8:82f64c4b9904 | 72 | datClk.output(); // clock to output |
spinal | 8:82f64c4b9904 | 73 | datOut.output(); // data out to output |
spinal | 8:82f64c4b9904 | 74 | datIn.input(); // data In to input |
spinal | 8:82f64c4b9904 | 75 | datIn.mode(PullUp); |
spinal | 8:82f64c4b9904 | 76 | |
spinal | 8:82f64c4b9904 | 77 | datClk = 1; // start clock line high |
spinal | 8:82f64c4b9904 | 78 | datOut = 0; // start data low |
spinal | 8:82f64c4b9904 | 79 | |
spinal | 8:82f64c4b9904 | 80 | |
spinal | 8:82f64c4b9904 | 81 | //wait(5); // hang on a little |
spinal | 8:82f64c4b9904 | 82 | |
spinal | 8:82f64c4b9904 | 83 | //printShape(1); // test! |
spinal | 8:82f64c4b9904 | 84 | |
spinal | 8:82f64c4b9904 | 85 | mygame.display.persistence = 1; |
spinal | 8:82f64c4b9904 | 86 | mygame.display.clear(); |
spinal | 8:82f64c4b9904 | 87 | mygame.display.print("Printer Test\n"); |
spinal | 8:82f64c4b9904 | 88 | |
Pokitto | 0:2d2a3994d55d | 89 | while (mygame.isRunning()) { |
Pokitto | 0:2d2a3994d55d | 90 | if (mygame.update()) { |
spinal | 8:82f64c4b9904 | 91 | if (mygame.buttons.aBtn()){ |
spinal | 8:82f64c4b9904 | 92 | mygame.display.print("Sending init code\n"); |
spinal | 8:82f64c4b9904 | 93 | mygame.display.update(); |
spinal | 8:82f64c4b9904 | 94 | |
spinal | 8:82f64c4b9904 | 95 | sendByte(0x88); // magic |
spinal | 8:82f64c4b9904 | 96 | sendByte(0x33); // magic |
spinal | 8:82f64c4b9904 | 97 | checksum = 0; |
spinal | 8:82f64c4b9904 | 98 | sendByte(0x01); // 1 = init printer |
spinal | 8:82f64c4b9904 | 99 | sendByte(0x00); // compression, 0 = none, 1 = RLE |
spinal | 8:82f64c4b9904 | 100 | sendByte(0x00); // data length |
spinal | 8:82f64c4b9904 | 101 | sendByte(0x00); // data length 2nd byte |
spinal | 8:82f64c4b9904 | 102 | int temp = checksum; |
spinal | 8:82f64c4b9904 | 103 | sendByte(temp & 0xFF); // checksum 2nd byte |
spinal | 8:82f64c4b9904 | 104 | sendByte(temp >> 8); // checksum |
spinal | 8:82f64c4b9904 | 105 | getResponse(); |
spinal | 8:82f64c4b9904 | 106 | |
spinal | 8:82f64c4b9904 | 107 | mygame.display.print("Done\n"); |
spinal | 8:82f64c4b9904 | 108 | |
spinal | 8:82f64c4b9904 | 109 | char tempText[20]; |
spinal | 8:82f64c4b9904 | 110 | sprintf(tempText,"Response = %#04x, %#04x\n", respond[0], respond[1]); |
spinal | 8:82f64c4b9904 | 111 | mygame.display.print(tempText); |
spinal | 8:82f64c4b9904 | 112 | |
spinal | 8:82f64c4b9904 | 113 | if(respond[0]==0x81 && respond[1]==0x00){ |
spinal | 8:82f64c4b9904 | 114 | mygame.display.print("OK, Proceed\n"); |
spinal | 8:82f64c4b9904 | 115 | mygame.display.update(); |
spinal | 8:82f64c4b9904 | 116 | |
spinal | 8:82f64c4b9904 | 117 | // send test data |
spinal | 8:82f64c4b9904 | 118 | sendByte(0x88); // magic |
spinal | 8:82f64c4b9904 | 119 | sendByte(0x33); // magic |
spinal | 8:82f64c4b9904 | 120 | checksum = 0; |
spinal | 8:82f64c4b9904 | 121 | sendByte(0x04); // 4 = Send some print data |
spinal | 8:82f64c4b9904 | 122 | sendByte(0x00); // compression, 0 = none, 1 = RLE |
spinal | 8:82f64c4b9904 | 123 | // send 0x280 which is 640, the maximum data allowed at a time |
spinal | 8:82f64c4b9904 | 124 | sendByte(0x80); // data length |
spinal | 8:82f64c4b9904 | 125 | sendByte(0x02); // data length 2nd byte |
spinal | 8:82f64c4b9904 | 126 | for(int t=0; t<640; t++){ |
spinal | 8:82f64c4b9904 | 127 | sendByte(hadl[t]); // test data |
spinal | 8:82f64c4b9904 | 128 | } |
spinal | 8:82f64c4b9904 | 129 | temp = checksum; |
spinal | 8:82f64c4b9904 | 130 | sendByte(temp & 0xFF); // checksum 2nd byte |
spinal | 8:82f64c4b9904 | 131 | sendByte(temp >> 8); // checksum |
spinal | 8:82f64c4b9904 | 132 | getResponse(); |
spinal | 8:82f64c4b9904 | 133 | |
spinal | 8:82f64c4b9904 | 134 | sprintf(tempText,"Response = %#04x, %#04x\n", respond[0], respond[1]); |
spinal | 8:82f64c4b9904 | 135 | mygame.display.print(tempText); |
spinal | 8:82f64c4b9904 | 136 | mygame.display.update(); |
spinal | 8:82f64c4b9904 | 137 | |
spinal | 8:82f64c4b9904 | 138 | // end data statement |
spinal | 8:82f64c4b9904 | 139 | sendByte(0x88); // magic |
spinal | 8:82f64c4b9904 | 140 | sendByte(0x33); // magic |
spinal | 8:82f64c4b9904 | 141 | checksum = 0; |
spinal | 8:82f64c4b9904 | 142 | sendByte(0x04); // |
spinal | 8:82f64c4b9904 | 143 | sendByte(0x00); // |
spinal | 8:82f64c4b9904 | 144 | sendByte(0x00); // |
spinal | 8:82f64c4b9904 | 145 | sendByte(0x00); // |
spinal | 8:82f64c4b9904 | 146 | temp = checksum; |
spinal | 8:82f64c4b9904 | 147 | sendByte(temp & 0xFF); // checksum 2nd byte |
spinal | 8:82f64c4b9904 | 148 | sendByte(temp >> 8); // checksum |
spinal | 8:82f64c4b9904 | 149 | getResponse(); |
spinal | 8:82f64c4b9904 | 150 | |
spinal | 8:82f64c4b9904 | 151 | sprintf(tempText,"Response = %#04x, %#04x\n", respond[0], respond[1]); |
spinal | 8:82f64c4b9904 | 152 | mygame.display.print(tempText); |
spinal | 8:82f64c4b9904 | 153 | mygame.display.update(); |
spinal | 8:82f64c4b9904 | 154 | |
spinal | 8:82f64c4b9904 | 155 | sendByte(0x88); // Magic bytes |
spinal | 8:82f64c4b9904 | 156 | sendByte(0x33); |
spinal | 8:82f64c4b9904 | 157 | checksum = 0; |
spinal | 8:82f64c4b9904 | 158 | sendByte(0x02); // Commande 2 (Print) |
spinal | 8:82f64c4b9904 | 159 | sendByte(0x00); |
spinal | 8:82f64c4b9904 | 160 | sendByte(0x04); // 4 bytes to send |
spinal | 8:82f64c4b9904 | 161 | sendByte(0x00); |
spinal | 8:82f64c4b9904 | 162 | sendByte(0x01); // 1 = print, 0 = line feed |
spinal | 8:82f64c4b9904 | 163 | sendByte(0x13); // Marges (nibbles avant 1, après 3) |
spinal | 8:82f64c4b9904 | 164 | sendByte(0xE4); // Palette (11100100: Noir, Foncé, Clair, Blanc) |
spinal | 8:82f64c4b9904 | 165 | sendByte(0x40); // Expo (7 bits) |
spinal | 8:82f64c4b9904 | 166 | |
spinal | 8:82f64c4b9904 | 167 | temp = checksum; |
spinal | 8:82f64c4b9904 | 168 | sendByte(temp & 0xFF); // checksum 2nd byte |
spinal | 8:82f64c4b9904 | 169 | sendByte(temp >> 8); // checksum |
spinal | 8:82f64c4b9904 | 170 | getResponse(); |
spinal | 8:82f64c4b9904 | 171 | |
spinal | 8:82f64c4b9904 | 172 | sprintf(tempText,"Response = %#04x, %#04x\n", respond[0], respond[1]); |
spinal | 8:82f64c4b9904 | 173 | mygame.display.print(tempText); |
spinal | 8:82f64c4b9904 | 174 | mygame.display.update(); |
spinal | 8:82f64c4b9904 | 175 | |
spinal | 8:82f64c4b9904 | 176 | bool waiting=1; |
spinal | 8:82f64c4b9904 | 177 | while(waiting){ |
spinal | 8:82f64c4b9904 | 178 | sendByte(0x88); // magic |
spinal | 8:82f64c4b9904 | 179 | sendByte(0x33); // magic |
spinal | 8:82f64c4b9904 | 180 | checksum = 0; |
spinal | 8:82f64c4b9904 | 181 | sendByte(0x0F); // |
spinal | 8:82f64c4b9904 | 182 | sendByte(0x00); // |
spinal | 8:82f64c4b9904 | 183 | sendByte(0x00); // |
spinal | 8:82f64c4b9904 | 184 | sendByte(0x00); // |
spinal | 8:82f64c4b9904 | 185 | temp = checksum; |
spinal | 8:82f64c4b9904 | 186 | sendByte(temp & 0xFF); // checksum 2nd byte |
spinal | 8:82f64c4b9904 | 187 | sendByte(temp >> 8); // checksum |
spinal | 8:82f64c4b9904 | 188 | getResponse(); |
spinal | 8:82f64c4b9904 | 189 | |
spinal | 8:82f64c4b9904 | 190 | sprintf(tempText,"Response = %#04x, %#04x\n", respond[0], respond[1]); |
spinal | 8:82f64c4b9904 | 191 | mygame.display.print(tempText); |
spinal | 8:82f64c4b9904 | 192 | mygame.display.update(); |
spinal | 8:82f64c4b9904 | 193 | if(respond[1] & 2)waiting=0; |
spinal | 8:82f64c4b9904 | 194 | } |
spinal | 8:82f64c4b9904 | 195 | |
spinal | 8:82f64c4b9904 | 196 | waiting=1; |
spinal | 8:82f64c4b9904 | 197 | while(waiting){ |
spinal | 8:82f64c4b9904 | 198 | sendByte(0x88); // magic |
spinal | 8:82f64c4b9904 | 199 | sendByte(0x33); // magic |
spinal | 8:82f64c4b9904 | 200 | checksum = 0; |
spinal | 8:82f64c4b9904 | 201 | sendByte(0x0F); // |
spinal | 8:82f64c4b9904 | 202 | sendByte(0x00); // |
spinal | 8:82f64c4b9904 | 203 | sendByte(0x00); // |
spinal | 8:82f64c4b9904 | 204 | sendByte(0x00); // |
spinal | 8:82f64c4b9904 | 205 | temp = checksum; |
spinal | 8:82f64c4b9904 | 206 | sendByte(temp & 0xFF); // checksum 2nd byte |
spinal | 8:82f64c4b9904 | 207 | sendByte(temp >> 8); // checksum |
spinal | 8:82f64c4b9904 | 208 | getResponse(); |
spinal | 8:82f64c4b9904 | 209 | |
spinal | 8:82f64c4b9904 | 210 | sprintf(tempText,"Response = %#04x, %#04x\n", respond[0], respond[1]); |
spinal | 8:82f64c4b9904 | 211 | mygame.display.print(tempText); |
spinal | 8:82f64c4b9904 | 212 | mygame.display.update(); |
spinal | 8:82f64c4b9904 | 213 | if(!(respond[1] & 2))waiting=0; |
spinal | 8:82f64c4b9904 | 214 | } |
spinal | 8:82f64c4b9904 | 215 | |
spinal | 8:82f64c4b9904 | 216 | |
spinal | 8:82f64c4b9904 | 217 | }else{ |
spinal | 8:82f64c4b9904 | 218 | // show error log here |
spinal | 8:82f64c4b9904 | 219 | if(respond[0] != 0x81){ |
spinal | 8:82f64c4b9904 | 220 | mygame.display.print("Not Printer\n"); |
spinal | 8:82f64c4b9904 | 221 | }else{ |
spinal | 8:82f64c4b9904 | 222 | mygame.display.print("Printer Error\n"); |
spinal | 8:82f64c4b9904 | 223 | } |
spinal | 8:82f64c4b9904 | 224 | } |
spinal | 8:82f64c4b9904 | 225 | mygame.display.update(); |
spinal | 8:82f64c4b9904 | 226 | |
spinal | 8:82f64c4b9904 | 227 | wait(1); |
spinal | 8:82f64c4b9904 | 228 | } |
spinal | 8:82f64c4b9904 | 229 | } |
spinal | 8:82f64c4b9904 | 230 | } |
Pokitto | 0:2d2a3994d55d | 231 | |
Pokitto | 0:2d2a3994d55d | 232 | } |