	list      p=16F877            ; list directive to define processor
	#include <p16F877.inc>        ; processor specific variable definitions
;	org	0x40

; 変数定義
	CBLOCK	 H'20'			;16F877は20hから変数開始
	r_data
	buffer
	point
	tempa
	tempb	
	midmes
	note
	psga
	psgb
	psgc
	freq
	rough
	fine
	add_a
	add_b
	add_c
	COUNT
	CNT1
	CNT2
	CNT3
	ADR
	DAT
	ENDC

;ポートや変数の初期化部
	BSF		STATUS,RP0
	MOVLW	0x07			;すべてデジタルモードにする
	MOVWF	ADCON1
	BCF		STATUS,RP0
	CLRF	ADCON0			;A/D未使用

	BSF		STATUS,RP0		;ポートの入出力設定
	MOVLW	B'00000000'
	MOVWF	TRISA
	MOVLW	B'00000000'
	MOVWF	TRISB
	MOVLW	B'10000000'
	MOVWF	TRISC
	MOVLW	B'00000000'
	MOVWF	TRISD
	MOVLW	B'00000000'
	MOVWF	TRISE


;シリアルポート設定

	BCF		TXSTA,BRGH
	MOVLW	D'9'
	MOVWF	SPBRG			;ボーレート設定
	BCF		TXSTA,SYNC
	BCF		STATUS,RP0		;Set Page 0
	MOVLW	H'00'
	MOVWF	psga
	MOVWF	psgb
	MOVWF	psgc
	MOVLW	H'FF'
	MOVWF	add_a
	MOVWF	add_b
	MOVLW	H'1'
	MOVWF	add_c
	MOVLW	B'10000000'
	MOVWF	RCSTA			;受信ポート設定

	MOVLW	B'00000000'
	MOVWF	PORTD
	MOVWF	PORTE
	MOVWF	PORTC
	CALL 	TIM1SEC
;Initialize LCD
;9 RE1 RS
;8 RE0  E
	
	CALL	TIM100
	MOVLW	B'00110000'
	CALL	LCD_CMD

	CALL	TIM100
	MOVLW	B'00110000'
	CALL	LCD_CMD 

	CALL	TIM100
	MOVLW	B'00110000'
	CALL	LCD_CMD

	MOVLW	B'00111000'
	CALL	LCD_CMD

	MOVLW	B'00001000'
	CALL	LCD_CMD

	MOVLW	B'00000001'
	CALL	LCD_CMD

	MOVLW	B'00000110'
	CALL	LCD_CMD

;Main Part starts from here

	MOVLW	B'00001110'
	CALL	LCD_CMD
	MOVLW	A'M'
	CALL	LCD_DATA
	MOVLW	A'L'
	CALL	LCD_DATA
	MOVLW	H'03'
	MOVWF	tempb
	CALL	MIXVOL
	BSF	RCSTA,CREN

MAIN
	btfsc	RCSTA,OERR
	CALL	re_cren
	DECFSZ	add_a,f
	GOTO	ok1
	MOVLW	H'FF'
	MOVWF	add_a
	DECFSZ	add_b,f
	GOTO	ok1
	MOVLW	H'FF'
	MOVWF	add_b
	GOTO	all_sound_off2
ok1
	BTFSS	PIR1,RCIF
	GOTO	$-10
	CALL	GETDATA
