hgr: rectangle, more optimization

This commit is contained in:
Vince Weaver 2021-12-08 17:01:22 -05:00
parent 18e4ae1554
commit f03e452326

View File

@ -1,6 +1,17 @@
; Rectangle Transition
; "night fell like a power point"
; 167 bytes -- original
; 166 bytes -- make end loop beq not jmp
; 156 bytes -- use GBASL/GBASH rather than self-modifying code
; 154 bytes -- countdown X in inner loop
; 153 bytes -- remove unnecessary clc
; 151 bytes -- was setting Y twice
; 147 bytes -- lookup table for XADD/YADD
; 145 bytes -- stop on YY value
; 150 bytes -- have it cycle colors
; 147 bytes -- init zp to 0 in loop
; 144 bytes -- put lookup table in zero page
; zero page
GBASL = $26
@ -12,6 +23,14 @@ HGR_Y = $E2
HGR_COLOR = $E4
HGR_PAGE = $E6
GBASH_SAVED = $F5
TABLE = $F0 ; should be 0
TABLE2 = $F1 ; should be 1
TABLE3 = $F2 ; should be 0
TABLE4 = $F3 ; should be -1
TABLE5 = $F4 ; should be 0
XX = $F6
YY = $F7
XADD = $F8
@ -42,11 +61,19 @@ rectangle:
jsr HGR2 ; set hi-res 140x192, page2, fullscreen
; A and Y both 0 at end
sty XX ; X = 0
sty YY ; Y = 0
sty YMIN ; ymin=0
dey
sty XMIN ; xmin = -1
over:
; clear our zp things to 0
ldx #15
clear_loop:
sta $EF,X
dex
bne clear_loop
dec XMIN ; xmin = -1
inc TABLE2
dec TABLE4
ldy #39
sty XMAX ; xmax=39
@ -58,90 +85,82 @@ main_loop:
; left to right horizontal
dec YMAX
ldy #$1
sty XADD
dey
sty YADD
; XADD=1,YADD=0
jsr draw_line
inc XMIN
; top to bottom vertical
ldy #0
sty XADD
iny
sty YADD
inc XMIN
; XADD=0,YADD=1
jsr draw_line
; right to left horizontal
ldy #$ff
sty XADD
iny
sty YADD
inc YMIN
; XADD=-1,YADD=0
jsr draw_line
; bottom to top vertical
dec XMAX
; inc XMIN
inc YMIN
ldy #$ff
sty YADD
iny
sty XADD
; XADD=0,YADD=-1
jsr draw_line
; inc XX
; YY is in A here
; X is zero here
lda XX
cmp #12
bne main_loop
end:
jmp end
txa ; put zero into A
inc color_smc+1
bne over
; horizontal
;=================================
; draw a horizontal/vertical line
; 8 rows high
draw_line:
lda YY
get_next:
lda FRAME
and #$3
tax
lda TABLE2,X
sta XADD
lda TABLE,X
sta YADD
inc FRAME
repeat_line:
lda YY ; YY * 8
asl
asl
asl
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
lda GBASL
sta output_smc+1
lda GBASH
sta output_smc+2
; first top right
horiz_smc1:
ldx XX
sta GBASH_SAVED ; reset top of box
out_loop:
ldy #0
lda GBASH
sta output_smc+2
ldx #8
lda GBASH_SAVED
sta GBASH
ldy XX
in_loop:
lda #$FF
ldx XX
output_smc:
sta $4000,X
lda output_smc+2
color_smc:
lda #$7F ; draw white box
output_smc:
sta (GBASL),Y
lda GBASH ; move to next line
clc
adc #$4
sta output_smc+2
sta GBASH
iny
cpy #8
dex
bne in_loop
lda #25
lda #25 ; wait a bit
jsr WAIT
check_x:
@ -158,7 +177,7 @@ check_x:
bne out_loop
check_y:
clc
; c should already be clear
lda YY
adc YADD
sta YY
@ -168,7 +187,12 @@ check_y:
cmp YMAX
beq done_line
bne draw_line
bne repeat_line
done_line:
rts