2
This file is part of the Free Pascal run time library.
4
A file in Amiga system run time library.
5
Copyright (c) 1998-2003 by Nils Sjoholm
6
member of the Amiga RTL development team.
8
See the file COPYING.FPC, included in this distribution,
9
for details about the copyright.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
**********************************************************************}
20
Added DoMethodA, DoSuperMethodA, CoerceMethodA and SetSuperAttrsA.
22
I've translated those from amigae. I'm not sure that they are
23
correct but it's a start. Now you can try to make some tests
27
Added stuff for commodities.
37
Rewrote Createport and DeletePort.
40
Added two printf, one with pchar and one with string.
41
They use array of const so this unit compiles with
45
Added the define use_amiga_smartlink
48
nils.sjoholm@mailbox.swipnet.se
52
{$I useamigasmartlink.inc}
53
{$ifdef use_amiga_smartlink}
55
{$endif use_amiga_smartlink}
62
uses exec,intuition,utility,commodities,inputevent,amigados;
64
{* Exec support functions from amiga.lib *}
66
procedure BeginIO (ioRequest: pIORequest);
67
function CreateExtIO (port: pMsgPort; size: Longint): pIORequest;
68
procedure DeleteExtIO (ioReq: pIORequest);
69
function CreateStdIO (port: pMsgPort): pIOStdReq;
70
procedure DeleteStdIO (ioReq: pIOStdReq);
71
function CreatePort (name: PChar; pri: longint): pMsgPort;
72
procedure DeletePort (port: pMsgPort);
73
function CreateTask (name: STRPTR; pri: longint;
75
stackSize : ULONG): pTask;
76
procedure DeleteTask (task: pTask);
77
procedure NewList (list: pList);
79
{* Commodities support functions from amiga.lib *}
80
procedure FreeIEvents (events: pInputEvent);
85
function CxDebug (id: long): pCxObj;
86
function CxFilter (d: STRPTR): pCxObj;
95
function CxTranslate (ie: pInputEvent): pCxObj;
98
function DoMethodA(obj : pObject_; msg : APTR): ulong;
99
function DoSuperMethodA(cl : pIClass; obj : pObject_; msg : APTR): ulong;
100
function CoerceMethodA(cl : pIClass; obj : pObject_; msg : APTR): ulong;
101
function SetSuperAttrsA(cl : pIClass; obj: pObject_; msg : APTR): ulong;
106
printf - print a formatted output line to the standard output.
109
printf(formatstring [,value [,values] ] );
112
Format the output in accordance with specifications in the format
116
formatString - a C-language-like NULL-terminated format string,
117
with the following supported % options:
119
%[flags][width][.limit][length]type
121
$ - must follow the arg_pos value, if specified
122
flags - only one allowed. '-' specifies left justification.
123
width - field width. If the first character is a '0', the
124
field is padded with leading 0s.
125
. - must precede the field width value, if specified
126
limit - maximum number of characters to output from a string.
127
(only valid for %s or %b).
128
length - size of input data defaults to word (16-bit) for types c,
129
d, u and x, 'l' changes this to long (32-bit).
130
type - supported types are:
131
b - BSTR, data is 32-bit BPTR to byte count followed
132
by a byte string. A NULL BPTR is treated as an
136
x - hexadecimal with hex digits in uppercase
137
X - hexadecimal with hex digits in lowercase
138
s - string, a 32-bit pointer to a NULL-terminated
139
byte string. A NULL pointer is treated
143
value(s) - numeric variables or addresses of null-terminated strings
144
to be added to the format information.
147
The global "_stdout" must be defined, and contain a pointer to
148
a legal AmigaDOS file handle. Using the standard Amiga startup
149
module sets this up. In other cases you will need to define
150
stdout, and assign it to some reasonable value (like what the
151
dos.library/Output() call returns). This code would set it up:
157
This function will crash if the resulting stream after
158
parameter substitution is longer than 140 bytes.
162
procedure printf(Fmtstr : pchar; Args : array of const);
163
procedure printf(Fmtstr : string; Args : array of const);
169
{* Exec support functions from amiga.lib *}
171
procedure BeginIO (ioRequest: pIORequest);
175
move.l ioRequest,a1 ; get IO Request
176
move.l 20(a1),a6 ; extract Device ptr
177
jsr -30(a6) ; call BEGINIO directly
182
function CreateExtIO (port: pMsgPort; size: Longint): pIORequest;
189
IOReq := AllocMem(size, MEMF_CLEAR or MEMF_PUBLIC);
192
IOReq^.io_Message.mn_Node.ln_Type := NT_REPLYMSG;
193
IOReq^.io_Message.mn_Length := size;
194
IOReq^.io_Message.mn_ReplyPort := port;
197
CreateExtIO := IOReq;
201
procedure DeleteExtIO (ioReq: pIORequest);
205
ioReq^.io_Message.mn_Node.ln_Type := $FF;
206
ioReq^.io_Message.mn_ReplyPort := pMsgPort(-1);
207
ioReq^.io_Device := pDevice(-1);
208
ExecFreeMem(ioReq, ioReq^.io_Message.mn_Length);
213
function CreateStdIO (port: pMsgPort): pIOStdReq;
215
CreateStdIO := pIOStdReq(CreateExtIO(port, sizeof(tIOStdReq)))
219
procedure DeleteStdIO (ioReq: pIOStdReq);
221
DeleteExtIO(pIORequest(ioReq))
225
function Createport(name : PChar; pri : longint): pMsgPort;
230
sigbit := AllocSignal(-1);
231
if sigbit = -1 then CreatePort := nil;
232
port := Allocmem(sizeof(tMsgPort),MEMF_CLEAR or MEMF_PUBLIC);
233
if port = nil then begin
238
if assigned(name) then
239
mp_Node.ln_Name := name
240
else mp_Node.ln_Name := nil;
241
mp_Node.ln_Pri := pri;
242
mp_Node.ln_Type := NT_MsgPort;
243
mp_Flags := PA_Signal;
245
mp_SigTask := FindTask(nil);
247
if assigned(name) then AddPort(port)
248
else NewList(addr(port^.mp_MsgList));
252
procedure DeletePort (port: pMsgPort);
256
if port^.mp_Node.ln_Name <> NIL then
259
port^.mp_Node.ln_Type := $FF;
260
port^.mp_MsgList.lh_Head := pNode(-1);
261
FreeSignal(port^.mp_SigBit);
262
ExecFreeMem(port, sizeof(tMsgPort));
267
function CreateTask (name: STRPTR; pri: longint;
268
initPC: pointer; stackSize: ULONG): pTask;
275
stackSize := (stackSize + 3) and not 3;
276
totalsize := sizeof(tMemList) + sizeof(tTask) + stackSize;
278
memlist := AllocMem(totalsize, MEMF_PUBLIC + MEMF_CLEAR);
279
if memlist <> NIL then begin
280
memlist^.ml_NumEntries := 1;
281
memlist^.ml_ME[0].me_Un.meu_Addr := Pointer(memlist + 1);
282
memlist^.ml_ME[0].me_Length := totalsize - sizeof(tMemList);
284
task := pTask(memlist + sizeof(tMemList) + stackSize);
285
task^.tc_Node.ln_Pri := pri;
286
task^.tc_Node.ln_Type := NT_TASK;
287
task^.tc_Node.ln_Name := name;
288
task^.tc_SPLower := Pointer(memlist + sizeof(tMemList));
289
task^.tc_SPUpper := Pointer(task^.tc_SPLower + stackSize);
290
task^.tc_SPReg := task^.tc_SPUpper;
292
NewList(@task^.tc_MemEntry);
293
AddTail(@task^.tc_MemEntry,@memlist^.ml_Node);
295
AddTask(task,initPC,NIL)
301
procedure DeleteTask (task: pTask);
307
procedure NewList (list: pList);
311
lh_Head := pNode(@lh_Tail);
313
lh_TailPred := pNode(@lh_Head)
317
procedure FreeIEvents (events: pInputEvent);
319
while events <> NIL do
321
FreeMem (events, sizeof (tInputEvent));
322
events := events^.ie_NextEvent
328
id: longint): pCxObj;
330
CxCustom := CreateCxObj(CX_CUSTOM, longint(action), id)
333
function CxDebug (id: long): pCxObj;
335
CxDebug := CreateCxObj(CX_DEBUG, id, 0)
338
function CxFilter (d: STRPTR): pCxObj;
340
CxFilter := CreateCxObj(CX_FILTER, longint(d), 0)
345
id: longint): pCxObj;
347
CxSender := CreateCxObj(CX_SEND, longint(port), id)
354
CxSignal:= CreateCxObj(CX_SIGNAL, longint(task), sig)
357
function CxTranslate (ie: pInputEvent): pCxObj;
359
CxTranslate := CreateCxObj(CX_TRANSLATE, longint(ie), 0)
362
function DoMethodA(obj : pObject_; msg : APTR): ulong;
366
if assigned(obj) then begin
368
DoMethodA := CallHookPkt(@o^.o_Class^.cl_Dispatcher, obj,msg);
369
end else DoMethodA := 0;
372
function DoSuperMethodA(cl : pIClass; obj : pObject_; msg : APTR): ulong;
374
if assigned(obj) and assigned(cl) then
375
DoSuperMethodA := CallHookPkt(@cl^.cl_Super^.cl_Dispatcher,obj,msg)
376
else DoSuperMethodA := 0;
379
function CoerceMethodA(cl : pIClass; obj : pObject_; msg : APTR): ulong;
381
if assigned(cl) and assigned(obj) then
382
CoerceMethodA := CallHookPkt(@cl^.cl_Dispatcher,obj,msg)
383
else CoerceMethodA := 0;
386
function SetSuperAttrsA(cl : pIClass; obj: pObject_; msg : APTR): ulong;
388
arr : array[0..2] of longint;
391
arr[1] := longint(msg);
393
SetSuperAttrsA := DoSuperMethodA(cl, obj, @arr);
397
argarray : array [0..20] of longint;
399
function gettheconst(args : array of const): pointer;
405
for i := 0 to High(args) do begin
406
case args[i].vtype of
407
vtinteger : argarray[i] := longint(args[i].vinteger);
408
vtpchar : argarray[i] := longint(args[i].vpchar);
409
vtchar : argarray[i] := longint(args[i].vchar);
410
vtpointer : argarray[i] := longint(args[i].vpointer);
411
vtstring : argarray[i] := longint(pas2c(args[i].vstring^));
414
gettheconst := @argarray;
417
procedure printf(Fmtstr : pchar; Args : array of const);
419
VPrintf(Fmtstr,gettheconst(Args));
422
procedure printf(Fmtstr : string; Args : array of const);
424
VPrintf(pas2c(Fmtstr) ,gettheconst(Args));