megadrive_test1

view src/vdp.h @ 7:8253942b0a1a

in the middle of something
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 19 Feb 2017 14:00:26 +0200
parents 862f8a034cae
children
line source
1 #ifndef VDP_H_
2 #define VDP_H_
4 #include <stdint.h>
6 #define VDP_PORT_DATA (*(volatile uint16_t*)0xc00000)
7 #define VDP_PORT_DATA32 (*(volatile uint32_t*)0xc00000)
8 #define VDP_PORT_CTL (*(volatile uint16_t*)0xc00004)
9 #define VDP_PORT_CTL32 (*(volatile uint32_t*)0xc00004)
10 #define VDP_PORT_HVCOUNT (*(volatile uint16_t*)0xc00008)
11 #define VDP_PORT_PSG (*(volatile uint16_t*)0xc00010)
13 /* registers */
14 #define VDP_REG_MSET1 0
15 #define VDP_REG_MSET2 1
16 #define VDP_REG_PADDR_A 2
17 #define VDP_REG_PADDR_WIN 3
18 #define VDP_REG_PADDR_B 4
19 #define VDP_REG_SPRITE 5
20 #define VDP_REG_BGCOLOR 7
21 #define VDP_REG_HINT 10
22 #define VDP_REG_MSET3 11
23 #define VDP_REG_MSET4 12
24 #define VDP_REG_HSCROLL 13
25 #define VDP_REG_AUTOINC 15
26 #define VDP_REG_SCROLL_SIZE 16
27 #define VDP_REG_WINXPOS 17
28 #define VDP_REG_WINYPOS 18
29 #define VDP_REG_DMALEN_LOW 19
30 #define VDP_REG_DMALEN_HIGH 20
31 #define VDP_REG_DMA_SADDR_LOW 21
32 #define VDP_REG_DMA_SADDR_MID 22
33 #define VDP_REG_DMA_SADDR_HIGH 23
35 /* shadow copy of any register we set */
36 unsigned char vdp_shadow_reg[24];
38 /* control register read flags */
39 #define VDP_CTL_PAL_BIT 0x0001
40 #define VDP_CTL_HBLANK_BIT 0x0002
41 #define VDP_CTL_VBLANK_BIT 0x0004
42 #define VDP_CTL_DT3_BIT 0x0008
43 #define VDP_CTL_ODD_FRAME_BIT 0x0010
44 #define VDP_CTL_COLIDE_BIT 0x0020
45 #define VDP_CTL_SPRITE_OVF_BIT 0x0040
46 #define VDP_CTL_FRAME_BIT 0x0080
47 #define VDP_CTL_FIFO_FULL_BIT 0x0100
48 #define VDP_CTL_FIFO_EMPTY_BIT 0x0200
50 /* control register write flags (RSET) */
51 #define VDP_CTL_REGSEL_MASK 0x1f00
52 #define VDP_CTL_DATA_MASK 0x00ff
54 #define VDP_RSET(reg, val) \
55 (0x8000ul | (VDP_CTL_REGSEL_MASK & ((uint16_t)(reg) << 8)) | \
56 (VDP_CTL_DATA_MASK & (uint16_t)(val)))
58 #define VDP_SET_REG(reg, val) \
59 do { VDP_PORT_CTL = vdp_shadow_reg[reg] = VDP_RSET(reg, val); } while(0)
60 #define VDP_SET_REG_NOSHADOW(reg, val) \
61 do { VDP_PORT_CTL = VDP_RSET(reg, val); } while(0)
63 #define VDP_MSET1_BASE 4
64 #define VDP_MSET1_HVCNT_BIT 0x02
65 #define VDP_MSET1_HINTR_BIT 0x10
67 #define VDP_MSET2_BASE 4
68 #define VDP_MSET2_30CELL_BIT 0x08
69 #define VDP_MSET2_DMA_BIT 0x10
70 #define VDP_MSET2_VINTR_BIT 0x20
71 #define VDP_MSET2_DISP_BIT 0x40
72 #define VDP_MSET2_XVRAM_BIT 0x80
74 #define VDP_MODE_WR_BIT 1
76 #define VDP_VRAM_WR 1
77 #define VDP_CRAM_WR 3
79 #define VDP_DMA_MEM_VRAM 0
80 #define VDP_DMA_VRAM_FILL 0x80
81 #define VDP_DMA_VRAM_COPY 0xc0
83 #define VDP_ADDRSET(addr, mode) /* TODO */
85 #define VDP_CRAM_ADDR32(addr) (0xc0000000 | ((uint32_t)(addr) << 16))
87 #define VDP_SET_CRAM_ADDR(addr) \
88 do { VDP_PORT_CTL32 = VDP_CRAM_ADDR32(addr); } while(0)
90 #define VDP_RGB(r, g, b) \
91 ((((uint16_t)(r) << 1) & 0xe) | \
92 (((uint16_t)(g) << 5) & 0xe0) | \
93 (((uint16_t)(b) << 9) & 0xe00))
95 #define VDP_RGB24(r, g, b) \
96 ((((uint16_t)(r) >> 4) & 0xe) | \
97 ((uint16_t)(g) & 0xe0) | \
98 (((uint16_t)(b) << 4) & 0xe00))
100 #define VDP_SET_CRAM_RGB(r, g, b) \
101 do { VDP_PORT_DATA = VDP_RGB(r, g, b); } while(0)
103 #define VDP_SET_CRAM_RGB24(r, g, b) \
104 do { VDP_PORT_DATA = VDP_RGB24(r, g, b); } while(0)
106 #define VDP_SET_BGCOLOR(pal, col) \
107 do { VDP_SET_REG(VDP_REG_BGCOLOR, ((pal) << 4) | (col)); } while(0)
109 #define VDP_TILE_HFLIP (1 << 11)
110 #define VDP_TILE_VFLIP (1 << 12)
111 #define VDP_TILE_PRIO (1 << 15)
113 #define VDP_MKTILE(tidx, pal, flags) \
114 (((uint16_t)tidx) | ((uint16_t)(pal) << 13) | (flags))
116 /* arguments to vdp_tilemap_slot */
117 #define VDP_PLANE_A 0
118 #define VDP_PLANE_WIN 1
119 #define VDP_PLANE_B 2
121 int vdp_init(void);
122 void vdp_set_tilemap_slot(int plane, int slot);
123 uint32_t vdp_tilemap_addr(int plane);
124 void vdp_setpal_rgb24(int idx, int r, int g, int b);
125 void vdp_setpal(int idx0, int count, unsigned char *pal);
126 /* TODO vdp_setpal_dma */
128 /* xtiles and ytiles can only be 32, 64, or 128 */
129 void vdp_set_scroll_size(int xtiles, int ytiles);
131 void vdp_memcpy(uint32_t vaddr, void *src, int sz);
133 #endif /* VDP_H_ */