Prev: D303 Up: Map Next: D3D2
D319: Next Step
Used by the routine at FinishStep.
Moves to the next step of a segment: the pixel row goes up by the vertical step and the pixel column along by the horizontal step. Then the step is tested against the position at PositionAcross and PositionDown, and the flags in ContactFlags are set to say where they are in relation to each other.
NextStep D319 LD A,($CE37) The vertical step.
D31C LD B,A B=A.
D31D LD A,($CE44) The segment row.
D320 SUB B Subtract B from A.
D321 LD ($CE44),A Update the segment row.
D324 LD A,($5C2D) The segment screen row.
D327 SUB B Subtract B from A.
D328 LD ($5C2D),A Update the segment screen row.
D32B LD A,($CE35) The horizontal step.
D32E LD B,A B=A.
D32F LD A,($5C2C) The segment screen column.
D332 ADD A,B A gains B.
D333 LD ($5C2C),A Update the segment screen column.
D336 LD A,($CE43) The segment column.
D339 ADD A,B A gains B.
D33A LD ($CE43),A Update the segment column.
This entry point is used by the routine at DrawTerrain.
Test the row. Rows that are above the position are drawn, a step at the same row is flagged by FlagFloorContact or FlagCeilingContact, and steps below the position are skipped.
NextStep_Test D33D XOR A Clear A.
D33E LD ($5C31),A Update the contact flags.
D341 LD A,($5C1D) The tile number.
D344 BIT 0,A Jump to NextStep_Bottom if bit 0 of A is set.
D346 JR NZ,NextStep_Bottom
D348 LD A,($CE44) The segment row.
D34B LD B,A B=A.
D34C LD A,($CE46) The position down.
D34F CP B Jump to FlagCeilingContact if A is B.
D350 JP Z,FlagCeilingContact
D353 JP NC,FinishStep_Next Jump to FinishStep_Next if the carry flag is clear.
D356 JP NextStep_Column Jump to NextStep_Column.
NextStep_Bottom D359 LD A,($CE5A) The vertical step copy.
D35C LD B,A B=A.
D35D LD A,($CE44) The segment row.
D360 SUB B Subtract B from A.
D361 LD B,A B=A.
D362 LD A,($CE46) The position down.
D365 CP B Jump to FinishStep_Next if A is less than B.
D366 JP C,FinishStep_Next
D369 JP Z,FlagFloorContact Jump to FlagFloorContact if the zero flag is set.
This entry point is used by the routines at FlagFloorContact and FlagCeilingContact.
Test the column in the same way, with FlagLeftContact and FlagRightContact for the same column.
NextStep_Column D36C LD A,($CE43) The segment column.
D36F LD B,A B=A.
D370 LD A,($5C1D) The tile number.
D373 BIT 1,A Jump to NextStep_Right if bit 1 of A is set.
D375 JR NZ,NextStep_Right
D377 LD A,($CE37) The vertical step.
D37A AND A Jump to NextStep_Width if A is not zero.
D37B JR NZ,NextStep_Width
D37D LD A,($CE41) The horizontal offset.
D380 ADD A,B A gains B.
D381 CP $F0 Jump to NextStep_Width if A is less than F0.
D383 JR C,NextStep_Width
D385 JP Z,FlagLeftContact Jump to FlagLeftContact if the zero flag is set.
D388 CP $F7 Jump to NextStep_Width if A is F7 or more.
D38A JR NC,NextStep_Width
D38C LD A,C A=C.
D38D DEC A Step A back.
D38E JP NZ,FinishStep_Next Jump to FinishStep_Next if the zero flag is clear.
D391 DEC A Step A back.
D392 LD ($D85D),A Update the edge flag.
NextStep_Width D395 LD A,($5C25) The horizontal step size.
D398 ADD A,B A gains B.
D399 LD B,A B=A.
D39A LD A,($CE45) The position across.
D39D CP B Jump to FlagLeftContact if A is B.
D39E JP Z,FlagLeftContact
D3A1 JP NC,FinishStep_Next Jump to FinishStep_Next if the carry flag is clear.
D3A4 JR NextStep_Flags Jump to NextStep_Flags.
NextStep_Right D3A6 LD A,($CE45) The position across.
D3A9 CP B Jump to FlagRightContact if A is B.
D3AA JP Z,FlagRightContact
D3AD JP C,FinishStep_Next Jump to FinishStep_Next if the carry flag is set.
This entry point is used by the routines at FlagLeftContact and FlagRightContact.
If any of the flags have been set the step is handled by one of the routines for contact. Otherwise the step is drawn.
NextStep_Flags D3B0 LD A,($5C31) The contact flags.
D3B3 AND A Jump to SetUpPiece if A is zero.
D3B4 JR Z,SetUpPiece
D3B6 CP $08 Jump to NoteWallContact if A is 08.
D3B8 JP Z,NoteWallContact
D3BB CP $04 Jump to NoteWallContact if A is 04.
D3BD JP Z,NoteWallContact
D3C0 CP $01 Jump to CountVerticalContact if A is 01.
D3C2 JP Z,CountVerticalContact
D3C5 CP $02 Jump to CountVerticalContact if A is 02.
D3C7 JP Z,CountVerticalContact
D3CA AND %00001111 Keep the bits of A that are set in 0F.
D3CC JP NZ,CountVerticalContact Jump to CountVerticalContact if the zero flag is clear.
D3CF JP FinishStep_Next Jump to FinishStep_Next.
Prev: D303 Up: Map Next: D3D2