comparison src/adplug/core/rad.cxx @ 955:4709ce4e209e trunk

[svn] Run indent -ts4 -nut -bli0 -cdw on this messy lot. Upstream is not consistent with whitespace anyway, no loss there.
author chainsaw
date Sat, 14 Apr 2007 15:23:50 -0700
parents 87666f9bf6d0
children
comparison
equal deleted inserted replaced
954:d7a6fd179cd2 955:4709ce4e209e
22 * some volumes are dropped out 22 * some volumes are dropped out
23 */ 23 */
24 24
25 #include "rad.h" 25 #include "rad.h"
26 26
27 CPlayer *CradLoader::factory(Copl *newopl) 27 CPlayer *
28 CradLoader::factory (Copl * newopl)
28 { 29 {
29 return new CradLoader(newopl); 30 return new CradLoader (newopl);
30 } 31 }
31 32
32 bool CradLoader::load(VFSFile *fd, const CFileProvider &fp) 33 bool
34 CradLoader::load (VFSFile * fd, const CFileProvider & fp)
33 { 35 {
34 binistream *f = fp.open(fd); if(!f) return false; 36 binistream *f = fp.open (fd);
35 char id[16]; 37 if (!f)
36 unsigned char buf,ch,c,b,inp; 38 return false;
37 char bufstr[2] = "\0"; 39 char id[16];
38 unsigned int i,j; 40 unsigned char buf, ch, c, b, inp;
39 unsigned short patofs[32]; 41 char bufstr[2] = "\0";
40 const unsigned char convfx[16] = {255,1,2,3,255,5,255,255,255,255,20,255,17,0xd,255,19}; 42 unsigned int i, j;
43 unsigned short patofs[32];
44 const unsigned char convfx[16] =
45 { 255, 1, 2, 3, 255, 5, 255, 255, 255, 255, 20, 255, 17, 0xd, 255, 19 };
41 46
42 // file validation section 47 // file validation section
43 f->readString(id, 16); version = f->readInt(1); 48 f->readString (id, 16);
44 if(strncmp(id,"RAD by REALiTY!!",16) || version != 0x10) 49 version = f->readInt (1);
45 { fp.close(f); return false; } 50 if (strncmp (id, "RAD by REALiTY!!", 16) || version != 0x10)
51 {
52 fp.close (f);
53 return false;
54 }
46 55
47 // load section 56 // load section
48 radflags = f->readInt(1); 57 radflags = f->readInt (1);
49 if(radflags & 128) { // description 58 if (radflags & 128)
50 memset(desc,0,80*22); 59 { // description
51 while((buf = f->readInt(1))) 60 memset (desc, 0, 80 * 22);
52 if(buf == 1) 61 while ((buf = f->readInt (1)))
53 strcat(desc,"\n"); 62 if (buf == 1)
54 else 63 strcat (desc, "\n");
55 if(buf >= 2 && buf <= 0x1f) 64 else if (buf >= 2 && buf <= 0x1f)
56 for(i=0;i<buf;i++) 65 for (i = 0; i < buf; i++)
57 strcat(desc," "); 66 strcat (desc, " ");
58 else { 67 else
59 *bufstr = buf; 68 {
60 strcat(desc,bufstr); 69 *bufstr = buf;
61 } 70 strcat (desc, bufstr);
62 } 71 }
63 while((buf = f->readInt(1))) { // instruments 72 }
64 buf--; 73 while ((buf = f->readInt (1)))
65 inst[buf].data[2] = f->readInt(1); inst[buf].data[1] = f->readInt(1); 74 { // instruments
66 inst[buf].data[10] = f->readInt(1); inst[buf].data[9] = f->readInt(1); 75 buf--;
67 inst[buf].data[4] = f->readInt(1); inst[buf].data[3] = f->readInt(1); 76 inst[buf].data[2] = f->readInt (1);
68 inst[buf].data[6] = f->readInt(1); inst[buf].data[5] = f->readInt(1); 77 inst[buf].data[1] = f->readInt (1);
69 inst[buf].data[0] = f->readInt(1); 78 inst[buf].data[10] = f->readInt (1);
70 inst[buf].data[8] = f->readInt(1); inst[buf].data[7] = f->readInt(1); 79 inst[buf].data[9] = f->readInt (1);
71 } 80 inst[buf].data[4] = f->readInt (1);
72 length = f->readInt(1); 81 inst[buf].data[3] = f->readInt (1);
73 for(i = 0; i < length; i++) order[i] = f->readInt(1); // orderlist 82 inst[buf].data[6] = f->readInt (1);
74 for(i = 0; i < 32; i++) patofs[i] = f->readInt(2); // pattern offset table 83 inst[buf].data[5] = f->readInt (1);
75 init_trackord(); // patterns 84 inst[buf].data[0] = f->readInt (1);
76 for(i=0;i<32;i++) 85 inst[buf].data[8] = f->readInt (1);
77 if(patofs[i]) { 86 inst[buf].data[7] = f->readInt (1);
78 f->seek(patofs[i]); 87 }
79 do { 88 length = f->readInt (1);
80 buf = f->readInt(1); b = buf & 127; 89 for (i = 0; i < length; i++)
81 do { 90 order[i] = f->readInt (1); // orderlist
82 ch = f->readInt(1); c = ch & 127; 91 for (i = 0; i < 32; i++)
83 inp = f->readInt(1); 92 patofs[i] = f->readInt (2); // pattern offset table
84 tracks[i*9+c][b].note = inp & 127; 93 init_trackord (); // patterns
85 tracks[i*9+c][b].inst = (inp & 128) >> 3; 94 for (i = 0; i < 32; i++)
86 inp = f->readInt(1); 95 if (patofs[i])
87 tracks[i*9+c][b].inst += inp >> 4; 96 {
88 tracks[i*9+c][b].command = inp & 15; 97 f->seek (patofs[i]);
89 if(inp & 15) { 98 do
90 inp = f->readInt(1); 99 {
91 tracks[i*9+c][b].param1 = inp / 10; 100 buf = f->readInt (1);
92 tracks[i*9+c][b].param2 = inp % 10; 101 b = buf & 127;
93 } 102 do
94 } while(!(ch & 128)); 103 {
95 } while(!(buf & 128)); 104 ch = f->readInt (1);
96 } else 105 c = ch & 127;
97 memset(trackord[i],0,9*2); 106 inp = f->readInt (1);
98 fp.close(f); 107 tracks[i * 9 + c][b].note = inp & 127;
108 tracks[i * 9 + c][b].inst = (inp & 128) >> 3;
109 inp = f->readInt (1);
110 tracks[i * 9 + c][b].inst += inp >> 4;
111 tracks[i * 9 + c][b].command = inp & 15;
112 if (inp & 15)
113 {
114 inp = f->readInt (1);
115 tracks[i * 9 + c][b].param1 = inp / 10;
116 tracks[i * 9 + c][b].param2 = inp % 10;
117 }
118 } while (!(ch & 128));
119 } while (!(buf & 128));
120 }
121 else
122 memset (trackord[i], 0, 9 * 2);
123 fp.close (f);
99 124
100 // convert replay data 125 // convert replay data
101 for(i=0;i<32*9;i++) // convert patterns 126 for (i = 0; i < 32 * 9; i++) // convert patterns
102 for(j=0;j<64;j++) { 127 for (j = 0; j < 64; j++)
103 if(tracks[i][j].note == 15) 128 {
104 tracks[i][j].note = 127; 129 if (tracks[i][j].note == 15)
105 if(tracks[i][j].note > 16 && tracks[i][j].note < 127) 130 tracks[i][j].note = 127;
106 tracks[i][j].note -= 4 * (tracks[i][j].note >> 4); 131 if (tracks[i][j].note > 16 && tracks[i][j].note < 127)
107 if(tracks[i][j].note && tracks[i][j].note < 126) 132 tracks[i][j].note -= 4 * (tracks[i][j].note >> 4);
108 tracks[i][j].note++; 133 if (tracks[i][j].note && tracks[i][j].note < 126)
109 tracks[i][j].command = convfx[tracks[i][j].command]; 134 tracks[i][j].note++;
110 } 135 tracks[i][j].command = convfx[tracks[i][j].command];
111 restartpos = 0; initspeed = radflags & 31; 136 }
112 bpm = radflags & 64 ? 0 : 50; flags = Decimal; 137 restartpos = 0;
138 initspeed = radflags & 31;
139 bpm = radflags & 64 ? 0 : 50;
140 flags = Decimal;
113 141
114 rewind(0); 142 rewind (0);
115 return true; 143 return true;
116 } 144 }
117 145
118 float CradLoader::getrefresh() 146 float
147 CradLoader::getrefresh ()
119 { 148 {
120 if(tempo) 149 if (tempo)
121 return (float) (tempo); 150 return (float) (tempo);
122 else 151 else
123 return 18.2f; 152 return 18.2f;
124 } 153 }