| Routines

F95E: Change Sam's disguise

Continues from the routine at FADA. Replaces certain sprite tiles that are used by Sam's animatory states (thus changing his appearance), and then draws Sam's new disguise in the bottom right corner of the screen.
Input
H | 0xE6 (Sam)
F95E | LD L,$08 | Set Sam's main action timer (in byte 0x08 of his buffer) to 8
F960 | LD (HL),L
F961 | LD HL,$7FC9 | 7FC9 holds Sam's current disguise ID
F964 | LD A,(HL) | Pick this up in A
F965 | INC A | A=next disguise ID (0-7)
F966 | AND $07
F968 | LD (HL),A | Store the new disguise ID
This entry point is used by the routine at 790D.
F969 | CALL $7D0A | Set the attribute bytes for Sam's current disguise
F96C | LD A,($7FC9) | A=Sam's disguise ID (0-7)
F96F | ADD A,$DF | Point BC at the reference for the first replacement tile (in the data table at DF3E, E03E, E13E, E23E, E33E, E43E, E53E or E63E)
F971 | LD B,A
F972 | LD C,$3E
F974 | EXX |
F975 | LD HL,$DE3D | HL' will index the sprite tile reference data table at DE3E
F978 | EXX |
F979 | EXX |
F97A | INC L | Point HL' at the next sprite tile reference
F97B | LD A,(HL) | Collect the tile reference in A
F97C | EXX |
F97D | AND A | Have we reached the end of the table?
F97E | JR Z,$F9AA | Jump if so
F980 | LD E,A | Point DE at the first byte of graphic data for this sprite tile
F981 | LD D,$C7
F983 | LD A,(BC) | A=reference for the replacement tile
F984 | INC C | Point BC at the reference for the next replacement tile
F985 | CP $7E | Set the carry flag if the tile reference is < 0x7E
F987 | LD L,A | L=reference for the replacement tile
F988 | JR NC,$F99C | Jump if we're dealing with a tile reference >= 0x7E
We're dealing with a replacement tile (of Sam in disguise) whose reference is < 0x7E. The graphic data for such tiles is arranged in 8 pairs (graphic byte, mask byte) in bytes 0x50-0x7D across pages 0xDF-0xE6.
F98A | LD H,$DF | Point HL at the graphic data for the replacement tile
F98C | LD A,(HL) | Copy a byte of graphic data from the replacement tile into the target sprite tile
F98D | LD (DE),A
F98E | INC D | Point DE at the next byte of mask data for the target sprite tile
F98F | INC L | Point HL at the next byte of mask data for the replacement tile
F990 | LD A,(HL) | Copy a byte of mask data from the replacement tile into the target sprite tile
F991 | LD (DE),A
F992 | INC D | Point DE at the next byte of graphic data for the target sprite tile
F993 | DEC L | Point HL at the next byte of graphic data for the replacement tile
F994 | INC H
F995 | LD A,H | Have we copied the replacement tile over the target sprite tile yet?
F996 | CP $E7
F998 | JR NZ,$F98C | Jump back if not
F99A | JR $F979 | Jump back to deal with the next replacement tile
We're dealing with a replacement tile whose reference is >= 0x7E. The graphic data for such tiles is arranged in groups of 16 (8 pairs of graphic bytes and mask bytes) across pages 0xD7-0xE6.
F99C | LD H,$D7 | Point HL at the graphic data for the replacement tile
F99E | PUSH BC | Save the replacement tile reference pointer
F99F | LD B,$10 | There are 16 bytes of graphic and mask data to copy
F9A1 | LD A,(HL) | Copy the replacement tile over the target sprite tile
F9A2 | LD (DE),A
F9A3 | INC D
F9A4 | INC H
F9A5 | DJNZ $F9A1
F9A7 | POP BC | Restore the replacement tile reference pointer to BC
F9A8 | JR $F979 | Jump back to deal with the next replacement tile
Now we can draw Sam's disguise in the bottom right of the screen.
F9AA | LD HL,$D782 | This is the address of the tile reference for the top-left tile in Sam's sprite (animatory state 0x00)
F9AD | LD DE,$50BD | 50BD is the display file address for the leftmost byte in the top row of pixels of Sam's disguise in the bottom right of the screen
F9B0 | PUSH HL | Save the sprite tile reference pointer
F9B1 | LD L,(HL) | Point HL at the first byte of graphic data for this tile
F9B2 | LD H,$C7
F9B4 | LD A,(HL) | Copy the tile to the screen
F9B5 | LD (DE),A
F9B6 | INC H
F9B7 | INC H
F9B8 | INC D
F9B9 | BIT 3,D
F9BB | JR Z,$F9B4
F9BD | POP HL | Restore the sprite tile reference pointer to HL
F9BE | INC H | Point HL at the next tile reference
F9BF | LD D,$50 | Set DE to the display file address for the next tile
F9C1 | LD A,E
F9C2 | ADD A,$20
F9C4 | LD E,A
F9C5 | JR NC,$F9B0 | Jump back unless we've finished a column of three tiles
F9C7 | CP $1F | Have we just finished the third column?
F9C9 | RET Z | Return if so
F9CA | SUB $5F | Set DE to the display file address for the first tile in the next column
F9CC | LD E,A
F9CD | INC H | Point HL at the reference for the first tile in this column
F9CE | INC H
F9CF | JR $F9B0 | Jump back to draw this column of tiles