BIOS.Beep.Mod 870 B

123456789101112131415161718192021222324252627282930
  1. (* Aos, Copyright 2001, Pieter Muller, ETH Zurich *)
  2. MODULE Beep; (** AUTHOR "pjm"; PURPOSE "PC speaker driver"; *)
  3. IMPORT SYSTEM,Machine;
  4. CONST
  5. Rate = 1193180; (* timer clock is 1.19318 MHz *)
  6. (** Sound the PC speaker continuously at the specified frequency. Use 0 to switch off the sound. Not sharable. *)
  7. PROCEDURE Beep*(hz: LONGINT);
  8. VAR s: SET;
  9. BEGIN {EXCLUSIVE}
  10. (* stop counter *)
  11. Machine.Portin8(61H, SYSTEM.VAL(CHAR, s));
  12. Machine.Portout8(61H, CHR(SYSTEM.VAL(LONGINT, s - {0,1})));
  13. IF hz > 0 THEN
  14. hz := Rate DIV hz;
  15. (* init counter for hz *)
  16. Machine.Portout8(43H, 0B6X); (* timer 2, 16-bit, mode 3, binary *)
  17. Machine.Portout8(42H, CHR(hz MOD 100H));
  18. Machine.Portout8(42H, CHR(hz DIV 100H));
  19. (* start counter *)
  20. Machine.Portin8(61H, SYSTEM.VAL(CHAR, s));
  21. Machine.Portout8(61H, SYSTEM.VAL(CHAR, s + {0,1}))
  22. END
  23. END Beep;
  24. END Beep.