Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
Fix color expansion without the scandoubler
Browse files Browse the repository at this point in the history
  • Loading branch information
gyurco committed Jun 4, 2019
1 parent 23add9c commit 3dfec93
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
9 changes: 9 additions & 0 deletions Board/mist/mist.vhd
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
-- user_io
-- Interface to the MiST IO Controller

-- mist_video
-- A video pipeline for MiST. Just insert between the core video output and the VGA pins
-- Provides an optional scandoubler, a rotateable OSD and (optional) RGb->YPbPr conversion

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
Expand Down Expand Up @@ -45,6 +50,10 @@ component user_io

ps2_kbd_clk : out std_logic;
ps2_kbd_data : out std_logic;
key_pressed : out std_logic;
key_extended : out std_logic;
key_code : out std_logic_vector(7 downto 0);
key_strobe : out std_logic;

ps2_mouse_clk : out std_logic;
ps2_mouse_data : out std_logic;
Expand Down
32 changes: 28 additions & 4 deletions Board/mist/mist_video.v
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,38 @@ parameter OSD_COLOR = 3'd4;
parameter OSD_X_OFFSET = 10'd0;
parameter OSD_Y_OFFSET = 10'd0;
parameter SD_HCNT_WIDTH = 9;
parameter COLOR_DEPTH = 6; // 3-6
parameter COLOR_DEPTH = 6; // 1-6

wire [5:0] SD_R_O;
wire [5:0] SD_G_O;
wire [5:0] SD_B_O;
wire SD_HS_O;
wire SD_VS_O;

reg [5:0] R_full;
reg [5:0] G_full;
reg [5:0] B_full;

always @(*) begin
if (COLOR_DEPTH == 6) begin
R_full = R;
G_full = G;
B_full = B;
end else if (COLOR_DEPTH == 2) begin
R_full = {3{R}};
G_full = {3{G}};
B_full = {3{B}};
end else if (COLOR_DEPTH == 1) begin
R_full = {6{R}};
G_full = {6{G}};
B_full = {6{B}};
end else begin
R_full = { R, R[COLOR_DEPTH-1 -:(6-COLOR_DEPTH)] };
G_full = { G, G[COLOR_DEPTH-1 -:(6-COLOR_DEPTH)] };
B_full = { B, B[COLOR_DEPTH-1 -:(6-COLOR_DEPTH)] };
end
end

scandoubler #(SD_HCNT_WIDTH, COLOR_DEPTH) scandoubler
(
.clk_sys ( clk_sys ),
Expand Down Expand Up @@ -77,9 +101,9 @@ osd #(OSD_X_OFFSET, OSD_Y_OFFSET, OSD_COLOR) osd
.SPI_DI ( SPI_DI ),
.SPI_SCK ( SPI_SCK ),
.SPI_SS3 ( SPI_SS3 ),
.R_in ( scandoubler_disable ? R : SD_R_O ),
.G_in ( scandoubler_disable ? G : SD_G_O ),
.B_in ( scandoubler_disable ? B : SD_B_O ),
.R_in ( scandoubler_disable ? R_full : SD_R_O ),
.G_in ( scandoubler_disable ? G_full : SD_G_O ),
.B_in ( scandoubler_disable ? B_full : SD_B_O ),
.HSync ( scandoubler_disable ? HSync : SD_HS_O ),
.VSync ( scandoubler_disable ? VSync : SD_VS_O ),
.R_out ( osd_r_o ),
Expand Down
8 changes: 8 additions & 0 deletions Board/mist/scandoubler.v
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ always @(*) begin
b = sd_out[5:0];
g = sd_out[11:6];
r = sd_out[17:12];
end else if (COLOR_DEPTH == 2) begin
b = {3{sd_out[1:0]}};
g = {3{sd_out[3:2]}};
r = {3{sd_out[5:4]}};
end else if (COLOR_DEPTH == 1) begin
b = {6{sd_out[0]}};
g = {6{sd_out[1]}};
r = {6{sd_out[2]}};
end else begin
b = { sd_out[COLOR_DEPTH-1:0], sd_out[COLOR_DEPTH-1 -:(6-COLOR_DEPTH)] };
g = { sd_out[COLOR_DEPTH*2-1:COLOR_DEPTH], sd_out[COLOR_DEPTH*2-1 -:(6-COLOR_DEPTH)] };
Expand Down
22 changes: 22 additions & 0 deletions Board/mist/user_io.v
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ module user_io #(parameter STRLEN=0, parameter PS2DIV=100) (
output ps2_mouse_clk,
output reg ps2_mouse_data,

// keyboard data
output reg key_pressed, // 1-make (pressed), 0-break (released)
output reg key_extended, // extended code
output reg [7:0] key_code, // key scan code
output reg key_strobe, // key data valid

// mouse data
output reg [8:0] mouse_x,
output reg [8:0] mouse_y,
Expand Down Expand Up @@ -383,12 +389,16 @@ always @(posedge clk_sys) begin
reg [7:0] mouse_flags_r;
reg [7:0] mouse_x_r;

reg key_pressed_r;
reg key_extended_r;

//synchronize between SPI and sys clock domains
spi_receiver_strobeD <= spi_receiver_strobe_r;
spi_receiver_strobe <= spi_receiver_strobeD;
spi_transfer_endD <= spi_transfer_end_r;
spi_transfer_end <= spi_transfer_endD;

key_strobe <= 0;
mouse_strobe <= 0;

if (~spi_transfer_endD & spi_transfer_end) begin
Expand Down Expand Up @@ -427,6 +437,18 @@ always @(posedge clk_sys) begin
// store incoming ps2 keyboard bytes
ps2_kbd_fifo[ps2_kbd_wptr] <= spi_byte_in;
ps2_kbd_wptr <= ps2_kbd_wptr + 1'd1;
if (abyte_cnt == 1) begin
key_extended_r <= 0;
key_pressed_r <= 1;
end
if (spi_byte_in == 8'he0) key_extended_r <= 1'b1;
else if (spi_byte_in == 8'hf0) key_pressed_r <= 1'b0;
else begin
key_extended <= key_extended_r;
key_pressed <= key_pressed_r || abyte_cnt == 1;
key_code <= spi_byte_in;
key_strobe <= 1'b1;
end
end

// joystick analog
Expand Down

0 comments on commit 3dfec93

Please sign in to comment.