]> git.sur5r.net Git - cc65/blob - include/cbm.h
Changes by Greg King:
[cc65] / include / cbm.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   cbm.h                                   */
4 /*                                                                           */
5 /*                      CBM system-specific definitions                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (c) 1998-2011, 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
50 #if !defined(_STDDEF_H)
51 #  include <stddef.h>
52 #endif
53
54 /* Load the system-specific files here, if needed. */
55 #if   defined(__C64__)    && !defined(_C64_H)
56 #  include <c64.h>
57 #elif defined(__VIC20__)  && !defined(_VIC20_H)
58 #  include <vic20.h>
59 #elif defined(__C128__)   && !defined(_C128_H)
60 #  include <c128.h>
61 #elif defined(__PLUS4__)  && !defined(_PLUS4_H)
62 #  include <plus4.h>
63 #elif defined(__C16__)    && !defined(_C16_H)
64 #  include <c16.h>
65 #elif defined(__CBM510__) && !defined(_CBM510_H)
66 #  include <cbm510.h>
67 #elif defined(__CBM610__) && !defined(_CBM610_H)
68 #  include <cbm610.h>
69 #elif defined(__PET__)    && !defined(_PET_H)
70 #  include <pet.h>
71 #endif
72
73
74
75 /*****************************************************************************/
76 /*                                 Variables                                 */
77 /*****************************************************************************/
78
79
80
81 /* The file stream implementation and the POSIX I/O functions will use the
82  * following variables to determine the file type and the disk unit to use.
83  */
84 extern unsigned char _curunit;  /* Defaults to current when program started */
85 extern char _filetype;          /* Defaults to 'u' */
86
87
88
89 /*****************************************************************************/
90 /*                       Character-codes (CBM charset)                       */
91 /*****************************************************************************/
92
93
94
95 #ifdef __CC65__
96 /* ASCII-to-PetSCII character-map translations:
97  * These lines convert characters that are not in CBM's character-set
98  * into codes with shapes that resemble the ASCII shapes.
99  */
100 #pragma charmap(0x5c,0xbf)      /* '\\' */
101 #pragma charmap(0x5f,0xa4)      /* '_'  thinner than built-in one */
102 #pragma charmap(0x60,0xad)      /* '`'  */
103 #pragma charmap(0x7b,0xb3)      /* '{'  */
104 #pragma charmap(0x7c,0xdd)      /* '|'  "official" PetSCII code */
105 #pragma charmap(0x7d,0xab)      /* '}'  */
106 #pragma charmap(0x7e,0xb1)      /* '~'  */
107 #endif
108
109
110
111 #define CH_HLINE        192
112 #define CH_VLINE        221
113 #define CH_ULCORNER     176
114 #define CH_URCORNER     174
115 #define CH_LLCORNER     173
116 #define CH_LRCORNER     189
117 #define CH_TTEE         178
118 #define CH_BTEE         177
119 #define CH_LTEE         171
120 #define CH_RTEE         179
121 #define CH_CROSS        219
122 #define CH_CURS_UP      145
123 #define CH_CURS_DOWN     17
124 #define CH_CURS_LEFT    157
125 #define CH_CURS_RIGHT    29
126 #define CH_PI           222
127 #define CH_HOME          19
128 #define CH_DEL           20
129 #define CH_INS          148
130 #define CH_ENTER         13
131 #define CH_STOP           3
132 #define CH_LIRA          92
133 #define CH_ESC           27
134
135
136
137 /*****************************************************************************/
138 /*                Definitions for directory reading functions                */
139 /*****************************************************************************/
140
141
142
143 /* CBM FILE TYPES */
144 #define CBM_T_DEL    0
145 #define CBM_T_SEQ    1
146 #define CBM_T_PRG    2
147 #define CBM_T_USR    3
148 #define CBM_T_REL    4
149 #define CBM_T_CBM    5          /* 1581 sub-partition */
150 #define CBM_T_DIR    6          /* IDE64 and CMD sub-directory */
151 #define CBM_T_LNK    7          /* IDE64 soft-link */
152 #define CBM_T_VRP    8          /* Vorpal fast-loadable format */
153 #define CBM_T_OTHER  9          /* File-type not recognized */
154 #define CBM_T_HEADER 10         /* Disk header / title */
155
156 /* CBM FILE ACCESS */
157 #define CBM_A_RO    1           /* Read only   */
158 #define CBM_A_WO    2           /* Write only  */
159 #define CBM_A_RW    3           /* Read, Write */
160
161 struct cbm_dirent {
162              char name[17];     /* File name in PetSCII, limited to 16 chars */
163     unsigned int  size;         /* Size, in 254-/256-byte blocks */
164     unsigned char type;
165     unsigned char access;
166 };
167
168
169
170 /*****************************************************************************/
171 /*                               Machine info                                */
172 /*****************************************************************************/
173
174
175
176 #define TV_NTSC         0
177 #define TV_PAL          1
178 #define TV_OTHER        2
179
180 unsigned char __fastcall__ get_tv (void);
181 /* Return the video mode the machine is using. */
182
183
184
185 /*****************************************************************************/
186 /*                           CBM kernal functions                            */
187 /*****************************************************************************/
188
189
190
191 /* Constants to use with cbm_open() for openning a file for reading or
192  * writing without the need to append ",r" or ",w" to the filename.
193  *
194  * e.g., cbm_open(2, 8, CBM_READ, "0:data,s");
195  */
196 #define CBM_READ        0       /* default is ",p" */
197 #define CBM_WRITE       1       /* ditto */
198 #define CBM_SEQ         2       /* default is ",r" -- or ",s" when writing */
199
200 /* Kernal-level functions */
201 void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV,
202                                 unsigned char SA);
203 void __fastcall__ cbm_k_setnam (const char* Name);
204 unsigned int __fastcall__ cbm_k_load(unsigned char flag, unsigned addr);
205 unsigned char __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
206 unsigned char cbm_k_open (void);
207 void __fastcall__ cbm_k_close (unsigned char FN);
208 signed char cbm_k_readst (void);
209 unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
210 unsigned char __fastcall__ cbm_k_ckout (unsigned char FN);
211 unsigned char cbm_k_basin (void);
212 unsigned char cbm_k_getin (void);
213 void __fastcall__ cbm_k_bsout (unsigned char C);
214 void cbm_k_clrch (void);
215 void cbm_clall (void);
216
217
218
219 /*****************************************************************************/
220 /*                       BASIC-like file I/O functions                       */
221 /*****************************************************************************/
222
223
224
225 /* The cbm_* I/O functions below set _oserror (see errno.h),
226  * in case of an error.
227  *
228  * error-code   BASIC error
229  * ----------   -----------
230  *       1  =   too many files
231  *       2  =   file open
232  *       3  =   file not open
233  *       4  =   file not found
234  *       5  =   device not present
235  *       6  =   not input-file
236  *       7  =   not output-file
237  *       8  =   missing file-name
238  *       9  =   illegal device-number
239  *
240  *      10  =   STOP-key pushed
241  *      11  =   general I/O-error
242  */
243
244
245
246 unsigned int cbm_load (const char* name, unsigned char device, void* data);
247 /* Loads file "name", from given device, to given address -- or, to the load
248  * address of the file if "data" is the null pointer (like load"name",8,1
249  * in BASIC).
250  * Returns number of bytes that were loaded if loading was successful;
251  * otherwise 0, "_oserror" contains an error-code, then (see table above).
252  */
253
254 unsigned char __fastcall__ cbm_save (const char* name, unsigned char device,
255                                      const void* addr, unsigned int size);
256 /* Saves "size" bytes, starting at "addr", to a file.
257  * Returns 0 if saving was successful, otherwise an error-code (see table
258  * above).
259  */
260
261 unsigned char __fastcall__ cbm_open (unsigned char lfn, unsigned char device,
262                                      unsigned char sec_addr, const char* name);
263 /* Opens a file. Works just like the BASIC command.
264  * Returns 0 if openning was successful, otherwise an error-code (see table
265  * above).
266  */
267
268 void __fastcall__ cbm_close (unsigned char lfn);
269 /* Closes a file */
270
271 int __fastcall__ cbm_read (unsigned char lfn, void* buffer, unsigned int size);
272 /* Reads up to "size" bytes from a file into "buffer".
273  * Returns the number of actually-read bytes, 0 if there are no bytes left.
274  * -1 in case of an error; then, _oserror contains an error-code (see table
275  * above).  (Remember:  0 means end-of-file; -1 means error.)
276  */
277
278 int __fastcall__ cbm_write (unsigned char lfn, const void* buffer,
279                             unsigned int size);
280 /* Writes up to "size" bytes from "buffer" to a file.
281  * Returns the number of actually-written bytes, or -1 in case of an error;
282  * _oserror contains an error-code, then (see above table).
283  */
284
285 unsigned char __fastcall__ cbm_opendir (unsigned char lfn, unsigned char device);
286 /* Opens directory listing.
287  * Returns 0 if openning directory was successful;
288  * otherwise, an error-code corresponding to cbm_open().
289  */
290
291 unsigned char __fastcall__ cbm_readdir (unsigned char lfn,
292                                         struct cbm_dirent* l_dirent);
293 /* Reads one directory line into cbm_dirent structure.
294  * Returns 0 if reading directory-line was successful.
295  * Returns non-zero if reading directory failed, or no more file-names to read.
296  * Returns 2 on last line.  Then, l_dirent->size = the number of "blocks free."
297  */
298
299 void __fastcall__ cbm_closedir (unsigned char lfn);
300 /* Closes directory by cbm_close(lfn) */
301
302
303
304 /* End of cbm.h */
305 #endif
306
307