home *** CD-ROM | disk | FTP | other *** search
- /////////////
- /////////////
- //// This program is intended to get you started using the ASYNC
- //// library. MYPROG is just a simple little dumb (stupid, actually)
- //// terminal emulator. It doesn't process ANSI codes, so, depending on
- //// what you talk to, you may seem some strange characters from time to
- //// time.
- ////
- //// The first thing to do is to make sure that ASYNCS.LIB (assuming
- //// that you'll be using the small memory model) and ASYNC.H are in
- //// your LIB and INCLUDE directories, respectively. Use CREASYNC.BAT to
- //// create the ASYNCx.LIB files if you haven't already done so.
- ////
- //// To compile MYPROG.C, just issue the command
- ////
- //// tcc -ms myprog asyncs.lib
- ////
- //// This will compile MYPROG.C and link it with the functions it needs
- //// from ASYNCS.LIB to produce the executable file MYPROG.EXE.
- ////
- //// This program was originally intended to talk to a 2400 baud modem
- //// using no parity, 8 data bits, and 1 stop bit. Change the parameters
- //// to a_open in main() if you want to change these communication
- //// parameters.
- /////////////
- /////////////
-
- #include <bios.h>
- #include <conio.h>
- #include <dos.h>
- #include <string.h>
-
- #include <async.h>
-
- void dumbterm(ASYNC *port);
-
- int main(void)
- {ASYNC *com2;
- //
- // Open COM2 at 2400 buad for no parity, 8 data bits, 1 stop bit, using
- // a 4096-byte input buffer and no output buffer.
- //
- com2=a_open(2,2400,PAR_NONE,8,1,4096,0);
- if (!com2)
- {cputs("Cannot open COM2.\r\n");
- return 1;
- }
- //
- // Start the dumb terminal emulator.
- //
- dumbterm(com2);
- //
- // Close COM2. (Never forget to do this.)
- //
- a_close(com2,0);
- return 0;
- } // end of void main().
-
- void dumbterm(ASYNC *port)
- {int ch,x,y;
- //
- // Give the user some last-minute instructions.
- //
- textattr(7);
- cputs("Your in terminal mode now. To return to DOS, press ALT-X.\r\n");
- textattr(2);
- //
- // Keep acting like a terminal until Alt-X is pressed.
- //
- do
- {// If a key has been pressed, read it from the keyboard.
- if (bioskey(1))
- ch=bioskey(0);
- else
- ch=0;
- // If Alt-X was pressed, leave this loop.
- if (ch==0x2d00)
- break;
- // If a key was pressed, the scan code off of ch and transmit it.
- ch&=0xff;
- if (ch)
- a_putc(ch,port);
-
- // If a character has been received, display it.
- ch=a_getc(port);
- if (ch!=-1)
- switch(ch)
- {case 0: // Ignore null characters.
- break;
- case 7: // Beep for bell characters.
- sound(2000);
- delay(50);
- nosound();
- delay(25);
- case 8: // Do back spaces manually.
- x=wherex()-1;
- y=wherey();
- if (x<1)
- {x=80;
- y--;
- if (y<1)
- x=y=1;
- }
- gotoxy(x,y);
- putch(' ');
- gotoxy(x,y);
- break;
- case '\n': // Ignore linefeeds.
- break;
- case '\r': // Treat carriage returns as carriage return/line feeds.
- cputs("\r\n");
- break;
- default:
- putch(ch);
- }
- }
- while(1);
- } // end of dumbterm(port).
-