beep.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Copyright (C) 2021 Rain */
  2. /* This file is part of XNIX. */
  3. /*
  4. XNIX is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) and later version.
  8. */
  9. /*
  10. XNIX is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. */
  15. /*
  16. You should have received a copy of the GNU General Public License
  17. along with XNIX. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. #include <kernel/init.h>
  20. #include <kernel/errno.h>
  21. #include <kernel/types.h>
  22. #include <kernel/console.h>
  23. #include <kernel/mm.h>
  24. #include <kernel/int.h>
  25. #include <kernel/panic.h>
  26. #include <arch/io.h>
  27. #include <modules/beep.h>
  28. static void beep_on(void) {
  29. __uint8_t a;
  30. a = (inb(0x61) | 0x03) & 0x0f;
  31. outb(a, 0x61);
  32. return;
  33. }
  34. void beep_off(void) {
  35. __uint8_t a;
  36. a = inb(0x61) & 0x0d;
  37. outb(a, 0x61);
  38. return;
  39. }
  40. errno_t beep_init(void) {
  41. return 0;
  42. }
  43. void beep(__uint32_t value) {
  44. value = 1193180000 / value;
  45. outb(0xb6, 0x43);
  46. outb(value & 0xff, 0x42);
  47. outb((value >> 8) & 0xff, 0x42);
  48. beep_on();
  49. return;
  50. }