src/emu/sound/okim6258.c
| r0 | r3560 | |
| 1 | /********************************************************************************************** |
| 2 | * |
| 3 | * OKI MSM6258 ADPCM |
| 4 | * |
| 5 | * TODO: |
| 6 | * 3-bit ADPCM support |
| 7 | * Recording? |
| 8 | * |
| 9 | **********************************************************************************************/ |
| 10 | |
| 11 | |
| 12 | #include <math.h> |
| 13 | |
| 14 | #include "sndintrf.h" |
| 15 | #include "deprecat.h" |
| 16 | #include "streams.h" |
| 17 | #include "okim6258.h" |
| 18 | |
| 19 | #define COMMAND_STOP (1 << 0) |
| 20 | #define COMMAND_PLAY (1 << 1) |
| 21 | #define COMMAND_RECORD (1 << 2) |
| 22 | |
| 23 | #define STATUS_PLAYING (1 << 1) |
| 24 | #define STATUS_RECORDING (1 << 2) |
| 25 | |
| 26 | static const int dividers[4] = { 1024, 768, 512, 512 }; |
| 27 | |
| 28 | struct okim6258 |
| 29 | { |
| 30 | UINT8 status; |
| 31 | |
| 32 | UINT32 master_clock; /* master clock frequency */ |
| 33 | UINT32 divider; /* master clock divider */ |
| 34 | UINT8 adpcm_type; /* 3/4 bit ADPCM select */ |
| 35 | UINT8 data_in; /* ADPCM data-in register */ |
| 36 | UINT8 nibble_shift; /* nibble select */ |
| 37 | sound_stream *stream; /* which stream are we playing on? */ |
| 38 | |
| 39 | UINT8 output_bits; |
| 40 | |
| 41 | INT32 signal; |
| 42 | INT32 step; |
| 43 | }; |
| 44 | |
| 45 | /* step size index shift table */ |
| 46 | static const int index_shift[8] = { -1, -1, -1, -1, 2, 4, 6, 8 }; |
| 47 | |
| 48 | /* lookup table for the precomputed difference */ |
| 49 | static int diff_lookup[49*16]; |
| 50 | |
| 51 | /* tables computed? */ |
| 52 | static int tables_computed = 0; |
| 53 | |
| 54 | /********************************************************************************************** |
| 55 | |
| 56 | compute_tables -- compute the difference tables |
| 57 | |
| 58 | ***********************************************************************************************/ |
| 59 | |
| 60 | static void compute_tables(void) |
| 61 | { |
| 62 | /* nibble to bit map */ |
| 63 | static const int nbl2bit[16][4] = |
| 64 | { |
| 65 | { 1, 0, 0, 0}, { 1, 0, 0, 1}, { 1, 0, 1, 0}, { 1, 0, 1, 1}, |
| 66 | { 1, 1, 0, 0}, { 1, 1, 0, 1}, { 1, 1, 1, 0}, { 1, 1, 1, 1}, |
| 67 | {-1, 0, 0, 0}, {-1, 0, 0, 1}, {-1, 0, 1, 0}, {-1, 0, 1, 1}, |
| 68 | {-1, 1, 0, 0}, {-1, 1, 0, 1}, {-1, 1, 1, 0}, {-1, 1, 1, 1} |
| 69 | }; |
| 70 | |
| 71 | int step, nib; |
| 72 | |
| 73 | /* loop over all possible steps */ |
| 74 | for (step = 0; step <= 48; step++) |
| 75 | { |
| 76 | /* compute the step value */ |
| 77 | int stepval = floor(16.0 * pow(11.0 / 10.0, (double)step)); |
| 78 | |
| 79 | /* loop over all nibbles and compute the difference */ |
| 80 | for (nib = 0; nib < 16; nib++) |
| 81 | { |
| 82 | diff_lookup[step*16 + nib] = nbl2bit[nib][0] * |
| 83 | (stepval * nbl2bit[nib][1] + |
| 84 | stepval/2 * nbl2bit[nib][2] + |
| 85 | stepval/4 * nbl2bit[nib][3] + |
| 86 | stepval/8); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | tables_computed = 1; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | static INT16 clock_adpcm(struct okim6258 *chip, UINT8 nibble) |
| 95 | { |
| 96 | INT32 max = (1 << (chip->output_bits - 1)) - 1; |
| 97 | INT32 min = -(1 << (chip->output_bits - 1)); |
| 98 | |
| 99 | chip->signal += diff_lookup[chip->step * 16 + (nibble & 15)]; |
| 100 | |
| 101 | /* clamp to the maximum */ |
| 102 | if (chip->signal > max) |
| 103 | chip->signal = max; |
| 104 | else if (chip->signal < min) |
| 105 | chip->signal = min; |
| 106 | |
| 107 | /* adjust the step size and clamp */ |
| 108 | chip->step += index_shift[nibble & 7]; |
| 109 | if (chip->step > 48) |
| 110 | chip->step = 48; |
| 111 | else if (chip->step < 0) |
| 112 | chip->step = 0; |
| 113 | |
| 114 | /* return the signal scaled up to 32767 */ |
| 115 | return chip->signal << 4; |
| 116 | } |
| 117 | |
| 118 | /********************************************************************************************** |
| 119 | |
| 120 | okim6258_update -- update the sound chip so that it is in sync with CPU execution |
| 121 | |
| 122 | ***********************************************************************************************/ |
| 123 | |
| 124 | static void okim6258_update(void *param, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 125 | { |
| 126 | struct okim6258 *chip = param; |
| 127 | stream_sample_t *buffer = outputs[0]; |
| 128 | |
| 129 | memset(outputs[0], 0, samples * sizeof(*outputs[0])); |
| 130 | |
| 131 | if (chip->status & STATUS_PLAYING) |
| 132 | { |
| 133 | int nibble_shift = chip->nibble_shift; |
| 134 | |
| 135 | while (samples) |
| 136 | { |
| 137 | /* Compute the new amplitude and update the current step */ |
| 138 | int nibble = (chip->data_in >> nibble_shift) & 0xf; |
| 139 | |
| 140 | /* Output to the buffer */ |
| 141 | INT16 sample = clock_adpcm(chip, nibble); |
| 142 | |
| 143 | nibble_shift ^= 4; |
| 144 | |
| 145 | *buffer++ = sample; |
| 146 | samples--; |
| 147 | } |
| 148 | |
| 149 | /* Update the parameters */ |
| 150 | chip->nibble_shift = nibble_shift; |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | /* Fill with 0 */ |
| 155 | while (samples--) |
| 156 | *buffer++ = 0; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | |
| 161 | |
| 162 | /********************************************************************************************** |
| 163 | |
| 164 | state save support for MAME |
| 165 | |
| 166 | ***********************************************************************************************/ |
| 167 | |
| 168 | static void okim6258_state_save_register(struct okim6258 *info, int sndindex) |
| 169 | { |
| 170 | char buf[20]; |
| 171 | |
| 172 | sprintf(buf, "OKIM6258"); |
| 173 | |
| 174 | state_save_register_item(buf, sndindex, info->status); |
| 175 | state_save_register_item(buf, sndindex, info->master_clock); |
| 176 | state_save_register_item(buf, sndindex, info->divider); |
| 177 | state_save_register_item(buf, sndindex, info->data_in); |
| 178 | state_save_register_item(buf, sndindex, info->nibble_shift); |
| 179 | state_save_register_item(buf, sndindex, info->signal); |
| 180 | state_save_register_item(buf, sndindex, info->step); |
| 181 | } |
| 182 | |
| 183 | |
| 184 | /********************************************************************************************** |
| 185 | |
| 186 | OKIM6258_start -- start emulation of an OKIM6258-compatible chip |
| 187 | |
| 188 | ***********************************************************************************************/ |
| 189 | |
| 190 | static void *okim6258_start(const char *tag, int sndindex, int clock, const void *config) |
| 191 | { |
| 192 | const okim6258_interface *intf = config; |
| 193 | struct okim6258 *info; |
| 194 | |
| 195 | info = auto_malloc(sizeof(*info)); |
| 196 | memset(info, 0, sizeof(*info)); |
| 197 | |
| 198 | compute_tables(); |
| 199 | |
| 200 | info->master_clock = clock; |
| 201 | info->adpcm_type = intf->adpcm_type; |
| 202 | |
| 203 | /* D/A precision is 10-bits but 12-bit data can be output serially to an external DAC */ |
| 204 | info->output_bits = intf->output_12bits ? 12 : 10; |
| 205 | info->divider = dividers[intf->divider]; |
| 206 | |
| 207 | info->stream = stream_create(0, 1, clock/info->divider, info, okim6258_update); |
| 208 | |
| 209 | info->signal = -2; |
| 210 | info->step = 0; |
| 211 | |
| 212 | okim6258_state_save_register(info, sndindex); |
| 213 | |
| 214 | return info; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | /********************************************************************************************** |
| 219 | |
| 220 | OKIM6258_stop -- stop emulation of an OKIM6258-compatible chip |
| 221 | |
| 222 | ***********************************************************************************************/ |
| 223 | |
| 224 | static void okim6258_reset(void *chip) |
| 225 | { |
| 226 | struct okim6258 *info = chip; |
| 227 | |
| 228 | stream_update(info->stream); |
| 229 | |
| 230 | info->signal = -2; |
| 231 | info->step = 0; |
| 232 | info->status = 0; |
| 233 | } |
| 234 | |
| 235 | |
| 236 | /********************************************************************************************** |
| 237 | |
| 238 | okim6258_set_divider -- set the master clock divider |
| 239 | |
| 240 | ***********************************************************************************************/ |
| 241 | |
| 242 | void okim6258_set_divider(int which, int val) |
| 243 | { |
| 244 | struct okim6258 *info = sndti_token(SOUND_OKIM6258, which); |
| 245 | int divider = dividers[val]; |
| 246 | |
| 247 | info->divider = dividers[val]; |
| 248 | stream_set_sample_rate(info->stream, info->master_clock / divider); |
| 249 | } |
| 250 | |
| 251 | |
| 252 | /********************************************************************************************** |
| 253 | |
| 254 | okim6258_set_clock -- set the master clock |
| 255 | |
| 256 | ***********************************************************************************************/ |
| 257 | |
| 258 | void okim6258_set_clock(int which, int val) |
| 259 | { |
| 260 | struct okim6258 *info = sndti_token(SOUND_OKIM6258, which); |
| 261 | |
| 262 | info->master_clock = val; |
| 263 | stream_set_sample_rate(info->stream, info->master_clock / info->divider); |
| 264 | } |
| 265 | |
| 266 | |
| 267 | /********************************************************************************************** |
| 268 | |
| 269 | okim6258_get_vclk -- get the VCLK/sampling frequency |
| 270 | |
| 271 | ***********************************************************************************************/ |
| 272 | |
| 273 | int okim6258_get_vclk(int which) |
| 274 | { |
| 275 | struct okim6258 *info = sndti_token(SOUND_OKIM6258, which); |
| 276 | |
| 277 | return (info->master_clock / info->divider); |
| 278 | } |
| 279 | |
| 280 | |
| 281 | /********************************************************************************************** |
| 282 | |
| 283 | okim6258_status_r -- read the status port of an OKIM6258-compatible chip |
| 284 | |
| 285 | ***********************************************************************************************/ |
| 286 | |
| 287 | static int okim6258_status_r(int num) |
| 288 | { |
| 289 | struct okim6258 *info = sndti_token(SOUND_OKIM6258, num); |
| 290 | |
| 291 | stream_update(info->stream); |
| 292 | |
| 293 | return (info->status & STATUS_PLAYING) ? 0x00 : 0x80; |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /********************************************************************************************** |
| 298 | |
| 299 | okim6258_data_w -- write to the control port of an OKIM6258-compatible chip |
| 300 | |
| 301 | ***********************************************************************************************/ |
| 302 | static void okim6258_data_w(int num, int data) |
| 303 | { |
| 304 | struct okim6258 *info = sndti_token(SOUND_OKIM6258, num); |
| 305 | |
| 306 | /* update the stream */ |
| 307 | stream_update(info->stream); |
| 308 | |
| 309 | info->data_in = data; |
| 310 | info->nibble_shift = 0; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | /********************************************************************************************** |
| 315 | |
| 316 | okim6258_ctrl_w -- write to the control port of an OKIM6258-compatible chip |
| 317 | |
| 318 | ***********************************************************************************************/ |
| 319 | |
| 320 | static void okim6258_ctrl_w(int num, int data) |
| 321 | { |
| 322 | struct okim6258 *info = sndti_token(SOUND_OKIM6258, num); |
| 323 | |
| 324 | stream_update(info->stream); |
| 325 | |
| 326 | if (data & COMMAND_STOP) |
| 327 | { |
| 328 | info->status &= ~(STATUS_PLAYING | STATUS_RECORDING); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | if (data & COMMAND_PLAY) |
| 333 | { |
| 334 | if (!(info->status & STATUS_PLAYING)) |
| 335 | { |
| 336 | info->status |= STATUS_PLAYING; |
| 337 | |
| 338 | /* Also reset the ADPCM parameters */ |
| 339 | info->signal = -2; |
| 340 | info->step = 0; |
| 341 | info->nibble_shift = 0; |
| 342 | } |
| 343 | } |
| 344 | else |
| 345 | { |
| 346 | info->status &= ~STATUS_PLAYING; |
| 347 | } |
| 348 | |
| 349 | if (data & COMMAND_RECORD) |
| 350 | { |
| 351 | logerror("M6258: Record enabled\n"); |
| 352 | info->status |= STATUS_RECORDING; |
| 353 | } |
| 354 | else |
| 355 | { |
| 356 | info->status &= ~STATUS_RECORDING; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | |
| 361 | /********************************************************************************************** |
| 362 | |
| 363 | okim6258_status_0_r -- generic status read functions |
| 364 | |
| 365 | ***********************************************************************************************/ |
| 366 | |
| 367 | READ8_HANDLER( okim6258_status_0_r ) |
| 368 | { |
| 369 | return okim6258_status_r(0); |
| 370 | } |
| 371 | |
| 372 | READ16_HANDLER( okim6258_status_0_lsb_r ) |
| 373 | { |
| 374 | return okim6258_status_r(0); |
| 375 | } |
| 376 | |
| 377 | READ16_HANDLER( okim6258_status_0_msb_r ) |
| 378 | { |
| 379 | return okim6258_status_r(0) << 8; |
| 380 | } |
| 381 | |
| 382 | READ8_HANDLER( okim6258_data_0_r ) |
| 383 | { |
| 384 | // TODO |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | READ16_HANDLER( okim6258_data_0_lsb_r ) |
| 389 | { |
| 390 | // TODO |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | READ16_HANDLER( okim6258_data_0_msb_r ) |
| 395 | { |
| 396 | // TODO |
| 397 | return 0; |
| 398 | } |
| 399 | |
| 400 | /********************************************************************************************** |
| 401 | |
| 402 | okim6258_data_0_w -- generic data write functions |
| 403 | okim6258_data_1_w |
| 404 | |
| 405 | ***********************************************************************************************/ |
| 406 | |
| 407 | WRITE8_HANDLER( okim6258_data_0_w ) |
| 408 | { |
| 409 | okim6258_data_w(0, data); |
| 410 | } |
| 411 | |
| 412 | WRITE8_HANDLER( okim6258_data_1_w ) |
| 413 | { |
| 414 | okim6258_data_w(1, data); |
| 415 | } |
| 416 | |
| 417 | WRITE8_HANDLER( okim6258_data_2_w ) |
| 418 | { |
| 419 | okim6258_data_w(2, data); |
| 420 | } |
| 421 | |
| 422 | WRITE16_HANDLER( okim6258_data_0_lsb_w ) |
| 423 | { |
| 424 | if (ACCESSING_BITS_0_7) |
| 425 | okim6258_data_w(0, data & 0xff); |
| 426 | } |
| 427 | |
| 428 | WRITE16_HANDLER( okim6258_data_1_lsb_w ) |
| 429 | { |
| 430 | if (ACCESSING_BITS_0_7) |
| 431 | okim6258_data_w(1, data & 0xff); |
| 432 | } |
| 433 | |
| 434 | WRITE16_HANDLER( okim6258_data_2_lsb_w ) |
| 435 | { |
| 436 | if (ACCESSING_BITS_0_7) |
| 437 | okim6258_data_w(2, data & 0xff); |
| 438 | } |
| 439 | |
| 440 | WRITE16_HANDLER( okim6258_data_0_msb_w ) |
| 441 | { |
| 442 | if (ACCESSING_BITS_8_15) |
| 443 | okim6258_data_w(0, data >> 8); |
| 444 | } |
| 445 | |
| 446 | WRITE16_HANDLER( okim6258_data_1_msb_w ) |
| 447 | { |
| 448 | if (ACCESSING_BITS_8_15) |
| 449 | okim6258_data_w(1, data >> 8); |
| 450 | } |
| 451 | |
| 452 | WRITE16_HANDLER( okim6258_data_2_msb_w ) |
| 453 | { |
| 454 | if (ACCESSING_BITS_8_15) |
| 455 | okim6258_data_w(2, data >> 8); |
| 456 | } |
| 457 | |
| 458 | WRITE16_HANDLER( okim6258_ctrl_0_lsb_w ) |
| 459 | { |
| 460 | if (ACCESSING_BITS_0_7) |
| 461 | okim6258_ctrl_w(0, data & 0xff); |
| 462 | } |
| 463 | |
| 464 | |
| 465 | /************************************************************************** |
| 466 | * Generic get_info |
| 467 | **************************************************************************/ |
| 468 | |
| 469 | static void okim6258_set_info(void *token, UINT32 state, sndinfo *info) |
| 470 | { |
| 471 | switch (state) |
| 472 | { |
| 473 | /* no parameters to set */ |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | |
| 478 | void okim6258_get_info(void *token, UINT32 state, sndinfo *info) |
| 479 | { |
| 480 | switch (state) |
| 481 | { |
| 482 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 483 | |
| 484 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 485 | case SNDINFO_PTR_SET_INFO: info->set_info = okim6258_set_info; break; |
| 486 | case SNDINFO_PTR_START: info->start = okim6258_start; break; |
| 487 | case SNDINFO_PTR_STOP: /* nothing */ break; |
| 488 | case SNDINFO_PTR_RESET: info->reset = okim6258_reset; break; |
| 489 | |
| 490 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 491 | case SNDINFO_STR_NAME: info->s = "OKI6258"; break; |
| 492 | case SNDINFO_STR_CORE_FAMILY: info->s = "OKI ADPCM"; break; |
| 493 | case SNDINFO_STR_CORE_VERSION: info->s = "1.0"; break; |
| 494 | case SNDINFO_STR_CORE_FILE: info->s = __FILE__; break; |
| 495 | case SNDINFO_STR_CORE_CREDITS: info->s = "Copyright Nicola Salmoria and the MAME Team"; break; |
| 496 | } |
| 497 | } |
| 498 | |
src/mess/machine/hd63450.c
| r3559 | r3560 | |
| 26 | 26 | dmac->timer[x] = timer_alloc(dma_transfer_timer, (void*)device); |
| 27 | 27 | dmac->reg[x].niv = 0x0f; // defaults? |
| 28 | 28 | dmac->reg[x].eiv = 0x0f; |
| 29 | dmac->clock[x] = dmac->intf->clock[x]; |
| 30 | dmac->burst_clock[x] = dmac->intf->burst_clock[x]; |
| 29 | 31 | } |
| 30 | 32 | return DEVICE_START_OK; |
| 31 | 33 | } |
| r3559 | r3560 | |
| 200 | 202 | dmac->reg[channel].csr &= ~0xe0; |
| 201 | 203 | dmac->reg[channel].csr |= 0x08; // Channel active |
| 202 | 204 | dmac->reg[channel].csr &= ~0x30; // Reset Error and Normal termination bits |
| 203 | | if(dmac->reg[channel].btc > 0) |
| 205 | if((dmac->reg[channel].ocr & 0x0c) != 0x00) // Array chain or Link array chain |
| 204 | 206 | { |
| 205 | 207 | dmac->reg[channel].mar = program_read_word(dmac->reg[channel].bar) << 16; |
| 206 | 208 | dmac->reg[channel].mar |= program_read_word(dmac->reg[channel].bar+2); |
| 207 | 209 | dmac->reg[channel].mtc = program_read_word(dmac->reg[channel].bar+4); |
| 208 | | dmac->reg[channel].btc--; |
| 210 | if(dmac->reg[channel].btc > 0) |
| 211 | dmac->reg[channel].btc--; |
| 209 | 212 | } |
| 210 | 213 | |
| 211 | 214 | // Burst transfers will halt the CPU until the transfer is complete |
| 212 | 215 | if((dmac->reg[channel].dcr & 0xc0) == 0x00) // Burst transfer |
| 213 | 216 | { |
| 214 | 217 | cpunum_set_input_line(device->machine, dmac->intf->cpu,INPUT_LINE_HALT,ASSERT_LINE); |
| 215 | | timer_adjust_periodic(dmac->timer[channel], attotime_zero, channel, dmac->intf->burst_clock[channel]); |
| 218 | timer_adjust_periodic(dmac->timer[channel], attotime_zero, channel, dmac->burst_clock[channel]); |
| 216 | 219 | } |
| 217 | 220 | else |
| 218 | | timer_adjust_periodic(dmac->timer[channel], ATTOTIME_IN_USEC(500), channel, dmac->intf->clock[channel]); |
| 221 | timer_adjust_periodic(dmac->timer[channel], ATTOTIME_IN_USEC(500), channel, dmac->clock[channel]); |
| 219 | 222 | |
| 220 | | |
| 221 | 223 | dmac->transfer_size[channel] = dmac->reg[channel].mtc; |
| 222 | 224 | |
| 223 | 225 | logerror("DMA: Transfer begins: size=0x%08x\n",dmac->transfer_size[channel]); |
| 224 | 226 | } |
| 225 | 227 | |
| 228 | void hd63450_set_timer(const device_config* device, int channel, attotime tm) |
| 229 | { |
| 230 | hd63450_t* dmac = device->token; |
| 231 | |
| 232 | dmac->clock[channel] = tm; |
| 233 | if(dmac->in_progress[channel] != 0) |
| 234 | timer_adjust_periodic(dmac->timer[channel], attotime_zero, channel, dmac->clock[channel]); |
| 235 | } |
| 236 | |
| 226 | 237 | static TIMER_CALLBACK(dma_transfer_timer) |
| 227 | 238 | { |
| 228 | 239 | hd63450_single_transfer(ptr, param); |
| r3559 | r3560 | |
| 255 | 266 | if(dmac->halted[channel] != 0) |
| 256 | 267 | { |
| 257 | 268 | dmac->halted[channel] = 0; |
| 258 | | timer_adjust_periodic(dmac->timer[channel], attotime_zero, channel, dmac->intf->clock[channel]); |
| 269 | timer_adjust_periodic(dmac->timer[channel], attotime_zero, channel, dmac->clock[channel]); |
| 259 | 270 | } |
| 260 | 271 | } |
| 261 | 272 | |
| r3559 | r3560 | |
| 366 | 377 | { |
| 367 | 378 | // End of transfer |
| 368 | 379 | logerror("DMA#%i: End of transfer\n",x); |
| 369 | | if(dmac->reg[x].btc > 0) |
| 380 | if((dmac->reg[x].ocr & 0x0c) != 0 && dmac->reg[x].btc > 0) |
| 370 | 381 | { |
| 371 | 382 | dmac->reg[x].btc--; |
| 372 | 383 | dmac->reg[x].bar+=6; |
src/mess/drivers/x68k.c
| r3559 | r3560 | |
| 105 | 105 | Keyboard doesn't work (MFP USART). |
| 106 | 106 | Supervisor area set isn't implemented. |
| 107 | 107 | |
| 108 | | Some minor game-specific issues (at 22/10/08): |
| 108 | Some minor game-specific issues (at 14/05/08): |
| 109 | 109 | Pacmania: Black squares on the maze (transparency?). |
| 110 | Nemesis '94: Menu system doesn't work except for start buttons. |
| 111 | Flying Shark: Appears to lock up at main menu. |
| 110 | 112 | Salamander: System error when using keys in-game. No error if a joystick is used. |
| 111 | 113 | Kyukyoku Tiger:Sprites offset by a looooong way. |
| 112 | | Dragon Buster: Text is black and unreadable. |
| 113 | | Baraduke: Locks up on demo mode. |
| 114 | Dragon Buster: Text is black and unreadable (text palette should be loaded from disk, but it reads all zeroes). |
| 115 | Baraduke: Corrupt background, locks up on demo mode. |
| 116 | Viewpoint: Corrupt graphics on title screen, phantom movements on title screen, corrupt sprites, locks up. |
| 114 | 117 | Tetris: Black dots over screen (text layer). |
| 115 | 118 | Parodius Da!: Black squares in areas. |
| 116 | 119 | |
| r3559 | r3560 | |
| 126 | 129 | #include "machine/8255ppi.h" |
| 127 | 130 | #include "machine/nec765.h" |
| 128 | 131 | #include "sound/2151intf.h" |
| 129 | | #include "sound/okim6295.h" |
| 132 | #include "sound/okim6258.h" |
| 130 | 133 | #include "machine/8530scc.h" |
| 131 | 134 | #include "machine/hd63450.h" |
| 132 | 135 | #include "machine/rp5c15.h" |
| r3559 | r3560 | |
| 650 | 653 | } |
| 651 | 654 | } |
| 652 | 655 | |
| 656 | static void x68k_set_adpcm(running_machine* machine) |
| 657 | { |
| 658 | const device_config *dev = device_list_find_by_tag(machine->config->devicelist, HD63450, "hd63450"); |
| 659 | UINT32 rate = 0; |
| 660 | |
| 661 | switch(sys.adpcm.rate & 0x0c) |
| 662 | { |
| 663 | case 0x00: |
| 664 | rate = 7812/2; |
| 665 | break; |
| 666 | case 0x04: |
| 667 | rate = 10417/2; |
| 668 | break; |
| 669 | case 0x08: |
| 670 | rate = 15625/2; |
| 671 | break; |
| 672 | default: |
| 673 | logerror("PPI: Invalid ADPCM sample rate set.\n"); |
| 674 | rate = 15625/2; |
| 675 | } |
| 676 | if(sys.adpcm.clock != 0) |
| 677 | rate = rate/2; |
| 678 | hd63450_set_timer(dev,3,ATTOTIME_IN_HZ(rate)); |
| 679 | } |
| 680 | |
| 681 | |
| 653 | 682 | // Judging from the XM6 source code, PPI ports A and B are joystick inputs |
| 654 | 683 | static READ8_DEVICE_HANDLER( ppi_port_a_r ) |
| 655 | 684 | { |
| r3559 | r3560 | |
| 685 | 714 | static WRITE8_DEVICE_HANDLER( ppi_port_c_w ) |
| 686 | 715 | { |
| 687 | 716 | // ADPCM / Joystick control |
| 717 | |
| 688 | 718 | ppi_port[2] = data; |
| 689 | 719 | sys.adpcm.pan = data & 0x03; |
| 690 | 720 | sys.adpcm.rate = data & 0x0c; |
| 721 | x68k_set_adpcm(device->machine); |
| 722 | okim6258_set_divider(0, (data >> 2) & 3); |
| 723 | |
| 691 | 724 | sys.joy.joy1_enable = data & 0x10; |
| 692 | 725 | sys.joy.joy2_enable = data & 0x20; |
| 693 | 726 | sys.joy.ioc6 = data & 0x40; |
| r3559 | r3560 | |
| 695 | 728 | } |
| 696 | 729 | |
| 697 | 730 | |
| 698 | | |
| 699 | 731 | // NEC uPD72065 at 0xe94000 |
| 700 | 732 | static WRITE16_HANDLER( x68k_fdc_w ) |
| 701 | 733 | { |
| r3559 | r3560 | |
| 866 | 898 | // CT1 - ADPCM clock - 0 = 8MHz, 1 = 4MHz |
| 867 | 899 | // CT2 - 1 = Set ready state of FDC |
| 868 | 900 | nec765_set_ready_state(data & 0x01); |
| 901 | sys.adpcm.clock = data & 0x02; |
| 902 | x68k_set_adpcm(machine); |
| 903 | okim6258_set_clock(0, data & 0x02 ? 4000000 : 8000000); |
| 869 | 904 | } |
| 870 | 905 | |
| 871 | 906 | /* |
| r3559 | r3560 | |
| 1330 | 1365 | return 0xff; |
| 1331 | 1366 | } |
| 1332 | 1367 | |
| 1333 | | static READ16_HANDLER( x68k_adpcm_r ) |
| 1334 | | { |
| 1335 | | return 0x0000; |
| 1336 | | } |
| 1337 | | |
| 1338 | | static WRITE16_HANDLER( x68k_adpcm_w ) |
| 1339 | | { |
| 1340 | | } |
| 1341 | | |
| 1342 | 1368 | static READ16_HANDLER( x68k_areaset_r ) |
| 1343 | 1369 | { |
| 1344 | 1370 | // register is write-only |
| r3559 | r3560 | |
| 1500 | 1526 | prev = level; |
| 1501 | 1527 | } |
| 1502 | 1528 | |
| 1529 | static INTERRUPT_GEN( x68k_vsync_irq ) |
| 1530 | { |
| 1531 | // if(sys.mfp.ierb & 0x40) |
| 1532 | // { |
| 1533 | // sys.mfp.isrb |= 0x40; |
| 1534 | // current_vector[6] = (sys.mfp.vr & 0xf0) | 0x06; // GPIP4 (V-DISP) |
| 1535 | // current_irq_line = 6; |
| 1536 | // mfp_timer_a_callback(0); // Timer A is usually always in event count mode, and is tied to V-DISP |
| 1537 | // mfp_trigger_irq(MFP_IRQ_GPIP4); |
| 1538 | // } |
| 1539 | // if(sys.crtc.height == 256) |
| 1540 | // video_screen_update_partial(machine->primary_screen,256);//sys.crtc.reg[4]/2); |
| 1541 | // else |
| 1542 | // video_screen_update_partial(machine->primary_screen,512);//sys.crtc.reg[4]); |
| 1543 | } |
| 1544 | |
| 1503 | 1545 | static IRQ_CALLBACK(x68k_int_ack) |
| 1504 | 1546 | { |
| 1505 | 1547 | const device_config *x68k_mfp = device_list_find_by_tag(machine->config->devicelist, MC68901, MC68901_TAG); |
| 1506 | 1548 | |
| 1507 | 1549 | if(irqline == 6) // MFP |
| 1508 | 1550 | { |
| 1551 | // if(sys.mfp.isra & 0x10) |
| 1552 | // sys.mfp.rsr &= ~0x80; |
| 1553 | // if(sys.mfp.isra & 0x04) |
| 1554 | // sys.mfp.tsr &= ~0x80; |
| 1555 | |
| 1556 | // if(sys.mfp.current_irq < 8) |
| 1557 | // { |
| 1558 | // sys.mfp.iprb &= ~(1 << sys.mfp.current_irq); |
| 1559 | // IRQ is in service |
| 1560 | // if(sys.mfp.eoi_mode != 0) // automatic EOI does not set the ISR registers |
| 1561 | // sys.mfp.isrb |= (1 << sys.mfp.current_irq); |
| 1562 | // } |
| 1563 | // else |
| 1564 | // { |
| 1565 | // sys.mfp.ipra &= ~(1 << (sys.mfp.current_irq - 8)); |
| 1566 | // IRQ is in service |
| 1567 | // if(sys.mfp.eoi_mode != 0) // automatic EOI does not set the ISR registers |
| 1568 | // sys.mfp.isra |= (1 << (sys.mfp.current_irq - 8)); |
| 1569 | // } |
| 1509 | 1570 | sys.mfp.current_irq = -1; |
| 1510 | 1571 | current_vector[6] = mc68901_get_vector(x68k_mfp); |
| 1511 | 1572 | logerror("SYS: IRQ acknowledged (vector=0x%02x, line = %i)\n",current_vector[6],irqline); |
| r3559 | r3560 | |
| 1542 | 1603 | // AM_RANGE(0xe8c000, 0xe8dfff) AM_READWRITE(x68k_printer_r, x68k_printer_w) |
| 1543 | 1604 | AM_RANGE(0xe8e000, 0xe8ffff) AM_READWRITE(x68k_sysport_r, x68k_sysport_w) |
| 1544 | 1605 | AM_RANGE(0xe90000, 0xe91fff) AM_READWRITE(x68k_fm_r, x68k_fm_w) |
| 1545 | | AM_RANGE(0xe92000, 0xe93fff) AM_READWRITE(x68k_adpcm_r, x68k_adpcm_w) |
| 1606 | AM_RANGE(0xe92000, 0xe92001) AM_READWRITE(okim6258_status_0_lsb_r, okim6258_ctrl_0_lsb_w) |
| 1607 | AM_RANGE(0xe92002, 0xe92003) AM_READWRITE(okim6258_data_0_lsb_r, okim6258_data_0_lsb_w) |
| 1546 | 1608 | AM_RANGE(0xe94000, 0xe95fff) AM_READWRITE(x68k_fdc_r, x68k_fdc_w) |
| 1547 | 1609 | AM_RANGE(0xe96000, 0xe97fff) AM_DEVREADWRITE(X68KHDC,"x68k_hdc",x68k_hdc_r, x68k_hdc_w) |
| 1548 | 1610 | AM_RANGE(0xe98000, 0xe99fff) AM_READWRITE(x68k_scc_r, x68k_scc_w) |
| r3559 | r3560 | |
| 1586 | 1648 | static const hd63450_intf dmac_interface = |
| 1587 | 1649 | { |
| 1588 | 1650 | 0, // CPU - 68000 |
| 1589 | | {STATIC_ATTOTIME_IN_USEC(32),STATIC_ATTOTIME_IN_NSEC(450),STATIC_ATTOTIME_IN_USEC(4),STATIC_ATTOTIME_IN_USEC(32)}, // Cycle steal mode timing (guesstimate) |
| 1651 | {STATIC_ATTOTIME_IN_USEC(32),STATIC_ATTOTIME_IN_NSEC(450),STATIC_ATTOTIME_IN_USEC(4),STATIC_ATTOTIME_IN_HZ(15625/2)}, // Cycle steal mode timing (guesstimate) |
| 1590 | 1652 | {STATIC_ATTOTIME_IN_USEC(32),STATIC_ATTOTIME_IN_NSEC(450),STATIC_ATTOTIME_IN_NSEC(50),STATIC_ATTOTIME_IN_NSEC(50)}, // Burst mode timing (guesstimate) |
| 1591 | 1653 | x68k_dma_end, |
| 1592 | 1654 | x68k_dma_error, |
| r3559 | r3560 | |
| 1608 | 1670 | x68k_ct_w // CT1, CT2 from YM2151 port 0x1b |
| 1609 | 1671 | }; |
| 1610 | 1672 | |
| 1673 | static const okim6258_interface x68k_okim6258_interface = |
| 1674 | { |
| 1675 | FOSC_DIV_BY_512, |
| 1676 | TYPE_4BITS, |
| 1677 | OUTPUT_10BITS, |
| 1678 | }; |
| 1679 | |
| 1611 | 1680 | static const struct rp5c15_interface rtc_intf = |
| 1612 | 1681 | { |
| 1613 | 1682 | x68k_rtc_alarm_irq |
| r3559 | r3560 | |
| 2050 | 2119 | led_timer = timer_alloc(x68k_led_callback,NULL); |
| 2051 | 2120 | } |
| 2052 | 2121 | |
| 2053 | | |
| 2054 | 2122 | static MACHINE_DRIVER_START( x68000 ) |
| 2055 | 2123 | /* basic machine hardware */ |
| 2056 | 2124 | MDRV_CPU_ADD("main", M68000, 10000000) /* 10 MHz */ |
| 2057 | 2125 | MDRV_CPU_PROGRAM_MAP(x68k_map, 0) |
| 2126 | MDRV_CPU_VBLANK_INT("main", x68k_vsync_irq) |
| 2058 | 2127 | MDRV_INTERLEAVE(1) |
| 2059 | 2128 | |
| 2060 | 2129 | MDRV_MACHINE_START( x68000 ) |
| r3559 | r3560 | |
| 2095 | 2164 | MDRV_SOUND_ADD("ym2151", YM2151, 4000000) |
| 2096 | 2165 | MDRV_SOUND_CONFIG(x68k_ym2151_interface) |
| 2097 | 2166 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 2098 | | // MDRV_SOUND_ADD("okim6295", OKIM6295, 0) |
| 2099 | | // MDRV_SOUND_CONFIG(oki_interface) |
| 2100 | | // MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00) |
| 2167 | MDRV_SOUND_ADD("okim6258", OKIM6258, 4000000) |
| 2168 | MDRV_SOUND_CONFIG(x68k_okim6258_interface) |
| 2169 | MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00) |
| 2101 | 2170 | |
| 2102 | 2171 | MDRV_NVRAM_HANDLER( generic_0fill ) |
| 2103 | 2172 | MACHINE_DRIVER_END |