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.
849 lines
22 KiB
Systemverilog
849 lines
22 KiB
Systemverilog
// Original Coco 3 Plus contributions: Copyright (c) 2026 Brian K. Holman.
|
|
// Original component notices/terms retained; see COPYRIGHT.md and LICENSING.md.
|
|
//============================================================================
|
|
// CoCo3 port to MiSTer
|
|
// Copyright (c) 2019 Alan Steremberg - alanswx, Stan Hodge - MasterS3263827
|
|
//
|
|
//
|
|
//============================================================================
|
|
|
|
module emu
|
|
(
|
|
//Master input clock
|
|
input CLK_50M,
|
|
|
|
//Async reset from top-level module.
|
|
//Can be used as initial reset.
|
|
input RESET,
|
|
|
|
//Must be passed to hps_io module
|
|
inout [48:0] HPS_BUS,
|
|
|
|
//Base video clock. Usually equals to CLK_SYS.
|
|
output CLK_VIDEO,
|
|
|
|
//Multiple resolutions are supported using different CE_PIXEL rates.
|
|
//Must be based on CLK_VIDEO
|
|
output CE_PIXEL,
|
|
|
|
//Video aspect ratio for HDMI. Most retro systems have ratio 4:3.
|
|
//if VIDEO_ARX[12] or VIDEO_ARY[12] is set then [11:0] contains scaled size instead of aspect ratio.
|
|
output [12:0] VIDEO_ARX,
|
|
output [12:0] VIDEO_ARY,
|
|
|
|
output [7:0] VGA_R,
|
|
output [7:0] VGA_G,
|
|
output [7:0] VGA_B,
|
|
output VGA_HS,
|
|
output VGA_VS,
|
|
output VGA_DE, // = ~(VBlank | HBlank)
|
|
output VGA_F1,
|
|
output [1:0] VGA_SL,
|
|
output VGA_SCALER, // Force VGA scaler
|
|
output VGA_DISABLE, // analog out is off
|
|
|
|
input [11:0] HDMI_WIDTH,
|
|
input [11:0] HDMI_HEIGHT,
|
|
output HDMI_FREEZE,
|
|
output HDMI_BLACKOUT,
|
|
output HDMI_BOB_DEINT,
|
|
|
|
`ifdef MISTER_FB
|
|
// Use framebuffer in DDRAM
|
|
// FB_FORMAT:
|
|
// [2:0] : 011=8bpp(palette) 100=16bpp 101=24bpp 110=32bpp
|
|
// [3] : 0=16bits 565 1=16bits 1555
|
|
// [4] : 0=RGB 1=BGR (for 16/24/32 modes)
|
|
//
|
|
// FB_STRIDE either 0 (rounded to 256 bytes) or multiple of pixel size (in bytes)
|
|
output FB_EN,
|
|
output [4:0] FB_FORMAT,
|
|
output [11:0] FB_WIDTH,
|
|
output [11:0] FB_HEIGHT,
|
|
output [31:0] FB_BASE,
|
|
output [13:0] FB_STRIDE,
|
|
input FB_VBL,
|
|
input FB_LL,
|
|
output FB_FORCE_BLANK,
|
|
|
|
`ifdef MISTER_FB_PALETTE
|
|
// Palette control for 8bit modes.
|
|
// Ignored for other video modes.
|
|
output FB_PAL_CLK,
|
|
output [7:0] FB_PAL_ADDR,
|
|
output [23:0] FB_PAL_DOUT,
|
|
input [23:0] FB_PAL_DIN,
|
|
output FB_PAL_WR,
|
|
`endif
|
|
`endif
|
|
|
|
output LED_USER, // 1 - ON, 0 - OFF.
|
|
|
|
// b[1]: 0 - LED status is system status OR'd with b[0]
|
|
// 1 - LED status is controled solely by b[0]
|
|
// hint: supply 2'b00 to let the system control the LED.
|
|
output [1:0] LED_POWER,
|
|
output [1:0] LED_DISK,
|
|
|
|
// I/O board button press simulation (active high)
|
|
// b[1]: user button
|
|
// b[0]: osd button
|
|
output [1:0] BUTTONS,
|
|
|
|
input CLK_AUDIO, // 24.576 MHz
|
|
output [15:0] AUDIO_L,
|
|
output [15:0] AUDIO_R,
|
|
output AUDIO_S, // 1 - signed audio samples, 0 - unsigned
|
|
output [1:0] AUDIO_MIX, // 0 - no mix, 1 - 25%, 2 - 50%, 3 - 100% (mono)
|
|
|
|
//ADC
|
|
inout [3:0] ADC_BUS,
|
|
|
|
//SD-SPI
|
|
output SD_SCK,
|
|
output SD_MOSI,
|
|
input SD_MISO,
|
|
output SD_CS,
|
|
input SD_CD,
|
|
|
|
//High latency DDR3 RAM interface
|
|
//Use for non-critical time purposes
|
|
output DDRAM_CLK,
|
|
input DDRAM_BUSY,
|
|
output [7:0] DDRAM_BURSTCNT,
|
|
output [28:0] DDRAM_ADDR,
|
|
input [63:0] DDRAM_DOUT,
|
|
input DDRAM_DOUT_READY,
|
|
output DDRAM_RD,
|
|
output [63:0] DDRAM_DIN,
|
|
output [7:0] DDRAM_BE,
|
|
output DDRAM_WE,
|
|
|
|
//SDRAM interface with lower latency
|
|
output SDRAM_CLK,
|
|
output SDRAM_CKE,
|
|
output [12:0] SDRAM_A,
|
|
output [1:0] SDRAM_BA,
|
|
inout [15:0] SDRAM_DQ,
|
|
output SDRAM_DQML,
|
|
output SDRAM_DQMH,
|
|
output SDRAM_nCS,
|
|
output SDRAM_nCAS,
|
|
output SDRAM_nRAS,
|
|
output SDRAM_nWE,
|
|
|
|
`ifdef MISTER_DUAL_SDRAM
|
|
//Secondary SDRAM
|
|
//Set all output SDRAM_* signals to Z ASAP if SDRAM2_EN is 0
|
|
input SDRAM2_EN,
|
|
output SDRAM2_CLK,
|
|
output [12:0] SDRAM2_A,
|
|
output [1:0] SDRAM2_BA,
|
|
inout [15:0] SDRAM2_DQ,
|
|
output SDRAM2_nCS,
|
|
output SDRAM2_nCAS,
|
|
output SDRAM2_nRAS,
|
|
output SDRAM2_nWE,
|
|
`endif
|
|
|
|
input UART_CTS,
|
|
output UART_RTS,
|
|
input UART_RXD,
|
|
output UART_TXD,
|
|
output UART_DTR,
|
|
input UART_DSR,
|
|
|
|
// Open-drain User port.
|
|
// 0 - D+/RX
|
|
// 1 - D-/TX
|
|
// 2..6 - USR2..USR6
|
|
// Set USER_OUT to 1 to read from USER_IN.
|
|
input [6:0] USER_IN,
|
|
output [6:0] USER_OUT,
|
|
|
|
input OSD_STATUS
|
|
);
|
|
|
|
//`define SOUND_DBG
|
|
//assign CE_PIXEL=1;
|
|
|
|
//assign {UART_RTS, UART_TXD, UART_DTR} = 0;
|
|
assign {SD_SCK, SD_MOSI, SD_CS} = 'Z;
|
|
//assign USER_OUT = '1;
|
|
assign {DDRAM_CLK, DDRAM_BURSTCNT, DDRAM_ADDR, DDRAM_DIN, DDRAM_BE, DDRAM_RD, DDRAM_WE} = 0;
|
|
assign ADC_BUS = 'Z;
|
|
//assign {SDRAM_DQ, SDRAM_A, SDRAM_BA, SDRAM_CLK, SDRAM_CKE, SDRAM_DQML, SDRAM_DQMH, SDRAM_nWE, SDRAM_nCAS, SDRAM_nRAS, SDRAM_nCS} = 'Z;
|
|
assign BUTTONS = 0;
|
|
|
|
|
|
assign VGA_F1 = 0;
|
|
//assign USER_OUT = '1;
|
|
assign LED_USER = ioctl_download;
|
|
assign LED_DISK = 0;
|
|
assign LED_POWER = 0;
|
|
|
|
assign VGA_SCALER = 0;
|
|
assign HDMI_FREEZE = 0;
|
|
assign HDMI_BLACKOUT = 0;
|
|
assign HDMI_BOB_DEINT = 0;
|
|
|
|
wire [1:0] ar = status[9:8];
|
|
|
|
assign VIDEO_ARX = (!ar) ? 12'd4 : (ar - 1'd1);
|
|
assign VIDEO_ARY = (!ar) ? 12'd3 : 12'd0;
|
|
|
|
|
|
|
|
`include "build_id.v"
|
|
`include "build_id_num.v"
|
|
|
|
localparam CONF_STR = {
|
|
"Coco 3 Plus;UART19200:9600:4800:2400:1200:300;",
|
|
// Native remembered-file records are deliberately independent of pages.
|
|
"H0FC1,CCCROMBIN,Legacy cartridge;",
|
|
"H4FC4,BINROM,Load SSC controller (4K);",
|
|
"H4FC5,BINROM,Load SSC voice (2K);",
|
|
"P1,Cartridges & Multi-Pak;",
|
|
"P1OCD,Startup slot,Slot 1,Slot 2,Slot 3,Slot 4;",
|
|
"P1-,Built-in devices move slots;",
|
|
"P1-,Changes restart the CoCo;",
|
|
"P1oBD,Slot 1,Empty,ROM file,Floppy,CoCo SDC,Sound & Speech,Orchestra90,Audio expansions,RS232;",
|
|
"H8P1FC6,CCCROMBIN,Slot 1 ROM;",
|
|
"P1oEG,Slot 2,Empty,ROM file,Floppy,CoCo SDC,Sound & Speech,Orchestra90,Audio expansions,RS232;",
|
|
"H9P1FC7,CCCROMBIN,Slot 2 ROM;",
|
|
"P1oHJ,Slot 3,Empty,ROM file,Floppy,CoCo SDC,Sound & Speech,Orchestra90,Audio expansions,RS232;",
|
|
"HAP1FC8,CCCROMBIN,Slot 3 ROM;",
|
|
"P1oKM,Slot 4,Empty,ROM file,Floppy,CoCo SDC,Sound & Speech,Orchestra90,Audio expansions,RS232;",
|
|
"HBP1FC9,CCCROMBIN,Slot 4 ROM;",
|
|
"P1-,ROM pool: 256K total;",
|
|
"P1-,Max ROM: 128K per slot;",
|
|
"HCP1-,ROM load error: size/full;",
|
|
"P2,Floppy Disks;",
|
|
"P2-,Media follows controller;",
|
|
"D3P2S2,DSK,Drive 0;",
|
|
"D3P2S3,DSK,Drive 1;",
|
|
"D3P2S4,DSK,Drive 2;",
|
|
"D3P2S5,DSK,Drive 3;",
|
|
"P3,CoCo SDC;",
|
|
"D1P3S0,DSKVHD,SDC Drive 0;",
|
|
"D1P3S1,DSKVHD,SDC Drive 1;",
|
|
"P3-,OS9 floppy mounts;",
|
|
"D1P3S2,DSK,OS9 Floppy /d0;",
|
|
"D1P3S3,DSK,OS9 Floppy /d1;",
|
|
"D1P3S4,DSK,OS9 Floppy /d3;",
|
|
"D1P3S5,DSK,OS9 Floppy /d4;",
|
|
"P4,Sound & Expansion;",
|
|
"DDP4oA,Expansion,Extended palette,Sound & Speech;",
|
|
"hDP4-,Assign SSC in Multi-Pak;",
|
|
"H5P4-,Sound & Speech not ready;",
|
|
"H6P4-,Sound & Speech ready;",
|
|
"H7P4-,Sound & Speech error;",
|
|
"HFP4-,Orchestra90 stereo enabled;",
|
|
"P4-,Audio = SSC + Orchestra90;",
|
|
"P5,Cassette;",
|
|
"P5F2,CAS,Load Cassette;",
|
|
"P5TF,Stop & Rewind;",
|
|
"P5OH,Monitor Tape Sound,No,Yes;",
|
|
"P5S6,CAS,Save Cassette;",
|
|
"P5OE,Transport,Playback / Rewind,Record;",
|
|
"P6,Machine;",
|
|
"P6OPR,Memory Size,512K,1M,2M,16M;",
|
|
"P6OO,Force Turbo,No,Yes;",
|
|
"P6o02,Turbo Speed,CoCo Ctrl,0.89 MHz,1.78 MHz,2.86 MHz,3.58 MHz,7.16 MHz,9.54 MHz;",
|
|
"P6o89,Auto Run,Off,DOS,AUTO.BAS;",
|
|
"P6RM,Cold Boot;",
|
|
"P6R0,Reset;",
|
|
"P7,Display;",
|
|
"P7O89,Aspect ratio,Original,Full Screen,Wide,[ARC1];",
|
|
"P7O35,Scandoubler Fx,None,HQ2x,CRT 25%,CRT 50%,CRT 75%;",
|
|
"P7OL,CoCo3 LC,Yes,No-(SG6=Yes);",
|
|
"P7o56,Artifact Type,MESS,Simple,NONE;",
|
|
"P7OI,Artifact Color Set,0,1;",
|
|
"P8,Input;",
|
|
"P8ON,D-Pad Joystick emu,No,Yes;",
|
|
"P8O6,Swap Joysticks,Off,On;",
|
|
"P8OS,Mouse as right joystick,Off,On;",
|
|
"P9,Advanced;",
|
|
"P9F3,BIN,Load COCO Font;",
|
|
"P9OG,Swap MiSTer Uart,RS CART,Default;",
|
|
"P9OU,Swap Uart to IO,RS IO,MiSTer;",
|
|
"P9OT,Display Debug,Off,On;",
|
|
"P9RA,Easter Egg;",
|
|
"J,Button1,Button2;",
|
|
"jn,A,B;",
|
|
"v,51;",
|
|
"V,v",{`BUILD_DATE,"-",`BUILD_NUMBER}
|
|
};
|
|
|
|
// Status bits Directory
|
|
|
|
// Status Bit Map:
|
|
// Upper Lower
|
|
// 0 1 2 3 4 5 6
|
|
// 01234567890123456789012345678901 23456789012345678901234567890123
|
|
// 0123456789ABCDEFGHIJKLMNOPQRSTUV 0123456789ABCDEFGHIJKLMNOPQRSTUV
|
|
//
|
|
|
|
// R OOOO OOR OOOTOOOOOOROOOOOOOO ooo oo oo
|
|
//F FF
|
|
//S SSSSSSS
|
|
|
|
//////////////////// CLOCKS ///////////////////
|
|
|
|
wire clk_sys;
|
|
|
|
assign clk_sys=CLK_57;
|
|
|
|
wire pll2_locked;
|
|
wire CLK_114, CLK_57, CLK_28, CLK_14;
|
|
|
|
assign VGA_DISABLE = 1'b0;
|
|
|
|
pll pll
|
|
(
|
|
.refclk(CLK_50M),
|
|
.rst(0),
|
|
.outclk_0(CLK_114),
|
|
.outclk_1(CLK_57),
|
|
.outclk_2(CLK_28),
|
|
.outclk_3(CLK_14),
|
|
.locked(pll2_locked)
|
|
);
|
|
|
|
// Cartridge ROM validity is cleared only by loss of the actual core PLL lock.
|
|
// Release synchronously after two system-clock edges, independent of CoCo reset.
|
|
(* preserve, altera_attribute = "-name SYNCHRONIZER_IDENTIFICATION FORCED_IF_ASYNCHRONOUS" *)
|
|
reg [1:0] ssc_power_release = 2'b00;
|
|
always @(posedge clk_sys or negedge pll2_locked)
|
|
if(!pll2_locked) ssc_power_release <= 2'b00;
|
|
else ssc_power_release <= {ssc_power_release[0],1'b1};
|
|
wire ssc_power_reset = !ssc_power_release[1];
|
|
|
|
///////////////////////////////////////////////////
|
|
|
|
wire [63:0] status_raw;
|
|
reg [63:0] status = 64'd0;
|
|
wire [63:0] status_accepted;
|
|
bh_mpi_config mpi_configuration(.clk(clk_sys),.reset(ssc_power_reset),
|
|
.requested(status_raw),.accepted(status_accepted),
|
|
.status_in(status_in),.status_set(status_set));
|
|
always @(negedge clk_sys) status <= status_accepted;
|
|
wire [11:0] mpi_layout=status[54:43];
|
|
wire [3:0] mpi_rom_fault;
|
|
wire mpi_rom_loading,mpi_rom_loaded;
|
|
wire [2:0] menu_rom_kind,menu_io_kind;
|
|
wire menu_ssc,menu_orchestra,menu_floppy,menu_sdc;
|
|
bh_mpi_router menu_devices(.layout(mpi_layout),.cts(status[13:12]),.scs(status[13:12]),
|
|
.rom_kind(menu_rom_kind),.io_kind(menu_io_kind),.floppy_io(),.sdc_io(),.rom_io(),.serial_io(),
|
|
.ssc_present(menu_ssc),.orchestra_present(menu_orchestra),
|
|
.floppy_present(menu_floppy),.sdc_present(menu_sdc));
|
|
function rom_picker_hidden(input [2:0] kind);
|
|
begin rom_picker_hidden=!(kind==1||kind==5||kind==6);end
|
|
endfunction
|
|
wire [63:0] status_in;
|
|
wire status_set;
|
|
|
|
wire [1:0] buttons;
|
|
wire forced_scandoubler;
|
|
wire direct_video;
|
|
|
|
wire ioctl_download;
|
|
wire [7:0] ioctl_index;
|
|
wire ioctl_wr;
|
|
wire [24:0] ioctl_addr;
|
|
wire [7:0] ioctl_data;
|
|
|
|
wire [10:0] ps2_key;
|
|
|
|
wire [31:0] joy1, joy2;
|
|
|
|
wire [15:0] joya1, joya2;
|
|
|
|
wire [21:0] gamma_bus;
|
|
|
|
assign CLK_VIDEO = clk_sys;
|
|
|
|
wire [64:0] RTC;
|
|
wire [15:0] sdram_sz;
|
|
|
|
// SD - 7 drives [4 fdc, 2 sdc and 1 cass_wr] 512 size blocks [the wd1793 translates to a 256 byte sector size]
|
|
hps_io #(.CONF_STR(CONF_STR),.PS2DIV(2400), .VDNUM(7), .BLKSZ(2)) hps_io
|
|
(
|
|
.clk_sys(clk_sys),
|
|
.HPS_BUS(HPS_BUS),
|
|
|
|
|
|
.buttons(buttons),
|
|
.status(status_raw),
|
|
.status_in(status_in),
|
|
.status_set(status_set),
|
|
|
|
.status_menumask({!menu_orchestra,1'b0,!menu_ssc,!(|mpi_rom_fault),
|
|
rom_picker_hidden(mpi_layout[11:9]),
|
|
rom_picker_hidden(mpi_layout[8:6]),
|
|
rom_picker_hidden(mpi_layout[5:3]),
|
|
rom_picker_hidden(mpi_layout[2:0]),
|
|
!status[42]||!ssc_fault,!status[42]||!ssc_ready,
|
|
!status[42]||ssc_ready,1'b1,
|
|
!menu_floppy,1'b0,!menu_sdc,1'b1}),
|
|
.forced_scandoubler(forced_scandoubler),
|
|
.RTC(RTC),
|
|
.gamma_bus(gamma_bus),
|
|
.direct_video(direct_video),
|
|
|
|
.ioctl_download(ioctl_download),
|
|
.ioctl_wr(ioctl_wr),
|
|
.ioctl_addr(ioctl_addr),
|
|
.ioctl_dout(ioctl_data),
|
|
.ioctl_index(ioctl_index),
|
|
|
|
.sdram_sz(sdram_sz),
|
|
|
|
// SD block level interface
|
|
|
|
.img_mounted(img_mounted), // signaling that new image has been mounted
|
|
.img_readonly(img_readonly), // mounted as read only. valid only for active bit in img_mounted
|
|
.img_size(img_size), // size of image in bytes.
|
|
|
|
.sd_lba(sd_lba),
|
|
.sd_blk_cnt(sd_blk_cnt), // number of blocks-1, total size ((sd_blk_cnt+1)*(1<<(BLKSZ+7))) must be <= 16384!
|
|
|
|
.sd_rd(sd_rd),
|
|
.sd_wr(sd_wr),
|
|
.sd_ack(sd_ack),
|
|
|
|
// SD byte level access. Signals for 2-PORT altsyncram.
|
|
.sd_buff_addr(sd_buff_addr),
|
|
.sd_buff_dout(sd_buff_dout),
|
|
.sd_buff_din(sd_buff_din),
|
|
.sd_buff_wr(sd_buff_wr),
|
|
|
|
.joystick_0(joy1),
|
|
.joystick_1(joy2),
|
|
|
|
.joystick_l_analog_0(joya1),
|
|
.joystick_l_analog_1(joya2),
|
|
|
|
.ps2_key(ps2_key),
|
|
|
|
|
|
.ps2_kbd_clk_out ( ps2_kbd_clk ),
|
|
.ps2_kbd_data_out ( ps2_kbd_data ),
|
|
.ps2_mouse(ps2_mouse)
|
|
);
|
|
|
|
// SD block level interface
|
|
wire [6:0] img_mounted;
|
|
wire img_readonly;
|
|
wire [63:0] img_size;
|
|
|
|
wire [31:0] sd_lba[7];
|
|
wire [5:0] sd_blk_cnt[7];
|
|
|
|
wire [6:0] sd_rd;
|
|
wire [6:0] sd_wr;
|
|
wire [6:0] sd_ack;
|
|
|
|
// SD byte level access. Signals for 2-PORT altsyncram.
|
|
wire [8:0] sd_buff_addr;
|
|
wire [7:0] sd_buff_dout;
|
|
wire [7:0] sd_buff_din[7];
|
|
wire sd_buff_wr;
|
|
|
|
|
|
wire [9:0] center_joystick_y1 = 8'd128 + joya1[15:8];
|
|
wire [9:0] center_joystick_x1 = 8'd128 + joya1[7:0];
|
|
wire [9:0] center_joystick_y2 = 8'd128 + joya2[15:8];
|
|
wire [9:0] center_joystick_x2 = 8'd128 + joya2[7:0];
|
|
wire vclk;
|
|
|
|
reg [31:0] coco_joy1 = 0;
|
|
always @(negedge clk_sys) coco_joy1 <= status[6] ? joy2 : joy1;
|
|
reg [31:0] coco_joy2 = 0;
|
|
always @(negedge clk_sys) coco_joy2 <= status[6] ? joy1 : joy2;
|
|
|
|
reg [15:0] coco_ajoy1 = 0;
|
|
always @(negedge clk_sys) coco_ajoy1 <= status[6] ? {center_joystick_x2[7:0],center_joystick_y2[7:0]} : {center_joystick_x1[7:0],center_joystick_y1[7:0]};
|
|
reg [15:0] coco_ajoy2 = 0;
|
|
always @(negedge clk_sys) coco_ajoy2 <= status[6] ? {center_joystick_x1[7:0],center_joystick_y1[7:0]} : {center_joystick_x2[7:0],center_joystick_y2[7:0]};
|
|
|
|
|
|
|
|
wire ps2_kbd_clk;
|
|
wire ps2_kbd_data;
|
|
|
|
wire [24:0] ps2_mouse;
|
|
|
|
wire hblank, vblank;
|
|
wire hs, vs;
|
|
|
|
wire pix_clk;
|
|
|
|
|
|
wire [2:0] scale = status[5:3];
|
|
wire [2:0] sl = scale ? scale - 1'd1 : 3'd0;
|
|
wire scandoubler = (scale || forced_scandoubler);
|
|
assign VGA_SL = sl[1:0];
|
|
|
|
wire freeze_sync;
|
|
|
|
|
|
video_mixer #(.GAMMA(1)) video_mixer
|
|
(
|
|
.*,
|
|
|
|
.CLK_VIDEO(clk_sys),
|
|
.ce_pix(pix_clk),
|
|
|
|
.hq2x(scale==1),
|
|
|
|
|
|
.R(r),
|
|
.G(g),
|
|
.B(b),
|
|
|
|
// Positive pulses.
|
|
.HSync(hs),
|
|
.VSync(vs),
|
|
.HBlank(hblank),
|
|
.VBlank(vblank)
|
|
);
|
|
//
|
|
//
|
|
|
|
wire Programmed_RESET_N;
|
|
wire Programmed_EE;
|
|
|
|
EE_Cold_Bt COCO3_EE_Cold_Bt (
|
|
.CLK(CLK_14),
|
|
.RESET(1'b0),
|
|
|
|
// .Display_EE(1'b0), // from MISTer subsystem
|
|
.Display_EE(easter_egg), // from MISTer subsystem
|
|
.Cold_Boot(AMW_ACK), // from AMW system
|
|
|
|
.RESET_to_COCO_N(Programmed_RESET_N), // RESET_N to the coco3 [logically AND'ed to top reset]
|
|
.EE_to_COCO(Programmed_EE) // Easter Egg to the coco3
|
|
);
|
|
|
|
|
|
wire [15:0] audio_left;
|
|
wire ssc_ready,ssc_fault;
|
|
assign AUDIO_L = { audio_left[15:14], audio_left[13] ^ (status[17] ? casdout : 1'b0),audio_left[12:0]};
|
|
//assign AUDIO_R = AUDIO_L;
|
|
assign AUDIO_S = 0;
|
|
assign AUDIO_MIX = 0;
|
|
|
|
wire [7:0] r;
|
|
wire [7:0] g;
|
|
wire [7:0] b;
|
|
|
|
wire easter_egg = status[10];
|
|
wire [6:0] probe_o;
|
|
wire [6:0] probe_i;
|
|
|
|
assign USER_OUT[6:0] = probe_o[6:0];
|
|
assign probe_i[6:0] = USER_IN[6:0];
|
|
|
|
wire [71:0] Config_Data;
|
|
|
|
assign Config_Data = {`BUILD_DATE, `BUILD_NUMBER};
|
|
|
|
coco3fpga coco3 (
|
|
// CLOCKS
|
|
|
|
.CLK_50M(CLK_50M),
|
|
.CLK_114(CLK_114),
|
|
.CLK_57(CLK_57),
|
|
.CLK_28(CLK_28),
|
|
.CLK_14(CLK_14),
|
|
|
|
.SSC_POWER_RESET(ssc_power_reset),
|
|
.SSC_MODE(status[42]),
|
|
.MPI_LAYOUT(mpi_layout),.MPI_BOOT_LOADING(status[0]),.MPI_ROM_FAULT(mpi_rom_fault),
|
|
.MPI_ROM_LOADING(mpi_rom_loading),.MPI_ROM_LOADED(mpi_rom_loaded),
|
|
.SSC_READY(ssc_ready),
|
|
.SSC_FAULT(ssc_fault),
|
|
|
|
// Reset
|
|
.COCO_RESET_N((~reset & Programmed_RESET_N) && !mpi_rom_loading),
|
|
|
|
.RED_O(r),
|
|
.GREEN_O(g),
|
|
.BLUE_O(b),
|
|
|
|
.EE_N(Programmed_EE),
|
|
.PHASE(PHASE),
|
|
|
|
.H_SYNC(hs),
|
|
.V_SYNC(vs),
|
|
.HBLANK(hblank),
|
|
.VBLANK(vblank),
|
|
.PIX_CLK(pix_clk),
|
|
// PS/2
|
|
.ps2_clk(ps2_kbd_clk),
|
|
.ps2_data(ps2_kbd_data),
|
|
|
|
.ps2_mouse(ps2_mouse),
|
|
|
|
.joy_use_dpad(digitalJoy),
|
|
|
|
.joy1(coco_joy1),
|
|
.joy2(coco_joy2),
|
|
|
|
.joya1(coco_ajoy1),
|
|
.joya2(coco_ajoy2),
|
|
|
|
.SWAP_M_J(SWAP_M_J),
|
|
|
|
// R1, L2, R2, L1
|
|
.P_SWITCH(~{coco_joy2[4],coco_joy1[5],coco_joy2[5],coco_joy1[4]}),
|
|
.SWITCH(switch),
|
|
// .SOUND_OUT(cocosound),
|
|
.SOUND_LEFT(audio_left),
|
|
.SOUND_RIGHT(AUDIO_R),
|
|
|
|
// Removed offset addition
|
|
.ioctl_addr(ioctl_addr),
|
|
.ioctl_data(ioctl_data),
|
|
.ioctl_download(ioctl_download),
|
|
.ioctl_index(ioctl_index),
|
|
.ioctl_wr(ioctl_wr),
|
|
|
|
// SDRAM Info
|
|
.sdram_sz(sdram_sz),
|
|
|
|
// SD block level interface
|
|
|
|
.img_mounted(img_mounted), // signaling that new image has been mounted
|
|
.img_readonly(img_readonly), // mounted as read only. valid only for active bit in img_mounted
|
|
.img_size(img_size), // size of image in bytes.
|
|
|
|
.sd_lba(sd_lba),
|
|
.sd_blk_cnt(sd_blk_cnt), // number of blocks-1, total size ((sd_blk_cnt+1)*(1<<(BLKSZ+7))) must be <= 16384!
|
|
|
|
.sd_rd(sd_rd),
|
|
.sd_wr(sd_wr),
|
|
.sd_ack(sd_ack),
|
|
|
|
// SD byte level access. Signals for 2-PORT altsyncram.
|
|
.sd_buff_addr(sd_buff_addr),
|
|
.sd_buff_dout(sd_buff_dout),
|
|
.sd_buff_din(sd_buff_din),
|
|
.sd_buff_wr(sd_buff_wr),
|
|
|
|
.PROBE_O(probe_o),
|
|
.PROBE_I(probe_i),
|
|
.clk_Q_out(clk_Q_out),
|
|
.casdout( cassette_cpu_sample),
|
|
.cas_relay(cas_relay),
|
|
|
|
// SDRAM
|
|
|
|
.sdram_cpu_addr(sdram_cpu_addr),
|
|
.sdram_dout(sdram_dout),
|
|
.sdram_cpu_din(sdram_cpu_din),
|
|
.sdram_cpu_req(sdram_cpu_req),
|
|
.sdram_cpu_rnw(sdram_cpu_rnw),
|
|
.sdram_cpu_ack(sdram_cpu_ack),
|
|
.sdram_cpu_ready(sdram_cpu_ready),
|
|
|
|
.sdram_vid_addr(sdram_vid_addr[24:0]),
|
|
.sdram_vid_req(sdram_vid_req),
|
|
.sdram_vid_ack(sdram_vid_ack),
|
|
.sdram_vid_ready(sdram_vid_ready),
|
|
|
|
.sdram_busy(sdram_busy),
|
|
|
|
.turbo_speed(turbo_speed),
|
|
.assigned_turbo_speed(assigned_turbo_speed),
|
|
|
|
.RTC(RTC),
|
|
|
|
.AMW_Trigger(coldboot | mpi_reset | mem_reset | mpi_rom_loaded),
|
|
// .AMW_Trigger(coldboot),
|
|
.AMW_ACK(AMW_ACK),
|
|
|
|
.F_Turbo(F_Turbo),
|
|
|
|
.Mem_Size(Mem_Size),
|
|
|
|
.AUTO_MODE(Auto_Mode),
|
|
|
|
.Config_Data(Config_Data),
|
|
.Display_Debug(display_debug),
|
|
|
|
.UART_TXD(UART_TXD),
|
|
.UART_RXD(UART_RXD),
|
|
.UART_RTS(UART_RTS),
|
|
.UART_CTS(UART_CTS),
|
|
.UART_DTR(UART_DTR),
|
|
.UART_DSR(UART_DSR)
|
|
);
|
|
|
|
// status_set is driven by the versioned layout/status normalizer.
|
|
|
|
//wire [5:0] cocosound;
|
|
|
|
wire [2:0] turbo_speed = status[34:32];
|
|
wire [2:0] assigned_turbo_speed;
|
|
wire [1:0] art = status[38:37];
|
|
wire [1:0] Auto_Mode = status[41:40];
|
|
|
|
wire AMW_ACK;
|
|
|
|
//wire cpu_speed = status[11];
|
|
|
|
wire [1:0] mpi = status[13:12];
|
|
//wire video=status[14];
|
|
wire CASS_REW_RECORD=status[14];
|
|
wire rs_swap=status[16];
|
|
wire sg4v6 = status[21];
|
|
|
|
wire PHASE = status[18];
|
|
|
|
wire coldboot = status[22];
|
|
|
|
wire F_Turbo = status[24];
|
|
wire [2:0] Mem_Size = status[27:25];
|
|
wire SWAP_M_J = status[28];
|
|
wire display_debug = status[29];
|
|
wire UART_INPUT = status[30];
|
|
wire digitalJoy = status[23];
|
|
reg [13:0] mpi_d=14'd0;
|
|
reg first_mpi_chg = 1'b0;
|
|
reg mpi_reset = 1'b0;
|
|
|
|
always @ (negedge CLK_14)
|
|
begin
|
|
mpi_d <= {mpi_layout,mpi};
|
|
mpi_reset <= 1'b0;
|
|
|
|
if (~({mpi_layout,mpi} == mpi_d))
|
|
if (~first_mpi_chg)
|
|
first_mpi_chg <= 1'b1;
|
|
else
|
|
mpi_reset <= 1'b1;
|
|
|
|
end
|
|
|
|
reg [2:0] Mem_Size_d = 3'b000;
|
|
reg first_mem_chg = 1'b0;
|
|
reg mem_reset = 1'b0;
|
|
|
|
always @ (negedge CLK_14)
|
|
begin
|
|
Mem_Size_d <= Mem_Size;
|
|
mem_reset <= 1'b0;
|
|
|
|
if (~(Mem_Size == Mem_Size_d))
|
|
if (~first_mem_chg)
|
|
first_mem_chg <= 1'b1;
|
|
else
|
|
mem_reset <= 1'b1;
|
|
|
|
end
|
|
|
|
// Set bit 9 to swap serial ports...
|
|
wire [9:0] switch = { 1'b0,UART_INPUT,art,sg4v6,rs_swap,CASS_REW_RECORD,mpi,1'b0};
|
|
|
|
|
|
wire reset = RESET | status[0] | buttons[1];
|
|
//wire reset = buttons[1];
|
|
|
|
wire clk_Q_out;
|
|
|
|
wire [24:0] sdram_cpu_addr;
|
|
//wire [31:0] sdram_ldout;
|
|
wire [15:0] sdram_dout;
|
|
wire [7:0] sdram_cpu_din;
|
|
wire sdram_cpu_req, sdram_cpu_rnw;
|
|
wire sdram_cpu_ack, sdram_vid_ack;
|
|
wire sdram_cpu_ready;
|
|
|
|
wire [24:0] sdram_vid_addr;
|
|
wire sdram_vid_req;
|
|
wire sdram_vid_ready;
|
|
wire sdram_busy;
|
|
|
|
|
|
// Research: decoded request payload is captured before the fast controller.
|
|
wire [24:0] bridge_addr;
|
|
wire [7:0] bridge_din;
|
|
wire bridge_req, bridge_rnw, bridge_ack;
|
|
cpu_sdram_bridge cpu_memory_boundary (
|
|
.clk(clk_sys), .fast_clk(CLK_114), .reset(reset), .cpu_addr(sdram_cpu_addr),
|
|
.cpu_din(sdram_cpu_din), .cpu_req(sdram_cpu_req), .cpu_rnw(sdram_cpu_rnw),
|
|
.memory_ack(bridge_ack), .cpu_ack(sdram_cpu_ack),
|
|
.memory_addr(bridge_addr), .memory_din(bridge_din),
|
|
.memory_req(bridge_req), .memory_rnw(bridge_rnw)
|
|
);
|
|
|
|
sdram_32r8w coco3_sdram
|
|
(
|
|
.*,
|
|
.init(reset),
|
|
.clk(CLK_114),
|
|
.sdram_cpu_addr(bridge_addr),
|
|
// .sdram_ldout(sdram_ldout),
|
|
.sdram_dout(sdram_dout),
|
|
.sdram_cpu_din(bridge_din),
|
|
.sdram_cpu_req(bridge_req),
|
|
.sdram_cpu_rnw(bridge_rnw),
|
|
.sdram_cpu_ack(bridge_ack),
|
|
.sdram_cpu_ready(sdram_cpu_ready),
|
|
|
|
.sdram_vid_addr(sdram_vid_addr[24:0]),
|
|
.sdram_vid_req(sdram_vid_req),
|
|
.sdram_vid_ack(sdram_vid_ack),
|
|
.sdram_vid_ready(sdram_vid_ready),
|
|
|
|
.sdram_busy(sdram_busy)
|
|
);
|
|
|
|
|
|
wire casdout;
|
|
reg cassette_cpu_sample = 1'b0;
|
|
always @(negedge clk_sys) cassette_cpu_sample <= casdout;
|
|
wire cas_relay;
|
|
wire load_tape = ioctl_index == 2;
|
|
|
|
wire [15:0] ram_addr;
|
|
wire [7:0] ram_data_o;
|
|
wire ram_rd;
|
|
wire ram_wr;
|
|
wire [15:0] ram_ad_buf;
|
|
|
|
always @(posedge clk_sys)
|
|
begin
|
|
ram_wr <= ~(ioctl_wr & load_tape);
|
|
if (ioctl_download)
|
|
ram_ad_buf <= ioctl_addr[15:0];
|
|
else
|
|
ram_ad_buf <= ram_addr;
|
|
end
|
|
|
|
COCO_SRAM CC3_CAS1(
|
|
.CLK(clk_sys),
|
|
.ADDR(ram_ad_buf),
|
|
.R_W(ram_wr),
|
|
.DATA_I(ioctl_data),
|
|
.DATA_O(ram_data_o)
|
|
);
|
|
|
|
|
|
cassette cassette(
|
|
.clk(clk_sys),
|
|
.Q(clk_Q_out),
|
|
|
|
.rewind(status[15]|~ram_wr),
|
|
.en(cas_relay),
|
|
|
|
.sdram_addr(ram_addr),
|
|
.sdram_data(ram_data_o),
|
|
// .sdram_rd(ram_rd), // Not connected for sram
|
|
|
|
.data(casdout)
|
|
);
|
|
endmodule
|