From 14e40851e9b3b8d4c4474e4a51834c154629f796 Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 13 Nov 2004 10:34:06 +0000 Subject: [PATCH] New kbhit and cgetc functions from Karri git-svn-id: svn://svn.cc65.org/cc65/trunk@3295 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/lynx/Makefile | 4 ++- libsrc/lynx/cgetc.s | 41 +++++++++++++++++++++++ libsrc/lynx/kbhit.s | 79 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 1 deletion(-) create mode 100644 libsrc/lynx/cgetc.s create mode 100644 libsrc/lynx/kbhit.s diff --git a/libsrc/lynx/Makefile b/libsrc/lynx/Makefile index cc6613638..b4196b8fc 100644 --- a/libsrc/lynx/Makefile +++ b/libsrc/lynx/Makefile @@ -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 diff --git a/libsrc/lynx/cgetc.s b/libsrc/lynx/cgetc.s new file mode 100644 index 000000000..e72a79025 --- /dev/null +++ b/libsrc/lynx/cgetc.s @@ -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 + diff --git a/libsrc/lynx/kbhit.s b/libsrc/lynx/kbhit.s new file mode 100644 index 000000000..66b375f7e --- /dev/null +++ b/libsrc/lynx/kbhit.s @@ -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 + +