1 {
2     This file is part of the Free Pascal run time library.
3 
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.
7 
8     See the file COPYING.FPC, included in this distribution,
9     for details about the copyright.
10 
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.
14 
15  **********************************************************************}
16 
17 {
18     History:
19 
20     Added functions and procedures with array of const.
21     For use with fpc 1.0.7. Thay are in systemvartags.
22     11 Nov 2002.
23 
24     Added the defines use_amiga_smartlink and
25     use_auto_openlib.
26     13 Jan 2003.
27 
28     Update for AmigaOS 3.9.
29     Changed startcode for unit.
30     09 Feb 2003.
31 
32     nils.sjoholm@mailbox.swipnet.se
33 }
34 {$PACKRECORDS 2}
35 
36 UNIT lowlevel;
37 
38 INTERFACE
39 USES exec, utility, timer;
40 
41 Type
42 { structure for use with QueryKeys() }
43  pKeyQuery = ^tKeyQuery;
44  tKeyQuery = record
45     kq_KeyCode  : WORD;
46     kq_Pressed  : Boolean;
47  end;
48 
49 {***************************************************************************}
50 
51 Const
52 
53  LOWLEVELNAME : PChar = 'lowlevel.library';
54 
55 { bits in the return value of GetKey() }
56  LLKB_LSHIFT     = 16;
57  LLKB_RSHIFT     = 17;
58  LLKB_CAPSLOCK   = 18;
59  LLKB_CONTROL    = 19;
60  LLKB_LALT       = 20;
61  LLKB_RALT       = 21;
62  LLKB_LAMIGA     = 22;
63  LLKB_RAMIGA     = 23;
64 
65  LLKF_LSHIFT     = 65536;
66  LLKF_RSHIFT     = 131072;
67  LLKF_CAPSLOCK   = 262144;
68  LLKF_CONTROL    = 524288;
69  LLKF_LALT       = 1048576;
70  LLKF_RALT       = 2097152;
71  LLKF_LAMIGA     = 4194304;
72  LLKF_RAMIGA     = 8388608;
73 
74 {***************************************************************************}
75 
76 
77 { Tags for SetJoyPortAttrs() }
78  SJA_Dummy        = (TAG_USER+$c00100);
79  SJA_Type         = (SJA_Dummy+1); { force type to mouse, joy, game cntrlr }
80  SJA_Reinitialize = (SJA_Dummy+2); { free potgo bits, reset to autosense   }
81 
82 { Controller types for SJA_Type tag }
83  SJA_TYPE_AUTOSENSE = 0;
84  SJA_TYPE_GAMECTLR  = 1;
85  SJA_TYPE_MOUSE     = 2;
86  SJA_TYPE_JOYSTK    = 3;
87 
88 
89 {***************************************************************************}
90 
91 
92 { ReadJoyPort() return value definitions }
93 
94 { Port types }
95  JP_TYPE_NOTAVAIL  = 0;          { port data unavailable    }
96  JP_TYPE_GAMECTLR  = 268435456;  { port has game controller }
97  JP_TYPE_MOUSE     = 536870912;  { port has mouse           }
98  JP_TYPE_JOYSTK    = 805306368;  { port has joystick        }
99  JP_TYPE_UNKNOWN   = 1073741824; { port has unknown device  }
100  JP_TYPE_MASK      = -268435456; { controller type          }
101 
102 { Button types, valid for all types except JP_TYPE_NOTAVAIL }
103  JPB_BUTTON_BLUE    = 23;     { Blue - Stop; Right Mouse                }
104  JPB_BUTTON_RED     = 22;     { Red - Select; Left Mouse; Joystick Fire }
105  JPB_BUTTON_YELLOW  = 21;     { Yellow - Repeat                         }
106  JPB_BUTTON_GREEN   = 20;     { Green - Shuffle                         }
107  JPB_BUTTON_FORWARD = 19;     { Charcoal - Forward              }
108  JPB_BUTTON_REVERSE = 18;     { Charcoal - Reverse              }
109  JPB_BUTTON_PLAY    = 17;     { Grey - Play/Pause; Middle Mouse         }
110  JPF_BUTTON_BLUE    = 8388608;
111  JPF_BUTTON_RED     = 4194304;
112  JPF_BUTTON_YELLOW  = 2097152;
113  JPF_BUTTON_GREEN   = 1048576;
114  JPF_BUTTON_FORWARD = 524288;
115  JPF_BUTTON_REVERSE = 262144;
116  JPF_BUTTON_PLAY    = 131072;
117  JP_BUTTON_MASK     = JPF_BUTTON_BLUE OR JPF_BUTTON_RED OR JPF_BUTTON_YELLOW OR JPF_BUTTON_GREEN OR JPF_BUTTON_FORWARD OR JPF_BUTTON_REVERSE OR JPF_BUTTON_PLAY;
118 
119 { Direction types, valid for JP_TYPE_GAMECTLR and JP_TYPE_JOYSTK }
120  JPB_JOY_UP        = 3;
121  JPB_JOY_DOWN      = 2;
122  JPB_JOY_LEFT      = 1;
123  JPB_JOY_RIGHT     = 0;
124  JPF_JOY_UP        = 8;
125  JPF_JOY_DOWN      = 4;
126  JPF_JOY_LEFT      = 2;
127  JPF_JOY_RIGHT     = 1;
128  JP_DIRECTION_MASK = JPF_JOY_UP OR JPF_JOY_DOWN OR JPF_JOY_LEFT OR JPF_JOY_RIGHT;
129 
130 { Mouse position reports, valid for JP_TYPE_MOUSE }
131  JP_MHORZ_MASK     = 255;        { horzizontal position }
132  JP_MVERT_MASK     = 65280;      { vertical position    }
133  JP_MOUSE_MASK     = JP_MHORZ_MASK OR JP_MVERT_MASK;
134 
135 { Obsolete ReadJoyPort() definitions, here for source code compatibility only.
136  * Please do NOT use in new code.
137  }
138  JPB_BTN1  = JPB_BUTTON_BLUE   ;
139  JPF_BTN1  = JPF_BUTTON_BLUE   ;
140  JPB_BTN2  = JPB_BUTTON_RED    ;
141  JPF_BTN2  = JPF_BUTTON_RED    ;
142  JPB_BTN3  = JPB_BUTTON_YELLOW ;
143  JPF_BTN3  = JPF_BUTTON_YELLOW ;
144  JPB_BTN4  = JPB_BUTTON_GREEN  ;
145  JPF_BTN4  = JPF_BUTTON_GREEN  ;
146  JPB_BTN5  = JPB_BUTTON_FORWARD;
147  JPF_BTN5  = JPF_BUTTON_FORWARD;
148  JPB_BTN6  = JPB_BUTTON_REVERSE;
149  JPF_BTN6  = JPF_BUTTON_REVERSE;
150  JPB_BTN7  = JPB_BUTTON_PLAY   ;
151  JPF_BTN7  = JPF_BUTTON_PLAY   ;
152  JPB_UP    = JPB_JOY_UP        ;
153  JPF_UP    = JPF_JOY_UP        ;
154  JPB_DOWN  = JPB_JOY_DOWN      ;
155  JPF_DOWN  = JPF_JOY_DOWN      ;
156  JPB_LEFT  = JPB_JOY_LEFT      ;
157  JPF_LEFT  = JPF_JOY_LEFT      ;
158  JPB_RIGHT = JPB_JOY_RIGHT     ;
159  JPF_RIGHT = JPF_JOY_RIGHT     ;
160 
161 
162 {***************************************************************************}
163 
164 
165 { Tags for SystemControl() }
166  SCON_Dummy         = (TAG_USER+$00C00000);
167  SCON_TakeOverSys   = (SCON_Dummy+0);
168  SCON_KillReq       = (SCON_Dummy+1);
169  SCON_CDReboot      = (SCON_Dummy+2);
170  SCON_StopInput     = (SCON_Dummy+3);
171  SCON_AddCreateKeys = (SCON_Dummy+4);
172  SCON_RemCreateKeys = (SCON_Dummy+5);
173 
174 { Reboot control values for use with SCON_CDReboot tag }
175  CDReboot_On        =     1;
176  CDReboot_Off       =     0;
177  CDReboot_Default   =     2;
178 
179 
180 {***************************************************************************}
181 
182 
183 { Rawkey codes returned when using SCON_AddCreateKeys with SystemControl() }
184 
185  RAWKEY_PORT0_BUTTON_BLUE      =  $72;
186  RAWKEY_PORT0_BUTTON_RED       =  $78;
187  RAWKEY_PORT0_BUTTON_YELLOW    =  $77;
188  RAWKEY_PORT0_BUTTON_GREEN     =  $76;
189  RAWKEY_PORT0_BUTTON_FORWARD   =  $75;
190  RAWKEY_PORT0_BUTTON_REVERSE   =  $74;
191  RAWKEY_PORT0_BUTTON_PLAY      =  $73;
192  RAWKEY_PORT0_JOY_UP           =  $79;
193  RAWKEY_PORT0_JOY_DOWN         =  $7A;
194  RAWKEY_PORT0_JOY_LEFT         =  $7C;
195  RAWKEY_PORT0_JOY_RIGHT        =  $7B;
196 
197  RAWKEY_PORT1_BUTTON_BLUE      =  $172;
198  RAWKEY_PORT1_BUTTON_RED       =  $178;
199  RAWKEY_PORT1_BUTTON_YELLOW    =  $177;
200  RAWKEY_PORT1_BUTTON_GREEN     =  $176;
201  RAWKEY_PORT1_BUTTON_FORWARD   =  $175;
202  RAWKEY_PORT1_BUTTON_REVERSE   =  $174;
203  RAWKEY_PORT1_BUTTON_PLAY      =  $173;
204  RAWKEY_PORT1_JOY_UP           =  $179;
205  RAWKEY_PORT1_JOY_DOWN         =  $17A;
206  RAWKEY_PORT1_JOY_LEFT         =  $17C;
207  RAWKEY_PORT1_JOY_RIGHT        =  $17B;
208 
209  RAWKEY_PORT2_BUTTON_BLUE      =  $272;
210  RAWKEY_PORT2_BUTTON_RED       =  $278;
211  RAWKEY_PORT2_BUTTON_YELLOW    =  $277;
212  RAWKEY_PORT2_BUTTON_GREEN     =  $276;
213  RAWKEY_PORT2_BUTTON_FORWARD   =  $275;
214  RAWKEY_PORT2_BUTTON_REVERSE   =  $274;
215  RAWKEY_PORT2_BUTTON_PLAY      =  $273;
216  RAWKEY_PORT2_JOY_UP           =  $279;
217  RAWKEY_PORT2_JOY_DOWN         =  $27A;
218  RAWKEY_PORT2_JOY_LEFT         =  $27C;
219  RAWKEY_PORT2_JOY_RIGHT        =  $27B;
220 
221  RAWKEY_PORT3_BUTTON_BLUE      =  $372;
222  RAWKEY_PORT3_BUTTON_RED       =  $378;
223  RAWKEY_PORT3_BUTTON_YELLOW    =  $377;
224  RAWKEY_PORT3_BUTTON_GREEN     =  $376;
225  RAWKEY_PORT3_BUTTON_FORWARD   =  $375;
226  RAWKEY_PORT3_BUTTON_REVERSE   =  $374;
227  RAWKEY_PORT3_BUTTON_PLAY      =  $373;
228  RAWKEY_PORT3_JOY_UP           =  $379;
229  RAWKEY_PORT3_JOY_DOWN         =  $37A;
230  RAWKEY_PORT3_JOY_LEFT         =  $37C;
231  RAWKEY_PORT3_JOY_RIGHT        =  $37B;
232 
233 
234 {***************************************************************************}
235 
236 
237 { Return values for GetLanguageSelection() }
238  LANG_UNKNOWN    = 0 ;
239  LANG_AMERICAN   = 1 ;      { American English }
240  LANG_ENGLISH    = 2 ;      { British English  }
241  LANG_GERMAN     = 3 ;
242  LANG_FRENCH     = 4 ;
243  LANG_SPANISH    = 5 ;
244  LANG_ITALIAN    = 6 ;
245  LANG_PORTUGUESE = 7 ;
246  LANG_DANISH     = 8 ;
247  LANG_DUTCH      = 9 ;
248  LANG_NORWEGIAN  = 10;
249  LANG_FINNISH    = 11;
250  LANG_SWEDISH    = 12;
251  LANG_JAPANESE   = 13;
252  LANG_CHINESE    = 14;
253  LANG_ARABIC     = 15;
254  LANG_GREEK      = 16;
255  LANG_HEBREW     = 17;
256  LANG_KOREAN     = 18;
257 
258 
259 {***************************************************************************}
260 
261 
262 { --- functions in V40 or higher (Release 3.1) --- }
263 
264 VAR LowLevelBase : pLibrary = nil;
265 
AddKBIntnull266 FUNCTION AddKBInt(const intRoutine : POINTER location 'a0'; const intData : POINTER location 'a1') : POINTER; syscall LowLevelBase 060;
AddTimerIntnull267 FUNCTION AddTimerInt(const intRoutine : POINTER location 'a0'; const  intData : POINTER location 'a1') : POINTER; syscall LowLevelBase 078;
AddVBlankIntnull268 FUNCTION AddVBlankInt(const intRoutine : POINTER location 'a0'; const intData : POINTER location 'a1') : POINTER; syscall LowLevelBase 108;
ElapsedTimenull269 FUNCTION ElapsedTime(context : pEClockVal location 'a0') : ULONG; syscall LowLevelBase 102;
GetKeynull270 FUNCTION GetKey : ULONG; syscall LowLevelBase 048;
GetLanguageSelectionnull271 FUNCTION GetLanguageSelection : BYTE; syscall LowLevelBase 036;
272 PROCEDURE QueryKeys(queryArray : pKeyQuery location 'a0'; arraySize : ULONG location 'd1'); syscall LowLevelBase 054;
ReadJoyPortnull273 FUNCTION ReadJoyPort(port : ULONG location 'd0') : ULONG; syscall LowLevelBase 030;
274 PROCEDURE RemKBInt(intHandle : POINTER location 'a1'); syscall LowLevelBase 066;
275 PROCEDURE RemTimerInt(intHandle : POINTER location 'a1'); syscall LowLevelBase 084;
276 PROCEDURE RemVBlankInt(intHandle : POINTER location 'a1'); syscall LowLevelBase 114;
SetJoyPortAttrsAnull277 FUNCTION SetJoyPortAttrsA(portNumber : ULONG location 'd0'; const tagList : pTagItem location 'a1') : LongBool; syscall LowLevelBase 132;
278 PROCEDURE StartTimerInt(intHandle : POINTER location 'a1'; timeInterval : ULONG location 'd0'; continuous : LONGINT location 'd1'); syscall LowLevelBase 096;
279 PROCEDURE StopTimerInt(intHandle : POINTER location 'a1'); syscall LowLevelBase 090;
SystemControlAnull280 FUNCTION SystemControlA(const tagList : pTagItem location 'a1') : ULONG; syscall LowLevelBase 072;
281 
SetJoyPortAttrsnull282 function SetJoyPortAttrs(portNumber : ULONG; Const argv : array of PtrUInt) : BOOLEAN;
SystemControlnull283 function SystemControl(Const argv : array of PtrUInt) : ULONG;
284 
285 IMPLEMENTATION
286 
SetJoyPortAttrsnull287 function SetJoyPortAttrs(portNumber : ULONG; Const argv : array of PtrUInt) : BOOLEAN;
288 begin
289     SetJoyPortAttrs := SetJoyPortAttrsA(portNumber,@argv);
290 end;
291 
SystemControlnull292 function SystemControl(Const argv : array of PtrUInt) : ULONG;
293 begin
294     SystemControl := SystemControlA(@argv);
295 end;
296 
297 const
298     { Change VERSION and LIBVERSION to proper values }
299     VERSION : string[2] = '0';
300     LIBVERSION : longword = 0;
301 
302 initialization
303   LowLevelBase := OpenLibrary(LOWLEVELNAME,LIBVERSION);
304 finalization
305   if Assigned(LowLevelBase) then
306     CloseLibrary(LowLevelBase);
307 END. (* UNIT LOWLEVEL *)
308 
309 
310 
311 
312