Prev: 54226 Up: Map Next: 54898
54664: 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 58021 and 58026 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 24, 25, 28 or 29) 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 54664 XOR A Clear A.
54665 LD (57946),A Draw the first word of the flat row.
54668 LD (57950),A Draw the second word of the flat row.
54671 LD (57954),A Draw the third word of the flat row.
54674 LD A,(52809) The segment screen address.
54677 AND %00011111 Keep the bits of A that are set in 31.
54679 CP 29 Jump to SetUpFlatPiece_Right if A is 29.
54681 JR Z,SetUpFlatPiece_Right
54683 CP 28 Jump to SetUpFlatPiece_Edge if A is 28.
54685 JR Z,SetUpFlatPiece_Edge
54687 CP 24 Jump to SetUpFlatPiece_Column if A is 24.
54689 JR Z,SetUpFlatPiece_Column
54691 CP 25 Jump to SetUpFlatPiece_Skip if A is 25.
54693 JR Z,SetUpFlatPiece_Skip
54695 LD A,(55389) The edge flag.
54698 AND A Jump to FinishStep_Count if A is not zero.
54699 JP NZ,FinishStep_Count
54702 LD A,(23586) The segment length.
54705 CP C Jump to SetUpFlatPiece_Shape if A is not C.
54706 JR NZ,SetUpFlatPiece_Shape
54708 LD A,(23603) The segment start shape.
54711 CP 16 Jump to SetUpFlatPiece_Shape if A is not 16.
54713 JR NZ,SetUpFlatPiece_Shape
54715 LD A,(52801) The horizontal offset.
54718 AND %00000111 Keep the bits of A that are set in 7.
54720 JR Z,SetUpFlatPiece_Shape Jump to SetUpFlatPiece_Shape if the zero flag is set.
54722 LD A,238 A=238.
54724 JR SetUpFlatPiece_Patch Jump to SetUpFlatPiece_Patch.
SetUpFlatPiece_Right 54726 LD A,51 A=51.
SetUpFlatPiece_Patch 54728 LD (57946),A Skip part of the flat row at the right edge.
54731 XOR A Clear A.
54732 LD (58026),A Draw the right-hand byte.
54735 INC A Advance A.
54736 LD (58021),A Skip the byte before the right-hand byte.
54739 JR SetUpFlatPiece_Shape Jump to SetUpFlatPiece_Shape.
SetUpFlatPiece_Edge 54741 LD A,51 A=51.
54743 LD (57946),A Skip part of the flat row at the edge.
54746 LD A,11 A=11.
54748 LD (58026),A Skip most of the right-hand side.
54751 XOR A Clear A.
54752 LD (58021),A Draw the byte before the right-hand byte.
54755 JR SetUpFlatPiece_Shape Jump to SetUpFlatPiece_Shape.
SetUpFlatPiece_Column 54757 LD A,38 A=38.
54759 LD (57954),A Skip the third word of the flat row.
54762 JR SetUpFlatPiece_Shape Jump to SetUpFlatPiece_Shape.
SetUpFlatPiece_Skip 54764 LD A,36 A=36.
54766 LD (57950),A Skip the second word of the flat row.
SetUpFlatPiece_Shape 54769 LD A,(23586) The segment length.
54772 CP C Jump to SetUpFlatPiece_Last if A is not C.
54773 JP NZ,SetUpFlatPiece_Last
54776 LD A,(23603) The segment start shape.
54779 BIT 4,A Jump to LocatePicture if bit 4 of A is clear.
54781 JP Z,LocatePicture
54784 OR %10000000 Set the bits of A that are set in 128.
54786 LD (23603),A Update the segment start shape.
SetUpFlatPiece_Picture 54789 LD B,A B=A.
54790 CP 150 Jump to SetUpFlatPiece_Edges if A is 150.
54792 JR Z,SetUpFlatPiece_Edges
54794 BIT 0,A Jump to SetUpFlatPiece_Offset if bit 0 of A is clear.
54796 JR Z,SetUpFlatPiece_Offset
54798 CP 145 Compare A with 145.
54800 LD A,(52411) The horizontal scroll speed.
54803 JR Z,SetUpFlatPiece_Direction Jump to SetUpFlatPiece_Direction if the zero flag is set.
54805 NEG Negate A.
SetUpFlatPiece_Direction 54807 BIT 7,A Jump to SetUpFlatPiece_Offset if bit 7 of A is set.
54809 JR NZ,SetUpFlatPiece_Offset
54811 LD A,(IX+0) Read offset 0 of IX.
54814 AND %00000111 Keep the bits of A that are set in 7.
54816 JR NZ,SetUpFlatPiece_Offset Jump to SetUpFlatPiece_Offset if the zero flag is clear.
54818 LD A,B A=B.
54819 LD (23591),A Update the shape flag.
54822 EXX Switch to the alternate registers.
54823 LD HL,(52809) Fetch the word at SegmentScreenAddress into HL.
54826 LD (52815),HL Update the saved screen address.
54829 LD A,(23596) The segment screen column.
54832 LD (23580),A Update the screen column.
54835 EXX Switch to the alternate registers.
54836 JR SetUpFlatPiece_Offset Jump to SetUpFlatPiece_Offset.
SetUpFlatPiece_Edges 54838 LD A,(52809) The segment screen address.
54841 INC A Advance A.
54842 INC A Advance A.
54843 AND %00011111 Keep the bits of A that are set in 31.
54845 CP 28 Jump to FinishStep_Next if A is 28 or more.
54847 JP NC,FinishStep_Next
54850 XOR A Clear A.
54851 LD (57946),A Draw the first word of the flat row.
54854 LD (57954),A Draw the third word of the flat row.
54857 LD A,36 A=36.
54859 LD (57950),A Skip the second word of the flat row.
SetUpFlatPiece_Offset 54862 LD A,B A=B.
54863 AND %00000011 Keep the bits of A that are set in 3.
54865 ADD A,A Double A.
54866 ADD A,A Double A.
54867 LD B,A B=A.
54868 ADD A,A Double A.
54869 ADD A,B A gains B.
54870 ADD A,36 Add 36 to A.
54872 EXX Switch to the alternate registers.
54873 LD E,A E=A.
54874 LD D,0 Clear D.
54876 JR LocatePicture_Address Jump to LocatePicture_Address.
SetUpFlatPiece_Last 54878 LD A,C A=C.
54879 CP 1 Jump to LocatePicture if A is not 1.
54881 JR NZ,LocatePicture
54883 LD A,(23604) The segment end shape.
54886 BIT 4,A Jump to LocatePicture if bit 4 of A is clear.
54888 JR Z,LocatePicture
54890 OR %10000000 Set the bits of A that are set in 128.
54892 LD (23604),A Update the segment end shape.
54895 JP SetUpFlatPiece_Picture Jump to SetUpFlatPiece_Picture.
Prev: 54226 Up: Map Next: 54898