home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Phoenix Heaven Sunny 2
/
APPARE2.BIN
/
oh_towns
/
his
/
source
/
hisl10.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-20
|
4KB
|
152 lines
/***********************************************************************
* *
* ハードウェア割り込み支援ライブラリ *
* *
* 1995.6.12 by ちょもらんま *
* *
***********************************************************************/
#include <hisinner.h>
/******************************* 外部変数 ******************************/
/*----------------- ユーザー割り込みハンドラ記録用構造体 --------------*/
userHandler_t userHandler[ HardwareIntTypes ];
/*--- 旧割り込みハンドラアドレス&割り込みマスクレジスタの記録状態 ----*/
intInfo *topIntInfo[ HardwareIntTypes ] =
{
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL
};
/************************ 割り込みハンドラの登録 ***********************/
int HIS_setHandler( int intnum, void (*handler)() )
{
int retValue = HIS_OtherHandler;
intInfo *newInfo,*preInfo;
_Handler HardIntEntryX;
/*--------------- 割り込み番号は正常か? --------------*/
if( HIS_checkIntNumber( intnum ) == HIS_IllegalIntNumber )
{
return HIS_IllegalIntNumber;
}
/*----- 割り込みハンドラ記録変数のサイズは予定通り(8バイト)か?-----*/
if( sizeof( userHandler_t ) != 8 )
{
return HIS_UnexpectedSize;
}
/*--------- 旧割り込みハンドラを退避する場所を確保 ------*/
if( ( newInfo = malloc( sizeof( intInfo ) ) ) == NULL )
{
return HIS_OutofMemory;
}
newInfo->nextInfo = NULL;
/*--------------- 旧割り込みハンドラを退避 --------------*/
if( topIntInfo[ intnum ] == NULL )
{
/* 初めての場合 */
topIntInfo[ intnum ] = newInfo;
retValue = HIS_NoError;
/* リアル側ハンドラ退避 */
newInfo->RealHandler = _getrvect( intnum + HardVector );
/* ネイティブ側ハンドラ退避 */
newInfo->NativeHandler = _getpvect( intnum + HardVector );
}
else
{
/* 先客がいる場合 */
preInfo = topIntInfo[ intnum ];
while( preInfo->nextInfo != NULL )
{
preInfo = preInfo->nextInfo;
}
preInfo->nextInfo = newInfo;
retValue = HIS_OtherHandler;
/* 旧ユーザハンドラ退避 */
newInfo->NativeHandler = (_Handler)(userHandler[ intnum ].handlerAdr);
newInfo->dataSegment = userHandler[ intnum ].dataSegment;
}
/*--------------------- IMR退避 --------------------*/
newInfo->IMR = HIS_checkMask( intnum );
/*----------------- 割り込みの一時禁止 ----------------*/
HIS_disableAllInt();
/*--------------- ユーザのハンドラを登録 --------------*/
_FP_OFF( userHandler[ intnum ].handlerAdr ) = (unsigned)handler;
_FP_SEG( userHandler[ intnum ].handlerAdr ) = HIS_getCS();
userHandler[ intnum ].dataSegment = HIS_getDS();
switch( intnum )
{
case 0 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry0;
break;
case 1 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry1;
break;
case 2 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry2;
break;
case 3 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry3;
break;
case 4 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry4;
break;
case 5 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry5;
break;
case 6 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry6;
break;
case 7 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry7;
break;
case 8 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry8;
break;
case 9 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry9;
break;
case 10 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry10;
break;
case 11 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry11;
break;
case 12 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry12;
break;
case 13 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry13;
break;
case 14 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry14;
break;
case 15 :
_FP_OFF( HardIntEntryX ) = (unsigned int)HardIntEntry15;
break;
}
_FP_SEG( HardIntEntryX ) = HIS_getCS();
_setrpvectp( intnum + HardVector , HardIntEntryX );
/*------------------- 割り込みの許可 ------------------*/
HIS_enableAllInt();
return retValue;
}