move CPU timer to its own file, begin implementing PC Speaker Support
This commit is contained in:
parent
9cdd5d3c48
commit
a29a7b5c50
@ -14,10 +14,13 @@
|
|||||||
#define CMOS_ADDPORT 0x70
|
#define CMOS_ADDPORT 0x70
|
||||||
#define CMOS_DATAPORT 0x71
|
#define CMOS_DATAPORT 0x71
|
||||||
|
|
||||||
|
int CMOS_Timer;
|
||||||
|
|
||||||
void CMOS_RTC_Handler()
|
void CMOS_RTC_Handler()
|
||||||
{
|
{
|
||||||
outb(0x70, 0x0C); // select register C
|
outb(0x70, 0x0C); // select register C
|
||||||
inb(0x71); // just throw away contents
|
inb(0x71); // just throw away contents
|
||||||
|
CMOS_Timer++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Write_CMOS(uint8_t Register)
|
void Write_CMOS(uint8_t Register)
|
||||||
@ -81,8 +84,9 @@ int Slave_FDD_Detect()
|
|||||||
return FDDType;
|
return FDDType;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uptime;
|
void CMOS_Timer_Wait(int cycles)
|
||||||
void CPU_Timer()
|
|
||||||
{
|
{
|
||||||
uptime++;
|
int tmp;
|
||||||
|
tmp = CMOS_Timer;
|
||||||
|
while(CMOS_Timer - tmp <= cycles) return;
|
||||||
}
|
}
|
||||||
@ -8,9 +8,9 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
void CMOS_RTC_Handler();
|
void CMOS_RTC_Handler();
|
||||||
void CPU_Timer();
|
|
||||||
int Master_FDD_Detect();
|
int Master_FDD_Detect();
|
||||||
int Slave_FDD_Detect();
|
int Slave_FDD_Detect();
|
||||||
|
void CMOS_Timer_Wait(int cycles);
|
||||||
uint8_t Read_CMOS(uint8_t Register);
|
uint8_t Read_CMOS(uint8_t Register);
|
||||||
|
|
||||||
enum CMOSRegisters
|
enum CMOSRegisters
|
||||||
|
|||||||
50
src/kernel/dri/sound/pcspeaker.c
Normal file
50
src/kernel/dri/sound/pcspeaker.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2025|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#include "pcspeaker.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <util/binary.h>
|
||||||
|
|
||||||
|
#include <arch/i686/io.h>
|
||||||
|
|
||||||
|
#include <dri/timer.h>
|
||||||
|
#include <dri/cmos.h>
|
||||||
|
#include <dri/serial.h>
|
||||||
|
|
||||||
|
extern uint16_t DEBUG_COM_PORT;
|
||||||
|
|
||||||
|
void PCSP_Play(uint32_t nFrequence)
|
||||||
|
{
|
||||||
|
uint32_t Div;
|
||||||
|
uint8_t tmp;
|
||||||
|
|
||||||
|
Div = 1193180 / nFrequence;
|
||||||
|
outb(0x43, 0xb6);
|
||||||
|
outb(0x42, (uint8_t) (Div) );
|
||||||
|
outb(0x42, (uint8_t) (Div >> 8));
|
||||||
|
|
||||||
|
tmp = inb(0x61);
|
||||||
|
if (tmp != (tmp | 3)) {
|
||||||
|
outb(0x61, tmp | 3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// make it shut up
|
||||||
|
void PCSP_Mute()
|
||||||
|
{
|
||||||
|
uint8_t tmp = inb(0x61) & 0xFC;
|
||||||
|
|
||||||
|
outb(0x61, tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make a beep
|
||||||
|
void PCSP_Beep()
|
||||||
|
{
|
||||||
|
PCSP_Play(1000);
|
||||||
|
Timer_Wait(100000000);
|
||||||
|
PCSP_Mute();
|
||||||
|
}
|
||||||
12
src/kernel/dri/sound/pcspeaker.h
Normal file
12
src/kernel/dri/sound/pcspeaker.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2025|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void PCSP_Play(uint32_t nFrequence);
|
||||||
|
void PCSP_Mute();
|
||||||
|
void PCSP_Beep();
|
||||||
19
src/kernel/dri/timer.c
Normal file
19
src/kernel/dri/timer.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2025|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
|
int uptime;
|
||||||
|
void Timer_Handler()
|
||||||
|
{
|
||||||
|
uptime++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Timer_Wait(int cycles) // Seems to not work? i'll fix it later.
|
||||||
|
{
|
||||||
|
int tmp;
|
||||||
|
tmp = uptime;
|
||||||
|
while(uptime - tmp <= cycles) return;
|
||||||
|
}
|
||||||
9
src/kernel/dri/timer.h
Normal file
9
src/kernel/dri/timer.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2025|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
void Timer_Handler();
|
||||||
|
void Timer_Wait(int cycles);
|
||||||
@ -13,22 +13,30 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <memory.h>
|
#include <memory.h>
|
||||||
|
|
||||||
#include <dri/keyboard.h>
|
#include <dri/keyboard.h>
|
||||||
#include <dri/cmos.h>
|
#include <dri/cmos.h>
|
||||||
|
#include <dri/timer.h>
|
||||||
#include <dri/serial.h>
|
#include <dri/serial.h>
|
||||||
#include <dri/fat.h>
|
#include <dri/fat.h>
|
||||||
#include <dri/disk/floppy.h>
|
#include <dri/disk/floppy.h>
|
||||||
#include <dri/disk/ata.h>
|
#include <dri/disk/ata.h>
|
||||||
|
#include <dri/sound/pcspeaker.h>
|
||||||
|
|
||||||
#include <core/hal/hal.h>
|
#include <core/hal/hal.h>
|
||||||
#include <core/memory/page.h>
|
#include <core/memory/page.h>
|
||||||
|
|
||||||
#include <util/param.h>
|
#include <util/param.h>
|
||||||
#include <util/util.h>
|
#include <util/util.h>
|
||||||
#include <util/binary.h>
|
#include <util/binary.h>
|
||||||
|
|
||||||
#include <version.h>
|
#include <version.h>
|
||||||
|
|
||||||
extern uint8_t __bss_start;
|
extern uint8_t __bss_start;
|
||||||
extern uint8_t __end;
|
extern uint8_t __end;
|
||||||
|
|
||||||
|
extern int uptime;
|
||||||
|
|
||||||
uint16_t DEBUG_COM_PORT = COM1_PORT;
|
uint16_t DEBUG_COM_PORT = COM1_PORT;
|
||||||
|
|
||||||
void __attribute__((section(".entry"))) start(uint64_t multiboot_magic, void *multiboot_data) {
|
void __attribute__((section(".entry"))) start(uint64_t multiboot_magic, void *multiboot_data) {
|
||||||
@ -50,7 +58,7 @@ void __attribute__((section(".entry"))) start(uint64_t multiboot_magic, void *mu
|
|||||||
|
|
||||||
// Register IRQs
|
// Register IRQs
|
||||||
printf("Registering IRQs...");
|
printf("Registering IRQs...");
|
||||||
IRQ_RegisterHandler(0, CPU_Timer);
|
IRQ_RegisterHandler(0, Timer_Handler);
|
||||||
IRQ_RegisterHandler(1, Keyboard_Handler);
|
IRQ_RegisterHandler(1, Keyboard_Handler);
|
||||||
IRQ_RegisterHandler(4, COM1_Serial_Handler);
|
IRQ_RegisterHandler(4, COM1_Serial_Handler);
|
||||||
IRQ_RegisterHandler(6, Floppy_Handler);
|
IRQ_RegisterHandler(6, Floppy_Handler);
|
||||||
@ -76,6 +84,8 @@ void __attribute__((section(".entry"))) start(uint64_t multiboot_magic, void *mu
|
|||||||
BCD2BIN(Read_CMOS(CMOS_RTC_Day)),
|
BCD2BIN(Read_CMOS(CMOS_RTC_Day)),
|
||||||
BCD2BIN(Read_CMOS(CMOS_RTC_Century)),
|
BCD2BIN(Read_CMOS(CMOS_RTC_Century)),
|
||||||
BCD2BIN(Read_CMOS(CMOS_RTC_Year)));
|
BCD2BIN(Read_CMOS(CMOS_RTC_Year)));
|
||||||
|
// Beep!
|
||||||
|
PCSP_Beep();
|
||||||
|
|
||||||
end:
|
end:
|
||||||
for (;;);
|
for (;;);
|
||||||
|
|||||||
@ -6,4 +6,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n"
|
#define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n"
|
||||||
#define VERSION "RD-00046"
|
#define VERSION "RD-00047"
|
||||||
Loading…
x
Reference in New Issue
Block a user