]> git.sur5r.net Git - cc65/blob - doc/lynx.sgml
Merge pull request #86 from AntiheroSoftware/ca65-65816
[cc65] / doc / lynx.sgml
1 <!doctype linuxdoc system>
2
3 <article>
4
5 <title>Atari Lynx specific information for cc65
6 <author>Karri Kaksonen, <htmlurl url="mailto:karri@sipo.fi" name="karri@sipo.fi">
7 Ullrich von Bassewitz, <htmlurl url="mailto:uz@cc65.org" name="uz@cc65.org">
8 <date>2011-04-01
9
10 <abstract>
11 An overview over the Atari Lynx 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 Atari Lynx runtime system as it comes
23 with the cc65 C compiler. It describes the memory layout, Lynx specific header
24 files, available drivers, and any pitfalls specific to that platform.
25
26 Please note that Lynx specific functions are just mentioned here, they are
27 described in detail in the separate <htmlurl 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
33 <sect>Building your first Hello World application<p>
34
35 Here is a small traditional Hello World program for the Atari Lynx.
36
37 <tscreen><verb>
38 #include <lynx.h>
39 #include <tgi.h>
40 #include <6502.h> 
41
42 void main(void) {
43   tgi_install(tgi_static_stddrv);
44   tgi_init();
45   CLI();
46   while (tgi_busy())
47     ;
48   tgi_clear();
49   tgi_setcolor(COLOR_GREEN);
50   tgi_outtextxy(0, 0, "Hello World");
51   tgi_updatedisplay();
52   while (1)
53     ;
54 }
55 </verb></tscreen>
56
57 The lynx.h contains all kind of system dependent things.
58
59 The tgi.h contains the graphics driver functions.
60
61 The 6502.h is needed for executing the CLI() command.
62
63 As the Atari Lynx does not have ASCII characters available you need to use
64 the Tiny Graphics Interface library for producing letters on the screen.
65
66 The cc65 compiler suite has a graphics library called "Tiny Graphics
67 Interface". This interface has some relocatable code. In order to use this
68 in your own program you need to load it at run time.
69
70 Unfortunately the Lynx does not have a disk drive from where to load it.
71 Therefore you must already load it at compile time. The easiest way is to
72 automatically link it in statically from the Lynx C library.
73
74 <tscreen><verb>
75 cl65 -t lynx -o game.lnx main.c
76 </verb></tscreen>
77
78 This will create a bootable cart image called game.lnx
79
80
81 <sect>Binary format<p>
82
83 The standard binary output format generated by the linker for the Lynx target
84 is a cart image. By specifying the config file lynx-bll.cfg the linker will
85 generate BLL download compatible binary files.
86
87 It is of course possible to change this behaviour by using a modified startup
88 file and linker config.
89
90 The bootloader used in the cc65 lynx library uses a very minimal bootloader
91 that does not check the cart or show a title screen.
92
93 The advantage of this bootloader is that it allows creation of cart images to
94 many common formats.
95
96 Cart sizes
97 <tscreen><verb>
98 Block size Rom size Description
99 512 bytes  128k     Standard old games like Warbirds
100 1024 bytes 256k     Most common format for homebrew. Also newer games like Lemmings
101 2048 bytes 512k     Largest games like EOTB
102 </verb></tscreen>
103
104 <sect>Memory layout<p>
105
106 cc65 generated programs with the default setup run with the I/O area and the
107 kernal enabled, which gives a usable memory range of &dollar;200 - &dollar;C037.
108
109 Special locations:
110 <tscreen><verb>
111   0000 - 00FF Zero page
112   0100 - 01FF Machine stack
113
114   A058 - C037 Collision buffer
115   C038 - E017 Screen buffer 1
116   E018 - FFF7 Screen buffer 0
117   FFF8 - FFFF Hardware vectors
118 </verb></tscreen>
119
120 <descrip>
121   <tag/Text screen/
122   No conio support is currently available for the Lynx.
123
124   <tag/Keyboard/
125   The Lynx "flabode" keys, Opt 1, Pause and Opt 2 are implemented using the
126   conio interface. The only characters the keyboard is able to produce are
127   'R' for Restart (Opt 1 + Pause), 'F' for flip (Opt 2 + Pause),
128   'P' for pause, '1' for Opt 1, '2' for Opt 2, '3' for Opt 1 + Opt 2 and
129   '?' for all keys down at the same time.
130
131   <tag/Stack/
132   The C runtime stack is located at &dollar;C037 (or &dollar;A057 if collision
133   detection is enabled) and growing downwards.
134
135   <tag/Heap/
136   The C heap is located at the end of the program and grows towards the C
137   runtime stack.
138
139   <tag/Screen/
140   The collision detection screen is at &dollar;A058 if it is enabled. The
141   double buffered screens are at &dollar;C038 and &dollar;E018.
142
143 </descrip><p>
144
145
146
147 <sect>Platform specific header files<p>
148
149 Programs containing Lynx specific code may use the <tt/lynx.h/ header file.
150
151
152 <sect1>Lynx specific functions<p>
153
154 <itemize>
155 <item>lynx_eeprom_erase
156 <item>lynx_eeprom_read
157 <item>lynx_eeprom_write
158 <item>lynx_eeread
159 <item>lynx_eewrite
160 <item>lynx_exec
161 <item>lynx_load
162 </itemize>
163
164
165
166 <sect1>Hardware access<p>
167
168 The following pseudo variables declared in the <tt/lynx.h/ header file do
169 allow access to hardware located in the address space. Some variables are
170 structures, accessing the struct fields will access the chip registers.
171
172 <descrip>
173
174   <tag><tt/MIKEY/</tag>
175   The <tt/MIKEY/ structure allows access to MIKEY chip. See the <tt/_mikey.h/
176   header file located in the include directory for the declaration of the
177   structure.
178
179   <tag><tt/SUZY/</tag>
180   The <tt/SUZY/ structure allows access to SUZY chip. See the <tt/_suzy.h/
181   header file located in the include directory for the declaration of the
182   structure.
183
184 </descrip><p>
185
186
187
188 <sect>Loadable drivers<p>
189
190 The names in the parentheses denote the symbols to be used for static linking of the drivers.
191
192
193 <sect1>Graphics drivers<p>
194
195 <descrip>
196
197   <tag><tt/lynx-160-102-16.tgi (lynx_160_102_16_tgi)/</tag>
198   A TGI driver for the standard graphics mode (160&times;102 in 16 colors).
199
200   The TGI driver is implemented as an interrupt driven dual buffering device.
201   To use it as a single-buffer device set draw page and view page to the same
202   value 0 or 1;
203
204   The TGI driver has a few Lynx-specific extensions.
205
206   Calling tgi_sprite(spr) or tgi_ioctl(0, spr) will display a standard Lynx
207   sprite on screen.
208
209   Calling tgi_flip() or tgi_ioctl(1, 0) will do a flip screen.
210
211   Calling tgi_setbgcolor(bgcolor) or tgi_ioctl(2, bgindex) will set the text
212   background color to the index defined by bgindex. If bgindex is 0 then the
213   background color is transparent.
214
215   To set the framerate of the display hardware call tgi_setframerate(rate) or
216   tgi_ioctl(3, rate). The supported framerates are 50, 60 and 75 frames per
217   second. Actually there is no real reason to use anything else than 75 frames
218   per second.
219
220   To check if the drawing engine is busy with the previous swap you can
221   call tgi_busy or tgi_ioctl(4, 0). It returns 0 if idle and 1 if busy
222
223   To update displays you can call tgi_updatedisplay() or tgi_ioctl(4, 1) it
224   will wait for the next VBL interrupt and set the draw buffer to the
225   view buffer. The draw buffer is also changed to (drawbuffer xor 1).
226
227   You can also enable or disable collision detection by a call to
228   tgi_setcollisiondetection(active) or tgi_ioctl(5, active). The collision
229   result is located before the sprite structure by default in this driver.
230
231   In order to reserve memory for the collision detection buffer you need to
232   specify lynx-coll.cfg as the configuration file to the linker.
233
234 </descrip><p>
235
236
237 <sect1>Extended memory drivers<p>
238
239 No extended memory drivers are currently available for the Lynx.
240
241
242 <sect1>Joystick drivers<p>
243
244 <descrip>
245
246   <tag><tt/lynx-stdjoy.joy (lynx_stdjoy_joy)/</tag>
247   A joystick driver for the standard buttons.
248
249 </descrip><p>
250
251
252 <sect1>Mouse drivers<p>
253
254 No mouse drivers are currently available for the Lynx.
255
256
257 <sect1>RS232 device drivers<p>
258
259 <descrip>
260
261   <tag><tt/lynx-comlynx.ser (lynx_comlynx_ser)/</tag>
262   A serial driver for the ComLynx port.
263
264   The ComLynx port has Tx and Rx wired together. Every byte is sent
265   to all connected Lynxes. Only one Lynx can send at a time. There is no
266   protocol created for communication. You are on your own.
267
268   If the Lynx returns framing error then it is likely that another Lynx is
269   sending data at the same time.
270
271   The Lynx can also send a break and receive a break. The Lynx break is
272   recognized if the bit is down for 24 bit cycles or more.
273
274   To send a break you just set the break bit. The length of the break depends
275   on how long this bit is down.
276
277   The driver supports the baudrates:
278   <itemize>
279   <item>62500
280   <item>31250
281   <item>9600
282   <item>7200
283   <item>4800
284   <item>3600
285   <item>2400
286   <item>1800
287   <item>1200
288   <item>600
289   <item>300
290   <item>150
291   <item>134.5
292   <item>110
293   <item>75
294   </itemize>
295   The parity bit supports MARK and SPACE. It also supports EVEN and ODD parity
296   but the parity bit is included in the calculation. Most of us don't want it
297   this way. But there is nothing we can do about it.
298
299   The Lynx hardware will always check parity on incoming traffic. Currently
300   the driver cannot receive data from standard PC's due to this parity bug.
301   For working with Lynx to Lynx communication use EVEN parity.
302
303   To send data to standard PC's use MARK or SPACE as parity setting.
304
305   There is always only one stop bit. And the data length is always 8 bits.
306
307   We have no handshaking available. Even software handshake is impossible
308   as ComLynx has only one wire for the data.
309
310   Both transmit and receive are interrupt driven.
311
312 </descrip><p>
313
314
315 <sect>Limitations<p>
316
317
318
319 <sect>Cart access<p>
320
321 At this point in time there is no support for the cart filesystem yet. I have
322 a <tt/lynx-cart-demo/ example project that uses an interrupt driven display,
323 has support for the cart filesystem and an abcmusic sound module.
324
325 At some point in time we may find a way to rewrite these to fit the way the
326 cc65 drivers require. But for the time being you can create less portable
327 applications using these Lynx specific modules in <tt/lynx-cart-demo/.
328
329
330 <sect>License<p>
331
332 This software is provided 'as-is', without any expressed or implied
333 warranty.  In no event will the authors be held liable for any damages
334 arising from the use of this software.
335
336 Permission is granted to anyone to use this software for any purpose,
337 including commercial applications, and to alter it and redistribute it
338 freely, subject to the following restrictions:
339
340 <enum>
341 <item>  The origin of this software must not be misrepresented; you must not
342         claim that you wrote the original software. If you use this software
343         in a product, an acknowledgment in the product documentation would be
344         appreciated but is not required.
345 <item>  Altered source versions must be plainly marked as such, and must not
346         be misrepresented as being the original software.
347 <item>  This notice may not be removed or altered from any source
348         distribution.
349 </enum>
350
351 </article>