C99

From Ninerpedia
Jump to: navigation, search

c99 is a language for the TI99/4a written by Clint Pulley where you create a text file which is then converted to 9900 source code to assemble into 9900 object code.


The files were originally on one single sided single density disks, later on two which included some source files and some utilities.

Required

In order to write C99 programs you need an Editor, either the one supplied in the Editor/Assembler package or TI Writer(TIW). If you use TIW you must save the file by using the Print option and naming a disc file as destination. (This avoids the problems caused by the format information included. when you save TIW files in the usual way.).

Start with c99 source

The first step in writing a C99 program is to write the C99 source using an Editor and save it. As well as C99 source you can instruct the compiler to include other files and the library functions provided.

See the sample code below and note if you are inputting the text with TI Writer to save it using PF to disk and not SF to disk.

Compile the source to 9900 source

Your source code is now on a disk in D/V 80 format (see above).

Then using option 5 of the E/a module you run the c99 compiler. eg Editor Assembler Option 5, run program file C99C

C99C will ask you to key in some instructions.

Assuming we have source DSK1.TEST on disk as a DV80 file.

Let's keep it simple: answer n (or N) to the first two questions.

The compiler will now ask for input and output filenames.

Our C source was saved as TEST- remember! So that is our input filename.

Output filename can be anything you want...lets call it TEST/SO.

You will recall that TEST is going to make the compiler load CONIO from Disk 1. so make sure that the file CONIO is on a disk in drive one! and that the input file TEST is on the disk in the drive specified, and that the disk in the output drive specified has room on it for our output file!

Off you go. As the compiler is in action it will tell you what program it is compiling- so (main) will appear on screen.

When it has finished - quite quickly - you will have a 9900 Machine Code SOURCE file called TEST/SO, which must now be assembled using the TI Editor Assembler module.

One option is to include the C99 source in this assembly language file as comments.

Assemble to 9900 Object code

Having successfully created a 9900 source file and hopefully avoided errors, you now run the editor / assembler against the file you have just produced with the compiler.

The usual assembler options are available although you never need to specify the R option.

Select ASSEMBLE and indicate on the screen which appears:

Source file: DSKx.TEST/SO
Object file: DSKx.TEST/OB
List device: [press enter]
Options: [none- press enter with a blank here]

and off the assembler goes, producing a machine code object file which you can then run... or can you?

No. c-99 produces code which is incomplete. You need to 'add the end'
To run our test program, you must:
Select Editor Assembler Option 3 (or FUNLWRITER Utility Option 4).
Enter the first filename: TEST/OB
then a second filename... from the c-99 package: CSUP.

NOW you are ready to roll... press ENTER to move to the next item on the menu [PROGRAM NAME] and ask the computer to start running: START and off you should go.

You MUST always load CSUP after loading the object files produced by C.

You SHOULD always include either CONIO or STDIO in your C source code. STDIO is REQUIRED for file output.

To load the resulting 9900 object code

First it is necessary to load CSUP, a C99 support file, any other library files that may be needed (perhaps for file handling), and then load your object file. This is with the E/a option 3. The program name is always START in these programs. At this stage we can hope that our program works as expected.

Sample c99 source code

This is a simple listing, which just fills the screen with asterisks, one at a time.

Here is a BASIC form for comparison:

100 CALL CLEAR
110 FOR ROW=1 TO 24
120 FOR COLUMN=3 TO 30
130 CALL HCHAR(ROW,COLUMN,42)
140 NEXT COLUMN
150 NEXT ROW
160 CALL KEY(4,K,S)
170 IF S<1 THEN 160
180 IF K<>26 THEN 100
190 END

Why use key unit 4 in line 160? To maintain compatability with the c99 listing below where we use CTRL-Z to exit the program.

And now in c99:-

/* Malcolm's test program 1 */ 
#include dsk1.conio 
int row,col; 
main() 
{ while(1) 
{ row=0 
   putchar(FF); 
   while(++row<25) 
   { col=6; 
      while(++col<35)
      { locate(row,co1); 
        putchar(42}; 
      }
    }
   if(getchar()<1) break; 
  }
}

If you use TI Writer to prepare the code, you must save it WITHOUT the usual TI Writer tabs, by using PF DSK1.NAME instead of SF. Note the use throughout of lower case.

Notice that the variables row and col are DECLARED as INTEGERS before we use them. c99 uses a 40 column screen not the usual 32 columns of TI BASIC. Almost all lines terminate with a semi colon (;).

Anything between /* and */ is a comment or remark.

c99 does not have GOTO, we instead use while, which allows us to move to another section of code when the condition is no longer true.

The opening { marks the beginning of the command.

Provided the stack has a 1 in it when the program loops back to while(1=TRUE) then the loop is reentered, else you drop out ot it.

PUTCHAR places a single character on the screen - FF is predefined in the CONIO file as "form feed" which has the effect of clearing the screen and moving the cursor to top left.

++row<25 is the very short way that c99 says (row=row+1 :: if row<25 then...)

The double plus sign acts to increment the variable while locate merely locates the cursor. C99 is based on the 40 column screen

Incompatibility

C function files in DF8O form ready to load, which have been compiled by C99REL1 will not work with C99REL2.