serial debugging fail
[retrocrawl] / src / game.c
1 #include <stdio.h>
2 #include <string.h>
3 #include "game.h"
4 #include "gfx.h"
5 #include "copper.h"
6 #include "data.h"
7 #include "sprite.h"
8
9 #include "hwregs.h"     /* XXX */
10
11 #define TILE_W  64
12 #define TILE_H  32
13
14 void draw_tile(int tid, int x, int y, int light);
15
16 static uint16_t *sprdata[NUM_HWSPRITES];
17 static uint16_t *sprdata2[NUM_HWSPRITES];
18
19 /* hardcoded test sprite */
20 static struct sprite test_sprite;
21 static struct sprite test_sprite2;
22
23 int game_init(void)
24 {
25         int i;
26
27         printf("hello world\n");
28
29         REG_COLOR0 = 0x221;
30         REG_COLOR1 = 0x222;
31         REG_COLOR2 = 0x332;
32         REG_COLOR3 = 0x433;
33         REG_COLOR4 = 0x543;
34         REG_COLOR5 = 0x554;
35         REG_COLOR6 = 0x654;
36         REG_COLOR7 = 0x765;
37
38         for(i=0; i<16; i++) {
39                 REG_COLOR_PTR[i + 16] = sprpal[i];
40         }
41
42         sprdata[0] = sprdata2[0] = spr0a;
43         sprdata[1] = sprdata2[1] = spr0b;
44         sprdata[2] = sprdata2[2] = spr1a;
45         sprdata[3] = sprdata2[3] = spr1b;
46         sprdata[4] = sprdata2[4] = spr2a;
47         sprdata[5] = sprdata2[5] = spr2b;
48
49         test_sprite.width = test_sprite.height = 48;
50         test_sprite.origx = 24;
51         test_sprite.origy = 24;
52         test_sprite.img = test_sprite.mask = 0;
53         test_sprite.hwslices = 3;
54         for(i=0; i<8; i++) {
55                 test_sprite.hwspr[i] = i < 6 ? sprdata[i] : 0;
56         }
57
58         test_sprite2 = test_sprite;
59         for(i=0; i<8; i++) {
60                 test_sprite2.hwspr[i] = i < 6 ? sprdata2[i] : 0;
61         }
62
63         return 0;
64 }
65
66 #define XTILES  5
67 #define YTILES  13
68
69 void game_draw(void)
70 {
71         int i, j, xoffs, yoffs, ntiles;
72
73         yoffs = 0;
74         for(i=0; i<YTILES; i++) {
75                 xoffs = i & 1 ? TILE_W / 2 : 0;
76                 ntiles = i & 1 ? XTILES - 1 : XTILES;
77                 for(j=0; j<ntiles; j++) {
78                         draw_tile(0, xoffs, yoffs, 0);
79                         xoffs += TILE_W;
80                 }
81                 yoffs += TILE_H / 2;
82         }
83
84         begin_sprites();
85         draw_sprite(&test_sprite, 160, 80);
86         draw_sprite(&test_sprite2, 160, 160);
87         end_sprites();
88 }
89
90
91 void draw_tile(int tid, int x, int y, int light)
92 {
93         unsigned char *dest = bplptr[0] + (y * SCANSZ * NBPL) + x / 8;
94         unsigned char *src = test_tile;
95
96         wait_blit();
97
98         REG32_BLTCON = BLTCON_USEA | BLTCON_USEB | BLTCON_USEC | BLTCON_USED |
99                 BLTCON_LF(0xca);
100         REG32_BLTAFLWM = 0xffffffff;
101         REG_BLTAMOD = 0;
102         REG_BLTBMOD = 0;
103         REG_BLTCMOD = SCANSZ - TILE_W / 8;
104         REG_BLTDMOD = SCANSZ - TILE_W / 8;
105         REG32_BLTAPT = (intptr_t)test_tile_mask;
106         REG32_BLTBPT = (intptr_t)src;
107         REG32_BLTCPT = (intptr_t)dest;
108         REG32_BLTDPT = (intptr_t)dest;
109         REG_BLTSIZE = BLTSIZE(TILE_W, TILE_H * NBPL);
110 }