commanderx16 / x16-emulator

Emulator for the Commander X16 8-bit computer
384 stars 60 forks source link

ADDR_SEL of VERA_CTRL must be 0 when returning control to kernal #166

Open joolin1 opened 5 years ago

joolin1 commented 5 years ago

Run the following code:

lda #1
sta VERA_CTRL
lda #$10
sta VERA_ADDR_HI
lda #20
sta VERA_ADDR_MID
stz VERA_ADDR_LO
lda #1
sta VERA_DATA1
rts

After returning the system goes bananas and starts printing random characters to the screen. The problem is that the address selection of VERA_CTRL has the value 1 when returning. If we add the line "stz VERA_CTRL" before returning everything works fine. But should this really be necessary? This can cause a lot of confusion if left as it is.

kktos commented 5 years ago

@joolin1 I suppose by "returning to the kernal", you mean back to BASIC, right ? So if you do a SYS to call your program, you wish the BASIC will set the VERA_CTRL to the one needed for itself, that's right ?

joolin1 commented 5 years ago

Yes, I mean back to BASIC. If I call the included code with a SYS, everything should work fine, at least that is my supposition. But it does not. I have to make sure VERA_CTRL is set to 0, otherwise the system/BASIC starts to print characters to the screen after returning to BASIC. If I am not making myself clear you can test the code and see what happens.

mist64 commented 5 years ago

I can see how this is a problem. We should probably fix it, and add a stz veractl to all KERNAL code that accesses VERA. This is a little tricky to audit though.

RevCurtisP commented 5 years ago

The code I've been writing assumes that any Kernal calls will return veractl to a safe value, so this behavior is definitely preferred.