Код:
module ZX_clock_gen(
input wire CLK, // 14 MHz clock input
input wire M1n,
input wire IORQn,
input wire RESn,
output reg PIXCLK = 0,
output wire PIXCLKn,
output wire DC0,
output wire DC0n,
output wire DC1,
output wire DC1n,
output wire DC2,
output wire DC2n,
output wire [4:0] H,
output wire [7:0] V,
output wire HSYN,
output wire VSYN,
output wire BORD,
output wire BLANCn,
output wire INTn,
output wire SYNn,
output wire CASn,
output reg RASn = 1,
output wire RAS
);
parameter HBorderStart = 256; // X resolution
parameter HBlancStart = 320;
parameter HBlancEnd = 384;
parameter HSynStart = 320;
parameter HSynEnd = 352;
parameter HLineEnd = 448;
parameter VBorderStart = 192; // Y Resolution
parameter VBlancStart = 248;
parameter VBlancEnd = 256;
parameter VSynStart = 248;
parameter VSynEnd = 256;
parameter VIntStart = 256;
parameter VIntEnd = 264;
parameter VLineEnd = 320;
reg [8:0] cntH = 0;
reg [8:0] cntV = 0;
reg CAS = 0;
always @(negedge CLK)
begin
PIXCLK <= ~PIXCLK;
CAS <= cntH[0];
end
always @(negedge PIXCLK)// or negedge RESn)
begin
cntH <= cntH + 1'b1;
RASn <= cntH[0];
if(cntH + 1'b1 == HLineEnd) // should be cntH + 1 as it is non blocking!
begin
cntH <= 9'b000000000;
cntV <= cntV + 1'b1;
if(cntV + 1'b1 == VLineEnd) // should be cntV + 1 as it is non blocking!
cntV <= 9'b000000000;
end
end
wire HBR = (cntH >= HBorderStart) ? 1'b1 : 1'b0;
wire VBR = (cntV >= VBorderStart) ? 1'b1 : 1'b0;
wire HBL = (cntH >= HBlancStart && cntH <= HBlancEnd ) ? 1'b1 : 1'b0;
wire VBL = (cntV >= VBlancStart && cntV <= VBlancEnd ) ? 1'b1 : 1'b0;
assign HSYN = (cntH >= HSynStart && cntH <= HSynEnd ) ? 1'b1 : 1'b0;
assign VSYN = (cntV >= VSynStart && cntV <= VSynEnd ) ? 1'b1 : 1'b0;
assign INTn = (cntV >= VIntStart && cntV <= VIntEnd ) ? 1'b0 : 1'b1;
assign PIXCLKn = PIXCLK;
assign DC0 = cntH[0];
assign DC0n = ~cntH[0];
assign DC1 = cntH[1];
assign DC1n = ~cntH[1];
assign DC2 = cntH[2];
assign DC2n = ~cntH[2];
assign H[4:0] = cntH[7:3];
assign V[7:0] = cntV[7:0];
assign BLANCn = ~(VBL | HBL);
assign SYNn = ~(HSYN ^ VSYN);
assign BORD = VBR | HBR;
assign CASn = ~CAS;
assign RAS = ~RASn;
endmodule