Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch music engine to avoid echo buffer overwriting sample data #292

Merged
merged 4 commits into from
Apr 17, 2024

Conversation

charasyn
Copy link
Contributor

@charasyn charasyn commented Apr 2, 2024

Recently, we've become aware of a bug. When transitioning from a song with a non-zero echo delay value to a new song which uses instrument samples that would overlap with the previous echo buffer, the samples may become corrupted independent of the echo value used by the new song. This is because the echo feature was not disabled when the instruments for the new song were uploaded.

This branch adds a new feature where CoilSnake will patch the music engine to disable echo when uploading data.

This is the assembly code added to the SPC, assembled by hand:

<          > ; push old echo value
< eb 4d    >     mov y, $4d
< f0 13    >     beq _exit
< 6d       >     push y
<          > ; call existing code at $0b2c with A=0 to disable echo
< e8 00    >     mov a, #0
< 3f 2c 0b >     call $0b2c
<          > ; wait for (old echo) * 16ms = 2ms * (old echo) * 8
< ae       >     pull a
< 1c       >     asl a
< 1c       >     asl a
< 1c       >     asl a
< bc       >     inc a
< fd       >     mov y, a
< e5 fd 00 > -   mov a, $00fd
< f0 fb    >     beq -
< fe f9    >     dbnz y, -
<          > ; continue with normal code
<          > _exit:
< 5f e1 0e >     jmp $0ee1

I think this is a good standard to follow for the rest of the size-related messages. They should have bounds checking which raises an exception if it fails, and debug logs which print out the size in case you need to know how much space is left.
@charasyn charasyn merged commit cf1087a into pk-hack:master Apr 17, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant