module GBZ80Core(
input clk,
- output reg [15:0] busaddress, /* BUS_* is latched on STATE_FETCH. */
+ output reg [15:0] busaddress = 0, /* BUS_* is latched on STATE_FETCH. */
inout [7:0] busdata,
- output reg buswr, output reg busrd);
+ output reg buswr = 0, output reg busrd = 0);
reg [1:0] state = 0; /* State within this bus cycle (see STATE_*). */
reg [2:0] cycle = 0; /* Cycle for instructions. */
wire [7:0] iflag = {3'b0,buttons,serial,tovf,lcdc,vblank};
reg [7:0] imask = 16'hFFFF;
- reg [7:0] ihold = 0;
+ reg [7:0] ihold = 8'b0;
wire [7:0] imasked = ihold & imask;
assign data = rd ?
imasked[3] ? 8'h58 :
imasked[4] ? 8'h60 : 8'h00;
- always @ (negedge clk)
+ always @(negedge clk)
begin
- if (wr) begin
+ if (wr && (addr == `ADDR_IF || addr == `ADDR_IE)) begin
case(addr)
`ADDR_IF : ihold <= iflag | data;
- `ADDR_IE : imask <= data;
+ `ADDR_IE : begin imask <= data; ihold <= ihold | iflag; end
endcase
end
endmodule
module TestBench();
- reg clk = 0;
+ reg clk = 1;
wire [15:0] addr;
wire [7:0] data;
wire wr, rd;
input rd,
input [15:0] addr,
inout [7:0] data,
- output reg irq);
+ output reg irq = 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;
ld c, $51 ; Note that we are alive.
ld a, $FF
ld [c],a
-
+
ld sp, $DFFF
ld hl, signon
call puts
ld c, $07
- ld a, $07 ;start timer, 4.096KHz
+ ld a, $04 ;start timer, 4.096KHz
ld [c], a
ld c, $51
ret z
xor a
ld [c], a
- ld hl, $D000
- ld c, [hl]
- inc bc
- ld [hl], c
- ld a, c
- ld c, $50
- ld [c], a
+ ld a, $41
+ call putc
ret
; Core instruction basic acceptance tests.
putc:
ld b, 0
ld c, $50
+ push af
.waitport:
ld a,[c]
cp b
jr nz,.waitport
+ pop af
ld [c],a
ret
ld a, [hli]
ld b, $00
cp b
- ret z
+ jr z, .done
call putc
jr puts
+.done:
+ ret