public ROMWriterStream(IROM rom, ManagedPointer areaToWriteTo)
 {
     this.rom = rom;
     this.areaToWriteTo = areaToWriteTo;
     offset = areaToWriteTo.Offset;
     buffer = rom.ReadData(areaToWriteTo);
 }
Example #2
0
 public static void copyVertex(V3D_f _in, ManagedPointer _out)
 {
     _out.WriteInt(0, (int)_in.x);
     _out.WriteInt(sizeof(Int32), (int)_in.y);
     _out.WriteInt(2 * sizeof(Int32), (int)_in.z);
     _out.WriteInt(5 * sizeof(Int32), (int)_in.c);
 }
Example #3
0
        static void draw_cube(ref MATRIX_f matrix)
        {
            for (int j = 0; j < 4; j++)
            {
                apply_matrix_f(ref matrix, quad[j].x, quad[j].y, quad[j].z, ref quad[j].x, ref quad[j].y, ref quad[j].z);
            }

            for (int j = 0; j < 4; j++)
            {
                persp_project_f(quad[j].x, quad[j].y, quad[j].z, ref quad[j].x, ref quad[j].y);
            }

            ManagedPointer vtx = new ManagedPointer(4 * sizeof(Int32));

            for (int j = 0; j < 4; j++)
            {
                ManagedPointer v = new ManagedPointer(6 * sizeof(Int32));
                v.WriteInt(0, (int)quad[j].x);
                v.WriteInt(sizeof(Int32), (int)quad[j].y);
                v.WriteInt(2 * sizeof(Int32), (int)quad[j].z);
                v.WriteInt(3 * sizeof(Int32), (int)quad[j].u);
                v.WriteInt(4 * sizeof(Int32), (int)quad[j].v);
                v.WriteInt(5 * sizeof(Int32), (int)quad[j].c);
                vtx.WritePointer(j * sizeof(Int32), v);
            }

            if (scene_polygon3d_f(POLYTYPE_GCOL, NULL, 4, vtx) != 0)
            {
                allegro_message("Lack of rendering routine");
            }
        }
 public LazyReserver(int offset, int size, IROM rom, IMemoryManager manager)
 {
     this.offset = offset;
     this.size = size;
     this.rom = rom;
     this.man = manager;
     dataPointer = null;
 }
    public void Memcpy(ManagedPointer <T> Src, int Length)
    {
        var Dst = this;

        Array.Copy(Src.Container, Src.Offset, Dst.Container, Dst.Offset, Length);
        //Src.Array.CopyTo(Dst.Array,
        //for (int n = 0; n < Length; n++) Dst[n] = Src[n];
    }
        public int Out(ManagedPointer <byte> head, int length)
        {
            if (_status != 0)
            {
                return(0);
            }

            //while ( (is_ining) || (is_outing) ) Mai_Sleep(1);
            //is_outing = 1;
#if BIT_READER_THREAD_SAFE
            lock (this)
#endif
            {
                var @base   = _base;
                var rear    = _rear;
                var front   = _front;
                var maxSize = _maxSize;

                var space      = (rear - front + maxSize) % maxSize;
                var copyLength = (length > space) ? space : length;

                var ato   = maxSize - front;
                var copy1 = (copyLength > ato) ? ato : copyLength;
                var copy2 = (copyLength > ato) ? (copyLength - ato) : 0;

                if (copy1 != 0)
                {
                    head.Memcpy(@base.GetPointer(front), copy1);
                    front = (front + copy1) % maxSize;
                    head += copy1;
                }

                if (copy2 != 0)
                {
                    head.Memcpy(@base.GetPointer(front), copy2);
                    front = (front + copy2) % maxSize;
                    // ReSharper disable once RedundantAssignment
                    head += copy2;
                }

                _front = front;

                //is_outing = 0;
                return(copyLength);
            }
        }
        private GeneralizedPointerTableEntry(GeneralizedPointerTableEntry copyMe)
        {
            this.MainPortraitPointer = copyMe.MainPortraitPointer;
            this.MiniPortraitPointer = copyMe.MiniPortraitPointer;
            this.PalettePointer = copyMe.PalettePointer;
            this.MouthPointer = copyMe.MouthPointer;
            this.GenericPointer = copyMe.GenericPointer;
            this.MainPortraitOffset = copyMe.MainPortraitOffset;
            this.MiniPortraitOffset = copyMe.MiniPortraitOffset;
            this.PaletteOffset = copyMe.PaletteOffset;
            this.MouthOffset = copyMe.MouthOffset;
            this.GenericOffset = copyMe.GenericOffset;

            this.MouthPosition = copyMe.MouthPosition;
            this.EyePosition = copyMe.EyePosition;
            this.EyeControl = copyMe.EyeControl;
        }
