Пример #1
0
    private static void init()    // throws Exception
    {
        Logger.log("In init!!!!!!!!!!");
        //Class cls = Class.forName("CRunTime");
        Stream isData = Application.GetResourceStream(new Uri("/WazeWP7;component/resources/program.data.bin", UriKind.Relative)).Stream;

        Logger.log("program.data.bin:" + isData);
        CRunTime.init(isData);
        isData.Close();
        CRunTime.publishCallback("Cibyl.atexit");
        int c_start = CibylCallTable.getAddressByName("__start");

        Logger.log("Start: " + c_start);

        /*
         * This is the stack which will be used for all the C calls.
         */
        int c_sp = (CRunTime.memory.Length * 4) - 8;

        Logger.log("c_sp: " + c_sp);
        CibylCallTable.fcall(c_start, c_sp, 0, 0, 0, 0);

        /*
         * The blackberry menu button can be clicked on async when other waze tasks
         * are handled, and we want the response to be immediate. Thus we allocate a special
         * stack for the menu button clicks, to be used by the FreemapMainScreen object.
         */
        int c_malloc_stack = 0;

        try
        {
            c_malloc_stack = CibylCallTable.getAddressByName("roadmap_main_alloc_stack");
        }
        catch (Exception e)
        {
            Logger.log("could not call c_malloc_stack" + e.ToString());
            safe_exit();
            //MessageBox.Show("Exception in c_malloc_stack");
        }
        if (c_malloc_stack != 0)
        {
            int stackAddress = CibylCallTable.fcall(c_malloc_stack, c_sp, 4096, 0, 0, 0);
            GamePage.setStackAddress(stackAddress);
        }
    }
Пример #2
0
    public static void init(Stream codeStream)
    {
        CRunTime.memory           = null;
        CRunTime.objectRepository = null;
        //System.gc();

        int memorySize = 512 * 1024 * 10;    // (int)(51200000 * 4 /* Runtime.getRuntime().freeMemory() */ * CibylConfig.cibylMemoryProportion);

        if (CibylConfig.memorySize != 0)
        {
            memorySize = CibylConfig.memorySize;
        }

        if (CibylConfig.faultMemoryIn)
        {
            memorySize = (int)CRunTime.faultMemoryIn(CibylConfig.memorySize);
        }

        /* See to it that the memory is aligned to 8. This caused a very
         * fun bug before in printf when called with "%f".
         *
         * Also setup the event stack at the very top of the memory
         */
        memorySize -= (memorySize & 7);
        CRunTime.eventStackPointer = memorySize - 8;

        int len = (int)codeStream.Length / 4;

        if (len < 5)
        {
            /* This binary is broken - we need the header data */
            throw new Exception("Data input is too small");
        }

        CRunTime.init(codeStream, memorySize);
    }