home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / tools / pufferfish / source / tasks.c < prev   
C/C++ Source or Header  |  1994-03-22  |  5KB  |  230 lines

  1. /*
  2.  * tasks.c
  3.  *
  4.  * Start floppy generate tasks
  5.  *
  6.  */
  7. #include <exec/types.h>
  8.  
  9. #include <utility/tagitem.h>
  10. #include <dos/dostags.h>
  11.  
  12. #include <clib/dos_protos.h>
  13. #include <clib/exec_protos.h>
  14. #include <clib/intuition_protos.h>
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18.  
  19. #include "PufferFish.h"
  20.  
  21. extern struct Library *GfxBase;
  22.  
  23. /*
  24.  * Routines to block input from:
  25.  * AMIGA ROM Kernel Reference Manual: Libraries
  26.  * Third Edition  Copyright © 1992 by Commodore Electronics, Limited.
  27.  * pp. 207-209
  28.  *
  29.  * Modified to take advantage of V39 by Peter Janes
  30.  *
  31.  */
  32.  
  33. /*
  34.  * Data for a busy pointer.
  35.  * This data must be in chip memory!!!
  36.  *
  37.  */
  38. UWORD __chip waitPointer[] =
  39. {
  40.     0x0000, 0x0000,    /* reserved, must be NULL */
  41.     0x0400, 0x07C0,
  42.     0x0000, 0x07C0,
  43.     0x0100, 0x0380,
  44.     0x0000, 0x07E0,
  45.     0x07C0, 0x1FF8,
  46.     0x1FF0, 0x3FEC,
  47.     0x3FF8, 0x7FDE,
  48.     0x3FF8, 0x7FBE,
  49.     0x7FFC, 0xFF7F,
  50.     0x7EFC, 0xFFFF,
  51.     0x7FFC, 0xFFFF,
  52.     0x3FF8, 0x7FFE,
  53.     0x3FF8, 0x7FFE,
  54.     0x1FF0, 0x3FFC,
  55.     0x07C0, 0x1FF8,
  56.     0x0000, 0x07E0,
  57.     0x0000, 0x0000    /* reserved, must be NULL */
  58. };
  59.  
  60. /*
  61.  * beginWait()
  62.  *
  63.  * Clear the requester with InitRequester.  This makes a requester of
  64.  * width = 0, height = 0, left = 0, top = 0; in fact, everything is zero.
  65.  * This requester will simply block input to the window until EndRequest
  66.  * is called.
  67.  *
  68.  * The pointer is set to a reasonable 4-colour busy pointer, with proper offsets.
  69.  *
  70.  * Returns TRUE if requester created, FALSE otherwise
  71.  *
  72.  */
  73. BOOL beginWait( struct Window *win, struct Requester *waitRequest )
  74. {
  75.     extern UWORD __chip waitPointer[];
  76.     
  77.     InitRequester(waitRequest);
  78.     
  79.     if (Request(waitRequest, win))
  80.     {
  81.         if( GfxBase->lib_Version >= 39 )
  82.         {
  83.             SetWindowPointer( win, WA_BusyPointer, TRUE, TAG_END );
  84.         }
  85.         else
  86.         {
  87.             SetPointer(win, waitPointer, 16, 16, -6, 0);
  88.         }
  89.         
  90.         return(TRUE);
  91.     }
  92.     else
  93.     {
  94.         return(FALSE);
  95.     }
  96. }
  97.  
  98. /*
  99.  * endWait()
  100.  *
  101.  * Reset the pointer to the system default, and remove the requester
  102.  * installed with beginWait().
  103.  *
  104.  */
  105. VOID endWait( struct Window *win, struct Requester *waitRequest )
  106. {
  107.     if( GfxBase->lib_Version >= 39 )
  108.     {
  109.         SetWindowPointer( win, WA_BusyPointer, FALSE, TAG_END );
  110.     }
  111.     else
  112.     {
  113.         ClearPointer(win);
  114.     }
  115.     EndRequest(waitRequest, win);
  116. }
  117.  
  118. /*
  119.  * start_disk_generate()
  120.  *
  121.  * Starts disk generation processes and feeds them
  122.  *
  123.  */
  124. void start_disk_generate(void)
  125. {
  126.     struct GFMessage *msg;
  127.     int i;
  128.     char diskname[32], diskpath[255], taskname[255];
  129.     int current_disk = start_disknum, current_drive = -1, drives_in_use = 0;
  130.     BOOL done = FALSE;
  131.     struct Requester req;
  132.     
  133.     strcpy( diskname, "" );
  134.     strcpy( diskpath, "" );
  135.     
  136.     // Open requester (to disable main window)
  137.     // Should probably check return code, but I won't bother
  138.     beginWait(win, &req);
  139.     
  140.     if( myPort = CreateMsgPort() )
  141.     {
  142.         for( i = 0; i < 5; i += 1 )
  143.         {
  144.             if( drives_selected & (1<<i) )
  145.             {
  146.                 if( i < 4 )
  147.                 {
  148.                     sprintf( taskname, "DF%ld: Floppy Generator", i );
  149.                 }
  150.                 else
  151.                 {
  152.                     sprintf( taskname, "%s Floppy Generator", additional_device );
  153.                 }
  154.                 myProc[i] = CreateNewProcTags( NP_Entry, generate_disk,
  155.                     NP_Name, taskname,
  156.                     NP_StackSize, 20000,
  157.                     // NP_Cli is necessary to pass the path (created by WB2CLI) to the child tasks
  158.                     NP_Cli, TRUE,
  159.                     TAG_END );
  160.             }
  161.         }
  162.         while( !done )
  163.         {
  164.             WaitPort( myPort );
  165.             
  166.             // We receive a message only when the process has finished generating
  167.             // (or, in the first case, when it needs us to assign a drive number)
  168.             while( msg = (struct GFMessage *)GetMsg( myPort ) )
  169.             {
  170.                 if( msg->gf_DriveNum < 0 )
  171.                 {
  172.                     do
  173.                     {
  174.                         current_drive += 1;
  175.                     } while( !((1<<current_drive) & drives_selected ) && current_drive < 4 );
  176.                     msg->gf_DriveNum = current_drive;
  177.                     drives_in_use += 1;
  178.                 }
  179.                 else if( current_disk <= end_disknum )
  180.                 {
  181.                     if( find_disk_path( current_disk, (char **)&diskname, (char **)&diskpath ) )
  182.                     {
  183.                         // Send message to start floppy generate
  184.                         msg->gf_DiskName = diskname;
  185.                         msg->gf_DiskPath = diskpath;
  186.                         msg->gf_DiskNumber = current_disk;
  187.                     }
  188.                     else
  189.                     {
  190.                         struct EasyStruct easyStruct =
  191.                         {
  192.                             sizeof( struct EasyStruct ),
  193.                             0,
  194.                             NULL,
  195.                             "Disk %ld: disk not found",
  196.                             "OK"
  197.                         };
  198.                         
  199.                         msg->gf_DiskNumber = 0;
  200.                         EasyRequest( win, &easyStruct, NULL, current_disk );
  201.                     }
  202.                     
  203.                     // Sorry, no retry for disks
  204.                     current_disk += 1;
  205.                 }
  206.                 else
  207.                 {
  208.                     // send quit message to process
  209.                     msg->gf_DiskNumber = lastdisk + 1;
  210.                     drives_in_use -= 1;
  211.                     if( drives_in_use == 0 )
  212.                     {
  213.                         done = TRUE;
  214.                     }
  215.                 }
  216.                 ReplyMsg( (struct Message *)msg );
  217.             }
  218.         }
  219.         
  220.         while( msg = (struct GFMessage *)GetMsg( myPort ) )
  221.         {
  222.             msg->gf_DiskNumber = lastdisk + 1;
  223.             ReplyMsg( (struct Message *)msg );
  224.         }
  225.         
  226.         DeleteMsgPort( myPort );
  227.     }
  228.     endWait(win,&req);
  229. }
  230.