97c1895be7f7647790e37fbbba43332d541b3a0b
[retrocrawl] / src / game.c
1 #include <string.h>
2 #include "game.h"
3 #include "gfx.h"
4 #include "data.h"
5
6 #include "hwregs.h"     /* XXX */
7
8 #define TILE_W  64
9 #define TILE_H  32
10
11 void draw_tile(int tid, int x, int y, int light);
12
13
14 int game_init(void)
15 {
16         REG_COLOR0 = 0x221;
17         REG_COLOR1 = 0x222;
18         REG_COLOR2 = 0x332;
19         REG_COLOR3 = 0x433;
20         REG_COLOR4 = 0x543;
21         REG_COLOR5 = 0x554;
22         REG_COLOR6 = 0x654;
23         REG_COLOR7 = 0x765;
24
25         return 0;
26 }
27
28 #define XTILES  5
29 #define YTILES  13
30
31 void game_draw(void)
32 {
33         int i, j, xoffs, yoffs, ntiles;
34
35         yoffs = 0;
36         for(i=0; i<YTILES; i++) {
37                 xoffs = i & 1 ? TILE_W / 2 : 0;
38                 ntiles = i & 1 ? XTILES - 1 : XTILES;
39                 for(j=0; j<ntiles; j++) {
40                         draw_tile(0, xoffs, yoffs, 0);
41                         xoffs += TILE_W;
42                 }
43                 yoffs += TILE_H / 2;
44         }
45 }
46
47
48 void draw_tile(int tid, int x, int y, int light)
49 {
50         unsigned char *dest = bplptr[0] + (y * SCANSZ * NBPL) + x / 8;
51         unsigned char *src = test_tile;
52
53         wait_blit();
54
55         REG32_BLTCON = BLTCON_USEA | BLTCON_USEB | BLTCON_USEC | BLTCON_USED |
56                 BLTCON_LF(0xca);
57         REG32_BLTAFLWM = 0xffffffff;
58         REG_BLTAMOD = 0;
59         REG_BLTBMOD = 0;
60         REG_BLTCMOD = SCANSZ - TILE_W / 8;
61         REG_BLTDMOD = SCANSZ - TILE_W / 8;
62         REG32_BLTAPT = (intptr_t)test_tile_mask;
63         REG32_BLTBPT = (intptr_t)src;
64         REG32_BLTCPT = (intptr_t)dest;
65         REG32_BLTDPT = (intptr_t)dest;
66         REG_BLTSIZE = BLTSIZE(TILE_W, TILE_H * NBPL);
67 }