summaryrefslogtreecommitdiff
path: root/rtl/atari/sysdir.inc
blob: e05538b402e9f353967ae0c6d5f342178ad71935 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{
    This file is part of the Free Pascal run time library.
    Copyright (c) 2016 by Free Pascal development team

    Low level directory functions for Atari TOS

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}


{*****************************************************************************
                           Directory Handling
*****************************************************************************}
procedure do_mkdir(const s : rawbytestring);
var
  dosResult: longint;
  ps: rawbytestring;
begin
  ps:=s;
  DoDirSeparators(ps);
  dosResult:=gemdos_dcreate(pchar(ps));
  if dosResult < 0 then
    Error2InOutRes(dosResult);
end;


procedure do_rmdir(const s : rawbytestring);
var
  dosResult: longint;
  ps: rawbytestring;
begin
  ps:=s;
  DoDirSeparators(ps);
  if ps='.' then
    begin
      InOutRes:=16;
      exit;
    end;

  dosResult:=gemdos_ddelete(pchar(ps));
  if dosResult < 0 then
    Error2InOutRes(dosResult);
end;


procedure do_ChDir(const s: rawbytestring);
var
  ps: rawbytestring;
  len: longint;
  drives: dword;
  curdrive: word;
  newdrive: word;
  dosResult: longint;
begin
  ps:=s;
  DoDirSeparators(ps);
  len:=Length(ps);

  { first, handle drive changes }
  if (len>=2) and (ps[2]=':') then
    begin
      curdrive:=gemdos_dgetdrv;
      newdrive:=(ord(ps[1]) and (not 32))-ord('A');
      if (newdrive <> curdrive) then
        begin
          { verify if the drive we have to set actually exist.
            not doing so may corrupt TOS internal structures, 
            according to docs. (KB) }
          drives:=gemdos_dsetdrv(curdrive);
          if (drives and (1 shl newdrive)) = 0 then
            begin
              InOutRes:=15;
              exit;
            end;
          gemdos_dsetdrv(newdrive);
        end;
      if len=2 then
        exit;
    end;
  { do normal setpath }
  dosResult:=gemdos_dsetpath(pchar(ps));
  if dosResult < 0 then
    Error2InOutRes(dosResult);
end;


procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
var
  dosResult: longint;
  pathbuf: array[0..259] of char;
begin
  Dir := '';

  dosResult:=gemdos_dgetpath(@pathbuf[2],DriveNr);
  if dosResult < 0 then
    begin
      Error2InOutRes(dosResult);
      exit;
    end;

  if DriveNr = 0 then
    DriveNr := gemdos_dgetdrv + 1;

  { return a full path, including drive }
  pathbuf[0]:=char(ord('A') + DriveNr - 1);
  pathbuf[1]:=DriveSeparator;

  Dir:=pathbuf;
  SetCodePage(Dir,DefaultSystemCodePage,false);
end;