peasant: optimize sprite routines

This commit is contained in:
Vince Weaver 2021-08-24 20:42:11 -04:00
parent 6b5c3612b0
commit d8155c8f4e
5 changed files with 164 additions and 56 deletions

View File

@ -106,7 +106,7 @@ PEASANT2: peasant2.o
peasant2.o: peasant2.s zp.inc \ peasant2.o: peasant2.s zp.inc \
graphics/graphics_peasant2.inc sprites/peasant_sprite.inc \ graphics/graphics_peasant2.inc sprites/peasant_sprite.inc \
draw_box.s hgr_rectangle.s hgr_font.s hgr_input.s \ draw_box.s hgr_rectangle.s hgr_font.s hgr_input.s \
hgr_7x30_sprite.s hgr_1x5_sprite.s hgr_save_restore.s \ hgr_7x30_sprite_mask.s hgr_1x5_sprite.s hgr_save_restore.s \
wait_a_bit.s draw_peasant.s hgr_text_box.s \ wait_a_bit.s draw_peasant.s hgr_text_box.s \
keyboard.s parse_input.s new_map_location.s \ keyboard.s parse_input.s new_map_location.s \
peasant_move.s peasant_move.s

View File

@ -17,27 +17,18 @@ hgr_draw_sprite_1x5:
ldx #0 ldx #0
hgr_1x5_sprite_yloop: hgr_1x5_sprite_yloop:
txa txa ; row
pha
clc clc
adc CURSOR_Y adc CURSOR_Y ; add in y offset
ldx #0 ; calc GBASL/GBASH from lookup table
ldy #0
; calc GBASL/GBASH tay
; jsr HPOSN ; (Y,X),(A) (values stored in HGRX,XH,Y) lda hposn_low,Y
tax
lda hposn_low,X
sta GBASL sta GBASL
lda hposn_high,X lda hposn_high,Y
sta GBASH sta GBASH
pla
tax
ldy CURSOR_X ldy CURSOR_X
h1x5_smc1: h1x5_smc1:

View File

@ -1,7 +1,7 @@
;====================== ;===============================================
; hgr 7x30 draw sprite ; hgr 7x30 draw sprite
;====================== ;===============================================
; SPRITE in INL/INH ; SPRITE in INL/INH
; Location at CURSOR_X CURSOR_Y ; Location at CURSOR_X CURSOR_Y
@ -26,37 +26,29 @@ hgr_draw_sprite_7x30:
adc #0 adc #0
sta h730_smc3+2 sta h730_smc3+2
ldx #0 ldx #0 ; X is row counter
hgr_7x30_sprite_yloop: hgr_7x30_sprite_yloop:
txa txa ; X is current row
pha
clc clc
adc CURSOR_Y adc CURSOR_Y ; add in cursor_y
ldx #0
ldy #0
; calc GBASL/GBASH ; calc GBASL/GBASH
; jsr HPOSN ; (Y,X),(A) (values stored in HGRX,XH,Y)
tax tay ; get output ROW into GBASL/H
lda hposn_low,X lda hposn_low,Y
sta GBASL sta GBASL
lda hposn_high,X lda hposn_high,Y
sta GBASH sta GBASH
pla
tax
ldy CURSOR_X ldy CURSOR_X
lda (GBASL),Y lda (GBASL),Y ; load background
h730_smc3: h730_smc3:
and $d000,X ; mask and $d000,X ; mask with sprite mask
h730_smc1: h730_smc1:
ora $d000,X ; sprite ora $d000,X ; or in sprite
sta (GBASL),Y sta (GBASL),Y ; store out
inx inx
cpx #30 cpx #30
@ -65,7 +57,6 @@ h730_smc1:
rts rts
;====================== ;======================
; save bg 7x30 ; save bg 7x30
;====================== ;======================
@ -80,11 +71,8 @@ save_yloop:
clc clc
adc CURSOR_Y adc CURSOR_Y
ldx #0
ldy #0
; calc GBASL/GBASH ; calc GBASL/GBASH
; jsr HPOSN ; (Y,X),(A) (values stored in HGRX,XH,Y)
tax tax
lda hposn_low,X lda hposn_low,X
@ -114,27 +102,18 @@ restore_bg_7x30:
ldx #0 ldx #0
restore_yloop: restore_yloop:
txa txa ; current row
pha
clc clc
adc CURSOR_Y adc CURSOR_Y ; add in y start point
ldx #0 ; calc GBASL/GBASH using lookup table
ldy #0
; calc GBASL/GBASH tay
; jsr HPOSN ; (Y,X),(A) (values stored in HGRX,XH,Y) lda hposn_low,Y
tax
lda hposn_low,X
sta GBASL sta GBASL
lda hposn_high,X lda hposn_high,Y
sta GBASH sta GBASH
pla
tax
ldy CURSOR_X ldy CURSOR_X
lda save_sprite_7x30,X lda save_sprite_7x30,X

View File

@ -0,0 +1,138 @@
;===============================================
; hgr 7x30 draw sprite, with bg mask in GR $400
;===============================================
; SPRITE in INL/INH
; Location at CURSOR_X CURSOR_Y
; for now, BG mask is only all or nothing
; so we just skip drawing if behind
; left sprite AT INL/INH
; right sprite at INL/INH + 14
; left mask at INL/INH + 28
; right mask at INL/INH + 42
hgr_draw_sprite_7x30:
; set up pointers
lda INL
sta h730_smc1+1
lda INH
sta h730_smc1+2
clc
lda INL
adc #30
sta h730_smc3+1
lda INH
adc #0
sta h730_smc3+2
ldx #0 ; X is row counter
hgr_7x30_sprite_yloop:
txa ; X is current row
clc
adc CURSOR_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
sta GBASH
ldy CURSOR_X
lda (GBASL),Y ; load background
h730_smc3:
and $d000,X ; mask with sprite mask
h730_smc1:
ora $d000,X ; or in sprite
sta (GBASL),Y ; store out
inx
cpx #30
bne hgr_7x30_sprite_yloop
rts
;======================
; save bg 7x30
;======================
save_bg_7x30:
ldx #0
save_yloop:
txa
pha
clc
adc CURSOR_Y
; calc GBASL/GBASH
tax
lda hposn_low,X
sta GBASL
lda hposn_high,X
sta GBASH
pla
tax
ldy CURSOR_X
lda (GBASL),Y
sta save_sprite_7x30,X
inx
cpx #30
bne save_yloop
rts
;======================
; restore bg 7x30
;======================
restore_bg_7x30:
ldx #0
restore_yloop:
txa ; current row
clc
adc CURSOR_Y ; add in y start point
; calc GBASL/GBASH using lookup table
tay
lda hposn_low,Y
sta GBASL
lda hposn_high,Y
sta GBASH
ldy CURSOR_X
lda save_sprite_7x30,X
sta (GBASL),Y
inx
cpx #30
bne restore_yloop
rts
;====================
; save area
;====================
save_sprite_7x30:
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00

View File

@ -167,7 +167,7 @@ score_text:
.include "hgr_font.s" .include "hgr_font.s"
.include "draw_box.s" .include "draw_box.s"
.include "hgr_rectangle.s" .include "hgr_rectangle.s"
.include "hgr_7x30_sprite.s" .include "hgr_7x30_sprite_mask.s"
.include "hgr_1x5_sprite.s" .include "hgr_1x5_sprite.s"
;.include "hgr_save_restore.s" ;.include "hgr_save_restore.s"
.include "hgr_partial_save.s" .include "hgr_partial_save.s"