home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / ISC366.ZIP / EXAMPLES / EXAMPLE2.CPP < prev    next >
C/C++ Source or Header  |  1993-09-01  |  3KB  |  88 lines

  1. //////////////////////////////////////////////////////////////////////////////
  2. //                                                                          //
  3. //                             example2 of ISC...                           //
  4. //                             ------------------                           //
  5. //                                                                          //
  6. //  - Put an isr on interrupt 65h which gets 2 params (in ax and bx)        //
  7. //    which control the frequency and length of a beep.if it is installed   //
  8. //    it returns ax=0x44.                                                   //
  9. //  - This is also a small example of multiple inheritence...               //
  10. //  - The beep handler is automatic (because the program is not a TSR).     //
  11. //                                                                          //
  12. //////////////////////////////////////////////////////////////////////////////
  13. //                                                                          //
  14. //                       By:- Ofer Laor (AKA LeucroTTa)                     //
  15. //                                                                          //
  16. //////////////////////////////////////////////////////////////////////////////
  17.  
  18. #include "isc.h"   // ISC.
  19. #include <stdio.h> // printf.
  20. #include <dos.h>   // outportb.
  21.  
  22. class SCREEN {
  23.       virtual void inc();
  24. };
  25.  
  26. void SCREEN::inc()
  27. {
  28.     (*((char far *)0xb8000000L))++;
  29. }
  30.  
  31. class BEEP: public SCREEN, public ISC {
  32.  
  33.       unsigned i, j;
  34.       char originalbits, bits;
  35.       unsigned char bcount;
  36.  
  37.       virtual void isr (IREGS& regs);
  38.  
  39.       virtual void inc();
  40. };
  41.  
  42. void BEEP::inc()
  43. {
  44.     (*((char far *)0xb8000000L))++;
  45.     (*((char far *)0xb8000000L))++;
  46. }
  47.  
  48. void BEEP::isr (IREGS& regs)
  49. {
  50.     bcount= regs.x.ax>> 8;
  51.     bits= originalbits= inportb(0x61);
  52.  
  53.     for (i= 0; i<= bcount; i++)  {
  54.  
  55.     outportb(0x61, bits & 0xfc); // speaker off.
  56.  
  57.     for (j= 0; j<= regs.x.bx; j++);
  58.  
  59.     outportb(0x61, bits| 2); // speaker on.
  60.  
  61.     for (j= 0; j<= regs.x.bx; j++);
  62.     }
  63.  
  64.     outportb(0x61, originalbits);
  65.     inc();
  66.     regs.x.ax= 0x44;
  67.     regs.x.flags&= ~1; // reset CARRY.
  68. }
  69.  
  70.  
  71. int main()
  72. {
  73.     BEEP beep; // not a TSR so automatic vars are OK.
  74.  
  75.     beep.activate(0x65);
  76.  
  77.     REGS regs;
  78.  
  79.     regs.x.ax= 0xffff;
  80.     regs.x.bx= 1700;
  81.     int86(0x65,®s,®s);
  82.     if ((regs.x.ax!= 0x44) || regs.x.cflag)
  83.        printf("Error!!!\a\n");
  84.     else
  85.        printf("Ok...\n");
  86.  
  87.     return 0;
  88. }