From 17a34c079c4d4f29c1925771c2199d13526c04d3 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Fri, 29 Jun 2018 17:04:07 +0200 Subject: [PATCH] Backported EG hack. Courtesy of libretro. See https://github.com/libretro/reicast-emulator/commit/13dacb0021e5d0b8e914d1531217040ecbafb14e --- core/hw/aica/sgc_if.cpp | 49 +++++++++++++++++++++++++++++++++++------ core/nullDC.cpp | 39 ++++++++++++++++++++++++++++++++ core/types.h | 1 + 3 files changed, 82 insertions(+), 7 deletions(-) diff --git a/core/hw/aica/sgc_if.cpp b/core/hw/aica/sgc_if.cpp index 2abcfa806..2e69cb1da 100755 --- a/core/hw/aica/sgc_if.cpp +++ b/core/hw/aica/sgc_if.cpp @@ -3,6 +3,8 @@ #include "aica_mem.h" #include "hw/aica/aica_if.h" #include +#include +using namespace std; #undef FAR //#define CLIP_WARN @@ -390,7 +392,7 @@ struct ChannelEx return rv; } - __forceinline bool Step(SampleType& oLeft, SampleType& oRight, SampleType& oDsp) + __forceinline bool Step(SampleType& oLeft, SampleType& oRight, SampleType& oDsp, int32_t mixl, int32_t mixr) { if (!enabled) { @@ -409,12 +411,18 @@ struct ChannelEx //logtable handles up to 1024, anything >=255 is mute u32 ofsatt=lfo.alfo+(AEG.GetValue()>>2); + ofsatt = min(ofsatt, (u32)255); // make sure it never gets more 255 -- it can happen with some alfo/aeg combinations + u32 const max_att = ((16 << 4) - 1) - ofsatt; - s32* logtable=ofsatt+tl_lut; + s32* logtable = ofsatt + tl_lut; - oLeft=FPMul(sample,logtable[VolMix.DLAtt],15); - oRight=FPMul(sample,logtable[VolMix.DRAtt],15); - oDsp=FPMul(sample,logtable[VolMix.DSPAtt],15); + u32 dl = min(VolMix.DLAtt, max_att); + u32 dr = min(VolMix.DRAtt, max_att); + u32 ds = min(VolMix.DSPAtt, max_att); + + oLeft = FPMul(sample, logtable[dl], 15); + oRight = FPMul(sample, logtable[dr], 15); + oDsp = FPMul(sample, logtable[ds], 15); clip_verify(((s16)oLeft)==oLeft); clip_verify(((s16)oRight)==oRight); @@ -423,6 +431,33 @@ struct ChannelEx clip_verify(sample*oRight>=0); clip_verify(sample*oDsp>=0); + if (settings.aica.EGHack) + { + if ((s64)(this->ccd->DL + mixl + mixr + *VolMix.DSPOut) == 0) + { + switch(this->AEG.state) + { + case EG_Decay1: + if(this->AEG.AttackRate > this->AEG.Decay1Rate) + { + //printf("Promote 1\n"); + this->SetAegState(EG_Attack); + } + + break; + + case EG_Decay2: + if(this->AEG.AttackRate > this->AEG.Decay2Rate) + { + //printf("Promote 2\n"); + this->SetAegState(EG_Attack); + } + + break; + } + } + } + StepAEG(this); StepFEG(this); StepStream(this); @@ -435,7 +470,7 @@ struct ChannelEx { SampleType oLeft,oRight,oDsp; - Step(oLeft,oRight,oDsp); + Step(oLeft, oRight, oDsp, mixl, mixr); *VolMix.DSPOut+=oDsp; mixl+=oLeft; @@ -1191,7 +1226,7 @@ void AICA_Sample32() { SampleType oLeft,oRight,oDsp; //stop working on this channel if its turned off ... - if (!Chans[ch].Step(oLeft, oRight, oDsp)) + if (!Chans[ch].Step(oLeft, oRight, oDsp, mxlr[i * 2 + 0], mxlr[i * 2 + 1])) break; sg++; diff --git a/core/nullDC.cpp b/core/nullDC.cpp index 187891639..e8af2a1b7 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -129,6 +129,37 @@ void* webui_th(void* p) cThread webui_thd(&webui_th,0); #endif +const char *EGHackGamesList[] = { + "T46703M", /* Border Down (Japan) */ + "RDC-0117", /* Border Down (Japan) */ + "MK-51065", /* Bomberman Online (USA) */ + "T47801M", /* Chaos Field (Japan) */ + "T23202M", /* Death Crimson OX (Japan) */ + "T2401N", /* Death Crimson OX (USA) */ + "T3108M", /* Garou: Mark of the Wolves (Japan) */ + "HDR-0078", /* Jet Set Radio (Japan) */ + "MK-51058", /* Jet Grind Radio (USA, Europe) */ + "HDR-0079", /* Napple Tale (Japan) */ + "MK-5110050", /* Phantasy Star Online (Europe) */ + "HDR-0129", /* Phantasy Star Online (Japan) */ + "MK-51100", /* Phantasy Star Online (USA) */ + "MK-5119350", /* Phantasy Star Online Ver. 2 (Europe) */ + "HDR-0163", /* Phantasy Star Online Ver. 2 (Japan) */ + "MK-51193", /* Phantasy Star Online Ver. 2 (USA) */ + "T9907M", /* Psyvariar 2 (Japan) */ + "HDR-0216", /* Puyo Puyo Fever (Japan) */ + "T47802M", /* Radirgy (Japan) */ + "HDR-0151", /* Segagaga (Japan) */ + "HDR-0125", /* Sonic Shuffle (Japan) */ + "MK-5106050", /* Sonic Shuffle (Europe) */ + "MK-51060", /* Sonic Shuffle (USA) */ + "T29102M", /* Trigger Heart Exelica (Japan) */ + "T45101M", /* WWF Royal Rumble (Japan) */ + "T10003D 50", /* WWF Royal Rumble (Europe) */ + "T10005N", /* WWF Royal Rumble (USA) */ + NULL +}; + void LoadSpecialSettings() { if (!strncmp("T13008D", reios_product_number, 7) || !strncmp("T13006N", reios_product_number, 7)) @@ -137,6 +168,13 @@ void LoadSpecialSettings() if (!strncmp("RDC-0057", reios_product_number, 8)) // Cosmic Smash settings.rend.TranslucentPolygonDepthMask = 1; + for (int i = 0; EGHackGamesList[i] != NULL; i++) + if (!strncmp(reios_product_number, EGHackGamesList[i], strlen(EGHackGamesList[i]))) + { + printf("Enabling EG Hack\n"); + settings.aica.EGHack = 1; + break; + } } int dc_init(int argc,wchar* argv[]) @@ -258,6 +296,7 @@ void LoadSettings() settings.aica.LimitFPS = cfgLoadInt("config","aica.LimitFPS",1); settings.aica.NoBatch = cfgLoadInt("config","aica.NoBatch",0); settings.aica.NoSound = cfgLoadInt("config","aica.NoSound",0); + settings.aica.EGHack = cfgLoadInt("config","aica.EGHack", 0);; settings.rend.UseMipmaps = cfgLoadInt("config","rend.UseMipmaps",1); settings.rend.WideScreen = cfgLoadInt("config","rend.WideScreen",0); settings.rend.ShowFPS = cfgLoadInt("config", "rend.ShowFPS", 0); diff --git a/core/types.h b/core/types.h index 2f3f084c7..a4951e0fe 100644 --- a/core/types.h +++ b/core/types.h @@ -653,6 +653,7 @@ struct settings_t u32 DSPEnabled; //0 -> no, 1 -> yes u32 NoBatch; u32 NoSound; //0 ->sound, 1 -> no sound + u32 EGHack; } aica; #if USE_OMX