Thursday, November 10, 2022

Apple IIe - Apple FORTRAN - It's an odd language and HELLO, WORLD!

Known as FORTRAN (FORmula TRANSlating system, FORmula TRANslator, or possibly FORmula TRANSlation), is an early programming language known for it's use in numerical computation and scientific computing. 

Statement Format

It's an odd language that has a statement structure that reflects it's original representation on 80 character punch cards. 


Columns 1 to 5 are reserved for line numbers.

Column 6 is reserved for the line continuation character, an asterisk (*). 

Columns 7 to 72 are for programming statements. Unfortunately, a TAB will move you to column 9 instead of 7. I suggest just using the TAB key and waste columns 7 and 8.

Columns 73 to 80 were originally used to write comments, like line number to keep your cards in order. They are ignored by the compiler.

If your statement must extend past column 72, you continue on the next line by putting an asterisk in column 6 and then continue typing your statement in column 7. 

If you deviate from the column format above, your program will not compile.

Variables

Variable names must begin with the letter A to Z, followed by letters and/or the digits 0 to 9, and are limited to six characters. For example, FOOBAR, FOO999, FOR, and NEXT are all valid variable names. 9BAR, F$$BAR, ME&YOU, and THISISALONGNAME are invalid variable names.

Reserved Key Words

There are none! Key words are recognized by their position in context of the statement. 

The First Line

The first line of your program must be six spaces followed by the word PROGRAM starting in the seventh column, followed by a space, and then the name of the program. The name of the program must be a valid variable name. In fact, you cannot use the program name in the program as a variable name.

The Last Line

The last line of your program must be he word END starting in the seventh column followed by a single press of the RETURN key. The editor will place the cursor on the line immediately below the "E" in the END statement. If you move remove spaces or insert anything past this position, your program will fail to compile.

Numbers, Strings, Assignment Statements, etc.

Instead of reinventing the wheel here, I'm going to refer you to the following book - Learning Apple Fortran by Donald J. Geenen. The information above and more along with examples can be found here. 

Editing a Program

Let's type in the classic hello, world! program.

Put your FORT1 and FORT2 disks into your Apple IIe and start it up. Or, start AppleWin or some other emulator. You can find the disk images you need on the internet. 

You will see the command program running at the top of your screen.

