home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 198_02 / st520.c < prev    next >
C/C++ Source or Header  |  1990-01-23  |  21KB  |  1,033 lines

  1. /*
  2.  
  3. The routines in this file provide support for the Atari 520 or 1040ST
  4. using VT52 emulation.  The I/O services are provided here as well.  It
  5. compiles into nothing if not a 520ST style device.
  6.  
  7. */
  8.  
  9. #define    termdef    1            /* don't define "term" external */
  10.  
  11. #include        <stdio.h>
  12. #include        "estruct.h"
  13. #include    "edef.h"
  14.  
  15. #if     ATARI & ST520 & MEGAMAX
  16. #include    <osbind.h>
  17. #include    <ctype.h>
  18.  
  19. #define LINEA_INIT 0xA000
  20. #define V_CEL_WR   -0x28
  21.  
  22. #define V_CEL_MY   -0x2a
  23. #define V_CEL_HT   -0x2e
  24. #define V_FNT_AD   -0x16
  25. #define V_OFF_AD   -0x0a
  26. #define V_DISAB    -346
  27.  
  28. #define NROW    25                      /* Screen size.                 */
  29. #define NCOL    80                      /* Edit if you want to.         */
  30. #define    MARGIN    8            /* size of minimim margin and    */
  31. #define    SCRSIZ    64            /* scroll size for extended lines */
  32. #define    NPAUSE    25            /* # times thru update to pause */
  33. #define BIAS    0x20                    /* Origin 0 coordinate bias.    */
  34. #define ESC     0x1B                    /* ESC character.               */
  35. #define BEL     0x07                    /* ascii bell character         */
  36.  
  37. extern  int     ttopen();               /* Forward references.          */
  38. extern  int     ttgetc();
  39. extern  int     ttputc();
  40. extern  int     ttflush();
  41. extern  int     ttclose();
  42. extern  int     st520move();
  43. extern  int     st520eeol();
  44. extern  int     st520eeop();
  45. extern  int     st520beep();
  46. extern  int     st520open();
  47. extern    int    st520close();
  48. extern    int    st520rev();
  49. extern  int st520kopen();
  50. extern  int st520kclose();
  51. extern    int st520chgrez();
  52.  
  53. #if    COLOR
  54. extern    int    st520fcol();
  55. extern    int    st520bcol();
  56.  
  57. int        cfcolor = -1;        /* current fg (character) color */
  58. int        cbcolor = -1;        /* current bg color */
  59. int        oldpal[8];        /* pallette when emacs was invoked */
  60. int        newpal[8] = {        /* default emacs pallette */
  61.     0x000, 0x700, 0x070, 0x770, 0x007, 0x707, 0x077, 0x777};
  62. #endif
  63.  
  64. int STncolors = 0;        /* number of colors  */
  65. int STrez;            /* physical screen resolution */    
  66.  
  67. /*
  68.  * Dispatch table. All the
  69.  * hard fields just point into the
  70.  * terminal I/O code.
  71.  */
  72. TERM    term    = {
  73.         NROW-1,
  74.         NCOL,
  75.     MARGIN,
  76.     MARGIN,
  77.     SCRSIZ,
  78.     NPAUSE,
  79.         &st520open,
  80.         &st520close,
  81.     &st520kopen,
  82.     &st520kclose,
  83.         &ttgetc,
  84.         &ttputc,
  85.         &ttflush,
  86.         &st520move,
  87.         &st520eeol,
  88.         &st520eeop,
  89.         &st520beep,
  90.         &st520rev
  91. #if    MULTREZ
  92.     , &st520chgrez
  93. #endif
  94. #if    COLOR
  95.     , &st520fcol,
  96.     &st520bcol
  97. #endif
  98. };
  99.     struct KBDvecs {
  100.         int (*midivec) ();
  101.         int (*vkbderr) ();
  102.         int (*vmiderr) ();
  103.         int (*statvec) ();
  104.         int (*mousevec) ();
  105.         int (*clockvec) ();
  106.         int (*joyvec) ();
  107.         int (*midisys) ();
  108.         int (*ikbdsys) ();
  109.     };
  110.     struct Param {
  111.         char topmode;
  112.         char buttons;
  113.         char xparam;
  114.         char yparam;
  115.         int xmax,ymax;
  116.         int xinitial,yinitial;
  117.     };
  118.     struct KBDvecs *kbdvecs;
  119.     struct Param *paramp;
  120.     char kbdcmds[25];
  121.  
  122. st520move(row, col)
  123. {
  124.         ttputc(ESC);
  125.         ttputc('Y');
  126.         ttputc(row+BIAS);
  127.         ttputc(col+BIAS);
  128. }
  129.  
  130. st520eeol()
  131. {
  132.         ttputc(ESC);
  133.         ttputc('K');
  134. }
  135.  
  136. st520eeop()
  137. {
  138.  
  139. #if    COLOR
  140.         st520fcol(gfcolor);
  141.         st520bcol(gbcolor);
  142. #endif
  143.         ttputc(ESC);
  144.         ttputc('J');
  145. }
  146.  
  147. st520rev(status)    /* set the reverse video state */
  148.  
  149. int status;    /* TRUE = reverse video, FALSE = normal video */
  150.  
  151. {
  152.  
  153.     if(status) {
  154.         ttputc(ESC);
  155.         ttputc('p');
  156.     }
  157.     else {
  158.         ttputc(ESC);
  159.         ttputc('q');
  160.     }
  161. }
  162.  
  163. #if    COLOR
  164. st520fcol(color)
  165. int color;    
  166. {
  167.         if(color == cfcolor || !STncolors)
  168.             return;
  169.         else {
  170.  
  171.             ttputc(ESC);
  172.             ttputc('b');
  173.             ttputc(color & 0x0f);
  174.             cfcolor = color;
  175.         }
  176. }
  177.  
  178. st520bcol(color)
  179. int color;
  180. {
  181.         if(color == cbcolor || !STncolors)
  182.             return;
  183.         else {
  184.             ttputc(ESC);
  185.             ttputc('c');
  186.             ttputc(color & 0x0f);
  187.             cbcolor = color;
  188.         }
  189.  
  190. }
  191. #endif
  192.  
  193. st520beep()
  194. {
  195. #ifdef    BEL
  196.         ttputc(BEL);
  197.         ttflush();
  198. #endif
  199. }
  200.  
  201. st520open()
  202. {
  203.     int i,j,k;
  204.     long phys, log;    /* screen bases */
  205.     
  206. /* IMPORTANT: it is ABSOLUTELY necessary that the default resolution be the
  207.  *    largest possible so that display will allocate (malloc) the maximum
  208.  *    size for the VIDEO arrray
  209.  */
  210.     STrez = Getrez();
  211.     switch(STrez) {
  212.         case 0: /* low res 25x40 16 colors */
  213.             phys = Physbase();
  214.             log  = Logbase();
  215.             Setscreen(log, phys, 1);
  216.             STrez = 1;
  217.             /* fall thru to med res */
  218.  
  219.         case 1: /* med res 25x80 4 colors */
  220.             term.t_nrow = 25 - 1;
  221.             term.t_ncol  = 80;
  222.             grez = 1;
  223. #if    COLOR
  224.             STncolors = 4;
  225.             for(i=0;i<8;i++) {
  226.                 oldpal[i] = Setcolor(i,newpal[i]);
  227.             }
  228. #endif
  229.             break;
  230.         case 2: /* high res 25x80 no colors */
  231.             term.t_nrow  = 40 - 1;
  232.             term.t_ncol  = 80;
  233.             grez = 2;
  234.             make_8x10(); /* create a smaller font */
  235.             set_40();    /* and go to 40 line mode */
  236. #if    COLOR
  237.             STncolors = 0;
  238. #endif
  239.             break;
  240.     }
  241.  
  242.     revexist = TRUE;
  243.     eolexist = TRUE;
  244.     paramp = (struct Param *)malloc(sizeof(struct Param));
  245.     kbdvecs = (struct KBDvecs *)Kbdvbase();
  246.     paramp -> topmode = 0;
  247.     paramp -> buttons = 4;
  248.     paramp -> xparam = 8;
  249.     paramp -> yparam = 10;
  250.     paramp -> xmax = 79;
  251.     paramp -> ymax = 23;
  252.     paramp -> xinitial = 0;
  253.     paramp -> yinitial = 0;
  254.     Initmous(1,paramp,kbdvecs -> mousevec);
  255.  
  256.     i = 0;
  257.     kbdcmds[i++] = 0x0a;    /*set mouse keycode mode */
  258.     kbdcmds[i++] = 0x08;
  259.     kbdcmds[i++] = 0x0a;
  260.     Ikbdws(i-1,&kbdcmds[0]);
  261.     Cursconf(1,0);
  262.     Cursconf(3,0);
  263.     Cconout(27);Cconout('E');
  264.         ttopen();
  265. }
  266.  
  267. st520close()
  268.  
  269. {
  270.     int i,j,k;
  271.  
  272.     i = 0;
  273.     kbdcmds[i++] = 0x80;    /*reset mouse keycode mode */
  274.     kbdcmds[i++] = 0x01;
  275.     Ikbdws(i-1,&kbdcmds[0]);
  276.     if(grez == 2 && STrez == 2) /* b/w monitor in 40 row mode */
  277.         restore();
  278.  
  279. #if        COLOR
  280.     for(i=0;i<STncolors;i++)
  281.         Setcolor(i,oldpal[i]);
  282. #endif
  283.     Cconout(27);Cconout('E');
  284.     paramp -> buttons = 0;
  285.     Initmous(2,paramp,kbdvecs -> mousevec);
  286.     i = 0;
  287.     kbdcmds[i++] = 0x80;    /*reset the keyboard*/
  288.     kbdcmds[i++] = 0x01;
  289.     Ikbdws(i-1,&kbdcmds[0]);
  290.     Cursconf(1,0);
  291.     ttclose();
  292. }
  293. st520kopen()
  294. {
  295.  
  296. }
  297. st520kclose()
  298. {
  299.  
  300. }
  301.  
  302. st520chgrez(nurez)
  303. int nurez;
  304. {
  305.     int ierr, i, j ,k;
  306.     long phys, log;    /* screen bases */
  307.     char dum[80]; /* for debugging only */
  308.         
  309.     if(grez == nurez)
  310.         return(TRUE);
  311.         
  312.     if(STrez == 2) { /* b/w monitor-only allow hi | med rez */
  313.         switch(nurez) {
  314.             case 2: /* high res */
  315.                 term.t_nrow  = 40 - 1;
  316.                 term.t_ncol  = 80;
  317.                 make_8x10(); /* create a smaller font */
  318.                 set_40();    /* and go to 40 line mode */
  319.                 grez = 2;
  320.                 sgarbf = TRUE;
  321.                 onlywind(1,1);
  322.                 break;
  323.             case 1: /* med res */
  324.                 term.t_nrow  = 25 - 1;
  325.                 term.t_ncol  = 80;
  326.                 restore();
  327.                 grez = 1;
  328.                 sgarbf = TRUE;
  329.                 onlywind(1,1);
  330.                 break;
  331.             default:
  332.                 mlwrite("Invalid resolution");
  333.                 return(FALSE);
  334.                 break;
  335.         }
  336.     }
  337.     else { /* color monitor-only allow low | medium resolution */
  338.         phys = Physbase();
  339.         log  = Logbase();
  340.         switch(nurez) {
  341.             case 1:
  342.                 term.t_nrow  = 25 - 1;
  343.                 term.t_ncol  = 80;
  344.                 Setscreen(log, phys, 1);
  345.                 STncolors = 4;
  346.                 grez = 1;
  347.                 sgarbf = TRUE;
  348.                 onlywind(1,1);
  349.                 break;
  350.             case 0:
  351.                 term.t_nrow  = 25 - 1;
  352.                 term.t_ncol  = 40;
  353.                 Setscreen(log, phys, 0);
  354.                 STncolors = 8;
  355.                 grez = 0;
  356.                 sgarbf = TRUE;
  357.                 onlywind(1,1);
  358.                 break;
  359.             default:
  360.                 mlwrite("%Invalid resolution");
  361.                 return(FALSE);
  362.                 break;
  363.         }
  364.     }
  365. }            
  366.  
  367. STcurblink(onoff)
  368. int onoff;
  369. {
  370.     if(onoff)
  371.         Cursconf(2,0);
  372.     else
  373.         Cursconf(3,0);
  374. }
  375.  
  376.  
  377. char parm_save[28];
  378. long fnt_8x10[640];
  379.  
  380. make_8x10()
  381. {
  382.     int i,j,k;
  383.     long savea23[2];
  384.     
  385.     for(i=0;i<640;i++)
  386.         fnt_8x10[i] = 0;
  387.         
  388.     asm {
  389.     movem.l    A2-A3,savea23(A6)
  390.     
  391.     dc.w    LINEA_INIT        ;A1 -> array of font headers
  392.  
  393.     lea    parm_save(A4),A2    ;A2 -> parameters savearea
  394.     move.l    V_OFF_AD(A0),(A2)+
  395.     move.l    V_FNT_AD(A0),(A2)+
  396.     move.w    V_CEL_HT(A0),(A2)+
  397.     move.w    V_CEL_MY(A0),(A2)+
  398.     move.w    V_CEL_WR(A0),(A2)+
  399.  
  400.  
  401.     move.l    04(A1),A1        ; A1 -> 8x8 font header
  402.     move.l    76(A1),A2        ; A2 -> 8x8 font data
  403.     lea    fnt_8x10+0x100(A4),A3    ; A3 -> 2nd line of font buffer
  404.     move.w    #0x200-1,D0        ; D0 <- longword counter for font xfer
  405.  
  406. fnt_loop:
  407.  
  408.     move.l    (A2)+,(A3)+
  409.     dbf    D0,fnt_loop
  410.         
  411.     movem.l    savea23(A6),A2-A3
  412.     }
  413.     
  414. }
  415.  
  416. set_40()
  417. {
  418.     long    savea23[2];
  419.     
  420.     asm {
  421.     
  422. ;
  423. ;  use the 8x10 character set: 40 line mode
  424. ;
  425.  
  426.     movem.l    A2-A3,savea23(A6)
  427.     
  428.     dc.w    LINEA_INIT
  429.  
  430.     move.l    04(A1),A1        ; A1 -> 8x8 font header
  431.     move.l    72(A1),V_OFF_AD(A0)    ; v_off_ad <- 8x8  offset table addr
  432.     lea    fnt_8x10(A4),A2
  433.     move.l    A2,V_FNT_AD(A0)        ; v_fnt_ad <- 8x10 font data addr
  434.  
  435.     move.w    #10,V_CEL_HT(A0)    ; v_cel_ht <- 10   8x10 cell height
  436.     move.w    #39,V_CEL_MY(A0)    ; v_cel_my <- 39   maximum cell "Y"
  437.     move.w    #800,V_CEL_WR(A0)    ; v_cel_wr <- 800  offset to cell Y+1
  438.  
  439.     movem.l savea23,A2-A3
  440.     }
  441. }
  442.  
  443. set_20()
  444. {
  445.     long    savea23[2];
  446.  
  447.     asm {
  448.         
  449. ;
  450. ;  use the 8x10 character set: 20 line mode
  451. ;
  452.  
  453.     movem.l    A2-A3,savea23(A6)
  454.     
  455.     dc.w    LINEA_INIT        ; A0 -> line A variables
  456.  
  457.     move.l    04(A1),A1        ; A1 -> 8x8 font header
  458.     move.l    72(A1),V_OFF_AD(A0)    ; v_off_ad <- 8x8  offset table addr
  459.     lea    fnt_8x10(A4),A2
  460.     move.l    A2,V_FNT_AD(A0)        ; v_fnt_ad <- 8x10 font data addr
  461.  
  462.     move.w    #10,V_CEL_HT(A0)    ; v_cel_ht <- 10   8x10 cell height
  463.     move.w    #19,V_CEL_MY(A0)    ; v_cel_my <- 19   maximum cell "Y"
  464.     move.w    #1600,V_CEL_WR(A0)    ; v_cel_wr <- 800  offset to cell Y+1
  465.     
  466.     movem.l    savea23,A2-A3
  467.     }
  468. }
  469.  
  470.  
  471. restore()
  472. {
  473.     long savea23[2];
  474.     
  475.     asm {
  476.     
  477. ;  return what was saved in parameter save zone    
  478.  
  479.     movem.l    A2-A3,savea23(A6)
  480.  
  481.     dc.w    LINEA_INIT        ; a0 -> line A variables
  482.  
  483.     lea    parm_save(A4),A2    ; a2 -> parameter save area
  484.     move.l    (A2)+,V_OFF_AD(A0)
  485.     move.l    (A2)+,V_FNT_AD(A0)
  486.     move.w    (A2)+,V_CEL_HT(A0)
  487.     move.w    (A2)+,V_CEL_MY(A0)
  488.     move.w    (A2)+,V_CEL_WR(A0)
  489.     
  490.     movem.l    savea23(A6),A2-A3
  491.     }          
  492. }
  493. GetCurStat(onoff)
  494. int    onoff;
  495. {
  496.     long savea23[2];
  497.  
  498.     asm {
  499.     movem.l    A2-A3,savea23(A6)
  500.  
  501.     dc.w    LINEA_INIT        ; a0 -> line A variables
  502.     move.w    V_DISAB(A0),onoff(A6)    ; 0 = cursor visible
  503.     moveq    #0,D0
  504.     move.w    V_DISAB(A0),D0    
  505.     movem.l    savea23(A6),A2-A3
  506.     }          
  507. }
  508. #else
  509. #if    ATARI & ST520 & LATTICE
  510.  
  511. /*
  512.     These routines provide support for the ATARI 1040ST using
  513. the LATTICE compiler using the virtual VT52 Emulator
  514.  
  515. */
  516.  
  517. #define NROW    40                      /* Screen size.                 */
  518. #define NCOL    80                      /* Edit if you want to.         */
  519. #define    MARGIN    8            /* size of minimim margin and    */
  520. #define    SCRSIZ    64            /* scroll size for extended lines */
  521. #define    NPAUSE    300            /* # times thru update to pause */
  522. #define BIAS    0x20                    /* Origin 0 coordinate bias.    */
  523. #define ESC     0x1B                    /* ESC character.               */
  524. #define BEL     0x07                    /* ASCII bell character         */
  525.  
  526. /****    ST Internals definitions        *****/
  527.  
  528. /*    BIOS calls */
  529.  
  530. #define    BCONSTAT    1    /* return input device status */
  531. #define    CONIN        2    /* read character from device */
  532. #define    BCONOUT        3    /* write character to device */
  533.  
  534. /*    XBIOS calls */
  535.  
  536. #define    INITMOUS    0    /* initialize the mouse */
  537. #define    GETREZ        4    /* get current resolution */
  538. #define    SETSCREEN    5    /* set screen resolution */
  539. #define    SETPALETTE    6    /* set the color pallette */
  540. #define    SETCOLOR    7    /* set or read a color */
  541. #define    CURSCONF    21    /* set cursor configuration */
  542. #define    IKBDWS        25    /* intelligent keyboard send command */
  543. #define    KBDVBASE    34    /* get keyboard table base */
  544.  
  545. /*    GEMDOS calls */
  546.  
  547. #define    EXEC        0x4b    /* Exec off a process */
  548.  
  549. #define    CON        2    /* CON: Keyboard and screen device */
  550.  
  551. /*    LINE A variables    */
  552.  
  553. #define LINEA_INIT 0xA000
  554. #define V_CEL_WR   -0x28
  555. #define V_CEL_MY   -0x2a
  556. #define V_CEL_HT   -0x2e
  557. #define V_FNT_AD   -0x16
  558. #define V_OFF_AD   -0x0a
  559. #define V_DISAB    -346
  560.  
  561. /*    Palette color definitions    */
  562.  
  563. #define    LOWPAL    "000700070770007707077777"
  564. #define    MEDPAL    "000700007777"
  565. #define    HIGHPAL    "000111"
  566.  
  567. /*    ST Global definitions        */
  568.  
  569. /* keyboard vector table */
  570. struct KVT {
  571.     long midivec;        /* midi input */
  572.     long vkbderr;        /* keyboard error */
  573.     long vmiderr;        /* MIDI error */
  574.     long statvec;        /* IKBD status */
  575.     int (*mousevec)();    /* mouse vector */
  576.     long clockvec;        /* clock vector */
  577.     long joyvec;        /* joystict vector */
  578. } *ktable;
  579.  
  580. int (*sysmint)();            /* system mouse interupt handler */
  581.  
  582. /* mouse parameter table */
  583. struct Param {
  584.     char topmode;
  585.     char buttons;
  586.     char xparam;
  587.     char yparam;
  588.     int xmax,ymax;
  589.     int xinitial,yinitial;
  590. } mparam;
  591.  
  592. int initrez;            /* initial screen resolution */
  593. int currez;            /* current screen resolution */
  594. char resname[][8] = {        /* screen resolution names */
  595.     "LOW", "MEDIUM", "HIGH", "DENSE"
  596. };
  597. short spalette[16];            /* original color palette settings */
  598. short palette[16];            /* current palette settings */
  599.  
  600. extern  int     ttopen();               /* Forward references.          */
  601. extern  int     ttgetc();
  602. extern  int     ttputc();
  603. extern  int     ttflush();
  604. extern  int     ttclose();
  605. extern  int     stmove();
  606. extern  int     steeol();
  607. extern  int     steeop();
  608. extern  int     stbeep();
  609. extern  int     stopen();
  610. extern    int    stclose();
  611. extern    int    stgetc();
  612. extern    int    stputc();
  613. extern    int    strev();
  614. extern    int    strez();
  615. extern    int    stkopen();
  616. extern    int    stkclose();
  617.  
  618. #if    COLOR
  619. extern    int    stfcol();
  620. extern    int    stbcol();
  621. #endif
  622.  
  623. /*
  624.  * Dispatch table. All the
  625.  * hard fields just point into the
  626.  * terminal I/O code.
  627.  */
  628. TERM    term    = {
  629.     NROW-1,
  630.         NROW-1,
  631.         NCOL,
  632.         NCOL,
  633.     MARGIN,
  634.     SCRSIZ,
  635.     NPAUSE,
  636.         &stopen,
  637.         &stclose,
  638.     &stkopen,
  639.     &stkclose,
  640.         &stgetc,
  641.     &stputc,
  642.         &ttflush,
  643.         &stmove,
  644.         &steeol,
  645.         &steeop,
  646.         &stbeep,
  647.         &strev,
  648.     &strez
  649. #if    COLOR
  650.     , &stfcol,
  651.     &stbcol
  652. #endif
  653. };
  654.  
  655. stmove(row, col)
  656. {
  657.         stputc(ESC);
  658.         stputc('Y');
  659.         stputc(row+BIAS);
  660.         stputc(col+BIAS);
  661. }
  662.  
  663. steeol()
  664. {
  665.         stputc(ESC);
  666.         stputc('K');
  667. }
  668.  
  669. steeop()
  670. {
  671. #if    COLOR
  672.     stfcol(gfcolor);
  673.     stbcol(gbcolor);
  674. #endif
  675.         stputc(ESC);
  676.         stputc('J');
  677. }
  678.  
  679. strev(status)    /* set the reverse video state */
  680.  
  681. int status;    /* TRUE = reverse video, FALSE = normal video */
  682.  
  683. {
  684.     if (currez > 1) {
  685.         stputc(ESC);
  686.         stputc(status ? 'p' : 'q');
  687.     }
  688. }
  689.  
  690. #if    COLOR
  691. mapcol(clr)    /* medium rez color translation */
  692.  
  693. int clr;    /* emacs color number to translate */
  694.  
  695. {
  696.     static int mctable[] = {0, 1, 2, 3, 2, 1, 2, 3};
  697.  
  698.     if (currez != 1)
  699.         return(clr);
  700.     else
  701.         return(mctable[clr]);
  702. }
  703.  
  704. stfcol(color)    /* set the forground color */
  705.  
  706. int color;    /* color to set forground to */
  707.  
  708. {
  709.     if (currez < 2) {
  710.         stputc(ESC);
  711.         stputc('b');
  712.         stputc(mapcol(color));
  713.     }
  714. }
  715.  
  716. stbcol(color)    /* set the background color */
  717.  
  718. int color;    /* color to set background to */
  719.  
  720.  
  721. {
  722.     if (currez < 2) {
  723.         stputc(ESC);
  724.         stputc('c');
  725.         stputc(mapcol(color));
  726.     }
  727. }
  728. #endif
  729.  
  730. stbeep()
  731. {
  732.         stputc(BEL);
  733.         ttflush();
  734. }
  735.  
  736. domouse()    /* mouse interupt handler */
  737.  
  738. {
  739.     return((*sysmint)());
  740. }
  741.  
  742. stkopen()    /* open the keyboard (and mouse) */
  743.  
  744. {
  745.     /* grab the keyboard vector table */
  746.     ktable = (struct KVT *)xbios(KBDVBASE);
  747.     sysmint = ktable->mousevec;    /* save mouse vector */
  748.  
  749.     /* initialize the mouse */
  750.     mparam.topmode = 0;
  751.     mparam.buttons = 4;
  752.     mparam.xparam = 8;
  753.     mparam.yparam = 10;
  754.     mparam.xmax = 79;
  755.     mparam.ymax = 23;
  756.     mparam.xinitial = 0;
  757.     mparam.yinitial = 0;
  758.     xbios(INITMOUS, 4, &mparam, &domouse);
  759. }
  760.  
  761. stopen()    /* open the screen */
  762.  
  763. {
  764.     int i;
  765.  
  766.         ttopen();
  767.     eolexist = TRUE;
  768.  
  769.     /* switch to a steady cursor */
  770.     xbios(CURSCONF, 3);
  771.  
  772.     /* save the current color palette */
  773.     for (i=0; i<16; i++)
  774.         spalette[i] = xbios(SETCOLOR, i, -1);
  775.  
  776.     /* and find the current resolution */
  777.     initrez = currez = xbios(GETREZ);
  778.     strcpy(sres, resname[currez]);
  779.  
  780.     /* set up the screen size and palette */
  781.     switch (currez) {
  782.         case 0:    term.t_mrow = 25 - 1;
  783.             term.t_nrow = 25 - 1;
  784.             term.t_ncol = 40;
  785.             strcpy(palstr, LOWPAL);
  786.             break;
  787.  
  788.         case 1: term.t_mrow = 25 - 1;
  789.             term.t_nrow = 25 - 1;
  790.             strcpy(palstr, MEDPAL);
  791.             break;
  792.  
  793.         case 2: term.t_mrow = 40 - 1;
  794.             term.t_nrow = 25 - 1;
  795.             strcpy(palstr, HIGHPAL);
  796.     }
  797.  
  798.     /* and set up the default palette */
  799.     spal(palstr);
  800.  
  801.     stputc(ESC);    /* automatic overflow off */
  802.     stputc('w');
  803.     stputc(ESC);    /* turn cursor on */
  804.     stputc('e');
  805. }
  806.  
  807. stkclose()    /* close the keyboard (and mouse) */
  808.  
  809. {
  810.     static char resetcmd[] = {0x80, 0x01};    /* keyboard reset command */
  811.  
  812.     /* restore the mouse interupt routines */
  813.     xbios(INITMOUS, 2, &mparam, (long)sysmint);
  814.  
  815.     /* and reset the keyboard controller */
  816.     xbios(IKBDWS, 1, &resetcmd[0]);
  817. }
  818.  
  819. stclose()
  820.  
  821. {
  822.     stputc(ESC);    /* auto overflow on */
  823.     stputc('v');
  824.  
  825.     /* switch to a flashing cursor */
  826.     xbios(CURSCONF, 2);
  827.  
  828.     /* restore the original screen resolution */
  829.     strez(resname[initrez]);
  830.  
  831.     /* restore the original palette settings */
  832.     xbios(SETPALETTE, spalette);
  833.  
  834.     ttclose();
  835. }
  836.  
  837. /*     spal(pstr):    reset the current palette according to a
  838.             "palette string" of the form
  839.  
  840.     000111222333444555666777
  841.  
  842.     which contains the octal values for the palette registers
  843. */
  844.  
  845. spal(pstr)
  846.  
  847. char *pstr;    /* palette string */
  848.  
  849. {
  850.     int pal;    /* current palette position */
  851.     int clr;    /* current color value */
  852.     int i;
  853.  
  854.     for (pal = 0; pal < 16; pal++) {
  855.         if (*pstr== 0)
  856.             break;
  857.  
  858.         /* parse off a color */
  859.         clr = 0;
  860.         for (i = 0; i < 3; i++)
  861.             if (*pstr)
  862.                 clr = clr * 16 + (*pstr++ - '0');
  863.         palette[pal] = clr;
  864.     };
  865.  
  866.     /* and now set it */
  867.     xbios(SETPALETTE, palette);
  868. }
  869.  
  870. stgetc()    /* get a char from the keyboard */
  871.  
  872. {
  873.     int rval;        /* return value from BIOS call */
  874.     static int funkey = 0;    /* held fuction key scan code */
  875.  
  876.     /* if there is a pending function key, return it */
  877.     if (funkey) {
  878.         rval = funkey;
  879.         funkey = 0;
  880.     } else {
  881.         /* waiting... flash the cursor */
  882.         xbios(CURSCONF, 2);
  883.  
  884.         /* get the character */
  885.         rval = bios(CONIN, CON);
  886.         if ((rval & 255) == 0) {
  887.             funkey = (rval >> 16) & 255;
  888.             rval = 0;
  889.         }
  890.  
  891.         /* and switch to a steady cursor */
  892.         xbios(CURSCONF, 3);
  893.     }
  894.  
  895.     return(rval & 255);
  896. }
  897.  
  898. stputc(c)    /* output char c to the screen */
  899.  
  900. char c;        /* character to print out */
  901.  
  902. {
  903.     bios(BCONOUT, CON, c);
  904. }
  905.  
  906. strez(newrez)    /* change screen resolution */
  907.  
  908. char *newrez;    /* requested resolution */
  909.  
  910. {
  911.     int nrez;    /* requested new resolution */
  912.  
  913.     /* first, decode the resolution name */
  914.     for (nrez = 0; nrez < 4; nrez++)
  915.         if (strcmp(newrez, resname[nrez]) == 0)
  916.             break;
  917.     if (nrez == 4) {
  918.         mlwrite("%%No such resolution");
  919.         return(FALSE);
  920.     }
  921.  
  922.     /* next, make sure this resolution is legal for this monitor */
  923.     if ((currez < 2 && nrez > 1) || (currez > 1 && nrez < 2)) {
  924.         mlwrite("%%Resolution illegal for this monitor");
  925.         return(FALSE);
  926.     }
  927.  
  928.     /* eliminate non-changes */
  929.     if (currez == nrez)
  930.         return(TRUE);
  931.  
  932.     /* finally, make the change */
  933.     switch (nrez) {
  934.         case 0:    /* low resolution - 16 colors */
  935.             newwidth(TRUE, 40);
  936.             strcpy(palstr, LOWPAL);
  937.             xbios(SETSCREEN, -1, -1, 0);
  938.             break;
  939.  
  940.         case 1:    /* medium resolution - 4 colors */
  941.             newwidth(TRUE, 80);
  942.             strcpy(palstr, MEDPAL);
  943.             xbios(SETSCREEN, -1, -1, 1);
  944.             break;
  945.  
  946.         case 2:    /* High resolution - 2 colors - 25 lines */
  947.             newsize(TRUE, 25);
  948.             strcpy(palstr, HIGHPAL);
  949.             /* change char set back to normal */
  950.             break;
  951.  
  952.         case 3:    /* Dense resolution - 2 colors - 40 lines */
  953.             /* newsize(TRUE, 40); */
  954.             strcpy(palstr, HIGHPAL);
  955.             /*change char set size */
  956.             break;
  957.     }
  958.  
  959.     /* and set up the default palette */
  960.     spal(palstr);
  961.     currez = nrez;
  962.     strcpy(sres, resname[currez]);
  963.  
  964.     stputc(ESC);    /* automatic overflow off */
  965.     stputc('w');
  966.     stputc(ESC);    /* turn cursor on */
  967.     stputc('e');
  968.  
  969.     return(TRUE);
  970. }
  971.  
  972. system(cmd)    /* call the system to execute a new program */
  973.  
  974. char *cmd;    /* command to execute */
  975.  
  976. {
  977.     char *pptr;            /* pointer into program name */
  978.     char pname[NSTRING];        /* name of program to execute */
  979.     char tail[NSTRING];        /* command tail */
  980.  
  981.     /* scan off program name.... */
  982.     pptr = pname;
  983.     while (*cmd && (*cmd != ' ' && *cmd != '\t'))
  984.         *pptr++ = *cmd++;
  985.     *pptr = 0;
  986.  
  987.     /* create program name length/string */
  988.     tail[0] = strlen(cmd);
  989.     strcpy(&tail[1], cmd);
  990.  
  991.     /* go do it! */
  992.     return(gemdos(        (int)EXEC,
  993.                 (int)0,
  994.                 (char *)pname,
  995.                 (char *)tail,
  996.                 (char *)NULL));
  997. }
  998.  
  999. #if    TYPEAH
  1000. typahead()
  1001.  
  1002. {
  1003.     int rval;    /* return value from BIOS call */
  1004.  
  1005.     /* get the status of the console */
  1006.     rval = bios(BCONSTAT, CON);
  1007.  
  1008.     /* end return the results */
  1009.     if (rval == 0)
  1010.         return(FALSE);
  1011.     else
  1012.         return(TRUE);
  1013. }
  1014. #endif
  1015.  
  1016. #if    FLABEL
  1017. fnclabel(f, n)        /* label a function key */
  1018.  
  1019. int f,n;    /* default flag, numeric argument [unused] */
  1020.  
  1021. {
  1022.     /* on machines with no function keys...don't bother */
  1023.     return(TRUE);
  1024. }
  1025. #endif
  1026. #else
  1027. sthello()
  1028. {
  1029. }
  1030. #endif
  1031. #endif
  1032.  
  1033.