Minor fix to Highly Theoretical that won't be used (yet?) anyway.

CQTexperiment
Chris Moeller 2016-07-07 15:55:36 -07:00
parent 540ca59b50
commit d94bd9a183
1 changed files with 34 additions and 3 deletions

View File

@ -370,8 +370,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;
@ -443,7 +445,9 @@ struct YAM_STATE {
//
// Buffer for dynarec code
//
#ifdef ENABLE_DYNAREC
uint8 dynacode[DYNACODE_MAX_SIZE];
#endif
};
//
@ -495,7 +499,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
}
/////////////////////////////////////////////////////////////////////////////
@ -562,7 +568,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
}
/////////////////////////////////////////////////////////////////////////////
@ -584,12 +592,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) {
YAMSTATE->dsp_dyna_enabled = (enable != 0);
#ifdef ENABLE_DYNAREC
if(enable == 0) { YAMSTATE->dsp_dyna_valid = 0; }
#endif
}
/////////////////////////////////////////////////////////////////////////////
@ -1241,7 +1253,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) {
@ -1250,7 +1264,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) {
@ -1363,7 +1379,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;
}
@ -1414,7 +1432,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;
}
@ -1616,7 +1636,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;
}
@ -1799,7 +1821,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;
}
@ -2005,8 +2029,7 @@ static void readnextsample(
if(out < (-0x8000)) { out = (-0x8000); /* logf("<adpcmunderflow>"); */ }
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;
@ -2500,6 +2523,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
@ -2517,12 +2541,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;
@ -2663,7 +2689,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
@ -2812,6 +2838,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
/////////////////////////////////////////////////////////////////////////////
@ -2834,11 +2861,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;
}