Kazuki Yamamoto
/
LCDRAM
yet another AkiSpiLcd library example
Fork of LCDRAM by
Revision 1:72320e85a5e2, committed 2015-01-12
- Comitter:
- k4zuki
- Date:
- Mon Jan 12 12:06:38 2015 +0000
- Parent:
- 0:e705efefad3f
- Commit message:
- first commit; mov ing cube, moving ascii characters, movin invaders
Changed in this revision
--- a/AkiSpiLcd.lib Tue Nov 25 10:28:12 2014 +0000 +++ b/AkiSpiLcd.lib Mon Jan 12 12:06:38 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/k4zuki/code/AkiSpiLcd/#20ba395cbf2a +http://mbed.org/users/k4zuki/code/AkiSpiLcd/#fa277cbcc890
--- a/main.cpp Tue Nov 25 10:28:12 2014 +0000 +++ b/main.cpp Mon Jan 12 12:06:38 2015 +0000 @@ -3,13 +3,14 @@ #include "AkiSpiLcd.h" //AkiSpiLcd LCD(MISO, MOSI, SCK, CSL, CSR); -AkiSpiLcd LCDRAM(p11, p12, p13, p9, p10); -uint8_t lineBuffer[400 / 8]; +//AkiSpiLcd LCDRAM(p11, p12, p13, p9, p10); +AkiSpiLcd LCDRAM(p5, p6, p7, p9, p10); +uint8_t lineBuffer[RAMLINE_LENGTH]; // SYSTEM -------------------------------------------------- uint8_t mainCounter; // GAME ---------------------------------------------------- -int scrollX,scrollY; +int scrollX=2,scrollY; // BOX ----------------------------------------------------- int8_t boxPosi[8][3] = { {-78,-78,-78},{-78,+78,-78},{-78,+78,+78},{-78,-78,+78}, @@ -28,9 +29,14 @@ // ASCII --------------------------------- int8_t asciiPosi[9][2] = { + {-6,-7},{ 0,-7},{+6,-7}, + {-6, 0},{ 0, 0},{+6, 0}, + {-6,+11},{ 0,+11},{+6,+11} + /* {-6,-9},{ 0,-9},{+6,-9}, {-6, 0},{ 0, 0},{+6, 0}, {-6,+9},{ 0,+9},{+6,+9} + */ }; uint8_t asciiLink[10 + 26][6][2] = { {{0,2},{2,8},{8,6},{6,0},{0,0},{0,0}}, // 0 @@ -73,18 +79,36 @@ int buff2D[9][2]; int asciiAngle; -void dotSet(int posX, int posY) { +/* +void dotSet(int posX, int posY) +{ int ramAddress; uint8_t data; if ((posX >= 0) && (posX < 400) && (posY >= 0) && (posY < 240)) { - ramAddress = (posX / 8) + (posY * 400 / 8); + ramAddress = (posX / 8) + (posY * RAMLINE_LENGTH); data = LCDRAM.ram_read(ramAddress); data |= 0x80 >> (posX % 8); LCDRAM.ram_write(ramAddress, data); } } +*/ -void drawLine(int posX1, int posY1, int posX2, int posY2) { +int dotAddress = -1; +uint8_t dotData; +void dotSet(int posX, int posY) { + if ((posX >= 0) && (posX < 416) && (posY >= 0) && (posY < 240)) { + int address = (posX / 8) + (posY * RAMLINE_LENGTH); + if (address != dotAddress) { + dotAddress = address; + dotData = LCDRAM.ram_read(dotAddress); + } + dotData |= 0x80 >> (posX % 8); + LCDRAM.ram_write(dotAddress, dotData); + } +} + +void drawLine(int posX1, int posY1, int posX2, int posY2) +{ float moveX = (float)(posX1 - posX2); float moveY = (float)(posY1 - posY2); int absX = abs((int)(moveX)); @@ -97,26 +121,32 @@ } moveX = moveX / (float)(tmp); moveY = moveY / (float)(tmp); - for (int i = 0;i < tmp;i++) { + for (int i = 0; i < tmp; i++) { dotSet(posX2 + moveX * i, posY2 + moveY * i); } } -void ram2lcdAll() { - for (int y = 0;y < 240;y++) { - LCDRAM.ram_read(y * 400 / 8,lineBuffer,400 / 8); +void ram2lcdAll() +{ +// LCDRAM.ram2lcd(0,240,SCREEN0); + LCDRAM.ram2lcd(SCREEN0); +/* + for (int y = 0; y < 240; y++) { + LCDRAM.ram_read(y * RAMLINE_LENGTH+2,lineBuffer,RAMLINE_LENGTH); LCDRAM.directUpdateSingle(y + 1,lineBuffer); } +*/ } -void calcBox() { +void calcBox() +{ float tmpX = boxAngleX * 3.141592653f / 180.0f; float tmpZ = boxAngleZ * 3.141592653f / 180.0f; float sinX = sin(tmpX); float cosX = cos(tmpX); float sinZ = sin(tmpZ); float cosZ = cos(tmpZ); - for (int i = 0;i < 8;i++) { + for (int i = 0; i < 8; i++) { buff3D[i][0] = cosZ * boxPosi[i][0] - sinZ * boxPosi[i][1]; buff3D[i][1] = sinZ * boxPosi[i][0] + cosZ * boxPosi[i][1]; buff3D[i][2] = sinX * boxPosi[i][1] + cosX * boxPosi[i][2]; @@ -126,29 +156,32 @@ } } -void drawBox() { - for (int i = 0;i < 12;i++) { +void drawBox() +{ + for (int i = 0; i < 12; i++) { 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); } } -void drawAscii(uint8_t num,int posX,int posY,int angle) { +void drawAscii(uint8_t num,int posX,int posY,int angle) +{ float tmpA = angle * 3.141592653f / 180.0f; float tmpS = sin(tmpA); float tmpC = cos(tmpA); - for (int i = 0;i < 9;i++) { + for (int i = 0; i < 9; i++) { buff2D[i][0] = (int)(tmpC * asciiPosi[i][0] - tmpS * asciiPosi[i][1]); buff2D[i][1] = (int)(tmpS * asciiPosi[i][0] + tmpC * asciiPosi[i][1]); } - for (int i = 0;i < 6;i++) { + for (int i = 0; i < 6; i++) { if ((asciiLink[num][i][0] != 0) || (asciiLink[num][i][1] != 0)) { 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); } } } -void rollAscii() { - for (int i = 0;i < (10 + 26);i++) { +void rollAscii() +{ + for (int i = 0; i < (10 + 26); i++) { int angle = (asciiAngle + i * 8) % 360; float tmpA = angle * 3.141592653f / 180.0f; float tmpS = sin(tmpA); @@ -161,51 +194,57 @@ uint16_t vaders[5]; uint8_t vaderLine[5] = {0,1,1,2,2}; uint8_t cgBuffer[3][2][2 * 8] = { - {{0x03,0x00,0x07,0x80,0x0f,0xc0,0x1b,0x60,0x1f,0xe0,0x04,0x80,0x0b,0x40,0x14,0xa0}, - {0x00,0x30,0x00,0x78,0x00,0xfc,0x01,0xb6,0x01,0xfe,0x00,0x84,0x01,0x02,0x00,0x84}}, - {{0x08,0x20,0x04,0x40,0x0f,0xe0,0x1b,0xb0,0x3f,0xf8,0x2f,0xe8,0x28,0x28,0x06,0xc0}, - {0x01,0x04,0x04,0x89,0x05,0xfd,0x0b,0xb7,0x07,0xff,0x01,0xfc,0x01,0x04,0x00,0xd8}}, - {{0x0f,0x00,0x7f,0xe0,0xff,0xf0,0xe6,0x70,0xff,0xf0,0x19,0x80,0x36,0xc0,0xc0,0x30}, - { -0x00,0xf0, -0x07,0xfe, -0x0f,0xff, -0x0e,0x67, -0x0f,0xff, -0x01,0x98, -0x06,0x66, -0x01,0x98, -}}, + { {0x03,0x00,0x07,0x80,0x0f,0xc0,0x1b,0x60,0x1f,0xe0,0x04,0x80,0x0b,0x40,0x14,0xa0}, + {0x00,0x30,0x00,0x78,0x00,0xfc,0x01,0xb6,0x01,0xfe,0x00,0x84,0x01,0x02,0x00,0x84} + }, + { {0x08,0x20,0x04,0x40,0x0f,0xe0,0x1b,0xb0,0x3f,0xf8,0x2f,0xe8,0x28,0x28,0x06,0xc0}, + {0x01,0x04,0x04,0x89,0x05,0xfd,0x0b,0xb7,0x07,0xff,0x01,0xfc,0x01,0x04,0x00,0xd8} + }, + { {0x0f,0x00,0x7f,0xe0,0xff,0xf0,0xe6,0x70,0xff,0xf0,0x19,0x80,0x36,0xc0,0xc0,0x30}, + { + 0x00,0xf0, + 0x07,0xfe, + 0x0f,0xff, + 0x0e,0x67, + 0x0f,0xff, + 0x01,0x98, + 0x06,0x66, + 0x01,0x98, + } + }, }; -void draw_vaders() { +void draw_vaders() +{ uint8_t counter,tmp; - for (int y = 0;y < 5;y++) { - for (int x = 0;x < 11;x++) { + for (int y = 0; y < 5; y++) { + for (int x = 0; x < 11; x++) { if ((vaders[y] & (0x400 >> x)) != 0) { counter = 0; - for (int i = 0;i < 8;i++) { + for (int i = 0; i < 8; i++) { tmp = cgBuffer[vaderLine[y]][(mainCounter + scrollY) & 1][counter++]; if (tmp != 0) { - LCDRAM.ram_write((((y + scrollY) * 12 + i) * 400 / 8) + (x * 2 + scrollX + 0),tmp); + LCDRAM.ram_write((((y + scrollY) * 12 + i) * RAMLINE_LENGTH) + (x * 2 + scrollX + 0),tmp); } tmp = cgBuffer[vaderLine[y]][(mainCounter + scrollY) & 1][counter++]; if (tmp != 0) { - LCDRAM.ram_write((((y + scrollY) * 12 + i) * 400 / 8) + (x * 2 + scrollX + 1),tmp); + LCDRAM.ram_write((((y + scrollY) * 12 + i) * RAMLINE_LENGTH) + (x * 2 + scrollX + 1),tmp); } } } } } } -void init_vaders() { - for (int i = 0;i < 5;i++) { +void init_vaders() +{ + for (int i = 0; i < 5; i++) { vaders[i] = 0x7ff; } } -void gameControl() { +void gameControl() +{ if ((mainCounter & 1) == 0) { if ((scrollY & 1) == 0) { - if (++scrollX > 28) { + if (++scrollX > 30) { scrollX--; scrollY++; } @@ -220,10 +259,12 @@ // -------------------------------------------------------------------- // -------------------------------------------------------------------- -int main() { +int main() +{ wait_ms(1); LCDRAM.cls(); - boxOffsetX = 400 / 2; + LCDRAM.cls_ram(SCREEN0); + boxOffsetX = 416 / 2; boxOffsetY = 240 / 2; boxAngleX = 0; boxAngleZ = 0;
--- a/mbed.bld Tue Nov 25 10:28:12 2014 +0000 +++ b/mbed.bld Mon Jan 12 12:06:38 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file