diff --git a/Makefile b/Makefile index c5eb20c9..e737cd4b 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,7 @@ SRCDIR_KERNAL = $(SRCDIR_COMMON) \ c64/kernal/jumptable \ c64/kernal/iec \ c64/kernal/interrupts \ + c64/kernal/keyboard \ c64/kernal/print \ c64/kernal/screen diff --git a/c64/kernal/fda3.ioinit.s b/c64/kernal/fda3.ioinit.s index 778d5492..7bb0cc06 100644 --- a/c64/kernal/fda3.ioinit.s +++ b/c64/kernal/fda3.ioinit.s @@ -101,6 +101,14 @@ IOINIT: sta CIA1_CRA lda CIA1_ICR + // Setup the CIA1 for reading the keyboard - 'POKE 56322, 0' on original ROMs proves this + // is done during initialization, not during the interrupt + + ldx #$FF + stx CIA1_DDRA // output + ldy #$00 + sty CIA1_DDRB // input + // Set DDR on CIA2 for IEC bus, VIC-II banking lda #$3B sta CIA2_DDRA diff --git a/c64/kernal/udtim.s b/c64/kernal/interrupts/udtim.s similarity index 100% rename from c64/kernal/udtim.s rename to c64/kernal/interrupts/udtim.s diff --git a/c64/kernal/scnkey.s b/c64/kernal/keyboard/scnkey.s similarity index 90% rename from c64/kernal/scnkey.s rename to c64/kernal/keyboard/scnkey.s index a1946dc0..1ea166da 100644 --- a/c64/kernal/scnkey.s +++ b/c64/kernal/keyboard/scnkey.s @@ -34,7 +34,7 @@ SCNKEY: beq sk_start dec KOUNT - // Setup the CIA registers + // Setup the CIA registers XXX check whether the C64 does it every time ldx #$FF stx CIA1_DDRA // output @@ -45,6 +45,7 @@ SCNKEY: lda SHFLAG sta LSTSHF + ldy #$00 sty SHFLAG // XXX retrieve ALT and NO_SCRL status for C128/C65 keyboards @@ -52,6 +53,7 @@ SCNKEY: // Check for any activity sty CIA1_PRA // connect all the lines + ldx #$FF cpx CIA1_PRB beq scnkey_no_keys @@ -60,7 +62,9 @@ SCNKEY: // Set pointer in KEYTAB jsr scnkey_via_keytab - // XXX scan the keyboard matrix + // XXX check for joystick activity + + // Scan the keyboard matrix diff --git a/c64/kernal/scnkey_set_keytab.s b/c64/kernal/keyboard/scnkey_set_keytab.s similarity index 92% rename from c64/kernal/scnkey_set_keytab.s rename to c64/kernal/keyboard/scnkey_set_keytab.s index e9ae5671..52db9f7d 100644 --- a/c64/kernal/scnkey_set_keytab.s +++ b/c64/kernal/keyboard/scnkey_set_keytab.s @@ -31,6 +31,8 @@ scnkey_set_keytab: adc KEYTAB+1 sta KEYTAB+1 +scnkey_toggle_if_needed: // entry for SCNKEY (TWW/CTR version) + // Check if we should toggle the character set lda MODE diff --git a/c64/kernal/scnkey_tww_ctr.s b/c64/kernal/keyboard/scnkey_tww_ctr.s similarity index 94% rename from c64/kernal/scnkey_tww_ctr.s rename to c64/kernal/keyboard/scnkey_tww_ctr.s index 83db260a..954ec933 100644 --- a/c64/kernal/scnkey_tww_ctr.s +++ b/c64/kernal/keyboard/scnkey_tww_ctr.s @@ -218,18 +218,15 @@ Main: sta BufferNew+0 sta BufferNew+1 sta BufferNew+2 - - ldx #$ff - stx $dc02 // Port A - Output - ldy #$00 - sty $dc03 // Port B - Input - // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Check for Port Activity - sty $dc00 // Connect all Keyboard Rows - cpx $dc01 + ldx #$FF + ldy #$00 + + sty CIA1_PRA // Connect all Keyboard Rows + cpx CIA1_PRB bne skip0 jmp NoActivityDetected @@ -240,7 +237,7 @@ JoystickActivity: lda #$00 sta SHFLAG - lda $dc01 + lda CIA1_PRB and #$03 cmp #$01 bne !+ @@ -267,7 +264,7 @@ JoystickActivity: beq !+ jmp skdone !: - lda $dc01 + lda CIA1_PRB and #$0c cmp #$04 bne !+ @@ -293,8 +290,8 @@ skip0: // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Check for Control Port #1 Activity - stx $dc00 // Disconnect all Keyboard Rows - cpx $dc01 // Only Control Port activity will be detected + stx CIA1_PRA // Disconnect all Keyboard Rows + cpx CIA1_PRB // Only Control Port activity will be detected bne JoystickActivity // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -303,9 +300,9 @@ skip0: ldx #7 lda #%11111110 next_row: - sta $dc00 + sta CIA1_PRA pha - lda $dc01 + lda CIA1_PRB sta ScanResult,x pla sec @@ -318,8 +315,8 @@ next_row: // //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // // Check for Control Port #1 Activity (again) - stx $dc00 // Disconnect all Keyboard Rows - cpx $dc01 // Only Control Port activity will be detected + stx CIA1_PRA // Disconnect all Keyboard Rows + cpx CIA1_PRB // Only Control Port activity will be detected beq !+ jmp ReturnNoKeys !: @@ -375,19 +372,8 @@ next_row: ora SHFLAG sta SHFLAG - // Chick for shift + Vendor - cmp #$03 - bne no_case_toggle - lda LSTSHF - cmp #$03 - beq no_case_toggle - - lda MODE - bne no_case_toggle - - lda VIC_YMCSB - eor #$02 - sta VIC_YMCSB + // Handle SHIFT + VENDOR + jsr scnkey_toggle_if_needed no_case_toggle: