From e44a0734ddd590daf0d2490f31c8f98caa1af2cd Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Sun, 27 Jan 2019 14:47:03 -0500 Subject: [PATCH] verilog-vga --- doc/notes.txt | 2 + presets/verilog-vga/hvsync_generator.v | 69 ++++++++++++++++++++++ presets/verilog-vga/lfsr.v | 31 ++++++++++ presets/verilog-vga/ram.v | 80 ++++++++++++++++++++++++++ presets/verilog-vga/test_hvsync.v | 32 +++++++++++ src/platform/verilog.ts | 24 ++++---- 6 files changed, 228 insertions(+), 10 deletions(-) create mode 100644 presets/verilog-vga/hvsync_generator.v create mode 100644 presets/verilog-vga/lfsr.v create mode 100644 presets/verilog-vga/ram.v create mode 100644 presets/verilog-vga/test_hvsync.v diff --git a/doc/notes.txt b/doc/notes.txt index 14487f51..e6576b6b 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -91,6 +91,8 @@ TODO: - Safari: scope doesn't show while CRT in use - recording video indicator - verilog: support VGA/multisync monitor? +- stego shareable images (http://pico-8.wikia.com/wiki/P8PNGFileFormat) +- https://makecode.com/language? WEB WORKER FORMAT diff --git a/presets/verilog-vga/hvsync_generator.v b/presets/verilog-vga/hvsync_generator.v new file mode 100644 index 00000000..24587616 --- /dev/null +++ b/presets/verilog-vga/hvsync_generator.v @@ -0,0 +1,69 @@ + +`ifndef HVSYNC_GENERATOR_H +`define HVSYNC_GENERATOR_H + +/* +Video sync generator, used to drive a simulated CRT. +To use: +- Wire the hsync and vsync signals to top level outputs +- Add a 3-bit (or more) "rgb" output to the top level +*/ + +module hvsync_generator(clk, reset, hsync, vsync, display_on, hpos, vpos); + + input clk; + input reset; + output reg hsync, vsync; + output display_on; + output reg [8:0] hpos; + output reg [8:0] vpos; + + // declarations for TV-simulator sync parameters + // horizontal constants + parameter H_DISPLAY = 256; // horizontal display width + parameter H_BACK = 23; // horizontal left border (back porch) + parameter H_FRONT = 7; // horizontal right border (front porch) + parameter H_SYNC = 23; // horizontal sync width + // vertical constants + parameter V_DISPLAY = 240; // vertical display height + parameter V_TOP = 5; // vertical top border + parameter V_BOTTOM = 14; // vertical bottom border + parameter V_SYNC = 3; // vertical sync # lines + // derived constants + parameter H_SYNC_START = H_DISPLAY + H_FRONT; + parameter H_SYNC_END = H_DISPLAY + H_FRONT + H_SYNC - 1; + parameter H_MAX = H_DISPLAY + H_BACK + H_FRONT + H_SYNC - 1; + parameter V_SYNC_START = V_DISPLAY + V_BOTTOM; + parameter V_SYNC_END = V_DISPLAY + V_BOTTOM + V_SYNC - 1; + parameter V_MAX = V_DISPLAY + V_TOP + V_BOTTOM + V_SYNC - 1; + + wire hmaxxed = (hpos == H_MAX) || reset; // set when hpos is maximum + wire vmaxxed = (vpos == V_MAX) || reset; // set when vpos is maximum + + // horizontal position counter + always @(posedge clk) + begin + hsync <= (hpos>=H_SYNC_START && hpos<=H_SYNC_END); + if(hmaxxed) + hpos <= 0; + else + hpos <= hpos + 1; + end + + // vertical position counter + always @(posedge clk) + begin + vsync <= (vpos>=V_SYNC_START && vpos<=V_SYNC_END); + if(hmaxxed) + if (vmaxxed) + vpos <= 0; + else + vpos <= vpos + 1; + end + + // display_on is set when beam is in "safe" visible frame + assign display_on = (hpos