Example #8
0
        //{
        /* (dialog proc)     (x)   (y)   (w)   (h) (fg)(bg) (key) (flags)     (d1) (d2)    (dp)                   (dp2) (dp3) */

        /* this element just clears the screen, therefore it should come before the others */
        //new DIALOG( d_clear_proc,        0,   0,    0,    0,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  ),

        /* these just display text, either left aligned, centered, or right aligned */
        //new DIALOG( "d_text_proc",         0,  20,    0,    0,   0,  0,    0,      0,       0,   0,    "d_text_proc",          NULL, NULL  ),
        //new DIALOG( "d_ctext_proc",      318,  20,    0,    0,   0,  0,    0,      0,       0,   0,    "d_ctext_proc",         NULL, NULL  ),
        //new DIALOG( "d_rtext_proc",      636,  20,    0,    0,   0,  0,    0,      0,       0,   0,    "d_rtext_proc",         NULL, NULL  ),

        ///* lots of descriptive text elements */
        //new DIALOG( "d_text_proc",         0,   0,    0,    0,   0,  0,    0,      0,       0,   0,    "d_menu_proc->",        NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0,  40,    0,    0,   0,  0,    0,      0,       0,   0,    "d_button_proc->",      NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0,  70,    0,    0,   0,  0,    0,      0,       0,   0,    "d_check_proc->",       NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 100,    0,    0,   0,  0,    0,      0,       0,   0,    "d_radio_proc->",       NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 130,    0,    0,   0,  0,    0,      0,       0,   0,    "d_edit_proc->",        NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 150,    0,    0,   0,  0,    0,      0,       0,   0,    "d_list_proc->",        NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 200,    0,    0,   0,  0,    0,      0,       0,   0,    "d_text_list_proc->",   NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 250,    0,    0,   0,  0,    0,      0,       0,   0,    "d_textbox_proc->",     NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 300,    0,    0,   0,  0,    0,      0,       0,   0,    "d_slider_proc->",      NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 330,    0,    0,   0,  0,    0,      0,       0,   0,    "d_box_proc->",         NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 360,    0,    0,   0,  0,    0,      0,       0,   0,    "d_shadow_box_proc->",  NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 390,    0,    0,   0,  0,    0,      0,       0,   0,    "d_keyboard_proc. Press F1 to see me trigger the about box.", NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 410,    0,    0,   0,  0,    0,      0,       0,   0,    "d_clear_proc. I draw the white background.", NULL, NULL  ),
        //new DIALOG( "d_text_proc",         0, 430,    0,    0,   0,  0,    0,      0,       0,   0,    "d_yield_proc. I make us play nice with the OS scheduler.", NULL, NULL  ),
        //new DIALOG( "d_rtext_proc",      636,  40,    0,    0,   0,  0,    0,      0,       0,   0,    "<-d_bitmap_proc",      NULL, NULL  ),
        //new DIALOG( "d_rtext_proc",      636,  80,    0,    0,   0,  0,    0,      0,       0,   0,    "<-d_icon_proc",        NULL, NULL  ),

        ///* a menu bar - note how it auto-calculates its dimension if they are not given */
        //new DIALOG( "d_menu_proc",       160,   0,    0,    0,   0,  0,    0,      0,       0,   0,    the_menu,               NULL, NULL  ),

        ///* some more GUI elements, all of which require you to specify their dimensions */
        //new DIALOG( "d_button_proc",     160,  40,  160,   20,   0,  0,  't',      0,       0,   0,    "&Toggle Me!",          NULL, NULL  ),
        //new DIALOG( "d_check_proc",      160,  70,  160,   20,   0,  0,  'c',      0,       0,   0,    "&Check Me!",           NULL, NULL  ),
        //new DIALOG( "d_radio_proc",      160, 100,  160,   19,   0,  0,  's',      0,       0,   0,    "&Select Me!",          NULL, NULL  ),
        //new DIALOG( "d_radio_proc",      320, 100,  160,   19,   0,  0,  'o',      0,       0,   0,    "&Or Me!",              NULL, NULL  ),
        //new DIALOG( "d_edit_proc",       160, 130,  160,    8,   0,  0,    0,      0,     LEN,   0,    the_string,             NULL, NULL  ),
        //new DIALOG( "d_list_proc",       160, 150,  160,   44,   0,  0,    0,      0,       0,   0,    (void *)listbox_getter, sel,  NULL  ),
        //new DIALOG( "d_text_list_proc",  160, 200,  160,   44,   0,  0,    0,      0,       0,   0,    (void *)listbox_getter, NULL, NULL  ),
        //new DIALOG( "d_textbox_proc",    160, 250,  160,   48,   0,  0,    0,      0,       0,   0,    (void *)the_text,       NULL, NULL  ),
        //new DIALOG( "d_slider_proc",     160, 300,  160,   12,   0,  0,    0,      0,     100,   0,    NULL,                   NULL, NULL  ),
        //new DIALOG( "d_box_proc",        160, 330,  160,   20,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  ),
        //new DIALOG( "d_shadow_box_proc", 160, 360,  160,   20,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  ),

        ///* note how we don't fill in the dp field yet, because we first need to load the bitmap */
        //new DIALOG( "d_bitmap_proc",     480,  40,   30,   30,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  ),
        //new DIALOG( "d_icon_proc",       480,  80,   30,   30,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  ),

        ///* the quit and info buttons use our customized dialog procedure, using dp3 as callback */
        //new DIALOG( my_button_proc,      0, 450,  160,   20,   0,  0,  'q', D_EXIT,       0,   0,    "&Quit",                NULL, (void *)quit  ),
        //new DIALOG( my_button_proc,    400, 150,  160,   20,   0,  0,  'i', D_EXIT,       0,   0,    "&Info",                NULL, (void *)info1 ),
        //new DIALOG( my_button_proc,    400, 200,  160,   20,   0,  0,  'n', D_EXIT,       0,   0,    "I&nfo",                NULL, (void *)info2 ),
        //new DIALOG( my_button_proc,    400, 300,  160,   20,   0,  0,  'f', D_EXIT,       0,   0,    "In&fo",                NULL, (void *)info3 ),

        ///* the next two elements don't draw anything */
        //new DIALOG( "d_keyboard_proc",     0,   0,    0,    0,   0,  0,    0,      0,  KEY_F1,   0,    (void *)about,          NULL, NULL  ),
        //   new DIALOG( "d_yield_proc",        0,   0,    0,    0,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  ),
        //   new DIALOG( NULL,                0,   0,    0,    0,   0,  0,    0,      0,       0,   0,    NULL,                   NULL, NULL  )
        //};



        /* These three functions demonstrate how to query dialog elements.
         */
        static int info1()
        {
            //char buf1[256];
            //char buf2[256] = "";
            string buf1 = string.Empty;
            string buf2 = string.Empty;
            //int i, s = 0, n;
            int            i, s = 0;
            ManagedPointer n = new ManagedPointer(1);

            //listbox_getter(-1, &n);
            listbox_getter(-1, n);
            ///* query the list proc */
            for (i = 0; i < n.ReadInt(0); i++)
            {
                //if (sel[i]) {
                if (sel.ReadByte(i * sizeof(byte)) > 0)
                {
                    //uszprintf(buf1, sizeof buf1, "%i ", i);
                    buf1 = string.Format("{0} ", i);
                    //ustrzcat(buf2, sizeof buf2, buf1);
                    buf2 += buf1;
                    s     = 1;
                }
            }
            if (s > 0)
            {
                //   ustrzcat(buf2, sizeof buf2, "are in the multiple selection!");
                buf2 += "are in the multiple selection!";
            }
            else
            {
                //   ustrzcat(buf2, sizeof buf2, "There is no multiple selection!");
                buf2 += "There is no multiple selection!";
            }
            //uszprintf(buf1, sizeof buf1, "Item number %i is selected!",
            //   the_dialog[LIST_OBJECT].d1);
            buf1 = string.Format("Item number {0} is selected!", the_dialog[LIST_OBJECT].d1);
            alert("Info about the list:", buf1, buf2, "Ok", null, 0, 0);
            return(D_O_K);
        }
        public PortraitIndexManager(IMemoryManager memoryManager, IROM rom, bool edited)
        {
            currentGame = GameEnumHelpers.GetGame(rom.GameCode);
            var defaultInfo = defaultInfos[currentGame];
            portraitDataPointerPointer = memoryManager.Reserve(defaultInfo.tablePointerOffset, 4);
            int tableRawPtr = BitConverter.ToInt32(rom.ReadData(portraitDataPointerPointer), 0);

            int tableEntryCount;
            if (edited)
            {
                string data = rom.GetCustomData(portraitProperty);
                if (data != null)
                {
                    tableEntryCount = Convert.ToInt32(data);
                }
                else
                {
                    //Let's just hope for the best...
                    tableEntryCount = defaultInfo.indexAmount;
                    rom.AddCustomData(portraitProperty, tableEntryCount.ToString());
                }
            }
            else
            {
                tableEntryCount = defaultInfo.indexAmount;
                rom.AddCustomData(portraitProperty, tableEntryCount.ToString());
            }

            portraitDataPointer =
            memoryManager.Reserve(
                Pointer.GetOffset(tableRawPtr + defaultInfo.IndexSize),
                tableEntryCount);

            entries = new List<GeneralizedPointerTableEntry>(tableEntryCount);

            LoadDataFromROM(memoryManager, rom, defaultInfo.fe6format, tableEntryCount);
        }
