Prev: 9B6C Up: Map Next: 9BCD
9B96: How much room is left in a room?
Returns in A the free space in room A: byte 1 of the room record is the room's capacity, from which the size (byte 2) of every ordinary object there is subtracted. Returns 0 if the room is overfull.
Input
A Room
Output
A Free space
9B96 PUSH IX Save IX, IY and BC
9B98 PUSH IY
9B9A PUSH BC
9B9B LD B,A B = the room being asked about
9B9C CALL $9B0C IX = its own record
9B9F LD A,(IX+$01) C = its own total capacity
9BA2 LD C,A
9BA3 LD IX,$BF50 Search every object in the game...
9BA7 CALL $9AEE Look at the next one; IY = its own record
9BAA JR Z,$9BC2 No more objects: finished (below)
9BAC LD A,(IY+$00) Is it an ordinary, single-place object?
9BAF CP $01
9BB1 JR NZ,$9BA7 No (e.g. a door): does not count towards the room's capacity
9BB3 LD A,B Is it actually in the room we are asking about?
9BB4 CP (IY+$10)
9BB7 JR NZ,$9BA7 No: skip it
9BB9 LD A,C Yes: subtract its own size from the space left
9BBA SUB (IY+$02)
9BBD JR C,$9BC9 Already overfull: give up with 0 space left
9BBF LD C,A Otherwise keep the smaller total
9BC0 JR $9BA7 Look for more objects
9BC2 LD A,C A = the space left
9BC3 POP BC Restore BC, IY and IX
9BC4 POP IY
9BC6 POP IX
9BC8 RET
9BC9 LD C,$00 Overfull: 0 space left
9BCB JR $9BC2
Prev: 9B6C Up: Map Next: 9BCD