diff --git a/games/sb/Makefile b/games/sb/Makefile index 17943d6b..62950624 100644 --- a/games/sb/Makefile +++ b/games/sb/Makefile @@ -33,7 +33,7 @@ DUCK_POND: duck_pond.o duck_pond.o: duck_pond.s zx02_optim.s \ 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 diff --git a/games/sb/duck_pond.s b/games/sb/duck_pond.s index dabe659a..28a3b10e 100644 --- a/games/sb/duck_pond.s +++ b/games/sb/duck_pond.s @@ -43,18 +43,10 @@ duck_pond: ;=================== - ; Load graphics + ; TITLE SCREEN ;=================== -load_loop: - ;============================= - - - ;========================== - ; Load Image - ;=========================== - -load_image: +title_screen: lda #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 + + diff --git a/games/sb/gr_putsprite.s b/games/sb/gr_putsprite.s new file mode 100644 index 00000000..4a9bb94b --- /dev/null +++ b/games/sb/gr_putsprite.s @@ -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 diff --git a/games/sb/graphics/Makefile b/games/sb/graphics/Makefile index d32aa174..0353487a 100644 --- a/games/sb/graphics/Makefile +++ b/games/sb/graphics/Makefile @@ -7,9 +7,30 @@ DOS33 = ../../../utils/dos33fs-utils/dos33 EMPTY_DISK = ../../../empty_disk/empty.dsk TOKENIZE = ../../../utils/asoft_basic-utils/tokenize_asoft PNG2GR = ../../../utils/gr-utils/png2gr +PNG2SPRITES = ../../../utils/gr-utils/png2sprites 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 + + #### diff --git a/games/sb/zp.inc b/games/sb/zp.inc index 8760309c..2f39a567 100644 --- a/games/sb/zp.inc +++ b/games/sb/zp.inc @@ -127,34 +127,23 @@ CURSOR = $9D ; More zero-page addresses ; we try not to conflict with anything DOS, MONITOR or BASIC related - ;COLOR1 = $E0 - ;COLOR2 = $E1 - ;MATCH = $E2 -XX = $E3 -YY = $E4 -HGR_COLOR = $E4 - ;SHIPY = $E4 - ;YADD = $E5 - ;LOOP = $E6 - ;MEMPTRL = $E7 - ;MEMPTRH = $E8 - ;NAMEL = $E9 - ;NAMEH = $EA - ;NAMEX = $EB - ;CHAR = $EC + +D1_SCORE = $E0 +D1_SCORE_H = $E1 +D2_SCORE = $E2 +D2_SCORE_H = $E3 + + STATE = $ED DISP_PAGE = $ED DRAW_PAGE = $EE OFFSET = $EF - ;FIRST = $F0 -LASTKEY = $F1 -PADDLE_STATUS = $F2 +XPOS = $F0 +YPOS = $F1 +XMAX = $F2 -SPRITETEMP = $F2 -XPOS = $F3 -YPOS = $F4 TEMP = $FA TEMPY = $FB INL = $FC diff --git a/utils/gr-utils/Makefile b/utils/gr-utils/Makefile index 656decdb..50720052 100644 --- a/utils/gr-utils/Makefile +++ b/utils/gr-utils/Makefile @@ -4,7 +4,7 @@ CFLAGS = -g -Wall -O2 all: text2gr png2gr png2gr_text png2rle png2lz4 png_to_40x48d png_to_40x96 \ 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 $(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: - 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: - 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 diff --git a/utils/gr-utils/png2sprites.c b/utils/gr-utils/png2sprites.c new file mode 100644 index 00000000..9831d0af --- /dev/null +++ b/utils/gr-utils/png2sprites.c @@ -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 +#include + +#include +#include +#include +#include +#include + +#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