From 1375489a8bfa71800b8040dd90e45006b946ffc0 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Thu, 7 Jul 2016 16:41:27 -0700 Subject: [PATCH] Fix previous commit so it compiles. --- Frameworks/GME/vgmplay/chips/yam.c | 67 ++++++++++++++----- .../HighlyTheoretical/Core/yam.c | 2 +- 2 files changed, 51 insertions(+), 18 deletions(-) diff --git a/Frameworks/GME/vgmplay/chips/yam.c b/Frameworks/GME/vgmplay/chips/yam.c index 8b7db7b3f..6c92826d0 100644 --- a/Frameworks/GME/vgmplay/chips/yam.c +++ b/Frameworks/GME/vgmplay/chips/yam.c @@ -74,7 +74,7 @@ #define MAKELFOPHASEINC(x) (((uint64)(0x100000000)) / ((uint64)(x))) -static uint32 lfophaseinctable[0x20] = { +static const uint32 lfophaseinctable[0x20] = { MAKELFOPHASEINC(0x3FC00),MAKELFOPHASEINC(0x37C00),MAKELFOPHASEINC(0x2FC00),MAKELFOPHASEINC(0x27C00), MAKELFOPHASEINC(0x1FC00),MAKELFOPHASEINC(0x1BC00),MAKELFOPHASEINC(0x17C00),MAKELFOPHASEINC(0x13C00), MAKELFOPHASEINC(0x0FC00),MAKELFOPHASEINC(0x0BC00),MAKELFOPHASEINC(0x0DC00),MAKELFOPHASEINC(0x09C00), @@ -85,7 +85,7 @@ MAKELFOPHASEINC(0x00C00),MAKELFOPHASEINC(0x00A00),MAKELFOPHASEINC(0x00800),MAKEL MAKELFOPHASEINC(0x00400),MAKELFOPHASEINC(0x00300),MAKELFOPHASEINC(0x00200),MAKELFOPHASEINC(0x00100) }; -static uint8 envattackshift[0x3D][4] = { +static const uint8 envattackshift[0x3D][4] = { /* 00-07 */ {4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4}, /* 08-0F */ {4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4}, /* 10-17 */ {4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4},{4,4,4,4}, @@ -96,7 +96,7 @@ static uint8 envattackshift[0x3D][4] = { /* 38-3C */ {2,2,2,2},{1,2,2,2},{1,2,1,2},{1,1,1,2},{1,1,1,1} }; -static uint8 envdecayvalue[0x3D][4] = { +static const uint8 envdecayvalue[0x3D][4] = { /* 00-07 */ {1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}, /* 08-0F */ {1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}, /* 10-17 */ {1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}, @@ -107,16 +107,15 @@ static uint8 envdecayvalue[0x3D][4] = { /* 38-3C */ {4,4,4,4},{8,4,4,4},{8,4,8,4},{8,8,8,4},{8,8,8,8} }; -static sint32 adpcmscale[8] = { - 0x0E6, 0x0E6, 0x0E6, 0x0E6, 0x133, 0x199, 0x200, 0x266 +static const int adpcmscale[8] = { + 0xE6, 0xE6, 0xE6, 0xE6, 0x133, 0x199, 0x200, 0x266 }; -static sint32 adpcmdiff[16] = { - 1, 3, 5, 7, 9, 11, 13, 15, --1,-3,-5,-7,-9,-11,-13,-15 +static const int adpcmdiff[8] = { + 1, 3, 5, 7, 9, 11, 13, 15 }; -static sint32 qtable[32] = { +static const sint32 qtable[32] = { 0x0E00,0x0E80,0x0F00,0x0F80, 0x1000,0x1080,0x1100,0x1180, 0x1200,0x1280,0x1300,0x1280, @@ -127,8 +126,8 @@ static sint32 qtable[32] = { 0x1C00,0x1D00,0x1E00,0x1F00 }; -static uint8 pan_att_l[32] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; -static uint8 pan_att_r[32] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,32 }; +static const uint8 pan_att_l[32] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; +static const uint8 pan_att_r[32] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,32 }; static void convert_stereo_send_level( uint8 sdl, uint8 pan, @@ -163,6 +162,7 @@ sint32 EMU_CALL yam_init(void) { return 0; } + ///////////////////////////////////////////////////////////////////////////// /* static int gfreq[201]; @@ -381,8 +381,10 @@ struct YAM_STATE { uint32 odometer; uint8 dry_out_enabled; uint8 dsp_emulation_enabled; +#ifdef ENABLE_DYNAREC uint8 dsp_dyna_enabled; uint8 dsp_dyna_valid; +#endif uint32 randseed; uint32 mem_word_address_xor; uint32 mem_byte_address_xor; @@ -454,7 +456,9 @@ struct YAM_STATE { // // Buffer for dynarec code // +#ifdef ENABLE_DYNAREC uint8 dynacode[DYNACODE_MAX_SIZE]; +#endif }; // @@ -476,7 +480,6 @@ void EMU_CALL yam_clear_state(void *state, uint8 version) { YAMSTATE->version = version; // Clear channel regs for(i = 0; i < 64; i++) { - YAMSTATE->chan[i].mute = 0; YAMSTATE->chan[i].envstate = 3; YAMSTATE->chan[i].lpfstate = 3; YAMSTATE->chan[i].envlevel = 0x1FFF; @@ -507,7 +510,9 @@ void EMU_CALL yam_clear_state(void *state, uint8 version) { YAMSTATE->dsp_emulation_enabled = 1; // Enable DSP dynarec +#ifdef ENABLE_DYNAREC YAMSTATE->dsp_dyna_enabled = 1; +#endif } ///////////////////////////////////////////////////////////////////////////// @@ -557,6 +562,7 @@ static void dumpch(struct YAM_STATE *state, struct YAM_CHAN *chan) { logf(" rbp=%X rbl=%X\n",state->rbp,state->rbl); } */ + ///////////////////////////////////////////////////////////////////////////// // // Set RAM pointer and size (must be a power of 2) @@ -573,7 +579,9 @@ void EMU_CALL yam_setram(void *state, uint32 *ram, uint32 size, uint8 mbx, uint8 // // Invalidate dynarec code // +#ifdef ENABLE_DYNAREC YAMSTATE->dsp_dyna_valid = 0; +#endif } ///////////////////////////////////////////////////////////////////////////// @@ -595,12 +603,16 @@ void EMU_CALL yam_enable_dry(void *state, uint8 enable) { void EMU_CALL yam_enable_dsp(void *state, uint8 enable) { YAMSTATE->dsp_emulation_enabled = (enable != 0); +#ifdef ENABLE_DYNAREC if(enable == 0) { YAMSTATE->dsp_dyna_valid = 0; } +#endif } void EMU_CALL yam_enable_dsp_dynarec(void *state, uint8 enable) { +#ifdef ENABLE_DYNAREC YAMSTATE->dsp_dyna_enabled = (enable != 0); if(enable == 0) { YAMSTATE->dsp_dyna_valid = 0; } +#endif } ///////////////////////////////////////////////////////////////////////////// @@ -1252,7 +1264,9 @@ static void coef_write(struct YAM_STATE *state, uint32 n, uint32 d, uint32 mask) state->coef[n] &= ~mask; state->coef[n] |= d & mask; state->coef[n] = ((sint16)(state->coef[n])) >> 3; +#ifdef ENABLE_DYNAREC if(old != state->coef[n]) { state->dsp_dyna_valid = 0; } +#endif } static void madrs_write(struct YAM_STATE *state, uint32 n, uint32 d, uint32 mask) { @@ -1261,7 +1275,9 @@ static void madrs_write(struct YAM_STATE *state, uint32 n, uint32 d, uint32 mask n &= 0x3F; state->madrs[n] &= ~mask; state->madrs[n] |= d & mask; +#ifdef ENABLE_DYNAREC if(old != state->madrs[n]) { state->dsp_dyna_valid = 0; } +#endif } static uint32 temp_read(struct YAM_STATE *state, uint32 n) { @@ -1374,7 +1390,9 @@ static void dsp_scsp_store_reg( if(newvalue != oldvalue) { yam_flush(state); mpro_scsp_write(state->mpro + index64, newvalue); +#ifdef ENABLE_DYNAREC state->dsp_dyna_valid = 0; +#endif } return; } @@ -1425,7 +1443,9 @@ static void dsp_aica_store_reg( if(newvalue != oldvalue) { yam_flush(state); mpro_aica_write(state->mpro + index64, newvalue); +#ifdef ENABLE_DYNAREC state->dsp_dyna_valid = 0; +#endif } return; } @@ -1627,7 +1647,9 @@ void EMU_CALL yam_scsp_store_reg(void *state, uint32 a, uint32 d, uint32 mask, u YAMSTATE->rbp = oldrbp; YAMSTATE->rbl = oldrbl; yam_flush(YAMSTATE); +#ifdef ENABLE_DYNAREC YAMSTATE->dsp_dyna_valid = 0; +#endif YAMSTATE->rbp = newrbp; YAMSTATE->rbl = newrbl; } @@ -1810,7 +1832,9 @@ void EMU_CALL yam_aica_store_reg(void *state, uint32 a, uint32 d, uint32 mask, u YAMSTATE->rbp = oldrbp; YAMSTATE->rbl = oldrbl; yam_flush(YAMSTATE); +#ifdef ENABLE_DYNAREC YAMSTATE->dsp_dyna_valid = 0; +#endif YAMSTATE->rbp = newrbp; YAMSTATE->rbl = newrbl; } @@ -2008,14 +2032,15 @@ static void readnextsample( s = *(uint8*)(((uint8*)(state->ram_ptr)) + (((chan->sampleaddr + (chan->playpos >> 1)) ^ (state->mem_byte_address_xor)) & (state->ram_mask))); s >>= 4 * ((chan->playpos & 1) ^ 0); s &= 0xF; - { sint32 out = chan->adpcmprev; - out += (chan->adpcmstep * adpcmdiff[s]) / 8; + { sint32 out = (chan->adpcmstep * adpcmdiff[s & 7]) / 8; + if(out > ( 0x7FFF)) { out = 0x7FFF; } + out*=1-((s >> 2) & 2); + out+=chan->adpcmprev; if(out > ( 0x7FFF)) { out = ( 0x7FFF); /* logf(""); */ } if(out < (-0x8000)) { out = (-0x8000); /* logf(""); */ } chan->adpcmstep = (chan->adpcmstep * adpcmscale[s & 7]) >> 8; if(chan->adpcmstep > 0x6000) { chan->adpcmstep = 0x6000; } - if(chan->adpcmstep < 0x007F) { chan->adpcmstep = 0x007F; } - chan->adpcmprev = out; + if(chan->adpcmstep < 0x7F) { chan->adpcmstep = 0x7F; } s = out; } break; @@ -2509,6 +2534,7 @@ static void __fastcall dsp_sample_interpret(struct YAM_STATE *state) { #define STRUCTOFS(thetype,thefield) ((uint32)(&(((struct thetype*)0)->thefield))) #define STATEOFS(thefield) STRUCTOFS(YAM_STATE,thefield) +#ifdef ENABLE_DYNAREC static int instruction_uses_shifted(struct MPRO *mpro) { // uses SHIFTED if: // - ADRL and INTERP @@ -2526,12 +2552,14 @@ static int instruction_uses_shifted(struct MPRO *mpro) { // otherwise not return 0; } +#endif // // Compile x86 code out of the current DSP program/coef/address set // Also uses the current ringbuffer pointer and size, and ram pointer/mask/memwordxor // So if any of those change, the compiled dynacode must be invalidated // +#ifdef ENABLE_DYNAREC static void dynacompile(struct YAM_STATE *state) { // Pre-compute ringbuffer size mask uint32 rbmask = (1 << ((state->rbl)+13)) - 1; @@ -2672,7 +2700,7 @@ static void dynacompile(struct YAM_STATE *state) { C(0x8D) C(0x14) C(0x36) // lea edx,[esi+esi] // 16 bytes max } - C(0x72) C(0x09) // jb +9bytes + C(0x74) C(0x09) // je +9bytes C(0xC1) C(0xFA) C(0x1F) // sar edx,1Fh C(0x81) C(0xF2) C32(0x007FFFFF) // xor edx,7FFFFFh // 27 bytes max @@ -2821,6 +2849,7 @@ static void dynacompile(struct YAM_STATE *state) { //{FILE*f=fopen("C:\\Corlett\\yamdyna.bin","wb");if(f){fwrite(state->dynacode,1,0x6000,f);fclose(f);}} } +#endif ///////////////////////////////////////////////////////////////////////////// @@ -2843,11 +2872,15 @@ static void render_effects( sint32 eflin_l[16]; sint32 eflin_r[16]; +#ifdef ENABLE_DYNAREC if(state->dsp_dyna_enabled) { if(!(state->dsp_dyna_valid)) { dynacompile(state); } samplefunc = (dsp_sample_t)(((uint8*)(state->dynacode)) + DYNACODE_SLOP_SIZE); +#else + if (0) { +#endif } else { samplefunc = dsp_sample_interpret; } diff --git a/Frameworks/HighlyTheoretical/HighlyTheoretical/Core/yam.c b/Frameworks/HighlyTheoretical/HighlyTheoretical/Core/yam.c index f39d7c20f..4f54de2e6 100644 --- a/Frameworks/HighlyTheoretical/HighlyTheoretical/Core/yam.c +++ b/Frameworks/HighlyTheoretical/HighlyTheoretical/Core/yam.c @@ -598,8 +598,8 @@ void EMU_CALL yam_enable_dsp(void *state, uint8 enable) { } void EMU_CALL yam_enable_dsp_dynarec(void *state, uint8 enable) { - YAMSTATE->dsp_dyna_enabled = (enable != 0); #ifdef ENABLE_DYNAREC + YAMSTATE->dsp_dyna_enabled = (enable != 0); if(enable == 0) { YAMSTATE->dsp_dyna_valid = 0; } #endif }