home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol076 / ed8.c < prev    next >
Encoding:
C/C++ Source or Header  |  1984-04-29  |  4.5 KB  |  253 lines

  1. /* ED8.C */
  2.  
  3. /* altered for Software Toolworks compiler with M80 option */
  4. #include ed0.c
  5. #include ed1.ccc
  6. cpmcall(o,c) int o; char c;    /* new: cpmcall absent from original listing */
  7. {
  8. #asm
  9.     POP    H    ;RETURN
  10.     POP    D    ;CHAR C -- INPUT OR OUTPUT
  11.     POP    B    ;INT O -- OPCODE
  12.     PUSH    B
  13.     PUSH    D
  14.     PUSH    H    ;REPLACE RETURN
  15.     CALL    5
  16.     MOV    L,A
  17.     MVI    H,0
  18. /*    RET         Note: Software Tookworks compiler supplies RET */
  19. #endasm
  20. }    /* added */
  21. syscstat()
  22. {
  23. int c;
  24.     c=cpmcall(6,-1);
  25.     if (c==0){        /* correction of original version */
  26.         return(-1);
  27.     }
  28.     else {
  29.         return(c);
  30.     }
  31. }
  32. syscin()    /* extensively altered to recognize escape sequences */
  33. {        /* from H19/H89 special keys */
  34. int s,c;
  35.     while ((c=cpmcall(6,-1))==0) {
  36.         ;
  37.     }
  38.     if (c==ESC1) {
  39.         while ((c=cpmcall(6,-1))==0) {
  40.             ;
  41.         }
  42.         if (c=='?') {
  43.             while ((c=cpmcall(6,-1))==0) {
  44.                 ;
  45.             }
  46. /* "switch" and "case" construct can be altered to a sequence of        */
  47. /* "else if" statements if compiler lacks "switch".                */
  48. /* Looks slow, but main body is executed only in command mode and only        */
  49. /* for escape sequences */
  50.             switch (c) {
  51.                 case 'q': return(UP1);
  52.                 case 'x': return(UP2);
  53.                 case 'r': return(DOWN2);
  54.                 case 't': return(LEFT1);
  55.                 case 'v': return(RIGHT1);
  56.                 case 'w': return(INS1);
  57.                 case 'M': return(ESC1);
  58.                 case 'y': return(DEL1);
  59.                 case 'p': return(GTOCH);
  60.                 case 's': return(ZAP1);
  61.                 case 'n': return(DTOCH);
  62.                 case 'u': return(HOME);
  63.                 default: continue;
  64.             }
  65.         }
  66.         else {
  67.             switch (c) {
  68.                 case 'S': return(DSCROL);
  69.                 case 'W': return(USCROL);
  70.                 case 'U': return(GOTO);
  71.                 case 'V': return(LSTRT);
  72.                 case 'Q': return(ABT1);
  73.                 case 'P': return(EDIT1);
  74.                 case 'T': return(LEND);
  75.                 case 'R': return(ESC1);
  76.                 case 'J': return(ERASE);
  77.                 default: return(c);
  78.             }
  79.         }
  80.     }
  81.     else {
  82.         return(c);
  83.     }
  84. }
  85. syscout(c) char c;
  86. {
  87.     cpmcall(6,c);
  88.     return(c);
  89. }
  90. syslout(c) char c;
  91. {
  92.     cpmcall(5,c);
  93.     return(c);
  94. }
  95. sysend()
  96. {
  97. #asm
  98.     LHLD    6
  99.     DCX    H
  100. /*    RET         Note: Software Tookworks compiler supplies RET */
  101. #endasm
  102. }    /* added */
  103. sysopen(name,mode) char *name, *mode;
  104. {
  105. int file;
  106.     if ((file=fopen(name,mode))==0) {
  107.         return(ERR);
  108.     }
  109.     else {
  110.         return(file);
  111.     }
  112. }
  113. sysclose(file) int file;
  114. {
  115.     fclose(file);
  116.     return(OK);
  117. }
  118. sysrdch(file) int file;
  119. {
  120. int c;
  121.     if ((c=getc(file))==-1) {
  122.         return(EOF);
  123.     }
  124.     else if (c==LF) {    /* map LF to CR for Software Toolworks    */
  125.         return(CR);    /* compiler */
  126.     }
  127.     else {
  128.         return(c);
  129.     }
  130. }
  131. syspshch(c,file) char c; int file;
  132. {
  133.     if (c==CR) {        /* map CR to LF for Software Toolworks     */
  134.         if (putc(LF,file)==-1) {    /* compiler */
  135.             error("disk write failed");
  136.             return(ERR);
  137.         }
  138.     }
  139.     else if (putc(c,file)==-1) {
  140.         error("disk write failed");
  141.         return(ERR);
  142.     }
  143.     else {
  144.         return(c);
  145.     }
  146. }
  147. syspopch(file) int file;
  148. {
  149.     error("syspopch() not implemented");
  150.     return(ERR);
  151. }
  152. syschkfn(args) char *args;
  153. {
  154.     if (args[0] == EOS) {    /* add check for zero-length file name */
  155.         message("no file name");
  156.         return(ERR);
  157.     }
  158.     else {
  159.         return(OK);
  160.     }
  161. }
  162. syscopfn(args,buffer) char *args, *buffer;
  163. {
  164. int n;
  165.     n=0;
  166.     while (n<SYSFNMAX-1) {
  167.         if (args[n]==EOS) {
  168.             break;
  169.         }
  170.         else {
  171.             buffer[n]=args[n];
  172.             n++;
  173.         }
  174.     }
  175.     buffer[n]=EOS;
  176. }
  177. sysdnmov(n,d,s) int n,d,s;
  178. {
  179. /* extensively altered to allow LDDR for Z80 processors using parity check
  180.    for processor type.    Also checks for zero-length move to avoid moving
  181.    everything */
  182. #asm
  183.     POP    PSW    ;RETURN
  184.     POP    H    ;SOURCE
  185.     POP    D    ;DESTINATION
  186.     POP    B    ;LENGTH
  187.     PUSH    PSW    ;RESTORE RETURN
  188.     MOV    A,C
  189.     ORA    B
  190.     JZ    SYSDN3
  191.     MVI    A,2
  192.     INR    A
  193.     JPE    SYSDN1
  194.     DB    0EDH,0B8H    ;LDDR INSTRUCTION FOR Z80
  195.     JMP    SYSDN3
  196. ;
  197. SYSDN1: MOV    A,B
  198.     ORA    C
  199.     JZ    SYSDN3
  200.     MOV    A,M
  201.     STAX    D
  202.     DCX    H
  203.     DCX    D
  204.     DCX    B
  205.     JMP    SYSDN1
  206. ;
  207. SYSDN3: POP    H
  208.     PUSH    H
  209.     PUSH    H
  210.     PUSH    H
  211.     PUSH    H
  212. /*    RET         Note: Software Tookworks compiler supplies RET */
  213. #endasm
  214. }    /* added */
  215. sysupmov (n,d,s) int n,d,s;
  216. /* extensively altered to allow LDIR for Z80 processors using parity check
  217.    for processor type.    Also checks for zero-length move to avoid moving
  218.    everything */
  219. {
  220. #asm
  221.     POP    PSW    ;RETURN
  222.     POP    H    ;SOURCE
  223.     POP    D    ;DESTINATION
  224.     POP    B    ;LENGTH
  225.     PUSH    PSW    ;RESTORE RETURN
  226.     MOV    A,C
  227.     ORA    B
  228.     JZ    SYSUP3
  229.     MVI    A,2
  230.     INR    A
  231.     JPE    SYSUP1
  232.     DB    0EDH,0B0H    ;LDIR INSTRUCTION FOR Z80
  233.     JMP    SYSUP3
  234. ;
  235. SYSUP1: MOV    A,B
  236.     ORA    C
  237.     JZ    SYSUP3
  238.     MOV    A,M
  239.     STAX    D
  240.     INX    H
  241.     INX    D
  242.     DCX    B
  243.     JMP    SYSUP1
  244. ;
  245. SYSUP3: POP    H
  246.     PUSH    H
  247.     PUSH    H
  248.     PUSH    H
  249.     PUSH    H
  250. /*    RET         Note: Software Tookworks compiler supplies RET */
  251. #endasm
  252. }    /* added */
  253.