[comp.os.msdos.programmer] Dual Monitor Switching

roger@wrq.com (Roger Fulton) (03/12/91)

In article <1991Mar11.172914.4450@engin.umich.edu> pong@caen.engin.umich.edu (Bryan John Jalowitz) writes:
>
>Hi,
>I would like to know how, from within an application, I can switch
>monitors in a dual configuration.  I would like something similar to
>"mode mono" vs. "mode co80", but that does not clear the display.
>
>More specifically, I am using a VGA/HERC dual monitor configuration,
>and I would like to be able to route text/graphics to one or the other
>display systems.  I know about setting the mode with int 10h func 0,
>but there appears to be more to it than that.  That doesn't "switch" the
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>video bios' notion of the current display.

Yes, there is.  In addition to setting the video mode,
you need to also update the equipment flag at 0040:0010
appropriately: xx10xxxx for color, xx11xxxx for mono
(where 'x' means leave it alone).  Also, you should account
for the fact that color systems have a different maximum
cursor line count than mono systems (so you should save and
restore the cursor when changing video modes).






.
-- 
Roger Fulton
roger@wrq.com

rkl@cbnewsh.att.com (kevin.laux) (03/12/91)

In article <1991Mar11.172914.4450@engin.umich.edu>, pong@caen.engin.umich.edu (Bryan John Jalowitz) writes:
> 
> Hi,
> I would like to know how, from within an application, I can switch
> monitors in a dual configuration.  I would like something similar to
> "mode mono" vs. "mode co80", but that does not clear the display.
> 
> More specifically, I am using a VGA/HERC dual monitor configuration,
> and I would like to be able to route text/graphics to one or the other
> display systems.  I know about setting the mode with int 10h func 0,
> but there appears to be more to it than that.  That doesn't "switch" the
> video bios' notion of the current display.
> 
> What am I missing here?

	You're missing Int 10h Function 12h Subfunction 35h, the Display
Switch Interface.

	AH:	12h
	BL:	35h
	AL:	0	Initial external adapter off
		1	Initial VGA on
		2	Active adapter off
		3	Inactive adapter on
	ES:	Segment of Switch State area
	DX:	Offset of Switch State area

	The first time you switch displays you must use AL=0,1.  After that,
you use a double call to AL=2,3.  The Switch state area is a 128 byte buffer
and each display needs it own.

-- 
________________________________________________________________________________
	R. Kevin Laux				Email: rkl1@hound.att.com
	AT&T Bell Labs				Voice: (908) 949-1160
	Holmdel, NJ 07733			Fax:   (908) 949-0959

rkl@cbnewsh.att.com (kevin.laux) (03/12/91)

In article <18203@milton.u.washington.edu>, roger@wrq.com (Roger Fulton) writes:
> In article <1991Mar11.172914.4450@engin.umich.edu> pong@caen.engin.umich.edu (Bryan John Jalowitz) writes:
> >
> >Hi,
> >I would like to know how, from within an application, I can switch
> >monitors in a dual configuration.  I would like something similar to
> >"mode mono" vs. "mode co80", but that does not clear the display.
> >
> >More specifically, I am using a VGA/HERC dual monitor configuration,
> >and I would like to be able to route text/graphics to one or the other
> >display systems.  I know about setting the mode with int 10h func 0,
> >but there appears to be more to it than that.  That doesn't "switch" the
>      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >video bios' notion of the current display.
> 
> Yes, there is.  In addition to setting the video mode,
> you need to also update the equipment flag at 0040:0010
> appropriately: xx10xxxx for color, xx11xxxx for mono
> (where 'x' means leave it alone).  Also, you should account
> for the fact that color systems have a different maximum
> cursor line count than mono systems (so you should save and
> restore the cursor when changing video modes).

	Yes, there is but this is not it!  Those bits in the equipment flag word
are for the *INITIAL* video mode.  Changing those bits will *not* effect a
display adapter switch.  As I answered in alt.msdos.programmer, what's missing
is Int 10h, Function 12h, Subfunction 35h:

	AH:	12h
	BL:	35h
	AL:	0	Initial external adapter off
		1	Initial VGA on
		2	Active adapter off
		3	Inactive adapter on
	ES:	Segment of Switch State area
	DX:	Offset of Switch State area

	The first time display adapters are switched call the subfunction with
