Writing to screen
1. Video Modes
2. Writing to screen - methods
3. Cursor Position
4. Simpliest Method is fine... so why get complex?
Video Modes
Writing something on the screen is essential. There are MANY ways to do it, even in DOS.
We'll speak of video modes. For more info on video modes and Video Memory space, see Robinson's MicroRepair pages.
Click here to read about VGA and some of the video modes it supports. All modern video cards support VGA.
Click here, Ralf Brown's Interupt list- Set Video Mode. It describes all the video modes accessable by BIOS.
There are diferent video modes. Each one has a differrent amount of columns/rows, colors and resolution.
The video card is the device whose video mode we can select. The BIOS provdes an easy interface to select any video mode (#3 is normally used by DOS).
The video mode dictates how the video card interprets it's data. Data can be interpreted as pixel data(graphics mode) or as ASCII characters (text mode).
Also, since different video modes have more or less colums/rows, colors and resoution,
different video modes take up various amounts of ram. Though a set portion of ram is set aside for the video memory, I think.
Video memory is a part of normal ram where programs (BIOS) write their Screen-Data. The Video card independently reads that data and updates the Screen.
That is the data which can be interpreted in varous ways.
Let's examine video mode #3 (text mode). It provides 80 column and 25 rows. Video Memory is treated as an ARRAY.
The first 160 bytes in that array (from 0 - 159) are the columns 0-79 on row 0 (the top of the screen).
The next 160 bytes (160-319) are columns 0-79 on row 1.
Why is each row 160 bytes in size when there are only 80 columns per row? Beuase in this text mode, one byte is for the ASCII character and the other byte is for it's color attribute. Two bytes per CHAR.
The video card will take care of drawing the CHAR on screen. It just needs to know which one to draw and what color.
Writing to screen - methods
So if we wanted to write a string to the screen we could do 3 things.
1. Call DOS to do it
2. Call BIOS to do it
3. Write the data to Video Memory ourselves.
Dos is easiest. All it requires is a pointer to a '$' terminated string. Calling the BIOS to do it requires more of a setup, but provides much more control.
BIOS let's us pick the color and location on screen. But it has to be told how long the string is. Not a big deal.
If we do it ourselves, it's faster than the bios, beacuse the BIOS code is on a ROM chip (which is slower than RAM).
HEY, DOS might even use the bios... Let's make an INTERUPT handler to spy on DOS! (INT 10h are BIOS video functions)
Whenever DOS calls bios with an INT 10h, our handler will intercept the call and tell us, then pass the call to the original INT 10h handler (bios).
To write to video memory directly. We need to know which video mode is selected (we can easiliy get/set the dideo mode with BIOS (INT 10h) function 0).
Each video-mode's memory area starts at it's own Segment.
So if we known which mode is active, then we know which segment to write to. Next, we take into account that each video mode can implement numerous video-pages.
Each video page is a screenful of data. Each video-page is in it's own area of ram. Video pages are conveinient, because you can write a whole screen of data, and switch to it when needed, then swith back to the previous screen, thus eliminating the need to re-draw.
Once we know the segment, and page (and size of page), use an Offset pointer to seed the video array. (hint-- mov es:[di], al)
Cursor Position
When using an API (DOS's or BIOS's) to print to screen, the text will be printed at the current cursor position.
String printing with the BIOS let's you decide where, but the BIOS can also print ONE char at a time at the current cursor position.
The Cursor is that blinking underscore at the DOS-Prompt.
Simpliest Method
For normal printing-to-screen, using DOS is beautiful and easy (as you've seen using function 9 of INT 21h).
The only reason to print using BIOS (or doing it manually) is when you need control of what the screen looks like.
Reasons:
-Making a cool front-end to a program
-text editing
-video game
-special applications
The tutorials will provide all you need to know, of course - no need to copy the following functions, it's just there to look at in awe.
from Ralf Brown's Interupt List - http://www.ctyme.com/rbrown.htm
all the following are the setups for functions using Int 10h
-------------------------------------------------------------------
VIDEO - WRITE STRING (AT and later,EGA)
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
Return:Nothing
Notes: Recognizes CR, LF, BS, and bell; for the ET4000 BIOS, scrolling, backspace, and CR only take place in the active page. Also available PC or XT with EGA or higher. HP 95LX only supports write mode 00h. IBM documents AL=10h,11h,20h,21h as "private" rather than "reserved". With PhysTechSoft's PTS ROM-DOS the AL,BH,BL,DH, and DL values are ignored on entry.
BUG: On the IBM VGA Adapter, any scrolling which may occur is performed on the active page rather than the requested page
--------------------------------------------------------
VIDEO - WRITE CHARACTER AND ATTRIBUTE AT CURSOR POSITION
AH = 09h
AL = character to display
BH = page number (00h to number of pages - 1) (see #00010)
background color in 256-color graphics modes (ET4000)
BL = attribute (text mode) or color (graphics mode)
if bit 7 set in <256-color graphics mode, character is XOR'ed
onto screen
CX = number of times to write character
Return:Nothing
Notes: All characters are displayed, including CR, LF, and BS. Replication count in CX may produce an unpredictable result in graphics modes if it is greater than the number of positions remaining in the current row. With PhysTechSoft's PTS ROM-DOS the BH, BL, and CX values are ignored on entry.
-------------------------------------------------
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)
Return:Nothing
------------------------------------------------------
VIDEO - GET CURSOR POSITION AND SIZE
AH = 03h
BH = page number
0-3 in modes 2&3
0-7 in modes 0&1
0 in graphics modes
Return:AX = 0000h (Phoenix BIOS)
CH = start scan line
CL = end scan line
DH = row (00h is top)
DL = column (00h is left)
Notes: A separate cursor is maintained for each of up to 8 display pages. Many ROM BIOSes incorrectly return the default size for a color display (start 06h, end 07h) when a monochrome display is attached. With PhysTechSoft's PTS ROM-DOS the BH value is ignored on entry.
----------------------------------------------------------