1
0
mirror of https://github.com/Gehstock/Mist_FPGA.git synced 2026-02-13 11:24:06 +00:00
This commit is contained in:
Marcel
2019-04-09 02:01:50 +02:00
parent 6c8d7dfca7
commit a13ecf0b40
78 changed files with 10545 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
# -------------------------------------------------------------------------- #
#
# 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.
#
# -------------------------------------------------------------------------- #
#
# Quartus II 64-Bit
# Version 13.1.0 Build 162 10/23/2013 SJ Web Edition
# Date created = 23:59:05 March 16, 2017
#
# -------------------------------------------------------------------------- #
QUARTUS_VERSION = "13.1"
DATE = "23:59:05 March 16, 2017"
# Revisions
PROJECT_REVISION = "Frenzy_MiST"

View File

@@ -0,0 +1,222 @@
# -------------------------------------------------------------------------- #
#
# Copyright (C) 1991-2014 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.
#
# -------------------------------------------------------------------------- #
#
# Quartus II 64-Bit
# Version 13.1.4 Build 182 03/12/2014 SJ Web Edition
# Date created = 19:37:13 March 20, 2019
#
# -------------------------------------------------------------------------- #
#
# Notes:
#
# 1) The default values for assignments are stored in the file:
# Berzerk_MiST_assignment_defaults.qdf
# If this file doesn't exist, see file:
# assignment_defaults.qdf
#
# 2) Altera recommends that you do not modify this file. This
# file is updated automatically by the Quartus II software
# and any changes you make may be lost or overwritten.
#
# -------------------------------------------------------------------------- #
# Project-Wide Assignments
# ========================
set_global_assignment -name ORIGINAL_QUARTUS_VERSION 13.1
set_global_assignment -name PROJECT_CREATION_TIME_DATE "23:59:05 MARCH 16, 2017"
set_global_assignment -name LAST_QUARTUS_VERSION 13.1
set_global_assignment -name PROJECT_OUTPUT_DIRECTORY Output
set_global_assignment -name PRE_FLOW_SCRIPT_FILE "quartus_sh:rtl/build_id.tcl"
# Pin & Location Assignments
# ==========================
set_location_assignment PIN_54 -to CLOCK_27
set_location_assignment PIN_7 -to LED
set_location_assignment PIN_144 -to VGA_R[5]
set_location_assignment PIN_143 -to VGA_R[4]
set_location_assignment PIN_142 -to VGA_R[3]
set_location_assignment PIN_141 -to VGA_R[2]
set_location_assignment PIN_137 -to VGA_R[1]
set_location_assignment PIN_135 -to VGA_R[0]
set_location_assignment PIN_133 -to VGA_B[5]
set_location_assignment PIN_132 -to VGA_B[4]
set_location_assignment PIN_125 -to VGA_B[3]
set_location_assignment PIN_121 -to VGA_B[2]
set_location_assignment PIN_120 -to VGA_B[1]
set_location_assignment PIN_115 -to VGA_B[0]
set_location_assignment PIN_114 -to VGA_G[5]
set_location_assignment PIN_113 -to VGA_G[4]
set_location_assignment PIN_112 -to VGA_G[3]
set_location_assignment PIN_111 -to VGA_G[2]
set_location_assignment PIN_110 -to VGA_G[1]
set_location_assignment PIN_106 -to VGA_G[0]
set_location_assignment PIN_136 -to VGA_VS
set_location_assignment PIN_119 -to VGA_HS
set_location_assignment PIN_65 -to AUDIO_L
set_location_assignment PIN_80 -to AUDIO_R
set_location_assignment PIN_105 -to SPI_DO
set_location_assignment PIN_88 -to SPI_DI
set_location_assignment PIN_126 -to SPI_SCK
set_location_assignment PIN_127 -to SPI_SS2
set_location_assignment PIN_91 -to SPI_SS3
set_location_assignment PIN_90 -to SPI_SS4
set_location_assignment PIN_13 -to CONF_DATA0
set_location_assignment PIN_49 -to SDRAM_A[0]
set_location_assignment PIN_44 -to SDRAM_A[1]
set_location_assignment PIN_42 -to SDRAM_A[2]
set_location_assignment PIN_39 -to SDRAM_A[3]
set_location_assignment PIN_4 -to SDRAM_A[4]
set_location_assignment PIN_6 -to SDRAM_A[5]
set_location_assignment PIN_8 -to SDRAM_A[6]
set_location_assignment PIN_10 -to SDRAM_A[7]
set_location_assignment PIN_11 -to SDRAM_A[8]
set_location_assignment PIN_28 -to SDRAM_A[9]
set_location_assignment PIN_50 -to SDRAM_A[10]
set_location_assignment PIN_30 -to SDRAM_A[11]
set_location_assignment PIN_32 -to SDRAM_A[12]
set_location_assignment PIN_83 -to SDRAM_DQ[0]
set_location_assignment PIN_79 -to SDRAM_DQ[1]
set_location_assignment PIN_77 -to SDRAM_DQ[2]
set_location_assignment PIN_76 -to SDRAM_DQ[3]
set_location_assignment PIN_72 -to SDRAM_DQ[4]
set_location_assignment PIN_71 -to SDRAM_DQ[5]
set_location_assignment PIN_69 -to SDRAM_DQ[6]
set_location_assignment PIN_68 -to SDRAM_DQ[7]
set_location_assignment PIN_86 -to SDRAM_DQ[8]
set_location_assignment PIN_87 -to SDRAM_DQ[9]
set_location_assignment PIN_98 -to SDRAM_DQ[10]
set_location_assignment PIN_99 -to SDRAM_DQ[11]
set_location_assignment PIN_100 -to SDRAM_DQ[12]
set_location_assignment PIN_101 -to SDRAM_DQ[13]
set_location_assignment PIN_103 -to SDRAM_DQ[14]
set_location_assignment PIN_104 -to SDRAM_DQ[15]
set_location_assignment PIN_58 -to SDRAM_BA[0]
set_location_assignment PIN_51 -to SDRAM_BA[1]
set_location_assignment PIN_85 -to SDRAM_DQMH
set_location_assignment PIN_67 -to SDRAM_DQML
set_location_assignment PIN_60 -to SDRAM_nRAS
set_location_assignment PIN_64 -to SDRAM_nCAS
set_location_assignment PIN_66 -to SDRAM_nWE
set_location_assignment PIN_59 -to SDRAM_nCS
set_location_assignment PIN_33 -to SDRAM_CKE
set_location_assignment PIN_43 -to SDRAM_CLK
set_location_assignment PIN_31 -to UART_RX
set_location_assignment PIN_46 -to UART_TX
# Classic Timing Assignments
# ==========================
set_global_assignment -name MIN_CORE_JUNCTION_TEMP 0
set_global_assignment -name MAX_CORE_JUNCTION_TEMP 85
# Analysis & Synthesis Assignments
# ================================
set_global_assignment -name FAMILY "Cyclone III"
set_global_assignment -name TOP_LEVEL_ENTITY frenzy_mist
set_global_assignment -name DEVICE_FILTER_PACKAGE TQFP
set_global_assignment -name DEVICE_FILTER_PIN_COUNT 144
set_global_assignment -name DEVICE_FILTER_SPEED_GRADE 8
set_global_assignment -name VERILOG_INPUT_VERSION SYSTEMVERILOG_2005
set_global_assignment -name VERILOG_SHOW_LMF_MAPPING_MESSAGES OFF
# Fitter Assignments
# ==================
set_global_assignment -name DEVICE EP3C25E144C8
set_global_assignment -name ERROR_CHECK_FREQUENCY_DIVISOR 1
set_global_assignment -name STRATIX_DEVICE_IO_STANDARD "3.3-V LVTTL"
set_global_assignment -name CYCLONEIII_CONFIGURATION_SCHEME "PASSIVE SERIAL"
set_global_assignment -name CRC_ERROR_OPEN_DRAIN OFF
set_global_assignment -name FORCE_CONFIGURATION_VCCIO ON
set_global_assignment -name CYCLONEII_RESERVE_NCEO_AFTER_CONFIGURATION "USE AS REGULAR IO"
set_global_assignment -name RESERVE_DATA0_AFTER_CONFIGURATION "USE AS REGULAR IO"
set_global_assignment -name RESERVE_DATA1_AFTER_CONFIGURATION "USE AS REGULAR IO"
set_global_assignment -name RESERVE_FLASH_NCE_AFTER_CONFIGURATION "USE AS REGULAR IO"
set_global_assignment -name RESERVE_DCLK_AFTER_CONFIGURATION "USE AS REGULAR IO"
# EDA Netlist Writer Assignments
# ==============================
set_global_assignment -name EDA_SIMULATION_TOOL "ModelSim-Altera (VHDL)"
# Assembler Assignments
# =====================
set_global_assignment -name USE_CONFIGURATION_DEVICE OFF
set_global_assignment -name GENERATE_RBF_FILE ON
# Power Estimation Assignments
# ============================
set_global_assignment -name POWER_PRESET_COOLING_SOLUTION "23 MM HEAT SINK WITH 200 LFPM AIRFLOW"
set_global_assignment -name POWER_BOARD_THERMAL_MODEL "NONE (CONSERVATIVE)"
# Advanced I/O Timing Assignments
# ===============================
set_global_assignment -name OUTPUT_IO_TIMING_NEAR_END_VMEAS "HALF VCCIO" -rise
set_global_assignment -name OUTPUT_IO_TIMING_NEAR_END_VMEAS "HALF VCCIO" -fall
set_global_assignment -name OUTPUT_IO_TIMING_FAR_END_VMEAS "HALF SIGNAL SWING" -rise
set_global_assignment -name OUTPUT_IO_TIMING_FAR_END_VMEAS "HALF SIGNAL SWING" -fall
# start EDA_TOOL_SETTINGS(eda_simulation)
# ---------------------------------------
# EDA Netlist Writer Assignments
# ==============================
set_global_assignment -name EDA_OUTPUT_DATA_FORMAT VHDL -section_id eda_simulation
# end EDA_TOOL_SETTINGS(eda_simulation)
# -------------------------------------
# --------------------------
# start ENTITY(berzerk_mist)
# start DESIGN_PARTITION(Top)
# ---------------------------
# Incremental Compilation Assignments
# ===================================
# end DESIGN_PARTITION(Top)
# -------------------------
# end ENTITY(berzerk_mist)
# ------------------------
set_global_assignment -name SYSTEMVERILOG_FILE rtl/frenzy_mist.sv
set_global_assignment -name VHDL_FILE rtl/berzerk.vhd
set_global_assignment -name VHDL_FILE rtl/video_gen.vhd
set_global_assignment -name VHDL_FILE rtl/berzerk_speech.vhd
set_global_assignment -name VHDL_FILE rtl/berzerk_speech_rom.vhd
set_global_assignment -name VHDL_FILE rtl/berzerk_sound_fx.vhd
set_global_assignment -name VHDL_FILE rtl/berzerk_program2.vhd
set_global_assignment -name VHDL_FILE rtl/berzerk_program1.vhd
set_global_assignment -name VHDL_FILE rtl/gen_ram.vhd
set_global_assignment -name VHDL_FILE rtl/T80/T80se.vhd
set_global_assignment -name VHDL_FILE rtl/T80/T80_Reg.vhd
set_global_assignment -name VHDL_FILE rtl/T80/T80_Pack.vhd
set_global_assignment -name VHDL_FILE rtl/T80/T80_MCode.vhd
set_global_assignment -name VHDL_FILE rtl/T80/T80_ALU.vhd
set_global_assignment -name VHDL_FILE rtl/T80/T80.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/pll.v
set_global_assignment -name VERILOG_FILE rtl/osd.v
set_global_assignment -name VERILOG_FILE rtl/mist_io.v
set_global_assignment -name SYSTEMVERILOG_FILE rtl/hq2x.sv
set_global_assignment -name VHDL_FILE rtl/dac.vhd
set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top
set_global_assignment -name PARTITION_FITTER_PRESERVATION_LEVEL PLACEMENT_AND_ROUTING -section_id Top
set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top
set_instance_assignment -name PARTITION_HIERARCHY root_partition -to | -section_id Top

View File

@@ -0,0 +1,3 @@
{ "" "" "" "VHDL Signal Declaration warning at berzerk.vhd(107): used implicit default value for signal \"dbg_cpu_di\" because signal was never assigned a value or an explicit default value. Use of implicit default value may introduce unintended design optimizations." { } { } 0 10541 "" 0 0 "Quartus II" 0 -1 0 ""}
{ "" "" "" "Verilog HDL information at scandoubler.v(114): always construct contains both blocking and non-blocking assignments" { } { } 0 10268 "" 0 0 "Quartus II" 0 -1 0 ""}
{ "" "" "" "Verilog HDL warning at hq2x.sv(247): extended using \"x\" or \"z\"" { } { } 0 10273 "" 0 0 "Quartus II" 0 -1 0 ""}

View File

@@ -0,0 +1,150 @@
Frenzy Port to MiST
-------------------------------------------------
-- Berzerk FPGA by Dar - (darfpga@aol.fr)
-- http://darfpga.blogspot.fr
-------------------------------------------------
-- Berzerk releases
--
-- Release 0.0 - 07/07/2018 - Dar
-------------------------------------------------
Educational use only
Do not redistribute synthetized file with roms
Do not redistribute roms whatever the form
Use at your own risk
--------------------------------------------------------------------
make sure to use berzerk.zip roms
--------------------------------------------------------------------
--
-- Main features :
-- PS2 keyboard input @gpio pins 35/34 (beware voltage translation/protection)
-- Audio pwm output @gpio pins 1/3 (beware voltage translation/protection)
--
-- Uses 1 pll for 10MHz generation from 50MHz
--
-- Board key :
-- 0 : reset game
--
-- Board switch :
-- 1 : tv 15Khz mode / VGA 640x480 mode
--
-- Keyboard players inputs :
--
-- F3 : Add coin
-- F2 : Start 2 players
-- F1 : Start 1 player
-- SPACE : fire
-- RIGHT arrow : move right
-- LEFT arrow : move left
-- UP arrow : move up
-- DOWN arrow : move down
--
-- Sound effects : OK
-- Speech synthesis : todo
--
---------------
VHDL File list
---------------
max10_pll_10M.vhd Pll 10MHz from 50MHz altera mf
berzerk_de10_lite.vhd Top level for de10-lite board
berzerk.vhd Main logic
berzerk_sound_fx.vhd Music logic
berzerk_program1.vhd
berzerk_program2.vhd
video_gen.vhd Video scheduler, syncs (h,v and composite)
line_doubler.vhd Line doubler 15kHz -> 31kHz VGA
kbd_joystick.vhd Keyboard key to player/coin input
T80se.vhd T80 release 304
T80_Reg.vhd
T80_Pack.vhd
T80_MCode.vhd
T80_ALU.vhd
T80.vhd
io_ps2_keyboard.vhd Copyright 2005-2008 by Peter Wendrich (pwsoft@syntiac.com)
gen_ram.vhd
decodeur_7_seg.vhd for debug
----------------------
Quartus project files
----------------------
de10_lite/berzerk_de10_lite.qsf de10_lite settings (files,pins,...)
de10_lite/berzerk_de10_lite.qpf de10_lite project
de10_lite/berzerk_de10_lite.sdc timequest constraints
+----------------------------------------------------------------------------------+
; Fitter Summary ;
+------------------------------------+---------------------------------------------+
; Fitter Status ; Successful - Sat Jul 07 07:38:44 2018 ;
; Quartus Prime Version ; 16.1.0 Build 196 10/24/2016 SJ Lite Edition ;
; Revision Name ; berzerk_de10_lite ;
; Top-level Entity Name ; berzerk_de10_lite ;
; Family ; MAX 10 ;
; Device ; 10M50DAF484C6GES ;
; Timing Models ; Preliminary ;
; Total logic elements ; 3,277 / 49,760 ( 7 % ) ;
; Total combinational functions ; 3,043 / 49,760 ( 6 % ) ;
; Dedicated logic registers ; 886 / 49,760 ( 2 % ) ;
; Total registers ; 886 ;
; Total pins ; 121 / 360 ( 34 % ) ;
; Total virtual pins ; 0 ;
; Total memory bits ; 241,664 / 1,677,312 ( 14 % ) ;
; Embedded Multiplier 9-bit elements ; 0 / 288 ( 0 % ) ;
; Total PLLs ; 1 / 4 ( 25 % ) ;
; UFM blocks ; 0 / 1 ( 0 % ) ;
; ADC blocks ; 0 / 2 ( 0 % ) ;
+------------------------------------+---------------------------------------------+
-----------------------------
Required ROMs (Not included)
-----------------------------
You need the following 8 ROMs from berzerk.zip
berzerk_rc31_1c.rom0.1c CRC(ca566dbc) SHA1(fae2647f12f1cd82826db61b53b116a5e0c9f995)
berzerk_rc31_1d.rom1.1d CRC(7ba69fde) SHA1(69af170c4a39a3494dcd180737e5c87b455f9203)
berzerk_rc31_3d.rom2.3d CRC(a1d5248b) SHA1(a0b7842f6a5f86c16d80d78e7012c78b3ea11d1d)
berzerk_rc31_5d.rom3.5d CRC(fcaefa95) SHA1(07f849aa39f1e3db938187ffde4a46a588156ddc)
berzerk_rc31_6d.rom4.6d CRC(1e35b9a0) SHA1(5a5e549ec0e4803ab2d1eac6b3e7171aedf28244)
berzerk_rc31_5c.rom5.5c CRC(c8c665e5) SHA1(e9eca4b119549e0061384abf52327c14b0d56624)
berzerk_r_vo_1c.1c CRC(2cfe825d) SHA1(f12fed8712f20fa8213f606c4049a8144bfea42e)
berzerk_r_vo_2c.2c CRC(d2b6324e) SHA1(20a6611ad6ec19409ac138bdae7bdfaeab6c47cf)
------
Tools
------
You need to build vhdl ROM image files from the binary file :
- Unzip the roms file in the tools/berzerk_unzip directory
- Double click (execute) the script tools/berzerk_unzip/make_berzerk_proms.bat to get the following files
berzerk_program1.vhd
berzerk_program2.vhd
*DO NOT REDISTRIBUTE THESE FILES*
The script make_berzerk_proms uses make_vhdl_prom and and duplicate_byte executables delivered both in linux and windows version. The script itself is delivered only in windows version (.bat) but should be easily ported to linux.
Source code of make_vhdl_prom.c and and duplicate_byte.c is also delivered.
---------------------------------
Compiling for de10_lite
---------------------------------
You can rebuild the project with ROM image embeded in the sof file. DO NOT REDISTRIBUTE THESE FILES.
4 steps
- put the VHDL rom files into the project directory
- rebuild berzerk_de10_lite
- program berzerk_de10_lite.sof into the fpga
------------------------
End of file
------------------------

View File

@@ -0,0 +1,37 @@
@echo off
del /s *.bak
del /s *.orig
del /s *.rej
del /s *~
rmdir /s /q db
rmdir /s /q incremental_db
rmdir /s /q output_files
rmdir /s /q simulation
rmdir /s /q greybox_tmp
rmdir /s /q hc_output
rmdir /s /q .qsys_edit
rmdir /s /q hps_isw_handoff
rmdir /s /q sys\.qsys_edit
rmdir /s /q sys\vip
cd sys
for /d %%i in (*_sim) do rmdir /s /q "%%~nxi"
cd ..
for /d %%i in (*_sim) do rmdir /s /q "%%~nxi"
del build_id.v
del c5_pin_model_dump.txt
del PLLJ_PLLSPE_INFO.txt
del /s *.qws
del /s *.ppf
del /s *.ddb
del /s *.csv
del /s *.cmp
del /s *.sip
del /s *.spd
del /s *.bsf
del /s *.f
del /s *.sopcinfo
del /s *.xml
del /s new_rtl_netlist
del /s old_rtl_netlist
pause

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,199 @@
-- ****
-- T80(b) core. In an effort to merge and maintain bug fixes ....
--
-- Ver 300 started tidyup
--
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
--
-- $Id: T8080se.vhd 1330 2015-05-22 19:55:46Z wolfgang.scherr $
--
-- ****
--
-- 8080 compatible microprocessor core, synchronous top level with clock enable
-- Different timing than the original 8080
-- Inputs needs to be synchronous and outputs may glitch
--
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
-- MikeJ March 2005
--
-- 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/t80/
--
-- Limitations :
-- STACK status output not supported
--
-- File history :
--
-- 0237 : First version
--
-- 0238 : Updated for T80 interface change
--
-- 0240 : Updated for T80 interface change
--
-- 0242 : Updated for T80 interface change
--
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use work.T80_Pack.all;
entity T8080se is
generic(
Mode : integer := 2; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
T2Write : integer := 1 -- 0 => WR_n active in T3, /=0 => WR_n active in T2
);
port(
RESET_n : in std_logic;
CLK : in std_logic;
CLKEN : in std_logic;
READY : in std_logic;
HOLD : in std_logic;
INT : in std_logic;
INTE : out std_logic;
DBIN : out std_logic;
SYNC : out std_logic;
VAIT : out std_logic;
HLDA : out std_logic;
RD_n : out std_logic;
WR_n : out std_logic;
A : out std_logic_vector(15 downto 0);
DI : in std_logic_vector(7 downto 0);
DO : out std_logic_vector(7 downto 0)
);
end T8080se;
architecture rtl of T8080se is
signal IntCycle_n : std_logic;
signal NoRead : std_logic;
signal Write : std_logic;
signal IORQ : std_logic;
signal INT_n : std_logic;
signal HALT_n : std_logic;
signal BUSRQ_n : std_logic;
signal BUSAK_n : std_logic;
signal DO_i : std_logic_vector(7 downto 0);
signal DI_Reg : std_logic_vector(7 downto 0);
signal MCycle : std_logic_vector(2 downto 0);
signal TState : std_logic_vector(2 downto 0);
signal One : std_logic;
begin
INT_n <= not INT;
BUSRQ_n <= HOLD;
HLDA <= not BUSAK_n;
SYNC <= '1' when TState = "001" else '0';
VAIT <= '1' when TState = "010" else '0';
One <= '1';
DO(0) <= not IntCycle_n when TState = "001" else DO_i(0); -- INTA
DO(1) <= Write when TState = "001" else DO_i(1); -- WO_n
DO(2) <= DO_i(2); -- STACK not supported !!!!!!!!!!
DO(3) <= not HALT_n when TState = "001" else DO_i(3); -- HLTA
DO(4) <= IORQ and Write when TState = "001" else DO_i(4); -- OUT
DO(5) <= DO_i(5) when TState /= "001" else '1' when MCycle = "001" else '0'; -- M1
DO(6) <= IORQ and not Write when TState = "001" else DO_i(6); -- INP
DO(7) <= not IORQ and not Write and IntCycle_n when TState = "001" else DO_i(7); -- MEMR
u0 : T80
generic map(
Mode => Mode,
IOWait => 0)
port map(
CEN => CLKEN,
M1_n => open,
IORQ => IORQ,
NoRead => NoRead,
Write => Write,
RFSH_n => open,
HALT_n => HALT_n,
WAIT_n => READY,
INT_n => INT_n,
NMI_n => One,
RESET_n => RESET_n,
BUSRQ_n => One,
BUSAK_n => BUSAK_n,
CLK_n => CLK,
A => A,
DInst => DI,
DI => DI_Reg,
DO => DO_i,
MC => MCycle,
TS => TState,
IntCycle_n => IntCycle_n,
IntE => INTE);
process (RESET_n, CLK)
begin
if RESET_n = '0' then
DBIN <= '0';
RD_n <= '0';
WR_n <= '1';
DI_Reg <= "00000000";
elsif CLK'event and CLK = '1' then
if CLKEN = '1' then
DBIN <= '0';
RD_n <= '0';
WR_n <= '1';
if MCycle = "001" then
if TState = "001" or (TState = "010" and READY = '0') then
DBIN <= IntCycle_n;
end if;
else
if (TState = "001" or (TState = "010" and READY = '0')) and NoRead = '0' and Write = '0' then
DBIN <= '1';
end if;
if T2Write = 0 then
if TState = "010" and Write = '1' then
WR_n <= '0';
RD_n <= '1';
end if;
else
if (TState = "001" or (TState = "010" and READY = '0')) and Write = '1' then
WR_n <= '0';
RD_n <= '1';
end if;
end if;
end if;
if TState = "010" and READY = '1' then
DI_Reg <= DI;
end if;
end if;
end if;
end process;
end;

View File

