megadrive_test2

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