home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************/
- /* */
- /* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
- /* ------------------------------- ------------------ */
- /* */
- /* Book: ACM Devices Amiga C Club */
- /* Chapter: Trackdisk Device Tulevagen 22 */
- /* File: Example2.c 181 41 LIDINGO */
- /* Author: Anders Bjerin SWEDEN */
- /* Date: 92-04-27 */
- /* Version: 1.00 */
- /* */
- /* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
- /* */
- /* Registered members may use this program freely in their */
- /* own commercial/noncommercial programs/articles. */
- /* */
- /***********************************************************/
-
-
-
- /* This program demonstrates how you can check what went */
- /* wrong while you were using the Trackdisk Device. This */
- /* example will try to use drive DF3:, which most of us */
- /* does not have, and thus we will receive an error */
- /* message. (Well if you have four diskdrives connected */
- /* to your Amiga there will not be any error message.) */
-
-
-
- #include <exec/types.h> /* STRPTR */
- #include <exec/ports.h> /* struct Message */
- #include <exec/nodes.h> /* NT_MESSAGE */
- #include <exec/errors.h> /* IO Error */
- #include <devices/trackdisk.h> /* Trackdisk Device */
-
-
-
- /* Diskdrive: */
- #define DF0 0
- #define DF1 1
- #define DF2 2
- #define DF3 3
-
-
-
- /* Declare a pointer to our reply port: */
- struct MsgPort *replymp;
-
- /* Declare a pointer to a IOStdReq structure: */
- /* (We do not use the extended IOExtTD structure.) */
- struct IOStdReq *req;
-
- /* Store error messages in this: */
- BYTE error = TRUE;
-
-
-
- /* Declare our functions: */
- void main();
- void clean_up( STRPTR text );
- void TrackdiskError( BYTE error );
-
-
-
- void main()
- {
- /* Get a reply port: */
- replymp = (struct MsgPort *)
- CreatePort( NULL, 0 );
- if( !replymp )
- clean_up( "Could not create the reply port!" );
-
-
- /* Create an IOStdReq structure: */
- req = (struct IOStdReq *)
- CreateStdIO( replymp );
- if( !req )
- clean_up( "Could not create the IO!" );
-
-
- /* Try to open the Trackdisk Device, unit DF3: */
- error = OpenDevice( TD_NAME, DF3, req, 0 );
- if( error )
- {
- /* Tell the user what went wrong: */
- TrackdiskError( error );
-
- /* Clean up and quit: */
- clean_up( "Could not open the Trackdisk Device!" );
- }
-
-
-
- /* Well, err... it is a stupid example... */
-
-
-
- /* Clean up and quit: */
- clean_up( "The End!" );
- }
-
-
-
- /* Close and return everything that has been */
- /* opened and allocated before we quit: */
-
- void clean_up( STRPTR text )
- {
- /* Close the Trackdisk Device: */
- if( !error )
- CloseDevice( req );
-
- /* Delete the IOStdReq structure: */
- if( req )
- DeleteStdIO( req, sizeof( struct IOStdReq ) );
-
- /* Remove the replyport: */
- if( replymp )
- DeletePort( replymp);
-
- /* Print the message: */
- printf( "%s\n", text );
-
- /* Quit: */
- exit( 0 );
- }
-
-
-
- /* TrackdiskError() will give the user some more information */
- /* about the error. */
- /* */
- /* Synopsis: TrackdiskError( error ); */
- /* */
- /* error: (BYTE) Give this function the error value, and */
- /* it will give the user some more information */
- /* about the error. */
-
- void TrackdiskError( BYTE error )
- {
- /* The complete list of possible errors: */
- switch( error )
- {
- case TDERR_NotSpecified:
- printf( "Something, we do not know what, failed!\n" );
- break;
-
- case TDERR_NoSecHdr:
- printf( "Could not find a sector!\n" );
- break;
-
- case TDERR_BadSecPreamble:
- printf( "The sector is corrupted!\n" );
- break;
-
- case TDERR_BadSecID:
- printf( "Problems with identifying the sector!\n" );
- break;
-
- case TDERR_BadHdrSum:
- printf( "The header had incorrect checksum!\n" );
- break;
-
- case TDERR_BadSecSum:
- printf( "The sector had incorrect checksum!\n" );
- break;
-
- case TDERR_TooFewSecs:
- printf( "There are too few sectors!\n" );
- break;
-
- case TDERR_BadSecHdr:
- printf( "The sector's header is corrupted!\n" );
- break;
-
- case TDERR_WriteProt:
- printf( "The disk is write protected!\n" );
- break;
-
- case TDERR_DiskChanged:
- printf( "The user removed the disk!\n" );
- break;
-
- case TDERR_SeekError:
- printf( "Could not find track 0!\n" );
- break;
-
- case TDERR_NoMem:
- printf( "Not enough memory!\n" );
- break;
-
- case TDERR_BadUnitNum:
- printf( "Requested diskdrive does not exist!\n" );
- break;
-
- case TDERR_BadDriveType:
- printf( "The Trackdisk Device can not handle that diskdrive!\n" );
- break;
-
- case TDERR_DriveInUse:
- printf( "The requested diskdrive is already used by someone else!\n" );
- break;
-
- case TDERR_PostReset:
- printf( "Oh no! The user hit the reset buttons, we are going down!\n" );
- break;
-
-
- /* The standard device errors: */
-
- case IOERR_OPENFAIL:
- printf( "Could not open the device!\n" );
- break;
-
- case IOERR_ABORTED:
- printf( "The request was aborted!\n" );
- break;
-
- case IOERR_NOCMD:
- printf( "Not a valid command! Not supported by the trackdisk device!\n" );
- break;
-
- case IOERR_BADLENGTH:
- printf( "Bad length or value!\n" );
- break;
-
- default:
- /* Unknown error value: */
- printf( "What? Unknown error code!\n" );
- }
- }
-
-
-