Browse Source

[util] Add optional debug messages to zbin.c

tags/v0.9.6
Michael Brown 16 years ago
parent
commit
96ea558e98
1 changed files with 27 additions and 0 deletions
  1. 27
    0
      src/util/zbin.c

+ 27
- 0
src/util/zbin.c View File

6
 #include "nrv2b.c"
6
 #include "nrv2b.c"
7
 FILE *infile, *outfile;
7
 FILE *infile, *outfile;
8
 
8
 
9
+#define DEBUG 0
10
+
9
 struct input_file {
11
 struct input_file {
10
 	void *buf;
12
 	void *buf;
11
 	size_t len;
13
 	size_t len;
151
 		return -1;
153
 		return -1;
152
 	}
154
 	}
153
 
155
 
156
+	if ( DEBUG ) {
157
+		fprintf ( stderr, "COPY [%#zx,%#zx) to [%#zx,%#zx)\n", offset, ( offset + len ),
158
+			  output->len, ( output->len + len ) );
159
+	}
160
+
154
 	memcpy ( ( output->buf + output->len ),
161
 	memcpy ( ( output->buf + output->len ),
155
 		 ( input->buf + offset ), len );
162
 		 ( input->buf + offset ), len );
156
 	output->len += len;
163
 	output->len += len;
184
 		return -1;
191
 		return -1;
185
 	}
192
 	}
186
 
193
 
194
+	if ( DEBUG ) {
195
+		fprintf ( stderr, "PACK [%#zx,%#zx) to [%#zx,%#zx)\n", offset, ( offset + len ),
196
+			  output->len, ( output->len + packed_len ) );
197
+	}
198
+
187
 	output->len += packed_len;
199
 	output->len += packed_len;
188
 	if ( output->len > output->max_len ) {
200
 	if ( output->len > output->max_len ) {
189
 		fprintf ( stderr, "Output buffer overrun on pack\n" );
201
 		fprintf ( stderr, "Output buffer overrun on pack\n" );
200
 	size_t offset = subtract->offset;
212
 	size_t offset = subtract->offset;
201
 	void *target;
213
 	void *target;
202
 	long delta;
214
 	long delta;
215
+	unsigned long old;
216
+	unsigned long new;
203
 
217
 
204
 	if ( ( offset + datasize ) > output->len ) {
218
 	if ( ( offset + datasize ) > output->len ) {
205
 		fprintf ( stderr, "Subtract at %#zx outside output buffer\n",
219
 		fprintf ( stderr, "Subtract at %#zx outside output buffer\n",
214
 	switch ( datasize ) {
228
 	switch ( datasize ) {
215
 	case 1: {
229
 	case 1: {
216
 		uint8_t *byte = target;
230
 		uint8_t *byte = target;
231
+		old = *byte;
217
 		*byte += delta;
232
 		*byte += delta;
233
+		new = *byte;
218
 		break; }
234
 		break; }
219
 	case 2: {
235
 	case 2: {
220
 		uint16_t *word = target;
236
 		uint16_t *word = target;
237
+		old = *word;
221
 		*word += delta;
238
 		*word += delta;
239
+		new = *word;
222
 		break; }
240
 		break; }
223
 	case 4: {
241
 	case 4: {
224
 		uint32_t *dword = target;
242
 		uint32_t *dword = target;
243
+		old = *dword;
225
 		*dword += delta;
244
 		*dword += delta;
245
+		new = *dword;
226
 		break; }
246
 		break; }
227
 	default:
247
 	default:
228
 		fprintf ( stderr, "Unsupported subtract datasize %d\n",
248
 		fprintf ( stderr, "Unsupported subtract datasize %d\n",
229
 			  datasize );
249
 			  datasize );
230
 		return -1;
250
 		return -1;
231
 	}
251
 	}
252
+
253
+	if ( DEBUG ) {
254
+		fprintf ( stderr, "SUBx [%#zx,%#zx) (%#lx+(%#lx/%#lx)-(%#lx/%#lx)) = %#lx\n",
255
+			  offset, ( offset + datasize ), old, output->len, subtract->divisor,
256
+			  input->len, subtract->divisor, new );
257
+	}
258
+
232
 	return 0;
259
 	return 0;
233
 }
260
 }
234
 
261
 

Loading…
Cancel
Save