rev |
line source |
nuclear@1
|
1 #include <stdint.h>
|
nuclear@0
|
2 #include "vdp.h"
|
nuclear@6
|
3 #include "io.h"
|
nuclear@5
|
4 #include "tun_data.h"
|
nuclear@0
|
5
|
nuclear@5
|
6 #define NAMETAB_A 6
|
nuclear@5
|
7 #define NAMETAB_B 6
|
nuclear@5
|
8
|
nuclear@5
|
9 void load_pattern(int idx, void *data);
|
nuclear@5
|
10 void set_tile(int nametab_idx, int x, int y, int tile_idx, int palidx);
|
nuclear@5
|
11
|
nuclear@5
|
12 #define CYCLE_BEG 1
|
nuclear@5
|
13 #define CYCLE_END 14
|
nuclear@5
|
14 static uint16_t pal[16] = {
|
nuclear@5
|
15 VDP_PACK_RGB(0, 0, 0), /* 0: fixed */
|
nuclear@5
|
16 VDP_PACK_RGB(0, 0, 0), /* 1: cycle start */
|
nuclear@5
|
17 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
|
nuclear@5
|
18 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
|
nuclear@5
|
19 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
|
nuclear@5
|
20 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
|
nuclear@5
|
21 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
|
nuclear@5
|
22 VDP_PACK_RGB(0, 0, 0), /* 12: \ */
|
nuclear@5
|
23 VDP_PACK_RGB(7, 0, 3), /* 13: > beam */
|
nuclear@5
|
24 VDP_PACK_RGB(0, 0, 0), /* 14: / cycle end */
|
nuclear@5
|
25 VDP_PACK_RGB(7, 0, 3) /* 15: fixed */
|
nuclear@4
|
26 };
|
nuclear@4
|
27
|
nuclear@4
|
28
|
nuclear@0
|
29 int main(void)
|
nuclear@0
|
30 {
|
nuclear@4
|
31 int i, j;
|
nuclear@4
|
32
|
nuclear@0
|
33 vdp_init();
|
nuclear@0
|
34
|
nuclear@6
|
35 if(IO_REG_VER & IO_VER_PAL) {
|
nuclear@6
|
36 vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) | VDP_MODE2_V30CELL);
|
nuclear@6
|
37 }
|
nuclear@5
|
38
|
nuclear@5
|
39 vdp_begin_palette(0, 0);
|
nuclear@5
|
40 for(i=0; i<16; i++) {
|
nuclear@5
|
41 VDP_PORT_DATA = pal[i];
|
nuclear@5
|
42 }
|
nuclear@4
|
43 vdp_set_bgcolor(0, 0);
|
nuclear@0
|
44
|
nuclear@5
|
45 for(i=0; i<tun_xtiles * tun_ytiles; i++) {
|
nuclear@5
|
46 load_pattern(i, tun_tiles[i]);
|
nuclear@5
|
47 }
|
nuclear@4
|
48
|
nuclear@5
|
49 vdp_set_nametab_idx(VDP_PLANE_A, NAMETAB_A);
|
nuclear@5
|
50 vdp_set_nametab_idx(VDP_PLANE_B, NAMETAB_B);
|
nuclear@4
|
51
|
nuclear@5
|
52 for(i=0; i<tun_ytiles; i++) {
|
nuclear@5
|
53 for(j=0; j<tun_xtiles; j++) {
|
nuclear@5
|
54 set_tile(NAMETAB_A, j, i, i * tun_xtiles + j, 0);
|
nuclear@4
|
55 }
|
nuclear@4
|
56 }
|
nuclear@4
|
57
|
nuclear@4
|
58 //vdp_enable_hintr(12);
|
nuclear@5
|
59 vdp_enable_vintr();
|
nuclear@1
|
60
|
nuclear@0
|
61 for(;;);
|
nuclear@0
|
62
|
nuclear@0
|
63 return 0;
|
nuclear@0
|
64 }
|
nuclear@1
|
65
|
nuclear@4
|
66 void load_pattern(int idx, void *data)
|
nuclear@4
|
67 {
|
nuclear@4
|
68 int i;
|
nuclear@4
|
69 uint32_t *ptr = data;
|
nuclear@4
|
70 uint16_t addr = idx << 5;
|
nuclear@4
|
71 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
|
nuclear@4
|
72
|
nuclear@4
|
73 for(i=0; i<16; i++) {
|
nuclear@4
|
74 VDP_PORT_DATA32 = *ptr++;
|
nuclear@4
|
75 }
|
nuclear@4
|
76 }
|
nuclear@4
|
77
|
nuclear@5
|
78 void set_tile(int nametab_idx, int x, int y, int tile_idx, int palidx)
|
nuclear@4
|
79 {
|
nuclear@4
|
80 uint16_t tile_ent, addr;
|
nuclear@4
|
81
|
nuclear@4
|
82 tile_ent = vdp_nametab_entry(tile_idx, palidx, VDP_TILE_LOW_PRIO);
|
nuclear@4
|
83
|
nuclear@5
|
84 addr = vdp_nametab_addr(nametab_idx) + (y * 64 + x) * 2;
|
nuclear@4
|
85 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
|
nuclear@4
|
86 VDP_PORT_DATA = tile_ent;
|
nuclear@4
|
87 }
|
nuclear@5
|
88
|
nuclear@5
|
89 void vblank_handler(void)
|
nuclear@5
|
90 {
|
nuclear@5
|
91 int idx = CYCLE_BEG;
|
nuclear@5
|
92 uint16_t first = pal[idx];
|
nuclear@5
|
93
|
nuclear@5
|
94 vdp_begin_palette(0, idx);
|
nuclear@5
|
95 while(idx < CYCLE_END) {
|
nuclear@5
|
96 pal[idx] = pal[idx + 1];
|
nuclear@5
|
97 VDP_PORT_DATA = pal[idx];
|
nuclear@5
|
98 ++idx;
|
nuclear@5
|
99 }
|
nuclear@5
|
100 pal[idx] = first;
|
nuclear@5
|
101 VDP_PORT_DATA = pal[idx];
|
nuclear@5
|
102 }
|