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.
 
 

192 lines
4.9 KiB

BITS 16
svim:
pusha ; save state before program
;mov si, .os_clear_screen_str
;call print
xor bx, bx
mov [.buffer_counter_svim], bx
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
mov ax, 0x10 ; BIOS call to wait for key
int 0x16
cmp ax, 0x1c0d ; enter key
je .fileindex_done
.no_enter:
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
add cx, .buffer_for_svim
mov bx, cx
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
xor bx, bx
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
; move cursor back up to the top
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 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, 0x00 ;Drive number
int 0x13
; 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_fileindex
call printCRLF
jmp .svim_loop
.no_enter_fileindex:
cmp ax, 0x11b ; ESC key
je .end_svim
cmp ax, 0x3c00 ; f2 key
je .f_key_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 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, 0x0 ;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
; Move curser back to the top of the screen
mov ah, 0x02
mov bh, 0x00 ; page number 0
mov dh, 0x00 ; row zero
mov dl, 0x00 ; coloumn zero
int 0x10
popa
ret
.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