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