home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / editc80 / ed8.c < prev    next >
C/C++ Source or Header  |  1984-06-15  |  3KB  |  241 lines

  1. /* Screen editor:  operating system module
  2.  *           C/80 version
  3.  *
  4.  * Source:  ed8.c
  5.  * Version: June 19, 1981.
  6.  */
  7.  
  8. /* define globals */
  9.  
  10. #include ed1.h
  11.  
  12.  
  13. /* all calls to the operating system are made here.
  14.  * only this module will have to be
  15.  * rewritten for a new operating system.
  16.  */
  17.  
  18. /* CP/M 2.2 versions of syscstat(), syscin(), syscout() */
  19.  
  20. /* return -1 if no character is ready from the console. 
  21.  * otherwise, return the character.
  22.  */
  23.  
  24. syscstat()
  25. {
  26.     return(bdos(6,-1));
  27. }
  28.  
  29. /* wait for next character from the console.
  30.  * do not echo it.
  31.  */
  32.  
  33. syscin()
  34. {
  35. int c;
  36.     while ((c=bdos(6,-1))==0) {
  37.         ;
  38.     }
  39.     return(c);
  40. }
  41.  
  42. /* print character on the console */
  43.  
  44. syscout(c) char c;
  45. {
  46.     bdos(6,c);
  47.     return(c);
  48. }
  49.  
  50.  
  51. /* print character on the printer */
  52.  
  53. syslout(c) char c;
  54. {
  55.     bdos(5,c);
  56.     return(c);
  57. }
  58.  
  59. /* open a file */
  60.  
  61. sysopen(name,mode) char *name, *mode;
  62. {
  63. int file;
  64. int m;
  65.     m=tolower(mode[0]);
  66.     if (m=='r' || m=='w') {
  67.         if ((file=fopen(name,mode))==0) {
  68.             iormode='c';
  69.             return(ERR);
  70.         }
  71.         else {
  72.             iormode=m;
  73.             return(file);
  74.         }
  75.     }
  76.     else {
  77.         iormode='c';
  78.         syserr("fopen: bad mode");
  79.         return(ERR);
  80.     }
  81. }
  82.  
  83. /* close a file */
  84.  
  85. sysclose(file) int file;
  86. {
  87.     if (iormode=='w') {
  88.         /* write end of file byte */
  89.         putc(0x1a,file);
  90.     }
  91.     iormode='c';
  92.     fclose(file);
  93.     return(OK);
  94. }
  95.  
  96. /* read next char from file */
  97.  
  98. sysrdch(file) int file;
  99. {
  100. int c;
  101.     if (iormode!='r') {
  102.         error ("sysrdch:  read in w mode");
  103.         return(ERR);
  104.     }
  105.     if ((c=getc(file))==-1) {
  106.         return(EOF);
  107.     }
  108.     else if (c==0x1a) {
  109.         return(EOF);
  110.     }
  111.     else if (c=='\n') {
  112.         return (CR);
  113.     }
  114.     else {
  115.         return(c);
  116.     }
  117. }
  118.  
  119. /* write next char to file */
  120.  
  121. syspshch(c,file) char c; int file;
  122. {
  123. char ch;
  124.     if (iormode!='w') {
  125.         error("syspshch:  write in r mode");
  126.         return(ERR);
  127.     }
  128.     if (c==CR) {
  129.         ch='\n';
  130.     }
  131.     else {
  132.         ch=c;
  133.     }
  134.     if (putc(ch,file)==-1) {
  135.         error("disk write failed");
  136.         return(ERR);
  137.     }
  138.     else {
  139.         return(c);
  140.     }
  141. }
  142.  
  143. /* read one char from END of file */
  144.  
  145. syspopch(file) int file;
  146. {
  147.     error("syspopch() not implemented");
  148.     return(ERR);
  149. }
  150.  
  151. /* check file name for syntax */
  152.  
  153. syschkfn(args) char *args;
  154. {
  155.     return(OK);
  156. }
  157.  
  158. /* copy file name from args to buffer */
  159.  
  160. syscopfn(args,buffer) char *args, *buffer;
  161. {
  162. int n;
  163.     n=0;
  164.     while (n<(SYSFNMAX-1)) {
  165.         if (args[n]==EOS) {
  166.             break;
  167.         }
  168.         else {
  169.             buffer[n]=args[n];
  170.             n++;
  171.         }
  172.     }
  173.     buffer[n]=EOS;
  174. }
  175.  
  176. /* move a block of n bytes down (towards HIGH addresses).
  177.  * block starts at source and the first byte goes to dest.
  178.  *    src:[<--n-->]   dest:[       ]
  179.  */
  180.  
  181. sysmovdn(n,dest,source) int n; char *dest, *source;
  182. {
  183.     if (n>0) {
  184. #asm
  185.     DB 0DDH,0E1H    ;POP IX = return address in IX
  186.     POP H        ;source in HL
  187.     POP D        ;dest in DE
  188.     POP B        ;count in BC
  189.     PUSH B        ;restore args
  190.     PUSH D
  191.     PUSH H
  192.     DB 0DDH,0E5H    ;PUSH IX
  193.     XCHG
  194.     DAD B
  195.     XCHG        ;dest+count in DE
  196.     DAD B        ;source+count in HL
  197.     INX B        ;count+1 in BC
  198.     DB 0EDH,0B8H    ;LDDR
  199. #endasm
  200.     }
  201. }
  202.  
  203. /* move a block of n bytes up (towards LOW addresses).
  204.  * the block starts at source and the first byte goes to dest.
  205.  *    dest:[       ]   src:[<--n-->]
  206.  */
  207.  
  208. sysmovup(n,dest,source) int n; char *dest, *source;
  209. {
  210.     if (n>0) {
  211. #asm
  212.     DB 0DDH,0E1H    ;POP IX = return address in IX
  213.     POP H        ;source in HL
  214.     POP D        ;dest in DE
  215.     POP B        ;count in BC
  216.     PUSH B        ;restore args
  217.     PUSH D
  218.     PUSH H
  219.     DB 0DDH,0E5H    ;PUSH IX
  220.     DB 0EDH,0B0H    ;LDIR
  221. #endasm
  222.     }
  223. }
  224.  
  225. /*
  226. Interfaces with operating system functions
  227. */
  228.  
  229. bdos(c,d) int c,d;
  230. {
  231. #asm
  232.     POP H
  233.     POP D
  234.     POP B
  235.     PUSH B
  236.     PUSH D
  237.     PUSH H
  238.     CALL 5
  239. #endasm
  240. }
  241.