1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-23 04:30:10 +00:00
cc65/libsrc/atari7800/setcursor.s

215 lines
5.3 KiB
ArmAsm
Raw Normal View History

2022-04-04 07:51:43 +00:00
;
; 2022-04-03, Karri Kaksonen
;
; setcursor (unsigned char on);
;
; The Atari 7800 does not have a hw cursor.
; This module emulates a cursor to be used with the conio
; implementation.
;
; The actual cursor display is included in the conio dll
; but every scanline has the element silenced by default
; at the end of every zone.
;
; The way the cursor works is to silence it before the cursor
; position changes and enable it afterwards.
;
; In order to get some performance we have a pointer to the
; cursor header structure. This structure is always at the
; end of the zone. So the pointer changes when CURS_Y changes.
;
; There is so many dependencies that it makes sense to
; deal with all CURS_X, CURS_Y stuff in this file and
; definitely not allow direct access to the variables.
;
2022-04-16 16:15:19 +00:00
.export gotoxy, _gotoxy, gotox, gotoy
2022-04-04 07:51:43 +00:00
.constructor init_cursor
2022-04-07 05:17:36 +00:00
.interruptor blink_cursor
2022-04-04 07:51:43 +00:00
2022-04-16 16:15:19 +00:00
.importzp sp
.import _zonecounter
2022-04-16 16:15:19 +00:00
.import _zones
.import cursor
.import pusha, incsp1, pusha0, pushax, popa
2022-04-04 07:51:43 +00:00
.include "atari7800.inc"
.include "extzp.inc"
2022-04-04 07:51:43 +00:00
.macpack generic
2022-04-16 16:15:19 +00:00
.data
2022-04-04 12:18:13 +00:00
;-----------------------------------------------------------------------------
; The variables used by cursor functions
;
2022-04-07 05:17:36 +00:00
blink_time:
2022-04-22 03:51:35 +00:00
.byte 200
2022-04-04 07:51:43 +00:00
2022-04-16 16:15:19 +00:00
.code
2022-04-04 07:51:43 +00:00
2022-04-18 10:49:29 +00:00
;---------------------------------------------------------------------------
; 8x16 routine
umula0:
ldy #8 ; Number of bits
lda #0
lsr ptr7800 ; Get first bit into carry
@L0: bcc @L1
clc
adc ptrtmp
tax
lda ptrtmp+1 ; hi byte of left op
clc
adc ptr7800+1
sta ptr7800+1
txa
@L1: ror ptr7800+1
ror a
ror ptr7800
dey
bne @L0
tax
lda ptr7800 ; Load the result
rts
2022-04-04 07:51:43 +00:00
;-----------------------------------------------------------------------------
; Calculate cursorzone address
; You also need to set the cursorzone to point to the correct cursor Header
; at the end of line CURS_Y.
; Offset to cursor zone 5. To next line offset 11
; cursorzone points to _zones + CURS_Y * 11 + 5
; A = CURS_Y
2022-04-04 12:18:13 +00:00
.proc calccursorzone
2022-04-16 16:15:19 +00:00
sta ptr7800
lda #11
sta ptrtmp
lda #0
sta ptr7800+1
sta ptrtmp+1
jsr umula0
clc
adc #5
bcc @L1
inx
@L1: clc
adc #<_zones
sta cursorzone ; calculate new cursorzone
txa
adc #>_zones
sta cursorzone+1
rts
2022-04-04 07:51:43 +00:00
2022-04-04 12:18:13 +00:00
.endproc
2022-04-04 07:51:43 +00:00
;-----------------------------------------------------------------------------
; Set cursor to Y position.
; You also need to set the cursorzone to point to the correct cursor Header
; at the end of line CURS_Y.
; Offset to cursor zone 5. To next line offset 11
; cursorzone points to _zones + CURS_Y * 11 + 5
;
; cursorzone[1] = 0 when not CURS_Y, 30 if CURS_Y
;
; Disable cursor
; cursorzone[1] = 0
;
; Enable cursor
; if showcursor cursorzone[1] = 30
;
2022-04-16 16:15:19 +00:00
.proc gotoy
pha
lda CURS_Y
jsr calccursorzone
ldy #1
lda #0
sta (cursorzone),y ; disable cursor
pla
sta CURS_Y
jsr calccursorzone
lda cursor
beq @L1
lda #30 ; enable cursor
@L1: ldy #1
sta (cursorzone),y
rts
2022-04-04 07:51:43 +00:00
2022-04-04 12:18:13 +00:00
.endproc
2022-04-04 07:51:43 +00:00
;-----------------------------------------------------------------------------
; 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
;
2022-04-16 16:15:19 +00:00
.proc gotox
2022-04-04 12:18:13 +00:00
2022-04-16 16:15:19 +00:00
sta CURS_X
ldy #3
clc
rol
rol
rol
sta (cursorzone),y
rts
2022-04-04 07:51:43 +00:00
2022-04-04 12:18:13 +00:00
.endproc
2022-04-04 07:51:43 +00:00
;-----------------------------------------------------------------------------
; Set cursor to desired position (X,Y)
;
2022-04-16 16:15:19 +00:00
.proc _gotoxy
2022-04-04 07:51:43 +00:00
2022-04-16 16:15:19 +00:00
jsr gotoy
jsr popa
jsr gotox
rts
.endproc
2022-04-04 07:51:43 +00:00
2022-04-16 16:15:19 +00:00
.proc gotoxy
jsr popa
jmp _gotoxy
.endproc
2022-04-04 07:51:43 +00:00
;-----------------------------------------------------------------------------
; Initialize cursorzone at startup
; Offset to cursor zone 5.
;
2022-04-16 16:15:19 +00:00
.proc blink_cursor
lda _zonecounter
and #01
beq @L3
2022-04-16 16:15:19 +00:00
inc blink_time
bne @L3
2022-04-22 03:51:35 +00:00
lda #200
2022-04-16 16:15:19 +00:00
sta blink_time
ldy #0
lda (cursorzone),y
bne @L1
lda #254
bne @L2
@L1: lda #0
@L2: sta (cursorzone),y
@L3: rts
.endproc
2022-04-07 05:17:36 +00:00
;-----------------------------------------------------------------------------
; Initialize cursorzone at startup
; Offset to cursor zone 5.
;
.segment "ONCE"
2022-04-04 07:51:43 +00:00
init_cursor:
2022-04-16 16:15:19 +00:00
lda #0
jsr calccursorzone
2022-04-19 17:01:47 +00:00
lda #0
sta blink_time
2022-04-16 16:15:19 +00:00
rts
2022-04-04 07:51:43 +00:00
;-----------------------------------------------------------------------------
; force the init constructor to be imported
.import initconio
conio_init = initconio