dos.h Header File in C: Full Explanation & MS-DOS Rules | Unit 3 | BKNMU BCA



BCA Sem 1  |  Unit 3  |  Computer Concepts & C Programming

Full Explanation of dos.h Header File in C — BKNMU Junagadh

Detailed breakdown of non-standard MS-DOS utilities, time/date access, system interrupts (int86), sound, and GCC portability warnings

BKNMU Junagadh NEP 2020 Unit 3 dos.h Explained System Access Non-Standard
Full Detailed Explanation: Welcome to Unit 3! While standard C library headers (like stdio.h) are designed to be portable across different operating systems, the dos.h header file is **NOT part of the Standard C Library**. It is a **legacy, platform-dependent** header file specifically created for Borland compilers (like Turbo C/C++) running on the **MS-DOS operating system**. It contains declarations for functions required to perform low-level hardware interaction, direct BIOS/DOS interrupt calls, and manage system resources (time, date, sound, ports) that were common in early personal computing. For **BKNMU BCA Semester 1 (Unit 3)** exams, understanding its specific MS-DOS context and functions is mandatory.
📖 Core MS-DOS Utilities Defined in dos.h

The dos.h library organizes its non-standard, system-level routines into four primary categories, corresponding to the quadrants in your thumbnail:

gettime() / getdate()

1. Time & Date Access

Used to read the current system time and date, accepting pointers to specialized time and date structures defined within the header.

sound() / nosound()

2. Hardware Sound

Functions to control the PC's internal motherbord speaker directly. `sound` starts a frequency; `nosound` strictly shuts it off.

delay(milliseconds)

3. Execution Pause

Halts program execution for a precise duration. Crucial rule: Accepts parameter in **milliseconds** (e.g., delay(1000) = 1 sec).

int86() / REGS struct

4. System Interrupts

The core low-level utility. Used to invoke specific BIOS or DOS Interrupt calls directly, passing data via the **REGS** union structure.

1️⃣ Master Table: Commonly Used dos.h Functions

Here is a comprehensive breakdown of the primary functions supplied by the non-standard dos.h standard library, detailing their specific required parameters for low-level access.

Function PrototypeFunctional DescriptionStandard Parameters / Required Structure
void gettime(struct time*)Retrieves the current system time into the provided `time` structure.Pointer to struct time (contains: ti_hour, ti_min, ti_sec, ti_hund).
void getdate(struct date*)Retrieves the current system date into the provided `date` structure.Pointer to struct date (contains: da_year, da_day, da_mon).
void sound(unsigned)Starts the internal PC speaker at the specified frequency (in Hertz).Unsigned Integer (Frequency in Hz).
void nosound(void)Strictly shuts off the internal PC speaker initiated by a previous `sound()` call.```html
void delay(unsigned)Halts program execution for the specified time period (in Milliseconds).Unsigned Integer (Time in **Milliseconds**: e.g., 2000 = 2 seconds).
int int86(int, union REGS*, union REGS*)Invokes a specific BIOS/DOS interrupt, passing input and receiving output via register unions.Interrupt Number (e.g., 0x10 for Video), Pointer to input REGS, Pointer to output REGS.Integer Result (AX register content).
void settime(struct time*)Sets the current system time using the provided `time` structure contents.Pointer to struct time with new contents.
ℹ️ Essential Structures Defined within dos.h: Because dos.h accesses low-level hardware, it defines mandatory structures (like struct date, struct time) and unions (like union REGS, struct WORDREGS, struct BYTEREGS) required to parse register data and format system calls correctly. You must understand how these structures map to hardware registers for advanced BKNMU theory questions.
💻 Practical Code Examples & Application

1. Using gettime() to display the current time:

#include <stdio.h>
#include <dos.h> // Required for dos functions and struct time
#include <conio.h>

int main() {
    struct time t; // Declare variable of structure type time

    // 1. Retrieve current time from system BIOS
    gettime(&t); // Pass address of structure

    printf("Program Lifecycle Demo Starting.\n");
    // 2. Display specific members using the . operator
    printf("Current BIOS Time: %2d:%2d:%2d.%d\n", t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);

    return 0;
}

2. PC Speaker Sound and Delay Sequence:

#include <dos.h> // Required for sound and delay

int main() {
    int freq = 1000; // Frequency 1000 Hz

    // 1. Start sound from speaker
    sound(freq);

    // 2. Hold sound: 2 seconds pause (2000 ms)
    delay(2000);

    // 3. *Mandatory* Stop sound
    nosound();

    return 0;
}
🔄 Step-by-Step Flow: Accessing low-level DOS utilities
1

Step 1: Declare Header & System structures

The preprocessor loads #include <dos.h>. You declare mandatory structures (`struct time t;`, `union REGS r;`) required to facilitate communication with BIOS hardware.

2

Step 2: Initialize inputs & Function Call

You invoke the function (e.g., `delay(1000)` or `gettime(&t)`). The predefined function initiates a Standard BIOS Interrupt call (like INT 21H on DOS), suspending current process priority until the lifecycle event or resource is accessed.

3

Step 3: Hardware Interface & structure return

Precompiled binary code executes standard instructions, accessing PC ports, timers, or register maps, fulfilling the specific low-level request and returning control/formatted data (structure contents) back to your program pass.

💡 Special BKNMU Exam Tip on non-ANSI C: In your GTU/BKNMU theory paper or viva, remember: dos.h is NOT ANSI-compliant. Using it locks your program to MS-DOS hardware. For cross-platform system access, standard C alternative headers like <time.h> should be used instead!
⚠️ Critical GCC Portability Error: Forgetting the Platform! Do not attempt to use `delay()`, `sound()`, or `gettime()` inside modern compilers like GCC (VS Code, Code::Blocks) on Windows or Linux! This is the #1 mistake BCA students make. Those environments are not MS-DOS, do not support low-level register access via ctype, and dos.h functions will simply **fail to compile**. They are purely taught in early BCA semesters for low-level historical context in specific legacy lab setups.
📝 Quick Revision — Key Exam Points
  • Full Header Name: Disk Operating System (DOS) Header (dos.h).
  • Header Type: Non-Standard / Platform-Dependent legacy header (Specific to MS-DOS).
  • Valid Target Environment: Legacy Borland Compilers (Turbo C) running on MS-DOS.
  • Primary Applications: low-level Hardware Control, BIOS/DOS Interrupts, and Time/Date manipulation via specific REGS unions.
  • Core Functions: `gettime()`, `getdate()`, `sound(freq)`, `nosound()`, `delay(ms)`, `int86()`.
  • Crucial difference: Unlike <time.h>, dos.h gives direct access to PC-specific timers and speaker ports.
  • Portability fallback: Modern GCC environments do NOT support dos.h!

Post a Comment

Thanks for comment.

Previous Post Next Post