First commit
This commit is contained in:
commit
62e1d36c38
23 files changed
+2501
No files matched your search
@@ -0,0 +1,337 @@
|
||||
%macro print_format 1
|
||||
lea si, [%1]
|
||||
call _print_format
|
||||
%endmacro
|
||||
%macro print_format 2
|
||||
lea si, [%1]
|
||||
push %2
|
||||
call _print_format
|
||||
add sp, 2
|
||||
%endmacro
|
||||
%macro print_format 3
|
||||
lea si, [%1]
|
||||
push %3
|
||||
push %2
|
||||
call _print_format
|
||||
add sp, 4
|
||||
%endmacro
|
||||
%macro print_format 4
|
||||
lea si, [%1]
|
||||
push %4
|
||||
push %3
|
||||
push %2
|
||||
call _print_format
|
||||
add sp, 6
|
||||
%endmacro
|
||||
%macro print_format 5
|
||||
lea si, [%1]
|
||||
push %5
|
||||
push %4
|
||||
push %3
|
||||
push %2
|
||||
call _print_format
|
||||
add sp, 8
|
||||
%endmacro
|
||||
%macro print_format 6
|
||||
lea si, [%1]
|
||||
push %6
|
||||
push %5
|
||||
push %4
|
||||
push %3
|
||||
push %2
|
||||
call _print_format
|
||||
add sp, 10
|
||||
%endmacro
|
||||
%macro print_format 7
|
||||
lea si, [%1]
|
||||
push %7
|
||||
push %6
|
||||
push %5
|
||||
push %4
|
||||
push %3
|
||||
push %2
|
||||
call _print_format
|
||||
add sp, 12
|
||||
%endmacro
|
||||
|
||||
|
||||
BITS 16
|
||||
|
||||
dumpmem_hardcoded_args:
|
||||
mov si, sp
|
||||
mov si, [si]
|
||||
mov cx, 400
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
dumpmem:
|
||||
; Dumps memory
|
||||
; IN 'si': Start address to dump from
|
||||
; IN 'cx': Number of bytes do dump
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
pusha
|
||||
|
||||
xor edx, edx
|
||||
|
||||
.loop:
|
||||
mov ax, word [esi + 2*edx]
|
||||
inc edx
|
||||
call dumpax
|
||||
mov ax, (0xE<<8)|' ' ; print space
|
||||
int 0x10
|
||||
loop .loop
|
||||
.end:
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
dumpax:
|
||||
; Prints the contens of ax as a hexadecimal number
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
pusha ; save registers
|
||||
mov dx, ax
|
||||
mov ah, 0xE ; Teletype output
|
||||
|
||||
mov cx, 4 ; 4 nibbles in a 16 bit word
|
||||
.print_loop:
|
||||
rol dx, 4 ; rotate to next nibble
|
||||
mov al, dl ; we copy to al because we need to mask only the low 4 bits
|
||||
and al, 0xF ; Do the masking
|
||||
add al, '0' ; convert to ASCII
|
||||
|
||||
; If we are greater than 9 ascii...
|
||||
cmp al, '9'
|
||||
jbe .skip_diff_to_ascii_A
|
||||
add al, 'A'-('9'+1) ; ...add 7 to make digits 10 to 15 be represented as 'A' to 'F'
|
||||
.skip_diff_to_ascii_A:
|
||||
|
||||
int 0x10 ; BIOS call 'output'
|
||||
loop .print_loop
|
||||
|
||||
popa ; restore registers
|
||||
ret
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
dumpax10:
|
||||
; Prints the contens of ax as a decimal number
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
pusha
|
||||
|
||||
mov bx, 10 ; Divisor
|
||||
|
||||
xor cx, cx ; Digit count starts at 0
|
||||
|
||||
.loop_divide: ; finds digits and pushes them to stack
|
||||
test ax, ax
|
||||
jz .break_loop_divide
|
||||
xor dx, dx
|
||||
div bx ; dx = (dx:ax)%bx, ax = (dx:ax)/bx
|
||||
push dx
|
||||
inc cx ; Increase digit count
|
||||
jmp .loop_divide
|
||||
.break_loop_divide:
|
||||
|
||||
.loop_print:
|
||||
pop ax
|
||||
add al, '0' ; Convert to ascii
|
||||
mov ah, 0xE
|
||||
int 0x10
|
||||
loop .loop_print
|
||||
|
||||
popa
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
dumpax_char:
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
mov ah, 0xE
|
||||
int 0x10
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
keyprint:
|
||||
; Enters a loop where the keycode of each pressed key is printed
|
||||
; [ESC] exits the loop
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
pusha
|
||||
|
||||
mov si, .f_info
|
||||
call print
|
||||
|
||||
.keyprint_loop:
|
||||
mov ax, 0x1000 ; BIOS call to wait for key
|
||||
int 0x16
|
||||
|
||||
mov bx, ax ; Save KeyCode in bx
|
||||
|
||||
print_format .f, ax, ax
|
||||
|
||||
cmp bx, 0x011B ; ESC key
|
||||
je .break_keyprint_loop
|
||||
|
||||
jmp .keyprint_loop
|
||||
.break_keyprint_loop:
|
||||
|
||||
popa
|
||||
ret
|
||||
.f_info: db 13, 10, "Press keys to see their keycodes.",13,10,"Press [ESC] to exit.", 13, 10, 0
|
||||
.f: db "(%c: %x)", 13, 10, 0
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
dump_stack_registers:
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
push si
|
||||
print_format .format_string, sp, bp
|
||||
pop si
|
||||
ret
|
||||
.format_string: db "StackRegisters(SP:%x BP:%x)", 0
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
dump_general_registers:
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
push si
|
||||
print_format .format_string, ax, cx, dx, bx, si, di
|
||||
pop si
|
||||
ret
|
||||
.format_string: db "GeneralRegisters(ax:%x cx:%x dx:%x bx:%x si:%x di:%x)", 0
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
dump_segment_registers:
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
push si
|
||||
print_format .format_string, ss, cs, ds, es, fs, gs
|
||||
pop si
|
||||
ret
|
||||
.format_string: db "SegmentRegisters(Stack:%x Code:%x Data:%x Extra:%x F:%x G:%x)", 0
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
_print_format:
|
||||
; IN: variable number of 16-bit numbers on stack
|
||||
; IN: 'si' points to beginning of format string with the following format:
|
||||
; %x in string replaced with hexadecimal representation
|
||||
; %d in string replaced with decimal representation
|
||||
; %% in string replaced with literal % sign
|
||||
;
|
||||
; EXAMPLE call:
|
||||
; push word 1337
|
||||
; push word 0xbeef
|
||||
; push word 0xdead
|
||||
; lea si, [.FORMAT]
|
||||
; call print_format ; output: "(DEAD-BEEF){1337} 100%"
|
||||
; add sp, 6
|
||||
; (...)
|
||||
; .FORMAT: db "(%x-%x){%d} 100%%",0
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
push bp
|
||||
mov bp, sp
|
||||
pushf
|
||||
pusha
|
||||
|
||||
lea bp, [bp+4]
|
||||
|
||||
.outer_loop:
|
||||
mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
|
||||
|
||||
.print_loop:
|
||||
lodsb ; al = *si++
|
||||
cmp al, '%'
|
||||
je .break_print
|
||||
test al, al
|
||||
jz .break_outer
|
||||
int 0x10
|
||||
jmp .print_loop
|
||||
.break_print:
|
||||
|
||||
lodsb
|
||||
cmp al, 'x'
|
||||
je .format_hex
|
||||
cmp al, 'd'
|
||||
je .format_dec
|
||||
cmp al, 'c'
|
||||
je .format_char
|
||||
cmp al, '%'
|
||||
je .print_literal_percent
|
||||
|
||||
.format_hex:
|
||||
lea cx, [dumpax]
|
||||
jmp .print_ax
|
||||
.format_dec:
|
||||
lea cx, [dumpax10]
|
||||
jmp .print_ax
|
||||
.format_char:
|
||||
lea cx, [dumpax_char]
|
||||
|
||||
.print_ax:
|
||||
mov ax, [bp]
|
||||
lea bp, [bp+2]
|
||||
call cx
|
||||
jmp .outer_loop
|
||||
|
||||
.print_literal_percent:
|
||||
mov ax, (0xE<<8)|'%'
|
||||
int 0x10
|
||||
jmp .outer_loop
|
||||
.break_outer:
|
||||
|
||||
popa
|
||||
popf
|
||||
pop bp
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
dump_dx_as_two_chars:
|
||||
; IN dh: first char
|
||||
; IN dl: second char
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
push ax
|
||||
mov ah, 0xE
|
||||
mov al, dh
|
||||
int 0x10
|
||||
mov al, dl
|
||||
int 0x10
|
||||
pop ax
|
||||
ret
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
dump_status_flags:
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
pushf
|
||||
push si
|
||||
push ax
|
||||
push bx
|
||||
|
||||
lahf
|
||||
mov bl, ah
|
||||
|
||||
lea si, [.flags_string]
|
||||
|
||||
mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
|
||||
|
||||
.outer_loop:
|
||||
; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
|
||||
.print_loop:
|
||||
lodsb ; Load byte at address SI into AL, and increment SI
|
||||
cmp al, '%'
|
||||
je .break_print_loop ; If the character is zero (NUL), stop writing the string
|
||||
test al, al
|
||||
jz .break_outer_loop
|
||||
int 0x10 ; Otherwise, print the character via 'int 0x10'
|
||||
jmp .print_loop ; Repeat for the next character
|
||||
.break_print_loop:
|
||||
|
||||
ror bl, 1
|
||||
mov al, bl
|
||||
and al, 1
|
||||
add al, '0'
|
||||
int 0x10
|
||||
jmp .outer_loop
|
||||
|
||||
.break_outer_loop:
|
||||
|
||||
pop bx
|
||||
pop ax
|
||||
pop si
|
||||
popf
|
||||
ret
|
||||
.flags_string: db "Flags(Sign:% Zero:% ?:% Adjust:% ?:% Parity:% ?:% Carry:%)", 0
|
||||
@@ -0,0 +1,72 @@
|
||||
BITS 16
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
print:
|
||||
; Prints string in si
|
||||
; IN si: zero terminated string to print
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
mov ah, 0xE ; Specify 'int 0x10' 'teletype output' function
|
||||
; [AL = Character, BH = Page Number, BL = Colour (in graphics mode)]
|
||||
.printchar:
|
||||
lodsb ; 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
|
||||
int 0x10 ; Otherwise, print the character via 'int 0x10'
|
||||
jmp .printchar ; Repeat for the next character
|
||||
.done:
|
||||
ret
|
||||
|
||||
printCRLF:
|
||||
mov ah, 0xE
|
||||
mov al, 13
|
||||
int 0x10
|
||||
mov al, 10
|
||||
int 0x10
|
||||
ret
|
||||
|
||||
printSpace:
|
||||
mov ax, 0xE20
|
||||
int 0x10
|
||||
ret
|
||||
|
||||
printALChar:
|
||||
mov ah, 0xE
|
||||
mov bl, 0x02 ;color
|
||||
int 0x10
|
||||
ret
|
||||
|
||||
; Changing the screen the user i looking at.
|
||||
; value in 'al' is the screen we want to switch to.
|
||||
; starting from 0x00
|
||||
os_change_screen:
|
||||
; Here the addresses for the screens stack
|
||||
; and base pointer has to be set.
|
||||
mov ah, 0x05
|
||||
int 0x10
|
||||
ret
|
||||
|
||||
os_clear_screen:
|
||||
pusha
|
||||
; move cursor to the bootom
|
||||
xor ax, ax
|
||||
xor bx, bx
|
||||
mov ah, 0x02
|
||||
mov bh, 0x00 ; page number 0
|
||||
mov dh, 0x18 ; row zero
|
||||
mov dl, 0x00 ; coloumn zero
|
||||
int 0x10
|
||||
xor cx, cx
|
||||
.loop:
|
||||
call printCRLF
|
||||
add cx, 1
|
||||
cmp cx, 0x19 ; until blank screen
|
||||
jne .loop
|
||||
; 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
|
||||
@@ -0,0 +1,39 @@
|
||||
BITS 16
|
||||
; THIS LIBARY IS IN REALLY BAD SHAPE
|
||||
; Power_off is okay to use
|
||||
|
||||
power_check:
|
||||
;perform an installation check
|
||||
mov ah,53h ;this is an APM command
|
||||
mov al,00h ;installation check command
|
||||
xor bx,bx ;device id (0 = APM BIOS)
|
||||
int 15h ;call the BIOS function through interrupt 15h
|
||||
call printCRLF
|
||||
call dumpax
|
||||
;jc APM_error ;if the carry flag is set there was an error
|
||||
;the function was successful
|
||||
;AX = APM version number
|
||||
;AH = Major revision number (in BCD format)
|
||||
;AL = Minor revision number (also BCD format)
|
||||
;BX = ASCII characters "P" (in BH) and "M" (in BL)
|
||||
;CX = APM flags (see the official documentation for more details)
|
||||
ret
|
||||
|
||||
power_enable:
|
||||
;Enable power management for all devices
|
||||
mov ah,53h ;this is an APM command
|
||||
mov al,08h ;Change the state of power management...
|
||||
mov bx,0001h ;...on all devices to...
|
||||
mov cx,0001h ;...power management on.
|
||||
int 15h ;call the BIOS function through interrupt 15h
|
||||
;jc APM_error ;if the carry flag is set there was an error
|
||||
ret
|
||||
|
||||
power_off:
|
||||
;actual shutdown command
|
||||
mov ah, 0x53
|
||||
mov al, 0x07
|
||||
mov bx, 0x1
|
||||
mov cx, 0x3
|
||||
int 0x15
|
||||
ret
|
||||
@@ -0,0 +1,57 @@
|
||||
BITS 16
|
||||
; Compares two strings
|
||||
; IN si: the first (zero terminated) string
|
||||
; IN di: the second (zero terminated) string
|
||||
; OUT SF and ZF (same semantics as cmp)
|
||||
stringcompare:
|
||||
push bx
|
||||
push si
|
||||
push di
|
||||
.loop:
|
||||
mov bl, [si]
|
||||
mov bh, [di]
|
||||
cmp bl, bh
|
||||
jne .end
|
||||
test bl, bl ; bl and bh are the same, so bl = 0 => dl = 0
|
||||
jz .end
|
||||
inc si
|
||||
inc di
|
||||
jmp .loop
|
||||
.end:
|
||||
pop di
|
||||
pop si
|
||||
pop bx
|
||||
|
||||
ret
|
||||
|
||||
zstring_to_integer:
|
||||
;IN: si Pointer to string
|
||||
;OUT: ax result in binary
|
||||
push bx
|
||||
push si
|
||||
push cx
|
||||
push dx
|
||||
xor ax, ax
|
||||
xor bx, bx
|
||||
xor cx, cx
|
||||
xor dx, dx
|
||||
mov bx, 10
|
||||
.loop:
|
||||
mov cl, [si]
|
||||
cmp cl, 0
|
||||
je .end
|
||||
sub cl,'0'
|
||||
cmp cl, 9
|
||||
ja .end ; next number is not a number, or its a zero, and then we are done
|
||||
; multiply by 10, and add the new number.
|
||||
mul bx
|
||||
add ax, cx
|
||||
inc si
|
||||
jmp .loop
|
||||
|
||||
.end:
|
||||
pop dx
|
||||
pop cx
|
||||
pop si
|
||||
pop bx
|
||||
ret
|
||||
+290
@@ -0,0 +1,290 @@
|
||||
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
|
||||
mov si, .seperate_line
|
||||
call print
|
||||
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
|
||||
|
||||
; 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 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, 0x04 ;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, .buffer_for_svim
|
||||
add bx, 2046
|
||||
mov ax, [bx]
|
||||
mov [.buffer_counter_svim], ax
|
||||
; print buffer
|
||||
mov si, .buffer_for_svim
|
||||
mov es, si
|
||||
call print
|
||||
|
||||
.svim_loop:
|
||||
xor bx, bx
|
||||
xor cx, cx
|
||||
xor dx, dx
|
||||
mov ax, 0x1000 ; BIOS call to wait for key
|
||||
int 0x16
|
||||
cmp ax, 0x1c0d ; enter key
|
||||
jne .no_enter
|
||||
mov bx, .buffer_for_svim
|
||||
add bx, [.buffer_counter_svim]
|
||||
mov BYTE [bx], 13 ; put char in the buffer
|
||||
mov BYTE [bx + 1], 10 ; put char in the buffer
|
||||
mov bx, [.buffer_counter_svim]
|
||||
add bx, 0x02
|
||||
mov [.buffer_counter_svim], bx
|
||||
|
||||
xor bx, bx
|
||||
xor cx, cx
|
||||
xor dx, dx
|
||||
mov ax, 0x0e0d
|
||||
int 0x10
|
||||
|
||||
mov ax, 0x0e0a
|
||||
int 0x10
|
||||
|
||||
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, .buffer_for_svim
|
||||
add bx, 2046
|
||||
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, 0x04 ;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:
|
||||
mov bx, [.buffer_counter_svim]
|
||||
cmp bx, 0
|
||||
je .svim_loop
|
||||
;print_format .debug_buffer_counter, bx
|
||||
mov cx, bx
|
||||
sub cx, 1
|
||||
mov bx, .buffer_for_svim
|
||||
add bx, cx
|
||||
mov BYTE [bx], 0
|
||||
mov [.buffer_counter_svim], 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
|
||||
|
||||
; 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 .svim_loop
|
||||
|
||||
|
||||
;.f_key_pushed:
|
||||
;mov al, 0x01 ;arg: index 1
|
||||
;call os_change_screen
|
||||
;jmp .svim_loop
|
||||
|
||||
;.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 - Open file: ', 0
|
||||
.welcome_svim_enter_fileindex db 'Enter fileindex: ', 0
|
||||
.seperate_line db '________________________________________________________________________________', 0
|
||||
.fileindex_for_open_file dw 0
|
||||
.buffer_for_svim times 2048 db 0 ; db 'this is the buffer', 0, times 32 db 0
|
||||
.buffer_counter_svim dw 0
|
||||
Reference in new issue
Block a user