home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / HP95_100 / P_GRAMG / HPCLIB / HPCLIB.ZIP / HPCLIB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-08  |  19.7 KB  |  875 lines

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