~ubuntu-branches/ubuntu/quantal/vice/quantal

« back to all changes in this revision

Viewing changes to src/arch/unix/uicommands.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-03-27 13:06:04 UTC
  • mfrom: (4 hoary)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20050327130604-zodmv0i60dbbmcik
Tags: 1.16-3
Apply patch from Andreas Jochens <aj@andaco.de> to correct building on
AMD64 and GCC 4.x (closes: #300936)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * Written by
5
5
 *  Ettore Perazzoli <ettore@comm2000.it>
6
 
 *  Andreas Boose <boose@linux.rz.fh-hannover.de>
 
6
 *  Andreas Boose <viceteam@t-online.de>
7
7
 *
8
8
 * This file is part of VICE, the Versatile Commodore Emulator.
9
9
 * See README for copyright notice.
31
31
#include <stdio.h>
32
32
#include <stdlib.h>
33
33
#include <string.h>
34
 
#include <unistd.h>
35
34
 
36
35
#include "archdep.h"
37
 
#include "attach.h"
38
 
#include "autostart.h"
39
 
#include "fliplist.h"
40
 
#include "imagecontents.h"
41
 
#include "info.h"
 
36
#include "drivecpu.h"
 
37
#include "event.h"
 
38
#include "fullscreenarch.h"
42
39
#include "interrupt.h"
 
40
#include "ioutil.h"
 
41
#include "lib.h"
43
42
#include "log.h"
44
43
#include "machine.h"
45
 
#include "maincpu.h"
46
 
#include "mem.h"
47
 
#include "mon.h"
48
 
#include "mos6510.h"
 
44
#include "monitor.h"
49
45
#include "resources.h"
50
46
#include "sound.h"
51
 
#include "tape.h"
52
47
#include "types.h"
53
48
#include "uicommands.h"
54
 
#include "uiedisk.h"
55
49
#include "uimenu.h"
56
 
#include "uisettings.h"
57
50
#include "uisnapshot.h"
58
51
#include "uidrive.h"
59
 
#include "utils.h"
 
52
#include "util.h"
60
53
#include "vsync.h"
61
 
#ifdef USE_XF86_EXTENSIONS
62
 
#include "fullscreen.h"
63
 
#endif
64
 
 
65
 
static int selection_from_image = 0;
66
 
 
67
 
/* ------------------------------------------------------------------------- */
68
 
void ui_set_selected_file(int num)
69
 
{
70
 
    selection_from_image = num;
71
 
}
72
 
 
73
 
/* ------------------------------------------------------------------------- */
74
 
 
75
 
static char *read_disk_image_contents(const char *name)
76
 
{
77
 
    image_contents_t *contents;
78
 
    char *s;
79
 
 
80
 
    contents = image_contents_read_disk(name);
81
 
    if (contents == NULL)
82
 
        return NULL;
83
 
 
84
 
#ifdef USE_GNOMEUI
85
 
    s = image_contents_to_string(contents, IMAGE_CONTENTS_STRING_PETSCII);
86
 
#else
87
 
    s = image_contents_to_string(contents, IMAGE_CONTENTS_STRING_ASCII);
88
 
#endif
89
 
 
90
 
    image_contents_destroy(contents);
91
 
 
92
 
    return s;
93
 
}
94
 
 
95
 
static UI_CALLBACK(attach_disk)
96
 
{
97
 
    int unit = (int)UI_MENU_CB_PARAM;
98
 
    char *filename, *title;
99
 
    ui_button_t button;
100
 
    static char *last_dir;
101
 
    int attach_wp = 0;
102
 
 
103
 
    vsync_suspend_speed_eval();
104
 
    title = xmsprintf(_("Attach Disk Image as unit #%d"), unit);
105
 
    filename = ui_select_file(title, read_disk_image_contents,
106
 
                              unit == 8 ? True : False, last_dir,
107
 
                              "*.[gdxGDX]*", &button, True, &attach_wp);
108
 
 
109
 
    free(title);
110
 
    if (attach_wp) {
111
 
        printf("Write protect attach requested.\n");
112
 
        resources_set_sprintf("AttachDevice%dReadonly",
113
 
                              (resource_value_t)attach_wp, unit);
114
 
    }
115
 
 
116
 
    switch (button) {
117
 
      case UI_BUTTON_OK:
118
 
        if (file_system_attach_disk(unit, filename) < 0)
119
 
            ui_error(_("Invalid Disk Image"));
120
 
        if (last_dir)
121
 
            free(last_dir);
122
 
        util_fname_split(filename, &last_dir, NULL);
123
 
        break;
124
 
      case UI_BUTTON_AUTOSTART:
125
 
        if (autostart_disk(filename, NULL, selection_from_image,
126
 
            AUTOSTART_MODE_RUN) < 0)
127
 
            ui_error(_("Invalid Disk Image or Filename"));
128
 
        if (last_dir)
129
 
            free(last_dir);
130
 
        util_fname_split(filename, &last_dir, NULL);
131
 
        break;
132
 
      default:
133
 
        /* Do nothing special.  */
134
 
        break;
135
 
    }
136
 
 
137
 
    if (filename != NULL)
138
 
        free(filename);
139
 
}
140
 
 
141
 
static UI_CALLBACK(attach_empty_disk)
142
 
{
143
 
    int unit = (int)UI_MENU_CB_PARAM;
144
 
    /* Where does the 1024 come from?  */
145
 
    char filename[1024];
146
 
 
147
 
    vsync_suspend_speed_eval();
148
 
 
149
 
    /* The following code depends on a zeroed filename.  */
150
 
    memset(filename, 0, 1024);
151
 
 
152
 
    if (ui_empty_disk_dialog(filename) < 0)
153
 
        return;
154
 
 
155
 
    if (file_system_attach_disk(unit, filename) < 0)
156
 
        ui_error(_("Invalid Disk Image"));
157
 
}
158
 
 
159
 
static UI_CALLBACK(detach_disk)
160
 
{
161
 
    int unit = (int)UI_MENU_CB_PARAM;
162
 
 
163
 
    vsync_suspend_speed_eval();
164
 
    file_system_detach_disk(unit);
165
 
}
166
 
 
167
 
/* ------------------------------------------------------------------------- */
168
 
 
169
 
static char *read_tape_image_contents(const char *name)
170
 
{
171
 
    image_contents_t *contents;
172
 
    char *s;
173
 
 
174
 
    contents = image_contents_read_tape(name);
175
 
    if (contents == NULL)
176
 
        return NULL;
177
 
 
178
 
#ifdef USE_GNOMEUI
179
 
    s = image_contents_to_string(contents, IMAGE_CONTENTS_STRING_PETSCII);
180
 
#else
181
 
    s = image_contents_to_string(contents, IMAGE_CONTENTS_STRING_ASCII);
182
 
#endif
183
 
 
184
 
    image_contents_destroy(contents);
185
 
 
186
 
    return s;
187
 
}
188
 
 
189
 
static UI_CALLBACK(attach_tape)
190
 
{
191
 
    char *filename;
192
 
    ui_button_t button;
193
 
    static char *last_dir;
194
 
 
195
 
    vsync_suspend_speed_eval();
196
 
 
197
 
    filename = ui_select_file(_("Attach a tape image"),
198
 
                              read_tape_image_contents,
199
 
                              True, last_dir, "*.[tT]*", &button, True, NULL);
200
 
 
201
 
    switch (button) {
202
 
      case UI_BUTTON_OK:
203
 
        if (tape_attach_image(filename) < 0)
204
 
            ui_error(_("Invalid Tape Image"));
205
 
        if (last_dir)
206
 
            free(last_dir);
207
 
        util_fname_split(filename, &last_dir, NULL);
208
 
        break;
209
 
      case UI_BUTTON_AUTOSTART:
210
 
        if (autostart_tape(filename, NULL, selection_from_image,
211
 
            AUTOSTART_MODE_RUN) < 0)
212
 
            ui_error(_("Invalid Tape Image"));
213
 
        if (last_dir)
214
 
            free(last_dir);
215
 
        util_fname_split(filename, &last_dir, NULL);
216
 
        break;
217
 
      default:
218
 
        /* Do nothing special.  */
219
 
        break;
220
 
    }
221
 
    if (filename != NULL)
222
 
        free(filename);
223
 
}
224
 
 
225
 
static UI_CALLBACK(detach_tape)
226
 
{
227
 
    tape_detach_image();
228
 
}
229
 
 
230
 
/* ------------------------------------------------------------------------- */
231
 
 
232
 
static char *read_disk_or_tape_image_contents(const char *fname)
233
 
{
234
 
    char *tmp;
235
 
 
236
 
    tmp = read_disk_image_contents(fname);
237
 
    if (tmp)
238
 
        return tmp;
239
 
    return read_tape_image_contents(fname);
240
 
}
241
 
 
242
 
static UI_CALLBACK(smart_attach)
243
 
{
244
 
    char *filename;
245
 
    ui_button_t button;
246
 
    static char *last_dir;
247
 
 
248
 
    vsync_suspend_speed_eval();
249
 
 
250
 
    filename = ui_select_file(_("Smart-attach a file"),
251
 
                              read_disk_or_tape_image_contents,
252
 
                              True, last_dir, NULL, &button, True, NULL);
253
 
 
254
 
    switch (button) {
255
 
      case UI_BUTTON_OK:
256
 
        if (file_system_attach_disk(8, filename) < 0
257
 
            && tape_attach_image(filename) < 0) {
258
 
            ui_error(_("Unknown image type"));
259
 
        }
260
 
        if (last_dir)
261
 
            free(last_dir);
262
 
        util_fname_split(filename, &last_dir, NULL);
263
 
        break;
264
 
      case UI_BUTTON_AUTOSTART:
265
 
        if (autostart_autodetect(filename, NULL, selection_from_image,
266
 
            AUTOSTART_MODE_RUN) < 0)
267
 
            ui_error(_("Unknown image type"));
268
 
        if (last_dir)
269
 
            free(last_dir);
270
 
        util_fname_split(filename, &last_dir, NULL);
271
 
        break;
272
 
      default:
273
 
        /* Do nothing special.  */
274
 
        break;
275
 
    }
276
 
    if (filename != NULL)
277
 
        free(filename);
278
 
}
279
 
 
280
 
/* ------------------------------------------------------------------------- */
 
54
 
281
55
 
282
56
static UI_CALLBACK(change_working_directory)
283
57
{
284
58
    char *wd;
285
 
    wd = xmalloc(MAXPATHLEN);
286
 
 
287
 
    getcwd(wd, MAXPATHLEN);
 
59
    int len;
 
60
 
 
61
    len = ioutil_maxpathlen();
 
62
    wd = lib_malloc(len);
 
63
 
 
64
    ioutil_getcwd(wd, len);
288
65
    vsync_suspend_speed_eval();
289
66
    if (ui_input_string(_("VICE setting"),
290
67
                        _("Change current working directory"),
291
 
                        wd, MAXPATHLEN) == UI_BUTTON_OK) {
292
 
        if (chdir(wd) < 0)
 
68
                        wd, len) == UI_BUTTON_OK) {
 
69
        if (ioutil_chdir(wd) < 0)
293
70
            ui_error(_("Directory not found"));
294
71
    }
295
 
    free(wd);
296
 
}
297
 
 
298
 
