DECLARE FUNCTION found! (a$)
DECLARE FUNCTION hex4$ (a$)
DECLARE FUNCTION qual$ (a$)
DECLARE FUNCTION SVB$ (a!)
DECLARE FUNCTION SVE! (a$)
DECLARE FUNCTION ASS$ (a$)
DECLARE FUNCTION ISR$ (a$)
DECLARE FUNCTION PAT2$ (a$)
DECLARE FUNCTION nec$ (a$, c, d)
DECLARE FUNCTION hex2$ (a$)
DECLARE FUNCTION hex3$ (a$)
DECLARE FUNCTION cut$ (a$)
DECLARE FUNCTION ident$ (a$, lln, cp, qt)
DECLARE FUNCTION PAT1$ (a$)
REM This is a Compiler for Qbasic/QuickBasic.. I know there are some bugs,
REM or instruction sets missing, should you come across any problems, by bugs
REM or any instruction sets, email me as soon as you can, and i will take
REM care of it.
REM

PRINT "Assembler V1.48 Made in QBASIC, and assembles ASSEMBLER code into"
PRINT "Machine Language.. This is not yet perfected, but please send me"
PRINT "information on the bugs.. Era Scarecrow"
PRINT

'a$ = COMMAND$
a$ = "XP"
IF LEN(a$) > 3 THEN
   FOR a = 1 TO LEN(a$)
      'PRINT a, 1
      IF MID$(a$, a, 1) = " " THEN b = a: GOTO 25
   NEXT a
   25
   FOR a = b + 1 TO LEN(a$)
      'PRINT a, 2
      IF MID$(a$, a, 1) = " " THEN GOTO 26
   NEXT a
   26
   IF a > LEN(a$) THEN
      file1$ = MID$(a$, 1, b - 1)
      file2$ = MID$(a$, b + 1, LEN(a$) - b)
      a$ = ""
      'STOP
   END IF
   IF a < LEN(a$) THEN
      file1$ = MID$(a$, b + 1, a - (b + 1))
      file2$ = MID$(a$, a + 1, LEN(a$) - b)
      a$ = MID$(a$, 1, b - 1)
   END IF
END IF
FOR a = 1 TO LEN(a$)
   IF MID$(a$, a, 1) = "X" THEN
      'file1$ = "c:\temp\asm\filex2.txt"
      file1$ = "c:\temp\asm\junk2.txt"
      file2$ = "c:\temp\asm\file2.txt"
   END IF
   IF MID$(a$, a, 1) = "D" THEN dbg = 1' d debug code enabled?
   IF MID$(a$, a, 1) = "P" THEN percent = 1
NEXT a


IF file1$ = "" OR file2$ = "" THEN
   PRINT "Assembler Usage: Assemble [DXP] [File1.asm] [File2.com]"
   PRINT "Other options:"
   PRINT
   PRINT "D - Debug code.. (True assembly)"
   PRINT "X - Default Files - Junk2.txt File2.txt"
   PRINT "P - Precent follow (For LOTS of labels to help)"
   PRINT
   GOTO 17
END IF
'STOP

OPEN file1$ FOR INPUT AS #1
OPEN "Temp.asm" FOR OUTPUT AS #2
'OPEN file2$ FOR OUTPUT AS #2
PRINT "Assmebly File: "; file1$
DO
   LINE INPUT #1, a$
   IF LEFT$(a$, 1) <> "#" AND LEFT$(a$, 1) <> "*" AND LEFT$(a$, 1) <> "!" THEN
      PRINT #2, a$
   END IF
LOOP UNTIL EOF(1)
SEEK #1, 1
DO
   LINE INPUT #1, a$
   IF LEFT$(a$, 1) = "*" THEN
      IF fileopen1 = 1 THEN
         CLOSE #3
      END IF
      incl$ = RIGHT$(a$, LEN(a$) - 1)
      OPEN incl$ FOR INPUT AS #3
      DO
         LINE INPUT #3, a$
         PRINT #2, a$
      LOOP UNTIL EOF(3)
      CLOSE #3
   END IF
   IF LEFT$(a$, 1) = "#" THEN
      IF fileopen1 = 1 THEN
         CLOSE #3
      END IF

      IF fileopen1 = 0 THEN
         fileopen1 = 1
         incl$ = RIGHT$(a$, LEN(a$) - 1)
         OPEN incl$ FOR INPUT AS #3
      END IF

   END IF

   IF LEFT$(a$, 1) = "!" AND fileopen1 = 1 THEN
      SEEK #3, 1
      lln = 0
      lne = LOF(3)
      lnc = LOF(3)

      incl$ = RIGHT$(a$, LEN(a$) - 1)
      DO
         LINE INPUT #3, a$
         'PRINT a$, incl$
         'STOP
         lln = lln + 1
         IF LEFT$(a$, 1) = "!" THEN
            incr$ = MID$(a$, 2, LEN(incl$))
            IF incr$ = incl$ THEN
               'STOP
               FOR a = LEN(incl$) + 3 TO LEN(a$)
                  IF MID$(a$, a, 1) = " " THEN b = a
               NEXT a
               lnc = VAL(MID$(a$, LEN(incl$) + 3, b - (LEN(incl$) + 3)))
               lne = VAL(MID$(a$, b + 1, LEN(a$) - b))
               'STOP
            END IF
         END IF
         IF lln >= lnc AND lln <= lne THEN
            'STOP
            'PRINT a$
            PRINT #2, a$
         END IF
         IF lnn > lne THEN GOTO 28
      LOOP UNTIL EOF(3)
      28
   END IF


LOOP UNTIL EOF(1)
CLOSE #1
CLOSE #2
OPEN "Temp.asm" FOR INPUT AS #1
OPEN file2$ FOR OUTPUT AS #2
lln = 0
cp = 256
cpz = 0
qt = 1
lne = 1
lnc = 3
cp1 = 7
lnes$ = STRING$(13000, CHR$(0))
MID$(lnes$, 1, 6) = CHR$(3) + "CPX  "
DO
   lln = lln + 1

   9
   LINE INPUT #1, a$
   'STOP
   b = LEN(a$) + 1
   FOR a = LEN(a$) TO 1 STEP -1
      IF MID$(a$, a, 1) = ";" THEN b = a
   NEXT a
   b$ = LEFT$(a$, b - 1)
   a$ = b$
   b$ = cut$(UCASE$(a$))
   IF RIGHT$(b$, 1) = ":" THEN
      IF b$ = "CS:" OR b$ = "DS:" OR b$ = "ES:" OR b$ = "SS:" THEN GOTO 20
      'STOP
      lnb = LEN(b$)
      IF lnb > lnc THEN lnc = lnb
      MID$(lnes$, cp1, (LEN(b$) + 2)) = CHR$(LEN(b$) - 1) + LEFT$(b$, LEN(b$) - 1) + SVB$(cp)
      cp1 = cp1 + LEN(b$) + 2
      lne = lne + 1
      'STOP
   END IF
   IF LEFT$(b$, 1) = "$" THEN
      lnb = LEN(b$) - 1
      IF lnb > lnc THEN lnc = lnb
      MID$(lnes$, cp1, (lnb + 3)) = CHR$(lnb) + RIGHT$(b$, lnb) + SVB$(cp)
      cp1 = cp1 + LEN(b$) + 2
      lne = lne + 1
      'STOP
   END IF
   IF LEFT$(b$, 1) = "@" THEN
      'STOP
      FOR a = 1 TO LEN(b$)
         IF MID$(b$, a, 1) = " " THEN b$ = MID$(b$, 2, a - 2): GOTO 27
      NEXT a
      27
      lnb = a - 2
      IF lnb > lnc THEN lnc = lnb
      MID$(lnes$, cp1, (lnb + 3)) = CHR$(lnb) + MID$(b$, 1, lnb) + SVB$(cp)
      cp1 = cp1 + a + 1
      lne = lne + 1
      'STOP
   END IF
   20
   'PRINT #2, a$;
LOOP UNTIL EOF(1)
SEEK #1, 1
lnes1$ = LEFT$(lnes$, cp1)
'lnes$ = lnes1$
cp = 1
lln2 = lln
PRINT "Lines of Assembly:"; lln
PRINT "Labels (Jumps? Locations?):"; lne
'STOP
FOR lln = lnc TO 1 STEP -1
   cp1 = 1
   FOR a = 1 TO lne
      b = ASC(MID$(lnes$, cp1, 1))
      IF b = lln THEN
         lnn$ = MID$(lnes$, cp1 + 1, b)
         MID$(lnes1$, cp, b + 3) = CHR$(b) + lnn$ + SVB$(0)
         cp = cp + b + 3
      END IF
      cp1 = cp1 + (b + 3)
   NEXT a
NEXT lln
cp1 = 1
'STOP
lnes$ = ""
'lnes1$ = ""
cp = 256
FOR a = 1 TO lne
   b = ASC(MID$(lnes1$, cp1, 1))
   lnn$ = MID$(lnes1$, cp1 + 1, b)
   IF lnn$ = "CPX" THEN cpx = cp1 + 4
   cp1 = cp1 + (b + 3)
