$CPU 8086                 ' program works on any CPU
$OPTIMIZE SIZE            ' make smallest possible executable
$COMPILE EXE              ' compile to an EXE
$DEBUG MAP OFF            ' turn off map file generation
$DEBUG PBDEBUG OFF        ' don't include pbdebug support in our executable
$LIB COM        OFF       ' turn off PowerBASIC's communications library.
$LIB CGA        OFF       ' turn off PowerBASIC's CGA graphics library.
$LIB EGA        OFF       ' turn off PowerBASIC's EGA graphics library.
$LIB VGA        OFF       ' turn off PowerBASIC's VGA graphics library.
$LIB HERC       OFF       ' turn off PowerBASIC's hercules graphics library.
$LIB LPT        OFF       ' turn off PowerBASIC's printer support library.
$LIB IPRINT     OFF       ' turn off PowerBASIC's interpreted print library.
$LIB FULLFLOAT  OFF       ' turn off PowerBASIC's floating point support.
$ERROR BOUNDS   OFF       ' turn off bounds checking
$ERROR NUMERIC  OFF       ' turn off numeric checking
$ERROR OVERFLOW OFF       ' turn off overflow checking
$ERROR STACK    OFF       ' turn off stack checking
$COM    0                 ' set communications buffer to nothing
$STRING 16                ' set largest string size at 16k
$STACK  2048              ' let's use a 2k stack
$SOUND  1                 ' smallest music buffer possible
$DIM ARRAY                ' force arrays to be pre-dimensioned before they can
                          ' be used
$DYNAMIC                  ' all arrays will be dynamic by default
$OPTION CNTLBREAK OFF     ' don't allow Ctrl-Break to exit program
DEFINT A-Z                ' default all variables to integers for maximum
                          ' speed and minimum size

COLOR 11, 0
Versie$ = "2.65"
P$ = LTRIM$(RTRIM$(UCASE$(COMMAND$)))
PRINT "MicroBASIC Extensions Information Viewer v1.4 (MBX v" + Versie$ + ")"
PRINT : COLOR 14

IF INSTR(P$, "?") OR INSTR(P$, "/H") OR P$ = "" THEN
  PRINT "With this program you can display information about MBX-files, if they contain"
  PRINT "information."
  PRINT
  PRINT "Usage: MBXINFO mbxfile[.mbx] [/VERBOSE]"
  PRINT
  PRINT "mbxfile     The input MBX (MicroBASIC Extension) file. Extension not required."
  PRINT "/VERBOSE    Gives more detailed information."
  GOTO Einde
END IF


DIM Pars$(15)
Par$ = LTRIM$(RTRIM$(UCASE$(COMMAND$)))
Pars=1:v$=" "
FOR a = 1 to LEN(Par$)
  IF MID$(Par$,a,1)=" " THEN
    IF v$ <> " " then Pars=Pars+1
  ELSE
    Pars$(Pars)=Pars$(Pars)+mid$(Par$,a,1)
  END IF
  v$=MID$(Par$,a,1)
NEXT a

Text = 1

P$=""
for a = 1 to Pars
  if left$(Pars$(a),1)="/" THEN
    select case Pars$(a)
      case "/VERBOSE"
        Verbose = 1
      case else
        beep
        print "Invalid parameter "+Pars$(a)
        end
    end select
  else
    b=b+1
    p$=p$+Pars$(a)+" "
    if b>1 then
      b=2
      print "Too many parameters!"
      end
    end if
  end if
next a
MBXFile$ = rtrim$(p$)


IF Verbose = 1 then PRINT "VERBOSE MODE"

IF INSTR(MBXFile$, ".") = 0 THEN MBXFile$ = MBXFile$ + ".MBX"
PRINT "þ Opening file...";
IF DIR$(MBXFile$) = "" THEN
  PRINT "Error!": BEEP
  PRINT "Specified .MBX file not found (" + MBXFile$ + ")!"
  GOTO Einde
END IF
OPEN MBXFile$ FOR BINARY AS #1
IF LOF(1) = 0 THEN
  CLOSE #1
  PRINT "Error!": BEEP
  PRINT "Specified .MBX file is empty (" + MBXFile$ + ")!"
  GOTO Einde
END IF
PRINT "OK"
PRINT "þ Checking header...";
MBXHeader$ = SPACE$(21)
GET #1, , MBXHeader$
IF MBXHeader$ <> "MicroBASIC Extension" + CHR$(26) THEN
  CLOSE #1
  PRINT "Error! "; : COLOR 15: PRINT MBXHeader$: COLOR 14: BEEP
  PRINT "Invalid header in specified .MBX file (" + MBXFile$ + ")!"
  GOTO Einde
