]> git.sur5r.net Git - cc65/blob - doc/pet.sgml
Add CBM kernal call TKSA to CBM library
[cc65] / doc / pet.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4
5 <title>Commodore PET-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">
9 <date>2014-04-12
10
11 <abstract>
12 An overview over the PET runtime system as it is implemented for the cc65 C
13 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 PET runtime system as it comes with the
24 cc65 C compiler. It describes the memory layout, PET-specific header files,
25 available drivers, and any pitfalls specific to that platform.
26
27 Please note that PET-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
34 <sect>Binary format<p>
35
36 The standard binary output format generated by the linker for the PET target
37 is a machine language program with a one line BASIC stub, which calls the
38 machine language part via SYS. This means that a program can be loaded as
39 BASIC program and started with RUN. It is of course possible to change this
40 behaviour by using a modified startup file and linker config.
41
42
43 <sect>Memory layout<p>
44
45 cc65 generated programs with the default setup run with the I/O area and the
46 kernal and BASIC ROM enabled, which gives a usable memory range of
47 &dollar;0400 - &dollar;7FFF (32KB machine).
48 All ROM entry points may be called directly without additional code.
49
50 Special locations:
51
52 <descrip>
53   <tag/Text screen/
54   The text screen is located at &dollar;8000.
55
56   <tag/Stack/
57   The C runtime stack is located at &dollar;7FFF and growing downwards.
58
59   <tag/Heap/
60   The C heap is located at the end of the program and grows towards the C
61   runtime stack.
62
63 </descrip><p>
64
65
66
67 <sect>Platform-specific header files<p>
68
69 Programs containing PET-specific code may use the <tt/pet.h/ or <tt/cbm.h/
70 header files. Using the later may be an option when writing code for more than
71 one CBM platform, since it includes <tt/pet.h/ and declares several functions
72 common to all CBM platforms.
73
74
75 <sect1>PET-specific functions<p>
76
77 There are currently no special PET functions.
78
79
80
81 <sect1>CBM-specific functions<p>
82
83 Some functions are available for all (or at least most) of the Commodore
84 machines. See the <url url="funcref.html" name="function reference"> for
85 declaration and usage.
86
87 <itemize>
88 <item>cbm_close
89 <item>cbm_closedir
90 <item>cbm_k_setlfs
91 <item>cbm_k_setnam
92 <item>cbm_k_load
93 <item>cbm_k_save
94 <item>cbm_k_open
95 <item>cbm_k_close
96 <item>cbm_k_readst
97 <item>cbm_k_chkin
98 <item>cbm_k_ckout
99 <item>cbm_k_basin
100 <item>cbm_k_bsout
101 <item>cbm_k_clrch
102 <item>cbm_k_tksa
103 <item>cbm_load
104 <item>cbm_open
105 <item>cbm_opendir
106 <item>cbm_read
107 <item>cbm_readdir
108 <item>cbm_save
109 <item>cbm_write
110 <item>get_tv
111 </itemize>
112
113
114 <sect1>Hardware access<p>
115
116 The following pseudo variables declared in the <tt/pet.h/ header file do allow
117 access to hardware located in the address space. Some variables are
118 structures, accessing the struct fields will access the chip registers.
119
120 <descrip>
121
122   <tag><tt/PIA1, PIA2/</tag>
123   Access to the two PIA (peripheral interface adapter) chips is available via
124   the <tt/PIA1/ and <tt/PIA2/ variables. The structure behind these variables
125   is explained in <tt/_pia.h/.
126
127   <tag><tt/VIA/</tag>
128   The <tt/VIA/ structure allows access to the VIA (versatile interface
129   adapter). See the <tt/_6522.h/ header file located in the include
130   directory for the declaration of the structure.
131
132 </descrip><p>
133
134
135
136 <sect>Loadable drivers<p>
137
138 The names in the parentheses denote the symbols to be used for static linking of the drivers.
139
140
141 <sect1>Graphics drivers<p>
142
143 No graphics drivers are currently available for the PET.
144
145
146 <sect1>Extended memory drivers<p>
147
148 No extended memory drivers are currently available for the PET.
149
150
151 <sect1>Joystick drivers<p>
152
153 The default drivers, <tt/joy_stddrv (joy_static_stddrv)/, point to <tt/pet-stdjoy.joy (pet_stdjoy_joy)/.
154
155 <descrip>
156
157   <tag><tt/pet-ptvjoy.joy (pet_ptvjoy_joy)/</tag>
158   Driver for the Protovision 4-player adapter contributed by Groepaz. See
159   <url url="http://www.protovision-online.de/hardw/4_player.php?language=en"
160   name="Protovision shop"> for prices and building instructions. Up to two
161   joysticks are supported.
162
163   <tag><tt/pet-stdjoy.joy (pet_stdjoy_joy)/</tag>
164   Driver for the standard PET userport joystick.
165
166 </descrip><p>
167
168
169 <sect1>Mouse drivers<p>
170
171 No mouse drivers are currently available for the PET.
172
173
174 <sect1>RS232 device drivers<p>
175
176 No serial drivers are currently available for the PET.
177
178
179
180 <sect>Limitations<p>
181
182
183
184 <sect>Other hints<p>
185
186
187 <sect1>Passing arguments to the program<p>
188
189 Command-line arguments can be passed to <tt/main()/. Since that is not
190 supported directly by BASIC, the following syntax was chosen:
191
192 <tscreen><verb>
193     RUN:REM ARG1 " ARG2 IS QUOTED" ARG3 "" ARG5
194 </verb></tscreen>
195
196 <enum>
197 <item>Arguments are separated by spaces.
198 <item>Arguments may be quoted.
199 <item>Leading and trailing spaces around an argument are ignored. Spaces within
200       a quoted argument are allowed.
201 <item>The first argument passed to <tt/main()/ is the program name.
202 <item>A maximum number of 10 arguments (including the program name) are
203       supported.
204 </enum>
205
206
207 <sect1>Program return code<p>
208
209 The program return code (low byte) is passed back to BASIC by use of the
210 <tt/ST/ variable.
211
212
213 <sect1>Interrupts<p>
214
215 The runtime for the PET uses routines marked as <tt/.INTERRUPTOR/ for
216 interrupt handlers. Such routines must be written as simple machine language
217 subroutines and will be called automatically by the interrupt handler code
218 when they are linked into a program. See the discussion of the <tt/.CONDES/
219 feature in the <url url="ca65.html" name="assembler manual">.
220
221
222 <sect1>Using extended memory<p>
223
224 The extended memory at $9000 of the CBM 8x96 may be added to the heap by using
225 the following code:
226
227 <tscreen><verb>
228     /* Check for the existence of RAM */
229     if (PEEK(0x9000) == POKE(0x9000, PEEK(0x9000)+1)) {
230         /* Add it to the heap */
231         _heapadd ((void *) 0x9000, 0x2000);
232     }
233 </verb></tscreen>
234
235
236
237 <sect>License<p>
238
239 This software is provided 'as-is', without any expressed or implied
240 warranty.  In no event will the authors be held liable for any damages
241 arising from the use of this software.
242
243 Permission is granted to anyone to use this software for any purpose,
244 including commercial applications, and to alter it and redistribute it
245 freely, subject to the following restrictions:
246
247 <enum>
248 <item>  The origin of this software must not be misrepresented; you must not
249         claim that you wrote the original software. If you use this software
250         in a product, an acknowledgment in the product documentation would be
251         appreciated but is not required.
252 <item>  Altered source versions must be plainly marked as such, and must not
253         be misrepresented as being the original software.
254 <item>  This notice may not be removed or altered from any source
255         distribution.
256 </enum>
257
258 </article>