Esempio n. 1
0
esint32 ioman_findUnusedSpot(IOManager *ioman)
{
	esint32 r=-1;
	euint16 c;
	euint8 fr=0,lr=0xFF;
	
	for(c=0;c<ioman->numbuf;c++){
		if(ioman_getUseCnt(ioman,c)==0){
			if(!ioman_isWritable(c) && !fr){
				fr=1;
				lr=0xFF;
				r=-1;
			}
			if(ioman_isWritable(c) && !fr){
				if(ioman_getRefCnt(ioman,c)<=lr){
					r=c;
					lr=ioman_getRefCnt(ioman,c);
				}
			}
			if(fr && !ioman_isWritable(c)){
				if(ioman_getRefCnt(ioman,c)<=lr){
					r=c;
					lr=ioman_getRefCnt(ioman,c);
				}
			}
		}
	}
	return(r);
}
Esempio n. 2
0
signed long ioman_findUnusedSpot(IOManager *ioman)
{
	signed long r=-1;
	unsigned short c;
	unsigned char fr=0,lr=0xFF;
	
	for(c=0;c<ioman->numbuf;c++){
		if(ioman_getUseCnt(ioman,c)==0){
			if(!ioman_isWritable(c) && !fr){
				fr=1;
				lr=0xFF;
				r=-1;
			}
			if(ioman_isWritable(c) && !fr){
				if(ioman_getRefCnt(ioman,c)<=lr){
					r=c;
					lr=ioman_getRefCnt(ioman,c);
				}
			}
			if(fr && !ioman_isWritable(c)){
				if(ioman_getRefCnt(ioman,c)<=lr){
					r=c;
					lr=ioman_getRefCnt(ioman,c);
				}
			}
		}
	}
	return(r);
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
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);
}
Esempio n. 6
0
signed char ioman_flushAll(IOManager *ioman)
{
	unsigned short c;
	
	for(c=0;c<ioman->numbuf;c++){
		if(ioman_isWritable(c)){
			if(ioman_flushSector(ioman,c)){
				return(-1);
			}
			if(ioman->usage[c]==0)ioman_setNotWritable(c);
		}
	}
	return(0);
}
Esempio n. 7
0
esint8 ioman_flushAll(IOManager *ioman)
{
	euint16 c;
	
	for(c=0;c<ioman->numbuf;c++){
		if(ioman_isWritable(c)){
			if(ioman_flushSector(ioman,c)){
				return(-1);
			}
			if(ioman->usage[c]==0)ioman_setNotWritable(c);
		}
	}
	return(0);
}
Esempio n. 8
0
void ioman_printStatus(IOManager *ioman)
{
	unsigned short c;
	
	DBG((TXT("IO-Manager -- Report\n====================\n")));
	DBG((TXT("Buffer is %i sectors, from %p to %p\n"),
	          ioman->numbuf,ioman->bufptr,ioman->bufptr+(ioman->numbuf*512)));
	for(c=0;c<ioman->numbuf;c++){
		if(ioman_isValid(c)){
			DBG((TXT("BP %3i\t SC %8li\t\t US %i\t RF %i\t %s %s\n"),
				c,ioman->sector[c],ioman_getUseCnt(ioman,c),ioman_getRefCnt(ioman,c),
				ioman_isUserBuf(c) ? "USRBUF" : "      ",
				ioman_isWritable(c) ? "WRITABLE" : "READONLY"));
		}
	}
}
Esempio n. 9
0
signed char ioman_releaseSector(IOManager *ioman,unsigned char* buf)
{
	unsigned short bp;
	
	bp=ioman_getBp(ioman,buf);
	ioman_decUseCnt(ioman,bp);
	
	if(ioman_getUseCnt(ioman,bp)==0 && ioman->itptr[bp]!=0){
		if(ioman_isWritable(bp)){
			ioman_flushSector(ioman,bp);
		}
		ioman_pop(ioman,bp);
		ioman_putSectorInCache(ioman,ioman->sector[bp],bp);
	}
	return(0);
}
Esempio n. 10
0
esint8 ioman_releaseSector(IOManager *ioman,euint8* buf)
{
	euint16 bp;
	
	bp=ioman_getBp(ioman,buf);
	ioman_decUseCnt(ioman,bp);
	
	if(ioman_getUseCnt(ioman,bp)==0 && ioman->itptr[bp]!=0){
		if(ioman_isWritable(bp)){
			ioman_flushSector(ioman,bp);
		}
		ioman_pop(ioman,bp);
		ioman_putSectorInCache(ioman,ioman->sector[bp],bp);
	}
	return(0);
}
Esempio n. 11
0
signed char ioman_flushRange(IOManager *ioman,unsigned long address_low, unsigned long address_high)
{
	unsigned long c;
	
	if(address_low>address_high){
		c=address_low; address_low=address_high;address_high=c;
	}
	
	for(c=0;c<ioman->numbuf;c++){
		if((ioman->sector[c]>=address_low) && (ioman->sector[c]<=address_high) && (ioman_isWritable(c))){
			if(ioman_flushSector(ioman,c)){
				return(-1);
			}
			if(ioman->usage[c]==0)ioman_setNotWritable(c);
		}
	}
	return(0);
}
Esempio n. 12
0
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);
}
Esempio n. 13
0
signed long ioman_findOverallocableSpot(IOManager *ioman)
{
	unsigned char points,lp=0xFF;
	unsigned short c;
	signed long r=-1;
	
	for(c=0;c<ioman->numbuf;c++){
		if(ioman->itptr[c]<ioman->numit){
			points = 0;
			if(ioman_isWritable(c))points+=0x7F;
			points += ((unsigned short)(ioman->itptr[c]*0x4D))/(ioman->numit);
			points += ((unsigned short)(ioman_getRefCnt(ioman,c)*0x33))/0xFF;
			if(points<lp){
				lp=points;
				r=c;
			}
		}
	}
	return(r);
}
Esempio n. 14
0
esint32 ioman_findOverallocableSpot(IOManager *ioman)
{
	euint8 points,lp=0xFF;
	euint16 c;
	esint32 r=-1;
	
	for(c=0;c<ioman->numbuf;c++){
		if(ioman->itptr[c]<ioman->numit){
			points = 0;
			if(ioman_isWritable(c))points+=0x7F;
			points += ((euint16)(ioman->itptr[c]*0x4D))/(ioman->numit);
			points += ((euint16)(ioman_getRefCnt(ioman,c)*0x33))/0xFF;
			if(points<lp){
				lp=points;
				r=c;
			}
		}
	}
	return(r);
}