AL=0, then again with AL=1.  Thereafter, double calls with AL=2,3 are used.
The Switch State area is a 128 byte buffer and each display needs its own.

-- 
________________________________________________________________________________
	R. Kevin Laux				Email: rkl1@hound.att.com
	AT&T Bell Labs				Voice: (908) 949-1160
	Holmdel, NJ 07733			Fax:   (908) 949-0959

pong@caen.engin.umich.edu (Bryan John Jalowitz) (03/13/91)

In article <1991Mar12.133739.28811@cbnewsh.att.com> rkl@cbnewsh.att.com (kevin.laux) writes:
>
>	You're missing Int 10h Function 12h Subfunction 35h, the Display
>Switch Interface.
>
>	AH:	12h
>	BL:	35h
>	AL:	0	Initial external adapter off
>		1	Initial VGA on
>		2	Active adapter off
>		3	Inactive adapter on
>	ES:	Segment of Switch State area
>	DX:	Offset of Switch State area
>
>	The first time you switch displays you must use AL=0,1.  After that,
>you use a double call to AL=2,3.  The Switch state area is a 128 byte buffer
>and each display needs it own.
>
My documentation ("Programmer's guide to PC & PS/2 video systems", Microsoft
Press) says that this function is for PS/2 video systems.  I tried it 
anyway, in case the book's information was old, however I do not get a
successful return value.  I am using an AT clone with both cards on an
ISA bus.  Should this still apply?

Any other ideas?

Tony Whipple
Tony_Whipple@um.cc.umich.edu

jwbirdsa@amc-gw.amc.com (James Birdsall) (03/13/91)

In article <1991Mar12.140842.63@cbnewsh.att.com> rkl@cbnewsh.att.com (kevin.laux) writes:
>In article <18203@milton.u.washington.edu>, roger@wrq.com (Roger Fulton) writes:
>> In addition to setting the video mode,
>> you need to also update the equipment flag at 0040:0010
>> appropriately: xx10xxxx for color, xx11xxxx for mono
>> (where 'x' means leave it alone).  Also, you should account
>> for the fact that color systems have a different maximum
>> cursor line count than mono systems (so you should save and
>> restore the cursor when changing video modes).
>
>	Yes, there is but this is not it!  Those bits in the equipment flag word
>are for the *INITIAL* video mode.  Changing those bits will *not* effect a
>display adapter switch.  

   Sorry. Setting the BIOS equipment flag is the correct way to start. THEN
you have to do a video mode switch to an appropriate mode. This is a known
technique that works on a wide variety of machines that I have tried.

>As I answered in alt.msdos.programmer, what's missing
>is Int 10h, Function 12h, Subfunction 35h:
>
>	AH:	12h
>	BL:	35h
>	AL:	0	Initial external adapter off
>		1	Initial VGA on
>		2	Active adapter off
>		3	Inactive adapter on
>	ES:	Segment of Switch State area
>	DX:	Offset of Switch State area
>
>	The first time display adapters are switched call the subfunction with
>AL=0, then again with AL=1.  Thereafter, double calls with AL=2,3 are used.
>The Switch State area is a 128 byte buffer and each display needs its own.

   This, on the other hand, is just plain wrong. I quote:

"Switch Active Display

"Allows selection of one of two video adapters in the system, when memory
usage or port addresses conflict between the two adapters.

"Notes:

"This subfunction cannot be used unless both video adapters have a disable
capability (Int 10H Function 12H Subfunction 32H).

'If there is no conflict between the system board video and the adapter
board video in memory or port usage, both video controllers can be active
simultaneously and this subfunction is not required."

Ray Duncan, Programmer's Quick Reference Series, _IBM ROM BIOS_.

   A Hercules board does not have its own ROM, depending on the motherboard
