Subversion Repositories svn.mios

Rev

Rev 1075 | Rev 1109 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1075 Rev 1102
Line 1... Line 1...
1
; $Id: sid_sysex.inc 1075 2012-09-08 20:58:18Z tk $
1
; $Id: sid_sysex.inc 1102 2012-12-30 20:39:10Z tk $
2
;
2
;
3
; MIDIbox SID SysEx Parser
3
; MIDIbox SID SysEx Parser
4
;
4
;
5
; ==========================================================================
5
; ==========================================================================
6
;
6
;
Line 39... Line 39...
39
SID_DISACK_BS_NOT_AVAILABLE	EQU	0x0a
39
SID_DISACK_BS_NOT_AVAILABLE	EQU	0x0a
40
SID_DISACK_PAR_NOT_AVAILABLE	EQU	0x0b
40
SID_DISACK_PAR_NOT_AVAILABLE	EQU	0x0b
41
SID_DISACK_INVALID_COMMAND	EQU	0x0c
41
SID_DISACK_INVALID_COMMAND	EQU	0x0c
42
SID_DISACK_NO_RAM_ACCESS	EQU	0x10
42
SID_DISACK_NO_RAM_ACCESS	EQU	0x10
43
SID_DISACK_BS_TOO_SMALL		EQU	0x11
43
SID_DISACK_BS_TOO_SMALL		EQU	0x11
-
 
44
SID_DISACK_WRONG_TYPE		EQU	0x12
-
 
45
SID_DISACK_SLAVE_NOT_AVAILABLE	EQU	0x13
44
46
45
;; --------------------------------------------------------------------------
47
;; --------------------------------------------------------------------------
46
;;  This function is called by MIOS when a MIDI byte has been received
48
;;  This function is called by MIOS when a MIDI byte has been received
47
;;  Input:
49
;;  Input:
48
;;     o received MIDI byte in WREG and MIOS_PARAMETER1
50
;;     o received MIDI byte in WREG and MIOS_PARAMETER1
Line 426... Line 428...
426
SID_SYSEX_PATCH_Write_I_Mst_Next
428
SID_SYSEX_PATCH_Write_I_Mst_Next
427
	incf	CS_MENU_SID, F			; select next SID, loop until all 4 processed
429
	incf	CS_MENU_SID, F			; select next SID, loop until all 4 processed
428
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, SID_SYSEX_PATCH_Write_I_MstLoop
430
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, SID_SYSEX_PATCH_Write_I_MstLoop
429

431

430
432
431
SID_SYSEX_PATCH_Write_I_End
433
SID_SYSEX_PATCH_Write_I_End	; re-used from SID_SYSEX_Cmd_18_SavePatch_Ok
432
	;; print message if CS enabled
434
	;; print message if CS enabled
433
	TABLE_ADDR SID_SYSEX_PATCH_Write_I_STR
435
	TABLE_ADDR SID_SYSEX_PATCH_Write_I_STR
434
	call	MIOS_LCD_PrintMessage
436
	call	MIOS_LCD_PrintMessage
435
	
437
	
436
	movlw	0x00 + 6
438
	movlw	0x00 + 6
Line 453... Line 455...
453
	;; send acknowledge
455
	;; send acknowledge
454
	rgoto	SID_SYSEX_PATCH_Write_Ack
456
	rgoto	SID_SYSEX_PATCH_Write_Ack
455

457

456
458
457
SID_SYSEX_PATCH_Write_I_STR
459
SID_SYSEX_PATCH_Write_I_STR
458
	STRING	20, 0x00, "Patch A  1 uploaded "
460
	STRING	20, 0x00, "Patch A  1 stored   "
459
SID_SYSEX_PATCH_Write_E_STR
461
SID_SYSEX_PATCH_Write_E_STR
460
	STRING	20, 0x00, "Ensemble xxxx upld. "
462
	STRING	20, 0x00, "Ensemble xxxx stored"
461
463
462
SID_SYSEX_PATCH_Write_E
464
SID_SYSEX_PATCH_Write_E
463
	;; write into EEPROM or RAM?
465
	;; write into EEPROM or RAM?
464
	BRA_IFSET SID_SYSEX_TYPE, 3, BANKED, SID_SYSEX_PATCH_Write_E_RAM
466
	BRA_IFSET SID_SYSEX_TYPE, 3, BANKED, SID_SYSEX_PATCH_Write_E_RAM
465
SID_SYSEX_PATCH_Write_E_EE
467
SID_SYSEX_PATCH_Write_E_EE
Line 488... Line 490...
488
	rcall	SID_SYSEX_WritePar
