Jet Set Willy: Routine at 9637

| Routines

9637: Draw Willy to the screen buffer at 6000

Used by the routine at 95C8.
Input
B | y-coordinate offset (0, 4, 8 or 12)
9637 | LD A,($85CF) | Pick up Willy's y-coordinate from 85CF
963A | ADD A,B | Add the y-coordinate offset (to get Willy's true y-coordinate if he's standing on a ramp)
963B | LD IXh,$82 | Point IX at the entry in the screen buffer address lookup table at 8200 that corresponds to Willy's y-coordinate
963E | LD IXl,A
9640 | LD A,($85D0) | Pick up Willy's direction and movement flags from 85D0
9643 | AND $01 | Now E=0x00 if Willy is facing right, or 0x80 if he's facing left
9645 | RRCA
9646 | LD E,A
9647 | LD A,($85D2) | Pick up Willy's animation frame (0-3) from 85D2
964A | AND $03 | Point DE at the sprite graphic data for Willy's current animation frame (see 9D00)
964C | RRCA
964D | RRCA
964E | RRCA
964F | OR E
9650 | LD E,A
9651 | LD D,$9D
9653 | LD A,($8420) | Pick up the number of the current room from 8420
9656 | CP $1D | Are we in the The Nightmare Room?
9658 | JR NZ,$9660 | Jump if not
965A | LD D,$B6 | Point DE at the graphic data for the flying pig sprite (B600+E)
965C | LD A,E
965D | XOR $80
965F | LD E,A
9660 | LD B,$10 | There are 16 rows of pixels to copy
9662 | LD A,($85D3) | Pick up Willy's screen x-coordinate (0-31) from 85D3
9665 | AND $1F
9667 | LD C,A | Copy it to C
This entry point is used by the routine at 959A to draw the toilet in The Bathroom.
9668 | LD A,(IX+$00) | Set HL to the address in the screen buffer at 6000 that corresponds to where we are going to draw the next pixel row of the sprite graphic
966B | LD H,(IX+$01)
966E | OR C
966F | LD L,A
9670 | LD A,(DE) | Pick up a sprite graphic byte
9671 | OR (HL) | Merge it with the background
9672 | LD (HL),A | Save the resultant byte to the screen buffer
9673 | INC HL | Move HL along to the next cell to the right
9674 | INC DE | Point DE at the next sprite graphic byte
9675 | LD A,(DE) | Pick it up in A
9676 | OR (HL) | Merge it with the background
9677 | LD (HL),A | Save the resultant byte to the screen buffer
9678 | INC IX | Point IX at the next entry in the screen buffer address lookup table at 8200
967A | INC IX
967C | INC DE | Point DE at the next sprite graphic byte
967D | DJNZ $9668 | Jump back until all 16 rows of pixels have been drawn
967F | RET |