]> Joshua Wise's Git repositories - fpgaboy.git/blobdiff - GBZ80Core.v
Fix RAM bugs with kludge. Fix CALL bug. CALL test case.
[fpgaboy.git] / GBZ80Core.v
index cb231c2cfbc09eb684c6ae713416b6f3c63d230e..ec1756ebe3b6ed66c171327c5b8caa67990325e8 100644 (file)
@@ -395,16 +395,18 @@ module GBZ80Core(
                                                rd <= 1;
                                        end
                                2:      begin
+                                               `EXEC_INC_PC;
+                                       end
+                               3:      begin
                                                address <= {registers[`REG_SPH],registers[`REG_SPL]} - 1;
                                                wdata <= registers[`REG_PCH];
                                                wr <= 1;
                                        end
-                               3:      begin
+                               4:      begin
                                                address <= {registers[`REG_SPH],registers[`REG_SPL]} - 2;
                                                wdata <= registers[`REG_PCL];
                                                wr <= 1;
                                        end
-                               4:      begin /* nothing happens on the bus next cycle! */ end
                                5:      begin
                                                `EXEC_NEWCYCLE; /* do NOT increment the PC */
                                        end
@@ -680,15 +682,15 @@ module GBZ80Core(
                                        end
                                3: begin
                                                cycle <= 4;
-                                               registers[`REG_PCH] <= tmp2;
                                        end
                                4: begin
                                                cycle <= 5;
-                                               registers[`REG_PCL] <= tmp;
+                                               registers[`REG_PCH] <= tmp2;
                                        end
                                5: begin
                                                {registers[`REG_SPH],registers[`REG_SPL]} <=
                                                        {registers[`REG_SPH],registers[`REG_SPL]} - 2;
+                                               registers[`REG_PCL] <= tmp;
                                                cycle <= 0;
                                        end
                                endcase
@@ -715,16 +717,15 @@ module ROM(
        wire idata = data;
        assign data = (rd && decode) ? odata : 8'bzzzzzzzz;
        
-       always @(wr or rd)
-       begin
-               if (decode && rd)
+       always @(posedge rd)
+               if (decode)
                        odata <= rom[address];
-       end
 endmodule
 
 module InternalRAM(
        input [15:0] address,
        inout [7:0] data,
+       input clk,
        input wr, rd);
        
        reg [7:0] ram [8191:0];
@@ -734,12 +735,17 @@ module InternalRAM(
        wire idata = data;
        assign data = (rd && decode) ? odata : 8'bzzzzzzzz;
        
-       always @(rd or wr)
+       reg [13:0] diq;
+       initial
+               for (diq = 0; diq < 8191; diq = diq + 1)
+                       ram[diq] = 8'h43;
+       
+       always @(negedge clk)
        begin
                if (decode && rd)
-                       odata <= ram[address];
-               else if (decode && wr)
-                       ram[address] <= idata;
+                       odata <= ram[address[12:0]];
+               if (decode && wr)
+                       ram[address[12:0]] <= data;
        end
 endmodule
 
@@ -766,6 +772,7 @@ module TestBench();
        InternalRAM ram(
                .address(addr),
                .data(data),
+               .clk(clk),
                .wr(wr),
                .rd(rd));
 endmodule
This page took 0.02896 seconds and 4 git commands to generate.