Getting Started with the DJGPP Compiler

Get on a PC with the DJGPP compiler. You can install the compiler on your own computer by getting the following files:

    djdev203.zip
    bnu2112b.zip
    gcc2953b.zip
    gpp2953.zip
    mak3791b.zip
    txi40b.zip
    faq230b.zip
    gdb500b.zip
    csdpmi5b.zip  (needed for DOS OS only)
    rhide1478b.zip  (integrated development environment)
You can get these files from http://www.delorie.com. Make a directory for DJGPP (say, C:\DJGPP), and use WinZip or another program to extract the files from the zip archives into your DJGPP directory. Add C:\DJGPP\BIN to your path, and set the environment variable DJGPP to C:\DJGPP\DJGPP.ENV:
    PATH=%PATH%;C:\DJGPP\BIN
    SET DJGPP=C:\DJGPP\DJGPP.ENV
You will then be able to use the gcc compiler. Enter the following program hello.c using a text editor:
    #include <stdio.h>

    main()
    {
        printf("hello, world!\n");
    }
Compile the above program with the following command:
    gcc -o hello hello.c
You should have a file called hello.exe. Run by typing hello on the command line. This may not work in DOS. DOS needs something called DPMI to allow the use of 32-bit programs with the 16-bit DOS operating system. If the above programs (gcc or hello) will not run, install the DPMI server cwsdpmi with the following command:
    cwsdpmi -p
and try compiling and running hello again.

Instead of using gcc as a command-line compiler, you may use the Integrated Development Environment RHIDE if you prefer. This will give you access to an editor, the compiler and a debugger all in one window. Just type rhide at the command line prompt, enter the program using the editor, and use the pull-down menus to compile and run the program.

Here is a program status.c to read the status of LPT1:

    #include <stdio.h>
    #include <pc.h>

    #define P_STATUS 0x379

    main()
    {
        int status;
    
        status = inportb(P_STATUS);
        printf("status = 0x%02x\n",status);
    }
Compile the above program with the command
    gcc -o status status.c -lpc