1 <!doctype linuxdoc system>
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">
11 An overview over the Atari Lynx runtime system as it is implemented for the
15 <!-- Table of contents -->
18 <!-- Begin the document -->
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.
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
33 <sect>Building your first Hello World application<p>
35 Here is a small traditional Hello World program for the Atari Lynx.
41 extern char lynxtgi[];
44 tgi_install(&lynxtgi);
50 tgi_setcolor(COLOR_GREEN);
51 tgi_outtextxy(0, 0, "Hello World");
58 The lynx.h contains all kind of system dependent things.
60 The tgi.h contains the graphics driver functions.
62 The 6502.h is needed for executing the CLI() command.
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.
67 The cc65 compiler suite has a graphics library called "Tiny Graphics
68 Interface". This interface has some relocatable code. In order to use this
69 in your own program you need to load it at run time.
71 Unfortunately the Lynx does not have a disk drive from where to load it.
72 Therefore you must already load it at compile time. The easiest way is to
73 link it in statically.
75 This relocatable driver is found in <tt>$(CC65_HOME)/tgi/lynx-160-102-16.tgi</tt>.
78 The name comes from 160 by 102 pixels (The Lynx LCD size), 16 colors.
80 In order to link in this statically we have to make it back to a source
81 file so that we can compile it. The next command will turn the compiled
82 driver object file into an assembler source and compile it with the ca65
86 co65 --code-label _lynxtgi lynx-160-102-16.tgi
87 ca65 -t lynx lynx-160-102-16.s
90 This will create a linkable object file called lynx-160-102-16.o
92 Then we need to compile our main file to a linkable object file.
99 Finally we have to link them together to produce an executable cart.
102 cl65 -t lynx -o game.lnx main.o lynx-160-102-16.o lynx.lib
105 This will create a bootable cart image called game.lnx
108 <sect>Binary format<p>
110 The standard binary output format generated by the linker for the Lynx target
111 is a cart image. By specifying the config file lynx-bll.cfg the linker will
112 generate BLL download compatible binary files.
114 It is of course possible to change this behaviour by using a modified startup
115 file and linker config.
117 The bootloader used in the cc65 lynx library uses a very minimal bootloader
118 that does not check the cart or show a title screen.
120 The advantage of this bootloader is that it allows creation of cart images to
125 Block size Rom size Description
126 512 bytes 128k Standard old games like Warbirds
127 1024 bytes 256k Most common format for homebrew. Also newer games like Lemmings
128 2048 bytes 512k Largest games like EOTB
131 <sect>Memory layout<p>
133 cc65 generated programs with the default setup run with the I/O area and the
134 kernal enabled, which gives a usable memory range of $200 - $C037.
138 0000 - 00FF Zero page
139 0100 - 01FF Machine stack
141 A058 - C037 Collision buffer
142 C038 - E017 Screen buffer 1
143 E018 - FFF7 Screen buffer 0
144 FFF8 - FFFF Hardware vectors
149 No conio support is currently available for the Lynx.
152 The Lynx "flabode" keys, Opt 1, Pause and Opt 2 are implemented using the
153 conio interface. The only characters the keyboard is able to produce are
154 'R' for Restart (Opt 1 + Pause), 'F' for flip (Opt 2 + Pause),
155 'P' for pause, '1' for Opt 1, '2' for Opt 2, '3' for Opt 1 + Opt 2 and
156 '?' for all keys down at the same time.
159 The C runtime stack is located at $C037 (or $A057 if collision
160 detection is enabled) and growing downwards.
163 The C heap is located at the end of the program and grows towards the C
167 The collision detection screen is at $A058 if it is enabled. The
168 double buffered screens are at $C038 and $E018.
174 <sect>Platform specific header files<p>
176 Programs containing Lynx specific code may use the <tt/lynx.h/ header file.
179 <sect1>Lynx specific functions<p>
182 <item>lynx_eeprom_erase
183 <item>lynx_eeprom_read
184 <item>lynx_eeprom_write
193 <sect1>Hardware access<p>
195 The following pseudo variables declared in the <tt/lynx.h/ header file do
196 allow access to hardware located in the address space. Some variables are
197 structures, accessing the struct fields will access the chip registers.
201 <tag><tt/MIKEY/</tag>
202 The <tt/MIKEY/ structure allows access to MIKEY chip. See the <tt/_mikey.h/
203 header file located in the include directory for the declaration of the
207 The <tt/SUZY/ structure allows access to SUZY chip. See the <tt/_suzy.h/
208 header file located in the include directory for the declaration of the
215 <sect>Loadable drivers<p>
217 <sect1>Graphics drivers<p>
219 A TGI driver for the standard graphics mode (160×102 in 16 colors) is
220 available, but must be statically linked, because no file I/O is available.
221 See the documentation for the <htmlurl url="co65.html" name="co65 utility">
222 for information on how to do that.
224 The TGI driver is implemented as an interrupt driven dual buffering device.
225 To use it as a single-buffer device set draw page and view page to the same
228 The TGI driver has a few Lynx-specific extensions.
230 Calling tgi_sprite(spr) or tgi_ioctl(0, spr) will display a standard Lynx
233 Calling tgi_flip() or tgi_ioctl(1, 0) will do a flip screen.
235 Calling tgi_setbgcolor(bgcolor) or tgi_ioctl(2, bgindex) will set the text
236 background color to the index defined by bgindex. If bgindex is 0 then the
237 background color is transparent.
239 To set the framerate of the display hardware call tgi_setframerate(rate) or
240 tgi_ioctl(3, rate). The supported framerates are 50, 60 and 75 frames per
241 second. Actually there is no real reason to use anything else than 75 frames
244 To check if the drawing engine is busy with the previous swap you can
245 call tgi_busy or tgi_ioctl(4, 0). It returns 0 if idle and 1 if busy
247 To update displays you can call tgi_updatedisplay() or tgi_ioctl(4, 1) it
248 will wait for the next VBL interrupt and set the draw buffer to the
249 view buffer. The draw buffer is also changed to (drawbuffer xor 1).
251 You can also enable or disable collision detection by a call to
252 tgi_setcollisiondetection(active) or tgi_ioctl(5, active). The collision
253 result is located before the sprite structure by default in this driver.
255 In order to reserve memory for the collision detection buffer you need to
256 specify lynx-coll.cfg as the configuration file to the linker.
258 <sect1>Extended memory drivers<p>
260 No extended memory drivers are currently available for the Lynx.
263 <sect1>Joystick drivers<p>
265 A joystick driver for the standard buttons is available, but must be
266 statically linked, because no file I/O is available. See the documentation for
267 the <htmlurl url="co65.html" name="co65 utility"> for information on how to do
270 <sect1>Mouse drivers<p>
272 No mouse drivers are currently available for the Lynx.
275 <sect1>RS232 device drivers<p>
279 The ComLynx port has Tx and Rx wired together. Every byte is sent
280 to all connected Lynxes. Only one Lynx can send at a time. There is no
281 protocol created for communication. You are on your own.
283 If the Lynx returns framing error then it is likely that another Lynx is
284 sending data at the same time.
286 The Lynx can also send a break and receive a break. The Lynx break is
287 recognized if the bit is down for 24 bit cycles or more.
289 To send a break you just set the break bit. The length of the break depends
290 on how long this bit is down.
292 The driver supports the baudrates:
310 The parity bit supports MARK and SPACE. It also supports EVEN and ODD parity
311 but the parity bit is included in the calculation. Most of us don't want it
312 this way. But there is nothing we can do about it.
314 The Lynx hardware will always check parity on incoming traffic. Currently
315 the driver cannot receive data from standard PC's due to this parity bug.
316 For working with Lynx to Lynx communication use EVEN parity.
318 To send data to standard PC's use MARK or SPACE as parity setting.
320 There is always only one stop bit. And the data length is always 8 bits.
322 We have no handshaking available. Even software handshake is impossible
323 as ComLynx has only one wire for the data.
325 Both transmit and receive are interrupt driven.
336 At this point in time there is no support for the cart filesystem yet. I have
337 a <tt/lynx-cart-demo/ example project that uses an interrupt driven display,
338 has support for the cart filesystem and an abcmusic sound module.
340 At some point in time we may find a way to rewrite these to fit the way the
341 cc65 drivers require. But for the time being you can create less portable
342 applications using these Lynx specific modules in <tt/lynx-cart-demo/.
345 <sect>Bugs/Feedback<p>
347 If you have problems using the library, if you find any bugs, or if you're
348 doing something interesting with it, I would be glad to hear from you. Feel
349 free to contact me by email (<htmlurl url="mailto:uz@cc65.org"
350 name="uz@cc65.org">).
356 This software is provided 'as-is', without any expressed or implied
357 warranty. In no event will the authors be held liable for any damages
358 arising from the use of this software.
360 Permission is granted to anyone to use this software for any purpose,
361 including commercial applications, and to alter it and redistribute it
362 freely, subject to the following restrictions:
365 <item> The origin of this software must not be misrepresented; you must not
366 claim that you wrote the original software. If you use this software
367 in a product, an acknowledgment in the product documentation would be
368 appreciated but is not required.
369 <item> Altered source versions must be plainly marked as such, and must not
370 be misrepresented as being the original software.
371 <item> This notice may not be removed or altered from any source