megadrive_test1

diff src/vdp.c @ 6:862f8a034cae

expanding the megadrive code
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 11 Feb 2017 08:56:42 +0200
parents
children 8253942b0a1a
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/vdp.c	Sat Feb 11 08:56:42 2017 +0200
     1.3 @@ -0,0 +1,85 @@
     1.4 +#include <stdint.h>
     1.5 +#include "vdp.h"
     1.6 +#include "io.h"
     1.7 +#include "misc.h"
     1.8 +
     1.9 +static void *tilemap_ptr[3];
    1.10 +
    1.11 +int vdp_init(void)
    1.12 +{
    1.13 +	unsigned int mode1_flags = VDP_REG1_DISP_BIT;
    1.14 +
    1.15 +	if(mdg_ispal()) {
    1.16 +		mode1_flags |= VDP_REG1_30CELL_BIT;
    1.17 +	}
    1.18 +
    1.19 +	VDP_SET_REG(0, VDP_REG0_BASE);
    1.20 +	VDP_SET_REG(1, VDP_REG1_BASE | mode1_flags);
    1.21 +
    1.22 +	return 0;
    1.23 +}
    1.24 +
    1.25 +void vdp_set_tilemap_slot(int plane, int slot)
    1.26 +{
    1.27 +	switch(plane) {
    1.28 +	case VDP_PLANE_A:
    1.29 +		VDP_SET_REG(VDP_REG_PADDR_A, (slot & 7) << 3);
    1.30 +		tilemap_ptr[VDP_PLANE_A] = (void*)((uint32_t)slot << 13);
    1.31 +		break;
    1.32 +
    1.33 +	case VDP_PLANE_WIN:
    1.34 +		VDP_SET_REG(VDP_REG_PADDR_WIN, (slot & 0x1f) << 1);
    1.35 +		tilemap_ptr[VDP_PLANE_WIN] = (void*)((uint32_t)slot << 11);
    1.36 +		break;
    1.37 +
    1.38 +	case VDP_PLANE_B:
    1.39 +		VDP_SET_REG(VDP_REG_PADDR_B, slot & 7);
    1.40 +		tilemap_ptr[VDP_PLANE_B] = (void*)((uint32_t)slot << 13);
    1.41 +		break;
    1.42 +	}
    1.43 +}
    1.44 +
    1.45 +void *vdp_tilemap_ptr(int plane)
    1.46 +{
    1.47 +	return tilemap_ptr[plane];
    1.48 +}
    1.49 +
    1.50 +void vdp_setpal_rgb24(int idx, int r, int g, int b)
    1.51 +{
    1.52 +	VDP_SET_CRAM_ADDR(idx);
    1.53 +	VDP_SET_CRAM_RGB24(r, g, b);
    1.54 +}
    1.55 +
    1.56 +void vdp_setpal(int idx0, int count, unsigned char *pal)
    1.57 +{
    1.58 +	int i;
    1.59 +
    1.60 +	VDP_SET_CRAM_ADDR(idx0);
    1.61 +	for(i=0; i<count; i++) {
    1.62 +		VDP_SET_CRAM_RGB24(pal[0], pal[1], pal[2]);
    1.63 +		pal += 3;
    1.64 +	}
    1.65 +}
    1.66 +
    1.67 +#define SCROLLSIZE(x)	\
    1.68 +	do { \
    1.69 +		switch(xtiles) { \
    1.70 +		case 32: \
    1.71 +		case 64: \
    1.72 +			(x) >>= 6; \
    1.73 +			break; \
    1.74 +		case 128: \
    1.75 +			(x) = 3; \
    1.76 +			break; \
    1.77 +		default: \
    1.78 +			panic("invalid argument to %s: %d\n", (x), __func__); \
    1.79 +		} \
    1.80 +	} while(0)
    1.81 +
    1.82 +void vdp_set_scroll_size(int xtiles, int ytiles)
    1.83 +{
    1.84 +	SCROLLSIZE(xtiles);
    1.85 +	SCROLLSIZE(ytiles);
    1.86 +
    1.87 +	VDP_SET_REG(VDP_REG_SCROLL_SIZE, (ytiles << 4) | xtiles);
    1.88 +}