megadrive_test2
diff 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 diff
1.1 --- a/src/main.c Mon Jun 19 08:02:51 2017 +0300 1.2 +++ b/src/main.c Tue Jun 20 06:08:58 2017 +0300 1.3 @@ -1,41 +1,29 @@ 1.4 #include <stdint.h> 1.5 #include "vdp.h" 1.6 +#include "tun_data.h" 1.7 1.8 -uint32_t pat0[] = { 1.9 - 0x00000000, 1.10 - 0x00000000, 1.11 - 0x00000000, 1.12 - 0x00010000, 1.13 - 0x00000000, 1.14 - 0x00000000, 1.15 - 0x00000000, 1.16 - 0x00000000 1.17 +#define NAMETAB_A 6 1.18 +#define NAMETAB_B 6 1.19 + 1.20 +void load_pattern(int idx, void *data); 1.21 +void set_tile(int nametab_idx, int x, int y, int tile_idx, int palidx); 1.22 + 1.23 +#define CYCLE_BEG 1 1.24 +#define CYCLE_END 14 1.25 +static uint16_t pal[16] = { 1.26 + VDP_PACK_RGB(0, 0, 0), /* 0: fixed */ 1.27 + VDP_PACK_RGB(0, 0, 0), /* 1: cycle start */ 1.28 + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), 1.29 + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), 1.30 + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), 1.31 + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), 1.32 + VDP_PACK_RGB(0, 0, 0), VDP_PACK_RGB(0, 0, 0), 1.33 + VDP_PACK_RGB(0, 0, 0), /* 12: \ */ 1.34 + VDP_PACK_RGB(7, 0, 3), /* 13: > beam */ 1.35 + VDP_PACK_RGB(0, 0, 0), /* 14: / cycle end */ 1.36 + VDP_PACK_RGB(7, 0, 3) /* 15: fixed */ 1.37 }; 1.38 1.39 -uint32_t pat1[] = { 1.40 - 0x11111111, 1.41 - 0x11000011, 1.42 - 0x10100101, 1.43 - 0x10011001, 1.44 - 0x10011001, 1.45 - 0x10100101, 1.46 - 0x11000011, 1.47 - 0x11111111 1.48 -}; 1.49 - 1.50 -uint32_t pat2[] = { 1.51 - 0x11111111, 1.52 - 0x10011001, 1.53 - 0x10011001, 1.54 - 0x11111111, 1.55 - 0x11111111, 1.56 - 0x10011001, 1.57 - 0x10011001, 1.58 - 0x11111111 1.59 -}; 1.60 - 1.61 -void load_pattern(int idx, void *data); 1.62 -void set_tile(int x, int y, int tile_idx, int palidx); 1.63 1.64 int main(void) 1.65 { 1.66 @@ -43,39 +31,35 @@ 1.67 1.68 vdp_init(); 1.69 1.70 - vdp_set_pal_entry(0, 0, 0, 0, 0); 1.71 - vdp_set_pal_entry(0, 1, 7, 1, 3); 1.72 + vdp_setreg(VDP_REG_MODE2, vdp_getreg(VDP_REG_MODE2) | VDP_MODE2_V30CELL); 1.73 + 1.74 + vdp_begin_palette(0, 0); 1.75 + for(i=0; i<16; i++) { 1.76 + VDP_PORT_DATA = pal[i]; 1.77 + } 1.78 vdp_set_bgcolor(0, 0); 1.79 1.80 - load_pattern(0, pat0); 1.81 - load_pattern(1, pat1); 1.82 - load_pattern(2, pat2); 1.83 + for(i=0; i<tun_xtiles * tun_ytiles; i++) { 1.84 + load_pattern(i, tun_tiles[i]); 1.85 + } 1.86 1.87 - vdp_set_nametab_idx(VDP_PLANE_A, 6); 1.88 + vdp_set_nametab_idx(VDP_PLANE_A, NAMETAB_A); 1.89 + vdp_set_nametab_idx(VDP_PLANE_B, NAMETAB_B); 1.90 1.91 - for(i=0; i<20; i++) { 1.92 - for(j=0; j<20; j++) { 1.93 - set_tile(j, i, 1, 0); 1.94 + for(i=0; i<tun_ytiles; i++) { 1.95 + for(j=0; j<tun_xtiles; j++) { 1.96 + set_tile(NAMETAB_A, j, i, i * tun_xtiles + j, 0); 1.97 } 1.98 } 1.99 1.100 //vdp_enable_hintr(12); 1.101 - //vdp_enable_vintr(); 1.102 + vdp_enable_vintr(); 1.103 1.104 for(;;); 1.105 1.106 return 0; 1.107 } 1.108 1.109 -/* 1.110 -uint16_t testcol = 0x00c0; 1.111 - 1.112 -void vblank_handler(void) 1.113 -{ 1.114 - testcol = 0x00c0; 1.115 -} 1.116 -*/ 1.117 - 1.118 void load_pattern(int idx, void *data) 1.119 { 1.120 int i; 1.121 @@ -88,13 +72,28 @@ 1.122 } 1.123 } 1.124 1.125 -void set_tile(int x, int y, int tile_idx, int palidx) 1.126 +void set_tile(int nametab_idx, int x, int y, int tile_idx, int palidx) 1.127 { 1.128 uint16_t tile_ent, addr; 1.129 1.130 tile_ent = vdp_nametab_entry(tile_idx, palidx, VDP_TILE_LOW_PRIO); 1.131 1.132 - addr = vdp_nametab_addr(6) + (y * 64 + x) * 2; 1.133 + addr = vdp_nametab_addr(nametab_idx) + (y * 64 + x) * 2; 1.134 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM); 1.135 VDP_PORT_DATA = tile_ent; 1.136 } 1.137 + 1.138 +void vblank_handler(void) 1.139 +{ 1.140 + int idx = CYCLE_BEG; 1.141 + uint16_t first = pal[idx]; 1.142 + 1.143 + vdp_begin_palette(0, idx); 1.144 + while(idx < CYCLE_END) { 1.145 + pal[idx] = pal[idx + 1]; 1.146 + VDP_PORT_DATA = pal[idx]; 1.147 + ++idx; 1.148 + } 1.149 + pal[idx] = first; 1.150 + VDP_PORT_DATA = pal[idx]; 1.151 +}