From a3073a368ed759b3d2fb19abc21fceaa5a455dcb Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 21 Jan 2021 10:43:38 -0500 Subject: [PATCH] boxes: more optimization --- graphics/gr/boxes/boxes.s | 106 ++++++++++++++++------------- graphics/gr/boxes/boxes_good.s | 119 +++++++++++++++++++++++++++++++++ graphics/gr/boxes/make_boxes.c | 25 +++++++ 3 files changed, 205 insertions(+), 45 deletions(-) create mode 100644 graphics/gr/boxes/boxes_good.s diff --git a/graphics/gr/boxes/boxes.s b/graphics/gr/boxes/boxes.s index 2ea67582..0201a1a5 100644 --- a/graphics/gr/boxes/boxes.s +++ b/graphics/gr/boxes/boxes.s @@ -8,6 +8,9 @@ ; 208 -- add subroutine to read byte into A, no need to save Y ; 205 -- optimize end loop ; 197 -- only update color if changed +; 194 -- pack color in with the other 4 bytes +; 191 -- do more common stuff in load_byte +; 189 -- change how end is detected .include "zp.inc" .include "hardware.inc" @@ -32,21 +35,14 @@ boxes: draw_box_loop: - ; get color - + ; get color/Y0 jsr load_byte - bmi use_old_color - cmp #$7F + tax ; Y0 is in X + + tya ; check for end end: - beq end ; hit end + bmi end - jsr SETCOL - - jsr load_byte ; Y0 - -use_old_color: - and #$3f - tax jsr load_byte ; Y1 sta Y1 @@ -54,9 +50,27 @@ use_old_color: jsr load_byte ; X0 sta X0 + tya + lsr + lsr + sta COLOR + + jsr load_byte ; X1 sta H2 + tya + and #$C0 + ora COLOR + + lsr + lsr + lsr + lsr + + jsr SETCOL + + inner_loop: ;; HLINE Y,H2 at A @@ -74,46 +88,48 @@ inner_loop: bcs draw_box_loop + + load_byte: inc load_byte_smc+1 ; assume we are always < 256 bytes ; so no need to wrap load_byte_smc: lda box_data-1 - + tay + and #$3f rts ; 4 6 6 6 6 box_data: - - .byte $0F,$00,$2F,$00,$27 - .byte $08,$01,$2B,$0A,$1B - .byte $0D,$28,$29,$03,$14 - .byte $A4,$27,$03,$16 - .byte $A0,$23,$05,$17 - .byte $9C,$1F,$08,$18 - .byte $08,$23,$26,$07,$0E - .byte $A4,$27,$08,$12 - .byte $9F,$1F,$0D,$12 - .byte $05,$2A,$2B,$03,$14 - .byte $AC,$2D,$06,$13 - .byte $08,$2C,$2D,$14,$17 - .byte $88,$16,$1C,$1C - .byte $0D,$02,$1A,$09,$18 - .byte $08,$04,$18,$0A,$15 - .byte $00,$06,$17,$0B,$14 - .byte $08,$15,$29,$22,$22 - .byte $93,$28,$22,$24 - .byte $05,$13,$14,$1C,$23 - .byte $95,$16,$1B,$21 - .byte $0D,$17,$2B,$19,$21 - .byte $00,$18,$20,$1A,$20 - .byte $A2,$2A,$1A,$20 - .byte $05,$1C,$1C,$1B,$20 - .byte $A6,$26,$1B,$20 - .byte $03,$1F,$20,$1F,$1F - .byte $A9,$2A,$1F,$1F - .byte $05,$19,$1E,$1D,$1E - .byte $A3,$28,$1D,$1E - .byte $0C,$02,$03,$17,$17 - .byte $7F + .byte $00,$2F,$C0,$E7 + .byte $01,$2B,$0A,$9B + .byte $28,$29,$43,$D4 + .byte $24,$27,$43,$D6 + .byte $20,$23,$45,$D7 + .byte $1C,$1F,$48,$D8 + .byte $23,$26,$07,$8E + .byte $24,$27,$08,$92 + .byte $1F,$1F,$0D,$92 + .byte $2A,$2B,$43,$54 + .byte $2C,$2D,$46,$53 + .byte $2C,$2D,$14,$97 + .byte $08,$16,$1C,$9C + .byte $02,$1A,$49,$D8 + .byte $04,$18,$0A,$95 + .byte $06,$17,$0B,$14 + .byte $15,$29,$22,$A2 + .byte $13,$28,$22,$A4 + .byte $13,$14,$5C,$63 + .byte $15,$16,$5B,$61 + .byte $17,$2B,$59,$E1 + .byte $18,$20,$1A,$20 + .byte $22,$2A,$1A,$20 + .byte $1C,$1C,$5B,$60 + .byte $26,$26,$5B,$60 + .byte $1F,$20,$DF,$1F + .byte $29,$2A,$DF,$1F + .byte $19,$1E,$5D,$5E + .byte $23,$28,$5D,$5E + .byte $02,$03,$17,$D7 + .byte $FF diff --git a/graphics/gr/boxes/boxes_good.s b/graphics/gr/boxes/boxes_good.s new file mode 100644 index 00000000..2ea67582 --- /dev/null +++ b/graphics/gr/boxes/boxes_good.s @@ -0,0 +1,119 @@ +; make pictures by drawing boxes + +; 223 -- initial +; 220 -- update end +; 219 -- store color already multiplied by 17 +; 215 -- load Y0 directly into X +; 211 -- load X1 directly into H2 +; 208 -- add subroutine to read byte into A, no need to save Y +; 205 -- optimize end loop +; 197 -- only update color if changed + +.include "zp.inc" +.include "hardware.inc" + +X0 = $F0 +Y1 = $F3 + + +;1DEFFNP(X)=PEEK(2054+I*5+X)-32: +;GR:POKE49234,0: +;FORI=0TO29:COLOR=FNP(0):FORY=FNP(3)TOFNP(4) +;:HLINFNP(1),FNP(2)ATY:NEXTY,I:GETA + + + ;================================ + ; Clear screen and setup graphics + ;================================ +boxes: + + jsr SETGR ; set lo-res 40x40 mode + bit FULLGR ; make it 40x48 + +draw_box_loop: + + ; get color + + jsr load_byte + bmi use_old_color + cmp #$7F +end: + beq end ; hit end + + jsr SETCOL + + jsr load_byte ; Y0 + +use_old_color: + and #$3f + tax + + jsr load_byte ; Y1 + sta Y1 + + jsr load_byte ; X0 + sta X0 + + jsr load_byte ; X1 + sta H2 + +inner_loop: + + ;; HLINE Y,H2 at A + ;; X left alone, carry set on exit + ;; H2 left alone + ;; Y and A trashed + + ldy X0 + txa + jsr HLINE + + cpx Y1 + inx + bcc inner_loop + bcs draw_box_loop + + +load_byte: + inc load_byte_smc+1 ; assume we are always < 256 bytes + ; so no need to wrap +load_byte_smc: + lda box_data-1 + + rts + + + ; 4 6 6 6 6 +box_data: + + .byte $0F,$00,$2F,$00,$27 + .byte $08,$01,$2B,$0A,$1B + .byte $0D,$28,$29,$03,$14 + .byte $A4,$27,$03,$16 + .byte $A0,$23,$05,$17 + .byte $9C,$1F,$08,$18 + .byte $08,$23,$26,$07,$0E + .byte $A4,$27,$08,$12 + .byte $9F,$1F,$0D,$12 + .byte $05,$2A,$2B,$03,$14 + .byte $AC,$2D,$06,$13 + .byte $08,$2C,$2D,$14,$17 + .byte $88,$16,$1C,$1C + .byte $0D,$02,$1A,$09,$18 + .byte $08,$04,$18,$0A,$15 + .byte $00,$06,$17,$0B,$14 + .byte $08,$15,$29,$22,$22 + .byte $93,$28,$22,$24 + .byte $05,$13,$14,$1C,$23 + .byte $95,$16,$1B,$21 + .byte $0D,$17,$2B,$19,$21 + .byte $00,$18,$20,$1A,$20 + .byte $A2,$2A,$1A,$20 + .byte $05,$1C,$1C,$1B,$20 + .byte $A6,$26,$1B,$20 + .byte $03,$1F,$20,$1F,$1F + .byte $A9,$2A,$1F,$1F + .byte $05,$19,$1E,$1D,$1E + .byte $A3,$28,$1D,$1E + .byte $0C,$02,$03,$17,$17 + .byte $7F diff --git a/graphics/gr/boxes/make_boxes.c b/graphics/gr/boxes/make_boxes.c index a097c477..54e60dc7 100644 --- a/graphics/gr/boxes/make_boxes.c +++ b/graphics/gr/boxes/make_boxes.c @@ -9,6 +9,8 @@ int main(int argc, char **argv) { int out_ptr=0; int old_color=0xff; +#if 0 + while(1) { ptr=fgets(buffer,1024,stdin); @@ -42,5 +44,28 @@ int main(int argc, char **argv) { // printf("%s\n",output); printf("\t.byte $FF\n"); +#endif + + + + + while(1) { + + ptr=fgets(buffer,1024,stdin); + if (ptr==NULL) break; + + sscanf(buffer,"%d %d %d %d %d", + &color,&x1,&x2,&y1,&y2); + + printf("\t.byte $%02X,$%02X,$%02X,$%02X\n", + y1,y2, + ((color&0x03)<<6)|x1, + ((color&0x0c)<<4)|x2); + + + } + printf("\t.byte $FF\n"); + + return 0; }