;	MOVF	r_data,0
;	ANDLW	H'F0'
;	XORLW	H''
;	BTFSC	STATUS,Z
;	GOTO 			;ならとぶ
	MOVF	r_data,0
	XORLW	H'FE'
	BTFSC	STATUS,Z
	GOTO 	MAIN			;Active Sence

	CALL	kill_count
	MOVF	r_data,0
	XORLW	H'F8'
	BTFSC	STATUS,Z
	GOTO 	MAIN			;MIDI Clock

	MOVF	r_data,0
	XORLW	H'FC'
	BTFSC	STATUS,Z
	GOTO 	all_sound_off2		;ストップならとぶ

	MOVF	r_data,0
	XORLW	H'FF'
	BTFSC	STATUS,Z
	GOTO 	all_sound_off2		;リセットならとぶ

	MOVF	r_data,0
	ANDLW	H'F0'
	XORLW	H'90'
	BTFSC	STATUS,Z
	GOTO 	note_on			;Noteonメッセージならとぶ

	MOVF	r_data,0
	ANDLW	H'F0'
	XORLW	H'80'
	BTFSC	STATUS,Z
	GOTO 	note_off		;Noteoffメッセージならとぶ

	MOVF	r_data,0
	ANDLW	H'F0'
	XORLW	H'A0'
	BTFSC	STATUS,Z
	GOTO 	poly_key_press		;ポリフォニック・キー・プレッシャならとぶ

	MOVF	r_data,0
	ANDLW	H'F0'
	XORLW	H'D0'
	BTFSC	STATUS,Z
	GOTO 	ch_press		;チャンネルプレッシャならとぶ

	MOVF	r_data,0
	ANDLW	H'F0'
	XORLW	H'E0'
	BTFSC	STATUS,Z
	GOTO 	pitch_bend		;ピッチベンドならとぶ

	MOVF	r_data,0
	ANDLW	H'F0'
	XORLW	H'B0'
	BTFSC	STATUS,Z
	GOTO 	ctrl_chg		;コントロールチェンジならとぶ

	MOVF	r_data,0
	ANDLW	H'F0'
	XORLW	H'C0'
	BTFSC	STATUS,Z
	GOTO 	pgm_chg			;プログラムチェンジならとぶ

	MOVF	r_data,0
	XORLW	H'F0'
	BTFSC	STATUS,Z
	GOTO 	ex_mes			;エクスクルーシブメッセージならとぶ

	MOVF	r_data,0
	ANDLW	B'10000000'
	XORLW	H'00'
	BTFSC	STATUS,Z
	GOTO 	running_mes		;ランニングメッセージならとぶ

	GOTO 	MAIN
running_mes
	MOVF	midmes,W
	XORLW	H'80'
	BTFSC	STATUS,Z
	GOTO	note_off_run

	MOVF	midmes,W
	XORLW	H'90'
	BTFSC	STATUS,Z
	GOTO	note_on_run

	MOVF	midmes,W
	XORLW	H'A0'
	BTFSC	STATUS,Z
	GOTO	poly_key_press_run

	MOVF	midmes,W
	XORLW	H'D0'
	BTFSC	STATUS,Z
	GOTO	ch_press_run

	MOVF	midmes,W
	XORLW	H'E0'
	BTFSC	STATUS,Z
	GOTO	pitch_bend_run

	MOVF	midmes,W
	XORLW	H'B0'
	BTFSC	STATUS,Z
	GOTO	ctrl_chg_run

	MOVF	midmes,W
	XORLW	H'C0'
	BTFSC	STATUS,Z
	GOTO	pgm_chg_run

	MOVF	midmes,W
	XORLW	H'F0'
	BTFSC	STATUS,Z
	GOTO	ex_mes

	GOTO	MAIN

kill_count
	MOVLW	H'FF'
	MOVWF	add_a
	MOVWF	add_b
	MOVLW	H'1'
	MOVWF	add_c
	RETURN
disp_stat
	SWAPF	r_data,W
	MOVWF	tempa
	CALL	hextbl
	CALL 	LCD_DATA
	MOVF	r_data,0
	MOVWF	tempa
	CALL	hextbl
	CALL 	LCD_DATA
	RETURN

disp_w
	MOVWF	buffer
	SWAPF	buffer,W
	MOVWF	tempa
	CALL	hextbl
	CALL 	LCD_DATA
	MOVF	buffer,0
	MOVWF	tempa
	CALL	hextbl
	CALL 	LCD_DATA
	RETURN

