Skip to content

Commit

Permalink
Clean up in framebuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Łukasik committed Oct 25, 2024
1 parent f1debfc commit d661369
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/impl/x86_64/device/com.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ComDevice::print_str(const char *str, va_list args)
{
for (pt::size_t i=0; true; i++)
{
char character = (pt::uint8_t)str[i];
const char character = (pt::uint8_t)str[i];

if (character == '\0')
{
Expand Down
23 changes: 10 additions & 13 deletions src/impl/x86_64/device/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ void mouse_wait(const pt::uint8_t type)
}
}

static pt::uint16_t _x = 0;
static pt::uint16_t _y = 0;
static pt::int16_t screen_max_x = 0;
static pt::int16_t screen_max_y = 0;

void init_mouse(pt::uint16_t max_x, pt::uint16_t max_y)
void init_mouse(const pt::int16_t max_x, const pt::int16_t max_y)
{
klog("[MOUSE] Init mouse\n");

Expand All @@ -59,7 +59,7 @@ void init_mouse(pt::uint16_t max_x, pt::uint16_t max_y)
klog("[MOUSE] Enabled IRQ\n");

mouse_wait(0);
pt::uint8_t status = IO::inb(0x60) | 2;
const pt::uint8_t status = IO::inb(0x60) | 2;

mouse_wait(1);
IO::outb(0x64, 0x60);
Expand Down Expand Up @@ -87,8 +87,8 @@ void init_mouse(pt::uint16_t max_x, pt::uint16_t max_y)
kernel_panic("Mouse did not ACKed enable!", MouseNotAcked);


_x = max_x;
_y = max_y;
screen_max_x = max_x;
screen_max_y = max_y;
klog("[MOUSE] Initialized\n");
}

Expand All @@ -99,9 +99,6 @@ mouse_state mouse {
.right_button_pressed = false
};

extern void DrawCursor(pt::uint32_t x_pos, pt::uint32_t y_pos);
extern void EraseCursor(pt::uint32_t x_pos, pt::uint32_t y_pos);

void mouse_routine(const pt::int8_t mouse_byte[])
{
const pt::int8_t mouse_x = mouse_byte[1];
Expand All @@ -113,16 +110,16 @@ void mouse_routine(const pt::int8_t mouse_byte[])
pt::int16_t newPosX = mouse.pos_x + mouse_x;
if (newPosX < 0)
newPosX = 0;
if (newPosX > _x)
newPosX = _x;
if (newPosX > screen_max_x)
newPosX = screen_max_x;

mouse.pos_x = newPosX;

pt::int16_t newPosY = mouse.pos_y - mouse_y;
if (newPosY <0)
newPosY = 0;
if (newPosY > _y)
newPosY = _y;
if (newPosY > screen_max_y)
newPosY = screen_max_y;

mouse.pos_y = newPosY;
mouse.left_button_pressed = left_button_pressed;
Expand Down
9 changes: 2 additions & 7 deletions src/impl/x86_64/device/pci.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#include "../../../intf/pci.h"

pt::uint32_t pciConfigReadDWord(const pt::uint8_t bus, const pt::uint8_t slot, const pt::uint8_t func, const pt::uint8_t offset) {
const pt::uint32_t lbus = bus;
const pt::uint32_t lslot = slot;
const pt::uint32_t lfunc = func;

// Create configuration address as per Figure 1
const auto address = lbus << 16 | lslot << 11 |
lfunc << 8 | offset & 0xFC | 0x80000000;
const auto address = bus << 16 | slot << 11 |
func << 8 | offset & 0xFC | 0x80000000;

// Write out the address
IO::outd(0xCF8, address);
Expand Down
6 changes: 3 additions & 3 deletions src/intf/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class Framebuffer
pt::uint32_t m_bpp;
pt::uint32_t m_stride;
pt::uintptr_t *vga_font;
Framebuffer(pt::uintptr_t addr, pt::uint32_t width,
pt::uint32_t height, pt::uint32_t bpp,
pt::uint32_t stride) : m_addr(addr), m_width(width),
Framebuffer(const pt::uintptr_t addr, const pt::uint32_t width,
const pt::uint32_t height, const pt::uint32_t bpp,
const pt::uint32_t stride) : m_addr(addr), m_width(width),
m_height(height), m_bpp(bpp),
m_stride(stride)
{
Expand Down
6 changes: 3 additions & 3 deletions src/intf/mouse.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

struct mouse_state
{
pt::uint16_t pos_x;
pt::uint16_t pos_y;
pt::int16_t pos_x;
pt::int16_t pos_y;
bool left_button_pressed;
bool right_button_pressed;
};

void init_mouse(pt::uint16_t max_x, pt::uint16_t max_y);
void init_mouse(pt::int16_t max_x, pt::int16_t max_y);

void mouse_handler(pt::int8_t mouse_byte[]);

0 comments on commit d661369

Please sign in to comment.