BIOS to support it. Since this function only appeared with the advent of
VGA, the Hercules board does not have a disable function.

   Furthermore, there is no memory or port conflict between the two boards.
At a hardware level, it is possible to access both simultaneously without
difficulty. However, to use them via the BIOS or DOS, it is necessary to
switch between them using the technique outlined at the top of this
article.

-- 
James W. Birdsall   WORK: jwbirdsa@amc.com   {uunet,uw-coco}!amc-gw!jwbirdsa
HOME: {uunet,uw-coco}!amc-gw!picarefy!jwbirdsa OTHER: 71261.1731@compuserve.com
================== Kitten: a small homicidal muffin on legs. ==================
=========== "For it is the doom of men that they forget." -- Merlin ===========

roger@wrq.com (Roger Fulton) (03/13/91)

Well, this is really getting interesting now.
First we have this:

In article <1991Mar12.140842.63@cbnewsh.att.com>, rkl@cbnewsh.att.com (kevin.laux) writes:
> In article <18203@milton.u.washington.edu>, roger@wrq.com (Roger Fulton) writes:
> > In article <1991Mar11.172914.4450@engin.umich.edu> pong@caen.engin.umich.edu (Bryan John Jalowitz) writes:
> > >
> > >Hi,
> > >I would like to know how, from within an application, I can switch
> > >monitors in a dual configuration.  I would like something similar to
> > >"mode mono" vs. "mode co80", but that does not clear the display.
> > >
> > >More specifically, I am using a VGA/HERC dual monitor configuration,
> > >and I would like to be able to route text/graphics to one or the other
> > >display systems.  I know about setting the mode with int 10h func 0,
> > >but there appears to be more to it than that.  That doesn't "switch" the
> >      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > >video bios' notion of the current display.
> > 
> > Yes, there is.  In addition to setting the video mode,
> > you need to also update the equipment flag at 0040:0010
> > appropriately: xx10xxxx for color, xx11xxxx for mono
> > (where 'x' means leave it alone).  Also, you should account
> > for the fact that color systems have a different maximum
> > cursor line count than mono systems (so you should save and
> > restore the cursor when changing video modes).
> 
> 	Yes, there is but this is not it!  Those bits in the equipment flag word
> are for the *INITIAL* video mode.  Changing those bits will *not* effect a
> display adapter switch.  As I answered in alt.msdos.programmer, what's missing
> is Int 10h, Function 12h, Subfunction 35h:
> 
> 	AH:	12h
> 	BL:	35h
> 	AL:	0	Initial external adapter off
> 		1	Initial VGA on
> 		2	Active adapter off
> 		3	Inactive adapter on
> 	ES:	Segment of Switch State area
> 	DX:	Offset of Switch State area
> 
> 	The first time display adapters are switched call the subfunction with
> AL=0, then again with AL=1.  Thereafter, double calls with AL=2,3 are used.
> The Switch State area is a 128 byte buffer and each display needs its own.


Then we have this:


In article <1991Mar12.175839.1687@engin.umich.edu>, pong@caen.engin.umich.edu (Bryan John Jalowitz) writes:
> In article <1991Mar12.133739.28811@cbnewsh.att.com> rkl@cbnewsh.att.com (kevin.laux) writes:
> >
> >	You're missing Int 10h Function 12h Subfunction 35h, the Display
> >Switch Interface.
> >
> >	AH:	12h
> >	BL:	35h
> >	AL:	0	Initial external adapter off
> >		1	Initial VGA on
> >		2	Active adapter off
> >		3	Inactive adapter on
> >	ES:	Segment of Switch State area
> >	DX:	Offset of Switch State area
> >
> >	The first time you switch displays you must use AL=0,1.  After that,
> >you use a double call to AL=2,3.  The Switch state area is a 128 byte buffer
> >and each display needs it own.
> >
> My documentation ("Programmer's guide to PC & PS/2 video systems", Microsoft
> Press) says that this function is for PS/2 video systems.  I tried it 
> anyway, in case the book's information was old, however I do not get a
> successful return value.  I am using an AT clone with both cards on an
> ISA bus.  Should this still apply?
> 
> Any other ideas?
> 
> Tony Whipple
> Tony_Whipple@um.cc.umich.edu


