Turbo Pascal

Towers of Hanoi
Runtime Error 200
Pascal Programs
Installation
Object Oriented Programming
Problems with graphics ?
Students' Corner
Blaise Pascal
Free Lisp Interpreter


Towers of Hanoi

The game of Towers of Hanoi can be used to demonstrate the power of Dynamic Programming. For more see the document in my page giving the number of different solutions to the game. To check the formula I have written programs in Turbo Pascal 7 that generate the solutions in a text file, check whether the solutions are all different and simulate them to check whether they are correct. If you want you may download these programs. All should be clear from comments in the source files and the document mentioned above.

Go back to Heading
Quit to Home page


Runtime Error 200

Applications that use the CRT unit may generate this error message when running on very fast machines (like Pentium 300). The cause of this error is a timing loop that occurs as part of the initialization of the CRT unit. This timing loop counts how many clock ticks occur within the loop and then that number is divided by 55. The result of this division is a value that is too large to fit into an integer value. The 'Divide by 0' error message is the catch-all error that is displayed when this overflow occurs.

Borland (called INPRISE now) currently does not offer any patches to solve this problem. Fortunately, there are programmers who do. I have downloaded one written by Dennis Passmore and it works perfectly. The patch contains a program, that modifies the original files TURBO.TPL (and TPP.TPL for protected target) from \BP\BIN. In case of Turbo Pascal, only TURBO.TPL from \TP\BIN is modified. Dennis gave me a permision to use it, so you can download the two updated Pascal files New TPP.TPL & TURBO.TPL.

So if you have the same problem, download the new files and follow these instructions:

Go back to Heading
Quit to Home page


Pascal Programs

Turbo Pascal is not the first choice of system programmers, because in C and C++ you can write generally faster and shorter programs. Nevertheless the difference is not big (mostly negligible), so for most of us there is in fact no need to leave the comfortable Pascal programming. Turbo Pascal compiler is incredibly fast (on my old 486 Dx 33MHz I build (recompile) and link a program made of about 12000 lines in 20 sec). Clear structure of Pascal programs with no side effects and its direct access to all computer resources make it an ideal tool for everything from introduction to programming to advanced system programming where the time critical sections may be expressed by in-line assembly language instructions.
To make it even more useful, it is necessary to add mouse control and some commonly used routines like switching on/off the text cursor, drawing boxes in text mode, converting strings to upper/lower case, etc.
If you have Turbo Pascal 7 you may download these files:

exdbase.zip is a simple database application. Learn how to work with typed files and basic file management.

showcloc.zip contains a procedure that displays time on the text screen when running a program. It is a simple multitasking (that is generally not supported in MS DOS environment). The program shows how to take control over the timer interrupt and use it to update time on the screen.

mouse.zip mouse control.

others.zip various useful facilities like a general frame for Turbo Pascal graphics, some general routines like converting strings to upper/lower case, recursion (Hanoi towers), etc.

datastru.zip examples on data structures (A-level Computing).

search.zip examples on searching (A-level Computing).

sorting.zip examples on sorting (A-level Computing).

Note that the main objective when writing all the programs was simplicity and readability, not speed and memory saving.

Go back to Heading
Quit to Home page


Installation

All Turbo Pascal programs that you download from this page are zipped directories. To expand them you need the program pkunzip.exe. It is available in most shareware libraries - try for example Garbo. To expand, copy the file you have downloaded (for example the file mouse.zip) and pkunzip.exe to some directory. Then you have two options how to expand:

pkunzip -d mouse

creates a subdirectory (in this example MOUSE) in your directory with all the files.

pkunzip mouse

does not create any subdirectory, all files are placed to the current directory. Most directories contain files called readme.pas with more details.

Do not hesitate to contact me in case of any troubles.

Go back to Heading
Quit to Home page


Object Oriented Programming

A-level Computing and similar syllabi are based on traditional Structured Programming. Some (like International Baccalaureate and Advanced Placement Program) contain introduction to Object Oriented Programming (OOP), that represents an alternative to the traditional methods. This text is intended as a first simple introduction to the main principles of OOP for students of A-level Computing and similar courses.

These are the most commonly accepted features of OOP:

1. The algorithm or system dynamics is expressed in terms of objects (actors) that exist in parallel and that interact with each other. Every object is represented by:
- attributes (also called internal attributes or value attributes)
- methods (also called actions or procedure attributes).
Objects can interact in these ways:
- direct access to attributes
- mutual calling of methods.
Simply speaking: Object = Data + Procedures that is called Encapsulation. Very often the object's data or a part of it is hidden and values can be accessed and modified only through (well defined) methods. This concept is called Information hiding.

2. Similar objects (actors) are grouped to the so called classes also called prototypes. A class describes objects that have the same attributes and methods. A class declaration is interpreted as a pattern. It is possible to create any number of individual objects (actors) called object instances. Instances may differ in values of their attributes. It is necessary to make a clear difference between a class as such and object instances generated according to the class declaration. A class can be also interpreted as a knowledge of certain type of objects. Such knowledge is represented by a data part and by operations that can be performed on the data.
Note: In Turbo Pascal (and also some other OOP languages) classes are called "objects". This has been fortunately corrected in Delphi, that uses the correct term "class" (by the way this term was first used in this context by the Simula language 30 years ago).

