1 /*****************************************************************************/
5 /* CBM system specific definitions */
9 /* (C) 1998-2004 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
41 /* Check for errors */
43 # error This module may only be used when compiling for CBM machines!
48 /* Load the system specific files here, if needed */
49 #if defined(__C64__) && !defined(_C64_H)
51 #elif defined(__VIC20__) && !defined(_VIC20_H)
53 #elif defined(__C128__) && !defined(_C128_H)
55 #elif defined(__PLUS4__) && !defined(_PLUS4_H)
57 #elif defined(__C16__) && !defined(_C16_H)
59 #elif defined(__CBM510__) && !defined(_CBM510_H)
61 #elif defined(__CBM610__) && !defined(_CBM610_H)
63 #elif defined(__PET__) && !defined(_PET_H)
69 /*****************************************************************************/
71 /*****************************************************************************/
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.
78 extern unsigned char _curunit; /* Default 8 */
79 extern unsigned char _filetype; /* Default 'u' */
83 /*****************************************************************************/
84 /* Characters codes (CBM charset) */
85 /*****************************************************************************/
91 #define CH_ULCORNER 176
92 #define CH_URCORNER 174
93 #define CH_LLCORNER 173
94 #define CH_LRCORNER 189
100 #define CH_CURS_UP 145
101 #define CH_CURS_DOWN 17
102 #define CH_CURS_LEFT 157
103 #define CH_CURS_RIGHT 29
107 #define CH_ENTER '\n'
113 /*****************************************************************************/
114 /* Definitions for directory reading functions */
115 /*****************************************************************************/
125 #define CBM_T_CBM 5 /* 1581 sub-partition */
126 #define CBM_T_DIR 6 /* IDE64 and CMD sub-directory */
127 #define CBM_T_RESERVED 7 /* Not used, but kept free for compatibility */
128 #define CBM_T_VRP 8 /* Vorpal fast-loadable format */
129 #define CBM_T_OTHER 9 /* Other file-types not yet defined */
130 #define CBM_T_HEADER 10 /* Disk header / title */
132 /* CBM FILE ACCESS */
133 #define CBM_A_RO 1 /* Read only */
134 #define CBM_A_RW 3 /* Read, Write */
137 char name[17]; /* File name in PETSCII, limited to 16 chars */
138 unsigned int size; /* Size in 256B blocks */
140 unsigned char access;
145 /*****************************************************************************/
147 /*****************************************************************************/
155 unsigned char __fastcall__ get_tv (void);
156 /* Return the video mode the machine is using. */
160 /*****************************************************************************/
161 /* CBM kernal functions */
162 /*****************************************************************************/
166 /* Constants to use with cbm_open() for opening a file for reading or
167 * writing without the need to append ",r" or ",w" to the filename.
169 * e.g.: cbm_open(2, 8, CBM_READ, "data,s");
174 /* Kernel level functions */
175 void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV,
177 void __fastcall__ cbm_k_setnam (const char* Name);
178 unsigned int __fastcall__ cbm_k_load(unsigned char flag, unsigned addr);
179 unsigned char __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
180 unsigned char __fastcall__ cbm_k_open (void);
181 void __fastcall__ cbm_k_close (unsigned char FN);
182 unsigned char __fastcall__ cbm_k_readst (void);
183 unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
184 unsigned char __fastcall__ cbm_k_ckout (unsigned char FN);
185 unsigned char __fastcall__ cbm_k_basin (void);
186 void __fastcall__ cbm_k_bsout (unsigned char C);
187 void __fastcall__ cbm_k_clrch (void);
191 /*****************************************************************************/
192 /* BASIC-like file I/O functions */
193 /*****************************************************************************/
197 /* All cbm_* IO functions set _oserror (see errno.h) in case of an
200 * errorcode BASIC error
205 * 5 = device not present
207 * 7 = not output file
208 * 8 = missing filename
209 * 9 = illegal device number
214 unsigned int cbm_load (const char* name, unsigned char device, void* data);
215 /* Loads file "name" from given device to given address or to the load
216 * address of the file if "data" is the null pointer (like load"name",8,1
218 * Returns number of bytes that where loaded if loading was successful
219 * otherwise 0. "_oserror" contains an errorcode then (see table below).
222 unsigned char cbm_save (const char* name, unsigned char device,
223 const void* data, unsigned int size);
224 /* Saves "size" bytes starting at "data" to a file.
225 * Returns 0 if saving was successful, otherwise an errorcode (see table
229 unsigned char __fastcall__ cbm_open (unsigned char lfn,
230 unsigned char device,
231 unsigned char sec_addr,
233 /* Opens a file. Works just like the BASIC command.
234 * Returns 0 if opening was successful, otherwise an errorcode (see table
238 void __fastcall__ cbm_close (unsigned char lfn);
241 int __fastcall__ cbm_read (unsigned char lfn, void* buffer, unsigned int size);
242 /* Reads up to "size" bytes from a file to "buffer".
243 * Returns the number of actually read bytes, 0 if there are no bytes left
244 * (EOF) or -1 in case of an error. _oserror contains an errorcode then (see
248 int __fastcall__ cbm_write (unsigned char lfn, void* buffer, unsigned int size);
249 /* Writes up to "size" bytes from "buffer" to a file.
250 * Returns the number of actually written bytes or -1 in case of an error.
251 * _oserror contains an errorcode then (see above table).
254 unsigned char __fastcall__ cbm_opendir (unsigned char lfn, unsigned char device);
255 /* Opens directory listing.
256 * Returns 0 if opening directory was successful,
257 * othervise errorcode corresponding to cbm_open()
260 unsigned char __fastcall__ cbm_readdir (unsigned char lfn, struct cbm_dirent* l_dirent);
261 /* Reads one directory line into cbm_dirent structure.
262 * Returns 0 if reading directory line was successful.
263 * Returns 'true' if reading directory failed or no more files to read.
266 void __fastcall__ cbm_closedir (unsigned char lfn);
267 /* Closes directory by cbm_close (unsigned char lfn) */