commanderx16 / x16-rom

Other
153 stars 44 forks source link

r35 joystick_get switches banked memory and doesn't set it back #98

Closed c64skate closed 4 years ago

c64skate commented 4 years ago

i'm not sure if you consider this as a bug but even if isn't, it should be mentioned in documentation. in my opinion, it's a bug since you don't expect a kernal call to switch banked memory which has nothing to do with memory.

i understand now kernal uses banked memory space and i'm fine with it. but current banked memory should be preserved.

this is my workaround.

// set RAM bank to 1 lda #$01 sta $9f61 ... jsr $ff56 // joystick_get // set RAM bank to 1 > AGAIN < ldx #$01 stx $9f61 ...

this is not ideal.

mist64 commented 4 years ago

This is surprising. The code uses KVARS_START and KVARS_END to switch banks:

https://github.com/commanderx16/x16-rom/blob/0430b26306a07e7f45e555cd74ba72513dc7f14e/kernal/drivers/joystick.s#L97

The macros are defined here:

https://github.com/commanderx16/x16-rom/blob/a1d057289d9461ecb41604d2a1957798dd9b9d5a/banks.inc

Can you give me a small test program that shows the issue?

c64skate commented 4 years ago

I'm now tracing the bug and i will share a simplified code but i can give you a clue. it doesn't happen if you don't press a key (move your joystick). it switches to bank #0 as soon as you move the joystick. it might be a messed up stack issue.

c64skate commented 4 years ago

Here is the test case in KickAssembler format. Please notice left border color is read from current banked memory address which is set to 1. When you press any key or move joystick, bank switches to 0.

test-source.txt