ega.inc

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

INC
1,775
字号
DevName 	db	"EGA$    "

.ERRNZ		($ - main) - 18		; Keep device driver block together

pRequestHeader	LABEL	DWORD

ReqHeaderOff	DW	?
ReqHeaderSeg	DW	?

.ERRNZ		($ - pRequestHeader) - 4	; Keep vector together

;
; DevStrategy - Device driver strategy entry point
;
; ENTRY
;	es:bx	-> request packet
;
; EXIT
;	packet updated as appropriate
;
; DESTROYS
;	none
;

	assume	cs:CODE, ds:nothing, es:nothing, ss:nothing

DevStrategy	proc	far

	mov	[ReqHeaderOff],BX	; Save offset to request header
	mov	[ReqHeaderSeg],ES	; Save segment to request header
	ret				; Return to DOS

DevStrategy	endp

;
; DevInterrupt - Device driver interrupt entry point
;
; ENTRY
;
; EXIT
;	packet updated as appropriate
;
; DESTROYS
;	none
;

	assume	cs:CODE, ds:nothing, es:nothing, ss:nothing

DevInterrupt	proc	far

	pushf				; Save environment

ifdef	OS2
	pusha				; Save environment
else	; NOT OS2
	push	ax			; Save environment
	push	bx			; Save environment
endif	; NOT OS2

	push	ds			; Save environment
	lds	bx,[pRequestHeader]	; DS:BX -> Request header
	assume	ds:nothing		; But actually request header segment
	mov	al,ds:[bx].CommandCode	; AL = command
	cmp	al,MAX_FUNCTION		; Invalid command?
	ja	DevIntDone2		; Yes - skip
	cmp	al,8			; Can we handle the command?
	ja	DevIntDone1		; No - skip

ifndef	OS2
	push	cx			; Save environment
	push	dx			; Save environment
	push	bp			; Save environment
	push	di			; Save environment
	push	si			; Save environment
endif	; NOT OS2

	push	es			; Save environment
	cbw				; AX = command
	mov	si,ax			; SI = command
	shl	si,1			; SI = command table offset
	mov	ax,cs			; DS = Code segment
	mov	ds,ax			; Two instructions needed
	assume	ds:CODE
	call	[CmdTable][si]		; Call handler for command
	assume	ds:nothing, es:nothing
	or	ax,B$DONE 		; Set done bit
	lds	bx,[pRequestHeader]	; DS:BX -> Request header
	assume	ds:nothing		; But actually request header segment
	mov	ds:[bx].Status,AX	; Store status word in packet
	pop	es			; Restore environment
	assume	es:nothing

ifndef	OS2
	pop	si			; Restore environment
	pop	di			; Restore environment
	pop	bp			; Restore environment
	pop	dx			; Restore environment
	pop	cx			; Restore environment
endif	; NOT OS2

	jmp	short DevIntDone3	; Skip the error status

DevIntDone1:
	assume	ds:nothing		; But actually request header segment
	mov	ds:[bx].Status,B$DONE	; Return done with no error status
	jmp	short DevIntDone3	; Skip the error status

DevIntDone2:
	assume	ds:nothing		; But actually request header segment
	mov	ds:[bx].Status,B$DONE OR B$ERROR OR B$UnknownCommand
					; Return unknown command error

DevIntDone3:
	assume	ds:nothing
	pop	ds			; Restore environment
	assume	ds:nothing

ifdef	OS2
	popa				; Restore environment
else	; NOT OS2
	pop	bx			; Restore environment
	pop	ax			; Restore environment
endif	; NOT OS2

	popf				; Restore environment
	ret				; Return to DOS

DevInterrupt	endp

ForcedResidentEnd	label	near

ELSE	; NOT SYS

	ORG	2CH

pEnvSeg		DW	?		; Segment address of environment

	ORG	5CH

FCB1		DB	16 DUP (?)	; File Control Block 1
					; This marks the first spot in the PSP
					; where we are allowed to destroy
					; We relocate Int10Routine into the
					; PSP starting at this point

	ORG	80H

ParmLength	DB	?		; Length of command line

	ORG	81H

pComLine	DB	127 DUP (?)	; Actual command line

	org	100h			; Just call Init if TSR model

main:
	jmp	Init			; Init will vary depending on model

	org	OrgStartOfData		; Because Int10Routine is getting
					; Relocated in the PSP occupying
					; from 5ch to here

if2	; Pass 2 of the assembler
.errnz	(offset StartOfData - offset FCB1) - OpIntRoutineLength ; Exact fit
.errnz	OpIntRoutineLength LT 167	; Make full use of PSP
endif	; Pass 2 of the assembler

ENDIF	; NOT SYS

;
; V A R I A B L E S
;

	subttl	Data definitions for EGA.SYS (shadow maps)
	page

IFNDEF	OS2

StartOfData	equ	$

ENDIF	; NOT OS2

StartEGAContext label	near

PortTable	label	word		; Code dependent on order

