⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 midiplay.asm

📁 midi file with midi play.it can run in the computer
💻 ASM
字号:
.public F_SACM_MS02_Init_
.public T_SACM_MS02_SongTable
.public T_SACM_MS02_InstrumentSet

//----------------------------------------------------------------------------------------
//File Name:		MidiPlay.asm
//Applied Body:		SPT6604A
//Description:		This is a Demo code of MIDI play for SPT6604A
//Compile:		Sunplus u'nSP IDE
//Current Version:	V1.0
//Written Date:		2002/11/27
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
// Variable define
.OSRAM
//----------------------------------------------------------------------------------------
ShareArea1:		.dw			64  dup(0)
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
.ORAM
ShareArea2:		.dw			126  dup(0)

EndOfMidiSram:		.dw			0
//----------------------------------------------------------------------------------------


//----------------------------------------------------------------------------------------
.RAM
PhoneMode:		.dw			0
.const			Flag_PlayMidi		= 0x8000
SongIndex:		.dw			0
Volume:		.dw			0




.const			StackBottom		= 0x05FF


//============================== Midi Player External Function ===============================================//
.external		F_ISR_Service_SACM_MS02
.external		F_SACM_MS02_Volume 
.external		F_SACM_MS02_Initial
.external		F_SACM_MS02_Play
.external 		F_SACM_MS02_Status
.external 		F_SACM_MS02_ServiceLoop
.external		F_SACM_MS02_Stop

//----------------------------------------------------------------------------------------
.include		Resource.inc
.include		SPT6605.inc
//.include		..\Function\Display.ASM
.include		Keyscan.ASM
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
.const			C_SongTotal		= 8
.const			C_TopVolume		= 0x0003
.const			C_KeyVolumeUp		= C_Delete
.const			C_KeyVolumeDown		= C_Dummy
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
.Code
//----------------------------------------------------------------------------------------

.public _main;
.public _FIQ;
.public _IRQ0;
.public _IRQ1;
.public _IRQ2;
.public _IRQ3;
.public _IRQ4;
.public _IRQ5;
.public _IRQ6;
.public _IRQ7;
.public _BREAK;


_main:
	int	off
	r1 =	0x55aa
	[P_Watchdog_Clr] = r1			//Reset watchdog

	sp =	StackBottom			//Initialize stack

	r1 =	B_128Hz+B_512Hz+B_Enable32768
	[P_TimeBaseSet] = r1			//Initialize timebase for key scan

	r1 =	0x0000
	[P_IOA_Dir] = r1			//Set IOA as input port

	r1 =	0x001f
	[P_IOB_Dir] = r1			//Set IOB0~IOB4 as output ports
						//    IOB5~IOB7 as input ports
	r1 =	0x1f00
	[P_IOA_PullR] = r1			//Enable the pull-up resistor for IOA0~IOA4

	r1 =	B_512HzInt
	[P_Int] = r1

	int	fiq,irq

	call	F_StartKeyScan			//Start key scan

	r1 =	0x0002
	[Volume] = r1
	r1 =	0x0001
	[SongIndex] = r1
     	[PhoneMode] = r1
     	
     	R1 = 	C_HandFree;			// Play the first song after CPU Power-on
     	CALL	F_ModeSelectKeyDeal;
//----------------------------------------------------------------------------------------	 
?L_MainLoop:
	r1 =	0x55aa
	[P_Watchdog_Clr] = r1
	call	F_KeyScan
	call	F_KeyDeal
	call	F_PlayMidi
	jmp	?L_MainLoop
//----------------------------------------------------------------------------------------
F_PlayMidi:
	r1 =	[PhoneMode]
	test	r1,Flag_PlayMidi
	jz	?L_PlayMidiOver

	call	F_SACM_MS02_ServiceLoop
	call	F_SACM_MS02_Status
	test	r1, 0x0001			//Is song over?
	jnz	?L_PlayMidiOver			//No, function return

	call    F_StopPlay			//Yes, stop play

	r1 =	C_ModeSelectMode		//Set select mode for key deal
	r1&=	C_ModeRelatedBits
	r2=	[PhoneMode]
	r2&=	0xffff-C_ModeRelatedBits
	r2|=	r1
	[PhoneMode] = r2

?L_PlayMidiOver:
	retf


//----------------------------------------------------------------------------------------
F_KeyDeal:
	R2 =	[KeyQueueBufPtr]
	test	r2,0x0f00		//Check if have key in key buffer
	jnz	?L_KeyValueNotNull	
	goto	?L_KeyDealOver		//No, key deal over