END IF
PRINT "OK"
PRINT "þ Checking MBX-file version...";
Byte$ = " "
GET #1, , Byte$: MBXVer$ = LTRIM$(RTRIM$(STR$(ASC(Byte$)))) + "."
GET #1, , Byte$: MBXVer$ = MBXVer$ + LTRIM$(RTRIM$(STR$(ASC(Byte$))))
GET #1, , Byte$: MBXVer$ = MBXVer$ + LTRIM$(RTRIM$(STR$(ASC(Byte$))))
IF MBXVer$ > Versie$ THEN
  CLOSE #1
  PRINT "Error!": BEEP: PRINT "  ÀÄ[MBX Version " + MBXVer$ + "]ÄÙ"
  PRINT "Specified .MBX requires newer version (" + MBXFile$ + ")!"
  PRINT "Please download the newest version at http://come.to/blacklight"
  GOTO Einde
END IF
PRINT "OK": PRINT "  ÀÄ[MBX Version " + MBXVer$ + "]ÄÙ"

3 IF SEEK(1) >= LOF(1) THEN CLOSE #1: GOTO 1
  GET #1, , Byte$
  IF Verbose THEN PRINT USING "Offset: ####  "; SEEK(1) - 1;
  IF Byte$ = CHR$(1) THEN
    GET #1, , Byte$: MBXNaam$ = SPACE$(ASC(Byte$)): GET #1, , MBXNaam$
    IF Verbose THEN PRINT "01h = Name: "; : COLOR 15: PRINT MBXNaam$: COLOR 14
    GOTO 3
  END IF
  IF Byte$ = CHR$(2) THEN
    GET #1, , Byte$: MBXSize = ASC(Byte$) * 256
    GET #1, , Byte$: MBXSize = MBXSize + ASC(Byte$)
    Size = Size + MBXSize
    IF Verbose THEN PRINT "02h = Size: " + LTRIM$(RTRIM$(STR$(MBXSize))) + " bytes"
    GOTO 3
  END IF
  IF Byte$ = CHR$(3) THEN
    MBXRoutine$ = SPACE$(MBXSize)
    GET #1, , MBXRoutine$
    IF Verbose THEN PRINT "03h = <<<Routine>>>"
    GOTO 3
  END IF
  IF Byte$ = CHR$(4) THEN
    Size = Size + 3
    IF Verbose THEN PRINT "04h = Insert Text-parameter and add $-sign."
    GOTO 3
  END IF
  IF Byte$ = CHR$(5) THEN
    Size = Size + 3
    IF Verbose THEN PRINT "05h = Insert Text-parameter and add zero."
    GOTO 3
  END IF
  IF Byte$ = CHR$(6) THEN
    Size = Size + 2
    IF Verbose THEN PRINT "06h = Insert Text-parameter."
    GOTO 3
  END IF
  IF Byte$ = CHR$(7) THEN
    Size = Size + 2
    IF Verbose THEN PRINT "07h = Insert label-pointer."
    GOTO 3
  END IF
  IF Byte$ = CHR$(8) THEN
    Size = Size + 1
    IF Verbose THEN PRINT "08h = Insert 0-255 value"
    GOTO 3
  END IF
  IF Byte$ = CHR$(9) THEN
    Size = Size + 2
    IF Verbose THEN PRINT "09h = Insert 0-65535 value"
    GOTO 3
  END IF
  IF Byte$ = CHR$(32) THEN
    IF Verbose THEN PRINT "20h = Space (no function)."
    GOTO 3
  END IF
  IF Byte$ = CHR$(254) THEN
    GET #1, , Byte$: MBXCmt$ = SPACE$(ASC(Byte$)): GET #1, , MBXCmt$
    IF Verbose THEN PRINT "FEh = ";
    PRINT "Comment block: ";:COLOR 15:PRINT MBXCmt$:COLOR 14
    GOTO 3
  END IF
  IF Byte$ = CHR$(255) THEN
    IF Verbose THEN PRINT "FFh = End of file identifier"
    EOFSigns = EOFSigns + 1
    GOTO 3
  END IF
  PRINT HEX$(ASC(Byte$)) + "h = UNKNOWN!!! " + Byte$: BEEP
  GOTO 3

1 IF Verbose THEN PRINT "þ ";
IF Verbose THEN IF EOFSigns = 0 THEN PRINT "Unexpected ";
IF Verbose THEN PRINT "End of MBX-file"
PRINT
PRINT "MBX uses";Size;"bytes + length of text-parameters in COM/EXE file."

Einde:
COLOR 11:PRINT
PRINT "Copyright (C) 1995-2000 BlackLight. All rights reserved.";
COLOR 7, 0:PRINT
SYSTEM
