Example #1
0
unsigned int interrupt_cpu_status_int_new(interrupt_cpu_status_t *cs,
                                          const char *name)
{
    cs->num_ints += 1;

    cs->pending_int = lib_realloc(cs->pending_int, cs->num_ints * sizeof(*(cs->pending_int)));
    cs->pending_int[cs->num_ints - 1] = 0;

    cs->int_name = lib_realloc(cs->int_name, cs->num_ints * sizeof(char *));
    cs->int_name[cs->num_ints - 1] = lib_stralloc(name);

    return cs->num_ints - 1;
}
Example #2
0
static void ffmpeg_get_formats_and_codecs(void)
{
    int i, j, ai, vi = 0, f;
    gfxoutputdrv_codec_t *audio_codec_list;
    gfxoutputdrv_codec_t *video_codec_list;
    gfxoutputdrv_codec_t *ac, *vc;

    f = 0;
    ffmpegdrv_formatlist = lib_malloc(sizeof(gfxoutputdrv_format_t));

    for (i = 0; formats_to_test[i].name != NULL; i++) {
        if (VICE_P_AV_GUESS_FORMAT(formats_to_test[i].name, NULL, NULL)) {
            audio_codec_list = NULL;
            video_codec_list = NULL;
            if (formats_to_test[i].audio_codecs != NULL) {
                ai = 0;
                audio_codec_list = lib_malloc(sizeof(gfxoutputdrv_codec_t));
                ac = formats_to_test[i].audio_codecs;
                for (j = 0; ac[j].name != NULL; j++) {
                    if ((ac[j].id == AV_CODEC_ID_NONE) || VICE_P_AVCODEC_FIND_ENCODER(ac[j].id)) {
                        audio_codec_list[ai++] = ac[j];
                        audio_codec_list = lib_realloc(audio_codec_list, (ai + 1) * sizeof(gfxoutputdrv_codec_t));
                    }
                }
                audio_codec_list[ai].name = NULL;
            }
            if (formats_to_test[i].video_codecs != NULL) {
                vi = 0;
                video_codec_list = lib_malloc(sizeof(gfxoutputdrv_codec_t));
                vc = formats_to_test[i].video_codecs;
                for (j = 0; vc[j].name != NULL; j++) {
                    if (vc[j].id == AV_CODEC_ID_NONE || VICE_P_AVCODEC_FIND_ENCODER(vc[j].id)) {
                        video_codec_list[vi++] = formats_to_test[i].video_codecs[j];
                        video_codec_list = lib_realloc(video_codec_list, (vi + 1) * sizeof(gfxoutputdrv_codec_t));
                    }
                }
                video_codec_list[vi].name = NULL;
            }
            if (((audio_codec_list == NULL) || (ai > 0)) && ((video_codec_list == NULL) || (vi > 0))) {
                ffmpegdrv_formatlist[f].name = lib_stralloc(formats_to_test[i].name);
                ffmpegdrv_formatlist[f].audio_codecs = audio_codec_list;
                ffmpegdrv_formatlist[f++].video_codecs = video_codec_list;
                ffmpegdrv_formatlist = lib_realloc(ffmpegdrv_formatlist, (f + 1) * sizeof(gfxoutputdrv_format_t));
            }
        }
    }
    ffmpegdrv_formatlist[f].name = NULL;
    ffmpeg_drv.formatlist = ffmpegdrv_formatlist;
}
Example #3
0
static void tui_menu_call_callback(tui_menu_item_t *item, int param, int *become_default, tui_menu_item_behavior_t *behavior)
{
    tui_menu_callback_t callback = item->callback;
    tui_menu_item_behavior_t dummy;
    const char *new_par_string;

    if (callback == NULL) {
        lib_free(item->par_string);
        item->par_string = NULL;
        return;
    }

    new_par_string = (*callback)(param, item->callback_param, become_default, behavior == NULL ? &dummy : behavior);

    if (new_par_string == NULL) {
        lib_free(item->par_string);
        item->par_string = NULL;
    } else {
        if (item->par_string != NULL) {
            item->par_string = lib_realloc(item->par_string, strlen(new_par_string) + 1);
            strcpy(item->par_string, new_par_string);
        } else {
            item->par_string = lib_stralloc(new_par_string);
        }
    }
}
Example #4
0
static int plus60k_activate(void)
{
    plus60k_ram = (BYTE *)lib_realloc((void *)plus60k_ram, (size_t)0xf000);

    log_message(plus60k_log, "PLUS60K expansion installed.");

    if (!util_check_null_string(plus60k_filename)) {
        if (util_file_load(plus60k_filename, plus60k_ram, (size_t)0xf000,
                           UTIL_FILE_LOAD_RAW) < 0) {
            log_message(plus60k_log,
                        "Reading PLUS60K image %s failed.", plus60k_filename);
            if (util_file_save(plus60k_filename, plus60k_ram, 0xf000) < 0) {
                log_message(plus60k_log,
                            "Creating PLUS60K image %s failed.", plus60k_filename);
                return -1;
            }
            log_message(plus60k_log, "Creating PLUS60K image %s.", plus60k_filename);
            return 0;
        }
        log_message(plus60k_log, "Reading PLUS60K image %s.", plus60k_filename);
    }

    plus60k_reset();
    return 0;
}
Example #5
0
static CRITICAL_SECTION *__NTGetCriticalSection( void )
{
    CRITICAL_SECTION *ptr;

    if( critsect_next < MAX_CRITICAL_SECTION ) {
        ptr = &(critsect_cache[critsect_next]);
        critsect_next++;
    } else {
        ptr = lib_calloc( 1, sizeof( *ptr ) );
        if( ptr == NULL ) {
            __fatal_runtime_error(
                "Unable to allocate semaphore data", 1 );
        }
        critsect_vector = lib_realloc( critsect_vector,
                (critsect_vectornext+1)*sizeof(CRITICAL_SECTION*));
        if( critsect_vector == NULL ) {
            __fatal_runtime_error(
                "Unable to allocate semaphore data", 1 );
        }
        critsect_vector[critsect_vectornext] = ptr;
        critsect_vectornext++;
    }
    InitializeCriticalSection( ptr );
    return( ptr );
}
Example #6
0
unsigned __growPOSIXHandles( unsigned num )
{
    HANDLE *new2;
    unsigned i;

    if( num > __NHandles )
    {
        _AccessFList();
        if( __OSHandles == NULL )
        {
            new2 = lib_malloc( num * sizeof( int ) );
        }
        else
        {
            new2 = lib_realloc( __OSHandles, num * sizeof( int ) );
        }
        if( new2 == NULL )
        {
            __set_errno( ENOMEM );
            num = __NHandles;
        }
        else
        {
            for( i = __NHandles; i < num; i++ )
            {
                new2[ i ] = NULL_HANDLE;
            }
            __OSHandles = new2;
            __NHandles = num;
        }
        _ReleaseFList();
    }
    return( __NHandles );
}
Example #7
0
char *lib_mvsprintf(const char *fmt, va_list args)
{
    /* Guess we need no more than 100 bytes. */
    int n, size = 100;
    char *p, *np;

    if ((p = lib_malloc (size)) == NULL) {
        return NULL;
    }

    while (1) {
        /* Try to print in the allocated space. */
        n = vsnprintf (p, size, fmt, args /* ap */);

        /* If that worked, return the string. */
        if (n > -1 && n < size) {
            return p;
        }

        /* Else try again with more space. */
        if (n > -1) {     /* glibc 2.1 and C99 */
            size = n + 1; /* precisely what is needed */
        } else {          /* glibc 2.0 */
            size *= 2;    /* twice the old size */
        }

        if ((np = lib_realloc (p, size)) == NULL) {
            lib_free(p);
            return NULL;
        } else {
            p = np;
        }
    }
}
Example #8
0
static void kbd_buf_parse_string(const char *string)
{
    unsigned int i, j;
    size_t len;

    len = strlen(string);

    if (len > QUEUE_SIZE) {
        len = QUEUE_SIZE;
    }

    kbd_buf_string = lib_realloc(kbd_buf_string, len + 1);
    memset(kbd_buf_string, 0, len + 1);

    for (i = 0, j = 0; i < len; i++) {
        if (string[i] == '\\' && i < (len - 2) && isxdigit((int)string[i + 1])
                && isxdigit((int)string[i + 2])) {
            char hexvalue[3];

            hexvalue[0] = string[i + 1];
            hexvalue[1] = string[i + 2];
            hexvalue[2] = '\0';
            kbd_buf_string[j] = (char)strtol(hexvalue, NULL, 16);
            j++;
            i += 2;
        } else {
            kbd_buf_string[j] = string[i];
            j++;
        }
    }
}
Example #9
0
static int raster_realize_frame_buffer(raster_t *raster)
{
    unsigned int fb_width, fb_height, fb_pitch;

    raster_draw_buffer_free(raster->canvas);

    fb_width = raster_calc_frame_buffer_width(raster);
    fb_height = raster->geometry->screen_size.height > raster->geometry->last_displayed_line ?
                raster->geometry->screen_size.height
                : raster->geometry->last_displayed_line + 1; /* allocate extra space for the */
    /* lower part of the visible lower border (lines 0+) on NTSC VIC-II */

    if (fb_width > 0 && fb_height > 0) {
        if (raster_draw_buffer_alloc(raster->canvas, fb_width, fb_height, &fb_pitch)) {
            return -1;
        }

        raster->canvas->draw_buffer->draw_buffer_width = fb_width;
        raster->canvas->draw_buffer->draw_buffer_height = fb_height;
        raster->canvas->draw_buffer->draw_buffer_pitch = fb_pitch;

        raster_draw_buffer_clear(raster->canvas, 0, fb_width, fb_height,
                                 fb_pitch);
    }

    raster->fake_draw_buffer_line = lib_realloc(raster->fake_draw_buffer_line,
                                                fb_width);

    memset(raster->fake_draw_buffer_line, 0, fb_width);

    return 0;
}
Example #10
0
static int cs256k_activate(void)
{
    cs256k_ram = lib_realloc((void *)cs256k_ram, (size_t)0x40000);

    log_message(cs256k_log, "CSORY 256K expansion installed.");

    cs256k_reset();
    return 0;
}
Example #11
0
/* Make sure there is a trailing '/' in `*path'.  */
static void slashize_path(char **path)
{
    int len = strlen(*path);

    if ((*path)[len - 1] != '/') {
        *path = lib_realloc(*path, len + 2);
        (*path)[len] = '/';
        (*path)[len + 1] = '\0';
    }
}
Example #12
0
static void xmvsprintf_add(char **buf, unsigned int *bufsize,
                           unsigned int *position, char write)
{
    if (*position == *bufsize) {
        *bufsize *= 2;
        *buf = lib_realloc(*buf, *bufsize);
    }
    (*buf)[*position] = write;
    *position += 1;
}
Example #13
0
int cmdline_register_options(const cmdline_option_t *c)
{
    cmdline_option_ram_t *p;

    p = options + num_options;
    for (; c->name != NULL; c++, p++) {
        if (lookup_exact(c->name)) {
            archdep_startup_log_error("CMDLINE: (%d) Duplicated option '%s'.\n", num_options, c->name);
            return -1;
        }

        if (c->use_description_id != USE_DESCRIPTION_ID) {
            if (c->description == NULL) {
                archdep_startup_log_error("CMDLINE: (%d) description id not used and description NULL for '%s'.\n", num_options, c->name);
                return -1;
            }
        }

        /* archdep_startup_log_error("CMDLINE: (%d) registering option '%s'.\n", num_options, c->name); */

        if (num_allocated_options <= num_options) {
            num_allocated_options *= 2;
            options = lib_realloc(options, (sizeof(cmdline_option_ram_t) * num_allocated_options));
            p = options + num_options;
        }

        p->name = lib_stralloc(c->name);
        p->type = c->type;
        p->need_arg = c->need_arg;
        p->set_func = c->set_func;
        p->extra_param = c->extra_param;
        if (c->resource_name != NULL) {
            p->resource_name = lib_stralloc(c->resource_name);
        } else {
            p->resource_name = NULL;
        }
        p->resource_value = c->resource_value;

        p->use_param_name_id = c->use_param_name_id;
        p->use_description_id = c->use_description_id;

        p->param_name = c->param_name;
        p->description = c->description;

        p->param_name_trans = c->param_name_trans;
        p->description_trans = c->description_trans;

        p->combined_string = NULL;

        num_options++;
    }

    return 0;
}
Example #14
0
/*
    allocate/free buffers. these functions should somewhat mimic the behaviour
    of a real drive to increase compatibility with some hacks a bit. see
    testprogs/vdrive/disk/dircheck.bas

    FIXME: find out the *exact* behaviour of the various drives and implement
           this function accordingly.
    FIXME: REL files do not use this logic yet (vdrive-rel.c)
    FIXME: ideally this logic should allocate memory from a common drive memory
           array, which then can be used properly for M-R too
*/
void vdrive_alloc_buffer(bufferinfo_t *p, int mode)
{
    size_t size = 256;

    if (p->buffer == NULL) {
        /* first time actually allocate memory, and clear it */
        p->buffer = lib_malloc(size);
        memset(p->buffer, 0, size);
    } else {
        /* any other time, just adjust the size of the buffer */
        p->buffer = lib_realloc(p->buffer, size);
    }
    p->mode = mode;
}
Example #15
0
static void file_list_add_item(struct file_list *fl, const char *name, enum file_type type)
{
    if (fl->num_items == fl->num_used_items) {
        fl->num_items += 100;
        if (fl->items != NULL) {
            fl->items = lib_realloc(fl->items, fl->num_items * sizeof(*fl->items));
        } else {
            fl->items = lib_malloc(fl->num_items * sizeof(*fl->items));
        }
    }

    strcpy(fl->items[fl->num_used_items].name, name);
    fl->items[fl->num_used_items].type = type;
    fl->num_used_items++;
}
Example #16
0
/* IO helper functions.  */
char *ioutil_current_dir(void)
{
    static size_t len = 128;
    char *p = lib_malloc(len);

    while (getcwd(p, len) == NULL) {
        if (errno == ERANGE) {
            len *= 2;
            p = lib_realloc(p, len);
        } else
            return NULL;
    }

    return p;
}
Example #17
0
static void kbd_buf_parse_string(const char *string)
{
    unsigned int i, j;
    size_t len;

    len = strlen(string);

    if (len > QUEUE_SIZE) {
        len = QUEUE_SIZE;
    }

    kbd_buf_string = lib_realloc(kbd_buf_string, len + 1);
    memset(kbd_buf_string, 0, len + 1);

    for (i = 0, j = 0; i < len; i++) {
        if (string[i] == '\\') {
            /* printf("esc:%s\n", &string[i]); */
            if((i < (len - 1)) && (string[i + 1] == '\\')) {
                /* escaped backslash "\\" */
                kbd_buf_string[j] = charset_p_topetcii('\\');
                i += 1;
                j++;
            } else if((i < (len - 1)) && (string[i + 1] == 'n')) {
                /* escaped line ending "\n" */
                kbd_buf_string[j] = charset_p_topetcii('\n');
                i += 1;
                j++;
            } else if((i < (len - 3)) && (string[i + 1] == 'x') && isxdigit((int)string[i + 2]) && isxdigit((int)string[i + 3])) {
                /* escaped hex value in c-style format "\x00" */
                char hexvalue[3];

                hexvalue[0] = string[i + 2];
                hexvalue[1] = string[i + 3];
                hexvalue[2] = '\0';

                kbd_buf_string[j] = (char)strtol(hexvalue, NULL, 16);
                i += 3;
                j++;
            }
        } else {
            /* printf("chr:%s\n", &string[i]); */
            /* regular character, convert to petscii */
            kbd_buf_string[j] = charset_p_topetcii(string[i]);
            j++;
        }
    }
}
Example #18
0
static int ramcart_activate(void)
{
	if (!ramcart_size)
		return 0;

	ramcart_ram = lib_realloc((void *)ramcart_ram, (size_t)ramcart_size);

	/* Clear newly allocated RAM.  */
	if (ramcart_size > old_ramcart_ram_size)
		memset(ramcart_ram, 0, (size_t)(ramcart_size - old_ramcart_ram_size));

	old_ramcart_ram_size = ramcart_size;

	#ifdef CELL_DEBUG
	printf("INFO: %dKB unit installed.\n", ramcart_size >> 10);
	#endif

	if (!util_check_null_string(ramcart_filename))
	{
		if (util_file_load(ramcart_filename, ramcart_ram, (size_t)ramcart_size, UTIL_FILE_LOAD_RAW) < 0)
		{
			#ifdef CELL_DEBUG
			printf("INFO: Reading RAMCART image %s failed.\n", ramcart_filename);
			#endif
			if (util_file_save(ramcart_filename, ramcart_ram, ramcart_size) < 0)
			{
				#ifdef CELL_DEBUG
				printf("INFO: Creating RAMCART image %s failed.\n", ramcart_filename);
				#endif
				return -1;
			}
			#ifdef CELL_DEBUG
			printf("INFO: Creating RAMCART image %s.\n", ramcart_filename);
			#endif
			return 0;
		}
		#ifdef CELL_DEBUG
		printf("INFO: Reading RAMCART image %s.\n", ramcart_filename);
		#endif
	}

	ramcart_reset();
	return 0;
}
Example #19
0
/* IO helper functions.  */
char *ioutil_current_dir(void)
{
#ifdef __riscos
    return GetCurrentDirectory();
#else
    static size_t len = 128;
    char *p = lib_malloc(len);

    while (getcwd(p, len) == NULL) {
        if (errno == ERANGE) {
            len *= 2;
            p = lib_realloc(p, len);
        } else
            return NULL;
    }

    return p;
#endif
}
Example #20
0
void event_record_attach_in_list(event_list_state_t *list, unsigned int unit,
                                 const char *filename, unsigned int read_only)
{
    char *event_data;
    unsigned int size;

    list->current->type = EVENT_ATTACHIMAGE;
    list->current->clk = maincpu_clk;
    list->current->next
        = (event_list_t *)lib_calloc(1, sizeof(event_list_t));

    size = strlen(filename) + 3;

    event_data = lib_malloc(size);
    event_data[0] = unit;
    event_data[1] = read_only;
    strcpy(&event_data[2], filename);

    if (event_image_append(filename, NULL, 0) == 1) {
        FILE *fd;
        size_t file_len = 0;
        
        fd = fopen(filename, MODE_READ);

        if (fd != NULL) {
            file_len = util_file_length(fd);
            event_data = lib_realloc(event_data, size + file_len);

            if (fread(&event_data[size], file_len, 1, fd) != 1)
                log_error(event_log, "Cannot load image file %s", filename);

            fclose(fd);
        } else {
            log_error(event_log, "Cannot open image file %s", filename);
        }
        size += file_len;
    }

    list->current->size = size;
    list->current->data = event_data;
    list->current = list->current->next;
}
Example #21
0
log_t log_open(const char *id)
{
    log_t new_log = 0;
    log_t i;

    for (i = 0; i < num_logs; i++) {
        if (logs[i] == NULL) {
            new_log = i;
            break;
        }
    }
    if (i == num_logs) {
        new_log = num_logs++;
        logs = lib_realloc(logs, sizeof(*logs) * num_logs);
    }

    logs[new_log] = lib_stralloc(id);

    return new_log;
}
Example #22
0
int vidmode_init(void)
{
    unsigned int hz;
    int i;
    Display *display;

    vidmode_log = log_open("VidMode");

    display = x11ui_get_display_ptr();

    if (!XF86VidModeGetAllModeLines(display, screen, &vm_mode_count, &vm_modes)) {
        log_error(vidmode_log, "Error getting video mode information - disabling vidmode extension.");
        vm_available = 0;
        return 0;
    }

    for (i = 0; i < vm_mode_count; i++) {
        if (vm_modes[i]->hdisplay <= 800 && vm_modes[i]->hdisplay >= 320 && vm_modes[i]->vdisplay <= 600 && vm_modes[i]->vdisplay >= 200) {
            vm_bestmodes = (vm_bestvideomode_t *)lib_realloc(vm_bestmodes, (vm_index + 1) * sizeof(vm_bestvideomode_t));
            vm_bestmodes[vm_index].modeindex = i;

            if (vm_modes[i]->vtotal * vm_modes[i]->htotal) {
                hz = vm_modes[i]->dotclock * 1000 / (vm_modes[i]->vtotal * vm_modes[i]->htotal);
            } else {
                hz = 0;
            }

            vm_bestmodes[vm_index].name = lib_msprintf(" %ix%i-%iHz", vm_modes[i]->hdisplay, vm_modes[i]->vdisplay, hz);
            if (++vm_index > 29) {
                break;
            }
        }
    }

    if (vm_index == 0) {
        return 0;
    }

    vm_available = 1;
    return 0;
}
Example #23
0
static char* append_string_to_input_buffer(char *old_input_buffer, GtkWidget *terminal, GdkAtom clipboard_to_use)
{
    GtkClipboard *clipboard = gtk_widget_get_clipboard(terminal, clipboard_to_use);
    gchar *new_string = gtk_clipboard_wait_for_text(clipboard);

    if (new_string != NULL) {
        char *new_input_buffer = lib_realloc(old_input_buffer, strlen(old_input_buffer) + strlen(new_string) + 1);
        char *char_in, *char_out = new_input_buffer + strlen(new_input_buffer);

        for (char_in = new_string; *char_in; char_in++) {
            if (*char_in < 0 || *char_in >= 32) {
                *char_out++ = *char_in;
            }
        }
        *char_out = 0;
        g_free(new_string);

        return new_input_buffer;
    }
    return old_input_buffer;
}
Example #24
0
log_t log_open(const char *id)
{
    log_t new_log = 0;
    log_t i;

    for (i = 0; i < num_logs; i++) {
        if (logs[i] == NULL) {
            new_log = i;
            break;
        }
    }
    if (i == num_logs) {
        new_log = num_logs++;
        logs = lib_realloc(logs, sizeof(*logs) * num_logs);
    }

    logs[new_log] = lib_stralloc(id);

    /* printf("log_open(%s) = %d\n", id, (int)new_log); */
    return new_log;
}
Example #25
0
static int __F_NAME(addenv,waddenv)( int index, const CHAR_TYPE *name, const CHAR_TYPE *newvalue )
{
    int                 len;
    CHAR_TYPE           *env_str;
    const CHAR_TYPE     *old_val;
    const CHAR_TYPE     **envp;

    envp = (const CHAR_TYPE **)__F_NAME(_RWD_environ,_RWD_wenviron);
    len = __F_NAME(strlen,wcslen)( name );
    old_val = _RWD_env_mask[index] ? envp[index] : NULL;
    env_str = lib_realloc( (void *)old_val, ( len + __F_NAME(strlen,wcslen)( newvalue ) + 2 ) * sizeof( CHAR_TYPE ) );
    if( env_str == NULL )
        return( -1 );
    memcpy( env_str, name, len * sizeof( CHAR_TYPE ) );
    env_str[len] = STRING( '=' );
    __F_NAME(strcpy,wcscpy)( &env_str[len + 1], newvalue );
    envp[index] = env_str;
#ifndef __WIDECHAR__
    _RWD_env_mask[index] = 1;     /* indicate string alloc'd */
#endif
    return( 0 );
}
Example #26
0
static int plus256k_activate(void)
{
    plus256k_ram = lib_realloc((void *)plus256k_ram, (size_t)0x40000);

    log_message(plus256k_log, "PLUS256K hack installed.");

    if (!util_check_null_string(plus256k_filename)) {
        if (util_file_load(plus256k_filename, plus256k_ram, (size_t)0x40000, UTIL_FILE_LOAD_RAW) < 0) {
            log_message(plus256k_log, "Reading PLUS256K image %s failed.", plus256k_filename);
            if (util_file_save(plus256k_filename, plus256k_ram, 0x40000) < 0) {
                log_message(plus256k_log, "Creating PLUS256K image %s failed.", plus256k_filename);
                return -1;
            }
            log_message(plus256k_log, "Creating PLUS256K image %s.", plus256k_filename);
            return 0;
        }
        log_message(plus256k_log, "Reading PLUS256K image %s.", plus256k_filename);
    }
    plus256k_reset();
    set_cpu_lines_lock(CPU_LINES_PLUS256K, "PLUS256K");
    return 0;
}
Example #27
0
static int petdww_activate(void)
{
    if (petres.IOSize < 2048) {
        log_message(petdww_log, "Cannot enable DWW: IOSize too small (%d but must be 2K)", petres.IOSize);
        return -1;
    }

    if (petres.superpet) {
        log_message(petdww_log, "Cannot enable DWW: not compatible with SuperPET");
        return -1;
    }

    petdww_ram = lib_realloc((void *)petdww_ram, (size_t)PET_DWW_RAM_SIZE);

    /* Clear newly allocated RAM.  */
    memset(petdww_ram, 0, (size_t)PET_DWW_RAM_SIZE);

    log_message(petdww_log, "%dKB of hi-res RAM installed.", PET_DWW_RAM_SIZE >> 10);

    if (!util_check_null_string(petdww_filename)) {
        if (util_file_load(petdww_filename, petdww_ram, (size_t)PET_DWW_RAM_SIZE,
            UTIL_FILE_LOAD_RAW) < 0) {
            log_message(petdww_log, "Reading PET DWW image %s failed.",
                        petdww_filename);
            if (util_file_save(petdww_filename, petdww_ram, PET_DWW_RAM_SIZE) < 0) {
                log_message(petdww_log, "Creating PET DWW image %s failed.",
                            petdww_filename);
                return -1;
            }
            log_message(petdww_log, "Creating PET DWW image %s.",
                        petdww_filename);
            return 0;
        }
        log_message(petdww_log, "Reading PET DWW image %s.", petdww_filename);
    }

    petdww_reset();
    return 0;
}
Example #28
0
static void ui_hotkey_register(ui_hotkey_modifier_t modifier, signed long keysym, void *callback, void *client_data)
{
    registered_hotkey_t *p;

    if (registered_hotkeys == 0) {
        num_allocated_hotkeys = 32;
        registered_hotkeys = lib_malloc(num_allocated_hotkeys * sizeof(registered_hotkey_t));
        num_registered_hotkeys = 0;
    } else if (num_registered_hotkeys == num_allocated_hotkeys) {
        num_allocated_hotkeys *= 2;
        registered_hotkeys = lib_realloc(registered_hotkeys, (num_allocated_hotkeys * sizeof(registered_hotkey_t)));
    }

    p = registered_hotkeys + num_registered_hotkeys;

    p->modifier = modifier;
    p->keysym = (ui_keysym_t)keysym;
    p->callback = (ui_callback_t)callback;
    p->client_data = (ui_callback_data_t)client_data;

    num_registered_hotkeys++;
}
Example #29
0
void tui_area_get(tui_area_t *a, int x, int y, int width, int height)
{
    BYTE *p;
    int i, j;

    if (*a == NULL) {
        *a = lib_malloc(sizeof (struct tui_area));
        (*a)->mem = lib_malloc(2 * width * height);
    } else {
        (*a)->mem = lib_realloc((*a)->mem, 2 * width * height);
    }
    (*a)->width = width;
    (*a)->height = height;

    _farsetsel(_dos_ds);

    for (p = (*a)->mem, i = 0; i < height; i++) {
        int addr = screen_addr(x, y + i);

        for (j = 0; j < 2 * width; j++)
            *(p++) = _farnspeekb(addr + j);
    }
}
Example #30
0
int cmdline_register_options(const cmdline_option_t *c)
{
    cmdline_option_ram_t *p;

    p = options + num_options;
    for (; c->name != NULL; c++, p++) {
        if (num_allocated_options <= num_options) {
            num_allocated_options *= 2;
            options = lib_realloc(options, (sizeof(cmdline_option_ram_t) * num_allocated_options));
            p = options + num_options;
        }

        p->name = lib_stralloc(c->name);
        p->type = c->type;
        p->need_arg = c->need_arg;
        p->set_func = c->set_func;
        p->extra_param = c->extra_param;
        if (c->resource_name != NULL)
            p->resource_name = lib_stralloc(c->resource_name);
        else
            p->resource_name = NULL;
        p->resource_value = c->resource_value;

        p->use_param_name_id = c->use_param_name_id;
        p->use_description_id = c->use_description_id;

        p->param_name = c->param_name;
        p->description = c->description;

        p->param_name_trans = c->param_name_trans;
        p->description_trans = c->description_trans;

        num_options++;
    }

    return 0;
}