Browse Source

human68k: implemented some basic file and I/O handling functions

Karoly Balogh 1 year ago
parent
commit
42abb3395a
3 changed files with 97 additions and 1 deletions
  1. 16 0
      rtl/human68k/h68kdos.inc
  2. 22 0
      rtl/human68k/sysdir.inc
  3. 59 1
      rtl/human68k/sysfile.inc

+ 16 - 0
rtl/human68k/h68kdos.inc

@@ -48,8 +48,24 @@ type
     reserve_2: array[0..35] of byte;
     reserve_2: array[0..35] of byte;
   end;
   end;
 
 
+// as used by seek
+const
+    SEEK_FROM_START   = 0;
+    SEEK_FROM_CURRENT = 1;
+    SEEK_FROM_END     = 2;
+
 procedure h68kdos_exit; noreturn; syscall $ff00;
 procedure h68kdos_exit; noreturn; syscall $ff00;
+function h68kdos_gettim2: longint; syscall $ff27;
+function h68kdos_mkdir(name: pchar): longint; syscall $ff39;
+function h68kdos_rmdir(name: pchar): longint; syscall $ff3a;
+function h68kdos_chdir(name: pchar): longint; syscall $ff3b;
+function h68kdos_create(name: pchar; attr: word): longint; syscall $ff3c;
+function h68kdos_open(name: pchar; mode: word): longint; syscall $ff3d;
+function h68kdos_close(fileno: word): longint; syscall $ff3e;
+function h68kdos_read(fileno: word; buffer: pointer; len: longint): longint; syscall $ff3f;
 function h68kdos_write(fileno: word; buffer: pointer; len: longint): longint; syscall $ff40;
 function h68kdos_write(fileno: word; buffer: pointer; len: longint): longint; syscall $ff40;
+function h68kdos_delete(name: pchar): longint; syscall $ff41;
+function h68kdos_seek(fileno: word; offset: longint; mode: word): longint; syscall $ff42;
 function h68kdos_malloc(size: longint): pointer; syscall $ff48;
 function h68kdos_malloc(size: longint): pointer; syscall $ff48;
 function h68kdos_mfree(ptr: pointer): longint; syscall $ff49;
 function h68kdos_mfree(ptr: pointer): longint; syscall $ff49;
 function h68kdos_setblock(ptr: pointer; size: longint): longint; syscall $ff4a;
 function h68kdos_setblock(ptr: pointer; size: longint): longint; syscall $ff4a;

+ 22 - 0
rtl/human68k/sysdir.inc

@@ -18,12 +18,34 @@
                            Directory Handling
                            Directory Handling
 *****************************************************************************}
 *****************************************************************************}
 procedure do_mkdir(const s : rawbytestring);
 procedure do_mkdir(const s : rawbytestring);
+var
+  dosResult: longint;
+  ps: rawbytestring;
 begin
 begin
+  ps:=s;
+  DoDirSeparators(ps);
+  dosResult:=h68kdos_mkdir(PAnsiChar(ps));
+  if dosResult < 0 then
+    Error2InOutRes(dosResult);
 end;
 end;
 
 
 
 
 procedure do_rmdir(const s : rawbytestring);
 procedure do_rmdir(const s : rawbytestring);
+var
+  dosResult: longint;
+  ps: rawbytestring;
 begin
 begin
+  ps:=s;
+  DoDirSeparators(ps);
+  if ps='.' then
+    begin
+      InOutRes:=16;
+      exit;
+    end;
+
+  dosResult:=h68kdos_rmdir(PAnsiChar(ps));
+  if dosResult < 0 then
+    Error2InOutRes(dosResult);
 end;
 end;
 
 
 
 

+ 59 - 1
rtl/human68k/sysfile.inc

@@ -21,12 +21,27 @@
 
 
 { close a file from the handle value }
 { close a file from the handle value }
 procedure do_close(handle : longint);
 procedure do_close(handle : longint);
+var
+  dosResult: longint;
 begin
 begin
+  dosResult:=h68kdos_close(handle);
+  if dosResult < 0 then
+    Error2InOutRes(dosResult);
 end;
 end;
 
 
 
 
 procedure do_erase(p : pchar; pchangeable: boolean);
 procedure do_erase(p : pchar; pchangeable: boolean);
+var
+  oldp: PAnsiChar;
+  dosResult: longint;
 begin
 begin
+  oldp:=p;
+  DoDirSeparators(p,pchangeable);
+  dosResult:=h68kdos_delete(p);
+  if dosResult <0 then
+    Error2InOutRes(dosResult);
+  if oldp<>p then
+    FreeMem(p);
 end;
 end;
 
 
 
 
@@ -54,31 +69,74 @@ end;
 
 
 
 
 function do_read(h: longint; addr: pointer; len: longint) : longint;
 function do_read(h: longint; addr: pointer; len: longint) : longint;
+var
+  dosResult: longint;
 begin
 begin
-  do_read:=-1;
+  do_read:=0;
+  if (len<=0) or (h=-1) then exit;
+
+  dosResult:=h68kdos_read(h, addr, len);
+  if dosResult<0 then
+    begin
+      Error2InOutRes(dosResult);
+    end
+  else
+    do_read:=dosResult;
 end;
 end;
 
 
 
 
 function do_filepos(handle: longint) : longint;
 function do_filepos(handle: longint) : longint;
+var
+  dosResult: longint;
 begin
 begin
   do_filepos:=-1;
   do_filepos:=-1;
+  dosResult:=h68kdos_seek(handle, 0, SEEK_FROM_CURRENT);
+  if dosResult < 0 then
+    begin
+      Error2InOutRes(dosResult);
+    end
+  else
+    do_filepos:=dosResult;
 end;
 end;
 
 
 
 
 procedure do_seek(handle, pos: longint);
 procedure do_seek(handle, pos: longint);
+var
+  dosResult: longint;
 begin
 begin
+  dosResult:=h68kdos_seek(handle, pos, SEEK_FROM_START);
+  if dosResult < 0 then
+    Error2InOutRes(dosResult);
 end;
 end;
 
 
 
 
 function do_seekend(handle: longint):longint;
 function do_seekend(handle: longint):longint;
+var
+  dosResult: longint;
 begin
 begin
   do_seekend:=-1;
   do_seekend:=-1;
+
+  dosResult:=h68kdos_seek(handle, 0, SEEK_FROM_END);
+  if dosResult < 0 then
+    begin
+      Error2InOutRes(dosResult);
+    end
+  else
+    do_seekend:=dosResult;
 end;
 end;
 
 
 
 
 function do_filesize(handle : THandle) : longint;
 function do_filesize(handle : THandle) : longint;
+var
+  currfilepos: longint;
 begin
 begin
   do_filesize:=-1;
   do_filesize:=-1;
+  currfilepos:=do_filepos(handle);
+  if currfilepos >= 0 then
+    begin
+      do_filesize:=do_seekend(handle);
+    end;
+  do_seek(handle,currfilepos);
 end;
 end;