Example #1
0
/* Handle reset button if poweron=0;
   handle hard reset or initial poweron if poweron=1 */
void trs_reset(int poweron)
{
    trs_emu_mouse = FALSE;

#ifndef ANDROID
    /* Close disks opened by Z80 programs */
    do_emt_resetdisk();
#endif
    /* Reset devices (Model I SYSRES, Model III/4 RESET) */
    trs_cassette_reset();
    trs_timer_speed(0);
    trs_disk_init(poweron); // also inits trs_hard and trs_stringy
    /* I'm told that the hard disk controller is enabled on powerup */
    /* XXX should trs_hard_init do this, then? */
    trs_hard_out(TRS_HARD_CONTROL,
		 TRS_HARD_SOFTWARE_RESET|TRS_HARD_DEVICE_ENABLE);
    if (trs_model == 5) {
        /* Switch in boot ROM */
	z80_out(0x9C, 1);
    }
    if (trs_model >= 4) {
        /* Turn off various memory map and video mode bits */
	z80_out(0x84, 0);
    }
    if (trs_model >= 3) {
	grafyx_write_mode(0);
	trs_interrupt_mask_write(0);
	trs_nmi_mask_write(0);
    }
    if (trs_model == 3) {
        grafyx_m3_reset();
    }
    if (trs_model == 1) {
	hrg_onoff(0);		/* Switch off HRG1B hi-res graphics. */
    }
    trs_kb_reset();  /* Part of keyboard stretch kludge */

    trs_cancel_event();
    trs_timer_interrupt(0);
    if (poweron || trs_model >= 4) {
        /* Reset processor */
	z80_reset();
    } else {
	/* Signal a nonmaskable interrupt. */
	trs_reset_button_interrupt(1);
	trs_schedule_event(trs_reset_button_interrupt, 0, 2000);
    }
}
Example #2
0
static void init_xtrs(JNIEnv* env, jint model, jstring romFile, Ushort entryAddr, jstring xtrsCassette,
                      jstring xtrsDisk0, jstring xtrsDisk1, jstring xtrsDisk2, jstring xtrsDisk3) {
    int debug = FALSE;

    program_name = "xtrs";
    check_endian();
    trs_model = model;
    init_emulator();

    const char* path = (*env)->GetStringUTFChars(env, romFile, NULL);
    char* dest = NULL;
    switch(model) {
    case 1:
        dest = romfile;
        break;
    case 3:
        dest = romfile3;
        break;
    case 4:
    case 5:
        dest = romfile4p;
        break;
    }
    strncpy(dest, path, FILENAME_MAX);
    (*env)->ReleaseStringUTFChars(env, romFile, path);
    trs_autodelay = 1;
    trs_emtsafe = 1;
    trs_show_led = 0;
    timer_overclock = 0;
    grafyx_set_microlabs(0);
    trs_disk_doubler = TRSDISK_BOTH;
    trs_disk_truedam = 0;
    trs_uart_name = "UART";
    trs_uart_switches = 0;
    trs_kb_bracket(0);
    mem_init();
    trs_rom_init();
    trs_screen_init();
    trs_timer_init();
    trs_reset(1);
    // Cassette
    trs_cassette_remove();
    if (xtrsCassette != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsCassette, NULL);
        trs_cassette_insert((char*) path);
        (*env)->ReleaseStringUTFChars(env, xtrsCassette, path);
    }
    // Disk 0
    trs_disk_remove(0);
    if (xtrsDisk0 != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsDisk0, NULL);
        if (ends_with(path, ".cmd")) {
            FILE* f = fopen(path, "rb");
            load_cmd(f, memory, NULL, 0, NULL, -1, NULL, &entryAddr, 1);
            fclose(f);
        } else {
            trs_disk_insert(0, (char *) path);
        }
        (*env)->ReleaseStringUTFChars(env, xtrsDisk0, path);
    }
    // Disk 1
    trs_disk_remove(1);
    if (xtrsDisk1 != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsDisk1, NULL);
        trs_disk_insert(1, (char*) path);
        (*env)->ReleaseStringUTFChars(env, xtrsDisk1, path);
    }
    // Disk 2
    trs_disk_remove(2);
    if (xtrsDisk2 != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsDisk2, NULL);
        trs_disk_insert(2, (char*) path);
        (*env)->ReleaseStringUTFChars(env, xtrsDisk2, path);
    }
    // Disk 3
    trs_disk_remove(3);
    if (xtrsDisk3 != NULL) {
        path = (*env)->GetStringUTFChars(env, xtrsDisk3, NULL);
        trs_disk_insert(3, (char*) path);
        (*env)->ReleaseStringUTFChars(env, xtrsDisk3, path);
    }

    trs_disk_init(1);
    z80_state.pc.word = entryAddr;
    clear_paste_string();
}
Example #3
0
int SDLmain(int argc, char *argv[])
{
    int debug = FALSE;
    struct stat st;

    /* program_name must be set first because the error
     * printing routines use it. */
    program_name = strrchr(argv[0], '/');
    if (program_name == NULL) {
      program_name = argv[0];
    } else {
      program_name++;
    }

    check_endian();

#ifndef MACOSX
    putenv("SDL_VIDEO_CENTERED=1");
#endif	
    
    if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) != 0) { 
        fprintf(stderr, "Failed to initialize SDL library");
  	    exit(1);
    }
        
    /* Enable Unicode key translations */
    SDL_EnableUNICODE(TRUE); 

    argc = trs_parse_command_line(argc, argv, &debug);
    if (argc > 1) {
      fprintf(stderr, "%s: erroneous argument %s\n", program_name, argv[1]);
      exit(1);
    }
    
    trs_set_keypad_joystick();    
    trs_open_joystick();
    
    if (stat(trs_disk_dir, &st) < 0) {
      strcpy(trs_disk_dir,".");
    }                   
    if (stat(trs_hard_dir, &st) < 0) {
      strcpy(trs_hard_dir,".");
    }                   
    if (stat(trs_cass_dir, &st) < 0) {
      strcpy(trs_cass_dir,".");
    }                   
    if (stat(trs_state_dir, &st) < 0) {
      strcpy(trs_state_dir,".");
    }                   
    if (stat(trs_disk_set_dir, &st) < 0) {
      strcpy(trs_disk_set_dir,".");
    }                   
    if (stat(trs_printer_dir, &st) < 0) {
      strcpy(trs_printer_dir,".");
    }                   
 
    mem_init();
    trs_disk_init(0);
    trs_rom_init();
    trs_screen_init();
    screen_init();
    trs_timer_init();

    trs_reset(1);
    if (init_state_file[0] != 0) {
      trs_state_load(init_state_file);
      trs_screen_init();
      trs_screen_refresh();
      }
#ifdef MACOSX
	TrsOriginSet();
#endif
	
    if (!debug || fullscreen) {
      /* Run continuously until exit or request to enter debugger */
      z80_run(TRUE);
    }
    printf("Entering debugger.\n");
    debug_init();
    debug_shell();
    printf("Quitting.\n");
#ifdef MACOSX
    trs_mac_save_defaults();
#endif
    exit(0);
}