I wrote and compiled my first Fortran program, the venerable Hello World program. Not surprisingly, it isn't long or complex, but the main purpose of the exercise was really to figure out how to write, compile, and execute a Fortran program. It was not a simple as I would have liked, but as the image shows, I did figure it out.
The first obstacle was just to create the program itself. OS/8 has two built-in editors, Edit and TECO. Both are line editors, that is, you basically work on a single line of text at a time. You have to set which line you're working with, then make your changes, then move to the next one. Fortunately, when you're creating a new file, you enter Append mode and you just type your text, so it's not much different than using a full-screen editor. But once you have to make a change, then the pain begins. I can see why programmers would write out their programs on paper forms first. Writing a program using a screen editor is a fairly interactive experience. You write some code, go back and make a quick edit, add lines in the middle, go to the bottom of the file and add a new function, return to where you started, etc. While you can do all this in a line editor, it is much more difficult. And Edit poses another problem: You can only work on one buffer at a time, and the buffers are only 3000 characters in length. So to move around in the file, for example, you'd have to write the current buffer, then read in the buffer that contains the location you want to go to.
I also ran into a bit of a problem with Edit on simh, specifically with keyboard mapping. Edit has two modes, Command and Edit. Command (designated by a leading # on the line) let's you do stuff like save/load buffers, delete lines, etc. Edit mode is for entering text, and obviously it treats whatever you type as text to be saved in the file. When you're done entering text, you have to switch back to Command mode, and according to the OS/8 handbook, you do this with the Ctrl-FORM key combo. But there is no FORM key, of course. I tried Ctrl with a bunch of keys - Home, End, Delete, etc. - but none of them worked. I finally found a blog Editing Files on a PDP-8 Using OS/8 EDIT where the guy was doing a lot of what I'm doing now, playing with OS/8 using the simh emulator. It was here that I found out that Ctrl-L will switch from Edit to Command mode. I'll probably start taking a look at TECO to see if it's any better.
It was actually trying to figure out Edit that took me the most time in getting my HELLO program to run, but it wasn't the only issue. The aforementioned blog also had a very nice post on writing Hello World in Fortran, including going through the steps of compiling and executing the program, but unfortunately this turned out not to work on my system. OS/8 has a command called COMPILE that, as you might have already guessed, compiles programs. But this command isn't specific to Fortran - it compiles any of the native OS/8 languages: the three or four assembly languages; Fortran II; and Fortran IV. It uses the source file's extension to figure out what actual compiler to invoke, and then runs it through the whole chain of programs (Fortran IV, for example, uses four or five separate programs to do a full compilation). But I recall reading in the OS/8 Handbook that the COMPILE command will only work if the compiler was installed at the time the system was setup. As the blogger indicates, his Fortran was not working when he first tried it, so he had to go and install it manually on his OS/8 system. So I assume this is why COMPILE did not work for him. Instead, he had to invoke the Fortran compiler directly using the command, RUN F4. So I did this, and while the command itself gave me no errors, the resulting HELLO.LD file would not run as his did when I did, EXECUTE HELLO. But my COMPILE did work, and it generated a HELLO.RL file which did work with the EXECUTE command, as shown above.
So I got the basic steps down, which means I can move on to actually writing my game. And on that front as well I have a little news - I have decided to write Hammurabi. For those who aren't familiar with it, this is a pretty simple game (usually written in BASIC) where the player has to rule a small kingdom, feed his people, plant crops, and try and keep everyone from starving (usually eventually failing). I remember having a lot of fun with it back in the day when I was a teenager. Unfortunately, it really does have a pretty simple strategy, and you'll either win or lose based mostly on luck. But I'm hoping to add features that will change that while hopefully still maintaining the essence of the game. But first, I just want to implement the basic game, so that's next.
No comments:
Post a Comment