emu.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  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/PicoInt.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_ACC_SPRITES))
  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_ACC_SPRITES) && !(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. static void sound_prepare(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. static void sound_end(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. static void sound_deinit(void)
  556. {
  557. sound_thread_exit = 1;
  558. sceKernelSignalSema(sound_sem, 1);
  559. sceKernelDeleteSema(sound_sem);
  560. sound_sem = -1;
  561. }
  562. static void writeSound(int len)
  563. {
  564. int ret;
  565. if (PicoOpt&8) len<<=1;
  566. PsndOut += len;
  567. /*if (PsndOut > sndBuffer_endptr) {
  568. memcpy32((int *)(void *)sndBuffer, (int *)endptr, (PsndOut - endptr + 1) / 2);
  569. PsndOut = &sndBuffer[PsndOut - endptr];
  570. lprintf("mov\n");
  571. }
  572. else*/
  573. if (PsndOut > sndBuffer_endptr) lprintf("snd oflow %i!\n", PsndOut - sndBuffer_endptr);
  574. if (PsndOut >= sndBuffer_endptr)
  575. PsndOut = sndBuffer;
  576. // signal the snd thread
  577. samples_made += len;
  578. if (samples_made - samples_done > samples_block*2) {
  579. // lprintf("signal, %i/%i\n", samples_done, samples_made);
  580. ret = sceKernelSignalSema(sound_sem, 1);
  581. //if (ret < 0) lprintf("snd signal ret %08x\n", ret);
  582. }
  583. }
  584. static void SkipFrame(void)
  585. {
  586. PicoSkipFrame=1;
  587. PicoFrame();
  588. PicoSkipFrame=0;
  589. }
  590. void emu_forcedFrame(int opts)
  591. {
  592. int po_old = PicoOpt;
  593. int eo_old = currentConfig.EmuOpt;
  594. PicoOpt &= ~0x10;
  595. PicoOpt |= opts|POPT_ACC_SPRITES;
  596. currentConfig.EmuOpt |= 0x80;
  597. vidResetMode();
  598. memset32(VRAM_CACHED_STUFF, 0xe0e0e0e0, 512*8/4); // borders
  599. memset32((int *)VRAM_CACHED_STUFF + 512*232/4, 0xe0e0e0e0, 512*8/4);
  600. memset32_uncached((int *)psp_screen + 512*264*2/4, 0, 512*8*2/4);
  601. PicoDrawSetColorFormat(-1);
  602. PicoScanBegin = EmuScanSlowBegin;
  603. PicoScanEnd = EmuScanSlowEnd;
  604. EmuScanPrepare();
  605. PicoFrameDrawOnly();
  606. blit1();
  607. sceGuSync(0,0);
  608. PicoOpt = po_old;
  609. currentConfig.EmuOpt = eo_old;
  610. }
  611. static void RunEventsPico(unsigned int events, unsigned int keys)
  612. {
  613. emu_RunEventsPico(events);
  614. if (pico_inp_mode != 0)
  615. {
  616. PicoPad[0] &= ~0x0f; // release UDLR
  617. if (keys & BTN_UP) { pico_pen_y--; if (pico_pen_y < 8) pico_pen_y = 8; }
  618. if (keys & BTN_DOWN) { pico_pen_y++; if (pico_pen_y > 224-PICO_PEN_ADJUST_Y) pico_pen_y = 224-PICO_PEN_ADJUST_Y; }
  619. if (keys & BTN_LEFT) { pico_pen_x--; if (pico_pen_x < 0) pico_pen_x = 0; }
  620. if (keys & BTN_RIGHT) {
  621. int lim = (Pico.video.reg[12]&1) ? 319 : 255;
  622. pico_pen_x++;
  623. if (pico_pen_x > lim-PICO_PEN_ADJUST_X)
  624. pico_pen_x = lim-PICO_PEN_ADJUST_X;
  625. }
  626. PicoPicohw.pen_pos[0] = pico_pen_x;
  627. if (!(Pico.video.reg[12]&1)) PicoPicohw.pen_pos[0] += pico_pen_x/4;
  628. PicoPicohw.pen_pos[0] += 0x3c;
  629. PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);
  630. }
  631. }
  632. static void RunEvents(unsigned int which)
  633. {
  634. if (which & 0x1800) // save or load (but not both)
  635. {
  636. int do_it = 1;
  637. if ( emu_checkSaveFile(state_slot) &&
  638. (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load
  639. (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) // save
  640. {
  641. int keys;
  642. sceGuSync(0,0);
  643. blit2("", (which & 0x1000) ? "LOAD STATE? (X=yes, O=no)" : "OVERWRITE SAVE? (X=yes, O=no)", 0);
  644. while( !((keys = psp_pad_read(1)) & (BTN_X|BTN_CIRCLE)) )
  645. psp_msleep(50);
  646. if (keys & BTN_CIRCLE) do_it = 0;
  647. while( ((keys = psp_pad_read(1)) & (BTN_X|BTN_CIRCLE)) ) // wait for release
  648. psp_msleep(50);
  649. clearArea(0);
  650. }
  651. if (do_it)
  652. {
  653. osd_text(4, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME", 1, 0);
  654. PicoStateProgressCB = emu_msg_cb;
  655. emu_SaveLoadGame((which & 0x1000) >> 12, 0);
  656. PicoStateProgressCB = NULL;
  657. psp_msleep(0);
  658. }
  659. reset_timing = 1;
  660. }
  661. if (which & 0x0400) // switch renderer
  662. {
  663. if (PicoOpt&0x10) { PicoOpt&=~0x10; currentConfig.EmuOpt |= 0x80; }
  664. else { PicoOpt|= 0x10; currentConfig.EmuOpt &= ~0x80; }
  665. vidResetMode();
  666. if (PicoOpt&0x10)
  667. strcpy(noticeMsg, "fast renderer");
  668. else if (currentConfig.EmuOpt&0x80)
  669. strcpy(noticeMsg, "accurate renderer");
  670. noticeMsgTime = sceKernelGetSystemTimeLow();
  671. }
  672. if (which & 0x0300)
  673. {
  674. if(which&0x0200) {
  675. state_slot -= 1;
  676. if(state_slot < 0) state_slot = 9;
  677. } else {
  678. state_slot += 1;
  679. if(state_slot > 9) state_slot = 0;
  680. }
  681. sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");
  682. noticeMsgTime = sceKernelGetSystemTimeLow();
  683. }
  684. }
  685. static void updateKeys(void)
  686. {
  687. unsigned int keys, allActions[2] = { 0, 0 }, events;
  688. static unsigned int prevEvents = 0;
  689. int i;
  690. keys = psp_pad_read(0);
  691. if (keys & PSP_CTRL_HOME)
  692. sceDisplayWaitVblankStart();
  693. if (keys & BTN_SELECT)
  694. engineState = PGS_Menu;
  695. keys &= CONFIGURABLE_KEYS;
  696. for (i = 0; i < 32; i++)
  697. {
  698. if (keys & (1 << i))
  699. {
  700. int pl, acts = currentConfig.KeyBinds[i];
  701. if (!acts) continue;
  702. pl = (acts >> 16) & 1;
  703. if (kb_combo_keys & (1 << i))
  704. {
  705. int u = i+1, acts_c = acts & kb_combo_acts;
  706. // let's try to find the other one
  707. if (acts_c) {
  708. for (; u < 32; u++)
  709. if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {
  710. allActions[pl] |= acts_c & currentConfig.KeyBinds[u];
  711. keys &= ~((1 << i) | (1 << u));
  712. break;
  713. }
  714. }
  715. // add non-combo actions if combo ones were not found
  716. if (!acts_c || u == 32)
  717. allActions[pl] |= acts & ~kb_combo_acts;
  718. } else {
  719. allActions[pl] |= acts;
  720. }
  721. }
  722. }
  723. PicoPad[0] = allActions[0] & 0xfff;
  724. PicoPad[1] = allActions[1] & 0xfff;
  725. if (allActions[0] & 0x7000) emu_DoTurbo(&PicoPad[0], allActions[0]);
  726. if (allActions[1] & 0x7000) emu_DoTurbo(&PicoPad[1], allActions[1]);
  727. events = (allActions[0] | allActions[1]) >> 16;
  728. if ((events ^ prevEvents) & 0x40) {
  729. emu_changeFastForward(events & 0x40);
  730. reset_timing = 1;
  731. }
  732. events &= ~prevEvents;
  733. if (PicoAHW == PAHW_PICO)
  734. RunEventsPico(events, keys);
  735. if (events) RunEvents(events);
  736. if (movie_data) emu_updateMovie();
  737. prevEvents = (allActions[0] | allActions[1]) >> 16;
  738. }
  739. static void simpleWait(unsigned int until)
  740. {
  741. unsigned int tval;
  742. int diff;
  743. tval = sceKernelGetSystemTimeLow();
  744. diff = (int)until - (int)tval;
  745. if (diff >= 512 && diff < 100*1024)
  746. sceKernelDelayThread(diff);
  747. }
  748. void emu_Loop(void)
  749. {
  750. static int mp3_init_done = 0;
  751. char fpsbuff[24]; // fps count c string
  752. unsigned int tval, tval_thissec = 0; // timing
  753. int target_fps, target_frametime, lim_time, tval_diff, i, oldmodes = 0;
  754. int pframes_done, pframes_shown; // "period" frames, used for sync
  755. int frames_done, frames_shown, tval_fpsc = 0; // actual frames
  756. char *notice = NULL;
  757. lprintf("entered emu_Loop()\n");
  758. fpsbuff[0] = 0;
  759. if (currentConfig.CPUclock != psp_get_cpu_clock()) {
  760. lprintf("setting cpu clock to %iMHz... ", currentConfig.CPUclock);
  761. i = psp_set_cpu_clock(currentConfig.CPUclock);
  762. lprintf(i ? "failed\n" : "done\n");
  763. currentConfig.CPUclock = psp_get_cpu_clock();
  764. }
  765. // make sure we are in correct mode
  766. vidResetMode();
  767. clearArea(1);
  768. Pico.m.dirtyPal = 1;
  769. oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;
  770. emu_findKeyBindCombos();
  771. // pal/ntsc might have changed, reset related stuff
  772. target_fps = Pico.m.pal ? 50 : 60;
  773. target_frametime = Pico.m.pal ? (1000000<<8)/50 : (1000000<<8)/60+1;
  774. reset_timing = 1;
  775. if (PicoAHW & PAHW_MCD) {
  776. // prepare CD buffer
  777. PicoCDBufferInit();
  778. // mp3...
  779. if (!mp3_init_done) {
  780. i = mp3_init();
  781. mp3_init_done = 1;
  782. if (i) { engineState = PGS_Menu; return; }
  783. }
  784. }
  785. // prepare sound stuff
  786. PsndOut = NULL;
  787. if (currentConfig.EmuOpt & 4)
  788. {
  789. sound_prepare();
  790. }
  791. sceDisplayWaitVblankStart();
  792. pframes_shown = pframes_done =
  793. frames_shown = frames_done = 0;
  794. tval_fpsc = sceKernelGetSystemTimeLow();
  795. // loop?
  796. while (engineState == PGS_Running)
  797. {
  798. int modes;
  799. tval = sceKernelGetSystemTimeLow();
  800. if (reset_timing || tval < tval_fpsc) {
  801. //stdbg("timing reset");
  802. reset_timing = 0;
  803. tval_thissec = tval;
  804. pframes_shown = pframes_done = 0;
  805. }
  806. // show notice message?
  807. if (noticeMsgTime) {
  808. static int noticeMsgSum;
  809. if (tval - noticeMsgTime > 2000000) { // > 2.0 sec
  810. noticeMsgTime = 0;
  811. clearArea(0);
  812. notice = 0;
  813. } else {
  814. int sum = noticeMsg[0]+noticeMsg[1]+noticeMsg[2];
  815. if (sum != noticeMsgSum) { clearArea(0); noticeMsgSum = sum; }
  816. notice = noticeMsg;
  817. }
  818. }
  819. // check for mode changes
  820. modes = ((Pico.video.reg[12]&1)<<2)|(Pico.video.reg[1]&8);
  821. if (modes != oldmodes) {
  822. oldmodes = modes;
  823. clearArea(1);
  824. set_scaling_params();
  825. }
  826. // second passed?
  827. if (tval - tval_fpsc >= 1000000)
  828. {
  829. if (currentConfig.EmuOpt & 2)
  830. sprintf(fpsbuff, "%02i/%02i ", frames_shown, frames_done);
  831. frames_done = frames_shown = 0;
  832. tval_fpsc += 1000000;
  833. }
  834. if (tval - tval_thissec >= 1000000)
  835. {
  836. // missing 1 frame?
  837. if (currentConfig.Frameskip < 0 && pframes_done < target_fps) {
  838. SkipFrame(); pframes_done++; frames_done++;
  839. }
  840. tval_thissec += 1000000;
  841. if (currentConfig.Frameskip < 0) {
  842. pframes_done -= target_fps; if (pframes_done < 0) pframes_done = 0;
  843. pframes_shown -= target_fps; if (pframes_shown < 0) pframes_shown = 0;
  844. if (pframes_shown > pframes_done) pframes_shown = pframes_done;
  845. } else {
  846. pframes_done = pframes_shown = 0;
  847. }
  848. }
  849. #ifdef PFRAMES
  850. sprintf(fpsbuff, "%i", Pico.m.frame_count);
  851. #endif
  852. lim_time = (pframes_done+1) * target_frametime;
  853. if (currentConfig.Frameskip >= 0) // frameskip enabled
  854. {
  855. for (i = 0; i < currentConfig.Frameskip; i++) {
  856. updateKeys();
  857. SkipFrame(); pframes_done++; frames_done++;
  858. if (!(currentConfig.EmuOpt&0x40000)) { // do framelimitting if needed
  859. int tval_diff;
  860. tval = sceKernelGetSystemTimeLow();
  861. tval_diff = (int)(tval - tval_thissec) << 8;
  862. if (tval_diff < lim_time) // we are too fast
  863. simpleWait(tval + ((lim_time - tval_diff)>>8));
  864. }
  865. lim_time += target_frametime;
  866. }
  867. }
  868. else // auto frameskip
  869. {
  870. int tval_diff;
  871. tval = sceKernelGetSystemTimeLow();
  872. tval_diff = (int)(tval - tval_thissec) << 8;
  873. if (tval_diff > lim_time && (pframes_done/16 < pframes_shown))
  874. {
  875. // no time left for this frame - skip
  876. if (tval_diff - lim_time >= (300000<<8)) {
  877. reset_timing = 1;
  878. continue;
  879. }
  880. updateKeys();
  881. SkipFrame(); pframes_done++; frames_done++;
  882. continue;
  883. }
  884. }
  885. updateKeys();
  886. if (!(PicoOpt&0x10))
  887. EmuScanPrepare();
  888. PicoFrame();
  889. sceGuSync(0,0);
  890. // check time
  891. tval = sceKernelGetSystemTimeLow();
  892. tval_diff = (int)(tval - tval_thissec) << 8;
  893. blit2(fpsbuff, notice, tval_diff > lim_time);
  894. if (currentConfig.Frameskip < 0 && tval_diff - lim_time >= (300000<<8)) { // slowdown detection
  895. reset_timing = 1;
  896. }
  897. else if (!(currentConfig.EmuOpt&0x40000) || currentConfig.Frameskip < 0)
  898. {
  899. // sleep if we are still too fast
  900. if (tval_diff < lim_time)
  901. {
  902. // we are too fast
  903. simpleWait(tval + ((lim_time - tval_diff) >> 8));
  904. }
  905. }
  906. pframes_done++; pframes_shown++;
  907. frames_done++; frames_shown++;
  908. }
  909. emu_changeFastForward(0);
  910. if (PicoAHW & PAHW_MCD) PicoCDBufferFree();
  911. if (PsndOut != NULL) {
  912. PsndOut = NULL;
  913. sound_end();
  914. }
  915. // save SRAM
  916. if ((currentConfig.EmuOpt & 1) && SRam.changed) {
  917. emu_msg_cb("Writing SRAM/BRAM..");
  918. emu_SaveLoadGame(0, 1);
  919. SRam.changed = 0;
  920. }
  921. // clear fps counters and stuff
  922. memset32_uncached((int *)psp_video_get_active_fb() + 512*264*2/4, 0, 512*8*2/4);
  923. }
  924. void emu_ResetGame(void)
  925. {
  926. PicoReset();
  927. reset_timing = 1;
  928. }
  929. void emu_HandleResume(void)
  930. {
  931. if (!(PicoAHW & PAHW_MCD)) return;
  932. // reopen first CD track
  933. if (Pico_mcd->TOC.Tracks[0].F != NULL)
  934. {
  935. char *fname = romFileName;
  936. int len = strlen(romFileName);
  937. cue_data_t *cue_data = NULL;
  938. if (len > 4 && strcasecmp(fname + len - 4, ".cue") == 0)
  939. {
  940. cue_data = cue_parse(romFileName);
  941. if (cue_data != NULL)
  942. fname = cue_data->tracks[1].fname;
  943. }
  944. lprintf("emu_HandleResume: reopen %s\n", fname);
  945. pm_close(Pico_mcd->TOC.Tracks[0].F);
  946. Pico_mcd->TOC.Tracks[0].F = pm_open(fname);
  947. lprintf("reopen %s\n", Pico_mcd->TOC.Tracks[0].F != NULL ? "ok" : "failed");
  948. if (cue_data != NULL) cue_destroy(cue_data);
  949. }
  950. mp3_reopen_file();
  951. if (!(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1))
  952. cdda_start_play();
  953. }