?L_KeyValueNotNull:
	r2&=	0x000f			//Yes, get key pointer
//----------------------------------------------------------------------------------------
	r3 =	r2 lsr 1		//Get key Value from key buffer
	r3+=	KeyQueueBuf
	r1 =	[r3]
	test	r2,0x0001
	jz	?L_KeyValueOk
	r1 =	r1 lsr 4
	r1 =	r1 lsr 4
?L_KeyValueOk:
	r1&=	0x00ff
//----------------------------------------------------------------------------------------
	r2 =	[KeyQueueBufPtr]	//Shift key buffer pointer to
	r2+=	0x0001			//next key value
	r2-=	0x0100
	r2&=	0xfff7
	[KeyQueueBufPtr] = r2
//----------------------------------------------------------------------------------------
	r2 =	[PhoneMode]
	r2&=	C_ModeRelatedBits
	r2+=	TW_PhoneMode
	pc =	[r2]
?L_KeyDealOver:
	retf


//----------------------------------------------------------------------------------------
.const		C_ModeRelatedBits	= 0x0001
.const		C_ModeSelectMode	= 0x0000
.const		C_MidiPlayMode		= 0x0001
TW_PhoneMode:
	.dw	F_ModeSelectKeyDeal
	.dw	F_PlayMidiModeKeyDeal
//----------------------------------------------------------------------------------------
F_ModeSelectKeyDeal:
	cmp	r1,C_HandFree
	jnz	?L_NotKeyDel
	
	r1 =	0x0001				// play_rate : 32768/2
	r2 =	0x0006				// channel_num
	call    F_SACM_MS02_Initial

	r1 =	[SongIndex]			// Song_Index
	r2 =	[Volume]			// Volume : 0~3
	call	F_SACM_MS02_Play		//Start play MIDI (Song_Index)
	
	r1 =	[PhoneMode]
	r1|=	Flag_PlayMidi
	[PhoneMode] = r1
	
	r1 =	C_MidiPlayMode			//Set MIDI play mode for key deal
	r1&=	C_ModeRelatedBits
	r2 =	[PhoneMode]
	r2&=	0xffff-C_ModeRelatedBits
	r2|=	r1
	[PhoneMode] = r2
?L_NotKeyDel:
	retf
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
F_PlayMidiModeKeyDeal:
	cmp	r1,C_KeyVolumeUp
	jnz	?L_NotKeyVolumeUp
	r1 =	[Volume]
	r1+=	0x0001
	cmp	r1,C_TopVolume
	jbe	?L_VolumeOk
	r1 =	C_TopVolume
?L_VolumeOk:
	[Volume] = r1
	call	F_SACM_MS02_Volume		// Adjust Volume
	goto	?L_KeyDealOver
?L_NotKeyVolumeUp:
//----------------------------------------------------------------------------------------
	cmp	r1,C_KeyVolumeDown
	jnz	?L_NotKeyVolumeDown
	r1 =	[Volume]
	jz	?L_VolumeOk
	r1-=	0x0001
	jmp	?L_VolumeOk
?L_NotKeyVolumeDown:
//----------------------------------------------------------------------------------------
	cmp	r1,C_Up
	jnz	?L_NotKeyUp
	r1 =	[SongIndex]
	r1+=	0x0001
	cmp	r1,C_SongTotal
	jb	?L_SongIndexOk
	r1 =	C_SongTotal-1
?L_SongIndexOk:
	[SongIndex] = r1

	r1 =	[SongIndex]			// Song_Index
	r2 =	[Volume]			// Volume : 0~3
	call	F_SACM_MS02_Play		// Start play MIDI (Song_Index)

	goto	?L_KeyDealOver
?L_NotKeyUp:
//----------------------------------------------------------------------------------------
	cmp	r1,C_Down
	jnz	?L_NotKeyDown
	r1 =	[SongIndex]
	jz	?L_SongIndexOk
	r1-=	0x0001
	jmp	?L_SongIndexOk
?L_NotKeyDown:
//----------------------------------------------------------------------------------------
	cmp	r1,C_HandFree
	jnz	?L_NotKeyDel
	
	call	F_StopPlay			//Stop play MIDI
	
	r1 =	C_ModeSelectMode		//Set select mode for key deal
	r1&=	C_ModeRelatedBits
	r2=	[PhoneMode]
	r2&=	0xffff-C_ModeRelatedBits
	r2|=	r1
	[PhoneMode] = r2
?L_NotKeyDel:
//----------------------------------------------------------------------------------------
?L_KeyDealOver:
	retf
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------


