-
Notifications
You must be signed in to change notification settings - Fork 1
/
PCX2REC.CPP
349 lines (312 loc) · 7.24 KB
/
PCX2REC.CPP
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// „¥áᨠâ®à ¤«ï ⪠檮£® áâ ª
#include <stdlib.h>
#include <conio.h>
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <fcntl.h>
#include <dos.h>
#include <alloc.h>
#include "famegraf.h"
#include "mouse.h"
#include "dialog.h"
block hidscr;
int yesno(char *);
void info(char *t);
void message(char *t);
unsigned long PckBlock(block src, unsigned long lenblk);
void f_help(void);
void f_quit(void); //¢ë室 ¢ ¤®á
void f_set(void);
void f_setup(void);
void send_rom(void);
void print_info(void);
void print_utok(void);
void print_osnova(void);
void print_fact(void);
void print_bigfact(void);
void print_smallfact(void);
void choose_utok(void);
void choose_osnova(void);
void choose_fact(void);
void do_fact(void);
void f_disk(void);
void print_hat(void);
unsigned char set_rgb(unsigned char n);
void read_shabl(void);
void save_shabl(void);
void save_col(void);
void save_npcx(void);
void f_clearfact(void);
void f_new(void);
void pcx_bin(void);
void bin_rom(void);
void show_bin(void);
void show_pcx(void);
void run_ani(void);
//íâ® ª ª cut insert ¢ Windows
void savepocket(void);
void restorepocket(void);
//Mouse m;
//Panel p;
#define xsp 240
#define ysp 30
#define maxROM 1806336L
struct RGB {
char R;
char G;
char B;
};
//®¯¨á ¨¥ ‡ £®«®¢®ª PCX:
struct {
char manuf; // ‚ᥣ¤ =10 ¤«ï Paintbrush
char hard; // ˆä®à¬ æ¨ï ® ¢¥àᨨ
char encod; // ƒà㯯®¢®¥ ª®¤¨à®¢ ¨¥(=1)
char bitpx; // ¨â â®çªã
int x1; // §¬¥àë ª à⨪¨(¢ª«îç¨â.)
int y1;
int x2;
int y2;
int hres; // ƒ®à¨§.à §à¥è¥¨¥ ¤¨á¯«¥ï
int vres; // ‚¥à⨪.à §à¥è¥¨¥ ¤¨á¯«¥ï
char clrma[48]; // «¨âà
char vmode; // (¨£®à¨àã¥âáï)
char nplanes; // Š®«-¢® ¯«®áª®á⥩ (¢¥à.2.5=0)
int bplin; // ©â áâபã
int palinfo; // ˆä®à¬.® ¯ «¨âॠ(1=æ¢.,2=á¥à)
int shres; // §à¥è¥¨¥ ᪠¥à
int svres;
char xtra[54]; // „®¯.¯ãá⮥ ¬¥áâ® (䨫ìâà)
} Pcx={
10,
5,
1,
8,
0,
0,
1343,
499,
320,
200,
"",
0,
1,
1344,
1,
0,
0,
""
};
#define Headersize 128L
//䨪á¨à®¢ . ¤«¨ ¨ä. á«®¢ ¢ áâப¥!!!!
#define fixlen 169
struct {
unsigned int CRC; //CRC-16bit ª®â஫ì ï á㬬
char pack; //§ à娢¨à. ¨«¨ ¥â
char typ; //⨯ à¨áãª
char nutok,nosnova; //ª®«-¢® ¨â¥© ®á. ¢ ä ªâ ¨ ª®«-¢® ã⪮¢
unsigned int lx,ly; //à §¬¥à ª à⨪¨ ¢ â®çª å
unsigned int bplin; //ª®«-¢® ¡ ©â áâபã
unsigned int leftx,rightx; //¯ãá⮩ ®âáâ㯠᫥¢ ¨ á¯à ¢
} ROMhead={
00,
0,0,6,8,
1344,500,
168,
00,00
};
const unsigned char mask[8]={128,64,32,16,8,4,2,1};
//¤«ï AND
const unsigned char mask0[8]={127,191,223,239,247,251,253,254};
//¤«ï OR
const unsigned char sizes[10]={7,8,9,10,11,12,13,14,15,16};
struct shablon {
//â®«é¨ ¨â¨ ãâª
unsigned char siz_utok[6];
//â®«é¨ ¨â¨ ®á®¢ë
unsigned char siz_osnova[8];
//ä ªâãà
//梥â ãâª
RGB col_utok[6];
//梥⠨⨠®á®¢ë
RGB col_osnova[8];
//"梥â" ä ªâãàë (ª ¦¤®© ¨§ 64)
RGB col_fact[64];
unsigned char fact[64][8][6];
};
shablon s; //⥪ãé ï ®¡« ¤«ï à ¡®âë
//¤«ï á®åà. ¯à¨ । ªâ¨à® ¨¨
unsigned char pocket[8][6];
unsigned char tek_utok;
unsigned char tek_osnova;
unsigned char tek_fact;
block menu;
block tfnt;
block tmp;
char stroka[64];
char stroka0[64];
char stroka1[64];
char name0[16]="noname";
char name1[16]="noname1";
void main(int argc, char *argv[]) {
int x,y,i,j,t,u,old_butt;
int fdz,fdz1;
puts("PCX2REC by BMV \n example: pcx2rec rec.pcx");
// if( strlen(argv[1])==0 ) {
// fatalerror("¥ § ¤ ä ©«");
// }
strcpy(stroka,argv[1]);
hidscr=(block)famemalloc((unsigned long)320*200);
tmp=(block)famemalloc((unsigned long)320*200);
SetLib("graph");
pcx_bin();
if ( (fdz=open ("reclama.pic",O_BINARY | O_RDWR)) < 0) {
fatalerror("” ©« .pic ¥ ©¤¥!");
}
if (read (fdz, hidscr,(unsigned long)320*200)==-1 ) {
fatalerror("¥ ¬®£ã áç¨â âì à¨á㮪");
return;
}
close(fdz);
//§ ¯¨áì
PutLib("reclama.pic",hidscr,(unsigned long)320*200);
remove("reclama.pic");
PackLib();
SetLib("");
puts("¢á¥ ¯à®è«® ŽŠ!");
}
void fatalerror(char *t) {
//¢ë室 ¯® ä ⠫쮩 ®è¨¡ª¥
SetLib("");
puts(t);
exit(1);
}
void pcx_bin(void) {
int fdz,fdz1;
unsigned char data,repeatcount,lencod;
unsigned int Xl,Yl;
if ( (fdz=open (stroka,O_BINARY | O_RDWR)) < 0) {
fatalerror("” ©« .PCX ¥ ©¤¥!");
}
if (read (fdz, tmp,Headersize)==-1 ) {
fatalerror("¥ ¬®£ã áç¨â âì § £®«®¢®ª");
return;
}
lseek (fdz,128,SEEK_SET);
_fmemcpy((block)&Pcx,tmp,Headersize);
//---------------- à §¬¥àë ª à⨪¨ ---------------
ROMhead.lx=Xl=Pcx.x2-Pcx.x1+1; ROMhead.ly=Yl=Pcx.y2-Pcx.y1+1;
ROMhead.bplin=ROMhead.lx/8;
if(ROMhead.lx%8) { //¥á«¨ § ¨¬ ¥â ¥é¥ ¥¯®«. ¡ ©â
++ROMhead.bplin;
}
ROMhead.leftx=(fixlen-ROMhead.bplin)/2;
ROMhead.rightx=(fixlen-ROMhead.bplin-ROMhead.leftx);
//-------------------------------------------------
//if( ((long)Xl*(long)Yl)>320*200 ) {
// fatalerror(" §¬¥àë (®¡ê¥¬) à¨á㪠¡®«¥¥ 320*200");
// return;
//}
_creat("reclama.pic",FA_ARCH);
if ( (fdz1=open ("reclama.pic",O_BINARY | O_RDWR)) < 0) {
fatalerror("¥ ¬®£ã ®âªàëâì ¤«ï § ¯¨á¨ ä ©«");
return;
}
puts("®¤®¦¤¨â¥! ˆ¤¥â à ᯠª®¢ª à¨á㪠...");
while (1) {
if (read (fdz, &data, 1) == -1) {
fatalerror("Žè¨¡ª ç⥨ï");
close(fdz);
close(fdz1);
return;
}
//if ( (Yl&7)==0 ) {
//MoveXY(290,190);char_fgd=16; char_bkgd=31;vprint("%04u",Yl);
//SetColor(12); Bar(220,191,(int)max(99-(99*(long)Yl/ROMhead.ly),1),8);
//}
if ( (data & 0xC0)==0xC0 ) { /*ãáâ ®¢«¥ë «¨ ¯¥à¢ë¥ 2 ¡¨â */
repeatcount=(data & 0x3F);
if ( read (fdz, &data, 1) == -1 ) {
fatalerror("Žè¨¡ª ç⥨ï");
close(fdz);
close(fdz1);
return;
}
}
else {
repeatcount=1;
}
lencod=repeatcount;
do { //¢ë¢®¤ à ᪮¤¨à®¢. ¤ ëå
tmp[--repeatcount]=data;
/*¯à®¢¥àª ª®æ ä ©« */
if(!(--Xl)) {
Xl=Pcx.x2-Pcx.x1+1;
if(!(--Yl)) {
if ( write (fdz1, tmp, (int)lencod) == -1 ) {
fatalerror("Žè¨¡ª § ¯¨á¨");
}
close(fdz);
close(fdz1);
puts("” ©« .BIN ᮧ¤ ãᯥè®");
return;
}
}
} while (repeatcount);
if (write (fdz1, tmp, lencod) == -1 ) {
fatalerror("Žè¨¡ª § ¯¨á¨");
close(fdz);
close(fdz1);
return;
}
}
}
unsigned long PckBlock(block src, unsigned long lenblk) {
static unsigned char t,l,cl;
static unsigned long dpos,spos;
cl=dpos=spos=0;
//pakdest=(block)famemalloc((unsigned long)(lenblk+3));
t=src[spos];
for ( spos=0; spos<lenblk; spos++ ) {
l=t; //¯à¥¤ë¤ã騩 ᨬ¢®«
t=src[spos]; //¢®§¬¥¬ ®¢ë© ᨬ¢
if (l==t) { //®¢ë© ᨬ¢®« à ¢¥ ¯à¥¤ë¤ã饬ã
cl++;
if (cl>63) { //ª®«-¢® ®¤¨ ª®¢ëå ᨬ¢ ¯à¥¢ëᨫ® 64
//§ ª®¤¨à § £®«®¢®ª 11åååååå & ᨬ¢®«
pakdest[dpos++]= (0xff); //63
pakdest[dpos++]= l;
cl=1;
}
} else { //®¢ë© ᨬ¢®« ¥ à ¢¥ ¯à¥¤ë¤ã饬ã
if (cl>1) { //§ ¯¨áì 楯®çª¨
pakdest[dpos++]= (0xc0 | cl);
pakdest[dpos++]= l;
} else { //ᨬ¢®« ¡¥§ 2å ¯¥à¢ ¡¨â
if (l>127) { //§ ¯¨áì 楯®çª¨
pakdest[dpos++]= 0xc1; //1
pakdest[dpos++]= l;
} else {
pakdest[dpos++]= l;
}
}
cl=1;
}
//if (dpos>=lenblk) {
//®è¨¡ª -¯¥à¥¯®«¥¨¥ ¯à¨ à娢 樨
// return (dpos);
//}
} //ª®¥æ ®á. 横«
if (cl >1) {
pakdest[dpos++]= (0xc0 | cl);
pakdest[dpos++]= l;
} else {
if (t>127) { //§ ¯¨áì 楯®çª¨
pakdest[dpos++]= 0xc1; //63
pakdest[dpos++]= t;
} else {
pakdest[dpos++]= t;
}
}
return (dpos);
}