Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <drivers/mouse.h>
- using namespace hardware;
- using namespace drivers;
- void print(uint8_t* str);
- void setCursorPosition(uint8_t newx, uint8_t newy);
- void MouseEventHandler::onMouseDown(uint8_t button) {}
- void MouseEventHandler::onMouseUp(uint8_t button) {}
- void MouseEventHandler::onMouseMove(int x, int y) {}
- MouseDriver::MouseDriver(InterruptManager* interruptManager, MouseEventHandler* events)
- :dataport(0x60),
- commandport(0x64),
- InterruptHandler(interruptManager, 0x2C) {
- offset = 0;
- buttons = 0;
- x = 0;
- y = 0;
- eventHandler = events;
- eventHandler->onMouseMove(x, y);
- }
- void MouseDriver::activate() {
- 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();
- }
- 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) {
- 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;
- eventHandler->onMouseMove(x, y);
- }
- }
- return esp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement