Jet Set Willy: Routine at 9456

| Routines

9456: Draw a sprite

Used by the routines at 86C3 (to draw the number key graphics on the code entry screen), 898B (to draw the remaining lives), 8C4A (to draw Willy, the foot and the barrel during the game over sequence), 91BE (to draw guardians in the current room) and 9534 (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
9456 | LD B,$10 | There are 16 rows of pixels to draw
9458 | BIT 0,C | Set the zero flag if we're in overwrite mode
945A | LD A,(DE) | Pick up a sprite graphic byte
945B | JR Z,$9461 | Jump if we're in overwrite mode
945D | 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)
945E | RET NZ
945F | LD A,(DE) | Pick up the sprite graphic byte again
9460 | OR (HL) | Blend it with the background byte
9461 | LD (HL),A | Copy the graphic byte to its destination cell
9462 | INC L | Move HL along to the next cell on the right
9463 | INC DE | Point DE at the next sprite graphic byte
9464 | BIT 0,C | Set the zero flag if we're in overwrite mode
9466 | LD A,(DE) | Pick up a sprite graphic byte
9467 | JR Z,$946D | Jump if we're in overwrite mode
9469 | 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)
946A | RET NZ
946B | LD A,(DE) | Pick up the sprite graphic byte again
946C | OR (HL) | Blend it with the background byte
946D | LD (HL),A | Copy the graphic byte to its destination cell
946E | DEC L | Move HL to the next pixel row down in the cell on the left
946F | INC H
9470 | INC DE | Point DE at the next sprite graphic byte
9471 | LD A,H | Have we drawn the bottom pixel row in this pair of cells yet?
9472 | AND $07
9474 | JR NZ,$9486 | Jump if not
9476 | LD A,H | Otherwise move HL to the top pixel row in the cell below
9477 | SUB $08
9479 | LD H,A
947A | LD A,L
947B | ADD A,$20
947D | LD L,A
947E | AND $E0 | Was the last pair of cells at y-coordinate 7 or 15?
9480 | JR NZ,$9486 | Jump if not
9482 | 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
9483 | ADD A,$08
9485 | LD H,A
9486 | DJNZ $9458 | Jump back until all 16 rows of pixels have been drawn
9488 | XOR A | Set the zero flag (to indicate no collision)
9489 | RET |