Prev: 52488 Up: Map Next: 52740
52587: 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 52587 LD A,(52791) The vertical step.
52590 AND A Jump to ReadSegmentShapes_Store if A is not zero.
52591 JR NZ,ReadSegmentShapes_Store
52593 LD A,(23590) The upside down flag.
52596 AND A Jump to ReadSegmentShapes_BackToFront if A is zero.
52597 JR Z,ReadSegmentShapes_BackToFront
52599 LD A,(52804) The segment row.
52602 XOR %00001100 Flip the bits of A that are set in 12.
52604 LD (52804),A Update the segment row.
ReadSegmentShapes_BackToFront 52607 LD A,(23600) The back to front flag.
52610 AND A Jump to ReadSegmentShapes_Normal if A is zero.
52611 JR Z,ReadSegmentShapes_Normal
52613 LD A,(HL) Read HL.
52614 XOR %00000010 Flip the bits of A that are set in 2.
52616 LD (23604),A Update the segment end shape.
52619 INC HL Advance HL.
52620 LD A,(HL) Read HL.
52621 CP 22 Jump to ReadSegmentShapes_End if A is 22.
52623 JR Z,ReadSegmentShapes_End
52625 XOR %00000010 Flip the bits of A that are set in 2.
52627 LD (23603),A Update the segment start shape.
52630 INC HL Advance HL.
52631 JR ReadSegmentShapes_UpsideDown Jump to ReadSegmentShapes_UpsideDown.
ReadSegmentShapes_End 52633 LD (23604),A Update the segment end shape.
52636 INC HL Advance HL.
52637 JR ReadSegmentShapes_UpsideDown Jump to ReadSegmentShapes_UpsideDown.
ReadSegmentShapes_Normal 52639 LD A,(HL) Read HL.
52640 LD (23603),A Update the segment start shape.
52643 INC HL Advance HL.
52644 LD A,(HL) Read HL.
52645 LD (23604),A Update the segment end shape.
52648 INC HL Advance HL.
ReadSegmentShapes_UpsideDown 52649 LD A,(23590) The upside down flag.
52652 AND A Jump to ReadSegmentShapes_Store if A is zero.
52653 JR Z,ReadSegmentShapes_Store
52655 LD A,(23603) The segment start shape.
52658 XOR %00000001 Flip the bits of A that are set in 1.
52660 LD (23603),A Update the segment start shape.
52663 LD A,(23604) The segment end shape.
52666 CP 22 Jump to ReadSegmentShapes_Store if A is 22.
52668 JR Z,ReadSegmentShapes_Store
52670 XOR %00000001 Flip the bits of A that are set in 1.
52672 LD (23604),A Update the segment end shape.
ReadSegmentShapes_Store 52675 LD (52813),HL Update the script pointer.
52678 LD A,(23600) The back to front flag.
52681 AND A Return if A is zero.
52682 RET Z
52683 LD A,(23604) The segment end shape.
52686 CP 22 Return if A is 22.
52688 RET Z
52689 LD A,(52803) The segment column.
52692 LD B,A B=A.
52693 LD A,(23589) The horizontal step size.
52696 ADD A,B A gains B.
52697 ADD A,15 Add 15 to A.
52699 CPL Invert A.
52700 LD (52803),A Update the segment column.
52703 EXX Switch to the alternate registers.
52704 LD E,(IX+3) Read offset 3 of IX into E.
52707 LD D,0 Clear D.
52709 LD HL,52740 The mirror type table.
52712 ADD HL,DE HL gains DE.
52713 LD A,(HL) Read HL.
52714 LD (IX+3),A Write A to offset 3 of IX.
52717 CALL SetSlopeParameters Call SetSlopeParameters.
52720 EXX Switch to the alternate registers.
52721 LD A,(52791) The vertical step.
52724 AND A Return if A is not zero.
52725 RET NZ
52726 LD B,C B=C.
52727 LD A,(52803) The segment column.
52730 DEC B Step B back.
52731 RET Z Return if the zero flag is set.
ReadSegmentShapes_Position 52732 SUB 24 Subtract 24 from A.
52734 DJNZ ReadSegmentShapes_Position Decrease B and jump to ReadSegmentShapes_Position until none remain.
52736 LD (52803),A Update the segment column.
52739 RET Return.
Prev: 52488 Up: Map Next: 52740