nds_test2

diff src/main.c @ 2:dd8c9847bae9

cube
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 29 Jan 2018 14:40:45 +0200
parents d625ba001a62
children
line diff
     1.1 --- a/src/main.c	Mon Jan 29 03:48:05 2018 +0200
     1.2 +++ b/src/main.c	Mon Jan 29 14:40:45 2018 +0200
     1.3 @@ -3,6 +3,7 @@
     1.4  #include "dsregs.h"
     1.5  #include "ds3.h"
     1.6  
     1.7 +static void draw_cube(void);
     1.8  static void xorpat(void *addr, int xsz, int ysz);
     1.9  
    1.10  static void *vram = VRAM_LCDC_PTR;
    1.11 @@ -53,37 +54,39 @@
    1.12  
    1.13  	ds3_enable(DS3_POLYGON_SMOOTH);
    1.14  
    1.15 -	REG_POLYGON_ATTR = 0x001f00c0;	/* alpha = 31, cull none */
    1.16 +	REG_POLYGON_ATTR = 0x001f0080;	/* alpha = 31, cull back */
    1.17  
    1.18  	ds3_matrix_mode(DS3_PROJECTION);
    1.19  	ds3_load_identity();
    1.20 -	ds3_scale(49152, 65536, 65536);
    1.21 +	/*ds3_ortho(-87381, 87381, -65536, 65536, -65536, 65536);*/
    1.22 +	/*ds3_orthof(-1.3333, 1.33333, -1, 1, -1, 1);*/
    1.23 +	ds3_perspectivef(45, 1.33333, 1.0, 100.0);
    1.24  
    1.25  	for(;;) {
    1.26  		int idx = frame & 0xff;
    1.27  		int32_t scale = (sintab[(frame >> 1) & 0xff] >> 9) + 204;
    1.28  		int32_t sa = ((sintab[idx] >> 8) * scale) >> 8;
    1.29  		int32_t ca = ((costab[idx] >> 8) * scale) >> 8;
    1.30 -
    1.31  		int32_t x = ca * -128 + sa * -96 + (128 << 8);
    1.32  		int32_t y = -sa * -128 + ca * -96 + (96 << 8);
    1.33  
    1.34 -		m[0] = ca << 8; m[1] = sa << 8;
    1.35 -		m[4] = -sa << 8; m[5] = ca << 8;
    1.36 +		ds3_matrix_mode(DS3_MODELVIEW);
    1.37 +		ds3_load_identity();
    1.38 +		ds3_translate(0, 0, -0x30000);
    1.39  
    1.40 -		ds3_matrix_mode(DS3_MODELVIEW);
    1.41 -		ds3_load_matrix(m);
    1.42 +		m[0] = 0x10000;
    1.43 +		m[2] = m[8] = 0;
    1.44 +		m[5] = costab[idx]; m[6] = sintab[idx];
    1.45 +		m[9] = -sintab[idx]; m[10] = costab[idx];
    1.46 +		ds3_mult_matrix(m);
    1.47  
    1.48 -		ds3_begin(DS3_QUADS);
    1.49 -		ds3_color(RGB15(31, 0, 0));
    1.50 -		ds3_vertex3(-0x8000, -0x8000, 0);
    1.51 -		ds3_color(RGB15(0, 31, 0));
    1.52 -		ds3_vertex3(0x8000, -0x8000, 0);
    1.53 -		ds3_color(RGB15(0, 0, 31));
    1.54 -		ds3_vertex3(0x8000, 0x8000, 0);
    1.55 -		ds3_color(RGB15(31, 0, 31));
    1.56 -		ds3_vertex3(-0x8000, 0x8000, 0);
    1.57 -		ds3_end();
    1.58 +		m[5] = 0x10000;
    1.59 +		m[6] = m[9] = 0;
    1.60 +		m[0] = costab[idx]; m[2] = -sintab[idx];
    1.61 +		m[8] = sintab[idx];
    1.62 +		ds3_mult_matrix(m);
    1.63 +
    1.64 +		draw_cube();
    1.65  
    1.66  		ds3_swap_buffers();
    1.67  		while(REG_VCOUNT < 192);
    1.68 @@ -100,6 +103,43 @@
    1.69  	return 0;
    1.70  }
    1.71  
    1.72 +#define VOFFS	0x8000
    1.73 +static void draw_cube(void)
    1.74 +{
    1.75 +	ds3_begin(DS3_QUADS);
    1.76 +	ds3_color(RGB15(31, 0, 0));
    1.77 +	ds3_vertex3(-VOFFS, -VOFFS, VOFFS);
    1.78 +	ds3_vertex3(VOFFS, -VOFFS, VOFFS);
    1.79 +	ds3_vertex3(VOFFS, VOFFS, VOFFS);
    1.80 +	ds3_vertex3(-VOFFS, VOFFS, VOFFS);
    1.81 +	ds3_color(RGB15(0, 31, 0));
    1.82 +	ds3_vertex3(VOFFS, -VOFFS, VOFFS);
    1.83 +	ds3_vertex3(VOFFS, -VOFFS, -VOFFS);
    1.84 +	ds3_vertex3(VOFFS, VOFFS, -VOFFS);
    1.85 +	ds3_vertex3(VOFFS, VOFFS, VOFFS);
    1.86 +	ds3_color(RGB15(0, 0, 31));
    1.87 +	ds3_vertex3(VOFFS, -VOFFS, -VOFFS);
    1.88 +	ds3_vertex3(-VOFFS, -VOFFS, -VOFFS);
    1.89 +	ds3_vertex3(-VOFFS, VOFFS, -VOFFS);
    1.90 +	ds3_vertex3(VOFFS, VOFFS, -VOFFS);
    1.91 +	ds3_color(RGB15(31, 31, 0));
    1.92 +	ds3_vertex3(-VOFFS, -VOFFS, -VOFFS);
    1.93 +	ds3_vertex3(-VOFFS, -VOFFS, VOFFS);
    1.94 +	ds3_vertex3(-VOFFS, VOFFS, VOFFS);
    1.95 +	ds3_vertex3(-VOFFS, VOFFS, -VOFFS);
    1.96 +	ds3_color(RGB15(31, 0, 31));
    1.97 +	ds3_vertex3(-VOFFS, VOFFS, VOFFS);
    1.98 +	ds3_vertex3(VOFFS, VOFFS, VOFFS);
    1.99 +	ds3_vertex3(VOFFS, VOFFS, -VOFFS);
   1.100 +	ds3_vertex3(-VOFFS, VOFFS, -VOFFS);
   1.101 +	ds3_color(RGB15(0, 31, 31));
   1.102 +	ds3_vertex3(VOFFS, -VOFFS, -VOFFS);
   1.103 +	ds3_vertex3(VOFFS, -VOFFS, VOFFS);
   1.104 +	ds3_vertex3(-VOFFS, -VOFFS, VOFFS);
   1.105 +	ds3_vertex3(-VOFFS, -VOFFS, -VOFFS);
   1.106 +	ds3_end();
   1.107 +}
   1.108 +
   1.109  static void xorpat(void *addr, int xsz, int ysz)
   1.110  {
   1.111  	int i, j;