From f1e62229ca1ce4d7768268724204772049341282 Mon Sep 17 00:00:00 2001
From: Marvin Borner
Date: Mon, 16 Sep 2019 19:44:04 +0200
Subject: Added basic frequency sound generator

 Changes to be committed:
	new file:   src/graphics/graphics.h
	modified:   src/kernel.c
	new file:   src/sound/frequency.c
	new file:   src/sound/sound.h
	modified:   build.sh
 Changes not staged for commit:
	deleted:    src/graphics/vga.h
	modified:   src/input/ps2/keyboard.c
	modified:   src/input/ps2/mouse.c
	modified:   src/interrupts/irq.c
	modified:   src/interrupts/isr.c
	modified:   src/memory/memory.c
---
 src/graphics/graphics.h | 19 +++++++++++++++++++
 src/kernel.c            |  4 +++-
 src/sound/frequency.c   | 32 ++++++++++++++++++++++++++++++++
 src/sound/sound.h       |  6 ++++++
 4 files changed, 60 insertions(+), 1 deletion(-)
 create mode 100644 src/graphics/graphics.h
 create mode 100644 src/sound/frequency.c
 create mode 100644 src/sound/sound.h

(limited to 'src')

diff --git a/src/graphics/graphics.h b/src/graphics/graphics.h
new file mode 100644
index 0000000..7c449f1
--- /dev/null
+++ b/src/graphics/graphics.h
@@ -0,0 +1,19 @@
+#ifndef MELVIX_VGA_H
+#define MELVIX_VGA_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+enum vga_color;
+
+void terminal_initialize(void);
+
+void terminal_set_color(uint8_t color);
+
+void terminal_clear();
+
+void terminal_write_string(const char *data);
+
+void terminal_put_char(char c);
+
+#endif
\ No newline at end of file
diff --git a/src/kernel.c b/src/kernel.c
index 0e1b020..102c21e 100644
--- a/src/kernel.c
+++ b/src/kernel.c
@@ -1,8 +1,9 @@
-#include "graphics/vga.h"
+#include "graphics/graphics.h"
 #include "gdt/gdt.h"
 #include "interrupts/interrupts.h"
 #include "input/input.h"
 #include "timer/timer.h"
+#include "sound/sound.h"
 
 void kernel_main(void) {
     gdt_install();
@@ -18,5 +19,6 @@ void kernel_main(void) {
     mouse_install();
 
     terminal_write_string("Melvix loaded successfully!\n");
+    beep();
     // __asm__  ("div %0" :: "r"(0)); // Exception testing x/0
 }
\ No newline at end of file
diff --git a/src/sound/frequency.c b/src/sound/frequency.c
new file mode 100644
index 0000000..e5e831c
--- /dev/null
+++ b/src/sound/frequency.c
@@ -0,0 +1,32 @@
+#include <stdint.h>
+#include "../io/io.h"
+#include "../timer/timer.h"
+
+static void play_sound(uint32_t frequency) {
+    uint32_t divided;
+    uint8_t tmp;
+
+    divided = 1193180 / frequency;
+    send(0x43, 0xb6);
+    send(0x42, (uint8_t) (divided));
+    send(0x42, (uint8_t) (divided >> 8));
+
+    //And play the sound using the PC speaker
+    tmp = receive(0x61);
+    if (tmp != (tmp | 3)) {
+        send(0x61, tmp | 3);
+    }
+}
+
+static void shut_up() {
+    uint8_t tmp = receive(0x61) & 0xFC;
+
+    send(0x61, tmp);
+}
+
+//Make a beep
+void beep() {
+    play_sound(1000);
+    timer_wait(100);
+    shut_up();
+}
\ No newline at end of file
diff --git a/src/sound/sound.h b/src/sound/sound.h
new file mode 100644
index 0000000..f8692ea
--- /dev/null
+++ b/src/sound/sound.h
@@ -0,0 +1,6 @@
+#ifndef MELVIX_SOUND_H
+#define MELVIX_SOUND_H
+
+void beep();
+
+#endif
-- 
cgit v1.2.3