Set VGA videomodes, clear screen

Every VGA card has built-in, low-level subroutines for basic reasons. This is called VGA-BIOS, and in the DOS age it was a de-facto standard, so manufacturers garantee, that the BIOS routines (in the IBM terminology they called interrupts) will work in the same way on different products. With these functions you can do the most basic functions, like Later on you'll need a full functional list of the VGA BIOS services. If you google for the text "INT 10 BIOS Video services", you'll find tons of resources on the net. This is just a quick summary that shows, what we could do by the BIOS:
 
   0: set video mode                    1: set cursor shape         2: set cursor location
   3: report cursor location,shape      4: light pen service        5: select active page
   6: scroll up (clear screen)          7: scroll down              8: read char&attrib at cursor
   9: write char&attrib                 A: write char               B: set palette
   C: write pixel                       D: read pixel               E: write char teletype
   F: read video mode                  10: EGA/VGA BIOS            11: Character Generator
  12: Alternate select                 13: write text string       1A: Video combination code
  1B: Get BIOS Functionality Info      1C: VGA State               4F: VESA 

In the DOS, calling a system function is always done by software interrupts, by then instruction INT. You pass the parameters via the CPU registers and if there is any return value, you'll get back them in the registers, too. For the VIDEO routines, the BIOS uses the interrupt number $10 (16 in decimal). Usually we pass a function code in the register AH, and the other parameters go into AL,BX,CX.. etc. For setting a videomode, we must place the code in the AL, while the function code is $00 in the AH.

Now, what we want to do is setup the standard 320x200 videomode with 256 colors. Each videomode has a code. Because earlier the IBM PC had different video cards, for compatibility reasons the VGA can use the previous CGA and EGA video modes as well. Anyway, the here comes the standard list:

   Code: VIDEO MODE:
     00: text 40*25 16 color (mono) 
     01: text 40*25 16 color 
     02: text 80*25 16 color (mono) 
     03: text 80*25 16 color 
     04: CGA 320*200 4 color 
     05: CGA 320*200 4 color (m) 
     06: CGA 640*200 2 color 
     07: MDA monochrome text 80*25 
     08: PCjr 
     09: PCjr 
     0A: PCjr 
     0B: reserved 
     0C: reserved 
     0D: EGA 320*200 16 color 
     0E: EGA 640*200 16 color 
     0F: EGA 640*350 mono 
     10: EGA 640*350 16 color 
     11: VGA 640*480 16 color 
     12: VGA 640*480 16 color 
     13: VGA 320*200 256 color*

Set the videomode

As you see above, the mode we need is $13. However, we have to have a way to switch back to the normal text mode, which is the mode number $03. Our procedures then look like this:

procedure Graph320x200; assembler; { turn on the graph mode }
asm
   mov  ax,0013h
   int  10h
end;

procedure Text80x25; assembler; { back to textmode }
asm
   mov  ax,0003h
   int  10h
end;

Notice, that we pass both parameters by one MOV AX,... instruction, where there AH is always $00 and the AL is the code for the videomode. Simple, right? Surely we could write other procedures or pass the mode code as a parameter, but for now these two will do.

Clear the screen

The screen memory is a 64000 bytes memory area, so clearing (or filling) it is a basic task. For example, the well known easy fillchar function can do it, like this:

  fillchar(mem[$a000:0],64000,0);

However, if we do it, do it perfectly. The follwing procedure clears the picture with the given color.

procedure Cls(color:integer); assembler;
asm
   mov  ax,color      { color code, only AL is important   }
   mov  ah,al         { now AH=color as well               }
   cld
   mov  ES,SegA000
   xor  di,di
   mov  cx,32000      { fill up 32000 words with the color }
   rep  stosw
end;

Note, that we use the STOSW instruction to fill up the memory with words. Therefore AH and AL have the same value. In theory we could use the STOSD instruction - assuming 32bits CPU -, but for this simple screen STOSW is good enough.

Test

This is a small program to test the procedures.

program test0;

uses gfx256;

begin
  graph320x200; { initalize the graphic mode }

  cls(1);       { solid blue screen          }
  readln;
  cls(2);       { solid green screen         } 

  readln;
  text80x25;    { back to textmode           }
end.

Downloads: [ Gfx256 unit | Test0 ]

Back