megadrive_test1

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