1 /*****************************************************************************/
5 /* CBM system-specific definitions */
9 /* (C) 1998-2012, Ullrich von Bassewitz */
10 /* Roemerstrasse 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 be used only when compiling for CBM machines!
50 #if !defined(_STDDEF_H)
54 /* Load the system-specific files here, if needed. */
55 #if defined(__C64__) && !defined(_C64_H)
57 #elif defined(__VIC20__) && !defined(_VIC20_H)
59 #elif defined(__C128__) && !defined(_C128_H)
61 #elif defined(__PLUS4__) && !defined(_PLUS4_H)
63 #elif defined(__C16__) && !defined(_C16_H)
65 #elif defined(__CBM510__) && !defined(_CBM510_H)
67 #elif defined(__CBM610__) && !defined(_CBM610_H)
69 #elif defined(__PET__) && !defined(_PET_H)
73 /* Include definitions for CBM file types */
74 #include <cbm_filetype.h>
78 /*****************************************************************************/
80 /*****************************************************************************/
84 /* The file stream implementation and the POSIX I/O functions will
85 * use the following variable to determine the file type to use.
87 extern char _filetype; /* Defaults to 's' */
91 /*****************************************************************************/
92 /* Character-codes (CBM charset) */
93 /*****************************************************************************/
99 #define CH_ULCORNER 176
100 #define CH_URCORNER 174
101 #define CH_LLCORNER 173
102 #define CH_LRCORNER 189
108 #define CH_CURS_UP 145
109 #define CH_CURS_DOWN 17
110 #define CH_CURS_LEFT 157
111 #define CH_CURS_RIGHT 29
123 /*****************************************************************************/
124 /* Definitions for directory reading functions */
125 /*****************************************************************************/
129 /* CBM FILE ACCESS */
130 #define CBM_A_RO 1 /* Read only */
131 #define CBM_A_WO 2 /* Write only */
132 #define CBM_A_RW 3 /* Read, Write */
135 char name[17]; /* File name in PetSCII, limited to 16 chars */
136 unsigned int size; /* Size, in 254-/256-byte blocks */
138 unsigned char access;
143 /*****************************************************************************/
145 /*****************************************************************************/
153 unsigned char get_tv (void);
154 /* Return the video mode the machine is using. */
158 /*****************************************************************************/
159 /* CBM kernal functions */
160 /*****************************************************************************/
164 /* Constants to use with cbm_open() for openning a file for reading or
165 * writing without the need to append ",r" or ",w" to the filename.
167 * e.g., cbm_open(2, 8, CBM_READ, "0:data,s");
169 #define CBM_READ 0 /* default is ",p" */
170 #define CBM_WRITE 1 /* ditto */
171 #define CBM_SEQ 2 /* default is ",r" -- or ",s" when writing */
173 /* Kernal-level functions */
174 unsigned char cbm_k_acptr (void);
175 unsigned char cbm_k_basin (void);
176 void __fastcall__ cbm_k_bsout (unsigned char C);
177 unsigned char __fastcall__ cbm_k_chkin (unsigned char FN);
178 void __fastcall__ cbm_k_ciout (unsigned char C);
179 unsigned char __fastcall__ cbm_k_ckout (unsigned char FN);
180 void cbm_k_clall (void);
181 void __fastcall__ cbm_k_close (unsigned char FN);
182 void cbm_k_clrch (void);
183 unsigned char cbm_k_getin (void);
184 unsigned cbm_k_iobase (void);
185 void __fastcall__ cbm_k_listen (unsigned char dev);
186 unsigned int __fastcall__ cbm_k_load(unsigned char flag, unsigned addr);
187 unsigned char cbm_k_open (void);
188 unsigned char cbm_k_readst (void);
189 unsigned char __fastcall__ cbm_k_save(unsigned int start, unsigned int end);
190 void __fastcall__ cbm_k_setlfs (unsigned char LFN, unsigned char DEV,
192 void __fastcall__ cbm_k_setnam (const char* Name);
193 void __fastcall__ cbm_k_talk (unsigned char dev);
194 void cbm_k_unlsn (void);
198 /*****************************************************************************/
199 /* BASIC-like file I/O functions */
200 /*****************************************************************************/
204 /* The cbm_* I/O functions below set _oserror (see errno.h),
205 * in case of an error.
207 * error-code BASIC error
208 * ---------- -----------
213 * 5 = device not present
215 * 7 = not output-file
216 * 8 = missing file-name
217 * 9 = illegal device-number
219 * 10 = STOP-key pushed
220 * 11 = general I/O-error
225 unsigned int cbm_load (const char* name, unsigned char device, void* data);
226 /* Loads file "name", from given device, to given address -- or, to the load
227 * address of the file if "data" is the null pointer (like load"name",8,1
229 * Returns number of bytes that were loaded if loading was successful;
230 * otherwise 0, "_oserror" contains an error-code, then (see table above).
233 unsigned char __fastcall__ cbm_save (const char* name, unsigned char device,
234 const void* addr, unsigned int size);
235 /* Saves "size" bytes, starting at "addr", to a file.
236 * Returns 0 if saving was successful, otherwise an error-code (see table
240 unsigned char __fastcall__ cbm_open (unsigned char lfn, unsigned char device,
241 unsigned char sec_addr, const char* name);
242 /* Opens a file. Works just like the BASIC command.
243 * Returns 0 if openning was successful, otherwise an error-code (see table
247 void __fastcall__ cbm_close (unsigned char lfn);
250 int __fastcall__ cbm_read (unsigned char lfn, void* buffer, unsigned int size);
251 /* Reads up to "size" bytes from a file into "buffer".
252 * Returns the number of actually-read bytes, 0 if there are no bytes left.
253 * -1 in case of an error; then, _oserror contains an error-code (see table
254 * above). (Remember: 0 means end-of-file; -1 means error.)
257 int __fastcall__ cbm_write (unsigned char lfn, const void* buffer,
259 /* Writes up to "size" bytes from "buffer" to a file.
260 * Returns the number of actually-written bytes, or -1 in case of an error;
261 * _oserror contains an error-code, then (see above table).
264 unsigned char cbm_opendir (unsigned char lfn, unsigned char device, ...);
265 /* Opens directory listing. Returns 0 if opening directory was successful;
266 * otherwise, an error-code corresponding to cbm_open(). As an optional
267 * argument, the name of the directory may be passed to the function. If
268 * no explicit name is specified, "$" is used.
271 unsigned char __fastcall__ cbm_readdir (unsigned char lfn,
272 struct cbm_dirent* l_dirent);
273 /* Reads one directory line into cbm_dirent structure.
274 * Returns 0 if reading directory-line was successful.
275 * Returns non-zero if reading directory failed, or no more file-names to read.
276 * Returns 2 on last line. Then, l_dirent->size = the number of "blocks free."
279 void __fastcall__ cbm_closedir (unsigned char lfn);
280 /* Closes directory by cbm_close(lfn) */