C Libraries

The second thing I want to note is that in producing this project, we have to cheat a little. The problem is that standard C does not have the functionality to provide things like memory mapped text output, nor coloured text and the like. In order to make C do what we want, we have to use some non-standard C functions (which Pelle was kind enough to include in the latest version of his C compiler). The functions which are not standard C are written with a leading dash, e.g. _gotoxy() or _textcolor(), (which we make use of). These non-standard C functions also show up as green in the Pelles C IDE.

Functions like this are not new to C compilers, however they aren't portable from one C compiler to another. Other C compilers may or may not have them, and they may or may not be called by the same name, let alone do the same things.

One of the great features of C is its portability. However, because of this, standard C can only do so much, as it obviously can't make use of machine dependent features, such as graphics hardware or sound cards, otherwise it wouldn't be portable. For this reason, we have to rely on extensions to C of one form or another to do what we want.

In this case, the key word is library. The non-standard functions we will use are included in a library (called conio.h) that we import into our C program and use, just as if it were standard C. Many C libraries exist and can be downloaded to add functionality to C. Some C compilers (such as Pelles C) come with a large array of built-in libraries which you can access.

In this project, we go one step further and write our own "library". This library contains all the declarations and the implementation of the assembly language for our emulated machine. Once the library is complete, it can be imported by other programs and used by them, just like the standard C libraries, which you have already met. So even though standard C is limited by the requirement for portability, it has the built in feature of being extensible, through libraries. (Actually, Pelles C takes this concept a step further and provides for libraries of a different type, which exist outside of the normal C paradigm and make use of a librarian. However this is a topic for another time, and being a very Pelles C specific issue, does not belong in an introductory C tutorial, so we will not cover that kind of library here.)