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