start using GTE, rotate triangle with MVMVA cmd
[psx_test1] / src / main.c
1 #include "gpu.h"
2 #include "gte.h"
3 #include "psxregs.h"
4 #include "sintab.h"
5
6 static struct gpu_gvert triangle[] = {{0xff0000}, {0x00ff00}, {0x0000ff}};
7
8 static struct gte_svector svtri[] = {
9         {-0x1000, -0x800}, {0, 0x1000}, {0x1000, -0x800}
10 };
11
12 int dbg;
13
14 int main(void)
15 {
16         int i;
17         unsigned int frame = 0;
18         int16_t rotmat[9] = {0x1000, 0, 0, 0, 0x1000, 0, 0, 0, 0x1000};
19         int trans[3] = {160, 120, 0};
20         int resv[3];
21
22         gte_init();
23
24         gpu_reset();
25         gpu_setmode(320, 264, 15, 50);
26         gpu_display(1);
27
28         REG_GP0 = GPCMD(GP0_TEXPG) | TEXPG_DRAWDISP | TEXPG_DITHER;
29
30         gpu_cliprect(0, 0, 320, 264);
31         gpu_origin(0, 0);
32
33         for(;;) {
34                 rotmat[0] = rotmat[4] = COS(frame);
35                 rotmat[1] = SIN(frame);
36                 rotmat[3] = -SIN(frame);
37
38                 gte_loadrot(rotmat);
39                 //gte_loadtrans(trans);
40                 for(i=0; i<3; i++) {
41                         gte_loadsvec0(svtri + i);
42                         gte_cmd_rot();
43                         gte_getvec(resv);
44
45                         triangle[i].x = (resv[0] >> 6) + 160;
46                         triangle[i].y = (resv[1] >> 6) + 130;
47                 }
48
49                 gpu_fillrect(0, 0, 320, 264, 0x202020);
50
51                 gpu_draw_gouraud(GP0_GTRI, triangle, 3);
52
53                 for(i=0; i<100000; i++) {
54                         asm volatile("nop; nop; nop; nop");
55                 }
56
57                 frame++;
58         }
59         return 0;
60 }