Skip to content

Commit 50bf5cc

Browse files
committed
feat: dual-mode menu core with switchable native FB reader
Adds a runtime-switchable "FB mode" alongside the original menu behavior. When status[9]=0 (default), the menu core renders the original cosine+LFSR pattern through the unchanged PAL/NTSC scandoubler timing — every existing menu surface (HDMI wallpaper compositor, OSD, F1 wallpaper cycle) keeps working. When status[9]=1, native_video_top takes over and feeds VGA from the 320x240 RGBX8888 framebuffer the HPS-side launcher writes into DDR. Carried forward from codex/zaparoo-rgbx8888-native-core (PR #2): - rtl/native_video_reader.sv — DDR burst reader with ping-pong buffers - rtl/native_video_timing.sv — 320x240 NTSC native CRT timing - rtl/native_video_top.sv — wrapper - PLL output1 20 MHz -> 27.027 MHz (required for 15.734 kHz NTSC line rate) Deliberately NOT carried forward — preserves original menu functionality: - CONF_STR title stays "MENU" (so is_menu() in Main_MiSTer still matches, F1 wallpaper cycling still works) - VIDEO_ARX/ARY stay 0/0 (no aspect-ratio change in cosine mode) - PAL/NTSC scandoubler ce_pix logic intact - Original cosine HV counters intact Mux on status[9] & native_active, with fallback to the cosine path until the first DDR frame is loaded so the output is never undriven. The DDR clear loop is removed — it was one-time boot scaffolding using the same DDRAM_* signals the native reader now owns. native_video_reader holds ddr_rd/ddr_we low when status[9]=0, so DDR is unused in the default mode.
1 parent 5c09db7 commit 50bf5cc

6 files changed

Lines changed: 592 additions & 33 deletions

File tree

files.qip

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
set_global_assignment -name SYSTEMVERILOG_FILE rtl/sdram.sv
2-
set_global_assignment -name SYSTEMVERILOG_FILE rtl/ddram.sv
32
set_global_assignment -name VERILOG_FILE rtl/lfsr.v
43
set_global_assignment -name SYSTEMVERILOG_FILE rtl/cos.sv
4+
set_global_assignment -name SYSTEMVERILOG_FILE rtl/native_video_reader.sv
5+
set_global_assignment -name SYSTEMVERILOG_FILE rtl/native_video_timing.sv
6+
set_global_assignment -name SYSTEMVERILOG_FILE rtl/native_video_top.sv
57
set_global_assignment -name SYSTEMVERILOG_FILE menu.sv

menu.sv

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -336,36 +336,15 @@ always @(posedge clk_sys) begin
336336
state <= state+1'd1;
337337
end
338338
16: begin
339-
sdram_addr <= addr[24:0];
340-
sdram_din <= 0;
341-
sdram_we <= we;
339+
sdram_we <= 0;
342340
end
343341
endcase
344342
end
345343
end
346344

347-
ddram ddr
348-
(
349-
.*,
350-
.reset(RESET),
351-
.dout(),
352-
.din(0),
353-
.rd(0),
354-
.ready()
355-
);
356-
357-
reg we;
358-
reg [28:0] addr = 0;
359-
360-
always @(posedge clk_sys) begin
361-
reg [4:0] cnt = 9;
362-
363-
if(~RESET & cfg[15]) begin
364-
cnt <= cnt + 1'b1;
365-
we <= &cnt;
366-
if(cnt == 8) addr <= addr + 1'd1;
367-
end
368-
end
345+
// DDR clear loop removed: native_video_reader owns DDRAM_* signals.
346+
// When status[9]=0 the reader is held in idle (rd=0, we=0) and DDR is unused;
347+
// when status[9]=1 the reader takes over to fetch the linux-rendered framebuffer.
369348

370349
//////////////////////////// MT32pi //////////////////////////////////
371350

@@ -550,11 +529,58 @@ cos cos(vvc + {vc>>forced_scandoubler, 2'b00}, cos_out);
550529

551530
wire [7:0] comp_v = (cos_g >= rnd_c) ? {cos_g - rnd_c, 2'b00} : 8'd0;
552531

553-
assign VGA_DE = ~(HBlank | VBlank);
554-
assign VGA_HS = HSync;
555-
assign VGA_VS = VSync;
556-
assign VGA_G = comp_v;
557-
assign VGA_R = comp_v;
558-
assign VGA_B = comp_v;
532+
// Runtime FB-mode gate driven by the HPS-side launcher via status[9].
533+
wire mode_zaparoo = status[9];
534+
535+
wire [7:0] native_r;
536+
wire [7:0] native_g;
537+
wire [7:0] native_b;
538+
wire native_hs;
539+
wire native_vs;
540+
wire native_de;
541+
wire native_active;
542+
543+
native_video_top native_video
544+
(
545+
.clk_sys (clk_sys),
546+
.clk_vid (CLK_VIDEO),
547+
.ce_pix (ce_pix),
548+
.reset (RESET),
549+
550+
.ddr_busy (DDRAM_BUSY),
551+
.ddr_burstcnt (DDRAM_BURSTCNT),
552+
.ddr_addr (DDRAM_ADDR),
553+
.ddr_dout (DDRAM_DOUT),
554+
.ddr_dout_ready (DDRAM_DOUT_READY),
555+
.ddr_rd (DDRAM_RD),
556+
.ddr_din (DDRAM_DIN),
557+
.ddr_be (DDRAM_BE),
558+
.ddr_we (DDRAM_WE),
559+
560+
.vga_r (native_r),
561+
.vga_g (native_g),
562+
.vga_b (native_b),
563+
.vga_hs (native_hs),
564+
.vga_vs (native_vs),
565+
.vga_de (native_de),
566+
.vga_hblank (),
567+
.vga_vblank (),
568+
.enable (mode_zaparoo),
569+
.active (native_active)
570+
);
571+
572+
// Mode A (default): cosine+LFSR pattern drives RGB and the original PAL/NTSC
573+
// scandoubler timing drives sync/DE. HDMI wallpaper compositor runs unchanged.
574+
// Mode B (status[9]=1, frame ready): native_video_top drives RGB+sync from the
575+
// linux-rendered 320x240 RGBX8888 buffer in DDR. Falls back to cosine until the
576+
// first frame is loaded so the screen is never undriven.
577+
wire use_native = mode_zaparoo & native_active;
578+
579+
assign VGA_DE = use_native ? native_de : ~(HBlank | VBlank);
580+
assign VGA_HS = use_native ? native_hs : HSync;
581+
assign VGA_VS = use_native ? native_vs : VSync;
582+
assign VGA_R = use_native ? native_r : comp_v;
583+
assign VGA_G = use_native ? native_g : comp_v;
584+
assign VGA_B = use_native ? native_b : comp_v;
559585

560586
endmodule

0 commit comments

Comments
 (0)