Prev: 52392 Up: Map Next: 52513
52445: Maroc has picked up an item
Used by the routine at 52338.
There are 4 inventory slots in Maroc's backpack (32626). However, he can only carry 3 objects.
The 4th consecutive slot is used as an 'overflow' slot. This is checked later at 55564. If there's an object in it, Maroc will immediately drop it. So Maroc can actually - but (very) temporarily - carry 4 objects.
Add the collected object to Maroc's inventory:
52445 LD HL,(60348) Address pointer to current slot of Maroc's inventory at 32626
52448 LD A,(HL)
52449 CP 0 Empty inventory slot?
52451 JP NZ,52613 If the slot isn't empty, it may be that the servant has moved the object over Maroc's backpack (rather than Maroc picking it up himself).
If so, and the servant moves slowly enough, it can swap the carried object with the next one in the inventory - so go and check if this is the case.
Empty inventory slot has been found:
52454 LD A,(60238) Get the item properties byte
52457 LD C,A
52458 AND 16 Is the item being carried by the servant (if bit 4 is set)?
52460 JR Z,52473 If not, skip next few instructions
The servant has just put the item in Maroc's backpack. Set item status to 'not carried by servant'
52462 LD A,C Retrieve item properties byte
52463 AND 239 Object is now in Maroc's backpack, so reset bit 4 of its properties byte, as it's no longer carried by the servant.
52465 LD (60238),A ...and re-store the item properties byte
52468 LD A,0
52470 LD (60337),A Set the 'servant-carrying-item' flag to zero
Copy 16 bytes of the item's data from the working buffer at 60227 into the inventory slot (at 32626).
Then move the inventory address pointer to the next available slot.
Next time the servant moves over Maroc's backpack, it will retrieve the next consecutive object.
52473 EX DE,HL Swap inventory address pointer into DE register pair
52474 LD HL,60227 Start of item working data buffer
52477 LD BC,16
52480 LDIR Copy 16 bytes of item data into inventory slot
52482 EX DE,HL HL register pair is now pointing to the start of the next inventory slot
52483 LD A,(HL)
52484 CP 255 Are we at the end of the 4 inventory slots?
52486 JR NZ,52491
52488 LD HL,(60346) If so, switch the inventory pointer back to inventory slot 1
52491 LD (60348),HL Store inventory slot pointer
The next few instructions check if the spell number is >=224. If so a value (240) is subtracted, which sets the amount to increase/decrease Maroc's energy by (from -16 to +15).
No object/spell number is close to this value. It's likely that it was added for the collection of energy giving/reducing items (e.g. food), but not used in favour of the other better energy routines.
52494 LD A,(60298) Get the spell number (normally will be 0 for objects)
52497 CP 224
52499 JR C,52506
52501 SUB 240 If >=224, subtract 240 (would give a value of -16 to +15)...
52503 CALL 58316 ...and increase/decrease Maroc's energy accordingly
This object has now been collected:
52506 LD A,0
52508 LD (60227),A Set it's object type to 0, as it's in Maroc's inventory and no longer in the room
52511 JR 52613
Prev: 52392 Up: Map Next: 52513