megadrive_test2

view src/main.c @ 5:ea70f3da150f

color cycling tunnel
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 20 Jun 2017 06:08:58 +0300
parents 72ab63f262bf
children df2c6b3c6f2e
line source
1 #include <stdint.h>
2 #include "vdp.h"
3 #include "tun_data.h"
5 #define NAMETAB_A 6
6 #define NAMETAB_B 6
8 void load_pattern(int idx, void *data);
9 void set_tile(int nametab_idx, int x, int y, int tile_idx, int palidx);
11 #define CYCLE_BEG 1
12 #define CYCLE_END 14
13 static uint16_t pal[16] = {
14 VDP_PACK_RGB(0, 0, 0), /* 0: fixed */
15 VDP_PACK_RGB(0, 0, 0), /* 1: cycle start */
16 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
17 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
18 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
19 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
20 VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0),
21 VDP_PACK_RGB(0, 0, 0), /* 12: \ */
22 VDP_PACK_RGB(7, 0, 3), /* 13: > beam */
23 VDP_PACK_RGB(0, 0, 0), /* 14: / cycle end */
24 VDP_PACK_RGB(7, 0, 3) /* 15: fixed */
25 };
28 int main(void)
29 {
30 int i, j;
32 vdp_init();
34 vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) | VDP_MODE2_V30CELL);
36 vdp_begin_palette(0, 0);
37 for(i=0; i<16; i++) {
38 VDP_PORT_DATA = pal[i];
39 }
40 vdp_set_bgcolor(0, 0);
42 for(i=0; i<tun_xtiles * tun_ytiles; i++) {
43 load_pattern(i, tun_tiles[i]);
44 }
46 vdp_set_nametab_idx(VDP_PLANE_A, NAMETAB_A);
47 vdp_set_nametab_idx(VDP_PLANE_B, NAMETAB_B);
49 for(i=0; i<tun_ytiles; i++) {
50 for(j=0; j<tun_xtiles; j++) {
51 set_tile(NAMETAB_A, j, i, i * tun_xtiles + j, 0);
52 }
53 }
55 //vdp_enable_hintr(12);
56 vdp_enable_vintr();
58 for(;;);
60 return 0;
61 }
63 void load_pattern(int idx, void *data)
64 {
65 int i;
66 uint32_t *ptr = data;
67 uint16_t addr = idx << 5;
68 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
70 for(i=0; i<16; i++) {
71 VDP_PORT_DATA32 = *ptr++;
72 }
73 }
75 void set_tile(int nametab_idx, int x, int y, int tile_idx, int palidx)
76 {
77 uint16_t tile_ent, addr;
79 tile_ent = vdp_nametab_entry(tile_idx, palidx, VDP_TILE_LOW_PRIO);
81 addr = vdp_nametab_addr(nametab_idx) + (y * 64 + x) * 2;
82 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
83 VDP_PORT_DATA = tile_ent;
84 }
86 void vblank_handler(void)
87 {
88 int idx = CYCLE_BEG;
89 uint16_t first = pal[idx];
91 vdp_begin_palette(0, idx);
92 while(idx < CYCLE_END) {
93 pal[idx] = pal[idx + 1];
94 VDP_PORT_DATA = pal[idx];
95 ++idx;
96 }
97 pal[idx] = first;
98 VDP_PORT_DATA = pal[idx];
99 }