2021-08-25 00:42:11 +00:00
|
|
|
|
|
|
|
;===============================================
|
2021-08-25 00:58:44 +00:00
|
|
|
; hgr 7x28 draw sprite, with bg mask in GR $400
|
2021-08-25 00:42:11 +00:00
|
|
|
;===============================================
|
|
|
|
; 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
|
|
|
|
|
2021-08-25 00:58:44 +00:00
|
|
|
hgr_draw_sprite_7x28:
|
2021-08-25 00:42:11 +00:00
|
|
|
|
2021-08-25 01:31:07 +00:00
|
|
|
lda #0
|
|
|
|
sta MASK_COUNTDOWN
|
|
|
|
|
2021-08-25 00:42:11 +00:00
|
|
|
; set up pointers
|
|
|
|
lda INL
|
2021-08-25 00:58:44 +00:00
|
|
|
sta h728_smc1+1
|
2021-08-25 00:42:11 +00:00
|
|
|
lda INH
|
2021-08-25 00:58:44 +00:00
|
|
|
sta h728_smc1+2
|
2021-08-25 00:42:11 +00:00
|
|
|
|
|
|
|
clc
|
|
|
|
lda INL
|
2021-08-25 00:58:44 +00:00
|
|
|
adc #28
|
|
|
|
sta h728_smc3+1
|
2021-08-25 00:42:11 +00:00
|
|
|
lda INH
|
|
|
|
adc #0
|
2021-08-25 00:58:44 +00:00
|
|
|
sta h728_smc3+2
|
2021-08-25 00:42:11 +00:00
|
|
|
|
|
|
|
ldx #0 ; X is row counter
|
2021-08-25 00:58:44 +00:00
|
|
|
hgr_7x28_sprite_yloop:
|
2021-08-25 01:31:07 +00:00
|
|
|
lda MASK_COUNTDOWN
|
|
|
|
and #$3 ; only update every 4th
|
|
|
|
bne mask_good
|
|
|
|
|
|
|
|
txa
|
|
|
|
pha ; save X
|
|
|
|
|
|
|
|
; recalculate mask
|
|
|
|
txa
|
|
|
|
clc
|
|
|
|
adc CURSOR_Y
|
|
|
|
tax
|
|
|
|
ldy CURSOR_X
|
|
|
|
jsr update_bg_mask
|
|
|
|
|
|
|
|
|
|
|
|
pla ; restore X
|
|
|
|
tax
|
|
|
|
|
|
|
|
mask_good:
|
|
|
|
lda MASK
|
|
|
|
bne draw_sprite_skip
|
|
|
|
|
|
|
|
|
2021-08-25 00:42:11 +00:00
|
|
|
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
|
2021-08-25 00:58:44 +00:00
|
|
|
h728_smc3:
|
2021-08-25 00:42:11 +00:00
|
|
|
and $d000,X ; mask with sprite mask
|
2021-08-25 00:58:44 +00:00
|
|
|
h728_smc1:
|
2021-08-25 00:42:11 +00:00
|
|
|
ora $d000,X ; or in sprite
|
|
|
|
sta (GBASL),Y ; store out
|
|
|
|
|
2021-08-25 01:31:07 +00:00
|
|
|
|
|
|
|
draw_sprite_skip:
|
|
|
|
|
|
|
|
inc MASK_COUNTDOWN
|
|
|
|
|
2021-08-25 00:42:11 +00:00
|
|
|
inx
|
2021-08-25 00:58:44 +00:00
|
|
|
cpx #28
|
|
|
|
bne hgr_7x28_sprite_yloop
|
2021-08-25 00:42:11 +00:00
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
;======================
|
2021-08-25 00:58:44 +00:00
|
|
|
; save bg 7x28
|
2021-08-25 00:42:11 +00:00
|
|
|
;======================
|
|
|
|
|
2021-08-25 00:58:44 +00:00
|
|
|
save_bg_7x28:
|
2021-08-25 00:42:11 +00:00
|
|
|
|
|
|
|
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
|
2021-08-25 00:58:44 +00:00
|
|
|
sta save_sprite_7x28,X
|
2021-08-25 00:42:11 +00:00
|
|
|
|
|
|
|
inx
|
2021-08-25 00:58:44 +00:00
|
|
|
cpx #28
|
2021-08-25 00:42:11 +00:00
|
|
|
bne save_yloop
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
;======================
|
2021-08-25 00:58:44 +00:00
|
|
|
; restore bg 7x28
|
2021-08-25 00:42:11 +00:00
|
|
|
;======================
|
|
|
|
|
2021-08-25 00:58:44 +00:00
|
|
|
restore_bg_7x28:
|
2021-08-25 00:42:11 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2021-08-25 00:58:44 +00:00
|
|
|
lda save_sprite_7x28,X
|
2021-08-25 00:42:11 +00:00
|
|
|
sta (GBASL),Y
|
|
|
|
|
|
|
|
inx
|
2021-08-25 00:58:44 +00:00
|
|
|
cpx #28
|
2021-08-25 00:42:11 +00:00
|
|
|
bne restore_yloop
|
|
|
|
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
2021-08-25 01:31:07 +00:00
|
|
|
;===================
|
|
|
|
; update_bg_mask
|
|
|
|
;===================
|
|
|
|
; newx/7 in Y
|
|
|
|
; newy in X
|
|
|
|
; updates MASK
|
|
|
|
update_bg_mask:
|
|
|
|
|
2021-08-25 03:48:31 +00:00
|
|
|
; calculate peasant priority
|
|
|
|
; based on head
|
|
|
|
; FIXME: only do this once at beginning
|
|
|
|
lda PEASANT_Y
|
|
|
|
sec
|
|
|
|
sbc #48 ; Y=48
|
|
|
|
lsr ; div by 8
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
clc
|
|
|
|
adc #2
|
|
|
|
sta PEASANT_PRIORITY
|
|
|
|
|
|
|
|
|
2021-08-25 01:31:07 +00:00
|
|
|
; rrrr rtii top 5 bits row, bit 2 top/bottom
|
|
|
|
|
|
|
|
txa
|
|
|
|
and #$04 ; see if odd/even
|
|
|
|
beq bg_mask_even
|
|
|
|
|
|
|
|
bg_mask_odd:
|
|
|
|
lda #$f0
|
|
|
|
bne bg_mask_mask ; bra
|
|
|
|
|
|
|
|
bg_mask_even:
|
|
|
|
lda #$0f
|
|
|
|
bg_mask_mask:
|
|
|
|
|
|
|
|
sta MASK
|
|
|
|
|
|
|
|
txa
|
|
|
|
lsr
|
|
|
|
lsr ; need to divide by 8 then * 2
|
|
|
|
lsr ; can't just div by 4 as we need to mask bottom bit
|
|
|
|
asl
|
|
|
|
tax
|
|
|
|
|
|
|
|
lda gr_offsets,X
|
|
|
|
sta BASL
|
|
|
|
lda gr_offsets+1,X
|
|
|
|
sta BASH
|
|
|
|
|
|
|
|
lda (BASL),Y
|
|
|
|
|
2021-08-25 03:48:31 +00:00
|
|
|
ldy MASK
|
|
|
|
cpy #$f0
|
|
|
|
bne mask_bottom
|
|
|
|
mask_top:
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
lsr
|
|
|
|
jmp mask_mask_mask
|
|
|
|
mask_bottom:
|
|
|
|
and #$0f
|
|
|
|
mask_mask_mask:
|
|
|
|
sta MASK
|
2021-08-25 01:31:07 +00:00
|
|
|
|
2021-08-25 03:48:31 +00:00
|
|
|
cmp PEASANT_PRIORITY
|
|
|
|
beq mask_false ; branch less than equal
|
|
|
|
bcc mask_false ; blt
|
2021-08-25 01:31:07 +00:00
|
|
|
|
|
|
|
mask_true:
|
|
|
|
lda #$ff
|
|
|
|
sta MASK
|
|
|
|
rts
|
|
|
|
|
|
|
|
mask_false:
|
|
|
|
lda #$00
|
|
|
|
sta MASK
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2021-08-25 03:48:31 +00:00
|
|
|
; priorities
|
|
|
|
; 0 = collision
|
|
|
|
; 1 = bg = always draw ; Y-48
|
|
|
|
; 2 0-55
|
|
|
|
; 3 56-63 ; 8/8+2 = 3
|
|
|
|
; 4 64-71 ; 16/8+2 = 4
|
|
|
|
; 5 72-79
|
|
|
|
; 6 80-87 ; 32/8+2 = 6
|
|
|
|
; 7 88-95
|
|
|
|
; 8 96-103
|
|
|
|
; 9 104-111
|
|
|
|
; 10 112-119
|
|
|
|
; 11 120-127
|
|
|
|
; 12 128-135 ; 8
|
|
|
|
; 13 136-143
|
|
|
|
; 14 144-151
|
|
|
|
; 15 152-159
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
2021-08-25 01:31:07 +00:00
|
|
|
|
|
|
|
|
2021-08-25 00:42:11 +00:00
|
|
|
;====================
|
|
|
|
; save area
|
|
|
|
;====================
|
|
|
|
|
2021-08-25 00:58:44 +00:00
|
|
|
save_sprite_7x28:
|
2021-08-25 00:42:11 +00:00
|
|
|
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
|
2021-08-25 00:58:44 +00:00
|
|
|
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
|