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

  1.  
  2. /*******************************************************************
  3.  $CRT 09 Jan 1997 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>TDChgDsk.c<<   09 Jan 1997    16:31:12 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/TDChgDsk p:pLib/StartCode.o p:/pOS_RKRM/pTrackdisk/TDChgDsk.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/Interupt.h"
  54. #include "p:pExec/Node.h"
  55. #include "p:pDOS/ArgTags.h"
  56. #include "p:pDOS/DosSig.h"
  57. #include "p:pDOS/DosErrors.h"
  58. #include "p:Device/Trackdisk.h"
  59.  
  60. #include "p:proto/pLibExt.h"
  61. #include "p:proto/pExec2.h"
  62. #include "p:proto/pDOS2.h"
  63.  
  64. #ifdef _____ME_____
  65.   #include "grund/inc_string.h"
  66.   #include "grund/inc_stdio.h"
  67. #else
  68.  #ifdef __cplusplus
  69.  extern "C" {
  70.  #endif
  71.   #include <string.h>
  72.   #include <stdio.h>
  73.  #ifdef __cplusplus
  74.  }
  75.  #endif
  76. #endif
  77.  
  78.  
  79. const CHAR *HelpText=
  80. ""
  81. ;
  82.  
  83. const CHAR *PrgHeader=
  84. "";
  85.  
  86. const CHAR *PrgVerText=
  87. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  88.  
  89.  
  90.  
  91.  
  92.  
  93. /*----------------------------------
  94. -----------------------------------*/
  95. ULONG Inter_func(_R_A0 const pOS_Interrupt* inter,_R_A1 APTR)
  96. {
  97.   pOS_SendSignal((struct pOS_Task*)inter->is_UserData[0],DOSSIGF_CTRL_F);
  98.  
  99.   return(FALSE); // *** folgende Interrupts ausfrufen
  100. }
  101.  
  102.  
  103.  
  104.  
  105. /*----------------------------------
  106. -----------------------------------*/
  107. #ifdef __cplusplus
  108. extern "C"
  109. #endif
  110.  
  111. VOID main()
  112. {
  113.   struct pOS_DosArgs* Args;
  114.   UWORD Err=0;
  115.   ULONG Ops[1]={0};
  116.  
  117.   Args=pOS_ReadDosArgs(
  118. //
  119. "UNIT/N",
  120. Ops,sizeof(Ops)/sizeof(ULONG),
  121.  
  122.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  123.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  124.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  125.     TAG_END);
  126.  
  127.   if(Args) {
  128.     pOS_MsgPort Port;
  129.     pOS_TrackdiskIO *IO;
  130.  
  131.     if(pOS_ConstructMsgPort(&Port)) {
  132.       if(IO=(pOS_TrackdiskIO*)pOS_CreateIORequest(&Port,sizeof(pOS_TrackdiskIO))) {
  133.         pOS_OpenDevice("pTrackdisk.device",Ops[0] ? *((ULONG*)Ops[0]):0,
  134.                        (pOS_IORequest*)IO,0,0);
  135.         if(IO->tdio_Error==0) {
  136.           pOS_Interrupt Inter;
  137.  
  138.           Inter.is_Node.ln_Succ=NULL;
  139.           Inter.is_Node.ln_Pred=NULL;
  140.           Inter.is_Node.ln_Type=NTYP_INTERRUPT;
  141.           Inter.is_Node.ln_Name="Disk-Change-Test";
  142.           Inter.is_Node.ln_Pri=0;
  143.           Inter.is_Code=Inter_func;
  144.           Inter.is_UserData[0]=(ULONG)pOS_FindTask(0);
  145.  
  146.           IO->tdio_Command=TDCMD_AddChangeInt;
  147.           IO->tdio_Data    =&Inter;
  148.           IO->tdio_Length  =sizeof(Inter);
  149.           pOS_DoIO((pOS_IORequest*)IO);
  150.           if(IO->tdio_Error==0) {
  151.             ULONG Sigs;
  152.  
  153.             printf("Disk-Change Handler installed. (Ctrl-C for abort)\n");
  154.             do {
  155.               Sigs=pOS_WaitSignal(DOSSIGF_CTRL_C | DOSSIGF_CTRL_F);
  156.               if(Sigs & DOSSIGF_CTRL_F) {
  157.                 printf("Disk-Change\n");
  158.               }
  159.             } while( !(Sigs & DOSSIGF_CTRL_C));
  160.  
  161.             IO->tdio_Command=TDCMD_RemChangeInt;
  162.             IO->tdio_Data    =&Inter;
  163.             IO->tdio_Length  =sizeof(Inter);
  164.             pOS_DoIO((pOS_IORequest*)IO);
  165.           }
  166.           else printf("TDCMD_AddChangeInt failed, error=%ld\n",IO->tdio_Error);
  167.  
  168.           pOS_CloseDevice((pOS_IORequest*)IO);
  169.         }
  170.         else printf("pOS_OpenDevice failed, error=%ld\n",IO->tdio_Error);
  171.         pOS_DeleteIORequest((pOS_IORequest*)IO);
  172.       }
  173.       else printf("pOS_CreateIORequest failed\n");
  174.       pOS_DestructMsgPort(&Port);
  175.     }
  176.     else printf("pOS_ConstructMsgPort failed\n");
  177.  
  178.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  179.   }
  180.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  181.  
  182.   pOS_SetShellFail(Err);
  183. }
  184.