@@ -0,0 +1,371 @@
-- ****
-- T80(b) core. In an effort to merge and maintain bug fixes ....
--
-- Ver 301 parity flag is just parity for 8080, also overflow for Z80, by Sean Riddle
-- Ver 300 started tidyup
--
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
--
-- $Id: T80_ALU.vhd 1330 2015-05-22 19:55:46Z wolfgang.scherr $
--
-- ****
--
-- Z80 compatible microprocessor core
--
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
-- MikeJ March 2005
--
-- 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/t80/
--
-- Limitations :
--
-- File history :
--
-- 0214 : Fixed mostly flags, only the block instructions now fail the zex regression test
--
-- 0238 : Fixed zero flag for 16 bit SBC and ADC
--
-- 0240 : Added GB operations
--
-- 0242 : Cleanup
--
-- 0247 : Cleanup
--
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity T80_ALU is
generic(
Mode : integer := 0;
Flag_C : integer := 0;
Flag_N : integer := 1;
Flag_P : integer := 2;
Flag_X : integer := 3;
Flag_H : integer := 4;
Flag_Y : integer := 5;
Flag_Z : integer := 6;
Flag_S : integer := 7
);
port(
Arith16 : in std_logic;
Z16 : in std_logic;
ALU_Op : in std_logic_vector(3 downto 0);
IR : in std_logic_vector(5 downto 0);
ISet : in std_logic_vector(1 downto 0);
BusA : in std_logic_vector(7 downto 0);
BusB : in std_logic_vector(7 downto 0);
F_In : in std_logic_vector(7 downto 0);
Q : out std_logic_vector(7 downto 0);
F_Out : out std_logic_vector(7 downto 0)
);
end T80_ALU;
architecture rtl of T80_ALU is
procedure AddSub(A : std_logic_vector;
B : std_logic_vector;
Sub : std_logic;
Carry_In : std_logic;
signal Res : out std_logic_vector;
signal Carry : out std_logic) is
variable B_i : unsigned(A'length - 1 downto 0);
variable Res_i : unsigned(A'length + 1 downto 0);
begin
if Sub = '1' then
B_i := not unsigned(B);
else
B_i := unsigned(B);
end if;
Res_i := unsigned("0" & A & Carry_In) + unsigned("0" & B_i & "1");
Carry <= Res_i(A'length + 1);
Res <= std_logic_vector(Res_i(A'length downto 1));
end;
-- AddSub variables (temporary signals)
signal UseCarry : std_logic;
signal Carry7_v : std_logic;
signal Overflow_v : std_logic;
signal HalfCarry_v : std_logic;
signal Carry_v : std_logic;
signal Q_v : std_logic_vector(7 downto 0);
signal BitMask : std_logic_vector(7 downto 0);
begin
with IR(5 downto 3) select BitMask <= "00000001" when "000",
"00000010" when "001",
"00000100" when "010",
"00001000" when "011",
"00010000" when "100",
"00100000" when "101",
"01000000" when "110",
"10000000" when others;
UseCarry <= not ALU_Op(2) and ALU_Op(0);
AddSub(BusA(3 downto 0), BusB(3 downto 0), ALU_Op(1), ALU_Op(1) xor (UseCarry and F_In(Flag_C)), Q_v(3 downto 0), HalfCarry_v);
AddSub(BusA(6 downto 4), BusB(6 downto 4), ALU_Op(1), HalfCarry_v, Q_v(6 downto 4), Carry7_v);
AddSub(BusA(7 downto 7), BusB(7 downto 7), ALU_Op(1), Carry7_v, Q_v(7 downto 7), Carry_v);
-- bug fix - parity flag is just parity for 8080, also overflow for Z80
process (Carry_v, Carry7_v, Q_v)
begin
if(Mode=2) then
OverFlow_v <= not (Q_v(0) xor Q_v(1) xor Q_v(2) xor Q_v(3) xor
Q_v(4) xor Q_v(5) xor Q_v(6) xor Q_v(7)); else
OverFlow_v <= Carry_v xor Carry7_v;
end if;
end process;
process (Arith16, ALU_OP, F_In, BusA, BusB, IR, Q_v, Carry_v, HalfCarry_v, OverFlow_v, BitMask, ISet, Z16)
variable Q_t : std_logic_vector(7 downto 0);
variable DAA_Q : unsigned(8 downto 0);
begin
Q_t := "--------";
F_Out <= F_In;
DAA_Q := "---------";
case ALU_Op is
when "0000" | "0001" | "0010" | "0011" | "0100" | "0101" | "0110" | "0111" =>
F_Out(Flag_N) <= '0';
F_Out(Flag_C) <= '0';
case ALU_OP(2 downto 0) is
when "000" | "001" => -- ADD, ADC
Q_t := Q_v;
F_Out(Flag_C) <= Carry_v;
F_Out(Flag_H) <= HalfCarry_v;
F_Out(Flag_P) <= OverFlow_v;
when "010" | "011" | "111" => -- SUB, SBC, CP
Q_t := Q_v;
F_Out(Flag_N) <= '1';
F_Out(Flag_C) <= not Carry_v;
F_Out(Flag_H) <= not HalfCarry_v;
F_Out(Flag_P) <= OverFlow_v;
when "100" => -- AND
Q_t(7 downto 0) := BusA and BusB;
F_Out(Flag_H) <= '1';
when "101" => -- XOR
Q_t(7 downto 0) := BusA xor BusB;
F_Out(Flag_H) <= '0';
when others => -- OR "110"
Q_t(7 downto 0) := BusA or BusB;
F_Out(Flag_H) <= '0';
end case;
if ALU_Op(2 downto 0) = "111" then -- CP
F_Out(Flag_X) <= BusB(3);
F_Out(Flag_Y) <= BusB(5);
else
F_Out(Flag_X) <= Q_t(3);
F_Out(Flag_Y) <= Q_t(5);
end if;
if Q_t(7 downto 0) = "00000000" then
F_Out(Flag_Z) <= '1';
if Z16 = '1' then
F_Out(Flag_Z) <= F_In(Flag_Z); -- 16 bit ADC,SBC
end if;
else
F_Out(Flag_Z) <= '0';
end if;
F_Out(Flag_S) <= Q_t(7);
case ALU_Op(2 downto 0) is
when "000" | "001" | "010" | "011" | "111" => -- ADD, ADC, SUB, SBC, CP
when others =>
F_Out(Flag_P) <= not (Q_t(0) xor Q_t(1) xor Q_t(2) xor Q_t(3) xor
Q_t(4) xor Q_t(5) xor Q_t(6) xor Q_t(7));
end case;
if Arith16 = '1' then
F_Out(Flag_S) <= F_In(Flag_S);
F_Out(Flag_Z) <= F_In(Flag_Z);
F_Out(Flag_P) <= F_In(Flag_P);
end if;
when "1100" =>
-- DAA
F_Out(Flag_H) <= F_In(Flag_H);
F_Out(Flag_C) <= F_In(Flag_C);
DAA_Q(7 downto 0) := unsigned(BusA);
DAA_Q(8) := '0';
if F_In(Flag_N) = '0' then
-- After addition
-- Alow > 9 or H = 1
if DAA_Q(3 downto 0) > 9 or F_In(Flag_H) = '1' then
if (DAA_Q(3 downto 0) > 9) then
F_Out(Flag_H) <= '1';
else
F_Out(Flag_H) <= '0';
end if;
DAA_Q := DAA_Q + 6;
end if;
-- new Ahigh > 9 or C = 1
if DAA_Q(8 downto 4) > 9 or F_In(Flag_C) = '1' then
DAA_Q := DAA_Q + 96; -- 0x60
end if;
else
-- After subtraction
if DAA_Q(3 downto 0) > 9 or F_In(Flag_H) = '1' then
if DAA_Q(3 downto 0) > 5 then
F_Out(Flag_H) <= '0';
end if;
DAA_Q(7 downto 0) := DAA_Q(7 downto 0) - 6;
end if;
if unsigned(BusA) > 153 or F_In(Flag_C) = '1' then
DAA_Q := DAA_Q - 352; -- 0x160
end if;
end if;
F_Out(Flag_X) <= DAA_Q(3);
F_Out(Flag_Y) <= DAA_Q(5);
F_Out(Flag_C) <= F_In(Flag_C) or DAA_Q(8);
Q_t := std_logic_vector(DAA_Q(7 downto 0));
if DAA_Q(7 downto 0) = "00000000" then
F_Out(Flag_Z) <= '1';
else
F_Out(Flag_Z) <= '0';
end if;
F_Out(Flag_S) <= DAA_Q(7);
F_Out(Flag_P) <= not (DAA_Q(0) xor DAA_Q(1) xor DAA_Q(2) xor DAA_Q(3) xor
DAA_Q(4) xor DAA_Q(5) xor DAA_Q(6) xor DAA_Q(7));
when "1101" | "1110" =>
-- RLD, RRD
Q_t(7 downto 4) := BusA(7 downto 4);
if ALU_Op(0) = '1' then
Q_t(3 downto 0) := BusB(7 downto 4);
else
Q_t(3 downto 0) := BusB(3 downto 0);
end if;
F_Out(Flag_H) <= '0';
F_Out(Flag_N) <= '0';
F_Out(Flag_X) <= Q_t(3);
F_Out(Flag_Y) <= Q_t(5);
if Q_t(7 downto 0) = "00000000" then
F_Out(Flag_Z) <= '1';
else
F_Out(Flag_Z) <= '0';
end if;
F_Out(Flag_S) <= Q_t(7);
F_Out(Flag_P) <= not (Q_t(0) xor Q_t(1) xor Q_t(2) xor Q_t(3) xor
Q_t(4) xor Q_t(5) xor Q_t(6) xor Q_t(7));
when "1001" =>
-- BIT
Q_t(7 downto 0) := BusB and BitMask;
F_Out(Flag_S) <= Q_t(7);
if Q_t(7 downto 0) = "00000000" then
F_Out(Flag_Z) <= '1';
F_Out(Flag_P) <= '1';
else
F_Out(Flag_Z) <= '0';
F_Out(Flag_P) <= '0';
end if;
F_Out(Flag_H) <= '1';
F_Out(Flag_N) <= '0';
F_Out(Flag_X) <= '0';
F_Out(Flag_Y) <= '0';
if IR(2 downto 0) /= "110" then
F_Out(Flag_X) <= BusB(3);
F_Out(Flag_Y) <= BusB(5);
end if;
when "1010" =>
-- SET
Q_t(7 downto 0) := BusB or BitMask;
when "1011" =>
-- RES
Q_t(7 downto 0) := BusB and not BitMask;
when "1000" =>
-- ROT
case IR(5 downto 3) is
when "000" => -- RLC
Q_t(7 downto 1) := BusA(6 downto 0);
Q_t(0) := BusA(7);
F_Out(Flag_C) <= BusA(7);
when "010" => -- RL
Q_t(7 downto 1) := BusA(6 downto 0);
Q_t(0) := F_In(Flag_C);
F_Out(Flag_C) <= BusA(7);
when "001" => -- RRC
Q_t(6 downto 0) := BusA(7 downto 1);
Q_t(7) := BusA(0);
F_Out(Flag_C) <= BusA(0);
when "011" => -- RR
Q_t(6 downto 0) := BusA(7 downto 1);
Q_t(7) := F_In(Flag_C);
F_Out(Flag_C) <= BusA(0);
when "100" => -- SLA
Q_t(7 downto 1) := BusA(6 downto 0);
Q_t(0) := '0';
F_Out(Flag_C) <= BusA(7);
when "110" => -- SLL (Undocumented) / SWAP
if Mode = 3 then
Q_t(7 downto 4) := BusA(3 downto 0);
Q_t(3 downto 0) := BusA(7 downto 4);
F_Out(Flag_C) <= '0';
else
Q_t(7 downto 1) := BusA(6 downto 0);
Q_t(0) := '1';
F_Out(Flag_C) <= BusA(7);
end if;
when "101" => -- SRA
Q_t(6 downto 0) := BusA(7 downto 1);
Q_t(7) := BusA(7);
F_Out(Flag_C) <= BusA(0);
when others => -- SRL
Q_t(6 downto 0) := BusA(7 downto 1);
Q_t(7) := '0';
F_Out(Flag_C) <= BusA(0);
end case;
F_Out(Flag_H) <= '0';
F_Out(Flag_N) <= '0';
F_Out(Flag_X) <= Q_t(3);
F_Out(Flag_Y) <= Q_t(5);
F_Out(Flag_S) <= Q_t(7);
if Q_t(7 downto 0) = "00000000" then
F_Out(Flag_Z) <= '1';
else
F_Out(Flag_Z) <= '0';
end if;
F_Out(Flag_P) <= not (Q_t(0) xor Q_t(1) xor Q_t(2) xor Q_t(3) xor
Q_t(4) xor Q_t(5) xor Q_t(6) xor Q_t(7));
if ISet = "00" then
F_Out(Flag_P) <= F_In(Flag_P);
F_Out(Flag_S) <= F_In(Flag_S);
F_Out(Flag_Z) <= F_In(Flag_Z);
end if;
when others =>
null;
end case;
Q <= Q_t;
end process;
end;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,220 @@
-- ****
-- T80(b) core. In an effort to merge and maintain bug fixes ....
--
-- Ver 303 add undocumented DDCB and FDCB opcodes by TobiFlex 20.04.2010
-- Ver 300 started tidyup
--
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
--
-- $Id: T80_Pack.vhd 1330 2015-05-22 19:55:46Z wolfgang.scherr $
--
-- ****
--
-- Z80 compatible microprocessor core
--
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
-- MikeJ March 2005
--
-- 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/t80/
--
-- Limitations :
--
-- File history :
--
library IEEE;
use IEEE.std_logic_1164.all;
package T80_Pack is
component T80
generic(
Mode : integer := 0; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
IOWait : integer := 0; -- 1 => Single cycle I/O, 1 => Std I/O cycle
Flag_C : integer := 0;
Flag_N : integer := 1;
Flag_P : integer := 2;
Flag_X : integer := 3;
Flag_H : integer := 4;
Flag_Y : integer := 5;
Flag_Z : integer := 6;
Flag_S : integer := 7
);
port(
RESET_n : in std_logic;
CLK_n : in std_logic;
CEN : in std_logic;
WAIT_n : in std_logic;
INT_n : in std_logic;
NMI_n : in std_logic;
BUSRQ_n : in std_logic;
M1_n : out std_logic;
IORQ : out std_logic;
NoRead : out std_logic;
Write : out std_logic;
RFSH_n : out std_logic;
HALT_n : out std_logic;
BUSAK_n : out std_logic;
A : out std_logic_vector(15 downto 0);
DInst : in std_logic_vector(7 downto 0);
DI : in std_logic_vector(7 downto 0);
DO : out std_logic_vector(7 downto 0);
MC : out std_logic_vector(2 downto 0);
TS : out std_logic_vector(2 downto 0);
IntCycle_n : out std_logic;
IntE : out std_logic;
Stop : out std_logic
);
end component;
component T80_Reg
port(
Clk : in std_logic;
CEN : in std_logic;
WEH : in std_logic;
WEL : in std_logic;
AddrA : in std_logic_vector(2 downto 0);
AddrB : in std_logic_vector(2 downto 0);
AddrC : in std_logic_vector(2 downto 0);
DIH : in std_logic_vector(7 downto 0);
DIL : in std_logic_vector(7 downto 0);
DOAH : out std_logic_vector(7 downto 0);
DOAL : out std_logic_vector(7 downto 0);
DOBH : out std_logic_vector(7 downto 0);
DOBL : out std_logic_vector(7 downto 0);
DOCH : out std_logic_vector(7 downto 0);
DOCL : out std_logic_vector(7 downto 0)
);
end component;
component T80_MCode
generic(
Mode : integer := 0;
Flag_C : integer := 0;
Flag_N : integer := 1;
Flag_P : integer := 2;
Flag_X : integer := 3;
Flag_H : integer := 4;
Flag_Y : integer := 5;
Flag_Z : integer := 6;
Flag_S : integer := 7
);
port(
IR : in std_logic_vector(7 downto 0);
ISet : in std_logic_vector(1 downto 0);
MCycle : in std_logic_vector(2 downto 0);
F : in std_logic_vector(7 downto 0);
NMICycle : in std_logic;
IntCycle : in std_logic;
XY_State : in std_logic_vector(1 downto 0);
MCycles : out std_logic_vector(2 downto 0);
TStates : out std_logic_vector(2 downto 0);
Prefix : out std_logic_vector(1 downto 0); -- None,BC,ED,DD/FD
Inc_PC : out std_logic;
Inc_WZ : out std_logic;
IncDec_16 : out std_logic_vector(3 downto 0); -- BC,DE,HL,SP 0 is inc
Read_To_Reg : out std_logic;
Read_To_Acc : out std_logic;
Set_BusA_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI/DB,A,SP(L),SP(M),0,F
Set_BusB_To : out std_logic_vector(3 downto 0); -- B,C,D,E,H,L,DI,A,SP(L),SP(M),1,F,PC(L),PC(M),0
ALU_Op : out std_logic_vector(3 downto 0);
-- ADD, ADC, SUB, SBC, AND, XOR, OR, CP, ROT, BIT, SET, RES, DAA, RLD, RRD, None
Save_ALU : out std_logic;
PreserveC : out std_logic;
Arith16 : out std_logic;
Set_Addr_To : out std_logic_vector(2 downto 0); -- aNone,aXY,aIOA,aSP,aBC,aDE,aZI
IORQ : out std_logic;
Jump : out std_logic;
JumpE : out std_logic;
JumpXY : out std_logic;
Call : out std_logic;
RstP : out std_logic;
LDZ : out std_logic;
LDW : out std_logic;
LDSPHL : out std_logic;
Special_LD : out std_logic_vector(2 downto 0); -- A,I;A,R;I,A;R,A;None
ExchangeDH : out std_logic;
ExchangeRp : out std_logic;
ExchangeAF : out std_logic;
ExchangeRS : out std_logic;
I_DJNZ : out std_logic;
I_CPL : out std_logic;
I_CCF : out std_logic;
I_SCF : out std_logic;
I_RETN : out std_logic;
I_BT : out std_logic;
I_BC : out std_logic;
I_BTR : out std_logic;
I_RLD : out std_logic;
I_RRD : out std_logic;
I_INRC : out std_logic;
SetDI : out std_logic;
SetEI : out std_logic;
IMode : out std_logic_vector(1 downto 0);
Halt : out std_logic;
NoRead : out std_logic;
Write : out std_logic;
XYbit_undoc : out std_logic
);
end component;
component T80_ALU
generic(
Mode : integer := 0;
Flag_C : integer := 0;
Flag_N : integer := 1;
Flag_P : integer := 2;
Flag_X : integer := 3;
Flag_H : integer := 4;
Flag_Y : integer := 5;
Flag_Z : integer := 6;
Flag_S : integer := 7
);
port(
Arith16 : in std_logic;
Z16 : in std_logic;
ALU_Op : in std_logic_vector(3 downto 0);
IR : in std_logic_vector(5 downto 0);
ISet : in std_logic_vector(1 downto 0);
BusA : in std_logic_vector(7 downto 0);
BusB : in std_logic_vector(7 downto 0);
F_In : in std_logic_vector(7 downto 0);
Q : out std_logic_vector(7 downto 0);
F_Out : out std_logic_vector(7 downto 0)
);
end component;
end;

View File

@@ -0,0 +1,116 @@
-- ****
-- T80(b) core. In an effort to merge and maintain bug fixes ....
--
-- Ver 304 init values of registers on first startup (better simulation)
-- Ver 300 started tidyup
--
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
--
-- $Id: T80_Reg.vhd 1330 2015-05-22 19:55:46Z wolfgang.scherr $
--
-- ****
--
-- T80 Registers, technology independent
--
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
-- MikeJ March 2005
-- Wolfgang Scherr 2011-2015 (email: WoS <at> pin4 <dot> at)
--
-- 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/t51/
--
-- Limitations :
--
-- File history :
--
-- 0242 : Initial release
--
-- 0244 : Changed to single register file
--
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity T80_Reg is
port(
Clk : in std_logic;
CEN : in std_logic;
WEH : in std_logic;
WEL : in std_logic;
AddrA : in std_logic_vector(2 downto 0);
AddrB : in std_logic_vector(2 downto 0);
AddrC : in std_logic_vector(2 downto 0);
DIH : in std_logic_vector(7 downto 0);
DIL : in std_logic_vector(7 downto 0);
DOAH : out std_logic_vector(7 downto 0);
DOAL : out std_logic_vector(7 downto 0);
DOBH : out std_logic_vector(7 downto 0);
DOBL : out std_logic_vector(7 downto 0);
DOCH : out std_logic_vector(7 downto 0);
DOCL : out std_logic_vector(7 downto 0)
);
end T80_Reg;
architecture rtl of T80_Reg is
type Register_Image is array (natural range <>) of std_logic_vector(7 downto 0);
signal RegsH : Register_Image(0 to 7) := (others => (others => '0'));
signal RegsL : Register_Image(0 to 7) := (others => (others => '0'));
begin
process (Clk)
begin
if Clk'event and Clk = '1' then
if CEN = '1' then
if WEH = '1' then
RegsH(to_integer(unsigned(AddrA))) <= DIH;
end if;
if WEL = '1' then
RegsL(to_integer(unsigned(AddrA))) <= DIL;
end if;
end if;
end if;
end process;
DOAH <= RegsH(to_integer(unsigned(AddrA)));
DOAL <= RegsL(to_integer(unsigned(AddrA)));
DOBH <= RegsH(to_integer(unsigned(AddrB)));
DOBL <= RegsL(to_integer(unsigned(AddrB)));
DOCH <= RegsH(to_integer(unsigned(AddrC)));
DOCL <= RegsL(to_integer(unsigned(AddrC)));
end;

View File

@@ -0,0 +1,262 @@
-- ****
-- T80(b) core. In an effort to merge and maintain bug fixes ....
--
-- Ver 300 started tidyup
--
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
--
-- $Id: T80a.vhd 1330 2015-05-22 19:55:46Z wolfgang.scherr $
--
-- ****
--
-- Z80 compatible microprocessor core, asynchronous top level
--
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
-- MikeJ March 2005
--
-- 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/t80/
--
-- Limitations :
--
-- File history :
--
-- 0208 : First complete release
--
-- 0211 : Fixed interrupt cycle
--
-- 0235 : Updated for T80 interface change
--
-- 0238 : Updated for T80 interface change
--
-- 0240 : Updated for T80 interface change
--
-- 0242 : Updated for T80 interface change
--
-- 0247 : Fixed bus req/ack cycle
--
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use work.T80_Pack.all;
entity T80a is
generic(
Mode : integer := 0 -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
);
port(
RESET_n : in std_logic;
CLK_n : in std_logic;
WAIT_n : in std_logic;
INT_n : in std_logic;
NMI_n : in std_logic;
BUSRQ_n : in std_logic;
M1_n : out std_logic;
MREQ_n : out std_logic;
IORQ_n : out std_logic;
RD_n : out std_logic;
WR_n : out std_logic;
RFSH_n : out std_logic;
HALT_n : out std_logic;
BUSAK_n : out std_logic;
A : out std_logic_vector(15 downto 0);
D : inout std_logic_vector(7 downto 0)
);
end T80a;
architecture rtl of T80a is
signal CEN : std_logic;
signal Reset_s : std_logic;
signal IntCycle_n : std_logic;
signal IORQ : std_logic;
signal NoRead : std_logic;
signal Write : std_logic;
signal MREQ : std_logic;
signal MReq_Inhibit : std_logic;
signal Req_Inhibit : std_logic;
signal RD : std_logic;
signal MREQ_n_i : std_logic;
signal IORQ_n_i : std_logic;
signal RD_n_i : std_logic;
signal WR_n_i : std_logic;
signal RFSH_n_i : std_logic;
signal BUSAK_n_i : std_logic;
signal A_i : std_logic_vector(15 downto 0);
signal DO : std_logic_vector(7 downto 0);
signal DI_Reg : std_logic_vector (7 downto 0); -- Input synchroniser
signal Wait_s : std_logic;
signal MCycle : std_logic_vector(2 downto 0);
signal TState : std_logic_vector(2 downto 0);
begin
CEN <= '1';
BUSAK_n <= BUSAK_n_i;
MREQ_n_i <= not MREQ or (Req_Inhibit and MReq_Inhibit);
RD_n_i <= not RD or Req_Inhibit;
MREQ_n <= MREQ_n_i when BUSAK_n_i = '1' else 'Z';
IORQ_n <= IORQ_n_i when BUSAK_n_i = '1' else 'Z';
RD_n <= RD_n_i when BUSAK_n_i = '1' else 'Z';
WR_n <= WR_n_i when BUSAK_n_i = '1' else 'Z';
RFSH_n <= RFSH_n_i when BUSAK_n_i = '1' else 'Z';
A <= A_i when BUSAK_n_i = '1' else (others => 'Z');
D <= DO when Write = '1' and BUSAK_n_i = '1' else (others => 'Z');
process (RESET_n, CLK_n)
begin
if RESET_n = '0' then
Reset_s <= '0';
elsif CLK_n'event and CLK_n = '1' then
Reset_s <= '1';
end if;
end process;
u0 : T80
generic map(
Mode => Mode,
IOWait => 1)
port map(
CEN => CEN,
M1_n => M1_n,
IORQ => IORQ,
NoRead => NoRead,
Write => Write,
RFSH_n => RFSH_n_i,
HALT_n => HALT_n,
WAIT_n => Wait_s,
INT_n => INT_n,
NMI_n => NMI_n,
RESET_n => Reset_s,
BUSRQ_n => BUSRQ_n,
BUSAK_n => BUSAK_n_i,
CLK_n => CLK_n,
A => A_i,
DInst => D,
DI => DI_Reg,
DO => DO,
MC => MCycle,
TS => TState,
IntCycle_n => IntCycle_n);
process (CLK_n)
begin
if CLK_n'event and CLK_n = '0' then
Wait_s <= WAIT_n;
if TState = "011" and BUSAK_n_i = '1' then
DI_Reg <= to_x01(D);
end if;
end if;
end process;
process (Reset_s,CLK_n)
begin
if Reset_s = '0' then
WR_n_i <= '1';
elsif CLK_n'event and CLK_n = '1' then
WR_n_i <= '1';
if TState = "001" then -- To short for IO writes !!!!!!!!!!!!!!!!!!!
WR_n_i <= not Write;
end if;
end if;
end process;
process (Reset_s,CLK_n)
begin
if Reset_s = '0' then
Req_Inhibit <= '0';
elsif CLK_n'event and CLK_n = '1' then
if MCycle = "001" and TState = "010" then
Req_Inhibit <= '1';
else
Req_Inhibit <= '0';
end if;
end if;
end process;
process (Reset_s,CLK_n)
begin
if Reset_s = '0' then
MReq_Inhibit <= '0';
elsif CLK_n'event and CLK_n = '0' then
if MCycle = "001" and TState = "010" then
MReq_Inhibit <= '1';
else
MReq_Inhibit <= '0';
end if;
end if;
end process;
process(Reset_s,CLK_n)
begin
if Reset_s = '0' then
RD <= '0';
IORQ_n_i <= '1';
MREQ <= '0';
elsif CLK_n'event and CLK_n = '0' then
if MCycle = "001" then
if TState = "001" then
RD <= IntCycle_n;
MREQ <= IntCycle_n;
IORQ_n_i <= IntCycle_n;
end if;
if TState = "011" then
RD <= '0';
IORQ_n_i <= '1';
MREQ <= '1';
end if;
if TState = "100" then
MREQ <= '0';
end if;
else
if TState = "001" and NoRead = '0' then
RD <= not Write;
IORQ_n_i <= not IORQ;
MREQ <= not IORQ;
end if;
if TState = "011" then
RD <= '0';
IORQ_n_i <= '1';
MREQ <= '0';
end if;
end if;
end if;
end process;
end;

View File

@@ -0,0 +1,193 @@
-- ****
-- T80(b) core. In an effort to merge and maintain bug fixes ....
--
--
-- Ver 300 started tidyup
--
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
--
-- $Id: T80se.vhd 1330 2015-05-22 19:55:46Z wolfgang.scherr $
--
-- ****
--
-- Z80 compatible microprocessor core, synchronous top level with clock enable
-- Different timing than the original z80
-- Inputs needs to be synchronous and outputs may glitch
--
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
-- MikeJ March 2005
--
-- 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/t80/
--
-- Limitations :
--
-- File history :
--
-- 0235 : First release
--
-- 0236 : Added T2Write generic
--
-- 0237 : Fixed T2Write with wait state
--
-- 0238 : Updated for T80 interface change
--
-- 0240 : Updated for T80 interface change
--
-- 0242 : Updated for T80 interface change
--
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use work.T80_Pack.all;
entity T80se is
generic(
Mode : integer := 0; -- 0 => Z80, 1 => Fast Z80, 2 => 8080, 3 => GB
T2Write : integer := 0; -- 0 => WR_n active in T3, /=0 => WR_n active in T2
IOWait : integer := 1 -- 0 => Single cycle I/O, 1 => Std I/O cycle
);
port(
RESET_n : in std_logic;
CLK_n : in std_logic;
CLKEN : in std_logic;
WAIT_n : in std_logic;
INT_n : in std_logic;
NMI_n : in std_logic;
BUSRQ_n : in std_logic;
M1_n : out std_logic;
MREQ_n : out std_logic;
IORQ_n : out std_logic;
RD_n : out std_logic;
WR_n : out std_logic;
RFSH_n : out std_logic;
HALT_n : out std_logic;
BUSAK_n : out std_logic;
A : out std_logic_vector(15 downto 0);
DI : in std_logic_vector(7 downto 0);
DO : out std_logic_vector(7 downto 0)
);
end T80se;
architecture rtl of T80se is
signal IntCycle_n : std_logic;
signal NoRead : std_logic;
signal Write : std_logic;
signal IORQ : std_logic;
signal DI_Reg : std_logic_vector(7 downto 0);
signal MCycle : std_logic_vector(2 downto 0);
signal TState : std_logic_vector(2 downto 0);
begin
u0 : T80
generic map(
Mode => Mode,
IOWait => IOWait)
port map(
CEN => CLKEN,
M1_n => M1_n,
IORQ => IORQ,
NoRead => NoRead,
Write => Write,
RFSH_n => RFSH_n,
HALT_n => HALT_n,
WAIT_n => Wait_n,
INT_n => INT_n,
NMI_n => NMI_n,
RESET_n => RESET_n,
BUSRQ_n => BUSRQ_n,
BUSAK_n => BUSAK_n,
CLK_n => CLK_n,
A => A,
DInst => DI,
DI => DI_Reg,
DO => DO,
MC => MCycle,
TS => TState,
IntCycle_n => IntCycle_n);
process (RESET_n, CLK_n)
begin
if RESET_n = '0' then
RD_n <= '1';
WR_n <= '1';
IORQ_n <= '1';
MREQ_n <= '1';
DI_Reg <= "00000000";
elsif CLK_n'event and CLK_n = '1' then
if CLKEN = '1' then
RD_n <= '1';
WR_n <= '1';
IORQ_n <= '1';
MREQ_n <= '1';
if MCycle = "001" then
if TState = "001" or (TState = "010" and Wait_n = '0') then
RD_n <= not IntCycle_n;
MREQ_n <= not IntCycle_n;
IORQ_n <= IntCycle_n;
end if;
if TState = "011" then
MREQ_n <= '0';
end if;
else
if (TState = "001" or (TState = "010" and Wait_n = '0')) and NoRead = '0' and Write = '0' then
RD_n <= '0';
IORQ_n <= not IORQ;
MREQ_n <= IORQ;
end if;
if T2Write = 0 then
if TState = "010" and Write = '1' then
WR_n <= '0';
IORQ_n <= not IORQ;
MREQ_n <= IORQ;
end if;
else
if (TState = "001" or (TState = "010" and Wait_n = '0')) and Write = '1' then
WR_n <= '0';
IORQ_n <= not IORQ;
MREQ_n <= IORQ;
end if;
end if;
end if;
if TState = "010" and Wait_n = '1' then
DI_Reg <= DI;
end if;
end if;
end if;
end process;
end;

View File

@@ -0,0 +1,177 @@
-- ****
-- T80(b) core. In an effort to merge and maintain bug fixes ....
--
--
-- Ver 300 started tidyup
--
-- Latest version from www.fpgaarcade.com (original www.opencores.org)
--
-- $Id: T80sed.vhd 1330 2015-05-22 19:55:46Z wolfgang.scherr $
--
-- ****
--
-- ** CUSTOM 2 CLOCK MEMORY ACCESS FOR PACMAN, MIKEJ **
--
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
-- MikeJ March 2005
--
-- 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/t80/
--
-- Limitations :
--
-- File history :
--
-- 0235 : First release
--
-- 0236 : Added T2Write generic
--
-- 0237 : Fixed T2Write with wait state
--
-- 0238 : Updated for T80 interface change
--
-- 0242 : Updated for T80 interface change
--
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use work.T80_Pack.all;
entity T80sed is
port(
RESET_n : in std_logic;
CLK_n : in std_logic;
CLKEN : in std_logic;
WAIT_n : in std_logic;
INT_n : in std_logic;
NMI_n : in std_logic;
BUSRQ_n : in std_logic;
M1_n : out std_logic;
MREQ_n : out std_logic;
IORQ_n : out std_logic;
RD_n : out std_logic;
WR_n : out std_logic;
RFSH_n : out std_logic;
HALT_n : out std_logic;
BUSAK_n : out std_logic;
A : out std_logic_vector(15 downto 0);
DI : in std_logic_vector(7 downto 0);
DO : out std_logic_vector(7 downto 0)
);
end T80sed;
architecture rtl of T80sed is
signal IntCycle_n : std_logic;
signal NoRead : std_logic;
signal Write : std_logic;
signal IORQ : std_logic;
signal DI_Reg : std_logic_vector(7 downto 0);
signal MCycle : std_logic_vector(2 downto 0);
signal TState : std_logic_vector(2 downto 0);
begin
u0 : T80
generic map(
Mode => 0,
IOWait => 1)
port map(
CEN => CLKEN,
M1_n => M1_n,
IORQ => IORQ,
NoRead => NoRead,
Write => Write,
RFSH_n => RFSH_n,
HALT_n => HALT_n,
WAIT_n => Wait_n,
INT_n => INT_n,
NMI_n => NMI_n,
RESET_n => RESET_n,
BUSRQ_n => BUSRQ_n,
BUSAK_n => BUSAK_n,
CLK_n => CLK_n,
A => A,
DInst => DI,
DI => DI_Reg,
DO => DO,
MC => MCycle,
TS => TState,
IntCycle_n => IntCycle_n);
process (RESET_n, CLK_n)
begin
if RESET_n = '0' then
RD_n <= '1';
WR_n <= '1';
IORQ_n <= '1';
MREQ_n <= '1';
DI_Reg <= "00000000";
elsif CLK_n'event and CLK_n = '1' then
if CLKEN = '1' then
RD_n <= '1';
WR_n <= '1';
IORQ_n <= '1';
MREQ_n <= '1';
if MCycle = "001" then
if TState = "001" or (TState = "010" and Wait_n = '0') then
RD_n <= not IntCycle_n;
MREQ_n <= not IntCycle_n;
IORQ_n <= IntCycle_n;
end if;
if TState = "011" then
MREQ_n <= '0';
end if;
else
if (TState = "001" or TState = "010") and NoRead = '0' and Write = '0' then
RD_n <= '0';
IORQ_n <= not IORQ;
MREQ_n <= IORQ;
end if;
if ((TState = "001") or (TState = "010")) and Write = '1' then
WR_n <= '0';
IORQ_n <= not IORQ;
MREQ_n <= IORQ;
end if;
end if;
if TState = "010" and Wait_n = '1' then
DI_Reg <= DI;
end if;
end if;
end if;
end process;
end;

View File

@@ -0,0 +1,615 @@
----------------------------------------------------------------------------------
-- berzerk by Dar (darfpga@aol.fr) (June 2018)
-- http://darfpga.blogspot.fr
----------------------------------------------------------------------------------
-- Educational use only
-- Do not redistribute synthetized file with roms
-- Do not redistribute roms whatever the form
-- Use at your own risk
---------------------------------------------------------------------------------
-- T80/T80se - Version : 0304 /!\ (0247 has some interrupt vector problems)
-----------------------------
-- Z80 compatible microprocessor core
-- Copyright (c) 2001-2002 Daniel Wallner (jesus@opencores.org)
-- MikeJ March 2005
-- Wolfgang Scherr 2011-2015 (email: WoS <at> pin4 <dot> at)
---------------------------------------------------------------------------------
-- gen_ram.vhd & io_ps2_keyboard
--------------------------------
-- Copyright 2005-2008 by Peter Wendrich (pwsoft@syntiac.com)
-- http://www.syntiac.com/fpga64.html
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
-- Use berzerk_de10_lite.sdc to compile (Timequest constraints)
-- /!\
-- Don't forget to set device configuration mode with memory initialization
-- (Assignments/Device/Pin options/Configuration mode)
---------------------------------------------------------------------------------
---------------------------------------------------------------------------------
--
-- Berzerk has not graphics tile nor sprite. Instead berzerk use a 1 pixel video
-- buffer and a color map buffer.
--
-- Video buffer is 256 pixels x 224 lines : 32 x 224 bytes
--
-- Video buffer can be written by cpu @4000-5fff (normal write : cpu_do => vram_di)
-- video buffer and working ram share the same ram.
--
-- Video buffer can be written by cpu @6000-7fff
-- in that case the written cpu data can be shifted and completed with previous written data
-- then the result can be bit reversed 0..7 => 7..0 (flopper)
-- then the result can be combined (alu) with the current video data at that address
-- shift/flop and alu function are controled by data written at I/O 0x4B
-- during such write flopper output is compared with current video data to detect
-- pixel colision (called intercept)
--
-- color buffer is @8000-87ff :32x64 area of 1 byte
-- one byte covers 2x4 pixels and 4 lines.
-- bits 7-4 => 4 pixels of color1
-- bits 3-0 => 4 pixels of color2
-- color 4bits : intensity/blue/green/red
--
-- Sound effects uses a ptm6840 timer (3 channel) + noise generator and volume control
--
--
-----------------------------------------------------------------------------------------------
-- Problème rencontré : cpu_int acquitée par iorq durant le cylce de capture du vecteur
-- d'interruption => mauvais vecteur lu => plantage un peu plus tard.
--
-- Solution : ajouter m1_n dans l'equation d'acquitement de int.
-----------------------------------------------------------------------------------------------
-- Mame command reminder
-- wpiset 40,1,w,1,{printf "a:%08x d:%02X",wpaddr,wpdata; g}
-- wpiset 40,1,w,(wpdata!=0) && (wpdata!=90) && (wpdata!=92),{printf "a:%08x d:%02X",wpaddr,wpdata; g}
-----------------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity berzerk is
port(
clock_10 : in std_logic;
reset : in std_logic;
video_r : out std_logic;
video_g : out std_logic;
video_b : out std_logic;
video_hi : out std_logic;
video_clk : out std_logic;
video_csync : out std_logic;
video_hs : out std_logic;
video_vs : out std_logic;
video_hb : out std_logic;
video_vb : out std_logic;
audio_out : out std_logic_vector(15 downto 0);
start2 : in std_logic;
start1 : in std_logic;
coin1 : in std_logic;
cocktail : in std_logic;
right1 : in std_logic;
left1 : in std_logic;
down1 : in std_logic;
up1 : in std_logic;
fire1 : in std_logic;
right2 : in std_logic;
left2 : in std_logic;
down2 : in std_logic;
up2 : in std_logic;
fire2 : in std_logic;
sw : in std_logic_vector(9 downto 0);
ledr : out std_logic_vector(9 downto 0) := "0000000000";
dbg_cpu_di : out std_logic_vector( 7 downto 0);
dbg_cpu_addr : out std_logic_vector(15 downto 0);
dbg_cpu_addr_latch : out std_logic_vector(15 downto 0)
);
end berzerk;
architecture struct of berzerk is
-- clocks
signal clock_10n : std_logic;
signal reset_n : std_logic;
-- video syncs
signal hsync : std_logic;
signal vsync : std_logic;
signal csync : std_logic;
signal blank : std_logic;
-- global synchronisation
signal ena_pixel : std_logic := '0';
signal hcnt : std_logic_vector(8 downto 0);
signal vcnt : std_logic_vector(8 downto 0);
signal hcnt_r : std_logic_vector(8 downto 0);
signal vcnt_r : std_logic_vector(8 downto 0);
-- Z80 interface
signal cpu_clock : std_logic;
signal cpu_wr_n : std_logic;
signal cpu_addr : std_logic_vector(15 downto 0);
signal cpu_do : std_logic_vector(7 downto 0);
signal cpu_di : std_logic_vector(7 downto 0);
signal cpu_di_r : std_logic_vector(7 downto 0);
signal cpu_mreq_n : std_logic;
signal cpu_m1_n : std_logic;
signal cpu_int_n : std_logic := '1';
signal cpu_nmi_n : std_logic := '1';
signal cpu_iorq_n : std_logic;
signal cpu_di_mem : std_logic_vector(7 downto 0);
signal cpu_di_io : std_logic_vector(7 downto 0);
-- rom/ram addr/we/do
signal prog2_rom_addr : std_logic_vector(15 downto 0);
signal prog1_do : std_logic_vector(7 downto 0);
signal prog2_do : std_logic_vector(7 downto 0);
signal mosram_do : std_logic_vector(7 downto 0);
signal mosram_we : std_logic;
signal vram_addr : std_logic_vector(12 downto 0);
signal vram_di : std_logic_vector( 7 downto 0);
signal vram_do : std_logic_vector( 7 downto 0);
signal vram_we : std_logic;
signal cram_addr : std_logic_vector(10 downto 0);
signal cram_do : std_logic_vector(7 downto 0);
signal cram_we : std_logic;
-- I/O chip seclect
signal io1_cs : std_logic;
signal io2_cs : std_logic;
-- misc
signal int_enable : std_logic;
signal nmi_enable : std_logic;
signal inta : std_logic;
signal vcnt_int : std_logic;
signal vcnt_int_r : std_logic;
signal led_on : std_logic;
--signal intercept : std_logic;
signal intercept_latch : std_logic;
-- grapihcs computation
signal shifter_flopper_alu_cmd : std_logic_vector(7 downto 0);
signal last_data_written : std_logic_vector(6 downto 0);
signal shifter_do : std_logic_vector(7 downto 0);
signal flopper_do : std_logic_vector(7 downto 0);
signal alu_do : std_logic_vector(7 downto 0);
signal vram_do_latch : std_logic_vector(7 downto 0);
-- graphics data
signal graphx : std_logic_vector (7 downto 0);
signal colors : std_logic_vector (7 downto 0);
signal color : std_logic_vector (3 downto 0);
-- player I/O
signal player1 : std_logic_vector(7 downto 0);
signal player2 : std_logic_vector(7 downto 0);
signal system : std_logic_vector(7 downto 0);
-- line doubler I/O
signal video : std_logic_vector (3 downto 0);
signal video_i : std_logic_vector (3 downto 0);
signal video_o : std_logic_vector (3 downto 0);
signal video_s : std_logic_vector (3 downto 0);
signal hsync_o : std_logic;
signal vsync_o : std_logic;
signal sound_out : std_logic_vector(11 downto 0);
signal speech_out : std_logic_vector(11 downto 0);
signal speech_busy : std_logic;
begin
audio_out <= ("00"&speech_out&"00")+('0'&sound_out&"000");
clock_10n <= not clock_10;
reset_n <= not reset;
ledr(0) <= led_on;
----------
-- debug
----------
dbg_cpu_addr <= cpu_addr;
process(cpu_clock, reset)
begin
if rising_edge(cpu_clock) then
if cpu_m1_n = '0' then
dbg_cpu_addr_latch <= cpu_addr;
end if;
end if;
end process;
-----------------------
-- Enable pixel counter
-- and cpu clock
-----------------------
process(clock_10, reset)
begin
if reset = '1' then
ena_pixel <= '0';
else
if rising_edge(clock_10) then
ena_pixel <= not ena_pixel;
end if;
end if;
end process;
cpu_clock <= hcnt(0);
------------------
-- video output
------------------
-- demux color nibbles
color <= colors(7 downto 4) when hcnt(2) = '0' else colors(3 downto 0);
-- serialize video byte
video <= color when graphx(to_integer(unsigned(not hcnt(2 downto 0)))) = '1' else "0000";
------------------
-- player controls
------------------
player1 <= not( "000" & fire1 & down1 & up1 & right1 & left1);
player2 <= not(cocktail & "00" & fire2 & down2 & up2 & right2 & left2);
system <= not(coin1 & "00000" & start2 & start1 );
-----------------------
-- cpu write addressing
-- cpu I/O chips select
----------------------- 111110 0000000000
mosram_we <= '1' when cpu_mreq_n = '0' and cpu_wr_n = '0' and cpu_addr(15 downto 10) = "111110" else '0'; -- 0800-0bff 000010 0000000000
vram_we <= '1' when cpu_mreq_n = '0' and cpu_wr_n = '0' and cpu_addr(15 downto 14) = "01" and cpu_clock = '0' else '0'; -- 4000-5fff mirror 6000-7fff
cram_we <= '1' when cpu_mreq_n = '0' and cpu_wr_n = '0' and cpu_addr(15 downto 11) = "10000" and cpu_clock = '0' else '0'; -- 8000-87ff
io1_cs <= '1' when cpu_iorq_n ='0' and cpu_m1_n = '1' and cpu_addr(7 downto 4) = "0100" else '0'; -- x40-x4f
io2_cs <= '1' when cpu_iorq_n ='0' and cpu_m1_n = '1' and cpu_addr(7 downto 5) = "011" else '0'; -- x60-x7f
---------------------------
-- enable/disable interrupt
-- latch/clear interrupt
-- led
---------------------------
vcnt_int <= (not(vcnt(6)) and vcnt(7)) or vcnt(8);
process (cpu_clock, reset)
begin
if reset = '1' then
nmi_enable <= '0';
int_enable <= '0';
led_on <= '0';
else
if rising_edge(cpu_clock) then
if io1_cs ='1' then
if cpu_addr(3 downto 0) = "1100" then nmi_enable <= '1'; end if; -- 4c
if cpu_addr(3 downto 0) = "1101" then nmi_enable <= '0'; end if; -- 4d
if cpu_addr(3 downto 0) = "1111" and cpu_wr_n = '0' then int_enable <= cpu_do(0); end if; -- 4f
end if;
if io2_cs ='1' then
if cpu_addr(2 downto 0) = "110" then led_on <= '0'; end if; -- 66
if cpu_addr(2 downto 0) = "111" then led_on <= '1'; end if; -- 67
end if;
end if;
end if;
end process;
process (clock_10, cpu_iorq_n, cpu_addr, reset)
begin
if reset = '1' then
cpu_int_n <= '1';
cpu_nmi_n <= '1';
else
if rising_edge(clock_10) then
vcnt_r <= vcnt;
vcnt_int_r <= vcnt_int;
if nmi_enable = '1' then
if vcnt_r(4) = '0' and vcnt(4) = '1' then cpu_nmi_n <= '0';end if;
if hcnt_r(0) = '0' and hcnt(0) = '1' then cpu_nmi_n <= '1';end if;
else
cpu_nmi_n <= '1';
end if;
end if;
if rising_edge(clock_10) then
if cpu_iorq_n ='0' then
-- m1_n avoid clear interrupt during vector reading
if cpu_addr(7 downto 0) = X"4e" and cpu_m1_n = '1' then cpu_int_n <= '1'; end if;
end if;
if int_enable = '1' then
if vcnt_int_r = '0' and vcnt_int = '1' then cpu_int_n <= '0';end if;
end if;
end if;
end if;
end process;
------------------------------------
-- mux cpu data mem read and io read
------------------------------------
-- memory mux
with cpu_addr(15 downto 11) select
cpu_di_mem <=
prog1_do when "00000", -- 0000-0fff 16k 00
prog1_do when "00001", -- 0000-0fff 16k 00
prog1_do when "00010", -- 1000-1fff 16k 01
prog1_do when "00011", -- 1000-1fff 16k 01
prog1_do when "00100", -- 1000-1fff 16k 01
prog1_do when "00101", -- 2000-2fff 16k 10
prog1_do when "00110", -- 3000-3fff 16k 11
prog1_do when "00111", -- 3000-3fff 16k 11
vram_do when "01000", -- 4000-47ff
vram_do when "01001", -- 4800-4fff
vram_do when "01010", -- 5000-57ff
vram_do when "01011", -- 5800-5fff
vram_do when "01100", -- 6000-67ff
vram_do when "01101", -- 6800-6fff
vram_do when "01110", -- 7000-77ff
vram_do when "01111", -- 7800-7fff
cram_do when "10000", -- 8000-87ff 10000 00000000000
prog2_do when "11000", -- c000-c7ff 4k 11000 00000000000
prog2_do when "11001", -- c800-cfff 4k 11001 00000000000
mosram_do when "11111", -- f800-fbff 11111 00000000000
x"FF" when others;
-- I/O-2 mux
with cpu_addr(2 downto 0) select
cpu_di_io <=
X"33" when "000", -- 60 (F3)
X"F0" when "001", -- 61 (F2)
X"01" when "010", -- 62 (F6)
X"01" when "011", -- 63 (F5)
X"01" when "100", -- 64 (F4)
X"00" when "101", -- 65 (SW2)
X"00" when "110", -- 66 (led on )
X"00" when "111", -- 67 (led off)
X"00" when others;
-- I/O-1 and final mux
-- pull up on ZPU board
cpu_di <= "111111" & cpu_int_n & '0' when cpu_iorq_n = '0' and cpu_m1_n = '0' -- interrupt vector
else '0'&not(speech_busy)&"000000" when io1_cs = '1' and cpu_addr(3 downto 0) = X"4" -- speech board
else player1 when io1_cs = '1' and cpu_addr(3 downto 0) = X"8" -- P1
else system when io1_cs = '1' and cpu_addr(3 downto 0) = X"9" -- sys
else player2 when io1_cs = '1' and cpu_addr(3 downto 0) = X"a" -- P2
else intercept_latch & "111111" & vcnt(8) when io1_cs = '1' and cpu_addr(3 downto 0) = X"e"
else cpu_di_io when io2_cs = '1'
else cpu_di_mem;
-- video memory computation
process(clock_10, reset)
begin
if reset = '1' then
shifter_flopper_alu_cmd <= (others => '0');
else
if rising_edge(clock_10) then
if cpu_clock = '0' and ena_pixel = '1' then
vram_do_latch <= vram_do;
end if;
if vram_we = '1' and cpu_addr(13) = '1' then
if ena_pixel = '1' then
last_data_written <= cpu_do(6 downto 0);
if (vram_do_latch and flopper_do) /= X"00" then
intercept_latch <= '1';
end if;
end if;
end if;
if io1_cs = '1' then
if cpu_addr(3 downto 0) = "1011" then -- 4b
shifter_flopper_alu_cmd <= cpu_do;
last_data_written <= (others => '0');
intercept_latch <= '0';
end if;
end if;
end if;
end if;
end process;
-- shifter - flopper
with shifter_flopper_alu_cmd(2 downto 0) select
shifter_do <= cpu_do(7 downto 0) when "000",
last_data_written( 0) & cpu_do(7 downto 1) when "001",
last_data_written(1 downto 0) & cpu_do(7 downto 2) when "010",
last_data_written(2 downto 0) & cpu_do(7 downto 3) when "011",
last_data_written(3 downto 0) & cpu_do(7 downto 4) when "100",
last_data_written(4 downto 0) & cpu_do(7 downto 5) when "101",
last_data_written(5 downto 0) & cpu_do(7 downto 6) when "110",
last_data_written(6 downto 0) & cpu_do(7 ) when others;
with shifter_flopper_alu_cmd(3) select
flopper_do <= shifter_do when '0',
shifter_do(0)&shifter_do(1)&shifter_do(2)&shifter_do(3)&
shifter_do(4)&shifter_do(5)&shifter_do(6)&shifter_do(7) when others;
-- 74181 - alu (logical computation only)
with not(shifter_flopper_alu_cmd(7 downto 4)) select
alu_do <= not flopper_do when "0000",
not(flopper_do or vram_do_latch) when "0001",
not(flopper_do) and vram_do_latch when "0010",
X"00" when "0011",
not(flopper_do and vram_do_latch) when "0100",
not(vram_do_latch) when "0101",
flopper_do xor vram_do_latch when "0110",
flopper_do and not(vram_do_latch) when "0111",
not(flopper_do) or vram_do_latch when "1000",
not(flopper_do xor vram_do_latch) when "1001",
vram_do_latch when "1010",
flopper_do and vram_do_latch when "1011",
X"FF" when "1100",
flopper_do or not(vram_do_latch) when "1101",
flopper_do or vram_do_latch when "1110",
flopper_do when others;
------------------------------------------------------
-- video & color ram address/data mux
------------------------------------------------------
with cpu_addr(13) select
vram_di <= cpu_do when '0',
alu_do when others;
vram_addr <= cpu_addr(12 downto 0) when cpu_clock = '0'
else vcnt(7 downto 0) & hcnt(7 downto 3);
cram_addr <= cpu_addr(10 downto 0) when cpu_clock = '0'
else vcnt(7 downto 2) & hcnt(7 downto 3);
-------------------------------------------------------
-- video & color ram read
-------------------------------------------------------
process(clock_10)
begin
if rising_edge(clock_10) then
if hcnt(2 downto 0) = "111" and ena_pixel = '1' then
graphx <= vram_do;
colors <= cram_do;
end if;
end if;
end process;
-- Sync and video counters
video_gen : entity work.video_gen
port map (
clock => clock_10,
reset => reset,
ena_pixel => ena_pixel,
hsync => hsync,
vsync => vsync,
csync => csync,
hblank => video_hb,
vblank => video_vb,
hcnt_o => hcnt,
vcnt_o => vcnt
);
video_s <= video;
video_hs <= hsync;
video_vs <= vsync;
video_r <= video_s(0);
video_g <= video_s(1);
video_b <= video_s(2);
video_hi <= video_s(3);
video_clk <= clock_10;
video_csync <= csync;
-- Z80
Z80 : entity work.T80se
generic map(Mode => 0, T2Write => 1, IOWait => 1)
port map(
RESET_n => reset_n,
CLK_n => cpu_clock,
CLKEN => '1',
WAIT_n => '1',
INT_n => cpu_int_n,
NMI_n => cpu_nmi_n,
BUSRQ_n => '1',
M1_n => cpu_m1_n,
MREQ_n => cpu_mreq_n,
IORQ_n => cpu_iorq_n,
RD_n => open,
WR_n => cpu_wr_n,
RFSH_n => open,
HALT_n => open,
BUSAK_n => open,
A => cpu_addr,
DI => cpu_di,
DO => cpu_do
);
-- program roms
program1 : entity work.berzerk_program1
port map (
addr => cpu_addr(13 downto 0),
clk => clock_10n,
data => prog1_do
);
prog2_rom_addr <= cpu_addr-X"c000";
program2 : entity work.berzerk_program2
port map (
addr => cpu_addr(11 downto 0),
clk => clock_10n,
data => prog2_do
);
-- working ram - 0800-0bff
mosram : entity work.gen_ram
generic map( dWidth => 8, aWidth => 10)
port map(
clk => clock_10n,
we => mosram_we,
addr => cpu_addr( 9 downto 0),
d => cpu_do,
q => mosram_do
);
-- video/working ram - 4000-5fff mirrored 6000-7fff
vram : entity work.gen_ram
generic map( dWidth => 8, aWidth => 13)
port map(
clk => clock_10n,
we => vram_we,
addr => vram_addr,
d => vram_di,
q => vram_do
);
-- color ram - 8000-87ff
cram : entity work.gen_ram
generic map( dWidth => 8, aWidth => 11)
port map(
clk => clock_10n,
we => cram_we,
addr => cram_addr,
d => cpu_do,
q => cram_do
);
-- sound effects
berzerk_sound_fx : entity work.berzerk_sound_fx
port map(
clock => cpu_clock,
reset => reset,
cs => io1_cs,
addr => cpu_addr(4 downto 0),
di => cpu_do,
sample => sound_out
);
-- speech synthesis (s14001a)
berzerk_speech : entity work.berzerk_speech
port map(
sw => sw,
clock => cpu_clock,
reset => reset,
cs => io1_cs,
wr_n => cpu_wr_n,
addr => cpu_addr(4 downto 0),
di => cpu_do,
busy => speech_busy,
sample => speech_out
);
------------------------------------------
end architecture;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,278 @@
library ieee;
use ieee.std_logic_1164.all,ieee.numeric_std.all;
entity berzerk_program2 is
port (
clk : in std_logic;
addr : in std_logic_vector(11 downto 0);
data : out std_logic_vector(7 downto 0)
);
end entity;
architecture prom of berzerk_program2 is
type rom is array(0 to 4095) of std_logic_vector(7 downto 0);
signal rom_data: rom := (
X"07",X"01",X"0B",X"3C",X"7E",X"C7",X"D7",X"C7",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"0B",
X"3C",X"7E",X"E3",X"EB",X"E3",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"0B",X"3C",X"7E",X"F1",
X"F5",X"F1",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"0B",X"3C",X"7E",X"F8",X"FA",X"F8",X"7E",
X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"0B",X"3C",X"7E",X"FC",X"FD",X"FC",X"7E",X"3C",X"DB",X"7E",
X"FF",X"5A",X"01",X"0B",X"3C",X"7E",X"FF",X"FF",X"FF",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",
X"0B",X"3C",X"7E",X"3F",X"BF",X"3F",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"0B",X"3C",X"7E",
X"1F",X"5F",X"1F",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"0B",X"3C",X"7E",X"8F",X"AF",X"8F",
X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"0B",X"3C",X"7E",X"F1",X"F5",X"F1",X"7E",X"3C",X"DB",
X"7E",X"FF",X"5A",X"01",X"0B",X"3C",X"7E",X"F1",X"F5",X"F1",X"7E",X"3C",X"6D",X"FF",X"FE",X"36",
X"01",X"0B",X"3C",X"7E",X"F1",X"F5",X"F1",X"7E",X"3C",X"B6",X"FF",X"7F",X"6C",X"01",X"0B",X"3C",
X"7E",X"8F",X"AF",X"8F",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"0B",X"3C",X"7E",X"8F",X"AF",
X"8F",X"7E",X"3C",X"B6",X"FF",X"7F",X"6C",X"01",X"0B",X"3C",X"7E",X"8F",X"AF",X"8F",X"7E",X"3C",
X"6D",X"FF",X"FE",X"36",X"01",X"0B",X"3C",X"7E",X"FF",X"FF",X"FF",X"7E",X"3C",X"FF",X"1F",X"F8",
X"E7",X"01",X"0B",X"3C",X"7E",X"FF",X"FF",X"FF",X"7E",X"3C",X"1F",X"F8",X"FF",X"07",X"01",X"0B",
X"3C",X"7E",X"FF",X"FF",X"FF",X"7E",X"3C",X"F8",X"FF",X"1F",X"E0",X"01",X"0B",X"3C",X"7E",X"FF",
X"C7",X"D7",X"46",X"3C",X"FF",X"1F",X"F8",X"E7",X"01",X"0B",X"3C",X"7E",X"FF",X"C7",X"D7",X"46",
X"3C",X"F8",X"FF",X"1F",X"E0",X"01",X"0B",X"3C",X"7E",X"FF",X"C7",X"D7",X"46",X"3C",X"1F",X"F8",
X"FF",X"07",X"02",X"11",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",
X"03",X"C0",X"07",X"E0",X"0F",X"78",X"13",X"C8",X"0A",X"D0",X"03",X"40",X"33",X"CC",X"09",X"F0",
X"02",X"48",X"1E",X"78",X"06",X"60",X"02",X"11",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",
X"03",X"C0",X"06",X"60",X"12",X"48",X"08",X"90",X"10",X"08",X"22",X"44",X"24",X"48",X"0A",X"90",
X"13",X"60",X"08",X"18",X"14",X"20",X"02",X"40",X"06",X"60",X"02",X"13",X"00",X"00",X"02",X"00",
X"00",X"20",X"01",X"08",X"10",X"00",X"02",X"40",X"20",X"12",X"08",X"01",X"80",X"20",X"08",X"82",
X"40",X"02",X"04",X"10",X"21",X"00",X"08",X"04",X"20",X"02",X"04",X"08",X"20",X"20",X"10",X"08",
X"18",X"0C",X"01",X"01",X"00",X"00",X"82",X"01",X"02",X"18",X"18",X"00",X"82",X"01",X"03",X"10",
X"38",X"10",X"00",X"82",X"01",X"04",X"10",X"38",X"38",X"10",X"00",X"82",X"01",X"05",X"18",X"3C",
X"3C",X"3C",X"18",X"00",X"82",X"01",X"06",X"38",X"7C",X"7C",X"7C",X"7C",X"38",X"00",X"82",X"01",
X"07",X"38",X"7C",X"FE",X"FE",X"FE",X"7C",X"1C",X"00",X"82",X"01",X"08",X"18",X"7E",X"5A",X"FF",
X"FF",X"7E",X"7E",X"18",X"00",X"81",X"01",X"0A",X"18",X"7E",X"7E",X"DB",X"FF",X"BD",X"DB",X"66",
X"7E",X"18",X"80",X"80",X"01",X"0A",X"18",X"7E",X"7E",X"DB",X"FF",X"BD",X"DB",X"66",X"7E",X"18",
X"40",X"80",X"01",X"0A",X"18",X"7E",X"7E",X"DB",X"FF",X"BD",X"DB",X"66",X"7E",X"18",X"01",X"0A",
X"18",X"7E",X"7E",X"DB",X"FF",X"BD",X"DB",X"66",X"7E",X"18",X"00",X"82",X"01",X"09",X"00",X"00",
X"00",X"3C",X"5A",X"FF",X"FF",X"C3",X"7E",X"00",X"81",X"01",X"0A",X"18",X"7E",X"7E",X"DB",X"FF",
X"FF",X"C3",X"7E",X"7E",X"18",X"80",X"80",X"01",X"0A",X"18",X"7E",X"7E",X"DB",X"FF",X"FF",X"C3",
X"7E",X"7E",X"18",X"40",X"80",X"01",X"0A",X"18",X"7E",X"7E",X"DB",X"FF",X"FF",X"C3",X"7E",X"7E",
X"18",X"01",X"0A",X"18",X"7E",X"7E",X"DB",X"FF",X"FF",X"C3",X"7E",X"7E",X"18",X"00",X"81",X"01",
X"0A",X"18",X"7E",X"7E",X"DB",X"FF",X"FF",X"E7",X"5A",X"7E",X"18",X"80",X"80",X"01",X"0A",X"18",
X"7E",X"7E",X"DB",X"FF",X"FF",X"E7",X"5A",X"7E",X"18",X"40",X"80",X"01",X"0A",X"18",X"7E",X"7E",
X"DB",X"FF",X"FF",X"E7",X"5A",X"7E",X"18",X"01",X"0A",X"18",X"7E",X"7E",X"DB",X"FF",X"FF",X"E7",
X"5A",X"7E",X"18",X"00",X"82",X"01",X"09",X"00",X"00",X"00",X"00",X"00",X"3C",X"5A",X"C3",X"FF",
X"00",X"82",X"01",X"09",X"00",X"00",X"00",X"00",X"00",X"00",X"3C",X"5A",X"FF",X"00",X"82",X"01",
X"09",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"3C",X"FF",X"00",X"82",X"01",X"09",X"00",X"00",
X"00",X"00",X"00",X"00",X"00",X"00",X"FF",X"01",X"10",X"18",X"18",X"00",X"3C",X"5A",X"5A",X"5A",
X"18",X"18",X"18",X"18",X"18",X"18",X"18",X"1C",X"18",X"01",X"10",X"18",X"18",X"00",X"3C",X"5A",
X"9A",X"59",X"18",X"18",X"24",X"22",X"41",X"41",X"81",X"81",X"C0",X"01",X"10",X"00",X"18",X"18",
X"00",X"3C",X"5C",X"5A",X"3A",X"18",X"18",X"14",X"12",X"F2",X"82",X"02",X"03",X"01",X"10",X"18",
X"18",X"00",X"3C",X"3C",X"3C",X"1A",X"18",X"18",X"0C",X"0A",X"0F",X"78",X"48",X"08",X"0C",X"01",
X"10",X"18",X"18",X"00",X"3C",X"5A",X"59",X"9A",X"18",X"18",X"24",X"44",X"82",X"82",X"81",X"81",
X"03",X"01",X"10",X"00",X"18",X"18",X"00",X"3C",X"3A",X"3A",X"DC",X"18",X"18",X"28",X"48",X"4F",
X"41",X"40",X"80",X"01",X"10",X"18",X"18",X"00",X"3C",X"3C",X"3C",X"58",X"18",X"18",X"30",X"50",
X"F0",X"1E",X"12",X"10",X"30",X"01",X"10",X"00",X"18",X"18",X"00",X"3C",X"5A",X"5A",X"5A",X"18",
X"18",X"18",X"18",X"18",X"18",X"18",X"3C",X"01",X"11",X"18",X"24",X"24",X"42",X"81",X"81",X"81",
X"81",X"81",X"42",X"24",X"24",X"24",X"24",X"24",X"42",X"3C",X"01",X"11",X"18",X"24",X"24",X"7E",
X"C3",X"A5",X"A5",X"A5",X"E7",X"66",X"24",X"24",X"24",X"24",X"66",X"42",X"3C",X"01",X"11",X"3C",
X"3C",X"3C",X"7E",X"FF",X"FF",X"FF",X"FF",X"FF",X"7E",X"3C",X"3C",X"3C",X"3C",X"7E",X"7E",X"7E",
X"01",X"0F",X"18",X"19",X"02",X"1C",X"18",X"18",X"18",X"18",X"18",X"18",X"18",X"18",X"18",X"18",
X"1C",X"01",X"0F",X"18",X"18",X"00",X"1F",X"18",X"18",X"18",X"18",X"18",X"18",X"18",X"18",X"18",
X"18",X"1C",X"01",X"0F",X"18",X"18",X"00",X"18",X"18",X"1C",X"1A",X"18",X"18",X"18",X"18",X"18",
X"18",X"18",X"1C",X"01",X"0F",X"18",X"18",X"00",X"3C",X"3C",X"3A",X"3A",X"3A",X"18",X"18",X"18",
X"18",X"18",X"18",X"1C",X"01",X"0F",X"18",X"18",X"00",X"3C",X"3C",X"5C",X"9C",X"1C",X"18",X"18",
X"18",X"18",X"18",X"18",X"38",X"01",X"0F",X"18",X"18",X"00",X"F8",X"18",X"18",X"18",X"18",X"18",
X"18",X"18",X"18",X"18",X"18",X"38",X"01",X"0F",X"98",X"58",X"20",X"18",X"18",X"18",X"18",X"18",
X"18",X"18",X"18",X"18",X"18",X"18",X"38",X"01",X"0F",X"18",X"18",X"00",X"1D",X"1B",X"19",X"18",
X"18",X"18",X"18",X"18",X"18",X"18",X"18",X"1C",X"00",X"3E",X"41",X"5D",X"51",X"5D",X"41",X"3E",
X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"10",X"10",X"10",X"10",X"10",X"10",
X"10",X"00",X"10",X"14",X"14",X"14",X"00",X"00",X"00",X"00",X"00",X"00",X"14",X"14",X"14",X"7F",
X"14",X"7F",X"14",X"14",X"14",X"14",X"7F",X"54",X"54",X"7F",X"15",X"15",X"7F",X"14",X"20",X"51",
X"22",X"04",X"08",X"10",X"22",X"45",X"02",X"00",X"18",X"24",X"28",X"10",X"29",X"46",X"46",X"39",
X"08",X"08",X"08",X"00",X"00",X"00",X"00",X"00",X"00",X"04",X"08",X"10",X"10",X"10",X"10",X"10",
X"08",X"04",X"10",X"08",X"04",X"04",X"04",X"04",X"04",X"08",X"10",X"00",X"00",X"08",X"2A",X"1C",
X"1C",X"2A",X"08",X"00",X"00",X"00",X"08",X"08",X"3E",X"08",X"08",X"00",X"00",X"80",X"00",X"00",
X"00",X"18",X"18",X"08",X"10",X"00",X"00",X"00",X"00",X"00",X"3E",X"00",X"00",X"00",X"00",X"00",
X"00",X"00",X"00",X"00",X"00",X"00",X"18",X"18",X"00",X"00",X"01",X"02",X"04",X"08",X"10",X"20",
X"40",X"1C",X"22",X"41",X"41",X"41",X"41",X"41",X"22",X"1C",X"08",X"18",X"08",X"08",X"08",X"08",
X"08",X"08",X"1C",X"3E",X"41",X"01",X"01",X"3E",X"40",X"40",X"40",X"7F",X"3E",X"41",X"01",X"01",
X"1E",X"01",X"01",X"41",X"3E",X"02",X"06",X"0A",X"12",X"22",X"7F",X"02",X"02",X"02",X"7F",X"40",
X"40",X"40",X"7E",X"01",X"01",X"41",X"3E",X"3E",X"41",X"40",X"40",X"7E",X"41",X"41",X"41",X"3E",
X"7F",X"01",X"02",X"02",X"04",X"04",X"08",X"08",X"08",X"3E",X"41",X"41",X"41",X"3E",X"41",X"41",
X"41",X"3E",X"3E",X"41",X"41",X"41",X"3F",X"01",X"01",X"41",X"3E",X"00",X"00",X"00",X"18",X"18",
X"00",X"00",X"18",X"18",X"98",X"18",X"00",X"00",X"18",X"18",X"08",X"10",X"00",X"02",X"04",X"08",
X"10",X"20",X"10",X"08",X"04",X"02",X"00",X"00",X"00",X"3E",X"00",X"3E",X"00",X"00",X"00",X"20",
X"10",X"08",X"04",X"02",X"04",X"08",X"10",X"20",X"1C",X"22",X"02",X"02",X"04",X"08",X"08",X"00",
X"08",X"3E",X"41",X"4F",X"49",X"49",X"4F",X"40",X"40",X"3F",X"3E",X"41",X"41",X"41",X"7F",X"41",
X"41",X"41",X"41",X"7E",X"41",X"41",X"41",X"7E",X"41",X"41",X"41",X"7E",X"3E",X"41",X"40",X"40",
X"40",X"40",X"40",X"41",X"3E",X"7E",X"41",X"41",X"41",X"41",X"41",X"41",X"41",X"7E",X"7F",X"40",
X"40",X"40",X"7C",X"40",X"40",X"40",X"7F",X"7F",X"40",X"40",X"40",X"7C",X"40",X"40",X"40",X"40",
X"3E",X"41",X"40",X"40",X"47",X"41",X"41",X"41",X"3F",X"41",X"41",X"41",X"41",X"7F",X"41",X"41",
X"41",X"41",X"1C",X"08",X"08",X"08",X"08",X"08",X"08",X"08",X"1C",X"01",X"01",X"01",X"01",X"01",
X"01",X"01",X"41",X"3E",X"41",X"42",X"44",X"48",X"50",X"68",X"44",X"42",X"41",X"40",X"40",X"40",
X"40",X"40",X"40",X"40",X"40",X"7F",X"41",X"63",X"55",X"49",X"41",X"41",X"41",X"41",X"41",X"41",
X"61",X"51",X"49",X"45",X"43",X"41",X"41",X"41",X"3E",X"41",X"41",X"41",X"41",X"41",X"41",X"41",
X"3E",X"7E",X"41",X"41",X"41",X"7E",X"40",X"40",X"40",X"40",X"3E",X"41",X"41",X"41",X"41",X"41",
X"45",X"42",X"3D",X"7E",X"41",X"41",X"41",X"7E",X"48",X"44",X"42",X"41",X"3E",X"41",X"40",X"40",
X"3E",X"01",X"01",X"41",X"3E",X"7F",X"08",X"08",X"08",X"08",X"08",X"08",X"08",X"08",X"41",X"41",
X"41",X"41",X"41",X"41",X"41",X"41",X"3E",X"41",X"41",X"41",X"22",X"22",X"14",X"14",X"08",X"08",
X"41",X"41",X"41",X"41",X"41",X"49",X"55",X"63",X"41",X"41",X"41",X"22",X"14",X"08",X"14",X"22",
X"41",X"41",X"41",X"41",X"22",X"14",X"08",X"08",X"08",X"08",X"08",X"7F",X"01",X"02",X"04",X"08",
X"10",X"20",X"40",X"7F",X"3C",X"20",X"20",X"20",X"20",X"20",X"20",X"20",X"3C",X"00",X"00",X"40",
X"20",X"10",X"08",X"04",X"02",X"01",X"3C",X"04",X"04",X"04",X"04",X"04",X"04",X"04",X"3C",X"08",
X"14",X"22",X"41",X"00",X"00",X"00",X"00",X"00",X"80",X"00",X"00",X"00",X"00",X"00",X"FF",X"00",
X"00",X"18",X"18",X"10",X"08",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"00",X"3A",X"46",X"42",
X"42",X"46",X"3A",X"40",X"40",X"40",X"5C",X"62",X"42",X"42",X"62",X"5C",X"00",X"00",X"00",X"3C",
X"42",X"40",X"40",X"42",X"3C",X"02",X"02",X"02",X"3A",X"46",X"42",X"42",X"46",X"3A",X"00",X"00",
X"00",X"3C",X"42",X"7E",X"40",X"40",X"3C",X"0C",X"12",X"10",X"10",X"38",X"10",X"10",X"10",X"10",
X"BA",X"46",X"42",X"42",X"46",X"3A",X"02",X"42",X"3C",X"40",X"40",X"40",X"7C",X"42",X"42",X"42",
X"42",X"42",X"00",X"08",X"00",X"08",X"08",X"08",X"08",X"08",X"08",X"84",X"04",X"04",X"04",X"04",
X"04",X"04",X"44",X"38",X"40",X"40",X"40",X"44",X"48",X"50",X"70",X"48",X"44",X"10",X"10",X"10",
X"10",X"10",X"10",X"10",X"10",X"10",X"00",X"00",X"00",X"76",X"49",X"49",X"49",X"49",X"49",X"00",
X"00",X"00",X"7C",X"42",X"42",X"42",X"42",X"42",X"00",X"00",X"00",X"3C",X"42",X"42",X"42",X"42",
X"3C",X"DC",X"62",X"42",X"42",X"62",X"5C",X"40",X"40",X"40",X"BA",X"46",X"42",X"42",X"46",X"3A",
X"02",X"02",X"02",X"00",X"00",X"00",X"5C",X"62",X"40",X"40",X"40",X"40",X"00",X"00",X"00",X"3C",
X"42",X"30",X"0C",X"42",X"3C",X"00",X"10",X"10",X"7C",X"10",X"10",X"10",X"10",X"10",X"00",X"00",
X"00",X"42",X"42",X"42",X"42",X"42",X"3C",X"00",X"00",X"00",X"44",X"44",X"44",X"44",X"28",X"10",
X"00",X"00",X"00",X"41",X"41",X"41",X"49",X"49",X"36",X"00",X"00",X"00",X"42",X"24",X"18",X"18",
X"24",X"42",X"C2",X"42",X"42",X"42",X"46",X"3A",X"02",X"42",X"3C",X"00",X"00",X"00",X"7E",X"04",
X"08",X"10",X"20",X"7E",X"0C",X"10",X"10",X"10",X"20",X"10",X"10",X"10",X"0C",X"08",X"08",X"08",
X"00",X"00",X"08",X"08",X"08",X"00",X"18",X"04",X"04",X"04",X"02",X"04",X"04",X"04",X"18",X"08",
X"00",X"1C",X"2A",X"08",X"08",X"14",X"22",X"00",X"55",X"2A",X"55",X"2A",X"55",X"2A",X"55",X"2A",
X"55",X"08",X"00",X"1C",X"2A",X"08",X"08",X"14",X"22",X"00",X"02",X"28",X"00",X"0F",X"00",X"3F",
X"00",X"FF",X"01",X"FF",X"03",X"FF",X"07",X"FF",X"0F",X"FF",X"1F",X"FF",X"1F",X"FF",X"3F",X"FF",
X"3F",X"FF",X"7F",X"FF",X"7F",X"FF",X"7F",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"7F",X"FF",X"7F",X"FF",X"7F",X"FF",X"3F",X"FF",X"3F",X"FF",X"1F",X"FF",X"1F",X"FF",X"0F",X"FF",
X"07",X"FF",X"03",X"FF",X"01",X"FF",X"00",X"FF",X"00",X"3F",X"00",X"0F",X"02",X"28",X"F0",X"00",
X"FC",X"00",X"FF",X"00",X"FF",X"80",X"FF",X"C0",X"FF",X"E0",X"FF",X"F0",X"FF",X"F8",X"FF",X"F8",
X"FF",X"FC",X"FF",X"FC",X"FF",X"FE",X"FF",X"FE",X"FF",X"FE",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FE",X"FF",X"FE",X"FF",X"FE",X"FF",X"FC",X"FF",X"FC",X"FF",X"F8",X"FF",X"F8",
X"FF",X"F0",X"FF",X"E0",X"FF",X"C0",X"FF",X"80",X"FF",X"00",X"FC",X"00",X"F0",X"00",X"01",X"0C",
X"20",X"30",X"18",X"0C",X"06",X"03",X"70",X"F8",X"C8",X"C8",X"F8",X"70",X"01",X"0C",X"04",X"0C",
X"18",X"30",X"60",X"C0",X"0E",X"1F",X"13",X"13",X"1F",X"0E",X"02",X"07",X"00",X"03",X"00",X"1F",
X"00",X"3C",X"00",X"60",X"00",X"C0",X"01",X"80",X"01",X"00",X"02",X"07",X"C0",X"00",X"F8",X"00",
X"3C",X"00",X"06",X"00",X"03",X"00",X"01",X"80",X"00",X"80",X"02",X"07",X"01",X"00",X"01",X"80",
X"00",X"C0",X"00",X"60",X"00",X"3C",X"00",X"1F",X"00",X"03",X"02",X"07",X"00",X"80",X"01",X"80",
X"03",X"00",X"06",X"00",X"3C",X"00",X"F8",X"00",X"C0",X"00",X"02",X"02",X"FF",X"FF",X"FF",X"FF",
X"02",X"08",X"00",X"30",X"00",X"78",X"00",X"CC",X"01",X"86",X"00",X"00",X"00",X"00",X"00",X"00",
X"03",X"F0",X"02",X"08",X"0C",X"00",X"1E",X"00",X"33",X"00",X"61",X"80",X"00",X"00",X"00",X"00",
X"00",X"00",X"0F",X"C0",X"01",X"0B",X"F8",X"F8",X"98",X"68",X"68",X"08",X"68",X"68",X"68",X"F8",
X"F8",X"02",X"06",X"00",X"00",X"FF",X"00",X"02",X"80",X"07",X"80",X"02",X"80",X"FF",X"00",X"02",
X"06",X"60",X"00",X"FF",X"00",X"05",X"80",X"02",X"80",X"05",X"80",X"FF",X"00",X"02",X"06",X"06",
X"00",X"FF",X"00",X"02",X"80",X"07",X"80",X"02",X"80",X"FF",X"00",X"02",X"06",X"00",X"00",X"FF",
X"60",X"05",X"B0",X"02",X"80",X"05",X"80",X"FF",X"00",X"02",X"06",X"00",X"00",X"FF",X"00",X"02",
X"B0",X"07",X"98",X"02",X"80",X"FF",X"00",X"02",X"06",X"00",X"00",X"FF",X"00",X"05",X"80",X"02",
X"80",X"05",X"98",X"FF",X"0C",X"02",X"08",X"00",X"00",X"FF",X"00",X"02",X"80",X"07",X"80",X"02",
X"80",X"FF",X"00",X"00",X"0C",X"00",X"06",X"02",X"06",X"00",X"00",X"FF",X"00",X"05",X"80",X"02",
X"80",X"05",X"80",X"FF",X"00",X"01",X"17",X"30",X"78",X"FC",X"FC",X"FC",X"8C",X"B4",X"B4",X"8C",
X"B4",X"B4",X"8C",X"FC",X"FC",X"78",X"30",X"30",X"78",X"30",X"34",X"3F",X"1F",X"04",X"02",X"1D",
X"3F",X"FC",X"1F",X"F8",X"0F",X"F0",X"07",X"E0",X"FF",X"FF",X"80",X"01",X"93",X"29",X"AA",X"B9",
X"BB",X"39",X"AA",X"A9",X"AA",X"A9",X"80",X"01",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"01",X"09",X"00",X"00",X"00",X"00",
X"C0",X"40",X"40",X"40",X"78",X"01",X"08",X"00",X"00",X"00",X"00",X"C0",X"40",X"40",X"78",X"01",
X"05",X"00",X"00",X"00",X"00",X"F8",X"01",X"05",X"00",X"78",X"40",X"40",X"C0",X"01",X"05",X"78",
X"40",X"40",X"40",X"C0",X"01",X"05",X"04",X"04",X"FC",X"04",X"04",X"01",X"05",X"02",X"0C",X"74",
X"84",X"08",X"01",X"05",X"02",X"1A",X"24",X"C8",X"08",X"01",X"05",X"09",X"12",X"24",X"48",X"90",
X"01",X"05",X"10",X"13",X"24",X"58",X"40",X"01",X"05",X"10",X"21",X"2E",X"30",X"40",X"01",X"05",
X"20",X"20",X"3F",X"20",X"20",X"01",X"05",X"40",X"30",X"2E",X"21",X"10",X"01",X"05",X"40",X"58",
X"24",X"13",X"10",X"01",X"05",X"90",X"48",X"24",X"12",X"09",X"01",X"05",X"08",X"C8",X"24",X"1A",
X"02",X"01",X"05",X"08",X"84",X"74",X"0C",X"02",X"01",X"01",X"5A",X"01",X"02",X"FF",X"5A",X"01",
X"03",X"7E",X"FF",X"5A",X"01",X"04",X"DB",X"7E",X"FF",X"5A",X"01",X"05",X"3C",X"DB",X"7E",X"FF",
X"5A",X"01",X"06",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"07",X"FF",X"7E",X"3C",X"DB",X"7E",
X"FF",X"5A",X"01",X"08",X"EF",X"FF",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"09",X"FF",X"EF",
X"FF",X"7E",X"3C",X"DB",X"7E",X"FF",X"5A",X"01",X"0A",X"7E",X"FF",X"EF",X"FF",X"7E",X"3C",X"DB",
X"7E",X"FF",X"5A",X"01",X"10",X"38",X"54",X"7C",X"28",X"38",X"10",X"7C",X"92",X"BA",X"92",X"38",
X"10",X"38",X"28",X"28",X"6C",X"01",X"10",X"38",X"54",X"7C",X"28",X"38",X"10",X"7C",X"92",X"BA",
X"90",X"38",X"10",X"38",X"28",X"68",X"0C",X"01",X"10",X"38",X"54",X"7C",X"28",X"38",X"10",X"7C",
X"92",X"BA",X"12",X"38",X"10",X"38",X"28",X"2C",X"60",X"01",X"10",X"38",X"7C",X"7C",X"38",X"38",
X"10",X"7C",X"92",X"BA",X"92",X"38",X"10",X"38",X"28",X"28",X"6C",X"01",X"10",X"38",X"7C",X"7C",
X"38",X"38",X"10",X"7C",X"92",X"BA",X"12",X"38",X"10",X"38",X"28",X"2C",X"60",X"01",X"10",X"38",
X"7C",X"7C",X"38",X"38",X"10",X"7C",X"92",X"BA",X"90",X"38",X"10",X"38",X"28",X"68",X"0C",X"01",
X"10",X"38",X"74",X"7C",X"30",X"38",X"10",X"7C",X"92",X"BA",X"92",X"38",X"10",X"38",X"28",X"28",
X"3C",X"01",X"10",X"38",X"74",X"7C",X"30",X"38",X"10",X"7C",X"92",X"BA",X"92",X"38",X"10",X"7C",
X"44",X"44",X"66",X"01",X"10",X"38",X"74",X"7C",X"30",X"38",X"10",X"7C",X"92",X"BA",X"92",X"38",
X"10",X"10",X"10",X"10",X"18",X"01",X"10",X"38",X"5C",X"7C",X"18",X"38",X"10",X"7C",X"92",X"BA",
X"92",X"38",X"10",X"38",X"28",X"28",X"78",X"01",X"10",X"38",X"5C",X"7C",X"18",X"38",X"10",X"7C",
X"92",X"BA",X"92",X"38",X"10",X"7C",X"44",X"44",X"CC",X"01",X"10",X"38",X"5C",X"7C",X"18",X"38",
X"10",X"7C",X"92",X"BA",X"92",X"38",X"10",X"10",X"10",X"10",X"30",X"02",X"1E",X"80",X"00",X"80",
X"00",X"80",X"00",X"80",X"07",X"80",X"08",X"80",X"10",X"80",X"20",X"80",X"20",X"80",X"20",X"80",
X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",
X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",X"20",X"80",
X"20",X"40",X"40",X"40",X"40",X"20",X"80",X"1F",X"00",X"02",X"1E",X"00",X"01",X"00",X"01",X"00",
X"01",X"E0",X"01",X"10",X"01",X"08",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",
X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",
X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"04",X"01",X"02",
X"02",X"02",X"02",X"01",X"04",X"00",X"F8",X"01",X"08",X"3C",X"00",X"FF",X"FF",X"FF",X"7E",X"7E",
X"3C",X"02",X"04",X"0F",X"FF",X"08",X"01",X"08",X"01",X"0F",X"FF",X"02",X"04",X"0F",X"FF",X"08",
X"01",X"09",X"F9",X"0F",X"FF",X"02",X"06",X"0F",X"FF",X"08",X"01",X"0B",X"FD",X"0F",X"FF",X"01",
X"F8",X"00",X"F0",X"02",X"08",X"0F",X"FF",X"08",X"01",X"0F",X"BF",X"0F",X"BF",X"03",X"FC",X"03",
X"FC",X"01",X"F8",X"00",X"F0",X"02",X"0A",X"0F",X"FF",X"08",X"01",X"0F",X"BF",X"0F",X"BF",X"07",
X"BE",X"07",X"BE",X"03",X"FC",X"03",X"FC",X"01",X"F8",X"00",X"F0",X"02",X"0C",X"0F",X"FF",X"08",
X"01",X"0F",X"BF",X"0F",X"BF",X"07",X"BE",X"07",X"BE",X"07",X"BE",X"07",X"BE",X"03",X"FC",X"03",
X"FC",X"01",X"F8",X"00",X"F0",X"02",X"0E",X"0F",X"FF",X"08",X"01",X"0F",X"BF",X"0F",X"BF",X"07",
X"BE",X"07",X"BE",X"07",X"BE",X"07",X"BE",X"07",X"BE",X"07",X"BE",X"03",X"FC",X"03",X"FC",X"01",
X"F8",X"00",X"F0",X"02",X"0F",X"0F",X"FF",X"08",X"01",X"0F",X"BF",X"0F",X"BF",X"07",X"BE",X"07",
X"BE",X"07",X"BE",X"07",X"BE",X"07",X"BE",X"07",X"BE",X"07",X"BE",X"03",X"FC",X"03",X"FC",X"01",
X"F8",X"00",X"F0",X"02",X"0C",X"1E",X"00",X"33",X"00",X"73",X"80",X"73",X"80",X"F3",X"C0",X"FF",
X"C0",X"FF",X"C0",X"F3",X"C0",X"73",X"80",X"73",X"80",X"33",X"00",X"1E",X"00",X"02",X"0C",X"1E",
X"00",X"3F",X"00",X"4F",X"80",X"67",X"80",X"E7",X"C0",X"FF",X"C0",X"FF",X"C0",X"F9",X"C0",X"79",
X"80",X"7C",X"80",X"3F",X"00",X"1E",X"00",X"02",X"0C",X"1E",X"00",X"3F",X"00",X"7F",X"80",X"7F",
X"80",X"FF",X"C0",X"8C",X"40",X"8C",X"40",X"FF",X"C0",X"7F",X"80",X"7F",X"80",X"3F",X"00",X"1E",
X"00",X"02",X"0C",X"1E",X"00",X"3F",X"00",X"7C",X"80",X"79",X"80",X"F9",X"C0",X"FF",X"C0",X"FF",
X"C0",X"E7",X"C0",X"67",X"80",X"4F",X"80",X"3F",X"00",X"1E",X"00",X"02",X"08",X"FF",X"F0",X"CF",
X"30",X"B6",X"D0",X"BE",X"D0",X"A6",X"D0",X"B6",X"D0",X"C7",X"30",X"FF",X"F0",X"02",X"08",X"FF",
X"F0",X"CE",X"30",X"B7",X"70",X"BF",X"70",X"A7",X"70",X"B7",X"70",X"C6",X"30",X"FF",X"F0",X"02",
X"08",X"FF",X"F0",X"BB",X"B0",X"D7",X"30",X"EF",X"B0",X"EF",X"B0",X"D7",X"B0",X"BB",X"10",X"FF",
X"F0",X"02",X"08",X"FF",X"F0",X"BA",X"10",X"D6",X"F0",X"EE",X"30",X"EF",X"D0",X"EF",X"D0",X"EE",
X"30",X"FF",X"F0",X"01",X"10",X"3C",X"7E",X"FF",X"FF",X"FF",X"FF",X"7E",X"3C",X"18",X"18",X"3C",
X"18",X"18",X"3C",X"18",X"18",X"01",X"08",X"3C",X"18",X"18",X"3C",X"18",X"18",X"3C",X"18",X"02",
X"08",X"0E",X"00",X"01",X"C0",X"00",X"30",X"00",X"20",X"00",X"40",X"00",X"30",X"00",X"0C",X"00",
X"03",X"02",X"08",X"0E",X"00",X"01",X"C0",X"00",X"30",X"00",X"70",X"00",X"C0",X"00",X"30",X"00",
X"0C",X"00",X"03",X"02",X"08",X"00",X"00",X"0F",X"80",X"00",X"60",X"00",X"80",X"01",X"80",X"00",
X"60",X"00",X"18",X"00",X"07",X"02",X"08",X"00",X"00",X"00",X"00",X"0E",X"00",X"01",X"C0",X"00",
X"60",X"00",X"E0",X"00",X"1C",X"00",X"07",X"02",X"08",X"00",X"00",X"0C",X"00",X"03",X"80",X"00",
X"70",X"00",X"20",X"00",X"40",X"00",X"38",X"00",X"07",X"02",X"08",X"00",X"00",X"00",X"01",X"00",
X"C6",X"00",X"A8",X"01",X"30",X"02",X"00",X"04",X"00",X"08",X"00",X"02",X"08",X"00",X"01",X"00",
X"02",X"00",X"64",X"00",X"98",X"01",X"00",X"02",X"00",X"04",X"00",X"08",X"00",X"02",X"08",X"00",
X"00",X"00",X"03",X"00",X"0C",X"00",X"10",X"00",X"E0",X"03",X"00",X"04",X"00",X"08",X"00",X"02",
X"08",X"00",X"03",X"00",X"0C",X"00",X"30",X"00",X"80",X"00",X"30",X"01",X"C0",X"0E",X"00",X"00",
X"00",X"02",X"08",X"00",X"03",X"00",X"0E",X"00",X"18",X"00",X"D0",X"01",X"B0",X"02",X"00",X"04",
X"00",X"08",X"00",X"02",X"08",X"00",X"00",X"00",X"07",X"00",X"8C",X"00",X"C8",X"01",X"B0",X"02",
X"10",X"04",X"00",X"08",X"00",X"02",X"02",X"FF",X"F8",X"FF",X"F8",X"02",X"02",X"FF",X"F0",X"FF",
X"F0",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF");
begin
process(clk)
begin
if rising_edge(clk) then
data <= rom_data(to_integer(unsigned(addr)));
end if;
end process;
end architecture;

View File

@@ -0,0 +1,276 @@
---------------------------------------------------------------------------------
-- Berzerk sound effects - Dar - July 2018
---------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity berzerk_sound_fx is
port (
clock : in std_logic;
reset : in std_logic;
cs : in std_logic;
addr : in std_logic_vector(4 downto 0);
di : in std_logic_vector(7 downto 0);
sample : out std_logic_vector(11 downto 0)
);
end berzerk_sound_fx;
architecture struct of berzerk_sound_fx is
signal hdiv : std_logic_vector(1 downto 0);
signal ena_internal_clock : std_logic;
signal ptm6840_msb_buffer : std_logic_vector(7 downto 0);
signal ptm6840_max1 : std_logic_vector(15 downto 0);
signal ptm6840_max2 : std_logic_vector(15 downto 0);
signal ptm6840_max3 : std_logic_vector(15 downto 0);
signal ptm6840_cnt1 : std_logic_vector(15 downto 0);
signal ptm6840_cnt2 : std_logic_vector(15 downto 0);
signal ptm6840_cnt3 : std_logic_vector(15 downto 0);
signal ptm6840_ctrl1 : std_logic_vector(7 downto 0);
signal ptm6840_ctrl2 : std_logic_vector(7 downto 0);
signal ptm6840_ctrl3 : std_logic_vector(7 downto 0);
signal ptm6840_q1 : std_logic;
signal ptm6840_q2 : std_logic;
signal ptm6840_q3 : std_logic;
signal ctrl_noise_and_ch1 : std_logic_vector(1 downto 0);
signal ctrl_vol_ch1 : std_logic_vector(2 downto 0);
signal ctrl_vol_ch2 : std_logic_vector(2 downto 0);
signal ctrl_vol_ch3 : std_logic_vector(2 downto 0);
type vol_type is array(0 to 7) of unsigned(7 downto 0);
constant vol : vol_type := (X"01", X"02", X"04", X"08", X"10", X"20", X"40", X"80");
signal snd1 : signed(8 downto 0);
signal snd2 : signed(8 downto 0);
signal snd3 : signed(8 downto 0);
--signal snd : std_logic_vector(11 downto 0);
signal ptm6840_q1_r : std_logic;
signal ena_q1_clock : std_logic;
signal noise_xor, noise_xor_r : std_logic;
signal noise_shift_reg : std_logic_vector(127 downto 0) := (others => '1');
signal noise_shift_reg_95_r : std_logic;
signal ena_external_clock : std_logic;
begin
sample <= std_logic_vector(snd1+snd2+snd3) + X"7FF";
-- make enable signal to replace misc clocks
process(clock)
begin
if rising_edge(clock) then
-- ptm_6840 E input pin (internal clock)
-- board input clock divide by 4
if hdiv = "11" then
hdiv <= "00";
ena_internal_clock <= '1';
else
hdiv <= std_logic_vector(unsigned(hdiv) + 1);
ena_internal_clock <= '0';
end if;
-- ptm6840_q1 is used for alternate noise generator clock
ptm6840_q1_r <= ptm6840_q1;
if ptm6840_q1_r = '0' and ptm6840_q1 = '1' then
ena_q1_clock <= '1';
else
ena_q1_clock <= '0';
end if;
-- noise generator ouput is use for ptm6840 external clocks (C1, C2, C3)
noise_shift_reg_95_r <= noise_shift_reg(95);
if noise_shift_reg_95_r = '0' and noise_shift_reg(95) = '1' then
ena_external_clock <= '1';
else
ena_external_clock <= '0';
end if;
end if;
end process;
--control/registers interface with cpu addr/data
ctrl_regs : process(clock, reset)
begin
if reset = '1' then
ptm6840_ctrl1 <= X"01";
ptm6840_ctrl2 <= (others => '0');
ptm6840_ctrl3 <= (others => '0');
ctrl_noise_and_ch1 <= (others => '0');
ctrl_vol_ch1 <= (others => '0');
ctrl_vol_ch2 <= (others => '0');
ctrl_vol_ch3 <= (others => '0');
else
if rising_edge(clock) then
if cs = '1' and addr(4 downto 3) = "00" then
case addr(2 downto 0) is
when "000" =>
if ptm6840_ctrl2(0) = '1' then
ptm6840_ctrl1 <= di;
else
ptm6840_ctrl3 <= di;
end if;
when "001" =>
ptm6840_ctrl2 <= di;
when "011" =>
ptm6840_max1 <= ptm6840_msb_buffer & di;
when "101" =>
ptm6840_max2 <= ptm6840_msb_buffer & di;
when "111" =>
ptm6840_max3 <= ptm6840_msb_buffer & di;
when "110" =>
-- ptm6840_msb_buffer <= di;
case di(7 downto 6) is
when "00" =>
ctrl_noise_and_ch1 <= di(1 downto 0);
when "01" =>
ctrl_vol_ch1 <= di(2 downto 0);
when "10" =>
ctrl_vol_ch2 <= di(2 downto 0);
when others =>
ctrl_vol_ch3 <= di(2 downto 0);
end case;
when others =>
ptm6840_msb_buffer <= di;
end case;
end if;
end if;
end if;
end process;
-- simplified ptm6840 (only useful part for berzerk)
-- only synthesis mode
-- 16 bits count mode only (no dual 8 bits mode)
-- count on internal or external clock
-- no status
-- no IRQ
-- no gates input
counters : process(clock, reset, ptm6840_max1, ptm6840_max2, ptm6840_max3)
begin
if reset = '1' then
ptm6840_cnt1 <= ptm6840_max1;
ptm6840_cnt2 <= ptm6840_max2;
ptm6840_cnt3 <= ptm6840_max3;
ptm6840_q1 <= '0';
ptm6840_q2 <= '0';
ptm6840_q3 <= '0';
else
if rising_edge(clock) then
if ptm6840_ctrl1(0) = '0' then
-- counter #1
if (ptm6840_ctrl1(1) = '1' and ena_internal_clock = '1') or
(ptm6840_ctrl1(1) = '0' and ena_external_clock = '1') then
if ptm6840_cnt1 = X"0000" then
ptm6840_cnt1 <= ptm6840_max1;
ptm6840_q1 <= not ptm6840_q1;
else
ptm6840_cnt1 <= ptm6840_cnt1 - '1';
end if;
end if;
-- counter #2
if (ptm6840_ctrl2(1) = '1' and ena_internal_clock = '1') or
(ptm6840_ctrl2(1) = '0' and ena_external_clock = '1') then
if ptm6840_cnt2 = X"0000" then
ptm6840_cnt2 <= ptm6840_max2;
ptm6840_q2 <= not ptm6840_q2;
else
ptm6840_cnt2 <= ptm6840_cnt2 - '1';
end if;
end if;
-- counter #3
if (ptm6840_ctrl3(1) = '1' and ena_internal_clock = '1') or
(ptm6840_ctrl3(1) = '0' and ena_external_clock = '1') then
if ptm6840_cnt3 = X"0000" then
ptm6840_cnt3 <= ptm6840_max3;
ptm6840_q3 <= not ptm6840_q3;
else
ptm6840_cnt3 <= ptm6840_cnt3 - '1';
end if;
end if;
else
ptm6840_cnt1 <= ptm6840_max1;
ptm6840_cnt2 <= ptm6840_max2;
ptm6840_cnt3 <= ptm6840_max3;
end if;
-- fx channel #1 enable and volume
-- channel #1 output is OFF when q1 drive noise generator clock
snd1 <= (others=>'0');
if ptm6840_ctrl1(7) = '1' then
if ptm6840_q1 = '1' and ctrl_noise_and_ch1(1) = '0' then
snd1 <= signed('0'&vol(to_integer(unsigned(ctrl_vol_ch1))));
else
snd1 <= -signed('0'&vol(to_integer(unsigned(ctrl_vol_ch1))));
end if;
end if;
-- fx channel #2 enable and volume
snd2 <= (others=>'0');
if ptm6840_ctrl2(7) = '1' then
if ptm6840_q2 = '1' then
snd2 <= signed('0'&vol(to_integer(unsigned(ctrl_vol_ch2))));
else
snd2 <= -signed('0'&vol(to_integer(unsigned(ctrl_vol_ch2))));
end if;
end if;
-- fx channel #2 enable and volume
snd3 <= (others=>'0');
if ptm6840_ctrl3(7) = '1' then
if ptm6840_q3 = '1' then
snd3 <= signed('0'&vol(to_integer(unsigned(ctrl_vol_ch3))));
else
snd3 <= -signed('0'&vol(to_integer(unsigned(ctrl_vol_ch3))));
end if;
end if;
end if;
end if;
end process;
-- noise generator
noise_xor <= noise_shift_reg(127) xor noise_shift_reg(95);
noise: process(clock, reset)
begin
if reset = '1' then
noise_shift_reg <= (others => '1');
else
if rising_edge(clock) then
-- noise clock is either same as internal clock or q1 output
if (ctrl_noise_and_ch1(0) = '0' and ena_internal_clock = '1') or
(ctrl_noise_and_ch1(0) = '1' and ena_q1_clock = '1') then
noise_shift_reg <= noise_shift_reg(126 downto 0) & (noise_xor_r xor noise_xor);
noise_xor_r <= noise_xor;
end if;
end if;
end if;
end process;
end architecture;

View File

@@ -0,0 +1,441 @@
---------------------------------------------------------------------------------
-- Berzerk speech by Dar - July 2018
---------------------------------------------------------------------------------
-- s14001a speech synthesis based on Mame source code : TSI S14001A emulator v1.32
--
-- By Jonathan Gevaryahu ("Lord Nightmare") with help from Kevin Horton ("kevtris")
-- MAME conversion and integration by R. Belmont
-- Clock Frequency control updated by Zsolt Vasvari
-- Other fixes by AtariAce
--
-- Copyright (C) 2006-2013 Jonathan Gevaryahu aka Lord Nightmare
--
--
-- VHDL conversion by Dar
--
---------------------------------------------------------------------------------
-- S14001a principle
--
-- Command + start select a word to be played
-- One word is a list of first phoneme address called syllables
-- Each phoneme is composed of an LPC data first bloc address and a phoneme parameter
-- Phoneme parameter gives the mode (mirror/not mirror), silent, last_phoneme,
-- repeat and length of begining counters values.
--
-- Sound is LPC data encoded by bloc of 32 samples (8 bytes and 4 delta value/byte)
--
-- In non mirror mode blocs of LPC data are read consecutively from first to
-- first+N. with N = (8-repeat) * (16-length)
--
-- In mirror mode blocs of LPC data are read once forward and once backward
-- repeatedly (8-repeat) times then next bloc is read. Change to next syllable
-- after (16-length)/2 blocs have been read.
--
-- Output is set to silent (value 7) under some circumstances (third and fourth
-- quarter in mirror mode or for one sample after changing read direction).
--
-- Silence can modify output value (in the loop) or not (silence modify
-- output_sil but not output)
--
--
---------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity berzerk_speech is
port (
sw : in std_logic_vector(9 downto 0);
clock : in std_logic;
reset : in std_logic;
cs : in std_logic;
wr_n : in std_logic;
addr : in std_logic_vector(4 downto 0);
di : in std_logic_vector(7 downto 0);
busy : out std_logic;
sample : out std_logic_vector(11 downto 0)
);
end berzerk_speech;
architecture struct of berzerk_speech is
signal hdiv1 : std_logic_vector(3 downto 0);
signal hdiv2 : std_logic_vector(3 downto 0);
signal ena_hdiv2 : std_logic;
signal ctrl_hdiv1 : std_logic_vector(2 downto 0);
signal ctrl_volume : std_logic_vector(2 downto 0);
signal ctrl_s14001_cmd : std_logic_vector(5 downto 0);
signal busy_in : std_logic;
type vol_type is array(0 to 7) of integer range 0 to 255 ;
constant vol : vol_type := (0, 32, 46, 64, 89, 126, 180, 255); -- resistor ladder
signal rom_addr : std_logic_vector(11 downto 0);
signal rom_do : std_logic_vector( 7 downto 0);
type state_t is (waiting_start, reading, next_syllable);
signal state : state_t;
signal syllable_addr : std_logic_vector(11 downto 0);
signal phoneme_addr : std_logic_vector(11 downto 0);
signal phoneme_offset : std_logic_vector(11 downto 0);
signal phoneme_param : std_logic_vector( 7 downto 0);
alias last_phoneme : std_logic is phoneme_param(7);
alias mirror : std_logic is phoneme_param(6);
alias silence : std_logic is phoneme_param(5);
signal phoneme_length : std_logic_vector(3 downto 0);
signal phoneme_repeat : std_logic_vector(2 downto 0);
signal length_counter : std_logic_vector(4 downto 0);
signal repeat_counter : std_logic_vector(3 downto 0);
signal output_counter : std_logic_vector(2 downto 0);
signal phoneme_start : std_logic;
signal read_direction : std_logic;
signal last_offset : std_logic;
signal output : signed(4 downto 0); -- actually unsigned between 0 and F, silence = 7
signal output_sil : signed(4 downto 0); -- actually unsigned between 0 and F, silence = 7
signal start_speech : std_logic;
signal old_delta : std_logic_vector (1 downto 0);
signal cur_delta : std_logic_vector (1 downto 0);
type delta_table_row_t is array(0 to 3,0 to 3) of signed(2 downto 0);
constant delta_table : delta_table_row_t := (
("101", "101", "111", "111"),
("111", "111", "000", "000"),
("000", "000", "001", "001"),
("001", "001", "011", "011"));
begin
-- busy output
busy <= busy_in;
-- conversion from 0-F ouput and volume scale to 0-F*256, silence at 7*256.
sample <= std_logic_vector(to_unsigned(
((to_integer(output_sil) -7) * vol(to_integer(unsigned(ctrl_volume)))) + 7*256, 12));
-- clock divider
counter : process(clock, reset)
begin
if reset = '1' then
hdiv1 <= (others => '0');
hdiv2 <= (others => '0');
else
if rising_edge(clock) then
-- divide between 9 and 16 upon ctrl
if hdiv1 = "1111" then
hdiv1 <= "0"&ctrl_hdiv1;
ena_hdiv2 <= '1';
else
hdiv1 <= hdiv1 + '1';
ena_hdiv2 <= '0';
end if;
-- divide by 16 is ok because : IC A5 divide by 8 and s14001a divide by 2 internally
if ena_hdiv2 = '1' then
if hdiv2 = "1111" then
hdiv2 <= (others => '0');
else
hdiv2 <= hdiv2 + '1';
end if;
end if;
end if;
end if;
end process;
--control/registers interface with cpu addr/data
ctrl_regs : process(clock, reset)
begin
if reset = '1' then
ctrl_s14001_cmd <= (others => '0');
ctrl_hdiv1 <= (others => '0');
ctrl_volume <= (others => '0');
start_speech <= '0';
else
if rising_edge(clock) then
if busy_in = '1' then
start_speech <= '0';
end if;
if (cs = '1') and (wr_n = '0') and (addr = "00100") then -- 0x44
if (di(7 downto 6) = "00") and (busy_in = '0') and (start_speech = '0') then
ctrl_s14001_cmd <= di(5 downto 0);
start_speech <= '1';
end if;
if di(7 downto 6) = "01" then
ctrl_hdiv1 <= di(2 downto 0);
ctrl_volume <= di(5 downto 3);
end if;
end if;
end if;
end if;
end process;
-- s14001a
phoneme_length <= phoneme_param(4 downto 2)&'0';
phoneme_repeat <= phoneme_param(1 downto 0)&'0';
s14001a: process(clock, reset)
begin
if reset = '1' then
state <= waiting_start;
else
if rising_edge(clock) then
if ena_hdiv2 = '1' then
-- using hdiv2 as a sub-state counter
-- computation are done during sub-state 0-14
-- new sample is ready on sub-state 15
-- next state is set on sub-state transition from 15 to 0
case state is
when waiting_start =>
output <= "00111";
case hdiv2 is
-- wait for start, set busy when done
when X"0" =>
busy_in <= '0';
if start_speech = '1' then
busy_in <= '1';
end if;
-- compute syllable addr from word cmd
when X"1" =>
rom_addr <= "00000"&ctrl_s14001_cmd&'0';
when X"2" =>
syllable_addr(11 downto 4) <= rom_do;
rom_addr <= "00000"&ctrl_s14001_cmd&'1';
when X"3" =>
syllable_addr(3 downto 0) <= rom_do(7 downto 4);
-- init playing speech
when X"F" =>
if busy_in = '1' then
state <= reading;
phoneme_start <= '1';
phoneme_offset <= (others =>'0');
end if;
when others => null;
end case;
when reading =>
case hdiv2 is
-- get phoneme addr and parameter
when X"0" =>
rom_addr <= syllable_addr;
when X"1" =>
phoneme_addr <= rom_do&"0000";
rom_addr <= syllable_addr + '1';
when X"2" =>
phoneme_param <= rom_do;
rom_addr <= phoneme_addr + phoneme_offset(11 downto 2);
when X"3" =>
-- start with a new phoneme
if phoneme_start = '1' then
length_counter <= '0'&phoneme_length;
repeat_counter <= '0'&phoneme_repeat;
read_direction <= '1';
old_delta <= "10";
output_counter <= (others =>'0');
phoneme_start <= '0';
phoneme_offset <= (others =>'0');
output <= "00111";
end if;
-- get LPC data
case phoneme_offset(1 downto 0) is
when "00" => cur_delta <= rom_do(7 downto 6);
when "01" => cur_delta <= rom_do(5 downto 4);
when "10" => cur_delta <= rom_do(3 downto 2);
when others => cur_delta <= rom_do(1 downto 0);
end case;
-- compute new ouput from previous value and new LPC data
when X"4" =>
if read_direction = '1' then
if ((mirror = '1') and (output_counter(1) = '1')) or (silence = '1') then
output <= "00111" + delta_table(to_integer(unsigned(cur_delta)), 2);
else
output <= output + delta_table(to_integer(unsigned(cur_delta)),to_integer(unsigned(old_delta)));
end if;
else
if phoneme_offset(4 downto 0) = "11111" then
if (output_counter(1) = '1') or (silence = '1') then
output <= "00111";
else
-- keep last value
end if;
else
if (output_counter(1) = '1') or (silence = '1') then
output <= "00111" - delta_table(2, to_integer(unsigned(cur_delta)));
else
output <= output - delta_table(to_integer(unsigned(old_delta)),to_integer(unsigned(cur_delta)));
end if;
end if;
end if;
old_delta <= cur_delta;
-- increase or decrease phoneme_offset (one offset = one sample)
-- last offset when 32 samples have been read either forward or backward
last_offset <= '0';
if read_direction = '1' then
if phoneme_offset(4 downto 0) = "11111" then
last_offset <= '1';
if mirror = '0' then
phoneme_offset <= phoneme_offset + '1';
end if;
else
phoneme_offset <= phoneme_offset + '1';
end if;
else
if phoneme_offset(4 downto 0) = "00000" then
last_offset <= '1';
else
phoneme_offset <= phoneme_offset - '1';
end if;
end if;
-- increase repeat counter every 32 samples
when X"5" =>
if last_offset = '1' then
repeat_counter <= repeat_counter + '1';
output_counter <= output_counter + '1';
last_offset <= '0';
end if;
-- limit ouput to 0 - F
if output > "01111" then output <= "01111"; end if;
if output < "00000" then output <= "00000"; end if;
-- manage read_direction and phoneme advance (+8bytes = next 32 samples)
-- upon mirror condition
when X"6" =>
if mirror = '1' then
if repeat_counter = 8 then
repeat_counter <= '0'&phoneme_repeat;
if length_counter(0) = '1' then
phoneme_offset <= phoneme_offset + "100000";
end if;
if length_counter = 15 then
-- will be 16 after on next state
else
if output_counter(0) = '1' then
read_direction <= '0';
else
read_direction <= '1';
end if;
end if;
length_counter <= length_counter + 1;
else
if output_counter(0) = '1' then
read_direction <= '0';
else
read_direction <= '1';
end if;
end if;
else -- not in mirror mode
if repeat_counter = 8 then
repeat_counter <= '0'&phoneme_repeat;
if length_counter = 15 then
-- will be 16 after this state
end if;
length_counter <= length_counter + 1;
end if;
end if;
-- goto next syllable when length counter reach 16
when X"F" =>
if length_counter = 16 then
state <= next_syllable;
end if;
when others => null;
end case;
when next_syllable =>
case hdiv2 is
-- prepare for next syllable
when X"0" =>
syllable_addr <= syllable_addr + 2;
phoneme_offset <= (others =>'0');
phoneme_start <= '1';
-- one silent sample during syllable change
when X"4" =>
output <= "00111";
-- terminate if last phoneme reached
when X"F" =>
if last_phoneme = '1' then
state <= waiting_start;
else
state <= reading;
end if;
when others => null;
end case;
when others => null;
end case; -- case state
-- set silent final output during 2 last quarter when in mirror mode
if hdiv2 = X"6" then
if ((mirror = '1') and (output_counter(1) = '1')) or (silence = '1') then
output_sil <= "00111";
else
output_sil <= output;
end if;
end if;
end if;
end if;
end if;
end process;
-- program roms
speech_rom : entity work.berzerk_speech_rom
port map (
addr => rom_addr(11 downto 0),
clk => clock,
data => rom_do
);
end architecture;

View File

@@ -0,0 +1,278 @@
library ieee;
use ieee.std_logic_1164.all,ieee.numeric_std.all;
entity berzerk_speech_rom is
port (
clk : in std_logic;
addr : in std_logic_vector(11 downto 0);
data : out std_logic_vector(7 downto 0)
);
end entity;
architecture prom of berzerk_speech_rom is
type rom is array(0 to 4095) of std_logic_vector(7 downto 0);
signal rom_data: rom := (
X"03",X"A0",X"04",X"40",X"04",X"E0",X"05",X"E0",X"06",X"E0",X"07",X"80",X"08",X"40",X"08",X"C0",
X"09",X"20",X"09",X"A0",X"0A",X"E0",X"0B",X"40",X"0B",X"80",X"0B",X"E0",X"0C",X"60",X"0C",X"A0",
X"0D",X"80",X"0E",X"60",X"0F",X"80",X"10",X"80",X"10",X"C0",X"11",X"E0",X"12",X"C0",X"13",X"60",
X"13",X"C0",X"14",X"C0",X"15",X"60",X"15",X"E0",X"16",X"00",X"17",X"1D",X"17",X"1D",X"1D",X"49",
X"1D",X"6E",X"20",X"9F",X"22",X"1F",X"22",X"1F",X"17",X"1E",X"24",X"41",X"28",X"D9",X"29",X"59",
X"29",X"78",X"2D",X"1F",X"2D",X"1F",X"2D",X"7F",X"2A",X"49",X"2A",X"78",X"22",X"9F",X"2D",X"1F",
X"2D",X"1F",X"2F",X"1C",X"37",X"41",X"37",X"7C",X"2D",X"1F",X"3B",X"5B",X"2F",X"9C",X"22",X"1F",
X"3C",X"51",X"3E",X"51",X"3E",X"6E",X"2D",X"9F",X"2F",X"1D",X"2F",X"1E",X"2F",X"1D",X"40",X"50",
X"40",X"6E",X"2D",X"9F",X"22",X"1F",X"42",X"49",X"42",X"78",X"2D",X"9F",X"45",X"41",X"49",X"1C",
X"49",X"9C",X"51",X"59",X"52",X"41",X"52",X"78",X"2D",X"9F",X"2D",X"1F",X"56",X"52",X"56",X"79",
X"2D",X"1F",X"58",X"51",X"58",X"78",X"2D",X"1F",X"5A",X"51",X"5A",X"78",X"2D",X"9F",X"5C",X"1E",
X"5C",X"1E",X"60",X"C1",X"64",X"41",X"68",X"D9",X"69",X"50",X"69",X"6E",X"2D",X"9F",X"5C",X"1E",
X"5C",X"1E",X"6B",X"5A",X"6C",X"C1",X"70",X"41",X"74",X"D1",X"17",X"1D",X"17",X"1D",X"76",X"41",
X"7A",X"41",X"7E",X"59",X"7E",X"7C",X"2D",X"9F",X"22",X"1F",X"22",X"1F",X"22",X"7E",X"7F",X"41",
X"83",X"58",X"49",X"1D",X"49",X"9D",X"20",X"1F",X"17",X"1E",X"84",X"51",X"84",X"78",X"22",X"1F",
X"22",X"7F",X"86",X"58",X"86",X"78",X"2D",X"9F",X"87",X"49",X"87",X"7C",X"2D",X"1F",X"2D",X"1F",
X"2D",X"7E",X"8F",X"5B",X"8A",X"5A",X"8B",X"C1",X"96",X"51",X"98",X"D0",X"9A",X"58",X"49",X"1D",
X"49",X"1D",X"49",X"7C",X"22",X"1F",X"17",X"1E",X"9B",X"49",X"9B",X"79",X"20",X"9F",X"2D",X"1F",
X"9E",X"52",X"49",X"1D",X"49",X"1D",X"49",X"79",X"A0",X"41",X"A4",X"D9",X"A5",X"41",X"49",X"1D",
X"49",X"1D",X"49",X"78",X"2D",X"9F",X"A9",X"49",X"A9",X"78",X"2D",X"9F",X"2D",X"1F",X"2D",X"1F",
X"2F",X"1C",X"AC",X"58",X"AC",X"79",X"22",X"1F",X"22",X"7F",X"AD",X"C9",X"B0",X"1D",X"B0",X"1D",
X"B6",X"49",X"B6",X"78",X"2D",X"9F",X"B9",X"41",X"B9",X"78",X"22",X"1F",X"17",X"9F",X"BD",X"C1",
X"8F",X"41",X"8F",X"7C",X"20",X"1F",X"93",X"49",X"93",X"78",X"2D",X"9F",X"FF",X"FF",X"FF",X"FF",
X"75",X"A3",X"28",X"C9",X"D7",X"59",X"D9",X"67",X"5D",X"69",X"75",X"D8",X"C7",X"97",X"5A",X"29",
X"89",X"A5",X"A5",X"A6",X"26",X"97",X"5A",X"89",X"67",X"65",X"9D",X"96",X"69",X"89",X"A5",X"A2",
X"67",X"5D",X"76",X"28",X"9E",X"22",X"98",X"CA",X"63",X"27",X"28",X"9A",X"65",X"A5",X"9A",X"66",
X"63",X"28",X"9D",X"99",X"66",X"96",X"76",X"5A",X"27",X"59",X"D9",X"66",X"78",X"89",X"D6",X"75",
X"96",X"98",X"9A",X"5D",X"8A",X"71",X"78",X"D8",X"CA",X"59",X"D9",X"69",X"98",X"99",X"D6",X"76",
X"27",X"5D",X"8A",X"65",X"99",X"9D",X"6A",X"19",X"D8",X"D5",X"E6",X"5A",X"5D",X"69",X"75",X"99",
X"67",X"62",X"77",X"1A",X"94",X"7A",X"98",X"7F",X"C0",X"FC",X"6D",X"0F",X"80",X"AE",X"61",X"AF",
X"A8",X"26",X"2F",X"85",X"46",X"F0",X"3D",X"7F",X"1A",X"A7",X"85",X"D6",X"B4",X"64",X"3F",X"6F",
X"67",X"66",X"62",X"A5",X"A5",X"26",X"2B",X"9F",X"A6",X"62",X"66",X"65",X"98",X"69",X"7A",X"9E",
X"99",X"72",X"63",X"69",X"99",X"99",X"99",X"97",X"72",X"5A",X"66",X"59",X"99",X"98",X"A6",X"65",
X"E2",X"97",X"66",X"5D",X"99",X"69",X"99",X"99",X"8A",X"66",X"59",X"99",X"9D",X"75",X"99",X"98",
X"8D",X"72",X"66",X"76",X"27",X"5D",X"97",X"5C",X"9D",X"75",X"99",X"E2",X"62",X"73",X"65",X"A2",
X"8A",X"27",X"29",X"89",X"9A",X"5D",X"66",X"6A",X"25",X"9D",X"99",X"62",X"79",X"99",X"66",X"99",
X"98",X"A6",X"26",X"5D",X"67",X"86",X"B5",X"3F",X"D4",X"F4",X"2F",X"03",X"E5",X"67",X"B1",X"2F",
X"99",X"79",X"A5",X"1F",X"42",X"A7",X"B5",X"3F",X"2A",X"8A",X"5A",X"96",X"42",X"F4",X"3C",X"EF",
X"78",X"2D",X"6F",X"43",X"82",X"E0",X"2F",X"3F",X"1E",X"2B",X"57",X"82",X"E0",X"E4",X"2F",X"6F",
X"2A",X"67",X"59",X"89",X"E1",X"95",X"6E",X"6B",X"9A",X"65",X"99",X"99",X"98",X"59",X"AA",X"9E",
X"99",X"97",X"62",X"98",X"98",X"69",X"AA",X"9E",X"99",X"98",X"99",X"99",X"96",X"29",X"AA",X"9E",
X"98",X"9E",X"59",X"8A",X"81",X"F8",X"78",X"2F",X"99",X"99",X"96",X"57",X"95",X"A9",X"E8",X"6E",
X"66",X"6A",X"65",X"6A",X"94",X"5E",X"A1",X"7F",X"D0",X"B8",X"AD",X"0F",X"D0",X"69",X"A8",X"7F",
X"D0",X"B8",X"6E",X"0B",X"C0",X"A7",X"94",X"BF",X"D1",X"D5",X"F5",X"2F",X"52",X"82",X"F4",X"3F",
X"E0",X"5A",X"B4",X"2F",X"81",X"E0",X"BC",X"2F",X"A5",X"1F",X"D4",X"2F",X"81",X"C5",X"F8",X"3F",
X"8A",X"63",X"66",X"87",X"63",X"5A",X"59",X"CA",X"5A",X"5A",X"29",X"69",X"8A",X"29",X"5E",X"29",
X"68",X"A5",X"A5",X"A6",X"66",X"66",X"66",X"66",X"62",X"66",X"63",X"67",X"26",X"69",X"96",X"89",
X"96",X"99",X"73",X"5A",X"63",X"5C",X"CC",X"CA",X"62",X"96",X"73",X"32",X"8C",X"D6",X"98",X"A6",
X"29",X"8A",X"32",X"8C",X"A5",X"A5",X"CA",X"5C",X"A3",X"35",X"A2",X"8C",X"D6",X"76",X"27",X"5C",
X"89",X"D6",X"75",X"A5",X"CC",X"A3",X"27",X"32",X"98",X"A6",X"28",X"CA",X"5A",X"35",X"9C",X"CD",
X"73",X"35",X"A6",X"29",X"8A",X"65",X"CD",X"73",X"26",X"96",X"98",X"9D",X"89",X"D8",X"A3",X"27",
X"8A",X"35",X"A5",X"A5",X"9C",X"D7",X"35",X"CD",X"69",X"67",X"62",X"97",X"32",X"97",X"5C",X"CA",
X"33",X"5D",X"72",X"8C",X"9D",X"73",X"5A",X"35",X"A5",X"CC",X"D7",X"33",X"35",X"D6",X"8D",X"69",
X"96",X"69",X"73",X"5C",X"D8",X"A5",X"CC",X"CC",X"A3",X"5A",X"33",X"32",X"8C",X"D8",X"9C",X"CD",
X"73",X"59",X"D7",X"32",X"8C",X"CC",X"A5",X"9C",X"CA",X"33",X"33",X"28",X"CA",X"5C",X"D7",X"35",
X"86",X"A9",X"57",X"98",X"56",X"7A",X"87",X"BE",X"A0",X"6E",X"8B",X"90",X"6A",X"62",X"71",X"BF",
X"A0",X"3F",X"5B",X"90",X"6A",X"95",X"99",X"AF",X"61",X"AA",X"69",X"E0",X"2F",X"43",X"96",X"BE",
X"88",X"9E",X"2B",X"80",X"A9",X"6A",X"81",X"FF",X"1F",X"55",X"AB",X"90",X"6A",X"5A",X"85",X"BF",
X"2A",X"D4",X"7A",X"26",X"55",X"7B",X"80",X"FF",X"96",X"A5",X"95",X"79",X"D5",X"3F",X"80",X"BF",
X"76",X"62",X"36",X"29",X"99",X"A9",X"66",X"3A",X"99",X"66",X"59",X"9D",X"99",X"A6",X"66",X"76",
X"99",X"A1",X"A8",X"6A",X"47",X"D1",X"F5",X"2F",X"66",X"6A",X"95",X"6A",X"52",X"72",X"F4",X"3F",
X"5A",X"95",X"E6",X"7A",X"02",X"F0",X"68",X"BF",X"98",X"D4",X"BC",X"6D",X"0B",X"C0",X"79",X"FF",
X"D4",X"95",X"FD",X"5D",X"0F",X"C0",X"A8",X"BF",X"C1",X"F0",X"BC",X"1F",X"47",X"D0",X"79",X"BF",
X"A1",X"69",X"9E",X"1A",X"86",X"D4",X"3D",X"6F",X"A1",X"9C",X"7A",X"57",X"56",X"E0",X"79",X"6F",
X"C5",X"A7",X"80",X"FD",X"0B",X"92",X"F4",X"3F",X"99",X"96",X"66",X"29",X"5A",X"A5",X"A8",X"6F",
X"98",X"A5",X"98",X"5E",X"67",X"A1",X"A9",X"7A",X"95",X"E1",X"78",X"67",X"99",X"E1",X"A9",X"9E",
X"6A",X"1A",X"87",X"56",X"D1",X"F4",X"AD",X"1F",X"76",X"1E",X"1A",X"63",X"5A",X"95",X"F5",X"2F",
X"C2",X"F4",X"2E",X"07",X"96",X"86",X"F4",X"3F",X"5B",X"81",X"FC",X"0F",X"47",X"93",X"F4",X"3F",
X"86",X"96",X"B8",X"0F",X"C0",X"B8",X"7C",X"2F",X"C0",X"FD",X"65",X"3F",X"03",X"A0",X"F8",X"3F",
X"96",X"B0",X"2F",X"02",X"E6",X"1A",X"E8",X"2F",X"D4",X"F4",X"2F",X"03",X"D5",X"D9",X"F8",X"2F",
X"97",X"94",X"BC",X"0B",X"D0",X"F4",X"BC",X"2B",X"C4",X"F8",X"3D",X"0F",X"C0",X"B8",X"A8",X"3F",
X"C4",X"BD",X"1A",X"17",X"D0",X"FC",X"3C",X"2F",X"A4",X"AD",X"1B",X"47",X"C1",X"F8",X"78",X"2F",
X"89",X"D9",X"57",X"96",X"A0",X"F8",X"6D",X"2F",X"66",X"66",X"57",X"96",X"95",X"F8",X"69",X"3F",
X"97",X"5A",X"5D",X"75",X"D8",X"D7",X"5C",X"A3",X"35",X"CA",X"33",X"28",X"CA",X"35",X"CA",X"33",
X"5A",X"28",X"9C",X"A5",X"D6",X"97",X"32",X"8D",X"72",X"8A",X"35",X"D6",X"96",X"8A",X"28",X"A5",
X"72",X"97",X"5C",X"A3",X"32",X"8C",X"A5",X"A2",X"8C",X"A3",X"28",X"A2",X"8D",X"73",X"35",X"CA",
X"5A",X"29",X"75",X"A2",X"97",X"28",X"CD",X"73",X"28",X"A3",X"33",X"5D",X"75",X"A5",X"D7",X"5C",
X"69",X"68",X"CC",X"A3",X"35",X"D6",X"96",X"8A",X"35",X"CA",X"27",X"28",X"D6",X"97",X"5C",X"CA",
X"29",X"75",X"D7",X"33",X"5C",X"CA",X"28",X"CA",X"33",X"28",X"D7",X"5C",X"A5",X"D7",X"5D",X"73",
X"8D",X"75",X"CA",X"32",X"8A",X"5D",X"75",X"D6",X"97",X"5A",X"29",X"73",X"28",X"A2",X"8A",X"5A",
X"28",X"D7",X"33",X"5A",X"5D",X"75",X"D6",X"8A",X"5D",X"68",X"A2",X"8A",X"5D",X"73",X"35",X"D7",
X"65",X"5F",X"9E",X"81",X"95",X"F4",X"6A",X"7E",X"95",X"AA",X"9A",X"50",X"F5",X"74",X"3F",X"7F",
X"9A",X"9E",X"54",X"56",X"A9",X"A5",X"2B",X"7B",X"66",X"99",X"86",X"62",X"A8",X"A5",X"6A",X"AA",
X"99",X"5E",X"57",X"56",X"A8",X"A9",X"2B",X"1F",X"75",X"F4",X"3F",X"0D",X"43",X"F4",X"79",X"7F",
X"3A",X"1F",X"12",X"F0",X"0B",X"D7",X"90",X"FF",X"67",X"E0",X"3E",X"55",X"61",X"7F",X"80",X"BF",
X"5F",X"85",X"66",X"89",X"91",X"EF",X"50",X"BF",X"99",X"99",X"98",X"67",X"95",X"6B",X"94",X"7F",
X"A1",X"79",X"5A",X"5A",X"86",X"D4",X"F9",X"2B",X"69",X"5E",X"57",X"66",X"86",X"D4",X"BC",X"2B",
X"69",X"5A",X"96",X"67",X"56",X"D4",X"BC",X"2B",X"69",X"5A",X"95",X"DA",X"56",X"D4",X"BC",X"2B",
X"69",X"99",X"76",X"56",X"98",X"9A",X"A1",X"AF",X"D0",X"F8",X"7D",X"0B",X"C0",X"7A",X"E0",X"7F",
X"C1",X"B5",X"B5",X"2F",X"40",X"B8",X"7D",X"2F",X"2B",X"12",X"F0",X"3F",X"05",X"DA",X"C4",X"BE",
X"A5",X"96",X"66",X"1E",X"85",X"E9",X"A8",X"2F",X"E4",X"78",X"6C",X"0B",X"D0",X"BC",X"79",X"2F",
X"D4",X"B8",X"3D",X"0B",X"C0",X"F8",X"A8",X"3F",X"B4",X"7D",X"0F",X"0A",X"C0",X"FC",X"79",X"2F",
X"8C",X"CD",X"75",X"A3",X"5C",X"D7",X"28",X"CD",X"73",X"5C",X"CA",X"33",X"28",X"D7",X"28",X"CC",
X"A3",X"32",X"8C",X"A3",X"33",X"28",X"CC",X"CD",X"73",X"35",X"CC",X"A3",X"33",X"28",X"C9",X"A3",
X"8C",X"CD",X"73",X"5C",X"A3",X"35",X"CC",X"CA",X"27",X"5C",X"D7",X"32",X"75",X"A3",X"28",X"CC",
X"CD",X"73",X"32",X"8A",X"26",X"8C",X"A3",X"5C",X"A3",X"5C",X"A5",X"CD",X"8D",X"73",X"28",X"D7",
X"99",X"A2",X"76",X"16",X"57",X"A5",X"A9",X"AF",X"88",X"99",X"FD",X"46",X"07",X"E0",X"7E",X"6F",
X"66",X"17",X"FC",X"18",X"47",X"E4",X"7D",X"7F",X"91",X"A7",X"BD",X"18",X"4E",X"D0",X"BC",X"6F",
X"89",X"86",X"F9",X"1E",X"07",X"D0",X"A9",X"FF",X"85",X"D7",X"BC",X"28",X"0F",X"C0",X"B9",X"7F",
X"86",X"57",X"F9",X"28",X"0F",X"D0",X"AC",X"7F",X"66",X"5A",X"AA",X"55",X"5A",X"94",X"5E",X"FE",
X"A1",X"6D",X"4A",X"D0",X"F8",X"78",X"AD",X"1F",X"75",X"7D",X"0B",X"C0",X"F8",X"79",X"7D",X"1F",
X"66",X"A4",X"7E",X"03",X"F0",X"3D",X"B8",X"2F",X"38",X"5B",X"A8",X"0B",X"D0",X"7E",X"78",X"3F",
X"35",X"7E",X"07",X"97",X"C0",X"BA",X"A0",X"BF",X"38",X"69",X"69",X"8A",X"57",X"E0",X"BC",X"2B",
X"75",X"69",X"69",X"8A",X"57",X"E0",X"BC",X"2B",X"75",X"69",X"69",X"8A",X"57",X"E0",X"BC",X"2B",
X"66",X"29",X"69",X"8A",X"57",X"E0",X"BC",X"2B",X"65",X"AA",X"12",X"B9",X"81",X"F8",X"78",X"7F",
X"6A",X"61",X"9D",X"85",X"E8",X"89",X"F5",X"2F",X"79",X"66",X"3A",X"07",X"D1",X"E2",X"B4",X"3F",
X"A0",X"F8",X"3D",X"0F",X"C0",X"B8",X"A8",X"2F",X"A4",X"AD",X"1F",X"0A",X"C0",X"F8",X"A8",X"2F",
X"76",X"29",X"5A",X"99",X"56",X"B5",X"68",X"7F",X"A1",X"AA",X"19",X"5A",X"94",X"AA",X"78",X"6F",
X"B0",X"6A",X"79",X"0B",X"C0",X"BC",X"3D",X"2F",X"2B",X"51",X"FC",X"0B",X"C0",X"F4",X"B8",X"2F",
X"2E",X"0E",X"D0",X"F4",X"7D",X"0F",X"E0",X"3F",X"C4",X"AF",X"02",X"F0",X"78",X"1F",X"D4",X"7F",
X"56",X"F5",X"27",X"95",X"A4",X"2F",X"C0",X"BF",X"1F",X"95",X"67",X"67",X"80",X"7F",X"90",X"BF",
X"3D",X"55",X"E7",X"66",X"50",X"BF",X"41",X"BF",X"77",X"26",X"66",X"66",X"21",X"EA",X"51",X"FE",
X"66",X"66",X"66",X"59",X"99",X"9D",X"DE",X"76",X"65",X"D9",X"99",X"89",X"99",X"A6",X"A7",X"76",
X"96",X"66",X"69",X"66",X"59",X"99",X"E9",X"DE",X"5E",X"66",X"75",X"5D",X"89",X"E1",X"7A",X"6F",
X"2A",X"67",X"83",X"B8",X"03",X"F0",X"B8",X"3F",X"A8",X"1B",X"D4",X"3F",X"03",X"D2",X"F4",X"3F",
X"3D",X"0F",X"C1",X"E1",X"E9",X"0B",X"F0",X"3F",X"A5",X"2F",X"47",X"55",X"F8",X"0F",X"E0",X"3F",
X"92",X"B8",X"5A",X"95",X"A4",X"2F",X"D0",X"BF",X"67",X"95",X"9E",X"62",X"55",X"7B",X"80",X"FF",
X"69",X"99",X"99",X"99",X"85",X"AD",X"55",X"EF",X"76",X"66",X"66",X"66",X"55",X"EA",X"15",X"BE",
X"96",X"75",X"99",X"79",X"5A",X"C1",X"F8",X"2F",X"2E",X"03",X"F4",X"2E",X"1B",X"53",X"F0",X"3F",
X"5B",X"81",X"A9",X"6D",X"0B",X"D2",X"B5",X"3F",X"8A",X"56",X"A5",X"5E",X"27",X"A1",X"7A",X"3B",
X"66",X"61",X"E8",X"6A",X"57",X"D1",X"B8",X"2F",X"71",X"A6",X"29",X"8E",X"57",X"D4",X"B8",X"2F",
X"B0",X"39",X"AE",X"06",X"1E",X"D5",X"76",X"7F",X"66",X"AC",X"0B",X"9A",X"02",X"F0",X"B8",X"3F",
X"66",X"62",X"67",X"67",X"56",X"E1",X"A8",X"2F",X"65",X"99",X"9A",X"66",X"67",X"A1",X"78",X"6F",
X"A5",X"1E",X"8B",X"D0",X"92",X"F8",X"35",X"BF",X"74",X"7E",X"2A",X"06",X"AA",X"60",X"2F",X"7F",
X"1E",X"5F",X"0F",X"43",X"E1",X"E0",X"2F",X"7F",X"A0",X"7C",X"7F",X"03",X"82",X"F0",X"3E",X"3F",
X"83",X"F0",X"F4",X"2F",X"02",X"B8",X"68",X"6F",X"8A",X"C0",X"FC",X"0B",X"57",X"C2",X"F4",X"3F",
X"86",X"B4",X"2F",X"43",X"E0",X"B8",X"7C",X"2B",X"56",X"A5",X"7A",X"27",X"5A",X"A1",X"7A",X"1E",
X"66",X"A9",X"55",X"99",X"A9",X"55",X"AA",X"EE",X"2A",X"9D",X"56",X"95",X"A9",X"46",X"B6",X"BE",
X"27",X"7A",X"55",X"96",X"7D",X"41",X"F7",X"BE",X"61",X"7F",X"1A",X"81",X"AD",X"45",X"A6",X"BF",
X"66",X"39",X"6B",X"A0",X"1D",X"5B",X"C0",X"FF",X"A5",X"6A",X"86",X"65",X"9D",X"1B",X"D0",X"BF",
X"66",X"A1",X"79",X"59",X"9D",X"4F",X"E0",X"7F",X"66",X"95",X"9D",X"86",X"A6",X"5A",X"B4",X"6F",
X"66",X"62",X"68",X"6A",X"5A",X"A1",X"B8",X"2F",X"62",X"6A",X"55",X"DD",X"8A",X"67",X"A5",X"3F",
X"96",X"66",X"76",X"59",X"D9",X"95",X"67",X"AE",X"C1",X"E1",X"BD",X"49",X"D7",X"94",X"3E",X"7F",
X"D4",X"78",X"7F",X"07",X"92",X"B0",X"2E",X"6F",X"D4",X"75",X"AF",X"07",X"85",X"F0",X"2E",X"6F",
X"6A",X"62",X"75",X"66",X"66",X"62",X"B4",X"3F",X"D0",X"FC",X"65",X"2F",X"02",X"E0",X"F8",X"3F",
X"96",X"76",X"27",X"56",X"A5",X"A1",X"B8",X"2F",X"86",X"E4",X"3F",X"03",X"E0",X"B5",X"7D",X"2B",
X"79",X"61",X"AD",X"0B",X"D0",X"BC",X"3C",X"2F",X"66",X"5A",X"62",X"69",X"99",X"A9",X"98",X"6F",
X"66",X"59",X"99",X"9A",X"5A",X"A5",X"A9",X"6A",X"65",X"99",X"99",X"9A",X"66",X"99",X"A9",X"6A",
X"96",X"69",X"65",X"9D",X"98",X"9E",X"95",X"EE",X"86",X"B8",X"0B",X"86",X"A5",X"3B",X"C0",X"BF",
X"7C",X"1B",X"43",X"F4",X"1F",X"C2",X"E0",X"AF",X"7A",X"07",X"99",X"95",X"6B",X"95",X"A5",X"AF",
X"79",X"66",X"15",X"F8",X"0F",X"C7",X"D0",X"BF",X"96",X"66",X"75",X"6A",X"85",X"AA",X"94",X"7F",
X"D4",X"AE",X"42",X"A5",X"B4",X"2F",X"C4",X"3F",X"86",X"E8",X"47",X"95",X"F4",X"2F",X"C0",X"BF",
X"8A",X"E0",X"69",X"66",X"94",X"7F",X"80",X"BF",X"6A",X"95",X"5A",X"62",X"95",X"6F",X"90",X"BF",
X"66",X"62",X"66",X"66",X"76",X"76",X"69",X"DD",X"66",X"59",X"99",X"99",X"DD",X"96",X"79",X"DD",
X"89",X"9D",X"85",X"9D",X"D9",X"99",X"9D",X"EA",X"99",X"99",X"D9",X"55",X"A9",X"9A",X"22",X"AE",
X"82",X"F5",X"F4",X"1E",X"0B",X"91",X"B9",X"6F",X"72",X"B8",X"2C",X"0F",X"57",X"84",X"7F",X"2F",
X"A6",X"65",X"69",X"5A",X"86",X"71",X"7E",X"3B",X"98",X"99",X"67",X"27",X"65",X"A6",X"2E",X"6A",
X"99",X"A6",X"1A",X"17",X"98",X"A5",X"6E",X"6B",X"95",X"6B",X"9E",X"03",X"D1",X"F0",X"3E",X"7F",
X"A4",X"3E",X"2F",X"02",X"87",X"B4",X"2E",X"2F",X"A4",X"3D",X"6F",X"46",X"52",X"F4",X"3A",X"3F",
X"D4",X"E0",X"BE",X"1E",X"02",X"F0",X"69",X"AF",X"66",X"98",X"7A",X"66",X"47",X"A5",X"65",X"BF",
X"65",X"9D",X"66",X"5A",X"96",X"A5",X"B8",X"6B",X"65",X"A6",X"27",X"1A",X"86",X"E1",X"B8",X"2F",
X"A4",X"7D",X"47",X"8E",X"82",X"F5",X"78",X"3F",X"95",X"A5",X"7F",X"0A",X"02",X"FC",X"0E",X"AF",
X"95",X"86",X"F9",X"55",X"56",X"F0",X"3E",X"6F",X"17",X"A3",X"F4",X"19",X"6A",X"A0",X"7D",X"7F",
X"6A",X"99",X"C5",X"89",X"96",X"90",X"FD",X"AF",X"A6",X"58",X"99",X"9C",X"85",X"99",X"EE",X"7E",
X"99",X"99",X"99",X"66",X"85",X"A8",X"E8",X"6F",X"A2",X"67",X"62",X"1E",X"81",X"F5",X"78",X"6F",
X"76",X"59",X"99",X"9A",X"1A",X"C1",X"F8",X"2F",X"C2",X"B4",X"79",X"69",X"4F",X"82",X"F4",X"2F",
X"A1",X"E8",X"2E",X"0B",X"47",X"C2",X"F4",X"2F",X"C4",X"BC",X"0F",X"83",X"D1",X"F0",X"BC",X"1F",
X"B4",X"3E",X"0A",X"D0",X"F5",X"78",X"7D",X"1F",X"A4",X"AD",X"2A",X"1E",X"4A",X"D0",X"F5",X"2F",
X"96",X"75",X"6A",X"1A",X"95",X"E2",X"A8",X"2F",X"A4",X"AD",X"0F",X"82",X"D6",X"A0",X"F8",X"2F",
X"78",X"2E",X"0E",X"8A",X"57",X"D0",X"FC",X"2B",X"75",X"6A",X"57",X"67",X"56",X"D4",X"F8",X"3B",
X"6A",X"55",X"E8",X"6A",X"55",X"6B",X"84",X"AF",X"99",X"96",X"76",X"18",X"9D",X"9E",X"85",X"FE",
X"9A",X"9D",X"56",X"11",X"FA",X"19",X"A9",X"7F",X"1F",X"87",X"D0",X"A8",X"6A",X"80",X"AE",X"AF",
X"57",X"E5",X"B0",X"2D",X"67",X"90",X"7E",X"AF",X"69",X"95",X"FC",X"0E",X"0B",X"C0",X"E6",X"BF",
X"1B",X"D1",X"E4",X"BC",X"03",X"F4",X"7C",X"3F",X"C6",X"92",X"F0",X"2F",X"02",X"E1",X"F0",X"7F",
X"99",X"A1",X"79",X"59",X"9D",X"87",X"B5",X"3F",X"98",X"9D",X"5A",X"62",X"69",X"99",X"B8",X"2F",
X"57",X"A5",X"66",X"2A",X"96",X"99",X"A7",X"66",X"59",X"D9",X"66",X"66",X"A6",X"66",X"77",X"66",
X"26",X"A5",X"69",X"5A",X"A6",X"66",X"6A",X"66",X"27",X"6A",X"62",X"19",X"E6",X"61",X"6A",X"AB",
X"79",X"0B",X"DA",X"90",X"E9",X"A4",X"2A",X"BF",X"75",X"5E",X"5B",X"D0",X"E1",X"F0",X"2A",X"BF",
X"79",X"1E",X"1F",X"C1",X"C2",X"F0",X"2E",X"7F",X"27",X"99",X"8A",X"A1",X"86",X"A5",X"66",X"7F",
X"66",X"62",X"66",X"69",X"87",X"D5",X"B8",X"2F",X"27",X"98",X"5E",X"D9",X"07",X"E1",X"E1",X"BF",
X"5E",X"84",X"7F",X"8A",X"41",X"F5",X"68",X"AF",X"E4",X"61",X"7E",X"9D",X"07",X"E0",X"7A",X"3F",
X"E1",X"18",X"BE",X"1A",X"06",X"E0",X"A8",X"AF",X"9A",X"80",X"BE",X"79",X"07",X"A1",X"69",X"AF",
X"9A",X"59",X"98",X"96",X"76",X"56",X"F4",X"3F",X"79",X"4B",X"D0",X"F4",X"AD",X"0B",X"E0",X"3F",
X"3E",X"12",X"B4",X"2E",X"0B",X"83",X"F4",X"3F",X"8A",X"82",X"F0",X"3F",X"03",X"B4",X"AC",X"2F",
X"D0",X"BC",X"2D",X"4B",X"C0",X"B8",X"A8",X"3F",X"29",X"8D",X"67",X"99",X"8A",X"A0",X"B8",X"2F",
X"2A",X"25",X"9A",X"98",X"67",X"A1",X"E9",X"2F",X"66",X"62",X"66",X"67",X"66",X"79",X"99",X"9E",
X"98",X"A6",X"26",X"97",X"35",X"CD",X"89",X"D8",X"A2",X"8D",X"73",X"28",X"D7",X"35",X"A6",X"28",
X"9C",X"D7",X"29",X"73",X"29",X"73",X"28",X"CD",X"8C",X"9D",X"68",X"A3",X"32",X"98",X"A3",X"5C",
X"73",X"59",X"9D",X"8A",X"86",X"69",X"66",X"98",X"9D",X"8A",X"35",X"D7",X"63",X"28",X"CA",X"65",
X"A3",X"62",X"75",X"A3",X"29",X"68",X"A5",X"D7",X"35",X"CA",X"32",X"8A",X"29",X"8A",X"65",X"CA",
X"69",X"8C",X"9A",X"5C",X"A3",X"63",X"5A",X"5D",X"73",X"5C",X"D7",X"32",X"8A",X"35",X"9A",X"29",
X"8A",X"35",X"C9",X"A3",X"32",X"8A",X"36",X"28",X"D7",X"32",X"8C",X"A3",X"5C",X"D7",X"35",X"D7",
X"66",X"77",X"59",X"66",X"72",X"61",X"7A",X"AE",X"C1",X"A9",X"EA",X"43",X"E0",X"B0",X"3E",X"3F",
X"C5",X"D4",X"BE",X"1C",X"46",X"F4",X"2E",X"2F",X"D0",X"F9",X"A4",X"3F",X"02",X"E4",X"B8",X"3F",
X"C4",X"F8",X"2B",X"42",X"F0",X"A5",X"F5",X"2F",X"99",X"67",X"17",X"98",X"9D",X"D5",X"F5",X"2F",
X"66",X"66",X"56",X"99",X"D9",X"A5",X"A7",X"7A",X"5D",X"97",X"56",X"99",X"E5",X"A6",X"69",X"DD",
X"67",X"99",X"85",X"96",X"A6",X"68",X"7A",X"3B",X"89",X"8A",X"A2",X"85",X"E5",X"A4",X"7A",X"7F",
X"98",X"5E",X"8E",X"C0",X"F4",X"B4",X"2E",X"7F",X"C0",X"FC",X"68",X"2F",X"03",X"E0",X"B8",X"3F",
X"75",X"A9",X"3D",X"0F",X"57",X"83",X"F4",X"3F",X"A1",X"A5",X"B4",X"7D",X"1F",X"42",X"F4",X"2F",
X"A8",X"2E",X"1A",X"0E",X"D0",X"7F",X"43",X"F0",X"9E",X"4A",X"E0",X"1F",X"81",X"F4",X"EC",X"2F",
X"3F",X"06",X"A8",X"0B",X"82",X"A5",X"F8",X"2F",X"9D",X"D8",X"2E",X"07",X"93",X"C3",X"F4",X"3F",
X"2E",X"47",X"D0",X"B8",X"2D",X"6D",X"1F",X"C2",X"2E",X"0A",X"D0",X"EC",X"2A",X"2B",X"0B",X"C3",
X"99",X"D1",X"F4",X"6D",X"2D",X"3E",X"0B",X"D0",X"3D",X"0F",X"82",X"B0",X"B4",X"F0",X"F8",X"3D",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",
X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF",X"FF");
begin
process(clk)
begin
if rising_edge(clk) then
data <= rom_data(to_integer(unsigned(addr)));
end if;
end process;
end architecture;

View File

@@ -0,0 +1,35 @@
# ================================================================================
#
# Build ID Verilog Module Script
# Jeff Wiencrot - 8/1/2011
#
# Generates a Verilog module that contains a timestamp,
# from the current build. These values are available from the build_date, build_time,
# physical_address, and host_name output ports of the build_id module in the build_id.v
# Verilog source file.
#
# ================================================================================
proc generateBuildID_Verilog {} {
# Get the timestamp (see: http://www.altera.com/support/examples/tcl/tcl-date-time-stamp.html)
set buildDate [ clock format [ clock seconds ] -format %y%m%d ]
set buildTime [ clock format [ clock seconds ] -format %H%M%S ]
# Create a Verilog file for output
set outputFileName "rtl/build_id.v"
set outputFile [open $outputFileName "w"]
# Output the Verilog source
puts $outputFile "`define BUILD_DATE \"$buildDate\""
puts $outputFile "`define BUILD_TIME \"$buildTime\""
close $outputFile
# Send confirmation message to the Messages window
post_message "Generated build identification Verilog module: [pwd]/$outputFileName"
post_message "Date: $buildDate"
post_message "Time: $buildTime"
}
# Comment out this line to prevent the process from automatically executing when the file is sourced:
generateBuildID_Verilog

View File

@@ -0,0 +1,2 @@
`define BUILD_DATE "190409"
`define BUILD_TIME "015714"

View File

@@ -0,0 +1,71 @@
-------------------------------------------------------------------------------
--
-- 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 := 12
);
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;

View File

@@ -0,0 +1,182 @@
module frenzy_mist(
output LED,
output [5:0] VGA_R,
output [5:0] VGA_G,
output [5:0] VGA_B,
output VGA_HS,
output VGA_VS,
output AUDIO_L,
output AUDIO_R,
input SPI_SCK,
output SPI_DO,
input SPI_DI,
input SPI_SS2,
input SPI_SS3,
input CONF_DATA0,
input CLOCK_27
);
`include "rtl\build_id.v"
localparam CONF_STR = {
"Frenzy;;",
"O34,Scanlines,None,CRT 25%,CRT 50%,CRT 75%;",
"T6,Reset;",
"V,v1.20.",`BUILD_DATE
};
assign LED = 1;
assign AUDIO_R = AUDIO_L;
wire clk_20, clk_10, clk_5;
pll pll(
.inclk0(CLOCK_27),
.areset(0),
.c0(clk_20),
.c1(clk_10),
.c2(clk_5)
);
wire [31:0] status;
wire [1:0] buttons;
wire [1:0] switches;
wire [9:0] kbjoy;
wire [7:0] joystick_0;
wire [7:0] joystick_1;
wire scandoublerD;
wire ypbpr;
wire [10:0] ps2_key;
wire hs, vs;
wire hb, vb;
wire blankn = ~(hb | vb);
wire r, g, b;
wire [15:0] audio;
berzerk berzerk(
.clock_10(clk_10),
.reset(status[0] | status[6] | buttons[1]),
.video_r(r),
.video_g(g),
.video_b(b),
.video_hi(),
.video_clk(),
.video_csync(),
.video_hs(hs),
.video_vs(vs),
.video_hb(hb),
.video_vb(vb),
.audio_out(audio),
.start2(btn_two_players),
.start1(btn_one_player),
.coin1(btn_coin),
.cocktail(1'b0),
.right1(m_right),
.left1(m_left),
.down1(m_down),
.up1(m_up),
.fire1(m_fire),
.right2(m_right),
.left2(m_left),
.down2(m_down),
.up2(m_up),
.fire2(m_fire),
.ledr(),
.dbg_cpu_di(),
.dbg_cpu_addr(),
.dbg_cpu_addr_latch()
);
video_mixer video_mixer(
.clk_sys(clk_20),
.ce_pix(clk_5),
.ce_pix_actual(clk_5),
.SPI_SCK(SPI_SCK),
.SPI_SS3(SPI_SS3),
.SPI_DI(SPI_DI),
.R(blankn ? {r,r,r} : "000"),
.G(blankn ? {g,g,g} : "000"),
.B(blankn ? {b,b,b} : "000"),
.HSync(hs),
.VSync(vs),
.VGA_R(VGA_R),
.VGA_G(VGA_G),
.VGA_B(VGA_B),
.VGA_VS(VGA_VS),
.VGA_HS(VGA_HS),
.scandoublerD(scandoublerD),
.scanlines(scandoublerD ? 2'b00 : status[4:3]),
.ypbpr(ypbpr),
.ypbpr_full(1),
.line_start(0),
.mono(0)
);
mist_io #(
.STRLEN(($size(CONF_STR)>>3)))
mist_io(
.clk_sys (clk_20 ),
.conf_str (CONF_STR ),
.SPI_SCK (SPI_SCK ),
.CONF_DATA0 (CONF_DATA0 ),
.SPI_SS2 (SPI_SS2 ),
.SPI_DO (SPI_DO ),
.SPI_DI (SPI_DI ),
.buttons (buttons ),
.switches (switches ),
.scandoublerD (scandoublerD ),
.ypbpr (ypbpr ),
.ps2_key (ps2_key ),
.joystick_0 (joystick_0 ),
.joystick_1 (joystick_1 ),
.status (status )
);
dac #(
.msbi_g(15))
dac(
.clk_i(clk_20),
.res_n_i(1),
.dac_i(audio),
.dac_o(AUDIO_L)
);
wire m_up = btn_up | joystick_0[3] | joystick_1[3];
wire m_down = btn_down | joystick_0[2] | joystick_1[2];
wire m_left = btn_left | joystick_0[1] | joystick_1[1];
wire m_right = btn_right | joystick_0[0] | joystick_1[0];
wire m_fire = btn_fire1 | joystick_0[4] | joystick_1[4];
wire m_bomb = btn_fire2 | joystick_0[5] | joystick_1[5];
reg btn_one_player = 0;
reg btn_two_players = 0;
reg btn_left = 0;
reg btn_right = 0;
reg btn_down = 0;
reg btn_up = 0;
reg btn_fire1 = 0;
reg btn_fire2 = 0;
reg btn_fire3 = 0;
reg btn_coin = 0;
wire pressed = ps2_key[9];
wire [7:0] code = ps2_key[7:0];
always @(posedge clk_20) begin
reg old_state;
old_state <= ps2_key[10];
if(old_state != ps2_key[10]) begin
case(code)
'h75: btn_up <= pressed; // up
'h72: btn_down <= pressed; // down
'h6B: btn_left <= pressed; // left
'h74: btn_right <= pressed; // right
'h76: btn_coin <= pressed; // ESC
'h05: btn_one_player <= pressed; // F1
'h06: btn_two_players <= pressed; // F2
'h14: btn_fire3 <= pressed; // ctrl
'h11: btn_fire2 <= pressed; // alt
'h29: btn_fire1 <= pressed; // Space
endcase
end
end
endmodule

View File

@@ -0,0 +1,84 @@
-- -----------------------------------------------------------------------
--
-- Syntiac's generic VHDL support files.
--
-- -----------------------------------------------------------------------
-- Copyright 2005-2008 by Peter Wendrich (pwsoft@syntiac.com)
-- http://www.syntiac.com/fpga64.html
--
-- Modified April 2016 by Dar (darfpga@aol.fr)
-- http://darfpga.blogspot.fr
-- Remove address register when writing
--
-- -----------------------------------------------------------------------
--
-- gen_rwram.vhd
--
-- -----------------------------------------------------------------------
--
-- generic ram.
--
-- -----------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.ALL;
-- -----------------------------------------------------------------------
entity gen_ram is
generic (
dWidth : integer := 8;
aWidth : integer := 10
);
port (
clk : in std_logic;
we : in std_logic;
addr : in std_logic_vector((aWidth-1) downto 0);
d : in std_logic_vector((dWidth-1) downto 0);
q : out std_logic_vector((dWidth-1) downto 0)
);
end entity;
-- -----------------------------------------------------------------------
architecture rtl of gen_ram is
subtype addressRange is integer range 0 to ((2**aWidth)-1);
type ramDef is array(addressRange) of std_logic_vector((dWidth-1) downto 0);
signal ram: ramDef;
signal rAddrReg : std_logic_vector((aWidth-1) downto 0);
signal qReg : std_logic_vector((dWidth-1) downto 0);
begin
-- -----------------------------------------------------------------------
-- Signals to entity interface
-- -----------------------------------------------------------------------
-- q <= qReg;
-- -----------------------------------------------------------------------
-- Memory write
-- -----------------------------------------------------------------------
process(clk)
begin
if rising_edge(clk) then
if we = '1' then
ram(to_integer(unsigned(addr))) <= d;
end if;
end if;
end process;
-- -----------------------------------------------------------------------
-- Memory read
-- -----------------------------------------------------------------------
process(clk)
begin
if rising_edge(clk) then
-- qReg <= ram(to_integer(unsigned(rAddrReg)));
-- rAddrReg <= addr;
---- qReg <= ram(to_integer(unsigned(addr)));
q <= ram(to_integer(unsigned(addr)));
end if;
end process;
--q <= ram(to_integer(unsigned(addr)));
end architecture;

View File

@@ -0,0 +1,454 @@
//
//
// 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

View File

@@ -0,0 +1,530 @@
//
// mist_io.v
//
// mist_io for the MiST board
// http://code.google.com/p/mist-board/
//
// Copyright (c) 2014 Till Harbaum <till@harbaum.org>
// Copyright (c) 2015-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/>.
//
///////////////////////////////////////////////////////////////////////
//
// 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 [31:0] joystick_2,
// output reg [31:0] joystick_3,
// output reg [31:0] joystick_4,
output reg [15:0] joystick_analog_0,
output reg [15:0] joystick_analog_1,
output [1:0] buttons,
output [1:0] switches,
output scandoublerD,
output ypbpr,
output reg [31:0] status,
// SD config
input sd_conf,
input sd_sdhc,
output [1:0] 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 [1:0] sd_rd,
input [1:0] 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,
// ps2 alternative interface.
// [8] - extended, [9] - pressed, [10] - toggles with every press/release
output reg [10:0] ps2_key = 0,
// [24] - toggles with every event
output reg [24:0] ps2_mouse = 0,
// ARM -> FPGA download
input ioctl_ce,
output reg ioctl_download = 0, // signal indicating an active download
output reg [7:0] ioctl_index, // menu index used to upload the file
output reg ioctl_wr = 0,
output reg [24:0] ioctl_addr,
output reg [7:0] ioctl_dout
);
reg [7:0] but_sw;
reg [2:0] stick_idx;
reg [1:0] mount_strobe = 0;
assign img_mounted = mount_strobe;
assign buttons = but_sw[1:0];
assign switches = but_sw[3:2];
assign scandoublerD = but_sw[4];
assign ypbpr = but_sw[5];
// 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 drive_sel = sd_rd[1] | sd_wr[1];
wire [7:0] sd_cmd = { 4'h6, sd_conf, sd_sdhc, sd_wr[drive_sel], sd_rd[drive_sel] };
reg [7:0] cmd;
reg [2:0] bit_cnt; // counts bits 0-7 0-7 ...
reg [9:0] byte_cnt; // counts bytes
reg spi_do;
assign SPI_DO = CONF_DATA0 ? 1'bZ : spi_do;
reg [7:0] spi_data_out;
// SPI transmitter
always@(negedge SPI_SCK) spi_do <= spi_data_out[~bit_cnt];
reg [7:0] spi_data_in;
reg spi_data_ready = 0;
// SPI receiver
always@(posedge SPI_SCK or posedge CONF_DATA0) begin
reg [6:0] sbuf;
reg [31:0] sd_lba_r;
reg drive_sel_r;
if(CONF_DATA0) begin
bit_cnt <= 0;
byte_cnt <= 0;
spi_data_out <= core_type;
end
else
begin
bit_cnt <= bit_cnt + 1'd1;
sbuf <= {sbuf[5:0], SPI_DI};
// finished reading command byte
if(bit_cnt == 7) begin
if(!byte_cnt) cmd <= {sbuf, SPI_DI};
spi_data_in <= {sbuf, SPI_DI};
spi_data_ready <= ~spi_data_ready;
if(~&byte_cnt) byte_cnt <= byte_cnt + 8'd1;
spi_data_out <= 0;
case({(!byte_cnt) ? {sbuf, SPI_DI} : cmd})
// reading config string
8'h14: if(byte_cnt < STRLEN) spi_data_out <= conf_str[(STRLEN - byte_cnt - 1)<<3 +:8];
// reading sd card status
8'h16: if(byte_cnt == 0) begin
spi_data_out <= sd_cmd;
sd_lba_r <= sd_lba;
drive_sel_r <= drive_sel;
end else if (byte_cnt == 1) begin
spi_data_out <= drive_sel_r;
end else if(byte_cnt < 6) spi_data_out <= sd_lba_r[(5-byte_cnt)<<3 +:8];
// reading sd card write data
8'h18: spi_data_out <= sd_buff_din;
endcase
end
end
end
reg [31:0] ps2_key_raw = 0;
wire pressed = (ps2_key_raw[15:8] != 8'hf0);
wire extended = (~pressed ? (ps2_key_raw[23:16] == 8'he0) : (ps2_key_raw[15:8] == 8'he0));
// transfer to clk_sys domain
always@(posedge clk_sys) begin
reg old_ss1, old_ss2;
reg old_ready1, old_ready2;
reg [2:0] b_wr;
reg got_ps2 = 0;
old_ss1 <= CONF_DATA0;
old_ss2 <= old_ss1;
old_ready1 <= spi_data_ready;
old_ready2 <= old_ready1;
sd_buff_wr <= b_wr[0];
if(b_wr[2] && (~&sd_buff_addr)) sd_buff_addr <= sd_buff_addr + 1'b1;
b_wr <= (b_wr<<1);
if(old_ss2) begin
got_ps2 <= 0;
sd_ack <= 0;
sd_ack_conf <= 0;
sd_buff_addr <= 0;
if(got_ps2) begin
if(cmd == 4) ps2_mouse[24] <= ~ps2_mouse[24];
if(cmd == 5) begin
ps2_key <= {~ps2_key[10], pressed, extended, ps2_key_raw[7:0]};
if(ps2_key_raw == 'hE012E07C) ps2_key[9:0] <= 'h37C; // prnscr pressed
if(ps2_key_raw == 'h7CE0F012) ps2_key[9:0] <= 'h17C; // prnscr released
if(ps2_key_raw == 'hF014F077) ps2_key[9:0] <= 'h377; // pause pressed
end
end
end
else
if(old_ready2 ^ old_ready1) begin
if(cmd == 8'h18 && ~&sd_buff_addr) sd_buff_addr <= sd_buff_addr + 1'b1;
if(byte_cnt < 2) begin
if (cmd == 8'h19) sd_ack_conf <= 1;
if((cmd == 8'h17) || (cmd == 8'h18)) sd_ack <= 1;
mount_strobe <= 0;
if(cmd == 5) ps2_key_raw <= 0;
end else begin
case(cmd)
// buttons and switches
8'h01: but_sw <= spi_data_in;
8'h02: joystick_0 <= spi_data_in;
8'h03: joystick_1 <= spi_data_in;
// 8'h60: if (byte_cnt < 5) joystick_0[(byte_cnt-1)<<3 +:8] <= spi_data_in;
// 8'h61: if (byte_cnt < 5) joystick_1[(byte_cnt-1)<<3 +:8] <= spi_data_in;
// 8'h62: if (byte_cnt < 5) joystick_2[(byte_cnt-1)<<3 +:8] <= spi_data_in;
// 8'h63: if (byte_cnt < 5) joystick_3[(byte_cnt-1)<<3 +:8] <= spi_data_in;
// 8'h64: if (byte_cnt < 5) joystick_4[(byte_cnt-1)<<3 +:8] <= spi_data_in;
// store incoming ps2 mouse bytes
8'h04: begin
got_ps2 <= 1;
case(byte_cnt)
2: ps2_mouse[7:0] <= spi_data_in;
3: ps2_mouse[15:8] <= spi_data_in;
4: ps2_mouse[23:16] <= spi_data_in;
endcase
ps2_mouse_fifo[ps2_mouse_wptr] <= spi_data_in;
ps2_mouse_wptr <= ps2_mouse_wptr + 1'd1;
end
// store incoming ps2 keyboard bytes
8'h05: begin
got_ps2 <= 1;
ps2_key_raw[31:0] <= {ps2_key_raw[23:0], spi_data_in};
ps2_kbd_fifo[ps2_kbd_wptr] <= spi_data_in;
ps2_kbd_wptr <= ps2_kbd_wptr + 1'd1;
end
8'h15: status[7:0] <= spi_data_in;
// 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_data_in;
b_wr <= 1;
end
// joystick analog
8'h1a: begin
// first byte is joystick index
if(byte_cnt == 2) stick_idx <= spi_data_in[2:0];
else if(byte_cnt == 3) begin
// second byte is x axis
if(stick_idx == 0) joystick_analog_0[15:8] <= spi_data_in;
else if(stick_idx == 1) joystick_analog_1[15:8] <= spi_data_in;
end else if(byte_cnt == 4) begin
// third byte is y axis
if(stick_idx == 0) joystick_analog_0[7:0] <= spi_data_in;
else if(stick_idx == 1) joystick_analog_1[7:0] <= spi_data_in;
end
end
// notify image selection
8'h1c: mount_strobe[spi_data_in[0]] <= 1;
// send image info
8'h1d: if(byte_cnt<6) img_size[(byte_cnt-2)<<3 +:8] <= spi_data_in;
// status, 32bit version
8'h1e: if(byte_cnt<6) status[(byte_cnt-2)<<3 +:8] <= spi_data_in;
default: ;
endcase
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;
reg rdownload = 0;
// 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
// don't shift in last bit. It is evaluated directly
// when writing to ram
if(cnt != 15) sbuf <= { sbuf[5:0], SPI_DI};
// 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
case(ioctl_index[4:0])
1: addr <= 25'h200000; // TRD buffer at 2MB
2: addr <= 25'h400000; // tape buffer at 4MB
default: addr <= 25'h150000; // boot rom
endcase
rdownload <= 1;
end else begin
addr_w <= addr;
rdownload <= 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};
addr <= addr + 1'd1;
rclk <= ~rclk;
end
// expose file (menu) index
if((cmd == UIO_FILE_INDEX) && (cnt == 15)) ioctl_index <= {sbuf, SPI_DI};
end
end
// transfer to ioctl_clk domain.
// ioctl_index is set before ioctl_download, so it's stable already
always@(posedge clk_sys) begin
reg rclkD, rclkD2;
if(ioctl_ce) begin
ioctl_download <= rdownload;
rclkD <= rclk;
rclkD2 <= rclkD;
ioctl_wr <= 0;
if(rclkD != rclkD2) begin
ioctl_dout <= data_w;
ioctl_addr <= addr_w;
ioctl_wr <= 1;
end
end
end
endmodule

View File

@@ -0,0 +1,194 @@
// 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

View File

@@ -0,0 +1,4 @@
set_global_assignment -name IP_TOOL_NAME "ALTPLL"
set_global_assignment -name IP_TOOL_VERSION "13.0"
set_global_assignment -name VERILOG_FILE [file join $::quartus(qip_path) "pll.v"]
set_global_assignment -name MISC_FILE [file join $::quartus(qip_path) "pll.ppf"]

View File

@@ -0,0 +1,376 @@
// megafunction wizard: %ALTPLL%
// GENERATION: STANDARD
// VERSION: WM1.0
// MODULE: altpll
// ============================================================
// File Name: pll.v
// Megafunction Name(s):
// altpll
//
// Simulation Library Files(s):
// altera_mf
// ============================================================
// ************************************************************
// THIS IS A WIZARD-GENERATED FILE. DO NOT EDIT THIS FILE!
//
// 13.0.1 Build 232 06/12/2013 SP 1 SJ Full Version
// ************************************************************
//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.
// synopsys translate_off
`timescale 1 ps / 1 ps
// synopsys translate_on
module pll (
areset,
inclk0,
c0,
c1,
c2,
locked);
input areset;
input inclk0;
output c0;
output c1;
output c2;
output locked;
`ifndef ALTERA_RESERVED_QIS
// synopsys translate_off
`endif
tri0 areset;
`ifndef ALTERA_RESERVED_QIS
// synopsys translate_on
`endif
wire [4:0] sub_wire0;
wire sub_wire2;
wire [0:0] sub_wire7 = 1'h0;
wire [2:2] sub_wire4 = sub_wire0[2:2];
wire [0:0] sub_wire3 = sub_wire0[0:0];
wire [1:1] sub_wire1 = sub_wire0[1:1];
wire c1 = sub_wire1;
wire locked = sub_wire2;
wire c0 = sub_wire3;
wire c2 = sub_wire4;
wire sub_wire5 = inclk0;
wire [1:0] sub_wire6 = {sub_wire7, sub_wire5};
altpll altpll_component (
.areset (areset),
.inclk (sub_wire6),
.clk (sub_wire0),
.locked (sub_wire2),
.activeclock (),
.clkbad (),
.clkena ({6{1'b1}}),
.clkloss (),
.clkswitch (1'b0),
.configupdate (1'b0),
.enable0 (),
.enable1 (),
.extclk (),
.extclkena ({4{1'b1}}),
.fbin (1'b1),
.fbmimicbidir (),
.fbout (),
.fref (),
.icdrclk (),
.pfdena (1'b1),
.phasecounterselect ({4{1'b1}}),
.phasedone (),
.phasestep (1'b1),
.phaseupdown (1'b1),
.pllena (1'b1),
.scanaclr (1'b0),
.scanclk (1'b0),
.scanclkena (1'b1),
.scandata (1'b0),
.scandataout (),
.scandone (),
.scanread (1'b0),
.scanwrite (1'b0),
.sclkout0 (),
.sclkout1 (),
.vcooverrange (),
.vcounderrange ());
defparam
altpll_component.bandwidth_type = "AUTO",
altpll_component.clk0_divide_by = 27,
altpll_component.clk0_duty_cycle = 50,
altpll_component.clk0_multiply_by = 20,
altpll_component.clk0_phase_shift = "0",
altpll_component.clk1_divide_by = 27,
altpll_component.clk1_duty_cycle = 50,
altpll_component.clk1_multiply_by = 10,
altpll_component.clk1_phase_shift = "0",
altpll_component.clk2_divide_by = 27,
altpll_component.clk2_duty_cycle = 50,
altpll_component.clk2_multiply_by = 5,
altpll_component.clk2_phase_shift = "0",
altpll_component.compensate_clock = "CLK0",
altpll_component.inclk0_input_frequency = 37037,
altpll_component.intended_device_family = "Cyclone III",
altpll_component.lpm_hint = "CBX_MODULE_PREFIX=pll",
altpll_component.lpm_type = "altpll",
altpll_component.operation_mode = "NORMAL",
altpll_component.pll_type = "AUTO",
altpll_component.port_activeclock = "PORT_UNUSED",
altpll_component.port_areset = "PORT_USED",
altpll_component.port_clkbad0 = "PORT_UNUSED",
altpll_component.port_clkbad1 = "PORT_UNUSED",
altpll_component.port_clkloss = "PORT_UNUSED",
altpll_component.port_clkswitch = "PORT_UNUSED",
altpll_component.port_configupdate = "PORT_UNUSED",
altpll_component.port_fbin = "PORT_UNUSED",
altpll_component.port_inclk0 = "PORT_USED",
altpll_component.port_inclk1 = "PORT_UNUSED",
altpll_component.port_locked = "PORT_USED",
altpll_component.port_pfdena = "PORT_UNUSED",
altpll_component.port_phasecounterselect = "PORT_UNUSED",
altpll_component.port_phasedone = "PORT_UNUSED",
altpll_component.port_phasestep = "PORT_UNUSED",
altpll_component.port_phaseupdown = "PORT_UNUSED",
altpll_component.port_pllena = "PORT_UNUSED",
altpll_component.port_scanaclr = "PORT_UNUSED",
altpll_component.port_scanclk = "PORT_UNUSED",
altpll_component.port_scanclkena = "PORT_UNUSED",
altpll_component.port_scandata = "PORT_UNUSED",
altpll_component.port_scandataout = "PORT_UNUSED",
altpll_component.port_scandone = "PORT_UNUSED",
altpll_component.port_scanread = "PORT_UNUSED",
altpll_component.port_scanwrite = "PORT_UNUSED",
altpll_component.port_clk0 = "PORT_USED",
altpll_component.port_clk1 = "PORT_USED",
altpll_component.port_clk2 = "PORT_USED",
altpll_component.port_clk3 = "PORT_UNUSED",
altpll_component.port_clk4 = "PORT_UNUSED",
altpll_component.port_clk5 = "PORT_UNUSED",
altpll_component.port_clkena0 = "PORT_UNUSED",
altpll_component.port_clkena1 = "PORT_UNUSED",
altpll_component.port_clkena2 = "PORT_UNUSED",
altpll_component.port_clkena3 = "PORT_UNUSED",
altpll_component.port_clkena4 = "PORT_UNUSED",
altpll_component.port_clkena5 = "PORT_UNUSED",
altpll_component.port_extclk0 = "PORT_UNUSED",
altpll_component.port_extclk1 = "PORT_UNUSED",
altpll_component.port_extclk2 = "PORT_UNUSED",
altpll_component.port_extclk3 = "PORT_UNUSED",
altpll_component.self_reset_on_loss_lock = "OFF",
altpll_component.width_clock = 5;
endmodule
// ============================================================
// CNX file retrieval info
// ============================================================
// Retrieval info: PRIVATE: ACTIVECLK_CHECK STRING "0"
// Retrieval info: PRIVATE: BANDWIDTH STRING "1.000"
// Retrieval info: PRIVATE: BANDWIDTH_FEATURE_ENABLED STRING "1"
// Retrieval info: PRIVATE: BANDWIDTH_FREQ_UNIT STRING "MHz"
// Retrieval info: PRIVATE: BANDWIDTH_PRESET STRING "Low"
// Retrieval info: PRIVATE: BANDWIDTH_USE_AUTO STRING "1"
// Retrieval info: PRIVATE: BANDWIDTH_USE_PRESET STRING "0"
// Retrieval info: PRIVATE: CLKBAD_SWITCHOVER_CHECK STRING "0"
// Retrieval info: PRIVATE: CLKLOSS_CHECK STRING "0"
// Retrieval info: PRIVATE: CLKSWITCH_CHECK STRING "0"
// Retrieval info: PRIVATE: CNX_NO_COMPENSATE_RADIO STRING "0"
// Retrieval info: PRIVATE: CREATE_CLKBAD_CHECK STRING "0"
// Retrieval info: PRIVATE: CREATE_INCLK1_CHECK STRING "0"
// Retrieval info: PRIVATE: CUR_DEDICATED_CLK STRING "c0"
// Retrieval info: PRIVATE: CUR_FBIN_CLK STRING "c0"
// Retrieval info: PRIVATE: DEVICE_SPEED_GRADE STRING "8"
// Retrieval info: PRIVATE: DIV_FACTOR0 NUMERIC "27"
// Retrieval info: PRIVATE: DIV_FACTOR1 NUMERIC "27"
// Retrieval info: PRIVATE: DIV_FACTOR2 NUMERIC "27"
// Retrieval info: PRIVATE: DUTY_CYCLE0 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 "20.000000"
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE1 STRING "10.000000"
// Retrieval info: PRIVATE: EFF_OUTPUT_FREQ_VALUE2 STRING "5.000000"
// Retrieval info: PRIVATE: EXPLICIT_SWITCHOVER_COUNTER STRING "0"
// Retrieval info: PRIVATE: EXT_FEEDBACK_RADIO STRING "0"
// Retrieval info: PRIVATE: GLOCKED_COUNTER_EDIT_CHANGED STRING "1"
// Retrieval info: PRIVATE: GLOCKED_FEATURE_ENABLED STRING "0"
// Retrieval info: PRIVATE: GLOCKED_MODE_CHECK STRING "0"
// Retrieval info: PRIVATE: GLOCK_COUNTER_EDIT NUMERIC "1048575"
// Retrieval info: PRIVATE: HAS_MANUAL_SWITCHOVER STRING "1"
// Retrieval info: PRIVATE: INCLK0_FREQ_EDIT STRING "27.000"
// Retrieval info: PRIVATE: INCLK0_FREQ_UNIT_COMBO STRING "MHz"
// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT STRING "100.000"
// Retrieval info: PRIVATE: INCLK1_FREQ_EDIT_CHANGED STRING "1"
// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_CHANGED STRING "1"
// Retrieval info: PRIVATE: INCLK1_FREQ_UNIT_COMBO STRING "MHz"
// Retrieval info: PRIVATE: INTENDED_DEVICE_FAMILY STRING "Cyclone III"
// Retrieval info: PRIVATE: INT_FEEDBACK__MODE_RADIO STRING "1"
// Retrieval info: PRIVATE: LOCKED_OUTPUT_CHECK STRING "1"
// Retrieval info: PRIVATE: LONG_SCAN_RADIO STRING "1"
// Retrieval info: PRIVATE: LVDS_MODE_DATA_RATE STRING "Not Available"
// 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_UNIT1 STRING "deg"
// Retrieval info: PRIVATE: LVDS_PHASE_SHIFT_UNIT2 STRING "ps"
// Retrieval info: PRIVATE: MIG_DEVICE_SPEED_GRADE STRING "Any"
// Retrieval info: PRIVATE: MIRROR_CLK0 STRING "0"
// Retrieval info: PRIVATE: MIRROR_CLK1 STRING "0"
// Retrieval info: PRIVATE: MIRROR_CLK2 STRING "0"
// Retrieval info: PRIVATE: MULT_FACTOR0 NUMERIC "20"
// Retrieval info: PRIVATE: MULT_FACTOR1 NUMERIC "10"
// Retrieval info: PRIVATE: MULT_FACTOR2 NUMERIC "5"
// Retrieval info: PRIVATE: NORMAL_MODE_RADIO STRING "1"
// Retrieval info: PRIVATE: OUTPUT_FREQ0 STRING "20.00000000"
// Retrieval info: PRIVATE: OUTPUT_FREQ1 STRING "10.00000000"
// Retrieval info: PRIVATE: OUTPUT_FREQ2 STRING "5.00000000"
// 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_UNIT0 STRING "MHz"
// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT1 STRING "MHz"
// Retrieval info: PRIVATE: OUTPUT_FREQ_UNIT2 STRING "MHz"
// Retrieval info: PRIVATE: PHASE_RECONFIG_FEATURE_ENABLED STRING "1"
// Retrieval info: PRIVATE: PHASE_RECONFIG_INPUTS_CHECK STRING "0"
// Retrieval info: PRIVATE: PHASE_SHIFT0 STRING "0.00000000"
// Retrieval info: PRIVATE: PHASE_SHIFT1 STRING "0.00000000"
// Retrieval info: PRIVATE: PHASE_SHIFT2 STRING "0.00000000"
// Retrieval info: PRIVATE: PHASE_SHIFT_STEP_ENABLED_CHECK STRING "0"
// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT0 STRING "deg"
// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT1 STRING "deg"
// Retrieval info: PRIVATE: PHASE_SHIFT_UNIT2 STRING "deg"
// Retrieval info: PRIVATE: PLL_ADVANCED_PARAM_CHECK STRING "0"
// Retrieval info: PRIVATE: PLL_ARESET_CHECK STRING "1"
// Retrieval info: PRIVATE: PLL_AUTOPLL_CHECK NUMERIC "1"
// Retrieval info: PRIVATE: PLL_ENHPLL_CHECK NUMERIC "0"
// Retrieval info: PRIVATE: PLL_FASTPLL_CHECK NUMERIC "0"
// Retrieval info: PRIVATE: PLL_FBMIMIC_CHECK STRING "0"
// Retrieval info: PRIVATE: PLL_LVDS_PLL_CHECK NUMERIC "0"
// Retrieval info: PRIVATE: PLL_PFDENA_CHECK STRING "0"
// Retrieval info: PRIVATE: PLL_TARGET_HARCOPY_CHECK NUMERIC "0"
// Retrieval info: PRIVATE: PRIMARY_CLK_COMBO STRING "inclk0"
// Retrieval info: PRIVATE: RECONFIG_FILE STRING "pll.mif"
// Retrieval info: PRIVATE: SACN_INPUTS_CHECK STRING "0"
// Retrieval info: PRIVATE: SCAN_FEATURE_ENABLED STRING "1"
// Retrieval info: PRIVATE: SELF_RESET_LOCK_LOSS STRING "0"
// Retrieval info: PRIVATE: SHORT_SCAN_RADIO STRING "0"
// Retrieval info: PRIVATE: SPREAD_FEATURE_ENABLED STRING "0"
// Retrieval info: PRIVATE: SPREAD_FREQ STRING "50.000"
// Retrieval info: PRIVATE: SPREAD_FREQ_UNIT STRING "KHz"
// Retrieval info: PRIVATE: SPREAD_PERCENT STRING "0.500"
// Retrieval info: PRIVATE: SPREAD_USE STRING "0"
// Retrieval info: PRIVATE: SRC_SYNCH_COMP_RADIO STRING "0"
// Retrieval info: PRIVATE: STICKY_CLK0 STRING "1"
// Retrieval info: PRIVATE: STICKY_CLK1 STRING "1"
// Retrieval info: PRIVATE: STICKY_CLK2 STRING "1"
// Retrieval info: PRIVATE: SWITCHOVER_COUNT_EDIT NUMERIC "1"
// Retrieval info: PRIVATE: SWITCHOVER_FEATURE_ENABLED STRING "1"
// Retrieval info: PRIVATE: SYNTH_WRAPPER_GEN_POSTFIX STRING "0"
// Retrieval info: PRIVATE: USE_CLK0 STRING "1"
// Retrieval info: PRIVATE: USE_CLK1 STRING "1"
// Retrieval info: PRIVATE: USE_CLK2 STRING "1"
// Retrieval info: PRIVATE: USE_CLKENA0 STRING "0"
// Retrieval info: PRIVATE: USE_CLKENA1 STRING "0"
// Retrieval info: PRIVATE: USE_CLKENA2 STRING "0"
// Retrieval info: PRIVATE: USE_MIL_SPEED_GRADE NUMERIC "0"
// Retrieval info: PRIVATE: ZERO_DELAY_RADIO STRING "0"
// Retrieval info: LIBRARY: altera_mf altera_mf.altera_mf_components.all
// Retrieval info: CONSTANT: BANDWIDTH_TYPE STRING "AUTO"
// Retrieval info: CONSTANT: CLK0_DIVIDE_BY NUMERIC "27"
// Retrieval info: CONSTANT: CLK0_DUTY_CYCLE NUMERIC "50"
// Retrieval info: CONSTANT: CLK0_MULTIPLY_BY NUMERIC "20"
// Retrieval info: CONSTANT: CLK0_PHASE_SHIFT STRING "0"
// Retrieval info: CONSTANT: CLK1_DIVIDE_BY NUMERIC "27"
// Retrieval info: CONSTANT: CLK1_DUTY_CYCLE NUMERIC "50"
// Retrieval info: CONSTANT: CLK1_MULTIPLY_BY NUMERIC "10"
// Retrieval info: CONSTANT: CLK1_PHASE_SHIFT STRING "0"
// Retrieval info: CONSTANT: CLK2_DIVIDE_BY NUMERIC "27"
// Retrieval info: CONSTANT: CLK2_DUTY_CYCLE NUMERIC "50"
// Retrieval info: CONSTANT: CLK2_MULTIPLY_BY NUMERIC "5"
// Retrieval info: CONSTANT: CLK2_PHASE_SHIFT STRING "0"
// Retrieval info: CONSTANT: COMPENSATE_CLOCK STRING "CLK0"
// Retrieval info: CONSTANT: INCLK0_INPUT_FREQUENCY NUMERIC "37037"
// Retrieval info: CONSTANT: INTENDED_DEVICE_FAMILY STRING "Cyclone III"
// Retrieval info: CONSTANT: LPM_TYPE STRING "altpll"
// Retrieval info: CONSTANT: OPERATION_MODE STRING "NORMAL"
// Retrieval info: CONSTANT: PLL_TYPE STRING "AUTO"
// Retrieval info: CONSTANT: PORT_ACTIVECLOCK STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_ARESET STRING "PORT_USED"
// Retrieval info: CONSTANT: PORT_CLKBAD0 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_CLKBAD1 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_CLKLOSS STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_CLKSWITCH STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_CONFIGUPDATE STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_FBIN STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_INCLK0 STRING "PORT_USED"
// Retrieval info: CONSTANT: PORT_INCLK1 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_LOCKED STRING "PORT_USED"
// Retrieval info: CONSTANT: PORT_PFDENA STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_PHASECOUNTERSELECT STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_PHASEDONE STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_PHASESTEP STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_PHASEUPDOWN STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_PLLENA STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_SCANACLR STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_SCANCLK STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_SCANCLKENA STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_SCANDATA STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_SCANDATAOUT STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_SCANDONE STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_SCANREAD STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_SCANWRITE STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_clk0 STRING "PORT_USED"
// Retrieval info: CONSTANT: PORT_clk1 STRING "PORT_USED"
// Retrieval info: CONSTANT: PORT_clk2 STRING "PORT_USED"
// Retrieval info: CONSTANT: PORT_clk3 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_clk4 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_clk5 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_clkena0 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_clkena1 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_clkena2 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_clkena3 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_clkena4 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_clkena5 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_extclk0 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_extclk1 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_extclk2 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: PORT_extclk3 STRING "PORT_UNUSED"
// Retrieval info: CONSTANT: SELF_RESET_ON_LOSS_LOCK STRING "OFF"
// Retrieval info: CONSTANT: WIDTH_CLOCK NUMERIC "5"
// Retrieval info: USED_PORT: @clk 0 0 5 0 OUTPUT_CLK_EXT VCC "@clk[4..0]"
// 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: 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: inclk0 0 0 0 0 INPUT_CLK_EXT GND "inclk0"
// Retrieval info: USED_PORT: locked 0 0 0 0 OUTPUT GND "locked"
// 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 0 inclk0 0 0 0 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: c2 0 0 0 0 @clk 0 0 1 2
// Retrieval info: CONNECT: locked 0 0 0 0 @locked 0 0 0 0
// 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.inc FALSE
// Retrieval info: GEN_FILE: TYPE_NORMAL pll.cmp FALSE
// Retrieval info: GEN_FILE: TYPE_NORMAL pll.bsf FALSE
// Retrieval info: GEN_FILE: TYPE_NORMAL pll_inst.v FALSE
// Retrieval info: GEN_FILE: TYPE_NORMAL pll_bb.v FALSE
// Retrieval info: LIB_FILE: altera_mf
// Retrieval info: CBX_MODULE_PREFIX: ON

View File

@@ -0,0 +1,195 @@
//
// 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
);
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
`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 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

View File

@@ -0,0 +1,134 @@
---------------------------------------------------------------------------------
-- Berzerk Video generator - Dar - Juin 2018
---------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity video_gen is
port(
clock : in std_logic;
reset : in std_logic;
ena_pixel : in std_logic;
hsync : out std_logic;
vsync : out std_logic;
csync : out std_logic;
hblank : out std_logic;
vblank : out std_logic;
hcnt_o : out std_logic_vector(8 downto 0);
vcnt_o : out std_logic_vector(8 downto 0)
);
end video_gen;
architecture struct of video_gen is
signal hcnt : std_logic_vector(8 downto 0);
signal vcnt : std_logic_vector(8 downto 0);
signal hsync0 : std_logic;
signal hsync1 : std_logic;
signal hsync2 : std_logic;
begin
hcnt_o <= hcnt;
vcnt_o <= vcnt;
hsync <= hsync0;
-- Compteur horizontal
-- 1C0..1FF-000..0FF : 64+256 = 320 pixels
-- 448..511-000..255
-- Compteur vertical
-- 1DA..1FF-020..0FF : 38+224 = 262 lignes
-- 474..511-032..255
-- Synchro horizontale : hcnt=[] (xx pixels)
-- Synchro verticale : vcnt=[] ( x lignes)
process(clock,reset)
begin
if reset = '1' then
hcnt <= (others=>'0');
vcnt <= (others=>'0');
else
if rising_edge(clock) then
if ena_pixel = '1' then
if hcnt = std_logic_vector(to_unsigned(511,9)) then -- 511
hcnt <= (others=>'0');
else
if hcnt = std_logic_vector(to_unsigned(255,9)) then -- 255
hcnt <= std_logic_vector(to_unsigned(448,9)); -- 448
else
hcnt <= hcnt + '1';
end if;
end if;
if hcnt = std_logic_vector(to_unsigned(255,9)) then
if vcnt = std_logic_vector(to_unsigned(511,9)) then
vcnt <= std_logic_vector(to_unsigned(32,9));
else
if vcnt = 255 then
vcnt <= std_logic_vector(to_unsigned(474,9));
else
vcnt <= vcnt + '1';
end if;
end if;
end if;
if hcnt = std_logic_vector(to_unsigned(448+16,9)) then
-- vblank_r <= vblank;
end if;
if hcnt = (466+ 0) then hsync0 <= '0';
elsif hcnt = (466+24) then hsync0 <= '1';
end if;
if hcnt = (466+ 0) then hsync1 <= '0';
elsif hcnt = (466+11) then hsync1 <= '1';
elsif hcnt = (466 +160-512) then hsync1 <= '0';
elsif hcnt = (466+11+160-512) then hsync1 <= '1';
end if;
if hcnt = (466) then hsync2 <= '0';
elsif hcnt = (466-10) then hsync2 <= '1';
end if;
if vcnt = (490-7) then csync <= hsync1;
elsif vcnt = (491-7) then csync <= hsync1;
elsif vcnt = (492-7) then csync <= hsync1;
elsif vcnt = (493-7) then csync <= hsync2;
elsif vcnt = (494-7) then csync <= hsync2;
elsif vcnt = (495-7) then csync <= hsync2;
elsif vcnt = (496-7) then csync <= hsync1;
elsif vcnt = (497-7) then csync <= hsync1;
elsif vcnt = (498-7) then csync <= hsync1;
else csync <= hsync0;
end if;
if vcnt = (490) then vsync <= '0';
elsif vcnt = (498) then vsync <= '1';
end if;
if hcnt = (448+8) then hblank <= '1';
elsif hcnt = (8) then hblank <= '0';
end if;
if vcnt = (474) then vblank <= '1';
elsif vcnt = (032) then vblank <= '0';
end if;
end if;
end if;
end if;
end process;
end architecture;

View File

@@ -0,0 +1,243 @@
//
//
// 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 = 480,
parameter HALF_DEPTH = 1,
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 scandoublerD,
// 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 = (scandoublerD ? R : R_sd);
wire [DWIDTH:0] gt = (scandoublerD ? G : G_sd);
wire [DWIDTH:0] bt = (scandoublerD ? 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 = (scandoublerD ? HSync : hs_sd);
wire vs = (scandoublerD ? 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 = (scandoublerD | ypbpr) ? 1'b1 : ~vs_sd;
assign VGA_HS = scandoublerD ? ~(HSync ^ VSync) : ypbpr ? ~(hs_sd ^ vs_sd) : ~hs_sd;
endmodule

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.