Example #10
0
        /* render a tile of the grid */
        static void draw_square(BITMAP bmp, ref MATRIX_f camera, int x, int z)
        {
            V3D_f[] _v = new V3D_f[4], _vout = new V3D_f[8], _vtmp = new V3D_f[8];
            V3D_f[] v = new V3D_f[4], vout = new V3D_f[8], vtmp = new V3D_f[8];
            int[]   flags = new int[4], _out = new int[8];
            int     c, vc = 0;

            for (c = 0; c < 4; c++)
            {
                v[c] = _v[c];
            }

            for (c = 0; c < 8; c++)
            {
                vout[c] = _vout[c];
                vtmp[c] = _vtmp[c];
            }

            /* set up four vertices with the world-space position of the tile */
            v[0].x = x - GRID_SIZE / 2;
            v[0].y = 0;
            v[0].z = z - GRID_SIZE / 2;

            v[1].x = x - GRID_SIZE / 2 + 1;
            v[1].y = 0;
            v[1].z = z - GRID_SIZE / 2;

            v[2].x = x - GRID_SIZE / 2 + 1;
            v[2].y = 0;
            v[2].z = z - GRID_SIZE / 2 + 1;

            v[3].x = x - GRID_SIZE / 2;
            v[3].y = 0;
            v[3].z = z - GRID_SIZE / 2 + 1;

            /* apply the camera matrix, translating world space . view space */
            for (c = 0; c < 4; c++)
            {
                apply_matrix_f(ref camera, v[c].x, v[c].y, v[c].z,
                               ref v[c].x, ref v[c].y, ref v[c].z);

                flags[c] = 0;

                /* set flags if this vertex is off the edge of the screen */
                if (v[c].x < -v[c].z)
                {
                    flags[c] |= 1;
                }
                else if (v[c].x > v[c].z)
                {
                    flags[c] |= 2;
                }

                if (v[c].y < -v[c].z)
                {
                    flags[c] |= 4;
                }
                else if (v[c].y > v[c].z)
                {
                    flags[c] |= 8;
                }

                if (v[c].z < 0.1)
                {
                    flags[c] |= 16;
                }
            }

            /* quit if all vertices are off the same edge of the screen */
            if ((flags[0] & flags[1] & flags[2] & flags[3]) != 0)
            {
                return;
            }

            //if ((flags[0] | flags[1] | flags[2] | flags[3]) != 0)
            //{
            //    /* clip if any vertices are off the edge of the screen */
            //    //vc = clip3d_f(POLYTYPE_FLAT, 0.1f, 0.1f, 4, v,
            //    //  vout, vtmp, _out);
            //    IntPtr w = Marshal.AllocHGlobal(24 * 4);
            //    IntPtr wout = Marshal.AllocHGlobal(24 * 8);
            //    IntPtr wtmp = Marshal.AllocHGlobal(24 * 8);
            //    IntPtr iout = Marshal.AllocHGlobal(sizeof(Int32) * 8);
            //    vc = clip3d_f(POLYTYPE_FLAT, 0.1f, 0.1f, 4, w, wout, wtmp, iout);

            //    if (vc <= 0)
            //        return;
            //}
            //else
            //{
            /* no need to bother clipping this one */
            vout[0] = v[0];
            vout[1] = v[1];
            vout[2] = v[2];
            vout[3] = v[3];

            vc = 4;
            //}

            /* project view space -> screen space */
            for (c = 0; c < vc; c++)
            {
                persp_project_f(vout[c].x, vout[c].y, vout[c].z,
                                ref vout[c].x, ref vout[c].y);
            }

            /* set the color */
            vout[0].c = ((x + z) & 1) > 0 ? makecol(0, 255, 0) : makecol(255, 255, 0);

            /* render the polygon */
            //ManagedPointer wout = Marshal.AllocHGlobal(4 * sizeof(Int32));
            //IntPtr[] wout = new IntPtr[4];
            V3D_f[] wout = new V3D_f[4];
            V3D_p   v0   = new V3D_p(vout[0].x, vout[0].y, vout[0].z, vout[0].u, vout[0].v, vout[0].c);
            V3D_p   v1   = new V3D_p(vout[1].x, vout[1].y, vout[1].z, vout[1].u, vout[1].v, vout[1].c);
            V3D_p   v2   = new V3D_p(vout[2].x, vout[2].y, vout[2].z, vout[2].u, vout[2].v, vout[2].c);
            V3D_p   v3   = new V3D_p(vout[3].x, vout[3].y, vout[3].z, vout[3].u, vout[3].v, vout[3].c);
            //ManagedPointer v0 = Marshal.AllocHGlobal(6 * sizeof(Int32));
            //ManagedPointer v1 = Marshal.AllocHGlobal(6 * sizeof(Int32));
            //ManagedPointer v2 = Marshal.AllocHGlobal(6 * sizeof(Int32));
            //ManagedPointer v3 = Marshal.AllocHGlobal(6 * sizeof(Int32));
            //copyVertex(vout[0], v0);
            //copyVertex(vout[1], v1);
            //copyVertex(vout[2], v2);
            //copyVertex(vout[3], v3);
            //wout.WritePointer(0, v0);
            //wout.WritePointer(sizeof(Int32), v1);
            //wout.WritePointer(2 * sizeof(Int32), v2);
            //wout.WritePointer(3 * sizeof(Int32), v3);
            //wout[0] = v0;
            //wout[1] = v1;
            //wout[2] = v2;
            //wout[3] = v3;
            //wout[0] = vout[0];
            //wout[1] = vout[1];
            //wout[2] = vout[2];
            //wout[3] = vout[3];
            //polygon3d_f(bmp, POLYTYPE_FLAT, NULL, vc, vout);
            //polygon3d_f(bmp, POLYTYPE_FLAT, NULL, vc, ref wout);
            //IntPtr[] wwout = new IntPtr[4];
            //wwout[0] = v0;
            //wwout[1] = v1;
            //wwout[2] = v2;
            //wwout[3] = v3;
            ManagedPointer wwout = new ManagedPointer(4 * sizeof(Int32));

            wwout.WritePointer(0, v0);
            wwout.WritePointer(sizeof(Int32), v1);
            wwout.WritePointer(2 * sizeof(Int32), v2);
            wwout.WritePointer(3 * sizeof(Int32), v3);
            polygon3d_f(bmp, POLYTYPE_FLAT, NULL, 4, wwout.pointer);
            //quad3d_f(bmp, POLYTYPE_FLAT, NULL, ref vout[0], ref vout[1], ref vout[2], ref vout[3]);
        }
 public static ManagedPointer <T> GetPointer <T>(this ManagedPointer <T> This, int Offset)
 {
     return(This.Slice(Offset));
 }
        private void LoadDataFromROM(IMemoryManager memoryManager, IROM rom)
        {
            int portraitPtrOffset;
            int defaultIndexAmount;
            bool FE6Format;
            switch (game = GameEnumHelpers.GetGame(rom.GameCode))
            {
                case GameEnum.FE6Trans:
                case GameEnum.FE6:
                    portraitPtrOffset = 0x007FD8;
                    defaultIndexAmount = 0xE6;
                    FE6Format = true;
                    break;
                case GameEnum.FE7U:
                    portraitPtrOffset = 0x006B30;
                    defaultIndexAmount = 0xE4;
                    FE6Format = false;
                    break;
                case GameEnum.FE8U:
                    portraitPtrOffset = 0x005524;
                    defaultIndexAmount = 0xAC;
                    FE6Format = false;
                    break;

                //Unknown
                case GameEnum.FE7J:
                case GameEnum.FE8J:
                case GameEnum.FE7E:
                case GameEnum.FE8E:
                default:
                    throw new Exception("Game not supported.");
            }

            portraitDataPointerPointer = memoryManager.Reserve(portraitPtrOffset, 4);
            int tableRawPtr = BitConverter.ToInt32(rom.ReadData(portraitDataPointerPointer), 0);

            int indexSize = Marshal.SizeOf(FE6Format ? typeof(FE6RawFormat) : typeof(FE78RawFormat));
            portraitDataPointer =
                memoryManager.Reserve(
                    Pointer.GetOffset(tableRawPtr + indexSize),
                    defaultIndexAmount * indexSize);

            byte[] portraitData = rom.ReadData(portraitDataPointer);

            portraitEntries.Clear();
            unsafe
            {
                if (FE6Format)
                {
                    FE6RawFormat[] rawData = new FE6RawFormat[defaultIndexAmount];
                    fixed (FE6RawFormat* ptr = rawData)
                    {
                        IntPtr ptr2 = (IntPtr)ptr;
                        Marshal.Copy(portraitData, 0, ptr2, portraitData.Length);
                    }
                    for (int i = 0; i < rawData.Length; i++)
                    {
                        portraitEntries.Add(new GeneralizedPointerTableEntry(
                            rom, memoryManager, rawData[i]));
                    }
                }
                else
                {
                    FE78RawFormat[] rawData = new FE78RawFormat[defaultIndexAmount];
                    fixed (FE78RawFormat* ptr = rawData)
                    {
                        IntPtr ptr2 = (IntPtr)ptr;
                        Marshal.Copy(portraitData, 0, ptr2, portraitData.Length);
                    }
                    for (int i = 0; i < rawData.Length; i++)
                    {
                        portraitEntries.Add(new GeneralizedPointerTableEntry(
                            rom, memoryManager, rawData[i]));
                    }
                }
            }
            CurrentIndex = 0;
            form.MaxIndex = portraitEntries.Count - 1;
        }
