]> git.sur5r.net Git - cc65/blob - include/cbm.h
Stefan Haubenthal fixed a few typos.
[cc65] / include / cbm.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   cbm.h                                   */
4 /*                                                                           */
5 /*                      CBM system specific definitions                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2004 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 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 only be used when compiling for CBM machines!
44 #endif
45
46
47
48 /* Load the system specific files here, if needed */
49 #if defined(__C64__) && !defined(_C64_H)
50 #  include <c64.h>
51 #elif defined(__VIC20__) && !defined(_VIC20_H)
52 #  include <vic20.h>
53 #elif defined(__C128__) && !defined(_C128_H)
54 #  include <c128.h>
55 #elif defined(__PLUS4__) && !defined(_PLUS4_H)
56 #  include <plus4.h>
57 #elif defined(__C16__) && !defined(_C16_H)
58 #  include <c16.h>
59 #elif defined(__CBM510__) && !defined(_CBM510_H)
60 #  include <cbm510.h>
61 #elif defined(__CBM610__) && !defined(_CBM610_H)
62 #  include <cbm610.h>
63 #elif defined(__PET__) && !defined(_PET_H)
64 #  include <pet.h>
65 #endif
66
67
68
69 /*****************************************************************************/
70 /*                                 Variables                                 */
71 /*****************************************************************************/
72
73
74
75 /* The file stream implementation and the POSIX I/O functions will use the
76  * following variables to determine the file type and the disk unit to use.
77  */
78 extern unsigned char _curunit;          /* Default 8 */
79 extern unsigned char _filetype;         /* Default 'u' */
80
81
82
83 /*****************************************************************************/
84 /*                      Characters codes (CBM charset)                       */
85 /*****************************************************************************/
86
87
88
89 #define CH_HLINE                 96
90 #define CH_VLINE                125
91 #define CH_ULCORNER             176
92 #define CH_URCORNER             174
93 #define CH_LLCORNER             173
94 #define CH_LRCORNER             189
95 #define CH_TTEE                 178
96 #define CH_RTEE                 179
97 #define CH_BTEE                 177
98 #define CH_LTEE                 171
99 #define CH_CROSS                123
100 #define CH_CURS_UP              145
101 #define CH_CURS_DOWN             17
102 #define CH_CURS_LEFT            157
103 #define CH_CURS_RIGHT            29
104 #define CH_PI                   126
105 #define CH_DEL                   20
106 #define CH_INS                  148
107 #define CH_ENTER                '\n'
108 #define CH_STOP                   3
109 #define CH_ESC                   27
110
111
112
113 /*****************************************************************************/
114 /*                Definitions for directory reading functions                */
115 /*****************************************************************************/
116
117
118
119 /* CBM FILE TYPES */
120 #define CBM_T_DEL   0
121 #define CBM_T_SEQ   1
122 #define CBM_T_PRG   2
123 #define CBM_T_USR   3
124 #define CBM_T_REL   4
125 #define CBM_T_CBM   5           /* 1581 sub-partition */
126 #define CBM_T_DIR   6           /* IDE64 and CMD sub-directory */
127 #define CBM_T_VRP   8           /* Vorpal fast-loadable format */
128 #define CBM_T_OTHER 5           /* Other file-types not yet defined */
129
130 /* CBM FILE ACCESS */
131 #define CBM_A_RO    1           /* Read only   */
132 #define CBM_A_RW    3           /* Read, Write */
133
134 struct cbm_dirent {
135     char          name[17];     /* File name in PETSCII, limited to 16 chars */
136     unsigned int  size;         /* Size in 256B blocks */
137     unsigned char type;
138     unsigned char access;
139 };
140
141
142
143 /*****************************************************************************/
144 /*                               Machine info                                */
145 /*****************************************************************************/
146
147
148
149 #define TV_NTSC         0
150 #define TV_PAL          1
151 #define TV_OTHER        2
152
153 unsigned char __fastcall__ get_tv (void);
154 /* Return the video mode the machine is using. */
155
156
157
158 /*****************************************************************************/
159 /*                           CBM kernal functions                            */
160 /*****************************************************************************/
161
162
163
164 /* Constants to use with cbm_open() for opening a file for reading or
165  * writing without the need to append ",r" or ",w" to the filename.
166  *
167  * e.g.: cbm_open(2, 8, CBM_READ, "data,s");
168  */
169 #define CBM_READ    0
170 #define CBM_WRITE   1
171
172 /* Kernel level functions */
173 void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV,
174                                 unsigned char SA);
175 void __fastcall__ cbm_k_setnam (const char* Name);
176 unsigned int __fastcall__ cbm_k_load(unsigned char flag, unsigned addr);
177 unsigned char __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
178 unsigned char __fastcall__ cbm_k_open (void);
179 void __fastcall__ cbm_k_close (unsigned char FN);
180 unsigned char __fastcall__ cbm_k_readst (void);
181 unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
182 unsigned char __fastcall__ cbm_k_ckout (unsigned char FN);
183 unsigned char __fastcall__ cbm_k_basin (void);
184 void __fastcall__ cbm_k_bsout (unsigned char C);
185 void __fastcall__ cbm_k_clrch (void);
186
187
188
189 /*****************************************************************************/
190 /*                       BASIC-like file I/O functions                       */
191 /*****************************************************************************/
192
193
194
195 /* All cbm_* IO functions set _oserror (see errno.h) in case of an
196  * error.
197  *
198  * errorcode    BASIC error
199  *      1   =   too many files
200  *      2   =   file open
201  *      3   =   file not open
202  *      4   =   file not found
203  *      5   =   device not present
204  *      6   =   not input file
205  *      7   =   not output file
206  *      8   =   missing filename
207  *      9   =   illegal device number
208  */
209
210
211
212 unsigned int cbm_load (const char* name, unsigned char device, void* data);
213 /* Loads file "name" from given device to given address or to the load
214  * address of the file if "data" is the null pointer (like load"name",8,1
215  * in BASIC).
216  * Returns number of bytes that where loaded if loading was successful
217  * otherwise 0. "_oserror" contains an errorcode then (see table below).
218  */
219
220 unsigned char cbm_save (const char* name, unsigned char device,
221                         const void* data, unsigned int size);
222 /* Saves "size" bytes starting at "data" to a file.
223  * Returns 0 if saving was successful, otherwise an errorcode (see table
224  * below).
225  */
226
227 unsigned char __fastcall__ cbm_open (unsigned char lfn,
228                                      unsigned char device,
229                                      unsigned char sec_addr,
230                                      const char* name);
231 /* Opens a file. Works just like the BASIC command.
232  * Returns 0 if opening was successful, otherwise an errorcode (see table
233  * below).
234  */
235
236 void __fastcall__ cbm_close (unsigned char lfn);
237 /* Closes a file */
238
239 int __fastcall__ cbm_read (unsigned char lfn, void* buffer, unsigned int size);
240 /* Reads up to "size" bytes from a file to "buffer".
241  * Returns the number of actually read bytes, 0 if there are no bytes left
242  * (EOF) or -1 in case of an error. _oserror contains an errorcode then (see
243  * table below).
244  */
245
246 int __fastcall__ cbm_write (unsigned char lfn, void* buffer, unsigned int size);
247 /* Writes up to "size" bytes from "buffer" to a file.
248  * Returns the number of actually written bytes or -1 in case of an error.
249  * _oserror contains an errorcode then (see above table).
250  */
251
252 unsigned char __fastcall__ cbm_opendir (unsigned char lfn, unsigned char device);
253 /* Opens directory listing.
254  * Returns 0 if opening directory was successful,
255  * othervise errorcode corresponding to cbm_open()
256  */
257
258 unsigned char __fastcall__ cbm_readdir (unsigned char lfn, struct cbm_dirent* l_dirent);
259 /* Reads one directory line into cbm_dirent structure.
260  * Returns 0 if reading directory line was successful.
261  * Returns 'true' if reading directory failed or no more files to read.
262  */
263
264 void __fastcall__ cbm_closedir (unsigned char lfn);
265 /* Closes directory by cbm_close (unsigned char lfn) */
266
267
268
269 /* End of cbm.h */
270 #endif
271
272