Prev: 55283 Up: Map Next: 55474
55347: SERVANT spell - check for retrieval of object from Maroc's backpack
Used by the routine at 55283.
Player is using the SERVANT spell.
  • Check if the servant is moving over Maroc's backpack area
  • If so, identify the item to retrieve, and set up a new room item in the data sets at 31744
55347 LD A,(60337) Servant object-carrying status flag
55350 CP 0
55352 JP NZ,55500 If this byte ISN'T 0, the servant is carrying an object - if so, jump to the end of this routine.
Check if the servant is over Maroc's sprite (for retrieving objects from his backpack)
55355 LD A,(60160) Horizontal (X) position (in pixels) for servant sprite
55358 LD D,A Store in D register
55359 LD A,(60159) Vertical (Y) position (in pixels) for servant sprite
55362 LD E,A Store in E register ready for collision call in 2 instructions
55363 LD C,0 Collision/event flag to check - 0 = check collision with Maroc sprite
55365 CALL 57301 Check if servant sprite is moving over Maroc
55368 CP 0 Flag in A register indicates if collision has occurred (1 = positive collision, 0 = no collision)
55370 JR Z,55474 If not (servant is not moving over Maroc) skip the next few sets of instructions
Servant is moving over Maroc. Check object sets in Maroc's backpack inventory at 32626
55372 LD DE,16 16 bytes in each inventory object data set
55375 LD B,4 4 object slots in Maroc's inventory to check
55377 LD HL,(60348) Get address pointer for Maroc's inventory at 32626
55380 LD A,(HL) Get first data byte of this set
55381 CP 0 First byte will be: 0 = Empty slot, or 4 = Interactable object
55383 JR NZ,55398 Object found - step out of check routine and deal with object
55385 ADD HL,DE No object in this slot - advance address pointer 16 bytes to get to next item slot
55386 LD A,(HL) Check if at end of inventory slots
55387 CP 255
55389 JR NZ,55394 ...If not, keep checking inventory slots
55391 LD HL,(60346) ...If so, restore the address pointer to the first slot and continue checking.
Objects rotate round so the check doesn't end at slot 4, but only when 4 slots are checked - e.g. the check may have started with slot 3.
55394 DJNZ 55380 Repeat until all 4 inventory slots have been checked
55396 JR 55500 Maroc is not carrying anything - jump out to next routine
Item found in inventory. Copy item data from inventory slot at 32626 into object data buffer at 60227
55398 LD BC,16 16 bytes to copy
55401 LD DE,60227 Start of working data buffer at 60227.
55404 LDIR Copy the 16 bytes over (HL is currently pointing at the start of the inventory slot where the item's data resides)
55406 LD DE,65520 Subtracts 16 from HL to return the address pointer to the start of this object's inventory slot at 32626
55409 ADD HL,DE
55410 LD (HL),0 As the servant has removed the object from Maroc's backpack, it's no longer in his inventory, so set the first byte of the inventory slot to zero
The next routine initializes the object's data (including X/Y screen co-ordinates) based on the servant sprite's X/Y position
An item set is then created at 31744, and the working data buffer is copied into this set.
55412 LD A,(60238) Object properties byte
55415 OR %01010101 Set:
  • bit 0 (1) = item visible on-screen
  • bit 2 (4) = item will need erasing
  • bit 4 (16) = item is being carried by servant
  • bit 6 (64) = item is portable
55417 AND %11110101 Reset bits 1 (2) = item is hidden and 3 (8) = item is dropped/falling
55419 LD (60238),A ...and re-store
55422 LD A,(60160) Horizontal (X) position (in pixels) for servant sprite
55425 LD L,0
Set object's horizontal position. This is in 4-pixel/half-character steps, so calculate this position by dividing the servant's horizontal pixel position by 4:
55427 RRA Divide by 2
55428 RR L Rotate fraction/overflow bit into low byte of horizontal position address
55430 RRA Divide by 4
55431 RR L Rotate fraction/overflow bit into low byte of horizontal position address
55433 AND 63 Filter out any stray carry bits from the rotate
55435 LD H,A
55436 LD (60231),HL Store calculated horizontal position
Set object's vertical pixel position (same as servant's position):
55439 LD A,(60159) Vertical (Y) position (in pixels) for servant sprite
55442 LD (60234),A ...copy into object's data buffer
Other object values:
55445 LD A,0 Set vertical movement speed/direction to 0
55447 LD (60237),A
55450 LD (60236),A Set horizontal movement speed/direction to 0
55453 LD (60233),A Reset vertical pixel position fraction byte (will be 0 at this point as servant is on-screen)
55456 CALL 56028 Identify object state and prepare graphics for printing
55459 CALL 57520 Copy object data into data set at 31744
55462 LD (HL),255 Set end-of-data byte at the start of the next data set
55464 LD (60274),HL ...and store the address pointer
55467 LD A,2 Servant-carrying-object flag. Normally set to 1 if carrying an object, but set to 2 here until the servant moves out of Maroc's backpack 'hit box' area
Otherwise inventory items would continuously/quickly cycle through the slots, swapping objects
55469 LD (60337),A
55472 JR 55500 Skip to end of next routine
Prev: 55283 Up: Map Next: 55474