Exemplo n.º 1
0
        static int memread_ungetc(int c, IntPtr userdata)
        {
            MEMREAD_INFO info = userdata;
            byte         ch   = (byte)c;

            if ((info.offset > 0) && (info.block[info.offset - 1] == ch))
            {
                return(ch);
            }
            else
            {
                return(EOF);
            }
        }
Exemplo n.º 2
0
        static int memread_getc(IntPtr userdata)
        {
            MEMREAD_INFO info = userdata;

            //ASSERT(info);
            //ASSERT(info.offset <= info.length);

            if (info.offset == info.length)
            {
                return(EOF);
            }
            else
            {
                return(info.block[info.offset++]);
            }
        }
Exemplo n.º 3
0
        static int memread_fread(IntPtr p, int n, IntPtr userdata)
        {
            MEMREAD_INFO info = userdata;
            //size_t actual;
            int actual;

            //ASSERT(info);
            //ASSERT(info.offset <= info.length);

            actual = MIN((int)n, info.length - info.offset);

            //memcpy(p, info.block + info.offset, actual);

            info.offset += actual;

            //ASSERT(info.offset <= info.length);

            return(actual);
        }
Exemplo n.º 4
0
        static int memread_seek(IntPtr userdata, int offset)
        {
            MEMREAD_INFO info = userdata;
            int          actual;

            //ASSERT(info);
            //ASSERT(info.offset <= info.length);

            actual = MIN(offset, info.length - info.offset);

            info.offset += actual;

            //ASSERT(info.offset <= info.length);

            if (offset == actual)
            {
                return(0);
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 5
0
        /* This reads the files mysha.pcx and allegro.pcx into a memory block as
         * binary data, and then uses the memory vtable to read the bitmaps out of
         * the memory block.
         */
        static void memread_test()
        {
            PACKFILE     f;
            MEMREAD_INFO memread_info = new MEMREAD_INFO();
            BITMAP       bmp, bmp2;
            IntPtr       block;
            int          l1, l2;
            PACKFILE     f1, f2;

            l1 = file_size_ex("allegro.pcx");
            l2 = file_size_ex("mysha.pcx");

            //block = malloc(l1 + l2);
            block = Marshal.AllocHGlobal(l1 + l2);

            /* Read mysha.pcx into the memory block. */
            f1 = pack_fopen("allegro.pcx", "rb");
            CHECK(f1.pointer.ToInt32(), "opening allegro.pcx");
            pack_fread(block, l1, f1);
            pack_fclose(f1);

            /* Read allegro.pcx into the memory block. */
            f2 = pack_fopen("mysha.pcx", "rb");
            CHECK(f2.pointer.ToInt32(), "opening mysha.pcx");
            pack_fread(new ManagedPointer(block).Offset(l1), l2, f2);
            pack_fclose(f2);

            /* Open the memory block as PACKFILE, using our memory vtable. */
            memread_info.block  = block;
            memread_info.length = l1 + l2;
            memread_info.offset = 0;
            f = pack_fopen_vtable(memread_vtable, memread_info);
            CHECK(f.pointer.ToInt32(), "reading from memory block");

            /* Read the bitmaps out of the memory block. */
            // TODO: check why f gets nulled
            PACKFILE t = f, u = f;

            bmp = load_pcx_pf(f, NULL);
            CHECK(bmp.pointer.ToInt32(), "load_pcx_pf");
            //bmp2 = load_pcx_pf(f, NULL);
            bmp2 = load_pcx_pf(t, NULL);
            CHECK(bmp2.pointer.ToInt32(), "load_pcx_pf");

            blit(bmp, screen, 0, 0, 0, 0, bmp.w, bmp.h);
            textprintf_ex(screen, font, bmp.w + 8, 8, -1, -1,
                          "\"allegro.pcx\"");
            textprintf_ex(screen, font, bmp.w + 8, 8 + 20, -1, -1,
                          "read out of a memory file");

            blit(bmp2, screen, 0, 0, 0, bmp.h + 8, bmp2.w, bmp2.h);
            textprintf_ex(screen, font, bmp2.w + 8, bmp.h + 8, -1, -1,
                          "\"mysha.pcx\"");
            textprintf_ex(screen, font, bmp2.w + 8, bmp.h + 8 + 20, -1, -1,
                          "read out of a memory file");

            destroy_bitmap(bmp);
            destroy_bitmap(bmp2);
            //pack_fclose(f);
            pack_fclose(u);

            next();
        }
Exemplo n.º 6
0
        static int memread_feof(IntPtr userdata)
        {
            MEMREAD_INFO info = userdata;

            return(info.offset >= info.length ? 1 : 0);
        }