Routines

24880: Update SRB for new animatory state and location of character


Used by several routines

A New animatory state
D New y-coordinate (3-17)
E New x-coordinate (0-189)
H Character number (183-214)

24880 2E02 LD L,2 HL points to byte 2 of the character's buffer
24882 72 LD (HL),D Fill in the new y-coordinate
24883 2D DEC L
24884 73 LD (HL),E Fill in the new x-coordinate
24885 2D DEC L
24886 77 LD (HL),A Fill in the new animatory state
24887 4F LD C,A

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 3AFF7F LD A,(32767) A=column of play area at left of screen (0-160)
24891 D603 SUB 3
24893 3802 JR C,24897
24895 BB CP E
24896 D0 RET NC Return if character is off-screen to the left
24897 C622 ADD A,34
24899 BB CP E
24900 D8 RET C Return if character is off-screen to the right
24901 D620 SUB 32
24903 2F CPL
24904 83 ADD A,E A=character's x-coordinate relative to current screen (-2 to 31)
24905 0603 LD B,3
24907 E5 PUSH HL
24908 26D7 LD H,215
24910 FEFE CP 254 Is character either fully on-screen or walking off it to the right?
24912 380A JR C,24924 Jump if so
24914 26DB LD H,219
24916 05 DEC B B=2
24917 3C INC A Is the character one-third off/two-thirds on at the left?
24918 2804 JR Z,24924 Jump if so
24920 26DF LD H,223
24922 05 DEC B B=1 (character is one-third on-screen at the left)
24923 AF XOR A
24924 5F LD E,A E=leftmost column of screen occupied by character sprite (0-31)
24925 D61E SUB 30
24927 3803 JR C,24932 Jump if character is one- or two-thirds off-screen to the right
24929 2F CPL
24930 80 ADD A,B
24931 47 LD B,A

Now B holds a value (1, 2 or 3) equal to the number of columns of the screen the character occupies.
24932 69 LD L,C L=animatory state
24933 0E00 LD C,0
24935 CB7D BIT 7,L Is character facing left?
24937 2806 JR Z,24945 Jump if so
24939 0EF8 LD C,248
24941 3EB6 LD A,182
24943 94 SUB H
24944 67 LD H,A

Now H holds 215, 219 or 223—pages which hold UDG references for the characters.
24945 CBFD SET 7,L "Normalise" the animatory state to 128-255
24947 7B LD A,E A=leftmost column of screen occupied by character sprite
24948 D9 EXX
24949 E607 AND 7
24951 C678 ADD A,120
24953 6F LD L,A
24954 26E1 LD H,225
24956 4E LD C,(HL) Pick up a byte from the table at 57720
24957 D9 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 one of the bytes of the screen refresh buffer.
24958 7B LD A,E A=leftmost column of screen occupied by character sprite
24959 0F RRCA
24960 0F RRCA
24961 0F RRCA
24962 E603 AND 3
24964 82 ADD A,D
24965 82 ADD A,D
24966 82 ADD A,D
24967 82 ADD A,D
24968 D9 EXX
24969 47 LD B,A Now B'=LSB of first byte of SRB to be modified (corresponding to the top left square of the game character sprite)
24970 267F LD H,127 The SRB starts at page 127 (32512)

Here we enter a loop to set the appropriate bits in the SRB:
24972 D9 EXX
24973 1E00 LD E,0 E will now count up to 4 (the number of rows occupied by a character sprite)
24975 7E LD A,(HL) A=UDG reference
24976 A7 AND A Is this the "null" UDG (blank square)?
24977 280A JR Z,24989 Jump if so
24979 7B LD A,E A=row number of character (0-3)
24980 87 ADD A,A Multiply by 4 (the number of bytes of the SRB that correspond to one horizontal line of the screen)
24981 87 ADD A,A
24982 D9 EXX
24983 80 ADD A,B
24984 6F LD L,A HL'=appropriate byte of SRB
24985 79 LD A,C The bit set in A is the bit that needs setting in the SRB byte
24986 B6 OR (HL)
24987 77 LD (HL),A Set the bit in the SRB
24988 D9 EXX
24989 24 INC H Point to next UDG reference for this character's animatory state
24990 1C INC E Next row in this column
24991 CB53 BIT 2,E Have we done all four rows yet?
24993 28EC JR Z,24975 Jump back if not
24995 05 DEC B Have we done all columns occupied by the character yet?
24996 280B JR Z,25009 Jump if so
24998 7C LD A,H
24999 81 ADD A,C C=0 if character's facing left, -8 if he's facing right
25000 67 LD H,A Now H=number of page containing the first UDG reference for the next column of the character sprite
25001 D9 EXX
25002 CB09 RRC C Move the marker bit one place to the right
25004 30DE JR NC,24972 Jump back if there are still bits to be set in the current SRB byte
25006 04 INC B Otherwise move to the next SRB byte
25007 18DB JR 24972
25009 E1 POP HL Restore character number to H (L=0)
25010 C9 RET