Introduce Coco 3 Plus for MiSTer
Add original-firmware Sound & Speech, four configurable Multi-Pak sockets, bounded per-slot ROM allocation and a nine-page menu organized around devices and media. Repair inherited clock/reset/CPU-memory/video paths and add explicit conditional external-I/O timing contracts. Preserve native Main startup-file ordering, saved layouts, stock-core separation and the coco3plus media profile. Provide native Windows tool downloads, pinned ToolShed ROM assembly, fresh Quartus builds, functional and fitted timing checks, reviewed release packaging and passwordless SSH installation with backups. Retain original component notices, document contribution copyright and keep SSC ROM inputs outside Git. Validation: Quartus17.0.2 Build602 seed5, zero errors; 15 functional jobs, 368 both-corner timing scopes and eight tooling-integrity checks pass. The renamed build reaches Disk BASIC, PRINT1+1 returns2 and SSC loads ready. Physical cold power cycling and conditional board-delay assumptions remain separate. Full original upstream histories are preserved before this single consolidated implementation commit.
This commit is contained in:
1 parent
8b8cf72d1f
commit
cb40fed3b9
126 files changed
+12795
-528
No files matched your search
+2
-8
@@ -1,11 +1,5 @@
|
||||
create_clock -period 1000.000 -name img_mounted[5] [get_nodes emu:emu|hps_io:hps_io|img_mounted[5]]
|
||||
create_clock -period 1000.000 -name img_mounted[4] [get_nodes emu:emu|hps_io:hps_io|img_mounted[4]]
|
||||
create_clock -period 1000.000 -name img_mounted[3] [get_nodes emu:emu|hps_io:hps_io|img_mounted[3]]
|
||||
create_clock -period 1000.000 -name img_mounted[2] [get_nodes emu:emu|hps_io:hps_io|img_mounted[2]]
|
||||
create_clock -period 1000.000 -name img_mounted[1] [get_nodes emu:emu|hps_io:hps_io|img_mounted[1]]
|
||||
create_clock -period 1000.000 -name img_mounted[0] [get_nodes emu:emu|hps_io:hps_io|img_mounted[0]]
|
||||
create_clock -period 1000.000 -name RESET_N [get_nodes emu:emu|coco3fpga:coco3|RESET_N]
|
||||
create_clock -period 1000.000 -name NMISample2 [get_nodes emu:emu|coco3fpga:coco3|mc6809x:GLBCPU09|NMISample2]
|
||||
# Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
# Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
#set_false_path -from [get_nodes sysmem_lite:sysmem|sysmem_HPS_fpga_interfaces:fpga_interfaces|clocks_resets~FF_4365]
|
||||
#create_clock -period 17.46 -name PH_2 [get_nodes emu:emu|coco3fpga:coco3|PH_2_RAW]
|
||||
#create_clock -period 1000.000 -name CLK_6551[4] [get_nodes emu:emu|coco3fpga:coco3|CLK_6551[4]]
|
||||
|
||||
+18
-4
@@ -1,3 +1,5 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Project Name: CoCo3FPGA Version 4.0
|
||||
// File Name: EE_Cold_Bt.v
|
||||
@@ -66,6 +68,18 @@ output EE_to_COCO // Easter Egg to the coco3
|
||||
);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Research: qualify slow-domain control before its program-decode logic.
|
||||
(* preserve *) reg [1:0] boot_control_release = 2'b00;
|
||||
(* preserve *) reg [1:0] display_control_release = 2'b00;
|
||||
always @(posedge CLK or posedge RESET)
|
||||
if (RESET) begin
|
||||
boot_control_release <= 2'b00;
|
||||
display_control_release <= 2'b00;
|
||||
end else begin
|
||||
boot_control_release <= {boot_control_release[0], Cold_Boot};
|
||||
display_control_release <= {display_control_release[0], Display_EE};
|
||||
end
|
||||
|
||||
reg Display_EE_D = 1'b0;
|
||||
reg Cold_Boot_D = 1'b0;
|
||||
wire Start_Display_EE, Start_Cold_Boot;
|
||||
@@ -103,8 +117,8 @@ localparam inst_SHORT_TIMER = 4'd5;
|
||||
localparam inst_LONG_TIMER = 4'd6;
|
||||
localparam inst_START = 4'd8;
|
||||
|
||||
assign Start_Display_EE = ((Display_EE == 1'b1) & (Display_EE_D == 1'b0));
|
||||
assign Start_Cold_Boot = ((Cold_Boot == 1'b1) & (Cold_Boot_D == 1'b0));
|
||||
assign Start_Display_EE = ((display_control_release[1] == 1'b1) & (Display_EE_D == 1'b0));
|
||||
assign Start_Cold_Boot = ((boot_control_release[1] == 1'b1) & (Cold_Boot_D == 1'b0));
|
||||
|
||||
|
||||
always @ (posedge CLK or posedge RESET)
|
||||
@@ -121,8 +135,8 @@ begin
|
||||
end
|
||||
else
|
||||
begin
|
||||
Display_EE_D <= Display_EE;
|
||||
Cold_Boot_D <= Cold_Boot;
|
||||
Display_EE_D <= display_control_release[1];
|
||||
Cold_Boot_D <= boot_control_release[1];
|
||||
|
||||
next_instruction <= 1'b0;
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Project Name: CoCo3FPGA Version 4.0
|
||||
// File Name: 6551rx.v
|
||||
@@ -167,6 +169,7 @@ begin
|
||||
RX_DATA0 <= 1'b1;
|
||||
RX_DATA1 <= 1'b1;
|
||||
READY <= 1'b0;
|
||||
PARITY_ERR <= 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
|
||||
+59
-12
@@ -1,3 +1,5 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Project Name: CoCo3FPGA Version 4.0
|
||||
// File Name: uart_6551.v
|
||||
@@ -133,6 +135,7 @@ reg TX_START;
|
||||
reg TDRE;
|
||||
reg RDRF;
|
||||
reg [10:0] TX_CLK_DIV;
|
||||
reg [3:0] baud_select;
|
||||
wire TX_CLK;
|
||||
wire RX_CLK;
|
||||
wire FRAME_BUF;
|
||||
@@ -151,6 +154,22 @@ reg [1:0] READ_STATE;
|
||||
wire GOT_DATA;
|
||||
reg READY0;
|
||||
reg READY1;
|
||||
// Research: independent async-assert, synchronous-release reset trees.
|
||||
// CPU state consumes falling edges; release its reset on rising edges.
|
||||
(* preserve *) reg [1:0] cpu_reset_release = 2'b00;
|
||||
(* preserve *) reg [1:0] serial_reset_release = 2'b00;
|
||||
wire CPU_RESET_N = cpu_reset_release[1];
|
||||
wire SERIAL_RESET_N = serial_reset_release[1];
|
||||
wire SOFTWARE_RESET = ({RW_N, CS, RS} == 5'b00101);
|
||||
always @(posedge CLK or negedge RESET_N)
|
||||
if (!RESET_N) cpu_reset_release <= 2'b00;
|
||||
else cpu_reset_release <= {cpu_reset_release[0], 1'b1};
|
||||
// Software reset request is held in the CPU domain until its next bus event.
|
||||
// Only these synchronizer async inputs see the unsynchronized reset sources.
|
||||
always @(posedge CLK or negedge RESET_X)
|
||||
if (!RESET_X) serial_reset_release <= 2'b00;
|
||||
else serial_reset_release <= {serial_reset_release[0], 1'b1};
|
||||
|
||||
/*
|
||||
Baud rate divisors
|
||||
(for toggle of baud clock bit)
|
||||
@@ -173,16 +192,23 @@ F 19200 3
|
||||
|
||||
//assign TX_CLK_REG = TX_CLK_REG_T & XTAL_CLK_IN;
|
||||
|
||||
always @ (negedge CLK or negedge RESET_X)
|
||||
always @ (negedge CLK or negedge SERIAL_RESET_N)
|
||||
begin
|
||||
if(!RESET_X)
|
||||
if(!SERIAL_RESET_N)
|
||||
begin
|
||||
TX_CLK_DIV <= 11'h000;
|
||||
baud_select <= 0;
|
||||
TX_CLK_REG_T <= 1'b0;
|
||||
TX_CLK_REG <= 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
else if (baud_select != CTL_REG[3:0]) begin
|
||||
baud_select <= CTL_REG[3:0];
|
||||
TX_CLK_DIV <= 0;
|
||||
TX_CLK_REG_T <= 0;
|
||||
TX_CLK_REG <= 0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
TX_CLK_REG <= 1'b0;
|
||||
if (XTAL_CLK_IN)
|
||||
begin
|
||||
@@ -314,9 +340,10 @@ assign RX_CLK = (CTL_REG[4] == 1'b0) ? RX_CLK_IN:
|
||||
assign RESET_X = RESET_NX ? 1'b0:
|
||||
RESET_N;
|
||||
|
||||
always @ (negedge CLK)
|
||||
always @ (negedge CLK or negedge SERIAL_RESET_N)
|
||||
begin
|
||||
if (TX_CLK)
|
||||
if (!SERIAL_RESET_N) LOOPBACK <= 0;
|
||||
else if (TX_CLK)
|
||||
LOOPBACK <= {LOOPBACK[6:0], TX_DATA}; //half bit time FIFO
|
||||
end
|
||||
|
||||
@@ -347,9 +374,9 @@ assign STOP = (CTL_REG[7] == 1'b0) ? 1'b0: // Stop = 1
|
||||
assign PAR_DIS = ~CMD_REG[5];
|
||||
assign WORD_SELECT = CTL_REG[6:5];
|
||||
|
||||
always @ (negedge CLK or negedge RESET_N)
|
||||
always @ (negedge CLK or negedge CPU_RESET_N)
|
||||
begin
|
||||
if(!RESET_N)
|
||||
if(!CPU_RESET_N)
|
||||
RESET_NX <= 1'b1;
|
||||
else
|
||||
begin
|
||||
@@ -361,9 +388,29 @@ begin
|
||||
end
|
||||
end
|
||||
|
||||
always @ (negedge CLK or negedge RESET_X)
|
||||
always @ (negedge CLK or negedge CPU_RESET_N)
|
||||
begin
|
||||
if(!RESET_X)
|
||||
if(!CPU_RESET_N)
|
||||
begin
|
||||
RDRF <= 1'b0;
|
||||
READ_STATE <= 2'b00;
|
||||
TX_BUFFER <= 8'h00;
|
||||
CTL_REG <= 8'h00;
|
||||
// Commador data sheet says reset value is 02
|
||||
// but Apple will not work unless it is 00
|
||||
CMD_REG <= 8'h00;
|
||||
TDRE <= 1'b1;
|
||||
TX_START <= 1'b0;
|
||||
RX_REG <= 8'h00;
|
||||
OVERRUN <= 1'b0;
|
||||
FRAME <= 1'b0;
|
||||
PARITY <= 1'b0;
|
||||
TX_DONE1 <= 1'b1;
|
||||
TX_DONE0 <= 1'b1;
|
||||
READY0 <= 1'b0;
|
||||
READY1 <= 1'b0;
|
||||
end
|
||||
else if (RESET_NX || (PH_2 && SOFTWARE_RESET))
|
||||
begin
|
||||
RDRF <= 1'b0;
|
||||
READ_STATE <= 2'b00;
|
||||
@@ -477,7 +524,7 @@ begin
|
||||
end
|
||||
|
||||
uart51_tx tx(
|
||||
.RESET_N(RESET_X),
|
||||
.RESET_N(SERIAL_RESET_N),
|
||||
.CLK(CLK),
|
||||
.BAUD_CLK(TX_CLK),
|
||||
.TX_DATA(TX_DATA),
|
||||
@@ -492,7 +539,7 @@ uart51_tx tx(
|
||||
);
|
||||
|
||||
uart51_rx rx(
|
||||
.RESET_N(RESET_X),
|
||||
.RESET_N(SERIAL_RESET_N),
|
||||
.CLK(CLK),
|
||||
.BAUD_CLK(RX_CLK),
|
||||
.RX_DATA(RX_DATA),
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// 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 persistent four-slot layout. Main's normal status exchange owns
|
||||
// storage; this module migrates old settings and moves singleton devices.
|
||||
module bh_mpi_config(
|
||||
input wire clk,reset,input wire [63:0] requested,
|
||||
output reg [63:0] accepted=0,
|
||||
output reg [63:0] status_in=0,output reg status_set=0);
|
||||
// Each slot: 0 empty,1 ROM,2 floppy,3 SDC,4 SSC,5 Orchestra,6 legacy audio,
|
||||
// 7 RS232. Audio is an explicitly named convenience combination preserving the old
|
||||
// independent Orchestra plus switchable SSC, not a physical cartridge claim.
|
||||
localparam [11:0] ORIGINAL={3'd2,3'd1,3'd3,3'd6};
|
||||
reg [63:0] last_requested=~64'd0;
|
||||
reg pending=0;
|
||||
reg host_started=0;
|
||||
reg [63:0] next_status;
|
||||
reg [11:0] layout;
|
||||
reg [4:0] used,mask,remaining;
|
||||
reg [2:0] kind;
|
||||
reg has_ssc;
|
||||
integer i,j,primary,order;
|
||||
function [4:0] devices(input [2:0] k);
|
||||
begin case(k)
|
||||
2:devices=1;3:devices=2;4:devices=4;5:devices=8;
|
||||
6:devices=12;7:devices=16;default:devices=0;
|
||||
endcase end
|
||||
endfunction
|
||||
always_comb begin
|
||||
next_status=requested;
|
||||
if(!requested[63])begin
|
||||
next_status[63]=1;
|
||||
next_status[13:12]=requested[13:12]+2'd1;
|
||||
next_status[54:43]=ORIGINAL;
|
||||
end
|
||||
layout=next_status[54:43];primary=0;
|
||||
// Most recently edited slot wins; a persisted multi-edit has a deterministic
|
||||
// highest changed slot. Read-only/default fields never move devices.
|
||||
for(i=0;i<4;i=i+1)
|
||||
if(layout[i*3+:3]!=accepted[43+i*3+:3])primary=i;
|
||||
used=0;
|
||||
for(order=0;order<5;order=order+1)begin
|
||||
j=(order==0)?primary:order-1;
|
||||
if(order==0||j!=primary)begin
|
||||
kind=layout[j*3+:3];mask=devices(kind);remaining=mask&~used;
|
||||
if(mask!=0&&remaining!=mask)begin
|
||||
if(kind==6&&remaining==4)kind=4;
|
||||
else if(kind==6&&remaining==8)kind=5;
|
||||
else kind=0;
|
||||
end
|
||||
layout[j*3+:3]=kind;used=used|devices(kind);
|
||||
end
|
||||
end
|
||||
next_status[54:43]=layout;
|
||||
has_ssc=0;
|
||||
for(i=0;i<4;i=i+1)has_ssc=has_ssc||layout[i*3+:3]==4||layout[i*3+:3]==6;
|
||||
if(!has_ssc)next_status[42]=0;
|
||||
if(requested[63]&&layout[primary*3+:3]==4&&
|
||||
accepted[43+primary*3+:3]!=4)next_status[42]=1;
|
||||
end
|
||||
always @(posedge clk)begin
|
||||
status_set<=0;
|
||||
if(reset)begin
|
||||
accepted<=0;last_requested<=~64'd0;pending<=0;status_in<=0;host_started<=0;
|
||||
end else begin
|
||||
if(requested[0])host_started<=1;
|
||||
// Main polls status requests after every FC transfer; acknowledgement clears
|
||||
// bit0. Publishing default migration during initialization would prematurely
|
||||
// end its reset-held ROM-loading phase. Wait for Main's own final release,
|
||||
// and never publish a pending snapshot while a newer host value is arriving.
|
||||
if(host_started&&!requested[0]&&requested==last_requested&&pending&&!status_set)
|
||||
begin status_set<=1;pending<=0;end
|
||||
if(requested!=last_requested)begin
|
||||
last_requested<=requested;accepted<=next_status;
|
||||
status_in<=next_status;pending<=requested!=next_status;
|
||||
end
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,129 @@
|
||||
// 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
|
||||
// Four private ROM address spaces, up to128 KiB each, sharing256 KiB of16 KiB
|
||||
// blocks. Four full128 KiB memories exceed this core's fitted M10K budget.
|
||||
// Same synchronous read edge as the previous COCO_ROM_CART. Loading one slot
|
||||
// never overwrites another or the built-in disk ROM. Partial/oversized streams
|
||||
// cannot expose stale bytes as a successfully loaded cartridge.
|
||||
module bh_mpi_rom(
|
||||
input wire clk,power_reset,input wire [1:0] read_slot,
|
||||
input wire [16:0] read_address,output wire [7:0] read_data,
|
||||
input wire download,wr,input wire [7:0] file_index,
|
||||
input wire [24:0] address,input wire [7:0] data,
|
||||
output wire loading,output reg [3:0] valid=0,fault=0,
|
||||
output reg loaded_pulse=0,input wire [3:0] enabled);
|
||||
reg [7:0] memory[0:262143];
|
||||
reg [3:0] blocks[0:31];
|
||||
reg [15:0] owned[0:3];
|
||||
reg [15:0] used=0;
|
||||
// HPS changes its bus on the opposite edge. Capture raw fields first; all
|
||||
// allocation/validation/RAM write logic then has a full clock period rather
|
||||
// than decoding HPS index and driving256 M10Ks in half a period.
|
||||
reg p_download=0,p_wr=0;
|
||||
reg [7:0] p_file_index=0,p_data=0;
|
||||
reg [24:0] p_address=0;
|
||||
reg [17:0] lengths[0:3];
|
||||
reg [16:0] masks[0:3];
|
||||
wire [5:0] index=p_file_index[5:0];
|
||||
wire selected=index==1||index==6||index==7||index==8||index==9;
|
||||
wire [1:0] target=index==6?0:index==7?1:index==9?3:2;
|
||||
reg active=0;
|
||||
reg [1:0] slot;
|
||||
reg [5:0] saved_index;
|
||||
reg [17:0] count;
|
||||
reg malformed;
|
||||
reg [7:0] sampled;
|
||||
reg sampled_valid=0;
|
||||
reg [16:0] next_mask;
|
||||
reg [15:0] start_used;
|
||||
reg [15:0] released;
|
||||
reg [4:0] available_block;
|
||||
integer n;
|
||||
integer k;
|
||||
wire [16:0] offset=read_address&masks[read_slot];
|
||||
function [4:0] find_free(input [15:0] occupancy);
|
||||
integer b;
|
||||
begin find_free=16;
|
||||
for(b=15;b>=0;b=b-1)if(!occupancy[b])find_free=b;
|
||||
end
|
||||
endfunction
|
||||
always_comb begin
|
||||
start_used=0;released=0;
|
||||
for(k=0;k<4;k=k+1)begin
|
||||
if(k!=target&&enabled[k])start_used=start_used|owned[k];
|
||||
if(!enabled[k])released=released|owned[k];
|
||||
end
|
||||
end
|
||||
wire raw_selected=file_index[5:0]==1||file_index[5:0]==6||
|
||||
file_index[5:0]==7||file_index[5:0]==8||file_index[5:0]==9;
|
||||
wire [1:0] raw_target=file_index[5:0]==6?0:file_index[5:0]==7?1:file_index[5:0]==9?3:2;
|
||||
assign loading=(download&&raw_selected&&enabled[raw_target])||
|
||||
(p_download&&selected&&enabled[target])||active;
|
||||
assign read_data=sampled_valid?sampled:8'hff;
|
||||
always @(posedge clk)begin
|
||||
loaded_pulse<=0;
|
||||
sampled<=memory[{blocks[{read_slot,offset[16:14]}],offset[13:0]}];
|
||||
sampled_valid<=valid[read_slot]&&
|
||||
({1'b0,(read_address&masks[read_slot])}<lengths[read_slot]);
|
||||
if(power_reset)begin
|
||||
p_download<=0;p_wr<=0;p_file_index<=0;p_address<=0;p_data<=0;
|
||||
valid<=0;fault<=0;active<=0;sampled_valid<=0;count<=0;malformed<=0;
|
||||
used<=0;
|
||||
for(n=0;n<4;n=n+1)begin lengths[n]<=0;masks[n]<=0;owned[n]<=0;end
|
||||
end else begin
|
||||
p_download<=download;p_wr<=wr;p_file_index<=file_index;
|
||||
p_address<=address;p_data<=data;
|
||||
used<=used&~released;
|
||||
for(n=0;n<4;n=n+1)if(!enabled[n])begin
|
||||
valid[n]<=0;fault[n]<=0;owned[n]<=0;lengths[n]<=0;
|
||||
end
|
||||
if(active&&!enabled[slot])begin
|
||||
active<=0;used<=used&~released;
|
||||
end else if(p_download&&selected&&enabled[target]&&!active)begin
|
||||
active<=1;slot<=target;saved_index<=index;count<=p_wr?1:0;
|
||||
malformed<=p_wr&&p_address!=0;valid[target]<=0;fault[target]<=0;
|
||||
used<=start_used;owned[target]<=0;
|
||||
if(p_wr&&p_address==0)begin
|
||||
available_block=find_free(start_used);
|
||||
if(available_block==16)malformed<=1;
|
||||
else begin
|
||||
blocks[{target,3'd0}]<=available_block[3:0];
|
||||
used<=start_used|(16'b1<<available_block);
|
||||
owned[target]<=16'b1<<available_block;
|
||||
memory[{available_block[3:0],14'd0}]<=p_data;
|
||||
end
|
||||
end
|
||||
end else if(active&&p_download&&p_wr)begin
|
||||
if(index!=saved_index||p_address!={7'd0,count}||count>=131072)
|
||||
malformed<=1;
|
||||
else if(!malformed)begin
|
||||
if(p_address[13:0]==0)begin
|
||||
available_block=find_free(used&~released);
|
||||
if(available_block==16)malformed<=1;
|
||||
else begin
|
||||
blocks[{slot,p_address[16:14]}]<=available_block[3:0];
|
||||
used<=(used&~released)|(16'b1<<available_block);
|
||||
owned[slot]<=owned[slot]|(16'b1<<available_block);
|
||||
memory[{available_block[3:0],14'd0}]<=p_data;
|
||||
end
|
||||
end else memory[{blocks[{slot,p_address[16:14]}],p_address[13:0]}]<=p_data;
|
||||
end
|
||||
if(count<131073)count<=count+1'd1;
|
||||
end
|
||||
if(active&&enabled[slot]&&!p_download)begin
|
||||
active<=0;
|
||||
if(!malformed&&count!=0&&count<=131072)begin
|
||||
lengths[slot]<=count;next_mask=count-1'd1;
|
||||
next_mask=next_mask|(next_mask>>1);next_mask=next_mask|(next_mask>>2);
|
||||
next_mask=next_mask|(next_mask>>4);next_mask=next_mask|(next_mask>>8);
|
||||
next_mask=next_mask|(next_mask>>16);
|
||||
masks[slot]<=next_mask;valid[slot]<=1;loaded_pulse<=1;
|
||||
end else begin
|
||||
valid[slot]<=0;fault[slot]<=1;lengths[slot]<=0;
|
||||
used<=(used&~released)&~owned[slot];owned[slot]<=0;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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
|
||||
// One shared engine per controller, independently placeable in four sockets.
|
||||
// ROM and SCS selectors remain separate, software-addressable MPI fields.
|
||||
module bh_mpi_router(
|
||||
input wire [11:0] layout,input wire [1:0] cts,scs,
|
||||
output wire [2:0] rom_kind,io_kind,
|
||||
output wire floppy_io,sdc_io,rom_io,serial_io,
|
||||
output reg ssc_present,orchestra_present,floppy_present,sdc_present);
|
||||
assign rom_kind=layout[cts*3+:3];
|
||||
assign io_kind=layout[scs*3+:3];
|
||||
assign floppy_io=io_kind==2;
|
||||
assign sdc_io=io_kind==3;
|
||||
assign rom_io=io_kind==1||io_kind==5||io_kind==6;
|
||||
// Legacy floppy/SDC setups include the existing RS232 endpoint. A separate
|
||||
// RS232 device can also be assigned without requiring a storage controller.
|
||||
assign serial_io=io_kind==2||io_kind==3||io_kind==7;
|
||||
integer n;
|
||||
always_comb begin
|
||||
ssc_present=0;orchestra_present=0;floppy_present=0;sdc_present=0;
|
||||
for(n=0;n<4;n=n+1)begin
|
||||
ssc_present=ssc_present||(layout[n*3+:3]==4)||(layout[n*3+:3]==6);
|
||||
orchestra_present=orchestra_present||(layout[n*3+:3]==5)||(layout[n*3+:3]==6);
|
||||
floppy_present=floppy_present||(layout[n*3+:3]==2);
|
||||
sdc_present=sdc_present||(layout[n*3+:3]==3);
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
+209
-136
@@ -1,3 +1,5 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Project Name: CoCo3FPGA Version 5.x.x
|
||||
// File Name: coco3fpga.sv
|
||||
@@ -83,6 +85,17 @@ input CLK_57,
|
||||
input CLK_28,
|
||||
input CLK_14,
|
||||
|
||||
// Research cartridge extension; FPGA power reset is distinct from CoCo reset.
|
||||
input SSC_POWER_RESET,
|
||||
input SSC_MODE,
|
||||
input [11:0] MPI_LAYOUT,
|
||||
input MPI_BOOT_LOADING,
|
||||
output [3:0] MPI_ROM_FAULT,
|
||||
output MPI_ROM_LOADING,
|
||||
output MPI_ROM_LOADED,
|
||||
output SSC_READY,
|
||||
output SSC_FAULT,
|
||||
|
||||
input COCO_RESET_N,
|
||||
|
||||
// Video
|
||||
@@ -263,13 +276,28 @@ wire PH_2;
|
||||
`ifndef CoCo3_CYC_ACC_6809
|
||||
reg PH_2_RAW;
|
||||
`endif
|
||||
reg RESET_N;
|
||||
reg RESET_RAW_N;
|
||||
(* preserve *) reg [1:0] reset_main_release = 2'b00;
|
||||
(* preserve *) reg [1:0] reset_positive_release = 2'b00;
|
||||
(* preserve *) reg [1:0] reset_fast_release = 2'b00;
|
||||
wire RESET_N = reset_main_release[1];
|
||||
wire RESET_POS_N = reset_positive_release[1];
|
||||
wire RESET_FAST_N = reset_fast_release[1];
|
||||
always @(negedge clk_sys or negedge RESET_RAW_N)
|
||||
if (!RESET_RAW_N) reset_main_release <= 2'b00;
|
||||
else reset_main_release <= {reset_main_release[0], 1'b1};
|
||||
always @(posedge clk_sys or negedge RESET_RAW_N)
|
||||
if (!RESET_RAW_N) reset_positive_release <= 2'b00;
|
||||
else reset_positive_release <= {reset_positive_release[0], 1'b1};
|
||||
always @(posedge CLK_114 or negedge RESET_RAW_N)
|
||||
if (!RESET_RAW_N) reset_fast_release <= 2'b00;
|
||||
else reset_fast_release <= {reset_fast_release[0], 1'b1};
|
||||
reg [6:0] CPU_RESET_SM;
|
||||
reg CPU_RESET;
|
||||
wire RESET_INS;
|
||||
reg MUGS = 0;
|
||||
wire RESET;
|
||||
wire RESET_P;
|
||||
(* keep *) wire RESET_P;
|
||||
wire [15:0] ADDRESS;
|
||||
wire [11:0] BLOCK_ADDRESS; // 5:0 for 512kb
|
||||
wire RW_N;
|
||||
@@ -335,6 +363,29 @@ wire HDD_EN_DATA;
|
||||
|
||||
reg [1:0] MPI_SCS; // IO select
|
||||
reg [1:0] MPI_CTS; // ROM select
|
||||
wire [2:0] mpi_rom_kind,mpi_io_kind;
|
||||
wire mpi_floppy_io,mpi_sdc_io,mpi_rom_io,mpi_serial_io;
|
||||
wire mpi_ssc_present,mpi_orchestra_present,mpi_floppy_present,mpi_sdc_present;
|
||||
bh_mpi_router mpi_router(.layout(MPI_LAYOUT),.cts(MPI_CTS),.scs(MPI_SCS),
|
||||
.rom_kind(mpi_rom_kind),.io_kind(mpi_io_kind),.floppy_io(mpi_floppy_io),
|
||||
.sdc_io(mpi_sdc_io),.rom_io(mpi_rom_io),.serial_io(mpi_serial_io),
|
||||
.ssc_present(mpi_ssc_present),.orchestra_present(mpi_orchestra_present),
|
||||
.floppy_present(mpi_floppy_present),.sdc_present(mpi_sdc_present));
|
||||
wire mpi_rom_selected=mpi_rom_kind==1||mpi_rom_kind==5||mpi_rom_kind==6;
|
||||
wire [3:0] mpi_rom_valid;
|
||||
wire [3:0] mpi_rom_enabled;
|
||||
genvar mpi_rom_socket;
|
||||
generate for(mpi_rom_socket=0;mpi_rom_socket<4;mpi_rom_socket=mpi_rom_socket+1)begin: rom_socket_enable
|
||||
wire [2:0] device_kind=MPI_LAYOUT[mpi_rom_socket*3+:3];
|
||||
// Main parses FC records before loading its saved status/configuration. Keep
|
||||
// startup transfers until that reset-held phase ends, then discard sockets
|
||||
// absent from the restored layout. Ordinary reset does not reload FC files.
|
||||
assign mpi_rom_enabled[mpi_rom_socket]=MPI_BOOT_LOADING||device_kind==1||device_kind==5||device_kind==6;
|
||||
end endgenerate
|
||||
wire ssc_mode_active=SSC_MODE&&mpi_ssc_present;
|
||||
wire [7:0] mpi_orch_left=mpi_orchestra_present?ORCH_LEFT:8'h80;
|
||||
wire [7:0] mpi_orch_right=mpi_orchestra_present?ORCH_RIGHT:8'h80;
|
||||
|
||||
reg SBS;
|
||||
reg [11:0] SAM00; // 8MB 5:0 for 512kb
|
||||
reg [11:0] SAM01;
|
||||
@@ -415,7 +466,9 @@ wire [7:0] DATA_HDD;
|
||||
wire RS232_EN;
|
||||
wire RX_CLK2;
|
||||
wire [7:0] DATA_RS232;
|
||||
reg [2:0] ROM_BANK;
|
||||
reg [2:0] rom_banks[0:3];
|
||||
wire [2:0] ROM_BANK=rom_banks[MPI_CTS];
|
||||
integer rom_bank_index;
|
||||
wire SLOT3_HW;
|
||||
reg TICK0;
|
||||
reg TICK1;
|
||||
@@ -570,6 +623,18 @@ reg ANALOG;
|
||||
wire VDAC_EN;
|
||||
wire [15:0] VDAC_OUT;
|
||||
|
||||
wire ssc_palette_owner,ssc_read_valid,ssc_files_valid,ssc_operational,ssc_chip_fault;
|
||||
wire [7:0] ssc_read_data,ssc_host_data,ssc_chip_read_data,ssc_status;
|
||||
wire [15:0] ssc_host_address,ssc_debug_pc;
|
||||
wire ssc_host_read,ssc_host_write,ssc_cartridge_reset,ssc_chip_read_valid;
|
||||
wire ssc_pic_begin,ssc_pic_write,ssc_speech_begin,ssc_speech_write;
|
||||
wire [11:0] ssc_pic_address;
|
||||
wire [10:0] ssc_speech_address;
|
||||
wire [7:0] ssc_pic_data,ssc_speech_data;
|
||||
wire ssc_pic_loaded,ssc_speech_loaded,ssc_audio_valid,ssc_standby,ssc_activity;
|
||||
wire signed [15:0] ssc_audio;
|
||||
wire [15:0] ssc_legacy_left,ssc_legacy_right;
|
||||
|
||||
wire CART_INT_N;
|
||||
reg CART_INT_N_D;
|
||||
wire VSYNC_INT_N;
|
||||
@@ -797,11 +862,8 @@ assign FLASH_ADDRESS = ENA_DSK ? {9'b000000000, ADDRESS[12:0]
|
||||
//10 32 Internal
|
||||
//11 32 External
|
||||
|
||||
assign FLASH_CE_S = ROM_SEL ? 1'b1:
|
||||
ENA_DISK2 ? 1'b1:
|
||||
ENA_PAK ? 1'b1:
|
||||
ENA_DSK ? 1'b1:
|
||||
1'b0;
|
||||
// Empty cartridge sockets read an open bus, not the internal system ROM.
|
||||
assign FLASH_CE_S = ROM_SEL || CART_SEL;
|
||||
|
||||
wire [7:0] COCO3_ROM_DATA;
|
||||
wire [7:0] COCO3_DISK_ROM_DATA;
|
||||
@@ -814,8 +876,9 @@ localparam [5:0] BOOT = 6'd0;
|
||||
|
||||
|
||||
wire COCO3_ROM_WRITE = (ioctl_index[7:0] == {BOOT0, BOOT}) & ioctl_wr;
|
||||
wire COCO3_DISKROM_WRITE = (ioctl_index[7:0] == {BOOT1, BOOT}) & ioctl_wr;
|
||||
wire COCO3_CART_WRITE = (ioctl_index[5:0] == 6'd1) & ioctl_wr & !cart_lock;
|
||||
wire COCO3_DISKROM_WRITE = ((ioctl_index[7:0] == {BOOT1, BOOT}) ||
|
||||
(ioctl_index[5:0] == 6'd10)) & ioctl_wr;
|
||||
// Program-ROM streaming and validity are owned by bh_mpi_rom below.
|
||||
|
||||
reg rom_loaded = 1'b0;
|
||||
|
||||
@@ -858,52 +921,34 @@ COCO_ROM_8K CC3_DISK_ROM(
|
||||
);
|
||||
|
||||
|
||||
assign FLASH_DATA = ENA_PAK ? CART_DATA:
|
||||
(ENA_DSK || ENA_DISK2) ? COCO3_DISK_ROM_DATA:
|
||||
COCO3_ROM_DATA;
|
||||
assign FLASH_DATA = CART_SEL ?
|
||||
(mpi_rom_selected ? CART_DATA :
|
||||
(mpi_rom_kind==2||mpi_rom_kind==3) ? COCO3_DISK_ROM_DATA : 8'hff) :
|
||||
COCO3_ROM_DATA;
|
||||
|
||||
bh_mpi_rom mpi_program_roms(.clk(~clk_sys),.power_reset(SSC_POWER_RESET),
|
||||
.read_slot(MPI_CTS),.read_address(FLASH_ADDRESS[16:0]),.read_data(CART_DATA),
|
||||
.download(ioctl_download),.wr(ioctl_wr),.file_index(ioctl_index[7:0]),
|
||||
.address(ioctl_addr),.data(ioctl_data),.loading(MPI_ROM_LOADING),
|
||||
.valid(mpi_rom_valid),.fault(MPI_ROM_FAULT),.loaded_pulse(MPI_ROM_LOADED),
|
||||
.enabled(mpi_rom_enabled));
|
||||
|
||||
COCO_ROM_CART CC3_ROM_CART(
|
||||
.ADDR(FLASH_ADDRESS[16:0]),
|
||||
.DATA(CART_DATA),
|
||||
.CLK(~clk_sys),
|
||||
.WR_ADDR(ioctl_addr[16:0]),
|
||||
.WR_DATA(ioctl_data[7:0]),
|
||||
.WRITE(COCO3_CART_WRITE)
|
||||
);
|
||||
|
||||
wire SDC_EN_CS;
|
||||
|
||||
assign ENA_DISK2 = ({CART_SEL, MPI_CTS} == 3'b101) ? 1'b1: // Alternative Disk controller ROM up to 32K
|
||||
1'b0;
|
||||
|
||||
assign ENA_PAK = ({CART_SEL, MPI_CTS} == 3'b110) ? 1'b1: // ROM SLOT 3
|
||||
1'b0;
|
||||
|
||||
assign ENA_DSK = ({CART_SEL, MPI_CTS} == 3'b111) ? 1'b1: // Disk C000-DFFF Slot 4
|
||||
1'b0;
|
||||
wire SDC_EN_CS;
|
||||
assign ENA_DISK2=CART_SEL&&mpi_rom_kind==3;
|
||||
assign ENA_PAK=CART_SEL&&mpi_rom_selected;
|
||||
assign ENA_DSK=CART_SEL&&mpi_rom_kind==2;
|
||||
`ifdef CoCo3_sdc_fix_os9_driver
|
||||
assign HDD_EN = ({ext_response, MPI_SCS, ADDRESS[15:5]} == 15'b01111111111010) ? 1'b1: // FF40-FF5F with MPI switch = 4
|
||||
1'b0;
|
||||
|
||||
assign SDC_EN_CS = (({MPI_SCS, ADDRESS[15:5]} == 13'b0111111111010) |
|
||||
((ADDRESS[15:5] == 11'b11111111010) & ext_response)) ? 1'b1: // FF40-FF5F with MPI switch = 2
|
||||
1'b0;
|
||||
assign HDD_EN=mpi_floppy_io&&ADDRESS[15:5]==11'h7fa&&
|
||||
!(ext_response&&mpi_sdc_present);
|
||||
assign SDC_EN_CS=(mpi_sdc_io||(ext_response&&mpi_sdc_present))&&
|
||||
ADDRESS[15:5]==11'h7fa;
|
||||
`else
|
||||
assign HDD_EN = ({MPI_SCS, ADDRESS[15:5]} == 13'b1111111111010) ? 1'b1: // FF40-FF5F with MPI switch = 4
|
||||
1'b0;
|
||||
assign SDC_EN_CS = ({MPI_SCS, ADDRESS[15:5]} == 13'b0111111111010) ? 1'b1: // FF40-FF5F with MPI switch = 2
|
||||
1'b0;
|
||||
assign HDD_EN=mpi_floppy_io&&ADDRESS[15:5]==11'h7fa;
|
||||
assign SDC_EN_CS=mpi_sdc_io&&ADDRESS[15:5]==11'h7fa;
|
||||
`endif
|
||||
|
||||
//assign RS232_EN = ({MPI_SCS, ADDRESS[15:2]} == 16'b0011111111011010) ? 1'b1: //FF68-FF6B - Now in slot 1
|
||||
// 1'b0 ;
|
||||
|
||||
assign RS232_EN = ({MPI_SCS[0], ADDRESS[15:2]} == 15'b111111111011010) ? 1'b1: //FF68-FF6B - Now in slot 2 and 4
|
||||
1'b0;
|
||||
|
||||
assign SLOT3_HW = ({SWITCH[2:1], ADDRESS[15:5]} == 13'b1011111111010) ? 1'b1: // FF40-FF5F Ensure this only appears in slot 3 PHYSICALLY
|
||||
1'b0;
|
||||
assign RS232_EN=mpi_serial_io&&ADDRESS[15:2]==14'h3fda;
|
||||
// Bank writes follow the independently selected I/O socket.
|
||||
assign SLOT3_HW=mpi_rom_io&&ADDRESS[15:5]==11'h7fa;
|
||||
|
||||
assign VDAC_EN = ({RW_N,ADDRESS[15:0]} == 17'H0FF7E) ? 1'b1: // FF7E
|
||||
1'b0;
|
||||
@@ -917,7 +962,8 @@ always @(negedge clk_sys or negedge RESET_N)
|
||||
begin
|
||||
if(!RESET_N)
|
||||
begin
|
||||
ROM_BANK <= 3'b000;
|
||||
for(rom_bank_index=0;rom_bank_index<4;rom_bank_index=rom_bank_index+1)
|
||||
rom_banks[rom_bank_index] <= 3'b000;
|
||||
end
|
||||
else
|
||||
begin
|
||||
@@ -925,7 +971,7 @@ begin
|
||||
case (ADDRESS[4:0])
|
||||
5'h00:
|
||||
begin
|
||||
ROM_BANK <= DATA_OUT[2:0];
|
||||
rom_banks[MPI_SCS] <= DATA_OUT[2:0];
|
||||
end
|
||||
endcase
|
||||
end
|
||||
@@ -1067,13 +1113,14 @@ end
|
||||
|
||||
|
||||
assign DATA_IN =
|
||||
ssc_read_valid ? ssc_read_data :
|
||||
(sdram_BE_0) ? hold_data_L[7:0]:
|
||||
(sdram_BE_1) ? hold_data_L[15:8]:
|
||||
FLASH_CE_S ? FLASH_DATA:
|
||||
SDC_EN_CS ? DATA_SDC: // needs priority due to nitros9 llcocosdc ddriver bug
|
||||
HDD_EN ? DATA_HDD:
|
||||
RS232_EN ? DATA_RS232:
|
||||
SLOT3_HW ? {5'b00000, ROM_BANK}:
|
||||
SLOT3_HW ? {5'b00000, rom_banks[MPI_SCS]}:
|
||||
// FF00, FF04, FF08, FF0C, FF10, FF14, FF18, FF1C
|
||||
({ADDRESS[15:5], ADDRESS[1:0]} == 13'b11111111000_00) ? DATA_REG1:
|
||||
// FF01, FF05, FF09, FF0D, FF11, FF15, FF19, FF1D
|
||||
@@ -1205,10 +1252,20 @@ wire AMW_End;
|
||||
|
||||
assign AMW_ACK = AMW_End;
|
||||
|
||||
// A ROM transfer holds the system reset. Its short completion pulse cannot
|
||||
// survive the143ms system-release delay; retain the cold-start request until
|
||||
// the real AMW sequencer reaches its ready state and consumes the first write.
|
||||
reg mpi_rom_cold_pending=0;
|
||||
always @(negedge clk_sys)begin
|
||||
if(SSC_POWER_RESET)mpi_rom_cold_pending<=0;
|
||||
else if(MPI_ROM_LOADING)mpi_rom_cold_pending<=1;
|
||||
else if(AMW_EN)mpi_rom_cold_pending<=0;
|
||||
end
|
||||
|
||||
AMW coco_AMW (
|
||||
.CLK(clk_sys),
|
||||
.RESET_N(RESET_N),
|
||||
.Trigger(AMW_Trigger),
|
||||
.Trigger(AMW_Trigger || (mpi_rom_cold_pending && AMW_Ready)),
|
||||
.Restart(1'b0),
|
||||
.Cycle_Run(AMW_WR),
|
||||
.AMW_Adrs(AMW_Adrs),
|
||||
@@ -1224,6 +1281,14 @@ reg [15:0] hold_data, hold_data_L;
|
||||
reg RAM0_BE0_L, RAM0_BE1_L;
|
||||
reg clear_data_ready, data_ready;
|
||||
|
||||
// Research: matching fast-clock falling-edge observations of completion.
|
||||
reg data_ready_phase;
|
||||
reg [15:0] hold_data_phase;
|
||||
always @(negedge CLK_114 or posedge clear_data_ready)
|
||||
if (clear_data_ready) data_ready_phase <= 1'b0;
|
||||
else data_ready_phase <= data_ready;
|
||||
always @(negedge CLK_114) hold_data_phase <= hold_data;
|
||||
|
||||
always @(posedge CLK_114 or posedge clear_data_ready)
|
||||
begin
|
||||
if (clear_data_ready)
|
||||
@@ -1314,14 +1379,14 @@ begin
|
||||
// If we are in hold were done @ data_ready.
|
||||
if (hold)
|
||||
begin
|
||||
if (data_ready)
|
||||
if (data_ready_phase)
|
||||
begin
|
||||
// Hold states are done - kill hold and set end hold to drive data
|
||||
hold <= 1'b0;
|
||||
end_hold <= 1'b1;
|
||||
cpu_cycle_ena <= 1'b1; // Cycle at the end of a memory transaction
|
||||
clear_data_ready <= 1'b1;
|
||||
hold_data_L <= hold_data;
|
||||
hold_data_L <= hold_data_phase;
|
||||
sdram_BE_0 <= RAM0_BE0_L;
|
||||
sdram_BE_1 <= RAM0_BE1_L;
|
||||
end
|
||||
@@ -1504,15 +1569,23 @@ begin
|
||||
MUGS <= RESET_INS; //This is holding a <ctrl><alt><ins> across a reset to activate the Easter Egg
|
||||
end
|
||||
|
||||
always @ (posedge clk_sys or posedge RESET_P)
|
||||
// Research: asynchronous request assertion, two-edge synchronized release.
|
||||
(* preserve, altera_attribute = "-name SYNCHRONIZER_IDENTIFICATION FORCED_IF_ASYNCHRONOUS" *)
|
||||
reg [1:0] reset_request_release = 2'b00;
|
||||
always @(posedge clk_sys or posedge RESET_P)
|
||||
if (RESET_P) reset_request_release <= 2'b00;
|
||||
else reset_request_release <= {reset_request_release[0], 1'b1};
|
||||
wire reset_request = !reset_request_release[1];
|
||||
|
||||
always @ (posedge clk_sys or posedge reset_request)
|
||||
begin
|
||||
reg [24:0] RESET_SM;
|
||||
|
||||
if(RESET_P)
|
||||
if(reset_request)
|
||||
begin
|
||||
RESET_SM <= 25'd0;
|
||||
CPU_RESET <= 1'b1;
|
||||
RESET_N <= 1'b0;
|
||||
RESET_RAW_N <= 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
@@ -1521,7 +1594,7 @@ begin
|
||||
// Take away RESET_N
|
||||
// Leave CPU_RESET Asserted
|
||||
begin
|
||||
RESET_N <= 1'b1;
|
||||
RESET_RAW_N <= 1'b1;
|
||||
CPU_RESET <= 1'b1;
|
||||
RESET_SM <= RESET_SM + 1'b1;
|
||||
end
|
||||
@@ -1529,7 +1602,7 @@ begin
|
||||
// Take away RESET_N & CPU_RESET
|
||||
// Stop RESET_SM count
|
||||
begin
|
||||
RESET_N <= 1'b1;
|
||||
RESET_RAW_N <= 1'b1;
|
||||
CPU_RESET <= 1'b0;
|
||||
end
|
||||
default:
|
||||
@@ -1617,7 +1690,7 @@ wire BUFFER_WRITE;
|
||||
|
||||
coco_mem_fetch video_fetch(
|
||||
.fast_clk(CLK_114),
|
||||
.RESET_N(RESET_N),
|
||||
.RESET_N(RESET_FAST_N),
|
||||
|
||||
// Memory Controller I/O
|
||||
.SDRAM_VID_REQ(sdram_vid_req),
|
||||
@@ -1780,58 +1853,15 @@ sdc_top coco_sdc_top(
|
||||
);
|
||||
|
||||
|
||||
reg cart_firq_enable;
|
||||
|
||||
reg firq_trig;
|
||||
reg cart_lock;
|
||||
|
||||
always @(negedge clk_sys or negedge RESET_N)
|
||||
begin
|
||||
if(!RESET_N)
|
||||
begin
|
||||
firq_trig <= 1'b0;
|
||||
cart_firq_enable <= 1'b1;
|
||||
cart_lock <= 1'b0;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if ((ioctl_index[5:0] == 6'd1) & ioctl_download)
|
||||
firq_trig <= 1'b1;
|
||||
|
||||
if (firq_trig)
|
||||
if (!ioctl_download)
|
||||
begin
|
||||
cart_firq_enable <= 1'b0;
|
||||
cart_lock <= 1'b1;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
//***********************************************************************
|
||||
// Interrupt Sources
|
||||
//***********************************************************************
|
||||
// Org FPGA code
|
||||
always @(negedge clk_sys or negedge RESET_N)
|
||||
begin
|
||||
if(!RESET_N)
|
||||
begin
|
||||
CART_INT_IN_N <= 1'b1;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if (PH_2)
|
||||
case (MPI_SCS)
|
||||
2'b00:
|
||||
CART_INT_IN_N <= (SER_IRQ);
|
||||
2'b01:
|
||||
CART_INT_IN_N <= (SER_IRQ);
|
||||
2'b10:
|
||||
CART_INT_IN_N <= (!CART_INT_IN_N | cart_firq_enable);
|
||||
2'b11:
|
||||
CART_INT_IN_N <= (SER_IRQ);
|
||||
endcase
|
||||
end
|
||||
// A loaded ROM drives the cartridge-present/autostart input only when CTS
|
||||
// selects its socket. Serial IRQ retains its own selected-controller path.
|
||||
always @(negedge clk_sys or negedge RESET_N)begin
|
||||
if(!RESET_N)CART_INT_IN_N<=1;
|
||||
else if(PH_2)begin
|
||||
CART_INT_IN_N <=
|
||||
(mpi_rom_selected&&mpi_rom_valid[MPI_CTS] ? !CART_INT_IN_N : 1'b1) &
|
||||
(mpi_serial_io ? SER_IRQ : 1'b1);
|
||||
end
|
||||
end
|
||||
|
||||
assign CART_INT_N = CART_INT_IN_N;
|
||||
@@ -3017,11 +3047,11 @@ begin
|
||||
|
||||
16'hFF7A:
|
||||
begin
|
||||
ORCH_LEFT <= DATA_OUT;
|
||||
if(mpi_orchestra_present)ORCH_LEFT <= DATA_OUT;
|
||||
end
|
||||
16'hFF7B:
|
||||
begin
|
||||
ORCH_RIGHT <= DATA_OUT;
|
||||
if(mpi_orchestra_present)ORCH_RIGHT <= DATA_OUT;
|
||||
end
|
||||
16'hFF7F:
|
||||
begin
|
||||
@@ -3560,8 +3590,35 @@ end
|
||||
assign SOUND = SOUND_EN ? {SOUND_DTOA, 2'b00}:
|
||||
{SBS,SBS,SBS,SBS,SBS,SBS, 2'b00};
|
||||
|
||||
assign SOUND_LEFT = {ORCH_LEFT, ORCH_LEFT} + {SOUND, SOUND};
|
||||
assign SOUND_RIGHT = {ORCH_RIGHT, ORCH_RIGHT} + {SOUND, SOUND};
|
||||
assign ssc_legacy_left = {mpi_orch_left,mpi_orch_left}+{SOUND,SOUND};
|
||||
assign ssc_legacy_right = {mpi_orch_right,mpi_orch_right}+{SOUND,SOUND};
|
||||
|
||||
ssc_mister_bridge ssc_bridge(
|
||||
.clk(clk_sys),.reset(SSC_POWER_RESET),.cpu_reset(!RESET_POS_N),.mode(ssc_mode_active),
|
||||
.cpu_commit(PH_2),.cpu_rnw(RW_N),.cpu_address(ADDRESS),.cpu_data(DATA_OUT),
|
||||
.ioctl_download(ioctl_download),.ioctl_wr(ioctl_wr),.ioctl_index(ioctl_index[7:0]),
|
||||
.ioctl_address(ioctl_addr),.ioctl_data(ioctl_data),
|
||||
.cartridge_operational(ssc_operational),.cartridge_fault(ssc_chip_fault),
|
||||
.cartridge_read_data(ssc_status),.cartridge_audio(ssc_audio),
|
||||
.sound_enable(SOUND_EN),.sound_select(SEL),.orchestra_left(mpi_orch_left),.orchestra_right(mpi_orch_right),
|
||||
.legacy_left(ssc_legacy_left),.legacy_right(ssc_legacy_right),
|
||||
.cartridge_reset(ssc_cartridge_reset),.host_read(ssc_host_read),.host_write(ssc_host_write),
|
||||
.host_address(ssc_host_address),.host_data(ssc_host_data),
|
||||
.read_valid(ssc_read_valid),.read_data(ssc_read_data),.palette_owner(ssc_palette_owner),
|
||||
.rom_files_valid(ssc_files_valid),.load_fault(SSC_FAULT),
|
||||
.pic_begin(ssc_pic_begin),.pic_write(ssc_pic_write),.pic_address(ssc_pic_address),.pic_data(ssc_pic_data),
|
||||
.speech_begin(ssc_speech_begin),.speech_write(ssc_speech_write),.speech_address(ssc_speech_address),.speech_data(ssc_speech_data),
|
||||
.audio_left(SOUND_LEFT),.audio_right(SOUND_RIGHT));
|
||||
assign SSC_READY=mpi_ssc_present&&ssc_files_valid&&ssc_operational;
|
||||
ssc_cartridge #(.CLOCK_HZ(57272727)) ssc(
|
||||
.clk(clk_sys),.reset(SSC_POWER_RESET),.cartridge_reset(ssc_cartridge_reset),.enable(ssc_mode_active),
|
||||
.host_read(ssc_host_read),.host_write(ssc_host_write),.host_address(ssc_host_address),.host_data(ssc_host_data),
|
||||
.host_read_valid(ssc_chip_read_valid),.host_read_data(ssc_chip_read_data),
|
||||
.status(ssc_status),
|
||||
.pic_rom_begin(ssc_pic_begin),.pic_rom_write(ssc_pic_write),.pic_rom_address(ssc_pic_address),.pic_rom_data(ssc_pic_data),
|
||||
.speech_rom_begin(ssc_speech_begin),.speech_rom_write(ssc_speech_write),.speech_rom_address(ssc_speech_address),.speech_rom_data(ssc_speech_data),
|
||||
.pic_loaded(ssc_pic_loaded),.speech_loaded(ssc_speech_loaded),.operational(ssc_operational),.fault(ssc_chip_fault),
|
||||
.audio_sample(ssc_audio),.audio_valid(ssc_audio_valid),.speech_standby(ssc_standby),.sound_activity(ssc_activity),.debug_pc(ssc_debug_pc));
|
||||
|
||||
|
||||
// the DAC isn't really a DAC but represents the DAC chip on the schematic.
|
||||
@@ -3709,17 +3766,21 @@ assign KEYBOARD_IN[5] = !((!KEY_COLUMN[0] & KEY[40]) // 8
|
||||
| (!KEY_COLUMN[6] & KEY[46]) // .
|
||||
| (!KEY_COLUMN[7] & KEY[47])); // /
|
||||
|
||||
// Research: phase-match the remaining CPU keyboard control flags.
|
||||
reg [3:0] keyboard_cpu_controls = 4'b1000;
|
||||
always @(negedge clk_sys) keyboard_cpu_controls <= {EE_N, MUGS, SHIFT, SHIFT_OVERRIDE};
|
||||
|
||||
assign KEYBOARD_IN[6] = !((!KEY_COLUMN[0] & KEY[48]) // CR
|
||||
| (!KEY_COLUMN[1] & KEY[49]) // TAB
|
||||
| (!KEY_COLUMN[2] & KEY[50]) // ESC
|
||||
| (!KEY_COLUMN[3] & KEY[51]) // ALT
|
||||
| (!KEY_COLUMN[3] & (!BUTTON_N[0] | MUGS)) // ALT (Easter Egg)
|
||||
| (!KEY_COLUMN[3] & (!keyboard_cpu_controls[3] | keyboard_cpu_controls[2])) // ALT (Easter Egg)
|
||||
| (!KEY_COLUMN[4] & KEY[52]) // CTRL
|
||||
| (!KEY_COLUMN[4] & (!BUTTON_N[0] | MUGS)) // CTRL (Easter Egg)
|
||||
| (!KEY_COLUMN[4] & (!keyboard_cpu_controls[3] | keyboard_cpu_controls[2])) // CTRL (Easter Egg)
|
||||
| (!KEY_COLUMN[5] & KEY[53]) // F1
|
||||
| (!KEY_COLUMN[6] & KEY[54]) // F2
|
||||
| (!KEY_COLUMN[7] & KEY[55] & !SHIFT_OVERRIDE) // shift
|
||||
| (!KEY_COLUMN[7] & SHIFT)); // Forced Shift
|
||||
| (!KEY_COLUMN[7] & KEY[55] & !keyboard_cpu_controls[0]) // shift
|
||||
| (!KEY_COLUMN[7] & keyboard_cpu_controls[1])); // Forced Shift
|
||||
|
||||
assign KEYBOARD_IN[7] = JSTICK; // Joystick input
|
||||
|
||||
@@ -3730,20 +3791,22 @@ COCOKEY coco_keyboard(
|
||||
.SLO_CLK(V_SYNC_N),
|
||||
.PS2_CLK(ps2_clk),
|
||||
.PS2_DATA(ps2_data),
|
||||
.KEY(KEY_RCVD),
|
||||
.KEY(KEY_RAW),
|
||||
.SHIFT(SHIFT),
|
||||
.SHIFT_OVERRIDE(SHIFT_OVERRIDE),
|
||||
.RESET(RESET),
|
||||
.RESET_INS(RESET_INS)
|
||||
);
|
||||
|
||||
wire [72:0] KEY_RCVD;
|
||||
wire [72:0] KEY_RAW;
|
||||
reg [72:0] KEY_RCVD = 73'd0;
|
||||
always @(negedge clk_sys) KEY_RCVD <= KEY_RAW;
|
||||
|
||||
Auto_Run CoCo3_Auto_Run(
|
||||
.RESET_N(RESET_N),
|
||||
.CLK(clk_sys),
|
||||
.CLK_1_78(clk_1_78),
|
||||
.MPI_SCS(SWITCH[2:1]),
|
||||
.MPI_SCS(MPI_LAYOUT[SWITCH[2:1]*3+:3]==3 ? 2'b01 : 2'b11),
|
||||
.MODE(AUTO_MODE),
|
||||
.AMW_ACK(AMW_ACK),
|
||||
.KEY_IN(KEY_RCVD),
|
||||
@@ -3776,12 +3839,12 @@ end
|
||||
// Borrowed from MAC PLUS
|
||||
|
||||
wire ps2_x1, ps2_y1, ps2_x2, ps2_y2;
|
||||
wire ps2_button;
|
||||
wire ps2_button, ps2_button_raw;
|
||||
|
||||
ps2_mouse coco_ps2_mouse(
|
||||
.clk(clk_sys),
|
||||
.ce(PH_2),
|
||||
.reset(~RESET_N),
|
||||
.reset(~RESET_POS_N),
|
||||
|
||||
.ps2_mouse(ps2_mouse),
|
||||
|
||||
@@ -3789,7 +3852,7 @@ ps2_mouse coco_ps2_mouse(
|
||||
.y1(ps2_y1),
|
||||
.x2(ps2_x2),
|
||||
.y2(ps2_y2),
|
||||
.button(ps2_button)
|
||||
.button(ps2_button_raw)
|
||||
);
|
||||
|
||||
// This code creates a virtual joystick based on mouse movements.
|
||||
@@ -3797,14 +3860,18 @@ ps2_mouse coco_ps2_mouse(
|
||||
// [note check of boundry before inc / dev]
|
||||
|
||||
reg [7:0] mouse_x_pos, mouse_y_pos;
|
||||
wire [15:0] mouse_xy_pos = {mouse_x_pos, mouse_y_pos};
|
||||
// Research: CPU-facing mouse sample, retaining the original position decoder.
|
||||
reg [16:0] mouse_cpu_sample = 17'h18080;
|
||||
always @(negedge clk_sys) mouse_cpu_sample <= {ps2_button_raw, mouse_x_pos, mouse_y_pos};
|
||||
wire [15:0] mouse_xy_pos = mouse_cpu_sample[15:0];
|
||||
assign ps2_button = mouse_cpu_sample[16];
|
||||
reg [1:0] old_x, old_y;
|
||||
wire [1:0] x_mouse = {ps2_x1, ps2_x2};
|
||||
wire [1:0] y_mouse = {ps2_y1, ps2_y2};
|
||||
|
||||
always @ (posedge clk_sys or negedge RESET_N)
|
||||
always @ (posedge clk_sys or negedge RESET_POS_N)
|
||||
begin
|
||||
if(!RESET_N)
|
||||
if(!RESET_POS_N)
|
||||
begin
|
||||
mouse_x_pos <= 8'h80;
|
||||
mouse_y_pos <= 8'h80;
|
||||
@@ -3962,8 +4029,8 @@ VDAC VDAC_inst (
|
||||
// .rdclock ( PIX_CLK ),
|
||||
// KEY: 01/14/26
|
||||
.wraddress ( DATA_OUT ),
|
||||
.wrclock ( clk_sys ),
|
||||
.wren ( VDAC_EN & PH_2 ),
|
||||
.wrclock ( ~clk_sys ),
|
||||
.wren ( VDAC_EN & PH_2 & ssc_palette_owner ),
|
||||
.q ( VDAC_OUT )
|
||||
);
|
||||
|
||||
@@ -4190,14 +4257,20 @@ coco3_Char_ROM coco3_Char_ROM(
|
||||
);
|
||||
|
||||
|
||||
// Research: reset the UART enable generator with synchronous release.
|
||||
(* preserve *) reg [1:0] uart_tick_release = 2'b00;
|
||||
wire uart_tick_reset_n = uart_tick_release[1];
|
||||
always @(posedge clk_sys or negedge RESET_N)
|
||||
if (!RESET_N) uart_tick_release <= 2'b00;
|
||||
else uart_tick_release <= {uart_tick_release[0], 1'b1};
|
||||
reg [4:0] CLK_6551;
|
||||
// Targeting 1.8432 Mhz.
|
||||
// 57.272727 Mhz / 31 = 1.8475 Mhz
|
||||
reg CLK_6551_EN;
|
||||
|
||||
always @(negedge clk_sys or negedge RESET_N)
|
||||
always @(negedge clk_sys or negedge uart_tick_reset_n)
|
||||
begin
|
||||
if(!RESET_N)
|
||||
if(!uart_tick_reset_n)
|
||||
begin
|
||||
CLK_6551 <= 5'd0;
|
||||
CLK_6551_EN <= 1'b0;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
// Research request boundary for the MiSTer 57 MHz CPU / 114 MHz SDRAM interface.
|
||||
// Captures the complete selected CPU/GART/AMW payload after the core raises req.
|
||||
// The clocks are related PLL outputs; all crossings retain normal timing checks.
|
||||
module cpu_sdram_bridge (
|
||||
input clk, fast_clk, reset,
|
||||
input [24:0] cpu_addr,
|
||||
input [7:0] cpu_din,
|
||||
input cpu_req, cpu_rnw, memory_ack,
|
||||
output cpu_ack,
|
||||
output reg [24:0] memory_addr,
|
||||
output reg [7:0] memory_din,
|
||||
output reg memory_rnw,
|
||||
output reg memory_req = 1'b0
|
||||
);
|
||||
// A falling fast-clock observation avoids the coincident positive-fast /
|
||||
// negative-system edge for ACK. Both half-period transfers remain timed.
|
||||
reg ack_phase = 1'b0;
|
||||
always @(negedge fast_clk) ack_phase <= reset ? 1'b0 : memory_ack;
|
||||
assign cpu_ack = cpu_req && memory_req && ack_phase;
|
||||
always @(negedge clk) begin
|
||||
if (reset || !cpu_req) memory_req <= 1'b0;
|
||||
else if (!memory_req && !ack_phase) begin
|
||||
memory_addr <= cpu_addr;
|
||||
memory_din <= cpu_din;
|
||||
memory_rnw <= cpu_rnw;
|
||||
memory_req <= 1'b1;
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
+75
-24
@@ -1,3 +1,5 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Project Name: COCO3 Targeting MISTer
|
||||
// File Name: fdc.sv
|
||||
@@ -107,6 +109,12 @@ wire [5:0] div_8mhz;
|
||||
|
||||
assign ena_8Mhz = (div_8mhz == 6'd5) ? 1'b1: 1'b0;
|
||||
|
||||
// Research: local positive-edge reset release for the WD1793 banks.
|
||||
(* preserve *) reg [1:0] wd_reset_release = 2'b00;
|
||||
always @(posedge CLK or negedge RESET_N)
|
||||
if (!RESET_N) wd_reset_release <= 2'b00;
|
||||
else wd_reset_release <= {wd_reset_release[0], 1'b1};
|
||||
|
||||
always@(negedge CLK or negedge RESET_N)
|
||||
begin
|
||||
if (~RESET_N) div_8mhz <= 6'd0;
|
||||
@@ -393,52 +401,95 @@ reg [23:0] drive_size[4];
|
||||
|
||||
// Reset of drive wp to a default of 1 removed because of persistance.
|
||||
|
||||
// Research: mount strobes are data from hps_io, not clock sources.
|
||||
reg [3:0] img_mounted_d = 0;
|
||||
always @(posedge CLK) img_mounted_d <= img_mounted;
|
||||
|
||||
reg [3:0] mount_pending = 0;
|
||||
reg [3:0] mount_wp;
|
||||
reg [3:0] mount_double_sided;
|
||||
reg [23:0] mount_size[4];
|
||||
always @(posedge CLK) mount_pending <= img_mounted_d & ~img_mounted;
|
||||
|
||||
// Drive 0
|
||||
|
||||
always @(negedge img_mounted[0])
|
||||
always @(posedge CLK)
|
||||
begin
|
||||
drive_wp[0] <= img_readonly;
|
||||
drive_ready[0] <= 1'b1;
|
||||
drive_size[0] <= {4'h0, img_size[19:0]}; //Size / 256 on [19:8]
|
||||
double_sided[0]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
if (img_mounted_d[0] && !img_mounted[0])
|
||||
begin
|
||||
mount_wp[0] <= img_readonly;
|
||||
mount_size[0] <= {4'h0, img_size[19:0]}; //Size / 256 on [19:8]
|
||||
mount_double_sided[0]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
end
|
||||
end
|
||||
|
||||
// Drive 1
|
||||
|
||||
always @(negedge img_mounted[1])
|
||||
always @(posedge CLK)
|
||||
begin
|
||||
drive_wp[1] <= img_readonly;
|
||||
drive_ready[1] <= 1'b1;
|
||||
drive_size[1] <= {4'h0, img_size[19:0]}; //Size / 256 on [19:8]
|
||||
double_sided[1]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
if (img_mounted_d[1] && !img_mounted[1])
|
||||
begin
|
||||
mount_wp[1] <= img_readonly;
|
||||
mount_size[1] <= {4'h0, img_size[19:0]}; //Size / 256 on [19:8]
|
||||
mount_double_sided[1]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
end
|
||||
end
|
||||
|
||||
// Drive 2
|
||||
|
||||
always @(negedge img_mounted[2])
|
||||
always @(posedge CLK)
|
||||
begin
|
||||
drive_wp[2] <= img_readonly;
|
||||
drive_ready[2] <= 1'b1;
|
||||
drive_size[2] <= {4'h0, img_size[19:0]}; //Size / 256 on [19:8]
|
||||
double_sided[2]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
if (img_mounted_d[2] && !img_mounted[2])
|
||||
begin
|
||||
mount_wp[2] <= img_readonly;
|
||||
mount_size[2] <= {4'h0, img_size[19:0]}; //Size / 256 on [19:8]
|
||||
mount_double_sided[2]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
end
|
||||
end
|
||||
|
||||
// Drive 3
|
||||
|
||||
always @(negedge img_mounted[3])
|
||||
always @(posedge CLK)
|
||||
begin
|
||||
drive_wp[3] <= img_readonly;
|
||||
drive_ready[3] <= 1'b1;
|
||||
drive_size[3] <= {4'h0, img_size[19:0]}; //Size / 256 on [19:8]
|
||||
//double_sided[3]<= img_size > 20'd368600;//20'd368640;
|
||||
if (img_mounted_d[3] && !img_mounted[3])
|
||||
begin
|
||||
mount_wp[3] <= img_readonly;
|
||||
mount_size[3] <= {4'h0, img_size[19:0]}; //Size / 256 on [19:8]
|
||||
//mount_double_sided[3]<= img_size > 20'd368600;//20'd368640;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
// Research: commit metadata on consumer's falling phase after classification.
|
||||
always @(negedge CLK) if (mount_pending[0]) begin
|
||||
drive_wp[0] <= mount_wp[0];
|
||||
drive_ready[0] <= 1'b1;
|
||||
drive_size[0] <= mount_size[0];
|
||||
double_sided[0] <= mount_double_sided[0];
|
||||
end
|
||||
always @(negedge CLK) if (mount_pending[1]) begin
|
||||
drive_wp[1] <= mount_wp[1];
|
||||
drive_ready[1] <= 1'b1;
|
||||
drive_size[1] <= mount_size[1];
|
||||
double_sided[1] <= mount_double_sided[1];
|
||||
end
|
||||
always @(negedge CLK) if (mount_pending[2]) begin
|
||||
drive_wp[2] <= mount_wp[2];
|
||||
drive_ready[2] <= 1'b1;
|
||||
drive_size[2] <= mount_size[2];
|
||||
double_sided[2] <= mount_double_sided[2];
|
||||
end
|
||||
always @(negedge CLK) if (mount_pending[3]) begin
|
||||
drive_wp[3] <= mount_wp[3];
|
||||
drive_ready[3] <= 1'b1;
|
||||
drive_size[3] <= mount_size[3];
|
||||
end
|
||||
|
||||
wd1793 #(1,0) coco_wd1793_0
|
||||
(
|
||||
.clk_sys(~CLK),
|
||||
.ce(ena_8Mhz),
|
||||
.reset(~RESET_N),
|
||||
.reset(~wd_reset_release[1]),
|
||||
.io_en(1'b1),
|
||||
.rd(RD[0]),
|
||||
.wr(WR[0]),
|
||||
@@ -480,7 +531,7 @@ wd1793 #(1,0) coco_wd1793_1
|
||||
(
|
||||
.clk_sys(~CLK),
|
||||
.ce(ena_8Mhz),
|
||||
.reset(~RESET_N),
|
||||
.reset(~wd_reset_release[1]),
|
||||
.io_en(1'b1),
|
||||
.rd(RD[1]),
|
||||
.wr(WR[1]),
|
||||
@@ -522,7 +573,7 @@ wd1793 #(1,0) coco_wd1793_2
|
||||
(
|
||||
.clk_sys(~CLK),
|
||||
.ce(ena_8Mhz),
|
||||
.reset(~RESET_N),
|
||||
.reset(~wd_reset_release[1]),
|
||||
.io_en(1'b1),
|
||||
.rd(RD[2]),
|
||||
.wr(WR[2]),
|
||||
@@ -564,7 +615,7 @@ wd1793 #(1,0) coco_wd1793_3
|
||||
(
|
||||
.clk_sys(~CLK),
|
||||
.ce(ena_8Mhz),
|
||||
.reset(~RESET_N),
|
||||
.reset(~wd_reset_release[1]),
|
||||
.io_en(1'b1),
|
||||
.rd(RD[3]),
|
||||
.wr(WR[3]),
|
||||
|
||||
+51
-14
@@ -1,3 +1,5 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
`timescale 1ns / 1ns
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
// Company:
|
||||
@@ -191,14 +193,14 @@ reg [15:0] ea_p1;
|
||||
// NMI is supposed to be masked - despite the name - until the 6809 loads a value into S.
|
||||
// Frankly, I'm cheating slightly. If someone does a LDS #$0, it won't disable the mask. Pretty much anything else
|
||||
// that changes the value of S from the default (which is currently $0) will clear the mask. A reset will set the mask again.
|
||||
reg NMIMask;
|
||||
(* keep *) wire NMIMask;
|
||||
|
||||
reg NMILatched;
|
||||
(* keep *) wire NMILatched;
|
||||
reg rnRESET=0; // The latched version of /RESET, useful 1 clock after it's latched
|
||||
reg NMISample;
|
||||
reg NMISample2;
|
||||
reg NMIClear;
|
||||
reg NMIClear_nxt;
|
||||
wire wNMIClear = NMIClear;
|
||||
|
||||
reg IRQLatched;
|
||||
|
||||
@@ -534,14 +536,52 @@ endgenerate
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
always @(negedge NMISample2 or posedge wNMIClear)
|
||||
// Research: registered observations replace event clocks and next-S logic.
|
||||
// S and its prior master-cycle value expose the actual CPU register update,
|
||||
// avoiding the long instruction/ALU -> s_nxt comparator in the NMI mask path.
|
||||
reg [15:0] NMIStackPrevious;
|
||||
reg NMIMaskStored = 1'b1;
|
||||
reg NMIEdge = 1'b0;
|
||||
reg NMIPending = 1'b0;
|
||||
function NMIStackDiff;
|
||||
input [15:0] previous_value, current_value;
|
||||
begin
|
||||
NMIStackDiff = 1'b0;
|
||||
if (previous_value != current_value) NMIStackDiff = 1'b1;
|
||||
end
|
||||
endfunction
|
||||
wire NMIStackChanged = NMIStackDiff(NMIStackPrevious, s);
|
||||
assign NMIMask = NMIMaskStored && !NMIStackChanged;
|
||||
reg NMIQualifiedEdge;
|
||||
always @* begin
|
||||
NMIQualifiedEdge = 1'b0;
|
||||
if (NMIEdge)
|
||||
if (NMIClear == 1'b1) NMIQualifiedEdge = 1'b0;
|
||||
else if (NMIMask == 1'b0) NMIQualifiedEdge = 1'b1;
|
||||
end
|
||||
// The same-event view uses new registered mask/clear values after NBA updates.
|
||||
// Pending state retains that view on the next master edge; CPU-visible timing
|
||||
// therefore has no extra E-cycle, including back-to-back CPU enables.
|
||||
reg NMIVisible;
|
||||
always @* begin
|
||||
NMIVisible = 1'b1;
|
||||
if (NMIClear == 1'b1) NMIVisible = 1'b1;
|
||||
else if (NMIPending || NMIQualifiedEdge) NMIVisible = 1'b0;
|
||||
end
|
||||
assign NMILatched = NMIVisible;
|
||||
always @(negedge MASTER)
|
||||
begin
|
||||
if (wNMIClear == 1)
|
||||
NMILatched <= 1;
|
||||
else if (NMIMask == 0)
|
||||
NMILatched <= 0;
|
||||
else
|
||||
NMILatched <= 1;
|
||||
NMIStackPrevious <= s;
|
||||
if (!nRESET || !rnRESET) begin
|
||||
NMIMaskStored <= 1'b1;
|
||||
NMIEdge <= 1'b0;
|
||||
NMIPending <= 1'b0;
|
||||
end else begin
|
||||
NMIEdge <= E && NMISample2 && !NMISample;
|
||||
if (NMIStackChanged) NMIMaskStored <= 1'b0;
|
||||
if (NMIClear == 1'b1) NMIPending <= 1'b0;
|
||||
else if (NMIQualifiedEdge) NMIPending <= 1'b1;
|
||||
end
|
||||
end
|
||||
|
||||
//
|
||||
@@ -579,7 +619,6 @@ begin
|
||||
end
|
||||
end
|
||||
|
||||
reg rnRESET=0; // The latched version of /RESET, useful 1 clock after it's latched
|
||||
always @(negedge MASTER)
|
||||
begin
|
||||
if (E)
|
||||
@@ -635,13 +674,11 @@ begin
|
||||
|
||||
IntType <= IntType_nxt;
|
||||
|
||||
if (s != s_nxt) // Once S changes at all (default is '0'), release the NMI Mask.
|
||||
NMIMask <= 1'b0;
|
||||
|
||||
end
|
||||
else
|
||||
begin
|
||||
CpuState <= CPUSTATE_RESET;
|
||||
NMIMask <= 1'b1; // Mask NMI until S is loaded.
|
||||
NMIClear <= 1'b0; // Mark us as not having serviced NMI
|
||||
end
|
||||
end
|
||||
|
||||
+4
-1
@@ -1,3 +1,5 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Project Name: COCO3 Targeting MISTer
|
||||
// File Name: sdc.sv
|
||||
@@ -505,7 +507,8 @@ always_ff@(posedge clock) begin
|
||||
end
|
||||
end
|
||||
|
||||
always_ff@(posedge clock) begin
|
||||
// CPU port shares the CPU-consuming edge; host port A stays positive.
|
||||
always_ff@(negedge clock) begin
|
||||
if(wren_b) begin
|
||||
ram[address_b] <= data_b;
|
||||
q_b <= data_b;
|
||||
|
||||
+48
-12
@@ -1,3 +1,5 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Project Name: COCO3 Targeting MISTer
|
||||
// File Name: sdc_top.sv
|
||||
@@ -115,6 +117,12 @@ wire [5:0] div_8mhz;
|
||||
|
||||
assign ena_8Mhz = (div_8mhz == 6'd5) ? 1'b1: 1'b0;
|
||||
|
||||
// Research: local positive-edge reset release for the WD1793 banks.
|
||||
(* preserve *) reg [1:0] wd_reset_release = 2'b00;
|
||||
always @(posedge CLK or negedge RESET_N)
|
||||
if (!RESET_N) wd_reset_release <= 2'b00;
|
||||
else wd_reset_release <= {wd_reset_release[0], 1'b1};
|
||||
|
||||
always@(negedge CLK or negedge RESET_N)
|
||||
begin
|
||||
if (~RESET_N) div_8mhz <= 6'd0;
|
||||
@@ -443,32 +451,60 @@ reg [31:0] drive_size[2];
|
||||
|
||||
// Reset of drive wp to a default of 1 removed because of persistance.
|
||||
|
||||
// Research: mount strobes are data from hps_io, not clock sources.
|
||||
reg [1:0] img_mounted_d = 0;
|
||||
always @(posedge CLK) img_mounted_d <= img_mounted;
|
||||
|
||||
reg [1:0] mount_pending = 0;
|
||||
reg [1:0] mount_wp;
|
||||
reg [1:0] mount_double_sided;
|
||||
reg [31:0] mount_size[2];
|
||||
always @(posedge CLK) mount_pending <= img_mounted_d & ~img_mounted;
|
||||
|
||||
// Drive 0
|
||||
|
||||
always @(negedge img_mounted[0])
|
||||
always @(posedge CLK)
|
||||
begin
|
||||
drive_wp[0] <= img_readonly;
|
||||
drive_ready[0] <= 1'b1;
|
||||
drive_size[0] <= img_size[31:0]; //Size / 256 on [31:8]
|
||||
double_sided[0]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
if (img_mounted_d[0] && !img_mounted[0])
|
||||
begin
|
||||
mount_wp[0] <= img_readonly;
|
||||
mount_size[0] <= img_size[31:0]; //Size / 256 on [31:8]
|
||||
mount_double_sided[0]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
end
|
||||
end
|
||||
|
||||
// Drive 1
|
||||
|
||||
always @(negedge img_mounted[1])
|
||||
always @(posedge CLK)
|
||||
begin
|
||||
drive_wp[1] <= img_readonly;
|
||||
drive_ready[1] <= 1'b1;
|
||||
drive_size[1] <= img_size[31:0]; //Size / 256 on [31:8]
|
||||
double_sided[1]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
if (img_mounted_d[1] && !img_mounted[1])
|
||||
begin
|
||||
mount_wp[1] <= img_readonly;
|
||||
mount_size[1] <= img_size[31:0]; //Size / 256 on [31:8]
|
||||
mount_double_sided[1]<= (img_size > 64'd368600) & (img_size < 64'd740000);//20'd368640;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
// Research: commit metadata on consumer's falling phase after classification.
|
||||
always @(negedge CLK) if (mount_pending[0]) begin
|
||||
drive_wp[0] <= mount_wp[0];
|
||||
drive_ready[0] <= 1'b1;
|
||||
drive_size[0] <= mount_size[0];
|
||||
double_sided[0] <= mount_double_sided[0];
|
||||
end
|
||||
always @(negedge CLK) if (mount_pending[1]) begin
|
||||
drive_wp[1] <= mount_wp[1];
|
||||
drive_ready[1] <= 1'b1;
|
||||
drive_size[1] <= mount_size[1];
|
||||
double_sided[1] <= mount_double_sided[1];
|
||||
end
|
||||
|
||||
wd1793 #(1,0) coco_wd1793_sdc_0
|
||||
(
|
||||
.clk_sys(~CLK),
|
||||
.ce(ena_8Mhz),
|
||||
.reset(~RESET_N),
|
||||
.reset(~wd_reset_release[1]),
|
||||
.io_en(1'b1),
|
||||
.rd(RD[0]),
|
||||
.wr(WR[0]),
|
||||
@@ -510,7 +546,7 @@ wd1793 #(1,0) coco_wd1793_sdc_1
|
||||
(
|
||||
.clk_sys(~CLK),
|
||||
.ce(ena_8Mhz),
|
||||
.reset(~RESET_N),
|
||||
.reset(~wd_reset_release[1]),
|
||||
.io_en(1'b1),
|
||||
.rd(RD[1]),
|
||||
.wr(WR[1]),
|
||||
|
||||
+68
-30
@@ -1,3 +1,5 @@
|
||||
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
||||
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
||||
//
|
||||
// sdram
|
||||
// Copyright (c) 2015-2019 Sorgelig
|
||||
@@ -81,10 +83,14 @@ localparam OP_MODE = 2'b00; // only 00 (standard operation) allow
|
||||
localparam NO_WRITE_BURST = 1'b1; // 0= write burst enabled, 1=only single access write
|
||||
localparam MODE = {3'b000, NO_WRITE_BURST, OP_MODE, CAS_LATENCY, ACCESS_TYPE, BURST_CODE};
|
||||
|
||||
localparam sdram_startup_cycles= 14'd12100;// 100us, plus a little more, @ 100MHz
|
||||
localparam startup_refresh_max = 14'b11111111111111;
|
||||
// AS4C32M16SB requires 200 us with stable inputs before initialization.
|
||||
// 25,000 cycles at 114.545454 MHz leaves >218 us, including command spacing.
|
||||
localparam sdram_startup_cycles= 15'd25000;
|
||||
localparam startup_refresh_max = 15'h7fff;
|
||||
//localparam cycles_per_refresh = 14'd780; // (64000*100)/8192-1 Calc'd as (64ms @ 100MHz)/8192 rose
|
||||
localparam cycles_per_refresh = 14'd890; // (64000*100)/8192-1 Calc'd as (64ms @ 114.560MHz)/8192 rose (act 895)
|
||||
// Reserve the bounded command/recovery latency before the 894.9-cycle limit
|
||||
// (64 ms / 8192 at 114.545454 MHz). Do not wait for twice this interval.
|
||||
localparam cycles_per_refresh = 14'd880;
|
||||
|
||||
// SDRAM commands
|
||||
wire [2:0] CMD_NOP = 3'b111;
|
||||
@@ -95,7 +101,7 @@ wire [2:0] CMD_PRECHARGE = 3'b010;
|
||||
wire [2:0] CMD_AUTO_REFRESH = 3'b001;
|
||||
wire [2:0] CMD_LOAD_MODE = 3'b000;
|
||||
|
||||
reg [13:0] refresh_count = startup_refresh_max - sdram_startup_cycles;
|
||||
reg [14:0] refresh_count = startup_refresh_max - sdram_startup_cycles;
|
||||
reg [2:0] command;
|
||||
|
||||
localparam STATE_STARTUP = 0;
|
||||
@@ -105,6 +111,7 @@ localparam STATE_RW1 = 3;
|
||||
localparam STATE_IDLE = 4;
|
||||
localparam STATE_DLY1 = 5;
|
||||
localparam STATE_DLY2 = 6;
|
||||
localparam STATE_DLY3 = 20;
|
||||
localparam STATE_IDLE_7 = 17;
|
||||
localparam STATE_IDLE_6 = 16;
|
||||
localparam STATE_IDLE_5 = 15;
|
||||
@@ -114,10 +121,32 @@ localparam STATE_IDLE_2 = 12;
|
||||
localparam STATE_IDLE_1 = 11;
|
||||
|
||||
reg [15:0] dq_reg;
|
||||
// CL3's output launches on the preceding edge (READ T4 -> launch T6,
|
||||
// receive T7). Preserve the original READY alignment: adding another cycle
|
||||
// selects burst beat two. Pin setup/hold remains checked in external-io.sdc.
|
||||
localparam READ_CAPTURE_EXTRA = 0;
|
||||
|
||||
// Research: CPU-only activation stage. Request arbitration controls state,
|
||||
// while payload snapshots isolate the external bus from the output mux tree.
|
||||
reg [24:0] cpu_address_snapshot;
|
||||
reg [7:0] cpu_data_snapshot;
|
||||
reg cpu_rnw_snapshot;
|
||||
localparam STATE_CPU_ACTIVE = 18;
|
||||
// Research: keep video address arithmetic out of the SDRAM output mux.
|
||||
// The next state consumes the snapshot from the arbitration edge, adding one
|
||||
// fast clock before ACTIVE. No address/command is issued from an invalid sample.
|
||||
reg [24:0] video_address_snapshot;
|
||||
localparam STATE_VIDEO_ACTIVE = 19;
|
||||
always @(posedge clk) video_address_snapshot <= sdram_vid_addr;
|
||||
always @(posedge clk) begin
|
||||
cpu_address_snapshot <= sdram_cpu_addr;
|
||||
cpu_data_snapshot <= sdram_cpu_din;
|
||||
cpu_rnw_snapshot <= sdram_cpu_rnw;
|
||||
end
|
||||
|
||||
always @(posedge clk) begin
|
||||
reg [CAS_LATENCY+BURST_LENGTH:0] data_cpu_ready_delay;
|
||||
reg [CAS_LATENCY+BURST_LENGTH:0] data_vid_ready_delay;
|
||||
reg [CAS_LATENCY+BURST_LENGTH+READ_CAPTURE_EXTRA:0] data_cpu_ready_delay;
|
||||
reg [CAS_LATENCY+BURST_LENGTH+READ_CAPTURE_EXTRA:0] data_vid_ready_delay;
|
||||
|
||||
reg saved_wr;
|
||||
reg saved_vid;
|
||||
@@ -127,9 +156,9 @@ always @(posedge clk) begin
|
||||
|
||||
refresh_count <= refresh_count + 1'b1;
|
||||
|
||||
data_vid_ready_delay[CAS_LATENCY+BURST_LENGTH] <= 0;
|
||||
data_vid_ready_delay[CAS_LATENCY+BURST_LENGTH+READ_CAPTURE_EXTRA] <= 0;
|
||||
|
||||
data_cpu_ready_delay[CAS_LATENCY+BURST_LENGTH] <= 0;
|
||||
data_cpu_ready_delay[CAS_LATENCY+BURST_LENGTH+READ_CAPTURE_EXTRA] <= 0;
|
||||
|
||||
data_cpu_ready_delay <= data_cpu_ready_delay>>1;
|
||||
data_vid_ready_delay <= data_vid_ready_delay>>1;
|
||||
@@ -206,7 +235,7 @@ always @(posedge clk) begin
|
||||
state <= STATE_IDLE;
|
||||
sdram_busy <= 1'b0;
|
||||
// mask possible refresh to reduce colliding.
|
||||
if(refresh_count > cycles_per_refresh) begin
|
||||
if(refresh_count >= cycles_per_refresh) begin
|
||||
state <= STATE_IDLE_7;
|
||||
command <= CMD_AUTO_REFRESH;
|
||||
refresh_count <= 0;
|
||||
@@ -216,47 +245,53 @@ always @(posedge clk) begin
|
||||
|
||||
STATE_IDLE: begin
|
||||
saved_vid <= 1'b0;
|
||||
if(refresh_count > (cycles_per_refresh<<1))
|
||||
if(refresh_count >= cycles_per_refresh)
|
||||
begin
|
||||
state <= STATE_IDLE_1;
|
||||
sdram_busy <= 1'b1;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if(sdram_cpu_req & !sdram_cpu_ack) // request has to go away after ready=0
|
||||
begin
|
||||
// fix byte writes [no new command until data is actually written]
|
||||
if (~sdram_cpu_rnw)
|
||||
{cas_addr[12:9],SDRAM_BA,SDRAM_A,cas_addr[8:0]} <= {~sdram_cpu_addr[0], sdram_cpu_addr[0], 2'b10, sdram_cpu_addr[24:1]}; // Bytes by A0 for writes
|
||||
else
|
||||
{cas_addr[12:9],SDRAM_BA,SDRAM_A,cas_addr[8:0]} <= {2'b00, 2'b10, sdram_cpu_addr[24:1]}; // No bytes for reads...
|
||||
|
||||
saved_data <= {sdram_cpu_din, sdram_cpu_din};
|
||||
saved_wr <= ~sdram_cpu_rnw;
|
||||
command <= CMD_ACTIVE;
|
||||
state <= STATE_WAIT;
|
||||
sdram_busy <= 1'b1;
|
||||
end
|
||||
if(sdram_cpu_req & !sdram_cpu_ack)
|
||||
begin
|
||||
state <= STATE_CPU_ACTIVE;
|
||||
sdram_busy <= 1'b1;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if (sdram_vid_req)
|
||||
begin
|
||||
{cas_addr[12:9],SDRAM_BA,SDRAM_A,cas_addr[8:0]} <= {2'b00, 2'b10, sdram_vid_addr[24:1]}; // No bytes for reads...
|
||||
command <= CMD_ACTIVE;
|
||||
state <= STATE_VIDEO_ACTIVE;
|
||||
saved_vid <= 1'b1;
|
||||
saved_wr <= 1'b0;
|
||||
sdram_busy <= 1'b1;
|
||||
state <= STATE_WAIT;
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
STATE_VIDEO_ACTIVE: begin
|
||||
{cas_addr[12:9],SDRAM_BA,SDRAM_A,cas_addr[8:0]} <= {2'b00, 2'b10, video_address_snapshot[24:1]};
|
||||
command <= CMD_ACTIVE;
|
||||
state <= STATE_WAIT;
|
||||
end
|
||||
|
||||
STATE_CPU_ACTIVE: begin
|
||||
if (~cpu_rnw_snapshot)
|
||||
{cas_addr[12:9],SDRAM_BA,SDRAM_A,cas_addr[8:0]} <= {~cpu_address_snapshot[0], cpu_address_snapshot[0], 2'b10, cpu_address_snapshot[24:1]};
|
||||
else
|
||||
{cas_addr[12:9],SDRAM_BA,SDRAM_A,cas_addr[8:0]} <= {2'b00, 2'b10, cpu_address_snapshot[24:1]};
|
||||
saved_data <= {cpu_data_snapshot, cpu_data_snapshot};
|
||||
saved_wr <= ~cpu_rnw_snapshot;
|
||||
command <= CMD_ACTIVE;
|
||||
state <= STATE_WAIT;
|
||||
end
|
||||
|
||||
STATE_WAIT: state <= STATE_WAIT1;
|
||||
STATE_WAIT1: begin
|
||||
if (saved_wr)
|
||||
begin
|
||||
if ((data_vid_ready_delay[5:1] == 5'b00000) && (data_cpu_ready_delay[5:1] == 5'b00000))
|
||||
if ((data_vid_ready_delay[CAS_LATENCY+BURST_LENGTH+READ_CAPTURE_EXTRA:1] == '0) && (data_cpu_ready_delay[CAS_LATENCY+BURST_LENGTH+READ_CAPTURE_EXTRA:1] == '0))
|
||||
state <= STATE_RW1; // added for clk > 100Mhz
|
||||
end
|
||||
else
|
||||
@@ -283,17 +318,20 @@ always @(posedge clk) begin
|
||||
state <= STATE_IDLE;
|
||||
if (saved_vid)
|
||||
begin
|
||||
data_vid_ready_delay[CAS_LATENCY+BURST_LENGTH] <= 1;
|
||||
data_vid_ready_delay[CAS_LATENCY+BURST_LENGTH+READ_CAPTURE_EXTRA] <= 1;
|
||||
state <= STATE_DLY1;
|
||||
end
|
||||
else
|
||||
data_cpu_ready_delay[CAS_LATENCY+BURST_LENGTH] <= 1;
|
||||
data_cpu_ready_delay[CAS_LATENCY+BURST_LENGTH+READ_CAPTURE_EXTRA] <= 1;
|
||||
state <= STATE_DLY1;
|
||||
end
|
||||
end
|
||||
STATE_DLY1:
|
||||
state <= STATE_DLY2;
|
||||
STATE_DLY2:
|
||||
state <= STATE_DLY3;
|
||||
STATE_DLY3:
|
||||
// Eight clocks between legal back-to-back ACTIVEs, >=63 ns tRC.
|
||||
state <= STATE_IDLE;
|
||||
endcase
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
SSC wiring and SP0256/TMS7000 portions are derived from MAME:
|
||||
Copyright holders: Tim Lindner, Joseph Zbiciak, hap.
|
||||
See the individual source headers for component provenance.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holder nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,91 @@
|
||||
// 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
|
||||
// Cartridge mix and digital SAC model, based on VCCPlus/MAME Tim Lindner.
|
||||
// audio_ce must be44100Hz: the reference RC coefficients are per audio sample.
|
||||
// Q16 PCM states and Q24 coefficients approximate the software float circuit.
|
||||
// This is a digital reference model, not a measured analog transfer function.
|
||||
module ssc_audio(input wire clk,reset,audio_ce,input wire [17:0] ay_sum,
|
||||
input wire signed [15:0] speech_sample,output reg signed [15:0] mixed_sample,
|
||||
output reg sample_valid,activity,overrun,output wire busy);
|
||||
localparam [3:0] IDLE=0,MIX=1,HP_PREP=2,HP_MULT=3,HP_STORE=4,
|
||||
ENV_PREP=5,ENV_MULT=6,ENV_STORE=7,AVERAGE=8,MULT_COMBINE=9;
|
||||
reg [3:0] state;
|
||||
assign busy=state!=IDLE;
|
||||
reg [15:0] ay_average;
|
||||
reg [17:0] divide_shift,quotient;
|
||||
reg [1:0] remainder;
|
||||
reg [4:0] divide_count;
|
||||
wire [2:0] division_step={remainder,divide_shift[17]};
|
||||
wire [2:0] next_remainder=division_step>=3 ? division_step-3'd3 : division_step;
|
||||
reg signed [15:0] speech_hold;
|
||||
reg signed [20:0] mix_quarters;
|
||||
reg signed [34:0] previous_input,previous_hp,rectified,operand;
|
||||
reg [34:0] envelope;
|
||||
reg [23:0] factor;
|
||||
reg signed [59:0] product;
|
||||
reg [41:0] product_low;
|
||||
reg signed [41:0] product_high;
|
||||
reg [3:0] combine_return;
|
||||
wire signed [41:0] combined_high=product_high+$signed({18'd0,product_low[41:18]});
|
||||
wire signed [39:0] scaled_product=product>>>24;
|
||||
wire signed [39:0] envelope_next=$signed({1'b0,envelope})+scaled_product;
|
||||
wire signed [34:0] current_input=$signed({3'd0,ay_average,16'd0});
|
||||
wire signed [20:0] speech_extended={{5{speech_hold[15]}},speech_hold};
|
||||
always @(posedge clk)begin
|
||||
if(reset)begin
|
||||
state<=IDLE;ay_average<=0;speech_hold<=0;mix_quarters<=0;
|
||||
divide_shift<=0;quotient<=0;remainder<=0;divide_count<=0;
|
||||
previous_input<=0;previous_hp<=0;rectified<=0;operand<=0;envelope<=0;
|
||||
factor<=0;product<=0;product_low<=0;product_high<=0;combine_return<=IDLE;
|
||||
mixed_sample<=0;sample_valid<=0;activity<=0;overrun<=0;
|
||||
end else begin
|
||||
sample_valid<=0;
|
||||
if(audio_ce&&busy)overrun<=1;
|
||||
case(state)
|
||||
IDLE:if(audio_ce)begin
|
||||
divide_shift<=ay_sum;quotient<=0;remainder<=0;divide_count<=18;
|
||||
speech_hold<=speech_sample;state<=AVERAGE;
|
||||
end
|
||||
AVERAGE:begin
|
||||
remainder<=next_remainder[1:0];
|
||||
quotient<={quotient[16:0],division_step>=3};divide_shift<=divide_shift<<1;
|
||||
divide_count<=divide_count-5'd1;
|
||||
if(divide_count==1)begin ay_average<={quotient[14:0],division_step>=3};state<=MIX;end
|
||||
end
|
||||
MIX:begin
|
||||
mix_quarters<=$signed({2'd0,ay_average,3'd0})+(speech_extended<<<3)-speech_extended;
|
||||
state<=HP_PREP;
|
||||
end
|
||||
HP_PREP:begin
|
||||
operand<=previous_hp+current_input-previous_input;factor<=24'd16609444;
|
||||
state<=HP_MULT;
|
||||
end
|
||||
HP_MULT,ENV_MULT:begin
|
||||
product_low<=operand[17:0]*factor;
|
||||
product_high<=$signed(operand[34:18])*$signed({1'b0,factor});
|
||||
combine_return<=state==HP_MULT?HP_STORE:ENV_STORE;state<=MULT_COMBINE;
|
||||
end
|
||||
MULT_COMBINE:begin product<={combined_high,product_low[17:0]};state<=combine_return;end
|
||||
HP_STORE:begin
|
||||
previous_input<=current_input;previous_hp<=scaled_product[34:0];
|
||||
rectified<=scaled_product[39]?-scaled_product[34:0]:scaled_product[34:0];state<=ENV_PREP;
|
||||
end
|
||||
ENV_PREP:begin
|
||||
operand<=rectified-$signed(envelope);
|
||||
factor<=rectified>$signed(envelope)?24'd43621:24'd5033;state<=ENV_MULT;
|
||||
end
|
||||
ENV_STORE:begin
|
||||
envelope<=envelope_next[34:0];
|
||||
if(activity&&envelope_next<40'sd21474836)activity<=0;
|
||||
else if(!activity&&envelope_next>40'sd107374182)activity<=1;
|
||||
if(mix_quarters>21'sd131068)mixed_sample<=16'sd32767;
|
||||
else if(mix_quarters< -21'sd131072)mixed_sample<=16'sh8000;
|
||||
else mixed_sample<=mix_quarters[17:2];
|
||||
sample_valid<=1;state<=IDLE;
|
||||
end
|
||||
default:state<=IDLE;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,106 @@
|
||||
// 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
|
||||
// AY-3-8913 behavioral hardware port for Coco 3 Plus.
|
||||
// Reference: VCCPlus a8a84f22 src/devices/ssc/ay8913.{h,cpp}; see LICENSE.
|
||||
// The reference volume table is a logarithmic approximation, not silicon data.
|
||||
// clock_enable pulses once per AY INPUT clock; internal generators divide by 8.
|
||||
// Same-edge register writes follow generator advancement using old registers.
|
||||
// sample_sum is the unnormalized three-channel sum, with two pipeline stages.
|
||||
// The future SSC mixer applies /3 normalization, gain, filtering and routing.
|
||||
module ssc_ay8913(
|
||||
input wire clk,reset,clock_enable,
|
||||
input wire reg_select,reg_write,
|
||||
input wire [7:0] bus_data,
|
||||
output wire [7:0] read_data,
|
||||
output reg [17:0] sample_sum
|
||||
);
|
||||
reg [7:0] registers[0:15];
|
||||
reg [3:0] selected;
|
||||
reg [2:0] divider;
|
||||
reg [11:0] tone_counter[0:2];
|
||||
reg [2:0] tone_output;
|
||||
reg [4:0] noise_counter;
|
||||
reg [16:0] noise_lfsr;
|
||||
reg [15:0] env_counter;
|
||||
reg [5:0] env_step;
|
||||
reg env_up,env_holding;
|
||||
reg [15:0] level[0:2];
|
||||
wire [11:0] tone_period[0:2];
|
||||
wire [4:0] noise_period=registers[6][4:0];
|
||||
wire [15:0] env_period={registers[12],registers[11]};
|
||||
wire [4:0] env_position=env_up?env_step[4:0]:~env_step[4:0];
|
||||
wire [3:0] env_level=(!registers[13][3] && env_holding)?4'd0:env_position[4:1];
|
||||
assign read_data=registers[selected];
|
||||
|
||||
function [15:0] volume(input [3:0] index);
|
||||
begin
|
||||
case(index)
|
||||
0:volume=0;1:volume=1304;2:volume=1642;3:volume=2067;
|
||||
4:volume=2603;5:volume=3277;6:volume=4125;7:volume=5193;
|
||||
8:volume=6538;9:volume=8231;10:volume=10362;11:volume=13045;
|
||||
12:volume=16422;13:volume=20675;14:volume=26028;15:volume=32767;
|
||||
endcase
|
||||
end
|
||||
endfunction
|
||||
genvar ch;
|
||||
generate for(ch=0;ch<3;ch=ch+1) begin:channels
|
||||
assign tone_period[ch]={registers[ch*2+1][3:0],registers[ch*2]};
|
||||
wire gate=(registers[7][ch] || tone_output[ch]) &&
|
||||
(registers[7][ch+3] || noise_lfsr[0]);
|
||||
wire [3:0] amplitude=registers[ch+8][4]?env_level:registers[ch+8][3:0];
|
||||
always @(posedge clk) begin
|
||||
if(reset) level[ch]<=0;
|
||||
else level[ch]<=gate?volume(amplitude):16'd0;
|
||||
end
|
||||
end endgenerate
|
||||
integer i;
|
||||
always @(posedge clk) begin
|
||||
if(reset) begin
|
||||
selected<=0;divider<=0;tone_output<=3'b111;
|
||||
noise_counter<=0;noise_lfsr<=17'd1;
|
||||
env_counter<=0;env_step<=0;env_up<=1;env_holding<=0;
|
||||
sample_sum<=0;
|
||||
for(i=0;i<16;i=i+1) registers[i]<=0;
|
||||
for(i=0;i<3;i=i+1) tone_counter[i]<=0;
|
||||
end else begin
|
||||
sample_sum<={2'b0,level[0]}+{2'b0,level[1]}+{2'b0,level[2]};
|
||||
if(clock_enable) begin
|
||||
divider<=divider+1'b1;
|
||||
if(divider==3'd7) begin
|
||||
for(i=0;i<3;i=i+1) begin
|
||||
if(tone_counter[i]>=(tone_period[i]==0?12'd0:tone_period[i]-12'd1)) begin
|
||||
tone_counter[i]<=0;tone_output[i]<=!tone_output[i];
|
||||
end else tone_counter[i]<=tone_counter[i]+1'b1;
|
||||
end
|
||||
if(noise_counter>=(noise_period==0?5'd0:noise_period-5'd1)) begin
|
||||
noise_counter<=0;
|
||||
noise_lfsr<={noise_lfsr[0]^noise_lfsr[3],noise_lfsr[16:1]};
|
||||
end else noise_counter<=noise_counter+1'b1;
|
||||
if(env_counter>=(env_period==0?16'd0:env_period-16'd1)) begin
|
||||
env_counter<=0;
|
||||
if(!env_holding) begin
|
||||
if(env_step==6'd31) begin
|
||||
if(!registers[13][3]) begin env_step<=32;env_holding<=1;end
|
||||
else if(registers[13][0]) begin
|
||||
env_step<=31;env_holding<=1;
|
||||
if(registers[13][1]) env_up<=!env_up;
|
||||
end else begin
|
||||
env_step<=0;
|
||||
if(registers[13][1]) env_up<=!env_up;
|
||||
end
|
||||
end else env_step<=env_step+1'b1;
|
||||
end
|
||||
end else env_counter<=env_counter+1'b1;
|
||||
end
|
||||
end
|
||||
if(reg_select) selected<=bus_data[3:0];
|
||||
if(reg_write) begin
|
||||
registers[selected]<=bus_data;
|
||||
if(selected==4'd13) begin
|
||||
env_step<=0;env_holding<=0;env_up<=bus_data[2];
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,74 @@
|
||||
// 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
|
||||
// Shared digital SSC cartridge; clocks use enables, never generated fabric clocks.
|
||||
// reset is FPGA power/reconfiguration reset (clears volatile ROM loader state).
|
||||
// cartridge_reset restarts chips while retaining loaded ROMs and glue SRAM.
|
||||
module ssc_cartridge #(parameter integer CLOCK_HZ=114545408)(
|
||||
input wire clk,reset,cartridge_reset,enable,host_read,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,output wire [7:0] status,
|
||||
input wire pic_rom_begin,pic_rom_write,input wire [11:0] pic_rom_address,input wire [7:0] pic_rom_data,
|
||||
input wire speech_rom_begin,speech_rom_write,input wire [10:0] speech_rom_address,input wire [7:0] speech_rom_data,
|
||||
output wire pic_loaded,speech_loaded,operational,fault,
|
||||
output wire signed [15:0] audio_sample,output wire audio_valid,
|
||||
output wire speech_standby,sound_activity,output wire [15:0] debug_pc);
|
||||
reg [31:0] ay_phase,speech_phase,audio_phase;
|
||||
reg ay_ce,phi_ce,speech_ce,audio_ce,phi_half;
|
||||
wire [32:0] ay_next={1'b0,ay_phase}+33'd1789772;
|
||||
wire [32:0] speech_next={1'b0,speech_phase}+33'd10000;
|
||||
wire [32:0] audio_next={1'b0,audio_phase}+33'd44100;
|
||||
wire [32:0] ay_wrapped=ay_next>=CLOCK_HZ?ay_next-CLOCK_HZ:ay_next;
|
||||
wire [32:0] speech_wrapped=speech_next>=CLOCK_HZ?speech_next-CLOCK_HZ:speech_next;
|
||||
wire [32:0] audio_wrapped=audio_next>=CLOCK_HZ?audio_next-CLOCK_HZ:audio_next;
|
||||
always @(posedge clk)begin
|
||||
if(reset)begin
|
||||
ay_phase<=0;speech_phase<=0;audio_phase<=0;ay_ce<=0;phi_ce<=0;speech_ce<=0;audio_ce<=0;phi_half<=0;
|
||||
end else begin
|
||||
ay_ce<=ay_next>=CLOCK_HZ;phi_ce<=0;speech_ce<=speech_next>=CLOCK_HZ;audio_ce<=audio_next>=CLOCK_HZ;
|
||||
ay_phase<=ay_wrapped[31:0];speech_phase<=speech_wrapped[31:0];audio_phase<=audio_wrapped[31:0];
|
||||
if(ay_next>=CLOCK_HZ)begin phi_half<=!phi_half;phi_ce<=phi_half;end
|
||||
end
|
||||
end
|
||||
wire pic_error,speech_error,pic_initialized,glue_initialized;
|
||||
wire pic_overrun,speech_overrun,speech_fault,audio_overrun;
|
||||
wire [31:0] illegal;
|
||||
wire [7:0] command,host_result;
|
||||
wire ignored_valid,command_read,busy_line,command_irq,command_busy,controller_reset,speech_reset;
|
||||
wire gpio_request,gpio_write,gpio_ready;
|
||||
wire [1:0] gpio_port;
|
||||
wire [7:0] gpio_write_data,gpio_read_data,ay_bus,ay_read_data;
|
||||
wire ay_select,ay_write,ald,speech_ready;
|
||||
wire [5:0] allophone;
|
||||
wire [17:0] ay_sum;
|
||||
wire signed [15:0] speech_sample;
|
||||
wire speech_valid,speech_busy,audio_busy;
|
||||
wire [18:0] speech_pc;
|
||||
wire [31:0] speech_frames;
|
||||
wire rom_ready=pic_loaded&&speech_loaded;
|
||||
assign fault=pic_error||speech_error||pic_overrun||speech_overrun||speech_fault||audio_overrun||(|illegal);
|
||||
assign operational=rom_ready&&pic_initialized&&glue_initialized&&!fault;
|
||||
// Address-independent status lets the wrapper sample at the CPU clock edge
|
||||
// without feeding live CPU address/control back through the cartridge.
|
||||
assign status=operational ? {!command_busy,speech_standby,!sound_activity,5'b11111} : 8'h7f;
|
||||
assign host_read_valid=enable&&host_read&&(host_address==16'hff7d||host_address==16'hff7e);
|
||||
assign host_read_data=!host_read_valid ? 8'd0 : host_address==16'hff7d ? 8'hff : operational ? host_result : 8'h7f;
|
||||
ssc_host host(clk,reset||!rom_ready,enable&&operational,host_read,host_write,host_address,host_data,
|
||||
ignored_valid,host_result,command_read,busy_line,command,command_irq,command_busy,
|
||||
speech_standby,sound_activity,controller_reset,speech_reset);
|
||||
ssc_tms7000 controller(.clk(clk),.reset(reset),.controller_reset(controller_reset||cartridge_reset),
|
||||
.icount_tick(phi_ce),.rom_begin(pic_rom_begin),.rom_write(pic_rom_write),.rom_address(pic_rom_address),.rom_data(pic_rom_data),
|
||||
.rom_loaded(pic_loaded),.load_error(pic_error),.initialized(pic_initialized),.overrun(pic_overrun),
|
||||
.debug_pc(debug_pc),.illegal_count(illegal),.irq1(speech_ready),.irq3(command_irq),.timer_external(command[7]),
|
||||
.gpio_request(gpio_request),.gpio_write(gpio_write),.gpio_port(gpio_port),.gpio_write_data(gpio_write_data),
|
||||
.gpio_ready(gpio_ready),.gpio_read_data(gpio_read_data));
|
||||
ssc_glue glue(clk,reset,gpio_request,gpio_write,gpio_port,gpio_write_data,gpio_ready,gpio_read_data,
|
||||
glue_initialized,command,command_read,busy_line,ay_select,ay_write,ay_bus,ay_read_data,ald,allophone);
|
||||
ssc_ay8913 ay(clk,reset||controller_reset||cartridge_reset,ay_ce,ay_select,ay_write,ay_bus,ay_read_data,ay_sum);
|
||||
ssc_sp0256 speech(.clk(clk),.reset(reset),.speech_reset(speech_reset||cartridge_reset),.sample_ce(speech_ce),
|
||||
.ald(ald),.allophone(allophone),.rom_begin(speech_rom_begin),.rom_write(speech_rom_write),
|
||||
.rom_address(speech_rom_address),.rom_data(speech_rom_data),.rom_loaded(speech_loaded),.load_error(speech_error),
|
||||
.data_request(speech_ready),.standby(speech_standby),.sample(speech_sample),.sample_valid(speech_valid),
|
||||
.busy(speech_busy),.overrun(speech_overrun),.fault(speech_fault),.debug_pc(speech_pc),.frame_count(speech_frames));
|
||||
ssc_audio audio(clk,reset,audio_ce,ay_sum,speech_sample,audio_sample,audio_valid,sound_activity,audio_overrun,audio_busy);
|
||||
endmodule
|
||||
@@ -0,0 +1,135 @@
|
||||
// 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: PIC7040 external ports and 2 KiB SRAM.
|
||||
// Behavioral reference: VCCPlus a8a84f22 src/devices/ssc/ssc_core.cpp;
|
||||
// MAME CoCo SSC wiring copyright Tim Lindner. Original notices: LICENSE.
|
||||
// Chip execution/audio is external to this block. All signals use clk.
|
||||
// Hold request/payload until io_ready, then withdraw request before another
|
||||
// access. Chip strobes occur once even if a completed request remains asserted.
|
||||
module ssc_glue (
|
||||
input wire clk, reset,
|
||||
input wire io_request, io_write,
|
||||
input wire [1:0] io_port, // A=0, B=1, C=2, D=3; GPIO values after PIC DDR
|
||||
input wire [7:0] io_write_data,
|
||||
output reg io_ready,
|
||||
output reg [7:0] io_read_data,
|
||||
output reg init_done,
|
||||
input wire [7:0] command_data,
|
||||
output reg command_read,
|
||||
output wire pic_busy_line,
|
||||
output reg ay_select, ay_write,
|
||||
output reg [7:0] ay_bus_data,
|
||||
input wire [7:0] ay_read_data,
|
||||
output reg speech_ald,
|
||||
output reg [5:0] speech_code
|
||||
);
|
||||
localparam [1:0] INITIALIZE=0, IDLE=1, EXECUTE=2, WAIT_RELEASE=3;
|
||||
reg [1:0] state;
|
||||
reg [10:0] clear_address;
|
||||
reg access_write;
|
||||
reg [1:0] access_port;
|
||||
reg [7:0] access_data;
|
||||
reg [7:0] port_b, port_c, port_d;
|
||||
reg [7:0] ram [0:2047];
|
||||
reg [7:0] ram_read;
|
||||
wire ram_clear = state == INITIALIZE;
|
||||
wire ram_store = state == EXECUTE && access_write && access_port == 2 &&
|
||||
!access_data[4] && !access_data[3];
|
||||
wire [10:0] ram_write_address = ram_clear ? clear_address : {access_data[2:0],port_b};
|
||||
wire [7:0] ram_write_data = ram_clear ? 8'h00 : port_d;
|
||||
wire ram_selected = !port_c[4] && port_c[3];
|
||||
wire ay_selected_read = !port_c[6] && !port_c[3] && port_c[0];
|
||||
// AY read overrides SRAM if both devices are selected, matching the reference.
|
||||
wire [7:0] read_d = ay_selected_read ? ay_read_data : ram_selected ? ram_read : port_d;
|
||||
assign pic_busy_line = port_c[7];
|
||||
|
||||
// Synchronous read/write inference, with a hardware scrub instead of resetting
|
||||
// every memory element. Keep the future PIC in reset until init_done.
|
||||
always @(posedge clk) begin
|
||||
ram_read <= ram[{port_c[2:0],port_b}];
|
||||
if (!reset && (ram_clear || ram_store))
|
||||
ram[ram_write_address] <= ram_write_data;
|
||||
end
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (reset) begin
|
||||
state <= INITIALIZE;
|
||||
clear_address <= 0;
|
||||
init_done <= 0;
|
||||
io_ready <= 0;
|
||||
io_read_data <= 0;
|
||||
command_read <= 0;
|
||||
ay_select <= 0;
|
||||
ay_write <= 0;
|
||||
ay_bus_data <= 0;
|
||||
speech_ald <= 0;
|
||||
speech_code <= 0;
|
||||
access_write <= 0;
|
||||
access_port <= 0;
|
||||
access_data <= 0;
|
||||
// Observable state after SscCore::Reset and the PIC's reset callbacks.
|
||||
port_b <= 8'hFF;
|
||||
port_c <= 8'h00;
|
||||
port_d <= 8'h00;
|
||||
end else begin
|
||||
command_read <= 0;
|
||||
ay_select <= 0;
|
||||
ay_write <= 0;
|
||||
speech_ald <= 0;
|
||||
case (state)
|
||||
INITIALIZE: begin
|
||||
if (clear_address == 11'd2047) begin
|
||||
init_done <= 1;
|
||||
state <= IDLE;
|
||||
end else clear_address <= clear_address + 1'b1;
|
||||
end
|
||||
IDLE: if (io_request) begin
|
||||
access_write <= io_write;
|
||||
access_port <= io_port;
|
||||
access_data <= io_write_data;
|
||||
state <= EXECUTE;
|
||||
end
|
||||
EXECUTE: begin
|
||||
if (access_write) begin
|
||||
case (access_port)
|
||||
1: port_b <= access_data;
|
||||
2: begin
|
||||
port_c <= access_data;
|
||||
if (!access_data[6] && access_data[3]) begin
|
||||
ay_bus_data <= port_d;
|
||||
ay_select <= access_data[0];
|
||||
ay_write <= !access_data[0];
|
||||
end
|
||||
if (port_c[5] && !access_data[5] && port_d < 8'd64) begin
|
||||
speech_ald <= 1;
|
||||
speech_code <= port_d[5:0];
|
||||
end
|
||||
end
|
||||
3: port_d <= access_data;
|
||||
endcase
|
||||
end else begin
|
||||
case (access_port)
|
||||
0: begin
|
||||
io_read_data <= command_data;
|
||||
command_read <= 1;
|
||||
end
|
||||
1: io_read_data <= port_b;
|
||||
2: io_read_data <= port_c;
|
||||
3: begin
|
||||
io_read_data <= read_d;
|
||||
port_d <= read_d;
|
||||
end
|
||||
endcase
|
||||
end
|
||||
io_ready <= 1;
|
||||
state <= WAIT_RELEASE;
|
||||
end
|
||||
WAIT_RELEASE: if (!io_request) begin
|
||||
io_ready <= 0;
|
||||
state <= IDLE;
|
||||
end
|
||||
endcase
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,84 @@
|
||||
// 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
|
||||
@@ -0,0 +1,109 @@
|
||||
// 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
|
||||
// MiSTer HPS file/bus/audio integration. Same57MHz domain; CPU commits on the
|
||||
// negative edge, cartridge logic on the positive edge. Both half paths are timed.
|
||||
module ssc_mister_bridge(input wire clk,reset,cpu_reset,mode,
|
||||
input wire cpu_commit,cpu_rnw,input wire [15:0] cpu_address,input wire [7:0] cpu_data,
|
||||
input wire ioctl_download,ioctl_wr,input wire [7:0] ioctl_index,
|
||||
input wire [24:0] ioctl_address,input wire [7:0] ioctl_data,
|
||||
input wire cartridge_operational,cartridge_fault,
|
||||
input wire [7:0] cartridge_read_data,input wire signed [15:0] cartridge_audio,
|
||||
input wire sound_enable,input wire [1:0] sound_select,
|
||||
input wire [7:0] orchestra_left,orchestra_right,input wire [15:0] legacy_left,legacy_right,
|
||||
output wire cartridge_reset,host_read,host_write,output wire [15:0] host_address,
|
||||
output wire [7:0] host_data,output wire read_valid,output wire [7:0] read_data,
|
||||
output wire palette_owner,rom_files_valid,load_fault,
|
||||
output wire pic_begin,pic_write,output wire [11:0] pic_address,output wire [7:0] pic_data,
|
||||
output wire speech_begin,speech_write,output wire [10:0] speech_address,output wire [7:0] speech_data,
|
||||
output wire [15:0] audio_left,audio_right);
|
||||
reg download_d,mode_d;
|
||||
reg [5:0] file_kind;
|
||||
reg [12:0] count;
|
||||
reg malformed,pic_valid,speech_valid,pic_bad,speech_bad;
|
||||
reg pipe_write;
|
||||
reg [5:0] pipe_kind;
|
||||
reg [24:0] pipe_address;
|
||||
reg [7:0] pipe_data;
|
||||
wire selected=ioctl_index[5:0]==4||ioctl_index[5:0]==5;
|
||||
wire start=ioctl_download&&!download_d&&selected;
|
||||
wire finish=!ioctl_download&&download_d;
|
||||
wire transferring=ioctl_download&&(selected||file_kind==4||file_kind==5);
|
||||
wire valid_length=(file_kind==4&&count==4096)||(file_kind==5&&count==2048);
|
||||
assign pic_begin=start&&ioctl_index[5:0]==4;
|
||||
assign speech_begin=start&&ioctl_index[5:0]==5;
|
||||
assign pic_write=pipe_write&&pipe_kind==4;
|
||||
assign speech_write=pipe_write&&pipe_kind==5;
|
||||
assign pic_address=pipe_address[11:0];assign speech_address=pipe_address[10:0];
|
||||
assign pic_data=pipe_data;assign speech_data=pipe_data;
|
||||
assign rom_files_valid=pic_valid&&speech_valid&&!transferring;
|
||||
assign load_fault=pic_bad||speech_bad||cartridge_fault;
|
||||
assign palette_owner=!mode;
|
||||
assign cartridge_reset=cpu_reset||transferring||(mode!=mode_d);
|
||||
always @(posedge clk)begin
|
||||
if(reset)begin
|
||||
download_d<=0;mode_d<=0;file_kind<=0;count<=0;malformed<=0;
|
||||
pic_valid<=0;speech_valid<=0;pic_bad<=0;speech_bad<=0;
|
||||
pipe_write<=0;pipe_kind<=0;pipe_address<=0;pipe_data<=0;
|
||||
end else begin
|
||||
download_d<=ioctl_download;mode_d<=mode;
|
||||
pipe_write<=ioctl_download&&ioctl_wr&&selected;
|
||||
pipe_kind<=ioctl_index[5:0];pipe_address<=ioctl_address;pipe_data<=ioctl_data;
|
||||
if(start)begin
|
||||
file_kind<=ioctl_index[5:0];count<=ioctl_wr?13'd1:13'd0;
|
||||
malformed<=ioctl_wr&&ioctl_address!=0;
|
||||
if(ioctl_index[5:0]==4)begin pic_valid<=0;pic_bad<=0;end
|
||||
else begin speech_valid<=0;speech_bad<=0;end
|
||||
end else if(ioctl_download&&ioctl_wr&&(file_kind==4||file_kind==5))begin
|
||||
if(ioctl_index[5:0]!=file_kind||ioctl_address!={12'd0,count})malformed<=1;
|
||||
if(count<4097)count<=count+13'd1;else malformed<=1;
|
||||
end
|
||||
if(finish)begin
|
||||
if(file_kind==4)begin pic_valid<=!malformed&&valid_length;pic_bad<=malformed||!valid_length;end
|
||||
else if(file_kind==5)begin speech_valid<=!malformed&&valid_length;speech_bad<=malformed||!valid_length;end
|
||||
file_kind<=0;
|
||||
end
|
||||
end
|
||||
end
|
||||
// Toggle handshake captures an old CPU bus at its real negative-edge commit.
|
||||
// It clears after the following positive-edge consume, leaving read data stable
|
||||
// before a possible back-to-back CPU read on the next negative edge.
|
||||
reg write_toggle=0,consumed_toggle=0;
|
||||
reg [15:0] write_address;
|
||||
reg [7:0] write_data;
|
||||
reg cpu_mode=0;
|
||||
reg [7:0] status_sample=8'h7f;
|
||||
wire write_pending=write_toggle!=consumed_toggle;
|
||||
always @(negedge clk)begin
|
||||
// CPU and this snapshot consume OLD values on the same negative edge.
|
||||
// The CPU therefore sees a full-cycle-stable status through its read mux;
|
||||
// this adds at most one57MHz tick of status visibility, no CPU wait state.
|
||||
cpu_mode<=mode;
|
||||
if(reset||cpu_reset||!rom_files_valid)status_sample<=8'h7f;
|
||||
else status_sample<=cartridge_read_data;
|
||||
if(reset||cpu_reset)begin write_toggle<=0;write_address<=0;write_data<=0;end
|
||||
else if(cpu_commit&&!cpu_rnw)begin
|
||||
write_address<=cpu_address;write_data<=cpu_data;write_toggle<=!write_toggle;
|
||||
end
|
||||
end
|
||||
always @(posedge clk)if(reset)consumed_toggle<=0;else consumed_toggle<=write_toggle;
|
||||
assign host_address=write_address;
|
||||
assign host_data=write_data;
|
||||
assign host_write=write_pending&&!cpu_reset&&rom_files_valid&&mode;
|
||||
assign host_read=1'b0;
|
||||
assign read_valid=cpu_mode&&cpu_rnw&&(cpu_address==16'hff7d||cpu_address==16'hff7e);
|
||||
assign read_data=!read_valid ? 8'd0 : cpu_address==16'hff7d ? 8'hff :
|
||||
status_sample;
|
||||
// In cartridge mux position replace the stale internal-DAC contribution.
|
||||
// Orchestra remains independent stereo. Its reset midpoint is128/0x8080.
|
||||
wire select_cartridge=mode&&sound_enable&&sound_select==2;
|
||||
wire signed [17:0] contribution=rom_files_valid&&cartridge_operational ?
|
||||
{{2{cartridge_audio[15]}},cartridge_audio} : 18'sd0;
|
||||
wire signed [17:0] sum_left=$signed({2'd0,orchestra_left,orchestra_left})-18'sd128+contribution;
|
||||
wire signed [17:0] sum_right=$signed({2'd0,orchestra_right,orchestra_right})-18'sd128+contribution;
|
||||
function [15:0] saturate(input signed [17:0] value);
|
||||
begin saturate=value<0 ? 16'd0 : value>18'sd65535 ? 16'hffff : value[15:0];end
|
||||
endfunction
|
||||
assign audio_left=select_cartridge?saturate(sum_left):legacy_left;
|
||||
assign audio_right=select_cartridge?saturate(sum_right):legacy_right;
|
||||
endmodule
|
||||
@@ -0,0 +1,242 @@
|
||||
// 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
|
||||
// SP0256-AL2 cartridge engine. Public microsequencer/LPC algorithm derived from
|
||||
// MAME Joseph Zbiciak, Tim Lindner, through pinned VCCPlus a8a84f22. See LICENSE.
|
||||
// No mask ROM embedded. AL2's on-chip 2 KiB occupies byte addresses1000..17ff;
|
||||
// unpopulated serial-ROM space reads zero. The cartridge has no host FIFO port.
|
||||
// sample_ce is native speech clock/312; clk must allow completion before next CE.
|
||||
module ssc_sp0256(input wire clk,reset,speech_reset,sample_ce,
|
||||
input wire ald,input wire [5:0] allophone,
|
||||
input wire rom_begin,rom_write,input wire [10:0] rom_address,input wire [7:0] rom_data,
|
||||
output wire rom_loaded,load_error,output reg data_request,standby,
|
||||
output reg signed [15:0] sample,output reg sample_valid,output wire busy,
|
||||
output reg overrun,fault,output wire [18:0] debug_pc,output reg [31:0] frame_count);
|
||||
`include "ssc_sp0256_tables.vh"
|
||||
localparam [5:0] IDLE=0,MICRO=1,IMM=2,OPCODE=3,BRANCH=4,
|
||||
CONTROL=5,FIELD_START=6,FIELD_APPLY=7,FIELD_NEXT=8,REGDEC=9,
|
||||
COEF_B=10,COEF_F=11,EXCITE=12,FILTER_MULT=13,FILTER_SUM=14,LIMIT=15,
|
||||
GET0=16,GET1=17,GET2=18,GET3=19,GET4=20,FILTER_PICK=21,COEF_DECODE=22,COEF_STORE=23;
|
||||
reg [5:0] state,return_state;
|
||||
reg [18:0] pc,stack,page;
|
||||
assign debug_pc=pc;
|
||||
assign busy=state!=IDLE;
|
||||
reg halted,pending,fifo_selected,initialized;
|
||||
reg [5:0] command,mode;
|
||||
reg [3:0] immediate,opcode,bit_length;
|
||||
reg [7:0] bit_value,control_index,control_last,byte0;
|
||||
reg [15:0] control_word;
|
||||
reg [15:0] next_byte;
|
||||
reg first_valid,second_valid;
|
||||
reg [10:0] read_address;
|
||||
wire [7:0] read_data;
|
||||
ssc_sp0256_memory memory(clk,reset,rom_begin,rom_write,rom_address,rom_data,
|
||||
rom_loaded,load_error,read_address,read_data);
|
||||
reg [7:0] r[0:15];
|
||||
reg signed [8:0] rpt;
|
||||
reg signed [10:0] cnt;
|
||||
reg [7:0] period;
|
||||
reg [11:0] amplitude;
|
||||
reg [14:0] rng;
|
||||
reg interpolate;
|
||||
reg signed [9:0] bcoef[0:5],fcoef[0:5];
|
||||
reg signed [15:0] z0[0:5],z1[0:5];
|
||||
reg signed [15:0] excitation;
|
||||
reg signed [25:0] product_b,product_f;
|
||||
reg signed [9:0] operand_b,operand_f,decoded_coefficient;
|
||||
reg signed [15:0] operand_z0,operand_z1;
|
||||
reg [7:0] coefficient_input;
|
||||
reg coefficient_forward;
|
||||
wire signed [31:0] filter_sum=$signed(excitation)+($signed(product_b)>>>9)+($signed(product_f)>>>8);
|
||||
reg [2:0] section;
|
||||
reg [12:0] micro_steps;
|
||||
integer j;
|
||||
wire pulse=period!=0 ? cnt<=0 : cnt<=1;
|
||||
wire [7:0] next_amplitude=r[0]+r[14];
|
||||
wire [7:0] next_period=r[1]+r[15];
|
||||
wire [7:0] signed_field=control_word[12] && bit_value[control_word[3:0]-1] ?
|
||||
(bit_value | (8'hff<<control_word[3:0])) : bit_value;
|
||||
wire [7:0] shifted_field=signed_field<<control_word[7:4];
|
||||
wire [15:0] rom_bit_window=({second_valid?read_data:8'd0,byte0}>>pc[2:0]) & ((16'h1<<bit_length)-16'd1);
|
||||
function [11:0] amp_decode(input [7:0] value);
|
||||
begin amp_decode={7'd0,value[4:0]}<<value[7:5];end
|
||||
endfunction
|
||||
function signed [9:0] coefficient(input [7:0] value);
|
||||
reg [7:0] negated;
|
||||
begin negated=-value;
|
||||
coefficient=value[7]?$signed({1'b0,sp_quant(negated[6:0])}):-$signed({1'b0,sp_quant(value[6:0])});
|
||||
end
|
||||
endfunction
|
||||
function [3:0] reverse4(input [3:0] value);
|
||||
begin reverse4={value[0],value[1],value[2],value[3]};end
|
||||
endfunction
|
||||
function [7:0] reverse8(input [7:0] value);
|
||||
begin reverse8={value[0],value[1],value[2],value[3],value[4],value[5],value[6],value[7]};end
|
||||
endfunction
|
||||
task bits(input [3:0] length,input [5:0] destination);
|
||||
begin bit_length<=length;return_state<=destination;state<=GET0;end
|
||||
endtask
|
||||
always @(posedge clk)begin
|
||||
if(reset || rom_begin || !rom_loaded || speech_reset)begin
|
||||
state<=IDLE;return_state<=IDLE;pc<=0;stack<=0;page<=19'h08000;
|
||||
halted<=1;pending<=0;fifo_selected<=0;initialized<=0;command<=0;mode<=0;
|
||||
immediate<=0;opcode<=0;bit_length<=0;bit_value<=0;control_index<=0;control_last<=0;
|
||||
control_word<=0;byte0<=0;next_byte<=0;first_valid<=0;second_valid<=0;read_address<=0;
|
||||
rpt<=-9'sd1;cnt<=0;period<=0;amplitude<=0;rng<=1;interpolate<=0;
|
||||
excitation<=0;product_b<=0;product_f<=0;section<=0;micro_steps<=0;
|
||||
operand_b<=0;operand_f<=0;operand_z0<=0;operand_z1<=0;decoded_coefficient<=0;
|
||||
coefficient_input<=0;coefficient_forward<=0;
|
||||
data_request<=rom_loaded&&!reset&&!rom_begin;standby<=1;sample<=0;sample_valid<=0;
|
||||
overrun<=0;fault<=0;frame_count<=0;
|
||||
for(j=0;j<16;j=j+1)r[j]<=0;
|
||||
for(j=0;j<6;j=j+1)begin bcoef[j]<=0;fcoef[j]<=0;z0[j]<=0;z1[j]<=0;end
|
||||
end else begin
|
||||
sample_valid<=0;
|
||||
if(!initialized)begin initialized<=1;data_request<=1;end
|
||||
if(sample_ce && busy)overrun<=1;
|
||||
case(state)
|
||||
IDLE:if(sample_ce)begin micro_steps<=0;state<=rpt<=0?MICRO:EXCITE;end
|
||||
MICRO:begin
|
||||
micro_steps<=micro_steps+13'd1;
|
||||
if(micro_steps==4095)begin
|
||||
fault<=1;halted<=1;data_request<=1;pending<=0;standby<=1;
|
||||
sample<=0;sample_valid<=1;state<=IDLE;
|
||||
end else if(halted && pending)begin
|
||||
pc<=19'h08000|{9'd0,command,4'd0};halted<=0;pending<=0;
|
||||
data_request<=1;fifo_selected<=0;
|
||||
for(j=0;j<16;j=j+1)r[j]<=0;
|
||||
end else if(halted)begin
|
||||
rpt<=1;data_request<=1;pending<=0;standby<=1;
|
||||
for(j=0;j<16;j=j+1)r[j]<=0;
|
||||
state<=EXCITE;
|
||||
end else bits(4,IMM);
|
||||
end
|
||||
IMM:begin immediate<=bit_value[3:0];bits(4,OPCODE);end
|
||||
OPCODE:begin
|
||||
opcode<=bit_value[3:0];
|
||||
if(bit_value!=1)mode<=mode&6'h0f;
|
||||
case(bit_value[3:0])
|
||||
0:begin
|
||||
if(immediate!=0)page<={reverse4(immediate),15'd0};
|
||||
else begin
|
||||
stack<=0;pc<=stack;fifo_selected<=stack==19'h0c000;
|
||||
if(stack==0)halted<=1;
|
||||
end
|
||||
state<=MICRO;
|
||||
end
|
||||
1:begin mode<={immediate[1:0],1'b0,immediate[2],immediate[3],1'b0};state<=MICRO;end
|
||||
13,14:bits(8,BRANCH);
|
||||
default:begin
|
||||
if({mode[5:4],immediate}==0)state<=MICRO;
|
||||
else begin
|
||||
rpt<=$signed({3'd0,mode[5:4],immediate})+9'sd1;
|
||||
control_index<=sp_index({bit_value[3:0],mode[2:1],1'b0});
|
||||
control_last<=sp_index({bit_value[3:0],mode[2:1],1'b1});state<=CONTROL;
|
||||
end
|
||||
end
|
||||
endcase
|
||||
end
|
||||
BRANCH:begin
|
||||
if(opcode==13)stack<=(pc+19'd7)&19'h7fff8;
|
||||
pc<=page|{4'd0,reverse4(immediate),11'd0}|{8'd0,reverse8(bit_value),3'd0};
|
||||
fifo_selected<=(page|{4'd0,reverse4(immediate),11'd0}|{8'd0,reverse8(bit_value),3'd0})==19'h0c000;
|
||||
state<=MICRO;
|
||||
end
|
||||
CONTROL:begin
|
||||
if(control_index>176 || control_last>176)begin fault<=1;sample<=0;sample_valid<=1;state<=IDLE;end
|
||||
else begin control_word<=sp_control(control_index);state<=FIELD_START;end
|
||||
end
|
||||
FIELD_START:begin
|
||||
if(control_word[15])for(j=0;j<16;j=j+1)r[j]<=0;
|
||||
if(control_word[14])begin r[12]<=0;r[13]<=0;end
|
||||
if(control_word[3:0]!=0)bits(control_word[3:0],FIELD_APPLY);
|
||||
else state<=FIELD_NEXT;
|
||||
end
|
||||
FIELD_APPLY:begin
|
||||
if(control_word[13])r[control_word[11:8]]<=
|
||||
(r[control_word[11:8]] & ~(8'hff<<control_word[7:4])) | shifted_field;
|
||||
else if(control_word[12])r[control_word[11:8]]<=r[control_word[11:8]]+shifted_field;
|
||||
else r[control_word[11:8]]<=shifted_field;
|
||||
state<=FIELD_NEXT;
|
||||
end
|
||||
FIELD_NEXT:begin
|
||||
if(control_index==control_last)begin
|
||||
if(opcode==15)r[1]<=64;
|
||||
state<=REGDEC;
|
||||
end else begin control_index<=control_index+8'd1;state<=CONTROL;end
|
||||
end
|
||||
REGDEC:begin
|
||||
amplitude<=amp_decode(r[0]);period<=r[1];cnt<=0;
|
||||
interpolate<=r[14]!=0||r[15]!=0;section<=0;frame_count<=frame_count+32'd1;state<=COEF_B;
|
||||
end
|
||||
COEF_B:begin coefficient_input<=r[2+{section,1'b0}];coefficient_forward<=0;state<=COEF_DECODE;end
|
||||
COEF_F:begin coefficient_input<=r[3+{section,1'b0}];coefficient_forward<=1;state<=COEF_DECODE;end
|
||||
COEF_DECODE:begin decoded_coefficient<=coefficient(coefficient_input);state<=COEF_STORE;end
|
||||
COEF_STORE:begin
|
||||
if(coefficient_forward)begin
|
||||
fcoef[section]<=decoded_coefficient;
|
||||
if(section==5)state<=EXCITE;else begin section<=section+3'd1;state<=COEF_B;end
|
||||
end else begin bcoef[section]<=decoded_coefficient;state<=COEF_F;end
|
||||
end
|
||||
EXCITE:begin
|
||||
if(period!=0)begin
|
||||
if(pulse)begin cnt<=cnt+$signed({3'd0,period});excitation<=$signed({4'd0,amplitude});end
|
||||
else begin cnt<=cnt-11'sd1;excitation<=0;end
|
||||
end else begin
|
||||
cnt<=pulse?11'sd64:cnt-11'sd1;
|
||||
rng<=(rng>>1)^(rng[0]?15'h4001:15'd0);
|
||||
excitation<=rng[0]?$signed({4'd0,amplitude}):-$signed({4'd0,amplitude});
|
||||
end
|
||||
if(pulse)begin
|
||||
rpt<=rpt-9'sd1;
|
||||
for(j=0;j<6;j=j+1)begin z0[j]<=0;z1[j]<=0;end
|
||||
if(interpolate)begin
|
||||
r[0]<=next_amplitude;r[1]<=next_period;
|
||||
amplitude<=amp_decode(next_amplitude);period<=next_period;
|
||||
end
|
||||
end
|
||||
section<=0;state<=(pulse && rpt<=1)?MICRO:FILTER_PICK;
|
||||
end
|
||||
FILTER_PICK:begin
|
||||
operand_b<=bcoef[section];operand_f<=fcoef[section];
|
||||
operand_z0<=z0[section];operand_z1<=z1[section];state<=FILTER_MULT;
|
||||
end
|
||||
FILTER_MULT:begin
|
||||
product_b<=$signed(operand_b)*$signed(operand_z1);
|
||||
product_f<=$signed(operand_f)*$signed(operand_z0);state<=FILTER_SUM;
|
||||
end
|
||||
FILTER_SUM:begin
|
||||
excitation<=filter_sum[15:0];z1[section]<=z0[section];z0[section]<=filter_sum[15:0];
|
||||
if(section==5)state<=LIMIT;else begin section<=section+3'd1;state<=FILTER_PICK;end
|
||||
end
|
||||
LIMIT:begin
|
||||
sample<=excitation > 16'sd8191 ? 16'sd32764 :
|
||||
excitation < -16'sd8192 ? 16'sh8000 : excitation<<<2;
|
||||
sample_valid<=1;state<=IDLE;
|
||||
end
|
||||
GET0:begin
|
||||
if(fifo_selected)begin bit_value<=0;state<=return_state;end
|
||||
else begin
|
||||
read_address<=pc[13:3];first_valid<=pc[18:14]==2;
|
||||
next_byte<=pc[18:3]+16'd1;state<=GET1;
|
||||
end
|
||||
end
|
||||
GET1:state<=GET2;
|
||||
GET2:begin
|
||||
byte0<=first_valid?read_data:8'd0;read_address<=next_byte[10:0];
|
||||
second_valid<=next_byte[15:11]==2;state<=GET3;
|
||||
end
|
||||
GET3:state<=GET4;
|
||||
GET4:begin
|
||||
bit_value<=rom_bit_window[7:0];
|
||||
pc<=pc+{15'd0,bit_length};state<=return_state;
|
||||
end
|
||||
default:begin fault<=1;state<=IDLE;end
|
||||
endcase
|
||||
// A newly accepted ALD wins over a simultaneous idle/microsequencer update.
|
||||
if(ald && data_request && initialized)begin
|
||||
command<=allophone;pending<=1;data_request<=0;standby<=0;
|
||||
end
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,26 @@
|
||||
// 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
|
||||
@@ -0,0 +1,455 @@
|
||||
// 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
|
||||
// GI SP0256 public algorithm tables, MAME Joseph Zbiciak/Tim Lindner.
|
||||
// Derived from pinned VCCPlus sp0256.cpp; see LICENSE. No mask ROM.
|
||||
// Generated by scripts/generate_ssc_sp0256_tables.py.
|
||||
// Source SHA256: 970ee4a027f637de820a10f66b119e95aeb366c4242df23de949ce1dccd030a3
|
||||
function [15:0] sp_control(input [7:0] address);
|
||||
begin case(address)
|
||||
8'd0: sp_control=16'h8000;
|
||||
8'd1: sp_control=16'h8008;
|
||||
8'd2: sp_control=16'h0108;
|
||||
8'd3: sp_control=16'h0208;
|
||||
8'd4: sp_control=16'h0308;
|
||||
8'd5: sp_control=16'h0408;
|
||||
8'd6: sp_control=16'h0508;
|
||||
8'd7: sp_control=16'h0608;
|
||||
8'd8: sp_control=16'h0708;
|
||||
8'd9: sp_control=16'h0808;
|
||||
8'd10: sp_control=16'h0908;
|
||||
8'd11: sp_control=16'h0a08;
|
||||
8'd12: sp_control=16'h0b08;
|
||||
8'd13: sp_control=16'h0c08;
|
||||
8'd14: sp_control=16'h0d08;
|
||||
8'd15: sp_control=16'h0e08;
|
||||
8'd16: sp_control=16'h0f08;
|
||||
8'd17: sp_control=16'h8026;
|
||||
8'd18: sp_control=16'h0108;
|
||||
8'd19: sp_control=16'h0834;
|
||||
8'd20: sp_control=16'h0926;
|
||||
8'd21: sp_control=16'h0a17;
|
||||
8'd22: sp_control=16'h0b26;
|
||||
8'd23: sp_control=16'h0c08;
|
||||
8'd24: sp_control=16'h0d08;
|
||||
8'd25: sp_control=16'h8026;
|
||||
8'd26: sp_control=16'h0108;
|
||||
8'd27: sp_control=16'h0816;
|
||||
8'd28: sp_control=16'h0917;
|
||||
8'd29: sp_control=16'h0a08;
|
||||
8'd30: sp_control=16'h0b08;
|
||||
8'd31: sp_control=16'h0c08;
|
||||
8'd32: sp_control=16'h0d08;
|
||||
8'd33: sp_control=16'h4000;
|
||||
8'd34: sp_control=16'h0026;
|
||||
8'd35: sp_control=16'h2926;
|
||||
8'd36: sp_control=16'h2b26;
|
||||
8'd37: sp_control=16'h2d08;
|
||||
8'd38: sp_control=16'h4000;
|
||||
8'd39: sp_control=16'h0026;
|
||||
8'd40: sp_control=16'h2917;
|
||||
8'd41: sp_control=16'h2b08;
|
||||
8'd42: sp_control=16'h2d08;
|
||||
8'd43: sp_control=16'h0000;
|
||||
8'd44: sp_control=16'h0000;
|
||||
8'd45: sp_control=16'h1024;
|
||||
8'd46: sp_control=16'h1105;
|
||||
8'd47: sp_control=16'h1243;
|
||||
8'd48: sp_control=16'h1333;
|
||||
8'd49: sp_control=16'h1443;
|
||||
8'd50: sp_control=16'h1533;
|
||||
8'd51: sp_control=16'h1643;
|
||||
8'd52: sp_control=16'h1733;
|
||||
8'd53: sp_control=16'h1833;
|
||||
8'd54: sp_control=16'h1924;
|
||||
8'd55: sp_control=16'h1a14;
|
||||
8'd56: sp_control=16'h1b24;
|
||||
8'd57: sp_control=16'h1c05;
|
||||
8'd58: sp_control=16'h1d05;
|
||||
8'd59: sp_control=16'h1024;
|
||||
8'd60: sp_control=16'h1105;
|
||||
8'd61: sp_control=16'h1214;
|
||||
8'd62: sp_control=16'h1324;
|
||||
8'd63: sp_control=16'h1414;
|
||||
8'd64: sp_control=16'h1524;
|
||||
8'd65: sp_control=16'h1614;
|
||||
8'd66: sp_control=16'h1724;
|
||||
8'd67: sp_control=16'h1814;
|
||||
8'd68: sp_control=16'h1915;
|
||||
8'd69: sp_control=16'h1a05;
|
||||
8'd70: sp_control=16'h1b05;
|
||||
8'd71: sp_control=16'h1c05;
|
||||
8'd72: sp_control=16'h1d05;
|
||||
8'd73: sp_control=16'h4000;
|
||||
8'd74: sp_control=16'h0026;
|
||||
8'd75: sp_control=16'h2335;
|
||||
8'd76: sp_control=16'h2535;
|
||||
8'd77: sp_control=16'h2735;
|
||||
8'd78: sp_control=16'h4000;
|
||||
8'd79: sp_control=16'h0026;
|
||||
8'd80: sp_control=16'h2326;
|
||||
8'd81: sp_control=16'h2526;
|
||||
8'd82: sp_control=16'h2726;
|
||||
8'd83: sp_control=16'h8026;
|
||||
8'd84: sp_control=16'h0108;
|
||||
8'd85: sp_control=16'h0243;
|
||||
8'd86: sp_control=16'h0335;
|
||||
8'd87: sp_control=16'h0443;
|
||||
8'd88: sp_control=16'h0535;
|
||||
8'd89: sp_control=16'h0643;
|
||||
8'd90: sp_control=16'h0735;
|
||||
8'd91: sp_control=16'h0834;
|
||||
8'd92: sp_control=16'h0926;
|
||||
8'd93: sp_control=16'h0a17;
|
||||
8'd94: sp_control=16'h0b26;
|
||||
8'd95: sp_control=16'h0e05;
|
||||
8'd96: sp_control=16'h0f05;
|
||||
8'd97: sp_control=16'h8026;
|
||||
8'd98: sp_control=16'h0108;
|
||||
8'd99: sp_control=16'h0216;
|
||||
8'd100: sp_control=16'h0326;
|
||||
8'd101: sp_control=16'h0416;
|
||||
8'd102: sp_control=16'h0526;
|
||||
8'd103: sp_control=16'h0616;
|
||||
8'd104: sp_control=16'h0726;
|
||||
8'd105: sp_control=16'h0816;
|
||||
8'd106: sp_control=16'h0917;
|
||||
8'd107: sp_control=16'h0a08;
|
||||
8'd108: sp_control=16'h0b08;
|
||||
8'd109: sp_control=16'h0e05;
|
||||
8'd110: sp_control=16'h0f05;
|
||||
8'd111: sp_control=16'h1024;
|
||||
8'd112: sp_control=16'h1105;
|
||||
8'd113: sp_control=16'h1833;
|
||||
8'd114: sp_control=16'h1924;
|
||||
8'd115: sp_control=16'h1a14;
|
||||
8'd116: sp_control=16'h1b24;
|
||||
8'd117: sp_control=16'h1c05;
|
||||
8'd118: sp_control=16'h1d05;
|
||||
8'd119: sp_control=16'h1024;
|
||||
8'd120: sp_control=16'h1105;
|
||||
8'd121: sp_control=16'h1814;
|
||||
8'd122: sp_control=16'h1915;
|
||||
8'd123: sp_control=16'h1a05;
|
||||
8'd124: sp_control=16'h1b05;
|
||||
8'd125: sp_control=16'h1c05;
|
||||
8'd126: sp_control=16'h1d05;
|
||||
8'd127: sp_control=16'h0026;
|
||||
8'd128: sp_control=16'h0108;
|
||||
8'd129: sp_control=16'h8026;
|
||||
8'd130: sp_control=16'h0108;
|
||||
8'd131: sp_control=16'h0243;
|
||||
8'd132: sp_control=16'h0335;
|
||||
8'd133: sp_control=16'h0443;
|
||||
8'd134: sp_control=16'h0535;
|
||||
8'd135: sp_control=16'h0643;
|
||||
8'd136: sp_control=16'h0735;
|
||||
8'd137: sp_control=16'h0834;
|
||||
8'd138: sp_control=16'h0926;
|
||||
8'd139: sp_control=16'h0a17;
|
||||
8'd140: sp_control=16'h0b26;
|
||||
8'd141: sp_control=16'h0c08;
|
||||
8'd142: sp_control=16'h0d08;
|
||||
8'd143: sp_control=16'h0e05;
|
||||
8'd144: sp_control=16'h0f05;
|
||||
8'd145: sp_control=16'h8026;
|
||||
8'd146: sp_control=16'h0108;
|
||||
8'd147: sp_control=16'h0216;
|
||||
8'd148: sp_control=16'h0326;
|
||||
8'd149: sp_control=16'h0416;
|
||||
8'd150: sp_control=16'h0526;
|
||||
8'd151: sp_control=16'h0616;
|
||||
8'd152: sp_control=16'h0726;
|
||||
8'd153: sp_control=16'h0816;
|
||||
8'd154: sp_control=16'h0917;
|
||||
8'd155: sp_control=16'h0a08;
|
||||
8'd156: sp_control=16'h0b08;
|
||||
8'd157: sp_control=16'h0c08;
|
||||
8'd158: sp_control=16'h0d08;
|
||||
8'd159: sp_control=16'h0e05;
|
||||
8'd160: sp_control=16'h0f05;
|
||||
8'd161: sp_control=16'h4000;
|
||||
8'd162: sp_control=16'h0026;
|
||||
8'd163: sp_control=16'h0108;
|
||||
8'd164: sp_control=16'h2335;
|
||||
8'd165: sp_control=16'h2535;
|
||||
8'd166: sp_control=16'h2735;
|
||||
8'd167: sp_control=16'h0e05;
|
||||
8'd168: sp_control=16'h0f05;
|
||||
8'd169: sp_control=16'h4000;
|
||||
8'd170: sp_control=16'h0026;
|
||||
8'd171: sp_control=16'h0108;
|
||||
8'd172: sp_control=16'h2326;
|
||||
8'd173: sp_control=16'h2526;
|
||||
8'd174: sp_control=16'h2726;
|
||||
8'd175: sp_control=16'h0e05;
|
||||
8'd176: sp_control=16'h0f05;
|
||||
default: sp_control=16'h0;
|
||||
endcase end
|
||||
endfunction
|
||||
function [7:0] sp_index(input [6:0] address);
|
||||
begin case(address)
|
||||
7'd0: sp_index=8'hff;
|
||||
7'd1: sp_index=8'hff;
|
||||
7'd2: sp_index=8'hff;
|
||||
7'd3: sp_index=8'hff;
|
||||
7'd4: sp_index=8'hff;
|
||||
7'd5: sp_index=8'hff;
|
||||
7'd6: sp_index=8'hff;
|
||||
7'd7: sp_index=8'hff;
|
||||
7'd8: sp_index=8'hff;
|
||||
7'd9: sp_index=8'hff;
|
||||
7'd10: sp_index=8'hff;
|
||||
7'd11: sp_index=8'hff;
|
||||
7'd12: sp_index=8'hff;
|
||||
7'd13: sp_index=8'hff;
|
||||
7'd14: sp_index=8'hff;
|
||||
7'd15: sp_index=8'hff;
|
||||
7'd16: sp_index=8'h11;
|
||||
7'd17: sp_index=8'h16;
|
||||
7'd18: sp_index=8'h11;
|
||||
7'd19: sp_index=8'h18;
|
||||
7'd20: sp_index=8'h19;
|
||||
7'd21: sp_index=8'h1e;
|
||||
7'd22: sp_index=8'h19;
|
||||
7'd23: sp_index=8'h20;
|
||||
7'd24: sp_index=8'h53;
|
||||
7'd25: sp_index=8'h5e;
|
||||
7'd26: sp_index=8'h81;
|
||||
7'd27: sp_index=8'h8e;
|
||||
7'd28: sp_index=8'h61;
|
||||
7'd29: sp_index=8'h6c;
|
||||
7'd30: sp_index=8'h91;
|
||||
7'd31: sp_index=8'h9e;
|
||||
7'd32: sp_index=8'h53;
|
||||
7'd33: sp_index=8'h60;
|
||||
7'd34: sp_index=8'h81;
|
||||
7'd35: sp_index=8'h90;
|
||||
7'd36: sp_index=8'h61;
|
||||
7'd37: sp_index=8'h6e;
|
||||
7'd38: sp_index=8'h91;
|
||||
7'd39: sp_index=8'ha0;
|
||||
7'd40: sp_index=8'h49;
|
||||
7'd41: sp_index=8'h4d;
|
||||
7'd42: sp_index=8'h4a;
|
||||
7'd43: sp_index=8'h4d;
|
||||
7'd44: sp_index=8'h4e;
|
||||
7'd45: sp_index=8'h52;
|
||||
7'd46: sp_index=8'h4f;
|
||||
7'd47: sp_index=8'h52;
|
||||
7'd48: sp_index=8'h21;
|
||||
7'd49: sp_index=8'h24;
|
||||
7'd50: sp_index=8'h22;
|
||||
7'd51: sp_index=8'h25;
|
||||
7'd52: sp_index=8'h26;
|
||||
7'd53: sp_index=8'h29;
|
||||
7'd54: sp_index=8'h27;
|
||||
7'd55: sp_index=8'h2a;
|
||||
7'd56: sp_index=8'h7f;
|
||||
7'd57: sp_index=8'h80;
|
||||
7'd58: sp_index=8'h7f;
|
||||
7'd59: sp_index=8'h80;
|
||||
7'd60: sp_index=8'h7f;
|
||||
7'd61: sp_index=8'h80;
|
||||
7'd62: sp_index=8'h7f;
|
||||
7'd63: sp_index=8'h80;
|
||||
7'd64: sp_index=8'h01;
|
||||
7'd65: sp_index=8'h0e;
|
||||
7'd66: sp_index=8'h01;
|
||||
7'd67: sp_index=8'h10;
|
||||
7'd68: sp_index=8'h01;
|
||||
7'd69: sp_index=8'h0e;
|
||||
7'd70: sp_index=8'h01;
|
||||
7'd71: sp_index=8'h10;
|
||||
7'd72: sp_index=8'h2d;
|
||||
7'd73: sp_index=8'h38;
|
||||
7'd74: sp_index=8'h2d;
|
||||
7'd75: sp_index=8'h3a;
|
||||
7'd76: sp_index=8'h3b;
|
||||
7'd77: sp_index=8'h46;
|
||||
7'd78: sp_index=8'h3b;
|
||||
7'd79: sp_index=8'h48;
|
||||
7'd80: sp_index=8'ha1;
|
||||
7'd81: sp_index=8'ha6;
|
||||
7'd82: sp_index=8'ha2;
|
||||
7'd83: sp_index=8'ha6;
|
||||
7'd84: sp_index=8'ha9;
|
||||
7'd85: sp_index=8'hae;
|
||||
7'd86: sp_index=8'haa;
|
||||
7'd87: sp_index=8'hae;
|
||||
7'd88: sp_index=8'h6f;
|
||||
7'd89: sp_index=8'h74;
|
||||
7'd90: sp_index=8'h6f;
|
||||
7'd91: sp_index=8'h76;
|
||||
7'd92: sp_index=8'h77;
|
||||
7'd93: sp_index=8'h7c;
|
||||
7'd94: sp_index=8'h77;
|
||||
7'd95: sp_index=8'h7e;
|
||||
7'd96: sp_index=8'ha1;
|
||||
7'd97: sp_index=8'ha8;
|
||||
7'd98: sp_index=8'ha2;
|
||||
7'd99: sp_index=8'ha8;
|
||||
7'd100: sp_index=8'ha9;
|
||||
7'd101: sp_index=8'hb0;
|
||||
7'd102: sp_index=8'haa;
|
||||
7'd103: sp_index=8'hb0;
|
||||
7'd104: sp_index=8'hff;
|
||||
7'd105: sp_index=8'hff;
|
||||
7'd106: sp_index=8'hff;
|
||||
7'd107: sp_index=8'hff;
|
||||
7'd108: sp_index=8'hff;
|
||||
7'd109: sp_index=8'hff;
|
||||
7'd110: sp_index=8'hff;
|
||||
7'd111: sp_index=8'hff;
|
||||
7'd112: sp_index=8'hff;
|
||||
7'd113: sp_index=8'hff;
|
||||
7'd114: sp_index=8'hff;
|
||||
7'd115: sp_index=8'hff;
|
||||
7'd116: sp_index=8'hff;
|
||||
7'd117: sp_index=8'hff;
|
||||
7'd118: sp_index=8'hff;
|
||||
7'd119: sp_index=8'hff;
|
||||
7'd120: sp_index=8'h00;
|
||||
7'd121: sp_index=8'h00;
|
||||
7'd122: sp_index=8'h00;
|
||||
7'd123: sp_index=8'h00;
|
||||
7'd124: sp_index=8'h00;
|
||||
7'd125: sp_index=8'h00;
|
||||
7'd126: sp_index=8'h00;
|
||||
7'd127: sp_index=8'h00;
|
||||
default: sp_index=8'hff;
|
||||
endcase end
|
||||
endfunction
|
||||
function [8:0] sp_quant(input [6:0] address);
|
||||
begin case(address)
|
||||
7'd0: sp_quant=9'h000;
|
||||
7'd1: sp_quant=9'h009;
|
||||
7'd2: sp_quant=9'h011;
|
||||
7'd3: sp_quant=9'h019;
|
||||
7'd4: sp_quant=9'h021;
|
||||
7'd5: sp_quant=9'h029;
|
||||
7'd6: sp_quant=9'h031;
|
||||
7'd7: sp_quant=9'h039;
|
||||
7'd8: sp_quant=9'h041;
|
||||
7'd9: sp_quant=9'h049;
|
||||
7'd10: sp_quant=9'h051;
|
||||
7'd11: sp_quant=9'h059;
|
||||
7'd12: sp_quant=9'h061;
|
||||
7'd13: sp_quant=9'h069;
|
||||
7'd14: sp_quant=9'h071;
|
||||
7'd15: sp_quant=9'h079;
|
||||
7'd16: sp_quant=9'h081;
|
||||
7'd17: sp_quant=9'h089;
|
||||
7'd18: sp_quant=9'h091;
|
||||
7'd19: sp_quant=9'h099;
|
||||
7'd20: sp_quant=9'h0a1;
|
||||
7'd21: sp_quant=9'h0a9;
|
||||
7'd22: sp_quant=9'h0b1;
|
||||
7'd23: sp_quant=9'h0b9;
|
||||
7'd24: sp_quant=9'h0c1;
|
||||
7'd25: sp_quant=9'h0c9;
|
||||
7'd26: sp_quant=9'h0d1;
|
||||
7'd27: sp_quant=9'h0d9;
|
||||
7'd28: sp_quant=9'h0e1;
|
||||
7'd29: sp_quant=9'h0e9;
|
||||
7'd30: sp_quant=9'h0f1;
|
||||
7'd31: sp_quant=9'h0f9;
|
||||
7'd32: sp_quant=9'h101;
|
||||
7'd33: sp_quant=9'h109;
|
||||
7'd34: sp_quant=9'h111;
|
||||
7'd35: sp_quant=9'h119;
|
||||
7'd36: sp_quant=9'h121;
|
||||
7'd37: sp_quant=9'h129;
|
||||
7'd38: sp_quant=9'h12d;
|
||||
7'd39: sp_quant=9'h131;
|
||||
7'd40: sp_quant=9'h135;
|
||||
7'd41: sp_quant=9'h139;
|
||||
7'd42: sp_quant=9'h13d;
|
||||
7'd43: sp_quant=9'h141;
|
||||
7'd44: sp_quant=9'h145;
|
||||
7'd45: sp_quant=9'h149;
|
||||
7'd46: sp_quant=9'h14d;
|
||||
7'd47: sp_quant=9'h151;
|
||||
7'd48: sp_quant=9'h155;
|
||||
7'd49: sp_quant=9'h159;
|
||||
7'd50: sp_quant=9'h15d;
|
||||
7'd51: sp_quant=9'h161;
|
||||
7'd52: sp_quant=9'h165;
|
||||
7'd53: sp_quant=9'h169;
|
||||
7'd54: sp_quant=9'h16d;
|
||||
7'd55: sp_quant=9'h171;
|
||||
7'd56: sp_quant=9'h175;
|
||||
7'd57: sp_quant=9'h179;
|
||||
7'd58: sp_quant=9'h17d;
|
||||
7'd59: sp_quant=9'h181;
|
||||
7'd60: sp_quant=9'h185;
|
||||
7'd61: sp_quant=9'h189;
|
||||
7'd62: sp_quant=9'h18d;
|
||||
7'd63: sp_quant=9'h191;
|
||||
7'd64: sp_quant=9'h195;
|
||||
7'd65: sp_quant=9'h199;
|
||||
7'd66: sp_quant=9'h19d;
|
||||
7'd67: sp_quant=9'h1a1;
|
||||
7'd68: sp_quant=9'h1a5;
|
||||
7'd69: sp_quant=9'h1a9;
|
||||
7'd70: sp_quant=9'h1ab;
|
||||
7'd71: sp_quant=9'h1ad;
|
||||
7'd72: sp_quant=9'h1af;
|
||||
7'd73: sp_quant=9'h1b1;
|
||||
7'd74: sp_quant=9'h1b3;
|
||||
7'd75: sp_quant=9'h1b5;
|
||||
7'd76: sp_quant=9'h1b7;
|
||||
7'd77: sp_quant=9'h1b9;
|
||||
7'd78: sp_quant=9'h1bb;
|
||||
7'd79: sp_quant=9'h1bd;
|
||||
7'd80: sp_quant=9'h1bf;
|
||||
7'd81: sp_quant=9'h1c1;
|
||||
7'd82: sp_quant=9'h1c3;
|
||||
7'd83: sp_quant=9'h1c5;
|
||||
7'd84: sp_quant=9'h1c7;
|
||||
7'd85: sp_quant=9'h1c9;
|
||||
7'd86: sp_quant=9'h1cb;
|
||||
7'd87: sp_quant=9'h1cd;
|
||||
7'd88: sp_quant=9'h1cf;
|
||||
7'd89: sp_quant=9'h1d1;
|
||||
7'd90: sp_quant=9'h1d3;
|
||||
7'd91: sp_quant=9'h1d5;
|
||||
7'd92: sp_quant=9'h1d7;
|
||||
7'd93: sp_quant=9'h1d9;
|
||||
7'd94: sp_quant=9'h1db;
|
||||
7'd95: sp_quant=9'h1dd;
|
||||
7'd96: sp_quant=9'h1df;
|
||||
7'd97: sp_quant=9'h1e1;
|
||||
7'd98: sp_quant=9'h1e2;
|
||||
7'd99: sp_quant=9'h1e3;
|
||||
7'd100: sp_quant=9'h1e4;
|
||||
7'd101: sp_quant=9'h1e5;
|
||||
7'd102: sp_quant=9'h1e6;
|
||||
7'd103: sp_quant=9'h1e7;
|
||||
7'd104: sp_quant=9'h1e8;
|
||||
7'd105: sp_quant=9'h1e9;
|
||||
7'd106: sp_quant=9'h1ea;
|
||||
7'd107: sp_quant=9'h1eb;
|
||||
7'd108: sp_quant=9'h1ec;
|
||||
7'd109: sp_quant=9'h1ed;
|
||||
7'd110: sp_quant=9'h1ee;
|
||||
7'd111: sp_quant=9'h1ef;
|
||||
7'd112: sp_quant=9'h1f0;
|
||||
7'd113: sp_quant=9'h1f1;
|
||||
7'd114: sp_quant=9'h1f2;
|
||||
7'd115: sp_quant=9'h1f3;
|
||||
7'd116: sp_quant=9'h1f4;
|
||||
7'd117: sp_quant=9'h1f5;
|
||||
7'd118: sp_quant=9'h1f6;
|
||||
7'd119: sp_quant=9'h1f7;
|
||||
7'd120: sp_quant=9'h1f8;
|
||||
7'd121: sp_quant=9'h1f9;
|
||||
7'd122: sp_quant=9'h1fa;
|
||||
7'd123: sp_quant=9'h1fb;
|
||||
7'd124: sp_quant=9'h1fc;
|
||||
7'd125: sp_quant=9'h1fd;
|
||||
7'd126: sp_quant=9'h1fe;
|
||||
7'd127: sp_quant=9'h1ff;
|
||||
default: sp_quant=9'h0;
|
||||
endcase end
|
||||
endfunction
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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-ROM PIC7040 controller. VCCPlus/MAME/TI provenance: LICENSE/docs.
|
||||
// No user firmware embedded. All external signals synchronous to clk.
|
||||
// icount_tick must pulse once per phi (PIC input clock /2); no clock is gated.
|
||||
module ssc_tms7000(input wire clk,reset,controller_reset,icount_tick,
|
||||
input wire rom_begin,rom_write,input wire [11:0] rom_address,input wire [7:0] rom_data,
|
||||
output wire rom_loaded,load_error,initialized,overrun,
|
||||
output wire [15:0] debug_pc,output wire [31:0] illegal_count,
|
||||
input wire irq1,irq3,timer_external,
|
||||
output wire gpio_request,gpio_write,output wire [1:0] gpio_port,
|
||||
output wire [7:0] gpio_write_data,input wire gpio_ready,input wire [7:0] gpio_read_data);
|
||||
wire memory_initialized,io_initialized,engine_initialized,engine_done,irq_valid,irq_ack;
|
||||
wire [1:0] irq_index;
|
||||
wire [15:0] pc,mem_address;
|
||||
wire [7:0] sp,status,mem_data,mem_read_data,pf_address,pf_data,pf_read_data;
|
||||
wire [31:0] illegal;
|
||||
wire [6:0] cycles;
|
||||
wire idle,mem_request,mem_write,mem_peripheral,mem_ready,pf_request,pf_write,pf_ready;
|
||||
wire step,quiet;
|
||||
reg pending_reset;
|
||||
reg [2:0] reset_state;
|
||||
reg io_restart,engine_restart;
|
||||
reg [1:0] acknowledged_irq;
|
||||
localparam [2:0] NORMAL=0,IO_WAIT_LOW=1,IO_WAIT_HIGH=2,CPU_WAIT_LOW=3,CPU_WAIT_HIGH=4;
|
||||
wire cold_reset=reset||rom_begin||!memory_initialized||!rom_loaded;
|
||||
wire engine_reset=cold_reset||(!io_initialized && reset_state==NORMAL);
|
||||
wire run=engine_initialized && io_initialized && !cold_reset && !pending_reset && reset_state==NORMAL;
|
||||
assign initialized=run && !overrun;
|
||||
assign debug_pc=pc;assign illegal_count=illegal;
|
||||
ssc_tms7000_exec engine(clk,engine_reset,engine_restart,step,irq_valid,irq_index,
|
||||
irq_ack,engine_initialized,engine_done,pc,sp,status,idle,illegal,cycles,
|
||||
mem_request,mem_write,mem_peripheral,mem_address,mem_data,mem_ready,mem_read_data);
|
||||
ssc_tms7000_memory memory(clk,reset,rom_begin,rom_write,rom_address,rom_data,
|
||||
rom_loaded,load_error,memory_initialized,mem_request,mem_write,mem_peripheral,
|
||||
mem_address,mem_data,mem_ready,mem_read_data,pf_request,pf_write,pf_address,pf_data,pf_ready,pf_read_data);
|
||||
ssc_tms7000_io peripherals(clk,reset||rom_begin,io_restart,io_initialized,
|
||||
pf_request,pf_write,pf_address,pf_data,pf_ready,pf_read_data,
|
||||
icount_tick && !cold_reset && (run||!quiet),irq1,irq3,timer_external,
|
||||
irq_ack,acknowledged_irq,irq_valid,irq_index,gpio_request,gpio_write,gpio_port,gpio_write_data,gpio_ready,gpio_read_data);
|
||||
ssc_tms7000_pacer scheduler(clk,cold_reset||!engine_initialized,run,icount_tick,
|
||||
engine_done,cycles,step,quiet,overrun);
|
||||
always @(posedge clk)begin
|
||||
if(reset)acknowledged_irq<=0;else acknowledged_irq<=irq_index;
|
||||
if(cold_reset)begin pending_reset<=0;reset_state<=NORMAL;io_restart<=0;engine_restart<=0;end
|
||||
else begin
|
||||
io_restart<=0;engine_restart<=0;
|
||||
if(controller_reset)pending_reset<=1;
|
||||
case(reset_state)
|
||||
NORMAL:if(pending_reset && quiet)begin pending_reset<=0;io_restart<=1;reset_state<=IO_WAIT_LOW;end
|
||||
IO_WAIT_LOW:if(!io_initialized)reset_state<=IO_WAIT_HIGH;
|
||||
IO_WAIT_HIGH:if(io_initialized)begin engine_restart<=1;reset_state<=CPU_WAIT_LOW;end
|
||||
CPU_WAIT_LOW:if(!engine_initialized)reset_state<=CPU_WAIT_HIGH;
|
||||
CPU_WAIT_HIGH:if(engine_initialized)reset_state<=NORMAL;
|
||||
default:reset_state<=NORMAL;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,52 @@
|
||||
// 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
|
||||
// TMS7000 arithmetic/flags, from VCCPlus a8a84f22/MAME hap, Tim Lindner.
|
||||
// Decimal/multiply use separate registered datapaths. Carry conventions: LICENSE.
|
||||
module ssc_tms7000_alu(input wire [5:0] operation,
|
||||
input wire [15:0] destination, input wire [7:0] source,status,
|
||||
output reg [15:0] result, output reg [7:0] next_status,
|
||||
output reg writeback, output reg branch, output reg [5:0] extra_cycles);
|
||||
`include "ssc_tms7000_defs.vh"
|
||||
reg [16:0] temp;
|
||||
reg [8:0] flags_value;
|
||||
reg set_flags,subtract;
|
||||
always @* begin
|
||||
temp=0;flags_value=0;result=0;next_status=status;writeback=1;branch=0;
|
||||
extra_cycles=0;set_flags=1;subtract=0;
|
||||
case(operation)
|
||||
OP_MOV:temp={9'd0,source};
|
||||
OP_AND:temp={9'd0,(destination[7:0]&source)};
|
||||
OP_OR:temp={9'd0,(destination[7:0]|source)};
|
||||
OP_XOR:temp={9'd0,(destination[7:0]^source)};
|
||||
OP_BTJO,OP_BTJZ:begin
|
||||
temp={9'd0,((operation==OP_BTJO?destination[7:0]:~destination[7:0])&source)};
|
||||
writeback=0;branch=(temp!=0);extra_cycles=branch?6'd4:6'd2;
|
||||
end
|
||||
OP_ADD:temp={9'd0,destination[7:0]}+{9'd0,source};
|
||||
OP_ADC:temp={9'd0,destination[7:0]}+{9'd0,source}+{16'd0,status[7]};
|
||||
OP_SUB,OP_CMP:begin temp={9'd0,destination[7:0]}-{9'd0,source};subtract=1;writeback=(operation!=OP_CMP);end
|
||||
OP_SBB:begin temp={9'd0,destination[7:0]}-{9'd0,source}-{16'd0,!status[7]};subtract=1;end
|
||||
// MPY has its own registered datapath in the instruction engine.
|
||||
OP_DEC:begin temp={9'd0,destination[7:0]}-17'd1;subtract=1;end
|
||||
OP_INC:temp={9'd0,destination[7:0]}+17'd1;
|
||||
OP_INV:temp={9'd0,~destination[7:0]};
|
||||
OP_CLR:temp=0;
|
||||
OP_XCHB:begin temp={9'd0,source};extra_cycles=1;end
|
||||
OP_SWAP:begin temp={5'd0,destination[7:0],4'd0}|{13'd0,destination[7:4]};extra_cycles=3;end
|
||||
OP_RR:temp={1'd0,destination[7:0],destination[0],destination[7:1]};
|
||||
OP_RRC:temp={1'd0,destination[7:0],status[7],destination[7:1]};
|
||||
OP_RL:temp={8'd0,destination[7:0],destination[7]};
|
||||
OP_RLC:temp={8'd0,destination[7:0],status[7]};
|
||||
OP_DJNZ:begin temp={9'd0,destination[7:0]}-17'd1;branch=(temp[15:0]!=0);extra_cycles=branch?6'd4:6'd2;set_flags=0;end
|
||||
OP_DECD:begin temp={1'b0,destination}-17'd1;subtract=1;end
|
||||
default:begin writeback=0;set_flags=0;end
|
||||
endcase
|
||||
result=temp[15:0];
|
||||
flags_value=(operation==OP_MPY || operation==OP_DECD)?temp[16:8]:temp[8:0];
|
||||
if(set_flags) begin
|
||||
next_status={flags_value[8],flags_value[7],(flags_value[7:0]==0),status[4:0]};
|
||||
if(subtract) next_status[7]=!flags_value[8];
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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
|
||||
// Two-stage parallel decimal adjust, VCCPlus/MAME TMS7000; see LICENSE.
|
||||
// No operation-select mux precedes the nibble arithmetic. Both results are
|
||||
// available two rising edges after stable operands, including invalid BCD.
|
||||
module ssc_tms7000_bcd(input wire clk,reset,input wire [7:0] destination,source,
|
||||
input wire carry,output reg [7:0] add_result,sub_result,
|
||||
output reg add_carry,sub_carry);
|
||||
reg [7:0] add_base,sub_base;
|
||||
reg [2:0] add_adjust,sub_adjust;
|
||||
wire [5:0] high_sum={2'd0,destination[7:4]}+{2'd0,source[7:4]};
|
||||
wire [5:0] low_sum={2'd0,destination[3:0]}+{2'd0,source[3:0]}+{5'd0,carry};
|
||||
wire low_borrow={1'b0,destination[3:0]}<({1'b0,source[3:0]}+{4'd0,!carry});
|
||||
function [7:0] correction(input [2:0] index);
|
||||
begin case(index) 1:correction=8'h06;3,5:correction=8'h66;4:correction=8'h60;default:correction=0;endcase end
|
||||
endfunction
|
||||
always @(posedge clk)begin
|
||||
if(reset)begin
|
||||
add_base<=0;sub_base<=0;add_adjust<=0;sub_adjust<=0;
|
||||
add_result<=0;sub_result<=0;add_carry<=0;sub_carry<=0;
|
||||
end else begin
|
||||
add_base<=destination+source+{7'd0,carry};
|
||||
sub_base<=destination-source-{7'd0,!carry};
|
||||
add_adjust<={(high_sum>9),(high_sum==9),(low_sum>=10)};
|
||||
sub_adjust<={(destination[7:4]<source[7:4]),(destination[7:4]==source[7:4]),low_borrow};
|
||||
add_result<=add_base+correction(add_adjust);
|
||||
sub_result<=sub_base-correction(sub_adjust);
|
||||
add_carry<=(add_adjust>2);sub_carry<=(sub_adjust<=2);
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,89 @@
|
||||
// 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
|
||||
// Full original TMS7000 opcode map. VCCPlus/MAME reference; see LICENSE.
|
||||
module ssc_tms7000_decode(input wire [7:0] opcode,
|
||||
output reg [5:0] operation,output reg [4:0] mode,
|
||||
output reg [5:0] base_cycles);
|
||||
`include "ssc_tms7000_defs.vh"
|
||||
reg [5:0] binary_operation,unary_operation;
|
||||
always @* begin
|
||||
binary_operation=OP_BAD;unary_operation=OP_BAD;
|
||||
case(opcode[3:0])
|
||||
2:binary_operation=OP_MOV;3:binary_operation=OP_AND;4:binary_operation=OP_OR;
|
||||
5:binary_operation=OP_XOR;6:binary_operation=OP_BTJO;7:binary_operation=OP_BTJZ;
|
||||
8:binary_operation=OP_ADD;9:binary_operation=OP_ADC;10:binary_operation=OP_SUB;
|
||||
11:binary_operation=OP_SBB;12:binary_operation=OP_MPY;13:binary_operation=OP_CMP;
|
||||
14:binary_operation=OP_DAC;15:binary_operation=OP_DSB;
|
||||
default:binary_operation=OP_BAD;
|
||||
endcase
|
||||
case(opcode[3:0])
|
||||
2:unary_operation=OP_DEC;3:unary_operation=OP_INC;4:unary_operation=OP_INV;
|
||||
5:unary_operation=OP_CLR;6:unary_operation=OP_XCHB;7:unary_operation=OP_SWAP;
|
||||
8:unary_operation=OP_PUSH;9:unary_operation=OP_POP;10:unary_operation=OP_DJNZ;
|
||||
11:unary_operation=OP_DECD;12:unary_operation=OP_RR;13:unary_operation=OP_RRC;
|
||||
14:unary_operation=OP_RL;15:unary_operation=OP_RLC;
|
||||
default:unary_operation=OP_BAD;
|
||||
endcase
|
||||
operation=OP_BAD;mode=AM_NONE;base_cycles=5;
|
||||
if(opcode>=8'h12 && opcode<=8'h7f && opcode[3:0]>=2) begin
|
||||
operation=binary_operation;
|
||||
case(opcode[7:4])
|
||||
1:begin mode=AM_R_A;base_cycles=8;end
|
||||
2:begin mode=AM_I_A;base_cycles=7;end
|
||||
3:begin mode=AM_R_B;base_cycles=8;end
|
||||
4:begin mode=AM_R_R;base_cycles=10;end
|
||||
5:begin mode=AM_I_B;base_cycles=7;end
|
||||
6:begin mode=AM_B_A;base_cycles=5;end
|
||||
7:begin mode=AM_I_R;base_cycles=9;end
|
||||
default:begin mode=AM_NONE;operation=OP_BAD;end
|
||||
endcase
|
||||
end else if(opcode>=8'hb0 && opcode<=8'hdf) begin
|
||||
operation=unary_operation;
|
||||
mode=(opcode[7:4]==11)?AM_A:(opcode[7:4]==12)?AM_B:AM_R;
|
||||
base_cycles=(mode==AM_R)?6'd7:6'd5;
|
||||
case(opcode[3:0])
|
||||
0:begin operation=OP_MOV;mode=(opcode[7:4]==11)?AM_A_A:(opcode[7:4]==12)?AM_A_B:AM_A_R;base_cycles=(mode==AM_A_R)?6'd8:6'd6;end
|
||||
1:begin operation=OP_MOV;mode=(opcode[7:4]==11)?AM_B_A:(opcode[7:4]==12)?AM_B_B:AM_B_R;base_cycles=(mode==AM_B_A)?6'd5:(mode==AM_B_R)?6'd7:6'd6;end
|
||||
8,9:base_cycles=(mode==AM_R)?6'd8:6'd6;
|
||||
11:base_cycles=(mode==AM_R)?6'd11:6'd9;
|
||||
default:begin end
|
||||
endcase
|
||||
end else if(opcode>=8'he8) begin operation=OP_TRAP;base_cycles=14;end
|
||||
else if(opcode>=8'he0) begin operation=OP_JUMP;base_cycles=3;end
|
||||
else case(opcode)
|
||||
8'h00:operation=OP_NOP;
|
||||
8'h01:begin operation=OP_IDLE;base_cycles=6;end
|
||||
8'h05:operation=OP_EINT;
|
||||
8'h06:operation=OP_DINT;
|
||||
8'h07:operation=OP_SETC;
|
||||
8'h08:begin operation=OP_POPST;base_cycles=6;end
|
||||
8'h09:begin operation=OP_STSP;base_cycles=6;end
|
||||
8'h0a:begin operation=OP_RETS;base_cycles=7;end
|
||||
8'h0b:begin operation=OP_RETI;base_cycles=9;end
|
||||
8'h0d:operation=OP_LDSP;
|
||||
8'h0e:begin operation=OP_PUSHST;base_cycles=6;end
|
||||
8'h80:begin operation=OP_MOV;mode=AM_P_A;base_cycles=9;end
|
||||
8'h91:begin operation=OP_MOV;mode=AM_P_B;base_cycles=8;end
|
||||
default:begin
|
||||
if(opcode[7:4]>=8 && opcode[7:4]<=10) begin
|
||||
if(opcode[3:0]>=2 && opcode[3:0]<=7) begin
|
||||
operation=binary_operation;mode=(opcode[7:4]==8)?AM_A_P:(opcode[7:4]==9)?AM_B_P:AM_I_P;
|
||||
base_cycles=(opcode[7:4]==8)?6'd10:(opcode[7:4]==9)?6'd9:6'd11;
|
||||
end else begin
|
||||
mode=(opcode[7:4]==8)?AM_DIR:(opcode[7:4]==9)?AM_IND:AM_INX;
|
||||
case(opcode[3:0])
|
||||
8:begin operation=OP_MOVD;base_cycles=(mode==AM_DIR)?6'd15:(mode==AM_IND)?6'd14:6'd17;end
|
||||
10:begin operation=OP_LDA;base_cycles=(mode==AM_DIR)?6'd11:(mode==AM_IND)?6'd10:6'd13;end
|
||||
11:begin operation=OP_STA;base_cycles=(mode==AM_DIR)?6'd11:(mode==AM_IND)?6'd10:6'd13;end
|
||||
12:begin operation=OP_BR;base_cycles=(mode==AM_DIR)?6'd10:(mode==AM_IND)?6'd9:6'd12;end
|
||||
13:begin operation=OP_CMPA;base_cycles=(mode==AM_DIR)?6'd12:(mode==AM_IND)?6'd11:6'd14;end
|
||||
14:begin operation=OP_CALL;base_cycles=(mode==AM_DIR)?6'd14:(mode==AM_IND)?6'd13:6'd16;end
|
||||
default:mode=AM_NONE;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
end
|
||||
endcase
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,19 @@
|
||||
// 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
|
||||
// Local instruction/micro-operation identifiers, not chip opcode encodings.
|
||||
// Behavioral port of VCCPlus/MAME TMS7000; notices in LICENSE.
|
||||
localparam [5:0] OP_BAD=0, OP_MOV=1, OP_AND=2, OP_OR=3, OP_XOR=4,
|
||||
OP_BTJO=5, OP_BTJZ=6, OP_ADD=7, OP_ADC=8, OP_SUB=9, OP_SBB=10,
|
||||
OP_MPY=11, OP_CMP=12, OP_DAC=13, OP_DSB=14, OP_DEC=15, OP_INC=16,
|
||||
OP_INV=17, OP_CLR=18, OP_XCHB=19, OP_SWAP=20, OP_RR=21, OP_RRC=22,
|
||||
OP_RL=23, OP_RLC=24, OP_DJNZ=25, OP_DECD=26, OP_PUSH=27, OP_POP=28,
|
||||
OP_NOP=29, OP_IDLE=30, OP_EINT=31, OP_DINT=32, OP_SETC=33,
|
||||
OP_POPST=34, OP_STSP=35, OP_RETS=36, OP_RETI=37, OP_LDSP=38,
|
||||
OP_PUSHST=39, OP_JUMP=40, OP_TRAP=41, OP_LDA=42, OP_STA=43,
|
||||
OP_BR=44, OP_CALL=45, OP_MOVD=46, OP_CMPA=47;
|
||||
localparam [4:0] AM_NONE=0, AM_R_A=1, AM_I_A=2, AM_R_B=3, AM_R_R=4,
|
||||
AM_I_B=5, AM_B_A=6, AM_I_R=7, AM_P_A=8, AM_A_P=9, AM_P_B=10,
|
||||
AM_B_P=11, AM_I_P=12, AM_A=13, AM_B=14, AM_R=15,
|
||||
AM_A_A=16, AM_A_B=17, AM_B_B=18, AM_A_R=19, AM_B_R=20,
|
||||
AM_DIR=21, AM_IND=22, AM_INX=23;
|
||||
@@ -0,0 +1,285 @@
|
||||
// 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
|
||||
// TMS7000 instruction engine, behavioral port of VCCPlus a8a84f22 / MAME.
|
||||
// Copyright/provenance: hap, Tim Lindner; original notices in LICENSE.
|
||||
// All state uses clk. One step executes one instruction OR interrupt entry.
|
||||
// cycles reports architectural icount (/2 input clock), NOT fabric clocks.
|
||||
// The future scheduler must pace steps/timer ticks; no chip clock is generated.
|
||||
// External memory supplies RF, peripheral file and ROM with a held-request bus.
|
||||
// Reset does the CPU reset TRAP; GPIO reset callbacks belong to the wrapper.
|
||||
module ssc_tms7000_exec(input wire clk,reset,restart,step,
|
||||
input wire irq_valid,input wire [1:0] irq_index,
|
||||
output reg irq_ack,output reg initialized,done,
|
||||
output reg [15:0] pc,output reg [7:0] sp,status,
|
||||
output reg idle,output reg [31:0] illegal_count,output reg [6:0] cycles,
|
||||
output reg mem_request,mem_write,mem_peripheral,output reg [15:0] mem_address,
|
||||
output reg [7:0] mem_write_data,input wire mem_ready,input wire [7:0] mem_read_data);
|
||||
`include "ssc_tms7000_defs.vh"
|
||||
localparam [6:0] RESET_START=0,WAIT_STEP=1,FETCHED=2,DECODE=3,
|
||||
SRC_INDEX=4,SRC_VALUE=5,DEST_START=6,DEST_INDEX=7,DEST_VALUE=8,ALU=9,
|
||||
UNARY_START=10,UNARY_INDEX=11,PAIR_HIGH=12,PAIR_LOW=13,XCH_VALUE=14,
|
||||
WRITE_RESULT=15,WRITE_PAIR_LOW=16,BRANCH_START=17,BRANCH_VALUE=18,
|
||||
ADDRESS_START=19,ADDRESS_HIGH=20,ADDRESS_LOW=21,POINTER_INDEX=22,
|
||||
POINTER_HIGH=23,POINTER_LOW=24,INDEX_VALUE=25,ADDRESS_READY=26,
|
||||
MOVD_INDEX=27,LOAD_VALUE=28,STORE_VALUE=29,CMP_VALUE=30,
|
||||
PUSH_HIGH=31,PUSH_LOW=32,AFTER_PUSH=33,VECTOR_HIGH=34,VECTOR_LOW=35,
|
||||
POP_VALUE=36,RETURN_LOW=37,RETURN_HIGH=38,RETURN_STATUS=39,
|
||||
LDSP_VALUE=40,FINISH=41,WAIT_RELEASE=42,BUS_WAIT=43,BUS_RELEASE=44,
|
||||
IRQ_PUSH_PC=45,ALU_COMMIT=46,MULTIPLY_COMMIT=47,DECIMAL_WAIT=48,DECIMAL_COMMIT=49,
|
||||
DISPATCH=50;
|
||||
reg [6:0] state,return_state;
|
||||
reg [7:0] opcode,value,source_value,destination_value,high_byte,low_byte;
|
||||
reg [5:0] operation;
|
||||
reg [4:0] mode;
|
||||
reg [15:0] destination_address,effective_address,pair_value,return_pc,vector_address;
|
||||
reg [7:0] pointer_index;
|
||||
reg branch_taken,is_reset,is_interrupt,destination_peripheral;
|
||||
reg [15:0] product,saved_result;
|
||||
reg [7:0] saved_status;
|
||||
reg saved_write,saved_branch;
|
||||
reg [5:0] saved_extra;
|
||||
wire [5:0] decoded_operation,decoded_cycles;
|
||||
wire [4:0] decoded_mode;
|
||||
ssc_tms7000_decode decoder(opcode,decoded_operation,decoded_mode,decoded_cycles);
|
||||
wire [15:0] alu_result;
|
||||
wire [7:0] alu_status;
|
||||
wire alu_write,alu_branch;
|
||||
wire [5:0] alu_extra;
|
||||
wire [7:0] decimal_add,decimal_sub;
|
||||
wire decimal_add_carry,decimal_sub_carry;
|
||||
wire [7:0] decimal_result=(operation==OP_DAC)?decimal_add:decimal_sub;
|
||||
ssc_tms7000_bcd decimal_unit(clk,reset,destination_value,source_value,status[7],
|
||||
decimal_add,decimal_sub,decimal_add_carry,decimal_sub_carry);
|
||||
ssc_tms7000_alu arithmetic(operation,
|
||||
(operation==OP_DECD)?pair_value:{8'd0,destination_value},source_value,status,
|
||||
alu_result,alu_status,alu_write,alu_branch,alu_extra);
|
||||
|
||||
task read_memory(input [15:0] address,input [6:0] continuation);
|
||||
begin mem_request<=1;mem_write<=0;mem_peripheral<=0;mem_address<=address;mem_write_data<=0;
|
||||
return_state<=continuation;state<=BUS_WAIT;end
|
||||
endtask
|
||||
task write_memory(input [15:0] address,input [7:0] data,input [6:0] continuation);
|
||||
begin mem_request<=1;mem_write<=1;mem_peripheral<=0;mem_address<=address;mem_write_data<=data;
|
||||
return_state<=continuation;state<=BUS_WAIT;end
|
||||
endtask
|
||||
task immediate(input [6:0] continuation);
|
||||
begin read_memory(pc,continuation);pc<=pc+16'd1;end
|
||||
endtask
|
||||
function [15:0] previous_register(input [15:0] address);
|
||||
begin previous_register={8'd0,(address[7:0]-8'd1)};end
|
||||
endfunction
|
||||
always @(posedge clk) begin
|
||||
if(reset) begin
|
||||
state<=RESET_START;return_state<=WAIT_STEP;mem_request<=0;mem_write<=0;mem_peripheral<=0;
|
||||
mem_address<=0;mem_write_data<=0;initialized<=0;done<=0;irq_ack<=0;
|
||||
pc<=0;sp<=8'hff;status<=0;idle<=0;illegal_count<=0;cycles<=0;
|
||||
opcode<=0;value<=0;source_value<=0;destination_value<=0;high_byte<=0;low_byte<=0;
|
||||
operation<=OP_BAD;mode<=AM_NONE;destination_address<=0;effective_address<=0;
|
||||
pair_value<=0;return_pc<=0;vector_address<=0;pointer_index<=0;
|
||||
branch_taken<=0;is_reset<=1;is_interrupt<=0;destination_peripheral<=0;
|
||||
product<=0;saved_result<=0;saved_status<=0;saved_write<=0;saved_branch<=0;saved_extra<=0;
|
||||
end else begin
|
||||
irq_ack<=0;
|
||||
// No operation-dependent operand mux before the physical multiplier.
|
||||
product<=destination_value*source_value;
|
||||
case(state)
|
||||
RESET_START:begin
|
||||
initialized<=0;done<=0;
|
||||
return_pc<=pc+{15'd0,idle};sp<=8'hff;status<=0;idle<=0;
|
||||
opcode<=8'hff;vector_address<=16'hfffe;is_reset<=1;is_interrupt<=0;
|
||||
cycles<=17;state<=PUSH_HIGH;
|
||||
end
|
||||
WAIT_STEP:begin
|
||||
done<=0;
|
||||
if(restart) state<=RESET_START;
|
||||
else if(step) begin
|
||||
is_reset<=0;is_interrupt<=0;
|
||||
if(irq_valid && status[4] && irq_index<3) begin
|
||||
irq_ack<=1;is_interrupt<=1;cycles<=idle?7'd17:7'd19;
|
||||
vector_address<=16'hfffc-{13'd0,irq_index,1'b0};
|
||||
return_pc<=pc+{15'd0,idle};idle<=0;
|
||||
sp<=sp+8'd1;write_memory({8'd0,(sp+8'd1)},status,IRQ_PUSH_PC);status<=0;
|
||||
end else immediate(FETCHED);
|
||||
end
|
||||
end
|
||||
FETCHED:begin opcode<=value;state<=DECODE;end
|
||||
DECODE:begin
|
||||
operation<=decoded_operation;mode<=decoded_mode;cycles<={1'b0,decoded_cycles};
|
||||
branch_taken<=0;destination_peripheral<=0;
|
||||
state<=DISPATCH;
|
||||
end
|
||||
DISPATCH:begin
|
||||
case(mode)
|
||||
AM_R_A,AM_R_B,AM_R_R,AM_P_A,AM_P_B:immediate(SRC_INDEX);
|
||||
AM_I_A,AM_I_B,AM_I_R,AM_I_P:immediate(SRC_VALUE);
|
||||
AM_A_A,AM_A_B,AM_A_R,AM_A_P:read_memory(0,SRC_VALUE);
|
||||
AM_B_A,AM_B_B,AM_B_R,AM_B_P:read_memory(1,SRC_VALUE);
|
||||
AM_A,AM_B,AM_R:state<=UNARY_START;
|
||||
AM_DIR,AM_IND,AM_INX:state<=ADDRESS_START;
|
||||
default:case(operation)
|
||||
OP_BAD:begin illegal_count<=illegal_count+1'b1;state<=FINISH;end
|
||||
OP_NOP:state<=FINISH;
|
||||
OP_IDLE:begin pc<=pc-16'd1;idle<=1;state<=FINISH;end
|
||||
OP_EINT:begin status<=status|8'hf0;state<=FINISH;end
|
||||
OP_DINT:begin status<=status&8'h0f;state<=FINISH;end
|
||||
OP_SETC:begin status<=(status&8'hbf)|8'ha0;state<=FINISH;end
|
||||
OP_STSP:write_memory(1,sp,FINISH);
|
||||
OP_LDSP:read_memory(1,LDSP_VALUE);
|
||||
OP_PUSHST:begin sp<=sp+8'd1;write_memory({8'd0,(sp+8'd1)},status,FINISH);end
|
||||
OP_POPST:begin read_memory({8'd0,sp},RETURN_STATUS);sp<=sp-8'd1;end
|
||||
OP_RETS,OP_RETI:begin read_memory({8'd0,sp},RETURN_LOW);sp<=sp-8'd1;end
|
||||
OP_TRAP:begin
|
||||
return_pc<=pc;vector_address<={8'hff,opcode[6:0],1'b0};state<=PUSH_HIGH;
|
||||
end
|
||||
OP_JUMP:begin
|
||||
case(opcode[2:0])
|
||||
0:branch_taken<=1;1:branch_taken<=status[6];2:branch_taken<=status[5];3:branch_taken<=status[7];
|
||||
4:branch_taken<=!(status[5]||status[6]);5:branch_taken<=!status[6];6:branch_taken<=!status[5];7:branch_taken<=!status[7];
|
||||
endcase
|
||||
state<=BRANCH_START;
|
||||
end
|
||||
default:state<=FINISH;
|
||||
endcase
|
||||
endcase
|
||||
end
|
||||
SRC_INDEX:begin
|
||||
read_memory((mode==AM_P_A||mode==AM_P_B)?{8'h01,value}:{8'd0,value},SRC_VALUE);
|
||||
mem_peripheral<=(mode==AM_P_A||mode==AM_P_B);
|
||||
end
|
||||
SRC_VALUE:begin source_value<=value;state<=DEST_START;end
|
||||
DEST_START:case(mode)
|
||||
AM_R_A,AM_I_A,AM_B_A,AM_P_A,AM_A_A:begin destination_address<=0;read_memory(0,DEST_VALUE);end
|
||||
AM_R_B,AM_I_B,AM_P_B,AM_A_B,AM_B_B:begin destination_address<=1;read_memory(1,DEST_VALUE);end
|
||||
default:immediate(DEST_INDEX);
|
||||
endcase
|
||||
DEST_INDEX:begin
|
||||
destination_address<=(mode==AM_A_P||mode==AM_B_P||mode==AM_I_P)?{8'h01,value}:{8'd0,value};
|
||||
destination_peripheral<=(mode==AM_A_P||mode==AM_B_P||mode==AM_I_P);
|
||||
read_memory((mode==AM_A_P||mode==AM_B_P||mode==AM_I_P)?{8'h01,value}:{8'd0,value},DEST_VALUE);
|
||||
mem_peripheral<=(mode==AM_A_P||mode==AM_B_P||mode==AM_I_P);
|
||||
end
|
||||
DEST_VALUE:begin destination_value<=value;state<=ALU;end
|
||||
UNARY_START:begin
|
||||
if(mode==AM_R) immediate(UNARY_INDEX);
|
||||
else begin destination_address<=(mode==AM_A)?16'd0:16'd1;state<=UNARY_INDEX;value<=(mode==AM_A)?8'd0:8'd1;end
|
||||
end
|
||||
UNARY_INDEX:begin
|
||||
destination_address<={8'd0,value};
|
||||
if(operation==OP_POP) begin read_memory({8'd0,sp},POP_VALUE);sp<=sp-8'd1;end
|
||||
else if(operation==OP_DECD) read_memory({8'd0,(value-8'd1)},PAIR_HIGH);
|
||||
else read_memory({8'd0,value},(operation==OP_PUSH)?STORE_VALUE:DEST_VALUE);
|
||||
end
|
||||
PAIR_HIGH:begin high_byte<=value;read_memory(destination_address,PAIR_LOW);end
|
||||
PAIR_LOW:begin pair_value<={high_byte,value};state<=ALU;end
|
||||
XCH_VALUE:begin source_value<=value;state<=ALU;end
|
||||
ALU:begin
|
||||
if(operation==OP_XCHB && mode!=AM_NONE) begin
|
||||
mode<=AM_NONE;read_memory(1,XCH_VALUE);
|
||||
end else if(operation==OP_MPY) state<=MULTIPLY_COMMIT;
|
||||
else if(operation==OP_DAC||operation==OP_DSB) state<=DECIMAL_WAIT;
|
||||
else begin
|
||||
saved_result<=alu_result;saved_status<=alu_status;saved_write<=alu_write;
|
||||
saved_branch<=alu_branch;saved_extra<=alu_extra;state<=ALU_COMMIT;
|
||||
end
|
||||
end
|
||||
MULTIPLY_COMMIT:begin
|
||||
status<={1'b0,product[15],(product[15:8]==0),status[4:0]};
|
||||
pair_value<=product;cycles<=cycles+7'd39;destination_address<=1;
|
||||
write_memory(0,product[15:8],WRITE_PAIR_LOW);
|
||||
end
|
||||
DECIMAL_WAIT:state<=DECIMAL_COMMIT;
|
||||
DECIMAL_COMMIT:begin
|
||||
status<={((operation==OP_DAC)?decimal_add_carry:decimal_sub_carry),
|
||||
decimal_result[7],(decimal_result==0),status[4:0]};
|
||||
cycles<=cycles+7'd2;
|
||||
write_memory(destination_address,decimal_result,FINISH);mem_peripheral<=destination_peripheral;
|
||||
end
|
||||
ALU_COMMIT:begin
|
||||
status<=saved_status;pair_value<=saved_result;branch_taken<=saved_branch;
|
||||
cycles<=cycles+{1'b0,saved_extra};
|
||||
if(operation==OP_DECD) write_memory(previous_register(destination_address),saved_result[15:8],WRITE_PAIR_LOW);
|
||||
else if(operation==OP_XCHB) write_memory(1,destination_value,WRITE_RESULT);
|
||||
// DJNZ consumes displacement BEFORE writing its decremented operand.
|
||||
// This matters when PC wraps into RF and the two addresses alias.
|
||||
else if(operation==OP_DJNZ) state<=BRANCH_START;
|
||||
else if(saved_write) begin write_memory(destination_address,saved_result[7:0],BRANCH_START);mem_peripheral<=destination_peripheral;end
|
||||
else state<=BRANCH_START;
|
||||
end
|
||||
WRITE_RESULT:begin write_memory(destination_address,pair_value[7:0],BRANCH_START);mem_peripheral<=destination_peripheral;end
|
||||
WRITE_PAIR_LOW:write_memory(destination_address,pair_value[7:0],BRANCH_START);
|
||||
BRANCH_START:begin
|
||||
if(operation==OP_JUMP) begin cycles<=cycles+(branch_taken?7'd4:7'd2);immediate(BRANCH_VALUE);end
|
||||
else if(operation==OP_BTJO||operation==OP_BTJZ||operation==OP_DJNZ) immediate(BRANCH_VALUE);
|
||||
else state<=FINISH;
|
||||
end
|
||||
BRANCH_VALUE:begin
|
||||
if(branch_taken) pc<=pc+{{8{value[7]}},value};
|
||||
if(operation==OP_DJNZ) write_memory(destination_address,pair_value[7:0],FINISH);
|
||||
else state<=FINISH;
|
||||
end
|
||||
ADDRESS_START:begin if(mode==AM_IND) immediate(POINTER_INDEX);else immediate(ADDRESS_HIGH);end
|
||||
ADDRESS_HIGH:begin high_byte<=value;immediate(ADDRESS_LOW);end
|
||||
ADDRESS_LOW:begin
|
||||
effective_address<={high_byte,value};
|
||||
if(mode==AM_INX) read_memory(1,INDEX_VALUE);else state<=ADDRESS_READY;
|
||||
end
|
||||
POINTER_INDEX:begin pointer_index<=value;read_memory({8'd0,(value-8'd1)},POINTER_HIGH);end
|
||||
POINTER_HIGH:begin high_byte<=value;read_memory({8'd0,pointer_index},POINTER_LOW);end
|
||||
POINTER_LOW:begin effective_address<={high_byte,value};state<=ADDRESS_READY;end
|
||||
INDEX_VALUE:begin effective_address<=effective_address+{8'd0,value};state<=ADDRESS_READY;end
|
||||
ADDRESS_READY:case(operation)
|
||||
OP_MOVD:immediate(MOVD_INDEX);
|
||||
OP_LDA:read_memory(effective_address,LOAD_VALUE);
|
||||
OP_STA:read_memory(0,STORE_VALUE);
|
||||
OP_CMPA:read_memory(effective_address,CMP_VALUE);
|
||||
OP_BR:begin pc<=effective_address;state<=FINISH;end
|
||||
OP_CALL:begin return_pc<=pc;state<=PUSH_HIGH;end
|
||||
default:state<=FINISH;
|
||||
endcase
|
||||
MOVD_INDEX:begin
|
||||
destination_address<={8'd0,value};pair_value<=effective_address;
|
||||
status<={1'b0,effective_address[15],(effective_address[15:8]==0),status[4:0]};
|
||||
write_memory({8'd0,(value-8'd1)},effective_address[15:8],WRITE_PAIR_LOW);
|
||||
end
|
||||
LOAD_VALUE:begin
|
||||
status<={1'b0,value[7],(value==0),status[4:0]};write_memory(0,value,FINISH);
|
||||
end
|
||||
STORE_VALUE:begin
|
||||
status<={1'b0,value[7],(value==0),status[4:0]};
|
||||
if(operation==OP_PUSH) begin sp<=sp+8'd1;write_memory({8'd0,(sp+8'd1)},value,FINISH);end
|
||||
else write_memory(effective_address,value,FINISH);
|
||||
end
|
||||
CMP_VALUE:begin source_value<=value;operation<=OP_CMP;read_memory(0,DEST_VALUE);end
|
||||
PUSH_HIGH:begin sp<=sp+8'd1;write_memory({8'd0,(sp+8'd1)},return_pc[15:8],PUSH_LOW);end
|
||||
PUSH_LOW:begin sp<=sp+8'd1;write_memory({8'd0,(sp+8'd1)},return_pc[7:0],AFTER_PUSH);end
|
||||
AFTER_PUSH:begin
|
||||
if(operation==OP_CALL && !is_reset && !is_interrupt) begin pc<=effective_address;state<=FINISH;end
|
||||
else read_memory(vector_address,VECTOR_HIGH);
|
||||
end
|
||||
VECTOR_HIGH:begin high_byte<=value;read_memory(vector_address+16'd1,VECTOR_LOW);end
|
||||
VECTOR_LOW:begin pc<={high_byte,value};state<=FINISH;end
|
||||
IRQ_PUSH_PC:state<=PUSH_HIGH;
|
||||
POP_VALUE:begin
|
||||
status<={1'b0,value[7],(value==0),status[4:0]};write_memory(destination_address,value,FINISH);
|
||||
end
|
||||
RETURN_LOW:begin low_byte<=value;read_memory({8'd0,sp},RETURN_HIGH);sp<=sp-8'd1;end
|
||||
RETURN_HIGH:begin
|
||||
pc<={value,low_byte};
|
||||
if(operation==OP_RETI) begin read_memory({8'd0,sp},RETURN_STATUS);sp<=sp-8'd1;end
|
||||
else state<=FINISH;
|
||||
end
|
||||
RETURN_STATUS:begin status<=value&8'hf0;state<=FINISH;end
|
||||
LDSP_VALUE:begin sp<=value;state<=FINISH;end
|
||||
FINISH:begin
|
||||
if(is_reset) begin initialized<=1;state<=WAIT_STEP;end
|
||||
else begin done<=1;state<=WAIT_RELEASE;end
|
||||
end
|
||||
WAIT_RELEASE:if(!step) begin done<=0;state<=WAIT_STEP;end
|
||||
BUS_WAIT:if(mem_ready) begin value<=mem_read_data;mem_request<=0;state<=BUS_RELEASE;end
|
||||
BUS_RELEASE:if(!mem_ready) state<=return_state;
|
||||
default:state<=RESET_START;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,132 @@
|
||||
// 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
|
||||
// PIC7040 peripherals. VCCPlus/MAME hap, Tim Lindner; notices in LICENSE.
|
||||
// TI SPND001A sections 2.2,2.5,2.6 govern DDR updates, latched/level IRQs,
|
||||
// and immediate automatic timer reload, where the software reference differs.
|
||||
// icount_tick is one phi clock (PIC input clock /2), NOT one fabric clock.
|
||||
// GPIO uses captured held requests. Input/high-impedance output bits are zero
|
||||
// on this digital glue interface; this does not model external pull resistors.
|
||||
module ssc_tms7000_io(input wire clk,reset,soft_reset,
|
||||
output reg initialized,
|
||||
input wire request,write,input wire [7:0] address,write_data,
|
||||
output reg ready,output reg [7:0] read_data,
|
||||
input wire icount_tick,irq1,irq3,timer_external,
|
||||
input wire irq_ack,input wire [1:0] irq_ack_index,
|
||||
output wire irq_valid,output wire [1:0] irq_index,
|
||||
output reg gpio_request,gpio_write,output reg [1:0] gpio_port,
|
||||
output reg [7:0] gpio_write_data,input wire gpio_ready,input wire [7:0] gpio_read_data);
|
||||
localparam [3:0] RESET_BEGIN=0,RESET_C=1,RESET_D=2,RESET_END=3,IDLE=4,
|
||||
EXECUTE=5,READ_GPIO=6,COMPLETE=7,WAIT_RELEASE=8,GPIO_WAIT=9,GPIO_RELEASE=10;
|
||||
reg [3:0] state,continuation;
|
||||
reg access_write;
|
||||
reg [7:0] access_address,access_data,gpio_value;
|
||||
reg [7:0] latch_b,latch_c,latch_d,ddr_c,ddr_d;
|
||||
reg [2:0] irq_enable,irq_latched;
|
||||
reg [1:0] mode_bits;
|
||||
reg previous_irq1,previous_irq3,previous_external;
|
||||
reg [7:0] timer_data,timer_control,timer_current,timer_capture;
|
||||
reg [4:0] timer_prescale;
|
||||
reg [2:0] timer_divider;
|
||||
reg timer_running;
|
||||
wire [2:0] flags=irq_latched|{irq3,1'b0,irq1};
|
||||
wire [2:0] pending=flags&irq_enable;
|
||||
assign irq_valid=|pending;
|
||||
assign irq_index=pending[0]?2'd0:pending[1]?2'd1:2'd2;
|
||||
wire timer_event=timer_running && icount_tick &&
|
||||
(timer_control[6]?(timer_external && !previous_external):(timer_divider==3'd7));
|
||||
wire pf_write=state==EXECUTE && access_write;
|
||||
task gpio(input w,input [1:0] port,input [7:0] data,input [3:0] next);
|
||||
begin gpio_request<=1;gpio_write<=w;gpio_port<=port;gpio_write_data<=data;
|
||||
continuation<=next;state<=GPIO_WAIT;end
|
||||
endtask
|
||||
always @(posedge clk)begin
|
||||
if(reset)begin
|
||||
state<=RESET_BEGIN;continuation<=IDLE;initialized<=0;ready<=0;read_data<=0;
|
||||
access_write<=0;access_address<=0;access_data<=0;gpio_value<=0;
|
||||
gpio_request<=0;gpio_write<=0;gpio_port<=0;gpio_write_data<=0;
|
||||
latch_b<=0;latch_c<=0;latch_d<=0;ddr_c<=0;ddr_d<=0;
|
||||
irq_enable<=0;irq_latched<=0;mode_bits<=0;previous_irq1<=0;previous_irq3<=0;
|
||||
previous_external<=0;timer_data<=0;timer_control<=0;timer_current<=0;
|
||||
timer_capture<=0;timer_prescale<=0;timer_divider<=0;timer_running<=0;
|
||||
end else begin
|
||||
previous_irq1<=irq1;previous_irq3<=irq3;
|
||||
if(icount_tick)previous_external<=timer_external;
|
||||
if(irq_ack && irq_ack_index<3)irq_latched[irq_ack_index]<=0;
|
||||
// Pulse latches survive deassertion; active levels remain visible after ack.
|
||||
// New assertions win over software clears/ack on the same fabric edge.
|
||||
if(irq1 && !previous_irq1)irq_latched[0]<=1;
|
||||
if(irq3 && !previous_irq3)begin irq_latched[2]<=1;timer_capture<=timer_current;end
|
||||
if(initialized && timer_running && icount_tick && !timer_control[6])
|
||||
timer_divider<=timer_divider+3'd1;
|
||||
if(initialized && timer_event)begin
|
||||
if(timer_prescale==0)begin
|
||||
timer_prescale<=timer_control[4:0];
|
||||
if(timer_current==0)begin timer_current<=timer_data;irq_latched[1]<=1;end
|
||||
else timer_current<=timer_current-8'd1;
|
||||
end else timer_prescale<=timer_prescale-5'd1;
|
||||
end
|
||||
case(state)
|
||||
RESET_BEGIN:begin
|
||||
initialized<=0;ready<=0;irq_enable<=0;mode_bits<=0;timer_running<=0;
|
||||
latch_b<=8'hff;latch_c<=8'hff;latch_d<=8'hff;ddr_c<=0;ddr_d<=0;
|
||||
if(!gpio_ready)gpio(1,1,8'hff,RESET_C);
|
||||
end
|
||||
RESET_C:gpio(1,2,0,RESET_D);
|
||||
RESET_D:gpio(1,3,0,RESET_END);
|
||||
RESET_END:begin initialized<=1;state<=IDLE;end
|
||||
IDLE:begin
|
||||
if(soft_reset)state<=RESET_BEGIN;
|
||||
else if(request)begin access_write<=write;access_address<=address;
|
||||
access_data<=write_data;state<=EXECUTE;end
|
||||
end
|
||||
EXECUTE:begin
|
||||
if(access_write)begin
|
||||
case(access_address)
|
||||
0:begin
|
||||
irq_enable<={access_data[4],access_data[2],access_data[0]};mode_bits<=access_data[7:6];
|
||||
if(access_data[1])irq_latched[0]<=irq1 && !previous_irq1;
|
||||
if(access_data[3])irq_latched[1]<=initialized && timer_event && timer_prescale==0 && timer_current==0;
|
||||
if(access_data[5])irq_latched[2]<=irq3 && !previous_irq3;
|
||||
state<=COMPLETE;
|
||||
end
|
||||
2:begin timer_data<=access_data;state<=COMPLETE;end
|
||||
3:begin
|
||||
timer_control<=access_data;timer_running<=access_data[7];
|
||||
if(access_data[7])begin timer_current<=timer_data;timer_prescale<=access_data[4:0];timer_divider<=0;end
|
||||
state<=COMPLETE;
|
||||
end
|
||||
6:begin latch_b<=access_data;gpio(1,1,access_data,COMPLETE);end
|
||||
8:begin latch_c<=access_data;gpio(1,2,access_data&ddr_c,COMPLETE);end
|
||||
9:begin ddr_c<=access_data;gpio(1,2,latch_c&access_data,COMPLETE);end
|
||||
10:begin latch_d<=access_data;gpio(1,3,access_data&ddr_d,COMPLETE);end
|
||||
11:begin ddr_d<=access_data;gpio(1,3,latch_d&access_data,COMPLETE);end
|
||||
default:state<=COMPLETE;
|
||||
endcase
|
||||
end else case(access_address)
|
||||
0:begin read_data<={mode_bits,flags[2],irq_enable[2],flags[1],irq_enable[1],flags[0],irq_enable[0]};state<=COMPLETE;end
|
||||
2:begin read_data<=timer_current;state<=COMPLETE;end
|
||||
3:begin read_data<=timer_capture;state<=COMPLETE;end
|
||||
4:gpio(0,0,0,READ_GPIO);
|
||||
6:begin read_data<=latch_b;state<=COMPLETE;end
|
||||
8:gpio(0,2,0,READ_GPIO);
|
||||
9:begin read_data<=ddr_c;state<=COMPLETE;end
|
||||
10:gpio(0,3,0,READ_GPIO);
|
||||
11:begin read_data<=ddr_d;state<=COMPLETE;end
|
||||
default:begin read_data<=0;state<=COMPLETE;end
|
||||
endcase
|
||||
end
|
||||
READ_GPIO:begin
|
||||
read_data<=(access_address==4)?gpio_value:(access_address==8)?
|
||||
((gpio_value&~ddr_c)|(latch_c&ddr_c)):((gpio_value&~ddr_d)|(latch_d&ddr_d));
|
||||
state<=COMPLETE;
|
||||
end
|
||||
COMPLETE:begin ready<=1;state<=WAIT_RELEASE;end
|
||||
WAIT_RELEASE:if(!request)begin ready<=0;state<=IDLE;end
|
||||
GPIO_WAIT:if(gpio_ready)begin gpio_value<=gpio_read_data;gpio_request<=0;state<=GPIO_RELEASE;end
|
||||
GPIO_RELEASE:if(!gpio_ready)state<=continuation;
|
||||
default:state<=RESET_BEGIN;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,70 @@
|
||||
// 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
|
||||
// Single-chip PIC7040 RF/ROM map and peripheral bus adapter. See LICENSE.
|
||||
// ROM is volatile, sequentially loaded 0..4095 after rom_begin. No ROM bytes
|
||||
// are built into this source. A malformed load invalidates the image.
|
||||
module ssc_tms7000_memory(input wire clk,reset,
|
||||
input wire rom_begin,rom_write,input wire [11:0] rom_address,input wire [7:0] rom_data,
|
||||
output reg rom_loaded,load_error,output reg initialized,
|
||||
input wire request,write,peripheral,input wire [15:0] address,input wire [7:0] write_data,
|
||||
output reg ready,output reg [7:0] read_data,
|
||||
output reg pf_request,pf_write,output reg [7:0] pf_address,pf_write_data,
|
||||
input wire pf_ready,input wire [7:0] pf_read_data);
|
||||
localparam [2:0] IDLE=0,EXECUTE=1,READ_RETURN=2,PF_WAIT=3,PF_RELEASE=4,WAIT_RELEASE=5;
|
||||
reg [2:0] state;
|
||||
reg [7:0] rf[0:127],rom[0:4095];
|
||||
reg [7:0] rf_read,rom_read;
|
||||
reg [6:0] clear_address;
|
||||
reg [15:0] access_address;
|
||||
reg [7:0] access_data;
|
||||
reg access_write,access_peripheral,loading;
|
||||
reg [11:0] expected_address;
|
||||
wire rf_store=initialized && !rom_begin && state==EXECUTE && access_write && access_address<128 && !access_peripheral;
|
||||
wire rom_store=!reset && !rom_begin && rom_write && loading && !load_error && rom_address==expected_address;
|
||||
always @(posedge clk)begin
|
||||
rf_read<=rf[access_address[6:0]];rom_read<=rom[access_address[11:0]];
|
||||
if(!reset && !initialized)rf[clear_address]<=0;
|
||||
else if(!reset && rf_store)rf[access_address[6:0]]<=access_data;
|
||||
if(rom_store)rom[rom_address]<=rom_data;
|
||||
end
|
||||
always @(posedge clk)begin
|
||||
if(reset)begin
|
||||
initialized<=0;clear_address<=0;state<=IDLE;ready<=0;read_data<=0;
|
||||
access_address<=0;access_data<=0;access_write<=0;access_peripheral<=0;
|
||||
pf_request<=0;pf_write<=0;pf_address<=0;pf_write_data<=0;
|
||||
rom_loaded<=0;load_error<=0;loading<=0;expected_address<=0;
|
||||
end else begin
|
||||
if(!initialized)begin
|
||||
if(clear_address==127)initialized<=1;else clear_address<=clear_address+7'd1;
|
||||
end
|
||||
if(rom_begin)begin rom_loaded<=0;load_error<=0;loading<=1;expected_address<=0;end
|
||||
else if(rom_write)begin
|
||||
if(!loading || load_error || rom_address!=expected_address)begin rom_loaded<=0;load_error<=1;loading<=0;end
|
||||
else if(expected_address==4095)begin rom_loaded<=1;loading<=0;end
|
||||
else expected_address<=expected_address+12'd1;
|
||||
end
|
||||
if(rom_begin)begin state<=IDLE;ready<=0;pf_request<=0;end
|
||||
else case(state)
|
||||
IDLE:if(initialized && request)begin
|
||||
access_address<=address;access_data<=write_data;access_write<=write;access_peripheral<=peripheral;
|
||||
state<=EXECUTE;
|
||||
end
|
||||
EXECUTE:begin
|
||||
if(access_peripheral || (access_address>=16'h100 && access_address<16'h10c))begin
|
||||
pf_request<=1;pf_write<=access_write;pf_address<=access_address[7:0];pf_write_data<=access_data;state<=PF_WAIT;
|
||||
end else state<=READ_RETURN;
|
||||
end
|
||||
READ_RETURN:begin
|
||||
read_data<=access_address<128?rf_read:access_address<256?8'h00:
|
||||
access_address>=16'hf000 ? rom_read:8'hff;
|
||||
ready<=1;state<=WAIT_RELEASE;
|
||||
end
|
||||
PF_WAIT:if(pf_ready)begin read_data<=pf_read_data;pf_request<=0;state<=PF_RELEASE;end
|
||||
PF_RELEASE:if(!pf_ready)begin ready<=1;state<=WAIT_RELEASE;end
|
||||
WAIT_RELEASE:if(!request)begin ready<=0;state<=IDLE;end
|
||||
default:state<=IDLE;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
@@ -0,0 +1,43 @@
|
||||
// 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
|
||||
// Instruction-boundary scheduler. icount_tick is PIC input clock /2.
|
||||
// Start-to-start intervals equal reported architectural cycles. An engine or
|
||||
// peripheral response that misses its deadline sets overrun and stops launches.
|
||||
// run may fall during a transaction; quiescent follows its completed budget.
|
||||
module ssc_tms7000_pacer(input wire clk,reset,run,icount_tick,
|
||||
input wire engine_done,input wire [6:0] engine_cycles,
|
||||
output reg step,output wire quiescent,output reg overrun);
|
||||
localparam [1:0] IDLE=0,EXECUTE=1,RELEASE=2,BUDGET=3;
|
||||
reg [1:0] state;
|
||||
reg [7:0] elapsed;
|
||||
reg [6:0] budget;
|
||||
wire [8:0] next_elapsed={1'b0,elapsed}+{8'd0,icount_tick};
|
||||
assign quiescent=state==IDLE && !step;
|
||||
always @(posedge clk)begin
|
||||
if(reset)begin state<=IDLE;step<=0;overrun<=0;elapsed<=0;budget<=0;end
|
||||
else begin
|
||||
if(state!=IDLE && icount_tick && elapsed!=255)elapsed<=elapsed+8'd1;
|
||||
// A nonresponding bus must be observable even if engine_done never arrives.
|
||||
// Original instructions take at most49 icount ticks. Do not abort a captured
|
||||
// bus operation; latch the fault and require reset if it cannot complete.
|
||||
if(state==EXECUTE && next_elapsed>=9'd127)overrun<=1;
|
||||
case(state)
|
||||
IDLE:if(run && icount_tick && !overrun)begin step<=1;elapsed<=0;state<=EXECUTE;end
|
||||
EXECUTE:if(engine_done)begin
|
||||
step<=0;budget<=engine_cycles;state<=RELEASE;
|
||||
if(next_elapsed>={2'd0,engine_cycles})overrun<=1;
|
||||
end
|
||||
RELEASE:if(!engine_done)begin
|
||||
state<=BUDGET;
|
||||
if(next_elapsed>={2'd0,budget})overrun<=1;
|
||||
end
|
||||
BUDGET:if(icount_tick && next_elapsed>={2'd0,budget})begin
|
||||
if(run && !overrun)begin step<=1;elapsed<=0;state<=EXECUTE;end
|
||||
else state<=IDLE;
|
||||
end
|
||||
default:state<=IDLE;
|
||||
endcase
|
||||
end
|
||||
end
|
||||
endmodule
|
||||
Reference in new issue
Block a user