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