Skip to content

quit and restart creates orphan code

First RESTART also needs to be a RETURN-type

txd.c
=====
line 921
	caseline (0x07, "RESTART",         NIL,      NIL,      NIL,      NIL,      NONE,   RETURN); // this should also be a RETURN-type

Then there needs to be a check in decode_operands that checks if QUIT and RESTART should be treated as PLAIN or RETURN.

txd.c
=====
line 1092-
	if (!decode.first_pass) {
		if (opcode.opcode == 0xBA || opcode.opcode == 0xB7) {
			// QUIT or RESTART (should this be expanded to other RETURN-types?)
			// These are considered as RETURN-type if the next opcode is illegal, otherwise they are PLAIN.
			// If the next address is a valid routine start, it is also considered as RETURN.
			if
				((decode.pc - (unsigned long)story_scaler * header.strings_offset) % (decode.pc * code_scaler) == 0 && read_data_byte(decode.pc + 1) < 16) {
				// Valid entrypoint for routine, keep type as RETURN
				opcode.type = RETURN;
			}
			else {
				// TODO: Check if next byte is a bad opcode; if it is, don't set type to PLAIN
				opcode.type = PLAIN;
			}
		}
	}

This check could be more sophisticated but this works for example Trinity (Release 12 / Serial Number 860926), routine at 0x28cfc and Craverly Heights for Dialog, routine at 0xa93c.