mirror of
https://github.com/cc65/cc65.git
synced 2025-01-11 11:30:13 +00:00
Updated version by Karri Kaksonen.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3771 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
6a9a5eeafc
commit
a47adefd7b
@ -1,12 +1,13 @@
|
|||||||
;
|
;
|
||||||
; Karri Kaksonen, 2004-11-01
|
; Karri Kaksonen, Harry Dodgson 2006-01-07
|
||||||
;
|
;
|
||||||
; char cgetc (void);
|
; char cgetc (void);
|
||||||
;
|
;
|
||||||
|
|
||||||
.export _cgetc
|
.export _cgetc
|
||||||
.import _kbhit
|
.import _kbhit
|
||||||
.import KBBUF
|
.import KBEDG
|
||||||
|
.import KBSTL
|
||||||
|
|
||||||
; --------------------------------------------------------------------------
|
; --------------------------------------------------------------------------
|
||||||
; The Atari Lynx has a very small keyboard - only 3 keys
|
; The Atari Lynx has a very small keyboard - only 3 keys
|
||||||
@ -19,23 +20,51 @@
|
|||||||
; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'.
|
; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'.
|
||||||
|
|
||||||
_cgetc:
|
_cgetc:
|
||||||
|
lda KBSTL
|
||||||
|
ora KBEDG
|
||||||
|
bne @L1
|
||||||
jsr _kbhit ; Check for char available
|
jsr _kbhit ; Check for char available
|
||||||
tax ; Test result
|
tax ; Test result
|
||||||
beq _cgetc
|
bra _cgetc
|
||||||
|
@L1:
|
||||||
ldx #5 ; Wait for some time... 0.2 seconds or so.
|
|
||||||
@L1: ldy #255
|
|
||||||
@L2: lda #255
|
|
||||||
@L3: dec
|
|
||||||
bne @L3
|
|
||||||
dey
|
|
||||||
bne @L2
|
|
||||||
dex
|
|
||||||
bne @L1
|
|
||||||
|
|
||||||
jsr _kbhit ; Check for double pressed buttons
|
|
||||||
lda KBBUF
|
|
||||||
stz KBBUF
|
|
||||||
ldx #0
|
ldx #0
|
||||||
|
and #1
|
||||||
|
beq @L6
|
||||||
|
lda KBEDG ; Pause button is pressed
|
||||||
|
and #$0c
|
||||||
|
beq @L3
|
||||||
|
ora KBSTL
|
||||||
|
@L2:
|
||||||
|
bit #$04
|
||||||
|
beq @L4 ; Pause + Opt 1 = Reset
|
||||||
|
bit #$08
|
||||||
|
beq @L5 ; Pause + Opt 2 = Flip
|
||||||
|
lda #'?' ; All buttons pressed
|
||||||
|
rts
|
||||||
|
@L3:
|
||||||
|
lda KBSTL ; Pause alone was the last placed button
|
||||||
|
and #$0c
|
||||||
|
bne @L2
|
||||||
|
lda #'P' ; Pause pressed
|
||||||
|
rts
|
||||||
|
@L4:
|
||||||
|
lda #'R' ; Reset pressed
|
||||||
|
rts
|
||||||
|
@L5:
|
||||||
|
lda #'F' ; Flip pressed
|
||||||
|
rts
|
||||||
|
@L6:
|
||||||
|
lda KBEDG ; No Pause pressed
|
||||||
|
ora KBSTL
|
||||||
|
bit #$08
|
||||||
|
beq @L8
|
||||||
|
bit #$04
|
||||||
|
beq @L7
|
||||||
|
lda #'3' ; opt 1 + opt 2 pressed
|
||||||
|
rts
|
||||||
|
@L7:
|
||||||
|
lda #'1' ; opt 1 pressed
|
||||||
|
rts
|
||||||
|
@L8:
|
||||||
|
lda #'2' ; opt 2 pressed
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
;
|
;
|
||||||
; Karri Kaksonen, 2004-11-01
|
; Karri Kaksonen, Harry Dodgson 2006-01-06
|
||||||
;
|
;
|
||||||
; unsigned char kbhit (void);
|
; unsigned char kbhit (void);
|
||||||
;
|
;
|
||||||
|
|
||||||
.export _kbhit
|
.export _kbhit
|
||||||
.export KBBUF
|
.export KBEDG
|
||||||
|
.export KBSTL
|
||||||
.import return0, return1
|
.import return0, return1
|
||||||
|
|
||||||
; --------------------------------------------------------------------------
|
; --------------------------------------------------------------------------
|
||||||
@ -19,61 +20,36 @@
|
|||||||
; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'.
|
; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'.
|
||||||
|
|
||||||
.data
|
.data
|
||||||
KBBUF: .byte 0
|
KBTMP: .byte 0
|
||||||
DEBOUNCE: .byte 0 ; Contains char until key is freed
|
KBPRV: .byte 0
|
||||||
|
KBEDG: .byte 0
|
||||||
|
KBSTL: .byte 0
|
||||||
|
KBDEB: .byte 0
|
||||||
|
KBNPR: .byte 0
|
||||||
|
|
||||||
.code
|
.code
|
||||||
_kbhit:
|
_kbhit:
|
||||||
lda $FCB1 ; Read the Pause key
|
lda $FCB0 ; Read the Opt buttons
|
||||||
|
and #$0c
|
||||||
|
sta KBTMP
|
||||||
|
lda $FCB1 ; Read Pause
|
||||||
and #1
|
and #1
|
||||||
bne @L4
|
ora KBTMP ; 0000210P
|
||||||
lda $FCB0 ; No Pause pressed
|
tax
|
||||||
and #$0c
|
and KBPRV
|
||||||
bne @L1
|
sta KBSTL ; for multibutton
|
||||||
stz DEBOUNCE ; No keys pressed at all
|
txa
|
||||||
lda KBBUF ; But we may have some old key in the buffer
|
and KBDEB
|
||||||
bne @L9
|
sta KBEDG ; for just depressed
|
||||||
jmp return0 ; No key has been pressed
|
txa
|
||||||
|
and KBNPR
|
||||||
|
sta KBDEB ; for debouncing
|
||||||
|
txa
|
||||||
|
eor #$ff
|
||||||
|
sta KBNPR ; inverted previous ones pressed
|
||||||
|
stx KBPRV
|
||||||
|
lda KBEDG
|
||||||
|
beq @L1
|
||||||
|
jmp return1 ; Key hit
|
||||||
@L1:
|
@L1:
|
||||||
cmp #$0c
|
jmp return0 ; No new keys hit
|
||||||
bne @L2
|
|
||||||
ldx #'3' ; Opt 1 + Opt 2 pressed
|
|
||||||
bra @L8
|
|
||||||
@L2:
|
|
||||||
cmp #$08
|
|
||||||
bne @L3
|
|
||||||
ldx #'1' ; Opt 1 pressed
|
|
||||||
bra @L8
|
|
||||||
@L3:
|
|
||||||
ldx #'2' ; Opt 2 pressed
|
|
||||||
bra @L8
|
|
||||||
@L4:
|
|
||||||
lda $FCB0
|
|
||||||
and #$0c
|
|
||||||
bne @L5
|
|
||||||
ldx #'P' ; Pause pressed
|
|
||||||
bra @L8
|
|
||||||
@L5:
|
|
||||||
cmp #$0c
|
|
||||||
bne @L6
|
|
||||||
ldx #'?' ; Opt 1 + Opt 2 + Pause pressed
|
|
||||||
bra @L8
|
|
||||||
@L6:
|
|
||||||
cmp #$08
|
|
||||||
bne @L7
|
|
||||||
ldx #'R' ; Restart pressed
|
|
||||||
bra @L8
|
|
||||||
@L7:
|
|
||||||
ldx #'F' ; Flip pressed
|
|
||||||
@L8:
|
|
||||||
lda KBBUF
|
|
||||||
bne @L10
|
|
||||||
lda DEBOUNCE
|
|
||||||
beq @L10
|
|
||||||
jmp return0 ; Return no key pressed until keys are released
|
|
||||||
@L10:
|
|
||||||
stx KBBUF
|
|
||||||
sta DEBOUNCE
|
|
||||||
@L9: jmp return1
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user