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 const char *renderer_names[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL };
\r
21 const char *renderer_names32x[] = { "accurate", "faster", "fastest", NULL };
\r
22 enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT };
\r
25 void pemu_prep_defconfig(void)
\r
29 void pemu_validate_config(void)
\r
32 // PicoOpt &= ~POPT_EXT_FM;
\r
33 PicoOpt &= ~POPT_EN_SVP_DRC;
\r
36 // FIXME: dupes from GP2X, need cleanup
\r
37 static void (*osd_text)(int x, int y, const char *text);
\r
40 static void osd_text8(int x, int y, const char *text)
\r
42 int len = strlen(text)*8;
\r
46 for (h = 0; h < 8; h++) {
\r
47 offs = (x + g_screen_width * (y+h)) & ~3;
\r
48 p = (int *) ((char *)g_screen_ptr + offs);
\r
49 for (i = len; i; i--, p++)
\r
52 emu_text_out8(x, y, text);
\r
56 static void osd_text16(int x, int y, const char *text)
\r
58 int len = strlen(text)*8;
\r
62 for (h = 0; h < 8; h++) {
\r
63 offs = (x + g_screen_width * (y+h)) & ~1;
\r
64 p = (int *) ((short *)g_screen_ptr + offs);
\r
65 for (i = len; i; i--, p++)
\r
66 *p = (*p >> 2) & 0x39e7;
\r
68 emu_text_out16(x, y, text);
\r
71 static void draw_cd_leds(void)
\r
73 int led_reg, pitch, scr_offs, led_offs;
\r
74 led_reg = Pico_mcd->s68k_regs[0];
\r
78 scr_offs = pitch * 2 + 4;
\r
80 if (currentConfig.renderer != RT_16BIT) {
\r
81 #define p(x) px[(x) >> 2]
\r
83 unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs);
\r
84 unsigned int col_g = (led_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;
\r
85 unsigned int col_r = (led_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;
\r
86 p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
\r
87 p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
\r
90 #define p(x) px[(x)*2 >> 2] = px[((x)*2 >> 2) + 1]
\r
92 unsigned int *px = (unsigned int *)((short *)g_screen_ptr + scr_offs);
\r
93 unsigned int col_g = (led_reg & 2) ? 0x06000600 : 0;
\r
94 unsigned int col_r = (led_reg & 1) ? 0xc000c000 : 0;
\r
95 p(pitch*0) = p(pitch*1) = p(pitch*2) = col_g;
\r
96 p(pitch*0 + led_offs) = p(pitch*1 + led_offs) = p(pitch*2 + led_offs) = col_r;
\r
101 void pemu_finalize_frame(const char *fps, const char *notice)
\r
103 if (currentConfig.renderer != RT_16BIT && !(PicoAHW & PAHW_32X)) {
\r
104 unsigned short *pd = (unsigned short *)g_screen_ptr + 8 * g_screen_width;
\r
105 unsigned char *ps = PicoDraw2FB + 328*8 + 8;
\r
106 unsigned short *pal = HighPal;
\r
108 if (Pico.m.dirtyPal)
\r
109 PicoDrawUpdateHighPal();
\r
110 for (i = 0; i < 224; i++, ps += 8)
\r
111 for (x = 0; x < 320; x++)
\r
112 *pd++ = pal[*ps++];
\r
115 if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) {
\r
117 osd_text(4, g_screen_height - 8, notice);
\r
118 if (currentConfig.EmuOpt & EOPT_SHOW_FPS)
\r
119 osd_text(g_screen_width - 60, g_screen_height - 8, fps);
\r
121 if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS))
\r
125 static void apply_renderer(void)
\r
127 switch (currentConfig.renderer) {
\r
129 PicoOpt &= ~POPT_ALT_RENDERER;
\r
130 PicoDrawSetOutFormat(PDF_RGB555, 0);
\r
131 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
134 PicoOpt &= ~POPT_ALT_RENDERER;
\r
135 PicoDrawSetOutFormat(PDF_8BIT, 0);
\r
136 PicoDrawSetOutBuf(PicoDraw2FB + 8, 328);
\r
139 PicoOpt |= POPT_ALT_RENDERER;
\r
140 PicoDrawSetOutFormat(PDF_NONE, 0);
\r
144 if (PicoAHW & PAHW_32X) {
\r
146 if (currentConfig.renderer == RT_16BIT)
\r
149 PicoDrawSetOutFormat(PDF_NONE, 0);
\r
150 PicoDraw32xSetFrameMode(1, only_32x);
\r
151 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
153 //PicoDraw32xSetFrameMode(0, 0);
\r
154 //PicoDrawSetOutFormat(PDF_RGB555, 1);
\r
157 void plat_video_toggle_renderer(int change, int is_menu)
\r
159 currentConfig.renderer += change;
\r
160 if (currentConfig.renderer >= RT_COUNT)
\r
161 currentConfig.renderer = 0;
\r
162 else if (currentConfig.renderer < 0)
\r
163 currentConfig.renderer = RT_COUNT - 1;
\r
168 emu_status_msg(renderer_names[currentConfig.renderer]);
\r
171 void plat_video_menu_enter(int is_rom_loaded)
\r
175 void plat_video_menu_begin(void)
\r
177 g_menuscreen_ptr = g_screen_ptr;
\r
180 void plat_video_menu_end(void)
\r
185 void plat_status_msg_clear(void)
\r
187 unsigned short *d = (unsigned short *)g_screen_ptr + g_screen_width * g_screen_height;
\r
188 int l = g_screen_width * 8;
\r
189 memset32((int *)(d - l), 0, l * 2 / 4);
\r
192 void plat_status_msg_busy_next(const char *msg)
\r
194 plat_status_msg_clear();
\r
195 pemu_finalize_frame("", msg);
\r
197 emu_status_msg("");
\r
201 void plat_status_msg_busy_first(const char *msg)
\r
203 // memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
\r
204 plat_status_msg_busy_next(msg);
\r
207 void plat_update_volume(int has_changed, int is_up)
\r
211 void pemu_forced_frame(int no_scale, int do_emu)
\r
213 PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2);
\r
214 PicoDraw32xSetFrameMode(0, 0);
\r
215 PicoDrawSetCallbacks(NULL, NULL);
\r
216 Pico.m.dirtyPal = 1;
\r
218 emu_cmn_forced_frame(no_scale, do_emu);
\r
220 g_menubg_src_ptr = g_screen_ptr;
\r
223 static void oss_write_nonblocking(int len)
\r
225 // sndout_oss_can_write() is not reliable, only use with no_frmlimit
\r
226 if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))
\r
229 sndout_oss_write_nb(PsndOut, len);
\r
232 void pemu_sound_start(void)
\r
236 if (currentConfig.EmuOpt & EOPT_EN_SOUND)
\r
238 int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;
\r
240 PsndRerate(Pico.m.frame_count ? 1 : 0);
\r
242 printf("starting audio: %i len: %i stereo: %i, pal: %i\n",
\r
243 PsndRate, PsndLen, is_stereo, Pico.m.pal);
\r
244 sndout_oss_start(PsndRate, is_stereo, 1);
\r
245 sndout_oss_setvol(currentConfig.volume, currentConfig.volume);
\r
246 PicoWriteSound = oss_write_nonblocking;
\r
247 plat_update_volume(0, 0);
\r
248 memset(sndBuffer, 0, sizeof(sndBuffer));
\r
249 PsndOut = sndBuffer;
\r
253 void pemu_sound_stop(void)
\r
257 void pemu_sound_wait(void)
\r
259 // don't need to do anything, writes will block by themselves
\r
262 void plat_debug_cat(char *str)
\r
266 void emu_video_mode_change(int start_line, int line_count, int is_32cols)
\r
268 // clear whole screen in all buffers
\r
269 memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);
\r
272 void pemu_loop_prep(void)
\r
275 osd_text = osd_text16;
\r
277 pemu_sound_start();
\r
280 void pemu_loop_end(void)
\r
284 /* do one more frame for menu bg */
\r
285 pemu_forced_frame(0, 1);
\r
288 void plat_wait_till_us(unsigned int us_to)
\r
292 now = plat_get_ticks_us();
\r
294 while ((signed int)(us_to - now) > 512)
\r
297 now = plat_get_ticks_us();
\r