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
@@ -7,3 +7,4 @@ build/
|
|||||||
basic/out/
|
basic/out/
|
||||||
sim/cpu/
|
sim/cpu/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
monitor/out/
|
||||||
@@ -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.
|
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
|
## Controls
|
||||||
|
|
||||||
| Control | Function |
|
| 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 |
|
| SW2 | Local echo |
|
||||||
| SW3 | Received LF also does CR (for hosts that send bare `\n`) |
|
| 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 |
|
| 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 |
|
| SW15 | Z-80 mode: the terminal is the Z-80's console |
|
||||||
| BTNC | Reset (clears screen, shows banner, restarts the Z-80) |
|
| BTNC | Reset (clears screen, shows banner, restarts the Z-80) |
|
||||||
| BTNU | Clear screen |
|
| 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 |
|
| LED7:0 | Last byte received |
|
||||||
| LED11:8 | VT220 keyboard LEDs L4..L1 (`ESC[n q`) |
|
| LED11:8 | VT220 keyboard LEDs L4..L1 (`ESC[n q`) |
|
||||||
| LED12 / 13 / 14 / 15 | Bell / Caps Lock / UART RX activity / keyboard activity |
|
| 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
|
background. 256-colour (`38;5;n`) and RGB (`38;2;r;g;b`) codes are
|
||||||
approximated to the 16 colours.
|
approximated to the 16 colours.
|
||||||
- **Modes**: `DECCKM` (cursor keys), `DECKPAM`/`DECKPNM` (keypad), `LNM`,
|
- **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**:
|
- **Replies to the host**:
|
||||||
- `DA` gets `ESC[?62;22c` (a VT220 with colour)
|
- `DA` gets `ESC[?62;22c` (a VT220 with colour)
|
||||||
- Secondary `DA` gets `ESC[>1;10;0c`
|
- 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`).
|
- **Commands**: `RUN [line]`, `LIST [a][-b]`, `NEW` (also `SCRATCH`).
|
||||||
- **Files in flash**: `SAVE "NAME"`, `LOAD "NAME"`, `RUN "NAME"`, `DIR`,
|
- **Files in flash**: `SAVE "NAME"`, `LOAD "NAME"`, `RUN "NAME"`, `DIR`,
|
||||||
`DEL "NAME"`; data files with `OPEN "NAME" FOR INPUT|OUTPUT|APPEND AS #n`,
|
`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
|
- **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.
|
they connect), `DATE$` reads it, and `DIR` shows when each file was made.
|
||||||
- **Statements**:
|
- **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`,
|
`ON expr GOTO|GOSUB list`, `FOR v = a TO b [STEP s]` / `NEXT [v]`, `END`,
|
||||||
`STOP`
|
`STOP`
|
||||||
- Data: `DIM`, `DEF FNx(v) = expr`, `READ`/`DATA`/`RESTORE`, `REM`
|
- 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`
|
- Graphics: `CLS`, `COLOR c`, `PLOT x,y[,c]`, `LINE`, `RECT`, `FILL`
|
||||||
(`x1,y1,x2,y2[,c]`), `CIRCLE x,y,r[,c]`
|
(`x1,y1,x2,y2[,c]`), `CIRCLE x,y,r[,c]`
|
||||||
- Text placement: `LOCATE row,col`, `INK fg[,bg]`
|
- 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.
|
- Spaces are optional, as at Dartmouth: `FORI=1TO10` works.
|
||||||
- `DATA` takes the rest of its line.
|
- `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
|
**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
|
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,
|
`basic/examples/graphics-demo.bas` shows off the graphics: colour bars,
|
||||||
circles, lines, curves, random shapes, a bouncing ball and a Mandelbrot set.
|
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
|
### The Z-80
|
||||||
|
|
||||||
`rtl/z80_cpu.v` is a Z-80 written for speed rather than cycle accuracy:
|
`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.
|
registers.
|
||||||
- It has the documented instruction set plus the undocumented IXH/IXL/IYH/IYL
|
- 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.
|
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
|
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.
|
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 |
|
| 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 |
|
| 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 |
|
| 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`):
|
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).
|
`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
|
- 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.
|
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.
|
- It draws graphics from BASIC and checks the pixels.
|
||||||
- Against a model flash (`sim/spiflash_model.v`) it sets the date, saves,
|
- 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
|
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/basys3_terminal.v` | Top level: reset, switches, FIFOs, flow control, banner, LEDs, Z-80 clock |
|
||||||
| `rtl/z80_cpu.v` | Z-80 CPU |
|
| `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 |
|
| `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 |
|
| `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` |
|
| `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 |
|
| `tools/z80emu.py`, `tools/cputest.py`, `scripts/cpusim.sh` | CPU test bench: reference emulator, random tests |
|
||||||
|
|||||||
Binary file not shown.
+46
-4
@@ -205,7 +205,7 @@ enum {
|
|||||||
T_TO, T_STEP, T_NEXT, T_DIM, T_DEF, T_END, T_STOP, T_REM, T_READ, T_DATA,
|
T_TO, T_STEP, T_NEXT, T_DIM, T_DEF, T_END, T_STOP, T_REM, T_READ, T_DATA,
|
||||||
T_RESTORE, T_ON, T_RANDOMIZE, T_POKE, T_OUT, T_RUN, T_LIST, T_NEW, T_SCRATCH,
|
T_RESTORE, T_ON, T_RANDOMIZE, T_POKE, T_OUT, T_RUN, T_LIST, T_NEW, T_SCRATCH,
|
||||||
T_BYE, T_CLS, T_COLOR, T_PLOT, T_LINE, T_RECT, T_FILL, T_CIRCLE, T_LOCATE, T_INK,
|
T_BYE, T_CLS, T_COLOR, T_PLOT, T_LINE, T_RECT, T_FILL, T_CIRCLE, T_LOCATE, T_INK,
|
||||||
T_SAVE, T_LOAD, T_DIR, T_DEL, T_DATE, T_OPEN, T_CLOSE, T_OUTPUT, T_APPEND, T_AND, T_OR, T_NOT, T_SIN, T_COS, T_TAN, T_ATN, T_EXP, T_LOG, T_ABS,
|
T_SAVE, T_LOAD, T_DIR, T_DEL, T_DATE, T_OPEN, T_CLOSE, T_MONITOR, T_CALL, T_BSAVE, T_BLOAD, T_OUTPUT, T_APPEND, T_AND, T_OR, T_NOT, T_SIN, T_COS, T_TAN, T_ATN, T_EXP, T_LOG, T_ABS,
|
||||||
T_SQR, T_INT, T_RND, T_SGN, T_FN, T_TAB, T_PEEK, T_INP, T_LEN, T_VAL, T_ASC, T_EOF,
|
T_SQR, T_INT, T_RND, T_SGN, T_FN, T_TAB, T_PEEK, T_INP, T_LEN, T_VAL, T_ASC, T_EOF,
|
||||||
T_CHRS, T_STRS, T_LEFTS, T_RIGHTS, T_MIDS, T_DATES, T_TIM, T_POINT, T_LE, T_GE, T_NE, T_LAST
|
T_CHRS, T_STRS, T_LEFTS, T_RIGHTS, T_MIDS, T_DATES, T_TIM, T_POINT, T_LE, T_GE, T_NE, T_LAST
|
||||||
};
|
};
|
||||||
@@ -215,13 +215,14 @@ static const char *const kw[] = {
|
|||||||
"TO", "STEP", "NEXT", "DIM", "DEF", "END", "STOP", "REM", "READ", "DATA",
|
"TO", "STEP", "NEXT", "DIM", "DEF", "END", "STOP", "REM", "READ", "DATA",
|
||||||
"RESTORE", "ON", "RANDOMIZE", "POKE", "OUT", "RUN", "LIST", "NEW", "SCRATCH",
|
"RESTORE", "ON", "RANDOMIZE", "POKE", "OUT", "RUN", "LIST", "NEW", "SCRATCH",
|
||||||
"BYE", "CLS", "COLOR", "PLOT", "LINE", "RECT", "FILL", "CIRCLE", "LOCATE", "INK",
|
"BYE", "CLS", "COLOR", "PLOT", "LINE", "RECT", "FILL", "CIRCLE", "LOCATE", "INK",
|
||||||
"SAVE", "LOAD", "DIR", "DEL", "DATE", "OPEN", "CLOSE", "OUTPUT", "APPEND", "AND", "OR", "NOT", "SIN", "COS", "TAN", "ATN", "EXP", "LOG", "ABS",
|
"SAVE", "LOAD", "DIR", "DEL", "DATE", "OPEN", "CLOSE", "MONITOR", "CALL", "BSAVE", "BLOAD", "OUTPUT", "APPEND", "AND", "OR", "NOT", "SIN", "COS", "TAN", "ATN", "EXP", "LOG", "ABS",
|
||||||
"SQR", "INT", "RND", "SGN", "FN", "TAB", "PEEK", "INP", "LEN", "VAL", "ASC", "EOF",
|
"SQR", "INT", "RND", "SGN", "FN", "TAB", "PEEK", "INP", "LEN", "VAL", "ASC", "EOF",
|
||||||
"CHR$", "STR$", "LEFT$", "RIGHT$", "MID$", "DATE$", "TIM", "POINT", "<=", ">=", "<>"
|
"CHR$", "STR$", "LEFT$", "RIGHT$", "MID$", "DATE$", "TIM", "POINT", "<=", ">=", "<>"
|
||||||
};
|
};
|
||||||
|
|
||||||
/* ----------------------------------------------------------------- memory */
|
/* ----------------------------------------------------------------- memory */
|
||||||
#define ARENA 22100 /* program text grows up, arrays grow down */
|
#define ARENA 21076 /* program text grows up, arrays grow down;
|
||||||
|
F000-F3F7 is left free for machine code */
|
||||||
#define STRMAX 80
|
#define STRMAX 80
|
||||||
#define NVARS (26 * 11)
|
#define NVARS (26 * 11)
|
||||||
#define FORMAX 16
|
#define FORMAX 16
|
||||||
@@ -322,8 +323,15 @@ static void error(u8 e)
|
|||||||
/* The date and time, set by DATE (the PC tools set it when they connect) and
|
/* The date and time, set by DATE (the PC tools set it when they connect) and
|
||||||
kept from the millisecond counter until the power goes off. Held as seconds
|
kept from the millisecond counter until the power goes off. Held as seconds
|
||||||
since 2000-01-01 00:00; 0 means not set. */
|
since 2000-01-01 00:00; 0 means not set. */
|
||||||
|
#ifdef __SDCC
|
||||||
|
/* at a fixed address (between BASIC's data and the stack) so the monitor
|
||||||
|
can read the clock too */
|
||||||
|
static volatile __at(0xF3F8) u32 clk_sec;
|
||||||
|
static volatile __at(0xF3FC) i32 clk_ms; /* millis() at clk_sec */
|
||||||
|
#else
|
||||||
static u32 clk_sec;
|
static u32 clk_sec;
|
||||||
static i32 clk_ms; /* millis() at clk_sec */
|
static i32 clk_ms;
|
||||||
|
#endif
|
||||||
|
|
||||||
static u32 now(void)
|
static u32 now(void)
|
||||||
{
|
{
|
||||||
@@ -1895,6 +1903,32 @@ static void st_close(void)
|
|||||||
} while (accept(','));
|
} while (accept(','));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* BSAVE "NAME", start, length / BLOAD "NAME" [, address]: memory files,
|
||||||
|
the load address (2 bytes) and then the bytes, as the monitor writes them */
|
||||||
|
static void st_bfile(u8 t)
|
||||||
|
{
|
||||||
|
char nm[8];
|
||||||
|
u16 a, n;
|
||||||
|
int b;
|
||||||
|
struct chan *c = &ch[0];
|
||||||
|
c->mode = 0;
|
||||||
|
get_name(nm);
|
||||||
|
if (t == T_BSAVE) {
|
||||||
|
expect(','); a = (u16)(i32)expr();
|
||||||
|
expect(','); n = (u16)(i32)expr();
|
||||||
|
chan_open_out(c, nm, 0);
|
||||||
|
chan_putc(c, a); chan_putc(c, a >> 8);
|
||||||
|
while (n--) chan_putc(c, peek(a++));
|
||||||
|
chan_close(c);
|
||||||
|
} else {
|
||||||
|
chan_open_in(c, nm);
|
||||||
|
a = chan_getc(c); a |= chan_getc(c) << 8;
|
||||||
|
if (accept(',')) a = (u16)(i32)expr();
|
||||||
|
while ((b = chan_getc(c)) >= 0) poke(a++, b);
|
||||||
|
c->mode = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void st_save(void)
|
static void st_save(void)
|
||||||
{
|
{
|
||||||
char nm[8];
|
char nm[8];
|
||||||
@@ -2054,6 +2088,11 @@ static void statement(void)
|
|||||||
case T_DEL: st_del(); break;
|
case T_DEL: st_del(); break;
|
||||||
case T_OPEN: st_open(); break;
|
case T_OPEN: st_open(); break;
|
||||||
case T_CLOSE: st_close(); break;
|
case T_CLOSE: st_close(); break;
|
||||||
|
case T_BSAVE: case T_BLOAD: st_bfile(t); break;
|
||||||
|
#ifdef __SDCC
|
||||||
|
case T_MONITOR: io_out(0x61, 0); break; /* NMI into the monitor */
|
||||||
|
case T_CALL: ((void (*)(void))(u16)(i32)expr())(); break;
|
||||||
|
#endif
|
||||||
case T_DATE: {
|
case T_DATE: {
|
||||||
char d[STRMAX];
|
char d[STRMAX];
|
||||||
if (is_str_start()) { sexpr(d); set_date(d); break; }
|
if (is_str_start()) { sexpr(d); set_date(d); break; }
|
||||||
@@ -2115,6 +2154,9 @@ int main(void)
|
|||||||
{
|
{
|
||||||
u16 n;
|
u16 n;
|
||||||
u8 *p;
|
u8 *p;
|
||||||
|
#ifdef __SDCC
|
||||||
|
clk_sec = 0;
|
||||||
|
#endif
|
||||||
new_prog();
|
new_prog();
|
||||||
g_clear(0);
|
g_clear(0);
|
||||||
newline();
|
newline();
|
||||||
|
|||||||
+2974
-2974
File diff suppressed because it is too large.
Load diff
@@ -12,6 +12,7 @@
|
|||||||
call gsinit
|
call gsinit
|
||||||
call _main
|
call _main
|
||||||
halt
|
halt
|
||||||
|
.include "tramp.s"
|
||||||
|
|
||||||
.area _HOME
|
.area _HOME
|
||||||
.area _CODE
|
.area _CODE
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
;; Monitor trampoline, the same bytes in BASIC's ROM and in the monitor's.
|
||||||
|
;; Both copies must match: when port 60h switches the bank, the CPU may already
|
||||||
|
;; have read the next bytes from the other one.
|
||||||
|
;; 0066 NMI: save AF, bring the monitor bank in, enter the monitor at 0100h
|
||||||
|
;; 0070 leave: A goes to port 60h (bank out, bit 1 = stop after one
|
||||||
|
;; instruction), then AF and PC come off the program's stack
|
||||||
|
.org 0x0066
|
||||||
|
push af
|
||||||
|
ld a, #1
|
||||||
|
out (0x60), a
|
||||||
|
jp 0x0100
|
||||||
|
.org 0x0070
|
||||||
|
out (0x60), a
|
||||||
|
pop af
|
||||||
|
retn
|
||||||
+148
-16
@@ -23,7 +23,8 @@ READY
|
|||||||
|
|
||||||
The Z-80 keeps running while SW15 is down. It just waits until it can print
|
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**
|
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
|
### Talking to BASIC
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ case, except inside quotes.
|
|||||||
| `LIST 100` | List line 100 |
|
| `LIST 100` | List line 100 |
|
||||||
| `LIST 100-200` | List lines 100 to 200 (`LIST -200` and `LIST 100-` work too) |
|
| `LIST 100-200` | List lines 100 to 200 (`LIST -200` and `LIST 100-` work too) |
|
||||||
| `NEW` or `SCRATCH` | Erase the program and all variables |
|
| `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 |
|
| `LOAD "NAME"` | Bring a saved program back |
|
||||||
| `RUN "NAME"` | Load a saved program and run it |
|
| `RUN "NAME"` | Load a saved program and run it |
|
||||||
| `DIR` / `DEL "NAME"` | List the saved programs / delete one |
|
| `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
|
`LINE INPUT A$` (or `LINE INPUT "PROMPT"; A$`) takes the whole line into one
|
||||||
string, commas and quotes included, and prints no `? `.
|
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
|
### IF … THEN — decisions
|
||||||
|
|
||||||
@@ -299,14 +300,18 @@ again from the first item.
|
|||||||
different numbers. Without it, `RND` produces the same sequence every time the
|
different numbers. Without it, `RND` produces the same sequence every time the
|
||||||
Z-80 is reset.
|
Z-80 is reset.
|
||||||
|
|
||||||
### POKE and OUT
|
### POKE, OUT, CALL and MONITOR
|
||||||
|
|
||||||
```
|
```
|
||||||
POKE address, value
|
POKE address, value
|
||||||
OUT port, 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
|
### Graphics and text placement
|
||||||
|
|
||||||
@@ -350,8 +355,8 @@ A whole number from 1 to 6: `1 + INT(RND * 6)`.
|
|||||||
| Function | Result |
|
| Function | Result |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `TIM` | Seconds since the Z-80 was reset, to the millisecond |
|
| `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) |
|
| `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 10) |
|
| `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) |
|
| `POINT(X, Y)` | Colour of the graphics pixel at *X, Y* (0 off screen) |
|
||||||
| `PEEK(A)` | Byte at memory address *A* |
|
| `PEEK(A)` | Byte at memory address *A* |
|
||||||
| `INP(P)` | Byte from I/O port *P* |
|
| `INP(P)` | Byte from I/O port *P* |
|
||||||
@@ -472,11 +477,14 @@ stays where it is.
|
|||||||
| Addresses | Contents |
|
| Addresses | Contents |
|
||||||
|---|---|
|
|---|---|
|
||||||
| 0000–7FFF | BASIC itself (writes here are ignored) |
|
| 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 |
|
| F400–FFFF | The Z-80 stack |
|
||||||
|
|
||||||
`PEEK` can read anything; `POKE` can change anything from 8000 up, including
|
`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
|
### 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 |
|
| 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 |
|
| 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 |
|
| 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
|
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
|
loop runs a little faster if a constant used inside it is put into a variable
|
||||||
first.
|
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
|
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
|
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 |
|
| `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
|
`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.
|
`DIR`, and gets one when it is next saved after the date is set.
|
||||||
|
|
||||||
```
|
```
|
||||||
PRINT "TODAY IS "; LEFT$(DATE$, 10)
|
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
|
### Data files
|
||||||
|
|
||||||
A program can write text to a file and read it back, with up to three 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
|
stop the board from starting, even one that sends commands to the flash itself
|
||||||
with `OUT` (ports 64 and 65, section 9).
|
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
|
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
|
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.
|
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
|
An error stops the program and reports the line, for example
|
||||||
`?DIVISION BY ZERO IN 120`.
|
`?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 |
|
| `BREAK IN n` | You pressed Ctrl-C |
|
||||||
| `STOP IN n` | The program ran `STOP` |
|
| `STOP IN n` | The program ran `STOP` |
|
||||||
|
|
||||||
## 13. Example programs
|
## 14. Example programs
|
||||||
|
|
||||||
### Times table
|
### 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
|
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.
|
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 |
|
| Item | Limit |
|
||||||
|---|---|
|
|---|---|
|
||||||
| Program and arrays together | about 21.5 KB |
|
| Program and arrays together | about 20.5 KB |
|
||||||
| Line numbers | 0 – 65535 |
|
| Line numbers | 0 – 65535 |
|
||||||
| Line length | 250 characters typed |
|
| Line length | 250 characters typed |
|
||||||
| Numeric variables | A–Z and A0–Z9 |
|
| Numeric variables | A–Z and A0–Z9 |
|
||||||
|
|||||||
Binary file not shown.
Executable
+12
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Compile the monitor and write monitor.mem (its 32 KB bank) and monitor.bin.
|
||||||
|
set -e
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
mkdir -p out
|
||||||
|
sdasz80 -plosgff out/crt0.rel crt0.s
|
||||||
|
sdcc -mz80 --opt-code-size --max-allocs-per-node 20000 --std-sdcc11 -c -o out/monitor.rel monitor.c
|
||||||
|
sdcc -mz80 --no-std-crt0 --code-loc 0x0180 --data-loc 0x7000 -o out/monitor.ihx out/crt0.rel out/monitor.rel
|
||||||
|
python3 ../tools/ihx2mem.py out/monitor.ihx out/monitor-full.bin out/monitor-full.mem
|
||||||
|
head -c 32768 out/monitor-full.bin > monitor.bin
|
||||||
|
head -n 32768 out/monitor-full.mem > monitor.mem
|
||||||
|
grep -E '^ *_DATA|^ *_CODE' out/monitor.map | head -2 || true
|
||||||
+115
@@ -0,0 +1,115 @@
|
|||||||
|
;; Monitor start-up. The monitor's bank holds ROM at 0000-6FFF and RAM at
|
||||||
|
;; 7000-7FFF. It is entered through the trampoline at 0066h (shared with
|
||||||
|
;; BASIC) with the program's AF and PC pushed on the program's stack.
|
||||||
|
.module crt0
|
||||||
|
.globl _mon_main
|
||||||
|
.globl l__INITIALIZER, s__INITIALIZER, s__INITIALIZED
|
||||||
|
.globl l__DATA, s__DATA
|
||||||
|
.globl _u
|
||||||
|
|
||||||
|
;; saved registers, at a fixed place gsinit never clears (see struct regs)
|
||||||
|
_u = 0x7F00
|
||||||
|
U_SP = 0x7F00
|
||||||
|
U_BC = 0x7F02
|
||||||
|
U_DE = 0x7F04
|
||||||
|
U_HL = 0x7F06
|
||||||
|
U_IX = 0x7F08
|
||||||
|
U_IY = 0x7F0A
|
||||||
|
U_AF2 = 0x7F0C
|
||||||
|
U_BC2 = 0x7F0E
|
||||||
|
U_DE2 = 0x7F10
|
||||||
|
U_HL2 = 0x7F12
|
||||||
|
U_I = 0x7F14
|
||||||
|
U_R = 0x7F15
|
||||||
|
U_EXIT = 0x7F16
|
||||||
|
INITED = 0x7FFE
|
||||||
|
|
||||||
|
.area _HEADER (ABS)
|
||||||
|
.org 0x0000
|
||||||
|
halt ; the bank is never in at reset
|
||||||
|
.include "../basic/tramp.s"
|
||||||
|
|
||||||
|
.org 0x0100
|
||||||
|
entry: ld (U_SP), sp
|
||||||
|
ld sp, #0x7F00
|
||||||
|
ld (U_BC), bc
|
||||||
|
ld (U_DE), de
|
||||||
|
ld (U_HL), hl
|
||||||
|
ld (U_IX), ix
|
||||||
|
ld (U_IY), iy
|
||||||
|
ex af, af'
|
||||||
|
push af
|
||||||
|
pop hl
|
||||||
|
ld (U_AF2), hl
|
||||||
|
ex af, af'
|
||||||
|
exx
|
||||||
|
ld (U_BC2), bc
|
||||||
|
ld (U_DE2), de
|
||||||
|
ld (U_HL2), hl
|
||||||
|
exx
|
||||||
|
ld a, i
|
||||||
|
ld (U_I), a
|
||||||
|
ld a, r
|
||||||
|
ld (U_R), a
|
||||||
|
ld a, (INITED) ; C data is set up once, then kept
|
||||||
|
cp #0xA5
|
||||||
|
jr z, 1$
|
||||||
|
call gsinit
|
||||||
|
ld a, #0xA5
|
||||||
|
ld (INITED), a
|
||||||
|
1$: call _mon_main
|
||||||
|
ld a, (U_I)
|
||||||
|
ld i, a
|
||||||
|
ld hl, (U_AF2)
|
||||||
|
push hl
|
||||||
|
pop af
|
||||||
|
ex af, af'
|
||||||
|
exx
|
||||||
|
ld bc, (U_BC2)
|
||||||
|
ld de, (U_DE2)
|
||||||
|
ld hl, (U_HL2)
|
||||||
|
exx
|
||||||
|
ld bc, (U_BC)
|
||||||
|
ld de, (U_DE)
|
||||||
|
ld hl, (U_HL)
|
||||||
|
ld ix, (U_IX)
|
||||||
|
ld iy, (U_IY)
|
||||||
|
ld sp, (U_SP)
|
||||||
|
ld a, (U_EXIT)
|
||||||
|
jp 0x0070
|
||||||
|
|
||||||
|
.area _HOME
|
||||||
|
.area _CODE
|
||||||
|
.area _INITIALIZER
|
||||||
|
.area _GSINIT
|
||||||
|
.area _GSFINAL
|
||||||
|
.area _DATA
|
||||||
|
.area _INITIALIZED
|
||||||
|
.area _BSEG
|
||||||
|
.area _BSS
|
||||||
|
.area _HEAP
|
||||||
|
|
||||||
|
.area _GSINIT
|
||||||
|
gsinit:
|
||||||
|
ld bc, #l__DATA ; clear uninitialised data
|
||||||
|
ld a, b
|
||||||
|
or a, c
|
||||||
|
jr z, 1$
|
||||||
|
ld hl, #s__DATA
|
||||||
|
ld (hl), #0
|
||||||
|
dec bc
|
||||||
|
ld a, b
|
||||||
|
or a, c
|
||||||
|
jr z, 1$
|
||||||
|
ld de, #s__DATA + 1
|
||||||
|
ldir
|
||||||
|
1$: ld bc, #l__INITIALIZER ; copy initialised data
|
||||||
|
ld a, b
|
||||||
|
or a, c
|
||||||
|
jr z, 2$
|
||||||
|
ld de, #s__INITIALIZED
|
||||||
|
ld hl, #s__INITIALIZER
|
||||||
|
ldir
|
||||||
|
2$:
|
||||||
|
.area _GSFINAL
|
||||||
|
ret
|
||||||
Binary file not shown.
@@ -0,0 +1,950 @@
|
|||||||
|
/* Machine-code monitor for the Basys 3 Z-80.
|
||||||
|
*
|
||||||
|
* Entered by an NMI (the Pause key, BASIC's MONITOR, a breakpoint or a single
|
||||||
|
* step), with the monitor's bank in place of 0000-7FFF. It shows the
|
||||||
|
* registers, a disassembly from the PC, the stack and a memory dump on the
|
||||||
|
* terminal's alternate screen, and takes commands on the bottom line.
|
||||||
|
*
|
||||||
|
* The program's memory below 8000h is hidden by the bank, so it is read
|
||||||
|
* through the debug port (62h-64h); from 8000h up it is read directly. The
|
||||||
|
* program's AF and PC sit on its stack (pushed by the NMI and the trampoline).
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
|
||||||
|
typedef uint8_t u8;
|
||||||
|
typedef uint16_t u16;
|
||||||
|
typedef int16_t i16;
|
||||||
|
typedef uint32_t u32;
|
||||||
|
typedef int32_t i32;
|
||||||
|
|
||||||
|
#ifdef __SDCC
|
||||||
|
__sfr __at 0x00 con_stat;
|
||||||
|
__sfr __at 0x01 con_data;
|
||||||
|
__sfr __at 0x60 mon_ctl;
|
||||||
|
__sfr __at 0x62 dbg_lo;
|
||||||
|
__sfr __at 0x63 dbg_hi;
|
||||||
|
__sfr __at 0x64 dbg_dat;
|
||||||
|
__sfr __at 0x65 bp0_lo;
|
||||||
|
__sfr __at 0x66 bp0_hi;
|
||||||
|
__sfr __at 0x67 bp_ctl;
|
||||||
|
__sfr __at 0x68 bp1_lo;
|
||||||
|
__sfr __at 0x69 bp1_hi;
|
||||||
|
__sfr __at 0x10 tim0;
|
||||||
|
__sfr __at 0x11 tim1;
|
||||||
|
__sfr __at 0x12 tim2;
|
||||||
|
__sfr __at 0x13 tim3;
|
||||||
|
__sfr __at 0x40 fl_ctl;
|
||||||
|
__sfr __at 0x41 fl_dat;
|
||||||
|
|
||||||
|
/* BASIC's clock (set by DATE), kept at a fixed address in its RAM */
|
||||||
|
#define CLK_SEC (*(volatile u32 *)0xF3F8)
|
||||||
|
#define CLK_MS (*(volatile i32 *)0xF3FC)
|
||||||
|
|
||||||
|
/* saved by crt0.s at 7F00h */
|
||||||
|
struct regs {
|
||||||
|
u16 sp, bc, de, hl, ix, iy, af2, bc2, de2, hl2;
|
||||||
|
u8 i, r, exit;
|
||||||
|
};
|
||||||
|
extern struct regs u;
|
||||||
|
|
||||||
|
static void putc_(char c) { while (!(con_stat & 2)); con_data = c; }
|
||||||
|
static u8 getk(void) { while (!(con_stat & 1)); return con_data; }
|
||||||
|
static u8 rd(u16 a)
|
||||||
|
{
|
||||||
|
if (a & 0x8000) return *(volatile u8 *)a;
|
||||||
|
dbg_lo = a; dbg_hi = a >> 8;
|
||||||
|
return dbg_dat;
|
||||||
|
}
|
||||||
|
static u8 wr(u16 a, u8 v)
|
||||||
|
{
|
||||||
|
if (!(a & 0x8000)) return 0;
|
||||||
|
*(volatile u8 *)a = v;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* host build: only for testing the disassembler (see disasm_test) */
|
||||||
|
#include <stdio.h>
|
||||||
|
static u8 hostmem[65536];
|
||||||
|
static void putc_(char c) { putchar(c); }
|
||||||
|
static u8 rd(u16 a) { return hostmem[a]; }
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------ text out */
|
||||||
|
static char line[96];
|
||||||
|
static char *lp;
|
||||||
|
|
||||||
|
static void s_ch(char c) { *lp++ = c; }
|
||||||
|
static void s_str(const char *s) { while (*s) *lp++ = *s++; }
|
||||||
|
static const char hexd[] = "0123456789ABCDEF";
|
||||||
|
static void s_h2(u8 v) { s_ch(hexd[v >> 4]); s_ch(hexd[v & 15]); }
|
||||||
|
static void s_h4(u16 v) { s_h2(v >> 8); s_h2(v); }
|
||||||
|
/* assembler style: 3EH, 0FFH, 1234H, 0C000H */
|
||||||
|
static void s_n8(u8 v) { if (v >= 0xA0) s_ch('0'); s_h2(v); s_ch('H'); }
|
||||||
|
static void s_n16(u16 v) { if (v >= 0xA000) s_ch('0'); s_h4(v); s_ch('H'); }
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------- disassembler */
|
||||||
|
static u16 da; /* next byte to decode */
|
||||||
|
static u8 ixm; /* 0 HL, 1 IX, 2 IY */
|
||||||
|
static u8 ixd; /* displacement for DDCB */
|
||||||
|
static u8 nb(void) { return rd(da++); }
|
||||||
|
|
||||||
|
static const char *const r8n[] = { "B", "C", "D", "E", "H", "L", "(HL)", "A" };
|
||||||
|
static const char *const ccn[] = { "NZ", "Z", "NC", "C", "PO", "PE", "P", "M" };
|
||||||
|
static const char *const alun[] = { "ADD A,", "ADC A,", "SUB ", "SBC A,", "AND ", "XOR ", "OR ", "CP " };
|
||||||
|
static const char *const rotn[] = { "RLC ", "RRC ", "RL ", "RR ", "SLA ", "SRA ", "SLL ", "SRL " };
|
||||||
|
static const char *const blkn[] = {
|
||||||
|
"LDI", "CPI", "INI", "OUTI", "LDD", "CPD", "IND", "OUTD",
|
||||||
|
"LDIR", "CPIR", "INIR", "OTIR", "LDDR", "CPDR", "INDR", "OTDR" };
|
||||||
|
static const char *const op7n[] = { "RLCA", "RRCA", "RLA", "RRA", "DAA", "CPL", "SCF", "CCF" };
|
||||||
|
|
||||||
|
static void s_hl(void) { s_str(ixm == 0 ? "HL" : ixm == 1 ? "IX" : "IY"); }
|
||||||
|
|
||||||
|
static void s_disp(u8 d)
|
||||||
|
{
|
||||||
|
if (d & 0x80) { s_ch('-'); d = -d; } else s_ch('+');
|
||||||
|
s_n8(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void s_ind(void) /* (HL) or (IX+d), reading d */
|
||||||
|
{
|
||||||
|
if (!ixm) { s_str("(HL)"); return; }
|
||||||
|
s_ch('('); s_hl(); s_disp(nb()); s_ch(')');
|
||||||
|
}
|
||||||
|
|
||||||
|
/* register r; mem = the instruction also uses (HL), so H and L stay H and L */
|
||||||
|
static void s_r8(u8 r, u8 mem)
|
||||||
|
{
|
||||||
|
if (r == 6) s_ind();
|
||||||
|
else if (ixm && !mem && (r == 4 || r == 5)) { s_str(ixm == 1 ? "IX" : "IY"); s_ch(r == 4 ? 'H' : 'L'); }
|
||||||
|
else s_str(r8n[r]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void s_rp(u8 p) { if (p == 2) s_hl(); else s_str(p == 0 ? "BC" : p == 1 ? "DE" : "SP"); }
|
||||||
|
static void s_rp2(u8 p) { if (p == 3) s_str("AF"); else s_rp(p); }
|
||||||
|
static void s_nn(void) { u16 v = nb(); v |= (u16)nb() << 8; s_n16(v); }
|
||||||
|
static void s_rel(void) { i16 d = (int8_t)nb(); s_n16(da + d); }
|
||||||
|
|
||||||
|
static void dis_cb(u8 op)
|
||||||
|
{
|
||||||
|
u8 x = op >> 6, y = (op >> 3) & 7, z = op & 7;
|
||||||
|
if (x == 0) s_str(rotn[y]);
|
||||||
|
else { s_str(x == 1 ? "BIT " : x == 2 ? "RES " : "SET "); s_ch('0' + y); s_ch(','); }
|
||||||
|
if (ixm) {
|
||||||
|
s_ch('('); s_hl(); s_disp(ixd); s_ch(')');
|
||||||
|
if (z != 6 && x != 1) { s_ch(','); s_str(r8n[z]); } /* undocumented copy */
|
||||||
|
} else s_str(r8n[z]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dis_ed(u8 op)
|
||||||
|
{
|
||||||
|
u8 x = op >> 6, y = (op >> 3) & 7, z = op & 7, p = y >> 1, q = y & 1;
|
||||||
|
if (x == 1) switch (z) {
|
||||||
|
case 0: s_str("IN "); if (y != 6) { s_str(r8n[y]); s_ch(','); } s_str("(C)"); return;
|
||||||
|
case 1: s_str("OUT (C),"); s_str(y == 6 ? "0" : r8n[y]); return;
|
||||||
|
case 2: s_str(q ? "ADC HL," : "SBC HL,"); s_rp(p); return;
|
||||||
|
case 3:
|
||||||
|
s_str("LD ");
|
||||||
|
if (q) { s_rp(p); s_ch(','); s_ch('('); s_nn(); s_ch(')'); }
|
||||||
|
else { s_ch('('); s_nn(); s_str("),"); s_rp(p); }
|
||||||
|
return;
|
||||||
|
case 4: s_str("NEG"); return;
|
||||||
|
case 5: s_str(y == 1 ? "RETI" : "RETN"); return;
|
||||||
|
case 6: s_str("IM "); s_ch("0012"[y & 3]); return;
|
||||||
|
case 7: {
|
||||||
|
static const char *const n7[] = { "LD I,A", "LD R,A", "LD A,I", "LD A,R", "RRD", "RLD", "NOP*", "NOP*" };
|
||||||
|
s_str(n7[y]); return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (x == 2 && z <= 3 && y >= 4) { s_str(blkn[(y - 4) * 4 + z]); return; }
|
||||||
|
s_str("NOP*");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void dis_main(u8 op)
|
||||||
|
{
|
||||||
|
u8 x = op >> 6, y = (op >> 3) & 7, z = op & 7, p = y >> 1, q = y & 1;
|
||||||
|
switch (x) {
|
||||||
|
case 0:
|
||||||
|
switch (z) {
|
||||||
|
case 0:
|
||||||
|
if (y == 0) s_str("NOP");
|
||||||
|
else if (y == 1) s_str("EX AF,AF'");
|
||||||
|
else if (y == 2) { s_str("DJNZ "); s_rel(); }
|
||||||
|
else if (y == 3) { s_str("JR "); s_rel(); }
|
||||||
|
else { s_str("JR "); s_str(ccn[y - 4]); s_ch(','); s_rel(); }
|
||||||
|
return;
|
||||||
|
case 1:
|
||||||
|
if (!q) { s_str("LD "); s_rp(p); s_ch(','); s_nn(); }
|
||||||
|
else { s_str("ADD "); s_hl(); s_ch(','); s_rp(p); }
|
||||||
|
return;
|
||||||
|
case 2: {
|
||||||
|
static const char *const m[] = { "(BC)", "(DE)" };
|
||||||
|
s_str("LD ");
|
||||||
|
if (!q) {
|
||||||
|
if (p < 2) { s_str(m[p]); s_str(",A"); }
|
||||||
|
else { s_ch('('); s_nn(); s_str("),"); if (p == 2) s_hl(); else s_ch('A'); }
|
||||||
|
} else {
|
||||||
|
if (p < 2) { s_str("A,"); s_str(m[p]); }
|
||||||
|
else { if (p == 2) s_hl(); else s_ch('A'); s_str(",("); s_nn(); s_ch(')'); }
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case 3: s_str(q ? "DEC " : "INC "); s_rp(p); return;
|
||||||
|
case 4: s_str("INC "); s_r8(y, 0); return;
|
||||||
|
case 5: s_str("DEC "); s_r8(y, 0); return;
|
||||||
|
case 6: s_str("LD "); s_r8(y, 0); s_ch(','); s_n8(nb()); return;
|
||||||
|
default: s_str(op7n[y]); return;
|
||||||
|
}
|
||||||
|
case 1:
|
||||||
|
if (op == 0x76) { s_str("HALT"); return; }
|
||||||
|
s_str("LD "); s_r8(y, z == 6); s_ch(','); s_r8(z, y == 6);
|
||||||
|
return;
|
||||||
|
case 2:
|
||||||
|
s_str(alun[y]); s_r8(z, 0);
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
switch (z) {
|
||||||
|
case 0: s_str("RET "); s_str(ccn[y]); return;
|
||||||
|
case 1:
|
||||||
|
if (!q) { s_str("POP "); s_rp2(p); }
|
||||||
|
else if (p == 0) s_str("RET");
|
||||||
|
else if (p == 1) s_str("EXX");
|
||||||
|
else if (p == 2) { s_str("JP ("); s_hl(); s_ch(')'); }
|
||||||
|
else { s_str("LD SP,"); s_hl(); }
|
||||||
|
return;
|
||||||
|
case 2: s_str("JP "); s_str(ccn[y]); s_ch(','); s_nn(); return;
|
||||||
|
case 3:
|
||||||
|
switch (y) {
|
||||||
|
case 0: s_str("JP "); s_nn(); return;
|
||||||
|
case 2: s_str("OUT ("); s_n8(nb()); s_str("),A"); return;
|
||||||
|
case 3: s_str("IN A,("); s_n8(nb()); s_ch(')'); return;
|
||||||
|
case 4: s_str("EX (SP),"); s_hl(); return;
|
||||||
|
case 5: s_str("EX DE,HL"); return;
|
||||||
|
case 6: s_str("DI"); return;
|
||||||
|
default: s_str("EI"); return;
|
||||||
|
}
|
||||||
|
case 4: s_str("CALL "); s_str(ccn[y]); s_ch(','); s_nn(); return;
|
||||||
|
case 5:
|
||||||
|
if (!q) { s_str("PUSH "); s_rp2(p); }
|
||||||
|
else { s_str("CALL "); s_nn(); }
|
||||||
|
return;
|
||||||
|
case 6: s_str(alun[y]); s_n8(nb()); return;
|
||||||
|
default: s_str("RST "); s_n8(y * 8); return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disassemble the instruction at a into line (from lp); returns its length. */
|
||||||
|
static u8 disasm(u16 a)
|
||||||
|
{
|
||||||
|
u8 op;
|
||||||
|
da = a;
|
||||||
|
ixm = 0;
|
||||||
|
op = nb();
|
||||||
|
if (op == 0xDD || op == 0xFD) {
|
||||||
|
u8 n = rd(da);
|
||||||
|
if (n == 0xDD || n == 0xFD || n == 0xED) { /* a prefix doing nothing */
|
||||||
|
s_str("DB "); s_n8(op);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
ixm = op == 0xDD ? 1 : 2;
|
||||||
|
op = nb();
|
||||||
|
}
|
||||||
|
if (op == 0xCB) {
|
||||||
|
if (ixm) { ixd = nb(); dis_cb(nb()); }
|
||||||
|
else dis_cb(nb());
|
||||||
|
} else if (op == 0xED) dis_ed(nb());
|
||||||
|
else dis_main(op);
|
||||||
|
return da - a;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef __SDCC
|
||||||
|
/* Host test: disassemble every opcode form, one per line, for the round trip
|
||||||
|
through sdasz80 in monitor/test-disasm.sh. Format: hex bytes TAB text. */
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
static const u8 pre[][2] = { {0, 0}, {0xCB, 0}, {0xED, 0}, {0xDD, 0}, {0xFD, 0}, {0xDD, 0xCB}, {0xFD, 0xCB} };
|
||||||
|
u16 k, i;
|
||||||
|
for (k = 0; k < 7; k++)
|
||||||
|
for (i = 0; i < 256; i++) {
|
||||||
|
u8 n = 0, len, j;
|
||||||
|
memset(hostmem, 0, 16);
|
||||||
|
if (pre[k][0]) hostmem[n++] = pre[k][0];
|
||||||
|
if (pre[k][1] == 0xCB) { hostmem[n++] = 0xCB; hostmem[n++] = 0x85; } /* d = -7BH */
|
||||||
|
hostmem[n++] = i;
|
||||||
|
if (k == 3 || k == 4) {
|
||||||
|
if (i == 0xCB || i == 0xDD || i == 0xED || i == 0xFD) continue;
|
||||||
|
}
|
||||||
|
hostmem[n] = 0x12; hostmem[n + 1] = 0x34; hostmem[n + 2] = 0x56;
|
||||||
|
lp = line;
|
||||||
|
len = disasm(0x100 - 0x100);
|
||||||
|
*lp = 0;
|
||||||
|
for (j = 0; j < len; j++) printf("%02X", hostmem[j]);
|
||||||
|
printf("\t%s\n", line);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------- screen */
|
||||||
|
static void puts_(const char *s) { while (*s) putc_(*s++); }
|
||||||
|
static void at(u8 r, u8 c) /* r, c from 0 */
|
||||||
|
{
|
||||||
|
putc_(27); putc_('[');
|
||||||
|
r++; c++;
|
||||||
|
if (r >= 10) putc_('0' + r / 10);
|
||||||
|
putc_('0' + r % 10); putc_(';');
|
||||||
|
if (c >= 10) putc_('0' + c / 10);
|
||||||
|
putc_('0' + c % 10); putc_('H');
|
||||||
|
}
|
||||||
|
static void sgr(const char *s) { putc_(27); putc_('['); puts_(s); putc_('m'); }
|
||||||
|
static void flush_line(void) { *lp = 0; puts_(line); }
|
||||||
|
static void clr_eol(void) { puts_("\033[K"); }
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------- state */
|
||||||
|
#define DIS_ROWS 16
|
||||||
|
#define MEM_ROWS 6
|
||||||
|
#define DIS_TOP 5
|
||||||
|
#define MEM_TOP 22
|
||||||
|
|
||||||
|
static u16 dis_a; /* first line of the disassembly window */
|
||||||
|
static u16 mem_a; /* first line of the memory window */
|
||||||
|
static u16 bp; /* the user's breakpoint */
|
||||||
|
static u8 bp_set;
|
||||||
|
static u8 go_after; /* stepping off a breakpoint, then G */
|
||||||
|
static u16 steps; /* more single steps to do */
|
||||||
|
static char cmd[40];
|
||||||
|
static u8 msg_err;
|
||||||
|
static const char *msg;
|
||||||
|
static u8 why_in; /* why the monitor was entered */
|
||||||
|
static char load_msg[24];
|
||||||
|
|
||||||
|
static u16 pc_get(void) { return rd(u.sp + 2) | (u16)rd(u.sp + 3) << 8; }
|
||||||
|
static u16 af_get(void) { return rd(u.sp) | (u16)rd(u.sp + 1) << 8; }
|
||||||
|
static u8 pc_set(u16 v) { return wr(u.sp + 2, v) & wr(u.sp + 3, v >> 8); }
|
||||||
|
static u8 af_set(u16 v) { return wr(u.sp, v) & wr(u.sp + 1, v >> 8); }
|
||||||
|
static u16 sp_get(void) { return u.sp + 4; }
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------- drawing */
|
||||||
|
static void s_reg(const char *n, u16 v) { s_str(n); s_h4(v); s_str(" "); }
|
||||||
|
|
||||||
|
static void draw_regs(void)
|
||||||
|
{
|
||||||
|
u16 af = af_get();
|
||||||
|
u8 f = af, i;
|
||||||
|
static const char fl[] = "SZ5H3PNC";
|
||||||
|
lp = line;
|
||||||
|
s_reg(" PC ", pc_get()); s_reg("SP ", sp_get()); s_reg("AF ", af);
|
||||||
|
s_reg("BC ", u.bc); s_reg("DE ", u.de); s_reg("HL ", u.hl);
|
||||||
|
s_reg("IX ", u.ix); s_reg("IY ", u.iy);
|
||||||
|
at(2, 0); flush_line(); clr_eol();
|
||||||
|
lp = line;
|
||||||
|
s_reg(" AF'", u.af2); s_reg("BC'", u.bc2); s_reg("DE'", u.de2); s_reg("HL'", u.hl2);
|
||||||
|
s_str("I "); s_h2(u.i); s_str(" FLAGS ");
|
||||||
|
for (i = 0; i < 8; i++) s_ch(f & (0x80 >> i) ? fl[i] : '-');
|
||||||
|
at(3, 0); flush_line(); clr_eol();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_dis(void)
|
||||||
|
{
|
||||||
|
u16 a = dis_a, pc = pc_get();
|
||||||
|
u8 r, n, j;
|
||||||
|
for (r = 0; r < DIS_ROWS; r++) {
|
||||||
|
lp = line;
|
||||||
|
s_ch(a == pc ? '>' : ' ');
|
||||||
|
s_ch(bp_set && a == bp ? '*' : ' ');
|
||||||
|
s_h4(a); s_str(" ");
|
||||||
|
{
|
||||||
|
char *t = lp;
|
||||||
|
n = disasm(a);
|
||||||
|
/* the text went in at t; move it right of the bytes */
|
||||||
|
{
|
||||||
|
char txt[40];
|
||||||
|
u8 k = lp - t;
|
||||||
|
memcpy(txt, t, k); txt[k] = 0;
|
||||||
|
lp = t;
|
||||||
|
for (j = 0; j < 4; j++) {
|
||||||
|
if (j < n) s_h2(rd(a + j)); else s_str(" ");
|
||||||
|
s_ch(' ');
|
||||||
|
}
|
||||||
|
s_ch(' ');
|
||||||
|
s_str(txt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (lp < line + 50) s_ch(' ');
|
||||||
|
at(DIS_TOP + r, 0);
|
||||||
|
if (a == pc) sgr("1;33;44");
|
||||||
|
flush_line();
|
||||||
|
if (a == pc) sgr("0");
|
||||||
|
a += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_stack(void)
|
||||||
|
{
|
||||||
|
u16 s = sp_get();
|
||||||
|
u8 r;
|
||||||
|
at(DIS_TOP, 54); sgr("36"); puts_("STACK"); sgr("0");
|
||||||
|
for (r = 0; r < DIS_ROWS - 2; r++) {
|
||||||
|
lp = line;
|
||||||
|
s_h4(s); s_str(" ");
|
||||||
|
s_h4(rd(s) | (u16)rd(s + 1) << 8);
|
||||||
|
at(DIS_TOP + 1 + r, 54); flush_line();
|
||||||
|
s += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_mem(void)
|
||||||
|
{
|
||||||
|
u16 a = mem_a;
|
||||||
|
u8 r, j, c;
|
||||||
|
for (r = 0; r < MEM_ROWS; r++) {
|
||||||
|
lp = line;
|
||||||
|
s_ch(' '); s_h4(a); s_str(" ");
|
||||||
|
for (j = 0; j < 16; j++) { s_h2(rd(a + j)); s_ch(j == 7 ? '-' : ' '); }
|
||||||
|
s_ch(' ');
|
||||||
|
for (j = 0; j < 16; j++) { c = rd(a + j); s_ch(c >= 32 && c < 127 ? c : '.'); }
|
||||||
|
at(MEM_TOP + r, 0); flush_line(); clr_eol();
|
||||||
|
a += 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *why_text(u8 w)
|
||||||
|
{
|
||||||
|
switch (w) {
|
||||||
|
case 1: return "PAUSE KEY";
|
||||||
|
case 2: return "MONITOR COMMAND";
|
||||||
|
case 3: return "STEP";
|
||||||
|
case 4: return "BREAKPOINT";
|
||||||
|
case 5: return "STEP OVER";
|
||||||
|
default: return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_all(void)
|
||||||
|
{
|
||||||
|
puts_("\033[2J");
|
||||||
|
at(0, 0); sgr("1;37;44");
|
||||||
|
lp = line;
|
||||||
|
s_str(" Z-80 MONITOR");
|
||||||
|
while (lp < line + 50) s_ch(' ');
|
||||||
|
s_str("STOPPED BY ");
|
||||||
|
s_str(why_text(why_in));
|
||||||
|
while (lp < line + 80) s_ch(' ');
|
||||||
|
flush_line(); sgr("0");
|
||||||
|
draw_regs();
|
||||||
|
at(DIS_TOP - 1, 0); sgr("36"); puts_(" ADDR BYTES INSTRUCTION"); sgr("0");
|
||||||
|
draw_dis();
|
||||||
|
draw_stack();
|
||||||
|
at(MEM_TOP - 1, 0); sgr("36"); puts_(" MEMORY"); sgr("0");
|
||||||
|
draw_mem();
|
||||||
|
at(28, 0); sgr("36");
|
||||||
|
puts_(" ENTER step O over G go X exit B bp D/M addr E edit R reg ? help");
|
||||||
|
sgr("0");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------- input */
|
||||||
|
static u8 is_hex(char c) { return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F'); }
|
||||||
|
static char *cp;
|
||||||
|
static void skip_sp(void) { while (*cp == ' ' || *cp == ',') cp++; }
|
||||||
|
|
||||||
|
/* hex number at cp; 0 if none */
|
||||||
|
static u8 get_hex(u16 *v)
|
||||||
|
{
|
||||||
|
u8 n = 0;
|
||||||
|
skip_sp();
|
||||||
|
*v = 0;
|
||||||
|
while (is_hex(*cp)) {
|
||||||
|
*v = *v << 4 | (*cp <= '9' ? *cp - '0' : *cp - 'A' + 10);
|
||||||
|
cp++; n++;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void show_msg(void)
|
||||||
|
{
|
||||||
|
at(29, 40); clr_eol();
|
||||||
|
if (msg) { sgr(msg_err ? "1;31" : "32"); puts_(msg); sgr("0"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Read a command into cmd. Returns 1 for a line, or a key code for a key
|
||||||
|
that acts at once on an empty line: 'U', 'N' (up, down), 'P', 'Q' (page). */
|
||||||
|
static u8 read_cmd(void)
|
||||||
|
{
|
||||||
|
u8 n = 0, c;
|
||||||
|
at(29, 0); puts_("> "); clr_eol();
|
||||||
|
show_msg();
|
||||||
|
at(29, 2);
|
||||||
|
puts_("\033[?25h");
|
||||||
|
for (;;) {
|
||||||
|
c = getk();
|
||||||
|
if (c == 27) {
|
||||||
|
c = getk();
|
||||||
|
if (c == '[' || c == 'O') {
|
||||||
|
u8 k = getk(), t = k;
|
||||||
|
while (t >= '0' && t <= '9') t = getk(); /* ESC [ 5 ~ */
|
||||||
|
puts_("\033[?25l");
|
||||||
|
if (k == 'A') return 'U';
|
||||||
|
if (k == 'B') return 'N';
|
||||||
|
if (k == '5') return 'P';
|
||||||
|
if (k == '6') return 'Q';
|
||||||
|
puts_("\033[?25h");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (c == '\r' || c == '\n') { cmd[n] = 0; puts_("\033[?25l"); return 1; }
|
||||||
|
if (c == 8 || c == 127) { if (n) { n--; puts_("\b \b"); } continue; }
|
||||||
|
if (c == 21) { while (n) { n--; puts_("\b \b"); } continue; }
|
||||||
|
if (c >= 'a' && c <= 'z') c -= 32;
|
||||||
|
if (c >= ' ' && c < 127 && n < sizeof cmd - 1) { cmd[n++] = c; putc_(c); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------- flash files */
|
||||||
|
/* The same file system as BASIC's (basic.c): 448 blocks of 4 KB from
|
||||||
|
240000h, a directory in block 0 or 1 (the newer valid one). A memory file
|
||||||
|
holds its load address (2 bytes, low first) and then the bytes. */
|
||||||
|
#define FS_BASE 0x240000UL
|
||||||
|
#define FS_BLOCKS 448
|
||||||
|
#define MAXFILES 64
|
||||||
|
#define FBLK 8
|
||||||
|
|
||||||
|
struct dirent { char name[8]; u16 len; u16 blk[FBLK]; u16 date[2]; };
|
||||||
|
#define OLD_DIRENT 26
|
||||||
|
static struct {
|
||||||
|
char magic[4];
|
||||||
|
u16 seq, next;
|
||||||
|
struct dirent e[MAXFILES];
|
||||||
|
u16 sum;
|
||||||
|
} dir;
|
||||||
|
static u8 dir_cur;
|
||||||
|
static u8 bmap[FS_BLOCKS / 8];
|
||||||
|
static u8 page[256];
|
||||||
|
static u16 w_pos;
|
||||||
|
static u16 w_blk[FBLK];
|
||||||
|
static jmp_buf fs_jmp;
|
||||||
|
static const char *fs_msg;
|
||||||
|
|
||||||
|
static void fs_fail(const char *m) { fs_msg = m; longjmp(fs_jmp, 1); }
|
||||||
|
|
||||||
|
static i32 millis(void)
|
||||||
|
{
|
||||||
|
u8 a = tim0;
|
||||||
|
return (i32)a | (i32)tim1 << 8 | (i32)tim2 << 16 | (i32)tim3 << 24;
|
||||||
|
}
|
||||||
|
static u32 now(void)
|
||||||
|
{
|
||||||
|
u32 s = CLK_SEC;
|
||||||
|
return s ? s + (u32)(millis() - CLK_MS) / 1000 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 spi(u8 b) { fl_dat = b; while (fl_ctl & 1); return fl_dat; }
|
||||||
|
static void fl_open(u8 cmd) { fl_ctl = 1; spi(cmd); }
|
||||||
|
static void fl_close(void) { fl_ctl = 0; }
|
||||||
|
static void fl_addr(u32 a) { spi(a >> 16); spi(a >> 8); spi(a); }
|
||||||
|
static void fl_read(u32 a, u8 *p, u16 n)
|
||||||
|
{
|
||||||
|
fl_open(0x03); fl_addr(a);
|
||||||
|
while (n--) *p++ = spi(0);
|
||||||
|
fl_close();
|
||||||
|
}
|
||||||
|
static void fl_wait(void)
|
||||||
|
{
|
||||||
|
i32 t = millis();
|
||||||
|
u8 st;
|
||||||
|
do {
|
||||||
|
fl_open(0x05); st = spi(0); fl_close();
|
||||||
|
if (millis() - t > 3000) fs_fail("FLASH ERROR");
|
||||||
|
} while (st & 1);
|
||||||
|
}
|
||||||
|
static void fl_write_op(u8 cmd, u32 a, const u8 *p, u16 n)
|
||||||
|
{
|
||||||
|
u8 ok;
|
||||||
|
fl_open(0x06); fl_close();
|
||||||
|
fl_open(cmd); fl_addr(a);
|
||||||
|
while (n--) spi(*p++);
|
||||||
|
ok = !(fl_ctl & 2);
|
||||||
|
fl_close();
|
||||||
|
if (!ok) fs_fail("FLASH ERROR");
|
||||||
|
fl_wait();
|
||||||
|
}
|
||||||
|
static u32 blk_addr(u16 b) { return FS_BASE + ((u32)b << 12); }
|
||||||
|
static u8 nblk(u16 len) { return (len + 4095) >> 12; }
|
||||||
|
static void fl_prog(u32 a, const u8 *p, u16 n)
|
||||||
|
{
|
||||||
|
u8 chk[32];
|
||||||
|
u16 i, k;
|
||||||
|
fl_write_op(0x02, a, p, n);
|
||||||
|
for (i = 0; i < n; i += k) {
|
||||||
|
k = n - i < 32 ? n - i : 32;
|
||||||
|
fl_read(a + i, chk, k);
|
||||||
|
if (memcmp(chk, p + i, k)) fs_fail("FLASH ERROR");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static u16 sum_of(u16 n)
|
||||||
|
{
|
||||||
|
u8 *p = (u8 *)&dir;
|
||||||
|
u16 s = 0x5AA5;
|
||||||
|
while (n--) s = (s << 1 | s >> 15) + *p++;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
static u8 load_dir(u8 b)
|
||||||
|
{
|
||||||
|
u8 *p = (u8 *)&dir, i;
|
||||||
|
u16 old = 8 + MAXFILES * OLD_DIRENT;
|
||||||
|
fl_read(blk_addr(b), p, sizeof dir);
|
||||||
|
if (!memcmp(dir.magic, "BFS2", 4)) return dir.sum == sum_of(sizeof dir - 2);
|
||||||
|
if (memcmp(dir.magic, "BFS1", 4) || (p[old] | p[old + 1] << 8) != sum_of(old)) return 0;
|
||||||
|
for (i = MAXFILES; i--; ) {
|
||||||
|
memmove(&dir.e[i], p + 8 + i * OLD_DIRENT, OLD_DIRENT);
|
||||||
|
dir.e[i].date[0] = dir.e[i].date[1] = 0;
|
||||||
|
}
|
||||||
|
memcpy(dir.magic, "BFS2", 4);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
static void fs_mount(void)
|
||||||
|
{
|
||||||
|
u8 va, vb;
|
||||||
|
u16 sa;
|
||||||
|
fl_open(0x9F); va = spi(0); vb = spi(0); sa = spi(0); fl_close();
|
||||||
|
if (va != 0xC2 || vb != 0x20 || sa != 0x16) fs_fail("NO FLASH");
|
||||||
|
va = load_dir(0);
|
||||||
|
sa = dir.seq;
|
||||||
|
vb = load_dir(1);
|
||||||
|
if (va && (!vb || (i16)(sa - dir.seq) > 0)) { load_dir(0); dir_cur = 0; }
|
||||||
|
else if (vb) dir_cur = 1;
|
||||||
|
else {
|
||||||
|
memset(&dir, 0, sizeof dir);
|
||||||
|
memcpy(dir.magic, "BFS2", 4);
|
||||||
|
dir.next = 2;
|
||||||
|
dir_cur = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void fs_commit(void)
|
||||||
|
{
|
||||||
|
u8 b = dir_cur ^ 1, *p = (u8 *)&dir;
|
||||||
|
u16 i, n;
|
||||||
|
dir.seq++;
|
||||||
|
dir.sum = sum_of(sizeof dir - 2);
|
||||||
|
fl_write_op(0x20, blk_addr(b), 0, 0);
|
||||||
|
for (i = 0; i < sizeof dir; i += 256) {
|
||||||
|
n = sizeof dir - i < 256 ? sizeof dir - i : 256;
|
||||||
|
fl_prog(blk_addr(b) + i, p + i, n);
|
||||||
|
}
|
||||||
|
dir_cur = b;
|
||||||
|
}
|
||||||
|
static i16 find_file(const char *nm)
|
||||||
|
{
|
||||||
|
u8 i;
|
||||||
|
for (i = 0; i < MAXFILES; i++)
|
||||||
|
if (!memcmp(dir.e[i].name, nm, 8)) return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
static u16 alloc_blk(void)
|
||||||
|
{
|
||||||
|
u16 b = dir.next, k;
|
||||||
|
for (k = 0; k < FS_BLOCKS; k++, b++) {
|
||||||
|
if (b >= FS_BLOCKS) b = 2;
|
||||||
|
if (!(bmap[b >> 3] & (1 << (b & 7)))) {
|
||||||
|
bmap[b >> 3] |= 1 << (b & 7);
|
||||||
|
dir.next = b + 1;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fs_fail("DISK FULL");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static void build_bmap(void)
|
||||||
|
{
|
||||||
|
u8 i, j, n;
|
||||||
|
memset(bmap, 0, sizeof bmap);
|
||||||
|
bmap[0] = 3;
|
||||||
|
for (i = 0; i < MAXFILES; i++)
|
||||||
|
if (dir.e[i].name[0])
|
||||||
|
for (j = 0, n = nblk(dir.e[i].len); j < n; j++)
|
||||||
|
bmap[dir.e[i].blk[j] >> 3] |= 1 << (dir.e[i].blk[j] & 7);
|
||||||
|
}
|
||||||
|
static void put_b(u8 c)
|
||||||
|
{
|
||||||
|
if (!(w_pos & 4095)) {
|
||||||
|
w_blk[w_pos >> 12] = alloc_blk();
|
||||||
|
fl_write_op(0x20, blk_addr(w_blk[w_pos >> 12]), 0, 0);
|
||||||
|
}
|
||||||
|
page[w_pos & 255] = c;
|
||||||
|
w_pos++;
|
||||||
|
if (!(w_pos & 255))
|
||||||
|
fl_prog(blk_addr(w_blk[(w_pos - 1) >> 12]) + ((w_pos - 256) & 4095), page, 256);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* "NAME" at cp: 1-8 letters and digits */
|
||||||
|
static void get_fname(char *nm)
|
||||||
|
{
|
||||||
|
u8 n = 0;
|
||||||
|
skip_sp();
|
||||||
|
if (*cp++ != '"') fs_fail("NAME IN QUOTES");
|
||||||
|
memset(nm, 0, 8);
|
||||||
|
while (*cp && *cp != '"') {
|
||||||
|
if (n == 8 || !((*cp >= 'A' && *cp <= 'Z') || (*cp >= '0' && *cp <= '9'))) fs_fail("BAD FILE NAME");
|
||||||
|
nm[n++] = *cp++;
|
||||||
|
}
|
||||||
|
if (*cp) cp++;
|
||||||
|
if (!n) fs_fail("BAD FILE NAME");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* SAVE "NAME" start end: memory start..end (inclusive) to a file */
|
||||||
|
static void mem_save(void)
|
||||||
|
{
|
||||||
|
char nm[8];
|
||||||
|
u16 a, e, n;
|
||||||
|
i16 i;
|
||||||
|
get_fname(nm);
|
||||||
|
if (!get_hex(&a) || !get_hex(&e) || e < a) fs_fail("SAVE \"NAME\" START END");
|
||||||
|
n = e - a + 1;
|
||||||
|
if (n > 32768U - 2) fs_fail("FILE TOO BIG");
|
||||||
|
fs_mount();
|
||||||
|
build_bmap();
|
||||||
|
i = find_file(nm);
|
||||||
|
if (i < 0) {
|
||||||
|
for (i = 0; i < MAXFILES && dir.e[i].name[0]; i++);
|
||||||
|
if (i == MAXFILES) fs_fail("TOO MANY FILES");
|
||||||
|
}
|
||||||
|
w_pos = 0;
|
||||||
|
put_b(a); put_b(a >> 8);
|
||||||
|
while (n--) put_b(rd(a++));
|
||||||
|
if (w_pos & 255)
|
||||||
|
fl_prog(blk_addr(w_blk[(w_pos - 1) >> 12]) + ((w_pos - (w_pos & 255)) & 4095), page, w_pos & 255);
|
||||||
|
if (!dir.e[i].name[0] || !(dir.e[i].date[0] | dir.e[i].date[1])) {
|
||||||
|
u32 t = now();
|
||||||
|
dir.e[i].date[0] = t; dir.e[i].date[1] = t >> 16;
|
||||||
|
}
|
||||||
|
memcpy(dir.e[i].name, nm, 8);
|
||||||
|
dir.e[i].len = w_pos;
|
||||||
|
memcpy(dir.e[i].blk, w_blk, sizeof w_blk);
|
||||||
|
fs_commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* LOAD "NAME" [addr]: a memory file back, to its own address or addr */
|
||||||
|
static u16 ld_first, ld_last;
|
||||||
|
static void mem_load(void)
|
||||||
|
{
|
||||||
|
char nm[8];
|
||||||
|
u16 a, pos, len;
|
||||||
|
i16 i;
|
||||||
|
u8 has;
|
||||||
|
get_fname(nm);
|
||||||
|
has = get_hex(&a);
|
||||||
|
fs_mount();
|
||||||
|
i = find_file(nm);
|
||||||
|
if (i < 0) fs_fail("FILE NOT FOUND");
|
||||||
|
len = dir.e[i].len;
|
||||||
|
if (len < 2) fs_fail("NOT A MEMORY FILE");
|
||||||
|
for (pos = 0; pos < len; pos++) {
|
||||||
|
u8 c;
|
||||||
|
if (!(pos & 255))
|
||||||
|
fl_read(blk_addr(dir.e[i].blk[pos >> 12]) + (pos & 4095), page, 256);
|
||||||
|
c = page[pos & 255];
|
||||||
|
if (pos == 0) { if (!has) a = c; }
|
||||||
|
else if (pos == 1) { if (!has) a |= (u16)c << 8; ld_first = a; }
|
||||||
|
else {
|
||||||
|
if (!wr(a, c)) fs_fail("CAN'T LOAD BELOW 8000H");
|
||||||
|
ld_last = a++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* DIR: the files, four to a line, in the memory window */
|
||||||
|
static void mem_dir(void)
|
||||||
|
{
|
||||||
|
u8 i, n = 0, r;
|
||||||
|
fs_mount();
|
||||||
|
for (r = 0; r < MEM_ROWS; r++) { at(MEM_TOP + r, 0); clr_eol(); }
|
||||||
|
for (i = 0; i < MAXFILES && n < MEM_ROWS * 4; i++) {
|
||||||
|
u8 j;
|
||||||
|
if (!dir.e[i].name[0]) continue;
|
||||||
|
lp = line;
|
||||||
|
for (j = 0; j < 8; j++) s_ch(dir.e[i].name[j] ? dir.e[i].name[j] : ' ');
|
||||||
|
s_ch(' '); s_h4(dir.e[i].len); s_ch('H');
|
||||||
|
at(MEM_TOP + n / 4, 1 + (n & 3) * 20); flush_line();
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
if (!n) { at(MEM_TOP, 1); puts_("NO FILES"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------- commands */
|
||||||
|
static u8 op_is_call(u16 a)
|
||||||
|
{
|
||||||
|
u8 op = rd(a);
|
||||||
|
return op == 0xCD || (op & 0xC7) == 0xC4 || (op & 0xC7) == 0xC7;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Leave the monitor. mode: 0 run, 2 one instruction */
|
||||||
|
static void leave(u8 mode)
|
||||||
|
{
|
||||||
|
u.exit = mode;
|
||||||
|
bp0_lo = bp; bp0_hi = bp >> 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u8 set_reg(void)
|
||||||
|
{
|
||||||
|
static const char *const names[] = { "PC", "SP", "AF", "BC", "DE", "HL", "IX", "IY" };
|
||||||
|
u8 i;
|
||||||
|
u16 v;
|
||||||
|
skip_sp();
|
||||||
|
for (i = 0; i < 8; i++)
|
||||||
|
if (cp[0] == names[i][0] && cp[1] == names[i][1]) break;
|
||||||
|
if (i == 8) return 0;
|
||||||
|
cp += 2;
|
||||||
|
skip_sp();
|
||||||
|
if (*cp == '=') cp++;
|
||||||
|
if (!get_hex(&v)) return 0;
|
||||||
|
switch (i) {
|
||||||
|
case 0: return pc_set(v);
|
||||||
|
case 1: { /* move AF and PC down to the new SP */
|
||||||
|
u16 pc = pc_get(), af = af_get();
|
||||||
|
u.sp = v - 4;
|
||||||
|
return pc_set(pc) & af_set(af);
|
||||||
|
}
|
||||||
|
case 2: return af_set(v);
|
||||||
|
case 3: u.bc = v; break;
|
||||||
|
case 4: u.de = v; break;
|
||||||
|
case 5: u.hl = v; break;
|
||||||
|
case 6: u.ix = v; break;
|
||||||
|
default: u.iy = v; break;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Returns 1 when the monitor should be left (u.exit set). */
|
||||||
|
static u8 command(void)
|
||||||
|
{
|
||||||
|
u16 v, a;
|
||||||
|
u8 c;
|
||||||
|
cp = cmd;
|
||||||
|
skip_sp();
|
||||||
|
msg = 0; msg_err = 0;
|
||||||
|
if (!memcmp(cp, "SAVE", 4) || !memcmp(cp, "LOAD", 4) || !memcmp(cp, "DIR", 3)) {
|
||||||
|
c = *cp;
|
||||||
|
cp += c == 'D' ? 3 : 4;
|
||||||
|
if (setjmp(fs_jmp)) { msg = fs_msg; msg_err = 1; return 0; }
|
||||||
|
if (c == 'S') { mem_save(); msg = "SAVED"; }
|
||||||
|
else if (c == 'L') {
|
||||||
|
mem_load();
|
||||||
|
lp = line; s_str("LOADED "); s_h4(ld_first); s_ch('-'); s_h4(ld_last); *lp = 0;
|
||||||
|
strcpy(load_msg, line);
|
||||||
|
msg = load_msg;
|
||||||
|
mem_a = ld_first;
|
||||||
|
draw_mem(); draw_dis();
|
||||||
|
} else { mem_dir(); msg = "M TO SHOW MEMORY AGAIN"; }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
c = *cp;
|
||||||
|
if (c) cp++;
|
||||||
|
switch (c) {
|
||||||
|
case 0: /* Enter: one step */
|
||||||
|
case 'S':
|
||||||
|
steps = get_hex(&v) && v ? v - 1 : 0;
|
||||||
|
leave(2);
|
||||||
|
return 1;
|
||||||
|
case 'O': /* step over a CALL or RST */
|
||||||
|
a = pc_get();
|
||||||
|
if (!op_is_call(a)) { leave(2); return 1; }
|
||||||
|
lp = line;
|
||||||
|
v = a + disasm(a);
|
||||||
|
bp1_lo = v; bp1_hi = v >> 8;
|
||||||
|
bp_ctl = (bp_set && bp != a ? 1 : 0) | 2;
|
||||||
|
leave(0);
|
||||||
|
return 1;
|
||||||
|
case 'G':
|
||||||
|
case 'X':
|
||||||
|
if (get_hex(&v) && !pc_set(v)) { msg = "STACK IS IN ROM"; msg_err = 1; return 0; }
|
||||||
|
if (bp_set && pc_get() == bp) { go_after = 1; leave(2); return 1; }
|
||||||
|
bp_ctl = bp_set;
|
||||||
|
leave(0);
|
||||||
|
return 1;
|
||||||
|
case 'B':
|
||||||
|
if (get_hex(&v)) { bp = v; bp_set = 1; msg = "BREAKPOINT SET"; }
|
||||||
|
else { bp_set = 0; msg = "BREAKPOINT CLEARED"; }
|
||||||
|
draw_dis();
|
||||||
|
return 0;
|
||||||
|
case 'D':
|
||||||
|
if (get_hex(&v)) dis_a = v; else dis_a = pc_get();
|
||||||
|
draw_dis();
|
||||||
|
return 0;
|
||||||
|
case 'M':
|
||||||
|
if (get_hex(&v)) mem_a = v;
|
||||||
|
draw_mem();
|
||||||
|
return 0;
|
||||||
|
case 'E': /* E addr bytes... */
|
||||||
|
if (!get_hex(&a)) { msg = "E ADDR BYTE BYTE ..."; msg_err = 1; return 0; }
|
||||||
|
while (get_hex(&v))
|
||||||
|
if (!wr(a++, v)) { msg = "ROM: NOT CHANGED"; msg_err = 1; break; }
|
||||||
|
draw_all();
|
||||||
|
return 0;
|
||||||
|
case 'R':
|
||||||
|
if (!set_reg()) { msg = "R PC|SP|AF|BC|DE|HL|IX|IY = VALUE"; msg_err = 1; return 0; }
|
||||||
|
draw_regs(); draw_dis(); draw_stack();
|
||||||
|
return 0;
|
||||||
|
case '?':
|
||||||
|
case 'H':
|
||||||
|
msg = "SAVE \"N\" A B LOAD \"N\" [A] DIR";
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
msg = "? TYPE ? FOR HELP"; msg_err = 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Is pc shown in the disassembly window? */
|
||||||
|
static u8 dis_shows(u16 pc)
|
||||||
|
{
|
||||||
|
u16 a = dis_a;
|
||||||
|
u8 r;
|
||||||
|
for (r = 0; r < DIS_ROWS - 2; r++) {
|
||||||
|
if (a == pc) return 1;
|
||||||
|
lp = line;
|
||||||
|
a += disasm(a);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mon_main(void)
|
||||||
|
{
|
||||||
|
u8 why = mon_ctl, k;
|
||||||
|
u16 pc = pc_get();
|
||||||
|
|
||||||
|
bp_ctl = 0; /* no breakpoints inside the monitor */
|
||||||
|
if (go_after && why == 3) { /* stepped off the breakpoint: now go */
|
||||||
|
go_after = 0;
|
||||||
|
bp_ctl = bp_set;
|
||||||
|
leave(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (steps && why == 3) {
|
||||||
|
steps--;
|
||||||
|
leave(2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
steps = 0;
|
||||||
|
go_after = 0;
|
||||||
|
if (!dis_shows(pc)) dis_a = pc;
|
||||||
|
|
||||||
|
puts_("\0337\033[?47h\033[?25l"); /* save the cursor, alternate screen */
|
||||||
|
why_in = why;
|
||||||
|
draw_all();
|
||||||
|
for (;;) {
|
||||||
|
k = read_cmd();
|
||||||
|
if (k == 1) {
|
||||||
|
if (command()) break;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (k == 'U') dis_a--;
|
||||||
|
else if (k == 'N') { lp = line; dis_a += disasm(dis_a); }
|
||||||
|
else if (k == 'P') mem_a -= 16 * MEM_ROWS;
|
||||||
|
else if (k == 'Q') mem_a += 16 * MEM_ROWS;
|
||||||
|
if (k == 'U' || k == 'N') draw_dis(); else draw_mem();
|
||||||
|
}
|
||||||
|
puts_("\033[?25h\033[?47l\0338");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
+32768
File diff suppressed because it is too large.
Load diff
Executable
+80
@@ -0,0 +1,80 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Check the monitor's disassembler: disassemble every opcode form (host build
|
||||||
|
of monitor.c), assemble each line back with sdasz80 and compare the bytes.
|
||||||
|
Undocumented forms sdasz80 doesn't know are listed, not failed.
|
||||||
|
|
||||||
|
monitor/test-disasm.py
|
||||||
|
"""
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
here = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
tmp = tempfile.mkdtemp()
|
||||||
|
exe = os.path.join(tmp, "dis")
|
||||||
|
subprocess.check_call(["gcc", "-O1", "-w", "-o", exe, os.path.join(here, "monitor.c")])
|
||||||
|
lines = subprocess.check_output([exe], text=True).splitlines()
|
||||||
|
|
||||||
|
UNDOC = re.compile(r"IX[HL]|IY[HL]|SLL|NOP\*|\),[A-L]$|IN \(C\)|OUT \(C\),0|^DB |IM 0$")
|
||||||
|
|
||||||
|
|
||||||
|
def to_asx(t):
|
||||||
|
"""Zilog text as printed by the monitor -> sdasz80 syntax."""
|
||||||
|
m = re.match(r"(\S+)\s*(.*)", t)
|
||||||
|
mn, ops = m.group(1), m.group(2)
|
||||||
|
out = []
|
||||||
|
for o in [x for x in ops.split(",")] if ops else []:
|
||||||
|
o = re.sub(r"\b([0-9][0-9A-F]*)H\b", lambda k: "0x" + k.group(1), o)
|
||||||
|
im = re.match(r"\((I[XY])([+-])(0x[0-9A-F]+)\)$", o)
|
||||||
|
if im:
|
||||||
|
o = ("-" if im.group(2) == "-" else "") + im.group(3) + "(" + im.group(1) + ")"
|
||||||
|
elif re.match(r"0x[0-9A-F]+$", o) and mn in ("JR", "DJNZ"):
|
||||||
|
o = ".+" + o # sdasz80 takes a bare number as the offset
|
||||||
|
elif re.match(r"0x[0-9A-F]+$", o) and mn not in ("JP", "CALL", "RST"):
|
||||||
|
o = "#" + o
|
||||||
|
out.append(o)
|
||||||
|
return (mn + " " + ",".join(out)).lower()
|
||||||
|
|
||||||
|
|
||||||
|
def alias(hexb, text):
|
||||||
|
"""Undocumented duplicates, shown as the documented instruction."""
|
||||||
|
if hexb[:2] in ("DD", "FD") and hexb[2:4] != "CB" and "IX" not in text and "IY" not in text:
|
||||||
|
return True # prefix with no effect
|
||||||
|
if hexb[:2] == "ED" and hexb[2:4] in ("4C 54 5C 64 6C 74 7C 55 5D 65 6D 75 7D "
|
||||||
|
"4E 66 6E 76 7E 63 6B").split():
|
||||||
|
return True
|
||||||
|
if hexb[2:4] == "CB" and text.startswith("BIT") and int(hexb[6:8], 16) & 7 != 6:
|
||||||
|
return True # DDCB BIT with a register field
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
ok = bad = skipped = aliases = 0
|
||||||
|
for ln in lines:
|
||||||
|
hexb, text = ln.split("\t")
|
||||||
|
if UNDOC.search(text):
|
||||||
|
skipped += 1
|
||||||
|
continue
|
||||||
|
src = os.path.join(tmp, "t.s")
|
||||||
|
with open(src, "w") as f:
|
||||||
|
f.write("\t.area\tA (ABS)\n\t.org\t0\n\t%s\n" % to_asx(text))
|
||||||
|
r = subprocess.run(["sdasz80", "-l", "-o", src], capture_output=True, text=True)
|
||||||
|
got = ""
|
||||||
|
lst = src[:-2] + ".lst"
|
||||||
|
if r.returncode == 0 and os.path.exists(lst):
|
||||||
|
for l in open(lst):
|
||||||
|
m = re.match(r"\s+0+\s+((?:[0-9A-F]{2}\s)+)", l)
|
||||||
|
if m:
|
||||||
|
got = m.group(1).replace(" ", "")
|
||||||
|
if got.upper() == hexb[:len(got)].upper() and got and len(got) == len(hexb):
|
||||||
|
ok += 1
|
||||||
|
elif got and alias(hexb, text):
|
||||||
|
aliases += 1
|
||||||
|
else:
|
||||||
|
bad += 1
|
||||||
|
print("MISMATCH %-10s %-24s asm %-22s -> %s %s" % (hexb, text, to_asx(text), got or "error",
|
||||||
|
r.stderr.strip()[:60]))
|
||||||
|
print("%d match, %d undocumented duplicates shown as the documented form, %d mismatch, "
|
||||||
|
"%d undocumented forms sdasz80 can't assemble" % (ok, aliases, bad, skipped))
|
||||||
|
sys.exit(1 if bad else 0)
|
||||||
+26
-11
@@ -5,7 +5,7 @@
|
|||||||
// UART RX -> 80x30 colour text on VGA
|
// UART RX -> 80x30 colour text on VGA
|
||||||
// SW15 up: the terminal is the Z-80's console
|
// SW15 up: the terminal is the Z-80's console
|
||||||
//
|
//
|
||||||
// SW1:0 baud rate: 00 115200, 01 9600, 10 19200, 11 57600 (8N1)
|
// SW1:0 baud rate: 00 115200, 01 9600, 10 921600, 11 3000000 (8N1)
|
||||||
// SW2 local echo
|
// SW2 local echo
|
||||||
// SW3 received LF also does CR
|
// SW3 received LF also does CR
|
||||||
// SW5:4 default text colour: 00 green, 01 yellow, 10 white, 11 cyan
|
// SW5:4 default text colour: 00 green, 01 yellow, 10 white, 11 cyan
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
module basys3_terminal #(
|
module basys3_terminal #(
|
||||||
parameter FONT_FILE = "font.mem",
|
parameter FONT_FILE = "font.mem",
|
||||||
parameter MEM_FILE = "basic.mem",
|
parameter MEM_FILE = "basic.mem",
|
||||||
|
parameter MON_FILE = "monitor.mem",
|
||||||
parameter CLK_HZ = 100_000_000,
|
parameter CLK_HZ = 100_000_000,
|
||||||
parameter real CPU_MULT = 9.0, // Z-80 clock = 100 MHz * CPU_MULT / CPU_DIV
|
parameter real CPU_MULT = 9.0, // Z-80 clock = 100 MHz * CPU_MULT / CPU_DIV
|
||||||
parameter real CPU_DIV = 10.0,
|
parameter real CPU_DIV = 10.0,
|
||||||
@@ -82,8 +83,8 @@ module basys3_terminal #(
|
|||||||
case (sw_r[1:0])
|
case (sw_r[1:0])
|
||||||
2'b00: baud_div <= CLK_HZ / 115200;
|
2'b00: baud_div <= CLK_HZ / 115200;
|
||||||
2'b01: baud_div <= CLK_HZ / 9600;
|
2'b01: baud_div <= CLK_HZ / 9600;
|
||||||
2'b10: baud_div <= CLK_HZ / 19200;
|
2'b10: baud_div <= CLK_HZ / 921600; // 108: 0.5% fast
|
||||||
2'b11: baud_div <= CLK_HZ / 57600;
|
2'b11: baud_div <= CLK_HZ / 3000000; // 33: 1% fast
|
||||||
endcase
|
endcase
|
||||||
|
|
||||||
reg [3:0] def_fg;
|
reg [3:0] def_fg;
|
||||||
@@ -108,13 +109,18 @@ module basys3_terminal #(
|
|||||||
.code(scan), .valid(scan_valid)
|
.code(scan), .valid(scan_valid)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
wire cad;
|
||||||
ps2_keymap kbd_map (
|
ps2_keymap kbd_map (
|
||||||
.clk(clk), .rst(rst), .code(scan), .code_valid(scan_valid),
|
.clk(clk), .rst(rst), .code(scan), .code_valid(scan_valid),
|
||||||
.bs_del(sw_r[6]), .enter_crlf(sw_r[7] | lnm),
|
.bs_del(sw_r[6]), .enter_crlf(sw_r[7] | lnm),
|
||||||
.cursor_app(cursor_app), .keypad_app(keypad_app),
|
.cursor_app(cursor_app), .keypad_app(keypad_app),
|
||||||
.ascii(key), .ascii_valid(key_valid), .caps(caps)
|
.ascii(key), .ascii_valid(key_valid), .caps(caps), .cad(cad)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Ctrl-Alt-Del in Z-80 mode restarts the Z-80, like BTND (held 1 us)
|
||||||
|
reg [6:0] cad_t = 7'd0;
|
||||||
|
always @(posedge clk) cad_t <= cad && z80_mode ? 7'd100 : cad_t - (cad_t != 0);
|
||||||
|
|
||||||
// ----------------------------------------------------------- host input
|
// ----------------------------------------------------------- host input
|
||||||
// Keyboard bytes and terminal replies go to the host: the PC's UART, or in
|
// Keyboard bytes and terminal replies go to the host: the PC's UART, or in
|
||||||
// Z-80 mode the Z-80's input FIFO. The keyboard/reply choice sticks until
|
// Z-80 mode the Z-80's input FIFO. The keyboard/reply choice sticks until
|
||||||
@@ -259,7 +265,7 @@ module basys3_terminal #(
|
|||||||
`endif
|
`endif
|
||||||
|
|
||||||
(* ASYNC_REG = "TRUE" *) reg [2:0] cpu_rst_s;
|
(* ASYNC_REG = "TRUE" *) reg [2:0] cpu_rst_s;
|
||||||
always @(posedge cpu_clk) cpu_rst_s <= {cpu_rst_s[1:0], rst | zrst_sync[1] | !locked};
|
always @(posedge cpu_clk) cpu_rst_s <= {cpu_rst_s[1:0], rst | zrst_sync[1] | (cad_t != 0) | !locked};
|
||||||
|
|
||||||
// Z-80 input: one byte at a time from z80_in_fifo
|
// Z-80 input: one byte at a time from z80_in_fifo
|
||||||
reg zrx_req, zrx_pend;
|
reg zrx_req, zrx_pend;
|
||||||
@@ -293,11 +299,18 @@ module basys3_terminal #(
|
|||||||
wire [16:0] gfx_addr;
|
wire [16:0] gfx_addr;
|
||||||
wire [3:0] gfx_pix;
|
wire [3:0] gfx_pix;
|
||||||
|
|
||||||
z80_system #(.MEM_FILE(MEM_FILE), .CPU_HZ(CPU_HZ)) z80 (
|
// The Pause key (its scan codes start E1, used by nothing else) enters the
|
||||||
|
// Z-80 monitor: a toggle crosses to the CPU clock.
|
||||||
|
reg brk_t = 1'b0;
|
||||||
|
always @(posedge clk) if (scan_valid && scan == 8'hE1 && z80_mode) brk_t <= ~brk_t;
|
||||||
|
(* ASYNC_REG = "TRUE" *) reg [2:0] brk_s = 3'd0;
|
||||||
|
always @(posedge cpu_clk) brk_s <= {brk_s[1:0], brk_t};
|
||||||
|
|
||||||
|
z80_system #(.MEM_FILE(MEM_FILE), .MON_FILE(MON_FILE), .CPU_HZ(CPU_HZ)) z80 (
|
||||||
.clk(cpu_clk), .rst(cpu_rst_s[2]),
|
.clk(cpu_clk), .rst(cpu_rst_s[2]),
|
||||||
.rx_req(zrx_req), .rx_data(zrx_data), .rx_ack(zrx_ack),
|
.rx_req(zrx_req), .rx_data(zrx_data), .rx_ack(zrx_ack),
|
||||||
.tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack),
|
.tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack),
|
||||||
.seg_val(z80_seg), .halted(),
|
.seg_val(z80_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]),
|
||||||
.vclk(clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
.vclk(clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
||||||
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1])
|
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1])
|
||||||
);
|
);
|
||||||
@@ -367,6 +380,7 @@ module basys3_terminal #(
|
|||||||
|
|
||||||
// ------------------------------------------------------------- terminal
|
// ------------------------------------------------------------- terminal
|
||||||
wire [11:0] t_addr;
|
wire [11:0] t_addr;
|
||||||
|
wire alt_scr;
|
||||||
wire t_we;
|
wire t_we;
|
||||||
wire [17:0] t_wdata, t_rdata;
|
wire [17:0] t_wdata, t_rdata;
|
||||||
wire [4:0] cur_row, stop, sbot, sm_off;
|
wire [4:0] cur_row, stop, sbot, sm_off;
|
||||||
@@ -385,22 +399,23 @@ module basys3_terminal #(
|
|||||||
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
|
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
|
||||||
.resp_byte(resp_byte), .resp_wr(resp_wr), .resp_full(rq_full),
|
.resp_byte(resp_byte), .resp_wr(resp_wr), .resp_full(rq_full),
|
||||||
.cursor_app(cursor_app), .keypad_app(keypad_app), .lnm(lnm),
|
.cursor_app(cursor_app), .keypad_app(keypad_app), .lnm(lnm),
|
||||||
.dec_leds(dec_leds), .bell(bell)
|
.dec_leds(dec_leds), .bell(bell), .alt_scr(alt_scr)
|
||||||
);
|
);
|
||||||
|
|
||||||
wire [11:0] v_addr;
|
wire [11:0] v_addr;
|
||||||
wire [17:0] v_data;
|
wire [17:0] v_data;
|
||||||
|
|
||||||
|
// the alternate screen (the Z-80 monitor uses it) has no graphics layer
|
||||||
char_ram screen (
|
char_ram screen (
|
||||||
.clk(clk),
|
.clk(clk),
|
||||||
.a_addr(t_addr), .a_we(t_we), .a_wdata(t_wdata), .a_rdata(t_rdata),
|
.a_addr({alt_scr, t_addr}), .a_we(t_we), .a_wdata(t_wdata), .a_rdata(t_rdata),
|
||||||
.b_addr(v_addr), .b_rdata(v_data)
|
.b_addr({alt_scr, v_addr}), .b_rdata(v_data)
|
||||||
);
|
);
|
||||||
|
|
||||||
text_display #(.FONT_FILE(FONT_FILE)) video (
|
text_display #(.FONT_FILE(FONT_FILE)) video (
|
||||||
.clk(clk), .rst(rst), .cur_row(cur_row), .cur_col(cur_col), .cur_vis(cur_vis),
|
.clk(clk), .rst(rst), .cur_row(cur_row), .cur_col(cur_col), .cur_vis(cur_vis),
|
||||||
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
|
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
|
||||||
.ram_addr(v_addr), .ram_data(v_data), .gfx_addr(gfx_addr), .gfx_pix(gfx_pix),
|
.ram_addr(v_addr), .ram_data(v_data), .gfx_addr(gfx_addr), .gfx_pix(alt_scr ? 4'd0 : gfx_pix),
|
||||||
.red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .hsync(Hsync), .vsync(Vsync),
|
.red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .hsync(Hsync), .vsync(Vsync),
|
||||||
.frame_tick(frame_tick)
|
.frame_tick(frame_tick)
|
||||||
);
|
);
|
||||||
|
|||||||
+4
-1
@@ -76,7 +76,8 @@ module ps2_keymap (
|
|||||||
input keypad_app, // DECKPAM
|
input keypad_app, // DECKPAM
|
||||||
output reg [7:0] ascii,
|
output reg [7:0] ascii,
|
||||||
output reg ascii_valid,
|
output reg ascii_valid,
|
||||||
output reg caps
|
output reg caps,
|
||||||
|
output reg cad // Ctrl-Alt-Del was pressed (one clock)
|
||||||
);
|
);
|
||||||
localparam [7:0] ESC = 8'h1B;
|
localparam [7:0] ESC = 8'h1B;
|
||||||
|
|
||||||
@@ -189,6 +190,7 @@ module ps2_keymap (
|
|||||||
|
|
||||||
always @(posedge clk) begin
|
always @(posedge clk) begin
|
||||||
ascii_valid <= 1'b0;
|
ascii_valid <= 1'b0;
|
||||||
|
cad <= 1'b0;
|
||||||
if (rst) begin
|
if (rst) begin
|
||||||
{e0, f0, lsh, rsh, lct, rct, alt, caps} <= 8'd0;
|
{e0, f0, lsh, rsh, lct, rct, alt, caps} <= 8'd0;
|
||||||
skip <= 3'd0;
|
skip <= 3'd0;
|
||||||
@@ -212,6 +214,7 @@ module ps2_keymap (
|
|||||||
else begin
|
else begin
|
||||||
e0 <= 1'b0;
|
e0 <= 1'b0;
|
||||||
f0 <= 1'b0;
|
f0 <= 1'b0;
|
||||||
|
cad <= !f0 && code == 8'h71 && (lct || rct) && alt; // Delete or keypad .
|
||||||
if (code == 8'h12 && !e0) lsh <= !f0; // E0 12 / E0 59 are fake shifts
|
if (code == 8'h12 && !e0) lsh <= !f0; // E0 12 / E0 59 are fake shifts
|
||||||
else if (code == 8'h59 && !e0) rsh <= !f0;
|
else if (code == 8'h59 && !e0) rsh <= !f0;
|
||||||
else if (code == 8'h14) begin
|
else if (code == 8'h14) begin
|
||||||
|
|||||||
+5
-1
@@ -11,6 +11,7 @@
|
|||||||
// CSI A B C D E F G H I J K L M P S T X Z @ ` a d e f g h l m n q r s u c
|
// CSI A B C D E F G H I J K L M P S T X Z @ ` a d e f g h l m n q r s u c
|
||||||
// CSI ? J K h l n CSI > c CSI ! p
|
// CSI ? J K h l n CSI > c CSI ! p
|
||||||
// Modes: IRM(4) LNM(20) DECCKM(?1) DECSCLM(?4) DECOM(?6) DECAWM(?7) DECTCEM(?25)
|
// Modes: IRM(4) LNM(20) DECCKM(?1) DECSCLM(?4) DECOM(?6) DECAWM(?7) DECTCEM(?25)
|
||||||
|
// alternate screen ?47 (parameters stop at 255, so not ?1047/?1049)
|
||||||
// SGR 0 1 4 5 7 8 21-28 30-49 90-107, 38/48;5;n and 38/48;2;r;g;b (approximated)
|
// SGR 0 1 4 5 7 8 21-28 30-49 90-107, 38/48;5;n and 38/48;2;r;g;b (approximated)
|
||||||
// DECLL (CSI n q) drives four LEDs.
|
// DECLL (CSI n q) drives four LEDs.
|
||||||
// OSC, DCS, APC, PM and SOS strings (e.g. titles, OSC 3008) are discarded.
|
// OSC, DCS, APC, PM and SOS strings (e.g. titles, OSC 3008) are discarded.
|
||||||
@@ -52,7 +53,8 @@ module term_ctrl (
|
|||||||
output reg keypad_app,
|
output reg keypad_app,
|
||||||
output reg lnm,
|
output reg lnm,
|
||||||
output reg [3:0] dec_leds,
|
output reg [3:0] dec_leds,
|
||||||
output reg bell
|
output reg bell,
|
||||||
|
output reg alt_scr // showing and writing the alternate screen
|
||||||
);
|
);
|
||||||
localparam [4:0] LAST_ROW = 5'd29;
|
localparam [4:0] LAST_ROW = 5'd29;
|
||||||
localparam [6:0] LAST_COL = 7'd79;
|
localparam [6:0] LAST_COL = 7'd79;
|
||||||
@@ -319,6 +321,7 @@ module term_ctrl (
|
|||||||
{g0, g1} <= 4'b0;
|
{g0, g1} <= 4'b0;
|
||||||
awm <= 1'b1;
|
awm <= 1'b1;
|
||||||
cur_vis <= 1'b1;
|
cur_vis <= 1'b1;
|
||||||
|
alt_scr <= 1'b0;
|
||||||
stop <= 5'd0;
|
stop <= 5'd0;
|
||||||
sbot <= LAST_ROW;
|
sbot <= LAST_ROW;
|
||||||
{sv_row, sv_col, sv_pend, sv_om, sv_gl, sv_bold, sv_ul, sv_blink, sv_rev, sv_conceal} <= 0;
|
{sv_row, sv_col, sv_pend, sv_om, sv_gl, sv_bold, sv_ul, sv_blink, sv_rev, sv_conceal} <= 0;
|
||||||
@@ -415,6 +418,7 @@ module term_ctrl (
|
|||||||
if (v == 6) begin om <= on; row <= on ? stop : 5'd0; col <= 7'd0; pend <= 1'b0; end
|
if (v == 6) begin om <= on; row <= on ? stop : 5'd0; col <= 7'd0; pend <= 1'b0; end
|
||||||
if (v == 7) awm <= on;
|
if (v == 7) awm <= on;
|
||||||
if (v == 25) cur_vis <= on;
|
if (v == 25) cur_vis <= on;
|
||||||
|
if (v == 47) alt_scr <= on;
|
||||||
end else begin
|
end else begin
|
||||||
if (v == 4) irm <= on;
|
if (v == 4) irm <= on;
|
||||||
if (v == 20) lnm <= on;
|
if (v == 20) lnm <= on;
|
||||||
|
|||||||
+6
-5
@@ -115,20 +115,21 @@ module text_display #(
|
|||||||
end
|
end
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
// 2400-cell character buffer: read/write port for the terminal engine,
|
// Two 2400-cell character buffers (the normal and the alternate screen; the
|
||||||
|
// top address bit picks one): read/write port for the terminal engine,
|
||||||
// read-only port for video.
|
// read-only port for video.
|
||||||
module char_ram (
|
module char_ram (
|
||||||
input clk,
|
input clk,
|
||||||
input [11:0] a_addr,
|
input [12:0] a_addr,
|
||||||
input a_we,
|
input a_we,
|
||||||
input [17:0] a_wdata,
|
input [17:0] a_wdata,
|
||||||
output reg [17:0] a_rdata,
|
output reg [17:0] a_rdata,
|
||||||
input [11:0] b_addr,
|
input [12:0] b_addr,
|
||||||
output reg [17:0] b_rdata
|
output reg [17:0] b_rdata
|
||||||
);
|
);
|
||||||
(* ram_style = "block" *) reg [17:0] mem [0:4095];
|
(* ram_style = "block" *) reg [17:0] mem [0:8191];
|
||||||
integer i;
|
integer i;
|
||||||
initial for (i = 0; i < 4096; i = i + 1) mem[i] = {10'h00A, 8'h20};
|
initial for (i = 0; i < 8192; i = i + 1) mem[i] = {10'h00A, 8'h20};
|
||||||
|
|
||||||
always @(posedge clk) begin
|
always @(posedge clk) begin
|
||||||
if (a_we) mem[a_addr] <= a_wdata;
|
if (a_we) mem[a_addr] <= a_wdata;
|
||||||
|
|||||||
+23
-5
@@ -11,8 +11,11 @@
|
|||||||
//
|
//
|
||||||
// The full documented instruction set is implemented, plus the undocumented
|
// The full documented instruction set is implemented, plus the undocumented
|
||||||
// IXH/IXL/IYH/IYL forms, SLL and the DDCB register copies. Block instructions
|
// IXH/IXL/IYH/IYL forms, SLL and the DDCB register copies. Block instructions
|
||||||
// loop internally (LDIR moves a byte every 3 clocks). There are no interrupts:
|
// loop internally (LDIR moves a byte every 3 clocks). The only interrupt is a
|
||||||
// EI/DI/IM only set their registers, and HALT stops the CPU until reset.
|
// non-maskable one for the monitor: a pulse on `nmi` is taken at the next
|
||||||
|
// instruction start from that clock on (or in HALT), `nmi_now` at this one. It
|
||||||
|
// pushes the address of the instruction not yet run, jumps to 0066h and clears
|
||||||
|
// IFF1 (RETN copies IFF2 back). EI/DI/IM only set their registers.
|
||||||
module z80_cpu (
|
module z80_cpu (
|
||||||
input clk,
|
input clk,
|
||||||
input rst,
|
input rst,
|
||||||
@@ -28,6 +31,8 @@ module z80_cpu (
|
|||||||
output reg [7:0] io_wd,
|
output reg [7:0] io_wd,
|
||||||
input [7:0] io_din,
|
input [7:0] io_din,
|
||||||
output halted,
|
output halted,
|
||||||
|
input nmi, // pulse: take at the next instruction start
|
||||||
|
input nmi_now, // level: take at this instruction start
|
||||||
// debug: ins_start is high on the first clock of each instruction
|
// debug: ins_start is high on the first clock of each instruction
|
||||||
output ins_start,
|
output ins_start,
|
||||||
output [15:0] dbg_pc,
|
output [15:0] dbg_pc,
|
||||||
@@ -70,12 +75,14 @@ module z80_cpu (
|
|||||||
reg take;
|
reg take;
|
||||||
reg [15:0] ea, tmp;
|
reg [15:0] ea, tmp;
|
||||||
reg [7:0] tlo;
|
reg [7:0] tlo;
|
||||||
|
reg nmi_p; // NMI waiting
|
||||||
|
|
||||||
wire [15:0] BC = {rB, rC}, DE = {rD, rE}, HL = {rH, rL};
|
wire [15:0] BC = {rB, rC}, DE = {rD, rE}, HL = {rH, rL};
|
||||||
|
|
||||||
assign halted = st == S_HALT;
|
assign halted = st == S_HALT;
|
||||||
assign ins_start = st == S_D && xm == 2'd0;
|
assign ins_start = st == S_D && xm == 2'd0;
|
||||||
assign dbg_pc = PC - 1'b1;
|
assign dbg_pc = PC - 1'b1;
|
||||||
|
wire take_nmi = xm == 2'd0 && (nmi_p || nmi || nmi_now);
|
||||||
assign dbg_af = {rA, rF}; assign dbg_bc = BC; assign dbg_de = DE;
|
assign dbg_af = {rA, rF}; assign dbg_bc = BC; assign dbg_de = DE;
|
||||||
assign dbg_hl = HL; assign dbg_ix = IX; assign dbg_iy = IY; assign dbg_sp = SP;
|
assign dbg_hl = HL; assign dbg_ix = IX; assign dbg_iy = IY; assign dbg_sp = SP;
|
||||||
|
|
||||||
@@ -317,6 +324,7 @@ module z80_cpu (
|
|||||||
io_wr <= 1'b0;
|
io_wr <= 1'b0;
|
||||||
pd <= 1'b0;
|
pd <= 1'b0;
|
||||||
if (pd) nxt <= din;
|
if (pd) nxt <= din;
|
||||||
|
if (nmi) nmi_p <= 1'b1;
|
||||||
|
|
||||||
if (rst) begin
|
if (rst) begin
|
||||||
st <= S_F; ma <= 16'h0000; PC <= 16'h0000;
|
st <= S_F; ma <= 16'h0000; PC <= 16'h0000;
|
||||||
@@ -325,12 +333,17 @@ module z80_cpu (
|
|||||||
{aA, aF, aB, aC, aD, aE, aH, aL} <= 64'd0;
|
{aA, aF, aB, aC, aD, aE, aH, aL} <= 64'd0;
|
||||||
IX <= 16'hFFFF; IY <= 16'hFFFF;
|
IX <= 16'hFFFF; IY <= 16'hFFFF;
|
||||||
rI <= 8'h00; rR <= 8'h00; iff1 <= 1'b0; iff2 <= 1'b0; im <= 2'd0;
|
rI <= 8'h00; rR <= 8'h00; iff1 <= 1'b0; iff2 <= 1'b0; im <= 2'd0;
|
||||||
xm <= 2'd0; un <= 1'b0; rsm <= 1'b0; nbad <= 1'b0;
|
xm <= 2'd0; un <= 1'b0; rsm <= 1'b0; nbad <= 1'b0; nmi_p <= 1'b0;
|
||||||
end else case (st)
|
end else case (st)
|
||||||
S_F: next_stream;
|
S_F: next_stream;
|
||||||
|
|
||||||
// ------------------------------------------------------ main opcodes
|
// ------------------------------------------------------ main opcodes
|
||||||
S_D: begin
|
S_D: if (take_nmi) begin // NMI: like RST 66h, before this opcode
|
||||||
|
tmp <= dbg_pc; ea <= 16'h0066;
|
||||||
|
SP <= SP - 1'b1; wr(SP - 1'b1, dbg_pc[15:8]);
|
||||||
|
iff2 <= iff1; iff1 <= 1'b0; nmi_p <= 1'b0;
|
||||||
|
ic <= I_CALL; st <= S_W1;
|
||||||
|
end else begin
|
||||||
op = un ? nxt : din;
|
op = un ? nxt : din;
|
||||||
x = op[7:6]; y = op[5:3]; z = op[2:0]; p = op[5:4]; q = op[3];
|
x = op[7:6]; y = op[5:3]; z = op[2:0]; p = op[5:4]; q = op[3];
|
||||||
rR <= {rR[7], rR[6:0] + 7'd1};
|
rR <= {rR[7], rR[6:0] + 7'd1};
|
||||||
@@ -716,7 +729,12 @@ module z80_cpu (
|
|||||||
st <= S_W;
|
st <= S_W;
|
||||||
end
|
end
|
||||||
|
|
||||||
S_HALT: ;
|
S_HALT: if (nmi_p || nmi) begin // NMI wakes HALT, returning after it
|
||||||
|
tmp <= dbg_pc; ea <= 16'h0066;
|
||||||
|
SP <= SP - 1'b1; wr(SP - 1'b1, dbg_pc[15:8]);
|
||||||
|
iff2 <= iff1; iff1 <= 1'b0; nmi_p <= 1'b0;
|
||||||
|
ic <= I_CALL; st <= S_W1;
|
||||||
|
end
|
||||||
default: st <= S_F;
|
default: st <= S_F;
|
||||||
endcase
|
endcase
|
||||||
end
|
end
|
||||||
|
|||||||
+97
-5
@@ -13,11 +13,29 @@
|
|||||||
// 33 out plot colour at (X,Y), then X+1 in colour at (X,Y)
|
// 33 out plot colour at (X,Y), then X+1 in colour at (X,Y)
|
||||||
// 34 out fill the whole graphics screen in bit 0 = fill busy
|
// 34 out fill the whole graphics screen in bit 0 = fill busy
|
||||||
// 40 SPI flash control, 41 SPI flash data (see flash_spi.v)
|
// 40 SPI flash control, 41 SPI flash data (see flash_spi.v)
|
||||||
|
// 60 out bit 0 = monitor bank in; bit 1 (with bit 0 = 0) = stop again after
|
||||||
|
// one instruction of the program
|
||||||
|
// in why the monitor was entered: 1 Pause key, 2 port 61, 3 step,
|
||||||
|
// 4 breakpoint 0, 5 breakpoint 1
|
||||||
|
// 61 out enter the monitor (NMI)
|
||||||
|
// 62 out debug address low 63 out debug address high
|
||||||
|
// 64 in main-memory byte at the debug address, then address + 1
|
||||||
|
// 65 out breakpoint 0 low 66 high 68 out breakpoint 1 low 69 high
|
||||||
|
// 67 out bit 0 = breakpoint 0 on, bit 1 = breakpoint 1 on
|
||||||
|
//
|
||||||
|
// The monitor: an NMI (Pause key, port 61, a breakpoint or the step counter)
|
||||||
|
// pushes the program's PC and jumps to 0066h, where both BASIC and the monitor
|
||||||
|
// ROM hold the same few bytes: they switch the monitor bank in, which replaces
|
||||||
|
// 0000-7FFF with the monitor's ROM (0000-6FFF) and RAM (7000-7FFF), and leave
|
||||||
|
// through 0070h, which switches it out again and returns. No NMI is taken while
|
||||||
|
// the bank is in, or between the request and the bank coming in.
|
||||||
//
|
//
|
||||||
// Graphics are 320x240 in 16 colours (0 = transparent), shown over the text.
|
// Graphics are 320x240 in 16 colours (0 = transparent), shown over the text.
|
||||||
// Writes below ROM_TOP are ignored so a crashed program cannot damage BASIC.
|
// Writes below ROM_TOP are ignored so a crashed program cannot damage BASIC.
|
||||||
module z80_system #(
|
module z80_system #(
|
||||||
parameter MEM_FILE = "basic.mem",
|
parameter MEM_FILE = "basic.mem",
|
||||||
|
parameter MON_FILE = "monitor.mem",
|
||||||
|
parameter MON_RAM = 16'h7000,
|
||||||
parameter CPU_HZ = 100_000_000,
|
parameter CPU_HZ = 100_000_000,
|
||||||
parameter ROM_TOP = 16'h8000
|
parameter ROM_TOP = 16'h8000
|
||||||
) (
|
) (
|
||||||
@@ -33,6 +51,7 @@ module z80_system #(
|
|||||||
input tx_ack,
|
input tx_ack,
|
||||||
output reg [15:0] seg_val,
|
output reg [15:0] seg_val,
|
||||||
output halted,
|
output halted,
|
||||||
|
input brk_key, // pulse: the Pause key, enter the monitor
|
||||||
// graphics layer read port, on the video clock
|
// graphics layer read port, on the video clock
|
||||||
input vclk,
|
input vclk,
|
||||||
input [16:0] gfx_vaddr,
|
input [16:0] gfx_vaddr,
|
||||||
@@ -43,25 +62,40 @@ module z80_system #(
|
|||||||
output fl_mosi,
|
output fl_mosi,
|
||||||
input fl_miso
|
input fl_miso
|
||||||
);
|
);
|
||||||
wire [15:0] ma, io_addr;
|
wire [15:0] ma, io_addr, pc_dbg;
|
||||||
wire we, io_rd, io_wr;
|
wire we, io_rd, io_wr, ins_start;
|
||||||
|
wire nmi, nmi_now;
|
||||||
wire [7:0] wd, io_wd;
|
wire [7:0] wd, io_wd;
|
||||||
reg [7:0] din, io_din;
|
reg [7:0] din, io_din;
|
||||||
|
|
||||||
z80_cpu cpu (
|
z80_cpu cpu (
|
||||||
.clk(clk), .rst(rst), .ma(ma), .we(we), .wd(wd), .din(din),
|
.clk(clk), .rst(rst), .ma(ma), .we(we), .wd(wd), .din(din),
|
||||||
.io_addr(io_addr), .io_rd(io_rd), .io_wr(io_wr), .io_wd(io_wd), .io_din(io_din),
|
.io_addr(io_addr), .io_rd(io_rd), .io_wr(io_wr), .io_wd(io_wd), .io_din(io_din),
|
||||||
.halted(halted), .ins_start(), .dbg_pc(),
|
.halted(halted), .nmi(nmi), .nmi_now(nmi_now), .ins_start(ins_start), .dbg_pc(pc_dbg),
|
||||||
.dbg_af(), .dbg_bc(), .dbg_de(), .dbg_hl(), .dbg_ix(), .dbg_iy(), .dbg_sp()
|
.dbg_af(), .dbg_bc(), .dbg_de(), .dbg_hl(), .dbg_ix(), .dbg_iy(), .dbg_sp()
|
||||||
);
|
);
|
||||||
|
|
||||||
reg [7:0] ram [0:65535];
|
reg [7:0] ram [0:65535];
|
||||||
initial $readmemh(MEM_FILE, ram);
|
initial $readmemh(MEM_FILE, ram);
|
||||||
|
reg [7:0] ram_q, mon_q, dbg_q;
|
||||||
|
reg [15:0] dbg_a;
|
||||||
|
reg mon, sel_mon;
|
||||||
always @(posedge clk) begin
|
always @(posedge clk) begin
|
||||||
if (we && ma >= ROM_TOP) ram[ma] <= wd;
|
if (we && ma >= ROM_TOP && !(mon && !ma[15])) ram[ma] <= wd;
|
||||||
din <= ram[ma];
|
ram_q <= ram[ma];
|
||||||
|
dbg_q <= ram[dbg_a];
|
||||||
end
|
end
|
||||||
|
|
||||||
|
// the monitor bank, 0000-7FFF while mon is set
|
||||||
|
(* ram_style = "block" *) reg [7:0] mrom [0:32767];
|
||||||
|
initial $readmemh(MON_FILE, mrom);
|
||||||
|
always @(posedge clk) begin
|
||||||
|
if (we && mon && !ma[15] && ma >= MON_RAM) mrom[ma[14:0]] <= wd;
|
||||||
|
mon_q <= mrom[ma[14:0]];
|
||||||
|
sel_mon <= mon && !ma[15];
|
||||||
|
end
|
||||||
|
always @* din = sel_mon ? mon_q : ram_q;
|
||||||
|
|
||||||
// ------------------------------------------------------------- console
|
// ------------------------------------------------------------- console
|
||||||
(* ASYNC_REG = "TRUE" *) reg [1:0] rx_req_s, tx_ack_s;
|
(* ASYNC_REG = "TRUE" *) reg [1:0] rx_req_s, tx_ack_s;
|
||||||
always @(posedge clk) begin
|
always @(posedge clk) begin
|
||||||
@@ -132,6 +166,62 @@ module z80_system #(
|
|||||||
end else
|
end else
|
||||||
ms_div <= ms_div + 1'b1;
|
ms_div <= ms_div + 1'b1;
|
||||||
|
|
||||||
|
// ------------------------------------------------------------- monitor
|
||||||
|
reg [15:0] bp0, bp1; // breakpoint addresses
|
||||||
|
reg [1:0] bp_on;
|
||||||
|
reg [2:0] why;
|
||||||
|
reg nmi_busy, step_arm, nmi_r, io_rd_d;
|
||||||
|
reg [1:0] step_n;
|
||||||
|
wire can_nmi = !mon && !nmi_busy;
|
||||||
|
wire hit0 = bp_on[0] && pc_dbg == bp0;
|
||||||
|
wire hit1 = bp_on[1] && pc_dbg == bp1;
|
||||||
|
assign nmi_now = can_nmi && ins_start && (hit0 || hit1);
|
||||||
|
assign nmi = nmi_r;
|
||||||
|
|
||||||
|
always @(posedge clk) begin
|
||||||
|
nmi_r <= 1'b0;
|
||||||
|
io_rd_d <= io_rd && io_addr[7:0] == 8'h64;
|
||||||
|
if (io_rd_d) dbg_a <= dbg_a + 1'b1;
|
||||||
|
if (rst) begin
|
||||||
|
mon <= 1'b0; nmi_busy <= 1'b0; step_arm <= 1'b0; bp_on <= 2'b00; why <= 3'd0;
|
||||||
|
end else begin
|
||||||
|
if (io_wr) case (io_addr[7:0])
|
||||||
|
8'h60: begin
|
||||||
|
mon <= io_wd[0];
|
||||||
|
if (io_wd[0]) nmi_busy <= 1'b0;
|
||||||
|
step_arm <= !io_wd[0] && io_wd[1];
|
||||||
|
step_n <= ins_start ? 2'd1 : 2'd0; // POP AF may start on this clock
|
||||||
|
end
|
||||||
|
8'h62: dbg_a[7:0] <= io_wd;
|
||||||
|
8'h63: dbg_a[15:8] <= io_wd;
|
||||||
|
8'h65: bp0[7:0] <= io_wd;
|
||||||
|
8'h66: bp0[15:8] <= io_wd;
|
||||||
|
8'h68: bp1[7:0] <= io_wd;
|
||||||
|
8'h69: bp1[15:8] <= io_wd;
|
||||||
|
8'h67: bp_on <= io_wd[1:0];
|
||||||
|
default: ;
|
||||||
|
endcase
|
||||||
|
// step: the exit path runs POP AF and RETN, then one instruction
|
||||||
|
// of the program; ask for the NMI as that one starts
|
||||||
|
if (step_arm && ins_start) begin
|
||||||
|
step_n <= step_n + 1'b1;
|
||||||
|
if (step_n == 2'd2) begin
|
||||||
|
step_arm <= 1'b0;
|
||||||
|
nmi_r <= 1'b1; nmi_busy <= 1'b1; why <= 3'd3;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (can_nmi && !nmi_r) begin
|
||||||
|
if (nmi_now) begin
|
||||||
|
nmi_busy <= 1'b1; why <= hit0 ? 3'd4 : 3'd5;
|
||||||
|
end else if (brk_key) begin
|
||||||
|
nmi_r <= 1'b1; nmi_busy <= 1'b1; why <= 3'd1;
|
||||||
|
end else if (io_wr && io_addr[7:0] == 8'h61) begin
|
||||||
|
nmi_r <= 1'b1; nmi_busy <= 1'b1; why <= 3'd2;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
always @* case (io_addr[7:0])
|
always @* case (io_addr[7:0])
|
||||||
8'h00: io_din = {6'd0, tx_ready, rx_avail};
|
8'h00: io_din = {6'd0, tx_ready, rx_avail};
|
||||||
8'h01: io_din = rx_data;
|
8'h01: io_din = rx_data;
|
||||||
@@ -143,6 +233,8 @@ module z80_system #(
|
|||||||
8'h34: io_din = {7'd0, fill_busy};
|
8'h34: io_din = {7'd0, fill_busy};
|
||||||
8'h40: io_din = fl_ctl_q;
|
8'h40: io_din = fl_ctl_q;
|
||||||
8'h41: io_din = fl_dat_q;
|
8'h41: io_din = fl_dat_q;
|
||||||
|
8'h60: io_din = {5'd0, why};
|
||||||
|
8'h64: io_din = dbg_q;
|
||||||
default: io_din = 8'hFF;
|
default: io_din = 8'hFF;
|
||||||
endcase
|
endcase
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ puts "Z-80 clock: [expr {$hz / 1e6}] MHz"
|
|||||||
read_verilog [glob $root/rtl/*.v]
|
read_verilog [glob $root/rtl/*.v]
|
||||||
read_mem $root/font/font.mem
|
read_mem $root/font/font.mem
|
||||||
read_mem $root/basic/basic.mem
|
read_mem $root/basic/basic.mem
|
||||||
|
read_mem $root/monitor/monitor.mem
|
||||||
read_xdc $root/constraints/basys3.xdc
|
read_xdc $root/constraints/basys3.xdc
|
||||||
|
|
||||||
synth_design -top basys3_terminal -part xc7a35tcpg236-1 \
|
synth_design -top basys3_terminal -part xc7a35tcpg236-1 \
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@ ROOT=$(pwd)
|
|||||||
source scripts/vivado_env.sh
|
source scripts/vivado_env.sh
|
||||||
mkdir -p sim/work
|
mkdir -p sim/work
|
||||||
cd sim/work
|
cd sim/work
|
||||||
xvlog -d SIMULATION -d FONT_FILE="\"$ROOT/font/font.mem\"" -d MEM_FILE="\"$ROOT/basic/basic.mem\"" "$ROOT"/rtl/*.v "$ROOT"/sim/spiflash_model.v "$ROOT"/sim/tb_terminal.v
|
xvlog -d SIMULATION -d FONT_FILE="\"$ROOT/font/font.mem\"" -d MEM_FILE="\"$ROOT/basic/basic.mem\"" -d MON_FILE="\"$ROOT/monitor/monitor.mem\"" "$ROOT"/rtl/*.v "$ROOT"/sim/spiflash_model.v "$ROOT"/sim/tb_terminal.v
|
||||||
xelab -debug off tb_terminal -s tb_terminal
|
xelab -debug off tb_terminal -s tb_terminal
|
||||||
xsim tb_terminal -R
|
xsim tb_terminal -R
|
||||||
if command -v python3 >/dev/null; then
|
if command -v python3 >/dev/null; then
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ module tb_cpu;
|
|||||||
z80_cpu cpu (
|
z80_cpu cpu (
|
||||||
.clk(clk), .rst(rst), .ma(ma), .we(we), .wd(wd), .din(din),
|
.clk(clk), .rst(rst), .ma(ma), .we(we), .wd(wd), .din(din),
|
||||||
.io_addr(io_addr), .io_rd(io_rd), .io_wr(io_wr), .io_wd(io_wd), .io_din(io_din),
|
.io_addr(io_addr), .io_rd(io_rd), .io_wr(io_wr), .io_wd(io_wd), .io_din(io_din),
|
||||||
.halted(halted), .ins_start(ins_start), .dbg_pc(pc),
|
.halted(halted), .nmi(1'b0), .nmi_now(1'b0), .ins_start(ins_start), .dbg_pc(pc),
|
||||||
.dbg_af(af), .dbg_bc(bc), .dbg_de(de), .dbg_hl(hl), .dbg_ix(ix), .dbg_iy(iy), .dbg_sp(sp)
|
.dbg_af(af), .dbg_bc(bc), .dbg_de(de), .dbg_hl(hl), .dbg_ix(ix), .dbg_iy(iy), .dbg_sp(sp)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+110
-3
@@ -17,7 +17,7 @@ module tb_terminal;
|
|||||||
wire qcs;
|
wire qcs;
|
||||||
wire [3:0] qdb;
|
wire [3:0] qdb;
|
||||||
|
|
||||||
basys3_terminal #(.FONT_FILE(`FONT_FILE), .MEM_FILE(`MEM_FILE)) dut (
|
basys3_terminal #(.FONT_FILE(`FONT_FILE), .MEM_FILE(`MEM_FILE), .MON_FILE(`MON_FILE)) dut (
|
||||||
.clk(clk), .btnC(btnC), .btnU(btnU), .btnD(btnD), .sw(sw), .led(led), .seg(), .dp(), .an(),
|
.clk(clk), .btnC(btnC), .btnU(btnU), .btnD(btnD), .sw(sw), .led(led), .seg(), .dp(), .an(),
|
||||||
.vgaRed(r), .vgaGreen(g), .vgaBlue(b), .Hsync(hs), .Vsync(vs),
|
.vgaRed(r), .vgaGreen(g), .vgaBlue(b), .Hsync(hs), .Vsync(vs),
|
||||||
.RsRx(rsrx), .RsTx(rstx), .PS2Clk(ps2c), .PS2Data(ps2d),
|
.RsRx(rsrx), .RsTx(rstx), .PS2Clk(ps2c), .PS2Data(ps2d),
|
||||||
@@ -26,7 +26,7 @@ module tb_terminal;
|
|||||||
|
|
||||||
spiflash_model flash (.cs_n(qcs), .sck(dut.fl_sck), .mosi(qdb[0]), .miso(qdb[1]));
|
spiflash_model flash (.cs_n(qcs), .sck(dut.fl_sck), .mosi(qdb[0]), .miso(qdb[1]));
|
||||||
|
|
||||||
localparam BIT_NS = 1_000_000_000 / 115200;
|
real BIT_NS = 1_000_000_000.0 / 115200; // changed for the 3 Mbaud test
|
||||||
integer errors = 0;
|
integer errors = 0;
|
||||||
|
|
||||||
task uart_send(input [7:0] d);
|
task uart_send(input [7:0] d);
|
||||||
@@ -102,7 +102,7 @@ module tb_terminal;
|
|||||||
function [7:0] cellraw(input integer rr, input integer cc);
|
function [7:0] cellraw(input integer rr, input integer cc);
|
||||||
reg [17:0] v;
|
reg [17:0] v;
|
||||||
begin
|
begin
|
||||||
v = dut.screen.mem[rr * 80 + cc];
|
v = dut.screen.mem[(dut.alt_scr ? 4096 : 0) + rr * 80 + cc]; // the page on show
|
||||||
cellraw = v[7:0];
|
cellraw = v[7:0];
|
||||||
end
|
end
|
||||||
endfunction
|
endfunction
|
||||||
@@ -165,6 +165,34 @@ module tb_terminal;
|
|||||||
end
|
end
|
||||||
endtask
|
endtask
|
||||||
|
|
||||||
|
// wait (up to 300 ms) for text at row rr from column c0
|
||||||
|
task wait_at(input integer rr, input integer c0, input [8*40-1:0] want);
|
||||||
|
integer cc, n;
|
||||||
|
reg [8*40-1:0] got;
|
||||||
|
realtime t0;
|
||||||
|
begin
|
||||||
|
t0 = $realtime;
|
||||||
|
n = 0;
|
||||||
|
for (cc = 0; cc < 40; cc = cc + 1) if (want[cc*8 +: 8] != 0) n = cc + 1;
|
||||||
|
got = 0;
|
||||||
|
while (got != want && $realtime - t0 < 300_000_000) begin
|
||||||
|
#100_000;
|
||||||
|
for (cc = 0; cc < n; cc = cc + 1) got[(n - 1 - cc) * 8 +: 8] = cellraw(rr, c0 + cc);
|
||||||
|
end
|
||||||
|
if (got == want) $display("PASS row %0d col %0d: %0s", rr, c0, want);
|
||||||
|
else begin
|
||||||
|
$display("FAIL row %0d col %0d: want \"%0s\" got \"%0s\"", rr, c0, want, got);
|
||||||
|
errors = errors + 1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
endtask
|
||||||
|
|
||||||
|
reg [31:0] pc_a, pc_b, jp_to;
|
||||||
|
reg [23:0] jp_txt;
|
||||||
|
function [31:0] screen_pc(input integer dummy);
|
||||||
|
screen_pc = {cellraw(2, 4), cellraw(2, 5), cellraw(2, 6), cellraw(2, 7)};
|
||||||
|
endfunction
|
||||||
|
|
||||||
// capture one frame
|
// capture one frame
|
||||||
reg [11:0] fb [0:640*480-1];
|
reg [11:0] fb [0:640*480-1];
|
||||||
reg cap = 0, smp = 0;
|
reg cap = 0, smp = 0;
|
||||||
@@ -325,6 +353,85 @@ module tb_terminal;
|
|||||||
uart_str({"CLS:OPEN \"D\" FOR OUTPUT AS 1:PRINT #1,\"XY\";\",\";7:CLOSE\015",
|
uart_str({"CLS:OPEN \"D\" FOR OUTPUT AS 1:PRINT #1,\"XY\";\",\";7:CLOSE\015",
|
||||||
"OPEN \"D\" FOR INPUT AS 1:INPUT #1,A$,B:PRINT A$;B*6;EOF(1):CLOSE\015"});
|
"OPEN \"D\" FOR INPUT AS 1:INPUT #1,A$,B:PRINT A$;B*6;EOF(1):CLOSE\015"});
|
||||||
wait_row(3, "XY 42 -1");
|
wait_row(3, "XY 42 -1");
|
||||||
|
|
||||||
|
// ---- the machine-code monitor
|
||||||
|
uart_str("MONITOR\015");
|
||||||
|
wait_at(0, 50, "STOPPED BY MONITOR COMMAND");
|
||||||
|
wait_at(2, 0, " PC ");
|
||||||
|
wait_at(29, 0, "> ");
|
||||||
|
pc_a = screen_pc(0);
|
||||||
|
wait_at(5, 0, ">");
|
||||||
|
jp_txt = {cellraw(5, 21), cellraw(5, 22), cellraw(5, 23)};
|
||||||
|
jp_to = {cellraw(5, 24), cellraw(5, 25), cellraw(5, 26), cellraw(5, 27)};
|
||||||
|
dump_screen;
|
||||||
|
uart_str("\015"); // Enter: one step
|
||||||
|
wait_at(0, 50, "STOPPED BY STEP");
|
||||||
|
wait_at(29, 0, "> ");
|
||||||
|
pc_b = screen_pc(0);
|
||||||
|
// MONITOR stops on a JP (to the end of BASIC's statement routine): one
|
||||||
|
// step must land exactly on its target
|
||||||
|
if (pc_b == jp_to) $display("PASS step: PC %0s -> %0s (%0s)", pc_a, pc_b, jp_txt);
|
||||||
|
else begin $display("FAIL step: PC %0s -> %0s, wanted %0s (%0s)", pc_a, pc_b, jp_to, jp_txt); errors = errors + 1; end
|
||||||
|
// a breakpoint where the step stopped (the end of BASIC's statement
|
||||||
|
// routine), hit again by OUT; leaving from it steps off it first
|
||||||
|
uart_str("B "); uart_send(pc_b[31:24]); uart_send(pc_b[23:16]);
|
||||||
|
uart_send(pc_b[15:8]); uart_send(pc_b[7:0]); uart_send(8'h0D);
|
||||||
|
wait_at(29, 40, "BREAKPOINT SET");
|
||||||
|
uart_str("X\015");
|
||||||
|
wait_row(3, "XY 42 -1"); // BASIC's screen is back as it was
|
||||||
|
uart_str("OUT 32,7\015");
|
||||||
|
wait_at(0, 50, "STOPPED BY BREAKPOINT");
|
||||||
|
wait_at(29, 0, "> ");
|
||||||
|
if (screen_pc(0) == pc_b) $display("PASS breakpoint at %0s", pc_b);
|
||||||
|
else begin $display("FAIL breakpoint: PC %0s, wanted %0s", screen_pc(0), pc_b); errors = errors + 1; end
|
||||||
|
uart_str("B\015");
|
||||||
|
wait_at(29, 40, "BREAKPOINT CLEARED");
|
||||||
|
uart_str("X\015");
|
||||||
|
#5_000_000;
|
||||||
|
// the Pause key
|
||||||
|
ps2_send(8'hE1); ps2_send(8'h14); ps2_send(8'h77);
|
||||||
|
ps2_send(8'hE1); ps2_send(8'hF0); ps2_send(8'h14); ps2_send(8'hF0); ps2_send(8'h77);
|
||||||
|
wait_at(0, 50, "STOPPED BY PAUSE KEY");
|
||||||
|
wait_at(29, 0, "> ");
|
||||||
|
uart_str("X\015");
|
||||||
|
#2_000_000;
|
||||||
|
uart_str("CLS:PRINT 3*4\015");
|
||||||
|
wait_row(0, " 12");
|
||||||
|
|
||||||
|
// ---- 3 Mbaud (SW1:0 = 11): a program in, its output on screen and back
|
||||||
|
sw[1:0] = 2'b11;
|
||||||
|
BIT_NS = 1_000_000_000.0 / 3_000_000;
|
||||||
|
#200_000;
|
||||||
|
tx_n = 0; tx_log = 0;
|
||||||
|
uart_str({"CLS:NEW\01510 FOR I=1 TO 3:PRINT I*111;:NEXT I\01520 PRINT \"FAST\"\015",
|
||||||
|
"RUN\015"});
|
||||||
|
wait_row(5, " 111 222 333 FAST");
|
||||||
|
#2_000_000;
|
||||||
|
if (tx_log[8*7-1:0] == "READY\015\012") $display("PASS 3 Mbaud: %0d bytes back, ending READY", tx_n);
|
||||||
|
else begin $display("FAIL 3 Mbaud: %0d bytes back, last %h", tx_n, tx_log[8*7-1:0]); errors = errors + 1; end
|
||||||
|
|
||||||
|
// ---- memory files: the monitor's SAVE/LOAD/DIR, BASIC's BSAVE/BLOAD
|
||||||
|
uart_str("CLS:POKE 36864,72:POKE 36865,73:MONITOR\015");
|
||||||
|
wait_at(29, 0, "> ");
|
||||||
|
uart_str("SAVE \"MEM1\" 9000 9001\015");
|
||||||
|
wait_at(29, 40, "SAVED");
|
||||||
|
uart_str("E 9000 00 00\015");
|
||||||
|
wait_at(29, 0, "> ");
|
||||||
|
uart_str("LOAD \"MEM1\"\015");
|
||||||
|
wait_at(29, 40, "LOADED 9000-9001");
|
||||||
|
wait_at(22, 0, " 9000 48 49 ");
|
||||||
|
uart_str("DIR\015");
|
||||||
|
wait_at(29, 40, "M TO SHOW MEMORY AGAIN");
|
||||||
|
uart_str("X\015");
|
||||||
|
#3_000_000;
|
||||||
|
uart_str("CLS:POKE 36864,0:BLOAD \"MEM1\":BSAVE \"MEM2\",36864,2:BLOAD \"MEM2\",36866:PRINT PEEK(36866);PEEK(36867)\015");
|
||||||
|
wait_row(0, " 72 73");
|
||||||
|
|
||||||
|
// ---- Ctrl-Alt-Del restarts the Z-80
|
||||||
|
ps2_send(8'h14); ps2_send(8'h11); ps2_send(8'hE0); ps2_send(8'h71);
|
||||||
|
ps2_send(8'hE0); ps2_send(8'hF0); ps2_send(8'h71); ps2_send(8'hF0); ps2_send(8'h11);
|
||||||
|
ps2_send(8'hF0); ps2_send(8'h14);
|
||||||
|
wait_row(4, "DARTMOUTH-STYLE BASIC"); // the restarted BASIC's banner
|
||||||
dump_screen;
|
dump_screen;
|
||||||
if (errors == 0) $display("ALL TESTS PASSED");
|
if (errors == 0) $display("ALL TESTS PASSED");
|
||||||
else $display("%0d TESTS FAILED", errors);
|
else $display("%0d TESTS FAILED", errors);
|
||||||
|
|||||||
+2
-2
@@ -17,8 +17,8 @@ import select
|
|||||||
import termios
|
import termios
|
||||||
import time
|
import time
|
||||||
|
|
||||||
BAUDS = {9600: termios.B9600, 19200: termios.B19200, 57600: termios.B57600,
|
BAUDS = {9600: termios.B9600, 115200: termios.B115200, 921600: termios.B921600,
|
||||||
115200: termios.B115200}
|
3000000: termios.B3000000}
|
||||||
|
|
||||||
ap = argparse.ArgumentParser()
|
ap = argparse.ArgumentParser()
|
||||||
ap.add_argument("file", nargs="?", help="where to write the listing")
|
ap.add_argument("file", nargs="?", help="where to write the listing")
|
||||||
|
|||||||
+11
-2
@@ -10,11 +10,12 @@ SW1:0. Sets BASIC's clock to the PC's (unless --no-date), sends NEW unless
|
|||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
|
import select
|
||||||
import termios
|
import termios
|
||||||
import time
|
import time
|
||||||
|
|
||||||
BAUDS = {9600: termios.B9600, 19200: termios.B19200, 57600: termios.B57600,
|
BAUDS = {9600: termios.B9600, 115200: termios.B115200, 921600: termios.B921600,
|
||||||
115200: termios.B115200}
|
3000000: termios.B3000000}
|
||||||
|
|
||||||
ap = argparse.ArgumentParser()
|
ap = argparse.ArgumentParser()
|
||||||
ap.add_argument("file")
|
ap.add_argument("file")
|
||||||
@@ -41,10 +42,18 @@ if a.run:
|
|||||||
lines.append("RUN")
|
lines.append("RUN")
|
||||||
if not a.no_date:
|
if not a.no_date:
|
||||||
lines.insert(0, time.strftime('DATE "%Y-%m-%d %H:%M:%S"'))
|
lines.insert(0, time.strftime('DATE "%Y-%m-%d %H:%M:%S"'))
|
||||||
|
t[6][termios.VMIN] = 0 # reads don't wait
|
||||||
|
t[6][termios.VTIME] = 0
|
||||||
|
termios.tcsetattr(fd, termios.TCSANOW, t)
|
||||||
for n, line in enumerate(lines, 1):
|
for n, line in enumerate(lines, 1):
|
||||||
os.write(fd, line.encode("ascii") + b"\r")
|
os.write(fd, line.encode("ascii") + b"\r")
|
||||||
termios.tcdrain(fd)
|
termios.tcdrain(fd)
|
||||||
time.sleep(0.02) # let BASIC store the line
|
time.sleep(0.02) # let BASIC store the line
|
||||||
|
# Read BASIC's echo (copied back when SW14 is up). Left unread, it fills the
|
||||||
|
# PC's input buffer; Linux then stops reading the port, misses the board's
|
||||||
|
# XON and never sends again.
|
||||||
|
while select.select([fd], [], [], 0)[0] and os.read(fd, 4096):
|
||||||
|
pass
|
||||||
print("\r%d/%d lines" % (n, len(lines)), end="", flush=True)
|
print("\r%d/%d lines" % (n, len(lines)), end="", flush=True)
|
||||||
print()
|
print()
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
Reference in new issue
Block a user