]> git.sur5r.net Git - cc65/blob - doc/cbm510.sgml
New cbm510 docs by Stefan Haubenthal.
[cc65] / doc / cbm510.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4
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">
7 Stefan A. Haubenthal, <htmlurl url="mailto:polluks@sdf.lonestar.org" name="polluks@sdf.lonestar.org">
8 <date>2006-05-22
9
10 <abstract>
11 An overview over the Commodore 510 runtime system as it is implemented for the
12 cc65 C compiler.
13 </abstract>
14
15 <!-- Table of contents -->
16 <toc>
17
18 <!-- Begin the document -->
19
20 <sect>Overview<p>
21
22 This file contains an overview of the CBM 510 runtime system as it comes with
23 the cc65 C compiler. It describes the memory layout, CBM 510 specific header
24 files, available drivers, and any pitfalls specific to that platform.
25
26 Please note that CBM 510 specific functions are just mentioned here, they are
27 described in detail in the separate <htmlurl url="funcref.html" name="function
28 reference">. Even functions marked as "platform dependent" may be available on
29 more than one platform. Please see the function reference for more
30 information.
31
32 In addition to the Commodore 510 (named P128 in the U.S.), no other
33 machines are supported by this cc65 target.
34
35
36
37 <sect>Binary format<p>
38
39 The standard binary output format generated by the linker for the CBM510
40 target is a machine language program with a short BASIC stub. This means that
41 a program can be loaded as BASIC program and started with RUN. It is of course
42 possible to change this behaviour by using a modified startup file and linker
43 config.
44
45
46 <sect>Memory layout<p>
47
48 cc65 generated programs for the Commodore 510 run in bank 0, the memory bank
49 reserved for BASIC programs. Since there are no ROMs in this memory bank, the
50 program has almost full 64K for its own. A disadvantage is that kernal
51 subroutines cannot be called (at least not in a fast and effective manner), so
52 the runtime has replace kernal functionality.
53
54 The default memory configuration for the CBM 510 allocates all memory between
55 &dollar;0002 and &dollar;FFF0 in bank 0 for the compiled program. Some space
56 in low memory is lost, because a separate hardware stack is set up in page 1,
57 and the kernal replacement functions need some more memory locations. A few
58 more pages are lost in high memory, because the runtime sets up a copy of the
59 character ROM, a text screen and a CBM compatible jump table at &dollar;FF81.
60 The main startup code is located at &dollar;0400, so about 54K of the complete
61 bank are actually usable for applications.
62
63 Special locations:
64
65 <descrip>
66   <tag/Stack/
67   The C runtime stack is located at &dollar;FF81 and growing downwards.
68
69   <tag/Heap/
70   The C heap is located at the end of the program and grows towards the C
71   runtime stack.
72 </descrip><p>
73
74
75
76 <sect>Platform specific header files<p>
77
78 Programs containing CBM 510 specific code may use the <tt/cbm510.h/ or
79 <tt/cbm.h/ header files. Using the later may be an option when writing code
80 for more than one CBM platform, since it includes <tt/cbm510.h/ and declares
81 several functions common to all CBM platforms.
82
83 <sect1>CBM 510 specific functions<p>
84
85 The functions listed below are special for the CBM 510. See the <htmlurl
86 url="funcref.html" name="function reference"> for declaration and usage.
87
88 <itemize>
89 <item>peekbsys
90 <item>peekwsys
91 <item>pokebsys
92 <item>pokewsys
93 </itemize>
94
95
96 <sect1>CBM specific functions<p>
97
98 Some functions are available for all (or at least most) of the Commodore
99 machines. See the <htmlurl url="funcref.html" name="function reference"> for
100 declaration and usage.
101
102
103 <itemize>
104 <item>cbm_close
105 <item>cbm_closedir
106 <item>cbm_k_setlfs
107 <item>cbm_k_setnam
108 <item>cbm_k_load
109 <item>cbm_k_save
110 <item>cbm_k_open
111 <item>cbm_k_close
112 <item>cbm_k_readst
113 <item>cbm_k_chkin
114 <item>cbm_k_ckout
115 <item>cbm_k_basin
116 <item>cbm_k_bsout
117 <item>cbm_k_clrch
118 <item>cbm_load
119 <item>cbm_open
120 <item>cbm_opendir
121 <item>cbm_read
122 <item>cbm_readdir
123 <item>cbm_save
124 <item>cbm_write
125 <item>get_tv
126 </itemize>
127
128
129
130 <sect1>Hardware access<p>
131
132 The following pseudo variables declared in the <tt/cbm510.h/ header file do
133 allow access to hardware located in the address space. Some variables are
134 structures, accessing the struct fields will access the chip registers.
135
136 <bf>Note:</bf> All I/O chips are located in the system bank (bank 15) and can
137 therefore not be accessed like on other platforms. Please use one of the
138 <tt/peekbsys/, <tt/peekwsys/, <tt/pokebsys/ and <tt/pokewsys/ functions to
139 access the I/O chips. Direct reads and writes to the structures named below
140 will <em>not</em> work!
141
142 <descrip>
143
144   <tag><tt/VIC/</tag>
145   The <tt/VIC/ structure allows access to the VIC II (the graphics
146   controller). See the <tt/_vic2.h/ header file located in the include
147   directory for the declaration of the structure.
148
149   <tag><tt/SID/</tag>
150   The <tt/SID/ structure allows access to the SID (the sound interface
151   device). See the <tt/_sid.h/ header file located in the include directory
152   for the declaration of the structure.
153
154   <tag><tt/ACIA/</tag>
155   Access to the ACIA (the RS232 chip) is available via the <tt/ACIA/ variable.
156   See the <tt/_6551.h/ header file located in the include directory for the
157   declaration of the structure.
158
159   <tag><tt/CIA/</tag>
160   Access to the CIA chip is available via the <tt/CIA/ variable. See the
161   <tt/_6526.h/ header file located in the include directory for the
162   declaration of the structure.
163
164   <tag><tt/TPI1, TPI2/</tag>
165   The two 6525 triport chips may be accessed by using this variable. See the
166   <tt/_6525.h/ header file located in the include directory for the
167   declaration of the structure.
168
169 </descrip><p>
170
171
172
173 <sect>Loadable drivers<p>
174
175
176 <sect1>Graphics drivers<p>
177
178 No graphics drivers are currently available for the Commodore 510.
179
180
181 <sect1>Extended memory drivers<p>
182
183 <descrip>
184   <tag><tt/cbm510-ram.emd/</tag>
185   A driver for the RAM in bank 1. Supports up to 255 pages with 256 bytes
186   each.
187 </descrip><p>
188
189
190 <sect1>Joystick drivers<p>
191
192 <descrip>
193
194   <tag><tt/cbm510-std.joy/</tag>
195   Supports up to two standard joysticks connected to the joysticks port of
196   the Commodore 510.
197
198 </descrip><p>
199
200
201 <sect1>Mouse drivers<p>
202
203 No mouse drivers are currently available for the Commodore 510.
204
205
206 <sect1>RS232 device drivers<p>
207
208 <descrip>
209
210   <tag><tt/cbm510-std.ser/</tag>
211   Driver for the 6551 ACIA chip built into the Commodore 510. Supports up to
212   19200 baud, hardware flow control (RTS/CTS) and interrupt driven receives.
213   Note that because of the peculiarities of the 6551 chip transmits are not
214   interrupt driven, and the transceiver blocks if the receiver asserts flow
215   control because of a full buffer.
216
217 </descrip><p>
218
219
220 <sect>Limitations<label id="limitations"><p>
221
222
223 <sect1>Kernal and hardware access<p>
224
225 Since the program runs in bank 0, and the kernal and all I/O chips are located
226 in bank 15, calling ROM routines or accessing hardware needs special code. The
227 cc65 runtime implements wrappers for all functions in the kernal jump table.
228 While this simplifies things, it should be noted that the wrappers do have
229 quite an impact on performance: A cross bank call has an extra 300&micro;s
230 penalty added by the wrapper.
231
232 <sect1>Interrupts<p>
233
234 Compiled programs contain an interrupt handler that runs in the program bank.
235 This has several advantages, one of them being performance (see cross bank
236 call overhead mentioned above). However, this introduces one problem:
237 Interrupts are lost while the CPU executes code in the kernal bank. As a
238 result, the clock may go wrong and (worse) serial interrupts may get lost.
239
240 Since the cc65 runtime does only call the kernal for disk I/O, this means that
241 a program should not do file I/O while it depends on interrupts.
242
243
244 <sect>Other hints<p>
245
246 <sect1>Passing arguments to the program<p>
247
248 Command line argument passing is currently not supported for the Commodore
249 510.
250
251
252 <sect1>Program return code<p>
253
254 The program return code (signed char) is passed back to BASIC by use of the
255 <tt/ST/ variable.
256
257
258 <sect1>Interrupts<p>
259
260 The runtime for the Commodore 510 uses routines marked as <tt/.CONDES/ type 2
261 for interrupt handlers. Such routines must be written as simple machine
262 language subroutines and will be called automatically by the interrupt handler
263 code when they are linked into a program. See the discussion of the
264 <tt/.CONDES/ feature in the <htmlurl url="ca65.html" name="assembler manual">.
265
266
267
268 <sect>Bugs/Feedback<p>
269
270 If you have problems using the library, if you find any bugs, or if you're
271 doing something interesting with it, I would be glad to hear from you. Feel
272 free to contact me by email (<htmlurl url="mailto:uz@cc65.org"
273 name="uz@cc65.org">).
274
275
276
277 <sect>License<p>
278
279 This software is provided 'as-is', without any expressed or implied
280 warranty.  In no event will the authors be held liable for any damages
281 arising from the use of this software.
282
283 Permission is granted to anyone to use this software for any purpose,
284 including commercial applications, and to alter it and redistribute it
285 freely, subject to the following restrictions:
286
287 <enum>
288 <item>  The origin of this software must not be misrepresented; you must not
289         claim that you wrote the original software. If you use this software
290         in a product, an acknowledgment in the product documentation would be
291         appreciated but is not required.
292 <item>  Altered source versions must be plainly marked as such, and must not
293         be misrepresented as being the original software.
294 <item>  This notice may not be removed or altered from any source
295         distribution.
296 </enum>
297
298 </article>