# HG changeset patch # User John Tsiombikas # Date 1410234568 -10800 # Node ID 872e425f0e7f7102fffa9ed36b373899f3067f84 # Parent 9db99968b55e6986cfd0d4beb22cb9b0a538b893 foo diff -r 9db99968b55e -r 872e425f0e7f avrgame.c --- a/avrgame.c Tue Sep 09 04:40:47 2014 +0300 +++ b/avrgame.c Tue Sep 09 06:49:28 2014 +0300 @@ -1,4 +1,5 @@ #include +#include #include #include "dotmatrix.h" @@ -9,26 +10,71 @@ * - B3: DC * - B4: CE * - B5: RST + * - Port C[0,3]: buttons */ +enum { + BN_LEFT, + BN_RIGHT, + BN_ROT, + BN_DROP +}; + +void redraw(void); /*int lcd_stream_write(char c, FILE *fp);*/ +/*FILE stream_lcd = FDEV_SETUP_STREAM(lcd_stream_write, NULL, _FDEV_SETUP_WRITE);*/ -/*FILE stream_lcd = FDEV_SETUP_STREAM(lcd_stream_write, NULL, _FDEV_SETUP_WRITE);*/ +static int bx, by, brot; +static unsigned char fb[DM_WIDTH * DM_HEIGHT / 8]; int main(void) { /* stdout = stderr = &stream_lcd; */ + DDRC = 0; /* input */ + PORTC = 0; /* disable pull-ups */ + + /* enable pin change interrupts (PCINT2) */ + PCICR = (1 << PCIE2); + /* unmask interrupts PCINT16-19 (first 4 bits) */ + PCMSK2 = 0xf; dm_init(); - dm_test(); + + sei(); for(;;) { - _delay_ms(800); + redraw(); } return 0; } +void redraw(void) +{ +} + +ISR(PCINT2_vect) +{ + static unsigned char prev_st = 0xff; + unsigned char st = PINC; + unsigned char diff = st ^ prev_st; + + if((diff & (1 << BN_LEFT)) & ~st) { + bx -= 1; + } + if((diff & (1 << BN_RIGHT)) & ~st) { + bx += 1; + } + if((diff & (1 << BN_ROT)) & ~st) { + brot = (brot + 1) % 4; + } + if((diff & (1 << BN_DROP)) & ~st) { + /* TODO */ + } + + prev_st = st; +} + #if 0 int lcd_stream_write(char c, FILE *fp) {