Ejemplo n.º 1
0
int main(int argc, char* argv[]) {
  int i,j = 0;
  unsigned int frame = 0;
  char *rom_file = NULL;
  int rom_size = 0;
  double z80_cycles = 0;

  if (argc < 2) {
    fprintf(stderr, "Usage: %s ROM_FILE\n", argv[0]);
    return 1;
  }

  rom_file = argv[1];
  memory_init();
  rom_size = memory_load(rom_file);

  if (rom_size < 0) {
    fprintf(stderr, "Couldn't read ROM file %s\n", rom_file);
    return 1;
  }

  printf("Read ROM %s (%d bytes)\n", rom_file, rom_size);

  io_init();
  video_init();
  input_init();
  vpu_init();

  Z80Reset(&z80_state);
  z80_state.pc = 0;

  while (input_quit() == 0) {
    z80_cycles += Z80Emulate(&z80_state, Z80_CYCLES_PER_STEP);

    vpu_draw_screen();

    video_flip();
    video_wait_frame();

    input_process();

    Z80NonMaskableInterrupt (&z80_state);

    frame++;
  }

  printf("Ran %d frames and %f Z80 cycles.\n", frame, z80_cycles);

  return 0;
}
Ejemplo n.º 2
0
int main (int argc, char *const argv[])
{
    parser_result_t *config;
    
    config = try_input(argc, argv);

    run_flags = config->flags;

    memory_load(config);

    cpu_run(config->ninst, config->pc);

    cpu_status();
    if (run_flags & FLAG_WATCHMEM)
        show_interval_memory(config->watch_begin, config->watch_end); 
    return 0;
}
Ejemplo n.º 3
0
void *memory_user_autoload(char *prefix, char *selector, int l, int extension, int exit)
{
  char **files = memory_alloc(l);
  char *adr = malloc(strlen(prefix)+strlen(selector)+1);
  void *data;
  int x;

  sprintf(adr,"%s%s",prefix,selector);
  x = memory_find(adr,files,l);
  free(adr);
  x = memory_user_select(files,x,extension,exit);

  adr = malloc(strlen(prefix)+strlen(files[x])+1);
  sprintf(adr,"%s%s",prefix,files[x]);
  data = memory_load(adr);

  free(adr);
  memory_free(files,l);
  return data;
}
Ejemplo n.º 4
0
int load_memory(void) {
    config_setting_t *pmemory;
    config_setting_t *pblock;
    config_setting_t *args;
    config_setting_t *arg;

    int memory_items = 0;
    int arg_items = 0;
    char *name;
    const char *module;

    hw_config_t *hw_config = NULL;

    INFO("Loading memory");
    pmemory = config_lookup(&main_config, "memory");
    if(!pmemory) {
        INFO("No memory blocks to laod");
        return TRUE;
    }

    while(1) {
        pblock = config_setting_get_elem(pmemory, memory_items);
        memory_items++;
        if(!pblock)
            break;

        name = config_setting_name(pblock);

        INFO("Found memory element: %s", name);

        if(!config_setting_lookup_string(pblock, "module", &module)) {
            FATAL("Missing module entry for memory item %s", name);
            exit(1);
        }

        INFO("  Module name: %s", module);
        args = config_setting_get_member(pblock, "args");

        if (!args) {
            hw_config = malloc(sizeof(hw_config_t));
            if (!hw_config) {
                FATAL("malloc");
                exit(1);
            }

            arg_items = 0;
        } else {
            arg_items = config_setting_length(args);
            INFO("  %d arg items", arg_items);
            hw_config = malloc(sizeof(hw_config_t) +
                               (arg_items * sizeof(hw_config_item_t)));
            if(!hw_config) {
                FATAL("malloc");
                exit(1);
            }
        }

        /* now walk the args and put them in a
           config struct */
        hw_config->config_items = arg_items;
        for(int x = 0; x < arg_items; x++) {
            arg = config_setting_get_elem(args, x);
            const char *key = config_setting_name(arg);
            if(!key) {
                FATAL("Bad arg key in %s", name);
                exit(1);
            }
            const char *value = NULL;
            value = config_setting_get_string(arg);

            if(!value) {
                FATAL("Bad arg value for %s in %s",
                      key, name);
                exit(1);
            }

            hw_config->item[x].key = key;
            hw_config->item[x].value = value;

            INFO("    %s => %s", key, value);
        }

        /* now, let's load it */
        memory_load(name, module, hw_config);

        if (hw_config) {
            free(hw_config);
            hw_config = NULL;
        }
    }

    INFO("Memory loaded");
    return TRUE;
}