# SINFO.EXE, or playing with BIOS interrupts on my PC XT clone

*2016-01-26*

> Explore BIOS interrupts 11h and 12h with SINFO.EXE, a Turbo C and inline assembly program that reports hardware details on a PC XT clone.

I've been stuck for several days on a problem in the game I'm developing. When that happens, I usually do something else for a couple of hours. This time, I decided to play with BIOS interrupts on my PC XT clone.

{{< figure align="aligncenter" width=300 src="/blog/pravetz-300x225.jpg" alt="Pravetz 16 (IBM PC XT clone)" caption="Pravetz 16 (IBM PC XT clone)" >}}

**Note:** Writing code on a monochrome monitor is something every software developer should try at least once in their career.

The [Wikipedia article on interrupts](https://en.wikipedia.org/wiki/Interrupt) gives this overview:

> In system programming, an interrupt is a signal to the processor emitted by hardware or software indicating an event that needs immediate attention. An interrupt alerts the processor to a high-priority condition requiring the interruption of the current code the processor is executing. The processor responds by suspending its current activities, saving its state, and executing a function called an interrupt handler (or an interrupt service routine, ISR) to deal with the event. This interruption is temporary, and, after the interrupt handler finishes, the processor resumes normal activities. There are two types of interrupts: hardware interrupts and software interrupts.

The code below uses [inline assembly](http://www.codeproject.com/Articles/15971/Using-Inline-Assembly-in-C-C) to call BIOS interrupts [11h (Equipment Installed)](https://courses.engr.illinois.edu/ece390/books/artofasm/CH13/CH13-2.html#HEADING2-45) and [12h (Memory Available)](https://courses.engr.illinois.edu/ece390/books/artofasm/CH13/CH13-2.html#HEADING2-67). To compile it, you'll need Turbo C and TASM. Both can run under [DOSBox](https://www.dosbox.com/).

The compiled [SINFO.EXE](https://paskov.vmsoft-bg.com/downloads/pravetz/sinfo.exe) is available for download.

Here's the source:

```c
#include <stdio.h>

int main(void)
{
    int systemInfo;
    int floppyCount;
    int mem, memSize, memSizePost;
    int videoMode;
    int serialPorts;
    int parallelPorts;

    /* Call INT 11h ( Equipment Installed ) */
    asm int 11h;
    asm mov systemInfo, ax;

    /* Call INT 12h ( Memory Available ) */
    asm int 12h;
    asm mov memSizePost, ax;

    printf("********** SYSTEM INFO ***********\n");
    printf("Floppy drive(s): %s ", (systemInfo & 0x0001) ? "yes" : "no");

    if ((systemInfo & 0x0001))
    {
        switch ((systemInfo & 0x00C0))
        {
            case 0:
            {
                floppyCount = 1;
                break;
            }
            case 64:
            {
                floppyCount = 2;
                break;
            }
            case 128:
            {
                floppyCount = 3;
                break;
            }
            case 192:
            {
                floppyCount = 4;
                break;
            }
        }

        printf("(%d)\n", floppyCount);
    }
    else
    {
        printf("\n");
    }

    printf("Math co-processor: %s\n", (systemInfo & 0x0002) ? "yes" : "no");

    mem = (systemInfo & 0x000C);

    switch (mem)
    {
        case 0:
        {
            memSize = 16;
            break;
        }
        case 4:
        {
            memSize = 32;
            break;
        }
        case 8:
        {
            memSize = 48;
            break;
        }
        case 12:
        {
            memSize = 256;
            break;
        }
    }
    printf("On-board memory: %d K%s\n", memSize, (memSize >= 256) ? "+" : " ");
    printf("Memory reported by BIOS POST: %dK\n", memSizePost);

    videoMode = (systemInfo & 0x0030);
    switch (videoMode)
    {
        case 0:
        {
            printf("Video mode: EGA, VGA or PGA\n");
            break;
        }
        case 16:
        {
            printf("Video mode: CGA, 40 x 25\n");
            break;
        }
        case 32:
        {
            printf("Video mode: CGA, 80 x 25\n");
            break;
        }
        case 48:
        {
            printf("Video mode: monochrome, 80 x 25\n");
            break;
        }
    }

    printf("DMA support: %s\n", (systemInfo & 0x0100) == 0 ? "yes" : "no");
    printf("Game adapter: %s\n", (systemInfo & 0x1000) == 0 ? "no" : "yes");

    switch ((systemInfo & 0x0E00))
    {
        case 0:
        {
            serialPorts = 0;
            break;
        }
        case 512:
        {
            serialPorts = 1;
            break;
        }
        case 1024:
        {
            serialPorts = 2;
            break;
        }
        case 1536:
        {
            serialPorts = 3;
            break;
        }
        case 2048:
        {
            serialPorts = 4;
            break;
        }
    }
    printf("Serial ports: %d\n", serialPorts);

    switch ((systemInfo & 0xC000))
    {
        case 0:
        {
            parallelPorts = 0;
            break;
        }
        case 16384:
        {
            parallelPorts = 1;
            break;
        }
        case 32768:
        {
            parallelPorts = 2;
            break;
        }
        case 49152:
        {
            parallelPorts = 3;
            break;
        }
    }
    printf("Parallel ports: %d\n", parallelPorts);

    return 0;
}
```

