Exemple #1
0
short gif_decoder(short linewidth)
{
	unsigned char far *buf, far * stack, far * suffix;
	unsigned short far *prefix;
	short ret;

	ret = OUT_OF_MEMORY;
	stack = suffix = (unsigned char *) prefix = NULL;
	safe_alloc = 1;
	if ((buf = farmalloc(linewidth + 1)) == NULL)
		goto OUT;
	safe_alloc = 1;
	if ((stack = farmalloc(MAX_CODES + 1)) == NULL)
		goto OUT;
	safe_alloc = 1;
	if ((suffix = farmalloc(MAX_CODES + 1)) == NULL)
		goto OUT;
	safe_alloc = 1;
	if ((prefix = (unsigned short far *) farmalloc((MAX_CODES + 1) * sizeof(unsigned short))) == NULL)
		goto OUT;
	ret = decoder(linewidth, buf, stack, suffix, prefix);
OUT:
	if (ret == OUT_OF_MEMORY)
	    ErrorBox("Not enough memory to view a Gif file.");
	if (buf)
		farfree(buf);
	if (stack)
		farfree(stack);
	if (prefix)
		farfree(prefix);
	if (suffix)
		farfree(suffix);
	return (ret);
}
Exemple #2
0
void save(int x1, int y1, int x2, int y2)
{
unsigned area1,area2,area3,area4;

midx=x1+(x2-x1)/2;
midy=y1+(y2-y1)/2;

area1=imagesize(x1,y1,midx,midy);
(char)p1=(char)farmalloc(area1);
area2=imagesize(midx+1,y1,x2,midy);
(char)p2=(char)farmalloc(area2);
area3=imagesize(x1,midy+1,midx,y2);
(char)p3=(char)farmalloc(area3);
area4=imagesize(midx+1,midy+1,x2,y2);
(char)p4=(char)farmalloc(area4);

if(p1==NULL || p2==NULL || p3==NULL || p4==NULL)
	{
	closegraph();
	printf("Memory allocation error!");
	exit(2);
	}

getimage(x1,y1,midx,midy,p1);
getimage(midx+1,y1,x2,midy,p2);
getimage(x1,midy+1,midx,y2,p3);
getimage(midx+1,midy+1,x2,y2,p4);
}
void setVideoMode(unsigned char m)
{
	//TELL BIOS TO SET VGA MODE 0x13
	asm{
	mov ah, 0x00
	mov al, m
	int 0x10
	};
}

void waitVBlank()
{
	while((inp(VGA_STATUS_REGISTER) & 8));
	while(!(inp(VGA_STATUS_REGISTER) & 8));
}

int createBackBuffer()
{
	backBuffer = (byte far *) farmalloc(320L*200L);
	if (backBuffer == NULL)
	{
		printf("NO MEMORY\n");
		return 0;
	}
	return 1;
}
Exemple #4
0
//initialization
//--------------
int ie_initswap(void)
{
 int i;
#ifndef POSIX 
 if ( swapstr == NULL ) swapstr = (char *)farmalloc( IE_MAXSWAPLEN+IE_SWAPSTART+1);
 if ( swapstr == NULL) return 2;
#endif

 swapidx=(unsigned *)swapstr;
 swapcount=0; //0 lines
 i=0;
 do
 {
  swaplen[i]=0;
  swapsize[i]=0;
#ifndef POSIX
  swapbufflag[i]=0;
#else
  swapbuf[i]=NULL; 
#endif
  swapcontext[i]=-1;
 }
 while(++i<IE_MAXSWAP);
 swapnum=-1;
 ie_swap(0);
 firstswap=0;

 return 1;
}//end sub
Exemple #5
0
png_voidp
png_malloc_default(png_structp png_ptr, png_uint_32 size)
{
   png_voidp ret;
#endif /* PNG_USER_MEM_SUPPORTED */

#ifdef PNG_MAX_MALLOC_64K
   if (size > (png_uint_32)65536L)
      png_error(png_ptr, "Cannot Allocate > 64K");
#endif

#if defined(__TURBOC__) && !defined(__FLAT__)
   ret = farmalloc(size);
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
   ret = halloc(size, 1);
# else
   ret = malloc((size_t)size);
# endif
#endif

   if (ret == NULL)
   {
      png_error(png_ptr, "Out of Memory");
   }

   return (ret);
}
/* Alternate version of png_create_struct, for use with user-defined malloc. */
png_voidp /* PRIVATE */
png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
   png_size_t size;
   png_voidp struct_ptr;

   if (type == PNG_STRUCT_INFO)
      size = png_sizeof(png_info);
   else if (type == PNG_STRUCT_PNG)
      size = png_sizeof(png_struct);
   else
      return (png_get_copyright(NULL));

