📄 maresmgr.c
字号:
/****************************************************************************
*
* Copyright (C) 2002-2003 YAMAHA CORPORATION. All rights reserved.
*
* Module : maresmgr.c
*
* Description : MA Resource Manager
*
* Version : 1.0.3 2003.01.23
*
****************************************************************************/
#include "maresmgr.h" /* MA Resource Manager */
#include "mamachdep.h" /* MA Define machine dependent */
#define MARESMGR_STREAM_INT_POINT (0) /* stream irq point : size x 1/4 */
#define MARESMGR_STREAM_BUF_SIZE (1) /* stream buffer size: 1024byte */
#define MARESMGR_STREAM_WRITE_SIZE (256) /* write size (byte) for a int task */
#define MARESMGR_RB_MAP_MASK (0x000000FF) /* RAM block */
#define MARESMGR_CH_MAP_MASK (0x0001FFFF) /* Channel bit16:Ex Channel */
#define MARESMGR_FM_MAP_MASK (0xFFFFFFFF) /* FM voice */
#define MARESMGR_WT_MAP_MASK (0xFFFFFFFF) /* WT voice */
#define MARESMGR_SA_MAP_MASK (0x00000003) /* Stream Audio */
#define MARESMGR_AL_MAP_MASK (0x00000001) /* AL voice */
#define MARESMGR_HV_MAP_MASK (0x00000001) /* HV voice */
#define MARESMGR_LD_MAP_MASK (0x00000001) /* LED */
#define MARESMGR_MT_MAP_MASK (0x00000001) /* Motor */
#define MARESMGR_SQ_MAP_MASK (0x00000003) /* Sequencer */
#define MARESMGR_TM_MAP_MASK (0x0000000F) /* Timer */
#define MARESMGR_AI_MAP_MASK (0x00000003) /* Stream Audio Interrupt */
#define MARESMGR_SI_MAP_MASK (0x0000003F) /* Software Interrupt */
#define MA_FM_EXT_MAP_MASK (0xFFFF0000) /* FM voice for 2OP */
#define MARESMGR_MAX_WAVEID (31) /* maximum value of wave id */
#define MARESMGR_FMMODE_2OP (0) /* FM 2OP mode */
#define MARESMGR_FMMODE_4OP (1) /* FM 4OP mode */
#define MARESMGR_FMMODE_FREE (2) /* FM mode Free */
/* Resource Information */
static MA_RESOURCE_INFO gMaResInfo;
static PMA_RESOURCE_INFO pgMaResInfo = &gMaResInfo;
static const UINT16 wMaRomDrumType[128/16] =
{
/* F E D C B A 9 8 7 6 5 4 3 2 1 0 */
/* --------+------------------------------------ */
0x0000, /* 0- 15 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0x8000, /* 16- 31 | 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0xFF5A, /* 32- 47 | 1 1 1 1 1 1 1 1 0 1 0 1 1 0 1 0 */
0x0A9F, /* 48- 63 | 0 0 0 0 1 0 1 0 1 0 0 1 1 1 1 1 */
0x0000, /* 64- 79 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0x0000, /* 80- 95 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0x0000, /* 96-111 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
0x0000, /* 112-127 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 */
};
static const UINT16 wMaRomWaveAdrs[MA_MAX_ROM_WAVE] =
{ 0x1400, 0x15D6, 0x1BA4, 0x2288, 0x24F4, 0x2B72, 0x34D2 };
static const UINT16 wMaRomDrumKey[61] =
{
0x0058, 0x001D, 0x003C, 0x0024, 0x0018, 0x0012, 0x0057, 0x3E80,
0x005E, 0x2328, 0x0027, 0x2710, 0x2EE0, 0x004A, 0x4A38, 0x0063,
0x59D8, 0x1F40, 0x3A98, 0x2710, 0x36B0, 0x30D4, 0x3C8C, 0x3A98,
0x4650, 0x3390, 0x5208, 0x3E80, 0x2328, 0x006F, 0x006D, 0x5208,
0x0054, 0x36B0, 0x001A, 0x4650, 0x002b, 0x0021, 0x004C, 0x0013,
0x0039, 0x0033, 0x002E, 0x004D, 0x0048, 0x0064, 0x006D, 0x0032,
0x0030, 0x0031, 0x0030, 0x0045, 0x0049, 0x0044, 0x0050, 0x0010,
0x0058, 0x0058, 0x005E, 0x004C, 0x003E
};
/****************************************************************************
* MaResMgr_GetResourceInfo
*
* Function:
* Gets the currenet mapping of resources.
* Argument:
* None
* Return:
* Pointer to the resource information structure.
*
****************************************************************************/
PMA_RESOURCE_INFO MaResMgr_GetResourceInfo( void )
{
MARESMGR_DBGMSG((" MaResMgr_GetResourceInfo:\n"));
return pgMaResInfo;
}
/****************************************************************************
* MaResMgr_GetDefWaveAddress
*
* Function:
* Get internal memory address of specified wave data.
* Argument:
* dWaveId wave id number (0..6)
* Return:
* > 0 internal memory address of specified wave data.
* 0 no entry
* < 0 error code
*
****************************************************************************/
SINT32 MaResMgr_GetDefWaveAddress
(
UINT32 dWaveId /* wave id */
)
{
SINT32 sdResult;
MARESMGR_DBGMSG((" MaResMgr_GetDefWaveAddress: dWaveId=%d ->", dWaveId));
if ( dWaveId >= MA_MAX_ROM_WAVE )
{
MARESMGR_DBGMSG(("illegal wave id\n"));
return MASMW_ERROR_ARGUMENT;
}
sdResult = (SINT32)wMaRomWaveAdrs[dWaveId];
MARESMGR_DBGMSG((" %04lX\n", sdResult));
return sdResult;
}
/****************************************************************************
* MaResMgr_GetDefVoiceAddress
*
* Function:
* Get internal memory address of specified timber.
* Argument:
* dProg program number(0..127: melody timbers, 128..255: drum timbers)
* Return:
* > 0 internal memory address of specified timber.
* 0 no entry
* < 0 error code
*
****************************************************************************/
SINT32 MaResMgr_GetDefVoiceAddress
(
UINT32 dProg /* program number */
)
{
SINT32 sdResult;
MARESMGR_DBGMSG((" MaResMgr_GetDefVoiceAddress: dProg=%d ->", dProg));
if ( dProg < 128 )
{
/* melody */
sdResult = (SINT32)( MA_NORMAL_ROM_ADDRESS + ( dProg * 16 ) );
}
else
{
dProg -= 128;
/* drum */
if ( ( dProg < MA_MIN_ROM_DRUM ) || ( MA_MAX_ROM_DRUM < dProg ) )
{
sdResult = (SINT32)(0);
}
else
{
sdResult = (SINT32)( MA_DRUM_ROM_ADDRESS + ( ( dProg - MA_MIN_ROM_DRUM ) * 16 ) );
}
}
MARESMGR_DBGMSG((" %04lX\n", sdResult));
return sdResult;
}
/****************************************************************************
* MaResMgr_GetDefVoiceSynth
*
* Function:
* Get the voice type of specified timber.
* Argument:
* dProg program number(0..127: melody timbers, 128..255: drum timbers)
* Return:
* > 0 voice type of specified timber (1:FM, 2:WT).
* 0 no entry
* < 0 error code
*
****************************************************************************/
SINT32 MaResMgr_GetDefVoiceSynth
(
UINT32 dProg /* program number */
)
{
SINT32 sdResult;
MARESMGR_DBGMSG((" MaResMgr_GetDefVoiceSynth: dProg=%d ->", dProg));
if ( dProg < 128 )
{
sdResult = (SINT32)(1);
}
else
{
dProg -= 128;
if ( ( dProg < MA_MIN_ROM_DRUM ) || ( MA_MAX_ROM_DRUM < dProg ) )
{
sdResult = (SINT32)(0);
}
else
{
sdResult = (SINT32)( ( ( wMaRomDrumType[dProg/16] >> (dProg%16) ) & 0x1 ) + 1 );
}
}
MARESMGR_DBGMSG((" %lu\n", sdResult));
return sdResult;
}
/****************************************************************************
* MaResMgr_GetDefVoiceKey
*
* Function:
* Get the key(block:f-number) of specified timber.
* Argument:
* dProg program number(0..127: melody timbers, 128..255: drum timbers)
* Return:
* > 0 key of specified timber.
* 0 no entry
* < 0 error code
*
****************************************************************************/
SINT32 MaResMgr_GetDefVoiceKey
(
UINT32 dProg /* program number */
)
{
SINT32 sdResult;
MARESMGR_DBGMSG((" MaResMgr_GetDefVoiceKey: dProg=%d ->", dProg));
if ( dProg < 128 )
{
sdResult = (SINT32)MASMW_ERROR;
}
else
{
dProg -= 128;
if ( ( dProg < MA_MIN_ROM_DRUM ) || ( MA_MAX_ROM_DRUM < dProg ) )
{
sdResult = (SINT32)(0);
}
else
{
sdResult = (SINT32)wMaRomDrumKey[dProg - MA_MIN_ROM_DRUM];
}
}
MARESMGR_DBGMSG((" %ld\n", sdResult));
return sdResult;
}
/****************************************************************************
* MaResMgr_RegStreamAudio
*
* Function:
* Regist the wave data for stream audio.
* Argument:
* dWaveId wave id (0..31)
* dFormat wave format
* pbWave pointer to the wave data for stream audio
* dWaveSize size of the wave data for stream audio
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_RegStreamAudio
(
UINT32 dWaveId, /* wave id */
UINT32 dFormat, /* wave format */
UINT8 * pbWave, /* pointer to the wave data */
UINT32 dWaveSize /* size of the wave data */
)
{
MARESMGR_DBGMSG((" MaResMgr_RegStreamAudio: id=%d ptr=%p sz=%ld\n", dWaveId, pbWave, dWaveSize));
/* check argument */
if ( dWaveId > MARESMGR_MAX_WAVEID )
{
MARESMGR_DBGMSG(("illegal wave id\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( (dFormat & 0x0000007F) > 0x00000004 )
{
MARESMGR_DBGMSG(("illegal wave format\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( (dFormat & 0xFFFFFF80) > 0x00000080 )
{
MARESMGR_DBGMSG(("illegal wave format\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( pbWave == NULL )
{
MARESMGR_DBGMSG(("illegal pointer to the wave data\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( dWaveSize == 0 )
{
MARESMGR_DBGMSG(("illegal size of the wave data\n"));
return MASMW_ERROR_ARGUMENT;
}
/* regist wave data */
pgMaResInfo->StreamAudio[dWaveId].dFormat = dFormat;
pgMaResInfo->StreamAudio[dWaveId].pbWave = pbWave;
pgMaResInfo->StreamAudio[dWaveId].dWaveSize = dWaveSize;
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_DelStreamAudio
*
* Function:
* Delete the wave data for stream audio.
* Argument:
* dWaveId wave id
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_DelStreamAudio
(
UINT32 dWaveId /* wave id */
)
{
MARESMGR_DBGMSG((" MaResMgr_DelStreamAudio: id=%d\n", dWaveId));
/* check argument */
if ( dWaveId > MARESMGR_MAX_WAVEID )
{
MARESMGR_DBGMSG(("illegal wave id\n"));
return MASMW_ERROR_ARGUMENT;
}
pgMaResInfo->StreamAudio[dWaveId].pbWave = NULL;
pgMaResInfo->StreamAudio[dWaveId].dWaveSize = 0;
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_GetStreamAudioInfo
*
* Function:
* return the wave data for stream audio.
* Argument:
* dWaveId wave id
* pdFormat pointer to the area put wave format to
* ppbWave pointer to the area put the pointer to
* the wave data for stream audio to
* pdWaveSize pointer to the area put the size of
* the wave data for stream audio to
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_GetStreamAudioInfo
(
UINT32 dWaveId, /* wave id */
UINT32 * pdFormat, /* format */
UINT8 ** ppbWave, /* pointer to the wave data */
UINT32 * pdWaveSize /* size of the wave data */
)
{
MARESMGR_DBGMSG((" MaResMgr_GetStreamAudioInfo: dWaveId=%d\n", dWaveId));
/* check argument */
if ( dWaveId > MARESMGR_MAX_WAVEID )
{
MARESMGR_DBGMSG(("illegal wave id\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( pdFormat == NULL )
{
MARESMGR_DBGMSG(("illegal pointer\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( ppbWave == NULL )
{
MARESMGR_DBGMSG(("illegal pointer\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( pdWaveSize == NULL )
{
MARESMGR_DBGMSG(("illegal pointer\n"));
return MASMW_ERROR_ARGUMENT;
}
*pdFormat = pgMaResInfo->StreamAudio[dWaveId].dFormat;
*ppbWave = pgMaResInfo->StreamAudio[dWaveId].pbWave;
*pdWaveSize = pgMaResInfo->StreamAudio[dWaveId].dWaveSize;
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_AllocRam
*
* Function:
* Allocate the specified RAM block resources.
* Argument:
* dRbMap bit mapping of RAM block resources to allocate.
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_AllocRam
(
UINT32 dRbMap /* ram block map */
)
{
MARESMGR_DBGMSG((" MaResMgr_AllocRam : dRbMap=%08lX", dRbMap));
if ( dRbMap == 0x00000000 ) return MASMW_SUCCESS;
if ( ( dRbMap & MARESMGR_RB_MAP_MASK ) != dRbMap )
{
MARESMGR_DBGMSG(("illegal rb value\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( ( pgMaResInfo->dRbMap & dRbMap ) != 0 )
{
MARESMGR_DBGMSG(("can't alloc rb\n"));
return MASMW_ERROR_RESOURCE_OVER;
}
pgMaResInfo->dRbMap |= dRbMap;
MARESMGR_DBGMSG((" -> dRbMap=%08lX\n", pgMaResInfo->dRbMap));
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_FreeRam
*
* Function:
* Free RAM block resources.
* Argument:
* dRbMap bit mapping of RAM block resources to free
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_FreeRam
(
UINT32 dRbMap /* ram block map */
)
{
MARESMGR_DBGMSG((" MaResMgr_FreeRam : dRbMap=%08lX", dRbMap));
if ( dRbMap == 0x00000000 ) return MASMW_SUCCESS;
if ( ( dRbMap & MARESMGR_RB_MAP_MASK ) != dRbMap )
{
MARESMGR_DBGMSG(("illegal rb value\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( ( pgMaResInfo->dRbMap & dRbMap ) != dRbMap )
{
MARESMGR_DBGMSG(("can't free rb\n"));
return MASMW_ERROR;
}
pgMaResInfo->dRbMap &= ~dRbMap;
MARESMGR_DBGMSG((" -> dRbMap=%08lX\n", pgMaResInfo->dRbMap));
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_AllocCh
*
* Function:
* Allocate the channel resources.
* Argument:
* dChMap bit mapping of channel resources to allocate.
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_AllocCh
(
UINT32 dChMap /* channel map */
)
{
MARESMGR_DBGMSG((" MaResMgr_AllocCh : dChMap=%08lX", dChMap));
if ( dChMap == 0x00000000 ) return MASMW_SUCCESS;
if ( ( dChMap & MARESMGR_CH_MAP_MASK ) != dChMap )
{
MARESMGR_DBGMSG((" illegal ch value\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( ( pgMaResInfo->dChMap & dChMap ) != 0 )
{
MARESMGR_DBGMSG((" can't alloc ch\n"));
return MASMW_ERROR_RESOURCE_OVER;
}
pgMaResInfo->dChMap |= dChMap;
MARESMGR_DBGMSG((" -> dChMap=%08lX\n", pgMaResInfo->dChMap));
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_FreeCh
*
* Function:
* Free the specified channel resources.
* Argument:
* dChMap bit mapping of channel resources to free.
* Return:
* 0 success
* < 0 error codes
*
****************************************************************************/
SINT32 MaResMgr_FreeCh
(
UINT32 dChMap /* channel map */
)
{
MARESMGR_DBGMSG((" MaResMgr_FreeCh : dChMap=%08lX", dChMap));
if ( dChMap == 0x00000000 ) return MASMW_SUCCESS;
if ( ( dChMap & MARESMGR_CH_MAP_MASK ) != dChMap )
{
MARESMGR_DBGMSG(("illegal ch value\n"));
return MASMW_ERROR_ARGUMENT;
}
if ( ( pgMaResInfo->dChMap & dChMap ) != dChMap )
{
MARESMGR_DBGMSG(("can't free ch\n"));
return MASMW_ERROR;
}
pgMaResInfo->dChMap &= ~dChMap;
MARESMGR_DBGMSG((" -> dChMap=%08lX\n", pgMaResInfo->dChMap));
return MASMW_SUCCESS;
}
/****************************************************************************
* MaResMgr_AllocFmVoice
*
* Function:
* Allocate the FM voice resources.
* Argument:
* dFmMap bit mapping of FM voice resources to allocate
* dFmMode FM mode 0:2OP / 1:4OP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -