'
'
'
'         ###############
'       ###################
'      ###               ###
'     ###    ###          ###
'    ###    ## ##         ###
'    ###   ##   ##        ###
'    ###  ##     ##       ###
'    ###  ##      ##      ###
'    ###  ##      ##      ###
'    ###   ####  ##      ###
'     ###    ####       ###
'      ###             ###
'       ###           ###
'         #############
'           #########




'===========
kernel_funs:
'===========
'===========






'======================
'>>O2H LOW LEVEL MACROS
'======================


data  "#view 18 ###"
data  "#endv 18 ###"
data  "version 18 "+qu+version+qu
data  "true 18 -1"
data  "false 18 0"
data  "use 18 include once"
data  "uses 18 include once"
data  "using 18 include once"
data  "global 18 dim static" 'global is deprecated
data  "lobyte 18 ((%1) and 0xff)"
data  "loword 18 ((%1) and 0xffff)"
data  "hibyte 18 (((%1)>>8) and 0xff)"
data  "hiword 18 (((%1)>>16) and 0xffff)"
data  "redim 18"+cr+_
      "#ifndef %2_buffer"+cr+_
      "  dim static string %2_buffer = "+qu+qu+cr+_
      "  dim static int %2_count"+cr+_
      "  dim static %1 byref %2"+cr+_
      "#endif"+cr+_
      "scope"+cr+_
      "dim sys %2_qb = %3"+cr+_
      "dim sys %2_le = len %2_buffer"+cr+_
      "dim sys %2_qn = %2_le / sizeof(%1)"+cr+_
      "if %2_qb > %2_qn"+cr+_
      "  %2_buffer += nuls( sizeof(%1) * (%2_qb - %2_qn))"+cr+_
      "elseif %2_qb <  %2_qn"+cr+_
      "  %2_buffer = left( %2_buffer, sizeof(%1) * %2_qb )"+cr+_
      "end if"+cr+_
      "%2_count=%3"+cr+_
      "@%2=strptr(%2_buffer)"+cr+_
      "end scope"+cr
data  "del 18 "+cr+_
      "#if typecodeof(%1)>0x200"+cr+_
      "  #ifdef %1.destructor"+cr+_
      "    %1.destructor"+cr+_
      "  #endif"+cr+_
      "  freememory @%1 : @%1=0"+cr+_
      "#elseif typecodeof(%1)>0xe0"+cr+_
      "  freememory strptr(%1) : if ?%1 { *%1=0 : ?%1=0 }"+cr+_
      "#elseif typecodeof(%1)>0xc0"+cr+_
      "  freememory strptr(%1) : ?%1=0"+cr+_
      "#elseif typecodeof(%1)>0xa0"+cr+_
      "  #error Not a dynamic string: %1"+cr+_
      "#else"+cr+_
      "  #error Not a string or object: %1"+cr+_
      "#endif"+cr
data  "new 18 %1 * %2 = getmemory sizeof %1"+cr+_
      "#ifdef %1.___"+cr+_
      "? %2 = @%1_table"+cr+_
      "#endif"+cr+_
      "#ifdef %1.constructor"+cr+_
      "  %2.constructor(%3)"+cr+_
      "#endif"+cr




'===============================
'>>O2H SYSTEM TERMINATION MACROS
'===============================



data  "terminate 19 |go 0 [ebx+2448]"+cr+"|go 0 [ebx+2144]"+cr
data  "freestrings 19 |go 0 [ebx+2144]"+cr
data  "freelibs 19 |go 0 [ebx+2448]"+cr



'=======================
'>>O2H HIGH LEVEL MACROS
'=======================

data  "right 20 right(s,i) {mid(s,-(i))}"
data  "guidptr 20 guidptr(s) {byval guidval(guid{},s)}"

'========================
'>>O2 LOW LEVEL FUNCTIONS
'========================


data  "getmemory 4 8"
data  "freememory 4 16"
data  "loadlibrary 4 24"
data  "freelibrary 4 32"
data  "getprocaddress 4 40"
data  "copy0 4 56"
data  "copy00 4 64"
data  "copyn 4 72"
data  "copy 4 72"
data  "mbox 4 2048" 'mboxa
data  "comparestr 4 2192" ' comps ' COMPARING BSTRS


