![]() |
Routines |
| Prev: AD78 | Up: Map | Next: AE30 |
| ADBA | LD A,(IY+$0F) | Get the current room. | ||
| ADBD | CP (IY+$5A) | Does it equal the target room? (BCC1) | ||
| ADC0 | JR NZ,$ADC7 | Jump forward if not. | ||
| ADC2 | LD (IY-$14),$01 | Otherwise signal character is in the target room and return. | ||
| ADC6 | RET | |||
|
Move the character towards the target room.
|
||||
| ADC7 | LD D,$FF | Set D as "no match". | ||
| ADC9 | CALL $AC69 | Get the "next rooms" table for this room in HL. | ||
| ADCC | LD A,(IY+$0F) | Put the character's current room in A. | ||
| ADCF | CALL $AE30 | Can the room only be accessed via the 'in' key? | ||
| ADD2 | OR A | |||
| ADD3 | JR Z,$AE18 | Jump forward if not. | ||
|
Process a "next rooms" entry.
|
||||
| ADD5 | LD A,(HL) | Get the next room to move to. | ||
| ADD6 | CP $FF | Is it a terminating character (FF) instead? | ||
| ADD8 | JR Z,$AE26 | Jump forward if so, the B, C and D registers contain the best target room and co-ordinates. | ||
|
Look at the "next rooms" entry to work out how to get there.
|
||||
| ADDA | CALL $AE30 | Can the room only be accessed via the 'in' key? | ||
| ADDD | CP $01 | |||
| ADDF | JR Z,$ADEA | Jump forward if so. | ||
| ADE1 | LD A,(HL) | Get the room ID. | ||
| ADE2 | CP (IY+$5A) | Is it the target room? | ||
| ADE5 | JR NZ,$AE20 | Jump forward if not to look at the next entry. | ||
| ADE7 | XOR A | Signal 0 (character will walk the whole room) and jump forward to set it. | ||
| ADE8 | JR $AE18 | |||
| ADEA | LD A,(HL) | Get the target room ID. | ||
| ADEB | CP (IY+$6E) | Is it the previously visited room? (BCD5) | ||
| ADEE | JR Z,$AE20 | Jump forward if it is, we've just been here. | ||
|
Work out where to move the character.
|
||||
| ADF0 | EXX | Swap main registers. | ||
| ADF1 | ADD A,A | Double the ID to get a two byte offset. | ||
| ADF2 | LD D,$00 | Put this in DE. | ||
| ADF4 | LD E,A | |||
| ADF5 | LD HL,$AD78 | Add the base offset for the movement table. (AD78) | ||
| ADF8 | ADD HL,DE | |||
| ADF9 | LD C,(HL) | Put the first value in C. | ||
| ADFA | INC HL | Put the second value in B. | ||
| ADFB | LD B,(HL) | |||
| ADFC | LD A,(IY+$5A) | Get the movement ID of the target room. | ||
| ADFF | ADD A,A | Double the ID to get a two byte offset. | ||
| AE00 | LD E,A | Put this in DE. | ||
| AE01 | LD HL,$AD78 | Add the base offset for the movement table. (AD78) | ||
| AE04 | ADD HL,DE | |||
| AE05 | LD A,C | Make C the difference between the two values. | ||
| AE06 | SUB (HL) | |||
| AE07 | JR NC,$AE0B | |||
| AE09 | NEG | |||
| AE0B | LD C,A | |||
| AE0C | LD A,B | Add the difference in the two values in B to A to give us a "score" for this room. | ||
| AE0D | INC HL | |||
| AE0E | SUB (HL) | |||
| AE0F | JR NC,$AE13 | |||
| AE11 | NEG | |||
| AE13 | ADD A,C | |||
| AE14 | EXX | Swap main registers. | ||
| AE15 | CP D | Compare with the current match. | ||
| AE16 | JR NC,$AE20 | If this difference is greater, don't use the entry and skip forward. | ||
|
A room to move to has been found that's better than any others yet looked at, so use it.
|
||||
| AE18 | LD D,A | Set D to the current best "score" for the next room. | ||
| AE19 | LD B,(HL) | Put the desination room in B. | ||
| AE1A | INC HL | Put the target co-ordinate to move to that room in C. | ||
| AE1B | LD C,(HL) | |||
| AE1C | INC HL | Put the new co-ordinate in the destination room in E. | ||
| AE1D | LD E,(HL) | |||
| AE1E | JR $AE22 | Skip the next bit of code. | ||
|
Didn't find the target to move to, so skip to the next one.
|
||||
| AE20 | INC HL | Move to the next entry. | ||
| AE21 | INC HL | |||
| AE22 | INC HL | Ensure HL is pointing to the next place in the buffer. | ||
| AE23 | JP $ADD5 | Jump back to handle movement. | ||
|
Found the target room and co-ordinates to use for the next room, so set them.
|
||||
| AE26 | LD (IY+$64),C | Set the next room, target co-ordinates and new co-ordinates for this character. (BCCB / BCD0) / BCDA) | ||
| AE29 | LD (IY+$69),B | |||
| AE2C | LD (IY+$73),E | |||
| AE2F | RET | Return. | ||
| Prev: AD78 | Up: Map | Next: AE30 |