mirror of
https://github.com/Gehstock/Mist_FPGA.git
synced 2026-05-05 15:54:11 +00:00
Burning Rubber: update to common components
This commit is contained in:
@@ -41,32 +41,8 @@
|
|||||||
# ========================
|
# ========================
|
||||||
set_global_assignment -name ORIGINAL_QUARTUS_VERSION 15.1.0
|
set_global_assignment -name ORIGINAL_QUARTUS_VERSION 15.1.0
|
||||||
set_global_assignment -name PROJECT_CREATION_TIME_DATE "17:45:13 JUNE 17,2016"
|
set_global_assignment -name PROJECT_CREATION_TIME_DATE "17:45:13 JUNE 17,2016"
|
||||||
set_global_assignment -name LAST_QUARTUS_VERSION 13.1
|
set_global_assignment -name LAST_QUARTUS_VERSION "13.1 SP4.26"
|
||||||
set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files
|
set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files
|
||||||
set_global_assignment -name SYSTEMVERILOG_FILE rtl/burnin_rubber_mist.sv
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/burnin_rubber.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE "rtl/burnin_rubber _sound.vhd"
|
|
||||||
set_global_assignment -name VERILOG_FILE rtl/pll.v
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/YM2149_linmix_sep.vhd
|
|
||||||
set_global_assignment -name SYSTEMVERILOG_FILE rtl/video_mixer.sv
|
|
||||||
set_global_assignment -name VERILOG_FILE rtl/scandoubler.v
|
|
||||||
set_global_assignment -name VERILOG_FILE rtl/osd.v
|
|
||||||
set_global_assignment -name VERILOG_FILE rtl/mist_io.v
|
|
||||||
set_global_assignment -name VERILOG_FILE rtl/keyboard.v
|
|
||||||
set_global_assignment -name SYSTEMVERILOG_FILE rtl/hq2x.sv
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/gen_ram.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/dac.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/t65/T65_Pack.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/t65/T65_MCode.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/t65/T65_ALU.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/t65/T65.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/Roms/fg_sp_graphx_3.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/Roms/fg_sp_graphx_2.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/Roms/fg_sp_graphx_1.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/Roms/burnin_rubber_sound_prog.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/Roms/burnin_rubber_prog.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/Roms/bg_graphx_2.vhd
|
|
||||||
set_global_assignment -name VHDL_FILE rtl/Roms/bg_graphx_1.vhd
|
|
||||||
set_global_assignment -name PRE_FLOW_SCRIPT_FILE "quartus_sh:rtl/build_id.tcl"
|
set_global_assignment -name PRE_FLOW_SCRIPT_FILE "quartus_sh:rtl/build_id.tcl"
|
||||||
# Pin & Location Assignments
|
# Pin & Location Assignments
|
||||||
# ==========================
|
# ==========================
|
||||||
@@ -171,4 +147,20 @@ set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top
|
|||||||
|
|
||||||
# end ENTITY(burnin_rubber_mist)
|
# end ENTITY(burnin_rubber_mist)
|
||||||
# ------------------------------
|
# ------------------------------
|
||||||
|
set_global_assignment -name SYSTEMVERILOG_FILE rtl/burnin_rubber_mist.sv
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/burnin_rubber.vhd
|
||||||
|
set_global_assignment -name VHDL_FILE "rtl/burnin_rubber _sound.vhd"
|
||||||
|
set_global_assignment -name VERILOG_FILE rtl/pll.v
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/YM2149_linmix_sep.vhd
|
||||||
|
set_global_assignment -name VERILOG_FILE rtl/keyboard.v
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/gen_ram.vhd
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/Roms/fg_sp_graphx_3.vhd
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/Roms/fg_sp_graphx_2.vhd
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/Roms/fg_sp_graphx_1.vhd
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/Roms/burnin_rubber_sound_prog.vhd
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/Roms/burnin_rubber_prog.vhd
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/Roms/bg_graphx_2.vhd
|
||||||
|
set_global_assignment -name VHDL_FILE rtl/Roms/bg_graphx_1.vhd
|
||||||
|
set_global_assignment -name QIP_FILE ../../../common/CPU/T65/T65.qip
|
||||||
|
set_global_assignment -name QIP_FILE ../../../common/mist/mist.qip
|
||||||
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
|
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
## Generated SDC file "vectrex_MiST.out.sdc"
|
||||||
|
|
||||||
|
## Copyright (C) 1991-2013 Altera Corporation
|
||||||
|
## Your use of Altera Corporation's design tools, logic functions
|
||||||
|
## and other software and tools, and its AMPP partner logic
|
||||||
|
## functions, and any output files from any of the foregoing
|
||||||
|
## (including device programming or simulation files), and any
|
||||||
|
## associated documentation or information are expressly subject
|
||||||
|
## to the terms and conditions of the Altera Program License
|
||||||
|
## Subscription Agreement, Altera MegaCore Function License
|
||||||
|
## Agreement, or other applicable license agreement, including,
|
||||||
|
## without limitation, that your use is for the sole purpose of
|
||||||
|
## programming logic devices manufactured by Altera and sold by
|
||||||
|
## Altera or its authorized distributors. Please refer to the
|
||||||
|
## applicable agreement for further details.
|
||||||
|
|
||||||
|
|
||||||
|
## VENDOR "Altera"
|
||||||
|
## PROGRAM "Quartus II"
|
||||||
|
## VERSION "Version 13.1.0 Build 162 10/23/2013 SJ Web Edition"
|
||||||
|
|
||||||
|
## DATE "Sun Jun 24 12:53:00 2018"
|
||||||
|
|
||||||
|
##
|
||||||
|
## DEVICE "EP3C25E144C8"
|
||||||
|
##
|
||||||
|
|
||||||
|
# Clock constraints
|
||||||
|
|
||||||
|
# Automatically constrain PLL and other generated clocks
|
||||||
|
derive_pll_clocks -create_base_clocks
|
||||||
|
|
||||||
|
# Automatically calculate clock uncertainty to jitter and other effects.
|
||||||
|
derive_clock_uncertainty
|
||||||
|
|
||||||
|
# tsu/th constraints
|
||||||
|
|
||||||
|
# tco constraints
|
||||||
|
|
||||||
|
# tpd constraints
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Time Information
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
set_time_format -unit ns -decimal_places 3
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Create Clock
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
create_clock -name {SPI_SCK} -period 41.666 -waveform { 20.8 41.666 } [get_ports {SPI_SCK}]
|
||||||
|
|
||||||
|
set sys_clk "pll|altpll_component|auto_generated|pll1|clk[0]"
|
||||||
|
set vid_clk "pll|altpll_component|auto_generated|pll1|clk[1]"
|
||||||
|
set sdram_clk "pll|altpll_component|auto_generated|pll1|clk[1]"
|
||||||
|
#**************************************************************
|
||||||
|
# Create Generated Clock
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set Clock Latency
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set Clock Uncertainty
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set Input Delay
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
set_input_delay -add_delay -clock_fall -clock [get_clocks {CLOCK_27}] 1.000 [get_ports {CLOCK_27}]
|
||||||
|
set_input_delay -add_delay -clock_fall -clock [get_clocks {SPI_SCK}] 1.000 [get_ports {CONF_DATA0}]
|
||||||
|
set_input_delay -add_delay -clock_fall -clock [get_clocks {SPI_SCK}] 1.000 [get_ports {SPI_DI}]
|
||||||
|
set_input_delay -add_delay -clock_fall -clock [get_clocks {SPI_SCK}] 1.000 [get_ports {SPI_SCK}]
|
||||||
|
set_input_delay -add_delay -clock_fall -clock [get_clocks {SPI_SCK}] 1.000 [get_ports {SPI_SS2}]
|
||||||
|
set_input_delay -add_delay -clock_fall -clock [get_clocks {SPI_SCK}] 1.000 [get_ports {SPI_SS3}]
|
||||||
|
|
||||||
|
#set_input_delay -clock [get_clocks $sdram_clk] -reference_pin [get_ports {SDRAM_CLK}] -max 6.6 [get_ports SDRAM_DQ[*]]
|
||||||
|
#set_input_delay -clock [get_clocks $sdram_clk] -reference_pin [get_ports {SDRAM_CLK}] -min 3.5 [get_ports SDRAM_DQ[*]]
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set Output Delay
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
set_output_delay -add_delay -clock_fall -clock [get_clocks {SPI_SCK}] 1.000 [get_ports {SPI_DO}]
|
||||||
|
set_output_delay -add_delay -clock_fall -clock [get_clocks $sys_clk] 1.000 [get_ports {AUDIO_L}]
|
||||||
|
set_output_delay -add_delay -clock_fall -clock [get_clocks $sys_clk] 1.000 [get_ports {AUDIO_R}]
|
||||||
|
set_output_delay -add_delay -clock_fall -clock [get_clocks $sys_clk] 1.000 [get_ports {LED}]
|
||||||
|
set_output_delay -add_delay -clock_fall -clock [get_clocks $vid_clk] 1.000 [get_ports {VGA_*}]
|
||||||
|
|
||||||
|
#set_output_delay -clock [get_clocks $sdram_clk] -reference_pin [get_ports {SDRAM_CLK}] -max 1.5 [get_ports {SDRAM_D* SDRAM_A* SDRAM_BA* SDRAM_n* SDRAM_CKE}]
|
||||||
|
#set_output_delay -clock [get_clocks $sdram_clk] -reference_pin [get_ports {SDRAM_CLK}] -min -0.8 [get_ports {SDRAM_D* SDRAM_A* SDRAM_BA* SDRAM_n* SDRAM_CKE}]
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set Clock Groups
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
set_clock_groups -asynchronous -group [get_clocks {SPI_SCK}] -group [get_clocks {pll|altpll_component|auto_generated|pll1|clk[*]}]
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set False Path
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set Multicycle Path
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
set_multicycle_path -to {VGA_*[*]} -setup 2
|
||||||
|
set_multicycle_path -to {VGA_*[*]} -hold 1
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set Maximum Delay
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set Minimum Delay
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#**************************************************************
|
||||||
|
# Set Input Transition
|
||||||
|
#**************************************************************
|
||||||
|
|
||||||
@@ -20,9 +20,10 @@ module burnin_rubber_mist
|
|||||||
`include "rtl\build_id.v"
|
`include "rtl\build_id.v"
|
||||||
|
|
||||||
localparam CONF_STR = {
|
localparam CONF_STR = {
|
||||||
"Burn.Rubb;;",
|
"BurningR;;",
|
||||||
|
"O34,Scanlines,Off,25%,50%,75%;",
|
||||||
|
"O5,Blend,Off,On;",
|
||||||
"O2,Rotate Controls,Off,On;",
|
"O2,Rotate Controls,Off,On;",
|
||||||
"O34,Scandoubler Fx,None,HQ2x,CRT 25%,CRT 50%;",
|
|
||||||
"T6,Reset;",
|
"T6,Reset;",
|
||||||
"V,v1.10.",`BUILD_DATE
|
"V,v1.10.",`BUILD_DATE
|
||||||
};
|
};
|
||||||
@@ -33,7 +34,7 @@ wire [1:0] switches;
|
|||||||
wire [9:0] kbjoy;
|
wire [9:0] kbjoy;
|
||||||
wire [7:0] joystick_0;
|
wire [7:0] joystick_0;
|
||||||
wire [7:0] joystick_1;
|
wire [7:0] joystick_1;
|
||||||
wire scandoubler_disable;
|
wire scandoublerD;
|
||||||
wire ypbpr;
|
wire ypbpr;
|
||||||
wire ps2_kbd_clk, ps2_kbd_data;
|
wire ps2_kbd_clk, ps2_kbd_data;
|
||||||
|
|
||||||
@@ -45,10 +46,8 @@ wire pll_locked;
|
|||||||
pll pll(
|
pll pll(
|
||||||
.inclk0(CLOCK_27),
|
.inclk0(CLOCK_27),
|
||||||
.areset(0),
|
.areset(0),
|
||||||
.c0(clk_48),
|
.c0(clk_12),
|
||||||
.c1(clk_12),
|
.c1(clk_24),
|
||||||
.c2(clk_6),
|
|
||||||
.c3(clk_24)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
wire m_up = ~status[2] ? kbjoy[6] | joystick_0[1] | joystick_1[1] : kbjoy[4] | joystick_0[3] | joystick_1[3];
|
wire m_up = ~status[2] ? kbjoy[6] | joystick_0[1] | joystick_1[1] : kbjoy[4] | joystick_0[3] | joystick_1[3];
|
||||||
@@ -90,8 +89,8 @@ burnin_rubber burnin_rubber(
|
|||||||
|
|
||||||
wire [10:0] audio;
|
wire [10:0] audio;
|
||||||
|
|
||||||
dac dac(
|
dac #(11) dac(
|
||||||
.clk_i(clk_48),
|
.clk_i(clk_12),
|
||||||
.res_n_i(1),
|
.res_n_i(1),
|
||||||
.dac_i(audio),
|
.dac_i(audio),
|
||||||
.dac_o(AUDIO_L)
|
.dac_o(AUDIO_L)
|
||||||
@@ -104,59 +103,55 @@ wire [2:0] r, g;
|
|||||||
wire [1:0] b;
|
wire [1:0] b;
|
||||||
wire blankn;
|
wire blankn;
|
||||||
|
|
||||||
video_mixer #(
|
mist_video #(.COLOR_DEPTH(3), .SD_HCNT_WIDTH(10)) mist_video(
|
||||||
.LINE_LENGTH(320),
|
.clk_sys ( clk_24 ),
|
||||||
.HALF_DEPTH(1))
|
.SPI_SCK ( SPI_SCK ),
|
||||||
video_mixer(
|
.SPI_SS3 ( SPI_SS3 ),
|
||||||
.clk_sys(clk_48),
|
.SPI_DI ( SPI_DI ),
|
||||||
.ce_pix(clk_6),
|
.R ( blankn ? r : 0 ),
|
||||||
.ce_pix_actual(clk_6),
|
.G ( blankn ? g : 0 ),
|
||||||
.SPI_SCK(SPI_SCK),
|
.B ( blankn ? {b[1], b} : 0 ),
|
||||||
.SPI_SS3(SPI_SS3),
|
.HSync ( hs ),
|
||||||
.SPI_DI(SPI_DI),
|
.VSync ( vs ),
|
||||||
.R(blankn ? {r,r} : "000000"),
|
.VGA_R ( VGA_R ),
|
||||||
.G(blankn ? {g,g} : "000000"),
|
.VGA_G ( VGA_G ),
|
||||||
.B(blankn ? {b,b} : "0000"),
|
.VGA_B ( VGA_B ),
|
||||||
.HSync(hs),
|
.VGA_VS ( VGA_VS ),
|
||||||
.VSync(vs),
|
.VGA_HS ( VGA_HS ),
|
||||||
.VGA_R(VGA_R),
|
.rotate ( {1'b1,status[2]} ),
|
||||||
.VGA_G(VGA_G),
|
.ce_divider ( 1'b1 ),
|
||||||
.VGA_B(VGA_B),
|
.blend ( status[5] ),
|
||||||
.VGA_VS(VGA_VS),
|
.scandoubler_disable( scandoublerD ),
|
||||||
.VGA_HS(VGA_HS),
|
.no_csync ( 1'b0 ),
|
||||||
.rotate({1'b1,status[2]}),
|
.scanlines ( status[4:3] ),
|
||||||
.scandoubler_disable(scandoubler_disable),
|
.ypbpr ( ypbpr )
|
||||||
.scanlines(scandoubler_disable ? 2'b00 : {status[4:3] == 3, status[4:3] == 2}),
|
|
||||||
.hq2x(status[4:3]==1),
|
|
||||||
.ypbpr(ypbpr),
|
|
||||||
.ypbpr_full(1),
|
|
||||||
.line_start(0),
|
|
||||||
.mono(0)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
mist_io #(
|
user_io #(
|
||||||
.STRLEN(($size(CONF_STR)>>3)))
|
.STRLEN(($size(CONF_STR)>>3)))
|
||||||
mist_io(
|
user_io(
|
||||||
.clk_sys (clk_48 ),
|
.clk_sys (clk_12 ),
|
||||||
.conf_str (CONF_STR ),
|
.conf_str (CONF_STR ),
|
||||||
.SPI_SCK (SPI_SCK ),
|
.SPI_CLK (SPI_SCK ),
|
||||||
.CONF_DATA0 (CONF_DATA0 ),
|
.SPI_SS_IO (CONF_DATA0 ),
|
||||||
.SPI_SS2 (SPI_SS2 ),
|
.SPI_MISO (SPI_DO ),
|
||||||
.SPI_DO (SPI_DO ),
|
.SPI_MOSI (SPI_DI ),
|
||||||
.SPI_DI (SPI_DI ),
|
|
||||||
.buttons (buttons ),
|
.buttons (buttons ),
|
||||||
.switches (switches ),
|
.switches (switches ),
|
||||||
.scandoubler_disable(scandoubler_disable),
|
.scandoubler_disable (scandoublerD ),
|
||||||
.ypbpr (ypbpr ),
|
.ypbpr (ypbpr ),
|
||||||
|
.key_strobe (key_strobe ),
|
||||||
|
.key_pressed (key_pressed ),
|
||||||
|
.key_code (key_code ),
|
||||||
.ps2_kbd_clk (ps2_kbd_clk ),
|
.ps2_kbd_clk (ps2_kbd_clk ),
|
||||||
.ps2_kbd_data (ps2_kbd_data ),
|
.ps2_kbd_data (ps2_kbd_data ),
|
||||||
.joystick_0 (joystick_0 ),
|
.joystick_0 (joystick_0 ),
|
||||||
.joystick_1 (joystick_1 ),
|
.joystick_1 (joystick_1 ),
|
||||||
.status (status )
|
.status (status )
|
||||||
);
|
);
|
||||||
|
|
||||||
keyboard keyboard(
|
keyboard keyboard(
|
||||||
.clk(clk_48),
|
.clk(clk_12),
|
||||||
.reset(),
|
.reset(),
|
||||||
.ps2_kbd_clk(ps2_kbd_clk),
|
.ps2_kbd_clk(ps2_kbd_clk),
|
||||||
.ps2_kbd_data(ps2_kbd_data),
|
.ps2_kbd_data(ps2_kbd_data),
|
||||||
@@ -164,7 +159,3 @@ keyboard keyboard(
|
|||||||
);
|
);
|
||||||
|
|
||||||
endmodule
|
endmodule
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,71 +0,0 @@
|
|||||||
-------------------------------------------------------------------------------
|
|
||||||
--
|
|
||||||
-- Delta-Sigma DAC
|
|
||||||
--
|
|
||||||
-- $Id: dac.vhd,v 1.1 2005/10/25 21:09:42 arnim Exp $
|
|
||||||
--
|
|
||||||
-- Refer to Xilinx Application Note XAPP154.
|
|
||||||
--
|
|
||||||
-- This DAC requires an external RC low-pass filter:
|
|
||||||
--
|
|
||||||
-- dac_o 0---XXXXX---+---0 analog audio
|
|
||||||
-- 3k3 |
|
|
||||||
-- === 4n7
|
|
||||||
-- |
|
|
||||||
-- GND
|
|
||||||
--
|
|
||||||
-------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
library ieee;
|
|
||||||
use ieee.std_logic_1164.all;
|
|
||||||
|
|
||||||
entity dac is
|
|
||||||
|
|
||||||
generic (
|
|
||||||
msbi_g : integer := 11
|
|
||||||
);
|
|
||||||
port (
|
|
||||||
clk_i : in std_logic;
|
|
||||||
res_n_i : in std_logic;
|
|
||||||
dac_i : in std_logic_vector(msbi_g downto 0);
|
|
||||||
dac_o : out std_logic
|
|
||||||
);
|
|
||||||
|
|
||||||
end dac;
|
|
||||||
|
|
||||||
library ieee;
|
|
||||||
use ieee.numeric_std.all;
|
|
||||||
|
|
||||||
architecture rtl of dac is
|
|
||||||
|
|
||||||
signal DACout_q : std_logic;
|
|
||||||
signal DeltaAdder_s,
|
|
||||||
SigmaAdder_s,
|
|
||||||
SigmaLatch_q,
|
|
||||||
DeltaB_s : unsigned(msbi_g+2 downto 0);
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
DeltaB_s(msbi_g+2 downto msbi_g+1) <= SigmaLatch_q(msbi_g+2) &
|
|
||||||
SigmaLatch_q(msbi_g+2);
|
|
||||||
DeltaB_s(msbi_g downto 0) <= (others => '0');
|
|
||||||
|
|
||||||
DeltaAdder_s <= unsigned('0' & '0' & dac_i) + DeltaB_s;
|
|
||||||
|
|
||||||
SigmaAdder_s <= DeltaAdder_s + SigmaLatch_q;
|
|
||||||
|
|
||||||
seq: process (clk_i, res_n_i)
|
|
||||||
begin
|
|
||||||
if res_n_i = '0' then
|
|
||||||
SigmaLatch_q <= to_unsigned(2**(msbi_g+1), SigmaLatch_q'length);
|
|
||||||
DACout_q <= '0';
|
|
||||||
|
|
||||||
elsif clk_i'event and clk_i = '1' then
|
|
||||||
SigmaLatch_q <= SigmaAdder_s;
|
|
||||||
DACout_q <= SigmaLatch_q(msbi_g+2);
|
|
||||||
end if;
|
|
||||||
end process seq;
|
|
||||||
|
|
||||||
dac_o <= DACout_q;
|
|
||||||
|
|
||||||
end rtl;
|
|
||||||
@@ -1,454 +0,0 @@
|
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright (c) 2012-2013 Ludvig Strigeus
|
|
||||||
// Copyright (c) 2017 Sorgelig
|
|
||||||
//
|
|
||||||
// This program is GPL Licensed. See COPYING for the full license.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
// synopsys translate_off
|
|
||||||
`timescale 1 ps / 1 ps
|
|
||||||
// synopsys translate_on
|
|
||||||
|
|
||||||
`define BITS_TO_FIT(N) ( \
|
|
||||||
N <= 2 ? 0 : \
|
|
||||||
N <= 4 ? 1 : \
|
|
||||||
N <= 8 ? 2 : \
|
|
||||||
N <= 16 ? 3 : \
|
|
||||||
N <= 32 ? 4 : \
|
|
||||||
N <= 64 ? 5 : \
|
|
||||||
N <= 128 ? 6 : \
|
|
||||||
N <= 256 ? 7 : \
|
|
||||||
N <= 512 ? 8 : \
|
|
||||||
N <=1024 ? 9 : 10 )
|
|
||||||
|
|
||||||
module hq2x_in #(parameter LENGTH, parameter DWIDTH)
|
|
||||||
(
|
|
||||||
input clk,
|
|
||||||
|
|
||||||
input [AWIDTH:0] rdaddr,
|
|
||||||
input rdbuf,
|
|
||||||
output[DWIDTH:0] q,
|
|
||||||
|
|
||||||
input [AWIDTH:0] wraddr,
|
|
||||||
input wrbuf,
|
|
||||||
input [DWIDTH:0] data,
|
|
||||||
input wren
|
|
||||||
);
|
|
||||||
|
|
||||||
localparam AWIDTH = `BITS_TO_FIT(LENGTH);
|
|
||||||
wire [DWIDTH:0] out[2];
|
|
||||||
assign q = out[rdbuf];
|
|
||||||
|
|
||||||
hq2x_buf #(.NUMWORDS(LENGTH), .AWIDTH(AWIDTH), .DWIDTH(DWIDTH)) buf0(clk,data,rdaddr,wraddr,wren && (wrbuf == 0),out[0]);
|
|
||||||
hq2x_buf #(.NUMWORDS(LENGTH), .AWIDTH(AWIDTH), .DWIDTH(DWIDTH)) buf1(clk,data,rdaddr,wraddr,wren && (wrbuf == 1),out[1]);
|
|
||||||
endmodule
|
|
||||||
|
|
||||||
|
|
||||||
module hq2x_out #(parameter LENGTH, parameter DWIDTH)
|
|
||||||
(
|
|
||||||
input clk,
|
|
||||||
|
|
||||||
input [AWIDTH:0] rdaddr,
|
|
||||||
input [1:0] rdbuf,
|
|
||||||
output[DWIDTH:0] q,
|
|
||||||
|
|
||||||
input [AWIDTH:0] wraddr,
|
|
||||||
input [1:0] wrbuf,
|
|
||||||
input [DWIDTH:0] data,
|
|
||||||
input wren
|
|
||||||
);
|
|
||||||
|
|
||||||
localparam AWIDTH = `BITS_TO_FIT(LENGTH*2);
|
|
||||||
wire [DWIDTH:0] out[4];
|
|
||||||
assign q = out[rdbuf];
|
|
||||||
|
|
||||||
hq2x_buf #(.NUMWORDS(LENGTH*2), .AWIDTH(AWIDTH), .DWIDTH(DWIDTH)) buf0(clk,data,rdaddr,wraddr,wren && (wrbuf == 0),out[0]);
|
|
||||||
hq2x_buf #(.NUMWORDS(LENGTH*2), .AWIDTH(AWIDTH), .DWIDTH(DWIDTH)) buf1(clk,data,rdaddr,wraddr,wren && (wrbuf == 1),out[1]);
|
|
||||||
hq2x_buf #(.NUMWORDS(LENGTH*2), .AWIDTH(AWIDTH), .DWIDTH(DWIDTH)) buf2(clk,data,rdaddr,wraddr,wren && (wrbuf == 2),out[2]);
|
|
||||||
hq2x_buf #(.NUMWORDS(LENGTH*2), .AWIDTH(AWIDTH), .DWIDTH(DWIDTH)) buf3(clk,data,rdaddr,wraddr,wren && (wrbuf == 3),out[3]);
|
|
||||||
endmodule
|
|
||||||
|
|
||||||
|
|
||||||
module hq2x_buf #(parameter NUMWORDS, parameter AWIDTH, parameter DWIDTH)
|
|
||||||
(
|
|
||||||
input clock,
|
|
||||||
input [DWIDTH:0] data,
|
|
||||||
input [AWIDTH:0] rdaddress,
|
|
||||||
input [AWIDTH:0] wraddress,
|
|
||||||
input wren,
|
|
||||||
output [DWIDTH:0] q
|
|
||||||
);
|
|
||||||
|
|
||||||
altsyncram altsyncram_component (
|
|
||||||
.address_a (wraddress),
|
|
||||||
.clock0 (clock),
|
|
||||||
.data_a (data),
|
|
||||||
.wren_a (wren),
|
|
||||||
.address_b (rdaddress),
|
|
||||||
.q_b(q),
|
|
||||||
.aclr0 (1'b0),
|
|
||||||
.aclr1 (1'b0),
|
|
||||||
.addressstall_a (1'b0),
|
|
||||||
.addressstall_b (1'b0),
|
|
||||||
.byteena_a (1'b1),
|
|
||||||
.byteena_b (1'b1),
|
|
||||||
.clock1 (1'b1),
|
|
||||||
.clocken0 (1'b1),
|
|
||||||
.clocken1 (1'b1),
|
|
||||||
.clocken2 (1'b1),
|
|
||||||
.clocken3 (1'b1),
|
|
||||||
.data_b ({(DWIDTH+1){1'b1}}),
|
|
||||||
.eccstatus (),
|
|
||||||
.q_a (),
|
|
||||||
.rden_a (1'b1),
|
|
||||||
.rden_b (1'b1),
|
|
||||||
.wren_b (1'b0));
|
|
||||||
defparam
|
|
||||||
altsyncram_component.address_aclr_b = "NONE",
|
|
||||||
altsyncram_component.address_reg_b = "CLOCK0",
|
|
||||||
altsyncram_component.clock_enable_input_a = "BYPASS",
|
|
||||||
altsyncram_component.clock_enable_input_b = "BYPASS",
|
|
||||||
altsyncram_component.clock_enable_output_b = "BYPASS",
|
|
||||||
altsyncram_component.intended_device_family = "Cyclone III",
|
|
||||||
altsyncram_component.lpm_type = "altsyncram",
|
|
||||||
altsyncram_component.numwords_a = NUMWORDS,
|
|
||||||
altsyncram_component.numwords_b = NUMWORDS,
|
|
||||||
altsyncram_component.operation_mode = "DUAL_PORT",
|
|
||||||
altsyncram_component.outdata_aclr_b = "NONE",
|
|
||||||
altsyncram_component.outdata_reg_b = "UNREGISTERED",
|
|
||||||
altsyncram_component.power_up_uninitialized = "FALSE",
|
|
||||||
altsyncram_component.read_during_write_mode_mixed_ports = "DONT_CARE",
|
|
||||||
altsyncram_component.widthad_a = AWIDTH+1,
|
|
||||||
altsyncram_component.widthad_b = AWIDTH+1,
|
|
||||||
altsyncram_component.width_a = DWIDTH+1,
|
|
||||||
altsyncram_component.width_b = DWIDTH+1,
|
|
||||||
altsyncram_component.width_byteena_a = 1;
|
|
||||||
|
|
||||||
endmodule
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
module DiffCheck
|
|
||||||
(
|
|
||||||
input [17:0] rgb1,
|
|
||||||
input [17:0] rgb2,
|
|
||||||
output result
|
|
||||||
);
|
|
||||||
|
|
||||||
wire [5:0] r = rgb1[5:1] - rgb2[5:1];
|
|
||||||
wire [5:0] g = rgb1[11:7] - rgb2[11:7];
|
|
||||||
wire [5:0] b = rgb1[17:13] - rgb2[17:13];
|
|
||||||
wire [6:0] t = $signed(r) + $signed(b);
|
|
||||||
wire [6:0] gx = {g[5], g};
|
|
||||||
wire [7:0] y = $signed(t) + $signed(gx);
|
|
||||||
wire [6:0] u = $signed(r) - $signed(b);
|
|
||||||
wire [7:0] v = $signed({g, 1'b0}) - $signed(t);
|
|
||||||
|
|
||||||
// if y is inside (-24..24)
|
|
||||||
wire y_inside = (y < 8'h18 || y >= 8'he8);
|
|
||||||
|
|
||||||
// if u is inside (-4, 4)
|
|
||||||
wire u_inside = (u < 7'h4 || u >= 7'h7c);
|
|
||||||
|
|
||||||
// if v is inside (-6, 6)
|
|
||||||
wire v_inside = (v < 8'h6 || v >= 8'hfA);
|
|
||||||
assign result = !(y_inside && u_inside && v_inside);
|
|
||||||
endmodule
|
|
||||||
|
|
||||||
module InnerBlend
|
|
||||||
(
|
|
||||||
input [8:0] Op,
|
|
||||||
input [5:0] A,
|
|
||||||
input [5:0] B,
|
|
||||||
input [5:0] C,
|
|
||||||
output [5:0] O
|
|
||||||
);
|
|
||||||
|
|
||||||
function [8:0] mul6x3;
|
|
||||||
input [5:0] op1;
|
|
||||||
input [2:0] op2;
|
|
||||||
begin
|
|
||||||
mul6x3 = 9'd0;
|
|
||||||
if(op2[0]) mul6x3 = mul6x3 + op1;
|
|
||||||
if(op2[1]) mul6x3 = mul6x3 + {op1, 1'b0};
|
|
||||||
if(op2[2]) mul6x3 = mul6x3 + {op1, 2'b00};
|
|
||||||
end
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
wire OpOnes = Op[4];
|
|
||||||
wire [8:0] Amul = mul6x3(A, Op[7:5]);
|
|
||||||
wire [8:0] Bmul = mul6x3(B, {Op[3:2], 1'b0});
|
|
||||||
wire [8:0] Cmul = mul6x3(C, {Op[1:0], 1'b0});
|
|
||||||
wire [8:0] At = Amul;
|
|
||||||
wire [8:0] Bt = (OpOnes == 0) ? Bmul : {3'b0, B};
|
|
||||||
wire [8:0] Ct = (OpOnes == 0) ? Cmul : {3'b0, C};
|
|
||||||
wire [9:0] Res = {At, 1'b0} + Bt + Ct;
|
|
||||||
assign O = Op[8] ? A : Res[9:4];
|
|
||||||
endmodule
|
|
||||||
|
|
||||||
module Blend
|
|
||||||
(
|
|
||||||
input [5:0] rule,
|
|
||||||
input disable_hq2x,
|
|
||||||
input [17:0] E,
|
|
||||||
input [17:0] A,
|
|
||||||
input [17:0] B,
|
|
||||||
input [17:0] D,
|
|
||||||
input [17:0] F,
|
|
||||||
input [17:0] H,
|
|
||||||
output [17:0] Result
|
|
||||||
);
|
|
||||||
|
|
||||||
reg [1:0] input_ctrl;
|
|
||||||
reg [8:0] op;
|
|
||||||
localparam BLEND0 = 9'b1_xxx_x_xx_xx; // 0: A
|
|
||||||
localparam BLEND1 = 9'b0_110_0_10_00; // 1: (A * 12 + B * 4) >> 4
|
|
||||||
localparam BLEND2 = 9'b0_100_0_10_10; // 2: (A * 8 + B * 4 + C * 4) >> 4
|
|
||||||
localparam BLEND3 = 9'b0_101_0_10_01; // 3: (A * 10 + B * 4 + C * 2) >> 4
|
|
||||||
localparam BLEND4 = 9'b0_110_0_01_01; // 4: (A * 12 + B * 2 + C * 2) >> 4
|
|
||||||
localparam BLEND5 = 9'b0_010_0_11_11; // 5: (A * 4 + (B + C) * 6) >> 4
|
|
||||||
localparam BLEND6 = 9'b0_111_1_xx_xx; // 6: (A * 14 + B + C) >> 4
|
|
||||||
localparam AB = 2'b00;
|
|
||||||
localparam AD = 2'b01;
|
|
||||||
localparam DB = 2'b10;
|
|
||||||
localparam BD = 2'b11;
|
|
||||||
wire is_diff;
|
|
||||||
DiffCheck diff_checker(rule[1] ? B : H, rule[0] ? D : F, is_diff);
|
|
||||||
|
|
||||||
always @* begin
|
|
||||||
case({!is_diff, rule[5:2]})
|
|
||||||
1,17: {op, input_ctrl} = {BLEND1, AB};
|
|
||||||
2,18: {op, input_ctrl} = {BLEND1, DB};
|
|
||||||
3,19: {op, input_ctrl} = {BLEND1, BD};
|
|
||||||
4,20: {op, input_ctrl} = {BLEND2, DB};
|
|
||||||
5,21: {op, input_ctrl} = {BLEND2, AB};
|
|
||||||
6,22: {op, input_ctrl} = {BLEND2, AD};
|
|
||||||
|
|
||||||
8: {op, input_ctrl} = {BLEND0, 2'bxx};
|
|
||||||
9: {op, input_ctrl} = {BLEND0, 2'bxx};
|
|
||||||
10: {op, input_ctrl} = {BLEND0, 2'bxx};
|
|
||||||
11: {op, input_ctrl} = {BLEND1, AB};
|
|
||||||
12: {op, input_ctrl} = {BLEND1, AB};
|
|
||||||
13: {op, input_ctrl} = {BLEND1, AB};
|
|
||||||
14: {op, input_ctrl} = {BLEND1, DB};
|
|
||||||
15: {op, input_ctrl} = {BLEND1, BD};
|
|
||||||
|
|
||||||
24: {op, input_ctrl} = {BLEND2, DB};
|
|
||||||
25: {op, input_ctrl} = {BLEND5, DB};
|
|
||||||
26: {op, input_ctrl} = {BLEND6, DB};
|
|
||||||
27: {op, input_ctrl} = {BLEND2, DB};
|
|
||||||
28: {op, input_ctrl} = {BLEND4, DB};
|
|
||||||
29: {op, input_ctrl} = {BLEND5, DB};
|
|
||||||
30: {op, input_ctrl} = {BLEND3, BD};
|
|
||||||
31: {op, input_ctrl} = {BLEND3, DB};
|
|
||||||
default: {op, input_ctrl} = 11'bx;
|
|
||||||
endcase
|
|
||||||
|
|
||||||
// Setting op[8] effectively disables HQ2X because blend will always return E.
|
|
||||||
if (disable_hq2x) op[8] = 1;
|
|
||||||
end
|
|
||||||
|
|
||||||
// Generate inputs to the inner blender. Valid combinations.
|
|
||||||
// 00: E A B
|
|
||||||
// 01: E A D
|
|
||||||
// 10: E D B
|
|
||||||
// 11: E B D
|
|
||||||
wire [17:0] Input1 = E;
|
|
||||||
wire [17:0] Input2 = !input_ctrl[1] ? A :
|
|
||||||
!input_ctrl[0] ? D : B;
|
|
||||||
|
|
||||||
wire [17:0] Input3 = !input_ctrl[0] ? B : D;
|
|
||||||
InnerBlend inner_blend1(op, Input1[5:0], Input2[5:0], Input3[5:0], Result[5:0]);
|
|
||||||
InnerBlend inner_blend2(op, Input1[11:6], Input2[11:6], Input3[11:6], Result[11:6]);
|
|
||||||
InnerBlend inner_blend3(op, Input1[17:12], Input2[17:12], Input3[17:12], Result[17:12]);
|
|
||||||
endmodule
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
module Hq2x #(parameter LENGTH, parameter HALF_DEPTH)
|
|
||||||
(
|
|
||||||
input clk,
|
|
||||||
input ce_x4,
|
|
||||||
input [DWIDTH:0] inputpixel,
|
|
||||||
input mono,
|
|
||||||
input disable_hq2x,
|
|
||||||
input reset_frame,
|
|
||||||
input reset_line,
|
|
||||||
input [1:0] read_y,
|
|
||||||
input [AWIDTH+1:0] read_x,
|
|
||||||
output [DWIDTH:0] outpixel
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
localparam AWIDTH = `BITS_TO_FIT(LENGTH);
|
|
||||||
localparam DWIDTH = HALF_DEPTH ? 8 : 17;
|
|
||||||
|
|
||||||
wire [5:0] hqTable[256] = '{
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 47, 35, 23, 15, 55, 39,
|
|
||||||
19, 19, 26, 58, 19, 19, 26, 58, 23, 15, 35, 35, 23, 15, 7, 35,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 55, 39, 23, 15, 51, 43,
|
|
||||||
19, 19, 26, 58, 19, 19, 26, 58, 23, 15, 51, 35, 23, 15, 7, 43,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 61, 35, 35, 23, 61, 51, 35,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 51, 35, 23, 15, 51, 35,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 61, 7, 35, 23, 61, 7, 43,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 58, 23, 15, 51, 35, 23, 61, 7, 43,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 47, 35, 23, 15, 55, 39,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 51, 35, 23, 15, 51, 35,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 55, 39, 23, 15, 51, 43,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 51, 39, 23, 15, 7, 43,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 51, 35, 23, 15, 51, 39,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 51, 35, 23, 15, 7, 35,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 51, 35, 23, 15, 7, 43,
|
|
||||||
19, 19, 26, 11, 19, 19, 26, 11, 23, 15, 7, 35, 23, 15, 7, 43
|
|
||||||
};
|
|
||||||
|
|
||||||
reg [17:0] Prev0, Prev1, Prev2, Curr0, Curr1, Next0, Next1, Next2;
|
|
||||||
reg [17:0] A, B, D, F, G, H;
|
|
||||||
reg [7:0] pattern, nextpatt;
|
|
||||||
reg [1:0] i;
|
|
||||||
reg [7:0] y;
|
|
||||||
|
|
||||||
wire curbuf = y[0];
|
|
||||||
reg prevbuf = 0;
|
|
||||||
wire iobuf = !curbuf;
|
|
||||||
|
|
||||||
wire diff0, diff1;
|
|
||||||
DiffCheck diffcheck0(Curr1, (i == 0) ? Prev0 : (i == 1) ? Curr0 : (i == 2) ? Prev2 : Next1, diff0);
|
|
||||||
DiffCheck diffcheck1(Curr1, (i == 0) ? Prev1 : (i == 1) ? Next0 : (i == 2) ? Curr2 : Next2, diff1);
|
|
||||||
|
|
||||||
wire [7:0] new_pattern = {diff1, diff0, pattern[7:2]};
|
|
||||||
|
|
||||||
wire [17:0] X = (i == 0) ? A : (i == 1) ? Prev1 : (i == 2) ? Next1 : G;
|
|
||||||
wire [17:0] blend_result;
|
|
||||||
Blend blender(hqTable[nextpatt], disable_hq2x, Curr0, X, B, D, F, H, blend_result);
|
|
||||||
|
|
||||||
reg Curr2_addr1;
|
|
||||||
reg [AWIDTH:0] Curr2_addr2;
|
|
||||||
wire [17:0] Curr2 = HALF_DEPTH ? h2rgb(Curr2tmp) : Curr2tmp;
|
|
||||||
wire [DWIDTH:0] Curr2tmp;
|
|
||||||
|
|
||||||
reg [AWIDTH:0] wrin_addr2;
|
|
||||||
reg [DWIDTH:0] wrpix;
|
|
||||||
reg wrin_en;
|
|
||||||
|
|
||||||
function [17:0] h2rgb;
|
|
||||||
input [8:0] v;
|
|
||||||
begin
|
|
||||||
h2rgb = mono ? {v[5:3],v[2:0], v[5:3],v[2:0], v[5:3],v[2:0]} : {v[8:6],v[8:6],v[5:3],v[5:3],v[2:0],v[2:0]};
|
|
||||||
end
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function [8:0] rgb2h;
|
|
||||||
input [17:0] v;
|
|
||||||
begin
|
|
||||||
rgb2h = mono ? {3'b000, v[17:15], v[14:12]} : {v[17:15], v[11:9], v[5:3]};
|
|
||||||
end
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
hq2x_in #(.LENGTH(LENGTH), .DWIDTH(DWIDTH)) hq2x_in
|
|
||||||
(
|
|
||||||
.clk(clk),
|
|
||||||
|
|
||||||
.rdaddr(Curr2_addr2),
|
|
||||||
.rdbuf(Curr2_addr1),
|
|
||||||
.q(Curr2tmp),
|
|
||||||
|
|
||||||
.wraddr(wrin_addr2),
|
|
||||||
.wrbuf(iobuf),
|
|
||||||
.data(wrpix),
|
|
||||||
.wren(wrin_en)
|
|
||||||
);
|
|
||||||
|
|
||||||
reg [1:0] wrout_addr1;
|
|
||||||
reg [AWIDTH+1:0] wrout_addr2;
|
|
||||||
reg wrout_en;
|
|
||||||
reg [DWIDTH:0] wrdata;
|
|
||||||
|
|
||||||
hq2x_out #(.LENGTH(LENGTH), .DWIDTH(DWIDTH)) hq2x_out
|
|
||||||
(
|
|
||||||
.clk(clk),
|
|
||||||
|
|
||||||
.rdaddr(read_x),
|
|
||||||
.rdbuf(read_y),
|
|
||||||
.q(outpixel),
|
|
||||||
|
|
||||||
.wraddr(wrout_addr2),
|
|
||||||
.wrbuf(wrout_addr1),
|
|
||||||
.data(wrdata),
|
|
||||||
.wren(wrout_en)
|
|
||||||
);
|
|
||||||
|
|
||||||
always @(posedge clk) begin
|
|
||||||
reg [AWIDTH:0] offs;
|
|
||||||
reg old_reset_line;
|
|
||||||
reg old_reset_frame;
|
|
||||||
|
|
||||||
wrout_en <= 0;
|
|
||||||
wrin_en <= 0;
|
|
||||||
|
|
||||||
if(ce_x4) begin
|
|
||||||
|
|
||||||
pattern <= new_pattern;
|
|
||||||
|
|
||||||
if(~&offs) begin
|
|
||||||
if (i == 0) begin
|
|
||||||
Curr2_addr1 <= prevbuf;
|
|
||||||
Curr2_addr2 <= offs;
|
|
||||||
end
|
|
||||||
if (i == 1) begin
|
|
||||||
Prev2 <= Curr2;
|
|
||||||
Curr2_addr1 <= curbuf;
|
|
||||||
Curr2_addr2 <= offs;
|
|
||||||
end
|
|
||||||
if (i == 2) begin
|
|
||||||
Next2 <= HALF_DEPTH ? h2rgb(inputpixel) : inputpixel;
|
|
||||||
wrpix <= inputpixel;
|
|
||||||
wrin_addr2 <= offs;
|
|
||||||
wrin_en <= 1;
|
|
||||||
end
|
|
||||||
if (i == 3) begin
|
|
||||||
offs <= offs + 1'd1;
|
|
||||||
end
|
|
||||||
|
|
||||||
if(HALF_DEPTH) wrdata <= rgb2h(blend_result);
|
|
||||||
else wrdata <= blend_result;
|
|
||||||
|
|
||||||
wrout_addr1 <= {curbuf, i[1]};
|
|
||||||
wrout_addr2 <= {offs, i[1]^i[0]};
|
|
||||||
wrout_en <= 1;
|
|
||||||
end
|
|
||||||
|
|
||||||
if(i==3) begin
|
|
||||||
nextpatt <= {new_pattern[7:6], new_pattern[3], new_pattern[5], new_pattern[2], new_pattern[4], new_pattern[1:0]};
|
|
||||||
{A, G} <= {Prev0, Next0};
|
|
||||||
{B, F, H, D} <= {Prev1, Curr2, Next1, Curr0};
|
|
||||||
{Prev0, Prev1} <= {Prev1, Prev2};
|
|
||||||
{Curr0, Curr1} <= {Curr1, Curr2};
|
|
||||||
{Next0, Next1} <= {Next1, Next2};
|
|
||||||
end else begin
|
|
||||||
nextpatt <= {nextpatt[5], nextpatt[3], nextpatt[0], nextpatt[6], nextpatt[1], nextpatt[7], nextpatt[4], nextpatt[2]};
|
|
||||||
{B, F, H, D} <= {F, H, D, B};
|
|
||||||
end
|
|
||||||
|
|
||||||
i <= i + 1'b1;
|
|
||||||
if(old_reset_line && ~reset_line) begin
|
|
||||||
old_reset_frame <= reset_frame;
|
|
||||||
offs <= 0;
|
|
||||||
i <= 0;
|
|
||||||
y <= y + 1'd1;
|
|
||||||
prevbuf <= curbuf;
|
|
||||||
if(old_reset_frame & ~reset_frame) begin
|
|
||||||
y <= 0;
|
|
||||||
prevbuf <= 0;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
old_reset_line <= reset_line;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
endmodule // Hq2x
|
|
||||||
@@ -1,491 +0,0 @@
|
|||||||
//
|
|
||||||
// mist_io.v
|
|
||||||
//
|
|
||||||
// mist_io for the MiST board
|
|
||||||
// http://code.google.com/p/mist-board/
|
|
||||||
//
|
|
||||||
// Copyright (c) 2014 Till Harbaum <till@harbaum.org>
|
|
||||||
//
|
|
||||||
// This source file is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published
|
|
||||||
// by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This source file is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//
|
|
||||||
// Use buffer to access SD card. It's time-critical part.
|
|
||||||
// Made module synchroneous with 2 clock domains: clk_sys and SPI_SCK
|
|
||||||
// (Sorgelig)
|
|
||||||
//
|
|
||||||
// for synchronous projects default value for PS2DIV is fine for any frequency of system clock.
|
|
||||||
// clk_ps2 = clk_sys/(PS2DIV*2)
|
|
||||||
//
|
|
||||||
|
|
||||||
module mist_io #(parameter STRLEN=0, parameter PS2DIV=100)
|
|
||||||
(
|
|
||||||
|
|
||||||
// parameter STRLEN and the actual length of conf_str have to match
|
|
||||||
input [(8*STRLEN)-1:0] conf_str,
|
|
||||||
|
|
||||||
// Global clock. It should be around 100MHz (higher is better).
|
|
||||||
input clk_sys,
|
|
||||||
|
|
||||||
// Global SPI clock from ARM. 24MHz
|
|
||||||
input SPI_SCK,
|
|
||||||
|
|
||||||
input CONF_DATA0,
|
|
||||||
input SPI_SS2,
|
|
||||||
output SPI_DO,
|
|
||||||
input SPI_DI,
|
|
||||||
|
|
||||||
output reg [7:0] joystick_0,
|
|
||||||
output reg [7:0] joystick_1,
|
|
||||||
output reg [15:0] joystick_analog_0,
|
|
||||||
output reg [15:0] joystick_analog_1,
|
|
||||||
output [1:0] buttons,
|
|
||||||
output [1:0] switches,
|
|
||||||
output scandoubler_disable,
|
|
||||||
output ypbpr,
|
|
||||||
|
|
||||||
output reg [31:0] status,
|
|
||||||
|
|
||||||
// SD config
|
|
||||||
input sd_conf,
|
|
||||||
input sd_sdhc,
|
|
||||||
output img_mounted, // signaling that new image has been mounted
|
|
||||||
output reg [31:0] img_size, // size of image in bytes
|
|
||||||
|
|
||||||
// SD block level access
|
|
||||||
input [31:0] sd_lba,
|
|
||||||
input sd_rd,
|
|
||||||
input sd_wr,
|
|
||||||
output reg sd_ack,
|
|
||||||
output reg sd_ack_conf,
|
|
||||||
|
|
||||||
// SD byte level access. Signals for 2-PORT altsyncram.
|
|
||||||
output reg [8:0] sd_buff_addr,
|
|
||||||
output reg [7:0] sd_buff_dout,
|
|
||||||
input [7:0] sd_buff_din,
|
|
||||||
output reg sd_buff_wr,
|
|
||||||
|
|
||||||
// ps2 keyboard emulation
|
|
||||||
output ps2_kbd_clk,
|
|
||||||
output reg ps2_kbd_data,
|
|
||||||
output ps2_mouse_clk,
|
|
||||||
output reg ps2_mouse_data,
|
|
||||||
input ps2_caps_led,
|
|
||||||
|
|
||||||
// ARM -> FPGA download
|
|
||||||
output reg ioctl_download = 0, // signal indicating an active download
|
|
||||||
output reg [7:0] ioctl_index, // menu index used to upload the file
|
|
||||||
output ioctl_wr,
|
|
||||||
output reg [24:0] ioctl_addr,
|
|
||||||
output reg [7:0] ioctl_dout
|
|
||||||
);
|
|
||||||
|
|
||||||
reg [7:0] b_data;
|
|
||||||
reg [6:0] sbuf;
|
|
||||||
reg [7:0] cmd;
|
|
||||||
reg [2:0] bit_cnt; // counts bits 0-7 0-7 ...
|
|
||||||
reg [9:0] byte_cnt; // counts bytes
|
|
||||||
reg [7:0] but_sw;
|
|
||||||
reg [2:0] stick_idx;
|
|
||||||
|
|
||||||
reg mount_strobe = 0;
|
|
||||||
assign img_mounted = mount_strobe;
|
|
||||||
|
|
||||||
assign buttons = but_sw[1:0];
|
|
||||||
assign switches = but_sw[3:2];
|
|
||||||
assign scandoubler_disable = but_sw[4];
|
|
||||||
assign ypbpr = but_sw[5];
|
|
||||||
|
|
||||||
wire [7:0] spi_dout = { sbuf, SPI_DI};
|
|
||||||
|
|
||||||
// this variant of user_io is for 8 bit cores (type == a4) only
|
|
||||||
wire [7:0] core_type = 8'ha4;
|
|
||||||
|
|
||||||
// command byte read by the io controller
|
|
||||||
wire [7:0] sd_cmd = { 4'h5, sd_conf, sd_sdhc, sd_wr, sd_rd };
|
|
||||||
|
|
||||||
reg spi_do;
|
|
||||||
assign SPI_DO = CONF_DATA0 ? 1'bZ : spi_do;
|
|
||||||
|
|
||||||
wire [7:0] kbd_led = { 2'b01, 4'b0000, ps2_caps_led, 1'b1};
|
|
||||||
|
|
||||||
// drive MISO only when transmitting core id
|
|
||||||
always@(negedge SPI_SCK) begin
|
|
||||||
if(!CONF_DATA0) begin
|
|
||||||
// first byte returned is always core type, further bytes are
|
|
||||||
// command dependent
|
|
||||||
if(byte_cnt == 0) begin
|
|
||||||
spi_do <= core_type[~bit_cnt];
|
|
||||||
|
|
||||||
end else begin
|
|
||||||
case(cmd)
|
|
||||||
// reading config string
|
|
||||||
8'h14: begin
|
|
||||||
// returning a byte from string
|
|
||||||
if(byte_cnt < STRLEN + 1) spi_do <= conf_str[{STRLEN - byte_cnt,~bit_cnt}];
|
|
||||||
else spi_do <= 0;
|
|
||||||
end
|
|
||||||
|
|
||||||
// reading sd card status
|
|
||||||
8'h16: begin
|
|
||||||
if(byte_cnt == 1) spi_do <= sd_cmd[~bit_cnt];
|
|
||||||
else if((byte_cnt >= 2) && (byte_cnt < 6)) spi_do <= sd_lba[{5-byte_cnt, ~bit_cnt}];
|
|
||||||
else spi_do <= 0;
|
|
||||||
end
|
|
||||||
|
|
||||||
// reading sd card write data
|
|
||||||
8'h18:
|
|
||||||
spi_do <= b_data[~bit_cnt];
|
|
||||||
|
|
||||||
// reading keyboard LED status
|
|
||||||
8'h1f:
|
|
||||||
spi_do <= kbd_led[~bit_cnt];
|
|
||||||
|
|
||||||
default:
|
|
||||||
spi_do <= 0;
|
|
||||||
endcase
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
reg b_wr2,b_wr3;
|
|
||||||
always @(negedge clk_sys) begin
|
|
||||||
b_wr3 <= b_wr2;
|
|
||||||
sd_buff_wr <= b_wr3;
|
|
||||||
end
|
|
||||||
|
|
||||||
// SPI receiver
|
|
||||||
always@(posedge SPI_SCK or posedge CONF_DATA0) begin
|
|
||||||
|
|
||||||
if(CONF_DATA0) begin
|
|
||||||
b_wr2 <= 0;
|
|
||||||
bit_cnt <= 0;
|
|
||||||
byte_cnt <= 0;
|
|
||||||
sd_ack <= 0;
|
|
||||||
sd_ack_conf <= 0;
|
|
||||||
end else begin
|
|
||||||
b_wr2 <= 0;
|
|
||||||
|
|
||||||
sbuf <= spi_dout[6:0];
|
|
||||||
bit_cnt <= bit_cnt + 1'd1;
|
|
||||||
if(bit_cnt == 5) begin
|
|
||||||
if (byte_cnt == 0) sd_buff_addr <= 0;
|
|
||||||
if((byte_cnt != 0) & (sd_buff_addr != 511)) sd_buff_addr <= sd_buff_addr + 1'b1;
|
|
||||||
if((byte_cnt == 1) & ((cmd == 8'h17) | (cmd == 8'h19))) sd_buff_addr <= 0;
|
|
||||||
end
|
|
||||||
|
|
||||||
// finished reading command byte
|
|
||||||
if(bit_cnt == 7) begin
|
|
||||||
if(~&byte_cnt) byte_cnt <= byte_cnt + 8'd1;
|
|
||||||
if(byte_cnt == 0) begin
|
|
||||||
cmd <= spi_dout;
|
|
||||||
|
|
||||||
if(spi_dout == 8'h19) begin
|
|
||||||
sd_ack_conf <= 1;
|
|
||||||
sd_buff_addr <= 0;
|
|
||||||
end
|
|
||||||
if((spi_dout == 8'h17) || (spi_dout == 8'h18)) begin
|
|
||||||
sd_ack <= 1;
|
|
||||||
sd_buff_addr <= 0;
|
|
||||||
end
|
|
||||||
if(spi_dout == 8'h18) b_data <= sd_buff_din;
|
|
||||||
|
|
||||||
mount_strobe <= 0;
|
|
||||||
|
|
||||||
end else begin
|
|
||||||
|
|
||||||
case(cmd)
|
|
||||||
// buttons and switches
|
|
||||||
8'h01: but_sw <= spi_dout;
|
|
||||||
8'h02: joystick_0 <= spi_dout;
|
|
||||||
8'h03: joystick_1 <= spi_dout;
|
|
||||||
|
|
||||||
// store incoming ps2 mouse bytes
|
|
||||||
8'h04: begin
|
|
||||||
ps2_mouse_fifo[ps2_mouse_wptr] <= spi_dout;
|
|
||||||
ps2_mouse_wptr <= ps2_mouse_wptr + 1'd1;
|
|
||||||
end
|
|
||||||
|
|
||||||
// store incoming ps2 keyboard bytes
|
|
||||||
8'h05: begin
|
|
||||||
ps2_kbd_fifo[ps2_kbd_wptr] <= spi_dout;
|
|
||||||
ps2_kbd_wptr <= ps2_kbd_wptr + 1'd1;
|
|
||||||
end
|
|
||||||
|
|
||||||
8'h15: status[7:0] <= spi_dout;
|
|
||||||
|
|
||||||
// send SD config IO -> FPGA
|
|
||||||
// flag that download begins
|
|
||||||
// sd card knows data is config if sd_dout_strobe is asserted
|
|
||||||
// with sd_ack still being inactive (low)
|
|
||||||
8'h19,
|
|
||||||
// send sector IO -> FPGA
|
|
||||||
// flag that download begins
|
|
||||||
8'h17: begin
|
|
||||||
sd_buff_dout <= spi_dout;
|
|
||||||
b_wr2 <= 1;
|
|
||||||
end
|
|
||||||
|
|
||||||
8'h18: b_data <= sd_buff_din;
|
|
||||||
|
|
||||||
// joystick analog
|
|
||||||
8'h1a: begin
|
|
||||||
// first byte is joystick index
|
|
||||||
if(byte_cnt == 1) stick_idx <= spi_dout[2:0];
|
|
||||||
else if(byte_cnt == 2) begin
|
|
||||||
// second byte is x axis
|
|
||||||
if(stick_idx == 0) joystick_analog_0[15:8] <= spi_dout;
|
|
||||||
else if(stick_idx == 1) joystick_analog_1[15:8] <= spi_dout;
|
|
||||||
end else if(byte_cnt == 3) begin
|
|
||||||
// third byte is y axis
|
|
||||||
if(stick_idx == 0) joystick_analog_0[7:0] <= spi_dout;
|
|
||||||
else if(stick_idx == 1) joystick_analog_1[7:0] <= spi_dout;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
// notify image selection
|
|
||||||
8'h1c: mount_strobe <= 1;
|
|
||||||
|
|
||||||
// send image info
|
|
||||||
8'h1d: if(byte_cnt<5) img_size[(byte_cnt-1)<<3 +:8] <= spi_dout;
|
|
||||||
|
|
||||||
// status, 32bit version
|
|
||||||
8'h1e: if(byte_cnt<5) status[(byte_cnt-1)<<3 +:8] <= spi_dout;
|
|
||||||
default: ;
|
|
||||||
endcase
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////// PS2 ///////////////////////////////
|
|
||||||
// 8 byte fifos to store ps2 bytes
|
|
||||||
localparam PS2_FIFO_BITS = 3;
|
|
||||||
|
|
||||||
reg clk_ps2;
|
|
||||||
always @(negedge clk_sys) begin
|
|
||||||
integer cnt;
|
|
||||||
cnt <= cnt + 1'd1;
|
|
||||||
if(cnt == PS2DIV) begin
|
|
||||||
clk_ps2 <= ~clk_ps2;
|
|
||||||
cnt <= 0;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
// keyboard
|
|
||||||
reg [7:0] ps2_kbd_fifo[1<<PS2_FIFO_BITS];
|
|
||||||
reg [PS2_FIFO_BITS-1:0] ps2_kbd_wptr;
|
|
||||||
reg [PS2_FIFO_BITS-1:0] ps2_kbd_rptr;
|
|
||||||
|
|
||||||
// ps2 transmitter state machine
|
|
||||||
reg [3:0] ps2_kbd_tx_state;
|
|
||||||
reg [7:0] ps2_kbd_tx_byte;
|
|
||||||
reg ps2_kbd_parity;
|
|
||||||
|
|
||||||
assign ps2_kbd_clk = clk_ps2 || (ps2_kbd_tx_state == 0);
|
|
||||||
|
|
||||||
// ps2 transmitter
|
|
||||||
// Takes a byte from the FIFO and sends it in a ps2 compliant serial format.
|
|
||||||
reg ps2_kbd_r_inc;
|
|
||||||
always@(posedge clk_sys) begin
|
|
||||||
reg old_clk;
|
|
||||||
old_clk <= clk_ps2;
|
|
||||||
if(~old_clk & clk_ps2) begin
|
|
||||||
ps2_kbd_r_inc <= 0;
|
|
||||||
|
|
||||||
if(ps2_kbd_r_inc) ps2_kbd_rptr <= ps2_kbd_rptr + 1'd1;
|
|
||||||
|
|
||||||
// transmitter is idle?
|
|
||||||
if(ps2_kbd_tx_state == 0) begin
|
|
||||||
// data in fifo present?
|
|
||||||
if(ps2_kbd_wptr != ps2_kbd_rptr) begin
|
|
||||||
// load tx register from fifo
|
|
||||||
ps2_kbd_tx_byte <= ps2_kbd_fifo[ps2_kbd_rptr];
|
|
||||||
ps2_kbd_r_inc <= 1;
|
|
||||||
|
|
||||||
// reset parity
|
|
||||||
ps2_kbd_parity <= 1;
|
|
||||||
|
|
||||||
// start transmitter
|
|
||||||
ps2_kbd_tx_state <= 1;
|
|
||||||
|
|
||||||
// put start bit on data line
|
|
||||||
ps2_kbd_data <= 0; // start bit is 0
|
|
||||||
end
|
|
||||||
end else begin
|
|
||||||
|
|
||||||
// transmission of 8 data bits
|
|
||||||
if((ps2_kbd_tx_state >= 1)&&(ps2_kbd_tx_state < 9)) begin
|
|
||||||
ps2_kbd_data <= ps2_kbd_tx_byte[0]; // data bits
|
|
||||||
ps2_kbd_tx_byte[6:0] <= ps2_kbd_tx_byte[7:1]; // shift down
|
|
||||||
if(ps2_kbd_tx_byte[0])
|
|
||||||
ps2_kbd_parity <= !ps2_kbd_parity;
|
|
||||||
end
|
|
||||||
|
|
||||||
// transmission of parity
|
|
||||||
if(ps2_kbd_tx_state == 9) ps2_kbd_data <= ps2_kbd_parity;
|
|
||||||
|
|
||||||
// transmission of stop bit
|
|
||||||
if(ps2_kbd_tx_state == 10) ps2_kbd_data <= 1; // stop bit is 1
|
|
||||||
|
|
||||||
// advance state machine
|
|
||||||
if(ps2_kbd_tx_state < 11) ps2_kbd_tx_state <= ps2_kbd_tx_state + 1'd1;
|
|
||||||
else ps2_kbd_tx_state <= 0;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
// mouse
|
|
||||||
reg [7:0] ps2_mouse_fifo[1<<PS2_FIFO_BITS];
|
|
||||||
reg [PS2_FIFO_BITS-1:0] ps2_mouse_wptr;
|
|
||||||
reg [PS2_FIFO_BITS-1:0] ps2_mouse_rptr;
|
|
||||||
|
|
||||||
// ps2 transmitter state machine
|
|
||||||
reg [3:0] ps2_mouse_tx_state;
|
|
||||||
reg [7:0] ps2_mouse_tx_byte;
|
|
||||||
reg ps2_mouse_parity;
|
|
||||||
|
|
||||||
assign ps2_mouse_clk = clk_ps2 || (ps2_mouse_tx_state == 0);
|
|
||||||
|
|
||||||
// ps2 transmitter
|
|
||||||
// Takes a byte from the FIFO and sends it in a ps2 compliant serial format.
|
|
||||||
reg ps2_mouse_r_inc;
|
|
||||||
always@(posedge clk_sys) begin
|
|
||||||
reg old_clk;
|
|
||||||
old_clk <= clk_ps2;
|
|
||||||
if(~old_clk & clk_ps2) begin
|
|
||||||
ps2_mouse_r_inc <= 0;
|
|
||||||
|
|
||||||
if(ps2_mouse_r_inc) ps2_mouse_rptr <= ps2_mouse_rptr + 1'd1;
|
|
||||||
|
|
||||||
// transmitter is idle?
|
|
||||||
if(ps2_mouse_tx_state == 0) begin
|
|
||||||
// data in fifo present?
|
|
||||||
if(ps2_mouse_wptr != ps2_mouse_rptr) begin
|
|
||||||
// load tx register from fifo
|
|
||||||
ps2_mouse_tx_byte <= ps2_mouse_fifo[ps2_mouse_rptr];
|
|
||||||
ps2_mouse_r_inc <= 1;
|
|
||||||
|
|
||||||
// reset parity
|
|
||||||
ps2_mouse_parity <= 1;
|
|
||||||
|
|
||||||
// start transmitter
|
|
||||||
ps2_mouse_tx_state <= 1;
|
|
||||||
|
|
||||||
// put start bit on data line
|
|
||||||
ps2_mouse_data <= 0; // start bit is 0
|
|
||||||
end
|
|
||||||
end else begin
|
|
||||||
|
|
||||||
// transmission of 8 data bits
|
|
||||||
if((ps2_mouse_tx_state >= 1)&&(ps2_mouse_tx_state < 9)) begin
|
|
||||||
ps2_mouse_data <= ps2_mouse_tx_byte[0]; // data bits
|
|
||||||
ps2_mouse_tx_byte[6:0] <= ps2_mouse_tx_byte[7:1]; // shift down
|
|
||||||
if(ps2_mouse_tx_byte[0])
|
|
||||||
ps2_mouse_parity <= !ps2_mouse_parity;
|
|
||||||
end
|
|
||||||
|
|
||||||
// transmission of parity
|
|
||||||
if(ps2_mouse_tx_state == 9) ps2_mouse_data <= ps2_mouse_parity;
|
|
||||||
|
|
||||||
// transmission of stop bit
|
|
||||||
if(ps2_mouse_tx_state == 10) ps2_mouse_data <= 1; // stop bit is 1
|
|
||||||
|
|
||||||
// advance state machine
|
|
||||||
if(ps2_mouse_tx_state < 11) ps2_mouse_tx_state <= ps2_mouse_tx_state + 1'd1;
|
|
||||||
else ps2_mouse_tx_state <= 0;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////// DOWNLOADING ///////////////////////////////
|
|
||||||
|
|
||||||
reg [7:0] data_w;
|
|
||||||
reg [24:0] addr_w;
|
|
||||||
reg rclk = 0;
|
|
||||||
|
|
||||||
localparam UIO_FILE_TX = 8'h53;
|
|
||||||
localparam UIO_FILE_TX_DAT = 8'h54;
|
|
||||||
localparam UIO_FILE_INDEX = 8'h55;
|
|
||||||
|
|
||||||
// data_io has its own SPI interface to the io controller
|
|
||||||
always@(posedge SPI_SCK, posedge SPI_SS2) begin
|
|
||||||
reg [6:0] sbuf;
|
|
||||||
reg [7:0] cmd;
|
|
||||||
reg [4:0] cnt;
|
|
||||||
reg [24:0] addr;
|
|
||||||
|
|
||||||
if(SPI_SS2) cnt <= 0;
|
|
||||||
else begin
|
|
||||||
rclk <= 0;
|
|
||||||
|
|
||||||
// don't shift in last bit. It is evaluated directly
|
|
||||||
// when writing to ram
|
|
||||||
if(cnt != 15) sbuf <= { sbuf[5:0], SPI_DI};
|
|
||||||
|
|
||||||
// increase target address after write
|
|
||||||
if(rclk) addr <= addr + 1'd1;
|
|
||||||
|
|
||||||
// count 0-7 8-15 8-15 ...
|
|
||||||
if(cnt < 15) cnt <= cnt + 1'd1;
|
|
||||||
else cnt <= 8;
|
|
||||||
|
|
||||||
// finished command byte
|
|
||||||
if(cnt == 7) cmd <= {sbuf, SPI_DI};
|
|
||||||
|
|
||||||
// prepare/end transmission
|
|
||||||
if((cmd == UIO_FILE_TX) && (cnt == 15)) begin
|
|
||||||
// prepare
|
|
||||||
if(SPI_DI) begin
|
|
||||||
addr <= 0;
|
|
||||||
ioctl_download <= 1;
|
|
||||||
end else begin
|
|
||||||
addr_w <= addr;
|
|
||||||
ioctl_download <= 0;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
// command 0x54: UIO_FILE_TX
|
|
||||||
if((cmd == UIO_FILE_TX_DAT) && (cnt == 15)) begin
|
|
||||||
addr_w <= addr;
|
|
||||||
data_w <= {sbuf, SPI_DI};
|
|
||||||
rclk <= 1;
|
|
||||||
end
|
|
||||||
|
|
||||||
// expose file (menu) index
|
|
||||||
if((cmd == UIO_FILE_INDEX) && (cnt == 15)) ioctl_index <= {sbuf, SPI_DI};
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
assign ioctl_wr = |ioctl_wrd;
|
|
||||||
reg [1:0] ioctl_wrd;
|
|
||||||
|
|
||||||
always@(negedge clk_sys) begin
|
|
||||||
reg rclkD, rclkD2;
|
|
||||||
|
|
||||||
rclkD <= rclk;
|
|
||||||
rclkD2 <= rclkD;
|
|
||||||
ioctl_wrd<= {ioctl_wrd[0],1'b0};
|
|
||||||
|
|
||||||
if(rclkD & ~rclkD2) begin
|
|
||||||
ioctl_dout <= data_w;
|
|
||||||
ioctl_addr <= addr_w;
|
|
||||||
ioctl_wrd <= 2'b11;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
endmodule
|
|
||||||
@@ -1,194 +0,0 @@
|
|||||||
// A simple OSD implementation. Can be hooked up between a cores
|
|
||||||
// VGA output and the physical VGA pins
|
|
||||||
|
|
||||||
module osd (
|
|
||||||
// OSDs pixel clock, should be synchronous to cores pixel clock to
|
|
||||||
// avoid jitter.
|
|
||||||
input clk_sys,
|
|
||||||
|
|
||||||
// SPI interface
|
|
||||||
input SPI_SCK,
|
|
||||||
input SPI_SS3,
|
|
||||||
input SPI_DI,
|
|
||||||
|
|
||||||
input [1:0] rotate, //[0] - rotate [1] - left or right
|
|
||||||
|
|
||||||
// VGA signals coming from core
|
|
||||||
input [5:0] R_in,
|
|
||||||
input [5:0] G_in,
|
|
||||||
input [5:0] B_in,
|
|
||||||
input HSync,
|
|
||||||
input VSync,
|
|
||||||
|
|
||||||
// VGA signals going to video connector
|
|
||||||
output [5:0] R_out,
|
|
||||||
output [5:0] G_out,
|
|
||||||
output [5:0] B_out
|
|
||||||
);
|
|
||||||
|
|
||||||
parameter OSD_X_OFFSET = 10'd0;
|
|
||||||
parameter OSD_Y_OFFSET = 10'd0;
|
|
||||||
parameter OSD_COLOR = 3'd0;
|
|
||||||
|
|
||||||
localparam OSD_WIDTH = 10'd256;
|
|
||||||
localparam OSD_HEIGHT = 10'd128;
|
|
||||||
|
|
||||||
// *********************************************************************************
|
|
||||||
// spi client
|
|
||||||
// *********************************************************************************
|
|
||||||
|
|
||||||
// this core supports only the display related OSD commands
|
|
||||||
// of the minimig
|
|
||||||
reg osd_enable;
|
|
||||||
(* ramstyle = "no_rw_check" *) reg [7:0] osd_buffer[2047:0]; // the OSD buffer itself
|
|
||||||
|
|
||||||
// the OSD has its own SPI interface to the io controller
|
|
||||||
always@(posedge SPI_SCK, posedge SPI_SS3) begin
|
|
||||||
reg [4:0] cnt;
|
|
||||||
reg [10:0] bcnt;
|
|
||||||
reg [7:0] sbuf;
|
|
||||||
reg [7:0] cmd;
|
|
||||||
|
|
||||||
if(SPI_SS3) begin
|
|
||||||
cnt <= 0;
|
|
||||||
bcnt <= 0;
|
|
||||||
end else begin
|
|
||||||
sbuf <= {sbuf[6:0], SPI_DI};
|
|
||||||
|
|
||||||
// 0:7 is command, rest payload
|
|
||||||
if(cnt < 15) cnt <= cnt + 1'd1;
|
|
||||||
else cnt <= 8;
|
|
||||||
|
|
||||||
if(cnt == 7) begin
|
|
||||||
cmd <= {sbuf[6:0], SPI_DI};
|
|
||||||
|
|
||||||
// lower three command bits are line address
|
|
||||||
bcnt <= {sbuf[1:0], SPI_DI, 8'h00};
|
|
||||||
|
|
||||||
// command 0x40: OSDCMDENABLE, OSDCMDDISABLE
|
|
||||||
if(sbuf[6:3] == 4'b0100) osd_enable <= SPI_DI;
|
|
||||||
end
|
|
||||||
|
|
||||||
// command 0x20: OSDCMDWRITE
|
|
||||||
if((cmd[7:3] == 5'b00100) && (cnt == 15)) begin
|
|
||||||
osd_buffer[bcnt] <= {sbuf[6:0], SPI_DI};
|
|
||||||
bcnt <= bcnt + 1'd1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
// *********************************************************************************
|
|
||||||
// video timing and sync polarity anaylsis
|
|
||||||
// *********************************************************************************
|
|
||||||
|
|
||||||
// horizontal counter
|
|
||||||
reg [9:0] h_cnt;
|
|
||||||
reg [9:0] hs_low, hs_high;
|
|
||||||
wire hs_pol = hs_high < hs_low;
|
|
||||||
wire [9:0] dsp_width = hs_pol ? hs_low : hs_high;
|
|
||||||
|
|
||||||
// vertical counter
|
|
||||||
reg [9:0] v_cnt;
|
|
||||||
reg [9:0] vs_low, vs_high;
|
|
||||||
wire vs_pol = vs_high < vs_low;
|
|
||||||
wire [9:0] dsp_height = vs_pol ? vs_low : vs_high;
|
|
||||||
|
|
||||||
wire doublescan = (dsp_height>350);
|
|
||||||
|
|
||||||
reg ce_pix;
|
|
||||||
always @(negedge clk_sys) begin
|
|
||||||
integer cnt = 0;
|
|
||||||
integer pixsz, pixcnt;
|
|
||||||
reg hs;
|
|
||||||
|
|
||||||
cnt <= cnt + 1;
|
|
||||||
hs <= HSync;
|
|
||||||
|
|
||||||
pixcnt <= pixcnt + 1;
|
|
||||||
if(pixcnt == pixsz) pixcnt <= 0;
|
|
||||||
ce_pix <= !pixcnt;
|
|
||||||
|
|
||||||
if(hs && ~HSync) begin
|
|
||||||
cnt <= 0;
|
|
||||||
pixsz <= (cnt >> 9) - 1;
|
|
||||||
pixcnt <= 0;
|
|
||||||
ce_pix <= 1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
always @(posedge clk_sys) begin
|
|
||||||
reg hsD, hsD2;
|
|
||||||
reg vsD, vsD2;
|
|
||||||
|
|
||||||
if(ce_pix) begin
|
|
||||||
// bring hsync into local clock domain
|
|
||||||
hsD <= HSync;
|
|
||||||
hsD2 <= hsD;
|
|
||||||
|
|
||||||
// falling edge of HSync
|
|
||||||
if(!hsD && hsD2) begin
|
|
||||||
h_cnt <= 0;
|
|
||||||
hs_high <= h_cnt;
|
|
||||||
end
|
|
||||||
|
|
||||||
// rising edge of HSync
|
|
||||||
else if(hsD && !hsD2) begin
|
|
||||||
h_cnt <= 0;
|
|
||||||
hs_low <= h_cnt;
|
|
||||||
v_cnt <= v_cnt + 1'd1;
|
|
||||||
end else begin
|
|
||||||
h_cnt <= h_cnt + 1'd1;
|
|
||||||
end
|
|
||||||
|
|
||||||
vsD <= VSync;
|
|
||||||
vsD2 <= vsD;
|
|
||||||
|
|
||||||
// falling edge of VSync
|
|
||||||
if(!vsD && vsD2) begin
|
|
||||||
v_cnt <= 0;
|
|
||||||
vs_high <= v_cnt;
|
|
||||||
end
|
|
||||||
|
|
||||||
// rising edge of VSync
|
|
||||||
else if(vsD && !vsD2) begin
|
|
||||||
v_cnt <= 0;
|
|
||||||
vs_low <= v_cnt;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
// area in which OSD is being displayed
|
|
||||||
wire [9:0] h_osd_start = ((dsp_width - OSD_WIDTH)>> 1) + OSD_X_OFFSET;
|
|
||||||
wire [9:0] h_osd_end = h_osd_start + OSD_WIDTH;
|
|
||||||
wire [9:0] v_osd_start = ((dsp_height- (OSD_HEIGHT<<doublescan))>> 1) + OSD_Y_OFFSET;
|
|
||||||
wire [9:0] v_osd_end = v_osd_start + (OSD_HEIGHT<<doublescan);
|
|
||||||
wire [9:0] osd_hcnt = h_cnt - h_osd_start;
|
|
||||||
wire [9:0] osd_vcnt = v_cnt - v_osd_start;
|
|
||||||
wire [9:0] osd_hcnt_next = osd_hcnt + 2'd1; // one pixel offset for osd pixel
|
|
||||||
wire [9:0] osd_hcnt_next2 = osd_hcnt + 2'd2; // two pixel offset for osd byte address register
|
|
||||||
|
|
||||||
wire osd_de = osd_enable &&
|
|
||||||
(HSync != hs_pol) && (h_cnt >= h_osd_start) && (h_cnt < h_osd_end) &&
|
|
||||||
(VSync != vs_pol) && (v_cnt >= v_osd_start) && (v_cnt < v_osd_end);
|
|
||||||
|
|
||||||
reg [10:0] osd_buffer_addr;
|
|
||||||
wire [7:0] osd_byte = osd_buffer[osd_buffer_addr];
|
|
||||||
reg osd_pixel;
|
|
||||||
|
|
||||||
always @(posedge clk_sys) begin
|
|
||||||
if(ce_pix) begin
|
|
||||||
osd_buffer_addr <= rotate[0] ? {rotate[1] ? osd_hcnt_next2[7:5] : ~osd_hcnt_next2[7:5],
|
|
||||||
rotate[1] ? (doublescan ? ~osd_vcnt[7:0] : ~{osd_vcnt[6:0], 1'b0}) :
|
|
||||||
(doublescan ? osd_vcnt[7:0] : {osd_vcnt[6:0], 1'b0})} :
|
|
||||||
{doublescan ? osd_vcnt[7:5] : osd_vcnt[6:4], osd_hcnt_next2[7:0]};
|
|
||||||
|
|
||||||
osd_pixel <= rotate[0] ? osd_byte[rotate[1] ? osd_hcnt_next[4:2] : ~osd_hcnt_next[4:2]] :
|
|
||||||
osd_byte[doublescan ? osd_vcnt[4:2] : osd_vcnt[3:1]];
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
assign R_out = !osd_de ? R_in : {osd_pixel, osd_pixel, OSD_COLOR[2], R_in[5:3]};
|
|
||||||
assign G_out = !osd_de ? G_in : {osd_pixel, osd_pixel, OSD_COLOR[1], G_in[5:3]};
|
|
||||||
assign B_out = !osd_de ? B_in : {osd_pixel, osd_pixel, OSD_COLOR[0], B_in[5:3]};
|
|
||||||
|
|
||||||
endmodule
|
|
||||||
@@ -14,11 +14,11 @@
|
|||||||
// ************************************************************
|
// ************************************************************
|
||||||
// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
|
// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
|
||||||
//
|
//
|
||||||
// 13.1.0 Build 162 10/23/2013 SJ Web Edition
|
// 13.1.4 Build 182 03/12/2014 Patches 4.26 SJ Web Edition
|
||||||
// ************************************************************
|
// ************************************************************
|
||||||
|
|
||||||
|
|
||||||
//Copyright (C) 1991-2013 Altera Corporation
|
//Copyright (C) 1991-2014 Altera Corporation
|
||||||
//Your use of Altera Corporation's design tools, logic functions
|
//Your use of Altera Corporation's design tools, logic functions
|
||||||
//and other software and tools, and its AMPP partner logic
|
//and other software and tools, and its AMPP partner logic
|
||||||
//functions, and any output files from any of the foregoing
|
//functions, and any output files from any of the foregoing
|
||||||
@@ -40,16 +40,12 @@ module pll (
|
|||||||
areset,
|
areset,
|
||||||
inclk0,
|
inclk0,
|
||||||
c0,
|
c0,
|
||||||
c1,
|
c1);
|
||||||
c2,
|
|
||||||
c3);
|
|
||||||
|
|
||||||
input areset;
|
input areset;
|
||||||
input inclk0;
|
input inclk0;
|
||||||
output c0;
|
output c0;
|
||||||
output c1;
|
output c1;
|
||||||
output c2;
|
|
||||||
output c3;
|
|
||||||
`ifndef ALTERA_RESERVED_QIS
|
`ifndef ALTERA_RESERVED_QIS
|
||||||
// synopsys translate_off
|
// synopsys translate_off
|
||||||
`endif
|
`endif
|
||||||
@@ -59,21 +55,17 @@ module pll (
|
|||||||
`endif
|
`endif
|
||||||
|
|
||||||
wire [4:0] sub_wire0;
|
wire [4:0] sub_wire0;
|
||||||
wire [0:0] sub_wire7 = 1'h0;
|
wire [0:0] sub_wire5 = 1'h0;
|
||||||
wire [2:2] sub_wire4 = sub_wire0[2:2];
|
wire [0:0] sub_wire2 = sub_wire0[0:0];
|
||||||
wire [0:0] sub_wire3 = sub_wire0[0:0];
|
|
||||||
wire [3:3] sub_wire2 = sub_wire0[3:3];
|
|
||||||
wire [1:1] sub_wire1 = sub_wire0[1:1];
|
wire [1:1] sub_wire1 = sub_wire0[1:1];
|
||||||
wire c1 = sub_wire1;
|
wire c1 = sub_wire1;
|
||||||
wire c3 = sub_wire2;
|
wire c0 = sub_wire2;
|
||||||
wire c0 = sub_wire3;
|
wire sub_wire3 = inclk0;
|
||||||
wire c2 = sub_wire4;
|
wire [1:0] sub_wire4 = {sub_wire5, sub_wire3};
|
||||||
wire sub_wire5 = inclk0;
|
|
||||||
wire [1:0] sub_wire6 = {sub_wire7, sub_wire5};
|
|
||||||
|
|
||||||
altpll altpll_component (
|
altpll altpll_component (
|
||||||
.areset (areset),
|
.areset (areset),
|
||||||
.inclk (sub_wire6),
|
.inclk (sub_wire4),
|
||||||
.clk (sub_wire0),
|
.clk (sub_wire0),
|
||||||
.activeclock (),
|
.activeclock (),
|
||||||
.clkbad (),
|
.clkbad (),
|
||||||
@@ -113,20 +105,12 @@ module pll (
|
|||||||
altpll_component.bandwidth_type = "AUTO",
|
altpll_component.bandwidth_type = "AUTO",
|
||||||
altpll_component.clk0_divide_by = 9,
|
altpll_component.clk0_divide_by = 9,
|
||||||
altpll_component.clk0_duty_cycle = 50,
|
altpll_component.clk0_duty_cycle = 50,
|
||||||
altpll_component.clk0_multiply_by = 16,
|
altpll_component.clk0_multiply_by = 4,
|
||||||
altpll_component.clk0_phase_shift = "0",
|
altpll_component.clk0_phase_shift = "0",
|
||||||
altpll_component.clk1_divide_by = 9,
|
altpll_component.clk1_divide_by = 9,
|
||||||
altpll_component.clk1_duty_cycle = 50,
|
altpll_component.clk1_duty_cycle = 50,
|
||||||
altpll_component.clk1_multiply_by = 4,
|
altpll_component.clk1_multiply_by = 8,
|
||||||
altpll_component.clk1_phase_shift = "0",
|
altpll_component.clk1_phase_shift = "0",
|
||||||
altpll_component.clk2_divide_by = 9,
|
|
||||||
altpll_component.clk2_duty_cycle = 50,
|
|
||||||
altpll_component.clk2_multiply_by = 2,
|
|
||||||
altpll_component.clk2_phase_shift = "0",
|
|
||||||
altpll_component.clk3_divide_by = 9,
|
|
||||||
altpll_component.clk3_duty_cycle = 50,
|
|
||||||
altpll_component.clk3_multiply_by = 8,
|
|
||||||
altpll_component.clk3_phase_shift = "0",
|
|
||||||
altpll_component.compensate_clock = "CLK0",
|
altpll_component.compensate_clock = "CLK0",
|
||||||
altpll_component.inclk0_input_frequency = 37037,
|
altpll_component.inclk0_input_frequency = 37037,
|
||||||
altpll_component.intended_device_family = "Cyclone III",
|
altpll_component.intended_device_family = "Cyclone III",
|
||||||
@@ -161,8 +145,8 @@ module pll (
|
|||||||
altpll_component.port_scanwrite = "PORT_UNUSED",
|
altpll_component.port_scanwrite = "PORT_UNUSED",
|
||||||
altpll_component.port_clk0 = "PORT_USED",
|
altpll_component.port_clk0 = "PORT_USED",
|
||||||
altpll_component.port_clk1 = "PORT_USED",
|
altpll_component.port_clk1 = "PORT_USED",
|
||||||
altpll_component.port_clk2 = "PORT_USED",
|
altpll_component.port_clk2 = "PORT_UNUSED",
|
||||||
altpll_component.port_clk3 = "PORT_USED",
|
altpll_component.port_clk3 = "PORT_UNUSED",
|
||||||
altpll_component.port_clk4 = "PORT_UNUSED",
|
altpll_component.port_clk4 = "PORT_UNUSED",
|
||||||
altpll_component.port_clk5 = "PORT_UNUSED",
|
altpll_component.port_clk5 = "PORT_UNUSED",
|
||||||
altpll_component.port_clkena0 = "PORT_UNUSED",
|
altpll_component.port_clkena0 = "PORT_UNUSED",
|
||||||
@@ -201,16 +185,10 @@ endmodule
|
|||||||
// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING "8"
|
// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING "8"
|
||||||
// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC "9"
|
// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC "9"
|
||||||
// Retrieval info: PRIVATE: DIV_FACTOR1 NUMERIC "9"
|
// Retrieval info: PRIVATE: DIV_FACTOR1 NUMERIC "9"
|
||||||
// Retrieval info: PRIVATE: DIV_FACTOR2 NUMERIC "9"
|
|
||||||
// Retrieval info: PRIVATE: DIV_FACTOR3 NUMERIC "9"
|
|
||||||
// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING "50.00000000"
|
// Retrieval info: PRIVATE: DUTY_CYCLE0 STRING "50.00000000"
|
||||||
// Retrieval info: PRIVATE: DUTY_CYCLE1 STRING "50.00000000"
|
// Retrieval info: PRIVATE: DUTY_CYCLE1 STRING "50.00000000"
|
||||||
// Retrieval info: PRIVATE: DUTY_CYCLE2 STRING "50.00000000"
|
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING "12.000000"
|
||||||
// Retrieval info: PRIVATE: DUTY_CYCLE3 STRING "50.00000000"
|
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE1 STRING "24.000000"
|
||||||
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE0 STRING "48.000000"
|
|
||||||
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE1 STRING "12.000000"
|
|
||||||
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE2 STRING "6.000000"
|
|
||||||
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE3 STRING "24.000000"
|
|
||||||
// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING "0"
|
// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING "0"
|
||||||
// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING "0"
|
// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING "0"
|
||||||
// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING "1"
|
// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING "1"
|
||||||
@@ -232,41 +210,25 @@ endmodule
|
|||||||
// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC "0"
|
// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE_DIRTY NUMERIC "0"
|
||||||
// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING "deg"
|
// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT0 STRING "deg"
|
||||||
// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT1 STRING "deg"
|
// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT1 STRING "deg"
|
||||||
// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT2 STRING "ps"
|
|
||||||
// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT3 STRING "ps"
|
|
||||||
// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING "Any"
|
// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING "Any"
|
||||||
// Retrieval info: PRIVATE: MIRROR_CLK0 STRING "0"
|
// Retrieval info: PRIVATE: MIRROR_CLK0 STRING "0"
|
||||||
// Retrieval info: PRIVATE: MIRROR_CLK1 STRING "0"
|
// Retrieval info: PRIVATE: MIRROR_CLK1 STRING "0"
|
||||||
// Retrieval info: PRIVATE: MIRROR_CLK2 STRING "0"
|
|
||||||
// Retrieval info: PRIVATE: MIRROR_CLK3 STRING "0"
|
|
||||||
// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC "16"
|
// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC "16"
|
||||||
// Retrieval info: PRIVATE: MULT_FACTOR1 NUMERIC "4"
|
// Retrieval info: PRIVATE: MULT_FACTOR1 NUMERIC "4"
|
||||||
// Retrieval info: PRIVATE: MULT_FACTOR2 NUMERIC "2"
|
|
||||||
// Retrieval info: PRIVATE: MULT_FACTOR3 NUMERIC "8"
|
|
||||||
// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING "1"
|
// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING "1"
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING "48.00000000"
|
// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING "12.00000000"
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ1 STRING "12.00000000"
|
// Retrieval info: PRIVATE: OUTPUT_FREQ1 STRING "24.00000000"
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ2 STRING "6.00000000"
|
// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING "1"
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ3 STRING "24.00000000"
|
// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE1 STRING "1"
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE0 STRING "0"
|
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE1 STRING "0"
|
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE2 STRING "0"
|
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ_MODE3 STRING "0"
|
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING "MHz"
|
// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT0 STRING "MHz"
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT1 STRING "MHz"
|
// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT1 STRING "MHz"
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT2 STRING "MHz"
|
|
||||||
// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT3 STRING "MHz"
|
|
||||||
// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING "1"
|
// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING "1"
|
||||||
// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING "0"
|
// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING "0"
|
||||||
// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING "0.00000000"
|
// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING "0.00000000"
|
||||||
// Retrieval info: PRIVATE: PHASE_SHIFT1 STRING "0.00000000"
|
// Retrieval info: PRIVATE: PHASE_SHIFT1 STRING "0.00000000"
|
||||||
// Retrieval info: PRIVATE: PHASE_SHIFT2 STRING "0.00000000"
|
|
||||||
// Retrieval info: PRIVATE: PHASE_SHIFT3 STRING "0.00000000"
|
|
||||||
// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING "0"
|
// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING "0"
|
||||||
// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING "deg"
|
// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING "deg"
|
||||||
// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT1 STRING "deg"
|
// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT1 STRING "deg"
|
||||||
// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT2 STRING "ps"
|
|
||||||
// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT3 STRING "ps"
|
|
||||||
// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING "0"
|
// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING "0"
|
||||||
// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING "1"
|
// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING "1"
|
||||||
// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC "1"
|
// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC "1"
|
||||||
@@ -290,39 +252,25 @@ endmodule
|
|||||||
// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING "0"
|
// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING "0"
|
||||||
// Retrieval info: PRIVATE: STICKY_CLK0 STRING "1"
|
// Retrieval info: PRIVATE: STICKY_CLK0 STRING "1"
|
||||||
// Retrieval info: PRIVATE: STICKY_CLK1 STRING "1"
|
// Retrieval info: PRIVATE: STICKY_CLK1 STRING "1"
|
||||||
// Retrieval info: PRIVATE: STICKY_CLK2 STRING "1"
|
|
||||||
// Retrieval info: PRIVATE: STICKY_CLK3 STRING "1"
|
|
||||||
// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC "1"
|
// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC "1"
|
||||||
// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING "1"
|
// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING "1"
|
||||||
// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
|
// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
|
||||||
// Retrieval info: PRIVATE: USE_CLK0 STRING "1"
|
// Retrieval info: PRIVATE: USE_CLK0 STRING "1"
|
||||||
// Retrieval info: PRIVATE: USE_CLK1 STRING "1"
|
// Retrieval info: PRIVATE: USE_CLK1 STRING "1"
|
||||||
// Retrieval info: PRIVATE: USE_CLK2 STRING "1"
|
|
||||||
// Retrieval info: PRIVATE: USE_CLK3 STRING "1"
|
|
||||||
// Retrieval info: PRIVATE: USE_CLKENA0 STRING "0"
|
// Retrieval info: PRIVATE: USE_CLKENA0 STRING "0"
|
||||||
// Retrieval info: PRIVATE: USE_CLKENA1 STRING "0"
|
// Retrieval info: PRIVATE: USE_CLKENA1 STRING "0"
|
||||||
// Retrieval info: PRIVATE: USE_CLKENA2 STRING "0"
|
|
||||||
// Retrieval info: PRIVATE: USE_CLKENA3 STRING "0"
|
|
||||||
// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC "0"
|
// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC "0"
|
||||||
// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING "0"
|
// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING "0"
|
||||||
// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
|
// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
|
||||||
// Retrieval info: CONSTANT: BANDWIDTH_TYPE STRING "AUTO"
|
// Retrieval info: CONSTANT: BANDWIDTH_TYPE STRING "AUTO"
|
||||||
// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC "9"
|
// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC "9"
|
||||||
// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC "50"
|
// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC "50"
|
||||||
// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC "16"
|
// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC "4"
|
||||||
// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING "0"
|
// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING "0"
|
||||||
// Retrieval info: CONSTANT: CLK1_DIVIDE_BY NUMERIC "9"
|
// Retrieval info: CONSTANT: CLK1_DIVIDE_BY NUMERIC "9"
|
||||||
// Retrieval info: CONSTANT: CLK1_DUTY_CYCLE NUMERIC "50"
|
// Retrieval info: CONSTANT: CLK1_DUTY_CYCLE NUMERIC "50"
|
||||||
// Retrieval info: CONSTANT: CLK1_MULTIPLY_BY NUMERIC "4"
|
// Retrieval info: CONSTANT: CLK1_MULTIPLY_BY NUMERIC "8"
|
||||||
// Retrieval info: CONSTANT: CLK1_PHASE_SHIFT STRING "0"
|
// Retrieval info: CONSTANT: CLK1_PHASE_SHIFT STRING "0"
|
||||||
// Retrieval info: CONSTANT: CLK2_DIVIDE_BY NUMERIC "9"
|
|
||||||
// Retrieval info: CONSTANT: CLK2_DUTY_CYCLE NUMERIC "50"
|
|
||||||
// Retrieval info: CONSTANT: CLK2_MULTIPLY_BY NUMERIC "2"
|
|
||||||
// Retrieval info: CONSTANT: CLK2_PHASE_SHIFT STRING "0"
|
|
||||||
// Retrieval info: CONSTANT: CLK3_DIVIDE_BY NUMERIC "9"
|
|
||||||
// Retrieval info: CONSTANT: CLK3_DUTY_CYCLE NUMERIC "50"
|
|
||||||
// Retrieval info: CONSTANT: CLK3_MULTIPLY_BY NUMERIC "8"
|
|
||||||
// Retrieval info: CONSTANT: CLK3_PHASE_SHIFT STRING "0"
|
|
||||||
// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING "CLK0"
|
// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING "CLK0"
|
||||||
// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC "37037"
|
// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC "37037"
|
||||||
// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone III"
|
// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone III"
|
||||||
@@ -356,8 +304,8 @@ endmodule
|
|||||||
// Retrieval info: CONSTANT: PORT_SCANWRITE STRING "PORT_UNUSED"
|
// Retrieval info: CONSTANT: PORT_SCANWRITE STRING "PORT_UNUSED"
|
||||||
// Retrieval info: CONSTANT: PORT_clk0 STRING "PORT_USED"
|
// Retrieval info: CONSTANT: PORT_clk0 STRING "PORT_USED"
|
||||||
// Retrieval info: CONSTANT: PORT_clk1 STRING "PORT_USED"
|
// Retrieval info: CONSTANT: PORT_clk1 STRING "PORT_USED"
|
||||||
// Retrieval info: CONSTANT: PORT_clk2 STRING "PORT_USED"
|
// Retrieval info: CONSTANT: PORT_clk2 STRING "PORT_UNUSED"
|
||||||
// Retrieval info: CONSTANT: PORT_clk3 STRING "PORT_USED"
|
// Retrieval info: CONSTANT: PORT_clk3 STRING "PORT_UNUSED"
|
||||||
// Retrieval info: CONSTANT: PORT_clk4 STRING "PORT_UNUSED"
|
// Retrieval info: CONSTANT: PORT_clk4 STRING "PORT_UNUSED"
|
||||||
// Retrieval info: CONSTANT: PORT_clk5 STRING "PORT_UNUSED"
|
// Retrieval info: CONSTANT: PORT_clk5 STRING "PORT_UNUSED"
|
||||||
// Retrieval info: CONSTANT: PORT_clkena0 STRING "PORT_UNUSED"
|
// Retrieval info: CONSTANT: PORT_clkena0 STRING "PORT_UNUSED"
|
||||||
@@ -375,16 +323,12 @@ endmodule
|
|||||||
// Retrieval info: USED_PORT: areset 0 0 0 0 INPUT GND "areset"
|
// Retrieval info: USED_PORT: areset 0 0 0 0 INPUT GND "areset"
|
||||||
// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC "c0"
|
// Retrieval info: USED_PORT: c0 0 0 0 0 OUTPUT_CLK_EXT VCC "c0"
|
||||||
// Retrieval info: USED_PORT: c1 0 0 0 0 OUTPUT_CLK_EXT VCC "c1"
|
// Retrieval info: USED_PORT: c1 0 0 0 0 OUTPUT_CLK_EXT VCC "c1"
|
||||||
// Retrieval info: USED_PORT: c2 0 0 0 0 OUTPUT_CLK_EXT VCC "c2"
|
|
||||||
// Retrieval info: USED_PORT: c3 0 0 0 0 OUTPUT_CLK_EXT VCC "c3"
|
|
||||||
// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND "inclk0"
|
// Retrieval info: USED_PORT: inclk0 0 0 0 0 INPUT_CLK_EXT GND "inclk0"
|
||||||
// Retrieval info: CONNECT: @areset 0 0 0 0 areset 0 0 0 0
|
// Retrieval info: CONNECT: @areset 0 0 0 0 areset 0 0 0 0
|
||||||
// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
|
// Retrieval info: CONNECT: @inclk 0 0 1 1 GND 0 0 0 0
|
||||||
// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
|
// Retrieval info: CONNECT: @inclk 0 0 1 0 inclk0 0 0 0 0
|
||||||
// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
|
// Retrieval info: CONNECT: c0 0 0 0 0 @clk 0 0 1 0
|
||||||
// Retrieval info: CONNECT: c1 0 0 0 0 @clk 0 0 1 1
|
// Retrieval info: CONNECT: c1 0 0 0 0 @clk 0 0 1 1
|
||||||
// Retrieval info: CONNECT: c2 0 0 0 0 @clk 0 0 1 2
|
|
||||||
// Retrieval info: CONNECT: c3 0 0 0 0 @clk 0 0 1 3
|
|
||||||
// Retrieval info: GEN_FILE: TYPE_NORMAL pll.v TRUE
|
// Retrieval info: GEN_FILE: TYPE_NORMAL pll.v TRUE
|
||||||
// Retrieval info: GEN_FILE: TYPE_NORMAL pll.ppf TRUE
|
// Retrieval info: GEN_FILE: TYPE_NORMAL pll.ppf TRUE
|
||||||
// Retrieval info: GEN_FILE: TYPE_NORMAL pll.inc FALSE
|
// Retrieval info: GEN_FILE: TYPE_NORMAL pll.inc FALSE
|
||||||
|
|||||||
@@ -1,194 +0,0 @@
|
|||||||
//
|
|
||||||
// scandoubler.v
|
|
||||||
//
|
|
||||||
// Copyright (c) 2015 Till Harbaum <till@harbaum.org>
|
|
||||||
// Copyright (c) 2017 Sorgelig
|
|
||||||
//
|
|
||||||
// This source file is free software: you can redistribute it and/or modify
|
|
||||||
// it under the terms of the GNU General Public License as published
|
|
||||||
// by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
// (at your option) any later version.
|
|
||||||
//
|
|
||||||
// This source file is distributed in the hope that it will be useful,
|
|
||||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
// GNU General Public License for more details.
|
|
||||||
//
|
|
||||||
// You should have received a copy of the GNU General Public License
|
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
// TODO: Delay vsync one line
|
|
||||||
|
|
||||||
module scandoubler #(parameter LENGTH, parameter HALF_DEPTH)
|
|
||||||
(
|
|
||||||
// system interface
|
|
||||||
input clk_sys,
|
|
||||||
input ce_pix,
|
|
||||||
input ce_pix_actual,
|
|
||||||
|
|
||||||
input hq2x,
|
|
||||||
|
|
||||||
// shifter video interface
|
|
||||||
input hs_in,
|
|
||||||
input vs_in,
|
|
||||||
input line_start,
|
|
||||||
|
|
||||||
input [DWIDTH:0] r_in,
|
|
||||||
input [DWIDTH:0] g_in,
|
|
||||||
input [DWIDTH:0] b_in,
|
|
||||||
input mono,
|
|
||||||
|
|
||||||
// output interface
|
|
||||||
output reg hs_out,
|
|
||||||
output vs_out,
|
|
||||||
output [DWIDTH:0] r_out,
|
|
||||||
output [DWIDTH:0] g_out,
|
|
||||||
output [DWIDTH:0] b_out
|
|
||||||
);
|
|
||||||
|
|
||||||
`define BITS_TO_FIT(N) ( \
|
|
||||||
N <= 2 ? 0 : \
|
|
||||||
N <= 4 ? 1 : \
|
|
||||||
N <= 8 ? 2 : \
|
|
||||||
N <= 16 ? 3 : \
|
|
||||||
N <= 32 ? 4 : \
|
|
||||||
N <= 64 ? 5 : \
|
|
||||||
N <= 128 ? 6 : \
|
|
||||||
N <= 256 ? 7 : \
|
|
||||||
N <= 512 ? 8 : \
|
|
||||||
N <=1024 ? 9 : 10 )
|
|
||||||
|
|
||||||
localparam DWIDTH = HALF_DEPTH ? 2 : 5;
|
|
||||||
|
|
||||||
assign vs_out = vs_in;
|
|
||||||
|
|
||||||
reg [2:0] phase;
|
|
||||||
reg [2:0] ce_div;
|
|
||||||
reg [7:0] pix_len = 0;
|
|
||||||
wire [7:0] pl = pix_len + 1'b1;
|
|
||||||
|
|
||||||
reg ce_x1, ce_x4;
|
|
||||||
reg req_line_reset;
|
|
||||||
wire ls_in = hs_in | line_start;
|
|
||||||
always @(negedge clk_sys) begin
|
|
||||||
reg old_ce;
|
|
||||||
reg [2:0] ce_cnt;
|
|
||||||
|
|
||||||
reg [7:0] pixsz2, pixsz4 = 0;
|
|
||||||
|
|
||||||
old_ce <= ce_pix;
|
|
||||||
if(~&pix_len) pix_len <= pix_len + 1'd1;
|
|
||||||
|
|
||||||
ce_x4 <= 0;
|
|
||||||
ce_x1 <= 0;
|
|
||||||
|
|
||||||
// use such odd comparison to place c_x4 evenly if master clock isn't multiple 4.
|
|
||||||
if((pl == pixsz4) || (pl == pixsz2) || (pl == (pixsz2+pixsz4))) begin
|
|
||||||
phase <= phase + 1'd1;
|
|
||||||
ce_x4 <= 1;
|
|
||||||
end
|
|
||||||
|
|
||||||
if(~old_ce & ce_pix) begin
|
|
||||||
pixsz2 <= {1'b0, pl[7:1]};
|
|
||||||
pixsz4 <= {2'b00, pl[7:2]};
|
|
||||||
ce_x1 <= 1;
|
|
||||||
ce_x4 <= 1;
|
|
||||||
pix_len <= 0;
|
|
||||||
phase <= phase + 1'd1;
|
|
||||||
|
|
||||||
ce_cnt <= ce_cnt + 1'd1;
|
|
||||||
if(ce_pix_actual) begin
|
|
||||||
phase <= 0;
|
|
||||||
ce_div <= ce_cnt + 1'd1;
|
|
||||||
ce_cnt <= 0;
|
|
||||||
req_line_reset <= 0;
|
|
||||||
end
|
|
||||||
|
|
||||||
if(ls_in) req_line_reset <= 1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
reg ce_sd;
|
|
||||||
always @(*) begin
|
|
||||||
case(ce_div)
|
|
||||||
2: ce_sd = !phase[0];
|
|
||||||
4: ce_sd = !phase[1:0];
|
|
||||||
default: ce_sd <= 1;
|
|
||||||
endcase
|
|
||||||
end
|
|
||||||
|
|
||||||
localparam AWIDTH = `BITS_TO_FIT(LENGTH);
|
|
||||||
Hq2x #(.LENGTH(LENGTH), .HALF_DEPTH(HALF_DEPTH)) Hq2x
|
|
||||||
(
|
|
||||||
.clk(clk_sys),
|
|
||||||
.ce_x4(ce_x4 & ce_sd),
|
|
||||||
.inputpixel({b_in,g_in,r_in}),
|
|
||||||
.mono(mono),
|
|
||||||
.disable_hq2x(~hq2x),
|
|
||||||
.reset_frame(vs_in),
|
|
||||||
.reset_line(req_line_reset),
|
|
||||||
.read_y(sd_line),
|
|
||||||
.read_x(sd_h_actual),
|
|
||||||
.outpixel({b_out,g_out,r_out})
|
|
||||||
);
|
|
||||||
|
|
||||||
reg [10:0] sd_h_actual;
|
|
||||||
always @(*) begin
|
|
||||||
case(ce_div)
|
|
||||||
2: sd_h_actual = sd_h[10:1];
|
|
||||||
4: sd_h_actual = sd_h[10:2];
|
|
||||||
default: sd_h_actual = sd_h;
|
|
||||||
endcase
|
|
||||||
end
|
|
||||||
|
|
||||||
reg [10:0] sd_h;
|
|
||||||
reg [1:0] sd_line;
|
|
||||||
always @(posedge clk_sys) begin
|
|
||||||
|
|
||||||
reg [11:0] hs_max,hs_rise,hs_ls;
|
|
||||||
reg [10:0] hcnt;
|
|
||||||
reg [11:0] sd_hcnt;
|
|
||||||
|
|
||||||
reg hs, hs2, vs, ls;
|
|
||||||
|
|
||||||
if(ce_x1) begin
|
|
||||||
hs <= hs_in;
|
|
||||||
ls <= ls_in;
|
|
||||||
|
|
||||||
if(ls && !ls_in) hs_ls <= {hcnt,1'b1};
|
|
||||||
|
|
||||||
// falling edge of hsync indicates start of line
|
|
||||||
if(hs && !hs_in) begin
|
|
||||||
hs_max <= {hcnt,1'b1};
|
|
||||||
hcnt <= 0;
|
|
||||||
if(ls && !ls_in) hs_ls <= {10'd0,1'b1};
|
|
||||||
end else begin
|
|
||||||
hcnt <= hcnt + 1'd1;
|
|
||||||
end
|
|
||||||
|
|
||||||
// save position of rising edge
|
|
||||||
if(!hs && hs_in) hs_rise <= {hcnt,1'b1};
|
|
||||||
|
|
||||||
vs <= vs_in;
|
|
||||||
if(vs && ~vs_in) sd_line <= 0;
|
|
||||||
end
|
|
||||||
|
|
||||||
if(ce_x4) begin
|
|
||||||
hs2 <= hs_in;
|
|
||||||
|
|
||||||
// output counter synchronous to input and at twice the rate
|
|
||||||
sd_hcnt <= sd_hcnt + 1'd1;
|
|
||||||
sd_h <= sd_h + 1'd1;
|
|
||||||
if(hs2 && !hs_in) sd_hcnt <= hs_max;
|
|
||||||
if(sd_hcnt == hs_max) sd_hcnt <= 0;
|
|
||||||
|
|
||||||
// replicate horizontal sync at twice the speed
|
|
||||||
if(sd_hcnt == hs_max) hs_out <= 0;
|
|
||||||
if(sd_hcnt == hs_rise) hs_out <= 1;
|
|
||||||
|
|
||||||
if(sd_hcnt == hs_ls) sd_h <= 0;
|
|
||||||
if(sd_hcnt == hs_ls) sd_line <= sd_line + 1'd1;
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
endmodule
|
|
||||||
@@ -1,564 +0,0 @@
|
|||||||
-- ****
|
|
||||||
-- T65(b) core. In an effort to merge and maintain bug fixes ....
|
|
||||||
--
|
|
||||||
--
|
|
||||||
-- Ver 301 more merging
|
|
||||||
-- Ver 300 Bugfixes by ehenciak added, started tidyup *bust*
|
|
||||||
-- MikeJ March 2005
|
|
||||||
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
|
|
||||||
--
|
|
||||||
-- ****
|
|
||||||
--
|
|
||||||
-- 65xx compatible microprocessor core
|
|
||||||
--
|
|
||||||
-- Version : 0246
|
|
||||||
--
|
|
||||||
-- Copyright (c) 2002 Daniel Wallner (jesus@opencores.org)
|
|
||||||
--
|
|
||||||
-- All rights reserved
|
|
||||||
--
|
|
||||||
-- Redistribution and use in source and synthezised forms, with or without
|
|
||||||
-- modification, are permitted provided that the following conditions are met:
|
|
||||||
--
|
|
||||||
-- Redistributions of source code must retain the above copyright notice,
|
|
||||||
-- this list of conditions and the following disclaimer.
|
|
||||||
--
|
|
||||||
-- Redistributions in synthesized form must reproduce the above copyright
|
|
||||||
-- notice, this list of conditions and the following disclaimer in the
|
|
||||||
-- documentation and/or other materials provided with the distribution.
|
|
||||||
--
|
|
||||||
-- Neither the name of the author nor the names of other contributors may
|
|
||||||
-- be used to endorse or promote products derived from this software without
|
|
||||||
-- specific prior written permission.
|
|
||||||
--
|
|
||||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
|
||||||
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
--
|
|
||||||
-- Please report bugs to the author, but before you do so, please
|
|
||||||
-- make sure that this is not a derivative work and that
|
|
||||||
-- you have the latest version of this file.
|
|
||||||
--
|
|
||||||
-- The latest version of this file can be found at:
|
|
||||||
-- http://www.opencores.org/cvsweb.shtml/t65/
|
|
||||||
--
|
|
||||||
-- Limitations :
|
|
||||||
--
|
|
||||||
-- 65C02 and 65C816 modes are incomplete
|
|
||||||
-- Undocumented instructions are not supported
|
|
||||||
-- Some interface signals behaves incorrect
|
|
||||||
--
|
|
||||||
-- File history :
|
|
||||||
--
|
|
||||||
-- 0246 : First release
|
|
||||||
--
|
|
||||||
|
|
||||||
library IEEE;
|
|
||||||
use IEEE.std_logic_1164.all;
|
|
||||||
use IEEE.numeric_std.all;
|
|
||||||
use work.T65_Pack.all;
|
|
||||||
|
|
||||||
-- ehenciak 2-23-2005 : Added the enable signal so that one doesn't have to use
|
|
||||||
-- the ready signal to limit the CPU.
|
|
||||||
entity T65 is
|
|
||||||
port(
|
|
||||||
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65C816
|
|
||||||
Res_n : in std_logic;
|
|
||||||
Enable : in std_logic;
|
|
||||||
Clk : in std_logic;
|
|
||||||
Rdy : in std_logic;
|
|
||||||
Abort_n : in std_logic;
|
|
||||||
IRQ_n : in std_logic;
|
|
||||||
NMI_n : in std_logic;
|
|
||||||
SO_n : in std_logic;
|
|
||||||
R_W_n : out std_logic;
|
|
||||||
Sync : out std_logic;
|
|
||||||
EF : out std_logic;
|
|
||||||
MF : out std_logic;
|
|
||||||
XF : out std_logic;
|
|
||||||
ML_n : out std_logic;
|
|
||||||
VP_n : out std_logic;
|
|
||||||
VDA : out std_logic;
|
|
||||||
VPA : out std_logic;
|
|
||||||
A : out std_logic_vector(23 downto 0);
|
|
||||||
DI : in std_logic_vector(7 downto 0);
|
|
||||||
DO : out std_logic_vector(7 downto 0)
|
|
||||||
);
|
|
||||||
end T65;
|
|
||||||
|
|
||||||
architecture rtl of T65 is
|
|
||||||
|
|
||||||
-- Registers
|
|
||||||
signal ABC, X, Y, D : std_logic_vector(15 downto 0);
|
|
||||||
signal P, AD, DL : std_logic_vector(7 downto 0) := x"00";
|
|
||||||
signal BAH : std_logic_vector(7 downto 0);
|
|
||||||
signal BAL : std_logic_vector(8 downto 0);
|
|
||||||
signal PBR : std_logic_vector(7 downto 0);
|
|
||||||
signal DBR : std_logic_vector(7 downto 0);
|
|
||||||
signal PC : unsigned(15 downto 0);
|
|
||||||
signal S : unsigned(15 downto 0);
|
|
||||||
signal EF_i : std_logic;
|
|
||||||
signal MF_i : std_logic;
|
|
||||||
signal XF_i : std_logic;
|
|
||||||
|
|
||||||
signal IR : std_logic_vector(7 downto 0);
|
|
||||||
signal MCycle : std_logic_vector(2 downto 0);
|
|
||||||
|
|
||||||
signal Mode_r : std_logic_vector(1 downto 0);
|
|
||||||
signal ALU_Op_r : std_logic_vector(3 downto 0);
|
|
||||||
signal Write_Data_r : std_logic_vector(2 downto 0);
|
|
||||||
signal Set_Addr_To_r : std_logic_vector(1 downto 0);
|
|
||||||
signal PCAdder : unsigned(8 downto 0);
|
|
||||||
|
|
||||||
signal RstCycle : std_logic;
|
|
||||||
signal IRQCycle : std_logic;
|
|
||||||
signal NMICycle : std_logic;
|
|
||||||
|
|
||||||
signal B_o : std_logic;
|
|
||||||
signal SO_n_o : std_logic;
|
|
||||||
signal IRQ_n_o : std_logic;
|
|
||||||
signal NMI_n_o : std_logic;
|
|
||||||
signal NMIAct : std_logic;
|
|
||||||
|
|
||||||
signal Break : std_logic;
|
|
||||||
|
|
||||||
-- ALU signals
|
|
||||||
signal BusA : std_logic_vector(7 downto 0);
|
|
||||||
signal BusA_r : std_logic_vector(7 downto 0);
|
|
||||||
signal BusB : std_logic_vector(7 downto 0);
|
|
||||||
signal ALU_Q : std_logic_vector(7 downto 0);
|
|
||||||
signal P_Out : std_logic_vector(7 downto 0);
|
|
||||||
|
|
||||||
-- Micro code outputs
|
|
||||||
signal LCycle : std_logic_vector(2 downto 0);
|
|
||||||
signal ALU_Op : std_logic_vector(3 downto 0);
|
|
||||||
signal Set_BusA_To : std_logic_vector(2 downto 0);
|
|
||||||
signal Set_Addr_To : std_logic_vector(1 downto 0);
|
|
||||||
signal Write_Data : std_logic_vector(2 downto 0);
|
|
||||||
signal Jump : std_logic_vector(1 downto 0);
|
|
||||||
signal BAAdd : std_logic_vector(1 downto 0);
|
|
||||||
signal BreakAtNA : std_logic;
|
|
||||||
signal ADAdd : std_logic;
|
|
||||||
signal AddY : std_logic;
|
|
||||||
signal PCAdd : std_logic;
|
|
||||||
signal Inc_S : std_logic;
|
|
||||||
signal Dec_S : std_logic;
|
|
||||||
signal LDA : std_logic;
|
|
||||||
signal LDP : std_logic;
|
|
||||||
signal LDX : std_logic;
|
|
||||||
signal LDY : std_logic;
|
|
||||||
signal LDS : std_logic;
|
|
||||||
signal LDDI : std_logic;
|
|
||||||
signal LDALU : std_logic;
|
|
||||||
signal LDAD : std_logic;
|
|
||||||
signal LDBAL : std_logic;
|
|
||||||
signal LDBAH : std_logic;
|
|
||||||
signal SaveP : std_logic;
|
|
||||||
signal Write : std_logic;
|
|
||||||
|
|
||||||
signal really_rdy : std_logic;
|
|
||||||
signal R_W_n_i : std_logic;
|
|
||||||
|
|
||||||
begin
|
|
||||||
-- ehenciak : gate Rdy with read/write to make an "OK, it's
|
|
||||||
-- really OK to stop the processor now if Rdy is
|
|
||||||
-- deasserted" signal
|
|
||||||
really_rdy <= Rdy or not(R_W_n_i);
|
|
||||||
|
|
||||||
-- ehenciak : Drive R_W_n_i off chip.
|
|
||||||
R_W_n <= R_W_n_i;
|
|
||||||
|
|
||||||
Sync <= '1' when MCycle = "000" else '0';
|
|
||||||
EF <= EF_i;
|
|
||||||
MF <= MF_i;
|
|
||||||
XF <= XF_i;
|
|
||||||
ML_n <= '0' when IR(7 downto 6) /= "10" and IR(2 downto 1) = "11" and MCycle(2 downto 1) /= "00" else '1';
|
|
||||||
VP_n <= '0' when IRQCycle = '1' and (MCycle = "101" or MCycle = "110") else '1';
|
|
||||||
VDA <= '1' when Set_Addr_To_r /= "00" else '0'; -- Incorrect !!!!!!!!!!!!
|
|
||||||
VPA <= '1' when Jump(1) = '0' else '0'; -- Incorrect !!!!!!!!!!!!
|
|
||||||
|
|
||||||
mcode : T65_MCode
|
|
||||||
port map(
|
|
||||||
Mode => Mode_r,
|
|
||||||
IR => IR,
|
|
||||||
MCycle => MCycle,
|
|
||||||
P => P,
|
|
||||||
LCycle => LCycle,
|
|
||||||
ALU_Op => ALU_Op,
|
|
||||||
Set_BusA_To => Set_BusA_To,
|
|
||||||
Set_Addr_To => Set_Addr_To,
|
|
||||||
Write_Data => Write_Data,
|
|
||||||
Jump => Jump,
|
|
||||||
BAAdd => BAAdd,
|
|
||||||
BreakAtNA => BreakAtNA,
|
|
||||||
ADAdd => ADAdd,
|
|
||||||
AddY => AddY,
|
|
||||||
PCAdd => PCAdd,
|
|
||||||
Inc_S => Inc_S,
|
|
||||||
Dec_S => Dec_S,
|
|
||||||
LDA => LDA,
|
|
||||||
LDP => LDP,
|
|
||||||
LDX => LDX,
|
|
||||||
LDY => LDY,
|
|
||||||
LDS => LDS,
|
|
||||||
LDDI => LDDI,
|
|
||||||
LDALU => LDALU,
|
|
||||||
LDAD => LDAD,
|
|
||||||
LDBAL => LDBAL,
|
|
||||||
LDBAH => LDBAH,
|
|
||||||
SaveP => SaveP,
|
|
||||||
Write => Write
|
|
||||||
);
|
|
||||||
|
|
||||||
alu : T65_ALU
|
|
||||||
port map(
|
|
||||||
Mode => Mode_r,
|
|
||||||
Op => ALU_Op_r,
|
|
||||||
BusA => BusA_r,
|
|
||||||
BusB => BusB,
|
|
||||||
P_In => P,
|
|
||||||
P_Out => P_Out,
|
|
||||||
Q => ALU_Q
|
|
||||||
);
|
|
||||||
|
|
||||||
process (Res_n, Clk)
|
|
||||||
begin
|
|
||||||
if Res_n = '0' then
|
|
||||||
PC <= (others => '0'); -- Program Counter
|
|
||||||
IR <= "00000000";
|
|
||||||
S <= (others => '0'); -- Dummy !!!!!!!!!!!!!!!!!!!!!
|
|
||||||
D <= (others => '0');
|
|
||||||
PBR <= (others => '0');
|
|
||||||
DBR <= (others => '0');
|
|
||||||
|
|
||||||
Mode_r <= (others => '0');
|
|
||||||
ALU_Op_r <= "1100";
|
|
||||||
Write_Data_r <= "000";
|
|
||||||
Set_Addr_To_r <= "00";
|
|
||||||
|
|
||||||
R_W_n_i <= '1';
|
|
||||||
EF_i <= '1';
|
|
||||||
MF_i <= '1';
|
|
||||||
XF_i <= '1';
|
|
||||||
|
|
||||||
elsif Clk'event and Clk = '1' then
|
|
||||||
if (Enable = '1') then
|
|
||||||
if (really_rdy = '1') then
|
|
||||||
R_W_n_i <= not Write or RstCycle;
|
|
||||||
|
|
||||||
D <= (others => '1'); -- Dummy
|
|
||||||
PBR <= (others => '1'); -- Dummy
|
|
||||||
DBR <= (others => '1'); -- Dummy
|
|
||||||
EF_i <= '0'; -- Dummy
|
|
||||||
MF_i <= '0'; -- Dummy
|
|
||||||
XF_i <= '0'; -- Dummy
|
|
||||||
|
|
||||||
if MCycle = "000" then
|
|
||||||
Mode_r <= Mode;
|
|
||||||
|
|
||||||
if IRQCycle = '0' and NMICycle = '0' then
|
|
||||||
PC <= PC + 1;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if IRQCycle = '1' or NMICycle = '1' then
|
|
||||||
IR <= "00000000";
|
|
||||||
else
|
|
||||||
IR <= DI;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
ALU_Op_r <= ALU_Op;
|
|
||||||
Write_Data_r <= Write_Data;
|
|
||||||
if Break = '1' then
|
|
||||||
Set_Addr_To_r <= "00";
|
|
||||||
else
|
|
||||||
Set_Addr_To_r <= Set_Addr_To;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if Inc_S = '1' then
|
|
||||||
S <= S + 1;
|
|
||||||
end if;
|
|
||||||
if Dec_S = '1' and RstCycle = '0' then
|
|
||||||
S <= S - 1;
|
|
||||||
end if;
|
|
||||||
if LDS = '1' then
|
|
||||||
S(7 downto 0) <= unsigned(ALU_Q);
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if IR = "00000000" and MCycle = "001" and IRQCycle = '0' and NMICycle = '0' then
|
|
||||||
PC <= PC + 1;
|
|
||||||
end if;
|
|
||||||
--
|
|
||||||
-- jump control logic
|
|
||||||
--
|
|
||||||
case Jump is
|
|
||||||
when "01" =>
|
|
||||||
PC <= PC + 1;
|
|
||||||
|
|
||||||
when "10" =>
|
|
||||||
PC <= unsigned(DI & DL);
|
|
||||||
|
|
||||||
when "11" =>
|
|
||||||
if PCAdder(8) = '1' then
|
|
||||||
if DL(7) = '0' then
|
|
||||||
PC(15 downto 8) <= PC(15 downto 8) + 1;
|
|
||||||
else
|
|
||||||
PC(15 downto 8) <= PC(15 downto 8) - 1;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
PC(7 downto 0) <= PCAdder(7 downto 0);
|
|
||||||
|
|
||||||
when others => null;
|
|
||||||
end case;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
PCAdder <= resize(PC(7 downto 0),9) + resize(unsigned(DL(7) & DL),9) when PCAdd = '1'
|
|
||||||
else "0" & PC(7 downto 0);
|
|
||||||
|
|
||||||
process (Clk)
|
|
||||||
begin
|
|
||||||
if Clk'event and Clk = '1' then
|
|
||||||
if (Enable = '1') then
|
|
||||||
if (really_rdy = '1') then
|
|
||||||
if MCycle = "000" then
|
|
||||||
if LDA = '1' then
|
|
||||||
ABC(7 downto 0) <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if LDX = '1' then
|
|
||||||
X(7 downto 0) <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if LDY = '1' then
|
|
||||||
Y(7 downto 0) <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if (LDA or LDX or LDY) = '1' then
|
|
||||||
P <= P_Out;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
if SaveP = '1' then
|
|
||||||
P <= P_Out;
|
|
||||||
end if;
|
|
||||||
if LDP = '1' then
|
|
||||||
P <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if IR(4 downto 0) = "11000" then
|
|
||||||
case IR(7 downto 5) is
|
|
||||||
when "000" =>
|
|
||||||
P(Flag_C) <= '0';
|
|
||||||
when "001" =>
|
|
||||||
P(Flag_C) <= '1';
|
|
||||||
when "010" =>
|
|
||||||
P(Flag_I) <= '0';
|
|
||||||
when "011" =>
|
|
||||||
P(Flag_I) <= '1';
|
|
||||||
when "101" =>
|
|
||||||
P(Flag_V) <= '0';
|
|
||||||
when "110" =>
|
|
||||||
P(Flag_D) <= '0';
|
|
||||||
when "111" =>
|
|
||||||
P(Flag_D) <= '1';
|
|
||||||
when others =>
|
|
||||||
end case;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
--if IR = "00000000" and MCycle = "011" and RstCycle = '0' and NMICycle = '0' and IRQCycle = '0' then
|
|
||||||
-- P(Flag_B) <= '1';
|
|
||||||
--end if;
|
|
||||||
--if IR = "00000000" and MCycle = "100" and RstCycle = '0' and (NMICycle = '1' or IRQCycle = '1') then
|
|
||||||
-- P(Flag_I) <= '1';
|
|
||||||
-- P(Flag_B) <= B_o;
|
|
||||||
--end if;
|
|
||||||
|
|
||||||
-- B=1 always on the 6502
|
|
||||||
P(Flag_B) <= '1';
|
|
||||||
if IR = "00000000" and RstCycle = '0' and (NMICycle = '1' or IRQCycle = '1') then
|
|
||||||
if MCycle = "011" then
|
|
||||||
-- B=0 in *copy* of P pushed onto the stack
|
|
||||||
P(Flag_B) <= '0';
|
|
||||||
elsif MCycle = "100" then
|
|
||||||
P(Flag_I) <= '1';
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if SO_n_o = '1' and SO_n = '0' then
|
|
||||||
P(Flag_V) <= '1';
|
|
||||||
end if;
|
|
||||||
if RstCycle = '1' and Mode_r /= "00" then
|
|
||||||
P(Flag_1) <= '1';
|
|
||||||
P(Flag_D) <= '0';
|
|
||||||
P(Flag_I) <= '1';
|
|
||||||
end if;
|
|
||||||
P(Flag_1) <= '1';
|
|
||||||
|
|
||||||
B_o <= P(Flag_B);
|
|
||||||
SO_n_o <= SO_n;
|
|
||||||
IRQ_n_o <= IRQ_n;
|
|
||||||
NMI_n_o <= NMI_n;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
--
|
|
||||||
-- Buses
|
|
||||||
--
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
process (Res_n, Clk)
|
|
||||||
begin
|
|
||||||
if Res_n = '0' then
|
|
||||||
BusA_r <= (others => '0');
|
|
||||||
BusB <= (others => '0');
|
|
||||||
AD <= (others => '0');
|
|
||||||
BAL <= (others => '0');
|
|
||||||
BAH <= (others => '0');
|
|
||||||
DL <= (others => '0');
|
|
||||||
elsif Clk'event and Clk = '1' then
|
|
||||||
if (Enable = '1') then
|
|
||||||
if (Rdy = '1') then
|
|
||||||
BusA_r <= BusA;
|
|
||||||
BusB <= DI;
|
|
||||||
|
|
||||||
case BAAdd is
|
|
||||||
when "01" =>
|
|
||||||
-- BA Inc
|
|
||||||
AD <= std_logic_vector(unsigned(AD) + 1);
|
|
||||||
BAL <= std_logic_vector(unsigned(BAL) + 1);
|
|
||||||
when "10" =>
|
|
||||||
-- BA Add
|
|
||||||
BAL <= std_logic_vector(resize(unsigned(BAL(7 downto 0)),9) + resize(unsigned(BusA),9));
|
|
||||||
when "11" =>
|
|
||||||
-- BA Adj
|
|
||||||
if BAL(8) = '1' then
|
|
||||||
BAH <= std_logic_vector(unsigned(BAH) + 1);
|
|
||||||
end if;
|
|
||||||
when others =>
|
|
||||||
end case;
|
|
||||||
|
|
||||||
-- ehenciak : modified to use Y register as well (bugfix)
|
|
||||||
if ADAdd = '1' then
|
|
||||||
if (AddY = '1') then
|
|
||||||
AD <= std_logic_vector(unsigned(AD) + unsigned(Y(7 downto 0)));
|
|
||||||
else
|
|
||||||
AD <= std_logic_vector(unsigned(AD) + unsigned(X(7 downto 0)));
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if IR = "00000000" then
|
|
||||||
BAL <= (others => '1');
|
|
||||||
BAH <= (others => '1');
|
|
||||||
if RstCycle = '1' then
|
|
||||||
BAL(2 downto 0) <= "100";
|
|
||||||
elsif NMICycle = '1' then
|
|
||||||
BAL(2 downto 0) <= "010";
|
|
||||||
else
|
|
||||||
BAL(2 downto 0) <= "110";
|
|
||||||
end if;
|
|
||||||
if Set_addr_To_r = "11" then
|
|
||||||
BAL(0) <= '1';
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
|
|
||||||
if LDDI = '1' then
|
|
||||||
DL <= DI;
|
|
||||||
end if;
|
|
||||||
if LDALU = '1' then
|
|
||||||
DL <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if LDAD = '1' then
|
|
||||||
AD <= DI;
|
|
||||||
end if;
|
|
||||||
if LDBAL = '1' then
|
|
||||||
BAL(7 downto 0) <= DI;
|
|
||||||
end if;
|
|
||||||
if LDBAH = '1' then
|
|
||||||
BAH <= DI;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
Break <= (BreakAtNA and not BAL(8)) or (PCAdd and not PCAdder(8));
|
|
||||||
|
|
||||||
|
|
||||||
with Set_BusA_To select
|
|
||||||
BusA <= DI when "000",
|
|
||||||
ABC(7 downto 0) when "001",
|
|
||||||
X(7 downto 0) when "010",
|
|
||||||
Y(7 downto 0) when "011",
|
|
||||||
std_logic_vector(S(7 downto 0)) when "100",
|
|
||||||
P when "101",
|
|
||||||
(others => '-') when others;
|
|
||||||
|
|
||||||
with Set_Addr_To_r select
|
|
||||||
A <= "0000000000000001" & std_logic_vector(S(7 downto 0)) when "01",
|
|
||||||
DBR & "00000000" & AD when "10",
|
|
||||||
"00000000" & BAH & BAL(7 downto 0) when "11",
|
|
||||||
PBR & std_logic_vector(PC(15 downto 8)) & std_logic_vector(PCAdder(7 downto 0)) when others;
|
|
||||||
|
|
||||||
with Write_Data_r select
|
|
||||||
DO <= DL when "000",
|
|
||||||
ABC(7 downto 0) when "001",
|
|
||||||
X(7 downto 0) when "010",
|
|
||||||
Y(7 downto 0) when "011",
|
|
||||||
std_logic_vector(S(7 downto 0)) when "100",
|
|
||||||
P when "101",
|
|
||||||
std_logic_vector(PC(7 downto 0)) when "110",
|
|
||||||
std_logic_vector(PC(15 downto 8)) when others;
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------
|
|
||||||
--
|
|
||||||
-- Main state machine
|
|
||||||
--
|
|
||||||
-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
process (Res_n, Clk)
|
|
||||||
begin
|
|
||||||
if Res_n = '0' then
|
|
||||||
MCycle <= "001";
|
|
||||||
RstCycle <= '1';
|
|
||||||
IRQCycle <= '0';
|
|
||||||
NMICycle <= '0';
|
|
||||||
NMIAct <= '0';
|
|
||||||
elsif Clk'event and Clk = '1' then
|
|
||||||
if (Enable = '1') then
|
|
||||||
if (really_rdy = '1') then
|
|
||||||
if MCycle = LCycle or Break = '1' then
|
|
||||||
MCycle <= "000";
|
|
||||||
RstCycle <= '0';
|
|
||||||
IRQCycle <= '0';
|
|
||||||
NMICycle <= '0';
|
|
||||||
if NMIAct = '1' then
|
|
||||||
NMICycle <= '1';
|
|
||||||
elsif IRQ_n_o = '0' and P(Flag_I) = '0' then
|
|
||||||
IRQCycle <= '1';
|
|
||||||
end if;
|
|
||||||
else
|
|
||||||
MCycle <= std_logic_vector(unsigned(MCycle) + 1);
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if NMICycle = '1' then
|
|
||||||
NMIAct <= '0';
|
|
||||||
end if;
|
|
||||||
if NMI_n_o = '1' and NMI_n = '0' then
|
|
||||||
NMIAct <= '1';
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
end;
|
|
||||||
@@ -1,260 +0,0 @@
|
|||||||
-- ****
|
|
||||||
-- T65(b) core. In an effort to merge and maintain bug fixes ....
|
|
||||||
--
|
|
||||||
--
|
|
||||||
-- Ver 300 Bugfixes by ehenciak added
|
|
||||||
-- MikeJ March 2005
|
|
||||||
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
|
|
||||||
--
|
|
||||||
-- ****
|
|
||||||
--
|
|
||||||
-- 6502 compatible microprocessor core
|
|
||||||
--
|
|
||||||
-- Version : 0245
|
|
||||||
--
|
|
||||||
-- Copyright (c) 2002 Daniel Wallner (jesus@opencores.org)
|
|
||||||
--
|
|
||||||
-- All rights reserved
|
|
||||||
--
|
|
||||||
-- Redistribution and use in source and synthezised forms, with or without
|
|
||||||
-- modification, are permitted provided that the following conditions are met:
|
|
||||||
--
|
|
||||||
-- Redistributions of source code must retain the above copyright notice,
|
|
||||||
-- this list of conditions and the following disclaimer.
|
|
||||||
--
|
|
||||||
-- Redistributions in synthesized form must reproduce the above copyright
|
|
||||||
-- notice, this list of conditions and the following disclaimer in the
|
|
||||||
-- documentation and/or other materials provided with the distribution.
|
|
||||||
--
|
|
||||||
-- Neither the name of the author nor the names of other contributors may
|
|
||||||
-- be used to endorse or promote products derived from this software without
|
|
||||||
-- specific prior written permission.
|
|
||||||
--
|
|
||||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
|
||||||
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
--
|
|
||||||
-- Please report bugs to the author, but before you do so, please
|
|
||||||
-- make sure that this is not a derivative work and that
|
|
||||||
-- you have the latest version of this file.
|
|
||||||
--
|
|
||||||
-- The latest version of this file can be found at:
|
|
||||||
-- http://www.opencores.org/cvsweb.shtml/t65/
|
|
||||||
--
|
|
||||||
-- Limitations :
|
|
||||||
--
|
|
||||||
-- File history :
|
|
||||||
--
|
|
||||||
-- 0245 : First version
|
|
||||||
--
|
|
||||||
|
|
||||||
library IEEE;
|
|
||||||
use IEEE.std_logic_1164.all;
|
|
||||||
use IEEE.numeric_std.all;
|
|
||||||
use work.T65_Pack.all;
|
|
||||||
|
|
||||||
entity T65_ALU is
|
|
||||||
port(
|
|
||||||
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65816
|
|
||||||
Op : in std_logic_vector(3 downto 0);
|
|
||||||
BusA : in std_logic_vector(7 downto 0);
|
|
||||||
BusB : in std_logic_vector(7 downto 0);
|
|
||||||
P_In : in std_logic_vector(7 downto 0);
|
|
||||||
P_Out : out std_logic_vector(7 downto 0);
|
|
||||||
Q : out std_logic_vector(7 downto 0)
|
|
||||||
);
|
|
||||||
end T65_ALU;
|
|
||||||
|
|
||||||
architecture rtl of T65_ALU is
|
|
||||||
|
|
||||||
-- AddSub variables (temporary signals)
|
|
||||||
signal ADC_Z : std_logic;
|
|
||||||
signal ADC_C : std_logic;
|
|
||||||
signal ADC_V : std_logic;
|
|
||||||
signal ADC_N : std_logic;
|
|
||||||
signal ADC_Q : std_logic_vector(7 downto 0);
|
|
||||||
signal SBC_Z : std_logic;
|
|
||||||
signal SBC_C : std_logic;
|
|
||||||
signal SBC_V : std_logic;
|
|
||||||
signal SBC_N : std_logic;
|
|
||||||
signal SBC_Q : std_logic_vector(7 downto 0);
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
process (P_In, BusA, BusB)
|
|
||||||
variable AL : unsigned(6 downto 0);
|
|
||||||
variable AH : unsigned(6 downto 0);
|
|
||||||
variable C : std_logic;
|
|
||||||
begin
|
|
||||||
AL := resize(unsigned(BusA(3 downto 0) & P_In(Flag_C)), 7) + resize(unsigned(BusB(3 downto 0) & "1"), 7);
|
|
||||||
AH := resize(unsigned(BusA(7 downto 4) & AL(5)), 7) + resize(unsigned(BusB(7 downto 4) & "1"), 7);
|
|
||||||
|
|
||||||
-- pragma translate_off
|
|
||||||
if is_x(std_logic_vector(AL)) then AL := "0000000"; end if;
|
|
||||||
if is_x(std_logic_vector(AH)) then AH := "0000000"; end if;
|
|
||||||
-- pragma translate_on
|
|
||||||
|
|
||||||
if AL(4 downto 1) = 0 and AH(4 downto 1) = 0 then
|
|
||||||
ADC_Z <= '1';
|
|
||||||
else
|
|
||||||
ADC_Z <= '0';
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if AL(5 downto 1) > 9 and P_In(Flag_D) = '1' then
|
|
||||||
AL(6 downto 1) := AL(6 downto 1) + 6;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
C := AL(6) or AL(5);
|
|
||||||
AH := resize(unsigned(BusA(7 downto 4) & C), 7) + resize(unsigned(BusB(7 downto 4) & "1"), 7);
|
|
||||||
|
|
||||||
ADC_N <= AH(4);
|
|
||||||
ADC_V <= (AH(4) xor BusA(7)) and not (BusA(7) xor BusB(7));
|
|
||||||
|
|
||||||
-- pragma translate_off
|
|
||||||
if is_x(std_logic_vector(AH)) then AH := "0000000"; end if;
|
|
||||||
-- pragma translate_on
|
|
||||||
|
|
||||||
if AH(5 downto 1) > 9 and P_In(Flag_D) = '1' then
|
|
||||||
AH(6 downto 1) := AH(6 downto 1) + 6;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
ADC_C <= AH(6) or AH(5);
|
|
||||||
|
|
||||||
ADC_Q <= std_logic_vector(AH(4 downto 1) & AL(4 downto 1));
|
|
||||||
end process;
|
|
||||||
|
|
||||||
process (Op, P_In, BusA, BusB)
|
|
||||||
variable AL : unsigned(6 downto 0);
|
|
||||||
variable AH : unsigned(5 downto 0);
|
|
||||||
variable C : std_logic;
|
|
||||||
begin
|
|
||||||
C := P_In(Flag_C) or not Op(0);
|
|
||||||
AL := resize(unsigned(BusA(3 downto 0) & C), 7) - resize(unsigned(BusB(3 downto 0) & "1"), 6);
|
|
||||||
AH := resize(unsigned(BusA(7 downto 4) & "0"), 6) - resize(unsigned(BusB(7 downto 4) & AL(5)), 6);
|
|
||||||
|
|
||||||
-- pragma translate_off
|
|
||||||
if is_x(std_logic_vector(AL)) then AL := "0000000"; end if;
|
|
||||||
if is_x(std_logic_vector(AH)) then AH := "000000"; end if;
|
|
||||||
-- pragma translate_on
|
|
||||||
|
|
||||||
if AL(4 downto 1) = 0 and AH(4 downto 1) = 0 then
|
|
||||||
SBC_Z <= '1';
|
|
||||||
else
|
|
||||||
SBC_Z <= '0';
|
|
||||||
end if;
|
|
||||||
|
|
||||||
SBC_C <= not AH(5);
|
|
||||||
SBC_V <= (AH(4) xor BusA(7)) and (BusA(7) xor BusB(7));
|
|
||||||
SBC_N <= AH(4);
|
|
||||||
|
|
||||||
if P_In(Flag_D) = '1' then
|
|
||||||
if AL(5) = '1' then
|
|
||||||
AL(5 downto 1) := AL(5 downto 1) - 6;
|
|
||||||
end if;
|
|
||||||
AH := resize(unsigned(BusA(7 downto 4) & "0"), 6) - resize(unsigned(BusB(7 downto 4) & AL(6)), 6);
|
|
||||||
if AH(5) = '1' then
|
|
||||||
AH(5 downto 1) := AH(5 downto 1) - 6;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
SBC_Q <= std_logic_vector(AH(4 downto 1) & AL(4 downto 1));
|
|
||||||
end process;
|
|
||||||
|
|
||||||
process (Op, P_In, BusA, BusB,
|
|
||||||
ADC_Z, ADC_C, ADC_V, ADC_N, ADC_Q,
|
|
||||||
SBC_Z, SBC_C, SBC_V, SBC_N, SBC_Q)
|
|
||||||
variable Q_t : std_logic_vector(7 downto 0);
|
|
||||||
begin
|
|
||||||
-- ORA, AND, EOR, ADC, NOP, LD, CMP, SBC
|
|
||||||
-- ASL, ROL, LSR, ROR, BIT, LD, DEC, INC
|
|
||||||
P_Out <= P_In;
|
|
||||||
Q_t := BusA;
|
|
||||||
case Op(3 downto 0) is
|
|
||||||
when "0000" =>
|
|
||||||
-- ORA
|
|
||||||
Q_t := BusA or BusB;
|
|
||||||
when "0001" =>
|
|
||||||
-- AND
|
|
||||||
Q_t := BusA and BusB;
|
|
||||||
when "0010" =>
|
|
||||||
-- EOR
|
|
||||||
Q_t := BusA xor BusB;
|
|
||||||
when "0011" =>
|
|
||||||
-- ADC
|
|
||||||
P_Out(Flag_V) <= ADC_V;
|
|
||||||
P_Out(Flag_C) <= ADC_C;
|
|
||||||
Q_t := ADC_Q;
|
|
||||||
when "0101" | "1101" =>
|
|
||||||
-- LDA
|
|
||||||
when "0110" =>
|
|
||||||
-- CMP
|
|
||||||
P_Out(Flag_C) <= SBC_C;
|
|
||||||
when "0111" =>
|
|
||||||
-- SBC
|
|
||||||
P_Out(Flag_V) <= SBC_V;
|
|
||||||
P_Out(Flag_C) <= SBC_C;
|
|
||||||
Q_t := SBC_Q;
|
|
||||||
when "1000" =>
|
|
||||||
-- ASL
|
|
||||||
Q_t := BusA(6 downto 0) & "0";
|
|
||||||
P_Out(Flag_C) <= BusA(7);
|
|
||||||
when "1001" =>
|
|
||||||
-- ROL
|
|
||||||
Q_t := BusA(6 downto 0) & P_In(Flag_C);
|
|
||||||
P_Out(Flag_C) <= BusA(7);
|
|
||||||
when "1010" =>
|
|
||||||
-- LSR
|
|
||||||
Q_t := "0" & BusA(7 downto 1);
|
|
||||||
P_Out(Flag_C) <= BusA(0);
|
|
||||||
when "1011" =>
|
|
||||||
-- ROR
|
|
||||||
Q_t := P_In(Flag_C) & BusA(7 downto 1);
|
|
||||||
P_Out(Flag_C) <= BusA(0);
|
|
||||||
when "1100" =>
|
|
||||||
-- BIT
|
|
||||||
P_Out(Flag_V) <= BusB(6);
|
|
||||||
when "1110" =>
|
|
||||||
-- DEC
|
|
||||||
Q_t := std_logic_vector(unsigned(BusA) - 1);
|
|
||||||
when "1111" =>
|
|
||||||
-- INC
|
|
||||||
Q_t := std_logic_vector(unsigned(BusA) + 1);
|
|
||||||
when others =>
|
|
||||||
end case;
|
|
||||||
|
|
||||||
case Op(3 downto 0) is
|
|
||||||
when "0011" =>
|
|
||||||
P_Out(Flag_N) <= ADC_N;
|
|
||||||
P_Out(Flag_Z) <= ADC_Z;
|
|
||||||
when "0110" | "0111" =>
|
|
||||||
P_Out(Flag_N) <= SBC_N;
|
|
||||||
P_Out(Flag_Z) <= SBC_Z;
|
|
||||||
when "0100" =>
|
|
||||||
when "1100" =>
|
|
||||||
P_Out(Flag_N) <= BusB(7);
|
|
||||||
if (BusA and BusB) = "00000000" then
|
|
||||||
P_Out(Flag_Z) <= '1';
|
|
||||||
else
|
|
||||||
P_Out(Flag_Z) <= '0';
|
|
||||||
end if;
|
|
||||||
when others =>
|
|
||||||
P_Out(Flag_N) <= Q_t(7);
|
|
||||||
if Q_t = "00000000" then
|
|
||||||
P_Out(Flag_Z) <= '1';
|
|
||||||
else
|
|
||||||
P_Out(Flag_Z) <= '0';
|
|
||||||
end if;
|
|
||||||
end case;
|
|
||||||
|
|
||||||
Q <= Q_t;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
end;
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,117 +0,0 @@
|
|||||||
-- ****
|
|
||||||
-- T65(b) core. In an effort to merge and maintain bug fixes ....
|
|
||||||
--
|
|
||||||
--
|
|
||||||
-- Ver 300 Bugfixes by ehenciak added
|
|
||||||
-- MikeJ March 2005
|
|
||||||
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
|
|
||||||
--
|
|
||||||
-- ****
|
|
||||||
--
|
|
||||||
-- 65xx compatible microprocessor core
|
|
||||||
--
|
|
||||||
-- Version : 0246
|
|
||||||
--
|
|
||||||
-- Copyright (c) 2002 Daniel Wallner (jesus@opencores.org)
|
|
||||||
--
|
|
||||||
-- All rights reserved
|
|
||||||
--
|
|
||||||
-- Redistribution and use in source and synthezised forms, with or without
|
|
||||||
-- modification, are permitted provided that the following conditions are met:
|
|
||||||
--
|
|
||||||
-- Redistributions of source code must retain the above copyright notice,
|
|
||||||
-- this list of conditions and the following disclaimer.
|
|
||||||
--
|
|
||||||
-- Redistributions in synthesized form must reproduce the above copyright
|
|
||||||
-- notice, this list of conditions and the following disclaimer in the
|
|
||||||
-- documentation and/or other materials provided with the distribution.
|
|
||||||
--
|
|
||||||
-- Neither the name of the author nor the names of other contributors may
|
|
||||||
-- be used to endorse or promote products derived from this software without
|
|
||||||
-- specific prior written permission.
|
|
||||||
--
|
|
||||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
|
||||||
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
--
|
|
||||||
-- Please report bugs to the author, but before you do so, please
|
|
||||||
-- make sure that this is not a derivative work and that
|
|
||||||
-- you have the latest version of this file.
|
|
||||||
--
|
|
||||||
-- The latest version of this file can be found at:
|
|
||||||
-- http://www.opencores.org/cvsweb.shtml/t65/
|
|
||||||
--
|
|
||||||
-- Limitations :
|
|
||||||
--
|
|
||||||
-- File history :
|
|
||||||
--
|
|
||||||
|
|
||||||
library IEEE;
|
|
||||||
use IEEE.std_logic_1164.all;
|
|
||||||
|
|
||||||
package T65_Pack is
|
|
||||||
|
|
||||||
constant Flag_C : integer := 0;
|
|
||||||
constant Flag_Z : integer := 1;
|
|
||||||
constant Flag_I : integer := 2;
|
|
||||||
constant Flag_D : integer := 3;
|
|
||||||
constant Flag_B : integer := 4;
|
|
||||||
constant Flag_1 : integer := 5;
|
|
||||||
constant Flag_V : integer := 6;
|
|
||||||
constant Flag_N : integer := 7;
|
|
||||||
|
|
||||||
component T65_MCode
|
|
||||||
port(
|
|
||||||
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65816
|
|
||||||
IR : in std_logic_vector(7 downto 0);
|
|
||||||
MCycle : in std_logic_vector(2 downto 0);
|
|
||||||
P : in std_logic_vector(7 downto 0);
|
|
||||||
LCycle : out std_logic_vector(2 downto 0);
|
|
||||||
ALU_Op : out std_logic_vector(3 downto 0);
|
|
||||||
Set_BusA_To : out std_logic_vector(2 downto 0); -- DI,A,X,Y,S,P
|
|
||||||
Set_Addr_To : out std_logic_vector(1 downto 0); -- PC Adder,S,AD,BA
|
|
||||||
Write_Data : out std_logic_vector(2 downto 0); -- DL,A,X,Y,S,P,PCL,PCH
|
|
||||||
Jump : out std_logic_vector(1 downto 0); -- PC,++,DIDL,Rel
|
|
||||||
BAAdd : out std_logic_vector(1 downto 0); -- None,DB Inc,BA Add,BA Adj
|
|
||||||
BreakAtNA : out std_logic;
|
|
||||||
ADAdd : out std_logic;
|
|
||||||
AddY : out std_logic;
|
|
||||||
PCAdd : out std_logic;
|
|
||||||
Inc_S : out std_logic;
|
|
||||||
Dec_S : out std_logic;
|
|
||||||
LDA : out std_logic;
|
|
||||||
LDP : out std_logic;
|
|
||||||
LDX : out std_logic;
|
|
||||||
LDY : out std_logic;
|
|
||||||
LDS : out std_logic;
|
|
||||||
LDDI : out std_logic;
|
|
||||||
LDALU : out std_logic;
|
|
||||||
LDAD : out std_logic;
|
|
||||||
LDBAL : out std_logic;
|
|
||||||
LDBAH : out std_logic;
|
|
||||||
SaveP : out std_logic;
|
|
||||||
Write : out std_logic
|
|
||||||
);
|
|
||||||
end component;
|
|
||||||
|
|
||||||
component T65_ALU
|
|
||||||
port(
|
|
||||||
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65C816
|
|
||||||
Op : in std_logic_vector(3 downto 0);
|
|
||||||
BusA : in std_logic_vector(7 downto 0);
|
|
||||||
BusB : in std_logic_vector(7 downto 0);
|
|
||||||
P_In : in std_logic_vector(7 downto 0);
|
|
||||||
P_Out : out std_logic_vector(7 downto 0);
|
|
||||||
Q : out std_logic_vector(7 downto 0)
|
|
||||||
);
|
|
||||||
end component;
|
|
||||||
|
|
||||||
end;
|
|
||||||
@@ -1,243 +0,0 @@
|
|||||||
//
|
|
||||||
//
|
|
||||||
// Copyright (c) 2017 Sorgelig
|
|
||||||
//
|
|
||||||
// This program is GPL Licensed. See COPYING for the full license.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
`timescale 1ns / 1ps
|
|
||||||
|
|
||||||
//
|
|
||||||
// LINE_LENGTH: Length of display line in pixels
|
|
||||||
// Usually it's length from HSync to HSync.
|
|
||||||
// May be less if line_start is used.
|
|
||||||
//
|
|
||||||
// HALF_DEPTH: If =1 then color dept is 3 bits per component
|
|
||||||
// For half depth 6 bits monochrome is available with
|
|
||||||
// mono signal enabled and color = {G, R}
|
|
||||||
|
|
||||||
module video_mixer
|
|
||||||
#(
|
|
||||||
parameter LINE_LENGTH = 768,
|
|
||||||
parameter HALF_DEPTH = 0,
|
|
||||||
|
|
||||||
parameter OSD_COLOR = 3'd4,
|
|
||||||
parameter OSD_X_OFFSET = 10'd0,
|
|
||||||
parameter OSD_Y_OFFSET = 10'd0
|
|
||||||
)
|
|
||||||
(
|
|
||||||
// master clock
|
|
||||||
// it should be multiple by (ce_pix*4).
|
|
||||||
input clk_sys,
|
|
||||||
|
|
||||||
// Pixel clock or clock_enable (both are accepted).
|
|
||||||
input ce_pix,
|
|
||||||
|
|
||||||
// Some systems have multiple resolutions.
|
|
||||||
// ce_pix_actual should match ce_pix where every second or fourth pulse is enabled,
|
|
||||||
// thus half or qurter resolutions can be used without brake video sync while switching resolutions.
|
|
||||||
// For fixed single resolution (or when video sync stability isn't required) ce_pix_actual = ce_pix.
|
|
||||||
input ce_pix_actual,
|
|
||||||
|
|
||||||
// OSD SPI interface
|
|
||||||
input SPI_SCK,
|
|
||||||
input SPI_SS3,
|
|
||||||
input SPI_DI,
|
|
||||||
|
|
||||||
// scanlines (00-none 01-25% 10-50% 11-75%)
|
|
||||||
input [1:0] scanlines,
|
|
||||||
|
|
||||||
// 0 = HVSync 31KHz, 1 = CSync 15KHz
|
|
||||||
input scandoubler_disable,
|
|
||||||
|
|
||||||
// High quality 2x scaling
|
|
||||||
input hq2x,
|
|
||||||
|
|
||||||
// YPbPr always uses composite sync
|
|
||||||
input ypbpr,
|
|
||||||
|
|
||||||
// 0 = 16-240 range. 1 = 0-255 range. (only for YPbPr color space)
|
|
||||||
input ypbpr_full,
|
|
||||||
input [1:0] rotate, //[0] - rotate [1] - left or right
|
|
||||||
// color
|
|
||||||
input [DWIDTH:0] R,
|
|
||||||
input [DWIDTH:0] G,
|
|
||||||
input [DWIDTH:0] B,
|
|
||||||
|
|
||||||
// Monochrome mode (for HALF_DEPTH only)
|
|
||||||
input mono,
|
|
||||||
|
|
||||||
// interlace sync. Positive pulses.
|
|
||||||
input HSync,
|
|
||||||
input VSync,
|
|
||||||
|
|
||||||
// Falling of this signal means start of informative part of line.
|
|
||||||
// It can be horizontal blank signal.
|
|
||||||
// This signal can be used to reduce amount of required FPGA RAM for HQ2x scan doubler
|
|
||||||
// If FPGA RAM is not an issue, then simply set it to 0 for whole line processing.
|
|
||||||
// Keep in mind: due to algo first and last pixels of line should be black to avoid side artefacts.
|
|
||||||
// Thus, if blank signal is used to reduce the line, make sure to feed at least one black (or paper) pixel
|
|
||||||
// before first informative pixel.
|
|
||||||
input line_start,
|
|
||||||
|
|
||||||
// MiST video output signals
|
|
||||||
output [5:0] VGA_R,
|
|
||||||
output [5:0] VGA_G,
|
|
||||||
output [5:0] VGA_B,
|
|
||||||
output VGA_VS,
|
|
||||||
output VGA_HS
|
|
||||||
);
|
|
||||||
|
|
||||||
localparam DWIDTH = HALF_DEPTH ? 2 : 5;
|
|
||||||
|
|
||||||
wire [DWIDTH:0] R_sd;
|
|
||||||
wire [DWIDTH:0] G_sd;
|
|
||||||
wire [DWIDTH:0] B_sd;
|
|
||||||
wire hs_sd, vs_sd;
|
|
||||||
|
|
||||||
scandoubler #(.LENGTH(LINE_LENGTH), .HALF_DEPTH(HALF_DEPTH)) scandoubler
|
|
||||||
(
|
|
||||||
.*,
|
|
||||||
.hs_in(HSync),
|
|
||||||
.vs_in(VSync),
|
|
||||||
.r_in(R),
|
|
||||||
.g_in(G),
|
|
||||||
.b_in(B),
|
|
||||||
|
|
||||||
.hs_out(hs_sd),
|
|
||||||
.vs_out(vs_sd),
|
|
||||||
.r_out(R_sd),
|
|
||||||
.g_out(G_sd),
|
|
||||||
.b_out(B_sd)
|
|
||||||
);
|
|
||||||
|
|
||||||
wire [DWIDTH:0] rt = (scandoubler_disable ? R : R_sd);
|
|
||||||
wire [DWIDTH:0] gt = (scandoubler_disable ? G : G_sd);
|
|
||||||
wire [DWIDTH:0] bt = (scandoubler_disable ? B : B_sd);
|
|
||||||
|
|
||||||
generate
|
|
||||||
if(HALF_DEPTH) begin
|
|
||||||
wire [5:0] r = mono ? {gt,rt} : {rt,rt};
|
|
||||||
wire [5:0] g = mono ? {gt,rt} : {gt,gt};
|
|
||||||
wire [5:0] b = mono ? {gt,rt} : {bt,bt};
|
|
||||||
end else begin
|
|
||||||
wire [5:0] r = rt;
|
|
||||||
wire [5:0] g = gt;
|
|
||||||
wire [5:0] b = bt;
|
|
||||||
end
|
|
||||||
endgenerate
|
|
||||||
|
|
||||||
wire hs = (scandoubler_disable ? HSync : hs_sd);
|
|
||||||
wire vs = (scandoubler_disable ? VSync : vs_sd);
|
|
||||||
|
|
||||||
reg scanline = 0;
|
|
||||||
always @(posedge clk_sys) begin
|
|
||||||
reg old_hs, old_vs;
|
|
||||||
|
|
||||||
old_hs <= hs;
|
|
||||||
old_vs <= vs;
|
|
||||||
|
|
||||||
if(old_hs && ~hs) scanline <= ~scanline;
|
|
||||||
if(old_vs && ~vs) scanline <= 0;
|
|
||||||
end
|
|
||||||
|
|
||||||
wire [5:0] r_out, g_out, b_out;
|
|
||||||
always @(*) begin
|
|
||||||
case(scanlines & {scanline, scanline})
|
|
||||||
1: begin // reduce 25% = 1/2 + 1/4
|
|
||||||
r_out = {1'b0, r[5:1]} + {2'b00, r[5:2]};
|
|
||||||
g_out = {1'b0, g[5:1]} + {2'b00, g[5:2]};
|
|
||||||
b_out = {1'b0, b[5:1]} + {2'b00, b[5:2]};
|
|
||||||
end
|
|
||||||
|
|
||||||
2: begin // reduce 50% = 1/2
|
|
||||||
r_out = {1'b0, r[5:1]};
|
|
||||||
g_out = {1'b0, g[5:1]};
|
|
||||||
b_out = {1'b0, b[5:1]};
|
|
||||||
end
|
|
||||||
|
|
||||||
3: begin // reduce 75% = 1/4
|
|
||||||
r_out = {2'b00, r[5:2]};
|
|
||||||
g_out = {2'b00, g[5:2]};
|
|
||||||
b_out = {2'b00, b[5:2]};
|
|
||||||
end
|
|
||||||
|
|
||||||
default: begin
|
|
||||||
r_out = r;
|
|
||||||
g_out = g;
|
|
||||||
b_out = b;
|
|
||||||
end
|
|
||||||
endcase
|
|
||||||
end
|
|
||||||
|
|
||||||
wire [5:0] red, green, blue;
|
|
||||||
osd #(OSD_X_OFFSET, OSD_Y_OFFSET, OSD_COLOR) osd
|
|
||||||
(
|
|
||||||
.*,
|
|
||||||
|
|
||||||
.R_in(r_out),
|
|
||||||
.G_in(g_out),
|
|
||||||
.B_in(b_out),
|
|
||||||
.HSync(hs),
|
|
||||||
.VSync(vs),
|
|
||||||
.rotate(rotate),
|
|
||||||
|
|
||||||
.R_out(red),
|
|
||||||
.G_out(green),
|
|
||||||
.B_out(blue)
|
|
||||||
);
|
|
||||||
|
|
||||||
wire [5:0] yuv_full[225] = '{
|
|
||||||
6'd0, 6'd0, 6'd0, 6'd0, 6'd1, 6'd1, 6'd1, 6'd1,
|
|
||||||
6'd2, 6'd2, 6'd2, 6'd3, 6'd3, 6'd3, 6'd3, 6'd4,
|
|
||||||
6'd4, 6'd4, 6'd5, 6'd5, 6'd5, 6'd5, 6'd6, 6'd6,
|
|
||||||
6'd6, 6'd7, 6'd7, 6'd7, 6'd7, 6'd8, 6'd8, 6'd8,
|
|
||||||
6'd9, 6'd9, 6'd9, 6'd9, 6'd10, 6'd10, 6'd10, 6'd11,
|
|
||||||
6'd11, 6'd11, 6'd11, 6'd12, 6'd12, 6'd12, 6'd13, 6'd13,
|
|
||||||
6'd13, 6'd13, 6'd14, 6'd14, 6'd14, 6'd15, 6'd15, 6'd15,
|
|
||||||
6'd15, 6'd16, 6'd16, 6'd16, 6'd17, 6'd17, 6'd17, 6'd17,
|
|
||||||
6'd18, 6'd18, 6'd18, 6'd19, 6'd19, 6'd19, 6'd19, 6'd20,
|
|
||||||
6'd20, 6'd20, 6'd21, 6'd21, 6'd21, 6'd21, 6'd22, 6'd22,
|
|
||||||
6'd22, 6'd23, 6'd23, 6'd23, 6'd23, 6'd24, 6'd24, 6'd24,
|
|
||||||
6'd25, 6'd25, 6'd25, 6'd25, 6'd26, 6'd26, 6'd26, 6'd27,
|
|
||||||
6'd27, 6'd27, 6'd27, 6'd28, 6'd28, 6'd28, 6'd29, 6'd29,
|
|
||||||
6'd29, 6'd29, 6'd30, 6'd30, 6'd30, 6'd31, 6'd31, 6'd31,
|
|
||||||
6'd31, 6'd32, 6'd32, 6'd32, 6'd33, 6'd33, 6'd33, 6'd33,
|
|
||||||
6'd34, 6'd34, 6'd34, 6'd35, 6'd35, 6'd35, 6'd35, 6'd36,
|
|
||||||
6'd36, 6'd36, 6'd36, 6'd37, 6'd37, 6'd37, 6'd38, 6'd38,
|
|
||||||
6'd38, 6'd38, 6'd39, 6'd39, 6'd39, 6'd40, 6'd40, 6'd40,
|
|
||||||
6'd40, 6'd41, 6'd41, 6'd41, 6'd42, 6'd42, 6'd42, 6'd42,
|
|
||||||
6'd43, 6'd43, 6'd43, 6'd44, 6'd44, 6'd44, 6'd44, 6'd45,
|
|
||||||
6'd45, 6'd45, 6'd46, 6'd46, 6'd46, 6'd46, 6'd47, 6'd47,
|
|
||||||
6'd47, 6'd48, 6'd48, 6'd48, 6'd48, 6'd49, 6'd49, 6'd49,
|
|
||||||
6'd50, 6'd50, 6'd50, 6'd50, 6'd51, 6'd51, 6'd51, 6'd52,
|
|
||||||
6'd52, 6'd52, 6'd52, 6'd53, 6'd53, 6'd53, 6'd54, 6'd54,
|
|
||||||
6'd54, 6'd54, 6'd55, 6'd55, 6'd55, 6'd56, 6'd56, 6'd56,
|
|
||||||
6'd56, 6'd57, 6'd57, 6'd57, 6'd58, 6'd58, 6'd58, 6'd58,
|
|
||||||
6'd59, 6'd59, 6'd59, 6'd60, 6'd60, 6'd60, 6'd60, 6'd61,
|
|
||||||
6'd61, 6'd61, 6'd62, 6'd62, 6'd62, 6'd62, 6'd63, 6'd63,
|
|
||||||
6'd63
|
|
||||||
};
|
|
||||||
|
|
||||||
// http://marsee101.blog19.fc2.com/blog-entry-2311.html
|
|
||||||
// Y = 16 + 0.257*R + 0.504*G + 0.098*B (Y = 0.299*R + 0.587*G + 0.114*B)
|
|
||||||
// Pb = 128 - 0.148*R - 0.291*G + 0.439*B (Pb = -0.169*R - 0.331*G + 0.500*B)
|
|
||||||
// Pr = 128 + 0.439*R - 0.368*G - 0.071*B (Pr = 0.500*R - 0.419*G - 0.081*B)
|
|
||||||
|
|
||||||
wire [18:0] y_8 = 19'd04096 + ({red, 8'd0} + {red, 3'd0}) + ({green, 9'd0} + {green, 2'd0}) + ({blue, 6'd0} + {blue, 5'd0} + {blue, 2'd0});
|
|
||||||
wire [18:0] pb_8 = 19'd32768 - ({red, 7'd0} + {red, 4'd0} + {red, 3'd0}) - ({green, 8'd0} + {green, 5'd0} + {green, 3'd0}) + ({blue, 8'd0} + {blue, 7'd0} + {blue, 6'd0});
|
|
||||||
wire [18:0] pr_8 = 19'd32768 + ({red, 8'd0} + {red, 7'd0} + {red, 6'd0}) - ({green, 8'd0} + {green, 6'd0} + {green, 5'd0} + {green, 4'd0} + {green, 3'd0}) - ({blue, 6'd0} + {blue , 3'd0});
|
|
||||||
|
|
||||||
wire [7:0] y = ( y_8[17:8] < 16) ? 8'd16 : ( y_8[17:8] > 235) ? 8'd235 : y_8[15:8];
|
|
||||||
wire [7:0] pb = (pb_8[17:8] < 16) ? 8'd16 : (pb_8[17:8] > 240) ? 8'd240 : pb_8[15:8];
|
|
||||||
wire [7:0] pr = (pr_8[17:8] < 16) ? 8'd16 : (pr_8[17:8] > 240) ? 8'd240 : pr_8[15:8];
|
|
||||||
|
|
||||||
assign VGA_R = ypbpr ? (ypbpr_full ? yuv_full[pr-8'd16] : pr[7:2]) : red;
|
|
||||||
assign VGA_G = ypbpr ? (ypbpr_full ? yuv_full[y -8'd16] : y[7:2]) : green;
|
|
||||||
assign VGA_B = ypbpr ? (ypbpr_full ? yuv_full[pb-8'd16] : pb[7:2]) : blue;
|
|
||||||
assign VGA_VS = (scandoubler_disable | ypbpr) ? 1'b1 : ~vs_sd;
|
|
||||||
assign VGA_HS = scandoubler_disable ? ~(HSync ^ VSync) : ypbpr ? ~(hs_sd ^ vs_sd) : ~hs_sd;
|
|
||||||
|
|
||||||
endmodule
|
|
||||||
674
common/CPU/T65/T65.vhd
Normal file
674
common/CPU/T65/T65.vhd
Normal file
@@ -0,0 +1,674 @@
|
|||||||
|
-- ****
|
||||||
|
-- T65(b) core. In an effort to merge and maintain bug fixes ....
|
||||||
|
--
|
||||||
|
-- Ver 313 WoS January 2015
|
||||||
|
-- Fixed issue that NMI has to be first if issued the same time as a BRK instruction is latched in
|
||||||
|
-- Now all Lorenz CPU tests on FPGAARCADE C64 core (sources used: SVN version 1021) are OK! :D :D :D
|
||||||
|
-- This is just a starting point to go for optimizations and detailed fixes (the Lorenz test can't find)
|
||||||
|
--
|
||||||
|
-- Ver 312 WoS January 2015
|
||||||
|
-- Undoc opcode timing fixes for $B3 (LAX iy) and $BB (LAS ay)
|
||||||
|
-- Added comments in MCode section to find handling of individual opcodes more easily
|
||||||
|
-- All "basic" Lorenz instruction test (individual functional checks, CPUTIMING check) work now with
|
||||||
|
-- actual FPGAARCADE C64 core (sources used: SVN version 1021).
|
||||||
|
--
|
||||||
|
-- Ver 305, 306, 307, 308, 309, 310, 311 WoS January 2015
|
||||||
|
-- Undoc opcode fixes (now all Lorenz test on instruction functionality working, except timing issues on $B3 and $BB):
|
||||||
|
-- SAX opcode
|
||||||
|
-- SHA opcode
|
||||||
|
-- SHX opcode
|
||||||
|
-- SHY opcode
|
||||||
|
-- SHS opcode
|
||||||
|
-- LAS opcode
|
||||||
|
-- alternate SBC opcode
|
||||||
|
-- fixed NOP with immediate param (caused Lorenz trap test to fail)
|
||||||
|
-- IRQ and NMI timing fixes (in conjuction with branches)
|
||||||
|
--
|
||||||
|
-- Ver 304 WoS December 2014
|
||||||
|
-- Undoc opcode fixes:
|
||||||
|
-- ARR opcode
|
||||||
|
-- ANE/XAA opcode
|
||||||
|
-- Corrected issue with NMI/IRQ prio (when asserted the same time)
|
||||||
|
--
|
||||||
|
-- Ver 303 ost(ML) July 2014
|
||||||
|
-- (Sorry for some scratchpad comments that may make little sense)
|
||||||
|
-- Mods and some 6502 undocumented instructions.
|
||||||
|
-- Not correct opcodes acc. to Lorenz tests (incomplete list):
|
||||||
|
-- NOPN (nop)
|
||||||
|
-- NOPZX (nop + byte 172)
|
||||||
|
-- NOPAX (nop + word da ... da: byte 0)
|
||||||
|
-- ASOZ (byte $07 + byte 172)
|
||||||
|
--
|
||||||
|
-- Ver 303,302 WoS April 2014
|
||||||
|
-- Bugfixes for NMI from foft
|
||||||
|
-- Bugfix for BRK command (and its special flag)
|
||||||
|
--
|
||||||
|
-- Ver 300,301 WoS January 2014
|
||||||
|
-- More merging
|
||||||
|
-- Bugfixes by ehenciak added, started tidyup *bust*
|
||||||
|
--
|
||||||
|
-- MikeJ March 2005
|
||||||
|
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
|
||||||
|
-- ****
|
||||||
|
--
|
||||||
|
-- 65xx compatible microprocessor core
|
||||||
|
--
|
||||||
|
-- FPGAARCADE SVN: $Id: T65.vhd 1347 2015-05-27 20:07:34Z wolfgang.scherr $
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2002...2015
|
||||||
|
-- Daniel Wallner (jesus <at> opencores <dot> org)
|
||||||
|
-- Mike Johnson (mikej <at> fpgaarcade <dot> com)
|
||||||
|
-- Wolfgang Scherr (WoS <at> pin4 <dot> at>
|
||||||
|
-- Morten Leikvoll ()
|
||||||
|
--
|
||||||
|
-- All rights reserved
|
||||||
|
--
|
||||||
|
-- Redistribution and use in source and synthezised forms, with or without
|
||||||
|
-- modification, are permitted provided that the following conditions are met:
|
||||||
|
--
|
||||||
|
-- Redistributions of source code must retain the above copyright notice,
|
||||||
|
-- this list of conditions and the following disclaimer.
|
||||||
|
--
|
||||||
|
-- Redistributions in synthesized form must reproduce the above copyright
|
||||||
|
-- notice, this list of conditions and the following disclaimer in the
|
||||||
|
-- documentation and/or other materials provided with the distribution.
|
||||||
|
--
|
||||||
|
-- Neither the name of the author nor the names of other contributors may
|
||||||
|
-- be used to endorse or promote products derived from this software without
|
||||||
|
-- specific prior written permission.
|
||||||
|
--
|
||||||
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
||||||
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
--
|
||||||
|
-- Please report bugs to the author(s), but before you do so, please
|
||||||
|
-- make sure that this is not a derivative work and that
|
||||||
|
-- you have the latest version of this file.
|
||||||
|
--
|
||||||
|
-- ----- IMPORTANT NOTES -----
|
||||||
|
--
|
||||||
|
-- Limitations:
|
||||||
|
-- 65C02 and 65C816 modes are incomplete (and definitely untested after all 6502 undoc fixes)
|
||||||
|
-- 65C02 supported : inc, dec, phx, plx, phy, ply
|
||||||
|
-- 65D02 missing : bra, ora, lda, cmp, sbc, tsb*2, trb*2, stz*2, bit*2, wai, stp, jmp, bbr*8, bbs*8
|
||||||
|
-- Some interface signals behave incorrect
|
||||||
|
-- NMI interrupt handling not nice, needs further rework (to cycle-based encoding).
|
||||||
|
--
|
||||||
|
-- Usage:
|
||||||
|
-- The enable signal allows clock gating / throttling without using the ready signal.
|
||||||
|
-- Set it to constant '1' when using the Clk input as the CPU clock directly.
|
||||||
|
--
|
||||||
|
-- TAKE CARE you route the DO signal back to the DI signal while R_W_n='0',
|
||||||
|
-- otherwise some undocumented opcodes won't work correctly.
|
||||||
|
-- EXAMPLE:
|
||||||
|
-- CPU : entity work.T65
|
||||||
|
-- port map (
|
||||||
|
-- R_W_n => cpu_rwn_s,
|
||||||
|
-- [....all other ports....]
|
||||||
|
-- DI => cpu_din_s,
|
||||||
|
-- DO => cpu_dout_s
|
||||||
|
-- );
|
||||||
|
-- cpu_din_s <= cpu_dout_s when cpu_rwn_s='0' else
|
||||||
|
-- [....other sources from peripherals and memories...]
|
||||||
|
--
|
||||||
|
-- ----- IMPORTANT NOTES -----
|
||||||
|
--
|
||||||
|
|
||||||
|
library IEEE;
|
||||||
|
use IEEE.std_logic_1164.all;
|
||||||
|
use IEEE.numeric_std.all;
|
||||||
|
use work.T65_Pack.all;
|
||||||
|
|
||||||
|
entity T65 is
|
||||||
|
port(
|
||||||
|
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65C816
|
||||||
|
Res_n : in std_logic;
|
||||||
|
Enable : in std_logic;
|
||||||
|
Clk : in std_logic;
|
||||||
|
Rdy : in std_logic;
|
||||||
|
Abort_n : in std_logic;
|
||||||
|
IRQ_n : in std_logic;
|
||||||
|
NMI_n : in std_logic;
|
||||||
|
SO_n : in std_logic;
|
||||||
|
R_W_n : out std_logic;
|
||||||
|
Sync : out std_logic;
|
||||||
|
EF : out std_logic;
|
||||||
|
MF : out std_logic;
|
||||||
|
XF : out std_logic;
|
||||||
|
ML_n : out std_logic;
|
||||||
|
VP_n : out std_logic;
|
||||||
|
VDA : out std_logic;
|
||||||
|
VPA : out std_logic;
|
||||||
|
A : out std_logic_vector(23 downto 0);
|
||||||
|
DI : in std_logic_vector(7 downto 0);
|
||||||
|
DO : out std_logic_vector(7 downto 0);
|
||||||
|
-- 6502 registers (MSB) PC, SP, P, Y, X, A (LSB)
|
||||||
|
Regs : out std_logic_vector(63 downto 0);
|
||||||
|
DEBUG : out T_t65_dbg;
|
||||||
|
NMI_ack : out std_logic
|
||||||
|
);
|
||||||
|
end T65;
|
||||||
|
|
||||||
|
architecture rtl of T65 is
|
||||||
|
|
||||||
|
-- Registers
|
||||||
|
signal ABC, X, Y : std_logic_vector(15 downto 0);
|
||||||
|
signal P, AD, DL : std_logic_vector(7 downto 0) := x"00";
|
||||||
|
signal PwithB : std_logic_vector(7 downto 0);--ML:New way to push P with correct B state to stack
|
||||||
|
signal BAH : std_logic_vector(7 downto 0);
|
||||||
|
signal BAL : std_logic_vector(8 downto 0);
|
||||||
|
signal PBR : std_logic_vector(7 downto 0);
|
||||||
|
signal DBR : std_logic_vector(7 downto 0);
|
||||||
|
signal PC : unsigned(15 downto 0);
|
||||||
|
signal S : unsigned(15 downto 0);
|
||||||
|
signal EF_i : std_logic;
|
||||||
|
signal MF_i : std_logic;
|
||||||
|
signal XF_i : std_logic;
|
||||||
|
|
||||||
|
signal IR : std_logic_vector(7 downto 0);
|
||||||
|
signal MCycle : std_logic_vector(2 downto 0);
|
||||||
|
|
||||||
|
signal Mode_r : std_logic_vector(1 downto 0);
|
||||||
|
signal ALU_Op_r : T_ALU_Op;
|
||||||
|
signal Write_Data_r : T_Write_Data;
|
||||||
|
signal Set_Addr_To_r : T_Set_Addr_To;
|
||||||
|
signal PCAdder : unsigned(8 downto 0);
|
||||||
|
|
||||||
|
signal RstCycle : std_logic;
|
||||||
|
signal IRQCycle : std_logic;
|
||||||
|
signal NMICycle : std_logic;
|
||||||
|
|
||||||
|
signal SO_n_o : std_logic;
|
||||||
|
signal IRQ_n_o : std_logic;
|
||||||
|
signal NMI_n_o : std_logic;
|
||||||
|
signal NMIAct : std_logic;
|
||||||
|
|
||||||
|
signal Break : std_logic;
|
||||||
|
|
||||||
|
-- ALU signals
|
||||||
|
signal BusA : std_logic_vector(7 downto 0);
|
||||||
|
signal BusA_r : std_logic_vector(7 downto 0);
|
||||||
|
signal BusB : std_logic_vector(7 downto 0);
|
||||||
|
signal BusB_r : std_logic_vector(7 downto 0);
|
||||||
|
signal ALU_Q : std_logic_vector(7 downto 0);
|
||||||
|
signal P_Out : std_logic_vector(7 downto 0);
|
||||||
|
|
||||||
|
-- Micro code outputs
|
||||||
|
signal LCycle : std_logic_vector(2 downto 0);
|
||||||
|
signal ALU_Op : T_ALU_Op;
|
||||||
|
signal Set_BusA_To : T_Set_BusA_To;
|
||||||
|
signal Set_Addr_To : T_Set_Addr_To;
|
||||||
|
signal Write_Data : T_Write_Data;
|
||||||
|
signal Jump : std_logic_vector(1 downto 0);
|
||||||
|
signal BAAdd : std_logic_vector(1 downto 0);
|
||||||
|
signal BreakAtNA : std_logic;
|
||||||
|
signal ADAdd : std_logic;
|
||||||
|
signal AddY : std_logic;
|
||||||
|
signal PCAdd : std_logic;
|
||||||
|
signal Inc_S : std_logic;
|
||||||
|
signal Dec_S : std_logic;
|
||||||
|
signal LDA : std_logic;
|
||||||
|
signal LDP : std_logic;
|
||||||
|
signal LDX : std_logic;
|
||||||
|
signal LDY : std_logic;
|
||||||
|
signal LDS : std_logic;
|
||||||
|
signal LDDI : std_logic;
|
||||||
|
signal LDALU : std_logic;
|
||||||
|
signal LDAD : std_logic;
|
||||||
|
signal LDBAL : std_logic;
|
||||||
|
signal LDBAH : std_logic;
|
||||||
|
signal SaveP : std_logic;
|
||||||
|
signal Write : std_logic;
|
||||||
|
|
||||||
|
signal Res_n_i : std_logic;
|
||||||
|
signal Res_n_d : std_logic;
|
||||||
|
|
||||||
|
signal really_rdy : std_logic;
|
||||||
|
signal WRn_i : std_logic;
|
||||||
|
|
||||||
|
signal NMI_entered : std_logic;
|
||||||
|
|
||||||
|
begin
|
||||||
|
NMI_ack <= NMIAct;
|
||||||
|
|
||||||
|
-- gate Rdy with read/write to make an "OK, it's really OK to stop the processor
|
||||||
|
really_rdy <= Rdy or not(WRn_i);
|
||||||
|
Sync <= '1' when MCycle = "000" else '0';
|
||||||
|
EF <= EF_i;
|
||||||
|
MF <= MF_i;
|
||||||
|
XF <= XF_i;
|
||||||
|
R_W_n <= WRn_i;
|
||||||
|
ML_n <= '0' when IR(7 downto 6) /= "10" and IR(2 downto 1) = "11" and MCycle(2 downto 1) /= "00" else '1';
|
||||||
|
VP_n <= '0' when IRQCycle = '1' and (MCycle = "101" or MCycle = "110") else '1';
|
||||||
|
VDA <= '1' when Set_Addr_To_r /= Set_Addr_To_PBR else '0';
|
||||||
|
VPA <= '1' when Jump(1) = '0' else '0';
|
||||||
|
|
||||||
|
-- debugging signals
|
||||||
|
DEBUG.I <= IR;
|
||||||
|
DEBUG.A <= ABC(7 downto 0);
|
||||||
|
DEBUG.X <= X(7 downto 0);
|
||||||
|
DEBUG.Y <= Y(7 downto 0);
|
||||||
|
DEBUG.S <= std_logic_vector(S(7 downto 0));
|
||||||
|
DEBUG.P <= P;
|
||||||
|
|
||||||
|
Regs <= std_logic_vector(PC) & std_logic_vector(S)& P & Y(7 downto 0) & X(7 downto 0) & ABC(7 downto 0);
|
||||||
|
|
||||||
|
mcode : entity work.T65_MCode
|
||||||
|
port map(
|
||||||
|
--inputs
|
||||||
|
Mode => Mode_r,
|
||||||
|
IR => IR,
|
||||||
|
MCycle => MCycle,
|
||||||
|
P => P,
|
||||||
|
--outputs
|
||||||
|
LCycle => LCycle,
|
||||||
|
ALU_Op => ALU_Op,
|
||||||
|
Set_BusA_To => Set_BusA_To,
|
||||||
|
Set_Addr_To => Set_Addr_To,
|
||||||
|
Write_Data => Write_Data,
|
||||||
|
Jump => Jump,
|
||||||
|
BAAdd => BAAdd,
|
||||||
|
BreakAtNA => BreakAtNA,
|
||||||
|
ADAdd => ADAdd,
|
||||||
|
AddY => AddY,
|
||||||
|
PCAdd => PCAdd,
|
||||||
|
Inc_S => Inc_S,
|
||||||
|
Dec_S => Dec_S,
|
||||||
|
LDA => LDA,
|
||||||
|
LDP => LDP,
|
||||||
|
LDX => LDX,
|
||||||
|
LDY => LDY,
|
||||||
|
LDS => LDS,
|
||||||
|
LDDI => LDDI,
|
||||||
|
LDALU => LDALU,
|
||||||
|
LDAD => LDAD,
|
||||||
|
LDBAL => LDBAL,
|
||||||
|
LDBAH => LDBAH,
|
||||||
|
SaveP => SaveP,
|
||||||
|
Write => Write
|
||||||
|
);
|
||||||
|
|
||||||
|
alu : entity work.T65_ALU
|
||||||
|
port map(
|
||||||
|
Mode => Mode_r,
|
||||||
|
Op => ALU_Op_r,
|
||||||
|
BusA => BusA_r,
|
||||||
|
BusB => BusB,
|
||||||
|
P_In => P,
|
||||||
|
P_Out => P_Out,
|
||||||
|
Q => ALU_Q
|
||||||
|
);
|
||||||
|
|
||||||
|
-- the 65xx design requires at least two clock cycles before
|
||||||
|
-- starting its reset sequence (according to datasheet)
|
||||||
|
process (Res_n, Clk)
|
||||||
|
begin
|
||||||
|
if Res_n = '0' then
|
||||||
|
Res_n_i <= '0';
|
||||||
|
Res_n_d <= '0';
|
||||||
|
elsif Clk'event and Clk = '1' then
|
||||||
|
Res_n_i <= Res_n_d;
|
||||||
|
Res_n_d <= '1';
|
||||||
|
end if;
|
||||||
|
end process;
|
||||||
|
|
||||||
|
process (Res_n_i, Clk)
|
||||||
|
begin
|
||||||
|
if Res_n_i = '0' then
|
||||||
|
PC <= (others => '0'); -- Program Counter
|
||||||
|
IR <= "00000000";
|
||||||
|
S <= (others => '0'); -- Dummy
|
||||||
|
PBR <= (others => '0');
|
||||||
|
DBR <= (others => '0');
|
||||||
|
|
||||||
|
Mode_r <= (others => '0');
|
||||||
|
ALU_Op_r <= ALU_OP_BIT;
|
||||||
|
Write_Data_r <= Write_Data_DL;
|
||||||
|
Set_Addr_To_r <= Set_Addr_To_PBR;
|
||||||
|
|
||||||
|
WRn_i <= '1';
|
||||||
|
EF_i <= '1';
|
||||||
|
MF_i <= '1';
|
||||||
|
XF_i <= '1';
|
||||||
|
|
||||||
|
elsif Clk'event and Clk = '1' then
|
||||||
|
if (Enable = '1') then
|
||||||
|
if (really_rdy = '1') then
|
||||||
|
WRn_i <= not Write or RstCycle;
|
||||||
|
|
||||||
|
PBR <= (others => '1'); -- Dummy
|
||||||
|
DBR <= (others => '1'); -- Dummy
|
||||||
|
EF_i <= '0'; -- Dummy
|
||||||
|
MF_i <= '0'; -- Dummy
|
||||||
|
XF_i <= '0'; -- Dummy
|
||||||
|
|
||||||
|
if MCycle = "000" then
|
||||||
|
Mode_r <= Mode;
|
||||||
|
|
||||||
|
if IRQCycle = '0' and NMICycle = '0' then
|
||||||
|
PC <= PC + 1;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if IRQCycle = '1' or NMICycle = '1' then
|
||||||
|
IR <= "00000000";
|
||||||
|
else
|
||||||
|
IR <= DI;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if LDS = '1' then -- LAS won't work properly if not limited to machine cycle 0
|
||||||
|
S(7 downto 0) <= unsigned(ALU_Q);
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
ALU_Op_r <= ALU_Op;
|
||||||
|
Write_Data_r <= Write_Data;
|
||||||
|
if Break = '1' then
|
||||||
|
Set_Addr_To_r <= Set_Addr_To_PBR;
|
||||||
|
else
|
||||||
|
Set_Addr_To_r <= Set_Addr_To;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if Inc_S = '1' then
|
||||||
|
S <= S + 1;
|
||||||
|
end if;
|
||||||
|
if Dec_S = '1' and RstCycle = '0' then
|
||||||
|
S <= S - 1;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if IR = "00000000" and MCycle = "001" and IRQCycle = '0' and NMICycle = '0' then
|
||||||
|
PC <= PC + 1;
|
||||||
|
end if;
|
||||||
|
--
|
||||||
|
-- jump control logic
|
||||||
|
--
|
||||||
|
case Jump is
|
||||||
|
when "01" =>
|
||||||
|
PC <= PC + 1;
|
||||||
|
when "10" =>
|
||||||
|
PC <= unsigned(DI & DL);
|
||||||
|
when "11" =>
|
||||||
|
if PCAdder(8) = '1' then
|
||||||
|
if DL(7) = '0' then
|
||||||
|
PC(15 downto 8) <= PC(15 downto 8) + 1;
|
||||||
|
else
|
||||||
|
PC(15 downto 8) <= PC(15 downto 8) - 1;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
PC(7 downto 0) <= PCAdder(7 downto 0);
|
||||||
|
when others => null;
|
||||||
|
end case;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
end process;
|
||||||
|
|
||||||
|
PCAdder <= resize(PC(7 downto 0),9) + resize(unsigned(DL(7) & DL),9) when PCAdd = '1'
|
||||||
|
else "0" & PC(7 downto 0);
|
||||||
|
|
||||||
|
process (Res_n_i, Clk)
|
||||||
|
variable tmpP:std_logic_vector(7 downto 0);--Lets try to handle loading P at mcycle=0 and set/clk flags at same cycle
|
||||||
|
begin
|
||||||
|
if Res_n_i = '0' then
|
||||||
|
P <= x"00"; -- ensure we have nothing set on reset
|
||||||
|
elsif Clk'event and Clk = '1' then
|
||||||
|
tmpP:=P;
|
||||||
|
if (Enable = '1') then
|
||||||
|
if (really_rdy = '1') then
|
||||||
|
if MCycle = "000" then
|
||||||
|
if LDA = '1' then
|
||||||
|
ABC(7 downto 0) <= ALU_Q;
|
||||||
|
end if;
|
||||||
|
if LDX = '1' then
|
||||||
|
X(7 downto 0) <= ALU_Q;
|
||||||
|
end if;
|
||||||
|
if LDY = '1' then
|
||||||
|
Y(7 downto 0) <= ALU_Q;
|
||||||
|
end if;
|
||||||
|
if (LDA or LDX or LDY) = '1' then
|
||||||
|
tmpP:=P_Out;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
if SaveP = '1' then
|
||||||
|
tmpP:=P_Out;
|
||||||
|
end if;
|
||||||
|
if LDP = '1' then
|
||||||
|
tmpP:=ALU_Q;
|
||||||
|
end if;
|
||||||
|
if IR(4 downto 0) = "11000" then
|
||||||
|
case IR(7 downto 5) is
|
||||||
|
when "000" =>--0x18(clc)
|
||||||
|
tmpP(Flag_C) := '0';
|
||||||
|
when "001" =>--0x38(sec)
|
||||||
|
tmpP(Flag_C) := '1';
|
||||||
|
when "010" =>--0x58(cli)
|
||||||
|
tmpP(Flag_I) := '0';
|
||||||
|
when "011" =>--0x78(sei)
|
||||||
|
tmpP(Flag_I) := '1';
|
||||||
|
when "101" =>--0xb8(clv)
|
||||||
|
tmpP(Flag_V) := '0';
|
||||||
|
when "110" =>--0xd8(cld)
|
||||||
|
tmpP(Flag_D) := '0';
|
||||||
|
when "111" =>--0xf8(sed)
|
||||||
|
tmpP(Flag_D) := '1';
|
||||||
|
when others =>
|
||||||
|
end case;
|
||||||
|
end if;
|
||||||
|
tmpP(Flag_B) := '1';
|
||||||
|
if IR = "00000000" and MCycle = "100" and RstCycle = '0' then
|
||||||
|
--This should happen after P has been pushed to stack
|
||||||
|
tmpP(Flag_I) := '1';
|
||||||
|
end if;
|
||||||
|
if RstCycle = '1' then
|
||||||
|
tmpP(Flag_I) := '1';
|
||||||
|
tmpP(Flag_D) := '0';
|
||||||
|
end if;
|
||||||
|
tmpP(Flag_1) := '1';
|
||||||
|
|
||||||
|
P<=tmpP;--new way
|
||||||
|
|
||||||
|
if IR(4 downto 0)/="10000" or Jump/="01" then -- delay interrupts during branches (checked with Lorenz test and real 6510), not best way yet, though - but works...
|
||||||
|
IRQ_n_o <= IRQ_n;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
-- detect nmi even if not rdy
|
||||||
|
if IR(4 downto 0)/="10000" or Jump/="01" then -- delay interrupts during branches (checked with Lorenz test and real 6510) not best way yet, though - but works...
|
||||||
|
NMI_n_o <= NMI_n;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
-- act immediately on SO pin change
|
||||||
|
-- The signal is sampled on the trailing edge of phi1 and must be externally synchronized (from datasheet)
|
||||||
|
SO_n_o <= SO_n;
|
||||||
|
if SO_n_o = '1' and SO_n = '0' then
|
||||||
|
P(Flag_V) <= '1';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
end if;
|
||||||
|
end process;
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- Buses
|
||||||
|
--
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
process (Res_n_i, Clk)
|
||||||
|
begin
|
||||||
|
if Res_n_i = '0' then
|
||||||
|
BusA_r <= (others => '0');
|
||||||
|
BusB <= (others => '0');
|
||||||
|
BusB_r <= (others => '0');
|
||||||
|
AD <= (others => '0');
|
||||||
|
BAL <= (others => '0');
|
||||||
|
BAH <= (others => '0');
|
||||||
|
DL <= (others => '0');
|
||||||
|
elsif Clk'event and Clk = '1' then
|
||||||
|
if (Enable = '1') then
|
||||||
|
if (really_rdy = '1') then
|
||||||
|
NMI_entered <= '0';
|
||||||
|
BusA_r <= BusA;
|
||||||
|
BusB <= DI;
|
||||||
|
|
||||||
|
-- not really nice, but no better way found yet !
|
||||||
|
if Set_Addr_To_r = Set_Addr_To_PBR or Set_Addr_To_r = Set_Addr_To_ZPG then
|
||||||
|
BusB_r <= std_logic_vector(unsigned(DI(7 downto 0)) + 1); -- required for SHA
|
||||||
|
end if;
|
||||||
|
|
||||||
|
case BAAdd is
|
||||||
|
when "01" =>
|
||||||
|
-- BA Inc
|
||||||
|
AD <= std_logic_vector(unsigned(AD) + 1);
|
||||||
|
BAL <= std_logic_vector(unsigned(BAL) + 1);
|
||||||
|
when "10" =>
|
||||||
|
-- BA Add
|
||||||
|
BAL <= std_logic_vector(resize(unsigned(BAL(7 downto 0)),9) + resize(unsigned(BusA),9));
|
||||||
|
when "11" =>
|
||||||
|
-- BA Adj
|
||||||
|
if BAL(8) = '1' then
|
||||||
|
BAH <= std_logic_vector(unsigned(BAH) + 1);
|
||||||
|
end if;
|
||||||
|
when others =>
|
||||||
|
end case;
|
||||||
|
|
||||||
|
-- modified to use Y register as well
|
||||||
|
if ADAdd = '1' then
|
||||||
|
if (AddY = '1') then
|
||||||
|
AD <= std_logic_vector(unsigned(AD) + unsigned(Y(7 downto 0)));
|
||||||
|
else
|
||||||
|
AD <= std_logic_vector(unsigned(AD) + unsigned(X(7 downto 0)));
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if IR = "00000000" then
|
||||||
|
BAL <= (others => '1');
|
||||||
|
BAH <= (others => '1');
|
||||||
|
if RstCycle = '1' then
|
||||||
|
BAL(2 downto 0) <= "100";
|
||||||
|
elsif NMICycle = '1' or (NMIAct = '1' and MCycle="100") or NMI_entered='1' then
|
||||||
|
BAL(2 downto 0) <= "010";
|
||||||
|
if MCycle="100" then
|
||||||
|
NMI_entered <= '1';
|
||||||
|
end if;
|
||||||
|
else
|
||||||
|
BAL(2 downto 0) <= "110";
|
||||||
|
end if;
|
||||||
|
if Set_addr_To_r = Set_Addr_To_BA then
|
||||||
|
BAL(0) <= '1';
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if LDDI = '1' then
|
||||||
|
DL <= DI;
|
||||||
|
end if;
|
||||||
|
if LDALU = '1' then
|
||||||
|
DL <= ALU_Q;
|
||||||
|
end if;
|
||||||
|
if LDAD = '1' then
|
||||||
|
AD <= DI;
|
||||||
|
end if;
|
||||||
|
if LDBAL = '1' then
|
||||||
|
BAL(7 downto 0) <= DI;
|
||||||
|
end if;
|
||||||
|
if LDBAH = '1' then
|
||||||
|
BAH <= DI;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
end process;
|
||||||
|
|
||||||
|
Break <= (BreakAtNA and not BAL(8)) or (PCAdd and not PCAdder(8));
|
||||||
|
|
||||||
|
with Set_BusA_To select
|
||||||
|
BusA <=
|
||||||
|
DI when Set_BusA_To_DI,
|
||||||
|
ABC(7 downto 0) when Set_BusA_To_ABC,
|
||||||
|
X(7 downto 0) when Set_BusA_To_X,
|
||||||
|
Y(7 downto 0) when Set_BusA_To_Y,
|
||||||
|
std_logic_vector(S(7 downto 0)) when Set_BusA_To_S,
|
||||||
|
P when Set_BusA_To_P,
|
||||||
|
ABC(7 downto 0) and DI when Set_BusA_To_DA,
|
||||||
|
(ABC(7 downto 0) or x"ee") and DI when Set_BusA_To_DAO,--ee for OAL instruction. constant may be different on other platforms.TODO:Move to generics
|
||||||
|
(ABC(7 downto 0) or x"ee") and DI and X(7 downto 0) when Set_BusA_To_DAX,--XAA, ee for OAL instruction. constant may be different on other platforms.TODO:Move to generics
|
||||||
|
ABC(7 downto 0) and X(7 downto 0) when Set_BusA_To_AAX,--SAX, SHA
|
||||||
|
(others => '-') when Set_BusA_To_DONTCARE;--Can probably remove this
|
||||||
|
|
||||||
|
with Set_Addr_To_r select
|
||||||
|
A <=
|
||||||
|
"0000000000000001" & std_logic_vector(S(7 downto 0)) when Set_Addr_To_SP,
|
||||||
|
DBR & "00000000" & AD when Set_Addr_To_ZPG,
|
||||||
|
"00000000" & BAH & BAL(7 downto 0) when Set_Addr_To_BA,
|
||||||
|
PBR & std_logic_vector(PC(15 downto 8)) & std_logic_vector(PCAdder(7 downto 0)) when Set_Addr_To_PBR;
|
||||||
|
|
||||||
|
-- This is the P that gets pushed on stack with correct B flag. I'm not sure if NMI also clears B, but I guess it does.
|
||||||
|
PwithB<=(P and x"ef") when (IRQCycle='1' or NMICycle='1') else P;
|
||||||
|
|
||||||
|
with Write_Data_r select
|
||||||
|
DO <=
|
||||||
|
DL when Write_Data_DL,
|
||||||
|
ABC(7 downto 0) when Write_Data_ABC,
|
||||||
|
X(7 downto 0) when Write_Data_X,
|
||||||
|
Y(7 downto 0) when Write_Data_Y,
|
||||||
|
std_logic_vector(S(7 downto 0)) when Write_Data_S,
|
||||||
|
PwithB when Write_Data_P,
|
||||||
|
std_logic_vector(PC(7 downto 0)) when Write_Data_PCL,
|
||||||
|
std_logic_vector(PC(15 downto 8)) when Write_Data_PCH,
|
||||||
|
ABC(7 downto 0) and X(7 downto 0) when Write_Data_AX,
|
||||||
|
ABC(7 downto 0) and X(7 downto 0) and BusB_r(7 downto 0) when Write_Data_AXB, -- no better way found yet...
|
||||||
|
X(7 downto 0) and BusB_r(7 downto 0) when Write_Data_XB, -- no better way found yet...
|
||||||
|
Y(7 downto 0) and BusB_r(7 downto 0) when Write_Data_YB, -- no better way found yet...
|
||||||
|
(others=>'-') when Write_Data_DONTCARE;--Can probably remove this
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- Main state machine
|
||||||
|
--
|
||||||
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
process (Res_n_i, Clk)
|
||||||
|
begin
|
||||||
|
if Res_n_i = '0' then
|
||||||
|
MCycle <= "001";
|
||||||
|
RstCycle <= '1';
|
||||||
|
IRQCycle <= '0';
|
||||||
|
NMICycle <= '0';
|
||||||
|
NMIAct <= '0';
|
||||||
|
elsif Clk'event and Clk = '1' then
|
||||||
|
if (Enable = '1') then
|
||||||
|
if (really_rdy = '1') then
|
||||||
|
if MCycle = LCycle or Break = '1' then
|
||||||
|
MCycle <= "000";
|
||||||
|
RstCycle <= '0';
|
||||||
|
IRQCycle <= '0';
|
||||||
|
NMICycle <= '0';
|
||||||
|
if NMIAct = '1' and IR/=x"00" then -- delay NMI further if we just executed a BRK
|
||||||
|
NMICycle <= '1';
|
||||||
|
NMIAct <= '0'; -- reset NMI edge detector if we start processing the NMI
|
||||||
|
elsif IRQ_n_o = '0' and P(Flag_I) = '0' then
|
||||||
|
IRQCycle <= '1';
|
||||||
|
end if;
|
||||||
|
else
|
||||||
|
MCycle <= std_logic_vector(unsigned(MCycle) + 1);
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
--detect NMI even if not rdy
|
||||||
|
if NMI_n_o = '1' and (NMI_n = '0' and (IR(4 downto 0)/="10000" or Jump/="01")) then -- branches have influence on NMI start (not best way yet, though - but works...)
|
||||||
|
NMIAct <= '1';
|
||||||
|
end if;
|
||||||
|
-- we entered NMI during BRK instruction
|
||||||
|
if NMI_entered='1' then
|
||||||
|
NMIAct <= '0';
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
end process;
|
||||||
|
|
||||||
|
end;
|
||||||
293
common/CPU/T65/T65_ALU.vhd
Normal file
293
common/CPU/T65/T65_ALU.vhd
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
-- ****
|
||||||
|
-- T65(b) core. In an effort to merge and maintain bug fixes ....
|
||||||
|
--
|
||||||
|
-- See list of changes in T65 top file (T65.vhd)...
|
||||||
|
--
|
||||||
|
-- ****
|
||||||
|
-- 65xx compatible microprocessor core
|
||||||
|
--
|
||||||
|
-- FPGAARCADE SVN: $Id: T65_ALU.vhd 1234 2015-02-28 20:14:50Z wolfgang.scherr $
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2002...2015
|
||||||
|
-- Daniel Wallner (jesus <at> opencores <dot> org)
|
||||||
|
-- Mike Johnson (mikej <at> fpgaarcade <dot> com)
|
||||||
|
-- Wolfgang Scherr (WoS <at> pin4 <dot> at>
|
||||||
|
-- Morten Leikvoll ()
|
||||||
|
--
|
||||||
|
-- All rights reserved
|
||||||
|
--
|
||||||
|
-- Redistribution and use in source and synthezised forms, with or without
|
||||||
|
-- modification, are permitted provided that the following conditions are met:
|
||||||
|
--
|
||||||
|
-- Redistributions of source code must retain the above copyright notice,
|
||||||
|
-- this list of conditions and the following disclaimer.
|
||||||
|
--
|
||||||
|
-- Redistributions in synthesized form must reproduce the above copyright
|
||||||
|
-- notice, this list of conditions and the following disclaimer in the
|
||||||
|
-- documentation and/or other materials provided with the distribution.
|
||||||
|
--
|
||||||
|
-- Neither the name of the author nor the names of other contributors may
|
||||||
|
-- be used to endorse or promote products derived from this software without
|
||||||
|
-- specific prior written permission.
|
||||||
|
--
|
||||||
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
||||||
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
--
|
||||||
|
-- Please report bugs to the author(s), but before you do so, please
|
||||||
|
-- make sure that this is not a derivative work and that
|
||||||
|
-- you have the latest version of this file.
|
||||||
|
--
|
||||||
|
-- Limitations :
|
||||||
|
-- See in T65 top file (T65.vhd)...
|
||||||
|
|
||||||
|
library IEEE;
|
||||||
|
use IEEE.std_logic_1164.all;
|
||||||
|
use IEEE.numeric_std.all;
|
||||||
|
use work.T65_Pack.all;
|
||||||
|
|
||||||
|
entity T65_ALU is
|
||||||
|
port(
|
||||||
|
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65816
|
||||||
|
Op : in T_ALU_OP;
|
||||||
|
BusA : in std_logic_vector(7 downto 0);
|
||||||
|
BusB : in std_logic_vector(7 downto 0);
|
||||||
|
P_In : in std_logic_vector(7 downto 0);
|
||||||
|
P_Out : out std_logic_vector(7 downto 0);
|
||||||
|
Q : out std_logic_vector(7 downto 0)
|
||||||
|
);
|
||||||
|
end T65_ALU;
|
||||||
|
|
||||||
|
architecture rtl of T65_ALU is
|
||||||
|
|
||||||
|
-- AddSub variables (temporary signals)
|
||||||
|
signal ADC_Z : std_logic;
|
||||||
|
signal ADC_C : std_logic;
|
||||||
|
signal ADC_V : std_logic;
|
||||||
|
signal ADC_N : std_logic;
|
||||||
|
signal ADC_Q : std_logic_vector(7 downto 0);
|
||||||
|
signal SBC_Z : std_logic;
|
||||||
|
signal SBC_C : std_logic;
|
||||||
|
signal SBC_V : std_logic;
|
||||||
|
signal SBC_N : std_logic;
|
||||||
|
signal SBC_Q : std_logic_vector(7 downto 0);
|
||||||
|
signal SBX_Q : std_logic_vector(7 downto 0);
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
process (P_In, BusA, BusB)
|
||||||
|
variable AL : unsigned(6 downto 0);
|
||||||
|
variable AH : unsigned(6 downto 0);
|
||||||
|
variable C : std_logic;
|
||||||
|
begin
|
||||||
|
AL := resize(unsigned(BusA(3 downto 0) & P_In(Flag_C)), 7) + resize(unsigned(BusB(3 downto 0) & "1"), 7);
|
||||||
|
AH := resize(unsigned(BusA(7 downto 4) & AL(5)), 7) + resize(unsigned(BusB(7 downto 4) & "1"), 7);
|
||||||
|
|
||||||
|
-- pragma translate_off
|
||||||
|
if is_x(std_logic_vector(AL)) then AL := "0000000"; end if;
|
||||||
|
if is_x(std_logic_vector(AH)) then AH := "0000000"; end if;
|
||||||
|
-- pragma translate_on
|
||||||
|
|
||||||
|
if AL(4 downto 1) = 0 and AH(4 downto 1) = 0 then
|
||||||
|
ADC_Z <= '1';
|
||||||
|
else
|
||||||
|
ADC_Z <= '0';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
if AL(5 downto 1) > 9 and P_In(Flag_D) = '1' then
|
||||||
|
AL(6 downto 1) := AL(6 downto 1) + 6;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
C := AL(6) or AL(5);
|
||||||
|
AH := resize(unsigned(BusA(7 downto 4) & C), 7) + resize(unsigned(BusB(7 downto 4) & "1"), 7);
|
||||||
|
|
||||||
|
ADC_N <= AH(4);
|
||||||
|
ADC_V <= (AH(4) xor BusA(7)) and not (BusA(7) xor BusB(7));
|
||||||
|
|
||||||
|
-- pragma translate_off
|
||||||
|
if is_x(std_logic_vector(AH)) then AH := "0000000"; end if;
|
||||||
|
-- pragma translate_on
|
||||||
|
|
||||||
|
if AH(5 downto 1) > 9 and P_In(Flag_D) = '1' then
|
||||||
|
AH(6 downto 1) := AH(6 downto 1) + 6;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
ADC_C <= AH(6) or AH(5);
|
||||||
|
|
||||||
|
ADC_Q <= std_logic_vector(AH(4 downto 1) & AL(4 downto 1));
|
||||||
|
end process;
|
||||||
|
|
||||||
|
process (Op, P_In, BusA, BusB)
|
||||||
|
variable AL : unsigned(6 downto 0);
|
||||||
|
variable AH : unsigned(5 downto 0);
|
||||||
|
variable C : std_logic;
|
||||||
|
variable CT : std_logic;
|
||||||
|
begin
|
||||||
|
CT:='0';
|
||||||
|
if( Op=ALU_OP_AND or --"0001" These OpCodes used to have LSB set
|
||||||
|
Op=ALU_OP_ADC or --"0011"
|
||||||
|
Op=ALU_OP_EQ2 or --"0101"
|
||||||
|
Op=ALU_OP_SBC or --"0111"
|
||||||
|
Op=ALU_OP_ROL or --"1001"
|
||||||
|
Op=ALU_OP_ROR or --"1011"
|
||||||
|
-- Op=ALU_OP_EQ3 or --"1101"
|
||||||
|
Op=ALU_OP_INC --"1111"
|
||||||
|
) then
|
||||||
|
CT:='1';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
C := P_In(Flag_C) or not CT;--was: or not Op(0);
|
||||||
|
AL := resize(unsigned(BusA(3 downto 0) & C), 7) - resize(unsigned(BusB(3 downto 0) & "1"), 6);
|
||||||
|
AH := resize(unsigned(BusA(7 downto 4) & "0"), 6) - resize(unsigned(BusB(7 downto 4) & AL(5)), 6);
|
||||||
|
|
||||||
|
-- pragma translate_off
|
||||||
|
if is_x(std_logic_vector(AL)) then AL := "0000000"; end if;
|
||||||
|
if is_x(std_logic_vector(AH)) then AH := "000000"; end if;
|
||||||
|
-- pragma translate_on
|
||||||
|
|
||||||
|
if AL(4 downto 1) = 0 and AH(4 downto 1) = 0 then
|
||||||
|
SBC_Z <= '1';
|
||||||
|
else
|
||||||
|
SBC_Z <= '0';
|
||||||
|
end if;
|
||||||
|
|
||||||
|
SBC_C <= not AH(5);
|
||||||
|
SBC_V <= (AH(4) xor BusA(7)) and (BusA(7) xor BusB(7));
|
||||||
|
SBC_N <= AH(4);
|
||||||
|
|
||||||
|
SBX_Q <= std_logic_vector(AH(4 downto 1) & AL(4 downto 1));
|
||||||
|
|
||||||
|
if P_In(Flag_D) = '1' then
|
||||||
|
if AL(5) = '1' then
|
||||||
|
AL(5 downto 1) := AL(5 downto 1) - 6;
|
||||||
|
end if;
|
||||||
|
AH := resize(unsigned(BusA(7 downto 4) & "0"), 6) - resize(unsigned(BusB(7 downto 4) & AL(6)), 6);
|
||||||
|
if AH(5) = '1' then
|
||||||
|
AH(5 downto 1) := AH(5 downto 1) - 6;
|
||||||
|
end if;
|
||||||
|
end if;
|
||||||
|
|
||||||
|
SBC_Q <= std_logic_vector(AH(4 downto 1) & AL(4 downto 1));
|
||||||
|
end process;
|
||||||
|
|
||||||
|
process (Op, P_In, BusA, BusB,
|
||||||
|
ADC_Z, ADC_C, ADC_V, ADC_N, ADC_Q,
|
||||||
|
SBC_Z, SBC_C, SBC_V, SBC_N, SBC_Q,
|
||||||
|
SBX_Q)
|
||||||
|
variable Q_t : std_logic_vector(7 downto 0);
|
||||||
|
variable Q2_t : std_logic_vector(7 downto 0);
|
||||||
|
begin
|
||||||
|
-- ORA, AND, EOR, ADC, NOP, LD, CMP, SBC
|
||||||
|
-- ASL, ROL, LSR, ROR, BIT, LD, DEC, INC
|
||||||
|
P_Out <= P_In;
|
||||||
|
Q_t := BusA;
|
||||||
|
Q2_t := BusA;
|
||||||
|
case Op is
|
||||||
|
when ALU_OP_OR=>
|
||||||
|
Q_t := BusA or BusB;
|
||||||
|
when ALU_OP_AND=>
|
||||||
|
Q_t := BusA and BusB;
|
||||||
|
when ALU_OP_EOR=>
|
||||||
|
Q_t := BusA xor BusB;
|
||||||
|
when ALU_OP_ADC=>
|
||||||
|
P_Out(Flag_V) <= ADC_V;
|
||||||
|
P_Out(Flag_C) <= ADC_C;
|
||||||
|
Q_t := ADC_Q;
|
||||||
|
when ALU_OP_CMP=>
|
||||||
|
P_Out(Flag_C) <= SBC_C;
|
||||||
|
when ALU_OP_SAX=>
|
||||||
|
P_Out(Flag_C) <= SBC_C;
|
||||||
|
Q_t := SBX_Q; -- undoc: subtract (A & X) - (immediate)
|
||||||
|
when ALU_OP_SBC=>
|
||||||
|
P_Out(Flag_V) <= SBC_V;
|
||||||
|
P_Out(Flag_C) <= SBC_C;
|
||||||
|
Q_t := SBC_Q; -- undoc: subtract (A & X) - (immediate), then decimal correction
|
||||||
|
when ALU_OP_ASL=>
|
||||||
|
Q_t := BusA(6 downto 0) & "0";
|
||||||
|
P_Out(Flag_C) <= BusA(7);
|
||||||
|
when ALU_OP_ROL=>
|
||||||
|
Q_t := BusA(6 downto 0) & P_In(Flag_C);
|
||||||
|
P_Out(Flag_C) <= BusA(7);
|
||||||
|
when ALU_OP_LSR=>
|
||||||
|
Q_t := "0" & BusA(7 downto 1);
|
||||||
|
P_Out(Flag_C) <= BusA(0);
|
||||||
|
when ALU_OP_ROR=>
|
||||||
|
Q_t := P_In(Flag_C) & BusA(7 downto 1);
|
||||||
|
P_Out(Flag_C) <= BusA(0);
|
||||||
|
when ALU_OP_ARR=>
|
||||||
|
Q_t := P_In(Flag_C) & (BusA(7 downto 1) and BusB(7 downto 1));
|
||||||
|
P_Out(Flag_V) <= Q_t(5) xor Q_t(6);
|
||||||
|
Q2_t := Q_t;
|
||||||
|
if P_In(Flag_D)='1' then
|
||||||
|
if (BusA(3 downto 0) and BusB(3 downto 0)) > "0100" then
|
||||||
|
Q2_t(3 downto 0) := std_logic_vector(unsigned(Q_t(3 downto 0)) + x"6");
|
||||||
|
end if;
|
||||||
|
if (BusA(7 downto 4) and BusB(7 downto 4)) > "0100" then
|
||||||
|
Q2_t(7 downto 4) := std_logic_vector(unsigned(Q_t(7 downto 4)) + x"6");
|
||||||
|
P_Out(Flag_C) <= '1';
|
||||||
|
else
|
||||||
|
P_Out(Flag_C) <= '0';
|
||||||
|
end if;
|
||||||
|
else
|
||||||
|
P_Out(Flag_C) <= Q_t(6);
|
||||||
|
end if;
|
||||||
|
when ALU_OP_BIT=>
|
||||||
|
P_Out(Flag_V) <= BusB(6);
|
||||||
|
when ALU_OP_DEC=>
|
||||||
|
Q_t := std_logic_vector(unsigned(BusA) - 1);
|
||||||
|
when ALU_OP_INC=>
|
||||||
|
Q_t := std_logic_vector(unsigned(BusA) + 1);
|
||||||
|
when others =>
|
||||||
|
null;
|
||||||
|
--EQ1,EQ2,EQ3 passes BusA to Q_t and P_in to P_out
|
||||||
|
end case;
|
||||||
|
|
||||||
|
case Op is
|
||||||
|
when ALU_OP_ADC=>
|
||||||
|
P_Out(Flag_N) <= ADC_N;
|
||||||
|
P_Out(Flag_Z) <= ADC_Z;
|
||||||
|
when ALU_OP_CMP|ALU_OP_SBC|ALU_OP_SAX=>
|
||||||
|
P_Out(Flag_N) <= SBC_N;
|
||||||
|
P_Out(Flag_Z) <= SBC_Z;
|
||||||
|
when ALU_OP_EQ1=>--dont touch P
|
||||||
|
when ALU_OP_BIT=>
|
||||||
|
P_Out(Flag_N) <= BusB(7);
|
||||||
|
if (BusA and BusB) = "00000000" then
|
||||||
|
P_Out(Flag_Z) <= '1';
|
||||||
|
else
|
||||||
|
P_Out(Flag_Z) <= '0';
|
||||||
|
end if;
|
||||||
|
when ALU_OP_ANC=>
|
||||||
|
P_Out(Flag_N) <= Q_t(7);
|
||||||
|
P_Out(Flag_C) <= Q_t(7);
|
||||||
|
if Q_t = "00000000" then
|
||||||
|
P_Out(Flag_Z) <= '1';
|
||||||
|
else
|
||||||
|
P_Out(Flag_Z) <= '0';
|
||||||
|
end if;
|
||||||
|
when others =>
|
||||||
|
P_Out(Flag_N) <= Q_t(7);
|
||||||
|
if Q_t = "00000000" then
|
||||||
|
P_Out(Flag_Z) <= '1';
|
||||||
|
else
|
||||||
|
P_Out(Flag_Z) <= '0';
|
||||||
|
end if;
|
||||||
|
end case;
|
||||||
|
|
||||||
|
if Op=ALU_OP_ARR then
|
||||||
|
-- handled above in ARR code
|
||||||
|
Q <= Q2_t;
|
||||||
|
else
|
||||||
|
Q <= Q_t;
|
||||||
|
end if;
|
||||||
|
end process;
|
||||||
|
|
||||||
|
end;
|
||||||
1239
common/CPU/T65/T65_MCode.vhd
Normal file
1239
common/CPU/T65/T65_MCode.vhd
Normal file
File diff suppressed because it is too large
Load Diff
180
common/CPU/T65/T65_Pack.vhd
Normal file
180
common/CPU/T65/T65_Pack.vhd
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
-- ****
|
||||||
|
-- T65(b) core. In an effort to merge and maintain bug fixes ....
|
||||||
|
--
|
||||||
|
-- See list of changes in T65 top file (T65.vhd)...
|
||||||
|
--
|
||||||
|
-- ****
|
||||||
|
-- 65xx compatible microprocessor core
|
||||||
|
--
|
||||||
|
-- FPGAARCADE SVN: $Id: T65_Pack.vhd 1234 2015-02-28 20:14:50Z wolfgang.scherr $
|
||||||
|
--
|
||||||
|
-- Copyright (c) 2002...2015
|
||||||
|
-- Daniel Wallner (jesus <at> opencores <dot> org)
|
||||||
|
-- Mike Johnson (mikej <at> fpgaarcade <dot> com)
|
||||||
|
-- Wolfgang Scherr (WoS <at> pin4 <dot> at>
|
||||||
|
-- Morten Leikvoll ()
|
||||||
|
--
|
||||||
|
-- All rights reserved
|
||||||
|
--
|
||||||
|
-- Redistribution and use in source and synthezised forms, with or without
|
||||||
|
-- modification, are permitted provided that the following conditions are met:
|
||||||
|
--
|
||||||
|
-- Redistributions of source code must retain the above copyright notice,
|
||||||
|
-- this list of conditions and the following disclaimer.
|
||||||
|
--
|
||||||
|
-- Redistributions in synthesized form must reproduce the above copyright
|
||||||
|
-- notice, this list of conditions and the following disclaimer in the
|
||||||
|
-- documentation and/or other materials provided with the distribution.
|
||||||
|
--
|
||||||
|
-- Neither the name of the author nor the names of other contributors may
|
||||||
|
-- be used to endorse or promote products derived from this software without
|
||||||
|
-- specific prior written permission.
|
||||||
|
--
|
||||||
|
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
||||||
|
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||||
|
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
-- POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
--
|
||||||
|
-- Please report bugs to the author(s), but before you do so, please
|
||||||
|
-- make sure that this is not a derivative work and that
|
||||||
|
-- you have the latest version of this file.
|
||||||
|
--
|
||||||
|
-- Limitations :
|
||||||
|
-- See in T65 top file (T65.vhd)...
|
||||||
|
|
||||||
|
library IEEE;
|
||||||
|
use IEEE.std_logic_1164.all;
|
||||||
|
|
||||||
|
package T65_Pack is
|
||||||
|
|
||||||
|
constant Flag_C : integer := 0;
|
||||||
|
constant Flag_Z : integer := 1;
|
||||||
|
constant Flag_I : integer := 2;
|
||||||
|
constant Flag_D : integer := 3;
|
||||||
|
constant Flag_B : integer := 4;
|
||||||
|
constant Flag_1 : integer := 5;
|
||||||
|
constant Flag_V : integer := 6;
|
||||||
|
constant Flag_N : integer := 7;
|
||||||
|
|
||||||
|
subtype T_Lcycle is std_logic_vector(2 downto 0);
|
||||||
|
constant Cycle_sync :T_Lcycle:="000";
|
||||||
|
constant Cycle_1 :T_Lcycle:="001";
|
||||||
|
constant Cycle_2 :T_Lcycle:="010";
|
||||||
|
constant Cycle_3 :T_Lcycle:="011";
|
||||||
|
constant Cycle_4 :T_Lcycle:="100";
|
||||||
|
constant Cycle_5 :T_Lcycle:="101";
|
||||||
|
constant Cycle_6 :T_Lcycle:="110";
|
||||||
|
constant Cycle_7 :T_Lcycle:="111";
|
||||||
|
|
||||||
|
function CycleNext(c:T_Lcycle) return T_Lcycle;
|
||||||
|
|
||||||
|
type T_Set_BusA_To is
|
||||||
|
(
|
||||||
|
Set_BusA_To_DI,
|
||||||
|
Set_BusA_To_ABC,
|
||||||
|
Set_BusA_To_X,
|
||||||
|
Set_BusA_To_Y,
|
||||||
|
Set_BusA_To_S,
|
||||||
|
Set_BusA_To_P,
|
||||||
|
Set_BusA_To_DA,
|
||||||
|
Set_BusA_To_DAO,
|
||||||
|
Set_BusA_To_DAX,
|
||||||
|
Set_BusA_To_AAX,
|
||||||
|
Set_BusA_To_DONTCARE
|
||||||
|
);
|
||||||
|
|
||||||
|
type T_Set_Addr_To is
|
||||||
|
(
|
||||||
|
Set_Addr_To_PBR,
|
||||||
|
Set_Addr_To_SP,
|
||||||
|
Set_Addr_To_ZPG,
|
||||||
|
Set_Addr_To_BA
|
||||||
|
);
|
||||||
|
|
||||||
|
type T_Write_Data is
|
||||||
|
(
|
||||||
|
Write_Data_DL,
|
||||||
|
Write_Data_ABC,
|
||||||
|
Write_Data_X,
|
||||||
|
Write_Data_Y,
|
||||||
|
Write_Data_S,
|
||||||
|
Write_Data_P,
|
||||||
|
Write_Data_PCL,
|
||||||
|
Write_Data_PCH,
|
||||||
|
Write_Data_AX,
|
||||||
|
Write_Data_AXB,
|
||||||
|
Write_Data_XB,
|
||||||
|
Write_Data_YB,
|
||||||
|
Write_Data_DONTCARE
|
||||||
|
);
|
||||||
|
|
||||||
|
type T_ALU_OP is
|
||||||
|
(
|
||||||
|
ALU_OP_OR, --"0000"
|
||||||
|
ALU_OP_AND, --"0001"
|
||||||
|
ALU_OP_EOR, --"0010"
|
||||||
|
ALU_OP_ADC, --"0011"
|
||||||
|
ALU_OP_EQ1, --"0100" EQ1 does not change N,Z flags, EQ2/3 does.
|
||||||
|
ALU_OP_EQ2, --"0101" Not sure yet whats the difference between EQ2&3. They seem to do the same ALU op
|
||||||
|
ALU_OP_CMP, --"0110"
|
||||||
|
ALU_OP_SBC, --"0111"
|
||||||
|
ALU_OP_ASL, --"1000"
|
||||||
|
ALU_OP_ROL, --"1001"
|
||||||
|
ALU_OP_LSR, --"1010"
|
||||||
|
ALU_OP_ROR, --"1011"
|
||||||
|
ALU_OP_BIT, --"1100"
|
||||||
|
-- ALU_OP_EQ3, --"1101"
|
||||||
|
ALU_OP_DEC, --"1110"
|
||||||
|
ALU_OP_INC, --"1111"
|
||||||
|
ALU_OP_ARR,
|
||||||
|
ALU_OP_ANC,
|
||||||
|
ALU_OP_SAX,
|
||||||
|
ALU_OP_XAA
|
||||||
|
-- ALU_OP_UNDEF--"----"--may be replaced with any?
|
||||||
|
);
|
||||||
|
|
||||||
|
type T_t65_dbg is record
|
||||||
|
I : std_logic_vector(7 downto 0); -- instruction
|
||||||
|
A : std_logic_vector(7 downto 0); -- A reg
|
||||||
|
X : std_logic_vector(7 downto 0); -- X reg
|
||||||
|
Y : std_logic_vector(7 downto 0); -- Y reg
|
||||||
|
S : std_logic_vector(7 downto 0); -- stack pointer
|
||||||
|
P : std_logic_vector(7 downto 0); -- processor flags
|
||||||
|
end record;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
|
package body T65_Pack is
|
||||||
|
|
||||||
|
function CycleNext(c:T_Lcycle) return T_Lcycle is
|
||||||
|
begin
|
||||||
|
case(c) is
|
||||||
|
when Cycle_sync=>
|
||||||
|
return Cycle_1;
|
||||||
|
when Cycle_1=>
|
||||||
|
return Cycle_2;
|
||||||
|
when Cycle_2=>
|
||||||
|
return Cycle_3;
|
||||||
|
when Cycle_3=>
|
||||||
|
return Cycle_4;
|
||||||
|
when Cycle_4=>
|
||||||
|
return Cycle_5;
|
||||||
|
when Cycle_5=>
|
||||||
|
return Cycle_6;
|
||||||
|
when Cycle_6=>
|
||||||
|
return Cycle_7;
|
||||||
|
when Cycle_7=>
|
||||||
|
return Cycle_sync;
|
||||||
|
when others=>
|
||||||
|
return Cycle_sync;
|
||||||
|
end case;
|
||||||
|
end CycleNext;
|
||||||
|
|
||||||
|
end T65_Pack;
|
||||||
@@ -1,117 +0,0 @@
|
|||||||
-- ****
|
|
||||||
-- T65(b) core. In an effort to merge and maintain bug fixes ....
|
|
||||||
--
|
|
||||||
--
|
|
||||||
-- Ver 300 Bugfixes by ehenciak added
|
|
||||||
-- MikeJ March 2005
|
|
||||||
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
|
|
||||||
--
|
|
||||||
-- ****
|
|
||||||
--
|
|
||||||
-- 65xx compatible microprocessor core
|
|
||||||
--
|
|
||||||
-- Version : 0246
|
|
||||||
--
|
|
||||||
-- Copyright (c) 2002 Daniel Wallner (jesus@opencores.org)
|
|
||||||
--
|
|
||||||
-- All rights reserved
|
|
||||||
--
|
|
||||||
-- Redistribution and use in source and synthezised forms, with or without
|
|
||||||
-- modification, are permitted provided that the following conditions are met:
|
|
||||||
--
|
|
||||||
-- Redistributions of source code must retain the above copyright notice,
|
|
||||||
-- this list of conditions and the following disclaimer.
|
|
||||||
--
|
|
||||||
-- Redistributions in synthesized form must reproduce the above copyright
|
|
||||||
-- notice, this list of conditions and the following disclaimer in the
|
|
||||||
-- documentation and/or other materials provided with the distribution.
|
|
||||||
--
|
|
||||||
-- Neither the name of the author nor the names of other contributors may
|
|
||||||
-- be used to endorse or promote products derived from this software without
|
|
||||||
-- specific prior written permission.
|
|
||||||
--
|
|
||||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
|
||||||
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
--
|
|
||||||
-- Please report bugs to the author, but before you do so, please
|
|
||||||
-- make sure that this is not a derivative work and that
|
|
||||||
-- you have the latest version of this file.
|
|
||||||
--
|
|
||||||
-- The latest version of this file can be found at:
|
|
||||||
-- http://www.opencores.org/cvsweb.shtml/t65/
|
|
||||||
--
|
|
||||||
-- Limitations :
|
|
||||||
--
|
|
||||||
-- File history :
|
|
||||||
--
|
|
||||||
|
|
||||||
library IEEE;
|
|
||||||
use IEEE.std_logic_1164.all;
|
|
||||||
|
|
||||||
package pack_t65 is
|
|
||||||
|
|
||||||
constant Flag_C : integer := 0;
|
|
||||||
constant Flag_Z : integer := 1;
|
|
||||||
constant Flag_I : integer := 2;
|
|
||||||
constant Flag_D : integer := 3;
|
|
||||||
constant Flag_B : integer := 4;
|
|
||||||
constant Flag_1 : integer := 5;
|
|
||||||
constant Flag_V : integer := 6;
|
|
||||||
constant Flag_N : integer := 7;
|
|
||||||
|
|
||||||
component T65_MCode
|
|
||||||
port(
|
|
||||||
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65816
|
|
||||||
IR : in std_logic_vector(7 downto 0);
|
|
||||||
MCycle : in std_logic_vector(2 downto 0);
|
|
||||||
P : in std_logic_vector(7 downto 0);
|
|
||||||
LCycle : out std_logic_vector(2 downto 0);
|
|
||||||
ALU_Op : out std_logic_vector(3 downto 0);
|
|
||||||
Set_BusA_To : out std_logic_vector(2 downto 0); -- DI,A,X,Y,S,P
|
|
||||||
Set_Addr_To : out std_logic_vector(1 downto 0); -- PC Adder,S,AD,BA
|
|
||||||
Write_Data : out std_logic_vector(2 downto 0); -- DL,A,X,Y,S,P,PCL,PCH
|
|
||||||
Jump : out std_logic_vector(1 downto 0); -- PC,++,DIDL,Rel
|
|
||||||
BAAdd : out std_logic_vector(1 downto 0); -- None,DB Inc,BA Add,BA Adj
|
|
||||||
BreakAtNA : out std_logic;
|
|
||||||
ADAdd : out std_logic;
|
|
||||||
AddY : out std_logic;
|
|
||||||
PCAdd : out std_logic;
|
|
||||||
Inc_S : out std_logic;
|
|
||||||
Dec_S : out std_logic;
|
|
||||||
LDA : out std_logic;
|
|
||||||
LDP : out std_logic;
|
|
||||||
LDX : out std_logic;
|
|
||||||
LDY : out std_logic;
|
|
||||||
LDS : out std_logic;
|
|
||||||
LDDI : out std_logic;
|
|
||||||
LDALU : out std_logic;
|
|
||||||
LDAD : out std_logic;
|
|
||||||
LDBAL : out std_logic;
|
|
||||||
LDBAH : out std_logic;
|
|
||||||
SaveP : out std_logic;
|
|
||||||
Write : out std_logic
|
|
||||||
);
|
|
||||||
end component;
|
|
||||||
|
|
||||||
component T65_ALU
|
|
||||||
port(
|
|
||||||
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65C816
|
|
||||||
Op : in std_logic_vector(3 downto 0);
|
|
||||||
BusA : in std_logic_vector(7 downto 0);
|
|
||||||
BusB : in std_logic_vector(7 downto 0);
|
|
||||||
P_In : in std_logic_vector(7 downto 0);
|
|
||||||
P_Out : out std_logic_vector(7 downto 0);
|
|
||||||
Q : out std_logic_vector(7 downto 0)
|
|
||||||
);
|
|
||||||
end component;
|
|
||||||
|
|
||||||
end;
|
|
||||||
@@ -1,553 +0,0 @@
|
|||||||
-- ****
|
|
||||||
-- T65(b) core. In an effort to merge and maintain bug fixes ....
|
|
||||||
--
|
|
||||||
--
|
|
||||||
-- Ver 301 more merging
|
|
||||||
-- Ver 300 Bugfixes by ehenciak added, started tidyup *bust*
|
|
||||||
-- MikeJ March 2005
|
|
||||||
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
|
|
||||||
--
|
|
||||||
-- ****
|
|
||||||
--
|
|
||||||
-- 65xx compatible microprocessor core
|
|
||||||
--
|
|
||||||
-- Version : 0246
|
|
||||||
--
|
|
||||||
-- Copyright (c) 2002 Daniel Wallner (jesus@opencores.org)
|
|
||||||
--
|
|
||||||
-- All rights reserved
|
|
||||||
--
|
|
||||||
-- Redistribution and use in source and synthezised forms, with or without
|
|
||||||
-- modification, are permitted provided that the following conditions are met:
|
|
||||||
--
|
|
||||||
-- Redistributions of source code must retain the above copyright notice,
|
|
||||||
-- this list of conditions and the following disclaimer.
|
|
||||||
--
|
|
||||||
-- Redistributions in synthesized form must reproduce the above copyright
|
|
||||||
-- notice, this list of conditions and the following disclaimer in the
|
|
||||||
-- documentation and/or other materials provided with the distribution.
|
|
||||||
--
|
|
||||||
-- Neither the name of the author nor the names of other contributors may
|
|
||||||
-- be used to endorse or promote products derived from this software without
|
|
||||||
-- specific prior written permission.
|
|
||||||
--
|
|
||||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
|
||||||
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
--
|
|
||||||
-- Please report bugs to the author, but before you do so, please
|
|
||||||
-- make sure that this is not a derivative work and that
|
|
||||||
-- you have the latest version of this file.
|
|
||||||
--
|
|
||||||
-- The latest version of this file can be found at:
|
|
||||||
-- http://www.opencores.org/cvsweb.shtml/t65/
|
|
||||||
--
|
|
||||||
-- Limitations :
|
|
||||||
--
|
|
||||||
-- 65C02 and 65C816 modes are incomplete
|
|
||||||
-- Undocumented instructions are not supported
|
|
||||||
-- Some interface signals behaves incorrect
|
|
||||||
--
|
|
||||||
-- File history :
|
|
||||||
--
|
|
||||||
-- 0246 : First release
|
|
||||||
--
|
|
||||||
|
|
||||||
library IEEE;
|
|
||||||
use IEEE.std_logic_1164.all;
|
|
||||||
use IEEE.numeric_std.all;
|
|
||||||
library work;
|
|
||||||
use work.pack_t65.all;
|
|
||||||
|
|
||||||
-- ehenciak 2-23-2005 : Added the enable signal so that one doesn't have to use
|
|
||||||
-- the ready signal to limit the CPU.
|
|
||||||
entity T65 is
|
|
||||||
port(
|
|
||||||
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65C816
|
|
||||||
Res_n : in std_logic;
|
|
||||||
Enable : in std_logic;
|
|
||||||
Clk : in std_logic;
|
|
||||||
Rdy : in std_logic;
|
|
||||||
Abort_n : in std_logic;
|
|
||||||
IRQ_n : in std_logic;
|
|
||||||
NMI_n : in std_logic;
|
|
||||||
SO_n : in std_logic;
|
|
||||||
R_W_n : out std_logic;
|
|
||||||
Sync : out std_logic;
|
|
||||||
EF : out std_logic;
|
|
||||||
MF : out std_logic;
|
|
||||||
XF : out std_logic;
|
|
||||||
ML_n : out std_logic;
|
|
||||||
VP_n : out std_logic;
|
|
||||||
VDA : out std_logic;
|
|
||||||
VPA : out std_logic;
|
|
||||||
A : out std_logic_vector(23 downto 0);
|
|
||||||
DI : in std_logic_vector(7 downto 0);
|
|
||||||
DO : out std_logic_vector(7 downto 0)
|
|
||||||
);
|
|
||||||
end T65;
|
|
||||||
|
|
||||||
architecture rtl of T65 is
|
|
||||||
|
|
||||||
-- Registers
|
|
||||||
signal ABC, X, Y, D : std_logic_vector(15 downto 0);
|
|
||||||
signal P, AD, DL : std_logic_vector(7 downto 0) := x"00";
|
|
||||||
signal BAH : std_logic_vector(7 downto 0);
|
|
||||||
signal BAL : std_logic_vector(8 downto 0);
|
|
||||||
signal PBR : std_logic_vector(7 downto 0);
|
|
||||||
signal DBR : std_logic_vector(7 downto 0);
|
|
||||||
signal PC : unsigned(15 downto 0);
|
|
||||||
signal S : unsigned(15 downto 0);
|
|
||||||
signal EF_i : std_logic;
|
|
||||||
signal MF_i : std_logic;
|
|
||||||
signal XF_i : std_logic;
|
|
||||||
|
|
||||||
signal IR : std_logic_vector(7 downto 0);
|
|
||||||
signal MCycle : std_logic_vector(2 downto 0);
|
|
||||||
|
|
||||||
signal Mode_r : std_logic_vector(1 downto 0);
|
|
||||||
signal ALU_Op_r : std_logic_vector(3 downto 0);
|
|
||||||
signal Write_Data_r : std_logic_vector(2 downto 0);
|
|
||||||
signal Set_Addr_To_r : std_logic_vector(1 downto 0);
|
|
||||||
signal PCAdder : unsigned(8 downto 0);
|
|
||||||
|
|
||||||
signal RstCycle : std_logic;
|
|
||||||
signal IRQCycle : std_logic;
|
|
||||||
signal NMICycle : std_logic;
|
|
||||||
|
|
||||||
signal B_o : std_logic;
|
|
||||||
signal SO_n_o : std_logic;
|
|
||||||
signal IRQ_n_o : std_logic;
|
|
||||||
signal NMI_n_o : std_logic;
|
|
||||||
signal NMIAct : std_logic;
|
|
||||||
|
|
||||||
signal Break : std_logic;
|
|
||||||
|
|
||||||
-- ALU signals
|
|
||||||
signal BusA : std_logic_vector(7 downto 0);
|
|
||||||
signal BusA_r : std_logic_vector(7 downto 0);
|
|
||||||
signal BusB : std_logic_vector(7 downto 0);
|
|
||||||
signal ALU_Q : std_logic_vector(7 downto 0);
|
|
||||||
signal P_Out : std_logic_vector(7 downto 0);
|
|
||||||
|
|
||||||
-- Micro code outputs
|
|
||||||
signal LCycle : std_logic_vector(2 downto 0);
|
|
||||||
signal ALU_Op : std_logic_vector(3 downto 0);
|
|
||||||
signal Set_BusA_To : std_logic_vector(2 downto 0);
|
|
||||||
signal Set_Addr_To : std_logic_vector(1 downto 0);
|
|
||||||
signal Write_Data : std_logic_vector(2 downto 0);
|
|
||||||
signal Jump : std_logic_vector(1 downto 0);
|
|
||||||
signal BAAdd : std_logic_vector(1 downto 0);
|
|
||||||
signal BreakAtNA : std_logic;
|
|
||||||
signal ADAdd : std_logic;
|
|
||||||
signal AddY : std_logic;
|
|
||||||
signal PCAdd : std_logic;
|
|
||||||
signal Inc_S : std_logic;
|
|
||||||
signal Dec_S : std_logic;
|
|
||||||
signal LDA : std_logic;
|
|
||||||
signal LDP : std_logic;
|
|
||||||
signal LDX : std_logic;
|
|
||||||
signal LDY : std_logic;
|
|
||||||
signal LDS : std_logic;
|
|
||||||
signal LDDI : std_logic;
|
|
||||||
signal LDALU : std_logic;
|
|
||||||
signal LDAD : std_logic;
|
|
||||||
signal LDBAL : std_logic;
|
|
||||||
signal LDBAH : std_logic;
|
|
||||||
signal SaveP : std_logic;
|
|
||||||
signal Write : std_logic;
|
|
||||||
|
|
||||||
signal really_rdy : std_logic;
|
|
||||||
signal R_W_n_i : std_logic;
|
|
||||||
|
|
||||||
begin
|
|
||||||
-- ehenciak : gate Rdy with read/write to make an "OK, it's
|
|
||||||
-- really OK to stop the processor now if Rdy is
|
|
||||||
-- deasserted" signal
|
|
||||||
really_rdy <= Rdy or not(R_W_n_i);
|
|
||||||
|
|
||||||
-- ehenciak : Drive R_W_n_i off chip.
|
|
||||||
R_W_n <= R_W_n_i;
|
|
||||||
|
|
||||||
Sync <= '1' when MCycle = "000" else '0';
|
|
||||||
EF <= EF_i;
|
|
||||||
MF <= MF_i;
|
|
||||||
XF <= XF_i;
|
|
||||||
ML_n <= '0' when IR(7 downto 6) /= "10" and IR(2 downto 1) = "11" and MCycle(2 downto 1) /= "00" else '1';
|
|
||||||
VP_n <= '0' when IRQCycle = '1' and (MCycle = "101" or MCycle = "110") else '1';
|
|
||||||
VDA <= '1' when Set_Addr_To_r /= "000" else '0'; -- Incorrect !!!!!!!!!!!!
|
|
||||||
VPA <= '1' when Jump(1) = '0' else '0'; -- Incorrect !!!!!!!!!!!!
|
|
||||||
|
|
||||||
mcode : T65_MCode
|
|
||||||
port map(
|
|
||||||
Mode => Mode_r,
|
|
||||||
IR => IR,
|
|
||||||
MCycle => MCycle,
|
|
||||||
P => P,
|
|
||||||
LCycle => LCycle,
|
|
||||||
ALU_Op => ALU_Op,
|
|
||||||
Set_BusA_To => Set_BusA_To,
|
|
||||||
Set_Addr_To => Set_Addr_To,
|
|
||||||
Write_Data => Write_Data,
|
|
||||||
Jump => Jump,
|
|
||||||
BAAdd => BAAdd,
|
|
||||||
BreakAtNA => BreakAtNA,
|
|
||||||
ADAdd => ADAdd,
|
|
||||||
AddY => AddY,
|
|
||||||
PCAdd => PCAdd,
|
|
||||||
Inc_S => Inc_S,
|
|
||||||
Dec_S => Dec_S,
|
|
||||||
LDA => LDA,
|
|
||||||
LDP => LDP,
|
|
||||||
LDX => LDX,
|
|
||||||
LDY => LDY,
|
|
||||||
LDS => LDS,
|
|
||||||
LDDI => LDDI,
|
|
||||||
LDALU => LDALU,
|
|
||||||
LDAD => LDAD,
|
|
||||||
LDBAL => LDBAL,
|
|
||||||
LDBAH => LDBAH,
|
|
||||||
SaveP => SaveP,
|
|
||||||
Write => Write
|
|
||||||
);
|
|
||||||
|
|
||||||
alu : T65_ALU
|
|
||||||
port map(
|
|
||||||
Mode => Mode_r,
|
|
||||||
Op => ALU_Op_r,
|
|
||||||
BusA => BusA_r,
|
|
||||||
BusB => BusB,
|
|
||||||
P_In => P,
|
|
||||||
P_Out => P_Out,
|
|
||||||
Q => ALU_Q
|
|
||||||
);
|
|
||||||
|
|
||||||
process (Res_n, Clk)
|
|
||||||
begin
|
|
||||||
if Res_n = '0' then
|
|
||||||
PC <= (others => '0'); -- Program Counter
|
|
||||||
IR <= "00000000";
|
|
||||||
S <= (others => '0'); -- Dummy !!!!!!!!!!!!!!!!!!!!!
|
|
||||||
D <= (others => '0');
|
|
||||||
PBR <= (others => '0');
|
|
||||||
DBR <= (others => '0');
|
|
||||||
|
|
||||||
Mode_r <= (others => '0');
|
|
||||||
ALU_Op_r <= "1100";
|
|
||||||
Write_Data_r <= "000";
|
|
||||||
Set_Addr_To_r <= "00";
|
|
||||||
|
|
||||||
R_W_n_i <= '1';
|
|
||||||
EF_i <= '1';
|
|
||||||
MF_i <= '1';
|
|
||||||
XF_i <= '1';
|
|
||||||
|
|
||||||
elsif Clk'event and Clk = '1' then
|
|
||||||
if (Enable = '1') then
|
|
||||||
if (really_rdy = '1') then
|
|
||||||
R_W_n_i <= not Write or RstCycle;
|
|
||||||
|
|
||||||
D <= (others => '1'); -- Dummy
|
|
||||||
PBR <= (others => '1'); -- Dummy
|
|
||||||
DBR <= (others => '1'); -- Dummy
|
|
||||||
EF_i <= '0'; -- Dummy
|
|
||||||
MF_i <= '0'; -- Dummy
|
|
||||||
XF_i <= '0'; -- Dummy
|
|
||||||
|
|
||||||
if MCycle = "000" then
|
|
||||||
Mode_r <= Mode;
|
|
||||||
|
|
||||||
if IRQCycle = '0' and NMICycle = '0' then
|
|
||||||
PC <= PC + 1;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if IRQCycle = '1' or NMICycle = '1' then
|
|
||||||
IR <= "00000000";
|
|
||||||
else
|
|
||||||
IR <= DI;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
ALU_Op_r <= ALU_Op;
|
|
||||||
Write_Data_r <= Write_Data;
|
|
||||||
if Break = '1' then
|
|
||||||
Set_Addr_To_r <= "00";
|
|
||||||
else
|
|
||||||
Set_Addr_To_r <= Set_Addr_To;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if Inc_S = '1' then
|
|
||||||
S <= S + 1;
|
|
||||||
end if;
|
|
||||||
if Dec_S = '1' and RstCycle = '0' then
|
|
||||||
S <= S - 1;
|
|
||||||
end if;
|
|
||||||
if LDS = '1' then
|
|
||||||
S(7 downto 0) <= unsigned(ALU_Q);
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if IR = "00000000" and MCycle = "001" and IRQCycle = '0' and NMICycle = '0' then
|
|
||||||
PC <= PC + 1;
|
|
||||||
end if;
|
|
||||||
--
|
|
||||||
-- jump control logic
|
|
||||||
--
|
|
||||||
case Jump is
|
|
||||||
when "01" =>
|
|
||||||
PC <= PC + 1;
|
|
||||||
|
|
||||||
when "10" =>
|
|
||||||
PC <= unsigned(DI & DL);
|
|
||||||
|
|
||||||
when "11" =>
|
|
||||||
if PCAdder(8) = '1' then
|
|
||||||
if DL(7) = '0' then
|
|
||||||
PC(15 downto 8) <= PC(15 downto 8) + 1;
|
|
||||||
else
|
|
||||||
PC(15 downto 8) <= PC(15 downto 8) - 1;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
PC(7 downto 0) <= PCAdder(7 downto 0);
|
|
||||||
|
|
||||||
when others => null;
|
|
||||||
end case;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
PCAdder <= resize(PC(7 downto 0),9) + resize(unsigned(DL(7) & DL),9) when PCAdd = '1'
|
|
||||||
else "0" & PC(7 downto 0);
|
|
||||||
|
|
||||||
process (Clk)
|
|
||||||
begin
|
|
||||||
if Clk'event and Clk = '1' then
|
|
||||||
if (Enable = '1') then
|
|
||||||
if (really_rdy = '1') then
|
|
||||||
if MCycle = "000" then
|
|
||||||
if LDA = '1' then
|
|
||||||
-- assert false report "Chargement A" severity warning;
|
|
||||||
ABC(7 downto 0) <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if LDX = '1' then
|
|
||||||
X(7 downto 0) <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if LDY = '1' then
|
|
||||||
Y(7 downto 0) <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if (LDA or LDX or LDY) = '1' then
|
|
||||||
P <= P_Out;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
if SaveP = '1' then
|
|
||||||
P <= P_Out;
|
|
||||||
end if;
|
|
||||||
if LDP = '1' then
|
|
||||||
P <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if IR(4 downto 0) = "11000" then
|
|
||||||
case IR(7 downto 5) is
|
|
||||||
when "000" =>
|
|
||||||
P(Flag_C) <= '0';
|
|
||||||
when "001" =>
|
|
||||||
P(Flag_C) <= '1';
|
|
||||||
when "010" =>
|
|
||||||
P(Flag_I) <= '0';
|
|
||||||
when "011" =>
|
|
||||||
P(Flag_I) <= '1';
|
|
||||||
when "101" =>
|
|
||||||
P(Flag_V) <= '0';
|
|
||||||
when "110" =>
|
|
||||||
P(Flag_D) <= '0';
|
|
||||||
when "111" =>
|
|
||||||
P(Flag_D) <= '1';
|
|
||||||
when others =>
|
|
||||||
end case;
|
|
||||||
end if;
|
|
||||||
if IR = "00000000" and MCycle = "011" and RstCycle = '0' and NMICycle = '0' and IRQCycle = '0' then
|
|
||||||
P(Flag_B) <= '1';
|
|
||||||
end if;
|
|
||||||
if IR = "00000000" and MCycle = "100" and RstCycle = '0' and (NMICycle = '1' or IRQCycle = '1') then
|
|
||||||
P(Flag_I) <= '1';
|
|
||||||
P(Flag_B) <= B_o;
|
|
||||||
end if;
|
|
||||||
if SO_n_o = '1' and SO_n = '0' then
|
|
||||||
P(Flag_V) <= '1';
|
|
||||||
end if;
|
|
||||||
if RstCycle = '1' and Mode_r /= "00" then
|
|
||||||
P(Flag_1) <= '1';
|
|
||||||
P(Flag_D) <= '0';
|
|
||||||
P(Flag_I) <= '1';
|
|
||||||
end if;
|
|
||||||
P(Flag_1) <= '1';
|
|
||||||
|
|
||||||
B_o <= P(Flag_B);
|
|
||||||
SO_n_o <= SO_n;
|
|
||||||
IRQ_n_o <= IRQ_n;
|
|
||||||
NMI_n_o <= NMI_n;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
--
|
|
||||||
-- Buses
|
|
||||||
--
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
process (Res_n, Clk)
|
|
||||||
begin
|
|
||||||
if Res_n = '0' then
|
|
||||||
BusA_r <= (others => '0');
|
|
||||||
BusB <= (others => '0');
|
|
||||||
AD <= (others => '0');
|
|
||||||
BAL <= (others => '0');
|
|
||||||
BAH <= (others => '0');
|
|
||||||
DL <= (others => '0');
|
|
||||||
elsif Clk'event and Clk = '1' then
|
|
||||||
if (Enable = '1') then
|
|
||||||
if (Rdy = '1') then
|
|
||||||
BusA_r <= BusA;
|
|
||||||
BusB <= DI;
|
|
||||||
|
|
||||||
case BAAdd is
|
|
||||||
when "01" =>
|
|
||||||
-- BA Inc
|
|
||||||
AD <= std_logic_vector(unsigned(AD) + 1);
|
|
||||||
BAL <= std_logic_vector(unsigned(BAL) + 1);
|
|
||||||
when "10" =>
|
|
||||||
-- BA Add
|
|
||||||
BAL <= std_logic_vector(resize(unsigned(BAL(7 downto 0)),9) + resize(unsigned(BusA),9));
|
|
||||||
when "11" =>
|
|
||||||
-- BA Adj
|
|
||||||
if BAL(8) = '1' then
|
|
||||||
BAH <= std_logic_vector(unsigned(BAH) + 1);
|
|
||||||
end if;
|
|
||||||
when others =>
|
|
||||||
end case;
|
|
||||||
|
|
||||||
-- ehenciak : modified to use Y register as well (bugfix)
|
|
||||||
if ADAdd = '1' then
|
|
||||||
if (AddY = '1') then
|
|
||||||
AD <= std_logic_vector(unsigned(AD) + unsigned(Y(7 downto 0)));
|
|
||||||
else
|
|
||||||
AD <= std_logic_vector(unsigned(AD) + unsigned(X(7 downto 0)));
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if IR = "00000000" then
|
|
||||||
BAL <= (others => '1');
|
|
||||||
BAH <= (others => '1');
|
|
||||||
if RstCycle = '1' then
|
|
||||||
BAL(2 downto 0) <= "100";
|
|
||||||
elsif NMICycle = '1' then
|
|
||||||
BAL(2 downto 0) <= "010";
|
|
||||||
else
|
|
||||||
BAL(2 downto 0) <= "110";
|
|
||||||
end if;
|
|
||||||
if Set_addr_To_r = "11" then
|
|
||||||
BAL(0) <= '1';
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
|
|
||||||
if LDDI = '1' then
|
|
||||||
DL <= DI;
|
|
||||||
end if;
|
|
||||||
if LDALU = '1' then
|
|
||||||
DL <= ALU_Q;
|
|
||||||
end if;
|
|
||||||
if LDAD = '1' then
|
|
||||||
AD <= DI;
|
|
||||||
end if;
|
|
||||||
if LDBAL = '1' then
|
|
||||||
BAL(7 downto 0) <= DI;
|
|
||||||
end if;
|
|
||||||
if LDBAH = '1' then
|
|
||||||
BAH <= DI;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
Break <= (BreakAtNA and not BAL(8)) or (PCAdd and not PCAdder(8));
|
|
||||||
|
|
||||||
|
|
||||||
with Set_BusA_To select
|
|
||||||
BusA <= DI when "000",
|
|
||||||
ABC(7 downto 0) when "001",
|
|
||||||
X(7 downto 0) when "010",
|
|
||||||
Y(7 downto 0) when "011",
|
|
||||||
std_logic_vector(S(7 downto 0)) when "100",
|
|
||||||
P when "101",
|
|
||||||
(others => '-') when others;
|
|
||||||
|
|
||||||
with Set_Addr_To_r select
|
|
||||||
A <= "0000000000000001" & std_logic_vector(S(7 downto 0)) when "01",
|
|
||||||
DBR & "00000000" & AD when "10",
|
|
||||||
"00000000" & BAH & BAL(7 downto 0) when "11",
|
|
||||||
PBR & std_logic_vector(PC(15 downto 8)) & std_logic_vector(PCAdder(7 downto 0)) when others;
|
|
||||||
|
|
||||||
with Write_Data_r select
|
|
||||||
DO <= DL when "000",
|
|
||||||
ABC(7 downto 0) when "001",
|
|
||||||
X(7 downto 0) when "010",
|
|
||||||
Y(7 downto 0) when "011",
|
|
||||||
std_logic_vector(S(7 downto 0)) when "100",
|
|
||||||
P when "101",
|
|
||||||
std_logic_vector(PC(7 downto 0)) when "110",
|
|
||||||
std_logic_vector(PC(15 downto 8)) when others;
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------
|
|
||||||
--
|
|
||||||
-- Main state machine
|
|
||||||
--
|
|
||||||
-------------------------------------------------------------------------
|
|
||||||
|
|
||||||
process (Res_n, Clk)
|
|
||||||
begin
|
|
||||||
if Res_n = '0' then
|
|
||||||
MCycle <= "001";
|
|
||||||
RstCycle <= '1';
|
|
||||||
IRQCycle <= '0';
|
|
||||||
NMICycle <= '0';
|
|
||||||
NMIAct <= '0';
|
|
||||||
elsif Clk'event and Clk = '1' then
|
|
||||||
if (Enable = '1') then
|
|
||||||
if (really_rdy = '1') then
|
|
||||||
if MCycle = LCycle or Break = '1' then
|
|
||||||
MCycle <= "000";
|
|
||||||
RstCycle <= '0';
|
|
||||||
IRQCycle <= '0';
|
|
||||||
NMICycle <= '0';
|
|
||||||
if NMIAct = '1' then
|
|
||||||
NMICycle <= '1';
|
|
||||||
elsif IRQ_n_o = '0' and P(Flag_I) = '0' then
|
|
||||||
IRQCycle <= '1';
|
|
||||||
end if;
|
|
||||||
else
|
|
||||||
MCycle <= std_logic_vector(unsigned(MCycle) + 1);
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if NMICycle = '1' then
|
|
||||||
NMIAct <= '0';
|
|
||||||
end if;
|
|
||||||
if NMI_n_o = '1' and NMI_n = '0' then
|
|
||||||
NMIAct <= '1';
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
end;
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,261 +0,0 @@
|
|||||||
-- ****
|
|
||||||
-- T65(b) core. In an effort to merge and maintain bug fixes ....
|
|
||||||
--
|
|
||||||
--
|
|
||||||
-- Ver 300 Bugfixes by ehenciak added
|
|
||||||
-- MikeJ March 2005
|
|
||||||
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
|
|
||||||
--
|
|
||||||
-- ****
|
|
||||||
--
|
|
||||||
-- 6502 compatible microprocessor core
|
|
||||||
--
|
|
||||||
-- Version : 0245
|
|
||||||
--
|
|
||||||
-- Copyright (c) 2002 Daniel Wallner (jesus@opencores.org)
|
|
||||||
--
|
|
||||||
-- All rights reserved
|
|
||||||
--
|
|
||||||
-- Redistribution and use in source and synthezised forms, with or without
|
|
||||||
-- modification, are permitted provided that the following conditions are met:
|
|
||||||
--
|
|
||||||
-- Redistributions of source code must retain the above copyright notice,
|
|
||||||
-- this list of conditions and the following disclaimer.
|
|
||||||
--
|
|
||||||
-- Redistributions in synthesized form must reproduce the above copyright
|
|
||||||
-- notice, this list of conditions and the following disclaimer in the
|
|
||||||
-- documentation and/or other materials provided with the distribution.
|
|
||||||
--
|
|
||||||
-- Neither the name of the author nor the names of other contributors may
|
|
||||||
-- be used to endorse or promote products derived from this software without
|
|
||||||
-- specific prior written permission.
|
|
||||||
--
|
|
||||||
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
-- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
-- PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
|
|
||||||
-- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
-- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
-- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
-- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
-- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
-- POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
--
|
|
||||||
-- Please report bugs to the author, but before you do so, please
|
|
||||||
-- make sure that this is not a derivative work and that
|
|
||||||
-- you have the latest version of this file.
|
|
||||||
--
|
|
||||||
-- The latest version of this file can be found at:
|
|
||||||
-- http://www.opencores.org/cvsweb.shtml/t65/
|
|
||||||
--
|
|
||||||
-- Limitations :
|
|
||||||
--
|
|
||||||
-- File history :
|
|
||||||
--
|
|
||||||
-- 0245 : First version
|
|
||||||
--
|
|
||||||
|
|
||||||
library IEEE;
|
|
||||||
use IEEE.std_logic_1164.all;
|
|
||||||
use IEEE.numeric_std.all;
|
|
||||||
library work;
|
|
||||||
use work.pack_t65.all;
|
|
||||||
|
|
||||||
entity T65_ALU is
|
|
||||||
port(
|
|
||||||
Mode : in std_logic_vector(1 downto 0); -- "00" => 6502, "01" => 65C02, "10" => 65816
|
|
||||||
Op : in std_logic_vector(3 downto 0);
|
|
||||||
BusA : in std_logic_vector(7 downto 0);
|
|
||||||
BusB : in std_logic_vector(7 downto 0);
|
|
||||||
P_In : in std_logic_vector(7 downto 0);
|
|
||||||
P_Out : out std_logic_vector(7 downto 0);
|
|
||||||
Q : out std_logic_vector(7 downto 0)
|
|
||||||
);
|
|
||||||
end T65_ALU;
|
|
||||||
|
|
||||||
architecture rtl of T65_ALU is
|
|
||||||
|
|
||||||
-- AddSub variables (temporary signals)
|
|
||||||
signal ADC_Z : std_logic;
|
|
||||||
signal ADC_C : std_logic;
|
|
||||||
signal ADC_V : std_logic;
|
|
||||||
signal ADC_N : std_logic;
|
|
||||||
signal ADC_Q : std_logic_vector(7 downto 0);
|
|
||||||
signal SBC_Z : std_logic;
|
|
||||||
signal SBC_C : std_logic;
|
|
||||||
signal SBC_V : std_logic;
|
|
||||||
signal SBC_N : std_logic;
|
|
||||||
signal SBC_Q : std_logic_vector(7 downto 0);
|
|
||||||
|
|
||||||
begin
|
|
||||||
|
|
||||||
process (P_In, BusA, BusB)
|
|
||||||
variable AL : unsigned(6 downto 0);
|
|
||||||
variable AH : unsigned(6 downto 0);
|
|
||||||
variable C : std_logic;
|
|
||||||
begin
|
|
||||||
AL := resize(unsigned(BusA(3 downto 0) & P_In(Flag_C)), 7) + resize(unsigned(BusB(3 downto 0) & "1"), 7);
|
|
||||||
AH := resize(unsigned(BusA(7 downto 4) & AL(5)), 7) + resize(unsigned(BusB(7 downto 4) & "1"), 7);
|
|
||||||
|
|
||||||
-- pragma translate_off
|
|
||||||
if is_x(std_logic_vector(AL)) then AL := "0000000"; end if;
|
|
||||||
if is_x(std_logic_vector(AH)) then AH := "0000000"; end if;
|
|
||||||
-- pragma translate_on
|
|
||||||
|
|
||||||
if AL(4 downto 1) = 0 and AH(4 downto 1) = 0 then
|
|
||||||
ADC_Z <= '1';
|
|
||||||
else
|
|
||||||
ADC_Z <= '0';
|
|
||||||
end if;
|
|
||||||
|
|
||||||
if AL(5 downto 1) > 9 and P_In(Flag_D) = '1' then
|
|
||||||
AL(6 downto 1) := AL(6 downto 1) + 6;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
C := AL(6) or AL(5);
|
|
||||||
AH := resize(unsigned(BusA(7 downto 4) & C), 7) + resize(unsigned(BusB(7 downto 4) & "1"), 7);
|
|
||||||
|
|
||||||
ADC_N <= AH(4);
|
|
||||||
ADC_V <= (AH(4) xor BusA(7)) and not (BusA(7) xor BusB(7));
|
|
||||||
|
|
||||||
-- pragma translate_off
|
|
||||||
if is_x(std_logic_vector(AH)) then AH := "0000000"; end if;
|
|
||||||
-- pragma translate_on
|
|
||||||
|
|
||||||
if AH(5 downto 1) > 9 and P_In(Flag_D) = '1' then
|
|
||||||
AH(6 downto 1) := AH(6 downto 1) + 6;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
ADC_C <= AH(6) or AH(5);
|
|
||||||
|
|
||||||
ADC_Q <= std_logic_vector(AH(4 downto 1) & AL(4 downto 1));
|
|
||||||
end process;
|
|
||||||
|
|
||||||
process (Op, P_In, BusA, BusB)
|
|
||||||
variable AL : unsigned(6 downto 0);
|
|
||||||
variable AH : unsigned(5 downto 0);
|
|
||||||
variable C : std_logic;
|
|
||||||
begin
|
|
||||||
C := P_In(Flag_C) or not Op(0);
|
|
||||||
AL := resize(unsigned(BusA(3 downto 0) & C), 7) - resize(unsigned(BusB(3 downto 0) & "1"), 6);
|
|
||||||
AH := resize(unsigned(BusA(7 downto 4) & "0"), 6) - resize(unsigned(BusB(7 downto 4) & AL(5)), 6);
|
|
||||||
|
|
||||||
-- pragma translate_off
|
|
||||||
if is_x(std_logic_vector(AL)) then AL := "0000000"; end if;
|
|
||||||
if is_x(std_logic_vector(AH)) then AH := "000000"; end if;
|
|
||||||
-- pragma translate_on
|
|
||||||
|
|
||||||
if AL(4 downto 1) = 0 and AH(4 downto 1) = 0 then
|
|
||||||
SBC_Z <= '1';
|
|
||||||
else
|
|
||||||
SBC_Z <= '0';
|
|
||||||
end if;
|
|
||||||
|
|
||||||
SBC_C <= not AH(5);
|
|
||||||
SBC_V <= (AH(4) xor BusA(7)) and (BusA(7) xor BusB(7));
|
|
||||||
SBC_N <= AH(4);
|
|
||||||
|
|
||||||
if P_In(Flag_D) = '1' then
|
|
||||||
if AL(5) = '1' then
|
|
||||||
AL(5 downto 1) := AL(5 downto 1) - 6;
|
|
||||||
end if;
|
|
||||||
AH := resize(unsigned(BusA(7 downto 4) & "0"), 6) - resize(unsigned(BusB(7 downto 4) & AL(6)), 6);
|
|
||||||
if AH(5) = '1' then
|
|
||||||
AH(5 downto 1) := AH(5 downto 1) - 6;
|
|
||||||
end if;
|
|
||||||
end if;
|
|
||||||
|
|
||||||
SBC_Q <= std_logic_vector(AH(4 downto 1) & AL(4 downto 1));
|
|
||||||
end process;
|
|
||||||
|
|
||||||
process (Op, P_In, BusA, BusB,
|
|
||||||
ADC_Z, ADC_C, ADC_V, ADC_N, ADC_Q,
|
|
||||||
SBC_Z, SBC_C, SBC_V, SBC_N, SBC_Q)
|
|
||||||
variable Q_t : std_logic_vector(7 downto 0);
|
|
||||||
begin
|
|
||||||
-- ORA, AND, EOR, ADC, NOP, LD, CMP, SBC
|
|
||||||
-- ASL, ROL, LSR, ROR, BIT, LD, DEC, INC
|
|
||||||
P_Out <= P_In;
|
|
||||||
Q_t := BusA;
|
|
||||||
case Op(3 downto 0) is
|
|
||||||
when "0000" =>
|
|
||||||
-- ORA
|
|
||||||
Q_t := BusA or BusB;
|
|
||||||
when "0001" =>
|
|
||||||
-- AND
|
|
||||||
Q_t := BusA and BusB;
|
|
||||||
when "0010" =>
|
|
||||||
-- EOR
|
|
||||||
Q_t := BusA xor BusB;
|
|
||||||
when "0011" =>
|
|
||||||
-- ADC
|
|
||||||
P_Out(Flag_V) <= ADC_V;
|
|
||||||
P_Out(Flag_C) <= ADC_C;
|
|
||||||
Q_t := ADC_Q;
|
|
||||||
when "0101" | "1101" =>
|
|
||||||
-- LDA
|
|
||||||
when "0110" =>
|
|
||||||
-- CMP
|
|
||||||
P_Out(Flag_C) <= SBC_C;
|
|
||||||
when "0111" =>
|
|
||||||
-- SBC
|
|
||||||
P_Out(Flag_V) <= SBC_V;
|
|
||||||
P_Out(Flag_C) <= SBC_C;
|
|
||||||
Q_t := SBC_Q;
|
|
||||||
when "1000" =>
|
|
||||||
-- ASL
|
|
||||||
Q_t := BusA(6 downto 0) & "0";
|
|
||||||
P_Out(Flag_C) <= BusA(7);
|
|
||||||
when "1001" =>
|
|
||||||
-- ROL
|
|
||||||
Q_t := BusA(6 downto 0) & P_In(Flag_C);
|
|
||||||
P_Out(Flag_C) <= BusA(7);
|
|
||||||
when "1010" =>
|
|
||||||
-- LSR
|
|
||||||
Q_t := "0" & BusA(7 downto 1);
|
|
||||||
P_Out(Flag_C) <= BusA(0);
|
|
||||||
when "1011" =>
|
|
||||||
-- ROR
|
|
||||||
Q_t := P_In(Flag_C) & BusA(7 downto 1);
|
|
||||||
P_Out(Flag_C) <= BusA(0);
|
|
||||||
when "1100" =>
|
|
||||||
-- BIT
|
|
||||||
P_Out(Flag_V) <= BusB(6);
|
|
||||||
when "1110" =>
|
|
||||||
-- DEC
|
|
||||||
Q_t := std_logic_vector(unsigned(BusA) - 1);
|
|
||||||
when "1111" =>
|
|
||||||
-- INC
|
|
||||||
Q_t := std_logic_vector(unsigned(BusA) + 1);
|
|
||||||
when others =>
|
|
||||||
end case;
|
|
||||||
|
|
||||||
case Op(3 downto 0) is
|
|
||||||
when "0011" =>
|
|
||||||
P_Out(Flag_N) <= ADC_N;
|
|
||||||
P_Out(Flag_Z) <= ADC_Z;
|
|
||||||
when "0110" | "0111" =>
|
|
||||||
P_Out(Flag_N) <= SBC_N;
|
|
||||||
P_Out(Flag_Z) <= SBC_Z;
|
|
||||||
when "0100" =>
|
|
||||||
when "1100" =>
|
|
||||||
P_Out(Flag_N) <= BusB(7);
|
|
||||||
if (BusA and BusB) = "00000000" then
|
|
||||||
P_Out(Flag_Z) <= '1';
|
|
||||||
else
|
|
||||||
P_Out(Flag_Z) <= '0';
|
|
||||||
end if;
|
|
||||||
when others =>
|
|
||||||
P_Out(Flag_N) <= Q_t(7);
|
|
||||||
if Q_t = "00000000" then
|
|
||||||
P_Out(Flag_Z) <= '1';
|
|
||||||
else
|
|
||||||
P_Out(Flag_Z) <= '0';
|
|
||||||
end if;
|
|
||||||
end case;
|
|
||||||
|
|
||||||
Q <= Q_t;
|
|
||||||
end process;
|
|
||||||
|
|
||||||
end;
|
|
||||||
Reference in New Issue
Block a user