aboutsummaryrefslogtreecommitdiff
path: root/timed_getch.s
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2016-01-02 21:35:39 -0500
committerB. Watson <yalhcru@gmail.com>2016-01-02 21:35:39 -0500
commit7d412a05b2eb563f268d81387be0dacd1b77cac2 (patch)
treecb8d2c1a5356a2f83d21f3eebcef6d7edf3b3da0 /timed_getch.s
parentd3395e701c2a14d30508a7f36c84be620ff2261a (diff)
downloadtaipan-7d412a05b2eb563f268d81387be0dacd1b77cac2.tar.gz
leave title screen showing while loading (not quite right yet)
Diffstat (limited to 'timed_getch.s')
-rw-r--r--timed_getch.s108
1 files changed, 96 insertions, 12 deletions
diff --git a/timed_getch.s b/timed_getch.s
index 8675290..a5ac4d5 100644
--- a/timed_getch.s
+++ b/timed_getch.s
@@ -1,26 +1,110 @@
- .export _timed_getch, _set_jiffy_timer
- .import _cgetc
+ .export _timed_getch, _set_jiffy_timer, _agetc, _numgetc, _yngetc, _lcgetc
+ .import _cgetc, _cblank
-_set_jiffy_timer:
- sei
- sta 540
- stx 541
+ .include "atari.inc"
+
+_set_jiffy_timer: ; called by jsleep() also.
+ sei ; disable IRQ while setting timer
+ sta CDTMV3
+ stx CDTMV3+1
cli
rts
_timed_getch:
jsr _set_jiffy_timer
wait4key:
- lda 540
- ora 541
- beq done
- ldx 764
- inx
+ lda CDTMV3 ; has timer counted down to 0?
+ ora CDTMV3+1
+ beq done ; yes, return(-1)
+ lda CH ; no, check for a keypress
+ ; ...but don't let the capslock or inverse keys count
+ ; as a keypress, here.
+
+ cmp #$ff ; no key pressed
+ beq wait4key
+ and #$3f ; mask shift/control bits
+ cmp #$3c ; caps-lock
+ beq wait4key
+ cmp #$27 ; inverse (atari) key
beq wait4key
- jmp _cgetc
+ jmp _agetc ; user hit a key, read it.
+
done:
lda #$ff ; return -1
tax
rts
+
+; _agetc removes the inverse-video bit, and if
+; a control key is pressed, it turns it into the non-control version
+; (e.g. ^A = lowercase a). Keys that can't be mapped to regular ASCII
+; (such as clear, delete, escape) are replaced with a space.
+; extern char lcgetc();
+_agetc:
+; lda #0 ; show cursor
+; sta CRSINH
+; lda #$20
+; jsr _cblank
+
+ jsr _cgetc ; get ATASCII code of keypress
+
+ ; special cases
+ cmp #$9b ; enter key, return as-is
+ beq ok
+ cmp #$7e ; backspace
+ beq ok
+
+ ; everything else
+ and #$7f ; strip bit 7 (inverse)
+ bne notnull
+ lda #$20 ; map null (heart, ctrl-,) to space
+notnull:
+ cmp #$20
+ bcs notcontrol
+ ora #$60 ; 1 - 31 map to 96 - 127
+notcontrol:
+ cmp #$7c ; | (pipe, vertical bar) allowed as-is.
+ beq ok
+ cmp #$7a ; rest of range $7b - $7f is unmappable.
+ bcc ok ; (remember, $7e, backspace, was handled above)
+ lda #$20
+ok:
+; ldx #$01 ; hide cursor
+; stx CRSINH
+ rts
+
+_lcgetc:
+ jsr _agetc
+ cmp #'A'
+ bcc ok
+ cmp #'Z'+1
+ bcs ok
+ eor #$20 ; lowercase it
+ bcc ok
+
+_numgetc:
+ jsr _agetc
+ cmp #$9b
+ beq ok
+ cmp #$7e
+ beq ok
+ cmp #$61 ; allow 'a' for "all"
+ beq ok
+ cmp #'0'
+ bcc _numgetc
+ cmp #'9'+1
+ bcc ok
+ bcs _numgetc
+
+_yngetc:
+ sta FR0 ; stash default arg
+ jsr _lcgetc
+ cmp #'y' ; return y or n immediately
+ beq ok
+ cmp #'n'
+ beq ok
+ lda FR0 ; otherwise, check for default arg
+ beq _yngetc ; no default, get another keypress
+ rts ; else return the default
+