|
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
|
|
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
18 *
|
|
|
19 * [xad] HYBRID player, by Riven the Mage <riven@ok.ru>
|
|
|
20 */
|
|
|
21
|
|
|
22 /*
|
|
|
23 - discovery -
|
|
|
24
|
|
|
25 file(s) : HYBRID.EXE
|
|
|
26 type : Hybrid cracktro for Apache Longbow CD-RIP
|
|
|
27 tune : from 'Mig-29 Super Fulcrum' game by Domark
|
|
|
28 player : from 'Mig-29 Super Fulcrum' game by Domark
|
|
|
29 */
|
|
|
30
|
|
|
31 #include "hybrid.h"
|
|
|
32 #include "debug.h"
|
|
|
33
|
|
|
34 const unsigned char CxadhybridPlayer::hyb_adlib_registers[99] =
|
|
|
35 {
|
|
|
36 0xE0, 0x60, 0x80, 0x20, 0x40, 0xE3, 0x63, 0x83, 0x23, 0x43, 0xC0,
|
|
|
37 0xE1, 0x61, 0x81, 0x21, 0x41, 0xE4, 0x64, 0x84, 0x24, 0x44, 0xC1,
|
|
|
38 0xE2, 0x62, 0x82, 0x22, 0x42, 0xE5, 0x65, 0x85, 0x25, 0x45, 0xC2,
|
|
|
39 0xE8, 0x68, 0x88, 0x28, 0x48, 0xEB, 0x6B, 0x8B, 0x2B, 0x4B, 0xC3,
|
|
|
40 0xE9, 0x69, 0x89, 0x29, 0x49, 0xEC, 0x6C, 0x8C, 0x2C, 0x4C, 0xC4,
|
|
|
41 0xEA, 0x6A, 0x8A, 0x2A, 0x4A, 0xED, 0x6D, 0x8D, 0x2D, 0x4D, 0xC5,
|
|
|
42 0xF0, 0x70, 0x90, 0x30, 0x50, 0xF3, 0x73, 0x93, 0x33, 0x53, 0xC6,
|
|
|
43 0xF1, 0x71, 0x91, 0x31, 0x51, 0xF4, 0x74, 0x94, 0x34, 0x54, 0xC7,
|
|
|
44 0xF2, 0x72, 0x92, 0x32, 0x52, 0xF5, 0x75, 0x95, 0x35, 0x55, 0xC8
|
|
|
45 };
|
|
|
46
|
|
|
47 const unsigned short CxadhybridPlayer::hyb_notes[98] =
|
|
|
48 {
|
|
|
49 0x0000, 0x0000,
|
|
|
50 0x016B, 0x0181, 0x0198, 0x01B0, 0x01CA, 0x01E5, 0x0202, 0x0220, 0x0241, 0x0263, 0x0287, 0x02AE,
|
|
|
51 0x056B, 0x0581, 0x0598, 0x05B0, 0x05CA, 0x05E5, 0x0602, 0x0620, 0x0641, 0x0663, 0x0687, 0x06AE,
|
|
|
52 0x096B, 0x0981, 0x0998, 0x09B0, 0x09CA, 0x09E5, 0x0A02, 0x0A20, 0x0A41, 0x0A63, 0x0A87, 0x0AAE,
|
|
|
53 0x0D6B, 0x0D81, 0x0D98, 0x0DB0, 0x0DCA, 0x0DE5, 0x0E02, 0x0E20, 0x0E41, 0x0E63, 0x0E87, 0x0EAE,
|
|
|
54 0x116B, 0x1181, 0x1198, 0x11B0, 0x11CA, 0x11E5, 0x1202, 0x1220, 0x1241, 0x1263, 0x1287, 0x12AE,
|
|
|
55 0x156B, 0x1581, 0x1598, 0x15B0, 0x15CA, 0x15E5, 0x1602, 0x1620, 0x1641, 0x1663, 0x1687, 0x16AE,
|
|
|
56 0x196B, 0x1981, 0x1998, 0x19B0, 0x19CA, 0x19E5, 0x1A02, 0x1A20, 0x1A41, 0x1A63, 0x1A87, 0x1AAE,
|
|
|
57 0x1D6B, 0x1D81, 0x1D98, 0x1DB0, 0x1DCA, 0x1DE5, 0x1E02, 0x1E20, 0x1E41, 0x1E63, 0x1E87, 0x1EAE
|
|
|
58 };
|
|
|
59
|
|
|
60 const unsigned char CxadhybridPlayer::hyb_default_instrument[11] =
|
|
|
61 {
|
|
|
62 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00
|
|
|
63 };
|
|
|
64
|
|
|
65 CPlayer *CxadhybridPlayer::factory(Copl *newopl)
|
|
|
66 {
|
|
|
67 return new CxadhybridPlayer(newopl);
|
|
|
68 }
|
|
|
69
|
|
|
70 bool CxadhybridPlayer::xadplayer_load()
|
|
|
71 {
|
|
|
72 if(xad.fmt != HYBRID)
|
|
|
73 return false;
|
|
|
74
|
|
|
75 // load instruments
|
|
|
76 hyb.inst = (hyb_instrument *)&tune[0];
|
|
|
77
|
|
|
78 // load order
|
|
|
79 hyb.order = &tune[0x1D4];
|
|
|
80
|
|
|
81 return true;
|
|
|
82 }
|
|
|
83
|
|
|
84 void CxadhybridPlayer::xadplayer_rewind(int subsong)
|
|
|
85 {
|
|
|
86 int i;
|
|
|
87
|
|
|
88 hyb.order_pos = 0;
|
|
|
89 hyb.pattern_pos = 0;
|
|
|
90
|
|
|
91 hyb.speed = 6;
|
|
|
92 hyb.speed_counter = 1;
|
|
|
93
|
|
|
94 plr.speed = 1;
|
|
|
95
|
|
|
96 // init channel data
|
|
|
97 for(i=0;i<9;i++)
|
|
|
98 {
|
|
|
99 hyb.channel[i].freq = 0x2000;
|
|
|
100 hyb.channel[i].freq_slide = 0x0000;
|
|
|
101 }
|
|
|
102
|
|
|
103 // basic OPL init
|
|
|
104 opl_write(0x01, 0x20);
|
|
|
105 opl_write(0xBD, 0x40);
|
|
|
106 opl_write(0x08, 0x00);
|
|
|
107
|
|
|
108 // init OPL channels
|
|
|
109 for(i=0;i<9;i++)
|
|
|
110 {
|
|
|
111 for(int j=0;j<11;j++)
|
|
|
112 opl_write(hyb_adlib_registers[i*11+j], 0x00 /* hyb_default_instrument[j] */ );
|
|
|
113
|
|
|
114 opl_write(0xA0+i, 0x00);
|
|
|
115 opl_write(0xB0+i, 0x20);
|
|
|
116 }
|
|
|
117 }
|
|
|
118
|
|
|
119 void CxadhybridPlayer::xadplayer_update()
|
|
|
120 {
|
|
|
121 int i,j;
|
|
|
122 unsigned char patpos,ordpos;
|
|
|
123
|
|
|
124 if (--hyb.speed_counter)
|
|
|
125 goto update_slides;
|
|
|
126
|
|
|
127 hyb.speed_counter = hyb.speed;
|
|
|
128
|
|
|
129 patpos = hyb.pattern_pos;
|
|
|
130 ordpos = hyb.order_pos;
|
|
|
131
|
|
|
132 // process channels
|
|
|
133 for(i=0;i<9;i++)
|
|
|
134 {
|
|
|
135 // read event
|
|
|
136 unsigned short event = *(unsigned short *)&tune[0xADE + (hyb.order[hyb.order_pos*9 + i] * 64 * 2) + (patpos * 2)];
|
|
|
137
|
|
|
138 #ifdef DEBUG
|
|
|
139 AdPlug_LogWrite("track %02X, channel %02X, event %04X:\n", hyb.order[hyb.order_pos*9 + i], i, event );
|
|
|
140 #endif
|
|
|
141
|
|
|
142 // calculate variables
|
|
|
143 unsigned char note = event >> 9;
|
|
|
144 unsigned char ins = ((event & 0x01F0) >> 4);
|
|
|
145 unsigned char slide = event & 0x000F;
|
|
|
146
|
|
|
147 // play event
|
|
|
148 switch(note)
|
|
|
149 {
|
|
|
150 case 0x7D: // 0x7D: Set Speed
|
|
|
151 hyb.speed = event & 0xFF;
|
|
|
152 break;
|
|
|
153 case 0x7E: // 0x7E: Jump Position
|
|
|
154 hyb.order_pos = event & 0xFF;
|
|
|
155 hyb.pattern_pos = 0x3F;
|
|
|
156
|
|
|
157 // jumpback ?
|
|
|
158 if (hyb.order_pos <= ordpos)
|
|
|
159 plr.looping = 1;
|
|
|
160
|
|
|
161 break;
|
|
|
162 case 0x7F: // 0x7F: Pattern Break
|
|
|
163 hyb.pattern_pos = 0x3F;
|
|
|
164 break;
|
|
|
165 default:
|
|
|
166
|
|
|
167 // is instrument ?
|
|
|
168 if (ins)
|
|
|
169 for(j=0;j<11;j++)
|
|
|
170 opl_write(hyb_adlib_registers[i*11+j], *((unsigned char *)&hyb.inst[ins-1] + 7 + j)); // +7 = skip name...
|
|
|
171
|
|
|
172 // is note ?
|
|
|
173 if (note)
|
|
|
174 {
|
|
|
175 hyb.channel[i].freq = hyb_notes[note];
|
|
|
176 hyb.channel[i].freq_slide = 0;
|
|
|
177 }
|
|
|
178
|
|
|
179 // is slide ?
|
|
|
180 if (slide)
|
|
|
181 {
|
|
|
182 hyb.channel[i].freq_slide = (((slide >> 3) * -1) * (slide & 7)) << 1;
|
|
|
183
|
|
|
184 if (slide & 0x80)
|
|
|
185 slide = -(slide & 7);
|
|
|
186 }
|
|
|
187
|
|
|
188 // set frequency
|
|
|
189 if (!(hyb.channel[i].freq & 0x2000))
|
|
|
190 {
|
|
|
191 opl_write(0xA0+i, hyb.channel[i].freq & 0xFF);
|
|
|
192 opl_write(0xB0+i, hyb.channel[i].freq >> 8);
|
|
|
193
|
|
|
194 hyb.channel[i].freq |= 0x2000;
|
|
|
195
|
|
|
196 opl_write(0xA0+i, hyb.channel[i].freq & 0xFF);
|
|
|
197 opl_write(0xB0+i, hyb.channel[i].freq >> 8);
|
|
|
198 }
|
|
|
199
|
|
|
200 break;
|
|
|
201 }
|
|
|
202 }
|
|
|
203
|
|
|
204 hyb.pattern_pos++;
|
|
|
205
|
|
|
206 // end of pattern ?
|
|
|
207 if (hyb.pattern_pos >= 0x40)
|
|
|
208 {
|
|
|
209 hyb.pattern_pos = 0;
|
|
|
210
|
|
|
211 hyb.order_pos++;
|
|
|
212 }
|
|
|
213
|
|
|
214 update_slides:
|
|
|
215 #ifdef DEBUG
|
|
|
216 AdPlug_LogWrite("slides:\n");
|
|
|
217 #endif
|
|
|
218 // update fine frequency slides
|
|
|
219 for(i=0;i<9;i++)
|
|
|
220 if (hyb.channel[i].freq_slide)
|
|
|
221 {
|
|
|
222 hyb.channel[i].freq = (((hyb.channel[i].freq & 0x1FFF) + hyb.channel[i].freq_slide) & 0x1FFF) | 0x2000;
|
|
|
223
|
|
|
224 opl_write(0xA0+i, hyb.channel[i].freq & 0xFF);
|
|
|
225 opl_write(0xB0+i, hyb.channel[i].freq >> 8);
|
|
|
226 }
|
|
|
227 }
|
|
|
228
|
|
|
229 float CxadhybridPlayer::xadplayer_getrefresh()
|
|
|
230 {
|
|
|
231 return 50.0f;
|
|
|
232 }
|
|
|
233
|
|
|
234 std::string CxadhybridPlayer::xadplayer_gettype()
|
|
|
235 {
|
|
|
236 return (std::string("xad: hybrid player"));
|
|
|
237 }
|
|
|
238
|
|
|
239 std::string CxadhybridPlayer::xadplayer_getinstrument(unsigned int i)
|
|
|
240 {
|
|
|
241 return (std::string(hyb.inst[i].name,7));
|
|
|
242 }
|
|
|
243
|
|
|
244 unsigned int CxadhybridPlayer::xadplayer_getinstruments()
|
|
|
245 {
|
|
|
246 return 26;
|
|
|
247 }
|