-
Notifications
You must be signed in to change notification settings - Fork 0
/
dpic.c
167 lines (143 loc) · 4.46 KB
/
dpic.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
/*
* dumb-pic.c - Dumb interface, picture outline functions
*
* This file is part of Frotz.
*
* Frotz 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; either version 2 of the License, or
* (at your option) any later version.
*
* Frotz is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Or visit http://www.fsf.org/
*/
#include "dfrotz.h"
extern fs_t A00003;
#define PIC_FILE_HEADER_FLAGS 1
#define PIC_FILE_HEADER_NUM_IMAGES 4
#define PIC_FILE_HEADER_ENTRY_SIZE 8
#define PIC_FILE_HEADER_VERSION 14
#define PIC_HEADER_NUMBER 0
#define PIC_HEADER_WIDTH 2
#define PIC_HEADER_HEIGHT 4
static struct {
int z_num;
int width;
int height;
int orig_width;
int orig_height;
} *pict_info;
static int num_pictures = 0;
static unsigned char lookupb(unsigned char *p, int n) {return p[n];}
static unsigned short lookupw(unsigned char *p, int n)
{
return (p[n + 1] << 8) | p[n];
}
void A00021 (char *filename)
{
FILE *file = NULL;
int success = FALSE;
unsigned char gheader[16];
unsigned char *raw_info = NULL;
int i, entry_size, flags;
float x_scaler, y_scaler;
do {
if ((A00035 != V6)
|| !filename
|| ((file = fopen (filename, "rb")) == NULL)
|| (fread(&gheader, sizeof (gheader), 1, file) != 1))
break;
num_pictures = lookupw(gheader, PIC_FILE_HEADER_NUM_IMAGES);
entry_size = lookupb(gheader, PIC_FILE_HEADER_ENTRY_SIZE);
flags = lookupb(gheader, PIC_FILE_HEADER_FLAGS);
raw_info = malloc(num_pictures * entry_size);
if (fread(raw_info, num_pictures * entry_size, 1, file) != 1)
break;
pict_info = malloc((num_pictures + 1) * sizeof(*pict_info));
pict_info[0].z_num = 0;
pict_info[0].height = num_pictures;
pict_info[0].width = lookupw(gheader, PIC_FILE_HEADER_VERSION);
y_scaler = A00051 / 200.0;
x_scaler = A00052 / ((flags & 0x08) ? 640.0 : 320.0);
/* Copy and scale. */
for (i = 1; i <= num_pictures; i++) {
unsigned char *p = raw_info + entry_size * (i - 1);
pict_info[i].z_num = lookupw(p, PIC_HEADER_NUMBER);
pict_info[i].orig_height = lookupw(p, PIC_HEADER_HEIGHT);
pict_info[i].orig_width = lookupw(p, PIC_HEADER_WIDTH);
pict_info[i].height = pict_info[i].orig_height * y_scaler + .5;
pict_info[i].width = pict_info[i].orig_width * x_scaler + .5;
}
success = TRUE;
} while (0);
if (file)
fclose(file);
if (raw_info)
free(raw_info);
if (success)
A00036 |= CONFIG_PICTURES;
else {
A00044 &= ~GRAPHICS_FLAG;
if (filename)
fprintf(stderr, "Warning: could not read graphics file %s\n", filename);
}
}
/* Convert a Z picture number to an index into pict_info. */
static int z_num_to_index(int n)
{
int i;
for (i = 0; i <= num_pictures; i++)
if (pict_info[i].z_num == n)
return i;
return -1;
}
bool A00222(int num, int *height, int *width)
{
int index;
*height = 0;
*width = 0;
if (!pict_info)
return FALSE;
if ((index = z_num_to_index(num)) == -1)
return FALSE;
*height = pict_info[index].height;
*width = pict_info[index].width;
return TRUE;
}
void A00213 (int num, int row, int col)
{
int width, height, r, c;
if (!A00222(num, &height, &width) || !width || !height)
return;
col--, row--;
/* Draw corners */
A00020(row, col, '+');
A00020(row, col + width - 1, '+');
A00020(row + height - 1, col, '+');
A00020(row + height - 1, col + width - 1, '+');
/* sides */
for (c = col + 1; c < col + width - 1; c++) {
A00020(row, c, '-');
A00020(row + height - 1, c, '-');
}
for (r = row + 1; r < row + height - 1; r++) {
A00020(r, col, '|');
A00020(r, col + width - 1, '|');
}
/* body, but for last line */
for (r = row + 1; r < row + height - 2; r++)
for (c = col + 1; c < col + width - 1; c++)
A00020(r, c, ':');
/* Last line of body, including picture number. */
if (height >= 3)
for (c = col + width - 2; c > col; c--, (num /= 10))
A00020(row + height - 2, c, num ? (num % 10 + '0') : ':');
}
int A00221 (void) {return BLACK_COLOUR; }