home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / BDSC / BDSC-4 / TINIT.C < prev    next >
Text File  |  2000-06-30  |  8KB  |  279 lines

  1. /*  Terminal Initialization for TVI 950 by Richard Conn
  2.  
  3.     The purpose of this program is to quickly initialize the TVI 950
  4.     to a desired state.  Only a file name is allowed, and this program
  5.     has to be reassembled in order to change the initialization
  6.     parameters.
  7. */
  8.  
  9. #define    version    11    /* Version Number */
  10.  
  11. /* Header File */
  12. #include    "a:bdscio.h"
  13.  
  14. /*  File Name and Mode Strings  */
  15. #define    configfile    "STD.CFG"        /* File Name */
  16. #define    configtype    ".CFG"            /* Data File Type */
  17. #define    configmode    0            /* Read/Only */
  18.  
  19. /*  Basic Constants  */
  20. #define    strlen    100    /* Max number of chars in a string */
  21. #define    ESC    0x1b    /* Escape code */
  22. #define    CR    '\r'    /* Carriage Return */
  23. #define    BEL    0x07    /* Ring Bell */
  24. #define    CTRLH    0x08    /* Backspace Char */
  25. #define    CTRLL    0x0c    /* Cursor Back */
  26. #define    CTRLU    0x15    /* Delete Line Char */
  27. #define    CTRLX    0x18    /* Delete Line Char */
  28. #define    RUBOUT    0x7f    /* Backspace Char */
  29.  
  30. #define    FALSE    0
  31. #define    TRUE    -1
  32. #define    echo    TRUE
  33. #define    noecho    FALSE
  34. #define    YES    'Y'
  35. #define    NO    'N'
  36.  
  37. /*  Buffer Sizes  */
  38. #define    ullen    81    /*  User Line Length of ULBUFFER  */
  39. #define    tablen    80    /*  Length of TABBUFFER  */
  40. #define    fkeylen    464    /*  Length of FKEYBUFFER  */
  41.  
  42. /*  Cursor Positioning  */
  43. #define    gotoxy    '='    /* Position Cursor */
  44.  
  45. /*  Clear Screen  */
  46. #define    clear    '+'    /* Clear screen */
  47.  
  48. /*  Function Keys  */
  49. #define    fctkey    '|'    /* Begin function key definition */
  50. #define    fctend    0x19    /* Ctrl-Y for end function key definition */
  51. #define    ctrlp    0x10    /* Control-P for char ESCAPE in Fct Key cmd */
  52.  
  53. /*  User Line  */
  54. #define    loadusr    'f'    /* Load User Line */
  55. #define    dispusr    'g'    /* Display User Line */
  56. #define    dispst    'h'    /* Display Status Line */
  57.  
  58. /*  Scrolling  */
  59. #define    sscroll    '8'    /* Enable Smooth Scrolling */
  60. #define    hscroll    '9'    /* Enable Hard Scrolling (no Smooth Scrolling) */
  61.  
  62. /*  Tabs  */
  63. #define    tabclr    '3'    /* Clear All Tabs */
  64. #define    tabset    '1'    /* Set Tab at Cursor */
  65.  
  66. /*  Video  */
  67. #define    vidnorm    'd'    /* Normal (white on black) Video */
  68. #define    vidrev    'b'    /* Reverse (black on white) Video */
  69.  
  70. /*  Key Click  */
  71. #define    clkon    '>'    /* Keyclick ON */
  72. #define    clkoff    '<'    /* Keyclick OFF */
  73.  
  74. /*  Cursor Type  */
  75. #define    curs    '.'    /* Set cursor attribute */
  76.  
  77. /*  Single-char settings  */
  78. #define    cls    '+'    /* Clear Screen */
  79. #define    unlock    '"'    /* Unlock Keyboard */
  80. #define    nograph    '%'    /* Graphics Mode OFF */
  81. #define    noprot    0x27    /* Protect Mode OFF */
  82. #define    normi    '('    /* Normal Intensity */
  83. #define    notabs    '3'    /* Clear All Tabs */
  84. #define    noclick    '<'    /* Key Click OFF */
  85. #define    nocopy    'A'    /* Copy Print Mode OFF */
  86. #define    cmode    'C'    /* Conversation Mode ON (Block Mode OFF) */
  87. #define    fdx    'F'    /* Full Duplex */
  88. #define    nomonit    'X'    /* Clear Monitor Mode */
  89. #define    nobufpr    'a'    /* Buffer Print OFF */
  90. #define    vid1    'd'    /* White on Black */
  91. #define    nopage    'w'    /* Auto Page OFF */
  92.  
  93. /*  String Settings  */
  94. #define    videom    "G0"    /* Normal Video */
  95. #define    insert    "e "    /* Set Insert Char to <SP> */
  96.  
  97. char    iobuf[BUFSIZ];
  98. char    ulbuffer[ullen], tabbuffer[tablen], fkeybuffer[fkeylen];
  99. char    cursor, click, scroll, uline, video, tabs, fkeys;
  100.  
  101. main(argc,argv)
  102. int    argc;
  103. char    **argv;
  104. {
  105.     char *argstr;
  106.  
  107.     banner();  /* Print Banner */
  108.     tinit();  /* Initialize terminal */
  109.     switch (argc) {
  110.        case 1  :    readfile(configfile);  /* Program from default */
  111.             program();
  112.             break;
  113.        case 2  :    argstr = argv[1];  /* Pt to first arg */
  114.             if (*argstr == '/') help();
  115.             else {
  116.                 readfile(argstr);  /* Program from file */
  117.                 program();
  118.                 }
  119.             break;
  120.        default :    help(); break;
  121.        }
  122.     exit(TRUE);
  123. }  /* End of Mainline */
  124.  
  125. help()  /* HELP File */
  126. {
  127.     banner();  /* Print Banner */
  128.     printf("\nTerminal Initialization for TVI 950");
  129.     printf("\n\n\tThis program is invoked in one of two ways --");
  130.     printf("\n\t\tTINIT  <-- Initialize from %s File",configfile);
  131.     printf("\n\t\tTINIT filename.typ  <-- Initialize from file");
  132.     printf("\n\t\t\t\t(typ defaults to CFG)\n");
  133. }
  134.  
  135. banner()  /* Print Banner of Program */
  136. {
  137.     printf("\nTINIT Version %d.%d\n",version/10,version%10);
  138. }
  139.  
  140. readfile(name)  /* Read Indicated File */
  141. char *name;
  142. {
  143.     int fd, i, type, inch;
  144.     char newfile[20], filename[20], *ptr;
  145.  
  146.     ptr = name;  /* Copy passed name into FILENAME */
  147.     type = FALSE;
  148.     i = 0;
  149.     while (*ptr != '\0') {
  150.         if (*ptr == '.') type = TRUE;  /* Note if file type given */
  151.         filename[i++] = *ptr++;
  152.         }
  153.     filename[i] = '\0';
  154.     if (!type) strcat (filename,configtype);  /* Set default file type */
  155.  
  156.     fd = fopen (filename, iobuf);  /* Try to open file */
  157.     if (fd == ERROR) {  /* If failure, try to open file on A: */
  158.         newfile[0] = '\0';
  159.         strcat (newfile,"A:");
  160.         strcat (newfile,filename);
  161.         fd = fopen (newfile, iobuf);
  162.         if (fd == ERROR) {  /* If this fails, give error */
  163.             printf("File %s not found", filename);
  164.             exit (FALSE);
  165.             }
  166.         }
  167.  
  168.     /* Read in parameters from disk file */
  169.     inch = getc(iobuf); if (inch == ERROR) abort();
  170.     cursor = inch;
  171.     inch = getc(iobuf); if (inch == ERROR) abort();
  172.     fkeys = inch;
  173.     inch = getc(iobuf); if (inch == ERROR) abort();
  174.     click = inch;
  175.     inch = getc(iobuf); if (inch == ERROR) abort();
  176.     scroll = inch;
  177.     inch = getc(iobuf); if (inch == ERROR) abort();
  178.     tabs = inch;
  179.     inch = getc(iobuf); if (inch == ERROR) abort();
  180.     uline = inch;
  181.     inch = getc(iobuf); if (inch == ERROR) abort();
  182.     video = inch;
  183.     getc(iobuf); getc(iobuf);  /* Ignore <CR> <LF> */
  184.     if (uline == YES) readbuffer (ulbuffer, ullen);
  185.     if (tabs == YES) readbuffer (tabbuffer, tablen);
  186.     if (fkeys == YES) readbuffer (fkeybuffer, fkeylen);
  187.     fclose(iobuf);
  188. }
  189.  
  190. readbuffer (bufname, buflen)  /* Read into the buffer pted to by bufname */
  191. char *bufname;
  192. int buflen;
  193. {
  194.     int i, inch;
  195.     char *bptr;
  196.  
  197.     bptr = bufname;
  198.     for (i=1;i<=buflen;i++) {
  199.         inch = getc(iobuf);
  200.         if (inch == ERROR) abort();
  201.         *bptr++ = inch;
  202.         }
  203.     getc(iobuf); getc(iobuf);  /* Flush <CR> <LF> */
  204. }
  205.  
  206. program()  /* Program the Terminal */
  207. {
  208.     char *pstr;
  209.     int i;
  210.     char fch;
  211.  
  212.     printf("%c%c%c",ESC,curs,cursor);  /* Config Cursor Type */
  213.     if (fkeys == YES) {  /* Program Function Keys */
  214.         for (i=1;i<=22;i++) {
  215.             pstr = fkeybuffer + (i-1)*20;
  216.             fch = i+'1'-1;
  217.             if (*pstr != '\0')
  218.                printf("%c%c%c%s%c",ESC,fctkey,fch,pstr,fctend);
  219.             }
  220.         }
  221.     cmnd(click);  /* Set Key Click */
  222.     cmnd(scroll);  /* Set Scrolling */
  223.     if (tabs == YES) {  /* Set Tab Stops */
  224.         cmnd(tabclr);  /* Clear ALL Tab Stops */
  225.         printf("\n");
  226.         pstr = tabbuffer;
  227.         for (i=1;i<=80;i++) {
  228.             if (*pstr++ == '.') cmnd(tabset); 
  229.             putchar(' ');
  230.             }
  231.         printf("\n"); sleep(2);  /* Delay 0.2 sec */
  232.         }
  233.     if (uline == YES) {  /* Program User Line */
  234.         printf("%c%c%s%c",ESC,loadusr,ulbuffer,'\r');
  235.         cmnd(dispusr);
  236.         }
  237.     sleep(2);  /* Delay 0.2 sec */
  238.     cmnd(video);
  239.     cmnd(cls);  /* New Screen */
  240. }
  241.  
  242. tinit()  /* Initialize Terminal */
  243. {
  244.     cmnd (unlock);
  245.     cmnd (nograph);
  246.     cmnd (noprot);
  247.     cmnd (normi);
  248.     cmnd (notabs);
  249.     cmnd (noclick);
  250.     cmnd (nocopy);
  251.     cmnd (cmode);
  252.     cmnd (fdx);
  253.     cmnd (nomonit);
  254.     cmnd (nobufpr);
  255.     cmnd (vid1);
  256.     cmnd (nopage);
  257.     cmnds (videom);
  258.     cmnds (insert);
  259.     sleep(2);  /* Delay 0.2 sec */
  260. }
  261.  
  262. abort()  /* Abort to CP/M */
  263. {
  264.     printf("\nFatal Error in Data File -- Aborting\n");
  265.     exit(FALSE);
  266. }
  267.  
  268. cmnd (ch)  /* Issue single-character command */
  269. char ch;
  270. {
  271.     putchar(ESC); putchar(ch);
  272. }
  273.  
  274. cmnds (st)  /* Issue String command */
  275. char *st;
  276. {
  277.     printf("%c%s",ESC,st);
  278. }
  279.