]> git.sur5r.net Git - cc65/blob - doc/apple2.sgml
Now that cc65 programs can run as SYS files themselves my ProDOS Loader ulimately...
[cc65] / doc / apple2.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4
5 <title>Apple&nbsp;&rsqb;&lsqb; specific information for cc65
6 <author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">
7 <date>2003-12-16
8
9 <abstract>
10 An overview over the Apple&nbsp;&rsqb;&lsqb; runtime system as it is
11 implemented for the cc65 C 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 Apple&nbsp;&rsqb;&lsqb; runtime system
22 as it comes with the cc65 C compiler. It describes the memory layout,
23 Apple&nbsp;&rsqb;&lsqb; specific header files, available drivers, and any
24 pitfalls specific to that platform.
25
26 Please note that Apple&nbsp;&rsqb;&lsqb; specific functions are just mentioned
27 here, they are described in detail in the separate <htmlurl url="funcref.html"
28 name="function reference">. Even functions marked as "platform dependent" may
29 be available on more than one platform. Please see the function reference for
30 more information.
31
32
33
34 <sect>Binary format<p>
35
36 The standard binary output format generated by the linker for the
37 Apple&nbsp;&rsqb;&lsqb; target is a machine language program with a 4 byte DOS
38 3.3 header containing the load address and load size. The standard load address
39 is &dollar;803.
40
41 The DOS 3.3 header is in its own segment named <tt/EXEHDR/. If you don't want
42 the header for some reason, you can change
43
44 <verb>
45     HEADER: start = $0000, size = $0004, file = %O;
46 </verb>
47
48 to
49
50 <verb>
51     HEADER: start = $0000, size = $0004, file = "";
52 </verb>
53
54 in the linker configuration to have the linker remove it.
55
56 <bf/AppleCommander 1.3.5/ or later (available at <url
57 url="http://applecommander.sourceforge.net/">) includes an option <tt/-cc65/
58 that allows to put binary files with the DOS 3.3 header onto disk images
59 containing either DOS 3.3 or ProDOS 8.
60
61 Please note that there is an <bf/Apple&nbsp;&rsqb;&lsqb; ProDOS 8 system program
62 for loading binary programs/ available in the cc65 User Contributions section.
63 It adds all benefits of a ProDOS 8 system program to the standard binary
64 program generated by the linker for the Apple&nbsp;&rsqb;&lsqb; target.
65
66
67
68 <sect>Memory layout<p>
69
70 In the standard setup, cc65 generated programs use the memory from
71 &dollar;803 to &dollar;95FF, so 35.5KB of RAM are available. While running
72 <tt/main()/ the Language Card bank 2 is enabled for read access. However while
73 running module constructors/destructors the Language Card is disabled.
74
75 Special locations:
76
77 <descrip>
78   <tag/Stack/
79   The C runtime stack is located at HIMEM and grows downwards, regardless of
80   how your linker config file is setup.
81
82   <tag/Heap/
83   The C heap is located at the end of the program and grows towards the C
84   runtime stack.
85 </descrip><p>
86
87 Enabling the Language Card allows to use it as additional memory for executable
88 code. Actually doing so requires either to compile code with the option
89 <tt/--code-name HIGHCODE/ or to use <tt/#pragma codeseg ("HIGHCODE")/.
90
91 The amount of memory available in the Language Card for executable code depends
92 on the chosen program environment. A plain vanilla ProDOS 8 doesn't actually
93 use the Language Card bank 2 memory from &dollar;D400 to &dollar;DFFF.
94 Therefore the builtin linker configuration defines these 3KB as <tt/LC/ memory
95 area for executable code.
96
97 A plain vanilla DOS 3.3 doesn't make use of the Language Card at all. So you
98 can change
99
100 <verb>
101     LC: start = $D400, size = $0C00, define = yes;
102 </verb>
103
104 to
105
106 <verb>
107     LC: start = $D000, size = $3000, define = yes;
108 </verb>
109
110 in the linker configuration to define the whole 12KB Language Card address
111 space as memory area for executable code.
112
113
114
115 <sect>Platform specific header files<p>
116
117 Programs containing Apple&nbsp;&rsqb;&lsqb; specific code may use the
118 <tt/apple2.h/ header file.
119
120
121 <sect1>Apple&nbsp;&rsqb;&lsqb; specific functions<p>
122
123 The functions listed below are special for the Apple&nbsp;&rsqb;&lsqb;. See
124 the <htmlurl url="funcref.html" name="function reference"> for declaration and
125 usage.
126
127 <itemize>
128 <item>_dos_type
129 <item>get_ostype
130 <item>rebootafterexit
131 </itemize>
132
133
134 <sect1>Hardware access<p>
135
136 There's currently no support for direct hardware access. This does not mean
137 you cannot do it, it just means that there's no help.
138
139
140
141 <sect>Loadable drivers<p>
142
143
144 <sect1>Graphics drivers<p>
145
146 <descrip>
147
148   <tag><tt/a2.lo.tgi/</tag>
149   This driver features a resolution of 40&times;48 with 16 colors.
150
151   <tag><tt/a2.hi.tgi/</tag>
152   This driver features a resolution of 280&times;192 with 8 colors and two
153   hires pages. Note that programs using this driver will have to be linked
154   with <tt/--start-addr $4000/ to reserve the first hires page or with
155   <tt/--start-addr $6000/ to reserve both hires pages.
156   
157   In memory constrained situations the memory from &dollar;803 to &dollar;1FFF
158   can be made available to a program by executing <tt/_heapadd ((void *) 0x0803, 0x17FD);/
159   at the beginning of <tt/main()/. Doing so is beneficial even if the program
160   doesn't use the the heap explicitly because loading the driver (and in fact
161   already opening the driver file) uses the heap implicitly.
162
163 </descrip><p>
164
165
166 <sect1>Extended memory drivers<p>
167
168 <descrip>
169
170   <tag><tt/a2.auxmem.emd/</tag>
171   Gives access to 47,5 KB RAM (190 pages of 256 bytes each) on an Extended
172   80-Column Text Card.
173   
174   Note that this driver doesn't check for the actual existence of the memory
175   and that it doesn't check for ProDOS 8 RAM disk content!
176
177 </descrip><p>
178
179
180 <sect1>Joystick drivers<p>
181
182 <descrip>
183
184   <tag><tt/a2.stdjoy.joy/</tag>
185   Supports up to two standard analog joysticks connected to the game port of
186   the Apple&nbsp;&rsqb;&lsqb;.
187
188 </descrip><p>
189
190
191 <sect1>Mouse drivers<p>
192
193 <descrip>
194
195   <tag><tt/a2.stdmou.mou/</tag>
196   Driver for the AppleMouse&nbsp;II Card. Searches all Apple&nbsp;II slots
197   for an AppleMouse&nbsp;II Card compatible firmware. The default bounding
198   box is &lsqb;0..279,0..191&rsqb;.
199   
200   Programs using this driver will have to be linked with <tt/--start-addr $4000/
201   to reserve the first hires page if they are intended to run on an
202   Apple&nbsp;&rsqb;&lsqb; (in contrast to an Apple&nbsp;//e) because the
203   AppleMouse&nbsp;II Card firmware writes to the hires page when initializing
204   on that machine.
205
206   Note that the Apple&nbsp;&rsqb;&lsqb; default mouse callbacks support text
207   mode only.
208
209 </descrip><p>
210
211
212 <sect1>RS232 device drivers<p>
213
214 <descrip>
215
216   <tag><tt/a2.ssc.ser/</tag>
217   Driver for the Apple&nbsp;II Super Serial Card. Supports up to 19200 baud,
218   hardware flow control (RTS/CTS) and interrupt driven receives. Note
219   that because of the peculiarities of the 6551 chip transmits are not
220   interrupt driven, and the transceiver blocks if the receiver asserts
221   flow control because of a full buffer.
222
223   The driver defaults to slot 2. Call <tt/ser_ioctl(0, &lt;slot&gt;)/ prior to
224   <tt/ser_open()/ in order to select a different slot. <tt/ser_ioctl()/
225   succeeds for all Apple&nbsp;II slots, but <tt/ser_open()/ fails with
226   <tt/SER_ERR_NO_DEVICE/ if there's no SSC firmware found in the selected slot.
227
228 </descrip><p>
229
230
231
232 <sect>Limitations<p>
233
234
235 <sect1>DOS 3.3<p>
236
237 Although the standard binaries generated by the linker for the Apple&nbsp;&rsqb;&lsqb;
238 generally run both on DOS 3.3 (with Applesoft BASIC) and on ProDOS 8 (with
239 BASIC.SYSTEM) there are some limitations for DOS 3.3:
240
241 <descrip>
242
243   <tag>Disk File I/O</tag>
244   There's no disk file I/O support. Any attempt to use it yields an error with
245   <tt/errno/ set to <tt/ENOSYS/. This implicitly means that loadable drivers
246   are in general not functional as they depend on disk file I/O. However they
247   may be converted to statically linked drivers using the co65 object-file
248   converter.
249
250   <tag>Interrupts</tag>
251   There's no <tt/interruptor/ support. Any attempt to use it yields the message
252   'FAILED TO ALLOC INTERRUPT' on program startup. This implicitly means that
253   <tt/a2.stdmou.mou/ and <tt/a2.ssc.ser/ are not functional as they depend on
254   interrupts.
255   
256 </descrip><p>
257
258
259 <sect1>DIO<p>
260
261 Although <htmlurl url="dio.html" name="DIO"> generally works with all ProDOS 8
262 devices, the function <htmlurl url="dio-3.html" name="dio_query_sectcount()">
263 simply always return 280 (which is only correct for a 140KB disk).
264
265
266 <sect1>Direct console I/O<p>
267
268 <descrip>
269
270   <tag>Color</tag>
271   The Apple&nbsp;&rsqb;&lsqb; has no color text mode. Therefore the functions
272   <htmlurl url="funcref-205.html" name="textcolor()">,
273   <htmlurl url="funcref-68.html" name="bgcolor()"> and
274   <htmlurl url="funcref-69.html" name="bordercolor()"> have no effect.
275
276   <tag>Cursor</tag>
277   The Apple&nbsp;&rsqb;&lsqb; has no hardware cursor. Therefore the function
278   <htmlurl url="funcref-88.html" name="cursor()"> has no effect.
279
280 </descrip><p>
281
282
283
284 <sect>Other hints<p>
285
286
287 <sect1>Passing arguments to the program<p>
288
289 Command line arguments can be passed to <tt/main()/ after BLOAD. Since this is not
290 supported by BASIC, the following syntax was chosen:
291
292 <tscreen><verb>
293 ]CALL2051:REM ARG1 " ARG2 IS QUOTED" ARG3 "" ARG5
294 </verb></tscreen>
295
296 <enum>
297 <item>Arguments are separated by spaces.
298 <item>Arguments may be quoted.
299 <item>Leading and trailing spaces around an argument are ignored. Spaces within
300       a quoted argument are allowed.
301 <item>The first argument passed to <tt/main/ is the program name.
302 <item>A maximum number of 10 arguments (including the program name) are
303       supported.
304 </enum>
305
306
307 <sect1>Interrupts<p>
308
309 The runtime for the Apple&nbsp;&rsqb;&lsqb; uses routines marked as <tt/.CONDES/
310 type <tt/interruptor/ for ProDOS 8 interrupt handlers. Such routines must be
311 written as simple machine language subroutines and will be called automatically
312 by the interrupt handler code when they are linked into a program. See the
313 discussion of the <tt/.CONDES/ feature in the <htmlurl url="ca65.html"
314 name="assembler manual">.
315
316
317 <sect1>DIO<p>
318
319 The function <htmlurl url="dio-1.html" name="dio_open()"> has the single parameter
320 <tt/drive_id/ to identify the drive to be opened. Therefore an Apple&nbsp;II
321 slot and drive pair is mapped to that <tt/drive_id/ according to the formula
322
323 <verb>
324     drive_id = (slot * 2) + (drive - 1)
325 </verb>
326
327 so that for example slot 6 drive 1 is mapped to <tt/drive_id/ 12.
328
329 The function <htmlurl url="dio-1.html" name="dio_open()"> succeeds only if a
330 formatted disk is present in the drive. However intentionally no check is
331 performed on the presence of a ProDOS 8 disk. Therefore access to all standard
332 16-sector disks (as for instance DOS 3.3) is possible.
333
334
335
336 <sect>Bugs/Feedback<p>
337
338 If you have problems using the library, if you find any bugs, or if you're
339 doing something interesting with it, I would be glad to hear from you. Feel
340 free to contact me by email (<htmlurl url="mailto:uz@cc65.org"
341 name="uz@cc65.org">).
342
343
344
345 <sect>License<p>
346
347 This software is provided 'as-is', without any expressed or implied
348 warranty. In no event will the authors be held liable for any damages
349 arising from the use of this software.
350
351 Permission is granted to anyone to use this software for any purpose,
352 including commercial applications, and to alter it and redistribute it
353 freely, subject to the following restrictions:
354
355 <enum>
356 <item>  The origin of this software must not be misrepresented; you must not
357         claim that you wrote the original software. If you use this software
358         in a product, an acknowledgment in the product documentation would be
359         appreciated but is not required.
360 <item>  Altered source versions must be plainly marked as such, and must not
361         be misrepresented as being the original software.
362 <item>  This notice may not be removed or altered from any source
363         distribution.
364 </enum>
365
366 </article>