#pragma once

#include <common.h>

#define PS2_MOUSE_IRQ      12
#define PS2_MOUSE_VECTOR   (PIC_IRQ_BASE + PS2_MOUSE_IRQ)

// PS/2 controller ports
#define PS2_DATA_PORT      0x60
#define PS2_STATUS_PORT    0x64
#define PS2_CMD_PORT       0x64

// PS/2 controller commands
#define PS2_CMD_READ_MB    0x20   // Read command byte
#define PS2_CMD_WRITE_MB   0x60   // Write command byte
#define PS2_CMD_ENABLE_A2  0xA8   // Enable auxiliary (second) port
#define PS2_CMD_SELF_TEST  0xAA   // Controller self-test

// PS/2 command byte bits
#define PS2_CMD_IRQ12      0x02   // Enable IRQ12 (auxiliary device)
#define PS2_CMD_IRQ1       0x01   // Enable IRQ1  (keyboard)

// PS/2 controller status bits
#define PS2_STAT_OBF       0x01   // Output buffer full (data ready)
#define PS2_STAT_IBF       0x02   // Input buffer full (controller busy)

// PS/2 mouse commands
#define PS2_MOUSE_ENABLE   0xF4   // Enable data reporting
#define PS2_MOUSE_DISABLE  0xF5   // Disable data reporting
#define PS2_MOUSE_RESET    0xFF   // Reset mouse

// Mouse packet byte 0 flags
#define PS2_MOUSE_LEFT     0x01
#define PS2_MOUSE_RIGHT    0x02
#define PS2_MOUSE_MIDDLE   0x04
#define PS2_MOUSE_ALWAYS1  0x08
#define PS2_MOUSE_X_SIGN   0x10
#define PS2_MOUSE_Y_SIGN   0x20
#define PS2_MOUSE_X_OVER   0x40
#define PS2_MOUSE_Y_OVER   0x80

void mouse_init(void);

SSINT32 mouse_get_x(void);
SSINT32 mouse_get_y(void);
bool    mouse_get_btn_left(void);
bool    mouse_get_btn_right(void);
bool    mouse_get_btn_middle(void);
