]> git.sur5r.net Git - cc65/blob - doc/c16.sgml
remote TABs in doc/ and test/
[cc65] / doc / c16.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4 <title>Commodore 16/116 specific information for cc65
5 <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">
6
7 <abstract>
8 An overview over the C16 runtime system as it is implemented for the cc65 C
9 compiler.
10 </abstract>
11
12 <!-- Table of contents -->
13 <toc>
14
15 <!-- Begin the document -->
16
17 <sect>Overview<p>
18
19 This file contains an overview of the C16 runtime system as it comes with the
20 cc65 C compiler. It describes the memory layout, C16/116 specific header
21 files, available drivers, and any pitfalls specific to that platform.
22
23 Please note that C16 specific functions are just mentioned here, they are
24 described in detail in the separate <url url="funcref.html" name="function
25 reference">. Even functions marked as "platform dependent" may be available on
26 more than one platform. Please see the function reference for more
27 information.
28
29 Since the C16/C116 and the Commodore Plus/4 are almost identical (the former
30 don't have the 6551 ACIA and only 16KB of memory), the <url
31 url="plus4.html" name="Plus/4 documentation"> is also worth a look. The
32 difference between both cc65 targets is that the Plus/4 runtime uses banking
33 to support full 64K RAM, while the C16 does not use banking and supports up to
34 32K RAM. Because banking is not needed, most C16 programs will be somewhat
35 smaller than the same program compiled for the Plus/4. However, programs C16
36 will always run on the Plus/4, while the reverse is not necessarily true.
37
38
39 <sect>Binary format<p>
40
41 The standard binary output format generated by the linker for the C16/116
42 target is a machine language program with a one line BASIC stub which, calls
43 the machine language part via SYS. This means that a program can be loaded as
44 BASIC program and started with RUN. It is of course possible to change this
45 behaviour by using a modified startup file and linker config.
46
47
48 <sect>Memory layout<p>
49
50 cc65 generated programs with the default setup run with the kernal and basic
51 banked in. This gives a usable memory range of &dollar;1000 - &dollar;4000
52 (or &dollar;8000 if the machine is equipped with 32K RAM or more). Having the
53 kernal and basic ROMs banked in means, that ROM entry points may be called
54 directly from user code.
55
56 Special locations:
57
58 <descrip>
59   <tag/Text screen/
60   The text screen is located at &dollar;C00 (as in the standard setup).
61
62   <tag/Color RAM/
63   The color RAM is located at &dollar;800 (standard location).
64
65   <tag/Stack/
66   The C runtime stack is located at &dollar;3FFF (&dollar;7FFF in case of a
67   machine with 32K of memory or more) and growing downwards.
68
69   <tag/Heap/
70   The C heap is located at the end of the program and grows towards the C
71   runtime stack.
72
73 </descrip><p>
74
75
76
77 <sect>Platform specific header files<p>
78
79 Programs containing C16 specific code may use the <tt/c16.h/ or <tt/cbm.h/
80 header files. Using the later may be an option when writing code for more than
81 one CBM platform, since it includes <tt/c16.h/ and declares several functions
82 common to all CBM platforms.
83
84 Please note that most of the header file declarations from the <tt/c16.h/
85 header file are shared between the C16 and Plus/4 configurations. For this
86 reason, most of it is located in a common header file named <tt/cbm264.h/.
87
88
89
90 <sect1>C16/C116 specific functions<p>
91
92 There are currently no special C16/C116 functions.
93
94
95 <sect1>CBM specific functions<p>
96
97 Some functions are available for all (or at least most) of the Commodore
98 machines. See the <url url="funcref.html" name="function reference"> for
99 declaration and usage.
100
101 <itemize>
102 <item>cbm_close
103 <item>cbm_closedir
104 <item>cbm_k_setlfs
105 <item>cbm_k_setnam
106 <item>cbm_k_load
107 <item>cbm_k_save
108 <item>cbm_k_open
109 <item>cbm_k_close
110 <item>cbm_k_readst
111 <item>cbm_k_chkin
112 <item>cbm_k_ckout
113 <item>cbm_k_basin
114 <item>cbm_k_bsout
115 <item>cbm_k_clrch
116 <item>cbm_k_tksa
117 <item>cbm_k_second
118 <item>cbm_load
119 <item>cbm_open
120 <item>cbm_opendir
121 <item>cbm_read
122 <item>cbm_readdir
123 <item>cbm_save
124 <item>cbm_write
125 <item>get_tv
126 </itemize>
127
128
129 <sect1>CBM specific CPU functions<p>
130
131 Some CPU related functions are available for some of the Commodore
132 machines. See the <url url="funcref.html" name="function reference"> for
133 declaration and usage.
134
135 <itemize>
136 <item>fast
137 <item>slow
138 <item>isfast
139 </itemize>
140
141 <sect1>Hardware access<p>
142
143 The following pseudo variables declared in the <tt/c16.h/ header file do
144 allow access to hardware located in the address space. Some variables are
145 structures, accessing the struct fields will access the chip registers.
146
147 <descrip>
148
149   <tag><tt/TED/</tag>
150   The <tt/TED/ structure allows access to the TED chip. See the
151   <tt/_ted.h/ header file located in the include directory for the
152   declaration of the structure.
153
154   <tag><tt/COLOR_RAM/</tag>
155   A character array that mirrors the color RAM of the C16 at &dollar;0800.
156
157 </descrip><p>
158
159
160
161 <sect>Loadable drivers<p>
162
163 The names in the parentheses denote the symbols to be used for static linking of the drivers.
164
165
166 <sect1>Graphics drivers<p>
167
168 No graphics drivers are currently available for the C16/C116.
169
170
171 <sect1>Extended memory drivers<p>
172
173 <descrip>
174
175   <tag><tt/c16-ram.emd (c16_ram_emd)/</tag>
176   A driver for the hidden RAM below the BASIC and KERNAL ROMs. Supports 125
177   pages with 256 bytes each if the machine is equipped with 64K of memory
178   (a Plus/4 or a memory extended C16/116).
179
180 </descrip><p>
181
182
183
184 <sect1>Joystick drivers<p>
185
186 <descrip>
187
188   <tag><tt/c16-stdjoy.joy (c16_stdjoy_joy)/</tag>
189   Supports up to two joysticks connected to the standard joysticks port of
190   the Commodore 16/116.
191
192 </descrip><p>
193
194
195
196 <sect1>Mouse drivers<p>
197
198 No mouse drivers are currently available for the C16/C116.
199
200
201 <sect1>RS232 device drivers<p>
202
203 The Commodore 16 does not have a builtin ACIA and no RS232 extensions are
204 known. For this reason, there are no RS232 drivers available. Please note that
205 the standard Plus/4 driver will <em>not</em> run together with the C16
206 library, because the latter does not support interrupts needed by the driver.
207
208
209 <sect>Limitations<p>
210
211
212
213 <sect>Other hints<p>
214
215 <sect1>Passing arguments to the program<p>
216
217 Command line arguments can be passed to <tt/main()/. Since this is not
218 supported by BASIC, the following syntax was chosen:
219
220 <tscreen><verb>
221     RUN:REM ARG1 " ARG2 IS QUOTED" ARG3 "" ARG5
222 </verb></tscreen>
223
224 <enum>
225 <item>Arguments are separated by spaces.
226 <item>Arguments may be quoted.
227 <item>Leading and trailing spaces around an argument are ignored. Spaces within
228       a quoted argument are allowed.
229 <item>The first argument passed to <tt/main/ is the program name.
230 <item>A maximum number of 10 arguments (including the program name) are
231       supported.
232 </enum>
233
234
235 <sect1>Program return code<p>
236
237 The program return code (low byte) is passed back to BASIC by use of the
238 <tt/ST/ variable.
239
240
241 <sect1>Interrupts<p>
242
243 The runtime for the C16 uses routines marked as <tt/.INTERRUPTOR/ for
244 interrupt handlers. Such routines must be written as simple machine language
245 subroutines and will be called automatically by the interrupt handler code
246 when they are linked into a program. See the discussion of the <tt/.CONDES/
247 feature in the <url url="ca65.html" name="assembler manual">.
248
249
250
251 <sect>License<p>
252
253 This software is provided 'as-is', without any expressed or implied
254 warranty.  In no event will the authors be held liable for any damages
255 arising from the use of this software.
256
257 Permission is granted to anyone to use this software for any purpose,
258 including commercial applications, and to alter it and redistribute it
259 freely, subject to the following restrictions:
260
261 <enum>
262 <item>  The origin of this software must not be misrepresented; you must not
263         claim that you wrote the original software. If you use this software
264         in a product, an acknowledgment in the product documentation would be
265         appreciated but is not required.
266 <item>  Altered source versions must be plainly marked as such, and must not
267         be misrepresented as being the original software.
268 <item>  This notice may not be removed or altered from any source
269         distribution.
270 </enum>
271
272 </article>
273
274
275
276