Ejemplo n.º 1
0
void GBReset(struct LR35902Core* cpu) {
	struct GB* gb = (struct GB*) cpu->master;

	const struct GBCartridge* cart = (const struct GBCartridge*) &gb->memory.rom[0x100];
	if (cart->cgb & 0x80) {
		gb->model = GB_MODEL_CGB;
		gb->audio.style = GB_AUDIO_CGB;
		cpu->a = 0x11;
		cpu->f.packed = 0x80;
		cpu->c = 0;
		cpu->e = 0x08;
		cpu->h = 0;
		cpu->l = 0x7C;
	} else {
		// TODO: SGB
		gb->model = GB_MODEL_DMG;
		gb->audio.style = GB_AUDIO_DMG;
		cpu->a = 1;
		cpu->f.packed = 0xB0;
		cpu->c = 0x13;
		cpu->e = 0xD8;
		cpu->h = 1;
		cpu->l = 0x4D;
	}
	cpu->b = 0;
	cpu->d = 0;
	cpu->sp = 0xFFFE;
	cpu->pc = 0x100;

	if (gb->yankedRomSize) {
		gb->memory.romSize = gb->yankedRomSize;
		gb->yankedRomSize = 0;
	}
	GBMemoryReset(gb);
	GBVideoReset(&gb->video);
	GBTimerReset(&gb->timer);
	GBIOReset(gb);
	GBAudioReset(&gb->audio);
}
Ejemplo n.º 2
0
void GBReset(struct LR35902Core* cpu) {
	struct GB* gb = (struct GB*) cpu->master;
	GBDetectModel(gb);
	if (gb->biosVf) {
		if (!GBIsBIOS(gb->biosVf)) {
			gb->biosVf->close(gb->biosVf);
			gb->biosVf = NULL;
		} else {
			gb->biosVf->seek(gb->biosVf, 0, SEEK_SET);
			gb->memory.romBase = malloc(GB_SIZE_CART_BANK0);
			ssize_t size = gb->biosVf->read(gb->biosVf, gb->memory.romBase, GB_SIZE_CART_BANK0);
			memcpy(&gb->memory.romBase[size], &gb->memory.rom[size], GB_SIZE_CART_BANK0 - size);
			if (size > 0x100) {
				memcpy(&gb->memory.romBase[0x100], &gb->memory.rom[0x100], sizeof(struct GBCartridge));
			}

			cpu->a = 0;
			cpu->f.packed = 0;
			cpu->c = 0;
			cpu->e = 0;
			cpu->h = 0;
			cpu->l = 0;
			cpu->sp = 0;
			cpu->pc = 0;
		}
	}

	cpu->b = 0;
	cpu->d = 0;

	if (!gb->biosVf) {
		switch (gb->model) {
		case GB_MODEL_DMG:
			// TODO: SGB
		case GB_MODEL_SGB:
		case GB_MODEL_AUTODETECT: // Silence warnings
			gb->model = GB_MODEL_DMG;
			cpu->a = 1;
			cpu->f.packed = 0xB0;
			cpu->c = 0x13;
			cpu->e = 0xD8;
			cpu->h = 1;
			cpu->l = 0x4D;
			break;
		case GB_MODEL_AGB:
			cpu->b = 1;
			// Fall through
		case GB_MODEL_CGB:
			cpu->a = 0x11;
			cpu->f.packed = 0x80;
			cpu->c = 0;
			cpu->e = 0x08;
			cpu->h = 0;
			cpu->l = 0x7C;
			break;
		}

		cpu->sp = 0xFFFE;
		cpu->pc = 0x100;
	}

	gb->eiPending = INT_MAX;
	gb->doubleSpeed = 0;

	cpu->memory.setActiveRegion(cpu, cpu->pc);

	if (gb->yankedRomSize) {
		gb->memory.romSize = gb->yankedRomSize;
		gb->yankedRomSize = 0;
	}
	GBMemoryReset(gb);
	GBVideoReset(&gb->video);
	GBTimerReset(&gb->timer);
	GBAudioReset(&gb->audio);
	GBIOReset(gb);
	GBSIOReset(&gb->sio);

	GBSavedataUnmask(gb);
}