-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxgf2src.pas
360 lines (309 loc) · 9.85 KB
/
xgf2src.pas
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
350
351
352
353
354
355
356
357
358
359
360
{$mode TP}
{$PACKRECORDS 1}
Unit xgf2src;
Interface
uses SysUtils,FileUtil,rwxgf;
Function XgfToSrc(XgfFile,SrcFile:string;myWidth,myHeight,nColors,myformat,myComp:Word):word;
Procedure FilenameToImageName(Var filename,Imagename : string);
Implementation
Procedure Byte2str(mybyte : byte;Var mystring :string);
const
hexa : array[0..15] of char=('0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F');
var
h1,h2 : byte;
begin
h1:=mybyte shr 4;
h2:=mybyte shl 4;
h2:=h2 shr 4;
mystring:=hexa[h1]+hexa[h2];
end;
Procedure WriteHeaders(Var F : Text;myImageName : String; myWidth,myHeight,Ncolors,
myComp, myFormat:Word;myfilesize : LongInt);
Const
xprForm : array[SprSource..PPRSource] of String = ('SPR','','PPR');
Var
myRunCount : LongInt;
begin
{$I-}
If myFormat = SPRSource then
begin
myRunCount:=myFileSize div 2;
end
else
begin
myRunCount:=(myFileSize div 3)*2;
end;
Case myFormat of Source2..Source256:
begin
Case myComp of TPLan:
begin
WriteLn(F,'(* Turbo Pascal, Width= ',myWidth,
' Height= ',myHeight,' Colors= ',Ncolors,' *)');
end;
FPLan:
begin
WriteLn(F,'(* FreePascal, Width= ',myWidth,
' Height= ',myHeight,' Colors= ',Ncolors,' *)');
end;
TCLan:
begin
Writeln(F,'/* Turbo C, Width= ',myWidth,
' Height= ',myHeight,' Colors= ',Ncolors,' */');
end;
QCLan:
begin
Writeln(F,'/* QuickC, Width= ',myWidth,
' Height= ',myHeight,' Colors= ',Ncolors,' */');
end;
QBLan:
begin
Writeln(F,#39,' QuickBASIC\QB64, Array Size= ',myFileSize div 2,
' Width= ',myWidth,' Height= ',myHeight,' Colors= ',Ncolors);
Writeln(F,#39,' ',myImageName);
end;
FBLan:
begin
Writeln(F,#39,' FreeBASIC, Array Size= ',myFileSize div 2,
' Width= ',myWidth,' Height= ',myHeight,' Colors= ',Ncolors);
Writeln(F,#39,' ',myImageName);
end;
ABLan:
begin
Writeln(F,#39,' AmigaBASIC, Array Size= ',myFileSize div 2,
' Width= ',myWidth,' Height= ',myHeight,' Colors= ',Ncolors);
Writeln(F,#39,' ',myImageName);
end;
PBLan:
begin
Writeln(F,#39,' PowerBASIC, Array Size= ',myFileSize div 2,
' Width= ',myWidth,' Height= ',myHeight,' Colors= ',Ncolors);
Writeln(F,#39,' ',myImageName);
end;
GWLan:
begin
Writeln(F,'1000 ',#39,' ',myImageName);
Writeln(F,'1010 ',#39,' GWBASIC, Array Size= ',myFileSize div 2,
' Width= ',myWidth,' Height= ',myHeight,' Colors= ',Ncolors);
end;
End;
End;
SPRSource,PPRSource:
begin
Case myComp of TPLan:
begin
Writeln(F,'(* Width= ',myWidth,' Height= ',myHeight,
' Colors= ',Ncolors,' Format= ',xprForm[myFormat],' RunCount= ',myRunCount,' *)');
end;
TCLan,QCLan:
begin
Writeln(F,'/* Width= ',myWidth,' Height= ',myHeight,
' Colors= ',Ncolors,' Format= ',xprForm[myFormat],' RunCount= ',myRunCount,' */');
end;
QBLan,PBLan:
begin
Writeln(F,#39,' ',myImageName);
Writeln(F,#39,' Width= ',myWidth,' Height= ',myHeight,' Colors= ',Ncolors);
Writeln(F,#39,' String Size= ',myFileSize,' Format= ',xprForm[myFormat],' RunCount= ',myRunCount)
end;
End;
End;
PALSource:
begin
Case myComp of TPLan:
begin
Writeln(F,'(* Pascal Palette Source, ',NColors,' Colors (RGB) *)');
end;
TCLan,QCLan:
begin
Writeln(F,'/* C Palette Source, ',NColors,' Colors (RGB) */');
end;
QBLan,PBLan:
begin
Writeln(F,#39,' BASIC Palette Source, ',NColors,' Colors (RGB)');
end;
End;
End;
End;
if myComp=GWLan then
begin
writeln(F,'1020 ',#39);
end
else
begin
Writeln(F);
end;
If (myComp = TPlan) OR (myComp =FPLan) then
begin
WriteLn(F,myImageName, ' : Array[1..',myFileSize,'] of Byte = (');
end
Else if (myComp = QCLan) or (myComp = TCLan) then
begin
WriteLn(F,'char ',myImageName,'[',myFileSize,'] = {');
end;
{$I+}
end;
Procedure FilenameToImageName(Var filename,Imagename : string);
begin
Imagename:=ExtractFileName(ExtractFileNameWithoutExt(filename));
end;
Function XgfToSrc(XgfFile,SrcFile:string;myWidth,myHeight,nColors,myformat,myComp:Word):word;
Type
ImgBuf = array[1..60000] of byte;
Var
F : Text;
f2 : file;
Error : Word;
i : LongInt;
mybyte : integer;
RunCount : longint;
myImageName : String;
NumRead : Longint;
NumPerLine : Word;
Counter : Word;
NumToRead : LongInt;
S,S2 : String;
myWord : Word;
myFileSize : LongInt;
myPercent : Longint;
myLineNumber : Word;
myxprHeader:Array[1..24] of byte;
myBuf : ^ImgBuf;
begin
{$I-}
myLineNumber:=1040;
FilenameToImagename(SrcFile,myImageName);
Numread:=0;
NumPerLine:=12;
Case myComp of GWLan,PBLan,QBLan,FBLan,ABLan: begin
if myFormat < SPRBinary then NumPerLine:=8;
end;
End;
Counter:=0;
Assign(F,Srcfile);
Rewrite(F);
Assign(F2,XgfFile);
reset(F2,1);
myFileSize:=FileSize(F2);
Case myFormat of SPRSource:begin
Dec(myFileSize,16);
BlockRead(F2,myXprHeader,16);
end;
PPRSource:begin
Dec(myFileSize,24);
BlockRead(F2,myXprHeader,24);
end;
end;
NumToRead:=myFilesize;
(*
Case myComp of QBLan,PBLan,GWLan: if myformat < SPRBinary then NumToRead:=myFileSize div 2;
End;
*)
WriteHeaders(F,myImageName,myWidth,myHeight,nColors,myComp,myFormat,myFileSize);
Case myComp of QBLan,PBLan,FBLan,ABLan: Write(F,'DATA ');
GWLan: Write(F,'1030 DATA ');
else
Write(F,'':10);
End;
GetMem(myBuf,NumToRead);
BlockRead(F2,myBuf^,NumToREad);
NumRead:=0;
i:=1;
Repeat
case myComp of TPlan,FPLan: Write(F,'$');
GWLan,QBLan,PBLan,FBLan,ABLan: Write(F,'&H');
TCLan,QCLan: Write(F,'0x');
end;
Case myComp of GWLan,QBLan,PBLan,FBLan,ABLan:
begin
If myFormat<SPRsource then
begin
myWord:=(myBuf^[i+1] SHL 8) + myBuf^[i];
Inc(NumRead,2);
Inc(i,2);
Byte2Str(Hi(myWord),S);
Byte2Str(Lo(myWord),S2);
//insert code here for Amiga Byte swapping for integer
if myComp = ABLan then
begin
Write(F,S2,S);
end
else
begin
Write(F,S,S2);
end;
end
else
begin
myByte:=myBuf^[i];
Inc(NumRead);
Inc(i);
Byte2Str(myByte,S);
Write(F,S:2);
end;
end;
TCLan,QCLan,TPLan,FPLan:
begin
myByte:=myBuf^[i];
Inc(NumRead);
Inc(i);
Byte2Str(myByte,S);
Write(F,S:2);
end;
end;
inc(Counter);
if Counter=NumPerLine then
begin
Counter:=0;
If NumRead<NumToRead then
begin
Case myComp of QBLan,PBLan,FBLan,ABLan : begin
WriteLn(F);
Write(F,'DATA ');
end;
GWLan : begin
WriteLn(F);
Write(F,myLineNumber,' DATA ');
inc(myLineNumber,10);
end;
QCLan,TCLan,TPLan,FPLan:begin
WriteLn(F,',');
Write(F,'':10);
end;
end;
end;
end
else
begin
If NumRead < NumToRead then
begin
Write(F,',');
end;
end;
error:=ioresult;
if error<>0 then
begin
close(f);
close(f2);
erase(f);
FreeMem(myBuf,NumToRead);
XgfToSrc:=error;
Error:=IORESULT;
exit;
end;
Until i > NumToRead;
FreeMem(myBuf,NumToRead);
Case myComp of QCLan,TCLan:writeln(F,'};');
TPLan,FPLan:writeln(F,');');
End;
Close(F);
close(F2);
if error<>0 then
begin
erase(f);
end;
XgfToSrc:=IOResult;
{$I+}
end;
begin
end.