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