From cb275dd6a3fa34f0026d796d9789503d0344e577 Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 29 Jul 2024 04:34:47 +0200 Subject: [PATCH 1/2] Fixes the behavior of F(N)INIT and F(N)SAVE on 8087, fixes the only MCPDIAG failure that was actually an 86Box bug, closes #4518. --- src/cpu/x87_ops_misc.h | 8 ++++++++ src/cpu/x87_ops_sf.h | 10 ++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/cpu/x87_ops_misc.h b/src/cpu/x87_ops_misc.h index d40d70140..96750468a 100644 --- a/src/cpu/x87_ops_misc.h +++ b/src/cpu/x87_ops_misc.h @@ -78,7 +78,11 @@ opFINIT(uint32_t fetchdat) cpu_state.npxc = 0x37F; #endif codegen_set_rounding_mode(X87_ROUNDING_NEAREST); +#ifdef FPU_8087 + cpu_state.npxs &= 0x4700; +#else cpu_state.npxs = 0; +#endif p = (uint64_t *) cpu_state.tag; #ifdef USE_NEW_DYNAREC *p = 0; @@ -406,7 +410,11 @@ FSAVE(void) cpu_state.npxc = 0x37F; codegen_set_rounding_mode(X87_ROUNDING_NEAREST); +#ifdef FPU_8087 + cpu_state.npxs &= 0x4700; +#else cpu_state.npxs = 0; +#endif p = (uint64_t *) cpu_state.tag; #ifdef USE_NEW_DYNAREC *p = 0; diff --git a/src/cpu/x87_ops_sf.h b/src/cpu/x87_ops_sf.h index af94897c9..31416447e 100644 --- a/src/cpu/x87_ops_sf.h +++ b/src/cpu/x87_ops_sf.h @@ -431,11 +431,12 @@ sf_FNSAVE_a16(uint32_t fetchdat) } #ifdef FPU_8087 - fpu_state.swd = 0x3FF; + fpu_state.cwd = 0x3FF; + fpu_state.swd &= 0x4700; #else fpu_state.cwd = 0x37F; -#endif fpu_state.swd = 0; +#endif fpu_state.tos = 0; fpu_state.tag = 0xffff; cpu_state.ismmx = 0; @@ -467,7 +468,7 @@ sf_FNSAVE_a32(uint32_t fetchdat) } # ifdef FPU_8087 - fpu_state.swd = 0x3FF; + fpu_state.cwd = 0x3FF; # else fpu_state.cwd = 0x37F; # endif @@ -504,10 +505,11 @@ sf_FNINIT(uint32_t fetchdat) cpu_state.pc++; #ifdef FPU_8087 fpu_state.cwd = 0x3FF; + fpu_state.swd &= 0x4700; #else fpu_state.cwd = 0x37F; -#endif fpu_state.swd = 0; +#endif fpu_state.tos = 0; fpu_state.tag = 0xffff; fpu_state.foo = 0; From 9135083877dbb22a37016e6381b97b9992f3994f Mon Sep 17 00:00:00 2001 From: OBattler Date: Mon, 29 Jul 2024 06:37:40 +0200 Subject: [PATCH 2/2] SN76489: Correctly ignore bit 6 of the second data byte on the non-PSSJ types, fixes #4664. --- src/sound/snd_sn76489.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/sound/snd_sn76489.c b/src/sound/snd_sn76489.c index 519219934..d7bfa87b9 100644 --- a/src/sound/snd_sn76489.c +++ b/src/sound/snd_sn76489.c @@ -88,7 +88,7 @@ sn76489_write(UNUSED(uint16_t addr), uint8_t data, void *priv) case 0: sn76489->freqlo[3] = data & 0xf; sn76489->latch[3] = (sn76489->freqlo[3] | (sn76489->freqhi[3] << 4)) << 6; - if (sn76489->extra_divide) + if (!sn76489->extra_divide) sn76489->latch[3] &= 0x3ff; if (!sn76489->latch[3]) sn76489->latch[3] = (sn76489->extra_divide ? 2048 : 1024) << 6; @@ -101,7 +101,7 @@ sn76489_write(UNUSED(uint16_t addr), uint8_t data, void *priv) case 0x20: sn76489->freqlo[2] = data & 0xf; sn76489->latch[2] = (sn76489->freqlo[2] | (sn76489->freqhi[2] << 4)) << 6; - if (sn76489->extra_divide) + if (!sn76489->extra_divide) sn76489->latch[2] &= 0x3ff; if (!sn76489->latch[2]) sn76489->latch[2] = (sn76489->extra_divide ? 2048 : 1024) << 6; @@ -114,7 +114,7 @@ sn76489_write(UNUSED(uint16_t addr), uint8_t data, void *priv) case 0x40: sn76489->freqlo[1] = data & 0xf; sn76489->latch[1] = (sn76489->freqlo[1] | (sn76489->freqhi[1] << 4)) << 6; - if (sn76489->extra_divide) + if (!sn76489->extra_divide) sn76489->latch[1] &= 0x3ff; if (!sn76489->latch[1]) sn76489->latch[1] = (sn76489->extra_divide ? 2048 : 1024) << 6; @@ -132,7 +132,7 @@ sn76489_write(UNUSED(uint16_t addr), uint8_t data, void *priv) sn76489->latch[0] = sn76489->latch[1]; else sn76489->latch[0] = 0x400 << (data & 3); - if (sn76489->extra_divide) + if (!sn76489->extra_divide) sn76489->latch[0] &= 0x3ff; if (!sn76489->latch[0]) sn76489->latch[0] = (sn76489->extra_divide ? 2048 : 1024) << 6; @@ -157,9 +157,12 @@ sn76489_write(UNUSED(uint16_t addr), uint8_t data, void *priv) if (!sn76489->latch[0]) sn76489->latch[0] = 1024 << 6; } else if ((sn76489->firstdat & 0x70) != 0x60) { - sn76489->freqhi[sn76489->lasttone] = data & 0x7F; - freq = sn76489->freqlo[sn76489->lasttone] | (sn76489->freqhi[sn76489->lasttone] << 4); if (sn76489->extra_divide) + sn76489->freqhi[sn76489->lasttone] = data & 0x7F; + else + sn76489->freqhi[sn76489->lasttone] = data & 0x3F; + freq = sn76489->freqlo[sn76489->lasttone] | (sn76489->freqhi[sn76489->lasttone] << 4); + if (!sn76489->extra_divide) freq &= 0x3ff; if (!freq) freq = sn76489->extra_divide ? 2048 : 1024; @@ -174,6 +177,12 @@ void sn74689_set_extra_divide(sn76489_t *sn76489, int enable) { sn76489->extra_divide = enable; + + if (!enable) { + for (uint8_t c = 1; c < 4; c++) + sn76489->latch[c] &= ~(0x400 << 6); + sn76489->latch[0] &= ~(0x400 << 6); + } } void