Commit 9f5bc91

Nick Faro committed on
Refactor GD3 writing
commit 9f5bc91d0c4995b1c87193ca70672037714c8cda parent e1adc14
1 changed files +27−24
Modifiedvgm.pas +27−24
@@ -101,11 +101,22 @@ var
101 VGMFile: TFileStream; 101 VGMFile: TFileStream;
102 TotalWaitSamps: Integer; 102 TotalWaitSamps: Integer;
103 103
104 procedure WriteUtf16String(S: String);
105 var
106 Utf16Bytes: TBytes;
107 begin
108 if Length(S) > 0 then begin
109 Utf16Bytes := WideBytesOf(UTF8Decode(S));
110 VGMFile.WriteBuffer(Utf16Bytes[0], Length(Utf16Bytes));
111 end;
112 VGMFile.WriteWord(0);
113 end;
114
104 procedure ExportVGMFile(F: String; TrackName: String; ArtistName: String; Comments: String); 115 procedure ExportVGMFile(F: String; TrackName: String; ArtistName: String; Comments: String);
105 var 116 var
106 OldFD, OldFC, OldF4: TCPUCallback; 117 OldFD, OldFC, OldF4: TCPUCallback;
107 Header: TVGMHeader; 118 Header: TVGMHeader;
108 Utf16Bytes: TBytes; 119
109 YY,MM,DD: Word; 120 YY,MM,DD: Word;
110 GD3Temp: Integer; 121 GD3Temp: Integer;
111 begin 122 begin
@@ -136,6 +147,8 @@ begin
136 z80_decode 147 z80_decode
137 until StartOfSong <> -1; 148 until StartOfSong <> -1;
138 149
150 VGMFile.WriteByte($66); // End of data
151
139 WritingVGM := False; 152 WritingVGM := False;
140 153
141 // Update the header to point to the GD3 tag, then write it 154 // Update the header to point to the GD3 tag, then write it
@@ -146,31 +159,21 @@ begin
146 159
147 GD3Temp := VGMFile.Position; 160 GD3Temp := VGMFile.Position;
148 VGMFile.WriteDWord(0); // dummy value... 161 VGMFile.WriteDWord(0); // dummy value...
149 Utf16Bytes := WideBytesOf(UTF8Decode(TrackName));
150 VGMFile.WriteBuffer(Utf16Bytes[0], Length(Utf16Bytes)); // English name
151 VGMFile.WriteWord(0);
152 162
153 VGMFile.WriteWord(0); // No japanese track name
154 VGMFile.WriteWord(0); // No game name
155 VGMFile.WriteWord(0); // No japanese game name
156 Utf16Bytes := WideBytesOf('Nintendo Game Boy');
157 VGMFile.WriteBuffer(Utf16Bytes[0], Length(Utf16Bytes));
158 VGMFile.WriteWord(0);
159 VGMFile.WriteWord(0); // No japanese system name
160 Utf16Bytes := WideBytesOf(UTF8Decode(ArtistName));
161 VGMFile.WriteBuffer(Utf16Bytes[0], Length(Utf16Bytes));
162 VGMFile.WriteWord(0);
163 VGMFile.WriteWord(0); // No japanese author name
164 DecodeDate(Date, YY, MM, DD); 163 DecodeDate(Date, YY, MM, DD);
165 Utf16Bytes := WideBytesOf(UTF8Decode(Format('%d/%.2d/%.2d', [YY, MM, DD]))); 164
166 VGMFile.WriteBuffer(Utf16Bytes[0], Length(Utf16Bytes)); 165 WriteUtf16String(TrackName); // English track name
167 VGMFile.WriteWord(0); 166 WriteUtf16String(''); // Japanese track name
168 Utf16Bytes := WideBytesOf('hUGETracker'); 167 WriteUtf16String(''); // English game name
169 VGMFile.WriteBuffer(Utf16Bytes[0], Length(Utf16Bytes)); 168 WriteUtf16String(''); // Japanese game name
170 VGMFile.WriteWord(0); 169 WriteUtf16String('Nintendo Game Boy'); // English system name
171 Utf16Bytes := WideBytesOf(UTF8Decode(Comments)); 170 WriteUtf16String(''); // Japanese system name
172 VGMFile.WriteBuffer(Utf16Bytes[0], Length(Utf16Bytes)); 171 WriteUtf16String(ArtistName); // English artist name
173 VGMFile.WriteWord(0); 172 WriteUtf16String(''); // Japanese artist name
173 WriteUtf16String(Format('%d/%.2d/%.2d', [YY, MM, DD])); // Creation date
174 WriteUtf16String('hUGETracker'); // Program name
175 WriteUtf16String(''); // Japanese program name
176 WriteUtf16String(Comments); // Comments
174 177
175 // Go back and overwrite that dummy (unnecessary) length value. 178 // Go back and overwrite that dummy (unnecessary) length value.
176 // The VGM and GD3 formats sure are ugly. Not that UGE is any better. 179 // The VGM and GD3 formats sure are ugly. Not that UGE is any better.