hextbl
	MOVLW	H'00'
	MOVWF	PCLATH
	MOVF	tempa,W
	ANDLW	B'00001111'
	ADDWF	PCL,F

	RETLW	0x30
	RETLW	0x31
	RETLW	0x32
	RETLW	0x33
	RETLW	0x34
	RETLW	0x35
	RETLW	0x36
	RETLW	0x37
	RETLW	0x38
	RETLW	0x39
	RETLW	0x41
	RETLW	0x42
	RETLW	0x43
	RETLW	0x44
	RETLW	0x45
	RETLW	0x46

;ＭＩＤＩインターフェースオーバーフロー処理
re_cren
	BCF		RCSTA,CREN
	NOP
	BSF		RCSTA,CREN
	RETURN
;音源駆動用サブルーチン

MIXVOL
	MOVLW	B'00000111'	;Address		ミキサー設定
	MOVWF	ADR
	MOVLW	B'00111000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ

;エンベローブ
	MOVLW	H'0B'	;Address
	MOVWF	ADR
	MOVLW	B'10000100'	;Data
	MOVWF	DAT
	CALL	TO_YMZ
	MOVLW	H'0C'	;Address
	MOVWF	ADR
	MOVLW	B'00001110'	;Data
	MOVWF	DAT
	CALL	TO_YMZ
	RETURN
;ＹＭＺ２９４送信用サブ

TO_YMZ
	MOVLW	B'000000'
	MOVWF	PORTA		;Address write enabled
	MOVF	ADR,W		;ADR -> Wreg
	MOVWF	PORTB		;Address input
	MOVLW	B'000001'	
	MOVWF	PORTA		;Address write disabled
	MOVLW	B'100000'
	MOVWF	PORTA		;Data write enabled
	MOVF	DAT,W		;DAT -> Wreg
	MOVWF	PORTB		;Data input
	MOVLW	B'100001'
	MOVWF	PORTA		;Data write disabled
	RETURN
;ここまで

;****　LCD command out　*****
LCD_CMD
	MOVWF	PORTD			;RD0-7のデータバスへ出力
	CALL	TIM2
	BCF		PORTE,1			;RSを0にセット
	BSF		PORTE,0			;E high　ストローブ信号出力
	CALL	TIM6
	BCF		PORTE,0			;E low
	CALL	TIM2
	RETURN

LCD_CMD2
	MOVWF	PORTD			;RD0-7のデータバスへ出力
	CALL	TIM2m
	BCF		PORTE,1			;RSを0にセット
	BSF		PORTE,0			;E high　ストローブ信号出力
	NOP
	BCF		PORTE,0			;E low
	CALL	TIM2m
	RETURN


;****　LCD Data Write　****
LCD_DATA
	MOVWF	PORTD			;RD0-7のデータバスへ出力
	CALL	TIM2m
	BSF		PORTE,1			;RSを1にセット
	BSF		PORTE,0			;E high　ストローブ信号出力
	NOP
	BCF		PORTE,0			;E low
	CALL	TIM2m
	MOVF	tempb,W
	XORLW	D'16'
	BTFSC	STATUS,Z
	CALL 	sec_line		;Noteonメッセージならとぶ
	MOVF	tempb,W
	XORLW	D'32'
	BTFSC	STATUS,Z
	CALL 	first_line		;Noteonメッセージならとぶ
	MOVF	tempb,W
	ADDLW	H'01'
	MOVWF	tempb
	RETURN

sec_line
	MOVLW	B'11000000'
	CALL	LCD_CMD2
	RETURN

first_line
	MOVLW 	B'10000000'
	CALL	LCD_CMD2
	MOVLW	H'00'
	MOVWF	tempb
	RETURN

;40microsec Timer Subroutine
TIM2m
	MOVLW	D'40'			;40回
	MOVWF	CNT1
TIMLP1m	
	NOP
	NOP
	DECFSZ	CNT1,F
	GOTO	TIMLP1m
	RETURN
	
