megadrive_test2

view 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
line source
1 #include <stdint.h>
2 #include "vdp.h"
4 uint32_t pat0[] = {
5 0x00000000,
6 0x00000000,
7 0x00000000,
8 0x00010000,
9 0x00000000,
10 0x00000000,
11 0x00000000,
12 0x00000000
13 };
15 uint32_t pat1[] = {
16 0x11111111,
17 0x11000011,
18 0x10100101,
19 0x10011001,
20 0x10011001,
21 0x10100101,
22 0x11000011,
23 0x11111111
24 };
26 uint32_t pat2[] = {
27 0x11111111,
28 0x10011001,
29 0x10011001,
30 0x11111111,
31 0x11111111,
32 0x10011001,
33 0x10011001,
34 0x11111111
35 };
37 void load_pattern(int idx, void *data);
38 void set_tile(int x, int y, int tile_idx, int palidx);
40 int main(void)
41 {
42 int i, j;
44 vdp_init();
46 vdp_set_pal_entry(0, 0, 0, 0, 0);
47 vdp_set_pal_entry(0, 1, 7, 1, 3);
48 vdp_set_bgcolor(0, 0);
50 load_pattern(0, pat0);
51 load_pattern(1, pat1);
52 load_pattern(2, pat2);
54 vdp_set_nametab_idx(VDP_PLANE_A, 6);
56 for(i=0; i<20; i++) {
57 for(j=0; j<20; j++) {
58 set_tile(j, i, 1, 0);
59 }
60 }
62 //vdp_enable_hintr(12);
63 //vdp_enable_vintr();
65 for(;;);
67 return 0;
68 }
70 /*
71 uint16_t testcol = 0x00c0;
73 void vblank_handler(void)
74 {
75 testcol = 0x00c0;
76 }
77 */
79 void load_pattern(int idx, void *data)
80 {
81 int i;
82 uint32_t *ptr = data;
83 uint16_t addr = idx << 5;
84 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
86 for(i=0; i<16; i++) {
87 VDP_PORT_DATA32 = *ptr++;
88 }
89 }
91 void set_tile(int x, int y, int tile_idx, int palidx)
92 {
93 uint16_t tile_ent, addr;
95 tile_ent = vdp_nametab_entry(tile_idx, palidx, VDP_TILE_LOW_PRIO);
97 addr = vdp_nametab_addr(6) + (y * 64 + x) * 2;
98 vdp_setup_access(addr, VDP_MEM_WRITE, VDP_MEM_VRAM);
99 VDP_PORT_DATA = tile_ent;
100 }