home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 27 Dec 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>TDRead.c<< 15 Jan 1997 10:58:30 - (C) ProDAD
- *******************************************************************/
-
- //##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
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
- /*\
- *** Example:
- ***
- \*/
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:pExec/MsgPort.h"
- #include "p:pExec/Memory.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:Device/Trackdisk.h"
-
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_stdio.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
-
-
-
- /*----------------------------------
- -----------------------------------*/
- CHAR *MakeAscii(CHAR* string,size_t size,const UBYTE *line)
- {
- for(;size>0; --size,++string,++line) {
- if(*line>=32 && *line<=126) *string=*line;
- else *string='.';
- }
- return(string);
- }
-
- /*----------------------------------
- -----------------------------------*/
- VOID PrintHex(const UBYTE* buf,size_t size)
- {
- CHAR String[82];
- CHAR *Str;
- ULONG Offset;
-
- for(Offset=0; (SLONG)size>0; size-=16,Offset+=16,buf+=16) {
- Str=pOS_SPrintf(String,"%04lx:",Offset);
- Str=pOS_SPrintf(Str,"%.16lh ",buf);
- Str=MakeAscii(Str,16,buf);
- *Str++='\n'; *Str='\0';
- printf(String);
- }
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Ops[3]={0,0,(ULONG)"pTrackdisk.device"};
-
- Args=pOS_ReadDosArgs(
- //
- "S=SECTOR/N/A, UNIT/N, DEVICE",
- Ops,sizeof(Ops)/sizeof(ULONG),
-
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- TAG_END);
-
- if(Args) {
- pOS_MsgPort Port;
- pOS_TrackdiskIO *IO;
- ULONG Sector=Ops[0] ? *((ULONG*)Ops[0]) : 0;
- ULONG Unit =Ops[1] ? *((ULONG*)Ops[1]) : 0;
-
- if(pOS_ConstructMsgPort(&Port)) {
- if(IO=(pOS_TrackdiskIO*)pOS_CreateIORequest(&Port,sizeof(pOS_TrackdiskIO))) {
- pOS_OpenDevice((CHAR*)Ops[2],Unit,(pOS_IORequest*)IO,0,0);
- if(IO->tdio_Error==0) {
- pOS_DriveGeometry Geom;
- memset(&Geom,0,sizeof(pOS_DriveGeometry));
-
- IO->tdio_Command=TDCMD_GetGeometry;
- IO->tdio_Data =&Geom;
- IO->tdio_Length =sizeof(pOS_DriveGeometry);
- pOS_DoIO((pOS_IORequest*)IO);
- if(IO->tdio_Error!=0) Geom.dg_SectorSize=512;
- {
- APTR Buf;
- Buf=pOS_AllocMem(Geom.dg_SectorSize,MEMF_PUBLIC);
- if(Buf) {
- IO->tdio_Command=CMD_READ;
- IO->tdio_Data =Buf;
- IO->tdio_Length =Geom.dg_SectorSize;
- IO->tdio_LOffset =Geom.dg_SectorSize*Sector;
- pOS_DoIO((pOS_IORequest*)IO);
- if(IO->tdio_Error==0) {
- printf("Dump of Sector %ld [0x%lx], Size=%ld\n",Sector,Sector,Geom.dg_SectorSize);
- PrintHex((UBYTE*)Buf,Geom.dg_SectorSize);
- }
- else printf("CMD_READ failed, error=%ld\n",IO->tdio_Error);
-
- IO->tdio_Command=TDCMD_Motor;
- IO->tdio_Length =0;
- pOS_DoIO((pOS_IORequest*)IO);
-
- pOS_FreeMem(Buf,Geom.dg_SectorSize);
- }
- else printf("Cannot alloc memory, size=%ld\n",Geom.dg_SectorSize);
- }
-
- pOS_CloseDevice((pOS_IORequest*)IO);
- }
- else printf("pOS_OpenDevice <%s> failed, error=%ld\n",Ops[2],IO->tdio_Error);
- pOS_DeleteIORequest((pOS_IORequest*)IO);
- }
- else printf("pOS_CreateIORequest failed\n");
- pOS_DestructMsgPort(&Port);
- }
- else printf("pOS_ConstructMsgPort failed\n");
-
- pOS_DeleteDosArgs(Args); /* Args freigeben */
- }
- else Err=DOSFAIL_FAIL; /* vollkommen fehlgeschlagen */
-
- pOS_SetShellFail(Err);
- }
-