Prev: 8C8C Up: Map Next: 8D45
8CB7: Handle Player Appearing
The handler for the player (sprite ID 66) while the player is appearing at the start of a life, which is set up by PreparePlayer. While the timer at FlashTimer is running FlashScore counts it down. After that the sprite of the player (the sprite ID at offset 07) is drawn one row more every fourth frame by HandlerPlayerAppearing_DrawRow, while the sound of appearing is made and the colour of the cells changes. When all the rows have been drawn the sprite ID is put back and the handler is no longer used.
Input
IX The player entity
HandlerPlayerAppearing 8CB7 LD A,($5E3C) Fetch the timer from FlashTimer.
8CBA AND A Jump to FlashScore if the timer is running.
8CBB JR NZ,FlashScore
8CBD LD A,($5C78) Fetch FRAMES.
8CC0 AND %00000011 Keep only bits 0-1.
8CC2 JP NZ,HandlerPlayerAppearing_Colour Jump to HandlerPlayerAppearing_Colour unless this is every fourth frame.
8CC5 INC (IX+$06) Increment the number of rows to draw at offset 06.
8CC8 LD A,(IX+$07) Fetch the sprite ID of the player from offset 07.
8CCB CALL FetchSprite Call FetchSprite to get the address of the sprite data.
8CCE LD A,(DE) Fetch the height of the sprite.
8CCF CP (IX+$06) Jump to HandlerPlayerAppearing_Finish if all of the rows have been drawn.
8CD2 JR Z,HandlerPlayerAppearing_Finish
This entry point is used by the routine at HandlerPlayerVanishing.
Draw the row of the sprite that is given by the number of rows. This is done by pointing the entry for the sprite in the table of sprites at the row, and temporarily changing the byte before it to a height of one row.
HandlerPlayerAppearing_DrawRow 8CD4 PUSH DE Stash the address of the sprite data on the stack.
8CD5 PUSH HL Stash the address of the entry in the table of sprites on the stack.
8CD6 LD B,H Keep the address of the table entry in BC.
8CD7 LD C,L
8CD8 LD A,(IX+$04) Fetch the Y position of the entity.
8CDB LD (IX+$02),A Save it at offset 02.
8CDE SUB (IX+$06) Subtract the number of rows.
8CE1 LD (IX+$04),A Update the Y position of the entity.
8CE4 LD L,(IX+$06) Fetch the number of rows.
8CE7 LD H,$00 Clear the high byte of the number of rows in H.
8CE9 ADD HL,HL Double HL, as there are two bytes in each row.
8CEA ADD HL,DE Add the address of the sprite data to HL.
8CEB LD A,H Fetch the high byte of the address of the row.
8CEC LD (BC),A Write A to the high byte of the table entry.
8CED DEC BC Move BC back to the low byte.
8CEE LD A,L Fetch the low byte of the address of the row.
8CEF LD (BC),A Write A to the low byte of the table entry.
8CF0 PUSH HL Stash the address of the row on the stack.
8CF1 LD C,(HL) Fetch the byte at the address of the row.
8CF2 LD B,(IX+$00) Fetch the sprite ID of the entity.
8CF5 PUSH BC Stash them on the stack.
8CF6 LD (HL),$01 Write 01 (the height of one row) to the address of the row.
8CF8 LD A,(IX+$07) Fetch the sprite ID of the player from offset 07.
8CFB LD (IX+$00),A Write it to the sprite ID of the entity.
8CFE CALL DrawEntity Call DrawEntity to draw the row.
8D01 POP BC Restore the byte and the sprite ID from the stack.
8D02 POP HL Restore the address of the row from the stack.
8D03 LD (HL),C Write the byte back.
8D04 LD (IX+$00),B Write the sprite ID back to the entity.
8D07 LD A,(IX+$02) Fetch the saved Y position from offset 02.
8D0A LD (IX+$04),A Write it back to the Y position of the entity.
8D0D POP HL Restore the address of the table entry from the stack.
8D0E POP DE Restore the address of the sprite data from the stack.
8D0F LD (HL),D Write the high byte back to the table entry.
8D10 DEC HL Move HL back to the low byte.
8D11 LD (HL),E Write the low byte back to the table entry.
This entry point is used by the routine at HandlerPlayerVanishing.
Set the colour of the cells that have been drawn so far, which cycles with FRAMES, and make the sound of appearing.
HandlerPlayerAppearing_Colour 8D12 LD A,(IX+$05) Fetch the attribute of the entity.
8D15 PUSH AF Stash it on the stack.
8D16 LD A,($5C78) Fetch FRAMES.
8D19 RRCA Divide FRAMES by four.
8D1A RRCA
8D1B AND %00000111 Keep only bits 0-2.
8D1D JR NZ,HandlerPlayerAppearing_SetColour Jump to HandlerPlayerAppearing_SetColour if the result is not zero.
8D1F INC A Use 01 instead, to avoid black.
HandlerPlayerAppearing_SetColour 8D20 OR %01000000 Set bit 6 (bright).
8D22 LD (IX+$05),A Update the attribute of the entity.
8D25 LD A,(IX+$06) Fetch the number of rows.
8D28 CALL SetItemAttributes_Lines Call SetItemAttributes_Lines to set the attributes of that many rows.
8D2B POP AF Restore the attribute of the entity from the stack.
8D2C LD (IX+$05),A Write it back to the entity.
8D2F JP SoundsAppear Jump to SoundsAppear to make the sound of appearing.
All of the rows have been drawn, so the player is back.
HandlerPlayerAppearing_Finish 8D32 LD A,(IX+$07) Fetch the sprite ID of the player from offset 07.
8D35 LD (IX+$00),A Write it to the sprite ID of the entity.
8D38 LD (IX+$06),$00 Write 00 to offset 06.
8D3C LD (IX+$07),$00 Write 00 to offset 07.
8D40 LD (IX+$02),$00 Write 00 to offset 02.
8D44 RET Return.
Prev: 8C8C Up: Map Next: 8D45