NEXT a
'STOP
lnn = 0
cpcp = 0
PRINT "Prepair Progress:"
DO
   MID$(lnes1$, cpx, 2) = SVB$(cp)
   'STOP
   lln = lln + 1
   IF percent = 1 THEN
      aaa = INT((lln / lln2) * 1000)
      aaa = aaa / 10
      IF aaa <> aab THEN
         aab = aaa
         a$ = STR$(aab)
         PRINT SPACE$(5 - LEN(a$)); a$; "|";
      END IF
   END IF
   14
   LINE INPUT #1, a$
   'IF LEFT$(a$, 1) = "@" THEN STOP
   'STOP
   b = LEN(a$) + 1
   FOR a = LEN(a$) TO 1 STEP -1
      IF MID$(a$, a, 1) = ";" THEN b = a
   NEXT a
   b$ = LEFT$(a$, b - 1)
   a$ = b$
   b$ = cut$(UCASE$(a$))
   IF LEFT$(b$, 4) = "DB " + CHR$(34) THEN MID$(b$, 4, LEN(b$) - 4) = MID$(a$, 4, LEN(b$) - 4)
   'IF B$ = "" THEN GOTO 9
   'PRINT b$
   IF LEFT$(b$, 5) = "-CPX " OR LEFT$(b$, 5) = "+CPX " THEN
      MID$(b$, 2, 3) = "cpx"
      'STOP
   END IF

   13
   cp1 = 1
   'PRINT b$
   'STOP
   FOR a = 1 TO lne
      b = ASC(MID$(lnes1$, cp1, 1))
      lnn$ = MID$(lnes1$, cp1 + 1, b)
      cp1 = cp1 + (b + 3)
      FOR b = 1 TO LEN(b$) - (LEN(lnn$) - 1)
         IF MID$(b$, b, LEN(lnn$)) = lnn$ THEN
            IF b$ = lnn$ + ":" THEN
               MID$(lnes1$, cp1 - 2, 2) = SVB$(cp)
               lus = cp
               'lne = lne + 1
               'STOP
               b$ = ";"
               GOTO 13
            END IF
            IF b$ = "$" + lnn$ THEN
               MID$(lnes1$, cp1 - 2, 2) = SVB$(cp - lus)
               'lne = lne + 1
               'STOP
               b$ = ";"
               GOTO 13
            END IF
            'IF LEFT$(b$, 1) = "@" THEN STOP
            IF LEFT$(b$, LEN(lnn$) + 1) = "@" + lnn$ THEN
               MID$(lnes1$, cp1 - 2, 2) = hex3$(RIGHT$(b$, 4))
               IF lnn$ = "CPX" THEN cp = SVE(MID$(lnes1$, cp1 - 2, 2))
               'lne = lne + 1
               'STOP
               b$ = ";"
               GOTO 13
            END IF
            IF b > 1 THEN
               IF MID$(b$, b - 1, 1) = "`" THEN
                  a = ASC(MID$(lnes1$, cp1 - 1, 1))
                  cp1 = LEN(HEX$(a))
                  a$ = LEFT$(b$, b - 2) + STRING$(2 - cp1, "0") + HEX$(a) + MID$(b$, b + LEN(lnn$), LEN(a$) - (b + 1))
                  b$ = a$
                  GOTO 13
               END IF
               IF MID$(b$, b - 1, 1) = "'" THEN
                  a = ASC(MID$(lnes1$, cp1 - 2, 1))
                  cp1 = LEN(HEX$(a))
                  a$ = LEFT$(b$, b - 2) + STRING$(2 - cp1, "0") + HEX$(a) + MID$(b$, b + LEN(lnn$), LEN(a$) - (b + 1))
                  b$ = a$
                  GOTO 13
               END IF
            END IF

            a = SVE(MID$(lnes1$, cp1 - 2, 2))
            cp1 = LEN(HEX$(a))
            a$ = LEFT$(b$, b - 1) + STRING$(4 - cp1, "0") + HEX$(a) + MID$(b$, b + LEN(lnn$), LEN(a$) - (b + 1))
            'STOP
            b$ = a$
            GOTO 13
            'STOP
         END IF
      NEXT b
      'STOP
   NEXT a
   29
   IF LEFT$(b$, 4) = "+cpx " THEN
      cp = cp + SVE(hex3$(RIGHT$(b$, 4)))
   END IF
   IF LEFT$(b$, 4) = "-cpx " THEN
      cp = cp - SVE(hex3$(RIGHT$(b$, 4)))
   END IF

   'PRINT b$
   a$ = ident$(b$, lln, cp, qt)
   cpcp = cpcp + LEN(a$)
   cp = cp + LEN(a$)
   'PRINT #2, a$;
   'PRINT b$
LOOP UNTIL EOF(1)
PRINT "Size of Output:"; cpcp
SEEK #1, 1
cp = 256
lln = 0
qt = 0

PRINT
PRINT "Making .COM file:"
DO
   MID$(lnes1$, cpx, 2) = SVB$(cp)
   lln = lln + 1
   IF percent = 1 THEN
      aaa = INT((lln / lln2) * 1000)
      aaa = aaa / 10
      IF aaa <> aab THEN
         aab = aaa
         a$ = STR$(aab)
         PRINT SPACE$(5 - LEN(a$)); a$; "|";
      END IF
   END IF
   'PRINT lln
   LINE INPUT #1, a$
   'STOP
   b = LEN(a$) + 1
   FOR a = LEN(a$) TO 1 STEP -1
      IF MID$(a$, a, 1) = ";" THEN b = a
   NEXT a
   b$ = LEFT$(a$, b - 1)
   a$ = b$
   b$ = cut$(UCASE$(a$))
   IF LEFT$(b$, 4) = "DB " + CHR$(34) THEN MID$(b$, 4, LEN(b$) - 4) = MID$(a$, 4, LEN(b$) - 4)
   'IF B$ = "" THEN GOTO 9
   'PRINT b$
   15
   cp1 = 1
   IF LEFT$(b$, 4) = "-CP " OR LEFT$(b$, 4) = "+CP " THEN
      MID$(b$, 2, 2) = "cp"
   END IF

   FOR a = 1 TO lne
      b = ASC(MID$(lnes1$, cp1, 1))
      lnn$ = MID$(lnes1$, cp1 + 1, b)
      'PRINT lnn$
      cp1 = cp1 + (b + 3)
      IF b$ = lnn$ + ":" THEN b$ = ";": GOTO 18
      IF b$ = "$" + lnn$ THEN b$ = ";": GOTO 18

      IF LEFT$(b$, 5) = "@CPX " THEN
         cp = SVE(hex3$(RIGHT$(b$, 4)))
      END IF

      IF LEFT$(b$, LEN(lnn$) + 1) = "@" + lnn$ THEN b$ = ";": GOTO 18
      FOR b = 1 TO LEN(b$) - (LEN(lnn$) - 1)
         IF MID$(b$, b, LEN(lnn$)) = lnn$ THEN
            IF b > 1 THEN
               IF MID$(b$, b - 1, 1) = "`" THEN
                  a = ASC(MID$(lnes1$, cp1 - 1, 1))
                  cp1 = LEN(HEX$(a))
                  a$ = LEFT$(b$, b - 2) + STRING$(2 - cp1, "0") + HEX$(a) + MID$(b$, b + LEN(lnn$), LEN(a$) - (b + 1))
                  b$ = a$
                  GOTO 15
               END IF
               IF MID$(b$, b - 1, 1) = "'" THEN
                  a = ASC(MID$(lnes1$, cp1 - 2, 1))
                  cp1 = LEN(HEX$(a))
                  a$ = LEFT$(b$, b - 2) + STRING$(2 - cp1, "0") + HEX$(a) + MID$(b$, b + LEN(lnn$), LEN(a$) - (b + 1))
                  b$ = a$
                  GOTO 15
               END IF
            END IF
            a = SVE(MID$(lnes1$, cp1 - 2, 2))
            cp1 = LEN(HEX$(a))
            a$ = LEFT$(b$, b - 1) + STRING$(4 - cp1, "0") + HEX$(a) + MID$(b$, b + LEN(lnn$), LEN(a$) - (b + 1))
            'STOP
            b$ = a$
            'PRINT b$
            GOTO 15
            'STOP
         END IF
      NEXT b
   NEXT a
   'STOP
   18
   IF LEFT$(b$, 4) = "+cp " THEN
      cp = cp + SVE(hex3$(RIGHT$(b$, 4)))
      b$ = ";"
   END IF
   IF LEFT$(b$, 4) = "-cp " THEN
      cp = cp - SVE(hex3$(RIGHT$(b$, 4)))
      b$ = ";"
   END IF

   'PRINT b$
   a$ = ident$(b$, lln, cp, qt)
   d$ = HEX$(cp)
   IF dbg = 1 THEN PRINT STRING$(4 - LEN(d$), "0") + d$; " |" + STR$(LEN(a$)) + "| " + b$
   cp = cp + LEN(a$)
   PRINT #2, a$;
LOOP UNTIL EOF(1)
CLOSE #1
CLOSE #2
17
PRINT
PRINT "Thanks for using my Assembler :)"
PRINT "rtcvb32@coffey.com, Era Scarecrow 2/29/00"
PRINT "Last Updated: 4/05/00"

FUNCTION ASS$ (a$)
'LEVEL 1
lv = 0
x$ = ""
LC = LEN(a$)
IF a$ = "[BX+SI]" THEN cde = 0: GOTO 12
IF a$ = "[BX+DI]" THEN cde = 1: GOTO 12
IF a$ = "[BP+SI]" THEN cde = 2: GOTO 12
IF a$ = "[BP+DI]" THEN cde = 3: GOTO 12
IF a$ = "[SI]" THEN cde = 4: GOTO 12
IF a$ = "[DI]" THEN cde = 5: GOTO 12
IF LEN(a$) = 6 THEN
   IF MID$(a$, 1, 1) = "[" AND MID$(a$, 6, 1) = "]" THEN
      cde = 6
      x$ = hex3$(MID$(a$, 2, 4))
      GOTO 12
   END IF
END IF
'STOP
IF a$ = "[BX]" THEN
   'STOP
   cde = 7
   GOTO 12
END IF
'LEVEL 2... 8 BITS MORE
lv = 1
IF LEFT$(a$, 7) = "[BX+SI+" AND LC = 10 THEN
   cde = 0
   x$ = hex2$(MID$(a$, 8, 2))
   GOTO 12
END IF
IF LEFT$(a$, 7) = "[BX+DI+" AND LC = 10 THEN
   cde = 1
   x$ = hex2$(MID$(a$, 8, 2))
   GOTO 12
END IF
IF LEFT$(a$, 7) = "[BP+SI+" AND LC = 10 THEN
   cde = 2
   x$ = hex2$(MID$(a$, 8, 2))
   GOTO 12
END IF
IF LEFT$(a$, 7) = "[BP+DI+" AND LC = 10 THEN
   cde = 3
   x$ = hex2$(MID$(a$, 8, 2))
   GOTO 12
END IF
IF LEFT$(a$, 4) = "[SI+" AND LC = 7 THEN
   cde = 4
   x$ = hex2$(MID$(a$, 5, 2))
   GOTO 12
END IF
IF LEFT$(a$, 4) = "[DI+" AND LC = 7 THEN
   cde = 5
   x$ = hex2$(MID$(a$, 5, 2))
   GOTO 12
END IF
IF LEFT$(a$, 4) = "[BP+" AND LC = 7 THEN
   cde = 6
   x$ = hex2$(MID$(a$, 5, 2))
   GOTO 12
END IF
IF LEFT$(a$, 4) = "[BX+" AND LC = 7 THEN
   cde = 7
   x$ = hex2$(MID$(a$, 5, 2))
   GOTO 12
END IF

'LEVEL THREE, 16 BITS MORE
lv = 2
IF LEFT$(a$, 7) = "[BX+SI+" AND LC = 12 THEN
   cde = 0
   x$ = hex3$(MID$(a$, 8, 4))
   GOTO 12
END IF
IF LEFT$(a$, 7) = "[BX+DI+" AND LC = 12 THEN
   cde = 1
   x$ = hex3$(MID$(a$, 8, 4))
   GOTO 12