static void mon_trap(ADDRESS addr, void *unused_data)
299
 
{
300
 
    mon(addr);
 
72
    lib_free(wd);
301
73
}
302
74
 
303
75
static UI_CALLBACK(activate_monitor)
304
76
{
305
77
#ifdef USE_XF86_EXTENSIONS
306
 
    fullscreen_mode_off();
 
78
    fullscreen_suspend(0);
307
79
#endif
308
80
    vsync_suspend_speed_eval();
309
81
    ui_dispatch_events();               /* popdown the menu */
310
82
    ui_autorepeat_on();
311
83
 
 
84
#ifdef HAVE_MOUSE
 
85
    ui_restore_mouse();
 
86
#endif
312
87
    if (!ui_emulation_is_paused())
313
 
        maincpu_trigger_trap(mon_trap, (void *)0);
 
88
        monitor_startup_trap();
314
89
    else
315
 
        mon_trap(MOS6510_REGS_GET_PC(&maincpu_regs), 0);
 
90
        monitor_startup();
316
91
}
317
92
 
318
93
static UI_CALLBACK(run_c1541)
319
94
{
320
95
#ifdef USE_XF86_EXTENSIONS
321
 
    fullscreen_mode_off();
 
96
    fullscreen_suspend(0);
322
97
#endif
323
98
    vsync_suspend_speed_eval();
324
99
    sound_close();
336
111
    }
