Wednesday, 22 May 2013

Turbo Pascal 3 revisited

For some reason thoughts popped into my head of an old program I wrote to produce a Lissajous figure on the screen, in Turbo Pascal 3 back in the 1980s. This is done by plotting X and Y coordinates from two independently running sine waves.


At the time it ran very smoothly and impressively fast (I thought!) on my old DOS box - a gloriously primitive twin-floppy box with a mono CRT and IIRC it didn't even have a full 640k of RAM - and sat there rotating gracefully like a trace on an oscilloscope.

Looking at the file date it looks like I played with it again in 1995, and I vaguely remember it had sped up a bit on a more advanced Win 95 box, hehe.

Here's the code, FWIW - note the repeat.. until 1=2 will require Ctrl-C to break out :)

program liss;
VAR px, py : Real;  { phase in rad X,y-axis }
VAR ox, oy : Real;  { phase in deg X,y-axis }
    stepy : real;
CONST  ScXs = 38;  { Scr X Size }
       ScYs = 10;  { Scr X Size }
       StepX = 0.1;
begin
  StepY:=StepX/2.06;
  textColor(15);
  ClrScr;
  Px:=0.0;
  py:=0.0;
  ox:=-(StepX)*130;
  oy:=-(StepY)*130;
  Repeat
    ox:=ox+StepX;
    oy:=oy+StepY;
    If ox>6.2831 THEN ox:=ox-6.2831;
    If oy>6.2831 THEN oy:=oy-6.2831;
    GotoXy(Trunc(41-(SIN(oy)*ScXs)), Trunc(13-(SIN(ox)*ScYs)));
    Write( ' ');
    px:=px+StepX;
    py:=py+StepY;
    If px>6.2831 THEN px:=px-6.2831;
    If py>6.2831 THEN py:=py-6.2831;
    GotoXy( Trunc(41-(SIN(py)*Scxs)), Trunc(13-(SIN(Px)*Scys)));
    Write( 'þ');  { use block character obtained by
                    holding ALT and typing 2 5 4 on the numeric keypad }
  until 1=2;
end.
Needless to say, on modern kit it runs like lubed lightning, comparatively - even without XP's ALT+ENTER full screen textmode. I even tried it in DOSBox for a laugh - rather more slow there.
To install and play with TP v3, it can be downloaded (ZIP) free of charge from the copyright holders (seeing as it's an antique!) from here : https://downloads.embarcadero.com/free/turbopascal

I found a PDF manual at bitsavers.informatik.uni-stuttgart.de

I used 7zip (FOSS) to unzip the download into C:\DATA\TP\ and had a blast from the past. I can still remember Crtl-KB and Ctrl-KK to mark text, Ctrl-KC to copy, Ctrl-KD to exit :)

In fact, I still used turbo.com as a text editor for years, even when we moved on up to Metaware's Pro Pascal. It was handy for general text file use, until the 64k file size limit started to get in the way, and then I moved on to Win32Pad as it was easier than NotePad to retain my familiar DOS-like white-on-black colour scheme. From there I migrated to Notepad++ for coloured syntax.

TURBO runs in B&W mode at first, and you will need to set the TINST.MSG and TURBO.COM files to ReadWrite (if the unzip process sets them ReadOnly) before you'll have any luck setting the colour mode to 80x25 colour using the installer TINTST.COM

In this day and age I suspect that Pascal newcomers tend to go straight to FreePascal and the Lazarus IDE, but this old clunker would certainly be one way to start from the BEGINning :)

Workflow Automation


Another little program of mine was a working environment like this :


This was back in days of 8.3 filenames, and even with Win95 I still worked at the command line. So I rigged up this code to present pages of directory contents in alpha order, with the arrow keys moving the tab-card shaped surround around the files. I could tab between two different folders and selected files. At the push of a button I could do whatever I needed with the selected file - edit, launch all the usual batch files to compile, link, check in/out from version control, etc.

It was launched with two quick almost-adjacent keys because I found I could call a batch file '.bat - single quotes are valid in a DOS filename. The batch called my turbo pascal .com program, and that in turn rewrote the same batch file that had called it.. while it was still running! Odd, perhaps, but it worked well so long as the folder and filenames within the batch were padded with trailing exclamation mark characters so that the batch was always the same size with everything in the same place - otherwise poor old DOS got a bit confused by the mid-run rewrite :)

My turbo .com program launched further processes by adding the command to the end of the '.bat and then exiting - one batch file chained into another (no 'call' command with two batches in memory at once) so as much memory was available for compiling as if I'd typed the command at the prompt directly. This was vital when memory was at a premium and sometimes I had to be really careful to optimise my code to get things to compile! It all worked like a charm and made life a lot easier. I do enjoy harnessing the power of lazyness to make life easier.

Those were the days! Not sure I'd want to go back though, to be honest :)

No comments:

Post a Comment