Command: E(dit, R(un, F(ile, C(omp, L(ink, X(ecute, A(ssem, D(ebug,? [1.1]

Type "E" to enter the editor. If you get the error "No file :SYSTEM.EDITOR", try again. I think the emulator forgets to read the disk?

The editor program will start and load whatever text you have in the SYSTEM.WRK.TEXT file. SYSTEM.WRK.TEXT is the workfile used by the editor as a disk buffer file. 

If you are sure you want to start with a new file, before starting the editor, start the filer program and create a new workfile by typing "F" from the command line, then "N". You will be prompted to throw away the current workfile. Type "Y". The workfile will be cleared. Exit the filer by typing "Q" to quit and return to the command program. After clearing the workfile and restarting the editor, you will be prompted "No workfile is present. File? (<ret> for no file <esc-ret> to exit ):".Type RETURN.

Now, you are ready to edit your program. You would be forgiven for thinking you could just start typing. The editor does not work the way you're accustomed. It's more like a primitive version of VI. At least you're not working from a teletypewriter with ED. ED is a single line editor.

>Edit: A(djust C(py D(lete F(ind I(nsrt J(mp R(place Q(uit X(chng Z(ap  [1.1]

You need to put the editor into insert mode by typing "I". The command menu will change to:

>Insert: Text {<bs> a char, <del> a line} [<ext> accepts, <esc> escapes]

You can now start inserting your text. If you backspace, you will move the cursor back, erasing your text as you move back. Type CTRL+C to leave insert mode and save the text you entered into the program buffer. This is not the same as saving it to the workfile. It just puts the text onto the screen. If you flub it up and want to escape, losing the text you entered after moving into insert mode, type the ESCAPE key.

Remember, your first line needs to be six spaces, the word "PROGRAM" a single space, and the program name. If you mistype, just press backspace until you get back to where you can retype.

>Insert: Text {<bs> a char, <del> a line} [<ext> accepts, <esc> escapes]
      PROGRAM FOOBAR

If you need to edit text in a particular position, while not in edit mode, use the cursor keys to move to the desired location, then switch to insert mode.

Let's say we changed our mind and want the program name to be "HELLO" and not "FOOBAR". Move the cursor with the arrow keys to the "F" in "FOOBAR" and type "I". It will look like something has gone seriously wrong. The text "FOOBAR" will shift way over to the right hand end of the screen, leaving a huge amount of space between the cursor and the text "FOOBAR". The editor is just giving you room to type.

Type "HELLO" and press CTRL+C. The screen will move the text "FOOBAR" back next to "HELLO" resulting in:

>Edit: A(djust C(py D(lete F(ind I(nsrt J(mp R(place Q(uit X(chng Z(ap  [1.1]
      PROGRAM HELLOFOOBAR

Now, you need to delete "FOOBAR". If it isn't already there, move the cursor to the "F" in "FOOBAR" and type "D" to enter delete mode.

>Delete: < > <Moving commands> {<etx> to delete, <esc> to abort}
      PROGRAM HELLOFOOBAR

Type several spaces. As you type, the characters in "FOOBAR" are replaced by spaces. Type CTRL+C when you have finished removing "FOOBAR".

>Edit: A(djust C(py D(lete F(ind I(nsrt J(mp R(place Q(uit X(chng Z(ap  [1.1]
      PROGRAM HELLO

This sounds tedious, and I suppose it is. You'll get used to it, or not. Welcome to vintage software development!

Type in the rest of the program. Remember to properly enter the "END" at the end of the program. I'll add a column header to help line it up.

         1         2         3         4         5         6        7         8
12345678901234567890123456789012345678901234567890123456789012345678901234567890
#####*SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSCCCCCCCC
      PROGRAM HELLO
100   FORMAT (A)
      WRITE (*, 100) 'Hello, World!'
      END

Your program in the editor should look like the following. Notice how the cursor is placed directly under the "E" in the "END" statement. 

Type "Q" to quite the editor. You are prompted with the following choices:

>Quit: 
     U(pdate the workfile and leave
     E(xit without updating
     R(eturn to he editor without updating
     W(rite to a file name and return
     S(ave with same name and return 

Type "U" to update the workfile and leave the editor back to the command menu.

Compile and Run a Program

Now that we have our HELLO program ready, let's run it. The easiest way to accomplish this is to simply type "R" from the command menu. Your program will be compiled, linked, and run.

Compiling...
Listing file? 

You are prompted for a listing file. If you want to learn more about the compiler, please reference the book Learning Apple Fortran by Donald J. Geenen or the Apple II FORTRAN Language Reference Manual. For now, just press the RETURN key.

If you have an error in the program, the compiler will show you the error number and the line the error occurred on. Press the SPACE key to force the compiler to continue, ESCAPE to terminate compilation, or "E" to edit the program. The error is displayed at the top line of the editor. Press SPACE to edit and correct your code. If you look at the listing from the screen shot above, you may notice a double-quote at the end of the HELLO, WORLD! text instead of a single quote.

If everything goes well, and you have no compiler errors, your program will compile. Once compilation has finished, the linker will run to link your program to the necessary libraries, and then finally, it is run.







Type "Q" to quite.

Saving your Program

You could finish her. However, your HELLO program source is stored in the workfile SYSTEM.WRK.TEXT and the executable in SYSTEM.WRK.CODE. Not the most convenient place. If you followed my post Apple IIe - Apple Fortran/Pascal 1.1 - How to Format and Name a Disk, you should have a blank disk named "FCODE". 

Start the filer program by typing "F" then replace disk "FORT1" with your "FCODE" disk. Type "T" to start the Transfer program. You are prompted "Transfer ?". Type in SYSTEM.WRK.TEXT and press the ENTER key. You are prompted "To where ?". Type in FCODE:HELLO.TEXT and press the ENTER key. If you have done everything correctly, you will see:

Filer: G, S, N, L, R, C, T, D, Q [1.1]
To where ? FCODE:HELLO.TEXT
FORT1:SYSTEM.WRK.TEXT
 --> FCODE:HELLO.TEXT

If you could check to see by listing the files on the FCODE disk. Type "L" to list files. You are prompted "Dir listing of ?". Type in "FCODE:" and press ENTER (without the double quotes). The colon indicates you want a disk listing.

Dir listing of ?
FCODE:
DEMO.TEXT           4 25-Jan-99
DEMO.CODE          26 25-Jan-99
SIREN.TEXT          4 25-Jan-99
SIREN.CODE         26 25-Jan-99
SIREN2.TEXT         4 25-Jan-99
SIREN2.CODE        26 25-Jan-99
GALLNS.TEXT         4 25-Jan-99
GALLNS.CODE        26 25-Jan-99
HELLO.TEXT          4 25-Jan-99
9/9 files, 150 unused, 133 in largest

Now, copy over the CODE file with your executable program. Follow the directions about substituting "TEXT" with "CODE". 

Dir listing of ?
FCODE:
DEMO.TEXT           4 25-Jan-99
DEMO.CODE          26 25-Jan-99
SIREN.TEXT          4 25-Jan-99
SIREN.CODE         26 25-Jan-99
SIREN2.TEXT         4 25-Jan-99
SIREN2.CODE        26 25-Jan-99
GALLNS.TEXT         4 25-Jan-99
GALLNS.CODE        26 25-Jan-99
HELLO.TEXT          4 25-Jan-99
HELLO.CODE         26 25-Jan-99
10/10 files, 124 unused, 107 in largest














No comments:

Post a Comment