1 /* Copyright (C) 1996-1997 Aleksey Volynskov
2 * Copyright (C) 2011 Rambo
3 * Copyright (C) 2020 SovietPony
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, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "map.h" // MAP_load
28 #include "common/streams.h"
29 #include "common/files.h"
30 #include "common/wadres.h"
31 #include "common/cp866.h"
34 static int m_start
, m_end
;
35 static int s_start
, s_end
;
37 void F_startup (void) {
38 logo("F_startup: setup file system\n");
41 void F_addwad (const char *fn
) {
43 static FILE_Stream wadh
[MAX_WADS
];
45 if (FILE_Open(&wadh
[i
], fn
, "rb")) {
46 if (WADRES_addwad(&wadh
[i
].base
)) {
49 ERR_failinit("Invalid WAD %s", fn
);
52 ERR_failinit("Unable to add WAD %s", fn
);
55 ERR_failinit("Too many wads");
59 void F_initwads (void) {
60 if (!WADRES_rehash()) {
61 ERR_failinit("F_initwads: failed rehash");
65 void F_allocres (void) {
66 d_start
= F_getresid("D_START");
67 d_end
= F_getresid("D_END");
68 m_start
= F_getresid("M_START");
69 m_end
= F_getresid("M_END");
70 s_start
= F_getresid("S_START");
71 s_end
= F_getresid("S_END");
74 void F_loadres (int r
, void *p
) {
78 int F_findres (const char n
[8]) {
79 return WADRES_find(n
);
82 int F_getresid (const char n
[8]) {
85 ERR_fatal("F_getresid: resource %.8s not found", n
);
90 void F_getresname (char n
[8], int r
) {
94 int F_getsprid (const char n
[4], int s
, int d
, char *dir
) {
97 for (int i
= s_start
+ 1; i
< s_end
; i
++) {
100 WADRES_getname(i
, wn
);
101 if (cp866_strncasecmp(wn
, n
, 4) == 0 && (wn
[4] == s
|| wn
[6] == s
)) {
102 a
= wn
[4] == s
? wn
[5] : 0;
103 b
= wn
[6] == s
? wn
[7] : 0;
104 if (a
== '0' || b
== '0' || a
== d
|| b
== d
) {
106 *dir
= (a
!= '0' && b
== '0') || (a
!= d
&& b
== d
);
112 ERR_fatal("F_getsprid: image %.4s%c%c not found", n
, s
, d
);
116 int F_getreslen (int r
) {
117 return WADRES_getsize(r
);
120 void F_nextmus (char *s
) {
121 int i
= F_findres(s
);
122 if (i
<= m_start
|| i
>= m_end
) {
129 WADRES_getname(i
, s
);
130 if (cp866_strcasecmp(s
, "MENU") == 0 ||
131 cp866_strcasecmp(s
, "INTERMUS") == 0 ||
132 cp866_strcasecmp(s
, "\x8a\x8e\x8d\x85\x96\x0") == 0) {
135 if (cp866_strncasecmp(s
, "DMI", 3) != 0) {
141 void F_randmus (char *s
) {
144 for (i
= 0; i
< n
; i
++) {
149 void F_loadmap (char n
[8]) {
150 int id
= F_getresid(n
);
152 Stream
*r
= WADRES_getbasereader(id
);
153 long offset
= WADRES_getoffset(id
);
154 stream_setpos(r
, offset
);
156 ERR_fatal("Failed to load map");
159 ERR_fatal("Failed to load map: resource %.8s not found", n
);