megadrive_test1

view 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 source
1 #include <stdint.h>
2 #include "vdp.h"
3 #include "io.h"
4 #include "misc.h"
6 static void *tilemap_ptr[3];
8 int vdp_init(void)
9 {
10 unsigned int mode1_flags = VDP_REG1_DISP_BIT;
12 if(mdg_ispal()) {
13 mode1_flags |= VDP_REG1_30CELL_BIT;
14 }
16 VDP_SET_REG(0, VDP_REG0_BASE);
17 VDP_SET_REG(1, VDP_REG1_BASE | mode1_flags);
19 return 0;
20 }
22 void vdp_set_tilemap_slot(int plane, int slot)
23 {
24 switch(plane) {
25 case VDP_PLANE_A:
26 VDP_SET_REG(VDP_REG_PADDR_A, (slot & 7) << 3);
27 tilemap_ptr[VDP_PLANE_A] = (void*)((uint32_t)slot << 13);
28 break;
30 case VDP_PLANE_WIN:
31 VDP_SET_REG(VDP_REG_PADDR_WIN, (slot & 0x1f) << 1);
32 tilemap_ptr[VDP_PLANE_WIN] = (void*)((uint32_t)slot << 11);
33 break;
35 case VDP_PLANE_B:
36 VDP_SET_REG(VDP_REG_PADDR_B, slot & 7);
37 tilemap_ptr[VDP_PLANE_B] = (void*)((uint32_t)slot << 13);
38 break;
39 }
40 }
42 void *vdp_tilemap_ptr(int plane)
43 {
44 return tilemap_ptr[plane];
45 }
47 void vdp_setpal_rgb24(int idx, int r, int g, int b)
48 {
49 VDP_SET_CRAM_ADDR(idx);
50 VDP_SET_CRAM_RGB24(r, g, b);
51 }
53 void vdp_setpal(int idx0, int count, unsigned char *pal)
54 {
55 int i;
57 VDP_SET_CRAM_ADDR(idx0);
58 for(i=0; i<count; i++) {
59 VDP_SET_CRAM_RGB24(pal[0], pal[1], pal[2]);
60 pal += 3;
61 }
62 }
64 #define SCROLLSIZE(x) \
65 do { \
66 switch(xtiles) { \
67 case 32: \
68 case 64: \
69 (x) >>= 6; \
70 break; \
71 case 128: \
72 (x) = 3; \
73 break; \
74 default: \
75 panic("invalid argument to %s: %d\n", (x), __func__); \
76 } \
77 } while(0)
79 void vdp_set_scroll_size(int xtiles, int ytiles)
80 {
81 SCROLLSIZE(xtiles);
82 SCROLLSIZE(ytiles);
84 VDP_SET_REG(VDP_REG_SCROLL_SIZE, (ytiles << 4) | xtiles);
85 }