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