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@8
|
28 static int running = 1;
|
nuclear@8
|
29
|
nuclear@4
|
30
|
nuclear@0
|
31 int main(void)
|
nuclear@0
|
32 {
|
nuclear@4
|
33 int i, j;
|
nuclear@4
|
34
|
nuclear@0
|
35 vdp_init();
|
nuclear@0
|
36
|
nuclear@6
|
37 if(IO_REG_VER & IO_VER_PAL) {
|
nuclear@6
|
38 vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) | VDP_MODE2_V30CELL);
|
nuclear@6
|
39 }
|
nuclear@5
|
40
|
nuclear@5
|
41 vdp_begin_palette(0, 0);
|
nuclear@5
|
42 for(i=0; i<16; i++) {
|
nuclear@5
|
43 VDP_PORT_DATA = pal[i];
|
nuclear@5
|
44 }
|
nuclear@4
|
45 vdp_set_bgcolor(0, 0);
|
nuclear@0
|
46
|
nuclear@5
|
47 for(i=0; i<tun_xtiles * tun_ytiles; i++) {
|
nuclear@5
|
48 load_pattern(i, tun_tiles[i]);
|
nuclear@5
|
49 }
|
nuclear@4
|
50
|
nuclear@5
|
51 vdp_set_nametab_idx(VDP_PLANE_A, NAMETAB_A);
|
nuclear@5
|
52 vdp_set_nametab_idx(VDP_PLANE_B, NAMETAB_B);
|
nuclear@4
|
53
|
nuclear@5
|
54 for(i=0; i<tun_ytiles; i++) {
|
nuclear@5
|
55 for(j=0; j<tun_xtiles; j++) {
|
nuclear@5
|
56 set_tile(NAMETAB_A, j, i, i * tun_xtiles + j, 0);
|
nuclear@4
|
57 }
|
nuclear@4
|
58 }
|
nuclear@4
|
59
|
nuclear@4
|
60 //vdp_enable_hintr(12);
|
nuclear@5
|
61 vdp_enable_vintr();
|
nuclear@1
|
62
|
nuclear@8
|
63 for(;;) {
|
nuclear@8
|
64 uint16_t bnstate = io_readpad(0);
|
nuclear@8
|
65
|
nuclear@8
|
66 if(bnstate & IO_PAD_START) {
|
nuclear@8
|
67 running = !running;
|
nuclear@8
|
68 }
|
nuclear@8
|
69
|
nuclear@8
|
70 vdp_wait_vblank();
|
nuclear@8
|
71 }
|
nuclear@0
|
72
|
nuclear@0
|
73 return 0;
|
nuclear@0
|
74 }
|
nuclear@1
|
75
|
nuclear@4
|
76 void load_pattern(int idx, void *data)
|
nuclear@4
|
77 {
|
nuclear@4
|
78 int i;
|
nuclear@4
|
79 uint32_t *ptr = data;
|
nuclear@4
|
80 uint16_t addr = idx << 5;
|
nuclear@4
|
81 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
|
nuclear@4
|
82
|
nuclear@4
|
83 for(i=0; i<16; i++) {
|
nuclear@4
|
84 VDP_PORT_DATA32 = *ptr++;
|
nuclear@4
|
85 }
|
nuclear@4
|
86 }
|
nuclear@4
|
87
|
nuclear@5
|
88 void set_tile(int nametab_idx, int x, int y, int tile_idx, int palidx)
|
nuclear@4
|
89 {
|
nuclear@4
|
90 uint16_t tile_ent, addr;
|
nuclear@4
|
91
|
nuclear@4
|
92 tile_ent = vdp_nametab_entry(tile_idx, palidx, VDP_TILE_LOW_PRIO);
|
nuclear@4
|
93
|
nuclear@5
|
94 addr = vdp_nametab_addr(nametab_idx) + (y * 64 + x) * 2;
|
nuclear@4
|
95 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
|
nuclear@4
|
96 VDP_PORT_DATA = tile_ent;
|
nuclear@4
|
97 }
|
nuclear@5
|
98
|
nuclear@5
|
99 void vblank_handler(void)
|
nuclear@5
|
100 {
|
nuclear@5
|
101 int idx = CYCLE_BEG;
|
nuclear@8
|
102 uint16_t first;
|
nuclear@8
|
103
|
nuclear@8
|
104 if(!running) return;
|
nuclear@8
|
105
|
nuclear@8
|
106 first = pal[idx];
|
nuclear@5
|
107
|
nuclear@5
|
108 vdp_begin_palette(0, idx);
|
nuclear@5
|
109 while(idx < CYCLE_END) {
|
nuclear@5
|
110 pal[idx] = pal[idx + 1];
|
nuclear@5
|
111 VDP_PORT_DATA = pal[idx];
|
nuclear@5
|
112 ++idx;
|
nuclear@5
|
113 }
|
nuclear@5
|
114 pal[idx] = first;
|
nuclear@5
|
115 VDP_PORT_DATA = pal[idx];
|
nuclear@5
|
116 }
|