X-Git-Url: http://git.joshuawise.com/fpgaboy.git/blobdiff_plain/62940da0dd1b60db11e9861d6dd55a43c5756114..c3cb12e87f7dd29f5ed5a8da179993a1affc20d8:/Interrupt.v diff --git a/Interrupt.v b/Interrupt.v index 1450b2c..2686146 100644 --- a/Interrupt.v +++ b/Interrupt.v @@ -19,10 +19,13 @@ module Interrupt( reg [7:0] imask = 16'hFFFF; reg [7:0] ihold = 8'b0; wire [7:0] imasked = ihold & imask; + + reg rdlatch = 0; + reg [15:0] addrlatch = 0; - assign data = rd ? - (addr == `ADDR_IF) ? ihold : - (addr == `ADDR_IE) ? imask : + assign data = rdlatch ? + (addrlatch == `ADDR_IF) ? ihold : + (addrlatch == `ADDR_IE) ? imask : 8'bzzzzzzzz : 8'bzzzzzzzz; @@ -34,7 +37,7 @@ module Interrupt( imasked[3] ? 8'h58 : imasked[4] ? 8'h60 : 8'h00; - always @(negedge clk) + always @(posedge clk) begin if (wr && (addr == `ADDR_IF || addr == `ADDR_IE)) begin case(addr) @@ -45,6 +48,8 @@ module Interrupt( end else ihold <= ihold | iflag; + rdlatch <= rd; + addrlatch <= addr; end endmodule