Louis Mayencourt
/
NRFBOY
MBED NRF51 Arduboy port
Revision 7:fb7e549d1cf6, committed 2017-01-07
- Comitter:
- lmayencou
- Date:
- Sat Jan 07 23:35:36 2017 +0100
- Parent:
- 6:e86e6adbc3e8
- Commit message:
- circuitdude port done
Changed in this revision
--- a/abstractarduboy.cpp Sat Jan 07 22:03:21 2017 +0100 +++ b/abstractarduboy.cpp Sat Jan 07 23:35:36 2017 +0100 @@ -429,6 +429,7 @@ if (x + w < 0 || x > WIDTH - 1 || y + h < 0 || y > HEIGHT - 1) return; + int yOffset = abs(y) % 8; int sRow = y / 8; if (y < 0) { @@ -456,6 +457,17 @@ } } } + +/* + for (int16_t j=0; j<h; j++) + { + for (int16_t i=0; i<w; i++ ) + { + if (bitmap[i + (j/8)*w] & _BV(j%8)) + drawPixel(x+i, y+j, color); + } + } + */ } @@ -477,7 +489,7 @@ if (cs.bit == 0x100) { cs.bit = 0x1; - cs.byte = pgm_read_byte(&cs.src[cs.src_pos]); + cs.byte = cs.src[cs.src_pos]; cs.src_pos ++; } if (cs.byte & cs.bit) @@ -619,6 +631,45 @@ // draw a character void AbstractArduboy::drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size) { + boolean draw_background = bg != color; + + if ((x >= WIDTH) || // Clip right + (y >= HEIGHT) || // Clip bottom + ((x + 5 * size - 1) < 0) || // Clip left + ((y + 8 * size - 1) < 0) // Clip top + ) + { + return; + } + + for (int8_t i=0; i<6; i++ ) + { + uint8_t line; + if (i == 5) + { + line = 0x0; + } + else + { + line = font[(c*5)+i]; + } + + for (int8_t j = 0; j<8; j++) + { + uint8_t draw_color = (line & 0x1) ? color : bg; + + if (draw_color || draw_background) { + for (uint8_t a = 0; a < size; a++ ) { + for (uint8_t b = 0; b < size; b++ ) { + drawPixel(x + (i * size) + a, y + (j * size) + b, draw_color); + } + } + } + line >>= 1; + } + } + + /* if( (x >= WIDTH) || // Clip right (y >= HEIGHT) || // Clip bottom @@ -663,6 +714,7 @@ line >>= 1; } } + */ } void AbstractArduboy::swap(int16_t &a, int16_t &b)
--- a/abstractarduboy.h Sat Jan 07 22:03:21 2017 +0100 +++ b/abstractarduboy.h Sat Jan 07 23:35:36 2017 +0100 @@ -17,7 +17,7 @@ #define min(a,b) (((a)<(b))?(a):(b)) #define max(a,b) (((a)>(b))?(a):(b)) #define abs(a) (((a) < 0) ? -(a) : (a)) -#define pgm_read_byte(a) 1 +//#define pgm_read_byte(a) 1 #define LEFT_BUTTON _BV(0) #define RIGHT_BUTTON _BV(1)
--- a/circuitDude.hpp Sat Jan 07 22:03:21 2017 +0100 +++ b/circuitDude.hpp Sat Jan 07 23:35:36 2017 +0100 @@ -33,35 +33,35 @@ #define SAVELOCATION (EEPROM_STORAGE_SPACE_START + 410) void checkcompletion(); -void swapall(char from, char to); -void rotateinplace(char index); -void checklocation(char locx, char locy); -bool checkcollision(char locx, char locy) ; +void swapall(int8_t from, int8_t to); +void rotateinplace(int8_t index); +void checklocation(int8_t locx, int8_t locy); +bool checkcollision(int8_t locx, int8_t locy) ; void loadlevel(int givenlevel) ; -void continuestate(char tostate); +void continuestate(int8_t tostate); void drawlevel(); void drawtitle(); -void printmenuitem(char menuitem, char y) ; +void printmenuitem(int8_t menuitem, int8_t y) ; boolean menubuttonfree = true; -char menubuttoncounter = 0; +int8_t menubuttoncounter = 0; boolean gamebuttonfree = true; int frame = 0; -char animation = 0; -char transitionanimation = 0; -char deathcounter = 0; -char gamestate = 0; -char level = 0; +int8_t animation = 0; +int8_t transitionanimation = 0; +int8_t deathcounter = 0; +int8_t gamestate = 0; +int8_t level = 0; boolean levelcomplete = false; -char levelcompletecounter = 0; -char playerx = 0; -char playery = 0; -char playertox = 0; -char playertoy = 0; +int8_t levelcompletecounter = 0; +int8_t playerx = 0; +int8_t playery = 0; +int8_t playertox = 0; +int8_t playertoy = 0; boolean canswitch = true; -char temperature = 0; -char maxlevel = 0; -char levelchecker = 0; +int8_t temperature = 0; +int8_t maxlevel = 0; +int8_t levelchecker = 0; boolean soundon = true; const unsigned char lock[] = { @@ -1566,7 +1566,7 @@ BLCOR, HWALL, HWALL, HWALL, HWALL, HWALL, HWALL, HWALL, HWALL, HWALL, HWALL, HWALL, HWALL, BRCOR }; -void printmenuitem(char menuitem, char y) { +void printmenuitem(int8_t menuitem, int8_t y) { arduboy.setCursor(68, y); if(menuitem > -5 && menuitem < 50) { if(menuitem == -4) { @@ -1661,7 +1661,7 @@ } -void continuestate(char tostate) { +void continuestate(int8_t tostate) { if(arduboy.pressed(A_BUTTON) && menubuttonfree) { sound(NOISEMENUCLICK, 100); gamestate = tostate; @@ -1685,7 +1685,7 @@ canswitch = true; deathcounter = 0; for (int i = 0; i < sizeof(currentmap) / sizeof(currentmap[0]); i++) { - currentmap[i] = pgm_read_byte(&levelmap[givenlevel][i]); + currentmap[i] = levelmap[givenlevel][i]; if(currentmap[i] == 51) { playery = i / 14 * 8; playerx = (i - (i / 14) * 14) * 8; @@ -1700,10 +1700,10 @@ } } -bool checkcollision(char locx, char locy) { - char leftright = locx * 8 - playerx; //0 = Up/Down, - = Left, + = Right - char updown = locy * 8 - playery; //0 = Left/Right, - = Up, + = Down - char tile = currentmap[locx + locy * 14]; +bool checkcollision(int8_t locx, int8_t locy) { + int8_t leftright = locx * 8 - playerx; //0 = Up/Down, - = Left, + = Right + int8_t updown = locy * 8 - playery; //0 = Left/Right, - = Up, + = Down + int8_t tile = currentmap[locx + locy * 14]; if(locx < 0 || locy < 0 || locx >= 14 || locy >= 8) { return false; } @@ -1733,7 +1733,7 @@ return true; } -void checklocation(char locx, char locy) { +void checklocation(int8_t locx, int8_t locy) { switch(currentmap[locx + locy * 14]) { case CONUP: playertoy -= 8; @@ -1799,7 +1799,7 @@ } } -void rotateinplace(char index) { +void rotateinplace(int8_t index) { if(currentmap[index] == BRROT) { currentmap[index] = BLROT; sound(NOISEROTATE, 150); @@ -1832,7 +1832,7 @@ } } -void swapall(char from, char to) { +void swapall(int8_t from, int8_t to) { for (int i = 0; i < sizeof(currentmap) / sizeof(currentmap[0]); i++) { if(currentmap[i] == from) { currentmap[i] = to; @@ -1918,8 +1918,6 @@ continuestate(2); break; case 2: //Main Menu - printf("levelchecker %d", levelchecker); - frame++; drawtitle(); arduboy.fillRect(64, 0, 64, 64, BLACK); @@ -1969,7 +1967,6 @@ } } } - led3 = 0; printmenuitem(levelchecker - 2, 2); printmenuitem(levelchecker - 1, 10); arduboy.drawLine(64, 19, 128, 19, WHITE); @@ -1980,7 +1977,7 @@ printmenuitem(levelchecker + 1, 34); printmenuitem(levelchecker + 2, 42); printmenuitem(levelchecker + 3, 50); - printmenuitem(levelchecker + 4, 58); + // printmenuitem(levelchecker + 4, 58); break; case 3: //Instruction Screen arduboy.setCursor(0, 0); @@ -2023,7 +2020,7 @@ arduboy.printf("%d",(int)(level + 1)); drawlevel(); if(transitionanimation == 0 && gamebuttonfree) { - char index = playerx / 8 + playery / 8 * 14; + int8_t index = playerx / 8 + playery / 8 * 14; if(gamebuttonfree && arduboy.pressed(UP_BUTTON) && checkcollision(playerx / 8, (playery - 8) / 8) && currentmap[index] != HTROT && currentmap[index] != TLROT && currentmap[index] != TRROT) { rotateinplace(index); playertoy -= 8;
--- a/mbedboy.hpp Sat Jan 07 22:03:21 2017 +0100 +++ b/mbedboy.hpp Sat Jan 07 23:35:36 2017 +0100 @@ -28,7 +28,7 @@ void start() { // init systime - timer.attach(gameTimerCallback, 0.001); /* Blink LED every second */ + timer.attach(gameTimerCallback, 0.0005); // init SPI _spi.format(8,3); @@ -67,7 +67,7 @@ uint8_t getInput() { - return !_left + ((!_right) << 1) + ((!_A) << 4) + ((!_B) << 5); + return !_left + ((!_right) << 2) + ((!_A) << 4) + ((!_B) << 3); } void LCDCommandMode()