Skip to content

Commit

Permalink
Merge pull request #1 from vinsdragonis/mouse
Browse files Browse the repository at this point in the history
Mouse
  • Loading branch information
vinsdragonis authored Feb 20, 2022
2 parents 9379378 + 4ba0ad0 commit ed6e2a0
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 63 deletions.
Binary file modified boot/bin/boot.bin
Binary file not shown.
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.
Binary file modified boot/bin/kernel_entry.bin
Binary file not shown.
4 changes: 1 addition & 3 deletions boot/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ section code

mov bx, 0x1000 ; location of the code being loaded from the hard disk
mov ah, 0x02
mov al, 21 ; number of sectors to read from the hard disk
mov al, 25 ; number of sectors to read from the hard disk
mov ch, 0x00
mov dh, 0x00
mov cl, 0x02
Expand All @@ -79,8 +79,6 @@ section code

jmp code_seg:protected_start

startupmsg: db 'Welcome to Wyvern!', 0

[bits 32]
protected_start:
mov ax, data_seg
Expand Down
2 changes: 1 addition & 1 deletion boot/final.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "graphics/graphics.c"
#include "graphics/font.c"
// #include "input.c"
#include "input.c"
#include "main.c"
73 changes: 37 additions & 36 deletions boot/input.c
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#include <stdint.h>

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
#define pic2_command 0x20
#define pic2_data 0x21
#define pic2_command 0xa0
#define pic2_data 0xa1
#define icw1_def 0x10
#define icw1_icw4 0x01
#define icw4_x86 0x01

#define y_overflow 0b10000000
#define x_overflow 0b01000000
#define y_negative 0b00100000
#define x_negative 0b00010000
#define always_set 0b00001000
#define middle_click 0b00000100
#define right_click 0b00000010
#define left_click 0b00000001
#define unused_a 0b10000000
#define unused_b 0b01000000

#include <stdint.h>
#define y_overflow 0b10000000
#define x_overflow 0b01000000
#define y_negative 0b00100000
#define x_negative 0b00010000
#define always_set 0b00001000
#define middle_click 0b00000100
#define right_click 0b00000010
#define left_click 0b00000001
#define unused_a 0b10000000
#define unused_b 0b01000000

void InitializeIDT();
extern void LoadIDT();
Expand All @@ -33,7 +39,7 @@ struct IDTElement {
unsigned short higher;
};

struct IDTElement _idt[256];
struct IDTElement idt[256];
extern unsigned int isr1, isr12;
unsigned int base, base12;

Expand All @@ -50,22 +56,22 @@ void outportb(unsigned short port, unsigned char data) {
}

void InitializeIDT() {
_idt[1].lower = (base12 & 0xffff);
_idt[1].higher = (base12 >> 16) & 0xffff;
_idt[1].selector = 0x08;
_idt[1].zero = 0;
_idt[1].flags = 0x8e;

_idt[12].lower = (base12 & 0xffff);
_idt[12].higher = (base12 >> 16) & 0xffff;
_idt[12].selector = 0x08;
_idt[12].zero = 0;
_idt[12].flags = 0x8e;
idt[1].lower = (base & 0xffff);
idt[1].higher = (base >> 16) & 0xffff;
idt[1].selector = 0x08;
idt[1].zero = 0;
idt[1].flags = 0x8e;

idt[12].lower = (base12 & 0xffff);
idt[12].higher = (base12 >> 16) & 0xffff;
idt[12].selector = 0x08;
idt[12].zero = 0;
idt[12].flags = 0x8e;

RemapPIC();

outportb(0x21, 0b11111001);
outportb(0xa1, 0xff);
outportb(0xa1, 0x00);

LoadIDT();
}
Expand Down Expand Up @@ -107,11 +113,6 @@ void HandleISR12() {
outportb(0x20, 0x20);
}

int x, y;
int left_clicked, right_clicked, middle_clicked;
int current_byte = 0;
uint8_t bytes[4] = { 0 };

void MouseWait(unsigned char type)
{
int time_out = 100000;
Expand Down Expand Up @@ -215,12 +216,12 @@ void HandleMousePacket() {
middle_clicked = status & middle_click;

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

if (change_y > 0)
y -= 5;
y -= 2;
else if (change_y < 0)
y += 5;
y += 2;
}
40 changes: 20 additions & 20 deletions boot/kernel_entry.asm
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ START:
call _start
jmp $

; extern _idt, HandleISR1, HandleISR12
; global isr1, isr12
; global LoadIDT
extern _idt, _HandleISR1, _HandleISR12
global _isr1, _isr12
global _LoadIDT

; IDTDesc:
; dw 2048
; dd _idt
IDTDesc:
dw 2048
dd _idt

; isr1:
; pusha
; call HandleISR1
; popa
; iret
_isr1:
pusha
call _HandleISR1
popa
iret

; isr12:
; pusha
; call HandleISR12
; popa
; iret
_isr12:
pusha
call _HandleISR12
popa
iret

; LoadIDT:
; lidt[IDTDesc]
; sti
; ret
_LoadIDT:
lidt[IDTDesc]
sti
ret
14 changes: 11 additions & 3 deletions boot/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

int start() {
// String literals are limited to 61 characters
char header[] = "Welcome to Wyvern OS!\n- Developed by Vineeth Dragonis";
char header[] = "Welcome to Wyvern OS!";
char *p = header;

base = (unsigned int) &isr1;
base12 = (unsigned int) &isr12;

InitializeIDT();
InitializeMouse();

while (1) {
clearScreen(181.0f / 255.0f * 16.0f, 232.0f / 255.0f * 32.0f, 255.0f / 255.0f * 16.0f);

DrawRect(150, 140, 350, 70, 0, 0, 0);
DrawString(getArialCharacter, font_arial_width, font_arial_height, p, 200, 150, 255, 255, 255);
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);
Expand Down
Binary file modified os.img
Binary file not shown.

0 comments on commit ed6e2a0

Please sign in to comment.