Skip to content

Commit cc2daaf

Browse files
authored
Merge pull request #2 from 8bitmcu/zm
ZMachine Interpreter
2 parents 7e9389a + 4e68f83 commit cc2daaf

54 files changed

Lines changed: 16354 additions & 23 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

LICENSE.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,29 @@ The `vi` implementation is derived from Toybox.
4040
* **License:** **0BSD** (Zero-Clause BSD).
4141
* **Summary:** Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
4242

43-
### 3. st7789_mpy
43+
### 3. frotz (Zmachine interpreter)
44+
The Z-Machine interpreter is based on Frotz.
45+
* **Copyright:** 1995-1997 Stefan Jokisch, 1998-present David Griffith and contributors.
46+
* **License:** **GNU General Public License v2.0 (or later)**.
47+
* **Summary:** Frotz is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
48+
49+
### 4. st7789_mpy
4450
* **Copyright:** Russ Hughes.
4551
* **License:** **MIT License**.
4652

47-
### 4. Terminus Font
53+
### 5. Terminus Font
4854
* **Copyright:** (c) 2020 Dimitar Zhekov.
4955
* **License:** **SIL Open Font License 1.1**.
5056

51-
### 5. MicroPython
57+
### 6. MicroPython
5258
* **Copyright:** (c) Damien P. George.
5359
* **License:** **MIT License**.
5460

5561
---
5662

5763
### Implementation Note for the T-Deck
5864
While the original `vi` code follows the 0BSD license and the `st` engine follows the MIT/X Consortium license, the specific architectural modifications in this repository—including the **MicroPython VFS Bridge**, **NLR Exception Guarding**, **Zero-allocation Status Bar**, and **GC-safe Memory Management**—are contributed under the project's primary MIT license.
65+
66+
---
67+
68+
While the original source code for mpy_vt is provided under the MIT license, compiling it with the optional frotz module creates a combined work that falls under the GNU General Public License v2.0 (GPL-2.0) upon distribution.

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ As a showcase of the engine's capabilities, this project includes a fully functi
1717

1818
## ⚡ Quick Install (Pre-compiled Binaries)
1919

20-
Don't want to set up a build environment? You can download and flash the latest pre-compiled firmware directly to your T-Deck.
20+
You can download and flash the latest pre-compiled firmware directly to your T-Deck.
2121

2222
### Option A: Flash from command line
2323

@@ -61,6 +61,7 @@ You can execute the following commands directly in the MicroPython REPL:
6161
| `clear` | Clears the screen |
6262
| `telehack` | Connects telnet to telehack.com |
6363
| `retrocampus` | Connects telnet to bbs.retrocampus.com |
64+
| `zork` | Launches Zork through the ZMachine interpreter. Note: `zork1.dat` must be present on your SD card root directory |
6465

6566
## 🚀 VT Features
6667

@@ -92,6 +93,7 @@ This project is composed of six specialized modules that works in tandem:
9293
| `tdeck_trk` | Motion Engine | Interrupts | Low-level driver for the T-Deck trackball. Uses GPIO interrupts to track relative motion (deltas) and supports edge-detection for short/long click durations. |
9394
| `tdeck_kvm` | Stream Glue | Read/Write | A composite Keyboard-Video-Mouse (trackball) object. It binds vt (Output) and tdeck_kbd (Input) into a single stream object compatible with os.dupterm. |
9495
| `vi` | Text Editor | Read/Write | A C-integrated port of the classic `vi` editor. |
96+
| `zm` | ZMachine Interpreter | Read/Write | A port of the `frotz` Zmachine interpreter. |
9597

9698

9799
## 📟 T-Deck Hardware Integration
@@ -302,14 +304,22 @@ make repl PORT=/dev/ttyUSB0
302304
| **`inject()`** | `data` | **Macro Injection.** Accepts a string or bytes and places them into the high-priority ring buffer to be read by the REPL or active application. |
303305
| **`ioctl()`** | `cmd, arg` | Aggregates status from both objects (e.g., checks if KBD has data or if VT is ready). |
304306

305-
### **5. `vi.Vi` (Text Editor)**
307+
### **5. `zm.ZMachine` (ZMachine Interpreter)**
308+
*Port of the `frotz` interpreter.*
309+
310+
| Method | Parameters | Description |
311+
| :--- | :--- | :--- |
312+
| **`ZMachine()`** | `filename, stream, cols, rows` | **Constructor.** Creates a ZMachine instance with a given filename, using `stream` for input/outputs. |
313+
| **`run()`** | None | Launches the Zmachine interpreter. |
314+
315+
### **6. `vi.Vi` (Text Editor)**
306316
*Port of the classic `vi` text-editor.*
307317

308318
| Method | Parameters | Description |
309319
| :--- | :--- | :--- |
310320
| **`Vi()`** | `filename, stream, cols, rows` | **Constructor.** Launches the vi editor, opening a given filename, using `stream` for input/outputs. |
311321

312-
### **6. `st7789` (Modified Display Driver)**
322+
### **7. `st7789` (Modified Display Driver)**
313323
*Standard display driver with specific C-layer extensions for terminal performance.*
314324

315325
| Feature | Type | Description |
@@ -318,12 +328,13 @@ make repl PORT=/dev/ttyUSB0
318328

