From 4305eedcd20f5ed55a72e2aec395171c76a971d0 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Thu, 2 Jun 2022 15:08:58 -0400 Subject: [PATCH] gr: stars: see if it will fit in 128 bytes short answer is no --- graphics/gr/sprite/Makefile | 16 ++- graphics/gr/sprite/stars_128.s | 224 ++++++++++++++++++++++++++++++++ linker_scripts/apple2_60_zp.inc | 12 ++ linker_scripts/apple2_70_zp.inc | 2 +- 4 files changed, 250 insertions(+), 4 deletions(-) create mode 100644 graphics/gr/sprite/stars_128.s create mode 100644 linker_scripts/apple2_60_zp.inc diff --git a/graphics/gr/sprite/Makefile b/graphics/gr/sprite/Makefile index e68b7e02..2d4d098f 100644 --- a/graphics/gr/sprite/Makefile +++ b/graphics/gr/sprite/Makefile @@ -12,12 +12,13 @@ all: star.dsk $(DOS33): cd ../../../utils/dos33fs-utils && make -star.dsk: $(DOS33) HELLO STAR STARS STARS_BOT +star.dsk: $(DOS33) HELLO STAR STARS STARS_BOT STARS_128 cp $(EMPTY_DISK)/empty.dsk star.dsk $(DOS33) -y star.dsk SAVE A HELLO $(DOS33) -y star.dsk BSAVE -a 0xc00 STAR $(DOS33) -y star.dsk BSAVE -a 0xc00 STARS $(DOS33) -y star.dsk BSAVE -a 0x36B STARS_BOT + $(DOS33) -y star.dsk BSAVE -a 0x60 STARS_128 ### @@ -51,6 +52,15 @@ stars_bot.o: stars_bot.s ### -clean: - rm -f *~ *.o *.lst HELLO STAR STARS STARS_BOT +STARS_128: stars_128.o + ld65 -o STARS_128 stars_128.o -C $(LINKERSCRIPTS)/apple2_60_zp.inc + +stars_128.o: stars_128.s + ca65 -o stars_128.o stars_128.s -l stars_128.lst + + +### + +clean: + rm -f *~ *.o *.lst HELLO STAR STARS STARS_BOT STARS_128 diff --git a/graphics/gr/sprite/stars_128.s b/graphics/gr/sprite/stars_128.s new file mode 100644 index 00000000..9e0292dd --- /dev/null +++ b/graphics/gr/sprite/stars_128.s @@ -0,0 +1,224 @@ +; bouncing stars (128B version) + +; by Vince `deater` Weaver + +; 138 bytes -- starting with bot version +; 135 bytes -- make addresses zero page + +SPEAKER = $C030 +SET_GR = $C050 +SET_TEXT = $C051 +FULLGR = $C052 +PAGE1 = $C054 +PAGE2 = $C055 +LORES = $C056 ; Enable LORES graphics + +HGR2 = $F3D8 +PLOT = $F800 ; PLOT AT Y,A (A colors output, Y preserved) +GBASCALC = $F847 ; Y in A, put addr in GBASL/GBASH (what is C?) +SETGR = $FB40 +WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us + +GBASL = $26 +GBASH = $27 + +YPOS = $56 +XPOS = $57 +PO = $58 +FRAME = $5D +;PAGE = $5E + + +.zeropage +.globalzp bounce +.globalzp bitmap +.globalzp bg_smc + + + +stars: + bit SET_GR ; switch to lo-res mode + bit FULLGR ; set full screen + +main_loop: + + + ;====================== + ; flip page + ;====================== + +page_smc: + lda #0 ; 0 or 1 + + tax + ldy PAGE1,X ; flip page + + eor #$1 ; invert (leaving in A) + + sta page_smc+1 ; save PAGE value (PAGE in A here) + + + asl ; make OUTH $4 or $8 depending on value in PAGE + ; which we have in A above or at end of loop + asl ; (this also sets C to 0) + adc #4 + + sta GBASH + + inc FRAME ; increment frame # + lda FRAME + and #$1f ; cycle colors ever 32 frames + bne no_color_cycle + + inc bg_smc+1 + +no_color_cycle: + + lda #100 ; pause a bit + jsr WAIT + + sta GBASL ; A is 0 + + + ;================================= + ; clear lo-res screen, page1/page2 + ;================================= + ; proper with avoiding screen holes is ~25 instructions + ; this is more like 16 + ; assume GBASL/GBASH already points to proper $400 or $800 + + ldx #4 ; lores is 1k, so 4 pages +full_loop: + ldy #$00 ; clear whole page +bg_smc: + lda #$54 ; color +inner_loop: + sta (GBASL),Y + dey + bne inner_loop + + inc GBASH ; point to next page + dex + bne full_loop + + ; X=0 + ; Y=0 + ; A=color + + ;==================== + ; draw the stars + ;==================== + + lda #32 ; start from right to save a byte + + ;====================== + ; draw 8x8 bitmap star + ;====================== + ; A is XPOS on entry +draw_star: + + ; calculate YPOS + sta XPOS + + lsr ; make middle star offset+4 from others + lsr + + adc FRAME ; look up bounce amount + and #$7 + tax + lda bounce,X + sta YPOS + + + ldx #7 ; draw 7 lines +boxloop: + txa + clc + adc YPOS + jsr GBASCALC ; calc address of line in X (Y-coord) + + ; GBASL is in A at this point + ; is C always 0? + +; clc + adc XPOS ; adjust to X-coord + sta GBASL + + ; adjust for proper page + + lda page_smc+1 ; want to add 0 or 4 (not 0 or 1) + asl + asl ; this sets C to 0 + adc GBASH + sta GBASH + + ;================= + ; draw line + + + ldy #7 ; 8-bits wide + lda bitmap,X ; get low bit of bitmap into carry +draw_line_loop: + lsr + + pha + + bcc its_transparent + + lda #$dd ; yellow + sta (GBASL),Y ; draw on screen +its_transparent: + + pla + + dey + bpl draw_line_loop + + dex + bpl boxloop + + lda XPOS ; move to next position + ; going right to left saves 2 bytes for cmp + sec + sbc #16 + + ; X is $FF here + ; Y is $FF here + ; A is -16 here + + bpl draw_star + bmi main_loop + + + + + + +;================= +; star bitmap +;================= + +;012|456| +; @ ; +; @@ ; +; @@@@@ ; +;@@@@@@@ ; +; @@@@@ ; +; @@@@@ ; +; @@ @@ ; +;@@ @@ ; + +bitmap: + .byte $10 + .byte $18 + .byte $1f + .byte $fe + .byte $7c + .byte $3e + .byte $66 + .byte $C3 + +bounce: + .byte 10,11,12,13,13,12,11,10 + + diff --git a/linker_scripts/apple2_60_zp.inc b/linker_scripts/apple2_60_zp.inc new file mode 100644 index 00000000..076e792d --- /dev/null +++ b/linker_scripts/apple2_60_zp.inc @@ -0,0 +1,12 @@ +MEMORY { + ZP: start = $60, size = $90, type = rw; + RAM: start = $60, size = $8E00, file = %O; +} + +SEGMENTS { +CODE: load = RAM, type = ro; +#RODATA: load = RAM, type = ro; +#DATA: load = RAM, type = rw; +#BSS: load = RAM, type = bss, define = yes; +ZEROPAGE: load = ZP, type = ro; +} diff --git a/linker_scripts/apple2_70_zp.inc b/linker_scripts/apple2_70_zp.inc index 9737f2d1..2adba2d7 100644 --- a/linker_scripts/apple2_70_zp.inc +++ b/linker_scripts/apple2_70_zp.inc @@ -4,7 +4,7 @@ MEMORY { } SEGMENTS { -#CODE: load = RAM, type = ro; +CODE: load = RAM, type = ro; #RODATA: load = RAM, type = ro; #DATA: load = RAM, type = rw; #BSS: load = RAM, type = bss, define = yes;