From 755369c3f7861a018a314b27adfd421b2bc68b9e Mon Sep 17 00:00:00 2001 From: Alan Steremberg Date: Sat, 25 Dec 2021 15:40:40 -0800 Subject: [PATCH] fixed cassette and added dpad --- CoCo3.qsf | 5 +-- CoCo3.sv | 9 ++++-- rtl/coco3fpga.sv | 79 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 69 insertions(+), 24 deletions(-) diff --git a/CoCo3.qsf b/CoCo3.qsf index 085ea0e..e3945ce 100644 --- a/CoCo3.qsf +++ b/CoCo3.qsf @@ -13,7 +13,7 @@ set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top set_global_assignment -name PARTITION_FITTER_PRESERVATION_LEVEL PLACEMENT_AND_ROUTING -section_id Top set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top -set_global_assignment -name LAST_QUARTUS_VERSION "17.0.2 Lite Edition" +set_global_assignment -name LAST_QUARTUS_VERSION "17.0.2 Lite Edition" set_global_assignment -name GENERATE_RBF_FILE ON set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files @@ -63,4 +63,5 @@ set_global_assignment -name SEED 1 source sys/sys.tcl source sys/sys_analog.tcl source files.qip -set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top + +set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top \ No newline at end of file diff --git a/CoCo3.sv b/CoCo3.sv index 597db49..e2d8374 100644 --- a/CoCo3.sv +++ b/CoCo3.sv @@ -225,6 +225,7 @@ localparam CONF_STR = { //P2O?,Force Disk 0 DS,Off,On;" //P2O?,Force Disk 1 DS,Off,On;" "-;", + "ON,D-Pad Joystick emu,No,Yes;", "O6,Swap Joysticks,Off,On;", "RA,Easter Egg;", "-;", @@ -468,9 +469,10 @@ coco3fpga coco3 ( .ps2_clk(ps2_kbd_clk), .ps2_data(ps2_kbd_data), + .joy_use_dpad(digitalJoy), -// .joy1(coco_joy1), -// .joy2(coco_joy2), + .joy1(coco_joy1), + .joy2(coco_joy2), .joya1(coco_ajoy1), .joya2(coco_ajoy2), @@ -561,6 +563,7 @@ wire PHASE = status[18]; wire coldboot = status[22]; +wire digitalJoy = status[23]; reg [2:0] mpi_d = 2'b00; reg first_mpi_chg = 1'b0; reg mpi_reset = 1'b0; @@ -653,7 +656,7 @@ cassette cassette( .clk(clk_sys), .Q(clk_Q_out), - .rewind(status[15]), + .rewind(status[15]|~ram_wr), .en(cas_relay), .sdram_addr(ram_addr), diff --git a/rtl/coco3fpga.sv b/rtl/coco3fpga.sv index c0701e2..b09b4c4 100644 --- a/rtl/coco3fpga.sv +++ b/rtl/coco3fpga.sv @@ -129,8 +129,14 @@ output [15:0] SOUND_RIGHT, // Needs removal.... ??? input [3:0] PADDLE_CLK, input [3:0] P_SWITCH, -input [15:0] joya1, -input [15:0] joya2, + // joystick input + // digital for buttons + input [15:0] joy1, + input [15:0] joy2, + // analog for position + input [15:0] joya1, + input [15:0] joya2, + input joy_use_dpad, // Config Static switches input [9:0] SWITCH, @@ -439,12 +445,6 @@ wire RX_CLK2; wire [7:0] DATA_RS232; reg [2:0] ROM_BANK; wire SLOT3_HW; -wire UART51_TXD; -wire UART51_RXD; -wire UART51_RTS; -wire UART51_DTR; -wire UART50_RXD; -wire UART50_RTS; reg [9:0] SEC; reg TICK0; reg TICK1; @@ -791,7 +791,7 @@ assign LEDG[3] = FLASH_CE_S; assign LEDG[4] = (ADDRESS == 16'hFF84); // SDRAM assign LEDG[5] = 1'b0; assign LEDG[6] = 1'b0; // SD Card activity -assign LEDG[7] = !UART50_RXD; +assign LEDG[7] = 1'b0; // SRH DE2-115 Extra Green LED is unused and off assign LEDG[8] = 1'b0; @@ -2667,12 +2667,6 @@ assign CPU_IRQ_N = ( GIME_IRQ | (HSYNC1_IRQ_N & VSYNC1_IRQ_N)) assign CPU_FIRQ_N = ( GIME_FIRQ | (CART1_FIRQ_N)) & (!GIME_FIRQ | (TIMER3_FIRQ_N & HSYNC3_FIRQ_N & VSYNC3_FIRQ_N & KEY3_FIRQ_N & CART3_FIRQ_N)); -//Swap the DW and RS232 ports on connectors -assign UART51_RXD = (!SWITCH[9]) ? OPTRXD: // Switch 9 off - DE1RXD; // Switch 9 on -assign UART50_RXD = (!SWITCH[9]) ? DE1RXD: // Switch 9 off - OPTRXD; // Switch 9 on -assign DE1TXD = UART51_TXD; assign OPTTXD = 1'b0; // Timer @@ -4097,26 +4091,73 @@ assign SOUND_RIGHT = {ORCH_RIGHT, ORCH_RIGHT_EXT} + {SOUND, 8'h00}; Joystick direction code buttons are handled below in the keyboard routines */ +// the DAC isn't really a DAC but represents the DAC chip on the schematic. +// All the signals have been digitized before it gets here. + +reg [15:0] dac_joya1; +reg [15:0] dac_joya2; + +always @(clk_sys) begin + + if (joy_use_dpad) + begin + dac_joya1[15:8] <= 8'd128; + dac_joya1[7:0] <= 8'd128; + + dac_joya2[15:8] <= 8'd128; + dac_joya2[7:0] <= 8'd128; + + if (joy1[0]) // right + dac_joya1[15:8] <= 8'd240; + + if (joy1[1]) // left + dac_joya1[15:8] <= 8'd16; + + if (joy1[2]) // down + dac_joya1[7:0] <= 8'd240; + + if (joy1[3]) // up + dac_joya1[7:0] <= 8'd16; + + if (joy2[0]) // right + dac_joya2[15:8] <= 8'd240; + + if (joy2[1]) // left + dac_joya2[15:8] <= 8'd16; + + if (joy2[2]) // down + dac_joya2[7:0] <= 8'd240; + + if (joy2[3]) // upimg_mounted + dac_joya2[7:0] <= 8'd16; + end + else + begin + dac_joya1 <= joya1; + dac_joya2 <= joya2; + end +end + always @(posedge clk_sys) begin case (SEL) 2'b00: - if (joya2[15:10] > DTOA_CODE) + if (dac_joya2[15:10] > DTOA_CODE) JSTICK<=1; else JSTICK<=0; 2'b01: - if (joya2[7:2] > DTOA_CODE) + if (dac_joya2[7:2] > DTOA_CODE) JSTICK<=1; else JSTICK<=0; 2'b10: - if (joya1[15:10] > DTOA_CODE) + if (dac_joya1[15:10] > DTOA_CODE) JSTICK<=1; else JSTICK<=0; 2'b11: - if (joya1[7:2] > DTOA_CODE) + if (dac_joya1[7:2] > DTOA_CODE) JSTICK<=1; else JSTICK<=0;