megadrive_test1

diff 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
line diff
     1.1 --- a/src/vdp.c	Sat Feb 11 08:56:42 2017 +0200
     1.2 +++ b/src/vdp.c	Sun Feb 19 14:00:26 2017 +0200
     1.3 @@ -3,18 +3,20 @@
     1.4  #include "io.h"
     1.5  #include "misc.h"
     1.6  
     1.7 -static void *tilemap_ptr[3];
     1.8 +unsigned char vdp_shadow_reg[24];
     1.9 +
    1.10 +static uint32_t tilemap_addr[3];
    1.11  
    1.12  int vdp_init(void)
    1.13  {
    1.14 -	unsigned int mode1_flags = VDP_REG1_DISP_BIT;
    1.15 +	unsigned int mode1_flags = VDP_MSET2_DISP_BIT;
    1.16  
    1.17  	if(mdg_ispal()) {
    1.18 -		mode1_flags |= VDP_REG1_30CELL_BIT;
    1.19 +		mode1_flags |= VDP_MSET2_30CELL_BIT;
    1.20  	}
    1.21  
    1.22 -	VDP_SET_REG(0, VDP_REG0_BASE);
    1.23 -	VDP_SET_REG(1, VDP_REG1_BASE | mode1_flags);
    1.24 +	VDP_SET_REG(VDP_REG_MSET1, VDP_MSET1_BASE);
    1.25 +	VDP_SET_REG(VDP_REG_MSET2, VDP_MSET2_BASE | mode1_flags);
    1.26  
    1.27  	return 0;
    1.28  }
    1.29 @@ -24,24 +26,24 @@
    1.30  	switch(plane) {
    1.31  	case VDP_PLANE_A:
    1.32  		VDP_SET_REG(VDP_REG_PADDR_A, (slot & 7) << 3);
    1.33 -		tilemap_ptr[VDP_PLANE_A] = (void*)((uint32_t)slot << 13);
    1.34 +		tilemap_addr[VDP_PLANE_A] = ((uint32_t)slot << 13);
    1.35  		break;
    1.36  
    1.37  	case VDP_PLANE_WIN:
    1.38  		VDP_SET_REG(VDP_REG_PADDR_WIN, (slot & 0x1f) << 1);
    1.39 -		tilemap_ptr[VDP_PLANE_WIN] = (void*)((uint32_t)slot << 11);
    1.40 +		tilemap_addr[VDP_PLANE_WIN] = ((uint32_t)slot << 11);
    1.41  		break;
    1.42  
    1.43  	case VDP_PLANE_B:
    1.44  		VDP_SET_REG(VDP_REG_PADDR_B, slot & 7);
    1.45 -		tilemap_ptr[VDP_PLANE_B] = (void*)((uint32_t)slot << 13);
    1.46 +		tilemap_addr[VDP_PLANE_B] = ((uint32_t)slot << 13);
    1.47  		break;
    1.48  	}
    1.49  }
    1.50  
    1.51 -void *vdp_tilemap_ptr(int plane)
    1.52 +uint32_t vdp_tilemap_addr(int plane)
    1.53  {
    1.54 -	return tilemap_ptr[plane];
    1.55 +	return tilemap_addr[plane];
    1.56  }
    1.57  
    1.58  void vdp_setpal_rgb24(int idx, int r, int g, int b)
    1.59 @@ -83,3 +85,19 @@
    1.60  
    1.61  	VDP_SET_REG(VDP_REG_SCROLL_SIZE, (ytiles << 4) | xtiles);
    1.62  }
    1.63 +
    1.64 +void vdp_memcpy(uint32_t vaddr, void *src, int sz)
    1.65 +{
    1.66 +	uint32_t saddr = (uint32_t)src;
    1.67 +	sz >>= 1;	/* we'll transfer words */
    1.68 +	VDP_SET_REG_NOSHADOW(VDP_REG_MSET2,
    1.69 +			vdp_shadow_reg[VDP_REG_MSET2] | VDP_MSET2_DMA_BIT);
    1.70 +	VDP_SET_REG(VDP_REG_AUTOINC, 2);
    1.71 +	VDP_SET_REG(VDP_REG_DMALEN_LOW, sz);
    1.72 +	VDP_SET_REG(VDP_REG_DMALEN_HIGH, sz >> 8);
    1.73 +	VDP_SET_REG(VDP_REG_DMA_SADDR_LOW, saddr >> 1);
    1.74 +	VDP_SET_REG(VDP_REG_DMA_SADDR_MID, saddr >> 9);
    1.75 +	VDP_SET_REG(VDP_REG_DMA_SADDR_HIGH, saddr >> 17);
    1.76 +
    1.77 +	VDP_PORT_CTL = (vaddr & 0x3ffe) | 
    1.78 +}