Prev: ECBD Up: Map Next: EDB8
ED47: Sort one object into the redraw of a region: in front, behind, or out of it
Used by the routine at REDRAW_OBJECT.
Called by REDRAW_OBJECT for each object record but the one being redrawn (THIS_RECORD), with IX at the record and D, E, C the redrawn object's far corner and floor (FAR_CORNER). The region is the rectangle of screen being rebuilt, the redrawn object's own box with three rows more above and below it: its x at IY+$64, its top row at IY+$65 (y counts up the screen), its width in pixels at IY+$66 and its height at IY+$67. An object that does not overlap the region, or has no sprite, is left out. One that overlaps it and stands in front of the redrawn object (IS_IN_FRONT) has its cover drawn at once into page $D8 (DRAW_SPRITE, mode 0), which tells the compositor (COMPOSITE_TO_SCREEN) to leave the screen as it is there. One behind goes onto the list at page $DA for SORT_AND_DRAW_BEHIND to sort and draw. Krumlinde's name for it is Cull_TestObject.
What counts depends on the pass. Normally (bit 4 of IY+$17 clear) scenery -- an object whose +$10 has bits 0-4 clear, drawn once as the room was entered and so already in the clean copy of the screen (LOADING_TUNE) -- goes on the list but does not by itself ask for the list to be drawn: only a live object behind sets bit 1 of IY+$71. In the scenery pass as a room is entered (bit 4 set, ROOMST) live objects are left out altogether, since they are drawn later, and anything behind asks for the list. A door (type 1 in +$0C) skips both tests; anything taken out of the room (bit 5 of +$10: carried, or destroyed) is never drawn.
Input
IX An object record
D The redrawn object's far edge along +6
E Its floor
C Its far edge along +8
CULL_OBJECT ED47 LD A,(IX+OBJ_KIND) A door skips the flag tests
ED4A AND $0F
ED4C CP $01
ED4E JR Z,CULL_OBJECT_1
ED50 BIT 4,(IY+GAME_FLAGS-V) In the scenery pass, leave out live objects
ED54 JR Z,CULL_OBJECT_0
ED56 LD A,(IX+OBJ_WEIGHT)
ED59 AND $1F
ED5B RET NZ
CULL_OBJECT_0 ED5C BIT 5,(IX+OBJ_WEIGHT) Leave out anything taken out of the room
ED60 RET NZ
CULL_OBJECT_1 ED61 LD A,(IX+OBJ_SCREEN_X) Across: out if the object lies wholly right or wholly left of the region
ED64 SUB (IY+POINT-V)
ED67 JR C,CULL_OBJECT_2
ED69 SUB (IY+SECOND_POINT-V)
ED6C RET NC
ED6D JR CULL_OBJECT_3
CULL_OBJECT_2 ED6F ADD A,(IX+OBJ_WIDTH)
ED72 RET NC
ED73 RET Z
CULL_OBJECT_3 ED74 LD A,(IX+OBJ_SCREEN_Y) Down: y is the top row and the sprite hangs +3 rows below it; out if wholly below or above
ED77 SUB (IY+POINT_ROW-V)
ED7A JR C,CULL_OBJECT_4
ED7C SUB (IX+OBJ_ROWS)
ED7F RET NC
ED80 JR CULL_OBJECT_5
CULL_OBJECT_4 ED82 ADD A,(IY+SECOND_POINT_ROW-V)
ED85 RET NC
ED86 RET Z
CULL_OBJECT_5 ED87 LD A,(IX+OBJ_SPRITE) No sprite, nothing to draw
ED8A OR (IX+OBJ_SPRITE+$01)
ED8D RET Z
ED8E CALL IS_IN_FRONT In front of the redrawn object: its cover into page $D8, and done
ED91 XOR A
ED92 BIT 0,(IY+WORK_DIRECTION-V)
ED96 JP NZ,DRAW_SPRITE
ED99 LD A,(RIDE_DIRECTION) Behind it: its number onto the list at page $DA; IY+$7F, which REDRAW_OBJECT sets to $FF, holds the last entry's index
ED9C INC A
ED9D LD (RIDE_DIRECTION),A
EDA0 LD H,$DA
EDA2 LD L,A
EDA3 LD A,(DRAW_INDEX)
EDA6 LD (HL),A
EDA7 BIT 4,(IY+GAME_FLAGS-V) Scenery behind does not need the list drawn, except in the scenery pass
EDAB JR NZ,CULL_OBJECT_6
EDAD LD A,(IX+OBJ_WEIGHT)
EDB0 AND $1F
EDB2 RET Z
CULL_OBJECT_6 EDB3 SET 1,(IY+WORK_DIRECTION-V) The list has something to draw
EDB7 RET
Prev: ECBD Up: Map Next: EDB8