Kazuki Yamamoto
/
LCDRAM
yet another AkiSpiLcd library example
Fork of LCDRAM by
main.cpp@1:72320e85a5e2, 2015-01-12 (annotated)
- Committer:
- k4zuki
- Date:
- Mon Jan 12 12:06:38 2015 +0000
- Revision:
- 1:72320e85a5e2
- Parent:
- 0:e705efefad3f
first commit; mov ing cube, moving ascii characters, movin invaders
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
m_wakayama | 0:e705efefad3f | 1 | |
m_wakayama | 0:e705efefad3f | 2 | #include "mbed.h" |
m_wakayama | 0:e705efefad3f | 3 | #include "AkiSpiLcd.h" |
m_wakayama | 0:e705efefad3f | 4 | |
m_wakayama | 0:e705efefad3f | 5 | //AkiSpiLcd LCD(MISO, MOSI, SCK, CSL, CSR); |
k4zuki | 1:72320e85a5e2 | 6 | //AkiSpiLcd LCDRAM(p11, p12, p13, p9, p10); |
k4zuki | 1:72320e85a5e2 | 7 | AkiSpiLcd LCDRAM(p5, p6, p7, p9, p10); |
k4zuki | 1:72320e85a5e2 | 8 | uint8_t lineBuffer[RAMLINE_LENGTH]; |
m_wakayama | 0:e705efefad3f | 9 | |
m_wakayama | 0:e705efefad3f | 10 | // SYSTEM -------------------------------------------------- |
m_wakayama | 0:e705efefad3f | 11 | uint8_t mainCounter; |
m_wakayama | 0:e705efefad3f | 12 | // GAME ---------------------------------------------------- |
k4zuki | 1:72320e85a5e2 | 13 | int scrollX=2,scrollY; |
m_wakayama | 0:e705efefad3f | 14 | // BOX ----------------------------------------------------- |
m_wakayama | 0:e705efefad3f | 15 | int8_t boxPosi[8][3] = { |
m_wakayama | 0:e705efefad3f | 16 | {-78,-78,-78},{-78,+78,-78},{-78,+78,+78},{-78,-78,+78}, |
m_wakayama | 0:e705efefad3f | 17 | {+78,-78,-78},{+78,+78,-78},{+78,+78,+78},{+78,-78,+78} |
m_wakayama | 0:e705efefad3f | 18 | }; |
m_wakayama | 0:e705efefad3f | 19 | uint8_t boxLink[12][2] = { |
m_wakayama | 0:e705efefad3f | 20 | {0,1},{1,2},{2,3},{3,0}, |
m_wakayama | 0:e705efefad3f | 21 | {4,5},{5,6},{6,7},{7,4}, |
m_wakayama | 0:e705efefad3f | 22 | {0,4},{1,5},{2,6},{3,7} |
m_wakayama | 0:e705efefad3f | 23 | }; |
m_wakayama | 0:e705efefad3f | 24 | int boxOffsetX; |
m_wakayama | 0:e705efefad3f | 25 | int boxOffsetY; |
m_wakayama | 0:e705efefad3f | 26 | int boxAngleX; |
m_wakayama | 0:e705efefad3f | 27 | int boxAngleZ; |
m_wakayama | 0:e705efefad3f | 28 | float buff3D[8][3]; |
m_wakayama | 0:e705efefad3f | 29 | |
m_wakayama | 0:e705efefad3f | 30 | // ASCII --------------------------------- |
m_wakayama | 0:e705efefad3f | 31 | int8_t asciiPosi[9][2] = { |
k4zuki | 1:72320e85a5e2 | 32 | {-6,-7},{ 0,-7},{+6,-7}, |
k4zuki | 1:72320e85a5e2 | 33 | {-6, 0},{ 0, 0},{+6, 0}, |
k4zuki | 1:72320e85a5e2 | 34 | {-6,+11},{ 0,+11},{+6,+11} |
k4zuki | 1:72320e85a5e2 | 35 | /* |
m_wakayama | 0:e705efefad3f | 36 | {-6,-9},{ 0,-9},{+6,-9}, |
m_wakayama | 0:e705efefad3f | 37 | {-6, 0},{ 0, 0},{+6, 0}, |
m_wakayama | 0:e705efefad3f | 38 | {-6,+9},{ 0,+9},{+6,+9} |
k4zuki | 1:72320e85a5e2 | 39 | */ |
m_wakayama | 0:e705efefad3f | 40 | }; |
m_wakayama | 0:e705efefad3f | 41 | uint8_t asciiLink[10 + 26][6][2] = { |
m_wakayama | 0:e705efefad3f | 42 | {{0,2},{2,8},{8,6},{6,0},{0,0},{0,0}}, // 0 |
m_wakayama | 0:e705efefad3f | 43 | {{1,7},{1,7},{0,0},{0,0},{0,0},{0,0}}, // 1 |
m_wakayama | 0:e705efefad3f | 44 | {{0,2},{2,5},{3,5},{3,6},{6,8},{0,0}}, // 2 |
m_wakayama | 0:e705efefad3f | 45 | {{0,2},{3,5},{6,8},{2,8},{0,0},{0,0}}, // 3 |
m_wakayama | 0:e705efefad3f | 46 | {{0,3},{3,5},{2,8},{0,0},{0,0},{0,0}}, // 4 |
m_wakayama | 0:e705efefad3f | 47 | {{0,2},{0,3},{3,5},{5,8},{6,8},{0,0}}, // 5 |
m_wakayama | 0:e705efefad3f | 48 | {{0,2},{0,6},{3,5},{5,8},{6,8},{0,0}}, // 6 |
m_wakayama | 0:e705efefad3f | 49 | {{0,2},{2,7},{0,0},{0,0},{0,0},{0,0}}, // 7 |
m_wakayama | 0:e705efefad3f | 50 | {{0,2},{0,6},{2,8},{3,5},{6,8},{0,0}}, // 8 |
m_wakayama | 0:e705efefad3f | 51 | {{0,2},{0,3},{3,5},{2,5},{5,7},{0,0}}, // 9 |
m_wakayama | 0:e705efefad3f | 52 | {{1,3},{3,6},{1,5},{5,8},{0,0},{0,0}}, // A |
m_wakayama | 0:e705efefad3f | 53 | {{0,2},{2,3},{3,8},{6,8},{0,6},{0,0}}, // B |
m_wakayama | 0:e705efefad3f | 54 | {{0,2},{0,6},{6,8},{0,0},{0,0},{0,0}}, // C |
m_wakayama | 0:e705efefad3f | 55 | {{0,5},{6,5},{0,6},{0,0},{0,0},{0,0}}, // D |
m_wakayama | 0:e705efefad3f | 56 | {{0,2},{0,6},{3,5},{6,8},{0,0},{0,0}}, // E |
m_wakayama | 0:e705efefad3f | 57 | {{0,2},{0,6},{3,5},{0,0},{0,0},{0,0}}, // F |
m_wakayama | 0:e705efefad3f | 58 | {{0,2},{0,6},{6,8},{5,8},{4,5},{0,0}}, // G |
m_wakayama | 0:e705efefad3f | 59 | {{0,6},{3,5},{2,8},{0,0},{0,0},{0,0}}, // H |
m_wakayama | 0:e705efefad3f | 60 | {{1,7},{0,0},{0,0},{0,0},{0,0},{0,0}}, // I |
m_wakayama | 0:e705efefad3f | 61 | {{2,8},{6,8},{3,6},{0,0},{0,0},{0,0}}, // J |
m_wakayama | 0:e705efefad3f | 62 | {{0,6},{2,3},{3,8},{0,0},{0,0},{0,0}}, // K |
m_wakayama | 0:e705efefad3f | 63 | {{0,6},{6,8},{0,0},{0,0},{0,0},{0,0}}, // L |
m_wakayama | 0:e705efefad3f | 64 | {{0,6},{0,4},{2,4},{2,8},{0,0},{0,0}}, // M |
m_wakayama | 0:e705efefad3f | 65 | {{0,6},{0,8},{2,8},{0,0},{0,0},{0,0}}, // N |
m_wakayama | 0:e705efefad3f | 66 | {{0,6},{0,2},{2,8},{6,8},{0,0},{0,0}}, // O |
m_wakayama | 0:e705efefad3f | 67 | {{0,2},{2,5},{3,5},{0,6},{0,0},{0,0}}, // P |
m_wakayama | 0:e705efefad3f | 68 | {{0,2},{0,6},{2,5},{5,7},{6,7},{4,8}}, // Q |
m_wakayama | 0:e705efefad3f | 69 | {{0,2},{2,5},{3,5},{0,6},{3,8},{0,0}}, // R |
m_wakayama | 0:e705efefad3f | 70 | {{0,2},{0,3},{3,5},{5,8},{6,8},{0,0}}, // S |
m_wakayama | 0:e705efefad3f | 71 | {{0,2},{1,7},{0,0},{0,0},{0,0},{0,0}}, // T |
m_wakayama | 0:e705efefad3f | 72 | {{0,6},{6,8},{2,8},{0,0},{0,0},{0,0}}, // U |
m_wakayama | 0:e705efefad3f | 73 | {{0,7},{2,7},{0,0},{0,0},{0,0},{0,0}}, // V |
m_wakayama | 0:e705efefad3f | 74 | {{0,6},{4,6},{4,8},{2,8},{0,0},{0,0}}, // W |
m_wakayama | 0:e705efefad3f | 75 | {{0,8},{2,6},{0,0},{0,0},{0,0},{0,0}}, // X |
m_wakayama | 0:e705efefad3f | 76 | {{0,4},{2,4},{4,7},{0,0},{0,0},{0,0}}, // Y |
m_wakayama | 0:e705efefad3f | 77 | {{0,2},{2,6},{6,8},{0,0},{0,0},{0,0}}, // Z |
m_wakayama | 0:e705efefad3f | 78 | }; |
m_wakayama | 0:e705efefad3f | 79 | int buff2D[9][2]; |
m_wakayama | 0:e705efefad3f | 80 | int asciiAngle; |
m_wakayama | 0:e705efefad3f | 81 | |
k4zuki | 1:72320e85a5e2 | 82 | /* |
k4zuki | 1:72320e85a5e2 | 83 | void dotSet(int posX, int posY) |
k4zuki | 1:72320e85a5e2 | 84 | { |
m_wakayama | 0:e705efefad3f | 85 | int ramAddress; |
m_wakayama | 0:e705efefad3f | 86 | uint8_t data; |
m_wakayama | 0:e705efefad3f | 87 | if ((posX >= 0) && (posX < 400) && (posY >= 0) && (posY < 240)) { |
k4zuki | 1:72320e85a5e2 | 88 | ramAddress = (posX / 8) + (posY * RAMLINE_LENGTH); |
m_wakayama | 0:e705efefad3f | 89 | data = LCDRAM.ram_read(ramAddress); |
m_wakayama | 0:e705efefad3f | 90 | data |= 0x80 >> (posX % 8); |
m_wakayama | 0:e705efefad3f | 91 | LCDRAM.ram_write(ramAddress, data); |
m_wakayama | 0:e705efefad3f | 92 | } |
m_wakayama | 0:e705efefad3f | 93 | } |
k4zuki | 1:72320e85a5e2 | 94 | */ |
m_wakayama | 0:e705efefad3f | 95 | |
k4zuki | 1:72320e85a5e2 | 96 | int dotAddress = -1; |
k4zuki | 1:72320e85a5e2 | 97 | uint8_t dotData; |
k4zuki | 1:72320e85a5e2 | 98 | void dotSet(int posX, int posY) { |
k4zuki | 1:72320e85a5e2 | 99 | if ((posX >= 0) && (posX < 416) && (posY >= 0) && (posY < 240)) { |
k4zuki | 1:72320e85a5e2 | 100 | int address = (posX / 8) + (posY * RAMLINE_LENGTH); |
k4zuki | 1:72320e85a5e2 | 101 | if (address != dotAddress) { |
k4zuki | 1:72320e85a5e2 | 102 | dotAddress = address; |
k4zuki | 1:72320e85a5e2 | 103 | dotData = LCDRAM.ram_read(dotAddress); |
k4zuki | 1:72320e85a5e2 | 104 | } |
k4zuki | 1:72320e85a5e2 | 105 | dotData |= 0x80 >> (posX % 8); |
k4zuki | 1:72320e85a5e2 | 106 | LCDRAM.ram_write(dotAddress, dotData); |
k4zuki | 1:72320e85a5e2 | 107 | } |
k4zuki | 1:72320e85a5e2 | 108 | } |
k4zuki | 1:72320e85a5e2 | 109 | |
k4zuki | 1:72320e85a5e2 | 110 | void drawLine(int posX1, int posY1, int posX2, int posY2) |
k4zuki | 1:72320e85a5e2 | 111 | { |
m_wakayama | 0:e705efefad3f | 112 | float moveX = (float)(posX1 - posX2); |
m_wakayama | 0:e705efefad3f | 113 | float moveY = (float)(posY1 - posY2); |
m_wakayama | 0:e705efefad3f | 114 | int absX = abs((int)(moveX)); |
m_wakayama | 0:e705efefad3f | 115 | int absY = abs((int)(moveY)); |
m_wakayama | 0:e705efefad3f | 116 | int tmp; |
m_wakayama | 0:e705efefad3f | 117 | if (absX > absY) { |
m_wakayama | 0:e705efefad3f | 118 | tmp = absX; |
m_wakayama | 0:e705efefad3f | 119 | } else { |
m_wakayama | 0:e705efefad3f | 120 | tmp = absY; |
m_wakayama | 0:e705efefad3f | 121 | } |
m_wakayama | 0:e705efefad3f | 122 | moveX = moveX / (float)(tmp); |
m_wakayama | 0:e705efefad3f | 123 | moveY = moveY / (float)(tmp); |
k4zuki | 1:72320e85a5e2 | 124 | for (int i = 0; i < tmp; i++) { |
m_wakayama | 0:e705efefad3f | 125 | dotSet(posX2 + moveX * i, posY2 + moveY * i); |
m_wakayama | 0:e705efefad3f | 126 | } |
m_wakayama | 0:e705efefad3f | 127 | } |
m_wakayama | 0:e705efefad3f | 128 | |
k4zuki | 1:72320e85a5e2 | 129 | void ram2lcdAll() |
k4zuki | 1:72320e85a5e2 | 130 | { |
k4zuki | 1:72320e85a5e2 | 131 | // LCDRAM.ram2lcd(0,240,SCREEN0); |
k4zuki | 1:72320e85a5e2 | 132 | LCDRAM.ram2lcd(SCREEN0); |
k4zuki | 1:72320e85a5e2 | 133 | /* |
k4zuki | 1:72320e85a5e2 | 134 | for (int y = 0; y < 240; y++) { |
k4zuki | 1:72320e85a5e2 | 135 | LCDRAM.ram_read(y * RAMLINE_LENGTH+2,lineBuffer,RAMLINE_LENGTH); |
m_wakayama | 0:e705efefad3f | 136 | LCDRAM.directUpdateSingle(y + 1,lineBuffer); |
m_wakayama | 0:e705efefad3f | 137 | } |
k4zuki | 1:72320e85a5e2 | 138 | */ |
m_wakayama | 0:e705efefad3f | 139 | } |
m_wakayama | 0:e705efefad3f | 140 | |
k4zuki | 1:72320e85a5e2 | 141 | void calcBox() |
k4zuki | 1:72320e85a5e2 | 142 | { |
m_wakayama | 0:e705efefad3f | 143 | float tmpX = boxAngleX * 3.141592653f / 180.0f; |
m_wakayama | 0:e705efefad3f | 144 | float tmpZ = boxAngleZ * 3.141592653f / 180.0f; |
m_wakayama | 0:e705efefad3f | 145 | float sinX = sin(tmpX); |
m_wakayama | 0:e705efefad3f | 146 | float cosX = cos(tmpX); |
m_wakayama | 0:e705efefad3f | 147 | float sinZ = sin(tmpZ); |
m_wakayama | 0:e705efefad3f | 148 | float cosZ = cos(tmpZ); |
k4zuki | 1:72320e85a5e2 | 149 | for (int i = 0; i < 8; i++) { |
m_wakayama | 0:e705efefad3f | 150 | buff3D[i][0] = cosZ * boxPosi[i][0] - sinZ * boxPosi[i][1]; |
m_wakayama | 0:e705efefad3f | 151 | buff3D[i][1] = sinZ * boxPosi[i][0] + cosZ * boxPosi[i][1]; |
m_wakayama | 0:e705efefad3f | 152 | buff3D[i][2] = sinX * boxPosi[i][1] + cosX * boxPosi[i][2]; |
m_wakayama | 0:e705efefad3f | 153 | buff3D[i][1] = cosX * boxPosi[i][1] - sinX * boxPosi[i][2]; |
m_wakayama | 0:e705efefad3f | 154 | buff3D[i][0] = cosZ * boxPosi[i][0] - sinZ * buff3D[i][2]; |
m_wakayama | 0:e705efefad3f | 155 | buff3D[i][2] = sinZ * boxPosi[i][0] + cosZ * buff3D[i][2]; |
m_wakayama | 0:e705efefad3f | 156 | } |
m_wakayama | 0:e705efefad3f | 157 | } |
m_wakayama | 0:e705efefad3f | 158 | |
k4zuki | 1:72320e85a5e2 | 159 | void drawBox() |
k4zuki | 1:72320e85a5e2 | 160 | { |
k4zuki | 1:72320e85a5e2 | 161 | for (int i = 0; i < 12; i++) { |
m_wakayama | 0:e705efefad3f | 162 | drawLine((int)(buff3D[boxLink[i][0]][0]) + boxOffsetX, (int)(buff3D[boxLink[i][0]][1]) + boxOffsetY, (int)(buff3D[boxLink[i][1]][0]) + boxOffsetX, (int)(buff3D[boxLink[i][1]][1]) + boxOffsetY); |
m_wakayama | 0:e705efefad3f | 163 | } |
m_wakayama | 0:e705efefad3f | 164 | } |
m_wakayama | 0:e705efefad3f | 165 | |
k4zuki | 1:72320e85a5e2 | 166 | void drawAscii(uint8_t num,int posX,int posY,int angle) |
k4zuki | 1:72320e85a5e2 | 167 | { |
m_wakayama | 0:e705efefad3f | 168 | float tmpA = angle * 3.141592653f / 180.0f; |
m_wakayama | 0:e705efefad3f | 169 | float tmpS = sin(tmpA); |
m_wakayama | 0:e705efefad3f | 170 | float tmpC = cos(tmpA); |
k4zuki | 1:72320e85a5e2 | 171 | for (int i = 0; i < 9; i++) { |
m_wakayama | 0:e705efefad3f | 172 | buff2D[i][0] = (int)(tmpC * asciiPosi[i][0] - tmpS * asciiPosi[i][1]); |
m_wakayama | 0:e705efefad3f | 173 | buff2D[i][1] = (int)(tmpS * asciiPosi[i][0] + tmpC * asciiPosi[i][1]); |
m_wakayama | 0:e705efefad3f | 174 | } |
k4zuki | 1:72320e85a5e2 | 175 | for (int i = 0; i < 6; i++) { |
m_wakayama | 0:e705efefad3f | 176 | if ((asciiLink[num][i][0] != 0) || (asciiLink[num][i][1] != 0)) { |
m_wakayama | 0:e705efefad3f | 177 | drawLine(buff2D[asciiLink[num][i][0]][0] + posX,buff2D[asciiLink[num][i][0]][1] + posY,buff2D[asciiLink[num][i][1]][0] + posX,buff2D[asciiLink[num][i][1]][1] + posY); |
m_wakayama | 0:e705efefad3f | 178 | } |
m_wakayama | 0:e705efefad3f | 179 | } |
m_wakayama | 0:e705efefad3f | 180 | } |
m_wakayama | 0:e705efefad3f | 181 | |
k4zuki | 1:72320e85a5e2 | 182 | void rollAscii() |
k4zuki | 1:72320e85a5e2 | 183 | { |
k4zuki | 1:72320e85a5e2 | 184 | for (int i = 0; i < (10 + 26); i++) { |
m_wakayama | 0:e705efefad3f | 185 | int angle = (asciiAngle + i * 8) % 360; |
m_wakayama | 0:e705efefad3f | 186 | float tmpA = angle * 3.141592653f / 180.0f; |
m_wakayama | 0:e705efefad3f | 187 | float tmpS = sin(tmpA); |
m_wakayama | 0:e705efefad3f | 188 | float tmpC = cos(tmpA); |
m_wakayama | 0:e705efefad3f | 189 | drawAscii(i,(int)(tmpC * 400.0f / 2.9f - tmpS * 400.0f / 2.9f + 400.0f / 2.0f),(int)(tmpS * 240.0f / 2.9f + tmpC * 240.0f / 2.9f + 240.0f / 2.0f),(angle + 135) % 360); |
m_wakayama | 0:e705efefad3f | 190 | } |
m_wakayama | 0:e705efefad3f | 191 | } |
m_wakayama | 0:e705efefad3f | 192 | // -------------------------------------------------------------------- |
m_wakayama | 0:e705efefad3f | 193 | // -------------------------------------------------------------------- |
m_wakayama | 0:e705efefad3f | 194 | uint16_t vaders[5]; |
m_wakayama | 0:e705efefad3f | 195 | uint8_t vaderLine[5] = {0,1,1,2,2}; |
m_wakayama | 0:e705efefad3f | 196 | uint8_t cgBuffer[3][2][2 * 8] = { |
k4zuki | 1:72320e85a5e2 | 197 | { {0x03,0x00,0x07,0x80,0x0f,0xc0,0x1b,0x60,0x1f,0xe0,0x04,0x80,0x0b,0x40,0x14,0xa0}, |
k4zuki | 1:72320e85a5e2 | 198 | {0x00,0x30,0x00,0x78,0x00,0xfc,0x01,0xb6,0x01,0xfe,0x00,0x84,0x01,0x02,0x00,0x84} |
k4zuki | 1:72320e85a5e2 | 199 | }, |
k4zuki | 1:72320e85a5e2 | 200 | { {0x08,0x20,0x04,0x40,0x0f,0xe0,0x1b,0xb0,0x3f,0xf8,0x2f,0xe8,0x28,0x28,0x06,0xc0}, |
k4zuki | 1:72320e85a5e2 | 201 | {0x01,0x04,0x04,0x89,0x05,0xfd,0x0b,0xb7,0x07,0xff,0x01,0xfc,0x01,0x04,0x00,0xd8} |
k4zuki | 1:72320e85a5e2 | 202 | }, |
k4zuki | 1:72320e85a5e2 | 203 | { {0x0f,0x00,0x7f,0xe0,0xff,0xf0,0xe6,0x70,0xff,0xf0,0x19,0x80,0x36,0xc0,0xc0,0x30}, |
k4zuki | 1:72320e85a5e2 | 204 | { |
k4zuki | 1:72320e85a5e2 | 205 | 0x00,0xf0, |
k4zuki | 1:72320e85a5e2 | 206 | 0x07,0xfe, |
k4zuki | 1:72320e85a5e2 | 207 | 0x0f,0xff, |
k4zuki | 1:72320e85a5e2 | 208 | 0x0e,0x67, |
k4zuki | 1:72320e85a5e2 | 209 | 0x0f,0xff, |
k4zuki | 1:72320e85a5e2 | 210 | 0x01,0x98, |
k4zuki | 1:72320e85a5e2 | 211 | 0x06,0x66, |
k4zuki | 1:72320e85a5e2 | 212 | 0x01,0x98, |
k4zuki | 1:72320e85a5e2 | 213 | } |
k4zuki | 1:72320e85a5e2 | 214 | }, |
m_wakayama | 0:e705efefad3f | 215 | }; |
k4zuki | 1:72320e85a5e2 | 216 | void draw_vaders() |
k4zuki | 1:72320e85a5e2 | 217 | { |
m_wakayama | 0:e705efefad3f | 218 | uint8_t counter,tmp; |
k4zuki | 1:72320e85a5e2 | 219 | for (int y = 0; y < 5; y++) { |
k4zuki | 1:72320e85a5e2 | 220 | for (int x = 0; x < 11; x++) { |
m_wakayama | 0:e705efefad3f | 221 | if ((vaders[y] & (0x400 >> x)) != 0) { |
m_wakayama | 0:e705efefad3f | 222 | counter = 0; |
k4zuki | 1:72320e85a5e2 | 223 | for (int i = 0; i < 8; i++) { |
m_wakayama | 0:e705efefad3f | 224 | tmp = cgBuffer[vaderLine[y]][(mainCounter + scrollY) & 1][counter++]; |
m_wakayama | 0:e705efefad3f | 225 | if (tmp != 0) { |
k4zuki | 1:72320e85a5e2 | 226 | LCDRAM.ram_write((((y + scrollY) * 12 + i) * RAMLINE_LENGTH) + (x * 2 + scrollX + 0),tmp); |
m_wakayama | 0:e705efefad3f | 227 | } |
m_wakayama | 0:e705efefad3f | 228 | tmp = cgBuffer[vaderLine[y]][(mainCounter + scrollY) & 1][counter++]; |
m_wakayama | 0:e705efefad3f | 229 | if (tmp != 0) { |
k4zuki | 1:72320e85a5e2 | 230 | LCDRAM.ram_write((((y + scrollY) * 12 + i) * RAMLINE_LENGTH) + (x * 2 + scrollX + 1),tmp); |
m_wakayama | 0:e705efefad3f | 231 | } |
m_wakayama | 0:e705efefad3f | 232 | } |
m_wakayama | 0:e705efefad3f | 233 | } |
m_wakayama | 0:e705efefad3f | 234 | } |
m_wakayama | 0:e705efefad3f | 235 | } |
m_wakayama | 0:e705efefad3f | 236 | } |
k4zuki | 1:72320e85a5e2 | 237 | void init_vaders() |
k4zuki | 1:72320e85a5e2 | 238 | { |
k4zuki | 1:72320e85a5e2 | 239 | for (int i = 0; i < 5; i++) { |
m_wakayama | 0:e705efefad3f | 240 | vaders[i] = 0x7ff; |
m_wakayama | 0:e705efefad3f | 241 | } |
m_wakayama | 0:e705efefad3f | 242 | } |
k4zuki | 1:72320e85a5e2 | 243 | void gameControl() |
k4zuki | 1:72320e85a5e2 | 244 | { |
m_wakayama | 0:e705efefad3f | 245 | if ((mainCounter & 1) == 0) { |
m_wakayama | 0:e705efefad3f | 246 | if ((scrollY & 1) == 0) { |
k4zuki | 1:72320e85a5e2 | 247 | if (++scrollX > 30) { |
m_wakayama | 0:e705efefad3f | 248 | scrollX--; |
m_wakayama | 0:e705efefad3f | 249 | scrollY++; |
m_wakayama | 0:e705efefad3f | 250 | } |
m_wakayama | 0:e705efefad3f | 251 | } else { |
m_wakayama | 0:e705efefad3f | 252 | if (--scrollX < 0) { |
m_wakayama | 0:e705efefad3f | 253 | scrollX++; |
m_wakayama | 0:e705efefad3f | 254 | scrollY++; |
m_wakayama | 0:e705efefad3f | 255 | } |
m_wakayama | 0:e705efefad3f | 256 | } |
m_wakayama | 0:e705efefad3f | 257 | } |
m_wakayama | 0:e705efefad3f | 258 | } |
m_wakayama | 0:e705efefad3f | 259 | // -------------------------------------------------------------------- |
m_wakayama | 0:e705efefad3f | 260 | // -------------------------------------------------------------------- |
m_wakayama | 0:e705efefad3f | 261 | |
k4zuki | 1:72320e85a5e2 | 262 | int main() |
k4zuki | 1:72320e85a5e2 | 263 | { |
m_wakayama | 0:e705efefad3f | 264 | wait_ms(1); |
m_wakayama | 0:e705efefad3f | 265 | LCDRAM.cls(); |
k4zuki | 1:72320e85a5e2 | 266 | LCDRAM.cls_ram(SCREEN0); |
k4zuki | 1:72320e85a5e2 | 267 | boxOffsetX = 416 / 2; |
m_wakayama | 0:e705efefad3f | 268 | boxOffsetY = 240 / 2; |
m_wakayama | 0:e705efefad3f | 269 | boxAngleX = 0; |
m_wakayama | 0:e705efefad3f | 270 | boxAngleZ = 0; |
m_wakayama | 0:e705efefad3f | 271 | init_vaders(); |
m_wakayama | 0:e705efefad3f | 272 | while(1) { |
m_wakayama | 0:e705efefad3f | 273 | mainCounter++; |
m_wakayama | 0:e705efefad3f | 274 | gameControl(); |
m_wakayama | 0:e705efefad3f | 275 | LCDRAM.cls_ram(SCREEN0); |
m_wakayama | 0:e705efefad3f | 276 | draw_vaders(); |
m_wakayama | 0:e705efefad3f | 277 | calcBox(); |
m_wakayama | 0:e705efefad3f | 278 | drawBox(); |
m_wakayama | 0:e705efefad3f | 279 | rollAscii(); |
m_wakayama | 0:e705efefad3f | 280 | ram2lcdAll(); |
m_wakayama | 0:e705efefad3f | 281 | boxAngleX = (boxAngleX + 2) % 360; |
m_wakayama | 0:e705efefad3f | 282 | boxAngleZ = (boxAngleZ + 3) % 360; |
m_wakayama | 0:e705efefad3f | 283 | asciiAngle = (asciiAngle + 358) % 360; |
m_wakayama | 0:e705efefad3f | 284 | } |
m_wakayama | 0:e705efefad3f | 285 | } |