2 * Adplug - Replayer for many OPL2/OPL3 audio file formats.
3 * Copyright (C) 1999 - 2007 Simon Peter, <dn.tlp@gmx.net>, et al.
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.
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.
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
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * rad.cpp - RAD Loader by Simon Peter <dn.tlp@gmx.net>
22 * some volumes are dropped out
28 CPlayer *CradLoader::factory(Copl *newopl)
30 return new CradLoader(newopl);
33 bool CradLoader::load(const std::string &filename, const CFileProvider &fp)
35 binistream *f = fp.open(filename); if(!f) return false;
37 unsigned char buf,ch,c,b,inp;
38 char bufstr[2] = "\0";
40 unsigned short patofs[32];
41 const unsigned char convfx[16] = {255,1,2,3,255,5,255,255,255,255,20,255,17,0xd,255,19};
43 // file validation section
44 f->readString(id, 16); version = f->readInt(1);
45 if(strncmp(id,"RAD by REALiTY!!",16) || version != 0x10)
46 { fp.close(f); return false; }
49 radflags = f->readInt(1);
50 if(radflags & 128) { // description
52 while((buf = f->readInt(1)))
56 if(buf >= 2 && buf <= 0x1f)
64 while((buf = f->readInt(1))) { // instruments
66 inst[buf].data[2] = f->readInt(1); inst[buf].data[1] = f->readInt(1);
67 inst[buf].data[10] = f->readInt(1); inst[buf].data[9] = f->readInt(1);
68 inst[buf].data[4] = f->readInt(1); inst[buf].data[3] = f->readInt(1);
69 inst[buf].data[6] = f->readInt(1); inst[buf].data[5] = f->readInt(1);
70 inst[buf].data[0] = f->readInt(1);
71 inst[buf].data[8] = f->readInt(1); inst[buf].data[7] = f->readInt(1);
73 length = f->readInt(1);
74 for(i = 0; i < length; i++) order[i] = f->readInt(1); // orderlist
75 for(i = 0; i < 32; i++) patofs[i] = f->readInt(2); // pattern offset table
76 init_trackord(); // patterns
81 buf = f->readInt(1); b = buf & 127;
83 ch = f->readInt(1); c = ch & 127;
85 tracks[i*9+c][b].note = inp & 127;
86 tracks[i*9+c][b].inst = (inp & 128) >> 3;
88 tracks[i*9+c][b].inst += inp >> 4;
89 tracks[i*9+c][b].command = inp & 15;
92 tracks[i*9+c][b].param1 = inp / 10;
93 tracks[i*9+c][b].param2 = inp % 10;
96 } while(!(buf & 128));
98 memset(trackord[i],0,9*2);
101 // convert replay data
102 for(i=0;i<32*9;i++) // convert patterns
104 if(tracks[i][j].note == 15)
105 tracks[i][j].note = 127;
106 if(tracks[i][j].note > 16 && tracks[i][j].note < 127)
107 tracks[i][j].note -= 4 * (tracks[i][j].note >> 4);
108 if(tracks[i][j].note && tracks[i][j].note < 126)
110 tracks[i][j].command = convfx[tracks[i][j].command];
112 restartpos = 0; initspeed = radflags & 31;
113 bpm = radflags & 64 ? 0 : 50; flags = Decimal;
119 float CradLoader::getrefresh()
122 return (float) (tempo);