Feat: SCANF WORKING!

This commit is contained in:
AfonsoCMSousa
2026-08-05 11:29:15 +01:00
parent ba81bb8e10
commit 7a4394feb6
4 changed files with 39 additions and 34 deletions
+4
View File
@@ -682,8 +682,12 @@ exception_handler:
; Dummy interrupt handler for IRQs (not CPU exceptions)
dummy_handler:
push rax
; Save registers and acknowledge the interrupt
mov al, 0x20
out 0x20, al ; Send EOI to PIC
pop rax
iretq
idt_descriptor:
+3 -2
View File
@@ -35,6 +35,8 @@ nasm -f elf64 ./boot/kernel.asm -o ./obj/kernel.asm.o
# Step 4: Link kernel
echo -e "${BLUE}[4/6]${NC} Linking kernel..."
ld -T linker.ld -o ./bin/kernel.bin ./obj/kernel.asm.o ./obj/kernel.c.o --oformat binary --nostdlib
# Debug build (optional)
ld -T linker.ld -o ./bin/kernel_debug.elf ./obj/kernel.asm.o ./obj/kernel.c.o --oformat elf64-x86-64 --nostdlib
# Step 4.5: Calculate kernel size in sectors
KERNEL_SIZE=$(stat -f%z ./bin/kernel.bin 2>/dev/null || stat -c%s ./bin/kernel.bin 2>/dev/null)
@@ -51,8 +53,7 @@ cat ./bin/boot.bin ./bin/elevator.bin ./bin/kernel.bin > os.bin
# Pad to floppy size (1.44MB)
# FIX: Uncomment the line below if you want to ensure the image is exactly 1.44MB
#
truncate -s 1440K os.bin
#truncate -s 1440K os.bin
echo ""
echo -e "${GREEN}✓ Build complete!${NC}"
+8 -7
View File
@@ -33,14 +33,15 @@ void kmain(void) {
// TODO: Enable user input handling
char input_buffer[256] = {0};
gets(input_buffer, sizeof(input_buffer));
printf("Input buffer contents in hex:\n");
for (int i = 0; input_buffer[i] != '\0'; i++) {
printf("[%x]", (unsigned char)input_buffer[i]);
}
printf("\nYou entered: %s\n", input_buffer);
scanf("%s", input_buffer);
printf("You entered: %s\n", input_buffer);
int num1, num2;
printf("Enter num1: ");
scanf("%d", &num1);
printf("Enter num2: ");
scanf("%d", &num2);
printf("You entered: %d and %d\n", num1, num2);
// Infinite loop
while (1) {
__asm__ volatile("hlt");
+24 -25
View File
@@ -178,6 +178,17 @@ static inline int __put_char_VGA_POS(_VGA _c, _VGA_screen_space _position, int _
return written;
}
if (_c.codepoint == '\b') {
if (_position.column > 0) {
_position.column--;
vga[(_position.line * VGA_WIDTH) + _position.column].codepoint = ' ';
vga[(_position.line * VGA_WIDTH) + _position.column].color = _c.color;
}
text_pos.line = _position.line;
text_pos.column = _position.column;
return 1;
}
vga[(_position.line * VGA_WIDTH) + _position.column].codepoint = _c.codepoint;
vga[(_position.line * VGA_WIDTH) + _position.column].color = _c.color;
@@ -435,36 +446,14 @@ static inline char __convert_ascii(uint8_t __scancode) {
return __char;
}
uint8_t __scancode_h[128] = {0};
static uint32_t __total_isr_calls = 0;
void __keyboard_handle_scancode(uint8_t __scancode) {
__total_isr_calls++;
char __temp = __convert_ascii(__scancode);
static uint8_t __index = 0;
if (__index < sizeof(__scancode_h)) {
__scancode_h[__index++] = __scancode;
}
if (__temp == '\0') {
return;
}
__keyboard_buffer_push(__temp);
}
void __dump_scancode_history() {
printf("Scancode History: \n");
printf("Total ISR Calls: %u\n", __total_isr_calls);
for (size_t i = 0; i < sizeof(__scancode_h); i++) {
if (__scancode_h[i] != 0) {
printf("[%x] = %c\n", __scancode_h[i], __convert_ascii(__scancode_h[i]));
}
}
printf("\n");
}
static inline char __gets_internal(char *buffer, size_t max_length) {
size_t index = 0;
char __c;
@@ -477,10 +466,22 @@ static inline char __gets_internal(char *buffer, size_t max_length) {
}
if (__c == '\n' || __c == '\r') {
printf("\n");
buffer[index] = '\0';
break;
}
if (__c == '\b') {
if (index > 0) {
index--;
printf("\b \b");
scursor(text_pos.column, text_pos.line);
}
continue;
}
printf("%c", __c);
scursor(text_pos.column, text_pos.line);
buffer[index++] = __c;
}
@@ -492,9 +493,8 @@ void gets(char *buffer, size_t max_length) {
__gets_internal(buffer, max_length);
}
/*
static inline int __scanf_internal(const char *fmt, va_list args) {
scursor(text_pos.column, text_pos.line);
char buffer[256];
__gets_internal(buffer, sizeof(buffer));
@@ -559,6 +559,5 @@ int scanf(const char *fmt, ...) {
va_end(args);
return result;
}
*/
#endif