|
|||||
12
Video
Services
12.1.
BIOS VIDEO
SERVICES
The
Basic Input Output System
(BIOS) provides services for
video,
keyboard,
serial port, parallel port,
time etc. The video
services are exported
via INT
10. We will discuss some
very simple services. Video
services are
classified
into two broad categories;
graphics mode services and
text mode
services.
In graphics mode a location in
video memory corresponds to a
dot
on the
screen. In text mode this
relation is not straightforward.
The video
memory
holds the ASCII of the
character to be shown and
the actual shape is
read
from a font definition
stored elsewhere in memory. We
first present a list
of
common video services used
in text mode.
INT 10 -
VIDEO - SET VIDEO
MODE
AH =
00h
AL = desired video
mode
Some
common video modes include
40x25 text mode (mode
0), 80x25 text
mode
(mode 2), 80x50 text
mode (mode 3), and
320x200 graphics mode
(mode
D).
INT 10 -
VIDEO - SET TEXT-MODE CURSOR
SHAPE
AH =
01h
CH = cursor start
and options
CL = bottom scan
line containing cursor (bits 0-4)
INT 10 -
VIDEO - SET CURSOR
POSITION
AH =
02h
BH = page
number
0-3 in modes
2&3
0-7 in modes
0&1
0 in graphics
modes
DH = row (00h is
top)
DL = column (00h
is left)
INT 10 -
VIDEO - SCROLL UP
WINDOW
AH =
06h
AL = number of
lines by which to scroll up (00h = clear entire
window)
BH = attribute
used to write blank lines at bottom of
window
CH, CL = row,
column of window's upper left
corner
DH, DL = row,
column of window's lower right
corner
INT 10 -
VIDEO - SCROLL DOWN
WINDOW
AH =
07h
AL = number of
lines by which to scroll down (00h=clear entire
window)
BH = attribute
used to write blank lines at top of
window
CH, CL = row,
column of window's upper left
corner
DH, DL = row,
column of window's lower right
corner
INT 10 -
VIDEO - WRITE CHARACTER AND
ATTRIBUTE AT CURSOR
POSITION
AH =
09h
AL = character to
display
BH = page
number
Computer
Architecture & Assembly Language
Programming
Course
Code: CS401
CS401@vu.edu.pk
BL = attribute (text
mode) or color (graphics mode)
CX = number of
times to write character
INT 10 -
VIDEO - WRITE CHARACTER ONLY AT
CURSOR POSITION
AH =
0Ah
AL = character to
display
BH = page
number
BL = attribute (text
mode) or color (graphics mode)
CX = number of
times to write character
INT 10 -
VIDEO - WRITE
STRING
AH =
13h
AL = write
mode
bit 0: update
cursor after writing
bit 1: string contains
alternating characters and attributes
bits 2-7: reserved
(0)
BH = page
number
BL = attribute if string
contains only characters
CX = number of
characters in string
DH, DL = row,
column at which to start writing
ES:BP -> string
to write
Chargen
Services
In our
first example we will read
the font definition in
memory and change
it to
include a set of all on
pixels in the last line
showing an effect of
underline
on all character including
space. An 8x16 font is stored in
16
bytes.
A sample character and the
corresponding 16 values stored in
the font
information
are shown for the
character `A'. We
start
with two services from the
chargen subset
of
video services that we are
going to use.
INT 10 -
VIDEO - GET FONT
INFORMATION
AX =
1130h
BH = pointer
specifier
Return:
ES:BP = specified
pointer
CX = bytes/character of
on-screen font
DL = highest character
row on screen
INT 10 -
TEXT-MODE CHARGEN
AX =
1110h
ES:BP -> user
table
CX = count of patterns to
store
DX = character offset into
map 2 block
BL = block to load in
map 2
BH = number of
bytes per character pattern
We will
use 6 as the pointer
specifier which means the 8x16
font stored in
ROM.
Example
12.1
001
; put underlines on
screen font
002
[org
0x0100]
003
jmp
start
004
005
font:
times 256*16 db
0
; space for
font
006
007
start:
mov
ax,
0x1130
; service 11/30 get font
info
008
mov
bx,
0x0600
; ROM
8x16 font
009
int
0x10
; bios video
services
010
011
mov
si, bp
; point si to rom
font data
012
mov
di, font
; point di to
space for font
142
Computer
Architecture & Assembly Language
Programming
Course
Code: CS401
CS401@vu.edu.pk
013
mov
cx,
256*16
; font size
014
push
ds
015
push
es
016
pop
ds
;
ds:si to rom font
data
017
pop
es
;
es:di to space for
font
018
cld
;
auto increment
mode
019
rep
movsb
;
copy
font
020
021
push
cs
022
pop
ds
; restore ds to data
segment
023
024
mov
si, font-1
;
point si before first
char
025
mov
cx,
0x100
;
total 256
characters
026
change:
add
si, 16
;
one character
has 16 bytes
027
mov
byte [si],
0xFF
;
change last line
to all ones
028
loop
change
;
repeat for each
character
029
030
mov
bp, font
;
es:bp points to
new font
031
mov
bx,
0x1000
;
bytes per char & block
number
032
mov
cx,
0x100
;
number of
characters to change
033
xor
dx, dx
;
first character to
change
034
mov
ax,
0x1110
;
service 11/10 load user
font
035
int
0x10
;
bios video
services
036
037
mov ax,
0x4c00
; terminate
program
038
int
0x21
Our
second example is similar to
the last example however in
this case we
are
doing something funny on the
screen. We are reversing the
shapes of all
the
characters on the
screen.
Example
12.2
001
; reverse
each character of screen font
002
[org
0x0100]
003
jmp
start
004
005
font:
times 256*16 db
0
; space for
font
006
007
start:
mov
ax,
0x1130
; service 11/30 get font
info
008
mov
bx,
0x0600
; ROM
8x16 font
009
int
0x10
; bios video
services
010
011
mov
si, bp
; point si to rom
font data
012
mov
di, font
; point di to
space for font
013
mov
cx,
256*16
; font size
014
push
ds
015
push
es
016
pop
ds
;
ds:si to rom font
data
017
pop
es
;
es:di to space for
font
018
cld
;
auto increment
mode
019
rep
movsb
;
copy
font
020
021
push
cs
022
pop
ds
; restore ds to data
segment
023
024
mov si,
font
; point si to start of
font
025
change:
mov al,
[si]
; read one
byte
026
mov cx,
8
027
inner:
shl al, 1
;
shift left with
MSB in carry
028
rcr bl, 1
;
rotate right using
carry
029
loop inner
;
repeat eight
times
030
mov [si],
bl
;
write back
reversed byte
031
inc si
;
next byte of
font
032
cmp si,
font+256*16
;
is whole font
reversed
033
jne
change
;
no, reverse next
byte
034
035
mov
bp, font
;
es:bp points to
new font
036
mov
bx,
0x1000
;
bytes per char & block
number
037
mov
cx,
0x100
;
number of
characters to change
038
xor
dx, dx
;
first character to
change
039
mov
ax,
0x1110
;
service 11/10 load user
font
040
int
0x10
;
bios video
services
041
143
Computer
Architecture & Assembly Language
Programming
Course
Code: CS401
CS401@vu.edu.pk
042
mov
ax,
0x4c00
; terminate
program
043
int
0x21
Graphics
Mode Services
We will
take an example of using
graphics mode video services
as well. We
will draw a
line across the screen
using the following
service.
INT 10 -
VIDEO - WRITE GRAPHICS
PIXEL
AH =
0Ch
BH = page
number
AL = pixel
color
CX =
column
DX =
row
Example
12.3
001
; draw line in
graphics mode
002
[org
0x0100]
003
mov ax,
0x000D
; set 320x200
graphics mode
004
int
0x10
; bios video
services
005
006
mov
ax,
0x0C07
;
put pixel in white
color
007
xor
bx,
bx
;
page
number 0
008
mov
cx,
200
;
x position
200
009
mov
dx,
200
;
y position
200
010
011
l1:
int
0x10
; bios video
services
012
dec
dx
; decrease y
position
013
loop l1
; decrease x
position and repeat
014
015
mov
ah, 0
; service 0 get
keystroke
016
int
0x16
; bios keyboard
services
017
018
mov
ax,
0x0003
; 80x25 text
mode
019
int
0x10
; bios video
services
020
021
mov
ax,
0x4c00
; terminate
program
022
int
0x21
12.2.
DOS VIDEO
SERVICES
Services
of DOS are more cooked
and at a higher level than
BIOS. They
provide
less control but make
routine tasks much easier.
Some important
DOS
services are listed
below.
INT 21 - READ
CHARACTER FROM STANDARD INPUT,
WITH ECHO
AH =
01h
Return: AL = character
read
INT 21 -
WRITE STRING TO STANDARD
OUTPUT
AH =
09h
DS:DX -> $
terminated string
INT 21 -
BUFFERED INPUT
AH =
0Ah
DS:DX ->
dos input buffer
The
DOS input buffer has a
special format where the
first byte stores
the
maximum
characters buffer can hold,
the second byte holds
the number of
characters
actually read on return, and
the following space is used
for the
actual
characters read. We start will an
example of reading a string
with
service
1 and displaying it with service
9.
144
Computer
Architecture & Assembly Language
Programming
Course
Code: CS401
CS401@vu.edu.pk
Example
12.4
001
; character input using
dos services
002
[org
0x0100]
003
jmp start
004
005
maxlength:
dw
80
; maximum length
of input
006
message:
db
10, 13, 'hello
$'
; greetings
message
007
buffer:
times 81 db
0
; space for input
string
008
009
start:
mov
cx,
[maxlength]
; load maximum
length in cx
010
mov
si, buffer
; point si to start of
buffer
011
012
nextchar:
mov
ah, 1
; service 1 read
character
013
int
0x21
; dos
services
014
015
cmp
al, 13
;
is enter
pressed
016
je
exit
;
yes, leave
input
017
mov
[si], al
;
no, save this
character
018
inc
si
;
increment buffer
pointer
019
loop
nextchar
;
repeat for next input
char
020
021
exit:
mov
byte [si],
'$'
; append $ to user
input
022
023
mov
dx,
message
; greetings
message
024
mov
ah, 9
; service 9 write
string
025
int
0x21
; dos
services
026
027
mov
dx, buffer
; user input
buffer
028
mov
ah, 9
; service 9 write
string
029
int
0x21
; dos
services
030
031
mov
ax,
0x4c00
; terminate
program
032
int
0x21
Our
next example uses the
more cooked buffered input
service of DOS and
using
the same service 9 to print
the string.
Example
12.5
001
; buffer input using
dos services
002
[org
0x0100]
003
jmp
start
004
005
message:
db
10,13,'hello ', 10, 13,
'$'
006
buffer:
db
80
; length of
buffer
007
db
0
; number of
character on return
008
times 80 db
0
; actual buffer
space
009
010
start:
mov
dx, buffer
; input
buffer
011
mov
ah,
0x0A
; service A buffered
input
012
int
0x21
; dos
services
013
014
mov
bh, 0
015
mov
bl,
[buffer+1]
; read actual size in
bx
016
mov
byte [buffer+2+bx], '$' ;
append $ to user input
017
018
mov
dx,
message
; greetings
message
019
mov
ah, 9
; service 9 write
string
020
int
0x21
; dos
services
021
022
mov
dx,
buffer+2
; user input
buffer
023
mov
ah, 9
; service 9 write
string
024
int
0x21
; dos
services
025
026
mov
ax,
0x4c00
; terminate
program
027
int
0x21
More
detail of DOS and BIOS
interrupts is available in the
Ralf Brown
Interrupt
List.
145
Table of Contents:
|
|||||