diff --git a/graphics/gr/sprite/Makefile b/graphics/gr/sprite/Makefile index 9d4b5178..26e0c764 100644 --- a/graphics/gr/sprite/Makefile +++ b/graphics/gr/sprite/Makefile @@ -12,10 +12,11 @@ all: star.dsk $(DOS33): cd ../../../utils/dos33fs-utils && make -star.dsk: $(DOS33) HELLO STAR +star.dsk: $(DOS33) HELLO STAR STARS 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 ### @@ -32,6 +33,15 @@ star.o: star.s ### +STARS: stars.o + ld65 -o STARS stars.o -C $(LINKERSCRIPTS)/apple2_c00.inc + +stars.o: stars.s + ca65 -o stars.o stars.s -l stars.lst + + +### + STAR_BOT: star_bot.o ld65 -o STAR_BOT star_bot.o -C $(LINKERSCRIPTS)/apple2_36b.inc diff --git a/graphics/gr/sprite/star.s b/graphics/gr/sprite/star.s index cb96799f..b39550fe 100644 --- a/graphics/gr/sprite/star.s +++ b/graphics/gr/sprite/star.s @@ -1,7 +1,12 @@ -; star +; bouncing star ; by Vince `deater` Weaver +; 135 -- original +; 122 -- clear screen w/o consideration of screen holes +; 121 -- try to optimize the rotate in the sprite +; 119 -- draw transparent + SPEAKER = $C030 SET_GR = $C050 SET_TEXT = $C051 @@ -21,6 +26,7 @@ GBASH = $27 OUTL = $74 OUTH = $75 +YPOS = $76 FRAME = $6D PAGE = $6E @@ -41,8 +47,9 @@ star: bit FULLGR ; set FULL 48x40 + ; A should be 0 here main_loop: - sta PAGE ; start at page 1 + sta PAGE ; 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 @@ -56,59 +63,40 @@ main_loop: inc FRAME - ;============================ - ; clear screen - ;============================ + ;================================= + ; clear lo-res screen, page1/page2 + ;================================= + ; proper with avoiding screen holes is ~25 instructions + + ldx #4 full_loop: - ldx #3 - -line_loop: - ldy #119 - -screen_loop: - - tya ; extrapolate X from Y - - lda #$44 - -;inner_loop_smc: - + ldy #$00 +inner_loop: + lda #$55 ; color sta (OUTL),Y - dey - bpl screen_loop - - ; move to next line by adding $80 - ; we save a byte by using EOR instead - - lda OUTL - eor #$80 ; add $80 - sta OUTL - - bne line_loop - - ; we overflowed, so increment OUTH + bne inner_loop inc OUTH - dex - bpl line_loop - - ;============================ - ; end clear screen - ;============================ - - -done_bg: + bne full_loop ;====================== ; draw 8x8 bitmap ;====================== + lda FRAME + and #$7 + tax + lda bounce,X + sta YPOS + ldx #7 boxloop: txa + clc + adc YPOS jsr GBASCALC ; calc address of X ; note we center to middle of screen ; by noting the middle 8 lines @@ -117,9 +105,10 @@ boxloop: ; GBASL is in A at this point clc - adc #12+$28 - sta GBASL ; center x-coord and y-coord at same time + adc #16 + sta GBASL ; center x-coord + ; adjust for proper page lda PAGE ; want to add 0 or 4 (not 0 or 1) asl @@ -127,22 +116,20 @@ boxloop: adc GBASH sta GBASH - ldy #7 + lda bitmap,X ; get low bit of bitmap into carry draw_line_loop: - - lda bitmap,X ; get low bit of bitmap2 into carry lsr - lda #$00 ; black is default color + pha - ror bitmap,X ; 16-bit rotate (in memory) - - bcc its_black + bcc its_transparent lda #$dd ; yellow -its_black: - sta (GBASL),Y ; partway down screen + sta (GBASL),Y ; draw on screen +its_transparent: + + pla dey bpl draw_line_loop @@ -150,6 +137,7 @@ its_black: dex bpl boxloop + ;====================== ; switch page ;====================== @@ -186,3 +174,5 @@ bitmap: .byte $66 .byte $C3 +bounce: + .byte 10,11,12,13,13,12,11,10 diff --git a/graphics/gr/sprite/star_noholes.s b/graphics/gr/sprite/star_noholes.s new file mode 100644 index 00000000..aed2d722 --- /dev/null +++ b/graphics/gr/sprite/star_noholes.s @@ -0,0 +1,199 @@ +; star + +; by Vince `deater` Weaver + +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 +SETGR = $FB40 +WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us + +GBASL = $26 +GBASH = $27 + +OUTL = $74 +OUTH = $75 +YPOS = $76 + +FRAME = $6D +PAGE = $6E +LINE = $6F + +pattern1 = $d000 ; location in memory + +;.zeropage +;.globalzp pattern_smc + + +star: + + jsr SETGR ; set LORES + + lda #0 + sta OUTL + + bit FULLGR ; set FULL 48x40 + +main_loop: + sta PAGE ; start at page 1 + + asl ; make OUTH $4 or $8 depending on value in PAGE + ; which we have in A above or at end of loop + asl ; C is 0 + adc #4 + + sta OUTH + + lda #100 + jsr WAIT + + inc FRAME + + ;============================ + ; clear screen + ;============================ +full_loop: + ldx #3 + +line_loop: + ldy #119 + +screen_loop: + + tya ; extrapolate X from Y + + lda #$44 + +;inner_loop_smc: + + sta (OUTL),Y + + dey + bpl screen_loop + + ; move to next line by adding $80 + ; we save a byte by using EOR instead + + lda OUTL + eor #$80 ; add $80 + sta OUTL + + bne line_loop + + ; we overflowed, so increment OUTH + + inc OUTH + + dex + bpl line_loop + + ;============================ + ; end clear screen + ;============================ + + +done_bg: + + + ;====================== + ; draw 8x8 bitmap + ;====================== + + lda FRAME + and #$7 + tax + lda bounce,X + sta YPOS + + ldx #7 +boxloop: + txa + clc + adc YPOS + jsr GBASCALC ; calc address of X + ; note we center to middle of screen + ; by noting the middle 8 lines + ; are offset by $28 from first 8 lines + + ; GBASL is in A at this point + + clc + adc #12 + sta GBASL ; center x-coord and y-coord at same time + + + lda PAGE ; want to add 0 or 4 (not 0 or 1) + asl + asl ; this sets C to 0 + adc GBASH + sta GBASH + + + ldy #7 +draw_line_loop: + + lda bitmap,X ; get low bit of bitmap2 into carry + lsr + + lda #$00 ; black is default color + + ror bitmap,X ; 16-bit rotate (in memory) + + bcc its_black + + lda #$dd ; yellow +its_black: + sta (GBASL),Y ; partway down screen + + dey + bpl draw_line_loop + + dex + bpl boxloop + + ;====================== + ; switch page + ;====================== + + lda PAGE + + tax + ldy PAGE1,X ; flip page + + eor #$1 + + bpl main_loop ; bra + + +; 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/graphics/gr/sprite/stars.s b/graphics/gr/sprite/stars.s new file mode 100644 index 00000000..e534330c --- /dev/null +++ b/graphics/gr/sprite/stars.s @@ -0,0 +1,215 @@ +; bouncing stars + +; by Vince `deater` Weaver + +; 119 bytes -- single star original +; 143 bytes -- three stars +; 141 bytes -- optimize init +; 140 bytes -- 0 is already in X +; 143 bytes -- stars move independently +; 140 bytes -- optimize XPOS in multiple calls to draw_stars + +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 +SETGR = $FB40 +WAIT = $FCA8 ; delay 1/2(26+27A+5A^2) us + +GBASL = $26 +GBASH = $27 + +OUTL = $74 +OUTH = $75 +YPOS = $76 +XPOS = $77 + +FRAME = $6D +PAGE = $6E +LINE = $6F + +;.zeropage +;.globalzp pattern_smc + + +stars: + jsr HGR2 ; sets graphics/full-screen/hires/PAGE2 + ; sets A and Y to 0 + + bit LORES ; switch to lo-res mode + + sta OUTL ; store 0 to OUTL + + ; A should be 0 here +main_loop: + sta PAGE ; 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 ; C is 0 + adc #4 + + sta OUTH + + lda #100 ; pause a bit + jsr WAIT + + inc FRAME ; increment frame # + + ;================================= + ; clear lo-res screen, page1/page2 + ;================================= + ; proper with avoiding screen holes is ~25 instructions + + ldx #4 ; lores is 1k, so 4 pages +full_loop: + ldy #$00 ; clear whole page + lda #$55 ; color +inner_loop: + sta (OUTL),Y + dey + bne inner_loop + + inc OUTH ; point to next page + dex + bne full_loop + + + ;==================== + ; draw the stars + ;==================== + + txa ; X is zero here +; lda #0 +; sta XPOS + + jsr draw_star + jsr draw_star + jsr draw_star + + ;====================== + ; flip page + ;====================== + + lda PAGE + + tax + ldy PAGE1,X ; flip page + + eor #$1 ; invert (leaving in A) + + bpl main_loop ; bra + + + + + ;====================== + ; draw 8x8 bitmap star + ;====================== + ; A is XPOS on entry +draw_star: + + ; calculate YPOS + sta XPOS + +; lda XPOS + lsr ; make middle star offset+4 from others + lsr + + adc FRAME + 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 + + clc + adc XPOS ; adjust to X-coord + sta GBASL + + ; adjust for proper page + + lda PAGE ; 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 + clc + adc #16 +; sta XPOS + + rts + + +; 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 + + ; for apple II bot + + jmp stars