Routines
 Prev: 24832 Up: Map Next: 24963
24843: Print a tile
Used by the routines at 24576 and 27026. Copies a tile of the skool into the back buffer at 32513, superimposes character sprite tiles as appropriate, and then copies the resultant tile to the screen.
Input
D Skool y-coordinate (152-172)
E Skool x-coordinate (0-95)
24843 LD A,E A=skool x-coordinate (0-95)
24844 AND 96 Now H is 128 if 0<=E<32; 136 if 32<=E<64; or 144 if 64<=E<96
24846 RRCA
24847 INC A
24848 RRCA
24849 LD H,A
24850 LD A,(DE) A=skool UDG reference for the character square at (E,D)
24851 PUSH DE
24852 LD L,A HL=base address of the UDG bytes for the character square at (E,D)
24853 LD BC,2048 B=8, C=0
24856 LD DE,32513 Copy the 8 bytes of the skool UDG into the back buffer at 32513
24859 LD A,(HL)
24860 LD (DE),A
24861 INC H
24862 INC E
24863 DJNZ 24859
24865 NOP
24866 POP DE Restore the skool coordinates to DE
24867 LD B,21 There are 21 characters to consider
24869 LD H,152 152=little boy no. 1
Now we enter a loop that checks which part (if any) of each character's sprite appears at the skool coordinates in DE.
24871 LD L,98 Byte 98 of the character's buffer holds his x-coordinate
24873 LD A,E A=skool x-coordinate (0-95)
24874 SUB (HL) Subtract the character's x-coordinate
24875 DEC HL Byte 97 of the character's buffer holds his y-coordinate
24876 JR C,24926 Jump if no part of the character's sprite appears at this x-coordinate
24878 CP 3
24880 JR NC,24926
24882 ADD A,A Now C is 0, 4 or 8, corresponding to the column (left, middle or right) of the character's sprite that aligns with x-coordinate E
24884 LD C,A
24885 LD A,D A=skool y-coordinate (152-172)
24886 SUB (HL) Subtract the character's y-coordinate
24887 JR C,24926 Jump if no part of the character's sprite appears at this y-coordinate
24889 CP 4
24891 JR NC,24926
24893 ADD A,C A=0-11, corresponding to the sprite tile that appears at (E,D)
24894 EXX
24897 LD H,A H'=173-184
24898 EXX
24899 LD L,96 Pick up the character's animatory state in A
24901 LD A,(HL)
24902 EXX
24903 LD L,A L'=character's animatory state
24904 LD A,(HL) A=sprite tile UDG reference
24905 AND A Is it the blank UDG?
24906 JR Z,24925 Jump if so
24908 CALL 27914 Get the base address of the sprite tile UDG bytes in HL'
The following inner loop superimposes the sprite tile onto the tile built up so far in the back buffer at 32513 (which was originally populated with the relevant skool UDG).
24911 LD B,8 There are 8 bytes in the UDG
24913 LD DE,32513
24916 LD A,(DE) A=back buffer UDG byte
24917 OR (HL) OR in the sprite tile UDG byte
24918 INC H
24919 AND (HL) AND in the sprite tile UDG mask
24920 INC H
24921 LD (DE),A
24922 INC E
24923 DJNZ 24916 Jump back until the UDG is done
24925 EXX
24926 INC H Next character
24927 DJNZ 24871 Jump back to consider the next character
The display tile (consisting of the skool UDG with all relevant sprite tiles superimposed) has been built. Figure out where in the display file it should be printed.
24929 LD HL,32512 32512 holds the leftmost column of the skool on-screen (0-64)
24932 LD A,D A=skool y-coordinate (152-172)
24933 AND 7 Set C to the LSB of the display file address corresponding to the screen coordinates (0,D-152)
24935 RRCA
24936 RRCA
24937 RRCA
24938 LD C,A
24939 LD A,E A=screen x-coordinate (0-31)
24940 SUB (HL)
24941 ADD A,C Set L to the LSB of the display file address corresponding to the skool coordinates (E,D)
24942 LD L,A
24943 LD A,D A=screen y-coordinate (0-20)
24944 SUB 152
24946 AND 24 Set H to the MSB of the display file address corresponding to the skool coordinates (E,D)