From 2ca8929229c1db10982c9d60970cf169563f5b2b Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Tue, 27 Aug 2024 14:34:36 -0400 Subject: [PATCH] peasant_mini: horribl sprite code but it works for now --- games/peasant_mini/cliff/Makefile | 9 + games/peasant_mini/cliff/cliff.s | 60 ++++- games/peasant_mini/cliff/hgr_sprite.s | 238 ++++++++++++++++++ games/peasant_mini/cliff/sprites/Makefile | 14 ++ .../cliff/sprites/enemy_sprites.png | Bin 1489 -> 5381 bytes games/peasant_mini/cliff/zp.inc | 10 + 6 files changed, 329 insertions(+), 2 deletions(-) create mode 100644 games/peasant_mini/cliff/hgr_sprite.s create mode 100644 games/peasant_mini/cliff/sprites/Makefile diff --git a/games/peasant_mini/cliff/Makefile b/games/peasant_mini/cliff/Makefile index ab8e0530..b46891a3 100644 --- a/games/peasant_mini/cliff/Makefile +++ b/games/peasant_mini/cliff/Makefile @@ -29,15 +29,24 @@ CLIFF: cliff.o cliff.o: cliff.s zx02_optim.s \ hgr_copy.s hgr_partial_save.s \ + hgr_sprite.s \ cliff_graphics/cliff_base.hgr.zx02 \ + sprites/enemy_sprites.inc \ zp.inc hardware.inc ca65 -o cliff.o cliff.s -l cliff.lst +#### + cliff_graphics/cliff_base.hgr.zx02: cd cliff_graphics && make +sprites/enemy_sprites.inc: + cd sprites && make + + #### clean: rm -f *.lst *.o CLIFF HELLO cd cliff_graphics && make clean + cd sprites && make clean diff --git a/games/peasant_mini/cliff/cliff.s b/games/peasant_mini/cliff/cliff.s index e0c3218d..2252549d 100644 --- a/games/peasant_mini/cliff/cliff.s +++ b/games/peasant_mini/cliff/cliff.s @@ -110,6 +110,60 @@ game_loop: jsr draw_peasant + + ;===================== + ; draw enemies + + lda #$20 ; backup location + sta OUTH + lda #$00 + sta OUTL + + lda #8 + sta SPRITE_X + + lda #100 + sta SPRITE_Y + + lda #bird0_sprite + sta INH + + lda #bird0_mask + sta MASKH + + jsr hgr_draw_sprite + + lda #$21 ; backup location + sta OUTH + lda #$00 + sta OUTL + + lda #21 + sta SPRITE_X + + lda #89 + sta SPRITE_Y + + lda #bird1_sprite + sta INH + + lda #bird1_mask + sta MASKH + + jsr hgr_draw_sprite + + + + + ;===================== ; increment frame @@ -139,6 +193,8 @@ done_cliff: .include "hgr_tables.s" + .include "hgr_sprite.s" + .include "zx02_optim.s" .include "wait.s" @@ -162,7 +218,7 @@ bg_data: .incbin "cliff_graphics/cliff_base.hgr.zx02" priority_data: - .incbin "cliff_graphics/cliff_base_priority.zx02" - +sprites: + .include "sprites/enemy_sprites.inc" diff --git a/games/peasant_mini/cliff/hgr_sprite.s b/games/peasant_mini/cliff/hgr_sprite.s new file mode 100644 index 00000000..5dcab84c --- /dev/null +++ b/games/peasant_mini/cliff/hgr_sprite.s @@ -0,0 +1,238 @@ + ;=========================================== + ; hgr draw sprite (only at 7-bit boundaries) + ;=========================================== + ; attempts to shift to allow arbitray odd/even columns + ; + ; *cannot* handle sprites bigger than a 256 byte page + + ; SPRITE in INL/INH + ; note: xsize,ysize in first two bytes + ; total bytes in text two bytes + ; mask data immediately follows sprite data + + ; Location at SPRITE_X SPRITE_Y + ; note: sprite_x is column, so Xcoord/7 + + ; Save at OUTL/OUTH + +hgr_draw_sprite: + lda SPRITE_X + ror + bcs hgr_draw_sprite_odd + +hgr_draw_sprite_even: + ldy #0 + lda (INL),Y ; load xsize + sta (OUTL),Y ; store to screen backup + clc + adc SPRITE_X + sta sprite_width_end_smc+1 ; self modify for end of line + + iny ; load ysize + lda (INL),Y + sta (OUTL),Y ; store to screen backup + sta sprite_ysize_smc+1 ; self modify for end row + + ; point smc to sprite + lda INL + sta sprite_smc1+1 + lda INH + sta sprite_smc1+2 + sta INH + + ; point smc to backup + lda OUTL + sta backup_sprite_smc1+1 + lda OUTH + sta backup_sprite_smc1+2 + + ; point smc to mask + lda MASKL + sta sprite_mask_smc1+1 + lda MASKH + sta sprite_mask_smc1+2 + + ldx #0 ; X is pointer offset + stx CURRENT_ROW ; actual row + + ldx #2 ; start two bytes in (past x/y) + +hgr_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 + +sprite_inner_loop: + + lda (GBASL),Y ; load bg +backup_sprite_smc1: + sta $f000,X +sprite_smc1: + eor $f000,X ; load sprite data +sprite_mask_smc1: + and $f000,X + eor (GBASL),Y + sta (GBASL),Y ; store to screen + + inx ; increment sprite offset + iny ; increment output position + + +sprite_width_end_smc: + cpy #6 ; see if reached end of row + bne sprite_inner_loop ; if not, loop + + + inc CURRENT_ROW ; row + lda CURRENT_ROW ; row + +sprite_ysize_smc: + cmp #31 ; see if at end + bne hgr_sprite_yloop ; if not, loop + + rts + +hgr_draw_sprite_odd: + + ldy #0 + lda (INL),Y ; load xsize + sta (OUTL),Y ; store to screen backup + clc + adc SPRITE_X + sta osprite_width_end_smc+1 ; self modify for end of line + + iny + lda (INL),Y ; load ysize + sta (OUTL),Y ; store to screen backup + sta osprite_ysize_smc+1 ; self modify for end row + + ; point smc to sprite + lda INL + sta osprite_smc1+1 + lda INH + sta osprite_smc1+2 + + ; point smc to backup + lda OUTL + sta obackup_sprite_smc1+1 + lda OUTH + sta obackup_sprite_smc1+2 + + ; point smc to mask + lda MASKL + sta osprite_mask_smc1+1 + lda MASKH + sta osprite_mask_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 + + lda #$0 + sta SPRITE_TEMP ; default high bit to 0 + sta MASK_TEMP ; defailt high bit to 0 + +osprite_inner_loop: + + lda (GBASL),Y ; load bg data + sta TEMP + +obackup_sprite_smc1: + sta $f000,X ; store backup + +osprite_mask_smc1: + lda $f000,X ; load mask data + + eor #$FF + + rol MASK_TEMP + rol + sta MASK_TEMP + + and TEMP + sta TEMP + +osprite_smc1: + lda $f000,X ; load sprite data + + rol SPRITE_TEMP + rol + sta SPRITE_TEMP + ora TEMP + + and #$7f ; force purple/green + + sta (GBASL),Y ; store to screen + + + inx ; increment sprite offset + iny ; increment output position + + + +osprite_width_end_smc: + cpy #6 ; see if reached end of row + bne osprite_inner_loop ; if not, loop + + 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 + + +.if 0 + + + + +;hgr_sprite_page_smc: +; eor #$00 + + + + +backup_sprite1 = $1800 +backup_sprite2 = $1900 + +.endif diff --git a/games/peasant_mini/cliff/sprites/Makefile b/games/peasant_mini/cliff/sprites/Makefile new file mode 100644 index 00000000..2d15c0b4 --- /dev/null +++ b/games/peasant_mini/cliff/sprites/Makefile @@ -0,0 +1,14 @@ +HGR_SPRITE = ../../../../utils/hgr-utils/hgr_make_sprite + +all: enemy_sprites.inc + +enemy_sprites.inc: enemy_sprites.png + $(HGR_SPRITE) -s -l bird0_sprite enemy_sprites.png 210 50 230 66 > enemy_sprites.inc + $(HGR_SPRITE) -s -l bird0_mask enemy_sprites.png 238 50 258 66 >> enemy_sprites.inc + $(HGR_SPRITE) -s -l bird1_sprite enemy_sprites.png 210 74 230 88 >> enemy_sprites.inc + $(HGR_SPRITE) -s -l bird1_mask enemy_sprites.png 238 74 258 88 >> enemy_sprites.inc + + +clean: + rm -f *~ enemy_sprites.inc + diff --git a/games/peasant_mini/cliff/sprites/enemy_sprites.png b/games/peasant_mini/cliff/sprites/enemy_sprites.png index 57f13ee00ce5bb1f7c714068dcc4d233cc0bc0d1..6d41f961597cb4637f7fb43610c017f063a8bf57 100644 GIT binary patch literal 5381 zcmeHKYfw|y77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