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 / HEATH / HMSRC20.LBR / HCONFIG1.CZ / HCONFIG1.C
Text File  |  2000-06-30  |  14KB  |  603 lines

  1. /************************* START OF HCONFIG1 ********************************/
  2.  
  3. #define  C80
  4.  
  5. #include "hmodem80.h"
  6. #include "hconfig.h"
  7.  
  8. sethost()
  9. {
  10.    int c;
  11.  
  12. start:
  13.    cls();
  14.    printf("\tA - Welcome string.....%s\n",Host.welcome);
  15.    printf("\tB - Autoanswer string..%s\n",Host.autoanswer);
  16.    printf("\tC - Password...........%s\n",Host.password);
  17.    printf("\tD - Connection type....%s\n",Host.modemconnection ? 
  18.       "MODEM" : "DIRECT");
  19.    printf("\tZ - Exit\n\n");
  20.    printf("\tPlease enter your selection:  ");
  21.    c = toupper(getchar());
  22.    cls();
  23.    switch (c) {
  24.    case 'A':
  25.       gnewstr("welcome string",Host.welcome);
  26.       break;      
  27.  
  28.    case 'B':
  29.       gnewstr("autoanswer string",Host.autoanswer);
  30.       break;      
  31.  
  32.    case 'C':
  33.       gnewstr("password",Host.password);
  34.       break;      
  35.  
  36.    case 'D':
  37.       printf("(M)odem or (D)irect connection? <M> :  ");
  38.       if (toupper(getchar()) == 'D')
  39.          Host.modemconnection = FALSE;
  40.       else
  41.          Host.modemconnection = TRUE;
  42.       break;      
  43.  
  44.    case ESC:
  45.    case 'Z':
  46.       return;
  47.       break;
  48.  
  49.    default:
  50.       printf("\007\nInvalid Entry\n");
  51.       wait(1);
  52.       break;
  53.    }
  54.    goto start;
  55. }
  56.  
  57. phonedit()
  58. {
  59.    int i, c, change;
  60.    char *answer;
  61.  
  62.    loadnos();
  63.    answer = Pathname;
  64.    while(TRUE) {
  65.       flush();
  66.       shownos();
  67.       printf("\nPlease enter letter of number to change/enter,\n");
  68.       printf("or anything else to EXIT:  ");
  69.       c = toupper(getchar()) - 'A';
  70.       if (c < 0 || c > 20)
  71.          break;
  72.       change = TRUE;
  73.       flush();
  74.       printf("\n          Name:  %s\nEnter new name:  ",PBook[c].name);
  75.       if (getline(answer,18))
  76.          strcpy(PBook[c].name,answer);
  77.       printf("\n          Number:  %s\nEnter new number:  ",PBook[c].number);
  78.       if (getline(answer,18))
  79.          strcpy(PBook[c].number,answer);
  80.       printf("\n          Bit rate:  %d\nEnter new bit rate:  ",
  81.          Baudtable[PBook[c].pbaudindex]);
  82.       if (getline(answer,18)) {
  83.          for (i=0; i<11; i++) {
  84.             if (atoi(answer) == Baudtable[i]) {
  85.                PBook[c].pbaudindex = i;
  86.                break;
  87.             }
  88.          }
  89.       }
  90.       printf("\n          Parity:  %c\nEnter new parity:  ",PBook[c].pparity);
  91.       if (getline(answer,18))
  92.          PBook[c].pparity = toupper(answer[0]);
  93.       printf("\n    Nr data bits:  %d\nEnter new number:  ",PBook[c].pdatabits);
  94.       if (getline(answer,18))
  95.          PBook[c].pdatabits = atoi(answer);
  96.       printf("\n    Nr stop bits:  %d\nEnter new number:  ",PBook[c].pstopbits);
  97.       if (getline(answer,18))
  98.          PBook[c].pstopbits = atoi(answer);
  99.       printf("\n                Duplex:  %s\nEnter (H)alf or (F)ull:  ",
  100.          PBook[c].echo?"Half":"Full");
  101.       if (getline(answer,18))
  102.          PBook[c].echo = (toupper(answer[0]) == 'H');
  103.    }
  104.    flush();
  105.    cls();
  106. }
  107.  
  108. ldedit()
  109. {
  110.    char *p, *answer;
  111.    int c;
  112.  
  113.    answer = Pathname;
  114.    printf("\n\nEdit which long distance access code? (+ or -) <+>  ");
  115.    if ((c=getchar()) == '-')
  116.       p = Mci;
  117.    else {
  118.       c = '+';
  119.       p = Sprint;
  120.    }
  121.    printf("\n\nCurrent code for %c:  %s\n\n",c,p);
  122.    printf("Enter new code:  ");
  123.    if (getline(answer,20))
  124.       strcpy(p,answer);
  125. }
  126.  
  127. edit()
  128. {
  129.    static int i;
  130.    static char *buffer;
  131.    static char keypad[] = "pqrstuvwxynM";
  132.    static char keybuf[2];
  133.  
  134.    buffer = Pathname;
  135.    while (TRUE) {
  136.       cls();
  137.       flush();
  138.       printf("       KEYPAD MACRO LIST\n\n");
  139.       for (i=0; i<10; i++)
  140.          printf("%d - %s\n",i,KbMacro[i]);
  141.       printf(". (PERIOD) - %s\n",KbMacro[10]);
  142.       printf("ENTER - %s\n",KbMacro[11]);
  143.       printf("\nPress key of macro to edit, or anything else to EXIT:  ");
  144.       if (!(keybuf[0]=getfunction(getchar())))
  145.          break;
  146.       keybuf[1] = '\0';
  147.       i = index(keypad,keybuf);
  148.       if (i<0 || i>11)
  149.          break;
  150.       flush();
  151.       printf("\nIf you want the macro to end with a RETURN,\n");
  152.       printf("add a '!' to the end of your entry (20 characters max).");
  153.       printf("\n\nOld Macro:  %s",KbMacro[i]);
  154.       printf("\n\nNew Macro:  ");
  155.       if (getline(buffer,21))
  156.          strcpy(KbMacro[i],buffer);
  157.    }
  158.    flush();
  159.    cls();
  160. }
  161.  
  162. getfunction(c)  /*see if function key was pressed*/
  163. unsigned c;
  164. {
  165.    static unsigned m;
  166.  
  167.    if (c == ESC) {
  168.       mswait(50);                    /* wait 50 ms */
  169.       if ((m=getch()) == '?') {
  170.          mswait(50);
  171.          m = getch();
  172.       }
  173.       return m;
  174.    }
  175.    else
  176.       return 0;
  177. }
  178.  
  179. getch()
  180. {
  181.    return bdos(DIRCTIO,INPUT);
  182. }
  183.  
  184. getconfig()
  185. {
  186.    int fd, size, sectors;
  187.    char *p;
  188.  
  189.    fd = fopen(Cfgfile,"rb");
  190.    if (fd) {
  191.       p = Waste;
  192.       size = (unsigned)p - (unsigned)&BFlag;
  193.       sectors = roundup(size,128);
  194. #ifdef   DEBUG
  195.       printf("\nsize=%d\nsectors=%d",size,sectors);
  196.       printf("\nwaste=%x\n&bflag=%x\n",Waste,&BFlag);
  197. #endif
  198.       read(fd,&BFlag,sectors*128);
  199.       fclose(fd);
  200.    }
  201. }
  202.  
  203. savephone()
  204. {
  205.    int fd, sectors, size;
  206.  
  207.    size = 20 * sizeof(struct phonebook);
  208.    sectors = roundup(size,128);
  209. #ifdef   DEBUG
  210.    printf("\nsize=%d\nsectors=%d",size,sectors);
  211. #endif
  212.    fd = fopen(Phonefile,"wb");
  213.    if (!openerror(fd,Phonefile)) {
  214.       printf("\nSaving Phone numbers...");
  215.       if (!write(fd,PBook,sectors*128))
  216.          wrerror(Phonefile);
  217.       else
  218.          printf("Successful.\n");
  219.       fclose(fd);
  220.    }
  221. }
  222.  
  223. saveconfig()
  224. {
  225.    int fd, sectors, size;
  226.    char *p;
  227.  
  228.    p = Waste;
  229.    size = (unsigned)p - (unsigned)&BFlag;
  230.    sectors = roundup(size,128);
  231. #ifdef   DEBUG
  232.    printf("\nsize=%d\nsectors=%d",size,sectors);
  233.    printf("\nwaste=%x\n&bflag=%x\n",Waste,&BFlag);
  234. #endif
  235.    fd = fopen(Cfgfile,"wb");
  236.    if (!openerror(fd,Cfgfile)) {
  237.       printf("\n\nSaving Configuration...");
  238.       if (!write(fd,&BFlag,sectors*128))
  239.          wrerror(Cfgfile);
  240.       else
  241.          printf("Successful.\n");
  242.       fclose(fd);
  243.    }
  244. }
  245.  
  246. setbaud()
  247. {
  248.    int baud;
  249.    char *buffer;
  250.  
  251.    buffer = Pathname;
  252.    do {
  253.       printf("\nPlease enter modem bit rate:  ");
  254.       if (!(getline(buffer,6)))
  255.          break;
  256.       baud = atoi(buffer);
  257.       printf("\n");
  258.    }
  259.    while (!goodbaud(baud));
  260. }
  261.  
  262. goodbaud(value)
  263. int value;
  264. {
  265.    int i;
  266.    
  267.    for (i=0; i<11; i++) {
  268.       if (value == Baudtable[i]) {
  269.          Line.baudindex = i;
  270.          return TRUE;
  271.       }
  272.    }
  273.    printf("\nInvalid entry\n");
  274.    wait(1);
  275.    return FALSE;
  276. }
  277.  
  278. cls() /*clear the screen*/
  279. {
  280.    printf("\n\033E\b\b\b\b\b");
  281. }
  282.  
  283. openerror(chan,fname)
  284. int chan;
  285. char *fname;
  286. {
  287.    if (!chan) {
  288.       printf("\n\nERROR - Cannot open %s\n\n",fname);
  289.       wait(3);
  290.    }
  291.    return !chan;
  292. }
  293.  
  294. wrerror(fname)
  295. char *fname;
  296. {
  297.    printf("\n\nERROR - Cannot write to %s\n\n",fname);
  298.    wait(3);
  299. }
  300.  
  301. wait(seconds)
  302. unsigned seconds;
  303. {
  304.    mswait(seconds*1000);
  305. }
  306.  
  307. mswait(milliseconds)
  308. unsigned milliseconds;
  309. {
  310.         static unsigned *p = TICCNT;
  311.  
  312.         milliseconds /= 2;         /* 2-ms ticks */
  313.         milliseconds += *p;
  314.         while (milliseconds != *p);  /*wait until ready*/
  315. }
  316.  
  317. flush()
  318. {
  319.    while(bdos(GCS,NULL))          /*clear type-ahead buffer*/
  320.       bdos(CONIN,NULL);
  321.    getch();                       /*and anything else*/
  322. }
  323.  
  324. shownos()
  325. {
  326.    int i, j;
  327.  
  328.    cls();
  329.    printf("\033p         NAME                NUMBER          B   P D S E\033q");
  330.    for (i=0,j=1; i<20; i++,j++) {
  331.       locate(i+1,0);
  332.       printf("%c - %s",i+'A',PBook[i].name);
  333.       locate(i+1,41-strlen(PBook[i].number));
  334.       printf(PBook[i].number);
  335.       locate(i+1,44);
  336.       printf("%4d %c %d %d %c\n",Baudtable[PBook[i].pbaudindex],PBook[i].pparity,
  337.          PBook[i].pdatabits,PBook[i].pstopbits,PBook[i].echo?'H':'F');
  338.    }   
  339. }
  340.  
  341. loadnos()
  342. {
  343.    static unsigned amount;
  344.    static int fd, result;
  345.    static int sectors;
  346.  
  347.    result = NERROR;
  348.    amount = 20 * sizeof(struct phonebook);
  349.    sectors = roundup(amount,128);
  350.    if (fd = fopen(Phonefile,"rb")) {
  351.       read(fd,PBook,sectors*128);
  352.       result = OK;
  353.       fclose(fd);
  354.    }
  355.    return result;
  356. }      
  357.  
  358. roundup(dividend,divisor)
  359. int dividend, divisor;
  360. {
  361.    return (dividend/divisor + ((dividend%divisor) ? 1 : 0));
  362. }
  363.  
  364. locate(r,c)
  365. int r, c;
  366. {
  367.    printf("\033Y%c%c",r+32,c+32);
  368. }
  369.  
  370. /*
  371. /* exec: function to chain to another C-generated com file, with
  372. /*     text argument passing.
  373. /* Calling sequence:
  374. /*     exec(prog, args);
  375. /*     char *prog, *args;
  376. /* where
  377. /*     prog is the name of the program being executed next
  378. /*     args is a pointer to a string of arguments separated by
  379. /*       blanks or tabs.  Embedded blanks within the arguments are
  380. /*       not allowed, unless the called program does not use the
  381. /*       default FCB parameters (and most don't) and can parse the
  382. /*       command line parameter list itself (like C80 programs can).
  383. */
  384. exec() {
  385. #ifdef   C80
  386. #asm
  387.     JMP @exec
  388. ;
  389. ;    CP/M memory pointers
  390. ;
  391. @BASE       EQU 0000H    ;either 0 or 4200h for CP/M systems
  392. @FCB       EQU @BASE+5CH    ;default file control block
  393. @TBUFF    EQU @BASE+80H    ;sector buffer
  394. @BDOS       EQU @BASE+5    ;bdos entry point
  395. @TPA       EQU @BASE+100H    ;transient program area
  396. @ERRV       EQU 255     ;error value returned by bdos calls
  397. ;
  398. ;    CP/M BDOS CALL MNEMONICS
  399. ;
  400. @OPENC    EQU 15        ;open a file
  401. @READS    EQU 20        ;read a sector (sequential)
  402. @SDMA       EQU 26        ;set dma
  403. ;
  404. ;    Argument pointers
  405. ;
  406. @ARGS:    DS 0
  407. @ARG1:    DS 2
  408. @ARG2:    DS 2
  409. @ARG3:    DS 2
  410. @ARG4:    DS 2
  411. @ARG5:    DS 2
  412. @ARG6:    DS 2
  413. ;
  414. @exec:
  415.     LXI   H,4
  416.     DAD   SP
  417.     MOV   E,M
  418.     INX   H
  419.     MOV   D,M        ;DE points to program name now
  420.     LXI   H,-60
  421.     DAD   SP           ; compute &newfcb for use here
  422.     PUSH  H           ; save for much later (will pop into bc)
  423.     PUSH  H           ;make a few copies for local use below
  424.     PUSH  H
  425.     CALL  x?fcb##    ;set up com file for exec-ing
  426.     POP   H           ;get new fcb addr
  427.     LXI   B,9        ;set extension to com
  428.     DAD   B
  429.     MVI   M,'C'
  430.     INX   H
  431.     MVI   M,'O'
  432.     INX   H
  433.     MVI   M,'M'
  434.     POP   D              ;get new fcb addr again
  435.     MVI   C,@OPENC       ;open the file for reading
  436.     CALL  @BDOS
  437.     CPI   @ERRV
  438.     JNZ   @NOERR
  439.     POP   H              ;if can't (like it doesn't exist), return -1
  440.     LXI   H,-1
  441.     DB    0C9H        ; return instruction
  442.  
  443. @NOERR:  
  444.    LXI   H,4           ;get args pointer
  445.     DAD   SP
  446.     CALL  h@##          ;HL = *HL
  447.     CALL  @SPARG       ;separate them into individual strings
  448.     LHLD  @ARG1
  449.     MOV   A,H
  450.     ORA   L
  451.     JNZ   @EXCL0
  452.     LXI   D,@ARG1       ;no arguments -- create a blank FCB
  453.     PUSH  D              ;call x?fcb with null string
  454.     LXI   H,@FCB
  455.     CALL  x?fcb
  456.     POP   H
  457.     JMP   @EXCL6
  458.  
  459. @EXCL0: 
  460.    XCHG
  461.     LXI   H,@FCB
  462.     CALL  x?fcb          ;stick first param into default FCB slot
  463.     LHLD  @ARG2          ;and stick second param string
  464.     MOV   A,H
  465.     ORA   L
  466.     JNZ   @EXCL6
  467.     LXI   H,@ARG2
  468.  
  469. @EXCL6: 
  470.    XCHG                 ;into second default fcb slot
  471.     LXI   H,@FCB+16
  472.     CALL  x?fcb
  473.     LXI   D,@TBUFF+1     ;now construct command line:
  474.     LXI   H,4
  475.     DAD   SP           ;HL points to arg string pointer
  476.     CALL  h@        ;HL points to arg string
  477.     MVI   B,0        ;char count for com. line buf.
  478.     MOV   A,H        ;are there any arguments?
  479.     ORA   L
  480.     JZ    @EXCL9
  481.     ORA   M           ; (Bug fix 7/83 WB)
  482.     JNZ   @EXCL5
  483. @EXCL9: 
  484.    STAX  D        ;no--zero TBUFF and TBUFF+1
  485.     JMP   @EXCL2
  486. @EXCL5:  
  487.    MVI   A,' '    ;yes--start buffer off with a ' '
  488.     STAX  D
  489.     INX   D
  490.     INR   B
  491. @EXCL1: 
  492.    MOV   A,M           ;now copy argument string to command line
  493.     CALL  NAM@U##       ;make sure they're upper case
  494.     STAX  D
  495.     INX   D
  496.     INX   H
  497.     INR   B
  498.     ORA   A
  499.     JNZ   @EXCL1
  500.     DCR   B
  501.  
  502. @EXCL2: 
  503.    LXI   H,@TBUFF       ;set length of command line
  504.     MOV   M,B           ;at location tbuff
  505.  
  506.     LXI   D,@CODE0       ;copy loader down to end of tbuff
  507.     LXI   H,@TPA-42
  508.     MVI   B,42          ;length of loader
  509. @EXCL4:  LDAX D
  510.     MOV   M,A
  511.     INX   D
  512.     INX   H
  513.     DCR   B
  514.     JNZ   @EXCL4
  515.  
  516.     POP   B               ;get back working fcb pointer
  517.     LHLD  @BASE+6
  518.     SPHL
  519.     LXI   H,@BASE
  520.     PUSH  H               ;set base of ram as return addr
  521.     JMP   @TPA-42        ;(go to `CODE0:')
  522. ;
  523. ; THIS LOADER CODE IS NOW: 42 BYTES LONG.
  524. ;
  525. @CODE0:
  526.    LXI   D,@TPA    ;destination address of new program
  527. @CODE1: 
  528.    PUSH  D            ;push dma addr
  529.     PUSH  B            ;push fcb pointer
  530.     MVI   C,@SDMA        ;set dma address for new sector
  531.     CALL  @BDOS
  532.     POP   D            ;get pointer to working fcb in de
  533.     PUSH  D            ;and re-push it
  534.     MVI   C,@READS        ;read a sector
  535.     CALL  @BDOS
  536.     POP   B            ;restore fcb pointer into bc
  537.     POP   D            ;and dma address into de
  538.     ORA   A            ;end of file?
  539.     JZ    @TPA-8        ;if not, get next sector (goto `CODE2:')
  540.     MVI   C,@SDMA        ;reset dma pointer
  541.     LXI   D,@TBUFF
  542.     CALL  @BDOS
  543.     JMP   @TPA        ;and go invoke the program
  544.  
  545. @CODE2: 
  546.    LXI   H,80H        ; bump dma address
  547.     DAD   D
  548.     XCHG
  549.     JMP   @TPA-39        ;and go loop (at CODE1)
  550. ;
  551. ; this routine takes the string pointed to by HL,
  552. ; seperates it into non-white strings,
  553. ; and places them contiguously in array ARGST.
  554. ; also places pointers to these individual strings in ARGS
  555. ;
  556. @SPARG: 
  557.    XCHG              ;DE = original string
  558.     LXI   B,@ARGST    ;BC = new string (w/ each substr 0-terminated)
  559.     LXI   H,@ARGS    ;HL = pointer to ARGS space
  560. @SEP0:
  561.     DCX   D
  562. @SEP1:
  563.     INX   D        ;scan over white space
  564.     LDAX  D
  565.     CPI   ' '
  566.     JZ    @SEP1
  567.     CPI   9
  568.     JZ    @SEP1
  569.     CPI   0        ; char = 0?
  570.     JZ    @SPRET    ; yes -- return
  571.     MOV   M,C     ; no -- store local pointer at proper args
  572.     INX   H
  573.     MOV   M,B     ;argsn = BC
  574.     INX   H
  575. @TOWSP:
  576.    STAX  B        ;store non-white
  577.     INX   B
  578.     INX   D        ;now scan to next white space
  579.     LDAX  D
  580.     CPI   0
  581.     JZ    @SEP2
  582.     CPI   ' '
  583.     JZ    @SEP2
  584.     CPI   9
  585.     JNZ   @TOWSP
  586. @SEP2:
  587.     XRA   A
  588.     STAX  B        ;store 0 to terminate this string
  589.     INX   B
  590.     JMP   @SEP0    ; and loop
  591. @SPRET:
  592.    MOV   M,A     ;set last argn to 0 and return
  593.     INX   H
  594.     MOV   M,A
  595.     DB    0C9H  ; return instruction
  596. @ARGST: DS 100
  597. #endasm
  598. #endif
  599. }
  600.  
  601. /************************* END OF HCONFIG1 **********************************/
  602.  
  603.