Prev: 24878 Up: Map Next: 25011
24880: 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 (183-214)
24880 LD L,2 Point HL at byte 2 of the character's buffer
24882 LD (HL),D Fill in the new y-coordinate
24883 DEC L L=1
24884 LD (HL),E Fill in the new x-coordinate
24885 DEC L L=0
24886 LD (HL),A Fill in the new animatory state
24887 LD C,A C=new animatory state
This entry point is used by the routine at 25012 to update the SRB for the current animatory state and location of the character.
24888 LD A,(32767) A=leftmost column of the play area on screen (0-160)
24891 SUB 3
24893 JR C,24897
24895 CP E
24896 RET NC Return if the character is entirely off-screen to the left
24897 ADD A,34
24899 CP E
24900 RET C Return if the character is entirely off-screen to the right
24901 SUB 32 A=E-(32767): the character's relative x-coordinate (-2 to 31)
24903 CPL
24904 ADD A,E
24905 LD B,3 The sprites are 3 tiles wide
24907 PUSH HL
24908 LD H,215
24910 CP 254 Is the character either fully on-screen or walking off it to the right?
24912 JR C,24924 Jump if so
24914 LD H,219
24916 DEC B B=2
24917 INC A Is the character one-third off (two-thirds on) at the left?
24918 JR Z,24924 Jump if so
24920 LD H,223
24922 DEC B B=1 (the character is one-third on-screen at the left)
24923 XOR A
24924 LD E,A E=leftmost column of the screen occupied by the character's sprite (0-31)
24925 SUB 30
24927 JR C,24932 Jump if the character is one- or two-thirds off-screen to the right
24929 CPL
24930 ADD A,B
24931 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.
24932 LD L,C L=animatory state
24933 LD C,0
24935 BIT 7,L Is the character facing left?
24937 JR Z,24945 Jump if so
24939 LD C,248
24941 LD A,182
24943 SUB H
24944 LD H,A
Now H holds 215, 219 or 223 - 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.
24945 SET 7,L Point HL at the UDG reference for the sprite tile
24947 LD A,E A=leftmost column of the screen occupied by the sprite (0-31)
24948 EXX
24949 AND 7
24951 ADD A,120
24953 LD L,A
24954 LD H,225
24956 LD C,(HL) Pick up a byte from the table at 57720
24957 EXX
Now C' holds 1, 2, 4, 8, 16, 32, 64 or 128. The bit set in C' corresponds to the bit that needs to be set in the relevant byte of the screen refresh buffer (SRB).
24958 LD A,E A=leftmost column of the screen occupied by the sprite
24959 RRCA Set A to the LSB of the first byte of the SRB that needs to be modified
24960 RRCA
24961 RRCA
24962 AND 3
24964 ADD A,D
24965 ADD A,D
24966 ADD A,D
24967 ADD A,D
24968 EXX
24969 LD B,A Copy this LSB to B'
24970 LD H,127 The SRB starts at page 127 (32512)
Here we enter a loop to set the appropriate bits in the SRB.
24972 EXX
24973 LD E,0 E will count up to 4 (the number of rows occupied by a sprite)
24975 LD A,(HL) Pick up the sprite tile UDG reference in A
24976 AND A Is this the 'null' UDG (blank square)?
24977 JR Z,24989 Jump if so
24979 LD A,E A=sprite tile row number (0-3)
24980 ADD A,A Multiply by 4 (the number of bytes of the SRB that correspond to one row of the screen)
24981 ADD A,A
24982 EXX
24983 ADD A,B Point HL' at the relevant byte of the SRB
24984 LD L,A
24985 LD A,C The bit set in A is the bit that needs setting in the SRB byte
24986 OR (HL) Set the bit in the SRB
24987 LD (HL),A
24988 EXX
24989 INC H Point HL at the UDG reference for the next tile in the sprite (one row down)
24990 INC E Next row down in this column of the sprite
24991 BIT 2,E Have we done all four rows yet?
24993 JR Z,24975 Jump back if not
24995 DEC B Have we done all the columns occupied by the sprite yet?
24996 JR Z,25009 Jump if so
24998 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)
24999 ADD A,C
25000 LD H,A
25001 EXX
25002 RRC C Move the SRB marker bit one place to the right (possibly wrapping round to bit 7)
25004 JR NC,24972 Jump back if there are still bits to be set in the current SRB byte
25006 INC B Otherwise move to the next SRB byte
25007 JR 24972
25009 POP HL Restore the character number to H (L=0)
25010 RET
Prev: 24878 Up: Map Next: 25011