Skip to content

Commit

Permalink
Merge pull request #120 from MikeS11/main
Browse files Browse the repository at this point in the history
Update Sys, Adjust HSync / 60 Hz (HFreq)
  • Loading branch information
sorgelig authored May 26, 2024
2 parents d69d9c1 + 87f0372 commit fd7aa2a
Show file tree
Hide file tree
Showing 9 changed files with 371 additions and 53 deletions.
4 changes: 2 additions & 2 deletions arcadia/src/gfx/VideoRegs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ object VideoRegs {
def decode[T <: Bits](data: Vec[T]): VideoRegs = {
val regs = Wire(new VideoRegs)
regs.size := UVec2(data(0)(8, 0), data(1)(8, 0))
regs.frontPorch := UVec2(data(2)(8, 0), data(3)(8, 0))
regs.retrace := UVec2(data(4)(8, 0), data(5)(8, 0))
regs.frontPorch := UVec2(data(2)(8, 0), data(3)(8, 0))
regs.retrace := UVec2(data(4)(8, 0) + 8.U, data(5)(8, 0) + 1.U) // Adjust decoded video timing for CRT's (Extended HSYNC / VSYNC)
regs
}
}
2 changes: 1 addition & 1 deletion cave/src/Config.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ object Config {
val compatibilityVideoTimingConfig = VideoTimingConfig(
clockFreq = VIDEO_CLOCK_FREQ,
clockDiv = VIDEO_CLOCK_DIV,
hFreq = 15_625, // Hz
hFreq = 15_734, // Hz (Match NTSC SPEC)
vFreq = 60 // Hz
)

Expand Down
4 changes: 2 additions & 2 deletions cave/src/VideoSys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ object VideoSys {
vSize = Config.SCREEN_HEIGHT,
hFrontPorch = 36,
vFrontPorch = 12,
hRetrace = 20,
vRetrace = 2
hRetrace = 28, // Adjust Hsync to 28 and VSync to 3 to improve improve CRT compatibility
vRetrace = 3 //
)
}
12 changes: 11 additions & 1 deletion quartus/cave.sv
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module emu (
output VGA_F1,
output [1:0] VGA_SL,
output VGA_SCALER, // Force VGA scaler
output VGA_DISABLE,

input [11:0] HDMI_WIDTH,
input [11:0] HDMI_HEIGHT,
Expand Down Expand Up @@ -388,6 +389,15 @@ video_mixer #(.LINE_LENGTH(320), .HALF_DEPTH(0), .GAMMA(1)) video_mixer (
.VGA_DE(VGA_DE)
);

// Update HPS when video mode changes
reg [1:0] video_status;
always @(posedge clk_sys) begin
if (video_status != status[8]) begin
video_status <= status[8];
new_vmode <= ~new_vmode;
end
end

////////////////////////////////////////////////////////////////////////////////
// CONTROLS
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -524,7 +534,7 @@ Cave cave (
.player_1_pause(player_2_pause),
// Video signals
.video_clockEnable(ce_pix),
.video_changeMode(new_vmode),
.video_changeMode(0),
.video_hSync(hsync),
.video_vSync(vsync),
.video_hBlank(hblank),
Expand Down
8 changes: 8 additions & 0 deletions quartus/sys/hps_io.sv
Original file line number Diff line number Diff line change
Expand Up @@ -891,22 +891,28 @@ always @(posedge clk_sys) begin
11: dout <= vid_pix[31:16];
12: dout <= vid_vtime_hdmi[15:0];
13: dout <= vid_vtime_hdmi[31:16];
14: dout <= vid_ccnt[15:0];
15: dout <= vid_ccnt[31:16];
default dout <= 0;
endcase
end

reg [31:0] vid_hcnt = 0;
reg [31:0] vid_vcnt = 0;
reg [31:0] vid_ccnt = 0;
reg [7:0] vid_nres = 0;
reg [1:0] vid_int = 0;

always @(posedge clk_vid) begin
integer hcnt;
integer vcnt;
integer ccnt;
reg old_vs= 0, old_de = 0, old_vmode = 0;
reg [3:0] resto = 0;
reg calch = 0;

if(calch & de) ccnt <= ccnt + 1;

if(ce_pix) begin
old_vs <= vs;
old_de <= de;
Expand All @@ -927,9 +933,11 @@ always @(posedge clk_vid) begin
if(&resto) vid_nres <= vid_nres + 1'd1;
vid_hcnt <= hcnt;
vid_vcnt <= vcnt;
vid_ccnt <= ccnt;
end
vcnt <= 0;
hcnt <= 0;
ccnt <= 0;
calch <= 1;
end
end
Expand Down
26 changes: 13 additions & 13 deletions quartus/sys/ltc2308.sv
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ end

endmodule

module ltc2308_tape #(parameter HIST_LOW = 16, HIST_HIGH = 64, ADC_RATE = 48000, CLK_RATE = 50000000)
module ltc2308_tape #(parameter HIST_LOW = 16, HIST_HIGH = 64, ADC_RATE = 48000, CLK_RATE = 50000000, NUM_CH = 1)
(
input reset,
input clk,

inout [3:0] ADC_BUS,
output reg dout,
output active
input reset,
input clk,

inout [3:0] ADC_BUS,
output reg dout,
output active,
output adc_sync,
output [(NUM_CH*12)-1:0] adc_data
);

wire [11:0] adc_data;
wire adc_sync;
ltc2308 #(1, ADC_RATE, CLK_RATE) adc
ltc2308 #(NUM_CH, ADC_RATE, CLK_RATE) adc
(
.reset(reset),
.clk(clk),
Expand All @@ -133,8 +133,8 @@ always @(posedge clk) begin
data1 <= data2;
data2 <= data3;
data3 <= data4;
data4 <= adc_data;
data4 <= adc_data[11:0];

sum <= data1+data2+data3+data4;

if(sum[13:2]<HIST_LOW) dout <= 0;
Expand All @@ -148,7 +148,7 @@ reg [1:0] act;
always @(posedge clk) begin
reg [31:0] onesec;
reg old_dout;

onesec <= onesec + 1;
if(onesec>CLK_RATE) begin
onesec <= 0;
Expand Down
1 change: 1 addition & 0 deletions quartus/sys/sys.qip
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set_global_assignment -name SYSTEMVERILOG_FILE [file join $::quartus(qip_path) v
set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) arcade_video.v ]
set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) osd.v ]
set_global_assignment -name SYSTEMVERILOG_FILE [file join $::quartus(qip_path) vga_out.sv ]
set_global_assignment -name SYSTEMVERILOG_FILE [file join $::quartus(qip_path) yc_out.sv ]
set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) i2c.v ]
set_global_assignment -name SYSTEMVERILOG_FILE [file join $::quartus(qip_path) alsa.sv ]
set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) i2s.v ]
Expand Down
Loading

0 comments on commit fd7aa2a

Please sign in to comment.