Created
March 27, 2018 19:24
-
-
Save Pinacolada64/7b5c95f92ba376b028127973d53f2908 to your computer and use it in GitHub Desktop.
Cursor blink with CIA timer delay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; portion of code is combining 3-key rollover method of scanning keyboard, | |
; omitted to just focus on re-entrant cursor blink function | |
orig $c000 ; original was $c500 | |
CAS1 = $c0 ; Tape Motor Interlock (temp storage | |
LSTX = $c5 ; Matrix Coordinate of Last Key Pressed, 64=None Pressed | |
SFDX = $cb ; Matrix Coordinate of Current Key Pressed | |
BLNSW = $cc ; Cursor Blink Enable: 0=Flash Cursor | |
BLNCT = $cd ; Timer: Countdown to Blink Cursor | |
GDBLN = $ce ; Character Under Cursor | |
BLNON = $cf ; Flag: Was Last Cursor Blink on or off | |
PNT = $d1 ; Pointer to the Address of the Current Screen Line | |
PNTR = $d3 ; Cursor Column on Current Line | |
USER = $f3 ; Pointer: Address of the Current Screen Color RAM Location | |
KEYTAB = $f5 ; Vector: Keyboard Decode Table | |
COLOR = $0286 ; Current Foreground Color for Text | |
GDCOL = $0287 ; Color of Character Under Cursor | |
SHFLAG = $028d ; Flag: SHIFT/CTRL/Logo Keypress | |
KEYLOG = $028f ; Vector: Keyboard Table Setup Routine | |
CINV = $0314 ; Vector: IRQ Interrupt Routine | |
NMINV = $0318 ; Vector: Non-Maskable Interrupt | |
CIAPRA = $dc00 ; Data Port Register A | |
CIAPRB = $dc01 ; Data Port Register B | |
TI2ALO = $dd04 ; CIA #2 Timer A Lo Byte | |
TI2AHI = $dd05 ; CIA #2 Timer A Hi Byte | |
CI2ICR = $dd0d ; CIA #2 Interrupt Control Register | |
CI2CRA = $dd0e ; CIA #2 Control Register A | |
CI2CRB = $dd0f ; CIA #2 Control Register B | |
SCRNSTOR= $ea1c ; .a: char, $d1: screen addr, .x: color | |
COLRSYNC= $ea24 ; Synchronize Color RAM Pointer to Screen Line Pointer | |
CHROUT = $ffd2 ; Output char in .A to current output device | |
STOP = $ffe1 ; check for STOP key pressed | |
UDTIM = $ffea ; update the software clock | |
c509: | |
; re-implementation of $ea34 - update cursor flash, except no RTI | |
jsr UDTIM ; $c509 20 ea ff | |
lda BLNSW ; $c50c a5 cc ; should the cursor flash? | |
bne c539 ; $c50e d0 29 ; no, skip cursor flash routine | |
dec BLNCT ; $c510 c6 cd ; time to blink cursor yet? | |
bne c539 ; $c512 d0 25 | |
lda #$14 ; $c514 a9 14 | |
sta BLNCT ; $c516 85 cd | |
ldy PNTR ; $c518 a4 d3 | |
lsr BLNON ; $c51a 46 cf | |
ldx GDCOL ; $c51c ae 87 02 | |
lda (PNT),y ; $c51f b1 d1 | |
bcs c534 ; $c521 b0 11 | |
inc BLNON ; $c523 e6 cf | |
sta GDBLN ; $c525 85 ce | |
jsr COLRSYNC ; $c527 20 24 ea | |
lda (USER),y ; $c52a b1 f3 | |
sta GDCOL ; $c52c 8d 87 02 | |
ldx COLOR ; $c52f ae 86 02 | |
lda GDBLN ; $c532 a5 ce ; get char under cursor | |
c534: | |
eor #$80 ; $c534 49 80 ; toggle rvs state | |
jsr SCRNSTOR ; $c536 20 1c ea | |
c539: | |
lda 197 ; key hit? | |
bne out ; yes | |
jsr STOP ; check for STOP key | |
bne delay ; not hit, go on to delay | |
lda #$0d ; if so, output CR | |
out: | |
jsr CHROUT ; output char typed, or cr | |
rts ; return to BASIC | |
delay: | |
sty savey ; save .y | |
ldy #$30 ; 30 ms? | |
jsr delyms ; do the delay | |
ldy savey | |
jmp c509 | |
; from sliding input - delay used for cursor blink | |
; enter with .y = milliseconds | |
delyms: | |
pha | |
lda #{%:01111111}; $7f - clear ICR register. | |
; Bit 7: Write: set or clear bits of this register | |
; (1=bits written with 1 will be set, [0]=bits written with 1 will be cleared) | |
sta CI2ICR ; $dd0d: CIA #2 Interrupt Control Register | |
lda #$08 ; Bit 3: Timer A/B run mode (1=one-shot, 0=continuous) | |
sta CI2CRA ; $dd0e: CIA #2: Control Register A | |
sta CI2CRB ; $dd0f: CIA #2: Control Register B | |
lda #$ff | |
sta TI2ALO ; $dd04 | |
lda #$04 | |
sta TI2AHI ; $dd05 | |
de1: | |
lda #{%:00010001} ; #$11 | |
; Bit 0: Start Timer A (1=start, 0=stop) | |
; Bit 4: Force latched value to be loaded to Timer A counter (1=force | |
; load strobe) | |
sta CI2CRA ; $dd0e: CIA #2: Control Register A | |
de2: | |
lda TI2AHI ; $dd05 | |
bne de2 | |
dey | |
bne de2 | |
pla | |
rts | |
savey: | |
.byte $00 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment