home *** CD-ROM | disk | FTP | other *** search
- /*
- * FDEMO.C Version 2.31
- *
- * FILEdemo module. Contains code to demonstrate use of smx with smxFile.
- *
- * Copyright (c) 1993 Micro Digital Associates, Inc.
- * All Rights Reserved.
- *
- * Author: Peter Van Oudenaren
- *
- ***********************************************************************/
-
- #define SMX_HEAPS 1
-
- #include "conf.h"
- #include "core.h"
- #include "xmwin.h"
- #include "fdemo.h"
- #include <xfile.h> /* Also brings in fconf.h */
- #include <stdio.h> /* Included only for the dos test in xfd_read_test_main */
- #include <fcntl.h> /* Included only for the dos test in xfd_read_test_main */
- //#include <io.h> /* Included only for the dos test in xfd_read_test_main */
- #include <conio.h> /* For prototype of inp and outp */
- #include <time.h>
-
- /* function prototypes */
-
- #if __cplusplus
- extern "C" {
- #endif
-
- /* demo tasks */
- void _cdecl xfd_cscan_main(void);
- void _cdecl xfd_seek_test_main(void);
- void _cdecl xfd_read_test_main(void);
- void _cdecl xfd_write_test_main(void);
- void _cdecl xfd_ascan_main(void);
- void _cdecl xfd_prompt_main(void);
-
- /* demo task helpers */
- void mkname(char *buffer, DSTAT *pstat);
- void xfd_write_status(int line, char *message);
- void xfd_write_purge(char *subdir);
- BOOL xfd_write_rmdir(char *subdir);
- void xfd_write_make_files(char *subdir);
- void xfd_write_rename_files(char *subdir);
- BOOLEAN ram_disk_init(void);
- void prompt(int goto_sleep,char *p0, char *p1,char *p2, char *p3, char *p4);
- void draw_title(XMWIN_PTR win, char * title, char * buffer);
-
- /* control functions */
- void _cdecl opcon_main(void);
- void create_demo_menu(void);
- void command_dispatch(int command);
- void set_devtable(void);
- void fdemo_suspend_me(int do_signal);
- void _cdecl xfd_error(char *p);
-
- /* miscellaneous */
- void _cdecl appl_init(void);
- char * _cdecl ltoa(long, char *, int);
- void _cdecl quit_appl(void);
- extern int rand();
- void _cdecl show_etime(void);
- void swap_screen(void);
-
- #if __cplusplus
- }
- #endif
-
- /* variables */
-
- unsigned char FGCOLOR;
- unsigned char BGCOLOR;
- unsigned char MENU_FG;
- unsigned char MENU_BG;
- unsigned char MENU_GREYED_FG;
- unsigned char MENU_GREYED_BG;
- unsigned char MENU_HIGH_FG;
- unsigned char MENU_HIGH_BG;
-
- /* Room to control 10 tasks increase it if needed */
- #define MAXDEMOTASKS 5
- typedef struct _demo_control {
- TCB_PTR p_task; /* Task handle */
- char *pause_menu; /* Menu strings */
- char *resume_menu;
- XMWIN_PTR window;
- /* Flags. Add to these as we need them */
- word suspended;
- } _DEMO_CONTROL;
- _DEMO_CONTROL demo_control[MAXDEMOTASKS];
- /* Indeces into the above table */
- #define DEMO_TASK_CSCAN 0
- #define DEMO_TASK_SEEK 1
- #define DEMO_TASK_READ 2
- #define DEMO_TASK_WRITE 3
- #define DEMO_TASK_ASCAN 4
-
- XCB_PTR free_msgs;
-
- /* Tasks for the demo */
- TCB_PTR opcon; /* operation control task (for kbd) */
- TCB_PTR xfd_cscan_tcb; /* Scans the c drive */
- TCB_PTR xfd_seek_tcb; /* Seeks and reads a file on the c drive */
- TCB_PTR xfd_read_tcb; /* Fast reads a file on the c drive */
- TCB_PTR xfd_write_tcb; /* creates/removes files and dirs on a: or ramdisk */
- TCB_PTR xfd_ascan_tcb; /* Scans the a or ram disk */
- TCB_PTR xfd_prompt_tcb; /* Prints friendly mesages */
-
- TCB_PTR suspend_this_task; /* If true this task should be suspend next time it
- exits and unlocks the screen. */
-
- /* Windows */
- XMWIN_PTR xfd_appl_win = 0;
- XMWIN_PTR xfd_cscan_win = 0;
- XMWIN_PTR xfd_seek_win = 0;
- XMWIN_PTR xfd_read_win = 0;
- XMWIN_PTR xfd_write_win = 0;
- XMWIN_PTR xfd_ascan_win = 0;
- XMWIN_PTR xfd_prompt_win = 0;
-
- /* Window titles */
- char * xfd_cscan_df_title = "SCANNING HARD DRIVE";
- char * xfd_seek_df_title = "SEEK & READ ";
- char * xfd_read_df_title = "SEQ. READS/10K BUFFER - Suspend other Tasks For Speed";
- char * xfd_write_df_title = "FLOPPY WRITE ";
- char * xfd_ascan_df_title = "SCANNING FLOPPY ";
-
- /* User help */
- unsigned char * non_menu_u_prompt = "esc to Exit, F1, F2, F3 for menus ";
- /* 030 et all are arrow chars */
- unsigned char * menu_u_prompt = "\030 \031 \032 \032 Move, ^cr selects, esc cancels";
-
- /* Colors */
-
- /* Disk info */
- char *hd_drive_id = "C:";
- char *fd_drive_id = "A:";
-
- static char largest_f_path[EMAXPATH];
- unsigned long largest_f_size;
-
- /* DEBUGGING AIDS
- These can be sent on the command line */
- /* If true use semaphores to control access to the file system otherwise
- use process locks */
- BOOLEAN use_fs_sem = FALSE;
- /* If this is true we copy the bios entry points in to the devtable */
- BOOLEAN use_ebs_dev = FALSE;
- BOOLEAN force_mono = FALSE;
- BOOLEAN force_color = FALSE;
-
- /* Control objects */
- ECB_PTR first_scan_done;
- ECB_PTR suspend_completed;
- ECB_PTR go_event;
-
-
- /* externals */
- extern PXCB_PTR kbd_pipe; /* pipe used by keyin() */
- extern PXCB_PTR op_pipe; /* operation input pipe */
-
-
- /* Demo Menus */
- #define NMEN 3
- SUB_MENU menus[NMEN];
- /* Exprot this to the menu package in xmwin.c */
- int n_sub_menus = NMEN;
-
- /* Pause and resume. commands. The task is encoded */
- #define CMD_PAUSE_CSCAN (0x10|DEMO_TASK_CSCAN)
- #define CMD_RESUME_CSCAN (0x20|DEMO_TASK_CSCAN)
- #define CMD_PAUSE_SEEK (0x10|DEMO_TASK_SEEK)
- #define CMD_RESUME_SEEK (0x20|DEMO_TASK_SEEK)
- #define CMD_PAUSE_READ (0x10|DEMO_TASK_READ)
- #define CMD_RESUME_READ (0x20|DEMO_TASK_READ)
- #define CMD_PAUSE_WRITE (0x10|DEMO_TASK_WRITE)
- #define CMD_RESUME_WRITE (0x20|DEMO_TASK_WRITE)
- #define CMD_PAUSE_ASCAN (0x10|DEMO_TASK_ASCAN)
- #define CMD_RESUME_ASCAN (0x20|DEMO_TASK_ASCAN)
- #define CMD_USE_DOS 0x02
- #define CMD_USE_D 0x03
- #define CMD_USE_B 0x04
- #define CMD_USE_RD 0x05
- #define CMD_QUIT 0x06
- #define CMD_GO 0x07
-
- /* For debugging */
- void say(char * string) /* __fn__ */
- {
- wr_dbstring(1, 1, FGCOLOR, BGCOLOR, string);
- /* suspend(ct, 36); */
- }
- void say_2(char * string) /* __fn__ */
- {
- wr_dbstring(40, 1, FGCOLOR, BGCOLOR, string);
- /* suspend(ct, 36); */
- }
-
- /***** APPLICATION INITIALIZATION
- *
- * Creates all tasks and initialzes the windowing system
- *
- **********************************************************************/
-
- void _cdecl appl_init() /* __fn__ */
- {
- unsigned char buf[2];
- unsigned char video;
- extern BOOLEAN monochrome;
-
- /* If the video memory recognizer has trouble the user may specify M or C
- from the command line */
- if (force_mono)
- op_screen = (word far *)MDA;
- else if (force_color)
- op_screen = (word far *)CGA;
-
- /* Get the video adaptor from CMOS location 0x14 bits 4&5. 0x11 ==s monochrome */
- outp(0x70,0x14|0x80);
- video = inp(0x71);
-
- if ((video & 0x30) == 0x30)
- {
- monochrome = TRUE;
- FGCOLOR = MO_FGCOLOR;
- BGCOLOR = MO_BGCOLOR;
- MENU_FG = MO_MENU_FG;
- MENU_BG = MO_MENU_BG;
- MENU_GREYED_FG = MO_MENU_GREYED_FG;
- MENU_GREYED_BG = MO_MENU_GREYED_BG;
- MENU_HIGH_FG = MO_MENU_HIGH_FG;
- MENU_HIGH_BG = MO_MENU_HIGH_BG;
- }
- else
- {
- FGCOLOR = CO_FGCOLOR;
- BGCOLOR = CO_BGCOLOR;
- MENU_FG = CO_MENU_FG;
- MENU_BG = CO_MENU_BG;
- MENU_GREYED_FG = CO_MENU_GREYED_FG;
- MENU_GREYED_BG = CO_MENU_GREYED_BG;
- MENU_HIGH_FG = CO_MENU_HIGH_FG;
- MENU_HIGH_BG = CO_MENU_HIGH_BG;
- }
-
- #if (EBS_IDE && EBS_FLOPPY)
- /* Debugging aid. Use the drivers instead of bios */
- if (use_ebs_dev)
- {
- set_devtable();
- }
- #endif
-
- #ifdef CODEVIEW
- opcon = create_task(opcon_main, 0, 0);
- #else
- opcon = create_task(opcon_main, MAX, 0);
- #endif
-
- /* fdemo specific application initialization */
-
- /* xfile needs stime to be set properly so it can date stamp files.
- in this demo we call DOS's time function. to set it */
- _disable();
- time((time_t *) &stime);
- _enable();
-
- /* Create the video windoows for the demo */
- xfd_appl_win = xmwin_create( 0, 1, 80, 24, FGCOLOR, BGCOLOR, XWS_BORDER_DOUBLE|XWS_SAVE_UNDER);
- xfd_prompt_win = xmwin_create(0, 1, 58, 7, FGCOLOR, BGCOLOR, XWS_BORDER_DOUBLE);
- /* Fix the corner where the two windows intersect */
- buf[0] = 204; buf[1] = 0; wr_ustring(0, 7, FGCOLOR, BGCOLOR,buf);
- xfd_cscan_win = xmwin_create( 1, 8, 56, 4, FGCOLOR, BGCOLOR, XWS_BORDER_SINGLE);
- xfd_seek_win = xmwin_create( 1, 12, 56, 4, FGCOLOR, BGCOLOR, XWS_BORDER_SINGLE);
- xfd_read_win = xmwin_create( 1, 16, 56, 4, FGCOLOR, BGCOLOR, XWS_BORDER_SINGLE);
- xfd_write_win = xmwin_create( 1, 20, 56, 4, FGCOLOR, BGCOLOR, XWS_BORDER_SINGLE);
- xfd_ascan_win = xmwin_create(58, 2, 21, 22, FGCOLOR, BGCOLOR, XWS_BORDER_SINGLE);
-
- /* Put up a prompt at the bottom of the screen */
- wr_ustring(1, 24, FGCOLOR, BGCOLOR,non_menu_u_prompt);
-
- /* Create event queues we will use to control our tasks */
- first_scan_done = create_eq(); /* After the first scan of winchester */
- suspend_completed = create_eq(); /* Signal by task when it suspends */
- go_event = create_eq(); /* Signal when user presses Run Demos */
-
- #define PRIO NORM
- /* Create demo tasks */
- xfd_cscan_tcb = create_task(xfd_cscan_main, PRIO, 0);
- xfd_seek_tcb = create_task(xfd_seek_test_main, PRIO, 0);
- xfd_read_tcb = create_task(xfd_read_test_main, PRIO, 0);
- xfd_write_tcb = create_task(xfd_write_test_main, PRIO, 0);
- xfd_ascan_tcb = create_task(xfd_ascan_main, PRIO, 0);
- xfd_prompt_tcb = create_task(xfd_prompt_main, PRIO, 0);
-
- /* Tasks */
- demo_control[DEMO_TASK_CSCAN].p_task = xfd_cscan_tcb;
- demo_control[DEMO_TASK_SEEK].p_task = xfd_seek_tcb;
- demo_control[DEMO_TASK_READ].p_task = xfd_read_tcb;
- demo_control[DEMO_TASK_WRITE].p_task = xfd_write_tcb;
- demo_control[DEMO_TASK_ASCAN].p_task = xfd_ascan_tcb;
-
- /* Windows */
- demo_control[DEMO_TASK_CSCAN].window = xfd_cscan_win;
- demo_control[DEMO_TASK_SEEK].window = xfd_seek_win;
- demo_control[DEMO_TASK_READ].window = xfd_read_win;
- demo_control[DEMO_TASK_WRITE].window = xfd_write_win;
- demo_control[DEMO_TASK_ASCAN].window = xfd_ascan_win;
-
- /* Task menu when running */
- demo_control[DEMO_TASK_CSCAN].pause_menu = "Pause C Scan";
- demo_control[DEMO_TASK_SEEK].pause_menu = "Pause Seek Test";
- demo_control[DEMO_TASK_READ].pause_menu = "Pause Read Test";
- demo_control[DEMO_TASK_WRITE].pause_menu = "Pause Write Test";
- demo_control[DEMO_TASK_ASCAN].pause_menu = "Pause A Scan";
-
- /* Task menu when paused */
- demo_control[DEMO_TASK_CSCAN].resume_menu = "Resume C Scan";
- demo_control[DEMO_TASK_SEEK].resume_menu = "Resume Seek Test";
- demo_control[DEMO_TASK_READ].resume_menu = "Resume Read Test";
- demo_control[DEMO_TASK_WRITE].resume_menu = "Resume Write Test";
- demo_control[DEMO_TASK_ASCAN].resume_menu = "Resume A Scan";
-
-
- /* Smx probe task names */
- BUILD_HT(opcon, "opcon");
- BUILD_HT(xfd_cscan_tcb,"xfd_cscan_tcb");
- BUILD_HT(xfd_seek_tcb,"xfd_seek_tcb");
- BUILD_HT(xfd_read_tcb,"xfd_read_tcb");
- BUILD_HT(xfd_write_tcb,"xfd_write_tcb");
- BUILD_HT(xfd_ascan_tcb,"xfd_ascan_tcb");
-
- /* Pop up the top menu */
- create_demo_menu();
- start(opcon);
- start(xfd_cscan_tcb);
- start(xfd_seek_tcb);
- start(xfd_write_tcb);
- start(xfd_read_tcb);
- start(xfd_ascan_tcb);
- start(xfd_prompt_tcb);
- }
-
- /***** SUBROUTINES
- *
- **********************************************************************/
-
- /* DEMO Main Tasks */
-
- /* xfd_cscan_main - Walk the file tree
- *
- * This routine walks the directory tree of the file system on the hard disk
- * and displays each directory and file as it is encountered.
- * It is a bit complicated because it uses its own stack for the traversal.
- * Doing this is safer then writing the routine recurively (which would
- * be simpler). During its first scan it finds the largest file on the system.
- * After the first scan it signals those routines that need to know the largest
- * file. The routine is large but for demo purposes I did not want to break it
- * up into lots of little routines.
- * See pcls.c in the samples directory for similar information.
- * xfile calls demonstrated:
- *
- * create_file_mgr()
- * pc_dskopen()
- * pc_set_default_drive()
- * pc_set_cwd()
- * pc_gfirst()
- * pc_gnext()
- * pc_gdone()
- */
- static char cscan_stack[30][13];
- BOOLEAN find_largest;
-
- void _cdecl xfd_cscan_main(void) /* __fn__ */
- {
- static char display_buffer[80];
- static char path[EMAXPATH];
- char fname_buffer[14];
- DSTAT statobj;
- int i,stackp, path_len;
- BOOLEAN found_dir;
- BOOLEAN display_files;
-
-
- unlock();
-
- draw_title(xfd_cscan_win, xfd_cscan_df_title, display_buffer);
- xmwin_wr_string(xfd_cscan_win, 2, 1, FGCOLOR, BGCOLOR, "Dir :");
- xmwin_wr_string(xfd_cscan_win, 2, 2, FGCOLOR, BGCOLOR, "File:");
-
- /* Wait for the gun */
- count(1, go_event, INF);
-
- /* First register the task as a user of the file manager */
- if (!create_file_mgr())
- xfd_error("xfd_cscan: Can't access file manager");
-
- /* Now mount drive C. */
- if (!pc_dskopen(hd_drive_id))
- xfd_error("xfd_cscan: Can't open hard disk");
-
- /* Set the default drive to C: */
- if (!pc_set_default_drive(hd_drive_id))
- xfd_error("Can't select hard disk as default");
-
- /* Find the largest file on the first pass */
- find_largest = TRUE;
- largest_f_size = 0;
- largest_f_path[0] = '\0';
-
- while(bump_task(ct, ct->priority))
- {
- /* clear our directory stack */
- for (stackp=0; stackp<30;stackp++) cscan_stack[stackp][0]='\0';
- stackp = 0;
-
- while(bump_task(ct, ct->priority))
- {
- /* Walk up our stack and build a path from it */
- path[0]='\0';
- path_len = 0;
- for (i = 0; i < stackp; i++)
- {
- path_len += (strlen(cscan_stack[i])+1);
- if (path_len > EMAXPATH)
- xfd_error("Too many subdirs for this build");
- strcat(path,"\\");
- strcat(path,cscan_stack[i]);
- }
- if (!stackp)
- strcat(path,"\\");
-
- /* Display files if at a new directory (the stack is NULL for
- this dir. Otherwise we will scan forward til we find where
- we left */
- if (cscan_stack[stackp][0])
- display_files = FALSE;
- else
- display_files = TRUE;
-
- /* Display the path */
- if (display_files)
- {
- memset(display_buffer,' ', 67);
- display_buffer[66] = 0;
- xmwin_wr_string(xfd_cscan_win, 7, 1, FGCOLOR, BGCOLOR,
- display_buffer);
- xmwin_wr_string(xfd_cscan_win, 7, 1, FGCOLOR, BGCOLOR, path);
- }
- /* Set the path to the current working path */
- if (!pc_set_cwd(path))
- xfd_error("Can't set default directory");
-
- /* Get the first entry in the current working directory */
- found_dir = FALSE;
- if (!pc_gfirst(&statobj, "*.*"))
- xfd_error("No FIles Found");
- do
- {
- /* make the directory object into file.nam */
- mkname(fname_buffer, &statobj);
-
- if (statobj.fattribute & ADIRENT)
- {
- /* If it's a directory push it on our stack if we haven't
- visited it yet */
- if (fname_buffer[0] != '.')
- {
- if (!cscan_stack[stackp][0])
- {
- strcpy(cscan_stack[stackp],fname_buffer);
- found_dir = TRUE;
- break;
- }
- else
- {
- /* This is the one we just saw. zero the slot
- so we know to take another one */
- if (strcmp(cscan_stack[stackp],fname_buffer)==0)
- {
- /* 0 the stack so we take the next directory.
- plus display files again */
- display_files = TRUE;
- cscan_stack[stackp][0] = 0;
- }
- }
- }
- }
- else if (!(statobj.fattribute & AVOLUME))
- {
- /* It's a file. */
- /* Display the file */
- if (display_files)
- {
- if (find_largest)
- {
- if (statobj.fsize > largest_f_size)
- {
- largest_f_size = statobj.fsize;
- strcpy(largest_f_path, path);
- if (stackp)
- strcat(largest_f_path,"\\");
- strcat(largest_f_path, fname_buffer);
- }
- }
- xmwin_wr_string(xfd_cscan_win, 7, 2, FGCOLOR, BGCOLOR,
- " ");
- xmwin_wr_string(xfd_cscan_win, 7, 2, FGCOLOR, BGCOLOR,
- fname_buffer);
- }
- }
- bump_task(ct, ct->priority);
- } while (pc_gnext(&statobj));
- /* Call gdone to free up internal resources used by statobj */
- pc_gdone(&statobj);
-
- /* If we found a directory bump the stack pointer */
- if (found_dir)
- {
- stackp += 1;
- if (stackp >= 30)
- xfd_error("Too many subdirs for this build");
- cscan_stack[stackp][0] = 0;
- }
- else
- {
- /* Decrement the stack. If already 0 we finished the traverse */
- if (!stackp)
- break;
- /* Clean up the stack and decrement the pointer */
- cscan_stack[stackp--][0] = 0;
- }
- }
- if (find_largest)
- {
- /* Wake up the read task */
- find_largest = FALSE;
- signal(first_scan_done);
- bump_task(ct, ct->priority);
- /* ungrey all the other tests */
- menus[1].flags[DEMO_TASK_SEEK] &= ~ITEM_GREYED;
- menus[1].flags[DEMO_TASK_READ] &= ~ITEM_GREYED;
- menus[1].flags[DEMO_TASK_WRITE] &= ~ITEM_GREYED;
- menus[1].flags[DEMO_TASK_ASCAN] &= ~ITEM_GREYED;
- }
- }
- }
-
- /* xfd_seek_test_main - Randomly seek and read from a large file on the
- * hard disk.
- *
- * This routine waits for scan main to find the largest file on the hard
- * disk and then opens that file and continuously seeks and reads from it.
- * A graph displays the progress
- *
- * create_file_mgr()
- * pc_dskopen()
- * pc_set_default_drive()
- * po_open()
- * po_read()
- * po_lseek()
- */
-
- void _cdecl xfd_seek_test_main(void) /* __fn__ */
- {
- static unsigned char display_buffer[80];
- static unsigned char read_buff[512];
- unsigned long blocks_per_tick;
- unsigned long largest_f_blocks;
- long ltemp;
- PCFD fd;
- int th_posn = 0;
-
- unlock();
- draw_title(xfd_seek_win, xfd_seek_df_title, display_buffer);
-
- /* Wait for the gun */
- count(1, go_event, INF);
-
- /* Wait for the user to launch it */
- xmwin_wr_string(xfd_seek_win, 1, 1, FGCOLOR, BGCOLOR,
- "Suspended At start up Enable from menus..");
- fdemo_suspend_me(0);
-
-
- memset(display_buffer, ' ', 78);
- display_buffer[78] = 0;
- xmwin_wr_string(xfd_seek_win, 1, 1, FGCOLOR, BGCOLOR, display_buffer);
-
-
- xmwin_wr_string(xfd_seek_win, 1, 1, FGCOLOR, BGCOLOR, "File: ");
- xmwin_wr_string(xfd_seek_win, 7, 1, FGCOLOR, BGCOLOR, largest_f_path);
-
- /* Calculate how to position the thermometer */
- largest_f_blocks = largest_f_size/512;
- blocks_per_tick = largest_f_blocks/38;
-
- /* Now draw the thermometer with double line chars */
- memset(display_buffer,205, 40);
- display_buffer[0] = (unsigned char) 204;
- display_buffer[39] = (unsigned char) 185;
- display_buffer[40] = '\0';
- xmwin_wr_string(xfd_seek_win, 4, 2, FGCOLOR, BGCOLOR, display_buffer);
-
- /* First register the task as a user of the file manager */
- if (!create_file_mgr())
- xfd_error("xfd_cscan: Can't access file manager");
-
- /* Make sure drive C is mounted. */
- if (!pc_dskopen(hd_drive_id))
- xfd_error("xfd_cscan: Can't open hard disk");
-
- /* Set the default drive to C: */
- if (!pc_set_default_drive(hd_drive_id))
- xfd_error("Can't select hard disk as default");
-
- /* Open the file */
- if ((fd = po_open(largest_f_path, (PO_BINARY|PO_RDONLY), 0)) < 0)
- {
- xfd_error("Can't open the seek test file");
- }
-
- /* Now randomly seek and read */
- while(bump_task(ct, ct->priority))
- {
- ltemp = (long) rand();
- ltemp %= largest_f_blocks;
- display_buffer[1] = '\0';
- /* Clear the thumb */
- if (th_posn)
- {
- display_buffer[0] = 205;
- xmwin_wr_string(xfd_seek_win, th_posn, 2, FGCOLOR, BGCOLOR, display_buffer);
- }
- if (blocks_per_tick)
- {
- th_posn = (int) (ltemp/blocks_per_tick);
- /* There's a bug in the calculation, fix it here */
- if (th_posn > 37)
- th_posn = 37;
- th_posn += 5;
- display_buffer[0] = 206;
- xmwin_wr_string(xfd_seek_win, th_posn, 2, FGCOLOR, BGCOLOR, display_buffer);
- }
-
- ltemp *= 512;
- if (po_lseek(fd, ltemp, PSEEK_SET) != ltemp)
- xfd_error("Seek error");
- bump_task(ct, ct->priority);
- if (po_read(fd, read_buff, 512) != 512)
- xfd_error("Read error");
- }
- }
-
-
-
- /* xfd_read_test_main - Sequentially read from a large file on the
- * hard disk.
- *
- * This routine waits for scan main to find the largest file on the hard
- * disk and then opens that file and reads it sequentially. After each
- * read it calulates the throughput.
- * If the user selects it DOS can be used instead of RTFS. This gives an idea
- * of the relative performance of the two.
- * A graph displays the progress
- *
- * create_file_mgr()
- * pc_dskopen()
- * pc_set_default_drive()
- * po_open()
- * po_read()
- * po_lseek()
- */
-
- /* Use 20 blocks per read (10 K) */
- #if LARGE_DATA
- #define BLOCKS_PREAD 20
- #define BYTES_PREAD (20*512)
- #else
- #define BLOCKS_PREAD 1
- #define BYTES_PREAD (1*512)
- #endif
- void _cdecl xfd_read_test_main(void) /* __fn__ */
- {
- static unsigned char display_buffer[80];
- char *read_buff;
- unsigned long blocks_per_tick;
- unsigned long largest_f_blocks;
- unsigned long ltemp;
- PCFD fd;
- int th_posn = 0;
- long starting_ticks;
-
- unlock();
- draw_title(xfd_read_win, xfd_read_df_title, display_buffer);
-
- /* Wait for the gun */
- count(1, go_event, INF);
-
- /* Grab a buffer for the test */
- read_buff = (char *) malloc(BYTES_PREAD);
- if (!read_buff)
- xfd_error("Read Test, Not enough core to allocate buffer");
- xmwin_wr_string(xfd_read_win, 1, 1, FGCOLOR, BGCOLOR,
- "Scanning Drive For Largest File....");
-
- /* Wait for the largest file to be found */
- count(1, first_scan_done, INF);
-
- memset(display_buffer, ' ', 78);
- display_buffer[78] = 0;
- xmwin_wr_string(xfd_read_win, 1, 1, FGCOLOR, BGCOLOR, display_buffer);
-
- xmwin_wr_string(xfd_read_win, 1, 1, FGCOLOR, BGCOLOR, "File: ");
- xmwin_wr_string(xfd_read_win, 7, 1, FGCOLOR, BGCOLOR, largest_f_path);
-
- /* Calculate how to position the thermometer */
- largest_f_blocks = largest_f_size/512;
- blocks_per_tick = largest_f_blocks/38;
-
- /* Now draw the thermometer with double line chars */
- memset(display_buffer,205, 40);
- display_buffer[0] = (unsigned char) 204;
- display_buffer[39] = (unsigned char) 185;
- display_buffer[40] = '\0';
- xmwin_wr_string(xfd_read_win, 4, 2, FGCOLOR, BGCOLOR, display_buffer);
-
- /* First register the task as a user of the file manager */
- if (!create_file_mgr())
- xfd_error("xfd_cscan: Can't access file manager");
-
- /* Make sure drive C is mounted. */
- if (!pc_dskopen(hd_drive_id))
- xfd_error("xfd_cscan: Can't open hard disk");
-
- /* Set the default drive to C: */
- if (!pc_set_default_drive(hd_drive_id))
- xfd_error("Can't select hard disk as default");
-
- LOCK();
- /* Open the file */
- if ((fd = po_open(largest_f_path, (PO_BINARY|PO_RDONLY), 0)) < 0)
- {
- xfd_error("Can't open the read test file");
- }
- unlock();
-
- strcpy(read_buff,hd_drive_id);
- strcat(read_buff,largest_f_path);
-
-
- /* Now sequentially read */
- ltemp = 0;
- starting_ticks = get_etime();
-
- while(bump_task(ct, ct->priority))
- {
- if (ltemp == 0)
- draw_title(xfd_read_win, xfd_read_df_title, display_buffer);
-
- ltemp %= largest_f_blocks;
- display_buffer[1] = '\0';
- /* Clear the thumb */
-
- if (th_posn)
- {
- display_buffer[0] = 205;
- xmwin_wr_string(xfd_read_win, th_posn, 2, FGCOLOR, BGCOLOR, display_buffer);
- }
- if (blocks_per_tick)
- {
- th_posn = (int) (ltemp/blocks_per_tick);
- /* There's a bug in the calculation, fix it here */
- if (th_posn > 37)
- th_posn = 37;
- th_posn += 5;
- display_buffer[0] = 206;
- xmwin_wr_string(xfd_read_win, th_posn, 2, FGCOLOR, BGCOLOR, display_buffer);
- }
- if (po_read(fd, read_buff, BYTES_PREAD) == (UCOUNT) ~0)
- xfd_error("Read error");
-
- ltemp += BLOCKS_PREAD;
- if (ltemp >= largest_f_blocks)
- {
- if (po_lseek(fd, 0L, PSEEK_SET) != 0L)
- xfd_error("Seek error");
-
- /* Calculate transfer rate */
- /* Elapsed time in seconds */
- ltemp = get_etime()-starting_ticks;
- /* Bytes/second */
- if (ltemp)
- ltemp = ((largest_f_blocks*512)/ltemp)*SEC;
- else
- ltemp = 0;
-
- /* Clear the line and write the transfer rate */
- memset(display_buffer, ' ', 78);
- display_buffer[78] = 0;
- xmwin_wr_string(xfd_read_win, 1, 1, FGCOLOR, BGCOLOR, display_buffer);
- ltoa(ltemp, display_buffer, 10);
- strcat(display_buffer, " Bytes/Second");
- xmwin_wr_string(xfd_read_win, 1, 1, FGCOLOR, BGCOLOR, display_buffer);
-
- /* Remember the time for next time */
- starting_ticks = get_etime();
- /* reset the byte counter. ltemp is really overused, I know */
- ltemp = 0;
- }
- }
- }
-
- /* xfd_write_test_main - Create directorues and files. Then rename the files,
- * delete them and then delete the directories.
- *
- * This routine works on the user selected folppy or ram disk. Creates two
- * directories, populates them with files, renames the files, deletes the files
- * and finally deletes the directories. This loops continuosly. Its sister
- * function xfd_ascan_main() scans these directories and prints the tree
- * structure in a continuous manner.
- *
- * create_file_mgr()
- * pc_dskopen()
- * pc_set_default_drive()
- * pc_mkfs() - See ram_disk_init()
- * po_open()
- * po_read()
- * po_close()
- * po_mkdir()
- * po_rmdir()
- * pc_set_cwd()
- * pc_iddir()
- * pc_mv()
- * po_unlink()
- *
- * To do all this in line would have been unwieldly, so several helper functions
- * were created. See the task helper function section after the main tasks.
- *
- */
-
- /* used by write_test and its helpers */
- static char wr_display_buffer[80];
- static char wr_display_buffer_2[80];
-
- void _cdecl xfd_write_test_main(void) /* __fn__*/
- {
- static char dir[14];
- char c;
- extern PFILE_SYSTEM_USER fs_user; /* Current user pointer contains errno/pwd */
-
- unlock();
- draw_title(xfd_write_win, xfd_write_df_title, wr_display_buffer);
- /* Wait for the gun */
- count(1, go_event, INF);
-
-
- /* First register the task as a user of the file manager */
- if (!create_file_mgr())
- xfd_error("xfd_cscan: Can't access file manager");
- if (fd_drive_id[0] == 'E')
- if (!ram_disk_init())
- xfd_error("No Ram drive");
- /* Now mount drive A:. */
- if (!pc_dskopen(fd_drive_id))
- xfd_error("xfd_write: Can't open floppy drive");
- /* Set the default drive to A: */
- if (!pc_set_default_drive(fd_drive_id))
- xfd_error("Can't select floppy as default");
- if (!pc_set_cwd("\\"))
- xfd_error("Can't set default directory");
- /* Wait for the user to enable floppy operations */
- xmwin_wr_string(xfd_write_win, 1, 1, FGCOLOR, BGCOLOR,
- "Suspended At start up Enable from menus..");
- fdemo_suspend_me(0);
-
-
- memset(wr_display_buffer,' ', 67);
- xmwin_wr_string(xfd_write_win, 1, 1, FGCOLOR, BGCOLOR, wr_display_buffer);
- xmwin_wr_string(xfd_write_win, 1, 2, FGCOLOR, BGCOLOR, wr_display_buffer);
-
- strcpy(dir, "SUBDIR1");
-
- while(bump_task(ct, ct->priority))
- {
- /* Set the default path to \\ */
- if (!pc_set_cwd("\\"))
- xfd_error("Can't set default directory");
- /* Delete all files in two subdirectories and the dirs themselves */
- for (c = '1'; c < '3'; c++)
- {
- dir[6] = c; /* Flip from SUBDIR1 to SUBDIR2 */
- if (pc_isdir(dir))
- {
- /* Delete all files from dir */
- xfd_write_purge(dir);
- strcpy(wr_display_buffer_2, "Removing: ");
- strcat(wr_display_buffer_2, dir);
- xfd_write_status(1, wr_display_buffer_2);
- /* Call special rmdir routine which waits around for the
- scanner routine to stop looking at the directory.
- Normally you would just call pc_rmdir(dir). It would
- fail if someone else was using it (which is the
- correct behavior) */
- if (!xfd_write_rmdir(dir))
- xfd_error("Can't remove directory");
- }
- }
-
- /* Create the subdirectory and files */
- xfd_write_status(1, "Creating SUBDIR 1");
- if (!pc_mkdir("SUBDIR1"))
- cant_mkdir:
- xfd_error("Can't create directory");
-
- xfd_write_status(1, "Creating SUBDIR 2");
- if (!pc_mkdir("SUBDIR2"))
- goto cant_mkdir;
-
- /* Create a bunch of files */
- xfd_write_make_files("SUBDIR1");
- xfd_write_make_files("SUBDIR2");
- xfd_write_rename_files("SUBDIR1");
- xfd_write_rename_files("SUBDIR2");
- }
- }
-
- /* xfd_ascan_main - Scan directories and files on the floppy or ram disk.
- *
- * This routine works on the user selected floppy or ram disk. It scans for
- * the two directories created by xfd_write_test_main() and print their
- * contents. The display will vary ofer time as the directory contents
- * change.
- *
- * create_file_mgr()
- * pc_dskopen()
- * pc_set_default_drive()
- * pc_set_cwd()
- * pc_isdir()
- * pc_gfirst()
- * pc_gnext()
- * po_gdone()
- *
- */
-
- void _cdecl xfd_ascan_main(void) /* __fn__*/
- {
- static char display_buffer[80];
- DSTAT statobj;
- int i, posn;
- int n_found;
-
- unlock();
-
- draw_title(xfd_ascan_win, xfd_ascan_df_title, display_buffer);
-
- /* Wait for the gun */
- count(1, go_event, INF);
-
- /* First register the task as a user of the file manager */
- if (!create_file_mgr())
- xfd_error("Lost File manager");
-
- if (fd_drive_id[0] == 'E')
- if (!ram_disk_init())
- xfd_error("No Ram drive");
-
- /* Now mount drive A:. */
- if (!pc_dskopen(fd_drive_id))
- xfd_error("No floppy drive");
-
- /* Set the default drive to A: */
- if (!pc_set_default_drive(fd_drive_id))
- xfd_error("Can't set drive");
-
- /* Set the default path to \\ */
- if (!pc_set_cwd("\\"))
- xfd_error("Can't set dir");
-
-
- xmwin_wr_string(xfd_ascan_win, 1, 1, FGCOLOR, BGCOLOR, "Suspended At");
- xmwin_wr_string(xfd_ascan_win, 1, 2, FGCOLOR, BGCOLOR, "Start up..");
- /* Wait to be turned on */
- fdemo_suspend_me(0);
-
- while(bump_task(ct, ct->priority))
- {
- /* Clear the window */
- memset(display_buffer,' ', 20);
- for (i = 1; i < xfd_ascan_win->height-2; i++)
- xmwin_wr_string(xfd_ascan_win, 1, i, FGCOLOR, BGCOLOR, display_buffer);
-
- posn = 0;
- n_found = 0;
-
- /* See if the DIR exists. If it does we scan through it and display
- its contents */
- if (pc_isdir("SUBDIR1"))
- {
- posn += 1;
- n_found += 1;
-
- xmwin_wr_string(xfd_ascan_win, 1, posn++, FGCOLOR, BGCOLOR,"SUBDIR1");
- if (pc_gfirst(&statobj, "SUBDIR1\\*.*"))
- {
- /* Limit the display to for files */
- for (i = 1; i < ((xfd_ascan_win->height-4)/2); i++,posn++)
- {
- /* make the directory object into file.nam */
- mkname(display_buffer, &statobj);
- xmwin_wr_string(xfd_ascan_win, 4, posn, FGCOLOR,
- BGCOLOR, display_buffer);
- if (!pc_gnext(&statobj))
- break;
- }
- /* Call gdone to free up internal resources used by statobj */
- pc_gdone(&statobj);
- }
- }
- /* Repeat the loop for subdir2 */
- if (pc_isdir("SUBDIR2"))
- {
- posn += 1;
- n_found += 1;
- xmwin_wr_string(xfd_ascan_win, 1, posn++, FGCOLOR, BGCOLOR,"SUBDIR2");
- if (pc_gfirst(&statobj, "SUBDIR2\\*.*"))
- {
- for (i = 1; i < ((xfd_ascan_win->height-4)/2); i++,posn++)
- {
- /* make the directory object into file.nam */
- mkname(display_buffer, &statobj);
- xmwin_wr_string(xfd_ascan_win, 4, posn, FGCOLOR,
- BGCOLOR, display_buffer);
- if (!pc_gnext(&statobj))
- break;
- }
- /* Call gdone to free up internal resources used by statobj */
- pc_gdone(&statobj);
- }
- }
- /* Suspend a few ticks. This smooths thing out a little plus
- it masks a bug:
- If this routine did not find any files and we did not suspend
- smx doesn't preempt us and it spins in a tight loop. Will
- use probe to find out why later. */
- suspend(ct,5);
- }
- }
-
- /* This task manages the prompt window, There are now xfile calls in it */
-
- void _cdecl xfd_prompt_main(void) /* __fn__*/
- {
- unlock();
-
- prompt(0, " Welcome To The smxFile Demo ",
- " Use the Options Menu to Modify Parameters",
- " Then select Run Demo From The Files Menu",
- " Wait for first scan before selecting F2",
- " Press Escape at any time to Exit");
- #if 0
- xmwin_scroll(xfd_prompt_win; TRUE);
- xmwin_scroll(xfd_prompt_win; FALSE);
- #endif
-
- /* Wait for the gun */
- count(1, go_event, INF);
- while(bump_task(ct, ct->priority))
- {
- prompt(1," There are five tasks running, each performing",
- " a different function. The first continually scans",
- " the hard drive and prints the names of all files",
- " and directories.",0);
- prompt(1," The second task waits for the first scan of the disk",
- " to complete and then randomly seeks and reads from",
- " the largest file on it. This task is initially disabled",
- " for max thruput. The third task reads the largest file",
- " sequentially and calculates disk thruput.");
- prompt(1," The fourth task creates two directories on the floppy",
- " or RAM disk and fills them with files which are",
- " later renamed and deleted. The fifth task continually",
- " scans the floppy disk and displays the contents of",
- " the two directories.");
- prompt(1," The Floppy tasks are disabled at first because",
- " they slow down the hard disk tasks. It\'s the fault",
- " of the BIOS not smxFile. We have drivers to fix this.",
- " You may enable floppy tasks from the F2 menu. Be sure",
- " to use a high density floppy.");
- prompt(1," If you want something a little snappier, you may use",
- " a RAM disk instead of a floppy disk for the \"Floppy",
- " Tests\". To do this use the F3 options menu before",
- " you select Run Demo from the F1 menu.", 0);
- prompt(1," The \"Read Test\" demonstrates the throughput of",
- " smxFile. With some disk controllers the DOS driver is",
- " faster than the BIOS driver. Hence the BIOS driver may",
- " lower the performance of smxFile relative to DOS.",0);
- prompt(1," To get a better idea of smxFile performance, invoke",
- " this demo with the smx floppy and ide drivers.",
- " e.g.: \"run l d\"",0,0);
- }
- }
-
- /* Task helper functions */
-
- /* make a directory object into file.nam */
- void mkname(char *buffer, DSTAT *pstat) /* __fn__ */
- {
- char *pfr, *pto;
- pto = buffer; pfr = (char *) pstat->fname;
- while (*pfr && *pfr!=' ') *pto++ = *pfr++;
- pfr = pstat->fext;
- if (*pfr != ' ') *pto++ = '.';
- while (*pfr && *pfr!=' ') *pto++ = *pfr++;
- *pto = '\0';
- }
-
- /* These routines are helpers to xfd_write_test_main(void) below */
-
- void xfd_write_status(int line, char *message) /* __fn__*/
- {
- memset(wr_display_buffer,' ', 67);
- xmwin_wr_string(xfd_write_win, 1, line, FGCOLOR, BGCOLOR, wr_display_buffer);
- /* If status 1 has change clear status 2 */
- if (line == 1)
- xmwin_wr_string(xfd_write_win, 1, 2, FGCOLOR, BGCOLOR, wr_display_buffer);
- xmwin_wr_string(xfd_write_win, 1, line, FGCOLOR, BGCOLOR, message);
- }
-
- /* Delete all files in a subdirectory */
- void xfd_write_purge(char *subdir) /* __fn__*/
- {
- DSTAT statobj;
- BOOL more;
- int i;
- char fname_buffer[14];
- BOOL deleted;
- extern PFILE_SYSTEM_USER fs_user; /* Current user pointer contains errno/pwd */
-
- strcpy(wr_display_buffer_2,"Deleting Files In: ");
- strcat(wr_display_buffer_2,subdir);
- xfd_write_status(1, wr_display_buffer_2);
-
- if (!pc_set_cwd(subdir))
- goto cant_set;
-
- if (pc_gfirst(&statobj, "*.*"))
- {
- do {
- if (!(statobj.fattribute & ADIRENT))
- {
- mkname(fname_buffer, &statobj);
- strcpy(wr_display_buffer_2,"Deleting : ");
- strcat(wr_display_buffer_2,fname_buffer);
- xfd_write_status(2, wr_display_buffer_2);
- /* Get next so the DROJ is no longer open */
- more = pc_gnext(&statobj);
- if (!more)
- pc_gdone(&statobj);
- /* xfd_ascan_main is continually scanning the FLOPPY disk.
- If it happens to be looking at this file at the time we try
- to delete it this routine will fail (correctly) with
- fs_user->p_errno == PEACCES. So we suspend and try again
- later in this case.
-
- Note:
- PEACCES has other meanings as well so we we time out
- after a few. (this is a minor bug in the API)
- */
- for (i = 0; i < 100; i++)
- {
- deleted = pc_unlink(fname_buffer);
- if (deleted || (fs_user->p_errno != PEACCES))
- break;
- else
- suspend(ct,1);
- }
- if (!deleted)
- xfd_error("Can't delete File");
- }
- else
- {
- more = pc_gnext(&statobj);
- if (!more)
- pc_gdone(&statobj);
- }
- } while (more);
- }
- if (!pc_set_cwd("\\"))
- cant_set:
- xfd_error("Can't set default directory");
- }
-
-
- /* Remove a subdirectory, bearing in mind that it may be being accessed
- by the scanner task. */
- BOOL xfd_write_rmdir(char *subdir) /* __fn__*/
- {
- int i;
- BOOL deleted;
- extern PFILE_SYSTEM_USER fs_user; /* Current user pointer contains errno/pwd */
-
- for (i = 0; i < 100; i++)
- {
- /* xfd_ascan_main is continually scanning the FLOPPY disk.
- If it happens to be looking at this directory at the time we try
- to delete it this routine will fail (correctly) with
- fs_user->p_errno == PEACCES. So we suspend and try again
- later in this case.
- Note:
- PEACCES has other meanings as well so we we time out
- after a few. (this is a minor bug in the API)
- */
-
- deleted = pc_rmdir(subdir);
- if (deleted || (fs_user->p_errno != PEACCES))
- break;
- else
- suspend(ct,1);
- }
- return (deleted);
- }
-
-
- /* Create files in a subdirectory */
- void xfd_write_make_files(char *subdir) /* __fn__*/
- {
- int i;
- int fd;
- char fname_buffer[14];
- char c;
-
- strcpy(wr_display_buffer_2,"Creating Files In: ");
- strcat(wr_display_buffer_2,subdir);
- xfd_write_status(1, wr_display_buffer_2);
-
- if (!pc_set_cwd(subdir))
- goto cant_set;
- strcpy(fname_buffer, "FILE_1.TXT");
-
-
- for (i = 0, c = '1'; i < 8; i++, c++)
- {
- fname_buffer[5] = c;
- strcpy(wr_display_buffer_2,"Creating : ");
- strcat(wr_display_buffer_2,fname_buffer);
- xfd_write_status(2, wr_display_buffer_2);
- if ((fd = po_open(fname_buffer,(PO_BINARY|PO_WRONLY|PO_CREAT|PO_TRUNC),
- (PS_IWRITE | PS_IREAD) ) ) < 0)
- xfd_error("Can't open File");
- if (po_write(fd, fname_buffer, 10) != 10)
- xfd_error("Can't write File");
- po_close(fd);
- }
-
- if (!pc_set_cwd("\\"))
- cant_set:
- xfd_error("Can't set default directory");
- }
-
- /* Rename files in a directory */
- void xfd_write_rename_files(char *subdir) /* __fn__*/
- {
- DSTAT statobj;
- BOOL more;
- char fname_buffer[14];
-
- strcpy(wr_display_buffer_2,"Renaming Files In: ");
- strcat(wr_display_buffer_2,subdir);
- xfd_write_status(1, wr_display_buffer_2);
-
- if (!pc_set_cwd(subdir))
- goto cant_set;
-
- if (pc_gfirst(&statobj, "*.*"))
- {
- do {
- if (!(statobj.fattribute & ADIRENT))
- {
- mkname(&fname_buffer[1], &statobj);
- strcpy(wr_display_buffer_2,"Rename : ");
- strcat(wr_display_buffer_2,&fname_buffer[1]);
- xfd_write_status(2, wr_display_buffer_2);
- fname_buffer[0] = '_';
- /* Get next so the DROJ is no longer open */
- more = pc_gnext(&statobj);
- if (!pc_mv(&fname_buffer[1],fname_buffer))
- xfd_error("Can't rename File");
- }
- else
- more = pc_gnext(&statobj);
- } while (more);
- /* Call gdone to free up internal resources used by statobj */
- pc_gdone(&statobj);
- }
- if (!pc_set_cwd("\\"))
- cant_set:
- xfd_error("Can't set default directory");
- }
-
- /* Format a ram disk */
- BOOLEAN ram_disk_init() /* __fn__*/
- {
- IMPORT _PC_BDEVSW pc_bdevsw[];
- FMTPARMS fmt;
- int driveno;
- static BOOLEAN ram_disk_formatted = FALSE;
-
- LOCK();
-
- if (ram_disk_formatted)
- goto out;
-
-
- driveno = 4; /* E: */
- strcpy(&fmt.oemname[0], "EBS");
- fmt.secpalloc = (UTINY) 1;
- fmt.secreserved = (UCOUNT) 1;
- fmt.numfats = (UTINY) 1;
- fmt.secpfat = (UCOUNT) 1;
- fmt.numroot = (UCOUNT) 16; /* One block */
- fmt.mediadesc = (UTINY) 0xFD;
-
- /* 2 * 2 * (N/4) =s N */
- fmt.secptrk = (UCOUNT) NRAMDISKBLOCKS/4;
- fmt.numhead = (UCOUNT) 2;
- fmt.numcyl = (UCOUNT) 2;
- fmt.physical_drive_no = 0;
- fmt.binary_volume_label = 0x12345678L;
- strcpy(fmt.text_volume_label, "VOLUMELABE");
-
- if (!pc_bdevsw[driveno].open_proc(driveno))
- goto out;
-
- /* How many sectors do we need for the fat */
- fmt.secpfat = pc_fat_size( (UCOUNT) fmt.secreserved,
- (UCOUNT) fmt.secpalloc,
- (UCOUNT) fmt.numfats,
- (UCOUNT) fmt.numroot,NRAMDISKBLOCKS);
-
- if (!pc_mkfs(driveno, &fmt ))
- goto out;
- ram_disk_formatted = TRUE;
- out:
- unlock();
- return(ram_disk_formatted);
- }
-
- /* Used by prompt_main. This routine displays strings in the prompt window
- and sleeps if requested. */
-
- void prompt(int goto_sleep,char *p0, char *p1,char *p2, char *p3, char *p4)/*__fn__*/
- {
- int posn;
- static char display_buffer[80];
-
- /* Clear the rows */
- memset(display_buffer,' ', 79);
- for (posn = 1; posn < 6; posn++)
- xmwin_wr_string(xfd_prompt_win, 1, posn, FGCOLOR, BGCOLOR,display_buffer);
-
- if (p0)
- xmwin_wr_string(xfd_prompt_win, 1, 1, FGCOLOR, BGCOLOR,p0);
- if (p1)
- xmwin_wr_string(xfd_prompt_win, 1, 2, FGCOLOR, BGCOLOR,p1);
- if (p2)
- xmwin_wr_string(xfd_prompt_win, 1, 3, FGCOLOR, BGCOLOR,p2);
- if (p3)
- xmwin_wr_string(xfd_prompt_win, 1, 4, FGCOLOR, BGCOLOR,p3);
- if (p4)
- xmwin_wr_string(xfd_prompt_win, 1, 5, FGCOLOR, BGCOLOR,p4);
- if (goto_sleep)
- suspend(ct, 12*SEC);
- }
- /* Draws a title in top left corner of a window */
- void draw_title(XMWIN_PTR win, char * title, char * buffer) /* __fn__ */
- {
- char *p = buffer;
-
- memset(buffer, CH_SHOR, 76);
- buffer[75] = 0;
- while (*title)
- *p++ = *title++;
- xmwin_wr_string(win, 1, 0, FGCOLOR, BGCOLOR, buffer);
- }
-
- /* Task control and interaction functions */
-
- /***** OPERATION CONTROL
- * Filters key board input and exits or pops up menus
- *
- **********************************************************************/
- void _cdecl opcon_main(void) /* __fn__ */
- {
- char key;
- unsigned int ikey;
-
- while(key = (char)(ikey = pget_char(op_pipe, INF)))
- {
- if(key == Esc)
- start(exitx);
- else if ( (ikey &0xff) == KEY_F1)
- command_dispatch(process_menu(0));
- else if ( (ikey &0xff) == KEY_F2)
- command_dispatch(process_menu(1));
- else if ( (ikey &0xff) == KEY_F3)
- command_dispatch(process_menu(2));
- else if(key == Ctrl_S)
- {
- if(sp_scrn_sel)
- swap_screen();
- kbd_pipe = op_pipe;
- }
- }
- }
-
- /* This routine is called to create the menu system for the demo */
- void create_demo_menu() /* __fn__ */
- {
- menus[0].top = "F1: Files";
- menus[1].top = "F2: Tasks";
- menus[2].top = "F3: Options";
-
- menus[0].texts[0] = "Run Demos";
- menus[0].commands[0] = CMD_GO;
- menus[0].flags[0] = 0;
- menus[0].texts[1] = "Quit";
- menus[0].commands[1] = CMD_QUIT;
- menus[0].flags[1] = 0;
- menus[0].texts[2] = 0;
-
- /* Task menu */
- menus[1].texts[0] = demo_control[DEMO_TASK_CSCAN].pause_menu;
- menus[1].commands[0] = CMD_PAUSE_CSCAN;
- menus[1].flags[0] = ITEM_GREYED;
-
- /* The next group of tasks start in a paused state */
- menus[1].texts[1] = demo_control[DEMO_TASK_SEEK].resume_menu;
- menus[1].commands[1] = CMD_RESUME_SEEK;
- menus[1].flags[1] = ITEM_GREYED;
-
- /* Read has a delayed start but its starting state is on */
- menus[1].texts[2] = demo_control[DEMO_TASK_READ].pause_menu;
- menus[1].commands[2] = CMD_PAUSE_READ;
- menus[1].flags[2] = ITEM_GREYED;
-
- menus[1].texts[3] = demo_control[DEMO_TASK_WRITE].resume_menu;
- menus[1].commands[3] = CMD_RESUME_WRITE;
- menus[1].flags[3] = ITEM_GREYED;
-
- menus[1].texts[4] = demo_control[DEMO_TASK_ASCAN].resume_menu;
- menus[1].commands[4] = CMD_RESUME_ASCAN;
- menus[1].flags[4] = ITEM_GREYED;
-
- menus[1].texts[5] = 0;
-
- /* Menus 2 Options. */
- menus[2].texts[0] = "Use D: drive Instead of C:";
- menus[2].commands[0] = CMD_USE_D;
- menus[2].flags[0] = 0;
- menus[2].texts[1] = "Use B: drive Instead of A:";
- menus[2].commands[1] = CMD_USE_B;
- menus[2].flags[1] = 0;
- menus[2].texts[2] = "Use Ram Disk Instead Of Floppy";
- menus[2].commands[2] = CMD_USE_RD;
- menus[2].flags[2] = 0;
- #if 0
- menus[2].texts[3] = "Use DOS For Read Performance Test ";
- menus[2].commands[3] = CMD_USE_DOS;
- menus[2].flags[3] = 0;
- menus[2].texts[4] = 0;
- #else
- menus[2].texts[3] = 0;
- #endif
- build_menu();
- display_top();
- }
-
- /* This routine is called do dispatch commands from the menus */
- void command_dispatch(int command) /* __fn__ */
- {
- if (!command)
- return;
-
- switch(command)
- {
- case CMD_GO:
- /* Start the process. Grey out start-up items. */
- /*GO*/ menus[0].flags[0] =
- /*D:B:&E:*/ menus[2].flags[0] =
- menus[2].flags[1] =
- menus[2].flags[2] = ITEM_GREYED;
- /* pause C: */ menus[1].flags[0] &= ~ITEM_GREYED;
-
- signal(go_event);
- break;
- case CMD_QUIT:
- start(exitx);
- break;
- case CMD_USE_D:
- hd_drive_id = "D:";
- break;
- case CMD_USE_B:
- fd_drive_id = "B:";
- menus[2].flags[1] =
- menus[2].flags[2] = ITEM_GREYED;
- break;
- case CMD_USE_RD:
- fd_drive_id = "E:";
- menus[2].flags[1] =
- menus[2].flags[2] = ITEM_GREYED;
- break;
- case CMD_PAUSE_CSCAN:
- case CMD_PAUSE_SEEK:
- case CMD_PAUSE_READ:
- case CMD_PAUSE_WRITE:
- case CMD_PAUSE_ASCAN:
- if (!demo_control[(command & 0x0f)].suspended)
- {
- menus[1].texts[(command & 0x0f)] =
- demo_control[(command & 0x0f)].resume_menu;
- /* Hack. Change menu command from pause to resume */
- menus[1].commands[(command & 0x0f)] -= 0x10;
- menus[1].commands[(command & 0x0f)] |= 0x20;
-
- /* Request it be suspended */
- suspend_this_task = demo_control[(command & 0x0f)].p_task;
- /* And wait */
- count(1, suspend_completed, SEC);
- suspend_this_task = (TCB_PTR) 0;
- }
- break;
- case CMD_RESUME_CSCAN:
- case CMD_RESUME_SEEK:
- case CMD_RESUME_READ:
- case CMD_RESUME_WRITE:
- case CMD_RESUME_ASCAN:
- if (demo_control[(command & 0x0f)].suspended)
- {
- menus[1].texts[(command & 0x0f)] =
- demo_control[(command & 0x0f)].pause_menu;
- /* Hack. Change menu command from resume to pause */
- menus[1].commands[(command & 0x0f)] -= 0x20;
- menus[1].commands[(command & 0x0f)] |= 0x10;
- demo_control[(command & 0x0f)].suspended = 0;
- resume(demo_control[(command & 0x0f)].p_task);
- }
- break;
- default:
- break;
- }
- }
-
- /* Other miscelanous control functions */
-
- /* This is called from xmwin_epilogue in xmwin.c. The task must be locked on
- entry.It suspends the current tasks and notes it in demo control structure
- If requested it signals when the suspend is complete. This signaling
- mechanism is needed because opcon_main() asks the task to suspend and
- then waits for acknowledgement. This eliminates race conditions in the
- menus.
- */
-
- void fdemo_suspend_me(int do_signal) /* __fn__ */
- {
- int i;
- for (i = 0;i<MAXDEMOTASKS;i++)
- {
- if(demo_control[i].p_task == ct)
- {
- demo_control[i].suspended = 1; /* yea */
- if (do_signal)
- signal(suspend_completed);
- suspend(ct,INF);
- break;
- }
- }
- }
-
- /* Task error function. If called display the message in the tasks window
- and suspend forever */
- void _cdecl xfd_error(char *p) /* __fn__ */
- {
- int i;
- int j;
- char display_buffer[70];
-
- for (i = 0; i < MAXDEMOTASKS; i++)
- {
- if (ct == demo_control[i].p_task)
- {
- /* Clear the window */
- memset(display_buffer,' ', 69);
- for (j = 1; j < demo_control[i].window->height-1; j++)
- xmwin_wr_string(demo_control[i].window, 1, j, FGCOLOR, BGCOLOR,
- display_buffer);
- xmwin_wr_string(demo_control[i].window, 1, 1, FGCOLOR, BGCOLOR,
- p);
- xmwin_wr_string(demo_control[i].window, 1, 2, FGCOLOR, BGCOLOR,
- "Bye.....");
- break;
- }
- }
- suspend(ct, INF);
- }
-
- /* These tasks don't do anything at the current time */
- void _cdecl quit_appl() /* __fn__ */
- {
- #if IDE_FLOPPY
- /* Restore interrupt vectors */
- fl_restore();
- #endif
-
- /* Restore the screen */
- if (xfd_appl_win)
- xmwin_destroy(xfd_appl_win);
- clr_screen(LIGHTGRAY, BLACK);
- }
-
- void _cdecl show_etime() /* __fn__ */
- {
-
- }
-