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,10 +87,35 @@ 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
ret jc .ret
and dword [ebx-4], 0
mov dword [ebx], 2
.ret:
ret
open: open:
@ -112,29 +137,26 @@ 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 eax, 70
mov [fileio.count], eax push ebx
mov [fileio.buff], fileinfo int 0x40
mov byte [fileio.buff+4], al pop ebx
mov [fileio.name], fullpath_open test eax, eax
jnz .fail
mov eax, 70 mov eax, [fileinfo.size]
mov ebx, fileio mov [ebx-4], eax
int 0x40 and dword [ebx], 0
test eax, eax .ret:
jnz .fail ret
mov ebx, [fileinfo.size]
mov [filesize],ebx
clc
ret
.fail: .fail:
stc or dword [ebx], -1 ; close handle
ret stc
ret
read: read:
; pusha ; pusha
@ -146,19 +168,27 @@ 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 eax, 70
mov [fileio.count], ecx int 0x40
mov [fileio.buff], edx xchg eax, [esp]
mov byte [fileio.buff+4], al add [eax+4], ebx
mov [fileio.name], fullpath_open adc [eax+8], dword 0
mov eax, 70 mov ebx, eax
mov ebx, fileio pop eax
int 0x40 test eax, eax
jz .ok
cmp eax, 6
jz .ok
stc
.ok:
ret
close: close:
ret or dword [ebx], -1
ret
; ebx file handle ; ebx file handle
@ -175,24 +205,20 @@ 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 eax, 70
mov [fileio.count], ecx int 0x40
mov [fileio.buff], edx xchg eax, [esp]
mov byte [fileio.buff+4], al add [eax+4], ebx
mov [fileio.name], fullpath_write adc [eax+8], dword 0
mov eax, 70 mov ebx, eax
mov ebx, fileio pop eax
int 0x40 mov byte [ebx], 3
test eax, eax cmp eax, 1
jnz .fail cmc
clc ret
ret
.fail:
stc
ret
make_fullpaths: make_fullpaths:
pusha pusha
@ -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