home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilst / virtual / !Virtual / c / poll < prev   
Text File  |  1992-07-28  |  4KB  |  138 lines

  1. #include "swis.h"
  2. #include "swiv.h"
  3. #include "wimp.h"
  4.  
  5. #include "virtual.h"
  6. #include "lib.h"
  7. #include "pager.h"
  8. #include "output.h"
  9. #include "asm.h"
  10. #include "poll.h"
  11.  
  12. void Poll(WKSP *w)
  13. { int reason,i;
  14.   int suspended=0;
  15.   wimp_eventdata b;
  16.   if (!worksemaphore)
  17.     printf("Ooops!");
  18.   printflush(w);
  19.   usermode();
  20.   for (;;)
  21.   {
  22.     swi(OS_Release,IN(R0|R1|R2),3,&NormWriteC,w);
  23.     swi(Wimp_Poll,IN(R0|R1)|OUT(R0),suspended,&b,&reason);
  24.     swi(OS_Claim,IN(R0|R1|R2),3,&NormWriteC,w);
  25.     switch (reason)
  26.     { case wimp_ENULL:
  27.         if (w->moreavailable && w->incount<INSIZE)
  28.           goto doramfetch;
  29.         break;
  30.       case wimp_ESEND: case wimp_ESENDWANTACK:
  31.         switch (b.msg.hdr.action)
  32.         { case wimp_MCLOSEDOWN:
  33.             svcmode();
  34.             RealDoOff(w);
  35.             break;
  36.           case wimp_MSETSLOT:
  37.             /* if (b.msg.data.words[1]!=w->ourtask)
  38.               break; */
  39.             if (b.msg.data.words[0]>0)        /* min 2 pages */
  40.             { svcmode();
  41.               SetRealMem(w, b.msg.data.words[0]);
  42.               usermode();
  43.             }
  44.             b.msg.hdr.your_ref=b.msg.hdr.my_ref;
  45.             swi(Wimp_SendMessage,IN(R0|R1|R2),wimp_EACK,&b,b.msg.hdr.task);
  46.             break;
  47.           case /* TaskWindow_Input */  0x808c0:
  48.             { char *p=(char *)&b.msg.data.words[1];
  49.               int c;
  50.               for (c=b.msg.data.words[0];c>0;c--,p++)
  51.               { if (*p==w->EscapeChar && !w->EscapeCharEnable)
  52.                   w->EscapeCondition = 1;
  53.                 else
  54.                 { if (w->incount<INSIZE)
  55.                     w->inbuf[(w->instart+w->incount++)%INSIZE]=*p;
  56.                 }
  57.               }
  58.             }
  59.             break;
  60.           case wimp_MDATASAVE:
  61. doramfetch:
  62.             { char *p = &w->inbuf[(w->instart+w->incount++)%INSIZE];
  63.               w->innbytes = &w->inbuf[INSIZE] - p;
  64.               if (w->innbytes>INSIZE-w->incount)
  65.                 w->innbytes = INSIZE-w->incount;
  66.               printf("Ramfetch:%d\n",w->innbytes);
  67.               if (w->innbytes)
  68.               { b.msg.data.ramfetch.addr = p;
  69.                 b.msg.data.ramfetch.nbytes = w->innbytes;
  70.                 b.msg.hdr.your_ref = b.msg.hdr.my_ref;
  71.                 b.msg.hdr.action = wimp_MRAMFETCH;
  72.                 b.msg.hdr.size = sizeof(b.msg.data.ramfetch)+sizeof(b.msg.hdr);
  73.                 swi(Wimp_SendMessage,IN(R0|R1|R2),wimp_ESEND,&b,b.msg.hdr.task);
  74.               }
  75.               else
  76.                 w->moreavailable = 1;
  77.             }
  78.             break;
  79.           case wimp_MRAMTRANSMIT:
  80.             { w->incount += b.msg.data.ramtransmit.nbyteswritten;
  81.               printf("RamTransmit:%d\n",b.msg.data.ramtransmit.nbyteswritten);printflush(w);
  82.               if (b.msg.data.ramtransmit.nbyteswritten<w->innbytes)
  83.                 goto doramfetch;
  84.               else
  85.                 w->moreavailable = 0;
  86.             }
  87.             break;
  88.           case /* TaskWindow_Suspend */ 0x808c6:
  89.             printf("Suspended: PC=%x ",w->regs[15]);
  90.             for (i=0;i<=14;i++)
  91.               printf("R%d=%x ",i,w->regs[i]);
  92.             printf("\n");
  93.             printf("MemoryLimit=%x, ApplicationSpace=%x, CurrentlyActiveObject=%x\n",
  94.                         w->MemoryLimit, w->ApplicationSpace, w->CurrentlyActiveObject );
  95.             printflush(w);
  96.             suspended=1;
  97.             break;
  98.           case /* TaskWindow_Resume */ 0x808c7:
  99.             printf("Resumed\n");printflush(w);
  100.             suspended=0;
  101.             break;
  102.           case /* TaskWindow_Morite */ 0x808c4:
  103.             svcmode();
  104.             RealDoOff(w);
  105.             break;
  106.           default:
  107.             break;
  108.         }
  109.         continue;
  110.       default:
  111.         continue;
  112.     }
  113.     break;
  114.   }
  115.   svcmode();
  116.   FindPages(w);         /* in case its changed */
  117.   worksemaphore=1;
  118. }
  119.  
  120. int getc(WKSP *w)
  121. {
  122.   int c;
  123.   if (!w->incount && !w->EscapeCondition)
  124.   { Normal(w);
  125.     while (!w->incount && !w->EscapeCondition)
  126.       Poll(w);
  127.     Virtual(w);
  128.   }
  129.   if (w->EscapeCondition)
  130.     return -1;
  131.   c=w->inbuf[w->instart];
  132.   w->incount--;
  133.   if (++w->instart>INSIZE)
  134.     w->instart=0;
  135.   return c;
  136. }
  137.  
  138.