Jet Set Willy: Routine at 37974

| Routines

37974: Draw a sprite

Used by the routines at 34499 (to draw the number key graphics on the code entry screen), 35211 (to draw the remaining lives), 35914 (to draw Willy, the foot and the barrel during the game over sequence), 37310 (to draw guardians in the current room) and 38196 (to draw Maria in Master Bedroom). If C=1 on entry, this routine returns with the zero flag reset if any of the set bits in the sprite being drawn collides with a set bit in the background.
Input
C | Drawing mode: 0 (overwrite) or 1 (blend)
DE | Address of sprite graphic data
HL | Address to draw at
37974 | LD B,16 | There are 16 rows of pixels to draw
37976 | BIT 0,C | Set the zero flag if we're in overwrite mode
37978 | LD A,(DE) | Pick up a sprite graphic byte
37979 | JR Z,37985 | Jump if we're in overwrite mode
37981 | AND (HL) | Return with the zero flag reset if any of the set bits in the sprite graphic byte collide with a set bit in the background (e.g. in Willy's sprite)
37982 | RET NZ
37983 | LD A,(DE) | Pick up the sprite graphic byte again
37984 | OR (HL) | Blend it with the background byte
37985 | LD (HL),A | Copy the graphic byte to its destination cell
37986 | INC L | Move HL along to the next cell on the right
37987 | INC DE | Point DE at the next sprite graphic byte
37988 | BIT 0,C | Set the zero flag if we're in overwrite mode
37990 | LD A,(DE) | Pick up a sprite graphic byte
37991 | JR Z,37997 | Jump if we're in overwrite mode
37993 | AND (HL) | Return with the zero flag reset if any of the set bits in the sprite graphic byte collide with a set bit in the background (e.g. in Willy's sprite)
37994 | RET NZ
37995 | LD A,(DE) | Pick up the sprite graphic byte again
37996 | OR (HL) | Blend it with the background byte
37997 | LD (HL),A | Copy the graphic byte to its destination cell
37998 | DEC L | Move HL to the next pixel row down in the cell on the left
37999 | INC H
38000 | INC DE | Point DE at the next sprite graphic byte
38001 | LD A,H | Have we drawn the bottom pixel row in this pair of cells yet?
38002 | AND 7
38004 | JR NZ,38022 | Jump if not
38006 | LD A,H | Otherwise move HL to the top pixel row in the cell below
38007 | SUB 8
38009 | LD H,A
38010 | LD A,L
38011 | ADD A,32
38013 | LD L,A
38014 | AND 224 | Was the last pair of cells at y-coordinate 7 or 15?
38016 | JR NZ,38022 | Jump if not
38018 | LD A,H | Otherwise adjust HL to account for the movement from the top or middle third of the screen to the next one down
38019 | ADD A,8
38021 | LD H,A
38022 | DJNZ 37976 | Jump back until all 16 rows of pixels have been drawn
38024 | XOR A | Set the zero flag (to indicate no collision)
38025 | RET |