Debian Codegraph @

DOC/PORTING

raw
1 How to port Atari800 to new platforms
2 =====================================
3
4 This is a guide for people who intend to create a new version of Atari800
5 for their computer or operating system (called "target system" throughout
6 this document).
7
8
9 Prerequisites
10 -------------
11
12 The target system must have a raw computing power at least comparable
13 to a Pentium 100, otherwise the emulator will run slower than the original
14 8-bit Atari. Other hardware requirements are usually easier to fulfill:
15 a few megs RAM, a few megs disk space, a display, some keys and an audio
16 output.
17
18 You should have a working compiler of the C programming language
19 for the target system. The compiler, however, can run on another system
20 (such as PC), which is called cross-compiling and is common when developing
21 for small devices.
22
23 You should understand at least the basics of programming in C.
24 The more you know, the better.
25
26
27 Getting started
28 ---------------
29
30 Try compiling an existing version of Atari800 for a system different
31 from your target system, just to learn how this works.
32 See the INSTALL file for instructions.
33
34 Try compiling something for your target system: a "Hello world" program
35 or (preferrably) a game. In case of problems, ask people who develop
36 for your target system. If you are not an expert of programming
37 the target system, get in touch with more experienced developers,
38 as you may need their advice sooner or later.
39
40
41 Compile-time configuration
42 --------------------------
43
44 Before you start feeding your C compiler with *.c files,
45 you need a file named "config.h". This file specifies the system
46 to compile for, the C library functions that are available and features
47 to include. There are two methods of creating this file: manually
48 and using the configure script.
49
50 Using the configure script is recommended, because it makes your port
51 easier to maintain for people who have never seen your target system.
52 Yet if you find it too hard to use the configure script, go on with
53 editing config.h by hand and consider using the configure script later.
54 The configure script is works well on Unix and GNU/Linux systems,
55 but can be awkward to use on Windows, especially if you use
56 an Integrated Development Environment and not command-line tools.
57
58 The configure script is the file named "configure" that should be run
59 by a Unix shell program such as "bash". The file is hardly human-readable.
60 It is generated from the source file "configure.ac" by a tool called
61 "autoconf". Another tool "autoheader" turns "configure.ac" into
62 "config.h.in", which is a template for "config.h" used by "configure".
63 "autogen.sh" is a shortcut that simply runs "autoheader" and "autoconf".
64
65 If you opt to edit "config.h" by hand, make a copy of "config.h.in"
66 under the name "config.h" and edit it changing some #undef's into #define's.
67 Consult the comments and other config.h files created this way, in "dc"
68 and "wince/port" directories.
69
70
71 Compiling for the first time
72 ----------------------------
73
74 Try starting with something simple. Disable sound emulation,
75 either by passing "--without-sound" to the configure script or by #undef'ing
76 sound items in "config.h".
77
78 The easiest way to start is to compile a "simple" version of the emulator,
79 that does not use any external libraries/interfaces for emulation of video,
80 audio and input, and uses only standard C library functions. With the
81 configure script you specify "--without-video --without-sound". If editing
82 "config.h", "#define BASIC 1" and figure out which files to compile.
83
84 The "simple" version does not support graphics or joysticks and has a very
85 limited keyboard input. Most likely it will appear as a blank screen when
86 run. That's fine. Edit the runtime configuration file providing paths to
87 Atari ROM images and change "DISABLE_BASIC" to "0". If you're lucky, you'll
88 see the "READY" prompt of Atari BASIC.
89
90
91 Implementing platform-specific part
92 -----------------------------------
93
94 Create a new source file with your platform-specific code.
95 You have several examples to copy-and-paste from.
96
97 The entry point to the program normally looks like this:
98
99 int main(int argc, char **argv)
100 {
101 /* initialise Atari800 core */
102 if (!Atari800_Initialise(&argc, argv))
103 return 3;
104
105 /* main loop */
106 for (;;) {
107 key_code = Atari_Keyboard();
108 Atari800_Frame();
109 if (display_screen)
110 Atari_DisplayScreen();
111 }
112 }
113
114 You need to implement functions specified in "platform.h".
115 These functions should display graphics on screen and read keyboard
116 and joysticks/mouse in a platform-specific way.
117
118
119 Graphics
120 --------
121
122 Atari_Initialise() is the function that does platform-specific initialization.
123 You may need to switch the graphics mode in this function.
124
125 Atari_DisplayScreen() should update the screen with the contents
126 of the atari_screen array. atari_screen is declared in screen.h as (ULONG *),
127 but it is really a pointer to a rectangular array of bytes. There are
128 240 (ATARI_HEIGHT) rows, 384 (ATARI_WIDTH) bytes each. While there are exactly
129 240 rows to display, only 336 middle columns of the 384 are meaningful.
130 Do never display more than 336 middle columns! Although the remaining columns
131 may appear black when you start the emulator, there's no such guarantee
132 when the emulator is running.
133
134 It is fine to display only 320 middle columns if that's easier for you than 336.
135 You can also crop the Atari graphics from the top and the bottom, because most
136 programs use just the 192 middle lines. If your display has considerably lower
137 resolution, you need to provide your own bitmap rescaling.
138
139 Bytes in atari_screen[] are Atari color codes (0-15 = shades of gray,
140 16-31 = shades of brown/yellow, etc). 8-bit Ataris have a fixed palette
141 of 256 colors. You can get 8-bit RGB components of Atari colors
142 with the macros Palette_GetR(code), Palette_GetG(code) and Palette_GetB(code),
143 defined in "colours.h".
144
145
146 Keyboard input
147 --------------
148
149 There are three variables that are read by the emulation core and should be
150 set by your platform-specific code:
151
152 int key_code;
153 int key_shift;
154 int key_consol;
155
156 key_code is the Atari scancode of the currently pressed keystroke, or one
157 of the emulator-defined special values, such as AKEY_NONE, AKEY_COLDSTART,
158 AKEY_BREAK, etc. Atari scancodes are 8-bit values with 6 low bits containing
159 the code of a regular key and two high bits reflecting the status of Shift
160 and Control modifiers. See input.h or some Atari documentation for details.
161 Codes that are special to the emulator are AKEY_NONE (which means no key
162 pressed, or just the Shift or the Control) and AKEY_* values defined
163 in "atari.h".
164
165 key_shift should be TRUE when any Shift key is pressed, FALSE otherwise.
166
167 In 8-bit Atari world the term "console keys" refers to the three function keys
168 (Start, Select and Option) commonly used in games. The keys are independent
169 of each other and of all other keys. The state of each console key should
170 be reflected by one bit in key_consol (cleared if the key is pressed).
171 See "input.h".
172
173
174 Joystick input
175 --------------
176
177 Four Atari joysticks are emulated, but few Atari games support more than two.
178
179 Each joystick has one fire button. Your Atari_TRIG() is passed the joystick
180 number (0-3) and should return 0 if the corresponding fire button is pressed
181 and 1 if it's not.
182
183 The joysticks are "digital", that is, they can be moved in one of 8 directions
184 from the center position. Joystick positions are passed in a bit obscure way.
185 Atari_PORT(0) should return the position of joysticks 0 and 1, Atari_PORT(1)
186 - the position of joysticks 2 and 3. The returned values are 8-bit,
187 four bits per joystick. The acceptable values of the four bits are defined
188 as STICK_* constants in "input.h".
189
190
191 Mouse input
192 -----------
193
194 Nearly all Atari programs are controlled by keyboard or joysticks.
195 Other controllers were much less popular. However, it is easy to support
196 them in your version of Atari800.
197
198 Paddles, touch tablet, light pen and other devices can be emulated
199 by a pointing device such as mouse. In the main emulation loop your code
200 should update the variables mouse_delta_x, mouse_delta_y and mouse_butons.
201 mouse_delta_x and mouse_delta_y are *relative* positions, that is,
202 how far the mouse was moved since last time. mouse_buttons is composed
203 of 3 bits that represent left, right and middle mouse button (1 = pressed).
204
205 To test mouse input, select "Light pen" as the emulated device
206 and press right mouse button to enable the mouse pointer maintained
207 by the emulator.
208
209
210 Final words
211 -----------
212
213 That's the end of this guide. I hope it's useful for developers new
214 to Atari800. Suggestions about what to add or improve are welcome.
215
216 If you are serious about porting Atari800, please join our mailing list.
217 See the documentation or the web page for details.
218
219
220 Happy hacking!
221
222 Piotr Fusik
223 November 5, 2006