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

pce: accessing VDC registers in interrupt handlers may screw up libpce pce_vdc_* functions #348

Open
bcampbell opened this issue Jul 27, 2024 · 0 comments

Comments

@bcampbell
Copy link
Contributor

I think there's a potential issue accessing VDC registers, where things could get screwed up by an interrupt handler which also accesses VDC registers.
I'd imagine would be quite common - eg using raster interrupts to create a static status bar at the bottom of an otherwise scrolling screen.

The current pce_vdc_* functions all generate access code that looks like this:

; set up a write to vram $1000
stO #0     ; Memory Address Write Register (reg 0)
stl #$00   ; lo
st2 #$01   ; hi

But if an interrupt occurs immediately after the st0 and the interrupt handler accesses another VDC register, when the main code resumes, the st1 and st2 will likely be writing to the wrong register!

This issue is outlined in one of the original tech notes:

https://archive.org/details/PCEDev/HuC62%20-%20Tech%20Notes/page/n21/mode/2up

The solution they suggest is to store the register number in a global variable before the st0, then have the interrupt handler restore it when it exits.

Am I right in thinking that this is a potential issue?
The global-var solution seems like it'd work, although user-defined interrupt handlers would have to explicitly add something to restore the register.

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

No branches or pull requests

1 participant