TempleOSCD_140715.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:46:09 +02:00
1 parent 7ef616a20e
commit 64f679eeb9
1095 files changed
+24814 -221011

No files matched your search

+104 -98
View File
@@ -2,11 +2,11 @@ $WW,1$$FG,5$$TX+CX,"HolyC"$$FG$
* See $LK,"Scoping and Linkages",A="FI:::/Doc/ImportExports.TXT"$ for details on $FG,2$extern$FG$, $FG,2$import$FG$, $FG,2$_extern$FG$, $FG,2$_import$FG$, etc.
* See $LK,"::/Doc/Directives.TXT"$.
* See $LK,"::/Doc/CompilerOverview.TXT"$.
* Built-in types include $FG,2$I0,I8,I16,I32,I64$FG$ for signed 0-8 byte ints and $FG,2$U0,U8,U16,U32,U64$FG$ for unsigned 0-8 byte ints and $FG,2$F64$FG$ for 8 byte floats.
$FG,2$ U0 void
$FG,2$ U0 void, but ZERO size!
I8 char
U8 unsigned char
I16 short
@@ -20,6 +20,10 @@ $FG,2$ U0 void
* Function with no args, or just default args can be called without parentheses.
>$FG,2$Dir("*");$FG$
>$FG,2$Dir();$FG$
>$FG,2$Dir;$FG$
* Default args don't have to be on the end. This code is valid:
$ID,2$$FG,2$U0 Test(I64 i=4,I64 j,I64 k=5)
{
@@ -30,7 +34,7 @@ Test(,3);$FG$
$ID,-2$
* A char const all alone is sent to $LK,"PutChars",A="MN:PutChars"$(). A string with or without args is sent to $LK,"Print",A="MN:Print"$(). An empty string literal signals a variable fmt_str follows.
$ID,2$$FG,2$void Demo(char drv,char *fmt,char *name,int age)
$ID,2$$FG,2$void DemoC(char drv,char *fmt,char *name,int age)
{
printf("Hello World!\n");
printf("%s age %d\n",name,age);
@@ -39,7 +43,7 @@ $ID,2$$FG,2$void Demo(char drv,char *fmt,char *name,int age)
putchar('*');
}
U0 Demo(U8 drv,U8 *fmt,U8 *name,I64 age)
U0 DemoHolyC(U8 drv,U8 *fmt,U8 *name,I64 age)
{
"Hello World!\n";
"%s age %d\n",name,age;
@@ -48,20 +52,54 @@ U0 Demo(U8 drv,U8 *fmt,U8 *name,I64 age)
'*';
}
$FG$$ID,-2$
* When dealing with function addresses, precede the name with "$FG,2$&$FG$".
* When dealing with function addresses such as for callbacks, precede the name with "$FG,2$&$FG$".
* There is no $FG,2$main()$FG$ function. Any code outside of functions gets executed on start-up, in order.
* Type casting is postfix. To typecast int or F64, use $LK,"ToI64",A="MN:ToI64"$(), $LK,"ToBool",A="MN:ToBool"$() or $LK,"ToF64",A="MN:ToF64"$(). (TempleOS follows normal C float<-->int conversion, but sometimes you want to override. These functions are better than multiplying by "1.0" to convert to float.)
* You can access bytes or words within any int. $FG,2$i.u8[2]$FG$ returns bits 24-27 in the variable, $FG,2$i$FG$. See $LK,"I64 declaration",A="MN:I64"$. The real feature is that a class can be accessed as a whole, if you put a type in front of the $FG,2$class$FG$ declaration.
* There is no $FG,2$main()$FG$ function. Any code outside of functions gets executed upon start-up, in order.
* There are no bit fields, but there are $LK,"bit access",A="HI:Bit"$ routines and you can access bytes or words within any int. See $LK,"I64 declaration",A="MN:I64"$. A class can be accessed as a whole are subints, if you put a type in front of the $FG,2$class$FG$ declaration.
$ID,2$
$FG,2$public I64i union I64 //"I64i" is intrinsic. We are defining "I64".
{
I8i i8[8];
U8i u8[8];
I16 i16[4];
U16 u16[4];
I32 i32[2];
U32 u32[2];
};
I64 i=0x123456780000DEF0;
i.u16[1]=0x9ABC;
$FG$$ID,-2$
* Variable arg count functions ($FG,2$...$FG$) can access their args with built-in variables similar to '$FG,2$this$FG$' in C++. They are '$FG,2$I64 argc$FG$' and '$FG,2$I64 argv[]$FG$'.
$ID,2$$WW,0$
$FG,2$U0 GrPrint(CDC *dc,I64 x,I64 y,U8 *fmt,...)
$FG,2$I64 AddNums(...)
{
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
GrPrint(dc,x,y,buf);
I64 i,result=0;
for (i=0;i<argc;i++)
result+=argv[i];
return result;
}
$FG$>$FG,2$AddNums(1,2,3);$FG$
ans=6
$FG,2$
public U0 GrPrint(CDC *dc,I64 x,I64 y,U8 *fmt,...)
{
U8 *buf=$LK,"StrPrintJoin",A="MN:StrPrintJoin"$(NULL,fmt,argc,argv);//SPrintF() with $LK,"MAlloc",A="MN:MAlloc"$()ed string.
$LK,"GrPutS",A="MN:GrPutS"$(dc,x,y,buf); //Plot string at x,y pixels. GrPutS is not public.
Free(buf);
}
...
GrPrint(gr.dc,(GR_WIDTH-10*FONT_WIDTH)>>1,(GR_HEIGHT-FONT_HEIGHT)>>1,
"Score:%4d",score); //Print score in the center of the screen.
...
$WW,1$$FG$$ID,-2$
* Allows "$FG,2$5<i<j+1<20$FG$" instead of "$FG,2$5<i && i<j+1 && j+1<20$FG$".
$ID,2$
@@ -93,28 +131,58 @@ $ID,2$$FG,2$U0 SubSwitch()
"] ";
break;
}
NewLine;
'\n';
}$FG$$FG$
$BG$OutPut:
>$FG,2$Zero [One] Two [Three] Four [Five]$FG$
$ID,-2$
* $FG,2$noreg$FG$ or $FG,2$reg$FG$ can be placed before a function local var name. You can, optionally, specify a reg after the $FG,2$reg$FG$ keyword.
* $FG,2$interrupt$FG$, $FG,2$haserrcode$FG$, $FG,2$public$FG$, $FG,2$argpop$FG$ or $FG,2$noargpop$FG$ are function flags. See $LK,"::/Demo/Lectures/PageTableEntries2.CPP"$.
* A $FG,2$nounusedwarn$FG$ statement will suppress an unused var warning.
* You can have multiple member vars of a class named "$FG,2$pad$FG$" or "$FG,2$reserved$FG$", and it won't issue warnings.
* Type casting is postfix. To typecast int or F64, use $LK,"ToI64",A="MN:ToI64"$(), $LK,"ToBool",A="MN:ToBool"$() or $LK,"ToF64",A="MN:ToF64"$(). (TempleOS follows normal C float<-->int conversion, but sometimes you want to override. These functions are better than multiplying by "1.0" to convert to float.)
* $FG,2$noreg$FG$ or $FG,2$reg$FG$ can be placed before a function local var name. You can, optionally, specify a reg after the $FG,2$reg$FG$ keyword.
$ID,2$$FG,2$U0 Main()
{
//Only use $LK,"REG_VARS_MASK",A="MN:REG_VARS_MASK"$ or $LK,"REG_NON_PTR_MASK",A="MN:REG_NON_PTR_MASK"$ for reg vars or else clobbered.
I64 reg R15 i=5, noreg j=4;
nounusedwarn i;
asm {
MOV RAX,R15
CALL &PUT_HEX_U64
MOV RAX,'\n'
CALL &PUT_CHARS
MOV RAX,U64 &j[RBP]
CALL &PUT_HEX_U64
MOV RAX,'\n'
CALL &PUT_CHARS
}
}
$FG$$ID,-2$
* $FG,2$interrupt$FG$, $FG,2$haserrcode$FG$, $FG,2$public$FG$, $FG,2$argpop$FG$ or $FG,2$noargpop$FG$ are function flags. See $LK,"::/Demo/Lectures/PageTableEntries2.CPP"$.
* A single quote can encompass multiple characters. $FG,2$'ABC'$FG$ is equal to $FG,2$0x434241$FG$. $LK,"PutChars",A="MN:PutChars"$() takes multiple characters.
$ID,2$$FG,2$asm {
HELLO_WORLD::
PUSH RBP
MOV RBP,RSP
MOV RAX,'Hello '
CALL &PUT_CHARS
MOV RAX,'World\n'
CALL &PUT_CHARS
LEAVE
RET
}
Call(HELLO_WORLD);
PutChars('Hello ');
PutChars('World\n');
$FG$$ID,-2$
* The "$FG,2$`$FG$" operator raises a base to a power.
* There is no question-colon operator.
* TempleOS $LK,"operator precedence",A="FF:::/Compiler/CmpInit.CPP,binary_ops_table"$
* TempleOS $LK,"operator precedence",A="FF:::/Compiler/CmpInit.CPP,cmp.binary_ops"$
$FG,2$`$FG$,$FG,2$>>$FG$,$FG,2$<<$FG$
$FG,2$*$FG$,$FG,2$/$FG$,$FG,2$%$FG$
$FG,2$&$FG$
@@ -142,22 +210,20 @@ $ID,-2$
* Can't use $FG,2$<>$FG$ with $FG,2$#include$FG$, use $FG,2$""$FG$.
* "$FG,2$$$$FG$" is an escape character. Two dollar signs signify an ordinary $$. See $LK,"::/Doc/Dollar.TXT"$. In $FG,2$asm$FG$ or $LK,"HolyC",A="FI:::/Doc/HolyC.TXT"$ code, it also refers to the instruction's addr.
* "$FG,2$$$$FG$" is an escape character. Two dollar signs signify an ordinary $$. See $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT"$. In $FG,2$asm$FG$ or $LK,"HolyC",A="FI:::/Doc/HolyC.TXT"$ code, it also refers to the instruction's address or the offset in a $FG,2$class$FG$ definition.
* $FG,2$union$FG$ is more like a class, so you don't reference it with a $FG,2$union$FG$ label after you define it. Some common unions are declared in $LK,"Adam1a.HPP",A="MN:U16"$ for 1,2,4 and 8 byte objects. If you place a type in front of a union declaration, that is the type when used by itself. See $LK,"::/Demo/SubIntAccess.CPP"$.
* $FG,2$class$FG$ member vars can have meta data. $FG,2$fmtstr$FG$ and $FG,2$fmtdata$FG$ are two meta data types now used. All compiler structures are saved and you can access the compiler's info about classes and vars. See $LK,"::/Demo/ClassMeta.CPP"$ and $LK,"DocFormDo",A="MN:DocFormDo"$().
* There is a keyword $FG,2$lastclass$FG$ you use as a dft arg. It is set to the class name of the previous arg. See $LK,"ClassRep",A="MN:ClassRep"$().
* There is a keyword $FG,2$lastclass$FG$ you use as a dft arg. It is set to the class name of the previous arg. See $LK,"::/Demo/LastClass.CPP"$, $LK,"ClassRep",A="MN:ClassRep"$(), $LK,"DocFormDo",A="MN:DocFormDo"$() and $LK,"::/Demo/Dsk/BlkDevRep.CPP"$.
* See $LK,"::/Demo/Exceptions.CPP"$. $FG,2$try{} catch{}$FG$ and $FG,2$throw$FG$ are different from C++. $FG,2$throw$FG$ is a function with a char arg. The char string passed in $FG,2$throw()$FG$ can be accessed from within a $FG,2$catch{}$FG$ using the $FG,2$Fs->except_ch$FG$. Within a $FG,2$catch {}$FG$ blk, set the var $FG,2$Fs->catch_except$FG$ to $FG,2$TRUE$FG$ if you want to terminate the search for a handler. Use $LK,"PutExcept",A="MN:PutExcept"$() as a handler, if you like.
* See $LK,"::/Demo/Exceptions.CPP"$. $FG,2$try{} catch{}$FG$ and $FG,2$throw$FG$ are different from C++. $FG,2$throw$FG$ is a function with an 8-byte or less char arg. The char string passed in $FG,2$throw()$FG$ can be accessed from within a $FG,2$catch{}$FG$ using the $FG,2$Fs->except_ch$FG$. Within a $FG,2$catch {}$FG$ blk, set the var $FG,2$Fs->catch_except$FG$ to $FG,2$TRUE$FG$ if you want to terminate the search for a handler. Use $LK,"PutExcept",A="MN:PutExcept"$() as a handler, if you like.
* A function is available similar to $FG,2$sizeof$FG$ which provides the offset of a member of a class. It's called $FG,2$offset$FG$. You place the class name and member inside as in $FG,2$offset(classname.membername)$FG$. It has nothing to do with 16-bit code. Both $FG,2$sizeof$FG$ and $FG,2$offset$FG$ only accept one level of member vars. That is, you can't do $FG,2$sizeof(classname.membername.submembername)$FG$.$FG$
* There is no $FG,2$continue$FG$ statement. Use $FG,2$goto$FG$.
* No bit field support, but there are bit access $LK,"library routines",A="HI:Bit"$.
* $FG,2$lock{}$FG$ can be used to apply asm $FG,2$LOCK$FG$ prefixes to code for safe multicore read-modify-write accesses. The code bracked with have $FG,2$LOCK$FG$ asm prefix's applied to relevant instructions within. It's a little shoddy. See $LK,"::/Demo/MultiCore/Lock.CPP"$.
* There is a function called $LK,"MSize",A="MN:MSize"$() which gives the size of an object allocated off the heap. For larger size allocations, the system rounds-up to a power of two, so $FG,2$MSize()$FG$ lets you know the real size and you can take full advantage of it.
@@ -168,86 +234,26 @@ $ID,-2$
* Only one base class is allowed.
* $FG,2$printf()$FG$ has new codes. See $LK,"Print(\"\") Fmt Strings",A="FI:::/Doc/Print.TXT"$.
* All values are extended to 64-bit when accessed. Intermediate calculations are done with 64-bit values.
$ID,2$The follow examples should be inserted in a function, so that reg variables are used. (Global vars are never reg.)
$ID,2$$FG,2$U0 Main()
{
I16 i1;
I32 j1;
j1=i1=0x12345678; //Resulting i1 is 0x5678 but j1 is 0x12345678
$FG,2$I16 i;
I32 j;
j=i=0x12345678; //Resulting i is 0x5678 but j is 0x12345678
I64 i2=0x8000000000000000;
Print("%X\n",i2>>1); //Result is 0xC000000000000000 as expected
I64 i=0x8000000000000000;
Print("%X\n",i>>1); //Result is 0xC000000000000000 as expected
U64 u3=0x8000000000000000;
Print("%X\n",u3>>1); //Result is 0x4000000000000000 as expected
U64 u=0x8000000000000000;
Print("%X\n",u>>1); //Result is 0x4000000000000000 as expected
I32 i= 0x80000000; //const is loaded into a 64-bit reg var.
Print("%X\n",i>>1); //Result is 0x40000000
I32 i=-0x80000000;
Print("%X\n",i>>1); //Result is 0xC0000000 as expected
I32 i4=0x80000000; //const is loaded into a 64-bit reg var.
Print("%X\n",i4>>1); //Result is 0x40000000
I32 i5=-0x80000000;
Print("%X\n",i5>>1); //Result is 0xFFFFFFFFC0000000
}
$ID,-2$$FG$
$FG,5$$TX+CX,"Print Family"$$FG$
$LK,"MPrint",A="MN:MPrint"$() is like $LK,"SPrint",A="MN:SPrint"$() but it returns a $LK,"MAlloc",A="MN:MAlloc"$ated str. It is vary handy because you don't have to worry about overflow.
$LK,"Auto",A="MN:Auto"$(U8 *fmt,...) sends text to the current task's input buffer.
$LK,"AutoStr",A="MN:AutoStr"$(U8 *fmt,...) sends text of an $LK,"AutoFile",A="FF:::/Doc/Glossary.TXT,AutoFile"$ to the keyboard stream of the current TASK but can also do mouse cmds.
$LK,"XTalk",A="MN:XTalk"$(CTask *task,U8 *fmt,...) and text to another task's input buffer.
$LK,"XTalkStr",A="MN:XTalkStr"$(CTask *task,U8 *fmt,...) sends text of an $LK,"AutoFile",A="FF:::/Doc/Glossary.TXT,AutoFile"$ to the keyboard stream of another TASK but can also do mouse cmds.
$LK,"DocPrint",A="MN:DocPrint"$(CDoc *doc,U8 *fmt,...) sends text to a document. You can buffer to a Doc and save it, providing the functionality of $FG,2$fprintf$FG$. See $LK,"::/Demo/Dsk/FPrintF.CPP"$.
$LK,"Adam",A="MN:Adam"$(U8 *fmt,...) sends text to the adam task to be compiled and run.
$LK,"AdamLog",A="MN:AdamLog"$(U8 *fmt,...) and $LK,"AdamErr",A="MN:AdamErr"$(U8 *fmt,...) send text to the adam task to be displayed.
$LK,"StreamPrint",A="MN:StreamPrint"$(U8 *fmt,...) sends text to the stream of code being compiled and must reside in a $FG,2$#exe{}$FG$ blk.
$LK,"GrPrint",A="MN:GrPrint"$(CDC *dc,I64 x,I64 y,U8 *fmt,...) and $LK,"GrVPrint",A="MN:GrVPrint"$() plots text in graphics mode.
$LK,"ExePrint",A="MN:ExePrint"$(U8 *fmt,...) compiles and execute a string. Note: It returns the result of the last executed expression.
$LK,"AFPrint",A="MN:AFPrint"$(I64 mS,U8 *fmt) $LK,"PutChars",A="MN:PutChars"$()s one at a time with a delay.
$LK,"RawPrint",A="MN:RawPrint"$(I64 mS,U8 *fmt) sends direct to screen memory, bypassing window manager.
$BK,1$Note:$BK,0$ Use $FG,2$Print("%s",src)$FG$ if you need an unmodified string.
$AN,"",A="SPrintCodes"$The $LK,"Print",A="MN:Print"$() family supports extended format codes. See $LK,"SPrintJoin",A="MN:SPrintJoin"$().
$ID,2$$FG,2$%$FG$[$FG,2$-$FG$][$FG,2$0$FG$][$FG,5$width$FG$][$FG,2$.$FG,5$decimals$FG$][$FG,5$flags$FG$][$FG,2$h$FG,5$sub_fmt$FG$][$FG,5$main_fmt$FG$]
$FG,5$flags:$FG$
$ID,2$* $FG,2$'t'$FG$ is a flag which will truncate to field width.
* $FG,2$','$FG$ is a flag which will add commas every three digits in a $FG,2$%d$FG$, $FG,2$%f$FG$,$FG,2$ %g$FG$,$FG,2$ %e$FG$ and $FG,2$%n$FG$ entries.
* $FG,2$'$$'$FG$ is a flag which affects the $FG,2$%Q$FG$ entry, converting $FG,2$'$$'$FG$ to $FG,2$"\044"$FG$.
* $FG,2$'/'$FG$ is a flag which affects the $FG,2$%Q$FG$ and $FG,2$%q$FG$ entries, converting $FG,2$'%'$FG$ to $FG,2$"%%"$FG$.
$ID,-2$
$FG,5$sub_fmt:$FG$
$ID,2$For $FG,2$"%n"$FG$, $FG,2$"%d"$FG$ or $FG,2$"%u"$FG$, the sub_fmt causes thousands mode. $FG,2$"%h?n"$FG$ will pick a var exponent multiples of three unit, while $FG,2$"%h-3n"$FG$ will display milli units or $FG,2$"%h6n"$FG$ will display mega units. The $FG,2$'k'$FG$ flag is always on for $FG,2$"%n"$FG$. See $LK,"::/Demo/Print.CPP"$.
$ID,-2$
* $FG,2$"%n"$FG$ will print a floating point in engineering notation, exponents being multiples of three. If it has a $FG,5$sub_fmt$FG$ code, it will display scientific units letters.
* $FG,2$"%S"$FG$ will print a Define entry.
* $FG,2$"%C"$FG$ will print a ToUpper character.
* $FG,2$"%F"$FG$ will print a text file.
* $FG,2$"%p"$FG$ will display ptr.
* $FG,2$"%P"$FG$ will display link to ptr.
* $FG,2$"%T"$FG$ and $FG,2$"%D"$FG$ will display a date or time if you pass a $LK,"CDate",A="MN:CDate"$.
* $FG,2$"%z"$FG$ will display a subentry of an enumerated list of text entries. It calls $LK,"LstSub",A="MN:LstSub"$(). Pass subentry first, list second.
* $FG,2$"%Z"$FG$ will display a Define subentry. Pass subentry first, lst_define second.
* $FG,2$"%Q"$FG$ will convert "\" to "\\" and quote to backslash quote. (For use in creating strs in strs.)
* $FG,2$"%q"$FG$ will reverse a $FG,2$"%Q"$FG$.
$ID,-2$