remove unused/unmaintained code
[picodrive.git] / platform / psp / emu.c
CommitLineData
8b99ab90 1// (c) Copyright 2007 notaz, All rights reserved.
2// Free for non-commercial use.
3
4// For commercial use, separate licencing terms must be obtained.
5
1820b5a7 6#include <sys/stat.h>
7#include <sys/types.h>
8#include <sys/syslimits.h> // PATH_MAX
9
7d4906bf 10#include <pspthreadman.h>
70357ce5 11#include <pspdisplay.h>
9112b6ce 12#include <psputils.h>
13#include <pspgu.h>
a4221917 14#include <pspaudio.h>
7d4906bf 15
16#include "psp.h"
17#include "menu.h"
18#include "emu.h"
b542be46 19#include "mp3.h"
2445b7cb 20#include "asm_utils.h"
7d4906bf 21#include "../common/emu.h"
6fc57144 22#include "../common/config.h"
7d4906bf 23#include "../common/lprintf.h"
efcba75f 24#include <pico/pico_int.h>
25#include <pico/cd/cue.h>
1820b5a7 26
9dc09829 27#define OSD_FPS_X 432
7d4906bf 28
a4221917 29// additional pspaudio imports, credits to crazyc
30int sceAudio_38553111(unsigned short samples, unsigned short freq, char unknown); // play with conversion?
31int sceAudio_5C37C0AE(void); // end play?
32int sceAudio_E0727056(int volume, void *buffer); // blocking output
33int sceAudioOutput2GetRestSample();
34
35
9112b6ce 36unsigned char *PicoDraw2FB = (unsigned char *)VRAM_CACHED_STUFF + 8; // +8 to be able to skip border with 1 quadword..
713c9224 37int engineStateSuspend;
1820b5a7 38
c060a9ab 39#define PICO_PEN_ADJUST_X 4
40#define PICO_PEN_ADJUST_Y 2
41static int pico_pen_x = 320/2, pico_pen_y = 240/2;
7d4906bf 42
a4221917 43static void sound_init(void);
44static void sound_deinit(void);
3ec29f01 45static void blit2(const char *fps, const char *notice, int lagging_behind);
7d4906bf 46static void clearArea(int full);
1820b5a7 47
f2cf8472 48int plat_get_root_dir(char *dst, int len)
1820b5a7 49{
7d4906bf 50 if (len > 0) *dst = 0;
ca482e5d 51 return 0;
1820b5a7 52}
53
8022f53d 54static void osd_text(int x, const char *text, int is_active, int clear_all)
1820b5a7 55{
8ab3e3c1 56 unsigned short *screen = is_active ? psp_video_get_active_fb() : psp_screen;
8022f53d 57 int len = clear_all ? (480 / 2) : (strlen(text) * 8 / 2);
8ab3e3c1 58 int *p, h;
59 void *tmp;
60 for (h = 0; h < 8; h++) {
61 p = (int *) (screen+x+512*(264+h));
62 p = (int *) ((int)p & ~3); // align
b542be46 63 memset32_uncached(p, 0, len);
8ab3e3c1 64 }
65 if (is_active) { tmp = psp_screen; psp_screen = screen; } // nasty pointer tricks
cc41eb4f 66 emu_text_out16(x, 264, text);
8ab3e3c1 67 if (is_active) psp_screen = tmp;
68}
7d4906bf 69
8ab3e3c1 70void emu_msg_cb(const char *msg)
71{
8022f53d 72 osd_text(4, msg, 1, 1);
7d4906bf 73 noticeMsgTime = sceKernelGetSystemTimeLow() - 2000000;
74
75 /* assumption: emu_msg_cb gets called only when something slow is about to happen */
76 reset_timing = 1;
1820b5a7 77}
78
f2cf8472 79/* FIXME: move to plat */
1820b5a7 80void emu_Init(void)
81{
a4221917 82 sound_init();
1820b5a7 83}
84
85void emu_Deinit(void)
86{
a4221917 87 sound_deinit();
1820b5a7 88}
89
f2cf8472 90void pemu_prep_defconfig(void)
6fc57144 91{
6fc57144 92 defaultConfig.s_PsndRate = 22050;
6fc57144 93 defaultConfig.s_PicoCDBuffers = 64;
6fc57144 94 defaultConfig.CPUclock = 333;
95 defaultConfig.KeyBinds[ 4] = 1<<0; // SACB RLDU
96 defaultConfig.KeyBinds[ 6] = 1<<1;
97 defaultConfig.KeyBinds[ 7] = 1<<2;
98 defaultConfig.KeyBinds[ 5] = 1<<3;
99 defaultConfig.KeyBinds[14] = 1<<4;
100 defaultConfig.KeyBinds[13] = 1<<5;
101 defaultConfig.KeyBinds[15] = 1<<6;
102 defaultConfig.KeyBinds[ 3] = 1<<7;
103 defaultConfig.KeyBinds[12] = 1<<26; // switch rnd
104 defaultConfig.KeyBinds[ 8] = 1<<27; // save state
105 defaultConfig.KeyBinds[ 9] = 1<<28; // load state
106 defaultConfig.KeyBinds[28] = 1<<0; // num "buttons"
107 defaultConfig.KeyBinds[30] = 1<<1;
108 defaultConfig.KeyBinds[31] = 1<<2;
109 defaultConfig.KeyBinds[29] = 1<<3;
110 defaultConfig.scaling = 1; // bilinear filtering for psp
111 defaultConfig.scale = 1.20; // fullscreen
112 defaultConfig.hscale40 = 1.25;
113 defaultConfig.hscale32 = 1.56;
114}
115
7d4906bf 116
8ab3e3c1 117extern void amips_clut(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);
e5fa9817 118extern void amips_clut_6bit(unsigned short *dst, unsigned char *src, unsigned short *pal, int count);
119
c060a9ab 120static void (*amips_clut_f)(unsigned short *dst, unsigned char *src, unsigned short *pal, int count) = NULL;
9112b6ce 121
122struct Vertex
123{
124 short u,v;
125 short x,y,z;
126};
127
8ab3e3c1 128static struct Vertex __attribute__((aligned(4))) g_vertices[2];
129static unsigned short __attribute__((aligned(16))) localPal[0x100];
130static int dynamic_palette = 0, need_pal_upload = 0, blit_16bit_mode = 0;
131static int fbimg_offs = 0;
132
133static void set_scaling_params(void)
9112b6ce 134{
b542be46 135 int src_width, fbimg_width, fbimg_height, fbimg_xoffs, fbimg_yoffs, border_hack = 0;
8ab3e3c1 136 g_vertices[0].x = g_vertices[0].y =
137 g_vertices[0].z = g_vertices[1].z = 0;
138
139 fbimg_height = (int)(240.0 * currentConfig.scale + 0.5);
140 if (Pico.video.reg[12] & 1) {
141 fbimg_width = (int)(320.0 * currentConfig.scale * currentConfig.hscale40 + 0.5);
142 src_width = 320;
143 } else {
144 fbimg_width = (int)(256.0 * currentConfig.scale * currentConfig.hscale32 + 0.5);
145 src_width = 256;
146 }
9112b6ce 147
b542be46 148 if (fbimg_width & 1) fbimg_width++; // make even
149 if (fbimg_height & 1) fbimg_height++;
150
8ab3e3c1 151 if (fbimg_width >= 480) {
152 g_vertices[0].u = (fbimg_width-480)/2;
b542be46 153 g_vertices[1].u = src_width - (fbimg_width-480)/2 - 1;
8ab3e3c1 154 fbimg_width = 480;
155 fbimg_xoffs = 0;
156 } else {
157 g_vertices[0].u = 0;
158 g_vertices[1].u = src_width;
159 fbimg_xoffs = 240 - fbimg_width/2;
160 }
c6196c0f 161 if (fbimg_width > 320 && fbimg_width <= 480) border_hack = 1;
8ab3e3c1 162
163 if (fbimg_height >= 272) {
164 g_vertices[0].v = (fbimg_height-272)/2;
165 g_vertices[1].v = 240 - (fbimg_height-272)/2;
166 fbimg_height = 272;
167 fbimg_yoffs = 0;
168 } else {
169 g_vertices[0].v = 0;
170 g_vertices[1].v = 240;
171 fbimg_yoffs = 136 - fbimg_height/2;
172 }
173
174 g_vertices[1].x = fbimg_width;
175 g_vertices[1].y = fbimg_height;
176 if (fbimg_xoffs < 0) fbimg_xoffs = 0;
177 if (fbimg_yoffs < 0) fbimg_yoffs = 0;
b542be46 178 if (border_hack) {
179 g_vertices[0].u++;
180 g_vertices[0].x++;
181 g_vertices[1].u--;
182 g_vertices[1].x--;
183 }
8ab3e3c1 184 fbimg_offs = (fbimg_yoffs*512 + fbimg_xoffs) * 2; // dst is always 16bit
185
80db4442 186 /*
8ab3e3c1 187 lprintf("set_scaling_params:\n");
188 lprintf("offs: %i, %i\n", fbimg_xoffs, fbimg_yoffs);
189 lprintf("xy0, xy1: %i, %i; %i, %i\n", g_vertices[0].x, g_vertices[0].y, g_vertices[1].x, g_vertices[1].y);
190 lprintf("uv0, uv1: %i, %i; %i, %i\n", g_vertices[0].u, g_vertices[0].v, g_vertices[1].u, g_vertices[1].v);
80db4442 191 */
9112b6ce 192}
193
e5fa9817 194static void do_pal_update(int allow_sh, int allow_as)
7d4906bf 195{
8ab3e3c1 196 unsigned int *dpal=(void *)localPal;
197 int i;
9112b6ce 198
2445b7cb 199 //for (i = 0x3f/2; i >= 0; i--)
200 // dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4);
6fc57144 201 do_pal_convert(localPal, Pico.cram, currentConfig.gamma, currentConfig.gamma2);
9112b6ce 202
e5fa9817 203 Pico.m.dirtyPal = 0;
204 need_pal_upload = 1;
205
80db4442 206 if (allow_sh && (Pico.video.reg[0xC]&8)) // shadow/hilight?
8ab3e3c1 207 {
208 // shadowed pixels
9112b6ce 209 for (i = 0x3f/2; i >= 0; i--)
2445b7cb 210 dpal[0x20|i] = dpal[0x60|i] = (dpal[i]>>1)&0x7bcf7bcf;
8ab3e3c1 211 // hilighted pixels
212 for (i = 0x3f; i >= 0; i--) {
2445b7cb 213 int t=localPal[i]&0xf79e;t+=0x4208;
214 if (t&0x20) t|=0x1e;
215 if (t&0x800) t|=0x780;
216 if (t&0x10000) t|=0xf000;
217 t&=0xf79e;
8ab3e3c1 218 localPal[0x80|i]=(unsigned short)t;
219 }
220 localPal[0xe0] = 0;
c060a9ab 221 localPal[0xf0] = 0x001f;
9112b6ce 222 }
f8af9634 223 else if (allow_as && (rendstatus & PDRAW_SPR_LO_ON_HI))
e5fa9817 224 {
fcf94fcc 225 memcpy32((int *)dpal+0x80/2, (void *)localPal, 0x40*2/4);
e5fa9817 226 }
8ab3e3c1 227}
9112b6ce 228
8ab3e3c1 229static void do_slowmode_lines(int line_to)
230{
231 int line = 0, line_len = (Pico.video.reg[12]&1) ? 320 : 256;
232 unsigned short *dst = (unsigned short *)VRAM_STUFF + 512*240/2;
233 unsigned char *src = (unsigned char *)VRAM_CACHED_STUFF + 16;
234 if (!(Pico.video.reg[1]&8)) { line = 8; dst += 512*8; src += 512*8; }
9112b6ce 235
8ab3e3c1 236 for (; line < line_to; line++, dst+=512, src+=512)
e5fa9817 237 amips_clut_f(dst, src, localPal, line_len);
8ab3e3c1 238}
9112b6ce 239
8ab3e3c1 240static void EmuScanPrepare(void)
241{
242 HighCol = (unsigned char *)VRAM_CACHED_STUFF + 8;
243 if (!(Pico.video.reg[1]&8)) HighCol += 8*512;
9112b6ce 244
ae2bf944 245 if (dynamic_palette > 0)
246 dynamic_palette--;
fcf94fcc 247
8ab3e3c1 248 if (Pico.m.dirtyPal)
e5fa9817 249 do_pal_update(1, 1);
f8af9634 250 if ((rendstatus & PDRAW_SPR_LO_ON_HI) && !(Pico.video.reg[0xC]&8))
e5fa9817 251 amips_clut_f = amips_clut_6bit;
252 else amips_clut_f = amips_clut;
8ab3e3c1 253}
254
6fc57144 255static int EmuScanSlowBegin(unsigned int num)
256{
6fc57144 257 if (!dynamic_palette)
258 HighCol = (unsigned char *)VRAM_CACHED_STUFF + num * 512 + 8;
259
260 return 0;
261}
262
263static int EmuScanSlowEnd(unsigned int num)
8ab3e3c1 264{
8ab3e3c1 265 if (Pico.m.dirtyPal) {
266 if (!dynamic_palette) {
267 do_slowmode_lines(num);
ae2bf944 268 dynamic_palette = 3; // last for 2 more frames
8ab3e3c1 269 }
fcf94fcc 270 do_pal_update(1, 1);
8ab3e3c1 271 }
272
273 if (dynamic_palette) {
274 int line_len = (Pico.video.reg[12]&1) ? 320 : 256;
275 void *dst = (char *)VRAM_STUFF + 512*240 + 512*2*num;
e5fa9817 276 amips_clut_f(dst, HighCol + 8, localPal, line_len);
6fc57144 277 }
9112b6ce 278
7d4906bf 279 return 0;
280}
281
8ab3e3c1 282static void blitscreen_clut(void)
9112b6ce 283{
8ab3e3c1 284 int offs = fbimg_offs;
285 offs += (psp_screen == VRAM_FB0) ? VRAMOFFS_FB0 : VRAMOFFS_FB1;
9112b6ce 286
9112b6ce 287 sceGuSync(0,0); // sync with prev
288 sceGuStart(GU_DIRECT, guCmdList);
8ab3e3c1 289 sceGuDrawBuffer(GU_PSM_5650, (void *)offs, 512); // point to back buffer
9112b6ce 290
8ab3e3c1 291 if (dynamic_palette)
292 {
c060a9ab 293 if (!blit_16bit_mode) { // the current mode is not 16bit
8ab3e3c1 294 sceGuTexMode(GU_PSM_5650, 0, 0, 0);
295 sceGuTexImage(0,512,512,512,(char *)VRAM_STUFF + 512*240);
9112b6ce 296
8ab3e3c1 297 blit_16bit_mode = 1;
298 }
9112b6ce 299 }
8ab3e3c1 300 else
9112b6ce 301 {
8ab3e3c1 302 if (blit_16bit_mode) {
303 sceGuClutMode(GU_PSM_5650,0,0xff,0);
304 sceGuTexMode(GU_PSM_T8,0,0,0); // 8-bit image
305 sceGuTexImage(0,512,512,512,(char *)VRAM_STUFF + 16);
306 blit_16bit_mode = 0;
307 }
9112b6ce 308
8ab3e3c1 309 if ((PicoOpt&0x10) && Pico.m.dirtyPal)
e5fa9817 310 do_pal_update(0, 0);
80db4442 311
312 sceKernelDcacheWritebackAll();
9112b6ce 313
8ab3e3c1 314 if (need_pal_upload) {
315 need_pal_upload = 0;
316 sceGuClutLoad((256/8), localPal); // upload 32*8 entries (256)
317 }
318 }
7d4906bf 319
8ab3e3c1 320#if 1
321 if (g_vertices[0].u == 0 && g_vertices[1].u == g_vertices[1].x)
322 {
323 struct Vertex* vertices;
324 int x;
7d4906bf 325
8ab3e3c1 326 #define SLICE_WIDTH 32
327 for (x = 0; x < g_vertices[1].x; x += SLICE_WIDTH)
328 {
329 // render sprite
330 vertices = (struct Vertex*)sceGuGetMemory(2 * sizeof(struct Vertex));
331 memcpy(vertices, g_vertices, 2 * sizeof(struct Vertex));
332 vertices[0].u = vertices[0].x = x;
333 vertices[1].u = vertices[1].x = x + SLICE_WIDTH;
334 sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,vertices);
335 }
336 // lprintf("listlen: %iB\n", sceGuCheckList()); // ~480 only
7d4906bf 337 }
8ab3e3c1 338 else
339#endif
340 sceGuDrawArray(GU_SPRITES,GU_TEXTURE_16BIT|GU_VERTEX_16BIT|GU_TRANSFORM_2D,2,0,g_vertices);
341
342 sceGuFinish();
7d4906bf 343}
344
345
346static void cd_leds(void)
347{
9caf44b5 348 unsigned int reg, col_g, col_r, *p;
7d4906bf 349
9caf44b5 350 reg = Pico_mcd->s68k_regs[0];
7d4906bf 351
352 p = (unsigned int *)((short *)psp_screen + 512*2+4+2);
9caf44b5 353 col_g = (reg & 2) ? 0x06000600 : 0;
354 col_r = (reg & 1) ? 0x00180018 : 0;
7d4906bf 355 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2;
356 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += 512/2 - 12/2;
357 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;
358}
359
c060a9ab 360static void draw_pico_ptr(void)
361{
362 unsigned char *p = (unsigned char *)VRAM_STUFF + 16;
363
364 // only if pen enabled and for 8bit mode
365 if (pico_inp_mode == 0 || blit_16bit_mode) return;
366
367 p += 512 * (pico_pen_y + PICO_PEN_ADJUST_Y);
368 p += pico_pen_x + PICO_PEN_ADJUST_X;
369 p[ -1] = 0xe0; p[ 0] = 0xf0; p[ 1] = 0xe0;
370 p[ 511] = 0xf0; p[ 512] = 0xf0; p[ 513] = 0xf0;
371 p[1023] = 0xe0; p[1024] = 0xf0; p[1025] = 0xe0;
372}
373
374
b542be46 375#if 0
8ab3e3c1 376static void dbg_text(void)
7d4906bf 377{
8ab3e3c1 378 int *p, h, len;
379 char text[128];
7d4906bf 380
8ab3e3c1 381 sprintf(text, "sl: %i, 16b: %i", g_vertices[0].u == 0 && g_vertices[1].u == g_vertices[1].x, blit_16bit_mode);
382 len = strlen(text) * 8 / 2;
383 for (h = 0; h < 8; h++) {
384 p = (int *) ((unsigned short *) psp_screen+2+512*(256+h));
385 p = (int *) ((int)p & ~3); // align
b542be46 386 memset32_uncached(p, 0, len);
7d4906bf 387 }
cc41eb4f 388 emu_text_out16(2, 256, text);
8ab3e3c1 389}
b542be46 390#endif
8ab3e3c1 391
392/* called after rendering is done, but frame emulation is not finished */
393void blit1(void)
394{
395 if (PicoOpt&0x10)
7d4906bf 396 {
8ab3e3c1 397 int i;
398 unsigned char *pd;
399 // clear top and bottom trash
400 for (pd = PicoDraw2FB+8, i = 8; i > 0; i--, pd += 512)
401 memset32((int *)pd, 0xe0e0e0e0, 320/4);
402 for (pd = PicoDraw2FB+512*232+8, i = 8; i > 0; i--, pd += 512)
403 memset32((int *)pd, 0xe0e0e0e0, 320/4);
7d4906bf 404 }
8ab3e3c1 405
c060a9ab 406 if (PicoAHW & PAHW_PICO)
407 draw_pico_ptr();
408
8ab3e3c1 409 blitscreen_clut();
410}
411
412
3ec29f01 413static void blit2(const char *fps, const char *notice, int lagging_behind)
8ab3e3c1 414{
3ec29f01 415 int vsync = 0, emu_opt = currentConfig.EmuOpt;
7d4906bf 416
417 if (notice || (emu_opt & 2)) {
8022f53d 418 if (notice) osd_text(4, notice, 0, 0);
419 if (emu_opt & 2) osd_text(OSD_FPS_X, fps, 0, 0);
7d4906bf 420 }
421
b542be46 422 //dbg_text();
8ab3e3c1 423
602133e1 424 if ((emu_opt & 0x400) && (PicoAHW & PAHW_MCD))
7d4906bf 425 cd_leds();
426
3ec29f01 427 if (currentConfig.EmuOpt & 0x2000) { // want vsync
428 if (!(currentConfig.EmuOpt & 0x10000) || !lagging_behind) vsync = 1;
429 }
430
431 psp_video_flip(vsync);
7d4906bf 432}
433
434// clears whole screen or just the notice area (in all buffers)
435static void clearArea(int full)
436{
437 if (full) {
b542be46 438 memset32_uncached(psp_screen, 0, 512*272*2/4);
7d4906bf 439 psp_video_flip(0);
b542be46 440 memset32_uncached(psp_screen, 0, 512*272*2/4);
8ab3e3c1 441 memset32(VRAM_CACHED_STUFF, 0xe0e0e0e0, 512*240/4);
442 memset32((int *)VRAM_CACHED_STUFF+512*240/4, 0, 512*240*2/4);
7d4906bf 443 } else {
444 void *fb = psp_video_get_active_fb();
b542be46 445 memset32_uncached((int *)((char *)psp_screen + 512*264*2), 0, 512*8*2/4);
446 memset32_uncached((int *)((char *)fb + 512*264*2), 0, 512*8*2/4);
7d4906bf 447 }
448}
449
450static void vidResetMode(void)
451{
9112b6ce 452 // setup GU
453 sceGuSync(0,0); // sync with prev
454 sceGuStart(GU_DIRECT, guCmdList);
455
456 sceGuClutMode(GU_PSM_5650,0,0xff,0);
9112b6ce 457 sceGuTexMode(GU_PSM_T8,0,0,0); // 8-bit image
458 sceGuTexFunc(GU_TFX_REPLACE,GU_TCC_RGB);
8ab3e3c1 459 if (currentConfig.scaling)
460 sceGuTexFilter(GU_LINEAR, GU_LINEAR);
461 else sceGuTexFilter(GU_NEAREST, GU_NEAREST);
9112b6ce 462 sceGuTexScale(1.0f,1.0f);
463 sceGuTexOffset(0.0f,0.0f);
9112b6ce 464
8ab3e3c1 465 sceGuTexImage(0,512,512,512,(char *)VRAM_STUFF + 16);
9112b6ce 466
8ab3e3c1 467 // slow rend.
5a681086 468 PicoDrawSetOutFormat(PDF_NONE, 0);
f4750ee0 469 PicoDrawSetCallbacks(EmuScanSlowBegin, EmuScanSlowEnd);
9112b6ce 470
8ab3e3c1 471 localPal[0xe0] = 0;
c060a9ab 472 localPal[0xf0] = 0x001f;
7d4906bf 473 Pico.m.dirtyPal = 1;
8ab3e3c1 474 blit_16bit_mode = dynamic_palette = 0;
7d4906bf 475
9112b6ce 476 sceGuFinish();
8ab3e3c1 477 set_scaling_params();
9112b6ce 478 sceGuSync(0,0);
7d4906bf 479}
8ab3e3c1 480
f2cf8472 481void plat_debug_cat(char *str)
fcf94fcc 482{
483 strcat(str, blit_16bit_mode ? "soft clut\n" : "hard clut\n");
484}
485
a4221917 486
487/* sound stuff */
88b3d7c1 488#define SOUND_BLOCK_SIZE_NTSC (1470*2) // 1024 // 1152
489#define SOUND_BLOCK_SIZE_PAL (1764*2)
4b167c12 490#define SOUND_BLOCK_COUNT 8
a4221917 491
e41da5ce 492static short __attribute__((aligned(4))) sndBuffer[SOUND_BLOCK_SIZE_PAL*SOUND_BLOCK_COUNT + 44100/50*2];
493static short *snd_playptr = NULL, *sndBuffer_endptr = NULL;
494static int samples_made = 0, samples_done = 0, samples_block = 0;
a4221917 495static int sound_thread_exit = 0;
496static SceUID sound_sem = -1;
497
498static void writeSound(int len);
499
500static int sound_thread(SceSize args, void *argp)
7d4906bf 501{
4b167c12 502 int ret = 0;
a4221917 503
c5b61ac2 504 lprintf("sthr: started, priority %i\n", sceKernelGetThreadCurrentPriority());
a4221917 505
506 while (!sound_thread_exit)
507 {
508 if (samples_made - samples_done < samples_block) {
88b3d7c1 509 // wait for data (use at least 2 blocks)
110df09c 510 //lprintf("sthr: wait... (%i)\n", samples_made - samples_done);
88b3d7c1 511 while (samples_made - samples_done <= samples_block*2 && !sound_thread_exit)
512 ret = sceKernelWaitSema(sound_sem, 1, 0);
4b167c12 513 if (ret < 0) lprintf("sthr: sceKernelWaitSema: %i\n", ret);
a4221917 514 continue;
515 }
516
4b167c12 517 // lprintf("sthr: got data: %i\n", samples_made - samples_done);
a4221917 518
519 ret = sceAudio_E0727056(PSP_AUDIO_VOLUME_MAX, snd_playptr);
520
521 samples_done += samples_block;
522 snd_playptr += samples_block;
e41da5ce 523 if (snd_playptr >= sndBuffer_endptr)
a4221917 524 snd_playptr = sndBuffer;
110df09c 525 // 1.5 kernel returns 0, newer ones return # of samples queued
526 if (ret < 0)
527 lprintf("sthr: sceAudio_E0727056: %08x; pos %i/%i\n", ret, samples_done, samples_made);
88b3d7c1 528
529 // shouln't happen, but just in case
530 if (samples_made - samples_done >= samples_block*3) {
71de3cd9 531 //lprintf("sthr: block skip (%i)\n", samples_made - samples_done);
88b3d7c1 532 samples_done += samples_block; // skip
533 snd_playptr += samples_block;
534 }
535
a4221917 536 }
537
538 lprintf("sthr: exit\n");
539 sceKernelExitDeleteThread(0);
540 return 0;
541}
542
543static void sound_init(void)
544{
545 SceUID thid;
110df09c 546 int ret;
a4221917 547
548 sound_sem = sceKernelCreateSema("sndsem", 0, 0, 1, NULL);
549 if (sound_sem < 0) lprintf("sceKernelCreateSema() failed: %i\n", sound_sem);
550
c5b61ac2 551 samples_made = samples_done = 0;
552 samples_block = SOUND_BLOCK_SIZE_NTSC; // make sure it goes to sema
a4221917 553 sound_thread_exit = 0;
554 thid = sceKernelCreateThread("sndthread", sound_thread, 0x12, 0x10000, 0, NULL);
555 if (thid >= 0)
556 {
110df09c 557 ret = sceKernelStartThread(thid, 0, 0);
558 if (ret < 0) lprintf("sound_init: sceKernelStartThread returned %08x\n", ret);
a4221917 559 }
560 else
561 lprintf("sceKernelCreateThread failed: %i\n", thid);
562}
563
f2cf8472 564void pemu_sound_start(void)
a4221917 565{
566 static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;
567 int ret, stereo;
568
569 samples_made = samples_done = 0;
570
571 if (PsndRate != PsndRate_old || (PicoOpt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
9d917eea 572 PsndRerate(Pico.m.frame_count ? 1 : 0);
a4221917 573 }
574 stereo=(PicoOpt&8)>>3;
e41da5ce 575
576 samples_block = Pico.m.pal ? SOUND_BLOCK_SIZE_PAL : SOUND_BLOCK_SIZE_NTSC;
88b3d7c1 577 if (PsndRate <= 22050) samples_block /= 2;
e41da5ce 578 sndBuffer_endptr = &sndBuffer[samples_block*SOUND_BLOCK_COUNT];
a4221917 579
580 lprintf("starting audio: %i, len: %i, stereo: %i, pal: %i, block samples: %i\n",
581 PsndRate, PsndLen, stereo, Pico.m.pal, samples_block);
582
8022f53d 583 // while (sceAudioOutput2GetRestSample() > 0) psp_msleep(100);
584 // sceAudio_5C37C0AE();
e41da5ce 585 ret = sceAudio_38553111(samples_block/2, PsndRate, 2); // seems to not need that stupid 64byte alignment
a4221917 586 if (ret < 0) {
587 lprintf("sceAudio_38553111() failed: %i\n", ret);
b24e0f6c 588 emu_status_msg("sound init failed (%i), snd disabled", ret);
d34a42f9 589 currentConfig.EmuOpt &= ~EOPT_EN_SOUND;
a4221917 590 } else {
a4221917 591 PicoWriteSound = writeSound;
592 memset32((int *)(void *)sndBuffer, 0, sizeof(sndBuffer)/4);
e41da5ce 593 snd_playptr = sndBuffer_endptr - samples_block;
594 samples_made = samples_block; // send 1 empty block first..
a4221917 595 PsndOut = sndBuffer;
596 PsndRate_old = PsndRate;
597 PicoOpt_old = PicoOpt;
598 pal_old = Pico.m.pal;
599 }
600}
601
f2cf8472 602void pemu_sound_stop(void)
a4221917 603{
8022f53d 604 int i;
605 if (samples_done == 0)
606 {
607 // if no data is written between sceAudio_38553111 and sceAudio_5C37C0AE calls,
608 // we get a deadlock on next sceAudio_38553111 call
609 // so this is yet another workaround:
610 memset32((int *)(void *)sndBuffer, 0, samples_block*4/4);
611 samples_made = samples_block * 3;
612 sceKernelSignalSema(sound_sem, 1);
613 }
614 sceKernelDelayThread(100*1000);
80db4442 615 samples_made = samples_done = 0;
8022f53d 616 for (i = 0; sceAudioOutput2GetRestSample() > 0 && i < 16; i++)
e41da5ce 617 psp_msleep(100);
618 sceAudio_5C37C0AE();
a4221917 619}
620
7b3f44c6 621/* wait until we can write more sound */
f2cf8472 622void pemu_sound_wait(void)
7b3f44c6 623{
624 // TODO: test this
625 while (!sound_thread_exit && samples_made - samples_done > samples_block * 4)
626 psp_msleep(10);
627}
628
a4221917 629static void sound_deinit(void)
630{
631 sound_thread_exit = 1;
632 sceKernelSignalSema(sound_sem, 1);
80db4442 633 sceKernelDeleteSema(sound_sem);
634 sound_sem = -1;
a4221917 635}
636
637static void writeSound(int len)
638{
639 int ret;
7d4906bf 640
a4edca53 641 PsndOut += len / 2;
e41da5ce 642 /*if (PsndOut > sndBuffer_endptr) {
a4221917 643 memcpy32((int *)(void *)sndBuffer, (int *)endptr, (PsndOut - endptr + 1) / 2);
644 PsndOut = &sndBuffer[PsndOut - endptr];
e41da5ce 645 lprintf("mov\n");
a4221917 646 }
e41da5ce 647 else*/
4b167c12 648 if (PsndOut > sndBuffer_endptr) lprintf("snd oflow %i!\n", PsndOut - sndBuffer_endptr);
e41da5ce 649 if (PsndOut >= sndBuffer_endptr)
650 PsndOut = sndBuffer;
a4221917 651
652 // signal the snd thread
a4edca53 653 samples_made += len / 2;
88b3d7c1 654 if (samples_made - samples_done > samples_block*2) {
e41da5ce 655 // lprintf("signal, %i/%i\n", samples_done, samples_made);
a4221917 656 ret = sceKernelSignalSema(sound_sem, 1);
4b167c12 657 //if (ret < 0) lprintf("snd signal ret %08x\n", ret);
a4221917 658 }
7d4906bf 659}
a4221917 660
7d4906bf 661
662static void SkipFrame(void)
663{
664 PicoSkipFrame=1;
665 PicoFrame();
666 PicoSkipFrame=0;
667}
668
45285368 669void pemu_forced_frame(int no_scale, int do_emu)
7d4906bf 670{
671 int po_old = PicoOpt;
672 int eo_old = currentConfig.EmuOpt;
673
45285368 674 PicoOpt &= ~POPT_ALT_RENDERER;
675 PicoOpt |= POPT_ACC_SPRITES;
676 if (!no_scale)
677 PicoOpt |= POPT_EN_SOFTSCALE;
7d4906bf 678 currentConfig.EmuOpt |= 0x80;
679
8ab3e3c1 680 vidResetMode();
681 memset32(VRAM_CACHED_STUFF, 0xe0e0e0e0, 512*8/4); // borders
682 memset32((int *)VRAM_CACHED_STUFF + 512*232/4, 0xe0e0e0e0, 512*8/4);
b542be46 683 memset32_uncached((int *)psp_screen + 512*264*2/4, 0, 512*8*2/4);
8ab3e3c1 684
5a681086 685 PicoDrawSetOutFormat(PDF_NONE, 0);
f4750ee0 686 PicoDrawSetCallbacks(EmuScanSlowBegin, EmuScanSlowEnd);
9112b6ce 687 EmuScanPrepare();
7d4906bf 688 PicoFrameDrawOnly();
8ab3e3c1 689 blit1();
690 sceGuSync(0,0);
7d4906bf 691
692 PicoOpt = po_old;
693 currentConfig.EmuOpt = eo_old;
694}
695
696
c060a9ab 697static void RunEventsPico(unsigned int events, unsigned int keys)
698{
699 emu_RunEventsPico(events);
700
701 if (pico_inp_mode != 0)
702 {
703 PicoPad[0] &= ~0x0f; // release UDLR
e5ab6faf 704 if (keys & PBTN_UP) { pico_pen_y--; if (pico_pen_y < 8) pico_pen_y = 8; }
705 if (keys & PBTN_DOWN) { pico_pen_y++; if (pico_pen_y > 224-PICO_PEN_ADJUST_Y) pico_pen_y = 224-PICO_PEN_ADJUST_Y; }
706 if (keys & PBTN_LEFT) { pico_pen_x--; if (pico_pen_x < 0) pico_pen_x = 0; }
707 if (keys & PBTN_RIGHT) {
c060a9ab 708 int lim = (Pico.video.reg[12]&1) ? 319 : 255;
709 pico_pen_x++;
710 if (pico_pen_x > lim-PICO_PEN_ADJUST_X)
711 pico_pen_x = lim-PICO_PEN_ADJUST_X;
712 }
713 PicoPicohw.pen_pos[0] = pico_pen_x;
714 if (!(Pico.video.reg[12]&1)) PicoPicohw.pen_pos[0] += pico_pen_x/4;
715 PicoPicohw.pen_pos[0] += 0x3c;
716 PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);
717 }
718}
719
7d4906bf 720static void RunEvents(unsigned int which)
721{
722 if (which & 0x1800) // save or load (but not both)
723 {
724 int do_it = 1;
725
a47dd663 726 if ( emu_check_save_file(state_slot) &&
7d4906bf 727 (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load
728 (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) // save
729 {
730 int keys;
3ec29f01 731 sceGuSync(0,0);
732 blit2("", (which & 0x1000) ? "LOAD STATE? (X=yes, O=no)" : "OVERWRITE SAVE? (X=yes, O=no)", 0);
e5ab6faf 733 while( !((keys = psp_pad_read(1)) & (PBTN_X|PBTN_CIRCLE)) )
7d4906bf 734 psp_msleep(50);
e5ab6faf 735 if (keys & PBTN_CIRCLE) do_it = 0;
736 while( ((keys = psp_pad_read(1)) & (PBTN_X|PBTN_CIRCLE)) ) // wait for release
7d4906bf 737 psp_msleep(50);
738 clearArea(0);
739 }
740
741 if (do_it)
742 {
8022f53d 743 osd_text(4, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME", 1, 0);
8ab3e3c1 744 PicoStateProgressCB = emu_msg_cb;
a47dd663 745 emu_save_load_game((which & 0x1000) >> 12, 0);
7d4906bf 746 PicoStateProgressCB = NULL;
747 psp_msleep(0);
748 }
749
750 reset_timing = 1;
751 }
752 if (which & 0x0400) // switch renderer
753 {
754 if (PicoOpt&0x10) { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }
755 else { PicoOpt|= 0x10; currentConfig.EmuOpt &= ~0x80; }
756
757 vidResetMode();
758
d34a42f9 759 if (PicoOpt & POPT_ALT_RENDERER)
b24e0f6c 760 emu_status_msg("fast renderer");
c5b61ac2 761 else if (currentConfig.EmuOpt&0x80)
b24e0f6c 762 emu_status_msg("accurate renderer");
7d4906bf 763 }
764 if (which & 0x0300)
765 {
766 if(which&0x0200) {
767 state_slot -= 1;
768 if(state_slot < 0) state_slot = 9;
769 } else {
770 state_slot += 1;
771 if(state_slot > 9) state_slot = 0;
772 }
b24e0f6c 773 emu_status_msg("SAVE SLOT %i [%s]", state_slot,
a47dd663 774 emu_check_save_file(state_slot) ? "USED" : "FREE");
7d4906bf 775 }
776}
777
778static void updateKeys(void)
779{
780 unsigned int keys, allActions[2] = { 0, 0 }, events;
781 static unsigned int prevEvents = 0;
782 int i;
783
d34a42f9 784 /* FIXME: port to input fw, merge with emu.c:emu_update_input() */
7d4906bf 785 keys = psp_pad_read(0);
70357ce5 786 if (keys & PSP_CTRL_HOME)
787 sceDisplayWaitVblankStart();
788
e5ab6faf 789 if (keys & PBTN_SELECT)
7d4906bf 790 engineState = PGS_Menu;
791
792 keys &= CONFIGURABLE_KEYS;
793
f0f0d2df 794 PicoPad[0] = allActions[0] & 0xfff;
795 PicoPad[1] = allActions[1] & 0xfff;
796
797 if (allActions[0] & 0x7000) emu_DoTurbo(&PicoPad[0], allActions[0]);
798 if (allActions[1] & 0x7000) emu_DoTurbo(&PicoPad[1], allActions[1]);
7d4906bf 799
800 events = (allActions[0] | allActions[1]) >> 16;
801
c060a9ab 802 if ((events ^ prevEvents) & 0x40) {
a47dd663 803 emu_set_fastforward(events & 0x40);
c060a9ab 804 reset_timing = 1;
805 }
806
7d4906bf 807 events &= ~prevEvents;
c060a9ab 808
809 if (PicoAHW == PAHW_PICO)
810 RunEventsPico(events, keys);
7d4906bf 811 if (events) RunEvents(events);
812 if (movie_data) emu_updateMovie();
813
814 prevEvents = (allActions[0] | allActions[1]) >> 16;
815}
816
7d4906bf 817
818static void simpleWait(unsigned int until)
819{
820 unsigned int tval;
821 int diff;
822
823 tval = sceKernelGetSystemTimeLow();
824 diff = (int)until - (int)tval;
825 if (diff >= 512 && diff < 100*1024)
826 sceKernelDelayThread(diff);
827}
828
f2cf8472 829void pemu_loop(void)
7d4906bf 830{
110df09c 831 static int mp3_init_done = 0;
7d4906bf 832 char fpsbuff[24]; // fps count c string
6fc57144 833 unsigned int tval, tval_thissec = 0; // timing
834 int target_fps, target_frametime, lim_time, tval_diff, i, oldmodes = 0;
835 int pframes_done, pframes_shown; // "period" frames, used for sync
836 int frames_done, frames_shown, tval_fpsc = 0; // actual frames
7d4906bf 837 char *notice = NULL;
838
839 lprintf("entered emu_Loop()\n");
840
841 fpsbuff[0] = 0;
842
70357ce5 843 if (currentConfig.CPUclock != psp_get_cpu_clock()) {
844 lprintf("setting cpu clock to %iMHz... ", currentConfig.CPUclock);
845 i = psp_set_cpu_clock(currentConfig.CPUclock);
846 lprintf(i ? "failed\n" : "done\n");
847 currentConfig.CPUclock = psp_get_cpu_clock();
848 }
849
7d4906bf 850 // make sure we are in correct mode
851 vidResetMode();
8ab3e3c1 852 clearArea(1);
7d4906bf 853 Pico.m.dirtyPal = 1;
854 oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;
7d4906bf 855
856 // pal/ntsc might have changed, reset related stuff
857 target_fps = Pico.m.pal ? 50 : 60;
858 target_frametime = Pico.m.pal ? (1000000<<8)/50 : (1000000<<8)/60+1;
859 reset_timing = 1;
860
602133e1 861 if (PicoAHW & PAHW_MCD) {
110df09c 862 // prepare CD buffer
863 PicoCDBufferInit();
864 // mp3...
865 if (!mp3_init_done) {
866 i = mp3_init();
867 mp3_init_done = 1;
868 if (i) { engineState = PGS_Menu; return; }
869 }
870 }
7d4906bf 871
872 // prepare sound stuff
873 PsndOut = NULL;
f2cf8472 874 if (currentConfig.EmuOpt & EOPT_EN_SOUND)
7d4906bf 875 {
f2cf8472 876 pemu_sound_start();
7d4906bf 877 }
7d4906bf 878
1f4e9f14 879 sceDisplayWaitVblankStart();
6fc57144 880 pframes_shown = pframes_done =
881 frames_shown = frames_done = 0;
882
883 tval_fpsc = sceKernelGetSystemTimeLow();
1f4e9f14 884
7d4906bf 885 // loop?
886 while (engineState == PGS_Running)
887 {
888 int modes;
889
890 tval = sceKernelGetSystemTimeLow();
6fc57144 891 if (reset_timing || tval < tval_fpsc) {
7d4906bf 892 //stdbg("timing reset");
893 reset_timing = 0;
894 tval_thissec = tval;
6fc57144 895 pframes_shown = pframes_done = 0;
7d4906bf 896 }
897
898 // show notice message?
899 if (noticeMsgTime) {
900 static int noticeMsgSum;
901 if (tval - noticeMsgTime > 2000000) { // > 2.0 sec
902 noticeMsgTime = 0;
903 clearArea(0);
904 notice = 0;
905 } else {
906 int sum = noticeMsg[0]+noticeMsg[1]+noticeMsg[2];
907 if (sum != noticeMsgSum) { clearArea(0); noticeMsgSum = sum; }
908 notice = noticeMsg;
909 }
910 }
911
912 // check for mode changes
913 modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);
914 if (modes != oldmodes) {
915 oldmodes = modes;
916 clearArea(1);
8ab3e3c1 917 set_scaling_params();
7d4906bf 918 }
919
920 // second passed?
6fc57144 921 if (tval - tval_fpsc >= 1000000)
922 {
923 if (currentConfig.EmuOpt & 2)
924 sprintf(fpsbuff, "%02i/%02i ", frames_shown, frames_done);
925 frames_done = frames_shown = 0;
926 tval_fpsc += 1000000;
927 }
928
7d4906bf 929 if (tval - tval_thissec >= 1000000)
930 {
e41da5ce 931 // missing 1 frame?
6fc57144 932 if (currentConfig.Frameskip < 0 && pframes_done < target_fps) {
933 SkipFrame(); pframes_done++; frames_done++;
7d4906bf 934 }
e41da5ce 935
7d4906bf 936 tval_thissec += 1000000;
937
938 if (currentConfig.Frameskip < 0) {
6fc57144 939 pframes_done -= target_fps; if (pframes_done < 0) pframes_done = 0;
940 pframes_shown -= target_fps; if (pframes_shown < 0) pframes_shown = 0;
941 if (pframes_shown > pframes_done) pframes_shown = pframes_done;
7d4906bf 942 } else {
6fc57144 943 pframes_done = pframes_shown = 0;
7d4906bf 944 }
945 }
946#ifdef PFRAMES
947 sprintf(fpsbuff, "%i", Pico.m.frame_count);
948#endif
949
6fc57144 950 lim_time = (pframes_done+1) * target_frametime;
7d4906bf 951 if (currentConfig.Frameskip >= 0) // frameskip enabled
952 {
953 for (i = 0; i < currentConfig.Frameskip; i++) {
954 updateKeys();
6fc57144 955 SkipFrame(); pframes_done++; frames_done++;
c6196c0f 956 if (!(currentConfig.EmuOpt&0x40000)) { // do framelimitting if needed
7d4906bf 957 int tval_diff;
958 tval = sceKernelGetSystemTimeLow();
959 tval_diff = (int)(tval - tval_thissec) << 8;
960 if (tval_diff < lim_time) // we are too fast
961 simpleWait(tval + ((lim_time - tval_diff)>>8));
962 }
963 lim_time += target_frametime;
964 }
965 }
966 else // auto frameskip
967 {
968 int tval_diff;
969 tval = sceKernelGetSystemTimeLow();
970 tval_diff = (int)(tval - tval_thissec) << 8;
6fc57144 971 if (tval_diff > lim_time && (pframes_done/16 < pframes_shown))
7d4906bf 972 {
973 // no time left for this frame - skip
974 if (tval_diff - lim_time >= (300000<<8)) {
7d4906bf 975 reset_timing = 1;
976 continue;
977 }
978 updateKeys();
6fc57144 979 SkipFrame(); pframes_done++; frames_done++;
7d4906bf 980 continue;
981 }
982 }
983
984 updateKeys();
985
986 if (!(PicoOpt&0x10))
9112b6ce 987 EmuScanPrepare();
7d4906bf 988
989 PicoFrame();
990
3ec29f01 991 sceGuSync(0,0);
7d4906bf 992
993 // check time
994 tval = sceKernelGetSystemTimeLow();
995 tval_diff = (int)(tval - tval_thissec) << 8;
996
3ec29f01 997 blit2(fpsbuff, notice, tval_diff > lim_time);
998
6fc57144 999 if (currentConfig.Frameskip < 0 && tval_diff - lim_time >= (300000<<8)) { // slowdown detection
7d4906bf 1000 reset_timing = 1;
6fc57144 1001 }
c6196c0f 1002 else if (!(currentConfig.EmuOpt&0x40000) || currentConfig.Frameskip < 0)
7d4906bf 1003 {
1004 // sleep if we are still too fast
1005 if (tval_diff < lim_time)
1006 {
1007 // we are too fast
1008 simpleWait(tval + ((lim_time - tval_diff) >> 8));
1009 }
1010 }
1011
6fc57144 1012 pframes_done++; pframes_shown++;
1013 frames_done++; frames_shown++;
7d4906bf 1014 }
1015
1016
a47dd663 1017 emu_set_fastforward(0);
c060a9ab 1018
602133e1 1019 if (PicoAHW & PAHW_MCD) PicoCDBufferFree();
a4221917 1020
7d4906bf 1021 if (PsndOut != NULL) {
f2cf8472 1022 pemu_sound_stop();
a4221917 1023 PsndOut = NULL;
7d4906bf 1024 }
a4221917 1025
7d4906bf 1026 // save SRAM
1027 if ((currentConfig.EmuOpt & 1) && SRam.changed) {
8ab3e3c1 1028 emu_msg_cb("Writing SRAM/BRAM..");
a47dd663 1029 emu_save_load_game(0, 1);
7d4906bf 1030 SRam.changed = 0;
1031 }
a4221917 1032
80db4442 1033 // clear fps counters and stuff
b542be46 1034 memset32_uncached((int *)psp_video_get_active_fb() + 512*264*2/4, 0, 512*8*2/4);
7d4906bf 1035}
1036
ea08c296 1037void emu_HandleResume(void)
1038{
602133e1 1039 if (!(PicoAHW & PAHW_MCD)) return;
ea08c296 1040
2b02d6e5 1041 // reopen first CD track
ea08c296 1042 if (Pico_mcd->TOC.Tracks[0].F != NULL)
1043 {
713c9224 1044 char *fname = rom_fname_reload;
1045 int len = strlen(rom_fname_reload);
2b02d6e5 1046 cue_data_t *cue_data = NULL;
1047
1048 if (len > 4 && strcasecmp(fname + len - 4, ".cue") == 0)
1049 {
713c9224 1050 cue_data = cue_parse(rom_fname_reload);
2b02d6e5 1051 if (cue_data != NULL)
1052 fname = cue_data->tracks[1].fname;
1053 }
1054
1055 lprintf("emu_HandleResume: reopen %s\n", fname);
ea08c296 1056 pm_close(Pico_mcd->TOC.Tracks[0].F);
2b02d6e5 1057 Pico_mcd->TOC.Tracks[0].F = pm_open(fname);
ea08c296 1058 lprintf("reopen %s\n", Pico_mcd->TOC.Tracks[0].F != NULL ? "ok" : "failed");
2b02d6e5 1059
1060 if (cue_data != NULL) cue_destroy(cue_data);
ea08c296 1061 }
1062
1063 mp3_reopen_file();
2b02d6e5 1064
1065 if (!(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1))
1066 cdda_start_play();
ea08c296 1067}
1068