mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-25 01:49:09 +02:00
+ Error2InoutRes implemented
* do_read was doing a wrong os call! * do_open was not pushing the right values * DosDir was pushing the wrong params on the stack * do_close would never works, was pushing a longint instead of word
This commit is contained in:
parent
5bac56f11c
commit
1b9ffe21b8
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
$Id$
|
$Id$
|
||||||
This file is part of the Free Pascal run time library.
|
This file is part of the Free Pascal run time library.
|
||||||
Copyright (c) 1993,97 by the Free Pascal development team.
|
Copyright (c) 1993,98 by Carl Eric Codere
|
||||||
|
member of the Free Pascal development team
|
||||||
|
|
||||||
See the file COPYING.FPC, included in this distribution,
|
See the file COPYING.FPC, included in this distribution,
|
||||||
for details about the copyright.
|
for details about the copyright.
|
||||||
@ -14,9 +15,14 @@
|
|||||||
{$define ATARI}
|
{$define ATARI}
|
||||||
unit sysatari;
|
unit sysatari;
|
||||||
|
|
||||||
|
{--------------------------------------------------------------------}
|
||||||
|
{ LEFT TO DO: }
|
||||||
|
{--------------------------------------------------------------------}
|
||||||
|
{ o SBrk }
|
||||||
|
{ o Implement truncate }
|
||||||
|
{ o Implement paramcount and paramstr }
|
||||||
|
{--------------------------------------------------------------------}
|
||||||
|
|
||||||
{ Left to do : }
|
|
||||||
{ - Fix DOSError codes to conform to those of DOS (TP) }
|
|
||||||
|
|
||||||
{$I os.inc}
|
{$I os.inc}
|
||||||
|
|
||||||
@ -33,13 +39,15 @@ const
|
|||||||
UnusedHandle = $ffff;
|
UnusedHandle = $ffff;
|
||||||
StdInputHandle = 0;
|
StdInputHandle = 0;
|
||||||
StdOutputHandle = 1;
|
StdOutputHandle = 1;
|
||||||
StdErrorHandle = $ffff;
|
StdErrorHandle = $ffff;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
{$I system.inc}
|
{$I system.inc}
|
||||||
{$I lowmath.inc}
|
{$I lowmath.inc}
|
||||||
|
|
||||||
|
var
|
||||||
|
errno : integer;
|
||||||
type
|
type
|
||||||
plongint = ^longint;
|
plongint = ^longint;
|
||||||
|
|
||||||
@ -59,6 +67,34 @@ const
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Procedure Error2InOut;
|
||||||
|
Begin
|
||||||
|
if (errno <= -2) and (errno >= -11) then
|
||||||
|
InOutRes:=150-errno { 150+errno }
|
||||||
|
else
|
||||||
|
Begin
|
||||||
|
case errno of
|
||||||
|
-32 : InOutRes:=1;
|
||||||
|
-33 : InOutRes:=2;
|
||||||
|
-34 : InOutRes:=3;
|
||||||
|
-35 : InOutRes:=4;
|
||||||
|
-36 : InOutRes:=5;
|
||||||
|
-37 : InOutRes:=8;
|
||||||
|
-39 : InOutRes:=8;
|
||||||
|
-40 : InOutRes:=9;
|
||||||
|
-46 : InOutRes:=15;
|
||||||
|
-67..-64 : InOutRes:=153;
|
||||||
|
-15 : InOutRes:=151;
|
||||||
|
-13 : InOutRes:=150;
|
||||||
|
else
|
||||||
|
InOutres := word(errno);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
errno:=0;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
procedure halt(errnum : byte);
|
procedure halt(errnum : byte);
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -146,7 +182,8 @@ procedure do_close(h : longint);
|
|||||||
begin
|
begin
|
||||||
asm
|
asm
|
||||||
movem.l d2/d3/a2/a3,-(sp)
|
movem.l d2/d3/a2/a3,-(sp)
|
||||||
move.l h,-(sp)
|
move.l h,d0
|
||||||
|
move.w d0,-(sp)
|
||||||
move.w #$3e,-(sp)
|
move.w #$3e,-(sp)
|
||||||
trap #1
|
trap #1
|
||||||
add.l #4,sp { restore stack ... }
|
add.l #4,sp { restore stack ... }
|
||||||
@ -169,9 +206,11 @@ begin
|
|||||||
movem.l (sp)+,d3/a2/a3
|
movem.l (sp)+,d3/a2/a3
|
||||||
tst.w d0
|
tst.w d0
|
||||||
beq @doserend
|
beq @doserend
|
||||||
move.w d0,InOutRes
|
move.w d0,errno
|
||||||
@doserend:
|
@doserend:
|
||||||
end;
|
end;
|
||||||
|
if errno <> 0 then
|
||||||
|
Error2InOut;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -192,16 +231,18 @@ begin
|
|||||||
movem.l (sp)+,d3/a2/a3
|
movem.l (sp)+,d3/a2/a3
|
||||||
tst.w d0
|
tst.w d0
|
||||||
beq @dosreend
|
beq @dosreend
|
||||||
move.w d0,InOutRes { error ... }
|
move.w d0,errno { error ... }
|
||||||
@dosreend:
|
@dosreend:
|
||||||
end;
|
end;
|
||||||
|
if errno <> 0 then
|
||||||
|
Error2InOut;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function do_isdevice(handle:longint):boolean;
|
function do_isdevice(handle:word):boolean;
|
||||||
begin
|
begin
|
||||||
if (handle=stdoutputhandle) or (handle=stdinputhandle) or
|
if (handle=stdoutputhandle) or (handle=stdinputhandle) or
|
||||||
(handle=stderrorhandle) then
|
(handle=stderrorhandle) then
|
||||||
do_isdevice:=FALSE;
|
do_isdevice:=FALSE
|
||||||
else
|
else
|
||||||
do_isdevice:=TRUE;
|
do_isdevice:=TRUE;
|
||||||
end;
|
end;
|
||||||
@ -214,7 +255,8 @@ begin
|
|||||||
movem.l d3/a2/a3,-(sp)
|
movem.l d3/a2/a3,-(sp)
|
||||||
move.l addr,-(sp)
|
move.l addr,-(sp)
|
||||||
move.l len,-(sp)
|
move.l len,-(sp)
|
||||||
move.w h,-(sp)
|
move.l h,d0
|
||||||
|
move.w d0,-(sp)
|
||||||
move.w #$40,-(sp)
|
move.w #$40,-(sp)
|
||||||
trap #1
|
trap #1
|
||||||
lea 12(sp),sp
|
lea 12(sp),sp
|
||||||
@ -222,10 +264,12 @@ begin
|
|||||||
movem.l (sp)+,d3/a2/a3
|
movem.l (sp)+,d3/a2/a3
|
||||||
tst.l d0
|
tst.l d0
|
||||||
bpl @doswrend
|
bpl @doswrend
|
||||||
move.w d0,InOutRes { error ... }
|
move.w d0,errno { error ... }
|
||||||
@doswrend:
|
@doswrend:
|
||||||
move.l d0,@RESULT
|
move.l d0,@RESULT
|
||||||
end;
|
end;
|
||||||
|
if errno <> 0 then
|
||||||
|
Error2InOut;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -236,18 +280,21 @@ begin
|
|||||||
movem.l d3/a2/a3,-(sp)
|
movem.l d3/a2/a3,-(sp)
|
||||||
move.l addr,-(sp)
|
move.l addr,-(sp)
|
||||||
move.l len,-(sp)
|
move.l len,-(sp)
|
||||||
move.w h,-(sp)
|
move.l h,d0
|
||||||
move.w #$40,-(sp)
|
move.w d0,-(sp)
|
||||||
|
move.w #$3f,-(sp)
|
||||||
trap #1
|
trap #1
|
||||||
lea 12(sp),sp
|
lea 12(sp),sp
|
||||||
move.l d6,d2 { restore d2 }
|
move.l d6,d2 { restore d2 }
|
||||||
movem.l (sp)+,d3/a2/a3
|
movem.l (sp)+,d3/a2/a3
|
||||||
tst.l d0
|
tst.l d0
|
||||||
bpl @dosrdend
|
bpl @dosrdend
|
||||||
move.w d0,InOutRes { error ... }
|
move.w d0,errno { error ... }
|
||||||
@dosrdend:
|
@dosrdend:
|
||||||
move.l d0,@Result
|
move.l d0,@Result
|
||||||
end;
|
end;
|
||||||
|
if errno <> 0 then
|
||||||
|
Error2InOut;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -257,7 +304,8 @@ begin
|
|||||||
move.l d2,d6 { save d2 }
|
move.l d2,d6 { save d2 }
|
||||||
movem.l d3/a2/a3,-(sp)
|
movem.l d3/a2/a3,-(sp)
|
||||||
move.w #1,-(sp) { seek from current position }
|
move.w #1,-(sp) { seek from current position }
|
||||||
move.w handle,-(sp)
|
move.l handle,d0
|
||||||
|
move.w d0,-(sp)
|
||||||
move.l #0,-(sp) { with a seek offset of zero }
|
move.l #0,-(sp) { with a seek offset of zero }
|
||||||
move.w #$42,-(sp)
|
move.w #$42,-(sp)
|
||||||
trap #1
|
trap #1
|
||||||
@ -275,7 +323,8 @@ begin
|
|||||||
move.l d2,d6 { save d2 }
|
move.l d2,d6 { save d2 }
|
||||||
movem.l d3/a2/a3,-(sp)
|
movem.l d3/a2/a3,-(sp)
|
||||||
move.w #0,-(sp) { seek from start of file }
|
move.w #0,-(sp) { seek from start of file }
|
||||||
move.w handle,-(sp)
|
move.l handle,d0
|
||||||
|
move.w d0,-(sp)
|
||||||
move.l pos,-(sp)
|
move.l pos,-(sp)
|
||||||
move.w #$42,-(sp)
|
move.w #$42,-(sp)
|
||||||
trap #1
|
trap #1
|
||||||
@ -294,7 +343,8 @@ begin
|
|||||||
move.l d2,d6 { save d2 }
|
move.l d2,d6 { save d2 }
|
||||||
movem.l d3/a2/a3,-(sp)
|
movem.l d3/a2/a3,-(sp)
|
||||||
move.w #2,-(sp) { seek from end of file }
|
move.w #2,-(sp) { seek from end of file }
|
||||||
move.w handle,-(sp)
|
move.l handle,d0
|
||||||
|
move.w d0,-(sp)
|
||||||
move.l #0,-(sp) { with an offset of 0 from end }
|
move.l #0,-(sp) { with an offset of 0 from end }
|
||||||
move.w #$42,-(sp)
|
move.w #$42,-(sp)
|
||||||
trap #1
|
trap #1
|
||||||
@ -333,7 +383,7 @@ procedure do_open(var f;p:pchar;flags:longint);
|
|||||||
when (flags and $1000) there is no check for close (needed for textfiles)
|
when (flags and $1000) there is no check for close (needed for textfiles)
|
||||||
}
|
}
|
||||||
var
|
var
|
||||||
i : longint;
|
i : word;
|
||||||
oflags: longint;
|
oflags: longint;
|
||||||
begin
|
begin
|
||||||
AllowSlash(p);
|
AllowSlash(p);
|
||||||
@ -352,12 +402,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
{ reset file handle }
|
{ reset file handle }
|
||||||
filerec(f).handle:=UnusedHandle;
|
filerec(f).handle:=UnusedHandle;
|
||||||
oflags:=$04;
|
oflags:=$02; { read/write mode }
|
||||||
{ convert filemode to filerec modes }
|
{ convert filemode to filerec modes }
|
||||||
case (flags and 3) of
|
case (flags and 3) of
|
||||||
0 : begin
|
0 : begin
|
||||||
filerec(f).mode:=fminput;
|
filerec(f).mode:=fminput;
|
||||||
oflags:=$01;
|
oflags:=$00; { read mode only }
|
||||||
end;
|
end;
|
||||||
1 : filerec(f).mode:=fmoutput;
|
1 : filerec(f).mode:=fmoutput;
|
||||||
2 : filerec(f).mode:=fminout;
|
2 : filerec(f).mode:=fminout;
|
||||||
@ -365,13 +415,13 @@ begin
|
|||||||
if (flags and $100)<>0 then
|
if (flags and $100)<>0 then
|
||||||
begin
|
begin
|
||||||
filerec(f).mode:=fmoutput;
|
filerec(f).mode:=fmoutput;
|
||||||
oflags:=$02;
|
oflags:=$04; { read/write with create }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if (flags and $10)<>0 then
|
if (flags and $10)<>0 then
|
||||||
begin
|
begin
|
||||||
filerec(f).mode:=fmoutput;
|
filerec(f).mode:=fmoutput;
|
||||||
oflags:=$04;
|
oflags:=$02; { read/write }
|
||||||
end;
|
end;
|
||||||
{ empty name is special }
|
{ empty name is special }
|
||||||
if p[0]=#0 then
|
if p[0]=#0 then
|
||||||
@ -389,28 +439,42 @@ begin
|
|||||||
asm
|
asm
|
||||||
movem.l d2/d3/a2/a3,-(sp) { save used registers }
|
movem.l d2/d3/a2/a3,-(sp) { save used registers }
|
||||||
|
|
||||||
cmp.l #4,oflags { check if append mode ... }
|
cmp.l #4,oflags { check if rewrite mode ... }
|
||||||
bne @opencont2
|
bne @opencont2
|
||||||
move.w #2,d0 { append mode... r/w open }
|
{ rewrite mode - create new file }
|
||||||
bra @opencont1
|
move.w #0,-(sp)
|
||||||
|
move.l p,-(sp)
|
||||||
|
move.w #$3c,-(sp)
|
||||||
|
trap #1
|
||||||
|
add.l #8,sp { restore stack of os call }
|
||||||
|
bra @end
|
||||||
|
{ reset - open existing files }
|
||||||
@opencont2:
|
@opencont2:
|
||||||
move.l oflags,d0 { use flag as source ... }
|
move.l oflags,d0 { use flag as source ... }
|
||||||
@opencont1:
|
@opencont1:
|
||||||
move.w d0,-(sp)
|
move.w d0,-(sp)
|
||||||
pea p
|
move.l p,-(sp)
|
||||||
move.w #$3d,-(sp)
|
move.w #$3d,-(sp)
|
||||||
trap #1
|
trap #1
|
||||||
add.l #8,sp { restore stack of os call }
|
add.l #8,sp { restore stack of os call }
|
||||||
|
@end:
|
||||||
movem.l (sp)+,d2/d3/a2/a3
|
movem.l (sp)+,d2/d3/a2/a3
|
||||||
|
|
||||||
tst.l d0
|
tst.w d0
|
||||||
bpl @opennoerr
|
bpl @opennoerr { if positive return values then ok }
|
||||||
move.w d0,InOutRes
|
cmp.w #-1,d0 { if handle is -1 CON: }
|
||||||
|
beq @opennoerr
|
||||||
|
cmp.w #-2,d0 { if handle is -2 AUX: }
|
||||||
|
beq @opennoerr
|
||||||
|
cmp.w #-3,d0 { if handle is -3 PRN: }
|
||||||
|
beq @opennoerr
|
||||||
|
move.w d0,errno { otherwise normal error }
|
||||||
@opennoerr:
|
@opennoerr:
|
||||||
move.l d0,i { get handle ... }
|
move.w d0,i { get handle as SIGNED VALUE... }
|
||||||
end;
|
end;
|
||||||
filerec(f).handle:=i;
|
if errno <> 0 then
|
||||||
|
Error2InOut;
|
||||||
|
filerec(f).handle:=i;
|
||||||
if (flags and $10)<>0 then
|
if (flags and $10)<>0 then
|
||||||
do_seekend(filerec(f).handle);
|
do_seekend(filerec(f).handle);
|
||||||
end;
|
end;
|
||||||
@ -440,24 +504,28 @@ end;
|
|||||||
procedure DosDir(func:byte;const s:string);
|
procedure DosDir(func:byte;const s:string);
|
||||||
var
|
var
|
||||||
buffer : array[0..255] of char;
|
buffer : array[0..255] of char;
|
||||||
|
c : word;
|
||||||
begin
|
begin
|
||||||
move(s[1],buffer,length(s));
|
move(s[1],buffer,length(s));
|
||||||
buffer[length(s)]:=#0;
|
buffer[length(s)]:=#0;
|
||||||
AllowSlash(pchar(@buffer));
|
AllowSlash(pchar(@buffer));
|
||||||
|
c:=word(func);
|
||||||
asm
|
asm
|
||||||
move.l d2,d6 { save d2 }
|
move.l d2,d6 { save d2 }
|
||||||
movem.l d3/a2/a3,-(sp)
|
movem.l d3/a2/a3,-(sp)
|
||||||
pea buffer
|
pea buffer
|
||||||
move.b func,-(sp)
|
move.w c,-(sp)
|
||||||
trap #1
|
trap #1
|
||||||
add.l #6,sp
|
add.l #6,sp
|
||||||
move.l d6,d2 { restore d2 }
|
move.l d6,d2 { restore d2 }
|
||||||
movem.l (sp)+,d3/a2/a3
|
movem.l (sp)+,d3/a2/a3
|
||||||
tst.w d0
|
tst.w d0
|
||||||
beq @dosdirend
|
beq @dosdirend
|
||||||
move.w d0,InOutRes
|
move.w d0,errno
|
||||||
@dosdirend:
|
@dosdirend:
|
||||||
end;
|
end;
|
||||||
|
if errno <> 0 then
|
||||||
|
Error2InOut;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -485,19 +553,21 @@ end;
|
|||||||
procedure getdir(drivenr : byte;var dir : string);
|
procedure getdir(drivenr : byte;var dir : string);
|
||||||
var
|
var
|
||||||
temp : array[0..255] of char;
|
temp : array[0..255] of char;
|
||||||
sof : pchar;
|
|
||||||
i : longint;
|
i : longint;
|
||||||
|
j: byte;
|
||||||
|
drv: word;
|
||||||
begin
|
begin
|
||||||
sof:=pchar(@dir[4]);
|
drv:=word(drivenr);
|
||||||
asm
|
asm
|
||||||
move.l d2,d6 { save d2 }
|
move.l d2,d6 { save d2 }
|
||||||
movem.l d3/a2/a3,-(sp)
|
movem.l d3/a2/a3,-(sp)
|
||||||
|
|
||||||
{ Get dir from drivenr : 0=default, 1=A etc... }
|
{ Get dir from drivenr : 0=default, 1=A etc... }
|
||||||
move.w drivenr,-(sp)
|
move.w drv,-(sp)
|
||||||
|
|
||||||
{ put (previously saved) offset in si }
|
{ put (previously saved) offset in si }
|
||||||
pea dir
|
{ move.l temp,-(sp)}
|
||||||
|
pea temp
|
||||||
|
|
||||||
{ call attos function 47H : Get dir }
|
{ call attos function 47H : Get dir }
|
||||||
move.w #$47,-(sp)
|
move.w #$47,-(sp)
|
||||||
@ -509,21 +579,18 @@ begin
|
|||||||
move.l d6,d2 { restore d2 }
|
move.l d6,d2 { restore d2 }
|
||||||
movem.l (sp)+,d3/a2/a3
|
movem.l (sp)+,d3/a2/a3
|
||||||
end;
|
end;
|
||||||
{ Now Dir should be filled with directory in ASCIIZ, }
|
{ conversion to pascal string }
|
||||||
{ starting from dir[4] }
|
i:=0;
|
||||||
dir[0]:=#3;
|
while (temp[i]<>#0) do
|
||||||
dir[2]:=':';
|
|
||||||
dir[3]:='\';
|
|
||||||
i:=4;
|
|
||||||
{ conversation to Pascal string }
|
|
||||||
while (dir[i]<>#0) do
|
|
||||||
begin
|
begin
|
||||||
{ convert path name to DOS }
|
if temp[i]='/' then
|
||||||
if dir[i]='/' then
|
temp[i]:='\';
|
||||||
dir[i]:='\';
|
dir[i+3]:=temp[i];
|
||||||
dir[0]:=chr(i);
|
|
||||||
inc(i);
|
inc(i);
|
||||||
end;
|
end;
|
||||||
|
dir[2]:=':';
|
||||||
|
dir[3]:='\';
|
||||||
|
dir[0]:=char(i+2);
|
||||||
{ upcase the string (FPKPascal function) }
|
{ upcase the string (FPKPascal function) }
|
||||||
dir:=upcase(dir);
|
dir:=upcase(dir);
|
||||||
if drivenr<>0 then { Drive was supplied. We know it }
|
if drivenr<>0 then { Drive was supplied. We know it }
|
||||||
@ -536,14 +603,15 @@ begin
|
|||||||
move.w #$19,-(sp)
|
move.w #$19,-(sp)
|
||||||
trap #1
|
trap #1
|
||||||
add.l #2,sp
|
add.l #2,sp
|
||||||
|
move.w d0,drv
|
||||||
move.l d6,d2 { restore d2 }
|
move.l d6,d2 { restore d2 }
|
||||||
movem.l (sp)+,d3/a2/a3
|
movem.l (sp)+,d3/a2/a3
|
||||||
end;
|
end;
|
||||||
dir[1]:=chr(i);
|
dir[1]:=chr(byte(drv)+ord('A'));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{*****************************************************************************
|
{*****************************************************************************
|
||||||
SystemUnit Initialization
|
SystemUnit Initialization
|
||||||
*****************************************************************************}
|
*****************************************************************************}
|
||||||
@ -562,11 +630,19 @@ begin
|
|||||||
OpenStdIO(StdErr,fmOutput,StdErrorHandle);
|
OpenStdIO(StdErr,fmOutput,StdErrorHandle);
|
||||||
{ Reset IO Error }
|
{ Reset IO Error }
|
||||||
InOutRes:=0;
|
InOutRes:=0;
|
||||||
|
errno := 0;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.4 1998-07-02 12:39:27 carl
|
Revision 1.5 1998-07-13 12:34:13 carl
|
||||||
|
+ Error2InoutRes implemented
|
||||||
|
* do_read was doing a wrong os call!
|
||||||
|
* do_open was not pushing the right values
|
||||||
|
* DosDir was pushing the wrong params on the stack
|
||||||
|
* do_close would never works, was pushing a longint instead of word
|
||||||
|
|
||||||
|
Revision 1.4 1998/07/02 12:39:27 carl
|
||||||
* IOCheck for mkdir,chdir and rmdir, just like in TP
|
* IOCheck for mkdir,chdir and rmdir, just like in TP
|
||||||
|
|
||||||
Revision 1.3 1998/07/01 14:40:20 carl
|
Revision 1.3 1998/07/01 14:40:20 carl
|
||||||
|
Loading…
Reference in New Issue
Block a user