megadrive_test1

annotate src/vdp.c @ 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@6 1 #include <stdint.h>
nuclear@6 2 #include "vdp.h"
nuclear@6 3 #include "io.h"
nuclear@6 4 #include "misc.h"
nuclear@6 5
nuclear@7 6 unsigned char vdp_shadow_reg[24];
nuclear@7 7
nuclear@7 8 static uint32_t tilemap_addr[3];
nuclear@6 9
nuclear@6 10 int vdp_init(void)
nuclear@6 11 {
nuclear@7 12 unsigned int mode1_flags = VDP_MSET2_DISP_BIT;
nuclear@6 13
nuclear@6 14 if(mdg_ispal()) {
nuclear@7 15 mode1_flags |= VDP_MSET2_30CELL_BIT;
nuclear@6 16 }
nuclear@6 17
nuclear@7 18 VDP_SET_REG(VDP_REG_MSET1, VDP_MSET1_BASE);
nuclear@7 19 VDP_SET_REG(VDP_REG_MSET2, VDP_MSET2_BASE | mode1_flags);
nuclear@6 20
nuclear@6 21 return 0;
nuclear@6 22 }
nuclear@6 23
nuclear@6 24 void vdp_set_tilemap_slot(int plane, int slot)
nuclear@6 25 {
nuclear@6 26 switch(plane) {
nuclear@6 27 case VDP_PLANE_A:
nuclear@6 28 VDP_SET_REG(VDP_REG_PADDR_A, (slot & 7) << 3);
nuclear@7 29 tilemap_addr[VDP_PLANE_A] = ((uint32_t)slot << 13);
nuclear@6 30 break;
nuclear@6 31
nuclear@6 32 case VDP_PLANE_WIN:
nuclear@6 33 VDP_SET_REG(VDP_REG_PADDR_WIN, (slot & 0x1f) << 1);
nuclear@7 34 tilemap_addr[VDP_PLANE_WIN] = ((uint32_t)slot << 11);
nuclear@6 35 break;
nuclear@6 36
nuclear@6 37 case VDP_PLANE_B:
nuclear@6 38 VDP_SET_REG(VDP_REG_PADDR_B, slot & 7);
nuclear@7 39 tilemap_addr[VDP_PLANE_B] = ((uint32_t)slot << 13);
nuclear@6 40 break;
nuclear@6 41 }
nuclear@6 42 }
nuclear@6 43
nuclear@7 44 uint32_t vdp_tilemap_addr(int plane)
nuclear@6 45 {
nuclear@7 46 return tilemap_addr[plane];
nuclear@6 47 }
nuclear@6 48
nuclear@6 49 void vdp_setpal_rgb24(int idx, int r, int g, int b)
nuclear@6 50 {
nuclear@6 51 VDP_SET_CRAM_ADDR(idx);
nuclear@6 52 VDP_SET_CRAM_RGB24(r, g, b);
nuclear@6 53 }
nuclear@6 54
nuclear@6 55 void vdp_setpal(int idx0, int count, unsigned char *pal)
nuclear@6 56 {
nuclear@6 57 int i;
nuclear@6 58
nuclear@6 59 VDP_SET_CRAM_ADDR(idx0);
nuclear@6 60 for(i=0; i<count; i++) {
nuclear@6 61 VDP_SET_CRAM_RGB24(pal[0], pal[1], pal[2]);
nuclear@6 62 pal += 3;
nuclear@6 63 }
nuclear@6 64 }
nuclear@6 65
nuclear@6 66 #define SCROLLSIZE(x) \
nuclear@6 67 do { \
nuclear@6 68 switch(xtiles) { \
nuclear@6 69 case 32: \
nuclear@6 70 case 64: \
nuclear@6 71 (x) >>= 6; \
nuclear@6 72 break; \
nuclear@6 73 case 128: \
nuclear@6 74 (x) = 3; \
nuclear@6 75 break; \
nuclear@6 76 default: \
nuclear@6 77 panic("invalid argument to %s: %d\n", (x), __func__); \
nuclear@6 78 } \
nuclear@6 79 } while(0)
nuclear@6 80
nuclear@6 81 void vdp_set_scroll_size(int xtiles, int ytiles)
nuclear@6 82 {
nuclear@6 83 SCROLLSIZE(xtiles);
nuclear@6 84 SCROLLSIZE(ytiles);
nuclear@6 85
nuclear@6 86 VDP_SET_REG(VDP_REG_SCROLL_SIZE, (ytiles << 4) | xtiles);
nuclear@6 87 }
nuclear@7 88
nuclear@7 89 void vdp_memcpy(uint32_t vaddr, void *src, int sz)
nuclear@7 90 {
nuclear@7 91 uint32_t saddr = (uint32_t)src;
nuclear@7 92 sz >>= 1; /* we'll transfer words */
nuclear@7 93 VDP_SET_REG_NOSHADOW(VDP_REG_MSET2,
nuclear@7 94 vdp_shadow_reg[VDP_REG_MSET2] | VDP_MSET2_DMA_BIT);
nuclear@7 95 VDP_SET_REG(VDP_REG_AUTOINC, 2);
nuclear@7 96 VDP_SET_REG(VDP_REG_DMALEN_LOW, sz);
nuclear@7 97 VDP_SET_REG(VDP_REG_DMALEN_HIGH, sz >> 8);
nuclear@7 98 VDP_SET_REG(VDP_REG_DMA_SADDR_LOW, saddr >> 1);
nuclear@7 99 VDP_SET_REG(VDP_REG_DMA_SADDR_MID, saddr >> 9);
nuclear@7 100 VDP_SET_REG(VDP_REG_DMA_SADDR_HIGH, saddr >> 17);
nuclear@7 101
nuclear@7 102 VDP_PORT_CTL = (vaddr & 0x3ffe) |
nuclear@7 103 }