inout [15:0] bus1address, /* BUS_* is latched on STATE_FETCH. */
inout [7:0] bus1data,
inout bus1wr, bus1rd,
- input irq, input [7:0] jaddr,
+ input irq, output reg irqack, input [7:0] jaddr,
output reg [1:0] state);
// reg [1:0] state; /* State within this bus cycle (see STATE_*). */
cycle <= 0;
twobyte <= 0;
bootstrap_enb <= 1;
+ irqack <= 0;
end
always @(negedge clk) /* Set things up at the negedge to prepare for the posedge. */
state <= `STATE_EXECUTE;
end
`STATE_EXECUTE: begin
+ `ifdef isim
if (opcode[7:0] === 8'bxxxxxxxx)
$stop;
+ `endif
casex (opcode)
`define EXECUTE
`include "allinsns.v"
input serial,
input buttons,
output master,
+ input ack,
output [7:0] jaddr);
wire [7:0] iflag = {3'b0,buttons,serial,tovf,lcdc,vblank};
`ADDR_IE : begin imask <= data; ihold <= ihold | iflag; end
endcase
- end
+ end else if (ack)
+ ihold <= ihold &
+ (imasked[0] ? 8'b11111110 :
+ imasked[1] ? 8'b11111101 :
+ imasked[2] ? 8'b11111011 :
+ imasked[3] ? 8'b11110111 :
+ imasked[4] ? 8'b11101111 :
+ 8'b11111111);
else
ihold <= ihold | iflag;
rdlatch <= rd;
wire irq, tmrirq, lcdcirq, vblankirq;
wire [7:0] jaddr;
wire [1:0] state;
+ wire ack;
GBZ80Core core(
.clk(clk),
.bus1wr(wr[1]),
.bus1rd(rd[1]),
.irq(irq),
+ .irqack(ack),
.jaddr(jaddr),
.state(state));
.serial(1'b0),
.buttons(1'b0),
.master(irq),
+ .ack(ack),
.jaddr(jaddr));
Soundcore sound(
case (cycle)
0: `EXEC_WRITE(`_SP - 1, `_PCH)
1: `EXEC_WRITE(`_SP - 2, `_PCL)
- 2: `EXEC_NEWCYCLE
+ 2: begin
+ irqack <= 1;
+ `EXEC_NEWCYCLE
+ end
endcase
end
`endif
2: begin
ie <= 0;
`_PC <= {8'b0, jaddr};
+ irqack <= 0; // Must be at the same time as we latch jaddr, or we race!
`_SP <= `_SP - 2;
end
endcase