1
0

PixelEngine.v 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 [7:0] r,
  14. output wire [7:0] g,
  15. output wire [7: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 [23: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. wire h_active = (h_count > h_start);
  29. wire v_active = (v_count > v_start);
  30. wire [9:0] line_active = (v_active) ? v_count-(v_start+1'b1) : 10'd0;
  31. wire [9:0] pixel_active = (h_active && v_active) ? h_count-h_start : 10'd0;
  32. wire [16:0] pixel_idx = ( (line_active >> scale2x) *320) + (pixel_active >> 1);
  33. assign vram_addr = pixel_idx;
  34. assign r = (blank) ? 8'd0 : vram_q[23:16];
  35. assign g = (blank) ? 8'd0 : vram_q[15:8];
  36. assign b = (blank) ? 8'd0 : vram_q[7:0];
  37. endmodule