PortRec 	<CRTCAddr, CRTCRegs, DefCRTCRegs, NumCRTCRegs, 0>
PortRec 	<(EGA_BASE + SEQ_ADDR), SeqRegs, DefSeqRegs, NumSeqRegs, 0>
PortRec 	<(EGA_BASE + GRAF_CONT), GraphicsRegs, DefGraphicsRegs, NumGraphicsRegs, 0>
PortRec 	<AttCtrlAddrReg, AttrRegs, DefAttrRegs, NumAttrRegs, 0>
PortRec 	<MiscAddr, MiscOutReg, DefMiscOutReg, 1, 0>
PortRec 	<FeatAddr, FeatureReg, DefFeatureReg, 1, 0>
PortRec 	<Gr1PosAddr, Gr1PosReg, DefGr1PosReg, 1, 0>
PortRec 	<Gr2PosAddr, Gr2PosReg, DefGr2PosReg, 1, 0>

.ERRNZ		($ - PortTable) - (8 * SIZE PortRec) ; Keep table together

SingleRegMod	db	0		; >0 if a single reg modified

;
; This is the current shadow map table...order MUST be same as BIOS
;

StartShadowMaps label	byte

SeqRegs 	db	NumSeqRegs	dup (?)
MiscOutReg 	db	1		dup (?)
CRTCRegs	db	NumCRTCRegs	dup (?)
AttrRegs	db	NumAttrRegs	dup (?)

VGAPatch	EQU	$ - StartShadowMaps

GraphicsRegs	db	NumGraphicsRegs	dup (?)

SizeShadowMaps	EQU	$ - StartShadowMaps

;
; This is the default shadow map table...order MUST be same as BIOS
;

DefSeqRegs	db	NumSeqRegs	dup (?)
DefMiscOutReg	db	1		dup (?)
DefCRTCRegs	db	NumCRTCRegs	dup (?)
DefAttrRegs	db	NumAttrRegs	dup (?)
DefGraphicsRegs	db	NumGraphicsRegs	dup (?)

Gr1PosReg	db	0		; These aren't included in bios
Gr2PosReg	db	1
FeatureReg	db	0		; Never changed
DefGr1PosReg	db	0
DefGr2PosReg	db	1
DefFeatureReg	db	0		; Never changed

.ERRNZ		($ - StartShadowMaps) - ((NumSeqRegs * 2) + (NumCRTCRegs * 2) + (NumAttrRegs * 2) + (NumGraphicsRegs * 2) + 8)

FontBank	FontInfo	<>	; Font ids for 4 banks

SizeEGAContext	EQU	($ - StartEGAContext)

fVga		db	FALSE		; VGA presence flag
SaveAX		dw	?		; Temp variables
biosmode	db	?		; Current video mode #
biosinfo	db	?		; Static copy of ega info byte
biosinfo3	db	?		; Static copy of ega info3 byte

pOldInt10	label	dword

pOldInt10Off	dw	?		; Offset of old INT 10H vector
pOldInt10Seg	dw	?		; Segment of old INT 10H vector

.ERRNZ		($ - pOldInt10) - 4	; Keep vector together

fPalette	db	false		; This is used to flag when the user
					; has requested to read the palette
					; regs.  This is needed for VGA
					; to overcome a problem of rapid
					; video enable/disable needed to
					; read the palette registers

DriverInfo	label	byte		; A historic data area

Version 	db	MajVersion, MinVersion
CopyrightMsg	dw	offset Copyright
CheckSum	dw	0		; Why this ?
CheckSumStart	dw	offset SetMode	; Why this ?
fInBIOS 	db	0
Copyright	db	"*** This is Copyright (c) 1984-1990 Microsoft ***"

.errnz		($ - DriverInfo) - (9 + 49)

IFDEF	OS2
ContextCopy	db	SizeEGAContext dup (?) ; Enough storage for 1 context
ELSE	; NOT OS2

pOldINT2F	LABEL	DWORD

pOldINT2FOff	DW	?
pOldINT2FSeg	DW	?

.ERRNZ		($ - pOldINT2F) - 4	; Keep vector together

Int2FNumber	db	MyInt2FNumber	; User can change this value using
					; FUNC=XX command line parameter
					; (where XX is 80 through FF
					; hexadecimal inclusive)
					;
					; For example:  EGA FUNC=AC

Win386_Startup_Info	Win386_Startup_Info_Struc	<, ?, 0, ?, offset Instance_Item, ?>

Instance_Item		label	byte

RegData		Instance_Item_Struc	<offset StartOfData, ?, SizeOfData>

		dd	0		; Termination code

.errnz		($ - Instance_Item) - (4 + SIZE Instance_Item_Struc)

SizeOfData	equ	($ - StartOfData)

ENDIF	; NOT OS2

;
; Start of non-instance data (data which is not modified)
;

	subttl	Data definitions for EGA.SYS (dispatch tables)
	page

;
; The following table is used to look up the location to save the EGA/VGA
;	latch state depending on the video mode.  The mouse driver does
;	the same thing and uses the byte after the byte we use.
;