Well, Tony, I'm gratified to see that R. Kevin Laux's "solution"
did not work for you; I knew it wouldn't.  As you pointed out,
INT 10h, Func 12h, Subfunc 35h ONLY applies to PS/2 video systems.

From the well-known list of interrupts:

"INT 10 - VIDEO - ALTERNATE FUNCTION SELECT (PS) - DISPLAY-SWITCH INTERFACE
                                             ^^
                                             This means PS/2 ONLY.
         AH = 12h
         BL = 35h
         AL = 00h initial adapter video off
              01h initial planar video on
              02h switch active video off
              03h switch inactive video on
               80h *UNDOCUMENTED* set system board video active flag
         ES:DX = buffer (128 byte save area if AL = 0, 2 or 3)
 Return: AL = 12h if function supported"

From the "Programmer's Guide to PC & PS/2 Video Systems", Microsoft
Press (good choice, Tony):

"INT 10H function 1AH with BL = 35H provides a set of routines
that support switching between two PS/2 video subsystems in
the same computer.  In a computer that contains two different
PS/2-compatible video subsystems, calls to this function let a
program separately access the video BIOS on a video adapter and
the video BIOS on a PS/2 motherboard."

From "The New Peter Norton Programmer's Guide to the IBM PC
and PS/2, Microsoft Press:

"Subservices 32H (decimal 50) and 35H (decimal 53) are provided for
programmers who want to use two different video subsystems in the
same PS/2 computer.  In particular, these routines support the use
of a VGA alongside the built-in MCGA subsystem in a PS/2 Model 30."

So, well, gee, hmmmm, it kind of maybe looks like you wouldn't
want to use R. Kevin Laux's "solution" for the configuration
Tony has (VGA/Herc).

But, to be ABSOLUTELY SURE, I ran the following code (from
the "Programmer's Guide to PC & PS/2 Video Systems", Microsoft
Press) as a test:

---------------------------------------------------------------------------
        page    60,132

data segment public 'data'
        assume  ds:data

VGAsave         db      128 dup(?)
MCGAsave        db      128 dup(?)

data ends

code segment public 'code'
        assume  cs:code, ds:nothing, es:nothing
start:
        mov     ax,1200h
        mov     bl,35h
        mov     dx,seg VGAsave
        mov     es,dx
        mov     dx,offset VGAsave
        int     10h
        cmp     al,12h                  ; here's the test, folks
        jne     Error

        mov     ax,1201h
        mov     bl,35h
        int     10h

        mov     ax,1202h
        mov     bl,35h
        mov     dx,seg VGAsave
        mov     es,dx
        mov     dx,offset VGAsave
        int     10h

        mov     ax,1203h
        mov     bl,35h
        mov     dx,offset MCGAsave
        int     10h
Error:
        mov     ah,4ch
        int     21h
code ends

        end     start
---------------------------------------------------------------------------

In my AST 386/25, I have a Paradise Professional VGA and a
Hercules Incolor Plus.  Needless to say, when I ran the
above code, I did not flip from one screen to another.
Furthermore, when stepping thru the code with Periscope,
I saw that the value of AL at the line commented above as
"here's the test, folks" was zero (not 12H).  Seems like
proof to me.

To do the equivalent of MODE MONO or MODE CO80 (which I think
is what you want to do, Tony) you (as I said previously):

- set the equipment flag appropriately
- make the appropriate "set video mode" BIOS call

(This is exactly what MODE MONO and MODE CO80 do; I have
stepped thru them with Periscope and watched it happen.)

(As I also said previously, I think it's nice to also save and
restore the cursor configuration when switching between
screens.)

Example code for doing this is located at the end of chapter 1
in (guess what) the "Programmer's Guide to PC & PS/2 Video 
Systems", Microsoft Press.

About the equipment flag: yes, R. Kevin Laux, bits 4 and 5 DO
indicate the *initial* video mode.  So, why would you need
to update these bits?  Once again from the "Programmer's Guide
to PC & PS/2 Video Systems", Microsoft Press:

