2023-10-02 00:00:56 +02:00
|
|
|
// Top level gb module
|
2021-02-15 22:40:12 +01:00
|
|
|
module gb (
|
2023-10-02 00:00:56 +02:00
|
|
|
input logic clk,
|
|
|
|
input logic nreset,
|
|
|
|
|
|
|
|
// Cartridge bus
|
|
|
|
output logic cart_clk_o,
|
|
|
|
output logic cart_nreset_o,
|
|
|
|
output logic cart_nrd_o,
|
|
|
|
output logic cart_nwr_o,
|
|
|
|
output logic cart_ncs_o,
|
|
|
|
output logic [15:0] cart_addr_o,
|
|
|
|
input logic [ 7:0] cart_data_i
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
logic [15:0] cpu_addr;
|
|
|
|
logic [ 7:0] cpu_rdata;
|
|
|
|
logic cpu_we;
|
|
|
|
logic [ 7:0] cpu_wdata;
|
|
|
|
|
|
|
|
logic [ 7:0] cpu_ppu_rdata;
|
|
|
|
|
|
|
|
logic rom_enable_r;
|
|
|
|
logic rom_sel;
|
|
|
|
logic [ 7:0] rom_rdata;
|
|
|
|
|
|
|
|
logic hiram_sel;
|
|
|
|
logic hiram_we;
|
|
|
|
logic [ 7:0] hiram_rdata;
|
|
|
|
|
|
|
|
logic vram_sel;
|
|
|
|
logic vram_we;
|
|
|
|
logic [ 7:0] vram_rdata;
|
|
|
|
|
|
|
|
cpu cpu_inst (
|
|
|
|
.clk (clk),
|
|
|
|
.nreset (nreset),
|
|
|
|
|
|
|
|
.addr_o (cpu_addr),
|
|
|
|
.rdata_i(cpu_rdata),
|
|
|
|
.we_o (cpu_we),
|
|
|
|
.wdata_o(cpu_wdata)
|
|
|
|
);
|
|
|
|
|
|
|
|
ppu ppu_inst (
|
|
|
|
.clk (clk),
|
|
|
|
.nreset (nreset),
|
|
|
|
|
|
|
|
.cpu_addr_i (cpu_addr),
|
|
|
|
.cpu_rdata_o(cpu_ppu_rdata),
|
|
|
|
.cpu_we_i (cpu_we),
|
|
|
|
.cpu_wdata_i(cpu_wdata),
|
|
|
|
.cpu_addr_sel_o(ppu_sel)
|
2021-02-15 22:40:12 +01:00
|
|
|
);
|
|
|
|
|
2023-10-02 00:00:56 +02:00
|
|
|
assign rom_enable_r = '1;
|
|
|
|
|
|
|
|
assign rom_sel = rom_enable_r & ~(|cpu_addr[15:8]);
|
|
|
|
assign vram_sel = (cpu_addr[15:13] == 3'b100);
|
|
|
|
assign hiram_sel = (&cpu_addr[15:7]) & ~(&cpu_addr[6:0]);
|
|
|
|
|
|
|
|
assign vram_we = vram_sel & cpu_we;
|
|
|
|
assign hiram_we = hiram_sel & cpu_we;
|
|
|
|
|
|
|
|
assign cpu_rdata = ({8{ rom_sel}} & rom_rdata) |
|
|
|
|
({8{ vram_sel}} & vram_rdata) |
|
|
|
|
({8{hiram_sel}} & hiram_rdata)|
|
|
|
|
({8{ ppu_sel}} & cpu_ppu_rdata);
|
|
|
|
|
|
|
|
rom #(
|
|
|
|
.FILE_NAME("DMG_ROM.bin"),
|
|
|
|
.ADDR_W (8),
|
|
|
|
.DATA_W (8)
|
|
|
|
) rom_inst (
|
|
|
|
.clk (clk),
|
|
|
|
.address_i(cpu_addr[7:0]),
|
|
|
|
.rdata_o (rom_rdata)
|
|
|
|
);
|
|
|
|
|
|
|
|
ram #(
|
|
|
|
.ADDR_W (13),
|
|
|
|
.DATA_W (8)
|
|
|
|
) vram_inst (
|
|
|
|
.clk (clk),
|
|
|
|
.address_i (cpu_addr[12:0]),
|
|
|
|
.rdata_o (vram_rdata),
|
|
|
|
.we_i (vram_we),
|
|
|
|
.wdata_i (cpu_wdata)
|
|
|
|
);
|
|
|
|
|
|
|
|
ram #(
|
|
|
|
.ADDR_W (7),
|
|
|
|
.DATA_W (8)
|
|
|
|
) hiram_inst (
|
|
|
|
.clk (clk),
|
|
|
|
.address_i (cpu_addr[6:0]),
|
|
|
|
.rdata_o (hiram_rdata),
|
|
|
|
.we_i (hiram_we),
|
|
|
|
.wdata_i (cpu_wdata)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
endmodule : gb
|