Example #13
0
        /* copies from our magic format data onto a normal Allegro screen bitmap */
        static void blit_magic_format_to_screen(BITMAP bmp)
        {
            uint           addr;
            ManagedPointer data;
            uint           in1, in2, in3;
            uint           out1, out2;
            int            x, y;

            /* Warning: this function contains some rather hairy optimisations :-)
             * The fastest way to copy large amounts of data is in aligned 32 bit
             * chunks. If we expand it out to process 4 pixels per cycle, we can
             * do this by reading 12 bytes (4 pixels) from the 24 bit source data,
             * and writing 8 bytes (4 pixels) to the 16 bit destination. Then the
             * only problem is how to convert our 12 bytes of data into a suitable
             * 8 byte format, once we've got it loaded into registers. This is done
             * by some lookup tables, which are arranged so they can process 2 color
             * components in a single lookup, and allow me to precalculate the
             * makecol() operation.
             *
             * Warning #2: this code assumes little-endianess.
             *
             * Here is a (rather confusing) attempt to diagram the logic of the
             * lookup table lighting conversion from 24 to 16 bit format in little-
             * endian format:
             *
             *
             *  inputs: |     (dword 1)     |     (dword 2)     |     (dword 3)     |
             *  pixels: |   (pixel1)   |   (pixel2)   |   (pixel3)   |   (pixel4)   |
             *  bytes:  | r1   g1   b1   r2   g2   b2   r3   g3   b3   r4   g4   b4 |
             *          |    |         |         |         |         |         |    |
             *  lookup: | rgtable   brtable   gbtable   rgtable   brtable   gbtable |
             *          |    |         |         |         |         |         |    |
             *  pixels: |   (pixel1)   |   (pixel2)   |   (pixel3)   |   (pixel4)   |
             *  outputs |          (dword 1)          |          (dword 2)          |
             *
             *
             * For reference, here is the original, non-optimised but much easier
             * to understand version of this routine:
             *
             *    _farsetsel(screen->seg);
             *
             *    for (y=0; y<SCREEN_H; y++) {
             *       addr = bmp_write_line(screen, y);
             *
             *       for (x=0; x<SCREEN_W; x++) {
             *          r = bmp->line[y][x*3];
             *          g = bmp->line[y][x*3+1];
             *          b = bmp->line[y][x*3+2];
             *
             *          r = (r&31) * (r>>5) * 255/217;
             *          g = (g&31) * (g>>5) * 255/217;
             *          b = (b&31) * (b>>5) * 255/217;
             *
             *          _farnspokew(addr, makecol(r, g, b));
             *
             *          addr += 2;
             *       }
             *    }
             */

            bmp_select(screen);

            for (y = 0; y < SCREEN_H; y++)
            {
                addr = bmp_write_line(screen, y);
                //data = (uint32_t*)bmp->line[y];
                data = new ManagedPointer(bmp.line).Offset(y * bmp.w * sizeof(byte));

                for (x = 0; x < SCREEN_W / 4; x++)
                {
                    //in1 = *(data++);
                    //in2 = *(data++);
                    //in3 = *(data++);
                    in1  = (uint)data.ReadInt(0);
                    in2  = (uint)data.ReadInt(sizeof(Int32));
                    in3  = (uint)data.ReadInt(2 * sizeof(Int32));
                    data = data.Offset(3 * sizeof(Int32));

                    /* trust me, this does make sense, really :-) */
                    out1 = (uint)rgtable[in1 & 0xFFFF] |
                           (uint)brtable[in1 >> 16] |
                           (uint)(gbtable[in2 & 0xFFFF] << 16);

                    out2 = (uint)rgtable[in2 >> 16] |
                           (uint)brtable[in3 & 0xFFFF] |
                           (uint)(gbtable[in3 >> 16] << 16);

                    bmp_write32(addr, (int)out1);
                    bmp_write32(addr + 4, (int)out2);

                    addr += 8;
                }
            }

            bmp_unwrite_line(screen);
        }
 public void Deallocate(ManagedPointer pointer)
 {
 }
 public bool IsAllocated(ManagedPointer pointer)
 {
     return false;
 }
