Prev: D3D2 Up: Map Next: D672
D588: Set Up Flat Piece
Used by the routine at SetUpPiece.
Sets up the drawing of the piece of picture for a step of a flat segment, which is three bytes wide. The jumps at DrawFlatRows_Next, DrawFlatRows_PatchSecond and DrawFlatRows_PatchThird and the instructions at E2A5 and E2AA of DrawFlatRows are changed when the piece is at the edge of the screen (the column in the bottom five bits of the screen address is 18, 19, 1C or 1D) so that only the part inside the area of the terrain is drawn. The routine then reads the shape at the end of the segment from StartShape and EndShape and finds the picture and the routine that draws it.
Input
C Number of steps left in the segment
IX Address of the drawing record at ScrollWorld_Record
SetUpFlatPiece D588 XOR A Clear A.
D589 LD ($E25A),A Draw the first word of the flat row.
D58C LD ($E25E),A Draw the second word of the flat row.
D58F LD ($E262),A Draw the third word of the flat row.
D592 LD A,($CE49) The segment screen address.
D595 AND %00011111 Keep the bits of A that are set in 1F.
D597 CP $1D Jump to SetUpFlatPiece_Right if A is 1D.
D599 JR Z,SetUpFlatPiece_Right
D59B CP $1C Jump to SetUpFlatPiece_Edge if A is 1C.
D59D JR Z,SetUpFlatPiece_Edge
D59F CP $18 Jump to SetUpFlatPiece_Column if A is 18.
D5A1 JR Z,SetUpFlatPiece_Column
D5A3 CP $19 Jump to SetUpFlatPiece_Skip if A is 19.
D5A5 JR Z,SetUpFlatPiece_Skip
D5A7 LD A,($D85D) The edge flag.
D5AA AND A Jump to FinishStep_Count if A is not zero.
D5AB JP NZ,FinishStep_Count
D5AE LD A,($5C22) The segment length.
D5B1 CP C Jump to SetUpFlatPiece_Shape if A is not C.
D5B2 JR NZ,SetUpFlatPiece_Shape
D5B4 LD A,($5C33) The segment start shape.
D5B7 CP $10 Jump to SetUpFlatPiece_Shape if A is not 10.
D5B9 JR NZ,SetUpFlatPiece_Shape
D5BB LD A,($CE41) The horizontal offset.
D5BE AND %00000111 Keep the bits of A that are set in 07.
D5C0 JR Z,SetUpFlatPiece_Shape Jump to SetUpFlatPiece_Shape if the zero flag is set.
D5C2 LD A,$EE A=EE.
D5C4 JR SetUpFlatPiece_Patch Jump to SetUpFlatPiece_Patch.
SetUpFlatPiece_Right D5C6 LD A,$33 A=33.
SetUpFlatPiece_Patch D5C8 LD ($E25A),A Skip part of the flat row at the right edge.
D5CB XOR A Clear A.
D5CC LD ($E2AA),A Draw the right-hand byte.
D5CF INC A Advance A.
D5D0 LD ($E2A5),A Skip the byte before the right-hand byte.
D5D3 JR SetUpFlatPiece_Shape Jump to SetUpFlatPiece_Shape.
SetUpFlatPiece_Edge D5D5 LD A,$33 A=33.
D5D7 LD ($E25A),A Skip part of the flat row at the edge.
D5DA LD A,$0B A=0B.
D5DC LD ($E2AA),A Skip most of the right-hand side.
D5DF XOR A Clear A.
D5E0 LD ($E2A5),A Draw the byte before the right-hand byte.
D5E3 JR SetUpFlatPiece_Shape Jump to SetUpFlatPiece_Shape.
SetUpFlatPiece_Column D5E5 LD A,$26 A=26.
D5E7 LD ($E262),A Skip the third word of the flat row.
D5EA JR SetUpFlatPiece_Shape Jump to SetUpFlatPiece_Shape.
SetUpFlatPiece_Skip D5EC LD A,$24 A=24.
D5EE LD ($E25E),A Skip the second word of the flat row.
SetUpFlatPiece_Shape D5F1 LD A,($5C22) The segment length.
D5F4 CP C Jump to SetUpFlatPiece_Last if A is not C.
D5F5 JP NZ,SetUpFlatPiece_Last
D5F8 LD A,($5C33) The segment start shape.
D5FB BIT 4,A Jump to LocatePicture if bit 4 of A is clear.
D5FD JP Z,LocatePicture
D600 OR %10000000 Set the bits of A that are set in 80.
D602 LD ($5C33),A Update the segment start shape.
SetUpFlatPiece_Picture D605 LD B,A B=A.
D606 CP $96 Jump to SetUpFlatPiece_Edges if A is 96.
D608 JR Z,SetUpFlatPiece_Edges
D60A BIT 0,A Jump to SetUpFlatPiece_Offset if bit 0 of A is clear.
D60C JR Z,SetUpFlatPiece_Offset
D60E CP $91 Compare A with 91.
D610 LD A,($CCBB) The horizontal scroll speed.
D613 JR Z,SetUpFlatPiece_Direction Jump to SetUpFlatPiece_Direction if the zero flag is set.
D615 NEG Negate A.
SetUpFlatPiece_Direction D617 BIT 7,A Jump to SetUpFlatPiece_Offset if bit 7 of A is set.
D619 JR NZ,SetUpFlatPiece_Offset
D61B LD A,(IX+$00) Read offset 00 of IX.
D61E AND %00000111 Keep the bits of A that are set in 07.
D620 JR NZ,SetUpFlatPiece_Offset Jump to SetUpFlatPiece_Offset if the zero flag is clear.
D622 LD A,B A=B.
D623 LD ($5C27),A Update the shape flag.
D626 EXX Switch to the alternate registers.
D627 LD HL,($CE49) Fetch the word at SegmentScreenAddress into HL.
D62A LD ($CE4F),HL Update the saved screen address.
D62D LD A,($5C2C) The segment screen column.
D630 LD ($5C1C),A Update the screen column.
D633 EXX Switch to the alternate registers.
D634 JR SetUpFlatPiece_Offset Jump to SetUpFlatPiece_Offset.
SetUpFlatPiece_Edges D636 LD A,($CE49) The segment screen address.
D639 INC A Advance A.
D63A INC A Advance A.
D63B AND %00011111 Keep the bits of A that are set in 1F.
D63D CP $1C Jump to FinishStep_Next if A is 1C or more.
D63F JP NC,FinishStep_Next
D642 XOR A Clear A.
D643 LD ($E25A),A Draw the first word of the flat row.
D646 LD ($E262),A Draw the third word of the flat row.
D649 LD A,$24 A=24.
D64B LD ($E25E),A Skip the second word of the flat row.
SetUpFlatPiece_Offset D64E LD A,B A=B.
D64F AND %00000011 Keep the bits of A that are set in 03.
D651 ADD A,A Double A.
D652 ADD A,A Double A.
D653 LD B,A B=A.
D654 ADD A,A Double A.
D655 ADD A,B A gains B.
D656 ADD A,$24 Add 24 to A.
D658 EXX Switch to the alternate registers.
D659 LD E,A E=A.
D65A LD D,$00 Clear D.
D65C JR LocatePicture_Address Jump to LocatePicture_Address.
SetUpFlatPiece_Last D65E LD A,C A=C.
D65F CP $01 Jump to LocatePicture if A is not 01.
D661 JR NZ,LocatePicture
D663 LD A,($5C34) The segment end shape.
D666 BIT 4,A Jump to LocatePicture if bit 4 of A is clear.
D668 JR Z,LocatePicture
D66A OR %10000000 Set the bits of A that are set in 80.
D66C LD ($5C34),A Update the segment end shape.
D66F JP SetUpFlatPiece_Picture Jump to SetUpFlatPiece_Picture.
Prev: D3D2 Up: Map Next: D672