rix.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /*
  2. * Adplug - Replayer for many OPL2/OPL3 audio file formats.
  3. * Copyright (C) 1999 - 2007 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
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * rix.cpp - Softstar RIX OPL Format Player by palxex <palxex.ys168.com>
  20. * BSPAL <BSPAL.ys168.com>
  21. */
  22. #include "common.h"
  23. #include <cstring>
  24. #include <cstdio>
  25. #include <cstdlib>
  26. #include "rix.h"
  27. using namespace std;
  28. #if !defined(_WIN32) || defined(__SYMBIAN32__)
  29. #define stricmp strcasecmp
  30. #endif
  31. #if defined(__hppa__) || \
  32. defined(__m68k__) || defined(mc68000) || defined(_M_M68K) || \
  33. (defined(__MIPS__) && defined(__MISPEB__)) || \
  34. defined(__ppc__) || defined(__POWERPC__) || defined(_M_PPC) || \
  35. defined(__sparc__)
  36. // big endian
  37. #define RIX_SWAP32(a) (((a) << 24) | (((a) << 8) & 0x00FF0000) | (((a) >> 8) & 0x0000FF00) | ((a) >> 24))
  38. #define RIX_SWAP16(a) ((((a) << 8) & 0xFF00) | ((a) >> 8))
  39. #else
  40. // little endian
  41. #define RIX_SWAP32(a) (a)
  42. #define RIX_SWAP16(a) (a)
  43. #endif
  44. #ifdef DEBUG
  45. #define RELEASE_INLINE
  46. #else
  47. #define RELEASE_INLINE inline
  48. #endif
  49. const uint8_t CrixPlayer::adflag[] = {0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1};
  50. const uint8_t CrixPlayer::reg_data[] = {0,1,2,3,4,5,8,9,10,11,12,13,16,17,18,19,20,21};
  51. const uint8_t CrixPlayer::ad_C0_offs[] = {0,1,2,0,1,2,3,4,5,3,4,5,6,7,8,6,7,8};
  52. const uint8_t CrixPlayer::modify[] = {0,3,1,4,2,5,6,9,7,10,8,11,12,15,13,16,14,17,12,\
  53. 15,16,0,14,0,17,0,13,0};
  54. const uint8_t CrixPlayer::bd_reg_data[] = {
  55. 0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x08,0x04,0x02,0x01,
  56. 0x00,0x01,0x01,0x03,0x0F,0x05,0x00,0x01,0x03,0x0F,0x00,
  57. 0x00,0x00,0x01,0x00,0x00,0x01,0x01,0x0F,0x07,0x00,0x02,
  58. 0x04,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x0A,
  59. 0x04,0x00,0x08,0x0C,0x0B,0x00,0x00,0x00,0x01,0x00,0x00,
  60. 0x00,0x00,0x0D,0x04,0x00,0x06,0x0F,0x00,0x00,0x00,0x00,
  61. 0x01,0x00,0x00,0x0C,0x00,0x0F,0x0B,0x00,0x08,0x05,0x00,
  62. 0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x0F,0x0B,0x00,
  63. 0x07,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
  64. 0x0F,0x0B,0x00,0x05,0x05,0x00,0x00,0x00,0x00,0x00,0x00,
  65. 0x00,0x01,0x00,0x0F,0x0B,0x00,0x07,0x05,0x00,0x00,0x00,
  66. 0x00,0x00,0x00};
  67. uint8_t CrixPlayer::for40reg[] = {0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,
  68. 0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F};
  69. const uint16_t CrixPlayer::mus_time = 0x4268;
  70. /*** public methods *************************************/
  71. CPlayer *CrixPlayer::factory(Copl *newopl)
  72. {
  73. return new CrixPlayer(newopl);
  74. }
  75. CrixPlayer::CrixPlayer(Copl *newopl)
  76. : CPlayer(newopl), flag_mkf(0), fp(NULL)
  77. #if USE_RIX_EXTRA_INIT
  78. , extra_regs(NULL), extra_vals(NULL), extra_length(0)
  79. #endif
  80. {
  81. }
  82. CrixPlayer::~CrixPlayer()
  83. {
  84. fclose(fp);
  85. #if USE_RIX_EXTRA_INIT
  86. if (extra_regs) delete[] extra_regs;
  87. if (extra_vals) delete[] extra_vals;
  88. #endif
  89. }
  90. #if USE_RIX_EXTRA_INIT
  91. void CrixPlayer::set_extra_init(uint32_t* regs, uint8_t* datas, int n)
  92. {
  93. extra_length = n;
  94. if (extra_regs) delete[] extra_regs;
  95. if (extra_vals) delete[] extra_vals;
  96. if (n > 0)
  97. {
  98. extra_regs = new uint32_t[n];
  99. extra_vals = new uint8_t[n];
  100. if (extra_regs) memcpy(extra_regs, regs, n * sizeof(uint32_t));
  101. if (extra_vals) memcpy(extra_vals, datas, n * sizeof(uint8_t));
  102. }
  103. else
  104. {
  105. extra_regs = NULL;
  106. extra_vals = NULL;
  107. }
  108. }
  109. #endif
  110. bool CrixPlayer::load(const std::string &filename, const CFileProvider &cfp)
  111. {
  112. fp = fopen(filename.c_str(),"rb"); if(!fp) return false;
  113. if(stricmp(filename.substr(filename.length()-4,4).c_str(),".mkf")==0)
  114. {
  115. flag_mkf=1;
  116. fseek(fp,0,SEEK_SET);
  117. int offset;
  118. fread(&offset,4,1,fp);
  119. fseek(fp,RIX_SWAP32(offset),SEEK_SET);
  120. }
  121. uint16_t signature;
  122. fread(&signature,2,1,fp);
  123. if(RIX_SWAP16(signature)!=0x55aa){ fclose(fp);return false; }
  124. if(!flag_mkf)
  125. {
  126. fseek(fp,0,SEEK_END);
  127. length = (uint32_t)ftell(fp);
  128. fseek(fp,0,SEEK_SET);
  129. fread(rix_buf,length,1,fp);
  130. subsongs = 1;
  131. }
  132. else
  133. {
  134. fseek(fp,0,SEEK_SET);
  135. fread(&subsongs,4,1,fp);
  136. subsongs = RIX_SWAP32(subsongs);
  137. subsongs/=4;
  138. }
  139. rewind(0);
  140. return true;
  141. }
  142. bool CrixPlayer::update()
  143. {
  144. int_08h_entry();
  145. return !play_end;
  146. }
  147. void CrixPlayer::rewind(int subsong)
  148. {
  149. rewindReInit(subsong, true);
  150. }
  151. void CrixPlayer::rewindReInit(int subsong, bool reinit)
  152. {
  153. play_end = 0;
  154. pos = 0;
  155. if (reinit)
  156. {
  157. I = 0; T = 0;
  158. mus_block = 0;
  159. ins_block = 0;
  160. rhythm = 0;
  161. music_on = 0;
  162. pause_flag = 0;
  163. band = 0;
  164. band_low = 0;
  165. e0_reg_flag = 0;
  166. bd_modify = 0;
  167. sustain = 0;
  168. memset(f_buffer, 0, sizeof(f_buffer));
  169. memset(a0b0_data2, 0, sizeof(a0b0_data2));
  170. memset(a0b0_data3, 0, sizeof(a0b0_data3));
  171. memset(a0b0_data4, 0, sizeof(a0b0_data4));
  172. memset(a0b0_data5, 0, sizeof(a0b0_data5));
  173. memset(addrs_head, 0, sizeof(addrs_head));
  174. memset(insbuf, 0, sizeof(insbuf));
  175. memset(displace, 0, sizeof(displace));
  176. memset(reg_bufs, 0, sizeof(reg_bufs));
  177. memset(for40reg, 0x7F, sizeof(for40reg));
  178. }
  179. if (flag_mkf)
  180. {
  181. int index,index2;
  182. fseek(fp,subsong*4,SEEK_SET);
  183. fread(&index,4,1,fp);
  184. fread(&index2,4,1,fp);
  185. index = RIX_SWAP32(index);
  186. index2 = RIX_SWAP32(index2);
  187. length = index2 - index;
  188. fseek(fp,index,SEEK_SET);
  189. memset(rix_buf, 0, sizeof(rix_buf));
  190. fread(rix_buf,length,1,fp);
  191. }
  192. if (reinit)
  193. {
  194. opl->init();
  195. opl->write(1, 32); // go to OPL2 mode
  196. set_new_int();
  197. data_initial();
  198. }
  199. }
  200. unsigned int CrixPlayer::getsubsongs()
  201. {
  202. return subsongs;
  203. }
  204. float CrixPlayer::getrefresh()
  205. {
  206. return 70.0f;
  207. }
  208. /*------------------Implemention----------------------------*/
  209. RELEASE_INLINE void CrixPlayer::set_new_int()
  210. {
  211. // if(!ad_initial()) exit(1);
  212. ad_initial();
  213. }
  214. /*----------------------------------------------------------*/
  215. RELEASE_INLINE void CrixPlayer::Pause()
  216. {
  217. uint16_t i;
  218. pause_flag = 1;
  219. for(i=0;i<11;i++)
  220. switch_ad_bd(i);
  221. }
  222. /*----------------------------------------------------------*/
  223. RELEASE_INLINE void CrixPlayer::ad_a0b0l_reg_(uint16_t index,uint16_t p2,uint16_t p3)
  224. {
  225. // uint16_t i = p2+a0b0_data2[index];
  226. a0b0_data4[index] = p3;
  227. a0b0_data3[index] = p2;
  228. }
  229. RELEASE_INLINE void CrixPlayer::data_initial()
  230. {
  231. rhythm = rix_buf[2];
  232. mus_block = (rix_buf[0x0D]<<8)+rix_buf[0x0C];
  233. ins_block = (rix_buf[0x09]<<8)+rix_buf[0x08];
  234. I = mus_block+1;
  235. if(rhythm != 0)
  236. {
  237. ad_a0b0_reg(6);
  238. ad_a0b0_reg(7);
  239. ad_a0b0_reg(8);
  240. ad_a0b0l_reg_(8,0x18,0);
  241. ad_a0b0l_reg_(7,0x1F,0);
  242. // This is required for correct attack effect, by louyihua
  243. #if USE_RIX_EXTRA_INIT
  244. if (extra_regs && extra_vals && extra_length > 0)
  245. {
  246. for (uint32_t i = 0; i < extra_length; i++)
  247. opl->write(extra_regs[i], extra_vals[i]);
  248. }
  249. #else
  250. opl->write(0xa8, 87);
  251. opl->write(0xb8, 9);
  252. opl->write(0xa7, 3);
  253. opl->write(0xb7, 15/*10*/); // Changed from 10 (original value) to 15 for better quality
  254. #endif
  255. }
  256. bd_modify = 0;
  257. ad_bd_reg();
  258. band = 0; music_on = 1;
  259. }
  260. /*----------------------------------------------------------*/
  261. RELEASE_INLINE uint16_t CrixPlayer::ad_initial()
  262. {
  263. uint16_t i,j,k = 0;
  264. for(i=0;i<25;i++)
  265. {
  266. uint32_t res = ((uint32_t)i*24+10000)*52088/250000*0x24000/0x1B503;
  267. f_buffer[i*12]=((uint16_t)res+4)>>3;
  268. for(int t=1;t<12;t++)
  269. {
  270. res*=1.06;
  271. f_buffer[i*12+t]=((uint16_t)res+4)>>3;
  272. }
  273. }
  274. for(i=0;i<8;i++)
  275. for(j=0;j<12;j++)
  276. {
  277. a0b0_data5[k] = i;
  278. addrs_head[k] = j;
  279. k++;
  280. }
  281. ad_bd_reg();
  282. ad_08_reg();
  283. for(i=0;i<9;i++) ad_a0b0_reg(i);
  284. e0_reg_flag = 0x20;
  285. for(i=0;i<18;i++) ad_bop(0xE0+reg_data[i],0);
  286. ad_bop(1,e0_reg_flag);
  287. return 1;//ad_test();
  288. }
  289. /*----------------------------------------------------------*/
  290. RELEASE_INLINE void CrixPlayer::ad_bop(uint16_t reg,uint16_t value)
  291. {
  292. //if(reg == 2 || reg == 3)
  293. // AdPlug_LogWrite("switch OPL2/3 mode!\n");
  294. opl->write(reg & 0xff, value & 0xff);
  295. }
  296. /*--------------------------------------------------------------*/
  297. RELEASE_INLINE void CrixPlayer::int_08h_entry()
  298. {
  299. uint16_t band_sus = 1;
  300. while(band_sus)
  301. {
  302. if(sustain <= 0)
  303. {
  304. band_sus = rix_proc();
  305. if(band_sus) sustain += band_sus;
  306. else
  307. {
  308. play_end=1;
  309. break;
  310. }
  311. }
  312. else
  313. {
  314. if(band_sus) sustain -= 14; /* aging */
  315. break;
  316. }
  317. }
  318. }
  319. /*--------------------------------------------------------------*/
  320. RELEASE_INLINE uint16_t CrixPlayer::rix_proc()
  321. {
  322. uint8_t ctrl = 0;
  323. if(music_on == 0||pause_flag == 1) return 0;
  324. band = 0;
  325. while(rix_buf[I] != 0x80 && I<length-1)
  326. {
  327. band_low = rix_buf[I-1];
  328. ctrl = rix_buf[I]; I+=2;
  329. switch(ctrl&0xF0)
  330. {
  331. case 0x90: rix_get_ins(); rix_90_pro(ctrl&0x0F); break;
  332. case 0xA0: rix_A0_pro(ctrl&0x0F,((uint16_t)band_low)<<6); break;
  333. case 0xB0: rix_B0_pro(ctrl&0x0F,band_low); break;
  334. case 0xC0: switch_ad_bd(ctrl&0x0F);
  335. if(band_low != 0) rix_C0_pro(ctrl&0x0F,band_low);
  336. break;
  337. default: band = (ctrl<<8)+band_low; break;
  338. }
  339. if(band != 0) return band;
  340. }
  341. music_ctrl();
  342. I = mus_block+1;
  343. band = 0; music_on = 1;
  344. return 0;
  345. }
  346. /*--------------------------------------------------------------*/
  347. RELEASE_INLINE void CrixPlayer::rix_get_ins()
  348. {
  349. int i;
  350. uint8_t *baddr = (&rix_buf[ins_block])+(band_low<<6);
  351. for(i = 0; i < 28; i++)
  352. insbuf[i] = (baddr[i * 2 + 1] << 8) + baddr[i * 2];
  353. }
  354. /*--------------------------------------------------------------*/
  355. RELEASE_INLINE void CrixPlayer::rix_90_pro(uint16_t ctrl_l)
  356. {
  357. if(rhythm == 0 || ctrl_l < 6)
  358. {
  359. ins_to_reg(modify[ctrl_l*2],insbuf,insbuf[26]);
  360. ins_to_reg(modify[ctrl_l*2+1],insbuf+13,insbuf[27]);
  361. return;
  362. }
  363. else if(ctrl_l > 6)
  364. {
  365. ins_to_reg(modify[ctrl_l*2+6],insbuf,insbuf[26]);
  366. return;
  367. }
  368. else
  369. {
  370. ins_to_reg(12,insbuf,insbuf[26]);
  371. ins_to_reg(15,insbuf+13,insbuf[27]);
  372. return;
  373. }
  374. }
  375. /*--------------------------------------------------------------*/
  376. RELEASE_INLINE void CrixPlayer::rix_A0_pro(uint16_t ctrl_l,uint16_t index)
  377. {
  378. if(rhythm == 0 || ctrl_l <= 6)
  379. {
  380. prepare_a0b0(ctrl_l,index>0x3FFF?0x3FFF:index);
  381. ad_a0b0l_reg(ctrl_l,a0b0_data3[ctrl_l],a0b0_data4[ctrl_l]);
  382. }
  383. else return;
  384. }
  385. /*--------------------------------------------------------------*/
  386. RELEASE_INLINE void CrixPlayer::prepare_a0b0(uint16_t index,uint16_t v) /* important !*/
  387. {
  388. short high = 0,low = 0; uint32_t res;
  389. int res1 = (v-0x2000)*0x19;
  390. if(res1 == (int)0xff) return;
  391. low = res1/0x2000;
  392. if(low < 0)
  393. {
  394. low = 0x18-low; high = (signed short)low<0?0xFFFF:0;
  395. res = high; res<<=16; res+=low;
  396. low = ((signed short)res)/(signed short)0xFFE7;
  397. a0b0_data2[index] = low;
  398. low = res;
  399. res = low - 0x18;
  400. high = (signed short)res%0x19;
  401. low = (signed short)res/0x19;
  402. if(high != 0) {low = 0x19; low = low-high;}
  403. }
  404. else
  405. {
  406. res = high = low;
  407. low = (signed short)res/(signed short)0x19;
  408. a0b0_data2[index] = low;
  409. res = high;
  410. low = (signed short)res%(signed short)0x19;
  411. }
  412. low = (signed short)low*(signed short)0x18;
  413. displace[index] = low;
  414. }
  415. /*--------------------------------------------------------------*/
  416. RELEASE_INLINE void CrixPlayer::ad_a0b0l_reg(uint16_t index,uint16_t p2,uint16_t p3)
  417. {
  418. uint16_t data; uint16_t i = p2+a0b0_data2[index];
  419. a0b0_data4[index] = p3;
  420. a0b0_data3[index] = p2;
  421. i = ((signed short)i<=0x5F?i:0x5F);
  422. i = ((signed short)i>=0?i:0);
  423. data = f_buffer[addrs_head[i]+displace[index]/2];
  424. ad_bop(0xA0+index,data);
  425. data = a0b0_data5[i]*4+(p3<1?0:0x20)+((data>>8)&3);
  426. ad_bop(0xB0+index,data);
  427. }
  428. /*--------------------------------------------------------------*/
  429. RELEASE_INLINE void CrixPlayer::rix_B0_pro(uint16_t ctrl_l,uint16_t index)
  430. {
  431. int temp = 0;
  432. if(rhythm == 0 || ctrl_l < 6) temp = modify[ctrl_l*2+1];
  433. else
  434. {
  435. temp = ctrl_l > 6?ctrl_l*2:ctrl_l*2+1;
  436. temp = modify[temp+6];
  437. }
  438. for40reg[temp] = index>0x7F?0x7F:index;
  439. ad_40_reg(temp);
  440. }
  441. /*--------------------------------------------------------------*/
  442. RELEASE_INLINE void CrixPlayer::rix_C0_pro(uint16_t ctrl_l,uint16_t index)
  443. {
  444. uint16_t i = index>=12?index-12:0;
  445. if(ctrl_l < 6 || rhythm == 0)
  446. {
  447. ad_a0b0l_reg(ctrl_l,i,1);
  448. return;
  449. }
  450. else
  451. {
  452. if(ctrl_l != 6)
  453. {
  454. if(ctrl_l == 8)
  455. {
  456. ad_a0b0l_reg(ctrl_l,i,0);
  457. ad_a0b0l_reg(7,i+7,0);
  458. }
  459. }
  460. else ad_a0b0l_reg(ctrl_l,i,0);
  461. bd_modify |= bd_reg_data[ctrl_l];
  462. ad_bd_reg();
  463. return;
  464. }
  465. }
  466. /*--------------------------------------------------------------*/
  467. RELEASE_INLINE void CrixPlayer::switch_ad_bd(uint16_t index)
  468. {
  469. if(rhythm == 0 || index < 6) ad_a0b0l_reg(index,a0b0_data3[index],0);
  470. else
  471. {
  472. bd_modify &= (~bd_reg_data[index]),
  473. ad_bd_reg();
  474. }
  475. }
  476. /*--------------------------------------------------------------*/
  477. RELEASE_INLINE void CrixPlayer::ins_to_reg(uint16_t index,uint16_t* insb,uint16_t value)
  478. {
  479. uint16_t i;
  480. for(i=0;i<13;i++) reg_bufs[index].v[i] = insb[i];
  481. reg_bufs[index].v[13] = value&3;
  482. ad_bd_reg(),ad_08_reg(),
  483. ad_40_reg(index),ad_C0_reg(index),ad_60_reg(index),
  484. ad_80_reg(index),ad_20_reg(index),ad_E0_reg(index);
  485. }
  486. /*--------------------------------------------------------------*/
  487. RELEASE_INLINE void CrixPlayer::ad_E0_reg(uint16_t index)
  488. {
  489. uint16_t data = e0_reg_flag == 0?0:(reg_bufs[index].v[13]&3);
  490. ad_bop(0xE0+reg_data[index],data);
  491. }
  492. /*--------------------------------------------------------------*/
  493. RELEASE_INLINE void CrixPlayer::ad_20_reg(uint16_t index)
  494. {
  495. uint16_t data = (reg_bufs[index].v[9] < 1?0:0x80);
  496. data += (reg_bufs[index].v[10] < 1?0:0x40);
  497. data += (reg_bufs[index].v[5] < 1?0:0x20);
  498. data += (reg_bufs[index].v[11] < 1?0:0x10);
  499. data += (reg_bufs[index].v[1]&0x0F);
  500. ad_bop(0x20+reg_data[index],data);
  501. }
  502. /*--------------------------------------------------------------*/
  503. RELEASE_INLINE void CrixPlayer::ad_80_reg(uint16_t index)
  504. {
  505. uint16_t data = (reg_bufs[index].v[7]&0x0F),temp = reg_bufs[index].v[4];
  506. data |= (temp << 4);
  507. ad_bop(0x80+reg_data[index],data);
  508. }
  509. /*--------------------------------------------------------------*/
  510. void CrixPlayer::ad_60_reg(uint16_t index)
  511. {
  512. uint16_t data = reg_bufs[index].v[6]&0x0F,temp = reg_bufs[index].v[3];
  513. data |= (temp << 4);
  514. ad_bop(0x60+reg_data[index],data);
  515. }
  516. /*--------------------------------------------------------------*/
  517. RELEASE_INLINE void CrixPlayer::ad_C0_reg(uint16_t index)
  518. {
  519. uint16_t data = reg_bufs[index].v[2];
  520. if(adflag[index] == 1) return;
  521. data *= 2,
  522. data |= (reg_bufs[index].v[12] < 1?1:0);
  523. ad_bop(0xC0+ad_C0_offs[index],data);
  524. }
  525. /*--------------------------------------------------------------*/
  526. RELEASE_INLINE void CrixPlayer::ad_40_reg(uint16_t index)
  527. {
  528. uint32_t res = 0;
  529. uint16_t data = 0,temp = reg_bufs[index].v[0];
  530. data = 0x3F - (0x3F & reg_bufs[index].v[8]),
  531. data *= for40reg[index],
  532. data *= 2,
  533. data += 0x7F,
  534. res = data;
  535. data = res/0xFE,
  536. data -= 0x3F,
  537. data = -data,
  538. data |= temp<<6;
  539. ad_bop(0x40+reg_data[index],data);
  540. }
  541. /*--------------------------------------------------------------*/
  542. RELEASE_INLINE void CrixPlayer::ad_bd_reg()
  543. {
  544. uint16_t data = rhythm < 1? 0:0x20;
  545. data |= bd_modify;
  546. ad_bop(0xBD,data);
  547. }
  548. /*--------------------------------------------------------------*/
  549. RELEASE_INLINE void CrixPlayer::ad_a0b0_reg(uint16_t index)
  550. {
  551. ad_bop(0xA0+index,0);
  552. ad_bop(0xB0+index,0);
  553. }
  554. /*--------------------------------------------------------------*/
  555. RELEASE_INLINE void CrixPlayer::music_ctrl()
  556. {
  557. int i;
  558. for(i=0;i<11;i++)
  559. switch_ad_bd(i);
  560. }