gba-trycatch

diff src/main.c @ 4:78d1664c2443

- fixed sin_x16/cos_x16 - added fixed point header
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Jun 2014 03:04:56 +0300
parents 5143908d0220
children 850be43b3135
line diff
     1.1 --- a/src/main.c	Sat Jun 14 01:56:58 2014 +0300
     1.2 +++ b/src/main.c	Sat Jun 14 03:04:56 2014 +0300
     1.3 @@ -1,3 +1,4 @@
     1.4 +#include <math.h>
     1.5  #include <stdint.h>
     1.6  #include "gbasys.h"
     1.7  #include "logger.h"
     1.8 @@ -49,6 +50,8 @@
     1.9  
    1.10  static int offset;
    1.11  
    1.12 +#define X16INT(x)	((x) << 16)
    1.13 +
    1.14  static void draw(void)
    1.15  {
    1.16  	int i, j;
    1.17 @@ -58,16 +61,12 @@
    1.18  	clear_buffer(back_buffer, 0);
    1.19  
    1.20  	for(i=0; i<WIDTH; i++) {
    1.21 -		int16_t x = 2 * (i - offset) * SINLUT_SIZE / WIDTH;
    1.22 -		int16_t y = sin_int(x);
    1.23 -		y = HEIGHT - (y * (HEIGHT / 2) / SINLUT_SCALE / 2 + HEIGHT / 2);
    1.24 +		float x = M_PI * 4.0 * (float)(i - offset) / (float)WIDTH;/*((M_PI_X16 * ((2 * (i - offset)) << 8)) << 8) / WIDTH;*/
    1.25 +		float y = (HEIGHT / 4.0) * ((float)sin_x16(x * 65536.0) / 65536.0);
    1.26  
    1.27 -		pixels[y * WIDTH + i] = RGB(255, 0, 0);
    1.28 +		int iy = HEIGHT - (y + HEIGHT / 2.0);
    1.29  
    1.30 -		y = cos_int(x);
    1.31 -		y = HEIGHT - (y * (HEIGHT / 2) / SINLUT_SCALE / 2 + HEIGHT / 2);
    1.32 -
    1.33 -		pixels[y * WIDTH + i] = RGB(0, 255, 0);
    1.34 +		pixels[iy * WIDTH + i] = RGB(255, 0, 0);
    1.35  
    1.36  		if(i == offset) {
    1.37  			for(j=0; j<HEIGHT; j++) {
    1.38 @@ -83,12 +82,10 @@
    1.39  {
    1.40  	switch(key) {
    1.41  	case KEY_LEFT:
    1.42 -		logmsg(LOG_DBG, "foo! (%d)\n", offset);
    1.43  		--offset;
    1.44  		break;
    1.45  
    1.46  	case KEY_RIGHT:
    1.47 -		logmsg(LOG_DBG, "bar! (%d)\n", offset);
    1.48  		++offset;
    1.49  		break;
    1.50