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