home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DOOG / CTASK.ZIP / TPRT.C < prev    next >
C/C++ Source or Header  |  1989-12-13  |  3KB  |  147 lines

  1.  
  2. /*
  3.    Test program for checking CTask printer buffering.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <conio.h>
  8. #include <process.h>
  9. #include <ctype.h>
  10.  
  11. #include "tsk.h"
  12. #include "prt.h"
  13.  
  14. #define PORT 0x80    /* LPT1 (relative) */
  15. #define POLL 0       /* Set to 1 to use polling */
  16.  
  17. #if (TSK_NAMED)
  18. extern void snapshot (FILE *f);
  19. #endif
  20.  
  21. #define STACKSIZE 2048
  22.  
  23. unsigned int _stklen = 3 * STACKSIZE;  /* For Turbo C: Two tasks + main Task Stack */
  24.  
  25. tcb tcb1, tcb2;
  26. flag halt, ready;
  27.  
  28. byte xmtbuf [1024];
  29. int endrun;
  30. int pport;
  31.  
  32. FILE *pfile;
  33.  
  34.  
  35. void far task1 (void)
  36. {
  37.    int i;
  38.  
  39.    printf ("Task 1 started\n");
  40.  
  41.    /* Copy file into printer pipe. Using a larger file buffer would be more
  42.       efficient, but this is only a demo.
  43.    */
  44.  
  45.    while (!endrun && ((i = getc (pfile)) != EOF))
  46.       prt_write (pport, (byte)i, 0L);
  47.  
  48.    if (endrun)
  49.       return;
  50.  
  51.    /* Wait for printer to complete output. */
  52.  
  53.    if (!prt_complete (pport))
  54.       puts ("Waiting for Printer");
  55.    prt_wait_complete (pport, 0L);
  56.  
  57.    /* Stop program */
  58.  
  59.    set_flag (&halt);
  60.    set_flag (&ready);
  61. }
  62.  
  63.  
  64. /*
  65.    Second task just for fun. Echoes keyboard characters, aborts printing
  66.    when 'e' is entered. Also outputs snapshot dump on 'd'.
  67. */
  68.  
  69. void far task2 (void)
  70. {
  71.    int ch;
  72.  
  73.    printf ("Task 2 started\n");
  74.    while (!endrun)
  75.       {
  76.       ch = t_read_key () & 0xff;
  77.       putch (ch);
  78.       ch = tolower (ch);
  79.       endrun = (ch == 'e');
  80. #if (TSK_NAMED)
  81.       if (ch == 'd')
  82.          snapshot (stdout);
  83. #endif
  84.       }
  85.  
  86.    set_flag (&halt);
  87. }
  88.  
  89.  
  90.  
  91. void main (int argc, char **argv)
  92. {
  93.    char stack1 [STACKSIZE];
  94.    char stack2 [STACKSIZE];
  95.  
  96.    if ((pfile = fopen (argv [1], "rb")) == NULL)
  97.       {
  98.       printf ("Error opening file '%s'\n", argv [1]);
  99.       exit (1);
  100.       }
  101.  
  102.    endrun = 0;
  103.    install_tasker (0, 0, IFL_STD, "TPRT");
  104.  
  105.    pport = prt_install (PORT, POLL, PRI_STD, xmtbuf, sizeof (xmtbuf));
  106.  
  107.    create_task (&tcb1, task1, stack1, STACKSIZE, PRI_STD, NULL
  108. #if (TSK_NAMEPAR)
  109.                 ,"TASK1"
  110. #endif
  111.                 );
  112.    create_task (&tcb2, task2, stack2, STACKSIZE, PRI_STD, NULL
  113. #if (TSK_NAMEPAR)
  114.                 ,"TASK2"
  115. #endif
  116.                 );
  117.    create_flag (&halt
  118. #if (TSK_NAMEPAR)
  119.                 ,"Halt"
  120. #endif
  121.                 );
  122.    create_flag (&ready
  123. #if (TSK_NAMEPAR)
  124.                 ,"Ready"
  125. #endif
  126.                 );
  127.  
  128.    start_task (&tcb1);
  129.    start_task (&tcb2);
  130.  
  131.    preempt_on ();
  132.    wait_flag_set (&halt, 0L);
  133.  
  134.    endrun = 1;
  135.    puts ("******** Main Task *********");
  136.    wait_flag_set (&ready, 0L);
  137.  
  138.    puts ("******** End Run *********");
  139.    preempt_off ();
  140.    prt_remove (pport);
  141.    remove_tasker ();
  142.  
  143.    fclose (pfile);
  144. }
  145.  
  146.  
  147.