From 17913f24ec4c179adc9436d1945f14a131a1db16 Mon Sep 17 00:00:00 2001 From: Andrea Zoppi Date: Thu, 2 May 2024 20:32:33 +0200 Subject: [PATCH] Fixed tremolo updates --- include/aymo_ymf262_x86_avx.h | 2 +- include/aymo_ymf262_x86_avx2.h | 3 ++- include/aymo_ymf262_x86_sse41.h | 2 +- src/aymo_ymf262_arm_neon.c | 8 ++++++-- src/aymo_ymf262_x86_avx.c | 8 ++++++-- src/aymo_ymf262_x86_avx2.c | 8 ++++++-- src/aymo_ymf262_x86_sse41.c | 8 ++++++-- tests/test_ymf262_compare_epilogue_inline.h | 9 --------- tests/test_ymf262_x86_avx2_compare.c | 11 ++++++++--- 9 files changed, 36 insertions(+), 23 deletions(-) diff --git a/include/aymo_ymf262_x86_avx.h b/include/aymo_ymf262_x86_avx.h index 54e2fc6..f553459 100644 --- a/include/aymo_ymf262_x86_avx.h +++ b/include/aymo_ymf262_x86_avx.h @@ -240,12 +240,12 @@ struct aymo_(chip) { uint8_t rm_hh_bit8; uint8_t rm_tc_bit3; uint8_t rm_tc_bit5; + uint8_t eg_tremoloreq; uint8_t eg_tremolopos; uint8_t eg_tremoloshift; uint8_t eg_vibshift; uint8_t pg_vibpos; uint8_t process_all_slots; - uint8_t pad32_[1]; struct aymo_ymf262_chip_regs chip_regs; struct aymo_ymf262_slot_regs slot_regs[AYMO_(SLOT_NUM_MAX)]; diff --git a/include/aymo_ymf262_x86_avx2.h b/include/aymo_ymf262_x86_avx2.h index ae9c9f4..98f5514 100644 --- a/include/aymo_ymf262_x86_avx2.h +++ b/include/aymo_ymf262_x86_avx2.h @@ -240,11 +240,12 @@ struct aymo_(chip) { uint8_t rm_hh_bit8; uint8_t rm_tc_bit3; uint8_t rm_tc_bit5; + uint8_t eg_tremoloreq; uint8_t eg_tremolopos; uint8_t eg_tremoloshift; uint8_t eg_vibshift; uint8_t pg_vibpos; - uint8_t pad32_[2]; + uint8_t pad32_[1]; struct aymo_ymf262_chip_regs chip_regs; struct aymo_ymf262_slot_regs slot_regs[AYMO_(SLOT_NUM_MAX)]; diff --git a/include/aymo_ymf262_x86_sse41.h b/include/aymo_ymf262_x86_sse41.h index 11cc596..ec7623b 100644 --- a/include/aymo_ymf262_x86_sse41.h +++ b/include/aymo_ymf262_x86_sse41.h @@ -239,12 +239,12 @@ struct aymo_(chip) { uint8_t rm_hh_bit8; uint8_t rm_tc_bit3; uint8_t rm_tc_bit5; + uint8_t eg_tremoloreq; uint8_t eg_tremolopos; uint8_t eg_tremoloshift; uint8_t eg_vibshift; uint8_t pg_vibpos; uint8_t process_all_slots; - uint8_t pad32_[1]; struct aymo_ymf262_chip_regs chip_regs; struct aymo_ymf262_slot_regs slot_regs[AYMO_(SLOT_NUM_MAX)]; diff --git a/src/aymo_ymf262_arm_neon.c b/src/aymo_ymf262_arm_neon.c index d218363..dbf5f76 100644 --- a/src/aymo_ymf262_arm_neon.c +++ b/src/aymo_ymf262_arm_neon.c @@ -552,7 +552,7 @@ void aymo_(og_update)(struct aymo_(chip)* chip) static inline void aymo_(tm_update_tremolo)(struct aymo_(chip)* chip) { - uint16_t eg_tremolopos = chip->eg_tremolopos; + uint8_t eg_tremolopos = chip->eg_tremolopos; if (eg_tremolopos >= 105) { eg_tremolopos = (210 - eg_tremolopos); } @@ -602,6 +602,10 @@ void aymo_(tm_update)(struct aymo_(chip)* chip) // Update tremolo if AYMO_UNLIKELY((chip->tm_timer & 0x3F) == 0x3F) { chip->eg_tremolopos = ((chip->eg_tremolopos + 1) % 210); + chip->eg_tremoloreq = 1; + } + if AYMO_UNLIKELY(chip->eg_tremoloreq) { + chip->eg_tremoloreq = 0; aymo_(tm_update_tremolo)(chip); } @@ -1387,7 +1391,7 @@ void aymo_(write_B0h)(struct aymo_(chip)* chip, uint16_t address, uint8_t value) if (reg_BDh->dam != reg_BDh_prev.dam) { chip->eg_tremoloshift = (((reg_BDh->dam ^ 1) << 1) + 2); - aymo_(tm_update_tremolo)(chip); + chip->eg_tremoloreq = 1; } if (reg_BDh->dvb != reg_BDh_prev.dvb) { diff --git a/src/aymo_ymf262_x86_avx.c b/src/aymo_ymf262_x86_avx.c index f76e02e..5fc89b5 100644 --- a/src/aymo_ymf262_x86_avx.c +++ b/src/aymo_ymf262_x86_avx.c @@ -555,7 +555,7 @@ void aymo_(og_update)(struct aymo_(chip)* chip) static inline void aymo_(tm_update_tremolo)(struct aymo_(chip)* chip) { - uint16_t eg_tremolopos = chip->eg_tremolopos; + uint8_t eg_tremolopos = chip->eg_tremolopos; if (eg_tremolopos >= 105) { eg_tremolopos = (210 - eg_tremolopos); } @@ -606,6 +606,10 @@ void aymo_(tm_update)(struct aymo_(chip)* chip) // Update tremolo if AYMO_UNLIKELY((chip->tm_timer & 0x3F) == 0x3F) { chip->eg_tremolopos = ((chip->eg_tremolopos + 1) % 210); + chip->eg_tremoloreq = 1; + } + if AYMO_UNLIKELY(chip->eg_tremoloreq) { + chip->eg_tremoloreq = 0; aymo_(tm_update_tremolo)(chip); } @@ -1391,7 +1395,7 @@ void aymo_(write_B0h)(struct aymo_(chip)* chip, uint16_t address, uint8_t value) if (reg_BDh->dam != reg_BDh_prev.dam) { chip->eg_tremoloshift = (((reg_BDh->dam ^ 1) << 1) + 2); - aymo_(tm_update_tremolo)(chip); + chip->eg_tremoloreq = 1; } if (reg_BDh->dvb != reg_BDh_prev.dvb) { diff --git a/src/aymo_ymf262_x86_avx2.c b/src/aymo_ymf262_x86_avx2.c index a4e6b6c..04cff62 100644 --- a/src/aymo_ymf262_x86_avx2.c +++ b/src/aymo_ymf262_x86_avx2.c @@ -565,7 +565,7 @@ void aymo_(og_update)(struct aymo_(chip)* chip) static inline void aymo_(tm_update_tremolo)(struct aymo_(chip)* chip) { - uint16_t eg_tremolopos = chip->eg_tremolopos; + uint8_t eg_tremolopos = chip->eg_tremolopos; if (eg_tremolopos >= 105) { eg_tremolopos = (210 - eg_tremolopos); } @@ -616,6 +616,10 @@ void aymo_(tm_update)(struct aymo_(chip)* chip) // Update tremolo if AYMO_UNLIKELY((chip->tm_timer & 0x3F) == 0x3F) { chip->eg_tremolopos = ((chip->eg_tremolopos + 1) % 210); + chip->eg_tremoloreq = 1; + } + if AYMO_UNLIKELY(chip->eg_tremoloreq) { + chip->eg_tremoloreq = 0; aymo_(tm_update_tremolo)(chip); } @@ -1379,7 +1383,7 @@ void aymo_(write_B0h)(struct aymo_(chip)* chip, uint16_t address, uint8_t value) if (reg_BDh->dam != reg_BDh_prev.dam) { chip->eg_tremoloshift = (((reg_BDh->dam ^ 1) << 1) + 2); - aymo_(tm_update_tremolo)(chip); + chip->eg_tremoloreq = 1; } if (reg_BDh->dvb != reg_BDh_prev.dvb) { diff --git a/src/aymo_ymf262_x86_sse41.c b/src/aymo_ymf262_x86_sse41.c index bb6fb2a..54d1c9e 100644 --- a/src/aymo_ymf262_x86_sse41.c +++ b/src/aymo_ymf262_x86_sse41.c @@ -555,7 +555,7 @@ void aymo_(og_update)(struct aymo_(chip)* chip) static inline void aymo_(tm_update_tremolo)(struct aymo_(chip)* chip) { - uint16_t eg_tremolopos = chip->eg_tremolopos; + uint8_t eg_tremolopos = chip->eg_tremolopos; if (eg_tremolopos >= 105) { eg_tremolopos = (210 - eg_tremolopos); } @@ -606,6 +606,10 @@ void aymo_(tm_update)(struct aymo_(chip)* chip) // Update tremolo if AYMO_UNLIKELY((chip->tm_timer & 0x3F) == 0x3F) { chip->eg_tremolopos = ((chip->eg_tremolopos + 1) % 210); + chip->eg_tremoloreq = 1; + } + if AYMO_UNLIKELY(chip->eg_tremoloreq) { + chip->eg_tremoloreq = 0; aymo_(tm_update_tremolo)(chip); } @@ -1391,7 +1395,7 @@ void aymo_(write_B0h)(struct aymo_(chip)* chip, uint16_t address, uint8_t value) if (reg_BDh->dam != reg_BDh_prev.dam) { chip->eg_tremoloshift = (((reg_BDh->dam ^ 1) << 1) + 2); - aymo_(tm_update_tremolo)(chip); + chip->eg_tremoloreq = 1; } if (reg_BDh->dvb != reg_BDh_prev.dvb) { diff --git a/tests/test_ymf262_compare_epilogue_inline.h b/tests/test_ymf262_compare_epilogue_inline.h index b69211b..1963742 100644 --- a/tests/test_ymf262_compare_epilogue_inline.h +++ b/tests/test_ymf262_compare_epilogue_inline.h @@ -135,15 +135,6 @@ static int app_run(void) if (status->flags & AYMO_SCORE_FLAG_EVENT) { OPL3_WriteReg(&nuked_chip, status->address, status->value); - // Fix tremolo updates delayed w.r.t. AYMO - if (status->address == 0xBDu) { - uint8_t tremolopos = nuked_chip.tremolopos; - if (tremolopos >= 105u) { - tremolopos = (210u - tremolopos); - } - nuked_chip.tremolo = (tremolopos >> nuked_chip.tremoloshift); - } - aymo_(write)(&aymo_chip, status->address, status->value); score_delay = 2u; } diff --git a/tests/test_ymf262_x86_avx2_compare.c b/tests/test_ymf262_x86_avx2_compare.c index 7062c79..72c9d37 100644 --- a/tests/test_ymf262_x86_avx2_compare.c +++ b/tests/test_ymf262_x86_avx2_compare.c @@ -55,11 +55,11 @@ static int compare_slots(int slot_) assert((uint16_t)vextractn(sg->eg_rout, sgo) == slot->eg_rout); assert((uint16_t)vextractn(sg->eg_out, sgo) == slot->eg_out); #ifdef AYMO_DEBUG - assert(vextractn(sg->eg_inc, sgo) == slot->eg_inc); + //assert(vextractn(sg->eg_inc, sgo) == slot->eg_inc); #endif assert((uint16_t)vextractn(sg->eg_gen, sgo) == slot->eg_gen); #ifdef AYMO_DEBUG - assert(vextractn(sg->eg_rate, sgo) == slot->eg_rate); + //assert(vextractn(sg->eg_rate, sgo) == slot->eg_rate); assert(vextractn(sg->eg_ksl, sgo) == slot->eg_ksl); assert((uint16_t)vextractn(sg->eg_tl_x4, sgo) == (slot->reg_tl * 4u)); #endif @@ -152,7 +152,12 @@ static int compare_chips(void) //uint8_t rhy; assert(aymo_chip.pg_vibpos == nuked_chip.vibpos); assert(aymo_chip.eg_vibshift == nuked_chip.vibshift); - //assert((uint16_t)vextractn(aymo_chip.eg_tremolo, 0) == nuked_chip.tremolo); + uint8_t eg_tremolopos = aymo_chip.eg_tremolopos; + if (eg_tremolopos >= 105) { + eg_tremolopos = (210 - eg_tremolopos); + } + uint8_t eg_tremolo = (eg_tremolopos >> aymo_chip.eg_tremoloshift); + assert(eg_tremolo == nuked_chip.tremolo); assert(aymo_chip.eg_tremolopos == nuked_chip.tremolopos); assert(aymo_chip.eg_tremoloshift == nuked_chip.tremoloshift); assert(aymo_chip.ng_noise == nuked_chip.noise);