-- SPDX-License-Identifier: MIT -- Pin-level testbench for a POKEY written as VHDL (entity pokey_top with the -- chip's pins as ports). It only drives pins and prints pins: it contains no -- part of any model. scripts/run_vhdl.py builds and runs it. -- -- Stimulus file (generic STIM), one command per line, one command per phi2 cycle: -- W a d write byte d (decimal) to register a (decimal 0-15) -- R a read register a -- N n n cycles with the chip deselected -- K v set the keyboard response pins KR2,KR1 (v = 0-3; idle is 3); takes no cycle -- P v set the eight pot pins (decimal 0-255); takes no cycle -- S v set serial data in (0 or 1); takes no cycle -- -- Output, one line per cycle, sampled 20 ns before phi2 falls: -- cycle kind addr data audio irq sod oclk bclko dump k -- kind is W, R or N; data is the byte written, the byte read, or 255. -- A value that is not all 0/1 (U, X, Z) prints as -1. library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use std.textio.all; entity pokey_tb is generic (STIM : string := "stim.txt"); end pokey_tb; architecture bench of pokey_tb is constant HALF : time := 280 ns; signal phi2 : std_logic := '0'; signal cs : std_logic_vector(1 downto 0) := "00"; signal rw : std_logic := '1'; signal d : std_logic_vector(7 downto 0) := (others => 'Z'); signal a : std_logic_vector(3 downto 0) := "0000"; signal p : std_logic_vector(7 downto 0) := (others => '1'); signal kr : std_logic_vector(1 downto 0) := "11"; signal sid : std_logic := '1'; signal bclki : std_logic := '1'; signal bclko, irq, sod, oclk, dump : std_logic; signal audio : std_logic_vector(5 downto 0); signal k : std_logic_vector(5 downto 0); signal done : boolean := false; function num(v : std_logic_vector) return integer is begin if is_x(v) then return -1; end if; return to_integer(unsigned(v)); end function; function bit_of(v : std_logic) return integer is begin if v = '1' then return 1; elsif v = '0' then return 0; else return -1; end if; end function; begin phi2 <= not phi2 after HALF when not done else '0'; dut : entity work.pokey_top port map (phi2 => phi2, cs => cs, rw => rw, irq => irq, d => d, a => a, audio => audio, p => p, dump => dump, k => k, kr => kr, sid => sid, bclki => bclki, bclko => bclko, sod => sod, oclk => oclk); drive : process file commands : text open read_mode is STIM; variable row, line_out : line; variable op : character; variable x, y, cycle, shown : integer := 0; procedure report_cycle(kind : character; addr : integer; data : integer) is begin write(line_out, cycle); write(line_out, ' '); write(line_out, kind); write(line_out, ' '); write(line_out, addr); write(line_out, ' '); write(line_out, data); write(line_out, ' '); write(line_out, num(audio)); write(line_out, ' '); write(line_out, bit_of(irq)); write(line_out, ' '); write(line_out, bit_of(sod)); write(line_out, ' '); write(line_out, bit_of(oclk)); write(line_out, ' '); write(line_out, bit_of(bclko)); write(line_out, ' '); write(line_out, bit_of(dump)); write(line_out, ' '); write(line_out, num(k)); writeline(output, line_out); cycle := cycle + 1; end procedure; begin wait until falling_edge(phi2); while not endfile(commands) loop readline(commands, row); next when row'length = 0; read(row, op); read(row, x); case op is when 'W' => read(row, y); wait for 100 ns; cs <= "10"; rw <= '0'; a <= std_logic_vector(to_unsigned(x, 4)); wait until rising_edge(phi2); wait for 100 ns; d <= std_logic_vector(to_unsigned(y, 8)); wait for HALF - 120 ns; report_cycle('W', x, y); wait until falling_edge(phi2); wait for 60 ns; cs <= "00"; rw <= '1'; d <= (others => 'Z'); when 'R' => wait for 100 ns; cs <= "10"; rw <= '1'; a <= std_logic_vector(to_unsigned(x, 4)); wait until rising_edge(phi2); wait for HALF - 20 ns; report_cycle('R', x, num(d)); wait until falling_edge(phi2); wait for 60 ns; cs <= "00"; when 'N' => for i in 1 to x loop wait until rising_edge(phi2); wait for HALF - 20 ns; report_cycle('N', 0, 255); wait until falling_edge(phi2); end loop; when 'K' => kr <= std_logic_vector(to_unsigned(x, 2)); when 'P' => p <= std_logic_vector(to_unsigned(x, 8)); when 'S' => if x = 0 then sid <= '0'; else sid <= '1'; end if; when others => null; end case; end loop; done <= true; wait; end process; end bench;