Skip to content

Commit

Permalink
Add hack so zombie decrease kinda works
Browse files Browse the repository at this point in the history
Following the technique described here:
https://github.com/jkotlinski/apu-zombie-test, but looking for just
these values in this order, without understanding any of the underlying
behavior.
  • Loading branch information
binji committed Jun 6, 2023
1 parent b0ee86c commit 6f0bf66
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/emulator-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ static int s_breakpoint_max_id;
X(A, V, write_nrx2_initial_volume_abi, "(%#04x, %#02x) initial_volume=%u") \
X(A, V, write_nrx2_zombie_mode_abii, \
"(%#04x, %#02x) zombie mode: volume %u -> %u") \
X(A, V, write_nrx2_zombie_mode_hack_abi, \
"(%#04x, %#02x) zombie mode hack: step %u") \
X(A, D, write_nrx4_disable_channel_ab, "(%#04x, %#02x) disabling channel") \
X(A, D, write_nrx4_extra_length_clock_abi, \
"(%#04x, %#02x) extra length clock = %u") \
Expand Down
22 changes: 22 additions & 0 deletions src/emulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ typedef struct {
u8 volume; /* 0..15 */
u32 timer; /* 0..period */
Bool automatic; /* TRUE when MAX/MIN has not yet been reached. */
u8 zombie_step; /* HACK: support zombie volume decrease */
} Envelope;

/* Channel 1 and 2 */
Expand Down Expand Up @@ -2893,6 +2894,27 @@ static void write_nrx2_reg(Emulator* e, Channel* channel, Address addr,
HOOK(write_nrx2_zombie_mode_abii, addr, value, channel->envelope.volume,
new_volume);
channel->envelope.volume = new_volume;
// Super ugly hack to support decreasing volume in zombie mode.
channel->envelope.zombie_step = value == 9;
if (value == 9) {
HOOK(write_nrx2_zombie_mode_hack_abi, addr, value,
channel->envelope.zombie_step);
}
} else if (UNLIKELY(channel->envelope.zombie_step > 0)) {
if (channel->envelope.zombie_step == 1 && value == 0x11) {
channel->envelope.zombie_step++;
HOOK(write_nrx2_zombie_mode_hack_abi, addr, value,
channel->envelope.zombie_step);
} else if (channel->envelope.zombie_step == 2 && value == 0x18) {
channel->envelope.zombie_step++;
u8 new_volume = (channel->envelope.volume + ENVELOPE_MAX_VOLUME - 1) &
ENVELOPE_MAX_VOLUME;
HOOK(write_nrx2_zombie_mode_abii, addr, value, channel->envelope.volume,
new_volume);
channel->envelope.volume = new_volume;
} else {
channel->envelope.zombie_step = 0;
}
}
}
channel->envelope.direction = UNPACK(value, NRX2_ENVELOPE_DIRECTION);
Expand Down

0 comments on commit 6f0bf66

Please sign in to comment.