;0.2msec Timer Subroutine
TIM2
	MOVLW	0C7H			;199回
	MOVWF	CNT1
TIMLP1	
	NOP
	NOP
	DECFSZ	CNT1,F
	GOTO	TIMLP1
	RETURN

;0.6msec Timer Subroutine
TIM6
	MOVLW	3H			;4回 
	MOVWF	CNT2
TIMLP6
	CALL	TIM2
	DECFSZ	CNT2,F
	GOTO	TIMLP6
	RETURN

;1msec Timer Subroutine
TIM10
	MOVLW	5H			;4回 
	MOVWF	CNT2
TIMLP10
	CALL	TIM2
	DECFSZ	CNT2,F
	GOTO	TIMLP10
	RETURN

; 50msec Timer Subroutine
TIM100
	MOVLW	0F9H			;249回 
	MOVWF	CNT2
TIMLP2
	CALL	TIM2
	DECFSZ	CNT2,F
	GOTO	TIMLP2
	RETURN

; 1sec Timer Subroutine
TIM1SEC
	MOVLW	14H			;20回
	MOVWF	CNT3
T1LP
	CALL	TIM100
	DECFSZ	CNT3,F
	GOTO	T1LP
	RETURN 


FREQ_TBL
	movlw	H'01'
	movwf	PCLATH
	movf	note,W
	addwf	PCL,F

	GOTO	NOTE0
	GOTO	NOTE0
	GOTO	NOTE1
	GOTO	NOTE3
	GOTO	NOTE4
	GOTO	NOTE5
	GOTO	NOTE6
	GOTO	NOTE7
	GOTO	NOTE8
	GOTO	NOTE9
	GOTO	NOTE10
	GOTO	NOTE11
	GOTO	NOTE12
	GOTO	NOTE13
	GOTO	NOTE14
	GOTO	NOTE15
	GOTO	NOTE16
	GOTO	NOTE17
	GOTO	NOTE18
	GOTO	NOTE19
	GOTO	NOTE20
	GOTO	NOTE21
	GOTO	NOTE22
	GOTO	NOTE23
	GOTO	NOTE24
	GOTO	NOTE25
	GOTO	NOTE26
	GOTO	NOTE27
	GOTO	NOTE28
	GOTO	NOTE29
	GOTO	NOTE30
	GOTO	NOTE31
	GOTO	NOTE32
	GOTO	NOTE33
	GOTO	NOTE34
	GOTO	NOTE35
	GOTO	NOTE36
	GOTO	NOTE37
	GOTO	NOTE38
	GOTO	NOTE39
	GOTO	NOTE40
	GOTO	NOTE41
	GOTO	NOTE42
	GOTO	NOTE43
	GOTO	NOTE44
	GOTO	NOTE45
	GOTO	NOTE46
	GOTO	NOTE47
	GOTO	NOTE48
	GOTO	NOTE49
	GOTO	NOTE50
	GOTO	NOTE51
	GOTO	NOTE52
	GOTO	NOTE53
	GOTO	NOTE54
	GOTO	NOTE55
	GOTO	NOTE56
	GOTO	NOTE57
	GOTO	NOTE58
	GOTO	NOTE59
	GOTO	NOTE60
	GOTO	NOTE61
	GOTO	NOTE62
	GOTO	NOTE63
	GOTO	NOTE64
	GOTO	NOTE65
	GOTO	NOTE66
	GOTO	NOTE67
	GOTO	NOTE68
	GOTO	NOTE69
	GOTO	NOTE70
	GOTO	NOTE71
	GOTO	NOTE72
	GOTO	NOTE73
	GOTO	NOTE74
	GOTO	NOTE75
	GOTO	NOTE76
	GOTO	NOTE77
	GOTO	NOTE78
	GOTO	NOTE79
	GOTO	NOTE80
	GOTO	NOTE81
	GOTO	NOTE82
	GOTO	NOTE83
	GOTO	NOTE84
	GOTO	NOTE85
	GOTO	NOTE86
	GOTO	NOTE87
	GOTO	NOTE88
	GOTO	NOTE89
	GOTO	NOTE90
	GOTO	NOTE91
	GOTO	NOTE92
	GOTO	NOTE93
	GOTO	NOTE94
	GOTO	NOTE95
	GOTO	NOTE96
	GOTO	NOTE97
	GOTO	NOTE98
	GOTO	NOTE99
	GOTO	NOTE100
	GOTO	NOTE101
	GOTO	NOTE102
	GOTO	NOTE103
	GOTO	NOTE104
	GOTO	NOTE105
	GOTO	NOTE106
	GOTO	NOTE107
	GOTO	NOTE108
	GOTO	NOTE109
	GOTO	NOTE110
	GOTO	NOTE111
	GOTO	NOTE112
	GOTO	NOTE113
	GOTO	NOTE114
	GOTO	NOTE115
	GOTO	NOTE116
	GOTO	NOTE117
	GOTO	NOTE118
	GOTO	NOTE119
	GOTO	NOTE120
	GOTO	NOTE121
	GOTO	NOTE122
	GOTO	NOTE123
	GOTO	NOTE124
	GOTO	NOTE125
	GOTO	NOTE126
	GOTO	NOTE127
