/*SPLH*/ /*$TITLE='CP/M-86 2.0 --- ED'  */
ED:
DO;
    /* MODIFIED FOR .PRL OPERATION MAY, 1979 */
    /* MODIFIED FOR OPERATION WITH CP/M 2.0 AUGUST 1979 */
    /* MODIFIED FOR MP/M 2.0 JUNE 1981 */
    /* MODIFIED FOR CP/M 1.1 OCT  1981 */
    /* MODIFIED FOR CP/M-68K JULY 1982 BY H.CHAKI */
DECLARE
    MPMPRODUCT LITERALLY '01H', /* REQUIRES MP/M */
    CPM3       LITERALLY '30H'; /* REQUIRES 3.0 CP/M */
 
 
 
/* DECLARE                            8080 INTERFACE
    JMP EDCOMMAND - 3 (TO ADDRESS LXI SP) 
    EDJMP BYTE DATA(0C3H),
    EDADR ADDRESS DATA(.EDCOMMAND-3); */
 
 
  /**************************************
   *                                    *
   *       B D O S   INTERFACE          *
   *                                    *
   **************************************/
 
 
  MON1:
    PROCEDURE (FUNC,INFO) EXTERNAL;
      DECLARE FUNC BYTE;
      DECLARE INFO ADDRESS;
    END MON1;
 
  MON2:
    PROCEDURE (FUNC,INFO) BYTE EXTERNAL;
      DECLARE FUNC BYTE;
      DECLARE INFO ADDRESS;
    END MON2;
 
  MON3:
    PROCEDURE (FUNC,INFO) ADDRESS EXTERNAL;
      DECLARE FUNC BYTE;
      DECLARE INFO ADDRESS;
    END MON3;
 
 MON5 : PROC(FN,IN) EXT ;
      DCL FN BYTE;
      DCL IN POINTER ;
 END;
 
 MON6 : PROC(FN,IN) BYTE EXT ;
      DCL FN BYTE;
      DCL IN POINTER ;
 END ;
 
 MON7 : PROC(FN,IN) ADDR EXT;
      DCL FN BYTE ;
      DCL IN POINTER;
  END ;
 
/* DECLARE CMDRV     BYTE    EXTERNAL;   /* COMMAND DRIVE      */
  DECLARE FCB (128)  BYTE    EXTERNAL;   /* 1ST DEFAULT FCB    */
  DECLARE FCB16 (128) BYTE    EXTERNAL;   /* 2ND DEFAULT FCB    */
/* DECLARE PASS0     ADDRESS EXTERNAL;   /* 1ST PASSWORD PTR   */
/* DECLARE LEN0      BYTE    EXTERNAL;   /* 1ST PASSWD LENGTH  */
/* DECLARE PASS1     ADDRESS EXTERNAL;   /* 2ND PASSWORD PTR   */
/* DECLARE LEN1      BYTE    EXTERNAL;   /* 2ND PASSWD LENGTH  */
  DECLARE TBUFF (128) BYTE    EXTERNAL;   /* DEFAULT DMA BUFFER */
 
 
DECLARE
/*  BDISK     BYTE    EXTERNAL, /* BOOT DISK 0004H */
    MAXB      ADDRESS EXTERNAL, /* MAX BASE 0006H */
    BUFF (128)BYTE    EXTERNAL, /* BUFFER 0080H */
    SECTSHF   LITERALLY '7',    /* SHL(1,SECTSHF) = SECTSIZE */
    SECTSIZE  LITERALLY '80H';  /* SECTOR SIZE */
 
/* 68K */ DCL DUM1P POINTER,DUM1L LONG AT(@DUM1P);
/* 68K */ DCL DUM2P POINTER,DUM2L LONG AT(@DUM2P);
 
BOOT: PROCEDURE PUBLIC;
    CALL MON1(0,0);          /* CHANGED FOR MP/M-86 VERSION */
    /* SYSTEM REBOOT */
    END BOOT;
