llvm-mos-sdk
atari.h
Go to the documentation of this file.
1 // Copyright 2022 LLVM-MOS Project
2 // Licensed under the Apache License, Version 2.0 with LLVM Exceptions.
3 // See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
4 // information.
5 
6 // Originally from cc65. Modified from original version.
7 
8 // clang-format off
9 
10 /*****************************************************************************/
11 /* */
12 /* atari.h */
13 /* */
14 /* Atari system specific definitions */
15 /* */
16 /* */
17 /* */
18 /* (C) 2000-2021 Mark Keates <markk@dendrite.co.uk> */
19 /* Freddy Offenga <taf_offenga@yahoo.com> */
20 /* Christian Groessler <chris@groessler.org> */
21 /* Bill Kendrick <nbs@sonic.net> */
22 /* et al. */
23 /* */
24 /* */
25 /* This software is provided 'as-is', without any expressed or implied */
26 /* warranty. In no event will the authors be held liable for any damages */
27 /* arising from the use of this software. */
28 /* */
29 /* Permission is granted to anyone to use this software for any purpose, */
30 /* including commercial applications, and to alter it and redistribute it */
31 /* freely, subject to the following restrictions: */
32 /* */
33 /* 1. The origin of this software must not be misrepresented; you must not */
34 /* claim that you wrote the original software. If you use this software */
35 /* in a product, an acknowledgment in the product documentation would be */
36 /* appreciated but is not required. */
37 /* 2. Altered source versions must be plainly marked as such, and must not */
38 /* be misrepresented as being the original software. */
39 /* 3. This notice may not be removed or altered from any source */
40 /* distribution. */
41 /* */
42 /*****************************************************************************/
43 
44 #ifndef _ATARI_H
45 #define _ATARI_H
46 
47 
48 /*****************************************************************************/
49 /* Character codes */
50 /*****************************************************************************/
51 
52 #define CH_DELCHR 0xFE /* delete char under the cursor */
53 #define CH_ENTER 0x9B
54 #define CH_ESC 0x1B
55 #define CH_CURS_UP 28
56 #define CH_CURS_DOWN 29
57 #define CH_CURS_LEFT 30
58 #define CH_CURS_RIGHT 31
59 
60 #define CH_TAB 0x7F /* tabulator */
61 #define CH_EOL 0x9B /* end-of-line marker */
62 #define CH_CLR 0x7D /* clear screen */
63 #define CH_BEL 0xFD /* bell */
64 #define CH_DEL 0x7E /* back space (delete char to the left) */
65 #define CH_RUBOUT 0x7E /* back space (old, deprecated) */
66 #define CH_DELLINE 0x9C /* delete line */
67 #define CH_INSLINE 0x9D /* insert line */
68 
69 /* These are defined to be Atari + NumberKey */
70 #define CH_F1 177
71 #define CH_F2 178
72 #define CH_F3 179
73 #define CH_F4 180
74 #define CH_F5 181
75 #define CH_F6 182
76 #define CH_F7 183
77 #define CH_F8 184
78 #define CH_F9 185
79 #define CH_F10 176
80 
81 #define CH_ULCORNER 0x11
82 #define CH_URCORNER 0x05
83 #define CH_LLCORNER 0x1A
84 #define CH_LRCORNER 0x03
85 #define CH_TTEE 0x17
86 #define CH_BTEE 0x18
87 #define CH_LTEE 0x01
88 #define CH_RTEE 0x04
89 #define CH_CROSS 0x13
90 #define CH_HLINE 0x12
91 #define CH_VLINE 0x7C
92 
93 
94 /*****************************************************************************/
95 /* Masks for joy_read */
96 /*****************************************************************************/
97 
98 #define JOY_UP_MASK 0x01
99 #define JOY_DOWN_MASK 0x02
100 #define JOY_LEFT_MASK 0x04
101 #define JOY_RIGHT_MASK 0x08
102 #define JOY_BTN_1_MASK 0x10
103 
104 #define JOY_FIRE_MASK JOY_BTN_1_MASK
105 #define JOY_FIRE(v) ((v) & JOY_FIRE_MASK)
106 
107 
108 /*****************************************************************************/
109 /* Keyboard values returned by kbcode / CH */
110 /*****************************************************************************/
111 
112 #define KEY_NONE ((unsigned char) 0xFF)
113 
114 #define KEY_0 ((unsigned char) 0x32)
115 #define KEY_1 ((unsigned char) 0x1F)
116 #define KEY_2 ((unsigned char) 0x1E)
117 #define KEY_3 ((unsigned char) 0x1A)
118 #define KEY_4 ((unsigned char) 0x18)
119 #define KEY_5 ((unsigned char) 0x1D)
120 #define KEY_6 ((unsigned char) 0x1B)
121 #define KEY_7 ((unsigned char) 0x33)
122 #define KEY_8 ((unsigned char) 0x35)
123 #define KEY_9 ((unsigned char) 0x30)
124 
125 #define KEY_A ((unsigned char) 0x3F)
126 #define KEY_B ((unsigned char) 0x15)
127 #define KEY_C ((unsigned char) 0x12)
128 #define KEY_D ((unsigned char) 0x3A)
129 #define KEY_E ((unsigned char) 0x2A)
130 #define KEY_F ((unsigned char) 0x38)
131 #define KEY_G ((unsigned char) 0x3D)
132 #define KEY_H ((unsigned char) 0x39)
133 #define KEY_I ((unsigned char) 0x0D)
134 #define KEY_J ((unsigned char) 0x01)
135 #define KEY_K ((unsigned char) 0x05)
136 #define KEY_L ((unsigned char) 0x00)
137 #define KEY_M ((unsigned char) 0x25)
138 #define KEY_N ((unsigned char) 0x23)
139 #define KEY_O ((unsigned char) 0x08)
140 #define KEY_P ((unsigned char) 0x0A)
141 #define KEY_Q ((unsigned char) 0x2F)
142 #define KEY_R ((unsigned char) 0x28)
143 #define KEY_S ((unsigned char) 0x3E)
144 #define KEY_T ((unsigned char) 0x2D)
145 #define KEY_U ((unsigned char) 0x0B)
146 #define KEY_V ((unsigned char) 0x10)
147 #define KEY_W ((unsigned char) 0x2E)
148 #define KEY_X ((unsigned char) 0x16)
149 #define KEY_Y ((unsigned char) 0x2B)
150 #define KEY_Z ((unsigned char) 0x17)
151 
152 #define KEY_COMMA ((unsigned char) 0x20)
153 #define KEY_PERIOD ((unsigned char) 0x22)
154 #define KEY_SLASH ((unsigned char) 0x26)
155 #define KEY_SEMICOLON ((unsigned char) 0x02)
156 #define KEY_PLUS ((unsigned char) 0x06)
157 #define KEY_ASTERISK ((unsigned char) 0x07)
158 #define KEY_DASH ((unsigned char) 0x0E)
159 #define KEY_EQUALS ((unsigned char) 0x0F)
160 #define KEY_LESSTHAN ((unsigned char) 0x36)
161 #define KEY_GREATERTHAN ((unsigned char) 0x37)
162 
163 #define KEY_ESC ((unsigned char) 0x1C)
164 #define KEY_TAB ((unsigned char) 0x2C)
165 #define KEY_SPACE ((unsigned char) 0x21)
166 #define KEY_RETURN ((unsigned char) 0x0C)
167 #define KEY_DELETE ((unsigned char) 0x34)
168 #define KEY_CAPS ((unsigned char) 0x3C)
169 #define KEY_INVERSE ((unsigned char) 0x27)
170 #define KEY_HELP ((unsigned char) 0x11)
171 
172 /* Function keys only exist on the 1200XL model. */
173 #define KEY_F1 ((unsigned char) 0x03)
174 #define KEY_F2 ((unsigned char) 0x04)
175 #define KEY_F3 ((unsigned char) 0x13)
176 #define KEY_F4 ((unsigned char) 0x14)
177 
178 /* N.B. Cannot read Ctrl key alone */
179 #define KEY_CTRL ((unsigned char) 0x80)
180 
181 /* N.B. Cannot read Shift key alone via KBCODE;
182 ** instead, check "Shfit key press" bit of SKSTAT register.
183 ** Also, no way to tell left Shift from right Shift.
184 */
185 #define KEY_SHIFT ((unsigned char) 0x40)
186 
187 
188 /* Composed keys
189 ** (Other combinations are possible, including Shift+Ctrl+key,
190 ** though not all such combinations are available.)
191 */
192 
193 #define KEY_EXCLAMATIONMARK (KEY_1 | KEY_SHIFT)
194 #define KEY_QUOTE (KEY_2 | KEY_SHIFT)
195 #define KEY_HASH (KEY_3 | KEY_SHIFT)
196 #define KEY_DOLLAR (KEY_4 | KEY_SHIFT)
197 #define KEY_PERCENT (KEY_5 | KEY_SHIFT)
198 #define KEY_AMPERSAND (KEY_6 | KEY_SHIFT)
199 #define KEY_APOSTROPHE (KEY_7 | KEY_SHIFT)
200 #define KEY_AT (KEY_8 | KEY_SHIFT)
201 #define KEY_OPENINGPARAN (KEY_9 | KEY_SHIFT)
202 #define KEY_CLOSINGPARAN (KEY_0 | KEY_SHIFT)
203 #define KEY_UNDERLINE (KEY_DASH | KEY_SHIFT)
204 #define KEY_BAR (KEY_EQUALS | KEY_SHIFT)
205 #define KEY_COLON (KEY_SEMICOLON | KEY_SHIFT)
206 #define KEY_BACKSLASH (KEY_PLUS | KEY_SHIFT)
207 #define KEY_CIRCUMFLEX (KEY_ASTERISK | KEY_SHIFT)
208 #define KEY_OPENINGBRACKET (KEY_COMMA | KEY_SHIFT)
209 #define KEY_CLOSINGBRACKET (KEY_PERIOD | KEY_SHIFT)
210 #define KEY_QUESTIONMARK (KEY_SLASH | KEY_SHIFT)
211 #define KEY_CLEAR (KEY_LESSTHAN | KEY_SHIFT)
212 #define KEY_INSERT (KEY_GREATERTHAN | KEY_SHIFT)
213 
214 #define KEY_UP (KEY_DASH | KEY_CTRL)
215 #define KEY_DOWN (KEY_EQUALS | KEY_CTRL)
216 #define KEY_LEFT (KEY_PLUS | KEY_CTRL)
217 #define KEY_RIGHT (KEY_ASTERISK | KEY_CTRL)
218 
219 
220 /*****************************************************************************/
221 /* Color register functions */
222 /*****************************************************************************/
223 
224 // TODO
225 #if 0
226 extern void __fastcall__ _setcolor (unsigned char color_reg, unsigned char hue, unsigned char luminance);
227 extern void __fastcall__ _setcolor_low (unsigned char color_reg, unsigned char color_value);
228 extern unsigned char __fastcall__ _getcolor (unsigned char color_reg);
229 #endif
230 
231 /*****************************************************************************/
232 /* Other screen functions */
233 /*****************************************************************************/
234 
235 // TODO
236 #if 0
237 extern void waitvsync (void); /* wait for start of next frame */
238 extern int __fastcall__ _graphics (unsigned char mode); /* mode value same as in BASIC */
239 extern void __fastcall__ _scroll (signed char numlines);
240  /* numlines > 0 scrolls up */
241  /* numlines < 0 scrolls down */
242 #endif
243 
244 /*****************************************************************************/
245 /* Misc. functions */
246 /*****************************************************************************/
247 
248 // TODO
249 #if 0
250 extern unsigned char get_ostype(void); /* get ROM version */
251 extern unsigned char get_tv(void); /* get TV system */
252 extern void _save_vecs(void); /* save system vectors */
253 extern void _rest_vecs(void); /* restore system vectors */
254 extern char *_getdefdev(void); /* get default floppy device */
255 extern unsigned char _is_cmdline_dos(void); /* does DOS support command lines */
256 
257 /*****************************************************************************/
258 /* get_ostype return value defines (for explanation, see ostype.s) */
259 /*****************************************************************************/
260 
261 /* masks */
262 #define AT_OS_TYPE_MAIN 7
263 #define AT_OS_TYPE_MINOR (7 << 3)
264 /* AT_OS_TYPE_MAIN values */
265 #define AT_OS_UNKNOWN 0
266 #define AT_OS_400800 1
267 #define AT_OS_1200XL 2
268 #define AT_OS_XLXE 3
269 /* AS_OS_TYPE_MINOR values */
270 /* for 400/800 remember this are the ROM versions */
271 /* to check whether the hw is PAL or NTSC, use get_tv() */
272 #define AT_OS_400800PAL_A 1
273 #define AT_OS_400800PAL_B 2
274 #define AT_OS_400800NTSC_A 1
275 #define AT_OS_400800NTSC_B 2
276 #define AT_OS_1200_10 1
277 #define AT_OS_1200_11 2
278 #define AT_OS_XLXE_1 1
279 #define AT_OS_XLXE_2 2
280 #define AT_OS_XLXE_3 3
281 #define AT_OS_XLXE_4 4
282 
283 
284 /*****************************************************************************/
285 /* get_tv return values */
286 /*****************************************************************************/
287 
288 #define AT_NTSC 0
289 #define AT_PAL 1
290 
291 
292 /*****************************************************************************/
293 /* valid _dos_type values */
294 /*****************************************************************************/
295 
296 #define SPARTADOS 0
297 #define REALDOS 1
298 #define BWDOS 2
299 #define OSADOS 3
300 #define XDOS 4
301 #define ATARIDOS 5
302 #define MYDOS 6
303 #define NODOS 255
304 #endif
305 
306 /*****************************************************************************/
307 /* Define hardware and where they're mapped in memory */
308 /*****************************************************************************/
309 
310 #include <_atarios.h>
311 #define OS (*(volatile struct __os*)0x0000)
312 #define BASIC (*(volatile struct __basic*)0x0080)
313 
314 #include <_gtia.h>
315 #define GTIA_READ (*(volatile struct __gtia_read*)0xD000)
316 #define GTIA_WRITE (*(volatile struct __gtia_write*)0xD000)
317 
318 #include <_pbi.h>
319 
320 #include <_pokey.h>
321 #define POKEY_READ (*(volatile struct __pokey_read*)0xD200)
322 #define POKEY_WRITE (*(volatile struct __pokey_write*)0xD200)
323 
324 #include <_pia.h>
325 #define PIA (*(volatile struct __pia*)0xD300)
326 
327 #include <_antic.h>
328 #define ANTIC (*(volatile struct __antic*)0xD400)
329 
330 
331 /*****************************************************************************/
332 /* conio color defines */
333 /*****************************************************************************/
334 
335 /* Note that the conio color implementation is monochrome
336 ** (textcolor just sets text brightness low or high, depending on background
337 ** color)
338 ** These values can be used with bordercolor(), bgcolor(), and _setcolor_low()
339 */
340 #define COLOR_BLACK GTIA_COLOR_BLACK
341 #define COLOR_WHITE GTIA_COLOR_WHITE
342 #define COLOR_RED GTIA_COLOR_RED
343 #define COLOR_CYAN GTIA_COLOR_CYAN
344 #define COLOR_PURPLE GTIA_COLOR_VIOLET
345 #define COLOR_GREEN GTIA_COLOR_GREEN
346 #define COLOR_BLUE GTIA_COLOR_BLUE
347 #define COLOR_YELLOW GTIA_COLOR_YELLOW
348 #define COLOR_ORANGE GTIA_COLOR_ORANGE
349 #define COLOR_BROWN GTIA_COLOR_BROWN
350 #define COLOR_LIGHTRED GTIA_COLOR_LIGHTRED
351 #define COLOR_GRAY1 GTIA_COLOR_GRAY1
352 #define COLOR_GRAY2 GTIA_COLOR_GRAY2
353 #define COLOR_LIGHTGREEN GTIA_COLOR_LIGHTGREEN
354 #define COLOR_LIGHTBLUE GTIA_COLOR_LIGHTBLUE
355 #define COLOR_GRAY3 GTIA_COLOR_GRAY3
356 
357 
358 /*****************************************************************************/
359 /* PIA PORTA and PORTB register bits */
360 /*****************************************************************************/
361 
362 /* See also: "JOY_xxx_MASK" in "atari.h" */
363 
364 /* Paddle 0-3 triggers (per PORTA bits) */
365 #define PORTA_PTRIG3 0x80
366 #define PORTA_PTRIG2 0x40
367 #define PORTA_PTRIG1 0x08
368 #define PORTA_PTRIG0 0x04
369 
370 
371 /* On the Atari 400/800, PORTB is the same as PORTA, but for controller ports 3 & 4. */
372 
373 /* Paddle 4-7 triggers (per PORTB bits); only 400/800 had four controller ports */
374 #define PORTB_PTRIG7 0x80
375 #define PORTB_PTRIG6 0x40
376 #define PORTB_PTRIG5 0x08
377 #define PORTB_PTRIG4 0x04
378 
379 
380 /* On the XL series of computers, PORTB has been changed to a memory and
381 ** LED control (1200XL model only) register (read/write):
382 */
383 
384 /* If set, the built-in OS is enabled, and occupies the address range $C000-$FFFF
385 ** (except that the area $D000-$D7FF will only access the hardware registers.)
386 ** If clear, RAM is enabled in this area (again, save for the hole.)
387 */
388 #define PORTB_OSROM 0x01
389 
390 /* If set, RAM is enabled for the address range $A000-$BFFF.
391 ** If clear, the built-in BASIC ROM is enabled at this address.
392 ** And if there is a cartridge installed in the computer, it makes no difference.
393 */
394 #define PORTB_BASICROM 0x02
395 
396 /* If set, the corresponding LED is turned off. If clear, the LED will be on.
397 ** (1200XL only)
398 */
399 #define PORTB_LED1 0x04
400 #define PORTB_LED2 0x08
401 
402 
403 /* On the XE series of computers, PORTB is a bank-selected memory control register (read/write): */
404 
405 /* These bits determine which memory bank is visible to the CPU and/or ANTIC chip
406 ** when their Bank Switch bit is set. There are four possible banks of 16KB each.
407 */
408 #define PORTB_BANKSELECT1 0x00
409 #define PORTB_BANKSELECT2 0x04
410 #define PORTB_BANKSELECT3 0x08
411 #define PORTB_BANKSELECT4 0x0C
412 
413 /* If set, the CPU and/or ANTIC chip will access bank-switched memory mapped to the
414 ** address range $4000-$7FFF.
415 ** If clear, the CPU and/or ANTIC will see normal memory in this region.
416 */
417 #define PORTB_BANKSWITCH_CPU 0x10
418 #define PORTB_BANKSWITCH_ANTIC 0x20
419 
420 /* If set, RAM is enabled for the address range $5000-$57FF.
421 ** If clear, the self-test ROM (physically located at $D000-$D7FF, under the hardware registers)
422 ** is remapped to this memory area.
423 */
424 #define PORTB_SELFTEST 0x80
425 
426 
427 /*****************************************************************************/
428 /* PACTL and PBCTL register bits */
429 /*****************************************************************************/
430 
431 /* (W) Peripheral PA1/PB1 interrupt (IRQ) ("peripheral proceed line available") enable.
432 ** One equals enable. Set by the OS but available to the user; reset on powerup.
433 ** (PxCTL_IRQ_STATUS (R) bit will get set upon interrupt occurance)
434 */
435 #define PxCTL_IRQ_ENABLE 0x01 /* bit 0 */
436 
437 /* Note: Bit 1 is always set to */
438 
439 /* (W) Controls PORTA/PORTB addressing
440 ** 1 = PORTA/PORTB register; read/write to controller port
441 ** 0 = direction control register; write to direction controls
442 ** (allows setting data flow; write 0s & 1s to PORTA/PORTB bits
443 ** to set which port's pins are read (input), or write (output),
444 ** respectively)
445 */
446 #define PxCTL_ADDRESSING 0x04 /* bit 2 */
447 
448 /* (W) Peripheral motor control line; Turn the cassette on or off
449 ** (PACTL-specific register bit)
450 ** 0 = on
451 ** 1 = off
452 */
453 #define PACTL_MOTOR_CONTROL 0x08 /* bit 3 */
454 
455 /* Peripheral command identification (serial bus command line)
456 ** (PBCTL-specific register bit)
457 */
458 #define PBCTL_PERIPH_CMD_IDENT 0x08 /* bit 3 */
459 
460 /* Note: Bits 4 & 5 are always set to 1 */
461 
462 /* Note: Bit 6 is always set to 0 */
463 
464 /* (R) Peripheral interrupt (IRQ) status bit.
465 ** Set by Peripherals (PORTA / PORTB). Reset by reading from PORTA / PORTB.
466 ** PACTL's is interrupt status of PROCEED
467 ** PBCTL's is interrupt status of SIO
468 */
469 #define PxCTL_IRQ_STATUS 0x80
470 
471 
472 /* The following #define will cause the matching function calls in conio.h
473 ** to be overlaid by macros with the same names, saving the function call
474 ** overhead.
475 */
476 #define _textcolor(color) COLOR_WHITE
477 
478 /* End of atari.h */
479 #endif
get_ostype
signed char get_ostype(void) __attribute__((leaf))
_pbi.h
_gtia.h
_pokey.h
_atarios.h
_antic.h
get_tv
unsigned char get_tv(void) __attribute__((leaf))
_pia.h
waitvsync
void waitvsync(void)
mode
const void uint16_t uint8_t mode
Definition: memory.h:58