Difference between revisions of "Z-Machine"

From CPCWiki - THE Amstrad CPC encyclopedia!
Jump to: navigation, search
Line 4: Line 4:
  
 
CPCZVM features a virtual memory system supporting both the Z-machines RAM and ROM.
 
CPCZVM features a virtual memory system supporting both the Z-machines RAM and ROM.
 +
 +
==Running an adventure==
 +
 +
* Copy CPCZVM.COM, ZXZVM.BIN and the game file (e.g. ADVENT.Z3) to media which has at least 64KB free. All of these should  be in the same location. For Amstrad's CPM2.2 it is advised to use a VENDOR/SYSTEM formatted disc.
 +
* Boot into CP/M.
 +
* Select the disc (e.g. |B)
 +
* Type: CPCZVM ADVENT.Z3 to start.
  
 
==Technical Information==
 
==Technical Information==

Revision as of 06:03, 7 July 2019

The Z-Machine is a text based interpreter which runs text adventures made by Infocom and Z-code files.

CPCZVM is a Z-Machine interpreter for the CPC which runs under CPM. It is a modification of ZXZVM, an interpreter made by [[John Elliott] for the PCW. The Amstrad version was converted by Kevin Thacker.

CPCZVM features a virtual memory system supporting both the Z-machines RAM and ROM.

Running an adventure

  • Copy CPCZVM.COM, ZXZVM.BIN and the game file (e.g. ADVENT.Z3) to media which has at least 64KB free. All of these should be in the same location. For Amstrad's CPM2.2 it is advised to use a VENDOR/SYSTEM formatted disc.
  • Boot into CP/M.
  • Select the disc (e.g. |B)
  • Type: CPCZVM ADVENT.Z3 to start.

Technical Information

  • The program reads the first 64KB of the game file, padding with 0's if less than 64KB, and writes out a SWAP.DAT file. A Z-machine has a maximum of 64KB of RAM. Therefore the disc which CPCZVM is run from must have at least 64KB free and be writeable. When the RAM is written to this swap file is updated. This swap file is also re-generated from the game file when the game is restarted.
  • Part of the CPC's memory is used for the virtual memory cache. A page table describes which virtual memory blocks are loaded and their physical location within RAM. This is initially populated from the start from the game file. When a read is done, the virtual memory address is looked up in the page table, and if it is mapped to physical memory then the physical memory is read. A write is similar to a read with an additional flag being set if a write has been made to a mapped page. If a virtual memory page is not currently loaded, then depending on the metric used, a page is chosen to be evicted. If the page has been modified it is committed to the swap file. Then the new page is loaded into the same physical location. During game play, any access to virtual memory in the first 64KB comes from the swap file, and any accesses above 64KB come from the game file. In this way the virtual memory supports both Z-Machine RAM and Z-Machine ROM.
  • CP/M is used because it has a random access filesystem compared to AMSDOS which doesn't. The random access is required to read blocks from the swap and game file when needed.
  • Some versions of the z-machine require that the screen can be split into more than 1 window. The VT52 terminal emulation in CPM3.0 on the CPC is unsuitable because it only supports a single window compared to the VT52 terminal emulation on the ZX Spectrum Plus 3 and the PCW. Therefore it was decided to use the firmware TXT functions to provide this.
  • Disc accesses use normal CP/M functions so it will work with other devices such as RAM discs, Harddisks etc.