Prev: 68A1 Up: Map Next: 68F4
68A2: Transition
This is called when a visible character (a vischar, pointed to by IY) needs to change room, or to change position on the exterior map, e.g. when the hero moves outside of the main gate.
vischar.room is expected to already be set to the new room index. If the character is outdoors we take the given map position, (a tinypos, pointed to by HL) scale it up, multiplying the values by 4, then store those as vischar.mi.mappos. Otherwise we just copy them across without scaling.
If the current vischar is not the hero then we reset the character. Otherwise we're handling the hero so we either reset the visible scene for outdoors, or for the new room.
Input
HL Pointer to map position (type: tinypos_t).
IY Pointer to current visible character.
transition 68A2 EX DE,HL Save position into DE
68A3 PUSH IY Copy the current visible character pointer into HL
68A5 POP HL
68A6 LD A,L Extract the visible character's index/offset
68A7 PUSH AF Save it for later
68A8 ADD A,$0F Point HL at the visible character's position
68AA LD L,A
68AB LD A,(IY+$1C) Fetch the visible character's current room index
68AE AND A Are we outdoors?
68AF JP NZ,transition_1 Jump if not
We're outdoors.
Set position on X, Y axis and height by multiplying by 4.
68B2 LD B,$03 Iterate thrice: X, Y and height fields
transition_0 68B4 PUSH BC Save BC - multiply_by_4's output register
68B5 LD A,(DE) Fetch a position byte
68B6 CALL multiply_by_4 Multiply it by 4, widening it to a word in BC
68B9 LD (HL),C Store it to visible character's position and increment pointers
68BA INC L
68BB LD (HL),B
68BC INC L
68BD INC DE
68BE POP BC Restore
68BF DJNZ transition_0 Loop
68C1 JR transition_3 Jump over indoors case
We're indoors.
Set position on X, Y axis and height by copying.
transition_1 68C3 LD B,$03 Iterate thrice: X, Y and height fields
transition_2 68C5 LD A,(DE) Widen position bytes to words, store and increment pointers
68C6 LD (HL),A
68C7 INC L
68C8 LD (HL),$00
68CA INC L
68CB INC DE
68CC DJNZ transition_2 Loop
transition_3 68CE POP AF Retrieve vischar index/offset stacked at $68A7
68CF LD L,A
68D0 AND A Is it the hero?
68D1 JP Z,transition_4 Jump if so
Not the hero.
Commentary: This is an unusual construct. Why did the author not use JP NZ,$C5D3 above and fallthrough otherwise?
68D4 JP reset_visible_character If not, exit via reset_visible_character resetting the visible character
Hero only.
HL points to the hero's visible character at this point.
transition_4 68D7 INC L Point HL at the visible character's flags field (always $8001)
68D8 RES 7,(HL) Clear vischar_FLAGS_NO_COLLIDE in flags
68DA LD A,($801C) Get the visible character's room index
68DD LD ($68A0),A Set the global current room index
68E0 AND A Are we outdoors?
68E1 JP NZ,enter_room Jump if not
We're outdoors.
68E4 LD A,$0C Point HL at the visible character's input field (always $800D)
68E6 ADD A,L
68E7 LD L,A
68E8 LD (HL),$80 Set input to input_KICK
68EA INC L Point HL at the visible character's direction field (always $800E)
68EB LD A,(HL) Fetch the direction field and clear the non-direction bits, resetting the crawl flag
68EC AND $03
68EE LD (HL),A
68EF CALL reset_outdoors Reset the hero's position, redraw the scene then zoombox it onto the screen
68F2 JR squash_stack_goto_main Restart from main loop
Prev: 68A1 Up: Map Next: 68F4