/*SPLH*/ /*$EJECT    */
 
  /*  E D  :   T H E   C P / M   C O N T E X T    E D I T O R  */
 
    /*      COPYRIGHT (C) 1976, 1977, 1978, 1979, 1980, 1981
            DIGITAL RESEARCH
            BOX 579 PACIFIC GROVE
            CALIFORNIA 93950
 
            REVISED:
              07 APRIL 81  BY THOMAS ROLANDER
              21 JULY  81  BY DOUG HUSKEY
              29 OCT   81  BY DOUG HUSKEY
              10 NOV   81  BY DOUG HUSKEY
              31 JULY  81  BY H.CHAKI
    */
 
/*SPLH*/ /*$EJECT   */
 
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
 
                  * * *  GLOBAL VARIABLES * * *
 
 
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
DECLARE /*   LIT LITERALLY 'LITERALLY',
    DCL LIT 'DECLARE',
    PROC LIT 'PROCEDURE',
    ADDR LIT 'ADDRESS',    */
    CTLL LIT '0CH',
    CTLR LIT '12H',                /* REPEAT LINE IN INSERT MODE */
    CTLU LIT '15H',                /* LINE DELETE IN INSERT MODE */
    CTLX LIT '18H',                /* EQUIVALENT TO CTLU */
    CTLH LIT '08H',                /* BACKSPACE */
    TAB LIT '09H',                 /* TAB CHARACTER */
    LCA  LIT '110$0001B',          /* LOWER CASE A */
    LCZ  LIT '111$1010B',          /* LOWER CASE Z */
    ESC  LIT '1BH',                /* ESCAPE CHARACTER */
    ENDFILE LIT '1AH';             /* CP/M END OF FILE */
 
DECLARE
    TRUE LITERALLY '1', 
    FALSE LITERALLY '0',
    FOREVER LITERALLY 'WHILE TRUE',
    CTRL$C LITERALLY '3',
    CR LITERALLY '13',
    LF LITERALLY '10',
    WHAT LITERALLY '63';
 
 
DECLARE
    US LITERALLY '8',              /* FILE FROM USER 0   */
    RO LITERALLY '9',              /* R/O FILE INDICATOR */
    SY LITERALLY '10',             /* SYSTEM FILE ATTRIBUTE */
    EX LITERALLY '12',             /* EXTENT NUMBER POSITION */
    UB LITERALLY '13',             /* UNFILLED BYTES */
    CK LITERALLY '13',             /* CHECKSUM */
    MD LITERALLY '14',             /* MODULE NUMBER POSITION */
    NR LITERALLY '32',             /* NEXT RECORD FIELD */
    FS LITERALLY '33',             /* FCB SIZE */
    XFERON BYTE EXT INIT,          /* TRUE IF XFER ACTIVE */
    PASSWORD (16) BYTE EXT INIT;   /* SOURCE PASSWORD */
 
DECLARE
    LIBFCB (12) BYTE EXT DATA ;/* DEFAULT LIB NAME */
 
DECLARE
   PRINTSUPPR BYTE EXT INIT;        /* TRUE IF PRINT SUPPRESSED */
 
 
DECLARE
    COLUMN  BYTE EXT;         /* CONSOLE COLUMN POSITION */
/* COMMAND BUFFER */
 
DCL DCNT BYTE EXT   ;
 
DECLARE (MAXLEN,COMLEN) BYTE EXT, COMBUFF(128) BYTE EXT,
    (TCBP,CBP) BYTE EXT ;
 
/* MP/M PARSE FUNCTION CALL */
DECLARE
  PARSE$FN STRUCTURE(
    BUFF$ADR POINTER,
    FCB$ADR  POINTER);
 
DECLARE
    LPP LIT '23',            /* LINES PER PAGE */
    FORWARD LIT '1',
    BACKWARD LIT '0',
    RUBOUT LIT '07FH',
    POUND LIT '23H',
    MACSIZE LIT '128',       /* MAX MACRO SIZE */
    SCRSIZE LIT '100',       /* SCRATCH BUFFER SIZE */
    COMSIZE LIT 'ADDRESS';   /* DETERMINES MAX COMMAND NUMBER*/
 
DCL FLAG BYTE EXT;
 
DCL RESET LABEL EXT;
 
