1 #ifndef __CPM_H__
2 #define __CPM_H__
3 
4 /*
5  *    CPM Specific Header File
6  *
7  *    Many of these values have been obtained via reference to
8  *    Hitech C
9  *
10  *    $Id: cpm.h,v 1.16 2016-11-03 09:25:26 stefano Exp $
11  */
12 
13 #include <sys/compiler.h>
14 #include <sys/types.h>
15 
16 /* Maximum number of open files. If you want to change this then you
17  * should recompile the CPM library and change the crt0 code to creat
18  * enough space for the the FCBs */
19 #define MAXFILE  10
20 
21 /* If you want fileio to support devices then link with -lcpmdevice.
22  * This adds the following devices: CON: RDR: PUN: LST: without this
23  * library an optimised driver saves memory and
24  * permits to specify the user area in filenames, i.e.  "0/c:file.ext"
25  */
26 
27 
28 /* Size of CPM Sector */
29 #define SECSIZE  128
30 
31 /* Flags for fcp->use */
32 #define U_READ  1               /* file open for reading */
33 #define U_WRITE 2               /* file open for writing */
34 #define U_RDWR  3               /* open for read and write */
35 #define U_CON   4               /* device is console */
36 #define U_RDR   5               /* device is reader */
37 #define U_PUN   6               /* device is punch */
38 #define U_LST   7               /* list device */
39 
40 #define __STDIO_EOFMARKER  26   /* End of file marker (^Z) */
41 #define __STDIO_BINARY     1    /* We should consider binary/text differences */
42 #define __STDIO_CRLF       1    /* Automatically convert between CR and CRLF */
43 
44 struct fcb {
45     u8_t    drive;          /* drive code */
46     char    name[8];        /* file name */
47     char    ext[3];         /* file type */
48     u8_t    extent;         /* file extent */
49     char    filler[2];      /* not used */
50     char    records;        /* number of records in present extent */
51     char    discmap[16];    /* CP/M disc map */
52     char    next_record;    /* next record to read or write */
53     u8_t    ranrec[3];      /* random record number (24 bit no. ) */
54 
55     /* Below here is used by the library */
56     unsigned long rwptr;    /* read/write pointer in bytes */
57     u8_t    use;            /* use flag */
58     u8_t    uid;            /* user id belonging to this file */
59     u8_t    mode;           /* TEXT/BINARY discrimination */
60 };
61 
62 struct sfcb {
63     u8_t    drive;          /* drive code */
64     char    name[8];        /* file name */
65     char    ext[3];         /* file type */
66     u8_t    pwdmode;        /* Password mode (0=no pwd): bit 7-Read, bit 6-Write, bit 4-Delete */
67     char    filler[10];     /* not used */
68 	int 	c_date;			/* Create or Access date/time (depends on settings) */
69 	u8_t	c_hours;
70 	u8_t	c_minutes;
71 	int 	date;			/* Update date/time (days since January 1, 1978) */
72 	u8_t	hours;
73 	u8_t	minutes;
74 };
75 
76 
77 extern struct fcb  _fcb[MAXFILE];
78 
79 
80 /* BDOS calls */
81 #define CPM_RCON 1               /* read console */
82 #define CPM_WCON 2               /* write console */
83 #define CPM_RRDR 3               /* read reader */
84 #define CPM_WPUN 4               /* write punch */
85 #define CPM_WLST 5               /* write list */
86 #define CPM_DCIO 6               /* direct console I/O */
87 #define CPM_GIOB 7               /* get I/O byte */
88 #define CPM_SIOB 8               /* set I/O byte */
89 #define CPM_RCOB 10              /* read console buffered */
90 #define CPM_ICON 11              /* interrogate console ready */
91 #define CPM_VERS 12              /* return version number */
92 #define CPM_RDS  13              /* reset disk system */
93 #define CPM_LGIN 14              /* log in and select disk */
94 #define CPM_OPN  15              /* open file */
95 #define CPM_CLS  16              /* close file */
96 #define CPM_FFST 17              /* find first */
97 #define CPM_FNXT 18              /* find next */
98 #define CPM_DEL  19              /* delete file */
99 #define CPM_READ 20              /* read next record */
100 #define CPM_WRIT 21              /* write next record */
101 #define CPM_MAKE 22              /* create file */
102 #define CPM_REN  23              /* rename file */
103 #define CPM_ILOG 24              /* get bit map of logged in disks */
104 #define CPM_IDRV 25              /* interrogate drive number */
105 #define CPM_SDMA 26              /* set DMA address for i/o */
106 #define CPM_SUID 32              /* set/get user id */
107 #define CPM_RRAN 33              /* read random record */
108 #define CPM_WRAN 34              /* write random record */
109 #define CPM_CFS  35              /* compute file size */
110 #define CPM_DSEG 51              /* set DMA segment */
111 
112 
113 /* The CPM bdos call */
114 extern int __LIB__ bdos(int func,int arg) __smallc;
115 extern int __LIB__ bios(int func,int arg,int arg2) __smallc;
116 
117 
118 /* Get a free FCB */
119 
120 extern struct fcb __LIB__ *getfcb(void);
121 
122 /* Fill up the filename stuff */
123 extern int __LIB__ setfcb(struct fcb *fc, unsigned char *name) __smallc;
124 extern void __LIB__ parsefcb(struct fcb *fc, unsigned char *name) __smallc;
125 /* Write the file offset into the FCB */
126 extern void __LIB__ putoffset(char *dest, long val) __smallc;
127 
128 /* Set/get userid */
129 #define setuid(u)  bdos(CPM_SUID,u)
130 #define getuid()   bdos(CPM_SUID,0xFF)
131 
132 /* Write an offset as 3 bytes */
133 extern void __LIB__ _putoffset(unsigned char *where,long offset) __smallc;
134 
135 /* Mark an FCB as being unused */
136 #define clearfcb(f)  (f)->use = 0
137 
138 /*******************/
139 /* directory stuff */
140 /*******************/
141 
142 extern struct fcb __LIB__ fc_dir;
143 extern char __LIB__ fc_dirpos;
144 extern char __LIB__ *fc_dirbuf;
145 
146 /* Disk control (as for OSCA FLOS) */
147 extern int __LIB__  change_volume(int volume);
148 extern int __LIB__ get_current_volume();   // Current 'drive' (0..n)
149 /* Directory related commands (as for OSCA FLOS) */
150 extern int __LIB__ dir_move_first();
151 extern int __LIB__ dir_move_next();
152 extern int __LIB__ dir_get_entry_type();  // 0=normal, 1=directory
153 extern char __LIB__ *dir_get_entry_name();
154 extern unsigned long __LIB__ dir_get_entry_size();
155 extern int __LIB__ get_dir_name();
156 
157 
158 /********************************/
159 /* Amstrad CP/M Plus extensions */
160 /********************************/
161 
162 /* Enable/disable the bottom status line */
163 extern int __LIB__  a_statusline(int onoff);
164 /* Set keyboard speed */
165 extern int __LIB__ a_keyspeed(int delay, int repeat) __smallc;
166 /* Set border color, 6 bit color encoding, (or 8 bit if ULA256.FID is installed) */
167 extern int __LIB__  a_border(int color);
168 /* Set paper color, 6 bit color encoding, (OS patch needed or 8 bit if ULA256.FID is installed) */
169 extern int __LIB__  a_paper(int color);
170 /* Set ink color, 6 bit color encoding, (OS patch needed or 8 bit if ULA256.FID is installed) */
171 extern int __LIB__  a_ink(int color);
172 /* Get x cursor position in viewport */
173 extern int __LIB__ a_curx();
174 /* Get y cursor position in viewport */
175 extern int __LIB__ a_cury();
176 
177 /* Get Machine */
178 extern int __LIB__ a_machine();
179 #define M_CPC        0    // CPC6128
180 #define M_PCW        1    // PCW8000/9000/10 series
181 #define M_SPECTRUM   3    // Spectrum +3
182 #define M_PCW16     65    // (65 = 'A', ie "Anne")
183 
184 /* Get Machine HW version (or HW details on recent PCW versions) */
185 extern int __LIB__ a_machinever();
186 /* Get BIOS version */
187 extern int __LIB__ a_biosver();
188 
189 /* Get system memory size */
190 extern int __LIB__ a_memsize();
191 /* 2 drives available ? */
192 extern int __LIB__ a_driveb();
193 /* Serial Port available ? */
194 extern int __LIB__ a_serialport();
195 
196 #endif
197