1 <!doctype linuxdoc system>
5 <title>Commodore 510 (aka P500) specific information for cc65
6 <author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">&nl;
7 Stefan A. Haubenthal, <htmlurl url="mailto:polluks@sdf.lonestar.org" name="polluks@sdf.lonestar.org">&nl;
8 <htmlurl url="mailto:greg.king5@verizon.net" name="Greg King">
12 An overview over the Commodore 510 runtime system as it is implemented for the
16 <!-- Table of contents -->
19 <!-- Begin the document -->
23 This file contains an overview of the CBM 510 runtime system as it comes with
24 the cc65 C compiler. It describes the memory layout, CBM 510 specific header
25 files, available drivers, and any pitfalls specific to that platform.
27 Please note that CBM 510 specific functions are just mentioned here, they are
28 described in detail in the separate <htmlurl url="funcref.html" name="function
29 reference">. Even functions marked as "platform dependent" may be available on
30 more than one platform. Please see the function reference for more
33 In addition to the Commodore 510 (named P128 in the U.S.), no other
34 machines are supported by this cc65 target.
38 <sect>Binary format<p>
40 The standard binary output format generated by the linker for the Commodore
41 510 target is a machine language program with a one line BASIC stub, which
42 transfers control to the machine language running in bank 0. This means that a
43 program can be loaded as BASIC program and started with RUN. It is of course
44 possible to change this behaviour by using a modified startup file and linker
49 <sect>Memory layout<p>
51 cc65 generated programs for the Commodore 510 run in bank 0, the memory bank
52 reserved for BASIC programs. Since there are no ROMs in this memory bank,
53 kernal subroutines are either emulated or called by bank switching, which has
54 the disadvantage of being slow compared to a direct call.
56 The default memory configuration for the CBM 510 allocates all memory between
57 $0002 and $FFF0 in bank 0 for the compiled program. Some space
58 in low memory is lost, because a separate hardware stack is set up in page 1,
59 and the kernal replacement functions need some more memory locations. A few
60 more pages are lost in high memory, because the runtime sets up a copy of the
61 character ROM, a text screen and a CBM compatible jump table at $FF81.
62 The main startup code is located at $0400, so about 54K of the complete
63 bank are actually usable for applications.
69 The C runtime stack is located at $FF81 and growing downwards.
72 The C heap is located at the end of the program and grows towards the C
78 <sect>Platform specific header files<p>
80 Programs containing CBM 510 specific code may use the <tt/cbm510.h/ or
81 <tt/cbm.h/ header files. Using the later may be an option when writing code
82 for more than one CBM platform, since it includes <tt/cbm510.h/ and declares
83 several functions common to all CBM platforms.
85 <sect1>CBM 510 specific functions<p>
87 The functions listed below are special for the CBM 510. See the <htmlurl
88 url="funcref.html" name="function reference"> for declaration and usage.
98 <sect1>CBM specific functions<p>
100 Some functions are available for all (or at least most) of the Commodore
101 machines. See the <htmlurl url="funcref.html" name="function reference"> for
102 declaration and usage.
132 <sect1>Hardware access<p>
134 The following pseudo variables declared in the <tt/cbm510.h/ header file do
135 allow access to hardware located in the address space. Some variables are
136 structures, accessing the struct fields will access the chip registers.
138 <bf>Note:</bf> All I/O chips are located in the system bank (bank 15) and can
139 therefore not be accessed like on other platforms. Please use one of the
140 <tt/peekbsys/, <tt/peekwsys/, <tt/pokebsys/ and <tt/pokewsys/ functions to
141 access the I/O chips. Direct reads and writes to the structures named below
142 will <em>not</em> work!
147 The <tt/VIC/ structure allows access to the VIC II (the graphics
148 controller). See the <tt/_vic2.h/ header file located in the include
149 directory for the declaration of the structure.
152 The <tt/SID/ structure allows access to the SID (the sound interface
153 device). See the <tt/_sid.h/ header file located in the include directory
154 for the declaration of the structure.
157 Access to the ACIA (the RS232 chip) is available via the <tt/ACIA/ variable.
158 See the <tt/_6551.h/ header file located in the include directory for the
159 declaration of the structure.
162 Access to the CIA chip is available via the <tt/CIA/ variable. See the
163 <tt/_6526.h/ header file located in the include directory for the
164 declaration of the structure.
166 <tag><tt/TPI1, TPI2/</tag>
167 The two 6525 triport chips may be accessed by using this variable. See the
168 <tt/_6525.h/ header file located in the include directory for the
169 declaration of the structure.
175 <sect>Loadable drivers<p>
177 The names in the parentheses denote the symbols to be used for static linking of the drivers.
180 <sect1>Graphics drivers<p>
182 No graphics drivers are currently available for the Commodore 510.
185 <sect1>Extended memory drivers<p>
188 <tag><tt/cbm510-ram.emd (cbm510_ram_emd)/</tag>
189 A driver for the RAM in bank 1. Supports up to 255 pages with 256 bytes
194 <sect1>Joystick drivers<p>
198 <tag><tt/cbm510-std.joy (cbm510_std_joy)/</tag>
199 Supports up to two standard joysticks connected to the joysticks port of
205 <sect1>Mouse drivers<p>
209 <tag><tt/cbm510-joy.mou (cbm510_joy_mou)/</tag>
210 Supports a mouse that is emulated by a standard joystick, e.g. 1350
211 mouse, in joystick port #2 of the CBM510. That stick's fire button acts as
212 the left mouse button. The fire button of a stick in joystick port #1 can
213 act as the right mouse button.
215 <tag><tt/cbm510-inkwl.mou (cbm510_inkwl_mou)/</tag>
216 Supports the Inkwell Systems lightpens, connected to port #1 of the CBM510.
217 It can read both the 170-C and one button of the 184-C pens. (It can
218 read other lightpens and light-guns that send their button signal to the
219 joystick left-button pin.)
223 <sect1>RS232 device drivers<p>
227 <tag><tt/cbm510-std.ser (cbm510_std_ser)/</tag>
228 Driver for the 6551 ACIA chip built into the Commodore 510. Supports up to
229 19200 baud, hardware flow control (RTS/CTS) and interrupt driven receives.
230 Note that because of the peculiarities of the 6551 chip transmits are not
231 interrupt driven, and the transceiver blocks if the receiver asserts flow
232 control because of a full buffer.
237 <sect>Limitations<label id="limitations"><p>
240 <sect1>Kernal and hardware access<p>
242 Since the program runs in bank 0, and the kernal and all I/O chips are located
243 in bank 15, calling ROM routines or accessing hardware needs special code. The
244 cc65 runtime implements wrappers for all functions in the kernal jump table.
245 While this simplifies things, it should be noted that the wrappers do have
246 quite an impact on performance: A cross bank call has an extra 300µs
247 penalty added by the wrapper.
251 Compiled programs contain an interrupt handler that runs in the program bank.
252 This has several advantages, one of them being performance (see cross bank
253 call overhead mentioned above). However, this introduces one problem:
254 Interrupts are lost while the CPU executes code in the kernal bank. As a
255 result, the clock may go wrong and (worse) serial interrupts may get lost.
257 Since the cc65 runtime does only call the kernal for disk I/O, this means that
258 a program should not do file I/O while it depends on interrupts.
263 <sect1>Passing arguments to the program<p>
265 Command line argument passing is currently not supported for the Commodore
269 <sect1>Program return code<p>
271 The program return code (signed char) is passed back to BASIC by use of the
275 <sect1>Interrupt handlers<p>
277 The runtime for the Commodore 510 uses routines marked as <tt/.INTERRUPTOR/
278 for interrupt handlers. Such routines must be written as simple machine
279 language subroutines and will be called automatically by the interrupt handler
280 code when they are linked into a program. See the discussion of the
281 <tt/.CONDES/ feature in the <htmlurl url="ca65.html" name="assembler manual">.
287 This software is provided 'as-is', without any expressed or implied
288 warranty. In no event will the authors be held liable for any damages
289 arising from the use of this software.
291 Permission is granted to anyone to use this software for any purpose,
292 including commercial applications, and to alter it and redistribute it
293 freely, subject to the following restrictions:
296 <item> The origin of this software must not be misrepresented; you must not
297 claim that you wrote the original software. If you use this software
298 in a product, an acknowledgment in the product documentation would be
299 appreciated but is not required.
300 <item> Altered source versions must be plainly marked as such, and must not
301 be misrepresented as being the original software.
302 <item> This notice may not be removed or altered from any source