DECLARE
    EOS LITERALLY '0FFH';
 
/*SPLH*/ /*$EJECT     */
 
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
 
               * * *  CP/M INTERFACE ROUTINES * * *
 
 
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 
 /* IO SECTION */
 
READCHAR: PROCEDURE BYTE PUBLIC; RETURN MON2(1,0);
    END READCHAR;
 
  CONIN: 
    PROCEDURE BYTE PUBLIC;
    RETURN MON2(6,0FDH);
    END CONIN;
 
PRINTCHAR: PROCEDURE(CHAR) PUBLIC;
    DECLARE CHAR BYTE;
    IF PRINTSUPPR THEN RETURN;
    CALL MON1(2,CHAR);
    END PRINTCHAR;
 
TTYCHAR: PROCEDURE(CHAR) PUBLIC;
    DECLARE CHAR BYTE;
    IF CHAR >= ' ' THEN COLUMN = COLUMN + 1;
    IF CHAR = LF THEN COLUMN = 0;
    CALL PRINTCHAR(CHAR);
    END TTYCHAR;
 
BACKSPACE: PROCEDURE PUBLIC;
    /* MOVE BACK ONE POSITION */
    IF COLUMN = 0 THEN RETURN;
    CALL TTYCHAR(CTLH); /* COLUMN = COLUMN - 1 */
    CALL TTYCHAR(' ' ); /* COLUMN = COLUMN + 1 */
    CALL TTYCHAR(CTLH); /* COLUMN = COLUMN - 1 */
    COLUMN = COLUMN - 2;
    END BACKSPACE;
 
PRINTABS: PROCEDURE(CHAR) PUBLIC  ;
    DECLARE (CHAR,I,J) BYTE;
    I = CHAR = TAB AND 7 - (COLUMN AND 7);
    IF CHAR = TAB THEN CHAR = ' ';
        DO J = 0 TO I;
        CALL TTYCHAR(CHAR);
        END;
    END PRINTABS;
 
GRAPHIC: PROCEDURE(C) BYTE PUBLIC;
    DECLARE C BYTE;
    /* RETURN TRUE IF GRAPHIC CHARACTER */
    IF C >= ' ' THEN RETURN TRUE;
    RETURN C = CR OR C = LF OR C = TAB;
    END GRAPHIC;
 
PRINTC: PROCEDURE(C) PUBLIC;
    DECLARE C BYTE;
    IF NOT GRAPHIC(C) THEN
        DO; CALL PRINTABS('^');
        C = C + '@';
        END;
    CALL PRINTABS(C);
    END PRINTC;
 
CRLF: PROCEDURE PUBLIC;
    CALL PRINTC(CR); CALL PRINTC(LF);
    END CRLF;
 
PRINTM: PROCEDURE(A) PUBLIC;
    DECLARE A POINTER;
    CALL MON5(9,A);
    END PRINTM;
 
PRINT: PROCEDURE(A) PUBLIC;
    DECLARE A POINTER;
    CALL CRLF;
    CALL PRINTM(A);
    END PRINT;
 
READ: PROCEDURE(A) PUBLIC;
    DECLARE A POINTER;
    CALL MON5(10,A);
    END READ;
 
        /* USED FOR LIBRARY FILES */
OPEN: PROCEDURE(FCB) PUBLIC;
     DECLARE FCB POINTER;
     IF MON6(15,FCB) = 255 THEN DO;
        FLAG = 'O';
        GO TO RESET;
        END;
     END OPEN;
 
        /* USED FOR MAIN SOURCE FILE */
OPEN$FILE: PROCEDURE(FCB) ADDRESS PUBLIC;
     DECLARE FCB POINTER;
     RETURN MON7(15,FCB);
     END OPEN$FILE;
 
CLOSE: PROCEDURE(FCB) PUBLIC;
    DECLARE FCB POINTER;
    DCNT = MON6(16,FCB);
    END CLOSE;
 
SEARCH: PROCEDURE(FCB) PUBLIC;
    DECLARE FCB POINTER;
    DCNT = MON6(17,FCB);
    END SEARCH;
 
