.include "snes.inc" .include "snes_zvars.inc" .include "players.inc" .include "objects.inc" .import level_solid .export ClipVectorLeft, ClipVectorRight, ClipVectorUp, ClipVectorDown .export TestForEntitiesT .code .a8 .i16 ;============================================================================================== .macro PREPFUNC_Y ;============================================================================================== sta m0 ; m0 = amount (expand to 16 bits) stz m0+1 ; ;---------------------------------------------------------------------------------------------- rep #21h ; m1 = Y.H * 64 tya ; and #255<<8 ; lsr ; lsr ; sta m1 ; .endmacro ;---------------------------------------------------------------------------------------------- .macro ExitTestH pha ; EXIT if point is already colliding xba ; and #0FFh ; clc ; adc m1 ; txy ; tax ; sep #20h ; lda F:level_solid, x ; bpl :+ ; plx ; tyx ; sec ; rts ; : rep #21h ; pla ; .endmacro ;---------------------------------------------------------------------------------------------- ; x,y = point (12.4 fp) ; a = -movement amount ; ; returns: ; x = clipped point ; C = collision occured ; a = tile ;============================================================================================== ClipVectorLeft: ;============================================================================================== PREPFUNC_Y ;---------------------------------------------------------------------------------------------- txa ; x = Y.H*64 + (X - amt).H ExitTestH sec ; sbc m0 ; tay ; (y = X - amt) xba ; (a = a.H) and #0FFh ; clc ; adc m1 ; tax ; ;---------------------------------------------------------------------------------------------- sep #20h ; lda F:level_solid, x ; bne @clip_against_tile ; ;---------------------------------------------------------------------------------------------- tyx clc rts ;---------------------------------------------------------------------------------------------- @clip_against_tile: ;---------------------------------------------------------------------------------------------- pha rep #21h ; x = (x + 1.0 tiles) and delete fraction tya ; adc #256 ; and #0FF00h ; tax ; sep #20h ; ;---------------------------------------------------------------------------------------------- pla sec rts ; ;---------------------------------------------------------------------------------------------- ; x,y = point (12.4 fp) ; a = +movement amount ; ; returns: ; x = clipped point ; C = collision occured ;============================================================================================== ClipVectorRight: ;============================================================================================== PREPFUNC_Y ;---------------------------------------------------------------------------------------------- txa ; x = Y.H*64 + (X + amt).H ExitTestH adc m0 ; tay ; (y = X + amt) xba ; (a = a.H) and #0FFh ; adc m1 ; tax ; ;---------------------------------------------------------------------------------------------- sep #20h ; lda F:level_solid, x ; bne @clip_against_tile ; ;---------------------------------------------------------------------------------------------- tyx clc rts ;---------------------------------------------------------------------------------------------- @clip_against_tile: ;---------------------------------------------------------------------------------------------- pha rep #21h ; x = (x - 1.0 tiles) and max fraction tya ; sbc #256-1 ; ora #0FFh ; tax ; sep #20h ; ;---------------------------------------------------------------------------------------------- pla sec rts ; ;============================================================================================== .macro PREPFUNC_X ;============================================================================================== sta m0 ; m0 = amount (expand to 16 bits) stz m0+1 ; ;---------------------------------------------------------------------------------------------- rep #21h ; m1 = X.H [& clear carry] tya ; and #255<<8 ; xba ; sta m1 ; .endmacro ; ;---------------------------------------------------------------------------------------------- .macro ExitTestV pha ; EXIT if point is already colliding and #0FF00h ; lsr ; lsr ; adc m1 ; txy ; tax ; sep #20h ; lda F:level_solid, x ; bpl :+ ; plx ; tyx ; sec ; rts ; : rep #21h ; pla ; .endmacro ;---------------------------------------------------------------------------------------------- ; x = Y ; y = X (both 12.4 fp) ; a = amount to subtract from Y ; ; returns: ; x = clipped Y result ;============================================================================================== ClipVectorUp: ;============================================================================================== PREPFUNC_X ;---------------------------------------------------------------------------------------------- txa ; x = X.H + (Y - amt).H * 64 ExitTestV sec ; sbc m0 ; tay ; (y = Y - amt) and #0FF00h ; (a = a.H) *64 lsr ; lsr ; adc m1 ; tax ; ;---------------------------------------------------------------------------------------------- sep #20h ; lda F:level_solid, x ; bne @clip_against_tile ; ;---------------------------------------------------------------------------------------------- tyx clc rts ;---------------------------------------------------------------------------------------------- @clip_against_tile: ;---------------------------------------------------------------------------------------------- pha rep #21h ; x = (x + 1.0 tiles) and cut fraction tya ; adc #256 ; and #0FF00h ; tax ; sep #20h ; ;---------------------------------------------------------------------------------------------- pla sec rts ; ;---------------------------------------------------------------------------------------------- ; x = Y ; y = X (both 12.4 fp) ; a = amount to add to Y ; ; returns: ; x = clipped Y result ;============================================================================================== ClipVectorDown: ;============================================================================================== PREPFUNC_X ;---------------------------------------------------------------------------------------------- txa ; x = X.H + (Y + amt).H * 64 ExitTestV adc m0 ; tay ; (y = Y + amt) and #0FF00h ; (a = a.H) *64 lsr ; lsr ; adc m1 ; tax ; ;---------------------------------------------------------------------------------------------- sep #20h ; lda F:level_solid, x ; bne @clip_against_tile ; ;---------------------------------------------------------------------------------------------- tyx clc rts ;---------------------------------------------------------------------------------------------- @clip_against_tile: ;---------------------------------------------------------------------------------------------- pha rep #21h ; x = (x + 1.0 tiles) and max fraction tya ; sbc #256-1 ; ora #0FFh ; tax ; sep #20h ; ;---------------------------------------------------------------------------------------------- pla sec rts ; ;---------------------------------------------------------------------------------------------- ;m0.l=x ;m0.h=y ;============================================================================================== TestForEntitiesT: ;============================================================================================== lda m0+1 xba lda m0 ; x = solidmap address asl ; asl ; rep #20h ; lsr ; lsr ; tax ; ;---------------------------------------------------------------------------------------------- sep #20h ; lda F:level_solid, x ; test solid entry bne @hit ; ;---------------------------------------------------------------------------------------------- .macro test_p px, py .local @miss lda px cmp m0 bne @miss lda py cmp m0+1 beq @hit @miss: .endmacro test_p PL_XH, PL_YH test_p PL_XH+1, PL_YH+1 test_p PL_XH+2, PL_YH+2 jsr Objects_TestForEntity bcs @hit clc rts @hit: sec rts