Mercurial > audlegacy
comparison Plugins/Input/adplug/core/rix.cpp @ 1376:c71e2ef2dcf4 trunk
[svn] Security fixes from AdPlug CVS (their July 7 commit shortly before the secunia announcement).
| author | chainsaw |
|---|---|
| date | Sat, 08 Jul 2006 08:29:18 -0700 |
| parents | 6ad7eb96dd26 |
| children | f12d7e208b43 |
comparison
equal
deleted
inserted
replaced
| 1375:d2c411305bf8 | 1376:c71e2ef2dcf4 |
|---|---|
| 51 { | 51 { |
| 52 return new CrixPlayer(newopl); | 52 return new CrixPlayer(newopl); |
| 53 } | 53 } |
| 54 | 54 |
| 55 CrixPlayer::CrixPlayer(Copl *newopl) | 55 CrixPlayer::CrixPlayer(Copl *newopl) |
| 56 : CPlayer(newopl), buf_addr(0) | 56 : CPlayer(newopl), flag_mkf(0), file_buffer(0), buf_addr(0) |
| 57 { | 57 { |
| 58 } | 58 } |
| 59 | 59 |
| 60 CrixPlayer::~CrixPlayer() | 60 CrixPlayer::~CrixPlayer() |
| 61 { | 61 { |
| 62 if(buf_addr) | 62 if(file_buffer) |
| 63 delete [] buf_addr; | 63 delete [] file_buffer; |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool CrixPlayer::load(const std::string &filename, const CFileProvider &fp) | 66 bool CrixPlayer::load(const std::string &filename, const CFileProvider &fp) |
| 67 { | 67 { |
| 68 binistream *f = fp.open(filename); if(!f) return false; | 68 binistream *f = fp.open(filename); if(!f) return false; |
| 69 unsigned long i=0; | 69 unsigned long i=0; |
| 70 | 70 |
| 71 if(f->readInt(2)!=0x55aa) { fp.close(f);return false; } | 71 if(stricmp(filename.substr(filename.length()-4,4).c_str(),".mkf")==0) |
| 72 buf_addr = new unsigned char [fp.filesize(f) + 1]; | 72 { |
| 73 buf_addr[i++]=0xaa;buf_addr[i++]=0x55; | 73 flag_mkf=1; |
| 74 f->seek(0); | |
| 75 int offset=f->readInt(4); | |
| 76 f->seek(offset); | |
| 77 } | |
| 78 if(f->readInt(4)!=0x55aa){ fp.close(f);return false; } | |
| 79 file_buffer = new unsigned char [fp.filesize(f) + 1]; | |
| 80 f->seek(0); | |
| 74 while(!f->eof()) | 81 while(!f->eof()) |
| 75 buf_addr[i++]=f->readInt(1); | 82 file_buffer[i++]=f->readInt(1); |
| 76 length=i; | 83 length=i; |
| 77 fp.close(f); | 84 fp.close(f); |
| 78 | 85 if(!flag_mkf) |
| 86 buf_addr=file_buffer; | |
| 79 rewind(0); | 87 rewind(0); |
| 80 return true; | 88 return true; |
| 81 } | 89 } |
| 82 | 90 |
| 83 bool CrixPlayer::update() | 91 bool CrixPlayer::update() |
| 84 { | 92 { |
| 85 if (delay>100) { | |
| 86 delay-=100; | |
| 87 return true; | |
| 88 } else delay=1; | |
| 89 | |
| 90 int_08h_entry(); | 93 int_08h_entry(); |
| 91 return !dro_end; | 94 return !dro_end; |
| 92 } | 95 } |
| 93 | 96 |
| 94 void CrixPlayer::rewind(int subsong) | 97 void CrixPlayer::rewind(int subsong) |
| 102 pause_flag = 0; | 105 pause_flag = 0; |
| 103 band = 0; | 106 band = 0; |
| 104 band_low = 0; | 107 band_low = 0; |
| 105 e0_reg_flag = 0; | 108 e0_reg_flag = 0; |
| 106 bd_modify = 0; | 109 bd_modify = 0; |
| 107 delay = 1; | |
| 108 sustain = 0; | 110 sustain = 0; |
| 109 dro_end = 0; | 111 dro_end = 0; |
| 110 pos = index = 0; | 112 pos = index = 0; |
| 111 | 113 |
| 112 memset(buffer, 0, sizeof(unsigned short) * 300); | 114 memset(buffer, 0, sizeof(unsigned short) * 300); |
| 117 memset(addrs_head, 0, 96); | 119 memset(addrs_head, 0, 96); |
| 118 memset(insbuf, 0, 28 * sizeof(unsigned short)); | 120 memset(insbuf, 0, 28 * sizeof(unsigned short)); |
| 119 memset(displace, 0, 11 * sizeof(unsigned short)); | 121 memset(displace, 0, 11 * sizeof(unsigned short)); |
| 120 memset(reg_bufs, 0, 18 * sizeof(ADDT)); | 122 memset(reg_bufs, 0, 18 * sizeof(ADDT)); |
| 121 | 123 |
| 124 if(flag_mkf) | |
| 125 { | |
| 126 unsigned int *buf_index=(unsigned int *)file_buffer; | |
| 127 int offset1=buf_index[subsong],offset2; | |
| 128 while((offset2=buf_index[++subsong])==offset1); | |
| 129 length=offset2-offset1+1; | |
| 130 buf_addr=file_buffer+offset1; | |
| 131 } | |
| 122 opl->init(); | 132 opl->init(); |
| 123 opl->write(1,32); // go to OPL2 mode | 133 opl->write(1,32); // go to OPL2 mode |
| 124 set_new_int(); | 134 set_new_int(); |
| 125 data_initial(); | 135 data_initial(); |
| 126 } | 136 } |
| 137 unsigned int CrixPlayer::getsubsongs() | |
| 138 { | |
| 139 if(flag_mkf) | |
| 140 { | |
| 141 unsigned int *buf_index=(unsigned int *)file_buffer; | |
| 142 int songs=buf_index[0]/4,i=0; | |
| 143 for(i=0;i<songs;i++) | |
| 144 if(buf_index[i+1]==buf_index[i]) | |
| 145 songs--; | |
| 146 return songs; | |
| 147 } | |
| 148 else | |
| 149 return 1; | |
| 150 } | |
| 127 | 151 |
| 128 float CrixPlayer::getrefresh() | 152 float CrixPlayer::getrefresh() |
| 129 { | 153 { |
| 130 if (delay > 100) return 1000 / 100; | 154 return 70.0f; |
| 131 else return 1000.0 / (double)delay; | |
| 132 } | 155 } |
| 133 | 156 |
| 134 /*------------------Implemention----------------------------*/ | 157 /*------------------Implemention----------------------------*/ |
| 135 inline void CrixPlayer::set_new_int() | 158 inline void CrixPlayer::set_new_int() |
| 136 { | 159 { |
| 237 if(sustain <= 0 && mutex == 0) | 260 if(sustain <= 0 && mutex == 0) |
| 238 { | 261 { |
| 239 mutex++; | 262 mutex++; |
| 240 band_sus = rix_proc(); | 263 band_sus = rix_proc(); |
| 241 if(band_sus) sustain += band_sus; | 264 if(band_sus) sustain += band_sus; |
| 242 delay=sustain; | |
| 243 mutex--; | 265 mutex--; |
| 244 if(band_sus == 0) | 266 if(band_sus == 0) |
| 245 { | 267 { |
| 246 dro_end=1; | 268 dro_end=1; |
| 247 break; | 269 break; |
| 248 } | 270 } |
| 249 } | 271 } |
| 250 else | 272 else |
| 251 { | 273 { |
| 252 if(band_sus) sustain -= 9; /* aging */ | 274 if(band_sus) sustain -= 14; /* aging */ |
| 253 break; | 275 break; |
| 254 } | 276 } |
| 255 } | 277 } |
| 256 } | 278 } |
| 257 /*--------------------------------------------------------------*/ | 279 /*--------------------------------------------------------------*/ |
