Difference between revisions of "C99"

From Ninerpedia
Jump to navigation Jump to search
(add name of programmer who produced c99)
(→‎Sample c99 source code: add further description of sample code)
Line 24: Line 24:


==Sample c99 source code==
==Sample c99 source code==
This is a simple listing, which just fills the screen with asterisks, one at a time  
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 */  
  /* Malcolm's test program 1 */  
Line 44: Line 60:
  }
  }


Notice that the variables row and col are DECLARED as INTEGERS before we use them.  
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.  


PUTCHAR places a single character on the screen - FF is predefined in the CONIO file as "clear screen and home 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
The double plus sign acts to increment the variable while locate merely locates the cursor. C99 is based on the 40 column screen


[[Category:Programming language]]
[[Category:Programming language]]

Revision as of 17:27, 17 October 2014

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.

Compile the source to 9900 source

Then using option 5 of the E/a module you run the c99 compiler. This writes 9900 assembly language source statements to a file of your choice.

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

Assemble to 9900 Object code

Having done this and hopefully avoided errors, you now run the 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.

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