Journal Articles

CVu Journal Vol 8, #1 - Feb 1996
Browse in : All > Journals > CVu > 081 (7)

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.

Title: An Introduction to MSDOS and BIOS Interrupts

Author: Administrator

Date: 03 February 1996 13:15:26 +00:00 or Sat, 03 February 1996 13:15:26 +00:00

Summary: 

Body: 

This article intended as a basic introduction to interrupts. I am writing it because I consider the MSDOS and BIOS Interrupts are powerful and useful tools for any programmer using MSDOS based platforms and I wish to bring them to the attention of others as I think many people are unaware of them and the degree of power and flexibility they provide!

All the code fragments, etc. are created using Borland C++ 3.1, But the functions used should be standard amongst most PC compilers.

I will cover as much as possible in this article, but it would be impossible for me to cover every interrupt with required input values, etc. as there are hundreds. For please see the end of the article for details of complete listings.

I won't ask Francis to put the listings on the C VU disc as the list is about 1.6mb compressed :-) There are two different types of Interrupt Services BIOS (Basic Input Output System), and MSDOS.

The BIOS Services

These allow you to access:

  • Video functions: Cursor sizes, Window Scrolling, etc.

  • Disc Functions: Reading Disc Sectors, Disc Types, Recalibrate Drives, etc.

  • System Functions: Joystick Input, Extended Memory Size, Program Termination.etc.

  • And many other functions such as Keyboard, Printer, Time,. Bootstrap.......

The MSDOS Services

These allow you to get MSDOS Version Numbers, File Sizes, Free Disc Space, Create TSR's, Make Network Connections, Move File Pointers, Rename Files, Extended Open/Create Get/Set Files attributes, Sequential Read/Write, and many other functions.

The degree of flexibility that these interrupts give you lets you 'tinker' with the lowest level of you computer and create fast and powerful programs.

BIOS Services

Some background Information

The BIOS services work directly with the computers hardware and peripheral devices. They perform some of the computers fundamental tasks such as reading and writing bytes of data to and from the display or disk. The MSDOS Services which I will cover in the next article, are often built from these basic functions and enhanced to make a particular task more efficient. You can enhance your programs by directly accessing the BIOS, thereby gaining access to an extremely powerful set of tools.

All BIOS Services are invoked by interrupts, each interrupt instruction selects a specific entry in the interrupt vector table in low memory. The address of all the BIOS Services are stored in this table. This design makes it possible for a program to request a service without knowing the specific memory location of the BIOS service routine.

There are 12 BIOS interrupts and they fall into 5 groups:

10H 16 Video Display Services 13H 19 Disk Services 14H 20 Communications Services 15H 21 System Services 16H 22 Standard Keyboard Services 17H 23 Printer Services Equipment Status Services 11H 17 Equipment list service 12H 18 Memory size service Time / Date Service 1AH 26 Time and Date service Print Screen Service 05H 5 Print Screen Service Special Services 18H 24 Activate ROM Basic 19H 25 Activate Bootstrap start up Routine

Table 1.

<colgroup> <col> <col> <col></colgroup> <tbody> </tbody>
Interrupt (HEX) : Interrupt (DEC) : Use :
Peripheral Devices Services
10H 16 Video Display Services
13H 19 Disk Services
14H 20 Communications Services
15H 21 System Services
16H 22 Standard Keyboard Services
17H 23 Printer Services
Equipment Status Services
11H 17 Equipment Status Services
12H 18 Memory Size service
Time / Date Service
1AH 26 Time and Date Service
Print Screen Service
05H 5 Print Screen Service
Special Services
18H 24 Activate ROM Basic
19H 25 Activate Bootstrap start up Routine

Most of the interrupts are connected to a group of sub-services that actually do the work, for example the Video service has 25 sub-services that do everything from setting the video mode to changing the size of the cursor. You call a sub-service by invoking it's governing interrupt and specifying the sub-service number in register AH.

To use an interrupt you have to set any required input values in a register which you then pass with a interrupt number and a output register, to int86(), and any output is placed in the output register. Some interrupts do not require input values and some do not return any register values.

I recommend finding out about the available functions for using interrupts with your C Compiler as there are different variations such as int86x, etc.

To use the Memory Size service to see how much conventional memory is installed you have to use the interrupt 12H, The following code demonstrates how to do this:

#include <stdio.h> #include <dos.h> int main(void) { union REGS inregs, outregs; /* Invoke the 12H Interrupt to get the Conventional Memory Size. */ int86(0x12, &inregs,&outregs); printf("You have %d KB" "Conventional Memory",outregs.x.ax); }

This calls the 12H BIOS Interrupt which in turn places the memory size in AX within outregs.

To use the Current Video mode you have to use the Video Services (Interrupt 10H). Within the video services there are many sub-services. To specify the service number you place the number in the AH register. The service no. for the current video mode is 0FH.

The following program calls this sub-service and displays the current video mode information.

#include <stdio.h> #include <dos.h> #include <conio.h> int main(void) { union REGS inregs, outregs; clrscr(); /* Specify the Current Video Mode Service */ inregs.h.ah=0xF; // Invoke this Interrupt int86(0x10, &inregs,&outregs); printf("Width :%d\n", outregs.h.ah); printf("Video Mode : %d\n", outregs.h.al); printf("Page Number :%d\n", outregs.h.bh); return (0); }

