Kaynağa Gözat

svim can now go back in text and edit it

jorn_dev
Jørn Guldberg 5 yıl önce
ebeveyn
işleme
c6cf326c53
2 değiştirilmiş dosya ile 263 ekleme ve 107 silme
  1. +22
    -0
      lib/os_lib.nasm
  2. +241
    -107
      lib/svim.nasm

+ 22
- 0
lib/os_lib.nasm Dosyayı Görüntüle

@ -45,6 +45,28 @@ printALChar:
int 0x10
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print_reverse:
; Prints string in si
; IN bx: adress of string
; IN cx: length
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
add bx, cx
.printchar:
mov BYTE al, [bx] ; Load byte at address SI into AL, and increment SI
test al, al
jz .done ; If the character is zero (NUL), stop writing the string
cmp cx, 0
jz .done
int 0x10 ; Otherwise, print the character via 'int 0x10'
dec bx
dec cx
jmp .printchar ; Repeat for the next character
.done:
ret
; Changing the screen the user i looking at.
; value in 'al' is the screen we want to switch to.
; starting from 0x00

+ 241
- 107
lib/svim.nasm Dosyayı Görüntüle

@ -1,9 +1,17 @@
BITS 16
%define svim_starting_row_number_for_text 2
%define svim_end_row_number_for_text 24
%define svim_magic_buffer_size 2048
svim:
pusha ; save state before program
sub sp, svim_magic_buffer_size
mov [.buffer_for_svim_base], sp
mov [buffer_for_svim_base_left_of_cursor], sp
sub sp, svim_magic_buffer_size
mov [buffer_for_svim_base_right_of_cursor], sp
mov bx, sp
mov BYTE [bx], 0 ; be sure that the first byte is zero.
mov WORD [svim_counter_char_in_left_buffer], 0 ; reset these to zero
mov WORD [svim_counter_char_in_right_buffer], 0
call os_clear_screen
@ -13,10 +21,10 @@ svim:
mov dh, 0x00 ; row zero
mov dl, 0x17 ; coloumn zero
int 0x10
mov si, .welcome_svim_select_file
mov si, welcome_svim_select_file
call print
call printCRLF
mov si, .seperate_line
mov si, seperate_line
call print
call lsfs_list_files_command
@ -29,10 +37,10 @@ svim:
mov dl, 0x00 ; coloumn zero
int 0x10
mov si, .welcome_svim
mov si, welcome_svim
call print
call printCRLF
mov si, .welcome_svim_enter_fileindex
mov si, welcome_svim_enter_fileindex
call print
; Ask the user for the filename
@ -52,7 +60,7 @@ svim:
je .loop_no_push
pop cx
sub cx, 1
mov bx, [.buffer_for_svim_base]
mov bx, [buffer_for_svim_base_left_of_cursor]
add bx, cx
mov BYTE [bx], 0
; Go back one space
@ -74,7 +82,7 @@ svim:
mov ah, 0x0E
int 0x10 ; print char
pop cx
mov bx, [.buffer_for_svim_base]
mov bx, [buffer_for_svim_base_left_of_cursor]
add bx, cx
mov [bx], al
add cx, 1
@ -87,67 +95,63 @@ svim:
.fileindex_done:
pop cx ; Cleanup, and now contain filename size
mov ax, cx
add ax, [.buffer_for_svim_base]
add ax, [buffer_for_svim_base_left_of_cursor]
mov bx, ax
mov BYTE [bx], 0
mov si, [.buffer_for_svim_base]
mov si, [buffer_for_svim_base_left_of_cursor]
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
mov [fileindex_for_open_file], ax ; save the file index
call svim_redraw_window
; 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]
mov ax, [fileindex_for_open_file]
mov bx, [buffer_for_svim_base_left_of_cursor]
call lsfs_read_file
;mov bx, [.buffer_for_svim_base]
;mov bx, [buffer_for_svim_base_left_of_cursor]
;add bx, svim_magic_buffer_size - 2
;mov ax, [bx]
mov [.buffer_counter_svim], ax
mov [svim_counter_char_in_left_buffer], ax
;mov [svim_counter_char_in_left_buffer], ax
; print buffer
mov si, [.buffer_for_svim_base]
mov es, si
call print
;mov si, [buffer_for_svim_base_left_of_cursor]
;mov es, si
;call print
.svim_loop:
; Redraw the whole text,
; move cursor to the top, where the text has to start (line 2)
xor ax, ax
xor bx, bx
mov ah, 0x02
mov bh, 0x00 ; page number 0
mov dh, 0x02 ; row
mov dl, 0x00 ; coloumn
int 0x10
mov si, [buffer_for_svim_base_left_of_cursor]
call print
; Check if there is somthing to the right of the cursor that should be written to screen
mov cx, [svim_counter_char_in_right_buffer]
cmp cx, 0 ; Nothing to be written
je .no_write_right_of_the_cursor
call get_cursor_position
push dx
mov bx, [buffer_for_svim_base_right_of_cursor]
dec bx
mov cx, [svim_counter_char_in_right_buffer]
call print_reverse
pop dx
xor ax, ax
xor bx, bx
mov ah, 0x02
mov bx, 0x00 ; page zero
int 0x10
.no_write_right_of_the_cursor:
xor bx, bx
xor cx, cx
xor dx, dx
@ -155,26 +159,38 @@ svim:
int 0x16
cmp ax, 0x1c0d ; enter key
jne .no_enter
mov bx, [.buffer_for_svim_base]
add bx, [.buffer_counter_svim]
mov bx, [buffer_for_svim_base_left_of_cursor]
add bx, [svim_counter_char_in_left_buffer]
mov BYTE [bx], 13 ; put char in the buffer
mov BYTE [bx + 1], 10 ; put char in the buffer
mov bx, [.buffer_counter_svim]
mov bx, [svim_counter_char_in_left_buffer]
add bx, 0x02
mov [.buffer_counter_svim], bx
mov [svim_counter_char_in_left_buffer], bx
xor bx, bx
xor cx, cx
xor dx, dx
mov ax, 0x0e0d
int 0x10
mov ax, 0x0e0a
int 0x10
call svim_redraw_window
jmp .svim_loop
.no_enter:
cmp ax, 0x4be0 ; left key
jne .check_up_key
call handle_left_key_pressed
jmp .svim_loop
.check_up_key:
cmp ax, 0x48e0 ; up key
jne .check_right_key
jmp .svim_loop
.check_right_key:
cmp ax, 0x4de0 ; right key
jne .check_down_key
call handle_right_key_pressed
jmp .svim_loop
.check_down_key:
cmp ax, 0x50e0 ; down key
jne .no_arrow_key_pressed
jmp .svim_loop
.no_arrow_key_pressed:
cmp ax, 0x11b ; ESC key
je .end_svim
;cmp ax, 0x3c00 ; f2 key
@ -184,39 +200,40 @@ svim:
mov bx, ax
mov ax, 0xe20
mov al, bl
mov bx, [.buffer_for_svim_base]
add bx, [.buffer_counter_svim]
mov bx, [buffer_for_svim_base_left_of_cursor]
add bx, [svim_counter_char_in_left_buffer]
mov [bx], al ; put char in the buffer
mov bx, [.buffer_counter_svim]
mov bx, [svim_counter_char_in_left_buffer]
add bx, 0x01
mov [.buffer_counter_svim], bx
mov [svim_counter_char_in_left_buffer], bx
int 0x10 ; print char
jmp .svim_loop
.end_svim:
;mov bx, [.buffer_for_svim_base]
;mov bx, [buffer_for_svim_base_left_of_cursor]
;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]
mov ax, [fileindex_for_open_file]
mov bx, [buffer_for_svim_base_left_of_cursor]
mov cx, [svim_counter_char_in_left_buffer]
call lsfs_write_file
call os_clear_screen
add sp, svim_magic_buffer_size
add sp, svim_magic_buffer_size
popa
ret
.backspace_pushed:
mov bx, [.buffer_counter_svim]
mov bx, [svim_counter_char_in_left_buffer]
cmp bx, 0
je .svim_loop
mov cx, bx
sub cx , 1
mov bx, [.buffer_for_svim_base]
mov bx, [buffer_for_svim_base_left_of_cursor]
add bx, cx
.delete_linebreak:
@ -227,41 +244,28 @@ svim:
sub cx, 1 ; Substract one charecter from the buffer, CR and LF
sub bx, 1
mov BYTE [bx], 0
mov [.buffer_counter_svim], cx
; Redraw the whole text,
; move cursor to the top, where the text has to start (line 2)
xor ax, ax
xor bx, bx
mov ah, 0x02
mov bh, 0x00 ; page number 0
mov dh, 0x02 ; row
mov dl, 0x00 ; coloumn
int 0x10
mov si, [.buffer_for_svim_base]
call print
mov [svim_counter_char_in_left_buffer], cx
jmp .svim_loop
.delete_char:
mov BYTE [bx], 0
mov [.buffer_counter_svim], cx
mov [svim_counter_char_in_left_buffer], 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
;mov ax, 0x0e08 ; ah=0x0e means teletype output. al=0x08 means backspace character.
;int 0x10
; Place a NULL
mov al, 0x0 ; NULL
int 0x10
;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
;mov ax, 0x0e08
;int 0x10
call svim_redraw_window
jmp .svim_loop
;.f_key_pushed:
;mov al, 0x01 ;arg: index 1
;call os_change_screen
@ -269,11 +273,141 @@ svim:
;.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.10 - 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
handle_left_key_pressed:
mov ax, [svim_counter_char_in_left_buffer]
mov bx, [buffer_for_svim_base_left_of_cursor]
add bx, ax
dec bx ; Because it faces the next free spot
mov dx, [bx]
mov BYTE [bx], 0
push dx
mov cx, [svim_counter_char_in_right_buffer]
mov bx, [buffer_for_svim_base_right_of_cursor]
add bx, cx
mov [bx], dx
inc bx
mov BYTE [bx], 0 ; be sure that the next byte is always zero
dec ax
inc cx
mov [svim_counter_char_in_left_buffer], ax
mov [svim_counter_char_in_right_buffer], cx
pop bx
cmp bx, 10 ; check if we hit a line break.
jne .end
call handle_left_key_pressed ; we have hit a linebreak and need to go once more
.end:
ret
handle_right_key_pressed:
mov ax, [svim_counter_char_in_right_buffer]
cmp ax, 0 ; check if we have more on the right side of the buffer
je .end ; If we don't, jump to the end and do nothing.
mov bx, [buffer_for_svim_base_right_of_cursor]
add bx, ax
dec bx ; Because it faces the next free spot
mov dx, [bx]
mov BYTE [bx], 0
push dx
mov cx, [svim_counter_char_in_left_buffer]
mov bx, [buffer_for_svim_base_left_of_cursor]
add bx, cx
mov [bx], dx
inc bx
mov BYTE [bx], 0 ; be sure that the next byte is always zero
dec ax
inc cx
mov [svim_counter_char_in_right_buffer], ax
mov [svim_counter_char_in_left_buffer], cx
pop bx
cmp bx, 13 ; check if we hit a line break.
jne .end
call handle_right_key_pressed ; we have hit a linebreak and need to go once more
.end:
ret
get_cursor_position:
xor ax, ax
xor bx, bx
mov ah, 0x03
mov bh, 0x00 ; page number 0
int 0x10
ret
svim_get_end_of_line_count:
pusha
xor ax, ax ; Number of chars in the right side buffer
xor cx, cx ; This is our counter to the next line break
mov ax, [svim_counter_char_in_right_buffer]
mov bx, buffer_for_svim_base_right_of_cursor
.check_next:
cmp ax, 0 ; No more chars to check, we have hit the end of the last line
je .end
cmp BYTE [bx], 13 ; See if we have hit an linebreak
je .end_procedure
sub ax, 1 ; substract one for the numbers of element that we are looking at
inc bx ; add one the our buffer to look at the next element
inc cx
.end_procedure:
mov [svim_get_cursor_distance_to_next_line_break], cx
.end:
popa
ret
svim_redraw_window:
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
ret
svim_get_cursor_offset_on_current_line dw 0
svim_get_cursor_distance_to_next_line_break dw 0
buffer_for_svim_base_left_of_cursor dw 0
buffer_for_svim_base_right_of_cursor dw 0
svim_counter_char_in_left_buffer dw 0
svim_counter_char_in_right_buffer dw 0
seperate_line db '________________________________________________________________________________', 0
welcome_svim db 'Vim like text editor for SingOS, ESC to exit', 0
welcome_svim_select_file db 'svim v0.0.27 - Open file: ', 0
welcome_svim_enter_fileindex db 'Enter fileindex: ', 0
fileindex_for_open_file dw 0
svim_total_file_size_counter dw 0

Yükleniyor…
İptal
Kaydet