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:

    djdev201.zip
    bnu281b.zip
    gcc2721b.zip
    gpp2721b.zip
    lgb271b.zip
    mak3761b.zip
    txi390b.zip
    csdpmi4b.zip
    faq210b.zip
    rhide14b.zip
    unzip386.exe
You can get these files from http://www.delorie.com. Make a directory for DJGPP (say, C:\DJGPP), and use unzip386.exe 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. 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