; || $AX || BITS 16 ORG 7168 ; ------------------------------ ; ## FUNCTION CALLS ## boot_start equ 0000h ; Generally not used, completely restarts the OS start equ 0003h ; Generally not used, allows user to start a program one layer down print_string equ 0006h ; Prints a zero terminated string to the screen read_file equ 0009h ; Allows user to load a program from disk to RAM using a filename write_file equ 000Ch ; Allows user to load a program from RAM to disk using a filename disk_manage equ 000Fh ; Allows for custom use of the disk - USE WITH CARE! get_key_press equ 0012h ; Waits for the user to press a key and returns it get_string_and_print equ 0015h ; Gets a string of maximum length from the user and returns it string_compare equ 0018h ; Compares two strings and tells the user if they are equal error equ 001Bh ; Prints an OS error to the screen. If jumped to this will also exit ; the user from the program find_file equ 001Eh ; Searches for a file in the file table and returns whether it was ; found or not write_allocation_table equ 0021h ; Places a filename in a position that corresponds to a given sector print_char equ 0024h ; Prints a single character to the screen remove_file equ 0027h ; Allows for a given filename to deleted from the file allocation ; table. Note the contents remain until over-written ; ------------------------------ ; ## MAIN CODE ## main: add si, length_of_edit + 1 .param: cmp byte [si], '-' jne edit_file inc si ; Check next position for parameter letter .test: cmp byte [si], 'h' je print_help cmp byte [si], 'v' je print_version jmp error ; ------------------------------ edit_file: mov bx, si call make_file_blank mov si, file cmp byte [bx], 0 je display ; Check if there is a file being loaded call read_file display: call clear_screen mov dx, 100h call set_cursor_pos mov dx, -1 mov si, file .print_file: cmp si, file + size_of_file ; End of file? jge editing_loop cmp si, word [current] je .store_cursor_pos .print_char_continue: cmp dx, -1 ; Have we found our cursor? je .print ; If not keep printing push dx call get_cursor_pos mov ch, dh pop dx cmp ch, 24 ; Are we at bottom of screen? jl .print lodsb ; Simulate print cmp al, 0 jne .possible_end_2 jmp .print_file .print: lodsb call print_char .skip_print: cmp al, 0 jne .possible_end .print_char_display: cmp al, 13 jne .print_file mov al, 10 call print_char jmp .print_file .store_cursor_pos: call get_cursor_pos ; Get current cursor pos and store in DX jmp .print_char_continue .possible_end: mov word [last], si jmp .print_char_display .possible_end_2: mov word [last], si jmp .print_file editing_loop: push dx mov dx, 0 call set_cursor_pos mov si, menu call print_string pop dx call set_cursor_pos ; Set our cursor to our editing point call get_key_press cmp al, 8 ; Check if backspace je backspace cmp ah, 59 ; Check if f1 je new_file ; f1 = New cmp ah, 60 ; Check if f2 je save_file ; f2 = Save cmp ah, 61 ; Check if f3 je .exit_prog ; f3 = Exit mov cx, 1 ; Reserved for left and right arrows cmp ah, 75 ; Left Arrow je left_arrow ; Move cursor left cmp ah, 77 ; Right Arrow je right_arrow ; Move cursor right mov cx, 8 ; Reserved for up and down arrows cmp ah, 72 ; Up Arrow je left_arrow ; Move cursor up cmp ah, 80 ; Down Arrow je right_arrow ; Move cursor down cmp al, 0 je display ; Some unsupported char pressed ;If one of these cases isn't true then print ;a character to RAM and screen jmp print_char_to_file jmp display .exit_prog: call clear_screen ret ; ------------------------------ ; ## USER INPUT CALLS ## backspace: cmp word [current], file jle display ; Don't delete more that start of file call shift_left dec word [current] ; We are now further left jmp display print_char_to_file: cmp word [last], file + size_of_file jge display ; Don't add more bytes than available call shift_right mov di, word [current] stosb mov cx, 1 right_arrow: mov ax, file + size_of_file + 1 sub ax, cx cmp word [current], ax jge .done add word [current], cx .done: jmp display left_arrow: mov ax, file - 1 add ax, cx cmp word [current], ax jle .done sub word [current], cx .done: jmp display shift_right: push ax mov si, file + size_of_file - 1 mov di, si inc di std .repeat: cmp si, word [current] jl .done lodsb stosb jmp .repeat .done: cld pop ax ret shift_left: push ax mov si, word [current] mov di, si dec di .repeat: cmp si, file + size_of_file + 1 jge .done lodsb stosb jmp .repeat .done: pop ax ret ; ------------------------------ ; ## DISK CALLS ## ; ------------------------------ new_file: call make_file_blank jmp display ; ------------------------------ save_file: mov dx, 30 call set_cursor_pos mov si, prompt call print_string mov bl, 4 ; Set length of String call get_string_and_print mov bx, sys_vars mov si, file call write_file jmp display ; ------------------------------ make_file_blank: ; IN: OUT: USED: AL, CX, SI mov al, 0 ; Fill with zeros mov cx, size_of_file + 1; Do for size of file plus one (safety) mov di, file rep stosb mov word [current], file; Make cursor point at start ret ; ------------------------------ print_help: mov si, help jmp print_string ; ------------------------------ print_version: mov si, version jmp print_string ; ------------------------------ ; ## SCREEN CALLS ## get_cursor_pos: ; IN: OUT: DL=COL DH=ROW CL=END CH=START USED: DX, CX push ax mov ah, 03h ; Mode (Get Cursor Position) jmp cursor_pos_manager set_cursor_pos: ; IN: DL=COL DH=ROW OUT: USED: DX push ax mov ah, 02h ; Mode (Set Cursor Position) cursor_pos_manager: push bx mov bx, 0 ; Page number int 10h pop bx pop ax ret clear_screen: mov dx, 0 call set_cursor_pos ; DX is set to zero by the clear screen mov al, ' ' mov ah, 0Ah mov bh, 0 mov cx, 2000 int 10h ret ; ------------------------------ ; ## VARIABLES ## menu db 'f1=New f2=Sve f3=Ext', 0 version db 10, 13, 'ver 6' last dw 0 ; Last position in file help db 10, 13, 'Edit [file]' help2 db 10, 13, '-h Help' help3 db 10, 13, '-v Version' startln db 0 ; Line to be printed at the top of the screen prompt db 'File:', 0 current dw file ; Current position in file sys_vars equ 512 ; Location of system variables file_table equ 1024 ; Location of File Table filename_size equ 4 length_of_edit equ 4 ; The length of the Filename 'ls' size_of_file equ 512 ; ## SIGNATURE ## times 510-($-$$)db 0 ; Pad remainder of boot sector with zeros dw 02486h ; Boot signature (DO NOT CHANGE!) file: