// 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 // Coco 3 Plus: Sound/Speech host interface. // Behavioral reference: VCCPlus a8a84f22 src/devices/ssc/ssc_core.cpp; // CoCo SSC wiring derives from MAME, copyright Tim Lindner. See LICENSE. // This block does not implement the PIC, PSG, speech engine or audio circuit. // All inputs must be synchronous to clk. host_write/pic_command_read are // single-cycle transaction strobes, not unqualified CPU bus levels. module ssc_host ( input wire clk, input wire reset, input wire enable, input wire host_read, input wire host_write, input wire [15:0] host_address, input wire [7:0] host_data, output wire host_read_valid, output wire [7:0] host_read_data, // Future controller's port A input and INT3 command request. input wire pic_command_read, input wire pic_busy_line, output reg [7:0] command_data, output reg command_irq, output reg command_busy, // Future engines supply these levels; this block does not synthesize them. input wire speech_standby, input wire sound_active, // Reset requests last one clk tick (held asserted during global reset). output reg controller_reset, output reg speech_reset ); localparam [15:0] CONTROL_ADDRESS = 16'hFF7D; localparam [15:0] COMMAND_ADDRESS = 16'hFF7E; reg reset_bit; reg previous_busy_line; wire control_write = enable && host_write && host_address == CONTROL_ADDRESS; wire command_write = enable && host_write && host_address == COMMAND_ADDRESS; assign host_read_valid = enable && host_read && (host_address == CONTROL_ADDRESS || host_address == COMMAND_ADDRESS); // An unselected device contributes nothing to the shared read mux. assign host_read_data = !host_read_valid ? 8'h00 : host_address == CONTROL_ADDRESS ? 8'hFF : { !command_busy, speech_standby, !sound_active, 5'b11111 }; always @(posedge clk) begin if (reset) begin reset_bit <= 1'b1; previous_busy_line <= 1'b0; // controller reset drives port C to zero command_data <= 8'h00; command_irq <= 1'b0; command_busy <= 1'b0; controller_reset <= 1'b1; speech_reset <= 1'b1; end else begin controller_reset <= 1'b0; speech_reset <= 1'b0; previous_busy_line <= pic_busy_line; if (!previous_busy_line && pic_busy_line) command_busy <= 1'b0; if (pic_command_read) command_irq <= 1'b0; if (control_write) begin reset_bit <= host_data[0]; if (host_data[0]) speech_reset <= 1'b1; if (reset_bit && !host_data[0]) begin controller_reset <= 1'b1; command_busy <= 1'b0; command_irq <= 1'b0; previous_busy_line <= 1'b0; end end // A fresh host command wins over simultaneous completion/read strobes. // The controller consuming port A on this edge sees the OLD payload; // the new payload remains latched with INT3 asserted for its next read. if (command_write) begin command_data <= host_data; command_busy <= 1'b1; command_irq <= 1'b1; end end end endmodule