#ifdef PNG_USER_MEM_SUPPORTED
   if (malloc_fn != NULL)
   {
      png_struct dummy_struct;
      png_structp png_ptr = &dummy_struct;
      png_ptr->mem_ptr=mem_ptr;
      struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
   }
   else
#endif /* PNG_USER_MEM_SUPPORTED */
   struct_ptr = (png_voidp)farmalloc(size);
   if (struct_ptr != NULL)
      png_memset(struct_ptr, 0, size);
   return (struct_ptr);
}
//------- Zapis obdelnika videoram do XMS/Disk -------------------
int xv_to_virt(int xo, int yo, int xs, int ys, int dx, int dy)
{
//  xo,yo - pravy horni bod obrazu na obrazovce
//  xs,ys - pravy horni bod obrazu v souboru
//  dx,dy - velikost obrazu v pixlech

//  Ppg. zapise do souboru obdelnik z videoram.
//  Pozn: pro 2 a 16 barev musi byt vsechna x nasobkem 8 !!!

    char *inbuf=NULL;
    int  ist,yak,dyak,yoak;
    long lenmap,xx_lenbuf;
    int  nkusu,nline,x2o,kk,LenLine;

    if(xv_vv[xv_act].xv_file <= 0 && xv_vv[xv_act].xv_XMS==-1) return( 2 );
    if(xv_vv[xv_act].xv_bits != 0 && xg_256 == MM_256) return( 4 );
    if(xv_vv[xv_act].xv_bits != 3 && xg_256 == MM_2) return( 4 );
#if HI_COLOR
    if(xv_vv[xv_act].xv_bits != -1 && xg_256 == MM_Hic) return( 4 );
#endif

    lenmap = farcoreleft();                    // Kolik alokovat
    if(lenmap >= 65512L)
      xx_lenbuf = 55512L;
    else
      xx_lenbuf = lenmap - (dx+1024);

    if(xx_lenbuf < (dx+16)) return( 6 );       // Neni pamet ani na 1 radek

    inbuf = farmalloc(xx_lenbuf);
    if(inbuf == NULL) return( 6 );

	if(xv_vv[xv_act].xv_bits >= 0)
     LenLine = dx>>xv_vv[xv_act].xv_bits;
	else
Exemple #8
0
//-----------------------------------------------------------------------
// Ulozi do bufferu Buf vyrez obrazovky dany rozmery x0, y0, x1, y1
//------------------------------------------------------------------------
void GetScr(char x0,char y0,char x1,char y1)
{
	char x,y;
  int bufsize;

  bufsize=(x1-x0+1)*2 + (y1-y0+1)*(x1-x0+1)*2;  // Vypocet velikosti vyrezu

  //gotoxy(2,1);
  //printf("x0:%3i",x0);
  //printf("x1:%3i",x1);
  //printf("y0:%3i",y0);
  //printf("y1:%3i",y1);
  //printf("Buf:%3i",bufsize);


  ScrBuf[ScrBuf_ix]=0;
  ScrBuf[ScrBuf_ix]=(char far *) farmalloc(bufsize);
  if(ScrBuf[ScrBuf_ix]==0) printf("\r\nERROR-GetScr: Nelze alokovat pamet pro ulozeni obrazu. Index: %2d",ScrBuf_ix);
  else
  { for (y=y0; y<y1; y++)
    { for (x=x0; x<x1; x++)
      { ScrBuf[ScrBuf_ix][(x-x0)*2 + (y-y0)*(x1-x0)*2]=peekb(0xB800,x*2 + y*80*2);
        ScrBuf[ScrBuf_ix][(x-x0)*2 + (y-y0)*(x1-x0)*2 + 1]=peekb(0xB800,x*2 + y*80*2 + 1);
      }
    }
    if(ScrBuf_ix < ScrBuffers) ScrBuf_ix++;
    else cprintf("\r\nPrekrocen maximalni index pro ulozeni vyrezu !");
  }
}
Exemple #9
0
long calcexe(char *exename,long offset)
{
 long x=0;
 int i=0,step[5]={7,3,1,2,7},j=0;
 int f=a_open(exename,O_RDONLY|O_BINARY);
 char *buf=farmalloc(CHECKBUF+1);

 if(buf)
 {
  if(f>=0)
  {
   lseek(f, offset, SEEK_SET);
   a_read(f,buf,CHECKBUF);

   while(j<CHECKBUF)
   {
    x+=buf[j];
    j+=step[i++];
    if(i==4)i=0;
   }

   a_close(f);

   return x;
  }
  farfree(buf);
 }

 puts("?!");
 exit(0);
}
Exemple #10
0
int make_stack(void)
    {
    if ((stack = (int far*)farmalloc(sizeof(int)*STACK_SIZE)) == NULL)
        return 0;
    else
        return 1;
    }
Exemple #11
0
/* Alternate version of png_create_struct, for use with user-defined malloc. */
png_voidp
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
   png_size_t size;
   png_voidp struct_ptr;

   if (type == PNG_STRUCT_INFO)
     size = sizeof(png_info);
   else if (type == PNG_STRUCT_PNG)
     size = sizeof(png_struct);
   else
     return ((png_voidp)NULL);

#ifdef PNG_USER_MEM_SUPPORTED
   if(malloc_fn != NULL)
   {
      if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
         png_memset(struct_ptr, 0, size);
         return (struct_ptr);
   }
#endif /* PNG_USER_MEM_SUPPORTED */
   if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
   {
      png_memset(struct_ptr, 0, size);
   }
   return (struct_ptr);
}
Exemple #12
0
/* Allocate memory for a png_struct or a png_info.  The malloc and
 * memset can be replaced by a single call to calloc() if this is thought
 * to improve performance noticably.
 */
