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

« back to all changes in this revision

Viewing changes to src/arch/sdl/archdep_amiga.c

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2010-02-11 18:30:16 UTC
  • mfrom: (1.1.8 upstream) (9.2.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100211183016-f6n8usn3tzp0u6dp
Tags: 2.2.dfsg-1
* New upstream release, C64 DTV is included so update package description
  and add it to the menu.
* Drop patch fixing build failure with gcc-4.4 , applied upstream.
* Fix some lintian problems and clean up debian/rules .

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * archdep_amiga.c
 
3
 *
 
4
 * Written by
 
5
 *  Mathias Roslund <vice.emu@amidog.se>
 
6
 *
 
7
 * This file is part of VICE, the Versatile Commodore Emulator.
 
8
 * See README for copyright notice.
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program; if not, write to the Free Software
 
22
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
23
 *  02111-1307  USA.
 
24
 *
 
25
 */
 
26
 
 
27
#include "vice.h"
 
28
 
 
29
#ifndef __VBCC__
 
30
#define __USE_INLINE__
 
31
#endif
 
32
 
 
33
#include <proto/dos.h>
 
34
 
 
35
#include <stdarg.h>
 
36
#include <stdio.h>
 
37
#include <stdlib.h>
 
38
#include <string.h>
 
39
#include <strings.h>
 
40
#include <ctype.h>
 
41
#include <errno.h>
 
42
#include <signal.h>
 
43
#include <sys/stat.h>
 
44
#include <unistd.h>
 
45
 
 
46
#include "archdep.h"
 
47
#include "findpath.h"
 
48
#include "ioutil.h"
 
49
#include "lib.h"
 
50
#include "log.h"
 
51
#include "machine.h"
 
52
#include "ui.h"
 
53
#include "util.h"
 
54
 
 
55
static char *boot_path = NULL;
 
56
static int run_from_wb = 0;
 
57
 
 
58
#ifndef AMIGA_OS4
 
59
struct Library *SocketBase;
 
60
#endif
 
61
 
 
62
int archdep_network_init(void)
 
63
{
 
64
#ifndef AMIGA_OS4
 
65
    if (SocketBase == NULL) {
 
66
        SocketBase = OpenLibrary("bsdsocket.library", 3);
 
67
        if (SocketBase == NULL) {
 
68
            return -1;
 
69
        }
 
70
    }
 
71
#endif
 
72
 
 
73
    return 0;
 
74
}
 
75
 
 
76
void archdep_network_shutdown(void)
 
77
{
 
78
#ifndef AMIGA_OS4
 
79
    if (SocketBase != NULL) {
 
80
        CloseLibrary(SocketBase);
 
81
        SocketBase = NULL;
 
82
    }
 
83
#endif
 
84
}
 
85
 
 
86
int archdep_init_extra(int *argc, char **argv)
 
87
{
 
88
    if (*argc == 0) { /* run from WB */
 
89
        run_from_wb = 1;
 
90
    } else { /* run from CLI */
 
91
        run_from_wb = 0;
 
92
    }
 
93
 
 
94
    return 0;
 
95
}
 
96
 
 
97
char *archdep_program_name(void)
 
98
{
 
99
    static char *program_name = NULL;
 
100
 
 
101
    if (program_name == NULL) {
 
102
        char *p, name[1024];
 
103
 
 
104
        GetProgramName(name, 1024);
 
105
        p = FilePart(name);
 
106
 
 
107
        if (p != NULL) {
 
108
            program_name = lib_stralloc(p);
 
109
        }
 
110
    }
 
111
 
 
112
    return program_name;
 
113
}
 
114
 
 
115
const char *archdep_boot_path(void)
 
116
{
 
117
    return "PROGDIR:";
 
118
}
 
119
 
 
120
char *archdep_default_sysfile_pathlist(const char *emu_id)
 
121
{
 
122
    static char *default_path;
 
123
 
 
124
    if (default_path == NULL) {
 
125
        const char *boot_path;
 
126
 
 
127
        boot_path = archdep_boot_path();
 
128
 
 
129
        default_path = util_concat(emu_id, ARCHDEP_FINDPATH_SEPARATOR_STRING,
 
130
                                   boot_path, emu_id, ARCHDEP_FINDPATH_SEPARATOR_STRING,
 
131
                                   "DRIVES", ARCHDEP_FINDPATH_SEPARATOR_STRING,
 
132
                                   boot_path, "DRIVES", ARCHDEP_FINDPATH_SEPARATOR_STRING,
 
133
                                   "PRINTER", ARCHDEP_FINDPATH_SEPARATOR_STRING,
 
134
                                   boot_path, "PRINTER", NULL);
 
135
    }
 
136
 
 
137
    return default_path;
 
138
}
 
139
 
 
140
/* Return a malloc'ed backup file name for file `fname'.  */
 
141
char *archdep_make_backup_filename(const char *fname)
 
142
{
 
143
    return util_concat(fname, "~", NULL);
 
144
}
 
145
 
 
146
char *archdep_default_resource_file_name(void)
 
147
{
 
148
    const char *home;
 
149
 
 
150
    home = archdep_boot_path();
 
151
    return util_concat(home, "vice-sdl.ini", NULL);
 
152
}
 
153
 
 
154
char *archdep_default_fliplist_file_name(void)
 
155
{
 
156
    const char *home;
 
157
 
 
158
    home = archdep_boot_path();
 
159
    return util_concat(home, "fliplist-", machine_name, ".vfl", NULL);
 
160
}
 
161
 
 
162
char *archdep_default_autostart_disk_image_file_name(void)
 
163
{
 
164
    const char *home;
 
165
 
 
166
    home = archdep_boot_path();
 
167
    return util_concat(home, "autostart-", machine_name, ".d64", NULL);
 
168
}
 
169
 
 
170
char *archdep_default_hotkey_file_name(void)
 
171
{
 
172
    const char *home;
 
173
 
 
174
    home = archdep_boot_path();
 
175
    return util_concat(home, "sdl-hotkey-", machine_name, ".vkm", NULL);
 
176
}
 
177
 
 
178
char *archdep_default_joymap_file_name(void)
 
179
{
 
180
    const char *home;
 
181
 
 
182
    home = archdep_boot_path();
 
183
    return util_concat(home, "sdl-joymap-", machine_name, ".vjm", NULL);
 
184
}
 
185
 
 
186
char *archdep_default_save_resource_file_name(void)
 
187
{
 
188
    return archdep_default_resource_file_name();
 
189
}
 
190
 
 
191
FILE *archdep_open_default_log_file(void)
 
192
{
 
193
    if (run_from_wb) {
 
194
        char *fname;
 
195
        FILE *f;
 
196
 
 
197
        fname = util_concat(archdep_boot_path(), "vice.log", NULL);
 
198
        f = fopen(fname, MODE_WRITE_TEXT);
 
199
        lib_free(fname);
 
200
 
 
201
        return f;
 
202
    } else {
 
203
        return stdout;
 
204
    }
 
205
}
 
206
 
 
207
int archdep_num_text_lines(void)
 
208
{
 
209
    return 25;
 
210
}
 
211
 
 
212
int archdep_num_text_columns(void)
 
213
{
 
214
    return 80;
 
215
}
 
216
 
 
217
int archdep_default_logger(const char *level_string, const char *txt)
 
218
{
 
219
    if (run_from_wb) {
 
220
        return 0;
 
221
    }
 
222
 
 
223
    if (fputs(level_string, stdout) == EOF || fprintf(stdout, txt) < 0 || fputc ('\n', stdout) == EOF) {
 
224
        return -1;
 
225
    }
 
226
 
 
227
    return 0;
 
228
}
 
229
 
 
230
int archdep_path_is_relative(const char *path)
 
231
{
 
232
    if (path == NULL) {
 
233
        return 0;
 
234
    }
 
235
 
 
236
    return (strchr(path, ':') == NULL);
 
237
}
 
238
 
 
239
int archdep_spawn(const char *name, char **argv, char **stdout_redir, const char *stderr_redir)
 
240
{
 
241
    return -1;
 
242
}
 
243
 
 
244
/* return malloc'd version of full pathname of orig_name */
 
245
int archdep_expand_path(char **return_path, const char *orig_name)
 
246
{
 
247
    BPTR lock;
 
248
 
 
249
    lock = Lock(orig_name, ACCESS_READ);
 
250
    if (lock) {
 
251
        char name[1024];
 
252
        LONG rc;
 
253
        rc = NameFromLock(lock, name, 1024);
 
254
        UnLock(lock);
 
255
        if (rc) {
 
256
            *return_path = lib_stralloc(name);
 
257
            return 0;
 
258
        }
 
259
    }
 
260
    *return_path = lib_stralloc(orig_name);
 
261
    return 0;
 
262
}
 
263
 
 
264
void archdep_startup_log_error(const char *format, ...)
 
265
{
 
266
    va_list ap;
 
267
    va_start(ap, format);
 
268
    vfprintf(stderr, format, ap);
 
269
    va_end(ap);
 
270
}
 
271
 
 
272
char *archdep_filename_parameter(const char *name)
 
273
{
 
274
    return lib_stralloc(name);
 
275
}
 
276
 
 
277
char *archdep_quote_parameter(const char *name)
 
278
{
 
279
    return lib_stralloc(name);
 
280
}
 
281
 
 
282
char *archdep_tmpnam(void)
 
283
{
 
284
    return lib_stralloc(tmpnam(NULL));
 
285
}
 
286
 
 
287
FILE *archdep_mkstemp_fd(char **filename, const char *mode)
 
288
{
 
289
    char *tmp;
 
290
    FILE *fd;
 
291
 
 
292
    tmp = lib_stralloc(tmpnam(NULL));
 
293
 
 
294
    fd = fopen(tmp, mode);
 
295
 
 
296
    if (fd == NULL) {
 
297
        return NULL;
 
298
    }
 
299
 
 
300
    *filename = tmp;
 
301
 
 
302
    return fd;
 
303
}
 
304
 
 
305
int archdep_file_is_gzip(const char *name)
 
306
{
 
307
    size_t l = strlen(name);
 
308
 
 
309
    if ((l < 4 || strcasecmp(name + l - 3, ".gz")) && (l < 3 || strcasecmp(name + l - 2, ".z")) && (l < 4 || toupper(name[l - 1]) != 'Z' || name[l - 4] != '.')) {
 
310
        return 0;
 
311
    }
 
312
 
 
313
    return 1;
 
314
}
 
315
 
 
316
int archdep_file_set_gzip(const char *name)
 
317
{
 
318
    return 0;
 
319
}
 
320
 
 
321
int archdep_mkdir(const char *pathname, int mode)
 
322
{
 
323
    return mkdir(pathname, (mode_t)mode);
 
324
}
 
325
 
 
326
int archdep_stat(const char *file_name, unsigned int *len, unsigned int *isdir)
 
327
{
 
328
    struct stat statbuf;
 
329
 
 
330
    if (stat(file_name, &statbuf) < 0) {
 
331
        return -1;
 
332
    }
 
333
 
 
334
    *len = statbuf.st_size;
 
335
    *isdir = S_ISDIR(statbuf.st_mode);
 
336
 
 
337
    return 0;
 
338
}
 
339
 
 
340
int archdep_file_is_blockdev(const char *name)
 
341
{
 
342
    return 0;
 
343
}
 
344
 
 
345
int archdep_file_is_chardev(const char *name)
 
346
{
 
347
    return 0;
 
348
}
 
349
 
 
350
int archdep_require_vkbd(void)
 
351
{
 
352
    return 0;
 
353
}
 
354
 
 
355
void archdep_shutdown_extra(void)
 
356
{
 
357
    lib_free(boot_path);
 
358
}