예제 #1
0
/* Autostart tape image `file_name'.  */
int autostart_tape(const char *file_name, const char *program_name,
                   unsigned int program_number, unsigned int runmode)
{
    char *name = NULL;

    if (event_record_active() || event_playback_active() || !file_name || !autostart_enabled)
        return -1;

    /* Get program name first to avoid more than one file handle open on
       image.  */
    if (!program_name && program_number > 0)
        name = image_contents_filename_by_number(tapecontents_read(file_name), program_number);
    else
        name = lib_stralloc(program_name ? program_name : "");

    if (!(tape_image_attach(1, file_name) < 0)) {
        //log_message(autostart_log, "Attached file `%s' as a tape image.", file_name);
        if (tape_tap_attched()) {
            if (program_number > 0) {
                lib_free(name);
                name = NULL;
                /* program numbers in tape_seek_to_file() start at 0 */
                tape_seek_to_file(tape_image_dev1, program_number-1);
            } else {
                tape_seek_start(tape_image_dev1);
            }
        }
        resources_set_int("VirtualDevices", 1); /* Kludge: iAN CooG - for t64 images we need devtraps ON */
        reboot_for_autostart(name, AUTOSTART_HASTAPE, runmode);
        lib_free(name);

        return 0;
    }

    autostartmode = AUTOSTART_ERROR;
    deallocate_program_name();

    lib_free(name);

    return -1;
}
예제 #2
0
int sdl_ui_image_file_selection_dialog(const char* filename, ui_menu_filereq_mode_t mode)
{
    int total, dirs = 0, files, menu_max;
    int active = 1;
    int offset = 0;
    int redraw = 1;
    int cur = 0, cur_old = -1;

    image_contents_t *contents = NULL;
    image_contents_file_list_t *entry;
    int retval = -1;

    menu_draw = sdl_ui_get_menu_param();

    /* FIXME: it might be a good idea to wrap this into a common imagecontents_read */
    contents = tapecontents_read(filename);
    if (contents == NULL) {
        contents = diskcontents_read(filename, 0);
        if (contents == NULL) {
            return 0;
        }
    }

    /* count files in the list */
    files = 0;
    for (entry = contents->file_list; entry != NULL; entry = entry->next) {
        files++;
    }

    total = dirs + files + SDL_FILEREQ_META_NUM;
    menu_max = menu_draw->max_text_y - (IMAGE_FIRST_Y + SDL_FILEREQ_META_NUM);
    if (menu_max > 0) { menu_max--; } /* make room for BLOCKS FREE */

    while (active) {

        sdl_ui_set_active_font(MENU_FONT_IMAGES);

        if (redraw) {
            sdl_ui_image_file_selector_redraw(contents, filename, offset, 
                (total - offset > menu_max) ? menu_max : total - offset, 
                (total - offset > menu_max) ? 1 : 0, mode, cur);
            redraw = 0;
        } else {
            sdl_ui_image_file_selector_redraw_cursor(contents, offset, 
                    (total - offset > menu_max) ? menu_max : total - offset, 
                    mode, cur, cur_old);
        }

        sdl_ui_set_active_font(MENU_FONT_ASCII);

        sdl_ui_refresh();

        switch (sdl_ui_menu_poll_input()) {
            case MENU_ACTION_HOME:
                cur_old = cur;
                cur = 0;
                offset = 0;
                redraw = 1;
                break;

            case MENU_ACTION_END:
                cur_old = cur;
                if (total < (menu_max - 1)) {
                    cur = total - 1;
                    offset = 0;
                } else {
                    cur = menu_max - 1;
                    offset = total - menu_max;
                }
                redraw = 1;
                break;

            case MENU_ACTION_UP:
                if (cur > 0) {
                    cur_old = cur;
                    --cur;
                } else {
                    if (offset > 0) {
                        offset--;
                        redraw = 1;
                    }
                }
                break;

            case MENU_ACTION_PAGEUP:
            case MENU_ACTION_LEFT:
                offset -= menu_max;
                if (offset < 0) {
                    offset = 0;
                    cur_old = -1;
                    cur = 0;
                }
                redraw = 1;
                break;

            case MENU_ACTION_DOWN:
                if (cur < (menu_max - 1)) {
                    if ((cur + offset) < total - 1) {
                        cur_old = cur;
                        ++cur;
                    }
                } else {
                    if (offset < (total - menu_max)) {
                        offset++;
                        redraw = 1;
                    }
                }
                break;

            case MENU_ACTION_PAGEDOWN:
            case MENU_ACTION_RIGHT:
                offset += menu_max;
                if (offset >= total) {
                    offset = total - 1;
                    cur_old = -1;
                    cur = 0;
                } else if ((cur + offset) >= total) {
                    cur_old = -1;
                    cur = total - offset - 1;
                }
                redraw = 1;
                break;

            case MENU_ACTION_SELECT:
                active = 0;
                retval = offset + cur - dirs - SDL_FILEREQ_META_NUM + 1;
                break;

            case MENU_ACTION_CANCEL:
            case MENU_ACTION_EXIT:
                active = 0;
                break;

            default:
                SDL_Delay(10);
                break;
        }
    }

    return retval;
}