Exemplo n.º 1
0
ushort readushort(gzFile f)
{
    ushort t;
    gzread(f, &t, sizeof(ushort));
    endianswap(&t, sizeof(ushort), 1);
    return t;
}
Exemplo n.º 2
0
// -----------------------------------------------------------------------
int mem_mega_init(int modc, char *prom_image)
{
	int res;
	int mp, seg;
	FILE *f;

	if (modc == 0) {
		return E_OK;
	}

	if ((modc < 0) || (modc > MEM_MAX_MODULES)) {
		return E_MEM;
	}

	mem_mega_mp_start = MEM_MAX_MODULES-modc;
	mem_mega_mp_end = MEM_MAX_MODULES-1;

	LOG(L_MEM, 1, "MEGA modules: %d-%d, %d segments", mem_mega_mp_start, mem_mega_mp_end, MEM_MAX_MEGA_SEGMENTS);

	for (mp=mem_mega_mp_start ; mp<=mem_mega_mp_end ; mp++) {
		for (seg=0 ; seg<MEM_MAX_MEGA_SEGMENTS; seg++) {
			mem_mega[mp][seg] = calloc(sizeof(uint16_t), MEM_SEGMENT_SIZE);
			if (!mem_mega[mp][seg]) {
				return E_ALLOC;
			}
		}
	}

	// allocate memory for MEGA PROM
	mem_mega_prom_hidden = 0;
	mem_mega_prom = malloc(sizeof(uint16_t) * MEM_SEGMENT_SIZE);
	if (!mem_mega_prom) {
		return E_ALLOC;
	}

	// load PROM image
	if (prom_image && *prom_image) {
		f = fopen(prom_image, "rb");
		if (!f) {
			return E_FILE_OPEN;
		}
		res = fread(mem_mega_prom, sizeof(uint16_t), MEM_SEGMENT_SIZE, f);
		if (res != MEM_SEGMENT_SIZE) {
			fclose(f);
			return E_FILE_OPERATION;
		}
		fclose(f);
		endianswap(mem_mega_prom, res);
		LOG(L_MEM, 1, "Loaded MEGA PROM image: %s (%i words)", prom_image, res);
	} else {
		LOG(L_MEM, 1, "Empty MEGA PROM");
	}

	mem_mega_init_done = 0;

	return E_OK;
}
Exemplo n.º 3
0
Arquivo: cpu.c Projeto: jakubfi/em400
// -----------------------------------------------------------------------
int ectl_load(FILE *f, const char *name, int seg, uint16_t saddr)
{
	LOG(L_ECTL, "ECTL load: %i:0x%04x %s", seg, saddr, name);
	uint16_t *bufw = (uint16_t *) malloc(sizeof(uint16_t) * 0x10000);
	uint16_t *bufr = (uint16_t *) malloc(sizeof(uint16_t) * 0x10000);

	int res = fread(bufw, sizeof(uint16_t), 0x10000, f);
	if (res > 0) {
		endianswap(bufw, res);
		res = ectl_mem_set(seg, saddr, bufw, res);
		LOG(L_ECTL, "ECTL verify");
		ectl_mem_get(seg, saddr, bufr, res);
		int cmpres = memcmp(bufw, bufr, res * sizeof(uint16_t));
		LOG(L_ECTL, "ECTL verify (%i words): %s", res, cmpres ? "FAILED" : "OK");
		if (cmpres != 0) {
			res = -1;
		}
	}

	free(bufw);
	free(bufr);
	return res;
}
Exemplo n.º 4
0
void writeushort(gzFile f, ushort u)
{
    endianswap(&u, sizeof(ushort), 1);
    gzwrite(f, &u, sizeof(ushort));
}