| 1 |
/* |
| 2 |
* Copyright (C) 2023-2024 nukeykt |
| 3 |
* |
| 4 |
* This file is part of YM2608-LLE. |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU General Public License |
| 8 |
* as published by the Free Software Foundation; either version 2 |
| 9 |
* of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* YM2608/YM2610/YM2612 emulator. |
| 17 |
* Thanks: |
| 18 |
* Raki (ika-musume): |
| 19 |
* YM2608B decap |
| 20 |
* John McMaster (siliconpr0n.org): |
| 21 |
* YM2610 decap |
| 22 |
* HardWareMan: |
| 23 |
* YM2612 decap |
| 24 |
* |
| 25 |
*/ |
| 26 |
#include <string.h> |
| 27 |
#include "fmopna_impl.h" |
| 28 |
#ifdef FMOPNA_YM2608 |
| 29 |
#include "fmopna_rom.h" |
| 30 |
#endif |
| 31 |
|
| 32 |
enum { |
| 33 |
eg_state_attack = 0, |
| 34 |
eg_state_decay, |
| 35 |
eg_state_sustain, |
| 36 |
eg_state_release |
| 37 |
}; |
| 38 |
|
| 39 |
static const int fm_algorithm[4][6][8] = { |
| 40 |
{ |
| 41 |
{ 1, 1, 1, 1, 1, 1, 1, 1 }, /* OP1_0 */ |
| 42 |
{ 1, 1, 1, 1, 1, 1, 1, 1 }, /* OP1_1 */ |
| 43 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* OP2 */ |
| 44 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* Last operator */ |
| 45 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* Last operator */ |
| 46 |
{ 0, 0, 0, 0, 0, 0, 0, 1 } /* Out */ |
| 47 |
}, |
| 48 |
{ |
| 49 |
{ 0, 1, 0, 0, 0, 1, 0, 0 }, /* OP1_0 */ |
| 50 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* OP1_1 */ |
| 51 |
{ 1, 1, 1, 0, 0, 0, 0, 0 }, /* OP2 */ |
| 52 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* Last operator */ |
| 53 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* Last operator */ |
| 54 |
{ 0, 0, 0, 0, 0, 1, 1, 1 } /* Out */ |
| 55 |
}, |
| 56 |
{ |
| 57 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* OP1_0 */ |
| 58 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* OP1_1 */ |
| 59 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* OP2 */ |
| 60 |
{ 1, 0, 0, 1, 1, 1, 1, 0 }, /* Last operator */ |
| 61 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* Last operator */ |
| 62 |
{ 0, 0, 0, 0, 1, 1, 1, 1 } /* Out */ |
| 63 |
}, |
| 64 |
{ |
| 65 |
{ 0, 0, 1, 0, 0, 1, 0, 0 }, /* OP1_0 */ |
| 66 |
{ 0, 0, 0, 0, 0, 0, 0, 0 }, /* OP1_1 */ |
| 67 |
{ 0, 0, 0, 1, 0, 0, 0, 0 }, /* OP2 */ |
| 68 |
{ 1, 1, 0, 1, 1, 0, 0, 0 }, /* Last operator */ |
| 69 |
{ 0, 0, 1, 0, 0, 0, 0, 0 }, /* Last operator */ |
| 70 |
{ 1, 1, 1, 1, 1, 1, 1, 1 } /* Out */ |
| 71 |
} |
| 72 |
}; |
| 73 |
|
| 74 |
|
| 75 |
#ifdef FMOPNA_YM2608 |
| 76 |
void FMOPNA_Clock(fmopna_t* chip, int clk) |
| 77 |
#elif defined (FMOPNA_YM2610) |
| 78 |
void FMOPNA_2610_Clock(fmopna_2610_t* chip, int clk) |
| 79 |
#else |
| 80 |
void FMOPNA_2612_Clock(fmopna_2612_t* chip, int clk) |
| 81 |
#endif |
| 82 |
{ |
| 83 |
int i; |
| 84 |
|
| 85 |
chip->input.clk = clk; |
| 86 |
|
| 87 |
chip->mclk1 = !chip->input.clk; |
| 88 |
chip->mclk2 = chip->input.clk; |
| 89 |
|
| 90 |
chip->ic = !chip->input.ic; |
| 91 |
|
| 92 |
|
| 93 |
if (chip->mclk1) |
| 94 |
{ |
| 95 |
int prescaler_of = 0; |
| 96 |
int dclk = 1; |
| 97 |
#ifdef FMOPNA_YM2608 |
| 98 |
switch (chip->prescaler_sel[1]) |
| 99 |
{ |
| 100 |
case 2: |
| 101 |
prescaler_of = (chip->prescaler_latch[1] & 0x7ff) == 0; |
| 102 |
dclk = (chip->prescaler_latch[1] & 0xffc) == 0; |
| 103 |
break; |
| 104 |
case 0: |
| 105 |
prescaler_of = (chip->prescaler_latch[1] & 7) == 0; |
| 106 |
dclk = (chip->prescaler_latch[1] & 7) != 0; |
| 107 |
break; |
| 108 |
case 3: |
| 109 |
prescaler_of = (chip->prescaler_latch[1] & 0x1f) == 0; |
| 110 |
dclk = (chip->prescaler_latch[1] & 0x1f) == 0; |
| 111 |
break; |
| 112 |
|
| 113 |
} |
| 114 |
#endif |
| 115 |
#ifdef FMOPNA_YM2610 |
| 116 |
prescaler_of = (chip->prescaler_latch[1] & 0x7ff) == 0; |
| 117 |
dclk = (chip->prescaler_latch[1] & 0xffc) == 0; |
| 118 |
#endif |
| 119 |
#ifdef FMOPNA_YM2612 |
| 120 |
prescaler_of = (chip->prescaler_latch[1] & 0x1f) == 0; |
| 121 |
#endif |
| 122 |
chip->ic_latch1[0] = chip->ic; |
| 123 |
|
| 124 |
chip->ic_latch2[0] = (chip->ic_latch2[1] << 1) | chip->ic_latch1[1]; |
| 125 |
chip->ic_latch3[0] = (chip->ic_latch3[1] << 1) | chip->ic_check1; |
| 126 |
|
| 127 |
chip->prescaler_latch[0] = chip->prescaler_latch[1] << 1; |
| 128 |
chip->prescaler_latch[0] |= !chip->ic_check1 && prescaler_of; |
| 129 |
|
| 130 |
#ifdef FMOPNA_YM2608 |
| 131 |
chip->pssel_l[0][0] = (chip->prescaler_latch[1] & 0x861) != 0; |
| 132 |
chip->pssel_l[1][0] = (chip->prescaler_latch[1] & 0x30c) != 0; |
| 133 |
chip->pssel_l[2][0] = (chip->prescaler_latch[1] & 0x12) != 0; |
| 134 |
chip->pssel_l[3][0] = (chip->prescaler_latch[1] & 0x24) != 0; |
| 135 |
chip->pssel_l[4][0] = chip->pssel_l[4][1] << 1; |
| 136 |
chip->pssel_l[4][0] |= (chip->prescaler_latch[1] & 0x5) != 0; |
| 137 |
chip->pssel_l[5][0] = (chip->prescaler_latch[1] & 0x3c) != 0; |
| 138 |
chip->pssel_l[6][0] = (chip->prescaler_latch[1] & 0xf00) != 0; |
| 139 |
chip->pssel_l[7][0] = (chip->prescaler_latch[1] & 0xc) != 0; |
| 140 |
chip->pssel_l[8][0] = (chip->prescaler_latch[1] & 0x21) != 0; |
| 141 |
chip->pssel_l[9][0] = (chip->prescaler_latch[1] & 0x2) != 0; |
| 142 |
chip->pssel_l[10][0] = (chip->prescaler_latch[1] & 0x1) != 0; |
| 143 |
chip->pssel_l[11][0] = (chip->prescaler_latch[1] & 0x924) != 0; |
| 144 |
chip->pssel_l[12][0] = (chip->prescaler_latch[1] & 0x249) != 0; |
| 145 |
chip->pssel_l[13][0] = chip->pssel_l[13][1] << 1; |
| 146 |
chip->pssel_l[13][0] |= (chip->prescaler_latch[1] & 9) == 0; |
| 147 |
chip->pssel_l[14][0] = (chip->prescaler_latch[1] & 0x555) != 0; |
| 148 |
|
| 149 |
chip->dclk = dclk; |
| 150 |
#endif |
| 151 |
#ifdef FMOPNA_YM2610 |
| 152 |
chip->pssel_l[0][0] = (chip->prescaler_latch[1] & 0x861) != 0; |
| 153 |
chip->pssel_l[1][0] = (chip->prescaler_latch[1] & 0x30c) != 0; |
| 154 |
chip->pssel_l[5][0] = (chip->prescaler_latch[1] & 0x3c) != 0; |
| 155 |
chip->pssel_l[6][0] = (chip->prescaler_latch[1] & 0xf00) != 0; |
| 156 |
chip->pssel_l[11][0] = (chip->prescaler_latch[1] & 0x924) != 0; |
| 157 |
chip->pssel_l[12][0] = (chip->prescaler_latch[1] & 0x249) != 0; |
| 158 |
chip->pssel_l[14][0] = (chip->prescaler_latch[1] & 0x555) != 0; |
| 159 |
|
| 160 |
chip->dclk = dclk; |
| 161 |
#endif |
| 162 |
#ifdef FMOPNA_YM2612 |
| 163 |
chip->pssel_l[0][0] = (chip->prescaler_latch[1] & 0x21) != 0; |
| 164 |
chip->pssel_l[1][0] = (chip->prescaler_latch[1] & 0xc) != 0; |
| 165 |
#endif |
| 166 |
|
| 167 |
} |
| 168 |
if (chip->mclk2) |
| 169 |
{ |
| 170 |
chip->ic_latch1[1] = chip->ic_latch1[0]; |
| 171 |
chip->ic_latch2[1] = chip->ic_latch2[0]; |
| 172 |
chip->ic_latch3[1] = chip->ic_latch3[0]; |
| 173 |
|
| 174 |
#ifndef FMOPNA_YM2612 |
| 175 |
chip->ic_check1 = chip->ic_latch1[1] && (chip->ic_latch2[1] & 0x20000) == 0; |
| 176 |
chip->ic_check2 = (chip->ic_latch3[1] & 4) != 0; |
| 177 |
#else |
| 178 |
chip->ic_check1 = chip->ic_latch1[1] && (chip->ic_latch2[1] & 0x800) == 0; |
| 179 |
#endif |
| 180 |
chip->ic_check3 = (chip->ic_latch3[1] & 8) != 0; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
chip->prescaler_latch[1] = chip->prescaler_latch[0]; |
| 185 |
|
| 186 |
#ifndef FMOPNA_YM2612 |
| 187 |
for (i = 0; i < 15; i++) |
| 188 |
chip->pssel_l[i][1] = chip->pssel_l[i][0]; |
| 189 |
#else |
| 190 |
chip->pssel_l[0][1] = chip->pssel_l[0][0]; |
| 191 |
chip->pssel_l[1][1] = chip->pssel_l[1][0]; |
| 192 |
#endif |
| 193 |
} |
| 194 |
|
| 195 |
if (chip->clk1) |
| 196 |
{ |
| 197 |
chip->ic_latch_fm[0] = chip->ic; |
| 198 |
} |
| 199 |
if (chip->clk2) |
| 200 |
{ |
| 201 |
chip->ic_latch_fm[1] = chip->ic_latch_fm[0]; |
| 202 |
} |
| 203 |
|
| 204 |
{ |
| 205 |
#ifndef FMOPNA_YM2612 |
| 206 |
int clk1 = 1; |
| 207 |
int clk2 = 1; |
| 208 |
int aclk1 = 1; |
| 209 |
int aclk2 = 1; |
| 210 |
int bclk1 = 1; |
| 211 |
int bclk2 = 1; |
| 212 |
#ifdef FMOPNA_YM2608 |
| 213 |
switch (chip->prescaler_sel[1]) |
| 214 |
{ |
| 215 |
case 2: |
| 216 |
clk1 = chip->pssel_l[0][1]; |
| 217 |
clk2 = chip->pssel_l[1][1]; |
| 218 |
aclk1 = chip->pssel_l[5][1]; |
| 219 |
aclk2 = chip->pssel_l[6][1]; |
| 220 |
bclk1 = chip->pssel_l[11][1]; |
| 221 |
bclk2 = chip->pssel_l[12][1]; |
| 222 |
break; |
| 223 |
case 0: |
| 224 |
clk1 = (chip->pssel_l[4][1] & 2) != 0 && (chip->pssel_l[4][0] & 4) != 0; |
| 225 |
clk2 = (chip->pssel_l[4][1] & 1) != 0 && (chip->pssel_l[4][0] & 2) != 0; |
| 226 |
aclk1 = chip->pssel_l[9][1]; |
| 227 |
aclk2 = chip->pssel_l[10][1]; |
| 228 |
bclk1 = !chip->mclk2; |
| 229 |
bclk2 = !chip->mclk1; |
| 230 |
break; |
| 231 |
case 3: |
| 232 |
clk1 = chip->pssel_l[2][1]; |
| 233 |
clk2 = chip->pssel_l[3][1]; |
| 234 |
aclk1 = chip->pssel_l[7][1]; |
| 235 |
aclk2 = chip->pssel_l[8][1]; |
| 236 |
bclk1 = ((chip->pssel_l[13][1] & 4) == 0 && (chip->pssel_l[13][0] & 8) != 0) |
| 237 |
|| ((chip->pssel_l[13][1] & 1) == 0 && (chip->pssel_l[13][0] & 2) == 0); |
| 238 |
bclk2 = ((chip->pssel_l[13][1] & 1) == 0 && (chip->pssel_l[13][0] & 2) != 0) |
| 239 |
|| ((chip->pssel_l[13][1] & 2) == 0 && (chip->pssel_l[13][0] & 4) == 0); |
| 240 |
break; |
| 241 |
|
| 242 |
} |
| 243 |
#endif |
| 244 |
#ifdef FMOPNA_YM2610 |
| 245 |
clk1 = chip->pssel_l[0][1]; |
| 246 |
clk2 = chip->pssel_l[1][1]; |
| 247 |
aclk1 = chip->pssel_l[5][1]; |
| 248 |
aclk2 = chip->pssel_l[6][1]; |
| 249 |
bclk1 = chip->pssel_l[11][1]; |
| 250 |
bclk2 = chip->pssel_l[12][1]; |
| 251 |
#endif |
| 252 |
|
| 253 |
|
| 254 |
chip->clk1 = clk1; |
| 255 |
chip->clk2 = clk2; |
| 256 |
|
| 257 |
chip->aclk1 = aclk1; |
| 258 |
chip->aclk2 = aclk2; |
| 259 |
|
| 260 |
chip->bclk1 = bclk1; |
| 261 |
chip->bclk2 = bclk2; |
| 262 |
|
| 263 |
chip->cclk1 = !chip->pssel_l[14][1]; |
| 264 |
chip->cclk2 = chip->pssel_l[14][1]; |
| 265 |
#else |
| 266 |
chip->clk1 = chip->pssel_l[0][1]; |
| 267 |
chip->clk2 = chip->pssel_l[1][1]; |
| 268 |
#endif |
| 269 |
} |
| 270 |
|
| 271 |
// if (clk) |
| 272 |
// return; |
| 273 |
|
| 274 |
{ |
| 275 |
int read = !chip->ic && !chip->input.rd && !chip->input.cs; |
| 276 |
chip->read0 = !chip->ic && !chip->input.rd && !chip->input.cs && !chip->input.a1 && !chip->input.a0; |
| 277 |
int write = !chip->input.wr && !chip->input.cs; |
| 278 |
int writeaddr = chip->ic || (!chip->input.wr && !chip->input.cs && !chip->input.a0); |
| 279 |
int writedata = !chip->ic && !chip->input.wr && !chip->input.cs && chip->input.a0; |
| 280 |
#ifndef FMOPNA_YM2612 |
| 281 |
int read1 = !chip->ic && !chip->input.rd && !chip->input.cs && !chip->input.a1 && chip->input.a0; |
| 282 |
chip->read2 = !chip->ic && !chip->input.rd && !chip->input.cs && chip->input.a1 && !chip->input.a0; |
| 283 |
#ifdef FMOPNA_YM2608 |
| 284 |
chip->read3 = !chip->ic && !chip->input.rd && !chip->input.cs && chip->input.a1 && chip->input.a0; |
| 285 |
chip->write2 = !chip->ic && !chip->input.wr && !chip->input.cs && chip->input.a1 && !chip->input.a0; |
| 286 |
chip->write3 = !chip->ic && !chip->input.wr && !chip->input.cs && chip->input.a1 && chip->input.a0; |
| 287 |
#endif |
| 288 |
#ifdef FMOPNA_YM2610 |
| 289 |
chip->write2 = !chip->ic && !chip->input.wr && !chip->input.cs && !chip->input.a1 && !chip->input.a0; |
| 290 |
chip->write3 = !chip->ic && !chip->input.wr && !chip->input.cs && !chip->input.a1 && chip->input.a0; |
| 291 |
#endif |
| 292 |
chip->ssg_write0 = writeaddr && !chip->input.a1; |
| 293 |
chip->ssg_write1 = (writedata && !chip->input.a1) || chip->ic; |
| 294 |
chip->ssg_read1 = read1; |
| 295 |
#endif |
| 296 |
|
| 297 |
|
| 298 |
chip->o_data_d = !read; |
| 299 |
|
| 300 |
if (writeaddr) |
| 301 |
chip->write0_trig0 = 1; |
| 302 |
else if (chip->write0_l[0]) |
| 303 |
chip->write0_trig0 = 0; |
| 304 |
if (chip->clk1) |
| 305 |
{ |
| 306 |
chip->write0_trig1 = chip->write0_trig0; |
| 307 |
chip->write0_l[1] = chip->write0_l[0]; |
| 308 |
} |
| 309 |
if (chip->clk2) |
| 310 |
{ |
| 311 |
chip->write0_l[0] = chip->write0_trig1; |
| 312 |
chip->write0_l[2] = chip->write0_l[1]; |
| 313 |
} |
| 314 |
chip->write0_en = chip->write0_l[0] && !chip->write0_l[2]; |
| 315 |
|
| 316 |
if (writedata) |
| 317 |
chip->write1_trig0 = 1; |
| 318 |
else if (chip->write1_l[0]) |
| 319 |
chip->write1_trig0 = 0; |
| 320 |
if (chip->clk1) |
| 321 |
{ |
| 322 |
chip->write1_trig1 = chip->write1_trig0; |
| 323 |
chip->write1_l[1] = chip->write1_l[0]; |
| 324 |
} |
| 325 |
if (chip->clk2) |
| 326 |
{ |
| 327 |
chip->write1_l[0] = chip->write1_trig1; |
| 328 |
chip->write1_l[2] = chip->write1_l[1]; |
| 329 |
} |
| 330 |
chip->write1_en = chip->write1_l[0] && !chip->write1_l[2]; |
| 331 |
|
| 332 |
#ifdef FMOPNA_YM2608 |
| 333 |
if (writeaddr) |
| 334 |
chip->write2_trig0 = 1; |
| 335 |
else if (chip->write2_l[0]) |
| 336 |
chip->write2_trig0 = 0; |
| 337 |
if (chip->mclk1) |
| 338 |
{ |
| 339 |
chip->write2_trig1 = chip->write2_trig0; |
| 340 |
chip->write2_l[1] = chip->write2_l[0]; |
| 341 |
} |
| 342 |
if (chip->mclk2) |
| 343 |
{ |
| 344 |
chip->write2_l[0] = chip->write2_trig1; |
| 345 |
chip->write2_l[2] = chip->write2_l[1]; |
| 346 |
} |
| 347 |
chip->write2_en = chip->write2_l[0] && !chip->write2_l[2]; |
| 348 |
#endif |
| 349 |
|
| 350 |
#ifndef FMOPNA_YM2612 |
| 351 |
if (writedata) |
| 352 |
chip->write3_trig0 = 1; |
| 353 |
else if (chip->write3_l[0]) |
| 354 |
chip->write3_trig0 = 0; |
| 355 |
#endif |
| 356 |
|
| 357 |
if (write) |
| 358 |
chip->data_l = (chip->input.data & 255) | (chip->input.a1 << 8); |
| 359 |
|
| 360 |
#ifndef FMOPNA_YM2612 |
| 361 |
if (chip->ic) |
| 362 |
chip->data_bus2 |= 0x2f; |
| 363 |
else |
| 364 |
#endif |
| 365 |
if (!read && !chip->ic) |
| 366 |
chip->data_bus2 = chip->data_l ^ 0x1ff; |
| 367 |
|
| 368 |
if (chip->ic_latch_fm[1]) |
| 369 |
{ |
| 370 |
chip->data_bus1 &= ~255; |
| 371 |
} |
| 372 |
else if (!read && !chip->ic) |
| 373 |
{ |
| 374 |
chip->data_bus1 = chip->data_l; |
| 375 |
} |
| 376 |
#ifdef FMOPNA_YM2608 |
| 377 |
else if (read1 && chip->addr_ff[1]) |
| 378 |
{ |
| 379 |
chip->data_bus1 &= ~255; |
| 380 |
chip->data_bus1 |= 1; |
| 381 |
} |
| 382 |
#endif |
| 383 |
|
| 384 |
#define ADDRESS_MATCH(x) ((chip->data_bus2 & x) == 0 && (chip->data_bus1 & (x^511)) == 0) |
| 385 |
|
| 386 |
#ifdef FMOPNA_YM2608 |
| 387 |
if (chip->mclk1) |
| 388 |
{ |
| 389 |
int addr2d = chip->write2_en && ADDRESS_MATCH(0x2d); |
| 390 |
int addr2e = chip->write2_en && ADDRESS_MATCH(0x2e); |
| 391 |
int addr2f = chip->write2_en && ADDRESS_MATCH(0x2f); |
| 392 |
chip->prescaler_sel[0] = chip->prescaler_sel[1]; |
| 393 |
if (addr2f) |
| 394 |
chip->prescaler_sel[0] = 0; |
| 395 |
if (chip->ic) |
| 396 |
chip->prescaler_sel[0] = 2; |
| 397 |
if (addr2d) |
| 398 |
chip->prescaler_sel[0] |= 2; |
| 399 |
if (addr2e) |
| 400 |
chip->prescaler_sel[0] |= 1; |
| 401 |
} |
| 402 |
if (chip->mclk2) |
| 403 |
{ |
| 404 |
chip->prescaler_sel[1] = chip->prescaler_sel[0]; |
| 405 |
} |
| 406 |
#endif |
| 407 |
|
| 408 |
if (chip->clk1) |
| 409 |
{ |
| 410 |
int is_fm = (chip->data_bus1 & 0xf0) != 0; |
| 411 |
|
| 412 |
chip->write_fm_address[0] = chip->write0_en ? is_fm : chip->write_fm_address[1]; |
| 413 |
|
| 414 |
if (chip->ic) |
| 415 |
chip->fm_address[0] = 0; |
| 416 |
else if (is_fm && chip->write0_en) |
| 417 |
chip->fm_address[0] = chip->data_bus1; |
| 418 |
else |
| 419 |
chip->fm_address[0] = chip->fm_address[1]; |
| 420 |
|
| 421 |
if (chip->ic) |
| 422 |
chip->fm_data[0] = 0; |
| 423 |
else if (chip->write_fm_address[1] && chip->write1_en) |
| 424 |
chip->fm_data[0] = chip->data_bus1 & 255; |
| 425 |
else |
| 426 |
chip->fm_data[0] = chip->fm_data[1]; |
| 427 |
|
| 428 |
chip->write_fm_data[0] = (chip->write_fm_address[1] && chip->write1_en) || (chip->write_fm_data[1] && !chip->write0_en); |
| 429 |
|
| 430 |
#ifdef FMOPNA_YM2608 |
| 431 |
chip->addr_10[0] = chip->write0_en ? ADDRESS_MATCH(0x10) : chip->addr_10[1]; |
| 432 |
chip->addr_10h[0] = chip->write0_en ? ADDRESS_MATCH(0x110) : chip->addr_10h[1]; |
| 433 |
chip->addr_12[0] = chip->write0_en ? ADDRESS_MATCH(0x12) : chip->addr_12[1]; |
| 434 |
chip->addr_29[0] = chip->write0_en ? ADDRESS_MATCH(0x29) : chip->addr_29[1]; |
| 435 |
chip->addr_ff[0] = chip->write0_en ? ADDRESS_MATCH(0xff) : chip->addr_ff[1]; |
| 436 |
int write10 = chip->addr_10h[1] && (chip->data_bus1 & 0x100) != 0 && chip->write1_en; |
| 437 |
int irq_rst = write10 && (chip->data_bus2 & 0x80) == 0; |
| 438 |
|
| 439 |
#endif |
| 440 |
#ifdef FMOPNA_YM2610 |
| 441 |
chip->addr_00[0] = chip->write0_en ? ADDRESS_MATCH(0x100) : chip->addr_00[1]; |
| 442 |
chip->addr_02[0] = chip->write0_en ? ADDRESS_MATCH(0x102) : chip->addr_02[1]; |
| 443 |
chip->addr_1c[0] = chip->write0_en ? ADDRESS_MATCH(0x11c) : chip->addr_1c[1]; |
| 444 |
#endif |
| 445 |
#ifdef FMOPNA_YM2612 |
| 446 |
chip->addr_2a[0] = chip->write0_en ? ADDRESS_MATCH(0x2a) : chip->addr_2a[1]; |
| 447 |
chip->addr_2b[0] = chip->write0_en ? ADDRESS_MATCH(0x2b) : chip->addr_2b[1]; |
| 448 |
chip->addr_2c[0] = chip->write0_en ? ADDRESS_MATCH(0x2c) : chip->addr_2c[1]; |
| 449 |
#endif |
| 450 |
chip->addr_21[0] = chip->write0_en ? ADDRESS_MATCH(0x21) : chip->addr_21[1]; |
| 451 |
chip->addr_22[0] = chip->write0_en ? ADDRESS_MATCH(0x22) : chip->addr_22[1]; |
| 452 |
chip->addr_24[0] = chip->write0_en ? ADDRESS_MATCH(0x24) : chip->addr_24[1]; |
| 453 |
chip->addr_25[0] = chip->write0_en ? ADDRESS_MATCH(0x25) : chip->addr_25[1]; |
| 454 |
chip->addr_26[0] = chip->write0_en ? ADDRESS_MATCH(0x26) : chip->addr_26[1]; |
| 455 |
chip->addr_27[0] = chip->write0_en ? ADDRESS_MATCH(0x27) : chip->addr_27[1]; |
| 456 |
chip->addr_28[0] = chip->write0_en ? ADDRESS_MATCH(0x28) : chip->addr_28[1]; |
| 457 |
|
| 458 |
if (chip->ic) |
| 459 |
{ |
| 460 |
chip->reg_test_21[0] = 0; |
| 461 |
chip->reg_lfo[0] = 0; |
| 462 |
chip->reg_timer_a[0] = 0; |
| 463 |
chip->reg_timer_b[0] = 0; |
| 464 |
chip->reg_ch3[0] = 0; |
| 465 |
chip->reg_timer_a_load[0] = 0; |
| 466 |
chip->reg_timer_b_load[0] = 0; |
| 467 |
chip->reg_timer_a_enable[0] = 0; |
| 468 |
chip->reg_timer_b_enable[0] = 0; |
| 469 |
chip->reg_timer_a_reset[0] = 0; |
| 470 |
chip->reg_timer_b_reset[0] = 0; |
| 471 |
chip->reg_kon_operator[0] = 0; |
| 472 |
chip->reg_kon_channel[0] = 0; |
| 473 |
#ifdef FMOPNA_YM2608 |
| 474 |
chip->reg_test_12[0] = 0; |
| 475 |
chip->reg_sch[0] = 0; |
| 476 |
chip->reg_irq[0] = 31; |
| 477 |
chip->reg_mask[0] = 28; |
| 478 |
#endif |
| 479 |
#ifdef FMOPNA_YM2610 |
| 480 |
chip->reg_test_12[0] = 0; |
| 481 |
#endif |
| 482 |
#ifdef FMOPNA_YM2612 |
| 483 |
chip->reg_dac_en[0] = 0; |
| 484 |
chip->reg_dac_data[0] = 0x80; |
| 485 |
chip->reg_test_2c[0] = 0; |
| 486 |
#endif |
| 487 |
} |
| 488 |
else |
| 489 |
{ |
| 490 |
#ifdef FMOPNA_YM2608 |
| 491 |
int write10r = write10 && (chip->data_bus2 & 0x80) != 0; |
| 492 |
if (write10r) |
| 493 |
{ |
| 494 |
chip->reg_mask[0] = chip->data_bus1 & 3; |
| 495 |
chip->reg_mask[0] |= (chip->data_bus2 ^ 28) & 28; |
| 496 |
} |
| 497 |
else |
| 498 |
{ |
| 499 |
chip->reg_mask[0] = chip->reg_mask[1]; |
| 500 |
} |
| 501 |
if (chip->addr_12[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 502 |
{ |
| 503 |
chip->reg_test_12[0] = chip->data_bus1 & 252; |
| 504 |
} |
| 505 |
else |
| 506 |
{ |
| 507 |
chip->reg_test_12[0] = chip->reg_test_12[1]; |
| 508 |
} |
| 509 |
#endif |
| 510 |
#ifdef FMOPNA_YM2610 |
| 511 |
if (chip->addr_1c[1] && (chip->data_bus1 & 0x100) != 0 && chip->write1_en) |
| 512 |
{ |
| 513 |
chip->reg_flags[0] = chip->data_bus1 & 0xbf; |
| 514 |
} |
| 515 |
else |
| 516 |
{ |
| 517 |
chip->reg_flags[0] = chip->reg_flags[1]; |
| 518 |
} |
| 519 |
if (chip->addr_02[1] && (chip->data_bus1 & 0x100) != 0 && chip->write1_en) |
| 520 |
{ |
| 521 |
chip->reg_test_12[0] = chip->data_bus1 & 0xb8; |
| 522 |
} |
| 523 |
else |
| 524 |
{ |
| 525 |
chip->reg_test_12[0] = chip->reg_test_12[1]; |
| 526 |
} |
| 527 |
#endif |
| 528 |
if (chip->addr_21[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 529 |
{ |
| 530 |
chip->reg_test_21[0] = chip->data_bus1 & 255; |
| 531 |
} |
| 532 |
else |
| 533 |
{ |
| 534 |
chip->reg_test_21[0] = chip->reg_test_21[1]; |
| 535 |
} |
| 536 |
if (chip->addr_22[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 537 |
{ |
| 538 |
chip->reg_lfo[0] = chip->data_bus1 & 15; |
| 539 |
} |
| 540 |
else |
| 541 |
{ |
| 542 |
chip->reg_lfo[0] = chip->reg_lfo[1]; |
| 543 |
} |
| 544 |
chip->reg_timer_a[0] = 0; |
| 545 |
if (chip->addr_24[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 546 |
{ |
| 547 |
chip->reg_timer_a[0] |= (chip->data_bus1 & 255) << 2; |
| 548 |
} |
| 549 |
else |
| 550 |
{ |
| 551 |
chip->reg_timer_a[0] |= chip->reg_timer_a[1] & 0x3fc; |
| 552 |
} |
| 553 |
if (chip->addr_25[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 554 |
{ |
| 555 |
chip->reg_timer_a[0] |= chip->data_bus1 & 3; |
| 556 |
} |
| 557 |
else |
| 558 |
{ |
| 559 |
chip->reg_timer_a[0] |= chip->reg_timer_a[1] & 3; |
| 560 |
} |
| 561 |
if (chip->addr_26[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 562 |
{ |
| 563 |
chip->reg_timer_b[0] = chip->data_bus1 & 255; |
| 564 |
} |
| 565 |
else |
| 566 |
{ |
| 567 |
chip->reg_timer_b[0] = chip->reg_timer_b[1]; |
| 568 |
} |
| 569 |
if (chip->addr_27[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 570 |
{ |
| 571 |
chip->reg_ch3[0] = (chip->data_bus1 >> 6) & 3; |
| 572 |
chip->reg_timer_a_load[0] = (chip->data_bus1 >> 0) & 1; |
| 573 |
chip->reg_timer_b_load[0] = (chip->data_bus1 >> 1) & 1; |
| 574 |
chip->reg_timer_a_enable[0] = (chip->data_bus1 >> 2) & 1; |
| 575 |
chip->reg_timer_b_enable[0] = (chip->data_bus1 >> 3) & 1; |
| 576 |
chip->reg_timer_a_reset[0] = (chip->data_bus1 >> 4) & 1; |
| 577 |
chip->reg_timer_b_reset[0] = (chip->data_bus1 >> 5) & 1; |
| 578 |
} |
| 579 |
else |
| 580 |
{ |
| 581 |
chip->reg_ch3[0] = chip->reg_ch3[1]; |
| 582 |
chip->reg_timer_a_load[0] = chip->reg_timer_a_load[1]; |
| 583 |
chip->reg_timer_b_load[0] = chip->reg_timer_b_load[1]; |
| 584 |
chip->reg_timer_a_enable[0] = chip->reg_timer_a_enable[1]; |
| 585 |
chip->reg_timer_b_enable[0] = chip->reg_timer_b_enable[1]; |
| 586 |
chip->reg_timer_a_reset[0] = 0; |
| 587 |
chip->reg_timer_b_reset[0] = 0; |
| 588 |
} |
| 589 |
if (chip->addr_28[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 590 |
{ |
| 591 |
chip->reg_kon_operator[0] = (chip->data_bus1 >> 4) & 15; |
| 592 |
chip->reg_kon_channel[0] = (chip->data_bus1 >> 0) & 7; |
| 593 |
} |
| 594 |
else |
| 595 |
{ |
| 596 |
chip->reg_kon_operator[0] = chip->reg_kon_operator[1]; |
| 597 |
chip->reg_kon_channel[0] = chip->reg_kon_channel[1]; |
| 598 |
} |
| 599 |
#ifdef FMOPNA_YM2608 |
| 600 |
if (chip->addr_29[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 601 |
{ |
| 602 |
chip->reg_sch[0] = (chip->data_bus1 >> 7) & 1; |
| 603 |
chip->reg_irq[0] = (chip->data_bus2 & 31) ^ 31; |
| 604 |
} |
| 605 |
else |
| 606 |
{ |
| 607 |
chip->reg_sch[0] = chip->reg_sch[1]; |
| 608 |
chip->reg_irq[0] = chip->reg_irq[1]; |
| 609 |
} |
| 610 |
#endif |
| 611 |
#ifdef FMOPNA_YM2612 |
| 612 |
if (chip->addr_2a[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 613 |
{ |
| 614 |
chip->reg_dac_data[0] = chip->data_bus1 & 255; |
| 615 |
} |
| 616 |
else |
| 617 |
{ |
| 618 |
chip->reg_dac_data[0] = chip->reg_dac_data[1]; |
| 619 |
} |
| 620 |
if (chip->addr_2b[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 621 |
{ |
| 622 |
chip->reg_dac_en[0] = (chip->data_bus1 & 128) != 0; |
| 623 |
} |
| 624 |
else |
| 625 |
{ |
| 626 |
chip->reg_dac_en[0] = chip->reg_dac_en[1]; |
| 627 |
} |
| 628 |
if (chip->addr_2c[1] && (chip->data_bus1 & 0x100) == 0 && chip->write1_en) |
| 629 |
{ |
| 630 |
chip->reg_test_2c[0] = chip->data_bus1 & 0xf8; |
| 631 |
} |
| 632 |
else |
| 633 |
{ |
| 634 |
chip->reg_test_2c[0] = chip->reg_test_2c[1]; |
| 635 |
} |
| 636 |
#endif |
| 637 |
} |
| 638 |
|
| 639 |
int rst1 = chip->reg_cnt_sync || chip->ic; |
| 640 |
int of = (chip->reg_cnt1[1] & 2) != 0; |
| 641 |
|
| 642 |
chip->reg_cnt1[0] = (rst1 || of) ? 0 : ((chip->reg_cnt1[1] + 1) & 3); |
| 643 |
chip->reg_cnt2[0] = rst1 ? 0 : ((chip->reg_cnt2[1] + of) & 3); |
| 644 |
|
| 645 |
#ifdef FMOPNA_YM2608 |
| 646 |
int rst2 = chip->reg_cnt_sync || chip->reg_cnt_rss_of; |
| 647 |
chip->reg_cnt_rss[0] = rst2 ? 0 : ((chip->reg_cnt_rss[1] + 1) & 15); |
| 648 |
#endif |
| 649 |
|
| 650 |
int of2 = (chip->reg_key_cnt1[1] & 2) != 0; |
| 651 |
chip->reg_key_cnt1[0] = (rst1 || of2) ? 0 : ((chip->reg_key_cnt1[1] + 1) & 3); |
| 652 |
chip->reg_key_cnt2[0] = rst1 ? 0 : ((chip->reg_key_cnt2[1] + of2) & 7); |
| 653 |
|
| 654 |
chip->reg_kon[0][0] = chip->reg_kon[0][1] << 1; |
| 655 |
chip->reg_kon[1][0] = chip->reg_kon[1][1] << 1; |
| 656 |
chip->reg_kon[2][0] = chip->reg_kon[2][1] << 1; |
| 657 |
chip->reg_kon[3][0] = chip->reg_kon[3][1] << 1; |
| 658 |
|
| 659 |
if (chip->reg_kon_match) |
| 660 |
{ |
| 661 |
chip->reg_kon[0][0] |= (chip->reg_kon_operator[1] >> 0) & 1; |
| 662 |
chip->reg_kon[1][0] |= (chip->reg_kon_operator[1] >> 3) & 1; |
| 663 |
chip->reg_kon[2][0] |= (chip->reg_kon_operator[1] >> 1) & 1; |
| 664 |
chip->reg_kon[3][0] |= (chip->reg_kon_operator[1] >> 2) & 1; |
| 665 |
} |
| 666 |
else |
| 667 |
{ |
| 668 |
if (!chip->ic) |
| 669 |
chip->reg_kon[0][0] |= (chip->reg_kon[3][1] >> 5) & 1; |
| 670 |
chip->reg_kon[1][0] |= (chip->reg_kon[0][1] >> 5) & 1; |
| 671 |
chip->reg_kon[2][0] |= (chip->reg_kon[1][1] >> 5) & 1; |
| 672 |
chip->reg_kon[3][0] |= (chip->reg_kon[2][1] >> 5) & 1; |
| 673 |
} |
| 674 |
|
| 675 |
chip->reg_sync_timer_l[0] = chip->reg_sync_timer; |
| 676 |
|
| 677 |
int time = chip->timer_a_cnt[1]; |
| 678 |
time += (chip->reg_test_21[1] & 4) != 0 || (chip->timer_a_reg_load && chip->reg_sync_timer); |
| 679 |
|
| 680 |
chip->timer_a_cnt[0] = chip->timer_a_load ? chip->reg_timer_a[1] : (!chip->timer_a_reg_load ? 0 : (time & 1023)); |
| 681 |
chip->timer_a_of[0] = (time & 1024) != 0; |
| 682 |
|
| 683 |
chip->timer_a_reg_load_l[0] = chip->timer_a_reg_load; |
| 684 |
|
| 685 |
int rst_a = chip->reg_timer_a_reset[1] || chip->ic; |
| 686 |
int rst_a2 = rst_a |
| 687 |
#ifdef FMOPNA_YM2608 |
| 688 |
|| irq_rst || (chip->reg_mask[1] & 1) != 0 |
| 689 |
#endif |
| 690 |
; |
| 691 |
|
| 692 |
if (rst_a2) |
| 693 |
chip->timer_a_status[0] = 0; |
| 694 |
else |
| 695 |
chip->timer_a_status[0] = chip->timer_a_status[1]; |
| 696 |
|
| 697 |
chip->timer_a_status[0] |= !rst_a |
| 698 |
#ifdef FMOPNA_YM2608 |
| 699 |
&& (chip->reg_mask[1] & 1) == 0 |
| 700 |
#endif |
| 701 |
&& chip->reg_timer_a_enable[1] && chip->timer_a_of[1]; |
| 702 |
|
| 703 |
int subcnt = chip->timer_b_subcnt[1] + chip->reg_sync_timer; |
| 704 |
chip->timer_b_subcnt[0] = chip->ic ? 0 : subcnt & 15; |
| 705 |
chip->timer_b_subcnt_of[0] = (subcnt & 16) != 0; |
| 706 |
|
| 707 |
time = chip->timer_b_cnt[1]; |
| 708 |
time += (chip->reg_test_21[1] & 4) != 0 || (chip->timer_b_reg_load && chip->timer_b_subcnt_of[1]); |
| 709 |
|
| 710 |
chip->timer_b_cnt[0] = chip->timer_b_load ? chip->reg_timer_b[1] : (!chip->timer_b_reg_load ? 0 : (time & 255)); |
| 711 |
chip->timer_b_of[0] = (time & 256) != 0; |
| 712 |
|
| 713 |
chip->timer_b_reg_load_l[0] = chip->timer_b_reg_load; |
| 714 |
|
| 715 |
int rst_b = chip->reg_timer_b_reset[1] || chip->ic; |
| 716 |
int rst_b2 = rst_b |
| 717 |
#ifdef FMOPNA_YM2608 |
| 718 |
|| irq_rst || (chip->reg_mask[1] & 2) != 0 |
| 719 |
#endif |
| 720 |
; |
| 721 |
|
| 722 |
if (rst_b2) |
| 723 |
chip->timer_b_status[0] = 0; |
| 724 |
else |
| 725 |
chip->timer_b_status[0] = chip->timer_b_status[1]; |
| 726 |
|
| 727 |
chip->timer_b_status[0] |= !rst_b |
| 728 |
#ifdef FMOPNA_YM2608 |
| 729 |
&& (chip->reg_mask[1] & 2) == 0 |
| 730 |
#endif |
| 731 |
&& chip->reg_timer_b_enable[1] && chip->timer_b_of[1]; |
| 732 |
|
| 733 |
memcpy(&chip->reg_freq[0][1], &chip->reg_freq[1][0], 5 * sizeof(unsigned short)); |
| 734 |
memcpy(&chip->reg_freq_3ch[0][1], &chip->reg_freq_3ch[1][0], 5 * sizeof(unsigned short)); |
| 735 |
memcpy(&chip->reg_connect_fb[0][1], &chip->reg_connect_fb[1][0], 5 * sizeof(unsigned char)); |
| 736 |
memcpy(&chip->reg_b4[0][1], &chip->reg_b4[1][0], 5 * sizeof(unsigned char)); |
| 737 |
#ifdef FMOPNA_YM2608 |
| 738 |
memcpy(&chip->reg_rss[0][1], &chip->reg_rss[1][0], 5 * sizeof(unsigned char)); |
| 739 |
#endif |
| 740 |
memcpy(&chip->op_multi_dt[0][1][0], &chip->op_multi_dt[1][0][0], 11 * 2 * sizeof(unsigned char)); |
| 741 |
memcpy(&chip->op_tl[0][1][0], &chip->op_tl[1][0][0], 11 * 2 * sizeof(unsigned char)); |
| 742 |
memcpy(&chip->op_ar_ks[0][1][0], &chip->op_ar_ks[1][0][0], 11 * 2 * sizeof(unsigned char)); |
| 743 |
memcpy(&chip->op_dr_a[0][1][0], &chip->op_dr_a[1][0][0], 11 * 2 * sizeof(unsigned char)); |
| 744 |
memcpy(&chip->op_sr[0][1][0], &chip->op_sr[1][0][0], 11 * 2 * sizeof(unsigned char)); |
| 745 |
memcpy(&chip->op_rr_sl[0][1][0], &chip->op_rr_sl[1][0][0], 11 * 2 * sizeof(unsigned char)); |
| 746 |
memcpy(&chip->op_ssg[0][1][0], &chip->op_ssg[1][0][0], 11 * 2 * sizeof(unsigned char)); |
| 747 |
|
| 748 |
if (chip->ic) |
| 749 |
{ |
| 750 |
chip->reg_a4[0] = 0; |
| 751 |
chip->reg_freq[0][0] = 0; |
| 752 |
chip->reg_ac[0] = 0; |
| 753 |
chip->reg_freq_3ch[0][0] = 0; |
| 754 |
chip->reg_connect_fb[0][0] = 0; |
| 755 |
chip->reg_b4[0][0] = 0xc0; |
| 756 |
#ifdef FMOPNA_YM2608 |
| 757 |
chip->reg_rss[0][0] = 0; |
| 758 |
#endif |
| 759 |
|
| 760 |
chip->op_multi_dt[0][0][0] = 0; |
| 761 |
chip->op_multi_dt[0][0][1] = 0; |
| 762 |
chip->op_tl[0][0][0] = 0; |
| 763 |
chip->op_tl[0][0][1] = 0; |
| 764 |
chip->op_ar_ks[0][0][0] = 0; |
| 765 |
chip->op_ar_ks[0][0][1] = 0; |
| 766 |
chip->op_dr_a[0][0][0] = 0; |
| 767 |
chip->op_dr_a[0][0][1] = 0; |
| 768 |
chip->op_sr[0][0][0] = 0; |
| 769 |
chip->op_sr[0][0][1] = 0; |
| 770 |
chip->op_rr_sl[0][0][0] = 0; |
| 771 |
chip->op_rr_sl[0][0][1] = 0; |
| 772 |
chip->op_ssg[0][0][0] = 0; |
| 773 |
chip->op_ssg[0][0][1] = 0; |
| 774 |
} |
| 775 |
else |
| 776 |
{ |
| 777 |
chip->reg_a4[0] = chip->fm_isa4 ? (chip->fm_data[1] & 0x3f) : chip->reg_a4[1]; |
| 778 |
chip->reg_freq[0][0] = chip->fm_isa0 ? (chip->fm_data[1] & 0xff) | (chip->reg_a4[1] << 8) : chip->reg_freq[1][5]; |
| 779 |
chip->reg_ac[0] = chip->fm_isac ? (chip->fm_data[1] & 0x3f) : chip->reg_ac[1]; |
| 780 |
chip->reg_freq_3ch[0][0] = chip->fm_isa8 ? (chip->fm_data[1] & 0xff) | (chip->reg_ac[1] << 8) : chip->reg_freq_3ch[1][5]; |
| 781 |
chip->reg_connect_fb[0][0] = chip->fm_isb0 ? (chip->fm_data[1] & 0x3f) : chip->reg_connect_fb[1][5]; |
| 782 |
chip->reg_b4[0][0] = chip->fm_isb4 ? (chip->fm_data[1] & 0xf7) : chip->reg_b4[1][5]; |
| 783 |
#ifdef FMOPNA_YM2608 |
| 784 |
chip->reg_rss[0][0] = chip->rss_18 ? (chip->fm_data[1] & 0xdf) : chip->reg_rss[1][5]; |
| 785 |
#endif |
| 786 |
|
| 787 |
int bank = (chip->fm_address[1] & 8) != 0; |
| 788 |
chip->op_multi_dt[0][0][0] = (chip->fm_is30 && !bank) ? (chip->fm_data[1] & 0x7f) : chip->op_multi_dt[1][11][0]; |
| 789 |
chip->op_multi_dt[0][0][1] = (chip->fm_is30 && bank) ? (chip->fm_data[1] & 0x7f) : chip->op_multi_dt[1][11][1]; |
| 790 |
chip->op_tl[0][0][0] = (chip->fm_is40 && !bank) ? (chip->fm_data[1] & 0x7f) : chip->op_tl[1][11][0]; |
| 791 |
chip->op_tl[0][0][1] = (chip->fm_is40 && bank) ? (chip->fm_data[1] & 0x7f) : chip->op_tl[1][11][1]; |
| 792 |
chip->op_ar_ks[0][0][0] = (chip->fm_is50 && !bank) ? (chip->fm_data[1] & 0xdf) : chip->op_ar_ks[1][11][0]; |
| 793 |
chip->op_ar_ks[0][0][1] = (chip->fm_is50 && bank) ? (chip->fm_data[1] & 0xdf) : chip->op_ar_ks[1][11][1]; |
| 794 |
chip->op_dr_a[0][0][0] = (chip->fm_is60 && !bank) ? (chip->fm_data[1] & 0x9f) : chip->op_dr_a[1][11][0]; |
| 795 |
chip->op_dr_a[0][0][1] = (chip->fm_is60 && bank) ? (chip->fm_data[1] & 0x9f) : chip->op_dr_a[1][11][1]; |
| 796 |
chip->op_sr[0][0][0] = (chip->fm_is70 && !bank) ? (chip->fm_data[1] & 0x1f) : chip->op_sr[1][11][0]; |
| 797 |
chip->op_sr[0][0][1] = (chip->fm_is70 && bank) ? (chip->fm_data[1] & 0x1f) : chip->op_sr[1][11][1]; |
| 798 |
chip->op_rr_sl[0][0][0] = (chip->fm_is80 && !bank) ? (chip->fm_data[1] & 0xff) : chip->op_rr_sl[1][11][0]; |
| 799 |
chip->op_rr_sl[0][0][1] = (chip->fm_is80 && bank) ? (chip->fm_data[1] & 0xff) : chip->op_rr_sl[1][11][1]; |
| 800 |
chip->op_ssg[0][0][0] = (chip->fm_is90 && !bank) ? (chip->fm_data[1] & 0xf) : chip->op_ssg[1][11][0]; |
| 801 |
chip->op_ssg[0][0][1] = (chip->fm_is90 && bank) ? (chip->fm_data[1] & 0xf) : chip->op_ssg[1][11][1]; |
| 802 |
} |
| 803 |
|
| 804 |
int rst_cc = chip->ic || chip->ch_cnt_sync; |
| 805 |
int cc_of = (chip->ch_cnt1[1] & 2) != 0; |
| 806 |
|
| 807 |
chip->ch_cnt1[0] = (rst_cc || cc_of) ? 0 : (chip->ch_cnt1[1] + 1) & 3; |
| 808 |
chip->ch_cnt2[0] = rst_cc ? 0 : (chip->ch_cnt2[1] + cc_of) & 7; |
| 809 |
|
| 810 |
int cc_cnt = (chip->ch_cnt2[1] << 2) | chip->ch_cnt1[1]; |
| 811 |
|
| 812 |
|
| 813 |
int freq; |
| 814 |
if (chip->ch3_en && cc_cnt == 1) |
| 815 |
freq = chip->reg_freq_3ch[1][5]; |
| 816 |
else if (chip->ch3_en && cc_cnt == 9) |
| 817 |
freq = chip->reg_freq_3ch[1][0]; |
| 818 |
else if (chip->ch3_en && cc_cnt == 17) |
| 819 |
freq = chip->reg_freq_3ch[1][4]; |
| 820 |
else |
| 821 |
freq = chip->reg_freq[1][4]; |
| 822 |
|
| 823 |
chip->fnum[0] = freq & 0x7ff; |
| 824 |
chip->kcode[0] = ((freq >> 11) & 7) << 2; |
| 825 |
if (freq & 0x400) |
| 826 |
{ |
| 827 |
chip->kcode[0] |= 2; |
| 828 |
if ((freq & 0x380) != 0) |
| 829 |
chip->kcode[0] |= 1; |
| 830 |
} |
| 831 |
else |
| 832 |
{ |
| 833 |
if ((freq & 0x380) == 0x380) |
| 834 |
chip->kcode[0] |= 1; |
| 835 |
} |
| 836 |
|
| 837 |
chip->fnum[2] = chip->fnum[1]; |
| 838 |
chip->kcode[2] = chip->kcode[1]; |
| 839 |
} |
| 840 |
if (chip->clk2) |
| 841 |
{ |
| 842 |
chip->fm_address[1] = chip->fm_address[0]; |
| 843 |
chip->write_fm_address[1] = chip->write_fm_address[0]; |
| 844 |
chip->fm_data[1] = chip->fm_data[0]; |
| 845 |
chip->write_fm_data[1] = chip->write_fm_data[0]; |
| 846 |
|
| 847 |
chip->addr_21[1] = chip->addr_21[0]; |
| 848 |
chip->addr_22[1] = chip->addr_22[0]; |
| 849 |
chip->addr_24[1] = chip->addr_24[0]; |
| 850 |
chip->addr_25[1] = chip->addr_25[0]; |
| 851 |
chip->addr_26[1] = chip->addr_26[0]; |
| 852 |
chip->addr_27[1] = chip->addr_27[0]; |
| 853 |
chip->addr_28[1] = chip->addr_28[0]; |
| 854 |
#ifdef FMOPNA_YM2608 |
| 855 |
chip->addr_10[1] = chip->addr_10[0]; |
| 856 |
chip->addr_10h[1] = chip->addr_10h[0]; |
| 857 |
chip->addr_12[1] = chip->addr_12[0]; |
| 858 |
chip->addr_29[1] = chip->addr_29[0]; |
| 859 |
chip->addr_ff[1] = chip->addr_ff[0]; |
| 860 |
#endif |
| 861 |
#ifdef FMOPNA_YM2610 |
| 862 |
chip->addr_00[1] = chip->addr_00[0]; |
| 863 |
chip->addr_02[1] = chip->addr_02[0]; |
| 864 |
chip->addr_1c[1] = chip->addr_1c[0]; |
| 865 |
#endif |
| 866 |
#ifdef FMOPNA_YM2612 |
| 867 |
chip->addr_2a[1] = chip->addr_2a[0]; |
| 868 |
chip->addr_2b[1] = chip->addr_2b[0]; |
| 869 |
chip->addr_2c[1] = chip->addr_2c[0]; |
| 870 |
#endif |
| 871 |
|
| 872 |
#ifdef FMOPNA_YM2608 |
| 873 |
chip->reg_mask[1] = chip->reg_mask[0]; |
| 874 |
chip->reg_sch[1] = chip->reg_sch[0]; |
| 875 |
chip->reg_irq[1] = chip->reg_irq[0]; |
| 876 |
chip->reg_test_12[1] = chip->reg_test_12[0]; |
| 877 |
#endif |
| 878 |
#ifdef FMOPNA_YM2610 |
| 879 |
chip->reg_flags[1] = chip->reg_flags[0]; |
| 880 |
chip->reg_test_12[1] = chip->reg_test_12[0]; |
| 881 |
#endif |
| 882 |
#ifdef FMOPNA_YM2612 |
| 883 |
chip->reg_dac_en[1] = chip->reg_dac_en[0]; |
| 884 |
chip->reg_dac_data[1] = chip->reg_dac_data[0]; |
| 885 |
chip->reg_test_2c[1] = chip->reg_test_2c[0]; |
| 886 |
#endif |
| 887 |
chip->reg_test_21[1] = chip->reg_test_21[0]; |
| 888 |
chip->reg_lfo[1] = chip->reg_lfo[0]; |
| 889 |
chip->reg_timer_a[1] = chip->reg_timer_a[0]; |
| 890 |
chip->reg_timer_b[1] = chip->reg_timer_b[0]; |
| 891 |
chip->reg_ch3[1] = chip->reg_ch3[0]; |
| 892 |
chip->reg_timer_a_load[1] = chip->reg_timer_a_load[0]; |
| 893 |
chip->reg_timer_b_load[1] = chip->reg_timer_b_load[0]; |
| 894 |
chip->reg_timer_a_enable[1] = chip->reg_timer_a_enable[0]; |
| 895 |
chip->reg_timer_b_enable[1] = chip->reg_timer_b_enable[0]; |
| 896 |
chip->reg_timer_a_reset[1] = chip->reg_timer_a_reset[0]; |
| 897 |
chip->reg_timer_b_reset[1] = chip->reg_timer_b_reset[0]; |
| 898 |
chip->reg_kon_operator[1] = chip->reg_kon_operator[0]; |
| 899 |
chip->reg_kon_channel[1] = chip->reg_kon_channel[0]; |
| 900 |
|
| 901 |
int op_match = chip->write_fm_data[0] && (chip->reg_cnt1[0] == (chip->fm_address[0] & 3)) |
| 902 |
&& (chip->reg_cnt2[0] & 1) == ((chip->fm_address[0] >> 8) & 1) |
| 903 |
&& ((chip->reg_cnt2[0] >> 1) & 1) == ((chip->fm_address[0] >> 2) & 1); |
| 904 |
int ch_match = chip->write_fm_data[0] && (chip->reg_cnt1[0] == (chip->fm_address[0] & 3)) |
| 905 |
&& (chip->reg_cnt2[0] & 1) == ((chip->fm_address[0] >> 8) & 1); |
| 906 |
|
| 907 |
chip->fm_is30 = op_match && (chip->fm_address[0] & 0xf0) == 0x30; |
| 908 |
chip->fm_is40 = op_match && (chip->fm_address[0] & 0xf0) == 0x40; |
| 909 |
chip->fm_is50 = op_match && (chip->fm_address[0] & 0xf0) == 0x50; |
| 910 |
chip->fm_is60 = op_match && (chip->fm_address[0] & 0xf0) == 0x60; |
| 911 |
chip->fm_is70 = op_match && (chip->fm_address[0] & 0xf0) == 0x70; |
| 912 |
chip->fm_is80 = op_match && (chip->fm_address[0] & 0xf0) == 0x80; |
| 913 |
chip->fm_is90 = op_match && (chip->fm_address[0] & 0xf0) == 0x90; |
| 914 |
chip->fm_isa0 = ch_match && (chip->fm_address[0] & 0xfc) == 0xa0; |
| 915 |
chip->fm_isa4 = ch_match && (chip->fm_address[0] & 0xfc) == 0xa4; |
| 916 |
chip->fm_isa8 = ch_match && (chip->fm_address[0] & 0xfc) == 0xa8; |
| 917 |
chip->fm_isac = ch_match && (chip->fm_address[0] & 0xfc) == 0xac; |
| 918 |
chip->fm_isb0 = ch_match && (chip->fm_address[0] & 0xfc) == 0xb0; |
| 919 |
chip->fm_isb4 = ch_match && (chip->fm_address[0] & 0xfc) == 0xb4; |
| 920 |
|
| 921 |
chip->reg_cnt1[1] = chip->reg_cnt1[0]; |
| 922 |
chip->reg_cnt2[1] = chip->reg_cnt2[0]; |
| 923 |
chip->reg_cnt_sync = chip->fsm_sel23[1]; |
| 924 |
|
| 925 |
#ifdef FMOPNA_YM2608 |
| 926 |
chip->reg_cnt_rss[1] = chip->reg_cnt_rss[0]; |
| 927 |
|
| 928 |
chip->reg_cnt_rss_of = (chip->reg_cnt_rss[0] & 11) == 11; |
| 929 |
|
| 930 |
chip->rss_18 = chip->write_fm_data[0] |
| 931 |
&& chip->reg_cnt_rss[0] == (chip->fm_address[0] & 7) && (chip->fm_address[0] & 6) != 6 |
| 932 |
&& (chip->fm_address[0] & 0x1f8) == 0x18; |
| 933 |
#endif |
| 934 |
|
| 935 |
chip->reg_kon_match = chip->reg_key_cnt1[0] == (chip->reg_kon_channel[0] & 3) |
| 936 |
&& chip->reg_key_cnt2[0] == (((chip->reg_kon_channel[0] >> 2) & 1) |
| 937 |
#ifdef FMOPNA_YM2608 |
| 938 |
&& chip->reg_sch[0] |
| 939 |
#endif |
| 940 |
) |
| 941 |
#ifdef FMOPNA_YM2610 |
| 942 |
// tildearrow: changed to allow YM2610B emulation |
| 943 |
&& (chip->ym2610b || (chip->reg_kon_channel[0] & 3) != 0) |
| 944 |
#endif |
| 945 |
; |
| 946 |
|
| 947 |
chip->reg_key_cnt1[1] = chip->reg_key_cnt1[0]; |
| 948 |
chip->reg_key_cnt2[1] = chip->reg_key_cnt2[0]; |
| 949 |
|
| 950 |
chip->reg_kon[0][1] = chip->reg_kon[0][0]; |
| 951 |
chip->reg_kon[1][1] = chip->reg_kon[1][0]; |
| 952 |
chip->reg_kon[2][1] = chip->reg_kon[2][0]; |
| 953 |
chip->reg_kon[3][1] = chip->reg_kon[3][0]; |
| 954 |
|
| 955 |
chip->reg_ch3_sel = chip->fsm_sel_ch3[1]; |
| 956 |
|
| 957 |
chip->ch3_en = chip->reg_ch3[0] != 0; |
| 958 |
chip->ch3_csm = chip->reg_ch3[0] == 2; |
| 959 |
|
| 960 |
chip->timer_a_cnt[1] = chip->timer_a_cnt[0]; |
| 961 |
chip->timer_a_of[1] = chip->timer_a_of[0]; |
| 962 |
|
| 963 |
chip->reg_sync_timer = chip->fsm_sel1[1]; |
| 964 |
chip->reg_sync_timer_l[1] = chip->reg_sync_timer_l[0]; |
| 965 |
|
| 966 |
chip->timer_a_reg_load_l[1] = chip->timer_a_reg_load_l[0]; |
| 967 |
|
| 968 |
chip->reg_sync_timer_load = chip->reg_sync_timer_l[0] && chip->reg_sync_timer_l[1]; |
| 969 |
if (chip->reg_sync_timer_load) |
| 970 |
{ |
| 971 |
chip->timer_a_reg_load = chip->reg_timer_a_load[1]; |
| 972 |
chip->timer_b_reg_load = chip->reg_timer_b_load[1]; |
| 973 |
} |
| 974 |
|
| 975 |
chip->timer_a_load = chip->timer_a_of[1] || (!chip->timer_a_reg_load_l[1] && chip->timer_a_reg_load); |
| 976 |
|
| 977 |
if (chip->reg_sync_timer_load) |
| 978 |
{ |
| 979 |
chip->ch3_csm_load = chip->ch3_csm && chip->timer_a_load; |
| 980 |
} |
| 981 |
|
| 982 |
chip->kon_comb = (chip->reg_kon[3][1] >> 5) & 1; |
| 983 |
chip->kon_comb |= chip->reg_ch3_sel && chip->ch3_csm_load; |
| 984 |
|
| 985 |
chip->timer_a_status[1] = chip->timer_a_status[0]; |
| 986 |
|
| 987 |
chip->timer_b_subcnt[1] = chip->timer_b_subcnt[0]; |
| 988 |
chip->timer_b_subcnt_of[1] = chip->timer_b_subcnt_of[0]; |
| 989 |
|
| 990 |
chip->timer_b_cnt[1] = chip->timer_b_cnt[0]; |
| 991 |
chip->timer_b_of[1] = chip->timer_b_of[0]; |
| 992 |
|
| 993 |
chip->timer_b_reg_load_l[1] = chip->timer_b_reg_load_l[0]; |
| 994 |
|
| 995 |
chip->timer_b_load = chip->timer_b_of[1] || (!chip->timer_b_reg_load_l[1] && chip->timer_b_reg_load); |
| 996 |
|
| 997 |
chip->timer_b_status[1] = chip->timer_b_status[0]; |
| 998 |
|
| 999 |
#ifndef FMOPNA_YM2612 |
| 1000 |
chip->irq_eos_l = chip->eos_repeat; |
| 1001 |
#endif |
| 1002 |
|
| 1003 |
|
| 1004 |
memcpy(&chip->reg_freq[1][0], &chip->reg_freq[0][0], 6 * sizeof(unsigned short)); |
| 1005 |
memcpy(&chip->reg_freq_3ch[1][0], &chip->reg_freq_3ch[0][0], 6 * sizeof(unsigned short)); |
| 1006 |
memcpy(&chip->reg_connect_fb[1][0], &chip->reg_connect_fb[0][0], 6 * sizeof(unsigned char)); |
| 1007 |
memcpy(&chip->reg_b4[1][0], &chip->reg_b4[0][0], 6 * sizeof(unsigned char)); |
| 1008 |
#ifdef FMOPNA_YM2608 |
| 1009 |
memcpy(&chip->reg_rss[1][0], &chip->reg_rss[0][0], 6 * sizeof(unsigned char)); |
| 1010 |
#endif |
| 1011 |
memcpy(&chip->op_multi_dt[1][0][0], &chip->op_multi_dt[0][0][0], 12 * 2 * sizeof(unsigned char)); |
| 1012 |
memcpy(&chip->op_tl[1][0][0], &chip->op_tl[0][0][0], 12 * 2 * sizeof(unsigned char)); |
| 1013 |
memcpy(&chip->op_ar_ks[1][0][0], &chip->op_ar_ks[0][0][0], 12 * 2 * sizeof(unsigned char)); |
| 1014 |
memcpy(&chip->op_dr_a[1][0][0], &chip->op_dr_a[0][0][0], 12 * 2 * sizeof(unsigned char)); |
| 1015 |
memcpy(&chip->op_sr[1][0][0], &chip->op_sr[0][0][0], 12 * 2 * sizeof(unsigned char)); |
| 1016 |
memcpy(&chip->op_rr_sl[1][0][0], &chip->op_rr_sl[0][0][0], 12 * 2 * sizeof(unsigned char)); |
| 1017 |
memcpy(&chip->op_ssg[1][0][0], &chip->op_ssg[0][0][0], 12 * 2 * sizeof(unsigned char)); |
| 1018 |
|
| 1019 |
chip->reg_a4[1] = chip->reg_a4[0]; |
| 1020 |
chip->reg_ac[1] = chip->reg_ac[0]; |
| 1021 |
|
| 1022 |
chip->ch_cnt_sync = chip->fsm_sel23[1]; |
| 1023 |
|
| 1024 |
chip->ch_cnt1[1] = chip->ch_cnt1[0]; |
| 1025 |
chip->ch_cnt2[1] = chip->ch_cnt2[0]; |
| 1026 |
|
| 1027 |
chip->fnum[1] = chip->fnum[0]; |
| 1028 |
chip->fnum[3] = chip->fnum[2]; |
| 1029 |
chip->kcode[1] = chip->kcode[0]; |
| 1030 |
chip->kcode[3] = chip->kcode[2]; |
| 1031 |
} |
| 1032 |
|
| 1033 |
#ifdef FMOPNA_YM2608 |
| 1034 |
{ |
| 1035 |
int write10 = chip->addr_10h[1] && (chip->data_bus1 & 0x100) != 0 && chip->write1_en; |
| 1036 |
int irq_rst = write10 && (chip->data_bus2 & 0x80) == 0; |
| 1037 |
chip->irq_mask_eos = (chip->reg_mask[1] & 4) != 0 || chip->irq_eos_l || irq_rst; |
| 1038 |
chip->irq_mask_brdy = (chip->reg_mask[1] & 8) != 0 || irq_rst; |
| 1039 |
chip->irq_mask_zero = (chip->reg_mask[1] & 16) != 0 || irq_rst; |
| 1040 |
} |
| 1041 |
#endif |
| 1042 |
|
| 1043 |
} |
| 1044 |
|
| 1045 |
{ |
| 1046 |
if (chip->clk1) |
| 1047 |
{ |
| 1048 |
int fsm_cnt; |
| 1049 |
int of1 = (chip->fsm_cnt1[1] & 2) != 0; |
| 1050 |
chip->fsm_cnt1[0] = (chip->ic_check3 || of1) ? 0 : (chip->fsm_cnt1[1] + 1) & 3; |
| 1051 |
chip->fsm_cnt2[0] = chip->ic_check3 ? 0 : (chip->fsm_cnt2[1] + of1) & 7; |
| 1052 |
|
| 1053 |
fsm_cnt = (chip->fsm_cnt2[0] << 2) | chip->fsm_cnt1[0]; |
| 1054 |
|
| 1055 |
chip->fsm_out[0] = (fsm_cnt & 30) == 30; |
| 1056 |
chip->fsm_out[1] = (fsm_cnt & 28) == 0; |
| 1057 |
chip->fsm_out[2] = (fsm_cnt & 30) == 4; |
| 1058 |
chip->fsm_out[3] = (fsm_cnt & 30) == 22; |
| 1059 |
chip->fsm_out[4] = (fsm_cnt & 28) == 24; |
| 1060 |
chip->fsm_out[5] = (fsm_cnt & 30) == 28; |
| 1061 |
chip->fsm_out[6] = (fsm_cnt & 30) == 14; |
| 1062 |
chip->fsm_out[7] = (fsm_cnt & 28) == 16; |
| 1063 |
chip->fsm_out[8] = (fsm_cnt & 30) == 20; |
| 1064 |
chip->fsm_out[9] = (fsm_cnt & 30) == 6; |
| 1065 |
chip->fsm_out[10] = (fsm_cnt & 28) == 8; |
| 1066 |
chip->fsm_out[11] = (fsm_cnt & 30) == 12; |
| 1067 |
chip->fsm_out[12] = (fsm_cnt & 30) == 30; |
| 1068 |
chip->fsm_out[13] = fsm_cnt == 0; |
| 1069 |
chip->fsm_out[14] = fsm_cnt == 1; |
| 1070 |
#ifndef FMOPNA_YM2612 |
| 1071 |
chip->fsm_out[15] = fsm_cnt == 13; |
| 1072 |
#endif |
| 1073 |
chip->fsm_out[16] = fsm_cnt == 29; |
| 1074 |
chip->fsm_out[17] = (fsm_cnt & 7) == 1; |
| 1075 |
chip->fsm_out[18] = (fsm_cnt & 28) == 4; |
| 1076 |
chip->fsm_out[19] = fsm_cnt == 8; |
| 1077 |
#ifndef FMOPNA_YM2612 |
| 1078 |
chip->fsm_out[20] = (fsm_cnt & 28) == 20; |
| 1079 |
chip->fsm_out[21] = fsm_cnt == 24; |
| 1080 |
#endif |
| 1081 |
#ifdef FMOPNA_YM2612 |
| 1082 |
chip->fsm_out[20] = (fsm_cnt & 15) == 14; |
| 1083 |
chip->fsm_out[21] = (fsm_cnt & 15) == 4; |
| 1084 |
chip->fsm_out[22] = (fsm_cnt & 15) == 9; |
| 1085 |
chip->fsm_out[23] = fsm_cnt == 14; |
| 1086 |
chip->fsm_out[24] = (fsm_cnt & 24) == 16; |
| 1087 |
chip->fsm_out[25] = (fsm_cnt & 28) == 24; |
| 1088 |
chip->fsm_out[26] = (fsm_cnt & 30) == 28; |
| 1089 |
#endif |
| 1090 |
|
| 1091 |
chip->alg_mod_op1_0_l = 0; |
| 1092 |
chip->alg_mod_op1_1_l = 0; |
| 1093 |
chip->alg_mod_op2_l = 0; |
| 1094 |
chip->alg_mod_prev_0_l = 0; |
| 1095 |
chip->alg_mod_prev_1_l = 0; |
| 1096 |
chip->alg_output_l = 0; |
| 1097 |
|
| 1098 |
if (chip->fsm_op2_sel_l) |
| 1099 |
{ |
| 1100 |
chip->alg_mod_op1_0_l |= fm_algorithm[0][0][chip->fsm_connect]; |
| 1101 |
chip->alg_mod_op1_1_l |= fm_algorithm[0][1][chip->fsm_connect]; |
| 1102 |
chip->alg_mod_op2_l |= fm_algorithm[0][2][chip->fsm_connect]; |
| 1103 |
chip->alg_mod_prev_0_l |= fm_algorithm[0][3][chip->fsm_connect]; |
| 1104 |
chip->alg_mod_prev_1_l |= fm_algorithm[0][4][chip->fsm_connect]; |
| 1105 |
chip->alg_output_l |= fm_algorithm[2][5][chip->fsm_connect]; |
| 1106 |
} |
| 1107 |
if (chip->fsm_op4_sel_l) |
| 1108 |
{ |
| 1109 |
chip->alg_mod_op1_0_l |= fm_algorithm[1][0][chip->fsm_connect]; |
| 1110 |
chip->alg_mod_op1_1_l |= fm_algorithm[1][1][chip->fsm_connect]; |
| 1111 |
chip->alg_mod_op2_l |= fm_algorithm[1][2][chip->fsm_connect]; |
| 1112 |
chip->alg_mod_prev_0_l |= fm_algorithm[1][3][chip->fsm_connect]; |
| 1113 |
chip->alg_mod_prev_1_l |= fm_algorithm[1][4][chip->fsm_connect]; |
| 1114 |
chip->alg_output_l |= fm_algorithm[3][5][chip->fsm_connect]; |
| 1115 |
} |
| 1116 |
if (chip->fsm_op1_sel_l) |
| 1117 |
{ |
| 1118 |
chip->alg_mod_op1_0_l |= fm_algorithm[2][0][chip->fsm_connect]; |
| 1119 |
chip->alg_mod_op1_1_l |= fm_algorithm[2][1][chip->fsm_connect]; |
| 1120 |
chip->alg_mod_op2_l |= fm_algorithm[2][2][chip->fsm_connect]; |
| 1121 |
chip->alg_mod_prev_0_l |= fm_algorithm[2][3][chip->fsm_connect]; |
| 1122 |
chip->alg_mod_prev_1_l |= fm_algorithm[2][4][chip->fsm_connect]; |
| 1123 |
chip->alg_output_l |= fm_algorithm[0][5][chip->fsm_connect]; |
| 1124 |
} |
| 1125 |
if (chip->fsm_op3_sel_l) |
| 1126 |
{ |
| 1127 |
chip->alg_mod_op1_0_l |= fm_algorithm[3][0][chip->fsm_connect]; |
| 1128 |
chip->alg_mod_op1_1_l |= fm_algorithm[3][1][chip->fsm_connect]; |
| 1129 |
chip->alg_mod_op2_l |= fm_algorithm[3][2][chip->fsm_connect]; |
| 1130 |
chip->alg_mod_prev_0_l |= fm_algorithm[3][3][chip->fsm_connect]; |
| 1131 |
chip->alg_mod_prev_1_l |= fm_algorithm[3][4][chip->fsm_connect]; |
| 1132 |
chip->alg_output_l |= fm_algorithm[1][5][chip->fsm_connect]; |
| 1133 |
} |
| 1134 |
|
| 1135 |
chip->alg_do_fb[1] = chip->alg_do_fb[0]; |
| 1136 |
|
| 1137 |
chip->alg_load_fb = chip->fsm_op1_sel_l; |
| 1138 |
|
| 1139 |
chip->fsm_sel0[1] = chip->fsm_sel0[0]; |
| 1140 |
chip->fsm_sel1[1] = chip->fsm_sel1[0]; |
| 1141 |
chip->fsm_sel2[1] = chip->fsm_sel2[0]; |
| 1142 |
chip->fsm_sel23[1] = chip->fsm_sel23[0]; |
| 1143 |
chip->fsm_sel_ch3[1] = chip->fsm_sel_ch3[0]; |
| 1144 |
#ifndef FMOPNA_YM2612 |
| 1145 |
chip->fsm_sel11[1] = chip->fsm_sel11[0]; |
| 1146 |
chip->fsm_sh1[1] = chip->fsm_sh1[0]; |
| 1147 |
chip->fsm_sh2[1] = chip->fsm_sh2[0]; |
| 1148 |
|
| 1149 |
chip->fsm_rss2 = !chip->fsm_out[16] && !chip->fsm_sel23[1]; |
| 1150 |
#endif |
| 1151 |
#ifdef FMOPNA_YM2612 |
| 1152 |
chip->fsm_dac_ch6[1] = chip->fsm_dac_ch6[0]; |
| 1153 |
chip->fsm_dac_load[1] = chip->fsm_dac_load[0]; |
| 1154 |
chip->fsm_dac_out_sel[1] = chip->fsm_dac_out_sel[0]; |
| 1155 |
#endif |
| 1156 |
} |
| 1157 |
if (chip->clk2) |
| 1158 |
{ |
| 1159 |
chip->fsm_cnt1[1] = chip->fsm_cnt1[0]; |
| 1160 |
chip->fsm_cnt2[1] = chip->fsm_cnt2[0]; |
| 1161 |
|
| 1162 |
chip->fsm_op4_sel_l = chip->fsm_out[0] || chip->fsm_out[1] || chip->fsm_out[2]; |
| 1163 |
chip->fsm_op2_sel_l = chip->fsm_out[3] || chip->fsm_out[4] || chip->fsm_out[5]; |
| 1164 |
chip->fsm_op3_sel_l = chip->fsm_out[6] || chip->fsm_out[7] || chip->fsm_out[8]; |
| 1165 |
chip->fsm_op1_sel_l = chip->fsm_out[9] || chip->fsm_out[10] || chip->fsm_out[11]; |
| 1166 |
|
| 1167 |
chip->fsm_connect = chip->reg_connect_fb[0][4] & 7; |
| 1168 |
|
| 1169 |
chip->alg_do_fb[0] = chip->alg_mod_op1_1_l; |
| 1170 |
|
| 1171 |
chip->fsm_sel0[0] = chip->fsm_out[12]; |
| 1172 |
chip->fsm_sel1[0] = chip->fsm_out[13]; |
| 1173 |
chip->fsm_sel2[0] = chip->fsm_out[14]; |
| 1174 |
chip->fsm_sel23[0] = chip->fsm_out[16]; |
| 1175 |
chip->fsm_sel_ch3[0] = chip->fsm_out[17]; |
| 1176 |
#ifndef FMOPNA_YM2612 |
| 1177 |
chip->fsm_sel11[0] = chip->fsm_out[15]; |
| 1178 |
chip->fsm_sh1[0] = chip->fsm_out[18] || chip->fsm_out[19]; |
| 1179 |
chip->fsm_sh2[0] = chip->fsm_out[20] || chip->fsm_out[21]; |
| 1180 |
|
| 1181 |
chip->fsm_rss = (chip->fsm_cnt2[0] & 2) != 0; |
| 1182 |
#endif |
| 1183 |
#ifdef FMOPNA_YM2612 |
| 1184 |
chip->fsm_dac_ch6[0] = chip->fsm_out[18] || chip->fsm_out[19]; |
| 1185 |
chip->fsm_dac_load[0] = chip->fsm_out[20] || chip->fsm_out[21] || chip->fsm_out[22]; |
| 1186 |
chip->fsm_dac_out_sel[0] = chip->fsm_out[23] || chip->fsm_out[24] || chip->fsm_out[25] || chip->fsm_out[26]; |
| 1187 |
#endif |
| 1188 |
} |
| 1189 |
} |
| 1190 |
|
| 1191 |
{ |
| 1192 |
if (chip->clk1) |
| 1193 |
{ |
| 1194 |
int inc = chip->lfo_sync[0] |
| 1195 |
#ifndef FMOPNA_YM2610 |
| 1196 |
|| (chip->reg_test_21[1] & 2) != 0 |
| 1197 |
#endif |
| 1198 |
; |
| 1199 |
int subcnt_rst = chip->ic || chip->lfo_subcnt_of; |
| 1200 |
|
| 1201 |
chip->lfo_subcnt[0] = subcnt_rst ? 0 : (chip->lfo_subcnt[1] + inc) & 127; |
| 1202 |
|
| 1203 |
int cnt = chip->lfo_cnt[1] + chip->lfo_subcnt_of; |
| 1204 |
|
| 1205 |
#ifdef FMOPNA_YM2608 |
| 1206 |
chip->lfo_cnt_of = (cnt & 128) != 0 && chip->lfo_mode; |
| 1207 |
#endif |
| 1208 |
chip->lfo_cnt[0] = chip->lfo_cnt_rst ? 0 : cnt & 127; |
| 1209 |
|
| 1210 |
chip->lfo_sync[1] = chip->lfo_sync[0]; |
| 1211 |
chip->lfo_sync[3] = chip->lfo_sync[2]; |
| 1212 |
|
| 1213 |
// LFO shift |
| 1214 |
static const int pg_lfo_sh1[8][8] = { |
| 1215 |
{ 7, 7, 7, 7, 7, 7, 7, 7 }, |
| 1216 |
{ 7, 7, 7, 7, 7, 7, 7, 7 }, |
| 1217 |
{ 7, 7, 7, 7, 7, 7, 1, 1 }, |
| 1218 |
{ 7, 7, 7, 7, 1, 1, 1, 1 }, |
| 1219 |
{ 7, 7, 7, 1, 1, 1, 1, 0 }, |
| 1220 |
{ 7, 7, 1, 1, 0, 0, 0, 0 }, |
| 1221 |
{ 7, 7, 1, 1, 0, 0, 0, 0 }, |
| 1222 |
{ 7, 7, 1, 1, 0, 0, 0, 0 } |
| 1223 |
}; |
| 1224 |
|
| 1225 |
#if 0 |
| 1226 |
// YM2608/YM2610 decap, doesn't match YM2608 nor YM2610 hardware tests though |
| 1227 |
static const int pg_lfo_sh2[8][8] = { |
| 1228 |
{ 7, 7, 7, 7, 7, 7, 7, 7 }, |
| 1229 |
{ 7, 7, 7, 7, 2, 2, 2, 2 }, |
| 1230 |
{ 7, 7, 7, 2, 2, 2, 7, 7 }, |
| 1231 |
{ 7, 7, 2, 2, 7, 7, 2, 2 }, |
| 1232 |
{ 7, 2, 2, 7, 7, 2, 2, 7 }, |
| 1233 |
{ 7, 2, 7, 2, 7, 2, 2, 1 }, |
| 1234 |
{ 7, 2, 7, 2, 7, 2, 2, 1 }, |
| 1235 |
{ 7, 2, 7, 2, 7, 2, 2, 1 } |
| 1236 |
}; |
| 1237 |
#endif |
| 1238 |
#if 1 |
| 1239 |
// YM2612/YM3438 decap, matches to YM2608 and YM2610 hardware tests O_O |
| 1240 |
static const int pg_lfo_sh2[8][8] = { |
| 1241 |
{ 7, 7, 7, 7, 7, 7, 7, 7 }, |
| 1242 |
{ 7, 7, 7, 7, 2, 2, 2, 2 }, |
| 1243 |
{ 7, 7, 7, 2, 2, 2, 7, 7 }, |
| 1244 |
{ 7, 7, 2, 2, 7, 7, 2, 2 }, |
| 1245 |
{ 7, 7, 2, 7, 7, 7, 2, 7 }, |
| 1246 |
{ 7, 7, 7, 2, 7, 7, 2, 1 }, |
| 1247 |
{ 7, 7, 7, 2, 7, 7, 2, 1 }, |
| 1248 |
{ 7, 7, 7, 2, 7, 7, 2, 1 } |
| 1249 |
}; |
| 1250 |
#endif |
| 1251 |
int pms = chip->reg_b4[1][5] & 7; |
| 1252 |
int lfo = (chip->lfo_cnt_load >> 2) & 7; |
| 1253 |
if (chip->lfo_cnt_load & 32) |
| 1254 |
lfo ^= 7; |
| 1255 |
int fnum_h = chip->fnum[1] >> 4; |
| 1256 |
|
| 1257 |
chip->lfo_fnum1 = fnum_h >> pg_lfo_sh1[pms][lfo]; |
| 1258 |
chip->lfo_fnum2 = fnum_h >> pg_lfo_sh2[pms][lfo]; |
| 1259 |
|
| 1260 |
chip->lfo_shift = 2; |
| 1261 |
if (pms > 5) |
| 1262 |
chip->lfo_shift = 7 - pms; |
| 1263 |
|
| 1264 |
chip->lfo_sign = (chip->lfo_cnt_load >> 6) & 1; |
| 1265 |
|
| 1266 |
chip->lfo_fnum = ((chip->fnum[3] << 1) + chip->lfo_pm) & 0xfff; |
| 1267 |
} |
| 1268 |
if (chip->clk2) |
| 1269 |
{ |
| 1270 |
static const int lfo_cycles[8] = { |
| 1271 |
108, 77, 71, 67, 62, 44, 8, 5 |
| 1272 |
}; |
| 1273 |
chip->lfo_sync[0] = chip->fsm_sel23[1]; |
| 1274 |
chip->lfo_sync[2] = chip->lfo_sync[1]; |
| 1275 |
|
| 1276 |
chip->lfo_subcnt[1] = chip->lfo_subcnt[0]; |
| 1277 |
|
| 1278 |
int of = (chip->lfo_subcnt[0] & lfo_cycles[chip->reg_lfo[0] & 7]) == lfo_cycles[chip->reg_lfo[0] & 7]; |
| 1279 |
|
| 1280 |
#ifdef FMOPNA_YM2608 |
| 1281 |
chip->lfo_mode = chip->ad_sample_l[2] || (chip->ad_reg_rec && chip->ad_start_l[1]); |
| 1282 |
chip->lfo_subcnt_of = chip->lfo_mode ? (chip->lfo_subcnt[0] & 127) == 127 : of; |
| 1283 |
chip->lfo_cnt_rst = chip->lfo_mode ? chip->ad_ad_quiet : (chip->reg_lfo[0] & 8) == 0; |
| 1284 |
#else |
| 1285 |
chip->lfo_subcnt_of = of; |
| 1286 |
chip->lfo_cnt_rst = (chip->reg_lfo[0] & 8) == 0; |
| 1287 |
#endif |
| 1288 |
|
| 1289 |
chip->lfo_cnt[1] = chip->lfo_cnt[0]; |
| 1290 |
|
| 1291 |
if (!chip->lfo_sync[3] && chip->lfo_sync[2]) |
| 1292 |
{ |
| 1293 |
chip->lfo_cnt_load = chip->lfo_cnt[1]; |
| 1294 |
} |
| 1295 |
|
| 1296 |
if (chip->lfo_cnt_load & 64) |
| 1297 |
chip->lfo_am = chip->lfo_cnt_load & 63; |
| 1298 |
else |
| 1299 |
chip->lfo_am = (chip->lfo_cnt_load & 63) ^ 63; |
| 1300 |
|
| 1301 |
chip->lfo_pm = (chip->lfo_fnum1 + chip->lfo_fnum2) >> chip->lfo_shift; |
| 1302 |
if (chip->lfo_sign) |
| 1303 |
chip->lfo_pm = -chip->lfo_pm; |
| 1304 |
} |
| 1305 |
} |
| 1306 |
|
| 1307 |
|
| 1308 |
{ |
| 1309 |
if (chip->clk1) |
| 1310 |
{ |
| 1311 |
chip->pg_block = chip->kcode[3] >> 2; |
| 1312 |
|
| 1313 |
chip->pg_dt_multi = (chip->reg_key_cnt2[1] & 4) == 0 ? chip->op_multi_dt[1][11][0] |
| 1314 |
: chip->op_multi_dt[1][11][1]; |
| 1315 |
|
| 1316 |
chip->dt_note[1] = chip->dt_note[0]; |
| 1317 |
chip->dt_blockmax[1] = chip->dt_blockmax[0]; |
| 1318 |
|
| 1319 |
chip->dt_enable[1] = chip->dt_enable[0]; |
| 1320 |
|
| 1321 |
chip->dt_sign[1] = chip->dt_sign[0]; |
| 1322 |
|
| 1323 |
chip->dt_sum = chip->dt_add1 + chip->dt_add2 + 1; |
| 1324 |
|
| 1325 |
chip->pg_freqdt[0] = (chip->pg_freq + chip->pg_dt_add) & 0x1ffff; |
| 1326 |
|
| 1327 |
chip->pg_multi[1] = chip->pg_multi[0]; |
| 1328 |
chip->pg_multi[3] = chip->pg_multi[2]; |
| 1329 |
|
| 1330 |
chip->pg_add[0] = chip->pg_multi[4] ? chip->pg_freqdt[1] * chip->pg_multi[4] : |
| 1331 |
(chip->pg_freqdt[1] >> 1); |
| 1332 |
chip->pg_add[2] = chip->pg_add[1]; |
| 1333 |
chip->pg_add[4] = chip->pg_add[3]; |
| 1334 |
|
| 1335 |
chip->pg_reset[1] = chip->pg_reset[0]; |
| 1336 |
chip->pg_reset[3] = chip->pg_reset[2]; |
| 1337 |
|
| 1338 |
memcpy(&chip->pg_phase[0][1], &chip->pg_phase[1][0], 22 * sizeof(int)); |
| 1339 |
|
| 1340 |
chip->pg_phase2[0] = chip->pg_phase[1][22]; |
| 1341 |
|
| 1342 |
chip->pg_phase[0][0] = (chip->pg_phase2[1] + chip->pg_add[5]) & 0xfffff; |
| 1343 |
|
| 1344 |
chip->pg_dbg[0] = chip->pg_dbg[1] >> 1; |
| 1345 |
if (chip->pg_dbgsync) |
| 1346 |
chip->pg_dbg[0] |= chip->pg_phase[1][22] & 1023; |
| 1347 |
#ifdef FMOPNA_YM2610 |
| 1348 |
chip->pg_dbgsync_l[1] = chip->pg_dbgsync_l[0]; |
| 1349 |
#endif |
| 1350 |
|
| 1351 |
} |
| 1352 |
if (chip->clk2) |
| 1353 |
{ |
| 1354 |
chip->pg_freq = (chip->lfo_fnum << chip->pg_block) >> 2; |
| 1355 |
|
| 1356 |
chip->dt_note[0] = chip->kcode[2] & 3; |
| 1357 |
chip->dt_blockmax[0] = (chip->kcode[2] & 28) == 28; |
| 1358 |
chip->dt_add1 = (chip->kcode[2] >> 2) & 7; |
| 1359 |
if ((chip->pg_dt_multi & 0x30) != 0) |
| 1360 |
chip->dt_add1 |= 8; |
| 1361 |
chip->dt_add2 = 0; |
| 1362 |
if ((chip->pg_dt_multi & 0x30) == 0x30) |
| 1363 |
chip->dt_add2 |= 1; |
| 1364 |
if (chip->pg_dt_multi & 0x20) |
| 1365 |
chip->dt_add2 |= 2; |
| 1366 |
|
| 1367 |
chip->dt_enable[0] = (chip->pg_dt_multi & 0x30) != 0; |
| 1368 |
|
| 1369 |
chip->dt_sign[0] = (chip->pg_dt_multi & 0x40) != 0; |
| 1370 |
|
| 1371 |
int dt_l = (chip->dt_sum & 1) << 2; |
| 1372 |
if (!chip->dt_blockmax[1]) |
| 1373 |
dt_l |= chip->dt_note[1]; |
| 1374 |
int dt_h = chip->dt_sum >> 1; |
| 1375 |
|
| 1376 |
static const int pg_detune[8] = { 16, 17, 19, 20, 22, 24, 27, 29 }; |
| 1377 |
|
| 1378 |
int dt_freq = pg_detune[dt_l] >> (9 - dt_h); |
| 1379 |
|
| 1380 |
if (chip->dt_sign[1]) |
| 1381 |
dt_freq = -dt_freq; |
| 1382 |
|
| 1383 |
chip->pg_dt_add = dt_freq; |
| 1384 |
|
| 1385 |
chip->pg_multi[0] = chip->pg_dt_multi & 15; |
| 1386 |
chip->pg_multi[2] = chip->pg_multi[1]; |
| 1387 |
chip->pg_multi[4] = chip->pg_multi[3]; |
| 1388 |
|
| 1389 |
chip->pg_freqdt[1] = chip->pg_freqdt[0]; |
| 1390 |
|
| 1391 |
chip->pg_add[1] = chip->pg_add[0]; |
| 1392 |
chip->pg_add[3] = chip->pg_reset[1] ? 0 : chip->pg_add[2]; |
| 1393 |
chip->pg_add[5] = chip->pg_add[4]; |
| 1394 |
|
| 1395 |
chip->pg_reset[0] = (chip->eg_pg_reset[0] & 2) != 0; |
| 1396 |
chip->pg_reset[2] = chip->pg_reset[1]; |
| 1397 |
memcpy(&chip->pg_phase[1][0], &chip->pg_phase[0][0], 23 * sizeof(int)); |
| 1398 |
|
| 1399 |
chip->pg_out = chip->pg_phase[1][18] >> 10; |
| 1400 |
|
| 1401 |
chip->pg_phase2[1] = chip->pg_reset[3] ? 0 : chip->pg_phase2[0]; |
| 1402 |
|
| 1403 |
#ifdef FMOPNA_YM2610 |
| 1404 |
chip->pg_dbgsync_l[0] = chip->fsm_sel2[1]; |
| 1405 |
chip->pg_dbgsync = chip->pg_dbgsync_l[1]; |
| 1406 |
#else |
| 1407 |
chip->pg_dbgsync = chip->fsm_sel2[1]; |
| 1408 |
#endif |
| 1409 |
|
| 1410 |
chip->pg_dbg[1] = chip->pg_dbg[0]; |
| 1411 |
} |
| 1412 |
} |
| 1413 |
|
| 1414 |
{ |
| 1415 |
if (chip->clk1) |
| 1416 |
{ |
| 1417 |
chip->eg_prescaler_clock_l[0] = chip->eg_sync; |
| 1418 |
chip->eg_prescaler[0] = (chip->eg_prescaler[1] + chip->eg_sync) & 3; |
| 1419 |
if (((chip->eg_prescaler[1] & 2) != 0 && chip->eg_sync) || chip->ic) |
| 1420 |
chip->eg_prescaler[0] = 0; |
| 1421 |
chip->eg_step[0] = chip->eg_prescaler[1] >> 1; |
| 1422 |
chip->eg_step[2] = chip->eg_step[1]; |
| 1423 |
chip->eg_timer_step[1] = chip->eg_timer_step[0]; |
| 1424 |
|
| 1425 |
chip->eg_ic[0] = chip->ic; |
| 1426 |
|
| 1427 |
chip->eg_clock_delay[0] = (chip->eg_clock_delay[1] << 1) | chip->eg_prescaler_clock_l[1]; |
| 1428 |
|
| 1429 |
|
| 1430 |
int sum = (chip->eg_timer[1] >> 10) & 1; |
| 1431 |
int add = chip->eg_timer_carry[1]; |
| 1432 |
if ((chip->eg_prescaler[1] & 2) != 0 && chip->eg_prescaler_clock_l[1]) |
| 1433 |
add = 1; |
| 1434 |
sum += add; |
| 1435 |
|
| 1436 |
chip->eg_timer[0] = (chip->eg_timer[1] << 1) | chip->eg_timer_sum[1]; |
| 1437 |
|
| 1438 |
chip->eg_timer_carry[0] = sum >> 1; |
| 1439 |
chip->eg_timer_sum[0] = sum & 1; |
| 1440 |
chip->eg_timer_test = (chip->reg_test_21[1] & 32) != 0; |
| 1441 |
chip->eg_timer_test_bit[0] = chip->input.test; |
| 1442 |
|
| 1443 |
int timer_bit = chip->eg_timer_sum[1] || |
| 1444 |
(!chip->eg_timer_test_bit[1] |
| 1445 |
#ifdef FMOPNA_YM2612 |
| 1446 |
&& (chip->reg_test_2c[1] & 64) != 0 |
| 1447 |
#endif |
| 1448 |
); |
| 1449 |
|
| 1450 |
chip->eg_timer_mask[0] = timer_bit | chip->eg_timer_mask[1]; |
| 1451 |
if (chip->eg_prescaler_clock_l[1] || ((chip->eg_clock_delay[1] >> 11) & 1) != 0 || chip->eg_ic[1]) |
| 1452 |
chip->eg_timer_mask[0] = 0; |
| 1453 |
|
| 1454 |
int timer_bit_masked = timer_bit && !chip->eg_timer_mask[1]; |
| 1455 |
|
| 1456 |
chip->eg_timer_masked[0] = (chip->eg_timer_masked[1] << 1) | timer_bit_masked; |
| 1457 |
|
| 1458 |
if (chip->eg_timer_step[0] && chip->eg_timer_step[1]) |
| 1459 |
{ |
| 1460 |
int b0, b1, b2, b3; |
| 1461 |
b0 = (chip->eg_timer[0] >> 11) & 1; |
| 1462 |
b1 = (chip->eg_timer[0] >> 10) & 1; |
| 1463 |
chip->eg_timer_low_lock = b1 * 2 + b0; |
| 1464 |
|
| 1465 |
b0 = (chip->eg_timer_masked[0] & 0xaaa) != 0; |
| 1466 |
b1 = (chip->eg_timer_masked[0] & 0x666) != 0; |
| 1467 |
b2 = (chip->eg_timer_masked[0] & 0x1e1) != 0; |
| 1468 |
b3 = (chip->eg_timer_masked[0] & 0x1f) != 0; |
| 1469 |
chip->eg_shift_lock = b3 * 8 + b2 * 4 + b1 * 2 + b0; |
| 1470 |
} |
| 1471 |
|
| 1472 |
int bank = (chip->reg_key_cnt2[1] & 4) != 0; |
| 1473 |
|
| 1474 |
chip->eg_rate_ar = chip->op_ar_ks[1][11][bank] & 0x1f; |
| 1475 |
chip->eg_ks = (chip->op_ar_ks[1][11][bank] >> 6) & 3; |
| 1476 |
chip->eg_rate_dr = chip->op_dr_a[1][11][bank] & 0x1f; |
| 1477 |
chip->eg_rate_sr = chip->op_sr[1][11][bank] & 0x1f; |
| 1478 |
chip->eg_rate_rr = chip->op_rr_sl[1][11][bank] & 0xf; |
| 1479 |
|
| 1480 |
chip->eg_rate_nonzero[1] = chip->eg_rate_nonzero[0]; |
| 1481 |
|
| 1482 |
chip->eg_rate2 = (chip->eg_rate << 1) + chip->eg_ksv; |
| 1483 |
|
| 1484 |
chip->eg_maxrate[1] = chip->eg_maxrate[0]; |
| 1485 |
|
| 1486 |
int inc1 = 0; |
| 1487 |
if (chip->eg_rate_slow && chip->eg_rate_nonzero[2]) |
| 1488 |
{ |
| 1489 |
switch (chip->eg_rate_sum) |
| 1490 |
{ |
| 1491 |
case 12: |
| 1492 |
inc1 = chip->eg_ratenz; |
| 1493 |
break; |
| 1494 |
case 13: |
| 1495 |
inc1 = (chip->eg_rate_low >> 1) & 1; |
| 1496 |
break; |
| 1497 |
case 14: |
| 1498 |
inc1 = chip->eg_rate_low & 1; |
| 1499 |
break; |
| 1500 |
} |
| 1501 |
} |
| 1502 |
|
| 1503 |
chip->eg_incsh0[0] = inc1; |
| 1504 |
chip->eg_incsh3[0] = chip->eg_rate15; |
| 1505 |
if (!chip->eg_inc2) |
| 1506 |
{ |
| 1507 |
chip->eg_incsh0[0] |= chip->eg_rate12; |
| 1508 |
chip->eg_incsh1[0] = chip->eg_rate13; |
| 1509 |
chip->eg_incsh2[0] = chip->eg_rate14; |
| 1510 |
} |
| 1511 |
else |
| 1512 |
{ |
| 1513 |
chip->eg_incsh1[0] = chip->eg_rate12; |
| 1514 |
chip->eg_incsh2[0] = chip->eg_rate13; |
| 1515 |
chip->eg_incsh3[0] |= chip->eg_rate14; |
| 1516 |
} |
| 1517 |
|
| 1518 |
chip->eg_kon_latch[0] = (chip->eg_kon_latch[1] << 1) | chip->kon_comb; |
| 1519 |
int csm_kon = chip->reg_ch3_sel && chip->ch3_csm_load; |
| 1520 |
chip->eg_kon_csm[0] = (chip->eg_kon_csm[1] << 1) | csm_kon; |
| 1521 |
|
| 1522 |
int kon = (chip->eg_kon_latch[1] >> 1) & 1; |
| 1523 |
int okon = (chip->eg_key[1] >> 23) & 1; |
| 1524 |
int pg_reset = (kon && !okon) || (chip->eg_ssg_pgreset[1] & 2) != 0; |
| 1525 |
chip->eg_pg_reset[0] = (chip->eg_pg_reset[1] << 1) | pg_reset; |
| 1526 |
chip->eg_kon_event = (kon && !okon) || (okon && (chip->eg_ssg_egrepeat[1] & 2) != 0); |
| 1527 |
|
| 1528 |
chip->eg_key[0] = (chip->eg_key[1] << 1) | kon; |
| 1529 |
|
| 1530 |
int okon2 = (chip->eg_key[1] >> 21) & 1; |
| 1531 |
|
| 1532 |
|
| 1533 |
chip->eg_ssg_sign[0] = (chip->eg_level[1][18] & 0x200) != 0; |
| 1534 |
|
| 1535 |
int ssg_eg = chip->op_ssg[1][11][bank] & 15; |
| 1536 |
int ssg_enable = (ssg_eg & 8) != 0; |
| 1537 |
chip->eg_ssg_enable[0] = (chip->eg_ssg_enable[1] << 1) | ssg_enable; |
| 1538 |
int ssg_inv_e = ssg_enable && (ssg_eg & 4) != 0; |
| 1539 |
int ssg_holdup = ssg_enable && ((ssg_eg & 7) == 3 || (ssg_eg & 7) == 5) && chip->kon_comb; |
| 1540 |
chip->eg_ssg_holdup[0] = (chip->eg_ssg_holdup[1] << 1) | ssg_holdup; |
| 1541 |
int ssg_pgreset = ssg_enable && chip->eg_ssg_sign[1] && (ssg_eg & 3) == 0; |
| 1542 |
chip->eg_ssg_pgreset[0] = (chip->eg_ssg_pgreset[1] << 1) | ssg_pgreset; |
| 1543 |
int ssg_egrepeat = ssg_enable && chip->eg_ssg_sign[1] && (ssg_eg & 1) == 0; |
| 1544 |
chip->eg_ssg_egrepeat[0] = (chip->eg_ssg_egrepeat[1] << 1) | ssg_egrepeat; |
| 1545 |
|
| 1546 |
chip->eg_rate_sel = (okon2 ? ssg_egrepeat : chip->kon_comb) ? eg_state_attack : chip->eg_state[1][20]; |
| 1547 |
|
| 1548 |
int ssg_odir = (chip->eg_ssg_dir[1] >> 23) & 1; |
| 1549 |
int ssg_dir = ssg_enable && okon2 && |
| 1550 |
((ssg_odir ^ ((ssg_eg & 3) == 2 && chip->eg_ssg_sign[1])) || ((ssg_eg & 3) == 3 && chip->eg_ssg_sign[1])); |
| 1551 |
chip->eg_ssg_dir[0] = (chip->eg_ssg_dir[1] << 1) | ssg_dir; |
| 1552 |
|
| 1553 |
int ssg_inv = okon2 && (ssg_odir ^ ssg_inv_e); |
| 1554 |
|
| 1555 |
chip->eg_ssg_inv = ssg_inv; |
| 1556 |
|
| 1557 |
chip->eg_level_ssg[0] = chip->eg_output; |
| 1558 |
int eg_output = chip->eg_output; |
| 1559 |
|
| 1560 |
if (chip->reg_test_21[1] & 32) |
| 1561 |
eg_output = 0; |
| 1562 |
|
| 1563 |
int sl = (chip->op_rr_sl[1][11][bank] >> 4) & 15; |
| 1564 |
|
| 1565 |
if (sl == 15) |
| 1566 |
sl |= 16; |
| 1567 |
|
| 1568 |
chip->eg_sl[0][0] = sl; |
| 1569 |
chip->eg_sl[1][0] = chip->eg_sl[0][1]; |
| 1570 |
chip->eg_tl[0][0] = chip->op_tl[1][11][bank]; |
| 1571 |
chip->eg_tl[1][0] = chip->eg_tl[0][1]; |
| 1572 |
chip->eg_tl[2][0] = chip->eg_tl[1][1]; |
| 1573 |
|
| 1574 |
int level = (okon && !kon) ? chip->eg_level_ssg[1] : chip->eg_level[1][21]; |
| 1575 |
|
| 1576 |
chip->eg_off = (chip->eg_ssg_enable[1] & 2) != 0 ? (level & 512) != 0 : (level & 0x3f0) == 0x3f0; |
| 1577 |
chip->eg_slreach = (level >> 4) == (chip->eg_sl[1][1] << 1); |
| 1578 |
chip->eg_zeroreach = level == 0; |
| 1579 |
|
| 1580 |
chip->eg_level_l[0] = level; |
| 1581 |
|
| 1582 |
chip->eg_state_l = chip->eg_state[1][22]; |
| 1583 |
|
| 1584 |
memcpy(&chip->eg_state[0][1], &chip->eg_state[1][0], 22 * sizeof(unsigned char)); |
| 1585 |
chip->eg_state[0][0] = chip->eg_nextstate; |
| 1586 |
|
| 1587 |
int inc_total = 0; |
| 1588 |
if (chip->eg_exp) |
| 1589 |
{ |
| 1590 |
if (chip->eg_incsh0[1]) |
| 1591 |
inc_total |= ~chip->eg_level_l[1] >> 4; |
| 1592 |
if (chip->eg_incsh1[1]) |
| 1593 |
inc_total |= ~chip->eg_level_l[1] >> 3; |
| 1594 |
if (chip->eg_incsh2[1]) |
| 1595 |
inc_total |= ~chip->eg_level_l[1] >> 2; |
| 1596 |
if (chip->eg_incsh3[1]) |
| 1597 |
inc_total |= ~chip->eg_level_l[1] >> 1; |
| 1598 |
} |
| 1599 |
if (chip->eg_linear) |
| 1600 |
{ |
| 1601 |
if (chip->eg_ssg_enable[1] & 4) |
| 1602 |
{ |
| 1603 |
if (chip->eg_incsh0[1]) |
| 1604 |
inc_total |= 4; |
| 1605 |
if (chip->eg_incsh1[1]) |
| 1606 |
inc_total |= 8; |
| 1607 |
if (chip->eg_incsh2[1]) |
| 1608 |
inc_total |= 16; |
| 1609 |
if (chip->eg_incsh3[1]) |
| 1610 |
inc_total |= 32; |
| 1611 |
} |
| 1612 |
else |
| 1613 |
{ |
| 1614 |
if (chip->eg_incsh0[1]) |
| 1615 |
inc_total |= 1; |
| 1616 |
if (chip->eg_incsh1[1]) |
| 1617 |
inc_total |= 2; |
| 1618 |
if (chip->eg_incsh2[1]) |
| 1619 |
inc_total |= 4; |
| 1620 |
if (chip->eg_incsh3[1]) |
| 1621 |
inc_total |= 8; |
| 1622 |
} |
| 1623 |
} |
| 1624 |
|
| 1625 |
chip->eg_inc_total = inc_total; |
| 1626 |
|
| 1627 |
int nextlevel = 0; |
| 1628 |
|
| 1629 |
if (!chip->eg_istantattack) |
| 1630 |
nextlevel |= chip->eg_level_l[1]; |
| 1631 |
|
| 1632 |
if (chip->eg_kon_csm[1] & 4) |
| 1633 |
nextlevel |= chip->eg_tl[2][1] << 3; |
| 1634 |
|
| 1635 |
if (chip->eg_mute || chip->ic) |
| 1636 |
nextlevel |= 0x3ff; |
| 1637 |
|
| 1638 |
chip->eg_nextlevel[0] = nextlevel; |
| 1639 |
|
| 1640 |
memcpy(&chip->eg_level[0][1], &chip->eg_level[1][0], 21 * sizeof(unsigned short)); |
| 1641 |
chip->eg_level[0][0] = chip->eg_nextlevel[1]; |
| 1642 |
|
| 1643 |
chip->eg_am_l[0] = chip->lfo_am; |
| 1644 |
chip->eg_am_shift[0] = (chip->op_dr_a[1][11][bank] & 0x80) != 0 ? (chip->reg_b4[1][5] >> 4) & 3 : 0; |
| 1645 |
static const int eg_am_shift[4] = { |
| 1646 |
7, 3, 1, 0 |
| 1647 |
}; |
| 1648 |
|
| 1649 |
int lfo_add = (chip->eg_am_l[1] << 1) >> eg_am_shift[chip->eg_am_shift[1]]; |
| 1650 |
|
| 1651 |
eg_output += lfo_add; |
| 1652 |
|
| 1653 |
chip->eg_of1 = (eg_output & 1024) != 0; |
| 1654 |
chip->eg_output_lfo = eg_output & 1023; |
| 1655 |
|
| 1656 |
chip->eg_ch3_l[1] = chip->eg_ch3_l[0]; |
| 1657 |
|
| 1658 |
chip->eg_csm_tl = (chip->ch3_csm && (chip->eg_ch3_l[0] & 2) != 0) ? 0 : chip->eg_tl[1][0]; |
| 1659 |
|
| 1660 |
chip->eg_debug[0] = chip->eg_debug[1] << 1; |
| 1661 |
|
| 1662 |
if (chip->eg_dbg_sync) |
| 1663 |
{ |
| 1664 |
chip->eg_debug[0] |= chip->eg_out; |
| 1665 |
} |
| 1666 |
|
| 1667 |
chip->eg_debug_inc = chip->eg_incsh0[1] || chip->eg_incsh1[1] || chip->eg_incsh2[1] || chip->eg_incsh3[1]; |
| 1668 |
} |
| 1669 |
if (chip->clk2) |
| 1670 |
{ |
| 1671 |
chip->eg_sync = chip->fsm_sel0[1]; |
| 1672 |
chip->eg_prescaler_clock_l[1] = chip->eg_prescaler_clock_l[0]; |
| 1673 |
chip->eg_prescaler[1] = chip->eg_prescaler[0]; |
| 1674 |
chip->eg_step[1] = chip->eg_step[0]; |
| 1675 |
chip->eg_timer_step[0] = chip->eg_step[0] && chip->eg_prescaler_clock_l[0]; |
| 1676 |
|
| 1677 |
chip->eg_ic[1] = chip->eg_ic[0]; |
| 1678 |
|
| 1679 |
chip->eg_timer_test_bit[1] = chip->eg_timer_test_bit[0]; |
| 1680 |
|
| 1681 |
chip->eg_timer_sum[1] = chip->eg_timer_sum[0] && !chip->eg_ic[0] && !chip->eg_timer_test; |
| 1682 |
chip->eg_timer[1] = chip->eg_timer[0]; |
| 1683 |
chip->eg_clock_delay[1] = chip->eg_clock_delay[0]; |
| 1684 |
chip->eg_timer_carry[1] = chip->eg_timer_carry[0]; |
| 1685 |
chip->eg_timer_mask[1] = chip->eg_timer_mask[0]; |
| 1686 |
chip->eg_timer_masked[1] = chip->eg_timer_masked[0]; |
| 1687 |
|
| 1688 |
int rate = 0; |
| 1689 |
switch (chip->eg_rate_sel) |
| 1690 |
{ |
| 1691 |
case eg_state_attack: |
| 1692 |
rate = chip->eg_rate_ar; |
| 1693 |
break; |
| 1694 |
case eg_state_decay: |
| 1695 |
rate = chip->eg_rate_dr; |
| 1696 |
break; |
| 1697 |
case eg_state_sustain: |
| 1698 |
rate = chip->eg_rate_sr; |
| 1699 |
break; |
| 1700 |
case eg_state_release: |
| 1701 |
rate = (chip->eg_rate_rr * 2) | 1; |
| 1702 |
break; |
| 1703 |
} |
| 1704 |
|
| 1705 |
chip->eg_rate_nonzero[0] = rate != 0; |
| 1706 |
chip->eg_rate_nonzero[2] = chip->eg_rate_nonzero[1]; |
| 1707 |
chip->eg_rate = rate; |
| 1708 |
chip->eg_ksv = chip->kcode[2] >> (chip->eg_ks ^ 3); |
| 1709 |
|
| 1710 |
int rate2 = chip->eg_rate2; |
| 1711 |
if (rate2 & 64) |
| 1712 |
rate2 = 63; |
| 1713 |
|
| 1714 |
rate2 &= 63; |
| 1715 |
|
| 1716 |
static const int eg_stephi[4][4] = { |
| 1717 |
{ 0, 0, 0, 0 }, |
| 1718 |
{ 1, 0, 0, 0 }, |
| 1719 |
{ 1, 0, 1, 0 }, |
| 1720 |
{ 1, 1, 1, 0 } |
| 1721 |
}; |
| 1722 |
|
| 1723 |
chip->eg_inc2 = eg_stephi[rate2 & 3][chip->eg_timer_low_lock]; |
| 1724 |
chip->eg_ratenz = rate2 != 0; |
| 1725 |
chip->eg_rate12 = (rate2 & 60) == 48; |
| 1726 |
chip->eg_rate13 = (rate2 & 60) == 52; |
| 1727 |
chip->eg_rate14 = (rate2 & 60) == 56; |
| 1728 |
chip->eg_rate15 = (rate2 & 60) == 60; |
| 1729 |
chip->eg_maxrate[0] = (rate2 & 62) == 62; |
| 1730 |
chip->eg_rate_low = rate2 & 3; |
| 1731 |
chip->eg_rate_slow = (rate2 & 48) != 48; |
| 1732 |
|
| 1733 |
chip->eg_rate_sum = (chip->eg_shift_lock + (rate2 >> 2)) & 15; |
| 1734 |
|
| 1735 |
chip->eg_incsh0[1] = chip->eg_step[2] && chip->eg_incsh0[0]; |
| 1736 |
chip->eg_incsh1[1] = chip->eg_step[2] && chip->eg_incsh1[0]; |
| 1737 |
chip->eg_incsh2[1] = chip->eg_step[2] && chip->eg_incsh2[0]; |
| 1738 |
chip->eg_incsh3[1] = chip->eg_step[2] && chip->eg_incsh3[0]; |
| 1739 |
|
| 1740 |
chip->eg_kon_latch[1] = chip->eg_kon_latch[0]; |
| 1741 |
chip->eg_key[1] = chip->eg_key[0]; |
| 1742 |
|
| 1743 |
chip->eg_level_ssg[1] = chip->eg_level_ssg[0]; |
| 1744 |
|
| 1745 |
chip->eg_pg_reset[1] = chip->eg_pg_reset[0]; |
| 1746 |
|
| 1747 |
chip->eg_ssg_sign[1] = chip->eg_ssg_sign[0]; |
| 1748 |
|
| 1749 |
chip->eg_ssg_enable[1] = chip->eg_ssg_enable[0]; |
| 1750 |
chip->eg_ssg_dir[1] = chip->eg_ssg_dir[0]; |
| 1751 |
chip->eg_ssg_holdup[1] = chip->eg_ssg_holdup[0]; |
| 1752 |
chip->eg_ssg_pgreset[1] = chip->eg_ssg_pgreset[0]; |
| 1753 |
chip->eg_ssg_egrepeat[1] = chip->eg_ssg_egrepeat[0]; |
| 1754 |
|
| 1755 |
chip->eg_sl[0][1] = chip->eg_sl[0][0]; |
| 1756 |
chip->eg_sl[1][1] = chip->eg_sl[1][0]; |
| 1757 |
chip->eg_tl[0][1] = chip->eg_tl[0][0]; |
| 1758 |
chip->eg_tl[1][1] = chip->eg_tl[1][0]; |
| 1759 |
chip->eg_tl[2][1] = chip->eg_tl[2][0]; |
| 1760 |
|
| 1761 |
chip->eg_nextlevel[1] = chip->eg_nextlevel[0] + chip->eg_inc_total; |
| 1762 |
|
| 1763 |
chip->eg_kon_csm[1] = chip->eg_kon_csm[0]; |
| 1764 |
|
| 1765 |
int inv = ((chip->eg_level[0][20] ^ 1023) + 513) & 1023; |
| 1766 |
|
| 1767 |
chip->eg_output = chip->eg_ssg_inv ? inv : chip->eg_level[0][20]; |
| 1768 |
|
| 1769 |
chip->eg_level_l[1] = chip->eg_level_l[0]; |
| 1770 |
|
| 1771 |
|
| 1772 |
int nextstate = eg_state_attack; |
| 1773 |
|
| 1774 |
int eg_mute = !chip->eg_kon_event && chip->eg_off && (chip->eg_ssg_holdup[0] & 4) == 0 && chip->eg_state_l != eg_state_attack; |
| 1775 |
chip->eg_mute = eg_mute; |
| 1776 |
|
| 1777 |
if (eg_mute) |
| 1778 |
{ |
| 1779 |
nextstate |= eg_state_release; |
| 1780 |
} |
| 1781 |
|
| 1782 |
if (!chip->eg_kon_event && chip->eg_state_l == eg_state_sustain) |
| 1783 |
{ |
| 1784 |
nextstate |= eg_state_sustain; |
| 1785 |
} |
| 1786 |
|
| 1787 |
if (!chip->eg_kon_event && chip->eg_state_l == eg_state_decay && !chip->eg_slreach) |
| 1788 |
{ |
| 1789 |
nextstate |= eg_state_decay; |
| 1790 |
} |
| 1791 |
if (!chip->eg_kon_event && chip->eg_state_l == eg_state_decay && chip->eg_slreach) |
| 1792 |
{ |
| 1793 |
nextstate |= eg_state_sustain; |
| 1794 |
} |
| 1795 |
|
| 1796 |
if ((chip->eg_kon_latch[0] & 4) == 0 && !chip->eg_kon_event) |
| 1797 |
{ |
| 1798 |
nextstate |= eg_state_release; |
| 1799 |
} |
| 1800 |
if (!chip->eg_kon_event && chip->eg_state_l == eg_state_release) |
| 1801 |
{ |
| 1802 |
nextstate |= eg_state_release; |
| 1803 |
} |
| 1804 |
|
| 1805 |
if (!chip->eg_kon_event && chip->eg_state_l == eg_state_attack && chip->eg_zeroreach) |
| 1806 |
{ |
| 1807 |
nextstate |= eg_state_decay; |
| 1808 |
} |
| 1809 |
if (chip->eg_ic[0]) |
| 1810 |
{ |
| 1811 |
nextstate |= eg_state_release; |
| 1812 |
} |
| 1813 |
|
| 1814 |
chip->eg_nextstate = nextstate; |
| 1815 |
memcpy(&chip->eg_state[1][0], &chip->eg_state[0][0], 23 * sizeof(unsigned char)); |
| 1816 |
|
| 1817 |
chip->eg_exp = (chip->eg_kon_latch[0] & 4) != 0 && (chip->eg_state_l == eg_state_attack) && !chip->eg_maxrate[1] && !chip->eg_zeroreach; |
| 1818 |
chip->eg_linear = !chip->eg_kon_event && !chip->eg_off && (chip->eg_state_l == eg_state_sustain || chip->eg_state_l == eg_state_release); |
| 1819 |
chip->eg_linear |= !chip->eg_kon_event && !chip->eg_off && !chip->eg_slreach && chip->eg_state_l == eg_state_decay; |
| 1820 |
|
| 1821 |
chip->eg_istantattack = chip->eg_maxrate[1] && (!chip->eg_maxrate[1] || chip->eg_kon_event); |
| 1822 |
|
| 1823 |
memcpy(&chip->eg_level[1][0], &chip->eg_level[0][0], 22 * sizeof(unsigned short)); |
| 1824 |
|
| 1825 |
|
| 1826 |
chip->eg_am_l[1] = chip->eg_am_l[0]; |
| 1827 |
chip->eg_am_shift[1] = chip->eg_am_shift[0]; |
| 1828 |
|
| 1829 |
chip->eg_ch3_l[0] = (chip->eg_ch3_l[1] << 1) | chip->fsm_sel_ch3[1]; |
| 1830 |
|
| 1831 |
int levelsum = chip->eg_output_lfo + (chip->eg_csm_tl << 3); |
| 1832 |
|
| 1833 |
int eg_of = (levelsum & 1024) != 0; |
| 1834 |
|
| 1835 |
if (eg_of || chip->eg_of1) |
| 1836 |
levelsum = 1023; |
| 1837 |
|
| 1838 |
chip->eg_out = levelsum; |
| 1839 |
|
| 1840 |
chip->eg_dbg_sync = chip->fsm_sel2[1]; |
| 1841 |
|
| 1842 |
chip->eg_debug[1] = chip->eg_debug[0]; |
| 1843 |
} |
| 1844 |
} |
| 1845 |
|
| 1846 |
{ |
| 1847 |
if (chip->clk1) |
| 1848 |
{ |
| 1849 |
chip->op_phase1 = chip->pg_out; |
| 1850 |
chip->op_phase2 = chip->op_mod[1][5]; |
| 1851 |
|
| 1852 |
chip->op_sign[1] = chip->op_sign[0]; |
| 1853 |
static const int logsin[128] = { |
| 1854 |
0x6c3, 0x58b, 0x4e4, 0x471, 0x41a, 0x3d3, 0x398, 0x365, 0x339, 0x311, 0x2ed, 0x2cd, 0x2af, 0x293, 0x279, 0x261, |
| 1855 |
0x24b, 0x236, 0x222, 0x20f, 0x1fd, 0x1ec, 0x1dc, 0x1cd, 0x1be, 0x1b0, 0x1a2, 0x195, 0x188, 0x17c, 0x171, 0x166, |
| 1856 |
0x15b, 0x150, 0x146, 0x13c, 0x133, 0x129, 0x121, 0x118, 0x10f, 0x107, 0x0ff, 0x0f8, 0x0f0, 0x0e9, 0x0e2, 0x0db, |
| 1857 |
0x0d4, 0x0cd, 0x0c7, 0x0c1, 0x0bb, 0x0b5, 0x0af, 0x0a9, 0x0a4, 0x09f, 0x099, 0x094, 0x08f, 0x08a, 0x086, 0x081, |
| 1858 |
0x07d, 0x078, 0x074, 0x070, 0x06c, 0x068, 0x064, 0x060, 0x05c, 0x059, 0x055, 0x052, 0x04e, 0x04b, 0x048, 0x045, |
| 1859 |
0x042, 0x03f, 0x03c, 0x039, 0x037, 0x034, 0x031, 0x02f, 0x02d, 0x02a, 0x028, 0x026, 0x024, 0x022, 0x020, 0x01e, |
| 1860 |
0x01c, 0x01a, 0x018, 0x017, 0x015, 0x014, 0x012, 0x011, 0x00f, 0x00e, 0x00d, 0x00c, 0x00a, 0x009, 0x008, 0x007, |
| 1861 |
0x007, 0x006, 0x005, 0x004, 0x004, 0x003, 0x002, 0x002, 0x001, 0x001, 0x001, 0x001, 0x000, 0x000, 0x000, 0x000 |
| 1862 |
}; |
| 1863 |
static const int logsin_d[128] = { |
| 1864 |
0x196, 0x07c, 0x04a, 0x035, 0x029, 0x022, 0x01d, 0x019, 0x015, 0x013, 0x012, 0x00f, 0x00e, 0x00d, 0x00d, 0x00c, |
| 1865 |
0x00b, 0x00a, 0x00a, 0x009, 0x009, 0x009, 0x008, 0x007, 0x007, 0x007, 0x007, 0x006, 0x007, 0x006, 0x006, 0x005, |
| 1866 |
0x005, 0x005, 0x005, 0x005, 0x004, 0x005, 0x004, 0x004, 0x005, 0x004, 0x004, 0x003, 0x004, 0x003, 0x003, 0x003, |
| 1867 |
0x003, 0x004, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x002, 0x003, 0x003, 0x003, 0x003, 0x002, 0x002, |
| 1868 |
0x002, 0x002, 0x002, 0x002, 0x002, 0x002, 0x002, 0x002, 0x002, 0x002, 0x002, 0x001, 0x002, 0x002, 0x002, 0x001, |
| 1869 |
0x001, 0x001, 0x002, 0x002, 0x001, 0x001, 0x002, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, 0x001, |
| 1870 |
0x001, 0x001, 0x001, 0x000, 0x001, 0x000, 0x001, 0x000, 0x001, 0x001, 0x000, 0x000, 0x001, 0x001, 0x001, 0x001, |
| 1871 |
0x000, 0x000, 0x000, 0x001, 0x000, 0x000, 0x001, 0x000, 0x001, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000, 0x000 |
| 1872 |
}; |
| 1873 |
static const int pow[128] = { |
| 1874 |
0x3f5, 0x3ea, 0x3df, 0x3d4, 0x3c9, 0x3bf, 0x3b4, 0x3a9, 0x39f, 0x394, 0x38a, 0x37f, 0x375, 0x36a, 0x360, 0x356, |
| 1875 |
0x34c, 0x342, 0x338, 0x32e, 0x324, 0x31a, 0x310, 0x306, 0x2fd, 0x2f3, 0x2e9, 0x2e0, 0x2d6, 0x2cd, 0x2c4, 0x2ba, |
| 1876 |
0x2b1, 0x2a8, 0x29e, 0x295, 0x28c, 0x283, 0x27a, 0x271, 0x268, 0x25f, 0x257, 0x24e, 0x245, 0x23c, 0x234, 0x22b, |
| 1877 |
0x223, 0x21a, 0x212, 0x209, 0x201, 0x1f9, 0x1f0, 0x1e8, 0x1e0, 0x1d8, 0x1d0, 0x1c8, 0x1c0, 0x1b8, 0x1b0, 0x1a8, |
| 1878 |
0x1a0, 0x199, 0x191, 0x189, 0x181, 0x17a, 0x172, 0x16b, 0x163, 0x15c, 0x154, 0x14d, 0x146, 0x13e, 0x137, 0x130, |
| 1879 |
0x129, 0x122, 0x11b, 0x114, 0x10c, 0x106, 0x0ff, 0x0f8, 0x0f1, 0x0ea, 0x0e3, 0x0dc, 0x0d6, 0x0cf, 0x0c8, 0x0c2, |
| 1880 |
0x0bb, 0x0b5, 0x0ae, 0x0a8, 0x0a1, 0x09b, 0x094, 0x08e, 0x088, 0x082, 0x07b, 0x075, 0x06f, 0x069, 0x063, 0x05d, |
| 1881 |
0x057, 0x051, 0x04b, 0x045, 0x03f, 0x039, 0x033, 0x02d, 0x028, 0x022, 0x01c, 0x016, 0x011, 0x00b, 0x006, 0x000, |
| 1882 |
}; |
| 1883 |
static const int pow_d[128] = { |
| 1884 |
0x005, 0x005, 0x005, 0x006, 0x006, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x006, 0x005, 0x005, |
| 1885 |
0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x004, 0x005, |
| 1886 |
0x004, 0x004, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x005, 0x004, 0x004, 0x004, 0x005, 0x004, 0x005, |
| 1887 |
0x004, 0x004, 0x004, 0x005, 0x004, 0x004, 0x005, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, |
| 1888 |
0x004, 0x003, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x004, 0x003, 0x004, 0x004, 0x004, |
| 1889 |
0x003, 0x003, 0x003, 0x003, 0x004, 0x003, 0x003, 0x003, 0x003, 0x003, 0x004, 0x004, 0x003, 0x003, 0x004, 0x003, |
| 1890 |
0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x004, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, |
| 1891 |
0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x003, 0x002, 0x003, 0x003, 0x003, 0x003, 0x003, 0x002, 0x003, |
| 1892 |
}; |
| 1893 |
|
| 1894 |
chip->op_logsin_base = logsin[(chip->op_phase_index >> 1) & 127]; |
| 1895 |
chip->op_logsin_delta = (chip->op_phase_index & 1) != 0 ? 0 : logsin_d[(chip->op_phase_index >> 1) & 127]; |
| 1896 |
|
| 1897 |
chip->op_eglevel = chip->eg_out; |
| 1898 |
|
| 1899 |
chip->op_shift[0] = chip->op_att >> 8; |
| 1900 |
|
| 1901 |
chip->op_pow_base = pow[(chip->op_att >> 1) & 127]; |
| 1902 |
chip->op_pow_delta = (chip->op_att & 1) != 0 ? 0 : pow_d[(chip->op_att >> 1) & 127]; |
| 1903 |
|
| 1904 |
int output = chip->op_pow; |
| 1905 |
output = (output << 2) >> chip->op_shift[1]; |
| 1906 |
|
| 1907 |
if (chip->reg_test_21[1] & 16) |
| 1908 |
output ^= 1 << 13; |
| 1909 |
|
| 1910 |
if (chip->op_sign[0] & 4) |
| 1911 |
output ^= 0x3fff; |
| 1912 |
|
| 1913 |
chip->op_output[0] = output; |
| 1914 |
chip->op_output[2] = chip->op_output[1]; |
| 1915 |
|
| 1916 |
memcpy(&chip->op_op1_0[0][1], &chip->op_op1_0[1][0], 5 * sizeof(unsigned short)); |
| 1917 |
memcpy(&chip->op_op1_1[0][1], &chip->op_op1_1[1][0], 5 * sizeof(unsigned short)); |
| 1918 |
memcpy(&chip->op_op2[0][1], &chip->op_op2[1][0], 5 * sizeof(unsigned short)); |
| 1919 |
|
| 1920 |
chip->op_op1_0[0][0] = chip->op_loadfb ? chip->op_output[3] : chip->op_op1_0[1][5]; |
| 1921 |
chip->op_op1_1[0][0] = chip->op_loadfb ? chip->op_op1_0[1][5] : chip->op_op1_1[1][5]; |
| 1922 |
chip->op_op2[0][0] = chip->op_loadop2 ? chip->op_output[3] : chip->op_op2[1][5]; |
| 1923 |
|
| 1924 |
int mod1 = 0; |
| 1925 |
int mod2 = 0; |
| 1926 |
|
| 1927 |
if (chip->op_mod_op1_0) |
| 1928 |
{ |
| 1929 |
mod2 |= chip->op_op1_0[1][5]; |
| 1930 |
} |
| 1931 |
if (chip->op_mod_op1_1) |
| 1932 |
{ |
| 1933 |
mod1 |= chip->op_op1_1[1][5]; |
| 1934 |
} |
| 1935 |
if (chip->op_mod_op2) |
| 1936 |
{ |
| 1937 |
mod1 |= chip->op_op2[1][5]; |
| 1938 |
} |
| 1939 |
if (chip->op_mod_prev_0) |
| 1940 |
{ |
| 1941 |
mod2 |= chip->op_output[3]; |
| 1942 |
} |
| 1943 |
if (chip->op_mod_prev_1) |
| 1944 |
{ |
| 1945 |
mod1 |= chip->op_output[3]; |
| 1946 |
} |
| 1947 |
if (mod1 & (1 << 13)) |
| 1948 |
mod1 |= 1 << 14; |
| 1949 |
if (mod2 & (1 << 13)) |
| 1950 |
mod2 |= 1 << 14; |
| 1951 |
chip->op_mod1 = mod1; |
| 1952 |
chip->op_mod2 = mod2; |
| 1953 |
|
| 1954 |
int mod; |
| 1955 |
|
| 1956 |
if (chip->op_do_fb) |
| 1957 |
{ |
| 1958 |
if (!chip->op_fb) |
| 1959 |
mod = 0; |
| 1960 |
else |
| 1961 |
{ |
| 1962 |
mod = chip->op_mod_sum; |
| 1963 |
if (mod & (1 << 13)) |
| 1964 |
mod |= ~0x3fff; |
| 1965 |
|
| 1966 |
mod = mod >> (9 - chip->op_fb); |
| 1967 |
} |
| 1968 |
} |
| 1969 |
else |
| 1970 |
mod = chip->op_mod_sum; |
| 1971 |
|
| 1972 |
memcpy(&chip->op_mod[0][1], &chip->op_mod[1][0], 5 * sizeof(unsigned short)); |
| 1973 |
chip->op_mod[0][0] = mod; |
| 1974 |
} |
| 1975 |
if (chip->clk2) |
| 1976 |
{ |
| 1977 |
|
| 1978 |
int phase = chip->op_phase1 + chip->op_phase2; |
| 1979 |
|
| 1980 |
int phase2 = phase & 255; |
| 1981 |
if (phase & 256) |
| 1982 |
phase2 ^= 255; |
| 1983 |
|
| 1984 |
chip->op_phase_index = phase2; |
| 1985 |
|
| 1986 |
chip->op_sign[0] = chip->op_sign[1] << 1; |
| 1987 |
if (phase & 512) |
| 1988 |
chip->op_sign[0] |= 1; |
| 1989 |
|
| 1990 |
//chip->op_eglevel = 256; // |
| 1991 |
int level = chip->op_logsin_base + chip->op_logsin_delta + (chip->op_eglevel << 2); |
| 1992 |
if (level & 4096) |
| 1993 |
level = 4095; |
| 1994 |
chip->op_att = level; |
| 1995 |
|
| 1996 |
chip->op_shift[1] = chip->op_shift[0]; |
| 1997 |
|
| 1998 |
chip->op_pow = (chip->op_pow_base + chip->op_pow_delta) | 0x400; |
| 1999 |
|
| 2000 |
int output = chip->op_output[0]; |
| 2001 |
|
| 2002 |
if (chip->op_sign[1] & 4) |
| 2003 |
output++; |
| 2004 |
|
| 2005 |
chip->op_output[1] = output & 0x3fff; |
| 2006 |
chip->op_output[3] = chip->op_output[2]; |
| 2007 |
|
| 2008 |
chip->op_loadfb = chip->alg_load_fb; |
| 2009 |
chip->op_loadop2 = chip->alg_mod_op1_1_l; |
| 2010 |
chip->op_mod_op1_0 = chip->alg_mod_op1_0_l; |
| 2011 |
chip->op_mod_op1_1 = chip->alg_mod_op1_1_l; |
| 2012 |
chip->op_mod_op2 = chip->alg_mod_op2_l; |
| 2013 |
chip->op_mod_prev_0 = chip->alg_mod_prev_0_l; |
| 2014 |
chip->op_mod_prev_1 = chip->alg_mod_prev_1_l; |
| 2015 |
chip->op_do_fb = chip->alg_do_fb[1]; |
| 2016 |
|
| 2017 |
chip->op_fb = (chip->reg_connect_fb[0][0] >> 3) & 7; |
| 2018 |
|
| 2019 |
memcpy(&chip->op_op1_0[1][0], &chip->op_op1_0[0][0], 6 * sizeof(unsigned short)); |
| 2020 |
memcpy(&chip->op_op1_1[1][0], &chip->op_op1_1[0][0], 6 * sizeof(unsigned short)); |
| 2021 |
memcpy(&chip->op_op2[1][0], &chip->op_op2[0][0], 6 * sizeof(unsigned short)); |
| 2022 |
|
| 2023 |
int mod = (chip->op_mod1 + chip->op_mod2) >> 1; |
| 2024 |
mod &= 0x3fff; |
| 2025 |
chip->op_mod_sum = mod; |
| 2026 |
memcpy(&chip->op_mod[1][0], &chip->op_mod[0][0], 6 * sizeof(unsigned short)); |
| 2027 |
} |
| 2028 |
} |
| 2029 |
|
| 2030 |
#ifndef FMOPNA_YM2612 |
| 2031 |
{ |
| 2032 |
#ifdef FMOPNA_YM2608 |
| 2033 |
if (!chip->mclk2) |
| 2034 |
{ |
| 2035 |
int addr2d = chip->write2_en && ADDRESS_MATCH(0x2d); |
| 2036 |
int addr2e = chip->write2_en && ADDRESS_MATCH(0x2e); |
| 2037 |
int addr2f = chip->write2_en && ADDRESS_MATCH(0x2f); |
| 2038 |
chip->ssg_prescaler1[0] = (chip->ssg_prescaler1[1] && !addr2f) || addr2e; |
| 2039 |
chip->ssg_prescaler2[0] = (chip->ssg_prescaler2[1] && !addr2f) || addr2d || chip->ic; |
| 2040 |
} |
| 2041 |
else |
| 2042 |
{ |
| 2043 |
chip->ssg_prescaler1[1] = chip->ssg_prescaler1[0] && !chip->ic; |
| 2044 |
chip->ssg_prescaler2[1] = chip->ssg_prescaler2[0]; |
| 2045 |
} |
| 2046 |
#endif |
| 2047 |
if (!chip->mclk2) |
| 2048 |
{ |
| 2049 |
chip->ssg_div1[0] = !chip->ssg_div1[1]; |
| 2050 |
} |
| 2051 |
else |
| 2052 |
{ |
| 2053 |
chip->ssg_div1[1] = chip->ssg_div1[0]; |
| 2054 |
} |
| 2055 |
if (!chip->ssg_div1[0]) |
| 2056 |
{ |
| 2057 |
chip->ssg_div2[0] = !chip->ssg_div2[1]; |
| 2058 |
} |
| 2059 |
else |
| 2060 |
{ |
| 2061 |
chip->ssg_div2[1] = chip->ssg_div2[0]; |
| 2062 |
} |
| 2063 |
if (!chip->ssg_div2[0]) |
| 2064 |
{ |
| 2065 |
chip->ssg_div3[0] = !chip->ssg_div3[1]; |
| 2066 |
} |
| 2067 |
else |
| 2068 |
{ |
| 2069 |
chip->ssg_div3[1] = chip->ssg_div3[0]; |
| 2070 |
} |
| 2071 |
if (chip->ic_check2) |
| 2072 |
{ |
| 2073 |
chip->ssg_div1[0] = 0; |
| 2074 |
chip->ssg_div1[1] = 0; |
| 2075 |
chip->ssg_div2[0] = 0; |
| 2076 |
chip->ssg_div2[1] = 0; |
| 2077 |
chip->ssg_div3[0] = 0; |
| 2078 |
chip->ssg_div3[1] = 0; |
| 2079 |
} |
| 2080 |
|
| 2081 |
#ifdef FMOPNA_YM2608 |
| 2082 |
if (chip->ssg_prescaler2[1]) |
| 2083 |
{ |
| 2084 |
if (chip->ssg_prescaler1[1]) |
| 2085 |
{ |
| 2086 |
chip->ssg_clk = chip->ssg_div2[0]; |
| 2087 |
} |
| 2088 |
else |
| 2089 |
{ |
| 2090 |
chip->ssg_clk = chip->ssg_div3[0]; |
| 2091 |
} |
| 2092 |
} |
| 2093 |
else |
| 2094 |
chip->ssg_clk = chip->ssg_div1[0]; |
| 2095 |
#else |
| 2096 |
chip->ssg_clk = chip->ssg_div3[0]; |
| 2097 |
#endif |
| 2098 |
|
| 2099 |
chip->ssg_clk1 = !chip->ssg_clk; |
| 2100 |
chip->ssg_clk2 = chip->ssg_clk; |
| 2101 |
|
| 2102 |
if (chip->ic) |
| 2103 |
chip->ssg_ssg_addr = 0; |
| 2104 |
else if (chip->ssg_write0) |
| 2105 |
chip->ssg_ssg_addr = (chip->data_bus1 & 0xf0) == 0; |
| 2106 |
|
| 2107 |
if (chip->ic) |
| 2108 |
chip->ssg_address = 0; |
| 2109 |
else if (chip->ssg_write0 && (chip->data_bus1 & 0xe0) == 0) |
| 2110 |
chip->ssg_address = chip->data_bus1 & 0x1f; |
| 2111 |
|
| 2112 |
int ssg_access = chip->ssg_ssg_addr && (chip->ssg_write1 || chip->ssg_read1); |
| 2113 |
|
| 2114 |
if (chip->ssg_egtrig_rst) |
| 2115 |
chip->ssg_egtrig = 0; |
| 2116 |
|
| 2117 |
if (chip->ic) |
| 2118 |
{ |
| 2119 |
chip->ssg_freq_a[0] = chip->data_bus1 & 255; |
| 2120 |
chip->ssg_freq_a[1] = chip->data_bus1 & 15; |
| 2121 |
chip->ssg_freq_b[0] = chip->data_bus1 & 255; |
| 2122 |
chip->ssg_freq_b[1] = chip->data_bus1 & 15; |
| 2123 |
chip->ssg_freq_c[0] = chip->data_bus1 & 255; |
| 2124 |
chip->ssg_freq_c[1] = chip->data_bus1 & 15; |
| 2125 |
chip->ssg_noise = chip->data_bus1 & 31; |
| 2126 |
chip->ssg_mode = chip->data_bus1 & 255; |
| 2127 |
chip->ssg_level_a = chip->data_bus1 & 31; |
| 2128 |
chip->ssg_level_b = chip->data_bus1 & 31; |
| 2129 |
chip->ssg_level_c = chip->data_bus1 & 31; |
| 2130 |
chip->ssg_env[0] = chip->data_bus1 & 255; |
| 2131 |
chip->ssg_env[1] = chip->data_bus1 & 255; |
| 2132 |
chip->ssg_envmode = chip->data_bus1 & 15; |
| 2133 |
#ifdef FMOPNA_YM2608 |
| 2134 |
chip->o_gpio_a = chip->data_bus1 & 255; |
| 2135 |
chip->o_gpio_b = chip->data_bus1 & 255; |
| 2136 |
#endif |
| 2137 |
|
| 2138 |
chip->ssg_egtrig = 1; |
| 2139 |
} |
| 2140 |
else if (chip->ssg_ssg_addr && chip->ssg_write1) |
| 2141 |
{ |
| 2142 |
switch (chip->ssg_address) |
| 2143 |
{ |
| 2144 |
case 0x0: |
| 2145 |
chip->ssg_freq_a[0] = chip->data_bus1 & 255; |
| 2146 |
break; |
| 2147 |
case 0x1: |
| 2148 |
chip->ssg_freq_a[1] = chip->data_bus1 & 15; |
| 2149 |
break; |
| 2150 |
case 0x2: |
| 2151 |
chip->ssg_freq_b[0] = chip->data_bus1 & 255; |
| 2152 |
break; |
| 2153 |
case 0x3: |
| 2154 |
chip->ssg_freq_b[1] = chip->data_bus1 & 15; |
| 2155 |
break; |
| 2156 |
case 0x4: |
| 2157 |
chip->ssg_freq_c[0] = chip->data_bus1 & 255; |
| 2158 |
break; |
| 2159 |
case 0x5: |
| 2160 |
chip->ssg_freq_c[1] = chip->data_bus1 & 15; |
| 2161 |
break; |
| 2162 |
case 0x6: |
| 2163 |
chip->ssg_noise = chip->data_bus1 & 31; |
| 2164 |
break; |
| 2165 |
case 0x7: |
| 2166 |
chip->ssg_mode = chip->data_bus1 & 255; |
| 2167 |
break; |
| 2168 |
case 0x8: |
| 2169 |
chip->ssg_level_a = chip->data_bus1 & 31; |
| 2170 |
break; |
| 2171 |
case 0x9: |
| 2172 |
chip->ssg_level_b = chip->data_bus1 & 31; |
| 2173 |
break; |
| 2174 |
case 0xa: |
| 2175 |
chip->ssg_level_c = chip->data_bus1 & 31; |
| 2176 |
break; |
| 2177 |
case 0xb: |
| 2178 |
chip->ssg_env[0] = chip->data_bus1 & 255; |
| 2179 |
break; |
| 2180 |
case 0xc: |
| 2181 |
chip->ssg_env[1] = chip->data_bus1 & 255; |
| 2182 |
break; |
| 2183 |
case 0xd: |
| 2184 |
chip->ssg_envmode = chip->data_bus1 & 15; |
| 2185 |
chip->ssg_egtrig = 1; |
| 2186 |
break; |
| 2187 |
#ifdef FMOPNA_YM2608 |
| 2188 |
case 0xe: |
| 2189 |
chip->o_gpio_a = chip->data_bus1 & 255; |
| 2190 |
break; |
| 2191 |
case 0xf: |
| 2192 |
chip->o_gpio_b = chip->data_bus1 & 255; |
| 2193 |
break; |
| 2194 |
#endif |
| 2195 |
} |
| 2196 |
} |
| 2197 |
if (chip->ssg_ssg_addr && chip->ssg_read1) |
| 2198 |
{ |
| 2199 |
switch (chip->ssg_address) |
| 2200 |
{ |
| 2201 |
case 0x0: |
| 2202 |
chip->data_bus1 &= ~255; |
| 2203 |
chip->data_bus1 |= chip->ssg_freq_a[0] & 255; |
| 2204 |
break; |
| 2205 |
case 0x1: |
| 2206 |
chip->data_bus1 &= ~15; |
| 2207 |
chip->data_bus1 |= chip->ssg_freq_a[1] & 15; |
| 2208 |
break; |
| 2209 |
case 0x2: |
| 2210 |
chip->data_bus1 &= ~255; |
| 2211 |
chip->data_bus1 |= chip->ssg_freq_b[0] & 255; |
| 2212 |
break; |
| 2213 |
case 0x3: |
| 2214 |
chip->data_bus1 &= ~15; |
| 2215 |
chip->data_bus1 |= chip->ssg_freq_b[1] & 15; |
| 2216 |
break; |
| 2217 |
case 0x4: |
| 2218 |
chip->data_bus1 &= ~255; |
| 2219 |
chip->data_bus1 |= chip->ssg_freq_c[0] & 255; |
| 2220 |
break; |
| 2221 |
case 0x5: |
| 2222 |
chip->data_bus1 &= ~15; |
| 2223 |
chip->data_bus1 |= chip->ssg_freq_c[1] & 15; |
| 2224 |
break; |
| 2225 |
case 0x6: |
| 2226 |
chip->data_bus1 &= ~31; |
| 2227 |
chip->data_bus1 |= chip->ssg_noise & 31; |
| 2228 |
break; |
| 2229 |
case 0x7: |
| 2230 |
chip->data_bus1 &= ~255; |
| 2231 |
chip->data_bus1 |= chip->ssg_mode & 255; |
| 2232 |
break; |
| 2233 |
case 0x8: |
| 2234 |
chip->data_bus1 &= ~31; |
| 2235 |
chip->data_bus1 |= chip->ssg_level_a & 31; |
| 2236 |
break; |
| 2237 |
case 0x9: |
| 2238 |
chip->data_bus1 &= ~31; |
| 2239 |
chip->data_bus1 |= chip->ssg_level_b & 31; |
| 2240 |
break; |
| 2241 |
case 0xa: |
| 2242 |
chip->data_bus1 &= ~31; |
| 2243 |
chip->data_bus1 |= chip->ssg_level_c & 31; |
| 2244 |
break; |
| 2245 |
case 0xb: |
| 2246 |
chip->data_bus1 &= ~255; |
| 2247 |
chip->data_bus1 |= chip->ssg_env[0] & 255; |
| 2248 |
break; |
| 2249 |
case 0xc: |
| 2250 |
chip->data_bus1 &= ~255; |
| 2251 |
chip->data_bus1 |= chip->ssg_env[1] & 255; |
| 2252 |
break; |
| 2253 |
case 0xd: |
| 2254 |
chip->data_bus1 &= ~15; |
| 2255 |
chip->data_bus1 |= chip->ssg_envmode & 15; |
| 2256 |
break; |
| 2257 |
#ifdef FMOPNA_YM2608 |
| 2258 |
case 0xe: |
| 2259 |
chip->data_bus1 &= ~15; |
| 2260 |
chip->data_bus1 |= chip->input.gpio_a & 15; |
| 2261 |
break; |
| 2262 |
case 0xf: |
| 2263 |
chip->data_bus1 &= ~255; |
| 2264 |
chip->data_bus1 |= chip->input.gpio_b & 255; |
| 2265 |
break; |
| 2266 |
#endif |
| 2267 |
} |
| 2268 |
} |
| 2269 |
|
| 2270 |
if (chip->ssg_clk1) |
| 2271 |
{ |
| 2272 |
chip->ssg_envadd = (chip->ssg_eg_of[1] & 4) != 0 && (chip->ssg_sel[1] & 8) != 0; |
| 2273 |
chip->ssg_envcnt[1] = chip->ssg_hold[0] ? 31 : chip->ssg_envcnt[0]; |
| 2274 |
chip->ssg_dir[1] = chip->ssg_dir[0]; |
| 2275 |
chip->ssg_hold[1] = chip->ssg_hold[0]; |
| 2276 |
chip->ssg_t2[1] = chip->ssg_t2[0]; |
| 2277 |
|
| 2278 |
chip->ssg_egtrig_s = chip->ssg_egtrig; |
| 2279 |
|
| 2280 |
chip->ssg_eg_sel_l = (chip->ssg_sel[1] & 8) != 0; |
| 2281 |
|
| 2282 |
chip->ssg_sel[0] = chip->ssg_sel[1] << 1; |
| 2283 |
chip->ssg_sel[0] |= (chip->ssg_sel[1] & 7) == 0 && !chip->ic; |
| 2284 |
|
| 2285 |
chip->ssg_sel_freq = 0; |
| 2286 |
if (chip->ssg_sel[1] & 1) |
| 2287 |
chip->ssg_sel_freq |= (chip->ssg_freq_c[1] << 8) | chip->ssg_freq_c[0]; |
| 2288 |
if (chip->ssg_sel[1] & 2) |
| 2289 |
chip->ssg_sel_freq |= (chip->ssg_freq_b[1] << 8) | chip->ssg_freq_b[0]; |
| 2290 |
if (chip->ssg_sel[1] & 4) |
| 2291 |
chip->ssg_sel_freq |= (chip->ssg_freq_a[1] << 8) | chip->ssg_freq_a[0]; |
| 2292 |
if (chip->ssg_sel[1] & 8) |
| 2293 |
chip->ssg_sel_freq |= (chip->ssg_env[1] << 8) | chip->ssg_env[0]; |
| 2294 |
|
| 2295 |
int cnt = chip->ssg_freq_cnt[7] + 1; |
| 2296 |
int of = (cnt & 0x1000) != 0; |
| 2297 |
chip->ssg_freq_cnt[0] = cnt & 0xfff; |
| 2298 |
chip->ssg_freq_cnt[4] = chip->ssg_freq_cnt[3]; |
| 2299 |
chip->ssg_freq_cnt[6] = chip->ssg_freq_cnt[5]; |
| 2300 |
|
| 2301 |
chip->ssg_cnt_of[1] = chip->ssg_cnt_of[0]; |
| 2302 |
|
| 2303 |
if (chip->ssg_sel[1] & 8) |
| 2304 |
chip->ssg_sign_toggle = chip->ssg_cnt_of[0] & 7; |
| 2305 |
else |
| 2306 |
chip->ssg_sign_toggle = 0; |
| 2307 |
|
| 2308 |
chip->ssg_freq_cnt2[1] = chip->ssg_freq_cnt2[0]; |
| 2309 |
chip->ssg_freq_cnt2[3] = chip->ssg_freq_cnt2[2]; |
| 2310 |
chip->ssg_freq_cnt2[5] = chip->ssg_freq_cnt2[4]; |
| 2311 |
chip->ssg_freq_cnt2[7] = chip->ssg_freq_cnt2[6]; |
| 2312 |
|
| 2313 |
chip->ssg_sign[1] = chip->ssg_sign[0]; |
| 2314 |
|
| 2315 |
int cnt_of = !chip->ssg_cnt_reload && (chip->ssg_sel_freq_l - chip->ssg_cnt_of_l < chip->ssg_freq_cnt2[0]); |
| 2316 |
|
| 2317 |
chip->ssg_cnt2_add = (chip->ssg_sel[1] & 8) != 0 && of; |
| 2318 |
|
| 2319 |
chip->ssg_sel_eg_l[0] = (chip->ssg_sel[1] & 8) != 0; |
| 2320 |
|
| 2321 |
chip->ssg_eg_of[0] = (chip->ssg_eg_of[1] << 1) | cnt_of; |
| 2322 |
|
| 2323 |
int fr_rst = chip->ssg_ch_of || ((cnt_of || chip->ssg_cnt_reload) && chip->ssg_sel_eg_l[1]); |
| 2324 |
|
| 2325 |
chip->ssg_freq_cnt[2] = fr_rst ? 0 : chip->ssg_freq_cnt[1]; |
| 2326 |
|
| 2327 |
chip->ssg_fr_rst_l = fr_rst; |
| 2328 |
|
| 2329 |
chip->ssg_noise_add = (chip->ssg_sel[1] & 1) != 0; |
| 2330 |
|
| 2331 |
chip->ssg_noise_cnt[1] = chip->ssg_noise_cnt[0]; |
| 2332 |
|
| 2333 |
int noise_of = chip->ssg_noise <= (chip->ssg_noise_cnt[0] >> 1); |
| 2334 |
|
| 2335 |
chip->ssg_noise_of = noise_of && chip->ssg_noise_of_low; |
| 2336 |
|
| 2337 |
chip->ssg_test = chip->input.test; |
| 2338 |
|
| 2339 |
chip->ssg_noise_step = chip->ssg_noise_of || !chip->ssg_test; |
| 2340 |
} |
| 2341 |
if (chip->ssg_clk2) |
| 2342 |
{ |
| 2343 |
int sum = chip->ssg_envcnt[1] + chip->ssg_envadd; |
| 2344 |
int of = (sum & 32) != 0; |
| 2345 |
chip->ssg_envcnt[0] = chip->ssg_egtrig_s ? 0 : sum & 31; |
| 2346 |
|
| 2347 |
int dir = of && (chip->ssg_envmode & 2) != 0 && !chip->ssg_hold[1]; |
| 2348 |
chip->ssg_dir[0] = chip->ssg_egtrig_s ? 0 : chip->ssg_dir[1] ^ dir; |
| 2349 |
|
| 2350 |
chip->ssg_hold[0] = chip->ssg_egtrig_s ? 0 : chip->ssg_hold[1] || (of && (chip->ssg_envmode & 1) != 0); |
| 2351 |
|
| 2352 |
chip->ssg_t2[0] = chip->ssg_egtrig_s ? 0 : chip->ssg_t2[1] || of; |
| 2353 |
|
| 2354 |
chip->ssg_egtrig_rst = chip->ssg_egtrig_s && chip->ssg_eg_sel_l; |
| 2355 |
|
| 2356 |
|
| 2357 |
chip->ssg_sel[1] = chip->ssg_sel[0]; |
| 2358 |
|
| 2359 |
chip->ssg_freq_cnt[1] = chip->ssg_freq_cnt[0]; |
| 2360 |
chip->ssg_freq_cnt[3] = chip->ssg_freq_cnt[2]; |
| 2361 |
chip->ssg_freq_cnt[5] = chip->ssg_freq_cnt[4]; |
| 2362 |
chip->ssg_freq_cnt[7] = chip->ssg_freq_cnt[6]; |
| 2363 |
|
| 2364 |
int cnt_of = (chip->ssg_sel_freq & 0xfff) <= chip->ssg_freq_cnt[0]; |
| 2365 |
|
| 2366 |
chip->ssg_cnt_of_l = cnt_of; |
| 2367 |
chip->ssg_sel_freq_l = (chip->ssg_sel_freq >> 12) & 0xf; |
| 2368 |
|
| 2369 |
chip->ssg_cnt_of[0] = (chip->ssg_cnt_of[1] << 1) | cnt_of; |
| 2370 |
|
| 2371 |
if (chip->ic) |
| 2372 |
chip->ssg_sign[0] = 0; |
| 2373 |
else |
| 2374 |
chip->ssg_sign[0] = chip->ssg_sign[1] ^ chip->ssg_sign_toggle; |
| 2375 |
|
| 2376 |
int cnt = chip->ssg_freq_cnt2[7] + chip->ssg_cnt2_add; |
| 2377 |
chip->ssg_freq_cnt2[0] = cnt & 0xf; |
| 2378 |
chip->ssg_freq_cnt2[2] = chip->ssg_fr_rst_l ? 0 : chip->ssg_freq_cnt2[1]; |
| 2379 |
chip->ssg_freq_cnt2[4] = chip->ssg_freq_cnt2[3]; |
| 2380 |
chip->ssg_freq_cnt2[6] = chip->ssg_freq_cnt2[5]; |
| 2381 |
|
| 2382 |
chip->ssg_sel_eg_l[1] = chip->ssg_sel_eg_l[0]; |
| 2383 |
|
| 2384 |
chip->ssg_ch_of = (!chip->ssg_sel_eg_l[0] && cnt_of) || chip->ic; |
| 2385 |
|
| 2386 |
chip->ssg_cnt_reload = chip->ssg_sel_eg_l[0] && chip->ssg_egtrig_s; |
| 2387 |
|
| 2388 |
chip->ssg_eg_of[1] = chip->ssg_eg_of[0]; |
| 2389 |
|
| 2390 |
|
| 2391 |
chip->ssg_noise_cnt[0] = chip->ssg_noise_step ? 0 : ((chip->ssg_noise_cnt[1] + chip->ssg_noise_add) & 63); |
| 2392 |
|
| 2393 |
chip->ssg_noise_of_low = (chip->ssg_noise_cnt[1] & 1) != 0 && chip->ssg_noise_add; |
| 2394 |
|
| 2395 |
} |
| 2396 |
|
| 2397 |
if (!chip->ssg_noise_step) |
| 2398 |
{ |
| 2399 |
int bit = ((chip->ssg_noise_lfsr[1] >> 16) ^ (chip->ssg_noise_lfsr[1] >> 13)) & 1; |
| 2400 |
|
| 2401 |
if ((chip->ssg_noise_lfsr[1] & 0x1ffff) == 0) |
| 2402 |
bit |= 1; |
| 2403 |
|
| 2404 |
chip->ssg_noise_lfsr[0] = (chip->ssg_noise_lfsr[1] << 1) | bit; |
| 2405 |
} |
| 2406 |
else |
| 2407 |
{ |
| 2408 |
chip->ssg_noise_lfsr[1] = chip->ic ? 0 : chip->ssg_noise_lfsr[0]; |
| 2409 |
} |
| 2410 |
|
| 2411 |
if (chip->ssg_clk2) |
| 2412 |
chip->ssg_noise_bit = (chip->ssg_noise_lfsr[1] >> 16) & 1; |
| 2413 |
|
| 2414 |
int envlevel = chip->ssg_hold[0] ? 31 : chip->ssg_envcnt[0]; |
| 2415 |
envlevel = (chip->ssg_dir[0] ^ ((chip->ssg_envmode >> 2) & 1)) == 0 ? (envlevel ^ 31) : envlevel; |
| 2416 |
envlevel = (chip->ssg_t2[0] && (chip->ssg_envmode & 8) == 0) ? 0 : envlevel; |
| 2417 |
|
| 2418 |
int vol_a = (chip->ssg_level_a & 0x10) != 0 ? envlevel : (((chip->ssg_level_a & 15) << 1) | 1); |
| 2419 |
int vol_b = (chip->ssg_level_b & 0x10) != 0 ? envlevel : (((chip->ssg_level_b & 15) << 1) | 1); |
| 2420 |
int vol_c = (chip->ssg_level_c & 0x10) != 0 ? envlevel : (((chip->ssg_level_c & 15) << 1) | 1); |
| 2421 |
|
| 2422 |
int sign_a = ((chip->ssg_mode & 1) == 0 && (chip->ssg_sign[0] & 1) != 0) || ((chip->ssg_mode & 8) == 0 && chip->ssg_noise_bit); |
| 2423 |
int sign_b = ((chip->ssg_mode & 2) == 0 && (chip->ssg_sign[0] & 2) != 0) || ((chip->ssg_mode & 16) == 0 && chip->ssg_noise_bit); |
| 2424 |
int sign_c = ((chip->ssg_mode & 4) == 0 && (chip->ssg_sign[0] & 4) != 0) || ((chip->ssg_mode & 32) == 0 && chip->ssg_noise_bit); |
| 2425 |
|
| 2426 |
static const float volume_lut[32] = { |
| 2427 |
0.0000, 0.0000, 0.0049, 0.0075, 0.0105, 0.0131, 0.0156, 0.0183, |
| 2428 |
0.0228, 0.0276, 0.0321, 0.0367, 0.0448, 0.0535, 0.0626, 0.0713, |
| 2429 |
0.0884, 0.1057, 0.1225, 0.1392, 0.1691, 0.2013, 0.2348, 0.2670, |
| 2430 |
0.3307, 0.3951, 0.4573, 0.5196, 0.6316, 0.7528, 0.8787, 1.0000 |
| 2431 |
}; |
| 2432 |
|
| 2433 |
|
| 2434 |
// tildearrow: per-channel oscilloscope for SSG |
| 2435 |
chip->o_analog = 0; |
| 2436 |
chip->o_analog += chip->o_analog_ch[0] = volume_lut[sign_a ? 0 : vol_a]; |
| 2437 |
chip->o_analog += chip->o_analog_ch[1] = volume_lut[sign_b ? 0 : vol_b]; |
| 2438 |
chip->o_analog += chip->o_analog_ch[2] = volume_lut[sign_c ? 0 : vol_c]; |
| 2439 |
} |
| 2440 |
|
| 2441 |
{ |
| 2442 |
if (chip->mclk2) |
| 2443 |
{ |
| 2444 |
chip->rss_dclk_l = chip->dclk; |
| 2445 |
} |
| 2446 |
if (chip->clk2) |
| 2447 |
{ |
| 2448 |
chip->rss_cnt1_sync = !chip->fsm_rss2; |
| 2449 |
} |
| 2450 |
if (chip->aclk1) |
| 2451 |
{ |
| 2452 |
int cnt1_rst = chip->rss_cnt1[1] == 5 || chip->rss_cnt1_sync; |
| 2453 |
chip->rss_cnt1[0] = cnt1_rst ? 0 : (chip->rss_cnt1[1] + 1) & 7; |
| 2454 |
|
| 2455 |
chip->rss_eclk1_l = chip->rss_cnt1[1] == 2 || chip->rss_cnt1[1] == 3; |
| 2456 |
chip->rss_eclk2_l = chip->rss_cnt1[1] == 5 || chip->rss_cnt1[1] == 0; |
| 2457 |
chip->rss_fclk_sel[0] = chip->rss_cnt1[1] == 5 || chip->rss_cnt1[1] == 0 || chip->rss_cnt1[1] == 1; |
| 2458 |
} |
| 2459 |
|
| 2460 |
if (chip->aclk2) |
| 2461 |
{ |
| 2462 |
chip->rss_cnt1[1] = chip->rss_cnt1[0]; |
| 2463 |
|
| 2464 |
chip->rss_eclk1 = chip->rss_eclk1_l; |
| 2465 |
chip->rss_eclk2 = chip->rss_eclk2_l; |
| 2466 |
|
| 2467 |
chip->rss_fclk_sel[1] = chip->rss_fclk_sel[0]; |
| 2468 |
} |
| 2469 |
|
| 2470 |
chip->rss_fclk1 = !chip->rss_dclk_l && chip->aclk1 && chip->rss_fclk_sel[1]; |
| 2471 |
chip->rss_fclk2 = !chip->rss_dclk_l && chip->aclk2 && chip->rss_fclk_sel[1]; |
| 2472 |
|
| 2473 |
if (chip->clk1) |
| 2474 |
{ |
| 2475 |
int clk_rst = chip->rss_fmcnt_of || chip->rss_fmcnt_sync; |
| 2476 |
chip->rss_fmcnt[0] = clk_rst ? 0 : (chip->rss_fmcnt[1] + 1) & 15; |
| 2477 |
|
| 2478 |
#ifdef FMOPNA_YM2608 |
| 2479 |
chip->rss_tl_sel[0] = chip->write0_en ? chip->data_bus1 == 0x11 : chip->rss_tl_sel[1]; |
| 2480 |
#else |
| 2481 |
chip->rss_tl_sel[0] = chip->write0_en ? chip->data_bus1 == 0x101 : chip->rss_tl_sel[1]; |
| 2482 |
#endif |
| 2483 |
|
| 2484 |
if (chip->ic) |
| 2485 |
chip->rss_tl[0] = 0; |
| 2486 |
else |
| 2487 |
chip->rss_tl[0] = chip->rss_tl_sel[1] |
| 2488 |
#ifdef FMOPNA_YM2608 |
| 2489 |
&& (chip->data_bus1 & 0x100) == 0 |
| 2490 |
#else |
| 2491 |
&& (chip->data_bus1 & 0x100) != 0 |
| 2492 |
#endif |
| 2493 |
&& chip->write1_en ? chip->data_bus1 & 0x3f : chip->rss_tl[1]; |
| 2494 |
} |
| 2495 |
if (chip->clk2) |
| 2496 |
{ |
| 2497 |
chip->rss_fmcnt[1] = chip->rss_fmcnt[0]; |
| 2498 |
chip->rss_fmcnt_of = (chip->rss_fmcnt[0] & 11) == 11; |
| 2499 |
|
| 2500 |
chip->rss_fmcnt_sync = chip->fsm_sel23[1]; |
| 2501 |
|
| 2502 |
chip->rss_tl_sel[1] = chip->rss_tl_sel[0]; |
| 2503 |
|
| 2504 |
chip->rss_tl[1] = chip->rss_tl[0]; |
| 2505 |
} |
| 2506 |
|
| 2507 |
if (chip->rss_eclk1) |
| 2508 |
{ |
| 2509 |
int cnt2_rst = chip->ic || chip->rss_cnt2[1] == 5 || (chip->fsm_rss && chip->rss_cnt2[0] == 0); |
| 2510 |
chip->rss_cnt2[0] = cnt2_rst ? 0 : (chip->rss_cnt2[1] + 1) & 7; |
| 2511 |
} |
| 2512 |
if (chip->rss_eclk2) |
| 2513 |
{ |
| 2514 |
chip->rss_cnt2[1] = chip->rss_cnt2[0]; |
| 2515 |
} |
| 2516 |
|
| 2517 |
#ifdef FMOPNA_YM2610 |
| 2518 |
if (chip->clk1) |
| 2519 |
{ |
| 2520 |
if (chip->write0_en && (chip->data_bus1 & 0x3c) != 0) |
| 2521 |
{ |
| 2522 |
chip->rss_address[0] = chip->data_bus1; |
| 2523 |
} |
| 2524 |
else |
| 2525 |
{ |
| 2526 |
chip->rss_address[0] = chip->rss_address[1]; |
| 2527 |
} |
| 2528 |
|
| 2529 |
if (chip->rss_address_wr[1] && chip->write1_en) |
| 2530 |
{ |
| 2531 |
chip->rss_data[0] = chip->data_bus1 & 0xff; |
| 2532 |
} |
| 2533 |
else |
| 2534 |
{ |
| 2535 |
chip->rss_data[0] = chip->rss_data[1]; |
| 2536 |
} |
| 2537 |
|
| 2538 |
chip->rss_address_wr[0] = chip->write0_en ? (chip->data_bus1 & 0x3c) != 0 : chip->rss_address_wr[1]; |
| 2539 |
|
| 2540 |
chip->rss_data_wr[0] = (chip->write1_en && chip->rss_address_wr[1]) |
| 2541 |
|| (!chip->write0_en && chip->rss_data_wr[1]); |
| 2542 |
|
| 2543 |
memcpy(&chip->rss_reg_pan_tl[0][1], &chip->rss_reg_pan_tl[1][0], 5 * sizeof(unsigned char)); |
| 2544 |
memcpy(&chip->rss_reg_start_l[0][1], &chip->rss_reg_start_l[1][0], 5 * sizeof(unsigned char)); |
| 2545 |
memcpy(&chip->rss_reg_start_h[0][1], &chip->rss_reg_start_h[1][0], 5 * sizeof(unsigned char)); |
| 2546 |
memcpy(&chip->rss_reg_stop_l[0][1], &chip->rss_reg_stop_l[1][0], 5 * sizeof(unsigned char)); |
| 2547 |
memcpy(&chip->rss_reg_stop_h[0][1], &chip->rss_reg_stop_h[1][0], 5 * sizeof(unsigned char)); |
| 2548 |
|
| 2549 |
if (chip->ic) |
| 2550 |
{ |
| 2551 |
chip->rss_reg_pan_tl[0][0] = 0; |
| 2552 |
chip->rss_reg_start_l[0][0] = 0; |
| 2553 |
chip->rss_reg_start_h[0][0] = 0; |
| 2554 |
chip->rss_reg_stop_l[0][0] = 0; |
| 2555 |
chip->rss_reg_stop_h[0][0] = 0; |
| 2556 |
} |
| 2557 |
else |
| 2558 |
{ |
| 2559 |
if (chip->rss_write08) |
| 2560 |
{ |
| 2561 |
chip->rss_reg_pan_tl[0][0] = chip->rss_data[1] & 0xdf; |
| 2562 |
} |
| 2563 |
else |
| 2564 |
{ |
| 2565 |
chip->rss_reg_pan_tl[0][0] = chip->rss_reg_pan_tl[1][5]; |
| 2566 |
} |
| 2567 |
if (chip->rss_write10) |
| 2568 |
{ |
| 2569 |
chip->rss_reg_start_l[0][0] = chip->rss_data[1]; |
| 2570 |
} |
| 2571 |
else |
| 2572 |
{ |
| 2573 |
chip->rss_reg_start_l[0][0] = chip->rss_reg_start_l[1][5]; |
| 2574 |
} |
| 2575 |
if (chip->rss_write18) |
| 2576 |
{ |
| 2577 |
chip->rss_reg_start_h[0][0] = chip->rss_data[1]; |
| 2578 |
} |
| 2579 |
else |
| 2580 |
{ |
| 2581 |
chip->rss_reg_start_h[0][0] = chip->rss_reg_start_h[1][5]; |
| 2582 |
} |
| 2583 |
if (chip->rss_write20) |
| 2584 |
{ |
| 2585 |
chip->rss_reg_stop_l[0][0] = chip->rss_data[1]; |
| 2586 |
} |
| 2587 |
else |
| 2588 |
{ |
| 2589 |
chip->rss_reg_stop_l[0][0] = chip->rss_reg_stop_l[1][5]; |
| 2590 |
} |
| 2591 |
if (chip->rss_write28) |
| 2592 |
{ |
| 2593 |
chip->rss_reg_stop_h[0][0] = chip->rss_data[1] & 0xf; |
| 2594 |
} |
| 2595 |
else |
| 2596 |
{ |
| 2597 |
chip->rss_reg_stop_h[0][0] = chip->rss_reg_stop_h[1][5]; |
| 2598 |
} |
| 2599 |
} |
| 2600 |
} |
| 2601 |
if (chip->clk2) |
| 2602 |
{ |
| 2603 |
if (chip->ic) |
| 2604 |
{ |
| 2605 |
chip->rss_address[1] = 0; |
| 2606 |
chip->rss_data[1] = 0; |
| 2607 |
} |
| 2608 |
else |
| 2609 |
{ |
| 2610 |
chip->rss_address[1] = chip->rss_address[0]; |
| 2611 |
chip->rss_data[1] = chip->rss_data[0]; |
| 2612 |
} |
| 2613 |
chip->rss_address_wr[1] = chip->rss_address_wr[0]; |
| 2614 |
chip->rss_data_wr[1] = chip->rss_data_wr[0]; |
| 2615 |
|
| 2616 |
int addr_match = (chip->rss_fmcnt[0] == (chip->rss_address[0] & 7) && (chip->rss_address[0] & 6) != 6) |
| 2617 |
&& chip->rss_data_wr[0] && (chip->rss_address[0] & 0x100) != 0; |
| 2618 |
|
| 2619 |
chip->rss_write08 = addr_match && (chip->rss_address[0] & 0xf8) == 0x08; |
| 2620 |
chip->rss_write10 = addr_match && (chip->rss_address[0] & 0xf8) == 0x10; |
| 2621 |
chip->rss_write18 = addr_match && (chip->rss_address[0] & 0xf8) == 0x18; |
| 2622 |
chip->rss_write20 = addr_match && (chip->rss_address[0] & 0xf8) == 0x20; |
| 2623 |
chip->rss_write28 = addr_match && (chip->rss_address[0] & 0xf8) == 0x28; |
| 2624 |
memcpy(&chip->rss_reg_pan_tl[1][0], &chip->rss_reg_pan_tl[0][0], 6 * sizeof(unsigned char)); |
| 2625 |
memcpy(&chip->rss_reg_start_l[1][0], &chip->rss_reg_start_l[0][0], 6 * sizeof(unsigned char)); |
| 2626 |
memcpy(&chip->rss_reg_start_h[1][0], &chip->rss_reg_start_h[0][0], 6 * sizeof(unsigned char)); |
| 2627 |
memcpy(&chip->rss_reg_stop_l[1][0], &chip->rss_reg_stop_l[0][0], 6 * sizeof(unsigned char)); |
| 2628 |
memcpy(&chip->rss_reg_stop_h[1][0], &chip->rss_reg_stop_h[0][0], 6 * sizeof(unsigned char)); |
| 2629 |
} |
| 2630 |
#endif |
| 2631 |
|
| 2632 |
int rss_fm_match = chip->rss_fmcnt[1] == chip->rss_cnt2[1]; |
| 2633 |
|
| 2634 |
#ifdef FMOPNA_YM2608 |
| 2635 |
if (chip->clk1 && rss_fm_match) |
| 2636 |
{ |
| 2637 |
chip->rss_params[0] = chip->reg_rss[1][5]; |
| 2638 |
} |
| 2639 |
if (chip->rss_cnt1[1] == 3) |
| 2640 |
{ |
| 2641 |
chip->rss_params[1] = chip->rss_params[0]; |
| 2642 |
} |
| 2643 |
#endif |
| 2644 |
#ifdef FMOPNA_YM2610 |
| 2645 |
if (chip->clk1) |
| 2646 |
chip->rss_fm_match_l = rss_fm_match; |
| 2647 |
if (rss_fm_match && !chip->rss_fm_match_l) |
| 2648 |
{ |
| 2649 |
chip->rss_params[0] = chip->rss_reg_pan_tl[1][5]; |
| 2650 |
chip->rss_params_start[0] = chip->rss_reg_start_l[1][4] | (chip->rss_reg_start_h[1][4] << 8); |
| 2651 |
chip->rss_params_stop[0] = chip->rss_reg_stop_l[1][4] | (chip->rss_reg_stop_h[1][4] << 8); |
| 2652 |
} |
| 2653 |
if (chip->rss_cnt1[1] == 1) |
| 2654 |
{ |
| 2655 |
chip->rss_params_start_h = (chip->rss_params_start[2] >> 12) & 15; |
| 2656 |
} |
| 2657 |
if (chip->rss_cnt1[1] == 3) |
| 2658 |
{ |
| 2659 |
chip->rss_params[1] = chip->rss_params[0]; |
| 2660 |
chip->rss_params_start[1] = chip->rss_params_start[0]; |
| 2661 |
chip->rss_params_stop[1] = chip->rss_params_stop[0]; |
| 2662 |
} |
| 2663 |
if (chip->rss_cnt1[1] == 5) |
| 2664 |
{ |
| 2665 |
chip->rss_params_stop[2] = chip->rss_params_stop[1]; |
| 2666 |
chip->rss_params_start[2] = chip->rss_params_start[1] & 0xfff; |
| 2667 |
} |
| 2668 |
#endif |
| 2669 |
if (chip->rss_cnt1[1] == 3) |
| 2670 |
{ |
| 2671 |
chip->rss_tl_l = chip->rss_tl[1]; |
| 2672 |
|
| 2673 |
chip->rss_tl_shift[1] = chip->rss_tl_shift[0]; |
| 2674 |
} |
| 2675 |
int tl = (((chip->rss_params[1] & 0x1f) | 0x20) + chip->rss_tl_l + 1) ^ 63; |
| 2676 |
int key = (chip->rss_key[1] & 0x20) != 0; |
| 2677 |
if ((tl & 64) == 0 || !key) |
| 2678 |
tl = 63; |
| 2679 |
else |
| 2680 |
tl &= 63; |
| 2681 |
if (chip->rss_cnt1[1] == 5) |
| 2682 |
{ |
| 2683 |
chip->rss_tl_shift[0] = (tl >> 3); |
| 2684 |
chip->rss_tl_shift[2] = chip->rss_tl_shift[1]; |
| 2685 |
} |
| 2686 |
|
| 2687 |
int dbg_load = ((chip->reg_test_12[1] & 16) != 0 && chip->rss_cnt1[1] == 5) |
| 2688 |
|| ((chip->reg_test_12[1] & 8) != 0 && chip->rss_cnt1[1] == 1); |
| 2689 |
|
| 2690 |
if (chip->aclk1) |
| 2691 |
{ |
| 2692 |
int load = chip->rss_cnt1[1] == 5 && tl != 63; |
| 2693 |
chip->rss_multi_ctrl[0] = chip->rss_multi_ctrl[1] >> 1; |
| 2694 |
if (load) |
| 2695 |
{ |
| 2696 |
chip->rss_multi_ctrl[0] |= (15 - (tl & 7)) << 1; |
| 2697 |
} |
| 2698 |
|
| 2699 |
chip->rss_sample_load = chip->rss_cnt1[1] == 5; |
| 2700 |
chip->rss_sample_shift_load = chip->rss_cnt1[1] == 0; |
| 2701 |
|
| 2702 |
int add1 = 0; |
| 2703 |
if (chip->rss_multi_ctrl[1] & 1) |
| 2704 |
{ |
| 2705 |
add1 = chip->rss_sample; |
| 2706 |
if (add1 & 0x800) |
| 2707 |
add1 |= 0x1000; |
| 2708 |
} |
| 2709 |
int add2 = 0; |
| 2710 |
if (chip->rss_cnt1[1] != 5) |
| 2711 |
{ |
| 2712 |
add2 = chip->rss_multi_accum[1] >> 1; |
| 2713 |
if (add2 & 0x800) |
| 2714 |
add2 |= 0x1000; |
| 2715 |
} |
| 2716 |
chip->rss_multi_accum[0] = (add1 + add2) & 0x1fff; |
| 2717 |
|
| 2718 |
chip->rss_dbg_load = dbg_load; |
| 2719 |
} |
| 2720 |
if (chip->aclk2) |
| 2721 |
{ |
| 2722 |
chip->rss_multi_ctrl[1] = chip->rss_multi_ctrl[0]; |
| 2723 |
|
| 2724 |
chip->rss_multi_accum[1] = chip->rss_multi_accum[0]; |
| 2725 |
} |
| 2726 |
|
| 2727 |
if (chip->rss_cnt1[1] == 5 && !chip->rss_sample_load) |
| 2728 |
{ |
| 2729 |
chip->rss_sample = chip->rss_regs[1][16] & 0xfff; |
| 2730 |
|
| 2731 |
chip->rss_multi_accum_load = chip->rss_multi_accum[1]; |
| 2732 |
} |
| 2733 |
|
| 2734 |
if (chip->rss_cnt1[1] == 0 && !chip->rss_sample_shift_load) |
| 2735 |
{ |
| 2736 |
int sample = chip->rss_multi_accum_load; |
| 2737 |
if (sample & 0x1000) |
| 2738 |
sample |= ~0x1fff; |
| 2739 |
chip->rss_sample_shift = sample >> chip->rss_tl_shift[2]; |
| 2740 |
} |
| 2741 |
|
| 2742 |
if (dbg_load && !chip->rss_dbg_load) |
| 2743 |
{ |
| 2744 |
#ifdef FMOPNA_YM2608 |
| 2745 |
chip->rss_dbg_data = chip->rss_regs[1][16] | (chip->rss_isend << 15); |
| 2746 |
#else |
| 2747 |
chip->rss_dbg_data = chip->rss_regs[1][16] & 0xfff; |
| 2748 |
#endif |
| 2749 |
} |
| 2750 |
|
| 2751 |
|
| 2752 |
if (chip->rss_eclk1) |
| 2753 |
{ |
| 2754 |
chip->write3_trig1 = chip->write3_trig0; |
| 2755 |
chip->write3_l[1] = chip->write3_l[0]; |
| 2756 |
} |
| 2757 |
if (chip->rss_eclk2) |
| 2758 |
{ |
| 2759 |
chip->write3_l[0] = chip->write3_trig1; |
| 2760 |
chip->write3_l[2] = chip->write3_l[1]; |
| 2761 |
} |
| 2762 |
chip->write3_en = chip->write3_l[0] && !chip->write3_l[2]; |
| 2763 |
|
| 2764 |
if (chip->rss_eclk1) |
| 2765 |
{ |
| 2766 |
if (chip->ic) |
| 2767 |
{ |
| 2768 |
chip->rss_keydm[0] = 0; |
| 2769 |
chip->rss_keymask[0] = 0; |
| 2770 |
} |
| 2771 |
else |
| 2772 |
{ |
| 2773 |
#ifdef FMOPNA_YM2608 |
| 2774 |
int key_write = chip->write3_en && chip->addr_10[1] && (chip->data_bus1 & 0x100) == 0; |
| 2775 |
#else |
| 2776 |
int key_write = chip->write3_en && chip->addr_00[1] && (chip->data_bus1 & 0x100) != 0; |
| 2777 |
#endif |
| 2778 |
if (key_write) |
| 2779 |
{ |
| 2780 |
chip->rss_keydm[0] = (chip->data_bus1 & 0x80) != 0; |
| 2781 |
chip->rss_keymask[0] = chip->data_bus1 & 0x3f; |
| 2782 |
} |
| 2783 |
else |
| 2784 |
{ |
| 2785 |
chip->rss_keydm[0] = chip->rss_keydm[1]; |
| 2786 |
chip->rss_keymask[0] = chip->rss_keymask[1]; |
| 2787 |
} |
| 2788 |
} |
| 2789 |
|
| 2790 |
int mask = chip->rss_keymask[1] & (1 << chip->rss_cnt2[1]); |
| 2791 |
|
| 2792 |
int key_event = mask != 0; |
| 2793 |
|
| 2794 |
chip->rss_keymask[0] &= ~mask; |
| 2795 |
|
| 2796 |
int kon_event = key_event && !chip->rss_keydm[1]; |
| 2797 |
int koff_event = key_event && chip->rss_keydm[1]; |
| 2798 |
|
| 2799 |
chip->rss_ic[0] = (chip->rss_ic[1] << 1) | chip->ic; |
| 2800 |
|
| 2801 |
int ic = chip->ic || (chip->rss_ic[1] & 0x3f) != 0; |
| 2802 |
|
| 2803 |
int key = (chip->rss_key[1] & 0x20) != 0; |
| 2804 |
|
| 2805 |
int key_next = !ic && !koff_event && (key || kon_event); |
| 2806 |
|
| 2807 |
chip->rss_key[0] = (chip->rss_key[1] << 1) | key_next; |
| 2808 |
|
| 2809 |
int stop = (chip->rss_stop[1] & 0x20) != 0; |
| 2810 |
|
| 2811 |
int eos = chip->rss_eos_l && !(chip->reg_test_12[1] & 16); |
| 2812 |
|
| 2813 |
int stop_next = !kon_event && (stop || ic || koff_event || eos); |
| 2814 |
|
| 2815 |
chip->rss_stop[0] = (chip->rss_stop[1] << 1) | stop_next; |
| 2816 |
|
| 2817 |
|
| 2818 |
#ifdef FMOPNA_YM2610 |
| 2819 |
|
| 2820 |
chip->rss_stop_flag[0] = 0; |
| 2821 |
if (!stop && eos) |
| 2822 |
chip->rss_stop_flag[0] |= 1 << chip->rss_cnt2[1]; |
| 2823 |
#endif |
| 2824 |
|
| 2825 |
} |
| 2826 |
if (chip->rss_eclk2) |
| 2827 |
{ |
| 2828 |
chip->rss_keydm[1] = chip->rss_keydm[0]; |
| 2829 |
chip->rss_keymask[1] = chip->rss_keymask[0]; |
| 2830 |
|
| 2831 |
chip->rss_ic[1] = chip->rss_ic[0]; |
| 2832 |
|
| 2833 |
chip->rss_key[1] = chip->rss_key[0]; |
| 2834 |
|
| 2835 |
chip->rss_stop[1] = chip->rss_stop[0]; |
| 2836 |
#ifdef FMOPNA_YM2610 |
| 2837 |
chip->rss_stop_flag[1] = chip->rss_stop_flag[0]; |
| 2838 |
#endif |
| 2839 |
} |
| 2840 |
|
| 2841 |
#ifdef FMOPNA_YM2608 |
| 2842 |
if (chip->rss_cnt1[1] == 0) |
| 2843 |
{ |
| 2844 |
chip->rss_eos_l = chip->rss_isend; |
| 2845 |
chip->rss_step = (chip->rss_ix & 1) == 0; |
| 2846 |
} |
| 2847 |
#endif |
| 2848 |
#ifdef FMOPNA_YM2610 |
| 2849 |
if (chip->aclk1) |
| 2850 |
chip->rss_eos_load = chip->rss_cnt1[1] == 0; |
| 2851 |
if (chip->rss_cnt1[1] == 0 && !chip->rss_eos_load) |
| 2852 |
{ |
| 2853 |
chip->rss_eos_l = (chip->rss_ix >> 1) == ((chip->rss_params_stop[2] << 8) | 0xff); |
| 2854 |
|
| 2855 |
chip->rss_nibble = chip->rss_rad_bus; |
| 2856 |
|
| 2857 |
if (chip->rss_ix & 1) |
| 2858 |
chip->rss_nibble &= 15; |
| 2859 |
else |
| 2860 |
chip->rss_nibble >>= 4; |
| 2861 |
} |
| 2862 |
#endif |
| 2863 |
|
| 2864 |
static const int rss_delta[64] = { |
| 2865 |
16, 17, 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, 50, 55, 60, 66, |
| 2866 |
73, 80, 88, 97, 107, 118, 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, |
| 2867 |
337, 371, 408, 449, 494, 544, 598, 658, 724, 796, 876, 963, 1060, 1166, 1282, 1411, |
| 2868 |
1552, 1552, 1552, 1552, 1552, 1552, 1552, 1552, 1552, 1552, 1552, 1552, 1552, 1552, 1552, 1552 |
| 2869 |
}; |
| 2870 |
|
| 2871 |
static const int rss_adjust[8] = { |
| 2872 |
63, 63, 63, 63, 2, 5, 7, 9 |
| 2873 |
}; |
| 2874 |
|
| 2875 |
#ifdef FMOPNA_YM2608 |
| 2876 |
static const int rss_start[8] = { |
| 2877 |
0, 0x1c0, 0x440, 0x1b80, 0x1d00, 0x1f80, 0, 0 |
| 2878 |
}; |
| 2879 |
#endif |
| 2880 |
|
| 2881 |
{ |
| 2882 |
|
| 2883 |
if (chip->aclk1) |
| 2884 |
{ |
| 2885 |
|
| 2886 |
int mask = chip->rss_keymask[1] & (1 << chip->rss_cnt2[1]); |
| 2887 |
|
| 2888 |
int key_event = mask != 0; |
| 2889 |
|
| 2890 |
int kon_event = key_event && !chip->rss_keydm[1]; |
| 2891 |
int koff_event = key_event && chip->rss_keydm[1]; |
| 2892 |
|
| 2893 |
int eos = chip->rss_eos_l && !(chip->reg_test_12[1] & 16); |
| 2894 |
|
| 2895 |
int stop = (chip->rss_stop[1] & 0x20) != 0; |
| 2896 |
|
| 2897 |
int nibble = chip->rss_nibble; |
| 2898 |
|
| 2899 |
int adjust = rss_adjust[chip->rss_nibble & 7]; |
| 2900 |
|
| 2901 |
if (chip->reg_test_12[1] & 16) |
| 2902 |
{ |
| 2903 |
nibble = 4; |
| 2904 |
adjust = 1; |
| 2905 |
} |
| 2906 |
|
| 2907 |
int c5 = chip->rss_cnt1[1] == 2; |
| 2908 |
int c6 = chip->rss_cnt1[1] == 3 || chip->rss_cnt1[1] == 4; |
| 2909 |
int c8 = (!kon_event && chip->rss_cnt1[1] == 0) || (!kon_event && chip->rss_cnt1[1] == 1) |
| 2910 |
|| (chip->rss_cnt1[1] == 5 && !eos && !kon_event && !(chip->reg_test_12[1] & 16)); |
| 2911 |
|
| 2912 |
int c0 = !kon_event && !eos && (nibble & 8) != 0 && chip->rss_cnt1[1] == 5 |
| 2913 |
#ifdef FMOPNA_YM2608 |
| 2914 |
&& chip->rss_step |
| 2915 |
#endif |
| 2916 |
; |
| 2917 |
int c1 = !kon_event && !eos && (nibble & 8) == 0 && chip->rss_cnt1[1] == 5 |
| 2918 |
#ifdef FMOPNA_YM2608 |
| 2919 |
&& chip->rss_step |
| 2920 |
#endif |
| 2921 |
; |
| 2922 |
int c2 = !kon_event && chip->rss_cnt1[1] == 1 |
| 2923 |
#ifdef FMOPNA_YM2608 |
| 2924 |
&& chip->rss_step |
| 2925 |
#endif |
| 2926 |
; |
| 2927 |
int c3 = kon_event && chip->rss_cnt1[1] == 0; |
| 2928 |
int c4 = !kon_event && !eos && !stop && chip->rss_cnt1[1] == 0; |
| 2929 |
int c7 = (chip->rss_cnt1[1] == 2 && (nibble & 1) != 0) || (chip->rss_cnt1[1] == 3 && (nibble & 2) != 0) |
| 2930 |
|| (chip->rss_cnt1[1] == 4 && (nibble & 4) != 0); |
| 2931 |
|
| 2932 |
int delta = rss_delta[chip->rss_delta_ix]; |
| 2933 |
|
| 2934 |
// c5 c6 c8 |
| 2935 |
// c0 c1 c2 c3 c4 c7 |
| 2936 |
|
| 2937 |
int carry = c4 || c0; |
| 2938 |
int add1 = 0; |
| 2939 |
int add2 = 0; |
| 2940 |
if (c7) |
| 2941 |
{ |
| 2942 |
add1 |= delta; |
| 2943 |
} |
| 2944 |
if (c1) |
| 2945 |
{ |
| 2946 |
add1 |= chip->rss_accum[1] & 0xfff; |
| 2947 |
} |
| 2948 |
if (c0) |
| 2949 |
{ |
| 2950 |
add1 |= (chip->rss_accum[1] & 0xfff) ^ 0xfff; |
| 2951 |
} |
| 2952 |
if (c2) |
| 2953 |
{ |
| 2954 |
add1 |= adjust; |
| 2955 |
} |
| 2956 |
if (c3) |
| 2957 |
{ |
| 2958 |
#ifdef FMOPNA_YM2608 |
| 2959 |
add1 |= rss_start[chip->rss_cnt2[1]] << 2; |
| 2960 |
#else |
| 2961 |
add1 |= (chip->rss_params_start[2] & 0xfff) << 9; |
| 2962 |
#endif |
| 2963 |
} |
| 2964 |
#ifdef FMOPNA_YM2608 |
| 2965 |
if (c4) |
| 2966 |
{ |
| 2967 |
if (chip->rss_cnt2[1] == 0 || chip->rss_cnt2[1] == 1 || chip->rss_cnt2[1] == 2 || chip->rss_cnt2[1] == 3) |
| 2968 |
add1 |= 1; |
| 2969 |
} |
| 2970 |
#endif |
| 2971 |
|
| 2972 |
if (c8) |
| 2973 |
{ |
| 2974 |
add2 |= chip->rss_regs[1][16]; |
| 2975 |
} |
| 2976 |
if (c6) |
| 2977 |
{ |
| 2978 |
add2 |= (chip->rss_accum[1] >> 1) & 0x7ff; |
| 2979 |
} |
| 2980 |
if (c5) |
| 2981 |
{ |
| 2982 |
add2 |= delta >> 1; |
| 2983 |
} |
| 2984 |
|
| 2985 |
#ifdef FMOPNA_YM2608 |
| 2986 |
chip->rss_accum[0] = (add1 + add2 + carry) & 0x7fff; |
| 2987 |
#else |
| 2988 |
chip->rss_accum[0] = (add1 + add2 + carry) & 0x1fffff; |
| 2989 |
#endif |
| 2990 |
|
| 2991 |
chip->rss_delta_ix_load = chip->rss_cnt1[1] == 5; |
| 2992 |
chip->rss_ix_load = chip->rss_cnt1[1] == 1; |
| 2993 |
|
| 2994 |
chip->rss_cnt1_is1 = chip->rss_cnt1[1] == 1; |
| 2995 |
} |
| 2996 |
if (chip->aclk2) |
| 2997 |
{ |
| 2998 |
chip->rss_accum[1] = chip->rss_accum[0]; |
| 2999 |
if (chip->rss_cnt1_is1) |
| 3000 |
{ |
| 3001 |
if ((chip->rss_accum[0] & 0x3f) == 0x3f) |
| 3002 |
chip->rss_accum[1] &= ~0x3f; |
| 3003 |
if ((chip->rss_accum[0] & 0x38) == 0x30 || (chip->rss_accum[0] & 0x3c) == 0x38) |
| 3004 |
chip->rss_accum[1] &= ~0xf; |
| 3005 |
} |
| 3006 |
} |
| 3007 |
|
| 3008 |
if (chip->rss_cnt1[1] == 5 && !chip->rss_delta_ix_load) |
| 3009 |
{ |
| 3010 |
chip->rss_delta_ix = chip->rss_regs[1][14] & 63; |
| 3011 |
} |
| 3012 |
|
| 3013 |
#ifdef FMOPNA_YM2608 |
| 3014 |
if (chip->rss_cnt1[1] == 1 && !chip->rss_ix_load) |
| 3015 |
{ |
| 3016 |
chip->rss_ix = chip->rss_regs[1][14] & 0x7fff; |
| 3017 |
|
| 3018 |
int ix = chip->rss_ix >> 2; |
| 3019 |
|
| 3020 |
chip->rss_isend = ix == 0x1bf || ix == 0x43f || |
| 3021 |
ix == 0x1b7f || ix == 0x1cff || |
| 3022 |
ix == 0x1f7f || ix == 0x1fff; |
| 3023 |
} |
| 3024 |
|
| 3025 |
if (chip->rss_cnt1[1] == 0) |
| 3026 |
{ |
| 3027 |
chip->rss_nibble = rss_rom[(chip->rss_ix >> 2) & 0x1fff]; |
| 3028 |
if (chip->rss_ix & 2) |
| 3029 |
chip->rss_nibble >>= 4; |
| 3030 |
else |
| 3031 |
chip->rss_nibble &= 15; |
| 3032 |
} |
| 3033 |
#endif |
| 3034 |
#ifdef FMOPNA_YM2610 |
| 3035 |
if (chip->rss_cnt1[1] == 1 && !chip->rss_ix_load) |
| 3036 |
{ |
| 3037 |
chip->rss_ix = chip->rss_regs[1][14] & 0x1fffff; |
| 3038 |
} |
| 3039 |
#endif |
| 3040 |
|
| 3041 |
if (chip->rss_fclk1) |
| 3042 |
{ |
| 3043 |
memcpy(&chip->rss_regs[0][1], &chip->rss_regs[1][0], 16 * sizeof(int)); |
| 3044 |
chip->rss_regs[0][0] = chip->rss_accum[1]; |
| 3045 |
} |
| 3046 |
if (chip->rss_fclk2) |
| 3047 |
{ |
| 3048 |
memcpy(&chip->rss_regs[1][0], &chip->rss_regs[0][0], 17 * sizeof(int)); |
| 3049 |
} |
| 3050 |
|
| 3051 |
} |
| 3052 |
if (chip->rss_cnt1[1] == 5) |
| 3053 |
{ |
| 3054 |
chip->rss_pan[0] = (chip->rss_params[1] >> 6) & 3; |
| 3055 |
chip->rss_pan[2] = chip->rss_pan[1]; |
| 3056 |
} |
| 3057 |
if (chip->rss_cnt1[1] == 3) |
| 3058 |
{ |
| 3059 |
chip->rss_pan[1] = chip->rss_pan[0]; |
| 3060 |
} |
| 3061 |
#ifdef FMOPNA_YM2610 |
| 3062 |
int is1_2 = chip->rss_cnt1[1] == 1 || chip->rss_cnt1[1] == 2; |
| 3063 |
if (chip->aclk1) |
| 3064 |
{ |
| 3065 |
chip->rss_rmpx[0] = is1_2; |
| 3066 |
chip->rss_roe[0] = chip->rss_rmpx[1]; |
| 3067 |
chip->rss_roe[2] = chip->rss_roe[1]; |
| 3068 |
} |
| 3069 |
if (chip->aclk2) |
| 3070 |
{ |
| 3071 |
chip->rss_rmpx[1] = chip->rss_rmpx[0]; |
| 3072 |
chip->rss_roe[1] = chip->rss_roe[0]; |
| 3073 |
chip->rss_roe[3] = chip->rss_roe[2]; |
| 3074 |
} |
| 3075 |
|
| 3076 |
chip->o_rmpx = chip->rss_rmpx[1]; |
| 3077 |
chip->o_roe = !chip->rss_roe[1]; |
| 3078 |
int io_dir = is1_2 || chip->rss_roe[1]; |
| 3079 |
if (io_dir) |
| 3080 |
{ |
| 3081 |
chip->rss_rad_bus = is1_2 ? (chip->rss_ix >> 1) & 255 : (chip->rss_ix >> 11) & 255; |
| 3082 |
} |
| 3083 |
else |
| 3084 |
{ |
| 3085 |
chip->rss_rad_bus = chip->input.rad; |
| 3086 |
} |
| 3087 |
chip->o_ra8 = is1_2 ? (chip->rss_ix >> 9) & 3 : (chip->rss_ix >> 19) & 3; |
| 3088 |
chip->o_ra20 = chip->rss_params_start_h; |
| 3089 |
chip->o_rad = chip->rss_rad_bus; |
| 3090 |
chip->o_rad_d = !io_dir; |
| 3091 |
#endif |
| 3092 |
} |
| 3093 |
|
| 3094 |
// adpcm-b |
| 3095 |
{ |
| 3096 |
if (chip->write2) |
| 3097 |
{ |
| 3098 |
#ifdef FMOPNA_YM2608 |
| 3099 |
chip->ad_is0 = (chip->data_bus1 & 0xff) == 0x0; |
| 3100 |
chip->ad_is1 = (chip->data_bus1 & 0xff) == 0x1; |
| 3101 |
chip->ad_is2 = (chip->data_bus1 & 0xff) == 0x2; |
| 3102 |
chip->ad_is3 = (chip->data_bus1 & 0xff) == 0x3; |
| 3103 |
chip->ad_is4 = (chip->data_bus1 & 0xff) == 0x4; |
| 3104 |
chip->ad_is5 = (chip->data_bus1 & 0xff) == 0x5; |
| 3105 |
chip->ad_is6 = (chip->data_bus1 & 0xff) == 0x6; |
| 3106 |
chip->ad_is7 = (chip->data_bus1 & 0xff) == 0x7; |
| 3107 |
chip->ad_is8 = (chip->data_bus1 & 0xff) == 0x8; |
| 3108 |
chip->ad_is9 = (chip->data_bus1 & 0xff) == 0x9; |
| 3109 |
chip->ad_isa = (chip->data_bus1 & 0xff) == 0xa; |
| 3110 |
chip->ad_isb = (chip->data_bus1 & 0xff) == 0xb; |
| 3111 |
chip->ad_isc = (chip->data_bus1 & 0xff) == 0xc; |
| 3112 |
chip->ad_isd = (chip->data_bus1 & 0xff) == 0xd; |
| 3113 |
chip->ad_ise = (chip->data_bus1 & 0xff) == 0xe; |
| 3114 |
chip->ad_isf = (chip->data_bus1 & 0xff) == 0xf; |
| 3115 |
#else |
| 3116 |
chip->ad_is0 = (chip->data_bus1 & 0xff) == 0x10; |
| 3117 |
chip->ad_is1 = (chip->data_bus1 & 0xff) == 0x11; |
| 3118 |
chip->ad_is2 = (chip->data_bus1 & 0xff) == 0x12; |
| 3119 |
chip->ad_is3 = (chip->data_bus1 & 0xff) == 0x13; |
| 3120 |
chip->ad_is4 = (chip->data_bus1 & 0xff) == 0x14; |
| 3121 |
chip->ad_is5 = (chip->data_bus1 & 0xff) == 0x15; |
| 3122 |
chip->ad_is9 = (chip->data_bus1 & 0xff) == 0x19; |
| 3123 |
chip->ad_isa = (chip->data_bus1 & 0xff) == 0x1a; |
| 3124 |
chip->ad_isb = (chip->data_bus1 & 0xff) == 0x1b; |
| 3125 |
#endif |
| 3126 |
} |
| 3127 |
|
| 3128 |
if (chip->ic) |
| 3129 |
{ |
| 3130 |
#ifdef FMOPNA_YM2608 |
| 3131 |
chip->ad_reg_spoff = 0; |
| 3132 |
chip->ad_reg_memdata = 0; |
| 3133 |
chip->ad_reg_rec = 0; |
| 3134 |
chip->ad_reg_rom = 0; |
| 3135 |
chip->ad_reg_ramtype = 0; |
| 3136 |
chip->ad_reg_da_ad = 0; |
| 3137 |
chip->ad_reg_sample = 0; |
| 3138 |
#endif |
| 3139 |
chip->ad_reg_reset = 0; |
| 3140 |
chip->ad_reg_repeat = 0; |
| 3141 |
chip->ad_reg_start = 0; |
| 3142 |
chip->ad_reg_r = 0; |
| 3143 |
chip->ad_reg_l = 0; |
| 3144 |
} |
| 3145 |
else if (chip->write3) |
| 3146 |
{ |
| 3147 |
if (chip->ad_is0) |
| 3148 |
{ |
| 3149 |
#ifdef FMOPNA_YM2608 |
| 3150 |
chip->ad_reg_spoff = (chip->data_bus1 >> 3) & 1; |
| 3151 |
chip->ad_reg_memdata = (chip->data_bus1 >> 5) & 1; |
| 3152 |
chip->ad_reg_rec = (chip->data_bus1 >> 6) & 1; |
| 3153 |
#endif |
| 3154 |
chip->ad_reg_reset = (chip->data_bus1 >> 0) & 1; |
| 3155 |
chip->ad_reg_repeat = (chip->data_bus1 >> 4) & 1; |
| 3156 |
chip->ad_reg_start = (chip->data_bus1 >> 7) & 1; |
| 3157 |
} |
| 3158 |
if (chip->ad_is1) |
| 3159 |
{ |
| 3160 |
#ifdef FMOPNA_YM2608 |
| 3161 |
chip->ad_reg_rom = (chip->data_bus1 >> 0) & 1; |
| 3162 |
chip->ad_reg_ramtype = (chip->data_bus1 >> 1) & 1; |
| 3163 |
chip->ad_reg_da_ad = (chip->data_bus1 >> 2) & 1; |
| 3164 |
chip->ad_reg_sample = (chip->data_bus1 >> 3) & 1; |
| 3165 |
#endif |
| 3166 |
chip->ad_reg_r = (chip->data_bus1 >> 6) & 1; |
| 3167 |
chip->ad_reg_l = (chip->data_bus1 >> 7) & 1; |
| 3168 |
} |
| 3169 |
} |
| 3170 |
|
| 3171 |
if (chip->write3) |
| 3172 |
{ |
| 3173 |
if (chip->ad_is9) |
| 3174 |
{ |
| 3175 |
chip->ad_reg_delta_l = chip->data_bus1 & 255; |
| 3176 |
} |
| 3177 |
if (chip->ad_isa) |
| 3178 |
{ |
| 3179 |
chip->ad_reg_delta_h = chip->data_bus1 & 255; |
| 3180 |
} |
| 3181 |
if (chip->ad_is2) |
| 3182 |
{ |
| 3183 |
chip->ad_reg_start_l = chip->data_bus1 & 255; |
| 3184 |
} |
| 3185 |
if (chip->ad_is3) |
| 3186 |
{ |
| 3187 |
chip->ad_reg_start_h = chip->data_bus1 & 255; |
| 3188 |
} |
| 3189 |
if (chip->ad_is4) |
| 3190 |
{ |
| 3191 |
chip->ad_reg_stop_l = chip->data_bus1 & 255; |
| 3192 |
} |
| 3193 |
if (chip->ad_is5) |
| 3194 |
{ |
| 3195 |
chip->ad_reg_stop_h = chip->data_bus1 & 255; |
| 3196 |
} |
| 3197 |
if (chip->ad_isb) |
| 3198 |
{ |
| 3199 |
chip->ad_reg_level = chip->data_bus1 & 255; |
| 3200 |
} |
| 3201 |
#ifdef FMOPNA_YM2608 |
| 3202 |
if (chip->ad_isc) |
| 3203 |
{ |
| 3204 |
chip->ad_reg_limit_l = chip->data_bus1 & 255; |
| 3205 |
} |
| 3206 |
if (chip->ad_isd) |
| 3207 |
{ |
| 3208 |
chip->ad_reg_limit_h = chip->data_bus1 & 255; |
| 3209 |
} |
| 3210 |
if (chip->ad_is6) |
| 3211 |
{ |
| 3212 |
chip->ad_reg_prescale_l = chip->data_bus1 & 255; |
| 3213 |
} |
| 3214 |
if (chip->ad_is7) |
| 3215 |
{ |
| 3216 |
chip->ad_reg_prescale_h = chip->data_bus1 & 7; |
| 3217 |
} |
| 3218 |
if (chip->ad_ise) |
| 3219 |
{ |
| 3220 |
chip->ad_da_data = (chip->data_bus1 & 255) ^ 128; |
| 3221 |
} |
| 3222 |
#endif |
| 3223 |
} |
| 3224 |
|
| 3225 |
int reset = chip->ad_reg_reset || chip->ic; |
| 3226 |
|
| 3227 |
#ifdef FMOPNA_YM2608 |
| 3228 |
int mode1 = chip->ad_reg_memdata && chip->ad_reg_rec && !chip->ad_start_l[2] |
| 3229 |
&& (chip->ad_w2_l[1] & 16) != 0 |
| 3230 |
&& (chip->ad_write_port_l[1] & 4) != 0; // cpu->mem |
| 3231 |
int mode2 = !chip->ad_start_l[2] && (chip->ad_w2_l[1] & 16) != 0; |
| 3232 |
int mode3 = !chip->ad_reg_memdata && !chip->ad_start_l[2]; |
| 3233 |
int mode4 = chip->ad_reg_memdata && chip->ad_start_l[2] |
| 3234 |
&& (chip->ad_w2_l[1] & 16) != 0; |
| 3235 |
int mode5 = chip->ad_reg_memdata && chip->ad_reg_rec && chip->ad_start_l[2]; // enc->mem |
| 3236 |
int mode6 = chip->ad_reg_memdata && !chip->ad_reg_rec && chip->ad_start_l[2]; // mem->dec |
| 3237 |
int mode7 = !chip->ad_reg_ramtype && chip->ad_reg_rom && chip->ad_reg_memdata |
| 3238 |
&& !chip->ad_reg_rec && !chip->ad_start_l[2] && (chip->ad_w2_l[1] & 16) != 0 |
| 3239 |
&& (chip->ad_read_port_l[1] & 4) != 0; // mem(rom)->cpu |
| 3240 |
int mode8 = !chip->ad_reg_memdata && !chip->ad_reg_rec && chip->ad_start_l[2] |
| 3241 |
&& (chip->ad_write_port_l[1] & 4) != 0; // cpu->dec |
| 3242 |
int mode9 = chip->ad_reg_ramtype && !chip->ad_reg_rom && chip->ad_reg_memdata |
| 3243 |
&& !chip->ad_reg_rec && !chip->ad_start_l[2] && (chip->ad_w2_l[1] & 16) != 0 |
| 3244 |
&& (chip->ad_read_port_l[1] & 4) != 0; // mem(8bit)->cpu |
| 3245 |
int mode10 = !chip->ad_reg_memdata && chip->ad_reg_rec && chip->ad_start_l[2] |
| 3246 |
&& (chip->ad_read_port_l[1] & 4) != 0; // enc->cpu |
| 3247 |
int mode11 = !chip->ad_reg_ramtype && !chip->ad_reg_rom && chip->ad_reg_memdata |
| 3248 |
&& !chip->ad_reg_rec && !chip->ad_start_l[2] && (chip->ad_w2_l[1] & 16) != 0 |
| 3249 |
&& (chip->ad_read_port_l[1] & 4) != 0; // mem(1bit)->cpu |
| 3250 |
#else |
| 3251 |
int mode6 = chip->ad_start_l[2]; |
| 3252 |
#endif |
| 3253 |
|
| 3254 |
int code_end = chip->ad_code_end[1] && (chip->ad_w2_l[1] & 16) != 0; |
| 3255 |
|
| 3256 |
int repeat = chip->ad_reg_repeat && code_end && !chip->ad_code_ed_end[1]; |
| 3257 |
|
| 3258 |
#ifdef FMOPNA_YM2608 |
| 3259 |
int w28 = repeat || (!chip->ad_mode6_l[1] && mode6); |
| 3260 |
|
| 3261 |
int w6 = mode7 || mode9 || (w28 && |
| 3262 |
((!chip->ad_reg_rom && chip->ad_reg_ramtype) |
| 3263 |
|| (!chip->ad_reg_ramtype && chip->ad_reg_rom))); |
| 3264 |
|
| 3265 |
int sync = chip->ad_mem_sync_run || !chip->ad_mem_w20[1]; |
| 3266 |
int w16 = !chip->ad_mem_w10[1] && sync; |
| 3267 |
|
| 3268 |
int w18 = !(chip->ad_mem_w17[1] && (sync || !chip->ad_reg_memdata)); |
| 3269 |
|
| 3270 |
int p5 = (chip->ad_code_ctrl_l & 1) != 0 && !chip->ad_reg_rec && chip->ad_start_l[2] && (w16 || !chip->ad_reg_memdata); |
| 3271 |
|
| 3272 |
int w19 = !(w18 && chip->ad_start_l[2] && !p5); |
| 3273 |
|
| 3274 |
int p1 = chip->ad_reg_rec && w16 && w19 && chip->ad_reg_memdata && chip->ad_mem_w15[1]; |
| 3275 |
int p2 = !chip->ad_reg_rec && w16 && w19 && chip->ad_reg_memdata && chip->ad_mem_w15[1]; |
| 3276 |
int p3 = chip->ad_reg_rec && !w18; |
| 3277 |
int p4 = (!chip->ad_reg_rec && (w16 || !chip->ad_reg_memdata) && !w18) || p5; |
| 3278 |
|
| 3279 |
int w23 = p1 || p2; |
| 3280 |
|
| 3281 |
int w24 = (p4 && !chip->ad_reg_memdata) || (!chip->ad_start_l[2] && p1); |
| 3282 |
|
| 3283 |
int w25 = p2 || p3; |
| 3284 |
|
| 3285 |
int w26 = mode5 && !chip->ad_rec_start_l[1]; |
| 3286 |
int w27 = mode11 || (!chip->ad_reg_rom && w28 && !chip->ad_reg_ramtype); |
| 3287 |
|
| 3288 |
int w29 = w28 || w26 || mode10 || mode8; // start dsp |
| 3289 |
#else |
| 3290 |
int w28 = repeat || (!chip->ad_mode6_l[1] && mode6); |
| 3291 |
int w16 = !chip->ad_mem_w10[1]; |
| 3292 |
|
| 3293 |
int w18 = !chip->ad_mem_w17[1]; |
| 3294 |
|
| 3295 |
int p5 = (chip->ad_code_ctrl_l & 1) != 0 && chip->ad_start_l[2] && w16; |
| 3296 |
|
| 3297 |
int w19 = !(w18 && !p5); |
| 3298 |
|
| 3299 |
int p2 = w16 && w19 && chip->ad_mem_w15[1]; |
| 3300 |
int p4 = (w16 && !w18) || p5; |
| 3301 |
|
| 3302 |
int w23 = p2; |
| 3303 |
|
| 3304 |
int w29 = w28; // start dsp |
| 3305 |
#endif |
| 3306 |
|
| 3307 |
if (chip->cclk1) |
| 3308 |
{ |
| 3309 |
#ifdef FMOPNA_YM2608 |
| 3310 |
chip->ad_sample_l[1] = chip->ad_sample_l[0]; |
| 3311 |
|
| 3312 |
int read_sample = chip->read3 && chip->ad_is8; |
| 3313 |
int write_sample = chip->write3 && chip->ad_is8; |
| 3314 |
chip->ad_read_port_l[0] = (chip->ad_read_port_l[1] << 1) | read_sample; |
| 3315 |
chip->ad_write_port_l[0] = (chip->ad_write_port_l[1] << 1) | write_sample; |
| 3316 |
|
| 3317 |
chip->ad_rw_l[1] = chip->ad_rw_l[0]; |
| 3318 |
|
| 3319 |
int w3 = chip->ad_addr_isend_l && chip->ad_reg_rec; |
| 3320 |
#endif |
| 3321 |
chip->ad_start_l[1] = chip->ad_start_l[0]; |
| 3322 |
|
| 3323 |
int t1 = !chip->ad_addr_isend_l2[1] || chip->ad_addr_isend_l; |
| 3324 |
|
| 3325 |
#ifdef FMOPNA_YM2608 |
| 3326 |
chip->ad_w2[0] = (chip->ad_w2[1] && t1) || (chip->ad_rw_en && chip->ad_w4[1]) |
| 3327 |
|| (t1 && (reset || w3 || (chip->ad_w4[1] && chip->ad_start_l[2]))); |
| 3328 |
|
| 3329 |
chip->ad_w4[0] = (chip->ad_w4[1] && t1) || w3 || (chip->ad_addr_isend_l && p2); |
| 3330 |
#else |
| 3331 |
chip->ad_w2[0] = (chip->ad_w2[1] && t1) |
| 3332 |
|| (t1 && (reset || (chip->ad_w4[1] && chip->ad_start_l[2]))); |
| 3333 |
|
| 3334 |
chip->ad_w4[0] = (chip->ad_w4[1] && t1) || (chip->ad_addr_isend_l && p2); |
| 3335 |
#endif |
| 3336 |
|
| 3337 |
chip->ad_w2_l[0] = (chip->ad_w2_l[1] << 1) | chip->ad_w2[1]; |
| 3338 |
|
| 3339 |
chip->ad_addr_isend_l2[0] = chip->ad_addr_isend_l; |
| 3340 |
|
| 3341 |
#ifdef FMOPNA_YM2608 |
| 3342 |
int t2 = mode2 || mode3 || mode4; |
| 3343 |
#else |
| 3344 |
int t2 = (chip->ad_w2_l[1] & 16) != 0; |
| 3345 |
#endif |
| 3346 |
|
| 3347 |
chip->ad_w12[0] = chip->ad_w12[1] << 1; |
| 3348 |
chip->ad_w12[0] |= t2; |
| 3349 |
|
| 3350 |
chip->ad_w13[0] = (chip->ad_w12[1] & 3) == 1; |
| 3351 |
|
| 3352 |
chip->ad_mode6_l[0] = mode6; |
| 3353 |
|
| 3354 |
chip->ad_code_ed_end[0] = code_end; |
| 3355 |
|
| 3356 |
} |
| 3357 |
if (chip->cclk2) |
| 3358 |
{ |
| 3359 |
#ifdef FMOPNA_YM2608 |
| 3360 |
chip->ad_sample_l[0] = chip->ad_reg_sample; |
| 3361 |
chip->ad_sample_l[2] = chip->ad_sample_l[1]; |
| 3362 |
|
| 3363 |
chip->ad_read_port_l[1] = chip->ad_read_port_l[0]; |
| 3364 |
chip->ad_write_port_l[1] = chip->ad_write_port_l[0]; |
| 3365 |
|
| 3366 |
chip->ad_rw_l[0] = chip->ad_rw_l[1] << 1; |
| 3367 |
chip->ad_rw_l[0] |= (chip->ad_read_port_l[0] & 1) != 0 || (chip->ad_write_port_l[0] & 1) != 0; |
| 3368 |
|
| 3369 |
chip->ad_rw_en = (chip->ad_rw_l[0] & 1) == 0 && (chip->ad_rw_l[0] & 2) != 0; |
| 3370 |
|
| 3371 |
chip->ad_rec_start_l[1] = chip->ad_rec_start_l[0]; |
| 3372 |
#endif |
| 3373 |
|
| 3374 |
chip->ad_start_l[0] = chip->ad_reg_start; |
| 3375 |
chip->ad_start_l[2] = chip->ad_start_l[1]; |
| 3376 |
|
| 3377 |
chip->ad_w2[1] = chip->ad_w2[0]; |
| 3378 |
|
| 3379 |
chip->ad_w4[1] = chip->ad_w4[0]; |
| 3380 |
|
| 3381 |
chip->ad_w2_l[1] = chip->ad_w2_l[0]; |
| 3382 |
|
| 3383 |
chip->ad_addr_isend_l = chip->ad_stop_match2[0]; |
| 3384 |
|
| 3385 |
chip->ad_addr_isend_l2[1] = chip->ad_addr_isend_l2[0]; |
| 3386 |
|
| 3387 |
chip->ad_w12[1] = chip->ad_w12[0]; |
| 3388 |
|
| 3389 |
chip->ad_w13[1] = chip->ad_w13[0]; |
| 3390 |
chip->ad_mode6_l[1] = chip->ad_mode6_l[0]; |
| 3391 |
|
| 3392 |
chip->ad_code_ed_end[1] = chip->ad_code_ed_end[0]; |
| 3393 |
} |
| 3394 |
#ifdef FMOPNA_YM2608 |
| 3395 |
int cond = 0; |
| 3396 |
|
| 3397 |
if (chip->cclk1) |
| 3398 |
{ |
| 3399 |
if (chip->ic || (chip->ad_mem_ctrl_l & 64) != 0) |
| 3400 |
chip->ad_mem_sync[0] = 0; |
| 3401 |
else |
| 3402 |
chip->ad_mem_sync[0] = (chip->ad_mem_sync[1] + chip->ad_mem_sync_run) & 63; |
| 3403 |
|
| 3404 |
int next_ptr = 0; |
| 3405 |
chip->ad_mem_ctrl = 0; |
| 3406 |
|
| 3407 |
int cond_next = 0; |
| 3408 |
|
| 3409 |
if (mode1) |
| 3410 |
{ |
| 3411 |
cond_next |= 1; |
| 3412 |
} |
| 3413 |
if (w26) |
| 3414 |
{ |
| 3415 |
cond_next |= 2; |
| 3416 |
} |
| 3417 |
if (w27) |
| 3418 |
{ |
| 3419 |
cond_next |= 4; |
| 3420 |
} |
| 3421 |
if (w6) |
| 3422 |
{ |
| 3423 |
cond_next |= 8; |
| 3424 |
} |
| 3425 |
if (w23) |
| 3426 |
{ |
| 3427 |
cond_next |= 16; |
| 3428 |
} |
| 3429 |
|
| 3430 |
if (sync) |
| 3431 |
{ |
| 3432 |
cond = chip->ad_mem_cond[1]; |
| 3433 |
} |
| 3434 |
else |
| 3435 |
{ |
| 3436 |
cond_next |= chip->ad_mem_cond[1]; |
| 3437 |
} |
| 3438 |
|
| 3439 |
if ((cond & 15) == 0) |
| 3440 |
cond |= 32; |
| 3441 |
|
| 3442 |
chip->ad_mem_cond[0] = cond_next; |
| 3443 |
|
| 3444 |
int store_addr = 0; |
| 3445 |
|
| 3446 |
#if 0 |
| 3447 |
if ((chip->ad_mem_code_ptr[1] & 0x2f) == 0xf) |
| 3448 |
{ |
| 3449 |
next_ptr |= 0; |
| 3450 |
chip->ad_mem_ctrl |= 0; |
| 3451 |
} |
| 3452 |
#endif |
| 3453 |
// common code |
| 3454 |
switch (chip->ad_mem_code_ptr[1] & 0xf) |
| 3455 |
{ |
| 3456 |
case 0x0: |
| 3457 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3458 |
break; |
| 3459 |
case 0x1: |
| 3460 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3461 |
break; |
| 3462 |
case 0x2: |
| 3463 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3464 |
break; |
| 3465 |
case 0x3: |
| 3466 |
chip->ad_mem_ctrl |= 0b10011000000000; |
| 3467 |
break; |
| 3468 |
case 0x4: |
| 3469 |
chip->ad_mem_ctrl |= 0b10111000010000; |
| 3470 |
break; |
| 3471 |
case 0x5: |
| 3472 |
chip->ad_mem_ctrl |= 0b11010000000000; |
| 3473 |
break; |
| 3474 |
case 0x6: |
| 3475 |
chip->ad_mem_ctrl |= 0b11110000000000; |
| 3476 |
break; |
| 3477 |
case 0x7: |
| 3478 |
chip->ad_mem_ctrl |= 0b11000000000001; |
| 3479 |
break; |
| 3480 |
case 0x8: |
| 3481 |
chip->ad_mem_ctrl |= 0b11100000000001; |
| 3482 |
break; |
| 3483 |
} |
| 3484 |
|
| 3485 |
switch (chip->ad_mem_code_ptr[1]) |
| 3486 |
{ |
| 3487 |
case 0x9: |
| 3488 |
chip->ad_mem_ctrl |= 0b11100000000010; |
| 3489 |
break; |
| 3490 |
case 0xa: |
| 3491 |
chip->ad_mem_ctrl |= 0b11000010000000; |
| 3492 |
break; |
| 3493 |
case 0xb: |
| 3494 |
chip->ad_mem_ctrl |= 0b00000110000000; |
| 3495 |
break; |
| 3496 |
case 0xd: |
| 3497 |
if (sync) |
| 3498 |
{ |
| 3499 |
if (chip->ad_stop_match2[1]) |
| 3500 |
{ |
| 3501 |
next_ptr |= 0x3f|0x40; |
| 3502 |
} |
| 3503 |
if (!chip->ad_mem_w22) |
| 3504 |
{ |
| 3505 |
next_ptr |= 0x4|0x40; |
| 3506 |
chip->ad_mem_ctrl |= 0b10011000000000; |
| 3507 |
} |
| 3508 |
if ((cond & 16) == 0 && chip->ad_mem_w22) |
| 3509 |
{ |
| 3510 |
next_ptr |= 0xd|0x40; |
| 3511 |
} |
| 3512 |
if ((cond & 16) != 0 && chip->ad_mem_w22) |
| 3513 |
{ |
| 3514 |
next_ptr |= 0x4|0x40; |
| 3515 |
chip->ad_mem_ctrl |= 0b10011000000000; |
| 3516 |
} |
| 3517 |
} |
| 3518 |
else |
| 3519 |
{ |
| 3520 |
next_ptr = 0x3a | 0x40; |
| 3521 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3522 |
store_addr = 1; |
| 3523 |
} |
| 3524 |
break; |
| 3525 |
|
| 3526 |
case 0x19: |
| 3527 |
chip->ad_mem_ctrl |= 0b00100100001000; |
| 3528 |
break; |
| 3529 |
case 0x1b: |
| 3530 |
if (sync) |
| 3531 |
{ |
| 3532 |
if (chip->ad_stop_match2[1]) |
| 3533 |
{ |
| 3534 |
next_ptr |= 0x3f|0x40; |
| 3535 |
} |
| 3536 |
if (!chip->ad_mem_w22) |
| 3537 |
{ |
| 3538 |
next_ptr |= 0x14|0x40; |
| 3539 |
chip->ad_mem_ctrl |= 0b10011000000000; |
| 3540 |
} |
| 3541 |
if ((cond & 16) == 0 && chip->ad_mem_w22) |
| 3542 |
{ |
| 3543 |
next_ptr |= 0x1b|0x40; |
| 3544 |
} |
| 3545 |
if ((cond & 16) != 0 && chip->ad_mem_w22) |
| 3546 |
{ |
| 3547 |
next_ptr |= 0x14|0x40; |
| 3548 |
chip->ad_mem_ctrl |= 0b10011000000000; |
| 3549 |
} |
| 3550 |
} |
| 3551 |
else |
| 3552 |
{ |
| 3553 |
next_ptr = 0x3a | 0x40; |
| 3554 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3555 |
store_addr = 1; |
| 3556 |
} |
| 3557 |
break; |
| 3558 |
|
| 3559 |
case 0x29: |
| 3560 |
chip->ad_mem_ctrl |= 0b00100000000100; |
| 3561 |
break; |
| 3562 |
case 0x2b: |
| 3563 |
if (sync) |
| 3564 |
{ |
| 3565 |
if (chip->ad_stop_match2[1]) |
| 3566 |
{ |
| 3567 |
next_ptr |= 0x3f|0x40; |
| 3568 |
} |
| 3569 |
if ((cond & 16) == 0) |
| 3570 |
{ |
| 3571 |
next_ptr |= 0x2b|0x40; |
| 3572 |
} |
| 3573 |
if ((cond & 16) != 0) |
| 3574 |
{ |
| 3575 |
next_ptr |= 0x24|0x40; |
| 3576 |
chip->ad_mem_ctrl |= 0b10011000000000; |
| 3577 |
} |
| 3578 |
} |
| 3579 |
else |
| 3580 |
{ |
| 3581 |
next_ptr = 0x3a | 0x40; |
| 3582 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3583 |
store_addr = 1; |
| 3584 |
} |
| 3585 |
break; |
| 3586 |
|
| 3587 |
case 0x3a: |
| 3588 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3589 |
break; |
| 3590 |
case 0x3b: |
| 3591 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3592 |
break; |
| 3593 |
case 0x3c: |
| 3594 |
chip->ad_mem_ctrl |= 0b10011000000000; |
| 3595 |
break; |
| 3596 |
case 0x3d: |
| 3597 |
chip->ad_mem_ctrl |= 0b00111001000000; |
| 3598 |
break; |
| 3599 |
|
| 3600 |
case 0x2f: |
| 3601 |
if (sync) |
| 3602 |
{ |
| 3603 |
if ((cond & 16) == 0) |
| 3604 |
{ |
| 3605 |
next_ptr = 0x2f | 0x40; |
| 3606 |
} |
| 3607 |
else |
| 3608 |
{ |
| 3609 |
next_ptr = 0x0 | 0x40; |
| 3610 |
chip->ad_mem_ctrl |= 0b00100000100000; |
| 3611 |
} |
| 3612 |
} |
| 3613 |
else |
| 3614 |
{ |
| 3615 |
next_ptr = 0x3a | 0x40; |
| 3616 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3617 |
store_addr = 1; |
| 3618 |
} |
| 3619 |
break; |
| 3620 |
|
| 3621 |
case 0x3f: |
| 3622 |
if (sync) |
| 3623 |
{ |
| 3624 |
if (cond & 1) |
| 3625 |
{ |
| 3626 |
next_ptr |= 0x0 | 0x40; |
| 3627 |
chip->ad_mem_ctrl = 0b00100000100000; |
| 3628 |
} |
| 3629 |
if (cond & 2) |
| 3630 |
{ |
| 3631 |
next_ptr |= 0x2f | 0x40; |
| 3632 |
} |
| 3633 |
if (cond & 4) |
| 3634 |
{ |
| 3635 |
next_ptr |= 0x10 | 0x40; |
| 3636 |
chip->ad_mem_ctrl = 0b00100000100000; |
| 3637 |
} |
| 3638 |
if (cond & 8) |
| 3639 |
{ |
| 3640 |
next_ptr |= 0x20 | 0x40; |
| 3641 |
chip->ad_mem_ctrl = 0b00100000100000; |
| 3642 |
} |
| 3643 |
if (cond & 32) |
| 3644 |
{ |
| 3645 |
next_ptr |= 0x3f | 0x40; |
| 3646 |
} |
| 3647 |
} |
| 3648 |
else |
| 3649 |
{ |
| 3650 |
next_ptr = 0x3a | 0x40; |
| 3651 |
chip->ad_mem_ctrl |= 0b00100000000000; |
| 3652 |
store_addr = 1; |
| 3653 |
} |
| 3654 |
break; |
| 3655 |
} |
| 3656 |
|
| 3657 |
if ((chip->ad_mem_ctrl_l & 64) != 0) |
| 3658 |
{ |
| 3659 |
next_ptr |= chip->ad_mem_ptr_store | 0x40; |
| 3660 |
} |
| 3661 |
|
| 3662 |
if (chip->ic) |
| 3663 |
{ |
| 3664 |
next_ptr |= 0x3f | 0x40; |
| 3665 |
} |
| 3666 |
|
| 3667 |
if (next_ptr & 64) |
| 3668 |
chip->ad_mem_code_ptr[0] = next_ptr & 63; |
| 3669 |
else |
| 3670 |
chip->ad_mem_code_ptr[0] = (chip->ad_mem_code_ptr[1] + 1) & 63; |
| 3671 |
|
| 3672 |
if (store_addr) |
| 3673 |
chip->ad_mem_ptr_store = chip->ad_mem_code_ptr[1]; |
| 3674 |
} |
| 3675 |
if (chip->cclk2) |
| 3676 |
{ |
| 3677 |
chip->ad_mem_code_ptr[1] = chip->ad_mem_code_ptr[0]; |
| 3678 |
chip->ad_mem_ctrl_l = chip->ad_mem_ctrl; |
| 3679 |
|
| 3680 |
chip->ad_mem_cond[1] = chip->ad_mem_cond[0]; |
| 3681 |
|
| 3682 |
chip->ad_mem_sync[1] = chip->ad_mem_sync[0]; |
| 3683 |
|
| 3684 |
chip->ad_mem_sync_run = (chip->ad_mem_sync[0] & 40) != 40; |
| 3685 |
} |
| 3686 |
|
| 3687 |
if (chip->cclk1) |
| 3688 |
{ |
| 3689 |
chip->ad_end_sel[0] = chip->ad_end_sel[1]; |
| 3690 |
|
| 3691 |
int stop_val = 0; |
| 3692 |
int limit_val = 0; |
| 3693 |
if (chip->ad_end_sel[1] & 1) |
| 3694 |
{ |
| 3695 |
stop_val |= ((chip->ad_reg_stop_l & 15) << 5) | 31; |
| 3696 |
limit_val |= ((chip->ad_reg_limit_l & 15) << 5) | 31; |
| 3697 |
} |
| 3698 |
if (chip->ad_end_sel[1] & 4) |
| 3699 |
{ |
| 3700 |
stop_val |= ((chip->ad_reg_stop_h & 31) << 4) | ((chip->ad_reg_stop_l >> 4) & 15); |
| 3701 |
limit_val |= ((chip->ad_reg_limit_h & 31) << 4) | ((chip->ad_reg_limit_l >> 4) & 15); |
| 3702 |
} |
| 3703 |
if (chip->ad_end_sel[1] & 8) |
| 3704 |
{ |
| 3705 |
stop_val |= (chip->ad_reg_stop_h >> 5) & 7; |
| 3706 |
limit_val |= (chip->ad_reg_limit_h >> 5) & 7; |
| 3707 |
} |
| 3708 |
|
| 3709 |
chip->ad_stop_match[0] = chip->ad_stop_match[1] << 1; |
| 3710 |
if (stop_val == chip->ad_address_cnt[3][1]) |
| 3711 |
chip->ad_stop_match[0] |= 1; |
| 3712 |
chip->ad_limit_match[0] = chip->ad_limit_match[1] << 1; |
| 3713 |
if (limit_val == chip->ad_address_cnt[3][1]) |
| 3714 |
chip->ad_limit_match[0] |= 1; |
| 3715 |
|
| 3716 |
int rst = (chip->ad_mem_cond[1] & 2) != 0 || (chip->ad_start_sel[1] & 1) != 0; |
| 3717 |
|
| 3718 |
int stop_match = (chip->ad_stop_match[0] & 11) == 11 && (chip->ad_end_sel[1] & 8) != 0; |
| 3719 |
|
| 3720 |
chip->ad_stop_match2[0] = ((stop_match || chip->ad_stop_match2[1]) |
| 3721 |
&& !rst) || reset; |
| 3722 |
|
| 3723 |
chip->ad_limit_match2[0] = (chip->ad_limit_match[0] & 11) == 11 && (chip->ad_end_sel[1] & 8) != 0; |
| 3724 |
|
| 3725 |
chip->ad_start_sel[0] = chip->ad_start_sel[1]; |
| 3726 |
|
| 3727 |
int start_val = 0; |
| 3728 |
if (chip->ad_start_sel[1] & 1) |
| 3729 |
start_val |= ((chip->ad_reg_start_l & 15) << 5); |
| 3730 |
if (chip->ad_start_sel[1] & 2) |
| 3731 |
start_val |= ((chip->ad_reg_start_h & 31) << 4) | ((chip->ad_reg_start_l >> 4) & 15); |
| 3732 |
if (chip->ad_start_sel[1] & 4) |
| 3733 |
start_val |= (chip->ad_reg_start_h >> 5) & 7; |
| 3734 |
|
| 3735 |
chip->ad_address_cnt[0][0] = 0; |
| 3736 |
chip->ad_address_cnt[1][0] = 0; |
| 3737 |
chip->ad_address_cnt[2][0] = 0; |
| 3738 |
chip->ad_address_cnt[3][0] = 0; |
| 3739 |
|
| 3740 |
int add = chip->ad_address_cnt[3][1]; |
| 3741 |
|
| 3742 |
if ((chip->ad_mem_ctrl_l & 0x200) != 0 || chip->ad_address_carry[1]) |
| 3743 |
add++; |
| 3744 |
|
| 3745 |
int carry = ((add >> 9) & 1) != 0 && (chip->ad_mem_ctrl_l & 0x40) == 0; |
| 3746 |
add &= 0x1ff; |
| 3747 |
|
| 3748 |
if (!chip->ad_limit_match2[1]) |
| 3749 |
{ |
| 3750 |
if (chip->ad_mem_ctrl_l & 0x800) |
| 3751 |
{ |
| 3752 |
if ((chip->ad_start_sel[1] & 7) != 0) |
| 3753 |
chip->ad_address_cnt[0][0] = start_val; |
| 3754 |
else |
| 3755 |
chip->ad_address_cnt[0][0] = add; |
| 3756 |
chip->ad_address_cnt[1][0] = chip->ad_address_cnt[0][1]; |
| 3757 |
chip->ad_address_cnt[2][0] = chip->ad_address_cnt[1][1]; |
| 3758 |
} |
| 3759 |
else if (!chip->ic) |
| 3760 |
{ |
| 3761 |
chip->ad_address_cnt[0][0] = chip->ad_address_cnt[0][1]; |
| 3762 |
chip->ad_address_cnt[1][0] = chip->ad_address_cnt[1][1]; |
| 3763 |
chip->ad_address_cnt[2][0] = chip->ad_address_cnt[2][1]; |
| 3764 |
} |
| 3765 |
} |
| 3766 |
if (chip->ad_mem_ctrl_l & 0x800) |
| 3767 |
{ |
| 3768 |
chip->ad_address_cnt[3][0] = chip->ad_address_cnt[2][1]; |
| 3769 |
} |
| 3770 |
else if (!chip->ic) |
| 3771 |
{ |
| 3772 |
chip->ad_address_cnt[3][0] = chip->ad_address_cnt[3][1]; |
| 3773 |
} |
| 3774 |
|
| 3775 |
if (chip->ad_mem_ctrl_l & 0x800) |
| 3776 |
chip->ad_address_carry[0] = carry; |
| 3777 |
else |
| 3778 |
chip->ad_address_carry[0] = chip->ad_address_carry[1]; |
| 3779 |
} |
| 3780 |
if (chip->cclk2) |
| 3781 |
{ |
| 3782 |
chip->ad_end_sel[1] = chip->ad_end_sel[0] << 1; |
| 3783 |
if (chip->ad_mem_ctrl & 16) |
| 3784 |
chip->ad_end_sel[1] |= 1; |
| 3785 |
chip->ad_start_sel[1] = chip->ad_start_sel[0] << 1; |
| 3786 |
if (chip->ad_mem_ctrl & 32) |
| 3787 |
chip->ad_start_sel[1] |= 1; |
| 3788 |
chip->ad_stop_match[1] = chip->ad_stop_match[0]; |
| 3789 |
chip->ad_limit_match[1] = chip->ad_limit_match[0]; |
| 3790 |
chip->ad_stop_match2[1] = chip->ad_stop_match2[0]; |
| 3791 |
chip->ad_limit_match2[1] = chip->ad_limit_match2[0]; |
| 3792 |
|
| 3793 |
chip->ad_address_cnt[0][1] = chip->ad_address_cnt[0][0]; |
| 3794 |
chip->ad_address_cnt[1][1] = chip->ad_address_cnt[1][0]; |
| 3795 |
chip->ad_address_cnt[2][1] = chip->ad_address_cnt[2][0]; |
| 3796 |
chip->ad_address_cnt[3][1] = chip->ad_address_cnt[3][0]; |
| 3797 |
|
| 3798 |
chip->ad_address_carry[1] = chip->ad_address_carry[0]; |
| 3799 |
} |
| 3800 |
|
| 3801 |
if (chip->cclk1) |
| 3802 |
{ |
| 3803 |
|
| 3804 |
if (chip->ad_mem_ctrl_l & 1) |
| 3805 |
chip->ad_mem_addr_bank = chip->ad_address_cnt[3][1] & 7; |
| 3806 |
|
| 3807 |
int t1 = 0; |
| 3808 |
if (chip->ad_mem_ctrl_l & 1) |
| 3809 |
{ |
| 3810 |
t1 |= chip->ad_mem_bus & 254; |
| 3811 |
t1 |= chip->input.dt0; |
| 3812 |
} |
| 3813 |
if (chip->ad_mem_ctrl_l & 2) |
| 3814 |
{ |
| 3815 |
if (chip->ad_reg_ramtype) |
| 3816 |
{ |
| 3817 |
t1 |= chip->ad_mem_data_l2; |
| 3818 |
} |
| 3819 |
else |
| 3820 |
{ |
| 3821 |
if (chip->ad_mem_data_l2 & (1 << chip->ad_mem_bit_cnt[1])) |
| 3822 |
t1 |= 255; |
| 3823 |
} |
| 3824 |
} |
| 3825 |
if (((chip->ad_mem_ctrl_l & 2) != 0 && chip->ad_reg_ramtype) || (chip->ad_mem_ctrl_l & 1) != 0) |
| 3826 |
{ |
| 3827 |
chip->ad_mem_data_l1 = t1; |
| 3828 |
} |
| 3829 |
else if (chip->ad_mem_ctrl_l & 2) |
| 3830 |
{ |
| 3831 |
int mask = 1 << chip->ad_mem_addr_bank; |
| 3832 |
chip->ad_mem_data_l1 &= ~mask; |
| 3833 |
chip->ad_mem_data_l1 |= mask & t1; |
| 3834 |
} |
| 3835 |
|
| 3836 |
if (chip->ad_mem_ctrl_l & 32) |
| 3837 |
chip->ad_mem_bit_cnt[0] = 0; |
| 3838 |
else |
| 3839 |
{ |
| 3840 |
int add = !chip->ad_reg_ramtype && (chip->ad_mem_ctrl_l & 0x100) != 0; |
| 3841 |
chip->ad_mem_bit_cnt[0] = (chip->ad_mem_bit_cnt[1] + add) & 7; |
| 3842 |
} |
| 3843 |
|
| 3844 |
int t2 = 0; |
| 3845 |
if (p1) |
| 3846 |
{ |
| 3847 |
t2 |= chip->ad_mem_data_bus; |
| 3848 |
} |
| 3849 |
if (chip->ad_mem_ctrl_l & 4) |
| 3850 |
{ |
| 3851 |
t2 |= chip->ad_mem_data_l1; |
| 3852 |
} |
| 3853 |
if (chip->ad_mem_ctrl_l & 8) |
| 3854 |
{ |
| 3855 |
if (chip->ad_mem_data_l1 & (1 << chip->ad_mem_addr_bank)) |
| 3856 |
t2 |= 255; |
| 3857 |
} |
| 3858 |
|
| 3859 |
if ((chip->ad_mem_ctrl_l & 4) != 0 || p1) |
| 3860 |
{ |
| 3861 |
chip->ad_mem_data_l2 = t2; |
| 3862 |
} |
| 3863 |
else if (chip->ad_mem_ctrl_l & 8) |
| 3864 |
{ |
| 3865 |
int mask = 1 << chip->ad_mem_bit_cnt[1]; |
| 3866 |
chip->ad_mem_data_l2 &= ~mask; |
| 3867 |
chip->ad_mem_data_l2 |= mask & t2; |
| 3868 |
} |
| 3869 |
|
| 3870 |
int t4; |
| 3871 |
if (p4) |
| 3872 |
t4 = chip->ad_mem_data_bus; |
| 3873 |
else if (chip->ad_mem_w7[1]) |
| 3874 |
t4 = ((chip->ad_mem_data_l4[1] & 127) << 1) | !chip->ad_dsp_enc_bit; |
| 3875 |
else |
| 3876 |
t4 = chip->ad_mem_data_l4[1]; |
| 3877 |
|
| 3878 |
chip->ad_mem_data_l4[0] = t4; |
| 3879 |
|
| 3880 |
chip->ad_mem_w7[0] = (chip->ad_code_ctrl_l & 0x1000) != 0; |
| 3881 |
chip->ad_mem_w8[0] = (chip->ad_code_ctrl_l & 0x800) != 0; |
| 3882 |
|
| 3883 |
int add = chip->ad_mem_shift_cnt[1] + chip->ad_mem_w7[1]; |
| 3884 |
int of = (add & 8) != 0; |
| 3885 |
|
| 3886 |
if (!chip->ad_start_l[2]) |
| 3887 |
chip->ad_mem_shift_cnt[0] = 0; |
| 3888 |
else |
| 3889 |
chip->ad_mem_shift_cnt[0] = add & 7; |
| 3890 |
|
| 3891 |
chip->ad_mem_shift_cnt0_l[0] = (chip->ad_mem_shift_cnt[1] & 3) == 0; |
| 3892 |
|
| 3893 |
int mem_en = chip->ad_start_l[2] && chip->ad_reg_memdata; |
| 3894 |
|
| 3895 |
chip->ad_mem_mem_en_l[0] = mem_en; |
| 3896 |
|
| 3897 |
int w9 = (mem_en && !chip->ad_mem_mem_en_l[1] && !chip->ad_reg_rec) || |
| 3898 |
(!chip->ad_reg_memdata && chip->ad_start_l[2]) || |
| 3899 |
repeat || |
| 3900 |
w23; |
| 3901 |
|
| 3902 |
chip->ad_mem_mem_stop[0] = !mem_en && chip->ad_mem_mem_en_l[1]; |
| 3903 |
|
| 3904 |
int w11 = reset || chip->ad_mem_mem_stop[1] || chip->ad_w13[1] || chip->ad_mem_w21; |
| 3905 |
|
| 3906 |
chip->ad_mem_w10[0] = w9 || (chip->ad_mem_w10[1] && !w11); |
| 3907 |
|
| 3908 |
int w14 = reset || chip->ad_mem_mem_stop[1] || chip->ad_w13[1] || w16 || (!chip->ad_reg_memdata && (p3 || p4)); |
| 3909 |
|
| 3910 |
chip->ad_mem_w15[0] = (mem_en || chip->ad_rw_en) || (chip->ad_mem_w15[1] && !w14); |
| 3911 |
|
| 3912 |
chip->ad_brdy_set_l[0] = chip->ad_reg_memdata ? (!chip->ad_mem_w15[1] && w16) |
| 3913 |
: !chip->ad_mem_w15[1]; |
| 3914 |
|
| 3915 |
chip->ad_mem_w17[0] = of || (chip->ad_mem_w17[1] && w18); |
| 3916 |
|
| 3917 |
chip->ad_mem_rw_en[0] = chip->ad_mem_rw_en[1] << 1; |
| 3918 |
chip->ad_mem_rw_en[0] |= chip->ad_rw_en; |
| 3919 |
|
| 3920 |
chip->ad_mem_w20[0] = ((chip->ad_mem_rw_en[1] & 2) != 0 || chip->ad_start_l[2] || reset) || |
| 3921 |
(chip->ad_mem_w20[1] && (cond & 32) != 0); |
| 3922 |
|
| 3923 |
if (chip->ad_mem_ctrl_l & 32) |
| 3924 |
chip->ad_mem_ucnt[0] = 0; |
| 3925 |
else |
| 3926 |
{ |
| 3927 |
int inc = !chip->ad_reg_ramtype && (chip->ad_mem_ctrl_l & 0x100) != 0; |
| 3928 |
chip->ad_mem_ucnt[0] = (chip->ad_mem_ucnt[1] + inc) & 7; |
| 3929 |
} |
| 3930 |
|
| 3931 |
chip->ad_mem_we[0] = (chip->ad_mem_ctrl_l & 0x80) != 0; |
| 3932 |
chip->ad_mem_cas[0] = (chip->ad_mem_ctrl_l & 0x1000) != 0; |
| 3933 |
chip->ad_mem_ras[0] = (chip->ad_mem_ctrl_l & 0x2000) != 0; |
| 3934 |
} |
| 3935 |
if (chip->cclk2) |
| 3936 |
{ |
| 3937 |
chip->ad_mem_bit_cnt[1] = chip->ad_mem_bit_cnt[0]; |
| 3938 |
|
| 3939 |
chip->ad_mem_data_l4[1] = chip->ad_mem_data_l4[0]; |
| 3940 |
|
| 3941 |
chip->ad_mem_w7[1] = chip->ad_mem_w7[0]; |
| 3942 |
chip->ad_mem_w8[1] = chip->ad_mem_w8[0]; |
| 3943 |
|
| 3944 |
chip->ad_mem_shift_cnt[1] = chip->ad_mem_shift_cnt[0]; |
| 3945 |
|
| 3946 |
chip->ad_mem_shift_cnt0_l[1] = chip->ad_mem_shift_cnt0_l[0]; |
| 3947 |
|
| 3948 |
chip->ad_mem_mem_en_l[1] = chip->ad_mem_mem_en_l[0]; |
| 3949 |
|
| 3950 |
chip->ad_mem_mem_stop[1] = chip->ad_mem_mem_stop[0]; |
| 3951 |
|
| 3952 |
chip->ad_mem_w10[1] = chip->ad_mem_w10[0]; |
| 3953 |
|
| 3954 |
chip->ad_mem_w15[1] = chip->ad_mem_w15[0]; |
| 3955 |
|
| 3956 |
chip->ad_brdy_set_l[1] = chip->ad_brdy_set_l[0]; |
| 3957 |
|
| 3958 |
chip->ad_mem_w17[1] = chip->ad_mem_w17[0]; |
| 3959 |
|
| 3960 |
chip->ad_mem_rw_en[1] = chip->ad_mem_rw_en[0]; |
| 3961 |
|
| 3962 |
chip->ad_mem_ucnt[1] = chip->ad_mem_ucnt[0]; |
| 3963 |
|
| 3964 |
chip->ad_mem_w20[1] = chip->ad_mem_w20[0]; |
| 3965 |
|
| 3966 |
chip->ad_mem_w21 = (chip->ad_mem_ctrl & 4) != 0 || |
| 3967 |
(chip->ad_reg_ramtype && (chip->ad_mem_ctrl & 0x100) != 0) || |
| 3968 |
(!chip->ad_reg_ramtype && (chip->ad_mem_ctrl & 0x100) != 0 && chip->ad_mem_ucnt[0] == 7); |
| 3969 |
|
| 3970 |
chip->ad_mem_w22 = chip->ad_mem_ucnt[0] == 0; |
| 3971 |
|
| 3972 |
chip->ad_mem_we[1] = chip->ad_mem_we[0]; |
| 3973 |
chip->ad_mem_cas[1] = chip->ad_mem_cas[0]; |
| 3974 |
chip->ad_mem_ras[1] = chip->ad_mem_ras[0]; |
| 3975 |
|
| 3976 |
chip->ad_mem_dir = (chip->ad_mem_ctrl & 0x80) != 0 || (chip->ad_mem_ctrl & 0x400) != 0; |
| 3977 |
} |
| 3978 |
|
| 3979 |
{ |
| 3980 |
|
| 3981 |
int nibble_load; |
| 3982 |
if (chip->ad_reg_rec) |
| 3983 |
nibble_load = (chip->ad_mem_shift_cnt[1] & 3) == 0 && !chip->ad_mem_shift_cnt0_l[1]; |
| 3984 |
else |
| 3985 |
nibble_load = (chip->ad_mem_shift_cnt[1] & 3) == 0 && chip->ad_mem_w7[1]; |
| 3986 |
|
| 3987 |
if (chip->cclk1) |
| 3988 |
chip->ad_mem_nibble_load = nibble_load; |
| 3989 |
|
| 3990 |
if (nibble_load && !chip->ad_mem_nibble_load) |
| 3991 |
{ |
| 3992 |
int nibble; |
| 3993 |
if (chip->ad_reg_rec) |
| 3994 |
nibble = (chip->ad_mem_data_l4[1] & 15) ^ 8; |
| 3995 |
else |
| 3996 |
nibble = (chip->ad_mem_data_l4[1] >> 4) & 15; |
| 3997 |
chip->ad_mem_nibble = nibble; |
| 3998 |
} |
| 3999 |
|
| 4000 |
chip->ad_mem_nibble_msb = chip->ad_mem_w8[1] && (chip->ad_mem_nibble & 8) != 0; |
| 4001 |
} |
| 4002 |
|
| 4003 |
int write8 = chip->ad_is8 && chip->write3; |
| 4004 |
int read8 = chip->ad_is8 && chip->read3; |
| 4005 |
if (write8 || w25) |
| 4006 |
{ |
| 4007 |
int t3 = 0; |
| 4008 |
if (write8) |
| 4009 |
t3 |= chip->data_bus1 & 255; |
| 4010 |
if (w25) |
| 4011 |
t3 |= chip->ad_mem_data_bus; |
| 4012 |
chip->ad_mem_data_l3 = t3; |
| 4013 |
} |
| 4014 |
if (read8) |
| 4015 |
{ |
| 4016 |
chip->data_bus1 &= ~255; |
| 4017 |
chip->data_bus1 |= chip->ad_mem_data_l3 & 255; |
| 4018 |
} |
| 4019 |
|
| 4020 |
if (!chip->ad_mem_dir) |
| 4021 |
chip->ad_mem_bus = chip->input.dm; |
| 4022 |
|
| 4023 |
if (chip->ad_mem_ctrl_l & 0x400) |
| 4024 |
chip->ad_mem_bus = chip->ad_address_cnt[3][1]; |
| 4025 |
if (chip->ad_mem_ctrl_l & 0x80) |
| 4026 |
{ |
| 4027 |
chip->ad_mem_bus &= ~255; |
| 4028 |
chip->ad_mem_bus = chip->ad_mem_data_l1; |
| 4029 |
} |
| 4030 |
if (p2) |
| 4031 |
chip->ad_mem_data_bus = chip->ad_mem_data_l2; |
| 4032 |
if (w24) |
| 4033 |
chip->ad_mem_data_bus = chip->ad_mem_data_l3; |
| 4034 |
if (p3) |
| 4035 |
chip->ad_mem_data_bus = chip->ad_mem_data_l4[1] ^ 0x88; |
| 4036 |
#else |
| 4037 |
if (chip->cclk1) |
| 4038 |
{ |
| 4039 |
int next_ptr = 0; |
| 4040 |
chip->ad_mem_ctrl = 0; |
| 4041 |
|
| 4042 |
chip->ad_mem_cond[0] = 0; |
| 4043 |
if (p2) |
| 4044 |
chip->ad_mem_cond[0] |= 1; |
| 4045 |
if (w29) |
| 4046 |
chip->ad_mem_cond[0] |= 2; |
| 4047 |
|
| 4048 |
switch (chip->ad_mem_code_ptr[1]) |
| 4049 |
{ |
| 4050 |
case 0x0: |
| 4051 |
chip->ad_mem_ctrl = 0b00100000; |
| 4052 |
break; |
| 4053 |
case 0x1: |
| 4054 |
chip->ad_mem_ctrl = 0b01010000; |
| 4055 |
break; |
| 4056 |
case 0x2: |
| 4057 |
chip->ad_mem_ctrl = 0b01110100; |
| 4058 |
break; |
| 4059 |
case 0x3: |
| 4060 |
chip->ad_mem_ctrl = 0b00010000; |
| 4061 |
break; |
| 4062 |
case 0x4: |
| 4063 |
chip->ad_mem_ctrl = 0b00110000; |
| 4064 |
break; |
| 4065 |
case 0x5: |
| 4066 |
chip->ad_mem_ctrl = 0b10000000; |
| 4067 |
break; |
| 4068 |
case 0x6: |
| 4069 |
chip->ad_mem_ctrl = 0b10000001; |
| 4070 |
break; |
| 4071 |
case 0x7: |
| 4072 |
chip->ad_mem_ctrl = 0b00000010; |
| 4073 |
break; |
| 4074 |
case 0x9: |
| 4075 |
if (chip->ad_stop_match2[1]) |
| 4076 |
next_ptr = 0xf | 0x10; |
| 4077 |
if ((chip->ad_mem_cond[1] & 1) == 0) |
| 4078 |
next_ptr |= 0x9 | 0x10; |
| 4079 |
else |
| 4080 |
{ |
| 4081 |
chip->ad_mem_ctrl = 0b01010000; |
| 4082 |
next_ptr |= 0x2 | 0x10; |
| 4083 |
} |
| 4084 |
break; |
| 4085 |
case 0xf: |
| 4086 |
if ((chip->ad_mem_cond[1] & 2) != 0) |
| 4087 |
{ |
| 4088 |
chip->ad_mem_ctrl = 0b00101000; |
| 4089 |
next_ptr = 0x0 | 0x10; |
| 4090 |
} |
| 4091 |
else |
| 4092 |
next_ptr = 0xf | 0x10; |
| 4093 |
break; |
| 4094 |
} |
| 4095 |
if (chip->ic) |
| 4096 |
{ |
| 4097 |
next_ptr |= 0xf | 0x10; |
| 4098 |
} |
| 4099 |
|
| 4100 |
if (next_ptr & 0x10) |
| 4101 |
chip->ad_mem_code_ptr[0] = next_ptr & 0xf; |
| 4102 |
else |
| 4103 |
chip->ad_mem_code_ptr[0] = (chip->ad_mem_code_ptr[1] + 1) & 0xf; |
| 4104 |
} |
| 4105 |
if (chip->cclk2) |
| 4106 |
{ |
| 4107 |
chip->ad_mem_code_ptr[1] = chip->ad_mem_code_ptr[0]; |
| 4108 |
chip->ad_mem_ctrl_l = chip->ad_mem_ctrl; |
| 4109 |
|
| 4110 |
chip->ad_mem_cond[1] = chip->ad_mem_cond[0]; |
| 4111 |
} |
| 4112 |
|
| 4113 |
if (chip->cclk1) |
| 4114 |
{ |
| 4115 |
chip->ad_end_sel[0] = chip->ad_end_sel[1]; |
| 4116 |
int stop_val; |
| 4117 |
if (chip->ad_end_sel[1] & 1) |
| 4118 |
{ |
| 4119 |
stop_val = ((chip->ad_reg_stop_l & 15) << 8) | 0xff; |
| 4120 |
} |
| 4121 |
else |
| 4122 |
{ |
| 4123 |
stop_val = (chip->ad_reg_stop_h << 4) | ((chip->ad_reg_stop_l >> 4) & 15); |
| 4124 |
} |
| 4125 |
chip->ad_stop_match[0] = chip->ad_stop_match[1] << 1; |
| 4126 |
if (stop_val == chip->ad_address_cnt[1][1]) |
| 4127 |
chip->ad_stop_match[0] |= 1; |
| 4128 |
|
| 4129 |
int rst = (chip->ad_start_sel[1] & 1) != 0; |
| 4130 |
|
| 4131 |
int stop_match = (chip->ad_stop_match[0] & 5) == 5 && (chip->ad_end_sel[1] & 4) != 0; |
| 4132 |
|
| 4133 |
chip->ad_stop_match2[0] = ((stop_match || chip->ad_stop_match2[1]) |
| 4134 |
&& !rst) || reset; |
| 4135 |
|
| 4136 |
chip->ad_start_sel[0] = chip->ad_start_sel[1]; |
| 4137 |
|
| 4138 |
if (chip->ad_mem_ctrl_l & 0x20) |
| 4139 |
{ |
| 4140 |
int add = chip->ad_address_cnt[1][1]; |
| 4141 |
|
| 4142 |
if ((chip->ad_mem_ctrl_l & 0x40) != 0 || chip->ad_address_carry[1]) |
| 4143 |
add++; |
| 4144 |
|
| 4145 |
int carry = ((add >> 12) & 1) != 0; |
| 4146 |
add &= 0xfff; |
| 4147 |
|
| 4148 |
int start_val; |
| 4149 |
if (chip->ad_start_sel[1] & 1) |
| 4150 |
start_val = ((chip->ad_reg_start_l & 15) << 8); |
| 4151 |
else if (chip->ad_start_sel[1] & 2) |
| 4152 |
start_val = (chip->ad_reg_start_h << 4) | ((chip->ad_reg_start_l >> 4) & 15); |
| 4153 |
else |
| 4154 |
start_val = add; |
| 4155 |
|
| 4156 |
chip->ad_address_cnt[0][0] = start_val; |
| 4157 |
chip->ad_address_cnt[1][0] = chip->ad_address_cnt[0][1]; |
| 4158 |
chip->ad_address_carry[0] = carry; |
| 4159 |
} |
| 4160 |
else |
| 4161 |
{ |
| 4162 |
chip->ad_address_cnt[0][0] = chip->ad_address_cnt[0][1]; |
| 4163 |
chip->ad_address_cnt[1][0] = chip->ad_address_cnt[1][1]; |
| 4164 |
chip->ad_address_carry[0] = chip->ad_address_carry[1]; |
| 4165 |
} |
| 4166 |
|
| 4167 |
} |
| 4168 |
if (chip->cclk2) |
| 4169 |
{ |
| 4170 |
chip->ad_end_sel[1] = chip->ad_end_sel[0] << 1; |
| 4171 |
if (chip->ad_mem_ctrl & 4) |
| 4172 |
chip->ad_end_sel[1] |= 1; |
| 4173 |
chip->ad_start_sel[1] = chip->ad_start_sel[0] << 1; |
| 4174 |
if (chip->ad_mem_ctrl & 8) |
| 4175 |
chip->ad_start_sel[1] |= 1; |
| 4176 |
chip->ad_stop_match[1] = chip->ad_stop_match[0]; |
| 4177 |
chip->ad_stop_match2[1] = chip->ad_stop_match2[0]; |
| 4178 |
|
| 4179 |
chip->ad_address_cnt[0][1] = chip->ad_address_cnt[0][0]; |
| 4180 |
chip->ad_address_cnt[1][1] = chip->ad_address_cnt[1][0]; |
| 4181 |
|
| 4182 |
chip->ad_address_carry[1] = chip->ad_address_carry[0]; |
| 4183 |
} |
| 4184 |
|
| 4185 |
if (chip->cclk1) |
| 4186 |
{ |
| 4187 |
int t4; |
| 4188 |
if (p4) |
| 4189 |
t4 = chip->ad_mem_data_l3; |
| 4190 |
else if (chip->ad_mem_w7[1]) |
| 4191 |
t4 = (chip->ad_mem_data_l4[1] & 127) << 1; |
| 4192 |
else |
| 4193 |
t4 = chip->ad_mem_data_l4[1]; |
| 4194 |
|
| 4195 |
chip->ad_mem_data_l4[0] = t4; |
| 4196 |
|
| 4197 |
chip->ad_mem_w7[0] = (chip->ad_code_ctrl_l & 0x1000) != 0; |
| 4198 |
chip->ad_mem_w8[0] = (chip->ad_code_ctrl_l & 0x800) != 0; |
| 4199 |
|
| 4200 |
int add = chip->ad_mem_shift_cnt[1] + chip->ad_mem_w7[1]; |
| 4201 |
int of = (add & 8) != 0; |
| 4202 |
|
| 4203 |
if (!chip->ad_start_l[2]) |
| 4204 |
chip->ad_mem_shift_cnt[0] = 0; |
| 4205 |
else |
| 4206 |
chip->ad_mem_shift_cnt[0] = add & 7; |
| 4207 |
|
| 4208 |
int mem_en = chip->ad_start_l[2]; |
| 4209 |
|
| 4210 |
chip->ad_mem_mem_en_l[0] = mem_en; |
| 4211 |
|
| 4212 |
int w9 = (mem_en && !chip->ad_mem_mem_en_l[1]) || |
| 4213 |
repeat || |
| 4214 |
w23; |
| 4215 |
|
| 4216 |
chip->ad_mem_mem_stop[0] = !mem_en && chip->ad_mem_mem_en_l[1]; |
| 4217 |
|
| 4218 |
int w11 = reset || chip->ad_mem_mem_stop[1] || chip->ad_w13[1] || chip->ad_mem_w21; |
| 4219 |
|
| 4220 |
chip->ad_mem_w10[0] = w9 || (chip->ad_mem_w10[1] && !w11); |
| 4221 |
|
| 4222 |
int w14 = reset || chip->ad_mem_mem_stop[1] || chip->ad_w13[1] || w16; |
| 4223 |
|
| 4224 |
chip->ad_mem_w15[0] = mem_en || (chip->ad_mem_w15[1] && !w14); |
| 4225 |
|
| 4226 |
chip->ad_mem_w17[0] = of; |
| 4227 |
|
| 4228 |
chip->ad_mem_pmpx[0] = (chip->ad_mem_ctrl_l & 0x40) != 0; |
| 4229 |
chip->ad_mem_poe[0] = (chip->ad_mem_ctrl_l & 0x80) != 0; |
| 4230 |
} |
| 4231 |
if (chip->cclk2) |
| 4232 |
{ |
| 4233 |
chip->ad_mem_data_l4[1] = chip->ad_mem_data_l4[0]; |
| 4234 |
|
| 4235 |
chip->ad_mem_w7[1] = chip->ad_mem_w7[0]; |
| 4236 |
chip->ad_mem_w8[1] = chip->ad_mem_w8[0]; |
| 4237 |
|
| 4238 |
chip->ad_mem_shift_cnt[1] = chip->ad_mem_shift_cnt[0]; |
| 4239 |
|
| 4240 |
chip->ad_mem_mem_en_l[1] = chip->ad_mem_mem_en_l[0]; |
| 4241 |
|
| 4242 |
chip->ad_mem_mem_stop[1] = chip->ad_mem_mem_stop[0]; |
| 4243 |
|
| 4244 |
chip->ad_mem_w10[1] = chip->ad_mem_w10[0]; |
| 4245 |
|
| 4246 |
chip->ad_mem_w15[1] = chip->ad_mem_w15[0]; |
| 4247 |
|
| 4248 |
chip->ad_mem_w17[1] = chip->ad_mem_w17[0]; |
| 4249 |
|
| 4250 |
chip->ad_mem_w21 = (chip->ad_mem_ctrl & 2) != 0; |
| 4251 |
|
| 4252 |
chip->ad_mem_dir = (chip->ad_mem_ctrl & 0x10) != 0; |
| 4253 |
|
| 4254 |
chip->ad_mem_pmpx[1] = chip->ad_mem_pmpx[0]; |
| 4255 |
chip->ad_mem_poe[1] = chip->ad_mem_poe[0]; |
| 4256 |
} |
| 4257 |
|
| 4258 |
{ |
| 4259 |
|
| 4260 |
int nibble_load = (chip->ad_mem_shift_cnt[0] & 3) == 0 && chip->ad_mem_w7[0]; |
| 4261 |
|
| 4262 |
if (chip->cclk2) |
| 4263 |
chip->ad_mem_nibble_load = nibble_load; |
| 4264 |
|
| 4265 |
if (nibble_load && !chip->ad_mem_nibble_load) |
| 4266 |
chip->ad_mem_nibble = (chip->ad_mem_data_l4[1] >> 4) & 15;; |
| 4267 |
|
| 4268 |
chip->ad_mem_nibble_msb = chip->ad_mem_w8[1] && (chip->ad_mem_nibble & 8) != 0; |
| 4269 |
} |
| 4270 |
|
| 4271 |
if (chip->ad_mem_ctrl_l & 0x10) |
| 4272 |
chip->ad_mem_bus = chip->ad_address_cnt[1][1] & 0xff; |
| 4273 |
if (!chip->ad_mem_dir) |
| 4274 |
chip->ad_mem_bus = chip->input.pad; |
| 4275 |
if ((chip->ad_mem_ctrl & 1) != 0 && (chip->ad_mem_ctrl_l & 1) == 0) |
| 4276 |
chip->ad_mem_data_l3 = chip->ad_mem_bus; |
| 4277 |
|
| 4278 |
#endif |
| 4279 |
|
| 4280 |
if (chip->cclk1) |
| 4281 |
{ |
| 4282 |
#ifdef FMOPNA_YM2608 |
| 4283 |
#define PLAYBACK_BIT 0x40 |
| 4284 |
#else |
| 4285 |
#define PLAYBACK_BIT 0x00 |
| 4286 |
#endif |
| 4287 |
int w44 = (chip->ad_dsp_cnt1_run[1] & 3) == 0; |
| 4288 |
|
| 4289 |
int next_ptr = 0; |
| 4290 |
chip->ad_code_ctrl = 0; |
| 4291 |
int carry_mode = 0; |
| 4292 |
int vol_o = 0; |
| 4293 |
|
| 4294 |
switch (chip->ad_code_ptr[1]) |
| 4295 |
{ |
| 4296 |
#ifdef FMOPNA_YM2608 |
| 4297 |
case 0x3f: |
| 4298 |
#endif |
| 4299 |
case 0x3f|PLAYBACK_BIT: |
| 4300 |
if (w29) |
| 4301 |
{ |
| 4302 |
chip->ad_code_ctrl = 0b000100000011110011001; |
| 4303 |
next_ptr = 0x32; |
| 4304 |
} |
| 4305 |
else |
| 4306 |
next_ptr = 0x3f; |
| 4307 |
break; |
| 4308 |
#ifdef FMOPNA_YM2608 |
| 4309 |
case 0x32: |
| 4310 |
#endif |
| 4311 |
case 0x32|PLAYBACK_BIT: |
| 4312 |
chip->ad_code_ctrl = 0b000100000001110111001; |
| 4313 |
break; |
| 4314 |
#ifdef FMOPNA_YM2608 |
| 4315 |
case 0x33: |
| 4316 |
#endif |
| 4317 |
case 0x33|PLAYBACK_BIT: |
| 4318 |
chip->ad_code_ctrl = 0b000100000000110111101; |
| 4319 |
break; |
| 4320 |
#ifdef FMOPNA_YM2608 |
| 4321 |
case 0x34: |
| 4322 |
#endif |
| 4323 |
case 0x34|PLAYBACK_BIT: |
| 4324 |
chip->ad_code_ctrl = 0b000100000000110011011; |
| 4325 |
break; |
| 4326 |
#ifdef FMOPNA_YM2608 |
| 4327 |
case 0x35: |
| 4328 |
#endif |
| 4329 |
case 0x35|PLAYBACK_BIT: |
| 4330 |
chip->ad_code_ctrl = 0b000100000000110111011; |
| 4331 |
break; |
| 4332 |
#ifdef FMOPNA_YM2608 |
| 4333 |
case 0x36: |
| 4334 |
#endif |
| 4335 |
case 0x36|PLAYBACK_BIT: |
| 4336 |
chip->ad_code_ctrl = 0b000100000000010011100; |
| 4337 |
break; |
| 4338 |
#ifdef FMOPNA_YM2608 |
| 4339 |
case 0x3b: |
| 4340 |
next_ptr = 0x31; |
| 4341 |
break; |
| 4342 |
#endif |
| 4343 |
case 0x37|PLAYBACK_BIT: |
| 4344 |
chip->ad_code_ctrl = 0b000100000000110011111; |
| 4345 |
break; |
| 4346 |
case 0x38|PLAYBACK_BIT: |
| 4347 |
chip->ad_code_ctrl = 0b000100000000110111111; |
| 4348 |
break; |
| 4349 |
case 0x39|PLAYBACK_BIT: |
| 4350 |
chip->ad_code_ctrl = 0b000000000000110011001; |
| 4351 |
break; |
| 4352 |
case 0x3a|PLAYBACK_BIT: |
| 4353 |
if (!p5) |
| 4354 |
{ |
| 4355 |
next_ptr = 0x3a; |
| 4356 |
chip->ad_code_ctrl = 0b000000000000110011001; |
| 4357 |
} |
| 4358 |
break; |
| 4359 |
case 0x3b|PLAYBACK_BIT: |
| 4360 |
if (chip->ad_code_sync[2]) |
| 4361 |
{ |
| 4362 |
chip->ad_code_ctrl = 0b000000100010110010000; |
| 4363 |
next_ptr = 0x7; |
| 4364 |
} |
| 4365 |
else |
| 4366 |
next_ptr = 0x3b; |
| 4367 |
break; |
| 4368 |
|
| 4369 |
#ifdef FMOPNA_YM2608 |
| 4370 |
case 0x01: |
| 4371 |
chip->ad_code_ctrl = 0b000011000010000000000; |
| 4372 |
break; |
| 4373 |
case 0x02: |
| 4374 |
chip->ad_code_ctrl = 0b000010001000110010000; |
| 4375 |
break; |
| 4376 |
case 0x03: |
| 4377 |
chip->ad_code_ctrl = 0b001110000000000000010; |
| 4378 |
break; |
| 4379 |
case 0x04: |
| 4380 |
chip->ad_code_ctrl = 0b000110000000000100010; |
| 4381 |
break; |
| 4382 |
case 0x05: |
| 4383 |
if (chip->ad_dsp_enc_bit_l[1]) |
| 4384 |
chip->ad_code_ctrl = 0b100011000000010000010; |
| 4385 |
else |
| 4386 |
{ |
| 4387 |
chip->ad_code_ctrl = 0b100010100000000000010; |
| 4388 |
next_ptr = 0xa; |
| 4389 |
} |
| 4390 |
break; |
| 4391 |
case 0x06: |
| 4392 |
chip->ad_code_ctrl = 0b100010000000000100010; |
| 4393 |
break; |
| 4394 |
case 0x07: |
| 4395 |
chip->ad_code_ctrl = 0b001110000000000000010; |
| 4396 |
break; |
| 4397 |
case 0x08: |
| 4398 |
chip->ad_code_ctrl = 0b000110000000000100010; |
| 4399 |
break; |
| 4400 |
case 0x09: |
| 4401 |
chip->ad_code_ctrl = 0b100010100000000000010; |
| 4402 |
break; |
| 4403 |
case 0x0a: |
| 4404 |
chip->ad_code_ctrl = 0b100010000000000100010; |
| 4405 |
break; |
| 4406 |
case 0x0b: |
| 4407 |
chip->ad_code_ctrl = 0b100011000000000000100; |
| 4408 |
break; |
| 4409 |
case 0x0c: |
| 4410 |
chip->ad_code_ctrl = 0b100010001000000100100; |
| 4411 |
break; |
| 4412 |
case 0x0e: |
| 4413 |
chip->ad_code_ctrl = 0b000000000000010000000; |
| 4414 |
break; |
| 4415 |
case 0x0f: |
| 4416 |
if (chip->ad_dsp_enc_bit_l[1]) |
| 4417 |
{ |
| 4418 |
next_ptr = 0x13; |
| 4419 |
chip->ad_code_ctrl = 0b100000100000000000000; |
| 4420 |
} |
| 4421 |
break; |
| 4422 |
case 0x10: |
| 4423 |
chip->ad_code_ctrl = 0b011100100000000000000; |
| 4424 |
break; |
| 4425 |
case 0x11: |
| 4426 |
chip->ad_code_ctrl = 0b000100000000010110000; |
| 4427 |
break; |
| 4428 |
case 0x12: |
| 4429 |
next_ptr = 0x15; |
| 4430 |
break; |
| 4431 |
case 0x13: |
| 4432 |
chip->ad_code_ctrl = 0b100000000000010110000; |
| 4433 |
break; |
| 4434 |
case 0x15: |
| 4435 |
chip->ad_code_ctrl = 0b011001000000000000000; |
| 4436 |
break; |
| 4437 |
case 0x17: |
| 4438 |
chip->ad_code_ctrl = 0b100010100000100010010; |
| 4439 |
break; |
| 4440 |
case 0x18: |
| 4441 |
chip->ad_code_ctrl = 0b100010001000100110010; |
| 4442 |
break; |
| 4443 |
case 0x1a: |
| 4444 |
chip->ad_code_ctrl = 0b000000000000010000000; |
| 4445 |
break; |
| 4446 |
case 0x1b: |
| 4447 |
if (chip->ad_dsp_enc_bit_l[1]) |
| 4448 |
{ |
| 4449 |
next_ptr = 0x20; |
| 4450 |
chip->ad_code_ctrl = 0b100001000000000000100; |
| 4451 |
} |
| 4452 |
else |
| 4453 |
chip->ad_code_ctrl = 0b000000000000100010000; |
| 4454 |
break; |
| 4455 |
case 0x1c: |
| 4456 |
chip->ad_code_ctrl = 0b000000000000100010000; |
| 4457 |
break; |
| 4458 |
case 0x1d: |
| 4459 |
chip->ad_code_ctrl = 0b001100000000100010000; |
| 4460 |
break; |
| 4461 |
case 0x1e: |
| 4462 |
chip->ad_code_ctrl = 0b000100000000000100000; |
| 4463 |
break; |
| 4464 |
case 0x1f: |
| 4465 |
chip->ad_code_ctrl = 0b100001000000000000100; |
| 4466 |
break; |
| 4467 |
case 0x20: |
| 4468 |
chip->ad_code_ctrl = 0b100000000000000100100; |
| 4469 |
break; |
| 4470 |
case 0x21: |
| 4471 |
if (!chip->ad_dsp_alu_mask[1] && chip->ad_dsp_alu_shift == 2) |
| 4472 |
chip->ad_code_ctrl = 0b000000000000000011000; |
| 4473 |
else |
| 4474 |
{ |
| 4475 |
next_ptr = 0x13; |
| 4476 |
chip->ad_code_ctrl = 0b100000100000000000000; |
| 4477 |
} |
| 4478 |
break; |
| 4479 |
case 0x22: |
| 4480 |
chip->ad_code_ctrl = 0b100000000000010010100; |
| 4481 |
break; |
| 4482 |
case 0x23: |
| 4483 |
chip->ad_code_ctrl = 0b100000000000000100100; |
| 4484 |
break; |
| 4485 |
case 0x24: |
| 4486 |
chip->ad_code_ctrl = 0b100000100000000000000; |
| 4487 |
break; |
| 4488 |
case 0x25: |
| 4489 |
chip->ad_code_ctrl = 0b100000000000000100000; |
| 4490 |
break; |
| 4491 |
case 0x26: |
| 4492 |
chip->ad_code_ctrl = 0b001100000000000000000; |
| 4493 |
break; |
| 4494 |
case 0x27: |
| 4495 |
chip->ad_code_ctrl = 0b000100000000000100000; |
| 4496 |
break; |
| 4497 |
case 0x28: |
| 4498 |
chip->ad_code_ctrl = 0b100001000000110010000; |
| 4499 |
break; |
| 4500 |
case 0x29: |
| 4501 |
chip->ad_code_ctrl = 0b100000000100000100000; |
| 4502 |
break; |
| 4503 |
case 0x2a: |
| 4504 |
chip->ad_code_ctrl = 0b000000100110100011000; |
| 4505 |
break; |
| 4506 |
case 0x2b: |
| 4507 |
chip->ad_code_ctrl = 0b000000000100000000000; |
| 4508 |
break; |
| 4509 |
case 0x2c: |
| 4510 |
chip->ad_code_ctrl = 0b001000000111000000000; |
| 4511 |
break; |
| 4512 |
case 0x2d: |
| 4513 |
chip->ad_code_ctrl = 0b000000000001000000000; |
| 4514 |
break; |
| 4515 |
case 0x2e: |
| 4516 |
chip->ad_code_ctrl = 0b000100000000001000100; |
| 4517 |
break; |
| 4518 |
case 0x2f: |
| 4519 |
chip->ad_code_ctrl = 0b000100000000000100100; |
| 4520 |
break; |
| 4521 |
case 0x31: |
| 4522 |
if (chip->ad_w12[1] & 1) |
| 4523 |
next_ptr = 0x3f; |
| 4524 |
if (chip->ad_ad_w56) |
| 4525 |
{ |
| 4526 |
next_ptr |= 1; |
| 4527 |
chip->ad_code_ctrl = 0b000010010000100001000; |
| 4528 |
} |
| 4529 |
else |
| 4530 |
next_ptr |= 0x31; |
| 4531 |
break; |
| 4532 |
#endif |
| 4533 |
|
| 4534 |
case 0x01|PLAYBACK_BIT: |
| 4535 |
chip->ad_code_ctrl = 0b100000000000110110010; |
| 4536 |
break; |
| 4537 |
case 0x02|PLAYBACK_BIT: |
| 4538 |
chip->ad_code_ctrl = 0b000001000000000001000; |
| 4539 |
break; |
| 4540 |
case 0x03|PLAYBACK_BIT: |
| 4541 |
chip->ad_code_ctrl = 0b000000000000100000000; |
| 4542 |
break; |
| 4543 |
case 0x04|PLAYBACK_BIT: |
| 4544 |
chip->ad_code_ctrl = 0b001100000000100000010; |
| 4545 |
break; |
| 4546 |
case 0x05|PLAYBACK_BIT: |
| 4547 |
chip->ad_code_ctrl = 0b000100000000100100010; |
| 4548 |
break; |
| 4549 |
case 0x06|PLAYBACK_BIT: |
| 4550 |
if (chip->ad_dsp_alu_of) |
| 4551 |
chip->ad_code_ctrl = 0b000000100010110010000; |
| 4552 |
else |
| 4553 |
{ |
| 4554 |
next_ptr = 0x24; |
| 4555 |
chip->ad_code_ctrl = 0b100000000000010101010; |
| 4556 |
} |
| 4557 |
break; |
| 4558 |
case 0x08|PLAYBACK_BIT: |
| 4559 |
chip->ad_code_ctrl = 0b100001000000000000000; |
| 4560 |
break; |
| 4561 |
case 0x09|PLAYBACK_BIT: |
| 4562 |
chip->ad_code_ctrl = 0b100000000000000100000; |
| 4563 |
break; |
| 4564 |
case 0x0a|PLAYBACK_BIT: |
| 4565 |
chip->ad_code_ctrl = 0b011000001011000000000; |
| 4566 |
break; |
| 4567 |
case 0x0b|PLAYBACK_BIT: |
| 4568 |
chip->ad_code_ctrl = 0b000000000001010000000; |
| 4569 |
break; |
| 4570 |
case 0x0c|PLAYBACK_BIT: |
| 4571 |
chip->ad_code_ctrl = 0b000000000000000011000; |
| 4572 |
break; |
| 4573 |
case 0x0d|PLAYBACK_BIT: |
| 4574 |
chip->ad_code_ctrl = 0b100001001000000000100; |
| 4575 |
if (chip->ad_mem_data_l4[0] & 128) |
| 4576 |
chip->ad_code_ctrl |= 0b000000100000000000000; |
| 4577 |
break; |
| 4578 |
case 0x0e|PLAYBACK_BIT: |
| 4579 |
chip->ad_code_ctrl = 0b100000000000010110100; |
| 4580 |
break; |
| 4581 |
case 0x0f|PLAYBACK_BIT: |
| 4582 |
if ((chip->ad_mem_data_l4[0] & 128) == 0) |
| 4583 |
chip->ad_code_ctrl = 0b000000000000000010000; |
| 4584 |
break; |
| 4585 |
case 0x10|PLAYBACK_BIT: |
| 4586 |
if ((chip->ad_mem_data_l4[0] & 128) == 0) |
| 4587 |
chip->ad_code_ctrl = 0b000000000000000010000; |
| 4588 |
break; |
| 4589 |
case 0x11|PLAYBACK_BIT: |
| 4590 |
case 0x15|PLAYBACK_BIT: |
| 4591 |
chip->ad_code_ctrl = 0b011000101000100011000; |
| 4592 |
break; |
| 4593 |
case 0x12|PLAYBACK_BIT: |
| 4594 |
case 0x16|PLAYBACK_BIT: |
| 4595 |
chip->ad_code_ctrl = 0b000000000000010010000; |
| 4596 |
break; |
| 4597 |
case 0x13|PLAYBACK_BIT: |
| 4598 |
if ((chip->ad_mem_data_l4[0] & 128) == 0) |
| 4599 |
chip->ad_code_ctrl = 0b000000000000000010000; |
| 4600 |
break; |
| 4601 |
case 0x14|PLAYBACK_BIT: |
| 4602 |
if ((chip->ad_mem_data_l4[0] & 128) == 0) |
| 4603 |
chip->ad_code_ctrl = 0b000000000000000010000; |
| 4604 |
break; |
| 4605 |
case 0x18|PLAYBACK_BIT: |
| 4606 |
chip->ad_code_ctrl = 0b011001000000010010000; |
| 4607 |
break; |
| 4608 |
case 0x1a|PLAYBACK_BIT: |
| 4609 |
chip->ad_code_ctrl = 0b100000100100010010110; |
| 4610 |
carry_mode = 1; |
| 4611 |
break; |
| 4612 |
case 0x1b|PLAYBACK_BIT: |
| 4613 |
chip->ad_code_ctrl = 0b100000000100000100110; |
| 4614 |
carry_mode = 1; |
| 4615 |
break; |
| 4616 |
case 0x1c|PLAYBACK_BIT: |
| 4617 |
chip->ad_code_ctrl = 0b001100000100000000000; |
| 4618 |
carry_mode = 1; |
| 4619 |
break; |
| 4620 |
case 0x1d|PLAYBACK_BIT: |
| 4621 |
chip->ad_code_ctrl = 0b000100000100000100000; |
| 4622 |
carry_mode = 1; |
| 4623 |
break; |
| 4624 |
case 0x1e|PLAYBACK_BIT: |
| 4625 |
chip->ad_code_ctrl = 0b000000000100010000000; |
| 4626 |
break; |
| 4627 |
case 0x1f|PLAYBACK_BIT: |
| 4628 |
chip->ad_code_ctrl = 0b001100000100000000110; |
| 4629 |
break; |
| 4630 |
case 0x20|PLAYBACK_BIT: |
| 4631 |
chip->ad_code_ctrl = 0b000100000000000100110; |
| 4632 |
break; |
| 4633 |
case 0x21|PLAYBACK_BIT: |
| 4634 |
chip->ad_code_ctrl = 0b000100000000001000100; |
| 4635 |
break; |
| 4636 |
case 0x22|PLAYBACK_BIT: |
| 4637 |
chip->ad_code_ctrl = 0b000100000000000100100; |
| 4638 |
break; |
| 4639 |
case 0x23|PLAYBACK_BIT: |
| 4640 |
chip->ad_code_ctrl = 0b100000000000010101010; |
| 4641 |
break; |
| 4642 |
case 0x24|PLAYBACK_BIT: |
| 4643 |
chip->ad_code_ctrl = 0b100000000000000000000; |
| 4644 |
break; |
| 4645 |
case 0x25|PLAYBACK_BIT: |
| 4646 |
chip->ad_code_ctrl = 0b100000000000000100000; |
| 4647 |
break; |
| 4648 |
case 0x26|PLAYBACK_BIT: |
| 4649 |
chip->ad_code_ctrl = 0b000000100010000000000; |
| 4650 |
break; |
| 4651 |
case 0x29|PLAYBACK_BIT: |
| 4652 |
if (!w44) |
| 4653 |
next_ptr = 0x29; |
| 4654 |
else |
| 4655 |
chip->ad_code_ctrl = 0b000001000000111010000; |
| 4656 |
break; |
| 4657 |
case 0x2b|PLAYBACK_BIT: |
| 4658 |
chip->ad_code_ctrl = 0b000000000000110001000; |
| 4659 |
vol_o = 1; |
| 4660 |
break; |
| 4661 |
case 0x2c|PLAYBACK_BIT: |
| 4662 |
chip->ad_code_ctrl = 0b001000000000000000000; |
| 4663 |
break; |
| 4664 |
case 0x2f|PLAYBACK_BIT: |
| 4665 |
if (chip->ad_w12[1] & 1) |
| 4666 |
next_ptr = 0x3f; |
| 4667 |
if (chip->ad_code_sync[2]) |
| 4668 |
{ |
| 4669 |
next_ptr |= 1; |
| 4670 |
chip->ad_code_ctrl = 0b100000100000000000010; |
| 4671 |
} |
| 4672 |
else |
| 4673 |
next_ptr |= 0x2f; |
| 4674 |
break; |
| 4675 |
} |
| 4676 |
|
| 4677 |
#ifdef FMOPNA_YM2608 |
| 4678 |
if (!chip->ad_reg_rec) |
| 4679 |
next_ptr |= 64; // dec/enc |
| 4680 |
#endif |
| 4681 |
|
| 4682 |
if (reset) |
| 4683 |
next_ptr |= 63; // reset |
| 4684 |
|
| 4685 |
if (next_ptr & 63) |
| 4686 |
chip->ad_code_ptr[0] = next_ptr; |
| 4687 |
else |
| 4688 |
#ifdef FMOPNA_YM2608 |
| 4689 |
chip->ad_code_ptr[0] = (chip->ad_code_ptr[1] + 1) & 127; |
| 4690 |
#else |
| 4691 |
chip->ad_code_ptr[0] = (chip->ad_code_ptr[1] + 1) & 63; |
| 4692 |
#endif |
| 4693 |
|
| 4694 |
chip->ad_code_end[0] = (chip->ad_code_ptr[1] & 63) == 63; |
| 4695 |
|
| 4696 |
chip->ad_dsp_carry_mode[0] = carry_mode; |
| 4697 |
|
| 4698 |
#ifdef FMOPNA_YM2608 |
| 4699 |
chip->ad_dsp_enc_bit_l[0] = chip->ad_dsp_enc_bit; |
| 4700 |
#endif |
| 4701 |
|
| 4702 |
chip->ad_dsp_vol_o[0] = vol_o; |
| 4703 |
} |
| 4704 |
if (chip->cclk2) |
| 4705 |
{ |
| 4706 |
chip->ad_code_ptr[1] = chip->ad_code_ptr[0]; |
| 4707 |
chip->ad_code_end[1] = chip->ad_code_end[0]; |
| 4708 |
chip->ad_code_ctrl_l = chip->ad_code_ctrl; |
| 4709 |
|
| 4710 |
chip->ad_dsp_ctrl = 0; |
| 4711 |
if (chip->ad_code_ctrl & 8) |
| 4712 |
chip->ad_dsp_ctrl |= 1; |
| 4713 |
if (chip->ad_code_ctrl & 16) |
| 4714 |
chip->ad_dsp_ctrl |= 2; |
| 4715 |
if (chip->ad_code_ctrl & 0x80) |
| 4716 |
chip->ad_dsp_ctrl |= 4; |
| 4717 |
if (chip->ad_code_ctrl & 0x100) |
| 4718 |
chip->ad_dsp_ctrl |= 8; |
| 4719 |
|
| 4720 |
chip->ad_dsp_carry_mode[1] = chip->ad_dsp_carry_mode[0]; |
| 4721 |
|
| 4722 |
#ifdef FMOPNA_YM2608 |
| 4723 |
chip->ad_dsp_enc_bit_l[1] = chip->ad_dsp_enc_bit_l[0]; |
| 4724 |
#endif |
| 4725 |
|
| 4726 |
chip->ad_code_reg_id = 0; |
| 4727 |
if (chip->ad_code_ctrl & 32) |
| 4728 |
chip->ad_code_reg_id |= 1; |
| 4729 |
if (chip->ad_code_ctrl & 4) |
| 4730 |
chip->ad_code_reg_id |= 2; |
| 4731 |
if (chip->ad_code_ctrl & 2) |
| 4732 |
chip->ad_code_reg_id |= 4; |
| 4733 |
|
| 4734 |
chip->ad_dsp_vol_o[1] = chip->ad_dsp_vol_o[0]; |
| 4735 |
} |
| 4736 |
|
| 4737 |
int w30 = chip->ad_dsp_ctrl == 5 || chip->ad_dsp_ctrl == 13; |
| 4738 |
int w31 = chip->ad_dsp_ctrl == 5 || chip->ad_dsp_ctrl == 13 |
| 4739 |
|| chip->ad_dsp_ctrl == 3; |
| 4740 |
|
| 4741 |
int w35 = chip->ad_dsp_w36[1]; |
| 4742 |
if ((chip->ad_dsp_w31_l[1] & 2) != 0) |
| 4743 |
w35 |= chip->ad_dsp_w33; |
| 4744 |
|
| 4745 |
int cnt1; |
| 4746 |
if ((chip->ad_dsp_w31_l[1] & 2) != 0) |
| 4747 |
cnt1 = 0; |
| 4748 |
else |
| 4749 |
{ |
| 4750 |
int inc = (chip->ad_dsp_cnt1_run[1] & 1) != 0; |
| 4751 |
cnt1 = (chip->ad_dsp_cnt1[1] + inc) & 7; |
| 4752 |
} |
| 4753 |
|
| 4754 |
if (chip->ad_dsp_ctrl == 1) |
| 4755 |
chip->ad_dsp_bus = chip->ad_reg_delta_l; |
| 4756 |
if (chip->ad_dsp_delta_sel[1]) |
| 4757 |
chip->ad_dsp_bus = chip->ad_reg_delta_h; |
| 4758 |
if ((chip->ad_code_ctrl_l & 0x40) != 0) |
| 4759 |
chip->ad_dsp_bus = chip->ad_dsp_w45 & 255; |
| 4760 |
if (chip->ad_dsp_w46[1]) |
| 4761 |
chip->ad_dsp_bus = (chip->ad_dsp_w45 >> 8) & 255; |
| 4762 |
if (chip->ad_dsp_ctrl == 3) |
| 4763 |
{ |
| 4764 |
static const int adjust[8] = { |
| 4765 |
57, 57, 57, 57, 77, 102, 128, 153 |
| 4766 |
}; |
| 4767 |
|
| 4768 |
chip->ad_dsp_bus = adjust[chip->ad_mem_nibble & 7]; |
| 4769 |
} |
| 4770 |
|
| 4771 |
if ((chip->ad_code_ctrl_l & 0x40000) != 0) |
| 4772 |
chip->ad_dsp_bus = chip->ad_dsp_alu_res & 255; |
| 4773 |
if (chip->ad_dsp_read_res[1]) |
| 4774 |
chip->ad_dsp_bus = (chip->ad_dsp_alu_res >> 8) & 255; |
| 4775 |
|
| 4776 |
#ifdef FMOPNA_YM2608 |
| 4777 |
if ((chip->ad_code_ctrl_l & 0x2000) != 0) |
| 4778 |
chip->ad_dsp_bus = chip->ad_ad_buf; |
| 4779 |
#endif |
| 4780 |
if (chip->ad_dsp_vol_o[1]) |
| 4781 |
chip->ad_dsp_bus = chip->ad_reg_level; |
| 4782 |
if ((chip->ad_code_ctrl_l & 0x200) == 0 && chip->ad_dsp_w69[1]) |
| 4783 |
chip->ad_dsp_bus = chip->ad_dsp_sregs2[0][1]; |
| 4784 |
if ((chip->ad_code_ctrl_l & 0x200) == 0 && (chip->ad_code_ctrl_l & 0x400) != 0) |
| 4785 |
chip->ad_dsp_bus = chip->ad_dsp_sregs2[1][1]; |
| 4786 |
if (chip->ad_dsp_ctrl == 7) |
| 4787 |
chip->ad_dsp_bus = 127; |
| 4788 |
if (chip->ad_dsp_ctrl == 15) |
| 4789 |
chip->ad_dsp_bus = 0; |
| 4790 |
|
| 4791 |
if (chip->cclk1) |
| 4792 |
{ |
| 4793 |
chip->ad_dsp_delta_sel[0] = chip->ad_dsp_ctrl == 1; |
| 4794 |
|
| 4795 |
chip->ad_dsp_w30_l[0] = chip->ad_dsp_w30_l[1] << 1; |
| 4796 |
chip->ad_dsp_w30_l[0] |= w30; |
| 4797 |
|
| 4798 |
chip->ad_dsp_w31_l[0] = chip->ad_dsp_w31_l[1] << 1; |
| 4799 |
chip->ad_dsp_w31_l[0] |= w31; |
| 4800 |
|
| 4801 |
chip->ad_dsp_w36[0] = w35 >> 1; |
| 4802 |
chip->ad_dsp_w35_l = w35 & 1; |
| 4803 |
|
| 4804 |
chip->ad_dsp_cnt1[0] = cnt1; |
| 4805 |
|
| 4806 |
chip->ad_dsp_cnt1_run[0] = chip->ad_dsp_cnt1_run[1]; |
| 4807 |
|
| 4808 |
int accm2 = chip->ad_dsp_mul_accm2_add1 + chip->ad_dsp_mul_accm2_add2 + chip->ad_dsp_mul_accm1_c; |
| 4809 |
|
| 4810 |
chip->ad_dsp_mul_accm1_add1 = (w35 & 1) != 0 ? chip->ad_dsp_w34 : 0; |
| 4811 |
chip->ad_dsp_mul_accm1_add2 = cnt1 != 0 ? (chip->ad_dsp_mul_accm1[0] >> 1) | ((accm2 & 1) << 7) : 0; |
| 4812 |
|
| 4813 |
chip->ad_dsp_mul_accm1[1] = chip->ad_dsp_mul_accm1[0]; |
| 4814 |
|
| 4815 |
chip->ad_dsp_w32_l = chip->ad_dsp_w32; |
| 4816 |
|
| 4817 |
chip->ad_dsp_mul_accm2_load = cnt1 != 0; |
| 4818 |
|
| 4819 |
chip->ad_dsp_mul_accm2 = accm2 & 0x1ff; |
| 4820 |
|
| 4821 |
chip->ad_dsp_w38[0] = chip->ad_dsp_w38[1] << 1; |
| 4822 |
if (cnt1 != 0 && (chip->ad_dsp_mul_accm1[0] & 1) != 0) |
| 4823 |
chip->ad_dsp_w38[0] |= 1; |
| 4824 |
|
| 4825 |
chip->ad_dsp_w41[0] = chip->ad_dsp_w41[1] << 1; |
| 4826 |
if (chip->ad_dsp_ctrl == 11) |
| 4827 |
chip->ad_dsp_w41[0] |= 1; |
| 4828 |
|
| 4829 |
chip->ad_dsp_w43[0] = (chip->ad_dsp_w43[1] << 1) | ((chip->ad_dsp_cnt1_run[1] & 3) == 2); |
| 4830 |
|
| 4831 |
chip->ad_dsp_w46[0] = (chip->ad_code_ctrl_l & 0x40) != 0; |
| 4832 |
|
| 4833 |
if (chip->ad_dsp_ctrl == 14) |
| 4834 |
chip->ad_dsp_cnt2[0] = 0; |
| 4835 |
else |
| 4836 |
{ |
| 4837 |
int add = chip->ad_dsp_ctrl == 6; |
| 4838 |
chip->ad_dsp_cnt2[0] = (chip->ad_dsp_cnt2[1] + add) & 3; |
| 4839 |
} |
| 4840 |
|
| 4841 |
#ifdef FMOPNA_YM2608 |
| 4842 |
chip->ad_dsp_ctrl10_l = chip->ad_dsp_ctrl == 10; |
| 4843 |
#endif |
| 4844 |
|
| 4845 |
chip->ad_dsp_load_alu1[0] = chip->ad_dsp_load_alu1[1] << 1; |
| 4846 |
chip->ad_dsp_load_alu2[0] = chip->ad_dsp_load_alu2[1] << 1; |
| 4847 |
|
| 4848 |
chip->ad_dsp_load_alu1_h = (chip->ad_dsp_load_alu1[1] & 1) != 0 |
| 4849 |
#ifdef FMOPNA_YM2608 |
| 4850 |
|| chip->ad_dsp_ctrl == 9 |
| 4851 |
#endif |
| 4852 |
; |
| 4853 |
|
| 4854 |
if ((chip->ad_code_ctrl_l & 0x4000) != 0) |
| 4855 |
chip->ad_dsp_load_alu1[0] |= 1; |
| 4856 |
if ((chip->ad_code_ctrl_l & 0x8000) != 0) |
| 4857 |
chip->ad_dsp_load_alu2[0] |= 1; |
| 4858 |
|
| 4859 |
chip->ad_dsp_load_res[0] = (chip->ad_code_ctrl_l & 0x80000) != 0; |
| 4860 |
|
| 4861 |
chip->ad_dsp_alu_mask[0] = chip->ad_dsp_ctrl == 2; |
| 4862 |
|
| 4863 |
#ifdef FMOPNA_YM2608 |
| 4864 |
chip->ad_dsp_alu_neg[0] = (chip->ad_code_ctrl_l & 0x10000) != 0; |
| 4865 |
#endif |
| 4866 |
|
| 4867 |
chip->ad_dsp_read_res[0] = (chip->ad_code_ctrl_l & 0x40000) != 0; |
| 4868 |
chip->ad_dsp_w52[0] = (chip->ad_code_ctrl_l & 0x2000) != 0; |
| 4869 |
|
| 4870 |
chip->ad_dsp_sregs2[0][0] = (chip->ad_dsp_w69[1] && (chip->ad_code_ctrl_l & 0x200) != 0) ? chip->ad_dsp_bus : chip->ad_dsp_sregs2[0][1]; |
| 4871 |
chip->ad_dsp_sregs2[1][0] = ((chip->ad_code_ctrl_l & 0x400) != 0 && (chip->ad_code_ctrl_l & 0x200) != 0) ? chip->ad_dsp_bus : chip->ad_dsp_sregs2[1][1]; |
| 4872 |
|
| 4873 |
chip->ad_dsp_w69[0] = (chip->ad_code_ctrl_l & 0x400) != 0; |
| 4874 |
} |
| 4875 |
if (chip->cclk2) |
| 4876 |
{ |
| 4877 |
chip->ad_dsp_delta_sel[1] = chip->ad_dsp_delta_sel[0]; |
| 4878 |
chip->ad_dsp_w30_l[1] = chip->ad_dsp_w30_l[0]; |
| 4879 |
chip->ad_dsp_w31_l[1] = chip->ad_dsp_w31_l[0]; |
| 4880 |
|
| 4881 |
chip->ad_dsp_w36[1] = chip->ad_dsp_w36[0]; |
| 4882 |
|
| 4883 |
chip->ad_dsp_cnt1[1] = chip->ad_dsp_cnt1[0]; |
| 4884 |
|
| 4885 |
chip->ad_dsp_cnt1_run[1] = chip->ad_dsp_cnt1_run[0] << 1; |
| 4886 |
if (chip->ad_dsp_cnt1[0] != 7) |
| 4887 |
chip->ad_dsp_cnt1_run[1] |= 1; |
| 4888 |
|
| 4889 |
int accm1 = chip->ad_dsp_mul_accm1_add1 + chip->ad_dsp_mul_accm1_add2; |
| 4890 |
|
| 4891 |
chip->ad_dsp_mul_accm1_c = (accm1 & 256) != 0; |
| 4892 |
|
| 4893 |
chip->ad_dsp_mul_accm1[0] = accm1 & 255; |
| 4894 |
|
| 4895 |
int w37 = (chip->ad_dsp_w38[0] & 2) == 0 && (chip->ad_dsp_mul_accm1[1] & 63) == 0; |
| 4896 |
int w39 = (chip->ad_dsp_mul_accm1[1] & 192) == 0 && (chip->ad_dsp_mul_accm2 & 511) == 0; |
| 4897 |
|
| 4898 |
int b8 = (chip->ad_dsp_w32_l & 0x100) == 0 && !(w37 && w39); |
| 4899 |
|
| 4900 |
chip->ad_dsp_mul_accm2_add1 = chip->ad_dsp_w35_l ? (chip->ad_dsp_w32_l ^ 0x100) : 0; |
| 4901 |
chip->ad_dsp_mul_accm2_add2 = chip->ad_dsp_mul_accm2_load ? (chip->ad_dsp_mul_accm2 >> 1) | (b8 << 8) : 0; |
| 4902 |
|
| 4903 |
|
| 4904 |
chip->ad_dsp_w38[1] = chip->ad_dsp_w38[0]; |
| 4905 |
|
| 4906 |
chip->ad_dsp_w41[1] = chip->ad_dsp_w41[0]; |
| 4907 |
|
| 4908 |
int w42 = (chip->ad_dsp_mul_accm2 & 0x1c0) != 0x00 || (chip->ad_dsp_mul_accm2 & 0x30) == 0x30; |
| 4909 |
|
| 4910 |
if (chip->ad_dsp_w41[0] & 2) |
| 4911 |
{ |
| 4912 |
chip->ad_dsp_w40 = 0; |
| 4913 |
if (!w42) |
| 4914 |
{ |
| 4915 |
if ((chip->ad_dsp_w38[0] & 2) != 0) |
| 4916 |
chip->ad_dsp_w40 |= 1; |
| 4917 |
chip->ad_dsp_w40 |= (chip->ad_dsp_mul_accm1[1] & 255) << 1; |
| 4918 |
chip->ad_dsp_w40 |= (chip->ad_dsp_mul_accm2 & 15) << 9; |
| 4919 |
} |
| 4920 |
chip->ad_dsp_w40 |= (chip->ad_dsp_mul_accm2 & 0x30) << 9; |
| 4921 |
if (w42) |
| 4922 |
chip->ad_dsp_w40 |= 0x6000; |
| 4923 |
if (w39) |
| 4924 |
chip->ad_dsp_w40 |= 127; |
| 4925 |
} |
| 4926 |
else |
| 4927 |
{ |
| 4928 |
chip->ad_dsp_w40 = (chip->ad_dsp_mul_accm1[1] >> 1) & 127; |
| 4929 |
chip->ad_dsp_w40 |= (chip->ad_dsp_mul_accm2 & 511) << 7; |
| 4930 |
} |
| 4931 |
|
| 4932 |
chip->ad_dsp_w43[1] = chip->ad_dsp_w43[0]; |
| 4933 |
|
| 4934 |
chip->ad_dsp_w46[1] = chip->ad_dsp_w46[0]; |
| 4935 |
|
| 4936 |
chip->ad_dsp_cnt2[1] = chip->ad_dsp_cnt2[0]; |
| 4937 |
|
| 4938 |
chip->ad_dsp_load_alu1[1] = chip->ad_dsp_load_alu1[0]; |
| 4939 |
chip->ad_dsp_load_alu2[1] = chip->ad_dsp_load_alu2[0]; |
| 4940 |
|
| 4941 |
chip->ad_dsp_load_res[1] = chip->ad_dsp_load_res[0]; |
| 4942 |
|
| 4943 |
chip->ad_dsp_alu_mask[1] = chip->ad_dsp_alu_mask[0]; |
| 4944 |
|
| 4945 |
chip->ad_dsp_alu_shift = |
| 4946 |
#ifdef FMOPNA_YM2608 |
| 4947 |
chip->ad_dsp_ctrl10_l ? 0 : |
| 4948 |
#endif |
| 4949 |
chip->ad_dsp_cnt2[0]; |
| 4950 |
|
| 4951 |
#ifdef FMOPNA_YM2608 |
| 4952 |
chip->ad_dsp_alu_neg[1] = chip->ad_dsp_alu_neg[0]; |
| 4953 |
#endif |
| 4954 |
|
| 4955 |
chip->ad_dsp_read_res[1] = chip->ad_dsp_read_res[0]; |
| 4956 |
|
| 4957 |
chip->ad_dsp_w52[1] = chip->ad_dsp_w52[0]; |
| 4958 |
|
| 4959 |
chip->ad_dsp_sregs2[0][1] = chip->ad_dsp_sregs2[0][0]; |
| 4960 |
chip->ad_dsp_sregs2[1][1] = chip->ad_dsp_sregs2[1][0]; |
| 4961 |
|
| 4962 |
chip->ad_dsp_w69[1] = chip->ad_dsp_w69[0]; |
| 4963 |
} |
| 4964 |
|
| 4965 |
{ |
| 4966 |
int w47 = (chip->ad_code_ctrl_l & 0x100000) != 0; |
| 4967 |
int w48 = (chip->ad_code_ctrl & 0x100000) != 0 && chip->cclk2; |
| 4968 |
int w49 = (chip->ad_code_ctrl & 0x100000) == 0 && (chip->ad_code_ctrl_l & 0x20000) != 0; |
| 4969 |
int w51 = (chip->ad_code_ctrl_l & 0x100000) != 0 && !chip->cclk2; |
| 4970 |
|
| 4971 |
int reg_id = 0; |
| 4972 |
|
| 4973 |
|
| 4974 |
if (w49) |
| 4975 |
{ |
| 4976 |
if (!w51) |
| 4977 |
{ |
| 4978 |
if (chip->ad_code_reg_id == 0) |
| 4979 |
{ |
| 4980 |
if (((chip->ad_code_ctrl_l & 0x20000) != 0 || (chip->ad_code_ctrl_l & 0x100000) != 0)) |
| 4981 |
chip->ad_dsp_regs[0] = chip->ad_dsp_bus; |
| 4982 |
} |
| 4983 |
else |
| 4984 |
chip->ad_dsp_regs[chip->ad_code_reg_id] = chip->ad_dsp_bus; |
| 4985 |
} |
| 4986 |
} |
| 4987 |
if (chip->ad_dsp_w52[1]) |
| 4988 |
{ |
| 4989 |
chip->ad_dsp_regs[0] = 0; |
| 4990 |
chip->ad_dsp_regs[1] = 0; |
| 4991 |
} |
| 4992 |
if (w48) |
| 4993 |
{ |
| 4994 |
if (!w51) |
| 4995 |
{ |
| 4996 |
chip->ad_dsp_regs_o = chip->ad_dsp_regs[chip->ad_code_reg_id]; |
| 4997 |
} |
| 4998 |
} |
| 4999 |
if (w47) |
| 5000 |
{ |
| 5001 |
chip->ad_dsp_bus = chip->ad_dsp_regs_o; |
| 5002 |
} |
| 5003 |
} |
| 5004 |
|
| 5005 |
#ifdef FMOPNA_YM2608 |
| 5006 |
// FIXME: guesswork |
| 5007 |
if (chip->ad_ad_w57[2]) |
| 5008 |
chip->ad_ad_cmp_i = chip->ad_comp_da < chip->ad_ad_input; |
| 5009 |
else |
| 5010 |
chip->ad_comp_da = chip->input.da; |
| 5011 |
|
| 5012 |
int w54 = (chip->ad_ad_shift & 1) == 0 && !chip->ad_ad_w53[1]; |
| 5013 |
|
| 5014 |
int w64 = w54 ? (chip->ad_ad_w65_l ^ 127) : chip->ad_ad_w65_l; |
| 5015 |
int w63 = (w64 + (w54 && chip->ad_ad_w55)) & 127; |
| 5016 |
|
| 5017 |
if (chip->cclk1) |
| 5018 |
{ |
| 5019 |
if (chip->ad_ad_cnt3_of[1]) |
| 5020 |
chip->ad_ad_cnt1[0] = 0; |
| 5021 |
else |
| 5022 |
{ |
| 5023 |
int inc = chip->ad_ad_w57[2]; |
| 5024 |
chip->ad_ad_cnt1[0] = (chip->ad_ad_cnt1[1] + inc) & 15; |
| 5025 |
} |
| 5026 |
|
| 5027 |
chip->ad_ad_w53[0] = chip->ad_ad_w57[2] |
| 5028 |
? !(w54 || ((chip->ad_ad_shift & 1) != 0 && !chip->ad_ad_cmp_i)) |
| 5029 |
: chip->ad_ad_w53[1]; |
| 5030 |
|
| 5031 |
chip->ad_ad_w55_l[0] = chip->ad_ad_w55; |
| 5032 |
|
| 5033 |
int rst = chip->ad_ad_w57[2] || chip->ad_ad_cnt3_of[1]; |
| 5034 |
|
| 5035 |
if (rst) |
| 5036 |
chip->ad_ad_cnt2[0] = 0; |
| 5037 |
else |
| 5038 |
{ |
| 5039 |
int inc = chip->ad_ad_w55; |
| 5040 |
chip->ad_ad_cnt2[0] = (chip->ad_ad_cnt2[1] + inc) & 31; |
| 5041 |
} |
| 5042 |
|
| 5043 |
chip->ad_ad_w62[0] = rst; |
| 5044 |
|
| 5045 |
chip->ad_ad_w57[1] = chip->ad_ad_w57[0]; |
| 5046 |
chip->ad_ad_w58[1] = chip->ad_ad_w58[0]; |
| 5047 |
|
| 5048 |
chip->ad_ad_w61[0] = chip->ad_ad_w61[1] >> 1; |
| 5049 |
if (chip->ad_ad_w62[1]) |
| 5050 |
{ |
| 5051 |
chip->ad_ad_w61[0] |= w63; |
| 5052 |
if (!w54) |
| 5053 |
chip->ad_ad_w61[0] |= 128; |
| 5054 |
} |
| 5055 |
|
| 5056 |
int w59 = w54 ^ chip->ad_ad_w60; |
| 5057 |
|
| 5058 |
chip->ad_ad_w66[0] = chip->ad_ad_w57[2] ? (w59 ? chip->ad_ad_w65_l : chip->ad_ad_w68) |
| 5059 |
: chip->ad_ad_w66[1]; |
| 5060 |
|
| 5061 |
int inc3 = !chip->ad_ad_cnt3_of[1] && chip->ad_ad_cnt3_en[1]; |
| 5062 |
int cnt3 = chip->ad_ad_cnt3[1] + inc3; |
| 5063 |
int en = chip->ad_sample_l[2] || chip->ad_start_l[2]; |
| 5064 |
chip->ad_ad_cnt3[0] = cnt3 & 0x7ff; |
| 5065 |
chip->ad_ad_cnt3_of[0] = (cnt3 & 0x800) != 0; |
| 5066 |
chip->ad_ad_cnt3_en[0] = en; |
| 5067 |
chip->ad_ad_cnt3_load = chip->ad_ad_cnt3_of[1] || (en && !chip->ad_ad_cnt3_en[1]); |
| 5068 |
chip->ad_ad_cnt3_load_val = (chip->ad_reg_prescale_l | (chip->ad_reg_prescale_h << 8)) ^ 0x7ff; |
| 5069 |
} |
| 5070 |
if (chip->cclk2) |
| 5071 |
{ |
| 5072 |
int cnt1 = chip->ad_ad_cnt1[0]; |
| 5073 |
if (chip->ic) |
| 5074 |
cnt1 |= 8; |
| 5075 |
|
| 5076 |
int shift = 0; |
| 5077 |
int shift2 = 0; |
| 5078 |
if ((cnt1 & 8) == 0) |
| 5079 |
{ |
| 5080 |
shift = 1 << (cnt1 & 7); |
| 5081 |
shift2 = 128 >> (cnt1 & 7); |
| 5082 |
} |
| 5083 |
chip->ad_ad_shift = shift; |
| 5084 |
|
| 5085 |
chip->ad_ad_cnt1[1] = cnt1; |
| 5086 |
|
| 5087 |
chip->ad_ad_w53[1] = chip->ad_ad_w53[0]; |
| 5088 |
|
| 5089 |
chip->ad_ad_w55 = (cnt1 & 8) == 0; |
| 5090 |
|
| 5091 |
chip->ad_ad_w55_l[1] = chip->ad_ad_w55_l[0]; |
| 5092 |
|
| 5093 |
chip->ad_ad_cnt2[1] = chip->ad_ad_cnt2[0]; |
| 5094 |
|
| 5095 |
chip->ad_ad_w57[0] = chip->ad_ad_cnt2[0] == 23; |
| 5096 |
chip->ad_ad_w57[2] = chip->ad_ad_w57[1]; |
| 5097 |
|
| 5098 |
chip->ad_ad_w58[0] = (chip->ad_ad_cnt2[0] & 24) == 0; |
| 5099 |
chip->ad_ad_w58[2] = chip->ad_ad_w58[1]; |
| 5100 |
|
| 5101 |
chip->ad_ad_w61[1] = chip->ad_ad_w61[0]; |
| 5102 |
|
| 5103 |
chip->ad_ad_w62[1] = chip->ad_ad_w62[0]; |
| 5104 |
|
| 5105 |
int w67 = chip->ad_ad_w66[0]; |
| 5106 |
if (shift & 1) |
| 5107 |
w67 = 0; |
| 5108 |
|
| 5109 |
int sum = shift2 + w67; |
| 5110 |
chip->ad_ad_w65_l = sum & 127; |
| 5111 |
|
| 5112 |
chip->ad_ad_w66[1] = chip->ad_ad_w66[0]; |
| 5113 |
|
| 5114 |
chip->ad_ad_w68 = w67; |
| 5115 |
|
| 5116 |
chip->ad_ad_cnt3[1] = chip->ad_ad_cnt3[0]; |
| 5117 |
if (chip->ad_ad_cnt3_load) |
| 5118 |
chip->ad_ad_cnt3[1] |= chip->ad_ad_cnt3_load_val; |
| 5119 |
|
| 5120 |
chip->ad_ad_cnt3_of[1] = chip->ad_ad_cnt3_of[0]; |
| 5121 |
|
| 5122 |
chip->ad_ad_cnt3_en[1] = chip->ad_ad_cnt3_en[0]; |
| 5123 |
} |
| 5124 |
|
| 5125 |
if (chip->ad_ad_w57[2]) |
| 5126 |
chip->ad_ad_w60 = chip->ad_ad_cmp_i; |
| 5127 |
|
| 5128 |
if (!chip->ad_ad_w55) |
| 5129 |
chip->ad_ad_input = chip->input.ad; |
| 5130 |
|
| 5131 |
chip->ad_ad_w56 = !chip->ad_ad_w55 && chip->ad_ad_w55_l[1]; |
| 5132 |
|
| 5133 |
if (chip->ad_ad_w56) |
| 5134 |
{ |
| 5135 |
chip->ad_ad_buf = w63; |
| 5136 |
if (w54) |
| 5137 |
chip->ad_ad_buf |= 128; |
| 5138 |
} |
| 5139 |
|
| 5140 |
if (chip->ad_isf && chip->read3) |
| 5141 |
{ |
| 5142 |
chip->data_bus1 &= ~255; |
| 5143 |
chip->data_bus1 |= chip->ad_ad_buf & 255; |
| 5144 |
} |
| 5145 |
#endif |
| 5146 |
|
| 5147 |
|
| 5148 |
chip->ad_set_eos = chip->ad_w13[1] |
| 5149 |
#ifdef FMOPNA_YM2608 |
| 5150 |
|| (chip->ad_ad_w56 && chip->ad_sample_l[2]) |
| 5151 |
#endif |
| 5152 |
; |
| 5153 |
|
| 5154 |
|
| 5155 |
if (w31 && (chip->ad_dsp_w31_l[0] & 1) == 0) |
| 5156 |
chip->ad_dsp_w33 = chip->ad_dsp_bus; |
| 5157 |
if ((chip->ad_dsp_w31_l[1] & 1) != 0 && (chip->ad_dsp_w31_l[0] & 2) == 0) |
| 5158 |
chip->ad_dsp_w34 = chip->ad_dsp_bus; |
| 5159 |
if ((chip->ad_dsp_w31_l[1] & 2) != 0 && (chip->ad_dsp_w31_l[0] & 4) == 0) |
| 5160 |
{ |
| 5161 |
chip->ad_dsp_w32 = chip->ad_dsp_bus; |
| 5162 |
if ((chip->ad_dsp_w32 & 128) == 0 || (chip->ad_dsp_w30_l[1] & 2) == 0) |
| 5163 |
chip->ad_dsp_w32 |= 256; |
| 5164 |
} |
| 5165 |
|
| 5166 |
if ((chip->ad_dsp_w43[1] & 1) != 0 && (chip->ad_dsp_w43[0] & 2) == 0) |
| 5167 |
chip->ad_dsp_w45 = chip->ad_dsp_w40; |
| 5168 |
|
| 5169 |
if ((chip->ad_dsp_w45 >> 3) == 0x1fff || ((chip->ad_dsp_w45 >> 3) & 0x1ffe) == 0) |
| 5170 |
chip->ad_output = 0; |
| 5171 |
else |
| 5172 |
chip->ad_output = chip->ad_dsp_w45 >> 3; |
| 5173 |
|
| 5174 |
if ((chip->ad_code_ctrl_l & 0x4000) != 0 && (chip->ad_dsp_load_alu1[0] & 1) == 0) |
| 5175 |
{ |
| 5176 |
chip->ad_dsp_alu_in1 &= ~255; |
| 5177 |
chip->ad_dsp_alu_in1 |= chip->ad_dsp_bus; |
| 5178 |
} |
| 5179 |
if ((chip->ad_code_ctrl_l & 0x8000) != 0 && (chip->ad_dsp_load_alu2[0] & 1) == 0) |
| 5180 |
{ |
| 5181 |
chip->ad_dsp_alu_in2 &= ~255; |
| 5182 |
chip->ad_dsp_alu_in2 |= chip->ad_dsp_bus; |
| 5183 |
} |
| 5184 |
|
| 5185 |
if (((chip->ad_dsp_load_alu1[1] & 1) != 0 |
| 5186 |
#ifdef FMOPNA_YM2608 |
| 5187 |
|| chip->ad_dsp_ctrl == 9 |
| 5188 |
#endif |
| 5189 |
) && !chip->ad_dsp_load_alu1_h) |
| 5190 |
{ |
| 5191 |
chip->ad_dsp_alu_in1 &= ~0xff00; |
| 5192 |
chip->ad_dsp_alu_in1 |= chip->ad_dsp_bus << 8; |
| 5193 |
} |
| 5194 |
if ((chip->ad_dsp_load_alu2[1] & 1) != 0 && (chip->ad_dsp_load_alu2[0] & 2) == 0) |
| 5195 |
{ |
| 5196 |
chip->ad_dsp_alu_in2 &= ~0xff00; |
| 5197 |
chip->ad_dsp_alu_in2 |= chip->ad_dsp_bus << 8; |
| 5198 |
} |
| 5199 |
|
| 5200 |
if (chip->ad_dsp_ctrl == 4) |
| 5201 |
chip->ad_dsp_alu_in1 = 0; |
| 5202 |
#ifdef FMOPNA_YM2608 |
| 5203 |
if (chip->ad_dsp_ctrl == 9) |
| 5204 |
chip->ad_dsp_alu_in1 &= ~255; |
| 5205 |
#endif |
| 5206 |
|
| 5207 |
// alu |
| 5208 |
{ |
| 5209 |
int i1 = chip->ad_dsp_alu_in1; |
| 5210 |
int i2; |
| 5211 |
if (chip->ad_dsp_alu_mask[1]) |
| 5212 |
i2 = 0; |
| 5213 |
else |
| 5214 |
i2 = chip->ad_dsp_alu_in2 >> chip->ad_dsp_alu_shift; |
| 5215 |
|
| 5216 |
int c1 = chip->ad_dsp_carry_mode[1] && (chip->ad_dsp_alu_in2 & 1) != 0; |
| 5217 |
int c2 = chip->ad_mem_nibble_msb; |
| 5218 |
|
| 5219 |
int neg = |
| 5220 |
#ifdef FMOPNA_YM2608 |
| 5221 |
chip->ad_dsp_alu_neg[1] || |
| 5222 |
#endif |
| 5223 |
c2; |
| 5224 |
|
| 5225 |
int b15_i1 = (i1 & 0x8000) != 0; |
| 5226 |
int b15_i2 = (i2 & 0x8000) != 0; |
| 5227 |
|
| 5228 |
if (neg) |
| 5229 |
i2 = i2 ^ 0xffff; |
| 5230 |
|
| 5231 |
int carry = !(!neg && (c2 || !c1)) && (!c2 || !c1); |
| 5232 |
int sum = i1 + i2 + carry; |
| 5233 |
int of = (sum >> 16) & 1; |
| 5234 |
sum &= 0xffff; |
| 5235 |
sum ^= 0x8000; |
| 5236 |
|
| 5237 |
|
| 5238 |
int b15_s = (sum & 0x8000) != 0; |
| 5239 |
|
| 5240 |
if ((chip->ad_code_ctrl_l & 0x80000) == 0 && chip->ad_dsp_load_res[1] == 0) |
| 5241 |
{ |
| 5242 |
int clip_h = (!b15_s && chip->ad_dsp_ctrl != 8 && !neg && !b15_i2 && !b15_i1) |
| 5243 |
|| (!b15_s && chip->ad_dsp_ctrl != 8 && neg && b15_i2 && !b15_i1); |
| 5244 |
int clip_l = (b15_s && chip->ad_dsp_ctrl != 8 && !neg && b15_i2 && b15_i1) |
| 5245 |
|| (b15_s && chip->ad_dsp_ctrl != 8 && neg && !b15_i2 && b15_i1); |
| 5246 |
|
| 5247 |
chip->ad_dsp_alu_res = clip_h ? 0xffff : (clip_l ? 0 : sum); |
| 5248 |
chip->ad_dsp_alu_res ^= 0x8000; |
| 5249 |
} |
| 5250 |
|
| 5251 |
chip->ad_dsp_alu_of = of; |
| 5252 |
|
| 5253 |
#ifdef FMOPNA_YM2608 |
| 5254 |
chip->ad_dsp_enc_bit = (b15_i1 && !b15_i2) || (!b15_i1 && !of && !b15_i2) |
| 5255 |
|| (b15_i1 && !of && b15_i2); |
| 5256 |
#endif |
| 5257 |
} |
| 5258 |
|
| 5259 |
if (chip->clk2) |
| 5260 |
chip->ad_code_sync[0] = chip->fsm_sel23[1]; |
| 5261 |
if (chip->cclk1) |
| 5262 |
chip->ad_code_sync[1] = chip->ad_code_sync[0]; |
| 5263 |
if (chip->cclk2) |
| 5264 |
chip->ad_code_sync[2] = chip->ad_code_sync[1]; |
| 5265 |
|
| 5266 |
#ifdef FMOPNA_YM2608 |
| 5267 |
chip->ad_ad_quiet = (chip->ad_ad_buf & 0xf8) == 0 || (chip->ad_ad_buf & 0xf8) == 0xf8; |
| 5268 |
|
| 5269 |
chip->o_spoff = chip->ad_reg_spoff; |
| 5270 |
chip->o_a8 = (chip->ad_mem_bus & 0x100) != 0; |
| 5271 |
|
| 5272 |
chip->o_romcs = !(chip->ad_reg_rom && (chip->ad_mem_ctrl_l & 1) != 0); |
| 5273 |
chip->o_mden = !chip->ad_reg_rom && (chip->ad_mem_ctrl_l & 1) != 0; |
| 5274 |
|
| 5275 |
chip->o_we = !chip->ad_mem_we[1]; |
| 5276 |
chip->o_cas = !chip->ad_mem_cas[1]; |
| 5277 |
chip->o_ras = !chip->ad_mem_ras[1]; |
| 5278 |
|
| 5279 |
chip->o_dm = chip->ad_mem_bus & 0xff; |
| 5280 |
chip->o_dm_d = !chip->ad_mem_dir; |
| 5281 |
#else |
| 5282 |
chip->o_pad = chip->ad_mem_bus & 0xff; |
| 5283 |
chip->o_pad_d = !chip->ad_mem_dir; |
| 5284 |
|
| 5285 |
chip->o_pa8 = (chip->ad_address_cnt[1][1] >> 8) & 15; |
| 5286 |
|
| 5287 |
chip->o_pmpx = chip->ad_mem_pmpx[1]; |
| 5288 |
chip->o_poe = !chip->ad_mem_poe[1]; |
| 5289 |
#endif |
| 5290 |
} |
| 5291 |
|
| 5292 |
|
| 5293 |
// accumulator |
| 5294 |
{ |
| 5295 |
if (chip->clk1) |
| 5296 |
{ |
| 5297 |
#ifdef FMOPNA_YM2608 |
| 5298 |
chip->ac_da_w70[0] = (!chip->ac_da_sync && chip->ac_da_w70[1]) || (chip->ad_ise && chip->write1_en); |
| 5299 |
#endif |
| 5300 |
|
| 5301 |
chip->ac_da_sync3[0] = chip->ac_da_sync; |
| 5302 |
|
| 5303 |
int accm1 = chip->ac_rss_sum_l; |
| 5304 |
if (chip->ac_rss_sum_l & 0x8000) |
| 5305 |
accm1 |= 0x30000; |
| 5306 |
if ( |
| 5307 |
#ifdef FMOPNA_YM2608 |
| 5308 |
!chip->ad_reg_rec && |
| 5309 |
#endif |
| 5310 |
chip->ad_reg_l && chip->ad_start_l[2]) |
| 5311 |
accm1 += chip->ac_ad_output; |
| 5312 |
chip->ac_fm_accm1[0] = chip->ac_da_sync2 ? accm1 : chip->ac_fm_accm1[1]; |
| 5313 |
if ((chip->ac_fm_pan & 2) != 0 && chip->ac_fm_output_en) |
| 5314 |
chip->ac_fm_accm1[0] += chip->ac_fm_output; |
| 5315 |
chip->ac_fm_accm1[0] &= 0x3ffff; |
| 5316 |
|
| 5317 |
int accm2 = chip->ac_rss_sum_r; |
| 5318 |
if (chip->ac_rss_sum_r & 0x8000) |
| 5319 |
accm2 |= 0x30000; |
| 5320 |
if ( |
| 5321 |
#ifdef FMOPNA_YM2608 |
| 5322 |
!chip->ad_reg_rec && |
| 5323 |
#endif |
| 5324 |
chip->ad_reg_r && chip->ad_start_l[2]) |
| 5325 |
accm2 += chip->ac_ad_output; |
| 5326 |
chip->ac_fm_accm2[0] = chip->ac_da_sync ? accm2 : chip->ac_fm_accm2[1]; |
| 5327 |
if ((chip->ac_fm_pan & 1) != 0 && chip->ac_fm_output_en) |
| 5328 |
chip->ac_fm_accm2[0] += chip->ac_fm_output; |
| 5329 |
chip->ac_fm_accm2[0] &= 0x3ffff; |
| 5330 |
|
| 5331 |
chip->ac_shifter_load_l = chip->ac_da_sync2; |
| 5332 |
chip->ac_shifter_load_r = chip->ac_da_sync; |
| 5333 |
} |
| 5334 |
if (chip->clk2) |
| 5335 |
{ |
| 5336 |
#ifdef FMOPNA_YM2608 |
| 5337 |
chip->ac_da_w70[1] = chip->ac_da_w70[0]; |
| 5338 |
#endif |
| 5339 |
chip->ac_da_sync = chip->fsm_sel23[1]; |
| 5340 |
|
| 5341 |
chip->ac_fm_output = (chip->op_output[2] & 0x1fff) >> 1; |
| 5342 |
if (chip->op_output[2] & 0x2000) |
| 5343 |
chip->ac_fm_output |= 0x3f000; |
| 5344 |
|
| 5345 |
chip->ac_fm_output_en = chip->alg_output_l; |
| 5346 |
chip->ac_fm_pan = (chip->reg_b4[0][5] >> 6) & 3; |
| 5347 |
|
| 5348 |
chip->ac_da_sync2 = chip->fsm_sel11[1]; |
| 5349 |
|
| 5350 |
chip->ac_da_sync3[1] = chip->ac_da_sync3[0]; |
| 5351 |
|
| 5352 |
chip->ac_fm_accm1[1] = chip->ac_fm_accm1[0]; |
| 5353 |
chip->ac_fm_accm2[1] = chip->ac_fm_accm2[0]; |
| 5354 |
} |
| 5355 |
|
| 5356 |
if (chip->rss_eclk1) |
| 5357 |
{ |
| 5358 |
int rss_sample = (chip->rss_sample_shift & 0xfff) << 2; |
| 5359 |
if (chip->rss_sample_shift & 0x1000) |
| 5360 |
rss_sample |= 0xc000; |
| 5361 |
int accm1 = chip->rss_cnt2[1] == 0 ? 0 : chip->ac_rss_accm1[1]; |
| 5362 |
if (chip->rss_pan[2] & 2) |
| 5363 |
accm1 += rss_sample; |
| 5364 |
chip->ac_rss_accm1[0] = accm1 & 0xffff; |
| 5365 |
|
| 5366 |
int accm2 = chip->rss_cnt2[1] == 0 ? 0 : chip->ac_rss_accm2[1]; |
| 5367 |
if (chip->rss_pan[2] & 1) |
| 5368 |
accm2 += rss_sample; |
| 5369 |
chip->ac_rss_accm2[0] = accm2 & 0xffff; |
| 5370 |
|
| 5371 |
chip->ac_rss_load = chip->rss_cnt2[1] == 0; |
| 5372 |
|
| 5373 |
// tildearrow: per-channel osc |
| 5374 |
chip->last_rss_sample = rss_sample & 0xffff; |
| 5375 |
} |
| 5376 |
if (chip->rss_eclk2) |
| 5377 |
{ |
| 5378 |
chip->ac_rss_accm1[1] = chip->ac_rss_accm1[0]; |
| 5379 |
chip->ac_rss_accm2[1] = chip->ac_rss_accm2[0]; |
| 5380 |
} |
| 5381 |
|
| 5382 |
if (chip->rss_cnt2[1] == 0 && !chip->ac_rss_load) |
| 5383 |
{ |
| 5384 |
chip->ac_rss_sum_l = chip->ac_rss_accm1[1]; |
| 5385 |
chip->ac_rss_sum_r = chip->ac_rss_accm2[1]; |
| 5386 |
} |
| 5387 |
|
| 5388 |
if (chip->ac_da_sync3[1]) |
| 5389 |
{ |
| 5390 |
chip->ac_ad_output = (chip->ad_output & 0xfff) << 2; |
| 5391 |
if (chip->ad_output & 0x1000) |
| 5392 |
chip->ac_ad_output |= 0x3c000; |
| 5393 |
} |
| 5394 |
|
| 5395 |
int load_l = chip->ac_da_sync2 && !chip->ac_shifter_load_l; |
| 5396 |
int load_r = chip->ac_da_sync && !chip->ac_shifter_load_r; |
| 5397 |
|
| 5398 |
if (load_l) |
| 5399 |
chip->ac_shifter_top = (chip->ac_fm_accm1[1] >> 15) & 7; |
| 5400 |
else if (load_r) |
| 5401 |
chip->ac_shifter_top = (chip->ac_fm_accm2[1] >> 15) & 7; |
| 5402 |
|
| 5403 |
if (chip->bclk1) |
| 5404 |
{ |
| 5405 |
#ifdef FMOPNA_YM2608 |
| 5406 |
chip->ac_da_shift[1] = chip->ac_da_shift[0]; |
| 5407 |
|
| 5408 |
chip->ac_da_set[1] = chip->ac_da_set[0]; |
| 5409 |
|
| 5410 |
chip->opo_da[1] = chip->opo_da[0]; |
| 5411 |
#endif |
| 5412 |
|
| 5413 |
chip->ac_shifter[0] = chip->ac_shifter[1] >> 1; |
| 5414 |
|
| 5415 |
chip->ac_shifter_bit = chip->ac_shifter[1] & 1; |
| 5416 |
|
| 5417 |
chip->opo_fm = chip->ac_opo; |
| 5418 |
} |
| 5419 |
if (chip->bclk2) |
| 5420 |
{ |
| 5421 |
#ifdef FMOPNA_YM2608 |
| 5422 |
int set = chip->ac_da_w70[1] && chip->ac_da_sync; |
| 5423 |
|
| 5424 |
chip->opo_da[0] = chip->ac_da_shift[1] & 1; |
| 5425 |
|
| 5426 |
int bit = !chip->ic && (chip->ac_da_shift[1] & 1) != 0; |
| 5427 |
chip->ac_da_shift[0] = (chip->ac_da_shift[1] >> 1) | (bit << 23); |
| 5428 |
if (set && !chip->ac_da_set[1]) |
| 5429 |
{ |
| 5430 |
chip->ac_da_shift[0] &= ~(0xffff << 8); |
| 5431 |
chip->ac_da_shift[0] |= chip->ad_da_data << 8; |
| 5432 |
} |
| 5433 |
|
| 5434 |
chip->ac_da_set[0] = set; |
| 5435 |
#endif |
| 5436 |
|
| 5437 |
chip->ac_shifter[1] = chip->ac_shifter[0]; |
| 5438 |
|
| 5439 |
if (load_l || load_r) |
| 5440 |
{ |
| 5441 |
int sample = 0; |
| 5442 |
if (load_l) |
| 5443 |
sample = chip->ac_fm_accm1[1]; |
| 5444 |
else if (load_r) |
| 5445 |
sample = chip->ac_fm_accm2[1]; |
| 5446 |
|
| 5447 |
int sample16 = sample & 0x7fff; |
| 5448 |
if ((sample & 0x20000) == 0) |
| 5449 |
sample16 |= 0x8000; |
| 5450 |
|
| 5451 |
chip->ac_shifter[1] |= sample16; |
| 5452 |
} |
| 5453 |
|
| 5454 |
int clipl = chip->ac_shifter_top == 6 || (chip->ac_shifter_top & 6) == 4; |
| 5455 |
int cliph = chip->ac_shifter_top == 1 || (chip->ac_shifter_top & 6) == 2; |
| 5456 |
|
| 5457 |
chip->ac_opo = cliph ? 1 : (clipl ? 0 : chip->ac_shifter_bit); |
| 5458 |
} |
| 5459 |
|
| 5460 |
if (chip->clk2) |
| 5461 |
{ |
| 5462 |
chip->sh1_l = chip->fsm_sh1[1]; |
| 5463 |
chip->sh2_l = chip->fsm_sh2[1]; |
| 5464 |
} |
| 5465 |
|
| 5466 |
#ifdef FMOPNA_YM2608 |
| 5467 |
if (chip->cclk2) |
| 5468 |
{ |
| 5469 |
chip->opo_ad = chip->ad_ad_w61[0] & 1; |
| 5470 |
} |
| 5471 |
#endif |
| 5472 |
|
| 5473 |
|
| 5474 |
#ifdef FMOPNA_YM2608 |
| 5475 |
int dac_damode = chip->ad_reg_da_ad && chip->ad_sample_l[2]; |
| 5476 |
|
| 5477 |
int dac_admode = (chip->ad_reg_rec && chip->ad_start_l[2]) || (!chip->ad_reg_da_ad && chip->ad_sample_l[2]); |
| 5478 |
|
| 5479 |
if (dac_damode) |
| 5480 |
chip->o_sh1 = chip->ad_reg_l && chip->sh1_l; |
| 5481 |
else if (dac_admode) |
| 5482 |
chip->o_sh1 = 0; |
| 5483 |
else |
| 5484 |
chip->o_sh1 = chip->sh1_l; |
| 5485 |
|
| 5486 |
if (dac_damode) |
| 5487 |
chip->o_sh2 = chip->ad_reg_r && chip->sh2_l; |
| 5488 |
else if (dac_admode) |
| 5489 |
chip->o_sh2 = chip->ad_ad_w58[2]; |
| 5490 |
else |
| 5491 |
chip->o_sh2 = chip->sh2_l; |
| 5492 |
|
| 5493 |
if (dac_damode) |
| 5494 |
chip->o_opo = chip->opo_da[1]; |
| 5495 |
else if (dac_admode) |
| 5496 |
chip->o_opo = chip->opo_ad; |
| 5497 |
else |
| 5498 |
chip->o_opo = chip->opo_fm; |
| 5499 |
|
| 5500 |
if (dac_admode) |
| 5501 |
chip->o_s = chip->cclk2; |
| 5502 |
else |
| 5503 |
chip->o_s = chip->bclk1; |
| 5504 |
#else |
| 5505 |
chip->o_sh1 = chip->sh1_l; |
| 5506 |
chip->o_sh2 = chip->sh2_l; |
| 5507 |
chip->o_opo = chip->opo_fm; |
| 5508 |
chip->o_s = chip->bclk1; |
| 5509 |
#endif |
| 5510 |
|
| 5511 |
} |
| 5512 |
#endif |
| 5513 |
|
| 5514 |
{ |
| 5515 |
if (chip->clk1) |
| 5516 |
{ |
| 5517 |
int inc = chip->busy_cnt_en[1]; |
| 5518 |
int sum = chip->busy_cnt[1] + inc; |
| 5519 |
int of = (sum & 32) != 0; |
| 5520 |
if (chip->ic) |
| 5521 |
chip->busy_cnt[0] = 0; |
| 5522 |
else |
| 5523 |
chip->busy_cnt[0] = sum & 31; |
| 5524 |
|
| 5525 |
chip->busy_cnt_en[0] = chip->write1_en || (chip->busy_cnt_en[1] && !(of || chip->ic)); |
| 5526 |
|
| 5527 |
#ifndef FMOPNA_YM2612 |
| 5528 |
chip->eos_l[0] = chip->eos_flag; |
| 5529 |
|
| 5530 |
chip->eos_repeat = chip->eos_l[1] && chip->ad_set_eos && chip->ad_reg_repeat; |
| 5531 |
#endif |
| 5532 |
} |
| 5533 |
if (chip->clk2) |
| 5534 |
{ |
| 5535 |
chip->busy_cnt[1] = chip->busy_cnt[0]; |
| 5536 |
chip->busy_cnt_en[1] = chip->busy_cnt_en[0]; |
| 5537 |
|
| 5538 |
#ifdef FMOPNA_YM2608 |
| 5539 |
chip->zero_set = chip->lfo_cnt_of; |
| 5540 |
#endif |
| 5541 |
|
| 5542 |
#ifndef FMOPNA_YM2612 |
| 5543 |
chip->eos_l[1] = chip->eos_l[0]; |
| 5544 |
#endif |
| 5545 |
chip->eg_dbg = chip->reg_test_21[0] ? (chip->eg_debug[0] & 0x200) != 0 : |
| 5546 |
chip->eg_debug_inc; |
| 5547 |
} |
| 5548 |
|
| 5549 |
#ifdef FMOPNA_YM2608 |
| 5550 |
if (chip->irq_mask_eos) |
| 5551 |
chip->eos_flag = 0; |
| 5552 |
else |
| 5553 |
chip->eos_flag |= chip->ad_set_eos; |
| 5554 |
|
| 5555 |
if (chip->irq_mask_brdy) |
| 5556 |
chip->brdy_flag = 0; |
| 5557 |
else |
| 5558 |
chip->brdy_flag |= chip->ad_brdy_set_l[1]; |
| 5559 |
|
| 5560 |
if (chip->irq_mask_zero) |
| 5561 |
chip->zero_flag = 0; |
| 5562 |
else |
| 5563 |
chip->zero_flag |= chip->zero_set; |
| 5564 |
|
| 5565 |
if (!chip->read0 && !chip->read2) |
| 5566 |
{ |
| 5567 |
chip->status_timer_a = chip->timer_a_status[1]; |
| 5568 |
chip->status_timer_b = chip->timer_b_status[1]; |
| 5569 |
chip->status_eos = chip->eos_flag; |
| 5570 |
chip->status_brdy = chip->brdy_flag; |
| 5571 |
chip->status_zero = chip->zero_flag; |
| 5572 |
} |
| 5573 |
#endif |
| 5574 |
#ifdef FMOPNA_YM2610 |
| 5575 |
if (chip->ic || (chip->reg_flags[1] & 1) != 0) |
| 5576 |
chip->flag_rss_0 = 0; |
| 5577 |
else if (chip->rss_stop_flag[1] & 1) |
| 5578 |
chip->flag_rss_0 = 1; |
| 5579 |
if (chip->ic || (chip->reg_flags[1] & 2) != 0) |
| 5580 |
chip->flag_rss_1 = 0; |
| 5581 |
else if (chip->rss_stop_flag[1] & 2) |
| 5582 |
chip->flag_rss_1 = 1; |
| 5583 |
if (chip->ic || (chip->reg_flags[1] & 4) != 0) |
| 5584 |
chip->flag_rss_2 = 0; |
| 5585 |
else if (chip->rss_stop_flag[1] & 4) |
| 5586 |
chip->flag_rss_2 = 1; |
| 5587 |
if (chip->ic || (chip->reg_flags[1] & 8) != 0) |
| 5588 |
chip->flag_rss_3 = 0; |
| 5589 |
else if (chip->rss_stop_flag[1] & 8) |
| 5590 |
chip->flag_rss_3 = 1; |
| 5591 |
if (chip->ic || (chip->reg_flags[1] & 16) != 0) |
| 5592 |
chip->flag_rss_4 = 0; |
| 5593 |
else if (chip->rss_stop_flag[1] & 16) |
| 5594 |
chip->flag_rss_4 = 1; |
| 5595 |
if (chip->ic || (chip->reg_flags[1] & 32) != 0) |
| 5596 |
chip->flag_rss_5 = 0; |
| 5597 |
else if (chip->rss_stop_flag[1] & 32) |
| 5598 |
chip->flag_rss_5 = 1; |
| 5599 |
if (chip->ic || (chip->reg_flags[1] & 128) != 0 || chip->irq_eos_l) |
| 5600 |
chip->eos_flag = 0; |
| 5601 |
else if (chip->ad_set_eos) |
| 5602 |
chip->eos_flag = 1; |
| 5603 |
if (!chip->read0 && !chip->read2) |
| 5604 |
{ |
| 5605 |
chip->status_timer_a = chip->timer_a_status[1]; |
| 5606 |
chip->status_timer_b = chip->timer_b_status[1]; |
| 5607 |
|
| 5608 |
chip->status_rss_0 = chip->flag_rss_0; |
| 5609 |
chip->status_rss_1 = chip->flag_rss_1; |
| 5610 |
chip->status_rss_2 = chip->flag_rss_2; |
| 5611 |
chip->status_rss_3 = chip->flag_rss_3; |
| 5612 |
chip->status_rss_4 = chip->flag_rss_4; |
| 5613 |
chip->status_rss_5 = chip->flag_rss_5; |
| 5614 |
chip->status_eos = chip->eos_flag; |
| 5615 |
} |
| 5616 |
#endif |
| 5617 |
#ifdef FMOPNA_YM2612 |
| 5618 |
if (!chip->read0) |
| 5619 |
{ |
| 5620 |
chip->status_timer_a = chip->timer_a_status[1]; |
| 5621 |
chip->status_timer_b = chip->timer_b_status[1]; |
| 5622 |
} |
| 5623 |
#endif |
| 5624 |
|
| 5625 |
#ifdef FMOPNA_YM2608 |
| 5626 |
chip->o_irq_pull = 0; |
| 5627 |
if (chip->reg_irq[1] & 1) |
| 5628 |
chip->o_irq_pull |= chip->status_timer_a; |
| 5629 |
if (chip->reg_irq[1] & 2) |
| 5630 |
chip->o_irq_pull |= chip->status_timer_b; |
| 5631 |
if (chip->reg_irq[1] & 4) |
| 5632 |
chip->o_irq_pull |= chip->status_eos; |
| 5633 |
if (chip->reg_irq[1] & 8) |
| 5634 |
chip->o_irq_pull |= chip->status_brdy; |
| 5635 |
if (chip->reg_irq[1] & 16) |
| 5636 |
chip->o_irq_pull |= chip->status_zero; |
| 5637 |
#else |
| 5638 |
chip->o_irq_pull = chip->status_timer_a | chip->status_timer_b; |
| 5639 |
#endif |
| 5640 |
|
| 5641 |
chip->read_bus = 0; // FIXME |
| 5642 |
#ifndef FMOPNA_YM2612 |
| 5643 |
if (chip->ssg_read1 |
| 5644 |
#ifdef FMOPNA_YM2608 |
| 5645 |
|| chip->read3 |
| 5646 |
#endif |
| 5647 |
) |
| 5648 |
chip->read_bus = chip->data_bus1 & 255; |
| 5649 |
#endif |
| 5650 |
if ((chip->reg_test_21[1] & 0x40) == 0 |
| 5651 |
#ifndef FMOPNA_YM2612 |
| 5652 |
&& (chip->reg_test_12[1] & 0x20) == 0 |
| 5653 |
#endif |
| 5654 |
) |
| 5655 |
{ |
| 5656 |
if (chip->read0) |
| 5657 |
{ |
| 5658 |
if (chip->busy_cnt_en[1]) |
| 5659 |
chip->read_bus |= 128; |
| 5660 |
if (chip->status_timer_a) |
| 5661 |
chip->read_bus |= 1; |
| 5662 |
if (chip->status_timer_b) |
| 5663 |
chip->read_bus |= 2; |
| 5664 |
} |
| 5665 |
#ifdef FMOPNA_YM2608 |
| 5666 |
if (chip->read2) |
| 5667 |
{ |
| 5668 |
if (chip->busy_cnt_en[1]) |
| 5669 |
chip->read_bus |= 128; |
| 5670 |
if (chip->status_timer_a) |
| 5671 |
chip->read_bus |= 1; |
| 5672 |
if (chip->status_timer_b) |
| 5673 |
chip->read_bus |= 2; |
| 5674 |
if (chip->status_eos) |
| 5675 |
chip->read_bus |= 4; |
| 5676 |
if (chip->status_brdy) |
| 5677 |
chip->read_bus |= 8; |
| 5678 |
if (chip->status_zero) |
| 5679 |
chip->read_bus |= 16; |
| 5680 |
if (chip->ad_start_l[0]) |
| 5681 |
chip->read_bus |= 32; |
| 5682 |
} |
| 5683 |
#endif |
| 5684 |
#ifdef FMOPNA_YM2610 |
| 5685 |
if (chip->read2) |
| 5686 |
{ |
| 5687 |
if (chip->status_rss_0) |
| 5688 |
chip->read_bus |= 1; |
| 5689 |
if (chip->status_rss_1) |
| 5690 |
chip->read_bus |= 2; |
| 5691 |
if (chip->status_rss_2) |
| 5692 |
chip->read_bus |= 4; |
| 5693 |
if (chip->status_rss_3) |
| 5694 |
chip->read_bus |= 8; |
| 5695 |
if (chip->status_rss_4) |
| 5696 |
chip->read_bus |= 16; |
| 5697 |
if (chip->status_rss_5) |
| 5698 |
chip->read_bus |= 32; |
| 5699 |
if (chip->status_eos) |
| 5700 |
chip->read_bus |= 128; |
| 5701 |
} |
| 5702 |
#endif |
| 5703 |
} |
| 5704 |
#ifndef FMOPNA_YM2612 |
| 5705 |
if ((chip->reg_test_12[1] & 0x20) != 0 && chip->read0) |
| 5706 |
{ |
| 5707 |
#ifdef FMOPNA_YM2608 |
| 5708 |
if ((chip->reg_test_12[1] & 0x40) == 0) |
| 5709 |
{ |
| 5710 |
// FIXME |
| 5711 |
chip->read_bus = rss_rom[(chip->rss_ix >> 2) & 0x1fff]; |
| 5712 |
} |
| 5713 |
else |
| 5714 |
#endif |
| 5715 |
if ((chip->reg_test_12[1] & 0x80) == 0) |
| 5716 |
{ |
| 5717 |
chip->read_bus = (chip->rss_dbg_data >> 8) & 255; |
| 5718 |
} |
| 5719 |
else |
| 5720 |
{ |
| 5721 |
chip->read_bus = chip->rss_dbg_data & 255; |
| 5722 |
} |
| 5723 |
} |
| 5724 |
#endif |
| 5725 |
if ((chip->reg_test_21[1] & 0x40) != 0 && chip->read0) |
| 5726 |
{ |
| 5727 |
int testdata = 0; |
| 5728 |
#ifndef FMOPNA_YM2612 |
| 5729 |
testdata = chip->op_output[3] & 0x3fff; |
| 5730 |
#endif |
| 5731 |
#ifdef FMOPNA_YM2612 |
| 5732 |
if (chip->reg_test_2c[1] & 16) |
| 5733 |
testdata |= chip->ch_dbg[1] & 0x1ff; |
| 5734 |
else |
| 5735 |
testdata |= chip->op_output[3] & 0x3fff; |
| 5736 |
#endif |
| 5737 |
|
| 5738 |
testdata |= (chip->pg_dbg[1] & 1) << 15; |
| 5739 |
testdata |= chip->eg_dbg << 14; |
| 5740 |
|
| 5741 |
if ((chip->reg_test_21[1] & 0x80) == 0) |
| 5742 |
{ |
| 5743 |
chip->read_bus = (testdata >> 8) & 255; |
| 5744 |
} |
| 5745 |
else |
| 5746 |
{ |
| 5747 |
chip->read_bus = testdata & 255; |
| 5748 |
} |
| 5749 |
} |
| 5750 |
|
| 5751 |
chip->o_data = chip->read_bus; |
| 5752 |
} |
| 5753 |
#ifdef FMOPNA_YM2612 |
| 5754 |
// YM2612 channel accumulator |
| 5755 |
{ |
| 5756 |
int test_dac = (chip->reg_test_2c[1] & 32) != 0; |
| 5757 |
if (chip->clk1) |
| 5758 |
{ |
| 5759 |
int add = (!test_dac && chip->ch_op_add) ? chip->ch_op_output : 0; |
| 5760 |
int load = chip->ch_accm_load || test_dac; |
| 5761 |
int clear = !test_dac && load; |
| 5762 |
int acc = clear ? 0 : chip->ch_accm[1][5]; |
| 5763 |
int sum1 = (add + acc + test_dac) & 0x1ff; |
| 5764 |
|
| 5765 |
if ((acc & 0x100) == 0 && (add & 0x100) == 0 && (sum1 & 0x100) != 0) |
| 5766 |
sum1 = 255; |
| 5767 |
else if ((acc & 0x100) != 0 && (add & 0x100) != 0 && (sum1 & 0x100) == 0) |
| 5768 |
sum1 = 256; |
| 5769 |
|
| 5770 |
chip->ch_accm[0][0] = sum1; |
| 5771 |
memcpy(&chip->ch_accm[0][1], &chip->ch_accm[1][0], 5 * sizeof(short)); |
| 5772 |
memcpy(&chip->ch_buf[0][1], &chip->ch_buf[1][0], 5 * sizeof(short)); |
| 5773 |
|
| 5774 |
chip->ch_buf[0][0] = load ? chip->ch_accm[1][5] : chip->ch_buf[1][5]; |
| 5775 |
|
| 5776 |
chip->ch_load[1] = chip->ch_load[0]; |
| 5777 |
|
| 5778 |
chip->ch_dbg[0] = chip->ch_output; |
| 5779 |
} |
| 5780 |
if (chip->clk2) |
| 5781 |
{ |
| 5782 |
chip->ch_op_output = (chip->op_output[2] >> 5) & 0x1ff; |
| 5783 |
chip->ch_op_add = chip->alg_output_l; |
| 5784 |
chip->ch_accm_load = chip->alg_mod_op1_1_l; |
| 5785 |
memcpy(&chip->ch_accm[1][0], &chip->ch_accm[0][0], 6 * sizeof(short)); |
| 5786 |
memcpy(&chip->ch_buf[1][0], &chip->ch_buf[0][0], 6 * sizeof(short)); |
| 5787 |
|
| 5788 |
chip->ch_load[0] = chip->fsm_dac_load[1]; |
| 5789 |
|
| 5790 |
chip->ch_sel = chip->fsm_dac_out_sel[1]; |
| 5791 |
|
| 5792 |
chip->ch_ch6 = chip->fsm_dac_ch6[1]; |
| 5793 |
|
| 5794 |
chip->ch_dbg[1] = chip->ch_dbg[0]; |
| 5795 |
|
| 5796 |
chip->o_test = chip->fsm_sel23[1]; |
| 5797 |
} |
| 5798 |
|
| 5799 |
{ |
| 5800 |
if (test_dac || (chip->ch_load[0] && !chip->ch_load[1])) |
| 5801 |
{ |
| 5802 |
int sel = test_dac || chip->ch_sel; |
| 5803 |
chip->ch_output = sel ? chip->ch_buf[1][5] : chip->ch_buf[1][4]; |
| 5804 |
} |
| 5805 |
|
| 5806 |
if (chip->ch_load[0] && !chip->ch_load[1]) |
| 5807 |
{ |
| 5808 |
int sel = chip->ch_sel; |
| 5809 |
if (sel) |
| 5810 |
chip->ch_pan = (chip->reg_b4[1][5] >> 6) & 3; |
| 5811 |
else |
| 5812 |
chip->ch_pan = (chip->reg_b4[1][4] >> 6) & 3; |
| 5813 |
} |
| 5814 |
|
| 5815 |
int dac_sel = test_dac || (chip->reg_dac_en[1] && chip->ch_ch6); |
| 5816 |
|
| 5817 |
int ch_val; |
| 5818 |
|
| 5819 |
if (dac_sel) |
| 5820 |
{ |
| 5821 |
ch_val = (chip->reg_dac_data[1] ^ 0x80) << 1; |
| 5822 |
ch_val |= (chip->reg_test_2c[1] & 8) != 0; |
| 5823 |
} |
| 5824 |
else |
| 5825 |
ch_val = chip->ch_output; |
| 5826 |
|
| 5827 |
int do_out = test_dac || chip->ch_load[0]; |
| 5828 |
int sign; |
| 5829 |
|
| 5830 |
if (ch_val & 256) |
| 5831 |
{ |
| 5832 |
sign = -1; |
| 5833 |
ch_val |= ~0x1ff; |
| 5834 |
} |
| 5835 |
else |
| 5836 |
{ |
| 5837 |
sign = 1; |
| 5838 |
ch_val++; |
| 5839 |
} |
| 5840 |
|
| 5841 |
if (do_out && (chip->ch_pan & 2) != 0) |
| 5842 |
chip->o_mol = ch_val; |
| 5843 |
else |
| 5844 |
chip->o_mol = sign; |
| 5845 |
if (do_out && (chip->ch_pan & 1) != 0) |
| 5846 |
chip->o_mor = ch_val; |
| 5847 |
else |
| 5848 |
chip->o_mor = sign; |
| 5849 |
} |
| 5850 |
|
| 5851 |
chip->o_test_d = (chip->reg_test_2c[1] & 128) == 0; |
| 5852 |
} |
| 5853 |
#endif |
| 5854 |
|
| 5855 |
#undef ADDRESS_MATCH |
| 5856 |
} |