Tuesday, 17 April 2012

Pascal Programming on the Atari ST

Here's a strange feeling... I have the feeling that I've just done something unique for the day today... I think no-one else on this planet was coding Pascal on an Atari ST today... But I was...

I watched a video where by one of the tenants to meet in order to consider yourself a programmer was to know five languages fluently (that's computer programming languages folks, not GCSE French or German).

My considerations for my five languages are C++ (and therefore C), C#, Java, Pascal and Perl.  The latter I'm fairly rusty on, I only did one major task on it and that was a while back, so I'm going to have a look back later.  The C family and Java I use all the time... So this left Pascal.

I always put Pascal down, its on my CV, its one of the first languages I ever learned, its certainly the first language I actually coded and put through a compiler and linker (rather than just interpreting), I learned it in Turbo Pascal for DOS and my first job after leaving university was to work in Delphi (a derivative of Pascal) coaxing some legacy systems of my employer from Delphi to Borland C++ Builder standard code.

But that was a LONG time ago.  Over a decade.  So I took a step back and looked around for a copy of Turbo Pascal (I own one so it was around somewhere) but all I found was a broken zip file and a few 16bit applications I could not run on any of my current machines.  My old Laptop (the one my brother had stolen in a house burglary about eight years ago) had it all on it, so its gone... What Pascal/emulator/virtual machine do I have which I can work and reference and remember?  And you'll never believe where I ended up.

I ended up with an Atari ST emulator and making an image of the ST Format cover disk with Personal Pascal upon it.

My first task was to extract the Cover Disk LZH file - which took oh sooooo long.

Then I set up my desktop and got used to the interface again.  I love my Atari ST, I have the real machine under my desk and software still hanging around.

So, I'm using Hatari, compiled under gcc running on ubuntu for this work...

The challenge I had then was to pick something to actually do, I chose a simple application I have on the back burner for an item on GetACoder which I've bid on, and started to port the code from C# to Pascal...

The first thing I realized was how little infrastructure, or helpful, code there is in Pascal, you have to declare everything procedurally, my brain is very much object orientated.  So thinking procedurally rewired a whole bunch of connections in my brain... Then I had to remember how to use pointers in Pascal... I remember fighting with this before (when I was 16) but now, with years more experience I breezed through the logic and the allocation and disposal of resources.

The application was back together pretty quickly... except... I had a couple of bugs, the first bug I had was that in the iterator passing down the linked list of integers at each row in the code it was not referencing the correct "next" pointer.  So I had an infinite loop... doh.

But, oh my god, what a ball ache to debug it.  There is no debugger in this free Pascal compiler/linker, so debugging I was reduced to the level of primitives...

Putting in writeln statements looking where the code went wrong, instead of calculating values on the fly I was having to declare variables for them write them out to the screen and check their value visually as I let the program move between readln statements... Utter total ball ache.

But in the end the program was running...

(Don't worry about the negative values, thats just the 16bit integers rolling over a lot earlier than they do in my 32bit implementation).

The code, I'll post another day for you folks to enjoy... But this little foray into ST nostalgia did one of two things... firstly, finding these bugs in the code made me become very intent on the software as it left my fingers, far more intent on making sure its correct than I am with modern systems - where a quick compile helps find what's going wrong where - in the ST to compile this trivial code was a lengthy operation - taking up to a minute to compile and link alone - this changed my approach to the code, I was attentive, nurturing and double checking at each step making sure the logic was perfect that simple typo's and spelling mistakes were not made... I missed code complete terribly, but this lack of functionality pressed me to be a better programmer.  I had to remember what I was doing, where and when, I also have to think about the names of the functions and procedures I was laying down and remember their names, names which I had made meaningful.

All in all, to this point the coding has been a successful exercise.  Helping me refresh my knowledge and count my blessings working as a developer today.  On some levels I miss this kind of coding, closer to the machine, down near the bare metal, but in many more respects I thank progress for the innovations of modern development environments.

The absolute weakest thing about the code I produced on the ST however was that, because editing was such a chore, because there is only limited memory (1 megabyte) and that to have to strip the code down for compilation comments would take extra memory space, I simply ceased commenting my code.  I suddenly understand how frustrating some of the code problems I dealt with as a Millennium Prep manager really must have been for the folks I kept whipping into a frenzy.


  1. hey check this new website www.countcode.com. It's a social network made for programmers, where you can download,share or upload source codes, where you can count your own code lines for free. You have access to the web forum and the web chatroom. we are happy to have you joined to our community!

  2. Counting lines of code is counter productive, and though I hate to quote him, Steve Balmer has is right on when he says "Counting lines of code is no measure of productivity, just because someone has done something in 4KLocs, which took me 20KLocs does that mean he should be paid less?"....

    (See Triumph of the Nerds - Robert X Cringley - "Riding the Bear").