]> Joshua Wise's Git repositories - fpgaboy.git/blobdiff - GBZ80Core.v
Peripherals now have internal latches.
[fpgaboy.git] / GBZ80Core.v
index ec882da4d7841ee789180cd0ea85138843cfbc95..9db958fa85dc93189a0251b91d1b8cb5c600ff97 100644 (file)
@@ -280,7 +280,7 @@ module GBZ80Core(
                bootstrap_enb <= 1;
        end
 
-       always @(posedge clk)
+       always @(negedge clk)   /* Set things up at the negedge to prepare for the posedge. */
                case (state)
                `STATE_FETCH: begin
                        if (newcycle) begin
@@ -294,6 +294,15 @@ module GBZ80Core(
                                if (wr)
                                        buswdata <= wdata;
                        end
+               end
+               `STATE_DECODE: begin    /* Make sure this only happens for one clock. */
+               end
+               endcase
+       
+       always @(posedge clk)
+               case (state)
+               `STATE_FETCH: begin
+                       /* Things are set up in negedge so that something looking on posedge will get his shit. */
                        state <= `STATE_DECODE;
                end
                `STATE_DECODE: begin
@@ -305,8 +314,8 @@ module GBZ80Core(
                                        opcode <= `INSN_VOP_INTR;
                                else
                                        opcode <= {1'b0,busdata};
-                               rdata <= busdata;
                                newcycle <= 0;
+                               rdata <= busdata;
                                cycle <= 0;
                        end else begin
                                if (rd) rdata <= busdata;
@@ -316,10 +325,10 @@ module GBZ80Core(
                                ie <= 1;
                                iedelay <= 0;
                        end
-                       buswr <= 0;
-                       busrd <= 0;
                        wr <= 0;
                        rd <= 0;
+                       buswr <= 0;
+                       busrd <= 0;
                        address <= 16'bxxxxxxxxxxxxxxxx;        // Make it obvious if something of type has happened.
                        wdata <= 8'bxxxxxxxx;
                        state <= `STATE_EXECUTE;
This page took 0.027167 seconds and 4 git commands to generate.