2001-09-13 21:37:59 +00:00
|
|
|
;
|
2001-09-18 12:23:28 +00:00
|
|
|
; Ullrich von Bassewitz, 16.09.2001
|
2001-09-13 21:37:59 +00:00
|
|
|
;
|
|
|
|
; char cgetc (void);
|
|
|
|
;
|
|
|
|
|
|
|
|
.export _cgetc
|
2001-09-19 10:01:52 +00:00
|
|
|
.condes k_blncur, 2
|
2001-09-13 21:37:59 +00:00
|
|
|
.import cursor
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
.include "page3.inc"
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.proc _cgetc
|
|
|
|
|
2001-09-18 12:23:28 +00:00
|
|
|
lda KeyIndex ; Characters waiting?
|
|
|
|
bne L3 ; Jump if so
|
2001-09-13 21:37:59 +00:00
|
|
|
|
2001-09-18 12:23:28 +00:00
|
|
|
; Switch on the cursor if needed
|
|
|
|
|
|
|
|
lda CURS_FLAG
|
|
|
|
pha
|
|
|
|
lda cursor
|
|
|
|
jsr setcursor
|
|
|
|
L1: lda KeyIndex
|
|
|
|
beq L1
|
|
|
|
ldx #0
|
|
|
|
pla
|
|
|
|
bne L2
|
|
|
|
inx
|
|
|
|
L2: txa
|
|
|
|
jsr setcursor
|
|
|
|
|
|
|
|
; Read the character from the keyboard buffer
|
|
|
|
|
|
|
|
L3: ldx #$00 ; Get index
|
|
|
|
ldy KeyBuf ; Get first character in the buffer
|
2001-09-13 21:37:59 +00:00
|
|
|
sei
|
2001-09-18 12:23:28 +00:00
|
|
|
L4: lda KeyBuf+1,x ; Move up the remaining chars
|
|
|
|
sta KeyBuf,x
|
2001-09-13 21:37:59 +00:00
|
|
|
inx
|
2001-09-18 12:23:28 +00:00
|
|
|
cpx KeyIndex
|
|
|
|
bne L4
|
|
|
|
dec KeyIndex
|
2001-09-13 21:37:59 +00:00
|
|
|
cli
|
|
|
|
|
2001-09-18 12:23:28 +00:00
|
|
|
ldx #$00 ; High byte
|
|
|
|
tya ; First char from buffer
|
2001-09-13 21:37:59 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
2001-09-18 12:23:28 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
;
|
|
|
|
|
|
|
|
.proc setcursor
|
|
|
|
|
|
|
|
ldy #$00 ;
|
|
|
|
tax ; On or off?
|
|
|
|
bne @L9 ; Go set it on
|
|
|
|
lda CURS_FLAG ; Is the cursor currently off?
|
|
|
|
bne @L8 ; Jump if yes
|
|
|
|
lda #1
|
|
|
|
sta CURS_FLAG ; Mark it as off
|
|
|
|
lda CURS_STATE ; Cursor currently displayed?
|
|
|
|
sty CURS_STATE ; Cursor will be cleared later
|
|
|
|
beq @L8 ; Jump if no
|
|
|
|
|
|
|
|
; Switch to the system bank, load Y with the cursor X coordinate
|
|
|
|
|
|
|
|
lda #$0F
|
|
|
|
sta IndReg ; Access system bank
|
|
|
|
ldy CURS_X
|
|
|
|
|
|
|
|
; Reset the current cursor
|
|
|
|
|
|
|
|
lda CURS_COLOR
|
|
|
|
sta (CRAM_PTR),y ; Store cursor color
|
|
|
|
lda ExecReg
|
|
|
|
sta IndReg ; Switch to our segment
|
|
|
|
lda (SCREEN_PTR),y
|
|
|
|
eor #$80 ; Toggle reverse flag
|
|
|
|
sta (SCREEN_PTR),y
|
|
|
|
|
|
|
|
; Done
|
|
|
|
|
|
|
|
@L8: rts
|
|
|
|
|
|
|
|
@L9: sty CURS_FLAG ; Cursor on (Y = 0)
|
|
|
|
rts
|
2001-09-19 10:01:52 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Blink the cursor in the interrupt. A blinking cursor is only available if
|
|
|
|
; we use the cgetc() function, so we will export this IRQ handler only in
|
|
|
|
; case the module is included into a program.
|
|
|
|
|
|
|
|
|
|
|
|
.proc k_blncur
|
|
|
|
|
|
|
|
lda CURS_FLAG ; Is the cursor on?
|
|
|
|
bne curend ; Jump if not
|
|
|
|
dec CURS_BLINK
|
|
|
|
bne curend
|
|
|
|
|
|
|
|
; Re-initialize the blink counter
|
|
|
|
|
|
|
|
lda #20 ; Initial value
|
|
|
|
sta CURS_BLINK
|
|
|
|
|
|
|
|
; Load Y with the cursor X coordinate
|
|
|
|
|
|
|
|
ldy CURS_X
|
|
|
|
|
|
|
|
; Check if the cursor state was on or off before
|
|
|
|
|
|
|
|
lda CURS_COLOR ; Load color behind cursor
|
|
|
|
lsr CURS_STATE ; Cursor currently displayed?
|
|
|
|
bcs curset ; Jump if yes
|
|
|
|
|
|
|
|
; Cursor was off before, switch it on
|
|
|
|
|
|
|
|
inc CURS_STATE ; Mark as displayed
|
|
|
|
lda (CRAM_PTR),y ; Get color behind cursor...
|
|
|
|
sta CURS_COLOR ; ...and remember it
|
|
|
|
lda CHARCOLOR ; Use character color
|
|
|
|
|
|
|
|
; Set the cursor with color in A
|
|
|
|
|
|
|
|
curset: sta (CRAM_PTR),y ; Store cursor color
|
|
|
|
lda ExecReg
|
|
|
|
sta IndReg ; Switch to our segment
|
|
|
|
lda (SCREEN_PTR),y
|
|
|
|
eor #$80 ; Toggle reverse flag
|
|
|
|
sta (SCREEN_PTR),y
|
|
|
|
|
|
|
|
; Switch back to the system bank
|
|
|
|
|
|
|
|
lda #$0F
|
|
|
|
sta IndReg
|
|
|
|
|
|
|
|
curend: rts
|
2001-09-18 12:23:28 +00:00
|
|
|
|
|
|
|
.endproc
|
|
|
|
|
2001-09-19 10:01:52 +00:00
|
|
|
|