Prev: D7F3 Up: Map Next: D8B2
D833: SERVANT spell - check for retrieval of object from Maroc's backpack
Used by the routine at D7F3.
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 7C00
D833 LD A,($EBB1) Servant object-carrying status flag
D836 CP $00
D838 JP NZ,$D8CC 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)
D83B LD A,($EB00) Horizontal (X) position (in pixels) for servant sprite
D83E LD D,A Store in D register
D83F LD A,($EAFF) Vertical (Y) position (in pixels) for servant sprite
D842 LD E,A Store in E register ready for collision call in 2 instructions
D843 LD C,$00 Collision/event flag to check - 0 = check collision with Maroc sprite
D845 CALL $DFD5 Check if servant sprite is moving over Maroc
D848 CP $00 Flag in A register indicates if collision has occurred (1 = positive collision, 0 = no collision)
D84A JR Z,$D8B2 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 7F72
D84C LD DE,$0010 16 bytes in each inventory object data set
D84F LD B,$04 4 object slots in Maroc's inventory to check
D851 LD HL,($EBBC) Get address pointer for Maroc's inventory at 7F72
D854 LD A,(HL) Get first data byte of this set
D855 CP $00 First byte will be: 0 = Empty slot, or 4 = Interactable object
D857 JR NZ,$D866 Object found - step out of check routine and deal with object
D859 ADD HL,DE No object in this slot - advance address pointer 16 bytes to get to next item slot
D85A LD A,(HL) Check if at end of inventory slots
D85B CP $FF
D85D JR NZ,$D862 ...If not, keep checking inventory slots
D85F LD HL,($EBBA) ...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.
D862 DJNZ $D854 Repeat until all 4 inventory slots have been checked
D864 JR $D8CC Maroc is not carrying anything - jump out to next routine
Item found in inventory. Copy item data from inventory slot at 7F72 into object data buffer at EB43
D866 LD BC,$0010 16 bytes to copy
D869 LD DE,$EB43 Start of working data buffer at EB43.
D86C LDIR Copy the 16 bytes over (HL is currently pointing at the start of the inventory slot where the item's data resides)
D86E LD DE,$FFF0 Subtracts 16 from HL to return the address pointer to the start of this object's inventory slot at 7F72
D871 ADD HL,DE
D872 LD (HL),$00 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 7C00, and the working data buffer is copied into this set.
D874 LD A,($EB4E) Object properties byte
D877 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
D879 AND %11110101 Reset bits 1 (2) = item is hidden and 3 (8) = item is dropped/falling
D87B LD ($EB4E),A ...and re-store
D87E LD A,($EB00) Horizontal (X) position (in pixels) for servant sprite
D881 LD L,$00
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:
D883 RRA Divide by 2
D884 RR L Rotate fraction/overflow bit into low byte of horizontal position address
D886 RRA Divide by 4
D887 RR L Rotate fraction/overflow bit into low byte of horizontal position address
D889 AND $3F Filter out any stray carry bits from the rotate
D88B LD H,A
D88C LD ($EB47),HL Store calculated horizontal position
Set object's vertical pixel position (same as servant's position):
D88F LD A,($EAFF) Vertical (Y) position (in pixels) for servant sprite
D892 LD ($EB4A),A ...copy into object's data buffer
Other object values:
D895 LD A,$00 Set vertical movement speed/direction to 0
D897 LD ($EB4D),A
D89A LD ($EB4C),A Set horizontal movement speed/direction to 0
D89D LD ($EB49),A Reset vertical pixel position fraction byte (will be 0 at this point as servant is on-screen)
D8A0 CALL $DADC Identify object state and prepare graphics for printing
D8A3 CALL $E0B0 Copy object data into data set at 7C00
D8A6 LD (HL),$FF Set end-of-data byte at the start of the next data set
D8A8 LD ($EB72),HL ...and store the address pointer
D8AB LD A,$02 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
D8AD LD ($EBB1),A
D8B0 JR $D8CC Skip to end of next routine
Prev: D7F3 Up: Map Next: D8B2