END IF
IF LEFT$(a$, 7) = "[BP+SI+" AND LC = 12 THEN
   cde = 2
   x$ = hex3$(MID$(a$, 8, 4))
   GOTO 12
END IF
IF LEFT$(a$, 7) = "[BP+DI+" AND LC = 12 THEN
   cde = 3
   x$ = hex3$(MID$(a$, 8, 4))
   GOTO 12
END IF
IF LEFT$(a$, 4) = "[SI+" AND LC = 9 THEN
   cde = 4
   x$ = hex3$(MID$(a$, 5, 4))
   GOTO 12
END IF
IF LEFT$(a$, 4) = "[DI+" AND LC = 9 THEN
   cde = 5
   x$ = hex3$(MID$(a$, 5, 4))
   GOTO 12
END IF
IF LEFT$(a$, 4) = "[BP+" AND LC = 9 THEN
   cde = 6
   x$ = hex3$(MID$(a$, 5, 4))
   GOTO 12
END IF
IF LEFT$(a$, 4) = "[BX+" AND LC = 9 THEN
   cde = 7
   x$ = hex3$(MID$(a$, 5, 4))
   GOTO 12
END IF
lv = 3
'cde = 0
IF LEN(a$) = 2 THEN x$ = hex2$(a$)
IF LEN(a$) = 4 THEN x$ = hex3$(a$)
'X$ = ""
'STOP
12
IF lv < 3 THEN ASS$ = CHR$(lv) + CHR$(cde) + x$
IF lv = 3 THEN ASS$ = CHR$(lv) + x$
END FUNCTION

FUNCTION cut$ (a$)
'b$ = a$
b$ = ""
c = 1
3
FOR a = c TO LEN(a$)
   'PRINT ASC(MID$(a$, a, 1))
   IF MID$(a$, a, 1) <> " " AND MID$(a$, a, 1) <> CHR$(9) THEN b = a: GOTO 1
NEXT a
b = LEN(a$) + 1
GOTO 4
1
FOR a = b TO LEN(a$)
   'PRINT ASC(MID$(a$, a, 1))
   IF MID$(a$, a, 1) = " " OR MID$(a$, a, 1) = CHR$(9) THEN c = a: GOTO 2
NEXT a
GOTO 4
2
b$ = b$ + MID$(a$, b, c - b) + CHR$(32)
GOTO 3
4
b$ = b$ + MID$(a$, b, LEN(a$) - (b - 1))
IF RIGHT$(b$, 1) = CHR$(32) THEN
   c$ = LEFT$(b$, LEN(b$) - 1)
   b$ = c$
END IF

'STOP
cut$ = b$
END FUNCTION

FUNCTION found (a$)
F = 0
FOR a = 1 TO LEN(b$)
   IF MID$(a$, a, 1) = "2" AND F < 1 THEN F = 1
   IF MID$(a$, a, 1) = "3" AND F < 1 THEN F = 1
   IF MID$(a$, a, 1) = "4" AND F < 1 THEN F = 1
   IF MID$(a$, a, 1) = "5" AND F < 1 THEN F = 1
   IF MID$(a$, a, 1) = "6" AND F < 1 THEN F = 1
   IF MID$(a$, a, 1) = "7" AND F < 1 THEN F = 1
   IF MID$(a$, a, 1) = "8" AND F < 1 THEN F = 1
   IF MID$(a$, a, 1) = "9" AND F < 1 THEN F = 1
   IF MID$(a$, a, 1) = "A" AND F < 2 THEN F = 2
   IF MID$(a$, a, 1) = "B" AND F < 2 THEN F = 2
   IF MID$(a$, a, 1) = "C" AND F < 2 THEN F = 2
   IF MID$(a$, a, 1) = "D" AND F < 2 THEN F = 2
   IF MID$(a$, a, 1) = "E" AND F < 2 THEN F = 2
   IF MID$(a$, a, 1) = "F" AND F < 2 THEN F = 2
NEXT a
found = F
END FUNCTION

FUNCTION hex2$ (a$)
a1$ = LEFT$(a$, 1)
a2$ = RIGHT$(a$, 1)
b1 = VAL(a1$)
b2 = VAL(a2$)
IF a1$ = "A" THEN b1 = 10
IF a1$ = "B" THEN b1 = 11
IF a1$ = "C" THEN b1 = 12
IF a1$ = "D" THEN b1 = 13
IF a1$ = "E" THEN b1 = 14
IF a1$ = "F" THEN b1 = 15
IF a2$ = "A" THEN b2 = 10
IF a2$ = "B" THEN b2 = 11
IF a2$ = "C" THEN b2 = 12
IF a2$ = "D" THEN b2 = 13
IF a2$ = "E" THEN b2 = 14
IF a2$ = "F" THEN b2 = 15
hex2$ = CHR$((b1 * 16) + b2)
END FUNCTION

FUNCTION hex3$ (a$)
a1$ = MID$(a$, 1, 1)
a2$ = MID$(a$, 2, 1)
b1 = VAL(a1$)
b2 = VAL(a2$)
IF a1$ = "A" THEN b1 = 10
IF a1$ = "B" THEN b1 = 11
IF a1$ = "C" THEN b1 = 12
IF a1$ = "D" THEN b1 = 13
IF a1$ = "E" THEN b1 = 14
IF a1$ = "F" THEN b1 = 15
IF a2$ = "A" THEN b2 = 10
IF a2$ = "B" THEN b2 = 11
IF a2$ = "C" THEN b2 = 12
IF a2$ = "D" THEN b2 = 13
IF a2$ = "E" THEN b2 = 14
IF a2$ = "F" THEN b2 = 15
a1$ = MID$(a$, 3, 1)
a2$ = MID$(a$, 4, 1)
b3 = VAL(a1$)
b4 = VAL(a2$)
IF a1$ = "A" THEN b3 = 10
IF a1$ = "B" THEN b3 = 11
IF a1$ = "C" THEN b3 = 12
IF a1$ = "D" THEN b3 = 13
IF a1$ = "E" THEN b3 = 14
IF a1$ = "F" THEN b3 = 15
IF a2$ = "A" THEN b4 = 10
IF a2$ = "B" THEN b4 = 11
IF a2$ = "C" THEN b4 = 12
IF a2$ = "D" THEN b4 = 13
IF a2$ = "E" THEN b4 = 14
IF a2$ = "F" THEN b4 = 15
hex3$ = CHR$((b3 * 16) + b4) + CHR$((b1 * 16) + b2)
END FUNCTION

FUNCTION hex4$ (a$)
b$ = SPACE$(4)
FOR a = 1 TO 4
   a1$ = MID$(a$, (a * 2) - 1, 1)
   a2$ = MID$(a$, a * 2, 1)
   b1 = VAL(a1$)
   b2 = VAL(a2$)
   IF a1$ = "A" THEN b1 = 10
   IF a1$ = "B" THEN b1 = 11
   IF a1$ = "C" THEN b1 = 12
   IF a1$ = "D" THEN b1 = 13
   IF a1$ = "E" THEN b1 = 14
   IF a1$ = "F" THEN b1 = 15
   IF a2$ = "A" THEN b2 = 10
   IF a2$ = "B" THEN b2 = 11
   IF a2$ = "C" THEN b2 = 12
   IF a2$ = "D" THEN b2 = 13
   IF a2$ = "E" THEN b2 = 14
   IF a2$ = "F" THEN b2 = 15
   IF a = 1 THEN MID$(b$, 2, 1) = CHR$((b1 * 16) + b2)
   IF a = 2 THEN MID$(b$, 1, 1) = CHR$((b1 * 16) + b2)
   IF a = 3 THEN MID$(b$, 4, 1) = CHR$((b1 * 16) + b2)
   IF a = 4 THEN MID$(b$, 3, 1) = CHR$((b1 * 16) + b2)
NEXT a
hex4$ = b$
END FUNCTION

FUNCTION ident$ (a$, lln, cp, qt)
'IF a$ = "SHL EAX,1" THEN STOP
eax = 0
backwar$ = ""
b$ = qual$(a$)
IF b$ <> "" THEN
   backwar$ = LEFT$(b$, 2)
   a$ = RIGHT$(b$, LEN(b$) - 2)
   'STOP
END IF

IF LEN(a$) >= 5 THEN
   IF MID$(a$, LEN(a$), 1) = CHR$(34) AND MID$(a$, LEN(a$) - 2, 1) = CHR$(34) THEN
      a = ASC(MID$(a$, LEN(a$) - 1, 1))
      b$ = HEX$(a)
      a$ = LEFT$(a$, LEN(a$) - 3) + STRING$(2 - LEN(b$), "0") + b$
   END IF
END IF

'FOR a = 1 TO LEN(a$)
'IF MID$(a$, a, 1) = "," THEN b = a
'NEXT a
'IF b > 0 THEN
'if right$(a$,1)="H"
'a = found(MID$(a$, b + 1, LEN(a$) - b))
'STOP
'END IF
'b = 0



b$ = ""
c3$ = LEFT$(a$, 3)
C4$ = LEFT$(a$, 4)
c5$ = LEFT$(a$, 5)

IF LEN(a$) >= 3 AND LEN(a$) <= 5 THEN
   IF a$ = "CPUID" THEN b$ = CHR$(15) + CHR$(162)
   REM UNTESTED

   IF a$ = "DAA" THEN b$ = CHR$(39)
   IF a$ = "DAS" THEN b$ = CHR$(47)
   IF a$ = "AAA" THEN b$ = CHR$(55)
   IF a$ = "AAS" THEN b$ = CHR$(63)
   IF a$ = "NOP" THEN b$ = CHR$(144)
   IF a$ = "CBW" THEN b$ = CHR$(152)
   IF a$ = "CWD" THEN b$ = CHR$(153)
   IF a$ = "PUSHF" THEN b$ = CHR$(156)
   IF a$ = "POPF" THEN b$ = CHR$(157)
   IF a$ = "SAHF" THEN b$ = CHR$(158)
   IF a$ = "LAHF" THEN b$ = CHR$(159)
   IF a$ = "MOVSB" THEN b$ = CHR$(164)
   IF a$ = "MOVSW" THEN b$ = CHR$(165)
   IF a$ = "CMPSB" THEN b$ = CHR$(166)
   IF a$ = "CMPSW" THEN b$ = CHR$(167)
   IF a$ = "STOSB" THEN b$ = CHR$(170)
   IF a$ = "STOSW" THEN b$ = CHR$(171)
   IF a$ = "LODSB" THEN b$ = CHR$(172)
   IF a$ = "LODSW" THEN b$ = CHR$(173)
   IF a$ = "SCASB" THEN b$ = CHR$(174)
   IF a$ = "SCASW" THEN b$ = CHR$(175)
   IF a$ = "RET" THEN b$ = CHR$(195)
   IF a$ = "RETF" THEN b$ = CHR$(203)
   IF a$ = "INTO" THEN b$ = CHR$(206)
   IF a$ = "IRET" THEN b$ = CHR$(207)
   IF a$ = "AAM" THEN b$ = CHR$(212) + CHR$(10)
   IF a$ = "AAD" THEN b$ = CHR$(213) + CHR$(10)
   IF a$ = "XLAT" THEN b$ = CHR$(215)
   IF a$ = "LOCK" THEN b$ = CHR$(240)
   IF a$ = "REP" OR a$ = "REPNZ" THEN b$ = CHR$(242)
   IF a$ = "REPZ" THEN b$ = CHR$(243)
   IF a$ = "CMC" THEN b$ = CHR$(245)
   IF a$ = "CLC" THEN b$ = CHR$(248)
   IF a$ = "STC" THEN b$ = CHR$(249)
   IF a$ = "CLI" THEN b$ = CHR$(250)
   IF a$ = "STI" THEN b$ = CHR$(251)
   IF a$ = "CLD" THEN b$ = CHR$(252)
   IF a$ = "STD" THEN b$ = CHR$(253)
   IF a$ = "ES:" THEN b$ = CHR$(38)
   IF a$ = "CS:" THEN b$ = CHR$(46)
   IF a$ = "SS:" THEN b$ = CHR$(54)
   IF a$ = "DS:" THEN b$ = CHR$(62)