490
	rcall	SID_SYSEX_WritePar
489
	incf	SID_SYSEX_ADDRESS_L, F, BANKED
491
	incf	SID_SYSEX_ADDRESS_L, F, BANKED
490
	bnz	SID_SYSEX_PATCH_Write_E_RAM_Loop
492
	bnz	SID_SYSEX_PATCH_Write_E_RAM_Loop
491
493
492
494
493
SID_SYSEX_PATCH_Write_E_EE_Cont
495
SID_SYSEX_PATCH_Write_E_EE_Cont	; re-used from SID_SYSEX_Cmd_18_SaveEns
494
	;; if no direct RAM upload: re-init ensemble here
496
	;; if no direct RAM upload: re-init ensemble here
495
	SET_BSR	SID_BASE
497
	SET_BSR	SID_BASE
496
	CALL_IFCLR SID_SYSEX_TYPE, 3, BANKED, SID_ENS_Init
498
	CALL_IFCLR SID_SYSEX_TYPE, 3, BANKED, SID_ENS_Init
497
499
498
	;; print message if CS enabled
500
	;; print message if CS enabled
Line 726... Line 728...
726
SID_SYSEX_Cmd_End
728
SID_SYSEX_Cmd_End
727

729

728
	;; branch depending on command type
730
	;; branch depending on command type
729
	movf	SID_SYSEX_TYPE, W, BANKED
731
	movf	SID_SYSEX_TYPE, W, BANKED
730
	bz	SID_SYSEX_Cmd_00
732
	bz	SID_SYSEX_Cmd_00
731
	addlw	-8
733
	addlw	0x00-0x08
732
	bz	SID_SYSEX_Cmd_08
734
	bz	SID_SYSEX_Cmd_08
733
	addlw	-1
735
	addlw	0x08-0x09
734
	bz	SID_SYSEX_Cmd_09
736
	bz	SID_SYSEX_Cmd_09
-
 
737
	addlw	0x09-0x10
-
 
738
	bz	SID_SYSEX_Cmd_10
-
 
739
	addlw	0x10-0x18
-
 
740
	bz	SID_SYSEX_Cmd_18
735
SID_SYSEX_Cmd_Inv
741
SID_SYSEX_Cmd_Inv
736
	;; invalid command
742
	;; invalid command
737
	rgoto	SID_SYSEX_DisAck_InvCmd
743
	rgoto	SID_SYSEX_DisAck_InvCmd
738

744

739
SID_SYSEX_Cmd_00
745
SID_SYSEX_Cmd_00
Line 798... Line 804...
798
	incf	CS_MENU_SID, F
804
	incf	CS_MENU_SID, F
799
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, SID_SYSEX_Cmd_09_Loop
805
	BRA_IFCLR CS_MENU_SID, 2, ACCESS, SID_SYSEX_Cmd_09_Loop
800
806
801
	movff	SID_SYSEX_TYPE, CS_MENU_SELECTED_INS	; restore selected instrument
807
	movff	SID_SYSEX_TYPE, CS_MENU_SELECTED_INS	; restore selected instrument
802
	movff	SID_SYSEX_IN, CS_MENU_SELECTED_SID_LR	; restore left/right selection
808
	movff	SID_SYSEX_IN, CS_MENU_SELECTED_SID_LR	; restore left/right selection
803
	;; 	rgoto	SID_SYSEX_Cmd_Ack
809
 	rgoto	SID_SYSEX_Cmd_Ack
-
 
810
-
 
811
-
 
812
SID_SYSEX_Cmd_10
-
 
813
	;; action invalid if command byte hasn't been received
-
 
814
	BRA_IFCLR SID_SYSEX_STATE2, SID_SYSEX_STATE2_CMDBYTE_RECEIVED, BANKED, SID_SYSEX_DisAck_NotComplete
-
 
815

-
 
816
	;; enable/disable lemur mode
-
 
817
	bcf	CS_STAT3, CS_STAT3_LEMUR_MODE
-
 
818
	movf	SID_SYSEX_DATA, W, BANKED
-
 
819
	skpz
-
 
820
	bsf	CS_STAT3, CS_STAT3_LEMUR_MODE
-
 
821
	rgoto	SID_SYSEX_Cmd_Ack
-
 
822
-
 
823
-
 
824
SID_SYSEX_Cmd_18
-
 
825
	;; action invalid if command byte hasn't been received
-
 
