Prev: 60E2 Up: Map Next: 6137
60FD: Colour Shelf
Used by the routine at DrawPantry.
Colours the cells of one shelf of the pantry. The cells which have an attribute of 00 are given the colour of the ingredient for the shelf, which was fetched by PantryFillColour. As in DrawShelf there are two sets of attributes; the second is used when the shelf's bit is set in PantryHighlightMask.
Input
B Shelf number
DE Address of the attributes for the normal graphic
HL Position of the shelf
Output
HL Position of the shelf below
Make the second byte of a BIT command from the shelf number.
ColourShelf 60FD PUSH BC Stash the shelf number and C on the stack.
60FE PUSH DE Stash the address of the normal attributes on the stack.
60FF LD A,B Fetch the shelf number.
6100 RLCA Multiply by 08 so that the shelf number is in bits 3-5.
6101 RLCA
6102 RLCA
6103 AND %00111000 Keep only bits 3-5.
6105 OR %01000111 Set bits 0-2 and bit 6.
6107 LD ($610E),A Write A to 610E.
610A LD A,($5F2A) Fetch the mask of the highlighted shelf.
Self modifying code; the command which is here is made into BIT n,A, where n is the shelf number, by the instructions above. It is stored as BIT 0,A.
ColourShelf_TestBit 610D BIT 0,A Jump to ColourShelf_Rows if this shelf is not highlighted.
610F JR Z,ColourShelf_Rows
6111 PUSH HL Move DE on to the highlighted attributes, which are 12 bytes further on (preserving HL).
6112 LD HL,$0012
6115 ADD HL,DE
6116 EX DE,HL
6117 POP HL
ColourShelf_Rows 6118 LD C,$03 Set the number of rows to 03.
ColourShelf_Row 611A LD B,$06 Set the column counter to 06 (the width of the shelf).
611C PUSH HL Stash the position of the row on the stack.
611D PUSH BC Stash the counters on the stack.
611E CALL AttributeAddress Convert the position to an attribute address using AttributeAddress.
6121 POP BC Restore the counters from the stack.
ColourShelf_Loop 6122 LD A,(DE) Fetch the attribute.
6123 AND A Does the attribute need the colour of the ingredient (is it zero)?
6124 CALL Z,FetchShelfColour Call FetchShelfColour if it is, to get the colour of the ingredient.
6127 LD (HL),A Write the attribute to the attribute buffer.
6128 INC DE Move onto the next attribute.
6129 INC HL Move onto the next column.
612A DJNZ ColourShelf_Loop Decrease the column counter by one and loop back to ColourShelf_Loop until the row has been coloured.
612C POP HL Restore the position of the row from the stack.
612D LD A,H Fetch the vertical position of the row.
612E ADD A,$08 Add 08 to move down one row of tiles.
6130 LD H,A Update the vertical position of the row.
6131 DEC C Decrease the row counter by one.
6132 JR NZ,ColourShelf_Row Loop back to ColourShelf_Row until all of the rows have been done.
6134 POP DE Restore the address of the normal attributes from the stack.
6135 POP BC Restore the shelf number and C from the stack.
6136 RET Return.
Prev: 60E2 Up: Map Next: 6137