359
|
1 /*
|
|
2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
|
|
3 * Copyright (C) 1999 - 2003 Simon Peter, <dn.tlp@gmx.net>, et al.
|
|
4 *
|
|
5 * This library is free software; you can redistribute it and/or
|
|
6 * modify it under the terms of the GNU Lesser General Public
|
|
7 * License as published by the Free Software Foundation; either
|
|
8 * version 2.1 of the License, or (at your option) any later version.
|
|
9 *
|
|
10 * This library is distributed in the hope that it will be useful,
|
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
13 * Lesser General Public License for more details.
|
|
14 *
|
|
15 * You should have received a copy of the GNU Lesser General Public
|
|
16 * License along with this library; if not, write to the Free Software
|
1459
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
359
|
18 *
|
|
19 * rad.cpp - RAD Loader by Simon Peter <dn.tlp@gmx.net>
|
|
20 *
|
|
21 * BUGS:
|
|
22 * some volumes are dropped out
|
|
23 */
|
|
24
|
|
25 #include "rad.h"
|
|
26
|
|
27 CPlayer *CradLoader::factory(Copl *newopl)
|
|
28 {
|
|
29 return new CradLoader(newopl);
|
|
30 }
|
|
31
|
|
32 bool CradLoader::load(const std::string &filename, const CFileProvider &fp)
|
|
33 {
|
|
34 binistream *f = fp.open(filename); if(!f) return false;
|
|
35 char id[16];
|
|
36 unsigned char buf,ch,c,b,inp;
|
|
37 char bufstr[2] = "\0";
|
|
38 unsigned int i,j;
|
|
39 unsigned short patofs[32];
|
|
40 const unsigned char convfx[16] = {255,1,2,3,255,5,255,255,255,255,20,255,17,0xd,255,19};
|
|
41
|
|
42 // file validation section
|
|
43 f->readString(id, 16); version = f->readInt(1);
|
|
44 if(strncmp(id,"RAD by REALiTY!!",16) || version != 0x10)
|
|
45 { fp.close(f); return false; }
|
|
46
|
|
47 // load section
|
|
48 radflags = f->readInt(1);
|
|
49 if(radflags & 128) { // description
|
|
50 memset(desc,0,80*22);
|
|
51 while((buf = f->readInt(1)))
|
|
52 if(buf == 1)
|
|
53 strcat(desc,"\n");
|
|
54 else
|
|
55 if(buf >= 2 && buf <= 0x1f)
|
|
56 for(i=0;i<buf;i++)
|
|
57 strcat(desc," ");
|
|
58 else {
|
|
59 *bufstr = buf;
|
|
60 strcat(desc,bufstr);
|
|
61 }
|
|
62 }
|
|
63 while((buf = f->readInt(1))) { // instruments
|
|
64 buf--;
|
|
65 inst[buf].data[2] = f->readInt(1); inst[buf].data[1] = f->readInt(1);
|
|
66 inst[buf].data[10] = f->readInt(1); inst[buf].data[9] = f->readInt(1);
|
|
67 inst[buf].data[4] = f->readInt(1); inst[buf].data[3] = f->readInt(1);
|
|
68 inst[buf].data[6] = f->readInt(1); inst[buf].data[5] = f->readInt(1);
|
|
69 inst[buf].data[0] = f->readInt(1);
|
|
70 inst[buf].data[8] = f->readInt(1); inst[buf].data[7] = f->readInt(1);
|
|
71 }
|
|
72 length = f->readInt(1);
|
|
73 for(i = 0; i < length; i++) order[i] = f->readInt(1); // orderlist
|
|
74 for(i = 0; i < 32; i++) patofs[i] = f->readInt(2); // pattern offset table
|
|
75 init_trackord(); // patterns
|
|
76 for(i=0;i<32;i++)
|
|
77 if(patofs[i]) {
|
|
78 f->seek(patofs[i]);
|
|
79 do {
|
|
80 buf = f->readInt(1); b = buf & 127;
|
|
81 do {
|
|
82 ch = f->readInt(1); c = ch & 127;
|
|
83 inp = f->readInt(1);
|
|
84 tracks[i*9+c][b].note = inp & 127;
|
|
85 tracks[i*9+c][b].inst = (inp & 128) >> 3;
|
|
86 inp = f->readInt(1);
|
|
87 tracks[i*9+c][b].inst += inp >> 4;
|
|
88 tracks[i*9+c][b].command = inp & 15;
|
|
89 if(inp & 15) {
|
|
90 inp = f->readInt(1);
|
|
91 tracks[i*9+c][b].param1 = inp / 10;
|
|
92 tracks[i*9+c][b].param2 = inp % 10;
|
|
93 }
|
|
94 } while(!(ch & 128));
|
|
95 } while(!(buf & 128));
|
|
96 } else
|
|
97 memset(trackord[i],0,9*2);
|
|
98 fp.close(f);
|
|
99
|
|
100 // convert replay data
|
|
101 for(i=0;i<32*9;i++) // convert patterns
|
|
102 for(j=0;j<64;j++) {
|
|
103 if(tracks[i][j].note == 15)
|
|
104 tracks[i][j].note = 127;
|
|
105 if(tracks[i][j].note > 16 && tracks[i][j].note < 127)
|
|
106 tracks[i][j].note -= 4 * (tracks[i][j].note >> 4);
|
|
107 if(tracks[i][j].note && tracks[i][j].note < 126)
|
|
108 tracks[i][j].note++;
|
|
109 tracks[i][j].command = convfx[tracks[i][j].command];
|
|
110 }
|
|
111 restartpos = 0; activechan = 0xffff; initspeed = radflags & 31;
|
|
112 bpm = radflags & 64 ? 0 : 50; flags = Decimal;
|
|
113
|
|
114 rewind(0);
|
|
115 return true;
|
|
116 }
|
|
117
|
|
118 float CradLoader::getrefresh()
|
|
119 {
|
|
120 if(tempo)
|
|
121 return (float) (tempo);
|
|
122 else
|
|
123 return 18.2f;
|
|
124 }
|