-- SPDX-License-Identifier: MIT -- C18 probe testbench: srg320's HUC6280_CPU (MiSTer TurboGrafx16 core, GPL-2.0-or-later) run as -- a closed box under GHDL. Only the entity's ports are used; nothing of the core is copied here. -- -- One interrupt input (generic source: 0 IRQ2_N, 1 IRQ1_N, 2 IRQT_N) is held low from reset and -- released during the first bus cycle whose address is the generic trigger (a physical address; -- -1: never released), or during cycle number release_at (counted from the end of reset, as -- logged) when that is given. With generic rise = true the line instead starts high and goes low -- at that point (a source that appears). The program is in an 8 KB ROM image at physical $000000 (read from the -- file named by the generic rom, one decimal byte per line), RAM is 8 KB at $1F0000; everything -- else reads $FF. Every cycle is written to the output file as --
-- for the generic number of cycles. -- -- Port timing (OBSERVED in this simulation, docs/restart.md): A_OUT and WE_N are settled by the -- falling clock edge, and a read's DI must be in place before the rising edge that ends the -- cycle. With generic late = true the data is driven 1 ns after that rising edge instead, and -- the core misreads it (validation/vanish_vhdl.py --late --dump tiq held), which is how the -- second half was established. library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use std.textio.all; entity tb_vanish is generic ( rom : string := "rom.txt"; output : string := "bus.txt"; source : natural := 2; trigger : integer := -1; release_at : integer := -1; cycles : natural := 400; late : boolean := false; rise : boolean := false ); end entity; architecture sim of tb_vanish is signal clk, rst_n : std_logic := '0'; signal d_in, d_out : std_logic_vector(7 downto 0) := (others => '0'); signal a_out : std_logic_vector(20 downto 0); signal we_n, mcycle, cs : std_logic; signal irq_n : std_logic_vector(2 downto 0) := "111"; signal done : boolean := false; type mem_t is array (0 to 8191) of integer range 0 to 255; begin dut : entity work.HUC6280_CPU port map ( CLK => clk, RST_N => rst_n, CE => '1', A_OUT => a_out, DI => d_in, DO => d_out, WE_N => we_n, RDY => '1', NMI_N => '1', IRQ1_N => irq_n(1), IRQ2_N => irq_n(0), IRQT_N => irq_n(2), VDCNUM => '0', MCYCLE => mcycle, CS => cs); clock : process begin while not done loop clk <= '0'; wait for 5 ns; clk <= '1'; wait for 5 ns; end loop; wait; end process; drive : process file image : text open read_mode is rom; file log : text open write_mode is output; variable l : line; variable rom_bytes, ram : mem_t := (others => 0); variable value, address, n : integer; variable released : boolean := false; begin n := 0; while not endfile(image) and n < 8192 loop readline(image, l); read(l, value); rom_bytes(n) := value; n := n + 1; end loop; if rise then irq_n(source) <= '1'; else irq_n(source) <= '0'; end if; rst_n <= '0'; for i in 1 to 8 loop wait until rising_edge(clk); end loop; rst_n <= '1'; for count in 0 to cycles - 1 loop wait until falling_edge(clk); address := to_integer(unsigned(a_out)); if not released and (address = trigger or count = release_at) then if rise then irq_n(source) <= '0'; else irq_n(source) <= '1'; end if; released := true; end if; if we_n = '0' then value := to_integer(unsigned(d_out)); if address >= 16#1F0000# and address < 16#1F2000# then ram(address - 16#1F0000#) := value; end if; elsif address < 16#2000# then value := rom_bytes(address); elsif address >= 16#1F0000# and address < 16#1F2000# then value := ram(address - 16#1F0000#); else value := 255; end if; if we_n /= '0' then if late then d_in <= (others => '0'); wait until rising_edge(clk); wait for 1 ns; end if; d_in <= std_logic_vector(to_unsigned(value, 8)); end if; write(l, count); write(l, string'(" ")); write(l, address); write(l, string'(" ")); write(l, value); write(l, string'(" ")); write(l, std_logic'image(we_n)(2)); write(l, string'(" ")); write(l, std_logic'image(mcycle)(2)); write(l, string'(" ")); if released then write(l, string'("1")); else write(l, string'("0")); end if; writeline(log, l); end loop; done <= true; wait; end process; end architecture;