avr-game

changeset 1:872e425f0e7f

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 09 Sep 2014 06:49:28 +0300
parents 9db99968b55e
children 363acf3e61d4
files avrgame.c
diffstat 1 files changed, 49 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/avrgame.c	Tue Sep 09 04:40:47 2014 +0300
     1.2 +++ b/avrgame.c	Tue Sep 09 06:49:28 2014 +0300
     1.3 @@ -1,4 +1,5 @@
     1.4  #include <avr/io.h>
     1.5 +#include <avr/interrupt.h>
     1.6  #include <util/delay.h>
     1.7  #include "dotmatrix.h"
     1.8  
     1.9 @@ -9,26 +10,71 @@
    1.10   *   - B3: DC
    1.11   *   - B4: CE
    1.12   *   - B5: RST
    1.13 + * - Port C[0,3]: buttons
    1.14   */
    1.15  
    1.16 +enum {
    1.17 +	BN_LEFT,
    1.18 +	BN_RIGHT,
    1.19 +	BN_ROT,
    1.20 +	BN_DROP
    1.21 +};
    1.22 +
    1.23 +void redraw(void);
    1.24  /*int lcd_stream_write(char c, FILE *fp);*/
    1.25 +/*FILE stream_lcd = FDEV_SETUP_STREAM(lcd_stream_write, NULL, _FDEV_SETUP_WRITE);*/
    1.26  
    1.27 -/*FILE stream_lcd = FDEV_SETUP_STREAM(lcd_stream_write, NULL, _FDEV_SETUP_WRITE);*/
    1.28 +static int bx, by, brot;
    1.29 +static unsigned char fb[DM_WIDTH * DM_HEIGHT / 8];
    1.30  
    1.31  int main(void)
    1.32  {
    1.33  	/* stdout = stderr = &stream_lcd; */
    1.34 +	DDRC = 0;	/* input */
    1.35 +	PORTC = 0;	/* disable pull-ups */
    1.36 +
    1.37 +	/* enable pin change interrupts (PCINT2) */
    1.38 +	PCICR = (1 << PCIE2);
    1.39 +	/* unmask interrupts PCINT16-19 (first 4 bits) */
    1.40 +	PCMSK2 = 0xf;
    1.41  
    1.42  	dm_init();
    1.43 -	dm_test();
    1.44 +
    1.45 +	sei();
    1.46  
    1.47  	for(;;) {
    1.48 -		_delay_ms(800);
    1.49 +		redraw();
    1.50  	}
    1.51  
    1.52  	return 0;
    1.53  }
    1.54  
    1.55 +void redraw(void)
    1.56 +{
    1.57 +}
    1.58 +
    1.59 +ISR(PCINT2_vect)
    1.60 +{
    1.61 +	static unsigned char prev_st = 0xff;
    1.62 +	unsigned char st = PINC;
    1.63 +	unsigned char diff = st ^ prev_st;
    1.64 +
    1.65 +	if((diff & (1 << BN_LEFT)) & ~st) {
    1.66 +		bx -= 1;
    1.67 +	}
    1.68 +	if((diff & (1 << BN_RIGHT)) & ~st) {
    1.69 +		bx += 1;
    1.70 +	}
    1.71 +	if((diff & (1 << BN_ROT)) & ~st) {
    1.72 +		brot = (brot + 1) % 4;
    1.73 +	}
    1.74 +	if((diff & (1 << BN_DROP)) & ~st) {
    1.75 +		/* TODO */
    1.76 +	}
    1.77 +
    1.78 +	prev_st = st;
    1.79 +}
    1.80 +
    1.81  #if 0
    1.82  int lcd_stream_write(char c, FILE *fp)
    1.83  {