'===========================================================================
' Subject: BETTER ANSI TO .COM OUTPUT         Date: 01-10-97 (12:15)       
'  Author: Thomas Matysik                     Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: ANSI.ABC
'===========================================================================
'>It will work perfectly, unless the ANSI screen has a $ in it, the DOS
'>end-of-line character.  When the program hits this, it ceases to print and
'>the program quits.

'Here's my attempt, which works perfectly as far as I can see, even with
'a $ in it:

'* ANSI2COM.BAS *
'* By Thomas Matysik *

'* PUBLIC DOMAIN *

Cmd$ = COMMAND$
IF LEN(Cmd$) = 0 THEN
  PRINT "USAGE: ANSI2BIN <ansifile> <comfile> [W]"
  PRINT
  PRINT "where W means the .COM file should wait for a keypress before exiting."
  PRINT
END IF

AnsiFile$ = LEFT$(Cmd$, INSTR(Cmd$, " "))
ComFile$ = RIGHT$(Cmd$, LEN(Cmd$) - INSTR(Cmd$, " "))
IF INSTR(ComFile$, " ") THEN
  Switch$ = RIGHT$(ComFile$, LEN(ComFile$) - INSTR(ComFile$, " "))
  ComFile$ = LEFT$(ComFile$, INSTR(ComFile$, " "))
END IF

OPEN AnsiFile$ FOR BINARY AS #1
OPEN ComFile$ FOR BINARY AS #2

'Executable header for COM file
header$ = CHR$(&H56) + CHR$(&HB4) + CHR$(&H6) + CHR$(&HBA) + CHR$(&H1B)
header$ = header$ + CHR$(&H1) + CHR$(&H89) + CHR$(&HD6) + CHR$(&HFC)
header$ = header$ + CHR$(&HAC) + CHR$(&H3C) + CHR$(&H0) + CHR$(&H74)
header$ = header$ + CHR$(&H6) + CHR$(&H8A) + CHR$(&HD0) + CHR$(&HCD)
header$ = header$ + CHR$(&H21) + CHR$(&HEB) + CHR$(&HF5) + CHR$(&H5E)

'If switch = W, then wait for keypress at end of COM file, else 4 NOPs
IF UCASE$(Switch$) = "W" THEN
  header$ = header$ + CHR$(&HB4) + CHR$(&H0) + CHR$(&HCD) + CHR$(&H16)
ELSE
  header$ = header$ + CHR$(&H90) + CHR$(&H90) + CHR$(&H90) + CHR$(&H90)
END IF

header$ = header$ + CHR$(&HCD) + CHR$(&H20)

MyData$ = SPACE$(LOF(1))
PRINT
PRINT "Reading ANSI file."

GET #1, , MyData$
MyData$ = MyData$ + CHR$(0)     'Add null terminator to ansi file

PRINT "Writing COM file."
PUT #2, , header$
PUT #2, , MyData$

PRINT
CLOSE
END

'My ASM code was:

'        push  si
'        mov   ah,6
'        lea   dx,ansi
'        mov   si,dx

'        StartOfLoop:
'        cld
'        lodsb
'        cmp   al,00
'        jz    EndOfLoop
'        mov   dl,al
'        int   21h
'        jmp   StartOfLoop

'        EndOfLoop:
'        pop   si
'        nop
'        nop
'        nop
'        nop
'        int   20h

'        ansi  db ''


'>       What I (or we) need to do is find the $'s in the file, then make
'>separate ASM variables (or addresses) for them.  That part shouldn't be too
'>much trouble.  The part that I don't know how to do is to actually print a $
'>to the screen.  I don't know if you can use int21h to do it or not.

'You just have to use int 21h, AH=06, to print 1 character at a time,
'as I have done.  I also added an extra feature so that if the
'convertion program is started with the W switch, it will add extra code
'to wait for a keypress before exiting the COM file.  In this case, the
'four NOP instructions before the last INT 20h are changed to:

'        mov  ah,00
'        int  21h
