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); }
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); }
signed char ioman_push(IOManager *ioman,unsigned short bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return(-1); } if(ioman->itptr[bufplace]>=IOMAN_NUMITERATIONS){ ioman_setError(ioman,IOMAN_ERR_PUSHBEYONDSTACK); return(-1); } ioman->itptr[bufplace]++; ioman->stack[bufplace][ioman->itptr[bufplace]].sector = ioman->sector[bufplace]; ioman->stack[bufplace][ioman->itptr[bufplace]].status = ioman->status[bufplace]; ioman->stack[bufplace][ioman->itptr[bufplace]].usage = ioman->usage[bufplace]; return(0); }
unsigned char* ioman_getPtr(IOManager *ioman,unsigned short bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return(0); } return(ioman->bufptr+bufplace*512); }
void ioman_resetUseCnt(IOManager *ioman,euint16 bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return; } ioman->usage[bufplace]=0x00; }
void ioman_resetRefCnt(IOManager *ioman,unsigned short bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return; } ioman->reference[bufplace]=0x00; }
void ioman_reset(IOManager *ioman) { ioman->sector=ioman->status=ioman->itptr=0; ioman->stack.sector=ioman->stack.status=0; ioman_setError(ioman,IOMAN_NOERROR); }
signed short ioman_getBp(IOManager *ioman,unsigned char* buf) { if(buf<(ioman->bufptr) || buf>=( ioman->bufptr+(ioman->numbuf*512) )){ ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE); return(-1); } return((buf-(ioman->bufptr))/512); }
unsigned char ioman_getUseCnt(IOManager *ioman,unsigned short bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return(0x00); } return(ioman->usage[bufplace]); }
esint16 ioman_getBp(IOManager *ioman,euint8* buf) { if(buf<(ioman->bufptr) || buf>=( ioman->bufptr+(ioman->numbuf*512) )){ ioman_setError(ioman,IOMAN_ERR_CACHEPTROUTOFRANGE); return(-1); } return((buf-(ioman->bufptr))/512); }
euint8* ioman_getPtr(IOManager *ioman,euint16 bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return(0); } return(ioman->bufptr+bufplace*512); }
euint8 ioman_getRefCnt(IOManager *ioman,euint16 bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return(0x00); } return(ioman->reference[bufplace]); }
void ioman_incRefCnt(IOManager *ioman,unsigned short bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return; } if(ioman->reference[bufplace]==0xFF)return; else ioman->reference[bufplace]++; }
euint8 ioman_getAttr(IOManager *ioman,euint16 bufplace,euint8 attribute) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_GETATTROUTOFBOUNDS); return(0xFF); /* Out of bounds */ } return(ioman->status[bufplace]&(1<<attribute)); }
void ioman_decRefCnt(IOManager *ioman,euint16 bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return; } if(ioman->reference[bufplace]==0x00)return; else ioman->reference[bufplace]--; }
void ioman_decUseCnt(IOManager *ioman,unsigned short bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return; } if(ioman->usage[bufplace]==0x0)return; else ioman->usage[bufplace]--; }
void ioman_incUseCnt(IOManager *ioman,euint16 bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return; } if(ioman->usage[bufplace]==0xFF)return; else ioman->usage[bufplace]++; }
unsigned char ioman_getAttr(IOManager *ioman,unsigned short bufplace,unsigned char attribute) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_GETATTROUTOFBOUNDS); return(0xFF); /* Out of bounds */ } return(ioman->status[bufplace]&(1<<attribute)); }
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); }
void ioman_resetCacheItem(IOManager *ioman,unsigned short bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_OPOUTOFBOUNDS); return; } ioman->sector[bufplace] = 0; ioman->status[bufplace] = 0; ioman->usage[bufplace] = 0; ioman->reference[bufplace] = 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); }
signed char ioman_pop(IOManager *ioman,unsigned short bufplace) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_POPEMPTYSTACK); return(-1); } if(ioman->itptr[bufplace]==0 || ioman->itptr[bufplace]>IOMAN_NUMITERATIONS)return(-1); ioman->sector[bufplace] = ioman->stack[bufplace][ioman->itptr[bufplace]].sector; ioman->status[bufplace] = ioman->stack[bufplace][ioman->itptr[bufplace]].status; ioman->usage[bufplace] = ioman->stack[bufplace][ioman->itptr[bufplace]].usage; ioman->itptr[bufplace]--; return(0); }
void ioman_setAttr(IOManager *ioman,unsigned short bufplace,unsigned char attribute,unsigned char val) { if(bufplace>=ioman->numbuf){ ioman_setError(ioman,IOMAN_ERR_SETATTROUTOFBOUNDS); return; /* Out of bounds */ } if(val){ ioman->status[bufplace]|=1<<attribute; }else{ ioman->status[bufplace]&=~(1<<attribute); } }
esint8 ioman_writeSector(IOManager *ioman, euint32 address, euint8* buf) { esint8 r; if(buf==0)return(-1); r=if_writeBuf(ioman->iface,address,buf); if(r<=0){ ioman_setError(ioman,IOMAN_ERR_WRITEFAIL); return(-1); } return(0); }
signed char ioman_writeSector(IOManager *ioman, unsigned long address, unsigned char* buf) { signed char r; if(buf==0)return(-1); r=if_writeBuf(ioman->iface,address,buf); if(r<=0){ ioman_setError(ioman,IOMAN_ERR_WRITEFAIL); return(-1); } return(0); }
esint8 ioman_readSector(IOManager *ioman,euint32 address,euint8* buf) { esint8 r; if(buf==0){ return(-1); } r=if_readBuf(ioman->iface,address,buf); if(r!=0){ ioman_setError(ioman,IOMAN_ERR_READFAIL); return(-1); } return(0); }
signed char ioman_readSector(IOManager *ioman,unsigned long address,unsigned char* buf) { signed char r; if(buf==0){ return(-1); } r=if_readBuf(ioman->iface,address,buf); if(r!=0){ ioman_setError(ioman,IOMAN_ERR_READFAIL); return(-1); } return(0); }
void ioman_reset(IOManager *ioman) { euint16 nb,ni; memClr(ioman->sector,sizeof(euint32)*ioman->numbuf); memClr(ioman->status,sizeof(euint8) *ioman->numbuf); memClr(ioman->usage ,sizeof(euint8) *ioman->numbuf); memClr(ioman->itptr ,sizeof(euint8) *ioman->numbuf); ioman_setError(ioman,IOMAN_NOERROR); for(nb=0;nb<ioman->numbuf;nb++){ for(ni=0;ni<ioman->numit;ni++){ ioman->stack[nb][ni].sector=0; ioman->stack[nb][ni].status=0; ioman->stack[nb][ni].usage =0; } } }
void ioman_reset(IOManager *ioman) { unsigned short nb,ni; memClr(ioman->sector,sizeof(unsigned long)*ioman->numbuf); memClr(ioman->status,sizeof(unsigned char) *ioman->numbuf); memClr(ioman->usage ,sizeof(unsigned char) *ioman->numbuf); memClr(ioman->itptr ,sizeof(unsigned char) *ioman->numbuf); ioman_setError(ioman,IOMAN_NOERROR); for(nb=0;nb<ioman->numbuf;nb++){ for(ni=0;ni<ioman->numit;ni++){ ioman->stack[nb][ni].sector=0; ioman->stack[nb][ni].status=0; ioman->stack[nb][ni].usage =0; } } }