pinosaur
/
sped.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
final clean up
[sped.git]
/
fileutils.asm
diff --git
a/fileutils.asm
b/fileutils.asm
index
b9b41e7
..
32dcef6
100644
(file)
--- a/
fileutils.asm
+++ b/
fileutils.asm
@@
-1,5
+1,8
@@
+; sped - the stupidly pointless editor
+; written by pinosaur
+; fileutils.asm: file i/o
-
; %include "util
s.S"
+
%include "macro
s.S"
extern printf
extern malloc
extern printf
extern malloc
@@
-14,6
+17,7
@@
global writeFile
section .data
wrongfile_str db `unable to open file, error code: %i\n`, 0x00
section .data
wrongfile_str db `unable to open file, error code: %i\n`, 0x00
+ returnvalue_str db `system call return was %i\n`, 0x00
section .text
section .text
@@
-60,18
+64,14
@@
readFile:
_readFile_loop:
_readFile_loop:
- ; check if eof was reached
- cmp DWORD [ebp-IS_EOF], 1
- je _readFile_exit
-
push DWORD [ebp-FILE_HANDLE]
call readLine
push DWORD [ebp-FILE_HANDLE]
call readLine
-
mov esi, eax
mov [ebp-IS_EOF], ebx
mov esi, eax
mov [ebp-IS_EOF], ebx
-
- ; push esi
- ; call printf
+
+ ; check if eof was reached
+ cmp DWORD [ebp-IS_EOF], 1
+ je _readFile_exit
; make string buffer bigger
mov eax, DWORD [ebp-LINES_READ]
; make string buffer bigger
mov eax, DWORD [ebp-LINES_READ]
@@
-159,13
+159,6
@@
readLine:
add ecx, [ebp-CHAR_COUNT]
mov edx, 1
int 0x80
add ecx, [ebp-CHAR_COUNT]
mov edx, 1
int 0x80
-
- ; mov eax, 4
- ; mov ebx, 1
- ; mov ecx, [ebp-STR_PTR]
- ; add ecx, [ebp-CHAR_COUNT]
- ; mov edx, 1
- ; int 0x80
; check for eof
cmp eax, 0 ; eax has zero on eof
; check for eof
cmp eax, 0 ; eax has zero on eof
@@
-233,11
+226,13
@@
writeFile:
; check if file was open successfully
cmp eax, 0
; check if file was open successfully
cmp eax, 0
- jge _writeFile_loop
- push eax
- push wrongfile_str
- call printf
- jmp _writeFile_exit
+ jl _writeFile_error
+
+ ; truncate file
+ mov eax, 93
+ mov ebx, [ebp-FILE_HANDLE]
+ mov ecx, 1
+ int 0x80
_writeFile_loop:
_writeFile_loop:
@@
-262,6
+257,12
@@
writeFile:
jmp _writeFile_loop
jmp _writeFile_loop
+ _writeFile_error:
+ push eax
+ push wrongfile_str
+ call printf
+ jmp _writeFile_exit
+
_writeFile_exit:
; close file
_writeFile_exit:
; close file