Prev: E4C6 Up: Map Next: E57F
E4CC: Update Screen
Used by the routine at RunFrame.
Called every frame. Every eighth frame the restart position is updated if the player has been standing on a place where it can restart. The frame counter is increased and the screen buffer is copied to the screen, starting with the rows that are chosen by ScrollValue. The copy of the buffer to the screen is done by using the stack pointer.
update-screen-before update-screen-after
Every eighth frame, remember where the player is standing so that a new life can start from there.
UpdateScreen E4CC LD A,($A2DD) Fetch the frame counter.
E4CF AND %00000111 Use bits 0-2.
E4D1 JR NZ,UpdateScreen_Count Jump to UpdateScreen_Count unless this is an eighth frame.
E4D3 LD A,($B55E) Read field 1E of the player entity.
E4D6 AND %10000000 Keep bit 7, which is set if the player is on the ground.
E4D8 JR Z,UpdateScreen_Store Jump to UpdateScreen_Store if the player is not on the ground, to forget the place that was found.
E4DA LD A,($E4C7) Read the byte at E4C7, which is not zero if a place to restart from has been found.
E4DD AND A Test it.
E4DE JR Z,UpdateScreen_Count Jump to UpdateScreen_Count if no place has been found.
E4E0 LD A,($B540) Fetch the type of the player entity.
E4E3 DEC A Decrease it by one.
E4E4 LD A,$00 A is 00 ready to forget the place.
E4E6 JR NZ,UpdateScreen_Store Jump to UpdateScreen_Store if the player is not of type 01 to forget the place that was found.
Copy the place that was found to the restart position of the level.
E4E8 LD A,($E4C6) Read the byte at RestartCandidate.
E4EB LD ($DEF6),A Store it at DEF6.
E4EE LD A,($E4C7) Read the byte at E4C7 and take away 20.
E4F1 SUB $20
E4F3 LD B,A Keep it in B.
E4F4 LD A,($E4CB) Read the byte at E4CB.
E4F7 AND %11110000 Use bits 4-7.
E4F9 OR B Combine them with the byte in B.
E4FA LD ($DEF5),A Store them at RestartPosition.
E4FD LD A,($E4C9) Read the byte at E4C9.
E500 LD ($DEF7),A Store it at DEF7.
E503 LD A,($E4C8) Read the byte at E4C8.
E506 LD ($DEF8),A Store it at DEF8.
E509 XOR A A is 00.
UpdateScreen_Store E50A LD ($E4C7),A Forget the place that was found.
Count the frame, and make the random numbers move on.
UpdateScreen_Count E50D LD HL,($A2DD) Fetch the frame counter into HL.
E510 INC HL Add one to it.
E511 LD ($A2DD),HL Store it.
E514 CALL GetRandomNumber Update the random number.
Copy the screen buffer to the game window, one pixel line at a time, starting from the line that is chosen by ScrollValue. The stack pointer is used to read the buffer, which saves time.
E517 LD ($5CDA),SP Store the stack pointer, which is restored at the end.
E51B LD A,($5CE9) Fetch the number that selects the first line.
E51E LD HL,$E4A6 Point HL at the table of line addresses at BufferRowTable.
E521 CALL AddToAddress Find the entry in the table.
E524 LD E,(HL) Fetch the address of the first line of the buffer into DE.
E525 INC HL
E526 LD D,(HL)
E527 LD B,$70 Set the number of pixel lines to copy to 70.
E529 EX DE,HL Point the stack pointer at the first line of the buffer.
E52A LD SP,HL
This entry point is used by the routine at DrawWipeStep.
UpdateScreen_Copy E52B LD HL,$4026 Set HL to the screen address of the first pixel line of the game window, 4026.
E52E JP UpdateScreen_Bytes Jump to UpdateScreen_Bytes to copy the first line.
Move down by one pixel line on the screen.
UpdateScreen_Row E531 LD L,C Go back to the first column of the window.
E532 INC H Move down a pixel line.
E533 LD A,H Fetch the screen address into A.
E534 AND %00000111 Use bits 0-2, which are zero at the start of a character row.
E536 JP NZ,UpdateScreen_Bytes Jump to UpdateScreen_Bytes if the line is in the same character row.
E539 LD A,L Move on to the next character row...
E53A ADD A,$20
E53C LD L,A ...by adding 20.
E53D JP C,UpdateScreen_Bytes Jump to UpdateScreen_Bytes if that stays in the same third of the screen.
E540 LD A,H Move on to the next third of the screen.
E541 SUB $08
E543 LD H,A
Copy twenty bytes of the buffer to the screen, and skip the last four bytes of the line in the buffer.
UpdateScreen_Bytes E544 LD C,L Keep the first column of the line in C.
E545 POP DE Copy the first two bytes of the line.
E546 LD (HL),E
E547 INC L
E548 LD (HL),D
E549 INC L
E54A POP DE Copy the next two bytes of the line.
E54B LD (HL),E
E54C INC L
E54D LD (HL),D
E54E INC L
E54F POP DE Copy the next two bytes of the line.
E550 LD (HL),E
E551 INC L
E552 LD (HL),D
E553 INC L
E554 POP DE Copy the next two bytes of the line.
E555 LD (HL),E
E556 INC L
E557 LD (HL),D
E558 INC L
E559 POP DE Copy the next two bytes of the line.
E55A LD (HL),E
E55B INC L
E55C LD (HL),D
E55D INC L
E55E POP DE Copy the next two bytes of the line.
E55F LD (HL),E
E560 INC L
E561 LD (HL),D
E562 INC L
E563 POP DE Copy the next two bytes of the line.
E564 LD (HL),E
E565 INC L
E566 LD (HL),D
E567 INC L
E568 POP DE Copy the next two bytes of the line.
E569 LD (HL),E
E56A INC L
E56B LD (HL),D
E56C INC L
E56D POP DE Copy the next two bytes of the line.
E56E LD (HL),E
E56F INC L
E570 LD (HL),D
E571 INC L
E572 POP DE Copy the last two bytes of the line.
E573 LD (HL),E
E574 INC L
E575 LD (HL),D
E576 POP DE Skip the four bytes at the end of the line in the buffer.
E577 POP DE
E578 DJNZ UpdateScreen_Row Decrease the line counter and loop back to UpdateScreen_Row until all 70 lines have been copied.
UpdateScreen_Return E57A LD SP,($5CDA) Restore the stack pointer.
E57E RET Return.
Prev: E4C6 Up: Map Next: E57F