home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff267.lzh / Mackie / mackie.c < prev    next >
C/C++ Source or Header  |  1989-10-31  |  48KB  |  1,826 lines

  1. /*
  2.     Modified to work with Manx 3.6a; probably won't work with Lattice.
  3.                                 Based on:
  4.                                                                              */
  5. /*  Compile with -DSPLINES for splines instead of lines                      */
  6. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  7. /* |_o_o|\\ Copyright (c) 1986 The Software Distillery.  All Rights Reserved */
  8. /* |. o.| || This program may not be distributed without the permission of   */
  9. /* | .  | || the authors.                                                    */
  10. /* | o  | ||    Dave Baker     Ed Burnette  Stan Chow    Jay Denebeim        */
  11. /* |  . |//     Gordon Keener  Jack Rouse   John Toebes  Doug Walker         */
  12. /* ======          BBS:(919)-471-6436      VOICE:(919)-469-4210              */ 
  13. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  14. /*
  15.  * VERY loosely based on the input.device example by Rob Peck, 12/1/85
  16.  */
  17. /* * * * * * * * * INCLUDE FILES * * * * * * * * * * * */
  18. #include <exec/types.h>
  19. #include <exec/nodes.h>
  20. #include <exec/lists.h>
  21. #include <exec/memory.h>
  22. #include <exec/interrupts.h>
  23. #include <exec/ports.h>
  24. #include <exec/libraries.h>
  25. #include <exec/io.h>
  26. #include <exec/tasks.h>
  27. #include <exec/execbase.h>
  28. #include <exec/devices.h>
  29. #include <devices/timer.h>
  30. #include <devices/input.h>
  31. #include <devices/inputevent.h>
  32. #include <devices/console.h>
  33. #include <intuition/intuition.h>
  34. #include <intuition/intuitionbase.h>
  35. #include <libraries/dos.h>
  36. #include <libraries/dosextens.h>
  37. #include <graphics/gfxmacros.h>
  38. #include <hardware/custom.h>
  39. #include <hardware/dmabits.h>
  40. /*
  41.  *   I need this kludge because of a bug in functions.h.
  42.  */
  43. #define ConsoleDevice IDontReallyExist
  44. #include <functions.h>
  45. #undef ConsoleDevice
  46. #include <stdio.h>
  47.  
  48. /* * * * * * * * * * * CONSTANTS * * * * * * * * * * * * */
  49. #define PORTNAME     "Mackie.port"
  50. #define TIMEINTERVAL 1L      /* in seconds */
  51. #define DEFTIME      300     /* two minute timeout */
  52. #define MAXCMD       200
  53. #define MAXPENDINGSYSTEM 20
  54. #define DEFKEY    0x45
  55. #define DEFCMD    "NEWCLI >NIL: <NIL:"
  56. #define STARTUPFILE "s:.mackierc"
  57. /*
  58.  *   Macro to make BPTR things easier to work with.
  59.  */
  60. #define BSTRtoS(a) ((char *)(((long)(a))<<2))
  61. /* * * * * * * * * * * GLOBAL VARIABLES * * * * * * * * * */
  62. /*
  63.  *   Detach stuff (doesn't work, somehow!)
  64.  */
  65. struct Task          *globalbuddy ;
  66. ULONG                 globalcreatclisig ;
  67. ULONG                 globalunblanksig ;
  68. ULONG                 globalfrontsig ;
  69. ULONG                 globalnoevents ;
  70. short                 globalcreatsignum ;
  71. short                 globalblanksignum ;
  72. short                 globalreplysignum ;
  73. short                 globalfrontsignum ;
  74. short                 globalkey ;
  75. char                  globalfrontkey[MAXPENDINGSYSTEM] ;
  76. char                  globalfrontqual[MAXPENDINGSYSTEM] ;
  77. short                 globalfrontptr ;
  78. short                 globaldraw ;
  79. short                 globalhelppressed ;
  80. struct Screen        *globalblankscreen ;
  81. #define SHIFT 1
  82. #define NOTCLI 2
  83. #define NOTINTUITION 4
  84. struct hotkey {
  85.    struct hotkey*next ;
  86.    char key, flags ;
  87.    int structlen ;
  88.    char *matchstring, *startstring ;
  89.    char strings[2] ;
  90. } *hotkeys ;
  91. struct Window *lastwindows[200] ;
  92. struct Task *task ;
  93. long taskreply ; /* the signal the line drawing task will return */
  94. #define STACKSIZE (1000)
  95. long stackmem[STACKSIZE/4] ;
  96. struct InfoData *infoptr ;
  97. struct MsgPort *FindPort(), *CreatePort();
  98. void DeletePort();
  99. char *startupfile = STARTUPFILE ;
  100. struct OURMSG {
  101.  struct Message msgpart;
  102.  short key;
  103.  short interval;
  104.  short draw ;
  105.  char cmd[MAXCMD];
  106.  };
  107. short oldtime ;
  108. extern char *strcpy() ;
  109.  
  110. /************************************************************************/
  111. /* the handler subroutine - called through the handler stub             */
  112. /************************************************************************/
  113. extern void HandlerInterface();
  114. void foobar() {
  115. #asm
  116. _HandlerInterface:
  117.     movem.l a4,-(a7)
  118.     movem.L    A0/A1,-(A7)
  119.     jsr    _geta4#
  120.     jsr    _myhandler
  121.     addq.L    #8,A7
  122.     movem.L    (a7)+,a4
  123.     rts
  124. #endasm
  125. }
  126. char keytoasc[128] ;
  127. struct InputEvent *myhandler(ev, gptr)
  128. struct InputEvent *ev;      /* and a pointer to a list of events */
  129. long gptr ; /* ignore */
  130. {
  131.    register struct InputEvent *ep, *laste;
  132.    int key ;
  133.    /*
  134.     * run down the list of events
  135.     * to see if they pressed
  136.     * one of the magic buttons
  137.     */
  138.    for (ep = ev, laste = NULL; ep != NULL; ep = ep->ie_NextEvent) {
  139.       if ((ep->ie_Class == IECLASS_RAWKEY)    &&
  140.              (((ep->ie_Qualifier & IEQUALIFIER_LCOMMAND) &&
  141.                (ep->ie_Code == globalkey)) ||
  142.               (!globalhelppressed && ep->ie_Code == 0x5f) ||
  143.               (globalhelppressed &&
  144.                (ep->ie_Code & 0x80) == 0 &&
  145. /*
  146.  *   All the qualifiers have code = 0x6?; dangerous to take advantage
  147.  *   of?
  148.  */
  149.                (ep->ie_Code & 0xf0) != 0x60 &&
  150.                globalfrontkey[globalfrontptr] == 0 &&
  151.                (globalhelppressed = (keytoasc[ep->ie_Code] != '.'))))) {
  152.          if ((ep->ie_Qualifier & IEQUALIFIER_LCOMMAND) &&
  153.               (ep->ie_Code == globalkey))
  154.             key = -1 ;
  155.          else if (globalhelppressed) {
  156.             globalfrontkey[globalfrontptr] = key = ep->ie_Code ;
  157.             globalfrontqual[globalfrontptr] = ep->ie_Qualifier ;
  158.             globalfrontptr++ ;
  159.             if (globalfrontptr >= MAXPENDINGSYSTEM)
  160.                globalfrontptr = 0 ;
  161.             globalhelppressed = 0 ;
  162.          } else {
  163.             globalhelppressed = 1 ;
  164.             key = 0 ;
  165.          }
  166.          /* we can handle this event so take it off the chain */
  167.          if (laste == NULL)
  168.             ev = ep->ie_NextEvent;
  169.          else
  170.             laste->ie_NextEvent = ep->ie_NextEvent;
  171.          /* now tell him to create the new cli */
  172.          if (key == -1)
  173.             Signal(globalbuddy, globalcreatclisig);
  174.          else if (key > 0)
  175.             Signal(globalbuddy, globalfrontsig);
  176.       } else
  177.          laste = ep;
  178.       if (ep->ie_Class != IECLASS_TIMER) {
  179.          globalnoevents = 0;
  180.          if (globalblankscreen != NULL)
  181.             Signal(globalbuddy, globalunblanksig);
  182.       }
  183.    }
  184.    /* pass on the pointer to the event */
  185.    return(ev);
  186. }
  187.  
  188. /* * * * * * * * * * * EXTERNAL ROUTINES * * * * * * * * * */
  189. struct IntuitionBase *IntuitionBase;
  190. struct GfxBase       *GfxBase;
  191. struct DosLibrary    *DosBase;
  192. struct NewScreen      NewScreen = 
  193.    { 0, 0, 320, 30, 1, 0, 1, NULL, CUSTOMSCREEN, NULL, NULL, NULL, NULL };
  194.  
  195. extern struct MsgPort  *CreatePort();
  196. struct IOStdReq *CreateIOReq();
  197. void DeleteIOReq();
  198.  
  199. /************************************************************************/
  200. /* Queue a timer to go off in a given number of seconds                 */
  201. /************************************************************************/
  202. void QueueTimer(tr,seconds)
  203. register struct timerequest *tr;
  204. ULONG seconds;
  205. {
  206.    tr->tr_node.io_Command = TR_ADDREQUEST;   /* add a new timer request */
  207.    tr->tr_time.tv_secs =  seconds;            /* seconds */
  208.    tr->tr_time.tv_micro = 0;
  209.    SendIO( (struct IORequest *)tr );
  210. }
  211. /*
  212.  *   A utility to change our priority.
  213.  */
  214. prito(n)
  215. int n ;
  216. {
  217.    SetTaskPri(FindTask(0L), (long)n) ;
  218. }
  219. /************************************************************************/
  220. /* the main program to do the popcli stuff                              */
  221. /************************************************************************/
  222. main(argc, argv)
  223. int argc ;
  224. char *argv[] ;
  225. {
  226.    struct MsgPort *port;
  227.    int stay = 0;
  228.    register struct OURMSG *msg;
  229.    int i ;
  230.    char cmdstr[MAXCMD];
  231.    short key, timeout ;
  232.    struct FileHandle *nullfh = NULL ;
  233.    ULONG sig, timersig;
  234.    struct timerequest *timerreq;
  235.    struct MsgPort     *timerport;
  236.    struct MsgPort     *inputDevPort;
  237.    struct IOStdReq    *inputRequestBlock;
  238.    register struct Interrupt handlerStuff;
  239.    char *cmd ;
  240.    int draw = 0 ;
  241.    int nextfront = 0 ;
  242.  
  243.    prito(20) ;
  244.    globalcreatsignum  = -1;
  245.    globalblanksignum  = -1;
  246.    globalreplysignum  = -1;
  247.    globalfrontsignum  = -1;
  248.    globalblankscreen  = NULL;
  249.    globalkey          = DEFKEY ;
  250.    globaldraw         = 1 ;
  251.    timerreq            = NULL;
  252.    timerport           = NULL;
  253.    inputDevPort        = NULL;
  254.    inputRequestBlock   = NULL;
  255.    /* now see if we are already installed */
  256.    if ((port = FindPort(PORTNAME)) == NULL) {
  257.       stay = 1; /* remember to hang around when we are done */
  258.       /* not installed, we need to install our own port */
  259.       if ((port = CreatePort(PORTNAME,0L)) == NULL)
  260.          goto abort;
  261.    }
  262. /*
  263.  *   If we are hanging around, initialize our keyboard translation table.
  264.  *   If we have difficulty, exit angry.
  265.  */
  266.    if (stay)
  267.       if (initkeytoasc())
  268.          goto abort ;
  269.    /* now send the parameter to the waiting program */
  270.    if ((msg = (struct OURMSG *)
  271.        AllocMem((long)sizeof(struct OURMSG), MEMF_CLEAR|MEMF_PUBLIC)) == NULL)
  272.       goto abort;
  273.    if ((infoptr = (struct InfoData *)
  274.       AllocMem((long)sizeof(struct InfoData), MEMF_CLEAR)) == NULL)
  275.       goto abort ;
  276.    /* fill in the message information */
  277.    msg->msgpart.mn_Length = sizeof(struct OURMSG);
  278.    strcpy(cmdstr, DEFCMD);
  279.    timeout = -1 ;
  280.    key = 0 ;
  281.    msg->cmd[0] = 0;
  282.    /* if we were run from CLI then output our banner and process parameters */
  283.    if (argc > 0) {
  284.       /* display our copyright */
  285.       if (stay)
  286.          puts("Mackie 1.3 by Tomas Rokicki - Copyright \xa9 1987-9 Radical Eye Software") ;
  287.       if (argc == 1)
  288.          puts("Usage: Mackie [-q] [-l] [-b] [-f startup] [time] [\"command\"]") ;
  289.       argc-- ;
  290.       argv++ ;
  291.       while (argc > 0) {
  292.          cmd = argv[0] ;
  293.          if (*cmd == '-') {
  294.             cmd++ ;
  295.             switch (*cmd) {
  296. case 'q' : case 'Q' :
  297.                key = -1 ;
  298.                puts("\x9B1mMackie\x9B0m Terminating") ;
  299.                break ;
  300. case 'l' : case 'L' :
  301.                draw = 1 ;
  302.                break ;
  303. case 'b' : case 'B' :
  304.                draw = -1 ;
  305.                break ;
  306. case 'f' : case 'F' :
  307.                if (cmd[1])
  308.                   startupfile = cmd + 1 ;
  309.                else {
  310.                   argv++ ;
  311.                   argc-- ;
  312.                   startupfile = argv[0] ;
  313.                }
  314.                break ;
  315. default :
  316.                puts("Error in parameter!") ;
  317.             }
  318.          } else if ('0' <= *cmd && *cmd <= '9') {
  319.             timeout = 0;
  320.             while ((*cmd >= '0') && (*cmd <= '9'))
  321.                timeout = (timeout*10) + *cmd++ - '0';
  322.             if (timeout < 0)
  323.                timeout = DEFTIME;
  324.          } else {
  325.             strcpy(msg->cmd, cmd) ;
  326.          }
  327.          argc-- ;
  328.          argv++ ;
  329.       }
  330.    }
  331.    msg->interval = timeout;
  332.    msg->key = key;
  333.    msg->draw = draw ;
  334.    if (stay)
  335.       processstartup(startupfile, msg) ;
  336.    if (draw)
  337.       globaldraw = draw ;
  338.    PutMsg(port,(struct Message *)msg);
  339.    if (!stay) goto abort;
  340.    if (timeout == -1)
  341.       timeout = DEFTIME ;
  342.    globalblankscreen = NULL;
  343.    globalbuddy = FindTask(0L);
  344.    globalnoevents = 0;
  345.    nullfh = Open("NIL:", MODE_NEWFILE);
  346.    if (((inputDevPort = CreatePort(0L,0L)) == NULL) ||
  347.       ((inputRequestBlock =
  348.           CreateIOReq(inputDevPort, (long)sizeof(struct IOStdReq))) == NULL) ||
  349.       ((timerport = CreatePort(0L,0L)) == NULL) ||
  350.       ((timerreq  = (struct timerequest *)
  351.           CreateIOReq(timerport, (long)sizeof(struct timerequest))) == NULL))
  352.          goto abort ;
  353.    if (((globalcreatsignum = AllocSignal(-1L)) == -1) ||
  354.       ((globalblanksignum = AllocSignal(-1L)) == -1) ||
  355.       ((globalreplysignum = AllocSignal(-1L)) == -1) ||
  356.       ((globalfrontsignum = AllocSignal(-1L)) == -1) ||
  357.       ((GfxBase = (struct GfxBase *)
  358.                   OpenLibrary("graphics.library", 0L)) == NULL) ||
  359.       ((IntuitionBase = (struct IntuitionBase *)
  360.                         OpenLibrary("intuition.library", 0L)) == NULL) ||
  361.       OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *)timerreq, 0L) ||
  362.       OpenDevice("input.device",0L,(struct IORequest *)inputRequestBlock,0L))
  363.          goto abort;
  364.    handlerStuff.is_Data = (APTR)0L ;
  365.    handlerStuff.is_Code = HandlerInterface;
  366.    handlerStuff.is_Node.ln_Pri = 51;
  367.    timersig            = (1L << timerport->mp_SigBit);
  368.    globalcreatclisig  = 1L << globalcreatsignum;
  369.    globalunblanksig   = 1L << globalblanksignum;
  370.    globalfrontsig     = 1L << globalfrontsignum;
  371.    inputRequestBlock->io_Command = IND_ADDHANDLER;
  372.    inputRequestBlock->io_Data    = (APTR)&handlerStuff;
  373.    DoIO((struct IORequest *)inputRequestBlock);
  374.    QueueTimer(timerreq, TIMEINTERVAL);
  375.    for(;;) {         /* FOREVER */
  376.       sig = Wait( globalcreatclisig | globalunblanksig | timersig |
  377.                   globalfrontsig);
  378.       /* see if they asked us to change the interval */
  379.       if ((msg = (struct OURMSG *)GetMsg(port)) != NULL) {
  380.          if (msg->cmd[0]) strcpy(cmdstr, msg->cmd);
  381.          if (msg->key)
  382.             globalkey = msg->key;
  383.          if (msg->interval != -1)
  384.             timeout    = msg->interval;
  385.          if (msg->draw)
  386.             globaldraw = msg->draw ;
  387.          FreeMem((char *)msg, (long)msg->msgpart.mn_Length);
  388.          if (msg->key == -1) goto abort;
  389.       }
  390.       if ((sig & globalunblanksig) && globalblankscreen)
  391.          screenunblank() ;
  392.       if (sig & globalcreatclisig) {
  393.          WBenchToFront();
  394.          prito(0) ;
  395.          (void)Execute(cmdstr,nullfh,nullfh);
  396.          prito(20) ;
  397.       }
  398.       if (sig & globalfrontsig) {
  399.          while (i=globalfrontkey[nextfront]) {
  400.             windowtofront(keytoasc[i], globalfrontqual[nextfront]) ;
  401.             globalfrontkey[nextfront] = 0 ;
  402.             nextfront++ ;
  403.             if (nextfront >= MAXPENDINGSYSTEM)
  404.                nextfront = 0 ;
  405.          }
  406.       }
  407.       if (sig & timersig) {
  408.          /* get rid of the message */
  409.          oldtime++ ;
  410.          (void)GetMsg(timerport);
  411.          QueueTimer(timerreq, TIMEINTERVAL);
  412.          if (task)
  413.             SetTaskPri(task, 10L) ;
  414.          if (timeout != 0 && (globalnoevents++ >= timeout) && (globalblankscreen == NULL))
  415.             blankscreen() ;
  416.       }
  417.    }
  418. abort:
  419.    if (infoptr) {
  420.       FreeMem(infoptr, (long)sizeof(struct InfoData)) ;
  421.       infoptr = NULL ;
  422.    }
  423.    if (timerreq != NULL) {
  424.       if (timerreq->tr_node.io_Device != NULL)
  425.          CloseDevice((struct IORequest *)timerreq);
  426.       DeleteIOReq((struct IOStdReq *)timerreq);
  427.    }
  428.    if (inputRequestBlock != NULL) {
  429.       if (inputRequestBlock->io_Device != NULL) {
  430.          inputRequestBlock->io_Command = IND_REMHANDLER;
  431.          inputRequestBlock->io_Data = (APTR)&handlerStuff;
  432.          DoIO((struct IORequest *)inputRequestBlock);
  433.          CloseDevice((struct IORequest *)inputRequestBlock);
  434.       }
  435.       DeleteIOReq(inputRequestBlock);
  436.    }
  437.    screenunblank() ;
  438.    if (timerport != NULL)          DeletePort(timerport);
  439.    if (globalcreatsignum != -1)   FreeSignal(globalcreatsignum);
  440.    if (globalblanksignum != -1)   FreeSignal(globalblanksignum);
  441.    if (globalreplysignum != -1)   FreeSignal(globalreplysignum);
  442.    if (globalfrontsignum != -1)   FreeSignal(globalfrontsignum);
  443.    if (IntuitionBase != NULL)      CloseLibrary((struct Library *)IntuitionBase);
  444.    if (GfxBase != NULL)            CloseLibrary((struct Library *)GfxBase);
  445.    if (inputDevPort != NULL)       DeletePort(inputDevPort);
  446.    if (stay && (port != NULL))     DeletePort(port);
  447.    {
  448.       struct hotkey *hk ;
  449.  
  450.       while (hotkeys) {
  451.          hk = hotkeys->next ;
  452.          FreeMem(hotkeys, (long)hotkeys->structlen) ;
  453.          hotkeys = hk ;
  454.       }
  455.    }
  456.    if (nullfh)                     Close(nullfh);
  457.    prito(0) ;
  458. }
  459.  
  460. struct IOStdReq *
  461. CreateIOReq(port, size)
  462. struct MsgPort *port;
  463. long size;
  464. {
  465.    register struct IOStdReq *ioReq;
  466.  
  467.    if ((ioReq = (struct IOStdReq *)
  468.                 AllocMem(size, MEMF_CLEAR | MEMF_PUBLIC)) != NULL) {
  469.       ioReq->io_Message.mn_Node.ln_Type = NT_MESSAGE;
  470.       ioReq->io_Message.mn_Node.ln_Pri  = 0;
  471.       ioReq->io_Message.mn_Length       = size;
  472.       ioReq->io_Message.mn_ReplyPort    = port;
  473.    }
  474.    return(ioReq);
  475. }
  476.  
  477. void DeleteIOReq(ioReq)
  478. register struct IOStdReq *ioReq;
  479. {
  480.    ioReq->io_Message.mn_Node.ln_Type = 0xff;
  481.    ioReq->io_Device = (struct Device *) -1;
  482.    ioReq->io_Unit = (struct Unit *) -1;
  483.    FreeMem( (char *)ioReq, (long)ioReq->io_Message.mn_Length);
  484. }
  485. /*
  486.  *   All of this stuff down here was written by Tomas Rokicki.
  487.  *   (C) Copyright 1987, 1988, Radical Eye Software.
  488.  */
  489. #include "graphics/gfxbase.h"
  490. /*
  491.  *   The maximum number of lines on the screen at once.
  492.  */
  493. #define MAXLINES (50)
  494. #define MAXPOINTS (10)
  495. int maxpoints ;
  496. /*
  497.  *   The external variables we access.
  498.  */
  499. struct RastPort *rastport ;
  500. short screenheight, screenwidth ;
  501. /*
  502.  *   Some locals to this file.
  503.  */
  504. static struct NewScreen newscreen = {
  505.    0, 0,
  506.    640, 400,
  507.    1,
  508.    0, 1,
  509.    HIRES | LACE | SCREENQUIET,
  510.    CUSTOMSCREEN,
  511.    NULL,
  512.    NULL,
  513.    NULL,
  514.    NULL } ;
  515. /*
  516.  *   This routine opens a screen and fires off the task if apropriate.
  517.  */
  518. void taskrout() ;
  519. blankscreen() {
  520.    register struct Task *rtask ;
  521.  
  522.    screenheight = 2 * GfxBase->NormalDisplayRows ;
  523.    screenwidth = GfxBase->NormalDisplayColumns ;
  524.    newscreen.Height = screenheight ;
  525.    newscreen.Width = screenwidth ;
  526.    if (globaldraw == -1 || AvailMem(MEMF_CHIP) < 70000L ||
  527.              (globalblankscreen = OpenScreen(&newscreen)) == NULL) {
  528.       if ((globalblankscreen = OpenScreen(&NewScreen)) != NULL) {
  529.          SetRGB4(&(globalblankscreen->ViewPort), 0L, 0L, 0L, 0L);
  530.          OFF_DISPLAY ;
  531.       }
  532.    } else {
  533.       if (globalblankscreen == NULL &&
  534.           (globalblankscreen = OpenScreen(&newscreen))==NULL)
  535.          return ;
  536. /*
  537.  *   Turning off the sprites is a little bit tricky.  A simple OFF_SPRITE
  538.  *   will continue to display the data in the current sprite registers.
  539.  *   This happens most often with the cursor.  To fix, we simply clear out
  540.  *   the sprite control registers after turning the sprites off.  This
  541.  *   might break all of the sprites when the system comes back up . . .
  542.  */
  543.       OFF_SPRITE ;
  544.       custom.spr[0].ctl = 0 ;
  545.       custom.spr[1].ctl = 0 ;
  546.       custom.spr[2].ctl = 0 ;
  547.       custom.spr[3].ctl = 0 ;
  548.       custom.spr[4].ctl = 0 ;
  549.       custom.spr[5].ctl = 0 ;
  550.       custom.spr[6].ctl = 0 ;
  551.       custom.spr[7].ctl = 0 ;
  552.       SetRGB4(&(globalblankscreen->ViewPort), 0L, 0L, 0L, 0L) ;
  553.       rastport = &(globalblankscreen->RastPort) ;
  554.       SetAPen(rastport, 0L) ;
  555.       Forbid() ;
  556.       RectFill(rastport, 0L, 0L, (long)screenwidth-1, 30L) ;
  557.       Permit() ;
  558.       SetAPen(rastport, 1L) ;
  559.       rtask = (struct Task *)AllocMem((long)sizeof(struct Task),
  560.                 MEMF_CLEAR | MEMF_PUBLIC) ;
  561.       if (rtask != NULL) {
  562.          rtask->tc_Node.ln_Pri = 10 ;
  563.          rtask->tc_Node.ln_Type = NT_TASK ;
  564.          rtask->tc_Node.ln_Name = "ri.Lines" ;
  565.          rtask->tc_SPLower = (APTR)stackmem ;
  566.          rtask->tc_SPUpper = rtask->tc_SPReg =
  567.                       (APTR)(stackmem + STACKSIZE/4 - 8) ;
  568.          AddTask(rtask, taskrout, 0L) ;
  569.          task = rtask ;
  570.       }
  571.    }
  572. }
  573. /*
  574.  *   Unblank the screen.  We kill the task with the standard ^C kill signal.
  575.  */
  576. screenunblank() {
  577.    if (task != NULL) {
  578.       Signal(task, 1L << SIGBREAKB_CTRL_C) ;
  579.       SetTaskPri(task, 11L) ;
  580.       Wait(1L << globalreplysignum) ;
  581.       RemTask(task);
  582.       FreeMem(task, (long)sizeof(struct Task)) ;
  583.       task = NULL ;
  584.    }
  585.    if (globalblankscreen != NULL) {
  586.       CloseScreen(globalblankscreen);
  587.       globalblankscreen = NULL ;
  588.       ON_DISPLAY ;
  589.       ON_SPRITE ;
  590.    }
  591. }
  592. /*
  593.  *   This routine returns a random value from 0 to n-1.
  594.  */
  595. int randm(i)
  596. int i ;
  597. {
  598.    static long seed ;
  599.    register long rseed ;
  600.    register long rval ;
  601.  
  602.    rseed = seed ;
  603.    if (rseed == 0)
  604.       rseed = 323214521 + globalblankscreen->MouseX +
  605.               globalblankscreen->MouseY ;
  606.    rseed = rseed * 123213 + 121 ;
  607.    rval = (rseed >> 5) & 65535 ;
  608.    seed = rseed ;
  609.    return ((i * rval) >> 16) ;
  610. }
  611. /*
  612.  *   This routine sets x and y values to a random number.
  613.  */
  614. static long x, y ;
  615. randomxy() {
  616.    x = randm(screenwidth) ;
  617.    y = randm(screenheight) ;
  618. }
  619. /*
  620.  *   Main routines are always fun.
  621.  */
  622. struct box {
  623.    short x[MAXPOINTS], y[MAXPOINTS] ;
  624. } store[MAXLINES] ;
  625. #define FIX(x) (((long)(x)) << 7)
  626. #define FIXH(x) (((long)((*(x)+(x)[1])>>1)) << 7)
  627. #define UNFIX(x) ((x)>>7)
  628. struct box *ptr ;
  629. struct box *eptr ;
  630. int numlines ;
  631. int mdelta = -1 ;
  632. int maxlines = MAXLINES/2 ;
  633. short dx[MAXPOINTS], dy[MAXPOINTS] ;
  634. short ox[MAXPOINTS], oy[MAXPOINTS] ;
  635. short nx[MAXPOINTS], ny[MAXPOINTS] ;
  636. short dr, dg, db ;
  637. short or, og, ob ;
  638. short nr, ng, nb ;
  639. long oldx, oldy, oldwidth, oldptr ;
  640. int oldcol ;
  641. /*
  642.  *   Draws a spline!  Expects all arguments in registers.
  643.  */
  644. #asm
  645.     public    _Draw
  646.     cseg
  647. rspline
  648.     move.l    a0,d0
  649.     sub.l    d6,d0
  650.     move.l    d0,d3
  651.     bpl    save1
  652.     neg.l    d0
  653. save1
  654.     move.l    a1,d1
  655.     sub.l    d7,d1
  656.     move.l    d1,d4
  657.     bpl    save2
  658.     neg.l    d1
  659. save2
  660.     move.l    d0,d2
  661.     cmp.l    d0,d1
  662.     bmi    save3
  663.     lsr.l    #3,d2
  664.     bra    save9
  665. save3
  666.     lsr.l    #3,d1
  667. save9
  668.     add.l    d1,d2
  669.     asr.l    #3,d2
  670.     beq    check2
  671.     asr.l    #5,d3
  672.     asr.l    #5,d4
  673.     move.l    a2,d0
  674.     sub.l    a0,d0
  675.     move.l    a3,d1
  676.     sub.l    a1,d1
  677.     asr.l    #5,d0
  678.     asr.l    #5,d1
  679.     muls.w    d4,d0
  680.     muls.w    d3,d1
  681.     sub.l    d1,d0
  682.     bpl    save4
  683.     neg.l    d0
  684. save4
  685.     cmp.l    d0,d2
  686.     ble    pushem
  687.     move.l    a5,d0
  688.     sub.l    a0,d0
  689.     move.l    a6,d1
  690.     sub.l    a1,d1
  691.     asr.l    #5,d0
  692.     asr.l    #5,d1
  693.     muls.w    d4,d0
  694.     muls.w    d3,d1
  695.     sub.l    d1,d0
  696.     bpl    save5
  697.     neg.l    d0
  698. save5
  699.     cmp.l    d0,d2
  700.     ble    pushem
  701. makeline
  702.     lsr.l    #7,d7
  703.     move.l    d7,d1
  704.     lsr.l    #7,d6
  705.     move.l    d6,d0
  706.     movem.l    d2-d5/a0-a1,-(sp)
  707.     move.l    _oldx,d2
  708.     move.l    _oldy,d3
  709.     move.l    d0,_oldx
  710.     move.l    d1,_oldy
  711.     move.l    _oldwidth,d4
  712.     move.l    _oldptr,a0
  713.     jsr    mdraw
  714.     movem.l    (sp)+,d2-d5/a0-a1
  715.     rts
  716. check2
  717.     move.l    a0,d0
  718.     sub.l    a2,d0
  719.     bpl    ch1
  720.     neg.l    d0
  721. ch1
  722.     move.l    a1,d1
  723.     sub.l    a3,d1
  724.     bpl    ch2
  725.     neg.l    d1
  726. ch2
  727.     add.l    d0,d1
  728.     asr.l    #3,d1
  729.     bne    pushem
  730.     move.l    a0,d0
  731.     sub.l    a5,d0
  732.     bpl    ch3
  733.     neg.l    d0
  734. ch3
  735.     move.l    a1,d1
  736.     sub.l    a6,d1
  737.     bpl    ch4
  738.     neg.l    d1
  739. ch4
  740.     add.l    d0,d1
  741.     asr.l    #3,d1
  742.     beq    makeline
  743. pushem
  744.     movem.l    d6/d7,-(sp)
  745.     move.l    a5,d0
  746.     add.l    d6,d0
  747.     asr.l    #1,d0
  748.     move.l    a6,d1
  749.     add.l    d7,d1
  750.     asr.l    #1,d1
  751.     movem.l    d0/d1,-(sp)
  752.     move.l    a2,d2
  753.     add.l    a5,d2
  754.     asr.l    #1,d2
  755.     move.l    a3,d3
  756.     add.l    a6,d3
  757.     asr.l    #1,d3
  758.     move.l    d0,d4
  759.     add.l    d2,d4
  760.     asr.l    #1,d4
  761.     move.l    d1,d5
  762.     add.l    d3,d5
  763.     asr.l    #1,d5
  764.     movem.l    d4/d5,-(sp)
  765.     move.l    a0,d6
  766.     add.l    a2,d6
  767.     asr.l    #1,d6
  768.     move.l    a1,d7
  769.     add.l    a3,d7
  770.     asr.l    #1,d7
  771.     move.l    d2,d0
  772.     add.l    d6,d0
  773.     asr.l    #1,d0
  774.     move.l    d3,d1
  775.     add.l    d7,d1
  776.     asr.l    #1,d1
  777.     move.l    d6,a2
  778.     move.l    d7,a3
  779.     move.l    d0,d6
  780.     add.l    d4,d6
  781.     asr.l    #1,d6
  782.     move.l    d1,d7
  783.     add.l    d5,d7
  784.     asr.l    #1,d7
  785.     movem.l    d6/d7,-(sp)
  786.     move.l    d0,a5
  787.     move.l    d1,a6
  788.     jsr    rspline
  789.     movem.l    (sp)+,a0/a1
  790.     movem.l    (sp)+,a2/a3/a5/a6
  791.     movem.l    (sp)+,d6/d7
  792.     bra    rspline
  793. ;
  794.     include 'exec/types.i'
  795.     include 'hardware/custom.i'
  796.     include 'hardware/blit.i'
  797.     include 'hardware/dmabits.i'
  798. ;
  799.     xref    _custom
  800. ;
  801. ;
  802. ;   Our entry point.
  803. ;
  804. mdraw:
  805.     move.l    #$dff000,a1    ; Manx requires this
  806.     sub.w    d0,d2        ; calculate dx
  807.     bmi    xneg        ; if negative, octant is one of [3,4,5,6]
  808.     sub.w    d1,d3        ; calculate dy   ''   is one of [1,2,7,8]
  809.     bmi    yneg        ; if negative, octant is one of [7,8]
  810.     cmp.w    d3,d2        ; cmp |dx|,|dy|  ''   is one of [1,2]
  811.     bmi    ygtx        ; if y>x, octant is 2
  812.     moveq.l    #OCTANT1+LINEMODE,d5    ; otherwise octant is 1
  813.     bra    lineagain    ; go to the common section
  814. ygtx:
  815.     exg    d2,d3        ; X must be greater than Y
  816.     moveq.l    #OCTANT2+LINEMODE,d5    ; we are in octant 2
  817.     bra    lineagain    ; and common again.
  818. yneg:
  819.     neg.w    d3        ; calculate abs(dy)
  820.     cmp.w    d3,d2        ; cmp |dx|,|dy|, octant is [7,8]
  821.     bmi    ynygtx        ; if y>x, octant is 7
  822.     moveq.l    #OCTANT8+LINEMODE,d5    ; otherwise octant is 8
  823.     bra    lineagain
  824. ynygtx:
  825.     exg    d2,d3        ; X must be greater than Y
  826.     moveq.l    #OCTANT7+LINEMODE,d5    ; we are in octant 7
  827.     bra    lineagain
  828. xneg:
  829.     neg.w    d2        ; dx was negative! octant is [3,4,5,6]
  830.     sub.w    d1,d3        ; we calculate dy
  831.     bmi    xyneg        ; if negative, octant is one of [5,6]
  832.     cmp.w    d3,d2        ; otherwise it's one of [3,4]
  833.     bmi    xnygtx        ; if y>x, octant is 3
  834.     moveq.l    #OCTANT4+LINEMODE,d5    ; otherwise it's 4
  835.     bra    lineagain
  836. xnygtx:
  837.     exg    d2,d3        ; X must be greater than Y
  838.     moveq.l    #OCTANT3+LINEMODE,d5    ; we are in octant 3
  839.     bra    lineagain
  840. waitmore:
  841.     nop
  842.     nop
  843.     btst    #DMAB_BLTDONE-8,dmaconr(a1)
  844.     beq    donewait
  845.     bra    waitmore
  846. xyneg:
  847.     neg.w    d3        ; y was negative, in one of [5,6]
  848.     cmp.w    d3,d2        ; is y>x?
  849.     bmi    xynygtx        ; if so, octant is 6
  850.     moveq.l    #OCTANT5+LINEMODE,d5    ; otherwise, octant is 5
  851.     bra    lineagain
  852. xynygtx:
  853.     exg    d2,d3        ; X must be greater than Y
  854.     moveq.l    #OCTANT6+LINEMODE,d5    ; we are in octant 6
  855. lineagain:
  856.     mulu.w    d4,d1        ; Calculate y1 * width
  857.     ror.l    #4,d0        ; move upper four bits into hi word
  858.     add.w    d0,d0        ; multiply by 2
  859.     add.l    d1,a0        ; ptr += (x1 >> 3)
  860.     add.w    d0,a0        ; ptr += y1 * width
  861.     swap    d0        ; get the four bits of x1
  862.     or.w    _oldcol,d0    ; or with USEA, USEC, USED, F=A~C+~AC
  863.     lsl.w    #2,d3        ; Y = 4 * Y
  864.     add.w    d2,d2        ; X = 2 * X
  865.     move.w    d2,d1        ; set up size word
  866.     lsl.w    #5,d1        ; shift five left
  867.     add.w    #$42,d1        ; and add 1 to height, 2 to width
  868.     btst    #DMAB_BLTDONE-8,dmaconr(a1)    ; safety check
  869. waitblit:
  870.     btst    #DMAB_BLTDONE-8,dmaconr(a1)    ; wait for blitter
  871.     bne    waitmore
  872. donewait:
  873.     move.w    d3,bltbmod(a1)    ; B mod = 4 * Y
  874.     sub.w    d2,d3
  875.     ext.l    d3
  876.     move.l    d3,bltapt(a1)    ; A ptr = 4 * Y - 2 * X
  877.     bpl    lineover    ; if negative,
  878.     or.w    #SIGNFLAG,d5    ; set sign bit in con1
  879. lineover:
  880.     move.w    d0,bltcon0(a1)    ; write control registers
  881.     move.w    d5,bltcon1(a1)
  882.     move.w    d4,bltcmod(a1)    ; C mod = bitplane width
  883.     move.w    d4,bltdmod(a1)    ; D mod = bitplane width
  884.     sub.w    d2,d3
  885.     move.w    d3,bltamod(a1)    ; A mod = 4 * Y - 4 * X
  886.     move.w    #$8000,bltadat(a1)    ; A data = 0x8000
  887.     moveq.l    #-1,d5        ; Set masks to all ones
  888.     move.l    d5,bltafwm(a1)    ; we can hit both masks at once
  889.     move.l    a0,bltcpt(a1)    ; Pointer to first pixel to set
  890.     move.l    a0,bltdpt(a1)
  891.     move.w    d1,bltsize(a1)    ; Start blit
  892.     rts            ; and return, blit still in progress.
  893. #endasm
  894. /*
  895.  *   Now our linkage to the spline routine.  Parameters are in 8(a5)...
  896.  */
  897. int drawspline(x1, y1, x2, y2, x3, y3, x4, y4)
  898. long x1, y1, x2, y2, x3, y3, x4, y4 ;
  899. {
  900. #asm
  901.     movem.l    saver,-(sp)
  902.     move.l    8(a5),a0
  903.     move.l    12(a5),a1
  904.     move.l    16(a5),a2
  905.     move.l    20(a5),a3
  906.     move.l    28(a5),a6
  907.     move.l    32(a5),d6
  908.     move.l    36(a5),d7
  909.     move.l    24(a5),a5
  910.     jsr    rspline
  911.     movem.l    (sp)+,saver
  912. saver    reg    d0-d7/a0-a6
  913. #endasm
  914. }
  915. int closed ;
  916. char *nextlegal[] = { "01458", "236", "01458", "236", "01458", "23", "01458",
  917.                       "", "0145" } ;
  918. int advval[] = { 3, 2, 3, 2, 1, 0, 1, 0, 1 } ;
  919. unsigned char realfunc[14] ;
  920. char namefunc[20] ;
  921. struct IntuiText itext = { 1, 0, JAM1, 0, 0, NULL, (UBYTE *)&namefunc } ;
  922. saytext()
  923. {
  924.    PrintIText(rastport, &itext, 10L, 14L) ;
  925. }
  926. makefunc() {
  927.    register int i ;
  928.    register int goallen ;
  929.    register int sofar = 0 ;
  930.    register unsigned char *p ;
  931.    register char *nextpossib ;
  932.  
  933.    closed = randm(3) ;
  934.    switch(closed) {
  935. case 2:
  936.       goallen = 2 + randm(3) ;
  937.       break ;
  938. case 1:
  939.       goallen = 3 + randm(6) ;
  940.       break ;
  941. case 0:
  942.       goallen = 1 + randm(7) ;
  943.       break ;
  944.    }
  945.    while (1) {
  946.       if (closed == 0)
  947.          nextpossib = "0145" ;
  948.       else
  949.          nextpossib = "0123456" ;
  950.       sofar = 0 ;
  951.       p = realfunc ;
  952.       while (sofar < goallen) {
  953.          i = nextpossib[randm(strlen(nextpossib))] - '0' ;
  954.          *p++ = i ;
  955.          nextpossib = nextlegal[i] ;
  956.          sofar += advval[i] ;
  957.       }
  958.       if (sofar == goallen) {
  959.          if (closed == 0) {
  960.             if (nextpossib[0] == '0')
  961.                break ;
  962.          } else {
  963.             if (*nextpossib == '0' || realfunc[0] < 4 || *(p-1) < 4) {
  964.                if ((*nextpossib == '0') ?
  965.                       ((realfunc[0] & 2) != 0) : ((realfunc[0] & 2) == 0)) {
  966.                   if (realfunc[0] != 5) {
  967.                      realfunc[0] ^= 2 ;
  968.                      break ;
  969.                   }
  970.                } else {
  971.                   break ;
  972.                }
  973.             }
  974.          }
  975.       }
  976.    }
  977.    *p = 100 ;
  978.    maxpoints = goallen ;
  979.    switch (closed) {
  980. case 2:
  981.       for (i=0; i<p-realfunc; i++)
  982.          p[i] = realfunc[i] ;
  983.       p[p-realfunc] = 100 ;
  984.       break ;
  985. case 1:
  986.       break ;
  987. case 0:
  988.       maxpoints++ ;
  989.       break ;
  990.    }
  991.    for (i=0, p=realfunc; *p < 100; p++, i++)
  992.       namefunc[i] = *p + '0' ;
  993.    namefunc[i++] = ' ' ;
  994.    namefunc[i++] = '0' + closed ;
  995.    namefunc[i++] = ' ' ;
  996.    namefunc[i++] = '0' + maxpoints ;
  997.    namefunc[i] = 0 ;
  998. }
  999. #define HALF(a) ((*(a)+(a)[1])>>1)
  1000. draw_s_f(xptr, yptr)
  1001. register short *xptr, *yptr ;
  1002. {
  1003.    oldx = HALF(xptr) ;
  1004.    oldy = HALF(yptr) ;
  1005.    OwnBlitter() ;
  1006.    drawspline(FIX(oldx), FIX(oldy), FIX(xptr[1]), FIX(yptr[1]),
  1007.               FIX(xptr[2]), FIX(yptr[2]), FIXH(xptr+2), FIXH(yptr+2)) ;
  1008.    DisownBlitter() ;
  1009. }
  1010. draw_sf(xptr, yptr)
  1011. register short *xptr, *yptr ;
  1012. {
  1013.    oldx = HALF(xptr) ;
  1014.    oldy = HALF(yptr) ;
  1015.    OwnBlitter() ;
  1016.    drawspline(FIX(oldx), FIX(oldy), FIX(xptr[1]), FIX(yptr[1]),
  1017.               FIX(xptr[2]), FIX(yptr[2]), FIX(xptr[3]), FIX(yptr[3])) ;
  1018.    DisownBlitter() ;
  1019. }
  1020. draws_f(xptr, yptr)
  1021. register short *xptr, *yptr ;
  1022. {
  1023.    oldx = *xptr ;
  1024.    oldy = *yptr ;
  1025.    OwnBlitter() ;
  1026.    drawspline(FIX(*xptr), FIX(*yptr), FIX(xptr[1]), FIX(yptr[1]),
  1027.               FIX(xptr[2]), FIX(yptr[2]), FIXH(xptr+2), FIXH(yptr+2)) ;
  1028.    DisownBlitter() ;
  1029. }
  1030. drawsf(xptr, yptr)
  1031. register short *xptr, *yptr ;
  1032. {
  1033.    oldx = *xptr ;
  1034.    oldy = *yptr ;
  1035.    OwnBlitter() ;
  1036.    drawspline(FIX(*xptr), FIX(*yptr), FIX(xptr[1]), FIX(yptr[1]),
  1037.               FIX(xptr[2]), FIX(yptr[2]), FIX(xptr[3]), FIX(yptr[3])) ;
  1038.    DisownBlitter() ;
  1039. }
  1040. draw_lf(xptr, yptr)
  1041. register short *xptr, *yptr ;
  1042. {
  1043.    Move(rastport, (long)HALF(xptr), (long)HALF(yptr)) ;
  1044.    xptr++ ;
  1045.    yptr++ ;
  1046.    Draw(rastport, (long)*xptr, (long)*yptr) ;
  1047. }
  1048. drawl_f(xptr, yptr)
  1049. register short *xptr, *yptr ;
  1050. {
  1051.    Move(rastport, (long)*xptr, (long)*yptr) ;
  1052.    Draw(rastport, (long)HALF(xptr), (long)HALF(yptr)) ;
  1053. }
  1054. drawlf(xptr, yptr)
  1055. register short *xptr, *yptr ;
  1056. {
  1057.    Move(rastport, (long)*xptr, (long)*yptr) ;
  1058.    xptr++ ;
  1059.    yptr++ ;
  1060.    Draw(rastport, (long)*xptr, (long)*yptr) ;
  1061. }
  1062. drawnlf() {}
  1063. int (*funcs[])() = { &drawsf, &draws_f, &draw_sf, &draw_s_f,
  1064.                      &drawlf, &drawl_f, &draw_lf, NULL, &drawnlf } ;
  1065. drawfunc(bptr)
  1066. register struct box *bptr ;
  1067. {
  1068.    register long i ;
  1069.    register short *x, *y ;
  1070.    register unsigned char *p ;
  1071.  
  1072. /* saytext() ; */
  1073.    oldwidth = rastport->BitMap->BytesPerRow ;
  1074.    oldptr = (long)rastport->BitMap->Planes[0] ;
  1075.    switch(closed) {
  1076. case 2:
  1077.       for (i=0, x=&(bptr->x[0]), y=&(bptr->y[0]); i<maxpoints; i++, x++, y++) {
  1078.          x[maxpoints] = screenwidth - 1 - *x ;
  1079.          y[maxpoints] = screenheight - 1 - *y ;
  1080.       }
  1081. setup:
  1082.       x[maxpoints] = bptr->x[0] ;
  1083.       y[maxpoints] = bptr->y[0] ;
  1084.       x++, y++ ;
  1085.       x[maxpoints] = bptr->x[1] ;
  1086.       y[maxpoints] = bptr->y[1] ;
  1087.       break ;
  1088. case 1:
  1089.       x = &(bptr->x[0]) ;
  1090.       y = &(bptr->y[0]) ;
  1091.       goto setup ;
  1092.    }
  1093.    p = realfunc ;
  1094.    x = &(bptr->x[0]) ;
  1095.    y = &(bptr->y[0]) ;
  1096.    while (*p < 20) {
  1097.       (funcs[*p])(x, y) ;
  1098.       i = advval[*p] ;
  1099.       x += i ;
  1100.       y += i ;
  1101.       p++ ;
  1102.    }
  1103. }
  1104. /*
  1105.  *   Initialize things for the first lines.
  1106.  */
  1107. startlines() {
  1108.    register int i ;
  1109.  
  1110.    ptr = store ;
  1111.    eptr = store ;
  1112.    numlines = 0 ;
  1113.    if (dx[0] == 0) {
  1114.       for (i=0; i<MAXPOINTS; i++) {
  1115.          ox[i] = randm(screenwidth) ;
  1116.      oy[i] = randm(screenheight) ;
  1117.      dx[i] = 2 + randm(3) ;
  1118.      dy[i] = 2 + randm(3) ;
  1119.       }
  1120.    }
  1121.    nr = 53 ;
  1122.    ng = 33 ;
  1123.    nb = 35 ;
  1124.    dr = -3 ;
  1125.    dg = 5 ;
  1126.    db = 7 ;
  1127.    SetRGB4(&(globalblankscreen->ViewPort), 0L, 0L, 0L, 0L) ;
  1128.    SetRGB4(&(globalblankscreen->ViewPort), 1L, (long)(nr >> 3),
  1129.                                  (long)(ng >> 3), (long)(nb >> 3)) ;
  1130.    for (i=0; i<maxlines; i++) {
  1131.       advancelines() ;
  1132.       drawnew() ;
  1133.    }
  1134. }
  1135. /*
  1136.  *   Advance the number by the delta, and check the boundaries.
  1137.  */
  1138. adv(o, d, n, w)
  1139. register short *o, *d, *n ;
  1140. short w ;
  1141. {
  1142.    *n = *o + *d ;
  1143.    if (*n < 0) {
  1144.       *n = 0 ;
  1145.       *d = randm(6) + 1 ;
  1146.    } else if (*n >= w) {
  1147.       *n = w - 1 ;
  1148.       *d = - randm(6) - 1 ;
  1149.    }
  1150. }
  1151. /*
  1152.  *   Advance the two points which make up the lines.
  1153.  */
  1154. advancelines() {
  1155.    register int i ;
  1156.  
  1157.    for (i=0; i<maxpoints; i++) {
  1158.       adv(ox+i, dx+i, nx+i, screenwidth) ;
  1159.       adv(oy+i, dy+i, ny+i, screenheight) ;
  1160.    }
  1161. }
  1162. /*
  1163.  *   Draw a new set of lines.
  1164.  */
  1165. drawnew() {
  1166.    register int i ;
  1167.    register short oldpen ;
  1168.    register struct box *bptr ;
  1169.  
  1170.    while (numlines >= maxlines) {
  1171.       oldpen = rastport->FgPen ;
  1172.       oldcol = 0xb0a ;
  1173.       SetAPen(rastport, 0L) ;
  1174.       bptr = eptr ;
  1175.       drawfunc(bptr) ;
  1176.       oldcol = 0xbfa ;
  1177.       SetAPen(rastport, (long)oldpen) ;
  1178.       numlines-- ;
  1179.       bptr++ ;
  1180.       if (bptr == store + MAXLINES)
  1181.          bptr = store ;
  1182.       eptr = bptr ;
  1183.    }
  1184.    bptr = ptr ;
  1185.    for (i=0; i<maxpoints; i++) {
  1186.       bptr->x[i] = ox[i] = nx[i] ;
  1187.       bptr->y[i] = oy[i] = ny[i] ;
  1188.    }
  1189.    drawfunc(bptr) ;
  1190.    numlines++ ;
  1191.    bptr++ ;
  1192.    if (bptr == store + MAXLINES) {
  1193.       bptr = store ;
  1194.       if (mdelta == 1) {
  1195.          maxlines++ ;
  1196.          if (maxlines >= MAXLINES - 1)
  1197.             mdelta = -1 ;
  1198.       } else {
  1199.          maxlines-- ;
  1200.          if (maxlines <= 2)
  1201.             mdelta = 1 ;
  1202.       }
  1203.    }
  1204.    ptr = bptr ;
  1205. }
  1206. /*
  1207.  *   This routine mucks with the colors.
  1208.  */
  1209. colors() {
  1210.    or = nr ;
  1211.    og = ng ;
  1212.    ob = nb ;
  1213.    adv(&or, &dr, &nr, 128) ;
  1214.    adv(&og, &dg, &ng, 128) ;
  1215.    adv(&ob, &db, &nb, 128) ;
  1216.    SetRGB4(&(globalblankscreen->ViewPort), 1L, (long)(nr >> 3),
  1217.                                     (long)(ng >> 3), (long)(nb >> 3)) ;
  1218. }
  1219. #define settime() {oldtime=0;}
  1220. #define gettime() (oldtime)
  1221. /*
  1222.  *   Our actual task, in an infinite loop.
  1223.  */
  1224. void taskrout() {
  1225.    register struct Task *task ;
  1226.  
  1227.    geta4() ;
  1228.    settime() ;
  1229.    makefunc() ;
  1230.    task = FindTask(0L) ;
  1231.    startlines() ;
  1232.    colors() ;
  1233.    while (SetSignal(0L, 0L)==0) {
  1234.       if (task->tc_Node.ln_Pri == 10)
  1235.          SetTaskPri(task, -20L) ;
  1236.       advancelines() ;
  1237.       drawnew() ;
  1238.       advancelines() ;
  1239.       drawnew() ;
  1240.       if (task->tc_Node.ln_Pri == 10)
  1241.          SetTaskPri(task, -20L) ;
  1242.       advancelines() ;
  1243.       drawnew() ;
  1244.       advancelines() ;
  1245.       drawnew() ;
  1246.       if (task->tc_Node.ln_Pri == 10)
  1247.          SetTaskPri(task, -20L) ;
  1248.       advancelines() ;
  1249.       drawnew() ;
  1250.       advancelines() ;
  1251.       drawnew() ;
  1252.       colors() ;
  1253.       if (gettime() >= 60) {
  1254.          settime() ;
  1255.          makefunc() ;
  1256.          SetRast(rastport, 0L) ;
  1257.          startlines() ;
  1258.       }
  1259.    }
  1260. done:
  1261.    Signal(globalbuddy, 1L << globalreplysignum) ;
  1262.    Wait(0L) ;
  1263. }
  1264. /*
  1265.  *   Now we do hotkey magic to activate windows, bring them to front,
  1266.  *   etc.
  1267.  *
  1268.  *   Now we have a key, so we have to find a process with that name and
  1269.  *   bring her to front.  For now, we just deal with tasks, since the
  1270.  *   CLI stuff is so complicated.
  1271.  */
  1272. #define MAXMATCH (20)
  1273. char simplematch[3] = { ' ', '*', 0 } ;
  1274. struct Window *matchwindows[MAXMATCH] ;
  1275. extern long LockIBase() ;
  1276. windowtofront(key, qual)
  1277. char key ;
  1278. {
  1279.    long foo ;
  1280.    register int i, j ;
  1281.    int n ;
  1282.    register struct Window *w ;
  1283.    struct Screen *s ;
  1284.    struct Process *p ;
  1285.    struct MsgPort **mp ;
  1286.    struct CommandLineInterface *CLI ;
  1287.    int cli ;
  1288.    char *nameptr, *matchptr ;
  1289.    extern struct DosLibrary *DOSBase ;
  1290.    register struct hotkey *hk ;
  1291.    int shift, ctrl ;
  1292.    struct Window *activewindow ;
  1293.  
  1294. /*
  1295.  *   First we look for a matching record.
  1296.  */
  1297.    if (key == '.')
  1298.       goto goner ;
  1299.    shift = ((qual & (IEQUALIFIER_LSHIFT | IEQUALIFIER_RSHIFT)) != 0) ;
  1300.    ctrl = ((qual & IEQUALIFIER_CONTROL) != 0) ;
  1301.    activewindow = NULL ;
  1302.    for (hk=hotkeys; hk; hk=hk->next)
  1303.       if (hk->key == key && 
  1304.           (hk->flags & SHIFT) == shift)
  1305.          break ;
  1306.    cli = 0 ;
  1307.    if (hk && hk->matchstring)
  1308.       matchptr = hk->matchstring ;
  1309.    else {
  1310.       matchptr = simplematch ;
  1311.       if (key == ' ')
  1312.          matchptr++ ;
  1313.       else if ('A' <= key && key <= 'Z')
  1314.          simplematch[0] = key ;
  1315.       else if ('0' <= key && key <= '9') {
  1316.          cli = key ;
  1317.          if (cli == '0')
  1318.             cli += 10 ;
  1319.          matchptr++ ;
  1320.       } else
  1321.          goto goner ;
  1322.    }
  1323.    n = 0 ;
  1324.    foo = LockIBase(0L) ;
  1325.    if (! ctrl && !(hk && (hk->flags & NOTINTUITION)) && !cli) {
  1326.       for (s=IntuitionBase->FirstScreen; s; s=s->NextScreen)
  1327.          for (w=s->FirstWindow; w; w=w->NextWindow) {
  1328.             if (w->UserPort) {
  1329.                p = (struct Process *)(w->UserPort->mp_SigTask) ;
  1330.                if (((struct Task *)p)->tc_Node.ln_Type == NT_PROCESS) {
  1331.                   if (p->pr_CLI) {
  1332.                      CLI = (struct CommandLineInterface *)BSTRtoS(p->pr_CLI) ;
  1333.                      if (bstrcmp(BSTRtoS((CLI)->cli_CommandName), matchptr) &&
  1334.                          n < MAXMATCH) {
  1335.                            if (w==IntuitionBase->ActiveWindow)
  1336.                               activewindow = w ;
  1337.                            matchwindows[n++] = w ;
  1338.                         }
  1339.                   } else {
  1340.                      if (sstrcmp(((struct Task *)p)->tc_Node.ln_Name, matchptr)
  1341.                           && n < MAXMATCH) {
  1342.                         if (w==IntuitionBase->ActiveWindow)
  1343.                            activewindow = w ;
  1344.                         matchwindows[n++] = w ;
  1345.                      }
  1346.                   }
  1347.                }
  1348.             }
  1349.          }
  1350.    }
  1351. /*
  1352.  *   Folks, there are still several/many windows of vulnerability
  1353.  *   here; I'll have to plug them.  For instance, what happens if a
  1354.  *   CLI goes away while we are doing this?  Or what happens if a
  1355.  *   window goes away later, when we are looking at IntuitionBase?
  1356.  */
  1357.    if (! ctrl && !(hk && (hk->flags & NOTCLI))) {
  1358.       mp = (struct MsgPort **)BSTRtoS(*(DOSBase->dl_Root)) ;
  1359.       for (j=1; j<(long)(mp[0]); j++)
  1360.          if (mp[j] && (cli == 0 || j == cli - '0')) {
  1361.             p = (struct Process *)(mp[j]->mp_SigTask) ;
  1362.             CLI = (struct CommandLineInterface *)BSTRtoS(p->pr_CLI) ;
  1363.             if (!CLI->cli_Background &&
  1364.                   bstrcmp(BSTRtoS((CLI)->cli_CommandName), matchptr)) {
  1365.                infoptr->id_VolumeNode = NULL ;
  1366.                dos_packet(p->pr_ConsoleTask, ACTION_DISK_INFO,
  1367.                          ((long)(infoptr)) >> 2, 0L, 0L, 0L, 0L, 0L, 0L) ;
  1368.                if (w=(struct Window *)infoptr->id_VolumeNode)
  1369.                   if (n < MAXMATCH) {
  1370.                      if (w==IntuitionBase->ActiveWindow)
  1371.                         activewindow = w ;
  1372.                      matchwindows[n++] = w ;
  1373.                   }
  1374.             }
  1375.          }
  1376.    }
  1377.    if (shift)
  1378.       key += 100 ;
  1379.    if (ctrl || n==0) {
  1380.       UnlockIBase(foo) ;
  1381.       if (hk == NULL || hk->startstring == NULL)
  1382.          goto goner ;
  1383.       prito(0) ;
  1384.       Execute(hk->startstring, 0L, 0L) ;
  1385.       prito(20) ;
  1386.    } else {
  1387.       if (n == 1) {
  1388.          w = matchwindows[0] ;
  1389.       } else {
  1390. /*
  1391.  *   This is some real neat code.  We want to find the next window,
  1392.  *   that is, the window with the least address greater than the
  1393.  *   currently active window, unless the currently active window
  1394.  *   has the highest address, in which case we want to find the
  1395.  *   window with the least address.  Why this works is left as a
  1396.  *   puzzle for the reader.
  1397.  */
  1398.          if (activewindow) {
  1399.             w = activewindow ;
  1400.             for (j=0; j<n; j++)
  1401.                if ((w > activewindow) ^
  1402.                    (w > matchwindows[j]) ^
  1403.                    (matchwindows[j] > activewindow))
  1404.                   w = matchwindows[j] ;
  1405.          } else {
  1406.             w = NULL ;
  1407.             for (j=0; j<n; j++)
  1408.                if (lastwindows[key]==matchwindows[j]) {
  1409.                   w = lastwindows[key] ;
  1410.                   break ;
  1411.                }
  1412.             if (w==NULL)
  1413.                w = matchwindows[0] ;
  1414.          }
  1415.       }
  1416.       lastwindows[key] = w ;
  1417.       s = w->WScreen ;
  1418.       UnlockIBase(foo) ;
  1419.       ScreenToFront(s) ;
  1420. /*
  1421.  *   If only one window on screen, don't bring it to front
  1422.  *   (mostly for DPaint, but for other progs as well.)
  1423.  *   (Anyone know an easy way to see if this window is fully
  1424.  *   exposed?)
  1425.  */
  1426.       if (s->FirstWindow != w || w->NextWindow)
  1427.          WindowToFront(w) ;
  1428.       ActivateWindow(w) ;
  1429.    }
  1430.    return ;
  1431. goner:
  1432.    DisplayBeep(0L) ;
  1433. }
  1434. /*
  1435.  *   These two functions compare a given string `s' with a `key' string.
  1436.  *   The key string should be all upper case; this is a case insensitive
  1437.  *   match.  If the key string contains `*', this character is assumed to
  1438.  *   match the rest of the string (and it can only come at the end.)  We
  1439.  *   have a routine for BSTR's, and a routine for regular strings.
  1440.  */
  1441. int sstrcmp(s, key)
  1442. register char *s, *key ;
  1443. {
  1444.    while (1) {
  1445.       if (*key == '*')
  1446.          return(1) ;
  1447.       if (*key == 0)
  1448.          return(*s == 0) ;
  1449.       if (*s == 0)
  1450.          return(0) ;
  1451.       if (*s != *key &&
  1452.           (*s != *key + 32 || *s < 'a' || *s > 'z'))
  1453.          return(0) ;
  1454.       s++ ;
  1455.       key++ ;
  1456.    }
  1457. }
  1458. /*
  1459.  *   This is the same as above, only instead of using a null to
  1460.  *   end the string, we keep track of the number of characters.
  1461.  */
  1462. int bstrcmp(s, key)
  1463. register char *s, *key ;
  1464. {
  1465.    register int n ;
  1466.  
  1467.    n = *(unsigned char *)s++ ;
  1468.    while (1) {
  1469.       if (*key == '*')
  1470.          return(1) ;
  1471.       if (*key == 0)
  1472.          return(n == 0) ;
  1473.       if (n == 0)
  1474.          return(0) ;
  1475.       if (*s != *key &&
  1476.           (*s != *key + 32 || *s < 'a' || *s > 'z'))
  1477.          return(0) ;
  1478.       s++ ;
  1479.       key++ ;
  1480.       n-- ;
  1481.    }
  1482. }
  1483. /*
  1484.  *   A place to hold an input line.
  1485.  */
  1486. #define MAXSTARTUPLINE (100)
  1487. char startbuf[MAXSTARTUPLINE] ;
  1488. char upline[MAXSTARTUPLINE] ;
  1489. /*
  1490.  *   Is a legit separator of some sort.
  1491.  */
  1492. int issep(s)
  1493. register char s ;
  1494. {
  1495.    return (s <= ' ' || s == '=' || s == ':' || s == ',' || s == '-') ;
  1496. }
  1497. /*
  1498.  *   Go to next `word' in the startup file.
  1499.  */
  1500. char *getword(s)
  1501. register char *s ;
  1502. {
  1503.    while (*s && issep(*s))
  1504.       s++ ;
  1505.    return(s) ;
  1506. }
  1507. /*
  1508.  *   Upper case a string.
  1509.  */
  1510. char *upcase(dest, s)
  1511. char *dest ;
  1512. register char *s ;
  1513. {
  1514.    register char *d = dest ;
  1515.  
  1516.    while (*s) {
  1517.       if ('a' <= *s && *s <= 'z')
  1518.          *d++ = *s++ - 32 ;
  1519.       else
  1520.          *d++ = *s++ ;
  1521.    }
  1522.    *d = 0 ;
  1523.    return(dest) ;
  1524. }
  1525. /*
  1526.  *   Say we got a bad line.
  1527.  */
  1528. badline() {
  1529.    puts("Error in startup file!") ;
  1530.    puts(startbuf) ;
  1531. }
  1532. /*
  1533.  *   Copies a string from one place to another; string delimited by
  1534.  *   double quotes.
  1535.  */
  1536. char *cpystr(dest, src)
  1537. register char *dest, *src ;
  1538. {
  1539.    if (*src != '"')
  1540.       badline() ;
  1541.    else {
  1542.       src++ ;
  1543.       while (*src != '"' && *src != 0) {
  1544.          if (*src == '\\' && src[1] != 0)
  1545.             src++ ;
  1546.          *dest++ = *src++ ;
  1547.       }
  1548.       if (*src)
  1549.          src++ ;
  1550.    }
  1551.    *dest = 0 ;
  1552.    return(getword(src)) ;
  1553. }
  1554. /*
  1555.  *   Handle a single startup line that's not a comment and non-empty
  1556.  *   and been converted to all upper case.
  1557.  */
  1558. parseline(s, msg)
  1559. register char *s ;
  1560. struct OURMSG *msg ;
  1561. {
  1562.    int flags ;
  1563.    register short t ;
  1564.    register int key ;
  1565.    char *p ;
  1566.    register struct hotkey *hk ;
  1567.  
  1568.    flags = 0 ;
  1569.    if (strncmp(s, "COMMAND", 7)==0) {
  1570.       s = getword(s+7) ;
  1571.       cpystr(msg->cmd, s) ;
  1572.    } else if (strncmp(s, "TIMEOUT", 7)==0) {
  1573.       s = getword(s+7) ;
  1574.       t = 0 ;
  1575.       while ('0' <= *s && *s <= '9')
  1576.          t = t * 10 + *s++ - '0' ;
  1577.       if (t < 0)
  1578.          t = DEFTIME ;
  1579.       msg->interval = t ;
  1580.    } else if (strncmp(s, "LINES", 5)==0) {
  1581.       msg->draw = 1 ;
  1582.    } else if (strncmp(s, "BLANK", 5)==0) {
  1583.       msg->draw = -1 ;
  1584.    } else {
  1585.       if (strncmp(s, "SHIFT", 5)==0) {
  1586.          flags = SHIFT ;
  1587.          s = getword(s+5) ;
  1588.       }
  1589.       if (*s == 0)
  1590.          badline() ;
  1591.       else {
  1592.          if (issep(s[1]) &&
  1593.              (('A' <= *s && *s <= 'Z') ||
  1594.               ('0' <= *s && *s <= '9'))) {
  1595.             key = *s ;
  1596.             s = getword(s+1) ;
  1597.          } else if (strncmp(s, "SPACE", 5)==0) {
  1598.             key = ' ' ;
  1599.             s = getword(s+5) ;
  1600.          } else if (*s == 'F' && ('1' <= s[1] && s[1] <= '9')) {
  1601.             s++ ;
  1602.             t = *s++ - '0' ;
  1603.             if (t == 1 && *s == '0') {
  1604.                t = 10 ;
  1605.                s++ ;
  1606.             }
  1607.             key = t ;
  1608.             s = getword(s) ;
  1609.           } else {
  1610.             badline() ;
  1611.             return ;
  1612.          }
  1613.          if (strncmp(s, "INTUITION", 9)==0) {
  1614.             flags |= NOTCLI ;
  1615.             s = getword(s+9) ;
  1616.          } else if (strncmp(s, "CLI", 3)==0) {
  1617.             flags |= NOTINTUITION ;
  1618.             s = getword(s+3) ;
  1619.          }
  1620.          s = cpystr(upline, s) ;
  1621.          p = upline + strlen(upline) + 1 ;
  1622.          if (*s)
  1623.             cpystr(p, startbuf + (s-upline)) ;
  1624.          else
  1625.             *p = 0 ;
  1626.          t = sizeof(struct hotkey) + strlen(p) + strlen(upline) ;
  1627.          hk = AllocMem((long)t, MEMF_CLEAR | MEMF_PUBLIC) ;
  1628.          if (hk) {
  1629.             hk->key = key ;
  1630.             hk->flags = flags ;
  1631.             hk->next = hotkeys ;
  1632.         hk->structlen = t ;
  1633.         hk->matchstring = strcpy(hk->strings, upline) ;
  1634.         hk->startstring = strcpy(hk->strings + strlen(upline) + 1, p) ;
  1635.             if (hk->startstring[0]==0)
  1636.                hk->startstring = NULL ;
  1637.             hotkeys = hk ;
  1638.          } else
  1639.             puts("Out of memory in startup") ;
  1640.       }
  1641.    }
  1642. }
  1643. /*
  1644.  *   Handle the startup file.
  1645.  */
  1646. processstartup(s, msg)
  1647. char *s ;
  1648. struct OURMSG *msg ;
  1649. {
  1650.    FILE *f ;
  1651.    register char *p ;
  1652.  
  1653.    if (f=fopen(s, "r")) {
  1654.       while (fgets(startbuf, MAXSTARTUPLINE, f)) {
  1655.          p = getword(startbuf) ;
  1656.          if (*p != '*' && *p != '#' && *p != ';' && *p != 0) {
  1657.             upcase(upline, p) ;
  1658.             parseline(upline, msg) ;
  1659.          }
  1660.       }
  1661.       fclose(f) ;
  1662.    } else {
  1663.       puts("Couldn't open startup file:") ;
  1664.       puts(s) ;
  1665.    }
  1666. }
  1667. /*
  1668.  *   This stuff down here handles the raw key conversion stuff
  1669.  *   properly.  Thanks to Willy Langeveld and Carolyn Scheppner.
  1670.  */
  1671. char *dos_rkcv();
  1672. int  dos_rkcvinit(), dos_rkcvexit();
  1673. struct IOStdReq ConStdReq;
  1674. /*
  1675.  *   This code won't compile under Manx unless you delete the
  1676.  *   `ConsoleDevice' function in functions.h, or perform a kludge
  1677.  *   like the one I did when I included it.  Why the hell does
  1678.  *   Manx have that in there?  If you try to use it, it comes out
  1679.  *   undefined, but if you rename the following, it won't link
  1680.  *   because it needs the function `ConsoleDevice'.
  1681.  */
  1682. long ConsoleDevice ;
  1683. /**
  1684. *
  1685. *  Calling sequence:
  1686. *  =================
  1687. *
  1688. *    result = (char *) dos_rkcv(code, buffer, length);
  1689. *
  1690. *  Description:
  1691. *  ============
  1692. *
  1693. *    Covert raw key number to array of console device ascii text
  1694. *    using the default keymap.
  1695. *
  1696. *  Inputs:
  1697. *  =======
  1698. *
  1699. *    int code        Raw key number.
  1700. *    int qual        Qualifier.
  1701. *    char *buffer        Pointer to an array of char to receive the
  1702. *                conversion.
  1703. *    int length        length of buffer.
  1704. *
  1705. *  Outputs:
  1706. *  ========
  1707. *
  1708. *    F. value:        NULL on conversion failure, or pointer to
  1709. *                buffer on success.
  1710. *
  1711. **/
  1712. char *dos_rkcv(code, qual, buffer, length)
  1713. int code;
  1714. int qual;
  1715. char *buffer;
  1716. int length;
  1717. {
  1718.    static struct InputEvent event;
  1719.  
  1720.    event.ie_Class = IECLASS_RAWKEY;
  1721.    event.ie_Code = code;
  1722.    event.ie_Qualifier = qual;
  1723.  
  1724.    if (RawKeyConvert(&event, buffer, (long) length, NULL) == 0L) return(0L);
  1725.  
  1726.    return(buffer);
  1727. }
  1728.  
  1729. /**
  1730. *
  1731. *  Calling sequence:
  1732. *  =================
  1733. *
  1734. *    error = dos_rkcvinit();
  1735. *
  1736. *  Description:
  1737. *  ============
  1738. *
  1739. *    Open the Console device for later use with dos_rkcv().
  1740. *
  1741. *  Inputs:
  1742. *  =======
  1743. *
  1744. *    None
  1745. *
  1746. *  Outputs:
  1747. *  ========
  1748. *
  1749. *    F. value:        1 on failure, zero otherwise.
  1750. *                
  1751. *
  1752. **/
  1753. int dos_rkcvinit()
  1754. {
  1755.    if (OpenDevice("console.device", -1L, &ConStdReq, 0L) != NULL) {
  1756.       ConsoleDevice = 0L;
  1757.       return(1);
  1758.    }
  1759.    else {
  1760.       ConsoleDevice = (long) ConStdReq.io_Device;
  1761.       return(0);
  1762.    }
  1763. }
  1764.  
  1765. /**
  1766. *
  1767. *  Calling sequence:
  1768. *  =================
  1769. *
  1770. *    error = dos_rkcvexit();
  1771. *
  1772. *  Description:
  1773. *  ============
  1774. *
  1775. *    Close the Console device after use with dos_rkcv().
  1776. *
  1777. *  Inputs:
  1778. *  =======
  1779. *
  1780. *    None
  1781. *
  1782. *  Outputs:
  1783. *  ========
  1784. *
  1785. *    F. value:        Always zero;
  1786. *                
  1787. **/
  1788. int dos_rkcvexit()
  1789. {
  1790.    if (ConsoleDevice) CloseDevice(&ConStdReq);
  1791.    return(0);
  1792. }
  1793. /*
  1794.  *   Set up the key conversion table.  Note that the buffer has to be
  1795.  *   long word aligned!
  1796.  */
  1797. initkeytoasc() {
  1798.    register int i ;
  1799.    char buf[100] ;
  1800.  
  1801.    for (i=0; i<128; i++)
  1802.       keytoasc[i] = '.' ;
  1803.    if (dos_rkcvinit())
  1804.       return(1) ;
  1805.    for (i=0; i<128; i++) {
  1806.       buf[1] = 0 ;
  1807.       if (dos_rkcv(i, 0, buf, 100) && buf[1] == 0 &&
  1808.           (buf[0] == ' ' ||
  1809.            ('a' <= buf[0] && buf[0] <= 'z' && (buf[0] -= 32)) ||
  1810.            ('0' <= buf[0] && buf[0] <= '9'))) {
  1811.          keytoasc[i] = buf[0] ;
  1812.       }
  1813.    }
  1814. /*
  1815.  *   Have to handle the function keys separately
  1816.  */
  1817.    for (i=80; i<90; i++)
  1818.       keytoasc[i] = i-79 ;
  1819.    dos_rkcvexit() ;
  1820.    return(0) ;
  1821. }
  1822. /*
  1823.  *   Save a byte or two.
  1824.  */
  1825. _wb_parse() {}
  1826.