trying to fix the drivers and also the isr, gdt and isr header files.

This commit is contained in:
2023-07-15 14:25:31 -07:00
parent d98d2d4292
commit 3c103367d0
9 changed files with 166 additions and 30 deletions

View File

View File

View File

@@ -1,27 +1,63 @@
#include "screen.h"
#include <dos.h>
void screen_init() {
// Initialize the screen driver
// Add any necessary initialization code here
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// Video memory address
#define VIDEO_MEMORY_ADDRESS 0xB8000
// Screen attributes (color)
static uint8_t screen_color =
(SCREEN_COLOR_LIGHT_GRAY << 4) | SCREEN_COLOR_BLACK;
// Helper function to calculate the screen buffer offset
static inline uint16_t screen_offset(uint8_t x, uint8_t y)
{
return (y * SCREEN_WIDTH + x) * 2;
}
void set_40_column_mode() {
// Set the screen mode to 40 columns
union REGS regs;
regs.h.ah = 0x00;
regs.h.al = 0x03;
int86(0x10, &regs, &regs);
// Initialize the screen driver
void screen_init()
{
// No initialization required for this simple driver
}
void set_80_column_mode() {
// Set the screen mode to 80 columns
union REGS regs;
regs.h.ah = 0x00;
regs.h.al = 0x03;
int86(0x10, &regs, &regs);
// Clear the screen
void screen_clear()
{
uint16_t *video_memory = (uint16_t *)VIDEO_MEMORY_ADDRESS;
for (int i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++)
{
video_memory[i] = ' ' | (screen_color << 8);
}
}
regs.h.ah = 0x00;
regs.h.al = 0x07;
int86(0x10, &regs, &regs);
// Set the foreground and background colors
void screen_set_color(uint8_t foreground, uint8_t background)
{
screen_color = (background << 4) | foreground;
}
// Print a character at the specified position
void screen_put_char(char c, uint8_t x, uint8_t y)
{
uint16_t *video_memory = (uint16_t *)VIDEO_MEMORY_ADDRESS;
uint16_t offset = screen_offset(x, y);
video_memory[offset] = c | (screen_color << 8);
}
// Print a null-terminated string at the specified position
void screen_put_string(const char *str, uint8_t x, uint8_t y)
{
uint16_t *video_memory = (uint16_t *)VIDEO_MEMORY_ADDRESS;
uint16_t offset = screen_offset(x, y);
while (*str)
{
video_memory[offset] = *str | (screen_color << 8);
str++;
offset += 2;
}
}

View File

@@ -1,13 +1,47 @@
#ifndef SCREEN_H
#define SCREEN_H
// Function to initialize the screen driver
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// Screen dimensions
#define SCREEN_WIDTH 80
#define SCREEN_HEIGHT 25
// Screen colors
#define SCREEN_COLOR_BLACK 0
#define SCREEN_COLOR_BLUE 1
#define SCREEN_COLOR_GREEN 2
#define SCREEN_COLOR_CYAN 3
#define SCREEN_COLOR_RED 4
#define SCREEN_COLOR_MAGENTA 5
#define SCREEN_COLOR_BROWN 6
#define SCREEN_COLOR_LIGHT_GRAY 7
#define SCREEN_COLOR_DARK_GRAY 8
#define SCREEN_COLOR_LIGHT_BLUE 9
#define SCREEN_COLOR_LIGHT_GREEN 10
#define SCREEN_COLOR_LIGHT_CYAN 11
#define SCREEN_COLOR_LIGHT_RED 12
#define SCREEN_COLOR_LIGHT_MAGENTA 13
#define SCREEN_COLOR_YELLOW 14
#define SCREEN_COLOR_WHITE 15
// Initialize the screen driver
void screen_init();
// Function to set the screen mode to 40 columns
void set_40_column_mode();
// Clear the screen
void screen_clear();
// Function to set the screen mode to 80 columns
void set_80_column_mode();
// Set the foreground and background colors
void screen_set_color(uint8_t foreground, uint8_t background);
// Print a character at the specified position
void screen_put_char(char c, uint8_t x, uint8_t y);
// Print a null-terminated string at the specified position
void screen_put_string(const char *str, uint8_t x, uint8_t y);
#endif

36
src/drivers/tty/tty.c Normal file
View File

@@ -0,0 +1,36 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "../display.h"
#include "../interrupts.h"
#include "../io/io.h"
#include "../keyboard.h"
#include "../string.h"
#include "./screen/screen.h"
#include "./tty.h"
// Function definitions
// Example function to print a message to the console
void tty_print(const char *message)
{
printf("%s", message);
}
// Example function to read input from the console
void tty_read(char *buffer, size_t size)
{
fgets(buffer, size, stdin);
}
// Example function to clear the console
void tty_clear()
{
printf("\033[2J\033[H");
}
// More function definitions...

12
src/drivers/tty/tty.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef TTY_H
#define TTY_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
// Function declarations
#endif // TTY_H