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
+148
-16
@@ -23,7 +23,8 @@ READY
|
||||
|
||||
The Z-80 keeps running while SW15 is down. It just waits until it can print
|
||||
again, so you can flip back and forth without losing your program. **BTND**
|
||||
restarts the Z-80; that wipes the program. **BTNC** restarts the whole board.
|
||||
(or **Ctrl-Alt-Del** on the keyboard) restarts the Z-80; that wipes the program
|
||||
but not the files in flash. **BTNC** restarts the whole board.
|
||||
|
||||
### Talking to BASIC
|
||||
|
||||
@@ -66,7 +67,7 @@ case, except inside quotes.
|
||||
| `LIST 100` | List line 100 |
|
||||
| `LIST 100-200` | List lines 100 to 200 (`LIST -200` and `LIST 100-` work too) |
|
||||
| `NEW` or `SCRATCH` | Erase the program and all variables |
|
||||
| `SAVE "NAME"` | Keep the program in the board's flash (section 10) |
|
||||
| `SAVE "NAME"` | Keep the program in the board's flash (section 11) |
|
||||
| `LOAD "NAME"` | Bring a saved program back |
|
||||
| `RUN "NAME"` | Load a saved program and run it |
|
||||
| `DIR` / `DEL "NAME"` | List the saved programs / delete one |
|
||||
@@ -205,7 +206,7 @@ gives `?REDO` and asks again. Ctrl-C stops the program.
|
||||
`LINE INPUT A$` (or `LINE INPUT "PROMPT"; A$`) takes the whole line into one
|
||||
string, commas and quotes included, and prints no `? `.
|
||||
|
||||
`PRINT #`, `INPUT #` and `LINE INPUT #` do the same with a file (section 10).
|
||||
`PRINT #`, `INPUT #` and `LINE INPUT #` do the same with a file (section 11).
|
||||
|
||||
### IF … THEN — decisions
|
||||
|
||||
@@ -299,14 +300,18 @@ again from the first item.
|
||||
different numbers. Without it, `RND` produces the same sequence every time the
|
||||
Z-80 is reset.
|
||||
|
||||
### POKE and OUT
|
||||
### POKE, OUT, CALL and MONITOR
|
||||
|
||||
```
|
||||
POKE address, value
|
||||
OUT port, value
|
||||
CALL address
|
||||
MONITOR
|
||||
```
|
||||
|
||||
See section 9.
|
||||
`CALL` runs machine code at *address* as a subroutine: it must end with `RET`
|
||||
and leave `IX` and `SP` as it found them. `MONITOR` stops BASIC in the
|
||||
machine-code monitor (section 10). See section 9 for memory and ports.
|
||||
|
||||
### Graphics and text placement
|
||||
|
||||
@@ -350,8 +355,8 @@ A whole number from 1 to 6: `1 + INT(RND * 6)`.
|
||||
| Function | Result |
|
||||
|---|---|
|
||||
| `TIM` | Seconds since the Z-80 was reset, to the millisecond |
|
||||
| `DATE$` | The date and time as `"2026-11-28 09:30:15"`, or `""` if not set (section 10) |
|
||||
| `EOF(N)` | -1 (true) when file *N* has been read to the end, else 0 (section 10) |
|
||||
| `DATE$` | The date and time as `"2026-11-28 09:30:15"`, or `""` if not set (section 11) |
|
||||
| `EOF(N)` | -1 (true) when file *N* has been read to the end, else 0 (section 11) |
|
||||
| `POINT(X, Y)` | Colour of the graphics pixel at *X, Y* (0 off screen) |
|
||||
| `PEEK(A)` | Byte at memory address *A* |
|
||||
| `INP(P)` | Byte from I/O port *P* |
|
||||
@@ -472,11 +477,14 @@ stays where it is.
|
||||
| Addresses | Contents |
|
||||
|---|---|
|
||||
| 0000–7FFF | BASIC itself (writes here are ignored) |
|
||||
| 8000–F3FF | BASIC's variables, your program and arrays, file buffers |
|
||||
| 8000–EFFF | BASIC's variables, your program and arrays, file buffers |
|
||||
| F000–F3F7 | Free for your machine code (1016 bytes); BASIC never uses it |
|
||||
| F3F8–F3FF | The clock set by `DATE` |
|
||||
| F400–FFFF | The Z-80 stack |
|
||||
|
||||
`PEEK` can read anything; `POKE` can change anything from 8000 up, including
|
||||
BASIC's own data. Poke with care.
|
||||
BASIC's own data, so put machine code at **F000h (61440) to F3F7h**, which is
|
||||
kept free for it.
|
||||
|
||||
### I/O ports
|
||||
|
||||
@@ -492,6 +500,9 @@ BASIC's own data. Poke with care.
|
||||
| 52 | bit 0: screen fill in progress | fill the whole graphics layer with a colour |
|
||||
| 64 | bit 0: flash byte in progress; bit 1: last flash command refused | 1 selects the flash and starts a command, 0 ends it |
|
||||
| 65 | the byte the flash sent back during the last `OUT 65` | a byte to the flash |
|
||||
| 96 | why the monitor was entered (used by the monitor) | monitor bank and single step (used by the monitor) |
|
||||
| 97 | — | enter the monitor (what `MONITOR` does) |
|
||||
| 98–105 | memory read and breakpoint registers (used by the monitor) | |
|
||||
|
||||
```
|
||||
10 FOR I = 0 TO 255
|
||||
@@ -524,7 +535,107 @@ Constants in a program are converted from text every time they are used, so a
|
||||
loop runs a little faster if a constant used inside it is put into a variable
|
||||
first.
|
||||
|
||||
## 10. Files in the flash
|
||||
## 10. The machine-code monitor
|
||||
|
||||
The monitor stops the Z-80 wherever it is and shows what it is doing: the
|
||||
registers, the instructions at the program counter, the stack and a window of
|
||||
memory. From there you can step through the program one instruction at a time,
|
||||
set a breakpoint, change memory and registers, and carry on. It works on any
|
||||
code, including BASIC itself.
|
||||
|
||||
### Getting in and out
|
||||
|
||||
- Press **Pause/Break** on the keyboard at any time, even when a program has
|
||||
hung, or type `MONITOR` in BASIC.
|
||||
- A breakpoint or a single step also comes back to the monitor.
|
||||
- `X` (or `G`) carries on from where the program stopped.
|
||||
|
||||
The monitor has a screen of its own: when you leave, BASIC's screen and the
|
||||
graphics come back exactly as they were.
|
||||
|
||||
```
|
||||
Z-80 MONITOR STOPPED BY BREAKPOINT
|
||||
PC F000 SP FF9F AF 0042 BC 0000 DE 8000 HL 8000 IX FFF2 IY FF95
|
||||
AF'0000 BC'0000 DE'0000 HL'0000 I 00 FLAGS -Z----N-
|
||||
ADDR BYTES INSTRUCTION
|
||||
>*F000 3E 41 LD A,41H STACK
|
||||
F002 D3 01 OUT (01H),A FF9F 5755
|
||||
F004 C9 RET FFA1 0000
|
||||
...
|
||||
MEMORY
|
||||
F000 3E 41 D3 01 C9 00 00 00-00 00 00 00 00 00 00 00 >A..............
|
||||
```
|
||||
|
||||
- `>` marks the next instruction, which is also highlighted, and `*` the
|
||||
breakpoint.
|
||||
- The flags line shows S Z 5 H 3 P/V N C, with a dash for each flag that is
|
||||
clear.
|
||||
- The stack column shows the words at SP upwards.
|
||||
|
||||
### Commands
|
||||
|
||||
Type a command on the bottom line and press Enter. Numbers are in hex.
|
||||
|
||||
| Command | Does |
|
||||
|---|---|
|
||||
| Enter (empty line) or `S` | Run one instruction |
|
||||
| `S n` | Run *n* instructions, showing only the last |
|
||||
| `O` | Step over: run a `CALL` or `RST` until it returns, otherwise one step |
|
||||
| `G` or `X` | Carry on (stopping at the breakpoint, if set) |
|
||||
| `G addr` | Carry on from *addr* |
|
||||
| `B addr` | Set the breakpoint; `B` alone clears it |
|
||||
| `D addr` | Show the disassembly from *addr* (`D` alone: from PC) |
|
||||
| `M addr` | Show memory from *addr* |
|
||||
| `E addr bytes…` | Write bytes into memory: `E 8000 3E 41 C9` |
|
||||
| `R reg=value` | Set PC, SP, AF, BC, DE, HL, IX or IY: `R HL=1234` |
|
||||
| `SAVE "NAME" start end` | Save memory *start* to *end* (inclusive) to a file in flash |
|
||||
| `LOAD "NAME"` | Load a memory file back to where it was saved from |
|
||||
| `LOAD "NAME" addr` | Load it at *addr* instead (8000h or above) |
|
||||
| `DIR` | List the files in flash in the memory window (`M` brings the memory back) |
|
||||
| Up / Down | Scroll the disassembly by one instruction |
|
||||
| Page Up / Page Down | Scroll the memory window |
|
||||
| `?` | A short reminder of the commands |
|
||||
|
||||
- **Stepping** runs exactly one instruction (a whole `LDIR`, or a `HALT` and
|
||||
what wakes it). The hardware counts instructions, so it works on code in ROM
|
||||
as well as RAM.
|
||||
- **The breakpoint** is checked by hardware before each instruction, so it also
|
||||
works in ROM and costs no speed. When you carry on from the breakpoint
|
||||
itself, the monitor first steps past it.
|
||||
- **Memory below 8000h** is BASIC's ROM and can be viewed but not changed. `E`
|
||||
says so if you try.
|
||||
- **The disassembler** shows every instruction, including the undocumented
|
||||
ones (`IXH`, `SLL`, `IN (C)`, `RES 0,(IX+5),B` and so on), in Zilog syntax
|
||||
with hex numbers like `3EH` and `0C000H`.
|
||||
|
||||
### A machine-code example
|
||||
|
||||
```
|
||||
POKE 61440,62: POKE 61441,65: POKE 61442,211: POKE 61443,1: POKE 61444,201
|
||||
MONITOR
|
||||
```
|
||||
|
||||
The `POKE`s put `LD A,41H : OUT (1),A : RET` at F000h; it prints an `A`. In
|
||||
the monitor, `B F000` then `X`. Back in BASIC, `CALL 61440` stops at the
|
||||
breakpoint. Press Enter to step through each instruction, or `X` to let it
|
||||
finish.
|
||||
|
||||
### How it works
|
||||
|
||||
Pause, `MONITOR`, a breakpoint or the step counter raises the Z-80's
|
||||
non-maskable interrupt (NMI).
|
||||
1. **Entry:** the NMI pushes the program counter and jumps to 0066h. A few
|
||||
bytes there switch in the monitor's own 32 KB memory bank, which replaces
|
||||
0000–7FFF.
|
||||
2. **Reading memory:** the monitor reads the program's memory below 8000h
|
||||
through a debug port.
|
||||
3. **Leaving:** the monitor switches the bank out and returns. To single-step,
|
||||
it also tells the hardware to raise the NMI again after one instruction.
|
||||
|
||||
The monitor takes no memory from BASIC; its bank also has room for an
|
||||
assembler.
|
||||
|
||||
## 11. Files in the flash
|
||||
|
||||
The board's configuration flash has room for files next to the bitstream it
|
||||
boots from: saved programs, and data files that programs write and read. They
|
||||
@@ -575,13 +686,34 @@ restarted (**BTND**, **BTNC**, power-off or reprogramming).
|
||||
| `DATE$` | The date and time as a string, `""` if not set |
|
||||
|
||||
`send-bas.py` and `get-bas.py` set it from the PC's clock each time they
|
||||
connect (section 11; `--no-date` stops them). A file saved before the date is set has no date in
|
||||
connect (section 12; `--no-date` stops them). A file saved before the date is set has no date in
|
||||
`DIR`, and gets one when it is next saved after the date is set.
|
||||
|
||||
```
|
||||
PRINT "TODAY IS "; LEFT$(DATE$, 10)
|
||||
```
|
||||
|
||||
### Memory files
|
||||
|
||||
A memory file holds a block of memory, for machine code or data: its address
|
||||
(2 bytes) followed by the bytes, the same format as a C64 program file. The
|
||||
monitor's `SAVE`/`LOAD` (section 10) and BASIC's statements below read and write
|
||||
the same files.
|
||||
|
||||
| Statement | Does |
|
||||
|---|---|
|
||||
| `BSAVE "NAME", start, length` | Save *length* bytes from *start* |
|
||||
| `BLOAD "NAME"` | Load them back to the address they came from |
|
||||
| `BLOAD "NAME", address` | Load them at *address* instead |
|
||||
|
||||
```
|
||||
BSAVE "CODE", 61440, 5
|
||||
BLOAD "CODE", 61952: CALL 61952
|
||||
```
|
||||
|
||||
Only memory from 8000h up can be loaded into. A memory file is up to 32 KB.
|
||||
Don't `LOAD` one as a program: it isn't text.
|
||||
|
||||
### Data files
|
||||
|
||||
A program can write text to a file and read it back, with up to three files
|
||||
@@ -631,7 +763,7 @@ to erase or write anything below the area kept for programs, so no program can
|
||||
stop the board from starting, even one that sends commands to the flash itself
|
||||
with `OUT` (ports 64 and 65, section 9).
|
||||
|
||||
## 11. Programs on the PC
|
||||
## 12. Programs on the PC
|
||||
|
||||
Programs can also be kept as plain text files on the PC, one numbered line per
|
||||
line. SW14 links the PC's serial port to the Z-80: what the PC sends is typed
|
||||
@@ -700,7 +832,7 @@ into the board:
|
||||
|
||||
Pasting into a terminal program such as `picocom` works too.
|
||||
|
||||
## 12. Error messages
|
||||
## 13. Error messages
|
||||
|
||||
An error stops the program and reports the line, for example
|
||||
`?DIVISION BY ZERO IN 120`.
|
||||
@@ -733,7 +865,7 @@ An error stops the program and reports the line, for example
|
||||
| `BREAK IN n` | You pressed Ctrl-C |
|
||||
| `STOP IN n` | The program ran `STOP` |
|
||||
|
||||
## 13. Example programs
|
||||
## 14. Example programs
|
||||
|
||||
### Times table
|
||||
|
||||
@@ -777,11 +909,11 @@ An error stops the program and reports the line, for example
|
||||
bars, circles, a burst of lines, sine and cosine curves, random rectangles, a
|
||||
bouncing ball and a Mandelbrot set, then prints how long it all took.
|
||||
|
||||
## 14. Limits at a glance
|
||||
## 15. Limits at a glance
|
||||
|
||||
| Item | Limit |
|
||||
|---|---|
|
||||
| Program and arrays together | about 21.5 KB |
|
||||
| Program and arrays together | about 20.5 KB |
|
||||
| Line numbers | 0 – 65535 |
|
||||
| Line length | 250 characters typed |
|
||||
| Numeric variables | A–Z and A0–Z9 |
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user