2 * Copyright (C) 1996-1998 Szeredi Miklos
3 * Email: mszeredi@inf.bme.hu
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. See the file COPYING.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 #include "snapshot.h" /* for SN_Z80 and SN_SNA */
31 #include "tapefile.h" /* for TAP_TAP and TAP_TZX */
36 extern const char *spcf_keynames_ascii
[];
37 extern const char *spcf_keynames_misc
[];
39 char *spcf_init_snapshot
= NULL
;
40 int spcf_init_snapshot_type
;
41 char *spcf_init_tapefile
= NULL
;
42 int spcf_init_tapefile_type
;
45 static int file_type
= -1;
46 static int file_subtype
;
54 static struct ext_type extensions
[] = {
55 {"z80", FT_SNAPSHOT
, SN_Z80
},
56 {"sna", FT_SNAPSHOT
, SN_SNA
},
57 {"tzx", FT_TAPEFILE
, TAP_TZX
},
58 {"tap", FT_TAPEFILE
, TAP_TAP
},
63 int spcf_find_file_type(char *filename
, int *ftp
, int *ftsubp
)
68 if(*ftp
>= 0 && *ftsubp
>= 0) return 1;
72 for(i
= 0; extensions
[i
].ext
!= NULL
; i
++)
73 if((*ftp
< 0 || *ftp
== extensions
[i
].type
) &&
74 (*ftsubp
< 0 || *ftsubp
== extensions
[i
].subtype
) &&
75 check_ext(filename
, extensions
[i
].ext
)) {
77 *ftp
= extensions
[i
].type
;
78 *ftsubp
= extensions
[i
].subtype
;
82 if(!found
) for(i
= 0; extensions
[i
].ext
!= NULL
; i
++)
83 if((*ftp
< 0 || *ftp
== extensions
[i
].type
) &&
84 (*ftsubp
< 0 || *ftsubp
== extensions
[i
].subtype
) &&
85 try_extension(filename
, extensions
[i
].ext
)) {
87 *ftp
= extensions
[i
].type
;
88 *ftsubp
= extensions
[i
].subtype
;
95 static int find_extension(const char *ext
)
98 for(i
= 0; extensions
[i
].ext
!= NULL
; i
++)
99 if(rb
->strcasecmp(extensions
[i
].ext
, ext
) == 0) return i
;
105 /* now actually a snapshot/tape loader*/
106 void spcf_read_command_line(const void* parameter
)
110 ix
= find_extension( parameter
- 3 + rb
->strlen (parameter
) );
112 file_type
= extensions
[ix
].type
;
113 file_subtype
= extensions
[ix
].subtype
;
114 rb
->strlcpy(filenamebuf
, parameter
, MAXFILENAME
- 10 + 1);
115 if(file_type
< 0) file_subtype
= -1;
116 if(!spcf_find_file_type(filenamebuf
, &file_type
, &file_subtype
))
119 if(file_type
== FT_SNAPSHOT
) {
120 spcf_init_snapshot
= make_string(spcf_init_snapshot
, filenamebuf
);
121 spcf_init_snapshot_type
= file_subtype
;
123 else if(file_type
== FT_TAPEFILE
) {
124 spcf_init_tapefile
= make_string(spcf_init_tapefile
, filenamebuf
);
125 spcf_init_tapefile_type
= file_subtype
;