コード例 #1
0
ファイル: ioman.c プロジェクト: ACPLMaverick/marjan
signed char ioman_directSectorRead(IOManager *ioman,unsigned long address, unsigned char* buf)
{
	unsigned char* ibuf;
	signed short bp;
	
	if((bp=ioman_findSectorInCache(ioman,address))!=-1){
		ibuf=ioman_getPtr(ioman,bp);
		memCpy(ibuf,buf,512);
		return(0);
	}
	
	if((bp=ioman_findFreeSpot(ioman))!=-1){
		if((ioman_putSectorInCache(ioman,address,bp))){
			return(-1);
		}
		ibuf=ioman_getPtr(ioman,bp);
		memCpy(ibuf,buf,512);
		return(0);
	}

	if(ioman_readSector(ioman,address,buf)){
		return(-1);
	}

	return(0);
}
コード例 #2
0
ファイル: ioman.c プロジェクト: ACPLMaverick/marjan
signed char ioman_directSectorWrite(IOManager *ioman,unsigned long address, unsigned char* buf)
{
	unsigned char* ibuf;
	signed short bp;
	
	if((bp=ioman_findSectorInCache(ioman,address))!=-1){
		ibuf=ioman_getPtr(ioman,bp);
		memCpy(buf,ibuf,512);
		ioman_setWritable(bp);
		return(0);
	}
	
	if((bp=ioman_findFreeSpot(ioman))!=-1){
		ibuf=ioman_getPtr(ioman,bp);
		memCpy(buf,ibuf,512);
		ioman_resetCacheItem(ioman,bp);
		ioman->sector[bp]=address;
		ioman_setWritable(bp);
		ioman_setValid(bp);
		return(0);
	}

	if(ioman_writeSector(ioman,address,buf)){
		return(-1);
	}

	return(0);
}
コード例 #3
0
ファイル: ioman.c プロジェクト: m3y54m/32bitmicro
esint8 ioman_directSectorWrite(IOManager *ioman,euint32 address, euint8* buf)
{
	euint8* ibuf;
	esint16 bp;
	
	if((bp=ioman_findSectorInCache(ioman,address))!=-1){
		ibuf=ioman_getPtr(ioman,bp);
		memCpy(buf,ibuf,512);
		ioman_setWritable(bp);
		return(0);
	}
	
	if((bp=ioman_findFreeSpot(ioman))!=-1){
		ibuf=ioman_getPtr(ioman,bp);
		memCpy(buf,ibuf,512);
		ioman_resetCacheItem(ioman,bp);
		ioman->sector[bp]=address;
		ioman_setWritable(bp);
		ioman_setValid(bp);
		return(0);
	}

	if(ioman_writeSector(ioman,address,buf)){
		return(-1);
	}

	return(0);
}
コード例 #4
0
ファイル: ioman.c プロジェクト: m3y54m/32bitmicro
esint8 ioman_directSectorRead(IOManager *ioman,euint32 address, euint8* buf)
{
	euint8* ibuf;
	esint16 bp;
	
	if((bp=ioman_findSectorInCache(ioman,address))!=-1){
		ibuf=ioman_getPtr(ioman,bp);
		memCpy(ibuf,buf,512);
		return(0);
	}
	
	if((bp=ioman_findFreeSpot(ioman))!=-1){
		if((ioman_putSectorInCache(ioman,address,bp))){
			return(-1);
		}
		ibuf=ioman_getPtr(ioman,bp);
		memCpy(ibuf,buf,512);
		return(0);
	}

	if(ioman_readSector(ioman,address,buf)){
		return(-1);
	}

	return(0);
}
コード例 #5
0
ファイル: ioman.c プロジェクト: ACPLMaverick/marjan
unsigned char* ioman_getSector(IOManager *ioman,unsigned long address, unsigned char mode)
{
	signed long bp;
	
	if((bp=ioman_findSectorInCache(ioman,address))!=-1){
		if(ioman_isReqRw(mode)){
			ioman_setWritable(bp);
		}
		ioman_incUseCnt(ioman,bp);
		if(!ioman_isReqExp(mode))ioman_incRefCnt(ioman,bp);
		return(ioman_getPtr(ioman,bp));
	}
	
	if((bp=ioman_findFreeSpot(ioman))==-1){
		if(((bp=ioman_findUnusedSpot(ioman))!=-1)&&(ioman_isWritable(bp))){
			ioman_flushSector(ioman,bp);
		}
	}
	
	if(bp!=-1){
		ioman_resetCacheItem(ioman,bp);
		if((ioman_putSectorInCache(ioman,address,bp))){
			return(0);
		}
		if(mode==IOM_MODE_READWRITE){
			ioman_setWritable(bp);
		}
		ioman_incUseCnt(ioman,bp);
		if(!ioman_isReqExp(mode))ioman_incRefCnt(ioman,bp);
		return(ioman_getPtr(ioman,bp));
	}
	
	if((bp=ioman_findOverallocableSpot(ioman))!=-1){
		if(ioman_isWritable(bp)){
			ioman_flushSector(ioman,bp);
		}
		if(ioman_push(ioman,bp)){
			return(0);
		}
		ioman_resetCacheItem(ioman,bp);
		if((ioman_putSectorInCache(ioman,address,bp))){
			return(0);
		}
		if(ioman_isReqRw(mode)){
			ioman_setWritable(bp);
		}
		ioman_incUseCnt(ioman,bp);
		if(!ioman_isReqExp(mode))ioman_incRefCnt(ioman,bp);
		return(ioman_getPtr(ioman,bp));
	}
	ioman_setError(ioman,IOMAN_ERR_NOMEMORY);
	return(0);
}
コード例 #6
0
ファイル: ioman_v2.c プロジェクト: kono123/iam
euint8* ioman_getSector(IOManager *ioman,euint32 address, euint8 mode)
{
	esint32 bp;
	
	if((bp=ioman_findSectorInCache(ioman,address))!=-1){
		if(mode==IOM_MODE_READWRITE){
			ioman_setWritable(bp);
		}
		ioman_incUseCnt(ioman,bp);
		ioman_incRefCnt(ioman,bp);
		return(ioman_getPtr(ioman,bp));
	}
	
	if((bp=ioman_findFreeSpot(ioman))==-1){
		if(((bp=ioman_findUnusedSpot(ioman))!=-1)&&(ioman_isWritable(bp))){
			ioman_flushSector(ioman,bp);
		}
	}
	
	if(bp!=-1){
		ioman_resetCacheItem(ioman,bp);
		if((ioman_putSectorInCache(ioman,address,bp))){
			return(0);
		}
		if(mode==IOM_MODE_READWRITE){
			ioman_setWritable(bp);
		}
		ioman_incUseCnt(ioman,bp);
		ioman_incRefCnt(ioman,bp);
		return(ioman_getPtr(ioman,bp));
	}
	
	if((bp=ioman_findOverallocableSpot(ioman))!=-1){
		if(ioman_isWritable(bp)){
			ioman_flushSector(ioman,bp);
		}
		if(ioman_push(ioman,bp)){
			return(0);
		}
		ioman_resetCacheItem(ioman,bp);
		if((ioman_putSectorInCache(ioman,address,bp))){
			return(0);
		}
		if(mode==IOM_MODE_READWRITE){
			ioman_setWritable(bp);
		}
		ioman_incUseCnt(ioman,bp);
		ioman_incRefCnt(ioman,bp);
		return(ioman_getPtr(ioman,bp));
	}
	return(0);
}
コード例 #7
0
ファイル: ioman_v2.c プロジェクト: kono123/iam
esint8 ioman_flushSector(IOManager *ioman, euint16 bufplace)
{
	euint8* buf;
	
	if((buf = ioman_getPtr(ioman,bufplace))==0)return(-1);
	if(!ioman_isWritable(bufplace))return(-1);
	if(!(ioman_writeSector(ioman,ioman->sector[bufplace],buf)))return(-1);
	return(0);
}
コード例 #8
0
ファイル: ioman_v2.c プロジェクト: kono123/iam
esint8 ioman_putSectorInCache(IOManager *ioman, euint32 address, euint16 bufplace)
{
	euint8* buf;
	
	if((buf = ioman_getPtr(ioman,bufplace))==0)return(-1);
	if((ioman_readSector(ioman,address,buf)))return(-1);
	ioman_setValid(bufplace);
	ioman->sector[bufplace]=address;
	return(0);
}
コード例 #9
0
ファイル: ioman.c プロジェクト: ACPLMaverick/marjan
signed char ioman_putSectorInCache(IOManager *ioman, unsigned long address, unsigned short bufplace)
{
	unsigned char* buf;
	
	if((buf = ioman_getPtr(ioman,bufplace))==0){
		ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE);
		return(-1);
	}
	if((ioman_readSector(ioman,address,buf))){
		ioman_setError(ioman,IOMAN_ERR_READFAIL);
		return(-1);
	}
	ioman_setValid(bufplace);
	ioman->sector[bufplace]=address;
	return(0);
}
コード例 #10
0
ファイル: ioman.c プロジェクト: m3y54m/32bitmicro
esint8 ioman_putSectorInCache(IOManager *ioman, euint32 address, euint16 bufplace)
{
	euint8* buf;
	
	if((buf = ioman_getPtr(ioman,bufplace))==0){
		ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE);
		return(-1);
	}
	if((ioman_readSector(ioman,address,buf))){
		ioman_setError(ioman,IOMAN_ERR_READFAIL);
		return(-1);
	}
	ioman_setValid(bufplace);
	ioman->sector[bufplace]=address;
	return(0);
}
コード例 #11
0
ファイル: ioman.c プロジェクト: ACPLMaverick/marjan
signed char ioman_flushSector(IOManager *ioman, unsigned short bufplace)
{
	unsigned char* buf;
	
	if((buf = ioman_getPtr(ioman,bufplace))==0){
		ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE);
		return(-1);
	}
	if(!ioman_isWritable(bufplace)){
		ioman_setError(ioman,IOMAN_ERR_WRITEREADONLYSECTOR);
		return(-1);
	}
	if(!(ioman_writeSector(ioman,ioman->sector[bufplace],buf))){
		ioman_setError(ioman,IOMAN_ERR_WRITEFAIL);	
		return(-1);
	}
	if(ioman->usage==0)ioman_setNotWritable(bufplace);
	return(0);
}