EGALatchTable	dw	EGALatchOff_D
		dw	EGALatchOff_E
		dw	EGALatchOff_F_10
		dw	EGALatchOff_F_10
		dw	EGALatchOff_11
		dw	EGALatchOff_12
		dw	EGALatchOff_13

.errnz		($ - EGALatchTable) - 14 ; Keep table together

ContextTable	label	word		; Jump table for ContextInfo

		dw	GetContextSize	; Func 000h
		dw	SaveContext	; Func 001h
		dw	RestoreContext	; Func 002h
		dw	GetFontInfo	; Func 003h
		dw	GetInBiosFlag	; Func 004h

MaxContextCall	EQU	($ - ContextTable) / 2 - 1

.ERRNZ		($ - ContextTable) - (5 * 2) ; Keep table together

MyCallTable	label	word

		dw	offset ReadReg	; Call 0F0h
		dw	offset WriteReg	; Call 0F1h
		dw	offset ReadRange ; Call 0F2h
		dw	offset WriteRange ; Call 0F3h
		dw	offset ReadSet	; Call 0F4h
		dw	offset WriteSet	; Call 0F5h
		dw	offset RevertDefault ; Call 0F6h
		dw	offset DefineDefault ; Call 0F7h
		dw	offset GetDefault ; Call 0F8h
		dw	offset ContextInfo ; Call 0F9h
		dw	offset InquireDriver ; Call 0FAh

MaxMyCall	EQU	($ - MyCallTable) / 2 - 1

.ERRNZ		($ - MyCallTable) - (11 * 2) ; Keep table together

;
; Note that the following table of shadow routines is now complete.  Some
; entries still point to "Ignore" only because the BIOS either never
; changes the EGA regs for these routines, or it calls other int 10h
; functions which are already shadowed to do its work.	An exception to
; this are the entries marked (nop)*.  These entries change the readable
; regs in the CRTC chip, thus shadowing of these functions is simply a
; matter of reading those registers.  That functionality has been delegated
; to the routine UpdateCRTCMaps, which gets called by all of the READ
; procedures before returning any data.
;
; WARNING: If a new routine is added to this list, or if the shadowing
; logic in any of these is modified, you may need to update biostable.	It
; contains the lowest video mode # for which shadowing is performed for each
; BIOS function.
;

if	CallTableNeeded

BIOSCallTable	label	word

		dw	offset SetMode	; Set display mode
		dw	offset SetCursorType ; Set cursor shape
		dw	offset Ignore	; Set cursor position	(nop)*
		dw	offset Ignore	; Get cursor position	(nop)
		dw	offset Ignore	; Get light-pen pos	(nop)
		dw	offset Ignore	; Set display page	(nop)*
		dw	offset ScrollUpDown ; Scroll up
		dw	offset ScrollUpDown ; Scroll down
		dw	offset ReadChar	; Read  attr/char
		dw	offset WriteChar ; Write attr/char
		dw	offset WriteChar ; Write char only
		dw	offset SetCgaPalette ; Set CGA palette regs
		dw	offset WriteDot ; Write dot
		dw	offset ReadDot	; Read  dot
		dw	offset Ignore	; Write tty		(nop)
		dw	offset Ignore	; Get video state	(nop)
		dw	offset SetEgaPalette ; Set EGA palette regs
		dw	offset DownloadFont ; Download EGA fonts
		dw	offset Ignore	; Alternate select	(nop)
		dw	offset Ignore	; Write string		(nop)

MaxBIOSCall	EQU	($ - BIOSCallTable) / 2 - 1

.ERRNZ		($ - BIOSCallTable) - (20 * 2) ; Keep table together

biostable	db	0,0,-1,-1,-1,-1,0Dh,0Dh,8,8,8,0,8,8,-1,-1,0,0,-1,-1

.errnz	($ - biostable) - (MaxBIOSCall + 1)

else	; NOT CallTableNeeded

MaxBIOSCall	EQU	1

endif	; NOT CallTableNeeded

	subttl	Device Driver Code
	page

IFDEF	SYS

;
; Request packet command dispatch table
;

CmdTable	dw	Init		; 0  Initialization
		dw	StatusComplete	; 1  Media Check
		dw	StatusComplete	; 2  Build BPB
		dw	StatusComplete	; 3  Reserved

IFDEF	OS2
		dw	DoSave		; 4  Input (Read)
ELSE	; NOT OS2
		dw	StatusComplete	; 4  Input (Read)
ENDIF	; NOT OS2

		dw	StatusComplete	; 5  Non-Destructive read
		dw	StatusComplete	; 6  Input Status
		dw	StatusComplete	; 7  Input Flush

IFDEF	OS2
		dw	DoRestore	; 8  Output (Write)
ELSE	; NOT OS2
		dw	StatusComplete	; 8  Output (Write)
ENDIF	; NOT OS2

.ERRNZ		($ - CmdTable) - (9 * 2) ; Keep table together

⌨️ 快捷键说明

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