megadrive_test2

annotate src/main.c @ 4:72ab63f262bf

tiles
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 19 Jun 2017 08:02:51 +0300
parents 1d35c3b3a525
children ea70f3da150f
rev   line source
nuclear@1 1 #include <stdint.h>
nuclear@0 2 #include "vdp.h"
nuclear@0 3
nuclear@4 4 uint32_t pat0[] = {
nuclear@4 5 0x00000000,
nuclear@4 6 0x00000000,
nuclear@4 7 0x00000000,
nuclear@4 8 0x00010000,
nuclear@4 9 0x00000000,
nuclear@4 10 0x00000000,
nuclear@4 11 0x00000000,
nuclear@4 12 0x00000000
nuclear@4 13 };
nuclear@4 14
nuclear@4 15 uint32_t pat1[] = {
nuclear@4 16 0x11111111,
nuclear@4 17 0x11000011,
nuclear@4 18 0x10100101,
nuclear@4 19 0x10011001,
nuclear@4 20 0x10011001,
nuclear@4 21 0x10100101,
nuclear@4 22 0x11000011,
nuclear@4 23 0x11111111
nuclear@4 24 };
nuclear@4 25
nuclear@4 26 uint32_t pat2[] = {
nuclear@4 27 0x11111111,
nuclear@4 28 0x10011001,
nuclear@4 29 0x10011001,
nuclear@4 30 0x11111111,
nuclear@4 31 0x11111111,
nuclear@4 32 0x10011001,
nuclear@4 33 0x10011001,
nuclear@4 34 0x11111111
nuclear@4 35 };
nuclear@4 36
nuclear@4 37 void load_pattern(int idx, void *data);
nuclear@4 38 void set_tile(int x, int y, int tile_idx, int palidx);
nuclear@4 39
nuclear@0 40 int main(void)
nuclear@0 41 {
nuclear@4 42 int i, j;
nuclear@4 43
nuclear@0 44 vdp_init();
nuclear@0 45
nuclear@1 46 vdp_set_pal_entry(0, 0, 0, 0, 0);
nuclear@4 47 vdp_set_pal_entry(0, 1, 7, 1, 3);
nuclear@4 48 vdp_set_bgcolor(0, 0);
nuclear@0 49
nuclear@4 50 load_pattern(0, pat0);
nuclear@4 51 load_pattern(1, pat1);
nuclear@4 52 load_pattern(2, pat2);
nuclear@4 53
nuclear@4 54 vdp_set_nametab_idx(VDP_PLANE_A, 6);
nuclear@4 55
nuclear@4 56 for(i=0; i<20; i++) {
nuclear@4 57 for(j=0; j<20; j++) {
nuclear@4 58 set_tile(j, i, 1, 0);
nuclear@4 59 }
nuclear@4 60 }
nuclear@4 61
nuclear@4 62 //vdp_enable_hintr(12);
nuclear@4 63 //vdp_enable_vintr();
nuclear@1 64
nuclear@0 65 for(;;);
nuclear@0 66
nuclear@0 67 return 0;
nuclear@0 68 }
nuclear@1 69
nuclear@4 70 /*
nuclear@1 71 uint16_t testcol = 0x00c0;
nuclear@1 72
nuclear@1 73 void vblank_handler(void)
nuclear@1 74 {
nuclear@1 75 testcol = 0x00c0;
nuclear@1 76 }
nuclear@4 77 */
nuclear@4 78
nuclear@4 79 void load_pattern(int idx, void *data)
nuclear@4 80 {
nuclear@4 81 int i;
nuclear@4 82 uint32_t *ptr = data;
nuclear@4 83 uint16_t addr = idx << 5;
nuclear@4 84 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
nuclear@4 85
nuclear@4 86 for(i=0; i<16; i++) {
nuclear@4 87 VDP_PORT_DATA32 = *ptr++;
nuclear@4 88 }
nuclear@4 89 }
nuclear@4 90
nuclear@4 91 void set_tile(int x, int y, int tile_idx, int palidx)
nuclear@4 92 {
nuclear@4 93 uint16_t tile_ent, addr;
nuclear@4 94
nuclear@4 95 tile_ent = vdp_nametab_entry(tile_idx, palidx, VDP_TILE_LOW_PRIO);
nuclear@4 96
nuclear@4 97 addr = vdp_nametab_addr(6) + (y * 64 + x) * 2;
nuclear@4 98 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
nuclear@4 99 VDP_PORT_DATA = tile_ent;
nuclear@4 100 }