Clean: harmonizing & header-commenting code

This commit is contained in:
xamidev
2024-08-24 17:17:53 +02:00
parent a915ac15a1
commit fbd4fa6089
46 changed files with 339 additions and 130 deletions

View File

@@ -1,27 +1,12 @@
// ATA PIO driver implementation
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https//github.com/xamidev/blankos
#include <stdint.h>
#include "../kernel/io.h"
#include "../libc/stdio.h"
#define ATA_PRIMARY_IO 0x1F0
#define ATA_PRIMARY_CTRL 0x3F6
#define ATA_CMD_READ_PIO 0x20
#define ATA_CMD_WRITE_PIO 0x30
#define ATA_IDENTIFY 0xEC
#define ATA_REG_DATA 0x00
#define ATA_REG_ERROR 0x01
#define ATA_REG_SECCOUNT0 0x02
#define ATA_REG_LBA0 0x03
#define ATA_REG_LBA1 0x04
#define ATA_REG_LBA2 0x05
#define ATA_REG_HDDEVSEL 0x06
#define ATA_REG_COMMAND 0x07
#define ATA_REG_STATUS 0x07
#define ATA_SR_BSY 0x80
#define ATA_SR_DRDY 0x40
#define ATA_SR_DRQ 0x08
#define ATA_SR_ERR 0x01
#include "ata.h"
static inline uint16_t inw(uint16_t port) {
uint16_t result;

View File

@@ -1,8 +1,34 @@
// ATA PIO driver implementation header
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https//github.com/xamidev/blankos
#ifndef ATA_H
#define ATA_H
#include <stdint.h>
#define ATA_PRIMARY_IO 0x1F0
#define ATA_PRIMARY_CTRL 0x3F6
#define ATA_CMD_READ_PIO 0x20
#define ATA_CMD_WRITE_PIO 0x30
#define ATA_IDENTIFY 0xEC
#define ATA_REG_DATA 0x00
#define ATA_REG_ERROR 0x01
#define ATA_REG_SECCOUNT0 0x02
#define ATA_REG_LBA0 0x03
#define ATA_REG_LBA1 0x04
#define ATA_REG_LBA2 0x05
#define ATA_REG_HDDEVSEL 0x06
#define ATA_REG_COMMAND 0x07
#define ATA_REG_STATUS 0x07
#define ATA_SR_BSY 0x80
#define ATA_SR_DRDY 0x40
#define ATA_SR_DRQ 0x08
#define ATA_SR_ERR 0x01
void ata_read_sector(uint32_t lba, uint8_t* buffer);
void test_read_sector();

View File

@@ -1,11 +1,16 @@
// Framebuffer driver
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https//github.com/xamidev/blankos
#include <stdint.h>
#include "framebuffer.h"
#include "serial.h"
#include "../kernel/system.h"
//extern uint32_t *g_framebuffer;
extern char* framebuffer;
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color) // framebuffer pointer, x, y, color
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color)
{
if (bpp == 32) {
uint32_t* pixel_addr = (uint32_t*)((uint8_t*)fb + y * pitch + x *(bpp / 8));
@@ -13,14 +18,6 @@ void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color) //
}
}
extern char* framebuffer;
extern int scanline;
extern char _binary_include_fonts_UniCyr_8x16_psf_start;
uint16_t* unicode;
#define PIXEL uint32_t
// Character, cursor X, cursor Y, foreground, background
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg)
{
PSF_font *font = (PSF_font*)&_binary_include_fonts_UniCyr_8x16_psf_start;

View File

@@ -1,8 +1,19 @@
// Framebuffer driver header
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https//github.com/xamidev/blankos
#ifndef FRAMEBUFFER_H
#define FRAMEBUFFER_H
#include <stdint.h>
extern int scanline;
extern char _binary_include_fonts_UniCyr_8x16_psf_start;
uint16_t* unicode;
#define PIXEL uint32_t
#define PSF1_FONT_MAGIC 0x0436
typedef struct {
@@ -24,7 +35,6 @@ typedef struct {
uint32_t width; /* width in pixels */
} PSF_font;
//extern const unsigned char font[512][64];
void putpixel(uint32_t* fb, int pitch, int bpp, int x, int y, uint32_t color);
void draw_char(unsigned short int c, int cx, int cy, uint32_t fg, uint32_t bg);
void scroll();

View File

@@ -1,13 +1,12 @@
// Keyboard driver
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https//github.com/xamidev/blankos
#include "../kernel/io.h"
#include "../libc/stdio.h"
#include "../kernel/system.h"
#define KEYBOARD_BUFFER_SIZE 256
#define LEFT_SHIFT_PRESSED 0x2A
#define RIGHT_SHIFT_PRESSED 0x36
#define LEFT_SHIFT_RELEASED 0xAA
#define RIGHT_SHIFT_RELEASED 0xB6
#include "kb.h"
unsigned char kbdus[128] =
{

View File

@@ -1,6 +1,18 @@
// Keyboard driver header
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https//github.com/xamidev/blankos
#ifndef KB_H
#define KB_H
#define KEYBOARD_BUFFER_SIZE 256
#define LEFT_SHIFT_PRESSED 0x2A
#define RIGHT_SHIFT_PRESSED 0x36
#define LEFT_SHIFT_RELEASED 0xAA
#define RIGHT_SHIFT_RELEASED 0xB6
char keyboard_getchar();
#endif

View File

@@ -1,3 +1,8 @@
// Serial I/O driver
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https//github.com/xamidev/blankos
#include "../kernel/io.h"
#include "serial.h"
#include "../libc/stdio.h"
@@ -279,4 +284,3 @@ void serial_printf(int errlevel, const char* fmt, ...)
}
serial_puts("\n");
}

View File

@@ -1,5 +1,10 @@
#ifndef INCLUDE_SERIAL_H
#define INCLUDE_SERIAL_H
// Serial I/O driver header
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https//github.com/xamidev/blankos
#ifndef SERIAL_H
#define SERIAL_H
#define PORT 0x3f8 //COM1
@@ -9,4 +14,5 @@ void write_serial(const char a);
void serial_puts(const char* str);
void log(const char* str, const int errlevel);
void serial_printf(int errlevel, const char* fmt, ...);
#endif

View File

@@ -1,3 +1,8 @@
// Programmable Interval Timer channel 0 driver
// Author: xamidev
// Licensed under the Unlicense. See the repo below.
// https//github.com/xamidev/blankos
#include "../kernel/system.h"
#include "../libc/stdio.h"