    '
    '              Eamon
    '        GoAdvent  Program
    '
    '          by John Nelson
    '
    '
    '
    '  This program get the name of an adventure and runs the next program
    '
    DECLARE SUB Sort (AN$(), NA%)
    DECLARE FUNCTION Center$ (L$, L!)
    DECLARE SUB ReadDir (MPath$, DNam$(), D%)
    ON ERROR GOTO NoColors
    OPEN "EAMCOLOR" FOR INPUT AS #1
    INPUT #1, fgc%
    INPUT #1, bgc%
    INPUT #1, hfg%
    INPUT #1, hbg%
    INPUT #1, brt%
    CLOSE
In.BW:
    ON ERROR GOTO 0
    OPEN "EamonCtl" FOR INPUT AS #1
    INPUT #1, Prog$
    CLOSE 1
    COLOR fgc%, bgc%
    DIM DNam$(X)
    MASTPATH$ = ""
    ReadDir MASTPATH$, DNam$(), D%
PickfromList:
    CLS
    Esc = 0
    A = 1
    LOCATE 4, 20
    PRINT "Press <RETURN> to Select ..."
    LOCATE 23, 1
    PRINT "Use Up/Down Arrows to change adventures"
    ON ERROR GOTO NoNameFile
    DO
        OPEN AdvPath$ + DNam$(A) + "\EAMON.NAM" FOR INPUT AS #1
        INPUT #1, X$, Adv$
        CLOSE 1
        LOCATE 6, 20, 0
        COLOR hfg%, hbg%
        PRINT Center$(Adv$, 40)
        COLOR fgc%, bgc%
        DO
            A$ = INKEY$
        LOOP UNTIL A$ <> ""
' ===
        IF A$ = CHR$(0) + CHR$(80) THEN
            IF A < D% THEN A = A + 1
        END IF
        IF A$ = CHR$(0) + CHR$(81) THEN
            A = A + 10
            IF A > D% THEN A = D%
        END IF
        IF A$ = CHR$(0) + CHR$(73) THEN
            A = A - 10
            IF A < 1 THEN A = 1
        END IF
        IF A$ = CHR$(0) + CHR$(72) THEN
            IF A > 1 THEN A = A - 1
        END IF
        IF A$ = CHR$(0) + CHR$(71) THEN A = 1
        IF A$ = CHR$(0) + CHR$(79) THEN A = D%
        IF A$ = CHR$(27) THEN Esc = -1: EXIT DO
' ===
        IF A$ = CHR$(0) + CHR$(71) THEN A = 1
        IF A$ = CHR$(0) + CHR$(79) THEN A = D%
        IF A$ = CHR$(27) THEN Esc = -1: EXIT DO
    LOOP UNTIL A$ = CHR$(13)
    IF Esc THEN CLS : LOCATE 10, 1: GOTO EndProg
    IF AdvPath$ <> "" THEN
        AdvPath$ = AdvPath$ + DNam$(A)
    ELSE
        AdvPath$ = DNam$(A)
    END IF
    ON ERROR GOTO 0
    GOTO EndProg
NoNameFile:
    DNam$(A) = DNam$(D%)
    D% = D% - 1
    IF A > D% THEN A = D%
    RESUME
EndProg:
    OPEN "ADVPATH.DAT" FOR OUTPUT AS #1
    PRINT #1, DNam$(A)
    CLOSE 1
    RUN "DDD\DUNGEDIT"
NoColors:
    fgc% = 7
    bgc% = 0
    hfg% = 0
    hbg% = 7
    RESUME In.BW

FUNCTION Center$ (L$, L)
        C = L - LEN(L$)
        IF C < 2 THEN C = 0 ELSE C = C \ 2
        PRINT SPC(C); L$; SPC(C);

END FUNCTION

DEFINT A-Z
SUB ReadDir (MPath$, DNam$(), D%)
        SHELL "DIR " + Path$ + " >DIRFIL"
        OPEN "DIRFIL" FOR INPUT AS #1
        MaxDir = 200
        ArenaSw = 0
        REDIM DNam$(MaxDir)
        D% = 0
        DO UNTIL EOF(1)
          LINE INPUT #1, DLin$
          Dov = INSTR(DLin$, "Directory of ")
          IF Dov > 0 THEN MPath$ = MID$(DLin$, Dov + 13)
          I = INSTR(DLin$, "<DIR>")
          IF I > 0 THEN
              IF LEFT$(DLin$, 3) = "ADV" THEN
                  D% = D% + 1
                  DNam$(D%) = LEFT$(DLin$, 12)
              END IF
          ELSE
              V = INSTR(DLin$, "EAMON")
              N = INSTR(DLin$, "NAM")
              IF V = 1 AND N > V THEN
                  D% = D% + 1
                  DNam$(D%) = "."
              END IF
          END IF
          A = INSTR(DLin$, "ARENA")
          IF A > 0 THEN ArenaSw = -1
        LOOP
        CLOSE 1
        Sort DNam$(), D%
        Path$ = MPath$


END SUB

SUB Sort (AN$(), NA)
    IM = NA
SRT.1:
    IM = INT(IM / 2)
    IF IM = 0 THEN EXIT SUB
    K = NA - IM
    J = 1
SRT.2:
    I = J
SRT.3:
    L = I + IM
    IF AN$(I) <= AN$(L) THEN GOTO SRT.4
    SWAP AN$(I), AN$(L)
    ' SWAP REC%(I), REC%(L)
    I = I - IM
    IF I >= 1 THEN GOTO SRT.3
SRT.4:
    J = J + 1
    IF J <= K THEN GOTO SRT.2
    GOTO SRT.1

END SUB

