xmas2023: add snowflakes

This commit is contained in:
Vince Weaver 2023-12-23 23:56:36 -05:00
parent 466bd49ec4
commit 46da45ccb7
9 changed files with 446 additions and 4 deletions

View File

@ -126,7 +126,7 @@ XMAS: xmas.o
xmas.o: xmas.s plasma_tree.s fireplace.s \
zp.inc hardware.inc qload.inc \
vapor_lock.s gr_scroll.s draw_blocks.s \
regular_tree.s \
regular_tree.s snowflakes.s \
graphics/merry.hgr.zx02 \
graphics/tree01.gr.zx02 \
graphics/greets.raw.zx02

View File

@ -7,6 +7,8 @@ fireplace_restart:
sta FRAMEL
sta FRAMEH
bit LORES
bit PAGE2
lda #4
@ -419,7 +421,7 @@ frame_noflo2:
no_music2:
lda FRAMEH
cmp #2
cmp #1
beq totally_done_fireplace
done_music2:

View File

@ -3,6 +3,7 @@ include ../../../Makefile.inc
ZX02 = ~/research/6502_compression/zx02.git/build/zx02 -f
PNG_TO_HGR = ../../../utils/hgr-utils/png2hgr
PNG2GR = ../../../utils/gr-utils/png2gr
HGR_SPRITE = ../../../utils/hgr-utils/hgr_make_sprite
all: tree01.gr.zx02 tree03.gr.zx02 \
tree05.gr.zx02 tree07.gr.zx02 \
@ -12,11 +13,17 @@ all: tree01.gr.zx02 tree03.gr.zx02 \
tree06.gr.zx02 tree08.gr.zx02 \
tree10.gr.zx02 tree12.gr.zx02 \
tree14.gr.zx02 tree16.gr.zx02 \
merry.hgr.zx02 \
merry.hgr.zx02 snow.inc \
greets.raw.zx02 credits.raw.zx02
####
snow.inc: snow_sprite.png
$(HGR_SPRITE) -s -l snow_sprite snow_sprite.png 0 0 41 23 > snow.inc
###
greets.raw.zx02: greets.raw
$(ZX02) greets.raw greets.raw.zx02

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -0,0 +1,89 @@
hgr_clear_screen:
lda DRAW_PAGE
beq hgr_page1_clearscreen
lda #0
beq hgr_page2_clearscreen
hgr_page1_clearscreen:
ldy #0
hgr_page1_cls_loop:
sta $2000,Y
sta $2100,Y
sta $2200,Y
sta $2300,Y
sta $2400,Y
sta $2500,Y
sta $2600,Y
sta $2700,Y
sta $2800,Y
sta $2900,Y
sta $2A00,Y
sta $2B00,Y
sta $2C00,Y
sta $2D00,Y
sta $2E00,Y
sta $2F00,Y
sta $3000,Y
sta $3100,Y
sta $3200,Y
sta $3300,Y
sta $3400,Y
sta $3500,Y
sta $3600,Y
sta $3700,Y
sta $3800,Y
sta $3900,Y
sta $3A00,Y
sta $3B00,Y
sta $3C00,Y
sta $3D00,Y
sta $3E00,Y
sta $3F00,Y
iny
bne hgr_page1_cls_loop
rts
hgr_page2_clearscreen:
ldy #0
hgr_page2_cls_loop:
sta $4000,Y
sta $4100,Y
sta $4200,Y
sta $4300,Y
sta $4400,Y
sta $4500,Y
sta $4600,Y
sta $4700,Y
sta $4800,Y
sta $4900,Y
sta $4A00,Y
sta $4B00,Y
sta $4C00,Y
sta $4D00,Y
sta $4E00,Y
sta $4F00,Y
sta $5000,Y
sta $5100,Y
sta $5200,Y
sta $5300,Y
sta $5400,Y
sta $5500,Y
sta $5600,Y
sta $5700,Y
sta $5800,Y
sta $5900,Y
sta $5A00,Y
sta $5B00,Y
sta $5C00,Y
sta $5D00,Y
sta $5E00,Y
sta $5F00,Y
iny
bne hgr_page2_cls_loop
rts

View File

@ -0,0 +1,18 @@
hgr_page_flip:
lda DRAW_PAGE
beq flip_to_page1
flip_to_page2:
bit PAGE2
lda #0
beq done_hgr_page_flip ; bra
flip_to_page1:
bit PAGE1
lda #$20
done_hgr_page_flip:
sta DRAW_PAGE
rts

View File

