p p p p . p p p , "r" "s" p. "s" p p ; "r" p ( p ) .

_________________________________________________________________

""

------ ------

| | ---------------- | |

---------- ----------

---------- ----------

| |

| |

------ ------

| | ---------------- | |

---------- ----------

---------- ----------

_________________________________________________________________

""

------



| |

----------

----------

|

|

------ | ------

| | ---------- ---------- | |

---------- Р ----------

---------- | ----------

|

|

------

| |

----------

----------

. 6.1. p .

p pp蠠 p pp,

p p ,

頠 𠠠 , ࠠ 젠

p p


p p .

p p

pp p p .

p p . pp, p, p p p p ( ).

main()

printf(" ./n");

printf(" ./n/n");

port_init(PORT); /* p */

do

/* p p */

if(check_stat(PORT)&256)

switch(rport(PORT))

case 's': send_file(PORT);

break;

case 'r': rec_file(PORT);

break;

/*************************************

p p p p p ...

if(check_stat(PORT1)&256) switch(rport(PORT1))

case 's': send_file(PORT1);

break;

case 'r': rec_file(PORT1);

break;

.

.

.

if(check_stat(PORTn)&256)

switch(rport(PORTn))

case 's': send_file(PORTn);

break;

case 'r': rec_file(PORTn);

break;

******************************************/

while(!kbhit());

, p p ( ), , p, p p N . , p p, pp p. p p p p/ .

, send_file() rec_file() p p p, p p p. p p p. p p p p . send_file() rec_file() p p .



/* p p p p

*/

void send_file(port)

int port;

FILE *fp;

char ch, fname[14];

union

char c[2];

unsigned int count;

cnt;

sport(port, '.'); /* p */

get_file_name(fname, PORT);

if(!(fp=fopen(fname,"rb")))

printf(" p\n");

exit(1);

if(rport(port)!='.')

printf(" p p \n");

exit(1);

printf("p %s\n", fname);

/* p pp */

cnt.count = filesize(fp);

/* p pp */

sport(port, cnt.c[0]);

wait(port);

sport(port, cnt.c[1]);

do

ch = getc(fp);

if(ferror(fp))

printf(" \n");

break;

/* */

if(!feof(fp))

wait(port);

sport(port, ch);

while(!feof(fp));

wait(port); /* p p*/

fclose(fp);

/* p p*/

void rec_file(port)

int port;

FILE *fp;

char ch, fname[14];

union

char c[2];

unsigned int count;

cnt;

sport(port, '.'); /* p */

get_file_name(fname, PORT);

printf(" %s\n", fname);

remove(fname);

if(!(fp=fopen(fname,"wb")))

printf(" p\n");

exit(1);

/* */

sport(port, '.');

cnt.c[0] = rport(port);

sport(port, '.');

cnt.c[1] = rport(port);

sport(port, '.');

for(; cnt.count; cnt.count--)

ch = rport(port);

putc(ch, fp);

if(ferror(fp))



printf(" p \n");

exit(1);

sport(port, '.');

fclose(fp);



pp, p , p . pp p 0. , , pp pp ( . p ) p p .



/* p . pp p:

p p - 9600 ,

p 蠠 . ,

,

p -.

*/

#define PORT 0

#include "dos.h"

#include "stdio.h"

unsigned int filesize();

void sport(), send_file(), rec_file(), send_file_name();

void get_file_name(), port_init(), wait();

main()

printf(" .\n");

printf(" ./n/n");

port_init(PORT); /* p */

do

/* p p */

if(check_stat(PORT)&256)

switch(rport(PORT))

case 's': send_file(PORT);

break;

case 'r': rec_file(PORT);

break;

/*****************************************

p p p . p,

p ...

if(check_stat(PORT1)&256)

switch(rport(PORT1))

case 's': send_file(PORT1);

break;

case 'r': rec_file(PORT1);

break;

.

.

.

if(check_stat(PORTn)&256)

switch(rport(PORTn))

case 's': send_file(PORTn);

break;

case 'r': rec_file(PORTn);

break;

******************************************/

while(!kbhit());

/* p p p p */

void send_file(port)

int port;

FILE *fp;

char ch, fname[14];

union

char c[2];

unsigned int count;

cnt;

sport(port, '.'); /* p */

get_file_name(fname, PORT);

if(!(fp=fopen(fname,"rb")))

printf(" p\n");

exit(1);

if(rport(port)!='.')

printf(" p p \n");

exit(1);

printf("p %s\n", fname);

/* p pp */

cnt.count = filesize(fp);

/* p pp */

sport(port, cnt.c[0]);

wait(port);

sport(port, cnt.c[1]);

do

ch = getc(fp);

if(ferror(fp))

printf(" \n");



break;

/* */

if(!feof(fp))

wait(port);

sport(port, ch);

while(!feof(fp));

wait(port); /* p p*/ fclose(fp);

/*p p p p.*/

void rec_file(port)

int port;

FILE *fp;

char ch, fname[14];

union

char c[2];

unsigned int count;

cnt;

sport(port, '.'); /* p */

get_file_name(fname, PORT);

printf(" %s\n", fname);

remove(fname);

if(!(fp=fopen(fname,"wb")))

printf(" p\n");

exit(1);

/* */

sport(port, '.');

cnt.c[0] = rport(port);

sport(port, '.');

cnt.c[1] = rport(port);

sport(port, '.');

for(; cnt.count; cnt.count--)

ch = rport(port);

putc(ch, fp);

if(ferror(fp))

printf(" p \n");

exit(1);

sport(port, '.');

fclose(fp);

/* p */

unsigned int filesize(fp)

FILE *fp;

unsigned long int i;

i = 0;

do

getc(fp);

i++;

while(!feof(fp));

rewind(fp);

return (i-1); /* EOF */

/* p */

void send_file_name(f, port)

char *f;

int port;

do

sport(port, '?');

while(!kbhit() && !(check_stat(port)&256));

if(kbhit())

getch();

exit(1);

wait(port);

while(*f)

sport(port, *f++);

wait(port); /* p */

sport(port, 0); /* p */

/* */

void get_file_name(f, port)

char *f;

int port;

while(rport(port)!='?') printf(".");

sport(port, '.');

while((*f=rport(port)))

if(*f!='?')

f++;

sport(port, '.');

sport(port, '.');

/* */

void wait(port)

int port;

if(rport(port)!='.')

printf(" \n");

exit(1);

/* p p */



void sport(port, c)

int port; /* p / */

char c; /* p */

union REGS r;

r.x.dx = port; /* p */

r.h.al = c; /* p */

r.h.ah = 1; /* p */

int86(0x14, &r, &r);

if(r.h.ah & 128) /* p 7- */

printf("p p p "); printf("%d",r.h.ah);

exit(1);

/* p */

rport(port)

int port; /* p / */

union REGS r;

/* p */

while(!(check_stat(port)&256))

if(kbhit()) /* pp p */

getch();

exit(1);

r.x.dx = port; /* p */

r.h.ah = 2; /* */

int86(0x14, &r, &r);

if(r.h.ah & 128)

printf(" p p ");

return r.h.al;

/* pp p */

check_stat(port)

int port; /* p / */

union REGS r;

r.x.dx = port; /* p */

r.h.ah = 3; /* */

int86(0x14, &r, &r);

return r.x.ax;

/* p pp:

p p 9600 , -,

p ., 8 .

*/

void port_init(port)

int port;

union REGS r;

r.x.dx = port; /* p */

r.h.ah = 0; /* p*/

r.h.al = 231; /* - . */

int86(0x14, &r, &r);