home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / tst0831.zip / TST.C < prev    next >
Text File  |  1990-07-16  |  5KB  |  180 lines

  1. /********************************************************************
  2.         PopTEST (c) Copyright 1989 by MSI
  3.              Author - Ratko V. Tomic
  4. *********************************************************************/
  5.  
  6. #include "cr.h"
  7. #include "sio.h"
  8.  
  9. #ifdef PDK1
  10. #include "lm.h"
  11. #endif
  12.  
  13. #include "spawn.h"
  14.  
  15. /** RESIDENT CODE HOT-KEY LIST **/
  16.  
  17. #define SZX (80)
  18. #define SZY (25)
  19.  
  20. #define EXE_K1 (0x57)            /* F11 */
  21. #define EXE_K2 (M_LA|0x33)        /* Alt-Comma */
  22. #define CMD_K1 (0x58)            /* F12 */
  23. #define CMD_K2 (M_LA|0x34)        /* Alt-Period */
  24. #define UNL_KEY (M_LC|M_LS|0x16)    /* Ctl-Shift-U */
  25.  
  26. #ifdef PDK1
  27. word far *scr_buf;
  28. #else
  29. word *scr_buf;
  30. #endif
  31.  
  32. /** TEST FUNCTION FOR POP-UP **/
  33.  
  34. #define LEN 64
  35. #define MIN_P (0x0FFF)    /* 4K paragraphs = 64K of RAM minimum  */
  36. #define MAX_P (0x2FFF)    /* 12K paragraphs= 192K of RAM maximum */
  37.  
  38. int img_hndl;            /* File handle used for swapping */
  39. word lim_seg;            /* Valid only if LIM used */
  40. dword lfpos;            /* File or LIM posit for graphics */
  41. word MinP=MIN_P,MaxP=MAX_P;    /* MaxP may be adjusted if LIM too small */
  42. char *shell_ptr;        /* COMMAND.COM name/path */
  43. char shell_ln[]="  \r";        /* 2 spaces & Return */
  44. char prog[LEN+2];
  45. char cmd_ln[LEN+4]="  \r";    /* Strings for spawn() */
  46. word mem_sz;            /* Size allocated in paragraphs */
  47. char *tmp_buf;            /* Buffer with at least 128 char */
  48. word free_MCB;            /* Used for spawn() workspace */
  49. word cmd_env;            /* Environment to be passed to spawn() */
  50. char run_it;            /* Set to NZ if no questions asked */
  51.  
  52. pop_func(ask)
  53. {  register char *s;
  54.    int k,ep;
  55.    char *pn,*cn;
  56.  
  57.      crs_x=crs_y=0;
  58.      if (!ask)        /* Just shell out */
  59.     {
  60.     pn=shell_ptr;
  61.     cn=shell_ln;
  62.     dsp("Enter EXIT when done.");
  63.     goto RunProg;
  64.     }
  65.  
  66.      s=pn=prog;
  67.      cn=cmd_ln;
  68.      if (run_it) goto RunProg;
  69.  
  70.      s[ep=LEN]=0;
  71.      dsp("Program (w/.ext): ");        /* Get program name to run */
  72.      k=edit_str(s,ep,&ep,pckey);
  73.      if (k==K_ESC) return(0);
  74.  
  75. #ifdef PDK1     
  76.      exp_fname(s,tmp_buf);
  77.      tmp_buf[LEN]=0; str_cp(tmp_buf,s);
  78. #endif
  79.      crs_y++; crs_x=0;
  80.      dsp("Command line: ");        /* Get command line */
  81.      s=cmd_ln;*s++=0x20;*s++=0x20;    /* It must have 2 Blanks in front !*/
  82.      s[ep=LEN+1]=0;
  83.      k=str_pos(0xd,s); if (k) s[k-1]=0;    /* Remove <CR> from last run */
  84.      k=edit_str(s,ep,&ep,pckey);
  85.      if (k==K_ESC) return(0);
  86.      s+=str_len(s); *(word*)s=0xd;    /* Put <CR> NULL at the end */
  87.  
  88. /** EXECUTE PROGRAM (DOS access already obtained in do_pop() **/
  89.  
  90. RunProg:
  91.      crs_y++; crs_x=0; mv_crs();
  92.      set_crs_type(crs_type0);
  93.      if (!lim_seg) upd_file_size(img_hndl);
  94.      k=spawn(pn,cn,cmd_env,free_MCB);    /* Run the program */
  95.      if (pn==shell_ptr) flush_kbd();
  96.      else
  97.       {
  98.       if (k<0)
  99.      {
  100.      dsp("Cannot run: ");
  101.      dsp(pn);
  102.      crs_y++; crs_x=0;
  103.      dsp("Press any key...");
  104.      mv_crs();
  105.      }
  106.       if (run_it>=0) wait_key();
  107.       }
  108.      return(k);
  109. }
  110.  
  111.  
  112. /** SMALL UTILITY FUNCTIONS */
  113.  
  114. play()
  115. {
  116.    sound(880,20);
  117. }
  118.  
  119. wait_key()
  120. {
  121.    play();
  122.    flush_kbd();_hkey_again=0;
  123.    while (!(anykey()|_hkey_again));
  124.    flush_kbd();
  125. }
  126.  
  127. xchg_scr()
  128. {
  129.    crs_x=crs_y=0;
  130. #ifdef PDK1   
  131.    swap_fblk(SZX,SZY,scr_buf);
  132. #else
  133.    swap_blk(SZX,SZY,scr_buf);
  134. #endif
  135. }
  136.  
  137.  
  138. /************************************************
  139.      INTERRUPT SERVICE ROUTINE FOR HOT-KEYS
  140. *************************************************/
  141.  
  142.  
  143. isr(hk)
  144. { void far *tp; /* Temporary far pointer */
  145.   word fg_psp;  
  146.      sound_off();
  147.      if (dos_busy(20)) {play(); return;}  /* We need DOS */
  148.  
  149.      fg_psp=set_my_psp();
  150.  
  151.      mem_sz=get_app_mem(tmp_buf,img_hndl,lim_seg,MaxP,MaxP); /* Get memory */
  152.      if (!mem_sz) goto MemErr;        /* Exit if can't get memory */
  153.  
  154.      tp=get_app_ptr();            /* Far pointer for workspace */
  155.      if (0xffff==save_gs(img_hndl,lim_seg,1,lfpos,tp))
  156.     goto VidErr;
  157.      chk_video();            /* Get current video parameters */
  158. #ifdef PDK1
  159.      scr_buf=tp;            /*Save screen in freed far memory */
  160.      free_MCB=split_mcb(app_MCB,((SZX*SZY*2)+15)/16);
  161.      ffil_wrd(scr_buf,0x720,SZX*SZY);    /* Clear new screen */
  162. #else
  163.      free_MCB=app_MCB;
  164.      fil_wrd(scr_buf,0x720,SZX*SZY);    /* Clear new screen */
  165. #endif
  166.      save_hcrs();            /* Save hardware cursor */
  167.      xchg_scr();            /* Swap screen */
  168.     pop_func(hk&1);            /* Ask then run the program */
  169.      xchg_scr();
  170.      restore_hcrs();
  171.      restore_gs(img_hndl,lim_seg,1,lfpos,tp);
  172. VidErr:
  173.      ret_app_mem(tmp_buf,img_hndl,_dummy_ret);    /* Restore memory state */
  174. MemErr:
  175.      restore_psp(fg_psp);
  176.  
  177. }
  178.  
  179.  
  180.