1 // (c) Copyright 2006-2009 notaz, All rights reserved.
\r
2 // Free for non-commercial use.
\r
4 // For commercial use, separate licencing terms must be obtained.
\r
9 #include "../common/emu.h"
\r
10 #include "../common/menu.h"
\r
11 #include "../common/plat.h"
\r
12 #include "../common/arm_utils.h"
\r
13 #include "../linux/sndout_oss.h"
\r
14 #include "version.h"
\r
16 #include <pico/pico_int.h>
\r
19 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
\r
20 char cpu_clk_name[] = "unused";
\r
21 const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL };
\r
22 const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };
\r
23 enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };
\r
26 void pemu_prep_defconfig(void)
\r
30 void pemu_validate_config(void)
\r
33 // PicoOpt &= ~POPT_EXT_FM;
\r
34 PicoOpt &= ~POPT_EN_SVP_DRC;
\r
37 // FIXME: dupes from GP2X, need cleanup
\r
38 static void (*osd_text)(int x, int y, const char *text);
\r
41 static void osd_text8(int x, int y, const char *text)
\r
43 int len = strlen(text)*8;
\r
47 for (h = 0; h < 8; h++) {
\r
48 offs = (x + g_screen_width * (y+h)) & ~3;
\r
49 p = (int *) ((char *)g_screen_ptr + offs);
\r
50 for (i = len; i; i--, p++)
\r
53 emu_text_out8(x, y, text);
\r
57 static void osd_text16(int x, int y, const char *text)
\r
59 int len = strlen(text)*8;
\r
63 for (h = 0; h < 8; h++) {
\r
64 offs = (x + g_screen_width * (y+h)) & ~1;
\r
65 p = (int *) ((short *)g_screen_ptr + offs);
\r
66 for (i = len; i; i--, p++)
\r
67 *p = (*p >> 2) & 0x39e7;
\r
69 emu_text_out16(x, y, text);
\r
72 static void draw_cd_leds(void)
\r
74 int led_reg, pitch, scr_offs, led_offs;
\r
75 led_reg = Pico_mcd->s68k_regs[0];
\r
79 scr_offs = pitch * 2 + 4;
\r
81 if (currentConfig.renderer != RT_16BIT) {
\r
82 #define p(x) px[(x) >> 2]
\r
84 unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs);
\r
85 unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;
\r
86 unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;
\r
87 p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
\r
88 p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
\r
91 #define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]
\r
93 unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);
\r
94 unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;
\r
95 unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;
\r
96 p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
\r
97 p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
\r
102 void pemu_finalize_frame(const char *fps, const char *notice)
\r
104 if (currentConfig.renderer != RT_16BIT && !(PicoAHW & PAHW_32X)) {
\r
105 unsigned short *pd = (unsigned short *)g_screen_ptr + 8 * g_screen_width;
\r
106 unsigned char *ps = PicoDraw2FB + 328*8 + 8;
\r
107 unsigned short *pal = HighPal;
\r
109 if (Pico.m.dirtyPal)
\r
110 PicoDrawUpdateHighPal();
\r
111 for (i = 0; i < 224; i++, ps += 8)
\r
112 for (x = 0; x < 320; x++)
\r
113 *pd++ = pal[*ps++];
\r
116 if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) {
\r
118 osd_text(4, g_screen_height - 8, notice);
\r
119 if (currentConfig.EmuOpt & EOPT_SHOW_FPS)
\r
120 osd_text(g_screen_width - 60, g_screen_height - 8, fps);
\r
122 if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS))
\r
126 static void apply_renderer(void)
\r
128 PicoScanBegin = NULL;
\r
129 PicoScanEnd = NULL;
\r
131 switch (currentConfig.renderer) {
\r
133 PicoOpt &= ~POPT_ALT_RENDERER;
\r
134 PicoDrawSetOutFormat(PDF_RGB555, 0);
\r
135 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
138 PicoOpt &= ~POPT_ALT_RENDERER;
\r
139 PicoDrawSetOutFormat(PDF_8BIT, 0);
\r
140 PicoDrawSetOutBuf(PicoDraw2FB + 8, 328);
\r
143 PicoOpt |= POPT_ALT_RENDERER;
\r
144 PicoDrawSetOutFormat(PDF_NONE, 0);
\r
148 if (PicoAHW & PAHW_32X) {
\r
150 if (currentConfig.renderer == RT_16BIT)
\r
153 PicoDrawSetOutFormat(PDF_NONE, 0);
\r
154 PicoDraw32xSetFrameMode(1, only_32x);
\r
155 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
157 //PicoDraw32xSetFrameMode(0, 0);
\r
158 //PicoDrawSetOutFormat(PDF_RGB555, 1);
\r
161 void plat_video_toggle_renderer(int change, int is_menu)
\r
163 currentConfig.renderer += change;
\r
164 if (currentConfig.renderer >= RT_COUNT)
\r
165 currentConfig.renderer = 0;
\r
166 else if (currentConfig.renderer < 0)
\r
167 currentConfig.renderer = RT_COUNT - 1;
\r
172 emu_status_msg(renderer_names[currentConfig.renderer]);
\r
175 void plat_video_menu_enter(int is_rom_loaded)
\r
179 void plat_video_menu_begin(void)
\r
181 memcpy32(g_screen_ptr, g_menubg_ptr, g_screen_width * g_screen_height * 2 / 4);
\r
182 g_menuscreen_ptr = g_screen_ptr;
\r
185 void plat_video_menu_end(void)
\r
190 void plat_status_msg_clear(void)
\r
192 unsigned short *d = (unsigned short *)g_screen_ptr + g_screen_width * g_screen_height;
\r
193 int l = g_screen_width * 8;
\r
194 memset32((int *)(d - l), 0, l * 2 / 4);
\r
197 void plat_status_msg_busy_next(const char *msg)
\r
199 plat_status_msg_clear();
\r
200 pemu_finalize_frame("", msg);
\r
202 emu_status_msg("");
\r
206 void plat_status_msg_busy_first(const char *msg)
\r
208 // memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
\r
209 plat_status_msg_busy_next(msg);
\r
212 void plat_update_volume(int has_changed, int is_up)
\r
216 void pemu_forced_frame(int opts, int no_scale)
\r
218 int po_old = PicoOpt;
\r
219 int eo_old = currentConfig.EmuOpt;
\r
221 PicoOpt &= ~POPT_ALT_RENDERER;
\r
222 PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites
\r
224 PicoDrawSetOutFormat(PDF_RGB555, 1);
\r
225 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
226 PicoDraw32xSetFrameMode(0, 0);
\r
228 Pico.m.dirtyPal = 1;
\r
229 PicoFrameDrawOnly();
\r
232 currentConfig.EmuOpt = eo_old;
\r
235 static void updateSound(int len)
\r
238 if (PicoOpt & POPT_EN_STEREO)
\r
241 if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))
\r
244 /* avoid writing audio when lagging behind to prevent audio lag */
\r
245 if (PicoSkipFrame != 2)
\r
246 sndout_oss_write(PsndOut, len);
\r
249 void pemu_sound_start(void)
\r
251 int target_fps = Pico.m.pal ? 50 : 60;
\r
255 if (currentConfig.EmuOpt & EOPT_EN_SOUND)
\r
257 int snd_excess_add, frame_samples;
\r
258 int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;
\r
260 PsndRerate(Pico.m.frame_count ? 1 : 0);
\r
262 frame_samples = PsndLen;
\r
263 snd_excess_add = ((PsndRate - PsndLen * target_fps)<<16) / target_fps;
\r
264 if (snd_excess_add != 0)
\r
267 printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
\r
268 PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal);
\r
269 sndout_oss_start(PsndRate, frame_samples, is_stereo);
\r
270 sndout_oss_setvol(currentConfig.volume, currentConfig.volume);
\r
271 PicoWriteSound = updateSound;
\r
272 plat_update_volume(0, 0);
\r
273 memset(sndBuffer, 0, sizeof(sndBuffer));
\r
274 PsndOut = sndBuffer;
\r
278 void pemu_sound_stop(void)
\r
282 void pemu_sound_wait(void)
\r
284 // don't need to do anything, writes will block by themselves
\r
287 void plat_debug_cat(char *str)
\r
291 void emu_video_mode_change(int start_line, int line_count, int is_32cols)
\r
293 // clear whole screen in all buffers
\r
294 memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
\r
297 void pemu_loop_prep(void)
\r
300 osd_text = osd_text16;
\r
302 pemu_sound_start();
\r
305 void pemu_loop_end(void)
\r
307 int po_old = PicoOpt;
\r
308 int eo_old = currentConfig.EmuOpt;
\r
311 memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
\r
313 /* do one more frame for menu bg */
\r
314 PicoOpt &= ~POPT_ALT_RENDERER;
\r
315 PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES;
\r
317 PicoDrawSetOutFormat(PDF_RGB555, 1);
\r
318 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
319 PicoDraw32xSetFrameMode(0, 0);
\r
320 Pico.m.dirtyPal = 1;
\r
324 currentConfig.EmuOpt = eo_old;
\r
327 void plat_wait_till_us(unsigned int us_to)
\r
331 now = plat_get_ticks_us();
\r
333 while ((signed int)(us_to - now) > 512)
\r
336 now = plat_get_ticks_us();
\r
340 const char *plat_get_credits(void)
\r
342 return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n"
\r
344 "fDave: Cyclone 68000 core,\n"
\r
345 " base code of PicoDrive\n"
\r
346 "Reesy & FluBBa: DrZ80 core\n"
\r
347 "MAME devs: YM2612 and SN76496 cores\n"
\r
348 "rlyeh and others: minimal SDK\n"
\r
349 "Squidge: mmuhack\n"
\r
350 "Dzz: ARM940 sample\n"
\r
351 "GnoStiC / Puck2099: USB joy code\n"
\r
352 "craigix: GP2X hardware\n"
\r
353 "ketchupgun: skin design\n"
\r
355 "special thanks (for docs, ideas):\n"
\r
356 " Charles MacDonald, Haze,\n"
\r
357 " Stephane Dallongeville,\n"
\r
358 " Lordus, Exophase, Rokas,\n"
\r
359 " Nemesis, Tasco Deluxe";
\r