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