cff531af |
1 | /*\r |
2 | * PicoDrive\r |
3 | * (C) notaz, 2006-2010\r |
4 | *\r |
5 | * This work is licensed under the terms of MAME license.\r |
6 | * See COPYING file in the top-level directory.\r |
7 | */\r |
697746df |
8 | \r |
9 | #include <stdio.h>\r |
10 | #include <unistd.h>\r |
11 | \r |
e743be20 |
12 | #include "../libpicofe/menu.h"\r |
13 | #include "../libpicofe/plat.h"\r |
697746df |
14 | #include "../common/emu.h"\r |
697746df |
15 | #include "../common/arm_utils.h"\r |
90f0dedf |
16 | #include "../common/version.h"\r |
697746df |
17 | \r |
18 | #include <pico/pico_int.h>\r |
19 | \r |
20 | \r |
fcdefcf6 |
21 | const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL };\r |
22 | const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };\r |
5a681086 |
23 | enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };\r |
697746df |
24 | \r |
697746df |
25 | \r |
26 | void pemu_prep_defconfig(void)\r |
27 | {\r |
697746df |
28 | }\r |
29 | \r |
30 | void pemu_validate_config(void)\r |
31 | {\r |
32 | extern int PicoOpt;\r |
33 | // PicoOpt &= ~POPT_EXT_FM;\r |
92dfd9af |
34 | PicoOpt &= ~POPT_EN_DRC;\r |
697746df |
35 | }\r |
36 | \r |
697746df |
37 | static void draw_cd_leds(void)\r |
38 | {\r |
39 | int led_reg, pitch, scr_offs, led_offs;\r |
40 | led_reg = Pico_mcd->s68k_regs[0];\r |
41 | \r |
42 | pitch = 320;\r |
43 | led_offs = 4;\r |
44 | scr_offs = pitch * 2 + 4;\r |
45 | \r |
5a681086 |
46 | if (currentConfig.renderer != RT_16BIT) {\r |
697746df |
47 | #define p(x) px[(x) >> 2]\r |
48 | // 8-bit modes\r |
49 | unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs);\r |
50 | unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r |
51 | unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r |
52 | p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;\r |
53 | p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;\r |
54 | #undef p\r |
55 | } else {\r |
56 | #define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]\r |
57 | // 16-bit modes\r |
58 | unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);\r |
59 | unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;\r |
60 | unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;\r |
61 | p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;\r |
62 | p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;\r |
63 | #undef p\r |
64 | }\r |
65 | }\r |
66 | \r |
d08e7326 |
67 | void pemu_finalize_frame(const char *fps, const char *notice)\r |
697746df |
68 | {\r |
5a681086 |
69 | if (currentConfig.renderer != RT_16BIT && !(PicoAHW & PAHW_32X)) {\r |
70 | unsigned short *pd = (unsigned short *)g_screen_ptr + 8 * g_screen_width;\r |
71 | unsigned char *ps = PicoDraw2FB + 328*8 + 8;\r |
72 | unsigned short *pal = HighPal;\r |
73 | int i, x;\r |
74 | if (Pico.m.dirtyPal)\r |
75 | PicoDrawUpdateHighPal();\r |
76 | for (i = 0; i < 224; i++, ps += 8)\r |
77 | for (x = 0; x < 320; x++)\r |
78 | *pd++ = pal[*ps++];\r |
79 | }\r |
80 | \r |
697746df |
81 | if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) {\r |
82 | if (notice)\r |
f7e40c9b |
83 | emu_osd_text16(4, g_screen_height - 8, notice);\r |
697746df |
84 | if (currentConfig.EmuOpt & EOPT_SHOW_FPS)\r |
f7e40c9b |
85 | emu_osd_text16(g_screen_width - 60, g_screen_height - 8, fps);\r |
697746df |
86 | }\r |
87 | if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS))\r |
88 | draw_cd_leds();\r |
697746df |
89 | }\r |
90 | \r |
5a681086 |
91 | static void apply_renderer(void)\r |
92 | {\r |
5a681086 |
93 | switch (currentConfig.renderer) {\r |
94 | case RT_16BIT:\r |
95 | PicoOpt &= ~POPT_ALT_RENDERER;\r |
96 | PicoDrawSetOutFormat(PDF_RGB555, 0);\r |
97 | PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);\r |
98 | break;\r |
99 | case RT_8BIT_ACC:\r |
100 | PicoOpt &= ~POPT_ALT_RENDERER;\r |
101 | PicoDrawSetOutFormat(PDF_8BIT, 0);\r |
102 | PicoDrawSetOutBuf(PicoDraw2FB + 8, 328);\r |
103 | break;\r |
104 | case RT_8BIT_FAST:\r |
105 | PicoOpt |= POPT_ALT_RENDERER;\r |
106 | PicoDrawSetOutFormat(PDF_NONE, 0);\r |
107 | break;\r |
108 | }\r |
109 | \r |
41946d70 |
110 | if (PicoAHW & PAHW_32X)\r |
5a681086 |
111 | PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);\r |
5a681086 |
112 | }\r |
113 | \r |
114 | void plat_video_toggle_renderer(int change, int is_menu)\r |
697746df |
115 | {\r |
5a681086 |
116 | currentConfig.renderer += change;\r |
117 | if (currentConfig.renderer >= RT_COUNT)\r |
118 | currentConfig.renderer = 0;\r |
119 | else if (currentConfig.renderer < 0)\r |
120 | currentConfig.renderer = RT_COUNT - 1;\r |
121 | \r |
122 | if (!is_menu)\r |
123 | apply_renderer();\r |
124 | \r |
125 | emu_status_msg(renderer_names[currentConfig.renderer]);\r |
697746df |
126 | }\r |
127 | \r |
697746df |
128 | void plat_status_msg_clear(void)\r |
129 | {\r |
130 | unsigned short *d = (unsigned short *)g_screen_ptr + g_screen_width * g_screen_height;\r |
131 | int l = g_screen_width * 8;\r |
132 | memset32((int *)(d - l), 0, l * 2 / 4);\r |
133 | }\r |
134 | \r |
135 | void plat_status_msg_busy_next(const char *msg)\r |
136 | {\r |
137 | plat_status_msg_clear();\r |
d08e7326 |
138 | pemu_finalize_frame("", msg);\r |
139 | plat_video_flip();\r |
697746df |
140 | emu_status_msg("");\r |
141 | reset_timing = 1;\r |
142 | }\r |
143 | \r |
144 | void plat_status_msg_busy_first(const char *msg)\r |
145 | {\r |
146 | // memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);\r |
147 | plat_status_msg_busy_next(msg);\r |
148 | }\r |
149 | \r |
150 | void plat_update_volume(int has_changed, int is_up)\r |
151 | {\r |
152 | }\r |
153 | \r |
45285368 |
154 | void pemu_forced_frame(int no_scale, int do_emu)\r |
697746df |
155 | {\r |
e51e5983 |
156 | PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);\r |
a4edca53 |
157 | PicoDrawSetCallbacks(NULL, NULL);\r |
697746df |
158 | Pico.m.dirtyPal = 1;\r |
a4edca53 |
159 | \r |
160 | emu_cmn_forced_frame(no_scale, do_emu);\r |
697746df |
161 | \r |
45285368 |
162 | g_menubg_src_ptr = g_screen_ptr;\r |
697746df |
163 | }\r |
164 | \r |
697746df |
165 | void pemu_sound_start(void)\r |
166 | {\r |
df92fbd1 |
167 | emu_sound_start();\r |
697746df |
168 | }\r |
169 | \r |
170 | void plat_debug_cat(char *str)\r |
171 | {\r |
172 | }\r |
173 | \r |
174 | void emu_video_mode_change(int start_line, int line_count, int is_32cols)\r |
175 | {\r |
697746df |
176 | // clear whole screen in all buffers\r |
177 | memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);\r |
178 | }\r |
179 | \r |
180 | void pemu_loop_prep(void)\r |
181 | {\r |
5a681086 |
182 | apply_renderer();\r |
697746df |
183 | }\r |
184 | \r |
185 | void pemu_loop_end(void)\r |
186 | {\r |
697746df |
187 | /* do one more frame for menu bg */\r |
45285368 |
188 | pemu_forced_frame(0, 1);\r |
697746df |
189 | }\r |
190 | \r |
191 | void plat_wait_till_us(unsigned int us_to)\r |
192 | {\r |
193 | unsigned int now;\r |
194 | \r |
195 | now = plat_get_ticks_us();\r |
196 | \r |
197 | while ((signed int)(us_to - now) > 512)\r |
198 | {\r |
199 | usleep(1024);\r |
200 | now = plat_get_ticks_us();\r |
201 | }\r |
202 | }\r |
203 | \r |