[GOOD] BUILD 0.1.0.450 DATE 8/29/2011 AT 10:30 AM
==================================================== + Changed 'align 0x4' line above multiboot header in loader.asm to 'align 4' + Removed -e option for echo in build.sh + Modified build.sh for linux + Fixed triple fault when enabling paging + Fixed page faults at memory manager initialization + Fixed 'mem' console function + Added more info about page fault at crash screen + Added Panic() macro + Added verbose mode for memory manager [ BAD] BUILD 0.1.0.390 DATE 8/27/2011 AT 10:54 PM ==================================================== + Added stdlib routines, separated in different files + Rewritten physical memory manager + Added virtual mem manager + Added memory allocation/freeing + Added memory library + Added temporary allocation (at end of kernel), until paging is started - Removed functionality from debug console function 'mem' - Removed system.h, the one remaining function now in stdio.h
This commit is contained in:
116
Kernel/hal/mouse/mouse.c
Normal file
116
Kernel/hal/mouse/mouse.c
Normal file
@ -0,0 +1,116 @@
|
||||
#include <stdio.h>
|
||||
#include <debugio.h>
|
||||
#include "mouse.h"
|
||||
#include "../keyboard/keyboard.h"
|
||||
|
||||
uint8 MouseCycle = 0;
|
||||
uint8 MouseCycleExpected = 3;
|
||||
uint8 Packets[4];
|
||||
|
||||
Point MousePosition = {0,0};
|
||||
Point MouseMinimumPosition = {0,0}, MouseMaximumPosition = {80, 25};
|
||||
Point Prev = {0,0};
|
||||
|
||||
#define SpeedLimit 0x8
|
||||
|
||||
// IRQ12
|
||||
void MouseHandler (_RegsStack32* UNUSED(r))
|
||||
{
|
||||
uint8 data = inportb(0x60);
|
||||
Point delta;
|
||||
|
||||
if (MouseCycle == 0 && (data == 0 || data == 0xFA || data == 0xFF || data == 0xAA)) return;
|
||||
Packets[MouseCycle++] = data;
|
||||
|
||||
// Cycle ended
|
||||
if (MouseCycle >= MouseCycleExpected)
|
||||
{
|
||||
MouseCycle = 0;
|
||||
if (Packets[0] & 0xC0) return; // Discard packet
|
||||
|
||||
// Update X position
|
||||
if (Packets[0] & 0x10) delta.X = (int32) (Packets[1] | 0xFFFFFF00);
|
||||
else delta.X = (int32) Packets[1];
|
||||
|
||||
// Update Y position
|
||||
if (Packets[0] & 0x20) delta.Y = -1 * (int32) (Packets[2] | 0xFFFFFF00);
|
||||
else delta.Y = -1 * (int32)Packets[2];
|
||||
|
||||
if (delta.X >= SpeedLimit) delta.X = SpeedLimit;
|
||||
if (delta.X <= -SpeedLimit) delta.X = -SpeedLimit;
|
||||
if (delta.Y >= SpeedLimit) delta.Y = SpeedLimit;
|
||||
if (delta.Y <= -SpeedLimit) delta.Y = -SpeedLimit;
|
||||
|
||||
MousePosition.X += delta.X;
|
||||
MousePosition.Y += delta.Y;
|
||||
|
||||
// Check limits
|
||||
if (MousePosition.X < MouseMinimumPosition.X) MousePosition.X = MouseMinimumPosition.X;
|
||||
if (MousePosition.Y < MouseMinimumPosition.Y) MousePosition.Y = MouseMinimumPosition.Y;
|
||||
if (MousePosition.X >= MouseMaximumPosition.X) MousePosition.X = MouseMaximumPosition.X - 1;
|
||||
if (MousePosition.Y >= MouseMaximumPosition.Y) MousePosition.Y = MouseMaximumPosition.Y - 1;
|
||||
|
||||
/* TESTING ONLY */
|
||||
ConsoleSetColor(Prev, 0xFF - ConsoleGetColor(Prev));
|
||||
ConsoleSetColor(MousePosition, 0xFF - ConsoleGetColor(MousePosition));
|
||||
Prev = MousePosition;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MouseSendCommand(uint8 command)
|
||||
{
|
||||
KeyboardWaitOutport();
|
||||
outportb(0x64, 0xD4);
|
||||
KeyboardWaitOutport();
|
||||
outportb(0x60, command);
|
||||
}
|
||||
|
||||
uint8 MouseReadData ()
|
||||
{
|
||||
KeyboardWaitInport();
|
||||
return inportb(0x60);
|
||||
}
|
||||
|
||||
void MouseInstall()
|
||||
{
|
||||
KeyboardWaitOutport();
|
||||
outportb(0x64, 0xA8);
|
||||
|
||||
// Enable interrupts
|
||||
KeyboardWaitOutport();
|
||||
outportb(0x64, 0x20);
|
||||
|
||||
KeyboardWaitInport();
|
||||
uint8 temp = inportb(0x60) | 2;
|
||||
temp &= ~0x20;
|
||||
|
||||
KeyboardWaitOutport();
|
||||
outportb(0x64, 0x60);
|
||||
|
||||
KeyboardWaitOutport();
|
||||
outportb(0x60, temp);
|
||||
|
||||
// Reset mouse, and enable it
|
||||
MouseSendCommand(MouseCommandReset);
|
||||
MouseReadData(); MouseReadData();
|
||||
|
||||
MouseSendCommand(MouseCommandSetDefaults);
|
||||
MouseReadData(); // Read ack
|
||||
|
||||
MouseSendCommand(MouseCommandEnableDataReporting);
|
||||
MouseReadData(); // Read ack
|
||||
|
||||
}
|
||||
|
||||
void MouseSetLimits (Point min_pos, Point max_pos)
|
||||
{
|
||||
MouseMinimumPosition = min_pos;
|
||||
MouseMaximumPosition = max_pos;
|
||||
}
|
||||
|
||||
MouseState MouseGetState()
|
||||
{
|
||||
MouseState ret = { Packets[0] & 0x7, MousePosition};
|
||||
return ret;
|
||||
}
|
36
Kernel/hal/mouse/mouse.h
Normal file
36
Kernel/hal/mouse/mouse.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef __MOUSE__H
|
||||
#define __MOUSE__H
|
||||
|
||||
#include <types.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8 Buttons;
|
||||
Point Position;
|
||||
} MouseState;
|
||||
|
||||
enum MouseCommands
|
||||
{
|
||||
MouseCommandReset = 0xFF,
|
||||
MouseCommandResend = 0xFE,
|
||||
MouseCommandSetDefaults = 0xF6,
|
||||
MouseCommandDisableDataReporting = 0xF5,
|
||||
MouseCommandEnableDataReporting = 0xF4,
|
||||
MouseCommandSetSampleRate = 0xF3,
|
||||
MouseCommandGetDeviceID = 0xF2,
|
||||
MouseCommandSetRemoteMode = 0xF0,
|
||||
MouseCommandSetWrapMode = 0xEE,
|
||||
MouseCommandReadData = 0xEB,
|
||||
MouseCommandSetStreamMode = 0xEA,
|
||||
MouseCommandStatusRequest = 0xE9,
|
||||
MouseCommandSetResolution = 0xE8,
|
||||
MouseCommandSetScaling_2_1 = 0xE7,
|
||||
MouseCommandSetScaling_1_1 = 0xE6
|
||||
};
|
||||
|
||||
extern void MouseInstall();
|
||||
extern void MouseHandler (_RegsStack32 *r);
|
||||
extern void MouseSetLimits (Point min_pos, Point max_pos);
|
||||
extern MouseState MouseGetState();
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user