Exemple #1
0
void trs_protect_disk(int drive, int writeprot)
{
  char prot_filename[FILENAME_MAX];
  FILE *f;
  char *diskname;
  int emutype = trs_disk_getdisktype(drive);
  
  diskname = trs_disk_getfilename(drive);
  if (diskname[0] == 0)
    return;
    
  strcpy(prot_filename, diskname);
#ifndef _WIN32  
  if (stat(prot_filename, &st) < 0)
    return;
#endif    
  trs_disk_remove(drive);
  
  if (emutype == JV3 || emutype == DMK) {
#ifdef _WIN32  
    win_set_readonly(prot_filename,0);
#else
    chmod(prot_filename, st.st_mode | (S_IWUSR|S_IWGRP|S_IWOTH));
#endif
    f=fopen(prot_filename,"r+");
    if (f!=NULL) {
      if (emutype == JV3) {
        /* Set the magic byte */
        fseek(f, 256*34-1, 0);
        putc(writeprot ? 0 : 0xff, f);
      } else {
        /* Set the magic byte */
        putc(writeprot ? 0xff : 0, f);
      }
      fclose(f);  
    }
  }
    
#ifdef _WIN32  
  win_set_readonly(prot_filename,writeprot);
#else
  if (writeprot) 
    newmode = st.st_mode & ~(S_IWUSR|S_IWGRP|S_IWOTH);
  else 
    newmode = st.st_mode | (S_IWUSR|S_IWGRP|S_IWOTH);
  chmod(prot_filename, newmode);
#endif  
  trs_disk_insert(drive,prot_filename);
}
Exemple #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();
}