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