NOTE0
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE1
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE2
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE3
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE4
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE5
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE6
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE7
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN


NOTE8
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE9
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE10
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE11
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE12
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE13
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE14
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE15
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE16
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE17
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE18
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN


NOTE19
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE20
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE21
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE22
	MOVLW	H'FF'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE23
	MOVLW	H'D1'
	MOVWF	fine
	MOVLW	H'0F'
	MOVWF	rough
	RETURN

NOTE24
	MOVLW	H'EE'
	MOVWF	fine
	MOVLW	H'0E'
	MOVWF	rough
	RETURN

NOTE25
	MOVLW	H'17'
	MOVWF	fine
	MOVLW	H'0E'
	MOVWF	rough
	RETURN

NOTE26
	MOVLW	H'4D'
	MOVWF	fine
	MOVLW	H'0D'
	MOVWF	rough
	RETURN

NOTE27
	MOVLW	H'8E'
	MOVWF	fine
	MOVLW	H'0C'
	MOVWF	rough
	RETURN

NOTE28
	MOVLW	H'D9'
	MOVWF	fine
	MOVLW	H'0B'
	MOVWF	rough
	RETURN

NOTE29
	MOVLW	H'2F'
	MOVWF	fine
	MOVLW	H'0B'
	MOVWF	rough
	RETURN

NOTE30
	MOVLW	H'8E'
	MOVWF	fine
	MOVLW	H'0A'
	MOVWF	rough
	RETURN

NOTE31
	MOVLW	H'F7'
	MOVWF	fine
	MOVLW	H'09'
	MOVWF	rough
	RETURN

NOTE32
	MOVLW	H'67'
	MOVWF	fine
	MOVLW	H'09'
	MOVWF	rough
	RETURN

NOTE33
	MOVLW	H'E0'
	MOVWF	fine
	MOVLW	H'08'
	MOVWF	rough
	RETURN

NOTE34
	MOVLW	H'61'
	MOVWF	fine
	MOVLW	H'08'
	MOVWF	rough
	RETURN

NOTE35
	MOVLW	H'E8'
	MOVWF	fine
	MOVLW	H'07'
	MOVWF	rough
	RETURN

NOTE36
	MOVLW	H'77'
	MOVWF	fine
	MOVLW	H'07'
	MOVWF	rough
	RETURN

NOTE37
	MOVLW	H'0B'
	MOVWF	fine
	MOVLW	H'07'
	MOVWF	rough
	RETURN

NOTE38
	MOVLW	H'A6'
	MOVWF	fine
	MOVLW	H'06'
	MOVWF	rough
	RETURN

