From 77a5b944f6846b83582dc467d16b71d2a5a538ec Mon Sep 17 00:00:00 2001 From: allkern Date: Mon, 5 Aug 2024 11:48:41 -0300 Subject: [PATCH] Fixed resample buffer overflow Fixed GetTN (fixes Disney's Hercules Action Game (USA)) --- compat.txt | 12 ++++++------ psx/dev/cdrom/cdrom.h | 12 +++++++----- psx/dev/cdrom/impl.c | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/compat.txt b/compat.txt index aa2289b..bb6eae7 100644 --- a/compat.txt +++ b/compat.txt @@ -6,16 +6,16 @@ Not working: CTR - Crash Team Racing (USA) *16 (regression) Fixed: Crash Bash (USA) *1 (2989bb6) Fixed: Crime Crackers (Japan) *20 (e145a4e) -Disney's Hercules Action Game (USA) *22 -Disney's The Emperor's New Groove (USA).cue *22 + Fixed: Disney's Hercules Action Game (USA) *22 + Fixed: Disney's The Emperor's New Groove (USA).cue *22 Fixed: Doom (All) *4 (e145a4e) Fixed: Elder Gate (Japan) *1 (2989bb6) Fixed: Fear Effect (USA) (Disc 1) *3 Fixed: Final Doom (All) *4 (e145a4e) Fixed: Final Fantasy IX (USA) (Disc 1) *22 Fixed: Gran Turismo 2 - Music at the Speed of Sound - The Album (USA) (Bonus PlayStation Disc) *19 (regression) -Hello Kitty - Cube Frenzy (USA) *22 -Initial D (Japan) *3 (regression) + Fixed: Hello Kitty - Cube Frenzy (USA) *22 (FMVs are very slow though) + Fixed: Initial D (Japan) *22 Fixed: Konami 80's Arcade Gallery (Japan) *1 (2989bb6) Nagano Winter Olympics '98 (USA) *18 Need for Speed II (USA) *17 @@ -38,7 +38,7 @@ Tama - Adventurous Ball in Giddy Labyrinth (Japan) *5 Fixed: Time Gal & Ninja Hayate (Japan) (En,Ja) (Disc 2) (Ninja Hayate) *9 Fixed: Tokimeki Memorial 2 (Japan) *1 (2989bb6) Fixed: Tomb Raider (USA) *8 (e145a4e) -Tony Hawk's Pro Skater (USA) *10 + Fixed: Tony Hawk's Pro Skater (USA) *22 Vib-Ribbon (Japan) *8 WipeOut (USA) *7 Fixed: Yu-Gi-Oh! Forbidden Memories (USA) *1 (2989bb6) @@ -65,7 +65,7 @@ Notes: *19 Hangs on CdlSetloc deadloop *20 GetlocP loop hangs *21 Hangs after 0-sized CDROM DMA -*22 MDEC corruption (need to fix ASAP) +*22 MDEC corruption (fixed, XA resample buffer overflow) Graphical issues: Most graphical issues (black models, 1-pixel seams, polygon explosions, etc.) have been fixed! diff --git a/psx/dev/cdrom/cdrom.h b/psx/dev/cdrom/cdrom.h index 8a4027f..3413aa6 100644 --- a/psx/dev/cdrom/cdrom.h +++ b/psx/dev/cdrom/cdrom.h @@ -39,8 +39,10 @@ #define XA_STEREO_SAMPLES 2016 // Samples per sector #define XA_MONO_SAMPLES 4032 // Samples per sector -#define XA_STEREO_RESAMPLE_SIZE 2352 // 2352 * 2 -#define XA_MONO_RESAMPLE_SIZE 4704 // 4704 * 2 +#define XA_STEREO_RESAMPLE_SIZE 2352 // 2352 +#define XA_MONO_RESAMPLE_SIZE 4704 // 4704 +#define XA_STEREO_RESAMPLE_MAX_SIZE 4704 // 2352 * 2 (because of 18KHz mode) +#define XA_MONO_RESAMPLE_MAX_SIZE 9408 // 4704 * 2 (because of 18KHz mode) #define XA_UPSAMPLE_SIZE 28224 // 4032 * 7 #define XA_RINGBUF_SIZE 32 @@ -252,9 +254,9 @@ typedef struct { int16_t xa_right_buf[XA_STEREO_SAMPLES]; int16_t xa_mono_buf[XA_MONO_SAMPLES]; int16_t xa_upsample_buf[XA_UPSAMPLE_SIZE]; - int16_t xa_left_resample_buf[XA_STEREO_RESAMPLE_SIZE]; - int16_t xa_right_resample_buf[XA_STEREO_RESAMPLE_SIZE]; - int16_t xa_mono_resample_buf[XA_MONO_RESAMPLE_SIZE]; + int16_t xa_left_resample_buf[XA_STEREO_RESAMPLE_MAX_SIZE]; + int16_t xa_right_resample_buf[XA_STEREO_RESAMPLE_MAX_SIZE]; + int16_t xa_mono_resample_buf[XA_MONO_RESAMPLE_MAX_SIZE]; } psx_cdrom_t; enum { diff --git a/psx/dev/cdrom/impl.c b/psx/dev/cdrom/impl.c index a125ccd..f37f35d 100644 --- a/psx/dev/cdrom/impl.c +++ b/psx/dev/cdrom/impl.c @@ -484,7 +484,7 @@ void cdrom_cmd_gettn(psx_cdrom_t* cdrom) { queue_push(cdrom->response, 1); queue_push(cdrom->response, ITOB(tn)); - cdrom_pause(cdrom); + cdrom_restore_state(cdrom); } void cdrom_cmd_gettd(psx_cdrom_t* cdrom) {