home *** CD-ROM | disk | FTP | other *** search
- #include "swis.h"
- #include "swiv.h"
- #include "wimp.h"
-
- #include "virtual.h"
- #include "lib.h"
- #include "pager.h"
- #include "output.h"
- #include "asm.h"
- #include "poll.h"
-
- void Poll(WKSP *w)
- { int reason,i;
- int suspended=0;
- wimp_eventdata b;
- if (!worksemaphore)
- printf("Ooops!");
- printflush(w);
- usermode();
- for (;;)
- {
- swi(OS_Release,IN(R0|R1|R2),3,&NormWriteC,w);
- swi(Wimp_Poll,IN(R0|R1)|OUT(R0),suspended,&b,&reason);
- swi(OS_Claim,IN(R0|R1|R2),3,&NormWriteC,w);
- switch (reason)
- { case wimp_ENULL:
- if (w->moreavailable && w->incount<INSIZE)
- goto doramfetch;
- break;
- case wimp_ESEND: case wimp_ESENDWANTACK:
- switch (b.msg.hdr.action)
- { case wimp_MCLOSEDOWN:
- svcmode();
- RealDoOff(w);
- break;
- case wimp_MSETSLOT:
- /* if (b.msg.data.words[1]!=w->ourtask)
- break; */
- if (b.msg.data.words[0]>0) /* min 2 pages */
- { svcmode();
- SetRealMem(w, b.msg.data.words[0]);
- usermode();
- }
- b.msg.hdr.your_ref=b.msg.hdr.my_ref;
- swi(Wimp_SendMessage,IN(R0|R1|R2),wimp_EACK,&b,b.msg.hdr.task);
- break;
- case /* TaskWindow_Input */ 0x808c0:
- { char *p=(char *)&b.msg.data.words[1];
- int c;
- for (c=b.msg.data.words[0];c>0;c--,p++)
- { if (*p==w->EscapeChar && !w->EscapeCharEnable)
- w->EscapeCondition = 1;
- else
- { if (w->incount<INSIZE)
- w->inbuf[(w->instart+w->incount++)%INSIZE]=*p;
- }
- }
- }
- break;
- case wimp_MDATASAVE:
- doramfetch:
- { char *p = &w->inbuf[(w->instart+w->incount++)%INSIZE];
- w->innbytes = &w->inbuf[INSIZE] - p;
- if (w->innbytes>INSIZE-w->incount)
- w->innbytes = INSIZE-w->incount;
- printf("Ramfetch:%d\n",w->innbytes);
- if (w->innbytes)
- { b.msg.data.ramfetch.addr = p;
- b.msg.data.ramfetch.nbytes = w->innbytes;
- b.msg.hdr.your_ref = b.msg.hdr.my_ref;
- b.msg.hdr.action = wimp_MRAMFETCH;
- b.msg.hdr.size = sizeof(b.msg.data.ramfetch)+sizeof(b.msg.hdr);
- swi(Wimp_SendMessage,IN(R0|R1|R2),wimp_ESEND,&b,b.msg.hdr.task);
- }
- else
- w->moreavailable = 1;
- }
- break;
- case wimp_MRAMTRANSMIT:
- { w->incount += b.msg.data.ramtransmit.nbyteswritten;
- printf("RamTransmit:%d\n",b.msg.data.ramtransmit.nbyteswritten);printflush(w);
- if (b.msg.data.ramtransmit.nbyteswritten<w->innbytes)
- goto doramfetch;
- else
- w->moreavailable = 0;
- }
- break;
- case /* TaskWindow_Suspend */ 0x808c6:
- printf("Suspended: PC=%x ",w->regs[15]);
- for (i=0;i<=14;i++)
- printf("R%d=%x ",i,w->regs[i]);
- printf("\n");
- printf("MemoryLimit=%x, ApplicationSpace=%x, CurrentlyActiveObject=%x\n",
- w->MemoryLimit, w->ApplicationSpace, w->CurrentlyActiveObject );
- printflush(w);
- suspended=1;
- break;
- case /* TaskWindow_Resume */ 0x808c7:
- printf("Resumed\n");printflush(w);
- suspended=0;
- break;
- case /* TaskWindow_Morite */ 0x808c4:
- svcmode();
- RealDoOff(w);
- break;
- default:
- break;
- }
- continue;
- default:
- continue;
- }
- break;
- }
- svcmode();
- FindPages(w); /* in case its changed */
- worksemaphore=1;
- }
-
- int getc(WKSP *w)
- {
- int c;
- if (!w->incount && !w->EscapeCondition)
- { Normal(w);
- while (!w->incount && !w->EscapeCondition)
- Poll(w);
- Virtual(w);
- }
- if (w->EscapeCondition)
- return -1;
- c=w->inbuf[w->instart];
- w->incount--;
- if (++w->instart>INSIZE)
- w->instart=0;
- return c;
- }
-
-