Skip to content

Commit

Permalink
finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
kennypanjaitan committed Apr 29, 2023
1 parent 0e176c9 commit 51bf1f0
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 108 deletions.
52 changes: 26 additions & 26 deletions src/interrupt/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,45 +77,45 @@ void puts(char* str, uint32_t len, uint32_t color, uint8_t row, uint8_t col) {
framebuffer_set_cursor(row, col + i);
}

void cmd_ls(struct FAT32DriverRequest request){
void cmd_ls(struct FAT32DriverRequest request, uint8_t row, uint8_t col){
read_clusters(&fat_state.dir_table_buf, request.parent_cluster_number, 1);
for(int i =0;i<64; i++){
if (fat_state.dir_table_buf.table[i].name[0] != 0x00) {
puts(fat_state.dir_table_buf.table[i].name, 8, 0xF);
puts(fat_state.dir_table_buf.table[i].name, 8, 0xF, row, col);
}
}
}

void cmd_mkdir(struct FAT32DriverRequest request, struct CPURegister cpu){
void cmd_mkdir(struct FAT32DriverRequest request, struct CPURegister cpu, uint8_t row, uint8_t col){
*((int8_t*) cpu.ecx) = write(request);
// puts("yayyy", 5, 0xF);
if (cpu.ecx == (int8_t) 0){
puts("Folder has been created", 24, 0xF);
puts("Folder has been created", 24, 0xF, row, col);
}
else{
puts("Error", 5, 0xF);
puts("Error", 5, 0xF, row, col);
}
}

void cmd_rm(struct FAT32DriverRequest request, struct CPURegister cpu){
*((int8_t*) cpu.ecx) = delete(request);
// puts("yyy", 5, 0xF);
if (cpu.ecx == (int8_t) 0){
puts("Folder has been removed", 24, 0xF);
}
else{
puts("Error", 5, 0xF);
}
}

void cmd_cat(struct FAT32DriverRequest request){
read_clusters(&fat_state.dir_table_buf, request.parent_cluster_number, 1);
for(int i =0;i<64; i++){
if (fat_state.dir_table_buf.table[i].name[0] != 0x00) {
puts(fat_state.dir_table_buf.table[i].name, 8, 0xF);
}
}
}
// void cmd_rm(struct FAT32DriverRequest request, struct CPURegister cpu){
// *((int8_t*) cpu.ecx) = delete(request);
// // puts("yyy", 5, 0xF);
// if (cpu.ecx == (int8_t) 0){
// puts("Folder has been removed", 24, 0xF);
// }
// else{
// puts("Error", 5, 0xF);
// }
// }

// void cmd_cat(struct FAT32DriverRequest request){
// read_clusters(&fat_state.dir_table_buf, request.parent_cluster_number, 1);
// for(int i =0;i<64; i++){
// if (fat_state.dir_table_buf.table[i].name[0] != 0x00) {
// puts(fat_state.dir_table_buf.table[i].name, 8, 0xF);
// }
// }
// }

void syscall(struct CPURegister cpu, __attribute__((unused)) struct InterruptStack info) {
uint8_t row, col;
Expand Down Expand Up @@ -145,11 +145,11 @@ void syscall(struct CPURegister cpu, __attribute__((unused)) struct InterruptSta
.parent_cluster_number = ROOT_CLUSTER_NUMBER,
.buffer_size = 0x100000,
};
cmd_ls(request);
cmd_ls(request, row, col);
}
else if(cpu.eax == 10){
struct FAT32DriverRequest request = *(struct FAT32DriverRequest*) cpu.ebx;
cmd_mkdir(request, cpu);
cmd_mkdir(request, cpu, row, col);
}

// else if (cpu.eax == 11){
Expand Down
105 changes: 65 additions & 40 deletions src/keyboard/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ void keyboard_isr(void) {
uint8_t cursor_x, cursor_y;
static bool last_key_pressed = FALSE;
static bool make_code = FALSE;
char* framebuffer = (char*) 0xB8000;
// char* framebuffer = (char*) 0xB8000;


if (!is_keyboard_blocking()) {
keyboard_state.buffer_index = 0;
}
Expand All @@ -82,43 +81,41 @@ void keyboard_isr(void) {
keyboard_state.buffer_index--;
if (cursor_y == 0) {
if (cursor_x > 0) {
cursor_y = 79;
framebuffer_set_cursor(cursor_x - 1, cursor_y);
framebuffer_write(cursor_x - 1, cursor_y, ' ', 0x0F, 0X00);
framebuffer_set_cursor(cursor_x - 1, 79);
framebuffer_write(cursor_x - 1, 79, ' ', 0xF, 0);
}
} else {
framebuffer_set_cursor(cursor_x, cursor_y - 1);
framebuffer_write(cursor_x, cursor_y - 1, ' ', 0xF, 0);
for (int i = cursor_y; i < 79; i++) {
char c = *(framebuffer + ((cursor_x * 80) + i) * 2);
framebuffer_write(cursor_x, i - 1, c, 0xF, 0);
framebuffer_write(cursor_x, i, 0, 0xF, 0);
}
// for (int i = cursor_y; i < 254; i++) {
// char c = *(framebuffer + ((cursor_x * 80) + i) * 2);
// framebuffer_write(cursor_x, i - 1, c, 0xF, 0);
// framebuffer_write(cursor_x, i, 0, 0xF, 0);
// }
}
}
break;
default:
keyboard_state.keyboard_buffer[keyboard_state.buffer_index++] = last_key_pressed;
framebuffer_get_cursor(&cursor_x, &cursor_y);

if (cursor_y == 79) {
if (*(framebuffer + ((cursor_x * 80) + cursor_y) * 2) != ' ') {
for (int i = cursor_y - 1; i >= 0; i--) {
char temp_char = *(framebuffer + ((cursor_x * 80) + i) * 2);
framebuffer_write(cursor_x, i + 1, temp_char, 0x0F, 0x00);
}
}
// if (keyboard_state.keyboard_buffer[keyboard_state.buffer_index - 1] == '\n') {
// for (int i = cursor_y - 1; i >= 0; i--) {
// char temp_char = *(framebuffer + ((cursor_x * 80) + i) * 2);
// framebuffer_write(cursor_x, i + 1, temp_char, 0x0F, 0x00);
// }
// }
framebuffer_write(cursor_x, cursor_y, last_key_pressed, 0x0F, 0x00);
framebuffer_set_cursor(cursor_x + 1, 0);
cursor_x++;
cursor_y = 0;
} else {
if (*(framebuffer + ((cursor_x * 80) + cursor_y) * 2) != ' ') {
for (int i = 78; i > cursor_y; i--) {
char temp_char = *(framebuffer + ((cursor_x * 80) + i) * 2);
framebuffer_write(cursor_x, i + 1, temp_char, 0x0F, 0x00);
}
}
// if (cursor_y < keyboard_state.buffer_index) {
// for (int i = 254; i > cursor_y; i--) {
// char temp_char = *(framebuffer + ((cursor_x * 80) + i) * 2);
// framebuffer_write(cursor_x, i + 1, temp_char, 0x0F, 0x00);
// }
// }
framebuffer_write(cursor_x, cursor_y, last_key_pressed, 0x0F, 0x00);
framebuffer_set_cursor(cursor_x, cursor_y + 1);
cursor_y++;
Expand All @@ -130,42 +127,70 @@ void keyboard_isr(void) {
switch (scancode) {
case EXT_SCANCODE_RIGHT:
framebuffer_get_cursor(&cursor_x, &cursor_y);
if (cursor_y == 79) {
framebuffer_set_cursor(cursor_x + 1, 0);
} else {
if (*(framebuffer + ((cursor_x * 80) + cursor_y + 1) * 2) == ' ') {
framebuffer_set_cursor(cursor_x, cursor_y);
} else {
uint8_t currentBaris = cursor_x;
uint8_t nBaris = keyboard_state.buffer_index / 80;
uint8_t baris = currentBaris - nBaris;
uint8_t kolom = keyboard_state.buffer_index % 80;
if (keyboard_state.buffer_index > 79) {
if (cursor_x <= currentBaris && cursor_x >= baris) {
if (cursor_y == 79) {
if (cursor_x < 24) {
framebuffer_set_cursor(cursor_x + 1, 0);
}
}
else if (cursor_y < 79) {
framebuffer_set_cursor(cursor_x, cursor_y + 1);
}
}
else if (cursor_x == currentBaris - 1) {
if (cursor_y < kolom) {
framebuffer_set_cursor(cursor_x, cursor_y + 1);
} else {
framebuffer_set_cursor(cursor_x, cursor_y);
}
}
}
else {
if (cursor_y < keyboard_state.buffer_index) {
framebuffer_set_cursor(cursor_x, cursor_y + 1);
} else {
framebuffer_set_cursor(cursor_x, cursor_y);
}
}
break;
case EXT_SCANCODE_LEFT:
framebuffer_get_cursor(&cursor_x, &cursor_y);
if (cursor_y == 0) {
if (cursor_x > 0) {
framebuffer_set_cursor(cursor_x - 1, 79);
uint8_t barisL = cursor_x - (keyboard_state.buffer_index / 80);
if (keyboard_state.buffer_index > 80) {
if (cursor_x != barisL) {
if (cursor_y == 0) {
if (cursor_x > 0) {
framebuffer_set_cursor(cursor_x - 1, 79);
}
} else {
framebuffer_set_cursor(cursor_x, cursor_y - 1);
}
}
} else {
framebuffer_set_cursor(cursor_x, cursor_y - 1);
if (cursor_y > 0) {
framebuffer_set_cursor(cursor_x, cursor_y - 1);
} else {
framebuffer_set_cursor(cursor_x, cursor_y);
}
}
break;
case EXT_SCANCODE_UP:
framebuffer_get_cursor(&cursor_x, &cursor_y);
if (cursor_x > 0) {
framebuffer_set_cursor(cursor_x - 1, cursor_y);
}
framebuffer_set_cursor(cursor_x, cursor_y);
break;
case EXT_SCANCODE_DOWN:
framebuffer_get_cursor(&cursor_x, &cursor_y);
if (cursor_x < 24) {
framebuffer_set_cursor(cursor_x + 1, cursor_y);
}
framebuffer_set_cursor(cursor_x, cursor_y);
break;
default:
break;
}
}
}
pic_ack(IRQ_KEYBOARD);
}
}
84 changes: 42 additions & 42 deletions src/user-mode/user-shell.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../lib-header/stdtype.h"
#include "../filesystem/fat32.h"
// #include "../lib-header/stdmem.h"
#include "../interrupt/interrupt.h"
// #include "../interrupt/interrupt.h"

void syscall(uint32_t eax, uint32_t ebx, uint32_t ecx, uint32_t edx) {
__asm__ volatile("mov %0, %%ebx" : /* <Empty> */ : "r"(ebx));
Expand Down Expand Up @@ -34,47 +34,47 @@ void* memcpy(void* restrict dest, const void* restrict src, size_t n) {
return dstbuf;
}

void read_buffer(char* buf) {

if (memcmp(buf, "ls", 3) == 0) {
syscall(9, 0, 0, 0);
// puts("ls za", 5, 0xF);
}

if (memcmp(buf, "mkdir", 5) == 0){
char *name = buf + 6;
struct FAT32DriverRequest request = {
.parent_cluster_number = ROOT_CLUSTER_NUMBER,
.buffer_size = 0x0,
};
memcpy(request.name,name,8);
// puts("mkdir za", 8, 0xF);
syscall(10, (uint32_t) &request, 0, 0);
}
// void read_buffer(char* buf) {

// if (memcmp(buf, "ls", 3) == 0) {
// syscall(9, 0, 0, 0);
// // puts("ls za", 5, 0xF);
// }

// if (memcmp(buf, "mkdir", 5) == 0){
// char *name = buf + 6;
// struct FAT32DriverRequest request = {
// .parent_cluster_number = ROOT_CLUSTER_NUMBER,
// .buffer_size = 0x0,
// };
// memcpy(request.name,name,8);
// // puts("mkdir za", 8, 0xF);
// syscall(10, (uint32_t) &request, 0, 0);
// }

// if (memcmp((char*)buf, "rm", 2) == 0){
// char *name = buf + 3;
// // puts("yey", 8, 0xF);

// struct FAT32DriverRequest request = {
// .parent_cluster_number = ROOT_CLUSTER_NUMBER,
// .buffer_size = 0x0,
// };
// memcpy(request.name,name,8);
// syscall(11, (uint32_t) &request, 0, 0);
// }

// if (memcmp(buf, "cat ", 4) == 0){
// char *name = buf + 4;
// struct FAT32DriverRequest request = {
// .parent_cluster_number = ROOT_CLUSTER_NUMBER,
// .buffer_size = 0x0,
// };
// memcpy(request.name,name,8);
// syscall(10, (uint32_t) &request, 0, 0);
// }
// // if (memcmp((char*)buf, "rm", 2) == 0){
// // char *name = buf + 3;
// // // puts("yey", 8, 0xF);

// // struct FAT32DriverRequest request = {
// // .parent_cluster_number = ROOT_CLUSTER_NUMBER,
// // .buffer_size = 0x0,
// // };
// // memcpy(request.name,name,8);
// // syscall(11, (uint32_t) &request, 0, 0);
// // }

// // if (memcmp(buf, "cat ", 4) == 0){
// // char *name = buf + 4;
// // struct FAT32DriverRequest request = {
// // .parent_cluster_number = ROOT_CLUSTER_NUMBER,
// // .buffer_size = 0x0,
// // };
// // memcpy(request.name,name,8);
// // syscall(10, (uint32_t) &request, 0, 0);
// // }

}
// }


// int main(void) {
Expand All @@ -87,7 +87,7 @@ void read_buffer(char* buf) {
int main(void) {
char buf[16];
while (TRUE) {
syscall(6, (uint32_t) ("hexOS@OS-IF2230"), 15, 0x2);
syscall(6, (uint32_t) "hexOS@OS-IF2230", 15, 0x2);
syscall(6, (uint32_t) ":", 1, 0x7);
syscall(6, (uint32_t) "root", 4, 0x9);
// syscall(6, (uint32_t) print_cwd())
Expand All @@ -96,7 +96,7 @@ int main(void) {
syscall(4, (uint32_t) buf, 16, 0);
syscall(5, (uint32_t) buf, 16, 0xE);

read_buffer(buf);
// read_buffer(buf);

}

Expand Down

0 comments on commit 51bf1f0

Please sign in to comment.