]> git.sur5r.net Git - cc65/commitdiff
New kbhit and cgetc functions from Karri
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 13 Nov 2004 10:34:06 +0000 (10:34 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 13 Nov 2004 10:34:06 +0000 (10:34 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@3295 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/lynx/Makefile
libsrc/lynx/cgetc.s [new file with mode: 0644]
libsrc/lynx/kbhit.s [new file with mode: 0644]

index cc66136382398aa95062aff562288818f902f1bd..b4196b8fcce37a2251097e8aa90ca744cc8776b7 100644 (file)
@@ -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 (file)
index 0000000..e72a790
--- /dev/null
@@ -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 (file)
index 0000000..66b375f
--- /dev/null
@@ -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
+
+