DELETE: PROCEDURE(FCB) PUBLIC;
    DECLARE FCB POINTER;
    DCNT = MON6(19,FCB);
    END DELETE;
 
DISKREAD: PROCEDURE(FCB) BYTE PUBLIC ;
    DECLARE FCB POINTER;
    RETURN MON6(20,FCB);
    END DISKREAD;
 
DISKWRITE: PROCEDURE(FCB) BYTE PUBLIC;
    DECLARE FCB POINTER;
    RETURN MON6(21,FCB);
    END DISKWRITE;
 
MAKE: PROCEDURE(FCB) PUBLIC;
    DECLARE FCB POINTER;
    DCNT = MON6(22,FCB);
    END MAKE;
 
RENAME: PROCEDURE(FCB) PUBLIC;
    DECLARE FCB POINTER;
    CALL MON5(23,FCB);
    END RENAME;
 
READCOM: PROCEDURE PUBLIC;
    MAXLEN = 128; CALL READ(@MAXLEN);
    END READCOM;
 
BREAK$KEY: PROCEDURE BYTE PUBLIC;
    IF MON2(11,0) THEN
        DO; /* CLEAR CHAR */
        IF MON2(1,0) = CTRL$C THEN 
            RETURN TRUE;
        END;
    RETURN FALSE;
    END BREAK$KEY;
 
CSELECT: PROCEDURE BYTE PUBLIC;
    /* RETURN CURRENT DRIVE NUMBER */
    RETURN MON2(25,0);
    END CSELECT;
 
SELECT: PROCEDURE(DISK) PUBLIC;
    DECLARE DISK BYTE;
    /* SET DRIVE NUMBER */
    CALL MON1(14,DISK);
    END SELECT;
 
SETDMA: PROCEDURE(A) PUBLIC;
    DECLARE A POINTER;
    /* SET DMA ADDRESS */
    CALL MON5(26,A);
    END SETDMA;
 
SET$ATTRIBU: PROCEDURE(FCB) PUBLIC;
    DECLARE FCB POINTER;
    CALL MON5(30,FCB);
    END SET$ATTRIBU;
 
                  /* THIS ROUTINE IS INCLUDED SOLELY FOR 
                     ENCONOMY OF SPACE OVER THE USE OF THE
                     EQUIVALENT (IN-LINE) CODE GENERATED BY
                     THE BUILT-IN FUNCTION */
MOVE:   PROC(C,S,D) PUBLIC;
    DCL (S,D) POINTER, C BYTE;
    DCL A BASED DUM1P BYTE, B BASED DUM2P BYTE;
        DUM1P=S;DUM2P=D;
        DO WHILE (C:=C-1)<>255;
        B=A; DUM1L=DUM1L+1;DUM2L=DUM2L+1;
        END;
    END MOVE;
 
WRITE$XFCB: PROCEDURE(FCB) PUBLIC;
    DECLARE FCB POINTER;
    CALL MOVE(8,@PASSWORD,@PASSWORD(8));
    IF MON6(103,FCB)= 0FFH THEN
       CALL PRINT(@('ERROR CREATING PASSWORD$'));
    END WRITE$XFCB;
 
READ$XFCB: PROCEDURE(FCB) PUBLIC;
    DECLARE FCB POINTER;
    CALL MON5(102,FCB);
    END READ$XFCB;
 
  /* 0FF => RETURN BDOS ERRORS */
  RETURN$ERRO:
    PROCEDURE(MODE) PUBLIC;
    DECLARE MODE BYTE;
      CALL MON1 (45,MODE);      
    END RETURN$ERRO;
 
REBOOT: PROCEDURE PUBLIC;
    IF XFERON THEN 
        CALL DELETE(@LIBFCB);
    CALL BOOT;
    END REBOOT;
 
 
  VERSION: PROCEDURE ADDRESS PUBLIC;
    /* RETURNS CURRENT CP/M VERSION # */
    RETURN MON7(12,0);
    END VERSION;
 
PARSE: PROCEDURE PUBLIC;
    CALL MON5(152,@PARSE$FN);
    END PARSE;
END;
 
