PixelEngine.v 1.8 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. input halfRes, // render half res at full res (160x120 as 320x240), basically zooms in at top left corner
  13. // Output pixels
  14. output wire [7:0] r,
  15. output wire [7:0] g,
  16. output wire [7:0] b,
  17. input [11:0] h_count, // line position in pixels including blanking
  18. input [11:0] v_count, // frame position in lines including blanking
  19. // VRAMpixel
  20. output wire [16:0] vram_addr,
  21. input [23:0] vram_q
  22. );
  23. localparam HSTART_HDMI = 159; // Pixel to start rendering
  24. localparam VSTART_HDMI = 44; // Line to start rendering
  25. localparam HSTART_NTSC = 195; // Pixel to start rendering
  26. localparam VSTART_NTSC = 19; // Line to start rendering
  27. wire [9:0] h_start = (scale2x) ? HSTART_HDMI : HSTART_NTSC;
  28. wire [9:0] v_start = (scale2x) ? VSTART_HDMI : VSTART_NTSC;
  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 = (halfRes) ? ( ((line_active >> scale2x) >> 1) *320) + (pixel_active >> 2):
  34. ( (line_active >> scale2x) *320) + (pixel_active >> 1);
  35. assign vram_addr = pixel_idx;
  36. assign r = (blank) ? 8'd0 : vram_q[23:16];
  37. assign g = (blank) ? 8'd0 : vram_q[15:8];
  38. assign b = (blank) ? 8'd0 : vram_q[7:0];
  39. endmodule