]> icculus.org git repositories - btb/d2x.git/blob - arch/dos/include/dzcomm.h
Removed automake stuff from "inert" subdirs. And there was much rejoicing.
[btb/d2x.git] / arch / dos / include / dzcomm.h
1 /*
2  * DZcomm : serial communication add-on for Allegro.
3  * Copyright (c) 1997 Dim Zegebart, Moscow Russia.
4  * zager@post.comstar.ru
5  * file : dzcomm.h
6  * version : 0.6
7  */
8
9 //#x# are marks for automatic documentator and may be ignored by human reader.
10 //#d# function description
11 //#v# returned values
12 //#c# any comments, notes, etc.
13 //#n# exclude line from documentation
14 //#sb# begin structure. Type structure name (if any) after this tag.
15 //#ds# in structure description means what field maintained by system.
16 //#se# end structure
17 //#p# parameters list
18 //#dv# variable description
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #define not_commented(_s_) ((_s_)[-1]!='/'&&(_s_)[-2]!='/')
25
26 //-------------------------- SOME DECODERS --------------------------
27
28 #define scan_(_key_)  ({((_key_)>>8)&0xff;}) //#d#extract scan part
29 #define ascii_(_key_) ({(_key_)&0xff;})//#d#extract ascii part
30 #define key_shifts_(_key_) ({((_key_)>>16)&0xff;})//#d#extract shifts keys status
31
32 #define data_(_comm_data_) ({(_comm_data_)&0xff;}) //#d#extract data unsigned char
33 #define q_reg_(_comm_data_) ({((_comm_data_)>>16)&0xff;}) //#d#extract status registers unsigned char
34
35 //#d#Determine if Ctrl-... pressed
36 //#v# 1 - if yes. For example if(ctrl_,'C') {exit(1);}
37 //0 - if not
38 #define ctrl_(_key_,c)\
39 ({((key_shifts&KB_CTRL_FLAG)&&((ascii_(_key_)+'A'-1)==(c)));})
40
41 //----------------------------- FIFO QUEUE ------------------------
42 //#sb# First In First Out queue
43 typedef struct
44 { unsigned int size;  //size of queue. Use queue_resize(new_size) to change queue size
45   unsigned int dsize; //size of data element (default 4 unsigned chars)
46   unsigned int initial_size;
47   unsigned int resize_counter;
48   unsigned int fill_level;
49   int (*empty_handler)();
50   void *queue;     //pointer to queue. Points to int[], where actual data stored.
51   unsigned int head,tail;  //number of head and tail elements
52                    //head points to the first element in queue
53                    //tail points to the first element next to last
54                    //element in queue. (For example : we have ten elements
55                    //in queue, then head==0, tail==10
56 } fifo_queue;
57 //#se#
58 fifo_queue* queue_new(unsigned int size); //#d#Allocate storage space for new fifo_queue.
59 fifo_queue* queue_new_(unsigned int size,unsigned int dsize);
60 //#v# NULL if failed
61 // pointer to newly created fifo_queue structure
62 void queue_delete(fifo_queue *q); //#d#Delete queue description and free occuped space.
63 inline void queue_reset(fifo_queue *q);//#d#Set head and tail to zero (data not lost).
64 int queue_resize(fifo_queue *q,unsigned int new_size); //#d#Increase(decrease) storage space
65 //for fifo queue.
66 //#v# 0 if failed
67 //1 if success
68 inline int queue_put(fifo_queue *q,int c); //#d#Put value into given queue.
69 inline int queue_get(fifo_queue *q); //#d#Get values from queue.
70 inline int queue_put_(fifo_queue *q,void *data);
71 inline int queue_get_(fifo_queue *q,void *data);
72
73 //#v# Byte from queue's head
74 //#c# Use queue_empty befor calling queue_get. queue_get don't test
75 // queue's head and tail, just return queue[head].
76 inline int queue_empty(fifo_queue *q);//#d#Test queue for emptyness.
77 //#v# 1 if empty (head==tail)
78 // 0 if not empty (head!=tail)
79 //#c# Call this function before any queue_get calling
80
81 //---------------------------- COMM_PORT --------------------------
82
83 typedef enum {_com1,_com2,_com3,_com4,_com5,_com6,_com7,_com8} comm;
84 typedef enum {BITS_8=0x03,BITS_7=0x02,BITS_6=0x01,BITS_5=0x00} data_bits;
85 typedef enum {STOP_1=0x00,STOP_2=0x01} stop_bits;
86 typedef enum {EVEN_PARITY=0x03,ODD_PARITY=0x01,NO_PARITY=0x00} parity_bits;
87 typedef enum {_110=110,_150=150,_300=300,_600=600,
88               _1200=1200,_2400=2400,_4800=4800,
89               _9600=9600,_19200=19200,_38400=38400,
90               _57600=57600,_115200=115200} baud_bits;
91 //typedef enum {DTR_ON=0xFD,RTS_ON=0xFE,DTR_OFF=~0x1,RTS_OFF=~0x2} hand;
92 typedef enum {CTS_ON=0x01,CTS_OFF=0x0,RTS_ON=0x1,RTS_OFF=0x0} hand;
93 typedef enum {XON_RCVD=1,XON_SENT=1,XOFF_RCVD=0,XOFF_SENT=0} xon_xoff_status;
94 typedef enum {NO_CONTROL=1,XON_XOFF=2,RTS_CTS=3} flow_control_type;
95 typedef enum {XON_ASCII=0x11,XOFF_ASCII=0x13} control_char;
96
97 extern char szDZCommErr[50];
98
99 typedef enum {DATA_BYTE=1,MSR_BYTE=2,LSR_BYTE=4} comm_status_byte;
100
101 //#sb#Comm port.
102 typedef struct tag_comm_port
103 { //general parametrs
104 //You may alter this six  fields after comm_port_new() where defaults values are set.
105   char szName[255]; //#d#name of comm port. For example : MODEM
106   comm  nComm; //#d#comm port number
107   unsigned short nPort; //#d#comm port address
108   unsigned char  nIRQ; //#d#comm IRQ
109   unsigned short nIRQVector; //#d#number of software interrupt vector.
110   flow_control_type control_type; //default XON_XOFF
111
112   unsigned char xon;
113   unsigned char xoff;
114   unsigned char xonxoff_send;
115   unsigned char xonxoff_rcvd;
116   unsigned char rts;
117   unsigned char cts;
118
119  //next two fields are for unsigned char counting
120   unsigned int in_cnt; //counter for input data
121   unsigned int out_cnt; //counter for output data
122
123   unsigned char  interrupt_enable_mask; //#ds#
124   int (*comm_handler)(); //#d#pointer to short function see below
125   int (*msr_handler)(); //#d#pointer to modem status register handler.
126   int (*lsr_handler)(); //#d#pointer to line status register handler.
127 // template to comm's interrupt handler
128 //comm_port *your_comm,*your_comm1; //must be declared globaly
129 //int foo_comm_wrapper(void)
130 //{ dz_comm_interrupt_handler(ptr_your_comm);
131 //  return(0);
132 //}
133
134   enum {YES,NO} installed; //#ds#
135
136   //communication parametrs
137   baud_bits   nBaud;   //#d#baud rate
138   data_bits   nData;   //#d#data length
139   stop_bits   nStop;   //#d#stop bits
140   parity_bits nParity; //#d#parity
141
142   //input and output queue
143   fifo_queue *InBuf; //#ds#pointer to read buffer
144   fifo_queue *OutBuf; //#ds#pointer to write buffer
145
146   unsigned short THR;  //#ds# Transmitter Holding Register */
147   unsigned short RDR;  //#ds# Reciever Data Register */
148   unsigned short BRDL; //#ds#Baud Rate Divisor, Low unsigned short */
149   unsigned short BRDH; //#ds# Baud Rate Divisor, High Byte */
150   unsigned short IER;  //#ds# Interupt Enable Register */
151   unsigned short IIR;  //#ds# Interupt Identification Register */
152   unsigned short FCR;  //#ds# FIFO Control Register */
153   unsigned short LCR;  //#ds# Line Control Register */
154   unsigned short MCR;  //#ds# Modem Control Register */
155   unsigned short LSR;  //#ds# Line Status Register */
156   unsigned short MSR;  //#ds# Modem Status Register */
157   unsigned short SCR;  //#ds# SCR Register */
158   unsigned short ISR_8259; //#ds#interrupt service register
159   unsigned short IMR_8259; //#ds#interrupt mask register
160
161   int fifo; // 1 if 16550 FIFO enabled
162
163   void *next_port;
164   void *last_port;
165 } comm_port;
166 #define cport_(_p_) ({(comm_port*)(_p_);})
167 //#se#
168 extern char szDZCommErr[50];
169 comm_port *comm_port_init(comm com);
170 int comm_port_install_handler(comm_port *port);
171 inline void comm_port_out(comm_port *port,unsigned char c);
172 inline int comm_port_test(comm_port *port);
173 inline int dz_comm_port_interrupt_handler(comm_port *port);
174 void comm_port_delete(comm_port *port);
175 void comm_port_string_send(comm_port *port,char *s);
176 void comm_port_command_send(comm_port *port,char *s);
177 void comm_port_break_send(comm_port *port);
178 void comm_port_hand(comm_port *port,int m);
179 int comm_port_load_settings(comm_port *port,char *ini_name);
180 inline int comm_port_send_xoff(comm_port *port);
181 inline int comm_port_send_xon(comm_port *port);
182 int comm_port_reinsatall(comm_port *port);
183 void modem_hangup(comm_port *port);
184 void dzcomm_init(void);
185 void print_bin_s(int c,char *s);
186
187 extern comm_port *com1;
188 extern comm_port *com2;
189 extern comm_port *com3;
190 extern comm_port *com4;
191 extern comm_port *com5;
192 extern comm_port *com6;
193 extern comm_port *com7;
194 extern comm_port *com8;
195
196 #define LSR_DATAREADY  1
197 #define LSR_OVERRUN    2
198 #define LSR_PARITYERR  4
199 #define LSR_FRAMINGERR 8
200 #define LSR_BREAK      16
201 #define LSR_THRE       32  /* transmitter holding register empty */
202 #define LSR_TSRE       64  /* transmitter shift register empty */
203 #define LSR_FIFOERR    128 /* 16550 PE/FE/Break in FIFO queue, 0 for 8250 & 16450 */
204
205 #define MSR_DCTS       1
206 #define MSR_DRTS       2
207 #define MSR_DRI        4
208 #define MSR_DDCD       8
209 #define MSR_CTS        16
210 #define MSR_RTS        32
211 #define MSR_RI        64
212 #define MSR_DCD        128
213
214
215 #ifdef __cplusplus
216 } //end extern "C"
217 #endif
218
219
220