png_voidp
png_create_struct(uInt type)
{
   size_t size;
   png_voidp struct_ptr;

   if (type == PNG_STRUCT_INFO)
     size = sizeof(png_info);
   else if (type == PNG_STRUCT_PNG)
     size = sizeof(png_struct);
   else
     return (png_voidp)NULL;

#if defined(__TURBOC__) && !defined(__FLAT__)
   if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
   if ((struct_ptr = (png_voidp)halloc(size,1)) != NULL)
# else
   if ((struct_ptr = (png_voidp)malloc(size)) != NULL)
# endif
#endif
   {
      png_memset(struct_ptr, 0, size);
   }

   return (struct_ptr);
}
Exemple #13
0
png_voidp
png_large_malloc(png_structp png_ptr, png_uint_32 size)
{
   png_voidp ret;
   if (!png_ptr || !size)
      return ((voidp)0);

#ifdef PNG_MAX_MALLOC_64K
   if (size > (png_uint_32)65536L)
      png_error(png_ptr, "Cannot Allocate > 64K");
#endif

#if defined(__TURBOC__) && !defined(__FLAT__)
   ret = farmalloc(size);
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
   ret = halloc(size, 1);
# else
   ret = malloc(size);
# endif
#endif

   if (ret == NULL)
   {
      png_error(png_ptr, "Out of Memory");
   }

   return ret;
}
Exemple #14
0
void far *malloca(unsigned long nbytes)
{
  void *buf;

  buf=farmalloc(nbytes+1);
  return(buf);
}
Exemple #15
0
void Save_Screen( int x1, int y1, int x2, int y2 ) {
	register int x, y;
	int plane;
	if ( img_top >= 7 )
		return;
	if ( y1 > y2 )
		_iswap( &y1, &y2 );
	if ( x1 > x2 )
		_iswap( &x1, &x2 );
	x1 /= 8;
	x2 /= 8;
	if ( scr_ed[img_top].img[0] != NULL )
		return;
	scr_ed[img_top].x1 = x1;
	scr_ed[img_top].x2 = x2;
	scr_ed[img_top].y1 = y1;
	scr_ed[img_top].y2 = y2;
	for ( plane = 0; plane < 4; plane++ ) {
		if ( ( scr_ed[img_top].img[plane] = ( unsigned char far * )farmalloc( ( x2 + 1 - x1 ) * ( y2 + 1 - y1 ) ) ) == NULL ) {
			printf( "Not enough memory" );
			exit( 1 );
		}
		set_readplane( plane );
		for ( y = y1; y <= y2; y++ )
			for ( x = x1; x <= x2; x++ )
				scr_ed[img_top].img[plane][( x - x1 ) + ( y - y1 ) * ( x2 - x1 + 1 )] = scr[x + y * 80];
	}
	img_top += 1;
}
Exemple #16
0
void restore_screen(FILE *fptr, unsigned size)
{
	/* this function will display actual logo and then restore screen */

	int ystart=19,yend,yincr,x;
	void far *ptr[3];

	yincr=(465+1)/3;
	yend=yincr+ystart;

	for(x=0;x<=2;x++)
	{
		if((ptr[x] = farmalloc(size)) == NULL)
		{
			closegraph();
			printf("Error: not enough heap size in restore_screen().\n");
			exit(1);
		}
		fread(ptr[x],size,1,fptr);
		putimage(105,ystart,ptr[x],COPY_PUT);
		ystart=yend+1;
		yend+=yincr+1;
		farfree(ptr[x]);
	}
}
Exemple #17
0
static int load_file(int *Instru,char *cmffile)
  {
  FILE *fp;
  CMFHDR hdr;
  char extradat[32];
  long MusicSize;
  register int j;
    
  if ((fp=fopen(cmffile,"rb")) == NULL)
    {
    //               errorbox("Could not open file","(D)on't Use Music");
    return(1);
    }
  fread((char *)&hdr,1,sizeof(CMFHDR),fp);
  if ( (hdr.id[0]!='C') && (hdr.id[1]!='T') &&
       (hdr.id[2]!='M') && (hdr.id[3]!='F') )
    {
    fclose(fp);
    //              errorbox("This is not a CMF file!","(D)on't Use Music");
    return(2);
    }
  if (hdr.clock_ticks != HDRCLK)
    {
    fclose(fp);
    //              errorbox("This file has not been converted for use",
    //                       "with Game-Maker!    (D)on't use music");
    return(3);
    }
  *Instru=hdr.inst_num;
  fseek(fp,0L,SEEK_END);
  MusicSize = ftell(fp)-(long)hdr.music_blk;
  if ( ((inst = (char *)farmalloc((long)(hdr.inst_num*16))) == NULL) ||
       ((sbmusic = (unsigned char *)farmalloc(MusicSize)) == NULL)  )
    {
    fclose(fp);
    sbfreemem();
    //             errorbox("Not enough memory!","(D)on't Use Music");
    return(4);
    }
  fseek(fp,(long)hdr.inst_blk,SEEK_SET);
  fread(inst,1,(hdr.inst_num*16),fp);
  fseek(fp,(long)hdr.music_blk,SEEK_SET);
  fread((unsigned char *)sbmusic,1,MusicSize,fp);
  fclose(fp);
  return(0);
  }
