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