Timing fixes, Video mode fixes, Sound cleanup, and enabling RS-232 to physical SNAC pins.

1.	Overlay support for the detection of no rom loading on power up AND misc
    debugging. [done]
2.	Fix video HSCREEN 4 mode which is used in some demos and rs-232 terminal
	programs. [done]
3.	Reworked sound output to faithfully emulate the analog muxing in the coco.
	[done]
4.	Routing RS-232 tx/rx lines to the SNAC port for initial serial debugging
	of Fuji-Net interface. [done - untested]
This commit is contained in:
shodge12 committed 2026-10-02 00:49:54 -04:00
1 parent 77ee8b8c8c
commit ede23da6b0
9 files changed
+750 -105

No files matched your search

+251 -56
View File
@@ -87,9 +87,9 @@ input COCO_RESET_N,
// Video
output reg [7:0] RED,
output reg [7:0] GREEN,
output reg [7:0] BLUE,
output reg [7:0] RED_O,
output reg [7:0] GREEN_O,
output reg [7:0] BLUE_O,
output reg H_SYNC,
output reg V_SYNC,
@@ -106,6 +106,8 @@ input ps2_data,
input [24:0] ps2_mouse,
input Display_Debug,
// RS-232
output UART_TXD,
input UART_RXD,
@@ -170,7 +172,8 @@ inout [7:0] GPIO,
// Misc
input EE_N,
input PHASE,
output [31:0] PROBE,
output [6:0] PROBE_O,
input [6:0] PROBE_I,
// Cassette Input linkage
output clk_Q_out,
@@ -685,18 +688,28 @@ rtc #(50000000) CC3_rtc(
// Probe's defined
//assign PROBE[6:0] = {CART1_POL, CART1_BUF_RESET_N, CART1_FIRQ_STAT_N, CART1_CLK_N, CART1_FIRQ_N, RESET_N, PH_2};
//assign PROBE[7:0] = {1'b0, CART1_POL, CART1_FIRQ_N, CART1_FIRQ_BUF[0], CART1_CLK_N_D, CART1_FIRQ_RESET_N, CART1_CLK_N, PH_2};
assign PROBE[7:0] = {1'b0, TMR_CLK, DATA_IN[5], RST_FF93_N_SFT[0], RST_FF93_N, !TIMER3_FIRQ_N, VSYNC_INT_N, TIMER_INT_N};
assign PROBE[15:8] = 8'h00;
assign PROBE[23:16] = 8'h00;
//assign PROBE[31:24] = {3'b000, DATA_OUT[3], MOTOR, DRIVE_SEL_EXT[0], HDD_EN, ADDRESS[0]};
assign PROBE[31:24] = {8'h00};
assign PROBE_O[6:0] = {TMR_CLK, DATA_IN[5], RST_FF93_N_SFT[0], RST_FF93_N, !TIMER3_FIRQ_N, 1'b1, UART_TXD};
assign clk_sys = CLK_57;
assign BUTTON_N[3:0] = {COCO_RESET_N, 2'b1,EE_N};
wire UART_TXD_I;
wire UART_RXD_I;
assign UART_TXD = SWITCH[4]? coco_rs232_out:
UART_TXD_I;
assign uart_input = SWITCH[8]? PROBE_I[1]:
UART_RXD;
wire uart_input;
assign coco_rs232_in = uart_input;
assign UART_RXD_I = uart_input;
/*****************************************************************************
* RAM signals
@@ -771,9 +784,9 @@ assign CART_SEL = (ADDRESS[15:8] == 8'b1
//11 32 External
assign FLASH_ADDRESS = ENA_DSK ? {9'b000000100, ADDRESS[12:0]}: //8K Disk BASIC 8K Slot 4
ENA_DISK2 ? {9'b000000100, ADDRESS[12:0]}: //[maps to same disk rom]
({ENA_PAK, ROM[1]} == 2'b10) ? {5'b00000,ROM_BANK, ADDRESS[13:0]}: //16K External R CART ROM
assign FLASH_ADDRESS = ENA_DSK ? {9'b000000000, ADDRESS[12:0]}: //8K Disk BASIC 8K Slot 4
ENA_DISK2 ? {9'b000000000, ADDRESS[12:0]}: //[maps to same disk rom]
({ENA_PAK, ROM[1]} == 2'b10) ? {5'b00000,ROM_BANK, ADDRESS[13:0]}: //16K External R CART ROM
({ENA_PAK, ROM} == 3'b111) ? {4'b0000,ROM_BANK, ~ADDRESS[14], ADDRESS[13:0]}: //32K External R CART ROM
{7'b0000000,ADDRESS[14:0]}; //32K Internal COCO3 ROM
@@ -804,6 +817,25 @@ 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;
reg rom_loaded = 1'b0;
always @(negedge clk_sys)
begin
if({ioctl_addr[14], COCO3_ROM_WRITE} == 2'b11)
rom_loaded <= 1'b1;
end
// A decision.
// Looking at this logic it is fairly obvious that the 8Kx8 ROM is not needed.
// Physically (bus wise) it sits in the same place as the CART rom and is obviously
// smaller. I have made these changes at least twice during the development of
// this code. While it works and saves the resources of a 8kx8 sram, it does not
// work well from a systems perspective. With only 1 rom, when you load a cart
// then go back to a slot 2/4 disk system you have no os. So now you have to load
// boot1.bin as a cart from slot 3, then change back to 2/4 to restore dos. No real
// way to fix it. I could put dos at the top 8K of the 128K, then only 128K carts
// would cause a issue. But there still is an issue which would need to be explained.
// I choose not, along with this explanation why. SRH 5/29/26
COCO_ROM_32K CC3_ROM(
.ADDR(FLASH_ADDRESS[14:0]),
@@ -814,6 +846,8 @@ COCO_ROM_32K CC3_ROM(
.WRITE(COCO3_ROM_WRITE)
);
// DOS Cart for slot 2/4
COCO_ROM_8K CC3_DISK_ROM(
.ADDR(FLASH_ADDRESS[12:0]),
.DATA(COCO3_DISK_ROM_DATA),
@@ -824,10 +858,9 @@ COCO_ROM_8K CC3_DISK_ROM(
);
assign FLASH_DATA = ENA_PAK ? CART_DATA:
(FLASH_ADDRESS[15] == 1'b0) ? COCO3_ROM_DATA:
(FLASH_ADDRESS[15:13] == 3'b100) ? COCO3_DISK_ROM_DATA:
8'b00000000;
assign FLASH_DATA = ENA_PAK ? CART_DATA:
(ENA_DSK || ENA_DISK2) ? COCO3_DISK_ROM_DATA:
COCO3_ROM_DATA;
COCO_ROM_CART CC3_ROM_CART(
@@ -863,7 +896,10 @@ assign SDC_EN_CS = ({MPI_SCS, ADDRESS[15:5]} == 13'b0111111111010) ? 1'b1:
1'b0;
`endif
assign RS232_EN = ({MPI_SCS, ADDRESS[15:2]} == 16'b0011111111011010) ? 1'b1: //FF68-FF6B - Now in slot 1
//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
@@ -1134,13 +1170,13 @@ assign DATA_REG2 = !DDR2 ? DD_REG2:
KEY_COLUMN;
assign DATA_REG3 = !DDR3 ? DD_REG3:
{DTOA_CODE, 1'b1, casdout};
{DTOA_CODE, coco_rs232_out, casdout};
// A 0 in the DDR makes that pin an input
assign BIT3 = !DD_REG4[3] ? 1'b0:
CSS;
assign DATA_REG4 = !DDR4 ? DD_REG4:
{VDG_CONTROL, BIT3, KEY_COLUMN[6], SBS, 1'b1};
{VDG_CONTROL, BIT3, KEY_COLUMN[6], SBS, coco_rs232_in};
/********************************************************************************
* GPIO
*********************************************************************************/
@@ -2642,6 +2678,9 @@ end
//end
reg sync_rst1;
reg coco_rs232_out;
wire coco_rs232_in;
wire coco_rs232_cd;
// Most of the latches for settings
always @ (negedge clk_sys or negedge RESET_N)
@@ -2667,6 +2706,7 @@ begin
SEL[1] <= 1'b0;
// FF20
DD_REG3 <= 8'h00;
coco_rs232_out <= 1'b0;
DTOA_CODE <= 6'b000000;
SOUND_DTOA <= 6'b000000;
// BBTXD <= 1'b0;
@@ -2855,8 +2895,9 @@ begin
case ({SOUND_EN,SEL})
3'b100:
SOUND_DTOA <= DTOA_CODE;
3'b111:
SOUND_DTOA <= 6'b000000;
// This is still no sound as it just holds the previous DTOA Value
// 3'b111:
// SOUND_DTOA <= 6'b000000;
endcase
if(!RW_N)
@@ -2931,6 +2972,7 @@ begin
DD_REG3 <= DATA_OUT;
else
begin
coco_rs232_out <= DATA_OUT[1];
DTOA_CODE <= DATA_OUT[7:2];
end
end
@@ -3511,7 +3553,12 @@ end
// Internal Sound generation
//assign SOUND = {SBS, 7'b0000000} + {SOUND_DTOA, SOUND_DTOA[5:4]};
assign SOUND = {SBS, SOUND_DTOA, SOUND_DTOA[5]};
//assign SOUND = {SBS, SOUND_DTOA, SOUND_DTOA[5]};
//assign SOUND = {SBS || SOUND_DTOA[5], SOUND_DTOA[4:0], SOUND_DTOA[1:0]};
// Ver 3 of the sound arch
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};
@@ -3817,24 +3864,40 @@ wire PIX_CLK_D;
// The VBOARDER is used as a VBLANK as is [inverted]
reg [3:0] MISTER_HBLANK_D;
assign HBLANK = MISTER_HBLANK_D[2]; // This is 2 clock delay on the ~HBORDER...
assign HBLANK_ORG = MISTER_HBLANK_D[2]; // This is 2 clock delay on the ~HBORDER...
// KEY: 01/14/26
//assign HBLANK = MISTER_HBLANK_D[2]; // This is 2 clock delay on the ~HBORDER...
//assign VBLANK = ~VBORDER;
wire VBLANK_PRIME;
assign VBLANK = ~VBLANK_PRIME;
assign RED[3:0] = RED[7:4];
assign GREEN[3:0] = GREEN[7:4];
assign BLUE[3:0] = BLUE[7:4];
assign VBLANK_ORG = ~VBLANK_PRIME;
// KEY: 01/14/26
//assign VBLANK = ~VBLANK_PRIME;
assign RED_ORG[3:0] = RED_ORG[7:4];
assign GREEN_ORG[3:0] = GREEN_ORG[7:4];
assign BLUE_ORG[3:0] = BLUE_ORG[7:4];
// KEY: 01/14/26
//assign RED[3:0] = RED[7:4];
//assign GREEN[3:0] = GREEN[7:4];
//assign BLUE[3:0] = BLUE[7:4];
// Video DAC
always @ (negedge clk_sys)
begin
PIX_CLK_D <= PIX_CLK;
if (PIX_CLK == 1'b1 & PIX_CLK_D == 1'b0)
// PIX_CLK_D <= PIX_CLK;
// if (PIX_CLK == 1'b1 & PIX_CLK_D == 1'b0)
// KEY: 01/14/26
PIX_CLK_D <= PIX_CLK_ORG;
if (PIX_CLK_ORG == 1'b1 & PIX_CLK_D == 1'b0)
begin
COLOR_BUF <= COLOR; // Delay COLOR by 1 clock cycle to align with 256 Color SRAM
H_SYNC <= !H_SYNC_N; // Delay H_SYNC by 1 clock cycle
V_SYNC <= !V_SYNC_N; // Delay V_SYNC by 1 clock cycle
H_SYNC_ORG <= !H_SYNC_N; // Delay H_SYNC by 1 clock cycle
V_SYNC_ORG <= !V_SYNC_N; // Delay V_SYNC by 1 clock cycle
// H_SYNC <= !H_SYNC_N; // Delay H_SYNC by 1 clock cycle
// V_SYNC <= !V_SYNC_N; // Delay V_SYNC by 1 clock cycle
// KEY: 01/14/26
// RED[3:0] <= 4'B0000;
// GREEN[3:0] <= 4'B0000;
// BLUE[3:0] <= 4'B0000;
@@ -3846,27 +3909,48 @@ begin
if(COLOR_BUF[8])
begin
{RED[7], GREEN[7], BLUE[7], RED[6], GREEN[6], BLUE[6], RED[5], GREEN[5], BLUE[5], RED[4], GREEN[4], BLUE[4]} <= VDAC_OUT[11:0];
// KEY: 01/14/26
// {RED[7], GREEN[7], BLUE[7], RED[6], GREEN[6], BLUE[6], RED[5], GREEN[5], BLUE[5], RED[4], GREEN[4], BLUE[4]} <= VDAC_OUT[11:0];
{RED_ORG[7], GREEN_ORG[7], BLUE_ORG[7], RED_ORG[6], GREEN_ORG[6], BLUE_ORG[6], RED_ORG[5], GREEN_ORG[5], BLUE_ORG[5], RED_ORG[4], GREEN_ORG[4], BLUE_ORG[4]} <= VDAC_OUT[11:0];
end
else
begin
RED[7] <= PALETTE[COLOR_BUF[4:0]][11];
RED[6] <= PALETTE[COLOR_BUF[4:0]][8];
RED[5] <= PALETTE[COLOR_BUF[4:0]][5];
RED[4] <= PALETTE[COLOR_BUF[4:0]][2];
GREEN[7] <= PALETTE[COLOR_BUF[4:0]][10];
GREEN[6] <= PALETTE[COLOR_BUF[4:0]][7];
GREEN[5] <= PALETTE[COLOR_BUF[4:0]][4];
GREEN[4] <= PALETTE[COLOR_BUF[4:0]][1];
BLUE[7] <= PALETTE[COLOR_BUF[4:0]][9];
BLUE[6] <= PALETTE[COLOR_BUF[4:0]][6];
BLUE[5] <= PALETTE[COLOR_BUF[4:0]][3];
BLUE[4] <= PALETTE[COLOR_BUF[4:0]][0];
// KEY: 01/14/26
// RED[7] <= PALETTE[COLOR_BUF[4:0]][11];
// RED[6] <= PALETTE[COLOR_BUF[4:0]][8];
// RED[5] <= PALETTE[COLOR_BUF[4:0]][5];
// RED[4] <= PALETTE[COLOR_BUF[4:0]][2];
// GREEN[7] <= PALETTE[COLOR_BUF[4:0]][10];
// GREEN[6] <= PALETTE[COLOR_BUF[4:0]][7];
// GREEN[5] <= PALETTE[COLOR_BUF[4:0]][4];
// GREEN[4] <= PALETTE[COLOR_BUF[4:0]][1];
// BLUE[7] <= PALETTE[COLOR_BUF[4:0]][9];
// BLUE[6] <= PALETTE[COLOR_BUF[4:0]][6];
// BLUE[5] <= PALETTE[COLOR_BUF[4:0]][3];
// BLUE[4] <= PALETTE[COLOR_BUF[4:0]][0];
// end
// RED[4] = RED[6];
// GREEN[4] = GREEN[6];
// BLUE[5] = BLUE[7];
// BLUE[4] = BLUE[6];
RED_ORG[7] <= PALETTE[COLOR_BUF[4:0]][11];
RED_ORG[6] <= PALETTE[COLOR_BUF[4:0]][8];
RED_ORG[5] <= PALETTE[COLOR_BUF[4:0]][5];
RED_ORG[4] <= PALETTE[COLOR_BUF[4:0]][2];
GREEN_ORG[7] <= PALETTE[COLOR_BUF[4:0]][10];
GREEN_ORG[6] <= PALETTE[COLOR_BUF[4:0]][7];
GREEN_ORG[5] <= PALETTE[COLOR_BUF[4:0]][4];
GREEN_ORG[4] <= PALETTE[COLOR_BUF[4:0]][1];
BLUE_ORG[7] <= PALETTE[COLOR_BUF[4:0]][9];
BLUE_ORG[6] <= PALETTE[COLOR_BUF[4:0]][6];
BLUE_ORG[5] <= PALETTE[COLOR_BUF[4:0]][3];
BLUE_ORG[4] <= PALETTE[COLOR_BUF[4:0]][0];
end
RED[4] = RED[6];
GREEN[4] = GREEN[6];
BLUE[5] = BLUE[7];
BLUE[4] = BLUE[6];
RED_ORG[4] = RED_ORG[6];
GREEN_ORG[4] = GREEN_ORG[6];
BLUE_ORG[5] = BLUE_ORG[7];
BLUE_ORG[4] = BLUE_ORG[6];
end
end
@@ -3874,7 +3958,9 @@ end
VDAC VDAC_inst (
.data ( {4'h0,PALETTE[0][11:0]} ),
.rdaddress ( COLOR[7:0] ),
.rdclock ( PIX_CLK ),
.rdclock ( PIX_CLK_ORG ),
// .rdclock ( PIX_CLK ),
// KEY: 01/14/26
.wraddress ( DATA_OUT ),
.wrclock ( clk_sys ),
.wren ( VDAC_EN & PH_2 ),
@@ -3890,11 +3976,35 @@ wire VBLANK_1;
wire HBLANK_1;
wire double, buff_bank;
//
// Sync to pos edge of ck_sys
// Key: 01/14/26
//
reg HBLANK_ORG, VBLANK_ORG, PIX_CLK_ORG, H_SYNC_ORG, V_SYNC_ORG;
reg [7:0] RED_ORG;
reg [7:0] GREEN_ORG;
reg [7:0] BLUE_ORG;
always @ (posedge clk_sys)
begin
HBLANK <= HBLANK_ORG;
VBLANK <= VBLANK_ORG;
PIX_CLK <= PIX_CLK_ORG;
H_SYNC <= H_SYNC_ORG;
V_SYNC <= V_SYNC_ORG;
RED <= RED_ORG;
GREEN <= GREEN_ORG;
BLUE <= BLUE_ORG;
end
// Video timing and modes
COCO3VIDEO MISTER_COCOVID(
// Clocks / RESET
.MASTER_CLK(clk_sys),
.PIX_CLK(PIX_CLK), //14.32 MHz = 69.3 nS
.PIX_CLK(PIX_CLK_ORG), //14.32 MHz = 69.3 nS
.RESET_N(RESET_N),
// Video Out
@@ -3952,9 +4062,15 @@ COCO3VIDEO MISTER_COCOVID(
.HBORDER(HBORDER),
.VBORDER(VBORDER),
.art(SWITCH[7:6])
.art(SWITCH[7:6]),
.PIXEL_COUNT(PIXEL_COUNT),
.LINE(LINE)
);
reg [10:0] PIXEL_COUNT;
reg [9:0] LINE;
parameter SHDOW_FONT_LOCK_REG = 16'hfff0;
parameter SHDOW_FONT_DATA_REG = 16'hfff1;
@@ -4066,7 +4182,9 @@ coco3_Char_ROM coco3_Char_ROM(
.WE(((ioctl_index[5:0] == 6'd3) & ioctl_wr) | Font_ROM_Mach_WE), // Can be just Font_ROM_Mach_WE if no MISTer
.ADDR_W(Font_ROM_Adrs_Buf),
.DATA_W(Font_ROM_Data_Buf),
.RD_CLK(PIX_CLK),
.RD_CLK(PIX_CLK_ORG),
// .RD_CLK(PIX_CLK),
// KEY: 01/14/26
.ADDR_R({(COCO1 ^ Font_ROM_Upper_Select), font_adrs}),
.DATA_R(font_data)
);
@@ -4114,8 +4232,8 @@ glb6551 RS232(
.CS({1'b0, RS232_EN}),
.RW_N(RW_N),
.RS(ADDRESS[1:0]),
.TXDATA_OUT(UART_TXD),
.RXDATA_IN(UART_RXD),
.TXDATA_OUT(UART_TXD_I),
.RXDATA_IN(UART_RXD_I),
.RTS(UART_RTS),
.CTS(UART_CTS),
.DCD(1'b1),
@@ -4150,5 +4268,82 @@ Cassette_Write CoCo3_Cassette_Write(
.sd_buff_wr(sd_buff_wr)
);
wire [7:0] RED;
wire [7:0] GREEN;
wire [7:0] BLUE;
assign RED_O = RED | CN_R;
assign GREEN_O = GREEN;
assign BLUE_O = BLUE;
wire [159:0]NOrom1;
wire [159:0]NOrom2;
reg [7:0] CN_R ;
reg pixel_clk_d, clk_7Mhz;
always @ (negedge clk_sys)
begin
pixel_clk_d <= PIX_CLK_ORG;
if (PIX_CLK_ORG==1'b1 && pixel_clk_d==1'b0)
clk_7Mhz <= !clk_7Mhz;
end
ovo #(.COLS(32), .LINES(23)) NOROMOVO
(
.i_r(8'd0),
.i_g(8'd0),
.i_b(8'd0),
.i_clk(PIX_CLK_ORG),
.i_Hcount({1'b0, PIXEL_COUNT[10:1]}),
.i_VCount(LINE),
.o_r(CN_R),
.ena(Display_Debug || ((!rom_loaded) && SEC[0])),
.in0(NOrom1),
.in1(NOrom2)
);
assign NOrom2 = {
{32{5'b10000}}
};
assign NOrom1 = {
//{17{5'b10000}},
5'b10000, // space
5'b11011, // N
5'b11100, // O
5'b10000, // space
5'b11101, // R
5'b11100, // O
5'b11110, // M
5'b10000, // space
5'b10011, // -
5'b10000, // space
5'b11011, // N
5'b11100, // O
5'b10000, // space
5'b11101, // R
5'b11100, // O
5'b11110, // M
5'b10000, // space
5'b11011, // N
5'b11100, // O
5'b10000, // space
5'b11101, // R
5'b11100, // O
5'b11110, // M
5'b10000, // space
5'b10011, // -
5'b10000, // space
5'b11011, // N
5'b11100, // O
5'b10000, // space
5'b11101, // R
5'b11100, // O
5'b11110 // M
};
endmodule