Routines |
Prev: C5D3 | Up: Map | Next: C6A0 |
This returns the coordinates the character should move to, given a route_t pointer in HL. Coordinates are returned as a tinypos_t when moving to a door or as an xy_t when moving to a numbered location.
If the route specifies 'wander' then one of eight random locations starting from route.step is chosen.
|
||||||||||||||
get_target | C651 | LD A,(HL) | Get the route index | |||||||||||
C652 | CP $FF | Is it routeindex_255_WANDER? ($FF) | ||||||||||||
C654 | JR NZ,gt_not_halt | Jump if not | ||||||||||||
Wander around randomly.
Uses route.step + rand(0..7) to index locations[].
|
||||||||||||||
gt_wander | C656 | INC HL | Clear the bottom three bits of route.step | |||||||||||
C657 | LD A,(HL) | |||||||||||||
C658 | AND $F8 | |||||||||||||
C65A | LD (HL),A | |||||||||||||
C65B | CALL random_nibble | Get a pseudo-random number in A | ||||||||||||
C65E | AND $07 | Make it 0..7 | ||||||||||||
C660 | ADD A,(HL) | Add the random value to route.step | ||||||||||||
C661 | LD (HL),A | |||||||||||||
C662 | JR gt_pick_loc | Jump | ||||||||||||
gt_not_halt | C664 | PUSH HL | Preserve the route pointer | |||||||||||
C665 | INC HL | Load route.step | ||||||||||||
C666 | LD C,(HL) | |||||||||||||
Control can arrive here with route.index set to zero. This happens when the hero stands up during breakfast, is pursued by guards, then when left to idle sits down and the pursuing guards resume their original positions. get_route() will return in that case a zero pointer so it starts fetching from $0001. In the Spectrum ROM location $0001 holds XOR A ($AF).
|
||||||||||||||
C667 | CALL get_route | Get the route for A in DE | ||||||||||||
Since all of the routes are packed togther, this relies on being able to fetch the previous route's terminator.
|
||||||||||||||
C66A | LD H,$00 | High byte is set to zero unless... route.step is $FF when it's set to $FF | ||||||||||||
C66C | LD A,C | |||||||||||||
C66D | CP $FF | |||||||||||||
C66F | JR NZ,get_target_0 | |||||||||||||
C671 | DEC H | |||||||||||||
get_target_0 | C672 | LD L,A | HL = -1, or route.step | |||||||||||
C673 | ADD HL,DE | Point DE at the next route byte | ||||||||||||
C674 | EX DE,HL | |||||||||||||
C675 | LD A,(DE) | Read a byte of route | ||||||||||||
C676 | CP $FF | Is it routebyte_END? ($FF) | ||||||||||||
C678 | POP HL | Irrespectively restore HL | ||||||||||||
C679 | JR Z,gt_route_ends | Jump if so | ||||||||||||
C67B | AND $7F | Clear its door_REVERSE flag ($80) | ||||||||||||
C67D | CP $28 | Is it a door index? | ||||||||||||
C67F | JR NC,gt_location | Jump if not | ||||||||||||
Route byte < 40: A door.
|
||||||||||||||
gt_door | C681 | LD A,(DE) | Re-read routebyte to get the reversed flag | |||||||||||
C682 | BIT 7,(HL) | Reversed? | ||||||||||||
C684 | JR Z,get_target_1 | Jump if not | ||||||||||||
C686 | XOR $80 | Toggle reverse flag | ||||||||||||
get_target_1 | C688 | CALL get_door | Turn the door index into a door_t pointer (in HL) | |||||||||||
C68B | INC HL | Advance HL to point at door.pos | ||||||||||||
C68C | LD A,$80 | Return with A set to 128 | ||||||||||||
C68E | RET | |||||||||||||
Route byte = 40..117: A location index.
|
||||||||||||||
gt_location | C68F | LD A,(DE) | The location index is offset by 40 | |||||||||||
C690 | SUB $28 | |||||||||||||
gt_pick_loc | C692 | ADD A,A | Point HL at location[A] | |||||||||||
C693 | LD HL,$783A | |||||||||||||
C696 | ADD A,L | |||||||||||||
C697 | LD L,A | |||||||||||||
C698 | JR NC,get_target_2 | |||||||||||||
C69A | INC H | |||||||||||||
get_target_2 | C69B | XOR A | Return with A set to zero | |||||||||||
C69C | RET | |||||||||||||
gt_route_ends | C69D | LD A,$FF | Return with A set to 255 | |||||||||||
C69F | RET |
Prev: C5D3 | Up: Map | Next: C6A0 |