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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
unit system;
interface
{$define FPC_IS_SYSTEM}
{ The heap for ZX Spectrum is implemented
in tinyheap.inc include file,
but it uses default SysGetMem names }
{$define HAS_MEMORYMANAGER}
{ Use Ansi Char for files }
{$define FPC_ANSI_TEXTFILEREC}
{$define FPC_STDOUT_TRUE_ALIAS}
{$I systemh.inc}
{$I tnyheaph.inc}
{$ifndef FPUNONE}
{$ifdef FPC_HAS_FEATURE_SOFTFPU}
{$define fpc_softfpu_interface}
{$i softfpu.pp}
{$undef fpc_softfpu_interface}
{$endif FPC_HAS_FEATURE_SOFTFPU}
{$endif FPUNONE}
var
{ Mem[] support }
mem : array[0..$7fff-1] of byte absolute $0;
{ memw : array[0..($7fff div sizeof(word))-1] of word absolute $0:$0;
meml : array[0..($7fff div sizeof(longint))-1] of longint absolute $0:$0;}
{ OpenChannel(2) opens the upper screen
OpenChannel(1) opens the lower screen
OpenChannel(3) opens the ZX Printer }
procedure OpenChannel(Chan: Byte);
procedure PrintChar(Ch: Char);
procedure PrintLn;
procedure PrintShortString(const s: ShortString);
procedure PrintHexDigit(const d: byte);
procedure PrintHexByte(const b: byte);
procedure PrintHexWord(const w: word);
procedure Ink(colour: Byte);
procedure Paper(colour: Byte);
procedure GotoXY(X, Y: Byte);
function ReadKey: Char;
function KeyPressed: Boolean;
implementation
const
LineEnding = #13#10;
{ LFNSupport is a variable here, defined below!!! }
DirectorySeparator = '\';
DriveSeparator = ':';
ExtensionSeparator = '.';
PathSeparator = ';';
AllowDirectorySeparators : set of char = ['\','/'];
AllowDriveSeparators : set of char = [':'];
{ FileNameCaseSensitive and FileNameCasePreserving are defined separately below!!! }
maxExitCode = 255;
MaxPathLen = 256;
{ Default filehandles }
UnusedHandle = $ffff;{ instead of -1, as it is a word value}
StdInputHandle = 0;
StdOutputHandle = 1;
StdErrorHandle = 2;
FileNameCaseSensitive : boolean = false;
FileNameCasePreserving: boolean = false;
CtrlZMarksEOF: boolean = true; (* #26 is considered as end of file *)
sLineBreak = LineEnding;
DefaultTextLineBreakStyle : TTextLineBreakStyle = tlbsCRLF;
{$I system.inc}
{$I tinyheap.inc}
{$ifndef FPUNONE}
{$ifdef FPC_HAS_FEATURE_SOFTFPU}
{$define fpc_softfpu_implementation}
{$i softfpu.pp}
{$undef fpc_softfpu_implementation}
{ we get these functions and types from the softfpu code }
{$define FPC_SYSTEM_HAS_float64}
{$define FPC_SYSTEM_HAS_float32}
{$define FPC_SYSTEM_HAS_flag}
{$define FPC_SYSTEM_HAS_extractFloat64Frac0}
{$define FPC_SYSTEM_HAS_extractFloat64Frac1}
{$define FPC_SYSTEM_HAS_extractFloat64Exp}
{$define FPC_SYSTEM_HAS_extractFloat64Frac}
{$define FPC_SYSTEM_HAS_extractFloat64Sign}
{$define FPC_SYSTEM_HAS_ExtractFloat32Frac}
{$define FPC_SYSTEM_HAS_extractFloat32Exp}
{$define FPC_SYSTEM_HAS_extractFloat32Sign}
{$endif FPC_HAS_FEATURE_SOFTFPU}
{$endif FPUNONE}
procedure randomize;
begin
end;
function GetProcessID: SizeUInt;
begin
GetProcessID:=0;
end;
function CheckInitialStkLen(stklen : SizeUInt) : SizeUInt;
begin
result := stklen;
end;
procedure system_exit;
begin
repeat
until false;
end;
var
save_iy: Word; public name 'FPC_SAVE_IY';
LastKey: Char absolute 23560;
function ReadKey: Char;
begin
repeat
ReadKey:=LastKey;
until ReadKey<>#0;
LastKey:=#0;
end;
function KeyPressed: Boolean;
begin
KeyPressed:=LastKey<>#0;
end;
procedure OpenChannel(Chan: Byte);
begin
asm
ld iy,(save_iy)
ld a, (Chan)
push ix
call 5633
pop ix
ld (save_iy),iy
end;
end;
procedure PrintChar(Ch: Char);
begin
asm
ld iy,(save_iy)
ld a, (Ch)
push ix
rst 16
pop ix
ld (save_iy),iy
end;
end;
procedure PrintLn;
begin
PrintChar(#13);
end;
procedure PrintHexDigit(const d: byte);
begin
{ the code generator is still to broken to compile this, so we do it in a stupid way }
{ if (d >= 0) or (d <= 9) then
PrintChar(Char(d + Ord('0')))
else if (d >= 10) and (d <= 15) then
PrintChar(Char(d + (Ord('A') - 10)));}
if d=0 then
PrintChar('0')
else if d=1 then
PrintChar('1')
else if d=2 then
PrintChar('2')
else if d=3 then
PrintChar('3')
else if d=4 then
PrintChar('4')
else if d=5 then
PrintChar('5')
else if d=6 then
PrintChar('6')
else if d=7 then
PrintChar('7')
else if d=8 then
PrintChar('8')
else if d=9 then
PrintChar('9')
else if d=10 then
PrintChar('A')
else if d=11 then
PrintChar('B')
else if d=12 then
PrintChar('C')
else if d=13 then
PrintChar('D')
else if d=14 then
PrintChar('E')
else if d=15 then
PrintChar('F')
else
PrintChar('?');
end;
procedure PrintHexByte(const b: byte);
begin
PrintHexDigit(b shr 4);
PrintHexDigit(b and $F);
end;
procedure PrintHexWord(const w: word);
begin
PrintHexByte(Byte(w shr 8));
PrintHexByte(Byte(w));
end;
procedure Ink(colour: Byte);
begin
PrintChar(#16);
PrintChar(Char(colour));
end;
procedure Paper(colour: Byte);
begin
PrintChar(#17);
PrintChar(Char(colour));
end;
procedure GotoXY(X, Y: Byte);
begin
PrintChar(#22);
PrintChar(Char(X-1));
PrintChar(Char(Y-1));
end;
procedure PrintShortString(const s: ShortString);
var
i: byte;
begin
for i:=1 to length(s) do
PrintChar(s[i]);
end;
{*****************************************************************************
SystemUnit Initialization
*****************************************************************************}
var
ZXHeap: array [0..{1023}255] of Byte;
procedure InitZXHeap;
begin
RegisterTinyHeapBlock_Simple_Prealigned(@ZXHeap[0],SizeOf(ZXHeap));
end;
procedure SysInitStdIO;
begin
(* TODO: doesn't work yet...
OpenStdIO(Input,fmInput,StdInputHandle);
OpenStdIO(Output,fmOutput,StdOutputHandle);
OpenStdIO(ErrOutput,fmOutput,StdErrorHandle);
{$ifndef FPC_STDOUT_TRUE_ALIAS}
OpenStdIO(StdOut,fmOutput,StdOutputHandle);
OpenStdIO(StdErr,fmOutput,StdErrorHandle);
{$endif FPC_STDOUT_TRUE_ALIAS}
*)
end;
begin
{ StackBottom := __stkbottom;
StackLength := __stktop - __stkbottom;}
{ To be set if this is a GUI or console application }
IsConsole := TRUE;
{$ifdef FPC_HAS_FEATURE_DYNLIBS}
{ If dynlibs feature is disabled,
IsLibrary is a constant, which can thus not be set to a value }
{ To be set if this is a library and not a program }
IsLibrary := FALSE;
{$endif def FPC_HAS_FEATURE_DYNLIBS}
{ Setup heap }
InitZXHeap;
SysInitExceptions;
{$ifdef FPC_HAS_FEATURE_UNICODESTRINGS}
initunicodestringmanager;
{$endif def FPC_HAS_FEATURE_UNICODESTRINGS}
{ Setup stdin, stdout and stderr }
SysInitStdIO;
{ Reset IO Error }
InOutRes:=0;
{$ifdef FPC_HAS_FEATURE_THREADING}
InitSystemThreads;
{$endif}
end.
|