From 5e015925a79fd4e1c8d33369f6a4f6d9e103c3f1 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Wed, 2 Feb 2022 14:02:02 -0500 Subject: [PATCH] orb: more optimizations. so close... --- demos/l/orb_256/boxes.s | 23 +++--- demos/l/orb_256/combo.s | 17 ++-- demos/l/orb_256/horror.s | 154 ++++++++++++++++++++++++++++++++++++ demos/l/orb_256/orb.s | 2 +- demos/l/orb_256/staggered.s | 47 ++++++----- 5 files changed, 199 insertions(+), 44 deletions(-) create mode 100644 demos/l/orb_256/horror.s diff --git a/demos/l/orb_256/boxes.s b/demos/l/orb_256/boxes.s index 29a8b2e4..7c86b7f1 100644 --- a/demos/l/orb_256/boxes.s +++ b/demos/l/orb_256/boxes.s @@ -18,13 +18,15 @@ outer_boxes: ldx #5 ; grab 5 bytes ; YRUN, XRUN, Y1, X1, COLOR data_smc: - lda $f180 + lda $f200 ; was $f180 sta YRUN-1,X ; store reverse for some reason inc data_smc+1 ; move to next dex bne data_smc - lda YRUN + ; at end, YRUN is in A, X=0 + +; lda YRUN ; keep size of YRUN<64 and #$3f sta YRUN @@ -45,23 +47,20 @@ rectangle_loop: and #$f tax - jsr HCOLOR1 -; lda COLORTBL,X ; index into color table -; sta HGR_COLOR ; and store + jsr HCOLOR1 ; index into color table with X + ; Note: we purposefully index off end ldx X1 ; X1 into X lda Y1 ; Y1 into A ldy #0 ; always 0 - jsr HPOSN ; (Y,X),(A) (values stores in HGRX,XH,Y) + jsr HPLOT0 ; (Y,X),(A) (values stored in HGRX,XH,Y) lda XRUN ; XRUN into A - and #$3f -; ldx #0 ; always 0 -; ldy #0 ; relative Y is 0 -; jsr HLINRL ; (X,A),(Y) - jsr combo_hlinrl + and #$3f ; keep it <64 + + ; sets X=0,Y=0 first + jsr combo_hlinrl ; draw relative (X,A),Y -blah: inc Y1 dec YRUN bne rectangle_loop diff --git a/demos/l/orb_256/combo.s b/demos/l/orb_256/combo.s index 68907ab9..fdcd69c9 100644 --- a/demos/l/orb_256/combo.s +++ b/demos/l/orb_256/combo.s @@ -1,5 +1,7 @@ ; combo -- Apple II Hires +; need 252 bytes to qualify (4 byte Apple II header) + ; 280 bytes -- initial combo ; 276 bytes -- shave some bytes ; 275 bytes -- common HLINRL function (thought it would save more) @@ -7,6 +9,8 @@ ; 268 bytes -- circle code now <128 so use bne instead of jmp ; 266 bytes -- use X to index in zero page ; 263 bytes -- more circle optimization +; 261 bytes -- optimize boxes +; 257 bytes -- optimize staggered ; zero page @@ -58,9 +62,6 @@ WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us combo: - lda #$20 - sta FRAME - jsr HGR2 ; after, A=0, Y=0 @@ -71,6 +72,11 @@ combo: .include "boxes.s" +even_lookup: +.byte $D7,$DD,$F5,$D5, $D5,$D5,$D5,$D5 +odd_lookup: +.byte $AA,$AA,$AA,$AB, $AB,$AE,$BA,$EA + ; sadly this only saves a byte combo_hlinrl: ldy #0 @@ -78,8 +84,5 @@ combo_hlinrl: jmp HLINRL ; plot relative (X,A), (Y) -even_lookup: -.byte $D7,$DD,$F5,$D5, $D5,$D5,$D5,$D5 -odd_lookup: -.byte $AA,$AA,$AA,$AB, $AB,$AE,$BA,$EA + diff --git a/demos/l/orb_256/horror.s b/demos/l/orb_256/horror.s new file mode 100644 index 00000000..b357674e --- /dev/null +++ b/demos/l/orb_256/horror.s @@ -0,0 +1,154 @@ +; orb + +; this was found accidentally when trying to draw circles +; it's doing Bresenham circle algo I think, which does weird +; things when radius=0 + +orb: + ; a=0, y=0 here + + tax ; x=0 + + dey ; set init color to white + sty HGR_COLOR ; set init color to white + +draw_next: + stx R + + ;=============================== + ; draw circle + ;=============================== + ; draw circle at (CX,CY) of radius R + ; signed 8-bit math so problems if R > 64? + + lda #0 + sta XX ; XX = 0 + + stx YY ; YY =R (X is R here) + + lda #3 ; D=3-2*R + sec + sbc R + sbc R + sta D + + ; always odd, never zero + + bne do_plots ; bra skip ahead first time through + +circle_loop: + inc XX ; XX=XX+1 + + lda XX ; XX is common both paths + ldy #6 ; default path add 6 + + ; IF D>0 THEN Y=Y-1:D=D+4*(X-Y)+10 + bit D ; check if negative w/o changing A + bmi d_negative + + dec YY ; YY=YY-1 + +d_positive: + ; D=D+4*(XX-YY)+10 + + ; XX is already in A + sec + sbc YY + ldy #10 +d_negative: + ; ELSE D=D+4*(XX)+6 +common_D: + sty DADD + asl + asl + clc + adc DADD + adc D + sta D + +do_plots: + ; setup constants + + lda XX + eor #$FF + sta MINUSXX + inc MINUSXX + + lda YY + eor #$FF + sta MINUSYY + inc MINUSYY + + ; HPLOT CX+X,CY+Y + ; HPLOT CX-X,CY+Y + ; HPLOT CX+X,CY-Y + ; HPLOT CX-X,CY-Y + ; HPLOT CX+Y,CY+X + ; HPLOT CX-Y,CY+X + ; HPLOT CX+Y,CY-X + ; HPLOT CX-Y,CY-X + + lda #3 + sta COUNT +pos_loop: + + ; calc left side + + ; calc X co-ord + + lda COUNT + ora #$1 + eor #$2 + tax +; lda CX + + + lda #128 + clc + adc XX,X + tax + + ; calc y co-ord + + ldx COUNT +; lda CY + lda #96 + clc + adc XX,X + + ldy #0 + + jsr HPLOT0 ; plot at (Y,X), (A) + + + ; calc right side + lda COUNT + and #$2 + eor #$2 + tax + lda XX,X + asl + + jsr combo_hlinrl ; plot relative (X,A), (Y) + ; so in our case (0,XX*2),0 + + + dec COUNT + bpl pos_loop + + ; IF YY>=XX THEN 4 + ; equivelant to IF XX=XX THEN 4 - ; equivelant to IF XX