Skip to content

Commit

Permalink
Optimize text screen saving lib for space
Browse files Browse the repository at this point in the history
  • Loading branch information
inexorabletash committed Dec 26, 2024
1 parent 5d54e40 commit b82b9f2
Showing 1 changed file with 57 additions and 26 deletions.
83 changes: 57 additions & 26 deletions lib/save_textpage.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,36 @@
;;; might trash the text page (e.g. initializing SSC)
;;; ============================================================

.scope

ptr_screen := $06
ptr_aux_buf := $08
ptr_main_buf := $10

kNumSegments = 8
kSegmentWidth = $78
kSegmentStride = $80

;;; Saves text page (except screen holes)
.proc SaveTextPage
lda RD80STORE
pha
sta SET80STORE

ldx #0
loop:
.repeat 8, i
sta PAGE2ON
lda $400 + (i*$80),x
sta _textpage_aux_buf + (i*$78),x
jsr InitPointers
ldx #kNumSegments-1
loop1: ldy #kSegmentWidth-1
loop2: sta PAGE2ON
lda (ptr_screen),y
sta (ptr_aux_buf),y
sta PAGE2OFF
lda $400 + (i*$80),x
sta _textpage_main_buf + (i*$78),x
.endrepeat
inx
cpx #$78
jne loop
lda (ptr_screen),y
sta (ptr_main_buf),y
dey
bpl loop2
jsr IncPointers
dex
bpl loop1

pla
bmi :+
Expand All @@ -37,25 +48,45 @@ loop:
pha
sta SET80STORE

ldx #0
loop:
.repeat 8, i
sta PAGE2ON
lda _textpage_aux_buf + (i*$78),x
sta $400 + (i*$80),x
jsr InitPointers
ldx #kNumSegments-1
loop1: ldy #kSegmentWidth-1
loop2: sta PAGE2ON
lda (ptr_aux_buf),y
sta (ptr_screen),y
sta PAGE2OFF
lda _textpage_main_buf + (i*$78),x
sta $400 + (i*$80),x
.endrepeat
inx
cpx #$78
jne loop
lda (ptr_main_buf),y
sta (ptr_screen),y
dey
bpl loop2
jsr IncPointers
dex
bpl loop1

pla
bmi :+
sta CLR80STORE
: rts
.endproc

_textpage_main_buf: .res 40*24
_textpage_aux_buf: .res 40*24
.proc InitPointers
copy16 #$400, ptr_screen
copy16 #textpage_aux_buf, ptr_aux_buf
copy16 #textpage_main_buf, ptr_main_buf
rts
.endproc

.proc IncPointers
add16_8 ptr_screen, #kSegmentStride
add16_8 ptr_aux_buf, #kSegmentWidth
add16_8 ptr_main_buf, #kSegmentWidth
rts
.endproc

textpage_main_buf: .res 24*40
textpage_aux_buf: .res 24*40

;;; Exports
::SaveTextPage := SaveTextPage
::RestoreTextPage := RestoreTextPage
.endscope

0 comments on commit b82b9f2

Please sign in to comment.