work on new keyboard scanning routine
This commit is contained in:
1 parent
31d181aac3
commit
5b69467dc1
10 files changed
+319
-59
No files matched your search
@@ -0,0 +1,150 @@
|
||||
|
||||
//
|
||||
// PETSCII codes for all the supported keys, for all the keyboards
|
||||
//
|
||||
// - [CM64] Compute's Mapping the Commodore 64
|
||||
// - [CM128] Compute's Mapping the Commodore 128
|
||||
// - https://en.wikipedia.org/wiki/PETSCII
|
||||
//
|
||||
|
||||
|
||||
|
||||
// Not really PETSCII codes, but bitmask values for SHFLAG variable
|
||||
// [CM64] page 68, [CM128] page 212
|
||||
|
||||
.const KEY_FLAG_SHIFT = %00000001
|
||||
.const KEY_FLAG_VENDOR = %00000010
|
||||
.const KEY_FLAG_CTRL = %00000100
|
||||
.const KEY_FLAG_ALT = %00001000 // C65 / C128
|
||||
.const KEY_FLAG_NO_SCRL = %00100000 // C65 / C128, Open ROMs unofficial
|
||||
|
||||
|
||||
// Note - the following PETSCII codes are currently unassigned, can be used for further extensions:
|
||||
//
|
||||
// $01, $04, $06, $0A, $0B, $0C, $0F, $82, $83, $84
|
||||
|
||||
|
||||
.const KEY_NA = $00 // to indicate that no key is presed
|
||||
|
||||
|
||||
// PETSCII codes for our extended screen editor
|
||||
|
||||
.const KEY_BOTTOM = $02 // CTRL+B - DolphinDOS compatible
|
||||
.const KEY_TAB_FW = $8F // CTRL+>, TAB - Open ROMs unofficial
|
||||
.const KEY_TAB_BW = $80 // CTRL+<, SHIFT+TAB - Open ROMs unofficial
|
||||
|
||||
|
||||
// PETSCII codes for certain C128 and C65 functionalities
|
||||
|
||||
.const KEY_BELL = $07 // C65 / C128, no key
|
||||
.const KEY_ESC = $1B // C65 / C128
|
||||
.const KEY_HELP = $10 // C65 / C128, Open ROMs unofficial
|
||||
|
||||
|
||||
// PETSCII codes for programmable keys
|
||||
|
||||
.const KEY_RUN = $03
|
||||
|
||||
.const KEY_F1 = $85
|
||||
.const KEY_F2 = $86
|
||||
.const KEY_F3 = $87
|
||||
.const KEY_F4 = $88
|
||||
.const KEY_F5 = $89
|
||||
.const KEY_F6 = $8A
|
||||
.const KEY_F7 = $8B
|
||||
.const KEY_F8 = $8C
|
||||
|
||||
.const KEY_F9 = $15 // C65, Open ROMs unofficial
|
||||
.const KEY_F10 = $16 // C65, Open ROMs unofficial
|
||||
.const KEY_F11 = $17 // C65, Open ROMs unofficial
|
||||
.const KEY_F12 = $18 // C65, Open ROMs unofficial
|
||||
.const KEY_F13 = $19 // C65, Open ROMs unofficial
|
||||
.const KEY_F14 = $1A // C65, Open ROMs unofficial
|
||||
|
||||
|
||||
// PETSCII codes for cursor keys
|
||||
|
||||
.const KEY_CRSR_UP = $91
|
||||
.const KEY_CRSR_DOWN = $11
|
||||
.const KEY_CRSR_LEFT = $9D
|
||||
.const KEY_CRSR_RIGHT = $1D
|
||||
|
||||
|
||||
// PETSCII codes for colors
|
||||
|
||||
.const KEY_RVS_ON = $12 // CTRL+9
|
||||
.const KEY_RVS_OFF = $92 // CTRL+0
|
||||
|
||||
.const KEY_BLACK = $90 // CTRL+1
|
||||
.const KEY_WHITE = $05 // CTRL+2
|
||||
.const KEY_RED = $1C // CTRL+3
|
||||
.const KEY_CYAN = $9F // CTRL+4
|
||||
.const KEY_PURPLE = $9C // CTRL+5
|
||||
.const KEY_GREEN = $1E // CTRL+6
|
||||
.const KEY_BLUE = $1F // CTRL+7
|
||||
.const KEY_YELLOW = $9E // CTRL+8
|
||||
|
||||
.const KEY_ORANGE = $81 // VENDOR+1
|
||||
.const KEY_BROWN = $95 // VENDOR+2
|
||||
.const KEY_LT_RED = $96 // VENDOR+3
|
||||
.const KEY_GREY_1 = $97 // VENDOR+4
|
||||
.const KEY_GREY_2 = $98 // VENDOR+5
|
||||
.const KEY_LT_GREEN = $99 // VENDOR+6
|
||||
.const KEY_LT_BLUE = $9A // VENDOR+7
|
||||
.const KEY_GREY_3 = $9B // VENDOR+8
|
||||
|
||||
|
||||
// PETSCII codes for case toggle
|
||||
|
||||
.const KEY_SHIFT_ON = $09 // no key
|
||||
.const KEY_SHIFT_OFF = $08 // no key
|
||||
.const KEY_TXT = $0E // no key
|
||||
.const KEY_GFX = $8E // no key
|
||||
|
||||
|
||||
// PETSCII codes for other non-printable characters
|
||||
|
||||
.const KEY_RETURN = $0D
|
||||
.const KEY_CLR = $93
|
||||
.const KEY_HOME = $13
|
||||
.const KEY_INS = $94
|
||||
.const KEY_DEL = $14
|
||||
|
||||
|
||||
// PETSCII codes for printable characters
|
||||
|
||||
.const KEY_SPACE = $20
|
||||
.const KEY_EXCLAMATION = $21
|
||||
.const KEY_QUOTE = $22
|
||||
.const KEY_HASH = $23
|
||||
.const KEY_DOLLAR = $24
|
||||
.const KEY_PERCENT = $25
|
||||
.const KEY_AMPERSAND = $26
|
||||
.const KEY_APOSTROPHE = $27
|
||||
.const KEY_R_BRACKET_L = $28
|
||||
.const KEY_R_BRACKET_R = $29
|
||||
.const KEY_ASTERISK = $2A
|
||||
.const KEY_PLUS = $2B
|
||||
.const KEY_COMA = $2C
|
||||
.const KEY_MINUS = $2D
|
||||
.const KEY_FULLSTOP = $2E
|
||||
.const KEY_SLASH = $2F
|
||||
|
||||
.const KEY_0 = $30
|
||||
.const KEY_1 = $31
|
||||
.const KEY_2 = $32
|
||||
.const KEY_3 = $33
|
||||
.const KEY_4 = $34
|
||||
.const KEY_5 = $35
|
||||
.const KEY_6 = $36
|
||||
.const KEY_7 = $37
|
||||
.const KEY_8 = $38
|
||||
.const KEY_9 = $39
|
||||
.const KEY_COLON = $3A
|
||||
.const KEY_SEMICOLON = $3B
|
||||
.const KEY_LT = $3C
|
||||
.const KEY_EQ = $3D
|
||||
.const KEY_GT = $3E
|
||||
.const KEY_QUESTION = $3F
|
||||
|
||||
// XXX finish this: $4x, $5x, $6x, $7x, $Ax, $Bx, $Cx, $Dx, $Ex, $Fx
|
||||
@@ -74,6 +74,8 @@ cint_brk: // entry for BRK and STOP+RESTORE - XXX, where should it start?
|
||||
|
||||
// Set keyboard decode vector (Compute's Mapping the 64 p215)
|
||||
|
||||
#if CONFIG_SCNKEY_TWW_CTR
|
||||
|
||||
// Set initial variables for our improved keyboard scan routine
|
||||
lda #$FF
|
||||
ldx #6
|
||||
@@ -82,6 +84,8 @@ cint_brk: // entry for BRK and STOP+RESTORE - XXX, where should it start?
|
||||
bpl !-
|
||||
sta BufferQuantity
|
||||
|
||||
#endif
|
||||
|
||||
// Set key repeat delay (Compute's Mapping the 64 p215)
|
||||
// Making some numbers up here: Repeat every ~1/10th sec
|
||||
// But require key to be held for ~1/3sec before
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
|
||||
|
||||
keyboard_matrix:
|
||||
kb_matrix:
|
||||
|
||||
// Normal
|
||||
__kb_matrix_normal:
|
||||
.byte $14,$0D,$1D,$88,$85,$86,$87,$11
|
||||
.byte $33,$57,$41,$34,$5A,$53,$45,$00
|
||||
.byte $35,$52,$44,$36,$43,$46,$54,$58
|
||||
@@ -26,7 +26,7 @@ keyboard_matrix:
|
||||
.byte $5C,$2A,$3B,$13,$00,$3D,$5E,$2F
|
||||
.byte $31,$5F,$00,$32,$20,$00,$51,$03
|
||||
|
||||
// With SHIFT
|
||||
__kb_matrix_shift:
|
||||
.byte $94,$8D,$9D,$8C,$89,$8A,$8B,$91
|
||||
.byte $23,$77,$61,$24,$7A,$73,$65,$00
|
||||
.byte $25,$72,$64,$26,$63,$66,$74,$78
|
||||
@@ -36,7 +36,7 @@ keyboard_matrix:
|
||||
.byte $A9,$C0,$5D,$93,$00,$3D,$DE,$3F
|
||||
.byte $21,$5F,$00,$22,$A0,$00,$71,$83
|
||||
|
||||
// With VENDOR key
|
||||
__kb_matrix_vendor:
|
||||
.byte $94,$8D,$9D,$8C,$89,$8A,$8B,$91
|
||||
.byte $96,$B3,$B0,$97,$AD,$AE,$B1,$00
|
||||
.byte $98,$B2,$AC,$99,$BC,$BB,$A3,$BD
|
||||
@@ -46,7 +46,7 @@ keyboard_matrix:
|
||||
.byte $A8,$DF,$5D,$93,$00,$3D,$DE,$3F
|
||||
.byte $81,$5F,$00,$95,$a0,$00,$AB,$83
|
||||
|
||||
// With CTRL
|
||||
__kb_matrix_ctrl:
|
||||
.byte $00,$00,$00,$00,$00,$00,$00,$00
|
||||
.byte $1C,$17,$01,$9F,$1A,$13,$05,$00
|
||||
.byte $9C,$12,$04,$1E,$03,$06,$14,$18
|
||||
@@ -56,41 +56,19 @@ keyboard_matrix:
|
||||
.byte $1C,$00,$1D,$00,$00,$1F,$1E,$00
|
||||
.byte $90,$06,$00,$05,$00,$00,$11,$00
|
||||
|
||||
keyboard_matrix_lookup:
|
||||
// Work out if normal, shifted, control or Vendor modified keyboard.
|
||||
// Table contains the offsets into keyboard_matrixes that should be used
|
||||
// for different values of the bottom 3 bits of key_bucky_state XXX
|
||||
// Interaction is simple to work out when playing with a C64:
|
||||
// CTRL trumps SHIFT or VENDOR
|
||||
// VENDOR + SHIFT = DOES NOTHING
|
||||
// All 3 does CONTROL
|
||||
.byte $00 // Normal
|
||||
.byte $40 // SHIFT
|
||||
.byte $80 // CTRL
|
||||
.byte $80 // CTRL + SHIFT
|
||||
.byte $C0 // VENDOR
|
||||
.byte $C0 // VENDOR + SHIFT
|
||||
.byte $80 // VENDOR + CTRL
|
||||
.byte $80 // VENDOR + CTRL + SHIFT
|
||||
|
||||
|
||||
// keyboard_matrix_ext128: $D02F
|
||||
|
||||
// kb_matrix_ext128: $D02F
|
||||
|
||||
// .byte (HELP),$38,$35,(TAB),$32,$34,$37,$31 // $FE
|
||||
// .byte $1B, $2B, $2D,$0A,$0D,$36,$39,$33 // $FD
|
||||
// .byte $00,$30,$2E,$91,$11,$9D,$1D,(NO_SCRL) // $FB
|
||||
|
||||
// keyboard_matrix_ext65:
|
||||
// kb_matrix_ext65:
|
||||
|
||||
// Last column - normal
|
||||
// .byte (NO_SCRL),(TAB),$00,(HELP),(F9),(F11),(F13),$1B
|
||||
|
||||
// Last column - shifted
|
||||
// .byte (NO_SCRL),(TAB),$00,(HELP),(F10),(F12),(F14),$1B
|
||||
|
||||
|
||||
// XXX ESC : $1B (alias: CTRL [ )
|
||||
// XXX HELP : (to be determined, ?)
|
||||
// XXX TAB : (to be determined, $18 ?)
|
||||
// XXX NO_SCRL : (to be determined, ?)
|
||||
// XXX ALT : bucky, 128: row 3, 1st, 65: 3rd
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
//
|
||||
// Matrix for retrieving bucky key status on the C64 keyboard
|
||||
//
|
||||
// Values based on:
|
||||
// - [CM64] Compute's Mapping the Commodore 64 - pags 58 (SHFLAG), 173 (matrix)
|
||||
//
|
||||
|
||||
|
||||
#if !CONFIG_SCNKEY_TWW_CTR
|
||||
|
||||
|
||||
kb_matrix_bucky_confmask: // values to be written to CIA1_PRA
|
||||
|
||||
.byte %11111101 // SHIFT (left)
|
||||
.byte %10111111 // SHIFT (right)
|
||||
.byte %01111111 // VENDOR
|
||||
.byte %01111111 // CTRL
|
||||
|
||||
|
||||
kb_matrix_bucky_testmask: // for AND with CIA1_PRB value
|
||||
|
||||
.byte %10000000 // SHIFT (left)
|
||||
.byte %00010000 // SHIFT (right)
|
||||
.byte %00100000 // VENDOR
|
||||
.byte %00000100 // CTRL
|
||||
|
||||
|
||||
kb_matrix_bucky_shflag: // mask to be ORed to SHFLAG to mark key status
|
||||
.byte KEY_FLAG_SHIFT
|
||||
.byte KEY_FLAG_SHIFT
|
||||
.byte KEY_FLAG_VENDOR
|
||||
.byte KEY_FLAG_CTRL
|
||||
|
||||
|
||||
#endif // no CONFIG_SCNKEY_TWW_CTR
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
//
|
||||
// Matrix for filtering out bucky keys while scanning the C64 keyboard
|
||||
//
|
||||
// Values based on:
|
||||
// - [CM64] Compute's Mapping the Commodore 64 - pags 58 (SHFLAG), 173 (matrix)
|
||||
//
|
||||
|
||||
|
||||
#if !CONFIG_SCNKEY_TWW_CTR
|
||||
|
||||
|
||||
kb_matrix_bucky_filter:
|
||||
|
||||
// values for OR with CIA1_PRB content to filter out bucky keys
|
||||
|
||||
.byte %00100100 // VENDOR + CONTROL
|
||||
.byte %00010000 // SHIFT (right)
|
||||
.byte %00000000
|
||||
.byte %00000000
|
||||
.byte %00000000
|
||||
.byte %00000000
|
||||
.byte %10000000 // SHIFT (left)
|
||||
.byte %00000000
|
||||
|
||||
|
||||
#endif // no CONFIG_SCNKEY_TWW_CTR
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
//
|
||||
// Work out if normal, shifted, control or Vendor modified keyboard.
|
||||
// Table contains the offsets into keyboard_matrixes that should be used
|
||||
// for different values of the bottom 3 bits of key_bucky_state XXX
|
||||
// Interaction is simple to work out when playing with a C64:
|
||||
// CTRL trumps SHIFT or VENDOR
|
||||
// VENDOR + SHIFT = DOES NOTHING
|
||||
// All 3 does CONTROL
|
||||
//
|
||||
|
||||
kb_matrix_lookup:
|
||||
|
||||
.byte (__kb_matrix_normal - kb_matrix) // Normal
|
||||
.byte (__kb_matrix_shift - kb_matrix) // SHIFT
|
||||
.byte (__kb_matrix_ctrl - kb_matrix) // CTRL
|
||||
.byte (__kb_matrix_ctrl - kb_matrix) // CTRL + SHIFT
|
||||
.byte (__kb_matrix_vendor - kb_matrix) // VENDOR
|
||||
.byte (__kb_matrix_vendor - kb_matrix) // VENDOR + SHIFT
|
||||
.byte (__kb_matrix_ctrl - kb_matrix) // VENDOR + CTRL
|
||||
.byte (__kb_matrix_ctrl - kb_matrix) // VENDOR + CTRL + SHIFT
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
//
|
||||
// Single row key codes for scanning the C64 keyboard
|
||||
//
|
||||
// Values based on:
|
||||
// - [CM64] Compute's Mapping the Commodore 64 - pags 58 (SHFLAG), 173 (matrix)
|
||||
//
|
||||
|
||||
|
||||
#if !CONFIG_SCNKEY_TWW_CTR
|
||||
|
||||
|
||||
kb_matrix_row_keys:
|
||||
|
||||
// values for CIA1_PRA to connect only the given row
|
||||
|
||||
.byte %01111111
|
||||
.byte %10111111
|
||||
.byte %11011111
|
||||
.byte %11101111
|
||||
.byte %11110111
|
||||
.byte %11111011
|
||||
.byte %11111101
|
||||
.byte %11111110
|
||||
|
||||
|
||||
#endif // no CONFIG_SCNKEY_TWW_CTR
|
||||
@@ -30,43 +30,60 @@ SCNKEY:
|
||||
|
||||
// Handle repeat timer
|
||||
|
||||
ldx KOUNT
|
||||
beq sk_start
|
||||
lda KOUNT
|
||||
beq !+
|
||||
dec KOUNT
|
||||
|
||||
// Setup the CIA registers XXX check whether the C64 does it every time
|
||||
|
||||
ldx #$FF
|
||||
stx CIA1_DDRA // output
|
||||
ldy #$00
|
||||
sty CIA1_DDRB // input
|
||||
|
||||
!:
|
||||
// Prepare for SHFLAG update
|
||||
|
||||
lda SHFLAG
|
||||
sta LSTSHF
|
||||
ldy #$00
|
||||
sty SHFLAG
|
||||
lda #$00
|
||||
sta SHFLAG
|
||||
|
||||
// XXX retrieve ALT and NO_SCRL status for C128/C65 keyboards
|
||||
|
||||
// Check for any activity
|
||||
|
||||
sty CIA1_PRA // connect all the lines
|
||||
ldx #$FF
|
||||
cpx CIA1_PRB
|
||||
lda #$00
|
||||
sta CIA1_PRA // connect all the rows
|
||||
lda #$FF
|
||||
cmp CIA1_PRB
|
||||
beq scnkey_no_keys
|
||||
|
||||
// XXX retrieve SHIFT / CTRL / VENDOR status
|
||||
// Retrieve SHIFT / VENDOR / CTRL status
|
||||
ldy #$03
|
||||
scnkey_bucky_loop:
|
||||
lda kb_matrix_bucky_confmask, y
|
||||
sta CIA1_PRA
|
||||
lda kb_matrix_bucky_testmask, y
|
||||
and CIA1_PRB
|
||||
bne !+ // not pressed
|
||||
lda SHFLAG
|
||||
ora kb_matrix_bucky_shflag, y
|
||||
sta SHFLAG
|
||||
!:
|
||||
dey
|
||||
bpl scnkey_bucky_loop
|
||||
|
||||
// Set pointer in KEYTAB
|
||||
jsr scnkey_via_keytab
|
||||
// Set KEYTAB vector
|
||||
|
||||
jsr scnkey_via_keylog // XXX for some CPUs we have indirect jsr
|
||||
|
||||
// XXX check for joystick activity
|
||||
|
||||
// Scan the keyboard matrix
|
||||
|
||||
ldy #$07
|
||||
scnkey_matrix_loop:
|
||||
lda kb_matrix_row_keys, y
|
||||
sta CIA1_PRA
|
||||
lda kb_matrix_bucky_filter, y
|
||||
ora CIA1_PRB
|
||||
|
||||
// XXX
|
||||
dey
|
||||
bpl scnkey_matrix_loop
|
||||
|
||||
|
||||
|
||||
@@ -76,12 +93,12 @@ SCNKEY:
|
||||
|
||||
scnkey_no_keys:
|
||||
|
||||
// ldx #$FF
|
||||
stx LSTX
|
||||
lda #$FF
|
||||
sta LSTX
|
||||
|
||||
rts
|
||||
|
||||
scnkey_via_keytab:
|
||||
jmp (KEYTAB)
|
||||
scnkey_via_keylog:
|
||||
jmp (KEYLOG)
|
||||
|
||||
#endif // No CONFIG_SCNKEY_TWW_CTR
|
||||
#endif // no CONFIG_SCNKEY_TWW_CTR
|
||||
@@ -9,9 +9,9 @@ scnkey_set_keytab:
|
||||
|
||||
// Set initial KEYTAB value
|
||||
|
||||
lda #<keyboard_matrix
|
||||
lda #<kb_matrix
|
||||
sta KEYTAB+0
|
||||
lda #>keyboard_matrix
|
||||
lda #>kb_matrix
|
||||
sta KEYTAB+1
|
||||
|
||||
// Calculate table index
|
||||
@@ -21,7 +21,7 @@ scnkey_set_keytab:
|
||||
tax
|
||||
|
||||
// Retrieve table offset
|
||||
lda keyboard_matrix_lookup, x
|
||||
lda kb_matrix_lookup, x
|
||||
|
||||
// Add offset to the vector
|
||||
sec
|
||||
|
||||
@@ -57,7 +57,7 @@
|
||||
.label KeyQuantity = $A8 // 1 byte
|
||||
.label BufferNew = $A9 // 3 bytes
|
||||
.label TempZP = $B6 // 1 byte
|
||||
// These should be initialized in CINIT to $FF
|
||||
// These should be initialized in CINT to $FF
|
||||
.label BufferQuantity = $B4 // 1 byte
|
||||
.label BufferOld = $293 // 3 bytes
|
||||
.label Buffer = $297 // 4 bytes
|
||||
@@ -116,9 +116,9 @@ accept_key:
|
||||
tax
|
||||
pla
|
||||
and #$3f
|
||||
ora keyboard_matrix_lookup,x
|
||||
ora kb_matrix_lookup,x
|
||||
tax
|
||||
lda keyboard_matrix,x
|
||||
lda kb_matrix,x
|
||||
// But don't insert $00 characters
|
||||
beq sk_nokey
|
||||
|
||||
|
||||
Reference in new issue
Block a user