diff --git a/verilator/.gitignore b/verilator/.gitignore index ce93c2a..1aad6c1 100644 --- a/verilator/.gitignore +++ b/verilator/.gitignore @@ -1,6 +1,6 @@ *.vcd -dw_boot* -fujinet_boot*/ +/dw_boot* +/fujinet_boot*/ fujinet_boot/ imgui.ini obj_dir/ diff --git a/verilator/Makefile b/verilator/Makefile index ed48987..3ed5a2a 100644 --- a/verilator/Makefile +++ b/verilator/Makefile @@ -86,6 +86,7 @@ V_SRC = \ rtl/coco_rom.v \ rtl/coco_sram.v \ rtl/VDAC.v \ + rtl/ovo.v \ ../sys/hps_io.sv \ $(RTL)/coco3fpga.sv \ $(RTL)/EE_Cold_Bt.v \ @@ -107,8 +108,7 @@ V_SRC = \ $(RTL)/UART_6551/6551tx.v \ $(RTL)/UART_6551/6551rx.v \ $(RTL)/mc6809glb/mc6809glb.v \ - $(RTL)/Mister_Video.v \ - $(RTL)/Mister_Video_GIMEX.v + $(RTL)/Mister_Video.v C_SRC = \ sim_main.cpp dis6809.cpp serial.cpp \ diff --git a/verilator/README.md b/verilator/README.md index bc451dc..a8bff7c 100644 --- a/verilator/README.md +++ b/verilator/README.md @@ -156,7 +156,9 @@ pty; `tests/fujinet_boot.sh`). `HDB-DOS 1.5 SY6551 COCO 3`, and transmitted nothing. On a real CoCo the SCS line covers only `$FF40-$FF5F`, and the RS-232 Pak decodes `$FF68` from the address bus, so it works in any slot. **Fix:** `RS232_EN` no longer - looks at `MPI_SCS`. + looks at `MPI_SCS`. (Upstream's 20260927 release moved the decode to slots + 2 and 4, `MPI_SCS[0] == 1`; HDB-DOS carts can only boot from slot 3, so + that still missed every access.) 2. **The 19,200 cart received at 115,200.** `HDBDW3L3_19200.CCC` writes control `$0F`. Bit 4 = 0 selects the "external" receive clock, which `uart_6551.v` tied to the 1.8475 MHz enable, i.e. 115,200 baud. The cart @@ -173,7 +175,8 @@ pty; `tests/fujinet_boot.sh`). A reset cleared it, which is why "load cart, then Reset" worked. The OSD's "Cart Interrupt Disabled" option was not connected to anything. **Fix:** a cart that starts with `DK` gets a cold boot instead, the way BASIC starts - it at power-on, and the OSD option now suppresses the autostart interrupt. + it at power-on, and the OSD option (Debug menu, `status[19]` -> + `SWITCH[9]`) now suppresses the autostart interrupt. Program paks behave as before. The sim reproduces both cases with `--cart-frame N`, which loads the cart after boot the way the OSD and MGL do. @@ -229,6 +232,7 @@ names and ports: | `rtl/rom/coco_rom_16.vhd` | `rtl/coco_rom.v` (`COCO_ROM_16`) | | `rtl/rom/coco3_char_rom.vhd` | `rtl/coco_rom.v` (`coco3_Char_ROM`) + `rtl/coco3_char_rom.mem` | | `rtl/sram/coco_ram.vhd`, `coco_vid_ram_buf.vhd` | `rtl/coco_sram.v` (`COCO_SRAM`, `COCO_VID_RAM_BUF`) | +| `rtl/OVO.vhd` (debug / "NO ROM" overlay) | `rtl/ovo.v` (`ovo`) | `make mem` (`gen_mem.py`) regenerates `rtl/coco3_char_rom.mem` from the font table in the VHDL and `rtl/vdac.mem` from `rtl/VDAC.mif`. diff --git a/verilator/rtl/ovo.v b/verilator/rtl/ovo.v new file mode 100644 index 0000000..b1ee94c --- /dev/null +++ b/verilator/rtl/ovo.v @@ -0,0 +1,111 @@ +// Verilog translation of rtl/OVO.vhd (the debug / "NO ROM" text overlay) for the +// simulation, since the simulator cannot read VHDL. Same ports, generics and timing: two +// cycles of video delay, probes latched at Hcount = Vcount = 0, 8x8 font. +// +// VHDL bit order: vin0/vin1 are (0 TO COLS*5-1), so character 0 is the +// leftmost 5 bits of in0/in1, i.e. the first entry of the concatenation in +// coco3fpga.sv; a font row's bit 0 is the leftmost pixel. + +module ovo #( + parameter COLS = 32, + parameter LINES = 2, + parameter RGB = 24'hFFFFFF, + parameter H_OFFSET = 4, + parameter V_OFFSET = 45 +) ( + input [7:0] i_r, + input [7:0] i_g, + input [7:0] i_b, + input i_clk, + + input [10:0] i_Hcount, + input [9:0] i_VCount, + + output reg [7:0] o_r, + output reg [7:0] o_g, + output reg [7:0] o_b, + + input ena, + + input [COLS*5-1:0] in0, + input [COLS*5-1:0] in1 +); + +localparam N = COLS*5; + +reg [7:0] chars [0:255]; +initial begin + {chars[ 0],chars[ 1],chars[ 2],chars[ 3],chars[ 4],chars[ 5],chars[ 6],chars[ 7]} = 64'h3E63737B6F673E00; // 0 + {chars[ 8],chars[ 9],chars[ 10],chars[ 11],chars[ 12],chars[ 13],chars[ 14],chars[ 15]} = 64'h0C0E0C0C0C0C3F00; // 1 + {chars[ 16],chars[ 17],chars[ 18],chars[ 19],chars[ 20],chars[ 21],chars[ 22],chars[ 23]} = 64'h1E33301C06333F00; // 2 + {chars[ 24],chars[ 25],chars[ 26],chars[ 27],chars[ 28],chars[ 29],chars[ 30],chars[ 31]} = 64'h1E33301C30331E00; // 3 + {chars[ 32],chars[ 33],chars[ 34],chars[ 35],chars[ 36],chars[ 37],chars[ 38],chars[ 39]} = 64'h383C36337F307800; // 4 + {chars[ 40],chars[ 41],chars[ 42],chars[ 43],chars[ 44],chars[ 45],chars[ 46],chars[ 47]} = 64'h3F031F3030331E00; // 5 + {chars[ 48],chars[ 49],chars[ 50],chars[ 51],chars[ 52],chars[ 53],chars[ 54],chars[ 55]} = 64'h1C06031F33331E00; // 6 + {chars[ 56],chars[ 57],chars[ 58],chars[ 59],chars[ 60],chars[ 61],chars[ 62],chars[ 63]} = 64'h3F3330180C0C0C00; // 7 + {chars[ 64],chars[ 65],chars[ 66],chars[ 67],chars[ 68],chars[ 69],chars[ 70],chars[ 71]} = 64'h1E33331E33331E00; // 8 + {chars[ 72],chars[ 73],chars[ 74],chars[ 75],chars[ 76],chars[ 77],chars[ 78],chars[ 79]} = 64'h1E33333E30180E00; // 9 + {chars[ 80],chars[ 81],chars[ 82],chars[ 83],chars[ 84],chars[ 85],chars[ 86],chars[ 87]} = 64'h0C1E33333F333300; // A + {chars[ 88],chars[ 89],chars[ 90],chars[ 91],chars[ 92],chars[ 93],chars[ 94],chars[ 95]} = 64'h3F66663E66663F00; // B + {chars[ 96],chars[ 97],chars[ 98],chars[ 99],chars[100],chars[101],chars[102],chars[103]} = 64'h3C66030303663C00; // C + {chars[104],chars[105],chars[106],chars[107],chars[108],chars[109],chars[110],chars[111]} = 64'h1F36666666361F00; // D + {chars[112],chars[113],chars[114],chars[115],chars[116],chars[117],chars[118],chars[119]} = 64'h7F46161E16467F00; // E + {chars[120],chars[121],chars[122],chars[123],chars[124],chars[125],chars[126],chars[127]} = 64'h7F46161E16060F00; // F + {chars[128],chars[129],chars[130],chars[131],chars[132],chars[133],chars[134],chars[135]} = 64'h0000000000000000; // ' ' 10 + {chars[136],chars[137],chars[138],chars[139],chars[140],chars[141],chars[142],chars[143]} = 64'h00003F00003F0000; // = 11 + {chars[144],chars[145],chars[146],chars[147],chars[148],chars[149],chars[150],chars[151]} = 64'h000C0C3F0C0C0000; // + 12 + {chars[152],chars[153],chars[154],chars[155],chars[156],chars[157],chars[158],chars[159]} = 64'h0000003F00000000; // - 13 + {chars[160],chars[161],chars[162],chars[163],chars[164],chars[165],chars[166],chars[167]} = 64'h180C0603060C1800; // < 14 + {chars[168],chars[169],chars[170],chars[171],chars[172],chars[173],chars[174],chars[175]} = 64'h060C1830180C0600; // > 15 + {chars[176],chars[177],chars[178],chars[179],chars[180],chars[181],chars[182],chars[183]} = 64'h081C366341000000; // ^ 16 + {chars[184],chars[185],chars[186],chars[187],chars[188],chars[189],chars[190],chars[191]} = 64'h081C366341000000; // v 17 + {chars[192],chars[193],chars[194],chars[195],chars[196],chars[197],chars[198],chars[199]} = 64'h180C0606060C1800; // ( 18 + {chars[200],chars[201],chars[202],chars[203],chars[204],chars[205],chars[206],chars[207]} = 64'h060C1818180C0600; // ) 19 + {chars[208],chars[209],chars[210],chars[211],chars[212],chars[213],chars[214],chars[215]} = 64'h000C0C00000C0C00; // : 1A + {chars[216],chars[217],chars[218],chars[219],chars[220],chars[221],chars[222],chars[223]} = 64'h4143454951614100; // N 1B + {chars[224],chars[225],chars[226],chars[227],chars[228],chars[229],chars[230],chars[231]} = 64'h3E41414141413E00; // O 1C + {chars[232],chars[233],chars[234],chars[235],chars[236],chars[237],chars[238],chars[239]} = 64'h3F41413F11214100; // R 1D + {chars[240],chars[241],chars[242],chars[243],chars[244],chars[245],chars[246],chars[247]} = 64'h4163554941414100; // M 1E + {chars[248],chars[249],chars[250],chars[251],chars[252],chars[253],chars[254],chars[255]} = 64'h36367F367F363600; // # 1F +end + +reg [N-1:0] in0s, in1s, vin0, vin1; +reg [7:0] t_r, t_g, t_b; +reg [11:0] hcpt, hcpt2, vcpt; +reg [7:0] col; + +wire [N-1:0] vin_v = vcpt[3] ? vin1 : vin0; // (vcpt/8) mod 2 +wire [11:0] cidx = hcpt >> 3; +wire [4:0] char_v = (hcpt < COLS*8 && vcpt < LINES*8) ? vin_v[N-1-cidx*5 -: 5] : 5'b10000; + +always @(posedge i_clk) begin + in0s <= in0; + in1s <= in1; + + t_r <= i_r; + t_g <= i_g; + t_b <= i_b; + + if (i_Hcount == 0 && i_VCount == 0) begin + vin0 <= in0s; + vin1 <= in1s; + end + + hcpt <= (i_Hcount < H_OFFSET) ? COLS*8 : {1'b0, i_Hcount} - H_OFFSET; + vcpt <= (i_VCount < V_OFFSET) ? 12'd512 : {2'b0, i_VCount} - V_OFFSET; + hcpt2 <= hcpt; + + col <= chars[{char_v, vcpt[2:0]}]; + + if (ena && col[hcpt2[2:0]]) begin + o_r <= RGB[23:16]; + o_g <= RGB[15:8]; + o_b <= RGB[7:0]; + end else begin + o_r <= t_r; + o_g <= t_g; + o_b <= t_b; + end +end + +endmodule diff --git a/verilator/sim.v b/verilator/sim.v index 48d40c4..e165c9d 100644 --- a/verilator/sim.v +++ b/verilator/sim.v @@ -80,7 +80,7 @@ module emu output VGA_VS, output VGA_HB, output VGA_VB, - output CE_PIXEL, // = PIX_CLK (CLK_14); sample on its rising edge + output CE_PIXEL, // coco3fpga PIX_CLK: a clk_sys enable; sample RGB/syncs on a clk_sys rising edge when high output [15:0] AUDIO_L, output [15:0] AUDIO_R, @@ -141,7 +141,8 @@ wire AMW_ACK; wire [1:0] mpi = status_q[13:12] + 1'b1; wire CASS_REW_RECORD = status_q[14]; -wire cartint = status_q[16]; +wire rs_swap = status_q[16]; +wire cartint = status_q[19]; wire sg4v6 = status_q[21]; wire PHASE = status_q[18]; @@ -151,6 +152,8 @@ wire coldboot = status_q[22]; wire F_Turbo = status_q[24]; wire [2:0] Mem_Size = status_q[27:25]; wire SWAP_M_J = status_q[28]; +wire display_debug = status_q[29]; +wire UART_INPUT = status_q[30]; wire digitalJoy = status_q[23]; wire easter_egg = status_q[10]; @@ -184,7 +187,7 @@ always @(negedge CLK_14) begin end // Set bit 9 to swap serial ports... -wire [9:0] switch = { 2'b10,art,sg4v6,cartint,CASS_REW_RECORD,mpi,1'b0}; +wire [9:0] switch = { cartint,UART_INPUT,art,sg4v6,rs_swap,CASS_REW_RECORD,mpi,1'b0}; wire reset = RESET | status_q[0] | buttons[1]; @@ -292,7 +295,7 @@ assign AUDIO_R = audio_right; wire [7:0] r, g, b; wire hblank, vblank, hs, vs, pix_clk; -wire [31:0] probe; +wire [6:0] probe_o; wire [71:0] Config_Data = {"SIMULATE", 8'h00}; @@ -327,9 +330,9 @@ coco3fpga coco3 ( .COCO_RESET_N((~reset & Programmed_RESET_N)), - .RED(r), - .GREEN(g), - .BLUE(b), + .RED_O(r), + .GREEN_O(g), + .BLUE_O(b), .EE_N(Programmed_EE), .PHASE(PHASE), @@ -382,7 +385,8 @@ coco3fpga coco3 ( .GPIO(), - .PROBE(probe), + .PROBE_O(probe_o), + .PROBE_I(7'h7F), // SNAC (USER_IN) pins idle high .clk_Q_out(clk_Q_out), .casdout(casdout), .cas_relay(cas_relay), @@ -414,6 +418,7 @@ coco3fpga coco3 ( .Mem_Size(Mem_Size), .AUTO_MODE(Auto_Mode), .Config_Data(Config_Data), + .Display_Debug(display_debug), .UART_TXD(UART_TXD), .UART_RXD(uart_rxd), diff --git a/verilator/sim_main.cpp b/verilator/sim_main.cpp index ced9651..9630cd1 100644 --- a/verilator/sim_main.cpp +++ b/verilator/sim_main.cpp @@ -433,7 +433,6 @@ static void sim_step() { const bool c28 = !((k >> 2) & 1); const bool c14 = !((k >> 3) & 1); const bool sys_rise = c57 && !top->CLK_57; - const bool pix_rise = c14 && !top->CLK_14; // 50 MHz, free-running and asynchronous to the rest, as on the board. clk50_acc += fast_clocks ? 8730 : 4365; // step length in ps @@ -455,6 +454,18 @@ static void sim_step() { b_dout = top->dbg_dout; b_rs232 = top->dbg_rs232_en; + // Video is captured the way sys/video_mixer.sv does it: on a clk_sys + // rising edge, taking the values that stand before the edge. The core's + // pixel enable (PIX_CLK) is high for 2 of every 4 clk_sys cycles; the + // mixer sees it oscillate and takes one pixel per rising edge + // (~old_ce & ce_pix), and so does this. + static bool old_ce = false; + if (top->CE_PIXEL && !old_ce) { + uint32_t colour = 0xFF000000 | (top->VGA_B << 16) | (top->VGA_G << 8) | top->VGA_R; + video.Clock(top->VGA_HB, top->VGA_VB, top->VGA_HS, top->VGA_VS, colour); + } + old_ce = top->CE_PIXEL; + bus.BeforeEval(); blk.BeforeEval(main_time); input.BeforeEval(); @@ -531,10 +542,6 @@ static void sim_step() { old_irqn = top->dbg_irqn; } - if (pix_rise) { - uint32_t colour = 0xFF000000 | (top->VGA_B << 16) | (top->VGA_G << 8) | top->VGA_R; - video.Clock(top->VGA_HB, top->VGA_VB, top->VGA_HS, top->VGA_VS, colour); - } main_time++; } diff --git a/verilator/test-ref/boot.png b/verilator/test-ref/boot.png index 29f2a34..97d5d30 100644 Binary files a/verilator/test-ref/boot.png and b/verilator/test-ref/boot.png differ diff --git a/verilator/test-ref/disk.png b/verilator/test-ref/disk.png index 542502e..ddd7dcb 100644 Binary files a/verilator/test-ref/disk.png and b/verilator/test-ref/disk.png differ diff --git a/verilator/test-ref/hscreen.png b/verilator/test-ref/hscreen.png index 78269d0..c7312d4 100644 Binary files a/verilator/test-ref/hscreen.png and b/verilator/test-ref/hscreen.png differ diff --git a/verilator/test-ref/keyboard.png b/verilator/test-ref/keyboard.png index da7189c..f50d2ec 100644 Binary files a/verilator/test-ref/keyboard.png and b/verilator/test-ref/keyboard.png differ diff --git a/verilator/test-ref/width80.png b/verilator/test-ref/width80.png index 9bd4395..0c3c6a6 100644 Binary files a/verilator/test-ref/width80.png and b/verilator/test-ref/width80.png differ diff --git a/verilator/tests/dw_boot.sh b/verilator/tests/dw_boot.sh new file mode 100755 index 0000000..888dc9d --- /dev/null +++ b/verilator/tests/dw_boot.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# +# Boot a DriveWire cart (e.g. FujiNet's HDB-DOS SY6551 build) with the sim's +# RS-232 Pak bridged to tests/dwserver.py serving a disk image. +# +# tests/dw_boot.sh CART DISK STOP_FRAME [extra sim args...] +# +# tests/dw_boot.sh ../../FujiNet_MiSTer/roms/HDBDW3S3.CCC tests/hello.dsk 350 \ +# --type '140:RUN"HELLO\n' +# +# Output: dw_boot.log (sim), dw_boot.dw.log (server), dw_boot_frame_NNNN.png. +# Needs the RS232_EN fix in rtl/coco3fpga.sv (or --acia-any-slot on older RTL); +# see README, "FujiNet on this core". + +set -u +cd "$(dirname "$0")/.." +[ $# -ge 3 ] || { sed -n 3,14p "$0"; exit 2; } +cart=$1; disk=$2; stop=$3; shift 3 + +./obj_dir/Vemu --headless --cart "$cart" --serial-pty --stop-at-frame "$stop" \ + --screenshot "$stop" --screenshot-prefix dw_boot --ascii-end "$@" > dw_boot.log 2>&1 & +sim=$! +pty= +for _ in $(seq 1 100); do + pty=$(grep -o '/dev/ttys[0-9]*\|/dev/pts/[0-9]*' dw_boot.log | head -1) + [ -n "$pty" ] && break + sleep 0.1 +done +[ -n "$pty" ] || { echo "sim did not open a pty"; kill $sim; exit 1; } +echo "sim on $pty, serving $disk" +python3 tests/dwserver.py "$pty" "$disk" > dw_boot.dw.log 2>&1 & +dw=$! +trap 'kill $sim $dw 2>/dev/null' INT TERM +wait $sim +kill $dw 2>/dev/null + +echo "--- DriveWire server"; cat dw_boot.dw.log +echo "--- sim"; grep -E '^\||^Serial' dw_boot.log | grep -v '^| *|$'