?? get_a_re.c
字號:
#include <fcntl.h>
#include <conio.h>
#include <stdio.h>
#include <io.h>
#include <dos.h>
#include <graphics.h>
#include <key.inc>
#include <bio.inc>
#include <menu.inc>
#include "feedef.h"
#include <bios.h>
#include <alloc.h>
void interrupt far (*old_com1)(void);
void interrupt far (*old_com2)(void);
/* function : initialize the SIO port address, according to COM1 or COM2
* called by : take_all_record()
* date : 1993.9.24
*/
void InitPortAdd(void)
{
int i;
SIO_INT[0] = 0xc; /* interrupt vector of COM1 */
SIO_DATA[0] = 0x3f8; /* data port address of COM1 */
SIO_INT[1] = 0xb; /* interrupt vector of COM2 */
SIO_DATA[1] = 0x2f8; /* data port address of COM2 */
for(i=0; i<2; i++) {
SIO_IER[i] = SIO_DATA[i]+1; /* interrupt enable register */
SIO_IIR[i] = SIO_DATA[i]+2; /* interrupt identification register */
SIO_LCR[i] = SIO_DATA[i]+3; /* line control register */
SIO_MCR[i] = SIO_DATA[i]+4; /* modem control register */
SIO_LSR[i] = SIO_DATA[i]+5; /* line status register */
SIO_MSR[i] = SIO_DATA[i]+6; /* modem status register */
}
}
/* function : new interrupt serve program
* called by : SIOInit()
* date : 1993.9.25
*/
void far interrupt new_com1(void)
{
new_com(0);
}
void far interrupt new_com2(void)
{
new_com(1);
}
void new_com(UC port)
{
UC status;
while((status = inportb(SIO_IIR[port])&0x07) != 1) /* have interrupt */
{
disable(); /* disable further interrupt come in */
switch(status)
{
case 6: /* receiving line error */
inportb(SIO_LSR[port]);
break;
case 4: /* have received valid data */
SIORecInt(port);
break;
case 2: /* sending buffer is empty */
inportb(SIO_IIR[port]);
break;
case 0: /* modem interrupt */
inportb(SIO_MSR[port]);
break;
default:
break;
}
outportb(0x20,0x20); /* tell 8259 this is end of interupt*/
enable();
}
return;
}
/* function : data receiving handle
* called by : new_com()
* date : 1993.9.25
*/
void SIORecInt(UC port) /*receive data*/
{
UC ch;
ch = SIORecBuf[port][SIORecTail[port]++] = inportb(SIO_DATA[port]);
if(DEBUG)
{
int i;
UC str[4];
union REGS inregs, outregs;
sprintf(str, "#%02x", ch);
for(i=0; i<3; i++)
{
// show the character
inregs.h.ah = 0x09;
inregs.h.al = str[i];
inregs.h.bh = 0;
inregs.h.bl = 7; // character color
inregs.x.cx = 1;
int86(0x10, &inregs, &outregs);
// get the cursor position
inregs.h.ah = 0x03;
inregs.h.bh = 0;
int86(0x10, &inregs, &outregs);
// set the curosr positon
inregs.h.ah = 0x02;
if(outregs.h.dl == 79) // last one
{
inregs.h.dh = outregs.h.dh + 1; // the next row
inregs.h.dl = 0;
}
else
{
inregs.h.dh = outregs.h.dh; // the same row
inregs.h.dl = outregs.h.dl + 1;
}
inregs.h.bl = 0; // page
int86(0x10, &inregs, &outregs);
}
}
if( (ch==0xfd) || (ch==0xfc) || (ch==0xb4) || (ch==0xb7) || (ch==0xb8) )
CmdCount[port]++;
if(SIORecTail[port] >= SIO_BUF_SIZE)
SIORecTail[port] -= SIO_BUF_SIZE;
return;
}
/* function : send a char to SIO port, that is,send data to Exchanger
* date : 1993.9.25
*/
void ToCPU(UC port, UC ch)
{
if(DEBUG)
printf("%02x",ch);
if(port == 0 || port == 1) {
while(!(inportb(SIO_LSR[port]) & 0x20)); /* THR is not empty */
outportb(SIO_DATA[port],ch);
}
else
comtxch(IRQNO,port-2,ch);
delay(15); /* delay 15 ms */
return;
}
/* function : initialize Port address, set Baud rate, preserve the
* old INT vector, and set the new one
* date : 1993.9.25
*/
void SIOInit(void)
{
int i,j;
InitPortAdd();
for(j=0; j<2; j++) {
outportb(SIO_LCR[j],0x83); /* Access Divisor Latch */
outportb(SIO_DATA[j],0x30); /* 2400 Baud Rate */
outportb(SIO_IER[j],0); /* disable interrupt of UART */
outportb(SIO_LCR[j],0x03); /* set 3-bits data len */
}
disable();
old_com1 = getvect(SIO_INT[0]); /* preserve the old interrupt vector */
setvect(SIO_INT[0],new_com1); /* and set the new one */
old_com2 = getvect(SIO_INT[1]); /* preserve the old interrupt vector */
setvect(SIO_INT[1],new_com2); /* and set the new one */
for(j=0; j<2; j++) {
outportb(SIO_IER[j],0x1); /* Enable Receive Int */
outportb(SIO_MCR[j],0xb); /* must be set if want interruption */
}
/* in 8259A interrupt mask regiter(0x21), if bit is set, then the
* corresponding interrupt is disable. COM1(IRQ4) and COM2(IRQ3)
* interrupts are bit 4 and bit 3, so set them to 0 to enable
* interrupt
*/
outportb(0x21, inportb(0x21)&0xe7);
for(j=0; j<2; j++) {
for(i = 0; i < 100; i++)
{
inportb(SIO_DATA[j]);
inportb(SIO_LSR[j]);
inportb(SIO_MSR[j]);
inportb(SIO_IIR[j]);
}
}
for(j=0; j<PORT_NUM; j++) {
SIORecTail[j] = SIORecHead[j] = 0;
CmdCount[j] = 0;
}
TRCount = ERRCount = ErrCount = 0;
enable();
return;
}
/* function : set back the interrupt vector to the original one
* called by : take_all_record()
* date : 1993.9.25
*/
void SIOEnd(void)
{
setvect(SIO_INT[0],old_com1); /* and set the new one */
setvect(SIO_INT[1],old_com2); /* and set the new one */
return;
}
/* function : take all telephone records from Exchanger
* called by : phone_record_proc() (record.c)
* output : 0 -- unsuccessful in receiving
* 1 -- successful in receiving
* procedure : (1) connect with Exchanger
* (2) take all the telephone records to pabx.dat, and inform
* Exchanger to clear the record buffer
* (3) transfer the records to idd.dbf, ddd.dbf and
* ldd.dbf
* (4) remove pabx.dat
* date : 1993.9.25
*/
UC take_all_record(void)
{
UC suc;
int handle;
UL len1,len2;
FILE *fp;
UC port;
check_dat_tmp();
handle = open("pabx.chg",O_RDONLY|O_BINARY);
if(handle != -1) /* the file exists, then transfer again */
{
len1 = filelength(handle);
close(handle);
if(len1 != -1)
{
fp = fopen("pabx.lth","rb"); /* length file of pabx.chg */
if(fp != NULL)
{
if(fread(&len2,sizeof(UL),1,fp)==1)
{
fclose(fp);
if(len1 == len2)
{
message_disp(8,"正在分揀, 請稍候...");
all_record_transfer();
message_end();
tmp_to_dat();
remove("pabx.chg");
remove("pabx.lth");
if(Cashflg[PHONE_CASH])
overflow_cash(INQUIRE, PHONE_CASH,1,1); /* in overcash.c */
if(Cashflg[AUTH_CASH])
overflow_cash(INQUIRE, AUTH_CASH,1,1); /* in overcash.c */
} /* if(len1 == len2) */
} /* if(fread(&len2,sizeof(UL),1,fp)==1) */
} /* if(fp != NULL) */
remove("pabx.chg");
} /* if(len1 != -1) */
} /* if(handle != -1) */
pop_back(H_BX,H_BY,H_BX+3*H_XAD,H_BY+2*H_YAD,LIGHTGRAY);
for(port=0; port<PORT_NUM; port++) {
if(!Sys_mode.com_m[port]) continue;
suc = ConnTermAndCPU(port); /* connect with Exchanger */
if(suc != 1) /* not successful */
{
rid_pop();
return(suc);
}
}
suc = take_record();
if(suc == 1) /* successful */
{
if(TRCount != 0) /* backup */
tmp_to_dat();
remove("pabx.chg");
remove("pabx.lth");
if(Cashflg[PHONE_CASH])
overflow_cash(INQUIRE, PHONE_CASH, 1, 1); /* in overcash.c */
if(Cashflg[AUTH_CASH])
overflow_cash(INQUIRE, AUTH_CASH, 1, 1); /* in overcash.c */
}
rid_pop();
return(suc);
}
/* function : check whether *.dat and *.tmp are the same, if not the same,
* copy *.dat to *.tmp
* called by : take_all_record()
* date : 1993.10.18
*/
void check_dat_tmp(void)
{
int k;
long buff1,buff2;
if ((k=open("idd.tmp",O_RDONLY|O_BINARY)) != -1)
{
buff1 = filelength(k);
close(k);
if((k=open("idd.dbf",O_RDONLY|O_BINARY)) != -1)
{
buff2 = filelength(k);
close(k);
if((buff1 != buff2) && (buff2 != 0))
fcopy("idd.dbf","idd.tmp");
}
}
if ((k=open("ddd.tmp",O_RDONLY|O_BINARY)) != -1)
{
buff1 = filelength(k);
close(k);
if((k=open("ddd.dat",O_RDONLY|O_BINARY)) != -1)
{
buff2 = filelength(k);
close(k);
if((buff1 != buff2) && (buff2 != 0))
fcopy("ddd.dat","ddd.tmp");
}
}
if ((k=open("ldd.tmp",O_RDONLY|O_BINARY)) != -1)
{
buff1 = filelength(k);
close(k);
if((k=open("ldd.dbf",O_RDONLY|O_BINARY)) != -1)
{
buff2 = filelength(k);
close(k);
if((buff1 != buff2) && (buff2 != 0))
fcopy("ldd.dbf","ldd.tmp");
}
}
return;
}
/* function : connect with Exchanger
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -