| Routines

6412: Prepare sprite tiles used by Sam when somersaulting or rolling

Used by the routine at 64BD. Animatory states 0x09, 0x0A, 0x0F and 0x1F - corresponding to the sprites of Sam rolling and somersaulting - use sprite tiles 0xEF-0xF7. These sprite tiles are initialised before Sam starts his acrobatic manoeuvre, and later rotated as he moves through each phase of animation.
6412 | LD L,$02 | Copy sprite tiles 0x02-0x07 over sprite tiles 0xEF-0xF4
6414 | LD E,$EF
6416 | LD C,$06
6418 | CALL $6400
641B | LD E,$F2 | Copy sprite tile 0xAA over sprite tile 0xF2
641D | LD L,$AA
641F | INC C
6420 | CALL $6400
6423 | LD A,$B5 | Copy sprite tiles 0xB5, 0xBD and 0xC5 from base page 0xD7 over sprite tiles 0xF5-0xF7
6425 | LD E,$F5
6427 | LD L,A
6428 | LD H,$D7
642A | INC C
642B | CALL $6402
642E | LD A,L
642F | ADD A,$07
6431 | CP $CD
6433 | JR NZ,$6427
6435 | LD B,$08 | Superimpose sprite tile 0xCD from base page 0xD7 over sprite tile 0xF3 (which is currently a copy of sprite tile 0x06, the centre tile of Sam's base animatory state); this makes Sam appear to bend his arms and hold his knees while performing the acrobatic feat, at the expense of losing some detail from his current disguise
6437 | LD HL,$D7CD
643A | LD DE,$C7F3
643D | LD A,(DE)
643E | OR (HL)
643F | INC H
6440 | AND (HL)
6441 | INC H
6442 | LD (DE),A
6443 | INC D
6444 | LD (DE),A
6445 | INC D
6446 | DJNZ $643D
This entry point is used by the routine at 64BD. Here we rotate sprite tiles 0xEF-0xF7 and store the results in sprite tile slots 0xEE-0xF6.
6448 | LD L,$EF | Tile 0xEF is the first source tile
644A | LD E,L | E=0xEE (the first target tile)
644B | DEC E
644C | LD D,$C7 | The base page for these tiles is 0xC7
644E | LD B,$08 | Rotate the source sprite tile 90 degrees anticlockwise and copy it over the target sprite tile
6450 | LD H,$C6
6452 | LD C,$01
6454 | INC H
6455 | RRC (HL)
6457 | RLA
6458 | INC H
6459 | RRC (HL)
645B | RL C
645D | JR NC,$6454
645F | LD (DE),A
6460 | INC D
6461 | LD A,C
6462 | LD (DE),A
6463 | INC D
6464 | DJNZ $6450
6466 | INC L | Move to the next source sprite tile reference
6467 | BIT 3,L | Have we rotated sprite tiles 0xEF-0xF7 yet?
6469 | JR Z,$644A | Jump back if not
Next we move sprite tiles 0xEE-0xF6 up to 0xEF-0xF7.
646B | LD A,$10 | There are 16 bytes of graphic and mask data in each tile
646D | LD E,$F7 | Copy sprite tiles 0xEE-0xF6 into slots 0xEF-0xF7
646F | LD L,$F6
6471 | LD C,$09
6473 | DEC D
6474 | LD H,D
6475 | LDDR
6477 | DEC A
6478 | JR NZ,$646D
647A | RET | Return with the zero flag set