NOTE39
	MOVLW	H'47'
	MOVWF	fine
	MOVLW	H'06'
	MOVWF	rough
	RETURN

NOTE40
	MOVLW	H'EC'
	MOVWF	fine
	MOVLW	H'05'
	MOVWF	rough
	RETURN

NOTE41
	MOVLW	H'97'
	MOVWF	fine
	MOVLW	H'05'
	MOVWF	rough
	RETURN

NOTE42
	MOVLW	H'47'
	MOVWF	fine
	MOVLW	H'05'
	MOVWF	rough
	RETURN

NOTE43
	MOVLW	H'FB'
	MOVWF	fine
	MOVLW	H'04'
	MOVWF	rough
	RETURN

NOTE44
	MOVLW	H'B3'
	MOVWF	fine
	MOVLW	H'04'
	MOVWF	rough
	RETURN

NOTE45
	MOVLW	H'70'
	MOVWF	fine
	MOVLW	H'04'
	MOVWF	rough
	RETURN

NOTE46
	MOVLW	H'30'
	MOVWF	fine
	MOVLW	H'04'
	MOVWF	rough
	RETURN

NOTE47
	MOVLW	H'F4'
	MOVWF	fine
	MOVLW	H'03'
	MOVWF	rough
	RETURN

NOTE48
	MOVLW	H'BB'
	MOVWF	fine
	MOVLW	H'03'
	MOVWF	rough
	RETURN

NOTE49
	MOVLW	H'85'
	MOVWF	fine
	MOVLW	H'03'
	MOVWF	rough
	RETURN

NOTE50
	MOVLW	H'53'
	MOVWF	fine
	MOVLW	H'03'
	MOVWF	rough
	RETURN

NOTE51
	MOVLW	H'23'
	MOVWF	fine
	MOVLW	H'03'
	MOVWF	rough
	RETURN

NOTE52
	MOVLW	H'F6'
	MOVWF	fine
	MOVLW	H'02'
	MOVWF	rough
	RETURN

NOTE53
	MOVLW	H'CB'
	MOVWF	fine
	MOVLW	H'02'
	MOVWF	rough
	RETURN

NOTE54
	MOVLW	H'A3'
	MOVWF	fine
	MOVLW	H'02'
	MOVWF	rough
	RETURN

NOTE55
	MOVLW	H'7D'
	MOVWF	fine
	MOVLW	H'02'
	MOVWF	rough
	RETURN

NOTE56
	MOVLW	H'59'
	MOVWF	fine
	MOVLW	H'02'
	MOVWF	rough
	RETURN

NOTE57
	MOVLW	H'38'
	MOVWF	fine
	MOVLW	H'02'
	MOVWF	rough
	RETURN

NOTE58
	MOVLW	H'18'
	MOVWF	fine
	MOVLW	H'02'
	MOVWF	rough
	RETURN

NOTE59
	MOVLW	H'FA'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE60
	MOVLW	H'DD'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE61
	MOVLW	H'C2'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE62
	MOVLW	H'A9'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE63
	MOVLW	H'91'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE64
	MOVLW	H'7B'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE65
	MOVLW	H'65'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE66
	MOVLW	H'51'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE67
	MOVLW	H'3E'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE68
	MOVLW	H'2C'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE69
	MOVLW	H'1C'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE70
	MOVLW	H'0C'
	MOVWF	fine
	MOVLW	H'01'
	MOVWF	rough
	RETURN

