Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Keyboard scanning without kernal. Works but...
2008-06-17 05:25
Bastet

Registered: Jul 2005
Posts: 88
Keyboard scanning without kernal. Works but...

I have written some keyboard scanning code, but i am not that happy with it. Any suggestions?

!to "tastaohnekernal.prg",cbm

KeyboardMatrixRow           = $fc
KeyboardScanMatrixPointer   = $fe

*=$1000
sei
loop1:
jsr PrintFIFO
jsr KeyboardScan
jmp loop1

KeyboardScan:                       ;;;;;;; Prepare Scan

;;;;;;;;;;;;;;;;; DEBUG
lda #$7f
waitloop:
cmp $d012
bne waitloop

inc $d020
;;;;;;;;;;;;;;;;; DEBUG

lda #$00                            ; Check if we have a keypress after all
sta $dc00
lda $dc01
cmp #$ff
beq KeyboardScan_NoKeyPress

lda Keyboard_KeyboardUp             
bne KeyboardScanFinished            ; If the last status was no key press
                                    ; go and grab a key


lda #<KeyboardScanMatrix            ; Prepare Matrix Pointer
sta KeyboardScanMatrixPointer
lda #>KeyboardScanMatrix
sta KeyboardScanMatrixPointer+1

lda #%11111110                      ; Prepare row select
ldx #$00
stx KeyboardMatrixRow

KeyboardScanLoop:                   ;Check every row
sta $dc00               
pha                                 ;Put current row pos on stack
lda $dc01                           ;Grab that row

ldy #$ff                            ;Get the collumn
KeyboardScan_MatrixLoop1:
iny
clc
ror
bcs KeyboardScan_MatrixLoop1
cpy #$08                            ;When no key is pressed then check next row
beq KeyboardScan_NoKeyPressed
lda (KeyboardScanMatrixPointer),y
jsr Keyboard_AddToFIFO

KeyboardScan_NoKeyPressed:
pla                         ;Retrive row pos
sec                         ;ROL it
rol
pha
lda KeyboardScanMatrixPointer
clc
adc #$08
sta KeyboardScanMatrixPointer
pla
inx                         ;And check if we are finished
cpx #$08
bne KeyboardScanLoop
KeyboardScanFinished:
dec $d020
rts

KeyboardScan_NoKeyPress:
dec $d020
lda #$00
sta Keyboard_KeyboardUp
rts


Keyboard_AddToFIFO:
ldy #$01                                ;Keep that we had a keypress
sty Keyboard_KeyboardUp 
cmp #$ff
beq KeyboardScan_AddToFIFO_ShiftKey
ldy KeyboardScanFIFOWritePointer
cpy KeyboardScanFIFOReadPointer
;beq KeyboardScan_AddToFIFO_NoAdd
sta KeyboardScanFIFO,y
iny
cpy #$10
beq Keyboard_AddToFIFO_ResetPointer
sty KeyboardScanFIFOWritePointer
rts
Keyboard_AddToFIFO_ResetPointer
ldy #$00
sty KeyboardScanFIFOWritePointer
KeyboardScan_AddToFIFO_NoAdd:
KeyboardScan_AddToFIFO_ShiftKey:
rts

;;;;;;;;;;;;;;;;;;;;;; DEBUG, print current FIFO
PrintFIFO:
ldx #$00
PrintFIFO_Loop:
lda KeyboardScanFIFO,x
cpx KeyboardScanFIFOWritePointer
bne PrintFIFO_NoInvert
ora #$80
PrintFIFO_NoInvert:
sta $0400,x
inx
cpx #$10
bne PrintFIFO_Loop
lda KeyboardScanFIFOWritePointer
sta $0428
lda KeyboardScanFIFOReadPointer
sta $0429
rts




*=$3000
!convtab scr
KeyboardScanMatrix:
!byte $fb,$fc,$fd,$f7,$f1,$f3,$f5,$fe
!byte "3","w","a","4","z","s","e",$ff
!byte "5","r","d","6","c","f","t","x"
!byte "7","y","g","8","b","h","u","v"
!byte "9","i","j","0","m","k","o","n"
!byte "+","p","l","-",".",":","@",","
!byte $1c,"*",";",$53,$ff,"=",$1e,"/"
!byte "1",$1f,$58,"2"," ",$5a,"q",$57

KeyboardScanFIFOWritePointer:
!byte $00
KeyboardScanFIFOReadPointer:
!byte $0f
KeyboardScanFIFO:
!fill 16
!byte $01
Keyboard_KeyboardUp
!byte $00
2008-06-17 06:14
j0x

Registered: Mar 2004
Posts: 215
Haven't studied your code, sorry, but I want to direct your attention to Craig Bruce's article "Three-Key Rollover" in C=Hacking #6 (http://www.ffd2.com/fridge/chacking/c=hacking6.txt ).
2008-06-17 06:47
Bastet

Registered: Jul 2005
Posts: 88
Thanks, have skimmed trough it and will adapt it :)

I am playing a bit with self made kernal, nothing serious and nothing that will ever get finished, just some programming learning exercise.

Got the idea after seeing "WireOS", some toy OS for the CPU from the wire addon for the physical playground mod GMod (that is for HL2) and thought, shouldn't be that hard getting some sort of command prompt up from where someone can start programs. :)
(Call me naive and young *g*)
2008-06-17 09:39
WVL

Registered: Mar 2002
Posts: 902
So why exactly are you not happy with it? :P
2008-06-17 10:54
Bastet

Registered: Jul 2005
Posts: 88
Its ugly?
Might be my high level thinking, but that code is a mess.
2013-12-27 20:12
Rastah Bar
Account closed

Registered: Oct 2012
Posts: 336
2013-12-29 17:47
Stainless Steel

Registered: Mar 2003
Posts: 966
What color bar said.
2013-12-29 18:00
Rastah Bar
Account closed

Registered: Oct 2012
Posts: 336
;-)

No, I was not commenting on anyone, but I had some question, but found the answer elsewhere and therefore I removed the text in my post.
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
MWR/Visdom
csabanw
JackAsser/Booze Design
Flex/Artline Designs
Magic/Nah-Kolor
Guests online: 101
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Fullscreen Graphicians
1 Joe  (9.7)
2 Sulevi  (9.6)
3 The Sarge  (9.6)
4 Veto  (9.6)
5 Facet  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.042 sec.