Add: cool splash screen
This commit is contained in:
64
src/drivers/rtc.c
Normal file
64
src/drivers/rtc.c
Normal file
@@ -0,0 +1,64 @@
|
||||
// Real-time clock driver implementation for better PRNG
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https://github.com/xamidev/blankos
|
||||
|
||||
#include <stdint.h>
|
||||
#include "rtc.h"
|
||||
#include "../kernel/io.h"
|
||||
#include "../libc/stdio.h"
|
||||
|
||||
uint8_t rtc_read_register(uint8_t reg)
|
||||
{
|
||||
outb(0x70, reg);
|
||||
return inb(0x71);
|
||||
}
|
||||
|
||||
uint8_t bcd_to_bin(uint8_t bcd)
|
||||
{
|
||||
return ((bcd/16)*10) + (bcd%16);
|
||||
}
|
||||
|
||||
int rtc_is_updating()
|
||||
{
|
||||
outb(0x70, 0x0A);
|
||||
return (inb(0x71) & 0x80);
|
||||
}
|
||||
|
||||
void rtc_read_time(rtc_time_t *time)
|
||||
{
|
||||
while (rtc_is_updating());
|
||||
|
||||
time->seconds = rtc_read_register(0x00);
|
||||
time->minutes = rtc_read_register(0x02);
|
||||
time->hours = rtc_read_register(0x04);
|
||||
time->day = rtc_read_register(0x06);
|
||||
time->month = rtc_read_register(0x07);
|
||||
time->year = rtc_read_register(0x08);
|
||||
|
||||
outb(0x70, 0x0B);
|
||||
uint8_t registerB = inb(0x71);
|
||||
|
||||
if (!(registerB & 0x04))
|
||||
{
|
||||
time->seconds = bcd_to_bin(time->seconds);
|
||||
time->minutes = bcd_to_bin(time->minutes);
|
||||
time->hours = bcd_to_bin(time->hours);
|
||||
time->day = bcd_to_bin(time->day);
|
||||
time->month = bcd_to_bin(time->month);
|
||||
time->year = bcd_to_bin(time->year);
|
||||
}
|
||||
}
|
||||
|
||||
void print_time(const rtc_time_t *time)
|
||||
{
|
||||
printf("%02d/%02d/%02d %02d:%02d:%02d\n", time->day, time->month, time->year, time->hours, time->minutes, time->seconds);
|
||||
}
|
||||
|
||||
long time_seed()
|
||||
{
|
||||
rtc_time_t* time = {0};
|
||||
rtc_read_time(time);
|
||||
|
||||
return time->day + time->month + time->year + time->hours + time->minutes + time->seconds;
|
||||
}
|
||||
23
src/drivers/rtc.h
Normal file
23
src/drivers/rtc.h
Normal file
@@ -0,0 +1,23 @@
|
||||
// Real-time clock driver implementation header for better PRNG
|
||||
// Author: xamidev
|
||||
// Licensed under the Unlicense. See the repo below.
|
||||
// https://github.com/xamidev/blankos
|
||||
|
||||
#ifndef RTC_H
|
||||
#define RTC_H
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t seconds;
|
||||
uint8_t minutes;
|
||||
uint8_t hours;
|
||||
uint8_t day;
|
||||
uint8_t month;
|
||||
uint8_t year;
|
||||
} rtc_time_t;
|
||||
|
||||
void rtc_read_time(rtc_time_t *time);
|
||||
long time_seed();
|
||||
void print_time(const rtc_time_t *time);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user