This commit is contained in:
stid 2019-11-16 14:09:22 -08:00
parent fad701289f
commit 6013ca5d87
10 changed files with 312 additions and 606 deletions

2
arch/keyb.asm Executable file → Normal file
View File

@ -456,7 +456,7 @@ TempY:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
.pc = * "Keyboard Scan Routine"
* = * "Keyboard Scan Routine"
// ZERO PAGE Varibles

2
arch/precursor.asm Executable file → Normal file
View File

@ -510,7 +510,7 @@ cursorY:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
.pc = * "Keyboard Scan Routine"
* = * "Keyboard Scan Routine"
// ZERO PAGE Varibles

View File

@ -2,7 +2,7 @@
#import "mem_map.asm"
.filenamespace Hex
.pc = * "Hex Routines"
* = * "Hex Routines"
//

415
keyb.asm
View File

@ -1,415 +0,0 @@
#importonce
#import "mem_map.asm"
.filenamespace Keyboard
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Keyboard IO Routine
~~~~~~~~~~~~~~~~~~~
By: TWW/CTR
Preparatory Settings
~~~~~~~~~~~~~~~~~~~~
None
Destroys
~~~~~~~~
Accumulator
X-Register
Y-Register
Carry / Zero / Negative
$dc00
$dc01
$50-$5f
Footprint
~~~~~~~~~
#$206 Bytes
Information
~~~~~~~~~~~
The routine uses "2 Key rollower" or up to 3 if the key-combination doesen't induce shadowing.
If 2 or 3 keys are pressed simultaneously (within 1 scan) a "No Activity" state has to occur before new valid keys are returned.
RESTORE is not detectable and must be handled by NMI IRQ.
SHIFT LOCK is not detected due to unreliability.
Usage
~~~~~
Example Code:
jsr Keyboard
bcs NoValidInput
stx TempX
sty TempY
cmp #$ff
beq NoNewAphanumericKey
// Check A for Alphanumeric keys
sta $0400
NoNewAphanumericKey:
// Check X & Y for Non-Alphanumeric Keys
ldx TempX
ldy TempY
stx $0401
sty $0402
NoValidInput: // This may be substituted for an errorhandler if needed.
Returned
~~~~~~~~
+=================================================+
| Returned in Accumulator |
+===========+===========+=============+===========+
| $00 - @ | $10 - p | $20 - SPC | $30 - 0 |
| $01 - a | $11 - q | $21 - | $31 - 1 |
| $02 - b | $12 - r | $22 - | $32 - 2 |
| $03 - c | $13 - s | $23 - | $33 - 3 |
| $04 - d | $14 - t | $24 - | $34 - 4 |
| $05 - e | $15 - u | $25 - | $35 - 5 |
| $06 - f | $16 - v | $26 - | $36 - 6 |
| $07 - g | $17 - w | $27 - | $37 - 7 |
| $08 - h | $18 - x | $28 - | $38 - 8 |
| $09 - i | $19 - y | $29 - | $39 - 9 |
| $0a - j | $1a - z | $2a - * | $3a - : |
| $0b - k | $1b - | $2b - + | $3b - ; |
| $0c - l | $1c - £ | $2c - , | $3c - |
| $0d - m | $1d - | $2d - - | $3d - = |
| $0e - n | $1e - ^ | $2e - . | $3e - |
| $0f - o | $1f - <- | $2f - / | $3f - |
+-----------+-----------+-------------+-----------+
+================================================================================
| Return in X-Register |
+=========+=========+=========+=========+=========+=========+=========+=========+
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
+---------+---------+---------+---------+---------+---------+---------+---------+
| CRSR UD | F5 | F3 | F1 | F7 | CRSR RL | RETURN |INST/DEL |
+---------+---------+---------+---------+---------+---------+---------+---------+
+================================================================================
| Return in Y-Register |
+=========+=========+=========+=========+=========+=========+=========+=========+
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
+---------+---------+---------+---------+---------+---------+---------+---------+
|RUN STOP | L-SHIFT | C= | R-SHIFT |CLR/HOME | CTRL | | |
+---------+---------+---------+---------+---------+---------+---------+---------+
CARRY:
- Set = Error Condition (Check A for code):
A = #$01 => No keyboard activity is detected.
A = #$02 => Control Port #1 Activity is detected.
A = #$03 => Key Shadowing / Ghosting is detected.
A = #$04 => 2 or 3 new keys is detected within one scan
A = #$05 => Awaiting "No Activity" state
- Clear = Valid input
A = #$ff => No new Alphanumeric Keys detected (some key(s) being held down AND/OR some Non-Alphanumeric key is causing valid return).
A <> #$ff => New Alphanumeric Key returned. Non-Alphanumeric keys may also be returned in X or Y Register
Issues/ToDo:
~~~~~~~~~~~~
- None
Improvements:
~~~~~~~~~~~~~
- Replace the subroutine with a pseudocommand and account for speedcode parameter (Memory vs. Cycles).
- Shorten the routine / Optimize if possible.
History:
~~~~~~~~
V2.5 - New test tool.
Added return of error codes.
Fixed a bug causing Buffer Overflow.
Fixed a bug in Non Alphanumerical Flags from 2.0.
V2.1 - Shortened the source by adding .for loops & Updated the header and some comments.
Added "simultaneous keypress" check.
V2.0 - Added return of non-Alphanumeric keys into X & Y-Registers.
Small optimizations here and there.
V1.1 - Unrolled code to make it faster and optimized other parts of it.
Removed SHIFT LOCK scanning.
V1.0 - First Working Version along with test tool.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
.pc = * "Keyboard Scan Routine"
// Operational Variables
.var MaxKeyRollover = 3
start:
jmp Main
init:
lda #$ff
sta MemMap.KEYB_SPACE.BufferOld
sta MemMap.KEYB_SPACE.Buffer
sta MemMap.KEYB_SPACE.Buffer+1
sta MemMap.KEYB_SPACE.Buffer+2
sta MemMap.KEYB_SPACE.Buffer+3
sta MemMap.KEYB_SPACE.BufferQuantity
lda #$00
sta MemMap.KEYB_SPACE.SimultaneousAlphanumericKeysFlag
rts
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Routine for Scanning a Matrix Row
KeyInRow:
asl
bcs.r *+5
jsr KeyFound
.for (var i = 0 ; i < 7 ; i++) {
inx
asl
bcs.r *+5
jsr KeyFound
}
rts
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Routine for handling: Key Found
KeyFound:
stx MemMap.KEYB_SPACE.TempZP
dec MemMap.KEYB_SPACE.KeyQuantity
bmi.r OverFlow
ldy KeyTable,x
ldx MemMap.KEYB_SPACE.KeyQuantity
sty MemMap.KEYB_SPACE.BufferNew,x
ldx MemMap.KEYB_SPACE.TempZP
rts
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Routine for handling: Overflow
OverFlow:
pla // Dirty hack to handle 2 layers of JSR
pla
pla
pla
// Don't manipulate last legal buffer as the routine will fix itself once it gets valid input again.
lda #$03
sec
rts
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Exit Routine for: No Activity
NoActivityDetected:
// Exit With A = #$01, Carry Set & Reset MemMap.KEYB_SPACE.BufferOld.
lda #$00
sta MemMap.KEYB_SPACE.SimultaneousAlphanumericKeysFlag // Clear the too many keys flag once a "no activity" state is detected.
stx MemMap.KEYB_SPACE.BufferOld
stx MemMap.KEYB_SPACE.BufferOld+1
stx MemMap.KEYB_SPACE.BufferOld+2
sec
lda #$01
rts
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Exit Routine for Control Port Activity
ControlPort:
// Exit with A = #$02, Carry Set. Keep MemMap.KEYB_SPACE.BufferOld to verify input after Control Port activity ceases
sec
lda #$02
rts
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Configure Data Direction Registers
Main:
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
beq.r NoActivityDetected
lda MemMap.KEYB_SPACE.SimultaneousAlphanumericKeysFlag
beq.r !+
// Waiting for all keys to be released before accepting new input.
lda #$05
sec
rts
!:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Check for Control Port #1 Activity
stx $dc00 // Disconnect all Keyboard Rows
cpx $dc01 // Only Control Port activity will be detected
bne ControlPort
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Scan Keyboard Matrix
lda #%11111110
sta $dc00
ldy $dc01
sty MemMap.KEYB_SPACE.ScanResult+7
sec
.for (var i = 6 ; i > -1 ; i--) {
rol
sta $dc00
ldy $dc01
sty MemMap.KEYB_SPACE.ScanResult+i
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Check for Control Port #1 Activity (again)
stx $dc00 // Disconnect all Keyboard Rows
cpx $dc01 // Only Control Port activity will be detected
bne.r ControlPort
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Initialize Buffer, Flags and Max Keys
// Reset current read buffer
stx MemMap.KEYB_SPACE.BufferNew
stx MemMap.KEYB_SPACE.BufferNew+1
stx MemMap.KEYB_SPACE.BufferNew+2
// Reset Non-AlphaNumeric Flag
inx
stx MemMap.KEYB_SPACE.NonAlphaFlagY
// Set max keys allowed before ignoring result
lda #MaxKeyRollover
sta MemMap.KEYB_SPACE.KeyQuantity
// Counter to check for simultaneous alphanumeric key-presses
lda #$fe
sta MemMap.KEYB_SPACE.SimultaneousKeys
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Check and flag Non Alphanumeric Keys
lda MemMap.KEYB_SPACE.ScanResult+6
eor #$ff
and #%10000000 // Left Shift
lsr
sta MemMap.KEYB_SPACE.NonAlphaFlagY
lda MemMap.KEYB_SPACE.ScanResult+0
eor #$ff
and #%10100100 // RUN STOP - C= - CTRL
ora MemMap.KEYB_SPACE.NonAlphaFlagY
sta MemMap.KEYB_SPACE.NonAlphaFlagY
lda MemMap.KEYB_SPACE.ScanResult+1
eor #$ff
and #%00011000 // Right SHIFT - CLR HOME
ora MemMap.KEYB_SPACE.NonAlphaFlagY
sta MemMap.KEYB_SPACE.NonAlphaFlagY
lda MemMap.KEYB_SPACE.ScanResult+7 // The rest
eor #$ff
sta MemMap.KEYB_SPACE.NonAlphaFlagX
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Check for pressed key(s)
lda MemMap.KEYB_SPACE.ScanResult+7
cmp #$ff
beq *+5
jsr KeyInRow
.for (var i = 6 ; i > -1 ; i--) {
ldx #[7-i]*8
lda MemMap.KEYB_SPACE.ScanResult+i
beq *+5
jsr KeyInRow
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Key Scan Completed
// Put any new key (not in old scan) into buffer
ldx #MaxKeyRollover-1
!: lda MemMap.KEYB_SPACE.BufferNew,x
cmp #$ff
beq Exist // Handle 'null' values
cmp MemMap.KEYB_SPACE.BufferOld
beq Exist
cmp MemMap.KEYB_SPACE.BufferOld+1
beq Exist
cmp MemMap.KEYB_SPACE.BufferOld+2
beq Exist
// New Key Detected
inc MemMap.KEYB_SPACE.BufferQuantity
ldy MemMap.KEYB_SPACE.BufferQuantity
sta MemMap.KEYB_SPACE.Buffer,y
// Keep track of how many new Alphanumeric keys are detected
inc MemMap.KEYB_SPACE.SimultaneousKeys
beq TooManyNewKeys
Exist:
dex
bpl !-
// Anything in Buffer?
ldy MemMap.KEYB_SPACE.BufferQuantity
bmi BufferEmpty
// Yes: Then return it and tidy up the buffer
dec MemMap.KEYB_SPACE.BufferQuantity
lda MemMap.KEYB_SPACE.Buffer
ldx MemMap.KEYB_SPACE.Buffer+1
stx MemMap.KEYB_SPACE.Buffer
ldx MemMap.KEYB_SPACE.Buffer+2
stx MemMap.KEYB_SPACE.Buffer+1
jmp Return
BufferEmpty: // No new Alphanumeric keys to handle.
lda #$ff
Return: // A is preset
clc
// Copy MemMap.KEYB_SPACE.BufferNew to MemMap.KEYB_SPACE.BufferOld
ldx MemMap.KEYB_SPACE.BufferNew
stx MemMap.KEYB_SPACE.BufferOld
ldx MemMap.KEYB_SPACE.BufferNew+1
stx MemMap.KEYB_SPACE.BufferOld+1
ldx MemMap.KEYB_SPACE.BufferNew+2
stx MemMap.KEYB_SPACE.BufferOld+2
// Handle Non Alphanumeric Keys
ldx MemMap.KEYB_SPACE.NonAlphaFlagX
ldy MemMap.KEYB_SPACE.NonAlphaFlagY
rts
TooManyNewKeys:
sec
lda #$ff
sta MemMap.KEYB_SPACE.BufferQuantity
sta MemMap.KEYB_SPACE.SimultaneousAlphanumericKeysFlag
lda #$04
rts
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
KeyTable:
.byte $ff, $ff, $ff, $ff, $ff, $ff, $ff, $ff // CRSR DOWN, F5, F3, F1, F7, CRSR RIGHT, RETURN, INST DEL
.byte $ff, $05, $13, $1a, $34, $01, $17, $33 // LEFT SHIFT, "E", "S", "Z", "4", "A", "W", "3"
.byte $18, $14, $06, $03, $36, $04, $12, $35 // "X", "T", "F", "C", "6", "D", "R", "5"
.byte $16, $15, $08, $02, $38, $07, $19, $37 // "V", "U", "H", "B", "8", "G", "Y", "7"
.byte $0e, $0f, $0b, $0d, $30, $0a, $09, $39 // "N", "O" (Oscar), "K", "M", "0" (Zero), "J", "I", "9"
.byte $2c, $00, $3a, $2e, $2d, $0c, $10, $2b // ",", "@", ":", ".", "-", "L", "P", "+"
.byte $2f, $1e, $3d, $ff, $ff, $3b, $2a, $1c // "/", "^", "=", RIGHT SHIFT, HOME, ";", "*", "£"
.byte $ff, $11, $ff, $20, $32, $ff, $1f, $31 // RUN STOP, "Q", "C=" (CMD), " " (SPC), "2", "CTRL", "<-", "1"

309
keyb2.asm
View File

@ -2,6 +2,53 @@
#importonce
.filenamespace Keyboard2
#import "mem_map.asm"
#import "memory.asm"
.const CIA1_KeybWrite = $DC00
.const CIA1_KeybRead = $DC01
.const cSYS_DelayValue = 32
.const cKeybW_Row1 = $FE
init:
lda #64
sta MemMap.KEYB2_SPACE.SYS_Lstx
sta MemMap.KEYB2_SPACE.SYS_Sfdx
lda #cSYS_DelayValue
sta MemMap.KEYB2_SPACE.SYS_Delay
lda #6
sta MemMap.KEYB2_SPACE.SYS_Kount
lda #0
sta MemMap.KEYB2_SPACE.SYS_Shflag
sta MemMap.KEYB2_SPACE.SYS_Lstshf
sta MemMap.KEYB2_SPACE.SYS_Ndx
lda #10
sta MemMap.KEYB2_SPACE.SYS_Xmax
// CLODE TO RAM
lda #<cloneStart
sta MemMap.MEMORY_SPACE.from
lda #>cloneStart
sta MemMap.MEMORY_SPACE.from+1
lda #<$1000
sta MemMap.MEMORY_SPACE.to
lda #>$1000
sta MemMap.MEMORY_SPACE.to+1
lda #<cloneEnd-ReadKeyb
sta MemMap.MEMORY_SPACE.size+1
lda #>cloneEnd-ReadKeyb
sta MemMap.MEMORY_SPACE.size
jsr Memory.clone
rts
KeyMapVec:
.word KeyMap1, KeyMap2, KeyMap3, KeyMap4
@ -54,184 +101,166 @@ KeyMap4:
.byte $90, $06, $FF, $05, $FF, $FF, $11, $FF
.byte $FF
.const CIA1_KeybWrite = $DC00
.const CIA1_KeybRead = $DC01
* = * "Keyb Start"
.const cSYS_DelayValue = 32
.const cKeybW_Row1 = $FE
init:
lda #64
sta MemMap.KEYB2_SPACE.SYS_Lstx
sta MemMap.KEYB2_SPACE.SYS_Sfdx
lda #cSYS_DelayValue
sta MemMap.KEYB2_SPACE.SYS_Delay
lda #6
sta MemMap.KEYB2_SPACE.SYS_Kount
lda #0
sta MemMap.KEYB2_SPACE.SYS_Shflag
sta MemMap.KEYB2_SPACE.SYS_Lstshf
sta MemMap.KEYB2_SPACE.SYS_Ndx
lda #10
sta MemMap.KEYB2_SPACE.SYS_Xmax
rts
cloneStart:
.pseudopc $1000 {
ReadKeyb:
lda #<KeyMap1
sta @SMC_Vec + 1
lda #>KeyMap1
sta @SMC_Vec + 2
lda #<KeyMap1
sta @SMC_Vec
lda #>KeyMap1
sta @SMC_Vec + 1
// Clear Shift Flag
lda #$40
sta MemMap.KEYB2_SPACE.SYS_Sfdx
// Clear Shift Flag
lda #$40
sta MemMap.KEYB2_SPACE.SYS_Sfdx
lda #0
sta MemMap.KEYB2_SPACE.SYS_Shflag
lda #0
sta MemMap.KEYB2_SPACE.SYS_Shflag
sta CIA1_KeybWrite
ldx CIA1_KeybRead
cpx #$FF
beq @Cleanup
sta CIA1_KeybWrite
ldx CIA1_KeybRead
cpx #$FF
beq @Cleanup
ldy #$00
ldy #$00
lda #7
sta MemMap.KEYB2_SPACE.KeyR
lda #7
sta MemMap.KEYB2_SPACE.KeyR
lda #cKeybW_Row1
sta @SMC_Row + 1
@SMC_Row: lda #0
lda #cKeybW_Row1
sta @SMC_Row + 1
@SMC_Row: lda #0
sta CIA1_KeybWrite
sta CIA1_KeybWrite
@Loop_Debounce:
lda CIA1_KeybRead
cmp CIA1_KeybRead
bne @Loop_Debounce
lda CIA1_KeybRead
cmp CIA1_KeybRead
bne @Loop_Debounce
ldx #7
@Loop_Col: lsr
bcs @NextKey
sta @SMC_A + 1
ldx #7
@Loop_Col: lsr
bcs @NextKey
sta @SMC_A + 1
@SMC_Vec: lda $FFFF,Y
lda @SMC_Vec:$FFFF,Y
// If <4 then is Stop or a Shift Key
cmp #$05
bcs @NotShift // Not Shift
// If <4 then is Stop or a Shift Key
cmp #$05
bcs @NotShift // Not Shift
cmp #$03
beq @NotShift // Stop Key
cmp #$03
beq @NotShift // Stop Key
// Accumulate shift key types (SHIFT=1, COMM=2, CTRL=4)
ora MemMap.KEYB2_SPACE.SYS_Shflag
sta MemMap.KEYB2_SPACE.SYS_Shflag
bpl @SMC_A
// Accumulate shift key types (SHIFT=1, COMM=2, CTRL=4)
ora MemMap.KEYB2_SPACE.SYS_Shflag
sta MemMap.KEYB2_SPACE.SYS_Shflag
bpl @SMC_A
@NotShift: sty MemMap.KEYB2_SPACE.SYS_Sfdx
@NotShift: sty MemMap.KEYB2_SPACE.SYS_Sfdx
@SMC_A: lda #0
@SMC_A: lda #0
@NextKey: iny
dex
bpl @Loop_Col
@NextKey: iny
dex
bpl @Loop_Col
sec
rol @SMC_Row + 1
dec MemMap.KEYB2_SPACE.KeyR
bpl @SMC_Row
sec
rol @SMC_Row + 1
dec MemMap.KEYB2_SPACE.KeyR
bpl @SMC_Row
jmp @ProcKeyImg
jmp @ProcKeyImg
// Handles the key repeat
@Process: ldy MemMap.KEYB2_SPACE.SYS_Sfdx
@SMC_Key: lda $FFFF,Y
tax
cpy MemMap.KEYB_SPACE.KeyQuantity.SYS_Lstx
beq @SameKey
@Process: ldy MemMap.KEYB2_SPACE.SYS_Sfdx
@SMC_Key: lda $FFFF,Y
tax
cpy MemMap.KEYB2_SPACE.SYS_Lstx
beq @SameKey
ldy #cSYS_DelayValue
sty MemMap.KEYB2_SPACE.SYS_Delay // Repeat delay counter
bne @Cleanup
ldy #cSYS_DelayValue
sty MemMap.KEYB2_SPACE.SYS_Delay // Repeat delay counter
bne @Cleanup
@SameKey: and #$7F
ldy MemMap.KEYB2_SPACE.SYS_Delay
beq @EndDelay
dec MemMap.KEYB2_SPACE.SYS_Delay
bne @Exit
@SameKey: and #$7F
ldy MemMap.KEYB2_SPACE.SYS_Delay
beq @EndDelay
dec MemMap.KEYB2_SPACE.SYS_Delay
bne @Exit
@EndDelay: dec MemMap.KEYB2_SPACE.SYS_Kount
bne @Exit
@EndDelay: dec MemMap.KEYB2_SPACE.SYS_Kount
bne @Exit
ldy #$04
sty MemMap.KEYB2_SPACE.SYS_Kount
ldy MemMap.KEYB2_SPACE.SYS_Ndx
dey
bpl @Exit
ldy #$04
sty MemMap.KEYB2_SPACE.SYS_Kount
ldy MemMap.KEYB2_SPACE.SYS_Ndx
dey
bpl @Exit
// Updates the previous key and shift storage
@Cleanup: ldy MemMap.KEYB2_SPACE.SYS_Sfdx
sty MemMap.KEYB_SPACE.KeyQuantity.SYS_Lstx
ldy MemMap.KEYB2_SPACE.SYS_Shflag
sty MemMap.KEYB2_SPACE.SYS_Lstshf
@Cleanup: ldy MemMap.KEYB2_SPACE.SYS_Sfdx
sty MemMap.KEYB2_SPACE.SYS_Lstx
ldy MemMap.KEYB2_SPACE.SYS_Shflag
sty MemMap.KEYB2_SPACE.SYS_Lstshf
cpx #$FF
beq @Exit
txa
ldx MemMap.KEYB2_SPACE.SYS_Ndx
cpx MemMap.KEYB2_SPACE.SYS_Xmax
bcs @Exit
cpx #$FF
beq @Exit
txa
ldx MemMap.KEYB2_SPACE.SYS_Ndx
cpx MemMap.KEYB2_SPACE.SYS_Xmax
bcs @Exit
sta MemMap.KEYB2_SPACE.SYS_Keyd,X
inx
stx MemMap.KEYB2_SPACE.SYS_Ndx
sta MemMap.KEYB2_SPACE.SYS_Keyd,X
inx
stx MemMap.KEYB2_SPACE.SYS_Ndx
@Exit: lda #$7F
sta CIA1_KeybWrite
rts
@Exit: lda #$7F
sta CIA1_KeybWrite
rts
@ProcKeyImg:
lda MemMap.KEYB2_SPACE.SYS_Shflag
cmp #$03 // C= + SHIFT
bne @SetDecodeTable
cmp MemMap.KEYB2_SPACE.SYS_Lstshf
beq @Exit
lda MemMap.KEYB2_SPACE.SYS_Shflag
cmp #$03 // C= + SHIFT
bne @SetDecodeTable
cmp MemMap.KEYB2_SPACE.SYS_Lstshf
beq @Exit
@SetDecodeTable:
asl
cmp #8 // CONTROL
bcc @Cont
lda #$06
@Cont: tax
lda KeyMapVec,X
sta @SMC_Key + 1
lda KeyMapVec + 1,X
sta @SMC_Key + 2
jmp @Process
asl
cmp #8 // CONTROL
bcc @Cont
lda #$06
@Cont: tax
lda KeyMapVec,X
sta @SMC_Key + 1
lda KeyMapVec + 1,X
sta @SMC_Key + 2
jmp @Process
// --------------------------
GetKey: lda MemMap.KEYB2_SPACE.SYS_Ndx
bne @IsKey
GetKey: lda MemMap.KEYB2_SPACE.SYS_Ndx
bne @IsKey
@NoKey: lda #255 // Null
sec
rts
@NoKey: lda #255 // Null
sec
rts
@IsKey: ldy MemMap.KEYB2_SPACE.SYS_Keyd
ldx #0
@Loop: lda MemMap.KEYB2_SPACE.SYS_Keyd + 1,X
sta MemMap.KEYB2_SPACE.SYS_Keyd,X
inx
cpx MemMap.KEYB2_SPACE.SYS_Ndx
bne @Loop
dec MemMap.KEYB2_SPACE.SYS_Ndx
tya
clc
rts
@IsKey: ldy MemMap.KEYB2_SPACE.SYS_Keyd
ldx #0
@Loop: lda MemMap.KEYB2_SPACE.SYS_Keyd + 1,X
sta MemMap.KEYB2_SPACE.SYS_Keyd,X
inx
cpx MemMap.KEYB2_SPACE.SYS_Ndx
bne @Loop
dec MemMap.KEYB2_SPACE.SYS_Ndx
tya
clc
rts
cloneEnd:
}

View File

@ -1,4 +1,4 @@
//BasicUpstart2(start)
BasicUpstart2(start)
* = $8000 "Main"
@ -15,11 +15,11 @@
#import "screen.asm"
#import "keyb.asm"
#import "keyb2.asm"
#import "hex.asm"
.pc = * "Kernel Start"
* = * "Kernel Start"
coldstart:
ldx #$FF
@ -36,28 +36,26 @@ start:
jsr initApp;
print(testString)
getKeyb:
jsr Keyboard.start
bcs NoValidInput
stx MemMap.KEYB_SPACE.TempX
sty MemMap.KEYB_SPACE.TempY
cmp #$ff
// Check A for Alphanumeric keys
beq NoNewAphanumericKey
jsr printKey
jmp getKeyb
loop:
lda #$FF
Raster: cmp $D012
bne Raster
jsr Keyboard2.ReadKeyb
jsr Keyboard2.GetKey
bcs Skip
.break
jsr Screen.petToScreen
//jsr Hex.byteToHex
//cPrint()
//txa
printKey:
cPrint()
rts
NoNewAphanumericKey:
// Check X & Y for Non-Alphanumeric Keys
ldx MemMap.KEYB_SPACE.TempX
ldy MemMap.KEYB_SPACE.TempY
NoValidInput: // This may be substituted for an errorhandler if needed.
jmp getKeyb
Skip: jmp loop
initApp: {
@ -66,16 +64,17 @@ initApp: {
SetBorderColor(constants.MAIN_COLOR)
SetBackgroundColor(constants.BORDER_COLOR)
jsr Screen.init
jsr Keyboard.init
jsr Keyboard2.init
rts
}
.pc = * "Kernel Data"
* = * "Kernel Data"
.encoding "screencode_mixed"
testString:
.text "=stid= os - v 0.1.1a"
.byte $ff
.byte $8e
.byte 0

View File

@ -3,7 +3,7 @@
#import "mem_map.asm"
.pc = * "Math Routines"
* = * "Math Routines"
multiply: {
stx MemMap.MATH_SPACE.multiTmpX

View File

@ -20,29 +20,10 @@
.label result = ZPAGE_BASE+11 // 2 bytes
}
.namespace KEYB_SPACE {
.label ScanResult = ZPAGE_BASE+13 // 8 bytes
.label BufferNew = ZPAGE_BASE+21 // 3 bytes
.label KeyQuantity = ZPAGE_BASE+24 // 1 byte
.label NonAlphaFlagX = ZPAGE_BASE+25 // 1 byte
.label NonAlphaFlagY = ZPAGE_BASE+26 // 1 byte
.label TempZP = ZPAGE_BASE+27 // 1 byte
.label SimultaneousKeys = ZPAGE_BASE+28 // 1 byte
// TODO: Need $FF init
.label BufferOld = ZPAGE_BASE+28 // 1 byte
.label Buffer = ZPAGE_BASE+29 // 4 byte
.label BufferQuantity = ZPAGE_BASE+33 // 1 byte
.label SimultaneousAlphanumericKeysFlag = ZPAGE_BASE+34 // 1 byte
.label TempX = ZPAGE_BASE+35 // 1 byte
.label TempY = ZPAGE_BASE+36 // 1 byte
}
.namespace KEYB2_SPACE {
.label KeyR = ZPAGE_BASE+37
.label KeyR = ZPAGE_BASE+37 // 1 bytes
.label SYS_Keyd = ZPAGE_BASE+38 // 10 bytes
.label SYS_Ndx = ZPAGE_BASE+48 // 10 bytes
.label SYS_Ndx = ZPAGE_BASE+48 // 1 bytes
.label SYS_Xmax = ZPAGE_BASE+49 // 1 bytes
.label SYS_Shflag = ZPAGE_BASE+50 // 1 bytes
.label SYS_Sfdx = ZPAGE_BASE+51 // 1 bytes
@ -50,4 +31,10 @@
.label SYS_Delay = ZPAGE_BASE+53 // 1 bytes
.label SYS_Kount = ZPAGE_BASE+54 // 1 bytes
.label SYS_Lstshf = ZPAGE_BASE+55 // 1 bytes
}
.namespace MEMORY_SPACE {
.label from = ZPAGE_BASE+56 // 2 bytes
.label to = ZPAGE_BASE+58 // 2 bytes
.label size = ZPAGE_BASE+60 // 2 bytes
}

33
memory.asm Normal file
View File

@ -0,0 +1,33 @@
#importonce
.filenamespace Memory
#import "mem_map.asm"
* = * "Memory Routines"
// move memory down
//
// from = source start address
// to = destination start address
// size = number of bytes to move
//
clone:
ldy #0
ldx MemMap.MEMORY_SPACE.size
beq md2
md1: lda (MemMap.MEMORY_SPACE.from),y // move a page at a time
sta (MemMap.MEMORY_SPACE.to),y
iny
bne md1
inc MemMap.MEMORY_SPACE.from+1
inc MemMap.MEMORY_SPACE.to+1
dex
bne md1
md2: ldx MemMap.MEMORY_SPACE.size+1
beq md4
md3: lda (MemMap.MEMORY_SPACE.from),y // move the remaining bytes
sta (MemMap.MEMORY_SPACE.to),y
iny
dex
bne md3
md4: rts

View File

@ -6,7 +6,7 @@
// MACROS
// -----------------------
.pc = * "Screen Routines"
* = * "Screen Routines"
.macro print(stringAddr) {
lda #<stringAddr // Low byte
@ -102,7 +102,7 @@ init: {
printChar: {
stx MemMap.SCREEN_SPACE.tempX
// New Line
cmp #$ff
cmp #$8e
bne.r !+
jsr screenNewLine
iny
@ -186,3 +186,76 @@ screenNewLine: {
rts
}
//
// petToScreen
//
//
// preparatory ops: .a: pet byte to convert
//
// returned values: .a: conv SCREEN char
//
petToScreen: {
// $00-$1F
cmp #$1f
bcs !+
sec
adc #128
jmp convDone
// $20-$3F
!:
cmp #$3f
bcs !+
jmp convDone
// $40-$5F
!:
cmp #$5f
bcs !+
sec
sbc #$40
jmp convDone
// $60-$7F
!:
cmp #$7F
bcs !+
sec
sbc #32
jmp convDone
// $80-$9F
!:
cmp #$9F
bcs !+
sec
adc #64
jmp convDone
// $A0-$BF
!:
cmp #$BF
bcs !+
sec
sbc #64
jmp convDone
// $C0-$DF
// $E0-$FE
!:
cmp #$FE
bcs !+
sec
sbc #128
jmp convDone
// $FF
!:
lda $5E
convDone:
rts
}