Prev: 9F15 Up: Map Next: A007
9F21: In permitted area
This checks the hero's map position and colours the flag accordingly. It also detects escapes.
This also sets the main (hero's) map position in hero_map_position_x to that of the hero's vischar position.
Used by the routine at main_loop.
in_permitted_area 9F21 LD HL,$800F Point HL at the hero's vischar position
9F24 LD DE,$81B8 Point DE at the hero's map position
9F27 LD A,($68A0) Get the global current room index
9F2A AND A Is it indoors?
9F2B JP NZ,ipa_indoors Jump if so
ipa_outdoors 9F2E CALL pos_to_tinypos Scale down the vischar position and assign the result to the hero's map position
Check for the hero escaping across the edge of the map (obviously this only can happen outdoors).
9F31 LD HL,($8018) If the hero's isometric x position is 217 * 8 or higher... jump to "hero has escaped"
9F34 LD DE,$06C8
9F37 SBC HL,DE
9F39 JP NC,escaped
9F3C LD HL,($801A) If the hero's isometric y position is 137 * 8 or higher... jump to "hero has escaped"
9F3F LD DE,$0448
9F42 SBC HL,DE
9F44 JP NC,escaped
9F47 JR ipa_picking_or_cutting Otherwise jump over the indoors handling
ipa_indoors 9F49 LDI Copy position across
9F4B INC L
9F4C LDI
9F4E INC L
9F4F LDI
Set the flag red if picking a lock, or cutting wire.
ipa_picking_or_cutting 9F51 LD A,($8001) Read hero's vischar flags
9F54 AND $03 AND the flags with (vischar_FLAGS_PICKING_LOCK OR vischar_FLAGS_CUTTING_WIRE)
9F56 JP NZ,ipa_set_flag_red If either of those flags is set then set the morale flag red
Is it night time?
9F59 LD A,($A13D) Read the game clock
9F5C CP $64 If it's 100 or higher then it's night time
9F5E JR C,ipa_day Jump if it's not night time
At night, home room is the only safe place.
ipa_night 9F60 LD A,($68A0) What room are we in?
9F63 CP $02 Is it the home room? (room_2_HUT2LEFT)
9F65 JP Z,ipa_set_flag_green Jump if so
9F68 JP ipa_set_flag_red Otherwise set the flag red
If in solitary then bypass all checks.
ipa_day 9F6B LD A,($A13A) Are we in solitary?
9F6E AND A
9F6F JP NZ,ipa_set_flag_green Jump if we are
Not in solitary: turn the route into an area number then check that area is a permitted one.
9F72 LD HL,$8002 Point HL at the hero's vischar route
9F75 LD A,(HL) Load the route index
9F76 INC L Load the route step
9F77 LD C,(HL)
9F78 BIT 7,A Is the route index's route_REVERSED flag set? ($80)
9F7A JR Z,ipa_check_wander Jump if not
9F7C INC C Otherwise increment the route step
ipa_check_wander 9F7D CP $FF Is the route index routeindex_255_WANDER? ($FF)
9F7F JR NZ,ipa_en_route Jump if not
Hero is wandering.
9F81 LD A,(HL) Load the route step again and clear its bottom three bits
9F82 AND $F8
9F84 CP $08 If step is 8 then set A to 1 (hut area) otherwise set A to 2 (exercise yard area)
9F86 LD A,$01
9F88 JR Z,ipa_bounds_check
9F8A LD A,$02
ipa_bounds_check 9F8C CALL in_permitted_area_end_bit Check that the hero is in the specified room or camp bounds
9F8F JR Z,ipa_set_flag_green Jump if within the permitted area (Z set)
9F91 JR ipa_set_flag_red Otherwise goto set_flag_red
Hero is en route.
Check regular routes against route_to_permitted.
ipa_en_route 9F93 AND $7F Mask off the route_REVERSED flag
9F95 LD HL,$9EE4 Point HL at route_to_permitted table
9F98 LD B,$07 Set B for seven iterations
Start loop
ipa_route_check_loop 9F9A CP (HL) Does the first byte of the entry match the route index?
9F9B INC HL
9F9C JR Z,ipa_route_check_found Jump if so
9F9E INC HL Otherwise move to the next entry
9F9F INC HL
9FA0 DJNZ ipa_route_check_loop ...loop
If the route is not found in route_to_permitted assume a green flag
9FA2 JR ipa_set_flag_green Jump if route index wasn't found in the table
Route index was found in route_to_permitted.
ipa_route_check_found 9FA4 LD E,(HL) Load DE with the sub-table's address
9FA5 INC HL
9FA6 LD D,(HL)
9FA7 PUSH DE Move it into HL
9FA8 POP HL
9FA9 LD B,$00 Zero B so we can use BC in the next instruction
9FAB ADD HL,BC Fetch byte at HL + BC
9FAC LD A,(HL)
9FAD PUSH DE Save the sub-table's address
9FAE CALL in_permitted_area_end_bit Check that the hero is in the specified room or camp bounds
9FB1 POP HL Restore the sub-table address
9FB2 JR Z,ipa_set_flag_green Jump if within the permitted area (Z set)
9FB4 LD A,($8002) Load the hero's vischar route index
9FB7 BIT 7,A If the route index's route_REVERSED flag is set ($80) move the sub-table pointer forward by a byte
9FB9 JR Z,ipa_check_route_places
9FBB INC HL
Search through the list testing against the places permitted for the route we're on.
ipa_check_route_places 9FBC LD BC,$0000 Initialise index
Start loop
ipa_check_route_places_loop 9FBF PUSH BC Save index
9FC0 PUSH HL Save sub-table address
9FC1 ADD HL,BC Fetch byte at HL + BC
9FC2 LD A,(HL)
9FC3 CP $FF Did we hit the end of the list?
9FC5 JR Z,ipa_pop_and_set_flag_red Jump if we did
9FC7 CALL in_permitted_area_end_bit Check that the hero is in the specified room or camp bounds
9FCA POP HL Restore the sub-table address
9FCB POP BC Restore the index
9FCC JR Z,ipa_set_route_then_set_flag_green If within the area (Z set) break out of the loop
9FCE INC C Increment counter
9FCF JR ipa_check_route_places_loop ...loop
ipa_set_route_then_set_flag_green 9FD1 LD A,($8002) Fetch the hero's route index
9FD4 LD B,A
9FD5 CALL set_hero_route Set the hero's route (to A,C) unless in solitary
9FD8 JR ipa_set_flag_green Jump to "set flag green"
ipa_pop_and_set_flag_red 9FDA POP BC Restore the stack pointer position - don't care about order
9FDB POP HL
9FDC JR ipa_set_flag_red Jump to "set flag red"
Green flag code path.
ipa_set_flag_green 9FDE XOR A Clear the red flag
9FDF LD C,$44 Load C with attribute_BRIGHT_GREEN_OVER_BLACK
ipa_flag_select 9FE1 LD ($A138),A Assign red_flag
9FE4 LD A,C Shuffle wanted attribute value into A
9FE5 LD HL,$5842 Point HL at the first attribute byte of the morale flag
9FE8 CP (HL) Is the flag already the correct colour?
9FE9 RET Z Return if so
9FEA CP $44 Are we in the green flag case?
9FEC JP NZ,set_morale_flag_screen_attributes Exit via set_morale_flag_screen_attributes if not
9FEF LD A,$FF Silence the bell
9FF1 LD ($A130),A
9FF4 LD A,C Shuffle wanted attribute value into A
9FF5 JP set_morale_flag_screen_attributes Exit via set_morale_flag_screen_attributes
Red flag code path.
ipa_set_flag_red 9FF8 LD C,$42 Load C with attribute_BRIGHT_RED_OVER_BLACK
9FFA LD A,($5842) Fetch the first attribute byte of the morale flag
9FFD CP C Is the flag already the correct colour?
9FFE RET Z Return if so
9FFF XOR A Set the vischar's input to 0
A000 LD ($800D),A
A003 LD A,$FF Set the red flag flag
A005 JR ipa_flag_select Jump to flag_select
Prev: 9F15 Up: Map Next: A007