-
Notifications
You must be signed in to change notification settings - Fork 2
/
jzip.c
168 lines (137 loc) · 4.11 KB
/
jzip.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
/* $Id: jzip.c,v 1.3 2000/10/04 23:07:57 jholder Exp $
* --------------------------------------------------------------------
* see doc/License.txt for License Information
* --------------------------------------------------------------------
*
* File name: $Id: jzip.c,v 1.3 2000/10/04 23:07:57 jholder Exp $
*
* Description:
*
* Modification history:
* $Log: jzip.c,v $
* Revision 1.3 2000/10/04 23:07:57 jholder
* fixed redirect problem with isolatin1 range chars
*
* Revision 1.2 2000/05/25 22:28:56 jholder
* changes routine names to reflect zmachine opcode names per spec 1.0
*
* Revision 1.1.1.1 2000/05/10 14:21:34 jholder
*
* imported
*
*
* --------------------------------------------------------------------
*/
/*
* jzip.c
*
* Z code interpreter main routine.
*
* Revisions list:
* Mark Howell 10-Mar-1993 V2.0 [email protected]
* V2.0.1(some of a-f)
* John Holder 22-Nov-1995 V2.0.1g [email protected]
* John Holder 06-Feb-1998 V2.0.2 [email protected] Zstrict & Quetzal
*
* If you have problems with this interpreter and/or fix bugs in it,
* please notify John Holder ([email protected]) and he will add your
* fix to the official JZIP distribution.
*/
#include "ztypes.h"
#include "jzexe.h"
extern int GLOBALVER;
static void configure( zbyte_t, zbyte_t );
/*
* main
*
* Initialise environment, start interpreter, clean up.
*/
int main( int argc, char *argv[] )
{
process_arguments( argc, argv );
check_blorb();
configure( V1, V8 );
initialize_screen( );
load_cache( );
z_restart( );
( void ) interpret( );
close_story( );
close_script( );
unload_cache( );
reset_screen( );
exit( EXIT_SUCCESS );
return ( 0 );
} /* main */
/*
* configure
*
* Initialise global and type specific variables.
*
*/
static void configure( zbyte_t min_version, zbyte_t max_version )
{
zbyte_t header[PAGE_SIZE], second;
read_page( 0, header );
datap = header;
h_type = get_byte( H_TYPE );
if ( h_type == 'M' || h_type == 'Z' )
{
/* possibly a DOS executable file, look more closely. (mol951115) */
second = get_byte( H_TYPE + 1 );
if ( ( h_type == 'M' && second == 'Z' ) || ( h_type == 'Z' && second == 'M' ) )
if ( analyze_exefile( ) )
{
/* Bingo! File is a standalone game file. */
/* analyze_exefile has updated story_offset, so now we can */
/* read the _real_ first page, and continue as if nothing */
/* has happened. */
read_page( 0, header );
h_type = get_byte( H_TYPE );
}
}
GLOBALVER = h_type;
if ( h_type < min_version || h_type > max_version ||
( get_byte( H_CONFIG ) & CONFIG_BYTE_SWAPPED ) )
fatal( "Wrong game or version" );
/*
* if (h_type == V6 || h_type == V7)
* fatal ("Unsupported zcode version.");
*/
if ( h_type < V4 )
{
story_scaler = 2;
story_shift = 1;
property_mask = P3_MAX_PROPERTIES - 1;
property_size_mask = 0xe0;
}
else if ( h_type < V8 )
{
story_scaler = 4;
story_shift = 2;
property_mask = P4_MAX_PROPERTIES - 1;
property_size_mask = 0x3f;
}
else
{
story_scaler = 8;
story_shift = 3;
property_mask = P4_MAX_PROPERTIES - 1;
property_size_mask = 0x3f;
}
h_config = get_byte( H_CONFIG );
h_version = get_word( H_VERSION );
h_data_size = get_word( H_DATA_SIZE );
h_start_pc = get_word( H_START_PC );
h_words_offset = get_word( H_WORDS_OFFSET );
h_objects_offset = get_word( H_OBJECTS_OFFSET );
h_globals_offset = get_word( H_GLOBALS_OFFSET );
h_restart_size = get_word( H_RESTART_SIZE );
h_flags = get_word( H_FLAGS );
h_synonyms_offset = get_word( H_SYNONYMS_OFFSET );
h_file_size = get_word( H_FILE_SIZE );
if ( h_file_size == 0 )
h_file_size = get_story_size( );
h_checksum = get_word( H_CHECKSUM );
h_alternate_alphabet_offset = get_word( H_ALTERNATE_ALPHABET_OFFSET );
datap = NULL;
} /* configure */