Detect ANSI in QB45 in DOSBOX

163 Views Asked by At

I have been using DOSbox and ANSI with some success, but I want to detect ANSI installed.

Ralf Brown description for detecting ANSI is:

--------V-2F1A00-----------------------------
INT 2F - DOS 4.0+ ANSI.SYS - INSTALLATION CHECK
    AX = 1A00h
Return: AL = FFh if installed
Notes:  AVATAR.SYS also responds to this call
   documented for DOS 5+, but undocumented for DOS 4.x

And my code to detect ANSI is:

' detect ansi
InregsX.AX = &H1A00
CALL InterruptX(&H2F, InregsX, OutregsX)
PRINT "AX="; HEX$(OutregsX.AX)
IF (OutregsX.AX AND &HFF) = &HFF THEN
   Ansi.Installed = -1
ELSE
   Ansi.Installed = 0
END IF
IF Ansi.Installed THEN
   PRINT "Ansi installed."
ELSE
   PRINT "Ansi not installed."
END IF

which always displays "Ansi not installed." is there some other way to detect ANSI??

2

There are 2 best solutions below

2
On BEST ANSWER

I wrote this code to detect ANSI:

Cls
Const A$ = "alpha"
Const B$ = "beta"
Open "CONS:" For Output As #1
Print #1, A$
Z$ = Chr$(27) + "[2J" ' ansi cls
Print #1, Z$; B$;
Close #1
For T = 1 To Len(B$)
   T$ = T$ + Chr$(Screen(1, T))
Next
If T$ = B$ Then Print "ANSI detected."
6
On

I think you might resolve making the try to use ANSI codes.

The code below implements the function ansiOn% that returns 1 if an ansi string is written on the screen (used as console: see the code) as expected, otherwise returns 0.

The method that the function implements is to clear the screen and write a string that contains: the first char different from A$, the backward ANSI sequence for 1 char - CSI 1 D - and the content of A$. After the string is written, if the upper left char on the screen is A$ then ANSI is enabled.

DECLARE FUNCTION ansiOn% ()

ansi% = ansiOn%
CLS

PRINT "ANSI is";
IF ansi% = 0 THEN
  PRINT "n't";
END IF

PRINT " enabled."

FUNCTION ansiOn%

  CLS : A$ = "C"
  OPEN "CON" FOR OUTPUT AS #1
  PRINT #1, CHR$(ASC(A$) - 1); CHR$(27); "[1D"; A$;
  CLOSE #1

  IF CHR$(SCREEN(1, 1)) = A$ THEN
    ansiOn% = 1
  ELSE
    ansiOn% = 0
  END IF

END FUNCTION

I tried this code using QB45 in a DOS 6.22 VM and it works.