PixelEngine.v 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Renders Pixel Plane
  3. */
  4. module PixelEngine(
  5. // Video I/O
  6. input clk,
  7. input hs,
  8. input vs,
  9. input blank,
  10. input scale2x, // render vertically in 2x scaling (e.g. for HDMI to get full screen 320x240 on a 640x480 signal)
  11. // note: horizontally this scaling is always applied
  12. // Output pixels
  13. output wire [2:0] r,
  14. output wire [2:0] g,
  15. output wire [1:0] b,
  16. input [11:0] h_count, // line position in pixels including blanking
  17. input [11:0] v_count, // frame position in lines including blanking
  18. // VRAMpixel
  19. output wire [16:0] vram_addr,
  20. input [7:0] vram_q
  21. );
  22. localparam HSTART_HDMI = 159; // Pixel to start rendering
  23. localparam VSTART_HDMI = 44; // Line to start rendering
  24. localparam HSTART_NTSC = 195; // Pixel to start rendering
  25. localparam VSTART_NTSC = 19; // Line to start rendering
  26. wire [9:0] h_start = (scale2x) ? HSTART_HDMI : HSTART_NTSC;
  27. wire [9:0] v_start = (scale2x) ? VSTART_HDMI : VSTART_NTSC;
  28. reg [7:0] pixel_data = 8'd0;
  29. wire h_active = (h_count > h_start);
  30. wire v_active = (v_count > v_start);
  31. wire [9:0] line_active = (v_active) ? v_count-(v_start+1'b1) : 10'd0;
  32. wire [9:0] pixel_active = (h_active && v_active) ? h_count-h_start : 10'd0;
  33. wire [16:0] pixel_idx = ( (line_active >> scale2x) *320) + (pixel_active >> 1);
  34. assign vram_addr = pixel_idx;
  35. assign r = (blank) ? 3'd0 : vram_q[7:5];
  36. assign g = (blank) ? 3'd0 : vram_q[4:2];
  37. assign b = (blank) ? 2'd0 : vram_q[1:0];
  38. endmodule