Skip to content

Commit 95a5153

Browse files
committed
fix: widen native video centering range
1 parent 3f84a8e commit 95a5153

3 files changed

Lines changed: 19 additions & 21 deletions

File tree

menu.sv

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,13 @@ assign LED_POWER[0]= FB ? led[2] : act_cnt2[26] ? act_cnt2[25:18] > act_cnt2[7:0
208208

209209

210210
`include "build_id.v"
211-
// Image centering: 4-bit signed in OSD ordering 0,+1..+7,-8..-1 so that the
212-
// power-on default (status bits = 0) maps to "no shift". Bit pattern matches
213-
// 4-bit two's complement when reinterpreted as signed.
211+
// Image centering options use signed two's-complement ordering with 0 first,
212+
// so the power-on default (status bits = 0) selects the calibrated base timing.
214213
localparam CONF_STR = {
215214
"MENU;UART31250,MIDI;",
216215
"-;",
217-
"O[13:10],H Offset,0,+1,+2,+3,+4,+5,+6,+7,-8,-7,-6,-5,-4,-3,-2,-1;",
218-
"O[17:14],V Offset,0,+1,+2,+3,+4,+5,+6,+7,-8,-7,-6,-5,-4,-3,-2,-1;",
216+
"O[15:10],H Offset,0,+1,+2,+3,+4,+5,+6,+7,+8,+9,+10,+11,+12,+13,+14,+15,+16,+17,+18,+19,+20,+21,+22,+23,+24,+25,+26,+27,+28,+29,+30,+31,-32,-31,-30,-29,-28,-27,-26,-25,-24,-23,-22,-21,-20,-19,-18,-17,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1;",
217+
"O[19:16],V Offset,0,+1,+2,+3,+4,+5,+6,+7,-8,-7,-6,-5,-4,-3,-2,-1;",
219218
"-;",
220219
"V,v",`BUILD_DATE
221220
};
@@ -522,12 +521,10 @@ native_video_top native_video
522521
.enable (mode_zaparoo),
523522
.active (native_active),
524523

525-
// status[13:10] / status[17:14] are 4-bit fields whose bit pattern
526-
// matches signed two's complement when the OSD enum is ordered
527-
// 0,+1..+7,-8..-1 (see CONF_STR). $signed() makes the reinterpretation
528-
// explicit at the port boundary.
529-
.h_offset ($signed(status[13:10])),
530-
.v_offset ($signed(status[17:14]))
524+
// Status bit patterns match signed two's complement because CONF_STR orders
525+
// each OSD enum as 0,+1..max,min..-1. $signed() makes that explicit here.
526+
.h_offset ($signed(status[15:10])),
527+
.v_offset ($signed(status[19:16]))
531528
);
532529

533530
// Cosine + LFSR fallback noise pattern, painted into the 320x240 active area

rtl/native_video_timing.sv

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Zaparoo native video timing: 320x240 at 15.734 kHz from 27 MHz / 4.
2-
// h_offset/v_offset (signed -8..+7) shift the image by repartitioning
3-
// front porch and back porch. H_TOTAL/V_TOTAL are invariant, so line
4-
// rate and frame rate are unchanged regardless of offset values.
2+
// h_offset/v_offset shift the image by repartitioning front porch and back
3+
// porch. H_TOTAL/V_TOTAL are invariant, so line/frame rates stay unchanged.
54

65
module native_video_timing
76
(
@@ -10,8 +9,8 @@ module native_video_timing
109
input wire reset,
1110

1211
// Image centering: positive = shift right/down (FP shrinks, BP grows).
13-
input wire signed [3:0] h_offset, // -8..+7 pixels (budget H_FP=14 / H_BP=63)
14-
input wire signed [3:0] v_offset, // -8..+7 lines (budget V_FP=8 / V_BP=11)
12+
input wire signed [5:0] h_offset, // -32..+31 pixels (budget H_FP=38 / H_BP=39)
13+
input wire signed [3:0] v_offset, // -8..+7 lines (budget V_FP=8 / V_BP=11)
1514

1615
output reg hsync,
1716
output reg vsync,
@@ -25,9 +24,11 @@ module native_video_timing
2524
);
2625

2726
localparam [9:0] H_ACTIVE = 10'd320;
28-
localparam [9:0] H_FP = 10'd14;
27+
// 38/32/39 keeps total blanking fixed while moving the default image 24 px
28+
// left from the earlier CRT-specific 14/32/63 porch split.
29+
localparam [9:0] H_FP = 10'd38;
2930
localparam [5:0] H_SYNC = 6'd32;
30-
localparam [9:0] H_BP = 10'd63;
31+
localparam [9:0] H_BP = 10'd39;
3132
localparam [9:0] H_TOTAL = 10'd429;
3233

3334
// V blanking rebalanced from 6/3/13 to 8/3/11 to give symmetric ±8 budget
@@ -40,7 +41,7 @@ localparam [8:0] V_TOTAL = 9'd262;
4041

4142
// Sync starts shift with the offset; two's-complement subtraction in
4243
// unsigned arithmetic yields the correct result at both ends of the range.
43-
wire [9:0] H_SYNC_START = H_ACTIVE + (H_FP - {{6{h_offset[3]}}, h_offset});
44+
wire [9:0] H_SYNC_START = H_ACTIVE + (H_FP - {{4{h_offset[5]}}, h_offset});
4445
wire [9:0] H_SYNC_END = H_SYNC_START + H_SYNC;
4546
wire [8:0] V_SYNC_START = V_ACTIVE + (V_FP - {{5{v_offset[3]}}, v_offset});
4647
wire [8:0] V_SYNC_END = V_SYNC_START + V_SYNC;

rtl/native_video_top.sv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ module native_video_top
3131
input wire enable,
3232
output wire active,
3333

34-
// OSD image centering: signed -8..+7 pixels/lines, 0 = no shift.
35-
input wire signed [3:0] h_offset,
34+
// OSD image centering: 0 = default porch split.
35+
input wire signed [5:0] h_offset,
3636
input wire signed [3:0] v_offset
3737
);
3838

0 commit comments

Comments
 (0)