home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / rio006-2.zip / RIO.H < prev    next >
C/C++ Source or Header  |  1999-03-15  |  5KB  |  199 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. //    rio.h
  4. //
  5. ///////////////////////////////////////////////////////////////////////////////
  6.  
  7. #ifndef        _RIO_
  8. #define        _RIO_
  9.  
  10. // dependencies
  11. #include    "std.h"
  12.  
  13. // version
  14. #define        CRIO_ID_VERSION                106
  15.  
  16. // blocks available on 32M unit
  17. #define        CRIO_COUNT_32KBLOCKIN32M    1024
  18.  
  19. // max available 32k blocks
  20. #define        CRIO_MAX_32KBLOCK            8192
  21.  
  22. // size of 32k block
  23. #define        CRIO_SIZE_32KBLOCK            32768
  24.  
  25. // max directory entries
  26. #define        CRIO_MAX_DIRENTRY            60
  27.  
  28. // 32Kblock type
  29. #define        CRIO_ID_32KBLOCK_USED        0x00
  30. #define        CRIO_ID_32KBLOCK_BAD        0x0f
  31. #define        CRIO_ID_32KBLOCK_FREE        0xff
  32.  
  33. // 32 bit word
  34. #if defined(__alpha)
  35.     typedef int SIGNED32;
  36.     typedef unsigned int UNSIGNED32;
  37. #else
  38.     typedef long SIGNED32;
  39.     typedef unsigned long UNSIGNED32;
  40. #endif
  41.  
  42. // error id's
  43. enum
  44. {
  45.     CRIO_ERROR_ALLOC = 0,
  46.     CRIO_ERROR_IOPRERM,
  47.     CRIO_ERROR_CREATEFILE,
  48.     CRIO_ERROR_DEVICENOTFOUND,
  49.     CRIO_ERROR_DRIVERVERSION,
  50.     CRIO_ERROR_TXBLOCKRETRY,
  51.     CRIO_ERROR_RXBLOCKRETRY,
  52.     CRIO_ERROR_CORRUPT,
  53.     CRIO_ERROR_FILENOTFOUND,
  54.     CRIO_ERROR_INVALIDFILEPOSITION,
  55.     CRIO_ERROR_MAXDIRENTRY,
  56.     CRIO_ERROR_MEMORY,
  57.     CRIO_ERROR_OPEN,
  58.     CRIO_ERROR_STAT,
  59.     CRIO_ERROR_READ,
  60.     CRIO_ERROR_WRITE,
  61.     CRIO_ERROR_INTERRUPTED,
  62. };
  63.  
  64. ///////////////////////////////////////////////////////////////////////////////
  65. // enable byte align structs
  66. #pragma pack( 1 )
  67.  
  68. // directory header
  69. struct CDirHeader
  70. {
  71.     USHORT m_usCountEntry;
  72.     USHORT m_usCount32KBlockAvailable;
  73.     USHORT m_usCount32KBlockUsed;
  74.     USHORT m_usCount32KBlockRemaining;
  75.     USHORT m_usCount32KBlockBad;
  76.     SIGNED32 m_lTimeLastUpdate;
  77.     USHORT m_usChecksum1;
  78.     USHORT m_usChecksum2;
  79.     char m_acNotUsed2[ 2 ];
  80.     USHORT m_usVersion;
  81.     char m_acNotUsed3[ 512 - 22 ];
  82. };
  83.  
  84. // directory entry
  85. struct CDirEntry
  86. {
  87.     USHORT m_usPos32KBlock;
  88.     USHORT m_usCount32KBlock;
  89.     USHORT m_usSize32KMod;
  90.     SIGNED32 m_lSize;
  91.     char m_acNotUsed[ 5 ];
  92.     SIGNED32 m_lTimeUpload;
  93.     char m_aucProperty[ 4 ];
  94.     char m_acNotUsed3[ 5 ];
  95.     char m_szName[ 128 - 28 ];
  96. };
  97.  
  98. // directory block
  99. struct CDirBlock
  100. {
  101.     CDirHeader m_cDirHeader;
  102.     CDirEntry m_acDirEntry[ CRIO_MAX_DIRENTRY ];
  103.     UCHAR m_auc32KBlockUsed[ CRIO_MAX_32KBLOCK ];
  104.     USHORT m_ausFAT[ CRIO_MAX_32KBLOCK ];
  105. };
  106.  
  107. // end 512 byte block
  108. struct CEnd512ByteBlock
  109. {
  110.     UNSIGNED32 m_ulPos512ByteBlockNextMult256;
  111.     UCHAR m_ucPos8192KBlockNext1;
  112.     UCHAR m_ucPos8192KBlockNext2;
  113.     UNSIGNED32 m_ulPos512ByteBlockPrevMult256;
  114.     UCHAR m_ucPos8192KBlockPrev1;
  115.     UCHAR m_ucPos8192KBlockPrev2;
  116.     USHORT m_usChecksum;
  117.     USHORT m_usPos32KBlockPrevMult256;
  118. };
  119.  
  120. // disable byte align
  121. #pragma pack()
  122.  
  123. ///////////////////////////////////////////////////////////////////////////////
  124. // rio class
  125. class CRio
  126. {
  127. protected:
  128.     // directory block
  129.     CDirBlock m_cDirBlock;
  130.  
  131.     // error str
  132.     char m_szError[ 128 ];
  133.  
  134.     // external flash 32K block count
  135.     UINT m_uiCount32KBlockAvailableExternal;
  136.  
  137.     // port constants
  138.     int m_iPortBase;
  139.     int m_iPortData;
  140.     int m_iPortStatus;
  141.     int m_iPortControl;
  142.  
  143.     // error
  144.     int m_iIDError;
  145.  
  146.     // internal/external flash ram flag
  147.     BOOL m_bUseExternalFlash;
  148.  
  149.     void LogError( int iType, const char* pszFormat, ... );
  150.     UINT FindFirstFree32KBlock( void );
  151.     UINT CalculateChecksum1( void );
  152.     UINT CalculateChecksum2( void );
  153.     BOOL WaitInput( int iValue );
  154.     BOOL WaitAck( void );
  155.     UINT GetDataByte( void );
  156.     BOOL IOIntro( void );
  157.     BOOL IOOutro( void );
  158.  
  159.     BOOL Tx32KBlockRetry( void* pv, UINT uiPos32KBlock, UINT uiPos32KBlockPrev,
  160.         UINT uiPos32KBlockNext );
  161.     BOOL Tx32KBlock( void* pv, UINT uiPos32KBlock, UINT uiPos32KBlockPrev,
  162.         UINT uiPos32KBlockNext );
  163.     BOOL Rx32KBlockRetry( void* pv, UINT uiPos32KBlock );
  164.     BOOL Rx32KBlock( void* pv, UINT uiPos32KBlock );
  165.     BOOL MarkBadBlocks( BOOL (*pfProgress)(int iPos, int iCount) );
  166.  
  167. public:
  168.  
  169.     // set/unset
  170.     void Unset( void );
  171.     BOOL Set( int iPortBase );
  172.  
  173.     // constructors/destructors
  174.     CRio();
  175.     ~CRio();
  176.  
  177.     // retrieval
  178.     CDirBlock& GetDirectoryBlock( void ) { return m_cDirBlock; }
  179.     int GetErrorID( void ) { return m_iIDError; }
  180.     char* GetErrorStr( void ) { return m_szError; }
  181.     BOOL GetUseExternalFlashStatus( void ) { return m_bUseExternalFlash; }
  182.  
  183.     // operations
  184.     void UseExternalFlash( BOOL bUseExternalFlash );
  185.     BOOL CheckPresent( void );
  186.     CDirEntry* FindFile( char* pszFile );
  187.     BOOL Initialize( BOOL bMarkBadBlock, BOOL (*pfProgress)(int iPos, int iCount) );
  188.     BOOL RemoveFile( char* pszFile );
  189.     BOOL RemoveAllFiles( void );
  190.     BOOL SetFileOrder( UINT* pauiPosOrder, UINT uiCount );
  191.     BOOL TxDirectory( void );
  192.     BOOL RxDirectory( void );
  193.     BOOL TxFile( char* pszPathFile, BOOL (*pfProgress)(int iPos, int iCount) );
  194.     BOOL RxFile( char* pszPathFile, BOOL (*pfProgress)(int iPos, int iCount) );
  195. };
  196.  
  197. #endif        // _RIO_
  198.  
  199.