Routines |
Prev: 53870 | Up: Map | Next: 54053 |
This routine is run after each room scenery object/item data set has been set up ready for printing. It:
|
||||
53885 | LD A,(60238) | Item properties byte | ||
53888 | LD C,A | |||
53889 | AND 7 | Just the lowest 3 bits (bits 0-2) needed for this check | ||
53891 | CP 5 | Bit 0 (1) = the item is on screen, bit 2 (4) = the item will need erasing | ||
53893 | JR NZ,53930 | 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:
|
||||
53895 | LD A,0 | Set the draw/erase flag to 0 (ERASE) | ||
53897 | LD (60111),A | |||
53900 | LD HL,(60109) | Get address pointer for the item graphic to erase | ||
53903 | CALL 56216 | ...And erase the graphic | ||
53906 | LD A,(60072) | Get INK colour of room item/object | ||
53909 | CP 0 | 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 | ||
53911 | JR Z,53916 | |||
53913 | CALL 58365 | Otherwise, will need to set the screen attributes/colours for the object | ||
53916 | LD A,(60117) | Get the 'graphic visible' flag (1 = graphic drawn, 0 = graphic not drawn as fully off-screen) | ||
53919 | LD C,A | ...Store in C register | ||
53920 | LD A,(60238) | Get item properties byte | ||
53923 | AND 254 | Filter out (reset) bit 0 | ||
53925 | OR C | ...append the 'graphic visible' flag to bit 0 to indicate if the graphic is on screen or not | ||
53926 | LD (60238),A | ...and re-store | ||
53929 | LD C,A | Copy the item properties byte (60238) into the C register | ||
Check if the item needs drawing
|
||||
53930 | LD A,(60227) | Type of graphic to draw | ||
53933 | CP 0 | |||
53935 | JR Z,54053 | If this has been set to zero, the item is no longer visible or in existence - there's nothing to draw | ||
53937 | LD A,C | Retrieve item properties byte | ||
53938 | AND 5 | Check for bit 0 (item is visible) and bit 2 (item has moved/needs erasing) | ||
53940 | JR Z,54053 | If neither is set, there's nothing to draw, so skip the rest of the routine | ||
Set up item for drawing
|
||||
53942 | LD A,(60234) | Graphic vertical position within current room, in pixels, from top of room playing area | ||
53945 | LD (60114),A | Copy to working graphics data buffer | ||
53948 | LD HL,(60107) | Graphic's horizontal position, in pixels | ||
53951 | LD (60115),HL | Copy to working graphics data buffer | ||
53954 | LD A,(60235) | Room type byte - this is set to 64 for 'standard' rooms, or 254/255 for tunnel rooms | ||
53957 | LD (60118),A | Copy to working graphics data buffer | ||
53960 | LD A,1 | |||
53962 | LD (60111),A | Set draw/erase flag to 1 (DRAW) | ||
53965 | LD A,C | Retrieve item properties byte from C register | ||
53966 | AND 2 | Bit 1 (2) if set means item is hidden/not-visible, e.g. inside a chest | ||
53968 | JR Z,53975 | |||
53970 | LD HL,(60147) | If this is the case, set the graphics address pointer to the 'dummy' graphic (39097), so that nothing actually gets drawn | ||
53973 | JR 54037 | 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
|
||||
53975 | LD A,(60072) | Get item colour byte | ||
53978 | CP 0 | This is set for interactable items and creatures but 0 for most other things such as scenery (which is drawn with standard room colours) | ||
53980 | JR Z,54034 | If it's set to 0, don't need to print any colours | ||
53982 | CP 8 | Is the value 7 or less ('standard' INK colours) | ||
53984 | JR C,53993 | 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:
|
||||
53986 | LD A,(60074) | Get game counter/timer | ||
53989 | AND 3 | Keep just bits 0 and 1 (values = 0-3) | ||
53991 | ADD A,4 | Add 4, to give an INK value between 4 (green) and 7 (white) | ||
Set object colour:
|
||||
53993 | AND 7 | Only need to keep bits 0-2 (values = 0-7) | ||
53995 | OR 64 | Set BRIGHT bit for the colour (all on-screen/viewport colours are set to BRIGHT 1) | ||
53997 | 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):
|
||||
53998 | LD A,(60073) | Get room attribute colour | ||
54001 | LD B,A | Temp store in B register | ||
54002 | RRA | Shift bits so that the PAPER colour becomes an INK value to compare | ||
54003 | RRA | |||
54004 | RRA | |||
54005 | AND 7 | Filter out everything other than INK bits | ||
54007 | OR 64 | Set BRIGHT bit | ||
54009 | CP C | Compare with object colour | ||
54010 | JR NZ,54017 | 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:
|
||||
54012 | LD HL,(60147) | If it does happen, set the graphics address pointer to the 'dummy' graphic (39097), so nothing gets drawn (the item would appear invisible anyway) | ||
54015 | JR 54037 | ...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:
|
||||
54017 | LD A,B | Retrieve the room colour attribute value (stored in PAPER bits) | ||
54018 | AND 248 | Filter out/clear any INK bits | ||
54020 | OR C | Append the item's INK bits (0-7) | ||
54021 | LD (60072),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):
|
||||
54024 | LD A,(60116) | Get the horizontal position high byte - this indicates whether the object is within the current screen viewport | ||
54027 | CP 0 | |||
54029 | JR NZ,54034 | If not, no need to print attributes, skip the next instruction | ||
54031 | CALL 58365 | Print screen attribute colours for the room object/creature | ||
Now draw the item's graphics (pixels):
|
||||
54034 | LD HL,(60241) | Graphic address pointer | ||
54037 | CALL 56216 | Draw the item graphics | ||
54040 | LD A,(60117) | Get the visible graphic flag (1 = graphic drawn, 0 = graphic not drawn as fully off-screen) | ||
54043 | LD C,A | Append this flag (1/0) into bit 0 of the item properties byte at 60238 indicating whether this item is visible on screen | ||
54044 | LD A,(60238) | |||
54047 | AND 254 | Filter out bit 0 from the item properties byte | ||
54049 | OR C | Append a 0 or 1 accordingly (not on-screen/on-screen) | ||
54050 | LD (60238),A | ...and re-store the item properties byte. |
Prev: 53870 | Up: Map | Next: 54053 |