~ubuntu-branches/ubuntu/maverick/vice/maverick

« back to all changes in this revision

Viewing changes to src/arch/win32/uiquicksnapshot.c

  • Committer: Bazaar Package Importer
  • Author(s): Zed Pobre
  • Date: 2005-02-01 11:30:26 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050201113026-3eyakzsmmheclvjg
Tags: 1.16-1
* New upstream version
* Fixes crash on 64-bit architectures (closes: #287640)
* x128 working again (closes: #286767)
* Works fine with /dev/dsp in use (not in the main changelog, but tested
  on my local machine as working).  Presumably, this also takes care of
  the issue with dsp being held.  I'm not sure if this is because I'm
  testing it on a 2.6 kernel now -- if you are still having problems
  with /dev/dsp, please reopen the bugs. (closes: #152952, #207942)
* Don't kill Makefile.in on clean

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * uiquicksnapshot.c
 
3
 *
 
4
 * Written by
 
5
 *  Tibor Biczo <crown@mail.matav.hu>
 
6
 *  Andreas Boose <viceteam@t-online.de>
 
7
 *
 
8
 * This file is part of VICE, the Versatile Commodore Emulator.
 
9
 * See README for copyright notice.
 
10
 *
 
11
 *  This program is free software; you can redistribute it and/or modify
 
12
 *  it under the terms of the GNU General Public License as published by
 
13
 *  the Free Software Foundation; either version 2 of the License, or
 
14
 *  (at your option) any later version.
 
15
 *
 
16
 *  This program is distributed in the hope that it will be useful,
 
17
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 *  GNU General Public License for more details.
 
20
 *
 
21
 *  You should have received a copy of the GNU General Public License
 
22
 *  along with this program; if not, write to the Free Software
 
23
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
24
 *  02111-1307  USA.
 
25
 *
 
26
 */
 
27
 
 
28
#include "vice.h"
 
29
 
 
30
#include <stdio.h>
 
31
#include <windows.h>
 
32
#include <tchar.h>
 
33
 
 
34
#include "archdep.h"
 
35
#include "interrupt.h"
 
36
#include "lib.h"
 
37
#include "machine.h"
 
38
#include "system.h"
 
39
#include "ui.h"
 
40
#include "uiquicksnapshot.h"
 
41
#include "util.h"
 
42
 
 
43
 
 
44
typedef struct {
 
45
    char name[MAX_PATH];
 
46
    int valid;
 
47
} snapfiles;
 
48
 
 
49
 
 
50
static snapfiles files[10];
 
51
static int lastindex;
 
52
static int snapcounter;
 
53
 
 
54
 
 
55
static void scan_files(void)
 
56
{
 
57
    WIN32_FIND_DATA file_info;
 
58
    HANDLE search_handle;
 
59
    int i;
 
60
    char *dirname;
 
61
    TCHAR *st_dirname;
 
62
 
 
63
    dirname = util_concat(archdep_boot_path(), "\\", machine_name,
 
64
                          "\\quicksnap?.vsf", NULL);
 
65
    st_dirname = system_mbstowcs_alloc(dirname);
 
66
    search_handle = FindFirstFile(st_dirname, &file_info);
 
67
    system_mbstowcs_free(st_dirname);
 
68
    snapcounter = 0;
 
69
    lastindex = -1;
 
70
    for (i = 0; i < 10; i++) {
 
71
        files[i].valid = 0;
 
72
    }
 
73
    if (search_handle != INVALID_HANDLE_VALUE) {
 
74
        do {
 
75
            TCHAR c;
 
76
            c = file_info.cFileName[_tcslen(file_info.cFileName) - 5];
 
77
            if ((c >= '0') && (c <= '9')) {
 
78
                strcpy(files[c - '0'].name, file_info.cFileName);
 
79
                files[c - '0'].valid = 1;
 
80
                if ((c - '0') > lastindex) {
 
81
                    lastindex = c - '0';
 
82
                }
 
83
                snapcounter++;
 
84
            }
 
85
        } while (FindNextFile(search_handle, &file_info));
 
86
        FindClose(search_handle);
 
87
    }
 
88
    lib_free(dirname);
 
89
}
 
90
 
 
91
static void save_quicksnapshot_trap(WORD unused_addr, void *unused_data)
 
92
{
 
93
    int i, j;
 
94
    char *fullname, *fullname2;
 
95
    TCHAR *st_fullname, *st_fullname2;
 
96
 
 
97
    if (lastindex == -1) {
 
98
        lastindex = 0;
 
99
        strcpy(files[lastindex].name, "quicksnap0.vsf");
 
100
    } else {
 
101
        if (lastindex == 9) {
 
102
            if (snapcounter == 10) {
 
103
                fullname = util_concat(archdep_boot_path(), "\\", machine_name,
 
104
                                       "\\", files[0].name, NULL);
 
105
                st_fullname = system_mbstowcs_alloc(fullname);
 
106
                DeleteFile(st_fullname);
 
107
                system_mbstowcs_free(st_fullname);
 
108
                lib_free(fullname);
 
109
                for (i = 1; i < 10; i++) {
 
110
                    fullname = util_concat(archdep_boot_path(), "\\",
 
111
                                           machine_name,
 
112
                                           "\\", files[i].name, NULL);
 
113
                    fullname2 = util_concat(archdep_boot_path(), "\\",
 
114
                                            machine_name,
 
115
                                            "\\", files[i-1].name, NULL);
 
116
                    st_fullname = system_mbstowcs_alloc(fullname);
 
117
                    st_fullname2 = system_mbstowcs_alloc(fullname2);
 
118
                    MoveFile(st_fullname, st_fullname2);
 
119
                    system_mbstowcs_free(st_fullname);
 
120
                    system_mbstowcs_free(st_fullname2);
 
121
                    lib_free(fullname);
 
122
                    lib_free(fullname2);
 
123
                }
 
124
            } else {
 
125
                for (i = 0; i < 10; i++) {
 
126
                    if (files[i].valid == 0) break;
 
127
                }
 
128
                for (j = i + 1; j < 10; j++) {
 
129
                    if (files[j].valid) {
 
130
                        strcpy(files[i].name,files[j].name);
 
131
                        files[i].name[strlen(files[i].name) - 5] = '0' + i;
 
132
                        fullname = util_concat(archdep_boot_path(), "\\",
 
133
                                               machine_name, "\\",
 
134
                                               files[j].name, NULL);
 
135
                        fullname2 = util_concat(archdep_boot_path(), "\\",
 
136
                                                machine_name, "\\",
 
137
                                                files[i].name, NULL);
 
138
                        st_fullname = system_mbstowcs_alloc(fullname);
 
139
                        st_fullname2 = system_mbstowcs_alloc(fullname2);
 
140
                        MoveFile(st_fullname, st_fullname2);
 
141
                        system_mbstowcs_free(st_fullname);
 
142
                        system_mbstowcs_free(st_fullname2);
 
143
                        lib_free(fullname);
 
144
                        lib_free(fullname2);
 
145
                        i++;
 
146
                    }
 
147
                }
 
148
                strcpy(files[i].name,files[0].name);
 
149
                files[i].name[strlen(files[i].name) - 5]= '0' + i;
 
150
                lastindex = i;
 
151
            }
 
152
        } else {
 
153
            strcpy(files[lastindex + 1].name,files[lastindex].name);
 
154
            lastindex++;
 
155
            files[lastindex].name[strlen(files[lastindex].name) - 5]
 
156
                = '0' + lastindex;
 
157
        }
 
158
    }
 
159
 
 
160
    fullname = util_concat(archdep_boot_path(), "\\", machine_name, "\\",
 
161
                      files[lastindex].name, NULL);
 
162
    if (machine_write_snapshot(fullname, 0, 0, 0) < 0) {
 
163
        ui_error("Can't write snapshot file.");
 
164
    }
 
165
    lib_free(fullname);
 
166
}
 
167
 
 
168
static void load_quicksnapshot_trap(WORD unused_addr, void *unused_data)
 
169
{
 
170
    char *fullname;
 
171
 
 
172
    fullname = util_concat(archdep_boot_path(), "\\", machine_name, "\\",
 
173
                           files[lastindex].name, NULL);
 
174
    if (machine_read_snapshot(fullname, 0) < 0) {
 
175
        ui_error("Cannot read snapshot image");
 
176
    }
 
177
    lib_free(fullname);
 
178
}
 
179
 
 
180
void ui_quicksnapshot_load(HWND hwnd)
 
181
{
 
182
    scan_files();
 
183
    if (snapcounter > 0) {
 
184
        interrupt_maincpu_trigger_trap(load_quicksnapshot_trap, (void *)0);
 
185
    }
 
186
}
 
187
 
 
188
void ui_quicksnapshot_save(HWND hwnd)
 
189
{
 
190
    scan_files();
 
191
    interrupt_maincpu_trigger_trap(save_quicksnapshot_trap, (void *)0);
 
192
}
 
193