WeeGUI/painting.s

287 lines
6.0 KiB
ArmAsm
Raw Normal View History

2014-08-29 19:19:19 +00:00
;
; painting.s
; General rendering routines for 80 column text elements
2014-08-29 19:19:19 +00:00
;
; Created by Quinn Dunki on 8/15/14.
; Copyright (c) 2014 One Girl, One Laptop Productions. All rights reserved.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGDesktop
; Paints the desktop pattern (assumes 80 cols)
;
WGDesktop:
2018-03-02 19:20:17 +00:00
pha
2018-03-07 21:34:35 +00:00
lda #'W'
sta WGClearScreen_charPage1+1
lda #'V'
bra WGClearScreen_common
2018-03-02 19:20:17 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGClearScreen
; Clears the text screen (assumes 80 cols)
;
WGClearScreen:
pha
2018-03-07 21:34:35 +00:00
lda #' ' + $80
sta WGClearScreen_charPage1+1
2018-03-02 19:20:17 +00:00
WGClearScreen_common:
2018-03-07 21:34:35 +00:00
sta WGClearScreen_charPage2+1
2018-03-02 19:20:17 +00:00
SAVE_XY
2018-03-02 00:59:52 +00:00
SETSWITCH PAGE2OFF
2018-03-07 21:34:35 +00:00
ldx #23
2018-03-02 19:20:17 +00:00
WGClearScreen_lineLoop:
2018-03-07 21:34:35 +00:00
lda TEXTLINES_L,x ; Compute video memory address of line
sta WGClearScreen_charLoop1+1
sta WGClearScreen_charLoop2+1
lda TEXTLINES_H,x
sta WGClearScreen_charLoop1+2
sta WGClearScreen_charLoop2+2
ldy #39
2018-03-02 19:20:17 +00:00
WGClearScreen_charPage1:
2018-03-07 21:34:35 +00:00
lda #$FF ; Self-modifying code!
2018-03-02 19:20:17 +00:00
WGClearScreen_charLoop1:
2018-03-07 21:34:35 +00:00
sta $FFFF,y ; Self-modifying code!
dey
2018-03-07 21:34:35 +00:00
bpl WGClearScreen_charLoop1
2018-03-02 00:59:52 +00:00
SETSWITCH PAGE2ON
2018-03-07 21:34:35 +00:00
ldy #39
2018-03-02 19:20:17 +00:00
WGClearScreen_charPage2:
2018-03-07 21:34:35 +00:00
lda #$FF ; Self-modifying code!
2018-03-02 19:20:17 +00:00
WGClearScreen_charLoop2:
2018-03-07 21:34:35 +00:00
sta $FFFF,y ; Self-modifying code!
2018-03-02 00:59:52 +00:00
dey
2018-03-07 21:34:35 +00:00
bpl WGClearScreen_charLoop2
2018-03-02 00:59:52 +00:00
SETSWITCH PAGE2OFF
dex
2018-03-07 21:34:35 +00:00
bpl WGClearScreen_lineLoop
2018-03-02 19:20:17 +00:00
RESTORE_XY
pla
rts
2014-08-29 19:19:19 +00:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGPlot
; Plots a character at global cursor position (assumes 80 cols)
; A: Character to plot (Apple format)
; Side effects: Clobbers BASL,BASH
2014-08-29 19:19:19 +00:00
;
WGPlot:
SAVE_XY
pha
2014-08-29 19:19:19 +00:00
2018-03-07 21:34:35 +00:00
ldx WG_CURSORY
2014-08-29 19:19:19 +00:00
lda TEXTLINES_L,x ; Compute video memory address of point
sta BASL
lda TEXTLINES_H,x
sta BASH
2018-03-07 21:34:35 +00:00
lda WG_CURSORX
2014-08-29 19:19:19 +00:00
lsr
clc
2018-03-07 21:34:35 +00:00
adc BASL
2014-08-29 19:19:19 +00:00
sta BASL
2018-03-07 22:38:22 +00:00
bcc WGPlot_SkipInc
inc BASH
WGPlot_SkipInc:
2014-08-29 19:19:19 +00:00
2018-03-07 21:34:35 +00:00
lda WG_CURSORX ; X even?
2015-02-12 16:00:41 +00:00
ror
2018-03-07 21:34:35 +00:00
bcs WGPlot_xOdd
2014-08-29 19:19:19 +00:00
2018-03-07 21:34:35 +00:00
SETSWITCH PAGE2ON ; Plot the character
pla
2018-03-07 21:34:35 +00:00
sta (BASL)
2014-08-29 19:19:19 +00:00
jmp WGPlot_done
WGPlot_xOdd:
2018-03-07 21:34:35 +00:00
SETSWITCH PAGE2OFF ; Plot the character
pla
2018-03-07 21:34:35 +00:00
sta (BASL)
2014-08-29 19:19:19 +00:00
WGPlot_done:
2018-03-07 21:34:35 +00:00
SETSWITCH PAGE2OFF
RESTORE_XY
2014-08-29 19:19:19 +00:00
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGPrint
; Prints a null-terminated ASCII string at the current view's
2014-08-29 19:19:19 +00:00
; cursor position. Clips to current view.
; PARAM0: String pointer, LSB
; PARAM1: String pointer, MSB
; V: If set, characters are printed raw with no high bit alterations
; Side effects: Clobbers SA,BASL,BASH
2014-08-29 19:19:19 +00:00
;
WGPrint:
SAVE_AXY
SAVE_ZPS
lda #%10000000
ldx #%00111111
bvc WGPrint_setupMask
lda #0
ldx #$ff
clv
WGPrint_setupMask:
sta WGPrint_specialMask
stx WGPrint_setupMaskInverse
; Start checking clipping boundaries
lda WG_LOCALCURSORY
2018-03-07 21:34:35 +00:00
cmp WG_VIEWCLIP+3
bcs WGPrint_leapDone ; Entire string is below the clip box
2018-03-07 21:34:35 +00:00
jsr WGStrLen ; We'll need the length of the string
sta SCRATCH1
LDX_ACTIVEVIEW ; Cache view width for later
lda WG_VIEWRECORDS+7,x
sta WG_SCRATCHA
ldy #0
WGPrint_lineLoopFirst: ; Calculating start of first line is slightly different
2018-03-07 21:34:35 +00:00
lda WG_LOCALCURSORY
cmp WG_VIEWCLIP+1
bcc WGPrint_skipToEndFirst ; This line is above the clip box
2018-03-07 21:34:35 +00:00
lda WG_LOCALCURSORX ; Find start of line within clip box
cmp WG_VIEWCLIP+0
bcs WGPrint_visibleChars
2018-03-07 21:34:35 +00:00
lda WG_VIEWCLIP+0 ; Line begins before left clip plane
sec ; Advance string index and advance cursor into clip box
sbc WG_LOCALCURSORX
tay
lda WG_VIEWCLIP+0
2018-03-07 21:34:35 +00:00
sta WG_LOCALCURSORX
bra WGPrint_visibleChars
WGPrint_leapDone:
bra WGPrint_done
WGPrint_skipToEndFirst:
lda WG_SCRATCHA ; Skip string index ahead by distance to EOL
sec
sbc WG_LOCALCURSORX
2018-03-07 21:34:35 +00:00
cmp SCRATCH1
bcs WGPrint_done ; EOL is past the end of the string, so we're done
tay
2018-03-07 21:34:35 +00:00
lda WG_SCRATCHA ; Skip cursor ahead to EOL
sta WG_LOCALCURSORX
bra WGPrint_nextLine
WGPrint_skipToEnd:
tya ; Skip string index ahead by distance to EOL
clc
adc WG_SCRATCHA
cmp SCRATCH1
bcs WGPrint_done ; EOL is past the end of the string, so we're done
tay
2018-03-07 21:34:35 +00:00
lda WG_SCRATCHA ; Skip cursor ahead to EOL
sta WG_LOCALCURSORX
bra WGPrint_nextLine
WGPrint_lineLoop:
2018-03-07 21:34:35 +00:00
lda WG_LOCALCURSORY
cmp WG_VIEWCLIP+1
bcc WGPrint_skipToEnd ; This line is above the clip box
2018-03-07 21:34:35 +00:00
lda WG_LOCALCURSORX ; Find start of line within clip box
cmp WG_VIEWCLIP+0
bcs WGPrint_visibleChars
tya
clc
2018-03-07 21:34:35 +00:00
adc WG_VIEWCLIP+0 ; Jump ahead by left span
tay
lda WG_VIEWCLIP+0 ; Set cursor to left edge of visible area
2018-03-07 21:34:35 +00:00
sta WG_LOCALCURSORX
WGPrint_visibleChars:
2018-03-07 21:34:35 +00:00
jsr WGSyncGlobalCursor
lda INVERSE
cmp #CHAR_INVERSE
beq WGPrint_charLoopInverse
WGPrint_charLoopNormal:
2018-03-07 21:34:35 +00:00
lda (PARAM0),y ; Draw current character
beq WGPrint_done
ora WGPrint_specialMask
2018-03-07 21:34:35 +00:00
jsr WGPlot
iny
inc WG_CURSORX ; Advance cursors
inc WG_LOCALCURSORX
lda WG_LOCALCURSORX
2018-03-07 21:34:35 +00:00
cmp WG_SCRATCHA ; Check for wrap boundary
beq WGPrint_nextLine
cmp WG_VIEWCLIP+2 ; Check for right clip plane
beq WGPrint_endVisible
bra WGPrint_charLoopNormal
WGPrint_done: ; This is in the middle here to keep local branches in range
RESTORE_ZPS
RESTORE_AXY
rts
WGPrint_endVisible:
tya
clc
2018-03-07 21:34:35 +00:00
adc WG_VIEWCLIP+4 ; Advance string index by right span
cmp SCRATCH1
bcs WGPrint_done
tay
2014-08-29 19:19:19 +00:00
WGPrint_nextLine:
2018-03-07 21:34:35 +00:00
inc WG_LOCALCURSORY ; Advance cursor
lda WG_LOCALCURSORY
cmp WG_VIEWCLIP+3 ; Check for bottom clip plane
beq WGPrint_done
cmp WG_VIEWRECORDS+8,x ; Check for bottom of view
beq WGPrint_done
lda (PARAM0),y ; Check for end string landing exactly at line end
beq WGPrint_done
2018-03-07 22:38:22 +00:00
stz WG_LOCALCURSORX
bra WGPrint_lineLoop
2014-08-29 19:19:19 +00:00
WGPrint_charLoopInverse:
2018-03-07 21:34:35 +00:00
lda (PARAM0),y ; Draw current character
beq WGPrint_done
cmp #$60
bcc WGPrint_charLoopInverseLow
and #%01111111 ; Inverse lowercase is in alternate character set
bra WGPrint_charLoopInversePlot
WGPrint_charLoopInverseLow:
and WGPrint_setupMaskInverse ; Normal inverse
WGPrint_charLoopInversePlot:
2018-03-07 21:34:35 +00:00
jsr WGPlot
iny
inc WG_CURSORX ; Advance cursors
inc WG_LOCALCURSORX
lda WG_LOCALCURSORX
2018-03-07 21:34:35 +00:00
cmp WG_SCRATCHA ; Check for wrap boundary
beq WGPrint_nextLine
cmp WG_VIEWCLIP+2 ; Check for right clip plane
beq WGPrint_endVisible
bra WGPrint_charLoopInverse
WGPrint_specialMask:
.byte 0
WGPrint_setupMaskInverse:
.byte 0