Skip to content

Commit

Permalink
Fixed tremolo updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TexZK committed May 2, 2024
1 parent 1b80a0f commit 17913f2
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion include/aymo_ymf262_x86_avx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
3 changes: 2 additions & 1 deletion include/aymo_ymf262_x86_avx2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
2 changes: 1 addition & 1 deletion include/aymo_ymf262_x86_sse41.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand Down
8 changes: 6 additions & 2 deletions src/aymo_ymf262_arm_neon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions src/aymo_ymf262_x86_avx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions src/aymo_ymf262_x86_avx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions src/aymo_ymf262_x86_sse41.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 0 additions & 9 deletions tests/test_ymf262_compare_epilogue_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 8 additions & 3 deletions tests/test_ymf262_x86_avx2_compare.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 17913f2

Please sign in to comment.