319329
## ⚖️ License & Attribution
320330

321-
This project is licensed under the **MIT License**.
331+
This project's source code is licensed under the **MIT License**. However, if you compile the firmware with the optional `frotz` module enabled, the resulting compiled binary is distributed under the **GPLv2 License**.
322332

323333
### Third-Party Components:
324334
* **st License:** MIT (c) st engineers.
325335
* **st7789_mpy:** (c) Russ Hughes. MIT License
326336
* **vi** (Toybox): (c) Rob Landley, Jarno Mäkipää. 0BSD License (Zero-Clause BSD).
337+
* **frotz**: (c) Stefan Jokisch, David Griffith. GPLv2 License
327338
* **MicroPython**: (c) Damien P. George. MIT License.
328339

329340
### Fonts & Assets:

modules/micropython.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,8 @@ include(${CMAKE_CURRENT_LIST_DIR}/tdeck_trk/micropython.cmake)
1616
# include the vi editor module
1717
include(${CMAKE_CURRENT_LIST_DIR}/vi/micropython.cmake)
1818

19+
# include the zm module (Z-machine interpreter)
20+
include(${CMAKE_CURRENT_LIST_DIR}/zm/micropython.cmake)
21+
22+
# include the tu (text ui) module
23+
include(${CMAKE_CURRENT_LIST_DIR}/tu/micropython.cmake)

modules/scripts/main.py

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import time
1616
import status
1717

18+
1819
# Screen dimensions in pixel
1920
screen_width = 320
2021
screen_height = 240
@@ -28,21 +29,47 @@
2829
rows = usable_height // rfont.HEIGHT
2930

3031
# Must be called before initializing LCD / Keyboard
31-
pwr_en = machine.Pin(10, machine.Pin.OUT)
32-
pwr_en.value(1)
32+
machine.Pin(10, machine.Pin.OUT, value=1)
33+
time.sleep(0.1)
34+
35+
# Pull all SPI CS pins HIGH before touching the bus (prevents bus conflicts)
36+
machine.Pin(12, machine.Pin.OUT, value=1) # display CS
37+
machine.Pin(9, machine.Pin.OUT, value=1) # LoRa CS
38+
machine.Pin(39, machine.Pin.OUT, value=1) # SD CS
39+
machine.Pin(38, machine.Pin.IN, machine.Pin.PULL_UP) # MISO pull-up
3340
time.sleep(0.1)
3441

42+
# Mount SD Card (Experimental; doesn't seem to always work)
43+
try:
44+
import sdcard
45+
sd_spi = machine.SoftSPI(baudrate=400000, sck=machine.Pin(40), mosi=machine.Pin(41), miso=machine.Pin(38))
46+
sd = sdcard.SDCard(sd_spi, machine.Pin(39, machine.Pin.OUT))
47+
48+
os.mount(os.VfsFat(sd), '/sd')
49+
print("SD mounted at /sd")
50+
except Exception as e:
51+
print("SD mount failed: ", e)
52+
sd = None
53+
54+
# Create hardware SPI; this configures the GPIO matrix for pins 40/41.
55+
# SoftSPI is no longer used after this point.
56+
spi = machine.SPI(1, baudrate=40000000, sck=machine.Pin(40), mosi=machine.Pin(41), miso=machine.Pin(38))
57+
58+
# The card is already initialized. Only the transport changes.
59+
# Gives the already-mounted SD card faster hardware SPI for data transfers.
60+
if sd is not None:
61+
sd.spi = spi
62+
3563
# Initialze LCD
36-
spi = machine.SPI(1, baudrate=40000000, sck=machine.Pin(40), mosi=machine.Pin(41))
3764
tft = st7789.ST7789(spi,
38-
screen_height,
39-
screen_width,
40-
reset=machine.Pin(1, machine.Pin.OUT),
41-
dc=machine.Pin(11, machine.Pin.OUT),
42-
cs=machine.Pin(12, machine.Pin.OUT),
43-
backlight=machine.Pin(42, machine.Pin.OUT),
44-
rotation=1,
45-
buffer_size=screen_width*rfont.HEIGHT*2)
65+
screen_height,
66+
screen_width,
67+
reset=machine.Pin(1, machine.Pin.OUT),
68+
dc=machine.Pin(11, machine.Pin.OUT),
69+
cs=machine.Pin(12, machine.Pin.OUT),
70+
backlight=machine.Pin(42, machine.Pin.OUT),
71+
rotation=1,
72+
buffer_size=screen_width*rfont.HEIGHT*2)
4673
tft.init()
4774

4875
# Initialize ST engine
@@ -61,7 +88,7 @@
6188
# Redirect to REPL
6289
os.dupterm(kvm)
6390

64-
# status bar component
91+
# Status bar component
6592
sts = status.StatusBar(term, width=cols)
6693
sts.refresh()
6794

@@ -209,7 +236,10 @@ def telnet_retrocampus():
209236
retrocampus = Command(telnet_retrocampus)
210237

211238

239+
def zm_zork():
240+
import zm
241+
m = zm.ZMachine("/sd/zork1.dat", kvm, cols, rows)
242+
m.run()
212243

244+
zork = Command(zm_zork)
213245

214-
# type wlan to connect to wifi
215-
# type telehack for telnet telehack

0 commit comments

Comments
 (0)