Prev: 39668 Up: Map Next: 39714
39682: Change Magic Knight's current room if possible
Used by the routines at 39714 and 39758.
Input
A Magic Knight's new x-coordinate upon entering new room
DE Exit that Magic Knight is leaving old room from; either 0 (left exit) or 1 (right exit)
Output
F Zero flag set if Magic Knight can't leave his current room, reset otherwise
39682 PUSH AF Store new x-coordinate for later
39683 XOR A Set Magic Knight's temporary-movement flags to zero (new room, so Magic Knight can move both left and right)...
39684 LD (23451),A ...
39687 LD HL,48811 Point HL to room connectivity data table
39690 LD A,(23702) Load Magic Knight's current room's index into A...
39693 ADD A,A ...double it...
39694 LD C,A ...and load into BC...
39695 LD B,0 ...
39697 ADD HL,BC Add BC as offset to HL
39698 ADD HL,DE Point to left or right exit from current room, as determined by DE
39699 LD A,(HL) Load new room number into A...
39700 CP 255 ...and if this is 255 (i.e. Magic Knight can't leave his current room)...
39702 JR Z,39711 ...set zero flag and exit routine...
39704 LD (23702),A ...else update Magic Knight's current room to be this new room index
39707 POP BC Restore new x-coordinate to B...
39708 LD A,B ...and load back into A
39709 OR A Reset zero flag
39710 RET Return
39711 POP BC Restore AF to BC...
39712 LD A,B ...and load A with contents of B to restore to what it was on entering this routine
39713 RET Return
Prev: 39668 Up: Map Next: 39714