![]() |
Routines |
Prev: 59136 | Up: Map | Next: 59366 |
Used by the routines at 26075, 59406, 59461, 59516, 59575 and 60032. Copies a background tile of the play area into the back buffer at 40990, superimposes character sprite tiles and a foreground tile as appropriate, and then copies the resultant tile to the screen. Also sets the corresponding attribute byte.
|
||||||||||||
59148 | PUSH HL | Put the screen coordinates onto the stack | ||||||||||
59149 | LD A,H | Compute the corresponding display file address in HL | ||||||||||
59150 | AND 7 | |||||||||||
59152 | RRCA | |||||||||||
59153 | RRCA | |||||||||||
59154 | RRCA | |||||||||||
59155 | ADD A,L | |||||||||||
59156 | LD L,A | |||||||||||
59157 | LD A,H | |||||||||||
59158 | AND 24 | |||||||||||
59160 | ADD A,64 | |||||||||||
59162 | LD H,A | |||||||||||
59163 | EX (SP),HL | Put the display file address onto the stack and get the screen coordinates back in HL | ||||||||||
59164 | LD DE,(32766) | DE=play area coordinates of the top-left corner of the screen | ||||||||||
59168 | ADD HL,DE | HL=play area coordinates of the tile to be printed | ||||||||||
59169 | PUSH HL | Push these coordinates onto the stack... | ||||||||||
59170 | EXX | |||||||||||
59171 | POP DE | ...and pop them into DE' | ||||||||||
59172 | EXX | |||||||||||
59173 | LD A,H | A=Y, the play area y-coordinate (2-39) | ||||||||||
59174 | LD D,183 | Set D=184+INT(Y/6) (184-190) | ||||||||||
59176 | INC D | |||||||||||
59177 | SUB 6 | |||||||||||
59179 | JR NC,59176 | |||||||||||
59181 | ADD A,86 | 80<=A<=85 | ||||||||||
59183 | ADD A,A | A=160, 162, 164, 166, 168 or 170 | ||||||||||
59184 | LD B,A | B=160+2*(Y%6) | ||||||||||
59185 | LD A,L | A=X, the play area x-coordinate (0-255) | ||||||||||
59186 | AND 248 | Keep only bits 3-7 | ||||||||||
59188 | RRA | Slide them down into bits 0-4; now A=INT(X/8) | ||||||||||
59189 | RRCA | |||||||||||
59190 | RRCA | |||||||||||
59191 | LD E,A | Point DE at the Z value for the play area location (X,Y) | ||||||||||
59192 | LD A,L | A=X, the play area x-coordinate (0-255) | ||||||||||
59193 | AND 7 | Keep only bits 0-2; now A=X%8 | ||||||||||
59195 | PUSH AF | Save this value briefly | ||||||||||
59196 | ADD A,160 | 160<=A<=167 | ||||||||||
59198 | LD H,A | H=160+(X%8) | ||||||||||
59199 | LD L,21 | Point HL at byte 21 of page 160+(X%8) | ||||||||||
59201 | LD C,(HL) | Now C=128 (if X%8=0), 64, 32, 16, 8, 4, 2, or 1 (if X%8=7) | ||||||||||
59202 | LD A,(DE) | A=Z (value of byte INT(X/8) of page 184+INT(Y/6)) | ||||||||||
59203 | LD L,A | L=Z (0-101) | ||||||||||
59204 | LD H,191 | Point HL at the table of Z' values at 48896 | ||||||||||
59206 | LD A,(HL) | A=Z' (0, 1, 3, 7, 14, 31, 128, 134, 199, 215, 240, 252, or 255) | ||||||||||
59207 | AND C | Is bit 7-(X%8) of Z' set? | ||||||||||
59208 | JR Z,59214 | Jump if not | ||||||||||
59210 | LD A,B | Otherwise set B=172+2*(Y%6) | ||||||||||
59211 | ADD A,12 | |||||||||||
59213 | LD B,A | |||||||||||
59214 | SET 7,L | L=128+Z (128-229) | ||||||||||
59216 | POP AF | A=X%8 | ||||||||||
59217 | ADD A,184 | H=184+X%8 | ||||||||||
59219 | LD H,A | |||||||||||
59220 | LD C,(HL) | C=Z'' (value of byte 128+Z of page 184+X%8) | ||||||||||
59221 | SET 5,E | E=32+INT(X/8) | ||||||||||
59223 | LD A,(DE) | A=value of byte 32+INT(X/8) of page 184+INT(Y/6) | ||||||||||
59224 | LD L,A | L=attribute byte address LSB (0-27) | ||||||||||
59225 | LD A,E | A=32+INT(X/8) | ||||||||||
59226 | XOR 96 | A=64+INT(X/8) | ||||||||||
59228 | LD E,A | Point DE at the window flags for the play area location (X,Y) | ||||||||||
59229 | LD A,(BC) | A=T (value of byte Z'' of page 160+2*(Y%6) or 172+2*(Y%6)) | ||||||||||
We have collected the T value for the play area location (X,Y). Bits 7 and 6 of T have the following meanings:
When bit 7 of T is set and bit 6 is reset (10), bits 3-5 are unused, and bit 2 is set only if the right-hand window of a pair is at this location. The LSBs of the addresses of the graphic data for the two half-tiles that make up the foreground tile are derived from T' (0-31) and the window flags; the MSBs are always 128. When bit 7 of T is reset, bit 5 is unused (always reset), and bits 2-4 indicate the MSB of the address of the tile's graphic data (128, 136, 144, 152 or 160); the LSB is equal to T'. Finally, bits 1 and 0 of T indicate the MSB of the address of the tile's attribute byte (168, 169, 170 or 171); the LSB (0-27, already collected in L at this point) is found in byte 32+INT(X/8) of page 184+INT(Y/6). |
||||||||||||
59230 | AND 3 | Keep only bits 0 and 1 of T | ||||||||||
59232 | ADD A,168 | 168<=A<=171 | ||||||||||
59234 | LD H,A | 168<=H<=171 | ||||||||||
59235 | LD A,(HL) | A=play area tile attribute byte | ||||||||||
59236 | LD (43038),A | Save it at 43038 for later retrieval | ||||||||||
59239 | LD A,(BC) | A=T | ||||||||||
59240 | INC B | B=161+2*(Y%6) or 173+2*(Y%6); now BC points at the T' value | ||||||||||
59241 | RLCA | Does this play area location have a background tile and a foreground tile? | ||||||||||
59242 | JR NC,59324 | Jump if not | ||||||||||
The play area location under consideration has a background tile and a foreground tile.
|
||||||||||||
59244 | BIT 7,A | Is there a window here? | ||||||||||
59246 | JR NZ,59268 | Jump if not | ||||||||||
There is a window at this location.
|
||||||||||||
59248 | CALL 63450 | Collect the window flags | ||||||||||
59251 | JR Z,59259 | Jump unless we are dealing with the right-hand window of a pair | ||||||||||
59253 | AND 35 | Keep only bits 5 (light indicator), 1 and 0 (decoration indicator) of the window flags | ||||||||||
59255 | ADD A,96 | Set bit 7 if the light is off (i.e. copy bit 5 into bit 7) | ||||||||||
59257 | RRCA | Move bits 1 and 0 (decoration indicator) into bits 7 and 6, and the light indicator back into bit 5 | ||||||||||
59258 | RRCA | |||||||||||
59259 | AND 224 | Keep only bits 5 (light indicator), 6 and 7 (decoration indicator) of the window flags | ||||||||||
59261 | LD E,A | Copy these bits to E | ||||||||||
59262 | LD A,(BC) | A=T' (0-31 for window tiles) | ||||||||||
59263 | OR E | A=foreground tile identifier | ||||||||||
59264 | LD L,159 | Use tile 159 in page 128 (which is blank) as the background tile | ||||||||||
59266 | JR 59281 | |||||||||||
There is no window at this location, and it has a background tile and a transparent foreground tile.
|
||||||||||||
59268 | AND 120 | Keep only bits 2-5 of T | ||||||||||
59270 | RRA | |||||||||||
59271 | SCF | Shift bits 2-5 into bits 1-4 and set bit 7 | ||||||||||
59272 | RRA | |||||||||||
59273 | LD L,A | L=background tile reference (even number >= 128) | ||||||||||
59274 | LD A,(BC) | A=T' | ||||||||||
59275 | RLCA | Is bit 7 of T' set? | ||||||||||
59276 | JR NC,59279 | Jump if not | ||||||||||
59278 | INC L | Increment the background tile reference (to an odd number >= 129) | ||||||||||
59279 | SCF | A=T' with bit 7 set | ||||||||||
59280 | RRA | |||||||||||
59281 | LD E,A | E=foreground tile identifier | ||||||||||
59282 | LD H,128 | Point HL at the background tile graphic data | ||||||||||
Now HL holds the base address of the background tile graphic data.
|
||||||||||||
59284 | PUSH DE | Save the foreground tile identifier (in E) | ||||||||||
59285 | CALL 59136 | Copy the background tile into the back buffer at 40990 | ||||||||||
59288 | LD A,1 | Superimpose sprite tiles for characters who are indoors (z=1) | ||||||||||
59290 | CALL 59640 | |||||||||||
59293 | POP BC | Restore the foreground tile identifier to C | ||||||||||
Now we superimpose the foreground tile. The 16 graphic and mask bytes for the foreground tile are found in two groups of 8 bytes in pages 128-135.
|
||||||||||||
59294 | LD B,192 | The LSB of the first group of 8 bytes is found in page 192 | ||||||||||
59296 | LD DE,40990 | Point DE at the back buffer at 40990 | ||||||||||
59299 | LD A,(BC) | A=LSB of the first group of 8 bytes | ||||||||||
59300 | LD L,A | Copy the LSB to L | ||||||||||
59301 | LD H,128 | Point HL at the first byte (a graphic byte) in the group | ||||||||||
59303 | LD B,4 | There are 4 pairs of bytes per group | ||||||||||
59305 | LD A,(DE) | A=back buffer byte | ||||||||||
59306 | OR (HL) | OR on the graphic byte | ||||||||||
59307 | INC H | Point HL at the corresponding mask byte | ||||||||||
59308 | AND (HL) | AND on the mask byte | ||||||||||
59309 | INC H | Point HL at the next graphic byte | ||||||||||
59310 | LD (DE),A | Replace the back buffer byte | ||||||||||
59311 | INC D | Point DE at the next back buffer byte | ||||||||||
59312 | DJNZ 59305 | Jump back until all 8 bytes have been done | ||||||||||
59314 | LD B,193 | The LSB of the second group of 8 bytes is found in page 193 | ||||||||||
59316 | LD A,(BC) | A=LSB of the second group of 8 bytes | ||||||||||
59317 | INC C | Set the zero flag if we've just done the second group | ||||||||||
59318 | LD C,255 | Signal: the second group is next | ||||||||||
59320 | JR NZ,59300 | Jump back until both groups have been done | ||||||||||
59322 | JR 59342 | |||||||||||
The play area location under consideration has only one tile: either a background tile (if bit 6 of T is reset), or an opaque foreground tile (bit 6 of T set).
|
||||||||||||
59324 | AND 184 | Keep only bits 3-5 and 7 (bits 2-4 and 6 of T) | ||||||||||
59326 | RLCA | Copy bit 6 of T into the carry flag | ||||||||||
59327 | PUSH AF | Save the carry flag | ||||||||||
59328 | SCF | Now A has bit 7 set, and a copy of bits 2-4 of T in bits 3-5 | ||||||||||
59329 | RRA | |||||||||||
59330 | LD H,A | H=128, 136, 144, 152 or 160 | ||||||||||
59331 | LD A,(BC) | A=T' | ||||||||||
59332 | LD L,A | Point HL at the tile graphic data | ||||||||||
59333 | CALL 59136 | Copy the tile into the back buffer at 40990 | ||||||||||
59336 | POP AF | Restore the carry flag | ||||||||||
59337 | LD A,1 | Superimpose sprite tiles for characters who are indoors (z=1) if we're dealing with a background tile | ||||||||||
59339 | CALL NC,59640 | |||||||||||
Now we can superimpose sprite tiles for characters who are in the foreground.
|
||||||||||||
59342 | LD A,2 | Superimpose sprite tiles for characters who are between a building and the sidewalk (z=2), and then for characters who are on the sidewalk or road (z=4) | ||||||||||
59344 | CALL 59635 | |||||||||||
The tile in the back buffer is now ready to be drawn.
|
||||||||||||
59347 | POP DE | DE=display file address | ||||||||||
59348 | LD C,E | C=corresponding attribute file address LSB | ||||||||||
59349 | LD A,D | A=display file address MSB (64, 72 or 80) | ||||||||||
59350 | LD HL,40990 | Point HL at the back buffer containing the tile to be drawn | ||||||||||
59353 | RRCA | A=88, 89 or 90 | ||||||||||
59354 | RRCA | |||||||||||
59355 | RRCA | |||||||||||
59356 | ADD A,80 | |||||||||||
59358 | LD B,A | Point BC at the appropriate byte of the attribute file | ||||||||||
59359 | LD A,(43038) | Collect the attribute byte saved earlier at 43038 | ||||||||||
59362 | LD (BC),A | Copy it to the attribute file | ||||||||||
59363 | JP 59139 | Copy the tile to the display file |
Prev: 59136 | Up: Map | Next: 59366 |
The Z value (0<=Z<=101) for the play area location (X,Y) is found in byte INT(X/8) of page 184+INT(Y/6). Then the Z' value is found in byte Z of page 191, and the Z'' value in byte 128+Z of page 184+X%8.
Z'' and bit 7-(X%8) of Z' determine the address, P, of the T value for the play area location (X,Y): Z'' is the LSB, and the MSB is either 160+2*(Y%6) or 172+2*(Y%6), depending on whether bit 7-(X%8) of Z' is reset or set. The address of the T' value is P+256.