]> git.sur5r.net Git - cc65/blob - doc/library.sgml
remote TABs in doc/ and test/
[cc65] / doc / library.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4 <title>cc65 Library Overview
5 <author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">
6
7 <abstract>
8 An overview over the runtime and C libraries that come with the cc65 compiler,
9 including a discussion of the differences to the ISO standard.
10 </abstract>
11
12 <!-- Table of contents -->
13 <toc>
14
15 <!-- Begin the document -->
16
17 <sect>Overview<p>
18
19 This file contains a short overview of the libraries available for the cc65 C
20 compiler. Please have a look at the <url url="funcref.html" name="function
21 reference"> for a list function by function. Since the function reference is
22 not complete (I'm working on that) it may happen that you don't find a
23 specific function. In this case, have a look into the header files. All
24 functions, that are not defined by the ISO C standard have a short comment in
25 the headers, explaining their use.
26
27
28
29 <sect>ISO C compatible library<p>
30
31 The C library contains a large subset of the ISO C library. Functions are
32 usually missing in areas, where there is no support on typical 6502 systems.
33 Wide character sets are an example for this.
34
35 I will not go into detail about the ISO functions. If a function is not
36 mentioned here explicitly, expect it to be available and to behave as defined
37 in the C standard.
38
39 Functions that are <em/not/ available:
40
41 <itemize>
42   <item><tt>tmpfile/tmpnam</tt>
43   <p>
44   <item><tt>system</tt> (cc65 alternative <tt>exec</tt>)
45   <p>
46   <item>All functions that handle floating point numbers in some manner.
47   <p>
48   <item>The <tt/ldiv/ function (cc65 is currently not able to return structs
49   with a size not equal to 1, 2 or 4 bytes by value).
50   <p>
51   <item>All functions handling wide character strings.
52   <p>
53   <item>Signals and all related functions (having <tt/SIGSEGV/ would be
54   cool:-)
55   <p>
56   <item><tt>setbuf/setvbuf</tt>
57 </itemize>
58
59 Functions not available on all supported systems:
60
61 <itemize>
62   <item><tt>fopen/fread/fwrite/fclose/fputs/fgets/fscanf</tt>: The functions
63   are built on open/read/write/close. These latter functions are not available
64   on all systems.
65   <p>
66   <item><tt>ftell/fseek/fgetpos/fsetpos</tt>: Support depends on the
67   capabilities of the target machine.
68   <p>
69   <item><tt>rename/remove/rewind</tt>: Support depends on the capabilities of
70   the target machine.
71   <p>
72   <item><tt>time</tt>: Since many of the supported systems do not have a real
73   time clock, which means that the <tt/time/ function is not available. Please
74   note that the other functions from <tt/time.h/ <em/are/ available.
75 </itemize>
76
77
78 Functions that are limited in any way:
79
80 <itemize>
81   <item><tt>strcspn/strpbrk/strspn</tt>: These functions have a length
82   limitation of 256 for the second string argument. Since this string gives a
83   character set, and there are only 256 distinct characters, this shouldn't be
84   a problem.
85   <p>
86   <item><tt>getenv</tt>: Since there is no such thing as an environment on all
87   supported systems, the <tt/getenv/ function will always return a <tt/NULL/
88   pointer.
89   <p>
90   <item><tt>locale</tt>: There is no other locale than the "C" locale. The
91   native locale is identical to the "C" locale.
92 </itemize>
93
94
95 In addition to these limitations, some more functions are limited if inlined
96 versions are requested by using -Os:
97
98 <itemize>
99   <item>The <tt/strlen/ function only works for strings with a maximum length
100   of 255 characters.
101   <p>
102   <item>The <tt/isxxx/ character classification functions from
103   <tt/&lt;ctype.h&gt;/ will give unpredictable results if the argument is not
104   in character range (0..255). This limitation may be removed by #undef'ing
105   the function name (when using <tt/-Os/, the functions are actually macros
106   that expand to inline assembler code, but the real functions are still
107   available if the macro definition is removed).
108 </itemize>
109
110
111
112 <sect>CPU specific stuff - 6502.h<p>
113
114 The header file 6502.h contains some functions that make only sense with the
115 6502 CPU. Examples are macros to insert more or less useful instructions into
116 your C code, or a function to call arbitrary machine language subroutines,
117 passing registers in and out.
118
119
120
121 <sect>Target specific stuff<p>
122
123 For each supported system there's a header file that contains calls or defines
124 specific for this system. So, when programming for the C64, include c64.h, for
125 the C128, include c128.h and so on. To make the task for the Commodore systems
126 easier, there is also a header file named cbm.h that will define stuff common
127 for all CBM systems, and include the header file for the specific target
128 system.
129
130 The header files contain
131
132 <itemize>
133
134   <item>Defines for special keys (like function keys)
135
136   <item>Defines for special characters (like the graphics characters)
137
138   <item>Variables with a fixed address in memory that may be used to access
139   special hardware. For the C64 and C128 there is a variable struct named
140   <tt/SID/. Writing to the fields of this struct will write to the SID device
141   instead. Using these variables will make your program more readable and more
142   portable. Don't fear ineffective code when using these variables, the
143   compiler will translate reads and writes to these structs into direct memory
144   accesses.
145
146   <item>Other routines that make only sense for a specific system. One example
147   are routines to write memory locations in the system bank for the CBM PET-II
148   family.
149
150 </itemize>
151
152
153 <sect>Direct console I/O - <tt/conio.h/<p>
154
155 The <tt/conio.h/ header file contains a large set of functions that do screen
156 and keyboard I/O. The functions will write directly to the screen or poll the
157 keyboard directly with no more help from the operating system than needed.
158 This has some disadvantages, but on the other side it's fast and reasonably
159 portable. conio implementations exist for the following targets:
160
161   <itemize>
162   <item>apple2
163   <item>apple2enh
164   <item>atari
165   <item>atarixl
166   <item>atmos
167   <item>c16 (works also for the c116 with up to 32K memory)
168   <item>c64
169   <item>c128
170   <item>plus4 (or expanded c16/c116)
171   <item>cbm510 (40 column video)
172   <item>cbm610 (all CBM series-II computers with 80 column video)
173   <item>creativision
174   <item>gamate
175   <item>geos-apple
176   <item>geos-cbm
177   <item>nes
178   <item>osic1p
179   <item>pce
180   <item>pet (all CBM PET systems except the 2001)
181   <item>telestrat
182   <item>vic20
183   </itemize>
184
185 The conio.h header file does also include the system specific header files
186 which define constants for special characters and keys.
187
188
189
190 <sect>Using the joystick - <tt/joystick.h/<p>
191
192 For systems that have a joystick, <tt/joystick.h/ will define a subroutine to
193 read the current value, including constants to evaluate the result of this
194 function.
195
196
197
198 <sect>Using a mouse - <tt/mouse.h/<p>
199
200 Some target machines support a mouse. Mouse support is currently available for
201 the following targets:
202
203   <itemize>
204   <item>apple2
205   <item>apple2enh
206   <item>atari
207   <item>atarixl
208   <item>c64
209   <item>c128
210   <item>cbm510
211   </itemize>
212
213 The available functions are declared in <tt/mouse.h/.
214
215
216 <sect>Copyright<p>
217
218 This C runtime library implementation for the cc65 compiler is (C)
219 Copyright 1998-2002 Ullrich von Bassewitz. For usage of the binaries
220 and/or sources the following conditions do apply:
221
222 This software is provided 'as-is', without any expressed or implied
223 warranty.  In no event will the authors be held liable for any damages
224 arising from the use of this software.
225
226 Permission is granted to anyone to use this software for any purpose,
227 including commercial applications, and to alter it and redistribute it
228 freely, subject to the following restrictions:
229
230 <enum>
231 <item>  The origin of this software must not be misrepresented; you must not
232         claim that you wrote the original software. If you use this software
233         in a product, an acknowledgment in the product documentation would be
234         appreciated but is not required.
235 <item>  Altered source versions must be plainly marked as such, and must not
236         be misrepresented as being the original software.
237 <item>  This notice may not be removed or altered from any source
238         distribution.
239 </enum>
240
241 </article>