From f19344cf587094154355d8bfc1beddd666a76621 Mon Sep 17 00:00:00 2001 From: Niels Moseley Date: Sat, 27 Jan 2018 00:48:05 +0100 Subject: [PATCH] Editted CPU and testbench for better simulation --- rtl/apple1_top.v | 18 +++++++++++++++--- rtl/cpu/cpu.v | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/rtl/apple1_top.v b/rtl/apple1_top.v index 6e2e887..dfad67b 100644 --- a/rtl/apple1_top.v +++ b/rtl/apple1_top.v @@ -10,7 +10,7 @@ module top( input clk25, // 25 MHz master clock input rst_n, // active low synchronous reset (needed for simulation) - + input uart_rx, output uart_tx, output uart_cts, @@ -50,10 +50,17 @@ module top( // 25 clocks. This will (hopefully) make // the 6502 run at 1 MHz or 1Hz // + // the clock division counter is synchronously + // reset using rst_n to avoid undefined signals + // in simulation + // + reg [4:0] clk_div; always @(posedge clk25) begin - if ((clk_div == 25) || (rst_n == 1'b0)) + // note: clk_div should be compared to + // N-1, where N is the clock divisor + if ((clk_div == 24) || (rst_n == 1'b0)) clk_div <= 0; else clk_div <= clk_div + 1'b1; @@ -70,7 +77,12 @@ module top( always @(posedge clk25) begin - if (cpu_clken) + if (rst_n == 1'b0) + begin + reset_cnt <= 6'b0; + //hard_reset <= 1'b0; we should init hard_reset here too.. + end + else if (cpu_clken) begin if (!pwr_up_reset) reset_cnt <= reset_cnt + 1; diff --git a/rtl/cpu/cpu.v b/rtl/cpu/cpu.v index 10ad9f5..346e312 100644 --- a/rtl/cpu/cpu.v +++ b/rtl/cpu/cpu.v @@ -18,6 +18,8 @@ * on the output pads if external memory is required. */ +`define SIM + module cpu( clk, reset, AB, DI, DO, WE, IRQ, NMI, RDY ); input clk; // CPU clock