# too101/thaimsx architecture

> Architecture diagram of the GitHub repository too101/thaimsx, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/too101/thaimsx
- Repository: https://github.com/too101/thaimsx

## Overview

thaimsx is Z80 firmware that adds Thai input and output to MSX BASIC, distributed as an 8 KB cartridge or loadable BLOAD program. The principal workflow is machine startup and BASIC integration, followed by Thai keyboard entry and BASIC display/printing; separate commands convert strings, and graphics output is supported. The README documents these capabilities, but sampled source is limited to tape-conversion utilities, so internal call wiring is intentionally conservative.

Main entry points: [`src/init.asm`](https://github.com/too101/thaimsx/blob/main/src/init.asm) (Initialization), [`src/printon.asm`](https://github.com/too101/thaimsx/blob/main/src/printon.asm) (Print Hooks), [`src/main.asm`](https://github.com/too101/thaimsx/blob/main/src/main.asm) (Cartridge ROM), [`src/loader_bload.asm`](https://github.com/too101/thaimsx/blob/main/src/loader_bload.asm) (BLOAD Loader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and Loading"]
  node_cartridge["Cartridge ROM<br/>[main.asm]"]
  node_initialization["Initialization<br/>[init.asm]"]
  node_bload["BLOAD Loader<br/>[loader_bload.asm]"]
  node_workram["Runtime RAM<br/>[workram.asm]"]
  node_cas_builder["CAS Builder<br/>[mkcas.py]"]
  node_wav_converter["WAV Converter<br/>[cas2wav.py]"]
end

subgraph group_input["Thai Input"]
  node_keyboard["Thai Keyboard<br/>[keyboard.asm]"]
  node_keytables["Key Tables<br/>[kwtables_data.asm]"]
end

subgraph group_output["Thai Output"]
  node_thai_font["Thai Font<br/>[font_data.asm]"]
  node_screen["Text and Graphics<br/>[printon.asm]"]
  node_printer["Thai Printing<br/>[printer.asm]"]
end

subgraph group_basic["BASIC Extensions"]
  node_commands["BASIC Commands<br/>[thaicmd.asm]"]
  node_statement_hooks["BASIC Hooks<br/>[statement.asm]"]
  node_print_hooks["Print Hooks<br/>[printon.asm]"]
end

node_user(("MSX User"))
node_machine["MSX BASIC / BIOS"]
node_printer_device["Printer"]

node_user -->|"uses BASIC"| node_machine
node_machine -->|"starts ROM"| node_cartridge
node_cartridge -->|"initializes"| node_initialization
node_machine -.->|"loads program"| node_bload
node_bload -.->|"loads into"| node_workram
node_initialization -->|"enables input"| node_keyboard
node_keyboard -->|"uses mappings"| node_keytables
node_initialization -->|"enables display"| node_screen
node_screen -->|"uses glyphs"| node_thai_font
node_machine -->|"dispatches BASIC"| node_statement_hooks
node_statement_hooks -->|"handles commands"| node_commands
node_machine -->|"prints BASIC"| node_print_hooks
node_print_hooks -->|"renders text"| node_screen
node_print_hooks -->|"routes LPRINT"| node_printer
node_printer -->|"prints output"| node_printer_device
node_user -.->|"converts BLOAD"| node_cas_builder
node_cas_builder -.->|"converts CAS"| node_wav_converter

click node_cartridge "https://github.com/too101/thaimsx/blob/main/src/main.asm"
click node_initialization "https://github.com/too101/thaimsx/blob/main/src/init.asm"
click node_bload "https://github.com/too101/thaimsx/blob/main/src/loader_bload.asm"
click node_workram "https://github.com/too101/thaimsx/blob/main/src/workram.asm"
click node_keyboard "https://github.com/too101/thaimsx/blob/main/src/keyboard.asm"
click node_keytables "https://github.com/too101/thaimsx/blob/main/src/kwtables_data.asm"
click node_thai_font "https://github.com/too101/thaimsx/blob/main/src/font_data.asm"
click node_screen "https://github.com/too101/thaimsx/blob/main/src/printon.asm"
click node_printer "https://github.com/too101/thaimsx/blob/main/src/printer.asm"
click node_commands "https://github.com/too101/thaimsx/blob/main/src/thaicmd.asm"
click node_statement_hooks "https://github.com/too101/thaimsx/blob/main/src/statement.asm"
click node_print_hooks "https://github.com/too101/thaimsx/blob/main/src/printon.asm"
click node_cas_builder "https://github.com/too101/thaimsx/blob/main/scripts/mkcas.py"
click node_wav_converter "https://github.com/too101/thaimsx/blob/main/scripts/cas2wav.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cartridge,node_initialization,node_bload,node_workram,node_cas_builder,node_wav_converter,node_user toneBlue
class node_keyboard,node_keytables toneAmber
class node_thai_font,node_screen,node_printer toneMint
class node_commands,node_statement_hooks,node_print_hooks toneRose
class node_machine,node_printer_device toneIndigo
```

## Components

### Startup and Loading

- [Cartridge ROM](https://github.com/too101/thaimsx/blob/main/src/main.asm): `src/main.asm`
- [Initialization](https://github.com/too101/thaimsx/blob/main/src/init.asm): `src/init.asm`
- [BLOAD Loader](https://github.com/too101/thaimsx/blob/main/src/loader_bload.asm): `src/loader_bload.asm`
- [Runtime RAM](https://github.com/too101/thaimsx/blob/main/src/workram.asm): `src/workram.asm`
- [CAS Builder](https://github.com/too101/thaimsx/blob/main/scripts/mkcas.py): `scripts/mkcas.py`
- [WAV Converter](https://github.com/too101/thaimsx/blob/main/scripts/cas2wav.py): `scripts/cas2wav.py`

### Thai Input

- [Thai Keyboard](https://github.com/too101/thaimsx/blob/main/src/keyboard.asm): `src/keyboard.asm`
- [Key Tables](https://github.com/too101/thaimsx/blob/main/src/kwtables_data.asm): `src/kwtables_data.asm`

### Thai Output

- [Thai Font](https://github.com/too101/thaimsx/blob/main/src/font_data.asm): `src/font_data.asm`
- [Text and Graphics](https://github.com/too101/thaimsx/blob/main/src/printon.asm): `src/printon.asm`
- [Thai Printing](https://github.com/too101/thaimsx/blob/main/src/printer.asm): `src/printer.asm`

### BASIC Extensions

- [BASIC Commands](https://github.com/too101/thaimsx/blob/main/src/thaicmd.asm): `src/thaicmd.asm`
- [BASIC Hooks](https://github.com/too101/thaimsx/blob/main/src/statement.asm): `src/statement.asm`
- [Print Hooks](https://github.com/too101/thaimsx/blob/main/src/printon.asm): `src/printon.asm`

### Other components

- **MSX User**
- **MSX BASIC / BIOS**
- **Printer**

## Connections

- MSX User → MSX BASIC / BIOS: uses BASIC
- MSX BASIC / BIOS → Cartridge ROM: starts ROM
- Cartridge ROM → Initialization: initializes
- MSX BASIC / BIOS → BLOAD Loader: loads program
- BLOAD Loader → Runtime RAM: loads into
- Initialization → Thai Keyboard: enables input
- Thai Keyboard → Key Tables: uses mappings
- Initialization → Text and Graphics: enables display
- Text and Graphics → Thai Font: uses glyphs
- MSX BASIC / BIOS → BASIC Hooks: dispatches BASIC
- BASIC Hooks → BASIC Commands: handles commands
- MSX BASIC / BIOS → Print Hooks: prints BASIC
- Print Hooks → Text and Graphics: renders text
- Print Hooks → Thai Printing: routes LPRINT
- Thai Printing → Printer: prints output
- MSX User → CAS Builder: converts BLOAD
- CAS Builder → WAV Converter: converts CAS
