Work for part 4
This commit is contained in:
parent
dac25ae564
commit
5a946c1569
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@ -56,5 +56,9 @@
|
|||||||
"C_Cpp_Runner.showCompilationTime": false,
|
"C_Cpp_Runner.showCompilationTime": false,
|
||||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||||
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
"C_Cpp_Runner.msvcSecureNoWarnings": false,
|
||||||
"makefile.configureOnOpen": false
|
"makefile.configureOnOpen": false,
|
||||||
|
"files.associations": {
|
||||||
|
"portmap.h": "c",
|
||||||
|
"cstddef": "c"
|
||||||
|
}
|
||||||
}
|
}
|
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
|||||||
C_FILES=./kernel.c ./console/console.c
|
C_FILES=./kernel.c ./console/console.c ./device/keyboard/keyboard.c ./device/portmap/portmap.c
|
||||||
O_FILES=$(C_FILES:.c=.o)
|
O_FILES=$(C_FILES:.c=.o)
|
||||||
|
|
||||||
all: qemu_launch
|
all: qemu_launch
|
||||||
|
2
boot.asm
2
boot.asm
@ -78,7 +78,7 @@ begin_32bit:
|
|||||||
jmp KERNEL_ADDRESS
|
jmp KERNEL_ADDRESS
|
||||||
|
|
||||||
|
|
||||||
NUM_SECTORS db 0x09
|
NUM_SECTORS db 0x1F
|
||||||
DISK_SUCCESS_MESSAGE db "Read succeeded, continuing", 0
|
DISK_SUCCESS_MESSAGE db "Read succeeded, continuing", 0
|
||||||
DISK_READ_ERROR_MESSAGE db "Problem with disk read", 0
|
DISK_READ_ERROR_MESSAGE db "Problem with disk read", 0
|
||||||
DISK_SECTOR_ERROR_MESSAGE db "Read and requested sectors differ", 0
|
DISK_SECTOR_ERROR_MESSAGE db "Read and requested sectors differ", 0
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#include "../include/console.h"
|
#include "console.h"
|
||||||
|
#include "portmap.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
const int VGA_WIDTH = 80;
|
const int VGA_WIDTH = 80;
|
||||||
const int VGA_HEIGHT = 25;
|
const int VGA_HEIGHT = 25;
|
||||||
@ -41,13 +43,19 @@ void print_character(char c) {
|
|||||||
|
|
||||||
void print_character_with_color(char c, VGA_Color bg, VGA_Color fg) {
|
void print_character_with_color(char c, VGA_Color bg, VGA_Color fg) {
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
terminal_position = (terminal_position + (VGA_BYTES_PER_CHARACTER * VGA_WIDTH)) - (terminal_position % (VGA_BYTES_PER_CHARACTER * VGA_WIDTH));
|
terminal_position = (terminal_position + ((VGA_BYTES_PER_CHARACTER / 2 * VGA_WIDTH)) - (terminal_position % (VGA_BYTES_PER_CHARACTER / 2 * VGA_WIDTH)));
|
||||||
|
} else if (c == '\b') {
|
||||||
|
terminal_position -= 1;
|
||||||
|
VGA_BUFFER[(terminal_position * VGA_BYTES_PER_CHARACTER)] = ' ';
|
||||||
|
int full_color = (bg << 4) | fg;
|
||||||
|
VGA_BUFFER[(terminal_position * VGA_BYTES_PER_CHARACTER) + 1] = full_color;
|
||||||
} else {
|
} else {
|
||||||
VGA_BUFFER[(terminal_position * VGA_BYTES_PER_CHARACTER)] = c;
|
VGA_BUFFER[(terminal_position * VGA_BYTES_PER_CHARACTER)] = c;
|
||||||
int full_color = (bg << 4) | fg;
|
int full_color = (bg << 4) | fg;
|
||||||
VGA_BUFFER[(terminal_position * VGA_BYTES_PER_CHARACTER) + 1] = full_color;
|
VGA_BUFFER[(terminal_position * VGA_BYTES_PER_CHARACTER) + 1] = full_color;
|
||||||
terminal_position++;
|
terminal_position++;
|
||||||
}
|
}
|
||||||
|
update_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_string(char* string) {
|
void print_string(char* string) {
|
||||||
@ -70,3 +78,22 @@ void print_line(char* string) {
|
|||||||
print_character('\n');
|
print_character('\n');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_line_with_color(char* string, VGA_Color bg, VGA_Color fg) {
|
||||||
|
print_string_with_color(string, bg, fg);
|
||||||
|
print_character('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_cursor() {
|
||||||
|
|
||||||
|
uint16_t cursor_position = terminal_position >> 0;
|
||||||
|
|
||||||
|
outb(0x3D4, 0x0F);
|
||||||
|
|
||||||
|
outb(0x3D5, (uint8_t) (cursor_position));
|
||||||
|
|
||||||
|
outb(0x3D4, 0x0E);
|
||||||
|
|
||||||
|
outb(0x3D5, (uint8_t) (cursor_position >> 8));
|
||||||
|
|
||||||
|
}
|
30
device/keyboard/keyboard.c
Normal file
30
device/keyboard/keyboard.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "portmap.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint8_t scan(void) {
|
||||||
|
|
||||||
|
uint8_t brk;
|
||||||
|
|
||||||
|
static uint8_t key = 0;
|
||||||
|
|
||||||
|
uint8_t scan = inb(0x60);
|
||||||
|
|
||||||
|
brk = scan & 0x80;
|
||||||
|
|
||||||
|
scan = scan & 0x7f;
|
||||||
|
|
||||||
|
if (brk) {
|
||||||
|
|
||||||
|
return key = 0;
|
||||||
|
|
||||||
|
} else if (scan != key) {
|
||||||
|
|
||||||
|
return key = scan;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
device/portmap/portmap.c
Normal file
17
device/portmap/portmap.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint8_t inb(uint16_t port) {
|
||||||
|
|
||||||
|
uint8_t ret;
|
||||||
|
|
||||||
|
__asm__ __volatile__("inb %1, %0":"=a"(ret):"Nd"(port));
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void outb(uint16_t port, uint8_t val) {
|
||||||
|
|
||||||
|
__asm__ __volatile__("outb %0, %1": : "a" (val), "Nd" (port));
|
||||||
|
|
||||||
|
}
|
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
void print_line(char* str);
|
void print_line(char* str);
|
||||||
|
|
||||||
|
void update_cursor();
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
||||||
BLACK=0,
|
BLACK=0,
|
||||||
|
23
include/keyboard.h
Normal file
23
include/keyboard.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef MYOS_INCLUDE_KEYBOARD_H
|
||||||
|
|
||||||
|
#define MYOS_INCLUDE_KEYBOARD_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
static const char charmap[256] =
|
||||||
|
{0, 0x1B, '1', '2', '3', '4', '5', '6',
|
||||||
|
'7', '8', '9', '0', '-', '=', '\b', '\t',
|
||||||
|
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
|
||||||
|
'o', 'p', '[', ']', '\n', 0, 'a', 's',
|
||||||
|
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
|
||||||
|
'\'', '`', 0, '\\', 'z', 'x', 'c', 'v',
|
||||||
|
'b', 'n', 'm', ',', '.', '/', 0, '*',
|
||||||
|
0, ' ', 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, '7',
|
||||||
|
'8', '9', '-', '4', '5', '6', '+', '1',
|
||||||
|
'2', '3', '0', '.', 0, 0, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t scan(void);
|
||||||
|
|
||||||
|
#endif
|
11
include/portmap.h
Normal file
11
include/portmap.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef MYOS_INCLUDE_PORTMAP_H
|
||||||
|
|
||||||
|
#define MYOS_INCLUDE_PORTMAP_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
uint8_t inb(uint16_t port);
|
||||||
|
|
||||||
|
void outb(uint16_t port, uint8_t val);
|
||||||
|
|
||||||
|
#endif
|
14
kernel.c
14
kernel.c
@ -1,11 +1,19 @@
|
|||||||
#include "console.h"
|
#include "console.h"
|
||||||
|
#include "keyboard.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
clear_terminal();
|
clear_terminal();
|
||||||
print_string("HELLO");
|
update_cursor();
|
||||||
print_line("WORLD");
|
print_line_with_color("Welcome to myOS!", RED, WHITE);
|
||||||
print_string("TODAY");
|
uint8_t byte;
|
||||||
|
while(1) {
|
||||||
|
while (byte = scan()) {
|
||||||
|
print_character(charmap[byte]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user