卡西欧 FX-870P 模拟器
Casio FX-870P Emulator

原始链接: https://github.com/urbancamo/fx870p-emulator

该项目是一个基于 Web 的综合模拟器,用于模拟 1986 年推出的卡西欧 FX-870P (VX-4) 可编程袖珍计算机。它由 Mark Wickens 使用 TypeScript 和 Vue 3 开发,是对 Delphi 参考实现的完整移植,旨在让现代用户也能体验到复古计算器技术。 主要功能包括:对日立 HD61700 CPU 的精确模拟、可适应任何屏幕尺寸的响应式界面、完整的 PC 键盘映射,以及通过源私有文件系统 (OPFS) 对 MD-120 软盘驱动器的支持。该模拟器内置了强大的开发工具,如交互式 CPU 调试器、支持语法高亮的 BASIC 程序编辑器、RS-232C 串口通信以及 `DEFCHR$` 像素编辑器。 除了浏览器端,该项目代码库还提供了一些先进的 Node.js 工具,包括一个可将 Casio JIS BASIC 转换为原生 HD61700 机器码的编译器,以及用于自动化测试和指令追踪的无头 CLI 调试器。该项目专为普通用户和开发人员设计,为探索经典卡西欧硬件的架构和编程环境提供了一种高完成度且功能丰富的体验。

```Hacker News 最新 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 Casio FX-870P 模拟器 (github.com/urbancamo) 5 点,由 austinallegro 发布于 1 小时前 | 隐藏 | 过往 | 收藏 | 讨论 | 帮助 考虑申请 YC 2026 年秋季批次!申请截止日期为 7 月 27 日。 指南 | 常见问题解答 | 列表 | API | 安全 | 法律 | 申请 YC | 联系方式 搜索: ```
相关文章

原文

A browser-based emulator for the Casio FX-870P (also sold as the VX-4) pocket computer, written in TypeScript and Vue 3.

The FX-870P was a 1986 programmable calculator running a Hitachi HD61700 CPU at 921 kHz with a 96×64 pixel LCD, 83-key keyboard, serial port, and optional MD-120 floppy drive. This emulator is a full port of the original Delphi reference implementation to the web platform.

screenshot.png

The original emulator is available on the PISI and credit is given to the original author of the amazing suite of emulators available on this site. This implementation is designed to purely make the code behind that emulator available to a wider audience on the internet.

This version of the emulator implemented by Mark Wickens, the source code is hosted on GitHub here and it is hosted if here you want to try it.

Component Details
CPU Hitachi HD61700, 921 kHz
Memory 18-bit address space: ROM0 (6 KB, 16-bit words), ROM1 (128 KB × 2 banks), RAM (64 KB)
Display HD44352A01 LCD controller — 96×64 pixels + 5 status indicators
Keyboard 83-key matrix (9 blocks, 16 KO columns)
Serial UART with XON/XOFF flow control
Storage MD-120 floppy disk via Origin Private File System (OPFS)
  • Responsive calculator face — scales to fit any screen size with multiple resolution faceplate images
  • Full keyboard mapping — type directly on your PC keyboard with automatic CAPS and shifted-symbol handling
  • Program library — built-in curated collection of sample BASIC programs loadable directly from the toolbar
  • RS-232C serial — LOAD and SAVE BASIC programs via emulated COM0 with XON/XOFF flow control
  • Floppy disk — MD-120 disk emulation via Origin Private File System (OPFS)
  • Character set table — interactive 16x16 hex grid showing all 256 character bitmaps from the ROM font
  • DEFCHR$ pixel editor — click any character to open a drag-to-paint 5x8 pixel editor that generates the BASIC DEFCHR$ command with a one-click copy button
  • Turbo mode — run the CPU at ~50x speed for compute-heavy BASIC programs
  • Fullscreen mode — hide toolbar and panels to use the calculator full-screen (useful on mobile)
  • Firmware toggle — switch between FX-870P (Japanese) and VX-4 (English) ROM modes
  • CPU debugger — live registers, flags, and disassembly view
  • BASIC listing panel — live detokenized listing of all BASIC programs (P0–P9) stored in RAM, with tabbed navigation, syntax highlighting, and live/frozen toggle
  • BASIC editor — in-place editing of BASIC programs with syntax highlighting, direct RAM writes, add/delete/edit lines, whole-program import/export with rich-text clipboard support
  • Communications panel — UART register state, serial byte stream, and diagnostics
  • Node.js 22 LTS
  • ROM files placed in public/roms/ (not included)
npm install
./start.sh        # starts on http://localhost:3007/fx870p-emulator/
./stop.sh         # stops the server

Or use npm directly:

npm run dev       # foreground, Ctrl-C to stop
npm run build     # output in dist/
npm run preview   # preview the built app

The app is served under the /fx870p-emulator/ base path in both dev and production.

