Ha!! I freakin did it!!!
Okay so here is the basics, the 'clk' is a 100mhz clock for the ram and signal gen and is skewed back 30 degrees. hdmiClk @ 250mhz and vClk is at 25mhz are synced. The HDMI encoder sets the rgb/hsync/vsync/vAct off of the vClk which, again, is 30 degrees ahead of the ram clock it's pipelining from. I plan to drop the vClk and just setup a clock divider on the hdmi clock inside the encoder module to to drive the flipflops in there, but for now I have crisp clean video with no artifacts during cpu reads or writes and doesn't appear that I'm having any dropped pixels. Just need to setup hardware scrolling in text mode and reenable bitmap mode and I should have a fully functional video display adapter!!
Code listed below. Not sure 'best practices' but I did opt to use blocking assignments on the first phase the signal generation as it started getting confusing, this way I know exactly what my signals are at that first clock, I didn't find it necessary to use them anywhere else. Once I get everything cleanup up and refined I may share the whole project out on github or the likes for community input / usage.
Code:
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 12/28/2021 10:30:59 PM
// Design Name:
// Module Name: displayDriver
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module displayDriver(
input clk,
input syClk,
input vClk,
input hdmiClk,
input wire [7:0] clrReg,
input wire [7:0] vidReg,
input wire [18:0] syAdr,
input wire syCs,
input wire syRw,
inout wire [7:0] syDat,
inout wire [7:0] sram_d,
output wire [18:0] sram_a,
output wire sram_wen,
output wire sram_cen,
output wire [2:0] TMDSp,
output wire [2:0] TMDSn,
output wire TMDSp_clock,
output wire TMDSn_clock
);
wire [18:0] vAdr;
assign vAdr = {vPos[8:3],hPos[9:3]};
reg [11:0] _buffRGB;
assign sram_a = (!clkDiv[1] && (syRead || syWrite)) ? _syAdr : vAdr;
assign sram_cen = ( (!clkDiv[1] && (syRead || syWrite)) || (clkDiv[1] && !vCs) ) ? 0 : 1;
assign sram_wen = (!clkDiv[1] && syWrite) ? 0 : 1;
assign syDat = (!syCs && !syRw) ? 8'bZZZZZZZZ : _syDatOut;
assign sram_d = (!clkDiv[1] && syWrite) ? _syDatIn : 8'bZZZZZZZZ;
reg [9:0] hPosBuf,hPos,vPosBuf,vPos;
reg vAct,vCs,hSync,vSync;
reg lastSyEvtW,lastSyEvtR,syRead,syWrite;
reg [7:0] _vDat,_syDatOut;
reg [1:0] clkDiv;
always @(posedge clk) begin
clkDiv = clkDiv+1;
if (clkDiv == 2'b10) begin
hSync <= (hPosBuf > 655 && hPosBuf < 752) ? 0 : 1;
vSync <= (vPosBuf > 490 && vPosBuf < 493) ? 0 : 1;
vAct <= (hPosBuf<640) && (vPosBuf<480);
_rgb <= _txtRGB;
if (hPos == 799) begin
hPos = 0;
vPos = (vPos==524) ? 0 : vPos+1;
end
else hPos = hPos+1;
vCs = (hPos<640 && vPos<480) ? 0 : 1;
end
else if (clkDiv == 2'b00) begin
if (!lastSyEvtR && syEvtR) syRead <= 1;
else syRead <= 0;
if (!lastSyEvtW && syEvtW) syWrite <= 1;
else syWrite <= 0;
lastSyEvtW <= syEvtW;
lastSyEvtR <= syEvtR;
end
end
always @(negedge clk) begin
if (clkDiv == 2'b11) begin
hPosBuf <= hPos;
vPosBuf <= vPos;
_vDat <= sram_d;
end
else if (clkDiv == 2'b01 && syRead) _syDatOut <= sram_d;
end
reg [18:0] _syAdr;
reg [7:0] _syDatIn;
reg syEvtW,syEvtR;
always @(posedge syClk) begin
if (!syCs) begin
_syAdr <= syAdr;
if (syRw) syEvtR <= 1;
else syEvtR <= 0;
end
else syEvtR <= 0;
end
always @(negedge syClk) begin
if (!syRw && !syCs) begin
_syDatIn <= syDat;
syEvtW <= 1;
end
else syEvtW <= 0;
end
///////////////////////////////////////////Text Mode///////////////////////////////////////////
wire [11:0] _txtRGB;
textMode tm (
.vClk(clkDiv[1]),
.fontColors(clrReg),
.char(_vDat),
.row(hPos[2:0]),
.col(vPos[2:0]),
.pxOut(_txtRGB)
);
/////////////////////////////////////////Color Palette///////////////////////////////////////////
wire [11:0] _bmRGB;
colorPalette cp(
_vDat,
_bmRGB);
////////////////////////////////////HDMI Encoder////////////////////////////////////////////////
reg [11:0] _rgb;
hdmiEncoder enc(
.vClk(vClk),
.hdClk(hdmiClk),
.vSync(vSync),
.hSync(hSync),
.vAct(vAct),
.rgb(_rgb),
.TMDSp(TMDSp),
.TMDSn(TMDSn),
.TMDSp_Clk(TMDSp_clock),
.TMDSn_Clk(TMDSn_clock));
endmodule