Another Example is the Equipment List ( Interrupt 11H ) When you invoke this interrupt it creates a report of what equipment is installed in the computer. This report is coded as shown in the following table in the bits of a 16 bit Word.

Bit Coding for the Equipment List 16 bit Word.

Table 2.

<colgroup> <col> <col></colgroup> <tbody> </tbody>
Bit : Description :
0 1 If any floppy Drives Exist
1 1 If a Maths Co Processor is Installed
2,3 Amount Of System Board Ram, 11 = 64 KB, 10 = 48 KB, 01 = 32 KB, 00 = 16 KB
4,5 Initial Video Mode, 11 = Monochrome, 10 = 80 Column Colour, 01 = 40 Column Colour.
6,7 1 Less than Number of Floppies Installed eg. If one floppy is installed Bits 6 and 7 = 0
8 Not Used
9-11 Number of RS232 Serial Ports
12 Game Adapter, 1 = Installed
13 Reserved
14,15 Number of Printers Installed

This equipment list is compiled once at start-up, and is then left in memory. So removing a piece of equipment with the machine on (Not Recommended :-) would not alter this list.

The following code shows how to access the Equipment List and produce some useful information :

/*********************************************************************** * Interrupt 11H - BIOS Interrupt Service * * Equipment List Service * ************************************************************************/ #include <stdio.h> #include <dos.h> #include <conio.h> int reg, reg1, reg2, reg3; int main(void) { clrscr(); union REGS inregs, outregs; // Call the 11H Interrupt for a Equipment List int86(0x11, &inregs,&outregs); // If bit 0 equals 1 a Floppy Drive Exists if (outregs.x.ax && 1 == 1){ reg1=((outregs.x.ax && 32 + outregs.x.ax && 64)/32+1); printf("%d Floppy Drive(s) Installed\n", reg1); } // If bit 1 equals 1 a Maths Coprocesser Is installed. if (outregs.x.ax && 2) printf("Maths Coprocesser Installed\n"); reg1=outregs.x.ax && 4; reg2=outregs.x.ax && 8; if (reg1==1 && reg2==1) printf("64 KB of System Board Ram\n"); if (reg1==1 && reg2==0) printf("48 KB of System Board Ram\n"); if (reg1==0 && reg2==1) printf("32 KB of System Board Ram\n"); if (reg1==0 && reg2==0) printf("16 KB of System Board Ram\n"); reg1=outregs.x.ax && 16; reg2=outregs.x.ax && 32; if (reg1==1 && reg2==1) printf("Monochrome Initial Video Mode\n"); if (reg1==1 && reg2==0) printf("80 Column Colour Initial Video Mode\n"); if (reg1==0 && reg2==1) printf("40 Column Colour Initial Video Mode.\n"); reg1=outregs.x.ax && 512; reg2=outregs.x.ax && 1024; reg3=outregs.x.ax && 2048; reg=reg1+reg2+reg3/512; printf("%d RS-232 Serial Ports are Installed.\n", reg); reg1=outregs.x.ax && 4096; if (reg1==1)printf("Game Adapter Installed.\n"); else printf("There are no game adapters installed.\n"); reg1=outregs.x.ax && 16384; reg2=outregs.x.ax && 32768; reg=reg1+reg2/16384; printf("There are %d Printer(s) Installed.", reg); return(0); }

This code has a number of errors in it which you will be able to correct when you read it with understanding. If you just copy it, I think it will compile, but it won't work the way you expect.

I have only covered a small amount of the BIOS Interrupts there are many more, I can not List them all here but look at the end of the article for information on obtaining Interrupt Lists. In the Next Article we will cover the MSDOS Interrupts.

For further reading I recommend :

The Peter Norton PC Programmers Bible, (1-55615-555-7) @ £26.95

or :

PC Interrupts, A Programmer's Reference to BIOS, DOS, And Third Party Calls by Ralf Brown and Jim Kyle (0-201-57797) @ $32.95

The copy of PC Interrupts I have is quite old and there is probably a new edition out.

For a list of virtually every interrupt on the PC check out Ralf Browns Interrupt Listing which a computer based set of files listing all the interrupts and how to access them. If anyone is interested in using interrupts or is using them then I thoroughly recommend them to you, If you have Internet access you can get them using ftp at garbo.uwasa.fi/pc/programming/ or oak.oakland.edu/SimTel/msdos/info/

Or if you have WWW Access: www.cs.cmu.edu:8001/afs/cs/user/ralf/pub/WWW/ralf-home.html

There is a total of 5 files and they are presently at version 47, but by the time you read this version 48 or even 49 might be out !

inter47a.zip, inter47b.zip, inter47c.zip, inter47d.zip, inter47e.zip

If you don't have Internet access, if you send me two discs and return postage I will be pleased to send you a copy. The total size of the zips is about 1.6mb.

My Address is not in the Old Hand book:

37 Marions Way, Exmouth, DEVON, EX8 4LF Telephone (Evenings Only) : (01395) 264872. email : dajd@g8gon.zynet.co.uk

And just to confuse all of you look at this statement recently posted in a Internet newsgroup!

for (;P("\n"),R-;P("|"))for(e=C;e-:P("_"+(*u++/8)%2))P("|"+(*u/4)%2);

Notes: 

More fields may be available via dynamicdata ..