diff --git a/c64/aliases/,aliases_hardware.s b/c64/aliases/,aliases_hardware.s index 63790da6..e7a7a51c 100644 --- a/c64/aliases/,aliases_hardware.s +++ b/c64/aliases/,aliases_hardware.s @@ -70,6 +70,13 @@ .label VIC_XSCAN = $D02F // C128 only .label VIC_CLKRATE = $D030 // C128 only +#endif + +#if CONFIG_MB_MEGA_65 + + .label VIC_KEY = $D02F + .label VIC_XPOS = $D050 + #endif // SID registers @@ -165,7 +172,7 @@ .const BIT_CIA2_PRA_CLK_IN = $40 // 0 - low (pulled), 1 - high (released) .const BIT_CIA2_PRA_DAT_IN = $80 // 0 - low (pulled), 1 - high (released) -#if CONFIG_MB_MEGA_65 +#if CONFIG_MB_MEGA_65 .const C65_EXTKEYS_PR = $D607 .const C65_EXTKEYS_DDR = $D608 diff --git a/c64/kernal/keyboard/scnkey.s b/c64/kernal/keyboard/scnkey.s index 01a448c4..0aadfd93 100644 --- a/c64/kernal/keyboard/scnkey.s +++ b/c64/kernal/keyboard/scnkey.s @@ -30,6 +30,34 @@ SCNKEY: +#if CONFIG_KEYBOARD_C65 && CONFIG_MB_MEGA_65 + + // Idea by Paul Gardner-Stephen + + lda VIC_XPOS // check raster X position + cmp VIC_XPOS // if it changes, we are on a MEGA65 with VIC-IV registers already visible + bne scnkey_viciv_mode + + // We are on machine that is not in VIC-IV IO mode, so try enabling it (harmless on C64/C65) + // If we are on a C65 (or MEGA65 with C65 VIC-III IO mode selected), the above test would + // have failed, but we could already be in C65 IO mode. In that case, this will disable C65 IO + // mode when done. This is not ideal, but as MEGA65s start C65 mode with VIC-IV IO mode + // selected anyway, it should not be a big problem in practice. + + lda #$A5 + sta VIC_KEY + lda #$96 + sta VIC_KEY + + jsr scnkey_viciv_mode + + sta VIC_KEY + rts + +scnkey_viciv_mode: + +#endif + // Prepare for SHFLAG update lda SHFLAG