Prev: D26E Up: Map Next: D325
D27D: Drawing checks and routines for all on-screen room items
Used by the routines at C89F, C8DC, C99B, CAB4, CD66, CE71, CF99, D019, D04B, D07C, D12E, D161, D179, D1D2, D1FF, D21B and D23B.
This routine is run after each room scenery object/item data set has been set up ready for printing. It:
  • Checks if items need printing (on-screen, not hidden)
  • Erases item graphics if needed
  • Calculate and set item colours/attributes
  • Prints/draws the item's attribute colours and then pixels (CALLs to E3FD and DB98)
D27D LD A,($EB4E) Item properties byte
D280 LD C,A
D281 AND $07 Just the lowest 3 bits (bits 0-2) needed for this check
D283 CP $05 Bit 0 (1) = the item is on screen, bit 2 (4) = the item will need erasing
D285 JR NZ,$D2AA If both conditions are met, continue and erase it. Otherwise there's no need so skip the next set of instructions.
Item is on-screen and needs erasing:
D287 LD A,$00 Set the draw/erase flag to 0 (ERASE)
D289 LD ($EACF),A
D28C LD HL,($EACD) Get address pointer for the item graphic to erase
D28F CALL $DB98 ...And erase the graphic
D292 LD A,($EAA8) Get INK colour of room item/object
D295 CP $00 If it's zero, it's an erased scenery room item (rather than a differently coloured object), so there's no need to specially print colours/attributes for it
D297 JR Z,$D29C
D299 CALL $E3FD Otherwise, will need to set the screen attributes/colours for the object
D29C LD A,($EAD5) Get the 'graphic visible' flag (1 = graphic drawn, 0 = graphic not drawn as fully off-screen)
D29F LD C,A ...Store in C register
D2A0 LD A,($EB4E) Get item properties byte
D2A3 AND $FE Filter out (reset) bit 0
D2A5 OR C ...append the 'graphic visible' flag to bit 0 to indicate if the graphic is on screen or not
D2A6 LD ($EB4E),A ...and re-store
D2A9 LD C,A Copy the item properties byte (EB4E) into the C register
Check if the item needs drawing
D2AA LD A,($EB43) Type of graphic to draw
D2AD CP $00
D2AF JR Z,$D325 If this has been set to zero, the item is no longer visible or in existence - there's nothing to draw
D2B1 LD A,C Retrieve item properties byte
D2B2 AND $05 Check for bit 0 (item is visible) and bit 2 (item has moved/needs erasing)
D2B4 JR Z,$D325 If neither is set, there's nothing to draw, so skip the rest of the routine
Set up item for drawing
D2B6 LD A,($EB4A) Graphic vertical position within current room, in pixels, from top of room playing area
D2B9 LD ($EAD2),A Copy to working graphics data buffer
D2BC LD HL,($EACB) Graphic's horizontal position, in pixels
D2BF LD ($EAD3),HL Copy to working graphics data buffer
D2C2 LD A,($EB4B) Room type byte - this is set to 64 for 'standard' rooms, or 254/255 for tunnel rooms
D2C5 LD ($EAD6),A Copy to working graphics data buffer
D2C8 LD A,$01
D2CA LD ($EACF),A Set draw/erase flag to 1 (DRAW)
D2CD LD A,C Retrieve item properties byte from C register
D2CE AND $02 Bit 1 (2) if set means item is hidden/not-visible, e.g. inside a chest
D2D0 JR Z,$D2D7
D2D2 LD HL,($EAF3) If this is the case, set the graphics address pointer to the 'dummy' graphic (98B9), so that nothing actually gets drawn
D2D5 JR $D315 As nothing will be drawn, can also skip over the next section dealing with the item's colours/attributes
Set attribute colours for this item
D2D7 LD A,($EAA8) Get item colour byte
D2DA CP $00 This is set for interactable items and creatures but 0 for most other things such as scenery (which is drawn with standard room colours)
D2DC JR Z,$D312 If it's set to 0, don't need to print any colours
D2DE CP $08 Is the value 7 or less ('standard' INK colours)
D2E0 JR C,$D2E9 If so, can skip the next 3 instructions
If bit 3 (8) is set, it means this object flashes (changes colour). Use the game cycle timer to determine its INK colour at this exact moment:
D2E2 LD A,($EAAA) Get game counter/timer
D2E5 AND $03 Keep just bits 0 and 1 (values = 0-3)
D2E7 ADD A,$04 Add 4, to give an INK value between 4 (green) and 7 (white)
Set object colour:
D2E9 AND $07 Only need to keep bits 0-2 (values = 0-7)
D2EB OR $40 Set BRIGHT bit for the colour (all on-screen/viewport colours are set to BRIGHT 1)
D2ED LD C,A Store item (INK) colour in C register
Check if object graphic INK colour is the same as the current screen PAPER colour (if so, it'd be invisible):
D2EE LD A,($EAA9) Get room attribute colour
D2F1 LD B,A Temp store in B register
D2F2 RRA Shift bits so that the PAPER colour becomes an INK value to compare
D2F3 RRA
D2F4 RRA
D2F5 AND $07 Filter out everything other than INK bits
D2F7 OR $40 Set BRIGHT bit
D2F9 CP C Compare with object colour
D2FA JR NZ,$D301 If different, all is fine, skip next two instructions
Item INK colour is the same as screen PAPER colour.
This shouldn't really happen; most portable objects like keys are light colours (screens have dark backgrounds) and other objects like chests can't be moved from room to room:
D2FC LD HL,($EAF3) If it does happen, set the graphics address pointer to the 'dummy' graphic (98B9), so nothing gets drawn (the item would appear invisible anyway)
D2FF JR $D315 ...and skip to drawing the actual graphic (pixels)
As screen PAPER background colours vary, we need to combine the object attribute INK colour with the current screen PAPER colour:
D301 LD A,B Retrieve the room colour attribute value (stored in PAPER bits)
D302 AND $F8 Filter out/clear any INK bits
D304 OR C Append the item's INK bits (0-7)
D305 LD ($EAA8),A ...and re-store as the item's colour
Print the item's attribute colours on screen (this is done before drawing the actual pixels):
D308 LD A,($EAD4) Get the horizontal position high byte - this indicates whether the object is within the current screen viewport
D30B CP $00
D30D JR NZ,$D312 If not, no need to print attributes, skip the next instruction
D30F CALL $E3FD Print screen attribute colours for the room object/creature
Now draw the item's graphics (pixels):
D312 LD HL,($EB51) Graphic address pointer
D315 CALL $DB98 Draw the item graphics
D318 LD A,($EAD5) Get the visible graphic flag (1 = graphic drawn, 0 = graphic not drawn as fully off-screen)
D31B LD C,A Append this flag (1/0) into bit 0 of the item properties byte at EB4E indicating whether this item is visible on screen
D31C LD A,($EB4E)
D31F AND $FE Filter out bit 0 from the item properties byte
D321 OR C Append a 0 or 1 accordingly (not on-screen/on-screen)
D322 LD ($EB4E),A ...and re-store the item properties byte.
Prev: D26E Up: Map Next: D325