Prev: D319 Up: Map Next: D588
D3D2: Set Up Piece
Used by the routine at NextStep.
Sets up the drawing of the piece of picture for a step of a segment. Normally the routine for the type of the segment and the address of its picture are looked up in the table at ShapeTablePointer (four bytes for each type: the routine, which goes into IY, and the picture) and the screen address for the start of the piece is found with FindSegmentAddress. Then, depending on the type of the segment and where on the screen it is, the routine sets the displacement of the jump at JumpToDrawingRoutine_Jump (in D702) to choose a routine, and changes the instructions of the drawing routines to suit. Steps that were set up already start at SetUpPiece_Type.
Input
HL Address of the entry for the step in the table at ColumnPhaseTable
IX Address of the drawing record at ScrollWorld_Record
SetUpPiece D3D2 LD E,(HL) Read HL into E.
D3D3 LD A,(IX+$01) Read offset 01 of IX.
D3D6 AND A Jump to SetUpPiece_Type if A is not zero.
D3D7 JP NZ,SetUpPiece_Type
SetUpPiece_Table D3DA EXX Switch to the alternate registers.
D3DB LD HL,($CCBD) Fetch the word at ShapeTablePointer into HL.
D3DE LD E,(IX+$03) Read offset 03 of IX into E.
D3E1 LD D,$00 Clear D.
D3E3 SLA E Shift E left.
D3E5 SLA E Shift E left.
D3E7 ADD HL,DE HL gains DE.
D3E8 LD C,(HL) Read HL into C.
D3E9 INC HL Advance HL.
D3EA LD B,(HL) Read HL into B.
D3EB INC HL Advance HL.
D3EC PUSH BC Stash BC on the stack.
D3ED POP IY Bring IY back off the stack.
D3EF LD C,(HL) Read HL into C.
D3F0 INC HL Advance HL.
D3F1 LD B,(HL) Read HL into B.
D3F2 LD ($CE47),BC Update the picture pointer.
D3F6 LD A,($CE5A) The vertical step copy.
D3F9 SRL A Shift A right.
D3FB LD ($CE40),A Update the segment height.
D3FE CALL FindSegmentAddress Call FindSegmentAddress.
D401 LD A,($CE36) The column step.
D404 LD B,A B=A.
D405 LD A,L A=L.
D406 SUB B Subtract B from A.
D407 LD L,A L=A.
D408 LD ($CE49),HL Update the segment screen address.
D40B LD DE,($CE4B) Fetch the word at PictureOffsetsPointer into DE.
D40F LD A,(IX+$03) Read offset 03 of IX.
D412 CP $07 Jump to SetUpPiece_Offsets if A is less than 07.
D414 JR C,SetUpPiece_Offsets
D416 SUB $07 Subtract 07 from A.
SetUpPiece_Offsets D418 ADD A,A Double A.
D419 LD H,A H=A.
D41A ADD A,A Double A.
D41B ADD A,H A gains H.
D41C LD L,A L=A.
D41D LD H,$00 Clear H.
D41F ADD HL,DE HL gains DE.
D420 LD ($CE51),HL Update the segment picture offsets.
D423 EXX Switch to the alternate registers.
D424 XOR A Clear A.
D425 LD D,A D=A.
D426 LD ($D480),A Shorten the piece by one column.
D429 LD A,(IX+$00) Read offset 00 of IX.
D42C AND %00000111 Keep the bits of A that are set in 07.
D42E JR NZ,SetUpPiece_Type Jump to SetUpPiece_Type if the zero flag is clear.
D430 LD A,$01 A=01.
D432 LD ($D480),A Keep the width of the piece.
SetUpPiece_Type D435 LD A,($CE59) The horizontal step copy.
D438 AND A Jump to SetUpPiece_Slope if A is not zero.
D439 JR NZ,SetUpPiece_Slope
D43B LD A,D A=D.
D43C AND A Jump to LocatePicture if A is not zero.
D43D JP NZ,LocatePicture
D440 LD A,($E41B) The slope direction.
D443 NEG Negate A.
D445 ADD A,A Double A.
D446 ADD A,A Double A.
D447 ADD A,A Double A.
D448 LD ($CE35),A Update the horizontal step.
Flat segments are handled at SetUpFlatPiece.
SetUpPiece_Slope D44B XOR A Clear A.
D44C LD ($D702),A Use the routine in IY.
D44F LD A,($CE37) The vertical step.
D452 AND A Jump to SetUpFlatPiece if A is zero.
D453 JP Z,SetUpFlatPiece
D456 LD A,($5C2C) The segment screen column.
D459 CP $D1 Jump to SetUpPiece_Left if A is less than D1.
D45B JP C,SetUpPiece_Left
D45E LD B,A B=A.
D45F LD A,($CE35) The horizontal step.
The displacement of this jump is set by SetSlopeParameters: it is zero when the second step of the slope is negative, so that the next instruction is run, and two otherwise, to skip it.
SetUpPiece_Patched D462 JR SetUpPiece_Patched Skip ahead by the displacement at D463.
D464 NEG Negate A.
D466 ADD A,B A gains B.
D467 CP $E9 Jump to SetUpPiece_Left if A is less than E9.
D469 JP C,SetUpPiece_Left
D46C LD A,B A=B.
D46D CP $E0 Jump to SetUpPiece_Reverse if A is less than E0.
D46F JR C,SetUpPiece_Reverse
D471 LD A,($E41B) The slope direction.
D474 CP $01 Jump to SetUpPiece_Edge if A is 01.
D476 JR Z,SetUpPiece_Edge
D478 LD A,($CE36) The column step.
D47B LD B,A B=A.
D47C LD A,$21 A=21.
D47E SUB B Subtract B from A.
SetUpPiece_ShortPatch D47F JR SetUpPiece_ShortPatch Skip ahead by the displacement at D480.
D481 DEC A Step A back.
D482 LD ($DB92),A Whether the second byte of the slope row is skipped.
D485 LD A,$02 A=02.
D487 LD ($D702),A Draw the slope rows.
D48A LD A,($CE59) The horizontal step copy.
D48D AND A Call AdvanceScreenAddress if A is zero.
D48E CALL Z,AdvanceScreenAddress
D491 JP LocatePicture Jump to LocatePicture.
SetUpPiece_Reverse D494 LD A,($E41B) The slope direction.
D497 CP $01 Jump to SetUpPiece_Draw if A is 01.
D499 JR Z,SetUpPiece_Draw
D49B XOR A Clear A.
D49C LD ($DB92),A Draw both bytes of the slope row.
D49F LD A,$02 A=02.
D4A1 LD ($D702),A Draw the slope rows.
D4A4 JP LocatePicture Jump to LocatePicture.
SetUpPiece_Edge D4A7 LD A,($D480) Whether the piece was shortened.
D4AA LD ($D4B7),A Whether the piece is shortened at the edge.
D4AD LD A,($CE36) The column step.
D4B0 NEG Negate A.
D4B2 LD B,A B=A.
D4B3 LD A,$29 A=29.
D4B5 SUB B Subtract B from A.
SetUpPiece_EdgePatch D4B6 JR SetUpPiece_EdgePatch Skip ahead by the displacement at D4B7.
SetUpPiece_Draw D4B8 DEC A Step A back.
D4B9 LD ($DC5A),A How far to skip along the mirrored row.
D4BC LD A,$05 A=05.
D4BE LD ($D702),A Draw the mirrored slope rows.
D4C1 LD A,($CE59) The horizontal step copy.
D4C4 AND A Call AdvanceScreenAddress if A is zero.
D4C5 CALL Z,AdvanceScreenAddress
D4C8 JP LocatePicture Jump to LocatePicture.
SetUpPiece_Left D4CB LD A,($5C2C) The segment screen column.
D4CE ADD A,$08 Add 08 to A.
D4D0 CP $0F Jump to SetUpPiece_Direction if A is less than 0F.
D4D2 JR C,SetUpPiece_Direction
D4D4 LD A,($CE59) The horizontal step copy.
D4D7 AND A Jump to LocatePicture if A is not zero.
D4D8 JP NZ,LocatePicture
D4DB CALL AdvanceScreenAddress Call AdvanceScreenAddress.
D4DE JP LocatePicture Jump to LocatePicture.
SetUpPiece_Direction D4E1 LD A,($E41B) The slope direction.
D4E4 CP $01 Jump to SetUpPiece_Backwards if A is 01.
D4E6 JR Z,SetUpPiece_Backwards
D4E8 LD A,($CE49) The segment screen address.
D4EB AND %00011111 Keep the bits of A that are set in 1F.
D4ED CP $1D Jump to SetUpPiece_Column29 if A is 1D.
D4EF JR Z,SetUpPiece_Column29
D4F1 CP $1E Jump to SetUpPiece_Column30 if A is 1E.
D4F3 JR Z,SetUpPiece_Column30
SetUpPiece_Flat D4F5 LD A,($CE59) The horizontal step copy.
D4F8 AND A Call AdvanceScreenAddress if A is zero.
D4F9 CALL Z,AdvanceScreenAddress
D4FC LD A,($CE36) The column step.
D4FF LD ($5C2E),A Update the piece column.
D502 LD A,$2C A=2C.
D504 LD ($DBC6),A Skip along the slope row.
SetUpPiece_SetCounts D507 LD A,$01 A=01.
D509 LD ($DBC1),A Skip a word of the picture.
SetUpPiece_SelectEight D50C LD A,$08 A=08.
D50E LD ($D702),A Draw the slope rows from the edge.
D511 JP LocatePicture Jump to LocatePicture.
SetUpPiece_Column29 D514 LD A,$01 A=01.
D516 LD ($5C2E),A Update the piece column.
D519 XOR A Clear A.
D51A LD ($DBC1),A Keep the word of the picture.
D51D LD A,$30 A=30.
D51F LD ($DBC6),A Skip further along the slope row.
D522 JP SetUpPiece_SelectEight Jump to SetUpPiece_SelectEight.
SetUpPiece_Column30 D525 LD A,($D480) Whether the piece was shortened.
D528 CP $01 Jump to SetUpPiece_Flat if A is 01.
D52A JR Z,SetUpPiece_Flat
D52C LD A,($CE36) The column step.
D52F LD ($5C2E),A Update the piece column.
D532 XOR A Clear A.
D533 LD ($DBC6),A Do not skip along the slope row.
D536 JP SetUpPiece_SetCounts Jump to SetUpPiece_SetCounts.
SetUpPiece_Backwards D539 LD A,($CE36) The column step.
D53C LD B,A B=A.
D53D LD A,($CE49) The segment screen address.
D540 SUB B Subtract B from A.
D541 AND %00011111 Keep the bits of A that are set in 1F.
D543 CP $02 Jump to SetUpPiece_Two if A is 02.
D545 JR Z,SetUpPiece_Two
D547 CP $03 Jump to SetUpPiece_Three if A is 03.
D549 JR Z,SetUpPiece_Three
D54B LD A,($D480) Whether the piece was shortened.
D54E CP $01 Jump to SetUpPiece_Two if A is 01.
D550 JR Z,SetUpPiece_Two
D552 XOR A Clear A.
D553 LD ($DC14),A Do not skip along the mirrored slope row.
D556 INC A Advance A.
SetUpPiece_SelectEleven D557 LD ($DC0C),A Whether a word of the mirrored picture is skipped.
D55A LD A,$0B A=0B.
D55C LD ($D702),A Draw the mirrored rows from the edge.
D55F JP LocatePicture Jump to LocatePicture.
SetUpPiece_Two D562 LD A,($CE59) The horizontal step copy.
D565 AND A Call AdvanceScreenAddress if A is zero.
D566 CALL Z,AdvanceScreenAddress
D569 LD A,$26 A=26.
D56B LD ($DC14),A Skip along the mirrored slope row.
D56E LD A,$01 A=01.
D570 JP SetUpPiece_SelectEleven Jump to SetUpPiece_SelectEleven.
SetUpPiece_Three D573 LD A,D A=D.
D574 AND A Jump to SetUpPiece_ThreeBytes if A is not zero.
D575 JR NZ,SetUpPiece_ThreeBytes
D577 LD A,($CE49) The segment screen address.
D57A SUB $20 Subtract 20 from A.
D57C LD ($CE49),A Update the segment screen address.
SetUpPiece_ThreeBytes D57F LD A,$2A A=2A.
D581 LD ($DC14),A Skip further along the mirrored slope row.
D584 XOR A Clear A.
D585 JP SetUpPiece_SelectEleven Jump to SetUpPiece_SelectEleven.
Prev: D319 Up: Map Next: D588