mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
62 lines
1.1 KiB
Plaintext
62 lines
1.1 KiB
Plaintext
; The OS/K Team licenses this file to you under the MIT license.
|
|
; See the LICENSE file in the project root for more information.
|
|
|
|
.try_exec:
|
|
; try without appending ".com"
|
|
mov eax, Sys.OpenFile
|
|
mov ax0, argv0
|
|
trap 0
|
|
|
|
; we good?
|
|
blte zero, eax, .do_exec
|
|
|
|
; nope, append ".com" and try again
|
|
mov esi, argv0
|
|
sub ecx, argbuf.size, 5
|
|
scasb esi, zero ; find null-term
|
|
mov b[esi], '.' ; ".com"
|
|
mov b[esi+1], 'c'
|
|
mov b[esi+2], 'o'
|
|
mov b[esi+3], 'm'
|
|
nul b[esi+4]
|
|
|
|
; try again
|
|
mov eax, Sys.OpenFile
|
|
mov ax0, argv0
|
|
trap 0
|
|
|
|
; we good?
|
|
blte zero, eax, .do_exec
|
|
|
|
nul b[esi] ; erase ".com"
|
|
jmp .exec_not_found
|
|
|
|
.do_exec:
|
|
; load file into memory
|
|
mov ax0, eax
|
|
mov ax1, FILE_LOADP
|
|
mov ax2, FILE_MAXSZ
|
|
mov eax, Sys.ReadFile
|
|
trap 0
|
|
|
|
; save load address
|
|
mov ecx, eax
|
|
|
|
; close file
|
|
mov eax, Sys.CloseFile
|
|
trap 0
|
|
|
|
; read anything?
|
|
bltz ecx, .couldnt_read
|
|
jecxz .empty_file
|
|
|
|
; all good, let's go
|
|
mov eax, Sys.ExecuteInFrame
|
|
mov ax0, FILE_LOADP
|
|
mov ax1, 5
|
|
trap 0
|
|
|
|
; unreachable
|
|
jmp abort
|
|
|