home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pTrackdisk / TDRead.c < prev   
Encoding:
C/C++ Source or Header  |  1997-03-18  |  5.5 KB  |  199 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 27 Dec 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>TDRead.c<<   15 Jan 1997    10:58:30 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/TDRead p:pLib/StartCode.o p:/pOS_RKRM/pTrackdisk/TDRead.c p:pLib/StdIO.o -l pOSStub -l pOS
  10.  
  11. /***********************************************************
  12.   pOS programing example - Copyright (C) 1995-97 proDAD
  13.  
  14.   This code was written as an easy to understand example,
  15.   how to program pOS features. It is provided 'as-is',
  16.   without any express or implied warranty.
  17.  
  18.   Permission is hereby granted to use, copy and modify
  19.   this source code for any purpose, without fee, subject
  20.   to the following conditions:
  21.  
  22.     (1) This notice may not be removed or altered from any
  23.         source distribution.
  24.  
  25.     (2) Altered source versions must be plainly marked as
  26.         such, and must not be misrepresented as being
  27.         the original source code.
  28.  
  29.     (3) If only executable code is distributed, then the
  30.         accompanying documentation have to state that
  31.         "this software is based in part on examples of
  32.         the pOS developer packet".
  33.  
  34.     (4) Permission for use of this code is granted only
  35.         if the user accepts full responsibility for any
  36.         undesirable consequences. proDAD accept NO LIABILITY
  37.         for damages of any kind.
  38.  
  39.   ©proDAD
  40. ***********************************************************/
  41.  
  42. /*\
  43. *** Example:
  44. ***
  45. \*/
  46.  
  47.  
  48. #define __COMPUTER_AMIGA 1
  49. #define NOMYDEBUG
  50.  
  51. #include "p:pExec/Types.h"
  52. #include "p:pExec/MsgPort.h"
  53. #include "p:pExec/Memory.h"
  54. #include "p:pDOS/ArgTags.h"
  55. #include "p:pDOS/DosSig.h"
  56. #include "p:pDOS/DosErrors.h"
  57. #include "p:Device/Trackdisk.h"
  58.  
  59. #include "p:proto/pLibExt.h"
  60. #include "p:proto/pExec2.h"
  61. #include "p:proto/pDOS2.h"
  62.  
  63. #ifdef _____ME_____
  64.   #include "grund/inc_string.h"
  65.   #include "grund/inc_stdio.h"
  66. #else
  67.  #ifdef __cplusplus
  68.  extern "C" {
  69.  #endif
  70.   #include <string.h>
  71.   #include <stdio.h>
  72.  #ifdef __cplusplus
  73.  }
  74.  #endif
  75. #endif
  76.  
  77.  
  78. const CHAR *HelpText=
  79. ""
  80. ;
  81.  
  82. const CHAR *PrgHeader=
  83. "";
  84.  
  85. const CHAR *PrgVerText=
  86. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  87.  
  88.  
  89.  
  90. /*----------------------------------
  91. -----------------------------------*/
  92. CHAR *MakeAscii(CHAR* string,size_t size,const UBYTE *line)
  93. {
  94.   for(;size>0; --size,++string,++line) {
  95.     if(*line>=32 && *line<=126) *string=*line;
  96.     else                        *string='.';
  97.   }
  98.   return(string);
  99. }
  100.  
  101. /*----------------------------------
  102. -----------------------------------*/
  103. VOID PrintHex(const UBYTE* buf,size_t size)
  104. {
  105.   CHAR String[82];
  106.   CHAR *Str;
  107.   ULONG Offset;
  108.  
  109.   for(Offset=0; (SLONG)size>0; size-=16,Offset+=16,buf+=16) {
  110.     Str=pOS_SPrintf(String,"%04lx:",Offset);
  111.     Str=pOS_SPrintf(Str,"%.16lh ",buf);
  112.     Str=MakeAscii(Str,16,buf);
  113.     *Str++='\n'; *Str='\0';
  114.     printf(String);
  115.   }
  116. }
  117.  
  118.  
  119. /*----------------------------------
  120. -----------------------------------*/
  121. #ifdef __cplusplus
  122. extern "C"
  123. #endif
  124.  
  125. VOID main()
  126. {
  127.   struct pOS_DosArgs* Args;
  128.   UWORD Err=0;
  129.   ULONG Ops[3]={0,0,(ULONG)"pTrackdisk.device"};
  130.  
  131.   Args=pOS_ReadDosArgs(
  132. //
  133. "S=SECTOR/N/A, UNIT/N, DEVICE",
  134. Ops,sizeof(Ops)/sizeof(ULONG),
  135.  
  136.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  137.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  138.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  139.     TAG_END);
  140.  
  141.   if(Args) {
  142.     pOS_MsgPort Port;
  143.     pOS_TrackdiskIO *IO;
  144.     ULONG Sector=Ops[0] ? *((ULONG*)Ops[0]) : 0;
  145.     ULONG Unit  =Ops[1] ? *((ULONG*)Ops[1]) : 0;
  146.  
  147.     if(pOS_ConstructMsgPort(&Port)) {
  148.       if(IO=(pOS_TrackdiskIO*)pOS_CreateIORequest(&Port,sizeof(pOS_TrackdiskIO))) {
  149.         pOS_OpenDevice((CHAR*)Ops[2],Unit,(pOS_IORequest*)IO,0,0);
  150.         if(IO->tdio_Error==0) {
  151.           pOS_DriveGeometry Geom;
  152.           memset(&Geom,0,sizeof(pOS_DriveGeometry));
  153.  
  154.           IO->tdio_Command=TDCMD_GetGeometry;
  155.           IO->tdio_Data    =&Geom;
  156.           IO->tdio_Length  =sizeof(pOS_DriveGeometry);
  157.           pOS_DoIO((pOS_IORequest*)IO);
  158.           if(IO->tdio_Error!=0) Geom.dg_SectorSize=512;
  159.           {
  160.             APTR Buf;
  161.             Buf=pOS_AllocMem(Geom.dg_SectorSize,MEMF_PUBLIC);
  162.             if(Buf) {
  163.               IO->tdio_Command=CMD_READ;
  164.               IO->tdio_Data    =Buf;
  165.               IO->tdio_Length  =Geom.dg_SectorSize;
  166.               IO->tdio_LOffset =Geom.dg_SectorSize*Sector;
  167.               pOS_DoIO((pOS_IORequest*)IO);
  168.               if(IO->tdio_Error==0) {
  169.                 printf("Dump of Sector %ld [0x%lx],  Size=%ld\n",Sector,Sector,Geom.dg_SectorSize);
  170.                 PrintHex((UBYTE*)Buf,Geom.dg_SectorSize);
  171.               }
  172.               else printf("CMD_READ failed, error=%ld\n",IO->tdio_Error);
  173.  
  174.               IO->tdio_Command=TDCMD_Motor;
  175.               IO->tdio_Length  =0;
  176.               pOS_DoIO((pOS_IORequest*)IO);
  177.  
  178.               pOS_FreeMem(Buf,Geom.dg_SectorSize);
  179.             }
  180.             else printf("Cannot alloc memory, size=%ld\n",Geom.dg_SectorSize);
  181.           }
  182.  
  183.           pOS_CloseDevice((pOS_IORequest*)IO);
  184.         }
  185.         else printf("pOS_OpenDevice <%s> failed, error=%ld\n",Ops[2],IO->tdio_Error);
  186.         pOS_DeleteIORequest((pOS_IORequest*)IO);
  187.       }
  188.       else printf("pOS_CreateIORequest failed\n");
  189.       pOS_DestructMsgPort(&Port);
  190.     }
  191.     else printf("pOS_ConstructMsgPort failed\n");
  192.  
  193.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  194.   }
  195.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  196.  
  197.   pOS_SetShellFail(Err);
  198. }
  199.