#include #include #include #ifndef UNIX #include #include #endif #include "aplinks.h" #include "disp_ctr.h" #define RBUFLEN 256 #define SBUFLEN 256 static struct cominfo comst; static char rbuf[RBUFLEN]; static char sbuf[SBUFLEN]; int set_port_name(int argc, char *argv[], char *port_name) { int i; #ifdef UNIX strcpy(port_name, DEFAULT_PORT); for(i = 1; i < argc; i++){ if(strncmp(argv[i], "-P", 2) == 0){ strcpy(port_name, (argv[i] + 2)); } } #else strcpy(port_name, "COM1"); #endif return 0; } int open_port(char *port_name, unsigned int bps) { comst.baud = (int)(log((double)bps/75.0)/log(2.0) + 0.5); /* comst.baud = COM_B9600; */ comst.databit = COM_L8; comst.stopbit = COM_S1; comst.parity = COM_PNONE; comst.flow = COM_FNONE; comst.rbufsize = RBUFLEN; comst.rbuf = rbuf; comst.sbufsize = SBUFLEN; comst.sbuf = sbuf; return pc98cominit(&comst); } int close_port(void) { pc98comterm(); return 0; } unsigned char get_port(void) { long loop; struct combufinfo combufst; char buffer[1]; loop = 655360L; while(loop){ pc98comchkbuf(&combufst); if(combufst.rsize != 0){ pc98comrecv(buffer); return buffer[0]; } else{ loop--; } } /* displist_c_printf(6, "Time out!\n"); */ return 0; } unsigned char nowait_get_port(void) { struct combufinfo combufst; char buffer[1]; pc98comchkbuf(&combufst); if(combufst.rsize != 0){ pc98comrecv(buffer); return buffer[0]; } else{ /* displist_c_printf(6, "Time out!\n"); */ return 0; } return 0; } int put_port(unsigned char data) { long loop; struct combufinfo combufst; loop = 65536L; while(loop){ pc98comchkbuf(&combufst); if(combufst.ssize == 0){ pc98comsend(data); return 0; } else{ loop--; } } displist_c_printf(6, "Time out!\n"); return -1; #if 0 for(l = 0; l < 655360L; l++){ comst.buffer = (void far *)rxbuf; while(1){ if(_bios_serialcom(_COM_STATUS, _COM_CH1, &comst) == 0){ break; } } if(((rxbuf[0] & 0x05) == 0x05) && ((rxbuf[1] & 0x40) == 0)){ rxbuf[0] = data; rxbuf[1] = '\0'; comst.buffer = (void far *)rxbuf; while(1){ if(_bios_serialcom(_COM_SEND, _COM_CH1, &comst) == 0){ break; } } while(1){ while(1){ if(_bios_serialcom(_COM_STATUS, _COM_CH1, &comst) == 0){ break; } } if((rxbuf[0] & 0x05) == 0x05){ return 0; } } /* displist_c_printf(5, "%x ", rxbuf[1]); */ /* return 0; } */ } } displist_c_printf(-1, "put_port Time out!"); return -1; #endif } int put_sector(unsigned char *buffer[], unsigned int sector) { int i; unsigned char port_buffer[SECTOR_SIZE + 2]; int retval; if(buffer[sector] != NULL){ memcpy(port_buffer, buffer[sector], SECTOR_SIZE); if(buffer[sector + 1] != NULL){ port_buffer[SECTOR_SIZE] = *(buffer[sector + 1]); retval = 0; } else{ port_buffer[SECTOR_SIZE] = 0x00; retval = 0; } } else{ bell(); for(i = 0; i <= SECTOR_SIZE; i++){ port_buffer[i] = 0x00; } retval = -1; } for(i = 0; i <= SECTOR_SIZE; i++){ put_port(port_buffer[i]); } return retval; } int get_sector(unsigned char *buffer[], unsigned int sector) { unsigned char port_buffer[SECTOR_SIZE + 3]; int i; int retval; for(i = 0; i < SECTOR_SIZE + 2; i++){ port_buffer[i] = get_port(); } retval = 0; if(port_buffer[SECTOR_SIZE + 1] == 0xff){ if(buffer[sector] != NULL){ memcpy(buffer[sector], port_buffer, SECTOR_SIZE); } else{ bell(); retval = -1; } if(buffer[sector + 1] != NULL){ *(buffer[sector + 1]) = port_buffer[SECTOR_SIZE]; } else{ bell(); retval = -1; } } put_port(0); return retval; }