BITS 16 ;CLI ;Command syntax: ;Argument must not contain spaces. ; Data CLI_Command_Buffer times 256 db 0 CLI_Command_Length dw 0 ; API ; args: ; ax: keyboard keycode. CLI_ASCII_INPUT: pusha ; Fetch command buffer offset. ; If there is no room in the buffer, then just bail on the key press. mov bx, [CLI_Command_Length] cmp bx, 255 je .end inc bx ; The new last element will be located at this offset. mov [CLI_Command_Length], bx ; Save the new counter. dec bx ; Go back to the index the character should be written to. ; Move new ascii character into command buffer. add bx, CLI_Command_Buffer ; address+offset = destination mov [bx], al inc bx mov byte [bx], 0 ; Print out the input character mov ah, 0xe ; Teletype output mov bl, 0x02 ; color (green) int 0x10 .end: popa ret ; args: CLI_DELETE: pusha ; Check if at the beginning of the line. mov bx, [CLI_Command_Length] cmp bx, 0x00 je .end ; Move the counter one back sub bx, 0x01 mov [CLI_Command_Length], bx ;Move NULL into the last character of the line (delete) mov al, 0x0 add bx, CLI_Command_Buffer ; address+offset = destination mov [bx], al ; Go back one space mov ax, 0x0e08 ; ah=0x0e means teletype output. al=0x08 means backspace character. int 0x10 ; Place a NULL mov al, 0x0 ; NULL int 0x10 ; Go back one space again as the above print of NULL pushes the cursor forward again. mov ax, 0x0e08 int 0x10 .end: popa ret ; Probably activated with the 'Enter' button. CLI_CONFIRM_INPUT: call CLI_EXECUTE mov bx, 0 mov [CLI_Command_Length], bx mov [CLI_Command_Buffer], bx ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; print_help_message: ; Prints a list of available commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; push si mov si, .command_list_string call print pop si ret .command_list_string: db 13, 10 db "Available commands:", 13, 10 db " help: Prints this screen", 13, 10 db " dumpmem: Prints the contents of a memory region (At the moment hardcoded)", 13, 10 db " keyprint: Prints the character and keycode for a key presssd", 13, 10 db " clear: Clears the screen", 13, 10 db " formatdisk: Initialize the file system", 13, 10 db " createfile: Name a file, in the file system", 13, 10 db " fsinfo: Displays info about the file system", 13, 10 db " ls: Lists the named files", 13, 10 db " svim: SingOS' text editor", 13, 10, 0 ; Executes the command. CLI_EXECUTE: pusha mov bx, [CLI_Command_Length] cmp bx, 0 je near .end ; If there are not bytes in the buffer then there is no command. mov ax, [.Num_Commands] ; The number of commands available. lea si, [CLI_Command_Buffer] mov cx, 0 ; Index into the list of commands. .Interpreter_Search_Commands_Loop: ;cmp cx, ax ; Start by comparing. ;je .end mov bx, cx ; Move Index into bx to offset into the array of commands. add bx, bx ; The pointers are two bytes long. This compensates for that. mov bx, [.Command_Name_List + bx] ; Fetch the pointer for the string. lea di, [bx] call stringcompare je .Interpreter_Command_Execute inc cx ; Prepare for next iteration. cmp ax, cx je .end jmp .Interpreter_Search_Commands_Loop .Interpreter_Command_Execute: mov bx, cx ; Move Index into bx to offset into the array of commands. add bx, bx ; The pointers are two bytes long. This compensates for that. pusha call printCRLF popa mov dx, [.Command_Function_Pointers + bx] ; Program pointer ; Execute program. call dx .end: popa ret .tmp dw 0 .Num_Commands dw 9 .Command_Name_List dw .CMD1, .CMD2, .CMD3, .CMD4, .CMD5, .CMD6, .CMD7, .CMD8, .CMD9 .Command_Function_Pointers dw dumpmem_hardcoded_args, keyprint, svim, vsfs_list_files_command, vsfs_create_file, vsfs_format_disk, vsfs_get_fs_info, os_clear_screen, print_help_message .CMD1 db 'dumpmem', 0 .CMD2 db 'keyprint', 0 .CMD3 db 'svim', 0 .CMD4 db 'ls', 0 .CMD5 db 'createfile', 0 .CMD6 db 'formatdisk', 0 .CMD7 db 'fsinfo', 0 .CMD8 db 'clear', 0 .CMD9 db 'help', 0