source: oup/releases/0.25a/src/Unit4_Exporters.pas@ 8

Last change on this file since 8 was 8, checked in by alloc, 18 years ago

Uploaded old revs and structdefs.

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