FASM now compiles non-binary files correctly

git-svn-id: svn://kolibrios.org@332 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2007-02-08 16:38:05 +00:00
parent 13528c5c97
commit a89bf95159
2 changed files with 94 additions and 64 deletions

View File

@ -41,6 +41,10 @@ include 'fasm.inc'
center fix true center fix true
START: ; Start of execution START: ; Start of execution
mov edi, fileinfos
mov ecx, (fileinfos_end-fileinfos)/4
or eax, -1
rep stosd
cmp [params],0 cmp [params],0
jz red jz red
@ -545,4 +549,7 @@ memory_setting dd ?
start_time dd ? start_time dd ?
sc system_colors sc system_colors
max_handles = 8
fileinfos rb (4+20+MAX_PATH)*max_handles
fileinfos_end:
pinfo process_information pinfo process_information

View File

@ -87,9 +87,34 @@ get_environment_variable:
; stc ; stc
ret ret
alloc_handle:
call make_fullpaths
mov ebx, fileinfos+4
@@:
cmp dword [ebx], -1
jz .found
add ebx, 4+20+MAX_PATH
cmp ebx, fileinfos_end
jb @b
stc
ret
.found:
and dword [ebx+4], 0
and dword [ebx+8], 0
push esi edi ecx
mov esi, fullpath_open
lea edi, [ebx+20]
mov ecx, MAX_PATH
rep movsb
pop ecx edi esi
ret ; CF=0
create: create:
call make_fullpaths call alloc_handle
jc .ret
and dword [ebx-4], 0
mov dword [ebx], 2
.ret:
ret ret
@ -112,27 +137,24 @@ open:
; stc ; stc
; ret ; ret
call make_fullpaths call alloc_handle
jc .ret
xor eax, eax mov dword [ebx], 5
mov [fileio.cmd], 5 and dword [ebx+12], 0
mov [fileio.offset], eax mov dword [ebx+16], fileinfo
mov [fileio.offset+4], eax
mov [fileio.count], eax
mov [fileio.buff], fileinfo
mov byte [fileio.buff+4], al
mov [fileio.name], fullpath_open
mov eax, 70 mov eax, 70
mov ebx, fileio push ebx
int 0x40 int 0x40
pop ebx
test eax, eax test eax, eax
jnz .fail jnz .fail
mov ebx, [fileinfo.size] mov eax, [fileinfo.size]
mov [filesize],ebx mov [ebx-4], eax
clc and dword [ebx], 0
.ret:
ret ret
.fail: .fail:
or dword [ebx], -1 ; close handle
stc stc
ret ret
@ -146,18 +168,26 @@ read:
; popa ; popa
;; ret ;; ret
xor eax, eax mov [ebx+12], ecx
mov [fileio.cmd], eax mov [ebx+16], edx
mov [fileio.offset], eax push ebx
mov [fileio.offset+4], eax
mov [fileio.count], ecx
mov [fileio.buff], edx
mov byte [fileio.buff+4], al
mov [fileio.name], fullpath_open
mov eax, 70 mov eax, 70
mov ebx, fileio
int 0x40 int 0x40
xchg eax, [esp]
add [eax+4], ebx
adc [eax+8], dword 0
mov ebx, eax
pop eax
test eax, eax
jz .ok
cmp eax, 6
jz .ok
stc
.ok:
ret
close: close:
or dword [ebx], -1
ret ret
@ -175,23 +205,19 @@ write:
; popa ; popa
; ret ; ret
xor eax, eax mov [ebx+12], ecx
mov [fileio.cmd], 2 mov [ebx+16], edx
mov [fileio.offset], eax push ebx
mov [fileio.offset+4], eax
mov [fileio.count], ecx
mov [fileio.buff], edx
mov byte [fileio.buff+4], al
mov [fileio.name], fullpath_write
mov eax, 70 mov eax, 70
mov ebx, fileio
int 0x40 int 0x40
test eax, eax xchg eax, [esp]
jnz .fail add [eax+4], ebx
clc adc [eax+8], dword 0
ret mov ebx, eax
.fail: pop eax
stc mov byte [ebx], 3
cmp eax, 1
cmc
ret ret
make_fullpaths: make_fullpaths:
@ -278,16 +304,15 @@ make_fullpaths:
lseek: lseek:
cmp al,0 cmp al,0
jnz @f jnz @f
mov [filepos],0 and dword [ebx+4], 0
@@: cmp al,1 and dword [ebx+8], 0
jnz @f
@@: cmp al,2 @@: cmp al,2
jnz @f jnz @f
mov eax,[filesize] mov eax, [ebx-4]
mov [filepos],eax mov [ebx+4], eax
@@: mov eax,[filepos] and dword [ebx+8], 0
add eax,edx @@: add dword [ebx+4], edx
mov [filepos],eax adc dword [ebx+8], 0
ret ret
display_character: display_character:
@ -508,8 +533,6 @@ display_line_data:
call display_string call display_string
jmp exit_program jmp exit_program
align 4
fileio FILEIO
align 4 align 4
fileinfo FILEINFO fileinfo FILEINFO