-
Notifications
You must be signed in to change notification settings - Fork 0
/
showdizzy.c
148 lines (110 loc) · 2.48 KB
/
showdizzy.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define BITSPERBYTE 8
#define HEADERBYTES 2
#define WIDTH 48
#define NUMFRAMES 39
//#define ASMOUT 1
void drawbin(const unsigned char *data)
{
unsigned char mask=0x80;
while (mask>0)
{
printf("%c", (((*data)&mask)>0)?'#':' ');
printf("%c", (((*data)&mask)>0)?'#':' ');
mask>>=1;
}
}
void hexbin(const unsigned char *data)
{
unsigned char mask=0x80;
fprintf(stderr, "%%");
while (mask>0)
{
fprintf(stderr, "%c", (((*data)&mask)>0)?'1':'0');
mask>>=1;
}
fprintf(stderr, ",");
}
void drawbin_width(const unsigned char *data, const unsigned char width, const unsigned char mask)
{
unsigned char done=0;
#ifdef ASMOUT
if (!mask) fprintf(stderr, "EQUB ");
#endif
printf("|");
while ((done*8)<width)
{
if (((mask) && (!(done&1))) || ((!mask) && (done&1)))
drawbin(&data[done]);
#ifdef ASMOUT
if ((!mask) && (done&1))
hexbin(&data[done]);
#endif
done++;
}
if (!mask)
printf("|\n");
#ifdef ASMOUT
if (!mask)
fprintf(stderr, "\n");
#endif
}
int main()
{
FILE *rd;
struct stat fs;
uint8_t *framedata;
rd=fopen("dizzyfrm.bin", "rb");
if (rd==NULL) return 1;
fstat(fileno(rd), &fs);
framedata=malloc(fs.st_size);
if (framedata!=NULL)
{
int frame;
fread(framedata, fs.st_size, 1, rd);
fclose(rd);
// Process it
for (frame=0; frame<NUMFRAMES; frame++)
{
int start;
start=(framedata[frame*2]);
start=((framedata[(frame*2)+1]<<8)+start);
// Check for valid pointer
if (start<0xff00)
{
int width, height;
int offs;
int y;
printf("%d [%.2x] : 0x%.4x", frame, frame, start);
height=framedata[(NUMFRAMES*2)+start];
printf(" (%dx%d) / %.2x\n", WIDTH, height, framedata[(NUMFRAMES*2)+start+1]);
#ifdef ASMOUT
fprintf(stderr, ".frame%.2d\n", frame);
fprintf(stderr, "EQUB %.2d,%.2d\n", height, framedata[(NUMFRAMES*2)+start+1]);
#endif
// Decode the framedata
offs=0;
for (y=0; y<height; y++)
{
drawbin_width(&framedata[(NUMFRAMES*2)+start+HEADERBYTES+offs], WIDTH, 1);
drawbin_width(&framedata[(NUMFRAMES*2)+start+HEADERBYTES+offs], WIDTH, 0);
offs+=(WIDTH/8);
}
printf("\n");
}
}
free(framedata);
}
else
{
fclose(rd);
return 1;
}
return 0;
}