-
Notifications
You must be signed in to change notification settings - Fork 0
/
agi.c
executable file
·225 lines (171 loc) · 4.2 KB
/
agi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* Sarien - A Sierra AGI resource interpreter engine
* Copyright (C) 1999-2003 Stuart George and Claudio Matsuoka
*
* $Id: agi.c,v 1.65 2003/08/31 16:05:05 cmatsuoka Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; see docs/COPYING for further details.
*/
#include <stdio.h>
#include <string.h>
#include "sarien.h"
#include "agi.h"
#include "opcodes.h"
#include "keyboard.h"
#include "rand.h"
#include "menu.h"
#include "savegame.h"
static struct agi_loader *loader; /* loader */
#ifndef PALMOS
extern struct agi_loader agi_v2;
extern struct agi_loader agi_v3;
#else
extern struct agi_loader agi_v4;
#endif
static void init_pri_table ()
{
int i, p, y = 0;
for (p = 1; p < 15; p++) {
for (i = 0; i < 12; i++) {
game.pri_table[y++] = p < 4 ? 4 : p;
}
}
}
int agi_init ()
{
int ec, i;
_D ("initializing");
_D (_D_WARN "game.ver = 0x%x", game.ver);
/* reset all flags to false and all variables to 0 */
for (i = 0; i < MAX_FLAGS; i++)
game.flags[i] = 0;
for (i = 0; i < MAX_VARS; i++)
game.vars[i] = 0;
/* clear all resources and events */
for (i = 0; i < MAX_DIRS; i++) {
memset (&game.views[i], 0, sizeof (struct agi_view));
memset (&game.pictures[i], 0, sizeof (struct agi_picture));
memset (&game.logics[i], 0, sizeof (struct agi_logic));
memset (&game.sounds[i], 0, sizeof (struct agi_sound));
}
/* clear view table */
for (i = 0; i < MAX_VIEWTABLE; i++)
memset (&game.view_table[i], 0, sizeof (struct vt_entry));
init_words ();
set_rnd_seed ();
menu_init ();
init_pri_table ();
/* clear string buffer */
for (i = 0; i < MAX_STRINGS; i++)
game.strings[i][0] = 0;
/* setup emulation */
switch (loader->int_version >> 12) {
case 2:
report ("Emulating Sierra AGI v%x.%03x\n",
(int)(loader->int_version >> 12) & 0xF,
(int)(loader->int_version) & 0xFFF);
break;
case 3:
report ("Emulating Sierra AGI v%x.002.%03x\n",
(int)(loader->int_version >> 12) & 0xF,
(int)(loader->int_version) & 0xFFF);
break;
}
game.game_flags |= opt.amiga ? ID_AMIGA : 0;
game.game_flags |= opt.agds ? ID_AGDS : 0;
if (game.game_flags & ID_AMIGA)
report ("Amiga padded game detected.\n");
if (game.game_flags & ID_AGDS)
report ("AGDS mode enabled.\n");
ec = loader->init (); /* load vol files, etc */
if (ec == err_OK)
ec = loader->load_objects(OBJECTS);
/* note: demogs has no words.tok */
if(ec == err_OK)
ec = loader->load_words(WORDS);
/* FIXME: load IIgs instruments and samples */
/* load_instruments("kq.sys16"); */
/* Load logic 0 into memory */
if (ec == err_OK)
ec = loader->load_resource (rLOGIC, 0);
return ec;
}
/*
* Public functions
*/
void agi_unload_resources ()
{
int i;
/* Make sure logic 0 is always loaded */
for (i = 1; i < MAX_DIRS; i++) {
loader->unload_resource (rLOGIC, i);
}
for (i = 0; i < MAX_DIRS; i++) {
loader->unload_resource (rVIEW, i);
loader->unload_resource (rPICTURE, i);
loader->unload_resource (rSOUND, i);
}
}
int agi_deinit ()
{
int ec;
clean_input (); /* remove all words from memory */
agi_unload_resources (); /* unload resources in memory */
loader->unload_resource (rLOGIC, 0);
ec = loader->deinit ();
unload_objects();
unload_words();
clear_image_stack();
return ec;
}
int agi_detect_game (char *gn)
{
int ec = err_OK;
#ifdef DREAMCAST
strcpy(g_gamename, UNKNOWN_GAME);
#endif
#ifndef PALMOS
_D ("(gn = %s)", gn);
if (gn == NULL) /* assume current directory */
gn = get_current_directory ();
loader = &agi_v2;
ec = loader->detect_game (gn);
#ifndef FAKE_PALMOS
if (ec != err_OK) {
loader = &agi_v3;
ec = loader->detect_game (gn);
}
#endif
#else /* PALMOS */
loader = &agi_v4;
ec = loader->detect_game(gn);
#endif
return ec;
}
int agi_version ()
{
return loader->version;
}
int agi_get_release ()
{
return loader->int_version;
}
void agi_set_release (int n)
{
loader->int_version = n;
}
int agi_load_resource (int r, int n)
{
int i;
i = loader->load_resource (r, n);
#ifdef PATCH_LOGIC
if (r == rLOGIC)
patch_logic (n);
#endif
return i;
}
int agi_unload_resource (int r, int n)
{
return loader->unload_resource (r, n);
}