Skip to content

Commit

Permalink
Added improvised version of mouse cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
vinsdragonis committed Feb 20, 2022
1 parent 4ba0ad0 commit 7443e8f
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.

8 comments on commit 7443e8f

@teamsonic2011
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could I design a mouse cursor for you?

@vinsdragonis
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A mouse cursor is already implemented. But you're always welcome to add an alternative / improvised version of it. 👍

@teamsonic2011
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question, is the mouse cursor right side up in the code?

@teamsonic2011
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an alternative mouse cursor:
00000000
01000000
01100000
01110000
01111000
01111100
01111110
01111111
00011000
00001100

@vinsdragonis
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can u please post a PR for this? It makes tracing commits easier.

Thanks.

@vinsdragonis
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick question, is the mouse cursor right side up in the code?

It was initially designed that way. but feel free to make it either way.

@teamsonic2011
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you make one?

@vinsdragonis
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you make one?

Head over to the Pull Requests tab on the top. Create a new pull request from there with the changes you made to any file(s).

You can refer to this link for a detailed walkthrough:
https://docs.github.com/articles/creating-a-pull-request

Please sign in to comment.