Skip to content

Commit

Permalink
Ntsc fix (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
vossstef authored Oct 24, 2024
1 parent 587149d commit 0572db1
Show file tree
Hide file tree
Showing 14 changed files with 519 additions and 195 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The C64Nano is a port of some [MiST](https://github.com/mist-devel/mist-board/wi
| --- | - | - |-|
| [Tang Nano 20k](https://wiki.sipeed.com/nano20k) | [GW2AR](https://www.gowinsemi.com/en/product/detail/38/) | X |- |
| [Tang Primer 25K](https://wiki.sipeed.com/hardware/en/tang/tang-primer-25k/primer-25k.html) | [GW5A-25](https://www.gowinsemi.com/en/product/detail/60/) | X |no Dualshock 2, no Retro DB9 Joystick |
| [Tang Mega 60k](https://wiki.sipeed.com/hardware/en/tang/tang-mega-60k/mega-60k.html)|[GW5AT-60](https://www.gowinsemi.com/en/product/detail/60/)| planned |- |
| [Tang Mega 60k NEO](https://wiki.sipeed.com/hardware/en/tang/tang-mega-60k/mega-60k.html)|[GW5AT-60](https://www.gowinsemi.com/en/product/detail/60/)| planned |- |
| [Tang Mega 138k Pro](https://wiki.sipeed.com/hardware/en/tang/tang-mega-138k/mega-138k-pro.html)|[GW5AST-138](https://www.gowinsemi.com/en/product/detail/60/) | X |- |


Expand Down Expand Up @@ -87,10 +87,12 @@ Cartridge ROM can be loaded via OSD file selection.<br>
Copy a *.CRT to your sdcard and rename it to **c64crt.crt** as default boot cartridge ROM.<br>
Prevent the cartridge load at boot by OSD CRT selection **No Disk** , **Save settings** and System **Cold Boot**.<br>
> [!TIP]
**Detach Cartridge** by OSD CRT selection **No Disk** and System **Cold Boot**.<br>
**Detach Cartridge** by OSD CRT selection :<br>
```temporary``` **Cartridge unload & Reset**
```permanent``` **No Disk**, **Save settings** and System **Cold Boot**.<br>

> [!IMPORTANT]
> Be aware that most Freezer Card CRT require to use the standard C64 Kernal and the standard C1541 CBM DOS. Buildin DolphinDOS Speedloader isn't compatible.
> Be aware that some Freezer Card CRT require to use the standard C64 Kernal and the standard C1541 CBM DOS. Buildin DolphinDOS Speedloader isn't compatible.
## BASIC Program Loader (.PRG)
A BASIC Program *.PRG file can be loaded via OSD file selection.<br>
Expand Down Expand Up @@ -185,16 +187,19 @@ invoke by F12 keypress<br>
* geoRAM activation
* Loader (CRT/PRG/BIN/TAP/FLT) file selection<br>
* Joystick Port Swap
* Cartridge unload

## Gamecontrol support
legacy single D9 Digital Joystick. OSD: **Retro D9**<br>
Atari ST type of Joystick 2nd button supported using a MiSTeryNano shield.
Atari ST type of Joystick 2nd button supported using a MiSTeryNano shield.
Don't configure configure e.g. [ArcadeR](https://retroradionics.com) for C64 mode rather than<br> normal digital 2nd button mode (2nd trigger button connect signal to ground)

or<br>
USB Joystick(s). OSD: **USB #1 Joy** or **USB #2 Joy** <br>
Also [RII Mini Keyboard i8](http://www.riitek.com/product/220.html) left Multimedia Keys are active if **USB #1 Joy** selected.

or<br>
Gamepad Stick as Joystick. OSD: **DualShock 2**

<br>left **stick digital** for Move and **square** , **cross** and **circle** Button for 3 Trigger buttons
or following **Pad** controls:<br>
| Buttons | - | - |
Expand Down
1 change: 1 addition & 0 deletions build_tm138k.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ set_option -show_all_warn 0
set_option -rw_check_on_ram 0
set_option -user_code 00000001
set_option -bit_security 0
set_option -rpt_auto_place_io_info 1

#run syn
run all
5 changes: 5 additions & 0 deletions build_tn20k.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ set_option -show_all_warn 0
set_option -rw_check_on_ram 0
set_option -user_code 00000001
set_option -bit_security 0
set_option -rpt_auto_place_io_info 1
#set_option -timing_driven 1
#set_option -route_option 0
#set_option -place_option 0
#add_file -type gao -disable "src/test.gao"

#run syn
run all
1 change: 1 addition & 0 deletions build_tp25k.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ set_option -show_all_warn 0
set_option -rw_check_on_ram 0
set_option -user_code 00000001
set_option -bit_security 0
set_option -rpt_auto_place_io_info 1

#run syn
run all
6 changes: 3 additions & 3 deletions src/c1541/mist_sd_card.sv
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ always @(posedge clk) begin
if ({rel_lba, sd_buff_addr} == sector_offset) g64_tlen_lo[7:0] <= sd_buff_dout;
if ({rel_lba, sd_buff_addr} == sector_offset + 1'd1) begin
raw_track_len <= {sd_buff_dout, g64_tlen_lo};
track_lbas <= (sector_offset + 2'd2 + {sd_buff_dout, g64_tlen_lo} + 9'd511) >> 4'd9;
track_lbas <= 5'((sector_offset + 2'd2 + {sd_buff_dout, g64_tlen_lo} + 9'd511) >> 4'd9);
end
end

Expand All @@ -193,7 +193,7 @@ always @(posedge clk) begin
else begin
sector_offset <= { start_sectors[track[6:1]][0], 8'd0 } ;
lba <= start_sectors[track[6:1]][9:1];
track_lbas <= (start_sectors[track[6:1]+1'd1] - start_sectors[track[6:1]] + 1'd1) >> 1'd1;
track_lbas <= 5'((start_sectors[track[6:1]+1'd1] - start_sectors[track[6:1]] + 1'd1) >> 1'd1);
sd_rd <= 1;
end
end
Expand Down Expand Up @@ -241,7 +241,7 @@ always @(posedge clk) begin
else begin
sector_offset <= { start_sectors[new_track[6:1]][0], 8'd0 } ;
lba <= start_sectors[new_track[6:1]][9:1];
track_lbas <= (start_sectors[new_track[6:1]+1'd1] - start_sectors[new_track[6:1]] + 1'd1) >> 1'd1;
track_lbas <= 5'((start_sectors[new_track[6:1]+1'd1] - start_sectors[new_track[6:1]] + 1'd1) >> 1'd1);
sd_rd <= 1;
busy <= 1;
end
Expand Down
10 changes: 7 additions & 3 deletions src/misc/hid.v
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ reg [7:0] command;
reg [7:0] device; // used for joystick
reg irq_enable;
reg [5:0] db9_portD;
reg [5:0] db9_portD2;

// process mouse events
always @(posedge clk) begin
Expand All @@ -78,10 +79,12 @@ always @(posedge clk) begin
keyboard[ 6] <= 8'hff; keyboard[ 7] <= 8'hff;

end else begin
db9_portD <= db9_port;
db9_portD2 <= db9_portD;

// monitor db9 port for changes and raise interrupt
if(irq_enable) begin
db9_portD <= db9_port;
if(db9_portD != db9_port) begin
if(db9_portD2 != db9_portD) begin
// irq_enable prevents further interrupts until
// the db9 state has actually been read by the MCU
irq <= 1'b1;
Expand All @@ -90,6 +93,7 @@ always @(posedge clk) begin
end

if(iack) irq <= 1'b0; // iack clears interrupt

mouse_strobe <=1'b0;
joystick_strobe <=1'b0;
if(data_in_strobe) begin
Expand Down Expand Up @@ -152,7 +156,7 @@ always @(posedge clk) begin
// CMD 4: send digital joystick data to MCU
if(command == 8'd4) begin
if(state == 4'd1) irq_enable <= 1'b1; // (re-)enable interrupt
data_out <= {2'b00, db9_port };
data_out <= {2'b00, db9_portD };
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/misc/mcu_spi.v
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ assign mcu_osd_strobe = spi_in_strobe && spi_target == 8'd2;
assign mcu_sdc_strobe = spi_in_strobe && spi_target == 8'd3;

reg [7:0] spi_in_data;
assign mcu_start = spi_in_cnt == 2;
assign mcu_dout = spi_in_data;

reg [3:0] spi_in_cnt;
assign mcu_start = spi_in_cnt == 2;

always @(posedge clk) begin
reg [1:0] spi_data_in_readyD;
Expand Down
2 changes: 2 additions & 0 deletions src/misc/sd_rw.v
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ always @ (posedge clk or negedge rstn)
end
end
WCRC : begin
outaddr <= 9'd0;
for(i=0;i<4;i=i+1)
sddatout[i] <= data_crc[i][4'd15 - ridx[3:0]];

Expand Down Expand Up @@ -390,6 +391,7 @@ always @ (posedge clk or negedge rstn)
end
end
RCRC : begin
outaddr <= 9'd0;
for(i=0;i<4;i=i+1) begin
read_crc[i][4'd15 - ridx[3:0]] <= sddatin[i];
end
Expand Down
43 changes: 24 additions & 19 deletions src/misc/sysctrl.v
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ module sysctrl (
// interrupt interface
output int_out_n,
input [7:0] int_in,
output reg [7:0] int_ack,
output [7:0] int_ack,

input [1:0] buttons, // S0 and S1 buttons on Tang Nano 20k

output reg [1:0] leds, // two leds can be controlled from the MCU
output reg [23:0] color, // a 24bit color to e.g. be used to drive the ws2812
output [23:0] color, // a 24bit color to e.g. be used to drive the ws2812

// values that can be configured by the user
output reg system_reu_cfg,
output reg [1:0] system_reset,
output [1:0] system_reset,
output reg [1:0] system_scanlines,
output reg [1:0] system_volume,
output reg system_wide_screen,
output reg [1:0] system_floppy_wprot,
output reg [3:0] system_port_1,
output reg [3:0] system_port_2,
output reg [1:0] system_dos_sel,
output reg system_1541_reset,
output system_1541_reset,
output reg system_sid_digifix,
output reg [1:0] system_turbo_mode,
output reg [1:0] system_turbo_speed,
Expand All @@ -54,11 +54,12 @@ module sysctrl (
output reg system_georam,
output reg [1:0] system_uart,
output reg system_joyswap,
output reg system_detach_reset
output reg system_detach_reset,
output reg cold_boot
);

reg [3:0] state;
reg [7:0] command;
reg [3:0] state = 4'd0;
reg [7:0] command = 8'd0;
reg [7:0] id;

// reverse data byte for rgb
Expand All @@ -73,26 +74,30 @@ reg sys_int = 1'b1;
assign int_out_n = (int_in != 8'h00 || sys_int)?1'b0:1'b1;

// by default system is in reset
reg main_reset = 2'd3;
reg [1:0] main_reset = 2'd3;
reg [31:0] main_reset_timeout = 32'd80_000_000;
reg c1541reset = 1'b1;
reg [23:0] color_i = 24'h000000;
reg [7:0] int_ack_i = 8'h00;
assign system_reset = main_reset;
assign system_1541_reset = c1541reset;
assign cold_boot = coldboot;
assign color = color_i;
assign int_ack = int_ack_i;

reg [31:0] main_reset_timeout;

// process mouse events
always @(posedge clk) begin
if(reset) begin
state <= 4'd0;
leds <= 2'b00; // after reset leds are off
color <= 24'h000000; // color black -> rgb led off
color_i <= 24'h000000; // color black -> rgb led off

// stay in reset for about 3 seconds or until MCU releases reset
main_reset <= 2'd3;
c1541reset <= 1'b1;
main_reset_timeout <= 32'd80_000_000;

int_ack <= 8'h00;
int_ack_i <= 8'h00;
coldboot = 1'b1; // reset is actually the power-on-reset
sys_int = 1'b1; // coldboot interrupt

Expand Down Expand Up @@ -135,14 +140,14 @@ always @(posedge clk) begin
main_reset <= 2'd0;
c1541reset <= 1'b0;
// BRG LED yellow if no MCU has responded
color <= 24'h000202;
color_i <= 24'h000202;
end
end

int_ack <= 8'h00;
int_ack_i <= 8'h00;

// iack bit 0 acknowledges the coldboot notification
if(int_ack[0]) sys_int <= 1'b0;
if(int_ack_i[0]) sys_int <= 1'b0;

if(data_in_strobe) begin
if(data_in_start) begin
Expand All @@ -167,9 +172,9 @@ always @(posedge clk) begin

// CMD 2: a 24 color value to be mapped e.g. onto the ws2812
if(command == 8'd2) begin
if(state == 4'd1) color[15: 8] <= data_in_rev;
if(state == 4'd2) color[ 7: 0] <= data_in_rev;
if(state == 4'd3) color[23:16] <= data_in_rev;
if(state == 4'd1) color_i[15: 8] <= data_in_rev;
if(state == 4'd2) color_i[ 7: 0] <= data_in_rev;
if(state == 4'd3) color_i[23:16] <= data_in_rev;
end

// CMD 3: return button state
Expand Down Expand Up @@ -249,7 +254,7 @@ always @(posedge clk) begin
// CMD 5: interrupt control
if(command == 8'd5) begin
// second byte acknowleges the interrupts
if(state == 4'd1) int_ack <= data_in;
if(state == 4'd1) int_ack_i <= data_in;

// interrupt[0] notifies the MCU of a FPGA cold boot e.g. if
// the FPGA has been loaded via USB
Expand Down
Loading

0 comments on commit 0572db1

Please sign in to comment.