home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / HP95_100 / P_GRAMG / HPCLIB / HPCLIB.ZIP / HPWENV.C < prev   
Encoding:
C/C++ Source or Header  |  1994-09-07  |  19.4 KB  |  871 lines

  1. /************************************
  2. *      HP100LX GRAPHICS LIBRARY     *
  3. *            Version 2.1            *
  4. *          Sept. 31, 1994           *
  5. *         by: Harry Konstas         *
  6. *                                   *
  7. *   The following is the windows &  *
  8. * menu environment source code for  *
  9. * including in your programs. NOT   *
  10. * to be converted to a library.     *
  11. ************************************/
  12.                 
  13. #include <dos.h>
  14. #include <bios.h>
  15. #include <stdlib.h>
  16.  
  17. /* Constant declaration */
  18.  
  19. #define BLACK_COLOR 1
  20. #define WHITE_COLOR 0
  21.  
  22. #define AN_LEFT 0x20
  23. #define AN_RIGHT 0x60
  24.  
  25. #define SMALL_FONT 0x0808
  26. #define MEDIUM_FONT 0x0a0b
  27. #define LARGE_FONT 0x100c
  28.  
  29. #define FORCE_RULE 0
  30. #define AND_RULE 1
  31. #define OR_RULE 2
  32. #define XOR_RULE 3
  33. #define INVFOR_RULE 4
  34. #define INVAND_RULE 5
  35. #define INVOR_RULE 6
  36. #define INVXOR_RULE 7
  37. #define TXT_RULE 8
  38.  
  39. #define OUTLINE_FILL 0
  40. #define SOLID_FILL 1
  41. #define PATTERN_FILL 2
  42.  
  43. /* FUNCTION DECLARATIONS */
  44.  
  45.  
  46. /*****************
  47. * Misc functions *
  48. *****************/
  49.  
  50. void is100(void);
  51. void announ(int position);
  52. void toplin(char far *string);
  53. void botlin(char far *labels);
  54. void terminate(void);
  55. int  getscan(void);
  56.  
  57.  
  58. /*******************************
  59. * Low level graphics functions *
  60. *******************************/
  61.  
  62. void setgra(void);
  63. void setmda(void);
  64. void setfon(int size);
  65. void setpos(int horiz,int vert);
  66. void setcol(int color);
  67. void setrul(int rule);
  68. void setlin(unsigned int line_type);
  69. void setmsk(char far *fill_mask);
  70. void putimg(int horiz,int vert,int rule,char far *buffer);
  71. void getimg(int from_horiz,int from_vert,int to_horiz,int to_vert,char far *buffer);
  72. void wrtext(int horiz,int vert,char far *string);
  73.  
  74.  
  75. /********************************
  76. * High level graphics functions *
  77. ********************************/
  78.  
  79. void line(int from_horiz,int from_vert,int to_horiz,int to_vert);
  80. void rectan(int from_horiz,int from_vert,int to_horiz,int to_vert,int fill);
  81. void revblk(int from_horiz,int from_vert,int to_horiz,int to_vert);
  82.  
  83.  
  84. /*******************
  85. * Window functions *
  86. *******************/
  87.  
  88. void errwin(char far *message);
  89. void open_win(int winid,int from_horiz,int from_vert,int to_horiz,int to_vert,char far *message);
  90. void close_win(int winid);
  91. void window(int from_horiz,int from_vert,int to_horiz,int to_vert,char far *message);
  92.  
  93.  
  94. /*****************
  95. * Menu functions *
  96. *****************/
  97.  
  98. void open_mbar(void);
  99. void close_mbar(void);
  100. void sel_menu(int menuid);
  101. int  open_menu(int menuid);
  102. void close_menu();
  103. void sel_opt(int optnum);
  104. int navigate(int menum);
  105.  
  106.  
  107. /********************************************
  108. * Global (environment) variable definitions *
  109. ********************************************/
  110.  
  111. int  menupos;               /* Menu position register      */
  112. int  menuend;               /* Menu end position           */
  113. int  wposhor[15];           /* Window horiz pos. registers */
  114. int  wposver[15];           /* Window vert pos. registers  */
  115. char *winbuf[10];           /* Window buffer pointers      */
  116.  
  117.  
  118. /* Fill mask definition (for window shadows) */
  119.  
  120. char fmask[]=
  121. {'\x55','\xaa','\x55','\xaa','\x55','\xaa','\x55','\xaa','\x0'};
  122.  
  123.  
  124. /***************
  125. * IS IT 100LX? *
  126. ***************/
  127.  
  128. is100(void)
  129.  
  130. {
  131.     union REGS inregs,outregs;
  132.     struct SREGS segregs;
  133.     inregs.x.ax=0x4dd4;
  134.     int86x(0x15,&inregs,&outregs,&segregs);
  135.     if (outregs.x.bx != 0x4850) not100();
  136.     if (outregs.x.cx > 0x102) not100();
  137. }
  138.  
  139. not100()
  140. {
  141.     printf("This program runs only on the HP100LX palmtop.\n");
  142.     exit(1);
  143. }
  144.  
  145. /*************************
  146. * ANNOUNCIATORS POSITION *
  147. *************************/
  148.  
  149. announ(int position)
  150.  
  151. {
  152.     union REGS inregs,outregs;
  153.     struct SREGS segregs;
  154.     inregs.h.al = position;
  155.     inregs.h.ah = 0x61;
  156.     int86x(0x15,&inregs,&outregs,&segregs);
  157. }
  158.  
  159. /********************
  160. * SET GRAPHICS MODE *
  161. ********************/
  162.  
  163. setgra()
  164.  
  165. {
  166.     union REGS inregs,outregs;
  167.     struct SREGS segregs;
  168.     inregs.x.ax = 6;
  169.     int86x(0x5f,&inregs,&outregs,&segregs);
  170. }
  171.  
  172. /****************
  173. * SET TEXT MODE *
  174. ****************/
  175.  
  176. setmda()
  177.  
  178. {
  179.     union REGS inregs,outregs;
  180.     struct SREGS segregs;
  181.     inregs.x.ax = 3;
  182.     int86x(0x5f,&inregs,&outregs,&segregs);
  183. }
  184.  
  185. /***********
  186. * SET FONT *
  187. ***********/
  188.  
  189. setfon(int size)
  190.  
  191. {
  192.     union REGS inregs,outregs;
  193.     struct SREGS segregs;
  194.     inregs.x.cx=size;
  195.     inregs.h.ah=0x10;
  196.     int86x(0x5f,&inregs,&outregs,&segregs);
  197.     segregs.es=outregs.x.dx;
  198.     inregs.x.di=outregs.x.ax;
  199.     inregs.h.ah=0x11;
  200.     int86x(0x5f,&inregs,&outregs,&segregs);
  201. }
  202.  
  203. /*******************
  204. * SET PEN POSITION *
  205. *******************/
  206.  
  207. setpos(int horiz,int vert)
  208.  
  209. {
  210.     union REGS inregs,outregs;
  211.     struct SREGS segregs;
  212.     inregs.x.cx=horiz;
  213.     inregs.x.dx=vert;
  214.     inregs.h.ah=8;
  215.     inregs.h.al=0;
  216.     int86x(0x5f,&inregs,&outregs,&segregs);
  217. }
  218.  
  219. /***********************
  220. * SET REPLACEMENT RULE *
  221. ***********************/
  222.  
  223. setrul(int rule)
  224.  
  225. {
  226.     union REGS inregs,outregs;
  227.     struct SREGS segregs;
  228.     inregs.h.al=rule;
  229.     inregs.h.ah=0x0a;
  230.     int86x(0x5f,&inregs,&outregs,&segregs);
  231. }
  232.  
  233. /************
  234. * SET COLOR *
  235. ************/
  236.  
  237. setcol(int color)
  238.  
  239. {
  240.     union REGS inregs,outregs;
  241.     struct SREGS segregs;
  242.     inregs.h.ah=9;
  243.     inregs.h.al=color;
  244.     int86x(0x5f,&inregs,&outregs,&segregs);
  245. }
  246.  
  247. /****************
  248. * SET LINE TYPE *
  249. ****************/
  250.  
  251. setlin(unsigned int line_type)
  252.  
  253. {
  254.     union REGS inregs,outregs;
  255.     struct SREGS segregs;
  256.     inregs.h.ah=0x0b;
  257.     inregs.x.cx=line_type;
  258.     int86x(0x5f,&inregs,&outregs,&segregs);
  259. }
  260.  
  261. /****************
  262. * SET FILL MASK *
  263. ****************/
  264.  
  265. setmsk(char far *fill_mask)
  266.  
  267. {
  268.     union REGS inregs,outregs;
  269.     struct SREGS segregs;
  270.     inregs.x.di=FP_OFF(fill_mask);
  271.     segregs.es=FP_SEG(fill_mask);
  272.     inregs.h.ah=1;
  273.     int86x(0x5f,&inregs,&outregs,&segregs);
  274. }
  275.  
  276. /*****************
  277. * DRAW RECTANGLE *
  278. *****************/
  279.  
  280. rectan(int from_horiz,int from_vert,int to_horiz,int to_vert,int fill)
  281.  
  282. {
  283.     union REGS inregs,outregs;
  284.     struct SREGS segregs;
  285.     setpos(from_horiz,from_vert);
  286.     inregs.x.cx=to_horiz;
  287.     inregs.x.dx=to_vert;
  288.     inregs.h.ah=5;
  289.     inregs.h.al=fill;
  290.     int86x(0x5f,&inregs,&outregs,&segregs);
  291. }
  292.  
  293. /************
  294. * DRAW LINE *
  295. ************/
  296.  
  297. line(int from_horiz,int from_vert,int to_horiz,int to_vert)
  298.  
  299. {
  300.     union REGS inregs,outregs;
  301.     struct SREGS segregs;
  302.     inregs.x.cx=from_horiz;
  303.     inregs.x.dx=from_vert;
  304.     inregs.h.ah=8;
  305.     inregs.h.al=0;
  306.     int86x(0x5f,&inregs,&outregs,&segregs);
  307.  
  308.     inregs.x.cx=to_horiz;
  309.     inregs.x.dx=to_vert;
  310.     inregs.h.ah=6;
  311.     int86x(0x5f,&inregs,&outregs,&segregs);
  312. }
  313.  
  314. /****************
  315. * REVERSE BLOCK *
  316. ****************/
  317.  
  318. revblk(int from_horiz,int from_vert,int to_horiz,int to_vert)
  319.  
  320. {
  321.     setrul(XOR_RULE);
  322.     rectan(from_horiz,from_vert,to_horiz,to_vert,SOLID_FILL);
  323.     setrul(FORCE_RULE);
  324. }
  325.  
  326. /*************
  327. * WRITE TEXT *
  328. *************/
  329.  
  330. wrtext(int horiz,int vert,char far *string)
  331.  
  332. {
  333.     union REGS inregs,outregs;
  334.     struct SREGS segregs;
  335.     inregs.x.cx=horiz;
  336.     inregs.x.dx=vert;
  337.     inregs.x.di=FP_OFF(string);
  338.     segregs.es=FP_SEG(string);
  339.     inregs.h.ah=15;
  340.     inregs.h.al=0;
  341.     int86x(0x5f,&inregs,&outregs,&segregs);
  342. }
  343.  
  344. /******************
  345. * PUT IMAGE BLOCK *
  346. ******************/
  347.  
  348. putimg(int horiz,int vert,int rule,char far *buffer)
  349.  
  350. {
  351.     union REGS inregs,outregs;
  352.     struct SREGS segregs;
  353.     inregs.x.cx=horiz;
  354.     inregs.x.dx=vert;
  355.     inregs.x.di=FP_OFF(buffer);
  356.     segregs.es=FP_SEG(buffer);
  357.     inregs.h.ah=14;
  358.     inregs.h.al=rule;
  359.     int86x(0x5f,&inregs,&outregs,&segregs);
  360. }
  361.  
  362. /******************
  363. * GET IMAGE BLOCK * int86x() function doesn't support the BP register...
  364. ******************/
  365.  
  366. getimg(int from_horiz,int from_vert,int to_horiz,int to_vert,char far *buffer)
  367.  
  368. {
  369.  
  370.     char get_asm[]={
  371.     
  372.   '\x06',                /*   push    es                      */
  373.   '\x8B','\x0F',         /*   mov     cx,[bx] ; X 1st corner  */
  374.   '\x83','\xC3','\x02',  /*   add     bx,2                    */
  375.   '\x8B','\x17',         /*   mov     dx,[bx] ; Y 1st corner  */
  376.   '\x83','\xC3','\x02',  /*   add     bx,2                    */
  377.   '\x8B','\x37',         /*   mov     si,[bx] ; X 2nd corner  */
  378.   '\x83','\xC3','\x02',  /*   add     bx,2                    */
  379.   '\x8B','\x2F',         /*   mov     bp,[bx] ; Y 2nd corner  */
  380.   '\x83','\xC3','\x02',  /*   add     bx,2                    */
  381.   '\x8B','\x3F',         /*   mov     di,[bx] ; buffer offset */
  382.   '\x8C','\xC8',         /*   mov     ax,cs                   */
  383.   '\x8E','\xC0',         /*   mov     es,ax   ; buffer segment*/
  384.   '\xB4','\x0D',         /*   mov     ah,13                   */
  385.   '\xCD','\x5F',         /*   int     5fh     ; call get_image*/
  386.   '\x07',                /*   pop     es                      */
  387.   '\xC3'      };         /*   ret             ; returns AX    */
  388.  
  389.  
  390.     struct {
  391.         int x_1;
  392.         int y_1;
  393.         int x_2;
  394.         int y_2;
  395.         int boff;
  396.         int bseg;
  397.     }param;
  398.  
  399.     param.x_1=from_horiz;
  400.     param.y_1=from_vert;
  401.     param.x_2=to_horiz;
  402.     param.y_2=to_vert;
  403.     param.boff=FP_OFF(buffer);
  404.     param.bseg=FP_SEG(buffer);
  405.  
  406. /* Note: some compilers may not support the following 'asm'
  407.          function as my compiler does. Please modify accordingly.
  408.          In the mean time I will find a way to replace it with
  409.          something more standard.     */
  410.  
  411.     asm(get_asm,¶m);
  412. }
  413.  
  414. /******************
  415. * WINDOW CREATION *
  416. ******************/
  417.  
  418. window(int from_horiz,int from_vert,int to_horiz,int to_vert,char far *message)
  419.  
  420. {
  421.     int horiz_tab;
  422.  
  423.     setmsk(fmask);
  424.     setrul(FORCE_RULE);
  425.  
  426.     rectan(to_horiz+1,from_vert+4,to_horiz+6,to_vert+4,PATTERN_FILL);
  427.     rectan(from_horiz+5,to_vert+1,to_horiz+6,to_vert+4,PATTERN_FILL);
  428.  
  429.     setcol(WHITE_COLOR);
  430.     rectan(from_horiz,from_vert,to_horiz,to_vert,SOLID_FILL);
  431.  
  432.     setcol(BLACK_COLOR);
  433.     rectan(from_horiz,from_vert,to_horiz,to_vert,OUTLINE_FILL);
  434.  
  435.     if(message!=0)
  436.     {
  437.         horiz_tab=(((to_horiz-from_horiz)/8)-strlen(message));
  438.         horiz_tab=(horiz_tab*4)+from_horiz;
  439.         setfon(SMALL_FONT);
  440.         wrtext(horiz_tab,from_vert+2,message);
  441.         revblk(from_horiz+1,from_vert+1,to_horiz-1,from_vert+10);
  442.         setfon(MEDIUM_FONT);
  443.     }
  444.  
  445. }
  446.  
  447. /*********************
  448. * TOP LINE FORMATION *
  449. *********************/
  450.  
  451. toplin(char far *string)
  452.  
  453. {
  454.     setrul(TXT_RULE);
  455.     setcol(BLACK_COLOR);
  456.     setfon(SMALL_FONT);
  457.     wrtext(0,1,string);
  458.     revblk(0,0,639,9);
  459.     setrul(FORCE_RULE);
  460.     rectan(0,0,639,9,OUTLINE_FILL);
  461.     setfon(MEDIUM_FONT);
  462. }
  463.  
  464. /************************
  465. * BOTTOM LINE FORMATION *
  466. ************************/
  467.  
  468. botlin(char far *labels)
  469.  
  470. {
  471. int from_horiz,from_vert,to_horiz,to_vert;
  472.  
  473.     from_horiz=31;
  474.     from_vert=190;
  475.     to_horiz=88;
  476.     to_vert=199;
  477.  
  478.     setfon(SMALL_FONT);
  479.     setcol(BLACK_COLOR);
  480.     setrul(FORCE_RULE);
  481.  
  482.     rectan(from_horiz,from_vert,to_horiz,to_vert,SOLID_FILL);
  483.     from_horiz=to_horiz+3;
  484.     rectan(from_horiz,190,from_horiz+57,199,SOLID_FILL);
  485.     from_horiz=from_horiz+60;
  486.     rectan(from_horiz,190,from_horiz+57,199,SOLID_FILL);
  487.     from_horiz=from_horiz+60;
  488.     rectan(from_horiz,190,from_horiz+57,199,SOLID_FILL);
  489.     from_horiz=from_horiz+64;
  490.  
  491.     rectan(from_horiz,190,from_horiz+57,199,SOLID_FILL);
  492.     from_horiz=from_horiz+60;
  493.     rectan(from_horiz,190,from_horiz+57,199,SOLID_FILL);
  494.     from_horiz=from_horiz+60;
  495.     rectan(from_horiz,190,from_horiz+57,199,SOLID_FILL);
  496.     from_horiz=from_horiz+60;
  497.     rectan(from_horiz,190,from_horiz+57,199,SOLID_FILL);
  498.     from_horiz=from_horiz+64;
  499.  
  500.     rectan(from_horiz,190,from_horiz+57,199,SOLID_FILL);
  501.     from_horiz=from_horiz+60;
  502.     rectan(from_horiz,190,from_horiz+57,199,SOLID_FILL);
  503.  
  504.     setrul(XOR_RULE);
  505.     wrtext(39,191,labels);
  506. }
  507.  
  508. /***************
  509. * ERROR WINDOW *
  510. ***************/
  511.  
  512. errwin(char far *message)
  513.  
  514. {
  515.     int horiz_tab;
  516.  
  517.     horiz_tab=(((480-160)/8)-strlen(message));
  518.     horiz_tab=(horiz_tab*4)+160;
  519.  
  520.     open_win(0,160,60,480,120,"ERROR");
  521.     wrtext(horiz_tab,87,message);
  522.     sound(150,10);
  523.     while (!kbhit());                /* Wait for a key */
  524.     close_win(0);
  525. }
  526.  
  527. /**************
  528. * OPEN WINDOW *
  529. **************/
  530.  
  531. void open_win(int winid,int from_horiz,int from_vert,int to_horiz,int to_vert,char far *message)
  532.  
  533. {
  534.     unsigned int buflen,horlen,verlen;
  535.     char *buf_pnt;
  536.  
  537.     horlen=to_horiz-from_horiz+14;
  538.     verlen=to_vert-from_vert+7;
  539.     buflen=10+((horlen/8)*verlen);
  540.  
  541.     buf_pnt=malloc(buflen);
  542.     if(buf_pnt==NULL) abort();   /* abort if not enough memory */
  543.  
  544.     getimg(from_horiz,from_vert,to_horiz+6,to_vert+6,buf_pnt);
  545.     window(from_horiz,from_vert,to_horiz,to_vert,message);
  546.  
  547.     winbuf[winid]=buf_pnt;
  548.     wposhor[winid]=from_horiz;
  549.     wposver[winid]=from_vert;
  550. }
  551.  
  552. /***************
  553. * CLOSE WINDOW *
  554. ***************/
  555.  
  556. close_win(int winid)
  557.  
  558. {
  559.     putimg(wposhor[winid],wposver[winid],FORCE_RULE,winbuf[winid]);
  560.     free(winbuf[winid]);
  561.  
  562. }
  563.  
  564.  
  565. /****************
  566. * OPEN MENU BAR *
  567. ****************/
  568.  
  569. open_mbar()
  570.  
  571. {
  572.    open_win(11,0,9,633,28,0);
  573.    setfon(MEDIUM_FONT);
  574.    wrtext(10,14,mbarmes);
  575. }
  576.  
  577.  
  578. /*****************
  579. * CLOSE MENU BAR *
  580. *****************/
  581.  
  582. close_mbar()
  583.  
  584. {
  585.    close_win(11);
  586. }
  587.  
  588.  
  589. /**************
  590. * SELECT MENU *
  591. **************/
  592.  
  593. sel_menu(int menuid)
  594.  
  595.  
  596. {
  597.     int f,cpos,lpos,rpos;
  598.     cpos=0;
  599.  
  600.         for(f=1;f<=menuid;f++)
  601.         {
  602.             lpos=cpos;
  603.             while(mbarmes[cpos++]!=32);
  604.             rpos=cpos-1;
  605.             while(mbarmes[cpos++]==32);
  606.             cpos--;
  607.         }
  608.  
  609.     lpos=1+(lpos*10);
  610.     rpos=18+(rpos*10);
  611.     revblk(lpos,10,rpos,27);
  612.     menupos = lpos;
  613. }
  614.  
  615. /************
  616. * OPEN MENU *
  617. ************/
  618.  
  619. int open_menu(int menuid)
  620.  
  621. {
  622.  
  623.     int f,width,lenght,horiz,vert,nopt;
  624.     width=0;
  625.     menuid--;
  626.  
  627.     for(f=0;f<10;f++)
  628.     {
  629.         if(strlen(menitm[menuid][f])==0) break;
  630.         if(width<strlen(menitm[menuid][f]))
  631.         width=strlen(menitm[menuid][f]);
  632.     }
  633.  
  634.     width=(width+4)*10;
  635.     lenght=29+(f*16);
  636.  
  637.     if(menupos+width>632)
  638.         menupos=menupos-((menupos+width)-632);
  639.     if(menupos==1) menupos=0;
  640.  
  641.     open_win(10,menupos,28,menupos+width,lenght,0);
  642.  
  643.     horiz=menupos+20;
  644.     vert=32;
  645.     nopt=f;
  646.  
  647.     for(f=0;f<=nopt;f++)
  648.     {
  649.        wrtext(horiz,vert,menitm[menuid][f]);
  650.        vert=vert+16;
  651.     }
  652.  
  653.     menuend=menupos+width;
  654.     return(nopt);
  655. }
  656.  
  657. /*************
  658. * CLOSE MENU *
  659. *************/
  660.  
  661. close_menu()
  662.  
  663. {
  664.     close_win(10);
  665.  
  666. }
  667.  
  668.  
  669. /****************
  670. * SELECT OPTION *
  671. ****************/
  672.  
  673. sel_opt(int optn)
  674.  
  675. {
  676.     int vert;
  677.     optn--;
  678.     vert=(optn*16)+29;
  679.     revblk(menupos+1,vert,menuend-1,vert+15);
  680. }
  681.  
  682.  
  683. /************************************
  684. * MENU AUTOMATIC NAVIGATION PROCESS * Returns operid (0=nop,255=act,other=operation id.
  685. ************************************/
  686.  
  687. int navigate(int menum)
  688.  
  689.     {
  690.  
  691. static  char menuid,mbarflg,omenflg,optnum,optid;
  692. static  int operid,key;
  693.  
  694.         if(operid!=255) operid=0;
  695.         if(mbarflg==0) operid=0;
  696.  
  697.         if(inp(0x60)==0x7a) /* MENU key process */
  698.         {
  699.             if (mbarflg==0)
  700.             {
  701.                 operid=255;
  702.                 open_mbar();
  703.                 sel_menu(1);
  704.                 mbarflg=1;
  705.                 menuid=1;
  706.                 while(inp(0x60)==0x7a);
  707.             }
  708.         }
  709.  
  710.  
  711.         if(inp(0x60)==0x38)  /* ALT key process */
  712.         {
  713.             if(mbarflg==1)
  714.             {
  715.                 if(omenflg==0)
  716.                 {
  717.                     operid=0;
  718.                     close_mbar();
  719.                     mbarflg=0;
  720.                     while(inp(0x60)==0x38);
  721.                 }
  722.             }
  723.  
  724.             else
  725.             {
  726.                 operid=255;
  727.                 open_mbar();
  728.                 sel_menu(1);
  729.                 mbarflg=1;
  730.                 menuid=1;
  731.                 while(inp(0x60)==0x38);
  732.             }
  733.         }
  734.  
  735.  
  736.         if(inp(0x60)==1)  /* ESC key process */
  737.         {
  738.             if(mbarflg==0) terminate();
  739.  
  740.             if(mbarflg==1)
  741.             {
  742.                 if(omenflg==0)
  743.                 {
  744.                     close_mbar();
  745.                     mbarflg=0;
  746.                 }
  747.  
  748.                 else
  749.                 {
  750.                     close_menu();
  751.                     omenflg=0;
  752.                 }
  753.             }
  754.             while(inp(0x60)==1);
  755.         }
  756.  
  757.  
  758.         if(mbarflg==1)
  759.         {
  760.  
  761.             key=getch();
  762.  
  763.             if(key==0x4d)  /* RightArrow key process */
  764.             {
  765.                 key=0;
  766.                 if(omenflg==1) close_menu();
  767.                 sel_menu(menuid);
  768.                 menuid++;
  769.                 if(menuid>menum) menuid=1;
  770.                 sel_menu(menuid);
  771.  
  772.                 if(omenflg==1)
  773.                 {
  774.                     optnum=open_menu(menuid);
  775.                     optid=1;
  776.                     if(optnum!=0) sel_opt(optid);
  777.                 }
  778.             }
  779.  
  780.             if(key==0x4b)   /* LeftArrow key process */
  781.             {
  782.                 key=0;
  783.                 if(omenflg==1) close_menu();
  784.                 sel_menu(menuid);
  785.                 menuid--;
  786.                 if(menuid==0) menuid=menum;
  787.                 sel_menu(menuid);
  788.  
  789.                 if(omenflg==1)
  790.                 {
  791.                     optnum=open_menu(menuid);
  792.                     optid=1;
  793.                     if(optnum!=0) sel_opt(optid);
  794.                 }
  795.             }
  796.  
  797.  
  798.             if(omenflg==0)
  799.             {
  800.                 if(key==0x50) /* DownArrow key process */
  801.                 {
  802.                     key=0;
  803.                     optnum=open_menu(menuid);
  804.                     optid=1;
  805.                     if(optnum!=0) sel_opt(optid);
  806.                     omenflg=1;
  807.                 }
  808.  
  809.                 if(key==0x0d) /* ENTER key process */
  810.                 {
  811.                     key=0;
  812.                     optnum=open_menu(menuid);
  813.                     optid=1;
  814.                     if(optnum!=0) sel_opt(optid);
  815.                     omenflg=1;
  816.                 }
  817.             }
  818.  
  819.             if(omenflg==1)
  820.             {
  821.                 if(key==0x50)  /* DownArrow key (menu) process */
  822.                 {
  823.                     key=0;
  824.                     if(optnum!=0)
  825.                     {
  826.  
  827.                         sel_opt(optid++);
  828.                         if(optid>optnum) optid=1;
  829.                         sel_opt(optid);
  830.                     }
  831.                 }
  832.  
  833.                 if(key==0x48)   /* UpArrow key (menu) process */
  834.                 {
  835.                     key=0;
  836.                     if(optnum!=0)
  837.                     {
  838.                         sel_opt(optid--);
  839.                         if(optid==0) optid=optnum;
  840.                         sel_opt(optid);
  841.                     }
  842.                 }
  843.  
  844.                 if(key==0x0d) /* ENTER key (menu) process */
  845.                 {
  846.                     key=0;
  847.                     operid=(menuid<<4)+optid;
  848.                     close_menu();
  849.                     omenflg=0;
  850.                     close_mbar();
  851.                     mbarflg=0;
  852.                 }
  853.             }
  854.         }
  855.         return(operid);
  856.     }
  857.  
  858.  
  859. /********************
  860. * TERMINATE PROGRAM *
  861. ********************/
  862.  
  863. terminate(void)
  864.  
  865. {
  866.     announ(AN_RIGHT);            /* Place announciators right */
  867.     setmda();                    /* Set screen mode to text mode */
  868.     exit(0);                     /* Exit program */
  869. }
  870.  
  871.