megadrive_test1

view src/vdp.h @ 5:f99eab59e7dc

clarified the C code by using VDP macros
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 01 Feb 2017 14:40:19 +0200
parents e7138066c7ea
children 862f8a034cae
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 /* control register read flags */
14 #define VDP_CTL_PAL_BIT 0x0001
15 #define VDP_CTL_HBLANK_BIT 0x0002
16 #define VDP_CTL_VBLANK_BIT 0x0004
17 #define VDP_CTL_DT3_BIT 0x0008
18 #define VDP_CTL_ODD_FRAME_BIT 0x0010
19 #define VDP_CTL_COLIDE_BIT 0x0020
20 #define VDP_CTL_SPRITE_OVF_BIT 0x0040
21 #define VDP_CTL_FRAME_BIT 0x0080
22 #define VDP_CTL_FIFO_FULL_BIT 0x0100
23 #define VDP_CTL_FIFO_EMPTY_BIT 0x0200
25 /* control register write flags (RSET) */
26 #define VDP_CTL_REGSEL_MASK 0x1f00
27 #define VDP_CTL_DATA_MASK 0x00ff
29 #define VDP_RSET(reg, val) \
30 (0x8000 | (VDP_CTL_REGSEL_MASK & ((uint16_t)(reg) << 8)) | \
31 (VDP_CTL_DATA_MASK & (uint16_t)(val)))
33 #define VDP_SET_REG(reg, val) \
34 do { VDP_PORT_CTL = VDP_RSET(reg, val); } while(0)
36 #define VDP_REG0_BASE 4
37 #define VDP_REG0_HVCNT_BIT 0x02
38 #define VDP_REG0_HINTR_BIT 0x10
40 #define VDP_REG1_BASE 4
41 #define VDP_REG1_30CELL_BIT 0x08
42 #define VDP_REG1_DMA_BIT 0x10
43 #define VDP_REG1_VINTR_BIT 0x20
44 #define VDP_REG1_DISP_BIT 0x40
46 #define VDP_MODE_WR_BIT 1
48 #define VDP_VRAM_WR 1
49 #define VDP_CRAM_WR 3
51 #define VDP_ADDRSET(addr, mode) /* TODO */
53 #define VDP_CRAM_ADDR32(addr) (0xc0000000 | ((uint32_t)(addr) << 16))
55 #define VDP_SET_CRAM_ADDR(addr) \
56 do { VDP_PORT_CTL32 = VDP_CRAM_ADDR32(addr); } while(0)
58 #define VDP_RGB24(r, g, b) \
59 ((((uint16_t)(r) >> 4) & 0xe) | \
60 ((uint16_t)(g) & 0xe0) | \
61 (((uint16_t)(b) << 4) & 0xe00))
63 #define VDP_SET_CRAM_RGB24(r, g, b) \
64 do { VDP_PORT_DATA = VDP_RGB24(r, g, b); } while(0)
66 #define VDP_SET_BGCOLOR(pal, col) \
67 do { VDP_SET_REG(7, ((pal) << 4) | (col)); } while(0)
69 #endif /* VDP_H_ */