1 REM Ins{nd av Benny L|fgren SYSOP <2615>    1986-09-18 12.37.18 (KERMIT)
RUNBAS    PROG  ** RUNBAS ** EXECUTE A BASIC PROGRAM FROM DOS
*
          RADIX 16
          SQUEZ
*
*         RUNBAS - EXECUTE A BASIC PROGRAM FROM DOS
*         =========================================
*
*         BL  / 85-05-14 / X.00 / First version, no guarantees
*
          EJECT
*
*         INIT SOME SYSTEM VARIABLES
*         --------------------------
*
START*    =     *
          LA    Y,Y.BASE          PARK Y REGISTER IF SOMEONE MOVED IT
          MVI   0,Y.XQS(Y)        CLEAR EXECUTION STATUS
          MVI   0,Y.INT(Y)        RESET SOME FLAGS
          LD    SP,Y.BASE+Y.CMDSP GET COMMAND STACK
*
*         FIND AUTOSTART ENTRYPOINT IN BASIC
*         ----------------------------------
*
          LDI   HL,0              SEARCH ALL...
          LDI   BC,6000H          MAX NUMBER OF BYTES TO SEARCH
*
SEARCH    LA    X,RUNSTR          STRING TO FIND
          LDI   DE,RUNSTRSZ       SIZE OF STRING
          L     A,(X)             GET FIRST CHARACTER
          BCMP  IR                FIND FIRST OCCURANCE
          JNZ   FATAL             FATAL ERROR: 'RUN' NOT FOUND
          DECD  HL                DUMMY
*
SEARCH2   INCD  HL
          INCD  X                 CHECK NEXT CHARACTER
          DECD  BC
          DECD  DE
          LR    A,D
          OR    E
          JZS   FOUNDIT           THAT'S IT!
          L     A,(X)             FETCH IT
          NR    A                 CHECK IF WILDCARD
          JZS   SEARCH2           YES, SKIP THE CHECK!
          C     (HL)              ELSE, CHECK IF MATCH
          JNZS  SEARCH            SORRY, NO MATCH THIS TIME!
          JMPS  SEARCH2           NEXT ONE!
*
          EJECT
*
*         ENTRYPOINT FOUND. GET PARAMETER STRING
*         --------------------------------------
*
FOUNDIT   =     *
          LDI   BC,-RUNSTRSZ
          ADR   HL,BC             HL NOW POINTS AT ENTRY (AFTER OPTION SCAN)
          PUSH  HL                WE WANT TO JUMP TO THIS ADDRESS...
*
          LA    HL,MCMDR.         CMDINT COMMAND STRING
*
SCANDR    L     A,(HL)            SKIP DEVICE IF GIVEN
          INCD  HL
          CI    ':'
          JZS   SKIPDR
          CI    0DH               END OF STRING?
          JZS   NODR
          CI    ','
          JZS   NODR
          CI    '/'
          JZS   NODR
          CI    ' '
          JNZS  SCANDR
*
NODR      LA    HL,MCMDR.         REWIND COMMAND STRING POINTER
SKIPDR    LA    DE,AUTOSTR        CHECK IF THE COMMAND IS 'RUN'
R1        L     A,(DE)
          CI    ' '               END OF RUN STRING?
          JZS   R2                YES, CHECK IF END OF COMMAND STRING
          C     (HL)              CHECK IF MATCH
          INCD  HL
          INCD  DE
          JZS   R1                KEEP ON CHECKING!
          JMPS  GETFILE
*
R2        C     (HL)              CHECK IF COMMAND TERMINATED
          JZS   RUNCMD            RUN GIVEN. GET FILE NAME AND PAR:S
          L     A,(HL)
          CI    ','               LEGAL TERMINATOR
          JZS   RUNCMD
          CI    '/'
          JZS   RUNCMD
          CI    0DH
          JZS   RUNCMD            NO, GET FILE NAME
*                                 IT IS NOT 'RUN'. GET FILE TO USE
GETFILE   LA    HL,MCMDR.         POINT AT FILE NAME
          LA    DE,AUTOFILE       PLACE TO PUT FILENAME (AND PARAMETERS)
*
AUTOCOPY  L     A,(HL)            COPY FILE NAME
          CI    ' '               END OF FILE NAME
          JZS   ENDAUTCP
          CI    0DH
          JZS   ENDAUTCP
          CI    ','               SWITCH DELIMITER
          JZS   ENDAUTCP
          CI    '/'
          JZS   ENDAUTCP
          CI    '.'               DON'T USE EXTENSION, IF ANY
          JZS   ENDAUTCP
          ST    A,(DE)            COPY
          INCD  HL
          INCD  DE
          JMPS  AUTOCOPY
*
ENDAUTCP  EXDR                    HL - AUTO START BUFFER
          MVI   ',',(HL)          PAR STRING DELIMITER
          INCD  HL
          MVI   -1,(HL)           MARK THAT WE'VE ENTERED FROM DOS
          INCD  HL
          EXDR                    DE - PLACE TO PUT PARAMETER STRING
          CALL  FIXPAR
*
EXITBAS   LA    HL,AUTOSTR        NOW, SET UP FOR GRANDE FINALE
          STD   HL,XQTPTR
*
          LI    C,8               CLEAR ALL TRAPS
          LDI   DE,0
CLRTRP    CALL  TRAP.
          DECR  C
          JNZS  CLRTRP
*
          LD    HL,BUFAD.         GET POINTER TO DOSBUF 0
          LI    L,0               REWIND
          LDI   BC,500H           DOSBUF 5
          ADR   HL,BC
          STD   HL,BASICTRP       MARK NEW BASICTRAP HANDLER
          EXDR
          LA    HL,BASTRPH        BASICTRAP HANDLER
          LDI   BC,BASTRPHZ
          BTRF  IR                COPY CODE (WHICH *MUST* BE RELOCATEABLE!)
*
          RET                     RUN THE FILE...
*
RUNCMD    =     *
          LA    DE,AUTOFILE       PLACE TO PUT FIXED UP PARAMETER STRING
          PUSH  DE                SAVE POINTER
          CALL  FIXPAR
          POP   DE                GET POINTER
          XR    A                 CLEAR CARRY
          PUSH  HL                SAVE END POINTER
          SBDR  HL,DE             GET PAR STRING LENGTH
          LR    B,H               BC := LENGTH
          LR    C,L
          POP   HL
*                                 CHECK IF FILENAME GIVEN
          L     A,(DE)            GET FIRST CHARACTER
          CI    'A'               MUST BE ALPHABETHIC
          JCS   NOTFND
          CI    ']'+1
          JNCS  NOTFND
*
SCANEOF   L     A,(DE)            FIND END OF FILE NAME
          CI    0DH               END IS ONE OF <CR>, "," AND " " (SPACE)
          JZS   FEOF1
          CI    ','
          JZS   FEOF
          CI    ' '
          JZS   FEOF
          INCD  DE
          DECD  BC
          JMPS  SCANEOF
*
FEOF1     EXDR                    CONVERT "<CR>" INTO ",<0FFH><CR>"
          MVI   ',',(HL)
          INCD  HL
          MVI   -1,(HL)
          INCD  HL
          ST    A,(HL)
          JMPS  EXITBAS
*
FEOF      PUSH  DE                SAVE PLACE WHERE TO INSERT STRING
          LR    D,H               COPY SOURCE POINTER
          LR    E,L
          INCD  DE                MOVE ONE STEP
          BTRF  DR
          POP   HL                GET PATCH POS
          MVI   ',',(HL)
          INCD  HL
          MVI   -1,(HL)
          JMPS  EXITBAS
*
          EJECT
*
NOTFND    =     *
          LA    HL,NOTFNDTX       TELL HIM HE MUST ISSUE A FILENAME...
          LDI   BC,NOTFNDTZ
          JMPS  ERREXIT
*
NOTFNDTX  DB    7,0DH,0AH,'FILE NAME MISSING!'
NOTFNDTZ  EQU   *-NOTFNDTX
*
FATAL     =     *
          LA    HL,ERRTXT         SAY SOMETHING ABOUT IT...
          LDI   BC,ERRTXTSZ
ERREXIT   CALL  11
          JMP   NXTCM.
*
ERRTXT    DB    7,0DH,0AH,'FATAL ERROR OCCURED!!!'
ERRTXTSZ  =     *-ERRTXT
*
          EJECT
*
*         BASIC TRAP HANDLER
*         ==================
*
*         N.B. THIS CODE *MUST* BE RELOCATEABLE!!!
*
BASTRPH   =     *
          L     E,LU.LFT(X)
          LI    D,0
          LA    HL,LFT.+PDN.
          ADR   HL,DE             CLEAR NSA FLAG.
          L     D,(HL)            TEST IF FILE OPEN
          INCR  D
          STC
          RZ
*
          CI    E.DOS+2           CHECK IF 'RECORD FORMAT ERROR'
          STC
          RZ
*
          RBT   NSA.,(HL)
          RET
*
BASTRPHZ  EQU   *-BASTRPH
*
          EJECT
*
          PLC   1                 ** THIS PLC SHOULD BE PLACED LAST **
*
AUTOSTR   DB    'RUN '            AUTO START STRING
AUTOFILE  EQU   *                 PLACE TO PUT BASIC FILE TO "AUTOSTART"
*
*         THIS DATA IS OVERWRITEABLE - USED ONLY ONCE
*         -------------------------------------------
*
RUNSTR    DB    355Q,163Q,0,0     SEARCH STRING
          DB    41Q,0,0
          DB    71Q
          DB    42Q,0,0
          DB    315Q,0,0
          DB    355Q,133Q,0,0
          DB    315Q,0,0
          DB    371Q
          DB    353Q
          DB    325Q
          DB    355Q,260Q
RUNSTRSZ  EQU   *-RUNSTR
*
          END   START
