Prev: 77D3 Up: Map Next: 78F9
7866: Prepare for a cutscene
Used by the routine at 7AB6. On entry, A holds the LSB of the address of the screen refresh buffer byte that corresponds to the top row of the portion of the play area to be displayed during the cutscene.
Input
A Screen refresh buffer address LSB
D New y-coordinate for the topmost row of the play area on screen
E New x-coordinate for the leftmost column of the play area on screen
7866 PUSH DE Save the play area coordinates briefly
7867 PUSH AF Save the screen refresh buffer address LSB briefly
7868 CALL $FC57 Hide the play area
786B POP AF Restore the screen refresh buffer address LSB to A
786C LD L,A Point HL at the first screen refresh buffer (SRB) byte that will need updating later
786D POP DE Restore the play area coordinates to DE
786E PUSH HL Save the SRB address for now
786F AND $03 Compute Sam's new x-coordinate (x+5, where x is the x-coordinate of the leftmost column of the portion of the play area to be displayed)
7871 ADD A,A
7872 ADD A,A
7873 ADD A,A
7874 ADD A,$05
7876 ADD A,E
7877 LD C,A C=Sam's new x-coordinate
7878 LD A,D Set the new y-coordinate of the topmost row of the play area on screen
7879 LD ($7FFF),A
787C LD A,L A=screen refresh buffer address LSB
787D SUB $0C Compute Sam's new y-coordinate
787F AND $FC
7881 RRCA
7882 RRCA
7883 ADD A,D
7884 LD HL,$E600 Point HL at byte 0x00 of Sam's character buffer
7887 LD (HL),$00 Set Sam's animatory state to 0x00 (standing/walking phase 1)
7889 INC L L=0x01
788A LD (HL),C Set Sam's x-coordinate
788B INC L L=0x02
788C LD (HL),A Set Sam's y-coordinate
788D INC L L=0x04
788E INC L
788F LD (HL),$01 Set Sam's z-coordinate
Next we cycle character buffer groups forwards or backwards as appropriate to correspond with the portion of the play area that will be on screen.
7891 LD HL,$F1B7 Place a RET instruction at F1B7 so that the screen will not scroll right
7894 LD (HL),$C9
7896 LD L,$E0 Place a RET instruction at F1E0 so that the screen will not scroll left
7898 LD (HL),$C9
789A PUSH HL
789B LD HL,$7FFE Collect X (the x-coordinate of the leftmost column of the play area on screen) from 7FFE
789E LD A,(HL)
789F CP E Does X match the target x-coordinate (in E)?
78A0 JR Z,$78B9 Jump if so
78A2 PUSH DE Save the target x-coordinate briefly
78A3 JR C,$78AC Jump if X<E
78A5 CALL $F18E Cycle a character buffer group forwards (but without scrolling the screen)
78A8 LD A,$F8 A=-8
78AA JR $78B1
78AC CALL $F1BA Cycle a character buffer group backwards (but without scrolling the screen)
78AF LD A,$08
78B1 POP DE Restore the target x-coordinate to E
78B2 LD HL,$7FFE Add 8 to or subtract 8 from X (the x-coordinate of the leftmost column of the play area on screen, stored at 7FFE)
78B5 ADD A,(HL)
78B6 LD (HL),A
78B7 JR $789F Jump back to check whether we need to cycle any more character buffers backwards or forwards
78B9 POP HL
78BA LD (HL),$C3 Restore the JP instruction at F1E0
78BC LD L,$B7 Restore the JP instruction at F1B7
78BE LD (HL),$C3
Next we determine whether any lights near Sam need to be switched on and any window blinds need to be raised.
78C0 LD H,$E6 0xE6=Sam
78C2 CALL $F6A2 Collect in C the x-coordinate of the front column of Sam's sprite
78C5 LD B,$C0 Is there a light switch next to Sam?
78C7 CALL $F454
78CA JR Z,$78EB Jump if not (we can reveal the play area now)
78CC BIT 5,A Set the zero flag if the light switch affects the light in only one window or window-pair
78CE LD A,(BC) A=window flags for Sam's location
78CF JR Z,$78D8 Jump if the light switch affects the light in only one window or window-pair
78D1 BIT 5,A Is the light switch in the 'on' position?
78D3 CALL NZ,$F4A6 If not, switch the light on
78D6 JR $78EB Jump forward to reveal the play area
78D8 BIT 1,A Is there a right-hand window here with a blind?
78DA JR Z,$78DE Jump if not
78DC RES 0,A Reset bit 0: blind raised in the right-hand window
78DE BIT 7,A Is there a left-land or single window here with a blind?
78E0 JR Z,$78E4 Jump if not
78E2 RES 6,A Reset bit 6: blind raised in the left-hand or only window
78E4 RES 5,A Reset bit 5: light switch on
78E6 LD (BC),A Save the new window flags (blinds raised, light switch on)
78E7 XOR A Clear A to prevent the following call from changing the window flags (we've already updated them)
78E8 CALL $F499 Update the SRB for the window
Finally we can reveal the portion of the play area in which Sam will walk up and down until the cutscene message has been displayed and the game resumes.
78EB POP HL Restore the SRB address to HL
78EC LD B,$06 The portion is 6 rows high
78EE LD A,L Initialise A for the loop that follows
78EF LD L,A Set all bits in the relevant SRB bytes
78F0 LD (HL),$FF
78F2 ADD A,$04
78F4 DJNZ $78EF
78F6 JP $EA80 Update the display
Prev: 77D3 Up: Map Next: 78F9