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
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "../programs/programs.h"
|
||||
#include "../libc/crypto.h"
|
||||
#include <stdint.h>
|
||||
#include "../drivers/rtc.h"
|
||||
|
||||
#define BUFFER_SIZE 256
|
||||
#define MAX_COMMANDS 16
|
||||
@@ -19,7 +20,7 @@
|
||||
char* ascii_title =
|
||||
"\n"
|
||||
"----------------------------------------------\n"
|
||||
"Blank OS version 0.3.71-dev\n"
|
||||
"Blank OS version 0.3.84-alpha\n"
|
||||
"Author: @xamidev - star the repo for a cookie!\n"
|
||||
"----------------------------------------------\n"
|
||||
"\n";
|
||||
@@ -28,15 +29,23 @@ char* motd[] =
|
||||
{
|
||||
"Now in 2D!",
|
||||
"Supercalifragilisticexpialidocious!",
|
||||
"Tylko jedno w głowie mam!",
|
||||
"Tylko jedno w glowie mam!",
|
||||
};
|
||||
int motd_size = sizeof(motd)/sizeof(motd[0]);
|
||||
|
||||
void splash()
|
||||
{ // Change that seed to something RTC-related (need RTC driver)
|
||||
int random = randint(global_ticks);
|
||||
{
|
||||
int random = randint(time_seed());
|
||||
char* motd_pick = motd[random%motd_size];
|
||||
cowsay(motd_pick, red, black);
|
||||
colorputs(" blankOS 0.3.84-alpha", red, black);
|
||||
puts("\n");
|
||||
|
||||
|
||||
puts(" Time: ");
|
||||
rtc_time_t time;
|
||||
rtc_read_time(&time);
|
||||
print_time(&time);
|
||||
puts("\n");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user