Prev: 61A1 Up: Map Next: 6212
61B0: Update a character's animatory state and location and update the SRB
Used by many routines. Sets the new animatory state and location of a character, and updates the screen refresh buffer (SRB) accordingly.
Input
A New animatory state
D New y-coordinate (154-169)
E New x-coordinate (0-95)
H Character number (0x98-0xAC)
61B0 LD L,$60 Point HL at byte 0x60 of the character's buffer
61B2 LD (HL),A Set the new animatory state
61B3 LD B,A Store the new animatory state in B for later
61B4 INC L L=0x61
61B5 LD (HL),D Set the new y-coordinate
61B6 INC L L=0x62
61B7 LD (HL),E Set the new x-coordinate
This entry point is used by the routine at 6214.
61B8 LD A,($7F00) A=leftmost column of the skool on-screen (0-64)
61BB SUB $03 Is the far left of the skool in view?
61BD JR C,$61C1 Jump if so
61BF CP E Is the character off-screen to the left?
61C0 RET NC Return if so (SRB does not need updating)
61C1 ADD A,$22
61C3 CP E Is the character off-screen to the right?
61C4 RET C Return if so (SRB does not need updating)
61C5 SUB $20 A=character's screen x-coordinate: -2<=A<=31
61C7 CPL
61C8 ADD A,E
61C9 PUSH HL Save the character number
61CA LD L,B L=character's new animatory state
61CB LD H,$AD Pages 0xAD-0xB0 store UDG references for the left column of the sprites
61CD BIT 7,A Is the left column of the sprite on-screen?
61CF JR Z,$61DB Jump if so
61D1 LD H,$B1 Pages 0xB1-0xB4 store UDG references for the middle column of the sprites
61D3 INC A -1<=A<=0
61D4 BIT 7,A Is the middle column of the sprite on-screen at the left?
61D6 JR Z,$61DB Jump if so
61D8 INC A A=0
61D9 LD H,$B5 Pages 0xB5-0xB8 store UDG references for the right column of the sprites
At this point, A holds the leftmost column of the screen (0-31) occupied by the character's sprite, and H holds the page number (0xAD, 0xB1, 0xB5) corresponding to the leftmost column of the sprite that appears on-screen.
61DB RLCA Set the instruction at 6987 to SET n,(HL) where n is the appropriate bit of the SRB byte that needs to be set
61DC RLCA
61DD RLCA
61DE LD E,A
61DF AND $38
61E1 ADD A,$C6
61E3 LD ($6988),A
61E6 LD A,E A=8c (c=0-31: leftmost column of the screen occupied by the sprite)
61E7 RLCA
61E8 RLCA
61E9 AND $03 A=INT(c/8)
61EB LD E,A E=INT(c/8)
61EC LD A,D A=character's y-coordinate (155-169)
61ED SUB $95 5<=A<=20
61EF ADD A,A A=4*(D-149)
61F0 ADD A,A
61F1 ADD A,E A=4*(D-149)+INT(c/8)
61F2 LD E,A E=12+4*(D-152)+INT(c/8)
61F3 LD D,$7F Now HL points to the relevant byte of the SRB, and DE points to the base address of the sprite UDG references
61F5 EX DE,HL
61F6 CALL $6980 Update the SRB for one column of the character's sprite
61F9 JR NZ,$6210 Jump if we just updated the SRB for the right column of the sprite
61FB SUB $10 Point HL back to the relevant byte of the SRB
61FD LD L,A
61FE LD A,($6988) Prepare to change the instruction at 6987 from SET n,(HL) to SET n+1,(HL)
6201 ADD A,$08
6203 LD ($6988),A Change the instruction at 6987 from SET n,(HL) to SET n+1,(HL) or SET 0,(HL)
6206 JR NC,$61F6 Jump back unless the instruction at 6987 should be changed to SET 0,(HL) now
6208 INC L Move to the next byte of the SRB
6209 LD A,L The zero flag will be set now if we 'wrapped around' to the left side of the screen, i.e. the next column of the character sprite is off-screen to the right
620A AND $03
620C LD A,$C6 This will change the instruction at 6987 to SET 0,(HL)
620E JR NZ,$6203 Jump back to consider the remaining on-screen columns of the sprite
6210 POP HL Restore the character number (0x98-0xAC) to H
6211 RET
Prev: 61A1 Up: Map Next: 6212