2014-02-04 21:18:58 +00:00
|
|
|
<!doctype linuxdoc system>
|
|
|
|
|
|
|
|
<article>
|
|
|
|
<title>cc65 Library Overview
|
2014-04-08 19:36:39 +00:00
|
|
|
<author><url url="mailto:uz@cc65.org" name="Ullrich von Bassewitz">
|
2014-02-04 21:18:58 +00:00
|
|
|
|
|
|
|
<abstract>
|
|
|
|
An overview over the runtime and C libraries that come with the cc65 compiler,
|
|
|
|
including a discussion of the differences to the ISO standard.
|
|
|
|
</abstract>
|
|
|
|
|
|
|
|
<!-- Table of contents -->
|
|
|
|
<toc>
|
|
|
|
|
|
|
|
<!-- Begin the document -->
|
|
|
|
|
|
|
|
<sect>Overview<p>
|
|
|
|
|
|
|
|
This file contains a short overview of the libraries available for the cc65 C
|
2014-04-14 09:54:13 +00:00
|
|
|
compiler. Please have a look at the <url url="funcref.html" name="function
|
2020-01-10 20:17:23 +00:00
|
|
|
reference"> for a function-by-function list. Because the function reference is
|
|
|
|
not complete (we're working on that), it may happen that you don't find a
|
|
|
|
specific function. In that case, have a look into the header files. All
|
|
|
|
functions, that are not defined by the ISO C standard, have a short comment in
|
2014-02-04 21:18:58 +00:00
|
|
|
the headers, explaining their use.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<sect>ISO C compatible library<p>
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
The C library contains a large subset of the ISO C library. Functions usually
|
|
|
|
are missing in areas where there are no support on typical 6502 systems.
|
|
|
|
Wide-character sets are an example for that.
|
2014-02-04 21:18:58 +00:00
|
|
|
|
|
|
|
I will not go into detail about the ISO functions. If a function is not
|
2020-01-10 20:17:23 +00:00
|
|
|
mentioned here explicitly, expect it to be available, and to behave as defined
|
2014-02-04 21:18:58 +00:00
|
|
|
in the C standard.
|
|
|
|
|
|
|
|
Functions that are <em/not/ available:
|
|
|
|
|
|
|
|
<itemize>
|
|
|
|
<item><tt>tmpfile/tmpnam</tt>
|
|
|
|
<p>
|
2018-02-28 00:24:28 +00:00
|
|
|
<item><tt>system</tt> (cc65 alternative <tt>exec</tt>)
|
2014-02-04 21:18:58 +00:00
|
|
|
<p>
|
|
|
|
<item>All functions that handle floating point numbers in some manner.
|
|
|
|
<p>
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>The <tt/ldiv/ function (cc65 currently is not able to return structs,
|
|
|
|
by value, with a size not equal to 1, 2, or 4 bytes).
|
2014-02-04 21:18:58 +00:00
|
|
|
<p>
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>All functions handling wide-character strings.
|
2014-02-04 21:18:58 +00:00
|
|
|
<p>
|
|
|
|
<item>Signals and all related functions (having <tt/SIGSEGV/ would be
|
2020-01-10 20:17:23 +00:00
|
|
|
cool. :-)
|
2014-02-04 21:18:58 +00:00
|
|
|
<p>
|
|
|
|
<item><tt>setbuf/setvbuf</tt>
|
|
|
|
</itemize>
|
|
|
|
|
|
|
|
Functions not available on all supported systems:
|
|
|
|
|
|
|
|
<itemize>
|
2021-11-21 21:56:02 +00:00
|
|
|
<item><tt>clock</tt>: Support depends on the capabilities of the target
|
|
|
|
machine.
|
|
|
|
<p>
|
2014-02-04 21:18:58 +00:00
|
|
|
<item><tt>fopen/fread/fwrite/fclose/fputs/fgets/fscanf</tt>: The functions
|
2020-01-10 20:17:23 +00:00
|
|
|
are built on open/read/write/close. Those latter functions are not available
|
2014-02-04 21:18:58 +00:00
|
|
|
on all systems.
|
|
|
|
<p>
|
|
|
|
<item><tt>ftell/fseek/fgetpos/fsetpos</tt>: Support depends on the
|
|
|
|
capabilities of the target machine.
|
|
|
|
<p>
|
|
|
|
<item><tt>rename/remove/rewind</tt>: Support depends on the capabilities of
|
|
|
|
the target machine.
|
|
|
|
<p>
|
2020-01-10 20:17:23 +00:00
|
|
|
<item><tt>time</tt>: Many of the supported systems don't have a real-time
|
|
|
|
clock, which means that the <tt/time/ function is not available. Please note
|
|
|
|
that the other functions from <tt/time.h/ <em/are/ available.
|
2014-02-04 21:18:58 +00:00
|
|
|
</itemize>
|
|
|
|
|
|
|
|
|
|
|
|
Functions that are limited in any way:
|
|
|
|
|
|
|
|
<itemize>
|
2020-01-10 20:17:23 +00:00
|
|
|
<item><tt>strcspn/strpbrk/strspn</tt>: Those functions have a length
|
|
|
|
limitation of 256 for the second string argument. Since that string gives a
|
|
|
|
character set, and there are only 256 distinct characters, that shouldn't be
|
2014-02-04 21:18:58 +00:00
|
|
|
a problem.
|
|
|
|
<p>
|
|
|
|
<item><tt>getenv</tt>: Since there is no such thing as an environment on all
|
2020-01-10 20:17:23 +00:00
|
|
|
supported systems, the <tt/getenv/ function always will return a <tt/NULL/
|
2014-02-04 21:18:58 +00:00
|
|
|
pointer.
|
|
|
|
<p>
|
2020-01-10 20:17:23 +00:00
|
|
|
<item><tt>locale</tt>: There is no locale other than the "C" locale. The
|
2014-02-04 21:18:58 +00:00
|
|
|
native locale is identical to the "C" locale.
|
|
|
|
</itemize>
|
|
|
|
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
In addition to those limitations, some more functions are limited if inlined
|
|
|
|
versions are requested by using the <tt/-Os/ command-line option:
|
2014-02-04 21:18:58 +00:00
|
|
|
|
|
|
|
<itemize>
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>The <tt/strlen/ function works for only strings with a maximum length
|
2014-02-04 21:18:58 +00:00
|
|
|
of 255 characters.
|
|
|
|
<p>
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>The <tt/isXXX/ character classification functions from
|
2014-02-04 21:18:58 +00:00
|
|
|
<tt/<ctype.h>/ will give unpredictable results if the argument is not
|
2020-01-10 20:17:23 +00:00
|
|
|
in character range (0..255). That limitation may be removed by #undef'ing
|
2014-02-04 21:18:58 +00:00
|
|
|
the function name (when using <tt/-Os/, the functions are actually macros
|
2020-01-10 20:17:23 +00:00
|
|
|
that expand to inline assembly code, but the real functions still are
|
2014-02-04 21:18:58 +00:00
|
|
|
available if the macro definition is removed).
|
|
|
|
</itemize>
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
<sect>CPU-specific stuff - 6502.h<p>
|
2014-02-04 21:18:58 +00:00
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
The header file 6502.h contains some functions that make sense only with the
|
2014-02-04 21:18:58 +00:00
|
|
|
6502 CPU. Examples are macros to insert more or less useful instructions into
|
|
|
|
your C code, or a function to call arbitrary machine language subroutines,
|
|
|
|
passing registers in and out.
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
<sect>Target-specific stuff<p>
|
2014-02-04 21:18:58 +00:00
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
For each supported system, there's a header file that contains calls or
|
|
|
|
defines specific for that system. So, when programming for the C64, include
|
|
|
|
<tt/<c64.h>/, for the C128, include <tt/<c128.h>/, and so on.
|
|
|
|
To make the task for the Commodore systems easier, there is also a header file
|
|
|
|
named <tt/<cbm.h>/ that will define stuff common for all CBM systems,
|
|
|
|
and include the header file for the specific target system.
|
2014-02-04 21:18:58 +00:00
|
|
|
|
|
|
|
The header files contain
|
|
|
|
|
|
|
|
<itemize>
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>Defines for special keys (such as function keys)
|
2014-02-04 21:18:58 +00:00
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>Defines for special characters (such as the graphics characters)
|
2014-02-04 21:18:58 +00:00
|
|
|
|
|
|
|
<item>Variables with a fixed address in memory that may be used to access
|
2020-01-10 20:17:23 +00:00
|
|
|
special hardware. For the C64 and C128, there is a variable struct named
|
|
|
|
<tt/SID/. Writing to the fields of that struct will write to the SID device
|
|
|
|
instead. Using those variables will make your program more readable and more
|
|
|
|
portable. Don't fear ineffective code when using those variables, the
|
|
|
|
compiler will translate reads and writes to those structs into direct memory
|
2014-02-04 21:18:58 +00:00
|
|
|
accesses.
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>Other routines that make sense for only a specific system. One example
|
|
|
|
is routines to write memory locations in the system bank for the CBM-II
|
2014-02-04 21:18:58 +00:00
|
|
|
family.
|
|
|
|
|
|
|
|
</itemize>
|
|
|
|
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
|
2014-02-04 21:18:58 +00:00
|
|
|
<sect>Direct console I/O - <tt/conio.h/<p>
|
|
|
|
|
|
|
|
The <tt/conio.h/ header file contains a large set of functions that do screen
|
|
|
|
and keyboard I/O. The functions will write directly to the screen or poll the
|
|
|
|
keyboard directly with no more help from the operating system than needed.
|
|
|
|
This has some disadvantages, but on the other side it's fast and reasonably
|
2020-01-10 20:17:23 +00:00
|
|
|
portable. Conio implementations exist for the following targets:
|
2014-02-04 21:18:58 +00:00
|
|
|
|
|
|
|
<itemize>
|
|
|
|
<item>apple2
|
|
|
|
<item>apple2enh
|
|
|
|
<item>atari
|
2019-04-12 12:01:26 +00:00
|
|
|
<item>atari5200
|
2014-02-04 21:51:39 +00:00
|
|
|
<item>atarixl
|
2014-02-04 21:18:58 +00:00
|
|
|
<item>atmos
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>c128
|
2014-02-04 21:18:58 +00:00
|
|
|
<item>c16 (works also for the c116 with up to 32K memory)
|
|
|
|
<item>c64
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>cbm510 (40-column video)
|
|
|
|
<item>cbm610 (all CBM series-II computers with 80-column video)
|
2018-02-28 00:24:28 +00:00
|
|
|
<item>creativision
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>cx16
|
2018-02-28 00:24:28 +00:00
|
|
|
<item>gamate
|
2014-02-04 21:18:58 +00:00
|
|
|
<item>geos-apple
|
|
|
|
<item>geos-cbm
|
|
|
|
<item>nes
|
2018-02-28 00:24:28 +00:00
|
|
|
<item>osic1p
|
|
|
|
<item>pce
|
2014-02-04 21:18:58 +00:00
|
|
|
<item>pet (all CBM PET systems except the 2001)
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>plus4 (or expanded c16/c116)
|
2018-02-28 00:24:28 +00:00
|
|
|
<item>telestrat
|
2014-02-04 21:18:58 +00:00
|
|
|
<item>vic20
|
|
|
|
</itemize>
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
The <tt/conio.h/ header file does include the system-specific header files also,
|
2014-02-04 21:18:58 +00:00
|
|
|
which define constants for special characters and keys.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<sect>Using the joystick - <tt/joystick.h/<p>
|
|
|
|
|
|
|
|
For systems that have a joystick, <tt/joystick.h/ will define a subroutine to
|
2020-01-10 20:17:23 +00:00
|
|
|
read the current value, including constants to evaluate the result of that
|
2014-02-04 21:51:39 +00:00
|
|
|
function.
|
2014-02-04 21:18:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<sect>Using a mouse - <tt/mouse.h/<p>
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
Some target machines support a mouse. Mouse support currently is available for
|
2014-02-04 21:18:58 +00:00
|
|
|
the following targets:
|
|
|
|
|
|
|
|
<itemize>
|
|
|
|
<item>apple2
|
|
|
|
<item>apple2enh
|
|
|
|
<item>atari
|
2014-02-04 21:51:39 +00:00
|
|
|
<item>atarixl
|
2014-02-04 21:18:58 +00:00
|
|
|
<item>c128
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>c64
|
2018-02-28 00:24:28 +00:00
|
|
|
<item>cbm510
|
2020-01-10 20:17:23 +00:00
|
|
|
<item>cx16
|
2014-02-04 21:18:58 +00:00
|
|
|
</itemize>
|
|
|
|
|
2014-02-04 21:51:39 +00:00
|
|
|
The available functions are declared in <tt/mouse.h/.
|
2014-02-04 21:18:58 +00:00
|
|
|
|
|
|
|
|
2020-01-10 20:17:23 +00:00
|
|
|
|
2014-02-04 21:18:58 +00:00
|
|
|
<sect>Copyright<p>
|
|
|
|
|
|
|
|
This C runtime library implementation for the cc65 compiler is (C)
|
|
|
|
Copyright 1998-2002 Ullrich von Bassewitz. For usage of the binaries
|
2020-01-10 20:17:23 +00:00
|
|
|
and/or sources, the following conditions do apply:
|
2014-02-04 21:18:58 +00:00
|
|
|
|
|
|
|
This software is provided 'as-is', without any expressed or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
<enum>
|
2019-02-12 21:50:49 +00:00
|
|
|
<item> The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
2020-01-10 20:17:23 +00:00
|
|
|
appreciated, but is not required.
|
|
|
|
<item> Altered source versions must be marked plainly as such, and must not
|
2019-02-12 21:50:49 +00:00
|
|
|
be misrepresented as being the original software.
|
|
|
|
<item> This notice may not be removed or altered from any source
|
|
|
|
distribution.
|
2014-02-04 21:18:58 +00:00
|
|
|
</enum>
|
|
|
|
|
|
|
|
</article>
|