---------------------------------------------------------------------------------------------------
-- TOP_A7_LOGIC_ANALYZER.VHD
-- (C) 2025 JAPAN LOGIC DESIGN 日本ロジック設計
-- No unauthorized reproduction or AI training allowed.
-- Unauthorized reproduction prohibited.
---------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------
-- Ver : Date		: Description
-- 0.1 : 2026.01.01	: 1st Version
-- 0.2 : 2026.01.12	: FPGA-CLOCK:50MHz, シリアル通信:460800 BPS
-- 0.3 : 2026.01.30	: 波形の先頭の表示 '_' '~' が不安定になる不具合を修正
---------------------------------------------------------------------------------------------------
-- 概要：
-- ・16ch入力ロジックアナライザー
-- ・内部ロジックの波形モニターの他、入力にI/Oピンを接続すれば単体のロジアナとして使用可能。
-- ・ロジアナの制御はシリアル通信(UART)で行うため、FPGAの追加I/Oピンは２本のみ。
--   Digilent Inc.製、Cmod A7-35T(搭載FPGA:Artix-7)では、FPGAのシリアル通信(UART)ピンが
--   FTDI製FT2232(シリアル-USB変換LSI)を経由してUSBコネクタに接続されており、PCとはUSBで接続可能。
-- ・ESCシーケンスで画面を作成しており専用ソフトは不要。ターミナルソフト Tera Term 5 を使用する。
-- ・Cmod A7-35T 基板上のスイッチ入力[FPGAピン:B18]を、簡易型のRESETスイッチとしている。
-- 
---------------------------------------------------------------------------------------------------

