The BIOS (Basic Input-Output System)
provides low-level hardware drivers for the operating system.
¾ accessible to 16-bit applications
¾ written in assembly language, of coursey g g ,
¾ source code published by IBM in early 1980's
Advantages over MS-DOS:
¾ permits graphics and color programming
¾ faster I/O speeds
¾ read mouse, serial port, parallel port
¾ low-level disk access
BIOS Data Area
Fixed-location data area at address 00400h
¾ this area is also used by MS-DOS
¾ this area is accessible under Windows 98 & Windows Me, but not under Windows NT, 2000, or XP.
Contents:
Contents:
¾ Serial and parallel port addresses
¾ Hardware list, memory size
¾ Keyboard status flags, keyboard buffer pointers, keyboard buffer data
¾ Video hardware configuration
¾ Timer data
What's Next
Introduction
Keyboard Input with INT 16h
VIDEO Programming with INT 10hg g
Drawing Graphics Using INT 10h
Memory-Mapped Graphics
Mouse Programming
Keyboard Input with INT 16h
How the Keyboard Works
INT 16h Functions
How the Keyboard Works
Keystroke sends a scan code to the keyboard serial input port
Interrupt triggered: INT 9h service routine executes
Scan code and ASCII code inserted into keyboard
Scan code and ASCII code inserted into keyboard typeahead buffer
Keyboard
INT 9h handler
INT 16h handler INT 21h handler
typeahead buffer
input port sc
sc sc, ac
sc, ac ac
sc = scan code ac = ASCII code
Keyboard Flags
16-bits, located at 0040:0017h – 0018h.
INT 16h Functions
Provide low-level access to the keyboard, more so than MS-DOS.
Input-output cannot be redirected at the command prompt.
Function number is always in the AH register
Function number is always in the AH register
Important functions:
¾ set typematic rate
¾ push key into buffer
¾ wait for key
¾ check keyboard buffer
¾ get keyboard flags
Function 10h: Wait for Key
.data
scanCode BYTE ? ASCIICode BYTE ?
If a key is waiting in the buffer, the function returns it immediately. If no key is waiting, the program pauses (blocks), waiting for user input.
ASCIICode BYTE ? .code
mov ah,10h int 16h
mov scanCode,ah mov ASCIICode,al
Function 12h: Get Keyboard Flags
.data
keyFlags WORD ?
Retrieves a copy of the keyboard status flags from the BIOS data area.
.code
mov ah,12h int 16h
mov keyFlags,ax
Clearing the Keyboard Buffer
L1: mov ah,11h ; check keyboard buffer int 16h ; any key pressed?
jz noKey ; no: exit now
mov ah 10h ; yes: remove from buffer
Function 11h clears the Zero flag if a key is waiting in the keyboard typeahead buffer.
mov ah,10h ; yes: remove from buffer int 16h
cmp ah,scanCode ; was it the exit key?
je quit ; yes: exit now (ZF=1) jmp L1 ; no: check buffer again
noKey: ; no key pressed
or al,1 ; clear zero flag quit:
What's Next
Introduction
Keyboard Input with INT 16h
VIDEO Programming with INT 10h
Drawing Graphics Using INT 10h
Memory-Mapped Graphics
Mouse Programming
VIDEO Programming with INT 10h
Basic Background
Controlling the Color
INT 10h Video Functions
Library Procedure Examples
Video Modes
Graphics video modes
¾ draw pixel by pixel
¾ multiple colors
Text video modes
h i h d f b d
¾ character output, using hardware or software-based font table
¾ mode 3 (color text) is the default
¾ default range of 80 columns by 25 rows.
¾ color attribute byte contains foreground and background colors
Three Levels of Video Access
MS-DOS function calls
¾ slow, but they work on any MS-DOS machine
¾ I/O can be redirected
BIOS function calls
di f k l ll S OS b d
¾ medium-fast, work on nearly all MS-DOS-based machines
¾ I/O cannot be redirected
Direct memory-mapped video
¾ fast – works only on 100% IBM-compatible computers
¾ cannot be redirected
¾ does not work under Windows NT, 2000, or XP
Controlling the Color
Mix primary colors: red, yellow, blue
¾ called subtractive mixing
¾ add the intensity bit for 4th channel
Examples:
¾ red + green + blue = light gray (0111)g g g y ( )
¾ intensity + green + blue = white (1111)
¾ green + blue = cyan (0011)
¾ red + blue = magenta (0101)
Attribute byte:
¾ 4 MSB bits = background
¾ 4 LSB bits = foreground
Constructing Attribute Bytes
Color constants defined in Irvine32.inc and Irvine16.inc:
Examples:
Li ht t t bl b k d
¾ Light gray text on a blue background:
(blue SHL 4) OR lightGray
¾ White text on a red background:
(red SHL 4) OR white
INT 10h Video Functions
AH register contains the function number
00h: Set video mode
¾ text modes listed in Table 15-6
¾ graphics modes listed in Table 15-6
01h: Set cursor lines01h: Set cursor lines
02h: Set cursor position
03h: Get cursor position and size
06h: Scroll window up
07h: Scroll window down
08h: Read character and attribute
INT 10h Video Functions (cont)
09h: Write character and attribute
0Ah: Write character
10h (AL = 03h): Toggle blinking/intensity bit
0Fh: Get video mode
13h: Write string in teletype mode
Displaying a Color String
Write one character and attribute:
mov si,OFFSET string . . .
mov ah,9 ; write character/attribute mov al,[si] ; character to display
mov bh 0 ; video page 0
mov bh,0 ; video page 0 mov bl,color ; attribute
or bl,10000000b ; set blink/intensity bit mov cx,1 ; display it one time
int 10h
Gotoxy Procedure
;
--Gotoxy PROC
;
; Sets the cursor position on video page 0.
; Receives: DH,DL = row, column
R t thi
; Returns: nothing
;
---pusha
mov ah,2 mov bh,0 int 10h popa
ret
Gotoxy ENDP
Clrscr Procedure
Clrscr PROC pusha
mov ax,0600h ; scroll window up
mov cx,0 ; upper left corner (0,0) mov dx,184Fh ; lower right corner
(24,79)
bh 7 l tt ib t
mov bh,7 ; normal attribute int 10h ; call BIOS
mov ah,2 ; locate cursor at 0,0 mov bh,0 ; video page 0
mov dx,0 ; row 0, column 0 int 10h
popa ret
Clrscr ENDP
What's Next
Introduction
Keyboard Input with INT 16h
VIDEO Programming with INT 10hg g
Drawing Graphics Using INT 10h
Memory-Mapped Graphics
Mouse Programming
Drawing Graphics Using INT 10h
INT 10h Pixel-Related Functions
DrawLine Program
Cartesian Coordinates Program
Converting Cartesian Coordinates to
Converting Cartesian Coordinates to Screen Coordinates
INT 10h Pixel-Related Functions
Slow performance
Easy to program
0Ch: Write graphics pixel
0Dh: Read graphics pixel
DrawLine Program
Draws a straight line, using INT 10h function calls
Saves and restores current video mode
Excerpt from the
DrawLine
program (DrawLine.asm):mov ah,0Ch ; write pixel
mov al,color ; pixel color mov bh,0 ; video page 0
mov cx,currentX int 10h
Cartesian Coordinates Program
Draws the X and Y axes of a Cartesian coordinate system
Uses video mode 6A (800 x 600, 16 colors)
Name: Pixel2.asm
Important procedures:
¾ DrawHorizLine
¾ DrawVerticalLine
Converting Cartesian Coordinates to Screen Coordinates
Screen coordinates place the origin (0,0) at the upper-left corner of the screen
Graphing functions often need to display negative values
¾ move origin point to the middle of the screen
For Cartesian coordinates X, Y and origin points
sOrigX
andsOrigY
, screen X and screen Y are calculated as:¾ sx = (sOrigX + X)
¾ sy = (sOrigY – Y)
What's Next
Introduction
Keyboard Input with INT 16h
VIDEO Programming with INT 10hg g
Drawing Graphics Using INT 10h
Memory-Mapped Graphics
Mouse Programming
Memory-Mapped Graphics
Binary values are written to video RAM
¾ video adapter must use standard address
Very fast performance
¾ no BIOS or DOS routines to get in the way
Mode 13h: 320 X 200, 256 Colors
Mode 13h graphics (320 X 200, 256 colors)
¾ Fairly easy to program
¾ read and write video adapter via IN and OUT instructions
¾ pixel mapping scheme (1 byte per pixel)
¾ pixel-mapping scheme (1 byte per pixel)
Mode 13h Details
OUT Instruction
¾ 16-bit port address assigned to DX register
¾ output value in AL, AX, or EAX
¾ Example:
mov dx,3c8h ; port address mov dx,3c8h ; port address
mov al,20h ; value to be sent out dx,al ; send to the port
Color Indexes
¾ color integer value is an index into a table of colors called a palette
Color Indexes in Mode 13h
RGB Colors
Additive mixing of light (red, green, blue). Intensities vary from 0 to 255.
Examples:
What's Next
Introduction
Keyboard Input with INT 16h
VIDEO Programming with INT 10hg g
Drawing Graphics Using INT 10h
Memory-Mapped Graphics
Mouse Programming
Mouse Programming
MS-DOS functions for reading the mouse
Mickey – unit of measurement (200th of an inch)
¾ mickeys-to-pixels ratio (8 x 16) is variable
INT 33h functions
Mouse Tracking Program Example
Reset Mouse and Get Status
INT 33h, AX = 0
Example:
mov ax,0 int 33h cmp ax,0
je MouseNotAvailable mov numberOfButtons,bx
Show/Hide Mouse
INT 33h, AX = 1 (show), AX = 2 (hide)
Example:
mov ax,1 ; show int 33h
mov ax,2 ; hide int 33h
Get Mouse Position & Status
INT 33h, AX = 4
Example:
mov ax,4
mov cx,200 ; X-position mov dx,100 ; Y-position int 33h
Get Button Press Information
INT 33h, AX = 5
Example:
mov ax,5
mov bx,0 ; button ID
int 33h
test ax,1 ; left button down?
jz skip ; no - skip
mov X_coord,cx ; yes: save coordinates mov Y_coord,dx
Other Mouse Functions
AX = 6: Get Button Release Information
AX = 7: Set Horizontal Limits
AX = 8: Set Vertical Limits
Mouse Tracking Program
Tracks the movement of the text mouse cursor
X and Y coordinates are continually updated in the lower-right corner of the screen
When the user presses the left button, the
’ i i i di l d i h l l f mouse’s position is displayed in the lower left corner of the screen
Source code (c:\Irvine\Examples\ch15\mouse.asm)
Set Mouse Position
INT 33h, AX = 3
Example:
mov ax,3 int 33h test bx 1 test bx,1
jne Left_Button_Down test bx,2
jne Right_Button_Down test bx,4
jne Center_Button_Down mov Xcoord,cx
mov yCoord,dx