public static int NOPH_Canvas_get()
    {
        function_info fi = new function_info("NOPH_Canvas_get");
        fis.Add(fi.setFinishTime());

        return Syscalls.canvasHandle;
    }
    public static int NOPH_Font_getAdvance(int __font, int __text)
    {
        function_info fi = new function_info("NOPH_Font_getAdvance");

        int charwidth;

        switch (__font)
        {
            case 7:
            case 8:
                charwidth = 5;
                break;
            case 9:
            case 10:
                charwidth = 6;
                break;
            case 11:
                charwidth = 7;
                break;
            case 12:
            case 13:
                charwidth = 8;
                break;
            case 14:
                charwidth = 9;
                break;
            case 15:
            case 16:
                charwidth = 10;
                break;
            case 17:
                charwidth = 11;
                break;
            case 18:
            case 19:
                charwidth = 12;
                break;
            case 20:
                charwidth = 13;
                break;
            case 21:
            case 22:
                charwidth = 14;
                break;
            case 23:
            case 24:
                charwidth = 15;
                break;
            case 25:
                charwidth = 16;
                break;
            case 26:
            case 27:
                charwidth = 17;
                break;
            case 28:
                charwidth = 18;
                break;
            case 29:
            case 30:
                charwidth = 19;
                break;
            case 31:
            case 32:
                charwidth = 20;
                break;
            case 33:
                charwidth = 21;
                break;
            case 34:
                charwidth = 22;
                break;
            case 35:
                charwidth = 23;
                break;
            default:
                charwidth = 5;
                break;
        }

        String text = CRunTime.charPtrToString(__text);
        int ret = (int)((__font * 0.56) * text.Length);
                fis.Add(fi.setFinishTime());

        return ret;
    }
    public static int NOPH_Font_getDefault()
    {
        function_info fi = new function_info("NOPH_Font_getDefault");

        object ret = new object();
        //todomt Font ret = (Font)new Font("FreeSans",8,FontStyle.Regular);// todomt. .getDefault();
        int registeredHandle = CRunTime.registerObject(ret);
                fis.Add(fi.setFinishTime());

        return registeredHandle;
    }
    public static int NOPH_FileConnection_openInputStream(int __fc)
    {
        function_info fi = new function_info("NOPH_FileConnection_openInputStream");

        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        if (File.Exists(fc.filename))
        {
            FileStream ret = new FileStream(fc.filename, FileMode.Open, FileAccess.Read);
            fc.stream = ret;
            int registeredHandle = CRunTime.registerObject(ret);
                    fis.Add(fi.setFinishTime());

            return registeredHandle;
        }
        else
        {
                    fis.Add(fi.setFinishTime());

            return 0;
        }
    }
    public static void NOPH_FileConnection_truncate(int __fc, int byteOffest)
    {
        function_info fi = new function_info("NOPH_FileConnection_truncate");

        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        if (fc.filename.ToLower().StartsWith("userstore://"))
        {
            var store = IsolatedStorageFile.GetUserStoreForApplication();
            store.DeleteFile(fc.filename.Substring(12));
        }
        else
        {
                    fis.Add(fi.setFinishTime());

            return;
        }
                fis.Add(fi.setFinishTime());
    }
    public static void NOPH_FileConnection_delete(int __fc)
    {
        function_info fi = new function_info("NOPH_FileConnection_delete");

        NOPH_FileConnection_truncate(__fc, 0);
                fis.Add(fi.setFinishTime());
    }
    public static int NOPH_FileConnection_fileSize(int __fc)
    {
        function_info fi = new function_info("NOPH_FileConnection_fileSize");

        string name;
        FileType file_type;
        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        GetFileTypeAndName(fc.filename, out file_type, out name);

        if (file_type == FileType.USER_STORE)
        {
            var store = IsolatedStorageFile.GetUserStoreForApplication();
                    fis.Add(fi.setFinishTime());

            return store.FileExists(name) ? 1 : 0;
        }
        else
        {
                    fis.Add(fi.setFinishTime());

            return (int)GetFileStream(fc.filename, FileMode.Open).Length;
        }
    }
    public static int NOPH_DeviceInfo_getBatteryLevel()
    {
        function_info fi = new function_info("NOPH_DeviceInfo_getBatteryLevel");
        fis.Add(fi.setFinishTime());

        return 100;
    }
    public static void NOPH_DeviceSpecific_getPlatform(int addr, int size)
    {
        function_info fi = new function_info("NOPH_DeviceSpecific_getPlatform");

        //todomt
        String p = "WindowsPhone";
        byte[] bytes = StringToAscii(p);
        size--;
        if (size > bytes.Length) size = bytes.Length;
        CRunTime.memcpy(addr, bytes, 0, size);
        CRunTime.memoryWriteByte(addr + size, 0);
                fis.Add(fi.setFinishTime());
    }
    public static int NOPH_Connector_openFileConnection_mode(int __name, int mode)
    {
        function_info fi = new function_info("NOPH_Connector_openFileConnection_mode");

        String name = CRunTime.charPtrToString(__name);
        FileConnection ret = new FileConnection(name, mode);
        int registeredHandle = CRunTime.registerObject(ret);
                fis.Add(fi.setFinishTime());

        return registeredHandle;
    }
    public static void NOPH_delete(int a0)
    {
        function_info fi = new function_info("NOPH_delete");

        // todomt2 - avoid begininvoke still not running and noph_delete already called
                if (CRunTime.objectRepository[a0] is BitmapImage)
                {
                    fis.Add(fi.setFinishTime());

                    return;
                }

        // todomt2 when i will handle the above this will keep memory stable
        if (CRunTime.objectRepository[a0] is BitmapImage)
            bitmaps_info.Remove(a0);

        CRunTime.deRegisterObject(a0);

                fis.Add(fi.setFinishTime());
    }
    public static int NOPH_Connector_openDataOutputStream(int __name)
    {
        function_info fi = new function_info("NOPH_Connector_openDataOutputStream");

        /*        String name = CRunTime.charPtrToString(__name);
                DataOutputStream ret = (DataOutputStream)Connector.openDataOutputStream(name);
                int registeredHandle = CRunTime.registerObject(ret);
                return registeredHandle;*/
                fis.Add(fi.setFinishTime());

        return 1;
    }
    public static void NOPH_ConfirmDialog_CreateDialog(int __title, int __text, int defaultYes, int __textYes, int __textNo, int seconds, int yesCallback, int noCallback, int context)
    {
        function_info fi = new function_info("NOPH_ConfirmDialog_CreateDialog");

        String title = CRunTime.charPtrToString(__title);
        String text = CRunTime.charPtrToString(__text);
        String textYes = CRunTime.charPtrToString(__textYes);
        String textNo = CRunTime.charPtrToString(__textNo);

        mre.Reset();

        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
            {

                MessageBoxResult res = MessageBox.Show(text, title, MessageBoxButton.OKCancel);
                if (res == MessageBoxResult.OK || res == MessageBoxResult.Yes)
                {
                    UIWorker.addUIEvent(yesCallback, context, 0, 0, 0, true);
                }
                else
                {
                    UIWorker.addUIEvent(noCallback, context, 0, 0, 0, true);
                }
                mre.Set();
            });
        mre.WaitOne();
                fis.Add(fi.setFinishTime());
    }
    public static int NOPH_Class_getResourceAsStream(int __obj, int __name)
    {
        function_info fi = new function_info("NOPH_Class_getResourceAsStream");

        Type obj = (Type)CRunTime.objectRepository[__obj];
        String name = CRunTime.charPtrToString(__name);

        Stream ret = GetFileStream(name, FileMode.Open);
        if (ret == null)
        {
            ret = GetFileStream("userstore://" + name, FileMode.Open);
            if (ret == null)
            {
                        fis.Add(fi.setFinishTime());

                return 0;
            }
        }

        int registeredHandle = CRunTime.registerObject(ret);
                fis.Add(fi.setFinishTime());

        return registeredHandle;
    }
    public static void NOPH_FileConnection_close(int __fc)
    {
        function_info fi = new function_info("NOPH_FileConnection_close");

        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        fc.stream.Close();
                fis.Add(fi.setFinishTime());
    }
    public static void NOPH_DeviceSpecific_init(int timeout, int isRefreshThread)
    {
        function_info fi = new function_info("NOPH_DeviceSpecific_init");

        fis.Add(fi.setFinishTime());
        /*todomt2
        DeviceSpecific.init(timeout, isRefreshThread);*/
    }
    public static void NOPH_FileConnection_create(int __fc)
    {
        function_info fi = new function_info("NOPH_FileConnection_create");

        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        Stream stream = GetFileStream(fc.filename, FileMode.OpenOrCreate);
        fc.stream = stream;
        stream.Close();
                fis.Add(fi.setFinishTime());
    }
    public static void NOPH_DeviceSpecific_setBacklightOn()
    {
        function_info fi = new function_info("NOPH_DeviceSpecific_setBacklightOn");
        fis.Add(fi.setFinishTime());

        /*todomt2
        DeviceSpecific.setBacklightOn();
         */
    }
    public static int NOPH_FileConnection_exists(int __fc)
    {
        function_info fi = new function_info("NOPH_FileConnection_exists");

        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        Stream stream = GetFileStream(fc.filename, FileMode.Open);
        int exist = (stream != null) ? 1 : 0;
        if (stream != null)
        {
            stream.Close();
        }
                fis.Add(fi.setFinishTime());

        return exist;
    }
 public static int NOPH_EditBoxScreenOS5_isTouchScreenSupported()
 {
     function_info fi = new function_info("NOPH_EditBoxScreenOS5_isTouchScreenSupported");
     fis.Add(fi.setFinishTime());
     return 1;
 }
    public static int NOPH_FileConnection_openDataInputStream(int __fc)
    {
        function_info fi = new function_info("NOPH_FileConnection_openDataInputStream");

        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        Stream stream = GetFileStream(fc.filename, FileMode.Open);
        if (stream == null)
        {
            fis.Add(fi.setFinishTime());

            return 0;
        }
        else
        {
            int registeredHandle = CRunTime.registerObject(stream);
                    fis.Add(fi.setFinishTime());

            return registeredHandle;
        }
    }
    public static void NOPH_EditBoxScreenOS5_showEditBox(int i_label, int i_in_text, int in_callback, int in_data, int style)
    {
        function_info fi = new function_info("NOPH_EditBoxScreenOS5_showEditBox");
        mre.Reset();
        bool confirm = false;
        InputDialog dialog = null;
        FreeMapMainScreen mainScreen = (FreeMapMainScreen)FreeMapMainScreen.get();

        //mre.Reset();
        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
        {

            String label = CRunTime.charPtrToString(i_label);
            String in_text = CRunTime.charPtrToString(i_in_text);

            dialog = new InputDialog(mainScreen);
            dialog.SetLabelAndText(label, in_text);
            dialog.Show();

            mre.Set();
        });

        mre.WaitOne();

        dialog.dialogShowing.WaitOne();

        //mre.WaitOne();

        mre.Reset();
        System.Windows.Deployment.Current.Dispatcher.BeginInvoke(() =>
        {
            mainScreen.LayoutRoot.Children.Remove(dialog);

            confirm = dialog.confirm;
            byte[] str_bytes = StringToAscii(dialog.GetInput());// StringToAscii("bavli 11 tel aviv");
            int length = str_bytes.Length;
            CRunTime.memcpy(textAddr, str_bytes, 0, length);
            int c_editbox_callback = CibylCallTable.getAddressByName("rim_on_editbox_closed");
            if (c_editbox_callback != 0)
                UIWorker.addUIEvent(c_editbox_callback, in_callback, in_data, confirm ? 1 : 0, length, true);

            mre.Set();
        });
        mre.WaitOne();
        fis.Add(fi.setFinishTime());
    }
    public static int NOPH_FileConnection_openOutputStream(int __fc, int offset)
    {
        function_info fi = new function_info("NOPH_FileConnection_openOutputStream");

        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        Stream ret = GetFileStream(fc.filename, FileMode.OpenOrCreate);
        fc.stream = ret;
        int registeredHandle = CRunTime.registerObject(ret);
                fis.Add(fi.setFinishTime());

        return registeredHandle;
    }
    public static void NOPH_EditBoxScreen_registerEditBoxTextAddr(int addr)
    {
        function_info fi = new function_info("NOPH_EditBoxScreen_registerEditBoxTextAddr");

        textAddr = addr;
                fis.Add(fi.setFinishTime());
    }
    /*
    public static int NOPH_FileConnection_list(int __fc)
    {
        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        Enumeration ret = (Enumeration)fc.list();
        int registeredHandle = CRunTime.registerObject(ret);
        return registeredHandle;
    }
    public static void NOPH_FileConnection_mkdir(int __fc)
    {
        FileConnection fc = (FileConnection)CRunTime.objectRepository[__fc];
        fc.mkdir();
    }*/
    public static int NOPH_Font_derive(int __font, int style, int height)
    {
        function_info fi = new function_info("NOPH_Font_derive");
        fis.Add(fi.setFinishTime());

        return height;
        /*        object font = new object();

        //todomt
        //Font font = (Font)CRunTime.objectRepository[__font];
        //        Font ret = (Font)font.derive(style, height);
        int registeredHandle = CRunTime.registerObject(font);
        return registeredHandle;*/
    }
    /*
    public static int NOPH_Enumeration_hasMoreElements(int __enumeration)
    {
        Enumeration enumeration = (Enumeration)CRunTime.objectRepository[__enumeration];
        boolean ret = (boolean)enumeration.hasMoreElements();
        return ret ? 1 : 0;
    }
    public static int NOPH_Enumeration_nextElement(int __enumeration)
    {
        Enumeration enumeration = (Enumeration)CRunTime.objectRepository[__enumeration];
        Object ret = (Object)enumeration.nextElement();
        int registeredHandle = CRunTime.registerObject(ret);
        return registeredHandle;
    }*/
    public static int NOPH_Exception_new()
    {
        function_info fi = new function_info("NOPH_Exception_new");

        Exception ret = (Exception)new Exception();
        int registeredHandle = CRunTime.registerObject(ret);
                fis.Add(fi.setFinishTime());

        return registeredHandle;
    }
    public static int NOPH_Font_getAscent(int __font)
    {
        function_info fi = new function_info("NOPH_Font_getAscent");
        fis.Add(fi.setFinishTime());

        //todomt
        return __font;
        /*        Font font = (Font)CRunTime.objectRepository[__font];
                int ret = (int)font. .getAscent();
                return ret;*/
    }
    public static int NOPH_Exception_new_string(int __s)
    {
        function_info fi = new function_info("NOPH_Exception_new_string");

        String s = CRunTime.charPtrToString(__s);
        Exception ret = (Exception)new Exception(s);
        int registeredHandle = CRunTime.registerObject(ret);
                fis.Add(fi.setFinishTime());

        return registeredHandle;
    }
    public static int NOPH_Font_getDescent(int __font)
    {
        function_info fi = new function_info("NOPH_Font_getDescent");

        switch (__font)
        {
            case 7:
            case 8:
        fis.Add(fi.setFinishTime());
                return 2;
                break;
            case 9:
            case 10:
            case 11:
        fis.Add(fi.setFinishTime());
                return 3;
                break;
            case 12:
            case 13:
            case 14:
            case 15:
        fis.Add(fi.setFinishTime());
                return 4;
                break;
            case 16:
            case 17:
            case 18:
        fis.Add(fi.setFinishTime());
                return 5;
                break;
            case 19:
            case 20:
            case 21:
        fis.Add(fi.setFinishTime());
                return 6;
                break;
            case 22:
            case 23:
            case 24:
        fis.Add(fi.setFinishTime());
                return 7;
                break;
            case 25:
            case 26:
            case 27:
            case 28:
        fis.Add(fi.setFinishTime());
                return 8;
                break;
            case 29:
            case 30:
            case 31:
        fis.Add(fi.setFinishTime());
                return 9;
            case 32:
            case 33:
            case 34:
        fis.Add(fi.setFinishTime());
                return 10;
            case 35:
        fis.Add(fi.setFinishTime());
                return 11;
                break;

            default:
                fis.Add(fi.setFinishTime());
        return 3;
                break;
        }
    }
    public static int NOPH_Calendar_getInstance()
    {
        function_info fi = new function_info("NOPH_Calendar_getInstance");

        DateTime ret = DateTime.Now;
        int registeredHandle = CRunTime.registerObject(ret);
                fis.Add(fi.setFinishTime());

        return registeredHandle;
    }