END IF

IF a$ = "PUSHFD" THEN b$ = CHR$(156): eax = 1
IF a$ = "POPFD" THEN b$ = CHR$(157): eax = 1
IF a$ = "SAHFD" THEN b$ = CHR$(158): eax = 1
IF a$ = "LAHFD" THEN b$ = CHR$(159): eax = 1


IF a$ = "SETALC" THEN b$ = CHR$(214)
IF a$ = "WBINVD" THEN b$ = CHR$(15) + CHR$(9)
IF a$ = "WRMSR" THEN b$ = CHR$(15) + CHR$(48)
IF a$ = "RDMSR" THEN b$ = CHR$(15) + CHR$(50)
IF a$ = "FSIN" THEN b$ = CHR$(217) + CHR$(254)
IF a$ = "FCOS" THEN b$ = CHR$(217) + CHR$(255)
IF a$ = "FENI" THEN b$ = CHR$(155) + CHR$(219) + CHR$(224)
IF a$ = "FNENI" THEN b$ = CHR$(219) + CHR$(224)
IF a$ = "FDISI" THEN b$ = CHR$(155) + CHR$(219) + CHR$(225)
IF a$ = "FNDISI" THEN b$ = CHR$(219) + CHR$(225)
IF a$ = "FPREM" THEN b$ = CHR$(217) + CHR$(248)
IF a$ = "FPTAN" THEN b$ = CHR$(217) + CHR$(242)
IF a$ = "FSETPM" THEN b$ = CHR$(217) + CHR$(228)
IF a$ = "FRSTPM" THEN b$ = CHR$(217) + CHR$(244)
IF a$ = "FSCALE" THEN b$ = CHR$(217) + CHR$(253)
IF a$ = "FSINCOS" THEN b$ = CHR$(217) + CHR$(251)
REM Special codes, careful, not all cpu's use all of these



IF LEFT$(a$, 3) = "INC" THEN
   IF MID$(a$, 5, 1) = "E" THEN c$ = RIGHT$(a$, 3)
   IF MID$(a$, 5, 1) <> "E" THEN c$ = RIGHT$(a$, 2)
   d$ = ISR$(c$)
   IF LEFT$(d$, 1) = "3" THEN
      MID$(d$, 1, 1) = "1"
      eax = 1
   END IF

   IF LEFT$(d$, 1) = "1" THEN
      c = VAL(RIGHT$(d$, 1))
      b$ = CHR$(64 + c)
   END IF
   IF LEFT$(d$, 1) = "2" THEN
      'STOP
      c = VAL(RIGHT$(d$, 1))
      b$ = CHR$(254) + CHR$(192 + c)
   END IF
END IF

IF LEFT$(a$, 3) = "DEC" THEN
   IF MID$(a$, 5, 1) = "E" THEN c$ = RIGHT$(a$, 3)
   IF MID$(a$, 5, 1) <> "E" THEN c$ = RIGHT$(a$, 2)
   d$ = ISR$(c$)
   IF LEFT$(d$, 1) = "3" THEN
      MID$(d$, 1, 1) = "1"
      eax = 1
   END IF
   IF LEFT$(d$, 1) = "1" THEN
      c = VAL(RIGHT$(d$, 1))
      b$ = CHR$(72 + c)
   END IF
   IF LEFT$(d$, 1) = "2" THEN
      c = VAL(RIGHT$(d$, 1))
      b$ = CHR$(254) + CHR$(200 + c)
   END IF
END IF

IF C4$ = "CMP " OR c5$ = "TEST " OR C4$ = "ADD " OR C4$ = "SUB " OR C4$ = "ADC " OR C4$ = "SBB " OR C4$ = "LEA " OR C4$ = "LES " OR C4$ = "LDS " OR c3$ = "OR " OR C4$ = "AND " OR C4$ = "XOR " THEN
   'STOP
   IF C4$ <> "TEST" AND c3$ <> "OR " THEN b$ = PAT1$(RIGHT$(a$, LEN(a$) - 4))
   'PRINT a$
   'STOP
   c3$ = MID$(a$, 5, 3)
   IF c5$ = "TEST " THEN lw = 168: b$ = PAT1$(RIGHT$(a$, LEN(a$) - 5)): c3$ = MID$(a$, 6, 3)
   IF C4$ = "ADD " THEN lw = 0
   IF c3$ = "OR " THEN lw = 8: b$ = PAT1$(RIGHT$(a$, LEN(a$) - 3)): c3$ = MID$(a$, 4, 3)
   IF C4$ = "ADC " THEN lw = 16
   IF C4$ = "SBB " THEN lw = 24
   IF C4$ = "AND " THEN lw = 32
   IF C4$ = "SUB " THEN lw = 40
   IF C4$ = "XOR " THEN lw = 48
   IF C4$ = "CMP " THEN lw = 56
   IF C4$ = "LEA " THEN lw = 138
   IF C4$ = "LES " THEN lw = 193
   IF C4$ = "LDS " THEN lw = 194
   IF LEFT$(b$, 1) = CHR$(1) THEN eax = 1
   IF c3$ = "EAX" THEN eax = 1
   IF c3$ = "EBX" THEN eax = 1
   IF c3$ = "ECX" THEN eax = 1
   IF c3$ = "EDX" THEN eax = 1
   IF c3$ = "ESP" THEN eax = 1
   IF c3$ = "EBP" THEN eax = 1
   IF c3$ = "ESI" THEN eax = 1
   IF c3$ = "EDI" THEN eax = 1
   c3$ = LEFT$(a$, 3)
   IF b$ = "" THEN GOTO 7
   x$ = RIGHT$(b$, LEN(b$) - 1)
   b$ = x$
   IF b$ = "" THEN GOTO 7
   c = ASC(MID$(b$, 1, 1))
   MID$(b$, 1, 1) = CHR$(lw + c)
   FOR a = 5 TO LEN(a$)
      IF MID$(a$, a, 1) = "," THEN b = a
   NEXT a
   'STOP
   c$ = ISR$(MID$(a$, 5, b - 5))
   d$ = ISR$(MID$(a$, b + 1, LEN(a$) - b))

   IF LEFT$(c$, 1) = "0" OR LEFT$(d$, 1) = "0" THEN
      a = (VAL(MID$(d$, 2, 1)) * 8) + ASC(MID$(b$, 2, 1))
      IF a <= 255 THEN MID$(b$, 2, 1) = CHR$(a)
      IF a > 255 THEN b$ = ""

   END IF

   IF lw = 16 AND LEFT$(c$, 1) = "2" AND LEFT$(d$, 1) = "0" THEN
      a = VAL(RIGHT$(c$, 1))
      b$ = PAT1$(RIGHT$(a$, LEN(a$) - 4))
      MID$(b$, 1, 2) = CHR$(128) + CHR$(208 + a)
      'STOP
   END IF

   '2073:0100 80C000        ADD     AL,00
   '2073:0118 80C800        OR      AL,00
   '2073:0130 80D000        ADC     AL,00
   '2073:0148 80D800        SBB     AL,00
   '2073:0160 80E000        AND     AL,00
   '2073:0178 80E800        SUB     AL,00
   '2073:0190 80F000        XOR     AL,00
   '2073:01A8 80F800        CMP     AL,00


   IF MID$(c$, 2, 1) <> "0" AND LEFT$(d$, 1) = "0" THEN
      a = VAL(MID$(c$, 2, 1))
      IF lw = 0 THEN a = a + 192: sor = 4: GOTO 22
      IF lw = 40 THEN a = a + 232: sor = 44: GOTO 22
      IF lw = 56 THEN a = a + 248: sor = 60: GOTO 22
      REM lw=0 / add : sor, the catch for generated code..
      REM lw=56 / cmp : which is bad.. and needs to be fixed
      GOTO 21
      22
      x$ = b$
      MID$(x$, 1, 1) = CHR$(a)
      IF MID$(b$, 1, 1) = CHR$(sor) THEN b$ = CHR$(128) + x$
      IF MID$(b$, 1, 1) = CHR$(sor + 1) THEN
         'PRINT a$
         'STOP
         IF MID$(a$, 10, 2) = "00" THEN
            a = 0
            IF MID$(a$, 8, 2) <> "00" THEN a = 256 - ASC(hex2$(MID$(a$, 8, 2)))
            REM first section ADD BX,:)00
            REM for minus...???
            IF a = 256 THEN a = 0
            x$ = LEFT$(x$, 1) + CHR$(a)
         END IF
         IF MID$(a$, 8, 2) = "00" THEN x$ = LEFT$(x$, 1) + hex2$(MID$(a$, 10, 2))
         REM second section ADD BX,00:)
         REM for plus...
         b$ = CHR$(131) + x$
      END IF
   END IF
   21
   IF lw = 168 THEN
      'test ??,0000
      'STOP
      IF b$ = "" THEN GOTO 7
      IF MID$(a$, 5, 3) = " AX" THEN MID$(b$, 1, 1) = CHR$(169)
      IF MID$(a$, 5, 3) = " AL" THEN MID$(b$, 1, 1) = CHR$(168)
      IF MID$(a$, 5, 4) = " EAX" THEN MID$(b$, 1, 1) = CHR$(169): eax = 1
   END IF
END IF

