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 ; Rectangle Transition
; "night fell like a power point" ; "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 ; zero page
GBASL = $26 GBASL = $26
@ -12,6 +23,14 @@ HGR_Y = $E2
HGR_COLOR = $E4 HGR_COLOR = $E4
HGR_PAGE = $E6 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 XX = $F6
YY = $F7 YY = $F7
XADD = $F8 XADD = $F8
@ -42,11 +61,19 @@ rectangle:
jsr HGR2 ; set hi-res 140x192, page2, fullscreen jsr HGR2 ; set hi-res 140x192, page2, fullscreen
; A and Y both 0 at end ; A and Y both 0 at end
sty XX ; X = 0 over:
sty YY ; Y = 0 ; clear our zp things to 0
sty YMIN ; ymin=0
dey ldx #15
sty XMIN ; xmin = -1 clear_loop:
sta $EF,X
dex
bne clear_loop
dec XMIN ; xmin = -1
inc TABLE2
dec TABLE4
ldy #39 ldy #39
sty XMAX ; xmax=39 sty XMAX ; xmax=39
@ -58,90 +85,82 @@ main_loop:
; left to right horizontal ; left to right horizontal
dec YMAX dec YMAX
ldy #$1 ; XADD=1,YADD=0
sty XADD
dey
sty YADD
jsr draw_line jsr draw_line
inc XMIN
; top to bottom vertical ; top to bottom vertical
ldy #0 inc XMIN
sty XADD ; XADD=0,YADD=1
iny
sty YADD
jsr draw_line jsr draw_line
; right to left horizontal ; right to left horizontal
ldy #$ff inc YMIN
sty XADD ; XADD=-1,YADD=0
iny
sty YADD
jsr draw_line jsr draw_line
; bottom to top vertical ; bottom to top vertical
dec XMAX dec XMAX
; inc XMIN ; XADD=0,YADD=-1
inc YMIN
ldy #$ff
sty YADD
iny
sty XADD
jsr draw_line jsr draw_line
; inc XX ; YY is in A here
; X is zero here
lda XX
cmp #12 cmp #12
bne main_loop bne main_loop
end: 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: 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 asl
asl asl
jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y) jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y)
lda GBASL
sta output_smc+1
lda GBASH lda GBASH
sta output_smc+2 sta GBASH_SAVED ; reset top of box
; first top right
horiz_smc1:
ldx XX
out_loop: out_loop:
ldy #0 ldx #8
lda GBASH lda GBASH_SAVED
sta output_smc+2 sta GBASH
ldy XX
in_loop: 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 clc
adc #$4 adc #$4
sta output_smc+2 sta GBASH
iny dex
cpy #8
bne in_loop bne in_loop
lda #25 lda #25 ; wait a bit
jsr WAIT jsr WAIT
check_x: check_x:
@ -158,7 +177,7 @@ check_x:
bne out_loop bne out_loop
check_y: check_y:
clc ; c should already be clear
lda YY lda YY
adc YADD adc YADD
sta YY sta YY
@ -168,7 +187,12 @@ check_y:
cmp YMAX cmp YMAX
beq done_line beq done_line
bne draw_line bne repeat_line
done_line: done_line:
rts rts