//----------------------------------------------------------------------------------------
// Function Name:	F_SACM_MS02_Init_
// Purpose:		Initialize related hardware
//			(Set Fosc , TimerA or TimerB , TimerData , P_DAC_Ctrl)
// Parameters:		None
//----------------------------------------------------------------------------------------
F_SACM_MS02_Init_:
	int	off

	r1 =	0x0081
	[P_SystemClock] = r1			//Set High Speed and (/1)

	r1 =	0x0080
	[P_SystemClock] = r1			//Set High Speed and (/1)

	r1 =	0xffff
	[P_IntClr] = r1

	r1 = 0xD500				//Base 32768Hz
	[P_Tmr_Ctrl] = r1

	R1 = 0xFFFE				// 16.384k
	[P_TmrA_Data] = r1			//Set play rate
	[P_TmrA_Load] = r1

	r1 =	[P_Int]
	r1|=	B_TmrAInt
	[P_Int]	= r1				//Enable TimerA interrupt

	R1 = 0x0700				//From DACO pin
	[P_DtmfTone] = r1

	int	fiq, irq
	retf
//----------------------------------------------------------------------------------------

//----------------------------------------------------------------------------------------
// Function Name:	F_StopPlay
// Purpose:		Stop playing MIDI
//			(Clear Flag, Disable TimerA and INT)
// Parameters:		None
//----------------------------------------------------------------------------------------
F_StopPlay:
	call	F_SACM_MS02_Stop

	r1 =	0xFFFF
	[P_IntClr] = r1

	r1 =	0x0000			//Disable TimerA
	[P_Tmr_Ctrl] = r1

	r1 = 	0x0000			//Disable DAC
	[P_DtmfTone] = r1

	r1 = 	[P_Int]
	r1&=	0xffff-0x0004
	[P_Int]	= r1			//Disable TimerA INT

	retf
//----------------------------------------------------------------------------------------


.TEXT
//----------------------------------------------------------------------------------------
//ISR : TimerA INT
//----------------------------------------------------------------------------------------
_FIQ:	
	push	r1,r5 to [sp]
	r1=	B_Ioc1Int
	[P_IntClr] = r1 	
	pop	r1,r5 from [sp]
	reti 
//------------------------------------------------------------------------------
_IRQ0:	
	push	r1,r5 to [sp] 
	r1=	B_Ioc0Int+B_RiInt
	[P_IntClr] = r1
	pop	r1,r5 from [sp] 
	reti
//------------------------------------------------------------------------------
_IRQ1:	
	push	r1,r5 to [sp]
	r1 =	B_IoaInt
	[P_IntClr] = r1
	pop	r1,r5 from [sp]
	reti 
//------------------------------------------------------------------------------
_IRQ2:	
	push r1,r5 to [sp]
	r1=	B_TmrAInt
	[P_IntClr] = r1
	call	F_ISR_Service_SACM_MS02
	pop	r1,r5 from [sp]
	reti 
//------------------------------------------------------------------------------
_IRQ3:
	push	r1,r5 to [sp]
	r1 = 	B_TmrBInt
	[P_IntClr] = r1
	pop	 r1,r5 from [sp]
	reti 
//------------------------------------------------------------------------------
_IRQ4:
	push	r1,r5 to [sp]
	r1 = 	B_T32KHzInt
	[P_IntClr] = r1
	pop	 r1,r5 from [sp]
	reti
//------------------------------------------------------------------------------
_IRQ5:
	push	r1,r5 to [sp] 
	r1=	B_T2KHzInt 
	[P_IntClr] = r1
	
	call	F_KeyTimerService
	
	pop	r1,r5 from [sp] 
	reti 
//------------------------------------------------------------------------------
_IRQ6:
	push	r1,r5 to [sp] 
	r1 =	B_T128HzInt 
	[P_IntClr] = r1
	pop	r1,r5 from [sp] 
	reti 
//------------------------------------------------------------------------------
_IRQ7:
 	push	r1,bp to [sp]
	r1=	B_T8HzInt
	[P_IntClr] = r1
	pop	r1,bp from [sp] 
	reti 
//------------------------------------------------------------------------------
_BREAK:
	reti
//------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
T_SACM_MS02_SongTable:
.DW _RES_01_SA;
.DW _RES_04N_SA;
.DW _RES_ALISOK_SA;
.DW _RES_ARMYN_SA;
.DW _RES_CUCKOO_SA;
.DW _RES_K525_SA;
.DW _RES_LADEN_SA;
.DW _RES_TURKEY_SA;

T_SACM_MS02_InstrumentSet:
   .dw _RES_INSTRUMENT_SA


//----------------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -