home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / HP95_100 / COMM / TT / TT.C next >
Encoding:
C/C++ Source or Header  |  1994-07-19  |  1.6 KB  |  97 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <stdlib.h>
  4.  
  5. /* timing constants determined by linear regression */
  6. #define K1 758
  7. #define K2 45
  8.  
  9. void nap(long delay)
  10. {
  11.     while(--delay > 0) ;
  12. }
  13.  
  14. void twotone(long pt1, long pt2, long duration)
  15. {
  16.     char bits;
  17.     register int delay = 0;
  18.     long t1=pt1, t2=pt2;
  19.  
  20.     bits = inportb(0x61);
  21.     bits &= 0xfc;
  22.     disable();
  23.     while(duration > 0) {
  24.         outportb(0x61, bits);
  25.         bits ^= 2;
  26.         if(t1 < t2) {
  27.             delay += t1;
  28.             t2 -= delay;
  29.             t1 = pt1;
  30.         } else {
  31.             delay += t2;
  32.             t1 -= delay;
  33.             t2 = pt2;
  34.         }
  35.         duration -= delay;
  36.         delay -= K1;
  37.         while(delay > 0) delay -= K2;
  38.     }
  39.             
  40.     enable();
  41. }
  42.  
  43. struct dtmf {
  44.     int lo;
  45.     int hi;
  46. } tones[] = {
  47.     941, 1336,
  48.     697, 1209,
  49.     697, 1336,
  50.     697, 1477,
  51.     770, 1209,
  52.     770, 1336,
  53.     770, 1477,
  54.     852, 1209,
  55.     852, 1336,
  56.     852, 1477
  57. };
  58.  
  59. main(argc, argv)
  60. int argc;
  61. char *argv[];
  62. {
  63.     long pt1 =  4294;
  64.     long pt2 = 16000;
  65.     long duration = 2500000;
  66.         char *number = argv[1];
  67.         long one = 10000000;
  68.  
  69.     if(argc==4) { /* for testing, period1 period2 duration */
  70.         pt1 = atol(argv[1]);
  71.         pt2 = atol(argv[2]);
  72.         duration = atol(argv[3]);
  73.         twotone(pt1, pt2, duration);
  74.         exit(0);
  75.     }
  76.  
  77.     if(argc!=2) {
  78.         fprintf(stderr, "usage: tt number\n");
  79.         exit(1);
  80.     }
  81.     while(*number) {
  82.         int digit = *number - '0';
  83.         if(digit >= 0 && digit <= 9) {
  84.             int lo = tones[digit].lo;
  85.             int hi = tones[digit].hi;
  86.             int f1 = hi + lo;
  87.             int f2 = hi - lo;            
  88.             pt1 = (one + f1/2) / f1;
  89.             pt2 = (one + f2/2) / f2;
  90.                     printf("%ld %ld %ld\n", pt1, pt2, duration);
  91.             twotone(pt1, pt2, duration);
  92.         }
  93.         nap(2000);
  94.         number++;
  95.     }
  96. }
  97.