Prev: CD08 Up: Map Next: CE04
CD6B: Read Segment Shapes
Used by the routine at DrawTerrain.
Reads the two bytes that give the shapes at the ends of a flat segment from the script and stores them in StartShape and EndShape. It changes them if the tile is drawn back to front or upside down. When the tile is back to front the horizontal position of the segment is mirrored and its type is changed with the table at MirrorTypeTable. The routine finally stores the address of the rest of the script in ScriptPointer.
Input
HL Address of the shape bytes in the script
Output
HL Address of the next segment in the script
ReadSegmentShapes CD6B LD A,($CE37) The vertical step.
CD6E AND A Jump to ReadSegmentShapes_Store if A is not zero.
CD6F JR NZ,ReadSegmentShapes_Store
CD71 LD A,($5C26) The upside down flag.
CD74 AND A Jump to ReadSegmentShapes_BackToFront if A is zero.
CD75 JR Z,ReadSegmentShapes_BackToFront
CD77 LD A,($CE44) The segment row.
CD7A XOR %00001100 Flip the bits of A that are set in 0C.
CD7C LD ($CE44),A Update the segment row.
ReadSegmentShapes_BackToFront CD7F LD A,($5C30) The back to front flag.
CD82 AND A Jump to ReadSegmentShapes_Normal if A is zero.
CD83 JR Z,ReadSegmentShapes_Normal
CD85 LD A,(HL) Read HL.
CD86 XOR %00000010 Flip the bits of A that are set in 02.
CD88 LD ($5C34),A Update the segment end shape.
CD8B INC HL Advance HL.
CD8C LD A,(HL) Read HL.
CD8D CP $16 Jump to ReadSegmentShapes_End if A is 16.
CD8F JR Z,ReadSegmentShapes_End
CD91 XOR %00000010 Flip the bits of A that are set in 02.
CD93 LD ($5C33),A Update the segment start shape.
CD96 INC HL Advance HL.
CD97 JR ReadSegmentShapes_UpsideDown Jump to ReadSegmentShapes_UpsideDown.
ReadSegmentShapes_End CD99 LD ($5C34),A Update the segment end shape.
CD9C INC HL Advance HL.
CD9D JR ReadSegmentShapes_UpsideDown Jump to ReadSegmentShapes_UpsideDown.
ReadSegmentShapes_Normal CD9F LD A,(HL) Read HL.
CDA0 LD ($5C33),A Update the segment start shape.
CDA3 INC HL Advance HL.
CDA4 LD A,(HL) Read HL.
CDA5 LD ($5C34),A Update the segment end shape.
CDA8 INC HL Advance HL.
ReadSegmentShapes_UpsideDown CDA9 LD A,($5C26) The upside down flag.
CDAC AND A Jump to ReadSegmentShapes_Store if A is zero.
CDAD JR Z,ReadSegmentShapes_Store
CDAF LD A,($5C33) The segment start shape.
CDB2 XOR %00000001 Flip the bits of A that are set in 01.
CDB4 LD ($5C33),A Update the segment start shape.
CDB7 LD A,($5C34) The segment end shape.
CDBA CP $16 Jump to ReadSegmentShapes_Store if A is 16.
CDBC JR Z,ReadSegmentShapes_Store
CDBE XOR %00000001 Flip the bits of A that are set in 01.
CDC0 LD ($5C34),A Update the segment end shape.
ReadSegmentShapes_Store CDC3 LD ($CE4D),HL Update the script pointer.
CDC6 LD A,($5C30) The back to front flag.
CDC9 AND A Return if A is zero.
CDCA RET Z
CDCB LD A,($5C34) The segment end shape.
CDCE CP $16 Return if A is 16.
CDD0 RET Z
CDD1 LD A,($CE43) The segment column.
CDD4 LD B,A B=A.
CDD5 LD A,($5C25) The horizontal step size.
CDD8 ADD A,B A gains B.
CDD9 ADD A,$0F Add 0F to A.
CDDB CPL Invert A.
CDDC LD ($CE43),A Update the segment column.
CDDF EXX Switch to the alternate registers.
CDE0 LD E,(IX+$03) Read offset 03 of IX into E.
CDE3 LD D,$00 Clear D.
CDE5 LD HL,$CE04 The mirror type table.
CDE8 ADD HL,DE HL gains DE.
CDE9 LD A,(HL) Read HL.
CDEA LD (IX+$03),A Write A to offset 03 of IX.
CDED CALL SetSlopeParameters Call SetSlopeParameters.
CDF0 EXX Switch to the alternate registers.
CDF1 LD A,($CE37) The vertical step.
CDF4 AND A Return if A is not zero.
CDF5 RET NZ
CDF6 LD B,C B=C.
CDF7 LD A,($CE43) The segment column.
CDFA DEC B Step B back.
CDFB RET Z Return if the zero flag is set.
ReadSegmentShapes_Position CDFC SUB $18 Subtract 18 from A.
CDFE DJNZ ReadSegmentShapes_Position Decrease B and jump to ReadSegmentShapes_Position until none remain.
CE00 LD ($CE43),A Update the segment column.
CE03 RET Return.
Prev: CD08 Up: Map Next: CE04