Routines |
Prev: AA8D | Up: Map | Next: AB66 |
This moves the map when the hero walks around outdoors. The map is shunted around in the opposite direction to the apparent character motion.
Used by the routines at setup_movable_items and main_loop.
|
||||||||||||||
move_map | AAB2 | LD A,($68A0) | Ignore any attempt to move the map when we're indoors | |||||||||||
AAB5 | AND A | |||||||||||||
AAB6 | RET NZ | |||||||||||||
AAB7 | LD HL,$8007 | Is the hero's vischar_BYTE7_DONT_MOVE_MAP flag set? (See AF93) | ||||||||||||
AABA | BIT 6,(HL) | |||||||||||||
AABC | RET NZ | Return if so | ||||||||||||
AABD | LD HL,$800A | Point HL at the hero's animation pointer field | ||||||||||||
AAC0 | LD E,(HL) | Fetch the animation pointer into DE | ||||||||||||
AAC1 | INC L | |||||||||||||
AAC2 | LD D,(HL) | |||||||||||||
AAC3 | INC L | |||||||||||||
AAC4 | LD C,(HL) | Load the current animation index | ||||||||||||
AAC5 | INC DE | Step forward through the animation structure to the map direction field | ||||||||||||
AAC6 | INC DE | |||||||||||||
AAC7 | INC DE | |||||||||||||
AAC8 | LD A,(DE) | Read the animation's map direction field | ||||||||||||
AAC9 | CP $FF | A map direction of 255 means "don't move" | ||||||||||||
AACB | RET Z | Return if 255 | ||||||||||||
AACC | BIT 7,C | If animation index's vischar_ANIMINDEX_REVERSE bit is set then exchange the up and down directions | ||||||||||||
AACE | JR Z,move_map_0 | |||||||||||||
AAD0 | XOR $02 | |||||||||||||
move_map_0 | AAD2 | PUSH AF | Preserve map direction | |||||||||||
AAD3 | ADD A,A | Point HL at move_map_jump_table[A] | ||||||||||||
AAD4 | LD C,A | |||||||||||||
AAD5 | LD B,$00 | |||||||||||||
AAD7 | LD HL,$AB31 | |||||||||||||
AADA | ADD HL,BC | |||||||||||||
AADB | LD A,(HL) | Load jump address into HL | ||||||||||||
AADC | INC HL | |||||||||||||
AADD | LD H,(HL) | |||||||||||||
AADE | LD L,A | |||||||||||||
AADF | POP AF | Restore map direction | ||||||||||||
AAE0 | PUSH HL | Stack the jump table target - our final RET will call it | ||||||||||||
AAE1 | PUSH AF | Preserve map direction | ||||||||||||
Calculate the position at which we should stop scrolling the map
For example in the animation anim_walk_tl (where 'tl' denotes a character walking towards the top left) we're asked to scroll the map to the bottom and right. If the map scrolls further than 192 across we'll render off the side of the map, so we clamp the scroll at that point. Similar for vertical.
|
||||||||||||||
AAE2 | LD BC,$7C00 | Set the initial clamp position (x,y) to (C = 0,B = 124) | ||||||||||||
AAE5 | CP $02 | If the map scroll direction is direction_BOTTOM_* (scrolling up) then the y limit becomes 0 | ||||||||||||
AAE7 | JR C,move_map_1 | |||||||||||||
AAE9 | LD B,$00 | |||||||||||||
move_map_1 | AAEB | CP $01 | If the map scroll direction is direction_*_LEFT (scrolling right) then the x limit becomes 192 | |||||||||||
AAED | JR Z,move_map_2 | |||||||||||||
AAEF | CP $02 | |||||||||||||
AAF1 | JR Z,move_map_2 | |||||||||||||
AAF3 | LD C,$C0 | |||||||||||||
move_map_2 | AAF5 | LD HL,($81BB) | Read the current map position into HL | |||||||||||
AAF8 | LD A,L | If current map X equals limit X then return | ||||||||||||
AAF9 | CP C | |||||||||||||
AAFA | JR NZ,move_map_4 | |||||||||||||
move_map_3 | AAFC | POP AF | Restore map direction | |||||||||||
AAFD | POP HL | Restore jump table target | ||||||||||||
AAFE | RET | Return | ||||||||||||
move_map_4 | AAFF | LD A,H | If current map Y equals limit Y then return | |||||||||||
AB00 | CP B | |||||||||||||
AB01 | JR Z,move_map_3 | |||||||||||||
AB03 | POP AF | Restore map direction | ||||||||||||
Now we form a counter that's used by the move_map functions to decide in which order the map shunt operations will be issued. Instead of immediately shunting the map in the named direction, they use this counter to work through a pattern of moves.
|
||||||||||||||
AB04 | LD HL,$A7C6 | Point HL at move_map_y | ||||||||||||
AB07 | CP $02 | Is the map direction direction_BOTTOM_*? | ||||||||||||
AB09 | JR NC,move_map_5 | Jump if so | ||||||||||||
AB0B | LD A,(HL) | Cycle the counter forwards for TOP cases | ||||||||||||
AB0C | INC A | |||||||||||||
AB0D | JR move_map_6 | |||||||||||||
move_map_5 | AB0F | LD A,(HL) | Cycle the counter backwards for BOTTOM cases | |||||||||||
AB10 | DEC A | |||||||||||||
move_map_6 | AB11 | AND $03 | Clamp to 0..3 | |||||||||||
AB13 | LD (HL),A | Save it back to move_map_y | ||||||||||||
AB14 | EX DE,HL | Transpose (for passing into move_map_*) | ||||||||||||
Now choose the game window offset that will be used by plot_game_window. A 255 in the high byte means to plot the screen offset (which direction?) by half a byte. The low byte is a byte offset added to the source data.
|
||||||||||||||
AB15 | LD HL,$0000 | Clear the game window offset (GWO) | ||||||||||||
AB18 | AND A | If move_map_y is 0 GWO becomes (0, 0) | ||||||||||||
AB19 | JR Z,move_map_7 | |||||||||||||
AB1B | LD L,$60 | If move_map_y is 2 GWO becomes (4 * 24, 0) | ||||||||||||
AB1D | CP $02 | |||||||||||||
AB1F | JR Z,move_map_7 | |||||||||||||
AB21 | LD HL,$FF30 | If move_map_y is 1 GWO becomes (2 * 24, 255) | ||||||||||||
AB24 | CP $01 | |||||||||||||
AB26 | JR Z,move_map_7 | |||||||||||||
AB28 | LD L,$90 | Otherwise GWO becomes (6 * 24, 255) | ||||||||||||
move_map_7 | AB2A | LD ($A7C7),HL | Write it to game_window_offset | |||||||||||
AB2D | LD HL,($81BB) | Point HL at map_position | ||||||||||||
AB30 | RET | NOT a return - pops and calls the move_map_* routine pushed at AAE0 which then returns | ||||||||||||
move_map_jump_table | AB31 | DEFW move_map_up_left | move_map_up_left | |||||||||||
AB33 | DEFW move_map_up_right | move_map_up_right | ||||||||||||
AB35 | DEFW move_map_down_right | move_map_down_right | ||||||||||||
AB37 | DEFW move_map_down_left | move_map_down_left | ||||||||||||
Called when player moves down-right (map is shifted up or left). This moves the map in the pattern up/left/none/left.
|
||||||||||||||
move_map_up_left | AB39 | LD A,(DE) | Fetch move_map_y | |||||||||||
AB3A | AND A | If move_map_y is 0 then jump to shunt_map_up | ||||||||||||
AB3B | JP Z,shunt_map_up | |||||||||||||
AB3E | BIT 0,A | If move_map_y is 2 then return | ||||||||||||
AB40 | RET Z | |||||||||||||
AB41 | JP shunt_map_left | Otherwise move_map_y is 1 or 3 - jump to shunt_map_left | ||||||||||||
Called when player moves down-left (map is shifted up or right). This moves the map in the pattern up-right/none/right/none.
|
||||||||||||||
move_map_up_right | AB44 | LD A,(DE) | Fetch move_map_y | |||||||||||
AB45 | AND A | If move_map_y is 0 then jump to shunt_map_up_right | ||||||||||||
AB46 | JP Z,shunt_map_up_right | |||||||||||||
AB49 | CP $02 | If move_map_y is 1 or 3 then return | ||||||||||||
AB4B | RET NZ | |||||||||||||
AB4C | JP shunt_map_right | Otherwise move_map_y is 2 - jump to shunt_map_right | ||||||||||||
Called when player moves up-left (map is shifted down or right). This moves the map in the pattern right/none/right/down.
|
||||||||||||||
move_map_down_right | AB4F | LD A,(DE) | Fetch move_map_y | |||||||||||
AB50 | CP $03 | If move_map_y is 3 then jump to shunt_map_down | ||||||||||||
AB52 | JP Z,shunt_map_down | |||||||||||||
AB55 | RRA | If move_map_y is 0 or 2 then jump to shunt_map_right | ||||||||||||
AB56 | JP NC,shunt_map_right | |||||||||||||
AB59 | RET | Otherwise move_map_y is 1 - return | ||||||||||||
Called when player moves up-right (map is shifted down or left). This moves the map in the pattern none/left/down/left.
|
||||||||||||||
move_map_down_left | AB5A | LD A,(DE) | Fetch move_map_y | |||||||||||
AB5B | CP $01 | If move_map_y is 1 then jump to shunt_map_left | ||||||||||||
AB5D | JP Z,shunt_map_left | |||||||||||||
AB60 | CP $03 | If move_map_y is 3 then jump to shunt_map_down_left | ||||||||||||
AB62 | JP Z,shunt_map_down_left | |||||||||||||
AB65 | RET | Otherwise move_map_y is 0 or 2 - return |
Prev: AA8D | Up: Map | Next: AB66 |