]> git.sur5r.net Git - cc65/blob - include/cbm.h
Unified names of CBM kernal level functions and completed the list of
[cc65] / include / cbm.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                   cbm.h                                   */
4 /*                                                                           */
5 /*                      CBM system-specific definitions                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2012, 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 /* Include definitions for CBM file types */
74 #include <cbm_filetype.h>
75
76
77
78 /*****************************************************************************/
79 /*                                 Variables                                 */
80 /*****************************************************************************/
81
82
83
84 /* The file stream implementation and the POSIX I/O functions will use the
85  * following variables to determine the file type and the disk unit to use.
86  */
87 extern unsigned char _curunit;  /* Defaults to current when program started */
88 extern char _filetype;          /* Defaults to 'u' */
89
90
91
92 /*****************************************************************************/
93 /*                       Character-codes (CBM charset)                       */
94 /*****************************************************************************/
95
96
97
98 #define CH_HLINE        192
99 #define CH_VLINE        221
100 #define CH_ULCORNER     176
101 #define CH_URCORNER     174
102 #define CH_LLCORNER     173
103 #define CH_LRCORNER     189
104 #define CH_TTEE         178
105 #define CH_BTEE         177
106 #define CH_LTEE         171
107 #define CH_RTEE         179
108 #define CH_CROSS        219
109 #define CH_CURS_UP      145
110 #define CH_CURS_DOWN     17
111 #define CH_CURS_LEFT    157
112 #define CH_CURS_RIGHT    29
113 #define CH_PI           222
114 #define CH_HOME          19
115 #define CH_DEL           20
116 #define CH_INS          148
117 #define CH_ENTER         13
118 #define CH_STOP           3
119 #define CH_LIRA          92
120 #define CH_ESC           27
121
122
123
124 /*****************************************************************************/
125 /*                Definitions for directory reading functions                */
126 /*****************************************************************************/
127
128
129
130 /* CBM FILE ACCESS */
131 #define CBM_A_RO    1           /* Read only   */
132 #define CBM_A_WO    2           /* Write only  */
133 #define CBM_A_RW    3           /* Read, Write */
134
135 struct cbm_dirent {
136              char name[17];     /* File name in PetSCII, limited to 16 chars */
137     unsigned int  size;         /* Size, in 254-/256-byte blocks */
138     unsigned char type;
139     unsigned char access;
140 };
141
142
143
144 /*****************************************************************************/
145 /*                               Machine info                                */
146 /*****************************************************************************/
147
148
149
150 #define TV_NTSC         0
151 #define TV_PAL          1
152 #define TV_OTHER        2
153
154 unsigned char get_tv (void);
155 /* Return the video mode the machine is using. */
156
157
158
159 /*****************************************************************************/
160 /*                           CBM kernal functions                            */
161 /*****************************************************************************/
162
163
164
165 /* Constants to use with cbm_open() for openning a file for reading or
166  * writing without the need to append ",r" or ",w" to the filename.
167  *
168  * e.g., cbm_open(2, 8, CBM_READ, "0:data,s");
169  */
170 #define CBM_READ        0       /* default is ",p" */
171 #define CBM_WRITE       1       /* ditto */
172 #define CBM_SEQ         2       /* default is ",r" -- or ",s" when writing */
173
174 /* Kernal-level functions */
175 unsigned char cbm_k_acptr (void);
176 unsigned char cbm_k_basin (void);
177 void __fastcall__ cbm_k_bsout (unsigned char C);
178 unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
179 void __fastcall__ cbm_k_ciout (unsigned char C);
180 unsigned char __fastcall__ cbm_k_ckout (unsigned char FN);
181 void cbm_clall (void);
182 void __fastcall__ cbm_k_close (unsigned char FN);
183 void cbm_k_clrch (void);
184 unsigned char cbm_k_getin (void);
185 unsigned cbm_k_iobase (void);
186 void __fastcall__ cbm_k_listen (unsigned char dev);
187 unsigned int __fastcall__ cbm_k_load(unsigned char flag, unsigned addr);
188 unsigned char cbm_k_open (void);
189 unsigned char cbm_k_readst (void);
190 unsigned char __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
191 void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV, 
192                                 unsigned char SA);
193 void __fastcall__ cbm_k_setnam (const char* Name);
194 void __fastcall__ cbm_k_talk (unsigned char dev);
195 void cbm_k_unlsn (void);
196
197
198
199 /*****************************************************************************/
200 /*                       BASIC-like file I/O functions                       */
201 /*****************************************************************************/
202
203
204
205 /* The cbm_* I/O functions below set _oserror (see errno.h),
206  * in case of an error.
207  *
208  * error-code   BASIC error
209  * ----------   -----------
210  *       1  =   too many files
211  *       2  =   file open
212  *       3  =   file not open
213  *       4  =   file not found
214  *       5  =   device not present
215  *       6  =   not input-file
216  *       7  =   not output-file
217  *       8  =   missing file-name
218  *       9  =   illegal device-number
219  *
220  *      10  =   STOP-key pushed
221  *      11  =   general I/O-error
222  */
223
224
225
226 unsigned int cbm_load (const char* name, unsigned char device, void* data);
227 /* Loads file "name", from given device, to given address -- or, to the load
228  * address of the file if "data" is the null pointer (like load"name",8,1
229  * in BASIC).
230  * Returns number of bytes that were loaded if loading was successful;
231  * otherwise 0, "_oserror" contains an error-code, then (see table above).
232  */
233
234 unsigned char __fastcall__ cbm_save (const char* name, unsigned char device,
235                                      const void* addr, unsigned int size);
236 /* Saves "size" bytes, starting at "addr", to a file.
237  * Returns 0 if saving was successful, otherwise an error-code (see table
238  * above).
239  */
240
241 unsigned char __fastcall__ cbm_open (unsigned char lfn, unsigned char device,
242                                      unsigned char sec_addr, const char* name);
243 /* Opens a file. Works just like the BASIC command.
244  * Returns 0 if openning was successful, otherwise an error-code (see table
245  * above).
246  */
247
248 void __fastcall__ cbm_close (unsigned char lfn);
249 /* Closes a file */
250
251 int __fastcall__ cbm_read (unsigned char lfn, void* buffer, unsigned int size);
252 /* Reads up to "size" bytes from a file into "buffer".
253  * Returns the number of actually-read bytes, 0 if there are no bytes left.
254  * -1 in case of an error; then, _oserror contains an error-code (see table
255  * above).  (Remember:  0 means end-of-file; -1 means error.)
256  */
257
258 int __fastcall__ cbm_write (unsigned char lfn, const void* buffer,
259                             unsigned int size);
260 /* Writes up to "size" bytes from "buffer" to a file.
261  * Returns the number of actually-written bytes, or -1 in case of an error;
262  * _oserror contains an error-code, then (see above table).
263  */
264
265 unsigned char cbm_opendir (unsigned char lfn, unsigned char device, ...);
266 /* Opens directory listing. Returns 0 if opening directory was successful;
267  * otherwise, an error-code corresponding to cbm_open(). As an optional
268  * argument, the name of the directory may be passed to the function. If
269  * no explicit name is specified, "$" is used.
270  */
271
272 unsigned char __fastcall__ cbm_readdir (unsigned char lfn,
273                                         struct cbm_dirent* l_dirent);
274 /* Reads one directory line into cbm_dirent structure.
275  * Returns 0 if reading directory-line was successful.
276  * Returns non-zero if reading directory failed, or no more file-names to read.
277  * Returns 2 on last line.  Then, l_dirent->size = the number of "blocks free."
278  */
279
280 void __fastcall__ cbm_closedir (unsigned char lfn);
281 /* Closes directory by cbm_close(lfn) */
282
283
284
285 /* End of cbm.h */
286 #endif
287
288