TempleOSCD_140715.ISO
This commit is contained in:
1 parent
7ef616a20e
commit
64f679eeb9
1095 files changed
+24814
-221011
No files matched your search
+20
-17
@@ -1,25 +1,26 @@
|
||||
/*
|
||||
This is a JIT file, not AOT.
|
||||
|
||||
Asm labels can only be defined once
|
||||
in a task. Hit F5 to spawn a new task
|
||||
each time and run it.
|
||||
/*Asm labels can only be defined once
|
||||
in a task. <F5> will spawn a new task
|
||||
each time, so you don't get redefine
|
||||
error, like when repeatedly #including
|
||||
it from the cmd line.
|
||||
*/
|
||||
|
||||
asm {
|
||||
//Opcodes are slightly different to make writing my x86_64 assembler easier.
|
||||
//See $LK,"::/Compiler/OpCodes.TXT"$.
|
||||
|
||||
USE64 //Defaults to 64, but this is a good habit.
|
||||
|
||||
IMPORT Beep;
|
||||
|
||||
_BEEPS::
|
||||
//You can always clobber RAX,RBX,RCX,RDX,R8,R9
|
||||
//You can always clobber RAX,RBX,RCX,RDX,R8,R9. The compiler expects that.
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV RCX,U64 SF_ARG1[RBP] //$LK,"SF_ARG1",A="FF:::/Kernel/Adam1a.HPP,SF_ARG1"$
|
||||
|
||||
@@05: PUSH RCX
|
||||
//U0 Beep(I64 freq=500,Bool busy=FALSE)
|
||||
//U0 $LK,"Beep",A="MN:Beep"$(I64 freq=500,Bool busy=FALSE)
|
||||
PUSH FALSE //Do not busy (spin) wait
|
||||
PUSH 500 //Hz
|
||||
CALL Beep
|
||||
@@ -27,33 +28,35 @@ _BEEPS::
|
||||
LOOP @@05
|
||||
|
||||
POP RBP
|
||||
//Return vals are in RAX
|
||||
RET1 8
|
||||
}
|
||||
RET1 8 //Use special return. Pop one arg off of stack.
|
||||
|
||||
//HolyC return vals are in RAX. This function has no return value.
|
||||
}
|
||||
|
||||
//_extern binds a asm sym to a function.
|
||||
//My convention is to put an underscore
|
||||
//on C callable routines.
|
||||
//on C callable asm routines.
|
||||
_extern _BEEPS U0 Beeps(I64 cnt);
|
||||
|
||||
I64 AsmAndC1()
|
||||
{
|
||||
I64 noreg i; //Normally this would be stored in a reg
|
||||
//Check with $LK,"Uf",A="MN:Uf"$("AsmAndC1").
|
||||
//Check by unassembling with $LK,"Uf",A="MN:Uf"$("AsmAndC1").
|
||||
|
||||
i=PmtI64("Num of beeps 1-5 (%d):",3,1,5);
|
||||
i=GetI64("Num of beeps 1-5 (%d):",3,1,5);
|
||||
Beeps(i);
|
||||
|
||||
asm {
|
||||
//You can clobber RAX,RBX,RCX,RDX
|
||||
//You can clobber RAX,RBX,RCX,RDX. The compiler expects that.
|
||||
|
||||
USE64 //Defaults to 64, but this is a good habit.
|
||||
|
||||
IMPORT Snd; //Import an not use & or don't import and use &Snd.
|
||||
MOV RCX,&i[RBP] //You can clobber RAX,RBX,RCX,RDX.
|
||||
//You better preserve the rest.
|
||||
|
||||
@@05: PUSH RCX
|
||||
//U0 Snd(F64 freq);
|
||||
//U0 $LK,"Snd",A="MN:Snd"$(F64 freq);
|
||||
|
||||
MOV RAX,RCX //freq=loop*100.0+100.0
|
||||
IMUL2 RAX,100 //TempleOS uses nonstandard opcodes
|
||||
@@ -66,7 +69,7 @@ USE64 //Defaults to 64, but this is a good habit.
|
||||
|
||||
CALL Snd
|
||||
|
||||
MOV RCX,time_stamp_freq>>3 //JIT Const. Simple delay loop
|
||||
MOV RCX,cnts.time_stamp_freq>>3 //JIT Const. Simple delay loop
|
||||
@@10: LOOP @@10
|
||||
|
||||
POP RCX
|
||||
|
||||
+17
-15
@@ -1,18 +1,18 @@
|
||||
/*
|
||||
This is a JIT file, not AOT.
|
||||
|
||||
Asm labels can only be defined once
|
||||
in a task. Hit F5 to spawn a new task
|
||||
each time and run it.
|
||||
/*Asm labels can only be defined once
|
||||
in a task. <F5> will spawn a new task
|
||||
each time, so you don't get redefine
|
||||
error, like when repeatedly #including
|
||||
it from the cmd line.
|
||||
*/
|
||||
|
||||
//This is to demo glbl var access.
|
||||
//Glbs defined elsewhere can accessed too, like sys_jiffies.
|
||||
//Glbs defined elsewhere can accessed too, like cnts.jiffies.
|
||||
I64 glbl_hz=400,glbl_hz_step=100,glbl_hz_base=100;
|
||||
|
||||
asm {
|
||||
//Opcodes are slightly different to make writing my x86_64 assembler easier.
|
||||
//See $LK,"::/Compiler/OpCodes.TXT"$.
|
||||
|
||||
USE64 //Defaults to 64, but this is a good habit.
|
||||
|
||||
JIFFIES_MSG: DU8 "Jiffies:",0;
|
||||
@@ -20,15 +20,15 @@ JIFFIES_MSG: DU8 "Jiffies:",0;
|
||||
//See $LK,"::/Kernel/Str1a.CPP",A="FL:::/Kernel/Str1a.CPP,1"$ and $LK,"::/Kernel/Utils1a.CPP"$.
|
||||
|
||||
_BEEPS2::
|
||||
//You can clobber RAX,RBX,RCX,RDX,R8,R9
|
||||
//You can clobber RAX,RBX,RCX,RDX,R8,R9. The compiler expects that.
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV RCX,U64 SF_ARG1[RBP] //$LK,"SF_ARG1",A="FF:::/Kernel/Adam1a.HPP,SF_ARG1"$
|
||||
|
||||
PUSH U64 [&sys_jiffies]
|
||||
PUSH U64 [&cnts.jiffies]
|
||||
|
||||
@@05: PUSH RCX
|
||||
//U0 Beep(I64 freq=500,Bool busy=FALSE)
|
||||
//U0 $LK,"Beep",A="MN:Beep"$(I64 freq=500,Bool busy=FALSE)
|
||||
PUSH FALSE //Do not busy (spin) wait
|
||||
PUSH U64 [&glbl_hz] //evaluated at run time
|
||||
CALL &Beep
|
||||
@@ -41,7 +41,7 @@ _BEEPS2::
|
||||
POP RSI
|
||||
|
||||
POP RAX
|
||||
SUB RAX,U64 [&sys_jiffies]
|
||||
SUB RAX,U64 [&cnts.jiffies]
|
||||
NEG RAX
|
||||
CALL PUT_HEX_U64
|
||||
MOV RAX,'\n'
|
||||
@@ -52,24 +52,26 @@ _BEEPS2::
|
||||
}
|
||||
|
||||
//My convention is to put an underscore
|
||||
//on C callable routines.
|
||||
//on C callable asm routines.
|
||||
_extern _BEEPS2 U0 Beeps2(I64 cnt);
|
||||
|
||||
U0 AsmAndC2()
|
||||
{
|
||||
I64 reg R15 i;
|
||||
|
||||
i=PmtI64("$$PURPLE$$\n\nNum of beeps 1-5 (%d):$$FG$$",3,1,5);
|
||||
i=GetI64("$$PURPLE$$\n\nNum of beeps 1-5 (%d):$$FG$$",3,1,5);
|
||||
Beeps2(i);
|
||||
|
||||
asm {
|
||||
LIST
|
||||
//You can clobber RAX,RBX,RCX,RDX, but preserve the rest.
|
||||
|
||||
USE64 //Defaults to 64, but this is a good habit.
|
||||
|
||||
MOV RCX,R15 //You can clobber RAX,RBX,RCX,RDX. Preserve the rest.
|
||||
|
||||
@@05: PUSH RCX
|
||||
//U0 Snd(F64 freq);
|
||||
//U0 $LK,"Snd",A="MN:Snd"$(F64 freq);
|
||||
|
||||
MOV RAX,RCX //freq=loop*100.0+100.0
|
||||
IMUL2 RAX,glbl_hz_step //evaluated at compile ttime
|
||||
@@ -80,7 +82,7 @@ USE64 //Defaults to 64, but this is a good habit.
|
||||
|
||||
CALL &Snd //We can skip IMPORT with & if JIT compiling.
|
||||
|
||||
MOV RCX,time_stamp_freq>>3 //JIT Const. Simple delay loop.
|
||||
MOV RCX,cnts.time_stamp_freq>>3 //JIT Const. Simple delay loop.
|
||||
@@10: LOOP @@10
|
||||
|
||||
POP RCX
|
||||
|
||||
+9
-10
@@ -1,23 +1,22 @@
|
||||
/*
|
||||
This is a JIT file, not AOT.
|
||||
|
||||
Asm labels can only be defined once
|
||||
in a task. Hit F5 to spawn a new task
|
||||
each time and run it.
|
||||
/*Asm labels can only be defined once
|
||||
in a task. <F5> will spawn a new task
|
||||
each time, so you don't get redefine
|
||||
error, like when repeatedly #including
|
||||
it from the cmd line.
|
||||
*/
|
||||
|
||||
U0 AsmAndC3()
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<3;i++) {
|
||||
"Meaning of life:";
|
||||
MOV AL,0x41
|
||||
STC
|
||||
ADC AL,0 //Round-about way to make the not special constant, 0x42.
|
||||
ADC AL,0 //Round-about way to make the not-special constant, 0x42.
|
||||
CALL PUT_HEX_U8
|
||||
MOV RCX,time_stamp_freq>>5 //JIT Cosnt. Simple delay loop.
|
||||
MOV RCX,cnts.time_stamp_freq>>5 //JIT Const. Simple delay loop.
|
||||
@@1: LOOP @@1
|
||||
MOV RAX,' What?\n'
|
||||
CALL PUT_CHARS
|
||||
'\n';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
/*
|
||||
This is a JIT file, not AOT.
|
||||
|
||||
Asm labels can only be defined once
|
||||
in a task. Hit F5 to spawn a new task
|
||||
each time and run it.
|
||||
/*Asm labels can only be defined once
|
||||
in a task. <F5> will spawn a new task
|
||||
each time, so you don't get redefine
|
||||
error, like when repeatedly #including
|
||||
it from the cmd line.
|
||||
|
||||
These are many useful kernel
|
||||
routines $LK,"::/Kernel/Str1a.CPP",A="FF:::/Kernel/Str1a.CPP,PUT_CHARS"$
|
||||
@@ -32,7 +31,7 @@ MY_WORLD_MSG:
|
||||
DU8 "World\n",0;
|
||||
|
||||
//My convention is to put an underscore
|
||||
//on C callable routines.
|
||||
//on C callable asm routines.
|
||||
_HELLO_WORLD::
|
||||
PUSH RSI //See $LK,"REG_VARS_MASK",A="MN:REG_VARS_MASK"$ & $LK,"REG_NON_PTR_MASK",A="MN:REG_NON_PTR_MASK"$
|
||||
MOV RCX,10
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
asm {
|
||||
DIV_U64_BY_U64::
|
||||
PUSH RBP
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
/*
|
||||
When I was a kid with a Commodore 64,
|
||||
/*When I was a kid with a Commodore 64,
|
||||
the 6502 chip had no multiply instruction
|
||||
and this is how we had to do it, except,
|
||||
I used more regs in this example.
|
||||
@@ -10,7 +9,7 @@ asm {
|
||||
|
||||
USE64 //Defaults to 64, but this is a good habit.
|
||||
|
||||
//You can clobber RAX,RBX,RCX,RDX,R8,R9
|
||||
//You can clobber RAX,RBX,RCX,RDX,R8,R9. The compiler expects that.
|
||||
|
||||
MUL_BY_HAND_U8_U8_TO_U16: //This is only for fun.
|
||||
//8bit * 8bit-->16bit
|
||||
@@ -48,7 +47,7 @@ _MUL_U64_U64_TO_U128::
|
||||
};
|
||||
|
||||
//My convention is to put an underscore
|
||||
//on C callable routines.
|
||||
//on C callable asm routines.
|
||||
_extern _MUL_BY_HAND_U8_U8_TO_U16 U16 MulU8(U8 n1,U8 n2);
|
||||
|
||||
class U128
|
||||
|
||||
+3
-3
@@ -13,7 +13,7 @@ PUT_DEC_U64::
|
||||
PUSH RSI //See $LK,"REG_VARS_MASK",A="MN:REG_VARS_MASK"$ & $LK,"REG_NON_PTR_MASK",A="MN:REG_NON_PTR_MASK"$
|
||||
LEA RSI,-1[RBP] //Load addr of end of buffer.
|
||||
//We picked RSI because of PUT_STR
|
||||
//We'll move backward
|
||||
//We'll move bwd
|
||||
MOV U8 [RSI],0 //Terminator
|
||||
|
||||
TEST RAX,RAX //Special case -- zero
|
||||
@@ -41,8 +41,8 @@ PUT_DEC_U64::
|
||||
_DO_IT:: //The convention is C-callable routines have underscores.
|
||||
MOV RAX,122333221
|
||||
CALL PUT_DEC_U64
|
||||
PUSH 1
|
||||
CALL &NewLine //Print one carriage return
|
||||
MOV RAX,'\n'
|
||||
CALL PUT_CHARS
|
||||
RET
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user