home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / tvgluetc.zip / INT15DEM.C < prev    next >
C/C++ Source or Header  |  1988-02-22  |  4KB  |  170 lines

  1. /*
  2. **    INT15DEM.C - demonstration program.
  3. **    IBM Personal Computer - TopView C Interface Header File.
  4. **    Written for Borland Turbo C v1.5.
  5. */
  6.  
  7. #include <dos.h>
  8. #include <io.h>
  9. #include <string.h>
  10.  
  11. #include "int15def.h"    /* definitions */
  12. #include "int15c.h"        /* types and function prototypes */
  13.  
  14. #define STDOUT  1
  15. #define STDERR  2
  16.  
  17. #define WR_STR(f,s)     write(f,s,strlen(s))    /* write any string */
  18. #define SO_STR(s)       WR_STR(STDOUT,s)    /* any string to STDOUT */
  19. #define SE_STR(s)       WR_STR(STDERR,s)    /* any string to STDERR */
  20.  
  21. #define WR_STRC(f,s)    write(f,s,sizeof(s)-1)  /* string constant */
  22. #define SO_STRC(s)      WR_STRC(STDOUT,s)   /* string con to STDOUT */
  23. #define SE_STRC(s)      WR_STRC(STDERR,s)   /* string con to STDERR */
  24.  
  25. void pascal tv_tone(                /* SOUND A TONE THRU TOPVIEW */
  26.     WORD frequency,                        /* hertz */
  27.     WORD duration                        /* timer ticks (18.2/second) */
  28. )
  29. {
  30.     REGLIST r;
  31.     r.bxreg = frequency;
  32.     r.cxreg = duration;
  33.     SubCall(SOUND,&r);
  34. }
  35.  
  36. OBJECT pascal tv_object(            /* GET A TOPVIEW OBJECT HANDLE */
  37.     WORD modifier                        /* which object */
  38. )
  39. {
  40.     PARMLIST p;
  41.     p.num_args = 0;
  42.     SendMsg(OBJECT_MSG,modifier,0,&p);
  43.     return (OBJECT)p.arg[0];
  44. }
  45.  
  46. int pascal tv_errormsg(                /* TOPVIEW ERROR MESSAGE WINDOW */
  47.     OBJECT window,                        /* handle of window object (0=ME) */
  48.     char *string,                        /* message text */
  49.     int tone,                            /* 1=sound a tone */
  50.     int button,                            /* 0=either; 1=1; 2=2; 3=either */
  51.     int rows,                            /* 0=default */
  52.     int columns                            /* 0=default */
  53. )
  54. {
  55.     REGLIST r;
  56.     typedef struct { WORD x:13, b:2, t:1; } TBX;
  57.     r.dxreg = window ? FP_SEG(window) : FP_SEG(tv_object(ME)) ;
  58.     r.esreg = FP_SEG((char far*)string);
  59.     r.direg = FP_OFF(string);
  60.     (*(TBX*)&r.bxreg).x = strlen(string);
  61.     (*(TBX*)&r.bxreg).b = button;
  62.     (*(TBX*)&r.bxreg).t = tone;
  63.     r.cxreg = rows | (columns << 8);
  64.     SubCall(DISPEROR,&r);
  65.     return r.bxreg;
  66. }
  67.  
  68. void pascal tv_printc(                /* CALL TOPVIEW TO PRINT A CHARACTER */
  69.     int character,
  70.     int attribute,
  71.     OBJECT window                        /* handle of window object (0=ME) */
  72. )
  73. {
  74.     REGLIST r;
  75.     r.dxreg = window ? FP_SEG(window) : FP_SEG(tv_object(ME)) ;
  76.     r.bxreg = character | (attribute << 8);
  77.     SubCall(PRINTC,&r);
  78. }
  79.  
  80. void pascal tv_pause(void)
  81. {
  82.     REGLIST r;
  83.     SubCall(PAUSE,&r);
  84. }
  85.  
  86. OBJECT pascal tv_newtimer(void)        /* GET A NEW TOPVIEW TIMER */
  87. {
  88.     PARMLIST p;
  89.     p.num_args = 0;
  90.     SendMsg(NEW_MSG,TIMER_CLASS,0,&p);
  91.     p.num_args = 0;
  92.     return (OBJECT)p.arg[0];
  93. }
  94.  
  95. void pascal tv_addtimer(            /* SET A TOPVIEW TIMER INTERVAL */
  96.     OBJECT timer,                        /* timer object */
  97.     DWORD time                            /* 1/100ths of a second from now */
  98. )
  99. {
  100.     PARMLIST p;
  101.     p.num_args = 1;
  102.     p.arg[0] = time;
  103.     SendMsg(ADDTO_MSG,TOS,timer,&p);
  104. }
  105.  
  106. DWORD pascal tv_lentimer(            /* TIMER REMAINING IN TOPVIEW TIMER */
  107.     OBJECT timer                        /* timer object */
  108. )
  109. {
  110.     PARMLIST p;
  111.     p.num_args = 0;
  112.     SendMsg(LEN_MSG,TOS,timer,&p);
  113.     return p.arg[0];
  114. }
  115.  
  116. DWORD pascal tv_readtimer(            /* READ/WAIT FOR TOPVIEW TIMER */
  117.     OBJECT timer                        /* timer object */
  118. )
  119. {
  120.     PARMLIST p;
  121.     p.num_args = 0;
  122.     SendMsg(READ_MSG,TOS,timer,&p);
  123.     return p.arg[0];
  124. }
  125.  
  126. void pascal    tv_freetimer(            /* SET A TOPVIEW TIMER INTERVAL */
  127.     OBJECT timer                        /* timer object */
  128. )
  129. {
  130.     PARMLIST p;
  131.     p.num_args = 0;
  132.     SendMsg(FREE_MSG,TOS,timer,&p);
  133. }
  134.  
  135. void window_test(void)
  136. {
  137.     PARMLIST p;
  138.     p.num_args = 2;
  139.     p.arg[0] = 6;
  140.     p.arg[1] = 2;
  141.     SendMsg(AT_MSG,ME,0,&p);
  142.     p.num_args = 2;
  143.     p.arg[0] = (DWORD)(void far*)"path";
  144.     p.arg[1] = 4;
  145.     SendMsg(WRITE_MSG,ME,0,&p);
  146.     tv_printc(0,0,0);    /* position the hardware cursor */
  147. #if 0
  148.     p.num_args = 0;
  149.     SendMsg(REDRAW_MSG,ME,0,&p);
  150. #endif
  151. }
  152.  
  153. main()
  154. {
  155.     OBJECT t;
  156.     if (!TopVer()) {
  157.         SE_STRC("This program requires TopView\n");
  158.         return 1;
  159.     }
  160.     window_test();
  161.     tv_addtimer(t=tv_newtimer(),500);    /* 5 seconds */
  162.     tv_readtimer(t);                    /* wait */
  163.     tv_freetimer(t);
  164.     tv_errormsg(0,"TEST ERROR MESSAGE - press ESC",1,0,0,0);
  165.     tv_tone(500,5);
  166.     tv_tone(750,2);
  167.     tv_tone(400,3);
  168.     return 0;
  169. }
  170.