IF C4$ = "MOV " THEN
   b$ = PAT1$(MID$(a$, 5, LEN(a$) - 4))
   'PRINT ASC(MID$(b$, 1, 1)), ASC(MID$(b$, 2, 1)), ASC(MID$(b$, 3, 1))
   'STOP
   IF LEFT$(b$, 1) = CHR$(1) THEN eax = 1
   x$ = RIGHT$(b$, LEN(b$) - 1)
   b$ = x$
   FOR a = 5 TO LEN(a$)
      IF MID$(a$, a, 1) = "," THEN b = a
   NEXT a
   c$ = ISR$(MID$(a$, 5, b - 5))
   d$ = ISR$(MID$(a$, b + 1, LEN(a$) - b))
   'STOP
   IF LEFT$(c$, 1) = "3" THEN
      MID$(c$, 1, 1) = "1"
      eax = 1
   END IF
   IF LEFT$(d$, 1) = "3" THEN
      MID$(d$, 1, 1) = "1"
      eax = 1
   END IF
   'STOP
   IF LEFT$(c$, 1) = "1" AND d$ = "00" AND (LEN(a$) - b) = 4 AND RIGHT$(a$, 1) <> "]" THEN
      'STOP
      a = VAL(RIGHT$(c$, 1))
      'STOP
      b$ = CHR$(184 + a) + hex3$(MID$(a$, b + 1, LEN(a$) - b))
   END IF
   IF LEFT$(c$, 1) = "2" AND d$ = "00" AND (LEN(a$) - b) = 2 THEN
      a = VAL(RIGHT$(c$, 1))
      'STOP
      b$ = CHR$(176 + a) + hex2$(MID$(a$, b + 1, LEN(a$) - b))
   END IF
   IF LEN(b$) > 0 THEN b = ASC(MID$(b$, 1, 1))
   IF b >= 0 AND b <= 4 THEN MID$(b$, 1, 1) = CHR$(b + 136)

   'STOP
   IF c$ = "00" AND d$ = "10" AND MID$(a$, 11, 1) = "," THEN
      'STOP
      b$ = RIGHT$(b$, 3)
      MID$(b$, 1, 1) = CHR$(163)
   END IF

   'STOP
   IF LEFT$(c$, 1) = "4" THEN
      '8e 142
      'b$ = RIGHT$(b$, 3)
      MID$(b$, 1, 1) = CHR$(142)
   END IF


END IF

IF LEFT$(a$, 1) = "J" THEN
   REM A little information...
   REM ja=jnbe, jae=jnb, jb=jnae, jbe=jna
   REM jg=jnle, jge=jnl, jl=jnge, jle=jng
   REM jna=jbe, jnae=jb, jnb=jae, jnbe=ja
   REM jng=jle, jnge=jl, jnl=jge, jnle=jg
   IF c3$ = "JA " THEN b$ = CHR$(119) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF C4$ = "JAE " THEN b$ = CHR$(115) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF c3$ = "JB " THEN b$ = CHR$(114) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF C4$ = "JBE " THEN b$ = CHR$(118) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF c3$ = "JC " THEN b$ = CHR$(114) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF c5$ = "JCXZ " THEN b$ = CHR$(227) + nec$(MID$(a$, 6, 4), cp + 2, 1)
   IF c3$ = "JE " THEN b$ = CHR$(116) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF c3$ = "JG " THEN b$ = CHR$(127) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF C4$ = "JGE " THEN b$ = CHR$(125) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF c3$ = "JL " THEN b$ = CHR$(124) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF C4$ = "JLE " THEN b$ = CHR$(126) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF C4$ = "JNA " THEN b$ = CHR$(118) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF c5$ = "JNAE " THEN b$ = CHR$(114) + nec$(MID$(a$, 6, 4), cp + 2, 1)
   IF C4$ = "JNB " THEN b$ = CHR$(115) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF c5$ = "JNBE " THEN b$ = CHR$(119) + nec$(MID$(a$, 6, 4), cp + 2, 1)
   IF C4$ = "JNC " THEN b$ = CHR$(115) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF C4$ = "JNE " THEN b$ = CHR$(117) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF C4$ = "JNG " THEN b$ = CHR$(126) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF c5$ = "JNGE " THEN b$ = CHR$(124) + nec$(MID$(a$, 6, 4), cp + 2, 1)
   IF C4$ = "JNL " THEN b$ = CHR$(125) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF c5$ = "JNLE " THEN b$ = CHR$(127) + nec$(MID$(a$, 6, 4), cp + 2, 1)
   IF C4$ = "JNO " THEN b$ = CHR$(113) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF C4$ = "JNP " THEN b$ = CHR$(123) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF C4$ = "JNS " THEN b$ = CHR$(121) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF C4$ = "JNZ " THEN b$ = CHR$(117) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF c3$ = "JO " THEN b$ = CHR$(112) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF c3$ = "JP " THEN b$ = CHR$(122) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF C4$ = "JPE " THEN b$ = CHR$(122) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF C4$ = "JPO " THEN b$ = CHR$(123) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF c3$ = "JS " THEN b$ = CHR$(120) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF c3$ = "JZ " THEN b$ = CHR$(116) + nec$(MID$(a$, 4, 4), cp + 2, 1)
   IF qt = 1 AND LEN(b$) = 1 THEN b$ = "  "
   'eb? 235
   IF C4$ = "JXX " THEN b$ = CHR$(235) + nec$(MID$(a$, 5, 4), cp + 2, 1)
   IF C4$ = "JMP " THEN b$ = CHR$(233) + nec$(MID$(a$, 5, 4), cp + 3, 2)
   IF c5$ = "JMP [" THEN b$ = CHR$(255) + CHR$(38) + hex3$(MID$(a$, 6, 4))
END IF

IF C4$ = "INT " THEN
   a = LEN(a$) - 4
   IF a = 1 THEN b$ = CHR$(205) + hex2$("0" + MID$(a$, 5, 1))
   IF a = 2 THEN b$ = CHR$(205) + hex2$(MID$(a$, 5, 2))
   IF a$ = "INT" THEN b$ = CHR$(204)
   IF a$ = "INT 3" THEN b$ = CHR$(204)
   IF a$ = "INT 03" THEN b$ = CHR$(204)
END IF
IF C4$ = "RET " THEN
   b$ = CHR$(194) + hex3$(MID$(a$, 5, 4))
END IF
IF c5$ = "RETF " THEN
   b$ = CHR$(202) + hex3$(MID$(a$, 6, 4))
END IF
IF C4$ = "AAM " THEN
   a = LEN(a$) - 4
   IF a = 1 THEN b$ = CHR$(212) + hex2$("0" + MID$(a$, 5, 1))
   IF a = 2 THEN b$ = CHR$(212) + hex2$(MID$(a$, 5, 2))
END IF
IF C4$ = "AAD " THEN
   a = LEN(a$) - 4
   IF a = 1 THEN b$ = CHR$(213) + hex2$("0" + MID$(a$, 5, 1))
   IF a = 2 THEN b$ = CHR$(213) + hex2$(MID$(a$, 5, 2))
END IF

REM this int 3 has some special purpose... i don't know.. Debug likes to
REM use it.. must be something special
'(All use CDh (HEX) or the number for it.. Save 3

'(Mov/copy routines)
'MOV=89 (Hex) for copy/move byte(s)
IF LEFT$(a$, 5) = "PUSH " THEN
   b$ = RIGHT$(a$, 3)
   IF LEFT$(b$, 1) = "E" THEN eax = 1
   b$ = RIGHT$(a$, 2)
   IF b$ = "SS" THEN b$ = CHR$(22)
   IF b$ = "DS" THEN b$ = CHR$(30)
   IF b$ = "ES" THEN b$ = CHR$(6)
   IF b$ = "CS" THEN b$ = CHR$(14)
   IF b$ = "AX" THEN b$ = CHR$(80)
   IF b$ = "CX" THEN b$ = CHR$(81)
   IF b$ = "DX" THEN b$ = CHR$(82)
   IF b$ = "BX" THEN b$ = CHR$(83)
   IF b$ = "SP" THEN b$ = CHR$(84)
   IF b$ = "BP" THEN b$ = CHR$(85)
   IF b$ = "SI" THEN b$ = CHR$(86)
   IF b$ = "DI" THEN b$ = CHR$(87)
   IF b$ = "" AND LEN(a$) = 7 THEN
      b$ = CHR$(106) + hex2$(RIGHT$(a$, 2))
   END IF
   IF b$ = "" AND LEN(a$) = 9 THEN
      b$ = CHR$(106) + hex3$(RIGHT$(a$, 4))
      REM it's not 106.. that's an error.. the next number for that is unknown
      REM when you find it.. tell me
      a$ = ";this is not right..."
   END IF

END IF
IF LEFT$(a$, 4) = "POP " THEN
   b$ = RIGHT$(a$, 3)
   IF LEFT$(b$, 1) = "E" THEN eax = 1
   b$ = RIGHT$(a$, 2)
   IF b$ = "SS" THEN b$ = CHR$(23)
   IF b$ = "DS" THEN b$ = CHR$(31)
   IF b$ = "ES" THEN b$ = CHR$(7)
   IF b$ = "CS" THEN b$ = CHR$(15)
   IF b$ = "AX" THEN b$ = CHR$(88)
   IF b$ = "CX" THEN b$ = CHR$(89)
   IF b$ = "DX" THEN b$ = CHR$(90)
   IF b$ = "BX" THEN b$ = CHR$(91)
   IF b$ = "SP" THEN b$ = CHR$(92)
   IF b$ = "BP" THEN b$ = CHR$(93)
   IF b$ = "SI" THEN b$ = CHR$(94)
   IF b$ = "DI" THEN b$ = CHR$(95)
END IF

'TEST: Sees if certain bits are on.. if returns 0, that means none are on..
'test=84
'test=85

'LOOP: jumps to a memory location (under 127 bytes) if CX>0
'(Throught the test, there is a limit.. it uses signed, so it can only jump
'as the conditional jumps go.. since it is one..)
'1371:0100 E2FE          LOOP    0100
'1371:0102 E2FC          LOOP    0100
'1371:0104 E2FA          LOOP    0100

IF LEFT$(a$, 5) = "LOOP " THEN b$ = CHR$(226) + nec$(MID$(a$, 6, 4), cp + 2, 1)

'loop=
'110 MOV CX,[????] ;Grab number from appropriate location
'114 CMP CX,0000 ;
'118 JZ 128
'120 DEC CX
'122 MOV [????],CX
'124 JMP 110
'128 ???
'(Something like this.. the exact sizes of the instructions may be different)
'(Jump far)
'CMP CX,[0000] ;compare..
'JNE L1 ;jump to good jumper if [0000]>0
'JE L2 ;bypass good jumper if 0
'L1:
'JMP 0000 ;jump to real location
'L2:
';.. continue here

