Sfoglia il codice sorgente

Trying to fix svim when up key ispressed

jorn_dev
Jørn Guldberg 5 anni fa
parent
commit
525c2be522
2 ha cambiato i file con 59 aggiunte e 17 eliminazioni
  1. +1
    -1
      bootloader.nasm
  2. +58
    -16
      lib/svim.nasm

+ 1
- 1
bootloader.nasm Vedi File

@ -31,7 +31,7 @@ start:
mov si, enter_debug_mode
call print
call printCRLF
%IF 1
%IF 0
; here goes wait call, for the user to enter debug mode.
; Wating for 2 seconds:
mov ah, 0x86 ; code for waiting interupt call

+ 58
- 16
lib/svim.nasm Vedi File

@ -12,6 +12,7 @@ svim:
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
mov WORD [svim_get_cursor_distance_to_next_line_break], 0
call os_clear_screen
@ -114,6 +115,7 @@ svim:
;add bx, svim_magic_buffer_size - 2
;mov ax, [bx]
mov [svim_counter_char_in_left_buffer], ax
;mov [svim_counter_char_in_left_buffer], ax
; print buffer
;mov si, [buffer_for_svim_base_left_of_cursor]
@ -178,7 +180,7 @@ svim:
.check_up_key:
cmp ax, 0x48e0 ; up key
jne .check_right_key
call handle_up_key_pressed
jmp .svim_loop
.check_right_key:
cmp ax, 0x4de0 ; right key
@ -275,7 +277,10 @@ svim:
handle_left_key_pressed:
pusha
mov ax, [svim_counter_char_in_left_buffer]
cmp ax, 0
je .end
mov bx, [buffer_for_svim_base_left_of_cursor]
add bx, ax
dec bx ; Because it faces the next free spot
@ -299,10 +304,11 @@ handle_left_key_pressed:
jne .end
call handle_left_key_pressed ; we have hit a linebreak and need to go once more
.end:
popa
ret
handle_right_key_pressed:
pusha
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.
@ -329,8 +335,41 @@ handle_right_key_pressed:
jne .end
call handle_right_key_pressed ; we have hit a linebreak and need to go once more
.end:
popa
ret
handle_up_key_pressed:
call get_cursor_position ; Find the position of the cursor
xor cx, cx
mov cl, dl ; Store coulun count
inc cx
push cx ; save the column count.
.find_first_line_break:
cmp BYTE cl, 0
je .find_right_position_on_new_line
call handle_left_key_pressed
dec cl
jmp .find_first_line_break
.find_right_position_on_new_line:
call svim_get_left_line_count ; updates the value in svim_get_cursor_distance_to_next_line_break
mov ax, [svim_get_cursor_distance_to_next_line_break]
call dumpax
pop cx
.move_curser_to_correct_position_on_the_new_line:
cmp cx, ax
jge .end
call handle_left_key_pressed
dec ax
jmp .move_curser_to_correct_position_on_the_new_line
.end:
ret
handle_down_key_pressed:
ret
get_cursor_position:
xor ax, ax
xor bx, bx
@ -339,24 +378,27 @@ get_cursor_position:
int 0x10
ret
svim_get_end_of_line_count:
svim_get_left_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
mov ax, [svim_counter_char_in_left_buffer]
mov bx, buffer_for_svim_base_left_of_cursor
add bx, ax
.check_next:
cmp ax, 0 ; check if we have hit the absolut beginnig of the string
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
mov BYTE dl, [bx]
cmp BYTE dl, 13 ; See if we have hit an linebreak
je .end_line_break
dec bx ; dec one, to check the prev char, until we hit a line break.
dec ax
inc cx ; add one to the counter
jmp .check_next
.end_line_break:
inc cx ; add one to the counter
.end:
mov WORD [svim_get_cursor_distance_to_next_line_break], cx
popa
ret
@ -407,7 +449,7 @@ 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_select_file db 'svim v0.0.28 - Open file: ', 0
welcome_svim_enter_fileindex db 'Enter fileindex: ', 0
fileindex_for_open_file dw 0
svim_total_file_size_counter dw 0

Caricamento…
Annulla
Salva