]> git.sur5r.net Git - cc65/blob - doc/atari.sgml
Merge pull request #849 from polluks/patch-4
[cc65] / doc / atari.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4 <title>Atari specific information for cc65
5 <author>
6 <url url="mailto:shawnjefferson@24fightingchickens.com" name="Shawn Jefferson"> and<newline>
7 <url url="mailto:chris@groessler.org" name="Christian Groessler">
8
9 <abstract>
10 An overview over the Atari runtime system as it is implemented for the cc65 C
11 compiler.
12 </abstract>
13
14 <!-- Table of contents -->
15 <toc>
16
17 <!-- Begin the document -->
18
19 <sect>Overview<p>
20
21 This file contains an overview of the Atari runtime system as it comes
22 with the cc65 C compiler. It describes the memory layout, Atari specific
23 header files, available drivers, and any pitfalls specific to that
24 platform.
25
26 The Atari runtime support comes in two flavors: <tt/atari/ and <tt/atarixl/.
27 The <tt/atari/ target supports all Atari 8-bit computers, the <tt/atarixl/ only
28 supports XL type or newer machines (excluding the 600XL).
29
30 The <tt/atarixl/ runtime makes the whole 64K of memory available, with the
31 exception of the I/O area at &dollar;D000 - &dollar;D7FF. Since the
32 <tt/atarixl/ runtime has some <ref name="limitations" id="xllimitations">, it is
33 recommended to use the <tt/atari/ target unless lack of memory dictates the
34 use of the <tt/atarixl/ target.
35
36 Please note that Atari specific functions are just mentioned here, they are
37 described in detail in the separate <url url="funcref.html" name="function
38 reference">. Even functions marked as "platform dependent" may be available on
39 more than one platform. Please see the function reference for more
40 information.
41
42
43 <sect>Binary format<p>
44
45 The Atari DOS executable file format supports more than one load block (<it/chunk/).
46
47 The default binary output format generated by the linker for the
48 Atari target is a machine language program with a standard executable
49 header (FF FF &lt;load chunk #1&gt; ... &lt;load chunk #n&gt).
50 A load chunk has the format &lsqb;&lt;2 byte start address&gt; &lt;2 bytes end address&gt;
51 &lt;chunk data&gt;&rsqb;.
52 A run vector is added to the end of the
53 file (&dollar;02E0 &dollar;02E1 &lt;run vector&gt;) and is calculated using
54 the <tt/start/ label in crt0.s.  (Technically the run vector is also a load chunk,
55 but is not regarded as such here.)
56
57 An <tt/atari/ program has two load chunks, an <tt/atarixl/ program has three load
58 chunks.  The load chunks are defined in the linker configuration files.  For more
59 detailed information about the load chunks see the chapter
60 <ref name="Technical details" id="techdetail">. For the discussion here it's
61 sufficient to know that the first load chunk(s) do preparation work and the
62 main part of the program is in the last load chunk.
63
64 The values determining the size of the main part of the program (the second load
65 chunk for <tt/atari/, the third load chunk for <tt/atarixl/) are calculated in
66 the crt0.s file from the __STARTUP_LOAD__ and __BSS_LOAD__ values.
67 Be aware of that if you create a custom linker config file and start moving segments around (see section
68 <ref name="Reserving a memory area inside the program" id="memhole">).
69
70
71 <sect>Memory layout<p>
72
73 <sect1><tt/atari/ target<p>
74
75 The default linker config file assumes that the BASIC ROM is disabled (or
76 the BASIC cartridge unplugged). This gives a usable memory range of
77 &lsqb;&dollar;2000-&dollar;BC1F&rsqb;. The library startup code examines the
78 current memory configuration, which depends on the size of the
79 installed memory and cartridges. It does so by using the value in
80 the MEMTOP (&dollar;2E5) variable as highest memory address the program
81 can use. The initial stack pointer, which is the upper bound of
82 memory used by the program, is set to this value, minus an optionally
83 defined __RESERVED_MEMORY__ value.
84
85 The default load address of &dollar;2000 can be changed by creating a custom
86 linker config file or by using the "--start-addr" cl65 command line
87 argument or the "--start-addr" or "-S" ld65 command line arguments.
88
89 Please note that the first load chunk (which checks the available memory)
90 will always be loaded at &dollar;2E00, regardless of the specified start
91 address. This address can only be changed by a custom linker config file.
92
93 Special locations:
94
95 <descrip>
96   <tag/Text screen/
97   The text screen depends on the installed memory size and cartridges
98   and can be obtained from the SAVMSC variable (&dollar;58).
99
100   <tag/Stack/
101   The C runtime stack is located at MEMTOP and grows downwards,
102   regardless of how your linker config file is setup.  This
103   accommodates the different memory configurations of the Atari
104   machines, as well as having a cartridge installed.  You can override
105   this behaviour by writing your own crt0.s file and linking it to
106   your program (see also <ref name="Final note"
107   id="memhole_final_note">).
108
109   <tag/Heap/
110   The C heap is located at the end of the program and grows towards the C
111   runtime stack.
112
113 </descrip><p>
114
115 <sect1><tt/atarixl/ target<p>
116
117 The startup code rearranges the memory as follows:
118
119 <enum>
120 <item>Sceen memory and display list are moved below the program start address.
121 <item>The ROM is disabled, making the memory in the areas &lsqb;&dollar;C000-&dollar;CFFF&rsqb;
122 and &lsqb;&dollar;D800-&dollar;FFF9&rsqb; available.
123 <item>Character generator data is copied from ROM to the CHARGEN location specified in the
124 linker config file.  This is (in the default <tt/atarixl.cfg/ file) at the same address as
125 where it is in ROM (&dollar;E000, it can be changed, see <ref name="atarixl chargen location"
126 id="chargenloc">).  With the character generator at &dollar;E000, there are two upper memory
127 areas available, &lsqb;&dollar;D800-&dollar;DFFF&rsqb; and &lsqb;&dollar;E400-&dollar;FFF9&rsqb;.
128 </enum>
129
130 With the default load address of &dollar;2400 this gives a usable memory range of
131 &lsqb;&dollar;2400-&dollar;CFFF&rsqb;.
132
133 Please note that the first load chunk (which checks the system
134 compatibilty and available memory) will always be loaded at
135 &dollar;2E00, regardless of the specified start address. This address
136 can only be changed by a custom linker config file.
137
138 Special locations:
139
140 <descrip>
141   <tag/Text screen/
142   The text screen depends on the selected load address (&dollar;2400
143   by default), and resides directly before that address, rounded to the next
144   lower page boundary.
145   The screen memory's start address can be obtained from the SAVMSC variable
146   (&dollar;58).
147
148   <tag/Stack/
149   The C runtime stack is located at end of the MAIN memory area (&dollar;CFFF)
150   and grows downwards.
151
152   <tag/Heap/
153   The C heap is located at the end of the program (end of BSS segment) and
154   grows towards the C runtime stack.
155
156 </descrip><p>
157
158 <sect>Linker configurations<p>
159
160 The ld65 linker comes with default config files for the Atari. There
161 are two targets for the Atari, <tt/atari/ and <tt/atarixl/.
162 The default config file for <tt/atari/ is selected with
163 <tt/-t atari/, and the default config file for <tt/atarixl/ is selected with
164 <tt/-t atarixl/.
165 The Atari package comes with additional secondary linker config files which
166 can be used via <tt/-t atari -C &lt;configfile&gt;/ (for <tt/atari/ target) or
167 <tt/-t atarixl -C &lt;configfile&gt;/ (for <tt/atarixl/ target).
168
169 <sect1><tt/atari/ config files<p>
170
171 <sect2>default config file (<tt/atari.cfg/)<p>
172
173 The default configuration is tailored to C programs. It creates files
174 which have a default load address of &dollar;2000.
175
176 The files generated by this config file include the
177 <ref name="&dquot;system check&dquot;" id="syschk"> load chunk. It can
178 optionally be left out, see <ref name="Getting rid of the &dquot;system check&dquot; load chunk" id="nosyschk">.
179
180 <sect2><tt/atari-asm.cfg/<p>
181
182 This config file aims to give the assembler programmer maximum
183 flexibility. All program segments (<tt/CODE/, <tt/DATA/, etc.) are
184 optional.
185
186 By default it creates regular DOS executable files, which have a default
187 load address of &dollar;2E00. It's also possible to generate an image of
188 just the program data without EXE header, load address, or (auto-)start address.
189 To you so, you have to define the symbols <tt/__AUTOSTART__/ and <tt/__EXEHDR__/
190 when linking the program. Therefore, to generate a "plain" binary file, pass the
191 options "<tt/-D__AUTOSTART__=1 -D__EXEHDR__=1/" to the linker.
192 It's also possible to create a non auto-starting program file, by defining
193 only the <tt/__AUTOSTART__/ symbol. Such a program has to be run manually
194 after being loaded by DOS (for example by using the "M" option of DOS 2.5).
195 Defining only the <tt/__EXEHDR__/ symbol will create a (useless) file which
196 doesn't conform to the DOS executable file format (like a "plain" binary file)
197 but still has the "autostart" load chunk appended.
198
199 The sections of the file which the defines refer to (<tt/__AUTOSTART__/ for
200 the autostart trailer, <tt/__EXEHDR__/ for the EXE header and load address)
201 is <it/left out/, keep this in mind.
202
203 The values you assign to the two symbols <tt/__AUTOSTART__/ and <tt/__EXEHDR__/
204 don't matter.
205
206 <sect2><tt/atari-asm-xex.cfg/<p>
207
208 This config file allows writing multi segment binaries easily, without having to
209 write the header explicitly on each segment.
210
211 It is similar to the <tt/atari-asm.cfg/ above, but uses the ATARI (xex) file
212 format support on LD65 instead of the standard binary output, so it does not
213 have the <tt/__AUTOSTART/ nor the <tt/__EXEHDR__/ symbols.
214
215 Note that each <tt/MEMORY/ area in the configuration file will have it's own
216 segment in the output file with the correct headers, and you can specify and
217 init address INITAD) for each memory area.
218
219 <sect2><tt/atari-cart.cfg/<p>
220
221 This config file can be used to create 8K or 16K cartridges. It's suited both
222 for C and assembly language programs.
223
224 By default, an 8K cartridge is generated. To create a 16K cartridge, pass the
225 size of the cartridge to the linker, like "<tt/-D__CARTSIZE__=0x4000/".
226 The only valid values for <tt/__CARTSIZE__/ are 0x2000 and 0x4000.
227
228 The option byte of the cartridge can be set with the <tt/__CARTFLAGS__/
229 value, passed to the linker. The default value is &dollar;01, which means
230 that the cartridge doesn't prevent the booting of DOS.
231
232 The option byte will be located at address &dollar;BFFD. For more information
233 about its use, see e.g. "Mapping the Atari".
234
235 <sect2><tt/atari-cassette.cfg/<p>
236
237 This config file can be used to create cassette boot files. It's suited both
238 for C and assembly language programs.
239
240 The size of a cassette boot file is restricted to 32K. Larger programs
241 would need to be split in more parts and the parts to be loaded manually.
242
243 To write the generated file to a cassette, a utility (<tt/w2cas.com/) to run
244 on an Atari is provided in the <tt/util/ directory of <tt/atari/ target dir.
245
246 <sect2><tt/atari-xex.cfg/<p>
247
248 This config file shows how to write a binary using the ATARI (xex) file format
249 support on LD65, this simplifies the memory areas and allows to add new memory
250 areas easily without writing new headers and trailers.
251
252 Note that the default C library includes the system-check chunk, so in this
253 linker configuration we suppress the importing of the header and trailer for
254 this chunk by defining the standard import symbols to a 0 value. For the
255 initialization address of the system-check chunk, the INITAD is set directly in
256 the configuration.
257
258 <sect1><tt/atarixl/ config files<p>
259
260 <sect2>default config file (<tt/atarixl.cfg/)<p>
261
262 The default configuration is tailored to C programs. It creates files
263 which have a default load address of &dollar;2400.
264
265 The files generated by this config file include the
266 <ref name="&dquot;system check&dquot;" id="syschkxl"> load chunk. It can
267 optionally be left out, see <ref name="Getting rid of the &dquot;system check&dquot; load chunk" id="nosyschk">.
268
269 <sect2><tt/atarixl-largehimem.cfg/<p>
270
271 This is the same as the default config file, but it rearranges the
272 high memory beneath the ROM into one large block. In order for this
273 config file to work, the runtime library has to be recompiled with a
274 special define. See the file <tt/libsrc&sol;atari&sol;Makefile.inc/ in the
275 source distribution.
276
277 The files generated by this config file include the
278 <ref name="&dquot;system check&dquot;" id="syschkxl"> load chunk. It can
279 optionally be left out, see <ref name="Getting rid of the &dquot;system check&dquot; load chunk" id="nosyschk">.
280
281 <sect2><tt/atarixl-xex.cfg/<p>
282
283 Similar to the <tt/atari-xex.cfg/ above, this config file shows how to write a
284 binary using the ATARI (xex) file format support on LD65.
285
286 In addition to the suppressing of the system-check headers and trailers, this
287 also suppresses the shadow-ram-preparation headers and trailers, but does this
288 by defining an "UNUSED" memory area that is not written to the output file.
289
290
291 <sect>Platform specific header files<p>
292
293 Programs containing Atari specific code may use the <tt/atari.h/
294 header file.
295
296
297 <sect1>Atari specific functions<p>
298
299 The functions and global variable listed below are special for the Atari.
300 See the <url url="funcref.html" name="function reference"> for declaration and usage.
301
302 <itemize>
303 <item>get_ostype
304 <item>get_tv
305 <item>_dos_type
306 <item>_gtia_mkcolor
307 <item>_getcolor
308 <item>_getdefdev
309 <item>_graphics
310 <item>_is_cmdline_dos
311 <item>_rest_vecs
312 <item>_save_vecs
313 <item>_scroll
314 <item>_setcolor
315 <item>_setcolor_low
316 </itemize>
317
318
319 <sect1>Hardware access<p>
320
321 The following pseudo variables declared in the <tt/atari.h/ header
322 file do allow access to hardware located in the address space. Some
323 variables are structures, accessing the struct fields will access the
324 chip registers.
325
326 <descrip>
327
328   <tag><tt/GTIA_READ/ and <tt/GTIA_WRITE/</tag>
329   The <tt/GTIA_READ/ structure allows read access to the GTIA. The
330   <tt/GTIA_WRITE/ structure allows write access to the GTIA.
331   See the <tt/_gtia.h/ header file located in the include directory
332   for the declaration of the structure.
333
334   <tag><tt/POKEY_READ/ and <tt/POKEY_WRITE/</tag>
335   The <tt/POKEY_READ/ structure allows read access to the POKEY. The
336   <tt/POKEY_WRITE/ structure allows write access to the POKEY.
337   See the <tt/_pokey.h/ header file located in the include directory
338   for the declaration of the structure.
339
340   <tag><tt/ANTIC/</tag>
341   The <tt/ANTIC/ structure allows read access to the ANTIC.
342   See the <tt/_antic.h/ header file located in the include directory
343   for the declaration of the structure.
344
345   <tag><tt/PIA/</tag>
346   The <tt/PIA/ structure allows read access to the PIA 6520.
347   See the <tt/_pia.h/ header file located in the include directory
348   for the declaration of the structure.
349
350 </descrip><p>
351
352 <sect1>Display lists<p>
353
354 A major feature of the Atari graphics chip "ANTIC" is to
355 process instructions for the display generation.
356 cc65 supports constructing these display lists by offering defines
357 for the instructions. In conjunction with the "void"-variable extension
358 of cc65, display lists can be created quite comfortable:
359
360 <verb>
361 ...
362 unsigned char ScreenMemory[100];
363
364 void DisplayList =
365 {
366     DL_BLK8,
367     DL_BLK8,
368     DL_BLK8,
369     DL_LMS(DL_CHR20x8x2),
370     ScreenMemory,
371     DL_CHR20x8x2,
372     DL_CHR20x8x2,
373     DL_CHR20x8x2,
374     DL_BLK4,
375     DL_CHR20x8x2,
376     DL_JVB
377 };
378 ...
379 POKEW(560,(unsigned int)&amp;DisplayList);      // SDLSTL
380 ...
381 </verb>
382
383 Please inspect the <tt/_antic.h/ header file to detemine the supported
384 instruction names. Modifiers on instructions can be nested without need
385 for an order:
386
387 <tt/DL_LMS(DL_HSCROL(DL_VSCROL(DL_DLI(DL_MAP80x4x2))))/
388
389 Please mind that ANTIC has memory alignment requirements for "player
390 missile graphics"-data, font data, display lists and screen memory. Creation
391 of a special linker configuration with appropriate aligned segments and
392 switching to that segment in the c-code is usually neccessary. A more memory
393 hungry solution consists in using the "<tt/posix_memalign()/" function in
394 conjunction with copying your data to the allocated memory.
395
396 <sect1>Character mapping<p>
397
398 The Atari has two representations for characters:
399 <enum>
400 <item> ATASCII is character mapping which is similar to ASCII and used
401 by the CIO system of the OS. This is the default mapping of cc65 when
402 producing code for the atari target.
403 <item> The internal/screen mapping represents the real value of the
404 screen ram when showing a character.
405 </enum>
406
407 For direct memory access (simplicity and speed) enabling the internal
408 mapping can be useful. This can be achieved by including the
409 "<tt/atari_screen_charmap.h/" header.
410
411 A word of caution: Since the <tt/0x00/ character has to be mapped in an
412 incompatible way to the C-standard, the usage of string functions in
413 conjunction with internal character mapped strings delivers unexpected
414 results regarding the string length. The end of strings are detected where
415 you may not expect them (too early or (much) too late). Internal mapped
416 strings typically support the "<tt/mem...()/" functions.
417
418 <em>For assembler sources the macro "<tt/scrcode/" from the "<tt/atari.mac/"
419 package delivers the same feature.</em>
420
421 You can switch back to the ATASCII mapping by including
422 "<tt/atari_atascii_charmap.h/".
423
424 A final note: Since cc65 has currently some difficulties with string merging
425 under different mappings, defining remapped strings works only flawlessly
426 with static array initialization:
427
428 <verb>
429 #include &lt;atari_screen_charmap.h&gt;
430 char pcScreenMappingString[] = "Hello Atari!";
431
432 #include &lt;atari_atascii_charmap.h&gt;
433 char pcAtasciiMappingString[] = "Hello Atari!";
434 </verb>
435
436 delivers correct results, while
437
438 <verb>
439 #include &lt;atari_screen_charmap.h&gt;
440 char* pcScreenMappingString = "Hello Atari!";
441
442 #include &lt;atari_atascii_charmap.h&gt;
443 char* pcAtasciiMappingString = "Hello Atari!";
444 </verb>
445
446 does not.
447
448 <sect1>Keyboard codes<p>
449
450 For direct keyboard scanning in conjunction with e.g. the OS location "CH" (764/$2FC),
451 all keyboard codes are available as defined values on C and assembler side.
452
453 Example:
454 <verb>
455 ...
456     while (!kbhit());
457     switch (PEEK(764))
458     {
459         case KEY_RETURN:
460         ...
461         case KEY_SPACE:
462         ...
463         case KEY_1:
464         ...
465     }
466 ...
467 </verb>
468
469 You can find the C defines in the file "<tt/atari.h/" or "<tt/atari.inc/" for the assembler variant.
470
471
472 <sect>Loadable drivers<p>
473
474 The names in the parentheses denote the symbols to be used for static linking of the drivers.
475
476
477 <sect1>Graphics drivers<p>
478
479 <table><tabular ca="rrrr">
480 <tt/atari/|<tt/atarixl/|screen resolution|display pages@<hline>
481 <tt/atr3.tgi (atr3_tgi)/|<tt/atrx3.tgi (atrx3_tgi)/|40x24x4 (CIO mode 3, ANTIC mode 8)|1@
482 <tt/atr4.tgi (atr4_tgi)/|<tt/atrx4.tgi (atrx4_tgi)/|80x48x2 (CIO mode 4, ANTIC mode 9)|1@
483 <tt/atr5.tgi (atr5_tgi)/|<tt/atrx5.tgi (atrx5_tgi)/|80x48x4 (CIO mode 5, ANTIC mode A)|1@
484 <tt/atr6.tgi (atr6_tgi)/|<tt/atrx6.tgi (atrx6_tgi)/|160x96x2 (CIO mode 6, ANTIC mode B)|1@
485 <tt/atr7.tgi (atr7_tgi)/|<tt/atrx7.tgi (atrx7_tgi)/|160x96x4 (CIO mode 7, ANTIC mode D)|1@
486 <tt/atr8.tgi (atr8_tgi)/|<tt/atrx8.tgi (atrx8_tgi)/|320x192x2 (CIO mode 8, ANTIC mode F)|1@
487 <tt/atr8p2.tgi (atr8p2_tgi)/|<tt/atrx8p2.tgi (atrx8p2_tgi)/|320x192x2 (CIO mode 8, ANTIC mode F)|2@
488 <tt/atr9.tgi (atr9_tgi)/|<tt/atrx9.tgi (atrx9_tgi)/|80x192x16b (CIO mode 9, ANTIC mode F, GTIA mode &dollar;40)|1@
489 <tt/atr9p2.tgi (atr9p2_tgi)/|<tt/atrx9p2.tgi (atrx9p2_tgi)/|80x192x16b (CIO mode 9, ANTIC mode F, GTIA mode &dollar;40)|2@
490 <tt/atr10.tgi (atr10_tgi)/|<tt/atrx10.tgi (atrx10_tgi)/|80x192x9 (CIO mode 10, ANTIC mode F, GTIA mode &dollar;80)|1@
491 <tt/atr10p2.tgi (atr10p2_tgi)/|<tt/atrx10p2.tgi (atrx10p2_tgi)/|80x192x9 (CIO mode 10, ANTIC mode F, GTIA mode &dollar;80)|2@
492 <tt/atr11.tgi (atr11_tgi)/|<tt/atrx11.tgi (atrx11_tgi)/|80x192x16h (CIO mode 11, ANTIC mode F, GTIA mode &dollar;C0)|1@
493 <tt/atr14.tgi (atr14_tgi)/|<tt/atrx14.tgi (atrx14_tgi)/|160x192x2 (CIO mode 14, ANTIC mode C)|1@
494 <tt/atr15.tgi (atr15_tgi)/|<tt/atrx15.tgi (atrx15_tgi)/|160x192x4 (CIO mode 15, ANTIC mode E)|1@
495 <tt/atr15p2.tgi (atr15p2_tgi)/|<tt/atrx15p2.tgi (atrx15p2_tgi)/|160x192x4 (CIO mode 15, ANTIC mode E)|2
496 </tabular>
497 <!-- <caption>bla bla -->
498 </table>
499
500
501 Many graphics modes require more memory than the text screen which is
502 in effect when the program starts up. Therefore the programmer has to
503 tell the program beforehand the memory requirements of the graphics
504 modes the program intends to use.
505
506 On the <tt/atari/ target his can be done by using the __RESERVED_MEMORY__
507 linker config variable. The number specified there describes the number
508 of bytes to subtract from the top of available memory as seen from the
509 runtime library. This memory is then used by the screen buffer.
510
511 On the <tt/atarixl/ target the screen memory resides below the program
512 load address.  In order to reserve memory for a graphics mode, one
513 simply uses a higher program load address.  There are restrictions on
514 selectable load addresses,
515 see <ref name="Selecting a good program load address" id="loadaddr">.
516
517 The numbers for the different graphics modes presented below should
518 only be seen as a rule of thumb. Since the screen buffer memory needs
519 to start at specific boundaries, the numbers depend on the current top
520 of available memory.
521 The following numbers were determined by a BASIC program.
522
523 <table>
524 <tabular ca="rr">
525 graphics mode|reserved memory@<hline>
526 0|1@
527 1|1@
528 2|1@
529 3|1@
530 4|1@
531 5|182@
532 6|1182@
533 7|3198@
534 8|7120@
535 9|7146@
536 10|7146@
537 11|7146@
538 12|162@
539 13|1@
540 14|3278@
541 15|7120@
542 16|1@
543 17|1@
544 18|1@
545 19|1@
546 20|1@
547 21|184@
548 22|1192@
549 23|3208@
550 24|7146@
551 25|7146@
552 26|7146@
553 27|7146@
554 28|162@
555 29|1@
556 30|3304@
557 31|7146
558 </tabular>
559 <caption>reserved memory required for different graphics modes
560 </table>
561
562 The values of "1" are needed because the graphics command crashes if
563 it doesn't have at least one byte available. This seems to be a bug of
564 the Atari ROM code.
565
566 Default drivers: <tt/atr8.tgi (atr8_tgi)/ and <tt/atrx8.tgi (atrx8_tgi)/.
567
568 <sect1>Extended memory drivers<p>
569
570 Currently there is only one extended memory driver.  It manages the second 64K of a 130XE.
571
572 <table>
573 <tabular ca="rr">
574 <tt/atari/|<tt/atarixl/@<hline>
575 <tt/atr130.emd (atr130_emd)/|<tt/atrx130.emd (atrx130_emd)/
576 </tabular>
577 </table>
578
579 <sect1>Joystick drivers<p>
580
581 Currently there are two joystick drivers available:
582
583 <table>
584 <tabular ca="rrr">
585 <tt/atari/|<tt/atarixl/|description@<hline>
586 <tt/atrstd.joy (atrstd_joy)/|<tt/atrxstd.joy (atrxstd_joy)/|Supports up to two/four standard joysticks connected to the joystick ports of the Atari. (Four on the pre-XL systems, two on XL or newer.)@
587 <tt/atrmj8.joy (atrmj8_joy)/|<tt/atrxmj8.joy (atrxmj8_joy)/|Supports up to eight standard joysticks connected to a MultiJoy adapter.
588 </tabular>
589 </table>
590
591 Default drivers: <tt/atrstd.joy (atrstd_joy)/ and <tt/atrxstd.joy (atrxstd_joy)/.
592
593 <sect1>Mouse drivers<p>
594
595 Currently there are five mouse drivers available:
596
597 <table>
598 <tabular ca="rrr">
599 <tt/atari/|<tt/atarixl/|description@<hline>
600 <tt/atrjoy.mou (atrjoy_mou)/|<tt/atrxjoy.mou (atrxjoy_mou)/|Supports a mouse emulated by a standard joystick.@
601 <tt/atrst.mou (atrst_mou)/|<tt/atrxst.mou (atrxst_mou)/|Supports an Atari ST mouse.@
602 <tt/atrami.mou (atrami_mou)/|<tt/atrxami.mou (atrxami_mou)/|Supports an Amiga mouse.@
603 <tt/atrtrk.mou (atrtrk_mou)/|<tt/atrxtrk.mou (atrxtrk_mou)/|Supports an Atari trakball.@
604 <tt/atrtt.mou (atrtt_mou)/|<tt/atrxtt.mou (atrxtt_mou)/|Supports an Atari touch tablet.
605 </tabular>
606 </table>
607
608 All mouse devices connect to joystick port #0.
609
610 Default drivers: <tt/atrst.mou (atrst_mou)/ and <tt/atrxst.mou (atrxst_mou)/.
611
612 <sect2>Mouse callbacks<p>
613
614 There are two mouse callbacks available.
615 <p>
616 The "text mode" callbacks (<tt/mouse_txt_callbacks/) display the mouse cursor as a "diamond" character
617 on the standard "GRAPHICS 0" text mode screen. The mouse cursor character can be changed by an
618 assembly file defining the character by exporting the zeropage symbol <tt/mouse_txt_char/.
619 The default file looks like this:
620 <tscreen><verb>
621         .export mouse_txt_char : zp = 96     ; 'diamond' screen code
622 </verb></tscreen>
623 <p>
624 The "P/M" callbacks (<tt/mouse_pm_callbacks/) use Player-Missile graphics for the mouse cursor.
625 The cursor shape can be changed, too, by an assembly file. Here's the default shape definition:
626 <tscreen><verb>
627         .export mouse_pm_bits
628         .export mouse_pm_height    : zeropage
629         .export mouse_pm_hotspot_x : zeropage
630         .export mouse_pm_hotspot_y : zeropage
631         .rodata
632 mouse_pm_bits:
633         .byte   %11110000
634         .byte   %11000000
635         .byte   %10100000
636         .byte   %10010000
637         .byte   %10001000
638         .byte   %00000100
639         .byte   %00000010
640 mouse_pm_height = * - mouse_pm_bits
641 ; hot spot is upper left corner
642 mouse_pm_hotspot_x = 0
643 mouse_pm_hotspot_y = 0
644 </verb></tscreen>
645 <p>
646 <tt/mouse_pm_bits/ defines the shape of the cursor, <tt/mouse_pm_height/ defines the number of
647 bytes in <tt/mouse_pm_bits/. <tt/mouse_pm_hotspot_x/ and <tt/mouse_pm_hotspot_y/ define the
648 position in the shape where "the mouse points to". When using this callback page #6 (&dollar;600
649  - &dollar;6FF) is used for the P/M graphics data and no P/M graphics can otherwise be used
650 by the program. The height of the shape (<tt/mouse_pm_height/)
651 must not exceed 32 lines since the callback routines cannot handle more than 32 lines.
652 <p>
653 The default callbacks definition (<tt/mouse_def_callbacks/) is an alias for the "P/M" callbacks.
654
655 <sect1>RS232 device drivers<p>
656
657 Currently there is one RS232 driver.  It uses the R: device (therefore
658 an R: driver needs to be installed) and was tested with the 850
659 interface module.
660
661 <table>
662 <tabular ca="rr">
663 <tt/atari/|<tt/atarixl/@<hline>
664 <tt/atrrdev.ser (atrrdev_ser)/|<tt/atrxrdev.ser (atrxrdev_ser)/
665 </tabular>
666 </table>
667
668
669 <sect>Limitations<p>
670
671 <sect1><tt/Realtime clock/<label id="realtimeclock"<p>
672
673 Access to the realtime clock is supported only when running on SpartaDOS-X.
674 There needs to be a realtime clock driver installed. This is normally the case
675 in the default installation (CONFIG.SYS) of SpartaDOS-X.
676 A missing realtime clock driver in SpartaDOS-X is not supported, and the program
677 may crash when calling the <tt/clock_settime()/ or <tt/clock_gettime()/
678 functions.
679
680 The resolution of the realtime clock driver is 1 second.
681
682 <sect1><tt/atarixl target/<#if output="info|latex2e"> limitations</#if><label id="xllimitations"<p>
683
684 <itemize>
685 <item>The display is cleared at program start and at program termination.  This is a side
686 effect of relocating the display memory below the program start address.
687 <item>Not all possible CIO and SIO functions are handled by the runtime stub code which banks
688 the ROM in and out.  All functions used by the runtime library are handled, though.
689 <item>The <tt/_sys()/ function is not supported.
690 <item>It is not compatible with DOSes or other programs using the memory below the ROM.
691 </itemize>
692
693 <sect>DIO implementation<label id="dio"><p>
694
695 The Atari supports disk drives with either 128 or 256 byte sectors.
696 The first three sectors of any disk are always 128 bytes long though. This is
697 because the system can only boot from 128 bytes sectors.
698
699 Therefore the DIO read and write functions transfer only 128 bytes
700 for sectors 1 to 3, regardless of the type of diskette.
701
702
703 <sect>CONIO implementation<label id="conio"><p>
704
705 The console I/O is speed optimized therefore support for XEP80 hardware
706 or f80.com software is missing. Of course you may use stdio.h functions.
707
708
709 <sect>Technical details<label id="techdetail"><p>
710
711 <sect1><tt/atari/<#if output="info|latex2e"> details</#if><p>
712
713 <sect2><#if output="info|latex2e"><tt/atari/ </#if>Load chunks<p>
714
715 An <tt/atari/ program contains two load chunks.
716
717 <enum>
718 <item>"system check"<label id="syschk">&nl;
719 This load chunk is always loaded at address &dollar;2E00, and checks if the system has
720 enough memory to run the program. It also checks if the program start address is not
721 below MEMLO. If any of the checks return false, the loading of the program is aborted.&nl;
722 The contents of this chunk come from the SYSCHKCHNK memory area of the linker config file.
723 <item>main program&nl;
724 This load chunk is loaded at the selected program start address (default &dollar;2000) and
725 contains all of the code and data of the program.&nl;
726 The contents of this chunk come from the MAIN memory area of the linker config file.
727 </enum>
728
729
730 <sect1><tt/atarixl/<#if output="info|latex2e"> details</#if><p>
731
732 <sect2>General operation<p>
733
734 The <tt/atarixl/ target banks out the ROM while the program is running in
735 order to make more memory available to the program.
736
737 The screen memory is by default located at the top of available memory,
738 &dollar;BFFF if BASIC is not enabled, &dollar;9FFF if BASIC is enabled.
739 Therefore, in order to create a largest possible continuous memory area,
740 the screen memory is moved below the program load address.  This gives
741 a memory area from &lt;program load addr&gt; to &dollar;CFFF.
742
743 The startup code installs wrappers for interrupt handlers and ROM routines.
744 When an interrupt or call to a ROM routine happens, the wrappers enable the
745 ROM, call the handler or routine, and disable the ROM again.
746
747 The "wrapping" of the ROM routines is done by changing the ROM entry
748 point symbols in <tt/atari.inc/ to point to the wrapper functions.
749
750 For ROM functions which require input or output buffers, the wrappers
751 copy the data as required to buffers in low memory.
752
753 <sect2><#if output="info|latex2e"><tt/atarixl/ </#if>Load chunks<label id="xlchunks"><p>
754
755 An <tt/atarixl/ program contains three load chunks.
756
757 <enum>
758 <item>"system check"<label id="syschkxl">&nl;
759 This load chunk is always loaded at address &dollar;2E00, and checks if the system is
760 suitable for running the program. It also checks if there is enough room between MEMLO
761 and the program start address to move the text mode screen buffer there. If any of the
762 checks return false, the loading of the program is aborted.&nl;
763 The contents of this chunk come from the SYSCHKCHNK memory area of the linker config file.
764 <item>"shadow RAM prepare"&nl;
765 The second load chunk gets loaded to the selected program load address (default &dollar;2400).
766 It moves the screen memory below the program load address, copies the character generator
767 from ROM to its new place in RAM, and copies the parts of the program which reside in
768 high memory below the ROM to their place. The high memory parts are included in this load chunk.&nl;
769 At the beginning of this load chunk there is a .bss area, which is not part of the
770 EXE file. Therefore the on-disk start address of this load chunk will be higher than the
771 selected start address. This .bss area (segment LOWBSS) contains the buffers for the
772 double buffering of ROM input and output data.  If you add contents to this segment be aware
773 that the contents won't be zero initialized by the startup code.&nl;
774 The contents of this chunk come from the SRPREPCHNK memory area of the linker config file.
775 <item>main program&nl;
776 This load chunk is loaded just above the LOWBSS segment, replacing the code of
777 the previous load chunk. It contains all remaining code and data sections of the program,
778 including the startup code.&nl;
779 The contents of this chunk come from the RAM memory area of the linker config file.
780 </enum>
781
782 <sect2>Moving screen memory below the program start address<p>
783
784 When setting a graphics mode, the ROM looks at the RAMTOP location. RAMTOP
785 describes the amount of installed memory in pages (RAMTOP is only one byte).
786 The screen memory and display list are placed immediately below RAMTOP.
787
788 Now in order to relocate the screen memory to lower memory, the startup code
789 puts a value into RAMTOP which causes the ROM routines to allocate the display
790 memory below the program start address and then it issues a ROM call to setup
791 the regular text mode.
792
793 <sect2>Selecting a good program load address<label id="loadaddr"><p>
794
795 Due to the movement of the screen memory below the program start, there are some
796 load addresses which are sub-optimal because they waste memory or prevent a
797 higher resolution graphics mode from being enabled.
798
799 There are restrictions at which addresses screen memory (display buffer and display
800 list) can be placed. The display buffer cannot cross a 4K boundary and a display
801 list cannot cross a 1K boundary.
802
803 The startup code takes this into account when moving the screen memory down.
804 If the program start address (aligned to the next lower page boundary) minus
805 the screen buffer size would result in a screen buffer which spans a 4K
806 boundary, the startup code lowers RAMTOP to this 4K boundary.&nl;
807 The size of the screen buffer in text mode is 960 (&dollar;3C0) bytes. So, for
808 example, a selected start address of &dollar;2300 would span the 4K boundary
809 at &dollar;2000. The startup code would adjust the RAMTOP value in such way that
810 the screen memory would be located just below this boundary (at &dollar;1C40).
811 This results in the area &lsqb;&dollar;2000-&dollar;22FF&rsqb; being wasted.
812 Additionally, the program might fail to load since the lowest address used
813 by the screen memory could be below MEMLO. (The lowest address used in this
814 example would be at &dollar;1C20, where the display list would allocated.)
815
816 These calculations are performed by the startup code (in the first two
817 load chunks), but the startup code only takes the default 40x24 text mode
818 into account. If the program later wants to load TGI drivers which set
819 a more memory consuming graphics mode, the user has to pick a higher
820 load address.
821 Using higher resolution modes there is a restriction in the ROM that it
822 doesn't expect RAMTOP to be at arbitrary values. The Atari memory modules
823 came only in 8K or 16K sizes, so the ROM expects RAMTOP to only have
824 values in 8K steps. Therefore, when using the highest resolution modes
825 the program start address must be at an 8K boundary.
826
827
828 <sect2>Character generator location<label id="chargenloc"><p>
829
830 The default <tt/atarixl/ linker config file (<tt/atarixl.cfg/) leaves the
831 character generator location at the same address where it is in ROM
832 (&dollar;E000). This has the disadvatage to split the upper memory into
833 two parts (&lsqb;&dollar;D800-&dollar;DFFF&rsqb; and
834 &lsqb;&dollar;E400-&dollar;FFF9&rsqb;). For applications which
835 require a large continuous upper memory area, an alternative linker
836 config file (<tt/atarixl-largehimem.cfg/) is provided. It relocates the
837 character generator to &dollar;D800, providing a single big upper
838 memory area at &lsqb;&dollar;DC00-&dollar;FFF9&rsqb;.
839
840 With the character generator at a different address than in ROM, the routines
841 which enable and disable the ROM also have to update the chargen pointer.
842 This code is not enabled by default. In order to enable it,
843 uncomment the line which sets CHARGEN_RELOC in <tt/libsrc&sol;atari&sol;Makefile.inc/
844 and recompile the <tt/atarixl/ runtime library.
845
846 <sect>Other hints<p>
847
848
849 <sect1>Function keys<p>
850
851 Function keys are mapped to Atari + number key.
852
853
854 <sect1>Passing arguments to the program<p>
855
856 Command line arguments can be passed to <tt/main()/ when the used DOS supports it.
857
858 <enum>
859 <item>Arguments are separated by spaces.
860 <item>Leading and trailing spaces around an argument are ignored.
861 <item>The first argument passed to <tt/main/ is the program name.
862 <item>A maximum number of 16 arguments (including the program name) are
863       supported.
864 </enum>
865
866
867 <sect1>Interrupts<p>
868
869 The runtime for the Atari uses routines marked as <tt/.INTERRUPTOR/ for
870 interrupt handlers. Such routines must be written as simple machine language
871 subroutines and will be called automatically by the VBI handler code
872 when they are linked into a program. See the discussion of the <tt/.CONDES/
873 feature in the <url url="ca65.html" name="assembler manual">.
874
875 Please note that on the Atari targets the <tt/.INTERRUPTOR/s are being
876 run in NMI context. The other targets run them in IRQ context.
877
878 <sect1>Reserving a memory area inside a program<label id="memhole"><p>
879
880 (This section is primarily applicable to the <tt/atari/ target, but the
881 principles apply to <tt/atatixl/ as well.)
882
883 The Atari 130XE maps its additional memory into CPU memory in 16K
884 chunks at address &dollar;4000 to &dollar;7FFF. One might want to
885 prevent this memory area from being used by cc65. Other reasons to
886 prevent the use of some memory area could be to reserve space for the
887 buffers for display lists and screen memory.
888 <p>
889 The Atari executable format allows holes inside a program, e.g. one
890 part loads into &dollar;2E00 to &dollar;3FFF, going below the reserved
891 memory area (assuming a reserved area from &dollar;4000 to
892 &dollar;7FFF), and another part loads into &dollar;8000 to
893 &dollar;BC1F.
894 <p>
895 Each load chunk of the executable starts with a 4 byte header which
896 defines its load address and size. In the following linker config files
897 these headers are named HEADER and SECHDR (for the MEMORY layout), and
898 accordingly NEXEHDR and CHKHDR (for the SEGMENTS layout).
899 <p>
900 <sect2>Low code and high data example<p>
901 Goal: Create an executable with 2 load chunks which doesn't use the
902 memory area from &dollar;4000 to &dollar;7FFF. The CODE segment of
903 the program should go below &dollar;4000 and the DATA and RODATA
904 segments should go above &dollar;7FFF.
905 <p>
906 The main problem is that the EXE header generated by the cc65 runtime
907 lib is wrong. It defines a single load chunk with the sizes/addresses
908 of the STARTUP, LOWCODE, ONCE, CODE, RODATA, and DATA segments, in
909 fact, the whole user program (we're disregarding the "system check"
910 load chunk here).
911 <p>
912 The contents of the EXE header come from the EXEHDR and MAINHDR segments.
913 The EXEHDR segment just contains the &dollar;FFFF value which is required
914 to be the first bytes of the EXE file.&nl;
915 The MAINHDR are defined in in crt0.s. This cannot be changed without
916 modifying and recompiling the cc65 atari runtime library. Therefore
917 the original contents of this segment must be discarded and be
918 replaced by a user created one. This discarding is done by assigning the
919 MAINHDR segment to the (new introduced) DISCARD memory area. The DISCARD memory area is
920 thrown away in the new linker config file (written to file "").
921 We add a new FSTHDR segment for the chunk header of the first chunk.
922 <p>
923 The user needs to create a customized linker config file which adds
924 new memory areas and segments to hold the new header data for the first load
925 chunk and the header data for the second load chunk. Also an assembly source file
926 needs to be created which defines the contents of the new header data
927 for the two load chunks.
928 <p>
929 <p>
930 This is an example of a modified cc65 Atari linker configuration file
931 (split.cfg):
932 <tscreen><verb>
933 SYMBOLS {
934     __STACKSIZE__:       value = $800   type = weak;    # 2K stack
935     __RESERVED_MEMORY__: value = $0000, type = weak;
936 }
937 FEATURES {
938     STARTADDRESS: default = $2E00;
939 }
940 MEMORY {
941     ZP: start = $82, size = $7E, type = rw, define = yes;
942
943     HEADER: start = $0000, size = $2, file = %O;        # first load chunk
944
945     FSTHDR: start = $0000, size = $4, file = %O;        # second load chunk
946     RAMLO: start = %S, size = $4000 - %S, file = %O;
947
948     DISCARD: start = $4000, size = $4000, file = "";
949
950     SECHDR: start = $0000, size = $4, file = %O;        # second load chunk
951     RAM: start = $8000, size = $3C20, file = %O;        # $3C20: matches upper bound $BC1F
952 }
953 SEGMENTS {
954     EXEHDR: load = HEADER, type = ro;
955
956     MAINHDR: load = DISCARD, type = ro;
957
958     NEXEHDR: load = FSTHDR, type = ro;                  # first load chunk
959     STARTUP: load = RAMLO, type = ro, define = yes;
960     LOWCODE: load = RAMLO, type = ro, define = yes, optional = yes;
961     ONCE: load = RAMLO, type = ro, optional = yes;
962     CODE: load = RAMLO, type = ro, define = yes;
963
964     CHKHDR: load = SECHDR, type = ro;                   # second load chunk
965     RODATA: load = RAM, type = ro, define = yes;
966     DATA: load = RAM, type = rw, define = yes;
967     BSS: load = RAM, type = bss, define = yes;
968
969     ZEROPAGE: load = ZP, type = zp;
970     AUTOSTRT: load = RAM, type = ro;                    # defines program entry point
971 }
972 FEATURES {
973     CONDES: segment = ONCE,
974             type = constructor,
975             label = __CONSTRUCTOR_TABLE__,
976             count = __CONSTRUCTOR_COUNT__;
977     CONDES: segment = RODATA,
978             type = destructor,
979             label = __DESTRUCTOR_TABLE__,
980             count = __DESTRUCTOR_COUNT__;
981 }
982 </verb></tscreen>
983 <p>
984
985 A new memory area DISCARD was added.
986 It gets loaded with the contents of the (now unused) MAINHDR segment. But the
987 memory area isn't written to the output file. This way the contents of
988 the MAINHDR segment get discarded.
989 <p>
990 The newly added NEXEHDR segment defines the correct chunk header for the
991 first intended load chunk. It
992 puts the STARTUP, LOWCODE, ONCE, and CODE segments, which are the
993 segments containing only code, into load chunk #1 (RAMLO memory area).
994 <p>
995 The header for the second load chunk comes from the new CHKHDR
996 segment. It puts the RODATA, DATA, BSS, and ZPSAVE segments into load
997 chunk #2 (RAM memory area).
998 <p>
999 <p>
1000 The contents of the new NEXEHDR and CHKHDR segments come from this
1001 file (split.s):
1002 <tscreen><verb>
1003     .import __CODE_LOAD__, __BSS_LOAD__, __CODE_SIZE__
1004     .import __DATA_LOAD__, __RODATA_LOAD__, __STARTUP_LOAD__
1005
1006     .segment "NEXEHDR"
1007     .word    __STARTUP_LOAD__
1008     .word    __CODE_LOAD__ + __CODE_SIZE__ - 1
1009
1010     .segment "CHKHDR"
1011     .word    __RODATA_LOAD__
1012     .word    __BSS_LOAD__ - 1
1013 </verb></tscreen>
1014 <p>
1015 Compile with
1016 <tscreen><verb>
1017 cl65 -t atari -C split.cfg -o prog.com prog.c split.s
1018 </verb></tscreen>
1019
1020 <sect2>Low data and high code example<p>
1021
1022
1023 Goal: Put RODATA and DATA into low memory and STARTUP, LOWCODE, ONCE,
1024 CODE, BSS, ZPSAVE into high memory (split2.cfg):
1025
1026 <tscreen><verb>
1027 SYMBOLS {
1028     __STACKSIZE__:       value = $800   type = weak;    # 2K stack
1029     __RESERVED_MEMORY__: value = $0000, type = weak;
1030 }
1031 FEATURES {
1032     STARTADDRESS: default = $2E00;
1033 }
1034 MEMORY {
1035     ZP: start = $82, size = $7E, type = rw, define = yes;
1036
1037     HEADER: start = $0000, size = $2, file = %O;        # first load chunk
1038
1039     FSTHDR: start = $0000, size = $4, file = %O;        # second load chunk
1040     RAMLO: start = %S, size = $4000 - %S, file = %O;
1041
1042     DISCARD: start = $4000, size = $4000, file = "";
1043
1044     SECHDR: start = $0000, size = $4, file = %O;        # second load chunk
1045     RAM: start = $8000, size = $3C20, file = %O;        # $3C20: matches upper bound $BC1F
1046 }
1047 SEGMENTS {
1048     EXEHDR: load = HEADER, type = ro;                     # discarded old EXE header
1049
1050     MAINHDR: load = DISCARD, type = ro;
1051
1052     NEXEHDR: load = FSTHDR, type = ro;                  # first load chunk
1053     RODATA: load = RAMLO, type = ro, define = yes;
1054     DATA: load = RAMLO, type = rw, define = yes;
1055
1056     CHKHDR: load = SECHDR, type = ro;                   # second load chunk
1057     STARTUP: load = RAM, type = ro, define = yes;
1058     ONCE: load = RAM, type = ro, optional = yes;
1059     CODE: load = RAM, type = ro, define = yes;
1060     BSS: load = RAM, type = bss, define = yes;
1061
1062     ZEROPAGE: load = ZP, type = zp;
1063     AUTOSTRT: load = RAM, type = ro;                    # defines program entry point
1064 }
1065 FEATURES {
1066     CONDES: segment = ONCE,
1067             type = constructor,
1068             label = __CONSTRUCTOR_TABLE__,
1069             count = __CONSTRUCTOR_COUNT__;
1070     CONDES: segment = RODATA,
1071             type = destructor,
1072             label = __DESTRUCTOR_TABLE__,
1073             count = __DESTRUCTOR_COUNT__;
1074 }
1075 </verb></tscreen>
1076
1077 New contents for NEXEHDR and CHKHDR are needed (split2.s):
1078 <tscreen><verb>
1079     .import __STARTUP_LOAD__, __BSS_LOAD__, __DATA_SIZE__
1080     .import __DATA_LOAD__, __RODATA_LOAD__
1081
1082     .segment "NEXEHDR"
1083     .word    __RODATA_LOAD__
1084     .word    __DATA_LOAD__ + __DATA_SIZE__ - 1
1085
1086     .segment "CHKHDR"
1087     .word    __STARTUP_LOAD__
1088     .word    __BSS_LOAD__ - 1
1089 </verb></tscreen>
1090
1091 Compile with
1092 <tscreen><verb>
1093 cl65 -t atari -C split2.cfg -o prog.com prog.c split2.s
1094 </verb></tscreen>
1095
1096 <sect2>Final note<label id="memhole_final_note"><p>
1097
1098 There are two other memory areas which don't appear directly in the
1099 linker config file. They are the stack and the heap.
1100
1101 The cc65 runtime lib places the stack location at the end of available
1102 memory. This is dynamically set from the MEMTOP system variable at
1103 startup. The heap is located in the area between the end of the BSS
1104 segment and the top of the stack as defined by __STACKSIZE__.
1105
1106 If BSS and/or the stack shouldn't stay at the end of the program,
1107 some parts of the cc65 runtime lib need to be replaced/modified.
1108
1109 common/_heap.s defines the location of the heap and atari/crt0.s
1110 defines the location of the stack by initializing sp.
1111
1112
1113 <sect1>Upgrading from an older cc65 version<p>
1114
1115 If you are using a customized linker config file you might get some errors
1116 regarding the MAINHDR segment. Like this:
1117
1118 <tscreen><verb>
1119 ld65: Error: Missing memory area assignment for segment 'MAINHDR'
1120 </verb></tscreen>
1121
1122 The old "HEADER" memory description contained six bytes: &dollar;FFFF
1123 and the first and last memory addess of the program. For the "system
1124 check" load chunk this had to be split into two memory assigments. The
1125 "HEADER" now only contains the &dollar;FFFF. The main program's first
1126 and last memory address were moved to a new segment, called "MAINHDR",
1127 which in the new linker config file goes into its own memory area (also
1128 called "MAINHDR").&nl;&nl;
1129 A simple way to adapt your old linker config file is to add the
1130 following line to the "SEGMENTS" section:
1131
1132 <tscreen><verb>
1133 MAINHDR: load = HEADER, type = ro;
1134 </verb></tscreen>
1135
1136
1137
1138 <sect1>Getting rid of the "system check" load chunk<label id="nosyschk"><p>
1139
1140 If, for some reason, you don't want to include the "system check" load
1141 chunk, you can do so by defining the symbol <tt/__SYSTEM_CHECK__/ when linking the
1142 program. The "system check" chunk doesn't include vital parts of the
1143 program. So if you don't want the system checks, it is save to leave them out.
1144 This is probably mostly interesting for debugging.
1145
1146 When using cl65, you can leave it out with this command line:
1147
1148 <tscreen><verb>
1149 cl65 -Wl -D__SYSTEM_CHECK__=1 <arguments>
1150 </verb></tscreen>
1151
1152 The value you assign to <tt/__SYSTEM_CHECK_/ doesn't matter. If the
1153 <tt/__SYSTEM_CHECK__/ symbol is defined, the load chunk won't be included.
1154
1155
1156 <sect>License<p>
1157
1158 This software is provided 'as-is', without any expressed or implied
1159 warranty.  In no event will the authors be held liable for any damages
1160 arising from the use of this software.
1161
1162 Permission is granted to anyone to use this software for any purpose,
1163 including commercial applications, and to alter it and redistribute it
1164 freely, subject to the following restrictions:
1165
1166 <enum>
1167 <item>  The origin of this software must not be misrepresented; you must not
1168     claim that you wrote the original software. If you use this software
1169     in a product, an acknowledgment in the product documentation would be
1170     appreciated but is not required.
1171 <item>  Altered source versions must be plainly marked as such, and must not
1172     be misrepresented as being the original software.
1173 <item>  This notice may not be removed or altered from any source
1174     distribution.
1175 </enum>
1176
1177 </article>