]> git.sur5r.net Git - cc65/blob - doc/cbm610.sgml
Added command-line argument parsing to the CBM510 and CBM610 targets.
[cc65] / doc / cbm610.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4
5 <title>Commodore 610-specific information for cc65
6 <author>Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org"><newline>
7 <url url="mailto:greg.king5@verizon.net" name="Greg King">
8 <date>2004-04-02
9
10 <abstract>
11 An overview over the Commodore 610 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 610 runtime system as it comes with
23 the cc65 C compiler. It describes the memory layout, CBM 610-specific header
24 files, available drivers, and any pitfalls specific to that platform.
25
26 Please note that CBM 610-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 610 (named B40 in the U.S.), several other
33 machines are supported by this cc65 target, since they have identical
34 hardware: The Commodore 620 and 630 (more memory, additional coprocessor
35 card), and the Commodore 710, 720, and 730 (same hardware in another case with
36 a built-in monitor).
37
38
39
40 <sect>Binary format<p>
41
42 The standard binary output format generated by the linker for the Commodore
43 610 target is a machine language program with a one-line BASIC stub, which
44 transfers control to the machine language running in bank 1. That means that a
45 program can be loaded as a BASIC program, and started with RUN. It is, of course,
46 possible to change that behaviour by using a modified startup file and linker
47 config.
48
49
50
51 <sect>Memory layout<p>
52
53 cc65 generated programs for the Commodore 610 run in bank 1, the memory bank
54 reserved for BASIC programs. Since there are no ROMs in this memory bank,
55 kernal subroutines are either emulated or called by bank switching, which has
56 the disadvantage of being slow compared to a direct call.
57
58 The default memory configuration for the CBM 610 allocates all memory between
59 &dollar;0002 and &dollar;FFF0 in bank 1 for the compiled program. Some space
60 in low memory is lost, because a separate hardware stack is set up in page 1,
61 and the kernal replacement functions need some more memory locations. A few
62 more bytes are lost in high memory, because the runtime sets up a CBM-compatible
63 jump table at &dollar;FF81. The main startup code is located at
64 &dollar;0400, so about 63K of the complete bank are actually usable for
65 applications.
66
67 Special locations:
68
69 <descrip>
70   <tag/Stack/
71   The C runtime stack is located at &dollar;FF81, and grows downwards.
72
73   <tag/Heap/
74   The C heap is located at the end of the program, and grows towards the C
75   runtime stack.
76 </descrip><p>
77
78
79
80 <sect>Platform-specific header files<p>
81
82 Programs containing CBM 610-specific code may use the <tt/cbm610.h/ or
83 <tt/cbm.h/ header files. Using the later may be an option when writing code
84 for more than one CBM platform, since it includes <tt/cbm610.h/, and declares
85 several functions common to all CBM platforms.
86
87
88 <sect1>CBM 610-specific functions<p>
89
90 The functions listed below are special for the CBM 610. See the <url
91 url="funcref.html" name="function reference"> for declaration and usage.
92
93 <itemize>
94 <item>peekbsys
95 <item>peekwsys
96 <item>pokebsys
97 <item>pokewsys
98 </itemize>
99
100
101 <sect1>CBM-specific functions<p>
102
103 Some functions are available for all (or at least most) of the Commodore
104 machines. See the <url url="funcref.html" name="function reference"> for
105 declaration and usage.
106
107
108 <itemize>
109 <item>cbm_close
110 <item>cbm_closedir
111 <item>cbm_k_setlfs
112 <item>cbm_k_setnam
113 <item>cbm_k_load
114 <item>cbm_k_save
115 <item>cbm_k_open
116 <item>cbm_k_close
117 <item>cbm_k_readst
118 <item>cbm_k_chkin
119 <item>cbm_k_ckout
120 <item>cbm_k_basin
121 <item>cbm_k_bsout
122 <item>cbm_k_clrch
123 <item>cbm_load
124 <item>cbm_open
125 <item>cbm_opendir
126 <item>cbm_read
127 <item>cbm_readdir
128 <item>cbm_save
129 <item>cbm_write
130 <item>get_tv
131 </itemize>
132
133
134 <sect1>Hardware access<p>
135
136 The following pseudo variables declared in the <tt/cbm610.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 <bf>Note:</bf> 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/CRTC/</tag>
149   The <tt/CRTC/ structure allows access to the CRTC (the video controller).
150   See the <tt/_6545.h/ header file located in the include directory for the
151   declaration of the structure.
152
153   <tag><tt/SID/</tag> The <tt/SID/ structure allows access to the SID (the
154   sound interface device). See the <tt/_sid.h/ header file located in the
155   include directory 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 610 (and since
184 the machine has no graphics capabilities, chances for a graphics driver aren't
185 really good :-).
186
187
188 <sect1>Extended memory drivers<p>
189
190 <descrip>
191   <tag><tt/cbm610-ram.emd (cbm610_ram_emd)/</tag>
192   A driver for the RAM in bank 2. Supports up to 255 pages with 256 bytes
193   each.
194 </descrip><p>
195
196
197 <sect1>Joystick drivers<p>
198
199 The Commodore 610 is a business machine, and doesn't have joystick ports. There
200 are no drivers for the non-existing ports available.
201
202
203 <sect1>Mouse drivers<p>
204
205 No mouse drivers are currently available for the Commodore 610.
206
207
208 <sect1>RS232 device drivers<p>
209
210 <descrip>
211
212   <tag><tt/cbm610-std.ser (cbm610_std_ser)/</tag>
213   Driver for the 6551 ACIA chip built into the Commodore 610. Supports up to
214   19200 BPS, hardware flow control (RTS/CTS), and interrupt-driven receives.
215   Note that, because of the peculiarities of the 6551 chip, transmits are not
216   interrupt driven; and, the transceiver blocks if the receiver asserts flow
217   control because of a full buffer.
218
219 </descrip><p>
220
221
222
223 <sect>Limitations<label id="limitations"><p>
224
225
226 <sect1>Kernal and hardware access<p>
227
228 Since the program runs in bank 1, and the kernal and all I/O chips are located
229 in bank 15, calling ROM routines or accessing hardware needs special code. The
230 cc65 runtime implements wrappers for all functions in the kernal jump table.
231 While this simplifies things, it should be noted that the wrappers do have
232 quite an impact on performance: A cross-bank call has an extra 300&micro;s
233 penalty added by the wrapper.
234
235
236 <sect1>Interrupts<p>
237
238 Compiled programs contain an interrupt handler that runs in the program bank.
239 This has several advantages, one of them being performance (see cross-bank
240 call overhead mentioned above). However, this introduces one problem:
241 Interrupts are lost while the CPU executes code in the kernal bank. As a
242 result, the clock may go wrong; and (worse), serial interrupts may get lost.
243
244 Since the cc65 runtime does only call the kernal for disk I/O, this means that
245 a program should not do file I/O while it depends on interrupts.
246
247
248
249 <sect>Other hints<p>
250
251
252 <sect1>Passing arguments to the program<p>
253
254 Command-line arguments can be passed to <tt/main()/. Since that is not
255 supported directly by BASIC, the following syntax was chosen:
256
257 <tscreen><verb>
258     RUN:REM ARG1 " ARG2 IS QUOTED" ARG3 "" ARG5
259 </verb></tscreen>
260
261 <enum>
262 <item>Arguments are separated by spaces.
263 <item>Arguments may be quoted.
264 <item>Leading and trailing spaces around an argument are ignored. Spaces within
265       a quoted argument are allowed.
266 <item>The first argument passed to <tt/main()/ is the program name.
267 <item>A maximum number of 10 arguments (including the program name) are
268       supported.
269 </enum>
270
271
272 <sect1>Program return code<p>
273
274 The program return code (low byte) is passed back to BASIC by use of the
275 <tt/ST/ variable.
276
277
278 <sect1>Interrupt handlers<p>
279
280 The runtime for the Commodore 610 uses routines marked as <tt/.INTERRUPTOR/
281 for interrupt handlers. Such routines must be written as simple machine
282 language subroutines and will be called automatically by the interrupt handler
283 code when they are linked into a program. See the discussion of the
284 <tt/.CONDES/ feature in the <url url="ca65.html" name="assembler manual">.
285
286
287
288 <sect>License<p>
289
290 This software is provided 'as-is', without any expressed or implied
291 warranty.  In no event will the authors be held liable for any damages
292 arising from the use of this software.
293
294 Permission is granted to anyone to use this software for any purpose,
295 including commercial applications, and to alter it and redistribute it
296 freely, subject to the following restrictions:
297
298 <enum>
299 <item>  The origin of this software must not be misrepresented; you must not
300         claim that you wrote the original software. If you use this software
301         in a product, an acknowledgment in the product documentation would be
302         appreciated but is not required.
303 <item>  Altered source versions must be plainly marked as such, and must not
304         be misrepresented as being the original software.
305 <item>  This notice may not be removed or altered from any source
306         distribution.
307 </enum>
308
309 </article>