|
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] PSI player, by Riven the Mage <riven@ok.ru>
|
|
|
20 */
|
|
|
21
|
|
|
22 /*
|
|
|
23 - discovery -
|
|
|
24
|
|
|
25 file(s) : 4BIDDEN.COM, PGRID.EXE
|
|
|
26 type : Forbidden Dreams BBStro
|
|
|
27 Power Grid BBStro
|
|
|
28 tune : by Friar Tuck [Shadow Faction/ICE]
|
|
|
29 player : by Psi [Future Crew]
|
|
|
30 comment : seems to me what 4bidden tune & player was ripped from pgrid
|
|
|
31
|
|
|
32 file(s) : MYSTRUNE.COM
|
|
|
33 type : Mystical Runes BBStro
|
|
|
34 tune : by ?
|
|
|
35 player : by Psi [Future Crew]
|
|
|
36 */
|
|
|
37
|
|
|
38 #include "psi.h"
|
|
|
39 #include "debug.h"
|
|
|
40
|
|
|
41 const unsigned char CxadpsiPlayer::psi_adlib_registers[99] =
|
|
|
42 {
|
|
|
43 0x20, 0x23, 0x40, 0x43, 0x60, 0x63, 0x80, 0x83, 0xE0, 0xE3, 0xC0,
|
|
|
44 0x21, 0x24, 0x41, 0x44, 0x61, 0x64, 0x81, 0x84, 0xE1, 0xE4, 0xC1,
|
|
|
45 0x22, 0x25, 0x42, 0x45, 0x62, 0x65, 0x82, 0x85, 0xE2, 0xE5, 0xC2,
|
|
|
46 0x28, 0x2B, 0x48, 0x4B, 0x68, 0x6B, 0x88, 0x8B, 0xE8, 0xEB, 0xC3,
|
|
|
47 0x29, 0x2C, 0x49, 0x4C, 0x69, 0x6C, 0x89, 0x8C, 0xE9, 0xEC, 0xC4,
|
|
|
48 0x2A, 0x2D, 0x4A, 0x4D, 0x6A, 0x6D, 0x8A, 0x8D, 0xEA, 0xED, 0xC5,
|
|
|
49 0x30, 0x33, 0x50, 0x53, 0x70, 0x73, 0x90, 0x93, 0xF0, 0xF3, 0xC6,
|
|
|
50 0x31, 0x34, 0x51, 0x54, 0x71, 0x74, 0x91, 0x94, 0xF1, 0xF4, 0xC7,
|
|
|
51 0x32, 0x35, 0x52, 0x55, 0x72, 0x75, 0x92, 0x95, 0xF2, 0xF5, 0xC8
|
|
|
52 };
|
|
|
53
|
|
|
54 const unsigned short CxadpsiPlayer::psi_notes[16] =
|
|
|
55 {
|
|
|
56 0x216B, 0x2181, 0x2198, 0x21B0, 0x21CA, 0x21E5, 0x2202, 0x2220,
|
|
|
57 0x2241, 0x2263, 0x2287, 0x2364,
|
|
|
58 0x0000, 0x0000, 0x0000, 0x0000 // by riven
|
|
|
59 };
|
|
|
60
|
|
|
61 CPlayer *CxadpsiPlayer::factory(Copl *newopl)
|
|
|
62 {
|
|
|
63 return new CxadpsiPlayer(newopl);
|
|
|
64 }
|
|
|
65
|
|
|
66 void CxadpsiPlayer::xadplayer_rewind(int subsong)
|
|
|
67 {
|
|
|
68 opl_write(0x01, 0x20);
|
|
|
69 opl_write(0x08, 0x00);
|
|
|
70 opl_write(0xBD, 0x00);
|
|
|
71
|
|
|
72 // define instruments
|
|
|
73 psi.instr_table = (unsigned short *)&tune[((psi_header *)&tune[0])->instr_ptr];
|
|
|
74
|
|
|
75 for(int i=0; i<8; i++)
|
|
|
76 {
|
|
|
77 for(int j=0; j<11; j++)
|
|
|
78 opl_write(psi_adlib_registers[i*11 + j],tune[psi.instr_table[i] + j]);
|
|
|
79
|
|
|
80 opl_write(0xA0+i, 0x00);
|
|
|
81 opl_write(0xB0+i, 0x00);
|
|
|
82
|
|
|
83 psi.note_delay[i] = 1;
|
|
|
84 psi.note_curdelay[i] = 1;
|
|
|
85 psi.looping[i] = 0;
|
|
|
86 }
|
|
|
87
|
|
|
88 // calculate sequence pointer
|
|
|
89 psi.seq_table = (unsigned short *)&tune[((psi_header *)&tune[0])->seq_ptr];
|
|
|
90 }
|
|
|
91
|
|
|
92 void CxadpsiPlayer::xadplayer_update()
|
|
|
93 {
|
|
|
94 unsigned short ptr;
|
|
|
95
|
|
|
96 for(int i=0; i<8; i++)
|
|
|
97 {
|
|
|
98 ptr = psi.seq_table[i<<1];
|
|
|
99
|
|
|
100 psi.note_curdelay[i]--;
|
|
|
101
|
|
|
102 if (!psi.note_curdelay[i])
|
|
|
103 {
|
|
|
104 opl_write(0xA0+i, 0x00);
|
|
|
105 opl_write(0xB0+i, 0x00);
|
|
|
106
|
|
|
107 unsigned char event = tune[ptr++];
|
|
|
108 #ifdef DEBUG
|
|
|
109 AdPlug_LogWrite("channel %02X, event %02X:\n",i+1,event);
|
|
|
110 #endif
|
|
|
111
|
|
|
112 // end of sequence ?
|
|
|
113 if (!event)
|
|
|
114 {
|
|
|
115 ptr = psi.seq_table[(i<<1) + 1];
|
|
|
116
|
|
|
117 event = tune[ptr++];
|
|
|
118 #ifdef DEBUG
|
|
|
119 AdPlug_LogWrite(" channel %02X, event %02X:\n",i+1,event);
|
|
|
120 #endif
|
|
|
121
|
|
|
122 // set sequence loop flag
|
|
|
123 psi.looping[i] = 1;
|
|
|
124
|
|
|
125 // module loop ?
|
|
|
126 plr.looping = 1;
|
|
|
127 for(int j=0; j<8; j++)
|
|
|
128 plr.looping &= psi.looping[j];
|
|
|
129 }
|
|
|
130
|
|
|
131 // new note delay ?
|
|
|
132 if (event & 0x80)
|
|
|
133 {
|
|
|
134 psi.note_delay[i] = (event & 0x7F);
|
|
|
135
|
|
|
136 event = tune[ptr++];
|
|
|
137 #ifdef DEBUG
|
|
|
138 AdPlug_LogWrite(" channel %02X, event %02X:\n",i+1,event);
|
|
|
139 #endif
|
|
|
140 }
|
|
|
141
|
|
|
142 psi.note_curdelay[i] = psi.note_delay[i];
|
|
|
143
|
|
|
144 // play note
|
|
|
145 unsigned short note = psi_notes[event & 0x0F];
|
|
|
146
|
|
|
147 opl_write(0xA0+i, note & 0xFF);
|
|
|
148 opl_write(0xB0+i, (note >> 8) + ((event >> 2) & 0xFC));
|
|
|
149
|
|
|
150 // save position
|
|
|
151 psi.seq_table[i<<1] = ptr;
|
|
|
152 }
|
|
|
153 }
|
|
|
154 }
|
|
|
155
|
|
|
156 float CxadpsiPlayer::xadplayer_getrefresh()
|
|
|
157 {
|
|
|
158 return 70.0f;
|
|
|
159 }
|
|
|
160
|
|
|
161 std::string CxadpsiPlayer::xadplayer_gettype()
|
|
|
162 {
|
|
|
163 return std::string("xad: psi player");
|
|
|
164 }
|
|
|
165
|
|
|
166 unsigned int CxadpsiPlayer::xadplayer_getinstruments()
|
|
|
167 {
|
|
|
168 return 8;
|
|
|
169 }
|