Jet Set Willy: Routine at 36307

| Routines

36307: Move Willy (1)

Used by the routine at 35245. This routine deals with Willy if he's jumping or falling.
36307 | LD A,(34262) | Pick up the rope status indicator from 34262
36310 | DEC A | Is Willy on a rope?
36311 | BIT 7,A
36313 | JP Z,36564 | Jump if so
36316 | LD A,(34257) | Pick up the airborne status indicator from 34257
36319 | CP 1 | Is Willy jumping?
36321 | JR NZ,36406 | Jump if not
Willy is currently jumping. Your browser doesn't support HTML5 audio. Here is a link to the audio instead.
36323 | LD A,(34261) | Pick up the jumping animation counter (0-17) from 34261
36326 | AND 254 | Discard bit 0
36328 | SUB 8 | Now -8<=A<=8 (and A is even)
36330 | LD HL,34255 | Adjust Willy's y-coordinate at 34255 depending on where Willy is in the jump
36333 | ADD A,(HL)
36334 | LD (HL),A
36335 | CP 240 | Is the new value negative (above the top of the screen)?
36337 | JP NC,38064 | If so, move Willy into the room above
36340 | CALL 36508 | Adjust Willy's attribute buffer location at 34259 depending on his y-coordinate
36343 | LD A,(32946) | Pick up the attribute byte of the wall tile for the current room from 32946
36346 | CP (HL) | Is the top-left cell of Willy's sprite overlapping a wall tile?
36347 | JP Z,36540 | Jump if so
36350 | INC HL | Point HL at the top-right cell occupied by Willy's sprite
36351 | CP (HL) | Is the top-right cell of Willy's sprite overlapping a wall tile?
36352 | JP Z,36540 | Jump if so
36355 | LD A,(34261) | Increment the jumping animation counter at 34261
36358 | INC A
36359 | LD (34261),A
36362 | SUB 8 | A=J-8, where J (1-18) is the new value of the jumping animation counter
36364 | JP P,36369 | Jump if J>=8
36367 | NEG | A=8-J (1<=J<=7, 1<=A<=7)
36369 | INC A | A=1+ABS(J-8)
36370 | RLCA | D=8*(1+ABS(J-8)); this value determines the pitch of the jumping sound effect (rising as Willy rises, falling as Willy falls)
36371 | RLCA
36372 | RLCA
36373 | LD D,A
36374 | LD C,32 | This value determines the duration of the jumping sound effect
36376 | LD A,(32990) | Pick up the border colour for the current room from 32990
36379 | OUT (254),A | Make a jumping sound effect
36381 | XOR 24
36383 | LD B,D
36384 | DJNZ 36384
36386 | DEC C
36387 | JR NZ,36379
36389 | LD A,(34261) | Pick up the jumping animation counter (1-18) from 34261
36392 | CP 18 | Has Willy reached the end of the jump?
36394 | JP Z,36528 | Jump if so
36397 | CP 16 | Is the jumping animation counter now 16?
36399 | JR Z,36406 | Jump if so
36401 | CP 13 | Is the jumping animation counter now 13?
36403 | JP NZ,36796 | Jump if not
If we get here, then Willy is standing on the floor or a ramp, or he's falling, or his jumping animation counter is 13 (at which point Willy is on his way down and is exactly two cell-heights above where he started the jump) or 16 (at which point Willy is on his way down and is exactly one cell-height above where he started the jump).
36406 | LD A,(34255) | Pick up Willy's y-coordinate from 34255
36409 | AND 14 | Is Willy either on a ramp, or occupying only four cells?
36411 | JR NZ,36450 | Jump if not
36413 | LD HL,(34259) | Pick up Willy's attribute buffer coordinates from 34259
36416 | LD DE,64 | Point HL at the left-hand cell below Willy's sprite
36419 | ADD HL,DE
36420 | BIT 1,H | Is this location below the floor of the current room?
36422 | JP NZ,38098 | If so, move Willy into the room below
36425 | LD A,(32955) | Pick up the attribute byte of the nasty tile for the current room from 32955
36428 | CP (HL) | Does the left-hand cell below Willy's sprite contain a nasty?
36429 | JR Z,36450 | Jump if so
36431 | INC HL | Point HL at the right-hand cell below Willy's sprite
36432 | LD A,(32955) | Pick up the attribute byte of the nasty tile for the current room from 32955 (again, redundantly)
36435 | CP (HL) | Does the right-hand cell below Willy's sprite contain a nasty?
36436 | JR Z,36450 | Jump if so
36438 | LD A,(32928) | Pick up the attribute byte of the background tile for the current room from 32928
36441 | CP (HL) | Set the zero flag if the right-hand cell below Willy's sprite is empty
36442 | DEC HL | Point HL at the left-hand cell below Willy's sprite
36443 | JP NZ,36564 | Jump if the right-hand cell below Willy's sprite is not empty
36446 | CP (HL) | Is the left-hand cell below Willy's sprite empty?
36447 | JP NZ,36564 | Jump if not
36450 | LD A,(34257) | Pick up the airborne status indicator from 34257
36453 | CP 1 | Is Willy jumping?
36455 | JP Z,36796 | Jump if so
If we get here, then Willy is either in the process of falling or just about to start falling. Your browser doesn't support HTML5 audio. Here is a link to the audio instead.
36458 | LD HL,34256 | Reset bit 1 at 34256: Willy is not moving left or right
36461 | RES 1,(HL)
36463 | LD A,(34257) | Pick up the airborne status indicator from 34257
36466 | OR A | Is Willy already falling?
36467 | JP Z,36534 | Jump if not
36470 | INC A | Increment the airborne status indicator
36471 | CP 16 | Is it 16 now?
36473 | JR NZ,36477 | Jump if not
36475 | LD A,12 | Decrease the airborne status indicator from 16 to 12
36477 | LD (34257),A | Update the airborne status indicator at 34257
36480 | RLCA | D=16*A; this value determines the pitch of the falling sound effect
36481 | RLCA
36482 | RLCA
36483 | RLCA
36484 | LD D,A
36485 | LD C,32 | This value determines the duration of the falling sound effect
36487 | LD A,(32990) | Pick up the border colour for the current room from 32990
36490 | OUT (254),A | Make a falling sound effect
36492 | XOR 24
36494 | LD B,D
36495 | DJNZ 36495
36497 | DEC C
36498 | JR NZ,36490
36500 | LD A,(34255) | Add 8 to Willy's y-coordinate at 34255; this moves Willy downwards by 4 pixels
36503 | ADD A,8
36505 | LD (34255),A
This entry point is used by the routine at 37310 to update Willy's attribute buffer location when he's on a rope.
36508 | AND 240 | L=16*Y, where Y is Willy's screen y-coordinate (0-14)
36510 | LD L,A
36511 | XOR A | Clear A and the carry flag
36512 | RL L | Now L=32*(Y-8*INT(Y/8)), and the carry flag is set if Willy is in the lower half of the room (Y>=8)
36514 | ADC A,92 | H=92 or 93 (MSB of the address of Willy's location in the attribute buffer)
36516 | LD H,A
36517 | LD A,(34259) | Pick up Willy's screen x-coordinate (0-30) from bits 0-4 at 34259
36520 | AND 31
36522 | OR L | Now L holds the LSB of Willy's attribute buffer address
36523 | LD L,A
36524 | LD (34259),HL | Store Willy's updated attribute buffer location at 34259
36527 | RET |
Willy has just finished a jump.
36528 | LD A,6 | Set the airborne status indicator at 34257 to 6: Willy will continue to fall unless he's landed on a wall or floor block
36530 | LD (34257),A
36533 | RET |
Willy has just started falling.
36534 | LD A,2 | Set the airborne status indicator at 34257 to 2
36536 | LD (34257),A
36539 | RET |
The top-left or top-right cell of Willy's sprite is overlapping a wall tile.
36540 | LD A,(34255) | Adjust Willy's y-coordinate at 34255 so that the top row of cells of his sprite is just below the wall tile
36543 | ADD A,16
36545 | AND 240
36547 | LD (34255),A
36550 | CALL 36508 | Adjust Willy's attribute buffer location at 34259 to account for this new y-coordinate
36553 | LD A,2 | Set the airborne status indicator at 34257 to 2: Willy has started falling
36555 | LD (34257),A
36558 | LD HL,34256 | Reset bit 1 at 34256: Willy is not moving left or right
36561 | RES 1,(HL)
36563 | RET |