Example #16
0
        public int OutPre(ManagedPointer<byte> head, int length)
        {
            if (status != 0) return 0;

            //while ( (is_ining) || (is_outing) ) Mai_Sleep(1);
            //is_outing = 1;
            #if BIT_READER_THREAD_SAFE
            lock (this)
            #endif
            {

                byte[] @base = this.@base;
                int rear = this.rear;
                int front = this.front;
                int max_size = this.max_size;

                int space = (rear - front + max_size) % max_size;
                int copy_length = (length > space) ? space : length;

                int ato = max_size - front;
                int copy1 = (copy_length > ato) ? ato : copy_length;
                int copy2 = (copy_length > ato) ? (copy_length - ato) : 0;

                if (copy1 != 0)
                {
                    head.Memcpy(@base.GetPointer(front), copy1);
                    front = (front + copy1) % max_size;
                    head += copy1;
                }

                if (copy2 != 0)
                {
                    head.Memcpy(@base.GetPointer(front), copy2);
                    front = (front + copy2) % max_size;
                    head += copy2;
                }

                //this.front = front;

                //is_outing = 0;
                return copy_length;
            }
        }
 public void Unpin(ManagedPointer ptr)
 {
 }
 public void Pin(ManagedPointer ptr)
 {
 }
        //used in decodeTable3
        static int MAPCDSF_decodeTable3Sub0(MaiBitReader mbr0, ManagedPointer<short> buf_to_read, uint num_to_read, MaiAT3PlusCoreDecoderSearchTableDes huff_table_now)
        {
            int rs = 0;

            if (huff_table_now.uk3 == 1)
            {
                uint tcounter0 = 0;
                for (uint b0 = 0; b0 < (num_to_read >> (huff_table_now.uk4)); b0++)
                {
                    uint group_value = MAPCDSF_getHuffValue(huff_table_now, mbr0);

                    for (uint b1 = 0; b1 < huff_table_now.uk2; b1++)
                    {
                        uint value_now = (uint)(group_value >> (int)((huff_table_now.uk2 - b1 - 1) * huff_table_now.uk6));
                        value_now &= huff_table_now.mask;

                        if (0 == huff_table_now.uk5)
                        {
                            if ((value_now & ( 1 << (huff_table_now.uk6 - 1) )) != 0 )
                                buf_to_read[tcounter0++] = (short)(value_now | ( ~( ( 1 << (huff_table_now.uk6) ) - 1 ) ));
                            else
                                buf_to_read[tcounter0++] = (short)(value_now);
                        }
                        else
                        {
                            if ( ((value_now != 0) && (mbr0.getWithI32Buffer(1) != 0)) )
                                buf_to_read[tcounter0++] = (short)(((short)(value_now)) * (-1));
                            else
                                buf_to_read[tcounter0++] = (short)(value_now);
                        }
                    }
                }
            }
            else if (huff_table_now.uk3 > 1)
            {
                uint tcounter0 = 0;
                for (uint b0 = 0; b0 < (num_to_read >> (huff_table_now.uk4)); b0 += huff_table_now.uk3)
                {
                    uint l320 = (uint)mbr0.getWithI32Buffer(1);
                    if (0 == l320)
                    {
                        for (uint b1 = 0; b1 < huff_table_now.uk3 * huff_table_now.uk2; b1++)
                        {
                            buf_to_read[tcounter0++] = 0;
                        }
                    }
                    else for (uint b2 = 0; b2 < huff_table_now.uk3; b2++)
                    {
                        uint group_value = MAPCDSF_getHuffValue(huff_table_now, mbr0);

                        for (uint b1 = 0; b1 < huff_table_now.uk2; b1++)
                        {
                            uint value_now = (uint)(group_value >> (int)((huff_table_now.uk2 - b1 - 1) * huff_table_now.uk6));
                            value_now &= huff_table_now.mask;

                            if (0 == huff_table_now.uk5)
                            {
                                if ((value_now & ( 1 << (huff_table_now.uk6 - 1) )) != 0 )
                                    buf_to_read[tcounter0++] = (short)(value_now | ( ~( ( 1 << (huff_table_now.uk6) ) - 1 ) ));
                                else
                                    buf_to_read[tcounter0++] = (short)(value_now);
                            }
                            else
                            {
                                if ( ((value_now!= 0) && (mbr0.getWithI32Buffer(1)!= 0))  )
                                    buf_to_read[tcounter0++] = (short)(((short)(value_now)) * (-1));
                                else
                                    buf_to_read[tcounter0++] = (short)(value_now);
                            }
                        }
                    }
                }
            }
            else
            {
                rs = -20;
            }

            return rs;
        }
        public int getAudioSamplesI16(uint index_chn, ManagedPointer<short> bufs)
        {
            int rs = 0;

            bufs.GetRawPointer((bufs_ptr_intptr) =>
            {
                short* bufs_ptr = (short *)bufs_ptr_intptr.ToPointer();
                fixed (float* dst_buf_chn_ptr = dst_buf[index_chn])
                {
                    for (int a0 = 0; a0 < 0x800; a0++)
                    {
                        int data_now = (int)dst_buf_chn_ptr[a0];
                        if (data_now > 0x7FFF) bufs_ptr[a0] = 0x7FFF;
                        else if (data_now < (-0x8000)) bufs_ptr[a0] = -0x8000;
                        else bufs_ptr[a0] = (short)data_now;
                    }
                }
            });

            return rs;
        }