![]() |
Routines |
| Prev: 55219 | Up: Map | Next: 55524 |
|
Used by the routine at MoveEntity.
Tests each cell of the level that the entity's box covers, by calling TestGroupObjects, and retests a cell when a collision moves the entity. When bit 6 of the flags is set, a z within one page of 255 is stored in field 31 after a zero top byte has been snapped up by one unit. A hit planted by HandleOverlap then turns the heading away from it. Purpose of bit 6 is not yet known.
|
||||||||
|
The cell is the high byte of x and the high byte of y. A collision can move those bytes, and the extent can make the entity cover the next cell.
|
||||||||
| TestEntityCells | 55268 | LD L,(IX+2) | Take the cell from the high bytes of x and y. | |||||
| 55271 | LD H,(IX+5) | |||||||
| 55274 | PUSH HL | Test that cell. | ||||||
| 55275 | CALL TestGroupObjects | |||||||
| 55278 | POP HL | Restore the cell. | ||||||
| 55279 | LD A,(IX+2) | Retest the previous column when the high byte of x moved. | ||||||
| 55282 | CP L | |||||||
| 55283 | JR Z,TestEntityCells_SpanX | |||||||
| 55285 | DEC A | Use the column below the new x. | ||||||
| 55286 | LD L,A | |||||||
| 55287 | JR TestEntityCells_Second | |||||||
| TestEntityCells_SpanX | 55289 | LD A,(IX+3) | The entity covers the next column when the x extent carries. | |||||
| 55292 | ADD A,(IX+11) | |||||||
| 55295 | JR NC,TestEntityCells_Moved | |||||||
| TestEntityCells_Second | 55297 | PUSH HL | Test the next column. | |||||
| 55298 | INC L | |||||||
| 55299 | CALL TestGroupObjects | |||||||
| 55302 | POP HL | Restore the cell. | ||||||
| 55303 | LD A,(IX+5) | Retest this row when the high byte of y moved. | ||||||
| 55306 | CP H | |||||||
| 55307 | JR Z,TestEntityCells_SpanY | |||||||
| 55309 | LD H,A | Test the entity's row, then the row above. | ||||||
| 55310 | PUSH HL | |||||||
| 55311 | CALL TestGroupObjects | |||||||
| 55314 | POP HL | |||||||
| 55315 | INC H | |||||||
| 55316 | JR TestEntityCells_Next | |||||||
| TestEntityCells_SpanY | 55318 | LD A,(IX+6) | The entity covers the next row when the y extent carries. | |||||
| 55321 | ADD A,(IX+12) | |||||||
| 55324 | JR NC,TestEntityCells_Snap | |||||||
| 55326 | INC H | Test the next row. | ||||||
| 55327 | PUSH HL | |||||||
| 55328 | CALL TestGroupObjects | |||||||
| 55331 | POP HL | |||||||
| TestEntityCells_Next | 55332 | INC L | Test the diagonal cell too. | |||||
| 55333 | JR TestEntityCells_Cell | |||||||
| TestEntityCells_Moved | 55335 | LD A,(IX+5) | Use the entity's row when y has moved. | |||||
| 55338 | CP H | |||||||
| 55339 | JR Z,TestEntityCells_SpanRow | |||||||
| 55341 | LD H,A | Use that row. | ||||||
| 55342 | JR TestEntityCells_Cell | |||||||
| TestEntityCells_SpanRow | 55344 | LD A,(IX+6) | Cover the next row when the y extent carries. | |||||
| 55347 | ADD A,(IX+12) | |||||||
| 55350 | JR NC,TestEntityCells_Snap | |||||||
| 55352 | INC H | Use the next row. | ||||||
| TestEntityCells_Cell | 55353 | CALL TestGroupObjects | Test this cell. | |||||
|
Bit 6 of the flags stores a z that is within one page of 255 into field 31. A zero top byte is snapped up by one unit first. A pickup stores zero instead.
|
||||||||
| TestEntityCells_Snap | 55356 | LD C,0 | Start with no hit. HandleOverlap plants one in this byte. | |||||
| 55358 | BIT 6,(IX+30) | Snap z when bit 6 of the flags is set. | ||||||
| 55362 | JR Z,TestEntityCells_Hit | |||||||
| 55364 | LD L,(IX+9) | A zero top byte of z is snapped up by one unit. | ||||||
| 55367 | LD A,(IX+8) | |||||||
| 55370 | AND A | |||||||
| 55371 | JR NZ,TestEntityCells_Distance | |||||||
| 55373 | LD L,A | Write that snap back into z. | ||||||
| 55374 | LD (IX+9),A | |||||||
| 55377 | INC A | |||||||
| 55378 | LD (IX+8),A | |||||||
| 55381 | LD A,(IX+0) | A pickup stores zero in field 31. | ||||||
| 55384 | CP 15 | |||||||
| 55386 | JR Z,TestEntityCells_Store | |||||||
| 55388 | LD A,L | Otherwise measure from one. | ||||||
| 55389 | INC A | |||||||
| TestEntityCells_Distance | 55390 | LD H,A | Store the distance when z is within one page of 255. | |||||
| 55391 | XOR A | |||||||
| 55392 | LD DE,255 | |||||||
| 55395 | SBC HL,DE | |||||||
| 55397 | OR H | |||||||
| 55398 | JR NZ,TestEntityCells_Hit | |||||||
| TestEntityCells_Store | 55400 | LD (IX+31),L | Remember that distance in field 31. | |||||
|
A hit turns the heading. Fields 24 and 25 supply the two components, and the low bits of the hit choose which axis is turned.
|
||||||||
| TestEntityCells_Hit | 55403 | LD A,C | Return when nothing was hit. | |||||
| 55404 | AND A | |||||||
| 55405 | RET Z | |||||||
| 55406 | LD B,A | Remember the hit and clear it. | ||||||
| 55407 | XOR A | |||||||
| 55408 | LD (55357),A | |||||||
| 55411 | BIT 5,(IX+1) | Return when bit 5 of the frame is set. | ||||||
| 55415 | RET NZ | |||||||
| 55416 | LD A,(IX+24) | Return when fields 24 and 25 are both zero. | ||||||
| 55419 | OR (IX+25) | |||||||
| 55422 | RET Z | |||||||
| 55423 | LD A,B | Return when the hit was 255. | ||||||
| 55424 | CP 255 | |||||||
| 55426 | RET Z | |||||||
| 55427 | LD A,(IX+24) | Use field 24 as one component. | ||||||
| 55430 | AND A | |||||||
| 55431 | JR NZ,TestEntityCells_Component | |||||||
| 55433 | LD A,(IX+17) | Read the heading. | ||||||
| 55436 | ADD A,16 | Add 16 to the heading. | ||||||
| 55438 | AND %00111111 | Use the low six bits of the heading. | ||||||
| 55440 | CP 32 | Use 254 when those bits are 32 or more. | ||||||
| 55442 | JR C,TestEntityCells_Component | |||||||
| 55444 | LD A,254 | Use 254 for that component. | ||||||
| TestEntityCells_Component | 55446 | LD L,A | Keep the first component. | |||||
| 55447 | LD A,(IX+25) | Use field 25 as the other component. | ||||||
| 55450 | AND A | |||||||
| 55451 | JR NZ,TestEntityCells_Other | |||||||
| 55453 | LD A,(IX+17) | Read the heading. | ||||||
| 55456 | AND %00111111 | Use the low six bits of the heading. | ||||||
| 55458 | CP 32 | Use 254 when those bits are 32 or more. | ||||||
| 55460 | JR C,TestEntityCells_Other | |||||||
| 55462 | LD A,254 | Use 254 for that component. | ||||||
| TestEntityCells_Other | 55464 | LD H,A | Keep the second component. | |||||
| 55465 | LD A,B | Use the low two bits of the hit. | ||||||
| 55466 | AND 3 | |||||||
| 55468 | JR Z,TestEntityCells_Swap | Swap the components when the hit was on x. | ||||||
| 55470 | LD B,H | |||||||
| 55471 | LD C,L | |||||||
| 55472 | JR TestEntityCells_Heading | |||||||
| TestEntityCells_Swap | 55474 | LD A,H | Turn the second component to face the other way. | |||||
| 55475 | NEG | |||||||
| 55477 | LD C,A | |||||||
| 55478 | LD A,B | |||||||
| 55479 | RRA | |||||||
| 55480 | RRA | |||||||
| 55481 | RRA | |||||||
| 55482 | LD B,L | Keep the first component. | ||||||
| TestEntityCells_Heading | 55483 | RRCA | Face the patched step away from the first component. | |||||
| 55484 | LD E,A | |||||||
| 55485 | XOR B | |||||||
| 55486 | RLA | |||||||
| 55487 | LD B,254 | |||||||
| 55489 | JR C,TestEntityCells_Signs | |||||||
| 55491 | LD A,B | Face the other way when the signs differ. | ||||||
| 55492 | NEG | |||||||
| 55494 | LD B,A | |||||||
| TestEntityCells_Signs | 55495 | LD A,E | Compare the signs of the two components. | |||||
| 55496 | XOR C | |||||||
| 55497 | RLA | |||||||
| 55498 | JR NC,TestEntityCells_Apply | Keep the turn when the signs agree. | ||||||
| 55500 | BIT 7,B | A positive turn is 1. | ||||||
| 55502 | LD B,1 | |||||||
| 55504 | JR Z,TestEntityCells_Apply | |||||||
| 55506 | LD B,255 | A negative turn is 255. | ||||||
| TestEntityCells_Apply | 55508 | LD A,(IX+17) | Read the heading. | |||||
| 55511 | LD C,A | Keep the old heading aside. | ||||||
| 55512 | ADD A,B | Add the turn to the heading. | ||||||
| 55513 | AND %00111111 | Use the low six bits of the new heading. | ||||||
| 55515 | LD B,A | Keep the new heading aside. | ||||||
| 55516 | LD A,C | Use bits 6-7 of the old heading. | ||||||
| 55517 | AND 192 | |||||||
| 55519 | OR B | Combine them with the new heading. | ||||||
| 55520 | LD (IX+17),A | |||||||
| 55523 | RET | Return. | ||||||
| Prev: 55219 | Up: Map | Next: 55524 |