3 * (C) notaz, 2006-2010
\r
5 * This work is licensed under the terms of MAME license.
\r
6 * See COPYING file in the top-level directory.
\r
12 #include "../libpicofe/menu.h"
\r
13 #include "../libpicofe/plat.h"
\r
14 #include "../libpicofe/linux/sndout_oss.h"
\r
15 #include "../common/emu.h"
\r
16 #include "../common/arm_utils.h"
\r
17 #include "version.h"
\r
19 #include <pico/pico_int.h>
\r
22 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
\r
23 const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL };
\r
24 const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };
\r
25 enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };
\r
28 void pemu_prep_defconfig(void)
\r
32 void pemu_validate_config(void)
\r
35 // PicoOpt &= ~POPT_EXT_FM;
\r
36 PicoOpt &= ~POPT_EN_SVP_DRC;
\r
39 // FIXME: dupes from GP2X, need cleanup
\r
40 static void (*osd_text)(int x, int y, const char *text);
\r
43 static void osd_text8(int x, int y, const char *text)
\r
45 int len = strlen(text)*8;
\r
49 for (h = 0; h < 8; h++) {
\r
50 offs = (x + g_screen_width * (y+h)) & ~3;
\r
51 p = (int *) ((char *)g_screen_ptr + offs);
\r
52 for (i = len; i; i--, p++)
\r
55 emu_text_out8(x, y, text);
\r
59 static void osd_text16(int x, int y, const char *text)
\r
61 int len = strlen(text)*8;
\r
65 for (h = 0; h < 8; h++) {
\r
66 offs = (x + g_screen_width * (y+h)) & ~1;
\r
67 p = (int *) ((short *)g_screen_ptr + offs);
\r
68 for (i = len; i; i--, p++)
\r
69 *p = (*p >> 2) & 0x39e7;
\r
71 emu_text_out16(x, y, text);
\r
74 static void draw_cd_leds(void)
\r
76 int led_reg, pitch, scr_offs, led_offs;
\r
77 led_reg = Pico_mcd->s68k_regs[0];
\r
81 scr_offs = pitch * 2 + 4;
\r
83 if (currentConfig.renderer != RT_16BIT) {
\r
84 #define p(x) px[(x) >> 2]
\r
86 unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs);
\r
87 unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;
\r
88 unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;
\r
89 p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
\r
90 p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
\r
93 #define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]
\r
95 unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);
\r
96 unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;
\r
97 unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;
\r
98 p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
\r
99 p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
\r
104 void pemu_finalize_frame(const char *fps, const char *notice)
\r
106 if (currentConfig.renderer != RT_16BIT && !(PicoAHW & PAHW_32X)) {
\r
107 unsigned short *pd = (unsigned short *)g_screen_ptr + 8 * g_screen_width;
\r
108 unsigned char *ps = PicoDraw2FB + 328*8 + 8;
\r
109 unsigned short *pal = HighPal;
\r
111 if (Pico.m.dirtyPal)
\r
112 PicoDrawUpdateHighPal();
\r
113 for (i = 0; i < 224; i++, ps += 8)
\r
114 for (x = 0; x < 320; x++)
\r
115 *pd++ = pal[*ps++];
\r
118 if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) {
\r
120 osd_text(4, g_screen_height - 8, notice);
\r
121 if (currentConfig.EmuOpt & EOPT_SHOW_FPS)
\r
122 osd_text(g_screen_width - 60, g_screen_height - 8, fps);
\r
124 if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS))
\r
128 static void apply_renderer(void)
\r
130 switch (currentConfig.renderer) {
\r
132 PicoOpt &= ~POPT_ALT_RENDERER;
\r
133 PicoDrawSetOutFormat(PDF_RGB555, 0);
\r
134 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
137 PicoOpt &= ~POPT_ALT_RENDERER;
\r
138 PicoDrawSetOutFormat(PDF_8BIT, 0);
\r
139 PicoDrawSetOutBuf(PicoDraw2FB + 8, 328);
\r
142 PicoOpt |= POPT_ALT_RENDERER;
\r
143 PicoDrawSetOutFormat(PDF_NONE, 0);
\r
147 if (PicoAHW & PAHW_32X) {
\r
149 if (currentConfig.renderer == RT_16BIT)
\r
152 PicoDrawSetOutFormat(PDF_NONE, 0);
\r
153 PicoDraw32xSetFrameMode(1, only_32x);
\r
154 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
156 //PicoDraw32xSetFrameMode(0, 0);
\r
157 //PicoDrawSetOutFormat(PDF_RGB555, 1);
\r
160 void plat_video_toggle_renderer(int change, int is_menu)
\r
162 currentConfig.renderer += change;
\r
163 if (currentConfig.renderer >= RT_COUNT)
\r
164 currentConfig.renderer = 0;
\r
165 else if (currentConfig.renderer < 0)
\r
166 currentConfig.renderer = RT_COUNT - 1;
\r
171 emu_status_msg(renderer_names[currentConfig.renderer]);
\r
174 void plat_video_menu_enter(int is_rom_loaded)
\r
178 void plat_video_menu_begin(void)
\r
180 g_menuscreen_ptr = g_screen_ptr;
\r
183 void plat_video_menu_end(void)
\r
188 void plat_status_msg_clear(void)
\r
190 unsigned short *d = (unsigned short *)g_screen_ptr + g_screen_width * g_screen_height;
\r
191 int l = g_screen_width * 8;
\r
192 memset32((int *)(d - l), 0, l * 2 / 4);
\r
195 void plat_status_msg_busy_next(const char *msg)
\r
197 plat_status_msg_clear();
\r
198 pemu_finalize_frame("", msg);
\r
200 emu_status_msg("");
\r
204 void plat_status_msg_busy_first(const char *msg)
\r
206 // memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
\r
207 plat_status_msg_busy_next(msg);
\r
210 void plat_update_volume(int has_changed, int is_up)
\r
214 void pemu_forced_frame(int no_scale, int do_emu)
\r
216 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
217 PicoDraw32xSetFrameMode(0, 0);
\r
218 PicoDrawSetCallbacks(NULL, NULL);
\r
219 Pico.m.dirtyPal = 1;
\r
221 emu_cmn_forced_frame(no_scale, do_emu);
\r
223 g_menubg_src_ptr = g_screen_ptr;
\r
226 static void oss_write_nonblocking(int len)
\r
228 // sndout_oss_can_write() is not reliable, only use with no_frmlimit
\r
229 if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))
\r
232 sndout_oss_write_nb(PsndOut, len);
\r
235 void pemu_sound_start(void)
\r
239 if (currentConfig.EmuOpt & EOPT_EN_SOUND)
\r
241 int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;
\r
243 PsndRerate(Pico.m.frame_count ? 1 : 0);
\r
245 printf("starting audio: %i len: %i stereo: %i, pal: %i\n",
\r
246 PsndRate, PsndLen, is_stereo, Pico.m.pal);
\r
247 sndout_oss_start(PsndRate, is_stereo, 1);
\r
248 sndout_oss_setvol(currentConfig.volume, currentConfig.volume);
\r
249 PicoWriteSound = oss_write_nonblocking;
\r
250 plat_update_volume(0, 0);
\r
251 memset(sndBuffer, 0, sizeof(sndBuffer));
\r
252 PsndOut = sndBuffer;
\r
256 void pemu_sound_stop(void)
\r
260 void pemu_sound_wait(void)
\r
262 // don't need to do anything, writes will block by themselves
\r
265 void plat_debug_cat(char *str)
\r
269 void emu_video_mode_change(int start_line, int line_count, int is_32cols)
\r
271 // clear whole screen in all buffers
\r
272 memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
\r
275 void pemu_loop_prep(void)
\r
278 osd_text = osd_text16;
\r
280 pemu_sound_start();
\r
283 void pemu_loop_end(void)
\r
287 /* do one more frame for menu bg */
\r
288 pemu_forced_frame(0, 1);
\r
291 void plat_wait_till_us(unsigned int us_to)
\r
295 now = plat_get_ticks_us();
\r
297 while ((signed int)(us_to - now) > 512)
\r
300 now = plat_get_ticks_us();
\r