// 1280x720 progressive timing (VESA CEA-861), pixel clock 75 MHz -> ~60.6 Hz
module video_timing #(
    parameter integer H_ACTIVE = 1280,
    parameter integer H_FP     = 110,
    parameter integer H_SYNC   = 40,
    parameter integer H_BP     = 220,
    parameter integer V_ACTIVE = 720,
    parameter integer V_FP     = 5,
    parameter integer V_SYNC   = 5,
    parameter integer V_BP     = 20
) (
    input  wire       pclk,
    input  wire       rst,
    output reg  [11:0] x,
    output reg  [11:0] y,
    output wire        de,
    output wire        hsync,
    output wire        vsync
);
    localparam integer H_TOTAL = H_ACTIVE + H_FP + H_SYNC + H_BP;   // 1650
    localparam integer V_TOTAL = V_ACTIVE + V_FP + V_SYNC + V_BP;   // 750

    wire h_end = (x == H_TOTAL - 1);
    wire v_end = (y == V_TOTAL - 1);

    always @(posedge pclk) begin
        if (rst) begin
            x <= 12'd0;
            y <= 12'd0;
        end else if (h_end) begin
            x <= 12'd0;
            if (v_end) y <= 12'd0;
            else       y <= y + 1'b1;
        end else begin
            x <= x + 1'b1;
        end
    end

    assign de    = (x < H_ACTIVE) && (y < V_ACTIVE);
    assign hsync = ~((x >= H_ACTIVE + H_FP) && (x < H_ACTIVE + H_FP + H_SYNC));
    assign vsync = ~((y >= V_ACTIVE + V_FP) && (y < V_ACTIVE + V_FP + V_SYNC));
endmodule