src/
  emulator/
    cpu.ts            HD61700 CPU core — reset, fetch/decode/execute loop
    exec.ts           Instruction handlers (~2100 lines)
    decoder.ts        256-entry instruction dispatch table
    def.ts            CPU state, memory map, srcRead/dstWrite
    disassemble.ts    Runtime disassembler (used by DebugPanel)
    lcd.ts            HD44352A01 LCD controller → Canvas ImageData
    keyboard.ts       83-key matrix — keydown + mouse events
    port.ts           I/O ports and UART state machine
    comm.ts           RS-232C TX/RX queue, XON/XOFF, SAVE receive
    basic-tokens.ts   Shared keyword tables (PREFIX4–7) and RAM layout constants
    detokenize.ts     BASIC program detokenizer — reads tokenized programs from RAM
    tokenize.ts       BASIC tokenizer — converts source text to FX-870P token bytes
    ram-edit.ts       RAM editor — writes tokenized programs to RAM with file table management
    casio-ascii.ts    Casio ASCII ↔ Unicode character mapping
    emulator.ts       Main rAF loop, ROM loading, state persistence
    remote-log.ts     Debug logging (dev only)
    trace.ts          Per-instruction JSONL trace recorder
  components/
    EmulatorView.vue    Top-level orchestrator + panel layout
    LcdCanvas.vue       Canvas LCD renderer
    KeyboardOverlay.vue Clickable key hit regions over face images
    CommPanel.vue       Serial comms panel + toolbar buttons
    DebugPanel.vue      CPU debugger (registers, flags, disassembly)
    BasicListPanel.vue  BASIC program listing/editor panel (detokenized view, in-place editing, import/export)
    CharsetPopup.vue    Character set table + DEFCHR$ pixel editor
    LibraryPopup.vue    Program library popup (browse + load sample programs)
    AboutPopup.vue      About dialog (renders ABOUT.md)
  editor/
    BasicEditor.vue     Reusable CodeMirror 6 editor component (single/multi-line modes)
    cm-basic-lang.ts    CodeMirror StreamLanguage definition for FX-870P BASIC
    cm-basic-theme.ts   CodeMirror dark theme matching the panel UI
    basic-highlight.ts  Syntax highlighter for listing display and rich-text clipboard export
public/
  ABOUT.md            User-facing documentation (rendered in About popup)
  basic/              Sample BASIC programs (.bas)
  images/
    face.png          Calculator faceplate (standard)
    face-large.png    Calculator faceplate (large)
    face-huge.png     Calculator faceplate (huge)
    keys.png          Key overlay reference
    casio-logo.svg    Casio logo (used as About popup watermark)
  roms/               ROM and charset binaries (not in repo)
tests/
  emu-harness.ts      Headless emulator boot + keystroke helpers
  sin90.test.ts       SIN(90) regression test
  tokenize.test.ts    BASIC tokenizer tests (keywords, round-trip, edge cases)
tools/
  dis.ts              Standalone disassembler (npm run dis)
  compare-traces.mjs  Delphi vs TypeScript trace comparison
  charset-dump.ts     Generate character set markdown (docs/charset.md)
  charset-table.ts    Generate character set HTML table (docs/charset-table.html)
  compiler/           Casio JIS BASIC → HD61700 machine code compiler (README inside)
  emu-debugger/       Headless debugger library + CLI (README inside)
reference/            Documentation and Delphi source
docs/                 Implementation notes

Beyond the browser emulator, this repo ships two Node.js tools for compiling and debugging HD61700 machine code:

Compiles Casio JIS Standard BASIC to HD61700 machine code. Generates an annotated 132-column assembly listing, a raw binary, a symbol table, and a self-loading BASIC program for real hardware. Generated code calls into the existing ROM for PRINT, INPUT, FP math, and string operations (the CosmicV4 pattern) rather than reimplementing the runtime.

npx tsx tools/compiler/compile.ts program.bas
# → build/compiler/program.{bin,lst,sym,loader.bas}

Library and CLI for driving the emulator programmatically. Breakpoints, memory watchpoints, instruction tracing, snapshot restore, single-stepping. Designed for debugging compiled binaries and automated regression testing.

npm run debug -- run <binary.bin>     # run + show LCD
npm run debug -- trace <binary.bin>   # log every instruction
npm run debug -- step <binary.bin>    # interactive single-step

The emulator has a headless test suite powered by vitest that boots the emulator in Node.js, injects keystrokes, runs the CPU, and verifies LCD output.

npx vitest run tests/sin90.test.ts

Run tests matching a name pattern

Watch mode (re-runs on file changes)

Tests require ROM files in public/roms/ (same as the dev server).

The dev server exposes a /fx870p-emulator/log endpoint that writes to emulator-debug.log. Enable logging from the browser console:

window.ioDebug(true)   // enable
window.ioDebug(false)  // disable
联系我们 contact @ memedata.com