Skip to content

Commit

Permalink
Merge pull request #2 from vinsdragonis/mouse
Browse files Browse the repository at this point in the history
Added improvised version of mouse cursor
  • Loading branch information
vinsdragonis authored Feb 20, 2022
2 parents ed6e2a0 + 7443e8f commit d58886a
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 8 deletions.
Binary file modified boot/bin/kernel.bin
Binary file not shown.
Binary file modified boot/bin/kernel.img
Binary file not shown.
Binary file modified boot/bin/kernel.o
Binary file not shown.
33 changes: 33 additions & 0 deletions boot/graphics/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,39 @@ void DrawString(int (*f)(int, int), int font_width, int font_height, char *c, in
}
}

void DrawMouse(int x, int y, int r, int g, int b) {
int mouse[] = {
0b1111111111,
0b1111111110,
0b1111111100,
0b1111111000,
0b1111110000,
0b1111100000,
0b1111000000,
0b1110000000,
0b1100000000,
0b1000000000,
};

int mouse_width = 10, mouse_height = 10;

for (int j = 0; j < mouse_height; j++)
{
unsigned int row = mouse[j];
int shift = mouse_width - 1;
int bit_val = 0;

for (int i = 0; i < mouse_width; i++)
{
bit_val = (row >> shift) & 0b00000000000000000000000000000001;
if (bit_val == 1)
Draw(x + i, y + j, r, g, b);

shift -= 1;
}
}
}

void Flush() {
VBEInfoBlock *VBE = (VBEInfoBlock *)VBEInfoAddress;
unsigned short *buffer = (unsigned short *)ScreenBufferAddress;
Expand Down
24 changes: 18 additions & 6 deletions boot/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ int x, y;
int left_clicked, right_clicked, middle_clicked;
int current_byte = 0;
uint8_t bytes[4] = {0};
int mouse_speed = 5;

#define pic1_command 0x20
#define pic1_data 0x21
Expand Down Expand Up @@ -198,9 +197,12 @@ void HandleMouseInterrupt() {
}

void HandleMousePacket() {
VBEInfoBlock *VBE = (VBEInfoBlock *)VBEInfoAddress;

uint8_t status = bytes[0];
int32_t change_x = (int32_t) bytes[1];
int32_t change_y = (int32_t) bytes[2];
int32_t change_y = (int32_t)bytes[2];
int mouse_speed = 3;

if (status & x_overflow || status & y_overflow)
return;
Expand All @@ -216,12 +218,22 @@ void HandleMousePacket() {
middle_clicked = status & middle_click;

if (change_x > 0)
x += 2;
x += mouse_speed;
else if (change_x < 0)
x -= 2;
x -= mouse_speed;

if (change_y > 0)
y -= 2;
y -= mouse_speed;
else if (change_y < 0)
y += 2;
y += mouse_speed;

if (x < 0)
x = 0;
else if (x > VBE->x_resolution)
x = VBE->x_resolution;

if (y < 0)
y = 0;
else if (y > VBE->y_resolution)
y = VBE->y_resolution;
}
10 changes: 8 additions & 2 deletions boot/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include "graphics/graphics.h"

int start() {
VBEInfoBlock *VBE = (VBEInfoBlock *)VBEInfoAddress;

x = VBE->x_resolution / 2;
y = VBE->y_resolution / 2;

// String literals are limited to 61 characters
char header[] = "Welcome to Wyvern OS!";
char *p = header;
Expand All @@ -14,14 +19,15 @@ int start() {
while (1) {
clearScreen(181.0f / 255.0f * 16.0f, 232.0f / 255.0f * 32.0f, 255.0f / 255.0f * 16.0f);

DrawRect(x, y, 10, 10, 0, 0, 0);

DrawRect(150, 140, 350, 40, 0, 0, 0);
DrawString(getArialCharacter, font_arial_width, font_arial_height, p, 240, 150, 255, 255, 255);

DrawRect(300, 300, 50, 50, 20, 200, 50);
DrawRect(325, 325, 50, 50, 200, 50, 50);

// DrawRect(x, y, 10, 10, 0, 0, 0);
DrawMouse(x, y, 40.0, 100.0 / 255.0 * 32, 100.0 / 255.0 * 16);

Flush();
}
}
Binary file modified os.img
Binary file not shown.

0 comments on commit d58886a

Please sign in to comment.