337
112
}
338
113
 
 
114
static UI_CALLBACK(drive_reset)
 
115
{
 
116
    vsync_suspend_speed_eval();
 
117
    drivecpu_trigger_reset((unsigned int)UI_MENU_CB_PARAM);
 
118
}
 
119
 
339
120
static UI_CALLBACK(reset)
340
121
{
341
122
    vsync_suspend_speed_eval();
342
 
    maincpu_trigger_reset();
 
123
    machine_trigger_reset(MACHINE_RESET_MODE_SOFT);
343
124
}
344
125
 
345
126
static UI_CALLBACK(powerup_reset)
346
127
{
347
128
    vsync_suspend_speed_eval();
348
 
    machine_powerup();
 
129
    machine_trigger_reset(MACHINE_RESET_MODE_HARD);
349
130
}
350
131
 
351
132
static UI_CALLBACK(browse_manual)
352
133
{
353
134
    const char *bcommand = NULL;
354
135
 
355
 
    resources_get_value("HTMLBrowserCommand", (resource_value_t *)&bcommand);
 
136
    resources_get_value("HTMLBrowserCommand", (void *)&bcommand);
356
137
 
357
138
    if (bcommand == NULL ||
358
139
        *bcommand == '\0') {
366
147
        int manual_path_len, cmd_len;
367
148
 
368
149
#ifdef USE_XF86_EXTENSIONS
369
 
        fullscreen_mode_off();
 
150
        fullscreen_suspend(0);
370
151
#endif
371
152
        cmd_len = strlen(bcommand);
372
153
        manual_path_len = strlen(manual_path);
446
227
 
447
228
/* Snapshot commands.  */
448
229
 
449
 
static void load_snapshot_trap(ADDRESS unused_addr, void *data)
 
230
static char *load_snapshot_last_dir = NULL;
 
231
 
 
232
static void load_snapshot_trap(WORD unused_addr, void *data)
450
233
{
451
234
    ui_button_t button;
452
235
    char *filename;
453
 
    static char *last_dir;
454
236
 
455
237
    vsync_suspend_speed_eval();
456
238
 
458
240
        log_debug(_("Quickloading file %s."), (char *)data);
459
241
        filename = (char *)data;
460
242
    } else {
461
 
        filename = ui_select_file(_("Load snapshot"), NULL, False, last_dir,
462
 
                              "*.vsf", &button, False, NULL);
 
243
        filename = ui_select_file(_("Load snapshot"), NULL, 0, False,
 
244
                                  load_snapshot_last_dir,
 
245
                                  "*.vsf", &button, False, NULL);
463
246
        if (button != UI_BUTTON_OK) {
464
247
            if (filename)
465
 
                free(filename);
 
248
                lib_free(filename);
466
249
            return;
467
250
        }
468
251
    }
469
 
    if (last_dir)
470
 
        free(last_dir);
471
 
    util_fname_split(filename, &last_dir, NULL);
 
252
    if (load_snapshot_last_dir)
 
253
        lib_free(load_snapshot_last_dir);
 
254
    util_fname_split(filename, &load_snapshot_last_dir, NULL);
472
255
 
473
 
    if (machine_read_snapshot(filename) < 0)
 
256
    if (machine_read_snapshot(filename, 0) < 0)
474
257
        ui_error(_("Cannot load snapshot file\n`%s'"), filename);
475
258
    ui_update_menus();
476
259
 
477
260
    if (filename != NULL)
478
 
        free(filename);
 
261
        lib_free(filename);
479
262
}
480
263
 
481
264
static UI_CALLBACK(load_snapshot)
482
265
{
483
266
    if (!ui_emulation_is_paused())
484
 
        maincpu_trigger_trap(load_snapshot_trap, (void *) 0);
 
267
        interrupt_maincpu_trigger_trap(load_snapshot_trap, (void *)0);
485
268
    else
486
269
        load_snapshot_trap(0, 0);
487
270
}
488
271
 
489
272
static UI_CALLBACK(load_quicksnap)
490
273
{
491
 
    char *fname = concat(archdep_home_path(), "/", VICEUSERDIR, "/",
 
274
    char *fname = util_concat(archdep_home_path(), "/", VICEUSERDIR, "/",
492
275
        machine_name, ".vsf", NULL);
493
276
 
494
277
    if (!ui_emulation_is_paused())
495
 
        maincpu_trigger_trap(load_snapshot_trap, (void *)fname);
 
278
        interrupt_maincpu_trigger_trap(load_snapshot_trap, (void *)fname);
496
279
    else
497
280
        load_snapshot_trap(0, (void *)fname);
498
281
}
499
282
 
500
 
static void save_snapshot_trap(ADDRESS unused_addr, void *data)
 
283
static void save_snapshot_trap(WORD unused_addr, void *data)
501
284
{
502
285
    if (data) {
503
286
        /* quick snapshot, save ROMs & disks (??) */
504
287
        log_debug(_("Quicksaving file %s."), (char *)data);
505
 
        if (machine_write_snapshot(data, 1, 1) < 0) {
 
288
        if (machine_write_snapshot(data, 1, 1, 0) < 0) {
506
289
            ui_error(_("Cannot write snapshot file\n`%s'\n"), data);
507
290
        }
508
 
        free(data);
 
291
        lib_free(data);
509
292
    } else {
510
293
        ui_snapshot_dialog();
511
294
    }
515
298
 
516
299
static UI_CALLBACK(save_snapshot)
517
300
{
518
 
    maincpu_trigger_trap(save_snapshot_trap, (void *) 0);
 
301
    interrupt_maincpu_trigger_trap(save_snapshot_trap, (void *)0);
519
302
}
520
303
 
521
304
static UI_CALLBACK(save_quicksnap)
522
305
{
523
 
    char *fname = concat(archdep_home_path(), "/", VICEUSERDIR, "/",
 
306
    char *fname = util_concat(archdep_home_path(), "/", VICEUSERDIR, "/",
524
307
        machine_name, ".vsf", NULL);
525
308
 
526
 
    maincpu_trigger_trap(save_snapshot_trap, (void *) fname);
527
 
}
528
 
 
529
 
/*  fliplist commands */
530
 
extern char last_attached_images[NUM_DRIVES][256];
531
 
extern ui_drive_enable_t enabled_drives;
532
 
 
533
 
struct cb_data_t {
534
 
    int unit;
535
 
    long data;                  /* should be enough for a pointer */
536
 
};
537
 
 
538
 
typedef enum {
539
 
    CBD_NEXT, CBD_PREV, CBD_ADD, CBD_REMOVE
540
 
} cbd_enum_t;
541
 
 
542
 
static UI_CALLBACK(attach_from_fliplist)
543
 
{
544
 
    flip_attach_head(((struct cb_data_t *) UI_MENU_CB_PARAM)->unit,
545
 
                     (int) ((struct cb_data_t *) UI_MENU_CB_PARAM)->data);
546
 
}
547
 
 
548
 
static UI_CALLBACK(attach_from_fliplist2)
549
 
{
550
 
    file_system_attach_disk(flip_get_unit((void *) UI_MENU_CB_PARAM),
551
 
                            flip_get_image((void *) UI_MENU_CB_PARAM));
552
 
}
553
 
 
554
 
static UI_CALLBACK(attach_from_fliplist3)
555
 
{
556
 
    flip_attach_head(8, (int) UI_MENU_CB_PARAM);
557
 
}
558
 
 
559
 
static UI_CALLBACK(add2fliplist)
560
 
{
561
 
    flip_add_image(8);
562
 
    ui_update_flip_menus(8, 8);
563
 
}
564
 
 
565
 
static UI_CALLBACK(add2fliplist2)
566
 
{
567
 
    flip_set_current(((struct cb_data_t *) UI_MENU_CB_PARAM)->unit,
568
 
                     (char *) ((struct cb_data_t *) UI_MENU_CB_PARAM)->data);
569
 
    flip_add_image(((struct cb_data_t *) UI_MENU_CB_PARAM)->unit);
570
 
    ui_update_flip_menus(((struct cb_data_t *) UI_MENU_CB_PARAM)->unit,
571
 
                         ((struct cb_data_t *) UI_MENU_CB_PARAM)->unit);
572
 
}
573
 
 
574
 
static UI_CALLBACK(remove_from_fliplist)
575
 
{
576
 
    flip_remove(8, NULL);
577
 
    ui_update_flip_menus(8, 8);
578
 
}
579
 
 
580
 
static UI_CALLBACK(remove_from_fliplist2)
581
 
{
582
 
    flip_remove(((struct cb_data_t *) UI_MENU_CB_PARAM)->unit,
583
 
                (char *) ((struct cb_data_t *) UI_MENU_CB_PARAM)->data);
584
 
    ui_update_flip_menus(((struct cb_data_t *) UI_MENU_CB_PARAM)->unit,
585
 
                         ((struct cb_data_t *) UI_MENU_CB_PARAM)->unit);
586
 
}
587
 
 
588
 
#ifdef USE_GNOMEUI
589
 
UI_MENU_DEFINE_TOGGLE(AttachDevice8Readonly)
590
 
UI_MENU_DEFINE_TOGGLE(AttachDevice9Readonly)
591
 
#endif
592
 
 
593
 
#define FLIPLIST_MENU_LIMIT 256
594
 
void ui_update_flip_menus(int from_unit, int to_unit)
595
 
{
596
 
    /* Yick, allocate dynamically */
597
 
    static ui_menu_entry_t flipmenu[NUM_DRIVES][FLIPLIST_MENU_LIMIT];
598
 
    static struct cb_data_t cb_data[NUM_DRIVES][sizeof(cbd_enum_t)];
599
 
 
600
 
    char *image = NULL, *t0 = NULL, *t1 = NULL, *t2 = NULL, *t3 = NULL;
601
 
    char *t4 = NULL, *t5 = NULL, *dir;
602
 
    void *fl_iterator;
603
 
    int i, drive, true_emu, fliplist_start = 0;
604
 
    static int name_count = 0;
605
 
    char *menuname;
606
 
 
607
 
    resources_get_value("DriveTrueEmulation",
608
 
                        (resource_value_t *)&true_emu);
609
 
 
610
 
    for (drive = from_unit - 8;
611
 
        (drive <= to_unit - 8) && (drive < NUM_DRIVES);
612
 
        drive++) {
613
 
 
614
 
        i = 0;
615
 
        t0 = t1 = t2 = t3 = t4 = t5 = NULL;
616
 
 
617
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
618
 
        t0 = xmsprintf(_("Attach #%d"), drive + 8);
619
 
        flipmenu[drive][i].string = t0;
620
 
        flipmenu[drive][i].callback = (ui_callback_t)attach_disk;
621
 
        flipmenu[drive][i].callback_data = (ui_callback_data_t)(drive + 8);
622
 
        i++;
623
 
 
624
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
625
 
        t5 = xmsprintf(_("Detach #%d"), drive + 8);
626
 
        flipmenu[drive][i].string = t5;
627
 
        flipmenu[drive][i].callback = (ui_callback_t)detach_disk;
628
 
        flipmenu[drive][i].callback_data = (ui_callback_data_t)(drive + 8);
629
 
        i++;
630
 
 
631
 
#ifdef USE_GNOMEUI
632
 
        /* drivesettings */
633
 
        /* this won't work so far for Xaw, because the checkmarks
634
 
           aren't updated when a menu is destroyed, as the flipmenu is
635
 
           dynamically regenerated; The Gnome code is already fixed. */
636
 
        memcpy(&flipmenu[drive][i], (const char *)ui_drive_settings_menu,
637
 
               sizeof (ui_menu_entry_t));
638
 
        i++;
639
 
        /* Write protext UI controll */
640
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
641
 
        flipmenu[drive][i].string = "*Write Protect";
642
 
        if (drive == 0)
643
 
            flipmenu[drive][i].callback = toggle_AttachDevice8Readonly;
644
 
        else
645
 
            flipmenu[drive][i].callback = toggle_AttachDevice9Readonly;
646
 
        i++;
647
 
#endif
648
 
 
649
 
        fliplist_start = i;     /* if we take the goto don't free anythin */
650
 
 
651
 
        /* don't update menu deeply when drive has not been enabled
652
 
           or nothing has been attached */
653
 
        if (true_emu) {
654
 
            if (! ((1 << drive) & enabled_drives))
655
 
                goto update_menu;
656
 
        } else {
657
 
            if (strcmp(last_attached_images[drive], "") == 0)
658
 
                goto update_menu;
659
 
        }
660
 
 
661
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
662
 
        flipmenu[drive][i].string = "--";
663
 
        i++;
664
 
 
665
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
666
 
        util_fname_split(flip_get_next(drive + 8), &dir, &image);
667
 
        t1 = concat(_("Next: "), image ? image : _("<empty>"), NULL);
668
 
        flipmenu[drive][i].string = t1;
669
 
        flipmenu[drive][i].callback = (ui_callback_t)attach_from_fliplist;
670
 
        cb_data[drive][CBD_NEXT].unit = drive + 8;
671
 
        cb_data[drive][CBD_NEXT].data = 1;
672
 
        flipmenu[drive][i].callback_data =
673
 
            (ui_callback_data_t)&(cb_data[drive][CBD_NEXT]);
674
 
        if (dir)
675
 
            free(dir);
676
 
        if (image)
677
 
            free(image);
678
 
        i++;
679
 
 
680
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
681
 
        util_fname_split(flip_get_prev(drive + 8), &dir, &image);
682
 
        t2 = concat(_("Previous: "), image ? image : _("<empty>"), NULL);
683
 
        flipmenu[drive][i].string = t2;
684
 
        flipmenu[drive][i].callback = (ui_callback_t)attach_from_fliplist;
685
 
        cb_data[drive][CBD_PREV].unit = drive + 8;
686
 
        cb_data[drive][CBD_PREV].data = 0;
687
 
        flipmenu[drive][i].callback_data =
688
 
            (ui_callback_data_t)&(cb_data[drive][CBD_PREV]);
689
 
        if (dir)
690
 
            free(dir);
691
 
        if (image)
692
 
            free(image);
693
 
        i++;
694
 
 
695
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
696
 
        util_fname_split(last_attached_images[drive], &dir, &image);
697
 
        t3 = concat(_("Add: "), image, NULL);
698
 
        flipmenu[drive][i].string = t3;
699
 
        flipmenu[drive][i].callback = (ui_callback_t)add2fliplist2;
700
 
        cb_data[drive][CBD_ADD].unit = drive + 8;
701
 
        cb_data[drive][CBD_ADD].data = (long) last_attached_images[drive];
702
 
        flipmenu[drive][i].callback_data =
703
 
            (ui_callback_data_t)&(cb_data[drive][CBD_ADD]);
704
 
        if (dir)
705
 
            free(dir);
706
 
        if (image)
707
 
            free(image);
708
 
        i++;
709
 
 
710
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
711
 
        util_fname_split(last_attached_images[drive], &dir, &image);
712
 
        t4 = concat(_("Remove: "), image, NULL);
713
 
        flipmenu[drive][i].string = t4;
714
 
        flipmenu[drive][i].callback = (ui_callback_t)remove_from_fliplist2;
715
 
        cb_data[drive][CBD_REMOVE].unit = drive + 8;
716
 
        cb_data[drive][CBD_REMOVE].data = (long) last_attached_images[drive];
717
 
        flipmenu[drive][i].callback_data =
718
 
            (ui_callback_data_t)&(cb_data[drive][CBD_REMOVE]);
719
 
        if (dir)
720
 
            free(dir);
721
 
        if (image)
722
 
            free(image);
723
 
        i++;
724
 
 
725
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
726
 
        flipmenu[drive][i].string = "--";
727
 
        i++;
728
 
 
729
 
        /* Now collect current fliplist */
730
 
        fl_iterator=flip_init_iterate(drive + 8);
731
 
        fliplist_start = i;
732
 
        while (fl_iterator) {
733
 
            memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
734
 
            util_fname_split(flip_get_image(fl_iterator), &dir, &image);
735
 
            flipmenu[drive][i].string = concat(NO_TRANS, image, NULL);
736
 
            flipmenu[drive][i].callback =
737
 
                (ui_callback_t)attach_from_fliplist2;
738
 
            flipmenu[drive][i].callback_data =
739
 
                (ui_callback_data_t)fl_iterator;
740
 
 
741
 
            fl_iterator = flip_next_iterate(drive + 8);
742
 
            if (dir)
743
 
                free(dir);
744
 
            if (image)
745
 
                free(image);
746
 
            i++;
747
 
            if (i >= (FLIPLIST_MENU_LIMIT - 1)) {
748
 
                /* the end delimitor must fit */ 
749
 
                log_warning(LOG_DEFAULT,
750
 
                            "Number of fliplist menu entries exceeded."
751
 
                            "Cutting after %d entries.", i);
752
 
                break;
753
 
            }
754
 
        }
755
 
 
756
 
    update_menu:
757
 
        /* make sure the menu is well terminated */
758
 
        memset(&(flipmenu[drive][i]), 0, sizeof(ui_menu_entry_t));
759
 
 
760
 
        menuname = xmsprintf("LeftDrive%iMenu%i", drive + 8, name_count);
761
 
 
762
 
        /* ugly ... */
763
 
        if (drive == 0)
764
 
        {
765
 
            ui_destroy_drive8_menu();
766
 
            /* FIXME: Make sure the widget is really destroyed! */
767
 
            ui_set_drive8_menu(ui_menu_create(menuname /*"LeftDrive8Menu"*/,
768
 
                                              flipmenu[drive], NULL));
769
 
        }
770
 
        else
771
 
        {
772
 
            ui_destroy_drive9_menu();
773
 
            /* FIXME: Make sure the widget is really destroyed! */
774
 
            ui_set_drive9_menu(ui_menu_create(menuname /*"LeftDrive9Menu"*/,
775
 
                                              flipmenu[drive], NULL));
776
 
        }
777
 
 
778
 
        free(menuname);
779
 
 
780
 
        if (t0)
781
 
            free(t0);
782
 
        if (t1)
783
 
            free(t1);
784
 
        if (t2)
785
 
            free(t2);
786
 
        if (t3)
787
 
            free(t3);
788
 
        if (t4)
789
 
            free(t4);
790
 
        if (t5)
791
 
            free(t5);
792
 
        while (fliplist_start < i) {
793
 
            if (flipmenu[drive][fliplist_start].string)
794
 
                free(flipmenu[drive][fliplist_start].string);
795
 
            fliplist_start++;
 
309
    interrupt_maincpu_trigger_trap(save_snapshot_trap, (void *)fname);
 
310
}
 
311
 
 
312
static UI_CALLBACK(events_select_dir)
 
313
{
 
314
    char *wd;
 
315
    unsigned int i, is_dir;
 
316
    int len;
 
317
 
 
318
    len = ioutil_maxpathlen();
 
319
    wd = lib_malloc(len);
 
320
 
 
321
    ioutil_getcwd(wd, len);
 
322
    vsync_suspend_speed_eval();
 
323
    if (ui_input_string(_("VICE setting"),
 
324
                        _("Select history directory"),
 
325
                        wd, len) == UI_BUTTON_OK) {
 
326
        ioutil_stat(wd, &i, &is_dir);
 
327
        if (!is_dir)
 
328
            ui_error(_("Directory not found"));
 
329
        else
 
330
            resources_set_value("EventSnapshotDir", (resource_value_t)wd);
 
331
    }
 
332
    lib_free(wd);
 
333
    
 
334
}
 
335
 
 
336
static UI_CALLBACK(record_events_start)
 
337
{
 
338
    event_record_start();
 
339
}
 
340
 
 
341
static UI_CALLBACK(record_events_stop)
 
342
{
 
343
    event_record_stop();
 
344
}
 
345
 
 
346
static UI_CALLBACK(playback_events_start)
 
347
{
 
348
    event_playback_start();
 
349
}
 
350
 
 
351
static UI_CALLBACK(playback_events_stop)
 
352
{
 
353
    event_playback_stop();
 
354
}
 
355
 
 
356
static UI_CALLBACK(events_set_ms)
 
357
{
 
358
    event_record_set_milestone();
 
359
}
 
360
 
 
361
static UI_CALLBACK(events_return_ms)
 
362
{
 
363
    event_record_reset_milestone();
 
364
}
 
365
 
 
366
static UI_CALLBACK(sound_record)
 
367
{
 
368
    ui_button_t button;
 
369
    char *s;
 
370
    const char *devicename;
 
371
 
 
372
    vsync_suspend_speed_eval();
 
373
 
 
374
    resources_get_value("SoundRecordDeviceName",(void *) &devicename);
 
375
    if (devicename && !strcmp(devicename,"wav")) {
 
376
        /* the recording is active; stop it  */
 
377
        resources_set_value("SoundRecordDeviceName", "");
 
378
/*        ui_display_statustext("");*/
 
379
    } else {
 
380
        s = ui_select_file(_("Record sound to file"), NULL, 0, False, NULL,
 
381
                              "*.wav", &button, False, NULL);
 
382
        if (button == UI_BUTTON_OK && s != NULL) {
 
383
            util_add_extension(&s, "wav");
 
384
            resources_set_value("SoundRecordDeviceArg", s);
 
385
            resources_set_value("SoundRecordDeviceName", "wav");
 
386
            resources_set_value("Sound", (resource_value_t)1);
 
387
            lib_free(s);
 
388
/*            ui_display_statustext("Recording wav...");*/
796
389
        }
797
390
    }
798
391
}
799
392
 
800
393
/* ------------------------------------------------------------------------- */
801
394
 
802
 
static ui_menu_entry_t attach_empty_disk_image_submenu[] = {
803
 
    { N_("Unit #8..."),
804
 
      (ui_callback_t) attach_empty_disk, (ui_callback_data_t) 8, NULL, },
805
 
    { N_("Unit #9..."),
806
 
      (ui_callback_t) attach_empty_disk, (ui_callback_data_t) 9, NULL, },
807
 
    { N_("Unit #10..."),
808
 
      (ui_callback_t) attach_empty_disk, (ui_callback_data_t) 10, NULL, },
809
 
    { N_("Unit #11..."),
810
 
      (ui_callback_t) attach_empty_disk, (ui_callback_data_t) 11, NULL, },
811
 
    { NULL }
812
 
};
813
 
 
814
 
static ui_menu_entry_t attach_disk_image_submenu[] = {
815
 
    { N_("Unit #8..."),
816
 
      (ui_callback_t) attach_disk, (ui_callback_data_t) 8, NULL,
817
 
      XK_8, UI_HOTMOD_META },
818
 
    { N_("Unit #9..."),
819
 
      (ui_callback_t) attach_disk, (ui_callback_data_t) 9, NULL,
820
 
      XK_9, UI_HOTMOD_META },
821
 
    { N_("Unit #10..."),
822
 
      (ui_callback_t) attach_disk, (ui_callback_data_t) 10, NULL,
823
 
      XK_0, UI_HOTMOD_META },
824
 
    { N_("Unit #11..."),
825
 
      (ui_callback_t) attach_disk, (ui_callback_data_t) 11, NULL,
826
 
      XK_1, UI_HOTMOD_META },
827
 
    { NULL }
828
 
};
829
 
 
830
 
static ui_menu_entry_t detach_disk_image_submenu[] = {
831
 
    { N_("Unit #8"),
832
 
      (ui_callback_t) detach_disk, (ui_callback_data_t) 8, NULL },
833
 
    { N_("Unit #9"),
834
 
      (ui_callback_t) detach_disk, (ui_callback_data_t) 9, NULL },
835
 
    { N_("Unit #10"),
836
 
      (ui_callback_t) detach_disk, (ui_callback_data_t) 10, NULL },
837
 
    { N_("Unit #11"),
838
 
      (ui_callback_t) detach_disk, (ui_callback_data_t) 11, NULL },
839
 
    { "--" },
840
 
    { N_("All"),
841
 
      (ui_callback_t) detach_disk, (ui_callback_data_t) -1, NULL },
842
 
    { NULL }
843
 
};
844
 
 
845
395
static ui_menu_entry_t reset_submenu[] = {
846
396
    { N_("Soft"),
847
 
      (ui_callback_t) reset, NULL, NULL,
 
397
      (ui_callback_t)reset, NULL, NULL,
848
398
      XK_F9, UI_HOTMOD_META },
849
399
    { N_("Hard"),
850
 
      (ui_callback_t) powerup_reset, NULL, NULL,
 
400
      (ui_callback_t)powerup_reset, NULL, NULL,
851
401
      XK_F12, UI_HOTMOD_META },
852
 
    { NULL }
853
 
};
854
 
 
855
 
static ui_menu_entry_t flip_submenu[] = {
856
 
    { N_("Add current image"),
857
 
      (ui_callback_t) add2fliplist, (ui_callback_data_t) 0, NULL,
858
 
      XK_i, UI_HOTMOD_META },
859
 
    { N_("Remove current image"),
860
 
      (ui_callback_t) remove_from_fliplist, (ui_callback_data_t) 0, NULL,
861
 
      XK_k, UI_HOTMOD_META },
862
 
    { N_("Attach next image"),
863
 
      (ui_callback_t) attach_from_fliplist3, (ui_callback_data_t) 1, NULL,
864
 
      XK_n, UI_HOTMOD_META },
865
 
    { N_("Attach previous image"),
866
 
      (ui_callback_t) attach_from_fliplist3, (ui_callback_data_t) 0, NULL,
867
 
      XK_N, UI_HOTMOD_META },
868
 
    { NULL }
869
 
};
870
 
 
871
 
ui_menu_entry_t ui_disk_commands_menu[] = {
872
 
    { N_("Attach a disk image"),
873
 
      NULL, NULL, attach_disk_image_submenu },
874
 
    { N_("Create and attach an empty disk"),
875
 
      NULL, NULL, attach_empty_disk_image_submenu },
876
 
    { N_("Detach disk image"),
877
 
      NULL, NULL, detach_disk_image_submenu },
878
 
    { N_("Fliplist for drive #8"),
879
 
      NULL, NULL, flip_submenu },
880
 
    { NULL }
881
 
};
882
 
 
883
 
ui_menu_entry_t ui_tape_commands_menu[] = {
884
 
    { N_("Attach a tape image..."),
885
 
      (ui_callback_t) attach_tape, NULL, NULL,
886
 
      XK_t, UI_HOTMOD_META},
887
 
    { N_("Detach tape image"),
888
 
      (ui_callback_t) detach_tape, NULL, NULL },
889
 
    { NULL }
890
 
};
891
 
 
892
 
ui_menu_entry_t ui_smart_attach_commands_menu[] = {
893
 
    { N_("Smart-attach disk/tape..."),
894
 
      (ui_callback_t) smart_attach, NULL, NULL,
895
 
      XK_a, UI_HOTMOD_META },
 
402
    { "--" },
 
403
    { N_("Unit #8"),
 
404
      (ui_callback_t)drive_reset, (ui_callback_data_t)0, NULL },
 
405
    { N_("Unit #9"),
 
406
      (ui_callback_t)drive_reset, (ui_callback_data_t)1, NULL },
 
407
    { N_("Unit #10"),
 
408
      (ui_callback_t)drive_reset, (ui_callback_data_t)2, NULL },
 
409
    { N_("Unit #11"),
 
410
      (ui_callback_t)drive_reset, (ui_callback_data_t)3, NULL },
896
411
    { NULL }
897
412
};
898
413
 
899
414
ui_menu_entry_t ui_directory_commands_menu[] = {
900
415
    { N_("Change working directory..."),
901
 
      (ui_callback_t) change_working_directory, NULL, NULL },
 
416
      (ui_callback_t)change_working_directory, NULL, NULL },
 
417
    { NULL }
 
418
};
 
419
 
 
420
UI_MENU_DEFINE_RADIO(EventStartMode)
 
421
 
 
422
static ui_menu_entry_t set_event_start_mode_submenu[] = {
 
423
    { N_("*Save new snapshot"), (ui_callback_t)radio_EventStartMode,
 
424
      (ui_callback_data_t)EVENT_START_MODE_FILE_SAVE, NULL },
 
425
    { N_("*Load existing snapshot"), (ui_callback_t)radio_EventStartMode,
 
426
      (ui_callback_data_t)EVENT_START_MODE_FILE_LOAD, NULL },
 
427
    { N_("*Start with reset"), (ui_callback_t)radio_EventStartMode,
 
428
      (ui_callback_data_t)EVENT_START_MODE_RESET, NULL },
 
429
    { N_("*Overwrite running playback"), (ui_callback_t)radio_EventStartMode,
 
430
      (ui_callback_data_t)EVENT_START_MODE_PLAYBACK, NULL },
902
431
    { NULL }
903
432
};
904
433
 
905
434
ui_menu_entry_t ui_snapshot_commands_submenu[] = {
906
435
    { N_("Load snapshot..."),
907
 
      (ui_callback_t) load_snapshot, NULL, NULL,
 
436
      (ui_callback_t)load_snapshot, NULL, NULL,
908
437
      XK_l, UI_HOTMOD_META },
909
438
    { N_("Save snapshot..."),
910
 
      (ui_callback_t) save_snapshot, NULL, NULL,
 
439
      (ui_callback_t)save_snapshot, NULL, NULL,
911
440
      XK_s, UI_HOTMOD_META },
912
441
    { "--" },
913
442
    { N_("Quickload snapshot"),
914
 
      (ui_callback_t) load_quicksnap, NULL, NULL,
 
443
      (ui_callback_t)load_quicksnap, NULL, NULL,
915
444
      XK_F10, UI_HOTMOD_META },
916
445
    { N_("Quicksave snapshot"),
917
 
      (ui_callback_t) save_quicksnap, NULL, NULL,
 
446
      (ui_callback_t)save_quicksnap, NULL, NULL,
918
447
      XK_F11, UI_HOTMOD_META },
 
448
    { "--" },
 
449
    { N_("Select history directory"),
 
450
      (ui_callback_t)events_select_dir, NULL, NULL },
 
451
    { N_("Start recording events"),
 
452
      (ui_callback_t)record_events_start, NULL, NULL },
 
453
    { N_("Stop recording events"),
 
454
      (ui_callback_t)record_events_stop, NULL, NULL },
 
455
    { N_("Start playing back events"),
 
456
      (ui_callback_t)playback_events_start, NULL, NULL },
 
457
    { N_("Stop playing back events"),
 
458
      (ui_callback_t)playback_events_stop, NULL, NULL },
 
459
    { N_("Set recording milestone"),
 
460
      (ui_callback_t)events_set_ms, NULL, NULL, XK_e, UI_HOTMOD_META },
 
461
    { N_("Return to milestone"),
 
462
      (ui_callback_t)events_return_ms, NULL, NULL, XK_u, UI_HOTMOD_META },
 
463
    { "--" },
 
464
    { N_("Recording start mode"),
 
465
      NULL, NULL, set_event_start_mode_submenu },
919
466
    { NULL }
920
467
};
921
468
 
925
472
    { NULL }
926
473
};
927
474
 
 
475
ui_menu_entry_t ui_sound_record_commands_menu[] = {
 
476
    { N_("Sound record..."),
 
477
      (ui_callback_t)sound_record, NULL, NULL,
 
478
      XK_r, UI_HOTMOD_META },
 
479
    { NULL }
 
480
};
 
481
 
928
482
ui_menu_entry_t ui_tool_commands_menu[] = {
929
483
    { N_("Activate monitor"),
930
 
      (ui_callback_t) activate_monitor, NULL, NULL },
 
484
      (ui_callback_t)activate_monitor, NULL, NULL,
 
485
      XK_h, UI_HOTMOD_META },
931
486
    { N_("Run C1541"),
932
 
      (ui_callback_t) run_c1541, NULL, NULL },
 
487
      (ui_callback_t)run_c1541, NULL, NULL },
933
488
    { NULL }
934
489
};
935
490
 
937
492
 
938
493
ui_menu_entry_t ui_help_commands_menu[] = {
939
494
    { N_("Browse manuals"),
940
 
      (ui_callback_t) browse_manual, NULL, NULL },
 
495
      (ui_callback_t)browse_manual, NULL, NULL },
941
496
    { N_("About VICE..."),
942
 
      (ui_callback_t) ui_about, NULL, NULL },
 
497
      (ui_callback_t)ui_about, NULL, NULL },
943
498
    { NULL }
944
499
};
945
500
 
947
502
    { N_("Reset"),
948
503
      NULL, NULL, reset_submenu },
949
504
    { N_("*Pause"),
950
 
      (ui_callback_t) toggle_pause, NULL, NULL,
 
505
      (ui_callback_t)toggle_pause, NULL, NULL,
951
506
      XK_p, UI_HOTMOD_META },
952
507
    { NULL }
953
508
};
954
509
 
955
510
ui_menu_entry_t ui_exit_commands_menu[] = {
956
511
    { N_("Exit emulator"),
957
 
      (ui_callback_t) do_exit, NULL, NULL,
 
512
      (ui_callback_t)do_exit, NULL, NULL,
958
513
      XK_q, UI_HOTMOD_META },
959
514
    { NULL }
960
515
};
961
516
 
 
517
void uicommands_shutdown(void)
 
518
{
 
519
    lib_free(load_snapshot_last_dir);
 
520
}
 
521