You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

235 lines
5.8 KiB

BITS 16
svim:
pusha ; save state before program
;mov si, .os_clear_screen_str
;call print
xor bx, bx
call os_clear_screen
;xor cx, cx ; Upper and left coordinate
;mov bh, 0x0a ; color for new screen 0 = black a = light green
;mov dh, 0xff ; Select all screen
;mov dl, 0xff ; Select all screen
;mov ah, 0x07 ; scrool down
;mov al, 0x00 ; scrool 0 lines (means blank screen )
;int 0x10
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
call vsfs_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
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
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
mov bx, ax
mov BYTE [bx], 0
mov si, .buffer_for_svim
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
; Load from disk and, enter it, into the buffer
mov ax, [.fileindex_for_open_file]
mov ch, al ; move the fileindex in the ch
mov bx, ds
mov es, bx
xor bx, bx
mov bx, .buffer_for_svim
xor ax, ax
mov ah, 0x02 ;Read sectors from drive
mov al, 0x01 ;Number of sectors to read (8 * 512 = 4096 bytes)
mov cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov dh, 0x00 ;Head number
mov dl, [global_disk_identifier] ;Drive number
int 0x13
mov bx, .fileindex_for_open_file
add bx, 510
mov ax, [bx]
mov [.buffer_counter_svim], ax
; print buffer
mov si, .buffer_for_svim
mov es, si
call print
.svim_loop:
mov ax, 0x1000 ; BIOS call to wait for key
int 0x16
cmp ax, 0x1c0d ; enter key
jne .no_enter
call printCRLF
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
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:
; save the written buffer
;AH 03h
;AL Sectors To Write Count
;CH Track
;CL Sector
;DH Head
;DL Drive
;ES:BX Buffer Address Pointer
mov ax, [.buffer_counter_svim]
mov bx, .fileindex_for_open_file
add bx, 510
mov [bx], ax
mov bx, ds
mov es, bx
mov bx, .buffer_for_svim
mov ax, [.fileindex_for_open_file]
mov ch, al ; move the fileindex in the ch
mov ah, 0x03 ;Write sectors to drive
mov al, 0x01 ;Number of sectors to write (8 * 512 = 4096 bytes)
mov cl, 0x01 ;First sector to read (bits 0-5), upper bits of cylinder (bits 6-7)
mov dh, 0x00 ;Head number
mov dl, [global_disk_identifier] ;Drive number
int 0x13 ;Low level disk services
; clean up swim
;xor bx, bx
;xor cx, cx ; Upper and left coordinate
;mov bh, 0x0f ; color for new screen 0 = black f = white
;mov dh, 0xff ; Select all screen
;mov dl, 0xff ; Select all screen
;mov ah, 0x07 ; scrool down
;mov al, 0x00 ; scrool 0 lines (means blank screen )
;int 0x10
call os_clear_screen
popa
ret
.backspace_pushed:
pusha
mov bx, [.buffer_counter_svim]
cmp bx, 0
je .svim_loop
mov cx, bx
sub cx, 1
mov bx, .buffer_for_svim
add bx, cx
mov BYTE [bx], 0
mov [.buffer_counter_svim], 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
popa
jmp .svim_loop
.f_key_pushed:
mov al, 0x01 ;arg: index 1
call os_change_screen
jmp .svim_loop
;.load_buffer_svim:
.welcome_svim db 'Vim like text editor for SingOS, ESC to exit', 0
.welcome_svim_select_file db 'svim - Open file', 0
.welcome_svim_enter_fileindex db 'Enter fileindex: ', 0
.fileindex_for_open_file dw 0
.buffer_for_svim times 512 dw 0 ; db 'this is the buffer', 0, times 32 db 0
.buffer_counter_svim dw 0