1 /*****************************************************************************/
5 /* Atari system specific definitions */
9 /* (C) 2000-2019 Mark Keates <markk@dendrite.co.uk> */
10 /* Freddy Offenga <taf_offenga@yahoo.com> */
11 /* Christian Groessler <chris@groessler.org> */
12 /* Bill Kendrick <nbs@sonic.net> */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
40 /* Check for errors */
41 #if !defined(__ATARI__)
42 # error This module may only be used when compiling for the Atari!
46 /*****************************************************************************/
48 /*****************************************************************************/
50 #define CH_DELCHR 0xFE /* delete char under the cursor */
54 #define CH_CURS_DOWN 29
55 #define CH_CURS_LEFT 30
56 #define CH_CURS_RIGHT 31
58 #define CH_TAB 0x7F /* tabulator */
59 #define CH_EOL 0x9B /* end-of-line marker */
60 #define CH_CLR 0x7D /* clear screen */
61 #define CH_BEL 0xFD /* bell */
62 #define CH_DEL 0x7E /* back space (delete char to the left) */
63 #define CH_RUBOUT 0x7E /* back space (old, deprecated) */
64 #define CH_DELLINE 0x9C /* delete line */
65 #define CH_INSLINE 0x9D /* insert line */
67 /* These are defined to be Atari + NumberKey */
79 #define CH_ULCORNER 0x11
80 #define CH_URCORNER 0x05
81 #define CH_LLCORNER 0x1A
82 #define CH_LRCORNER 0x03
92 /*****************************************************************************/
93 /* Masks for joy_read */
94 /*****************************************************************************/
96 #define JOY_UP_MASK 0x01
97 #define JOY_DOWN_MASK 0x02
98 #define JOY_LEFT_MASK 0x04
99 #define JOY_RIGHT_MASK 0x08
100 #define JOY_BTN_1_MASK 0x10
102 #define JOY_FIRE_MASK JOY_BTN_1_MASK
103 #define JOY_FIRE(v) ((v) & JOY_FIRE_MASK)
106 /*****************************************************************************/
107 /* Keyboard values returned by kbcode / CH */
108 /*****************************************************************************/
110 #define KEY_NONE ((unsigned char) 0xFF)
112 #define KEY_0 ((unsigned char) 0x32)
113 #define KEY_1 ((unsigned char) 0x1F)
114 #define KEY_2 ((unsigned char) 0x1E)
115 #define KEY_3 ((unsigned char) 0x1A)
116 #define KEY_4 ((unsigned char) 0x18)
117 #define KEY_5 ((unsigned char) 0x1D)
118 #define KEY_6 ((unsigned char) 0x1B)
119 #define KEY_7 ((unsigned char) 0x33)
120 #define KEY_8 ((unsigned char) 0x35)
121 #define KEY_9 ((unsigned char) 0x30)
123 #define KEY_A ((unsigned char) 0x3F)
124 #define KEY_B ((unsigned char) 0x15)
125 #define KEY_C ((unsigned char) 0x12)
126 #define KEY_D ((unsigned char) 0x3A)
127 #define KEY_E ((unsigned char) 0x2A)
128 #define KEY_F ((unsigned char) 0x38)
129 #define KEY_G ((unsigned char) 0x3D)
130 #define KEY_H ((unsigned char) 0x39)
131 #define KEY_I ((unsigned char) 0x0D)
132 #define KEY_J ((unsigned char) 0x01)
133 #define KEY_K ((unsigned char) 0x05)
134 #define KEY_L ((unsigned char) 0x00)
135 #define KEY_M ((unsigned char) 0x25)
136 #define KEY_N ((unsigned char) 0x23)
137 #define KEY_O ((unsigned char) 0x08)
138 #define KEY_P ((unsigned char) 0x0A)
139 #define KEY_Q ((unsigned char) 0x2F)
140 #define KEY_R ((unsigned char) 0x28)
141 #define KEY_S ((unsigned char) 0x3E)
142 #define KEY_T ((unsigned char) 0x2D)
143 #define KEY_U ((unsigned char) 0x0B)
144 #define KEY_V ((unsigned char) 0x10)
145 #define KEY_W ((unsigned char) 0x2E)
146 #define KEY_X ((unsigned char) 0x16)
147 #define KEY_Y ((unsigned char) 0x2B)
148 #define KEY_Z ((unsigned char) 0x17)
150 #define KEY_COMMA ((unsigned char) 0x20)
151 #define KEY_PERIOD ((unsigned char) 0x22)
152 #define KEY_SLASH ((unsigned char) 0x26)
153 #define KEY_SEMICOLON ((unsigned char) 0x02)
154 #define KEY_PLUS ((unsigned char) 0x06)
155 #define KEY_ASTERISK ((unsigned char) 0x07)
156 #define KEY_DASH ((unsigned char) 0x0E)
157 #define KEY_EQUALS ((unsigned char) 0x0F)
158 #define KEY_LESSTHAN ((unsigned char) 0x36)
159 #define KEY_GREATERTHAN ((unsigned char) 0x37)
161 #define KEY_ESC ((unsigned char) 0x1C)
162 #define KEY_TAB ((unsigned char) 0x2C)
163 #define KEY_SPACE ((unsigned char) 0x21)
164 #define KEY_RETURN ((unsigned char) 0x0C)
165 #define KEY_DELETE ((unsigned char) 0x34)
166 #define KEY_CAPS ((unsigned char) 0x3C)
167 #define KEY_INVERSE ((unsigned char) 0x27)
168 #define KEY_HELP ((unsigned char) 0x11)
170 /* Function keys only exist on the 1200XL model. */
171 #define KEY_F1 ((unsigned char) 0x03)
172 #define KEY_F2 ((unsigned char) 0x04)
173 #define KEY_F3 ((unsigned char) 0x13)
174 #define KEY_F4 ((unsigned char) 0x14)
176 /* N.B. Cannot read Ctrl key alone */
177 #define KEY_CTRL ((unsigned char) 0x80)
179 /* N.B. Cannot read Shift key alone via KBCODE;
180 ** instead, check "Shfit key press" bit of SKSTAT register.
181 ** Also, no way to tell left Shift from right Shift.
183 #define KEY_SHIFT ((unsigned char) 0x40)
187 ** (Other combinations are possible, including Shift+Ctrl+key,
188 ** though not all such combinations are available.)
191 #define KEY_EXCLAMATIONMARK (KEY_1 | KEY_SHIFT)
192 #define KEY_QUOTE (KEY_2 | KEY_SHIFT)
193 #define KEY_HASH (KEY_3 | KEY_SHIFT)
194 #define KEY_DOLLAR (KEY_4 | KEY_SHIFT)
195 #define KEY_PERCENT (KEY_5 | KEY_SHIFT)
196 #define KEY_AMPERSAND (KEY_6 | KEY_SHIFT)
197 #define KEY_APOSTROPHE (KEY_7 | KEY_SHIFT)
198 #define KEY_AT (KEY_8 | KEY_SHIFT)
199 #define KEY_OPENINGPARAN (KEY_9 | KEY_SHIFT)
200 #define KEY_CLOSINGPARAN (KEY_0 | KEY_SHIFT)
201 #define KEY_UNDERLINE (KEY_DASH | KEY_SHIFT)
202 #define KEY_BAR (KEY_EQUALS | KEY_SHIFT)
203 #define KEY_COLON (KEY_SEMICOLON | KEY_SHIFT)
204 #define KEY_BACKSLASH (KEY_PLUS | KEY_SHIFT)
205 #define KEY_CIRCUMFLEX (KEY_ASTERISK | KEY_SHIFT)
206 #define KEY_OPENINGBRACKET (KEY_COMMA | KEY_SHIFT)
207 #define KEY_CLOSINGBRACKET (KEY_PERIOD | KEY_SHIFT)
208 #define KEY_QUESTIONMARK (KEY_SLASH | KEY_SHIFT)
209 #define KEY_CLEAR (KEY_LESSTHAN | KEY_SHIFT)
210 #define KEY_INSERT (KEY_GREATERTHAN | KEY_SHIFT)
212 #define KEY_UP (KEY_UNDERLINE | KEY_CTRL)
213 #define KEY_DOWN (KEY_EQUALS | KEY_CTRL)
214 #define KEY_LEFT (KEY_PLUS | KEY_CTRL)
215 #define KEY_RIGHT (KEY_ASTERISK | KEY_CTRL)
218 /*****************************************************************************/
219 /* Color register functions */
220 /*****************************************************************************/
222 extern void __fastcall__ _setcolor (unsigned char color_reg, unsigned char hue, unsigned char luminace);
223 extern void __fastcall__ _setcolor_low (unsigned char color_reg, unsigned char color_value);
224 extern unsigned char __fastcall__ _getcolor (unsigned char color_reg);
226 /*****************************************************************************/
227 /* Other screen functions */
228 /*****************************************************************************/
230 extern int __fastcall__ _graphics (unsigned char mode); /* mode value same as in BASIC */
231 extern void __fastcall__ _scroll (signed char numlines);
232 /* numlines > 0 scrolls up */
233 /* numlines < 0 scrolls down */
236 /*****************************************************************************/
237 /* Misc. functions */
238 /*****************************************************************************/
240 extern unsigned char get_ostype(void); /* get ROM version */
241 extern unsigned char get_tv(void); /* get TV system */
242 extern void _save_vecs(void); /* save system vectors */
243 extern void _rest_vecs(void); /* restore system vectors */
244 extern char *_getdefdev(void); /* get default floppy device */
245 extern unsigned char _is_cmdline_dos(void); /* does DOS support command lines */
248 /*****************************************************************************/
249 /* Global variables */
250 /*****************************************************************************/
252 extern unsigned char _dos_type; /* the DOS flavour */
254 extern void atr130_emd[];
255 extern void atrstd_joy[]; /* referred to by joy_static_stddrv[] */
256 extern void atrmj8_joy[];
257 extern void atrjoy_mou[];
258 extern void atrst_mou[]; /* referred to by mouse_static_stddrv[] */
259 extern void atrami_mou[];
260 extern void atrtrk_mou[];
261 extern void atrtt_mou[];
262 extern void atrrdev_ser[];
263 extern void atr3_tgi[];
264 extern void atr4_tgi[];
265 extern void atr5_tgi[];
266 extern void atr6_tgi[];
267 extern void atr7_tgi[];
268 extern void atr8_tgi[]; /* referred to by tgi_static_stddrv[] */
269 extern void atr8p2_tgi[];
270 extern void atr9_tgi[];
271 extern void atr9p2_tgi[];
272 extern void atr10_tgi[];
273 extern void atr10p2_tgi[];
274 extern void atr11_tgi[];
275 extern void atr14_tgi[];
276 extern void atr15_tgi[];
277 extern void atr15p2_tgi[];
279 extern void atrx130_emd[];
280 extern void atrxstd_joy[]; /* referred to by joy_static_stddrv[] */
281 extern void atrxmj8_joy[];
282 extern void atrxjoy_mou[];
283 extern void atrxst_mou[]; /* referred to by mouse_static_stddrv[] */
284 extern void atrxami_mou[];
285 extern void atrxtrk_mou[];
286 extern void atrxtt_mou[];
287 extern void atrxrdev_ser[];
288 extern void atrx3_tgi[];
289 extern void atrx4_tgi[];
290 extern void atrx5_tgi[];
291 extern void atrx6_tgi[];
292 extern void atrx7_tgi[];
293 extern void atrx8_tgi[]; /* referred to by tgi_static_stddrv[] */
294 extern void atrx8p2_tgi[];
295 extern void atrx9_tgi[];
296 extern void atrx9p2_tgi[];
297 extern void atrx10_tgi[];
298 extern void atrx10p2_tgi[];
299 extern void atrx11_tgi[];
300 extern void atrx14_tgi[];
301 extern void atrx15_tgi[];
302 extern void atrx15p2_tgi[];
306 /*****************************************************************************/
307 /* get_ostype return value defines (for explanation, see ostype.s) */
308 /*****************************************************************************/
311 #define AT_OS_TYPE_MAIN 7
312 #define AT_OS_TYPE_MINOR (7 << 3)
313 /* AT_OS_TYPE_MAIN values */
314 #define AT_OS_UNKNOWN 0
315 #define AT_OS_400800 1
316 #define AT_OS_1200XL 2
318 /* AS_OS_TYPE_MINOR values */
319 /* for 400/800 remember this are the ROM versions */
320 /* to check whether the hw is PAL or NTSC, use get_tv() */
321 #define AT_OS_400800PAL_A 1
322 #define AT_OS_400800PAL_B 2
323 #define AT_OS_400800NTSC_A 1
324 #define AT_OS_400800NTSC_B 2
325 #define AT_OS_1200_10 1
326 #define AT_OS_1200_11 2
327 #define AT_OS_XLXE_1 1
328 #define AT_OS_XLXE_2 2
329 #define AT_OS_XLXE_3 3
330 #define AT_OS_XLXE_4 4
333 /*****************************************************************************/
334 /* get_tv return values */
335 /*****************************************************************************/
341 /*****************************************************************************/
342 /* valid _dos_type values */
343 /*****************************************************************************/
355 /*****************************************************************************/
356 /* Define hardware and where they're mapped in memory */
357 /*****************************************************************************/
359 #include <_atarios.h>
360 #define OS (*(struct __os*)0x0000)
361 #define BASIC (*(struct __basic*)0x0080)
364 #define GTIA_READ (*(struct __gtia_read*)0xD000)
365 #define GTIA_WRITE (*(struct __gtia_write*)0xD000)
370 #define POKEY_READ (*(struct __pokey_read*)0xD200)
371 #define POKEY_WRITE (*(struct __pokey_write*)0xD200)
374 #define PIA (*(struct __pia*)0xD300)
377 #define ANTIC (*(struct __antic*)0xD400)
380 /*****************************************************************************/
381 /* PIA PORTA and PORTB register bits */
382 /*****************************************************************************/
384 /* See also: "JOY_xxx_MASK" in "atari.h" */
386 /* Paddle 0-3 triggers (per PORTA bits) */
387 #define PORTA_PTRIG3 0x80
388 #define PORTA_PTRIG2 0x40
389 #define PORTA_PTRIG1 0x08
390 #define PORTA_PTRIG0 0x04
393 /* On the Atari 400/800, PORTB is the same as PORTA, but for controller ports 3 & 4. */
395 /* Paddle 4-7 triggers (per PORTB bits); only 400/800 had four controller ports */
396 #define PORTB_PTRIG7 0x80
397 #define PORTB_PTRIG6 0x40
398 #define PORTB_PTRIG5 0x08
399 #define PORTB_PTRIG4 0x04
402 /* On the XL series of computers, PORTB has been changed to a memory and
403 ** LED control (1200XL model only) register (read/write):
406 /* If set, the built-in OS is enabled, and occupies the address range $C000-$FFFF
407 ** (except that the area $D000-$D7FF will only access the hardware registers.)
408 ** If clear, RAM is enabled in this area (again, save for the hole.)
410 #define PORTB_OSROM 0x01
412 /* If set, RAM is enabled for the address range $A000-$BFFF.
413 ** If clear, the built-in BASIC ROM is enabled at this address.
414 ** And if there is a cartridge installed in the computer, it makes no difference.
416 #define PORTB_BASICROM 0x02
418 /* If set, the corresponding LED is turned off. If clear, the LED will be on.
421 #define PORTB_LED1 0x04
422 #define PORTB_LED2 0x08
425 /* On the XE series of computers, PORTB is a bank-selected memory control register (read/write): */
427 /* These bits determine which memory bank is visible to the CPU and/or ANTIC chip
428 ** when their Bank Switch bit is set. There are four possible banks of 16KB each.
430 #define PORTB_BANKSELECT1 0x00
431 #define PORTB_BANKSELECT2 0x04
432 #define PORTB_BANKSELECT3 0x08
433 #define PORTB_BANKSELECT4 0x0C
435 /* If set, the CPU and/or ANTIC chip will access bank-switched memory mapped to the
436 ** address range $4000-$7FFF.
437 ** If clear, the CPU and/or ANTIC will see normal memory in this region.
439 #define PORTB_BANKSWITCH_CPU 0x10
440 #define PORTB_BANKSWITCH_ANTIC 0x20
442 /* If set, RAM is enabled for the address range $5000-$57FF.
443 ** If clear, the self-test ROM (physically located at $D000-$D7FF, under the hardware registers)
444 ** is remapped to this memory area.
446 #define PORTB_SELFTEST 0x80
449 /*****************************************************************************/
450 /* PACTL and PBCTL register bits */
451 /*****************************************************************************/
453 /* (W) Peripheral PA1/PB1 interrupt (IRQ) ("peripheral proceed line available") enable.
454 ** One equals enable. Set by the OS but available to the user; reset on powerup.
455 ** (PxCTL_IRQ_STATUS (R) bit will get set upon interrupt occurance)
457 #define PxCTL_IRQ_ENABLE 0x01 /* bit 0 */
459 /* Note: Bit 1 is always set to */
461 /* (W) Controls PORTA/PORTB addressing
462 ** 1 = PORTA/PORTB register; read/write to controller port
463 ** 0 = direction control register; write to direction controls
464 ** (allows setting data flow; write 0s & 1s to PORTA/PORTB bits
465 ** to set which port's pins are read (input), or write (output),
468 #define PxCTL_ADDRESSING 0x04 /* bit 2 */
470 /* (W) Peripheral motor control line; Turn the cassette on or off
471 ** (PACTL-specific register bit)
475 #define PACTL_MOTOR_CONTROL 0x08 /* bit 3 */
477 /* Peripheral command identification (serial bus command line)
478 ** (PBCTL-specific register bit)
480 #define PBCTL_PERIPH_CMD_IDENT 0x08 /* bit 3 */
482 /* Note: Bits 4 & 5 are always set to 1 */
484 /* Note: Bit 6 is always set to 0 */
486 /* (R) Peripheral interrupt (IRQ) status bit.
487 ** Set by Peripherals (PORTA / PORTB). Reset by reading from PORTA / PORTB.
488 ** PACTL's is interrupt status of PROCEED
489 ** PBCTL's is interrupt status of SIO
491 #define PxCTL_IRQ_STATUS 0x80