diff --git a/programs/develop/metcc/trunk/libc/clean.cmd b/programs/develop/metcc/trunk/libc/clean.cmd new file mode 100644 index 0000000000..de4b39eca7 --- /dev/null +++ b/programs/develop/metcc/trunk/libc/clean.cmd @@ -0,0 +1 @@ +compile.js clean \ No newline at end of file diff --git a/programs/develop/metcc/trunk/libc/compile.js b/programs/develop/metcc/trunk/libc/compile.js index f43bb6b8ea..956c4a451d 100644 --- a/programs/develop/metcc/trunk/libc/compile.js +++ b/programs/develop/metcc/trunk/libc/compile.js @@ -1,118 +1,128 @@ -var fso=new ActiveXObject("Scripting.FileSystemObject"); -var wsh=WScript.CreateObject("WScript.Shell"); -var curpath="."; -var gccpath="c:\\program files\\MinGW\\MinGW\\bin\\"; -//var gccpath="cmd.exe /c "; -var gccexe="\""+gccpath+"cc1.exe"+"\" "; -var asexe="\""+gccpath+"as.exe"+"\" "; -var objcopyexe="\""+gccpath+"objcopy.exe"+"\" "; -//var gccexe=gccpath+"cc1.exe" ; -//var asexe=gccpath+"as.exe"; -var scriptline="CREATE melibc.a\r\n"; +ForReading = 1 +ForWriting = 2 +ForAppending = 8 +var fso = new ActiveXObject("Scripting.FileSystemObject"); +var wsh = new ActiveXObject("WScript.Shell"); +function alert(mes){WScript.Echo(mes);return mes} +function debug(obj){for(key in obj)alert('['+key+']="'+obj[key]+'"')} +function getFileContent(filename){ + var file = fso.OpenTextFile(filename, ForReading); + var content = file.ReadAll(); + file.close(); + return content; +} +function include(filename){ + eval(getFileContent(filename)); +} +function Project(filename){ + var text = getFileContent(filename); + eval("var config = {"+text+"};") + for(key in config) this[key] = config[key]; + if(!this.files) this.files = []; + function getFileExt(name){ + var i = name.lastIndexOf("."); + return (i==-1)? "" : name.substr(i); + } + this.getFileList = function(folder){ + var f = fso.GetFolder(folder); + var fc = new Enumerator(f.SubFolders); + for (; !fc.atEnd(); fc.moveNext()) + { + var name = fc.item()+""; + if(name[0]!='.' && !this.isIgnored(name)) + this.getFileList(name); + } + delete fc; + fc = new Enumerator(f.Files); + for (; !fc.atEnd(); fc.moveNext()) + { + var name = fc.item()+""; + if(name[0]!='.' && !this.isIgnored(name)) + this.files.push(name); + } + } + this.clean = function(){ + var fl = new Enumerator(this.files); + var fo; + for (; !fl.atEnd(); fl.moveNext()){ + var file = fl.item() + switch(getFileExt(file)){ + case ".o": + case ".s": + fo = fso.GetFile(file); + fo.Delete(); + break; + } + } + delete fl; + } + var objList = []; + this.compile_asm = function(filename){ + var objname = filename.replace(/.\w{1,3}$/,".o"); + objList.push(objname); + if(fso.FileExists(objname)) return; + wsh.Run(this.fasm+' "'+filename+'" "'+objname+'"',0,true); + } + this.compile_c = function(filename){ + var objname = filename.replace(/.\w{1,3}$/,".o"); + objList.push(objname); + if(fso.FileExists(objname)) return; + var asmname = filename.replace(/.\w{1,3}$/,".s"); + var command = ""; + if(!fso.FileExists(asmname)){ + command = this.gccpath +"\\"+ this.gccexe + " -nostdinc"; + if(this.include) command += " -I .\\include"; + command +=" -DGNUC" +' "'+filename + '" -o "' + asmname + '"'; + wsh.Run("cmd.exe /c "+command, 0, true); + } + command = this.gccpath +"\\"+ this.asexe +' "'+ asmname +'" -o "'+ objname +'"'; + wsh.Run("cmd.exe /c "+command, 0, true); + command = this.gccpath +"\\"+ this.objcopyexe +' -O elf32-i386 --remove-leading-char "'+ objname +'"'; + wsh.Run("cmd.exe /c "+command, 0, true); + } + this.build = function(){ + var fl = new Enumerator(this.files); + for (; !fl.atEnd(); fl.moveNext()){ + var file = fl.item() + switch(getFileExt(file)){ + case ".c": this.compile_c(file);break; + case ".asm": this.compile_asm(file);break; + case ".o": objList.push(file);break; + } + } + delete fl; + fl = new Enumerator(objList); + +/* var file = fso.CreateTextFile("OBJLIST.TXT", true); + file.Write("CREATE "+this.dstpath+'\\'+this.name+".a\r\n"); + for (; !fl.atEnd(); fl.moveNext()){file.Write("ADDMOD "+fl.item()+"\r\n");} + file.Write("SAVE\r\t"); + file.Close(); + wsh.Run(this.gccpath+"\\ar.exe -M < OBJLIST.TXT", 0, true);*/ + + var ar = wsh.Exec(this.gccpath+"\\ar.exe -M") + ar.StdIn.Write("CREATE "+this.dstpath+'\\'+this.name+".a\r\n"); + for (; !fl.atEnd(); fl.moveNext()){ar.StdIn.Write("ADDMOD "+fl.item()+"\r\n");} + ar.StdIn.Write("SAVE\r\t"); + } + this.rebuild = function(){ + this.clean(); + this.build(); + } + this.isIgnored = function(value){ + for(var i=0; i + \{ define@proc name, \{ prologue name,flag,parmbytes,localbytes,reglist \} + macro locals + \{ virtual at ebp-localbytes+current + macro label . \\{ deflocal@proc .,:, \\} + struc db [val] \\{ \common deflocal@proc .,db,val \\} + struc dw [val] \\{ \common deflocal@proc .,dw,val \\} + struc dp [val] \\{ \common deflocal@proc .,dp,val \\} + struc dd [val] \\{ \common deflocal@proc .,dd,val \\} + struc dt [val] \\{ \common deflocal@proc .,dt,val \\} + struc dq [val] \\{ \common deflocal@proc .,dq,val \\} + struc rb cnt \\{ deflocal@proc .,rb cnt, \\} + struc rw cnt \\{ deflocal@proc .,rw cnt, \\} + struc rp cnt \\{ deflocal@proc .,rp cnt, \\} + struc rd cnt \\{ deflocal@proc .,rd cnt, \\} + struc rt cnt \\{ deflocal@proc .,rt cnt, \\} + struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} + macro endl + \{ purge label + restruc db,dw,dp,dd,dt,dq + restruc rb,rw,rp,rd,rt,rq + restruc byte,word,dword,pword,tword,qword + current = $-(ebp-localbytes) + end virtual \} + macro ret operand + \{ match any, operand \\{ retn operand \\} + match , operand \\{ match epilogue:reglist, epilogue@proc: + \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} + macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2 + end if \} } + +macro defargs@proc [arg] + { common + if ~ arg eq + forward + local ..arg,current@arg + match argname:type, arg + \{ current@arg equ argname + label ..arg type + argname equ ..arg + if dqword eq type + dd ?,?,?,? + else if tbyte eq type + dd ?,?,? + else if qword eq type | pword eq type + dd ?,? + else + dd ? + end if \} + match =current@arg,current@arg + \{ current@arg equ arg + arg equ ..arg + ..arg dd ? \} + common + args@proc equ current@arg + forward + restore current@arg + common + end if } + +macro deflocal@proc name,def,[val] + { common + match vars, all@vars \{ all@vars equ all@vars, \} + all@vars equ all@vars name + forward + local ..var,..tmp + ..var def val + match =?, val \{ ..tmp equ \} + match any =dup (=?), val \{ ..tmp equ \} + match tmp : value, ..tmp : val + \{ tmp: end virtual + initlocal@proc ..var,def value + virtual at tmp\} + common + match first rest, ..var, \{ name equ first \} } + +macro initlocal@proc name,def + { virtual at name + def + size@initlocal = $ - name + end virtual + position@initlocal = 0 + while size@initlocal > position@initlocal + virtual at name + def + if size@initlocal - position@initlocal < 2 + current@initlocal = 1 + load byte@initlocal byte from name+position@initlocal + else if size@initlocal - position@initlocal < 4 + current@initlocal = 2 + load word@initlocal word from name+position@initlocal + else + current@initlocal = 4 + load dword@initlocal dword from name+position@initlocal + end if + end virtual + if current@initlocal = 1 + mov byte [name+position@initlocal],byte@initlocal + else if current@initlocal = 2 + mov word [name+position@initlocal],word@initlocal + else + mov dword [name+position@initlocal],dword@initlocal + end if + position@initlocal = position@initlocal + current@initlocal + end while } + +macro endp + { purge ret,locals,endl + finish@proc + purge finish@proc + restore regs@proc + match all,args@proc \{ restore all \} + restore args@proc + match all,all@vars \{ restore all \} } + +macro local [var] + { common + locals + forward done@local equ + match varname[count]:vartype, var + \{ match =BYTE, vartype \\{ varname rb count + restore done@local \\} + match =WORD, vartype \\{ varname rw count + restore done@local \\} + match =DWORD, vartype \\{ varname rd count + restore done@local \\} + match =PWORD, vartype \\{ varname rp count + restore done@local \\} + match =QWORD, vartype \\{ varname rq count + restore done@local \\} + match =TBYTE, vartype \\{ varname rt count + restore done@local \\} + match =DQWORD, vartype \\{ label varname dqword + rq count+count + restore done@local \\} + match , done@local \\{ virtual + varname vartype + end virtual + rb count*sizeof.\#vartype + restore done@local \\} \} + match :varname:vartype, done@local:var + \{ match =BYTE, vartype \\{ varname db ? + restore done@local \\} + match =WORD, vartype \\{ varname dw ? + restore done@local \\} + match =DWORD, vartype \\{ varname dd ? + restore done@local \\} + match =PWORD, vartype \\{ varname dp ? + restore done@local \\} + match =QWORD, vartype \\{ varname dq ? + restore done@local \\} + match =TBYTE, vartype \\{ varname dt ? + restore done@local \\} + match =DQWORD, vartype \\{ label varname dqword + dq ?,? + restore done@local \\} + match , done@local \\{ varname vartype + restore done@local \\} \} + match ,done@local + \{ var + restore done@local \} + common + endl } diff --git a/programs/develop/metcc/trunk/libc/public_stdcall.inc b/programs/develop/metcc/trunk/libc/public_stdcall.inc new file mode 100644 index 0000000000..83bd601c14 --- /dev/null +++ b/programs/develop/metcc/trunk/libc/public_stdcall.inc @@ -0,0 +1,7 @@ +macro public_stdcall name,size +{ + public name + public name#@#size + name: + name#@#size: +} diff --git a/programs/develop/metcc/trunk/libc/start/debug-fdo.inc b/programs/develop/metcc/trunk/libc/start/debug-fdo.inc new file mode 100644 index 0000000000..ecfd0fcc84 --- /dev/null +++ b/programs/develop/metcc/trunk/libc/start/debug-fdo.inc @@ -0,0 +1,422 @@ +; +; Formatted Debug Output (FDO) +; Copyright (c) 2005-2006, mike.dld +; Created: 2005-01-29, Changed: 2006-11-10 +; +; For questions and bug reports, mail to mike.dld@gmail.com +; +; Available format specifiers are: %s, %d, %u, %x (with partial width support) +; + +; to be defined: +; __DEBUG__ equ 1 +; __DEBUG_LEVEL__ equ 5 + +macro debug_func name { + if used name + name@of@func equ name +} + +macro debug_beginf { + align 4 + name@of@func: +} + +debug_endf fix end if + +macro DEBUGS _sign,[_str] { + common + local tp + tp equ 0 + match _arg:_num,_str \{ + DEBUGS_N _sign,_num,_arg + tp equ 1 + \} + match =0 _arg,tp _str \{ + DEBUGS_N _sign,,_arg + \} +} + +macro DEBUGS_N _sign,_num,[_str] { + common + pushf + pushad + local ..str,..label,is_str + is_str = 0 + forward + if _str eqtype '' + is_str = 1 + end if + common + if is_str = 1 + jmp ..label + ..str db _str,0 + ..label: + add esp,4*8+4 + mov edx,..str + sub esp,4*8+4 + else + mov edx,_str + end if + if ~_num eq + if _num eqtype eax + if _num in + mov esi,_num + else if ~_num eq esi + movzx esi,_num + end if + else if _num eqtype 0 + mov esi,_num + else + local tp + tp equ 0 + match [_arg],_num \{ + mov esi,dword[_arg] + tp equ 1 + \} + match =0 =dword[_arg],tp _num \{ + mov esi,dword[_arg] + tp equ 1 + \} + match =0 =word[_arg],tp _num \{ + movzx esi,word[_arg] + tp equ 1 + \} + match =0 =byte[_arg],tp _num \{ + movzx esi,byte[_arg] + tp equ 1 + \} + match =0,tp \{ + 'Error: specified string width is incorrect' + \} + end if + else + mov esi,0x7FFFFFFF + end if + call fdo_debug_outstr + popad + popf +} + +macro DEBUGD _sign,_dec { + local tp + tp equ 0 + match _arg:_num,_dec \{ + DEBUGD_N _sign,_num,_arg + tp equ 1 + \} + match =0 _arg,tp _dec \{ + DEBUGD_N _sign,,_arg + \} +} + +macro DEBUGD_N _sign,_num,_dec { + pushf + pushad + if (~_num eq) + if (_dec eqtype eax | _dec eqtype 0) + 'Error: precision allowed only for in-memory variables' + end if + if (~_num in <1,2,4>) + if _sign + 'Error: 1, 2 and 4 are only allowed for precision in %d' + else + 'Error: 1, 2 and 4 are only allowed for precision in %u' + end if + end if + end if + if _dec eqtype eax + if _dec in + mov eax,_dec + else if ~_dec eq eax + if _sign = 1 + movsx eax,_dec + else + movzx eax,_dec + end if + end if + else if _dec eqtype 0 + mov eax,_dec + else + add esp,4*8+4 + if _num eq + mov eax,dword _dec + else if _num = 1 + if _sign = 1 + movsx eax,byte _dec + else + movzx eax,byte _dec + end if + else if _num = 2 + if _sign = 1 + movsx eax,word _dec + else + movzx eax,word _dec + end if + else + mov eax,dword _dec + end if + sub esp,4*8+4 + end if + mov cl,_sign + call fdo_debug_outdec + popad + popf +} + +macro DEBUGH _sign,_hex { + local tp + tp equ 0 + match _arg:_num,_hex \{ + DEBUGH_N _sign,_num,_arg + tp equ 1 + \} + match =0 _arg,tp _hex \{ + DEBUGH_N _sign,,_arg + \} +} + +macro DEBUGH_N _sign,_num,_hex { + pushf + pushad + if (~_num eq) & (~_num in <1,2,3,4,5,6,7,8>) + 'Error: 1..8 are only allowed for precision in %x' + end if + if _hex eqtype eax + if _hex in + if ~_hex eq eax + mov eax,_hex + end if + else if _hex in + if ~_hex eq ax + movzx eax,_hex + end if + shl eax,16 + if (_num eq) + mov edx,4 + end if + else if _hex in + if ~_hex eq al + movzx eax,_hex + end if + shl eax,24 + if (_num eq) + mov edx,2 + end if + end if + else if _hex eqtype 0 + mov eax,_hex + else + add esp,4*8+4 + mov eax,dword _hex + sub esp,4*8+4 + end if + if ~_num eq + mov edx,_num + else + mov edx,8 + end if + call fdo_debug_outhex + popad + popf +} + +;----------------------------------------------------------------------------- + +debug_func fdo_debug_outchar +debug_beginf + pushad + mov cl,al + mov ebx,1 + mov eax,63 + int 0x40 + popad + ret +debug_endf + +debug_func fdo_debug_outstr +debug_beginf + mov eax,63 + mov ebx,1 + .l1: dec esi + js .l2 + mov cl,[edx] + or cl,cl + jz .l2 + int 0x40 + inc edx + jmp .l1 + .l2: ret +debug_endf + +debug_func fdo_debug_outdec +debug_beginf + or cl,cl + jz @f + or eax,eax + jns @f + neg eax + push eax + mov al,'-' + call fdo_debug_outchar + pop eax + @@: push 10 + pop ecx + push -'0' + .l1: xor edx,edx + div ecx + push edx + test eax,eax + jnz .l1 + .l2: pop eax + add al,'0' + jz .l3 + call fdo_debug_outchar + jmp .l2 + .l3: ret +debug_endf + +debug_func fdo_debug_outhex + __fdo_hexdigits db '0123456789ABCDEF' +debug_beginf + mov cl,dl + neg cl + add cl,8 + shl cl,2 + rol eax,cl + .l1: rol eax,4 + push eax + and eax,0x0000000F + mov al,[__fdo_hexdigits+eax] + call fdo_debug_outchar + pop eax + dec edx + jnz .l1 + ret +debug_endf + +;----------------------------------------------------------------------------- + +macro DEBUGF _level,_format,[_arg] { + common + if __DEBUG__ = 1 & _level >= __DEBUG_LEVEL__ + local ..f1,f2,a1,a2,c1,c2,c3,..lbl + _debug_str_ equ __debug_str_ # a1 + a1 = 0 + c2 = 0 + c3 = 0 + f2 = 0 + repeat ..lbl-..f1 + virtual at 0 + db _format,0,0 + load c1 word from %-1 + end virtual + if c1 = '%s' + virtual at 0 + db _format,0,0 + store word 0 at %-1 + load c1 from f2-c2 + end virtual + if c1 <> 0 + DEBUGS 0,_debug_str_+f2-c2 + end if + c2 = c2 + 1 + f2 = %+1 + DEBUGF_HELPER S,a1,0,_arg + else if c1 = '%x' + virtual at 0 + db _format,0,0 + store word 0 at %-1 + load c1 from f2-c2 + end virtual + if c1 <> 0 + DEBUGS 0,_debug_str_+f2-c2 + end if + c2 = c2 + 1 + f2 = %+1 + DEBUGF_HELPER H,a1,0,_arg + else if c1 = '%d' | c1 = '%u' + local c4 + if c1 = '%d' + c4 = 1 + else + c4 = 0 + end if + virtual at 0 + db _format,0,0 + store word 0 at %-1 + load c1 from f2-c2 + end virtual + if c1 <> 0 + DEBUGS 0,_debug_str_+f2-c2 + end if + c2 = c2 + 1 + f2 = %+1 + DEBUGF_HELPER D,a1,c4,_arg + else if c1 = '\n' + c3 = c3 + 1 + end if + end repeat + virtual at 0 + db _format,0,0 + load c1 from f2-c2 + end virtual + if (c1<>0)&(f2<>..lbl-..f1-1) + DEBUGS 0,_debug_str_+f2-c2 + end if + virtual at 0 + ..f1 db _format,0 + ..lbl: + __debug_strings equ __debug_strings,_debug_str_,<_format>,..lbl-..f1-1-c2-c3 + end virtual + end if +} + +macro __include_debug_strings dummy,[_id,_fmt,_len] { + common + local c1,a1,a2 + forward + if defined _len & ~_len eq + _id: + a1 = 0 + a2 = 0 + repeat _len + virtual at 0 + db _fmt,0,0 + load c1 word from %+a2-1 + end virtual + if (c1='%s')|(c1='%x')|(c1='%d')|(c1='%u') + db 0 + a2 = a2 + 1 + else if (c1='\n') + dw $0A0D + a1 = a1 + 1 + a2 = a2 + 1 + else + db c1 and 0x0FF + end if + end repeat + db 0 + end if +} + +macro DEBUGF_HELPER _letter,_num,_sign,[_arg] { + common + local num + num = 0 + forward + if num = _num + DEBUG#_letter _sign,_arg + end if + num = num+1 + common + _num = _num+1 +} + +macro include_debug_strings { + if __DEBUG__ = 1 + match dbg_str,__debug_strings \{ + __include_debug_strings dbg_str + \} + end if +} diff --git a/programs/develop/metcc/trunk/libc/start/macros.inc b/programs/develop/metcc/trunk/libc/start/macros.inc new file mode 100644 index 0000000000..ecf51616f1 --- /dev/null +++ b/programs/develop/metcc/trunk/libc/start/macros.inc @@ -0,0 +1,337 @@ +; language for programs +lang fix en ; ru en fr ge fi + +@^ fix macro comment { +^@ fix } + +; strings +macro sz name,[data] { ; from MFAR [mike.dld] + common + if used name + name db data + .size = $-name + end if +} + +macro lsz name,[lng,data] { ; from MFAR [mike.dld] + common + if used name + label name + forward + if lang eq lng + db data + end if + common + .size = $-name + end if +} + +macro szc name,elsz,[data] { ; from MFAR [mike.dld] + common + local s,m + m = 0 + if used name + label name + virtual at 0 + db data + s = $ + end virtual + d#elsz s + if m < s + m = s + end if + db data + .size = $-name + .maxl = m + end if +} + +macro lszc name,elsz,[lng,data] { ; from MFAR [mike.dld] + common + local s,m + m = 0 + if used name + label name + forward + if lang eq lng + virtual at 0 + db data + s = $ + end virtual + d#elsz s + if m < s + m = s + end if + db data + end if + common + .size = $-name + .maxl = m + end if +} + + +; easy system call macro +macro mpack dest, hsrc, lsrc +{ + if (hsrc eqtype 0) & (lsrc eqtype 0) + mov dest, (hsrc) shl 16 + lsrc + else + if (hsrc eqtype 0) & (~lsrc eqtype 0) + mov dest, (hsrc) shl 16 + add dest, lsrc + else + mov dest, hsrc + shl dest, 16 + add dest, lsrc + end if + end if +} + +macro __mov reg,a,b { ; mike.dld + if (~a eq)&(~b eq) + mpack reg,a,b + else if (~a eq)&(b eq) + mov reg,a + end if +} + +macro mcall a,b,c,d,e,f { ; mike.dld + __mov eax,a + __mov ebx,b + __mov ecx,c + __mov edx,d + __mov esi,e + __mov edi,f + int 0x40 +} + +; ------------------------- +macro header a,[b] { + common + use32 + org 0 + db 'MENUET',a + forward + if b eq + dd 0 + else + dd b + end if } +macro section name,algn + { + local boundary + boundary = 16 + if ~algn eq + boundary = algn + end if + align boundary + label name + } +macro func name { + if ~used name + display 'FUNC NOT USED: ',`name,13,10 + else + align 4 + name: +;pushad +;pushfd +;dps `name +;newline +;mcall 5,1 +;popfd +;popad +} +macro endf { end if } + +macro jif _op1,_cond,_op2,_label,_op + { + if _op eq + cmp _op1,_op2 + else + _op _op1,_op2 + end if + j#_cond _label + } + +macro diff16 title,l1,l2 + { + local s,d + s = l2-l1 + display title,': 0x' + repeat 8 + d = '0' + s shr ((8-%) shl 2) and $0F + if d > '9' + d = d + 'A'-'9'-1 + end if + display d + end repeat + display 13,10 + } + +macro diff10 title,l1,l2 + { + local s,d,z,m + s = l2-l1 + z = 0 + m = 1000000000 + display title,': ' + repeat 10 + d = '0' + s / m + s = s - (s/m)*m + m = m / 10 + if d <> '0' + z = 1 + end if + if z <> 0 + display d + end if + end repeat + display 13,10 + } + +; optimize the code for size +__regs fix + +macro add arg1,arg2 + { + if (arg2 eqtype 0) + if (arg2) = 1 + inc arg1 + else + add arg1,arg2 + end if + else + add arg1,arg2 + end if + } + +macro sub arg1,arg2 + { + if (arg2 eqtype 0) + if (arg2) = 1 + dec arg1 + else + sub arg1,arg2 + end if + else + sub arg1,arg2 + end if + } + +macro mov arg1,arg2 + { + if (arg1 in __regs) & (arg2 eqtype 0) + if (arg2) = 0 + xor arg1,arg1 + else if (arg2) = 1 + xor arg1,arg1 + inc arg1 + else if (arg2) = -1 + or arg1,-1 + else if (arg2) > -128 & (arg2) < 128 + push arg2 + pop arg1 + else + mov arg1,arg2 + end if + else + mov arg1,arg2 + end if + } + + +struc POINT _t,_dx,_dy { + .x _t _dx + .y _t _dy +} + +; structure definition helper +macro struct name, [arg] + { + common + name@struct fix name + struc name arg { + } + +macro struct_helper name + { + virtual at 0 + name name + sizeof.#name = $ - name + name equ sizeof.#name + end virtual + } + +ends fix } struct_helper name@struct + +macro union [def] + { + common size@union = 0 + origin@union = $ + forward virtual + def + if $-origin@union > size@union + size@union = $-origin@union + end if + end virtual + common rb size@union + } + +; structures used in MeOS +struc process_information +{ + .cpu_usage dd ? ; +0 + .window_stack_position dw ? ; +4 + .window_stack_value dw ? ; +6 + .not_used1 dw ? ; +8 + .process_name rb 12 ; +10 + .memory_start dd ? ; +22 + .used_memory dd ? ; +26 + .PID dd ? ; +30 + .x_start dd ? ; +34 + .y_start dd ? ; +38 + .x_size dd ? ; +42 + .y_size dd ? ; +46 + .slot_state dw ? ; +50 + rb (1024-52) +} + +struc system_colors +{ + .frame dd ? + .grab dd ? + .grab_button dd ? + .grab_button_text dd ? + .grab_text dd ? + .work dd ? + .work_button dd ? + .work_button_text dd ? + .work_text dd ? + .work_graph dd ? +} + + +; constants + +; events +EV_IDLE = 0 +EV_TIMER = 0 +EV_REDRAW = 1 +EV_KEY = 2 +EV_BUTTON = 3 +EV_EXIT = 4 +EV_BACKGROUND = 5 +EV_MOUSE = 6 +EV_IPC = 7 +EV_STACK = 8 + +; event mask bits for function 40 +EVM_REDRAW = 1b +EVM_KEY = 10b +EVM_BUTTON = 100b +EVM_EXIT = 1000b +EVM_BACKGROUND = 10000b +EVM_MOUSE = 100000b +EVM_IPC = 1000000b +EVM_STACK = 10000000b \ No newline at end of file diff --git a/programs/develop/metcc/trunk/libc/start/start.asm b/programs/develop/metcc/trunk/libc/start/start.asm index 30204dfbe9..be6adf70ab 100644 --- a/programs/develop/metcc/trunk/libc/start/start.asm +++ b/programs/develop/metcc/trunk/libc/start/start.asm @@ -3,31 +3,35 @@ section '.text' executable public start extrn mf_init extrn main -;include 'debug2.inc' -__DEBUG__=0 + +__DEBUG__ equ 1 +__DEBUG_LEVEL__ equ 1 + +include 'DEBUG-FDO.INC' + virtual at 0 - db 'MENUET01' ; 1. Magic number (8 bytes) - dd 0x01 ; 2. Version of executable file - dd 0x0 ; 3. Start address - dd 0x0 ; 4. Size of image - dd 0x100000 ; 5. Size of needed memory - dd 0x100000 ; 6. Pointer to stack -hparams dd 0x0 ; 7. Pointer to program arguments -hpath dd 0x0 ; 8. Pointer to program path + db 'MENUET01' ; 1. Magic number (8 bytes) + dd 0x01 ; 2. Version of executable file + dd 0x0 ; 3. Start address + dd 0x0 ; 4. Size of image + dd 0x100000 ; 5. Size of needed memory + dd 0x100000 ; 6. Pointer to stack +hparams dd 0x0 ; 7. Pointer to program arguments +hpath dd 0x0 ; 8. Pointer to program path end virtual start: -;DEBUGF 'Start programm\n' +DEBUGF 1,'Start programm\n' xor eax,eax call mf_init -;DEBUGF ' path "%s"\n params "%s"\n', .path, .params +DEBUGF 1,' path "%s"\n params "%s"\n', path, params ; check for overflow mov al, [path+buf_len-1] - or al, [params+buf_len-1] + or al, [params+buf_len-1] jnz .crash ; check if path written by OS mov eax, [hparams] test eax, eax - jz .without_path + jz .without_path mov eax, path .without_path: mov esi, eax @@ -35,21 +39,21 @@ start: ; retrieving parameters mov esi, params xor edx, edx ; dl - идёт параметр(1) или разделители(0) - ; dh - символ с которого начался параметр (1 кавычки, 0 остальное) + ; dh - символ с которого начался параметр (1 кавычки, 0 остальное) mov ecx, 1 ; cl = 1 - ; ch = 0 просто ноль + ; ch = 0 просто ноль .parse: lodsb test al, al - jz .run + jz .run test dl, dl jnz .findendparam - ;{если был разделитель + ;{если был разделитель cmp al, ' ' - jz .parse ;загружен пробел, грузим следующий символ + jz .parse ;загружен пробел, грузим следующий символ mov dl, cl ;начинается параметр cmp al, '"' - jz @f ;загружены кавычки + jz @f ;загружены кавычки mov dh, ch ;параметр без кавычек dec esi call push_param @@ -63,9 +67,9 @@ start: .findendparam: test dh, dh - jz @f ; без кавычек + jz @f ; без кавычек cmp al, '"' - jz .clear + jz .clear jmp .parse @@: cmp al, ' ' @@ -78,25 +82,25 @@ start: jmp .parse .run: -;DEBUGF 'call main(%x, %x) with params:\n', [argc], argv +DEBUGF 1,'call main(%x, %x) with params:\n', [argc], argv if __DEBUG__ = 1 mov ecx, [argc] @@: lea esi, [ecx * 4 + argv-4] - DEBUGF '0x%x) "%s"\n', cx, [esi] + DEBUGF 1,'%d) "%s"\n', cx, [esi] loop @b end if - push [argc] push argv + push [argc] call main .exit: -;DEBUGF 'Exit from prog\n'; +DEBUGF 1,'Exit from prog with code: %x\n', eax; xor eax,eax dec eax int 0x40 - dd -1 + dd -1 .crash: -;DEBUGF 'E:buffer overflowed\n' +DEBUGF 1,'E:buffer overflowed\n' jmp .exit ;============================ push_param: @@ -121,10 +125,10 @@ public path as '__path' section '.bss' buf_len = 0x400 max_parameters=0x20 -argc rd 1 -argv rd max_parameters -path rb buf_len -params rb buf_len +argc rd 1 +argv rd max_parameters +path rb buf_len +params rb buf_len -;section '.data' -;include_debug_strings ; ALWAYS present in data section \ No newline at end of file +section '.data' +include_debug_strings ; ALWAYS present in data section \ No newline at end of file diff --git a/programs/develop/metcc/trunk/libc/string/atoi.c b/programs/develop/metcc/trunk/libc/string/atoi.c new file mode 100644 index 0000000000..70ef2d6323 --- /dev/null +++ b/programs/develop/metcc/trunk/libc/string/atoi.c @@ -0,0 +1,21 @@ +#include "stdio.h" +#include "stdlib.h" +#include "ctype.h" + + +/* +** atoi(s) - convert s to integer. +*/ +int atoi(char *s) +{ + int sign, n; + while(isspace(*s)) ++s; + sign = 1; + switch(*s) { + case '-': sign = -1; + case '+': ++s; + } + n = 0; + while(isdigit(*s)) n = 10 * n + *s++ - '0'; + return (sign * n); +} diff --git a/programs/develop/metcc/trunk/libc/string/atoib.cpp b/programs/develop/metcc/trunk/libc/string/atoib.cpp new file mode 100644 index 0000000000..70c102bf95 --- /dev/null +++ b/programs/develop/metcc/trunk/libc/string/atoib.cpp @@ -0,0 +1,22 @@ +#include "stdio.h" +#include "stdlib.h" +#include "ctype.h" + +/* +** atoib(s,b) - Convert s to "unsigned" integer in base b. +** NOTE: This is a non-standard function. +*/ +int atoib(char *s,int b) +{ + int n, digit; + n = 0; + while(isspace(*s)) ++s; + while((digit = (127 & *s++)) >= '0') { + if(digit >= 'a') digit -= 87; + else if(digit >= 'A') digit -= 55; + else digit -= '0'; + if(digit >= b) break; + n = b * n + digit; + } + return (n); + } diff --git a/programs/develop/metcc/trunk/libc/string/is.c b/programs/develop/metcc/trunk/libc/string/is.c new file mode 100644 index 0000000000..19265ec0d1 --- /dev/null +++ b/programs/develop/metcc/trunk/libc/string/is.c @@ -0,0 +1,19 @@ +#include "ctype.h" +char __is[128] = { + 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, + 0x004, 0x104, 0x104, 0x104, 0x104, 0x104, 0x004, 0x004, + 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, + 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, + 0x140, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, + 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, + 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, 0x459, + 0x459, 0x459, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, + 0x0D0, 0x653, 0x653, 0x653, 0x653, 0x653, 0x653, 0x253, + 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, + 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, 0x253, + 0x253, 0x253, 0x253, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x0D0, + 0x0D0, 0x473, 0x473, 0x473, 0x473, 0x473, 0x473, 0x073, + 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, + 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, 0x073, + 0x073, 0x073, 0x073, 0x0D0, 0x0D0, 0x0D0, 0x0D0, 0x004 + }; diff --git a/programs/develop/metcc/trunk/libc/string/itoa.c b/programs/develop/metcc/trunk/libc/string/itoa.c new file mode 100644 index 0000000000..35b3bd455c --- /dev/null +++ b/programs/develop/metcc/trunk/libc/string/itoa.c @@ -0,0 +1,21 @@ +#include "stdio.h" +#include "stdlib.h" +#include "ctype.h" + +/* +** itoa(n,s) - Convert n to characters in s +*/ +void itoa(int n,char* s) +{ + int sign; + char *ptr; + ptr = s; + if ((sign = n) < 0) n = -n; + do { + *ptr++ = n % 10 + '0'; + } while ((n = n / 10) > 0); + if (sign < 0) *ptr++ = '-'; + *ptr = '\0'; + reverse(s); +} + diff --git a/programs/develop/metcc/trunk/libc/string/itoab.c b/programs/develop/metcc/trunk/libc/string/itoab.c new file mode 100644 index 0000000000..ac5fb114e6 --- /dev/null +++ b/programs/develop/metcc/trunk/libc/string/itoab.c @@ -0,0 +1,24 @@ +#include "stdio.h" +#include "stdlib.h" +#include "ctype.h" + +/* +** itoab(n,s,b) - Convert "unsigned" n to characters in s using base b. +** NOTE: This is a non-standard function. +*/ +void itoab(int n,char* s,int b) +{ + char *ptr; + int lowbit; + ptr = s; + b >>= 1; + do { + lowbit = n & 1; + n = (n >> 1) & 32767; + *ptr = ((n % b) << 1) + lowbit; + if(*ptr < 10) *ptr += '0'; else *ptr += 55; + ++ptr; + } while(n /= b); + *ptr = 0; + reverse (s); +} diff --git a/programs/develop/metcc/trunk/libc/string/strcat.c b/programs/develop/metcc/trunk/libc/string/strcat.c index 9f7d575df9..2d1d2c3cd4 100644 --- a/programs/develop/metcc/trunk/libc/string/strcat.c +++ b/programs/develop/metcc/trunk/libc/string/strcat.c @@ -2,12 +2,7 @@ char* strcat(char* strDest, const char* strSource) { char* res; res=strDest; - while (*strDest!='\0') strDest++; - while (*strSource!='\0') - { - *strDest=*strSource; - strDest++; - strSource++; - } + while (*strDest++) ; + while (*strDest++ = *strSource++) ; return res; } diff --git a/programs/develop/metcc/trunk/libc/string/strchr.c b/programs/develop/metcc/trunk/libc/string/strchr.c index bcf469cb36..1ac97c6de8 100644 --- a/programs/develop/metcc/trunk/libc/string/strchr.c +++ b/programs/develop/metcc/trunk/libc/string/strchr.c @@ -1,6 +1,6 @@ char* strchr(const char* string, int c) { - while (*string!='\0') + while (*string) { if (*string==c) return (char*)string; diff --git a/programs/develop/metcc/trunk/libc/string/strcpy.c b/programs/develop/metcc/trunk/libc/string/strcpy.c index dade01f84d..f0327666de 100644 --- a/programs/develop/metcc/trunk/libc/string/strcpy.c +++ b/programs/develop/metcc/trunk/libc/string/strcpy.c @@ -2,13 +2,6 @@ char* strcpy(char* strDest,char* strSource) { char* res; res=strDest; - while(1) - { - *strDest=*strSource; - if (*strSource=='\0') - break; - strDest++; - strSource++; - } + while(*strDest++ == strSource++) ; return res; -} +} \ No newline at end of file diff --git a/programs/develop/metcc/trunk/libc/string/strlen.c b/programs/develop/metcc/trunk/libc/string/strlen.c index aac63400ac..e766a7dc41 100644 --- a/programs/develop/metcc/trunk/libc/string/strlen.c +++ b/programs/develop/metcc/trunk/libc/string/strlen.c @@ -2,10 +2,6 @@ int strlen(const char* string) { int i; i=0; - while (*string!='\0') - { - i++; - string++; - } + while (*string!++) i++; return i; } diff --git a/programs/develop/metcc/trunk/libc/string/strncat.c b/programs/develop/metcc/trunk/libc/string/strncat.c index 6143ed4e4d..0ddb05db8c 100644 --- a/programs/develop/metcc/trunk/libc/string/strncat.c +++ b/programs/develop/metcc/trunk/libc/string/strncat.c @@ -2,13 +2,12 @@ char* strncat(char* strDest,const char* strSource,int count) { char* res; res=strDest; - while (*strDest!='\0') strDest++; - while (count>0 && *strSource!='\0') + while (*strDest++) ; + while(count-->0) { - *strDest=*strSource; - count--; - strDest++; - strSource++; + if(*strDest++ = *strSource++) continue; + return(res); } + *strDest = 0; return res; -} +} \ No newline at end of file diff --git a/programs/develop/metcc/trunk/libc/string/strncmp.c b/programs/develop/metcc/trunk/libc/string/strncmp.c index 0ccb00e361..1eb92f26cf 100644 --- a/programs/develop/metcc/trunk/libc/string/strncmp.c +++ b/programs/develop/metcc/trunk/libc/string/strncmp.c @@ -1,14 +1,12 @@ int strncmp(const char* string1, const char* string2, int count) { - while(count>0) + while(count>0 && *string1==*string2) { - if (*string1<*string2) - return -1; - if (*string1>*string2) - return 1; - if (*string1=='\0') - return 0; - count--; - } + if (*string1) return 0; + ++string1; + ++string2; + --count; + } + if(count) return (*string1 - *string2); return 0; -} +} \ No newline at end of file diff --git a/programs/develop/metcc/trunk/libc/string/strncpy.c b/programs/develop/metcc/trunk/libc/string/strncpy.c index 0d70a31d62..9c4b9fab2c 100644 --- a/programs/develop/metcc/trunk/libc/string/strncpy.c +++ b/programs/develop/metcc/trunk/libc/string/strncpy.c @@ -11,4 +11,4 @@ char* strncpy(char* strDest,const char* strSource,int count) count--; } return res; -} +} \ No newline at end of file diff --git a/programs/develop/metcc/trunk/libc/string/tolower.c b/programs/develop/metcc/trunk/libc/string/tolower.c new file mode 100644 index 0000000000..17945ad07b --- /dev/null +++ b/programs/develop/metcc/trunk/libc/string/tolower.c @@ -0,0 +1,8 @@ +/* +** return lower-case of c if upper-case, else c +*/ +char tolower(char c) +{ + if(c<='Z' && c>='A') return (c+32); + return (c); +} diff --git a/programs/develop/metcc/trunk/libc/string/toupper.c b/programs/develop/metcc/trunk/libc/string/toupper.c new file mode 100644 index 0000000000..a8b1becdc6 --- /dev/null +++ b/programs/develop/metcc/trunk/libc/string/toupper.c @@ -0,0 +1,8 @@ +/* +** return upper-case of c if it is lower-case, else c +*/ +char toupper(char c) +{ + if(c<='z' && c>='a') return (c-32); + return (c); +}