home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_26_1988_Transactor_Publishing.d64
/
cmast.c
< prev
next >
Wrap
Text File
|
2023-02-26
|
5KB
|
276 lines
/* cmast.c - main for cmaster */
/* W Mat Waites - Sept 1988 */
#include <stdio.h>
#define DEFBAUD 1200
#define DEFDRIVE 9
/* globals */
int echo;
int baud;
int bpchar;
int stopbits;
int parity;
int ddrive;
int done;
/* main() - main program for cmast */
main(argc, argv)
unsigned argc;
char *argv[];
{SHIFT-+}
int kbchar, serchar;
int outch;
/* initialization */
done = 0;
echo = 0;
baud = DEFBAUD;
bpchar = 8;
stopbits = 1;
parity = 0; /* 0 - none */
ddrive = DEFDRIVE;
/* check for baud rate parameter */
if(argc > 1)
{SHIFT-+}
baud = atoi(argv[1]);
switch(baud)
{SHIFT-+}
case 300:
case 450:
case 1200:
break;
default:
baud = DEFBAUD;
break;
{SHIFT--}
{SHIFT--}
/* open files */
openkb();
openserial();
setserial(baud, bpchar,
stopbits, parity);
/* set colors */
setborder(15);
setbg(0);
setfg(1);
initscr();
titlescr();
sleep(2);
erase();
move(0, 0);
cursoron();
updatecursor();
/* main loop */
while(!done)
{SHIFT-+}
/* check for <C=> key */
if(chkstop())
{SHIFT-+}
cursoroff();
menu();
updatecursor();
cursoron();
{SHIFT--}
/* check keyboard */
while(charsinq() > 0 && !done)
{SHIFT-+}
kbchar = getkb();
if(kbchar >= 133 &&
kbchar <= 140)
{SHIFT-+}
/* function keys */
putfunct(kbchar);
{SHIFT--}
else
{SHIFT-+}
/* non-function keys */
if(echo) /* local echo */
{SHIFT-+}
if(isprint(kbchar) {CBM-*}{CBM-*}
iscntrl(kbchar))
{SHIFT-+}
putchar((char)kbchar);
updatecursor();
{SHIFT--}
{SHIFT--}
outch = cbmtoasc(kbchar);
if(outch)
{SHIFT-+}
putserial((char)outch);
{SHIFT--}
{SHIFT--}
{SHIFT--}
/* check serial port */
if(!done)
{SHIFT-+}
while((serchar=getserial()) >= 0)
{SHIFT-+}
/* mask to 7 bits */
serchar &= 0x7f;
switch(serchar)
{SHIFT-+}
case 7: /* BEL */
break;
case 8: /* BS */
putchar(157);
break;
case 9: /* TAB */
putchar(' ');
putchar(' ');
break;
case 10: /* LF */
putchar(17);
break;
case 12: /* FF */
erase();
break;
case 13: /* CR */
putchar(13);
putchar(145); /* move up */
break;
default:
outch=asctocbm(serchar);
if(outch)
{SHIFT-+}
putchar((char)outch);
{SHIFT--}
else /* unexpected char */
{SHIFT-+}
/*printf("[%d]", serchar);*/
/*putchar((char)serchar);*/
{SHIFT--}
break;
{SHIFT--}
updatecursor();
if(charsinq() > 0 {CBM-*}{CBM-*} chkstop())
{SHIFT-+}
break;
{SHIFT--}
{SHIFT--}
{SHIFT--}
{SHIFT--}
/* shut down */
cursoroff();
erase();
closekb();
closeserial();
move(23, 0);
{SHIFT--}
/* cmaster support routines */
/* titlescr() - initial display */
titlescr()
{SHIFT-+}
erase();
center(5, "Cmaster Terminal");
center(15, "Press <C=> for menu");
{SHIFT--}
/* cbmtoasc() - convert cbm to ascii */
cbmtoasc(cbmchar)
int cbmchar;
{SHIFT-+}
/* lower case */
if(cbmchar >= 65 && cbmchar <= 90)
{SHIFT-+}
return(cbmchar + 32);
{SHIFT--}
/* upper case */
if(cbmchar >= 193 && cbmchar <= 218)
{SHIFT-+}
return(cbmchar - 128);
{SHIFT--}
if(cbmchar == 20) /* backspace */
{SHIFT-+}
return(8);
{SHIFT--}
return(cbmchar);
{SHIFT--}
/* asctocbm() - convert ascii to cbm */
asctocbm(ascchar)
int ascchar;
{SHIFT-+}
/* upper case */
if(ascchar >= 65 && ascchar <= 90)
{SHIFT-+}
return(ascchar + 128);
{SHIFT--}
/* lower case */
if(ascchar >= 97 && ascchar <= 122)
{SHIFT-+}
return(ascchar - 32);
{SHIFT--}
if(ascchar >= 32 && ascchar <= 64)
{SHIFT-+}
return(ascchar);
{SHIFT--}
if(ascchar >= 91 && ascchar <= 95)
{SHIFT-+}
return(ascchar);
{SHIFT--}
return 0;
{SHIFT--}
/* putserstr() - put string to port */
putserstr(str)
char *str;
{SHIFT-+}
while(*str)
{SHIFT-+}
putserial((char)cbmtoasc((int)*str));
str++;
{SHIFT--}
{SHIFT--}
static char *funcstr[8] =
{SHIFT-+}
"Function Key 1\n",
"Function Key 3\n",
"Function Key 5\n",
"Function Key 7\n",
"Function Key 2\n",
"Function Key 4\n",
"Function Key 6\n",
"Function Key 8\n"
{SHIFT--};
/* putfunct() - put function key string */
putfunct(key)
int key;
{SHIFT-+}
unsigned lockey;
if(key < 133 {CBM-*}{CBM-*} key > 140)
{SHIFT-+}
return;
{SHIFT--}
lockey = key - 133;
putserstr(funcstr[lockey]);
{SHIFT--}
/* end of file */