Ejemplo n.º 1
0
unsigned allocMemBlk(const unsigned size, const unsigned Xmode)
{	unsigned mode = Xmode;

	assert(size);
	if(forceLow)
		mode &= ~0x80;		/* Remove the "Use UMB" bit */
	return allocBlk(size, mode);
}
Ejemplo n.º 2
0
unsigned allocSysBlk(const unsigned size, const unsigned mode)
{	unsigned segm;
	struct MCB _seg *mcb;

	if((segm = allocBlk(size, mode)) != 0) {
		mcb = (struct MCB _seg*)SEG2MCB(segm);
		mcb->mcb_ownerPSP = 8;
		dprintf(("[MEM: allocated system memory block: %04x/%u]\n"
		 , segm, size));
	}

	return segm;
}
Ejemplo n.º 3
0
unsigned msgSegment(void)              /* load messages into memory */
{
  FILE *f;
  size_t len;
  struct REGPACK r;

  if(msgSegm)     /* already loaded */
    return msgSegm;

  if ((f = openStrFile()) == NULL)
    return 0;

  /* At this point f is positioned at the very first string index
     the data area is NUMBER_OF_STRINGS * sizeof(index) +
     SIZE_OF_STRINGS   */
  len = SIZE_OF_STRINGS + NUMBER_OF_STRINGS * sizeof(struct indextype);
  /* allocation mode: last fit, high first */
  if ((msgSegm = allocBlk(len, 0x82)) == 0)
  {
    fclose(f);
    return 0;
  }

  /* synchronize FILE* with file descriptor */
  lseek(fileno(f), ftell(f), SEEK_SET);
  r.r_ax = 0x3f00;              /* read from file descriptor */
  r.r_bx = fileno(f);           /* file descriptor */
  r.r_cx = len;                 /* size of block to read */
  r.r_ds = msgSegm;             /* segment of buffer to read block to */
  r.r_dx = 0;                   /* offset of buffer to read block to */
  intr(0x21, &r);               /* perform DOS API */
  if ((r.r_flags & 1) != 0      /* read failed */
      || r.r_ax != len)       /* couldn't read everything */
  {
    unloadMsgs();
    fclose(f);
    return 0;
  }

  dprintf(("[Messages successfully loaded to segment 0x%04x]\n", msgSegm));

  /* strings read successfully */
  fclose(f);
  return msgSegm;
}
Ejemplo n.º 4
0
int loadStrings(res_majorid_t major
	, res_minorid_t minor
	, long length
	, FILE* f
	, void * const arg)
{	loadStatus *ls = arg;
	char fdid[sizeof(STRINGS_ID)];
	string_size_t len, firstStr;
	string_index_t far*idx;
	int i;

	if((unsigned long)length >= 0x10000ul
	 || (unsigned)length < STRINGS_HEADER_SIZE) {
		*ls = STRINGS_SIZE_MISMATCH;
		return 0;
	}

	fread(fdid, sizeof(STRINGS_ID) - 1, 1, f);

	if (memcmp(fdid, STRINGS_ID, sizeof(STRINGS_ID) - 1)) {
		*ls = STRINGS_ID_MISMATCH;
		return 0;			/* Continue searching */
	}
	/* immediately after the ID a trailer follows */
	fseek(f, (long)STRINGS_ID_TRAILER, 1);

		/* Read the strings dimensionating parameters */
	if(ferror(f)
	 || fread(&strCnt, sizeof(strCnt), 1, f) != 1
	 || fread(&len, sizeof(len), 1, f) != 1) { /* Read error */
	 	*ls = STRINGS_READ_ERROR;
	 	return 0;			/* Continue searching */
	}
	/* At this point f is positioned at the very first string index
	 the data area is NUMBER_OF_STRINGS * sizeof(index) +
	 SIZE_OF_STRINGS   */
	len += firstStr = strCnt * sizeof(string_index_t);
	if((unsigned)length - STRINGS_HEADER_SIZE < len) {
		*ls = STRINGS_SIZE_MISMATCH;
		return 0;
	}
		/* allocation mode: last fit, high first */
	if ((msgSegm = allocBlk(len, 0x82)) == 0) {
		*ls = STRINGS_OUT_OF_MEMORY;
		return 0;
	}

	if(farread(MK_FP(msgSegm, 0), len, f) != len) {
		unloadMsgs();			/* Remove the message segment */
		*ls = STRINGS_READ_ERROR;
		return 0;
	}

	/* Now the offset of the index array are updated to point to the
		real offset instead of the displacement based on the first
		byte of the string data area */
	idx = MK_FP(msgSegm, 0);
	for(i = 0; i < strCnt; ++i)
		idx[i].index += firstStr;

	*ls = STRINGS_LOADED;
	return 1;		/* Stop searching */
}