Skip to main content

Printing like a pro

Printing in TempleOS means printing to the screen(not to paper). If you want to print a string,just type the string like this:

"Hello World\n";

Basic formatting

The print routine in TempleOS takes some (or no) arguments,you provide arguments like this:

"%d,%d,%d\n",1,2,3;

The arguments are 1,2, and 3 here and the format code is d(Integer decimal). There are various formatting codes for different types of data,to use a floating point number,use n

"Pi is %n\n",3.14;

The basic formatting codes are:

CodeMeaningType
dIntegerI64
SDefine stringU8*
CUppercase charactorU8/U64
p or PPointer to named symbolPointer
x or XHexidecimalPointer/I64
DDateCDate
TTimeCDate
qQuoted string(turns '"' into escape sequences)U8*
QReverse quoted stringU8*
ZDefineLst entry(Takes 2 arguments)U8 * and I64
zSub-entry of \0 terminated string(Takes 2 arguments)U8 * and I64

z/Z Formating

DefineLst's are things whose items are separated by \0s,they look like this:

DefineLstLoad("SOME_LIST","a\0b\0c\0");

We can use the list like this:

 DefineLstLoad("SOME_LIST","a\0b\0c\0");
I64 i;
for(i=0;i!=3;i++)
"HERE:%Z\n",i,"SOME_LIST";

Auxiliary value

The auxiliary value does various things for different format codes. For c,it repeats the character X times,we can do it like this:

"c%h3cl\n",'o';

For numbers,it will set the decimal point of the number(useful for F64's). For example if we want to view a number in units of 1000,we can do this

"%h3n\n",1234567.; //Be sure to use a . to get a F64

We get do negative numbers too for "milli" units

"%h-3n\n",0.123456;

We can have the Print routine choose the auxiliary for us using "?".

"%h?n\n",1234567.;

This is really cool. We can use an arbitrary value as the auxiliary value using *.

 I64 repeat=10;
"t%h*cn\n",repeat,'e';