826
	BRA_IFCLR SID_SYSEX_STATE2, SID_SYSEX_STATE2_CMDBYTE_RECEIVED, BANKED, SID_SYSEX_DisAck_NotComplete
-
 
827

-
 
828
	movff	SID_SYSEX_DATA, SID_SYSEX_TYPE
-
 
829
-
 
830
	;; branch depending on type
-
 
831
	movf	SID_SYSEX_TYPE, W, BANKED
-
 
832
	andlw	0xfc
-
 
833
	xorlw	0x08
-
 
834
	bz	SID_SYSEX_Cmd_18_SavePatch
-
 
835
-
 
836
	movf	SID_SYSEX_TYPE, W, BANKED
-
 
837
	xorlw	0x70
-
 
838
	bz	SID_SYSEX_Cmd_18_SaveEns
-
 
839
	;; invalid command
-
 
840
	rgoto	SID_SYSEX_DisAck_InvCmd
-
 
841

-
 
842
-
 
843
SID_SYSEX_Cmd_18_SavePatch
-
 
844
	movf	SID_SYSEX_TYPE, W, BANKED
-
 
845
	andlw	0x07
-
 
846
	xorwf	CS_MENU_EDIT_BUFFER_SID, W
-
 
847
	bz	SID_SYSEX_Cmd_18_SavePatch_NoUpd
-
 
848
SID_SYSEX_Cmd_18_SavePatch_Updat
-
 
849
	;; select SID
-
 
850
	movf	SID_SYSEX_TYPE, W, BANKED
-
 
851
	call	MIOS_HLP_GetBitORMask
-
 
852
	andlw	0x0f
-
 
853
	iorlw	0xf0
-
 
854
	movwf	CS_MENU_SELECTED_SID_FLAGS
-
 
855
-
 
856
	;; update edit buffer
-
 
857
	movf	SID_SYSEX_TYPE, W, BANKED
-
 
858
	andlw	0x03
-
 
859
	movwf	CS_MENU_EDIT_BUFFER_SID, W
-
 
860
	call	CS_MENU_MS_UpdateEditBufferNow
-
 
861
SID_SYSEX_Cmd_18_SavePatch_NoUpd
-
 
862
-
 
863
	;; check if node is available
-
 
864
	movff	MBNET_NODE_AVAIL, WREG
-
 
865
	iorlw	0x01		; master always available
-
 
866
	xorwf	CS_MENU_SELECTED_SID_FLAGS, W
-
 
867
	andlw	0x0f		; 4 SIDs maximum
-
 
868
	bz	SID_SYSEX_Cmd_18_SavePatch_Ok
-
 
869

-
 
870
	;; send error acknowledge
-
 
871
	rgoto	SID_SYSEX_DisAck_Slave_NotAvail
-
 
872

-
 
873
-
 
874
SID_SYSEX_Cmd_18_SavePatch_Ok
-
 
875
	;; copy current patch/bank number to SAVE_PATCH and SAVE_BANK
-
 
876
	call	CS_MENU_MS_GetSIDNumber
-
 
877
	call	CS_MENU_MS_GetSIDPatch; sets FSR1 to patch register
-
 
878
	movf	INDF1, W
-
 
879
	andlw	0x7f
-
 
880
	movwf	CS_MENU_SAVE_PATCH
-
 
881
	call	CS_MENU_MS_GetSIDBank; sets FSR1 to bank register
-
 
882
	movf	INDF1, W
-
 
883
	andlw	0x07
-
 
884
	movwf	CS_MENU_SAVE_BANK
-
 
885
-
 
886
	;; finally store patch
-
 
887
	call	CS_MENU_SavePatch
-
 
888

-
 
889
	;; and generate display message
-
 
890
	rgoto	SID_SYSEX_PATCH_Write_I_End
-
 
891

-
 
892
SID_SYSEX_Cmd_18_SaveEns
-
 
893
	;; store ensemble
-
 
894
	movff	SID_ENSEMBLE, CS_MENU_SAVE_ENS
-
 
895
	call	CS_MENU_SaveEns
-
 
896
-
 
897
	;; and generate display message
-
 
898
	rgoto	SID_SYSEX_PATCH_Write_E_EE_Cont
-
 
899

804
900
805
SID_SYSEX_Cmd_Ack
901
SID_SYSEX_Cmd_Ack
806
	;; send Acknowledge
902
	;; send Acknowledge
807
	rcall	SID_SYSEX_Send_Acknowledge
903
	rcall	SID_SYSEX_Send_Acknowledge
808

904

Line 864... Line 960...
864
	rgoto	SID_SYSEX_DisAck_Cont