Exemple #18
0
void install_new_key_handler(void)
{
  keybuf = farmalloc(KEY_WAS_PRESSED * 2);
  clear_key_buffer();

  old_int09_handler = getvect(9);
  setvect(9, new_int09_handler);
  new_key_handler_installed = TRUE;
}
Exemple #19
0
/* initialize a new object */
void init_object(int x,int y,int width, int height, int xdir, int ydir,
  char far * image){
  int i;
  objects[object_count].X = objects[object_count].XOtherPage = x;
  objects[object_count].Y = objects[object_count].YOtherPage = y;
  objects[object_count].Width = width;
  objects[object_count].Height = height;
  objects[object_count].XDir = xdir;
  objects[object_count].YDir = ydir;
  objects[object_count].Image = image;
  objects[object_count].bg = (char far *) farmalloc(4*width*height+20);
  objects[object_count].bgOtherPage = (char far *) farmalloc(4*width*height+20);
  x_get_pbm(x,y,(unsigned)width,height,VisiblePageOffs,
	objects[object_count].bg);
  x_get_pbm(x,y,(unsigned)width,height,HiddenPageOffs,
	objects[object_count].bgOtherPage);
  object_count++;
}
Exemple #20
0
void _HUGE* PrfDameMemoria (DWORD Tamano)

