diff --git a/boot.asm b/boot.asm new file mode 100644 index 0000000..e8c3164 --- /dev/null +++ b/boot.asm @@ -0,0 +1,72 @@ +[bits 16] ; Set to 16-bit mode +[org 0x7C00] ; BIOS loads the bootloader at this address + +start: + ; Clear screen + mov ax, 0x0003 ; Set video mode to 3 (80x25 color text) + int 0x10 ; BIOS interrupt to set video mode + + ; Print welcome message + mov si, welcome_message + call print_string + +command_loop: + ; Print prompt + mov si, prompt_message + call print_string + + ; Read user input + call read_input + + ; Process command + cmp al, 'h' ; Check for 'h' command (help) + je print_help + cmp al, 'q' ; Check for 'q' command (quit) + je quit_terminal + + ; Unknown command response + mov si, unknown_command_message + call print_string + jmp command_loop ; Repeat the command loop + +print_help: + mov si, help_message + call print_string + jmp command_loop ; Return to command loop + +quit_terminal: + mov si, goodbye_message + call print_string + jmp hang ; Hang the system + +; Function to read a character from keyboard input +read_input: + mov ah, 0x00 ; BIOS function to read a character + int 0x16 ; Call BIOS interrupt + ret ; Return with character in AL + +; Function to print a string +print_string: + mov ah, 0x0E ; BIOS teletype output function +.next_char: + lodsb ; Load byte at DS:SI into AL and increment SI + cmp al, 0 ; Check for null terminator + je .done ; If null, we are done + int 0x10 ; Call BIOS to print character in AL + jmp .next_char ; Repeat for next character +.done: + ret ; Return from function + +; Data section for messages +welcome_message db 'Welcome to the Simple Terminal!', 0 +prompt_message db 'Enter command (h for help, q to quit): ', 0 +help_message db 'Available commands: h (help), q (quit)', 0 +unknown_command_message db 'Unknown command! Try again.', 0 +goodbye_message db 'Goodbye!', 0 + +; Bootloader signature (must be present) +times 510 - ($ - $$) db 0 ; Fill the rest of the sector with zeros +dw 0xAA55 ; Boot signature + +hang: + jmp hang ; Jump to hang indefinitely \ No newline at end of file