"The BIOS video mode routines generally support dual-display
configurations.  The video BIOS routines use bits 4 and 5
of the variable EQUIP_FLAG at 0040:0010 in the BIOS video
data area to choose between two video subsystems."

So, R. Kevin Laux, do you still say, "Yes, there is but this is 
not it!"?
-- 
Roger Fulton
roger@wrq.com

pong@caen.engin.umich.edu (Bryan John Jalowitz) (03/13/91)

In article <18300@milton.u.washington.edu> roger@wrq.com (Roger Fulton) writes:
>Well, this is really getting interesting now.
>First we have this:
>
[summary of most of discussion deleted]
>> > Yes, there is.  In addition to setting the video mode,
>> > you need to also update the equipment flag at 0040:0010
>> > appropriately: xx10xxxx for color, xx11xxxx for mono
>> > (where 'x' means leave it alone).  Also, you should account
>> > for the fact that color systems have a different maximum
>> > cursor line count than mono systems (so you should save and
>> > restore the cursor when changing video modes).

I tried this last night and it works like a charm.  Many thanks
to Roger and everyone who joined the discussion.

rkl@cbnewsh.att.com (kevin.laux) (03/13/91)

In article <1991Mar12.175839.1687@engin.umich.edu>, pong@caen.engin.umich.edu (Bryan John Jalowitz) writes:
> In article <1991Mar12.133739.28811@cbnewsh.att.com> rkl@cbnewsh.att.com (kevin.laux) writes:
> >
> >	You're missing Int 10h Function 12h Subfunction 35h, the Display
> >Switch Interface.
> >
> >	AH:	12h
> >	BL:	35h
> >	AL:	0	Initial external adapter off
> >		1	Initial VGA on
> >		2	Active adapter off
> >		3	Inactive adapter on
> >	ES:	Segment of Switch State area
> >	DX:	Offset of Switch State area
> >
> >	The first time you switch displays you must use AL=0,1.  After that,
> >you use a double call to AL=2,3.  The Switch state area is a 128 byte buffer
> >and each display needs it own.
> >
> My documentation ("Programmer's guide to PC & PS/2 video systems", Microsoft
> Press) says that this function is for PS/2 video systems.  I tried it 
> anyway, in case the book's information was old, however I do not get a
> successful return value.  I am using an AT clone with both cards on an
> ISA bus.  Should this still apply?
> 
> Any other ideas?

	The book says that subfunction 35h was provided for PS/2 systems with
a VGA along with the built-in MCGA.  It does *not* say that it works *only*
on PS/2 systems.  In Chapter 13 (pg 269) under the ROM BIOS Services Summary,
the Notes for this subservice say only MCGA, VGA.  It is clearly a VGA
function (since one would add a VGA to the already existing MCGA in the PS/2
case).  Not all VGA cards/BIOS's support all functions.  Looks like yours
doesn't since AL!=12h after the call.

	I suppose one could play with the bits in 40:87h through 40:89h, in
particular, 40:87h bit 3 (0 = VGA system active, 1 = not active), and 40:89h
bit 6 (0 = display switching disabled, 1 = enabled).

-- 
________________________________________________________________________________
	R. Kevin Laux				Email: rkl1@hound.att.com
	AT&T Bell Labs				Voice: (908) 949-1160
	Holmdel, NJ 07733			Fax:   (908) 949-0959

rkl@cbnewsh.att.com (kevin.laux) (03/13/91)

In article <6150@amc-gw.amc.com>, jwbirdsa@amc-gw.amc.com (James Birdsall) writes:
> In article <1991Mar12.140842.63@cbnewsh.att.com> rkl@cbnewsh.att.com (kevin.laux) writes:
> >In article <18203@milton.u.washington.edu>, roger@wrq.com (Roger Fulton) writes:
> >> In addition to setting the video mode,
> >> you need to also update the equipment flag at 0040:0010
> >> appropriately: xx10xxxx for color, xx11xxxx for mono
> >> (where 'x' means leave it alone).  Also, you should account
> >> for the fact that color systems have a different maximum
> >> cursor line count than mono systems (so you should save and
> >> restore the cursor when changing video modes).
> >
> >	Yes, there is but this is not it!  Those bits in the equipment flag word
> >are for the *INITIAL* video mode.  Changing those bits will *not* effect a
> >display adapter switch.  
> 
>    Sorry. Setting the BIOS equipment flag is the correct way to start. THEN
> you have to do a video mode switch to an appropriate mode. This is a known
> technique that works on a wide variety of machines that I have tried.
> 
	[Switch Active Display stuff deleted]

	Ok, I stand corrected and agree about using Switch Active Display
