Jet Set Willy: Routine at 38344

| Routines

38344: Check and set the attribute bytes for Willy's sprite in the buffer at 23552

Used by the routine at 35245. Sets the attribute bytes in the buffer at 23552 for the six cells (in three rows of two) occupied by or under Willy's sprite, or kills Willy if any of the cells contains a nasty.
38344 | LD HL,(34259) | Pick up Willy's attribute buffer coordinates from 34259
38347 | LD B,0 | Initialise B to 0 (in case Willy is not standing on a ramp)
38349 | LD A,(32986) | Pick up the direction byte of the ramp definition for the current room from 32986
38352 | AND 1 | Point HL at one of the cells under Willy's feet (the one on the left if the ramp goes up to the left, the one on the right if the ramp goes up to the right)
38354 | ADD A,64
38356 | LD E,A
38357 | LD D,0
38359 | ADD HL,DE
38360 | LD A,(32964) | Pick up the ramp's attribute byte from 32964
38363 | CP (HL) | Is Willy on or just above the ramp?
38364 | JR NZ,38392 | Jump if not
38366 | LD A,(34257) | Pick up the airborne status indicator from 34257
38369 | OR A | Is Willy airborne?
38370 | JR NZ,38392 | Jump if so
Willy is standing on a ramp. Calculate the offset that needs to be added to the y-coordinate stored at 34255 to obtain Willy's true y-coordinate.
38372 | LD A,(34258) | Pick up Willy's current animation frame (0-3) from 34258
38375 | AND 3 | B=0, 4, 8 or 12
38377 | RLCA
38378 | RLCA
38379 | LD B,A
38380 | LD A,(32986) | Pick up the direction byte of the ramp definition for the current room from 32986
38383 | AND 1 | A=B (if the ramp goes up to the left) or 12-B (if the ramp goes up to the right)
38385 | DEC A
38386 | XOR 12
38388 | XOR B
38389 | AND 12
38391 | LD B,A | Copy this value to B
Now B holds a y-coordinate offset of 0, 4, 8 or 12 if Willy is standing on a ramp, or 0 otherwise.
38392 | LD HL,(34259) | Pick up Willy's attribute buffer coordinates from 34259
38395 | LD DE,31 | Prepare DE for later addition
38398 | LD C,15 | Set C=15 for the top two rows of cells (to make the routine at 38430 force white INK)
38400 | CALL 38430 | Check and set the attribute byte for the top-left cell
38403 | INC HL | Move HL to the next cell to the right
38404 | CALL 38430 | Check and set the attribute byte for the top-right cell
38407 | ADD HL,DE | Move HL down a row and back one cell to the left
38408 | CALL 38430 | Check and set the attribute byte for the mid-left cell
38411 | INC HL | Move HL to the next cell to the right
38412 | CALL 38430 | Check and set the attribute byte for the mid-right cell
38415 | LD A,(34255) | Pick up Willy's y-coordinate from 34255
38418 | ADD A,B | Add the y-coordinate offset calculated earlier (to get Willy's true y-coordinate if he's standing on a ramp) and transfer the result to C
38419 | LD C,A
38420 | ADD HL,DE | Move HL down a row and back one cell to the left; at this point HL may be pointing at one of the cells in the top row of the buffer at 24064, which is a bug
38421 | CALL 38430 | Check and set the attribute byte for the bottom-left cell
38424 | INC HL | Move HL to the next cell to the right
38425 | CALL 38430 | Check and set the attribute byte for the bottom-right cell
38428 | JR 38455 | Draw Willy to the screen buffer at 24576