'1371:0100 E1FE          LOOPZ   0100
'1371:0102 E1FC          LOOPZ   0100
'1371:0104 E0FA          LOOPNZ  0100
'1371:0106 E0F8          LOOPNZ  0100
IF LEFT$(a$, 6) = "LOOPZ " THEN b$ = CHR$(225) + nec$(MID$(a$, 7, 4), cp + 2, 1)
IF LEFT$(a$, 7) = "LOOPNZ " THEN b$ = CHR$(224) + nec$(MID$(a$, 8, 4), cp + 2, 1)
IF LEFT$(a$, 6) = "LOOPE " THEN b$ = CHR$(225) + nec$(MID$(a$, 7, 4), cp + 2, 1)
IF LEFT$(a$, 7) = "LOOPNE " THEN b$ = CHR$(224) + nec$(MID$(a$, 8, 4), cp + 2, 1)

'
'LOOPZ=if compare ==0
'LOOPNZ=if compare >0
'
'(patterns may follow mov ones...)
'ADD: Add a number to the left value, from the right.. (CF cautious..)

'ADD=00
'ADD=01

'SUB: Subtracts left value of the value of right value
'SUB=28
'SUB=29

'ADC: Same as ADD but uses the carry flag for longer numbers
'(C stands for, uses the Carry Flag.. in case it needs it..)
'ADC=10 (Small)
'ADC=11 (Big)

'SBB: Same as sub, but uses the CF for longer numbers
'SBB=18
'SBB=19

'AND: use.. change bit to 0.. of the bit that says 0..
'AND=80
'AND=81
'AND=24
'AND=25

'OR=80
'OR=81
'OR=0A
'OR=0B

'XOR=80 (Short, 2 registers)
'XOR=81 (Medium, 2 registers)

'XOR=32?
'XOR=33?
'XOR=34?
'XOR=35?

'NOT=F6 (Short, 1 register)
'NOT=F7 (Long, 1 register)

'CALL=E8 (Short)
'CALL=9A (LONG)
'STOP
IF LEFT$(a$, 5) = "CALL " AND LEN(a$) = 9 THEN b$ = CHR$(232) + nec$(MID$(a$, 6, 4), cp + 3, 2)
IF LEFT$(a$, 5) = "CALL " AND LEN(a$) = 14 THEN b$ = CHR$(154) + hex3$(MID$(a$, 11, 4)) + hex3$(MID$(a$, 6, 4))

'LEA=8D (Normal Patterns)
'LES=C4 (Normal Patterns)
'LDS=C5 (Normal Patterns)

'NEG=F7 (Part of a pattern)
'NEG=F6 (Part of a pattern?)
'(Start exactly unknown)

IF C4$ = "NEG " OR C4$ = "MUL " OR c5$ = "IMUL " OR C4$ = "DIV " OR c5$ = "IDIV " THEN
   IF C4$ = "NEG " THEN lw = 27
   IF C4$ = "MUL " THEN lw = 28
   IF c5$ = "IMUL " THEN lw = 29
   IF C4$ = "DIV " THEN lw = 30
   IF c5$ = "IDIV " THEN lw = 31
   b$ = RIGHT$(a$, 3)
   IF b$ = " AX" THEN b$ = CHR$(247) + CHR$(lw * 8)
   IF b$ = " CX" THEN b$ = CHR$(247) + CHR$((lw * 8) + 1)
   IF b$ = " DX" THEN b$ = CHR$(247) + CHR$((lw * 8) + 2)
   IF b$ = " BX" THEN b$ = CHR$(247) + CHR$((lw * 8) + 3)
   IF b$ = " SP" THEN b$ = CHR$(247) + CHR$((lw * 8) + 4)
   IF b$ = " BP" THEN b$ = CHR$(247) + CHR$((lw * 8) + 5)
   IF b$ = " SI" THEN b$ = CHR$(247) + CHR$((lw * 8) + 6)
   IF b$ = " DI" THEN b$ = CHR$(247) + CHR$((lw * 8) + 7)
   IF b$ = " AL" THEN b$ = CHR$(246) + CHR$(lw * 8)
   IF b$ = " CL" THEN b$ = CHR$(246) + CHR$((lw * 8) + 1)
   IF b$ = " DL" THEN b$ = CHR$(246) + CHR$((lw * 8) + 2)
   IF b$ = " BL" THEN b$ = CHR$(246) + CHR$((lw * 8) + 3)
   IF b$ = " AH" THEN b$ = CHR$(246) + CHR$((lw * 8) + 4)
   IF b$ = " CH" THEN b$ = CHR$(246) + CHR$((lw * 8) + 5)
   IF b$ = " DH" THEN b$ = CHR$(246) + CHR$((lw * 8) + 6)
   IF b$ = " BH" THEN b$ = CHR$(246) + CHR$((lw * 8) + 7)
   IF b$ = "EAX" THEN b$ = CHR$(247) + CHR$(lw * 8): eax = 1
   IF b$ = "ECX" THEN b$ = CHR$(247) + CHR$((lw * 8) + 1): eax = 1
   IF b$ = "EDX" THEN b$ = CHR$(247) + CHR$((lw * 8) + 2): eax = 1
   IF b$ = "EBX" THEN b$ = CHR$(247) + CHR$((lw * 8) + 3): eax = 1
   IF b$ = "ESP" THEN b$ = CHR$(247) + CHR$((lw * 8) + 4): eax = 1
   IF b$ = "EBP" THEN b$ = CHR$(247) + CHR$((lw * 8) + 5): eax = 1
   IF b$ = "ESI" THEN b$ = CHR$(247) + CHR$((lw * 8) + 6): eax = 1
   IF b$ = "EDI" THEN b$ = CHR$(247) + CHR$((lw * 8) + 7): eax = 1
END IF

'MUL: Multiply, though numbers AX and the location? (AH X AL) (AX * MUL?)
'F7;F6                                              (   AX  ) (AX + DX)
'(Unsigned multiply)

'SHL=D0 (direct values) SHR, RCL, RCR, ROR, ROL, SAR, (SAL? SOL?)
'SHL=D1 (2 direct values)
'SHL=D2 (2 registers)
'SHL=D3 (2 registers)

IF C4$ = "SHL " OR C4$ = "SHR " OR C4$ = "RCL " OR C4$ = "RCR " OR C4$ = "ROL " OR C4$ = "ROR " OR C4$ = "SAL " OR C4$ = "SAR " THEN
   b$ = PAT2$(a$)
END IF
'IN: Reads from IO port.. (Uncertainty.. bytes only?)
'IN AX,(Port) (AX port is the only one that will work for first, and DX for
'second?)
'IN=E5(Big AX)
'IN=E4(Small Al)
'1371:0100 E501          IN      AX,01
'1371:0106 ED            IN      AX,DX
IF c3$ = "IN " THEN
   IF MID$(a$, 5, 2) <> "DX" THEN
      IF LEN(a$) = 8 THEN b$ = CHR$(229) + hex2$(RIGHT$(a$, 2))
      IF LEN(a$) = 7 THEN b$ = CHR$(229) + hex2$("0" + RIGHT$(a$, 1))
   END IF

   IF a$ = "IN AX,DX" THEN b$ = CHR$(237)
END IF


'OUT: Writes information to port.. PORT, byte(s)
'OUT=E7 (Port and AX)
'OUT=E6 (Port and AL)
'1371:0100 EF            OUT     DX,AX
'1371:0101 EE            OUT     DX,AL
'1371:0102 E711          OUT     11,AX

IF c3$ = "OUT" THEN
   IF MID$(a$, 5, 2) <> "DX" THEN
      IF LEN(a$) = 9 THEN
         IF RIGHT$(a$, 2) = "AL" THEN b$ = CHR$(230) + hex2$(MID$(a$, 5, 2))
         IF RIGHT$(a$, 2) = "AX" THEN b$ = CHR$(231) + hex2$(MID$(a$, 5, 2))
      END IF
      IF LEN(a$) = 8 THEN
         IF RIGHT$(a$, 2) = "AL" THEN b$ = CHR$(230) + hex2$("0" + MID$(a$, 5, 1))
         IF RIGHT$(a$, 2) = "AX" THEN b$ = CHR$(231) + hex2$("0" + MID$(a$, 5, 1))
      END IF
   END IF
   IF a$ = "OUT DX,AX" THEN b$ = CHR$(239)
   IF a$ = "OUT DX,AL" THEN b$ = CHR$(238)
END IF
'1371:0100 EF            OUT     DX,AX
'1371:0101 EE            OUT     DX,AL

'Xchg: Change the two registers around..
'1371:0100 90            NOP
IF a$ = "NOP" THEN b$ = CHR$(144)
'Xchg=86 (Follow normal pattern) (Small)
'Xchg=87 (Follow Normal Pattern) (big)
'1371:01DC 94            XCHG    SP,AX
'1371:01DD 95            XCHG    BP,AX
'1371:01DE 96            XCHG    SI,AX
'1371:01DF 97            XCHG    DI,AX
IF c5$ = "XCHG " THEN
   '86 87
   '134 135

   FOR a = 6 TO LEN(a$)
      IF MID$(a$, a, 1) = "," THEN b = a
   NEXT a
   c$ = ISR$(MID$(a$, 6, b - 6))
   d$ = ISR$(MID$(a$, b + 1, LEN(a$) - b))
   'STOP
   a = VAL(RIGHT$(c$, 1))
   b = VAL(RIGHT$(d$, 1))
   'STOP
   IF LEFT$(c$, 1) = "1" THEN b$ = CHR$(135) + CHR$(192 + ((a * 8)) + b)
   IF LEFT$(c$, 1) = "2" THEN b$ = CHR$(134) + CHR$(192 + ((a * 8)) + b)
END IF



IF a$ = "XCHG SP,AX" THEN b$ = CHR$(148)
IF a$ = "XCHG BP,AX" THEN b$ = CHR$(149)
IF a$ = "XCHG SI,AX" THEN b$ = CHR$(150)
IF a$ = "XCHG DI,AX" THEN b$ = CHR$(151)

IF C4$ = "ERA " THEN
   b$ = MID$(a$, 5, LEN(a$) - 4)
END IF

IF C4$ = "DB " + CHR$(34) THEN
   b$ = MID$(a$, 5, LEN(a$) - 5)
   GOTO 7
END IF

