]> Joshua Wise's Git repositories - fpgaboy.git/blobdiff - Timer.v
Fix add sp, imm8 *sweatdrop*
[fpgaboy.git] / Timer.v
diff --git a/Timer.v b/Timer.v
index 0481614f5c97586672ba16ed34265b0dcc04b4da..facf20fe97584400ebff54f35095491806f2b2d2 100644 (file)
--- a/Timer.v
+++ b/Timer.v
@@ -9,17 +9,19 @@ module Timer(
        input rd,
        input [15:0] addr,
        inout [7:0] data,
-       output reg irq);
+       output reg irq = 0);
 
+       reg rdlatch = 0;
+       reg [15:0] addrlatch = 0;
        reg [7:0] tima = 0, tma = 0, tac = 0, div = 0;
        reg ovf = 0;
-       reg [9:0] clkdv;
+       reg [9:0] clkdv = 0;
 
-       wire is_tima = addr == `ADDR_TIMA;
-       wire is_tma  = addr == `ADDR_TMA;
-       wire is_tac  = addr == `ADDR_TAC;
+       wire is_tima = addrlatch == `ADDR_TIMA;
+       wire is_tma  = addrlatch == `ADDR_TMA;
+       wire is_tac  = addrlatch == `ADDR_TAC;
 
-       assign data = rd ?
+       assign data = rdlatch ?
                         is_tima ? tima :
                         is_tma ? tma :
                         is_tac ? tac :
@@ -33,8 +35,11 @@ module Timer(
                        (clkdv[7:0] == 8'b0) :
                     0;
 
-       always @ (negedge clk) 
+       always @ (posedge clk) 
        begin
+               rdlatch <= rd;
+               addrlatch <= addr;
+               
                if(wr) begin
                        case(addr)
                        `ADDR_DIV: div <= 8'b0;
This page took 0.024524 seconds and 4 git commands to generate.