コード例 #1
0
ファイル: tape.c プロジェクト: SMTDDR/droidsound
/* FIXME: This should be passed through a struct.  */
int tape_init(const tape_init_t *init)
{
    if (tape_log == LOG_ERR) {
        tape_log = log_open("Tape");
    }

    tape_internal_init();
    tape_image_init();

    lib_free(tape_image_dev1);
    tape_image_dev1 = lib_calloc(1, sizeof(tape_image_t));

    tap_init(init);

    tape_init_vars(init);
    tape_traps_install();

    tape_is_initialized = 1;
    return 0;
}
コード例 #2
0
ファイル: vsidcia2.c プロジェクト: OpenEmu/VICE-Core
void cia2_setup_context(machine_context_t *machine_ctx)
{
    cia_context_t *cia;

    machine_ctx->cia2 = lib_calloc(1, sizeof(cia_context_t));
    cia = machine_ctx->cia2;

    cia->prv = NULL;
    cia->context = NULL;

    cia->rmw_flag = &maincpu_rmw_flag;
    cia->clk_ptr = &maincpu_clk;

    cia2_set_timing(cia, C64_PAL_CYCLES_PER_SEC, 50);

    ciacore_setup_context(cia);

    cia->model = cia2_model;

    cia->debugFlag = 0;
    cia->irq_line = IK_NMI;
    cia->myname = lib_msprintf("CIA2");

    cia->undump_ciapa = undump_ciapa;
    cia->undump_ciapb = undump_ciapb;
    cia->store_ciapa = store_ciapa;
    cia->store_ciapb = store_ciapb;
    cia->store_sdr = store_sdr;
    cia->read_ciapa = read_ciapa;
    cia->read_ciapb = read_ciapb;
    cia->read_ciaicr = read_ciaicr;
    cia->read_sdr = read_sdr;
    cia->cia_set_int_clk = cia_set_int_clk;
    cia->cia_restore_int = cia_restore_int;
    cia->do_reset_cia = do_reset_cia;
    cia->pulse_ciapc = pulse_ciapc;
    cia->pre_store = pre_store;
    cia->pre_read = pre_read;
    cia->pre_peek = pre_peek;
}
コード例 #3
0
ファイル: c128cia1.c プロジェクト: SMTDDR/droidsound
void cia1_setup_context(machine_context_t *machine_context)
{
    cia_context_t *cia;

    machine_context->cia1 = lib_calloc(1, sizeof(cia_context_t));
    cia = machine_context->cia1;

    cia->prv = NULL;
    cia->context = NULL;

    cia->rmw_flag = &maincpu_rmw_flag;
    cia->clk_ptr = &maincpu_clk;

    cia->todticks = C64_PAL_CYCLES_PER_RFSH;

    ciacore_setup_context(cia);

    cia->model = cia1_model;

    cia->debugFlag = 0;
    cia->irq_line = IK_IRQ;
    cia->myname = lib_msprintf("CIA1");

    cia->undump_ciapa = undump_ciapa;
    cia->undump_ciapb = undump_ciapb;
    cia->store_ciapa = store_ciapa;
    cia->store_ciapb = store_ciapb;
    cia->store_sdr = store_sdr;
    cia->read_ciapa = read_ciapa;
    cia->read_ciapb = read_ciapb;
    cia->read_ciaicr = read_ciaicr;
    cia->read_sdr = read_sdr;
    cia->cia_set_int_clk = cia_set_int_clk;
    cia->cia_restore_int = cia_restore_int;
    cia->do_reset_cia = do_reset_cia;
    cia->pulse_ciapc = pulse_ciapc;
    cia->pre_store = pre_store;
    cia->pre_read = pre_read;
    cia->pre_peek = pre_peek;
}
コード例 #4
0
ファイル: uisound.c プロジェクト: BigBoss21X/vice-emu
void uisound_menu_create(void)
{
    unsigned int i, num;
    ui_menu_entry_t *devices_submenu;

    num = sound_device_num();

    if (num == 0) {
        return;
    }

    devices_submenu = lib_calloc((size_t)(num + 1), sizeof(ui_menu_entry_t));

    for (i = 0; i < num ; i++) {
        devices_submenu[i].string = (ui_callback_data_t)lib_msprintf("%s", sound_device_name(i));
        devices_submenu[i].type = UI_MENU_TYPE_TICK;
        devices_submenu[i].callback = (ui_callback_t)radio_SoundDeviceName;
        devices_submenu[i].callback_data = (ui_callback_data_t)lib_stralloc(sound_device_name(i));
    }

    sound_settings_submenu[2].sub_menu = devices_submenu;
}
コード例 #5
0
ファイル: initcmdline.c プロジェクト: r-type/vice-libretro
int initcmdline_check_args(int argc, char **argv)
{
    DBG(("initcmdline_check_args (argc:%d)\n", argc));
    if (cmdline_parse(&argc, argv) < 0) {
        archdep_startup_log_error("Error parsing command-line options, bailing out. For help use '-help'\n");
        return -1;
    }
    DBG(("initcmdline_check_args 1 (argc:%d)\n", argc));

    /* The last orphan option is the same as `-autostart'.  */
    if ((argc > 1) && (autostart_string == NULL)) {
        autostart_string = lib_stralloc(argv[1]);
        argc--, argv++;
    }
    DBG(("initcmdline_check_args 2 (argc:%d)\n", argc));

    if (argc > 1) {
        int len = 0, j;

        for (j = 1; j < argc; j++) {
            len += argv[j] ? (int)strlen(argv[j]) : 0;
        }

        {
            char *txt = lib_calloc(1, len + argc + 1);
            for (j = 1; j < argc; j++) {
                if (argv[j]) {
                    strcat(strcat(txt, " "), argv[j]);
                }
            }
            archdep_startup_log_error("Extra arguments on command-line: %s\n",
                                      txt);
            lib_free(txt);
        }
        return -1;
    }

    return 0;
}
コード例 #6
0
ファイル: event.c プロジェクト: martinpiper/VICE
/* writes or replaces version string in the initial event                */
static void event_write_version(void)
{
    BYTE *new_data;
    BYTE *data;
    unsigned int ver_idx;

    if (event_list->base->type != EVENT_INITIAL) {
        /* EVENT_INITIAL is missing (bug in 1.14.xx); fix it */
        event_list_t *new_event;

        new_event = (event_list_t *)lib_calloc(1, sizeof(event_list_t));
        new_event->clk = event_list->base->clk;
        new_event->size = strlen(event_start_snapshot) + 2;
        new_event->type = EVENT_INITIAL;
        data = lib_malloc(new_event->size);
        data[0] = EVENT_START_MODE_FILE_SAVE;
        strcpy((char *)&data[1], event_start_snapshot);
        new_event->data = data;
        new_event->next = event_list->base;
        event_list->base = new_event;
    }

    data = event_list->base->data;

    ver_idx = 1;
    if (data[0] == EVENT_START_MODE_FILE_SAVE)
        ver_idx += strlen((char *)&data[1]) + 1;

    event_list->base->size = ver_idx + strlen(VERSION) + 1;
    new_data = lib_malloc(event_list->base->size);

    memcpy(new_data, data, ver_idx);

    strcpy((char *)&new_data[ver_idx], VERSION);

    event_list->base->data = new_data;
    lib_free(data);
}
コード例 #7
0
ファイル: uited.c プロジェクト: markjreed/vice-emu
static UI_CALLBACK(openGL_set_desktoprefresh)
{
    char *enter_refresh_rate = util_concat(_("Enter refresh rate"), " (Hz): ", NULL);
    char *refresh_rate = util_concat(_("Refresh rate"), ": ", NULL);

    if (!CHECK_MENUS) {
        float f;
        char *buf = lib_calloc(sizeof(char), 10);

        sprintf(buf, "%.0f", openGL_get_canvas_refreshrate());
        ui_input_string(refresh_rate, enter_refresh_rate, buf, 10);
        f = (float) strtol(buf, NULL, 10);
        openGL_set_canvas_refreshrate(f);
        lib_free(buf);
        lib_free(enter_refresh_rate);
        lib_free(refresh_rate);
    } else {
        if (openGL_available(0) && openGL_sync_enabled()) {
            ui_menu_set_sensitive(w, 1);
        } else {
            ui_menu_set_sensitive(w, 0);
        }
    }
}
コード例 #8
0
int __CBeginThread( thread_fn *start_addr, void *stack_bottom,
                    unsigned stack_size, void *arglist )
