BITS 16 %define svim_magic_buffer_size 2048 svim: pusha ; save state before program sub sp, svim_magic_buffer_size mov [.buffer_for_svim_base], sp call os_clear_screen xor bx, bx mov ah, 0x02 mov bh, 0x00 ; page number 0 mov dh, 0x00 ; row zero mov dl, 0x17 ; coloumn zero int 0x10 mov si, .welcome_svim_select_file call print call printCRLF mov si, .seperate_line call print call lsfs_list_files_command ; move cursor to the bootom xor ax, ax xor bx, bx mov ah, 0x02 mov bh, 0x00 ; page number 0 mov dh, 0x17 ; row zero mov dl, 0x00 ; coloumn zero int 0x10 mov si, .welcome_svim call print call printCRLF mov si, .welcome_svim_enter_fileindex call print ; Ask the user for the filename xor bx, bx xor cx, cx ; are going to be the counter xor dx, dx .enter_fileindex_loop: push cx .loop_no_push: mov ax, 0x10 ; BIOS call to wait for key int 0x16 cmp ax, 0x1c0d ; enter key je .fileindex_done cmp ax, 0x0e08 ; backspace jne .no_enter_fileindex cmp cx, 0 je .loop_no_push pop cx sub cx, 1 mov bx, [.buffer_for_svim_base] add bx, cx mov BYTE [bx], 0 ; 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 jmp .enter_fileindex_loop .no_enter_fileindex: mov bh, 0x00 mov bl, 0x02 mov ah, 0x0E int 0x10 ; print char pop cx mov bx, [.buffer_for_svim_base] add bx, cx mov [bx], al add cx, 1 ; fileindex must only be 120 chars cmp cx, 120 jae .fileindex_done jmp .enter_fileindex_loop .fileindex_done: pop cx ; Cleanup, and now contain filename size mov ax, cx add ax, [.buffer_for_svim_base] mov bx, ax mov BYTE [bx], 0 mov si, [.buffer_for_svim_base] call zstring_to_integer ; ax now contain the interger index for the file mov [.fileindex_for_open_file], ax ; save the file index call os_clear_screen ; move cursor to the bootom xor ax, ax xor bx, bx mov ah, 0x02 mov bh, 0x00 ; page number 0 mov dh, 0x17 ; row zero mov dl, 0x00 ; coloumn zero int 0x10 mov si, .seperate_line call print mov si, .welcome_svim call print ; move cursor to the top xor ax, ax xor bx, bx mov ah, 0x02 mov bh, 0x00 ; page number 0 mov dh, 0x00 ; row zero mov dl, 0x00 ; coloumn zero int 0x10 ; Load from disk and, enter it, into the buffer mov si, .welcome_svim_select_file call print mov ax, [.fileindex_for_open_file] call dumpax10 call printCRLF mov si, .seperate_line call print ; LOAD FILE ; Prepare to ask the filesystem to load the file ; The file system should be given the file_id and the buffer where we can write mov ax, [.fileindex_for_open_file] mov bx, [.buffer_for_svim_base] call lsfs_read_file ;mov bx, [.buffer_for_svim_base] ;add bx, svim_magic_buffer_size - 2 ;mov ax, [bx] mov [.buffer_counter_svim], ax ; print buffer mov si, [.buffer_for_svim_base] mov es, si call print .svim_loop: xor bx, bx xor cx, cx xor dx, dx mov ax, 0x1000 ; BIOS call to wait for key int 0x16 cmp ax, 0x1c0d ; enter key jne .no_enter mov bx, [.buffer_for_svim_base] add bx, [.buffer_counter_svim] mov BYTE [bx], 13 ; put char in the buffer mov BYTE [bx + 1], 10 ; put char in the buffer mov bx, [.buffer_counter_svim] add bx, 0x02 mov [.buffer_counter_svim], bx xor bx, bx xor cx, cx xor dx, dx mov ax, 0x0e0d int 0x10 mov ax, 0x0e0a int 0x10 jmp .svim_loop .no_enter: cmp ax, 0x11b ; ESC key je .end_svim ;cmp ax, 0x3c00 ; f2 key ;je .f_key_pushed cmp ax, 0x0e08 ; backspace je .backspace_pushed mov bx, ax mov ax, 0xe20 mov al, bl mov bx, [.buffer_for_svim_base] add bx, [.buffer_counter_svim] mov [bx], al ; put char in the buffer mov bx, [.buffer_counter_svim] add bx, 0x01 mov [.buffer_counter_svim], bx int 0x10 ; print char jmp .svim_loop .end_svim: ;mov bx, [.buffer_for_svim_base] ;add bx, svim_magic_buffer_size - 2 ;mov [bx], ax mov ax, [.fileindex_for_open_file] mov bx, [.buffer_for_svim_base] mov cx, [.buffer_counter_svim] call lsfs_write_file call os_clear_screen add sp, svim_magic_buffer_size popa ret .backspace_pushed: mov bx, [.buffer_counter_svim] cmp bx, 0 je .svim_loop ;print_format .debug_buffer_counter, bx mov cx, bx sub cx, 1 mov bx, [.buffer_for_svim_base] add bx, cx mov BYTE [bx], 0 mov [.buffer_counter_svim], cx ;print_format .debug_buffer_counter, cx ; 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 jmp .svim_loop ;.f_key_pushed: ;mov al, 0x01 ;arg: index 1 ;call os_change_screen ;jmp .svim_loop ;.load_buffer_svim: .debug_buffer_counter db 'Buffer count: %d', 13, 10, 0 .welcome_svim db 'Vim like text editor for SingOS, ESC to exit', 0 .welcome_svim_select_file db 'svim v0.0.5 - Open file: ', 0 .welcome_svim_enter_fileindex db 'Enter fileindex: ', 0 .seperate_line db '________________________________________________________________________________', 0 .fileindex_for_open_file dw 0 .buffer_for_svim_base dw 0 .buffer_counter_svim dw 0