1 #ifndef __DEFAULT_H
2 #define __DEFAULT_H
3 
4 #define asm __asm__ /* for ANSI mode compiling */
5 
6 #define _main __main
7 
8 #define __ATTR_STD__ __attribute__((__stkparm__))
9 #define __ATTR_STD_NORETURN__ __attribute__((__stkparm__,__noreturn__))
10 #define CALLBACK __ATTR_STD__
11 #define __ATTR_TIOS__ __ATTR_STD__
12 #define __ATTR_TIOS_NORETURN__ __ATTR_STD_NORETURN__
13 #define __ATTR_TIOS_CALLBACK__ CALLBACK
14 #define __ATTR_GCC__
15 #define __ATTR_LIB_C__ __attribute__((__regparm__(4)))
16 #define __ATTR_LIB_ASM__ __ATTR_STD__
17 #define __ATTR_LIB_ASM_NORETURN__ __ATTR_STD_NORETURN__
18 #define __ATTR_LIB_CALLBACK_C__ CALLBACK
19 #define __ATTR_LIB_CALLBACK_ASM__ CALLBACK
20 
21 #ifndef FARGO
22 
23 #ifdef USE_TI92P
24 #define USE_TI92PLUS
25 #endif
26 
27 #ifdef USE_TI89
28 asm (".xdef _ti89");
29 asm (".xdef _ti89ti");
30 #if !defined (USE_TI92PLUS) && !defined (USE_V200)
31 #define _TI89_ONLY
32 #define _ONE_CALC_ONLY
33 #endif
34 #endif
35 
36 #ifdef USE_TI92PLUS
37 asm (".xdef _ti92plus");
38 #if !defined (USE_TI89) && !defined (USE_V200)
39 #define _TI92PLUS_ONLY
40 #define _ONE_CALC_ONLY
41 #endif
42 #endif
43 
44 #ifdef USE_V200
45 asm (".xdef _v200");
46 #if !defined (USE_TI89) && !defined (USE_TI92PLUS)
47 #define _V200_ONLY
48 #define _ONE_CALC_ONLY
49 #endif
50 #endif
51 
52 #if !defined (USE_TI89) && !defined (USE_TI92PLUS) && !defined (USE_V200)
53 /* The program uses its own symbols to control the linker.
54    So support all calcs. */
55 #define USE_TI89
56 #define USE_TI92PLUS
57 #define USE_V200
58 #endif
59 
60 #if defined (USE_TI89) && defined (USE_TI92PLUS) && defined (USE_V200)
61 #define _SUPPORT_ALL_CALCS
62 #endif
63 
64 #ifdef _NO_INCLUDE_PATCH
65 #define _INCLUDE_PATCH(patchname)
66 #else
67 #define _INCLUDE_PATCH(patchname) asm(".xdef __ref_all_"#patchname)
68 #endif
69 
70 /* Quick hacks for better archive support. */
71 #ifdef _GENERIC_ARCHIVE
72 #ifndef NO_CALC_DETECT
73 #define NO_CALC_DETECT
74 #endif
75 #undef OPTIMIZE_ROM_CALLS
76 #undef USE_FLINE_ROM_CALLS
77 #undef USE_FLINE_JUMPS
78 #undef USE_4_BYTE_FLINE_JUMPS
79 #undef USE_INTERNAL_FLINE_EMULATOR
80 #undef KERNEL_FORMAT_RELOCS
81 #undef KERNEL_FORMAT_ROM_CALLS
82 #undef KERNEL_FORMAT_BSS
83 #undef COMPRESSED_FORMAT_RELOCS
84 #undef COMPRESSED_FORMAT_ROM_CALLS
85 #undef COMPRESSED_FORMAT_BSS
86 #undef MLINK_FORMAT_RELOCS
87 #undef MLINK_FORMAT_ROM_CALLS
88 #undef MLINK_FORMAT_BSS
89 #ifndef MIN_AMS
90 #define MIN_AMS 100
91 #endif
92 #else
93 _INCLUDE_PATCH(__startup_code);
94 #ifndef MIN_AMS
95 #define MIN_AMS 101
96 #endif
97 #endif
98 
99 #ifdef EXECUTE_IN_GHOST_SPACE
100 #if defined(USE_KERNEL) || defined(DOORS)
101 #error EXECUTE_IN_GHOST_SPACE does not work in kernel mode yet
102 #endif
103 _INCLUDE_PATCH(__execute_in_ghost_space);
104 #endif
105 
106 #ifndef NO_CALC_DETECT
107 #if !defined (_SUPPORT_ALL_CALCS)
108 #define _NEED_CALC_DETECT
109  _INCLUDE_PATCH(__detect_calc);
110 #ifdef _ONE_CALC_ONLY
111   _INCLUDE_PATCH(__test_for_specific_calc);
112 #ifdef USE_TI89
113    _INCLUDE_PATCH(__test_for_89);
114 #endif
115 #ifdef USE_TI92PLUS
116    _INCLUDE_PATCH(__test_for_92p);
117 #endif
118 #ifdef USE_V200
119    _INCLUDE_PATCH(__test_for_v200);
120 #endif
121 #else
122   _INCLUDE_PATCH(__test_against_specific_calc);
123 #ifndef USE_TI89
124    _INCLUDE_PATCH(__test_for_89);
125 #endif
126 #ifndef USE_TI92PLUS
127    _INCLUDE_PATCH(__test_for_92p);
128 #endif
129 #ifndef USE_V200
130    _INCLUDE_PATCH(__test_for_v200);
131 #endif
132 #endif
133 #elif defined (OPTIMIZE_CALC_CONSTS)
134 #define _NEED_CALC_DETECT
135  _INCLUDE_PATCH(__detect_calc);
136  _INCLUDE_PATCH(__test_for_specific_calc);
137  _INCLUDE_PATCH(__test_for_any_calc);
138 #endif
139 #endif
140 
141 #if (!defined (NO_AMS_CHECK)) && ((MIN_AMS>101 && (defined (USE_TI89))) || (MIN_AMS>100 && (defined (USE_TI92PLUS))) || (MIN_AMS>206 && (defined (USE_V200))))
142 #define _NEED_AMS_CHECK
143  _INCLUDE_PATCH(__MIN_AMS_required);
144 #if (MIN_AMS>=300)
145   _INCLUDE_PATCH(__MIN_AMS_3_00);
146 #if (MIN_AMS>300)
147 #warning Cannot check for AMS versions greater than 3.00
148 #endif
149 #elif (MIN_AMS>=209)
150   _INCLUDE_PATCH(__MIN_AMS_2_09);
151 #if (MIN_AMS>209)
152 #warning Cannot check for AMS versions between 2.09 and 3.00
153 #endif
154 #elif (MIN_AMS>=208)
155   _INCLUDE_PATCH(__MIN_AMS_2_08);
156 #elif (MIN_AMS>=207)
157   _INCLUDE_PATCH(__MIN_AMS_2_07);
158 #elif (MIN_AMS>=205)
159   _INCLUDE_PATCH(__MIN_AMS_2_05);
160 #if (MIN_AMS>205)
161 #warning Cannot check for AMS version 2.06
162 #endif
163 #elif (MIN_AMS>=204)
164   _INCLUDE_PATCH(__MIN_AMS_2_04);
165 #elif (MIN_AMS>=203)
166   _INCLUDE_PATCH(__MIN_AMS_2_03);
167 #elif (MIN_AMS>=202)
168   _INCLUDE_PATCH(__MIN_AMS_2_02);
169 #elif (MIN_AMS>=201)
170   _INCLUDE_PATCH(__MIN_AMS_2_01);
171 #elif (MIN_AMS>=200)
172   _INCLUDE_PATCH(__MIN_AMS_2_00);
173 #elif (MIN_AMS>=105)
174   _INCLUDE_PATCH(__MIN_AMS_1_05);
175 #if (MIN_AMS>105)
176 #warning Cannot check for AMS versions between 1.05 and 2.00
177 #endif
178 #elif (MIN_AMS>=101)
179   _INCLUDE_PATCH(__MIN_AMS_1_01);
180 #if (MIN_AMS>101)
181 #warning Cannot check for AMS versions between 1.01 and 1.05
182 #endif
183 #endif
184 #endif
185 
186 /* The following auto-generated definitions are preliminary and possibly overridden later by other files. */
187 
188 #define __rom_call_addr_concat _rom_call_addr_concat
189 
190 /* Begin Auto-Generated Part */
191 #define MIN_AMS_MAJOR (MIN_AMS/100)
192 #define MIN_AMS_MINOR (MIN_AMS%100)
193 #define __jmp_tbl (*(void***)0xC8)
194 #define _rom_call_addr_concat(intindex,romindex) (__jmp_tbl[intindex])
195 #define _rom_call_addr_hack_concat(intindex,romindex,addr,minams,minindex) (MIN_AMS >= (minams) || TIOS_entries > (minindex) ? _rom_call_addr_concat (intindex, romindex) : ({ asm (".xdef __ref_all___reject_unofficial_os"); (void *) (addr); }))
196 #define _rom_call_addr_hack(index,addr,minams) (_rom_call_addr_hack_concat(0x##index,_ROM_CALL_##index,(addr),(minams),0x##index))
197 #define _rom_call_addr(index) (_rom_call_addr_concat(0x##index,_ROM_CALL_##index))
198 #define _rom_call_attr(type,args,attr,index) (*({typedef __ATTR_TIOS__ attr type(*__temp__type__)args;(__temp__type__)(__rom_call_addr_concat(0x##index,_ROM_CALL_##index));}))
199 #define _rom_call_concat(type,args,intindex,romindex) (*((type(*__ATTR_TIOS__)args)(__rom_call_addr_concat(intindex,romindex))))
200 #define _rom_call_hack_attr_concat(type,args,attr,intindex,romindex,addr,minams,minindex) (*({ typedef __ATTR_TIOS__ attr type (*__temp__type__hack__) args; (__temp__type__hack__) (MIN_AMS >= (minams) || TIOS_entries > (minindex) ? (const void *) (&(_rom_call_concat (void, (void), (intindex), (romindex)))) : ({ asm (".xdef __ref_all___reject_unofficial_os"); (const void *) (addr); })); }))
201 #define _rom_call_hack_attr(type,args,attr,index,addr,minams) (_rom_call_hack_attr_concat(type,args,attr,0x##index,_ROM_CALL_##index,(addr),(minams),0x##index))
202 #define _rom_call_hack(type,args,index,addr,minams) (_rom_call_hack_attr_concat(type,args,,0x##index,_ROM_CALL_##index,(addr),(minams),0x##index))
203 #define _rom_call(type,args,index) (_rom_call_concat(type,args,0x##index,_ROM_CALL_##index))
204 #define import_binary(filename,symname) asm(".globl "#symname"\n"#symname":\n\t.incbin \""filename"\"")
205 /* End Auto-Generated Part */
206 
207 #define TIOS_entries (*(unsigned long*)(__jmp_tbl-1))
208 
209 #ifdef UNOFFICIAL_OS_SUPPORT
210 #undef _rom_call_hack_attr_concat
211 #define _rom_call_hack_attr_concat(type,args,attr,intindex,romindex,addr,minams) (*({typedef __ATTR_TIOS__ attr type(*__temp__type__hack__)args;(__temp__type__hack__)(MIN_AMS>=(minams)||TIOS_entries>(intindex)?(const void*)(&(_rom_call_concat(void,(void),(intindex),(romindex)))):(const void*)__invalid_rom_call_hack);}))
212 #undef _rom_call_addr_hack_concat
213 #define _rom_call_addr_hack_concat(intindex,romindex,addr,minams,minindex) (MIN_AMS>=(minams)||TIOS_entries>(minindex)?_rom_call_addr_concat(intindex,romindex):__invalid_rom_call_hack)
214 extern void *__invalid_rom_call_hack;
215 #endif
216 
217 #ifdef REJECT_UNOFFICIAL_OS
218 _INCLUDE_PATCH(__reject_unofficial_os);
219 #endif
220 
221 #ifdef USE_INTERNAL_FLINE_EMULATOR
222 _INCLUDE_PATCH(__fline_internal_emulator);
223 #else
224 #if defined (USE_4_BYTE_FLINE_JUMPS)
225 #error You need to define USE_INTERNAL_FLINE_EMULATOR for 4-byte F-Line jumps
226 #elif defined (USE_FLINE_ROM_CALLS) || defined (USE_FLINE_JUMPS)
227 #if (MIN_AMS < 204) && !defined (USE_FLINE_EMULATOR)
228 #error You need to define USE_[INTERNAL_]FLINE_EMULATOR or an appropriate value for MIN_AMS
229 #endif
230 #endif
231 #endif
232 
233 #ifdef USE_FLINE_ROM_CALLS
234 _INCLUDE_PATCH(__fline_rom_calls);
235 asm(".set _F_LINE,0xF800");
236 #endif
237 #ifdef USE_4_BYTE_FLINE_JUMPS
238 _INCLUDE_PATCH(__fline_jumps_4byte);
239 asm(".xdef __ld_use_4byte_fline_jumps");
240 #else
241 #ifdef USE_FLINE_JUMPS
242 _INCLUDE_PATCH(__fline_jumps);
243 asm(".xdef __ld_use_fline_jumps");
244 #endif
245 #endif
246 
247 asm(".set _A_LINE,0xA000");
248 
249 #define __need_in_use_bit _INCLUDE_PATCH(__set_file_in_use_bit);
250 
251 #ifdef SET_FILE_IN_USE_BIT
252 __need_in_use_bit;
253 #endif
254 
255 #ifndef _GENERIC_ARCHIVE
256 #ifdef COMPRESSED_FORMAT_DATA_VAR
257 _INCLUDE_PATCH(__compressed_format_data_var);
258 #else
259 #ifdef MLINK_FORMAT_DATA_VAR
260 _INCLUDE_PATCH(__mlink_format_data_var);
261 #else
262 _INCLUDE_PATCH(__kernel_format_data_var);
263 #endif
264 #endif
265 #endif
266 
267 #if defined (DOORS) || defined (USE_KERNEL)
268 
269 #if MIN_AMS >= 200
270 #define AMS_1xx 0
271 #else
272 #define AMS_1xx ((_ram_call(14,unsigned short)&0x0F00)==0x100)
273 #endif
274 #if MIN_AMS >= 300
275 #define AMS_2xx 0
276 #else
277 #define AMS_2xx ((_ram_call(14,unsigned short)&0x0F00)==0x200)
278 #endif
279 #define AMS_3xx ((_ram_call(14,unsigned short)&0x0F00)==0x300)
280 
281 #else
282 
283 #if MIN_AMS >= 200
284 #define AMS_1xx 0
285 #else
286 #define AMS_1xx (TIOS_entries<1000)
287 #endif
288 #if MIN_AMS >= 300
289 #define AMS_2xx 0
290 #define AMS_3xx 1
291 #else
292 #define AMS_2xx (!AMS_1xx && TIOS_entries<0x608)
293 #define AMS_3xx (TIOS_entries>=0x608)
294 #endif
295 
296 #endif
297 
298 #endif
299 
300 #ifdef OMIT_BSS_INIT
301 asm(".xdef __ld_omit_bss_init");
302 #endif
303 
304 #ifndef __PINT
305 #define __PINT
306 
307 #ifdef __INT_SHORT__
308 
309 typedef union
310   {
311     short *__sp;
312     int *__ip;
313 #ifndef STRICT_POINTERS
314     unsigned short *__usp;
315     unsigned int *__uip;
316 #endif
317   } __pshort __attribute__((__transparent_union__));
318 
319 typedef union
320   {
321     unsigned short *__sp;
322     unsigned int *__ip;
323 #ifndef STRICT_POINTERS
324     short *__ssp;
325     int *__sip;
326 #endif
327   } __pushort __attribute__((__transparent_union__));
328 
329 typedef long *__plong;
330 typedef unsigned long *__pulong;
331 
332 typedef union
333   {
334     const short *__sp;
335     const int *__ip;
336 #ifndef STRICT_POINTERS
337     const unsigned short *__usp;
338     const unsigned int *__uip;
339 #endif
340   } __cpshort __attribute__((__transparent_union__));
341 
342 typedef union
343   {
344     const unsigned short *__sp;
345     const unsigned int *__ip;
346 #ifndef STRICT_POINTERS
347     const short *__ssp;
348     const int *__sip;
349 #endif
350   } __cpushort __attribute__((__transparent_union__));
351 
352 typedef const long *__cplong;
353 typedef const unsigned long *__cpulong;
354 
355 #else
356 
357 typedef short *__pshort;
358 typedef unsigned short *__pushort;
359 
360 typedef union
361   {
362     long *__lp;
363     int *__ip;
364 #ifndef STRICT_POINTERS
365     unsigned long *__ulp;
366     unsigned int *__uip;
367 #endif
368   } __plong __attribute__((__transparent_union__));
369 
370 typedef union
371   {
372     unsigned long *__lp;
373     unsigned int *__ip;
374 #ifndef STRICT_POINTERS
375     long *__slp;
376     int *__sip;
377 #endif
378   } __pulong __attribute__((__transparent_union__));
379 
380 typedef const short *__cpshort;
381 typedef const unsigned short *__cpushort;
382 
383 typedef union
384   {
385     const long *__lp;
386     const int *__ip;
387 #ifndef STRICT_POINTERS
388     const unsigned long *__ulp;
389     const unsigned int *__uip;
390 #endif
391   } __cplong __attribute__((__transparent_union__));
392 
393 typedef union
394   {
395     const unsigned long *__lp;
396     const unsigned int *__ip;
397 #ifndef STRICT_POINTERS
398     const long *__slp;
399     const int *__sip;
400 #endif
401   } __cpulong __attribute__((__transparent_union__));
402 
403 #endif
404 
405 #endif
406 
407 extern float __BC()__ATTR_LIB_ASM__;
408 #define _tios_float_1(f,x,t) ({typedef float(*__temp__type__)(short,t)__ATTR_LIB_ASM__;((__temp__type__)__BC)(4*0x##f,x);})
409 #define _tios_float_2(f,x,y,t1,t2) ({typedef float(*__temp__type__)(short,t1,t2)__ATTR_LIB_ASM__;((__temp__type__)__BC)(4*0x##f,x,y);})
410 
411 #if !defined (NOSTUB) && !defined (DOORS) && !defined (FARGO)
412 #ifdef USE_KERNEL
413 #include <doors.h>
414 #else
415 #include <nostub.h>
416 #endif
417 #endif
418 
419 #endif
420