3. Objects can be classified hierarchically by the so called inheritance (that is maybe the most important principle of OOP supporting creation of object libraries based on reuse of code at lower levels of hierarchy). Very often the term subclass is introduced. A subclass Y of a class X inherits all attributes and methods from the class X. Its declaration can add any number of additional attributes and methods. A subclass can be used as a parent class of other subclasses, etc. A subclass may be interpreted as a more detailed knowledge than the one defined by the parent class. So the parent class represents a general knowledge, that may be further specialized by declarations of subclasses in any number of steps. Typically it is possible to declare reference variables that may refer to an instance of certain class and to instances of all its subclasses. It might be desirable, that certain methods then behave in different way according to the current object instance being referenced, that may change dynamically during program execution. This concept called polymorphism is supported by the mechanism called late binding and the methods involved are called virtual methods, that may change at every level of hierarchy.

Download the following two files that both contain units with objects and demo examples of their use. Read the comments in the programs, to learn principles of OOP. You may find both units useful in your projects.

oopwint.zip Windows in text mode.

oopwing.zip Windows in graphics.

Go back to Heading
Quit to Home page


Problems with graphics ?

Too often I have heard this question: "My program with nice graphics works at school, but not on another computer. What is wrong ?".

There are two cases:

I. First let's assume, that the other computer has Turbo Pascal 7 installed (the version is important - if you have old programs, recompile them in TP7 environment). There can be three things wrong:

1. Corrupted BGI and/or CHR files.
2. Wrong directory parameter of the InitGraph procedure. Note, that Turbo Pascal may be installed in other than \TP directory (e.g. \TP7) and note also the difference between C:\TP and C:TP.
3. Not enough memory to load BGI and CHR files - make sure that the heap capacity when initializing graphics and loading a stroked font file is sufficient.

II. The other computer does not have Turbo Pascal. There are two ways to make the EXE file with graphics working:

1. Transfer the EXE file together with the BGI file and CHR files and make sure they are in the proper directory - the same that is used in InitGraph call.
2. Convert the BGI file and the CHR files into the OBJ format and link them to your program. Your EXE file will then work on any PC with the graphics card compatible with your BGI file (practically all PCs in case of EGAVGA.BGI file). You can download the linkgr.zip file that contains a unit with procedures that load and initialize graphics together with all standard OBJ files you will need.

Do not hesitate to contact me if the above still does not help.

Go back to Heading
Quit to Home page


Students' Corner

This place is reserved for students who wrote interesting programs and who are willing to share their experience with others. All programs included here are free ware. Download them to learn some less trivial Turbo Pascal programming. If you have interesting program(s) and are willing to offer them to others, contact the author of the page. Your contribution will be very appreciated. So here are the students who have so far contributed to this "program bank":

My friend Tamer Fakhoury wrote a unit that demonstrates the use of object-oriented programming when solving bitmap management problems. Features include the following:

  • Support for compressed/un-compressed windows bitmaps
  • Support for 4,8, and 24 bit windows bitmaps
  • Support for Bitmap Palette Extraction
  • Error Diffusion
Limitations (to be removed soon):
  • Image size must be less than 65K
Download the file bitmaps.zip that contains the unit source file.

Sven Neumann (KILLROY) is a brilliant programmer interested especially in very fast graphics and animation (for this he wrote his own units in assembly language). Here you can download several programs that show nice animation and keyboard control in text mode (hanoi.pas) and impressive fast 3D graphics animation based on direct access to video memory. (When compiling PAS files switch range checking off.) Don't hesitate to contact Sven for more information.

During Labs, I have collected some programs with nice graphics. They are left (some without indenting) as they were written. When compiling, leave the range and overflow checking off. I don't know (full) names of authors - so it might happen, that you find your program here. In this case contact me, to add info about the author.

Go back to Heading
Quit to Home page


Free Lisp Interpreter

Andrew Duncan (now student of the University of Malta) has developed a Lisp interpreter in Turbo Pascal called Quicklisp as his A-level project, and is willing to make it freeware. He believes - and he is right - that the more users, the quicker bugs can be found.

Quicklisp is a simple Lisp interpreter which is ideal for learning the Lisp language, the basics of AI, symbolic computation and functional programming generally. For example it might be a suitable tool for A-level tutors. Its features include:

Full commented source in Pascal is included which will compile on TP7 (real mode) or BP7 (DPMI - allows larger programs). Please send a description of any bugs found to adun001@um.edu.mt so that that they can be fixed in the next version. Of course contact Duncan if you have any problems and/or questions.

You can download Quicklisp now.

Go back to Heading
Quit to Home page


This article is translated to French language by Vicky Rotarova.