Debian Codegraph @

terps/scott/saga/atari8detect.c

raw symbols SCIP
1 //
2 // atari8detect.c
3 // Part of ScottFree, an interpreter for adventures in Scott Adams format
4 //
5 // Created by Petter Sjölund on 2022-01-30.
6 //
7
8 #include <ctype.h>
9 #include <stdbool.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include "hulk.h"
14 #include "saga.h"
15 #include "sagagraphics.h"
16 #include "scott.h"
17 #include "scottdefines.h"
18
19 #include "atari8c64draw.h"
20 #include "atari8detect.h"
21 #include "scottgameinfo.h"
22
23 static const pairrec a8companionlist[][2] = {
24 { { 0x16810, 0xa972, "S.A.G.A. 01 - Adventureland v5.0-416 (1982)(Adventure International)(US)(Side A)[!].atr", 87 }, { 0x16810, 0x8be3, "S.A.G.A. 01 - Adventureland v5.0-416 (1982)(Adventure International)(US)(Side B)[!][cr CSS].atr", 95 } },
25 { { 0x16810, 0x65a1, "S.A.G.A. 02 - Pirate Adventure v5.0-408 (1982)(Adventure International)(US)(Side A)[f][m].atr", 93 }, { 0x16810, 0x5750, "S.A.G.A. 02 - Pirate Adventure v5.0-408 (1982)(Adventure International)(US)(Side B)[cr CSS].atr", 95 } },
26 { { 0x16810, 0x3074, "S.A.G.A. 02 - Pirate Adventure v5.0-408 (1982)(Adventure International)(US)(Side A)[f][a].atr", 93 }, { 0x16810, 0x2429, "S.A.G.A. 02 - Pirate Adventure v5.0-408 (1982)(Adventure International)(US)(Side B)[a][cr CSS].atr", 98 } },
27 { { 0x16810, 0x4389, "S.A.G.A. 04 - Voodoo Castle v5.1-119 (1983)(Adventure International)(US)(Disk 1 of 2)[!].atr", 92 }, { 0x16810, 0x234f, "S.A.G.A. 04 - Voodoo Castle v5.1-119 (1983)(Adventure International)(US)(Disk 2 of 2)[!][cr CSS].atr", 100 } },
28 { { 0x16810, 0xc2f5, "S.A.G.A. 05 - The Count v5.1-115 (1983)(Adventure International)(US)(Side A)[!].atr", 83 }, { 0x16810, 0x3ebb, "S.A.G.A. 05 - The Count v5.1-115 (1983)(Adventure International)(US)(Side B)[!][cr CSS].atr", 91 } },
29 { { 0x16810, 0x6ee8, "S.A.G.A. 13 - The Sorcerer of Claymorgue Castle v5.1-125 (1983)(Adventure International)(US)(Disk 1 of 2)[!][cr CSS].atr", 120 }, { 0x16810, 0xac42, "S.A.G.A. 13 - The Sorcerer of Claymorgue Castle v5.1-125 (1983)(Adventure International)(US)(Disk 2 of 2)[f][!].atr", 115 } },
30 { { 0x16810, 0x1de8, "S.A.G.A. 13 - The Sorcerer of Claymorgue Castle v5.1-125 (1983)(Adventure International)(US)(Disk 1 of 2)[a][cr CSS].atr", 120 }, { 0x16810, 0x7c32, "S.A.G.A. 13 - The Sorcerer of Claymorgue Castle v5.1-125 (1983)(Adventure International)(US)(Disk 2 of 2)[a].atr", 112 } },
31 { { 0x16810, 0x1de8, "S.A.G.A. #13 - The Sorcerer of Claymorgue Castle v5.1-125 (1983)(Adventure International)(US)(Disk 1 of 2)[a][cr CSS].atr", 121 }, { 0x16810, 0x7c32, "S.A.G.A. #13 - The Sorcerer of Claymorgue Castle v5.1-125 (1983)(Adventure International)(US)(Disk 2 of 2)[a].atr", 113 } },
32
33 { { 0, 0, NULL }, { 0, 0, NULL } }
34
35 };
36
37 typedef struct imglist {
38 USImageType usage;
39 int index;
40 size_t offset;
41 } imglist;
42
43 static const struct imglist listHulk[] = {
44 { IMG_ROOM, 0, 0x297 }, // (0) Too dark
45 { IMG_ROOM, 1, 0x2479 }, // (1) *I'm Bruce Banner, tied hand & foot to a chair
46 { IMG_ROOM, 2, 0x71e }, // (2) dome
47 { IMG_ROOM, 3, 0x2a6b }, // (3) tunnel going outside
48 { IMG_ROOM, 4, 0xd17 }, // (4) field
49 { IMG_ROOM, 9, 0x2ef2 }, // (5) hole
50 { IMG_ROOM, 12, 0x1325 }, // (6) cavern
51 { IMG_ROOM, 15, 0x381e }, // (7) small underground room
52 { IMG_ROOM, 16, 0x4064 }, // (8) fuzzy area
53 { IMG_ROOM, 19, 0x4bac }, // (9) Chief Examiner working
54 { IMG_ROOM, 20, 0x5256 }, // (10) state of limbo
55 { IMG_ROOM, 81, 0x5ee4 }, // (11)
56 { IMG_ROOM, 82, 0x695d }, // (12)
57 { IMG_ROOM, 83, 0x7207 }, // (13)
58 { IMG_ROOM, 84, 0x8deb }, // (14)
59 { IMG_ROOM, 85, 0x7a8e }, // (15)
60 { IMG_ROOM, 86, 0x9deb }, // (16) Gas
61 { IMG_ROOM, 87, 0x8717 }, // (17) Victory
62 { IMG_ROOM, 88, 0xac90 }, // (18) Nightmares
63 { IMG_ROOM, 89, 0xba2c }, // (19) Digging
64 { IMG_ROOM, 90, 0xcb00 }, // (20) Dome with mesh
65 { IMG_ROOM, 91, 0xd497 }, // (21) Closeup bio gem
66 { IMG_ROOM, 92, 0xdea5 }, // (22) Closeup egg
67 { IMG_ROOM, 93, 0x10479 }, // (23) Closeup ant
68 { IMG_ROOM, 94, 0xe7c1 }, // (24) Closeup bees
69 { IMG_ROOM, 95, 0x10df2 }, // (25) Closeup ring
70 { IMG_ROOM, 96, 0xf5a5 }, // (26) Closeup Ant-Man
71 { IMG_ROOM, 97, 0x1146b }, // (27) Closeup outlet
72 { IMG_ROOM, 99, 0x11a33 }, // (28) Title
73 { IMG_ROOM_OBJ, 13, 0x12700 }, // (29) Large hole
74 { IMG_ROOM_OBJ, 20, 0x127ba }, // (30) Alien army ants
75 { IMG_ROOM_OBJ, 24, 0x12e0e }, // (31) Killer Bees
76 { IMG_ROOM_OBJ, 53, 0x12ea5 }, // (32) Sign
77 { IMG_ROOM_OBJ, 26, 0x12f0e }, // (33) Astral projection of Dr. Strange
78 { IMG_ROOM_OBJ, 17, 0x13b8e }, // (34) Natter energy egg
79 { IMG_ROOM_OBJ, 22, 0x13d17 }, // (35) Tiny holes
80 { IMG_ROOM_OBJ, 25, 0x13fdd }, // (36) Wire mesh in wall with bee size holes
81 { IMG_ROOM_OBJ, 33, 0x14100 }, // (37) Large iron ring set in floor
82 { IMG_ROOM_OBJ, 36, 0x141a5 }, // (38) Button in wall
83 { IMG_ROOM_OBJ, 34, 0x1420e }, // (39) Open hole in floor
84 { IMG_ROOM_OBJ, 39, 0x1440e }, // (40) Hole in ceiling
85 { IMG_ROOM_OBJ, 40, 0x145c1 }, // (41) Crack in floor
86 { IMG_ROOM_OBJ, 45, 0x1469e }, // (42) ULTRON
87 { IMG_ROOM_OBJ, 70, 0x1508e }, // (43) Bio gem in room
88 { IMG_ROOM_OBJ, 72, 0x15307 }, // (44) Wax in room
89 { IMG_INV_OBJ, 4, 0x15356 }, // (45) *Gem 1
90 { IMG_INV_OBJ, 12, 0x15397 }, // (46) *Gem 2
91 { IMG_INV_OBJ, 16, 0x153dd }, // (47) *Gem 3
92 { IMG_INV_OBJ, 19, 0x1541e }, // (48) *Gem 4
93 { IMG_INV_OBJ, 29, 0x15464 }, // (49) *Gem 5
94 { IMG_INV_OBJ, 30, 0x154a5 }, // (50) *Gem 6
95 { IMG_INV_OBJ, 31, 0x154eb }, // (51) *Gem 7
96 { IMG_INV_OBJ, 32, 0x1552c }, // (52) *Gem 8
97 { IMG_INV_OBJ, 35, 0x15572 }, // (53) *Gem 9
98 { IMG_INV_OBJ, 37, 0x155b3 }, // (54) *Gem 10
99 { IMG_INV_OBJ, 42, 0x155f9 }, // (55) *Gem 11
100 { IMG_INV_OBJ, 44, 0x1563a }, // (56) *Gem 12
101 { IMG_INV_OBJ, 46, 0x15680 }, // (57) *Gem 13
102 { IMG_INV_OBJ, 48, 0x156c1 }, // (58) Gem 14
103 { IMG_INV_OBJ, 50, 0x15707 }, // (59) *Gem 15
104 { IMG_INV_OBJ, 2, 0x15748 }, // (60) Mirror
105 { IMG_INV_OBJ, 21, 0x157ba }, // (61) Wax
106 { IMG_INV_OBJ, 1, 0x15807 }, // (62) Rage
107 { IMG_INV_OBJ, 18, 0x15cc8 }, // (63) *Bio gem
108 { IMG_INV_OBJ, 3, 0x15da5 }, // (64) Broken chair
109 { IMG_INV_OBJ, 23, 0x15ea5 }, // (65) Metal Hand Fan
110 { IMG_ROOM_OBJ, 250, 0x15f3a }, // (66) // color test
111 { IMG_INV_OBJ, 51, 0x15f79 }, // (67) *Gem 16
112 { IMG_ROOM_OBJ, 47, 0x15fba }, // (68) Small cage
113 { 0, 0, 0, }
114 };
115
116 // "R0198", 0, Disk image A at offset 0x9890
117
118 static const struct imglist listClaymorgue[] = {
119 { IMG_INV_OBJ, 5, 0x297 }, // (0) *STAR
120 { IMG_INV_OBJ, 6, 0x2c1 }, // (1) *STAR
121 { IMG_INV_OBJ, 7, 0x2e4 }, // (2) *STAR
122 { IMG_INV_OBJ, 8, 0x307 }, // (3) *STAR
123 { IMG_INV_OBJ, 9, 0x32c }, // (4) I'm glowing
124 { IMG_INV_OBJ, 10, 0x3b3 }, // (5) *STAR
125 { IMG_INV_OBJ, 11, 0x3d6 }, // (6) *STAR
126 { IMG_INV_OBJ, 12, 0x400 }, // (7) *STAR
127 { IMG_INV_OBJ, 13, 0x42c }, // (8) *STAR
128 { IMG_INV_OBJ, 14, 0x456 }, // (9) *STAR
129 { IMG_INV_OBJ, 15, 0x479 }, // (10) *STAR
130 { IMG_INV_OBJ, 16, 0x49e }, // (11) *STAR
131 { IMG_INV_OBJ, 17, 0x4c1 }, // (12) *STAR
132 { IMG_INV_OBJ, 20, 0x4eb }, // (13) Magic mirror
133 { IMG_INV_OBJ, 24, 0x52c }, // (14) Fire spell
134 { IMG_INV_OBJ, 33, 0x580 }, // (15) Spell of Methuselah
135 { IMG_INV_OBJ, 34, 0x5cf }, // (16) Seed spell
136 { IMG_INV_OBJ, 35, 0x61e }, // (17) Potion
137 { IMG_INV_OBJ, 36, 0x66b }, // (18) Light squared spell
138 { IMG_INV_OBJ, 40, 0x6b3 }, // (19) Permeability spell
139 { IMG_INV_OBJ, 41, 0x707 }, // (20) Spell of Bliss
140 { IMG_INV_OBJ, 42, 0x74f }, // (21) Piece of wood
141 { IMG_INV_OBJ, 45, 0x7ac }, // (22) Yoho spell
142 { IMG_INV_OBJ, 48, 0x800 }, // (23) Wooden crate
143 { IMG_INV_OBJ, 50, 0x864 }, // (24) Fire bricks
144 { IMG_INV_OBJ, 57, 0x8c1 }, // (25) Firefly spell
145 { IMG_INV_OBJ, 59, 0x910 }, // (26) Dust
146 { IMG_INV_OBJ, 61, 0x93a }, // (27) Wicked Queen's spell
147 { IMG_INV_OBJ, 62, 0x98e }, // (28) Soggy towel
148 { IMG_INV_OBJ, 63, 0x9f2 }, // (29) Ashes
149 { IMG_INV_OBJ, 64, 0xa33 }, // (30) Unravel spell
150 { IMG_INV_OBJ, 68, 0xa87 }, // (31) Tin can
151 { IMG_INV_OBJ, 70, 0xac8 }, // (32) Dizzy Dean spell
152 { IMG_INV_OBJ, 71, 0xb17 }, // (33) Piece of metal
153 { IMG_INV_OBJ, 73, 0xb56 }, // (34) Lycanthrope spell
154 { IMG_INV_OBJ, 28, 0xba5 }, // (35) Broken glass
155 { IMG_INV_OBJ, 51, 0xbf2 }, // (36) Water droplets
156 { IMG_INV_OBJ, 52, 0xc97 }, // (37) Wrinkles
157 { IMG_INV_OBJ, 65, 0xe80 }, // (38) Damp towel
158 { IMG_INV_OBJ, 66, 0xee4 }, // (39) Dry towel
159 { IMG_INV_OBJ, 69, 0xf33 }, // (40) Open can
160 { IMG_ROOM_OBJ, 26, 0xf87 }, // (41) Fallen Chandelier
161 { IMG_ROOM_OBJ, 38, 0x12b3 }, // (42) Loft
162 { IMG_ROOM_OBJ, 30, 0x1e17 }, // (43) Open door
163 { IMG_ROOM_OBJ, 32, 0x1fba }, // (44) Open door
164 { IMG_ROOM_OBJ, 75, 0x211e }, // (45) Rabid rats
165 { IMG_ROOM_OBJ, 39, 0x232c }, // (46) Moat bottom
166 { IMG_ROOM_OBJ, 54, 0x28eb }, // (47) Open door
167 { IMG_ROOM_OBJ, 55, 0x2bc1 }, // (48) Raised drawbridge
168 { IMG_ROOM_OBJ, 4, 0x2f0e }, // (49) Lowered drawbridge
169 { IMG_ROOM_OBJ, 60, 0x3000 }, // (50) Hole
170 { IMG_ROOM, 29, 0x3641 }, // (51) dragon's lair
171 { IMG_ROOM, 99, 0x4797 }, // (52) title
172 { IMG_ROOM_OBJ, 49, 0x51c8 }, // (53) Hole
173 { IMG_ROOM_OBJ, 47, 0x549e }, // (54) Hole
174 { IMG_ROOM_OBJ, 250, 0x5580 }, // (55) Color test
175 { IMG_INV_OBJ, 0, 0x55c1 }, // (56) *STAR
176 { IMG_ROOM_OBJ, 74, 0x55eb }, // (57) Old lever in wall
177 { IMG_ROOM, 0, 0x5617 }, // (58) Too dark to see
178 { IMG_ROOM, 1, 0x57ba }, // (59) field
179 { IMG_ROOM, 2, 0x628e }, // (60) *I'm on a Drawbridge
180 { IMG_ROOM, 3, 0x68cf }, // (61) courtyard
181 { IMG_ROOM, 4, 0x7864 }, // (62) magic fountain
182 { IMG_ROOM, 5, 0x8297 }, // (63) stream of lava
183 { IMG_ROOM, 6, 0x8c33 }, // (64) *I'm on top of the fountain
184 { IMG_ROOM, 7, 0x95dd }, // (65) ball room
185 { IMG_ROOM, 8, 0x9cb3 }, // (66) *I'm on a large chandelier
186 { IMG_ROOM, 9, 0xa61e }, // (67) forest of enchantment
187 { IMG_ROOM, 10, 0xa95d }, // (68) plain room
188 { IMG_ROOM, 11, 0xad72 }, // (69) storeroom
189 { IMG_ROOM, 12, 0xb4ac }, // (70) dungeon cell
190 { IMG_ROOM, 13, 0xbd33 }, // (71) anteroom
191 { IMG_ROOM, 14, 0xc39e }, // (72) staircase
192 { IMG_ROOM, 15, 0xc8d6 }, // (73) loft above ballroom
193 { IMG_ROOM, 16, 0xcf4f }, // (74) *I'm in the water of a moat
194 { IMG_ROOM, 17, 0xdbf2 }, // (75) *I'm underwater
195 { IMG_ROOM, 18, 0xdc48 }, // (76) *I'm under the stairs
196 { IMG_ROOM, 19, 0xeaba }, // (77) hollow tree
197 { IMG_ROOM, 20, 0xfd17 }, // (78) pool of dirty water
198 { IMG_ROOM, 21, 0x1029e }, // (79) kitchen
199 { IMG_ROOM, 22, 0x10aa5 }, // (80) *I'm on a box
200 { IMG_ROOM, 23, 0x10f3a }, // (81) box
201 { IMG_ROOM, 24, 0x116ac }, // (82) dusty room
202 { IMG_ROOM, 25, 0x1228e }, // (83) stone staircase
203 { IMG_ROOM, 26, 0x1260e }, // (84) damp cavern
204 { IMG_ROOM, 27, 0x135f2 }, // (85) stone grotto
205 { IMG_ROOM, 28, 0x14048 }, // (86) *I'm in an entryway
206 { IMG_ROOM, 30, 0x14c97 }, // (87) wizard's workshop
207 { IMG_ROOM, 31, 0x158b3 }, // (88) vacant room
208 { IMG_ROOM, 32, 0x15ccf }, // (89) real mess!
209 { 0, 0, 0 }
210 };
211
212 static const struct imglist listCount[] = {
213 { IMG_INV_OBJ, 0, 0x297 }, // (0) Sheets
214 { IMG_INV_OBJ, 16, 0x310 }, // (1) Tent STAKE
215 { IMG_INV_OBJ, 26, 0x36b }, // (2) Pack of cigarettes
216 { IMG_INV_OBJ, 19, 0x3e4 }, // (3) Empty bottle
217 { IMG_INV_OBJ, 45, 0x425 }, // (4) Package
218 { IMG_INV_OBJ, 42, 0x49e }, // (5) Small Vial
219 { IMG_INV_OBJ, 47, 0x4c8 }, // (6) Postcard
220 { IMG_INV_OBJ, 3, 0x4f9 }, // (7) Pillow
221 { IMG_INV_OBJ, 17, 0x58e }, // (8) Mirror
222 { IMG_INV_OBJ, 27, 0x5dd }, // (9) LIT cigarette
223 { IMG_INV_OBJ, 31, 0x656 }, // (10) Dusty clove of garlic
224 { IMG_INV_OBJ, 5, 0x697 }, // (11) Coat-of-Arms
225 { IMG_INV_OBJ, 18, 0x6f2 }, // (12) Bottle of type V blood
226 { IMG_INV_OBJ, 46, 0x73a }, // (13) Empty box
227 { IMG_INV_OBJ, 33, 0x7a5 }, // (14) Cigarette
228 { IMG_INV_OBJ, 8, 0x7eb }, // (15) 1 nodoz tablet
229 { IMG_INV_OBJ, 21, 0x848 }, // (16) Sulfur matches
230 { IMG_INV_OBJ, 20, 0x8a5 }, // (17) Unlit torch
231 { IMG_INV_OBJ, 51, 0x900 }, // (18) Note
232 { IMG_INV_OBJ, 61, 0x997 }, // (19) Daisies
233 { IMG_INV_OBJ, 9, 0xa4f }, // (20) LIT torch
234 { IMG_INV_OBJ, 24, 0xadd }, // (21) 2 nodoz tablets
235 { IMG_INV_OBJ, 37, 0xb56 }, // (22) Pocket watch
236 { IMG_INV_OBJ, 15, 0xbc8 }, // (23) Paper clip
237 { IMG_INV_OBJ, 23, 0xc2c }, // (24) 3 no-doz tablets
238 { IMG_INV_OBJ, 41, 0xceb }, // (25) Large tempered nail file
239 { IMG_INV_OBJ, 53, 0xd72 }, // (26) Rubber mallet
240 { IMG_INV_OBJ, 65, 0xdf9 }, // (27) Letter
241 { IMG_INV_OBJ, 58, 0xe90 }, // (28) portrait of DRACULA
242 { IMG_INV_OBJ, 70, 0xf2c }, // (29) Century worth of dust
243 { IMG_INV_OBJ, 35, 0xfac }, // (30) The other end of the sheet
244 { IMG_ROOM_OBJ, 6, 0x10c8 }, // (31) Sheet going into window
245 { IMG_ROOM_OBJ, 7, 0x116b }, // (32) sheet tied to flagpole
246 { IMG_ROOM_OBJ, 13, 0x12ba }, // (33) Open door
247 { IMG_ROOM_OBJ, 82, 0x13f9 }, // (34) Coat-of-arms in room
248 { IMG_ROOM_OBJ, 40, 0x168e }, // (35) Broken slide lock
249 { IMG_ROOM_OBJ, 52, 0x16b3 }, // (36) DRACULA
250 { IMG_ROOM_OBJ, 55, 0x1b48 }, // (37) Sheet tied to ring
251 { IMG_ROOM, 90, 0x1ccf }, // (38) Closeup package
252 { IMG_ROOM_OBJ, 63, 0x261e }, // (39) Dumb-waiter
253 { IMG_ROOM_OBJ, 67, 0x2733 }, // (40) Mouldy old skeleton
254 { IMG_ROOM_OBJ, 80, 0x2cdd }, // (41) wall mirror
255 { IMG_ROOM_OBJ, 81, 0x2ecf }, // (42) other end of sheet
256 { IMG_ROOM, 250, 0x3000 }, // (43) Color test
257 { IMG_ROOM_OBJ, 29, 0x302c }, // (44) Coffin is open
258 { IMG_ROOM_OBJ, 30, 0x334f }, // (45) Coffin is closed
259 { IMG_ROOM, 91, 0x3580 }, // (46) Closeup angry mob
260 { IMG_ROOM_OBJ, 1, 0x4072 }, // (47) Open window
261 { IMG_ROOM_OBJ, 36, 0x408e }, // (48) Sheet tied to bed
262 { IMG_ROOM, 2, 0x413a }, // (49) bedroom
263 { IMG_ROOM, 0, 0x4a25 }, // (50) Too dark
264 { IMG_ROOM, 1, 0x5580 }, // (51) *I'm lying in a large brass bed
265 { IMG_ROOM, 3, 0x5e48 }, // (52) *ledge outside an open window
266 { IMG_ROOM, 4, 0x6a17 }, // (53) *hanging on the end of a sheet
267 { IMG_ROOM, 5, 0x74c1 }, // (54) flower box outside window
268 { IMG_ROOM, 6, 0x7cba }, // (55) CRYPT
269 { IMG_ROOM, 7, 0x8f41 }, // (56) closet
270 { IMG_ROOM, 8, 0x984f }, // (57) Bathroom
271 { IMG_ROOM, 9, 0xa10e }, // (58) *I'm outside the castle
272 { IMG_ROOM, 10, 0xad79 }, // (59) DOORLESS room
273 { IMG_ROOM, 11, 0xb687 }, // (60) hall inside the castle
274 { IMG_ROOM, 12, 0xc0d6 }, // (61) kitchen
275 { IMG_ROOM, 13, 0xcc56 }, // (62) large COFFIN
276 { IMG_ROOM, 14, 0xdf5d }, // (63) pAntry
277 { IMG_ROOM, 15, 0xe872 }, // (64) giant SOLAR OVEN
278 { IMG_ROOM, 16, 0xf72c }, // (65) Dungeon
279 { IMG_ROOM, 17, 0x10441 }, // (66) Meandering path
280 { IMG_ROOM, 18, 0x1159e }, // (67) Pit
281 { IMG_ROOM, 19, 0x12872 }, // (68) Dark passage
282 { IMG_ROOM, 20, 0x12f5d }, // (69) dumb-waiter by a room
283 { IMG_ROOM, 21, 0x136b3 }, // (70) workroom
284 { IMG_ROOM, 22, 0x1400e }, // (71) LOT OF TROUBLE!
285 { IMG_ROOM, 99, 0x14f97 }, // (72) Title
286 { IMG_ROOM_OBJ, 56, 0x16156 }, // 73
287 { 0, 0, 0 }
288 };
289
290 static const struct imglist listVoodoo[] = {
291 { IMG_ROOM, 1, 0x297 }, // (0) chapel
292 { IMG_ROOM, 14, 0xac1 }, // (1) Chimney
293 { IMG_ROOM, 2, 0x1a79 }, // (2) Dingy Looking Stairwell
294 { IMG_ROOM, 3, 0x1e2c }, // (3) room in the castle
295 { IMG_ROOM, 4, 0x28a5 }, // (4) Tunnel
296 { IMG_ROOM, 5, 0x3817 }, // (5) room in the castle
297 { IMG_ROOM, 6, 0x3f87 }, // (6) *I'm in Medium Maegen's Mad Room
298 { IMG_ROOM, 7, 0x4664 }, // (7) room in the castle
299 { IMG_ROOM, 8, 0x4f0e }, // (8) room in the castle
300 { IMG_ROOM, 9, 0x52ac }, // (9) room in the castle
301 { IMG_ROOM, 10, 0x5b48 }, // (10) Ballroom
302 { IMG_ROOM, 11, 0x6264 }, // (11) dungeon
303 { IMG_ROOM, 12, 0x67dd }, // (12) *I'm in the Armory
304 { IMG_ROOM, 13, 0x740e }, // (13) torture chamber
305 { IMG_ROOM, 15, 0x7d4f }, // (14) large fireplace
306 { IMG_ROOM, 16, 0x8af2 }, // (15) room in the castle
307 { IMG_ROOM, 17, 0x954f }, // (16) Lab
308 { IMG_ROOM, 18, 0xa19e }, // (17) narrow part of the chimney
309 { IMG_ROOM, 19, 0xab17 }, // (18) Graveyard
310 { IMG_ROOM, 20, 0xbe1e }, // (19) parlor
311 { IMG_ROOM, 21, 0xc579 }, // (20) Jail Cell
312 { IMG_ROOM, 22, 0xcf9e }, // (21) *I'm on a ledge
313 { IMG_ROOM, 23, 0xd533 }, // (22) hidden VOODOO room
314 { IMG_ROOM, 24, 0xe5e4 }, // (23) room in the castle
315 { IMG_ROOM, 25, 0xeb3a }, // (24) lot of TROUBLE!
316 { IMG_ROOM, 90, 0xf856 }, // (25) Closeup Broken sword
317 { IMG_ROOM, 96, 0xfd87 }, // (26) Closeup Chemicals
318 { IMG_ROOM, 101, 0x1068e }, // (27) Closeup Count Cristo
319 { IMG_ROOM, 100, 0x114e4 }, // (28) Closeup dusty idol
320 { IMG_ROOM, 99, 0x11956 }, // (29) Title
321 { IMG_ROOM, 0, 0x12879 }, // (30) Too dark
322 { IMG_ROOM_OBJ, 17, 0x131cf }, // (31) Closed Coffin
323 { IMG_INV_OBJ, 26, 0x13325 }, // (32) Ju-Ju bag
324 { IMG_INV_OBJ, 43, 0x13407 }, // (33) Dusty idol
325 { IMG_INV_OBJ, 14, 0x134ba }, // (34) Four leaf clover
326 { IMG_INV_OBJ, 60, 0x1355d }, // (35) Advertising
327 { IMG_INV_OBJ, 16, 0x1359e }, // (36) Cast iron pot
328 { IMG_INV_OBJ, 44, 0x1360e }, // (37) Doll
329 { IMG_INV_OBJ, 25, 0x136ba }, // (38) Sapphire ring
330 { IMG_INV_OBJ, 39, 0x13733 }, // (39) Pocket Shovel
331 { IMG_INV_OBJ, 38, 0x1378e }, // (40) Labeled chemicals
332 { IMG_INV_OBJ, 54, 0x13817 }, // (41) Stick
333 { IMG_INV_OBJ, 33, 0x13879 }, // (42) Dull & broken sword
334 { IMG_INV_OBJ, 0, 0x138dd }, // (43) Bloody Knife
335 { IMG_INV_OBJ, 64, 0x1392c }, // (44) Page torn from a book
336 { IMG_INV_OBJ, 47, 0x13972 }, // (45) Antique hammer
337 { IMG_INV_OBJ, 2, 0x139c1 }, // (46) Plaque
338 { IMG_INV_OBJ, 52, 0x13a2c }, // (47) Voodoo book
339 { IMG_INV_OBJ, 21, 0x13aa5 }, // (48) Soot
340 { IMG_INV_OBJ, 49, 0x13b0e }, // (49) Rusting SAW
341 { IMG_INV_OBJ, 7, 0x13b64 }, // (50) Shield
342 { IMG_INV_OBJ, 4, 0x13c56 }, // (51) Broken glass
343 { IMG_INV_OBJ, 3, 0x13cac }, // (52) Animal heads
344 { IMG_INV_OBJ, 36, 0x13d6b }, // (53) Chem tubes
345 { IMG_INV_OBJ, 53, 0x13db3 }, // (54) Ju-Ju man statue
346 { IMG_INV_OBJ, 9, 0x13e97 }, // (55) Brightly glowing idol
347 { IMG_INV_OBJ, 40, 0x13f72 }, // (56) Mixed Chemicals
348 { IMG_INV_OBJ, 42, 0x13ff9 }, // (57) Nails
349 { IMG_INV_OBJ, 51, 0x1405d }, // (58) Paper
350 { IMG_INV_OBJ, 63, 0x140d6 }, // (59) Pieces of rock
351 { IMG_INV_OBJ, 45, 0x1415d }, // (60) Wooden boards
352 { IMG_INV_OBJ, 59, 0x14217 }, // (61) Broken grating
353 { IMG_INV_OBJ, 29, 0x14279 }, // (62) Ju-Ju man
354 { IMG_ROOM_OBJ, 19, 0x14333 }, // (63) Closed Window
355 { IMG_ROOM_OBJ, 23, 0x144c1 }, // (64) Spirit Medium
356 { IMG_ROOM_OBJ, 28, 0x147f2 }, // (65) Slick chute leading downward
357 { IMG_ROOM_OBJ, 35, 0x14e1e }, // (66) Stuck Chimney Sweep
358 { IMG_ROOM_OBJ, 6, 0x15710 }, // (67) Dark hole
359 { IMG_ROOM_OBJ, 41, 0x158c8 }, // (68) Wide open door
360 { IMG_ROOM_OBJ, 65, 0x15972 }, // (69) Smiling Count Cristo
361 { IMG_ROOM_OBJ, 13, 0x15cf9 }, // (70) Open Flue
362 { IMG_ROOM_OBJ, 31, 0x15eb3 }, // (71) Wide crack in the wall
363 { IMG_ROOM_OBJ, 34, 0x16025 }, // (72) Open SAfe
364 { IMG_ROOM_OBJ, 37, 0x1625d }, // (73) Closed SAfe
365 { IMG_ROOM_OBJ, 46, 0x16348 }, // (74) Wooden boards nailed
366 { IMG_ROOM_OBJ, 48, 0x16472 }, //75 Grating
367 { IMG_INV_OBJ, 32, 0x164f2 }, //76 Rabbit's foot? // 16590, bd9a
368 { IMG_ROOM, 250, 0x16490 }, // 77, Color test
369 { IMG_ROOM_OBJ, 80, 0x165c1 }, // 77, Wooden boards unnailed (45)
370 { 0, 0, 0, }
371 };
372
373 static const CropList a8croplist[] = {
374 { VOODOO_CASTLE_US, IMG_ROOM, 10, 8, 8 },
375 { VOODOO_CASTLE_US, IMG_ROOM, 11, 8, 8 },
376 { VOODOO_CASTLE_US, IMG_ROOM, 14, 8, 8 },
377 { VOODOO_CASTLE_US, IMG_ROOM, 19, 8, 8 },
378 { VOODOO_CASTLE_US, IMG_ROOM, 20, 8, 8 },
379 { HULK_US, IMG_ROOM, 0, 0, 32 },
380 { COUNT_US, IMG_ROOM, 0, 8, 0 },
381
382 { 0, 0, 0, 0, 0 }
383 };
384
385 static int StripBrackets(char sideB[], size_t length)
386 {
387 int left_bracket = 0;
388 int right_bracket = 0;
389 size_t ppos = length - 1;
390 while (sideB[ppos] != '.' && ppos > 0)
391 ppos--;
392 size_t extlen = length - ppos;
393 if (length > 4) {
394 for (int i = (int)ppos; i > 0; i--) {
395 char c = sideB[i];
396 if (c == ']') {
397 if (right_bracket == 0) {
398 right_bracket = i;
399 } else {
400 return 0;
401 }
402 } else if (c == '[') {
403 if (right_bracket > 0) {
404 left_bracket = i;
405 break;
406 } else {
407 return 0;
408 }
409 }
410 }
411 if (right_bracket && left_bracket && length > right_bracket + extlen) {
412 right_bracket++;
413 for (int i = 0; i < extlen; i++) {
414 sideB[left_bracket++] = sideB[right_bracket++];
415 }
416 sideB[left_bracket] = '\0';
417 return 1;
418 }
419 }
420 return 0;
421 }
422
423 static uint8_t *LookForAtari8CompanionFilename(int index, CompanionNameType type, size_t stringlen, size_t *filesize)
424 {
425
426 char *sideB = MemAlloc(stringlen + 10);
427 uint8_t *result = NULL;
428
429 memcpy(sideB, game_file, stringlen + 1);
430 switch (type) {
431 case TYPE_A:
432 sideB[index] = 'A';
433 break;
434 case TYPE_B:
435 sideB[index] = 'B';
436 break;
437 case TYPE_1:
438 sideB[index] = '1';
439 break;
440 case TYPE_2:
441 sideB[index] = '2';
442 break;
443 case TYPE_ONE:
444 sideB[index] = 'o';
445 sideB[index + 1] = 'n';
446 sideB[index + 2] = 'e';
447 break;
448 case TYPE_TWO:
449 sideB[index] = 't';
450 sideB[index + 1] = 'w';
451 sideB[index + 2] = 'o';
452 break;
453 case TYPE_NONE:
454 break;
455 }
456
457 debug_print("looking for companion file \"%s\"\n", sideB);
458 result = ReadFileIfExists(sideB, filesize);
459 if (!result) {
460 if (type == TYPE_B) {
461 if (StripBrackets(sideB, stringlen)) {
462 debug_print("looking for companion file \"%s\"\n", sideB);
463 result = ReadFileIfExists(sideB, filesize);
464 }
465 } else if (type == TYPE_A) {
466 // First we look for the period before the file extension
467 size_t ppos = stringlen - 1;
468 while (sideB[ppos] != '.' && ppos > 0)
469 ppos--;
470 if (ppos < 1) {
471 free(sideB);
472 return NULL;
473 }
474 // Then we copy the extension to the new end position
475 for (size_t i = ppos; i <= stringlen; i++) {
476 sideB[i + 8] = sideB[i];
477 }
478 sideB[ppos++] = '[';
479 sideB[ppos++] = 'c';
480 sideB[ppos++] = 'r';
481 sideB[ppos++] = ' ';
482 sideB[ppos++] = 'C';
483 sideB[ppos++] = 'S';
484 sideB[ppos++] = 'S';
485 sideB[ppos] = ']';
486 debug_print("looking for companion file \"%s\"\n", sideB);
487 result = ReadFileIfExists(sideB, filesize);
488 }
489 }
490 free(sideB);
491 return result;
492 }
493
494 static uint8_t *GetAtari8CompanionFile(size_t *size)
495 {
496
497 size_t gamefilelen = strlen(game_file);
498 char *foundname = LookInDatabase(a8companionlist, gamefilelen);
499 uint8_t *result = NULL;
500 if (foundname) {
501 result = ReadFileIfExists(foundname, size);
502 free((void *)foundname);
503 if (result)
504 return result;
505 }
506
507 char c;
508 for (int i = (int)gamefilelen - 1; i >= 0 && game_file[i] != '/' && game_file[i] != '\\'; i--) {
509 c = tolower(game_file[i]);
510 if (i > 3 && ((c == 'e' && game_file[i - 1] == 'd' && game_file[i - 2] == 'i' && tolower(game_file[i - 3]) == 's') || (c == 'k' && game_file[i - 1] == 's' && game_file[i - 2] == 'i' && tolower(game_file[i - 3]) == 'd'))) {
511 if (gamefilelen > i + 2) {
512 c = game_file[i + 1];
513 if (c == ' ' || c == '_') {
514 c = tolower(game_file[i + 2]);
515 CompanionNameType type = TYPE_NONE;
516 switch (c) {
517 case 'a':
518 type = TYPE_B;
519 break;
520 case 'b':
521 type = TYPE_A;
522 break;
523 case 't':
524 if (gamefilelen > i + 4 && game_file[i + 3] == 'w' && game_file[i + 4] == 'o') {
525 type = TYPE_ONE;
526 }
527 break;
528 case 'o':
529 if (gamefilelen > i + 4 && game_file[i + 3] == 'n' && game_file[i + 4] == 'e') {
530 type = TYPE_TWO;
531 }
532 break;
533 case '2':
534 type = TYPE_1;
535 break;
536 case '1':
537 type = TYPE_2;
538 break;
539 }
540 if (type != TYPE_NONE)
541 result = LookForAtari8CompanionFilename(i + 2, type, gamefilelen, size);
542 if (result)
543 return result;
544 }
545 }
546 }
547 }
548 return NULL;
549 }
550
551 static int ExtractImagesFromAtariCompanionFile(uint8_t *data, size_t datasize, uint8_t *otherdisk, size_t othersize)
552 {
553 size_t size;
554
555 int outpic;
556
557 const struct imglist *list;
558
559 switch (CurrentGame) {
560 case CLAYMORGUE_US:
561 list = listClaymorgue;
562 break;
563 case COUNT_US:
564 list = listCount;
565 break;
566 case VOODOO_CASTLE_US:
567 list = listVoodoo;
568 break;
569 case HULK_US:
570 list = listHulk;
571 break;
572 default:
573 return 0;
574 }
575
576 USImages = new_image();
577 struct USImage *image = USImages;
578
579 // Now loop round for each image
580 for (outpic = 0; list[outpic].offset != 0; outpic++) {
581 uint8_t *ptr = data + list[outpic].offset;
582
583 size = *ptr++;
584 size += *ptr * 256 + 2;
585
586 image->usage = list[outpic].usage;
587 image->index = list[outpic].index;
588 image->imagedata = MemAlloc(size);
589 image->datasize = size;
590 image->systype = SYS_ATARI8;
591 memcpy(image->imagedata, data + list[outpic].offset - 2, size);
592 /* Bytes 0xb390 to 0xb410 correspond to the content of sector 360 (0x0168) of the original Atari disk
593 which contains the volume table of contents (mostly a bitmap of used sectors). This is not part of the
594 graphics data, so we cut it out. */
595 if (list[outpic].offset < 0xb390 && list[outpic].offset + image->datasize > 0xb390) {
596 memcpy(image->imagedata + 0xb390 - list[outpic].offset + 2, data + 0xb410, size - 0xb390 + list[outpic].offset - 2);
597 }
598
599 /* Many images have black bars on one or more sides, probably used to center smaller images. The original
600 interpreters had a black background which hid this, but it looks strange if the background is not black,
601 so we crop them. */
602 if (CurrentGame == VOODOO_CASTLE_US && image->usage == IMG_ROOM)
603 image->cropleft = 8;
604
605 if ((CurrentGame == CLAYMORGUE_US || CurrentGame == COUNT_US) && image->usage == IMG_ROOM && image->imagedata[7] == 126)
606 image->cropright = 8;
607
608 for (int i = 0; a8croplist[i].game != 0; i++) {
609 CropList crop = a8croplist[i];
610 if (crop.game == CurrentGame && crop.index == image->index && crop.usage == image->usage) {
611 image->cropleft = crop.cropleft;
612 image->cropright = crop.cropright;
613 }
614 }
615
616 image->next = new_image();
617 image->next->previous = image;
618 image = image->next;
619 }
620
621 /* Read the inventory image from the boot disk */
622 if (otherdisk && othersize > 0x988e + 0x5fd) {
623 image->usage = IMG_ROOM;
624 image->index = 98;
625 image->datasize = 0x5fd;
626 image->imagedata = MemAlloc(image->datasize);
627 image->systype = SYS_ATARI8;
628 memcpy(image->imagedata, otherdisk + 0x988e, image->datasize);
629 } else if (image->imagedata == NULL) {
630 /* Free the last image, it is empty */
631 if (image != USImages) {
632 image->previous->next = NULL;
633 free(image);
634 image = NULL;
635 } else {
636 free(USImages);
637 USImages = NULL;
638 }
639 }
640
641 /* If no images are found, free USImages struct */
642 if (USImages != NULL && USImages->next == NULL && USImages->imagedata == NULL) {
643 free(USImages);
644 USImages = NULL;
645 }
646
647 return 1;
648 }
649
650 static const uint8_t atrheader[6] = { 0x96, 0x02, 0x80, 0x16, 0x80, 0x00 };
651
652 GameIDType DetectAtari8(uint8_t **sf, size_t *extent)
653 {
654 GameIDType result = UNKNOWN_GAME;
655 size_t data_start = 0x04c1;
656 // Header actually starts at offset 0x04f9 (0x04c1 + 0x38).
657 // We add 50 bytes at the head to match the C64 files.
658
659 if (*extent > MAX_LENGTH || *extent < data_start)
660 return UNKNOWN_GAME;
661
662 for (int i = 0; i < 6; i++)
663 if ((*sf)[i] != atrheader[i])
664 return UNKNOWN_GAME;
665
666 size_t companionsize;
667 uint8_t *companionfile = GetAtari8CompanionFile(&companionsize);
668
669 ImageWidth = 280;
670 ImageHeight = 158;
671 result = LoadBinaryDatabase(*sf + data_start, *extent - data_start, *Game, 0);
672 if (result == UNKNOWN_GAME && companionfile != NULL && companionsize > data_start) {
673 debug_print("Could not find database in this file, trying the companion file\n");
674 result = LoadBinaryDatabase(companionfile + data_start, companionsize - data_start, *Game, 0);
675 if (result != UNKNOWN_GAME) {
676 debug_print("Found database in companion file. Switching files.\n");
677 uint8_t *temp = companionfile;
678 size_t tempsize = companionsize;
679 companionfile = *sf;
680 companionsize = *extent;
681 *sf = temp;
682 *extent = tempsize;
683 }
684 }
685
686 if (result != UNKNOWN_GAME) {
687 CurrentSys = SYS_ATARI8;
688 if (companionfile) {
689 ExtractImagesFromAtariCompanionFile(companionfile, companionsize, *sf, *extent);
690 free(companionfile);
691 }
692 } else
693 debug_print("Failed loading database\n");
694
695 return result;
696 }