Z-machine stack size?

Has anyone examined how large the stack is in Infocom’s various interpreters for 8-bit computers?

Has anyone examined how much stack space the larger Infocom games require? (AMFV, Bureaucracy, Zork Zero…)

3 Likes

Since we now have access to the source code for one of Infocom’s interpreters [1] I guess we can check:

	PAGE
	SBTTL "--- MEMORY ORGANIZATION ---"

TRUE	EQU	$FF
FALSE	EQU	0

DSTART	EQU	0		; START OF DIRECT-PAGE RAM

MSTACK	EQU	MSTART+$FE	; TOP OF MACHINE STACK (254 BYTES)
IOBUFF	EQU	MSTART+$100	; 256-BYTE DISK I/O BUFFER
ZSTACK	EQU	MSTART+$200	; Z-STACK (255 WORDS)
ZSTAKL	EQU	255		; LENGTH OF Z-STACK IN WORDS
TOPSTA	EQU	(2*ZSTAKL)+ZSTACK	; TOP OF Z-STACK
PTABLE	EQU	MSTART+$400	; PAGING TABLE ($140 BYTES/$A0 WORDS)
LRUMAP	EQU	MSTART+$550	; TIMESTAMP MAP ($A0 BYTES)
LOCALS  EQU     MSTART+$600     ; LOCAL VARIABLE STORAGE (32 BYTES)
BUFFER  EQU     MSTART+$620     ; I/O LINE BUFFER (32 BYTES)
BUFSAV  EQU     MSTART+$640     ; I/O AUX BUFFER (32 BYTES)
ZIP	EQU	MSTART+$700	; START OF EXECUTABLE CODE
ZCODE	EQU	ZIP+$1700	; START OF Z-CODE (ASSUME 5.75K ZIP)

So at least for V3, apparently 255 words was deemed enough for the stack?

I don’t know about the larger games, though. You may be able to test A Mind Forever Voyaging, because of a bug in Library Mode. Every time you move the cursor it leaks a few bytes - I’m not sure exactly how much - of stack space that isn’t released until you exit Library Mode. (Apparently it’s because the main Library Mode loop calls functions without handling their return values, causing them to remain on the stack.)

So if you start the game, immediately go to Library Mode and hold down the “N”, eventually the game will crash. The game starts at 7:07 pm. Each time you move the cursor the clock advances by one minute. (Which doesn’t really make sense from a story point of view, but…) I only have access to the DOS and Mac versions in emulation, though, so I don’t have much to compare with, but:

The DOS interpreter crashes around 8:54 pm, i.e. less than 120 moves.
The Mac interpreter crashes around 8:52 pm, i.e. less than 120 moves.
Frotz 2.50 crashes around 11:00 pm, i.e. less than than 240 moves.

Frotz defines zword stack[STACK_SIZE], where STACK_SIZE is 1024. So perhaps a reasonable guess would be that Infocom’s had at most 512 words, and quite possibly less? (After all, it might not crash immediately when the stack space runs out.)

I have no idea about the V6 games.

[1] https://retrotinker.blogspot.com/2018/02/z-intepreter-source-for-coco-recovered.html

3 Likes