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