source: oup/releases/0.29a3/Unit4_Exporters.pas@ 455

Last change on this file since 455 was 31, checked in by alloc, 18 years ago
File size: 6.8 KB
RevLine 
[31]1UNIT Unit4_Exporters;
2INTERFACE
3USES Classes, Dialogs, StrUtils, SysUtils, Math, Unit3_data, Unit6_imgfuncs;
4
5PROCEDURE ExportDatFile(fileid:LongWord; filename:String);
6PROCEDURE ExportRawFile(fileid:LongWord; dat_offset:LongWord; filename:String);
7
8FUNCTION ExportSNDD(fileid:LongWord; filename:String; convert:Boolean):Integer;
9FUNCTION ExportTRAC(fileid:LongWord; filename:String; convert:Boolean):Integer;
10FUNCTION ExportTXAN(fileid:LongWord; filename:String; convert:Boolean):Integer;
11FUNCTION ExportTXMB(fileid:LongWord; filename:String; convert:Boolean):Integer;
12FUNCTION ExportTXMP(fileid:LongWord; filename:String; convert:Boolean):Integer;
13VAR
14 ExportHandlers:Array[1..1] OF TExportHandlers=(
15// (Ext:'ABNA'; needed:False),
16 //(Ext:'AGDB'; needed:False),
17 (Ext:'SNDD'; needed:True; Handler:ExportSNDD)
18{ (Ext:'TRAC'; needed:True; Handler:ExportTRAC),
19 (Ext:'TXAN'; needed:True; Handler:ExportTXAN),
20 (Ext:'TXMB'; needed:True; Handler:ExportTXMB),
21 (Ext:'TXMP'; needed:True; Handler:ExportTXMP)
22} );
23
24
25
26IMPLEMENTATION
27USES Unit2_functions, Unit9_data_structures;
28
29PROCEDURE ExportDatFile(fileid:LongWord; filename:String);
30 VAR
31 filestream:TFileStream;
32 data:Tdata;
33 BEGIN
34 data:=LoadDatFile(fileid);
35 IF FileExists(filename) THEN BEGIN
36 filestream:=TFileStream.Create(filename,fmOpenReadWrite);
37 filestream.Seek(0,soFromEnd);
38 END ELSE BEGIN
39 filestream:=TFileStream.Create(filename,fmCreate);
40 END;
41 filestream.Write(data[0],Length(data));
42 filestream.Free;
43 END;
44
45PROCEDURE ExportRawFile(fileid:LongWord; dat_offset:LongWord; filename:String);
46 VAR
47 filestream:TFileStream;
48 data:Tdata;
49 BEGIN
50 SetLength(data, GetRawInfo(fileid, dat_offset).raw_size);
51 LoadRawFileByIDOffset(fileid,dat_offset,@data[0]);
52 IF FileExists(filename+'.raw0x'+IntToHex(dat_offset,8)) THEN BEGIN
53 filestream:=TFileStream.Create(filename+'.raw0x'+IntToHex(dat_offset,8),fmOpenReadWrite);
54 filestream.Seek(0,soFromEnd);
55 END ELSE BEGIN
56 filestream:=TFileStream.Create(filename+'.raw0x'+IntToHex(dat_offset,8),fmCreate);
57 END;
58 filestream.Write(data[0],Length(data));
59 filestream.Free;
60 END;
61
62FUNCTION ExportSNDD;
63{ CONST
64 WAVheader:Array[0..0] OF Byte=(
65 Ord('R'),Ord('I'),Ord('F'),Ord('F'),0,0,0,0,Ord('W'),Ord('A'),Ord('V'),Ord('E'),
66 Ord('f'),Ord('m'),Ord('t'),Ord(' '),24,0,0,0,
67 );
68} TYPE
69 TDatData=RECORD
70 {0x00}
71 _fileid:LongWord;
72 level:LongWord;
73 Flag:LongWord;
74 FormatTag:Word;
75 ChanNo:Word;
76 {0x10}
77 SampleRate:LongWord;
78 BytesPSec:LongWord;
79 BPSample:LongWord;
80 BitsPS:LongWord;
81 {0x20}
82 Unknown:Array[1..7] OF LongWord;
83 Unknown2:Word;
84 {0x40}
85 RawSize:LongWord;
86 RawPos:LongWord;
87 END;
88 VAR
89 filestream:TFileStream;
90
91 DatData:TDatData;
92 //Wave Header Stuff
93 ASCII_Group:LongWord; //"RIFF"
94 WAV_Len:LongWord;
95 ASCII_WAV:LongWord; //"WAVE"
96 ASCII_FMT:LongWord; //"fmt "
97 WAV_FMT_Len:LongWord;
98 ASCII_DATA:LongWord; //"data"
99 WAV_FolLen:LongWord;
100
101 data:Tdata;
102 BEGIN
103 Result:=export_noerror;
104 LoadDatFilePart(fileid,0,SizeOf(DatData),@DatData);
105 WITH DatData DO BEGIN
106 //Initializing Header vars
107 ASCII_Group:=1179011410; // 'RIFF'
108 WAV_Len:=RAWSize+70;
109 ASCII_WAV:=1163280727; // 'WAVE'
110 ASCII_FMT:=544501094; // 'fmt '
111 WAV_FMT_Len:=50; // 50 bytes
112 ASCII_DATA:=1635017060; // 'data'
113 WAV_FolLen:=RAWSize;
114 SetLength(data,RAWSize);
115 LoadRawFile(fileid,$44,rawpos,Length(data),False,data);
116
117 filestream:=TFileStream.Create(filename+'.raw',fmCreate);
118 filestream.Write(data[0],Length(data));
119 filestream.Free;
120
121 IF convert THEN BEGIN
122 //Now start packing this into a neat wave...
123 filestream:=TFileStream.Create(filename+'.wav',fmCreate);
124 filestream.Write(ASCII_Group,SizeOf(ASCII_Group));
125 filestream.Write(WAV_Len,SizeOf(WAV_Len));
126 filestream.Write(ASCII_WAV,SizeOf(ASCII_WAV));
127 filestream.Write(ASCII_FMT,SizeOf(ASCII_FMT));
128 filestream.Write(WAV_FMT_Len,SizeOf(WAV_FMT_Len));
129 filestream.Write(ChanNo,SizeOf(ChanNo));
130 filestream.Write(Samplerate,SizeOf(Samplerate));
131 filestream.Write(BytesPSec,SizeOf(BytesPSec));
132 filestream.Write(BPSample,SizeOf(BPSample));
133 filestream.Write(BitsPS,SizeOf(BitsPS));
134 filestream.Write(Unknown[1],SizeOf(Unknown));
135 filestream.Write(Unknown2,SizeOf(Unknown2));
136 filestream.Write(ASCII_DATA,SizeOf(ASCII_DATA));
137 filestream.Write(WAV_FolLen,SizeOf(WAV_FolLen));
138 filestream.Write(data[0],Length(data));
139 filestream.Free;
140 END;
141 END;
142 END;
143
144FUNCTION ExportTRAC;
145 VAR
146 link:LongWord;
147 linkcount:Word;
148 i:LongWord;
149 BEGIN
150 Result:=export_noerror;
151
152 LoadDatFilePart(fileid,$18,SizeOf(link),@link);
153 link:=link DIV 256;
154
155 LoadDatFilePart(fileid,$1E,SizeOf(linkcount),@linkcount);
156 FOR i:=1 TO linkcount DO BEGIN
157 LoadDatFilePart(fileid,$20+(i-1)*12+8,SizeOf(link),@link);
158 link:=link DIV 256;
159 END;
160 END;
161
162FUNCTION ExportTXAN;
163 VAR
164 loop_speed,unknown:Word;
165 linkcount:LongWord;
166 link:LongWord;
167 i:Byte;
168 BEGIN
169 Result:=export_noerror;
170
171 LoadDatFilePart(fileid,$14,SizeOf(loop_speed),@loop_speed);
172 LoadDatFilePart(fileid,$16,SizeOf(unknown),@unknown);
173
174 LoadDatFilePart(fileid,$1C,SizeOf(linkcount),@linkcount);
175 FOR i:=0 TO linkcount-1 DO BEGIN
176 LoadDatFilePart(fileid,$20+i*4,SizeOf(link),@link);
177 link:=link DIV 256;
178 IF link=0 THEN link:=fileid-1;
179 END;
180 END;
181
182FUNCTION ExportTXMB;
183 VAR
184 filestream:TFileStream;
185 img:TImgPackage;
186 data:Tdata;
187 BEGIN
188 Result:=export_noerror;
189 IF convert THEN BEGIN
190 img:=LoadTXMBconnected(fileid);
191 data:=ImgdataToBmp(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
192 filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
193 filestream.Write(data[0],Length(data));
194 filestream.Free;
195 END;
196 END;
197
198FUNCTION ExportTXMP;
199 VAR
200 filestream:TFileStream;
201 img:TImgPackage;
202 BEGIN
203 Result:=export_noerror;
204 img:=LoadImgData(fileid);
205
206 filestream:=TFileStream.Create(filename+'.raw',fmCreate);
207 filestream.Write(img.imgdata[0],Length(img.imgdata));
208 filestream.Free;
209
210 IF convert THEN BEGIN
211 img.imgdata:=ImgdataToBMP(img.imgx,img.imgy,img.imgdepth,img.storetype,img.imgdata);
212 filestream:=TFileStream.Create(filename+'.bmp',fmCreate);
213 filestream.Write(img.imgdata[0],Length(img.imgdata));
214 filestream.Free;
215 END;
216 END;
217
218END.
Note: See TracBrowser for help on using the repository browser.