/******************************************************/
{
    pid_t       pid;
    thread_args td;
    int         rc;

    if( stack_bottom == NULL ) {
        if( stack_size == 0 ) {
            stack_size = 1024*4;
        }
        stack_bottom = lib_calloc( stack_size, 1 );
        if( stack_bottom == NULL ) {
            _RWD_errno = ENOMEM;
            return( -1 );
        }
    }
    __InitMultipleThread();
    td.rtn = start_addr;
    td.argument = arglist;
    td.stack_bottom = stack_bottom;
    rc = __posix_sem_init( &td.event, 1, 0 );
    if( rc == -1 ) return( -1 );
    pid = tfork( stack_bottom, stack_size, begin_thread_helper, &td, 0 );
    if( pid != -1 ) {
        /*
           suspend parent thread so that it can't call _beginthread() again
           before new thread extracts data from "td" (no problem if new
           thread calls _beginthread() since it has its own stack)
        */
        __posix_sem_wait( &td.event );
    }
    __posix_sem_destroy( &td.event );
    return( pid );
}
コード例 #9
0
ファイル: event.c プロジェクト: martinpiper/VICE
void event_register_event_list(event_list_state_t *list)
{
    list->base = (event_list_t *)lib_calloc(1, sizeof(event_list_t));
    list->current = list->base;
}
コード例 #10
0
static int iec_open_write(vdrive_t *vdrive, unsigned int secondary,
                          cbmdos_cmd_parse_t *cmd_parse, const BYTE *name)
{
    bufferinfo_t *p = &(vdrive->buffers[secondary]);
    unsigned int track, sector;
    BYTE *slot = p->slot, *e;

    if (vdrive->image->read_only || VDRIVE_IMAGE_FORMAT_4000_TEST) {
        vdrive_command_set_error(vdrive, CBMDOS_IPE_WRITE_PROTECT_ON, 0, 0);
        return SERIAL_ERROR;
    }

    /* set flag for overwrite mode */
    p->needsupdate = 0;

    if (slot) {
        /* file exists */
        if (*name == '@') {
            /* replace mode: we don't want the dirent updated at all until
                close */
            /* allocate buffers */
            vdrive_alloc_buffer(p, BUFFER_SEQUENTIAL);
            p->bufptr = 2;

            /* Create our own slot, since the one passed is static */
            p->slot = lib_calloc(1, 32);

            /* Copy the static on to the new one. */
            memcpy(p->slot, slot, 32);
            slot = p->slot;

            /* set flag for replace mode */
            p->needsupdate = 1;

            /* find a new track and sector when writing */
            p->track = p->sector = 0;
        } else {
            if (p->readmode == CBMDOS_FAM_APPEND) {
                /* append mode */
                /* allocate buffers */
                vdrive_alloc_buffer(p, BUFFER_SEQUENTIAL);

                /* Create our own slot, since the one passed is static */
                p->slot = lib_calloc(1, 32);

                /* Copy the static on to the new one. */
                memcpy(p->slot, slot, 32);
                slot = p->slot;

                /* set file unclosed */
                p->slot[SLOT_TYPE_OFFSET] &= 0x7f;

                /* get the starting track and sector */
                p->track = track = slot[SLOT_FIRST_TRACK];
                p->sector = sector = slot[SLOT_FIRST_SECTOR];

                /* update block count as we find the end of the file */
                /* the real drives actually don't do this, so each time you
                    append to a file, the block count increases by 1.  I think it
                    is safer to correct the block count. */
                slot[SLOT_NR_BLOCKS] = 255;
                slot[SLOT_NR_BLOCKS + 1] = 255;

                /* scan to the end of the file */
                while (track) {
                    p->track = track;
                    p->sector = sector;
                    if (vdrive_read_sector(vdrive, p->buffer, p->track, p->sector)) {
                        /* couldn't read sector, report error and leave */
                        vdrive_free_buffer(p);
                        vdrive_command_set_error(vdrive, CBMDOS_IPE_ILLEGAL_TRACK_OR_SECTOR, p->track, p->sector);
                        return SERIAL_ERROR;
                    }
                    /* setup next link */
                    track = p->buffer[0];
                    sector = p->buffer[1];

                    /* Increment block count. */
                    if (!(++slot[SLOT_NR_BLOCKS])) {
                        ++slot[SLOT_NR_BLOCKS + 1];
                    }
                }
                /* compensate if the dir link is 0 (rare possibility) */
                if (!p->track) {
                    /* Our loop didn't even execute once, set the block
                       size to 0 */
                    slot[SLOT_NR_BLOCKS] = 0;
                    slot[SLOT_NR_BLOCKS + 1] = 0;
                    /* set buffer pointer to 2 */
                    sector = 1;
                }
                /* set the buffer pointer */
                p->bufptr = sector + 1;
            } else {
                /* can't overwrite an existing file */
                vdrive_iec_close(vdrive, secondary);
                vdrive_command_set_error(vdrive, CBMDOS_IPE_FILE_EXISTS, 0, 0);
                return SERIAL_ERROR;
            }
        }
    } else {
        /* new file... */
        /* create a slot based on the opening name */
        vdrive_dir_create_slot(p, cmd_parse->parsecmd, cmd_parse->parselength,
                               cmd_parse->filetype);

        /* Write the directory entry to disk as an UNCLOSED file. */

        vdrive_dir_find_first_slot(vdrive, NULL, -1, 0, &p->dir);
        e = vdrive_dir_find_next_slot(&p->dir);

        /* If there is not space for the slot, disk is full */
        if (!e) {
            vdrive_free_buffer(p);
            vdrive_command_set_error(vdrive, CBMDOS_IPE_DISK_FULL, 0, 0);
            return SERIAL_ERROR;
        }

        /* find a new track and sector when writing */
        p->track = p->sector = 0;
    }

    if (!p->needsupdate) {
        /* copy the slot information into the sector. */
        memcpy(&p->dir.buffer[p->dir.slot * 32 + 2],
               p->slot + 2, 30);

        /* Write the sector. */
        vdrive_write_sector(vdrive, p->dir.buffer, p->dir.track, p->dir.sector);
    }

    return SERIAL_OK;
}
コード例 #11
0
ファイル: machine.c プロジェクト: AreaScout/vice
void machine_maincpu_init(void)
{
    maincpu_init();
    maincpu_monitor_interface = lib_calloc(1, sizeof(monitor_interface_t));
}
コード例 #12
0
ファイル: cbmdos.c プロジェクト: twinaphex/vice-next
unsigned int cbmdos_command_parse(cbmdos_cmd_parse_t *cmd_parse)
{
    const BYTE *p;
    char *parsecmd, *c;
    int cmdlen;

    cmd_parse->parsecmd = NULL;
    cmd_parse->readmode = (cmd_parse->secondary == 1)
                          ? CBMDOS_FAM_WRITE : CBMDOS_FAM_READ;

    if (cmd_parse->cmd == NULL || cmd_parse->cmdlength == 0)
        return CBMDOS_IPE_NO_NAME;

    p = memchr(cmd_parse->cmd, ':', cmd_parse->cmdlength);

    if (p) {
        p++;
    } else {      /* no colon found */
        if (cmd_parse->cmd[0] != '$') {
            p = cmd_parse->cmd;
        } else {
            /* Directory listings are special - see $da55 in the 1541 for reference*/
            if (cmd_parse->cmdlength > 1) {
                if (cmd_parse->cmdlength == 2 &&
                    (cmd_parse->cmd[1] == '0' || cmd_parse->cmd[1] == '1')) {
                    /* A single 0/1 digit is a drive number, ignore it */
                    p = cmd_parse->cmd + cmd_parse->cmdlength; /* set to null byte */
                } else {
                    /* no colon: everything after $ is the pattern */
                    p = cmd_parse->cmd + 1;
                }
            } else {
                /* Just a single $, set pointer to null byte */
                p = cmd_parse->cmd + cmd_parse->cmdlength;
            }
        }
    }

#if 0
    if (cmd_parse->cmd[0] == '@' && p == cmd_parse->cmd)
        p++;
#endif

    cmdlen = cmd_parse->cmdlength - (p - cmd_parse->cmd);
    cmd_parse->parselength = 0;

    /* Temporary hack.  */
    cmd_parse->parsecmd = lib_calloc(1, cmdlen + 2);

    parsecmd = cmd_parse->parsecmd;

    while (*p != ',' && cmdlen-- > 0) {
        (cmd_parse->parselength)++;
        *(parsecmd++) = *(p++);
    }

    cmd_parse->filetype = 0;

    /*
     * Change modes ?
     */
    while (cmdlen > 0) {
        cmdlen--;
        p++;

        if (cmdlen == 0)
            return CBMDOS_IPE_INVAL;

        switch (*p) {
          case 'S':
            cmd_parse->filetype = CBMDOS_FT_SEQ;
            break;
          case 'P':
            cmd_parse->filetype = CBMDOS_FT_PRG;
            break;
          case 'U':
            cmd_parse->filetype = CBMDOS_FT_USR;
            break;
          case 'L':                     /* L,(#record length)  max 254 */
            if (p[1] == ',') {
                cmd_parse->recordlength = p[2]; /* Changing RL causes error */

                /* Don't allow REL file record lengths less than 2 or
                   greater than 254.  The 1541/71/81 lets you create a
                   REL file of record length 0, but it locks up the CPU
                   on the drive - nice. */
                if (cmd_parse->recordlength < 2 || cmd_parse->recordlength > 254)
                    return CBMDOS_IPE_OVERFLOW;
                /* skip the REL length */
                p+=3;
                cmdlen-=3;
            }
            cmd_parse->filetype = CBMDOS_FT_REL;
            break;
          case 'R':
            cmd_parse->readmode = CBMDOS_FAM_READ;
            break;
          case 'W':
            cmd_parse->readmode = CBMDOS_FAM_WRITE;
            break;
          case 'A':
            cmd_parse->readmode = CBMDOS_FAM_APPEND;
            break;
          default:
            if (cmd_parse->readmode != CBMDOS_FAM_READ
                && cmd_parse->readmode != CBMDOS_FAM_WRITE)
                return CBMDOS_IPE_INVAL;
        }

        c = (char *)memchr(p, ',', cmdlen);
        if (c) {
            cmdlen -= (c - (const char *)p);
            p = (BYTE *)c;
        } else {
            cmdlen = 0;
        }
    }

    /* Override read mode if secondary is 0 or 1.  */
    if (cmd_parse->secondary == 0)
        cmd_parse->readmode = CBMDOS_FAM_READ;
    if (cmd_parse->secondary == 1)
        cmd_parse->readmode = CBMDOS_FAM_WRITE;

    /* Set filetype according secondary address, if it was not specified
        and if we are in write mode */
    if (cmd_parse->filetype == 0 && cmd_parse->readmode == CBMDOS_FAM_WRITE)
        cmd_parse->filetype = (cmd_parse->secondary < 2)
                              ? CBMDOS_FT_PRG : CBMDOS_FT_SEQ;

    return CBMDOS_IPE_OK;
}
コード例 #13
0
ファイル: attach.c プロジェクト: aerdnar/emu-ex-plus-alpha
static int attach_disk_image(disk_image_t **imgptr, vdrive_t *floppy,
                             const char *filename, unsigned int unit,
                             int devicetype)
{
    disk_image_t *image;
    disk_image_t new_image;
    int err = -1;

    if (filename == NULL) {
        log_error(attach_log, "No name, cannot attach floppy image.");
        return -1;
    }

    new_image.gcr = NULL;
    new_image.p64 = lib_calloc(1, sizeof(TP64Image));
    new_image.read_only = (unsigned int)attach_device_readonly_enabled[unit - 8];

    switch (devicetype) {
        case ATTACH_DEVICE_NONE:
        case ATTACH_DEVICE_VIRT:
        case ATTACH_DEVICE_FS:
            new_image.device = DISK_IMAGE_DEVICE_FS;
            break;
        case ATTACH_DEVICE_RAW:
            new_image.device = DISK_IMAGE_DEVICE_RAW;
            break;
    }

    disk_image_media_create(&new_image);

    switch (devicetype) {
        case ATTACH_DEVICE_NONE:
        case ATTACH_DEVICE_VIRT:
        case ATTACH_DEVICE_FS:
            disk_image_fsimage_name_set(&new_image, filename);
            break;
        case ATTACH_DEVICE_RAW:
            disk_image_rawimage_driver_name_set(&new_image);
            break;
    }

    if (disk_image_open(&new_image) < 0) {
        P64ImageDestroy((PP64Image) new_image.p64);
        lib_free(new_image.p64);
        disk_image_media_destroy(&new_image);
        return -1;
    }

    detach_disk_image_and_free(*imgptr, floppy, unit);

    *imgptr = disk_image_create();
    image = *imgptr;

    memcpy(image, &new_image, sizeof(disk_image_t));

    switch (unit) {
        case 8:
        case 9:
        case 10:
        case 11:
            err = drive_image_attach(image, unit);
            err &= vdrive_attach_image(image, unit, floppy);
            err &= machine_drive_image_attach(image, unit);
            break;
    }
    if (err) {
        disk_image_close(image);
        disk_image_media_destroy(image);
        disk_image_destroy(image);
        *imgptr = NULL;
    }
    return err;
}
コード例 #14
0
ファイル: uikeyboard.c プロジェクト: AreaScout/vice
HACCEL uikeyboard_create_accelerator_table(void)
{
    FILE *fshortcuts;
    char *complete_path;
    char buffer[1000];
    char *p, *menustr, *metastr, *keystr, *displaystr;
    int i;

    accelnum = 0;
    menuitemmodifier_len = 0;
    for (i = 0; idmlist[i].str != NULL; i++) {
        if (idmlist[i].cmd >= menuitemmodifier_len) {
            menuitemmodifier_len = idmlist[i].cmd + 1;
        }
    }

    menuitemmodifier = lib_calloc(menuitemmodifier_len, sizeof(char*));
    memset(menuitemmodifier, 0, menuitemmodifier_len * sizeof(char*));

    fshortcuts = sysfile_open("win_shortcuts.vsc", &complete_path, MODE_READ_TEXT);
    lib_free(complete_path);
    if (fshortcuts == NULL) {
        log_error(LOG_DEFAULT, "Warning. Cannot open keyboard shortcut file win_shortcuts.vsc.");
        return NULL;
    }

    /* read the shortcut table */
    do {
        buffer[0] = 0;
        if (fgets(buffer, 999, fshortcuts)) {

            if (strlen(buffer) == 0) {
                break;
            }

            buffer[strlen(buffer) - 1] = 0; /* remove newline */

	      /* remove comments */
	      if ((p = strchr(buffer, '#'))) {
                *p = 0;
            }

            metastr = strtok(buffer, " \t:");
            keystr = strtok(NULL, " \t:");
            menustr = strtok(NULL, " \t:");
            displaystr = strtok(NULL, " \t:");
	      if (displaystr && (p = strchr(displaystr, '#'))) {
	          *p = 0;
            }

            if (metastr && keystr && menustr) {
                for (i = 0; idmlist[i].str; i++) {
                    if (strcmp(idmlist[i].str, menustr) == 0) {
                        break;
                    }
                }

                if (idmlist[i].str) {
                    ACCEL accel;

                    accel.fVirt = FVIRTKEY | FNOINVERT;
                    if (strstr(strlwr(metastr), "shift") != NULL) {
                        accel.fVirt |= FSHIFT;
                    }
                    if (strstr(strlwr(metastr), "ctrl") != NULL) {
                        accel.fVirt |= FCONTROL;
                    }
                    if (strstr(strlwr(metastr), "alt") != NULL) {
                        accel.fVirt |= FALT;
                    }

                    if (keystr[0] == '\'' && keystr[2] == '\'') {
                        accel.key = keystr[1];
                        if (displaystr == NULL || displaystr[0] == 0) {
                            displaystr = keystr + 1;
                            keystr[2] = 0;
                        }
                    } else {
                        accel.key = (unsigned short)strtol(keystr, NULL, 0);
                    }

                    accel.cmd = idmlist[i].cmd;

                    if (accel.key > 0 && accel.cmd > 0 && accelnum < MAXACCEL) {
                        accellist[accelnum++] = accel;
                    }

                    if (displaystr != NULL && menuitemmodifier[accel.cmd] == NULL) {
                        p = util_concat("\t",
                                        ((accel.fVirt & FSHIFT  ) ? "Shift+" : ""),
                                        ((accel.fVirt & FCONTROL) ? "Ctrl+" : ""),
                                        ((accel.fVirt & FALT) ? "Alt+" : ""),
                                        displaystr, NULL);

                        menuitemmodifier[accel.cmd] = p;
                    }
                }
            }
        }
    } while (!feof(fshortcuts));
    fclose(fshortcuts);

    return CreateAcceleratorTable(accellist, accelnum);
}
コード例 #15
0
ファイル: fsimage-gcr.c プロジェクト: AreaScout/vice
int fsimage_gcr_write_half_track(disk_image_t *image, unsigned int half_track,
                                 const disk_track_t *raw)
{
    int gap, extend = 0, res;
    WORD max_track_length;
    BYTE buf[4];
    long offset;
    fsimage_t *fsimage;
    BYTE num_half_tracks;

    fsimage = image->media.fsimage;

    offset = fsimage_gcr_seek_half_track(fsimage, half_track, &max_track_length, &num_half_tracks);
    if (offset < 0) {
        return -1;
    }
    if (image->read_only != 0) {
        log_error(fsimage_gcr_log,
                  "Attempt to write to read-only disk image.");
        return -1;
    }

    if (raw->size > max_track_length) {
        log_error(fsimage_gcr_log,
                  "Track too long for image.");
        return -1;
    }

    if (offset == 0) {
        offset = fseek(fsimage->fd, 0, SEEK_END);
        if (offset == 0) {
            offset = ftell(fsimage->fd);
        }
        if (offset < 0) {
            log_error(fsimage_gcr_log, "Could not extend GCR disk image.");
            return -1;
        }
        extend = 1;
    }

    if (raw->data != NULL) {
        util_word_to_le_buf(buf, (WORD)raw->size);

        if (util_fpwrite(fsimage->fd, buf, 2, offset) < 0) {
            log_error(fsimage_gcr_log, "Could not write GCR disk image.");
            return -1;
        }

        /* Clear gap between the end of the actual track and the start of
           the next track.  */
        if (fwrite(raw->data, raw->size, 1, fsimage->fd) < 1) {
            log_error(fsimage_gcr_log, "Could not write GCR disk image.");
            return -1;
        }
        gap = max_track_length - raw->size;

        if (gap > 0) {
            BYTE *padding = lib_calloc(1, gap);
            res = fwrite(padding, gap, 1, fsimage->fd);
            lib_free(padding);
            if (res < 1) {
                log_error(fsimage_gcr_log, "Could not write GCR disk image.");
                return -1;
            }
        }

        if (extend) {
            util_dword_to_le_buf(buf, offset);
            if (util_fpwrite(fsimage->fd, buf, 4, 12 + (half_track - 2) * 4) < 0) {
                log_error(fsimage_gcr_log, "Could not write GCR disk image.");
                return -1;
            }

            util_dword_to_le_buf(buf, disk_image_speed_map(image->type, half_track / 2));
            if (util_fpwrite(fsimage->fd, buf, 4, 12 + (half_track - 2 + num_half_tracks) * 4) < 0) {
                log_error(fsimage_gcr_log, "Could not write GCR disk image.");
                return -1;
            }
        }
    }

    /* Make sure the stream is visible to other readers.  */
    fflush(fsimage->fd);

    return 0;
}
コード例 #16
0
ファイル: memiec.c プロジェクト: QaDeS/droidsound
static void realloc_expram(BYTE **expram, int size)
{
    lib_free(*expram);
    *expram = lib_calloc(1, size);
}
コード例 #17
0
void __InitMultipleThread( void )
/*******************************/
{
    if( __GetThreadPtr != __MultipleThread ) {
  #if defined( _NETWARE_CLIB )
        {
        /* __ThreadData[ 0 ] is used whenever GetThreadID() returns a pointer
           not in our __ThreadIDs list - ie. whenever it returns NULL, a
           pointer to a thread we didn't create, or an invalid pointer */
            void *ptr;
            ptr = lib_calloc( 1, __ThreadDataSize );
            if( ptr == NULL ) {
                __fatal_runtime_error(
                    "Unable to allocate thread-specific data", 1 );
            }
            __ThreadData[ 0 ].data = ptr;
            __ThreadData[ 0 ].allocated_entry = 1;
            __ThreadData[ 0 ].data->__allocated = 1;
            __ThreadData[ 0 ].data->__randnext = 1;
            __ThreadData[ 0 ].data->__data_size = __ThreadDataSize;
            if( __initthread( ptr ) ) {
                lib_free( ptr );
                __fatal_runtime_error(
                    "Unable to initialize thread-specific data", 1 );
            }
            ptr = lib_calloc( 1, __ThreadDataSize );
            if( ptr == NULL ) {
                __fatal_runtime_error(
                    "Unable to allocate thread-specific data", 1 );
            }
            __FirstThreadData = ptr;
            __FirstThreadData->__allocated = 1;
            __FirstThreadData->__randnext = 1;
            __FirstThreadData->__data_size = __ThreadDataSize;
            __ThreadData[ 1 ].data = __FirstThreadData;
            __ThreadData[ 1 ].allocated_entry = __FirstThreadData->__allocated;
            __ThreadIDs[ 1 ] = GetThreadID();
            if( __initthread( ptr ) ) {
                lib_free( ptr );
                __fatal_runtime_error(
                    "Unable to initialize thread-specific data", 1 );
            }
        }
  #elif defined( _NETWARE_LIBC )
        InitSemaphore.semaphore     = 0;    /* sema4 is mutex in this case */
        InitSemaphore.initialized   = 1;
        //_ThreadExitRtn = &__ThreadExit;   - might need this at some point??
        // Note: __AddThreadData uses the InitSemaphore, _AccessTDList & _ReleaseTDList

        __FirstThreadData->thread_id = GetCurrentThreadId();

        __AddThreadData( __FirstThreadData->thread_id, __FirstThreadData );
        if(0 != NXKeySetValue(__NXSlotID, __FirstThreadData)) {
            __fatal_runtime_error(
                "Unable to initialize thread-specific data", 1 );
        }
  #elif defined( __NT__ )
        InitSemaphore.semaphore = __NTGetCriticalSection();
        InitSemaphore.initialized = 1;
        _ThreadExitRtn = &__ThreadExit;
        // Note: __AddThreadData uses the InitSemaphore, _AccessTDList & _ReleaseTDList
        __AddThreadData( __FirstThreadData->thread_id, __FirstThreadData );
        TlsSetValue( __TlsIndex, __FirstThreadData );
  #elif defined( __QNX__ )
        __qsem_init( &InitSemaphore.semaphore, 1, 1 );
        InitSemaphore.initialized = 1;
        // first thread data already in magic memory
  #elif defined( __LINUX__ )
        // TODO: Init semaphores for Linux
  #elif defined( __RDOS__ )
        InitSemaphore.semaphore = RdosCreateSection();
        InitSemaphore.initialized = 1;
        __AddThreadData( __FirstThreadData->thread_id, __FirstThreadData );
        __tls_set_value( __TlsIndex, __FirstThreadData );
  #elif defined( __RDOSDEV__ )
        RdosInitKernelSection( &InitSemaphore.semaphore );
        InitSemaphore.initialized = 1;
  #elif defined( __OS2__ )
        DosCreateMutexSem( NULL, &InitSemaphore.semaphore, 0, FALSE );
        InitSemaphore.initialized = 1;
        __ThreadData[1].data = __FirstThreadData;
        __ThreadData[1].allocated_entry = __FirstThreadData->__allocated;
  #else
    #error Multiple thread support is not defined for this platform
  #endif

  #if !defined( _M_I86 )
    // Set these up after we have created the InitSemaphore
    #if !defined (_THIN_LIB)
        _AccessFileH      = &__AccessFileH;
        _ReleaseFileH     = &__ReleaseFileH;
        _AccessIOB        = &__AccessIOB;
        _ReleaseIOB       = &__ReleaseIOB;
    #endif
        _AccessTDList     = &__AccessTDList;
        _ReleaseTDList    = &__ReleaseTDList;
        __AccessSema4     = &__AccessSemaphore;
        __ReleaseSema4    = &__ReleaseSemaphore;
        __CloseSema4      = &__CloseSemaphore;
    #if !defined( __NETWARE__ )
        _AccessNHeap  = &__AccessNHeap;
        _AccessFHeap  = &__AccessFHeap;
        _ReleaseNHeap = &__ReleaseNHeap;
        _ReleaseFHeap = &__ReleaseFHeap;
    #endif
    #if defined( __NT__ )
        _AccessFList  = &__AccessFList;
        _ReleaseFList = &__ReleaseFList;
    #endif
  #endif
        __GetThreadPtr  = __MultipleThread;
    }
}
コード例 #18
0
static int disk_image_check_for_d81(disk_image_t *image)
{
    unsigned int blk = 0;
    char *ext;
    size_t len;
    BYTE block[256];
    fsimage_t *fsimage;
    int checkimage_errorinfo;
    unsigned int checkimage_blocks;

    fsimage = image->media.fsimage;

    if (!(IS_D81_LEN(util_file_length(fsimage->fd)))) {
        return 0;
    }

    /* .d1m images share the same sizes with .d81, so we reject based on the
       file extension what is likely a .d1m image */
    ext = util_get_extension(fsimage->name);
    if ((ext[0]) && (ext[1] == '1') && (ext[2])) {
        return 0;
    }

    rewind(fsimage->fd);

    while ((len = fread(block, 1, 256, fsimage->fd)) == 256) {
        if (++blk > (MAX_BLOCKS_1581 + 13)) {
            log_error(disk_image_probe_log, "Disk image too large.");
            break;
        }
    }

    if (disk_image_check_min_block(blk, NUM_BLOCKS_1581) < 0) {
        return 0;
    }

    switch (blk) {
        case NUM_BLOCKS_1581:          /* 80 tracks */
        case NUM_BLOCKS_1581 + 12:     /* 80 tracks, with errors */
            image->tracks = NUM_TRACKS_1581;
            break;
        case NUM_BLOCKS_1581 + 40:     /* 81 tracks */
        case NUM_BLOCKS_1581 + 40 + 12: /* 81 tracks, with errors */
            image->tracks = NUM_TRACKS_1581 + 1;
            break;
        case NUM_BLOCKS_1581 + 80:     /* 82 tracks */
        case NUM_BLOCKS_1581 + 80 + 12: /* 82 tracks, with errors */
            image->tracks = NUM_TRACKS_1581 + 2;
            break;
        case NUM_BLOCKS_1581 + 120:    /* 83 tracks */
        case NUM_BLOCKS_1581 + 120 + 12: /* 83 tracks, with errors */
            image->tracks = NUM_TRACKS_1581 + 3;
            break;
        default:
            return 0;
    }

    image->type = DISK_IMAGE_TYPE_D81;
    image->max_half_tracks = MAX_TRACKS_1581 * 2;

    switch (blk) {
        case NUM_BLOCKS_1581 + 12:     /* 80 tracks, with errors */
        case NUM_BLOCKS_1581 + 40 + 12: /* 81 tracks, with errors */
        case NUM_BLOCKS_1581 + 80 + 12: /* 82 tracks, with errors */
        case NUM_BLOCKS_1581 + 120 + 12: /* 83 tracks, with errors */
            checkimage_errorinfo = 1;
            break;
        default:
            checkimage_errorinfo = 0;
            break;
    }

    if (checkimage_errorinfo) {
        checkimage_blocks = image->tracks * 40;
        fsimage->error_info.map = lib_calloc(1, checkimage_blocks);
        fsimage->error_info.len = checkimage_blocks;
        if (util_fpread(fsimage->fd, fsimage->error_info.map, checkimage_blocks, 256 * checkimage_blocks) < 0) {
            return 0;
        }
    }
    disk_image_check_log(image, "D81");
    return 1;
}
コード例 #19
0
ファイル: interrupt.c プロジェクト: BigBoss21X/vice-emu
interrupt_cpu_status_t *interrupt_cpu_status_new(void)
{
    return (interrupt_cpu_status_t *)lib_calloc(1, sizeof(interrupt_cpu_status_t));
}
コード例 #20
0
ファイル: drive.c プロジェクト: Yifei0727/emu-ex-plus-alpha
/* Initialize the hardware-level drive emulation (should be called at least
   once before anything else).  Return 0 on success, -1 on error.  */
