Here's my mouse code:
Code: Select all
// SANiK source code adaptation
#define WorkAreaW 640
#define WorkAreaH 480
#define MousePort 0x60
#define MouseStatus 0x64
#define MouseABit 0x02
#define MouseBBit 0x01
#define MouseWriteC 0xd4
#define MouseFBit 0x20
#define MouseVBit 0x08
#define MouseDefault 0
#define MouseScrollWheel 1
#define MouseButtons 2
int MousePosX = 0;
int MousePosY = 0;
#define Cursor struct cursor_t
Cursor
{
int64_t bitmap[12 * 21];
uint8_t w, h;
};
#define X 0xffffff,
#define B 0x000000,
#define o (-1),
Cursor cursor = {
{
B o o o o o o o o o o o
B B o o o o o o o o o o
B X B o o o o o o o o o
B X B B o o o o o o o o
B X X X B o o o o o o o
B X X X X B o o o o o o
B X X X X X B o o o o o
B X X X X X X B o o o o
B X X X X X X X B o o o
B X X X X X X X X B o o
B X X X X X X X X X B o
B X X X X X X B B B B B
B X X X B X X B o o o o
B X X B B X X B o o o o
B X B o o B X X B o o o
B B o o o B X X B o o o
B o o o o o B X X B o o
o o o o o o B X X B o o
o o o o o o o B X X B o
o o o o o o o B X X B o
o o o o o o o o B B o o
},
12, 21
};
#undef X
#undef B
#undef o
uint8_t ps2_mouse_cycle = 0;
int8_t ps2_mouse_byte[3];
int8_t ps2_mouse_x = 0;
int8_t ps2_mouse_y = 0;
bool MouseAvailable = true;
// This is supposed to be called, but it doesn't, as to be expected.
void MouseHandlerMain()
{
puts("FIRED");
if (!MouseAvailable) puts("HOW");
}
// This function fails right at the beginning.
void MouseWait(uint8_t type, int linenum, int linenum2)
{
if (!MouseAvailable) return;
int timeout = 100000; //unsigned int
while (timeout--)
{
if ((ReadPort(0x64) & (type + 1)) == 1) return;
}
MouseAvailable = false;
printf("Mouse timeout reached, guessed that the mouse is unavailable. (failed at %d or %d)\n", linenum, linenum2);
return;
}
// NOTE: ReadPort and WritePort work like inportb and outportb respectively.
void MouseWrite(uint8_t write, int line)
{
if (!MouseAvailable) return;
MouseWait(1, line, __LINE__);
WritePort(0x64, 0xD4);
MouseWait(1, line, __LINE__);
WritePort(0x60, write);
}
uint8_t MouseRead(int line)
{
if (!MouseAvailable) return 0xff;
MouseWait(0, line, __LINE__);
return ReadPort(0x60);
}
void InitMouse()
{
puts("[INIT] Initializing Mouse...\n");
uint8_t _status;
// Enable the auxiliary mouse device.
MouseWait(1, __LINE__, __LINE__); // THIS is where the code fails.
WritePort(0x64, 0xA8);
// Enable the interrupts
MouseWait(1, __LINE__, __LINE__);
WritePort(0x64, 0x20);
MouseWait(0, __LINE__, __LINE__);
_status = (ReadPort(0x60) | 2);
MouseWait(1, __LINE__, __LINE__);
WritePort(0x64, 0x60);
MouseWait(1, __LINE__, __LINE__);
WritePort(0x60, _status);
// Tell the mouse to use default settings
MouseWrite(0xF6, __LINE__);
MouseRead(__LINE__);
// Enable data reporting
MouseWrite(0xF4, __LINE__);
MouseRead(__LINE__);
// The mouse handler is already set up
// in the PIC.
if (MouseAvailable)
puts("[INIT] Init finished.\n");
else
puts("Mouse failed to initialize.\n");
}
Code: Select all
// This is what I use to load the mouse interrupt.
IDT[0x2c].offset_lowerbits = mouse_address & 0xffff;
IDT[0x2c].selector = KERNEL_CODE_SEGMENT_OFFSET;
IDT[0x2c].zero = 0;
IDT[0x2c].type_attr = INTERRUPT_GATE;
IDT[0x2c].offset_higherbits = (mouse_address & 0xffff0000) >> 16;
Code: Select all
#define INTERRUPT_ENABLE_BITS_0 0b11111100
#define INTERRUPT_ENABLE_BITS_1 0b11101111
// Setting the interrupt mask flags...
WritePort(0x21 , INTERRUPT_ENABLE_BITS_0);
WritePort(0xA1 , INTERRUPT_ENABLE_BITS_1);
This is an adaptation of http://forum.osdev.org/viewtopic.php?t=10247 without the handler part (I'll add that later when I get interrupts properly).