IF LEFT$(a$, 7) = "DB DUP(" THEN
   a = 32
   'IF a$ = "DB DUP(40) 00" THEN STOP
   IF LEN(a$) = 10 OR LEN(a$) = 13 THEN
      b$ = hex2$(MID$(a$, 8, 2))
      b = ASC(b$)
   END IF
   IF LEN(a$) = 12 OR LEN(a$) = 15 THEN
      b$ = hex4$(MID$(a$, 8, 4))
      b = CVL(b$)
      'STOP
   END IF
   IF LEN(a$) = 13 OR LEN(a$) = 15 THEN a = ASC(hex2$(RIGHT$(a$, 2)))
   'STOP
   b$ = STRING$(b, CHR$(a))
   GOTO 7
END IF
'STOP
IF c3$ = "DB " THEN
    'STOP
   b$ = ""
   c = 3
   11
   b = c + 3
   IF b >= LEN(a$) THEN GOTO 10
   b$ = b$ + hex2$(MID$(a$, c + 1, 2))
   c = b
   GOTO 11
   10
   b$ = b$ + hex2$(MID$(a$, c + 1, 2))
END IF
7
IF b$ = "" AND qt = 0 AND LEFT$(a$, 1) <> ";" THEN PRINT lln, a$; "  ;Unknown.. command"
'STOP
IF eax = 1 AND ebx = 0 THEN ident$ = CHR$(102) + b$ + backwar$
IF eax = 1 AND ebx = 1 THEN ident$ = CHR$(102) + CHR$(103) + b$ + backwar$
IF eax = 0 THEN ident$ = b$
END FUNCTION

FUNCTION ISR$ (a$)
c$ = "00"
IF a$ = "AX" THEN c$ = "10"
IF a$ = "CX" THEN c$ = "11"
IF a$ = "DX" THEN c$ = "12"
IF a$ = "BX" THEN c$ = "13"
IF a$ = "SP" THEN c$ = "14"
IF a$ = "BP" THEN c$ = "15"
IF a$ = "SI" THEN c$ = "16"
IF a$ = "DI" THEN c$ = "17"
IF a$ = "AL" THEN c$ = "20"
IF a$ = "CL" THEN c$ = "21"
IF a$ = "DL" THEN c$ = "22"
IF a$ = "BL" THEN c$ = "23"
IF a$ = "AH" THEN c$ = "24"
IF a$ = "CH" THEN c$ = "25"
IF a$ = "DH" THEN c$ = "26"
IF a$ = "BH" THEN c$ = "27"
IF a$ = "EAX" THEN c$ = "30"
IF a$ = "ECX" THEN c$ = "31"
IF a$ = "EDX" THEN c$ = "32"
IF a$ = "EBX" THEN c$ = "33"
IF a$ = "ESP" THEN c$ = "34"
IF a$ = "EBP" THEN c$ = "35"
IF a$ = "ESI" THEN c$ = "36"
IF a$ = "EDI" THEN c$ = "37"
IF a$ = "ES" THEN c$ = "40"
IF a$ = "CS" THEN c$ = "41"
IF a$ = "SS" THEN c$ = "42"
IF a$ = "DS" THEN c$ = "43"
ISR$ = c$
END FUNCTION

FUNCTION nec$ (a$, c, d)
'STOP
REM Remember to add to C for the size of the entire
REM instruction before executing
a1$ = MID$(a$, 1, 1)
a2$ = MID$(a$, 2, 1)
b1 = VAL(a1$)
b2 = VAL(a2$)
IF a1$ = "A" THEN b1 = 10
IF a1$ = "B" THEN b1 = 11
IF a1$ = "C" THEN b1 = 12
IF a1$ = "D" THEN b1 = 13
IF a1$ = "E" THEN b1 = 14
IF a1$ = "F" THEN b1 = 15
IF a2$ = "A" THEN b2 = 10
IF a2$ = "B" THEN b2 = 11
IF a2$ = "C" THEN b2 = 12
IF a2$ = "D" THEN b2 = 13
IF a2$ = "E" THEN b2 = 14
IF a2$ = "F" THEN b2 = 15
a1$ = MID$(a$, 3, 1)
a2$ = MID$(a$, 4, 1)
b3 = VAL(a1$)
b4 = VAL(a2$)
IF a1$ = "A" THEN b3 = 10
IF a1$ = "B" THEN b3 = 11
IF a1$ = "C" THEN b3 = 12
IF a1$ = "D" THEN b3 = 13
IF a1$ = "E" THEN b3 = 14
IF a1$ = "F" THEN b3 = 15
IF a2$ = "A" THEN b4 = 10
IF a2$ = "B" THEN b4 = 11
IF a2$ = "C" THEN b4 = 12
IF a2$ = "D" THEN b4 = 13
IF a2$ = "E" THEN b4 = 14
IF a2$ = "F" THEN b4 = 15
x = ((b1 * 16) + b2)
y = ((b3 * 16) + b4)
z = (x * 256) + y
IF z > c THEN
   x = z - c
   IF d = 1 THEN
      IF x <= 127 THEN
         'x = x + 128
         nec$ = CHR$(x)
         'PRINT x
      END IF
   END IF
   IF d = 2 THEN
      IF x <= 32767 THEN
         'x = x + 32768
         y = INT(x / 256)
         z = x - (y * 256)
         nec$ = CHR$(z) + CHR$(y)
         z = x + c
         'PRINT x
      END IF
   END IF
END IF
IF z < c THEN
   x = c - z
   IF d = 1 THEN
      IF x <= 127 THEN
         y = 128 - x
         x = y
         x = x + 128
         nec$ = CHR$(x)
      END IF
   END IF
   IF d = 2 THEN
      IF x <= 32767 THEN
         y = 32768 - x
         x = y
         x = x + 32768
         y = INT(x / 256)
         z = x - (y * 256)
         nec$ = CHR$(z) + CHR$(y)
         'PRINT x
      END IF
   END IF
END IF
'PRINT x
'STOP
END FUNCTION

FUNCTION PAT1$ (a$)
FOR a = 1 TO LEN(a$)
   IF MID$(a$, a, 1) = "," THEN b = a
NEXT a
d$ = MID$(a$, b + 1, LEN(a$) - b)
c$ = MID$(a$, 1, b - 1)
c1$ = ISR$(c$)
d1$ = ISR$(d$)
IF LEFT$(c1$, 1) = "3" THEN
   MID$(c1$, 1, 1) = "1"
END IF
IF LEFT$(d1$, 1) = "3" THEN
   MID$(d1$, 1, 1) = "1"
END IF
IF LEFT$(c1$, 1) = "4" THEN
   MID$(c1$, 1, 1) = "1"
   sseg = 1
END IF
IF LEFT$(d1$, 1) = "4" THEN
   MID$(d1$, 1, 1) = "1"
   sseg = 1
END IF

a = VAL(LEFT$(c1$, 1))
b = VAL(LEFT$(d1$, 1))
'IF a$ = "[016E],SI" THEN STOP
IF a > 0 THEN a1 = VAL(RIGHT$(c1$, 1))
IF b > 0 THEN b1 = VAL(RIGHT$(d1$, 1))
IF a = 0 THEN
   c1$ = ASS$(c$)
   c = ASC(LEFT$(c1$, 1))
   a1 = VAL(MID$(c1$, 2, 1))
   c1 = (c * 8) + a1
   c1 = c1 + (b1 * 8)
   IF LEN(c1$) >= 2 THEN cde = ASC(MID$(c1$, 2, 1))
   'STOP
END IF
IF b = 0 THEN
   d1$ = ASS$(d$)
   c = ASC(LEFT$(d1$, 1))
   IF c < 3 THEN b1 = VAL(MID$(d1$, 2, 1))
   IF c = 3 THEN b1 = ASC(MID$(d1$, 2, 1))
   c1 = (c * 8) + b1
   c1 = c1 + (a1 * 8)
   IF LEN(d1$) >= 2 THEN cde = ASC(MID$(d1$, 2, 1))
   'STOP
END IF
'STOP
'IF a$ = "[BX],EAX" THEN STOP
IF sseg = 1 AND a = 1 AND b = 1 THEN
   sseg = a1
   a1 = b1
   b1 = sseg
   sseg = 1
END IF

IF a = 1 AND b = 0 AND c = 3 THEN x$ = CHR$(5) + RIGHT$(d1$, 2)
IF a = 2 AND b = 0 AND c = 3 THEN x$ = CHR$(4) + RIGHT$(d1$, 1)
IF a = 1 AND b = 0 AND c < 3 THEN x$ = CHR$(3) + CHR$(c1 + cde) + RIGHT$(d1$, LEN(d1$) - 2)
IF a = 2 AND b = 0 AND c < 3 THEN x$ = CHR$(2) + CHR$(c1 + cde) + RIGHT$(d1$, LEN(d1$) - 2)
IF a = 0 AND b = 1 AND c < 3 THEN x$ = CHR$(1) + CHR$(c1 + cde) + RIGHT$(c1$, LEN(c1$) - 2)
IF a = 0 AND b = 2 AND c < 3 THEN x$ = CHR$(0) + CHR$(c1 + cde) + RIGHT$(c1$, LEN(c1$) - 2)
IF a = 1 AND b = 0 AND c < 3 AND cde = 6 THEN x$ = CHR$(3) + CHR$(c1 + cde) + RIGHT$(d1$, LEN(d1$) - 2)
IF a = 2 AND b = 0 AND c < 3 AND cde = 6 THEN x$ = CHR$(2) + CHR$(c1 + cde) + RIGHT$(d1$, LEN(d1$) - 2)
IF a = 0 AND b = 1 AND c < 3 AND cde = 6 THEN x$ = CHR$(1) + CHR$(c1 + cde) + RIGHT$(c1$, LEN(c1$) - 2)
IF a = 0 AND b = 2 AND c < 3 AND cde = 6 THEN x$ = CHR$(0) + CHR$(c1 + cde) + RIGHT$(c1$, LEN(c1$) - 2)

IF a = 1 AND b = 1 THEN x$ = CHR$(1) + CHR$(192 + ((b1 * 8) + a1)) + RIGHT$(c1$, c)
IF a = 2 AND b = 2 THEN x$ = CHR$(0) + CHR$(192 + ((b1 * 8) + a1)) + RIGHT$(c1$, c)

'1371:0100 0000          ADD     [BX+SI],AL
'1371:0102 0100          ADD     [BX+SI],AX
'1371:0104 0200          ADD     AL,[BX+SI]
'1371:0106 0300          ADD     AX,[BX+SI]
'1371:0108 0400          ADD     AL,00
'1371:010A 050000        ADD     AX,0000
PAT1$ = CHR$(eax) + x$
END FUNCTION

FUNCTION PAT2$ (a$)
'STOP
b$ = LEFT$(a$, 3)
FOR a = 1 TO LEN(a$)
   IF MID$(a$, a, 1) = "," THEN b = a