int drive_init(void)
{
    unsigned int dnr;
    drive_t *drive;

    if (rom_loaded) {
        return 0;
    }

    drive_init_was_called = 1;

    driverom_init();
    drive_image_init();

    drive_log = log_open("Drive");

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        char *logname;

        drive = drive_context[dnr]->drive;
        logname = lib_msprintf("Drive %i", dnr + 8);
        drive->log = log_open(logname);
        lib_free(logname);

        drive_clk[dnr] = 0L;
        drive->clk = &drive_clk[dnr];
        drive->mynumber = dnr;
    }

    if (driverom_load_images() < 0) {
        resources_set_int("Drive8Type", DRIVE_TYPE_NONE);
        resources_set_int("Drive9Type", DRIVE_TYPE_NONE);
        resources_set_int("Drive10Type", DRIVE_TYPE_NONE);
        resources_set_int("Drive11Type", DRIVE_TYPE_NONE);
        return -1;
    }

    log_message(drive_log, "Finished loading ROM images.");
    rom_loaded = 1;

    drive_overflow_init();

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        drive = drive_context[dnr]->drive;

        machine_drive_port_default(drive_context[dnr]);

        if (drive_check_type(drive->type, dnr) < 1) {
            resources_set_int_sprintf("Drive%iType", DRIVE_TYPE_NONE, dnr + 8);
        }

        machine_drive_rom_setup_image(dnr);
    }

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        drive = drive_context[dnr]->drive;
        drive->gcr = gcr_create_image();
        drive->p64 = lib_calloc(1, sizeof(TP64Image));
        P64ImageCreate(drive->p64);
        drive->byte_ready_level = 1;
        drive->byte_ready_edge = 1;
        drive->GCR_dirty_track = 0;
        drive->GCR_write_value = 0x55;
        drive->GCR_track_start_ptr = NULL;
        drive->GCR_current_track_size = 0;
        drive->attach_clk = (CLOCK)0;
        drive->detach_clk = (CLOCK)0;
        drive->attach_detach_clk = (CLOCK)0;
        drive->old_led_status = 0;
        drive->old_half_track = 0;
        drive->side = 0;
        drive->GCR_image_loaded = 0;
        drive->P64_image_loaded = 0;
        drive->P64_dirty = 0;
        drive->read_only = 0;
        drive->clock_frequency = 1;
        drive->led_last_change_clk = *(drive->clk);
        drive->led_last_uiupdate_clk = *(drive->clk);
        drive->led_active_ticks = 0;

        rotation_reset(drive);

        /* Position the R/W head on the directory track.  */
        drive_set_half_track(36, 0, drive);
        drive_set_active_led_color(drive->type, dnr);
    }

    for (dnr = 0; dnr < DRIVE_NUM; dnr++) {
        drive = drive_context[dnr]->drive;
        driverom_initialize_traps(drive);

        drivesync_clock_frequency(drive->type, drive);

        rotation_init((drive->clock_frequency == 2) ? 1 : 0, dnr);

        if (drive->type == DRIVE_TYPE_2000 || drive->type == DRIVE_TYPE_4000) {
            drivecpu65c02_init(drive_context[dnr], drive->type);
        } else {
            drivecpu_init(drive_context[dnr], drive->type);
        }

        /* Make sure the sync factor is acknowledged correctly.  */
        drivesync_factor(drive_context[dnr]);

        /* Make sure the traps are moved as needed.  */
        if (drive->enable) {
            drive_enable(drive_context[dnr]);
        }
    }

    return 0;
}
コード例 #21
0
ファイル: event.c プロジェクト: martinpiper/VICE
void event_init_image_list(void)
{
    event_image_list_base = 
        (event_image_list_t *)lib_calloc(1, sizeof(event_image_list_t));
    image_number = 0;
}
コード例 #22
0
ファイル: fsimage-dxx.c プロジェクト: AreaScout/vice
int fsimage_dxx_write_half_track(disk_image_t *image, unsigned int half_track,
                                 const disk_track_t *raw)
{
    unsigned int track, sector, max_sector = 0, error_info_created = 0;
    int sectors, res;
    long offset;
    BYTE *buffer;
    fsimage_t *fsimage = image->media.fsimage;
    fdc_err_t rf;

    track = half_track / 2;

    max_sector = disk_image_sector_per_track(image->type, track);
    sectors = disk_image_check_sector(image, track, 0);
    if (sectors < 0) {
        log_error(fsimage_dxx_log, "Track: %i out of bounds.", track);
        return -1;
    }

    if (track > image->tracks) {
        if (fsimage->error_info.map) {
            int newlen = sectors + max_sector;
            fsimage->error_info.map = lib_realloc(fsimage->error_info.map, newlen);
            memset(fsimage->error_info.map + fsimage->error_info.len, 0,
                   newlen - fsimage->error_info.len);
            fsimage->error_info.len = newlen;
            fsimage->error_info.dirty = 1;
        }
        image->tracks = track;
    }

    buffer = lib_calloc(max_sector, 256);
    for (sector = 0; sector < max_sector; sector++) {
        rf = gcr_read_sector(raw, &buffer[sector * 256], (BYTE)sector);
        if (rf != CBMDOS_FDC_ERR_OK) {
            log_error(fsimage_dxx_log,
                      "Could not find data sector of T:%d S:%d.",
                      track, sector);
            if (fsimage->error_info.map == NULL) { /* create map if does not exists */
                int newlen = disk_image_check_sector(image, image->tracks, 0);
                if (newlen >= 0) {
                    newlen += disk_image_sector_per_track(image->type, image->tracks);
                    fsimage->error_info.map = lib_malloc(newlen);
                    memset(fsimage->error_info.map, (BYTE)CBMDOS_FDC_ERR_OK, newlen);
                    fsimage->error_info.len = newlen;
                    fsimage->error_info.dirty = 1;
                    error_info_created = 1;
                }
            }
        }
        if (fsimage->error_info.map != NULL) {
            if (fsimage->error_info.map[sectors + sector] != (BYTE)rf) {
                fsimage->error_info.map[sectors + sector] = (BYTE)rf;
                fsimage->error_info.dirty = 1;
            }
        }
    }
    offset = sectors * 256;

    if (image->type == DISK_IMAGE_TYPE_X64) {
        offset += X64_HEADER_LENGTH;
    }

    if (util_fpwrite(fsimage->fd, buffer, max_sector * 256, offset) < 0) {
        log_error(fsimage_dxx_log, "Error writing T:%i to disk image.",
                  track);
        lib_free(buffer);
        return -1;
    }
    lib_free(buffer);
    if (fsimage->error_info.map) {
        if (fsimage->error_info.dirty) {
            offset = fsimage->error_info.len * 256 + sectors;

            if (image->type == DISK_IMAGE_TYPE_X64) {
                offset += X64_HEADER_LENGTH;
            }

            fsimage->error_info.dirty = 0;
            if (error_info_created) {
                res = util_fpwrite(fsimage->fd, fsimage->error_info.map,
                                   fsimage->error_info.len, fsimage->error_info.len * 256);
            } else {
                res = util_fpwrite(fsimage->fd, fsimage->error_info.map + sectors,
                                   max_sector, offset);
            }
            if (res < 0) {
                log_error(fsimage_dxx_log, "Error writing T:%i error info to disk image.",
                          track);
                return -1;
            }
        }
    }

    /* Make sure the stream is visible to other readers.  */
    fflush(fsimage->fd);
    return 0;
}
コード例 #23
0
ファイル: fsimage.c プロジェクト: twinaphex/vice-next
void fsimage_error_info_create(fsimage_t *fsimage)
{
    fsimage->error_info = lib_calloc(1, MAX_BLOCKS_ANY);
}
コード例 #24
0
ファイル: trdlist.c プロジェクト: ABratovic/open-watcom-v2
// realloc thread data
thread_data *__ReallocThreadData( void )
{
    TID tid;
    thread_data *tdata;

    _AccessTDList();
    tid = GetCurrentThreadId();
    #ifdef __OS2__
        if( tid <= __MaxThreads ) {
            thread_data_vector *tdv;
            tdv = &(__ThreadData[tid]);
            if( tdv->allocated_entry ) 
            {
                #if defined (_NETWARE_LIBC)
                /*
                //  we don't want to lose __FirstThreadData as our global
                //  destructors will try and access it as they are called
                //  from a different thread.
                */
                if(__IsFirstThreadData(tdv->data))
                {
                    tdata = lib_realloc( tdv->data, __ThreadDataSize );
                    __RegisterFirstThreadData(tdata);
                }
                else
                #endif
                    tdata = lib_realloc( tdv->data, __ThreadDataSize );
                if( tdata == NULL ) {
                    __fatal_runtime_error( "Unable to resize thread-specific data", 1 );
                }
                tdv->data = tdata;
            } 
            else 
            {
                tdata = lib_calloc( 1, __ThreadDataSize );
                if( tdata == NULL ) {
                    __fatal_runtime_error( "Unable to resize thread-specific data", 1 );
                }
                memcpy( tdata, tdv->data, tdv->data->__data_size );
                tdv->allocated_entry = 1;
                tdv->data = tdata;
            }
        } else
    #endif
    {
        thread_data_list *tdl;

        for( tdl = __thread_data_list ; tdl != NULL ; tdl = tdl->next ) {
            if( tdl->tid == tid ) {
                break;
            }
        }
        if( tdl == NULL ) {
            __fatal_runtime_error( "Thread has no thread-specific data", 1 );
        }
        if( tdl->allocated_entry ) 
        {
            #if defined(_NETWARE_LIBC)
            if(tdata = lib_malloc( __ThreadDataSize ))
            {
                memcpy(tdata, tdl->data, min(__ThreadDataSize, tdl->data->__data_size));
                lib_free(tdl->data);
            }
            #else
            tdata = lib_realloc( tdl->data, __ThreadDataSize );
            #endif
            if( tdata == NULL ) 
            {
                __fatal_runtime_error( "Unable to resize thread-specific data", 1 );
            }
            tdl->data = tdata;
        } 
        else 
        {
            tdata = lib_calloc( 1, __ThreadDataSize );
            if( tdata == NULL ) 
            {
                __fatal_runtime_error( "Unable to resize thread-specific data", 1 );
            }
            memcpy( tdata, tdl->data, tdl->data->__data_size );
            tdl->allocated_entry = 1;
            tdl->data = tdata;
        }
    }
    tdata->__allocated = 1;
    tdata->__data_size = __ThreadDataSize;
    tdata->__resize = 0;
    #if defined(__NT__)
        TlsSetValue( __TlsIndex, tdata );
    #endif
    #if defined(_NETWARE_LIBC)
        if(0 != NXKeySetValue(__NXSlotID, tdata))
        {
            lib_free(tdata);
            tdata = NULL;
        }
    #endif
    _ReleaseTDList();
    return( tdata );
}
コード例 #25
0
static int drive_snapshot_read_gcrimage_module(snapshot_t *s, unsigned int dnr)
{
    BYTE major_version, minor_version;
    snapshot_module_t *m;
    char snap_module_name[10];
    BYTE *data;
    unsigned int i;
    drive_t *drive;
    DWORD num_half_tracks, track_size;

    drive = drive_context[dnr]->drive;
    sprintf(snap_module_name, "GCRIMAGE%i", dnr);

    m = snapshot_module_open(s, snap_module_name,
                             &major_version, &minor_version);
    if (m == NULL) {
        return 0;
    }

    if (major_version != GCRIMAGE_SNAP_MAJOR
        || minor_version != GCRIMAGE_SNAP_MINOR) {
        log_error(drive_snapshot_log,
                  "Snapshot module version (%d.%d) not supported.",
                  major_version, minor_version);
        snapshot_module_close(m);
        return -1;
    }


    if (0
        || SMR_DW(m, &num_half_tracks) < 0
        || num_half_tracks > MAX_GCR_TRACKS) {
        snapshot_module_close(m);
        return -1;
    }

    for (i = 0; i < num_half_tracks; i++) {
        if (SMR_DW(m, &track_size) < 0
            || track_size > NUM_MAX_MEM_BYTES_TRACK) {
            snapshot_module_close(m);
            return -1;
        }

        if (track_size) {
            if (drive->gcr->tracks[i].data == NULL) {
                drive->gcr->tracks[i].data = lib_calloc(1, track_size);
            } else if (drive->gcr->tracks[i].size != (int)track_size) {
                drive->gcr->tracks[i].data = lib_realloc(drive->gcr->tracks[i].data, track_size);
            }
            memset(drive->gcr->tracks[i].data, 0, track_size);
        } else {
            if (drive->gcr->tracks[i].data) {
                lib_free(drive->gcr->tracks[i].data);
                drive->gcr->tracks[i].data = NULL;
            }
        }
        data = drive->gcr->tracks[i].data;
        drive->gcr->tracks[i].size = track_size;

        if (track_size && SMR_BA(m, data, track_size) < 0) {
            snapshot_module_close(m);
            return -1;
        }
    }
    for (; i < MAX_GCR_TRACKS; i++) {
        if (drive->gcr->tracks[i].data) {
            lib_free(drive->gcr->tracks[i].data);
            drive->gcr->tracks[i].data = NULL;
            drive->gcr->tracks[i].size = 0;
        }
    }
    snapshot_module_close(m);

    drive->GCR_image_loaded = 1;
    drive->complicated_image_loaded = 1; /* TODO: verify if it's really like this */
    drive->image = NULL;

    return 0;
}
コード例 #26
0
ファイル: vdrive-rel.c プロジェクト: twinaphex/vice-next
static int vdrive_rel_open_new(vdrive_t *vdrive, unsigned int secondary,
                               cbmdos_cmd_parse_t *cmd_parse, const BYTE *name)
{
    bufferinfo_t *p = &(vdrive->buffers[secondary]);
    BYTE *slot;

    /* Allocate a directory slot */
    vdrive_dir_find_first_slot(vdrive, NULL, -1, 0);
    slot = vdrive_dir_find_next_slot(vdrive);

    /* If we can't get one the directory is full - disk full */
    if (!slot) {
        vdrive_command_set_error(vdrive, CBMDOS_IPE_DISK_FULL, 0, 0);
        return 1;
    }

    /* Create our own slot */
    p->slot = lib_calloc(1, 32);

    /* Populate it */
    memset(p->slot + SLOT_NAME_OFFSET, 0xa0, 16);
    memcpy(p->slot + SLOT_NAME_OFFSET, cmd_parse->parsecmd, cmd_parse->parselength);
#ifdef DEBUG_DRIVE
    log_debug("DIR: Created dir slot. Name (%d) '%s'\n",
              cmd_parse->parsecmd, cmd_parse->parselength);
#endif
    p->slot[SLOT_TYPE_OFFSET] = cmd_parse->filetype | 0x80;       /* closed */

    p->slot[SLOT_RECORD_LENGTH] = cmd_parse->recordlength;

    /* Store in buffer */
    memcpy(&(vdrive->Dir_buffer[vdrive->SlotNumber * 32 + 2]),
           p->slot + 2, 30);

#ifdef DEBUG_DRIVE
    log_debug("DEBUG: write DIR slot (%d %d).",
              vdrive->Curr_track, vdrive->Curr_sector);
#endif
    /* Write the sector */
    disk_image_write_sector(vdrive->image, vdrive->Dir_buffer,
                            vdrive->Curr_track, vdrive->Curr_sector);

    /* Allocate memory for super side sector */
    p->super_side_sector = lib_malloc(256);

    /* clear out block */
    memset(p->super_side_sector, 0, 256);
    /* build valid super side sector block */
    p->super_side_sector[OFFSET_SUPER_254] = 254;
    p->super_side_sector_track = 0;
    p->super_side_sector_sector = 0;
    /* Clear dirty flag */
    p->super_side_sector_needsupdate = 0;

     /* allocate memory for side sectors */
    p->side_sector = lib_malloc(SIDE_SECTORS_MAX * 256);
    memset(p->side_sector, 0, SIDE_SECTORS_MAX * 256);

    /* Also clear out track and sectors locations and dirty flag of
        each side sector */
    p->side_sector_track = lib_malloc(SIDE_SECTORS_MAX);
    p->side_sector_sector = lib_malloc(SIDE_SECTORS_MAX);
    p->side_sector_needsupdate = lib_malloc(SIDE_SECTORS_MAX);
    memset(p->side_sector_track, 0, SIDE_SECTORS_MAX);
    memset(p->side_sector_sector, 0, SIDE_SECTORS_MAX);
    memset(p->side_sector_needsupdate, 0, SIDE_SECTORS_MAX);

    /* Remember the directory information incase our REL file grows. */
    p->dir_track = vdrive->Curr_track;
    p->dir_sector = vdrive->Curr_sector;
    p->dir_slot = vdrive->SlotNumber;

    /* Everything okay */
    return 0;
}
コード例 #27
0
ファイル: sounddart.c プロジェクト: BigBoss21X/vice-emu
static int dart_init(const char *param, int *speed,
                     int *fragsize, int *fragnr, int *channels)
{

/* The application sends the MCI_MIX_SETUP message to the amp mixer to
 initialize the device for direct reading and writing of audio data in
 the correct mode and format-for example, PCM, MIDI, or MPEG audio.

 If waveform audio data will be played or recorded, the application
 fills in the ulDeviceType field with MCI_DEVICETYPE_WAVEFORM_AUDIO. It
 must also provide values for the following digital-audio-specific
 fields:  format tag, bits per sample, number of samples per second, and
 number of channels.*/

 // MCI_MIXSETUP informs the mixer device of the entry point
 // to report buffers being read or written.
 // We will also need to tell the mixer which media type
 // we will be streaming.  In this case, we'll use
 // MCI_DEVTYPE_WAVEFORM_AUDIO.

    ULONG i, rc;

    if (DosRequestMutexSem(hmtxOC, SEM_IMMEDIATE_RETURN))
        return TRUE;

    // ---------
    if (!DartOpen())
    {
        DosReleaseMutexSem(hmtxOC);
        return 1;
    }
    // ---------

    memset(&MixSetupParms, 0, sizeof(MCI_MIXSETUP_PARMS));

    MixSetupParms.ulBitsPerSample = 16;
    MixSetupParms.ulFormatTag     = MCI_WAVE_FORMAT_PCM;
    MixSetupParms.ulSamplesPerSec = *speed; 
    MixSetupParms.ulChannels      = *channels; /* Stereo/Mono */
    MixSetupParms.ulFormatMode    = MCI_PLAY;
    MixSetupParms.ulDeviceType    = MCI_DEVTYPE_WAVEFORM_AUDIO;

    // MCI_MIXSETUP_QUERYMODE
    // Queries a device to see if a specific mode is supported
    /*    rc = mciSendCommand( usDeviceID, MCI_MIXSETUP,
     MCI_WAIT | MCI_MIXSETUP_QUERYMODE,
     (PVOID) &MixSetupParms, 0);

     if (rc != MCIERR_SUCCESS) return sound_err(dlog, (rc, "Can't play.");*/

    // The mixer will inform us of entry points to
    // read/write buffers to and also give us a
    // handle to use with these entry points.

    MixSetupParms.pmixEvent = DARTEvent;

    // MCI_MIXSETUP_INIT (DEINIT)
    // Initializes the mixer for the correct mode (MCI_MIXSETUP_PARMS)
    rc = mciSendCommand(usDeviceID, MCI_MIXSETUP,
                        MCI_WAIT|MCI_MIXSETUP_INIT,
                        (PVOID) &MixSetupParms, 0);

    if (rc != MCIERR_SUCCESS)
    {
        sound_err(dlog, rc, "Initialising mixer device (MCI_MIXSETUP_INIT).");
        DartClose();
        DosReleaseMutexSem(hmtxOC);
        return 1;
    }

    //log_message(LOG_DEFAULT, "sounddart.c: %3i buffers � %6i bytes (suggested by dart)", MixSetupParms.ulNumBuffers, MixSetupParms.ulBufferSize);
    //log_message(LOG_DEFAULT, "sounddart.c: %3i buffers � %6i bytes (wanted by vice)", *fragnr, *fragsize*sizeof(SWORD));

    /*  After the mixer device is set up to use DART, the application
     instructs the device to allocate memory by sending the MCI_BUFFER
     message with the MCI_ALLOCATE_MEMORY flag set. The application uses the
     MCI_BUFFER_PARMS structure to specify the number of buffers it wants
     and the size to be used for each buffer.

     Note: Because of device driver restrictions, buffers are limited to
     64KB on Intel-based systems. No such limit exists on PowerPC systems.

     The pBufList field contains a pointer to an array of MCI_MIX_BUFFER
     structures where the allocated information is to be returned.*/

    buffers = lib_calloc(*fragnr, sizeof(MCI_MIX_BUFFER));

    BufferParms.pBufList     = buffers;
    BufferParms.ulNumBuffers = *fragnr;
    BufferParms.ulBufferSize = *fragsize*sizeof(SWORD);

    rc = mciSendCommand(usDeviceID, MCI_BUFFER, MCI_WAIT|MCI_ALLOCATE_MEMORY,
                        (PVOID) &BufferParms, 0);

    if (rc != MCIERR_SUCCESS)
    {
        sound_err(dlog, rc, "Allocating Memory (MCI_ALLOCATE_MEMORY).");
        DartClose();
        DosReleaseMutexSem(hmtxOC);
        return 1;
    }

    // MCI driver will return the number of buffers it
    // was able to allocate
    // it will also return the size of the information
    // allocated with each buffer.

    if (*fragnr  !=BufferParms.ulNumBuffers)
    {
        *fragnr   = BufferParms.ulNumBuffers;
        log_message(dlog, "got %3i buffers � %6i bytes.", BufferParms.ulNumBuffers, BufferParms.ulBufferSize);
    }
    if (*fragsize!=BufferParms.ulBufferSize/sizeof(SWORD))
    {
        *fragsize = BufferParms.ulBufferSize/sizeof(SWORD);
        log_message(dlog, "got %3i buffers � %6i bytes.", BufferParms.ulNumBuffers, BufferParms.ulBufferSize);
    }

    // SECURITY for *fragnr <2 ????
    for (i=0; i<*fragnr; i++)
        memset(buffers[i].pBuffer, 0, BufferParms.ulBufferSize);
    // *fragsize*sizeof(SWORD));

    mmtime  = (float)*speed/1000;
    written = 0;
    rest    = BufferParms.ulBufferSize;

    // Must write at least two buffers to start mixer
    play = 2;  // this is the buffer which is played next
    last = 1;  // this is the buffer which is played last before next
    pos  = 0;  // this is the position to which buffer we have to write
    MixSetupParms.pmixWrite(MixSetupParms.ulMixHandle,
                            &(buffers[0]), 2);

    DosReleaseMutexSem(hmtxOC);

    mute(MUTE_OFF);

    return 0;
}
コード例 #28
0
static int disk_image_check_for_d64(disk_image_t *image)
{
    /*** detect 35..42 track d64 image, determine image parameters.
         Walk from 35 to 42, calculate expected image file size for each track,
         and compare this with the size of the given image. */

    int checkimage_tracks, checkimage_errorinfo;
    size_t countbytes, checkimage_blocks, checkimage_realsize;
    fsimage_t *fsimage;

    fsimage = image->media.fsimage;

    checkimage_errorinfo = 0;
    checkimage_realsize = util_file_length(fsimage->fd);
    checkimage_tracks = NUM_TRACKS_1541; /* start at track 35 */
    checkimage_blocks = D64_FILE_SIZE_35 / 256;

    while (1) {
        /* check if image matches "checkimage_tracks" */
        if (checkimage_realsize == checkimage_blocks * 256) {
            /* image file matches size-with-no-error-info */
            checkimage_errorinfo = 0;
            break;
        } else if (checkimage_realsize == checkimage_blocks * 256 + checkimage_blocks) {
            /* image file matches size-with-error-info */
            checkimage_errorinfo = 1;
            break;
        }

        /* try next track (all tracks from 35 to 42 have 17 blocks) */
        checkimage_tracks++;
        checkimage_blocks += 17;

        /* we tried them all up to 42, none worked, image must be corrupt */
        if (checkimage_tracks > MAX_TRACKS_1541) {
            return 0;
        }
    }

    /*** test image file: read it (fgetc is pretty fast).
         further size checks are no longer necessary (done during detection) */
    rewind(fsimage->fd);
    for (countbytes = 0; countbytes < checkimage_realsize; countbytes++) {
        if (fgetc(fsimage->fd) == EOF) {
            log_error(disk_image_probe_log, "Cannot read D64 image.");
            return 0;
        }
    }

    /*** set parameters in image structure, read error info */
    image->type = DISK_IMAGE_TYPE_D64;
    image->tracks = checkimage_tracks;
    image->max_half_tracks = MAX_TRACKS_1541 * 2;

    if (checkimage_errorinfo) {
        fsimage->error_info.map = lib_calloc(1, checkimage_blocks);
        fsimage->error_info.len = checkimage_blocks;
        if (util_fpread(fsimage->fd, fsimage->error_info.map, checkimage_blocks, 256 * checkimage_blocks) < 0) {
            return 0;
        }
    }

    /*** log and return successfully */
    disk_image_check_log(image, "D64");
    return 1;
}
コード例 #29
0
ファイル: vdrive-rel.c プロジェクト: twinaphex/vice-next
static int vdrive_rel_open_existing(vdrive_t *vdrive, unsigned int secondary)
{
	unsigned int track, sector, side, i, j, o;
	bufferinfo_t *p = &(vdrive->buffers[secondary]);
	BYTE *slot;

	slot = p->slot;

	/* Create our own slot, since the one passed is static */
	p->slot = lib_calloc(1, 32);

	/* Copy the static on to the new one. */
	memcpy(p->slot, slot, 32);

	/* read super side sector, if it exists */

	track = p->slot[SLOT_SIDE_TRACK];
	sector = p->slot[SLOT_SIDE_SECTOR];

	/* Allocate memory for super side sector */
	p->super_side_sector = lib_malloc(256);

	if (disk_image_read_sector(vdrive->image, p->super_side_sector, track, sector) != 0)
	{
#ifdef CELL_DEBUG
		printf("ERROR: Cannot read side sector.\n");
#endif
		lib_free((char *)p->super_side_sector);
		return -1;
	}

	/* check to see if this is a super side sector.  If not, create an
	   imaginary one so we don't have to change all our code. */
	if (p->super_side_sector[OFFSET_SUPER_254] != 254) {
		/* clear out block */
		memset(p->super_side_sector, 0, 256);
		/* build valid super side sector block */
		p->super_side_sector[OFFSET_NEXT_TRACK] = track;
		p->super_side_sector[OFFSET_NEXT_SECTOR] = sector;
		p->super_side_sector[OFFSET_SUPER_254] = 254;
		p->super_side_sector[OFFSET_SUPER_POINTER] = track;
		p->super_side_sector[OFFSET_SUPER_POINTER+1] = sector;
		/* set track and sector to 0, i.e. no update */
		p->super_side_sector_track = 0;
		p->super_side_sector_sector = 0;
	}
	else {
		/* set track and sector */
		p->super_side_sector_track = track;
		p->super_side_sector_sector = sector;
	}
	/* Clear dirty flag */
	p->super_side_sector_needsupdate = 0;

	/* find the number of side sector groups */
	for (side = 0; p->super_side_sector[OFFSET_SUPER_POINTER + side * 2] != 0 ; side++ );

	/* allocate memory for side sectors */
	p->side_sector = lib_malloc(side * SIDE_SECTORS_MAX * 256);
	memset(p->side_sector, 0, side * SIDE_SECTORS_MAX * 256);

	/* Also clear out track and sectors locations and dirty flag of
	   each side sector */
	p->side_sector_track = lib_malloc(side * SIDE_SECTORS_MAX);
	p->side_sector_sector = lib_malloc(side * SIDE_SECTORS_MAX);
	p->side_sector_needsupdate = lib_malloc(side * SIDE_SECTORS_MAX);
	memset(p->side_sector_track, 0, side * SIDE_SECTORS_MAX);
	memset(p->side_sector_sector, 0, side * SIDE_SECTORS_MAX);
	memset(p->side_sector_needsupdate, 0, side * SIDE_SECTORS_MAX);

	for (j = 0; j < side ; j++ )
	{
		track = p->super_side_sector[OFFSET_SUPER_POINTER + j * 2];
		sector = p->super_side_sector[OFFSET_SUPER_POINTER + j * 2 + 1];

		for (i = 0; i < SIDE_SECTORS_MAX; i++)
		{
			o = i + j * SIDE_SECTORS_MAX;
			/* Save the track and sector of each side sector so we can also write
			   and update REL files. */
			p->side_sector_track[o] = track;
			p->side_sector_sector[o] = sector;

			o*=256;

			if (disk_image_read_sector(vdrive->image, &(p->side_sector[o]), track, sector) != 0)
			{
				#ifdef CELL_DEBUG
				printf("ERROR: Cannot read side sector.\n");
				#endif
				return -1;
			}
			if (p->side_sector[o + OFFSET_SECTOR_NUM] != i)
			{
				#ifdef CELL_DEBUG
				printf("ERROR: Side sector number do not match.\n");
				#endif
				return -1;
			}

			track = p->side_sector[o + OFFSET_NEXT_TRACK];
			sector = p->side_sector[o + OFFSET_NEXT_SECTOR];

			if (track == 0)
				break;
		}
	}

	/* Remember the directory information incase our REL file grows. */
	p->dir_track = vdrive->Curr_track;
	p->dir_sector = vdrive->Curr_sector;
	p->dir_slot = vdrive->SlotNumber;

	return 0;
}