]> Joshua Wise's Git repositories - fpgaboy.git/blobdiff - GBZ80Core.v
Make binwire a little bit more error-resistant
[fpgaboy.git] / GBZ80Core.v
index b06910a6c3052f3c8648424e6926aac0a8953ce5..3c2f7702aaa1c9e507232c435029c0a4456f48cf 100644 (file)
@@ -177,17 +177,21 @@ module GBZ80Core(
        
        reg bootstrap_enb;
        
-       wire bus = ((busaddress[15:8] == 8'h00) && bootstrap_enb) || ((busaddress[15:7] == 9'b111111111) && (busaddress != 16'hFFFF));  /* 0 or 1 depending on which bus */
+       wire bus = ((busaddress[15:8] == 8'h00) && bootstrap_enb) || ((busaddress[15:7] == 9'b111111111) && (busaddress != 16'hFFFF))   /* 0 or 1 depending on which bus */
+               `ifdef isim
+                       || (busaddress === 16'hxxxx) /* To avoid simulator glomulation. */
+               `endif
+                       ;
                
        assign bus0address = (bus == 0) ? busaddress : 16'bzzzzzzzzzzzzzzz;
        assign bus1address = (bus == 1) ? busaddress : 16'bzzzzzzzzzzzzzzz;
        assign bus0data = ((bus == 0) && buswr) ? buswdata : 8'bzzzzzzzz;
        assign bus1data = ((bus == 1) && buswr) ? buswdata : 8'bzzzzzzzz;
        assign busdata = (bus == 0) ? bus0data : bus1data;
-       assign bus0rd = (bus == 0) ? busrd : 1'bz;
-       assign bus1rd = (bus == 1) ? busrd : 1'bz;
-       assign bus0wr = (bus == 0) ? buswr : 1'bz;
-       assign bus1wr = (bus == 1) ? buswr : 1'bz;
+       assign bus0rd = (bus == 0) ? busrd : 1'b0;
+       assign bus1rd = (bus == 1) ? busrd : 1'b0;
+       assign bus0wr = (bus == 0) ? buswr : 1'b0;
+       assign bus1wr = (bus == 1) ? buswr : 1'b0;
 
        reg ie, iedelay;
 
@@ -291,11 +295,16 @@ module GBZ80Core(
                                busaddress <= address;
                                buswr <= wr;
                                busrd <= rd;
-                               if (wr)
+                               if (wr) begin
                                        buswdata <= wdata;
+                                       if (address == 16'hFF50)
+                                               bootstrap_enb <= 0;
+                               end
                        end
                end
                `STATE_DECODE: begin    /* Make sure this only happens for one clock. */
+                       buswr <= 0;
+                       busrd <= 0;
                end
                endcase
        
@@ -314,11 +323,11 @@ 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;
+                               if (rd) rdata <= busdata;       /* Still valid because peripherals are now expected to keep it held valid. */
                                cycle <= cycle + 1;
                        end
                        if (iedelay) begin
@@ -327,13 +336,13 @@ module GBZ80Core(
                        end
                        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;
                end
                `STATE_EXECUTE: begin
+                       if (opcode[7:0] === 8'bxxxxxxxx)
+                               $stop;
                        casex (opcode)
                        `define EXECUTE
                        `include "allinsns.v"
This page took 0.029368 seconds and 4 git commands to generate.