From 0cf8f51c921606c9c47fca43dcf0871941157f2e Mon Sep 17 00:00:00 2001 From: Jonathan Campbell Date: Sun, 12 Jan 2025 23:42:24 -0800 Subject: [PATCH] GUS: Add dosbox.conf configuration option to enable a logfile warning every time a peek or poke is made to an out of bounds address to GUS DRAM --- src/dosbox.cpp | 3 +++ src/hardware/gus.cpp | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/dosbox.cpp b/src/dosbox.cpp index 23bc9c0f6ed..af42c457006 100644 --- a/src/dosbox.cpp +++ b/src/dosbox.cpp @@ -3887,6 +3887,9 @@ void DOSBOX_SetupConfigSections(void) { "This setting may be needed for DOS demoscene entries that assume aliasing behavior such as Out of Control by Contract."); Pstring->SetBasic(true); + Pbool = secprop->Add_bool("warn on out of bounds dram access",Property::Changeable::WhenIdle,false); + Pbool->Set_help("Controls whether attempts to access GUS DRAM beyond the 1MB maximum supported by the card are logged to the log file as a warning."); + Pbool = secprop->Add_bool("autoamp",Property::Changeable::WhenIdle,false); Pbool->Set_help("If set, GF1 output will reduce in volume automatically if the sum of all channels exceeds full volume.\n" "If not set, then loud music will clip to full volume just as it would on real hardware.\n" diff --git a/src/hardware/gus.cpp b/src/hardware/gus.cpp index 9d778bd7923..15ef46c339e 100644 --- a/src/hardware/gus.cpp +++ b/src/hardware/gus.cpp @@ -82,6 +82,7 @@ static bool unmask_irq = false; static bool enable_autoamp = false; static bool startup_ultrinit = false; static bool ignore_active_channel_write_while_active = false; +static bool warn_out_of_bounds_dram_access = false; static bool dma_enable_on_dma_control_polling = false; static uint16_t vol16bit[4096]; static uint32_t pantable[16]; @@ -1567,11 +1568,13 @@ static Bitu read_gus(Bitu port,Bitu iolen) { return reg16; case 0x307: - if((myGUS.gDramAddr & myGUS.gDramAddrMask) < myGUS.memsize) { + if (warn_out_of_bounds_dram_access && myGUS.gDramAddr >= myGUS.memsize) + LOG(LOG_MISC,LOG_WARN)("GUS: out of bounds DRAM read %x",(unsigned int)myGUS.gDramAddr); + + if((myGUS.gDramAddr & myGUS.gDramAddrMask) < myGUS.memsize) return GUSRam[myGUS.gDramAddr & myGUS.gDramAddrMask]; - } else { + else return 0; - } case 0x306: case 0x706: if (gus_type >= GUS_MAX) @@ -1812,8 +1815,12 @@ static void write_gus(Bitu port,Bitu val,Bitu iolen) { ExecuteGlobRegister(); break; case 0x307: + if (warn_out_of_bounds_dram_access && myGUS.gDramAddr >= myGUS.memsize) + LOG(LOG_MISC,LOG_WARN)("GUS: out of bounds DRAM write %x val %x",(unsigned int)myGUS.gDramAddr,(unsigned int)val & 0xffu); + if ((myGUS.gDramAddr & myGUS.gDramAddrMask) < myGUS.memsize) - GUSRam[myGUS.gDramAddr & myGUS.gDramAddrMask] = (uint8_t)val; + GUSRam[myGUS.gDramAddr & myGUS.gDramAddrMask] = (uint8_t)val; + break; case 0x306: case 0x706: @@ -2280,6 +2287,7 @@ class GUS:public Module_base{ memset(GUSRam,0,1024*1024); ignore_active_channel_write_while_active = section->Get_bool("ignore channel count while active"); + warn_out_of_bounds_dram_access = section->Get_bool("warn on out of bounds dram access"); unmask_irq = section->Get_bool("pic unmask irq"); enable_autoamp = section->Get_bool("autoamp");