1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-19 06:31:31 +00:00

Add setcursor method

This commit is contained in:
Karri Kaksonen 2022-04-04 15:18:13 +03:00
parent c7cb201070
commit 43a1c24784

View File

@ -23,9 +23,9 @@
; definitely not allow direct access to the variables.
;
.export _cursor_visible
.export _cursorzone
.export _setcursor
.export _gotoxy, _gotox, _gotoy, wherex, wherey
.export CURS_X, CURS_Y
.constructor init_cursor
.importzp ptr1, sp
@ -36,6 +36,10 @@
.macpack generic
.data
;-----------------------------------------------------------------------------
; The variables used by cursor functions
;
CURS_X:
.byte 0
CURS_Y:
@ -49,6 +53,18 @@ _cursorzone:
.code
;-----------------------------------------------------------------------------
; Enable/disable cursor
;
.proc _setcursor
ldx _cursor_visible
sta _cursor_visible
txa
rts
.endproc
;-----------------------------------------------------------------------------
; Calculate cursorzone address
; You also need to set the cursorzone to point to the correct cursor Header
@ -56,7 +72,8 @@ _cursorzone:
; Offset to cursor zone 5. To next line offset 11
; cursorzone points to _zones + CURS_Y * 11 + 5
; A = CURS_Y
calccursorzone:
.proc calccursorzone
jsr pusha0
lda #11
jsr tosumula0
@ -71,6 +88,8 @@ calccursorzone:
sta ptr1+1
rts
.endproc
;-----------------------------------------------------------------------------
; Set cursor to Y position.
; You also need to set the cursorzone to point to the correct cursor Header
@ -86,7 +105,9 @@ calccursorzone:
; Enable cursor
; if showcursor cursorzone[1] = 30
;
_gotoy: pha
.proc _gotoy
pha
lda CURS_Y
jsr calccursorzone
ldy #1
@ -96,18 +117,23 @@ _gotoy: pha
sta CURS_Y
jsr calccursorzone
lda _cursor_visible
beq L2
beq @L1
lda #30 ; enable cursor
L2: ldy #1
@L1: ldy #1
sta (ptr1),y
rts
.endproc
;-----------------------------------------------------------------------------
; Set cursor to X position.
; You also need to set the hpos offset to the correct value on this line
; cursorzone[3] = 8 * CURS_X
;
_gotox: tay
.proc _gotox
sta CURS_X
tay
lda _cursorzone
ldx _cursorzone+1
sta ptr1
@ -121,6 +147,8 @@ _gotox: tay
sta (ptr1),y
rts
.endproc
;-----------------------------------------------------------------------------
; Set cursor to desired position (X,Y)
;