Permalink
Browse files

Files for part 8, https://www.youtube.com/watch?v=SQBBetLJA9w

  • Loading branch information...
Viktor Engelmann Viktor Engelmann
Viktor Engelmann authored and Viktor Engelmann committed Jul 4, 2016
1 parent 48959b0 commit 890d69a20af36531d8521b65f3c4968fbddfb687
Showing with 332 additions and 102 deletions.
  1. +44 −0 driver.cpp
  2. +33 −0 driver.h
  3. +3 −5 interrupts.cpp
  4. +89 −3 kernel.cpp
  5. +82 −57 keyboard.cpp
  6. +15 −2 keyboard.h
  7. +1 −1 makefile
  8. +47 −31 mouse.cpp
  9. +18 −3 mouse.h
View
@@ -0,0 +1,44 @@
#include "driver.h"
Driver::Driver()
{
}
Driver::~Driver()
{
}
void Driver::Activate()
{
}
int Driver::Reset()
{
return 0;
}
void Driver::Deactivate()
{
}
DriverManager::DriverManager()
{
numDrivers = 0;
}
void DriverManager::AddDriver(Driver* drv)
{
drivers[numDrivers] = drv;
numDrivers++;
}
void DriverManager::ActivateAll()
{
for(int i = 0; i < numDrivers; i++)
drivers[i]->Activate();
}
View
@@ -0,0 +1,33 @@
#ifndef __DRIVER_H
#define __DRIVER_H
class Driver
{
public:
Driver();
~Driver();
virtual void Activate();
virtual int Reset();
virtual void Deactivate();
};
class DriverManager
{
private:
Driver* drivers[265];
int numDrivers;
public:
DriverManager();
void AddDriver(Driver*);
void ActivateAll();
};
#endif
View
@@ -3,6 +3,7 @@
void printf(char* str);
void printfHex(uint8_t);
@@ -178,11 +179,8 @@ uint32_t InterruptManager::DoHandleInterrupt(uint8_t interrupt, uint32_t esp)
}
else if(interrupt != hardwareInterruptOffset)
{
char* foo = "UNHANDLED INTERRUPT 0x00";
char* hex = "0123456789ABCDEF";
foo[22] = hex[(interrupt >> 4) & 0xF];
foo[23] = hex[interrupt & 0xF];
printf(foo);
printf("UNHANDLED INTERRUPT 0x");
printfHex(interrupt);
}
// hardware interrupts must be acknowledged
View
@@ -2,6 +2,7 @@
#include "types.h"
#include "gdt.h"
#include "interrupts.h"
#include "driver.h"
#include "keyboard.h"
#include "mouse.h"
@@ -42,6 +43,75 @@ void printf(char* str)
}
}
void printfHex(uint8_t key)
{
char* foo = "00";
char* hex = "0123456789ABCDEF";
foo[0] = hex[(key >> 4) & 0xF];
foo[1] = hex[key & 0xF];
printf(foo);
}
class PrintfKeyboardEventHandler : public KeyboardEventHandler
{
public:
void OnKeyDown(char c)
{
char* foo = " ";
foo[0] = c;
printf(foo);
}
};
class MouseToConsole : public MouseEventHandler
{
int8_t x, y;
public:
MouseToConsole()
{
}
virtual void OnActivate()
{
uint16_t* VideoMemory = (uint16_t*)0xb8000;
x = 40;
y = 12;
VideoMemory[80*y+x] = (VideoMemory[80*y+x] & 0x0F00) << 4
| (VideoMemory[80*y+x] & 0xF000) >> 4
| (VideoMemory[80*y+x] & 0x00FF);
}
virtual void OnMouseMove(int xoffset, int yoffset)
{
static uint16_t* VideoMemory = (uint16_t*)0xb8000;
VideoMemory[80*y+x] = (VideoMemory[80*y+x] & 0x0F00) << 4
| (VideoMemory[80*y+x] & 0xF000) >> 4
| (VideoMemory[80*y+x] & 0x00FF);
x += xoffset;
if(x >= 80) x = 79;
if(x < 0) x = 0;
y += yoffset;
if(y >= 25) y = 24;
if(y < 0) y = 0;
VideoMemory[80*y+x] = (VideoMemory[80*y+x] & 0x0F00) << 4
| (VideoMemory[80*y+x] & 0xF000) >> 4
| (VideoMemory[80*y+x] & 0x00FF);
}
};
typedef void (*constructor)();
@@ -57,12 +127,28 @@ extern "C" void callConstructors()
extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot_magic*/)
{
printf("Hello World! --- http://www.AlgorithMan.de");
printf("Hello World! --- http://www.AlgorithMan.de\n");
GlobalDescriptorTable gdt;
InterruptManager interrupts(0x20, &gdt);
KeyboardDriver keyboard(&interrupts);
MouseDriver mouse(&interrupts);
printf("Initializing Hardware, Stage 1\n");
DriverManager drvManager;
PrintfKeyboardEventHandler kbhandler;
KeyboardDriver keyboard(&interrupts, &kbhandler);
drvManager.AddDriver(&keyboard);
MouseToConsole mousehandler;
MouseDriver mouse(&interrupts, &mousehandler);
drvManager.AddDriver(&mouse);
printf("Initializing Hardware, Stage 2\n");
drvManager.ActivateAll();
printf("Initializing Hardware, Stage 3\n");
interrupts.Activate();
while(1);
View
@@ -1,10 +1,40 @@
#include "keyboard.h"
KeyboardDriver::KeyboardDriver(InterruptManager* manager)
KeyboardEventHandler::KeyboardEventHandler()
{
}
void KeyboardEventHandler::OnKeyDown(char)
{
}
void KeyboardEventHandler::OnKeyUp(char)
{
}
KeyboardDriver::KeyboardDriver(InterruptManager* manager, KeyboardEventHandler *handler)
: InterruptHandler(manager, 0x21),
dataport(0x60),
commandport(0x64)
{
this->handler = handler;
}
KeyboardDriver::~KeyboardDriver()
{
}
void printf(char*);
void printfHex(uint8_t);
void KeyboardDriver::Activate()
{
while(commandport.Read() & 0x1)
dataport.Read();
@@ -16,72 +46,67 @@ commandport(0x64)
dataport.Write(0xf4);
}
KeyboardDriver::~KeyboardDriver()
{
}
void printf(char*);
uint32_t KeyboardDriver::HandleInterrupt(uint32_t esp)
{
uint8_t key = dataport.Read();
if(handler == 0)
return esp;
if(key < 0x80)
{
switch(key)
{
case 0x02: printf("1"); break;
case 0x03: printf("2"); break;
case 0x04: printf("3"); break;
case 0x05: printf("4"); break;
case 0x06: printf("5"); break;
case 0x07: printf("6"); break;
case 0x08: printf("7"); break;
case 0x09: printf("8"); break;
case 0x0A: printf("9"); break;
case 0x0B: printf("0"); break;
case 0x10: printf("q"); break;
case 0x11: printf("w"); break;
case 0x12: printf("e"); break;
case 0x13: printf("r"); break;
case 0x14: printf("t"); break;
case 0x15: printf("z"); break;
case 0x16: printf("u"); break;
case 0x17: printf("i"); break;
case 0x18: printf("o"); break;
case 0x19: printf("p"); break;
case 0x1E: printf("a"); break;
case 0x1F: printf("s"); break;
case 0x20: printf("d"); break;
case 0x21: printf("f"); break;
case 0x22: printf("g"); break;
case 0x23: printf("h"); break;
case 0x24: printf("j"); break;
case 0x25: printf("k"); break;
case 0x26: printf("l"); break;
case 0x2C: printf("y"); break;
case 0x2D: printf("x"); break;
case 0x2E: printf("c"); break;
case 0x2F: printf("v"); break;
case 0x30: printf("b"); break;
case 0x31: printf("n"); break;
case 0x32: printf("m"); break;
case 0x33: printf(","); break;
case 0x34: printf("."); break;
case 0x35: printf("-"); break;
case 0x1C: printf("\n"); break;
case 0x39: printf(" "); break;
case 0x02: handler->OnKeyDown('1'); break;
case 0x03: handler->OnKeyDown('2'); break;
case 0x04: handler->OnKeyDown('3'); break;
case 0x05: handler->OnKeyDown('4'); break;
case 0x06: handler->OnKeyDown('5'); break;
case 0x07: handler->OnKeyDown('6'); break;
case 0x08: handler->OnKeyDown('7'); break;
case 0x09: handler->OnKeyDown('8'); break;
case 0x0A: handler->OnKeyDown('9'); break;
case 0x0B: handler->OnKeyDown('0'); break;
case 0x10: handler->OnKeyDown('q'); break;
case 0x11: handler->OnKeyDown('w'); break;
case 0x12: handler->OnKeyDown('e'); break;
case 0x13: handler->OnKeyDown('r'); break;
case 0x14: handler->OnKeyDown('t'); break;
case 0x15: handler->OnKeyDown('z'); break;
case 0x16: handler->OnKeyDown('u'); break;
case 0x17: handler->OnKeyDown('i'); break;
case 0x18: handler->OnKeyDown('o'); break;
case 0x19: handler->OnKeyDown('p'); break;
case 0x1E: handler->OnKeyDown('a'); break;
case 0x1F: handler->OnKeyDown('s'); break;
case 0x20: handler->OnKeyDown('d'); break;
case 0x21: handler->OnKeyDown('f'); break;
case 0x22: handler->OnKeyDown('g'); break;
case 0x23: handler->OnKeyDown('h'); break;
case 0x24: handler->OnKeyDown('j'); break;
case 0x25: handler->OnKeyDown('k'); break;
case 0x26: handler->OnKeyDown('l'); break;
case 0x2C: handler->OnKeyDown('y'); break;
case 0x2D: handler->OnKeyDown('x'); break;
case 0x2E: handler->OnKeyDown('c'); break;
case 0x2F: handler->OnKeyDown('v'); break;
case 0x30: handler->OnKeyDown('b'); break;
case 0x31: handler->OnKeyDown('n'); break;
case 0x32: handler->OnKeyDown('m'); break;
case 0x33: handler->OnKeyDown(','); break;
case 0x34: handler->OnKeyDown('.'); break;
case 0x35: handler->OnKeyDown('-'); break;
case 0x1C: handler->OnKeyDown('\n'); break;
case 0x39: handler->OnKeyDown(' '); break;
default:
{
char* foo = "KEYBOARD 0x00 ";
char* hex = "0123456789ABCDEF";
foo[11] = hex[(key >> 4) & 0xF];
foo[12] = hex[key & 0xF];
printf(foo);
printf("KEYBOARD 0x");
printfHex(key);
break;
}
}
Oops, something went wrong.

0 comments on commit 890d69a

Please sign in to comment.