src/emulation/emulation.cc
/*
 * Attempts to create an emulation object using the given configuration object
 * and rom file.
 *
 * Returns NULL on failure. Fails if any of the objects necessary for the
 * emulation cannot be created.
 */
Attempts to create an emulation object using the given configuration object
and rom file.

Returns NULL on failure. Fails if any of the objects necessary for the
emulation cannot be created.
Attempts to create an emulation object using the given configuration object and rom file . Returns NULL on failure . Fails if any of the objects necessary for the emulation cannot be created .
Emulation *Emulation::Create(FILE *rom, Config *config) {
  Window *window = Window::Create(config);
  if (window == NULL) {
    fprintf(stderr, "Error: failed to create SDL window.\n");
    return NULL;
  }
  Memory *memory = Memory::Create(rom, config);
  if (memory == NULL) {
    fprintf(stderr, "Error: Failed to create emulated memory for rom.\n");
    delete window;
    return NULL;
  }
  Cpu *cpu = new Cpu();
  Ppu *ppu = new Ppu();
  Apu *apu = new Apu();
  window->GetRenderer()->SetPalette(memory->PaletteExpose());
  memory->AddController(window->GetInput());
  memory->Connect(cpu, ppu, apu);
  cpu->Connect(memory);
  ppu->Connect(memory, window->GetRenderer(), &(cpu->nmi_line_));
  apu->Connect(memory, window->GetAudioPlayer(), &(cpu->irq_line_));
  cpu->Power();
  return new Emulation(window, memory, cpu, ppu, apu);
}
Emulation * Emulation :: Create ( FILE * rom , Config * config ) { Window * window = Window :: Create ( config ) ; if ( window == NULL ) { fprintf ( stderr , " \n " ) ; return NULL ; } Memory * memory = Memory :: Create ( rom , config ) ; if ( memory == NULL ) { fprintf ( stderr , " \n " ) ; delete window ; return NULL ; } Cpu * cpu = new Cpu ( ) ; Ppu * ppu = new Ppu ( ) ; Apu * apu = new Apu ( ) ; window -> GetRenderer ( ) -> SetPalette ( memory -> PaletteExpose ( ) ) ; memory -> AddController ( window -> GetInput ( ) ) ; memory -> Connect ( cpu , ppu , apu ) ; cpu -> Connect ( memory ) ; ppu -> Connect ( memory , window -> GetRenderer ( ) , & ( cpu -> nmi_line_ ) ) ; apu -> Connect ( memory , window -> GetAudioPlayer ( ) , & ( cpu -> irq_line_ ) ) ; cpu -> Power ( ) ; return new Emulation ( window , memory , cpu , ppu , apu ) ; }
Attempts to create an emulation object using the given configuration object
 and rom file.
Attempts to create an emulation object using the given configuration object and rom file .
// Attempt to create the SDL window. // Attempt to create a Memory object with the given rom file. // Create the NES APU, CPU, and PPU. // Connect all of the emulated NES systems together. // Prepare the CPU for the emulation. // Create and return an emulation object.