Prev: 24560 Up: Map Next: 24677
24576: Superimpose sprite tiles onto a tile of the play area
Used by the routine at 24684. Checks through B characters, starting at character H. If any part of a character's sprite needs to be printed at the row and column specified by DE, the appropriate UDG is located and superimposed onto the contents of the buffer at 57712, which on the first call to this routine contains the appropriate skool UDG (the background).
Input
B Number of characters to consider
D Row of play area (0-20)
E Column of play area (0-191)
H Number of the first character to consider
24576 LD L,1 Point HL at byte 1 of the character's buffer
24578 LD A,E A=column of play area (0-191) under consideration
24579 SUB (HL) Subtract the character's x-coordinate
24580 CP 3 Sprites are three character squares wide
24582 JR NC,24652 Jump if no part of this character's sprite is in this column
24584 DEC L L=0
24585 BIT 7,(HL) Is the character facing left?
24587 JR Z,24592 Jump if so
24589 CPL 'Flip' the number in A, so 0 becomes 2, 1 remains 1, and 2 becomes 0 (i.e. A becomes 2-A)
24590 ADD A,3
24592 ADD A,A Now C=0 if the front of the character is in this column, 4 if it's the middle, or 8 if it's the back
24593 ADD A,A
24594 LD C,A
24595 LD L,2 Point HL at byte 2 of the character's buffer
24597 LD A,D A=row of play area (0-20) under consideration
24598 SUB (HL) Subtract the character's y-coordinate
24599 CP 4 Sprites are 4 character squares tall
24601 JR NC,24652 Jump if no part of this character's sprite is in this row
24603 ADD A,C 0<=A<=11 (index of the sprite tile at this row and column, where 0=top-front, 4=top-middle, 8=top-back, 11=bottom-back)
24604 ADD A,215 215<=A<=226
24606 EXX Set H' to the number of the page containing the UDG reference for the sprite tile
24607 LD H,A
24608 EXX
24609 LD L,0 Point HL at byte 0 of the character's buffer
24611 LD A,(HL) A=character's animatory state
24612 OR 128 Set bit 7 to obtain the LSB of the address that holds the sprite tile UDG reference
24614 EXX
24615 LD L,A 128<=L'<=255 (215<=H'<=226)
24616 LD A,(HL) A=sprite tile UDG reference (73-255)
24617 AND A Is this tile the 'null' UDG (a blank square)?
24618 JR Z,24651 Jump if so (no need to superimpose it)
24620 LD E,A E'=UDG reference (73-255)
24621 LD A,L A=(normalised) animatory state (128-255)
24622 CP 208 208=animatory state of MR WACKER, the first teacher
24624 EXX
24625 LD A,(HL) A=character's (true) animatory state (0-255)
24626 EXX
24627 LD D,183 Point DE' at the graphic data at page 183 onwards (for animatory states 0-79 and 128-207)
24629 JR C,24633 Jump unless we're dealing with animatory states 80-127 or 208-255 (teachers, ALBERT, and water fired from the pistol)
24631 LD D,199 Point DE' at the graphic data at page 199 onwards (for animatory states 80-127 and 208-255)
24633 LD HL,57712 Point HL' at the UDG back buffer
24636 RLCA Push the character's 'direction' bit into the carry flag
24637 JR C,24656 Jump if the character is facing right
24639 EX DE,HL
24640 LD A,(DE) A=byte already in the UDG buffer
24641 OR (HL) Superimpose the sprite tile byte
24642 INC H Point HL' at the outline mask for this tile byte
24643 AND (HL) AND with this mask
24644 INC H Point HL' at the next sprite tile byte
24645 LD (DE),A Place the resultant byte back in the UDG buffer
24646 INC E Move DE' along the UDG buffer
24647 BIT 3,E Have we done all 8 bytes yet?
24649 JR Z,24640 Jump back if not
24651 EXX
24652 INC H Next game character
24653 DJNZ 24576 Jump back until all characters have been done
24655 RET
The character is facing right, so we have to produce a mirror image of the graphic data.
24656 LD B,182 Page 182 contains mirror images of 0-255
24658 LD A,(DE) A=sprite tile byte
24659 LD C,A A=mirror image of this byte
24660 LD A,(BC)
24661 OR (HL) Superimpose what's already in the UDG buffer
24662 LD (HL),A Put the result so far back in the UDG buffer
24663 INC D A=outline mask for this sprite tile byte
24664 LD A,(DE)
24665 LD C,A A=mirror image of this mask
24666 LD A,(BC)
24667 AND (HL) AND it with what's in the UDG buffer
24668 LD (HL),A Place the result in the UDG buffer
24669 INC D Next sprite tile byte
24670 INC L Next byte of the UDG buffer
24671 BIT 3,L Have we done all 8 bytes yet?
24673 JR Z,24658 Jump back if not
24675 JR 24651
Prev: 24560 Up: Map Next: 24677