mirror of
https://github.com/cc65/cc65.git
synced 2024-11-18 15:05:14 +00:00
New kbhit and cgetc functions from Karri
git-svn-id: svn://svn.cc65.org/cc65/trunk@3295 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
4db225ae4a
commit
14e40851e9
@ -45,12 +45,14 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
|
||||
#--------------------------------------------------------------------------
|
||||
# Object files
|
||||
|
||||
OBJS = crt0.o \
|
||||
OBJS = cgetc.o \
|
||||
crt0.o \
|
||||
ctype.o \
|
||||
eeprom.o \
|
||||
extzp.o \
|
||||
framerate.o \
|
||||
getenv.o \
|
||||
kbhit.o \
|
||||
mainargs.o \
|
||||
sysuname.o \
|
||||
upload.o
|
||||
|
41
libsrc/lynx/cgetc.s
Normal file
41
libsrc/lynx/cgetc.s
Normal file
@ -0,0 +1,41 @@
|
||||
;
|
||||
; Karri Kaksonen, 2004-11-01
|
||||
;
|
||||
; char cgetc (void);
|
||||
;
|
||||
|
||||
.export _cgetc
|
||||
.import _kbhit
|
||||
.import KBBUF
|
||||
|
||||
; --------------------------------------------------------------------------
|
||||
; The Atari Lynx has a very small keyboard - only 3 keys
|
||||
; Opt1, Opt2 and Pause.
|
||||
; But the designers have decided that pressing Pause and Opt1 at the
|
||||
; same time means Restart and pressing Pause and Opt2 means Flip screen.
|
||||
|
||||
; For "easter egg" use I have also included all three keys pressed '?'
|
||||
; and Opt1 + Opt2 pressed '3'.
|
||||
; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'.
|
||||
|
||||
_cgetc:
|
||||
jsr _kbhit ; Check for char available
|
||||
tax ; Test result
|
||||
beq _cgetc
|
||||
|
||||
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
|
||||
rts
|
||||
|
79
libsrc/lynx/kbhit.s
Normal file
79
libsrc/lynx/kbhit.s
Normal file
@ -0,0 +1,79 @@
|
||||
;
|
||||
; Karri Kaksonen, 2004-11-01
|
||||
;
|
||||
; unsigned char kbhit (void);
|
||||
;
|
||||
|
||||
.export _kbhit
|
||||
.export KBBUF
|
||||
.import return0, return1
|
||||
|
||||
; --------------------------------------------------------------------------
|
||||
; The Atari Lynx has a very small keyboard - only 3 keys
|
||||
; Opt1, Opt2 and Pause.
|
||||
; But the designers have decided that pressing Pause and Opt1 at the
|
||||
; same time means Restart and pressing Pause and Opt2 means Flip screen.
|
||||
|
||||
; For "easter egg" use I have also included all three keys pressed '?'
|
||||
; and Opt1 + Opt2 pressed '3'.
|
||||
; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'.
|
||||
|
||||
.data
|
||||
KBBUF: .byte 0
|
||||
DEBOUNCE: .byte 0 ; Contains char until key is freed
|
||||
|
||||
.code
|
||||
_kbhit:
|
||||
lda $FCB1 ; Read the Pause key
|
||||
and #1
|
||||
bne @L4
|
||||
lda $FCB0 ; No Pause pressed
|
||||
and #$0c
|
||||
bne @L1
|
||||
stz DEBOUNCE ; No keys pressed at all
|
||||
lda KBBUF ; But we may have some old key in the buffer
|
||||
bne @L9
|
||||
jmp return0 ; No key has been pressed
|
||||
@L1:
|
||||
cmp #$0c
|
||||
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…
Reference in New Issue
Block a user