TIC step by step
TIC step by step
That link is what put me on Al's trail: there're only a few Beards in Franklin, MA.
Doing a straight "hello, world!" is a bit hard, because there is no standard library with printf in it; even a simple printf is 1..2 KB. Instead I have simple program that tests both input and output.
So, start with the following file, and call it 'test.c':
Code:
char s[81];
main()
{
while( gets(s) ) {
puts(s);
putchar('\n');
}
return 0;
}
This gets a string from the keyboard (and accepts editing with backspace, ctrl-h) and then prints that same line back to the user. If you type a ctrl-z the program exits (see the C99 manual for details, I used those routines as a basis). Compile this C program with TI-C to an assembler file:
TI-C will place the output in a file called 'test.S'. Now assemble this file to an object file:
Code:
./asm990 -o test.obj test.S
The runtime routine is supplied with the source and is called crt0.S. Also assemble the runtime routine to an object file (of course you need to do this only once, the resulting object file is the same for all projects):
Code:
./asm990 -o crt0.obj crt0.S
Next link the two parts together, taking care that crt0.obj comes first.
Code:
./lnk990 -o final.obj crt0.obj test.obj
The resulting 'final.obj' file is ready for downloading to the breadboard, were it not for the fact that it expects an object file with '\r' line endings and what we have produced has '\n' line endings (on linux and osx, haven't tried on windows). This can be fixed by a little tool 'flip':
Code:
./flip <final.obj >final.lmc
The 'final.lmc' file can be downloaded to the breadboard, using the LMC command. For that, reboot the breadboard, type 'A' to get the start-up menu and select '1' from that menu for EVMBUG. At the MON? prompt, type (note the use of uppercase):
EVMBUG will respond with 'Are you ready (Y/N)?' and type Y (again this has to be an uppercase Y). Now tell your terminal emulator to send the file 'final.lmc' to the breadboard. Once the file has been received, set the internal registers using the IR command:
Code:
MON? IR
WP ???? F000
PC ???? 8000
ST ???? 0
After typing each register value, end with a space to move to the next register, the enter key finalizes the command. Finally the progam can run, using the 'EX' command:
If all went well the code should run as expected.
Note (1)
The source code for the 'flip' build tool is:
Code:
#include <stdio.h>
int main()
{
char c;
while( (c = getchar())!=EOF ) {
if( c==0x0a )
c = 0x0d;
else if( c==0x0d )
c = 0x0a;
putchar(c);
}
return 0;
}
I think I need to do a ROM with EVMBUG modified to accept '\n' and perhaps also '\r\n', just to remove this annoying build step which will undoubtedly confuse the hell out of first time users of the breadboard system.
Note (2)
I have found my fresh build of TI-C to have a crash prone optimizer. To disable the optimizer, compile with the -O flag (see manual, -O means switch off, +O means switch on to TI-C). Perhaps Al's 20 year old win binary does not have this problem.
Note (3)
The compiler probably needs some TLC to make it fully usable. I found that static functions have their names preceded by a hash ('#') in the assembler output and asm990 does not accept this. In my fresh build calling a function pointer seemed to generate the wrong code. Modifying the main routine to automatically call asm990 and lnk990 after compiling also makes it a lot more user friendly. Personally, I'd like to finish the Ritchie compiler port first, so if somebody else feels called to make some touch ups to TIC, feel free.
Note (4)
If somebody needs C source for a simple version of 'printf', I can post one on request.
Sorry for an overly long post. Let me know if you get stuck somewhere and I'll post further instructions. Perhaps in due course this material could make an interesting additional page on your website.
Paul