CS306
Processing Systems and Structures
J. W. Lockwood
Lecture 17
Today's Topics
Pixel-based Graphics Overview
Programming with VGA Mode 13h
Higher SVGA Resolutions with/VESA
String operations for fast graphics
Pixel-based Graphics Overview
Review video card hardware
Pixels represented by bytes in memory
Typically Memory-Mapped (like text-mode)
Multiple
Color Depths
(D)
Mode
Bits/
Pixel
Number
of colors
Color
Mapping
256 Color
8
256
Palette
High Color
16
65,536
Palette
True Color
24
16,777,216
Red/Green/Blue
Multiple
Resolutions
(R)
320x200 = 64k pixels
640x480 = 307k pixels
800x600 = 480k pixels
1024x768 = 768k pixels
1280x1024 = 1.28M pixels
Amount of video memory required
Color Depth
*
Resolution
M (bytes) = D (bytes/pixel) * R (pixels)
Palette Registers
Diagram on board
Maps pixel values to colors
Table-Lookup provides many color
shades
(R/G/B values)
Color Depth limits # of
different
colors on screen
Artist Analogy
Programming with VGA Mode 13h
Low-Resolution Graphics
320x200 Mode w/256 Colors
One screen fits into one 64k segment
Mode used for CS306 MP5
vBIOS call to set video mode
AH=0h (Set Mode)
AL=13h (320x200 @ 256 colors)
INT 10h (vBIOS)
Palette Registers Define Color
Table-lookup maps 8-bit byte to 18-bit word
Palette entries store 6 bits/pixel (Red,Green,Blue)
Default (power-on) Palette color values
Entries 0-15: Basic Colors: [0,0,0,0,I,R,G,B]
Entries 16-31: Grayscale: [0,0,0,1,g3,g2,g1,g0]
Entries 32-255: User-Defined colors
Setting Palette Entries on VGA card
Method 1: Writing to VGA registers directly:
Write 0 to Port 3C8h
Write red, green, blue bytes to Port 3C9h for all 256 colors
Method 2: Using vBIOS call
BX = Palette Number (0..255)
CH = Green (0..63)
CL = Blue (0..63)
DH = Red (0..63)
AX = 1010h : Set VGA Palette Registers
INT 10h (vBIOS)
Base Address = VidGrSEG = 0A000h
Writing a (single) pixel
MOV AX,VidGrSEG ; VidGrSEG = 0A000h MOV ES,AX ; Use Extra Segment MOV BX,Location ; Location = R*320+C MOV ES:[BX],Color ; Palette Entry Number
SVGA Graphics
Higher resolution graphics require more than one segment of data
640x480 * 256 colors
800x600 * 256 colors
VESA SVGA cards use bank switching to plot pixels
Example Code
More Info
String operations for fast graphics
Repeat Prefix Opcode
REP/REPE/REPZ
:
CX--; Repeat until CX=0 while ZF=ZR=1
REPNE/REPNZ
: CX--; Repeat until CX=0 while ZF=NZ=0
Direction Flag
CLD
: CLear Direction flag
DF=0: Auto-increment
STD
: SeT Direction flag
DF=1: Auto-decrement
String Instructions
MOVS
: Move String
MOVSB (byte) ; MOVSW (word) ; MOVSD (double)
ES:[DI] = DS:[SI]
SI and DI incremented or decremented
CMPS
: Compare String
CMPSB (byte) ; CMPSW (word) ; CMPSD (double)
Set ZF if ES:[DI] = DS:[SI]
SI and DI incremented or decremented
SCAS
: Scan String
SCASB (byte) ; SCASW (word)
Set ZF if AL/AX=ES:[DI]
DI incremented or decremented
LODS
: Read AL/AX/EAX from string
LODSB : Read AL from DS:[SI]
LODSW : Read AX from DS:[SI]
LODSD : Read EAX from DS:[SI]
SI incremented or decremented
STOS
: Write AL/AX to string
STOSB : Write AL to ES:[DI]
STOSW : Write AX to ES:[DI]
STOSD : Write EAX to ES:[DI]
DI incremented or decremented
Fast Graphics
REP MOVSB
: Transfer image to video
CLD : Auto Increment
CX=count
DS:SI=source
ES:DI=destination
REP STOSB
: Draw Solid Horizontal Line
CLD : Auto Increment
CX=count
AL=source
ES:DI=destination