'=============================
'>>COMMON RESERVED WORDS
'=============================

data "exit   9 1"
data "repeat 9 1"
data "call   9 1"
data "jmp    9 1"
data "and    9 0"
data "or     9 0"
data "xor    9 0"
data "not    9 1"
data "null   9 1"



'===========================
'>>O2 ATTRIBUTE MACROS
'===========================



data  "sizeof      11 1 4"
data  "offsetof    11 2 4"
data  "countof     11 3 4"
data  "spanof      11 3 4"
data  "bytesof     11 4 4"
data  "typeof      11 5 193"
data  "structureof 11 6 193"
data  "encodingof  11 6 193"
data  "prototypeof 11 7 193"
data  "typecodeof  11 8 4"
data  "recordof    11 9 4"
data  "widthof    11 10 4"
data  "strptr      11 21 8"


'===========================
'>>O2 KEYWORDS
'===========================




data  "incl 13 1"


data  "#semicolon 13 2"
'data  "indexers 13 3"
data  "retn 13 4"
'data  "offset 13 5"
'data  "skip 13 6"
data  "with 13 7"
'data  "dataspace 13 8"
'data  "data 13 9"
data  "o2 13 10"
data  "bind 13 12"
data  "enum 13 14"
data  "def 13 15"
data  "#def 13 15"
data  "type 13 16"
data  "struct 13 11"
data  "class 13 13"
data  "var 13 17"
data  "include 13 18"
data  "#include 13 18"
'data  "asm 13 19"
'data  "#asm 13 19"
'data  "o2h 13 20"
'data  "#o2h 13 20"
'data  "basic 13 20"
'data  "#basic 13 20"
data  "packed 13 21"
data  "_def 13 22"
data  "namespace 13 23"
data  "restore 13 24"
'data  "read 13 25"
data  "rem 13 26"
data  "includepath 13 30"
data  "librarypath 13 31"
data  "#file 13 34"
data  "embedfile 13 35"
data  "quote 13 36"
data  "typedef 13 37"
data  "union 13 38"
data  "#case 13 41"
data  "#lookahead 13 43"
data  "#autodim 13 44"
data  "#alert 13 46"
data  "#error 13 47"
data  "#pragma 13 48"
data  "#unique 13 49"
data  "#console 13 50"
data  "#show 13 51 "
data  "#emit 13 52 "
data  "addr 13 53 "
data  "#compact 13 54 "
data  "#cpointer 13 55 "



'===========================
'>>O2H KEYWORDS
'===========================

