1 /*
2  *      Small C+ Library
3  *
4  *      Opus Discovery low level support
5  *
6  *      Stefano Bodrato - 7/6/2006
7  *
8  *	$Id: zxopus.h,v 1.10 2016-06-27 19:16:33 dom Exp $
9  */
10 
11 
12 #ifndef __ZXOPUS_H__
13 #define __ZXOPUS_H__
14 
15 #include <sys/compiler.h>
16 #include <sys/types.h>
17 #include <fcntl.h>
18 
19 
20 #ifndef __ZX_CHANNELS__
21 #define	__ZX_CHANNELS__
22 
23 struct BASE_CHAN {
24 	// base channel descriptor
25 	u16_t	out;		/* pointer to the output routine     */
26 	u16_t	in;		/* pointer to the input routine      */
27 	u8_t	id_char;	/* upper (if permanent) or lower "M".. char  */
28 	u16_t	len;		/* length of channel                 */
29 };
30 
31 
32 // M_CHAN is 33 bytes long (including BASE_CHAN), + the block size
33 // (the block-size can be 128, 256, 512 or 1024 bytes)
34 struct M_CHAN {
35 	// base channel descriptor
36 	struct	BASE_CHAN base;
37 	// "M" channel specific stuff
38 	u8_t	drive;		/* drive number */
39 	char    name[10];	/* file name */
40 	u16_t	blklen;		/* Block size */
41 	u16_t	reclen;		/* Number of databytes in record */
42 	u16_t	lastblkbyt;	/* Number of bytes in the last block */
43 	u16_t	firstblk;	/* Location of the first block */
44 	u16_t	lastblk;	/* Location of the last block */
45 	u16_t	block;		/* Location of the current block */
46 	u16_t	bytecount;	/* Position in the current block */
47 	u8_t	flag;		/* bit 0 : SET if changes were made to the buffer */
48 	//char	data[512]	/* the buffer */
49 };
50 
51 
52 // The 'd' channel is only used by the  MOVE  command,
53 // however it should act as a normal channel;
54 // you should be able to read and write to it.
55 struct D_CHAN {
56 	// base channel descriptor
57 	struct	BASE_CHAN base;
58 	// '#' channel specific stuff
59 	u8_t	outdrive;		/* output drive number */
60 	u8_t	indrive;		/* input drive number */
61 };
62 
63 
64 struct CODE_CHAN {
65 	// base channel descriptor
66 	struct	BASE_CHAN base;
67 	// '#' channel specific stuff
68 	u16_t	address;		/* pointed address */
69 };
70 
71 
72 struct T_CHAN {
73 	// base channel descriptor
74 	struct	BASE_CHAN base;
75 
76 	u8_t	tflags;
77 	u8_t	lastcol;
78 	u8_t	currcol;
79 };
80 
81 // these are the single bits for 'tflags' in T_CHAN
82 	#define TCHAN_ZXPRTEMU	1	/* ZX printer emulation     */
83 	#define TCHAN_SEQ	2
84 	#define TCHAN_BACKSP	4	/* set for true backspacing */
85 	#define TCHAN_AT	32	/* set for AT character     */
86 	#define TCHAN_TAB	64	/* set for TAB character    */
87 	#define TCHAN_AT_TAB	128
88 
89 
90 struct B_CHAN {
91 	// base channel descriptor
92 	struct	BASE_CHAN base;
93 	// that's all !!
94 };
95 
96 
97 struct STRM_CHAN {
98 	// base channel descriptor
99 	struct	BASE_CHAN base;
100 	// '#' channel specific stuff
101 	u8_t	stream;			/* stream address */
102 };
103 
104 
105 // Joystick !!
106 // Note that it works in this way only if the kempston emulation is off
107 // WARNING: all the joystick stuff could not work with the Spectrum emulators
108 struct J_CHAN {
109 	// base channel descriptor
110 	struct	BASE_CHAN base;
111 	// '#' channel specific stuff
112 	u8_t	joystick;		/* 1 for QWERT and 67890 */
113 					/* 2 for QWERT and 12345 */
114 };
115 
116 #endif /*__ZX_CHANNELS__*/
117 
118 
119 // set the kempston emulation (1=on, 0=off)
120 extern void __LIB__ set_kempston (int mode);
121 
122 // get the kempston emulation status (1=on, 0=off)
123 extern int __LIB__ get_kempston ();
124 
125 // get the number of sectors
126 extern int __LIB__ opus_getblocks (int drive);
127 
128 // get the sector size
129 extern int __LIB__ opus_getblocksize (int drive);
130 
131 // load a sector
132 // A standard 178K Opus disk has 0..718 (719?) sectors
133 // Each sector is 256 bytes long
134 extern int __LIB__ opus_getsect(int drive, int sector, unsigned char * buffer) __smallc;
135 extern int __LIB__  opus_getsect_callee(int drive, int sector, char * buffer)__smallc __z88dk_callee;
136 #define opus_getsect(a,b,c)           opus_getsect_callee(a,b,c)
137 
138 // save a sector
139 // A standard 178K Opus disk has 0..718 (719?) sectors
140 // Each sector is 256 bytes long
141 extern int __LIB__ opus_putsect(int drive, int sector, unsigned char * buffer) __smallc;
142 extern int __LIB__  opus_putsect_callee(int drive, int sector, char * buffer)__smallc __z88dk_callee;
143 #define opus_putsect(a,b,c)           opus_putsect_callee(a,b,c)
144 
145 // parallel port put/get byte
146 extern void __LIB__ opus_lptwrite (unsigned int databyte);
147 extern unsigned char __LIB__ opus_lptread ();
148 
149 // Returns true if the Opus Discovery interface is present
150 extern int __LIB__ zx_opus();
151 
152 // Get the Opus firmware version
153 extern float __LIB__ opus_version ();
154 
155 
156 #endif /* _ZXOPUS_H */
157