-- Use IEEE library -------------------------------------------------------------------------------
library	IEEE;
use		IEEE.STD_LOGIC_1164.ALL;
use		IEEE.STD_LOGIC_ARITH.ALL;
use		IEEE.STD_LOGIC_UNSIGNED.ALL;
use		IEEE.NUMERIC_STD.ALL;			-- to_unsigned(character'pos( char_data ), 8 ));

-- エンティティ宣言 -------------------------------------------------------------------------------

entity TOP_A7_LOGIC_ANALYZER is
port (
	-- システム
	nRESET				: in	std_logic;						-- nRESET
	CLK_IN				: in	std_logic;						-- CLOCK 12MHz
	-- 波形入力
	SIG_IN_DATA			: in	std_logic_vector(15 downto 0);	-- 波形入力
	-- UART
	UART_RX				: in	std_logic;
	UART_TX				: out	std_logic
);
end TOP_A7_LOGIC_ANALYZER;

architecture RTL of TOP_A7_LOGIC_ANALYZER is ------------------------------------------------------

-- 固定値定義 -------------------------------------------------------------------------------------

-- UARTクロック分周比	50.0MHz/460800/2-1 = 53d = 35h
constant	CLOCK_DIV_VALUE		: std_logic_vector(15 downto 0)	:= X"0035";
-- トリガータイムアウト 100mS	50.0MHz/10-1 = 4999999d = 4C4B3Fh
constant	COUNT_TRIG_TIMEOUT	: std_logic_vector(23 downto 0)	:= X"4C4B3F";
-- 波形表示、横幅文字数
--	波形バッファは 256ワード分、この半分より小さい値であること
--	トリガー前／トリガー後に、それぞれこの値の数を取り込むため、波形バッファは2倍以上が必要
constant	COUNT_WAVE_WIDTH	: std_logic_vector(7 downto 0)	:= X"63";

-- 信号定義 ---------------------------------------------------------------------------------------

-- ステートマシン用 -----------------------------
-- S1
TYPE SIGNAL_STATUS_1 IS (	S1_WAIT_ENTER, S1_START_WAIT, S1_SCREEN_CLR, S1_SCREEN_CLR_L1, 
							S1_SCREEN_CLR_SEND, S1_SCREEN_CLR_SEND_L2, S1_TITLE_SET, S1_TITLE_SET_L, 
							S1_TITLE_SEND, S1_TITLE_SEND_L, S1_MENU_SET, S1_MENU_SET_L, 
							S1_MENU_SEND, S1_MENU_SEND_L, S1_SCALE_SET, S1_SCALE_SET_L, 
							S1_SCAE_SEND, S1_SCAE_SEND_L, S1_GET_WAVE_JUDGE, S1_GET_WAVE_DATA, 
							S1_GET_WAVE_DATA_L, S1_WAVE_DISP_JOB, S1_WAVEDATA_JOB, S1_TRIG_POINT_SET_L, 
							S1_SEND_TRIG_POINT, S1_SEND_TRIG_POINT_L, S1_WAVEDATA_SET, S1_WAVEDATA_SET_L, 
							S1_SEND_WAVEFORM, S1_SEND_WAVEFORM_L, S1_NEXT_WAVE, S1_TIME_WAIT, 
							S1_TIME_WAIT_L, S1_NEXT_LOOP );
SIGNAL S1_STATUS	: SIGNAL_STATUS_1;
-- S2
TYPE SIGNAL_STATUS_2 IS (	S2_START_WAIT, S2_LOOP, S2_END_CEHCK, S2_STATUS_END );
SIGNAL S2_STATUS	: SIGNAL_STATUS_2;
-- S3
TYPE SIGNAL_STATUS_3 IS (	S3_START_WAIT, S3_END_CHECK, S3_DATA_SEND, S3_LOOP, S3_ADD_INC, 
							S3_DUMMY1, S3_STATUS_END );
SIGNAL S3_STATUS	: SIGNAL_STATUS_3;
-- S4
TYPE SIGNAL_STATUS_4 IS (	S4_START_WAIT, S4_CH_COLOR, S4_CH_COLOR_N1, S4_CH_COLOR_N2, 
							S4_CH_COLOR_N3, S4_CH_COLOR_N4, S4_HANTEN_ON, S4_HANTEN_ON_N1, 
							S4_HANTEN_ON_N2, S4_HANTEN_ON_N3, S4_CH_NUMBER, S4_CH_NUM_1, 
							S4_CH_NUM_2, S4_CH_NUM_3, S4_CH_NUM_4, S4_CH_NUM_5, 
							S4_HANTEN_OFF, S4_HANTEN_OFF_N1, S4_HANTEN_OFF_N2, S4_HANTEN_OFF_N3, 
							S4_HANTEN_OFF_N4, S4_SIG_DATA_ST1, S4_SIG_DATA_ST2, S4_SIG_DATA_1BYTE, 
							S4_STATUS_CRLF, S4_STATUS_CRLF_2, S4_STATUS_00h, S4_STATUS_END );
SIGNAL S4_STATUS	: SIGNAL_STATUS_4;
-- S5
TYPE SIGNAL_STATUS_5 IS (	S5_START_WAIT, S5_PRE_ACQUIS, S5_PRE_ACQUIS_L, S5_TRIG_WAIT, 
							S5_TRIG_WAIT_L, S5_POST_ACQUIS, S5_POST_ACQUIS_L, S5_STATUS_END );
SIGNAL S5_STATUS	: SIGNAL_STATUS_5;
-- S6
TYPE SIGNAL_STATUS_6 IS (	S6_START_WAIT, S6_ATT_CLR, S6_ATT_CLR_L1, S6_ATT_CLR_SEND, 
							S6_ATT_CLR_SEND_L2, S6_JOB_START, S6_TRIG_2, S6_TRIG_3, 
							S6_TRIG_4, S6_TRIG_5, S6_TRIG_6, S6_TRIG_7, 
							S6_TRIG_8, S6_TRIG_9, S6_TRIG_10, S6_TRIG_11, 
							S6_EDGE_JOB, S6_EDGE_N1, S6_EDGE_N2, S6_EDGE_N3, 
							S6_EDGE_N4, S6_TRIG_TYPE_JOB, S6_TRIG_TYPE_N1, S6_TRIG_TYPE_N2, 
							S6_TRIG_TYPE_N3, S6_TRIG_TYPE_N4, S6_DIV_JOB, S6_DIV_N0, 
							S6_DIV_N1, S6_DIV_N2, S6_DIV_N3, S6_DIV_N4, 
							S6_DIV_N5, S6_DIV_N6, S6_DIV_N7, S6_DIV_N8, 
							S6_DIV_N9, S6_NEXT_CRLF, S6_NEXT_CRLF_2, S6_NEXT_00h, 
							S6_STATUS_END );
SIGNAL S6_STATUS	: SIGNAL_STATUS_6;
-- S7
TYPE SIGNAL_STATUS_7 IS (	S7_START_WAIT, S7_CH_COLOR, S7_CH_COLOR_N1, S7_CH_COLOR_N2, 
							S7_CH_COLOR_N3, S7_CH_COLOR_N4, S7_POSITION, S7_STATUS_L1, S7_STATUS_N1, 
							S7_STATUS_N2, S7_STATUS_N3, S7_STATUS_N4, S7_STATUS_N5, S7_STATUS_END );
SIGNAL S7_STATUS	: SIGNAL_STATUS_7;
-- S8
TYPE SIGNAL_STATUS_8 IS (	S8_START_WAIT, S8_ATT_CLR, S8_ATT_CLR_L1, S8_ATT_CLR_SEND, 
							S8_ATT_CLR_SEND_L2, S8_JOB_START, S8_UNIT_N1, S8_UNIT_N2, 
							S8_UNIT_N3, S8_UNIT_N4, S8_SCALE, 
							S8_SCALE_L1, S8_NEXT_CRLF, S8_NEXT_CRLF_2, S8_NEXT_CRLF_3, 
							S8_NEXT_00h, S8_STATUS_END );
SIGNAL S8_STATUS	: SIGNAL_STATUS_8;
-- S10
TYPE SIGNAL_STATUS_10 IS (	S10_START_WAIT, S10_JOB_START, S10_NEXT_1, S10_NEXT_2, S10_NEXT_3, 
							S10_NEXT_4, S10_STATUS_END );
SIGNAL S10_STATUS	: SIGNAL_STATUS_10;
-- S11
TYPE SIGNAL_STATUS_11 IS (	S11_START_WAIT, S11_JOB_START, S11_NEXT_1, S11_NEXT_2, S11_NEXT_3, 
							S11_NEXT_4, S11_STATUS_END );
SIGNAL S11_STATUS	: SIGNAL_STATUS_11;

-- 一般信号 -------------------------------------
signal TX_DATA_IN			: std_logic_vector(7 downto 0);
signal TX_SEND_START		: std_logic;
signal TX_SEND_END			: std_logic;
signal RX_DATA				: std_logic_vector(7 downto 0);
signal RX_PARITY_ODD_EVEN	: std_logic;
signal RX_PARITY_bit		: std_logic;
signal RX_RECIEVE_END		: std_logic;

signal SIG_IN_DATA_d1		: std_logic_vector(15 downto 0);
signal SIG_IN_DATA_d2		: std_logic_vector(15 downto 0);
signal SIG_IN_DATA_d3		: std_logic_vector(15 downto 0);
signal SIG_IN_DATA_d4		: std_logic_vector(15 downto 0);

signal RAM_DATA_OUT			: std_logic_vector(7 downto 0);
signal MESSAGE_ADD			: std_logic_vector(6 downto 0);

signal UART_BUF_WR_EN		: std_logic;
signal UART_BUF_WR_EN_S2	: std_logic;
signal UART_BUF_WR_EN_S4	: std_logic;
signal UART_BUF_WR_EN_S6	: std_logic;
signal UART_BUF_WR_EN_S7	: std_logic;
signal UART_BUF_WR_EN_S8	: std_logic;
signal UART_BUF_WR_EN_S10	: std_logic;
signal UART_BUF_WR_EN_S11	: std_logic;
signal UART_BUF_ADD			: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S2		: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S3		: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S4		: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S6		: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S7		: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S8		: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S10		: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S11		: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S6_CLR	: std_logic;
signal UART_BUF_DATA_WR		: std_logic_vector(7 downto 0);
signal UART_BUF_DATA_WR_S2	: std_logic_vector(7 downto 0);
signal UART_BUF_DATA_WR_S4	: std_logic_vector(7 downto 0);
signal UART_BUF_DATA_WR_S6	: std_logic_vector(7 downto 0);
signal UART_BUF_DATA_WR_S7	: std_logic_vector(7 downto 0);
signal UART_BUF_DATA_WR_S8	: std_logic_vector(7 downto 0);
signal UART_BUF_DATA_WR_S10	: std_logic_vector(7 downto 0);
signal UART_BUF_DATA_WR_S11	: std_logic_vector(7 downto 0);
signal UART_BUF_DATA_RD		: std_logic_vector(7 downto 0);
signal UART_BUF_ADD_S8_CLR	: std_logic;

signal SIG_BUF_WR			: std_logic;
signal SIG_BUF_ADD			: std_logic_vector(7 downto 0);
signal SIG_BUF_ADD_WR		: std_logic_vector(7 downto 0);
signal SIG_BUF_ADD_RD		: std_logic_vector(7 downto 0);
signal SIG_DISP_OFFSET		: std_logic_vector(7 downto 0);
signal SCALE_OFFSET			: std_logic_vector(7 downto 0);
signal TRIG_POSITION_C		: std_logic_vector(7 downto 0);
signal TRIG_POSITION_END	: std_logic_vector(7 downto 0);

signal SIG_DISP_START_ADD	: std_logic_vector(7 downto 0);
signal SIG_PRE_GET_C		: std_logic_vector(7 downto 0);
signal SIG_POST_GET_C		: std_logic_vector(7 downto 0);
signal PRE_ACQUIS_END		: std_logic;
signal POST_ACQUIS_END		: std_logic;

signal SIG_BUF_DATA_WR		: std_logic_vector(15 downto 0);
signal SIG_BUF_DATA_RD		: std_logic_vector(15 downto 0);

signal S2_START_F			: std_logic;
signal S3_START_F			: std_logic;
signal S4_START_F			: std_logic;
signal S5_START_F			: std_logic;
signal S6_START_F			: std_logic;
signal S7_START_F			: std_logic;
signal S8_START_F			: std_logic;
signal S10_START_F			: std_logic;
signal S11_START_F			: std_logic;
signal S2_JOB_END			: std_logic;
signal S3_JOB_END			: std_logic;
signal S4_JOB_END			: std_logic;
signal S5_JOB_END			: std_logic;
signal S6_JOB_END			: std_logic;
signal S7_JOB_END			: std_logic;
signal S8_JOB_END			: std_logic;
signal S10_JOB_END			: std_logic;
signal S11_JOB_END			: std_logic;

signal TEMP_TRIG_d2			: std_logic;
signal TEMP_TRIG_d3			: std_logic;
signal TEMP_TRIG_UP			: std_logic;
signal TEMP_TRIG_DOWN		: std_logic;
signal TEMP_TRIG_F			: std_logic;
signal TRIG_DETECT_TIMING	: std_logic;
signal TRIG_DETECT_F		: std_logic;	-- トリガー検出フラグ
signal TRIG_TIMEOUT_C		: std_logic_vector(23 downto 0);
signal TRIG_TIMEOUT_F		: std_logic;

signal SIG_BUF_SET_END		: std_logic;
signal SIG_BUF_SET_LOOP		: std_logic_vector(7 downto 0);
signal SEND_WAVE_DATA		: std_logic;
signal SEND_WAVE_COLOR		: std_logic_vector(7 downto 0);

signal WAVE_CH_C			: std_logic_vector(3 downto 0);	-- 波形表示番号カウンタ:00-15
signal WAVE_CH_C_END		: std_logic;
signal WAVE_CH_NUM_10		: std_logic_vector(7 downto 0);
signal WAVE_CH_NUM_01		: std_logic_vector(7 downto 0);

signal MENU_TRIG_CH			: std_logic_vector(3 downto 0);	-- トリガーCH番号 : 0h-Fh
signal MENU_TRIG_EDGE		: std_logic;					-- トリガーエッジ : 0:RISE,1:FALL
signal START_ENTER_KEY		: std_logic;					-- ENTERキーフラグ
signal SAMPLING_DIV			: std_logic_vector(7 downto 0);	-- サンプリング分周比
signal SAMPLING_DIV_C		: std_logic_vector(7 downto 0);	-- サンプリング分周比カウンタ
signal SAMPLING_TIMING_F	: std_logic;					-- 波形サンプリングタイミング

signal TRIG_CH_NUM_10		: std_logic_vector(7 downto 0);
signal TRIG_CH_NUM_01		: std_logic_vector(7 downto 0);
signal TRIG_TYPE_1			: std_logic_vector(1 downto 0);	-- トリガーモード
signal TRIG_TYPE_2			: std_logic_vector(1 downto 0);

signal DIV_CHAR_STR			: string(1 to 5);
signal SCALE_UNIT_STR		: string(1 to 5);
signal EDGE_STR				: string(1 to 4);
signal TRIG_TYPE_STR		: string(1 to 4);

signal S8_SCALE_DATA		: std_logic_vector(7 downto 0);
signal S8_SCALE_C			: std_logic_vector(7 downto 0);
signal S8_10_PIECES_C		: std_logic_vector(7 downto 0);
signal S8_SCALE_END			: std_logic;
signal S8_10_PIECES_END		: std_logic;

signal TEMP_TRIG_CH_NUM		: std_logic_vector(3 downto 0);
signal TEMP_WAVE_CH_NUM		: std_logic_vector(3 downto 0);

-- 使用モジュール宣言 -----------------------------------------------------------------------------

-- UART モジュール ------------------------------
component MODULE_UART_8_bit
port (
	-- システム
	nRESET				: in	std_logic;						-- 外部 RESETIN 入力(負論理)
	CLK_IN				: in	std_logic;						-- クロック	20MHz
	-- 分周比
	CLOCK_DIV_VALUE		: in	std_logic_vector(15 downto 0);	-- クロック分周比: (例) 20MHz/100Kbps/2 = 100d
	-- UART信号
	UART_RX				: in	std_logic;
	UART_TX				: out	std_logic;
	-- 送信
	TX_DATA_IN			: in	std_logic_vector(7 downto 0);	-- 送信データ
	TX_PARITY_ODD_EVEN	: in	std_logic;						-- パリティ 0:偶数、1:奇数
	TX_SEND_START		: in	std_logic;						-- 動作開始信号
	TX_BUSY				: out	std_logic;						-- 送信処理中は '1'、送信終了後 '0'
	TX_SEND_END			: out	std_logic;						-- 送信終了信号 (1-CLOCK)
	-- 受信
	RX_DATA				: out	std_logic_vector(7 downto 0);	-- 受信データ
	RX_PARITY_ODD_EVEN	: out	std_logic;						-- 受信データから計算したパリティの値 0:偶数、1:奇数
	RX_PARITY_bit		: out	std_logic;						-- 受信したパリティビットの値
	RX_BUSY				: out	std_logic;						-- 受信処理中は '1'、受信終了後 '0'
	RX_RECIEVE_END		: out	std_logic						-- 受信終了信号 (1-CLOCK)
);
end component ;

-- UARTコマンドモジュール -----------------------
component COMMAND_MODULE
port (
	-- システム
	nRESET				: in	std_logic;						-- nRESET
	CLK_IN				: in	std_logic;						-- CLOCK 12MHz
	-- UART信号
	RX_DATA				: in	std_logic_vector(7 downto 0);	-- 受信データ
	RX_PARITY_ODD_EVEN	: in	std_logic;						-- 受信データから計算したパリティの値 0:偶数、1:奇数
	RX_RECIEVE_END		: in	std_logic;						-- 受信終了信号 (1-CLOCK)
	-- コマンド信号
	MENU_TRIG_CH		: out	std_logic_vector(3 downto 0);	-- トリガーCH番号 : 0h-Fh
	MENU_TRIG_EDGE		: out	std_logic;						-- トリガーエッジ : 0:RISE,1:FALL
	START_ENTER_KEY		: out	std_logic;						-- ENTERキーフラグ
	SAMPLING_DIV		: out	std_logic_vector(7 downto 0);	-- サンプリング分周比
	SIG_DISP_OFFSET		: out	std_logic_vector(7 downto 0);	-- トリガー前オフセット
	SCALE_OFFSET		: out	std_logic_vector(7 downto 0);	-- 目盛りの10個単位マーカーオフセット
	TRIG_TYPE_1			: out	std_logic_vector(1 downto 0);	-- トリガーモード
	TRIG_TYPE_2			: in	std_logic_vector(1 downto 0);	-- トリガーモード、画面表示同期後
	TRIG_DETECT_F		: in	std_logic						-- トリガー検出フラグ
);
end component ;

-- 起動タイトル用データ -------------------------
component TITLE_DATA_MEM
port(
	-- システム
	CLK_IN				: in	std_logic;
	-- 制御信号
	RAM_ENABLE			: in	std_logic;
	RAM_ADD				: in	std_logic_vector(6 downto 0);
	RAM_DATA_OUT		: out	std_logic_vector(7 downto 0)
);
end component ;

-- UART送信用バッファ ---------------------------
component UART_SEND_BUFFER
port(
	-- システム
	CLK_IN				: in	std_logic;
	-- 制御信号
	RAM_ENABLE			: in	std_logic;
	RAM_WRITE			: in	std_logic;
	RAM_ADD				: in	std_logic_vector(7 downto 0);
	RAM_DATA_IN			: in	std_logic_vector(7 downto 0);
	RAM_DATA_OUT		: out	std_logic_vector(7 downto 0)
);
end component ;

--波形データバッファ ----------------------------
component SIG_DATA_BUFFER
port(
	-- システム
	CLK_IN				: in	std_logic;
	-- 制御信号
	RAM_ENABLE			: in	std_logic;
	RAM_WRITE			: in	std_logic;
	RAM_ADD				: in	std_logic_vector(7 downto 0);
	RAM_DATA_IN			: in	std_logic_vector(15 downto 0);
	RAM_DATA_OUT		: out	std_logic_vector(15 downto 0)
);
end component ;

begin ---------------------------------------------------------------------------------------------

-- モジュール読み出し -----------------------------------------------------------------------------

-- UART モジュール ------------------------------
m_MODULE_UART_8_bit : MODULE_UART_8_bit
port map(
	-- システム
	nRESET				=> nRESET,		-- nRESET-2
	CLK_IN				=> CLK_IN,
	-- 分周比
	CLOCK_DIV_VALUE		=> CLOCK_DIV_VALUE,
	-- UART信号
	UART_RX				=> UART_RX,			-- RX
	UART_TX				=> UART_TX,			-- TX
	-- 送信
	TX_DATA_IN			=> TX_DATA_IN,
	TX_PARITY_ODD_EVEN	=> '0',				-- パリティ 0:偶数、1:奇数,
	TX_SEND_START		=> TX_SEND_START,
	TX_BUSY				=> open,
	TX_SEND_END			=> TX_SEND_END,		-- 送信終了信号 (1-CLOCK)
	-- 受信
	RX_DATA				=> RX_DATA,
	RX_PARITY_ODD_EVEN	=> RX_PARITY_ODD_EVEN,
	RX_PARITY_bit		=> RX_PARITY_bit,
	RX_BUSY				=> open,
	RX_RECIEVE_END		=> RX_RECIEVE_END
);

-- UARTコマンドモジュール -----------------------
m_COMMAND_MODULE : COMMAND_MODULE
port map(
	-- システム
	nRESET				=> nRESET,		-- nRESET-2
	CLK_IN				=> CLK_IN,
	-- UART信号
	RX_DATA				=> RX_DATA,
	RX_PARITY_ODD_EVEN	=> RX_PARITY_ODD_EVEN,
	RX_RECIEVE_END		=> RX_RECIEVE_END,
	-- コマンド信号
	MENU_TRIG_CH		=> MENU_TRIG_CH,
	MENU_TRIG_EDGE		=> MENU_TRIG_EDGE,
	START_ENTER_KEY		=> START_ENTER_KEY,
	SAMPLING_DIV		=> SAMPLING_DIV,
	SIG_DISP_OFFSET		=> SIG_DISP_OFFSET,
	SCALE_OFFSET		=> SCALE_OFFSET,
	TRIG_TYPE_1			=> TRIG_TYPE_1,
	TRIG_TYPE_2			=> TRIG_TYPE_2,
	TRIG_DETECT_F		=> TRIG_DETECT_F
);

-- 起動タイトル用データ -------------------------
m_TITLE_DATA_MEM : TITLE_DATA_MEM
port map(
	-- システム
	CLK_IN				=> CLK_IN,
	-- 制御信号
	RAM_ENABLE			=> '1',
	RAM_ADD				=> MESSAGE_ADD,
	RAM_DATA_OUT		=> RAM_DATA_OUT
);

-- UART送信用バッファ ---------------------------
m_UART_SEND_BUFFER : UART_SEND_BUFFER
port map(
	-- システム
	CLK_IN				=> CLK_IN,
	-- 制御信号
	RAM_ENABLE			=> '1',
	RAM_WRITE			=> UART_BUF_WR_EN,
	RAM_ADD				=> UART_BUF_ADD,
	RAM_DATA_IN			=> UART_BUF_DATA_WR,
	RAM_DATA_OUT		=> UART_BUF_DATA_RD
);

-- 波形データバッファ ---------------------------
m_SIG_DATA_BUFFER : SIG_DATA_BUFFER
port map(
	-- システム
	CLK_IN				=> CLK_IN,
	-- 制御信号
	RAM_ENABLE			=> '1',
	RAM_WRITE			=> SIG_BUF_WR,
	RAM_ADD				=> SIG_BUF_ADD,
	RAM_DATA_IN			=> SIG_BUF_DATA_WR,
	RAM_DATA_OUT		=> SIG_BUF_DATA_RD
);

-- ロジック本体 -----------------------------------------------------------------------------------

	---------------------------------------------
	-- 波形入力信号同期化
	---------------------------------------------
	-- 入力ピンダブルラッチ
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			if ( nRESET = '0' ) then
				SIG_IN_DATA_d1(15 downto 0)	<= ( others => '0');
				SIG_IN_DATA_d2(15 downto 0)	<= ( others => '0');
			else
				SIG_IN_DATA_d1(15 downto 0)	<= SIG_IN_DATA(15 downto 0);
				SIG_IN_DATA_d2(15 downto 0)	<= SIG_IN_DATA_d1(15 downto 0);
			end if;
		end if;
	end process;
	-- 立上り/立下り検出用
	--	SAMPLING_TIMING_F のタイミングでラッチする
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			if ( nRESET = '0' ) then
				SIG_IN_DATA_d3(15 downto 0)	<= ( others => '0');
				SIG_IN_DATA_d4(15 downto 0)	<= ( others => '0');
			-- LATCH
			elsif ( SAMPLING_TIMING_F = '1' ) then
				SIG_IN_DATA_d3(15 downto 0)	<= SIG_IN_DATA_d2(15 downto 0);
				SIG_IN_DATA_d4(15 downto 0)	<= SIG_IN_DATA_d3(15 downto 0);
			-- KEEP
			else
				SIG_IN_DATA_d3(15 downto 0)	<= SIG_IN_DATA_d3(15 downto 0);
				SIG_IN_DATA_d4(15 downto 0)	<= SIG_IN_DATA_d4(15 downto 0);
			end if;
		end if;
	end process;
	-- 波形バッファへの書き込みデータ
	SIG_BUF_DATA_WR(15 downto 0)	<= SIG_IN_DATA_d4(15 downto 0);

	---------------------------------------------
	-- メインシーケンサ[S1]
	---------------------------------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			if ( nRESET = '0' ) then
				S1_STATUS			<= S1_WAIT_ENTER;
			else
				case S1_STATUS is

				-- ENTERキー待ち ----------------
				when S1_WAIT_ENTER =>
					if ( START_ENTER_KEY = '1' ) then	S1_STATUS <= S1_START_WAIT;
					else								S1_STATUS <= S1_WAIT_ENTER;	-- LOOP
					end if;
				-- 開始
				when S1_START_WAIT =>				S1_STATUS <= S1_SCREEN_CLR;
				-- 画面クリア[S10] --------------
				when S1_SCREEN_CLR =>				S1_STATUS <= S1_SCREEN_CLR_L1;
				when S1_SCREEN_CLR_L1 =>
					if ( S10_JOB_END = '1' ) then	S1_STATUS <= S1_SCREEN_CLR_SEND;
					else							S1_STATUS <= S1_SCREEN_CLR_L1;
					end if;
				-- UART送信[S3]
				when S1_SCREEN_CLR_SEND =>			S1_STATUS <= S1_SCREEN_CLR_SEND_L2;
				when S1_SCREEN_CLR_SEND_L2 =>
					if ( S3_JOB_END = '1' ) then	S1_STATUS <= S1_TITLE_SET;
					else							S1_STATUS <= S1_SCREEN_CLR_SEND_L2;
					end if;
				-- タイトル文字[S2] -------------
				-- 文字列設定
				when S1_TITLE_SET =>				S1_STATUS <= S1_TITLE_SET_L;
				when S1_TITLE_SET_L =>
					if ( S2_JOB_END = '1' ) then	S1_STATUS <= S1_TITLE_SEND;
					else							S1_STATUS <= S1_TITLE_SET_L;
					end if;
				-- UART送信[S3]
				when S1_TITLE_SEND =>				S1_STATUS <= S1_TITLE_SEND_L;
				when S1_TITLE_SEND_L =>
					if ( S3_JOB_END = '1' ) then	S1_STATUS <= S1_MENU_SET;
					else							S1_STATUS <= S1_TITLE_SEND_L;
					end if;
				-- メニュー[S6] -----------------
				-- メニュー文字列設定
				when S1_MENU_SET =>					S1_STATUS <= S1_MENU_SET_L;
				when S1_MENU_SET_L =>
					if ( S6_JOB_END = '1' ) then	S1_STATUS <= S1_MENU_SEND;
					else							S1_STATUS <= S1_MENU_SET_L;
					end if;
				-- UART送信[S3]
				when S1_MENU_SEND =>				S1_STATUS <= S1_MENU_SEND_L;
				when S1_MENU_SEND_L =>
					if ( S3_JOB_END = '1' ) then	S1_STATUS <= S1_SCALE_SET;
					else							S1_STATUS <= S1_MENU_SEND_L;
					end if;
				-- 目盛り[S8] -------------------
				-- 目盛り文字列設定
				when S1_SCALE_SET =>				S1_STATUS <= S1_SCALE_SET_L;
				when S1_SCALE_SET_L =>
					if ( S8_JOB_END = '1' ) then	S1_STATUS <= S1_SCAE_SEND;
					else							S1_STATUS <= S1_SCALE_SET_L;
					end if;
				-- UART送信[S3]
				when S1_SCAE_SEND =>				S1_STATUS <= S1_SCAE_SEND_L;
				when S1_SCAE_SEND_L =>
					if ( S3_JOB_END = '1' ) then	S1_STATUS <= S1_GET_WAVE_JUDGE;
					else							S1_STATUS <= S1_SCAE_SEND_L;
					end if;
				-- 波形データ収集判定 -----------
				when S1_GET_WAVE_JUDGE =>
					if ( TRIG_TYPE_2 = "10" ) then	S1_STATUS <= S1_WAVE_DISP_JOB;	-- 停止：SKIP
					else							S1_STATUS <= S1_GET_WAVE_DATA;	-- 波形データ収集
					end if;
				-- 波形データ収集[S5]
				when S1_GET_WAVE_DATA =>			S1_STATUS <= S1_GET_WAVE_DATA_L;
				when S1_GET_WAVE_DATA_L =>
					if ( S5_JOB_END = '1' ) then	S1_STATUS <= S1_WAVE_DISP_JOB;
					else							S1_STATUS <= S1_GET_WAVE_DATA_L;
					end if;
				-- 波形表示 ---------------------
				when S1_WAVE_DISP_JOB =>			S1_STATUS <= S1_WAVEDATA_JOB;
				-- 波形表示 ループ CH00～CH15
				-- トリガポイントデータ生成[S7]
				when S1_WAVEDATA_JOB =>				S1_STATUS <= S1_TRIG_POINT_SET_L;
				when S1_TRIG_POINT_SET_L =>
					if ( S7_JOB_END = '1' ) then	S1_STATUS <= S1_SEND_TRIG_POINT;
					else							S1_STATUS <= S1_TRIG_POINT_SET_L;
					end if;
				-- UART送信[S3]
				when S1_SEND_TRIG_POINT =>			S1_STATUS <= S1_SEND_TRIG_POINT_L;
				when S1_SEND_TRIG_POINT_L =>
					if ( S3_JOB_END = '1' ) then	S1_STATUS <= S1_WAVEDATA_SET;
					else							S1_STATUS <= S1_SEND_TRIG_POINT_L;
					end if;
				-- 波形送信データ生成[S4]
				when S1_WAVEDATA_SET =>				S1_STATUS <= S1_WAVEDATA_SET_L;
				when S1_WAVEDATA_SET_L =>
					if ( S4_JOB_END = '1' ) then	S1_STATUS <= S1_SEND_WAVEFORM;
					else							S1_STATUS <= S1_WAVEDATA_SET_L;
					end if;
				-- UART送信[S3]
				when S1_SEND_WAVEFORM =>			S1_STATUS <= S1_SEND_WAVEFORM_L;
				when S1_SEND_WAVEFORM_L =>
					if ( S3_JOB_END = '1' ) then	S1_STATUS <= S1_NEXT_WAVE;			-- S3 終了判定
					else							S1_STATUS <= S1_SEND_WAVEFORM_L;
					end if;
				-- 次のCH
				when S1_NEXT_WAVE =>
					if ( WAVE_CH_C_END = '1' ) then	S1_STATUS <= S1_TIME_WAIT;			-- 1画面処理終了
					else							S1_STATUS <= S1_WAVEDATA_JOB;		-- 次のCH
					end if;
				-- 1画面処理終了 ----------------
				-- 100mS 待ち、PC側の処理に余裕を持たせる
				when S1_TIME_WAIT =>					S1_STATUS <= S1_TIME_WAIT_L;
				when S1_TIME_WAIT_L =>
					if ( TRIG_TIMEOUT_F = '1' ) then	S1_STATUS <= S1_NEXT_LOOP;		-- TIME OUT
					else								S1_STATUS <= S1_TIME_WAIT_L;	-- LOOP
					end if;
				-- 次の画面処理へ ---------------
				when S1_NEXT_LOOP =>				S1_STATUS <= S1_TITLE_SET;			-- LOOP
				-- その他(本来ここは実行されない)
				when others	=>						S1_STATUS <= S1_START_WAIT;
				end case;
			end if;
		end if;
	end process;
	---------------------------------------------
	-- トリガーモード状態の更新
	---------------------------------------------
	--	トリガーモードでシングルモード停止処理が、表示処理中に変化する影響を防ぐため、
	--	キー入力リアルタイムではなく、1画面処理終了時に更新する
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			if ( nRESET = '0' ) then				TRIG_TYPE_2	<= "00";		-- RESET
			elsif ( S1_STATUS = S1_NEXT_LOOP ) then	TRIG_TYPE_2	<= TRIG_TYPE_1;	-- LATCH
			else									TRIG_TYPE_2	<= TRIG_TYPE_2;	-- KEEP
			end if;
		end if;
	end process;
	---------------------------------------------
	-- 画面クリアデータ生成[S10]
	---------------------------------------------
	-- ESCシーケンスによる画面クリア文字データを、UART送信バッファーに設定する
	---
	-- 動作開始条件
	S10_START_F	<= '1' when ( S1_STATUS = S1_SCREEN_CLR ) else '0';
	-- シーケンサ本体
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				UART_BUF_DATA_WR_S10	<= (others => '0');
				S10_STATUS				<= S10_START_WAIT;
			else
				case S10_STATUS is
				-- 開始待機中
				when S10_START_WAIT =>
					UART_BUF_DATA_WR_S10	<= (others => '0');
					if ( S10_START_F = '1' ) then	S10_STATUS <= S10_JOB_START;
					else							S10_STATUS <= S10_START_WAIT;	-- LOOP
					end if;
				-- ESCシーケンス画面クリア ------
				when S10_JOB_START =>
					UART_BUF_DATA_WR_S10	<= X"1B";	-- ESC
					S10_STATUS				<= S10_NEXT_1;
				when S10_NEXT_1 =>
					UART_BUF_DATA_WR_S10	<= X"5B";	-- "["
					S10_STATUS				<= S10_NEXT_2;
				when S10_NEXT_2 =>
					UART_BUF_DATA_WR_S10	<= X"32";	-- '2'
					S10_STATUS				<= S10_NEXT_3;
				when S10_NEXT_3 =>
					UART_BUF_DATA_WR_S10	<= X"4A";	-- 'J'
					S10_STATUS				<= S10_NEXT_4;
				when S10_NEXT_4 =>
					UART_BUF_DATA_WR_S10	<= X"00";
					S10_STATUS				<= S10_STATUS_END;
				-- 終了
				when S10_STATUS_END =>
					UART_BUF_DATA_WR_S10	<= (others => '0');
					S10_STATUS				<= S10_START_WAIT;
				-- その他(本来ここは実行されない)
				when others	=>
					UART_BUF_DATA_WR_S10	<= (others => '0');
					S10_STATUS				<= S10_START_WAIT;
				end case;
			end if;
		end if;
	end process;
	-- UARTバッファ、アドレス
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				UART_BUF_ADD_S10	<= (others => '0');
			elsif ( S10_STATUS = S10_START_WAIT ) then
				UART_BUF_ADD_S10	<= (others => '0');
			elsif ( S10_STATUS = S10_JOB_START ) then
				UART_BUF_ADD_S10	<= (others => '0');
			elsif ( S10_STATUS = S10_STATUS_END ) then
				UART_BUF_ADD_S10	<= (others => '0');
			-- +1
			else
				UART_BUF_ADD_S10	<= UART_BUF_ADD_S10 + 1;
			end if;
		end if;
	end process;
	-- UART WRITE信号
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					UART_BUF_WR_EN_S10	<= '0';
			elsif ( S10_STATUS = S10_START_WAIT ) then	UART_BUF_WR_EN_S10	<= '0';
			elsif ( S10_STATUS = S10_STATUS_END ) then	UART_BUF_WR_EN_S10	<= '0';
			-- ON
			elsif ( S10_STATUS = S10_JOB_START ) then	UART_BUF_WR_EN_S10	<= '1';
			-- KEEP
			else										UART_BUF_WR_EN_S10	<= UART_BUF_WR_EN_S10;
			end if;
		end if;
	end process;
	-- S10:終了
	S10_JOB_END	<= '1' when ( S10_STATUS = S10_STATUS_END ) else '0';

	---------------------------------------------
	-- 文字属性クリアデータ生成[S11]
	---------------------------------------------
	-- ESCシーケンスによる文字属性クリアデータを、UART送信バッファーに設定する
	---
	-- 動作開始条件
	S11_START_F	<= '1' when (	( S6_STATUS = S6_ATT_CLR )
							or	( S8_STATUS = S8_ATT_CLR ) ) else '0';
	-- シーケンサ本体
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				UART_BUF_DATA_WR_S11	<= (others => '0');
				S11_STATUS				<= S11_START_WAIT;
			else
				case S11_STATUS is
				-- 開始待機中
				when S11_START_WAIT =>				UART_BUF_DATA_WR_S11	<= (others => '0');
					if ( S11_START_F = '1' ) then	S11_STATUS				<= S11_JOB_START;
					else							S11_STATUS				<= S11_START_WAIT;	-- LOOP
					end if;
				-- ESCシーケンス画面クリア ------
				when S11_JOB_START =>
					UART_BUF_DATA_WR_S11	<= X"1B";	-- ESC
					S11_STATUS				<= S11_NEXT_1;
				when S11_NEXT_1 =>
					UART_BUF_DATA_WR_S11	<= X"5B";	-- "["
					S11_STATUS				<= S11_NEXT_2;
				when S11_NEXT_2 =>
					UART_BUF_DATA_WR_S11	<= X"30";	-- '0' 全ての属性を解除する
					S11_STATUS				<= S11_NEXT_3;
				when S11_NEXT_3 =>
					UART_BUF_DATA_WR_S11	<= X"6D";	-- 'm'
					S11_STATUS				<= S11_NEXT_4;
				when S11_NEXT_4 =>
					UART_BUF_DATA_WR_S11	<= X"00";
					S11_STATUS				<= S11_STATUS_END;
				-- 終了
				when S11_STATUS_END =>
					UART_BUF_DATA_WR_S11	<= (others => '0');
					S11_STATUS				<= S11_START_WAIT;
				-- その他(本来ここは実行されない)
				when others	=>
					UART_BUF_DATA_WR_S11	<= (others => '0');
					S11_STATUS				<= S11_START_WAIT;
				end case;
			end if;
		end if;
	end process;
	-- UARTバッファ、アドレス
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				UART_BUF_ADD_S11	<= (others => '0');
			elsif ( S11_STATUS = S11_START_WAIT ) then
				UART_BUF_ADD_S11	<= (others => '0');
			elsif ( S11_STATUS = S11_JOB_START ) then
				UART_BUF_ADD_S11	<= (others => '0');
			elsif ( S11_STATUS = S11_STATUS_END ) then
				UART_BUF_ADD_S11	<= (others => '0');
			-- +1
			else
				UART_BUF_ADD_S11	<= UART_BUF_ADD_S11 + 1;
			end if;
		end if;
	end process;
	-- UART WRITE信号
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					UART_BUF_WR_EN_S11	<= '0';
			elsif ( S11_STATUS = S11_START_WAIT ) then	UART_BUF_WR_EN_S11	<= '0';
			elsif ( S11_STATUS = S11_STATUS_END ) then	UART_BUF_WR_EN_S11	<= '0';
			-- ON
			elsif ( S11_STATUS = S11_JOB_START ) then	UART_BUF_WR_EN_S11	<= '1';
			-- KEEP
			else										UART_BUF_WR_EN_S11	<= UART_BUF_WR_EN_S11;
			end if;
		end if;
	end process;
	-- S11:終了
	S11_JOB_END	<= '1' when ( S11_STATUS = S11_STATUS_END ) else '0';

	---------------------------------------------
	-- タイトル文字列設定[S2]
	---------------------------------------------
	-- タイトル文字バッファの文字列を、UART送信バッファーにコピーする

	-- 書き込みデータ　※非動作中は "00" にすること、他と or 合成する
	UART_BUF_DATA_WR_S2	<= X"00" when ( S2_STATUS = S2_START_WAIT ) else RAM_DATA_OUT;
	-- 動作開始条件
	S2_START_F	<= '1' when ( S1_STATUS = S1_TITLE_SET ) else '0';
	-- シーケンサ本体
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				S2_STATUS			<= S2_START_WAIT;
			else
				case S2_STATUS is
				-- 開始待機中
				when S2_START_WAIT =>
					if ( S2_START_F = '1' ) then	S2_STATUS <= S2_LOOP;		-- 動作開始
					else							S2_STATUS <= S2_START_WAIT;
					end if;
				-- 1-BYTE コピー
				when S2_LOOP =>						S2_STATUS	<= S2_END_CEHCK;
				when S2_END_CEHCK =>
					if ( UART_BUF_DATA_WR_S2 = X"00" ) then	S2_STATUS <= S2_STATUS_END;	-- 送信終了
					else									S2_STATUS <= S2_LOOP;		-- 次の送信へ
					end if;
				-- 終了
				when S2_STATUS_END =>				S2_STATUS	<= S2_START_WAIT;
				-- その他(本来ここは実行されない)
				when others	=>						S2_STATUS	<= S2_START_WAIT;
				end case;
			end if;
		end if;
	end process;
	-- UARTバッファ、アドレス
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				MESSAGE_ADD		<= (others => '0');
				UART_BUF_ADD_S2	<= (others => '0');
			elsif ( S2_STATUS = S2_START_WAIT ) then
				MESSAGE_ADD		 <= (others => '0');
				UART_BUF_ADD_S2	<= (others => '0');
			elsif ( S2_STATUS = S2_STATUS_END ) then
				MESSAGE_ADD		 <= (others => '0');
				UART_BUF_ADD_S2	<= (others => '0');
			-- +1
			elsif ( S2_STATUS = S2_END_CEHCK ) then
				MESSAGE_ADD		<= MESSAGE_ADD + 1;
				UART_BUF_ADD_S2	<= UART_BUF_ADD_S2 + 1;
			-- KEEP
			else
				MESSAGE_ADD		<= MESSAGE_ADD;
				UART_BUF_ADD_S2	<= UART_BUF_ADD_S2;
			end if;
		end if;
	end process;
	-- UART WRITE信号
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then			UART_BUF_WR_EN_S2	<= '0';
			-- ON
			elsif ( S2_STATUS = S2_LOOP ) then	UART_BUF_WR_EN_S2	<= '1';
			-- OFF
			else								UART_BUF_WR_EN_S2	<= '0';
			end if;
		end if;
	end process;
	-- S2:終了
	S2_JOB_END	<= '1' when ( S2_STATUS = S2_STATUS_END ) else '0';

	---------------------------------------------
	-- メニューエリア文字データ生成[S6]
	---------------------------------------------
	-- メニューエリア文字データを、UART送信バッファーに設定する
	---
	DIV_CHAR_STR	<=	"20nS " when ( SAMPLING_DIV = X"00" )	-- 50MHz:  " 20nS"
				else	"40nS " when ( SAMPLING_DIV = X"01" )	-- 25MHz:  " 40nS
				else	"100nS" when ( SAMPLING_DIV = X"04" )	-- 10MHz:  "100nS
				else	"200nS" when ( SAMPLING_DIV = X"09" )	-- 5MHz:   "200nS
				else	"400nS" when ( SAMPLING_DIV = X"13" )	-- 2.5MHz: "400nS
				else	"1uS  " when ( SAMPLING_DIV = X"31" )	-- 1MHz:   "  1uS
				else	"2uS  " when ( SAMPLING_DIV = X"63" )	-- 0.5MHz: "  2uS
				else	"4uS  " when ( SAMPLING_DIV = X"C7" )	-- 0.25MHz:"  4uS
				else	"     ";	-- other
	---
	EDGE_STR		<=	"RISE" when ( MENU_TRIG_EDGE = '0' ) else	"FALL";
	---
	TRIG_TYPE_STR	<=	"CONT" when ( TRIG_TYPE_2 = "00" )
				else	"SING" when ( TRIG_TYPE_2 = "01" )
				else	"STOP";
	-- トリガーCH番号文字列生成 -----------------
	TRIG_CH_NUM_10		<= X"30" when ( MENU_TRIG_CH < X"A" ) else X"31";							-- 10の位
	TEMP_TRIG_CH_NUM	<= MENU_TRIG_CH when ( MENU_TRIG_CH < X"A" ) else ( MENU_TRIG_CH - X"A" );	-- 1の位
	TRIG_CH_NUM_01		<= ( "0000" & TEMP_TRIG_CH_NUM ) + X"30";
	-- 動作開始条件
	S6_START_F	<= '1' when ( S1_STATUS = S1_MENU_SET ) else '0';
	-- シーケンサ本体
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				UART_BUF_DATA_WR_S6	<= (others => '0');
				S6_STATUS			<= S6_START_WAIT;
			else
				case S6_STATUS is
				-- 開始待機中
				when S6_START_WAIT =>
					UART_BUF_DATA_WR_S6	<= (others => '0');
					if ( S6_START_F = '1' ) then	S6_STATUS <= S6_ATT_CLR;
					else							S6_STATUS <= S6_START_WAIT;	-- LOOP
					end if;
				-- "TRIG:" ----------------------
				-- 文字属性クリア[S11]
				when S6_ATT_CLR =>
					UART_BUF_DATA_WR_S6	<= (others => '0');
					S6_STATUS			<= S6_ATT_CLR_L1;
				when S6_ATT_CLR_L1 =>
					UART_BUF_DATA_WR_S6	<= (others => '0');
					if ( S11_JOB_END = '1' ) then	S6_STATUS <= S6_ATT_CLR_SEND;
					else							S6_STATUS <= S6_ATT_CLR_L1;
					end if;
				-- UART送信[S3]
				when S6_ATT_CLR_SEND =>
					UART_BUF_DATA_WR_S6	<= (others => '0');
					S6_STATUS			<= S6_ATT_CLR_SEND_L2;
				when S6_ATT_CLR_SEND_L2 =>
					UART_BUF_DATA_WR_S6	<= (others => '0');
					if ( S3_JOB_END = '1' ) then	S6_STATUS <= S6_JOB_START;
					else							S6_STATUS <= S6_ATT_CLR_SEND_L2;
					end if;
				-- "TRIG:"
				when S6_JOB_START =>
					UART_BUF_DATA_WR_S6	<= X"20";	-- " "
					S6_STATUS			<= S6_TRIG_2;
				when S6_TRIG_2 =>
					UART_BUF_DATA_WR_S6	<= X"20";	-- " "
					S6_STATUS			<= S6_TRIG_3;
				when S6_TRIG_3 =>
					UART_BUF_DATA_WR_S6	<= X"54";	-- 'T'
					S6_STATUS			<= S6_TRIG_4;
				when S6_TRIG_4 =>
					UART_BUF_DATA_WR_S6	<= X"52";	-- 'R'
					S6_STATUS			<= S6_TRIG_5;
				when S6_TRIG_5 =>
					UART_BUF_DATA_WR_S6	<= X"49";	-- 'I'
					S6_STATUS			<= S6_TRIG_6;
				when S6_TRIG_6 =>
					UART_BUF_DATA_WR_S6	<= X"47";	-- 'G'
					S6_STATUS			<= S6_TRIG_7;
				when S6_TRIG_7 =>
					UART_BUF_DATA_WR_S6	<= X"3A";	-- ':'
					S6_STATUS			<= S6_TRIG_8;
				-- "CHxx"
				when S6_TRIG_8 =>
					UART_BUF_DATA_WR_S6	<= X"43";	-- 'C'
					S6_STATUS			<= S6_TRIG_9;
				when S6_TRIG_9 =>
					UART_BUF_DATA_WR_S6	<= X"48";	-- 'H'
					S6_STATUS			<= S6_TRIG_10;
				when S6_TRIG_10 =>
					UART_BUF_DATA_WR_S6	<= TRIG_CH_NUM_10;		-- 10の桁
					S6_STATUS			<= S6_TRIG_11;
				when S6_TRIG_11 =>
					UART_BUF_DATA_WR_S6	<= TRIG_CH_NUM_01;		-- 10の桁
					S6_STATUS			<= S6_EDGE_JOB;
				-- エッジ(Edge)	"RISE/FALL"
				when S6_EDGE_JOB =>
					UART_BUF_DATA_WR_S6	<= X"2C";				-- ','
					S6_STATUS			<= S6_EDGE_N1;
				when S6_EDGE_N1 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( EDGE_STR(1) ), 8 ));
					S6_STATUS			<= S6_EDGE_N2;
				when S6_EDGE_N2 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( EDGE_STR(2) ), 8 ));
					S6_STATUS			<= S6_EDGE_N3;
				when S6_EDGE_N3 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( EDGE_STR(3) ), 8 ));
					S6_STATUS			<= S6_EDGE_N4;
				when S6_EDGE_N4 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( EDGE_STR(4) ), 8 ));
					S6_STATUS			<= S6_TRIG_TYPE_JOB;
				-- トリガーモード "CONT/SINGLE/STOP"
				when S6_TRIG_TYPE_JOB =>
					UART_BUF_DATA_WR_S6	<= X"2C";				-- ','
					S6_STATUS			<= S6_TRIG_TYPE_N1;
				when S6_TRIG_TYPE_N1 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( TRIG_TYPE_STR(1) ), 8 ));
					S6_STATUS			<= S6_TRIG_TYPE_N2;
				when S6_TRIG_TYPE_N2 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( TRIG_TYPE_STR(2) ), 8 ));
					S6_STATUS			<= S6_TRIG_TYPE_N3;
				when S6_TRIG_TYPE_N3 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( TRIG_TYPE_STR(3) ), 8 ));
					S6_STATUS			<= S6_TRIG_TYPE_N4;
				when S6_TRIG_TYPE_N4 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( TRIG_TYPE_STR(4) ), 8 ));
					S6_STATUS			<= S6_DIV_JOB;
				-- "DIV"
				when S6_DIV_JOB =>
					UART_BUF_DATA_WR_S6	<= X"20";	-- " "
					S6_STATUS			<= S6_DIV_N0;
				when S6_DIV_N0 =>
					UART_BUF_DATA_WR_S6	<= X"20";	-- " " 2個目
					S6_STATUS			<= S6_DIV_N1;
				when S6_DIV_N1 =>
					UART_BUF_DATA_WR_S6	<= X"44";	-- 'D'
					S6_STATUS			<= S6_DIV_N2;
				when S6_DIV_N2 =>
					UART_BUF_DATA_WR_S6	<= X"49";	-- 'I'
					S6_STATUS			<= S6_DIV_N3;
				when S6_DIV_N3 =>
					UART_BUF_DATA_WR_S6	<= X"56";	-- 'V'
					S6_STATUS			<= S6_DIV_N4;
				when S6_DIV_N4 =>
					UART_BUF_DATA_WR_S6	<= X"3A";	-- ':'
					S6_STATUS			<= S6_DIV_N5;
				when S6_DIV_N5 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( DIV_CHAR_STR(1) ), 8 ));
					S6_STATUS			<= S6_DIV_N6;
				when S6_DIV_N6 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( DIV_CHAR_STR(2) ), 8 ));
					S6_STATUS			<= S6_DIV_N7;
				when S6_DIV_N7 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( DIV_CHAR_STR(3) ), 8 ));
					S6_STATUS			<= S6_DIV_N8;
				when S6_DIV_N8 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( DIV_CHAR_STR(4) ), 8 ));
					S6_STATUS			<= S6_DIV_N9;
				when S6_DIV_N9 =>
					UART_BUF_DATA_WR_S6	<= std_logic_vector( to_unsigned(character'pos( DIV_CHAR_STR(5) ), 8 ));
					S6_STATUS			<= S6_NEXT_CRLF;
				-- 0Dh,0Ah
				when S6_NEXT_CRLF =>
					UART_BUF_DATA_WR_S6	<= X"0D";
					S6_STATUS			<= S6_NEXT_CRLF_2;
				when S6_NEXT_CRLF_2 =>
					UART_BUF_DATA_WR_S6	<= X"0A";
					S6_STATUS			<= S6_NEXT_00h;
				-- 00h
				when S6_NEXT_00h =>
					UART_BUF_DATA_WR_S6	<= X"00";
					S6_STATUS			<= S6_STATUS_END;
				-- 終了
				when S6_STATUS_END =>
					UART_BUF_DATA_WR_S6	<= (others => '0');
					S6_STATUS			<= S6_START_WAIT;
				-- その他(本来ここは実行されない)
				when others	=>
					UART_BUF_DATA_WR_S6	<= (others => '0');
					S6_STATUS			<= S6_START_WAIT;
				end case;
			end if;
		end if;
	end process;
	-- UARTバッファ、アドレス
	UART_BUF_ADD_S6_CLR	<= '1' when (	( S6_STATUS = S6_START_WAIT )		or	( S6_STATUS = S6_ATT_CLR )
									or	( S6_STATUS = S6_ATT_CLR_L1 )		or	( S6_STATUS = S6_ATT_CLR_SEND )
									or	( S6_STATUS = S6_ATT_CLR_SEND_L2 )	or	( S6_STATUS = S6_JOB_START )
									or	( S6_STATUS = S6_STATUS_END ) ) else '0';
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					UART_BUF_ADD_S6	<= (others => '0');
			elsif ( UART_BUF_ADD_S6_CLR = '1' ) then	UART_BUF_ADD_S6	<= (others => '0');
			-- +1
			else										UART_BUF_ADD_S6	<= UART_BUF_ADD_S6 + 1;
			end if;
		end if;
	end process;
	-- UART WRITE信号
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					UART_BUF_WR_EN_S6	<= '0';
			elsif ( S6_STATUS = S6_START_WAIT ) then	UART_BUF_WR_EN_S6	<= '0';
			elsif ( S6_STATUS = S6_STATUS_END ) then	UART_BUF_WR_EN_S6	<= '0';
			-- ON
			elsif ( S6_STATUS = S6_JOB_START ) then		UART_BUF_WR_EN_S6	<= '1';
			-- KEEP
			else										UART_BUF_WR_EN_S6	<= UART_BUF_WR_EN_S6;
			end if;
		end if;
	end process;
	-- S2:終了
	S6_JOB_END	<= '1' when ( S6_STATUS = S6_STATUS_END ) else '0';

	---------------------------------------------
	-- 目盛り表示データ生成[S8]
	---------------------------------------------
	--	目盛り表示の文字データを、UART送信バッファーに設定する
	--	DIV の10倍

	-- 単位文字列設定
	SCALE_UNIT_STR	<=	"200nS" when ( SAMPLING_DIV = X"00" )	-- 50MHz:  " 20nS"	の10倍
				else	"400nS" when ( SAMPLING_DIV = X"01" )	-- 25MHz:  " 40nS
				else	"  1uS" when ( SAMPLING_DIV = X"04" )	-- 10MHz:  "100nS
				else	"  2uS" when ( SAMPLING_DIV = X"09" )	-- 5MHz:   "200nS
				else	"  4uS" when ( SAMPLING_DIV = X"13" )	-- 2.5MHz: "400nS
				else	" 10uS" when ( SAMPLING_DIV = X"31" )	-- 1MHz:   "  1uS
				else	" 20uS" when ( SAMPLING_DIV = X"63" )	-- 0.5MHz: "  2uS
				else	" 40uS" when ( SAMPLING_DIV = X"C7" )	-- 0.25MHz:"  4uS
				else	"     ";	-- other
	-- 動作開始条件
	S8_START_F	<= '1' when ( S1_STATUS = S1_SCALE_SET ) else '0';
	-- シーケンサ本体
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				UART_BUF_DATA_WR_S8	<= (others => '0');
				S8_STATUS			<= S8_START_WAIT;
			else
				case S8_STATUS is
				-- 開始待機中
				when S8_START_WAIT =>
					UART_BUF_DATA_WR_S8	<= (others => '0');
					if ( S8_START_F = '1' ) then	S8_STATUS <= S8_ATT_CLR;
					else							S8_STATUS <= S8_START_WAIT;	-- LOOP
					end if;
				-- 文字属性クリア[S11] ----------
				when S8_ATT_CLR =>
					UART_BUF_DATA_WR_S8	<= (others => '0');
					S8_STATUS			<= S8_ATT_CLR_L1;
				when S8_ATT_CLR_L1 =>
					UART_BUF_DATA_WR_S8	<= (others => '0');
					if ( S11_JOB_END = '1' ) then	S8_STATUS <= S8_ATT_CLR_SEND;
					else							S8_STATUS <= S8_ATT_CLR_L1;
					end if;
				-- UART送信[S3]
				when S8_ATT_CLR_SEND =>
					UART_BUF_DATA_WR_S8	<= (others => '0');
					S8_STATUS			<= S8_ATT_CLR_SEND_L2;
				when S8_ATT_CLR_SEND_L2 =>
					UART_BUF_DATA_WR_S8	<= (others => '0');
					if ( S3_JOB_END = '1' ) then	S8_STATUS <= S8_JOB_START;
					else							S8_STATUS <= S8_ATT_CLR_SEND_L2;
					end if;
				-- 単位文字列 -------------------
				when S8_JOB_START =>
					UART_BUF_DATA_WR_S8	<= std_logic_vector( to_unsigned(character'pos( SCALE_UNIT_STR(1) ), 8 ));
					S8_STATUS			<= S8_UNIT_N1;
				when S8_UNIT_N1	=>
					UART_BUF_DATA_WR_S8	<= std_logic_vector( to_unsigned(character'pos( SCALE_UNIT_STR(2) ), 8 ));
					S8_STATUS			<= S8_UNIT_N2;
				when S8_UNIT_N2	=>
					UART_BUF_DATA_WR_S8	<= std_logic_vector( to_unsigned(character'pos( SCALE_UNIT_STR(3) ), 8 ));
					S8_STATUS			<= S8_UNIT_N3;
				when S8_UNIT_N3	=>
					UART_BUF_DATA_WR_S8	<= std_logic_vector( to_unsigned(character'pos( SCALE_UNIT_STR(4) ), 8 ));
					S8_STATUS			<= S8_UNIT_N4;
				when S8_UNIT_N4	=>
					UART_BUF_DATA_WR_S8	<= std_logic_vector( to_unsigned(character'pos( SCALE_UNIT_STR(5) ), 8 ));
					S8_STATUS			<= S8_SCALE;
				-- 目盛り -----------------------
				when S8_SCALE =>
					UART_BUF_DATA_WR_S8		<= X"20";		-- SPACE
					S8_STATUS				<= S8_SCALE_L1;	-- LOOP
				when S8_SCALE_L1 =>
					UART_BUF_DATA_WR_S8		<= S8_SCALE_DATA;
					if ( S8_SCALE_END = '1' ) then	S8_STATUS <= S8_NEXT_CRLF;
					else							S8_STATUS <= S8_SCALE_L1;	-- LOOP
					end if;
				-- 0Dh,0Ah
				when S8_NEXT_CRLF =>
					UART_BUF_DATA_WR_S8	<= X"0D";
					S8_STATUS			<= S8_NEXT_CRLF_2;
				when S8_NEXT_CRLF_2 =>
					UART_BUF_DATA_WR_S8	<= X"0A";
					S8_STATUS			<= S8_NEXT_00h;
				-- 00h
				when S8_NEXT_00h =>
					UART_BUF_DATA_WR_S8	<= X"00";
					S8_STATUS			<= S8_STATUS_END;
				-- 終了
				when S8_STATUS_END =>
					UART_BUF_DATA_WR_S8	<= (others => '0');
					S8_STATUS			<= S8_START_WAIT;
				-- その他(本来ここは実行されない)
				when others	=>
					UART_BUF_DATA_WR_S8	<= (others => '0');
					S8_STATUS			<= S8_START_WAIT;
				end case;
			end if;
		end if;
	end process;
	-- 目盛り文字設定　10個ごとに '|' にする
	S8_SCALE_DATA	<= X"7C" when ( S8_10_PIECES_END = '1' ) else X"2D";	-- '|', '-'
	-- 目盛りカウンター(全体)
	S8_SCALE_END	<= '1' when ( S8_SCALE_C = X"63" ) else '0';
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then			S8_SCALE_C	<= (others => '0');
			elsif ( S8_STATUS = S8_SCALE ) then	S8_SCALE_C	<= (others => '0');
			-- END
			elsif ( S8_SCALE_END = '1' ) then	S8_SCALE_C	<= S8_SCALE_C;	-- KEEP
			-- +1
			else								S8_SCALE_C	<= S8_SCALE_C + 1;
			end if;
		end if;
	end process;
	-- 目盛りカウンター(10個単位)
	S8_10_PIECES_END	<= '1' when ( S8_10_PIECES_C = X"09" ) else '0';
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then				S8_10_PIECES_C	<= (others => '0');
			elsif ( S8_STATUS = S8_SCALE ) then		S8_10_PIECES_C	<= SCALE_OFFSET;
			elsif ( S8_10_PIECES_END = '1' ) then	S8_10_PIECES_C	<= (others => '0');
			-- +1
			else									S8_10_PIECES_C	<= S8_10_PIECES_C + 1;
			end if;
		end if;
	end process;
	-- UARTバッファ、アドレス
	UART_BUF_ADD_S8_CLR	<= '1' when (	( S8_STATUS = S8_START_WAIT )		or	( S8_STATUS = S8_ATT_CLR )
									or	( S8_STATUS = S8_ATT_CLR_L1 )		or	( S8_STATUS = S8_ATT_CLR_SEND )
									or	( S8_STATUS = S8_ATT_CLR_SEND_L2 )	or	( S8_STATUS = S8_JOB_START )
									or	( S8_STATUS = S8_STATUS_END ) ) else '0';
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					UART_BUF_ADD_S8	<= (others => '0');
			elsif ( UART_BUF_ADD_S8_CLR = '1' ) then	UART_BUF_ADD_S8	<= (others => '0');
			-- +1
			else										UART_BUF_ADD_S8	<= UART_BUF_ADD_S8 + 1;
			end if;
		end if;
	end process;
	-- UART WRITE信号
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					UART_BUF_WR_EN_S8	<= '0';
			elsif ( S8_STATUS = S8_START_WAIT ) then	UART_BUF_WR_EN_S8	<= '0';
			elsif ( S8_STATUS = S8_STATUS_END ) then	UART_BUF_WR_EN_S8	<= '0';
			-- ON
			elsif ( S8_STATUS = S8_JOB_START ) then		UART_BUF_WR_EN_S8	<= '1';
			-- KEEP
			else										UART_BUF_WR_EN_S8	<= UART_BUF_WR_EN_S8;
			end if;
		end if;
	end process;
	-- S2:終了
	S8_JOB_END	<= '1' when ( S8_STATUS = S8_STATUS_END ) else '0';

	---------------------------------------------
	-- 波形データ収集[S5]
	---------------------------------------------
	-- 動作開始条件 -----------------------------
	S5_START_F	<= '1' when ( S1_STATUS = S1_GET_WAVE_DATA ) else '0';
	-- シーケンサ -------------------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				S5_STATUS			<= S5_START_WAIT;
			else
				case S5_STATUS is
				-- 開始待機中
				when S5_START_WAIT =>
					if ( S5_START_F = '1' ) then		S5_STATUS <= S5_PRE_ACQUIS;		-- 動作開始
					else								S5_STATUS <= S5_START_WAIT;
					end if;
				-- 事前取り込み開始
				when S5_PRE_ACQUIS =>					S5_STATUS <= S5_PRE_ACQUIS_L;
				when S5_PRE_ACQUIS_L =>
					if ( PRE_ACQUIS_END = '1' ) then	S5_STATUS <= S5_TRIG_WAIT;
					else								S5_STATUS <= S5_PRE_ACQUIS_L;	-- LOOP
					end if;
				-- トリガー待ち
				when S5_TRIG_WAIT =>					S5_STATUS <= S5_TRIG_WAIT_L;
				when S5_TRIG_WAIT_L =>
					if ( TRIG_DETECT_F = '1' ) then		S5_STATUS <= S5_POST_ACQUIS;
					elsif ( TRIG_TIMEOUT_F = '1' ) then	S5_STATUS <= S5_POST_ACQUIS;	-- TIME OUT 判定
					else								S5_STATUS <= S5_TRIG_WAIT_L;	-- LOOP
					end if;
				-- トリガー以降の取り込み完了待ち
				when S5_POST_ACQUIS =>					S5_STATUS <= S5_POST_ACQUIS_L;
				when S5_POST_ACQUIS_L =>
					if ( POST_ACQUIS_END = '1' ) then	S5_STATUS <= S5_STATUS_END;		-- 終了
					else								S5_STATUS <= S5_POST_ACQUIS_L;	-- LOOP
					end if;
				-- 終了
				when S5_STATUS_END =>
					S5_STATUS			<= S5_START_WAIT;
				-- その他(本来ここは実行されない)
				when others	=>
					S5_STATUS			<= S5_START_WAIT;
				end case;
			end if;
		end if;
	end process;
	-- S5:終了
	S5_JOB_END	<= '1' when ( S5_STATUS = S5_STATUS_END ) else '0';

	---------------------------------------------
	-- 100mS 時間カウンタ
	---------------------------------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				TRIG_TIMEOUT_C	<= (others => '0');
				TRIG_TIMEOUT_F	<= '0';
			-- [S5] 処理
			elsif ( S5_STATUS = S5_TRIG_WAIT ) then
				TRIG_TIMEOUT_C	<= (others => '0');
				TRIG_TIMEOUT_F	<= '0';
			-- [S1] 処理
			elsif ( S1_STATUS = S1_TIME_WAIT ) then
				TRIG_TIMEOUT_C	<= (others => '0');
				TRIG_TIMEOUT_F	<= '0';
			-- TIME OUT
			elsif ( TRIG_TIMEOUT_C = COUNT_TRIG_TIMEOUT ) then
				TRIG_TIMEOUT_C	<= TRIG_TIMEOUT_C;
				TRIG_TIMEOUT_F	<= '1';
			-- +1
			else
				TRIG_TIMEOUT_C	<= TRIG_TIMEOUT_C + 1 ;
			end if;
		end if;
	end process;

	---------------------------------------------
	-- トリガポイントデータ生成[S7]
	---------------------------------------------
	-- トリガーポイントを表示する

	-- ポジション調整スペース数、CHxx表示分を追加して調整
	TRIG_POSITION_END(7 downto 0)	<= SIG_DISP_OFFSET(7 downto 0) + X"06";
	-- 動作開始条件
	S7_START_F	<= '1' when ( S1_STATUS = S1_WAVEDATA_JOB ) else '0';
	-- シーケンサ -------------------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			if ( nRESET = '0' ) then
				UART_BUF_DATA_WR_S7			<= (others => '0');
				S7_STATUS					<= S7_START_WAIT;
			else
				case S7_STATUS is
				-- 開始待機中 -------------------
				when S7_START_WAIT =>
					UART_BUF_DATA_WR_S7		<= (others => '0');
					if ( S7_START_F = '1' ) then	S7_STATUS <= S7_CH_COLOR;
					else							S7_STATUS <= S7_START_WAIT;	-- LOOP
					end if;
				-- CH色設定 ---------------------
				--	1Bh,5Bh,33h,SEND_WAVE_COLOR,6Dh => 1Bh,5Bh,'3','色','m'
				when S7_CH_COLOR =>
					UART_BUF_DATA_WR_S7		<= X"1B";
					S7_STATUS				<= S7_CH_COLOR_N1;
				when S7_CH_COLOR_N1 =>
					UART_BUF_DATA_WR_S7		<= X"5B";
					S7_STATUS				<= S7_CH_COLOR_N2;
				when S7_CH_COLOR_N2 =>
					UART_BUF_DATA_WR_S7		<= X"33";
					S7_STATUS				<= S7_CH_COLOR_N3;
				when S7_CH_COLOR_N3 =>
					UART_BUF_DATA_WR_S7		<= X"37";			-- 白
					S7_STATUS				<= S7_CH_COLOR_N4;
				when S7_CH_COLOR_N4 =>
					UART_BUF_DATA_WR_S7		<= X"6D";
					S7_STATUS				<= S7_POSITION;
				-- 座標調整 ---------------------
				when S7_POSITION =>
					UART_BUF_DATA_WR_S7		<= X"20";			-- SPACE
					S7_STATUS				<= S7_STATUS_L1;	-- LOOP
				when S7_STATUS_L1 =>
					UART_BUF_DATA_WR_S7		<= UART_BUF_DATA_WR_S7;
					if ( TRIG_POSITION_C = TRIG_POSITION_END ) then	S7_STATUS <= S7_STATUS_N1;
					else											S7_STATUS <= S7_STATUS_L1;	-- LOOP
					end if;
				-- トリガーマーカー
				when S7_STATUS_N1 =>
					if ( WAVE_CH_C = X"0" ) then	UART_BUF_DATA_WR_S7	<= X"54";	-- 'T'
					else							UART_BUF_DATA_WR_S7	<= X"7C";	-- '|'
					end if;
					S7_STATUS				<= S7_STATUS_N2;
				when S7_STATUS_N2 =>
					UART_BUF_DATA_WR_S7		<= X"20";		-- ' ' ※左移動時の文字消し
					S7_STATUS				<= S7_STATUS_N3;
				when S7_STATUS_N3 =>
					UART_BUF_DATA_WR_S7		<= X"0D";
					S7_STATUS				<= S7_STATUS_N4;
				when S7_STATUS_N4 =>
					UART_BUF_DATA_WR_S7		<= X"0A";
					S7_STATUS				<= S7_STATUS_N5;
				-- 00h
				when S7_STATUS_N5 =>
					UART_BUF_DATA_WR_S7		<= X"00";
					S7_STATUS				<= S7_STATUS_END;
				-- 終了
				when S7_STATUS_END =>
					UART_BUF_DATA_WR_S7		<= (others => '0');
					S7_STATUS				<= S7_START_WAIT;
				-- その他(本来ここは実行されない)
				when others	=>
					UART_BUF_DATA_WR_S7		<= (others => '0');
					S7_STATUS				<= S7_START_WAIT;
				end case;
			end if;
		end if;
	end process;
	-- トリガーポジションカウンター
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					TRIG_POSITION_C	<= (others => '0');
			elsif ( S7_STATUS = S7_START_WAIT ) then	TRIG_POSITION_C	<= (others => '0');
			-- +1
			elsif ( S7_STATUS = S7_POSITION ) then		TRIG_POSITION_C	<= TRIG_POSITION_C + 1;
			elsif ( S7_STATUS = S7_STATUS_L1 ) then		TRIG_POSITION_C	<= TRIG_POSITION_C + 1;
			-- KEEP
			else										TRIG_POSITION_C	<= TRIG_POSITION_C;	
			end if;
		end if;
	end process;
	-- UARTバッファ、アドレス
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					UART_BUF_ADD_S7	<= (others => '0');
			elsif ( S7_STATUS = S7_START_WAIT ) then	UART_BUF_ADD_S7	<= (others => '0');
			elsif ( S7_STATUS = S7_CH_COLOR ) then		UART_BUF_ADD_S7	<= (others => '0');
			elsif ( S7_STATUS = S7_STATUS_END ) then	UART_BUF_ADD_S7	<= (others => '0');
			-- +1
			else										UART_BUF_ADD_S7	<= UART_BUF_ADD_S7 + 1;
			end if;
		end if;
	end process;
	-- UART WRITE信号
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					UART_BUF_WR_EN_S7	<= '0';
			elsif ( S7_STATUS = S7_START_WAIT ) then	UART_BUF_WR_EN_S7	<= '0';
			elsif ( S7_STATUS = S7_STATUS_END ) then	UART_BUF_WR_EN_S7	<= '0';
			-- ON
			elsif ( S7_STATUS = S7_CH_COLOR ) then		UART_BUF_WR_EN_S7	<= '1';
			-- KEEP
			else										UART_BUF_WR_EN_S7	<= UART_BUF_WR_EN_S7;
			end if;
		end if;
	end process;
	-- S7:終了
	S7_JOB_END	<= '1' when ( S7_STATUS = S7_STATUS_END ) else '0';

	---------------------------------------------
	-- CH00-15 ループカウンター
	---------------------------------------------
	-- ループカウンター -------------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				WAVE_CH_C		<= (others => '0');
				WAVE_CH_C_END	<= '0';
			elsif ( S1_STATUS = S1_WAVE_DISP_JOB ) then
				WAVE_CH_C		<= (others => '0');
				WAVE_CH_C_END	<= '0';
			-- END
			elsif ( WAVE_CH_C = X"F" ) then
				WAVE_CH_C		<= WAVE_CH_C;	-- KEEP
				WAVE_CH_C_END	<= '1';
			-- +1
			elsif ( S1_STATUS = S1_NEXT_WAVE ) then
				WAVE_CH_C		<= WAVE_CH_C +1;
				WAVE_CH_C_END	<= '0';
			-- KEEP
			else
				WAVE_CH_C		<= WAVE_CH_C;	-- KEEP
				WAVE_CH_C_END	<= '0';
			end if;
		end if;
	end process;
	-- CH00-15 CH番号文字列生成 -----------------
	WAVE_CH_NUM_10		<= X"30" when ( WAVE_CH_C < X"A" ) else X"31";						-- 10の位
	TEMP_WAVE_CH_NUM	<= WAVE_CH_C when ( WAVE_CH_C < X"A" ) else ( WAVE_CH_C - X"A" );	-- 1の位
	WAVE_CH_NUM_01		<= ( "0000" & TEMP_WAVE_CH_NUM ) + X"30";

	---------------------------------------------
	-- トリガー検出信号
	---------------------------------------------
	-- CH 信号選択
	TEMP_TRIG_d2	<=	SIG_IN_DATA_d3(0)	when ( MENU_TRIG_CH = X"0" )
				else	SIG_IN_DATA_d3(1)	when ( MENU_TRIG_CH = X"1" )
				else	SIG_IN_DATA_d3(2)	when ( MENU_TRIG_CH = X"2" )
				else	SIG_IN_DATA_d3(3)	when ( MENU_TRIG_CH = X"3" )
				else	SIG_IN_DATA_d3(4)	when ( MENU_TRIG_CH = X"4" )
				else	SIG_IN_DATA_d3(5)	when ( MENU_TRIG_CH = X"5" )
				else	SIG_IN_DATA_d3(6)	when ( MENU_TRIG_CH = X"6" )
				else	SIG_IN_DATA_d3(7)	when ( MENU_TRIG_CH = X"7" )
				else	SIG_IN_DATA_d3(8)	when ( MENU_TRIG_CH = X"8" )
				else	SIG_IN_DATA_d3(9)	when ( MENU_TRIG_CH = X"9" )
				else	SIG_IN_DATA_d3(10)	when ( MENU_TRIG_CH = X"A" )
				else	SIG_IN_DATA_d3(11)	when ( MENU_TRIG_CH = X"B" )
				else	SIG_IN_DATA_d3(12)	when ( MENU_TRIG_CH = X"C" )
				else	SIG_IN_DATA_d3(13)	when ( MENU_TRIG_CH = X"D" )
				else	SIG_IN_DATA_d3(14)	when ( MENU_TRIG_CH = X"E" )
				else	SIG_IN_DATA_d3(15);	-- 	when ( MENU_TRIG_CH = "F" )
	TEMP_TRIG_d3	<=	SIG_IN_DATA_d4(0)	when ( MENU_TRIG_CH = X"0" )
				else	SIG_IN_DATA_d4(1)	when ( MENU_TRIG_CH = X"1" )
				else	SIG_IN_DATA_d4(2)	when ( MENU_TRIG_CH = X"2" )
				else	SIG_IN_DATA_d4(3)	when ( MENU_TRIG_CH = X"3" )
				else	SIG_IN_DATA_d4(4)	when ( MENU_TRIG_CH = X"4" )
				else	SIG_IN_DATA_d4(5)	when ( MENU_TRIG_CH = X"5" )
				else	SIG_IN_DATA_d4(6)	when ( MENU_TRIG_CH = X"6" )
				else	SIG_IN_DATA_d4(7)	when ( MENU_TRIG_CH = X"7" )
				else	SIG_IN_DATA_d4(8)	when ( MENU_TRIG_CH = X"8" )
				else	SIG_IN_DATA_d4(9)	when ( MENU_TRIG_CH = X"9" )
				else	SIG_IN_DATA_d4(10)	when ( MENU_TRIG_CH = X"A" )
				else	SIG_IN_DATA_d4(11)	when ( MENU_TRIG_CH = X"B" )
				else	SIG_IN_DATA_d4(12)	when ( MENU_TRIG_CH = X"C" )
				else	SIG_IN_DATA_d4(13)	when ( MENU_TRIG_CH = X"D" )
				else	SIG_IN_DATA_d4(14)	when ( MENU_TRIG_CH = X"E" )
				else	SIG_IN_DATA_d4(15);	-- 	when ( MENU_TRIG_CH = "F" )
	-- 立上り／立下り
	TEMP_TRIG_UP	<= TEMP_TRIG_d2 and ( not TEMP_TRIG_d3 );
	TEMP_TRIG_DOWN	<= ( not TEMP_TRIG_d2 ) and TEMP_TRIG_d3;
	TEMP_TRIG_F		<= TEMP_TRIG_UP when ( MENU_TRIG_EDGE = '0' ) else TEMP_TRIG_DOWN;
	-- トリガー検出有効タイミング
	TRIG_DETECT_TIMING	<= '1' when ( S5_STATUS = S5_TRIG_WAIT_L ) else '0';
	-- トリガー検出条件
	TRIG_DETECT_F	<= TRIG_DETECT_TIMING and TEMP_TRIG_F;

	---------------------------------------------
	-- 波形データをバッファに取り込む
	---------------------------------------------
	-- 波形取り込みタイミング分周 ---------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				SAMPLING_DIV_C		<= (others => '0');		-- SAMPLING_DIV : 00-FFh
				SAMPLING_TIMING_F	<= '0';
			-- 事前取り込み開始
			elsif ( S5_STATUS = S5_PRE_ACQUIS ) then
				SAMPLING_DIV_C		<= (others => '0');		-- SAMPLING_DIV : 00-FFh
				SAMPLING_TIMING_F	<= '0';
			-- 波形取り込み
			elsif ( SAMPLING_DIV_C = SAMPLING_DIV ) then
				SAMPLING_DIV_C		<= (others => '0');
				SAMPLING_TIMING_F	<= '1';
			-- +1
			else
				SAMPLING_DIV_C		<= SAMPLING_DIV_C + 1 ;
				SAMPLING_TIMING_F	<= '0';
			end if;
		end if;
	end process;
	-- 波形バッファアドレス[WRITE] --------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then				SIG_BUF_ADD_WR(7 downto 0)	<= (others => '0');
			-- +1 (サンプリングタイミング時)
			elsif ( SAMPLING_TIMING_F = '1' ) then	SIG_BUF_ADD_WR(7 downto 0)	<= SIG_BUF_ADD_WR(7 downto 0) + 1 ;
			-- KEEP
			else									SIG_BUF_ADD_WR(7 downto 0)	<= SIG_BUF_ADD_WR(7 downto 0);
			end if;
		end if;
	end process;
	-- バッファ書き込みWRITE制御 ----------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					SIG_BUF_WR	<= '0';
			-- トリガーモード停止中判定
			elsif ( TRIG_TYPE_2 = "10" ) then			SIG_BUF_WR	<= '0';		-- 書き込み禁止
			-- バッファ用WRITE:ON
			elsif ( S5_STATUS = S5_PRE_ACQUIS ) then	SIG_BUF_WR	<= '1';
			-- バッファ用WRITE:OFF
			elsif ( S5_STATUS = S5_STATUS_END ) then	SIG_BUF_WR	<= '0';
			-- KEEP
			else										SIG_BUF_WR	<= SIG_BUF_WR;
			end if;
		end if;
	end process;
	-- 波形表示開始アドレス記録 ---------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then			SIG_DISP_START_ADD(7 downto 0)	<= (others => '0');
			-- トリガー時のアドレス記録
			--	トリガー前の波形表示のため、オフセット分を減算する
			elsif ( TRIG_DETECT_F = '1' ) then	SIG_DISP_START_ADD(7 downto 0)	<= SIG_BUF_ADD_WR(7 downto 0) - SIG_DISP_OFFSET(7 downto 0);
			-- KEEP
			else								SIG_DISP_START_ADD(7 downto 0)	<= SIG_DISP_START_ADD(7 downto 0);
			end if;
		end if;
	end process;
	-- トリガー前取り込みカウンター ---------
	PRE_ACQUIS_END	<= '1' when ( SIG_PRE_GET_C(7 downto 0) = COUNT_WAVE_WIDTH ) else '0';
	-- カウント
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					SIG_PRE_GET_C(7 downto 0)	<= (others => '0');
			elsif ( S5_STATUS = S5_PRE_ACQUIS ) then	SIG_PRE_GET_C(7 downto 0)	<= (others => '0');
			-- 終了判定
			elsif ( PRE_ACQUIS_END = '1' ) then			SIG_PRE_GET_C(7 downto 0)	<= SIG_PRE_GET_C(7 downto 0);
			-- +1
			elsif ( SAMPLING_TIMING_F = '1' ) then		SIG_PRE_GET_C(7 downto 0)	<= SIG_PRE_GET_C(7 downto 0) + 1 ;
			-- KEEP
			else										SIG_PRE_GET_C(7 downto 0)	<= SIG_PRE_GET_C(7 downto 0);
			end if;
		end if;
	end process;
	-- トリガー以降の取り込みカウンター ---------
	-- 波形データ取り込み処理終了
	POST_ACQUIS_END	<= '1' when ( SIG_POST_GET_C(7 downto 0) = COUNT_WAVE_WIDTH ) else '0';
	-- カウント
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					SIG_POST_GET_C(7 downto 0)	<= (others => '0');
			elsif ( S5_STATUS = S5_POST_ACQUIS ) then	SIG_POST_GET_C(7 downto 0)	<= (others => '0');
			-- 終了判定
			elsif ( POST_ACQUIS_END = '1' ) then		SIG_POST_GET_C(7 downto 0)	<= SIG_POST_GET_C(7 downto 0);
			-- +1 
			elsif ( SAMPLING_TIMING_F = '1' ) then		SIG_POST_GET_C(7 downto 0)	<= SIG_POST_GET_C(7 downto 0) + 1 ;
			-- KEEP
			else										SIG_POST_GET_C(7 downto 0)	<= SIG_POST_GET_C(7 downto 0);
			end if;
		end if;
	end process;

	---------------------------------------------
	-- 波形送信データ生成[S4]
	---------------------------------------------
	-- 波形データ CH 選択 -----------------------
	SEND_WAVE_DATA	<=	SIG_BUF_DATA_RD(0)	when ( WAVE_CH_C = X"0" )
				else	SIG_BUF_DATA_RD(1)	when ( WAVE_CH_C = X"1" )
				else	SIG_BUF_DATA_RD(2)	when ( WAVE_CH_C = X"2" )
				else	SIG_BUF_DATA_RD(3)	when ( WAVE_CH_C = X"3" )
				else	SIG_BUF_DATA_RD(4)	when ( WAVE_CH_C = X"4" )
				else	SIG_BUF_DATA_RD(5)	when ( WAVE_CH_C = X"5" )
				else	SIG_BUF_DATA_RD(6)	when ( WAVE_CH_C = X"6" )
				else	SIG_BUF_DATA_RD(7)	when ( WAVE_CH_C = X"7" )
				else	SIG_BUF_DATA_RD(8)	when ( WAVE_CH_C = X"8" )
				else	SIG_BUF_DATA_RD(9)	when ( WAVE_CH_C = X"9" )
				else	SIG_BUF_DATA_RD(10)	when ( WAVE_CH_C = X"A" )
				else	SIG_BUF_DATA_RD(11)	when ( WAVE_CH_C = X"B" )
				else	SIG_BUF_DATA_RD(12)	when ( WAVE_CH_C = X"C" )
				else	SIG_BUF_DATA_RD(13)	when ( WAVE_CH_C = X"D" )
				else	SIG_BUF_DATA_RD(14)	when ( WAVE_CH_C = X"E" )
				else	SIG_BUF_DATA_RD(15);  -- ( WAVE_CH_C = X"F" )
	-- 色 CH 選択 -------------------------------
	--	'1' 赤(色番号1),	'2' 緑(色番号2),	'3' 黄色(色番号3),	'4' 青(色番号4)
	--	'5' 赤紫(色番号5),	'6' 水色(色番号6)
	-- このうち、見やすい4色のみ使用
	SEND_WAVE_COLOR	<=	X"32" when ( WAVE_CH_C = X"0" )	--	'2' 文字色を緑(色番号2)
				else	X"33" when ( WAVE_CH_C = X"1" )	--	'3' 文字色を黄色(色番号3)
				else	X"35" when ( WAVE_CH_C = X"2" )	--	'5' 文字色を赤紫(色番号5)
				else	X"36" when ( WAVE_CH_C = X"3" )	--	'6' 文字色を水色(色番号6)
				else	X"32" when ( WAVE_CH_C = X"4" )
				else	X"33" when ( WAVE_CH_C = X"5" )
				else	X"35" when ( WAVE_CH_C = X"6" )
				else	X"36" when ( WAVE_CH_C = X"7" )
				else	X"32" when ( WAVE_CH_C = X"8" )
				else	X"33" when ( WAVE_CH_C = X"9" )
				else	X"35" when ( WAVE_CH_C = X"A" )
				else	X"36" when ( WAVE_CH_C = X"B" )
				else	X"32" when ( WAVE_CH_C = X"C" )
				else	X"33" when ( WAVE_CH_C = X"D" )
				else	X"35" when ( WAVE_CH_C = X"E" )
				else	X"36";  -- ( WAVE_CH_C = X"F" )
	-- 動作開始条件
	S4_START_F	<= '1' when ( S1_STATUS = S1_WAVEDATA_SET ) else '0';
	-- シーケンサ -------------------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			if ( nRESET = '0' ) then
				UART_BUF_DATA_WR_S4			<= (others => '0');
				S4_STATUS					<= S4_START_WAIT;
			else
				case S4_STATUS is
				-- 開始待機中 -------------------
				when S4_START_WAIT =>				UART_BUF_DATA_WR_S4	<= (others => '0');
					if ( S4_START_F = '1' ) then	S4_STATUS			<= S4_CH_COLOR;
					else							S4_STATUS			<= S4_START_WAIT;	-- LOOP
					end if;
				-- CH番号生成 -------------------
				-- 色設定 : 1Bh,5Bh,'3','色','m'
				when S4_CH_COLOR =>
					UART_BUF_DATA_WR_S4			<= X"1B";
					S4_STATUS					<= S4_CH_COLOR_N1;
				when S4_CH_COLOR_N1 =>
					UART_BUF_DATA_WR_S4			<= X"5B";
					S4_STATUS					<= S4_CH_COLOR_N2;
				when S4_CH_COLOR_N2 =>
					UART_BUF_DATA_WR_S4			<= X"33";
					S4_STATUS					<= S4_CH_COLOR_N3;
				when S4_CH_COLOR_N3 =>
					UART_BUF_DATA_WR_S4			<= SEND_WAVE_COLOR;
					S4_STATUS					<= S4_CH_COLOR_N4;
				when S4_CH_COLOR_N4 =>
					UART_BUF_DATA_WR_S4			<= X"6D";
					if ( MENU_TRIG_CH = WAVE_CH_C ) then	S4_STATUS <= S4_HANTEN_ON;	-- 反転文字
					else									S4_STATUS <= S4_CH_NUMBER;
					end if;
				-- 反転処理
				when S4_HANTEN_ON =>
					UART_BUF_DATA_WR_S4			<= X"1B";
					S4_STATUS					<= S4_HANTEN_ON_N1;
				when S4_HANTEN_ON_N1 =>
					UART_BUF_DATA_WR_S4			<= X"5B";
					S4_STATUS					<= S4_HANTEN_ON_N2;
				when S4_HANTEN_ON_N2 =>
					UART_BUF_DATA_WR_S4			<= X"37";				-- '7'
					S4_STATUS					<= S4_HANTEN_ON_N3;
				when S4_HANTEN_ON_N3 =>
					UART_BUF_DATA_WR_S4			<= X"6D";
					S4_STATUS					<= S4_CH_NUMBER;
				-- 文字列(2桁)
				when S4_CH_NUMBER =>
					UART_BUF_DATA_WR_S4			<= X"20";	-- ' '
					S4_STATUS					<= S4_CH_NUM_1;
				when S4_CH_NUM_1 =>
					UART_BUF_DATA_WR_S4			<= X"43";	-- 'C'
					S4_STATUS					<= S4_CH_NUM_2;
				when S4_CH_NUM_2 =>
					UART_BUF_DATA_WR_S4			<= X"48";	-- 'H'
					S4_STATUS					<= S4_CH_NUM_3;
				when S4_CH_NUM_3 =>
					UART_BUF_DATA_WR_S4			<= WAVE_CH_NUM_10;		-- 番号:10の位
					S4_STATUS					<= S4_CH_NUM_4;
				when S4_CH_NUM_4 =>
					UART_BUF_DATA_WR_S4			<= WAVE_CH_NUM_01;		-- 番号:1の位
					S4_STATUS					<= S4_CH_NUM_5;
				when S4_CH_NUM_5 =>
					UART_BUF_DATA_WR_S4			<= X"20";	-- ' '
					if ( MENU_TRIG_CH = WAVE_CH_C ) then	S4_STATUS <= S4_HANTEN_OFF;	-- 反転解除
					else									S4_STATUS <= S4_SIG_DATA_ST1;
					end if;
				-- 反転解除
				when S4_HANTEN_OFF =>
					UART_BUF_DATA_WR_S4			<= X"1B";
					S4_STATUS					<= S4_HANTEN_OFF_N1;
				when S4_HANTEN_OFF_N1 =>
					UART_BUF_DATA_WR_S4			<= X"5B";
					S4_STATUS					<= S4_HANTEN_OFF_N2;
				when S4_HANTEN_OFF_N2 =>
					UART_BUF_DATA_WR_S4			<= X"32";				-- '2'
					S4_STATUS					<= S4_HANTEN_OFF_N3;
				when S4_HANTEN_OFF_N3 =>
					UART_BUF_DATA_WR_S4			<= X"37";				-- '7'
					S4_STATUS					<= S4_HANTEN_OFF_N4;
				when S4_HANTEN_OFF_N4 =>
					UART_BUF_DATA_WR_S4			<= X"6D";
					S4_STATUS					<= S4_SIG_DATA_ST1;
				-- 波形データ設定 ---------------
				when S4_SIG_DATA_ST1 =>
					UART_BUF_DATA_WR_S4			<= X"2A";	-- '*': このデータが無効となる確認
					S4_STATUS					<= S4_SIG_DATA_ST2;
				-- 波形データバッファアドレス[READ]を 1-CLOCK 早く設定するための CLOCK
				when S4_SIG_DATA_ST2 =>
					UART_BUF_DATA_WR_S4			<= X"23";	-- '#': このデータが無効となる確認
					S4_STATUS					<= S4_SIG_DATA_1BYTE;
				when S4_SIG_DATA_1BYTE =>
					if ( SEND_WAVE_DATA = '1' ) then	UART_BUF_DATA_WR_S4 <= X"7E";	-- H = '~'
					else								UART_BUF_DATA_WR_S4 <= X"5F";	-- L = '_'
					end if;
					if ( SIG_BUF_SET_END = '1' ) then	S4_STATUS	<= S4_STATUS_CRLF;	-- 終了
					else								S4_STATUS	<= S4_SIG_DATA_1BYTE;
					end if;
				-- 改行コード設定 ---------------
				-- 0Dh, 0Ah, 0Ah
				when S4_STATUS_CRLF =>
					UART_BUF_DATA_WR_S4 		<= X"0D";
					S4_STATUS					<= S4_STATUS_CRLF_2;
				when S4_STATUS_CRLF_2 =>
					UART_BUF_DATA_WR_S4 		<= X"0A";
					S4_STATUS					<= S4_STATUS_00h;
				-- 終了コード設定 [00h] ---------
				when S4_STATUS_00h =>
					UART_BUF_DATA_WR_S4 		<= X"00";
					S4_STATUS					<= S4_STATUS_END;
				-- 終了 -------------------------
				when S4_STATUS_END =>
					UART_BUF_DATA_WR_S4 		<= X"00";
					S4_STATUS					<= S4_START_WAIT;
				-- その他(本来ここは実行されない)
				when others	=>
					UART_BUF_DATA_WR_S4			<= (others => '0');
					S4_STATUS					<= S4_START_WAIT;
				end case;
			end if;
		end if;
	end process;
	-- 波形バッファアドレス選択 -----------------
	SIG_BUF_ADD(7 downto 0)	<=	SIG_BUF_ADD_WR(7 downto 0) when ( SIG_BUF_WR = '1' )	-- WRITE時
						else	SIG_BUF_ADD_RD(7 downto 0);								-- READ時
	-- 波形の横方向カウンタ 1CH分 --------------- 
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				SIG_BUF_SET_LOOP	<= (others => '0');
				SIG_BUF_SET_END		<= '0';
			elsif ( S4_STATUS = S4_SIG_DATA_ST2 ) then
				SIG_BUF_SET_LOOP	<= (others => '0');
				SIG_BUF_SET_END		<= '0';
			-- END
			elsif ( SIG_BUF_SET_LOOP = ( COUNT_WAVE_WIDTH - 1 ) ) then
				SIG_BUF_SET_LOOP	<= SIG_BUF_SET_LOOP;	-- KEEP
				SIG_BUF_SET_END		<= '1';
			-- +1
			else
				SIG_BUF_SET_LOOP	<= SIG_BUF_SET_LOOP + 1 ;
				SIG_BUF_SET_END		<= '0';
			end if;
		end if;
	end process;
	-- 波形データバッファアドレス[READ]
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					SIG_BUF_ADD_RD	<= (others => '0');
			elsif ( S4_STATUS = S4_START_WAIT ) then	SIG_BUF_ADD_RD	<= (others => '0');
			-- 波形表示開始アドレス
			elsif ( S4_STATUS = S4_SIG_DATA_ST1 ) then	SIG_BUF_ADD_RD	<= SIG_DISP_START_ADD;
			-- +1
			else										SIG_BUF_ADD_RD	<= SIG_BUF_ADD_RD + 1 ;
			end if;
		end if;
	end process;
	-- UARTバッファ、アドレス
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then					UART_BUF_ADD_S4	<= (others => '0');
			-- [S4]
			elsif ( S4_STATUS = S4_START_WAIT ) then	UART_BUF_ADD_S4	<= (others => '0');
			elsif ( S4_STATUS = S4_CH_COLOR ) then		UART_BUF_ADD_S4	<= (others => '0');
			elsif ( S4_STATUS = S4_STATUS_END ) then	UART_BUF_ADD_S4	<= (others => '0');
			-- KEEP
			elsif ( S4_STATUS = S4_SIG_DATA_ST1 ) then	UART_BUF_ADD_S4	<= UART_BUF_ADD_S4;
			elsif ( S4_STATUS = S4_SIG_DATA_ST2 ) then	UART_BUF_ADD_S4	<= UART_BUF_ADD_S4;
			-- +1
			else										UART_BUF_ADD_S4	<= UART_BUF_ADD_S4 + 1;
			end if;
		end if;
	end process;
	-- UART WRITE信号
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then						UART_BUF_WR_EN_S4	<= '0';
			-- ON
			elsif ( S4_STATUS = S4_CH_COLOR ) then			UART_BUF_WR_EN_S4	<= '1';
			elsif ( S4_STATUS = S4_SIG_DATA_1BYTE ) then	UART_BUF_WR_EN_S4	<= '1';
			-- OFF
			elsif ( S4_STATUS = S4_START_WAIT ) then		UART_BUF_WR_EN_S4	<= '0';
			elsif ( S4_STATUS = S4_SIG_DATA_ST1 ) then		UART_BUF_WR_EN_S4	<= '0';
			elsif ( S4_STATUS = S4_SIG_DATA_ST2 ) then		UART_BUF_WR_EN_S4	<= '0';
			elsif ( S4_STATUS = S4_STATUS_END ) then		UART_BUF_WR_EN_S4	<= '0';
			-- KEEP
			else											UART_BUF_WR_EN_S4	<= UART_BUF_WR_EN_S4;
			end if;
		end if;
	end process;
	-- S4:終了
	S4_JOB_END	<= '1' when ( S4_STATUS = S4_STATUS_END ) else '0';

	---------------------------------------------
	-- UART送信[S3]
	---------------------------------------------
	-- UARTバッファ内のデータを送信する

	-- 送信バッファ用信号選択 -------------------
	--	・各ステートマシンの動作に合わせて選択する。
	--	・上位ステートから下位ステートが呼ばれることがあるため、下位ステートを優先する必要がある。
	--	・ここでは「選択方式」としているが、or 方式とどちらが効率が良いか判断は難しい。
	--
	-- アドレス選択
	UART_BUF_ADD		<=	UART_BUF_ADD_S3			when ( UART_BUF_WR_EN = '0' )			-- READ用 (最優先)
					else	UART_BUF_ADD_S11		when ( S11_STATUS /= S11_START_WAIT )	-- 優先 2番目
					else	UART_BUF_ADD_S2			when ( S2_STATUS  /= S2_START_WAIT )
					else	UART_BUF_ADD_S4			when ( S4_STATUS  /= S4_START_WAIT )
					else	UART_BUF_ADD_S6			when ( S6_STATUS  /= S6_START_WAIT )
					else	UART_BUF_ADD_S7			when ( S7_STATUS  /= S7_START_WAIT )
					else	UART_BUF_ADD_S8			when ( S8_STATUS  /= S8_START_WAIT )
					else	UART_BUF_ADD_S10		when ( S10_STATUS /= S10_START_WAIT )
					else	X"00";
	-- 書き込みデータ選択
	UART_BUF_DATA_WR	<=	UART_BUF_DATA_WR_S11	when ( S11_STATUS /= S11_START_WAIT )	-- 優先 2番目
					else	UART_BUF_DATA_WR_S2		when ( S2_STATUS  /= S2_START_WAIT )
					else	UART_BUF_DATA_WR_S4		when ( S4_STATUS  /= S4_START_WAIT )
					else	UART_BUF_DATA_WR_S6		when ( S6_STATUS  /= S6_START_WAIT )
					else	UART_BUF_DATA_WR_S7		when ( S7_STATUS  /= S7_START_WAIT )
					else	UART_BUF_DATA_WR_S8		when ( S8_STATUS  /= S8_START_WAIT )
					else	UART_BUF_DATA_WR_S10	when ( S10_STATUS /= S10_START_WAIT )
					else	X"00";
	-- WRITE 制御
	UART_BUF_WR_EN		<=	UART_BUF_WR_EN_S11 or UART_BUF_WR_EN_S2 or UART_BUF_WR_EN_S4
						or	UART_BUF_WR_EN_S6 or UART_BUF_WR_EN_S7 or UART_BUF_WR_EN_S8
						or	UART_BUF_WR_EN_S10;

	-- 動作開始条件 -----------------------------
	S3_START_F	<= '1'	when (	( S1_STATUS = S1_SCREEN_CLR_SEND )
							or	( S1_STATUS = S1_TITLE_SEND )
							or	( S1_STATUS = S1_MENU_SEND )
							or	( S1_STATUS = S1_SCAE_SEND )
							or	( S1_STATUS = S1_SEND_TRIG_POINT )
							or	( S1_STATUS = S1_SEND_WAVEFORM )
							or	( S6_STATUS = S6_ATT_CLR_SEND )
							or	( S8_STATUS = S8_ATT_CLR_SEND )
							) else '0';
	-- シーケンサ -------------------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			if ( nRESET = '0' ) then
				S3_STATUS			<= S3_START_WAIT;
			else
				case S3_STATUS is
				-- 開始待機中
				when S3_START_WAIT =>
					if ( S3_START_F = '1' ) then		S3_STATUS <= S3_END_CHECK;	-- 送信開始
					else								S3_STATUS <= S3_START_WAIT;	-- LOOP
					end if;
				-- 送信終了判定(データ=00h)
				when S3_END_CHECK =>
					if ( UART_BUF_DATA_RD = X"00" ) then	S3_STATUS <= S3_STATUS_END;	-- 送信終了
					else									S3_STATUS <= S3_DATA_SEND;	-- 送信へ
					end if;
				-- 送信開始
				when S3_DATA_SEND =>					S3_STATUS <= S3_LOOP;
				-- 送信待ち
				when S3_LOOP =>
					if ( TX_SEND_END = '1' ) then		S3_STATUS <= S3_ADD_INC;	-- 送信終了
					else								S3_STATUS <= S3_LOOP;		-- LOOP
					end if;
				-- ADD +1
				when S3_ADD_INC =>						S3_STATUS <= S3_DUMMY1;
				-- DUMMY (メモリREADタイミング待ち)
				when S3_DUMMY1 =>						S3_STATUS <= S3_END_CHECK;
				-- 終了
				when S3_STATUS_END =>					S3_STATUS <= S3_START_WAIT;
				-- その他(本来ここは実行されない)
				when others	=>							S3_STATUS <= S3_START_WAIT;	-- 最初からやり直し
				end case;
			end if;
		end if;
	end process;
	-- UART_BUF_ADD_S3 設定 ---------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				UART_BUF_ADD_S3		<= (others => '0');
			elsif ( S3_STATUS = S3_START_WAIT ) then
				UART_BUF_ADD_S3		<= (others => '0');
			-- +1
			elsif ( S3_STATUS = S3_ADD_INC ) then
				UART_BUF_ADD_S3		<= UART_BUF_ADD_S3 +1;
			-- KEEP
			else
				UART_BUF_ADD_S3		<= UART_BUF_ADD_S3;
			end if;
		end if;
	end process;
	-- UART 送信制御 ----------------------------
	process ( CLK_IN ) begin
		if ( CLK_IN'event and CLK_IN = '1' ) then	-- '
			-- RESET
			if ( nRESET = '0' ) then
				TX_DATA_IN		<= (others => '0');
				TX_SEND_START	<= '0';
			-- 1-BYTE 送信処理
			elsif ( S3_STATUS = S3_DATA_SEND ) then
				TX_DATA_IN		<= UART_BUF_DATA_RD;	-- UARTバッファREADデータ
				TX_SEND_START	<= '1';					-- 送信開始 1-CLOCK
			-- KEEP
			else
				TX_DATA_IN		<= TX_DATA_IN;
				TX_SEND_START	<= '0';
			end if;
		end if;
	end process;
	-- S3:終了
	S3_JOB_END	<= '1' when ( S3_STATUS = S3_STATUS_END ) else '0';

-- 出力 -------------------------------------------------------------------------------------------

-- END --------------------------------------------------------------------------------------------
-- (C) 2025 JAPAN LOGIC DESIGN 日本ロジック設計
-- No unauthorized reproduction or AI training allowed.
-- Unauthorized reproduction prohibited.
end RTL;

