gba-x3dtest

diff src/main.c @ 2:5143908d0220

fixed
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Jun 2014 01:56:42 +0300
parents b7130fe3f073
children 78d1664c2443
line diff
     1.1 --- a/src/main.c	Fri Jun 13 19:10:11 2014 +0300
     1.2 +++ b/src/main.c	Sat Jun 14 01:56:42 2014 +0300
     1.3 @@ -1,5 +1,11 @@
     1.4 +#include <stdint.h>
     1.5  #include "gbasys.h"
     1.6  #include "logger.h"
     1.7 +#include "sincos.h"
     1.8 +
     1.9 +#define GFX_MODE	VMODE_LFB_160x128_16
    1.10 +#define WIDTH		160
    1.11 +#define HEIGHT		128
    1.12  
    1.13  static void draw(void);
    1.14  static void keyb(int key, int pressed);
    1.15 @@ -14,6 +20,7 @@
    1.16  int main(void)
    1.17  {
    1.18  	gba_init();
    1.19 +
    1.20  	interrupt(INTR_KEY, keyb_intr);
    1.21  
    1.22  	set_video_mode(VMODE_LFB_160x128_16, 1);
    1.23 @@ -22,6 +29,8 @@
    1.24  	set_text_writebg(1);
    1.25  	logmsg(LOG_ALL, "please wait...\n");
    1.26  
    1.27 +	sincos_init();
    1.28 +
    1.29  	for(;;) {
    1.30  		/* process events */
    1.31  		while(evhead != evtail) {
    1.32 @@ -29,18 +38,64 @@
    1.33  			evhead = (evhead + 1) % EVQ_SIZE;
    1.34  			keyb(ev, 1);
    1.35  		}
    1.36 +
    1.37 +		/* this is needed because there's no key release interrupt (!) */
    1.38 +		keystate = get_key_state(KEY_ALL);
    1.39 +
    1.40  		draw();
    1.41  	}
    1.42  	return 0;
    1.43  }
    1.44  
    1.45 +static int offset;
    1.46 +
    1.47  static void draw(void)
    1.48  {
    1.49 +	int i, j;
    1.50 +	unsigned long msec = get_millisec();
    1.51 +	uint16_t *pixels = back_buffer->pixels;
    1.52 +
    1.53 +	clear_buffer(back_buffer, 0);
    1.54 +
    1.55 +	for(i=0; i<WIDTH; i++) {
    1.56 +		int16_t x = 2 * (i - offset) * SINLUT_SIZE / WIDTH;
    1.57 +		int16_t y = sin_int(x);
    1.58 +		y = HEIGHT - (y * (HEIGHT / 2) / SINLUT_SCALE / 2 + HEIGHT / 2);
    1.59 +
    1.60 +		pixels[y * WIDTH + i] = RGB(255, 0, 0);
    1.61 +
    1.62 +		y = cos_int(x);
    1.63 +		y = HEIGHT - (y * (HEIGHT / 2) / SINLUT_SCALE / 2 + HEIGHT / 2);
    1.64 +
    1.65 +		pixels[y * WIDTH + i] = RGB(0, 255, 0);
    1.66 +
    1.67 +		if(i == offset) {
    1.68 +			for(j=0; j<HEIGHT; j++) {
    1.69 +				pixels[j * WIDTH + i] = RGB(255, 255, 0);
    1.70 +			}
    1.71 +		}
    1.72 +	}
    1.73 +
    1.74 +	flip();
    1.75  }
    1.76  
    1.77  static void keyb(int key, int pressed)
    1.78  {
    1.79 -	static const char *keyname[] = {
    1.80 +	switch(key) {
    1.81 +	case KEY_LEFT:
    1.82 +		logmsg(LOG_DBG, "foo! (%d)\n", offset);
    1.83 +		--offset;
    1.84 +		break;
    1.85 +
    1.86 +	case KEY_RIGHT:
    1.87 +		logmsg(LOG_DBG, "bar! (%d)\n", offset);
    1.88 +		++offset;
    1.89 +		break;
    1.90 +
    1.91 +	default:
    1.92 +		break;
    1.93 +	}
    1.94 +	/*static const char *keyname[] = {
    1.95  		"A", "B", "select", "start", "right", "left", "up", "down", "RT", "LT"
    1.96  	};
    1.97  	int i;
    1.98 @@ -53,6 +108,7 @@
    1.99  	if(i < sizeof keyname / sizeof *keyname) {
   1.100  		logmsg(LOG_ALL, "key %s %s\n", keyname[i], pressed ? "pressed" : "released");
   1.101  	}
   1.102 +	*/
   1.103  }
   1.104  
   1.105  static void keyb_intr(void)