ega.inc

来自「Dos6.0」· INC 代码 · 共 1,775 行 · 第 1/4 页

INC
1,775
字号
;
; NAME
;	EGA.SYS
;	Video Subsystem EGA Screen Device Driver
;
;	Copyright (C) Microsoft Corporation 1984-1990
;	Copyright (C) IBM 1986-1987
;	Portions Copyright (C) Hewlett-Packard Co. 1987 (by Jim Christy)
;
; WORK-IN-PROGRESS
;	To become version 2.10, this copy still needs :
;	[1] saving/restoring of memory latches in savecontext/restorecontext 
;	    subfunctions	DONE. Marc Pawliger (6/88)
;	[2] alternate save/restore logic in those functions whenever another,
;	    pre-2.0, version of this interface has been loaded on top of us
;	    (this MUST be detected by temporarily locking out our Int10Routine
;	    and issuing an InquireDriver call; only known culprit currently is
;	    Word 3.11) 
;	[3] fully functional VGA support 
;	[4] to be fully tested!
;
; PURPOSE
;	To provide a means of shadowing the state of the EGA's write-only
;	registers, so that the state of the card can be determined at
;	any instant, whether by a Real-mode-only mouse package, a Real-
;	mode pop-up (TSR), or a video manager as found in Windows or OS/2.
;
;	This is done by providing an Extended Int 10h interface (called
;	the EGA Register Interface) for new and existing Real-mode apps,
;	and by providing a set of device driver functions for the video
;	managers.
;
;	If "SYS" is defined, a device driver model is assembled.  Otherwise,
;	a COM file model is assumed, for TSR operation.  If "OS2" is
;	defined, then "SYS" will automatically be defined, and the generated
;	driver will contain the READ and WRITE functions required for OS/2.
;
; SYNOPSIS
;	EGA.SYS is an interface to the EGA card which allows all of the w/o
;	registers to be read from as well as written to.  This is a
;	requirement in order to use interrupt-driven graphics (such as cursor
;	update code).  Interrupt-driven graphics can be implemented on the EGA
;	if both the synchronous app and the interrupt code use the EGA.SYS
;	interface to the EGA registers.  The Microsoft mouse driver (versions
;	3.0 and greater) use the EGA.SYS interface to the EGA card.
;
;	This file contains the code that intercepts the int 10's and keeps
;	shadow maps of all EGA registers so that these registers can be read
;	as well as written.  Note that the primary consideration was speed,
;	some of the calls need to be made in tight graphics loops.  For this
;	reason, the interface may seem arbitrary and the code may seem
;	unnecessarily "tricky" at times.  I've tried to document all such
;	instances.  Also keep in mind that there is no error checking of
;	parameters.  Illegal parameters may cause unpredictable results,
;	including possibly a system crash.
;
; DESCRIPTION
;	The EGA.SYS interface spec follows.  For a more detailed description,
;	see each function header.  Bear in mind that function headers may
;	report a different register usage then that shown here.  They reflect
;	the state of the machine on entry and exit to that particular function
;	when in fact, some regs are restored by the dispatcher and thus do not
;	impact the caller.  For this release, ax, si, and ds will always be
;	restored by the dispatcher unless the spec indicates it specifically
;	returns a value in these regs.
;
;	In most of the following calls, dx is expected to point to a "register
;	id" which identifies the exact EGA chip to be addressed.  Since the 4
;	LSI chips contain multiple regs, the register index (usually in bl) is
;	also required for these chips.	The valid register ids for dx are:
;
;		port	chips/regs		 id
;		----	--------------		----
;		3x4h	crtc chip		000h
;		3C4h	sequencer chip		008h
;		3CEh	graphics chips		010h
;		3C0h	attribute chip		018h
;		3C2h	misc out reg		020h
;		3xAh	feature reg		028h
;		3CCh	gr 1 pos reg		030h
;		3CAh	gr 2 pos reg		038h
;
;
;	ReadReg - read a single EGA register from shadow maps
;
;	ENTRY
;	      ah      =  0F0h
;	      bx      =  register index 	      if reg id is indexd chip
;			 ignored		      if reg id is single reg
;	      dx      =  register id
;	EXIT
;	      bl      =  current register data
;	DESTROYS
;		None
;
;
;	WriteReg - write to a single EGA register and update shadow maps
;
;	ENTRY
;	      ah      =  0F1h
;	      bl      =  register index 	      if reg id is indexd chip
;			 data to be written	      if reg id is single reg
;	      bh      =  data to be written	      if reg id is indexd chip
;		      =  ignored		      if reg id is single reg
;	      dx      =  register id
;	EXIT
;	      none
;	DESTROYS
;	      bh, dx
;
;
;	ReadRange - read a range of EGA registers from shadow maps
;
;	ENTRY
;	      ah      =  0F2h
;	      dx      =  register id		      must be an indexed chip
;	      cl      =  # of registers to read       (must be > 1 !)
;	      ch      =  starting register index
;	      es:bx   -> buffer to put reg data
;	EXIT
;	      none
;	DESTROYS
;	      cx
;
;
;	WriteRange - write to a range of EGA registers and update shadow maps
;
;	ENTRY
;	      ah      =  0F3h
;	      dx      =  register id		      must be an indexed chip!
;	      cl      =  # of registers to write      (must be > 1 !)
;	      ch      =  starting register index
;	      es:bx   -> buffer to get reg data
;	EXIT
;	      none
;	DESTROYS
;	      bx, cx, dx
;
;
;	ReadSet - read a set of EGA registers from shadow maps
;
;	ENTRY
;	      ah      =  0F4h
;	      cx      =  # of registers to read       (must be > 1 !)
;	      es:bx   -> buffer of contiguous SetRec
;			 structures, one for each register
;			 to be read
;	EXIT
;	      none
;	DESTROYS
;	      cx
;
;
;	WriteSet - write to a set of EGA registers and update shadow maps
;
;	ENTRY
;	      ah      =  0F5h
;	      cx      =  # of registers to write      (must be > 1 !)
;	      es:bx   -> buffer of contiguous SetRec
;			 structures, one for each register
;			 to be written
;	EXIT
;	      none
;	DESTROYS
;	      cx
;
;
;	RevertDefault - blast default shadow maps to EGA, update shadow maps
;
;	ENTRY
;	      ah      =  0F6h
;	EXIT
;	      none
;	DESTROYS
;	      none
;
;
;	DefineDefault - load up default shadow maps from user buffer
;
;	ENTRY
;	      ah      =  0F7h
;	      cx      =  'TH' if user wants to program VGA specific color select
;			 register.  This was added version 2.07.12.
;			 Only checked if on a VGA and defining Attribute
;			 Controller Register.
;	      dx      =  register id
;			 If high bit of dx set, an internal RevertDefault will
;			 occur after the default shadow maps have been updated
;
;	      es:bx   -> buffer of default values for specified register id.
;			 If register id is a chip, all values must be present.
;	EXIT
;	      none
;	DESTROYS
;	      bx
;
;
;	GetDefault - dump default shadow maps to user buffer
;
;	ENTRY
;	      ah      =  0F8h
;	      dx      =  register id
;	      es:bx   -> buffer to receive default values
;			 If register id is a chip,table must have room for all
;			 regs in chip.
;	EXIT
;	      none
;	DESTROYS
;	      none
;
;
;	ContextInfo - Save/Restore full EGA.SYS context information
;
;	ENTRY
;	      ah      =  0F9h
;	      al      =  000h  GetContextSize
;		      =  001h  SaveContext
;		      =  002h  RestoreContext
;		      =  003h  GetFontInfo
;		      =  004h  GetInBiosFlag
;
;	      GetContextSize - return size in bytes needed to save 
;			       EGA.SYS context
;
;	      ENTRY
;		    none
;	      EXIT
;		    ax	    =  size in bytes needed to save EGA.SYS context
;	      DESTROYS
;		    none
;
;
;	      SaveContext - dump current EGA.SYS context data to user buffer
;
;	      ENTRY
;		    es:bx   ->	user save area buffer for EGA context
;	      EXIT
;		    none
;	      DESTROYS
;		    none
;
;
;	      RestoreContext - restore EGA.SYS context data from user buffer
;
;	      ENTRY
;		    es:bx   -> previously saved EGA context
;	      EXIT
;		    none
;	      DESTROYS
;		    none
;
;
;	      GetFontInfo - dump current font data in FontInfo format to 
;			    user buffer
;
;	      ENTRY
;		    es:bx   -> user buffer for FontInfo
;	      EXIT
;		    none
;	      DESTROYS
;		    none
;
;
;	      GetInBiosFlag - return segment:offset of the InBiosFlag
;
;	      ENTRY
;		    none
;	      EXIT
;		    es:bx   -> InBiosFlag
;	      DESTROYS
;		    none
;
;
;	InquireDriver - return ptr to driver version number
;
;	ENTRY
;	      ah      =  0FAh
;	EXIT
;	      es:bx   -> DriverInfo data area
;	DESTROYS
;	      bx, es
;
;
;	Calls 0FBh - 0FDh are reserved. 0FEh & 0FFh are used by
;	environments such as Windows, TopView, and Mondrian.
;
; Added new INT 2FH handler for interprocess communication in 2.07.11
;
; This handler is used to allow new copies to communicate with a previously
;	installed copy.  We support:
;
;	Function 0 - Return AL = 0FFH indicating installed
;	Function 6 - Return version number
;		CH = Major version number
;		CL = Minor version number
;		DL = Beta version number (or 0 for no Beta version)
;	Function 7 - Return end of installed code in paragraphs
;		CX = Paragraph value of code end (rounded up)
;		SI = Code segment (side-effect)
;	Function 8 - Return INT 2FH vector
;		CX = Offset of current vector
;		DX = Segment of current vector
;		DI = Offset of original vector
;		ES = Segment of original vector
;	Function 9 - Return INT 10H vector
;		CX = Offset of current vector
;		DX = Segment of current vector
;		DI = Offset of original vector
;		ES = Segment of original vector
;
;	All functions return BX = 'AH' for COM driver and BX = 'TV' for SYS
;		driver.  See cute comments in equate section.
;
; NOTES
;	EGA.SYS is reentrant.  This means that it is legal for an interrupt
;	routine to call EGA.SYS while the synchronous program is in the middle
;	of one of its calls to EGA.SYS.  [currently, this is only true if the
;	interrupt routine only saves and restores registers (i.e.  makes no
;	permanent changes) but this could be changed to accomodate interrupt
;	routines that make permanent changes (e.g.  an interrupt routine that
;	changed the palette on a vertical retrace)].
;
;	A special note about the attribute chip registers:  the flip-flop
;	which determines whether 003C0h is the address or data register will
;	always be left in the "address" state on return from EGA.SYS.  Any
;	code which sets the flip flop to "data" and then depends on it being
;	set that way must disable interrupts for the length of time between
;	setting it to "data" and the last time it is assumed to be "data".
;
;	Writing to the sequencer memory mode register is tricky because on
;	some vendors cards the sequencer will produce a 20 ns glitch on the
;	CAS lines when this register is accessed, which seems to have a chance
;	of glitching VRAM even though write enable is never asserted.
;	Therefore, when writing to this register, it is suggested that you
;	first synchronously reset the sequencer by writing a 001h to the
;	sequencer reset register (index 000h), then write your data to the
;	memory mode register, and finally write a 003h back to the reset
;	register.  Not that interrupts MUST be disabled during this whole
;	operation, as EGA RAM is not being refreshed when the sequencer is in
;	a reset state.
;
;	The clocking mode register in the sequencer has also appeared to cause
;	similar problems on IBM boards with slow memory on the daughterboard.
;	The same procedure as above is recommended, though may not be strictly
;	necessary.
;
;	And the same caveat applies to the graphics controller miscellaneous
;	register because it appears to cause a glitch on the CAS lines in a
;	similar to the sequencer memory mode register.	This problem is
;	particularly insideous because it will only show up on EGA cards with
;	the add on memory cards that have INMOS RAM chips.  Beware!!!
;
;	Due to these problems, the RevertDefault function does not restore
;	either the clocking mode register or the miscellaneous register (at
;	least in this release).  Since the ability to context switch the
;	EGA is a must, the RestoreContext subfunction of ContextInfo does
;	handle all three registers in a manner described above.
;
;	This code has no provisions for reading the input status registers on
;	the EGA.  Any code that wants to read either of the input status
;	registers should do so directly.  It does however return the most
;	up-to-date information about the cursor position and CRTC start
;	address (these are readable) when reading the CRTC shadow map.
;
; HISTORY
;	12/24/84  1.40	brian conte	epoch
;
;	11/11/85  1.50	steve shaiman	mod to RevertDefault for glitch in in
;					graphics controller misc. register
;
;	02/14/86  1.51	steve shaiman	mod to ChangeRegs to clear direction
;					flag instead of assuming it's cleared
;
;	02/21/86  1.52	steve shaiman	made pOldInt10, ChangeRegs,
;					Int10Routine public as needed by erice
;
;	06/09/86  1.53	steve shaiman	mod to RevertDefault for glitch in
;					sequencer clocking mode register
;
;	10/30/86  1.60	steve shaiman	added GetDefault as function 0F8h;
;					added SimWriteReg & SimWriteSet for
;					use by routines that intercept
;					standard int 010h calls and want to
;					modify the shadows regs (but not the
;					actual hardware regs);
;					added int 010h BIOS support for
;					functions 005h (set display page),
;					00Bh (set CGA palette registers), &
;					010h (set EGA palette registers)
;
;	04/20/87  2.00	jim christy	added remainder of int 010h shadow
;					functions;
;					cleaned up original shadow functions;
;					merged tom hensel's VGA code from
;					"other" EGA.SYS into this one;
;					added revert immediate bit for
;					DefineDefault per shaiman's request
;
;	05/04/87  2.01	jim christy	added ContextInfo functions (0F9h)
;					needed by Windows and TSR's;
;					changed stack handling by Int10Routine
;					and friends to be cleaner, avoiding
;					static SaveAX-style variables (truly
;					re-entrant now);
;					optimized all write reg functions and
;					RevertDefault to avoid redundent
;					special casing of the attribute
;					controller;
;					changed from an "include" file to a
;					device driver format;
;					added more comments, optimiziation,
;					fixed bugs introduced in v2.00
;
;	05/14/87  2.02	Jeff Parsons	Added GetInBiosFlag ContextInfo
;					subfunction (F904h).  Added device
;					driver interface and OS2 conditional
;					assembly.  Added wait for vert retrace
;					before writing attribute controller.
;					Optimized rep-movs to avoid jumps, and
;					added/modified some IN/OUT macros.
;
;	08/11/87  2.03	Jeff Parsons	Converted dirty byte-flag into bit
;					flags (bit 0 maintained same as old
;					dirty flag, bit 1 always set when 0
;					set but never cleared until mode set).
;					Bit 1 now a "truly-dirty" bit, to be
;					used in future revisions.  Optimized
;					path for shadowed Int 10h calls to
;					minimize performance impact, effected
;					in part through the addition of
;					biosmode, biosinfo, and biostable in
;					the local ds.  Cleaned up CheckEga and
;					the install logic to address all of
;					Jim Christy's concerns.  Modified
;					meaning of fInBIOS flag (only set for
;					actual ROM BIOS calls).  Protected all
;					sections where attr cont flip-flop is
;					data state.  Added workaround for
;					driver install bug on non-ega systems.
;
;	03/16/88  2.04  Tom Hensel	Fixed "Green screen" problem on VGA.
;					This only appears on a Compaq VGA so
;					far, but could occur on any VGA which
;					can switch between monochrome and

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?