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