{
void _HUGE*x;

if ((x=(void _HUGE*)farmalloc(Tamano)) == NULL)
    InformacionError=Tamano;
return x;

}
/* Reads an instance of TMDIClient from the passed ipstream. */
void *TMDIClient::read(ipstream& is)
{
  TWindow::read(is);
  ClientAttr = (LPCLIENTCREATESTRUCT)farmalloc(sizeof(CLIENTCREATESTRUCT));

  WORD idFirstChild = ClientAttr->idFirstChild; // prevent compiler warning
  is >> idFirstChild;
  ClientAttr->hWindowMenu = (HMENU)0;
  Attr.Param = (LPSTR)ClientAttr;
  return this;
}
Exemple #22
0
void main(void)
 {
   char far *string;
   int far *int_values;
   float far *float_values;

   if ((string = (char *) farmalloc(50)))
     printf("Successfully allocated a 50 byte string\n");
   else
     printf("Error allocating string\n");

   if ((int_values = (int *) farmalloc(100 * sizeof(int))) != NULL)
     printf("Successfully allocated int_values[100]\n");
   else 
     printf("Error allocating int_values[100]\n");

   if ((float_values = (float *) farmalloc(25 * sizeof(float))) != NULL)
     printf("Successfully allocated float_values[25]\n");
   else
     printf("Error allocating float_values[25]\n");
 }