with a Hercules/VGA combination.  What you're saying is, start with changing
the Equipment word and then to access the Hercules, switch to Video Mode 07.
Wouldn't you also have to setup bit 3 at 40:87H and bit 6 at 40:89
(bit 3, 0 = VGA active, 1 = inactive; bit 6, 0 = display switch disabled,
1 = enabled)?  Or does the Mode switch take care of this?

-- 
________________________________________________________________________________
	R. Kevin Laux				Email: rkl1@hound.att.com
	AT&T Bell Labs				Voice: (908) 949-1160
	Holmdel, NJ 07733			Fax:   (908) 949-0959

jwbirdsa@amc-gw.amc.com (James Birdsall) (03/15/91)

In article <1991Mar13.145206.4281@cbnewsh.att.com> rkl@cbnewsh.att.com (kevin.laux) writes:
>	Ok, I stand corrected and agree about using Switch Active Display
>with a Hercules/VGA combination.  What you're saying is, start with changing
>the Equipment word and then to access the Hercules, switch to Video Mode 07.
>Wouldn't you also have to setup bit 3 at 40:87H and bit 6 at 40:89
>(bit 3, 0 = VGA active, 1 = inactive; bit 6, 0 = display switch disabled,
>1 = enabled)?  Or does the Mode switch take care of this?

   Only if the color system is an EGA or better. [40:87H] exists for EGA
and up; [40:89H] is only with VGA and MCGA.
   The information in the BIOS data area does not control anything directly 
-- it is mostly a scratchpad. Video system information is kept because on 
most adapters (everything but MCGA and VGA) the hardware registers cannot
be read, so the BIOS must keep its own copy. And then there is information
that is only meaningful to the BIOS, such as the video mode number. The
hardware doesn't know anything about modes; the mode number is an index
into a table of actual hardware register values that the BIOS uses for
convenience.

   What we are doing when we switch displays is playing with the BIOS's
head. The following is speculation, but conforms with the observed behavior
of the BIOS.
   First, we change the equipment flag to indicate a mono setup. This has
no effect until the next call to the video BIOS. This next call is to
change to mode 7. Mode 7 is a monochrome mode; the equipment flag indicates
mono hardware. Fine. So the BIOS happily sets the CRTC base address [40:63]
to 3B4h, writes the appropriate values to the mono CRTC's registers, and
lo, the mono screen is active. The BIOS is no longer even aware that there
*is* a color setup.

   Actually, some parts of the BIOS are multiple-monitor aware. For
example, there is one call (func 1Ah, which returns information on the
active video configuration and the inactive video, if there is such). But
all these calls are only in the VGA and PS/2 BIOSes (BIOSi? BIi? :)). The
original set of calls, which included the mode change, were not aware of
multiple monitors and hence the later implementations are not either -- at
least in any way that would infringe on backward compatibility.
   The VGA BIOS in my Compaq 386/20e does in fact toggle the VGA
active/inactive bit. The switch enable/disable bit is permanently disabled,
presumably because there is only one video setup in the system which has
this capacity, which renders it meaningless.

-- 
James W. Birdsall   WORK: jwbirdsa@amc.com   {uunet,uw-coco}!amc-gw!jwbirdsa
HOME: {uunet,uw-coco}!amc-gw!picarefy!jwbirdsa OTHER: 71261.1731@compuserve.com
================== Kitten: a small homicidal muffin on legs. ==================
=========== "For it is the doom of men that they forget." -- Merlin ===========