    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: An Introduction to MSDOS and BIOS Interrupts</title>
        <link>https://members.accu.org/index.php/articles/716</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">CVu Journal Vol 8, #1 - Feb 1996</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c137/">081</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
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/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;An Introduction to MSDOS and BIOS Interrupts</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 February 1996 13:15:26 +00:00 or Sat, 03 February 1996 13:15:26 +00:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e16" id="d0e16"></a></h2>
</div>
<p>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!</p>
<p>All the code fragments, etc. are created using Borland C++ 3.1,
But the functions used should be standard amongst most PC
compilers.</p>
<p>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.</p>
<p>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.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e26" id="d0e26"></a>The BIOS
Services</h2>
</div>
<p>These allow you to access:</p>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Video functions: Cursor sizes, Window Scrolling, etc.</p>
</li>
<li>
<p>Disc Functions: Reading Disc Sectors, Disc Types, Recalibrate
Drives, etc.</p>
</li>
<li>
<p>System Functions: Joystick Input, Extended Memory Size, Program
Termination.etc.</p>
</li>
<li>
<p>And many other functions such as Keyboard, Printer, Time,.
Bootstrap.......</p>
</li>
</ul>
</div>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e44" id="d0e44"></a>The MSDOS
Services</h2>
</div>
<p>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.</p>
<p>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.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e51" id="d0e51"></a>BIOS
Services</h2>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e54" id="d0e54"></a>Some background
Information</h2>
</div>
<p>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.</p>
<p>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.</p>
<p>There are 12 BIOS interrupts and they fall into 5 groups:</p>
<p>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</p>
<div class="table"><a name="d0e65" id="d0e65"></a>
<p class="title c2">Table 1. </p>
<table summary="" border="1">
&lt;colgroup&gt;
&lt;col&gt;
&lt;col&gt;
&lt;col&gt;&lt;/colgroup&gt;
&lt;tbody&gt;
<tr>
<td><span class="bold"><b>Interrupt (HEX) :</b></span></td>
<td><span class="bold"><b>Interrupt (DEC) :</b></span></td>
<td><span class="bold"><b>Use :</b></span></td>
</tr>
<tr>
<td colspan="3" align="center"><span class=
"emphasis"><em>Peripheral Devices Services</em></span></td>
</tr>
<tr>
<td>10H</td>
<td>16</td>
<td>Video Display Services</td>
</tr>
<tr>
<td>13H</td>
<td>19</td>
<td>Disk Services</td>
</tr>
<tr>
<td>14H</td>
<td>20</td>
<td>Communications Services</td>
</tr>
<tr>
<td>15H</td>
<td>21</td>
<td>System Services</td>
</tr>
<tr>
<td>16H</td>
<td>22</td>
<td>Standard Keyboard Services</td>
</tr>
<tr>
<td>17H</td>
<td>23</td>
<td>Printer Services</td>
</tr>
<tr>
<td colspan="3" align="center"><span class="emphasis"><em>Equipment
Status Services</em></span></td>
</tr>
<tr>
<td>11H</td>
<td>17</td>
<td>Equipment Status Services</td>
</tr>
<tr>
<td>12H</td>
<td>18</td>
<td>Memory Size service</td>
</tr>
<tr>
<td colspan="3" align="center"><span class="emphasis"><em>Time /
Date Service</em></span></td>
</tr>
<tr>
<td>1AH</td>
<td>26</td>
<td>Time and Date Service</td>
</tr>
<tr>
<td colspan="3" align="center"><span class="emphasis"><em>Print
Screen Service</em></span></td>
</tr>
<tr>
<td>05H</td>
<td>5</td>
<td>Print Screen Service</td>
</tr>
<tr>
<td colspan="3" align="center"><span class="emphasis"><em>Special
Services</em></span></td>
</tr>
<tr>
<td>18H</td>
<td>24</td>
<td>Activate ROM Basic</td>
</tr>
<tr>
<td>19H</td>
<td>25</td>
<td>Activate Bootstrap start up Routine</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p>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.</p>
<p>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.</p>
<p>I recommend finding out about the available functions for using
interrupts with your C Compiler as there are different variations
such as <tt class="literal">int86x</tt>, etc.</p>
<p>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:</p>
<pre class="programlisting">
#include &lt;stdio.h&gt; #include &lt;dos.h&gt; int main(void) { union REGS inregs, outregs; /* Invoke the 12H Interrupt to get the Conventional Memory Size. */ int86(0x12, &amp;inregs,&amp;outregs); printf(&quot;You have %d KB&quot; &quot;Conventional Memory&quot;,outregs.x.ax); }
</pre>
<p>This calls the 12H BIOS Interrupt which in turn places the
memory size in AX within outregs.</p>
<p>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.</p>
<p>The following program calls this sub-service and displays the
current video mode information.</p>
<pre class="programlisting">
#include &lt;stdio.h&gt; #include &lt;dos.h&gt; #include &lt;conio.h&gt; int main(void) { union REGS inregs, outregs; clrscr(); /* Specify the Current Video Mode Service */ inregs.h.ah=0xF; // Invoke this Interrupt int86(0x10, &amp;inregs,&amp;outregs); printf(&quot;Width :%d\n&quot;, outregs.h.ah); printf(&quot;Video Mode : %d\n&quot;, outregs.h.al); printf(&quot;Page Number :%d\n&quot;, outregs.h.bh); return (0); }
</pre>
<p>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.</p>
<p>Bit Coding for the Equipment List 16 bit Word.</p>
<div class="table"><a name="d0e212" id="d0e212"></a>
<p class="title c2">Table 2. </p>
<table summary="" border="1">
&lt;colgroup&gt;
&lt;col&gt;
&lt;col&gt;&lt;/colgroup&gt;
&lt;tbody&gt;
<tr>
<td><span class="bold"><b>Bit :</b></span></td>
<td><span class="bold"><b>Description :</b></span></td>
</tr>
<tr>
<td>0</td>
<td>1 If any floppy Drives Exist</td>
</tr>
<tr>
<td>1</td>
<td>1 If a Maths Co Processor is Installed</td>
</tr>
<tr>
<td>2,3</td>
<td>Amount Of System Board Ram, 11 = 64 KB, 10 = 48 KB, 01 = 32 KB,
00 = 16 KB</td>
</tr>
<tr>
<td>4,5</td>
<td>Initial Video Mode, 11 = Monochrome, 10 = 80 Column Colour, 01
= 40 Column Colour.</td>
</tr>
<tr>
<td>6,7</td>
<td>1 Less than Number of Floppies Installed eg. If one floppy is
installed Bits 6 and 7 = 0</td>
</tr>
<tr>
<td>8</td>
<td>Not Used</td>
</tr>
<tr>
<td>9-11</td>
<td>Number of RS232 Serial Ports</td>
</tr>
<tr>
<td>12</td>
<td>Game Adapter, 1 = Installed</td>
</tr>
<tr>
<td>13</td>
<td>Reserved</td>
</tr>
<tr>
<td>14,15</td>
<td>Number of Printers Installed</td>
</tr>
&lt;/tbody&gt;
</table>
</div>
<p>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.</p>
<p>The following code shows how to access the Equipment List and
produce some useful information :</p>
<pre class="programlisting">
/*********************************************************************** * Interrupt 11H - BIOS Interrupt Service * * Equipment List Service * ************************************************************************/ #include &lt;stdio.h&gt; #include &lt;dos.h&gt; #include &lt;conio.h&gt; int reg, reg1, reg2, reg3; int main(void) { clrscr(); union REGS inregs, outregs; // Call the 11H Interrupt for a Equipment List int86(0x11, &amp;inregs,&amp;outregs); // If bit 0 equals 1 a Floppy Drive Exists if (outregs.x.ax &amp;&amp; 1 == 1){ reg1=((outregs.x.ax &amp;&amp; 32 + outregs.x.ax &amp;&amp; 64)/32+1); printf(&quot;%d Floppy Drive(s) Installed\n&quot;, reg1); } // If bit 1 equals 1 a Maths Coprocesser Is installed. if (outregs.x.ax &amp;&amp; 2) printf(&quot;Maths Coprocesser Installed\n&quot;); reg1=outregs.x.ax &amp;&amp; 4; reg2=outregs.x.ax &amp;&amp; 8; if (reg1==1 &amp;&amp; reg2==1) printf(&quot;64 KB of System Board Ram\n&quot;); if (reg1==1 &amp;&amp; reg2==0) printf(&quot;48 KB of System Board Ram\n&quot;); if (reg1==0 &amp;&amp; reg2==1) printf(&quot;32 KB of System Board Ram\n&quot;); if (reg1==0 &amp;&amp; reg2==0) printf(&quot;16 KB of System Board Ram\n&quot;); reg1=outregs.x.ax &amp;&amp; 16; reg2=outregs.x.ax &amp;&amp; 32; if (reg1==1 &amp;&amp; reg2==1) printf(&quot;Monochrome Initial Video Mode\n&quot;); if (reg1==1 &amp;&amp; reg2==0) printf(&quot;80 Column Colour Initial Video Mode\n&quot;); if (reg1==0 &amp;&amp; reg2==1) printf(&quot;40 Column Colour Initial Video Mode.\n&quot;); reg1=outregs.x.ax &amp;&amp; 512; reg2=outregs.x.ax &amp;&amp; 1024; reg3=outregs.x.ax &amp;&amp; 2048; reg=reg1+reg2+reg3/512; printf(&quot;%d RS-232 Serial Ports are Installed.\n&quot;, reg); reg1=outregs.x.ax &amp;&amp; 4096; if (reg1==1)printf(&quot;Game Adapter Installed.\n&quot;); else printf(&quot;There are no game adapters installed.\n&quot;); reg1=outregs.x.ax &amp;&amp; 16384; reg2=outregs.x.ax &amp;&amp; 32768; reg=reg1+reg2/16384; printf(&quot;There are %d Printer(s) Installed.&quot;, reg); return(0); }
</pre>
<p>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.</p>
<p>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.</p>
<p>For further reading I recommend :</p>
<p><span class="emphasis"><em>The Peter Norton PC Programmers
Bible</em></span>, (1-55615-555-7) @ &pound;26.95</p>
<p>or :</p>
<p><span class="emphasis"><em>PC Interrupts, A Programmer's
Reference to BIOS, DOS, And Third Party Calls</em></span> by Ralf
Brown and Jim Kyle (0-201-57797) @ $32.95</p>
<p>The copy of <span class="emphasis"><em>PC Interrupts</em></span>
I have is quite old and there is probably a new edition out.</p>
<p>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 <a href="ftp://garbo.uwasa.fi/pc/programming/" target=
"_top">garbo.uwasa.fi/pc/programming/</a> or <a href=
"ftp://oak.oakland.edu/SimTel/msdos/info/" target=
"_top">oak.oakland.edu/SimTel/msdos/info/</a></p>
<p>Or if you have WWW Access: <a href=
"http://www.cs.cmu.edu:8001/afs/cs/user/ralf/pub/WWW/ralf-home.html"
target=
"_top">www.cs.cmu.edu:8001/afs/cs/user/ralf/pub/WWW/ralf-home.html</a></p>
<p>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 !</p>
<p><tt class="literal">inter47a.zip, inter47b.zip, inter47c.zip,
inter47d.zip, inter47e.zip</tt></p>
<p>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.</p>
<p>My Address is not in the Old Hand book:</p>
<p>37 Marions Way, Exmouth, DEVON, EX8 4LF Telephone (Evenings
Only) : (01395) 264872. email : dajd@g8gon.zynet.co.uk</p>
<p>And just to confuse all of you look at this statement recently
posted in a Internet newsgroup!</p>
<p><tt class="literal">for
(;P(&quot;\n&quot;),R-;P(&quot;|&quot;))for(e=C;e-:P(&quot;_&quot;+(*u++/8)%2))P(&quot;|&quot;+(*u/4)%2);</tt></p>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
