Remove the sound chip; Ctrl-Alt-Del opens the monitor
The sound chip (rtl/sound.v, ports 90h-9Dh, the PmodAMP2 on JA) is removed: its ports now read FFh like any unused port, the JA pins are free, and the manual, README, example and tests no longer mention it. No game used it. Ctrl-Alt-Del raises the monitor's NMI (STOPPED BY CTRL-ALT-DEL) instead of resetting; pressed in the monitor, again within 2 s, or while an NMI is still pending it restarts the computer. The monitor gains RESET (port 62), and BASIC returns to the main screen at start-up. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
addf0157fc
commit
8420a5a226
19 files changed
+1707
-2021
No files matched your search
@@ -10,11 +10,10 @@ RISC-V processor written from scratch in Verilog:
|
|||||||
in a double-size font.
|
in a double-size font.
|
||||||
- **Graphics** over the text: 320 × 240 in 16 colours with hardware scrolling,
|
- **Graphics** over the text: 320 × 240 in 16 colours with hardware scrolling,
|
||||||
or 640 × 480 in two colours, plus 32 hardware sprites.
|
or 640 × 480 in two colours, plus 32 hardware sprites.
|
||||||
- **Sound**: a three-voice chip with noise and envelopes (PmodAMP2 on JA).
|
|
||||||
- **USB keyboard** on the board's USB host port, with a keys-held port for
|
- **USB keyboard** on the board's USB host port, with a keys-held port for
|
||||||
games.
|
games.
|
||||||
- **Files** saved in the board's configuration flash.
|
- **Files** saved in the board's configuration flash.
|
||||||
- **Software**: Dartmouth-style BASIC with graphics, sound and files,
|
- **Software**: Dartmouth-style BASIC with graphics and files,
|
||||||
`DO … LOOP`, block `IF … ELSE … END IF` and `SELECT CASE`, and scientific
|
`DO … LOOP`, block `IF … ELSE … END IF` and `SELECT CASE`, and scientific
|
||||||
functions (inverse and hyperbolic trigonometry in radians or degrees,
|
functions (inverse and hyperbolic trigonometry in radians or degrees,
|
||||||
`LOG10`, `ROUND`, `MOD`, `FACT` …), and `UCASE$`/`LCASE$`; a
|
`LOG10`, `ROUND`, `MOD`, `FACT` …), and `UCASE$`/`LCASE$`; a
|
||||||
@@ -25,7 +24,7 @@ RISC-V processor written from scratch in Verilog:
|
|||||||
arithmetic.
|
arithmetic.
|
||||||
|
|
||||||
The [BASIC manual](docs/basic-manual.md) ([PDF](docs/basic-manual.pdf))
|
The [BASIC manual](docs/basic-manual.md) ([PDF](docs/basic-manual.pdf))
|
||||||
describes the computer from the user's side: BASIC, graphics, sprites, sound,
|
describes the computer from the user's side: BASIC, graphics, sprites,
|
||||||
files, the monitor and the games.
|
files, the monitor and the games.
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
@@ -34,7 +33,7 @@ Download `basys3_terminal.bit` (or `basys3_terminal.mcs` to keep it in the
|
|||||||
flash) from the [latest release](https://git.barant.com/barant/Basys3RiscV/releases),
|
flash) from the [latest release](https://git.barant.com/barant/Basys3RiscV/releases),
|
||||||
or build it yourself (below).
|
or build it yourself (below).
|
||||||
|
|
||||||
1. Plug a VGA monitor, a USB keyboard, and optionally a PmodAMP2 into JA.
|
1. Plug in a VGA monitor and a USB keyboard.
|
||||||
2. Load the bitstream with Vivado's Hardware Manager, or `scripts/build.sh
|
2. Load the bitstream with Vivado's Hardware Manager, or `scripts/build.sh
|
||||||
program` / `flash` from a checkout.
|
program` / `flash` from a checkout.
|
||||||
3. Flip **SW15 up**. The screen shows BASIC's banner and `READY`.
|
3. Flip **SW15 up**. The screen shows BASIC's banner and `READY`.
|
||||||
@@ -73,8 +72,8 @@ then `SAVE "KEEP"` in BASIC, and `RUN "KEEP"` from then on.
|
|||||||
| SW15 | Computer mode: the terminal is the computer's console |
|
| SW15 | Computer mode: the terminal is the computer's console |
|
||||||
| BTNC | Reset everything |
|
| BTNC | Reset everything |
|
||||||
| BTNU | Clear the screen |
|
| BTNU | Clear the screen |
|
||||||
| BTND | Restart the computer only (or Ctrl-Alt-Del in computer mode) |
|
| BTND | Restart the computer only |
|
||||||
| Pause key | Stop the program in the machine-code monitor |
|
| Pause key, or Ctrl-Alt-Del | Stop the program in the machine-code monitor, with its registers (Ctrl-Alt-Del again within 2 s, or while the monitor shows, restarts the computer; so does the monitor's `RESET`) |
|
||||||
| 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–15 | Bell, Caps Lock, serial activity, keyboard activity |
|
| LED12–15 | Bell, Caps Lock, serial activity, keyboard activity |
|
||||||
@@ -141,9 +140,9 @@ LUTs (3,000 of them the FPU), 1,900 flip-flops and 6 DSP slices.
|
|||||||
|
|
||||||
The ports (listed at the top of `rv32_system.v` and in the manual) cover the
|
The ports (listed at the top of `rv32_system.v` and in the manual) cover the
|
||||||
console, the millisecond counter, the 7-segment display, graphics, sprites,
|
console, the millisecond counter, the 7-segment display, graphics, sprites,
|
||||||
sound, the keys held down and the flash. The peripherals are `term_ctrl.v`
|
the keys held down and the flash. The peripherals are `term_ctrl.v`
|
||||||
(the VT220), `text_display.v` (video), `sprites.v`, `sound.v`,
|
(the VT220), `text_display.v` (video), `sprites.v`, `flash_spi.v`,
|
||||||
`flash_spi.v`, `uart.v`, `ps2_keyboard.v` and `sevenseg.v`.
|
`uart.v`, `ps2_keyboard.v` and `sevenseg.v`.
|
||||||
|
|
||||||
The graphics memory is 76,800 four-bit entries: 320 × 240 pixels in 16
|
The graphics memory is 76,800 four-bit entries: 320 × 240 pixels in 16
|
||||||
colours, or, with port 38 set, 640 × 480 pixels at one bit each (four to an
|
colours, or, with port 38 set, 640 × 480 pixels at one bit each (four to an
|
||||||
|
|||||||
Binary file not shown.
@@ -2838,6 +2838,7 @@ int main(void)
|
|||||||
new_prog();
|
new_prog();
|
||||||
g_clear(0);
|
g_clear(0);
|
||||||
newline();
|
newline();
|
||||||
|
out_c(27); out_c('['); out_c('?'); out_c('4'); out_c('7'); out_c('l'); /* off the monitor's screen */
|
||||||
puts_("DARTMOUTH-STYLE BASIC RISC-V ON A BASYS 3");
|
puts_("DARTMOUTH-STYLE BASIC RISC-V ON A BASYS 3");
|
||||||
newline();
|
newline();
|
||||||
if (setjmp(errjmp)) {
|
if (setjmp(errjmp)) {
|
||||||
|
|||||||
+376
-376
File diff suppressed because it is too large.
Load diff
@@ -1,26 +0,0 @@
|
|||||||
10 REM SOUND DEMO - NEEDS A PMODAMP2 ON THE TOP ROW OF PMOD JA
|
|
||||||
20 REM PITCH = 125000 / FREQUENCY. PORTS: 144-149 PITCHES, 150 NOISE,
|
|
||||||
30 REM 151 MIXER, 152-154 VOLUMES, 155-157 ENVELOPES (ATTACK*16+DECAY)
|
|
||||||
40 PRINT "A SCALE"
|
|
||||||
50 OUT 151, 1: OUT 155, 3
|
|
||||||
60 FOR I = 1 TO 8
|
|
||||||
70 READ P: GOSUB 500
|
|
||||||
80 OUT 152, 15
|
|
||||||
90 IF INP(152) > 0 THEN 90
|
|
||||||
100 NEXT I
|
|
||||||
110 PRINT "A LASER"
|
|
||||||
120 OUT 151, 4: OUT 149, 0: OUT 157, 0: OUT 154, 13
|
|
||||||
130 FOR P = 30 TO 250 STEP 6: OUT 148, P: NEXT P
|
|
||||||
140 OUT 154, 0
|
|
||||||
150 PRINT "AN EXPLOSION"
|
|
||||||
160 OUT 151, 16: OUT 150, 24: OUT 156, 8: OUT 153, 15
|
|
||||||
170 IF INP(153) > 0 THEN 170
|
|
||||||
180 PRINT "A CHORD"
|
|
||||||
190 OUT 151, 7
|
|
||||||
200 OUT 144, 221: OUT 145, 1: OUT 146, 123: OUT 147, 1: OUT 148, 63: OUT 149, 1
|
|
||||||
210 OUT 155, 69: OUT 156, 69: OUT 157, 69
|
|
||||||
220 OUT 152, 12: OUT 153, 12: OUT 154, 12
|
|
||||||
230 IF INP(152) > 0 THEN 230
|
|
||||||
240 END
|
|
||||||
500 OUT 144, P - INT(P / 256) * 256: OUT 145, INT(P / 256): RETURN
|
|
||||||
900 DATA 477, 425, 379, 358, 319, 284, 253, 239
|
|
||||||
@@ -6,7 +6,7 @@ and the graphics come out the same; and time them.
|
|||||||
python3 test-compile.py [--only NAME] [--keep DIR]
|
python3 test-compile.py [--only NAME] [--keep DIR]
|
||||||
|
|
||||||
The programs are the ones in basic/examples (with their waits for the clock
|
The programs are the ones in basic/examples (with their waits for the clock
|
||||||
and the sound chip taken out, which an emulator can't time) and the programs
|
taken out, which an emulator can't time) and the programs
|
||||||
of the other basic/test-*.py suites, plus programs here that go through each
|
of the other basic/test-*.py suites, plus programs here that go through each
|
||||||
statement and the errors.
|
statement and the errors.
|
||||||
"""
|
"""
|
||||||
@@ -115,9 +115,6 @@ def examples():
|
|||||||
lines[810] = "810 FOR J=0 TO 14: FOR I=0 TO 19" # a corner of the set
|
lines[810] = "810 FOR J=0 TO 14: FOR I=0 TO 19" # a corner of the set
|
||||||
lines[900] = '900 INK 7: LOCATE 30,1: PRINT "MANDELBROT DONE";'
|
lines[900] = '900 INK 7: LOCATE 30,1: PRINT "MANDELBROT DONE";'
|
||||||
lines[910] = '910 PRINT " WHOLE DEMO DONE"'
|
lines[910] = '910 PRINT " WHOLE DEMO DONE"'
|
||||||
if name == "sound":
|
|
||||||
for n in (90, 170, 230): # waits for the envelopes
|
|
||||||
lines[n] = "%d REM" % n
|
|
||||||
if name == "sprites": # 30 frames, the same each time
|
if name == "sprites": # 30 frames, the same each time
|
||||||
lines[50] = "50 REM" # (RANDOMIZE takes the clock)
|
lines[50] = "50 REM" # (RANDOMIZE takes the clock)
|
||||||
lines[390] = "390 REM" # the wait for the next frame
|
lines[390] = "390 REM" # the wait for the next frame
|
||||||
|
|||||||
@@ -102,13 +102,6 @@ set_clock_groups -asynchronous -group [get_clocks sys_clk_pin] \
|
|||||||
-group [get_clocks -of_objects [get_pins pix_mmcm/CLKOUT0]]
|
-group [get_clocks -of_objects [get_pins pix_mmcm/CLKOUT0]]
|
||||||
set_false_path -to [get_ports {led[*] seg[*] dp an[*] RsTx}]
|
set_false_path -to [get_ports {led[*] seg[*] dp an[*] RsTx}]
|
||||||
|
|
||||||
## Pmod JA top row: a PmodAMP2 (AIN, GAIN, NC, SHUTDOWN)
|
|
||||||
set_property -dict { PACKAGE_PIN J1 IOSTANDARD LVCMOS33 } [get_ports {JA[0]}]
|
|
||||||
set_property -dict { PACKAGE_PIN L2 IOSTANDARD LVCMOS33 } [get_ports {JA[1]}]
|
|
||||||
set_property -dict { PACKAGE_PIN J2 IOSTANDARD LVCMOS33 } [get_ports {JA[2]}]
|
|
||||||
set_property -dict { PACKAGE_PIN G2 IOSTANDARD LVCMOS33 } [get_ports {JA[3]}]
|
|
||||||
set_false_path -to [get_ports {JA[*]}]
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
set_property CONFIG_VOLTAGE 3.3 [current_design]
|
set_property CONFIG_VOLTAGE 3.3 [current_design]
|
||||||
set_property CFGBVS VCCO [current_design]
|
set_property CFGBVS VCCO [current_design]
|
||||||
|
|||||||
+15
-45
@@ -23,8 +23,11 @@ READY
|
|||||||
|
|
||||||
The computer keeps running while SW15 is down. It just waits until it can print
|
The computer 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**
|
||||||
(or **Ctrl-Alt-Del** on the keyboard) restarts the computer; that wipes the program
|
restarts the computer; that wipes the program but not the files in flash.
|
||||||
but not the files in flash. **BTNC** restarts the whole board.
|
**BTNC** restarts the whole board. **Ctrl-Alt-Del** on the keyboard stops the
|
||||||
|
program in the machine-code monitor, wherever it is (section 10); pressed again
|
||||||
|
within 2 seconds, or while the monitor is showing, it restarts the computer as
|
||||||
|
BTND does.
|
||||||
|
|
||||||
### Talking to BASIC
|
### Talking to BASIC
|
||||||
|
|
||||||
@@ -868,7 +871,6 @@ compare value, 10h and 14h the monitor's breakpoint addresses.
|
|||||||
| 112–120, 128–135 | sprites (section 7) | sprites (section 7) |
|
| 112–120, 128–135 | sprites (section 7) | sprites (section 7) |
|
||||||
| 136 | keys held down, for games (below) | — |
|
| 136 | keys held down, for games (below) | — |
|
||||||
| 137 | 1 if the key picked with `OUT 137` is held down, else 0 | pick a key by its scan code |
|
| 137 | 1 if the key picked with `OUT 137` is held down, else 0 | pick a key by its scan code |
|
||||||
| 144–157 | voice volumes now (152–154) | sound (below) |
|
|
||||||
|
|
||||||
```
|
```
|
||||||
10 FOR I = 0 TO 255
|
10 FOR I = 0 TO 255
|
||||||
@@ -917,45 +919,6 @@ game should throw those away now and then with `IF INP(0) AND 1 THEN K =
|
|||||||
INP(1)` in a loop. Held keys only work with the board's own keyboard, not with
|
INP(1)` in a loop. Held keys only work with the board's own keyboard, not with
|
||||||
characters sent from the PC.
|
characters sent from the PC.
|
||||||
|
|
||||||
### Sound
|
|
||||||
|
|
||||||
The board has no speaker of its own. Plug a Digilent **PmodAMP2** into the
|
|
||||||
top row of Pmod header **JA** (pin 1 at the end marked 1) and headphones or a
|
|
||||||
powered speaker into its jack. The FPGA has a little sound chip in the style
|
|
||||||
of the 8-bit computers: three voices that play square-wave tones, a noise
|
|
||||||
source they can use instead or as well, sixteen volumes and an envelope for
|
|
||||||
each voice, so a note or a bang fades away by itself.
|
|
||||||
|
|
||||||
| Port | `OUT` |
|
|
||||||
|---|---|
|
|
||||||
| 144, 145 | voice 0 pitch: low byte, then high byte (0–15) |
|
|
||||||
| 146, 147 | voice 1 pitch |
|
|
||||||
| 148, 149 | voice 2 pitch |
|
|
||||||
| 150 | noise pitch, 0–31 (higher is lower and rougher) |
|
|
||||||
| 151 | mixer: add 1, 2, 4 for the tone of voice 0, 1, 2 and 8, 16, 32 for noise on voice 0, 1, 2 |
|
|
||||||
| 152, 153, 154 | voice 0, 1, 2 volume, 0 (off) to 15, which starts its envelope; `INP` gives the volume it has got to |
|
|
||||||
| 155, 156, 157 | voice 0, 1, 2 envelope: attack × 16 + decay, each 0–15 |
|
|
||||||
|
|
||||||
- **Pitch** = 125000 ÷ frequency: 284 is the A above middle C (440 Hz),
|
|
||||||
477 middle C. Each voice goes from about 30 Hz up beyond hearing.
|
|
||||||
- **Envelope:** with an attack, the volume climbs from 0 to the volume set,
|
|
||||||
one step every attack × 4 ms; then, with a decay, it falls back to 0 one step
|
|
||||||
every decay × 4 ms. 0 means no climb, or hold the volume until it is
|
|
||||||
changed. An envelope of 3 plays a short note; 8 with noise is an explosion.
|
|
||||||
- **Waiting for a sound to end:** `IF INP(152) > 0 THEN …` loops until voice
|
|
||||||
0 has faded out.
|
|
||||||
- A voice that has neither its tone nor noise on in the mixer gives a steady
|
|
||||||
level, so changing its volume clicks; that is how the old chips played
|
|
||||||
samples.
|
|
||||||
- `CLS` silences everything (as does restarting the computer).
|
|
||||||
|
|
||||||
```
|
|
||||||
10 OUT 151, 1: OUT 155, 3 : REM TONE ON VOICE 0, A SHORT NOTE
|
|
||||||
20 OUT 144, 28: OUT 145, 1: OUT 152, 15 : REM PITCH 284 = 440 HZ
|
|
||||||
```
|
|
||||||
|
|
||||||
`basic/examples/sound.bas` plays a scale, a laser, an explosion and a chord.
|
|
||||||
|
|
||||||
### Speed
|
### Speed
|
||||||
|
|
||||||
The processor is a 32-bit RISC-V (RV32IMF: the base instructions, multiply
|
The processor is a 32-bit RISC-V (RV32IMF: the base instructions, multiply
|
||||||
@@ -988,8 +951,14 @@ any code, including BASIC itself.
|
|||||||
|
|
||||||
### Getting in and out
|
### Getting in and out
|
||||||
|
|
||||||
- Press **Pause/Break** on the keyboard at any time, even when a program has
|
- Press **Pause/Break** or **Ctrl-Alt-Del** on the keyboard at any time, even
|
||||||
hung, or type `MONITOR` in BASIC.
|
when a program has hung with its interrupts off, or type `MONITOR` in BASIC.
|
||||||
|
The monitor shows every register as the program left it, and `X` carries
|
||||||
|
on.
|
||||||
|
- **Restarting:** Ctrl-Alt-Del while the monitor is showing, or twice within
|
||||||
|
2 seconds, restarts the computer, as BTND does: the way out of a machine too
|
||||||
|
wedged even for the monitor. So does the monitor's `RESET` command. Holding
|
||||||
|
the keys down counts as one press.
|
||||||
- A breakpoint or a single step also comes back to the monitor.
|
- A breakpoint or a single step also comes back to the monitor.
|
||||||
- So does a program that goes wrong: an illegal instruction, a misaligned load,
|
- So does a program that goes wrong: an illegal instruction, a misaligned load,
|
||||||
store or jump, an `EBREAK` or `ECALL`, or an interrupt with no handler. The
|
store or jump, an `EBREAK` or `ECALL`, or an interrupt with no handler. The
|
||||||
@@ -1104,6 +1073,7 @@ or without `0x`.
|
|||||||
| `A addr` | Assemble lines as you type them, from *addr*; an empty line ends |
|
| `A addr` | Assemble lines as you type them, from *addr*; an empty line ends |
|
||||||
| Up / Down | Scroll the disassembly by one instruction |
|
| Up / Down | Scroll the disassembly by one instruction |
|
||||||
| Page Up / Page Down | Scroll the memory window |
|
| Page Up / Page Down | Scroll the memory window |
|
||||||
|
| `RESET` | Restart the computer, as BTND does (the program in memory is lost; files in flash are not) |
|
||||||
| `?` | A short reminder of the commands |
|
| `?` | A short reminder of the commands |
|
||||||
| `:` *record* | An Intel HEX record, written into memory (`tools/send-hex.py` sends whole files this way; see section 12) |
|
| `:` *record* | An Intel HEX record, written into memory (`tools/send-hex.py` sends whole files this way; see section 12) |
|
||||||
|
|
||||||
@@ -1471,7 +1441,7 @@ numbers, only faster:
|
|||||||
Arithmetic, numeric variables and arrays, and every control statement (`GOTO`,
|
Arithmetic, numeric variables and arrays, and every control statement (`GOTO`,
|
||||||
`GOSUB`, `ON`, `FOR`, `IF`, `DO`, `SELECT CASE`, `EXIT`, `END`) become machine
|
`GOSUB`, `ON`, `FOR`, `IF`, `DO`, `SELECT CASE`, `EXIT`, `END`) become machine
|
||||||
code, using the FPU directly, and the graphics statements work out their
|
code, using the FPU directly, and the graphics statements work out their
|
||||||
numbers there too. Everything else (`PRINT`, `INPUT`, strings, files, sound,
|
numbers there too. Everything else (`PRINT`, `INPUT`, strings, files,
|
||||||
`DATA` and `READ`, `DEF FN`, and functions such as `LEN` and `MOD`) is handed
|
`DATA` and `READ`, `DEF FN`, and functions such as `LEN` and `MOD`) is handed
|
||||||
to BASIC in the ROM as it stands, so it behaves exactly as it does
|
to BASIC in the ROM as it stands, so it behaves exactly as it does
|
||||||
interpreted, at about the same speed. A program that spends its time
|
interpreted, at about the same speed. A program that spends its time
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+9
-4
@@ -642,10 +642,9 @@ static void draw_fregs(void)
|
|||||||
if (!u.fs) { if (r == 0) s_str(" THE FPU IS OFF (MSTATUS.FS = 0)"); }
|
if (!u.fs) { if (r == 0) s_str(" THE FPU IS OFF (MSTATUS.FS = 0)"); }
|
||||||
else for (i = 0; i < 6; i++) {
|
else for (i = 0; i < 6; i++) {
|
||||||
u8 k = r * 6 + i;
|
u8 k = r * 6 + i;
|
||||||
char n[4];
|
char n[6], *o = lp;
|
||||||
if (k < 32) {
|
if (k < 32) {
|
||||||
n[0] = 'F'; n[1] = k < 10 ? '0' + k : '0' + k / 10;
|
lp = n; s_freg(k); *lp = 0; lp = o; /* FT0 ... by ABI name */
|
||||||
n[2] = k < 10 ? 0 : '0' + k % 10; n[3] = 0;
|
|
||||||
s_rv(n, u.f[k]);
|
s_rv(n, u.f[k]);
|
||||||
} else if (k == 32) s_rv("FCSR", u.fcsr);
|
} else if (k == 32) s_rv("FCSR", u.fcsr);
|
||||||
}
|
}
|
||||||
@@ -697,6 +696,7 @@ static const char *why_text(void)
|
|||||||
case 3: return "STEP";
|
case 3: return "STEP";
|
||||||
case 4: return "BREAKPOINT";
|
case 4: return "BREAKPOINT";
|
||||||
case 5: return "STEP OVER";
|
case 5: return "STEP OVER";
|
||||||
|
case 6: return "CTRL-ALT-DEL";
|
||||||
default: return "";
|
default: return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1272,6 +1272,11 @@ static u8 command(void)
|
|||||||
skip_sp();
|
skip_sp();
|
||||||
msg = 0; msg_err = 0;
|
msg = 0; msg_err = 0;
|
||||||
if (*cp == ':') { hex_record(); return 0; }
|
if (*cp == ':') { hex_record(); return 0; }
|
||||||
|
if (!memcmp(cp, "RESET", 5)) { /* restart the computer, as BTND does */
|
||||||
|
puts_("\033[?47l");
|
||||||
|
IO8(0x62) = 0;
|
||||||
|
for (;;);
|
||||||
|
}
|
||||||
if (!memcmp(cp, "ASM", 3)) {
|
if (!memcmp(cp, "ASM", 3)) {
|
||||||
cp += 3;
|
cp += 3;
|
||||||
if (setjmp(fs_jmp)) { msg = fs_msg; msg_err = 1; return 0; }
|
if (setjmp(fs_jmp)) { msg = fs_msg; msg_err = 1; return 0; }
|
||||||
@@ -1352,7 +1357,7 @@ static u8 command(void)
|
|||||||
msg = "M TO SHOW MEMORY AGAIN";
|
msg = "M TO SHOW MEMORY AGAIN";
|
||||||
return 0;
|
return 0;
|
||||||
case 'R':
|
case 'R':
|
||||||
if (!set_reg()) { msg = "R PC|X1-X31|RA|SP|A0...|F0-F31|FCSR = VALUE"; msg_err = 1; return 0; }
|
if (!set_reg()) { msg = "R REG=HEX: PC A0 X10 FA0 F10 FCSR ..."; msg_err = 1; return 0; }
|
||||||
draw_regs(); draw_dis(); draw_stack(); draw_mem();
|
draw_regs(); draw_dis(); draw_stack(); draw_mem();
|
||||||
return 0;
|
return 0;
|
||||||
case '?':
|
case '?':
|
||||||
|
|||||||
+1187
-1187
File diff suppressed because it is too large.
Load diff
+32
-10
@@ -56,8 +56,7 @@ module basys3_terminal #(
|
|||||||
input PS2Clk,
|
input PS2Clk,
|
||||||
input PS2Data,
|
input PS2Data,
|
||||||
output QspiCSn,
|
output QspiCSn,
|
||||||
inout [3:0] QspiDB,
|
inout [3:0] QspiDB
|
||||||
output [3:0] JA // PmodAMP2: audio in, gain, -, shutdown (low)
|
|
||||||
);
|
);
|
||||||
localparam [7:0] XON = 8'h11, XOFF = 8'h13;
|
localparam [7:0] XON = 8'h11, XOFF = 8'h13;
|
||||||
|
|
||||||
@@ -127,9 +126,34 @@ module basys3_terminal #(
|
|||||||
.clk(clk), .rst(rst | ~rv_mode), .code(scan), .code_valid(scan_valid), .down(keys_down)
|
.clk(clk), .rst(rst | ~rv_mode), .code(scan), .code_valid(scan_valid), .down(keys_down)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ctrl-Alt-Del in computer mode restarts the computer, like BTND (held 1 us)
|
// Ctrl-Alt-Del in computer mode enters the monitor (an NMI, like Pause).
|
||||||
|
// It restarts the computer instead, like BTND (held 1 us), when the monitor
|
||||||
|
// is already running or an NMI is still waiting to be taken (the CPU is
|
||||||
|
// wedged), or when it comes again within 2 s. A press counts only after
|
||||||
|
// Delete has been up for 5 ms, so holding the keys (which repeats Delete)
|
||||||
|
// is one press. Port 62 (the monitor's RESET) restarts the computer too.
|
||||||
|
wire mon_busy, reset_t;
|
||||||
|
(* ASYNC_REG = "TRUE" *) reg [1:0] busy_s = 2'd0;
|
||||||
|
(* ASYNC_REG = "TRUE" *) reg [2:0] rreq_s = 3'd0;
|
||||||
|
always @(posedge clk) begin
|
||||||
|
busy_s <= {busy_s[0], mon_busy};
|
||||||
|
rreq_s <= {rreq_s[1:0], reset_t};
|
||||||
|
end
|
||||||
|
reg [19:0] del_up = 20'd0; // how long Delete has been up
|
||||||
|
reg [27:0] cad_win = 28'd0; // counts down 2 s after a press
|
||||||
|
reg cad_nmi_t = 1'b0; // toggles: enter the monitor
|
||||||
|
wire del_held = keys_down[8'h71] | keys_down[8'hF1];
|
||||||
|
wire cad_new = cad && rv_mode && del_up[19];
|
||||||
|
wire cad_rst = cad_new && (busy_s[1] || cad_win != 0);
|
||||||
reg [6:0] cad_t = 7'd0;
|
reg [6:0] cad_t = 7'd0;
|
||||||
always @(posedge clk) cad_t <= cad && rv_mode ? 7'd100 : cad_t - (cad_t != 0);
|
always @(posedge clk) begin
|
||||||
|
if (rst || del_held || (cad && rv_mode)) del_up <= 20'd0;
|
||||||
|
else del_up <= del_up + {19'd0, !del_up[19]};
|
||||||
|
if (rst) cad_win <= 28'd0;
|
||||||
|
else cad_win <= cad_new ? CLK_HZ * 2 : cad_win - (cad_win != 0);
|
||||||
|
if (cad_new && !cad_rst) cad_nmi_t <= ~cad_nmi_t;
|
||||||
|
cad_t <= cad_rst || (rreq_s[2] ^ rreq_s[1]) ? 7'd100 : cad_t - (cad_t != 0);
|
||||||
|
end
|
||||||
|
|
||||||
// ----------------------------------------------------------- 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
|
||||||
@@ -345,6 +369,8 @@ module basys3_terminal #(
|
|||||||
always @(posedge clk) if (scan_valid && scan == 8'hE1 && rv_mode) brk_t <= ~brk_t;
|
always @(posedge clk) if (scan_valid && scan == 8'hE1 && rv_mode) brk_t <= ~brk_t;
|
||||||
(* ASYNC_REG = "TRUE" *) reg [2:0] brk_s = 3'd0;
|
(* ASYNC_REG = "TRUE" *) reg [2:0] brk_s = 3'd0;
|
||||||
always @(posedge cpu_clk) brk_s <= {brk_s[1:0], brk_t};
|
always @(posedge cpu_clk) brk_s <= {brk_s[1:0], brk_t};
|
||||||
|
(* ASYNC_REG = "TRUE" *) reg [2:0] cad_s = 3'd0;
|
||||||
|
always @(posedge cpu_clk) cad_s <= {cad_s[1:0], cad_nmi_t};
|
||||||
|
|
||||||
wire wide; // DECCOLM from the terminal (term_ctrl below)
|
wire wide; // DECCOLM from the terminal (term_ctrl below)
|
||||||
rv32_system #(.MEM_FILE(MEM_FILE), .MEM_HI_FILE(MEM_HI_FILE), .MON_FILE(MON_FILE), .CPU_HZ(CPU_HZ), .ROM_TOP(ROM_TOP)) sys (
|
rv32_system #(.MEM_FILE(MEM_FILE), .MEM_HI_FILE(MEM_HI_FILE), .MON_FILE(MON_FILE), .CPU_HZ(CPU_HZ), .ROM_TOP(ROM_TOP)) sys (
|
||||||
@@ -352,19 +378,15 @@ module basys3_terminal #(
|
|||||||
.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), .wide(wide),
|
.tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack), .wide(wide),
|
||||||
.seg_val(rv_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]),
|
.seg_val(rv_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]),
|
||||||
|
.cad_key(cad_s[2] ^ cad_s[1]), .mon_busy(mon_busy), .reset_t(reset_t),
|
||||||
.vclk(pix_clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
.vclk(pix_clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
||||||
.scroll_x(scroll_x), .scroll_y(scroll_y), .g_border(g_border),
|
.scroll_x(scroll_x), .scroll_y(scroll_y), .g_border(g_border),
|
||||||
.g_hires(g_hires), .g_cols(g_cols),
|
.g_hires(g_hires), .g_cols(g_cols),
|
||||||
.sp_go(sp_go), .sp_line(sp_line), .sp_buf(sp_buf), .sp_x(sp_x), .sp_on(sp_on),
|
.sp_go(sp_go), .sp_line(sp_line), .sp_buf(sp_buf), .sp_x(sp_x), .sp_on(sp_on),
|
||||||
.sp_pix(sp_pix), .sp_ftick(pix_frame), .keys(keys_down),
|
.sp_pix(sp_pix), .sp_ftick(pix_frame), .keys(keys_down),
|
||||||
.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])
|
||||||
.audio(JA[0])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// PmodAMP2 on JA's top row: gain high is 6 dB (low would be 12 dB), and
|
|
||||||
// the amplifier is on unless its shutdown pin is low.
|
|
||||||
assign JA[3:1] = 3'b101;
|
|
||||||
|
|
||||||
// The flash clock is the configuration clock pin, reached through STARTUPE2.
|
// The flash clock is the configuration clock pin, reached through STARTUPE2.
|
||||||
// DQ2/DQ3 (write protect, hold) stay high.
|
// DQ2/DQ3 (write protect, hold) stay high.
|
||||||
assign QspiDB[1] = 1'bz;
|
assign QspiDB[1] = 1'bz;
|
||||||
|
|||||||
+11
-14
@@ -42,8 +42,9 @@
|
|||||||
// 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 1 = stop again (NMI) after one instruction of the program
|
// 60 out bit 1 = stop again (NMI) after one instruction of the program
|
||||||
// in why the last NMI came: 1 Pause key, 2 port 61, 3 step,
|
// in why the last NMI came: 1 Pause key, 2 port 61, 3 step,
|
||||||
// 4 breakpoint 0, 5 breakpoint 1
|
// 4 breakpoint 0, 5 breakpoint 1, 6 Ctrl-Alt-Del
|
||||||
// 61 out enter the monitor (NMI)
|
// 61 out enter the monitor (NMI)
|
||||||
|
// 62 out restart the computer (as BTND does; the monitor's RESET)
|
||||||
// 67 out bit 0 = breakpoint 0 on, bit 1 = breakpoint 1 on
|
// 67 out bit 0 = breakpoint 0 on, bit 1 = breakpoint 1 on
|
||||||
// 70-78, 80-87 sprites (see sprites.v)
|
// 70-78, 80-87 sprites (see sprites.v)
|
||||||
// 88 in keys held: bit 0 up (W, cursor or keypad 8), 1 down (S, 2), 2 left
|
// 88 in keys held: bit 0 up (W, cursor or keypad 8), 1 down (S, 2), 2 left
|
||||||
@@ -51,7 +52,6 @@
|
|||||||
// 7 Esc
|
// 7 Esc
|
||||||
// 89 out pick a scan code (set 2; add 128 for an E0 code)
|
// 89 out pick a scan code (set 2; add 128 for an E0 code)
|
||||||
// in 1 if that key is held, else 0
|
// in 1 if that key is held, else 0
|
||||||
// 90-9D sound (see sound.v)
|
|
||||||
// The Z-80's debug-read ports (62-64) are gone: the monitor runs in the same
|
// The Z-80's debug-read ports (62-64) are gone: the monitor runs in the same
|
||||||
// address space as the program. Its breakpoint addresses are 32 bits, below.
|
// address space as the program. Its breakpoint addresses are 32 bits, below.
|
||||||
//
|
//
|
||||||
@@ -88,6 +88,9 @@ module rv32_system #(
|
|||||||
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
|
input brk_key, // pulse: the Pause key, enter the monitor
|
||||||
|
input cad_key, // pulse: Ctrl-Alt-Del, enter the monitor too
|
||||||
|
output mon_busy, // the monitor runs, or an NMI waits to be taken
|
||||||
|
output reg reset_t = 1'b0, // toggles: port 62, restart the computer
|
||||||
// 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,
|
||||||
@@ -111,9 +114,7 @@ module rv32_system #(
|
|||||||
output fl_cs_n,
|
output fl_cs_n,
|
||||||
output fl_sck,
|
output fl_sck,
|
||||||
output fl_mosi,
|
output fl_mosi,
|
||||||
input fl_miso,
|
input fl_miso
|
||||||
// sound, for a PmodAMP2
|
|
||||||
output audio
|
|
||||||
);
|
);
|
||||||
localparam [31:0] MON_BASE = 32'h0002_0000;
|
localparam [31:0] MON_BASE = 32'h0002_0000;
|
||||||
assign halted = 1'b0;
|
assign halted = 1'b0;
|
||||||
@@ -366,13 +367,6 @@ module rv32_system #(
|
|||||||
.rd_on(sp_on), .pix(sp_pix), .gfx_pix(gfx_vpix), .ftick(sp_ftick)
|
.rd_on(sp_on), .pix(sp_pix), .gfx_pix(gfx_vpix), .ftick(sp_ftick)
|
||||||
);
|
);
|
||||||
|
|
||||||
// ---------------------------------------------------------------- sound
|
|
||||||
wire [7:0] snd_q;
|
|
||||||
sound #(.CPU_HZ(CPU_HZ)) snd (
|
|
||||||
.clk(clk), .rst(rst), .hush(io_wr && io_addr == 8'h34 && !io_wd[7]),
|
|
||||||
.io_wr(io_wr), .io_port(io_addr), .io_wd(io_wd), .io_q(snd_q), .audio(audio)
|
|
||||||
);
|
|
||||||
|
|
||||||
// ---------------------------------------------------------- held keys
|
// ---------------------------------------------------------- held keys
|
||||||
// The keyboard's clock writes these; a bit that changes while it is read
|
// The keyboard's clock writes these; a bit that changes while it is read
|
||||||
// just reads as before or after.
|
// just reads as before or after.
|
||||||
@@ -447,6 +441,8 @@ module rv32_system #(
|
|||||||
if (!nmi_r && !in_mon) begin
|
if (!nmi_r && !in_mon) begin
|
||||||
if (brk_key) begin
|
if (brk_key) begin
|
||||||
nmi_r <= 1'b1; why_r <= 3'd1;
|
nmi_r <= 1'b1; why_r <= 3'd1;
|
||||||
|
end else if (cad_key) begin
|
||||||
|
nmi_r <= 1'b1; why_r <= 3'd6;
|
||||||
end else if (io_wr && io_addr == 8'h61) begin
|
end else if (io_wr && io_addr == 8'h61) begin
|
||||||
nmi_r <= 1'b1; why_r <= 3'd2;
|
nmi_r <= 1'b1; why_r <= 3'd2;
|
||||||
end
|
end
|
||||||
@@ -459,6 +455,9 @@ module rv32_system #(
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assign mon_busy = nmi_r || in_mon;
|
||||||
|
always @(posedge clk) if (io_wr && io_addr == 8'h62) reset_t <= ~reset_t;
|
||||||
|
|
||||||
(* ASYNC_REG = "TRUE" *) reg [1:0] wide_s = 2'b00;
|
(* ASYNC_REG = "TRUE" *) reg [1:0] wide_s = 2'b00;
|
||||||
always @(posedge clk) wide_s <= {wide_s[0], wide};
|
always @(posedge clk) wide_s <= {wide_s[0], wide};
|
||||||
|
|
||||||
@@ -480,8 +479,6 @@ module rv32_system #(
|
|||||||
io_din = spr_q;
|
io_din = spr_q;
|
||||||
8'h88: io_din = joy;
|
8'h88: io_din = joy;
|
||||||
8'h89: io_din = {7'd0, keys[key_sel]};
|
8'h89: io_din = {7'd0, keys[key_sel]};
|
||||||
8'h98, 8'h99, 8'h9A:
|
|
||||||
io_din = snd_q;
|
|
||||||
default: io_din = 8'hFF;
|
default: io_din = 8'hFF;
|
||||||
endcase
|
endcase
|
||||||
always @* case (io_a[7:0])
|
always @* case (io_a[7:0])
|
||||||
|
|||||||
-173
@@ -1,173 +0,0 @@
|
|||||||
`timescale 1ns / 1ps
|
|
||||||
// A small sound chip for the Z-80, in the style of the 8-bit era's
|
|
||||||
// programmable sound generators, played through a Digilent PmodAMP2.
|
|
||||||
//
|
|
||||||
// Three square-wave voices and a noise source. Each voice plays its tone,
|
|
||||||
// the noise, or both (the mixer), at one of 16 volumes on a log scale (about
|
|
||||||
// 3 dB a step). A volume write starts an envelope: an optional rise from 0 at
|
|
||||||
// the attack rate, then an optional fall to 0 at the decay rate, so a game
|
|
||||||
// can fire off a shot or an explosion with a few OUTs and leave it.
|
|
||||||
//
|
|
||||||
// 90h/91h voice 0 pitch, low byte / high 4 bits frequency = 125000 / pitch Hz
|
|
||||||
// 92h/93h voice 1 pitch (pitch 0 counts as 1)
|
|
||||||
// 94h/95h voice 2 pitch
|
|
||||||
// 96h noise pitch, 0-31: higher is lower and rougher
|
|
||||||
// 97h mixer: bits 0-2 tone on for voices 0-2, bits 3-5 noise on for them
|
|
||||||
// 98h-9Ah voice 0-2 volume 0-15, which (re)starts its envelope; reading
|
|
||||||
// gives the volume it is at now, so 0 means the sound has ended
|
|
||||||
// 9Bh-9Dh voice 0-2 envelope: high nibble attack, low nibble decay, each
|
|
||||||
// n x 4 ms a volume step (0 = jump straight up / hold)
|
|
||||||
//
|
|
||||||
// A voice with neither its tone nor the noise on outputs a steady level, as
|
|
||||||
// on the old chips. `hush` (CLS) and reset silence everything.
|
|
||||||
//
|
|
||||||
// The three voices are added up and turned into a single bit by a first-order
|
|
||||||
// sigma-delta modulator at the full clock rate; the PmodAMP2 filters it and
|
|
||||||
// drives headphones or a speaker.
|
|
||||||
module sound #(
|
|
||||||
parameter CPU_HZ = 100_000_000
|
|
||||||
) (
|
|
||||||
input clk,
|
|
||||||
input rst,
|
|
||||||
input hush,
|
|
||||||
input io_wr,
|
|
||||||
input [7:0] io_port,
|
|
||||||
input [7:0] io_wd,
|
|
||||||
output reg [7:0] io_q, // for reads of 98h-9Ah
|
|
||||||
output reg audio = 1'b0
|
|
||||||
);
|
|
||||||
localparam TICK_DIV = CPU_HZ / 250_000; // tone counters run at 250 kHz
|
|
||||||
localparam MS4_DIV = CPU_HZ / 250; // envelope steps in 4 ms units
|
|
||||||
|
|
||||||
reg [11:0] pitch [0:2];
|
|
||||||
reg [4:0] npitch;
|
|
||||||
reg [5:0] mixer;
|
|
||||||
reg [3:0] vol [0:2]; // the volume asked for
|
|
||||||
reg [3:0] cur [0:2]; // the volume now
|
|
||||||
reg [3:0] att [0:2], dec [0:2];
|
|
||||||
reg rising [0:2];
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------- ticks
|
|
||||||
reg [9:0] tdiv = 10'd0;
|
|
||||||
reg tick = 1'b0;
|
|
||||||
reg [19:0] ediv = 20'd0;
|
|
||||||
reg etick = 1'b0;
|
|
||||||
always @(posedge clk) begin
|
|
||||||
tick <= tdiv == 0;
|
|
||||||
tdiv <= tdiv == 0 ? TICK_DIV - 1 : tdiv - 1'b1;
|
|
||||||
etick <= ediv == 0;
|
|
||||||
ediv <= ediv == 0 ? MS4_DIV - 1 : ediv - 1'b1;
|
|
||||||
end
|
|
||||||
|
|
||||||
// --------------------------------------------------------------- voices
|
|
||||||
reg [11:0] tcnt [0:2];
|
|
||||||
reg [2:0] tone = 3'd0;
|
|
||||||
reg [4:0] ncnt = 5'd0;
|
|
||||||
reg [16:0] lfsr = 17'd1;
|
|
||||||
reg [3:0] ecnt [0:2];
|
|
||||||
integer i;
|
|
||||||
initial for (i = 0; i < 3; i = i + 1) begin
|
|
||||||
tcnt[i] = 12'd0; ecnt[i] = 4'd0; cur[i] = 4'd0; vol[i] = 4'd0;
|
|
||||||
end
|
|
||||||
|
|
||||||
always @(posedge clk) begin
|
|
||||||
if (rst || hush) begin
|
|
||||||
for (i = 0; i < 3; i = i + 1) begin
|
|
||||||
vol[i] <= 4'd0; cur[i] <= 4'd0; rising[i] <= 1'b0;
|
|
||||||
if (rst) begin pitch[i] <= 12'd0; att[i] <= 4'd0; dec[i] <= 4'd0; end
|
|
||||||
end
|
|
||||||
mixer <= 6'd0;
|
|
||||||
if (rst) begin npitch <= 5'd0; lfsr <= 17'd1; tone <= 3'd0; end
|
|
||||||
end else begin
|
|
||||||
if (io_wr) case (io_port)
|
|
||||||
8'h90: pitch[0][7:0] <= io_wd;
|
|
||||||
8'h91: pitch[0][11:8] <= io_wd[3:0];
|
|
||||||
8'h92: pitch[1][7:0] <= io_wd;
|
|
||||||
8'h93: pitch[1][11:8] <= io_wd[3:0];
|
|
||||||
8'h94: pitch[2][7:0] <= io_wd;
|
|
||||||
8'h95: pitch[2][11:8] <= io_wd[3:0];
|
|
||||||
8'h96: npitch <= io_wd[4:0];
|
|
||||||
8'h97: mixer <= io_wd[5:0];
|
|
||||||
8'h9B: {att[0], dec[0]} <= io_wd;
|
|
||||||
8'h9C: {att[1], dec[1]} <= io_wd;
|
|
||||||
8'h9D: {att[2], dec[2]} <= io_wd;
|
|
||||||
default: ;
|
|
||||||
endcase
|
|
||||||
|
|
||||||
// tones: each output flips every `pitch` ticks
|
|
||||||
if (tick) begin
|
|
||||||
for (i = 0; i < 3; i = i + 1)
|
|
||||||
if (tcnt[i] <= 12'd1) begin
|
|
||||||
tcnt[i] <= pitch[i];
|
|
||||||
tone[i] <= ~tone[i];
|
|
||||||
end else
|
|
||||||
tcnt[i] <= tcnt[i] - 1'b1;
|
|
||||||
if (ncnt == 0) begin
|
|
||||||
ncnt <= npitch;
|
|
||||||
lfsr <= {lfsr[0] ^ lfsr[3], lfsr[16:1]};
|
|
||||||
end else
|
|
||||||
ncnt <= ncnt - 1'b1;
|
|
||||||
end
|
|
||||||
|
|
||||||
// envelopes
|
|
||||||
for (i = 0; i < 3; i = i + 1) begin
|
|
||||||
if (io_wr && io_port == 8'h98 + i) begin
|
|
||||||
vol[i] <= io_wd[3:0];
|
|
||||||
ecnt[i] <= 4'd0;
|
|
||||||
if (att[i] != 0 && io_wd[3:0] != 0) begin
|
|
||||||
cur[i] <= 4'd0; rising[i] <= 1'b1;
|
|
||||||
end else begin
|
|
||||||
cur[i] <= io_wd[3:0]; rising[i] <= 1'b0;
|
|
||||||
end
|
|
||||||
end else if (etick) begin
|
|
||||||
if (rising[i]) begin
|
|
||||||
if (ecnt[i] + 1'b1 >= att[i]) begin
|
|
||||||
ecnt[i] <= 4'd0;
|
|
||||||
cur[i] <= cur[i] + 1'b1;
|
|
||||||
if (cur[i] + 1'b1 >= vol[i]) rising[i] <= 1'b0;
|
|
||||||
end else
|
|
||||||
ecnt[i] <= ecnt[i] + 1'b1;
|
|
||||||
end else if (dec[i] != 0 && cur[i] != 0) begin
|
|
||||||
if (ecnt[i] + 1'b1 >= dec[i]) begin
|
|
||||||
ecnt[i] <= 4'd0;
|
|
||||||
cur[i] <= cur[i] - 1'b1;
|
|
||||||
end else
|
|
||||||
ecnt[i] <= ecnt[i] + 1'b1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
always @* case (io_port)
|
|
||||||
8'h98: io_q = {4'd0, cur[0]};
|
|
||||||
8'h99: io_q = {4'd0, cur[1]};
|
|
||||||
8'h9A: io_q = {4'd0, cur[2]};
|
|
||||||
default: io_q = 8'hFF;
|
|
||||||
endcase
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------- mixing
|
|
||||||
function [7:0] level(input [3:0] v); // about 3 dB a step
|
|
||||||
case (v)
|
|
||||||
4'd0: level = 8'd0; 4'd1: level = 8'd2; 4'd2: level = 8'd3; 4'd3: level = 8'd4;
|
|
||||||
4'd4: level = 8'd6; 4'd5: level = 8'd8; 4'd6: level = 8'd11; 4'd7: level = 8'd16;
|
|
||||||
4'd8: level = 8'd23; 4'd9: level = 8'd32; 4'd10: level = 8'd45; 4'd11: level = 8'd64;
|
|
||||||
4'd12: level = 8'd90; 4'd13: level = 8'd128; 4'd14: level = 8'd181; default: level = 8'd255;
|
|
||||||
endcase
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
wire [2:0] on;
|
|
||||||
genvar g;
|
|
||||||
generate for (g = 0; g < 3; g = g + 1) begin : mix
|
|
||||||
assign on[g] = (tone[g] | ~mixer[g]) & (lfsr[0] | ~mixer[g + 3]);
|
|
||||||
end endgenerate
|
|
||||||
|
|
||||||
reg [9:0] sum = 10'd0;
|
|
||||||
reg [10:0] acc = 11'd0;
|
|
||||||
always @(posedge clk) begin
|
|
||||||
sum <= (on[0] ? level(cur[0]) : 10'd0) + (on[1] ? level(cur[1]) : 10'd0) +
|
|
||||||
(on[2] ? level(cur[2]) : 10'd0);
|
|
||||||
acc <= rst ? 11'd0 : {1'b0, acc[9:0]} + {1'b0, sum}; // carry out = the output bit
|
|
||||||
audio <= acc[10];
|
|
||||||
end
|
|
||||||
endmodule
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
# Run the sound chip's testbench (sim/tb_sound.v) in Vivado's simulator.
|
|
||||||
set -e
|
|
||||||
cd "$(dirname "$0")/.."
|
|
||||||
ROOT=$(pwd)
|
|
||||||
source scripts/vivado_env.sh
|
|
||||||
mkdir -p sim/work-sound
|
|
||||||
cd sim/work-sound
|
|
||||||
xvlog "$ROOT"/rtl/sound.v "$ROOT"/sim/tb_sound.v
|
|
||||||
xelab -debug typical tb_sound -s tb_sound
|
|
||||||
xsim tb_sound -R
|
|
||||||
-142
@@ -1,142 +0,0 @@
|
|||||||
`timescale 1ns / 1ps
|
|
||||||
// Testbench for rtl/sound.v at the Z-80's 90 MHz clock: pitch, mixer, noise,
|
|
||||||
// volume levels, the attack and decay envelopes, reading back and hushing.
|
|
||||||
// scripts/sim-sound.sh
|
|
||||||
module tb_sound;
|
|
||||||
reg clk = 0, rst = 1, hush = 0, io_wr = 0;
|
|
||||||
reg [7:0] port = 0, wd = 0;
|
|
||||||
wire [7:0] q;
|
|
||||||
wire audio;
|
|
||||||
integer errors = 0;
|
|
||||||
|
|
||||||
sound #(.CPU_HZ(90_000_000)) dut (
|
|
||||||
.clk(clk), .rst(rst), .hush(hush), .io_wr(io_wr), .io_port(port), .io_wd(wd),
|
|
||||||
.io_q(q), .audio(audio)
|
|
||||||
);
|
|
||||||
always #5.556 clk = ~clk;
|
|
||||||
|
|
||||||
task out(input [7:0] p, input [7:0] v);
|
|
||||||
begin
|
|
||||||
@(posedge clk) begin port <= p; wd <= v; io_wr <= 1; end
|
|
||||||
@(posedge clk) io_wr <= 0;
|
|
||||||
end
|
|
||||||
endtask
|
|
||||||
|
|
||||||
task rd(input [7:0] p); // q then holds the port's value
|
|
||||||
begin port = p; #1; end
|
|
||||||
endtask
|
|
||||||
|
|
||||||
task check(input [8*48-1:0] what, input ok);
|
|
||||||
begin
|
|
||||||
if (ok) $display("PASS %0s", what);
|
|
||||||
else begin $display("FAIL %0s", what); errors = errors + 1; end
|
|
||||||
end
|
|
||||||
endtask
|
|
||||||
|
|
||||||
// count rising edges of voice 0's tone over a time, and the output's duty
|
|
||||||
integer edges, ones, total;
|
|
||||||
real t0, duty;
|
|
||||||
task measure(input real ms);
|
|
||||||
begin
|
|
||||||
edges = 0; ones = 0; total = 0;
|
|
||||||
t0 = $realtime;
|
|
||||||
while ($realtime - t0 < ms * 1e6) begin
|
|
||||||
@(posedge clk);
|
|
||||||
total = total + 1;
|
|
||||||
ones = ones + audio;
|
|
||||||
end
|
|
||||||
duty = 1.0 * ones / total;
|
|
||||||
end
|
|
||||||
endtask
|
|
||||||
reg t_prev = 0;
|
|
||||||
integer tone_edges = 0;
|
|
||||||
always @(posedge clk) begin
|
|
||||||
t_prev <= dut.tone[0];
|
|
||||||
if (dut.tone[0] && !t_prev) tone_edges = tone_edges + 1;
|
|
||||||
end
|
|
||||||
|
|
||||||
real d15, d7;
|
|
||||||
integer n0, v, k, rose_at, fell_at;
|
|
||||||
initial begin
|
|
||||||
repeat (10) @(posedge clk);
|
|
||||||
rst = 0;
|
|
||||||
repeat (10) @(posedge clk);
|
|
||||||
measure(1.0);
|
|
||||||
check("no output after reset", ones == 0);
|
|
||||||
|
|
||||||
// voice 0 at 440 Hz: 125000 / 284 = 440.1
|
|
||||||
out(8'h90, 284 % 256); out(8'h91, 284 / 256);
|
|
||||||
out(8'h97, 8'b000_001);
|
|
||||||
out(8'h98, 8'd15);
|
|
||||||
n0 = tone_edges;
|
|
||||||
measure(50.0);
|
|
||||||
$display(" voice 0: %0d cycles in 50 ms (%.1f Hz), duty %.3f", tone_edges - n0,
|
|
||||||
(tone_edges - n0) / 0.05, duty);
|
|
||||||
check("pitch 284 plays about 440 Hz", tone_edges - n0 >= 21 && tone_edges - n0 <= 23);
|
|
||||||
d15 = duty;
|
|
||||||
check("one voice at full volume: high 1/8 of the time", d15 > 0.11 && d15 < 0.13);
|
|
||||||
out(8'h98, 8'd7);
|
|
||||||
measure(50.0);
|
|
||||||
d7 = duty;
|
|
||||||
$display(" volume 15 duty %.4f, volume 7 duty %.4f (ratio %.1f)", d15, d7, d15 / d7);
|
|
||||||
check("volume 7 is about 24 dB quieter", d15 / d7 > 12 && d15 / d7 < 20);
|
|
||||||
rd(8'h98);
|
|
||||||
check("volume reads back", q == 8'd7);
|
|
||||||
|
|
||||||
// decay: 15 steps of 2 x 4 ms from 15 = 120 ms
|
|
||||||
out(8'h9B, 8'h02);
|
|
||||||
out(8'h98, 8'd15);
|
|
||||||
t0 = $realtime;
|
|
||||||
wait (dut.cur[0] == 0);
|
|
||||||
$display(" decay from 15 took %.1f ms", ($realtime - t0) / 1e6);
|
|
||||||
check("decay 2 fades 15 steps in 120 ms", ($realtime - t0) / 1e6 > 115 && ($realtime - t0) / 1e6 < 125);
|
|
||||||
rd(8'h98);
|
|
||||||
check("a finished sound reads back 0", q == 8'd0);
|
|
||||||
|
|
||||||
// attack then decay: up 12 steps of 1 x 4 ms, then down
|
|
||||||
out(8'h9B, 8'h13);
|
|
||||||
out(8'h98, 8'd12);
|
|
||||||
t0 = $realtime;
|
|
||||||
check("attack starts from 0", dut.cur[0] == 0);
|
|
||||||
wait (dut.cur[0] == 12);
|
|
||||||
rose_at = ($realtime - t0) / 1e6;
|
|
||||||
wait (dut.cur[0] == 0);
|
|
||||||
fell_at = ($realtime - t0) / 1e6;
|
|
||||||
$display(" attack reached 12 at %0d ms, faded out at %0d ms", rose_at, fell_at);
|
|
||||||
check("attack 1 rises 12 steps in 48 ms", rose_at >= 46 && rose_at <= 50);
|
|
||||||
check("decay 3 then falls 12 steps in 144 ms", fell_at - rose_at >= 140 && fell_at - rose_at <= 150);
|
|
||||||
|
|
||||||
// noise on voice 1, no tone
|
|
||||||
out(8'h96, 8'd4);
|
|
||||||
out(8'h97, 8'b010_000);
|
|
||||||
out(8'h9C, 8'h00);
|
|
||||||
out(8'h99, 8'd15);
|
|
||||||
n0 = 0;
|
|
||||||
for (k = 0; k < 2000; k = k + 1) begin
|
|
||||||
repeat (360) @(posedge clk);
|
|
||||||
n0 = n0 + dut.lfsr[0];
|
|
||||||
end
|
|
||||||
$display(" noise was high %0d of 2000 samples", n0);
|
|
||||||
check("noise is about half high, half low", n0 > 800 && n0 < 1200);
|
|
||||||
|
|
||||||
// all three voices and CLS
|
|
||||||
out(8'h92, 8'd142); out(8'h94, 8'd71);
|
|
||||||
out(8'h97, 8'b000_111);
|
|
||||||
out(8'h98, 8'd15); out(8'h99, 8'd15); out(8'h9A, 8'd15);
|
|
||||||
measure(20.0);
|
|
||||||
check("three voices make sound", duty > 0.2);
|
|
||||||
@(posedge clk) hush <= 1;
|
|
||||||
@(posedge clk) hush <= 0;
|
|
||||||
repeat (4) @(posedge clk); // what was already in the mixer
|
|
||||||
measure(2.0);
|
|
||||||
$display(" after CLS: output high %0d times in 2 ms", ones);
|
|
||||||
rd(8'h99);
|
|
||||||
check("CLS silences everything", ones == 0 && q == 0);
|
|
||||||
rd(8'h97);
|
|
||||||
check("other ports read FFh", q == 8'hFF);
|
|
||||||
|
|
||||||
if (errors == 0) $display("ALL SOUND TESTS PASSED");
|
|
||||||
else $display("%0d SOUND TESTS FAILED", errors);
|
|
||||||
$finish;
|
|
||||||
end
|
|
||||||
endmodule
|
|
||||||
+66
-12
@@ -52,6 +52,16 @@ module tb_terminal;
|
|||||||
end
|
end
|
||||||
endtask
|
endtask
|
||||||
|
|
||||||
|
// Ctrl-Alt-Del pressed and let go (Delete as E0 71), then 10 ms
|
||||||
|
task cad_press;
|
||||||
|
begin
|
||||||
|
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);
|
||||||
|
#10_000_000;
|
||||||
|
end
|
||||||
|
endtask
|
||||||
|
|
||||||
task ps2_send(input [7:0] d);
|
task ps2_send(input [7:0] d);
|
||||||
integer i;
|
integer i;
|
||||||
reg [10:0] f;
|
reg [10:0] f;
|
||||||
@@ -201,6 +211,34 @@ module tb_terminal;
|
|||||||
end
|
end
|
||||||
endtask
|
endtask
|
||||||
|
|
||||||
|
// the restarted BASIC's banner, on whichever row it lands, on the main
|
||||||
|
// screen (BASIC leaves the monitor's alternate screen as it starts)
|
||||||
|
task wait_banner(input [8*48-1:0] what);
|
||||||
|
realtime t0;
|
||||||
|
integer br, seen;
|
||||||
|
reg [7:0] b0, b1, b2;
|
||||||
|
begin
|
||||||
|
t0 = $realtime;
|
||||||
|
seen = 0;
|
||||||
|
while (!seen && $realtime - t0 < 500_000_000) begin
|
||||||
|
#100_000;
|
||||||
|
// one cellraw() at a time: several in one expression read wrong
|
||||||
|
for (br = 0; br < 32; br = br + 1) begin
|
||||||
|
b0 = cellraw(br, 0); b1 = cellraw(br, 1); b2 = cellraw(br, 2);
|
||||||
|
if ({b0, b1, b2} == "DAR") seen = 1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (seen && !dut.alt_scr) $display("PASS %0s", what);
|
||||||
|
else begin
|
||||||
|
$display("FAIL %0s: banner %0s, alternate screen %b", what,
|
||||||
|
seen ? "seen" : "not seen", dut.alt_scr);
|
||||||
|
errors = errors + 1;
|
||||||
|
dump_screen;
|
||||||
|
end
|
||||||
|
#5_000_000;
|
||||||
|
end
|
||||||
|
endtask
|
||||||
|
|
||||||
reg [31:0] pc_a, pc_b, jp_to;
|
reg [31:0] pc_a, pc_b, jp_to;
|
||||||
reg [15:0] jp_txt;
|
reg [15:0] jp_txt;
|
||||||
integer i;
|
integer i;
|
||||||
@@ -623,9 +661,9 @@ module tb_terminal;
|
|||||||
// the float registers, in place of the memory window, and setting one
|
// the float registers, in place of the memory window, and setting one
|
||||||
uart_str("F\015");
|
uart_str("F\015");
|
||||||
wait_at(21, 0, " FLOAT REGISTERS");
|
wait_at(21, 0, " FLOAT REGISTERS");
|
||||||
wait_at(22, 0, " F0 ");
|
wait_at(22, 0, "FT0 ");
|
||||||
uart_str("R F1=3FC00000\015");
|
uart_str("R F1=3FC00000\015");
|
||||||
wait_at(22, 13, " F1 3FC00000");
|
wait_at(22, 13, "FT1 3FC00000");
|
||||||
uart_str("M\015");
|
uart_str("M\015");
|
||||||
wait_at(21, 0, " MEMORY");
|
wait_at(21, 0, " MEMORY");
|
||||||
uart_str("\015"); // Enter: one step
|
uart_str("\015"); // Enter: one step
|
||||||
@@ -716,16 +754,32 @@ module tb_terminal;
|
|||||||
uart_str("CLS:CALL 73728\015");
|
uart_str("CLS:CALL 73728\015");
|
||||||
wait_row(0, "ASM OK");
|
wait_row(0, "ASM OK");
|
||||||
|
|
||||||
// ---- Ctrl-Alt-Del restarts the computer
|
// ---- Ctrl-Alt-Del: into the monitor, even with interrupts off in a
|
||||||
ps2_send(8'h14); ps2_send(8'h11); ps2_send(8'hE0); ps2_send(8'h71);
|
// tight loop; again (within 2 s, or in the monitor) restarts the computer
|
||||||
ps2_send(8'hE0); ps2_send(8'hF0); ps2_send(8'h71); ps2_send(8'hF0); ps2_send(8'h11);
|
// csrci mstatus,8 (interrupts off) at 12000, then j . at 12004
|
||||||
ps2_send(8'hF0); ps2_send(8'h14);
|
uart_str("CLS:POKE 73728,115:POKE 73729,112:POKE 73730,4:POKE 73731,48\015");
|
||||||
// the restarted BASIC's banner, on whichever row it lands
|
uart_str("POKE 73732,111:POKE 73733,0:POKE 73734,0:POKE 73735,0\015");
|
||||||
t_cmd = $realtime;
|
#5_000_000;
|
||||||
while ({cellraw(2, 0), cellraw(2, 1)} != "DA" && {cellraw(3, 0), cellraw(3, 1)} != "DA" &&
|
uart_str("CALL 73728\015"); // hangs at 12004, interrupts off
|
||||||
{cellraw(4, 0), cellraw(4, 1)} != "DA" && $realtime - t_cmd < 50_000_000) #100_000;
|
#5_000_000;
|
||||||
if ($realtime - t_cmd < 50_000_000) $display("PASS Ctrl-Alt-Del restarted BASIC");
|
cad_press;
|
||||||
else begin $display("FAIL Ctrl-Alt-Del: no banner"); errors = errors + 1; end
|
wait_at(0, 50, "STOPPED BY CTRL-ALT-DEL");
|
||||||
|
if (screen_pc(0) == 32'h12004) $display("PASS Ctrl-Alt-Del stopped the loop at 12004");
|
||||||
|
else begin $display("FAIL Ctrl-Alt-Del: PC %h", screen_pc(0)); errors = errors + 1; end
|
||||||
|
uart_str("X\015"); // back into the loop
|
||||||
|
#10_000_000;
|
||||||
|
cad_press; // within 2 s: restart
|
||||||
|
wait_banner("Ctrl-Alt-Del twice restarted BASIC");
|
||||||
|
// a trap goes to the monitor; Ctrl-Alt-Del there restarts
|
||||||
|
uart_str("CLS:POKE 73728,0:POKE 73729,0:POKE 73730,0:POKE 73731,0:CALL 73728\015");
|
||||||
|
wait_at(0, 50, "STOPPED BY ILLEGAL INSTRUCTI");
|
||||||
|
cad_press;
|
||||||
|
wait_banner("Ctrl-Alt-Del in the monitor restarted BASIC");
|
||||||
|
// the monitor's RESET
|
||||||
|
uart_str("CLS:MONITOR\015");
|
||||||
|
wait_at(29, 0, "> ");
|
||||||
|
uart_str("RESET\015");
|
||||||
|
wait_banner("the monitor's RESET restarted BASIC");
|
||||||
dump_screen;
|
dump_screen;
|
||||||
`endif
|
`endif
|
||||||
if (errors == 0) $display("ALL TESTS PASSED");
|
if (errors == 0) $display("ALL TESTS PASSED");
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ tokens, from basic/basic.c), and turned into C, which GCC compiles. Numbers,
|
|||||||
numeric variables and arrays, arithmetic, and all the control statements
|
numeric variables and arrays, arithmetic, and all the control statements
|
||||||
(GOTO, GOSUB, ON, FOR ... NEXT, IF ... THEN ... ELSE, block IF, DO ... LOOP,
|
(GOTO, GOSUB, ON, FOR ... NEXT, IF ... THEN ... ELSE, block IF, DO ... LOOP,
|
||||||
EXIT, SELECT CASE, END, STOP) become machine code, using the FPU directly.
|
EXIT, SELECT CASE, END, STOP) become machine code, using the FPU directly.
|
||||||
Every other statement (PRINT, INPUT, strings, graphics, sound, files, DATA
|
Every other statement (PRINT, INPUT, strings, graphics, files, DATA
|
||||||
and READ, DEF FN ...) and the functions without a fast path are handed, as
|
and READ, DEF FN ...) and the functions without a fast path are handed, as
|
||||||
tokens, to the interpreter in BASIC's ROM through a fixed jump table at 9F00h
|
tokens, to the interpreter in BASIC's ROM through a fixed jump table at 9F00h
|
||||||
(rt_table in basic.c), so they do exactly what they do interpreted. Control
|
(rt_table in basic.c), so they do exactly what they do interpreted. Control
|
||||||
|
|||||||
Reference in new issue
Block a user