]> git.sur5r.net Git - cc65/blob - include/atari.h
Relocate register values outside structs, + more
[cc65] / include / atari.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 atari.h                                   */
4 /*                                                                           */
5 /*                      Atari system specific definitions                    */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2018 Mark Keates <markk@dendrite.co.uk>                          */
10 /*               Freddy Offenga <taf_offenga@yahoo.com>                      */
11 /*               Christian Groessler <chris@groessler.org>                   */
12 /*                                                                           */
13 /*                                                                           */
14 /* This software is provided 'as-is', without any expressed or implied       */
15 /* warranty.  In no event will the authors be held liable for any damages    */
16 /* arising from the use of this software.                                    */
17 /*                                                                           */
18 /* Permission is granted to anyone to use this software for any purpose,     */
19 /* including commercial applications, and to alter it and redistribute it    */
20 /* freely, subject to the following restrictions:                            */
21 /*                                                                           */
22 /* 1. The origin of this software must not be misrepresented; you must not   */
23 /*    claim that you wrote the original software. If you use this software   */
24 /*    in a product, an acknowledgment in the product documentation would be  */
25 /*    appreciated but is not required.                                       */
26 /* 2. Altered source versions must be plainly marked as such, and must not   */
27 /*    be misrepresented as being the original software.                      */
28 /* 3. This notice may not be removed or altered from any source              */
29 /*    distribution.                                                          */
30 /*                                                                           */
31 /*****************************************************************************/
32
33
34
35 #ifndef _ATARI_H
36 #define _ATARI_H
37
38
39
40 /* Check for errors */
41 #if !defined(__ATARI__)
42 #  error This module may only be used when compiling for the Atari!
43 #endif
44
45
46
47 /* Character codes */
48 #define CH_DELCHR       0xFE   /* delete char under the cursor */
49 #define CH_ENTER        0x9B
50 #define CH_ESC          0x1B
51 #define CH_CURS_UP      28
52 #define CH_CURS_DOWN    29
53 #define CH_CURS_LEFT    30
54 #define CH_CURS_RIGHT   31
55
56 #define CH_TAB          0x7F   /* tabulator */
57 #define CH_EOL          0x9B   /* end-of-line marker */
58 #define CH_CLR          0x7D   /* clear screen */
59 #define CH_BEL          0xFD   /* bell */
60 #define CH_DEL          0x7E   /* back space (delete char to the left) */
61 #define CH_RUBOUT       0x7E   /* back space (old, deprecated) */
62 #define CH_DELLINE      0x9C   /* delete line */
63 #define CH_INSLINE      0x9D   /* insert line */
64
65 /* These are defined to be Atari + NumberKey */
66 #define CH_F1           177
67 #define CH_F2           178
68 #define CH_F3           179
69 #define CH_F4           180
70 #define CH_F5           181
71 #define CH_F6           182
72 #define CH_F7           183
73 #define CH_F8           184
74 #define CH_F9           185
75 #define CH_F10          176
76
77 #define CH_ULCORNER     0x11
78 #define CH_URCORNER     0x05
79 #define CH_LLCORNER     0x1A
80 #define CH_LRCORNER     0x03
81 #define CH_TTEE         0x17
82 #define CH_BTEE         0x18
83 #define CH_LTEE         0x01
84 #define CH_RTEE         0x04
85 #define CH_CROSS        0x13
86 #define CH_HLINE        0x12
87 #define CH_VLINE        0x7C
88
89
90 /* Color definitions */
91
92 /* Make a GTIA color value */
93 #define _gtia_mkcolor(hue,lum) (((hue) << 4) | ((lum) << 1))
94
95 /* Luminance values go from 0 (black) to 7 (white) */
96
97 /* Hue values */
98 /* (These can vary depending on TV standard (NTSC vs PAL),
99 ** tint potentiometer settings, TV tint settings, emulator palette, etc.)
100 */
101 #define HUE_GREY        0
102 #define HUE_GOLD        1
103 #define HUE_GOLDORANGE  2
104 #define HUE_REDORANGE   3
105 #define HUE_ORANGE      4
106 #define HUE_MAGENTA     5
107 #define HUE_PURPLE      6
108 #define HUE_BLUE        7
109 #define HUE_BLUE2       8
110 #define HUE_CYAN        9
111 #define HUE_BLUEGREEN   10
112 #define HUE_BLUEGREEN2  11
113 #define HUE_GREEN       12
114 #define HUE_YELLOWGREEN 13
115 #define HUE_YELLOW      14
116 #define HUE_YELLOWRED   15
117
118 /* Color defines, similar to c64 colors (untested) */
119 /* Note that the conio color implementation is monochrome
120 ** (bgcolor and textcolor are only placeholders)
121 */
122 /* Use the defines with the setcolor() or _atari_xxxcolor() functions */
123 #define COLOR_BLACK             _gtia_mkcolor(HUE_GREY,0)
124 #define COLOR_WHITE             _gtia_mkcolor(HUE_GREY,7)
125 #define COLOR_RED               _gtia_mkcolor(HUE_REDORANGE,1)
126 #define COLOR_CYAN              _gtia_mkcolor(HUE_CYAN,3)
127 #define COLOR_VIOLET            _gtia_mkcolor(HUE_PURPLE,4)
128 #define COLOR_GREEN             _gtia_mkcolor(HUE_GREEN,2)
129 #define COLOR_BLUE              _gtia_mkcolor(HUE_BLUE,2)
130 #define COLOR_YELLOW            _gtia_mkcolor(HUE_YELLOW,7)
131 #define COLOR_ORANGE            _gtia_mkcolor(HUE_ORANGE,5)
132 #define COLOR_BROWN             _gtia_mkcolor(HUE_YELLOW,2)
133 #define COLOR_LIGHTRED          _gtia_mkcolor(HUE_REDORANGE,6)
134 #define COLOR_GRAY1             _gtia_mkcolor(HUE_GREY,2)
135 #define COLOR_GRAY2             _gtia_mkcolor(HUE_GREY,3)
136 #define COLOR_LIGHTGREEN        _gtia_mkcolor(HUE_GREEN,6)
137 #define COLOR_LIGHTBLUE         _gtia_mkcolor(HUE_BLUE,6)
138 #define COLOR_GRAY3             _gtia_mkcolor(HUE_GREY,5)
139
140 /* TGI color defines */
141 #define TGI_COLOR_BLACK         COLOR_BLACK
142 #define TGI_COLOR_WHITE         COLOR_WHITE
143 #define TGI_COLOR_RED           COLOR_RED
144 #define TGI_COLOR_CYAN          COLOR_CYAN
145 #define TGI_COLOR_VIOLET        COLOR_VIOLET
146 #define TGI_COLOR_GREEN         COLOR_GREEN
147 #define TGI_COLOR_BLUE          COLOR_BLUE
148 #define TGI_COLOR_YELLOW        COLOR_YELLOW
149 #define TGI_COLOR_ORANGE        COLOR_ORANGE
150 #define TGI_COLOR_BROWN         COLOR_BROWN
151 #define TGI_COLOR_LIGHTRED      COLOR_LIGHTRED
152 #define TGI_COLOR_GRAY1         COLOR_GRAY1
153 #define TGI_COLOR_GRAY2         COLOR_GRAY2
154 #define TGI_COLOR_LIGHTGREEN    COLOR_LIGHTGREEN
155 #define TGI_COLOR_LIGHTBLUE     COLOR_LIGHTBLUE
156 #define TGI_COLOR_GRAY3         COLOR_GRAY3
157
158 /* Masks for joy_read */
159 #define JOY_UP_MASK     0x01
160 #define JOY_DOWN_MASK   0x02
161 #define JOY_LEFT_MASK   0x04
162 #define JOY_RIGHT_MASK  0x08
163 #define JOY_BTN_1_MASK  0x10
164
165 #define JOY_FIRE_MASK   JOY_BTN_1_MASK
166 #define JOY_FIRE(v)     ((v) & JOY_FIRE_MASK)
167
168 /* Keyboard values returned by kbcode / CH */
169 #define KEY_NONE        ((unsigned char) 0xFF)
170
171 #define KEY_0           ((unsigned char) 0x32)
172 #define KEY_1           ((unsigned char) 0x1F)
173 #define KEY_2           ((unsigned char) 0x1E)
174 #define KEY_3           ((unsigned char) 0x1A)
175 #define KEY_4           ((unsigned char) 0x18)
176 #define KEY_5           ((unsigned char) 0x1D)
177 #define KEY_6           ((unsigned char) 0x1B)
178 #define KEY_7           ((unsigned char) 0x33)
179 #define KEY_8           ((unsigned char) 0x35)
180 #define KEY_9           ((unsigned char) 0x30)
181
182 #define KEY_A           ((unsigned char) 0x3F)
183 #define KEY_B           ((unsigned char) 0x15)
184 #define KEY_C           ((unsigned char) 0x12)
185 #define KEY_D           ((unsigned char) 0x3A)
186 #define KEY_E           ((unsigned char) 0x2A)
187 #define KEY_F           ((unsigned char) 0x38)
188 #define KEY_G           ((unsigned char) 0x3D)
189 #define KEY_H           ((unsigned char) 0x39)
190 #define KEY_I           ((unsigned char) 0x0D)
191 #define KEY_J           ((unsigned char) 0x01)
192 #define KEY_K           ((unsigned char) 0x05)
193 #define KEY_L           ((unsigned char) 0x00)
194 #define KEY_M           ((unsigned char) 0x25)
195 #define KEY_N           ((unsigned char) 0x23)
196 #define KEY_O           ((unsigned char) 0x08)
197 #define KEY_P           ((unsigned char) 0x0A)
198 #define KEY_Q           ((unsigned char) 0x2F)
199 #define KEY_R           ((unsigned char) 0x28)
200 #define KEY_S           ((unsigned char) 0x3E)
201 #define KEY_T           ((unsigned char) 0x2D)
202 #define KEY_U           ((unsigned char) 0x0B)
203 #define KEY_V           ((unsigned char) 0x10)
204 #define KEY_W           ((unsigned char) 0x2E)
205 #define KEY_X           ((unsigned char) 0x16)
206 #define KEY_Y           ((unsigned char) 0x2B)
207 #define KEY_Z           ((unsigned char) 0x17)
208
209 #define KEY_COMMA       ((unsigned char) 0x20)
210 #define KEY_PERIOD      ((unsigned char) 0x22)
211 #define KEY_SLASH       ((unsigned char) 0x26)
212 #define KEY_SEMICOLON   ((unsigned char) 0x02)
213 #define KEY_PLUS        ((unsigned char) 0x06)
214 #define KEY_ASTERISK    ((unsigned char) 0x07)
215 #define KEY_DASH        ((unsigned char) 0x0E)
216 #define KEY_EQUALS      ((unsigned char) 0x0F)
217 #define KEY_LESSTHAN    ((unsigned char) 0x36)
218 #define KEY_GREATERTHAN ((unsigned char) 0x37)
219
220 #define KEY_ESC         ((unsigned char) 0x1C)
221 #define KEY_TAB         ((unsigned char) 0x2C)
222 #define KEY_SPACE       ((unsigned char) 0x21)
223 #define KEY_RETURN      ((unsigned char) 0x0C)
224 #define KEY_DELETE      ((unsigned char) 0x34)
225 #define KEY_CAPS        ((unsigned char) 0x3C)
226 #define KEY_INVERSE     ((unsigned char) 0x27)
227 #define KEY_HELP        ((unsigned char) 0x11)
228
229 #define KEY_F1          ((unsigned char) 0x03)
230 #define KEY_F2          ((unsigned char) 0x04)
231 #define KEY_F3          ((unsigned char) 0x13)
232 #define KEY_F4          ((unsigned char) 0x14)
233
234 #define KEY_CTRL        ((unsigned char) 0x80)
235 #define KEY_SHIFT       ((unsigned char) 0x40)
236
237 /* Composed keys */
238
239 #define KEY_EXCLAMATIONMARK     (KEY_1 | KEY_SHIFT)
240 #define KEY_QUOTE               (KEY_2 | KEY_SHIFT)
241 #define KEY_HASH                (KEY_3 | KEY_SHIFT)
242 #define KEY_DOLLAR              (KEY_4 | KEY_SHIFT)
243 #define KEY_PERCENT             (KEY_5 | KEY_SHIFT)
244 #define KEY_AMPERSAND           (KEY_6 | KEY_SHIFT)
245 #define KEY_APOSTROPHE          (KEY_7 | KEY_SHIFT)
246 #define KEY_AT                  (KEY_8 | KEY_SHIFT)
247 #define KEY_OPENINGPARAN        (KEY_9 | KEY_SHIFT)
248 #define KEY_CLOSINGPARAN        (KEY_0 | KEY_SHIFT)
249 #define KEY_UNDERLINE           (KEY_DASH | KEY_SHIFT)
250 #define KEY_BAR                 (KEY_EQUALS | KEY_SHIFT)
251 #define KEY_COLON               (KEY_SEMICOLON | KEY_SHIFT)
252 #define KEY_BACKSLASH           (KEY_PLUS | KEY_SHIFT)
253 #define KEY_CIRCUMFLEX          (KEY_ASTERISK | KEY_SHIFT)
254 #define KEY_OPENINGBRACKET      (KEY_COMMA | KEY_SHIFT)
255 #define KEY_CLOSINGBRACKET      (KEY_PERIOD | KEY_SHIFT)
256 #define KEY_QUESTIONMARK        (KEY_SLASH | KEY_SHIFT)
257 #define KEY_CLEAR               (KEY_LESSTHAN | KEY_SHIFT)
258 #define KEY_INSERT              (KEY_GREATERTHAN | KEY_SHIFT)
259
260 #define KEY_UP      (KEY_UNDERLINE | KEY_CTRL)
261 #define KEY_DOWN    (KEY_EQUALS | KEY_CTRL)
262 #define KEY_LEFT    (KEY_PLUS | KEY_CTRL)
263 #define KEY_RIGHT   (KEY_ASTERISK | KEY_CTRL)
264
265 /* Color register functions */
266 extern void __fastcall__ _setcolor     (unsigned char color_reg, unsigned char hue, unsigned char luminace);
267 extern void __fastcall__ _setcolor_low (unsigned char color_reg, unsigned char color_value);
268 extern unsigned char __fastcall__ _getcolor (unsigned char color_reg);
269
270 /* Other screen functions */
271 extern int  __fastcall__ _graphics (unsigned char mode); /* mode value same as in BASIC */
272 extern void __fastcall__ _scroll (signed char numlines);
273                                           /* numlines > 0  scrolls up */
274                                           /* numlines < 0  scrolls down */
275
276 /* Misc. functions */
277 extern unsigned char get_ostype(void);       /* get ROM version */
278 extern unsigned char get_tv(void);           /* get TV system */
279 extern void _save_vecs(void);                /* save system vectors */
280 extern void _rest_vecs(void);                /* restore system vectors */
281 extern char *_getdefdev(void);               /* get default floppy device */
282 extern unsigned char _is_cmdline_dos(void);  /* does DOS support command lines */
283
284 /* Global variables */
285 extern unsigned char _dos_type;         /* the DOS flavour */
286 #ifndef __ATARIXL__
287 extern void atr130_emd[];
288 extern void atrstd_joy[];               /* referred to by joy_static_stddrv[] */
289 extern void atrmj8_joy[];
290 extern void atrjoy_mou[];
291 extern void atrst_mou[];                /* referred to by mouse_static_stddrv[] */
292 extern void atrami_mou[];
293 extern void atrtrk_mou[];
294 extern void atrtt_mou[];
295 extern void atrrdev_ser[];
296 extern void atr3_tgi[];
297 extern void atr4_tgi[];
298 extern void atr5_tgi[];
299 extern void atr6_tgi[];
300 extern void atr7_tgi[];
301 extern void atr8_tgi[];                 /* referred to by tgi_static_stddrv[] */
302 extern void atr8p2_tgi[];
303 extern void atr9_tgi[];
304 extern void atr9p2_tgi[];
305 extern void atr10_tgi[];
306 extern void atr10p2_tgi[];
307 extern void atr11_tgi[];
308 extern void atr14_tgi[];
309 extern void atr15_tgi[];
310 extern void atr15p2_tgi[];
311 #else
312 extern void atrx130_emd[];
313 extern void atrxstd_joy[];              /* referred to by joy_static_stddrv[] */
314 extern void atrxmj8_joy[];
315 extern void atrxjoy_mou[];
316 extern void atrxst_mou[];               /* referred to by mouse_static_stddrv[] */
317 extern void atrxami_mou[];
318 extern void atrxtrk_mou[];
319 extern void atrxtt_mou[];
320 extern void atrxrdev_ser[];
321 extern void atrx3_tgi[];
322 extern void atrx4_tgi[];
323 extern void atrx5_tgi[];
324 extern void atrx6_tgi[];
325 extern void atrx7_tgi[];
326 extern void atrx8_tgi[];                /* referred to by tgi_static_stddrv[] */
327 extern void atrx8p2_tgi[];
328 extern void atrx9_tgi[];
329 extern void atrx9p2_tgi[];
330 extern void atrx10_tgi[];
331 extern void atrx10p2_tgi[];
332 extern void atrx11_tgi[];
333 extern void atrx14_tgi[];
334 extern void atrx15_tgi[];
335 extern void atrx15p2_tgi[];
336 #endif
337
338 /* get_ostype return value defines (for explanation, see ostype.s) */
339 /* masks */
340 #define AT_OS_TYPE_MAIN  7
341 #define AT_OS_TYPE_MINOR (7 << 3)
342 /* AT_OS_TYPE_MAIN values */
343 #define AT_OS_UNKNOWN  0
344 #define AT_OS_400800   1
345 #define AT_OS_1200XL   2
346 #define AT_OS_XLXE     3
347 /* AS_OS_TYPE_MINOR values */
348 /* for 400/800 remember this are the ROM versions */
349 /* to check whether the hw is PAL or NTSC, use get_tv() */
350 #define AT_OS_400800PAL_A  1
351 #define AT_OS_400800PAL_B  2
352 #define AT_OS_400800NTSC_A 1
353 #define AT_OS_400800NTSC_B 2
354 #define AT_OS_1200_10  1
355 #define AT_OS_1200_11  2
356 #define AT_OS_XLXE_1   1
357 #define AT_OS_XLXE_2   2
358 #define AT_OS_XLXE_3   3
359 #define AT_OS_XLXE_4   4
360
361 /* get_tv return values */
362 #define AT_NTSC     0
363 #define AT_PAL      1
364
365 /* valid _dos_type values */
366 #define SPARTADOS   0
367 #define REALDOS     1
368 #define BWDOS       2
369 #define OSADOS      3
370 #define XDOS        4
371 #define ATARIDOS    5
372 #define MYDOS       6
373 #define NODOS       255
374
375 /* Define hardware */
376 #include <_gtia.h>
377 #define GTIA_READ  (*(struct __gtia_read*)0xD000)
378 #define GTIA_WRITE (*(struct __gtia_write*)0xD000)
379
380 #include <_pbi.h>
381
382 #include <_pokey.h>
383 #define POKEY_READ  (*(struct __pokey_read*)0xD200)
384 #define POKEY_WRITE (*(struct __pokey_write*)0xD200)
385
386 #include <_pia.h>
387 #define PIA (*(struct __pia*)0xD300)
388
389 #include <_antic.h>
390 #define ANTIC (*(struct __antic*)0xD400)
391
392 /* device control block */
393 struct __dcb {
394     unsigned char device;     /* device id */
395     unsigned char unit;       /* unit number */
396     unsigned char command;    /* command */
397     unsigned char status;     /* command type / status return */
398     void          *buffer;    /* pointer to buffer */
399     unsigned char timeout;    /* device timeout in seconds */
400     unsigned char unused;
401     unsigned int  xfersize;   /* # of bytes to transfer */
402     unsigned char aux1;       /* 1st command auxiliary byte */
403     unsigned char aux2;       /* 2nd command auxiliary byte */
404 };
405 #define DCB (*(struct __dcb *)0x300)
406
407 /* I/O control block */
408 struct __iocb {
409     unsigned char handler;    /* handler index number (0xff free) */
410     unsigned char drive;      /* device number (drive) */
411     unsigned char command;    /* command */
412     unsigned char status;     /* status of last operation */
413     void          *buffer;    /* pointer to buffer */
414     void          *put_byte;  /* pointer to device's PUT BYTE routine */
415     unsigned int  buflen;     /* length of buffer */
416     unsigned char aux1;       /* 1st auxiliary byte */
417     unsigned char aux2;       /* 2nd auxiliary byte */
418     unsigned char aux3;       /* 3rd auxiliary byte */
419     unsigned char aux4;       /* 4th auxiliary byte */
420     unsigned char aux5;       /* 5th auxiliary byte */
421     unsigned char spare;      /* spare byte */
422 };
423 #define ZIOCB (*(struct __iocb *)0x20)  /* zero page IOCB */
424 #define IOCB (*(struct __iocb *)0x340)  /* system IOCB buffers */
425
426 /* IOCB Command Codes */
427 #define IOCB_OPEN        0x03  /* open */
428 #define IOCB_GETREC      0x05  /* get record */
429 #define IOCB_GETCHR      0x07  /* get character(s) */
430 #define IOCB_PUTREC      0x09  /* put record */
431 #define IOCB_PUTCHR      0x0B  /* put character(s) */
432 #define IOCB_CLOSE       0x0C  /* close */
433 #define IOCB_STATIS      0x0D  /* status */
434 #define IOCB_SPECIL      0x0E  /* special */
435 #define IOCB_DRAWLN      0x11  /* draw line */
436 #define IOCB_FILLIN      0x12  /* draw line with right fill */
437 #define IOCB_RENAME      0x20  /* rename disk file */
438 #define IOCB_DELETE      0x21  /* delete disk file */
439 #define IOCB_LOCKFL      0x23  /* lock file (set to read-only) */
440 #define IOCB_UNLOCK      0x24  /* unlock file */
441 #define IOCB_POINT       0x25  /* point sector */
442 #define IOCB_NOTE        0x26  /* note sector */
443 #define IOCB_GETFL       0x27  /* get file length */
444 #define IOCB_CHDIR_MYDOS 0x29  /* change directory (MyDOS) */
445 #define IOCB_MKDIR       0x2A  /* make directory (MyDOS/SpartaDOS) */
446 #define IOCB_RMDIR       0x2B  /* remove directory (SpartaDOS) */
447 #define IOCB_CHDIR_SPDOS 0x2C  /* change directory (SpartaDOS) */
448 #define IOCB_GETCWD      0x30  /* get current directory (MyDOS/SpartaDOS) */
449 #define IOCB_FORMAT      0xFE  /* format */
450
451
452 /* End of atari.h */
453 #endif