NEXT a
d$ = MID$(a$, b + 1, LEN(a$) - b)
c$ = MID$(a$, 5, b - 5)
LC = LEN(c$)
ld = LEN(d$)
'PRINT c$, d$
'STOP

'ROL,ROR,RCL,RCR,SHL,SHR,SAL,SAR
IF b$ = "ROL" THEN lx = 0
IF b$ = "ROR" THEN lx = 1
IF b$ = "RCL" THEN lx = 2
IF b$ = "RCR" THEN lx = 3
IF b$ = "SHL" THEN lx = 4
IF b$ = "SHR" THEN lx = 5
IF b$ = "SAL" THEN lx = 6
IF b$ = "SAR" THEN lx = 7
IF d$ = "1" THEN lx2 = 1
IF d$ = "CL" THEN lx2 = 2
''continue here

IF c$ = "AL" OR c$ = "AH" THEN CDD = 1
IF c$ = "CL" OR c$ = "CH" THEN CDD = 1
IF c$ = "DL" OR c$ = "DH" THEN CDD = 1
IF c$ = "BL" OR c$ = "BH" THEN CDD = 1
IF LEFT$(c$, 4) = "BYTE" THEN CDD = 3

IF c$ = "EAX" OR c$ = "ESP" THEN eax = 1: c$ = MID$(a$, 6, b - 6)
IF c$ = "ECX" OR c$ = "EBP" THEN eax = 1: c$ = MID$(a$, 6, b - 6)
IF c$ = "EDX" OR c$ = "ESI" THEN eax = 1: c$ = MID$(a$, 6, b - 6)
IF c$ = "EBX" OR c$ = "EDI" THEN eax = 1: c$ = MID$(a$, 6, b - 6)
IF c$ = "AX" OR c$ = "SP" THEN CDD = 2
IF c$ = "CX" OR c$ = "BP" THEN CDD = 2
IF c$ = "DX" OR c$ = "SI" THEN CDD = 2
IF c$ = "BX" OR c$ = "DI" THEN CDD = 2
IF LEFT$(c$, 4) = "WORD" THEN CDD = 4

IF CDD = 1 THEN
   IF c$ = "AL" THEN cda = 0
   IF c$ = "CL" THEN cda = 1
   IF c$ = "DL" THEN cda = 2
   IF c$ = "BL" THEN cda = 3
   IF c$ = "AH" THEN cda = 4
   IF c$ = "CH" THEN cda = 5
   IF c$ = "DH" THEN cda = 6
   IF c$ = "BH" THEN cda = 7
END IF

IF CDD = 2 THEN
   IF c$ = "AX" THEN cda = 0
   IF c$ = "CX" THEN cda = 1
   IF c$ = "DX" THEN cda = 2
   IF c$ = "BX" THEN cda = 3
   IF c$ = "SP" THEN cda = 4
   IF c$ = "BP" THEN cda = 5
   IF c$ = "SI" THEN cda = 6
   IF c$ = "DI" THEN cda = 7
END IF

'137D:0100 D201          ROL     BYTE PTR [BX+DI],CL
'137D:0102 D202          ROL     BYTE PTR [BP+SI],CL
'137D:0104 D203          ROL     BYTE PTR [BP+DI],CL
'137D:0106 D204          ROL     BYTE PTR [SI],CL
'137D:0108 D205          ROL     BYTE PTR [DI],CL
'137D:010A D2060000      ROL     BYTE PTR [0000],CL
'137D:010E D207          ROL     BYTE PTR [BX],CL
IF CDD = 3 OR CDD = 4 THEN
   c$ = MID$(a$, 14, b - 14)
   IF c$ = "[BX+SI]" THEN LX3 = 0: GOTO 8
   IF c$ = "[BX+DI]" THEN LX3 = 1: GOTO 8
   IF c$ = "[BP+SI]" THEN LX3 = 2: GOTO 8
   IF c$ = "[BP+DI]" THEN LX3 = 3: GOTO 8
   IF c$ = "[SI]" THEN LX3 = 4: GOTO 8
   IF c$ = "[DI]" THEN LX3 = 5: GOTO 8
   IF LEFT$(c$, 1) = "[" AND RIGHT$(c$, 1) = "]" THEN LX3 = 6: GOTO 8
   IF c$ = "[BX]" THEN LX3 = 7: GOTO 8

   IF LEFT$(c$, 6) = "[BX+SI+" AND LEN(c$) = 10 THEN
      LX3 = 0
      lx = lx + 8
      x$ = hex2$(MID$(c$, 8, 2))
      GOTO 8
   END IF
   IF LEFT$(c$, 6) = "[BX+DI+" AND LEN(c$) = 10 THEN
      LX3 = 1
      lx = lx + 8
      x$ = hex2$(MID$(c$, 8, 2))
      GOTO 8
   END IF
   IF LEFT$(c$, 6) = "[BP+SI+" AND LEN(c$) = 10 THEN
      LX3 = 2
      lx = lx + 8
      x$ = hex2$(MID$(c$, 8, 2))
      GOTO 8
   END IF
   IF LEFT$(c$, 6) = "[BP+DI+" AND LEN(c$) = 10 THEN
      LX3 = 3
      lx = lx + 8
      x$ = hex2$(MID$(c$, 8, 2))
      GOTO 8
   END IF
   IF LEFT$(c$, 4) = "[SI+" AND LEN(c$) = 7 THEN
      LX3 = 4
      lx = lx + 8
      x$ = hex2$(MID$(c$, 5, 2))
      GOTO 8
   END IF
   IF LEFT$(c$, 4) = "[DI+" AND LEN(c$) = 7 THEN
      LX3 = 5
      lx = lx + 8
      x$ = hex2$(MID$(c$, 5, 2))
      GOTO 8
   END IF
   IF LEFT$(c$, 4) = "[BP+" AND LEN(c$) = 7 THEN
      LX3 = 6
      lx = lx + 8
      x$ = hex2$(MID$(c$, 5, 2))
      GOTO 8
   END IF
   IF LEFT$(c$, 4) = "[BX+" AND LEN(c$) = 7 THEN
      LX3 = 7
      lx = lx + 8
      x$ = hex2$(MID$(c$, 5, 2))
      GOTO 8
   END IF

   IF LEFT$(c$, 6) = "[BX+SI+" AND LEN(c$) = 12 THEN
      LX3 = 0
      lx = lx + 16
      x$ = hex3$(MID$(c$, 8, 4))
      GOTO 8
   END IF
   IF LEFT$(c$, 6) = "[BX+DI+" AND LEN(c$) = 12 THEN
      LX3 = 1
      lx = lx + 16
      x$ = hex3$(MID$(c$, 8, 4))
      GOTO 8
   END IF
   IF LEFT$(c$, 6) = "[BP+SI+" AND LEN(c$) = 12 THEN
      LX3 = 2
      lx = lx + 16
      x$ = hex3$(MID$(c$, 8, 4))
      GOTO 8
   END IF
   IF LEFT$(c$, 6) = "[BP+DI+" AND LEN(c$) = 12 THEN
      LX3 = 3
      lx = lx + 16
      x$ = hex3$(MID$(c$, 8, 4))
      GOTO 8
   END IF
   IF LEFT$(c$, 4) = "[SI+" AND LEN(c$) = 9 THEN
      LX3 = 4
      lx = lx + 16
      x$ = hex3$(MID$(c$, 5, 4))
      GOTO 8
   END IF
   IF LEFT$(c$, 4) = "[DI+" AND LEN(c$) = 9 THEN
      LX3 = 5
      lx = lx + 16
      x$ = hex3$(MID$(c$, 5, 4))
      GOTO 8
   END IF
   IF LEFT$(c$, 4) = "[BP+" AND LEN(c$) = 9 THEN
      LX3 = 6
      lx = lx + 16
      x$ = hex3$(MID$(c$, 5, 4))
      GOTO 8
   END IF
   IF LEFT$(c$, 4) = "[BX+" AND LEN(c$) = 9 THEN
      LX3 = 7
      lx = lx + 16
      x$ = hex3$(MID$(c$, 5, 4))
      GOTO 8
   END IF
END IF
8
'STOP
IF CDD = 1 OR CDD = 2 THEN
   'lx type, cdd=register type, cda=actual register,lx2=(1 or cl)
   IF lx2 = 1 AND CDD = 1 THEN b$ = CHR$(208) + CHR$(192 + (lx * 8) + cda)
   IF lx2 = 1 AND CDD = 2 THEN b$ = CHR$(209) + CHR$(192 + (lx * 8) + cda)
   IF lx2 = 2 AND CDD = 1 THEN b$ = CHR$(210) + CHR$(192 + (lx * 8) + cda)
   IF lx2 = 2 AND CDD = 2 THEN b$ = CHR$(211) + CHR$(192 + (lx * 8) + cda)
END IF

IF CDD = 3 THEN
   IF lx2 = 1 THEN b$ = CHR$(208) + CHR$((lx * 8) + LX3) + x$
   IF lx2 = 2 THEN b$ = CHR$(210) + CHR$((lx * 8) + LX3) + x$
END IF
IF CDD = 4 THEN
   IF lx2 = 1 THEN b$ = CHR$(209) + CHR$((lx * 8) + LX3) + x$
   IF lx2 = 2 THEN b$ = CHR$(211) + CHR$((lx * 8) + LX3) + x$
END IF

IF eax = 0 THEN PAT2$ = b$
IF eax = 1 THEN PAT2$ = CHR$(102) + b$
END FUNCTION

FUNCTION qual$ (a$)
FOR a = 1 TO LEN(a$)
   IF MID$(a$, a, 1) = "," THEN b = a
NEXT a
c$ = ""
IF b = 0 THEN GOTO 31
b$ = RIGHT$(a$, LEN(a$) - b)
'STOP
s = 8
IF LEFT$(b$, 1) = "[" THEN s = s + 2
IF LEN(b$) = s THEN
   IF s = 10 THEN c$ = hex3$(MID$(b$, 2, 4)) + LEFT$(a$, b + 1) + RIGHT$(b$, 5)
   IF s = 8 THEN c$ = hex3$(MID$(b$, 1, 4)) + LEFT$(a$, b) + RIGHT$(b$, 4)
   'STOP
END IF
31
qual$ = c$
END FUNCTION

FUNCTION SVB$ (a)
b = INT(a / 256)
c = a - (b * 256)
IF b < 0 THEN b = 0
IF c < 0 THEN c = 0
REM in case a negative, it will make itself clear
SVB$ = CHR$(c) + CHR$(b)
END FUNCTION

FUNCTION SVE (a$)
b = ASC(MID$(a$, 1, 1))
c = ASC(MID$(a$, 2, 1))
d = (c * 256) + b
SVE = d
END FUNCTION