NOTE71
	MOVLW	H'FD'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE72
	MOVLW	H'EE'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE73
	MOVLW	H'E1'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE74
	MOVLW	H'D4'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE75
	MOVLW	H'C8'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE76
	MOVLW	H'BD'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE77
	MOVLW	H'B2'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE78
	MOVLW	H'A8'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE79
	MOVLW	H'9F'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE80
	MOVLW	H'96'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE81
	MOVLW	H'8E'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE82
	MOVLW	H'86'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE83
	MOVLW	H'7E'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE84
	MOVLW	H'77'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE85
	MOVLW	H'70'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE86
	MOVLW	H'6A'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE87
	MOVLW	H'64'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE88
	MOVLW	H'5E'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE89
	MOVLW	H'59'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE90
	MOVLW	H'54'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE91
	MOVLW	H'4F'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE92
	MOVLW	H'4B'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE93
	MOVLW	H'47'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE94
	MOVLW	H'43'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE95
	MOVLW	H'3F'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE96
	MOVLW	H'3B'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE97
	MOVLW	H'38'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE98
	MOVLW	H'35'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE99
	MOVLW	H'32'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE100
	MOVLW	H'2F'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE101
	MOVLW	H'2C'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE102
	MOVLW	H'2A'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE103
	MOVLW	H'27'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE104
	MOVLW	H'25'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE105
	MOVLW	H'23'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE106
	MOVLW	H'21'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE107
	MOVLW	H'1F'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE108
	MOVLW	H'1D'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE109
	MOVLW	H'1C'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE110
	MOVLW	H'1A'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE111
	MOVLW	H'19'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE112
	MOVLW	H'17'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE113
	MOVLW	H'16'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE114
	MOVLW	H'15'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE115
	MOVLW	H'13'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE116
	MOVLW	H'12'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE117
	MOVLW	H'11'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE118
	MOVLW	H'10'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE119
	MOVLW	H'0F'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE120
	MOVLW	H'0E'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE121
	MOVLW	H'0E'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE122
	MOVLW	H'0D'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE123
	MOVLW	H'0C'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE124
	MOVLW	H'0B'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE125
	MOVLW	H'0B'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE126
	MOVLW	H'0A'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

NOTE127
	MOVLW	H'09'
	MOVWF	fine
	MOVLW	H'00'
	MOVWF	rough
	RETURN

GETDATA
	MOVF	RCREG,W
	MOVWF	r_data
	BSF		RCSTA,CREN
	RETURN

note_on
	MOVLW	H'90'
	MOVWF	midmes
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
note_on_run
	MOVF	r_data,W
	MOVWF	note
	CALL	FREQ_TBL	;周波数テーブル参照
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
	XORLW	H'00'
	BTFSC	STATUS,Z
	GOTO	note_off_r
	MOVF	note,W
	CALL	disp_w

	MOVF	psga,W
	XORLW	H'00'
	BTFSC	STATUS,Z
	GOTO	ch_a

	MOVF	psgb,W
	XORLW	H'00'
	BTFSC	STATUS,Z
	GOTO	ch_b

	MOVF	psgc,W
	XORLW	H'00'
	BTFSC	STATUS,Z
	GOTO	ch_c
	GOTO	MAIN

ch_a
	MOVLW	B'00001000'	;Address		(Ach Volume Setting)
	MOVWF	ADR
	MOVLW	B'00001111'	;Data
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	H'01'
	MOVWF	ADR
	MOVF	rough,W
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	H'00'
	MOVWF	ADR
	MOVF	fine,W
	MOVWF	DAT
	CALL	TO_YMZ

	MOVF	note,W
	MOVWF	psga
	GOTO 	MAIN

ch_b
	MOVLW	B'00001001'	;Address		(Bch Volume Setting)
	MOVWF	ADR
	MOVLW	B'00001111'	;Data
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	H'03'
	MOVWF	ADR
	MOVF	rough,W
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	H'02'
	MOVWF	ADR
	MOVF	fine,W
	MOVWF	DAT
	CALL	TO_YMZ

	MOVF	note,W
	MOVWF	psgb
	GOTO 	MAIN

ch_c
	MOVLW	B'00001010'	;Address		(Cch Volume Setting)
	MOVWF	ADR
	MOVLW	B'00001111'	;Data
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	H'05'
	MOVWF	ADR
	MOVF	rough,W
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	H'04'
	MOVWF	ADR
	MOVF	fine,W
	MOVWF	DAT
	CALL	TO_YMZ

	MOVF	note,W
	MOVWF	psgc
	GOTO 	MAIN