@ -0,0 +1,205 @@
;===========================================
; hgr draw sprite (only at 7-bit boundaries)
;===========================================
; can handle sprites bigger than a 256 byte page
; Note this is optimized for blue/orange sprites
; it treats black0 as transparent
; SPRITE in INL/INH
; Location at SPRITE_X SPRITE_Y
; xsize, ysize in first two bytes
; sprite AT INL/INH
; orange = color5 1 101 0101 1 010 1010
hgr_draw_sprite_big:
lda SPRITE_X
ror
bcs hgr_draw_sprite_big_odd
hgr_draw_sprite_big_even:
ldy #0
lda (INL),Y ; load xsize
clc
adc SPRITE_X
sta big_sprite_width_end_smc+1 ; self modify for end of line
iny ; load ysize
lda (INL),Y
sta big_sprite_ysize_smc+1 ; self modify
; point smc to sprite
lda INL ; 16-bit add
sta big_sprite_smc1+1
lda INH
sta big_sprite_smc1+2
ldx #0 ; X is pointer offset
stx CURRENT_ROW ; actual row
ldx #2
hgr_big_sprite_yloop:
lda CURRENT_ROW ; row
clc
adc SPRITE_Y ; add in cursor_y
; calc GBASL/GBASH
tay ; get output ROW into GBASL/H
lda hposn_low,Y
sta GBASL
lda hposn_high,Y
clc
adc DRAW_PAGE
sta GBASH
ldy SPRITE_X
big_sprite_inner_loop:
big_sprite_smc1:
lda $f000,X ; load sprite data
beq big_sprite_transparent
sta (GBASL),Y ; store to screen
big_sprite_transparent:
inx ; increment sprite offset
; if > 1 page
bne big_sprite_no_page_cross
inc big_sprite_smc1+2
big_sprite_no_page_cross:
iny ; increment output position
big_sprite_width_end_smc:
cpy #6 ; see if reached end of row
bne big_sprite_inner_loop ; if not, loop
inc CURRENT_ROW ; row
lda CURRENT_ROW ; row
big_sprite_ysize_smc:
cmp #31 ; see if at end
bne hgr_big_sprite_yloop ; if not, loop
rts
hgr_draw_sprite_big_odd:
ldy #0
lda (INL),Y ; load xsize
clc
adc SPRITE_X
sta osprite_width_end_smc+1 ; self modify for end of line
iny ; load ysize
lda (INL),Y
sta osprite_ysize_smc+1 ; self modify
; point smc to sprite
lda INL ; 16-bit add
sta osprite_smc1+1
lda INH
sta osprite_smc1+2
ldx #0 ; X is pointer offset
stx CURRENT_ROW ; actual row
ldx #2
ohgr_sprite_yloop:
lda CURRENT_ROW ; row
clc
adc SPRITE_Y ; add in cursor_y
; calc GBASL/GBASH
tay ; get output ROW into GBASL/H
lda hposn_low,Y
sta GBASL
lda hposn_high,Y
clc
adc DRAW_PAGE
sta GBASH
ldy SPRITE_X
clc
php ; store 0 carry on stack
osprite_inner_loop:
osprite_smc1:
lda $f000,X ; load sprite data
bne osprite_not_transparent
; we can't just skip if 0 because we might shift a bit in
; from previous byte
plp
bcs osprite_oops
clc
php
bcc osprite_transparent_done
osprite_not_transparent:
plp ; restore carry from last
osprite_oops:
rol ; rotate in carry
asl ; one more time, bit6 in carry
php ; save on stack
sec ; assume blur/orange
ror ; rotate it back down
sta (GBASL),Y ; store to screen
osprite_transparent_done:
inx ; increment sprite offset
; if > 1 page
bne osprite_no_page_cross
inc osprite_smc1+2
osprite_no_page_cross:
iny ; increment output position
osprite_width_end_smc:
cpy #6 ; see if reached end of row
bne osprite_inner_loop ; if not, loop
plp ; restore stack
inc CURRENT_ROW ; row
lda CURRENT_ROW ; row
osprite_ysize_smc:
cmp #31 ; see if at end
bne ohgr_sprite_yloop ; if not, loop
rts

View File

@ -0,0 +1,115 @@
do_snow:
bit HIRES
bit PAGE1
lda #0
sta FRAMEL
sta FRAMEH
sta DRAW_PAGE
lda #8
sta XPOS
lda #100
sta YPOS
do_snow_loop:
;======================
; update frame count
inc FRAMEL ; 5
lda FRAMEL ; 3
and #$3f ; 2
sta FRAMEL ; 3
bne frame_noflo8 ; 2/3
inc FRAMEH ; 5
frame_noflo8:
lda KEYPRESS
bmi done_do_snow
; wait for_pattern / end
lda SOUND_STATUS
and #SOUND_MOCKINGBOARD
beq no_music8
; lda #1
; cmp current_pattern_smc+1
; bcc totally_done_fireplace
; beq totally_done_fireplace
; jmp done_music4
no_music8:
lda FRAMEH
cmp #6
beq done_do_snow
done_music8:
jsr hgr_clear_screen
; 0123456789012345678901234567890123456789
; XXXXXX XXXXXX XXXXXX
lda #2
sta SPRITE_X
ldy YPOS
lda sin2,Y
sta SPRITE_Y
lda #<snow_sprite
sta INL
lda #>snow_sprite
sta INH
jsr hgr_draw_sprite_big
lda #17
sta SPRITE_X
ldy YPOS
lda sin1,Y
sta SPRITE_Y
lda #<snow_sprite
sta INL
lda #>snow_sprite
sta INH
jsr hgr_draw_sprite_big
lda #32
sta SPRITE_X
ldy YPOS
lda sin2,Y
sta SPRITE_Y
lda #<snow_sprite
sta INL
lda #>snow_sprite
sta INH
jsr hgr_draw_sprite_big
jsr hgr_page_flip
; lda #128
; jsr wait
inc YPOS
; lda YPOS
; cmp #150
; bcc ypos_ok
; lda #100
; sta YPOS
;ypos_ok:
jmp do_snow_loop
done_do_snow:
rts
.include "hgr_sprite_big.s"
.include "hgr_clear_screen.s"
.include "hgr_page_flip.s"
.include "graphics/snow.inc"

View File

@ -40,6 +40,12 @@ repeat:
jsr plasma_tree
;======================================
; snowflakes
;======================================
jsr do_snow
;======================================
; fireplace without vapor lock
@ -58,4 +64,4 @@ finished:
.include "plasma_tree.s"
.include "fireplace.s"
.include "regular_tree.s"
.include "snowflakes.s"