home *** CD-ROM | disk | FTP | other *** search
- /*
- * tasks.c
- *
- * Start floppy generate tasks
- *
- */
- #include <exec/types.h>
-
- #include <utility/tagitem.h>
- #include <dos/dostags.h>
-
- #include <clib/dos_protos.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
-
- #include <stdio.h>
- #include <string.h>
-
- #include "PufferFish.h"
-
- extern struct Library *GfxBase;
-
- /*
- * Routines to block input from:
- * AMIGA ROM Kernel Reference Manual: Libraries
- * Third Edition Copyright © 1992 by Commodore Electronics, Limited.
- * pp. 207-209
- *
- * Modified to take advantage of V39 by Peter Janes
- *
- */
-
- /*
- * Data for a busy pointer.
- * This data must be in chip memory!!!
- *
- */
- UWORD __chip waitPointer[] =
- {
- 0x0000, 0x0000, /* reserved, must be NULL */
- 0x0400, 0x07C0,
- 0x0000, 0x07C0,
- 0x0100, 0x0380,
- 0x0000, 0x07E0,
- 0x07C0, 0x1FF8,
- 0x1FF0, 0x3FEC,
- 0x3FF8, 0x7FDE,
- 0x3FF8, 0x7FBE,
- 0x7FFC, 0xFF7F,
- 0x7EFC, 0xFFFF,
- 0x7FFC, 0xFFFF,
- 0x3FF8, 0x7FFE,
- 0x3FF8, 0x7FFE,
- 0x1FF0, 0x3FFC,
- 0x07C0, 0x1FF8,
- 0x0000, 0x07E0,
- 0x0000, 0x0000 /* reserved, must be NULL */
- };
-
- /*
- * beginWait()
- *
- * Clear the requester with InitRequester. This makes a requester of
- * width = 0, height = 0, left = 0, top = 0; in fact, everything is zero.
- * This requester will simply block input to the window until EndRequest
- * is called.
- *
- * The pointer is set to a reasonable 4-colour busy pointer, with proper offsets.
- *
- * Returns TRUE if requester created, FALSE otherwise
- *
- */
- BOOL beginWait( struct Window *win, struct Requester *waitRequest )
- {
- extern UWORD __chip waitPointer[];
-
- InitRequester(waitRequest);
-
- if (Request(waitRequest, win))
- {
- if( GfxBase->lib_Version >= 39 )
- {
- SetWindowPointer( win, WA_BusyPointer, TRUE, TAG_END );
- }
- else
- {
- SetPointer(win, waitPointer, 16, 16, -6, 0);
- }
-
- return(TRUE);
- }
- else
- {
- return(FALSE);
- }
- }
-
- /*
- * endWait()
- *
- * Reset the pointer to the system default, and remove the requester
- * installed with beginWait().
- *
- */
- VOID endWait( struct Window *win, struct Requester *waitRequest )
- {
- if( GfxBase->lib_Version >= 39 )
- {
- SetWindowPointer( win, WA_BusyPointer, FALSE, TAG_END );
- }
- else
- {
- ClearPointer(win);
- }
- EndRequest(waitRequest, win);
- }
-
- /*
- * start_disk_generate()
- *
- * Starts disk generation processes and feeds them
- *
- */
- void start_disk_generate(void)
- {
- struct GFMessage *msg;
- int i;
- char diskname[32], diskpath[255], taskname[255];
- int current_disk = start_disknum, current_drive = -1, drives_in_use = 0;
- BOOL done = FALSE;
- struct Requester req;
-
- strcpy( diskname, "" );
- strcpy( diskpath, "" );
-
- // Open requester (to disable main window)
- // Should probably check return code, but I won't bother
- beginWait(win, &req);
-
- if( myPort = CreateMsgPort() )
- {
- for( i = 0; i < 5; i += 1 )
- {
- if( drives_selected & (1<<i) )
- {
- if( i < 4 )
- {
- sprintf( taskname, "DF%ld: Floppy Generator", i );
- }
- else
- {
- sprintf( taskname, "%s Floppy Generator", additional_device );
- }
- myProc[i] = CreateNewProcTags( NP_Entry, generate_disk,
- NP_Name, taskname,
- NP_StackSize, 20000,
- // NP_Cli is necessary to pass the path (created by WB2CLI) to the child tasks
- NP_Cli, TRUE,
- TAG_END );
- }
- }
- while( !done )
- {
- WaitPort( myPort );
-
- // We receive a message only when the process has finished generating
- // (or, in the first case, when it needs us to assign a drive number)
- while( msg = (struct GFMessage *)GetMsg( myPort ) )
- {
- if( msg->gf_DriveNum < 0 )
- {
- do
- {
- current_drive += 1;
- } while( !((1<<current_drive) & drives_selected ) && current_drive < 4 );
- msg->gf_DriveNum = current_drive;
- drives_in_use += 1;
- }
- else if( current_disk <= end_disknum )
- {
- if( find_disk_path( current_disk, (char **)&diskname, (char **)&diskpath ) )
- {
- // Send message to start floppy generate
- msg->gf_DiskName = diskname;
- msg->gf_DiskPath = diskpath;
- msg->gf_DiskNumber = current_disk;
- }
- else
- {
- struct EasyStruct easyStruct =
- {
- sizeof( struct EasyStruct ),
- 0,
- NULL,
- "Disk %ld: disk not found",
- "OK"
- };
-
- msg->gf_DiskNumber = 0;
- EasyRequest( win, &easyStruct, NULL, current_disk );
- }
-
- // Sorry, no retry for disks
- current_disk += 1;
- }
- else
- {
- // send quit message to process
- msg->gf_DiskNumber = lastdisk + 1;
- drives_in_use -= 1;
- if( drives_in_use == 0 )
- {
- done = TRUE;
- }
- }
- ReplyMsg( (struct Message *)msg );
- }
- }
-
- while( msg = (struct GFMessage *)GetMsg( myPort ) )
- {
- msg->gf_DiskNumber = lastdisk + 1;
- ReplyMsg( (struct Message *)msg );
- }
-
- DeleteMsgPort( myPort );
- }
- endWait(win,&req);
- }
-