comparison src/adplug/core/psi.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 3da1b8942b8b
children
comparison
equal deleted inserted replaced
954:d7a6fd179cd2 955:4709ce4e209e
36 */ 36 */
37 37
38 #include "psi.h" 38 #include "psi.h"
39 #include "debug.h" 39 #include "debug.h"
40 40
41 const unsigned char CxadpsiPlayer::psi_adlib_registers[99] = 41 const unsigned char
42 { 42 CxadpsiPlayer::psi_adlib_registers[99] = {
43 0x20, 0x23, 0x40, 0x43, 0x60, 0x63, 0x80, 0x83, 0xE0, 0xE3, 0xC0, 43 0x20, 0x23, 0x40, 0x43, 0x60, 0x63, 0x80, 0x83, 0xE0, 0xE3, 0xC0,
44 0x21, 0x24, 0x41, 0x44, 0x61, 0x64, 0x81, 0x84, 0xE1, 0xE4, 0xC1, 44 0x21, 0x24, 0x41, 0x44, 0x61, 0x64, 0x81, 0x84, 0xE1, 0xE4, 0xC1,
45 0x22, 0x25, 0x42, 0x45, 0x62, 0x65, 0x82, 0x85, 0xE2, 0xE5, 0xC2, 45 0x22, 0x25, 0x42, 0x45, 0x62, 0x65, 0x82, 0x85, 0xE2, 0xE5, 0xC2,
46 0x28, 0x2B, 0x48, 0x4B, 0x68, 0x6B, 0x88, 0x8B, 0xE8, 0xEB, 0xC3, 46 0x28, 0x2B, 0x48, 0x4B, 0x68, 0x6B, 0x88, 0x8B, 0xE8, 0xEB, 0xC3,
47 0x29, 0x2C, 0x49, 0x4C, 0x69, 0x6C, 0x89, 0x8C, 0xE9, 0xEC, 0xC4, 47 0x29, 0x2C, 0x49, 0x4C, 0x69, 0x6C, 0x89, 0x8C, 0xE9, 0xEC, 0xC4,
49 0x30, 0x33, 0x50, 0x53, 0x70, 0x73, 0x90, 0x93, 0xF0, 0xF3, 0xC6, 49 0x30, 0x33, 0x50, 0x53, 0x70, 0x73, 0x90, 0x93, 0xF0, 0xF3, 0xC6,
50 0x31, 0x34, 0x51, 0x54, 0x71, 0x74, 0x91, 0x94, 0xF1, 0xF4, 0xC7, 50 0x31, 0x34, 0x51, 0x54, 0x71, 0x74, 0x91, 0x94, 0xF1, 0xF4, 0xC7,
51 0x32, 0x35, 0x52, 0x55, 0x72, 0x75, 0x92, 0x95, 0xF2, 0xF5, 0xC8 51 0x32, 0x35, 0x52, 0x55, 0x72, 0x75, 0x92, 0x95, 0xF2, 0xF5, 0xC8
52 }; 52 };
53 53
54 const unsigned short CxadpsiPlayer::psi_notes[16] = 54 const unsigned short
55 { 55 CxadpsiPlayer::psi_notes[16] = {
56 0x216B, 0x2181, 0x2198, 0x21B0, 0x21CA, 0x21E5, 0x2202, 0x2220, 56 0x216B, 0x2181, 0x2198, 0x21B0, 0x21CA, 0x21E5, 0x2202, 0x2220,
57 0x2241, 0x2263, 0x2287, 0x2364, 57 0x2241, 0x2263, 0x2287, 0x2364,
58 0x0000, 0x0000, 0x0000, 0x0000 // by riven 58 0x0000, 0x0000, 0x0000, 0x0000 // by riven
59 }; 59 };
60 60
61 CPlayer *CxadpsiPlayer::factory(Copl *newopl) 61 CPlayer *
62 CxadpsiPlayer::factory (Copl * newopl)
62 { 63 {
63 return new CxadpsiPlayer(newopl); 64 return new CxadpsiPlayer (newopl);
64 } 65 }
65 66
66 void CxadpsiPlayer::xadplayer_rewind(int subsong) 67 void
68 CxadpsiPlayer::xadplayer_rewind (int subsong)
67 { 69 {
68 opl_write(0x01, 0x20); 70 opl_write (0x01, 0x20);
69 opl_write(0x08, 0x00); 71 opl_write (0x08, 0x00);
70 opl_write(0xBD, 0x00); 72 opl_write (0xBD, 0x00);
71 73
72 // get header 74 // get header
73 header.instr_ptr = (tune[1] << 8) + tune[0]; 75 header.instr_ptr = (tune[1] << 8) + tune[0];
74 header.seq_ptr = (tune[3] << 8) + tune[2]; 76 header.seq_ptr = (tune[3] << 8) + tune[2];
75 77
76 // define instruments 78 // define instruments
77 psi.instr_table = &tune[header.instr_ptr]; 79 psi.instr_table = &tune[header.instr_ptr];
78 80
79 for(int i=0; i<8; i++) 81 for (int i = 0; i < 8; i++)
80 { 82 {
81 for(int j=0; j<11; j++) { 83 for (int j = 0; j < 11; j++)
82 unsigned short inspos = (psi.instr_table[i * 2 + 1] << 8) + psi.instr_table[i * 2]; 84 {
85 unsigned short inspos =
86 (psi.instr_table[i * 2 + 1] << 8) + psi.instr_table[i * 2];
83 87
84 opl_write(psi_adlib_registers[i*11 + j],tune[inspos + j]); 88 opl_write (psi_adlib_registers[i * 11 + j], tune[inspos + j]);
85 } 89 }
86 90
87 opl_write(0xA0+i, 0x00); 91 opl_write (0xA0 + i, 0x00);
88 opl_write(0xB0+i, 0x00); 92 opl_write (0xB0 + i, 0x00);
89 93
90 psi.note_delay[i] = 1; 94 psi.note_delay[i] = 1;
91 psi.note_curdelay[i] = 1; 95 psi.note_curdelay[i] = 1;
92 psi.looping[i] = 0; 96 psi.looping[i] = 0;
93 } 97 }
94 98
95 // calculate sequence pointer 99 // calculate sequence pointer
96 psi.seq_table = &tune[header.seq_ptr]; 100 psi.seq_table = &tune[header.seq_ptr];
97 } 101 }
98 102
99 void CxadpsiPlayer::xadplayer_update() 103 void
104 CxadpsiPlayer::xadplayer_update ()
100 { 105 {
101 unsigned short ptr; 106 unsigned short ptr;
102 107
103 for(int i=0; i<8; i++) 108 for (int i = 0; i < 8; i++)
104 { 109 {
105 ptr = (psi.seq_table[(i<<1) * 2 + 1] << 8) + psi.seq_table[(i<<1) * 2]; 110 ptr =
111 (psi.seq_table[(i << 1) * 2 + 1] << 8) + psi.seq_table[(i << 1) * 2];
106 112
107 psi.note_curdelay[i]--; 113 psi.note_curdelay[i]--;
108 114
109 if (!psi.note_curdelay[i]) 115 if (!psi.note_curdelay[i])
110 { 116 {
111 opl_write(0xA0+i, 0x00); 117 opl_write (0xA0 + i, 0x00);
112 opl_write(0xB0+i, 0x00); 118 opl_write (0xB0 + i, 0x00);
113 119
114 unsigned char event = tune[ptr++]; 120 unsigned char event = tune[ptr++];
115 #ifdef DEBUG 121 #ifdef DEBUG
116 AdPlug_LogWrite("channel %02X, event %02X:\n",i+1,event); 122 AdPlug_LogWrite ("channel %02X, event %02X:\n", i + 1, event);
117 #endif 123 #endif
118 124
119 // end of sequence ? 125 // end of sequence ?
120 if (!event) 126 if (!event)
121 { 127 {
122 ptr = (psi.seq_table[(i<<1) * 2 + 3] << 8) + psi.seq_table[(i<<1) * 2 + 2]; 128 ptr =
129 (psi.seq_table[(i << 1) * 2 + 3] << 8) +
130 psi.seq_table[(i << 1) * 2 + 2];
123 131
124 event = tune[ptr++]; 132 event = tune[ptr++];
125 #ifdef DEBUG 133 #ifdef DEBUG
126 AdPlug_LogWrite(" channel %02X, event %02X:\n",i+1,event); 134 AdPlug_LogWrite (" channel %02X, event %02X:\n", i + 1, event);
127 #endif 135 #endif
128 136
129 // set sequence loop flag 137 // set sequence loop flag
130 psi.looping[i] = 1; 138 psi.looping[i] = 1;
131 139
132 // module loop ? 140 // module loop ?
133 plr.looping = 1; 141 plr.looping = 1;
134 for(int j=0; j<8; j++) 142 for (int j = 0; j < 8; j++)
135 plr.looping &= psi.looping[j]; 143 plr.looping &= psi.looping[j];
136 } 144 }
137 145
138 // new note delay ? 146 // new note delay ?
139 if (event & 0x80) 147 if (event & 0x80)
140 { 148 {
141 psi.note_delay[i] = (event & 0x7F); 149 psi.note_delay[i] = (event & 0x7F);
142 150
143 event = tune[ptr++]; 151 event = tune[ptr++];
144 #ifdef DEBUG 152 #ifdef DEBUG
145 AdPlug_LogWrite(" channel %02X, event %02X:\n",i+1,event); 153 AdPlug_LogWrite (" channel %02X, event %02X:\n", i + 1, event);
146 #endif 154 #endif
147 } 155 }
148 156
149 psi.note_curdelay[i] = psi.note_delay[i]; 157 psi.note_curdelay[i] = psi.note_delay[i];
150 158
151 // play note 159 // play note
152 unsigned short note = psi_notes[event & 0x0F]; 160 unsigned short note = psi_notes[event & 0x0F];
153 161
154 opl_write(0xA0+i, note & 0xFF); 162 opl_write (0xA0 + i, note & 0xFF);
155 opl_write(0xB0+i, (note >> 8) + ((event >> 2) & 0xFC)); 163 opl_write (0xB0 + i, (note >> 8) + ((event >> 2) & 0xFC));
156 164
157 // save position 165 // save position
158 psi.seq_table[(i<<1) * 2] = ptr & 0xff; 166 psi.seq_table[(i << 1) * 2] = ptr & 0xff;
159 psi.seq_table[(i<<1) * 2 + 1] = ptr >> 8; 167 psi.seq_table[(i << 1) * 2 + 1] = ptr >> 8;
160 } 168 }
161 } 169 }
162 } 170 }
163 171
164 float CxadpsiPlayer::xadplayer_getrefresh() 172 float
173 CxadpsiPlayer::xadplayer_getrefresh ()
165 { 174 {
166 return 70.0f; 175 return 70.0f;
167 } 176 }
168 177
169 std::string CxadpsiPlayer::xadplayer_gettype() 178 std::string CxadpsiPlayer::xadplayer_gettype ()
170 { 179 {
171 return std::string("xad: psi player"); 180 return std::string ("xad: psi player");
172 } 181 }
173 182
174 unsigned int CxadpsiPlayer::xadplayer_getinstruments() 183 unsigned int
184 CxadpsiPlayer::xadplayer_getinstruments ()
175 { 185 {
176 return 8; 186 return 8;
177 } 187 }