emu.c 30 KB

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