velxio/scripts/killbits-rom.s

40 lines
1.5 KiB
ArmAsm
Raw Normal View History

feat(chips): programmable retro CPU chips with external ROM Adds a new way to use the retro CPU chips: write your program in a project file (.s / .asm / .hex / .bin), click Compile, click Run, and the same chip emulates whatever you wrote. Same chip + different ROMs = mini PC, calculator, LED demo, Kill-the-Bit game, etc. SDK: - velxio-chip.h gets two new host imports: uint32_t vx_rom_size(void); void vx_rom_read(uint32_t off, uint8_t* dst, uint32_t len); CPU-emulator chips call these in chip_setup to pull their program out of the host's romBytes property. Frontend runtime: - ChipRuntime accepts opts.romBytes (Uint8Array) and exposes the new imports, copying bytes into chip memory on vx_rom_read. - CustomChipPart pulls component.properties.romBytes (base64) and passes it through. - Component registry declares three new custom-chip properties: romBytes (base64), programFile (matching project filename), and programTarget (cpu name). New programmable bundled chip: - frontend/src/components/customChips/examples/intel/i8080-cpu.{c,chip.json} Same clean-room 8080 emulator as i8080-repl/i8080-counter, but ROM is loaded externally via vx_rom_*. Has 8 LEDs, 8 buttons, UART, 16 KB RAM, 32 KB of external ROM. Backend: - New /api/compile-rom endpoint and rom_compile service that turns chip-program source into ROM bytes. 8080 ASM is assembled by the in-tree two-pass assembler (moved to backend/app/services/asm8080.py). Intel HEX records are parsed; raw .bin is passed through. Future targets (z80, 8086, 4004) are scaffolded but not wired yet. EditorToolbar: - Compile button detects when the active file is .s/.asm/.hex/.bin and routes to compile-rom instead of arduino-cli. The compiled bytes are injected into every custom-chip on the canvas whose programFile property matches the active filename (or is empty). Example: - /examples/i8080-killbits loads Dean McDaniel's 1975 Kill-the-Bit on the programmable i8080-cpu chip. killbits.s is shipped as a project file alongside sketch.ino; the user clicks Compile then Run and the LED walks across 8 outputs, buttons kill it. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-19 09:38:18 +07:00
; Kill the Bit -- Dean McDaniel, May 15, 1975. Public domain.
;
; The classic Altair 8800 front-panel reflex game. Adapted to Velxio's
; i8080-cpu chip: instead of the Altair's address LEDs + sense switches,
; we use the chip's memory-mapped LED port (0xC000) and button bitmap
; (0xC003).
;
; How to play: a single LED walks left across the 8 LEDs. Press the
; button at the SAME bit position as the lit LED to "kill" it. Miss,
; and an extra bit lights up next time around.
;
; Logic per beat:
; 1. Wait some cycles (DAD B + JNC beat).
; 2. Show the current bit pattern (register D) on the LEDs.
; 3. Read which buttons the user is pressing.
; 4. XOR with D -- bits the user pressed at the right time get cleared.
; 5. Rotate right -- advances the bit one position.
ORG 0x0000
LXI SP, 0xBFFF ; stack at top of RAM (we don't push, but safe)
LXI H, 0x0000 ; clear delay accumulator
MVI D, 0x80 ; D = current bit pattern (start: LED7 lit)
LXI B, 0x0E00 ; B/C = delay step
beat:
DAD B ; HL += BC; loops ~18 times before carry
JNC beat
; One "tick" -- show D on LEDs, sample button, advance bit.
MOV A, D
STA 0xC000 ; LEDs <- D
LDA 0xC003 ; A = button bitmap
XRA D ; bits the user got right are toggled OFF
RRC ; rotate right (bit0 -> bit7)
MOV D, A
JMP beat