Skip to content

Commit 8fe32cd

Browse files
remove constants to separate file; replace content with constat
1 parent 3135f1a commit 8fe32cd

File tree

5 files changed

+368
-340
lines changed

5 files changed

+368
-340
lines changed

smm-conv/src/inc/load_smm.inc

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Var
3030
Begin
3131
If f.getByte(noteTabId) Then exit;
3232
// read ID
33-
If noteTabId>maxNoteTables-1 Then haltError('Bad index of note table definition');
33+
If noteTabId>maxNoteTables-1 Then haltError(ERR_SMMFILE_NOTETABLE_BAD_ID);
3434

3535
f.getBlock(IOBuf,NOTETABnameLength+64);
3636
// read data
@@ -54,31 +54,31 @@ Begin
5454

5555
If (isSFX) Then
5656
Begin
57-
If id>maxSFXs-1 Then haltError('Bad index of SFX definition');
57+
If id>maxSFXs-1 Then haltError(ERR_SMMFILE_SFX_BAD_ID);
5858

5959
If f.getByte(_sfxMode) Then exit;
6060
// read SFX Modulation Type
61-
If _sfxMode>3 Then haltError('');
61+
If _sfxMode>3 Then haltError(ERR_SMMFILE_SFX_MOD_BAD_ID);
6262

6363
sfxmodes[id] := _sfxMode;
6464

6565
If f.getByte(_sfxNoteTabOfs) Then exit;
6666
// read SFX note table index
67-
If _sfxNoteTabOfs>3 Then haltError('Bad note table of SFX definition');
67+
If _sfxNoteTabOfs>3 Then haltError(ERR_SMMFILE_SFX_NOTETABLE_BAD_ID);
6868
sfxnote[id] := _sfxNoteTabOfs*$40;
6969
inc(totalSFX);
7070
End
7171
Else
7272
Begin
73-
If id-64>maxTABs-1 Then haltError('');
73+
If id-64>maxTABs-1 Then haltError(ERR_SMMFILE_TAB_BAD_ID);
7474
id := id-64;
7575

7676
inc(totalTAB);
7777
End;
7878

7979
If f.getBlock(dataSize,2) Then exit;
8080
// read data size
81-
If dataSize>256+nameLength Then haltError('Incorrect length of SFX/TAB data');
81+
If dataSize>256+nameLength Then haltError(ERR_SMMFILE_INCORRECT_DATA_LENGTH);
8282

8383
f.getBlock(IOBuf,dataSize);
8484
// read data
@@ -93,13 +93,15 @@ Begin
9393
move(IOBuf[0],sfxnames[id][1],len);
9494
sfxptr[id] := topPtr;
9595
sfxSizes[id] := dataSize;
96+
sfxUsage[id] := id;
9697
End
9798
Else
9899
Begin
99100
tabnames[id][0] := char(len);
100101
move(IOBuf[0],tabnames[id][1],len);
101102
tabptr[id] := topPtr;
102103
tabSizes[id] := dataSize;
104+
tabUsage[id] := id;
103105
End;
104106
move(IOBuf[nameLength],data[topPtr],dataSize);
105107
inc(topPtr,dataSize);
@@ -118,7 +120,7 @@ Begin
118120

119121
If f.getBlock(dataSize,2) Then exit;
120122
// read data size
121-
If dataSize>256 Then haltError('Incorrect song data length');
123+
If dataSize>256 Then haltError(ERR_SMMFILE_INCORRECT_SONG_DATA_LENGTH);
122124

123125
f.getBlock(song,dataSize);
124126
// read data
@@ -138,49 +140,49 @@ Begin
138140
End;
139141

140142
Begin
141-
// TODO: Sprawdź najpierw, czy plik źródłowy istnieje!
142-
// TODO: Przerwij z błędem, jeżeli nie istnieje!
143-
144143
if verbose>0 then
145144
begin
146-
writeLn(stdout);
147-
write(stdout,'Reading `'+fn+'` file...');
145+
EOLStdOut;
146+
writeStdOut(STDOUT_READING_SMM_FILE,[fn]);
148147
end;
148+
if not fileExists(fn) then
149+
haltError(ERR_SOURCE_NOT_EXIST);
150+
149151
totalSFX := 0;
150152
totalTAB := 0;
151153
f.openFile(fRead,fn);
152154
While (f.IOErr=0) And (Not f.EOF) Do
153-
Begin
154-
// get tag
155-
If (Not f.getBlock(IOBuf,5)) Then
156-
Begin
157-
If compareTag(section_main) Then
158-
loadMain()
159-
Else If compareTag(section_NOTE) Then
160-
loadNoteTab()
161-
Else If compareTag(section_SFX) Then
162-
loadDefinition(true,SFXNameLength)
163-
Else If compareTag(section_TAB) Then
164-
loadDefinition(false,TABNameLength)
165-
Else If compareTag(section_SONG) Then
166-
loadSONG()
167-
Else
168-
haltError('Incorrect TAG in source file');
169-
End
170-
Else
171-
haltError('Unexpected end of file');
172-
// break;
173-
End;
155+
Begin
156+
// get tag
157+
If (Not f.getBlock(IOBuf,5)) Then
158+
Begin
159+
If compareTag(section_main) Then
160+
loadMain()
161+
Else If compareTag(section_NOTE) Then
162+
loadNoteTab()
163+
Else If compareTag(section_SFX) Then
164+
loadDefinition(true,SFXNameLength)
165+
Else If compareTag(section_TAB) Then
166+
loadDefinition(false,TABNameLength)
167+
Else If compareTag(section_SONG) Then
168+
loadSONG()
169+
Else
170+
haltError(ERR_SMMFILE_INCORRECT_TAG);
171+
End
172+
Else
173+
haltError(ERR_SMMFiLE_UNEXPECTED_EOF);
174+
// break;
175+
End;
174176
If f.IOErr<>0 Then
175-
haltError('Unexpected end of file');
177+
haltError(ERR_SMMFiLE_UNEXPECTED_EOF);
176178
f.closeFile();
177179

