;
-; Karri Kaksonen, 2004-11-01
+; Karri Kaksonen, Harry Dodgson 2006-01-07
;
; char cgetc (void);
;
.export _cgetc
.import _kbhit
- .import KBBUF
+ .import KBEDG
+ .import KBSTL
; --------------------------------------------------------------------------
; The Atari Lynx has a very small keyboard - only 3 keys
; 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
+ lda KBSTL
+ ora KBEDG
bne @L1
-
- jsr _kbhit ; Check for double pressed buttons
- lda KBBUF
- stz KBBUF
+ jsr _kbhit ; Check for char available
+ tax ; Test result
+ bra _cgetc
+@L1:
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
;
-; Karri Kaksonen, 2004-11-01
+; Karri Kaksonen, Harry Dodgson 2006-01-06
;
; unsigned char kbhit (void);
;
.export _kbhit
- .export KBBUF
+ .export KBEDG
+ .export KBSTL
.import return0, return1
; --------------------------------------------------------------------------
; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'.
.data
-KBBUF: .byte 0
-DEBOUNCE: .byte 0 ; Contains char until key is freed
+KBTMP: .byte 0
+KBPRV: .byte 0
+KBEDG: .byte 0
+KBSTL: .byte 0
+KBDEB: .byte 0
+KBNPR: .byte 0
.code
_kbhit:
- lda $FCB1 ; Read the Pause key
- and #1
- bne @L4
- lda $FCB0 ; No Pause pressed
+ lda $FCB0 ; Read the Opt buttons
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
+ sta KBTMP
+ lda $FCB1 ; Read Pause
+ and #1
+ ora KBTMP ; 0000210P
+ tax
+ and KBPRV
+ sta KBSTL ; for multibutton
+ txa
+ and KBDEB
+ sta KBEDG ; for just depressed
+ 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:
- 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
-
-
+ jmp return0 ; No new keys hit