Prev: 44923 Up: Map Next: 45212
45033: Build Ship
Used by the routines at RunFrame and BeginLife.
Builds the graphic of the ship from the parts that have been fitted. Copies the base of the ship to ShipWorkArea_ShipGraphic and adds each of the nine parts that are flagged at CurrentPlayerState_Parts with AddShipPart. Then works out the height of the ship from the parts, the position of the buffer to draw it from and the vertical position of the ship.
BuildShip 45033 LD A,(62958) The number stored for the first part.
45036 ADD A,A Double that number.
45037 LD (62959),A Use the double as the second part's number.
45040 LD A,2 Both scroll limits start at two.
45042 LD (23614),A The horizontal limit.
45045 LD (23615),A The vertical limit.
45048 LD BC,84 The base graphic is 84 bytes.
45051 LD DE,63317 The ship graphic is built at ShipWorkArea_ShipGraphic.
45054 LD HL,51345 The base graphic is at ShipBaseGraphic.
45057 LDIR Copy the base graphic into the buffer.
45059 LD IX,62958 The nine part flags start at CurrentPlayerState_Parts.
45063 LD A,14 The ship starts 14 rows tall.
45065 LD (49577),A That height.
45068 LD B,9 Nine parts.
BuildShip_Loop 45070 PUSH BC Keep the part count.
45071 LD A,(IX+0) This part's number.
45074 AND A Add the part when a number is stored.
45075 CALL NZ,AddShipPart
45078 INC IX The next part flag.
45080 POP BC Back to the part count.
45081 DJNZ BuildShip_Loop Repeat for all nine parts.
45083 LD A,(49577) The height of the ship.
45086 LD B,A B=A.
45087 LD A,40 A=40.
45089 SUB B Subtract B from A.
45090 ADD A,A Double A.
45091 LD E,A E=A.
45092 ADD A,A Double A.
45093 ADD A,E A gains E.
45094 LD E,A E=A.
45095 LD D,0 Clear D.
45097 LD HL,63161 The ship work area.
45100 ADD HL,DE HL gains DE.
45101 LD (49578),HL Update the ship buffer address.
45104 LD A,(51459) The row the ship was drawn on.
45107 LD B,A B=A.
45108 LD A,(49577) The height of the ship.
45111 SUB 14 Subtract 14 from A.
45113 ADD A,111 Add 111 to A.
45115 OR %00000111 Set the bits of A that are set in 7.
45117 LD (51459),A Update the row the ship was drawn on.
45120 SUB B Subtract B from A.
45121 LD (51438),A Update the high byte of the ship's vertical speed.
45124 LD IX,51429 The ship.
45128 CALL FindVerticalMove Call FindVerticalMove.
45131 LD (IX+4),H Write H to offset 4 of IX.
45134 LD (IX+5),L Write L to offset 5 of IX.
45137 CALL SetShipSpeeds Call SetShipSpeeds.
45140 LD A,(49577) The height of the ship.
45143 LD B,A B=A.
45144 LD A,(IX+30) Read offset 30 of IX.
45147 SUB B Subtract B from A.
45148 ADD A,9 Add 9 to A.
45150 LD (23608),A Update the ship row.
45153 LD A,(62961) The flag at 62961.
45156 AND A Leave the horizontal limit at two when it is clear.
45157 JR Z,BuildShip_Limit
45159 LD A,4 A fitted part raises the limit to four.
45161 LD (23614),A The horizontal limit.
BuildShip_Limit 45164 LD A,(62962) The flag at 62962.
45167 AND A Leave the vertical limit at two when it is clear.
45168 JR Z,BuildShip_Carried
45170 LD A,4 A fitted part raises the limit to four.
45172 LD (23615),A The vertical limit.
BuildShip_Carried 45175 LD A,(62977) The carried item.
45178 INC A Advance A.
45179 JR Z,BuildShip_Last Jump to BuildShip_Last if the zero flag is set.
45181 DEC A Step A back.
45182 OR %11000000 Set the bits of A that are set in 192.
45184 LD (51460),A Update the item the ship is about to pick up.
45187 CALL AttachItemToShip Call AttachItemToShip.
45190 XOR A Clear A.
45191 LD (51460),A Update the item the ship is about to pick up.
BuildShip_Last 45194 LD A,(62966) The ninth part flag.
45197 AND A Jump to BuildStackGraphic if A is zero.
45198 JP Z,BuildStackGraphic
45201 LD A,(49577) The height of the ship.
45204 ADD A,11 Add 11 to A.
45206 LD (49577),A Update the height of the ship.
45209 JP BuildStackGraphic Jump to BuildStackGraphic.
Prev: 44923 Up: Map Next: 45212