Exemple #23
0
void table::scrolldown()
{
	void far *bitmap=(void far*)farmalloc(visiblecolumns*visiblerows+10);
	if(windowposy+visiblerows<ROWS-1)
	{
		windowposy++;
		getimage(x1,y1+rowwidth,x2,y2,bitmap);
		putimage(x1,y1,bitmap,0);
		for(int loop=windowposx;loop<visiblecolumns+windowposx;loop++)
			drawvalue(loop,windowposy+visiblerows-1);
	}
	farfree(bitmap);
}
Exemple #24
0
png_voidp PNGAPI
png_malloc_default(png_structp png_ptr, png_uint_32 size) {
    png_voidp ret;
#endif /* PNG_USER_MEM_SUPPORTED */

    if (png_ptr == NULL || size == 0) {
        return (NULL);
    }

#ifdef PNG_MAX_MALLOC_64K
    if (size > (png_uint_32)65536L) {
#ifndef PNG_USER_MEM_SUPPORTED
        if ((png_ptr->flags & PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) {
            png_error(png_ptr, "Cannot Allocate > 64K");
        } else
#endif
            return NULL;
    }
#endif

    /* Check for overflow */
#if defined(__TURBOC__) && !defined(__FLAT__)
    if (size != (unsigned long)size) {
        ret = NULL;
    } else {
        ret = farmalloc(size);
    }
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
if (size != (unsigned long)size) {
    ret = NULL;
} else {
    ret = halloc(size, 1);
}
# else
if (size != (size_t)size) {
    ret = NULL;
} else {
    ret = malloc((size_t)size);
}
# endif
#endif

#ifndef PNG_USER_MEM_SUPPORTED
    if (ret == NULL && (png_ptr->flags & PNG_FLAG_MALLOC_NULL_MEM_OK) == 0) {
        png_error(png_ptr, "Out of Memory");
    }
#endif

    return (ret);
}
/* Constructor for a TMDIClient.  Initializes its data fields using
   passed parameter and default values. If this is not done, the default
   size of the window would be zero.  Allocates space for the
   CLIENTCREATESTRUCT on the heap and sets ClientAttr to point to this
   space. */
TMDIClient::TMDIClient(TMDIFrame *AParent, PTModule AModule)
           : TWindow(AParent, NULL, AModule)
{
  Attr.Id = ID_MDICLIENT;
  Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_CLIPCHILDREN;
  Attr.X = CW_USEDEFAULT;    Attr.Y = 0;
  Attr.W = CW_USEDEFAULT;    Attr.H = 0;

  ClientAttr = (LPCLIENTCREATESTRUCT)farmalloc(sizeof(CLIENTCREATESTRUCT));
  ClientAttr->hWindowMenu = (HMENU)0;
  ClientAttr->idFirstChild = ID_FIRSTMDICHILD;
  Attr.Param = (LPSTR)ClientAttr;
  SetFlags(WB_MDICHILD, FALSE);
}
Exemple #26
0
unsigned long my_farcoreleft(void)
{	unsigned long len, probe;

	for(len = 0, probe = 0x80000000l; probe; probe >>= 1) {
		void far*p;

		if((p = farmalloc(len | probe)) != 0) {
			len |= probe;
			farfree(p);
		}
	}

	return len;
}
Exemple #27
0
word SetGroupFreeSpace( byte Device, byte Party, dword GroupID,
			word FreeSpaceSec )
// - free space is in sectors
{
 MasterBootRecord MBR;

 word     far *Buffer = (word far *)farmalloc(512lu);
 if( !Buffer ) { printf("\n Not enough far memory in %s line %d...", __FILE__, __LINE__ ); exit(0); }

 // read MBR
 if( LoadMasterBoot( Device, &MBR ) )
 {
  farfree( Buffer );
  return ERR_FS_FATAL_ERROR;
 }

 // stat sector is second on party
 dword GroupSec    = GroupID/512lu,    // 512 records in one sector
       GroupSecOff = GroupID%512lu;

       GroupSec   += MBR.PartyTable.Party[Party-1].FirstSectorOff+2lu;
		     // 1 boot record + 1 second boot
		     // => now points to first grp stat sector
		     // offset in this statistic already counted

 // read group stat sector boot
 if( ReadLogicalSector( Device, GroupSec, Buffer ) )
 {
  farfree( Buffer );
  return ERR_FS_FATAL_ERROR;
 }

 // get free space in sectors
 Buffer[GroupSecOff]=FreeSpaceSec;

 #ifdef DEBUG
  printf("\n New free sectors in group %lu is %u...", GroupID, FreeSpaceSec );
 #endif

 // write new values
 if( WriteLogicalSector( Device, GroupSec, Buffer ) )
 {
  farfree( Buffer );
  return ERR_FS_FATAL_ERROR;
 }


 farfree( Buffer );
 return ERR_FS_NO_ERROR;
}
Exemple #28
0
void table::scrollup()
{
	void far *bitmap=(void far*)farmalloc(visiblecolumns*visiblerows+10);
	if(windowposy>0)
	{
		windowposy--;
		getimage(x1,y1,x2,y2-rowwidth,bitmap);
		putimage(x1,y1+rowwidth,bitmap,0);
		for(int loop=windowposx;loop<windowposx+visiblecolumns;loop++)
			drawvalue(loop,windowposy);
	}
	farfree(bitmap);

}
Exemple #29
0
void load_user_fonts(){
  FILE *f;
  int i; char c;
  f=fopen("var6x8.fnt","rb");
  newfnt = farmalloc(256*16+4);
  for (i=0;i<256*16+4;i++){
    fread(&c,1,1,f);
    *(newfnt+i)=c;
  }
  fclose(f);
  x_text_init();
  x_register_userfont(newfnt);
  x_set_font(2);
}
Exemple #30
0
void *mem_alloc(ULONG bytes) {
	ULONG *ptr;

	ptr = (ULONG*) farmalloc(bytes);

	if (ptr == NULL) {
		system_err = OUT_OF_MEMORY;
		report(E_FATAL, NULL, MSG_OOM);
	}

	checksum ^= (ULONG) *ptr;

	return (ptr);
}