// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman. // Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md. // SPDX-License-Identifier: BSD-3-Clause // Volatile, synchronous AL2 ROM. Original bytes arrive through a strict loader. module ssc_sp0256_memory(input wire clk,reset,rom_begin,rom_write, input wire [10:0] rom_address,input wire [7:0] rom_data, output reg rom_loaded,load_error,input wire [10:0] read_address, output reg [7:0] read_data); reg [7:0] rom[0:2047]; reg loading; reg [11:0] expected; always @(posedge clk)begin read_data<=rom[read_address]; if(reset)begin rom_loaded<=0;load_error<=0;loading<=0;expected<=0;end else if(rom_begin)begin rom_loaded<=0;load_error<=rom_write;loading<=!rom_write;expected<=0; end else if(rom_write)begin if(!loading || expected!= {1'b0,rom_address})begin load_error<=1;rom_loaded<=0;loading<=0; end else begin rom[rom_address]<=rom_data;expected<=expected+12'd1; if(expected==2047)begin rom_loaded<=1;loading<=0;end end end end endmodule