Machine-code monitor, fast serial, memory files, Ctrl-Alt-Del
Monitor: the CPU gets an NMI (taken at an instruction start, or from HALT) raised by the Pause key, BASIC's MONITOR, two hardware breakpoint comparators or a step counter. It enters through a trampoline at 0066h (the same bytes in BASIC's ROM and the monitor's, basic/tramp.s) that switches in a 32 KB monitor bank over 0000-7FFF. The monitor (monitor/, C) runs on the terminal's new alternate screen (CSI ?47 h/l, a second screen page; graphics hidden) and shows registers, flags, a disassembly from PC, the stack and memory. Commands: Enter/S n step, O step over, G/X go, B breakpoint, D/M windows, E edit, R registers, and SAVE/LOAD/ DIR for memory files. The disassembler covers every opcode; monitor/test-disasm.py round-trips all forms through sdasz80. Lockstep CPU tests still match the reference emulator. BASIC: MONITOR, CALL addr, BSAVE "N",start,len and BLOAD "N"[,addr] (memory files: load address then bytes). The DATE clock moves to F3F8h so the monitor can date files. F000-F3F7 is kept free for machine code (program area 21076 bytes). Serial: SW1:0 = 10 is now 921600 and 11 is 3 Mbaud. A 17 KB burst to BASIC lists back identical at both on the board. send-bas.py reads the echo while sending; unread, it could stall the PC's flow control. Ctrl-Alt-Del in Z-80 mode restarts the Z-80 like BTND. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
767377f38d
commit
634e314010
27 files changed
+37481
-3039
No files matched your search
@@ -61,11 +61,30 @@ echo 'ACTION=="add", SUBSYSTEM=="tty", ENV{ID_SERIAL_SHORT}=="210183BB7B5B", ENV
|
||||
|
||||
Set SW6 up so Backspace sends DEL, which the `basys3` entry expects.
|
||||
|
||||
### Speed
|
||||
|
||||
SW1:0 sets the serial speed: `00` 115200, `01` 9600, `10` 921600, `11` 3
|
||||
Mbaud. The terminal paces the PC with XON/XOFF (Linux honours it by default),
|
||||
so the PC can send at full speed. Tested on the board: a 17 KB, 300-line
|
||||
program sent to BASIC in one burst at 921600 and at 3 Mbaud listed back
|
||||
identical.
|
||||
|
||||
For the fastest terminal:
|
||||
- **SW8 down.** Smooth scrolling deliberately holds output to 7.5 lines a
|
||||
second (15 with SW9). A program can also turn it on with `ESC[?4h`;
|
||||
`printf '\033[?4l'` turns it off.
|
||||
- **The PC at the same speed**, for example the getty override above with
|
||||
`3000000` in place of `115200`, or `picocom -b 3000000 /dev/ttyUSB1`.
|
||||
- **Programs that write to the port must also read from it.** If nothing
|
||||
reads, the PC's input buffer fills and Linux stops reading the port. It then
|
||||
never sees the terminal's XON and stops sending. `tools/send-bas.py` reads the
|
||||
echo as it sends for this reason.
|
||||
|
||||
## Controls
|
||||
|
||||
| Control | Function |
|
||||
|---|---|
|
||||
| SW1:0 | Baud: `00` 115200, `01` 9600, `10` 19200, `11` 57600 |
|
||||
| SW1:0 | Baud: `00` 115200, `01` 9600, `10` 921600, `11` 3000000 (see Speed below) |
|
||||
| SW2 | Local echo |
|
||||
| SW3 | Received LF also does CR (for hosts that send bare `\n`) |
|
||||
| SW5:4 | Default text colour: `00` green, `01` yellow, `10` white, `11` cyan |
|
||||
@@ -77,7 +96,8 @@ Set SW6 up so Backspace sends DEL, which the `basys3` entry expects.
|
||||
| SW15 | Z-80 mode: the terminal is the Z-80's console |
|
||||
| BTNC | Reset (clears screen, shows banner, restarts the Z-80) |
|
||||
| BTNU | Clear screen |
|
||||
| BTND | Reset the Z-80 only |
|
||||
| BTND | Reset the Z-80 only (or Ctrl-Alt-Del on the keyboard, in Z-80 mode) |
|
||||
| Pause key | Z-80 mode: stop the Z-80 in the machine-code monitor |
|
||||
| LED7:0 | Last byte received |
|
||||
| LED11:8 | VT220 keyboard LEDs L4..L1 (`ESC[n q`) |
|
||||
| LED12 / 13 / 14 / 15 | Bell / Caps Lock / UART RX activity / keyboard activity |
|
||||
@@ -109,7 +129,8 @@ Set SW6 up so Backspace sends DEL, which the `basys3` entry expects.
|
||||
background. 256-colour (`38;5;n`) and RGB (`38;2;r;g;b`) codes are
|
||||
approximated to the 16 colours.
|
||||
- **Modes**: `DECCKM` (cursor keys), `DECKPAM`/`DECKPNM` (keypad), `LNM`,
|
||||
`DECTCEM` (cursor on/off), `DECSCLM` (smooth scroll).
|
||||
`DECTCEM` (cursor on/off), `DECSCLM` (smooth scroll), alternate screen
|
||||
(`CSI ?47 h`/`l`, a second page; graphics are hidden while it is shown).
|
||||
- **Replies to the host**:
|
||||
- `DA` gets `ESC[?62;22c` (a VT220 with colour)
|
||||
- Secondary `DA` gets `ESC[>1;10;0c`
|
||||
@@ -158,7 +179,8 @@ edit the line being typed.
|
||||
- **Commands**: `RUN [line]`, `LIST [a][-b]`, `NEW` (also `SCRATCH`).
|
||||
- **Files in flash**: `SAVE "NAME"`, `LOAD "NAME"`, `RUN "NAME"`, `DIR`,
|
||||
`DEL "NAME"`; data files with `OPEN "NAME" FOR INPUT|OUTPUT|APPEND AS #n`,
|
||||
`PRINT #n`, `INPUT #n`, `LINE INPUT #n`, `EOF(n)`, `CLOSE [#n]`.
|
||||
`PRINT #n`, `INPUT #n`, `LINE INPUT #n`, `EOF(n)`, `CLOSE [#n]`; memory
|
||||
blocks with `BSAVE "NAME",start,length` and `BLOAD "NAME"[,address]`.
|
||||
- **Date**: `DATE "2026-11-28 09:30"` sets the clock (the PC tools do it when
|
||||
they connect), `DATE$` reads it, and `DIR` shows when each file was made.
|
||||
- **Statements**:
|
||||
@@ -168,7 +190,8 @@ edit the line being typed.
|
||||
`ON expr GOTO|GOSUB list`, `FOR v = a TO b [STEP s]` / `NEXT [v]`, `END`,
|
||||
`STOP`
|
||||
- Data: `DIM`, `DEF FNx(v) = expr`, `READ`/`DATA`/`RESTORE`, `REM`
|
||||
- Machine access: `RANDOMIZE`, `POKE addr,v`, `OUT port,v`
|
||||
- Machine access: `RANDOMIZE`, `POKE addr,v`, `OUT port,v`, `CALL addr`,
|
||||
`MONITOR`
|
||||
- Graphics: `CLS`, `COLOR c`, `PLOT x,y[,c]`, `LINE`, `RECT`, `FILL`
|
||||
(`x1,y1,x2,y2[,c]`), `CIRCLE x,y,r[,c]`
|
||||
- Text placement: `LOCATE row,col`, `INK fg[,bg]`
|
||||
@@ -187,7 +210,7 @@ edit the line being typed.
|
||||
- Spaces are optional, as at Dartmouth: `FORI=1TO10` works.
|
||||
- `DATA` takes the rest of its line.
|
||||
|
||||
About 21.5 KB of program space is free.
|
||||
About 20.5 KB of program space is free; F000h-F3F7h is kept free for machine code.
|
||||
|
||||
**Graphics:** the layer is 320×240 pixels in the 16 terminal colours, each
|
||||
pixel a 2×2 block, with (0,0) at the top left. Colour 0 is transparent. Text is
|
||||
@@ -245,6 +268,48 @@ Z-80 waits when the copy to the PC falls behind.
|
||||
`basic/examples/graphics-demo.bas` shows off the graphics: colour bars,
|
||||
circles, lines, curves, random shapes, a bouncing ball and a Mandelbrot set.
|
||||
|
||||
### The machine-code monitor
|
||||
|
||||
The Pause key, BASIC's `MONITOR`, a breakpoint or a single step stops the
|
||||
Z-80 in a monitor in the style of the C64's cartridge monitors. It runs on the
|
||||
terminal's alternate screen, so BASIC's screen and graphics come back
|
||||
untouched, and shows:
|
||||
- the registers and flags;
|
||||
- a disassembly from PC, with the next instruction highlighted;
|
||||
- the stack and a memory window.
|
||||
|
||||
Commands: Enter steps one instruction, `S n` steps *n*, `O` steps over a call,
|
||||
`G`/`X` carries on, `B addr` sets the breakpoint, `D`/`M addr` move the windows,
|
||||
`E addr bytes` writes memory, `R HL=1234` sets a register, and
|
||||
`SAVE "NAME" start end`, `LOAD "NAME" [addr]` and `DIR` move memory to and
|
||||
from files in flash (the same files as BASIC's `BSAVE`/`BLOAD`). The manual's
|
||||
section 10 has the details.
|
||||
|
||||
How it works:
|
||||
- **Entry:** the NMI pushes PC and jumps to 0066h. Both BASIC's ROM and the
|
||||
monitor's have the same trampoline there (`basic/tramp.s`). It saves AF,
|
||||
switches in the monitor's 32 KB bank (`monitor/`, ROM 0000-6FFF and RAM
|
||||
7000-7FFF, replacing 0000-7FFF) and enters it.
|
||||
- **Reading memory:** the monitor reads the program's memory below 8000h
|
||||
through a debug port (62h-64h).
|
||||
- **Leaving:** through 0070h, which switches the bank out and does `POP AF`
|
||||
and `RETN`.
|
||||
- **Stepping:** the hardware counts instruction starts after the leaving
|
||||
write and raises the NMI as the program's next instruction begins, so
|
||||
exactly one instruction runs.
|
||||
- **Breakpoints:** two hardware comparators (the user's and a temporary one
|
||||
for step-over) watch each instruction's address. Both work in ROM.
|
||||
- **The disassembler:** it covers every opcode. `monitor/test-disasm.py`
|
||||
disassembles all 1,784 forms and assembles each back with `sdasz80`. The
|
||||
664 documented forms come back byte for byte. The 455 undocumented
|
||||
duplicates assemble to their documented equivalents. 665 undocumented forms
|
||||
can't be assembled by `sdasz80`.
|
||||
|
||||
```bash
|
||||
monitor/build.sh # -> monitor/monitor.mem, loaded by the bitstream build
|
||||
monitor/test-disasm.py # check the disassembler (needs gcc and sdasz80)
|
||||
```
|
||||
|
||||
### The Z-80
|
||||
|
||||
`rtl/z80_cpu.v` is a Z-80 written for speed rather than cycle accuracy:
|
||||
@@ -261,7 +326,9 @@ circles, lines, curves, random shapes, a bouncing ball and a Mandelbrot set.
|
||||
registers.
|
||||
- It has the documented instruction set plus the undocumented IXH/IXL/IYH/IYL
|
||||
forms, `SLL` and the DDCB register copies, with the undocumented X/Y flags.
|
||||
- There are no interrupts and HALT stops it until reset.
|
||||
- The only interrupt is a non-maskable one (NMI) for the monitor. It is
|
||||
taken at an instruction start, pushes the address of the next instruction
|
||||
and jumps to 0066h. It also wakes the CPU from HALT.
|
||||
|
||||
The 320×240×4-bit graphics layer is a separate dual-clock block RAM: the Z-80
|
||||
writes it on its own clock, and the video reads it on the 100 MHz clock.
|
||||
@@ -283,6 +350,10 @@ stack fill the top half.
|
||||
| 34h | bit 0: fill busy | fill the whole graphics layer with a colour |
|
||||
| 40h | bit 0: SPI byte busy, bit 1: command refused | 1 starts a flash command (chip select low), 0 ends it |
|
||||
| 41h | byte received during the last transfer | send a byte to the flash |
|
||||
| 60h | why the monitor was entered (1 Pause, 2 port 61h, 3 step, 4/5 breakpoint) | bit 0: monitor bank in; bit 1: stop after one instruction |
|
||||
| 61h | | enter the monitor (NMI) |
|
||||
| 62h, 63h, 64h | 64h: byte of main memory at the debug address, then address+1 | 62h/63h: debug address |
|
||||
| 65h/66h, 68h/69h, 67h | | breakpoint 0 and 1 addresses; 67h bits 1:0 turn them on |
|
||||
|
||||
BASIC is C (`basic/basic.c`) compiled with SDCC (`sudo apt install sdcc`):
|
||||
|
||||
@@ -353,6 +424,9 @@ older boards, Macronix `mx25l3273f` on newer ones).
|
||||
`sim/work/frame_2.png` (the second is taken mid-scroll).
|
||||
- It switches to Z-80 mode, types `PRINT 2+2` and a short program over the
|
||||
UART, and checks BASIC's output on the screen.
|
||||
- It enters the monitor with `MONITOR`, checks the screen, single-steps a
|
||||
`JP` onto its target and sets a breakpoint that BASIC then hits. It also
|
||||
enters through the Pause key and checks BASIC's screen comes back.
|
||||
- It draws graphics from BASIC and checks the pixels.
|
||||
- Against a model flash (`sim/spiflash_model.v`) it sets the date, saves,
|
||||
loads, runs and lists a program (checking the date in `DIR`), tries to erase
|
||||
@@ -372,8 +446,10 @@ which Vivado needs on newer distros.
|
||||
|---|---|
|
||||
| `rtl/basys3_terminal.v` | Top level: reset, switches, FIFOs, flow control, banner, LEDs, Z-80 clock |
|
||||
| `rtl/z80_cpu.v` | Z-80 CPU |
|
||||
| `rtl/z80_system.v` | Z-80 RAM, console, timer, graphics and flash ports |
|
||||
| `rtl/z80_system.v` | Z-80 RAM, console, timer, graphics and flash ports, monitor bank, step and breakpoints |
|
||||
| `rtl/flash_spi.v` | SPI port to the configuration flash, with bitstream write protection |
|
||||
| `monitor/` | Machine-code monitor (C and start-up code), its build script and disassembler test |
|
||||
| `basic/tramp.s` | The NMI entry and exit bytes shared by BASIC and the monitor |
|
||||
| `tools/send-bas.py`, `tools/get-bas.py` | Send a BASIC program to the board / copy one back, run commands |
|
||||
| `basic/` | BASIC interpreter (C), start-up code, build script, `basic.mem` |
|
||||
| `tools/z80emu.py`, `tools/cputest.py`, `scripts/cpusim.sh` | CPU test bench: reference emulator, random tests |
|
||||
|
||||
Reference in new issue
Block a user