1 /*
2  * serial.h - Serial device implementation.
3  *
4  * Written by
5  *  Teemu Rantanen <tvr@cs.hut.fi>
6  *  Andre Fachat <a.fachat@physik.tu-chemnitz.de>
7  *  Andreas Boose <viceteam@t-online.de>
8  *
9  * This file is part of VICE, the Versatile Commodore Emulator.
10  * See README for copyright notice.
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; either version 2 of the License, or
15  *  (at your option) any later version.
16  *
17  *  This program is distributed in the hope that it will be useful,
18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *  GNU General Public License for more details.
21  *
22  *  You should have received a copy of the GNU General Public License
23  *  along with this program; if not, write to the Free Software
24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
25  *  02111-1307  USA.
26  *
27  */
28 
29 #ifndef VICE_SERIAL_H
30 #define VICE_SERIAL_H
31 
32 #include "types.h"
33 
34 #define SERIAL_MAXDEVICES 16
35 
36 #define SERIAL_DEVICE_NONE 0
37 #define SERIAL_DEVICE_FS   1 /* filesystem */
38 #define SERIAL_DEVICE_REAL 2 /* real IEC device (opencbm) */
39 #define SERIAL_DEVICE_RAW  3 /* raw device */
40 #define SERIAL_DEVICE_VIRT 4 /* non-tde drive/image */
41 
42 struct cbmdos_cmd_parse_s;
43 struct disk_image_s;
44 struct trap_s;
45 struct vdrive_s;
46 
47 typedef struct serial_s {
48     int inuse;
49     int isopen[16]; /* isopen flag for each secondary address */
50     struct disk_image_s *image; /* pointer to the disk image data  */
51     char *name; /* name of the device */
52     int (*getf)(struct vdrive_s *, uint8_t *, unsigned int);
53     int (*putf)(struct vdrive_s *, uint8_t, unsigned int);
54     int (*openf)(struct vdrive_s *, const uint8_t *, unsigned int, unsigned int,
55                  struct cbmdos_cmd_parse_s *cmd_parse_ext);
56     int (*closef)(struct vdrive_s *, unsigned int);
57     void (*flushf)(struct vdrive_s *, unsigned int);
58     void (*listenf)(struct vdrive_s *, unsigned int);
59     uint8_t nextbyte[16]; /* next byte to send, per sec. addr. */
60     char nextok[16]; /* flag if nextbyte is valid */
61 
62     int nextst[16];
63     unsigned int device;
64 
65     /* The PET hardware emulation can be interrupted while
66        transferring a byte. Thus we also have to save the byte
67        and status last sent, to be able to send it again. */
68     uint8_t lastbyte[16];
69     char lastok[16];
70     int lastst[16];
71 } serial_t;
72 
73 #define ISOPEN_CLOSED		0
74 #define ISOPEN_AWAITING_NAME	1
75 #define ISOPEN_OPEN		2
76 
77 extern int serial_init(const struct trap_s *trap_list);
78 extern int serial_resources_init(void);
79 extern int serial_cmdline_options_init(void);
80 extern void serial_shutdown(void);
81 extern int serial_install_traps(void);
82 extern int serial_remove_traps(void);
83 
84 extern void serial_trap_init(uint16_t tmpin);
85 extern int serial_trap_attention(void);
86 extern int serial_trap_send(void);
87 extern int serial_trap_receive(void);
88 extern int serial_trap_ready(void);
89 extern void serial_traps_reset(void);
90 extern void serial_trap_eof_callback_set(void (*func)(void));
91 extern void serial_trap_attention_callback_set(void (*func)(void));
92 extern void serial_trap_truedrive_set(unsigned int flag);
93 
94 extern int serial_realdevice_enable(void);
95 extern void serial_realdevice_disable(void);
96 
97 extern int serial_iec_lib_directory(unsigned int unit, const char *pattern,
98                                     uint8_t **buf);
99 extern int serial_iec_lib_read_sector(unsigned int unit, unsigned int track,
100                                       unsigned int sector, uint8_t *buf);
101 extern int serial_iec_lib_write_sector(unsigned int unit, unsigned int track,
102                                        unsigned int sector, uint8_t *buf);
103 
104 extern serial_t *serial_device_get(unsigned int unit);
105 extern unsigned int serial_device_type_get(unsigned int unit);
106 extern void serial_device_type_set(unsigned int type, unsigned int unit);
107 
108 extern void serial_iec_device_set_machine_parameter(long cycles_per_sec);
109 extern void serial_iec_device_exec(CLOCK clk_value);
110 
111 extern void serial_iec_bus_init(void);
112 
113 #endif
114