data  "let 14 2"
data  "dim 14 4"
data  "const 14 4"
data  "local 14 5"
data  "static 14 6"
data  "! 14 8"
data  "declare 14 8"
data  "function 14 9"
data  "sub 14 10"
data  "method 14 11"
data  "loop 14 12" 'LOOP'` KEYWORD DISTINGUISHED FROM ASM LOOP
data  "if 14 13"
data  "then 14 14"
data  "else 14 15"
data  "elseif 14 16"
data  "endif 14 17"
data  "enddo 14 18"
data  "endwhile 14 19"
data  "endsel 14 20" 'ALSO: "END SELECT"
data  "do 14 21"
data  "while 14 23"
data  "wend 14 24"
data  "exit 14 25"
data  "redo 14 26"
data  "continue 14 26"
data  "repeat 14 26"
data  "default 14 27"
data  "break  14 28"
data  "switch 14 29"
data  "select 14 29"
data  "case 14 30"
data  "for 14 31"
data  "to 14 32"
data  "step 14 33"
data  "next 14 34"
data  "goto 14 35"
data  "gosub 14 36"
data  "methods 14 37"
data  "return 14 38"
data  "% 14 39" ' QB style equate
data  "$ 14 39" ' QB style equate
data  "block 14 41"
data  "scope 14 42"
data  "indexbase 14 44"
data  "lib 14 45"
data  "library 14 45"
data  "extern 14 48"
data  "that 14 49"
data  "this 14 50"
data  "#noprec 14 53"
data  "#noinit 14 54"
data  "#byval 14 55"
data  "#byref 14 56"
data  "#dim 14 57"
data  "#assign 14 58"
data  "#insert 14 59"
data  "readstate 14 60"
data  "deff 14 62"
'data  "operations 14 63"



'============
'METACOMMANDS
'============


data  "#if 13 100"
data  "#else 13 101"
data  "#elseif 13 102"
data  "#endif 13 103"
data  "#define 13 104"
data  "#ifdef 13 105"
data  "#ifndef 13 106"
data  "undef 13 107"
data  "#undef 13 107"
data  "#undefine 13 107"
data  "alias 13 108" 'thinBasic headers
data  "macro 13 109"
data  "#print 13 110"
'data  "#ifexist 13 111"
'data  "#ifnexist 13 112"
data  "#eval 13 113"
data  "#blockdepth 13 201"
data  "#recordof 13 202"
data  "#list 13 203"


'================================
'primitives (Basic and C style
'================================


data "void      15 &h00" '*
data "sbyte     15 &h01"
data "byte      15 &h21"
data "ubyte     15 &h21"
data "string    15 &he1"
data "string2   15 &he2"
data "wstring   15 &he2"
data "bstring   15 &hc1"
data "gstr_     15 &hc1" '* Accept any Bstring width. for core functions only
data "bstr      15 &hc1"
data "bstring2  15 &hc2"
data "char      15 &ha1"
data "wchar     15 &ha2"
data "cstr_     15 &ha1" '* Accept any string width. for core functions only
data "asciiz    15 &ha1"
data "zstring   15 &ha1"
data "zstring2  15 &ha2"
data "asciiz2   15 &ha2"
data "short     15 &h02"
data "long      15 &h04"
data "wide      15 &ha2"
data "int       15 &h04"
data "integer   15 &h04"
data "float     15 &h64"
data "single    15 &h64"
data "double    15 &h68"
data "extended  15 &h6A"
data "quad      15 &h48" '* using FPU on 32 bit systems (was 08), returns data on edx:eax
data "word      15 &h22"
data "dword     15 &h24"
data "ulong     15 &h24"
data "uint      15 &h24"
data "any       15 &h08" '* to be used by reference only
data "sys       15 &h08" '* 4/8 depending on 32/64 bit system
data "bool      15 &h04" '* MS
data "boolean   15 &h01" '* MS
data "fpu       15 &h40" '* fast call using fpu registers (not exportable)
data "signed    15 &h04"
data "unsigned  15 &h24"
data "qword     15 &h28" '* Assembler only



'===========================================
'>>OVERLOADABLE INTEGER AND STRING FUNCTIONS
' overloadable functions -16
' integer and string
' TREATED AS STDCALL
'===========================================



data  "news 16 ##sys@0 bstr 08"
data  "frees 16 ##gstr_#@0 sys 16 ##sys@0 sys 16"
data  "error 16 ##@ bstr 128"
data  "nuls 16 ##sys@0 bstr 08"
data  "compile 16 ##string@0 sys 368"
data  "val 16 ##zstring@1 fpu 192"
data  "valat 16 ##sys@0 fpu 192"
data  "ltrim 16 ##string@0 bstr 2312"
data  "rtrim 16 ##string@0 bstr 2320"
data  "lcase 16 ##string@0 bstr 2328"
data  "ucase 16 ##string@0 bstr 2336"
data  "stringbytes 16 ##sys#sys@00 bstr 2464"
data  "string 16 ##sys#zstring@00 bstr 2472 ##sys#string@00 bstr 2480"
data  "space 16 ##sys@0 bstr 2488"
data  "left 16 ##gstr_#sys@00 bstr 2344 ##cstr_#sys@10 bstr 2400"
data  "mid 16 "+_
      "##gstr_#sys#sys@000 bstr 2360 ##cstr_#sys#sys@100 bstr 2392 "+_
      "##gstr_#sys@00 bstr 2416 ##cstr_#sys@10 bstr 2424 "
      ''mid command
data  "_mid 16 ##gstr_#sys#gstr_@000 sys 2456 ##cstr_#sys#gstr_@100 sys 2352 "
data  "instr 16 ##string#string@00 sys 2504 ##sys#string#string@000 sys 320"
data  "getfile 16 ##cstr_@1 bstr 336 ##cstr_#gstr_@11 sys 2512"
data  "putfile 16 ##cstr_#gstr_@10 sys 344"
data  "print 16 ##cstr_@1 sys 2496"
data  "asc 16 ##string@0 sys 2432 ##string#sys@00 sys 2368"
data  "unic 16 ##wstring@0 sys 2536 ##wstring#sys@00 sys 2528"
data  "len 16 ##gstr_@0 sys 2376 ##cstr_@1 sys 2408"
data  "chr 16 ##sys@0 bstr 2384"
data  "wchr 16 ##sys@0 bstring2 2544"
data  "str 16 ##fpu@0 bstr 2520 ##fpu#sys@00 bstr 200 "
data  "hex 16 ##fpu#sys@00 bstr 216 ##fpu@0 bstr 208 "
data  "guidval 16 ##guid#bstr@10 sys 352  ##guid#zstring@11 sys 352"
data  "guidtxt 16 ##guid@1 bstr 360"
data  "numberformat 16 ##sys#sys#sys#sys#sys#sys@000000 sys 2552 ##@ sys 2560 "


'===========================
'>>FLOATING POINT MACRO
' macro function
'===========================


data  "abs 17 fabs"
data  "acos 17 fld st0 : fmul st0 : fld1 : fsubp st1,st0 : fchs : fsqrt : fxch : fpatan"
data  "asin 17 fld st0 : fmul st0 : fld1 : fsubp st1,st0 : fchs : fsqrt : fpatan"
data  "atan  17 fpatan"
data  "atn 17 fld1 : fpatan"
data  "cos 17 fcos"
data  "deg 17 fldpi : fdivp st1 : |sp -8 : mov [esp],180 : fimul dword [esp] : |sp 8"
data   "frac 17 fld1 : fxch : fprem : fstp st1"
'data  "frac 17 |sp -8 : fstcw [esp] : fstcw [esp+2] : or [esp],0xc00 : fldcw [esp]"+cr+_
'      "fld st0 : frndint : fsubp st1,st0 : fldcw [esp+2] : |sp 8"
data  "hypot 17 fmul st0 : fxch : fmul st0 : faddp st1 : fsqrt"
data  "lin 17 fldln2 : fxch : fyl2x"
data  "log 17 fldln2 : fxch : fyl2x"
data  "log2 17 fld1 : fxch : fyl2x"
data  "log10 17 fldlg2 : fxch : fyl2x"
data  "logn 17 fld1 : fxch st1 : fyl2x : fld1 : fdivrp st1 : fxch st1 : fyl2x"
data  "mod 17 fxch st1 : fprem : fstp st1"
data  "pi 17 fldpi"
data  "exp 17 "+exponents
data  "pow 17 "+powers
data  "rad 17 fldpi : fmulp st1 : |sp -8 : mov [esp],180 : fidiv dword [esp] : |sp 8"
data  "recip 17 fld1 : fdivrp"
data  "round 17 frndint"
data  "sgn 17 fldz : fcomip : ( :  jnz exit : fldz : jmp fwd _sd : ) : "+_
      " ( : ja exit : fld1 : jmp fwd _sd : ) : ( : jb exit : fld1 : fchs : jmp fwd _sd : ) : "+_
      "._sd : fxch : fstp st0"
data  "sin 17 fsin"
data  "sqr 17 fsqrt"
data  "sqrt 17 fsqrt"
data  "tan 17 fptan : fstp st0"
data  "floor 17 |sp -8 : fstcw [esp] : fstcw [esp+4] : and word [esp],0xf3ff : or word [esp],0x400 : fldcw [esp]"+cr+_
      "frndint : fldcw [esp+4] : |sp 8"
data  "ceil 17 |sp -8 : fstcw [esp] : fstcw [esp+4] : and word [esp],0xf3ff : or word [esp],0x800 : fldcw [esp]"+cr+_
      "frndint : fldcw [esp+4] : |sp 8"
data  "trunc 17 |sp -8 : fstcw [esp] : fstcw [esp+4] : or word [esp],0xc00 : fldcw [esp]"+cr+_
      "frndint : fldcw [esp+4] : |sp 8"
'data   "trunc 17 fld1 : fld st1 : fprem : fsubp st2 : fstp st0"


'===========================

data "" ,0,0 'mark end of data

'===========================
'>>REGISTERS
'===========================

x86_registers:

' regsize regno regtype

data "al    10 101"
data "cl    10 111"
data "dl    10 121"
data "bl    10 131"
data "ah    10 141"
data "ch    10 151"
data "dh    10 161"
data "bh    10 171"
'---------------------------
data "ax    10 201"
data "cx    10 211"
data "dx    10 221"
data "bx    10 231"
data "sp    10 241"
data "bp    10 251"
data "si    10 261"
data "di    10 271"
'---------------------------
data "eax   10 401"
data "ecx   10 411"
data "edx   10 421"
data "ebx   10 431"
data "esp   10 441"
data "ebp   10 451"
data "esi   10 461"
data "edi   10 471"
'---------------------------
data "st0   10 A02"
data "st1   10 A12"
data "st2   10 A22"
data "st3   10 A32"
data "st4   10 A42"
data "st5   10 A52"
data "st6   10 A62"
data "st7   10 A72"
'---------------------------
data "mmx0  10 F03" 
data "mmx1  10 F13" 
data "mmx2  10 F23" 
data "mmx3  10 F33" 
data "mmx4  10 F43" 
data "mmx5  10 F53" 
data "mmx6  10 F63" 
data "mmx7  10 F73" 
'---------------------------  
data "xmm0  10 F04"
data "xmm1  10 F14"
data "xmm2  10 F24"
data "xmm3  10 F34"
data "xmm4  10 F44"
data "xmm5  10 F54"
data "xmm6  10 F64"
data "xmm7  10 F74"
data "xmm8  10 F84"
data "xmm9  10 F94"
data "xmm10 10 FA4"
data "xmm11 10 FB4"
data "xmm12 10 FC4"
data "xmm13 10 FD4"
data "xmm14 10 FE4"
data "xmm15 10 FF4"
'---------------------------
data "cr0   10 405" '129  
data "cr2   10 415" 
data "cr3   10 425" 
data "cr4   10 435" 
'---------------------------
data "dr0   10 406" '130  
data "dr1   10 416" 
data "dr2   10 426" 
data "dr3   10 436" 
data "dr4   10 446"
data "dr5   10 456" 
data "dr6   10 466" 
data "dr7   10 476" 
'---------------------------
data "es    10 407"'131  
data "cs    10 417" 
data "ss    10 427" 
data "ds    10 437" 
data "fs    10 447"
data "gs    10 457" 
'---------------------------
'64 bit mode registers
'---------------------------
data "rax   10 809"
data "rcx   10 819"
data "rdx   10 829"
data "rbx   10 839"
data "rsp   10 849"
data "rbp   10 859"
data "rsi   10 869"
data "rdi   10 879"
data "r8    10 889"
data "r9    10 899"
data "r10   10 8A9"
data "r11   10 8B9"
data "r12   10 8C9"
data "r13   10 8D9"
data "r14   10 8E9"
data "r15   10 8F9"
'---------------------------
data "r8l   10 489"
data "r9l   10 499"
data "r10l  10 4A9"
data "r11l  10 4B9"
data "r12l  10 4C9"
data "r13l  10 4D9"
data "r14l  10 4E9"
data "r15l  10 4F9"
'---------------------------
data "r8w   10 289"
data "r9w   10 299"
data "r10w  10 2A9"
data "r11w  10 2B9"
data "r12w  10 2C9"
data "r13w  10 2D9"
data "r14w  10 2E9"
data "r15w  10 2F9"
'---------------------------
data "r8d   10 489"
data "r9d   10 499"
data "r10d  10 4A9"
data "r11d  10 4B9"
data "r12d  10 4C9"
data "r13d  10 4D9"
data "r14d  10 4E9"
data "r15d  10 4F9"


'=================================
data "" 'end of data x86 registers
'=================================



'===
'END
'===


