Routines
| Prev: CF43 | Up: Map | Next: D008 |
CF80: Save a sub-script call frame
|
Allocates a 7-byte node on the list at 9FE9: +0 the actor, +1/+2 HL (the calling instruction), +3/+4 the command's objects ($A034/$A035), +5 B, +6 the plan's verb (9FD6). CFB6 finds the current actor's frame; CFCF returns from the sub-script, restoring the script position and freeing the frame, and gives A = frame +5.
How it works:
1. Allocate a seven-byte node from the heap (A11C).
2. Fill it in: the actor ($A036); HL, where the script should carry on after the sub-script; the command's two objects ($A034, $A035); B; and the plan's verb (9FD6).
3. Link the node in at the head of the list of call frames at 9FE9.
4. The same block has two more entry points. CFB6 finds the current actor's frame by walking the list: NZ with IX at the frame, or Z if there is none. CFCF is the return: it finds the frame, sets the actor's script position back to the calling instruction, unlinks and frees the frame (A1C7), reloads the plan registers (D008) and returns the saved byte in A.
|
||||||||||
| CF80 | PUSH IX | Save IX on the stack | ||||||||
| CF82 | LD A,$07 | Load A with $07 - Allocate a 7-byte node | ||||||||
| CF84 | CALL $A11C | Call the routine "Allocate A + 3 bytes from the free list, cleared" (A11C) | ||||||||
| CF87 | LD A,($A036) | Read $A036 in "Game variables" into A - +0: the actor | ||||||||
| CF8A | LD (IX+$00),A | Store A in the first byte of the record at IX | ||||||||
| CF8D | LD (IX+$01),L | Store L in byte +1 of the record at IX - +1/+2: where to come back to | ||||||||
| CF90 | LD (IX+$02),H | Store H in byte +2 of the record at IX | ||||||||
| CF93 | LD DE,($A034) | Read $A034 in "Game variables" into DE - +3/+4: the objects | ||||||||
| CF97 | LD (IX+$03),E | Store E in byte +3 of the record at IX | ||||||||
| CF9A | LD (IX+$04),D | Store D in byte +4 of the record at IX | ||||||||
| CF9D | LD (IX+$05),B | +5: B | ||||||||
| CFA0 | LD A,($9FD6) | Read the plan's verb (9FD6) into A - +6: the plan's verb | ||||||||
| CFA3 | LD (IX+$06),A | Store A in byte +6 of the record at IX | ||||||||
| CFA6 | LD HL,($9FE9) | Read sub-script call frames (9FE9) into HL - Link it in at the head of the list | ||||||||
| CFA9 | LD ($9FE9),IX | Store IX in sub-script call frames (9FE9) | ||||||||
| CFAD | LD (IX-$02),L | Store L in byte -2 of the record at IX | ||||||||
| CFB0 | LD (IX-$01),H | Store H in byte -1 of the record at IX | ||||||||
| CFB3 | POP IX | Restore IX from the stack | ||||||||
| CFB5 | RET | Return to the caller | ||||||||
|
This entry point is used by the routines at 9B25, CC78, D008, E03A, E3B8, E6E6 and E70E.
|
||||||||||
| CFB6 | LD A,($A036) | Find this actor's call frame: Z if none | ||||||||
|
This entry point is used by the routine at E298.
|
||||||||||
| CFB9 | LD IX,$9FEB | Point IX at 9FEB in "Game variables" - Walk the call-frame list | ||||||||
| CFBD | PUSH AF | Save AF on the stack | ||||||||
| CFBE | CALL $A0F7 | Call the routine "Move IX to the next node of a list" (A0F7) - Next frame: Z at the end | ||||||||
| CFC1 | JR Z,$CFCC | If the zero flag is set, skip ahead to CFCC | ||||||||
| CFC3 | POP AF | Restore AF from the stack | ||||||||
| CFC4 | CP (IX+$00) | Compare A with the first byte of the record at IX - This actor's? | ||||||||
| CFC7 | JR NZ,$CFBD | If A differs from the first byte of the record at IX, go back to CFBD | ||||||||
| CFC9 | OR $01 | Make A non-zero, which clears the zero flag, and hand that back to the caller - Yes: NZ, IX = the frame | ||||||||
| CFCB | RET | Return to the caller | ||||||||
| CFCC | POP AF | Restore AF from the stack - None: Z | ||||||||
| CFCD | XOR A | Set A to zero, which sets the zero flag for the caller | ||||||||
| CFCE | RET | Return to the caller | ||||||||
|
This entry point is used by the routine at CC78.
|
||||||||||
| CFCF | CALL $CFB6 | Return from a sub-script: find the frame | ||||||||
| CFD2 | LD E,(IX+$01) | Read byte +1 of the record at IX into E - Back to the calling instruction | ||||||||
| CFD5 | LD D,(IX+$02) | Read byte +2 of the record at IX into D | ||||||||
| CFD8 | LD ($9FD9),DE | The script continues from there | ||||||||
| CFDC | LD (IY+$01),E | Store E in byte +1 of the record at IY | ||||||||
| CFDF | LD (IY+$02),D | Store D in byte +2 of the record at IY | ||||||||
| CFE2 | PUSH IX | Save IX on the stack - Unlink the frame | ||||||||
| CFE4 | POP DE | Restore DE from the stack | ||||||||
| CFE5 | PUSH IY | Save IY on the stack | ||||||||
| CFE7 | LD IY,$9FE9 | Point IY at sub-script call frames (9FE9) | ||||||||
| CFEB | CALL $A104 | Call the routine "Find the node before node DE in the list at IY" (A104) | ||||||||
| CFEE | LD L,(IX-$02) | Read byte -2 of the record at IX into L - Copy the link bytes (IX-2/-1) to IY-2/-1 | ||||||||
| CFF1 | LD H,(IX-$01) | Read byte -1 of the record at IX into H | ||||||||
| CFF4 | LD (IY-$02),L | Store L in byte -2 of the record at IY | ||||||||
| CFF7 | LD (IY-$01),H | Store H in byte -1 of the record at IY | ||||||||
| CFFA | LD A,(IX+$05) | Read byte +5 of the record at IX into A - A = frame +5 for the caller | ||||||||
| CFFD | PUSH AF | Save AF on the stack | ||||||||
| CFFE | CALL $A1C7 | Free the frame | ||||||||
| D001 | CALL $D008 | Call the routine "Load the current actor's plan registers" (D008) - Reload the plan registers (the caller's) | ||||||||
| D004 | POP AF | Restore AF from the stack | ||||||||
| D005 | POP IY | Restore IY from the stack | ||||||||
| D007 | RET | Return to the caller | ||||||||
| Prev: CF43 | Up: Map | Next: D008 |