diff --git a/README.md b/README.md index 8e6ef67..2232bcf 100644 --- a/README.md +++ b/README.md @@ -48,4 +48,7 @@ Clone and build: git clone https://github.com/gbowne1/ClassicOS.git cd ClassicOS make -``` \ No newline at end of file +``` + +build kernel +for %f in (*.c) do gcc -m32 -O0 -Wall -Wextra -Werror -pedantic -ffreestanding -nostdlib -fno-pic -fno-stack-protector -fno-pie -march=i386 -mtune=i386 -c "%f" -o "%f.o" diff --git a/kernel/mouse.c b/kernel/mouse.c new file mode 100644 index 0000000..b096c45 --- /dev/null +++ b/kernel/mouse.c @@ -0,0 +1,66 @@ +#include "mouse.h" +#include "usb.h" +#include +#include + +// Struct to store mouse state +typedef struct { + int x; + int y; + bool left_button; + bool right_button; +} mouse_data_t; + +// Mouse buffer +static mouse_data_t mouse_data; + +// Initialize USB Mouse (1.x & HID 1.0-1.11) +bool usb_mouse_init(void) { + if (!usb_init()) { + return false; + } + + if (!usb_hid_init()) { + return false; + } + + if (!usb_enumerate_devices()) { + return false; + } + + return true; +} + +// Detect if a USB mouse is connected +bool usb_mouse_detected(void) { + return usb_hid_init(); +} + +// Check if USB mouse data has been received +bool usb_mouse_received(void) { + return usb_interrupt_transfer(/* parameters */); +} + +// Read USB mouse data +mouse_data_t usb_read_mouse(void) { + uint8_t buffer[3]; // USB HID Mouse reports typically use 3 bytes + if (usb_interrupt_transfer(/* parameters */)) { + // Process the received data + mouse_data.x += buffer[1]; // X movement + mouse_data.y += buffer[2]; // Y movement + mouse_data.left_button = buffer[0] & 0x01; + mouse_data.right_button = buffer[0] & 0x02; + } + return mouse_data; +} + +// USB Host Controller Initialization (for USB 1.x) +bool uhci_init(void) { + // Initialize UHCI controller for legacy USB support + return true; +} + +bool ohci_init(void) { + // Initialize OHCI controller for USB 1.x + return true; +} diff --git a/kernel/mouse.h b/kernel/mouse.h new file mode 100644 index 0000000..5896507 --- /dev/null +++ b/kernel/mouse.h @@ -0,0 +1,25 @@ +#ifndef MOUSE_H +#define MOUSE_H + +#include +#include + +// Mouse data structure +typedef struct { + int x; + int y; + bool left_button; + bool right_button; +} mouse_data_t; + +// Function declarations for USB 1.x HID mouse support +bool usb_mouse_init(void); +bool usb_mouse_detected(void); +bool usb_mouse_received(void); +mouse_data_t usb_read_mouse(void); + +// USB Host Controller Interface functions (USB 1.x support) +bool uhci_init(void); +bool ohci_init(void); + +#endif // MOUSE_H diff --git a/kernel/usb.c b/kernel/usb.c new file mode 100644 index 0000000..5da1d8c --- /dev/null +++ b/kernel/usb.c @@ -0,0 +1,64 @@ +#include "usb.h" +#include +#include + +// USB version detection +bool usb_detect_version(uint16_t *version) { + if (!version) return false; + *version = 0x0110; // Example: USB 1.1 + return true; +} + +// USB initialization for 1.x +bool usb_init(void) { + // Detect controller type (UHCI or OHCI) + bool uhci_supported = uhci_init(); + bool ohci_supported = ohci_init(); + + if (!uhci_supported && !ohci_supported) { + return false; // No supported controllers found + } + + return true; +} + +// USB device enumeration (1.x) +bool usb_enumerate_devices(void) { + // Implementation for detecting devices on USB 1.x ports + return true; +} + +// HID initialization for USB 1.x +bool usb_hid_init(void) { + // Ensure USB is initialized + if (!usb_init()) return false; + + return usb_enumerate_devices(); +} + +// USB transfers (stubs for 1.x) +bool usb_control_transfer(/* parameters */) { + // Implement control transfer for USB 1.x + return true; +} + +bool usb_interrupt_transfer(/* parameters */) { + // Implement interrupt transfer for USB 1.x + return true; +} + +bool usb_bulk_transfer(/* parameters */) { + // Implement bulk transfer for USB 1.x + return true; +} + +// USB host controller initialization (UHCI & OHCI) +bool uhci_init(void) { + // Initialize UHCI controller (USB 1.x) + return true; +} + +bool ohci_init(void) { + // Initialize OHCI controller (USB 1.x) + return true; +} diff --git a/kernel/usb.h b/kernel/usb.h new file mode 100644 index 0000000..c84a30f --- /dev/null +++ b/kernel/usb.h @@ -0,0 +1,24 @@ +#ifndef USB_H +#define USB_H + +#include +#include + +// USB initialization and management functions +bool usb_init(void); +bool usb_detect_version(uint16_t *version); +bool usb_enumerate_devices(void); + +// HID-specific functions +bool usb_hid_init(void); + +// USB transfer functions +bool usb_control_transfer(/* parameters */); +bool usb_interrupt_transfer(/* parameters */); +bool usb_bulk_transfer(/* parameters */); + +// USB host controller initialization (USB 1.x only) +bool uhci_init(void); // UHCI support +bool ohci_init(void); // OHCI support + +#endif // USB_H