Prev: E8F0 Up: Map Next: E9BF
E8F3: Superimpose sprite tiles onto a tile of the play area
Used by the routine at E70C. If any part of a character's sprite needs to be printed at the row and column specified by DE', the appropriate tile is located and superimposed onto the contents of the buffer at A01E.
Input
A 2
D' Play area y-coordinate
E' Play area x-coordinate
E8F3 CALL $E8F8 Superimpose sprite tiles for characters whose z-coordinate is 2 (between a building and the sidewalk)
E8F6 LD A,$04 Prepare to superimpose sprite tiles for characters whose z-coordinate is 4 (on the sidewalk or road)
This entry point is used by the routine at E70C with A=1 (to superimpose sprite tiles for characters who are indoors).
E8F8 EXX
E8F9 LD C,A C'=1 (indoors), 2 (between buildings and the sidewalk) or 4 (on the sidewalk or road)
E8FA LD H,$D7 0xD7 is the first character
E8FC LD L,$04 Point HL' at byte 0x04 of the character's buffer
E8FE LD A,(HL) A=character's z-coordinate (1, 2, 4 or 8)
E8FF AND C Reset the zero flag if the character's sprite should be printed
This entry point is used by the routine at 6592 with H=0xE6 (Sam), DE holding the play area coordinates of a bullet, and the zero flag reset unless Sam's indoors.
E900 JR Z,$E95E Consider the next character if this one should not be printed
E902 LD L,$00 Point HL' at byte 0x00 of the character's buffer
E904 LD A,(HL) A=character's animatory state
E905 AND $7F Drop the direction bit (bit 7)
E907 CP $78 Is this character's animatory state >= 0x78?
E909 JR NC,$E945 Jump if so
The character's animatory state is < 0x78, which means he has a 5x3 sprite.
E90B INC L L'=0x01
E90C INC A A=character's animatory state + 1
E90D AND $07 Reduce this modulo 8
E90F LD A,E A=X, the play area x-coordinate (0-255)
E910 JR Z,$E92C Jump if the character's animatory state is congruent to 7 mod 8
The character's animatory state is congruent to 0-6 mod 8, which means he has a sprite with 5 rows and 3 columns. Check whether any part of the sprite impinges on the tile at (X,Y).
E912 SUB (HL) Subtract the character's x-coordinate
E913 CP $03 Does any part of the sprite impinge on column X?
E915 JR NC,$E95E Jump if not
E917 DEC L L'=0x00
E918 BIT 7,(HL) Is the character facing left?
E91A JR Z,$E91F Jump if so
E91C CPL Set A to 2-A if the character is facing right
E91D ADD A,$03
E91F LD B,A B'=0, 1 or 2 (the column of the character's sprite at (X,Y))
E920 ADD A,A A=5*B
E921 ADD A,A
E922 ADD A,B
E923 LD B,A B'=0, 5 or 10
E924 LD L,$02 Point HL' at byte 0x02 of the character's buffer
E926 LD A,D A=Y, the play area y-coordinate (2-39)
E927 SUB (HL) Subtract the character's y-coordinate
E928 CP $05 Set the carry flag if the sprite impinges on row Y
E92A JR $E95C
The character's animatory state is congruent to 7 mod 8, which means he has a sprite with 3 rows and 5 columns. Check whether any part of the sprite impinges on the tile at (X,Y).
E92C SUB (HL) Subtract the character's x-coordinate
E92D CP $05 Does any part of the character impinge on column X?
E92F JR NC,$E95E Jump if not
E931 DEC L L'=0x00
E932 BIT 7,(HL) Is the character facing left?
E934 JR Z,$E939 Jump if so
E936 CPL Set A=4-A if the character is facing right
E937 ADD A,$05
E939 LD B,A B'=0, 1, 2, 3 or 4 (the column of the sprite at (X,Y))
E93A ADD A,A A=3*B'
E93B ADD A,B
E93C LD B,A B'=0, 3, 6, 9 or 12
E93D LD L,$02 Point HL' at byte 0x02 of the character's buffer
E93F LD A,D A=Y, the play area y-coordinate (2-39)
E940 SUB (HL) Subtract the character's y-coordinate
E941 CP $03 Set the carry flag if the sprite impinges on row Y
E943 JR $E95C
The character's animatory state is >= 0x78, which means he has a sprite with 2 rows and 2 columns. Check whether any part of the sprite impinges on the tile at (X,Y).
E945 LD L,$01 Point HL' at byte 0x01 of the character's buffer
E947 LD A,E A=X, the play area x-coordinate (0-255)
E948 SUB (HL) Subtract the character's x-coordinate
E949 CP $02 Does any part of the sprite impinge on column X?
E94B JR NC,$E95E Consider the next character if not
E94D DEC L L'=0x00
E94E BIT 7,(HL) Is the character facing left?
E950 JR Z,$E954 Jump if so
E952 XOR $01 Set A=1-A
E954 ADD A,A A=0 or 2
E955 LD B,A B'=0 or 2
E956 LD L,$02 Point HL' at byte 0x02 of the character's buffer
E958 LD A,D A=Y, the play area y-coordinate (2-39)
E959 SUB (HL) Subtract the character's y-coordinate
E95A CP $02 Set the carry flag if the sprite impinges on row Y
E95C JR C,$E966 Jump if the sprite impinges on row Y
E95E INC H Next character
E95F LD A,H A=character number
E960 CP $E7 Have we done all the characters (0xD7-0xE6)?
E962 JR NZ,$E8FC Jump back if not
E964 EXX
E965 RET
The character's sprite impinges on the tile at coordinates (X,Y).
E966 ADD A,B A=0-14 (index of the sprite tile at (X,Y))
E967 ADD A,$D7 0xD7<=A<=0xE5
E969 EXX
E96A LD H,A 0xD7<=H<=0xE5
E96B EXX
E96C LD L,$00 Point HL' at byte 0x00 of the character's buffer
E96E LD A,(HL) A=character's animatory state
E96F AND $07 Keep only bits 0-2
E971 LD A,(HL) A=character's animatory state
E972 JR NZ,$E976 Jump if the animatory state is congruent to 1-7 mod 8
E974 ADD A,$02 Add 2 if the animatory state is congruent to 0 mod 8
E976 OR $80 A>=0x81
E978 EXX
E979 LD L,A L>=0x81, 0xD7<=H<=0xE5
E97A LD A,(HL) A=sprite tile reference (0x00-0xD6, 0xD9-0xFF)
E97B LD E,A Copy this to E
E97C AND A Set the zero flag if this is the blank tile
E97D EXX
E97E JR Z,$E95E Jump back to consider the next character if the sprite tile is blank
A tile of this character's sprite needs to be printed at (X,Y). The apparent intention of the next section of code is to treat animatory states 0x78-0x7F/0xF8-0xFF (used only by the hook) specially, but the next instruction copies L' (which holds 0) instead of L (which holds the adjusted animatory state) into A.
E980 LD A,L A=0
E981 CP $F8 This instruction sets the carry flag
E983 EXX
E984 JR C,$E98F This jump is always made
The next section of code is never executed.
E986 LD H,$DB Point HL at one of the eight bytes at DBF8 (which are all zero)
E988 LD A,(HL) Pick up the byte
E989 AND A Set the zero flag
E98A JR Z,$E98F This jump would always be made
E98C LD ($A81E),A Update the attribute byte stored at A81E
Normal service resumes here.
E98F EXX
E990 LD A,(HL) A=character's animatory state
E991 EXX
E992 LD D,$C7 Point DE at the graphic data for the sprite tile
E994 LD HL,$A01E Point HL at the back buffer at A01E
E997 RLCA Is the character facing right?
E998 JR C,$E9A9 Jump if so
The character is facing left, so we can use the tile as-is (there is no need to flip it).
E99A EX DE,HL Now DE points at the back buffer, and HL points at the graphic data for the sprite tile
E99B LD A,(DE) Pick up a graphic byte from the back buffer
E99C OR (HL) OR on the sprite tile graphic byte
E99D INC H Point HL at the sprite tile mask byte
E99E AND (HL) AND on the sprite tile mask byte
E99F LD (DE),A Update the back buffer byte
E9A0 INC H Point HL at the next graphic byte of the sprite tile
E9A1 INC D Point DE at the next byte of the back buffer
E9A2 BIT 3,D Have we finished all 8 bytes?
E9A4 JR Z,$E99B Jump back if not
E9A6 EX DE,HL This instruction is redundant
E9A7 JR $E9BC Consider the next character
The character is facing right, so we need to flip the tile.
E9A9 LD B,$7E The table of mirror bytes is in page 0x7E
E9AB LD A,(DE) Pick up a sprite tile graphic byte
E9AC LD C,A Copy it to C
E9AD LD A,(BC) A=mirror image of the sprite tile graphic byte
E9AE OR (HL) OR on the back buffer graphic byte
E9AF LD (HL),A Store the result in the back buffer
E9B0 INC D Point DE at the sprite tile mask byte
E9B1 LD A,(DE) Pick this up in A
E9B2 LD C,A Copy it to C
E9B3 LD A,(BC) A=mirror image of the sprite tile mask byte
E9B4 AND (HL) AND on the back buffer graphic byte
E9B5 LD (HL),A Store the result in the back buffer
E9B6 INC D Point DE at the next graphic byte of the sprite tile
E9B7 INC H Point HL at the next byte of the back buffer
E9B8 BIT 3,H Have we finished all 8 bytes?
E9BA JR Z,$E9AB Jump back if not
E9BC EXX
E9BD JR $E95E Jump back to consider the next character
Prev: E8F0 Up: Map Next: E9BF