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