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