SE-VGA/vgaout.sv

87 lines
2.4 KiB
Systemverilog
Raw Normal View History

2021-04-07 04:15:48 +00:00
/******************************************************************************
* SE-VGA
* VGA video output
* techav
* 2021-04-06
******************************************************************************
* Fetches video data from VRAM and shifts out
*****************************************************************************/
2021-04-12 04:46:29 +00:00
`include "primitives/primitives.sv"
2021-04-07 04:15:48 +00:00
module vgaout (
input wire pixClock,
input wire nReset,
input logic [9:0] hCount,
input logic [9:0] vCount,
input wire hSEActive,
input wire vSEActive,
2021-04-12 04:46:29 +00:00
input logic [7:0] vramData,
output logic [14:0] vramAddr,
2021-04-07 04:15:48 +00:00
output wire nvramOE,
output wire vidOut
);
reg [7:0] rVid;
wire vidMuxOut;
wire vidActive; // combined active video signal
2021-04-08 03:50:46 +00:00
wire vidMuxClk; // latch mux output just before updating rVid
2021-04-07 04:15:48 +00:00
2021-04-08 03:50:46 +00:00
// select bits 0..7 from the vram data in rVid, and latch if
// vidMuxClk goes high
mux8x1latch vidOutMux(rVid,hCount[2:0],vidMuxClk,nReset,vidMuxOut);
// vidMuxClk should be low during sequence 0..6, and high for 7
// this may lead to a race condition trying to change the mux
// before the output is latched. The alternative is to latch on
// the rising edge of pixClock during sequence 7, but then we may
// have a race condition with the data coming in from VRAM.
// What we really need is a half clock delay :-/
always_comb begin
if(hCount[2:0] == 3'd7) begin
vidMuxClk <= 1'b1;
end else begin
vidMuxClk <= 1'b0;
end
end
2021-04-07 04:15:48 +00:00
// latch incoming vram data on rising clock and sequence 7
always @(posedge pixClock or negedge nReset) begin
if(nReset == 1'b0) begin
rVid <= 8'h0;
end else begin
2021-04-12 04:46:29 +00:00
if(hCount[2:0] == 3'h7) begin
2021-04-07 04:15:48 +00:00
rVid <= vramData;
end
end
end
always_comb begin
// combined video active signal
if(hSEActive == 1'b1 && vSEActive == 1'b1) begin
vidActive <= 1'b1;
end else begin
vidActive <= 1'b0;
end
// video data output
if(vidActive == 1'b1) begin
vidOut <= vidMuxOut;
end else begin
vidOut <= 1'b0;
end
// vram read signal
2021-04-12 04:46:29 +00:00
if(vidActive == 1'b1 && hCount[2:0] == 3'h7) begin
2021-04-07 04:15:48 +00:00
nvramOE <= 1'b0;
end else begin
nvramOE <= 1'b1;
end
// vram address signals
// these will be mux'd with cpu addresses externally
2021-04-12 04:46:29 +00:00
vramAddr[14:6] <= vCount[8:0];
2021-04-07 04:15:48 +00:00
vramAddr[5:0] <= hCount[8:3];
end
endmodule