nuclear@6: #include nuclear@6: #include "vdp.h" nuclear@6: #include "io.h" nuclear@6: #include "misc.h" nuclear@6: nuclear@7: unsigned char vdp_shadow_reg[24]; nuclear@7: nuclear@7: static uint32_t tilemap_addr[3]; nuclear@6: nuclear@6: int vdp_init(void) nuclear@6: { nuclear@7: unsigned int mode1_flags = VDP_MSET2_DISP_BIT; nuclear@6: nuclear@6: if(mdg_ispal()) { nuclear@7: mode1_flags |= VDP_MSET2_30CELL_BIT; nuclear@6: } nuclear@6: nuclear@7: VDP_SET_REG(VDP_REG_MSET1, VDP_MSET1_BASE); nuclear@7: VDP_SET_REG(VDP_REG_MSET2, VDP_MSET2_BASE | mode1_flags); nuclear@6: nuclear@6: return 0; nuclear@6: } nuclear@6: nuclear@6: void vdp_set_tilemap_slot(int plane, int slot) nuclear@6: { nuclear@6: switch(plane) { nuclear@6: case VDP_PLANE_A: nuclear@6: VDP_SET_REG(VDP_REG_PADDR_A, (slot & 7) << 3); nuclear@7: tilemap_addr[VDP_PLANE_A] = ((uint32_t)slot << 13); nuclear@6: break; nuclear@6: nuclear@6: case VDP_PLANE_WIN: nuclear@6: VDP_SET_REG(VDP_REG_PADDR_WIN, (slot & 0x1f) << 1); nuclear@7: tilemap_addr[VDP_PLANE_WIN] = ((uint32_t)slot << 11); nuclear@6: break; nuclear@6: nuclear@6: case VDP_PLANE_B: nuclear@6: VDP_SET_REG(VDP_REG_PADDR_B, slot & 7); nuclear@7: tilemap_addr[VDP_PLANE_B] = ((uint32_t)slot << 13); nuclear@6: break; nuclear@6: } nuclear@6: } nuclear@6: nuclear@7: uint32_t vdp_tilemap_addr(int plane) nuclear@6: { nuclear@7: return tilemap_addr[plane]; nuclear@6: } nuclear@6: nuclear@6: void vdp_setpal_rgb24(int idx, int r, int g, int b) nuclear@6: { nuclear@6: VDP_SET_CRAM_ADDR(idx); nuclear@6: VDP_SET_CRAM_RGB24(r, g, b); nuclear@6: } nuclear@6: nuclear@6: void vdp_setpal(int idx0, int count, unsigned char *pal) nuclear@6: { nuclear@6: int i; nuclear@6: nuclear@6: VDP_SET_CRAM_ADDR(idx0); nuclear@6: for(i=0; i>= 6; \ nuclear@6: break; \ nuclear@6: case 128: \ nuclear@6: (x) = 3; \ nuclear@6: break; \ nuclear@6: default: \ nuclear@6: panic("invalid argument to %s: %d\n", (x), __func__); \ nuclear@6: } \ nuclear@6: } while(0) nuclear@6: nuclear@6: void vdp_set_scroll_size(int xtiles, int ytiles) nuclear@6: { nuclear@6: SCROLLSIZE(xtiles); nuclear@6: SCROLLSIZE(ytiles); nuclear@6: nuclear@6: VDP_SET_REG(VDP_REG_SCROLL_SIZE, (ytiles << 4) | xtiles); nuclear@6: } nuclear@7: nuclear@7: void vdp_memcpy(uint32_t vaddr, void *src, int sz) nuclear@7: { nuclear@7: uint32_t saddr = (uint32_t)src; nuclear@7: sz >>= 1; /* we'll transfer words */ nuclear@7: VDP_SET_REG_NOSHADOW(VDP_REG_MSET2, nuclear@7: vdp_shadow_reg[VDP_REG_MSET2] | VDP_MSET2_DMA_BIT); nuclear@7: VDP_SET_REG(VDP_REG_AUTOINC, 2); nuclear@7: VDP_SET_REG(VDP_REG_DMALEN_LOW, sz); nuclear@7: VDP_SET_REG(VDP_REG_DMALEN_HIGH, sz >> 8); nuclear@7: VDP_SET_REG(VDP_REG_DMA_SADDR_LOW, saddr >> 1); nuclear@7: VDP_SET_REG(VDP_REG_DMA_SADDR_MID, saddr >> 9); nuclear@7: VDP_SET_REG(VDP_REG_DMA_SADDR_HIGH, saddr >> 17); nuclear@7: nuclear@7: VDP_PORT_CTL = (vaddr & 0x3ffe) | nuclear@7: }