Skip to content

Commit 3a19e6d

Browse files
committed
fix: use safer native video centering steps
1 parent 95a5153 commit 3a19e6d

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

menu.sv

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ assign LED_POWER[0]= FB ? led[2] : act_cnt2[26] ? act_cnt2[25:18] > act_cnt2[7:0
213213
localparam CONF_STR = {
214214
"MENU;UART31250,MIDI;",
215215
"-;",
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;",
216+
"O[13:10],H Offset,0,+2,+4,+6,+8,+10,+12,+14,-16,-14,-12,-10,-8,-6,-4,-2;",
217+
"O[17:14],V Offset,0,+1,+2,+3,+4,+5,+6,+7,-8,-7,-6,-5,-4,-3,-2,-1;",
218218
"-;",
219219
"V,v",`BUILD_DATE
220220
};
@@ -521,10 +521,10 @@ native_video_top native_video
521521
.enable (mode_zaparoo),
522522
.active (native_active),
523523

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]))
524+
// H offset is a 4-bit signed OSD value doubled into 2-pixel steps.
525+
// V offset is a normal 4-bit signed OSD value in 1-line steps.
526+
.h_offset ($signed({status[13:10], 1'b0})),
527+
.v_offset ($signed(status[17:14]))
528528
);
529529

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

rtl/native_video_timing.sv

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module native_video_timing
99
input wire reset,
1010

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

1515
output reg hsync,
@@ -24,11 +24,11 @@ module native_video_timing
2424
);
2525

2626
localparam [9:0] H_ACTIVE = 10'd320;
27-
// 38/32/39 keeps total blanking fixed while moving the default image 24 px
27+
// 26/32/51 keeps total blanking fixed while moving the default image 12 px
2828
// left from the earlier CRT-specific 14/32/63 porch split.
29-
localparam [9:0] H_FP = 10'd38;
29+
localparam [9:0] H_FP = 10'd26;
3030
localparam [5:0] H_SYNC = 6'd32;
31-
localparam [9:0] H_BP = 10'd39;
31+
localparam [9:0] H_BP = 10'd51;
3232
localparam [9:0] H_TOTAL = 10'd429;
3333

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

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

rtl/native_video_top.sv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module native_video_top
3232
output wire active,
3333

3434
// OSD image centering: 0 = default porch split.
35-
input wire signed [5:0] h_offset,
35+
input wire signed [4:0] h_offset,
3636
input wire signed [3:0] v_offset
3737
);
3838

0 commit comments

Comments
 (0)