
|
 |
|
Zen of Graphics Programming, 2nd Edition
by Michael Abrash
Coriolis, The Coriolis Group
ISBN: 1883577896 Pub Date: 04/01/96
|
Overscan
While were at it, Im going to touch on overscan. Overscan is the color of the border of the display, the rectangular area around the edge of the monitor thats outside the region displaying active video data but inside the blanking area. The overscan (or border) color can be programmed to any of the 64 possible colors by either setting Attribute Controller register 11H directly or calling video function 10H, subfunction 1.
On ECD-compatible monitors, however, theres too little scan time to display a proper border when the EGA is in 350-scan-line mode, so overscan should always be 0 (black) unless youre in 200-scan-line mode. Note, though, that a VGA can easily display a border on a VGA-compatible monitor, and VGAs are in fact programmed at mode set for an 8-pixel-wide border in all modes; all you need do is set the overscan color on any VGA to see the border.
A Bonus Blanker
An interesting bonus: The Attribute Controller provides a very convenient way to blank the screen, in the form of the aforementioned bit 5 of the Attribute Controller Index register (at address 3C0H after the Input Status 1 register3DAH in color, 3BAH in monochromehas been read and on every other write to 3C0H thereafter). Whenever bit 5 of the AC Index register is 0, video data is cut off, effectively blanking the screen. Setting bit 5 of the AC Index back to 1 restores video data immediately. Listing 7.4 illustrates this simple but effective form of screen blanking.
LISTING 7.4 L7-4.ASM
; Program to demonstrate screen blanking via bit 5 of the
; Attribute Controller Index register.
;
AC_INDEX equ 3c0h ;Attribute Controller Index register
INPUT_STATUS_1 equ 3dah ;color-mode address of the Input
; Status 1 register
;
; Macro to wait for and clear the next keypress.
;
WAIT_KEY macro
mov ah,8 ;DOS input without echo function
int 21h
endm
;
stack segment para stack 'STACK'
db 512 dup (?)
stack ends
;
Data segment word 'DATA'
SampleText db 'This is bit-mapped text, drawn in hi-res '
db 'EGA graphics mode 10h.', 0dh, 0ah, 0ah
db 'Press any key to blank the screen, then '
db 'any key to unblank it,', 0dh, 0ah
db 'then any key to end.$'
Data ends
;
Code segment
assume cs:Code, ds:Data
Start proc near
mov ax,Data
mov ds,ax
;
; Go to hi-res graphics mode.
;
mov ax,10h ;AH = 0 means mode set, AL =
10h selects
; hi-res graphics mode
int 10h ;BIOS video interrupt
;
; Put up some text, so the screen isn't empty.
;
mov ah,9 ;DOS print string function
mov dx,offset SampleText
int 21h
;
WAIT_KEY
;
; Blank the screen.
;
mov dx,INPUT_STATUS_1
in al,dx ;reset port 3c0h to index (rather than
data)
; mode
mov dx,AC_INDEX
sub al,al ;make bit 5 zero
out dx,al ;
which blanks the screen
;
WAIT_KEY
;
; Unblank the screen.
;
mov dx,INPUT_STATUS_1
in al,dx ;reset port 3c0h to Index (rather than
data)
; mode
mov dx,AC_INDEX
mov al,20h ;make bit 5 one
out dx,al ;
which unblanks the screen
;
WAIT_KEY
;
; Restore text mode.
;
mov ax,2
int 10h
;
; Done.
;
Done:
mov ah,4ch ;DOS terminate function
int 21h
Start endp
Code ends
end Start
Does that do it for color selection? Yes and no. For the EGA, weve covered the whole of color selectionbut not so for the VGA. The VGA can emulate everything weve discussed, but actually performs one 4-bit to 8-bit translation (except in 256-color modes, where all 256 colors are simultaneously available), followed by yet another translation, this one 8-bit to 18-bit. Whats more, the VGA has the ability to flip instantly through as many as sixteen 16-color sets. The VGAs color selection capabilities, which are supported by another set of BIOS functions, can be used to produce stunning color effects, as well see when we cover them starting in Chapter 11.
Modifying VGA Registers
EGA registers are not readable. VGA registers are readable. This revelation will not come as news to most of you, but many programmers still insist on setting entire VGA registers even when theyre modifying only selected bits, as if they were programming the EGA. This comes to mind because I recently received a query inquiring why write mode 1 (in which the contents of the latches are copied directly to display memory) didnt work in Mode X. (Ill go into Mode X in detail later in this book.) Actually, write mode 1 does work in Mode X; it didnt work when this particular correspondent enabled it because he did so by writing the value 01H to the Graphics Mode register. As it happens, the write mode field is only one of several fields in that register, as shown in Figure 7.4. In 256-color modes, one of the other fieldsbit 6, which enables 256-color pixel formattingis not 0, and setting it to 0 messes up the screen quite thoroughly.
Figure 7.4 Graphics Mode Register Fields
The correct way to set a field within a VGA register is, of course, to read the register, mask off the desired field, insert the desired setting, and write the result back to the register. In the case of setting the VGA to write mode 1, do this:
mov dx,3ceh ;Graphics controller index
mov al,5 ;Graphics mode reg index
out dx,al ;point GC index to G_MODE
inc dx ;Graphics controller data
in al,dx ;get current mode setting
and al,not 3 ;mask off write mode field
or al,1 ;set write mode field to 1
out dx,al ;set write mode 1
|