178180
if verbose>0 then
179181
begin
180-
writeLn(stdout);
181-
writeLn(stdout,totalSFX,' SFX(s) declared');
182-
writeLn(stdout,totalTAB,' TAB(s) declared');
183-
writeLn(stdout,'Data (SFXs & TABs) size: ',topPtr,' byte(s)');
184-
writeLn(stdout);
182+
EOLStdOut(2);
183+
writeLnStdOut(STDOUT_SUMMARY_SFX,[totalSFX]);
184+
writeLnStdOut(STDOUT_SUMMARY_TAB,[totalTAB]);
185+
writeLnStdOut(STDOUT_SUMMARY_DATA_SIZE,[topPtr]);
186+
EOLStdOut;
185187
end;
186188
End;

smm-conv/src/inc/optimize.inc

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
procedure SFXScanUsage();
1+
procedure ReduceSFX();
22
var
33
nSFX:byte;
44

@@ -19,13 +19,13 @@ var
1919
inc(tabofs);
2020
rd2:=data[tabofs]; inc(tabofs);
2121
if rd2 and $80<>0 then continue;
22-
if rd2 and $3f=SFXCheck then result:=true;
22+
if rd2 and $3f=SFXCheck then exit(true); // result:=true;
2323
end;
2424
end;
2525
end;
2626

2727
begin
28-
if verbose>0 then Write(stdout,'SFX used: ');
28+
writeStdOut(STDOUT_REDUCE_SFX_LIST,[]);
2929
usedSFX:=0;
3030
for nSFX:=0 to 63 do
3131
begin
@@ -35,7 +35,7 @@ begin
3535
if checkSFXinTABs(nSFX) then
3636
begin
3737
SFXUsage[nSFX]:=nSFX;
38-
if verbose>0 then Write(stdout,'#',nSFX,' ');
38+
writeStdOut(STDOUT_REDUCE_SFX_ID,[nSFX]);
3939
inc(usedSFX);
4040
end
4141
else
@@ -44,14 +44,11 @@ begin
4444
end;
4545
end;
4646

47-
if verbose>0 then
48-
begin
49-
WriteLn(stdout);
50-
WriteLn(stdout,'Summary: ',usedSFX,' SFX(s) is used.');
51-
end;
47+
EOLStdOut();
48+
writeLnStdOut(STDOUT_REDUCE_SFX_SUMMARY,[usedSFX]);
5249
end;
5350

54-
procedure SFXOptimize();
51+
procedure ReindexSFX();
5552
var
5653
nSFX,newSFX:byte;
5754
nTAB:Byte;
@@ -101,7 +98,7 @@ var
10198
begin
10299
oSFX:=rd2 and $3f;
103100
nSFX:=SFXUsage[oSFX];
104-
if nSFX=-1 then HaltError('Something goes wrong.');
101+
if nSFX=-1 then HaltError(ERR_SFX_REINDEX);
105102
rd2:=(rd2 and $c0) or nSFX;
106103
end;
107104
data[ntopptr]:=rd1; inc(ntopptr);
@@ -134,10 +131,14 @@ begin
134131
changeSFXinTAB(nTAB);
135132
end;
136133
(* move(ndata,data,10240); *) topptr:=ntopptr;
137-
if verbose>0 then writeLn(stdOut);
134+
if verbose>0 then EOLStdOut();
138135
end;
139136

140-
procedure TABScanUsage();
137+
//
138+
//
139+
//
140+
141+
procedure ReduceTAB();
141142
var
142143
nTAB:byte;
143144

@@ -161,14 +162,14 @@ var
161162

162163
if se and $40=0 then
163164
begin
164-
if se and $3f=nTAB then result:=true;
165+
if se and $3f=nTAB then exit(true); // result:=true;
165166
end;
166167
end;
167168
until songofs=$100;
168169
end;
169170

170171
begin
171-
if verbose>0 then Write(stdout,'TAB used: ');
172+
writeStdOut(STDOUT_REDUCE_TAB_LIST,[]);
172173
usedTAB:=0;
173174
for nTAB:=0 to 63 do
174175
begin
@@ -177,7 +178,7 @@ begin
177178
{$ENDIF}
178179
if checkTABinSONG(nTAB) then
179180
begin
180-
if verbose>0 then Write(stdout,'#',nTAB,' ');
181+
writeStdOut(STDOUT_REDUCE_TAB_ID,[nTAB]);
181182
TABUsage[nTAB]:=nTAB;
182183
inc(usedTAB);
183184
end
@@ -187,14 +188,11 @@ begin
187188
end;
188189
end;
189190

190-
if verbose>0 then
191-
begin
192-
WriteLn(stdout);
193-
WriteLn(stdout,'Summary: ',usedTAB,' TAB(s) is used.');
194-
end;
191+
EOLStdOut();
192+
WriteLnStdOut(STDOUT_REDUCE_TAB_SUMMARY,[usedTAB]);
195193
end;
196194

197-
procedure TABOptimize();
195+
procedure ReindexTAB();
198196
var
199197
nSFX,nTAB,newTAB:byte;
200198
songofs:word;

0 commit comments

Comments
 (0)