]> git.sur5r.net Git - cc65/blob - include/cbm.h
Atari: add support for BW-DOS. Initially contributed by Daniel Serpell.
[cc65] / include / cbm.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   cbm.h                                   */
4 /*                                                                           */
5 /*                      CBM system-specific definitions                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2015, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef _CBM_H
37 #define _CBM_H
38
39
40
41 /* Check for errors */
42 #if !defined(__CBM__)
43 #  error This module may be used only when compiling for CBM machines!
44 #endif
45
46
47
48 /* We need NULL. */
49 #include <stddef.h>
50
51 /* Load the system-specific files here, if needed. */
52 #if   defined(__C64__)    && !defined(_C64_H)
53 #  include <c64.h>
54 #elif defined(__VIC20__)  && !defined(_VIC20_H)
55 #  include <vic20.h>
56 #elif defined(__C128__)   && !defined(_C128_H)
57 #  include <c128.h>
58 #elif defined(__PLUS4__)  && !defined(_PLUS4_H)
59 #  include <plus4.h>
60 #elif defined(__C16__)    && !defined(_C16_H)
61 #  include <c16.h>
62 #elif defined(__CBM510__) && !defined(_CBM510_H)
63 #  include <cbm510.h>
64 #elif defined(__CBM610__) && !defined(_CBM610_H)
65 #  include <cbm610.h>
66 #elif defined(__PET__)    && !defined(_PET_H)
67 #  include <pet.h>
68 #endif
69
70 /* Include definitions for CBM file types */
71 #include <cbm_filetype.h>
72
73
74
75 #define JOY_FIRE_MASK   JOY_BTN_1_MASK
76 #define JOY_FIRE(v)     ((v) & JOY_FIRE_MASK)
77
78
79
80 /*****************************************************************************/
81 /*                                 Variables                                 */
82 /*****************************************************************************/
83
84
85
86 /* The file stream implementation and the POSIX I/O functions will
87 ** use the following variable to determine the file type to use.
88 */
89 extern char _filetype;          /* Defaults to 's' */
90
91
92
93 /*****************************************************************************/
94 /*                       Character-codes (CBM charset)                       */
95 /*****************************************************************************/
96
97
98
99 #define CH_HLINE        192
100 #define CH_VLINE        221
101 #define CH_ULCORNER     176
102 #define CH_URCORNER     174
103 #define CH_LLCORNER     173
104 #define CH_LRCORNER     189
105 #define CH_TTEE         178
106 #define CH_BTEE         177
107 #define CH_LTEE         171
108 #define CH_RTEE         179
109 #define CH_CROSS        219
110 #define CH_CURS_UP      145
111 #define CH_CURS_DOWN     17
112 #define CH_CURS_LEFT    157
113 #define CH_CURS_RIGHT    29
114 #define CH_PI           222
115 #define CH_HOME          19
116 #define CH_DEL           20
117 #define CH_INS          148
118 #define CH_ENTER         13
119 #define CH_STOP           3
120 #define CH_LIRA          92
121 #define CH_ESC           27
122
123
124
125 /*****************************************************************************/
126 /*                Definitions for directory reading functions                */
127 /*****************************************************************************/
128
129
130
131 /* CBM FILE ACCESS */
132 #define CBM_A_RO    1           /* Read only   */
133 #define CBM_A_WO    2           /* Write only  */
134 #define CBM_A_RW    3           /* Read, Write */
135
136 struct cbm_dirent {
137              char name[17];     /* File name in PetSCII, limited to 16 chars */
138     unsigned int  size;         /* Size, in 254-/256-byte blocks */
139     unsigned char type;
140     unsigned char access;
141 };
142
143
144
145 /*****************************************************************************/
146 /*                               Machine info                                */
147 /*****************************************************************************/
148
149
150
151 #define TV_NTSC         0
152 #define TV_PAL          1
153 #define TV_OTHER        2
154
155 unsigned char get_tv (void);
156 /* Return the video mode the machine is using. */
157
158 #define KBREPEAT_CURSOR 0x00
159 #define KBREPEAT_NONE   0x40
160 #define KBREPEAT_ALL    0x80
161
162 unsigned char __fastcall__ kbrepeat (unsigned char mode);
163 /* Changes which keys have automatic repeat. */
164
165 #if !defined(__CBM610__) && !defined(__PET__)
166 void waitvsync (void);
167 /* Wait for the start of the next frame */
168 #endif
169
170 /*****************************************************************************/
171 /*                           CBM kernal functions                            */
172 /*****************************************************************************/
173
174
175
176 /* Constants to use with cbm_open() for openning a file for reading or
177 ** writing without the need to append ",r" or ",w" to the filename.
178 **
179 ** e.g., cbm_open(2, 8, CBM_READ, "0:data,s");
180 */
181 #define CBM_READ        0       /* default is ",p" */
182 #define CBM_WRITE       1       /* ditto */
183 #define CBM_SEQ         2       /* default is ",r" -- or ",s" when writing */
184
185 /* Kernal-level functions */
186 unsigned char cbm_k_acptr (void);
187 unsigned char cbm_k_basin (void);
188 void __fastcall__ cbm_k_bsout (unsigned char C);
189 unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
190 void __fastcall__ cbm_k_ciout (unsigned char C);
191 unsigned char __fastcall__ cbm_k_ckout (unsigned char FN);
192 void cbm_k_clall (void);
193 void __fastcall__ cbm_k_close (unsigned char FN);
194 void cbm_k_clrch (void);
195 unsigned char cbm_k_getin (void);
196 unsigned cbm_k_iobase (void);
197 void __fastcall__ cbm_k_listen (unsigned char dev);
198 unsigned int __fastcall__ cbm_k_load(unsigned char flag, unsigned addr);
199 unsigned char cbm_k_open (void);
200 unsigned char cbm_k_readst (void);
201 unsigned char __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
202 void cbm_k_scnkey (void);
203 void __fastcall__ cbm_k_second (unsigned char addr);
204 void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV,
205                                 unsigned char SA);
206 void __fastcall__ cbm_k_setnam (const char* Name);
207 void __fastcall__ cbm_k_talk (unsigned char dev);
208 void __fastcall__ cbm_k_tksa (unsigned char addr);
209 void cbm_k_udtim (void);
210 void cbm_k_unlsn (void);
211 void cbm_k_untlk (void);
212
213
214
215 /*****************************************************************************/
216 /*                       BASIC-like file I/O functions                       */
217 /*****************************************************************************/
218
219
220
221 /* The cbm_* I/O functions below set _oserror (see errno.h),
222 ** in case of an error.
223 **
224 ** error-code   BASIC error
225 ** ----------   -----------
226 **       1  =   too many files
227 **       2  =   file open
228 **       3  =   file not open
229 **       4  =   file not found
230 **       5  =   device not present
231 **       6  =   not input-file
232 **       7  =   not output-file
233 **       8  =   missing file-name
234 **       9  =   illegal device-number
235 **
236 **      10  =   STOP-key pushed
237 **      11  =   general I/O-error
238 */
239
240
241
242 unsigned int __fastcall__ cbm_load (const char* name, unsigned char device, void* data);
243 /* Loads file "name", from given device, to given address -- or, to the load
244 ** address of the file if "data" is the null pointer (like load"name",8,1
245 ** in BASIC).
246 ** Returns number of bytes that were loaded if loading was successful;
247 ** otherwise 0, "_oserror" contains an error-code, then (see table above).
248 */
249
250 unsigned char __fastcall__ cbm_save (const char* name, unsigned char device,
251                                      const void* addr, unsigned int size);
252 /* Saves "size" bytes, starting at "addr", to a file.
253 ** Returns 0 if saving was successful, otherwise an error-code (see table
254 ** above).
255 */
256
257 unsigned char __fastcall__ cbm_open (unsigned char lfn, unsigned char device,
258                                      unsigned char sec_addr, const char* name);
259 /* Opens a file. Works just like the BASIC command.
260 ** Returns 0 if openning was successful, otherwise an error-code (see table
261 ** above).
262 */
263
264 void __fastcall__ cbm_close (unsigned char lfn);
265 /* Closes a file */
266
267 int __fastcall__ cbm_read (unsigned char lfn, void* buffer, unsigned int size);
268 /* Reads up to "size" bytes from a file into "buffer".
269 ** Returns the number of actually-read bytes, 0 if there are no bytes left.
270 ** -1 in case of an error; then, _oserror contains an error-code (see table
271 ** above).  (Remember:  0 means end-of-file; -1 means error.)
272 */
273
274 int __fastcall__ cbm_write (unsigned char lfn, const void* buffer,
275                             unsigned int size);
276 /* Writes up to "size" bytes from "buffer" to a file.
277 ** Returns the number of actually-written bytes, or -1 in case of an error;
278 ** _oserror contains an error-code, then (see above table).
279 */
280
281 unsigned char cbm_opendir (unsigned char lfn, unsigned char device, ...);
282 /* Opens directory listing. Returns 0 if opening directory was successful;
283 ** otherwise, an error-code corresponding to cbm_open(). As an optional
284 ** argument, the name of the directory may be passed to the function. If
285 ** no explicit name is specified, "$" is used.
286 */
287
288 unsigned char __fastcall__ cbm_readdir (unsigned char lfn,
289                                         struct cbm_dirent* l_dirent);
290 /* Reads one directory line into cbm_dirent structure.
291 ** Returns 0 if reading directory-line was successful.
292 ** Returns non-zero if reading directory failed, or no more file-names to read.
293 ** Returns 2 on last line.  Then, l_dirent->size = the number of "blocks free."
294 */
295
296 void __fastcall__ cbm_closedir (unsigned char lfn);
297 /* Closes directory by cbm_close(lfn) */
298
299
300
301 /* End of cbm.h */
302 #endif
303
304