Permalink
Browse files

Files for part 7, https://www.youtube.com/watch?v=PgA05QaIu6Y

  • Loading branch information...
Viktor Engelmann Viktor Engelmann
Viktor Engelmann authored and Viktor Engelmann committed Jul 4, 2016
1 parent a2f1cad commit 48959b002f33a1e1428cd190da8c268929f2aee5
Showing with 105 additions and 2 deletions.
  1. +2 −1 kernel.cpp
  2. +1 −1 makefile
  3. +78 −0 mouse.cpp
  4. +24 −0 mouse.h
View
@@ -3,7 +3,7 @@
#include "gdt.h"
#include "interrupts.h"
#include "keyboard.h"
#include "mouse.h"
void printf(char* str)
{
@@ -62,6 +62,7 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t /*multiboot
GlobalDescriptorTable gdt;
InterruptManager interrupts(0x20, &gdt);
KeyboardDriver keyboard(&interrupts);
MouseDriver mouse(&interrupts);
interrupts.Activate();
while(1);
View
@@ -6,7 +6,7 @@ GCCPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-excep
ASPARAMS = --32
LDPARAMS = -melf_i386
objects = loader.o gdt.o port.o interruptstubs.o interrupts.o keyboard.o kernel.o
objects = loader.o gdt.o port.o interruptstubs.o interrupts.o keyboard.o mouse.o kernel.o
run: mykernel.iso
View
@@ -0,0 +1,78 @@
#include "mouse.h"
MouseDriver::MouseDriver(InterruptManager* manager)
: InterruptHandler(manager, 0x2C),
dataport(0x60),
commandport(0x64)
{
uint16_t* VideoMemory = (uint16_t*)0xb8000;
offset = 0;
buttons = 0;
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);
commandport.Write(0xA8);
commandport.Write(0x20); // command 0x60 = read controller command byte
uint8_t status = dataport.Read() | 2;
commandport.Write(0x60); // command 0x60 = set controller command byte
dataport.Write(status);
commandport.Write(0xD4);
dataport.Write(0xF4);
dataport.Read();
}
MouseDriver::~MouseDriver()
{
}
uint32_t MouseDriver::HandleInterrupt(uint32_t esp)
{
uint8_t status = commandport.Read();
if (!(status & 0x20))
return esp;
buffer[offset] = dataport.Read();
offset = (offset + 1) % 3;
if(offset == 0)
{
if(buffer[1] != 0 || buffer[2] != 0)
{
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 += buffer[1];
if(x >= 80) x = 79;
if(x < 0) x = 0;
y -= buffer[2];
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);
}
/*
for(uint8_t i = 0; i < 3; i++)
{
if((buffer[0] & (0x1<<i)) != (buttons & (0x1<<i)))
{
if(buttons & (0x1<<i))
handler->OnMouseButtonReleased(i+1);
else
handler->OnMouseButtonPressed(i+1);
}
}
buttons = buffer[0];
*/
}
return esp;
}
View
24 mouse.h
@@ -0,0 +1,24 @@
#ifndef __MOUSE_H
#define __MOUSE_H
#include "types.h"
#include "port.h"
#include "interrupts.h"
class MouseDriver : public InterruptHandler
{
Port8Bit dataport;
Port8Bit commandport;
uint8_t buffer[3];
uint8_t offset;
uint8_t buttons;
int8_t x, y;
public:
MouseDriver(InterruptManager* manager);
~MouseDriver();
virtual uint32_t HandleInterrupt(uint32_t esp);
};
#endif

1 comment on commit 48959b0

@AraHaan

This comment has been minimized.

Show comment
Hide comment
@AraHaan

AraHaan Sep 23, 2018

The mouse driver does not work with the one built-in to my laptop. @AlgorithMan-de
image

AraHaan commented on 48959b0 Sep 23, 2018

The mouse driver does not work with the one built-in to my laptop. @AlgorithMan-de
image

Please sign in to comment.