sb: auto-gen sprites

This commit is contained in:
Vince Weaver 2023-03-11 22:43:40 -05:00
parent a9708b9f5b
commit 2de3dbffc5
8 changed files with 447 additions and 39 deletions

View File

@ -33,7 +33,7 @@ DUCK_POND: duck_pond.o
duck_pond.o: duck_pond.s zx02_optim.s \ duck_pond.o: duck_pond.s zx02_optim.s \
zp.inc hardware.inc \ zp.inc hardware.inc \
gr_copy.s gr_copy.s duck_score.s gr_putsprite.s
ca65 -o duck_pond.o duck_pond.s -l duck_pond.lst ca65 -o duck_pond.o duck_pond.s -l duck_pond.lst

View File

@ -43,18 +43,10 @@ duck_pond:
;=================== ;===================
; Load graphics ; TITLE SCREEN
;=================== ;===================
load_loop:
;============================= title_screen:
;==========================
; Load Image
;===========================
load_image:
lda #<title_data lda #<title_data
sta ZX0_src sta ZX0_src
@ -74,7 +66,18 @@ wait_until_keypress:
bpl wait_until_keypress ; 3 bpl wait_until_keypress ; 3
bit KEYRESET ; clear the keyboard buffer bit KEYRESET ; clear the keyboard buffer
which_ok:
;===================
; INIT GAME
;===================
init_game:
lda #0
sta D1_SCORE
sta D1_SCORE_H
sta D2_SCORE
sta D2_SCORE_H
lda #<main_data lda #<main_data
sta ZX0_src sta ZX0_src
@ -89,22 +92,80 @@ which_ok:
bit FULLGR bit FULLGR
;===================
; MAIN LOOP
;===================
main_loop:
; copy over background
; draw arm animation
; draw food
; draw duck1
; draw duck2
; draw anvil/splash
; draw score
jsr draw_score
; move food
; move arm
; move anvil
; move ducks
; drain water
; check keyboard
wait_until_keypress2: wait_until_keypress2:
lda KEYPRESS ; 4 lda KEYPRESS ; 4
bpl wait_until_keypress2 ; 3 bpl done_loop
bit KEYRESET ; clear the keyboard buffer bit KEYRESET ; clear the keyboard buffer
jmp load_loop and #$7f ; clear high bit
cmp #' ' ; don't lose space
beq was_space
and #$df ; convert lowercase to uppercase
was_space:
check_bracket:
cmp #'S'
bne done_keyboard
jsr score_inc_d1
done_keyboard:
; flip page
done_loop:
jmp main_loop
.include "zx02_optim.s" .include "zx02_optim.s"
.include "gr_copy.s" .include "gr_copy.s"
.include "gr_offsets.s" .include "gr_offsets.s"
.include "gr_putsprite.s"
.include "duck_score.s"
title_data: title_data:
.incbin "graphics/a2_duckpond_title.gr.zx02" .incbin "graphics/a2_duckpond_title.gr.zx02"
main_data: main_data:
.incbin "graphics/a2_duckpond.gr.zx02" .incbin "graphics/a2_duckpond.gr.zx02"
.include "graphics/num_sprites.inc"

132
games/sb/duck_score.s Normal file
View File

@ -0,0 +1,132 @@
draw_score:
ldy #0
lda #42
sta YPOS
ldx #10
draw_score_1_loop:
lda score_xpos,Y
sta XPOS
lda score1_l,Y
sta INL
lda score1_h,Y
sta INH
txa
pha
tya
pha
jsr gr_put_sprite
pla
tay
pla
tax
iny
dex
bne draw_score_1_loop
rts
score1_l:
.byte <d_sprite
.byte <one_sprite
.byte <colon_sprite
.byte <space_sprite
.byte <zero_sprite
score2_l:
.byte <d_sprite
.byte <two_sprite
.byte <colon_sprite
.byte <four_sprite
.byte <zero_sprite
score1_h:
.byte >d_sprite
.byte >one_sprite
.byte >colon_sprite
.byte >space_sprite
.byte >zero_sprite
score2_h:
.byte >d_sprite
.byte >two_sprite
.byte >colon_sprite
.byte >four_sprite
.byte >zero_sprite
score_xpos:
.byte 1, 5, 8,11,15
.byte 22,26,29,32,36
score_inc_d1:
lda D1_SCORE
clc
sed ; enter decimal mode
adc #1
sta D1_SCORE
lda #0 ; handle overflow to hundreds
adc D1_SCORE_H
sta D1_SCORE_H
cld ; back from decimal mode
update_d1_score:
lda D1_SCORE
and #$f
tay
lda number_sprites_l,Y
sta score1_l+4
lda number_sprites_h,Y
sta score1_h+4
lda D1_SCORE
lsr
lsr
lsr
lsr
tay
lda number_sprites_l,Y
sta score1_l+3
lda number_sprites_h,Y
sta score1_h+3
rts
number_sprites_l:
.byte <zero_sprite
.byte <one_sprite
.byte <two_sprite
.byte <three_sprite
.byte <four_sprite
.byte <five_sprite
.byte <six_sprite
.byte <seven_sprite
.byte <eight_sprite
.byte <nine_sprite
number_sprites_h:
.byte >zero_sprite
.byte >one_sprite
.byte >two_sprite
.byte >three_sprite
.byte >four_sprite
.byte >five_sprite
.byte >six_sprite
.byte >seven_sprite
.byte >eight_sprite
.byte >nine_sprite

