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