second: work on animation

This commit is contained in:
Vince Weaver 2023-10-28 01:28:48 -04:00
parent 167373cd5e
commit 0e15f04fda
8 changed files with 372 additions and 18 deletions

View File

@ -11,12 +11,13 @@ all: NUTS
####
NUTS: nuts.o
ld65 -o NUTS nuts.o -C $(LINKER_SCRIPTS)/apple2_6000.inc
ld65 -o NUTS nuts.o -C $(LINKER_SCRIPTS)/apple2_8000.inc
nuts.o: nuts.s \
../zx02_optim.s \
../zp.inc ../hardware.inc ../qload2.inc \
graphics/fc_iipix.hgr.zx02
graphics/fc_iipix.hgr.zx02 \
graphics/ship_sprites.inc
ca65 -o nuts.o nuts.s -l nuts.lst
###

View File

@ -3,9 +3,20 @@ include ../../../../Makefile.inc
ZX02 = ~/research/6502_compression/zx02.git/build/zx02
PNG_TO_HGR = ../../../../utils/hgr-utils/png2hgr
PNG2GR = ../../../../utils/gr-utils/png2gr
HGR_SPRITE = ../../../../utils/hgr-utils/hgr_make_sprite
all: nuts4.hgr.zx02 nuts_pg.hgr.zx02 nuts_blue.hgr.zx02 \
fc_grey.hgr.zx02 fc_iipix.hgr.zx02
fc_grey.hgr.zx02 fc_iipix.hgr.zx02 ship_sprites.inc
####
ship_sprites.inc: ship_sprites.png
$(HGR_SPRITE) -s -l small_ship_sprite ship_sprites.png 14 7 27 13 > ship_sprites.inc
$(HGR_SPRITE) -s -l medium_ship_sprite ship_sprites.png 14 21 41 36 >> ship_sprites.inc
$(HGR_SPRITE) -s -l large_ship_sprite ship_sprites.png 14 49 69 81 >> ship_sprites.inc
####

Binary file not shown.

After

Width:  |  Height:  |  Size: 906 B

View File

@ -0,0 +1,54 @@
; special case
;=========================================================
; hgr copy from $A000/$8000 to current DRAW_PAGE
;=========================================================
; would be faster if we unroll it, but much bigger
; old numbers
; 14+ ((14*256)+20)*32 + 5 = 115347 = 8.6fps
; theoretical unrolled, 30*6 bytes bigger (180 bytes?)
; 2 + ((9*32)+5)*256 + 5 = 75015 = 13.3 fps
hgr_copy:
; copy from in A ($80/$A0)
sta hgr_copy_smc+2 ; 4
clc
adc #$20
sta hgr_copy_end_smc+1
; lda #$A0 ; 2
ldx #0 ; 2
lda DRAW_PAGE
clc
adc #$20
sta hgr_copy_smc+5 ; 4
hgr_copy_column:
hgr_copy_smc:
lda $8000,X ; 4
sta $2000,X ; 5
dex ; 2
bne hgr_copy_column ; 2nt/3t
inc hgr_copy_smc+2 ; 6
inc hgr_copy_smc+5 ; 6
lda hgr_copy_smc+2 ; 4
hgr_copy_end_smc:
cmp #$C0 ; 2
bne hgr_copy_column ; 2/3
rts ; 6

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

@ -31,9 +31,9 @@ load_loop:
lda #0
jsr hgr_page1_clearscreen
jsr hgr_page2_clearscreen
; jsr hgr_make_tables
bit PAGE2
; fc logo
@ -41,11 +41,63 @@ load_loop:
sta zx_src_l+1
lda #>fc_iipix_data
sta zx_src_h+1
lda #$20
lda #$60
jsr zx02_full_decomp
jsr wait_until_keypress
lda #0
sta COUNT
sta DRAW_PAGE
ship_sprite_loop:
lda #$60
jsr hgr_copy
ldx COUNT
lda ship_coords_x,X
cmp #$FF
beq done_ship_sprite_loop
sta SPRITE_X
lda ship_coords_y,X
sta SPRITE_Y
lda ship_size,X
tax
lda ship_lookup_low,X
sta INL
lda ship_lookup_high,X
sta INH
jsr hgr_draw_sprite_big
lda DRAW_PAGE
beq ship_sprite_flip
lda #0
sta DRAW_PAGE
bit PAGE2
jmp done_ship_sprite_flip
ship_sprite_flip:
lda #$20
sta DRAW_PAGE
bit PAGE1
done_ship_sprite_flip:
; jsr wait_until_keypress
inc COUNT
bne ship_sprite_loop ; bra
done_ship_sprite_loop:
bit PAGE1
; nuts4 logo
lda #<nuts4_data
@ -65,10 +117,36 @@ nuts_done:
.include "../zx02_optim.s"
; .include "../hgr_table.s"
.include "../hgr_clear_screen.s"
.include "hgr_sprite_big.s"
.include "hgr_copy_fast.s"
fc_iipix_data:
.incbin "graphics/fc_iipix.hgr.zx02"
nuts4_data:
.incbin "graphics/nuts4.hgr.zx02"
.include "graphics/ship_sprites.inc"
ship_coords_x:
.byte 28, 28, 28, 27, 26, 25, 24
.byte 23, 22, 21, 20, 19, 18
.byte 16, 14, 12, 10, 7, 3, 0,$FF
ship_coords_y:
.byte 91, 97 ,103,109,111,112,112
.byte 108,113,110,108,107,106
.byte 102,101, 95, 85, 77, 68,59
ship_size:
.byte 0,0,0,0,0,0,0
.byte 1,1,1,1,1,1
.byte 2,2,2,2,2,2,2
ship_lookup_low:
.byte <small_ship_sprite,<medium_ship_sprite,<large_ship_sprite
ship_lookup_high:
.byte >small_ship_sprite,>medium_ship_sprite,>large_ship_sprite

View File

@ -136,16 +136,16 @@ load_loop:
;=======================
; run NUTS
;============================================
; copy NUTS from AUX $2000 to MAIN $6000
; copy NUTS from AUX $2000 to MAIN $8000
lda #$20 ; AUX src $2000
ldy #$60 ; MAIN dest $6000
ldy #$80 ; MAIN dest $8000
ldx #32 ; 32 pages
jsr copy_aux_main
; run nuts
jsr $6000
jsr $8000
;=======================

View File

@ -140,10 +140,11 @@ SCENE_COUNT = $EC
STATE = $ED
OFFSET = $EF
IRQ_COUNTDOWN = $F0
;LASTKEY = $F1
;PADDLE_STATUS = $F2
; COMMON DON'T USE
IRQ_COUNTDOWN = $F0
COUNT = $F1
SPRITETEMP = $F2
XPOS = $F3
@ -163,8 +164,7 @@ OUTH = $FF
; tunnel
RR = $F0
COUNT = $F1
XX = $F2
MINUSXX = $F3
YY = $F4
@ -173,12 +173,17 @@ D = $F6
R = $F7
CX = $F8
CY = $F9
RR = $FA
; Credits
BACKUP_OUTL = $F1
BACKUP_OUTH = $F2
BACKUP_OUTL = $F2
BACKUP_OUTH = $F3
; Nuts/ operner
SPRITE_Y = $F2
SPRITE_X = $F3
CURRENT_ROW = $F4