105
games/sb/gr_putsprite.s Normal file
View File

@ -0,0 +1,105 @@
;==============
; gr_put_sprite
;==============
; Sprite to display in INH,INL
; Location is XPOS,YPOS
; Note, only works if YPOS is multiple of two
gr_put_sprite:
ldy #0 ; byte 0 is xsize ; 2
lda (INL),Y ; 5
sta CH ; xsize is in CH ; 3
iny ; 2
clc
adc XPOS
sta XMAX
lda (INL),Y ; byte 1 is ysize ; 5
sta CV ; ysize is in CV ; 3
iny ; 2
lda YPOS ; make a copy of ypos ; 3
sta TEMPY ; as we modify it ; 3
;===========
; 28
gr_put_sprite_loop:
sty TEMP ; save sprite pointer ; 3
ldy TEMPY ; 3
bpl put_sprite_raw_pos ; if < 0, skip to next
clc ; skip line in sprite too
lda TEMP
adc CH
tay
bne raw_increment_y
put_sprite_raw_pos:
psr_smc1:
cpy #48 ; bge if >= 48, done sprite
bcs raw_sprite_done
lda gr_offsets,Y ; lookup low-res memory address ; 4
clc ; 2
adc XPOS ; add in xpos ; 3
sta OUTL ; store out low byte of addy ; 3
clc ; never wraps, handle negative
lda gr_offsets+1,Y ; look up high byte ; 4
adc DRAW_PAGE ; ; 3
sta OUTH ; and store it out ; 3
ldy TEMP ; restore sprite pointer ; 3
; OUTH:OUTL now points at right place
ldx XPOS ; load xposition into x ; 3
;===========
; 34
raw_put_sprite_pixel:
lda (INL),Y ; get sprite colors ; 5
iny ; increment sprite pointer ; 2
sty TEMP ; save sprite pointer ; 3
cpx #0 ; if off-screen left, skip draw
bmi skip_drawing
cpx #40
bcs skip_drawing ; if off-screen right, skip draw
ldy #$0 ; 2
sta COLOR ; save color for later ; 3
; check if top pixel transparent
raw_put_sprite_all:
lda COLOR ; load color ; 3
sta (OUTL),Y ; and write it out ; 6
;============
; 9
raw_put_sprite_done_draw:
skip_drawing:
ldy TEMP ; restore sprite pointer ; 3
inc OUTL ; increment output pointer ; 5
inx ; increment x counter ; 2
cpx XMAX
bne raw_put_sprite_pixel ; if not done, keep looping ; 2nt/3
;==============
; 12/13
raw_increment_y:
inc TEMPY ; each line has two y vars ; 5
inc TEMPY ; 5
dec CV ; decemenet total y count ; 5
bne gr_put_sprite_loop ; loop if not done ; 2nt/3
;==============
; 17/18
raw_sprite_done:
rts ; return ; 6

View File

@ -7,9 +7,30 @@ DOS33 = ../../../utils/dos33fs-utils/dos33
EMPTY_DISK = ../../../empty_disk/empty.dsk EMPTY_DISK = ../../../empty_disk/empty.dsk
TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft
PNG2GR = ../../../utils/gr-utils/png2gr PNG2GR = ../../../utils/gr-utils/png2gr
PNG2SPRITES = ../../../utils/gr-utils/png2sprites
all: strongbad_sample.hgr.zx02 \ all: strongbad_sample.hgr.zx02 \
a2_duckpond_title.gr.zx02 a2_duckpond.gr.zx02 a2_duckpond_title.gr.zx02 a2_duckpond.gr.zx02 \
num_sprites.inc
####
num_sprites.inc: lores_font.png
$(PNG2SPRITES) lores_font.png zero_sprite 0 0 3 6 > num_sprites.inc
$(PNG2SPRITES) lores_font.png one_sprite 4 0 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png two_sprite 8 0 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png three_sprite 12 0 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png four_sprite 16 0 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png five_sprite 20 0 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png six_sprite 24 0 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png seven_sprite 28 0 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png eight_sprite 0 6 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png nine_sprite 4 6 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png colon_sprite 8 6 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png d_sprite 12 6 3 6 >> num_sprites.inc
$(PNG2SPRITES) lores_font.png space_sprite 16 6 3 6 >> num_sprites.inc
#### ####

View File