note_off
	MOVLW	H'80'
	MOVWF	midmes
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
note_off_run
	MOVF	r_data,W
	MOVWF	note
note_off_r
	MOVF	note,0
	XORWF	psga,0
	BTFSS	STATUS,Z
	GOTO 	nf_b
	MOVLW	B'00001000'	;Address		(Ach Volume Setting)
	MOVWF	ADR
	MOVLW	B'00000000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ
	MOVLW	H'00'
	MOVWF	psga
	GOTO 	MAIN
nf_b
	MOVF	note,0
	XORWF	psgb,0
	BTFSS	STATUS,Z
	GOTO 	nf_c
	MOVLW	B'00001001'	;Address		(Bch Volume Setting)
	MOVWF	ADR
	MOVLW	B'00000000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ
	MOVLW	H'00'
	MOVWF	psgb
	GOTO 	MAIN
nf_c
	MOVF	note,0
	XORWF	psgc,0
	BTFSS	STATUS,Z
	GOTO 	MAIN
	MOVLW	B'00001010'	;Address		(Cch Volume Setting)
	MOVWF	ADR
	MOVLW	B'00000000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ
	MOVLW	H'00'
	MOVWF	psgc
	GOTO 	MAIN



poly_key_press
	MOVLW	H'A0'
	MOVWF	midmes
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
poly_key_press_run
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
	GOTO	MAIN

ch_press
	MOVLW	H'D0'
	MOVWF	midmes
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
ch_press_run
	GOTO	MAIN

pitch_bend
	MOVLW	H'E0'
	MOVWF	midmes
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
pitch_bend_run
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
	GOTO	MAIN

ctrl_chg
	MOVLW	H'B0'
	MOVWF	midmes
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
ctrl_chg_run
	MOVF	r_data,W
	XORWF	H'78',W
	BTFSC	STATUS,Z
	CALL	all_sound_off

	XORWF	H'79',W
	BTFSC	STATUS,Z
	CALL	all_sound_off

	XORWF	H'7B',W
	BTFSC	STATUS,Z
	CALL	all_sound_off

	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
	GOTO	MAIN

all_sound_off
	MOVLW	B'00001000'	;Address		(Ach Volume Setting)
	MOVWF	ADR
	MOVLW	B'00000000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	B'00001001'	;Address		(Bch Volume Setting)
	MOVWF	ADR
	MOVLW	B'00000000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	B'00001010'	;Address		(Cch Volume Setting)
	MOVWF	ADR
	MOVLW	B'00000000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ
	MOVLW	H'00'
	MOVWF	psga
	MOVWF	psgb
	MOVWF	psgc
	RETURN

all_sound_off2
	MOVLW	B'00001000'	;Address		(Ach Volume Setting)
	MOVWF	ADR
	MOVLW	B'00000000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	B'00001001'	;Address		(Bch Volume Setting)
	MOVWF	ADR
	MOVLW	B'00000000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ

	MOVLW	B'00001010'	;Address		(Cch Volume Setting)
	MOVWF	ADR
	MOVLW	B'00000000'	;Data
	MOVWF	DAT
	CALL	TO_YMZ
	MOVLW	H'00'
	MOVWF	psga
	MOVWF	psgb
	MOVWF	psgc
	GOTO	MAIN

pgm_chg
	MOVLW	H'C0'
	MOVWF	midmes
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
pgm_chg_run
	GOTO	MAIN

ex_mes
	MOVLW	H'F0'
	MOVWF	midmes
	BTFSS	PIR1,RCIF	;次の信号待ち
	GOTO	$-1			;データが来ていなければ戻る
	CALL	GETDATA		;データ取得
	MOVF	r_data,W
	XORLW	H'F7'
	BTFSC	STATUS,Z
	GOTO	MAIN
	GOTO	ex_mes

	END
