Routines
 Prev: 612E Up: Map Next: 61B3
6130: 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 (3-17)
E New x-coordinate (0-189)
H Character number (0xB7-0xD6)
6130 LD L,\$02 Point HL at byte 0x02 of the character's buffer
6132 LD (HL),D Fill in the new y-coordinate
6133 DEC L L=0x01
6134 LD (HL),E Fill in the new x-coordinate
6135 DEC L L=0x00
6136 LD (HL),A Fill in the new animatory state
6137 LD C,A C=new animatory state
This entry point is used by the routine at 61B4 to update the SRB for the current animatory state and location of the character.
6138 LD A,(\$7FFF) A=leftmost column of the play area on screen (0-160)
613B SUB \$03
613D JR C,\$6141
613F CP E
6140 RET NC Return if the character is entirely off-screen to the left
6143 CP E
6144 RET C Return if the character is entirely off-screen to the right
6145 SUB \$20 A=E-(7FFF): the character's relative x-coordinate (-2 to 31)
6147 CPL
6149 LD B,\$03 The sprites are 3 tiles wide
614B PUSH HL
614C LD H,\$D7
614E CP \$FE Is the character either fully on-screen or walking off it to the right?
6150 JR C,\$615C Jump if so
6152 LD H,\$DB
6154 DEC B B=2
6155 INC A Is the character one-third off (two-thirds on) at the left?
6156 JR Z,\$615C Jump if so
6158 LD H,\$DF
615A DEC B B=1 (the character is one-third on-screen at the left)
615B XOR A
615C LD E,A E=leftmost column of the screen occupied by the character's sprite (0-31)
615D SUB \$1E
615F JR C,\$6164 Jump if the character is one- or two-thirds off-screen to the right
6161 CPL
6163 LD B,A
Now B holds a value (1, 2 or 3) equal to the number of columns of the screen occupied by the character's sprite.
6164 LD L,C L=animatory state
6165 LD C,\$00
6167 BIT 7,L Is the character facing left?
6169 JR Z,\$6171 Jump if so
616B LD C,\$F8
616D LD A,\$B6
616F SUB H
6170 LD H,A
Now H holds 0xD7, 0xDB or 0xDF - the page containing the UDG reference for the tile on the top row of the leftmost column of the sprite that is on-screen. C is 0 if the character is facing left, or -8 if he's facing right.
6171 SET 7,L Point HL at the UDG reference for the sprite tile
6173 LD A,E A=leftmost column of the screen occupied by the sprite (0-31)
6174 EXX
6175 AND \$07
6179 LD L,A
617A LD H,\$E1
617C LD C,(HL) Pick up a byte from the table at E178
617D EXX
Now C' holds 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40 or 0x80. The bit set in C' corresponds to the bit that needs to be set in the relevant byte of the screen refresh buffer (SRB).
617E LD A,E A=leftmost column of the screen occupied by the sprite
617F RRCA Set A to the LSB of the first byte of the SRB that needs to be modified
6180 RRCA
6181 RRCA
6182 AND \$03
6188 EXX
6189 LD B,A Copy this LSB to B'
618A LD H,\$7F The SRB starts at page 0x7F (7F00)
Here we enter a loop to set the appropriate bits in the SRB.
618C EXX
618D LD E,\$00 E will count up to 4 (the number of rows occupied by a sprite)
618F LD A,(HL) Pick up the sprite tile UDG reference in A
6190 AND A Is this the 'null' UDG (blank square)?
6191 JR Z,\$619D Jump if so
6193 LD A,E A=sprite tile row number (0-3)
6194 ADD A,A Multiply by 4 (the number of bytes of the SRB that correspond to one row of the screen)
6196 EXX
6197 ADD A,B Point HL' at the relevant byte of the SRB
6198 LD L,A
6199 LD A,C The bit set in A is the bit that needs setting in the SRB byte
619A OR (HL) Set the bit in the SRB
619B LD (HL),A
619C EXX
619D INC H Point HL at the UDG reference for the next tile in the sprite (one row down)
619E INC E Next row down in this column of the sprite
619F BIT 2,E Have we done all four rows yet?
61A1 JR Z,\$618F Jump back if not
61A3 DEC B Have we done all the columns occupied by the sprite yet?
61A4 JR Z,\$61B1 Jump if so
61A6 LD A,H Point HL at the UDG reference for the tile in the top row of the next column of the sprite (C=0 if the character's facing left, -8 if facing right)