+module ROM(
+ input [15:0] address,
+ inout [7:0] data,
+ input wr, rd);
+
+ reg [7:0] rom [2047:0];
+ initial $readmemh("rom.hex", rom);
+
+ wire decode = address[15:13] == 0;
+ reg [7:0] odata;
+ wire idata = data;
+ assign data = (rd && decode) ? odata : 8'bzzzzzzzz;
+
+ always @(wr or rd)
+ begin
+ if (decode && rd)
+ odata <= rom[address];
+ end
+endmodule
+
+module InternalRAM(
+ input [15:0] address,
+ inout [7:0] data,
+ input wr, rd);
+
+ reg [7:0] ram [8191:0];
+
+ wire decode = (address >= 16'hC000) && (address < 16'hFE00);
+ reg [7:0] odata;
+ wire idata = data;
+ assign data = (rd && decode) ? odata : 8'bzzzzzzzz;
+
+ always @(rd or wr)
+ begin
+ if (decode && rd)
+ odata <= ram[address];
+ else if (decode && wr)
+ ram[address] <= idata;
+ end
+endmodule
+