@ -127,34 +127,23 @@ CURSOR = $9D
; More zero-page addresses ; More zero-page addresses
; we try not to conflict with anything DOS, MONITOR or BASIC related ; we try not to conflict with anything DOS, MONITOR or BASIC related
;COLOR1 = $E0
;COLOR2 = $E1 D1_SCORE = $E0
;MATCH = $E2 D1_SCORE_H = $E1
XX = $E3 D2_SCORE = $E2
YY = $E4 D2_SCORE_H = $E3
HGR_COLOR = $E4
;SHIPY = $E4
;YADD = $E5
;LOOP = $E6
;MEMPTRL = $E7
;MEMPTRH = $E8
;NAMEL = $E9
;NAMEH = $EA
;NAMEX = $EB
;CHAR = $EC
STATE = $ED STATE = $ED
DISP_PAGE = $ED DISP_PAGE = $ED
DRAW_PAGE = $EE DRAW_PAGE = $EE
OFFSET = $EF OFFSET = $EF
;FIRST = $F0
LASTKEY = $F1 XPOS = $F0
PADDLE_STATUS = $F2 YPOS = $F1
XMAX = $F2
SPRITETEMP = $F2
XPOS = $F3
YPOS = $F4
TEMP = $FA TEMP = $FA
TEMPY = $FB TEMPY = $FB
INL = $FC INL = $FC

View File

@ -4,7 +4,7 @@ CFLAGS = -g -Wall -O2
all: text2gr png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 \ all: text2gr png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 \
png2sixbitmap png2six80 png2sixrle png2fourrle png2sixrle2 png_16x16 \ png2sixbitmap png2six80 png2sixrle png2fourrle png2sixrle2 png_16x16 \
png2raw png2raw png2sprites
### ###
@ -31,6 +31,15 @@ png2gr.o: png2gr.c loadpng.h
### ###
png2sprites: png2sprites.o loadpng.o
$(CC) $(LFLAGS) -o png2sprites png2sprites.o loadpng.o -lpng
png2sprites.o: png2sprites.c loadpng.h
$(CC) $(CFLAGS) -c png2sprites.c
###
png2gr_text: png2gr_text.o loadpng.o png2gr_text: png2gr_text.o loadpng.o
$(CC) $(LFLAGS) -o png2gr_text png2gr_text.o loadpng.o -lpng $(CC) $(LFLAGS) -o png2gr_text png2gr_text.o loadpng.o -lpng
@ -136,8 +145,8 @@ png_to_40x96.o: png_to_40x96.c loadpng.h rle_common.h
### ###
install: install:
cp png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2sixrle2 png2fourrle png2six80 png_16x16 png2raw $(INSTALL_LOC) cp png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2sixrle2 png2fourrle png2six80 png_16x16 png2raw png2sprites $(INSTALL_LOC)
clean: clean:
rm -f *~ *.o png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2fourrle png2sixrle2 png2six80 text2gr pnglarge2rle png_16x16 png2raw rm -f *~ *.o png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 png2sixbitmap png2sixrle png2fourrle png2sixrle2 png2six80 text2gr pnglarge2rle png_16x16 png2raw png2sprites

View File

@ -0,0 +1,91 @@
/* png2sprites */
/* take a png image and generate sprites */
/* they will be in the format */
/* label: */
/* .byte xsize,ysize */
/* .byte line0data */
/* ... */
/* .byte lineNdata */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "loadpng.h"
int main(int argc, char **argv) {
int row=0;
int col=0;
int pixel;
int sprite_x, sprite_y, sprite_xsize, sprite_ysize;
unsigned char *image;
int xsize,ysize;
if (argc<6) {
fprintf(stderr,"Usage:\t%s INFILE label x y xsize ysize\n\n",argv[0]);
exit(-1);
}
sprite_x=atoi(argv[3]);
sprite_y=atoi(argv[4]);
sprite_xsize=atoi(argv[5]);
sprite_ysize=atoi(argv[6]);
if ((sprite_x>40) || (sprite_y>48)) {
fprintf(stderr,"Error! %d %d for sprite x,y out of bounds!\n",
sprite_x,sprite_y);
exit(-1);
}
if ((sprite_x+sprite_xsize>40) || (sprite_y+sprite_ysize>48)) {
fprintf(stderr,"Error! %d %d for sprite x,y out of bounds!\n",
sprite_x+sprite_xsize,sprite_y+sprite_ysize);
exit(-1);
}
if ( ((sprite_y%2)!=0) || ((sprite_y+sprite_ysize)%2!=0)) {
fprintf(stderr,"Error! Y co-ords need to be a multiple of 2\n");
exit(-1);
}
if (loadpng(argv[1],&image,&xsize,&ysize,PNG_WHOLETHING)<0) {
fprintf(stderr,"Error loading png!\n");
exit(-1);
}
fprintf(stderr,"Loaded image %d by %d\n",xsize,ysize);
if ((xsize!=40) || (ysize!=48)) {
fprintf(stderr,"Error! Must be 80x48!\n");
exit(1);
}
fprintf(stdout,"%s:\n",argv[2]);
fprintf(stdout,".byte %d,%d\n",sprite_xsize,sprite_ysize/2);
for(row=sprite_y/2;row<(sprite_y+sprite_ysize)/2;row++) {
fprintf(stdout,".byte ");
for(col=sprite_x;col<sprite_x+sprite_xsize;col++) {
if (col!=sprite_x) fprintf(stdout,",");
pixel=(image[row*xsize+col]);
fprintf(stdout,"$%02X",pixel);
}
fprintf(stdout,"\n");
}
fprintf(stdout,"\n");
return 0;
}