Exemple #1
0
/* ============================================================================
 *  CreateDevice: Creates a new CEN64 device.
 * ========================================================================= */
struct CEN64Device *
CreateDevice(const char *pifROMPath) {
  struct AIFController *aif;
  struct BusController *bus;
  struct PIFController *pif;
  struct RDRAMController *rdram;
  struct ROMController *rom;
  struct VIFController *vif;

  struct VR4300 *vr4300;
  struct RDP *rdp;
  struct RSP *rsp;

  struct CEN64Device *device;

  if ((aif = CreateAIF()) == NULL)
    goto release_out;

  if ((pif = CreatePIF(pifROMPath)) == NULL)
    goto release_aif;

  if ((rom = CreateROM()) == NULL)
    goto release_pif;

  if ((rdp = CreateRDP()) == NULL)
    goto release_rom;

  if ((rdram = CreateRDRAM()) == NULL)
    goto release_rdp;

  if ((rsp = CreateRSP()) == NULL)
    goto release_rdram;

  if ((vif = CreateVIF()) == NULL)
    goto release_rsp;

  if ((vr4300 = CreateVR4300()) == NULL)
    goto release_vif;

  if ((bus = CreateBus(aif, pif, rdram, rom, vif, rdp, rsp, vr4300)) == NULL)
    goto release_vr4300;

  if ((device = (struct CEN64Device*) malloc(
    sizeof(struct CEN64Device))) == NULL) {
    debug("Failed to create all devices.");
    goto release_bus;
  }

  device->aif = aif;
  device->bus = bus;
  device->pif = pif;
  device->rdram = rdram;
  device->rom = rom;
  device->rdp = rdp;
  device->rsp = rsp;
  device->vif = vif;
  device->vr4300 = vr4300;

  return device;

  /* Deallocate memory on failure. */
  release_bus:    DestroyBus(bus);
  release_vr4300: DestroyVR4300(vr4300);
  release_vif:    DestroyVIF(vif);
  release_rsp:    DestroyRSP(rsp);
  release_rdram:  DestroyRDRAM(rdram);
  release_rdp:    DestroyRDP(rdp);
  release_rom:    DestroyROM(rom);
  release_pif:    DestroyPIF(pif);
  release_aif:    DestroyAIF(aif);
  release_out:

  return NULL;
}
Exemple #2
0
/* Entry point. */
int main(int argc, const char *argv[]) {
	FILE *rspUCodeFile;
	struct RSP *rsp;
	size_t total, size;
	long i, cycles;

	if (argc != 3) {
		printf("Usage: %s <uCode> <Cycles>\n", argv[0]);
		return 0;
	}

	/* Open the uCode file, create an RSP instance. */
	if ((rspUCodeFile = fopen(argv[1], "rb")) == NULL) {
		printf("Failed to open RSP uCode.\n");

		return 1;
	}

	if ((rsp = CreateRSP()) == NULL) {
		printf("Failed to initialize the RSP.\n");

		fclose(rspUCodeFile);
		return 2;
	}

	/* Read the uCode into the RSP. */
	for (size = 0, total = 0; total < 4096; total += size) {
		size = fread(rsp->imem + total, 1, 4096 - total, rspUCodeFile);

		if (ferror(rspUCodeFile)) {
			printf("Unable to read the uCode file.\n");

			fclose(rspUCodeFile);
			DestroyRSP(rsp);
			return 3;
		}
	}

	/* Read the uCode into the RSP. */
	for (size = 0, total = 0; total < 4096; total += size) {
		size = fread(rsp->dmem + total, 1, 4096 - total, rspUCodeFile);

		if (ferror(rspUCodeFile)) {
			printf("Unable to read the uCode file.\n");

			fclose(rspUCodeFile);
			DestroyRSP(rsp);
			return 3;
		}
	}

	fclose(rspUCodeFile);
	cycles = strtol(argv[2], NULL, 10);

	printf("Running RSP for %ld cycles.\n", cycles);
  rsp->cp0.regs[SP_STATUS_REG] = 0; /* Unhalt. */

	for (i = 0; i < cycles; i++)
		CycleRSP(rsp);

	RSPDumpRegisters(rsp);
	return 0;
}