Manic Miner: Routine at 36707

| Routines

36707: Draw the items in the current cavern and collect any that Willy is touching

Used by the routine at 34574.
36707 | XOR A | Initialise the attribute of the last item drawn at 32884 to 0 (in case there are no items left to draw)
36708 | LD (32884),A
36711 | LD IY,32885 | Point IY at the first byte of the first item definition at 32885
The item-drawing loop begins here.
36715 | LD A,(IY+0) | Pick up the first byte of the item definition
36718 | CP 255 | Have we dealt with all the items yet?
36720 | JR Z,36794 | Jump if so
36722 | OR A | Has this item already been collected?
36723 | JR Z,36782 | If so, skip it and consider the next one
36725 | LD E,(IY+1) | Point DE at the address of the item's location in the attribute buffer at 23552
36728 | LD D,(IY+2)
36731 | LD A,(DE) | Pick up the current attribute byte at the item's location
36732 | AND 7 | Is the INK white (which happens if Willy is touching the item)?
36734 | CP 7
36736 | JR NZ,36750 | Jump if not
Willy is touching this item, so add it to his collection.
36738 | LD HL,33836 | Add 100 to the score
36741 | CALL 37118
36744 | LD (IY+0),0 | Set the item's attribute byte to 0 so that it will be skipped the next time
36748 | JR 36782 | Jump forward to consider the next item
This item has not been collected yet.
36750 | LD A,(IY+0) | Pick up the item's current attribute byte
36753 | AND 248 | Keep the BRIGHT and PAPER bits, and set the INK to 3 (magenta)
36755 | OR 3
36757 | LD B,A | Store this value in B
36758 | LD A,(IY+0) | Pick up the item's current attribute byte again
36761 | AND 3 | Keep only bits 0 and 1 and add the value in B; this maintains the BRIGHT and PAPER bits, and cycles the INK colour through 3, 4, 5 and 6
36763 | ADD A,B
36764 | LD (IY+0),A | Store the new attribute byte
36767 | LD (DE),A | Update the attribute byte at the item's location in the buffer at 23552
36768 | LD (32884),A | Store the new attribute byte at 32884 as well
36771 | LD D,(IY+3) | Point DE at the address of the item's location in the screen buffer at 24576
36774 | LD HL,32948 | Point HL at the item graphic for the current cavern (at 32948)
36777 | LD B,8 | There are eight pixel rows to copy
36779 | CALL 37589 | Draw the item to the screen buffer at 24576
The current item definition has been dealt with. Time for the next one.
36782 | INC IY | Point IY at the first byte of the next item definition
36784 | INC IY
36786 | INC IY
36788 | INC IY
36790 | INC IY
36792 | JR 36715 | Jump back to deal with the next item
All the items have been dealt with. Check whether there were any left.
36794 | LD A,(32884) | Pick up the attribute of the last item drawn at 32884
36797 | OR A | Were any items drawn?
36798 | RET NZ | Return if so (some remain to be collected)
36799 | LD HL,32911 | Ensure that the portal is flashing by setting bit 7 of its attribute byte at 32911
36802 | SET 7,(HL)
36804 | RET |