960
	rgoto	SID_SYSEX_DisAck_Cont
865
961
866
SID_SYSEX_DisAck_BSTooSmall
962
SID_SYSEX_DisAck_BSTooSmall
867
	;; send disacknowledge "BankStick too small"
963
	;; send disacknowledge "BankStick too small"
868
	movlw	SID_DISACK_BS_TOO_SMALL
964
	movlw	SID_DISACK_BS_TOO_SMALL
-
 
965
	rgoto	SID_SYSEX_DisAck_Cont
-
 
966
-
 
967
SID_SYSEX_DisAck_Slave_NotAvail
-
 
968
	;; send disacknowledge "Slave not available"
-
 
969
	movlw	SID_DISACK_SLAVE_NOT_AVAILABLE
869
	;; 	rgoto	SID_SYSEX_DisAck_Cont
970
	;; 	rgoto	SID_SYSEX_DisAck_Cont
870
971
871
SID_SYSEX_DisAck_Cont
972
SID_SYSEX_DisAck_Cont
872
	movwf	TMP2		; error code in WREG
973
	movwf	TMP2		; error code in WREG
873
	
974
	
Line 1598... Line 1699...
1598
	SET_BSR	SID_BASE
1699
	SET_BSR	SID_BASE
1599
	clrf	SID_SYSEX_CHECKSUM, BANKED
1700
	clrf	SID_SYSEX_CHECKSUM, BANKED
1600
1701
1601
	;; feed WDT
1702
	;; feed WDT
1602
	clrwdt
1703
	clrwdt
-
 
1704

-
 
1705
	;; lemur mode?
-
 
1706
	BRA_IFCLR CS_STAT3, CS_STAT3_LEMUR_MODE, ACCESS, SID_SYSEX_SendDump_NoLemur
-
 
1707
SID_SYSEX_SendDump_Lemur
-
 
1708
	movlw	0xf7		; end SysEx
-
 
1709
	rcall	SID_SYSEX_TxBufferPut
-
 
1710

-
 
1711
	movlw	0xa0		; for Lemur: start sending common MIDI events
-
 
1712
	rcall	SID_SYSEX_TxBufferPut
-
 
1713
	SET_BSR	SID_BASE
-
 
1714
SID_SYSEX_SendDump_NoLemur
1603

1715
1604
	;; branch depending on SysEx type
1716
	;; branch depending on SysEx type
1605
	movf	SID_SYSEX_TYPE, W, BANKED
1717
	movf	SID_SYSEX_TYPE, W, BANKED
1606
	andlw	0xf7
1718
	andlw	0xf7
1607
	xorlw	0x70
1719
	xorlw	0x70
Line 1777... Line 1889...
1777
1889
1778
	;; reload edit buffer with data of currently selected SID
1890
	;; reload edit buffer with data of currently selected SID
1779
	call	CS_MENU_MS_UpdateEnsBuffer
1891
	call	CS_MENU_MS_UpdateEnsBuffer
1780

1892

1781
SID_SYSEX_SendDump_I_Cont
1893
SID_SYSEX_SendDump_I_Cont
-
 
1894
	;; lemur mode?
-
 
1895
	BRA_IFCLR CS_STAT3, CS_STAT3_LEMUR_MODE, ACCESS, SID_SYSEX_SendDump_I_Cont_NoLemur
-
 
1896
SID_SYSEX_SendDump_I_Cont_Lemur
-
 
1897
	;; send checksum
-
 
1898
	movlw	0xa1		; Poly Pressure, Channel 2 - all data sent + checksum
-
 
1899
	rcall	SID_SYSEX_TxBufferPut
-
 
1900
-
 
1901
	movff	SID_SYSEX_CHECKSUM, WREG
-
 
1902
	sublw	0x80
-
 
1903
	andlw	0x7f
-
 
1904
	rcall	SID_SYSEX_TxBufferPut
-
 
1905
-
 
1906
	movlw	0x00		; dummy
-
 
1907
	rgoto	SID_SYSEX_TxBufferPut
-
 
1908

-
 
1909
SID_SYSEX_SendDump_I_Cont_NoLemur
1782
	;; send checksum
1910
	;; send checksum
1783
	movff	SID_SYSEX_CHECKSUM, WREG
1911
	movff	SID_SYSEX_CHECKSUM, WREG
1784
	sublw	0x80
1912
	sublw	0x80
1785
	andlw	0x7f
1913
	andlw	0x7f
1786
	rcall	SID_SYSEX_TxBufferPut
1914
	rcall	SID_SYSEX_TxBufferPut