src/mess/machine/cdicdic.c
| r0 | r8790 | |
| 1 | /****************************************************************************** |
| 2 | |
| 3 | |
| 4 | CD-i Mono-I CDIC MCU simulation |
| 5 | ------------------- |
| 6 | |
| 7 | MESS implementation by Harmony |
| 8 | |
| 9 | |
| 10 | ******************************************************************************* |
| 11 | |
| 12 | STATUS: |
| 13 | |
| 14 | - Just enough for the Mono-I CD-i board to work somewhat properly. |
| 15 | |
| 16 | TODO: |
| 17 | |
| 18 | - Decapping and proper emulation. |
| 19 | |
| 20 | *******************************************************************************/ |
| 21 | |
| 22 | #include "emu.h" |
| 23 | #include "cpu/m68000/m68000.h" |
| 24 | #include "machine/cdicdic.h" |
| 25 | #include "includes/cdi.h" |
| 26 | #include "sound/cdda.h" |
| 27 | |
| 28 | #if ENABLE_VERBOSE_LOG |
| 29 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| 30 | { |
| 31 | if( VERBOSE_LEVEL >= n_level ) |
| 32 | { |
| 33 | va_list v; |
| 34 | char buf[ 32768 ]; |
| 35 | va_start( v, s_fmt ); |
| 36 | vsprintf( buf, s_fmt, v ); |
| 37 | va_end( v ); |
| 38 | logerror( "%08x: %s", cpu_get_pc(machine->device("maincpu")), buf ); |
| 39 | } |
| 40 | } |
| 41 | #else |
| 42 | #define verboselog(x,y,z,...) |
| 43 | #endif |
| 44 | |
| 45 | static void cdic_decode_xa_mono(int *cdic_xa_last, const unsigned char *xa, signed short *dp); |
| 46 | static void cdic_decode_xa_mono8(int *cdic_xa_last, const unsigned char *xa, signed short *dp); |
| 47 | static void cdic_decode_xa_stereo(int *cdic_xa_last, const unsigned char *xa, signed short *dp); |
| 48 | static void cdic_decode_xa_stereo8(int *cdic_xa_last, const unsigned char *xa, signed short *dp); |
| 49 | static void cdic_decode_audio_sector(running_machine *machine, const unsigned char *xa, int triggered); |
| 50 | static UINT32 increment_cdda_frame_bcd(UINT32 bcd); |
| 51 | static UINT32 increment_cdda_sector_bcd(UINT32 bcd); |
| 52 | |
| 53 | static const INT32 cdic_adpcm_filter_coef[5][2] = |
| 54 | { |
| 55 | { 0,0 }, |
| 56 | { 60,0 }, |
| 57 | { 115,-52 }, |
| 58 | { 98,-55 }, |
| 59 | { 122,-60 }, |
| 60 | }; |
| 61 | |
| 62 | INLINE int CDIC_IS_VALID_SAMPLE_BUF(UINT16 *cdram, UINT16 addr) |
| 63 | { |
| 64 | UINT8 *cdram8 = ((UINT8*)cdram) + addr + 8; |
| 65 | if(cdram8[2] != 0xff) |
| 66 | { |
| 67 | return 1; |
| 68 | } |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | INLINE double CDIC_SAMPLE_BUF_FREQ(UINT16 *cdram, UINT16 addr) |
| 73 | { |
| 74 | UINT8 *cdram8 = ((UINT8*)cdram) + addr + 8; |
| 75 | switch(cdram8[2] & 0x3f) |
| 76 | { |
| 77 | case 0: |
| 78 | case 1: |
| 79 | case 16: |
| 80 | case 17: |
| 81 | return 37800.0f; |
| 82 | |
| 83 | case 4: |
| 84 | case 5: |
| 85 | return 18900.0f; |
| 86 | |
| 87 | default: |
| 88 | return 18900.0f; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | INLINE int CDIC_SAMPLE_BUF_SIZE(UINT16 *cdram, UINT16 addr) |
| 93 | { |
| 94 | UINT8 *cdram8 = ((UINT8*)cdram) + addr + 8; |
| 95 | switch(cdram8[2] & 0x3f) |
| 96 | { |
| 97 | case 0: |
| 98 | case 4: |
| 99 | return 4; |
| 100 | |
| 101 | case 1: |
| 102 | case 5: |
| 103 | case 16: |
| 104 | return 2; |
| 105 | |
| 106 | case 17: |
| 107 | return 1; |
| 108 | |
| 109 | default: |
| 110 | return 2; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | INLINE INT16 clamp(INT16 in) |
| 115 | { |
| 116 | return in; |
| 117 | } |
| 118 | |
| 119 | static void cdic_decode_xa_mono(int *cdic_xa_last, const unsigned char *xa, signed short *dp) |
| 120 | { |
| 121 | int l0=cdic_xa_last[0], |
| 122 | l1=cdic_xa_last[1]; |
| 123 | int b=0; |
| 124 | int s=0; |
| 125 | |
| 126 | for (b=0; b<18; b++) |
| 127 | { |
| 128 | for (s=0; s<4; s++) |
| 129 | { |
| 130 | unsigned char flags=xa[(4+(s<<1))^1], |
| 131 | shift=flags&0xf, |
| 132 | filter=flags>>4; |
| 133 | int f0=cdic_adpcm_filter_coef[filter][0], |
| 134 | f1=cdic_adpcm_filter_coef[filter][1]; |
| 135 | int i=0; |
| 136 | |
| 137 | for (i=0; i<28; i++) |
| 138 | { |
| 139 | short d=(xa[(16+(i<<2)+s)^1]&0xf)<<12; |
| 140 | d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 141 | *dp++=d; |
| 142 | l1=l0; |
| 143 | l0=d; |
| 144 | } |
| 145 | |
| 146 | flags=xa[(5+(s<<1))^1]; |
| 147 | shift=flags&0xf; |
| 148 | filter=flags>>4; |
| 149 | f0=cdic_adpcm_filter_coef[filter][0]; |
| 150 | f1=cdic_adpcm_filter_coef[filter][1]; |
| 151 | |
| 152 | for (i=0; i<28; i++) |
| 153 | { |
| 154 | short d=(xa[(16+(i<<2)+s)^1]>>4)<<12; |
| 155 | d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 156 | *dp++=d; |
| 157 | l1=l0; |
| 158 | l0=d; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | xa+=128; |
| 163 | } |
| 164 | |
| 165 | cdic_xa_last[0]=l0; |
| 166 | cdic_xa_last[1]=l1; |
| 167 | } |
| 168 | |
| 169 | static void cdic_decode_xa_mono8(int *cdic_xa_last, const unsigned char *xa, signed short *dp) |
| 170 | { |
| 171 | int l0=cdic_xa_last[0], |
| 172 | l1=cdic_xa_last[1]; |
| 173 | int b=0; |
| 174 | int s=0; |
| 175 | |
| 176 | for (b=0; b<18; b++) |
| 177 | { |
| 178 | for (s=0; s<4; s++) |
| 179 | { |
| 180 | unsigned char flags=xa[(4+s)^1], |
| 181 | shift=flags&0xf, |
| 182 | filter=flags>>4; |
| 183 | int f0=cdic_adpcm_filter_coef[filter][0], |
| 184 | f1=cdic_adpcm_filter_coef[filter][1]; |
| 185 | int i=0; |
| 186 | |
| 187 | for (i=0; i<28; i++) |
| 188 | { |
| 189 | short d=(xa[(16+(i<<2)+s)^1]<<8); |
| 190 | d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 191 | *dp++=d; |
| 192 | l1=l0; |
| 193 | l0=d; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | xa+=128; |
| 198 | } |
| 199 | |
| 200 | cdic_xa_last[0]=l0; |
| 201 | cdic_xa_last[1]=l1; |
| 202 | } |
| 203 | |
| 204 | static void cdic_decode_xa_stereo(int *cdic_xa_last, const unsigned char *xa, signed short *dp) |
| 205 | { |
| 206 | int l0=cdic_xa_last[0], |
| 207 | l1=cdic_xa_last[1], |
| 208 | l2=cdic_xa_last[2], |
| 209 | l3=cdic_xa_last[3]; |
| 210 | int b=0; |
| 211 | int s=0; |
| 212 | //int decoded = 0; |
| 213 | |
| 214 | for (b=0; b<18; b++) |
| 215 | { |
| 216 | for (s=0; s<4; s++) |
| 217 | { |
| 218 | unsigned char flags0=xa[(4+(s<<1))^1], |
| 219 | shift0=flags0&0xf, |
| 220 | filter0=flags0>>4, |
| 221 | flags1=xa[(5+(s<<1))^1], |
| 222 | shift1=flags1&0xf, |
| 223 | filter1=flags1>>4; |
| 224 | |
| 225 | int f0=cdic_adpcm_filter_coef[filter0][0], |
| 226 | f1=cdic_adpcm_filter_coef[filter0][1], |
| 227 | f2=cdic_adpcm_filter_coef[filter1][0], |
| 228 | f3=cdic_adpcm_filter_coef[filter1][1]; |
| 229 | int i=0; |
| 230 | |
| 231 | for (i=0; i<28; i++) |
| 232 | { |
| 233 | short d=xa[(16+(i<<2)+s)^1], |
| 234 | d0=(d&0xf)<<12, |
| 235 | d1=(d>>4)<<12; |
| 236 | d0=clamp((d0>>shift0)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 237 | *dp++=d0; |
| 238 | l1=l0; |
| 239 | l0=d0; |
| 240 | |
| 241 | d1=clamp((d1>>shift1)+(((l2*f2)+(l3*f3)+32)>>6)); |
| 242 | *dp++=d1; |
| 243 | l3=l2; |
| 244 | l2=d1; |
| 245 | //decoded += 2; |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | xa+=128; |
| 250 | } |
| 251 | |
| 252 | cdic_xa_last[0]=l0; |
| 253 | cdic_xa_last[1]=l1; |
| 254 | cdic_xa_last[2]=l2; |
| 255 | cdic_xa_last[3]=l3; |
| 256 | |
| 257 | //printf( "Decoded %d samples\n", decoded ); |
| 258 | } |
| 259 | |
| 260 | static void cdic_decode_xa_stereo8(int *cdic_xa_last, const unsigned char *xa, signed short *dp) |
| 261 | { |
| 262 | int l0=cdic_xa_last[0], |
| 263 | l1=cdic_xa_last[1], |
| 264 | l2=cdic_xa_last[2], |
| 265 | l3=cdic_xa_last[3]; |
| 266 | int b=0; |
| 267 | int s=0; |
| 268 | |
| 269 | for (b=0; b<18; b++) |
| 270 | { |
| 271 | for (s=0; s<4; s += 2) |
| 272 | { |
| 273 | unsigned char flags0=xa[(4+s)^1], |
| 274 | shift0=flags0&0xf, |
| 275 | filter0=flags0>>4, |
| 276 | flags1=xa[(5+s)^1], |
| 277 | shift1=flags1&0xf, |
| 278 | filter1=flags1>>4; |
| 279 | int f0=cdic_adpcm_filter_coef[filter0][0], |
| 280 | f1=cdic_adpcm_filter_coef[filter0][1], |
| 281 | f2=cdic_adpcm_filter_coef[filter1][0], |
| 282 | f3=cdic_adpcm_filter_coef[filter1][1]; |
| 283 | int i=0; |
| 284 | |
| 285 | for (i=0; i<28; i++) |
| 286 | { |
| 287 | //short d0=(xa[(16+((i+0)<<2)+s)^1]<<8); |
| 288 | //short d1=(xa[(16+((i+1)<<2)+s)^1]<<8); |
| 289 | short d0=(xa[(16+(i<<2)+s+0)^1]<<8); |
| 290 | short d1=(xa[(16+(i<<2)+s+1)^1]<<8); |
| 291 | |
| 292 | d0=clamp((d0>>shift0)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 293 | *dp++=d0; |
| 294 | l1=l0; |
| 295 | l0=d0; |
| 296 | |
| 297 | d1=clamp((d1>>shift1)+(((l2*f2)+(l3*f3)+32)>>6)); |
| 298 | *dp++=d1; |
| 299 | l3=l2; |
| 300 | l2=d1; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | xa+=128; |
| 305 | } |
| 306 | |
| 307 | cdic_xa_last[0]=l0; |
| 308 | cdic_xa_last[1]=l1; |
| 309 | cdic_xa_last[2]=l2; |
| 310 | cdic_xa_last[3]=l3; |
| 311 | } |
| 312 | |
| 313 | void cdic_decode_audio_sector(running_machine *machine, const unsigned char *xa, int triggered) |
| 314 | { |
| 315 | // Get XA format from sector header |
| 316 | |
| 317 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 318 | cdic_regs_t *cdic = &state->cdic_regs; |
| 319 | const unsigned char *hdr = xa + 4; |
| 320 | int channels; |
| 321 | int bits = 4; |
| 322 | int index = 0; |
| 323 | INT16 samples[18*28*16+16]; |
| 324 | //FILE* temp_adpcm = fopen("temp_adpcm.bin","ab"); |
| 325 | |
| 326 | //printf( "%02x\n", hdr[2] & 0x3f ); |
| 327 | |
| 328 | if(hdr[2] == 0xff && triggered == 1) |
| 329 | { |
| 330 | // Don't play |
| 331 | //timer_adjust_oneshot(cdic->audio_sample_timer, attotime_never, 0); |
| 332 | //fclose(temp_adpcm); |
| 333 | return; |
| 334 | } |
| 335 | |
| 336 | verboselog(machine, 0, "cdic_decode_audio_sector, got header type %02x\n", hdr[2] ); |
| 337 | |
| 338 | //fseek(temp_adpcm, 0, SEEK_END); |
| 339 | switch(hdr[2] & 0x3f) // ignore emphasis and reserved bits |
| 340 | { |
| 341 | case 0: |
| 342 | channels=1; |
| 343 | cdic->audio_sample_freq=37800.0f; //18900.0f; |
| 344 | bits=4; |
| 345 | cdic->audio_sample_size=4; |
| 346 | break; |
| 347 | |
| 348 | case 1: |
| 349 | channels=2; |
| 350 | cdic->audio_sample_freq=37800.0f; |
| 351 | bits=4; |
| 352 | cdic->audio_sample_size=2; |
| 353 | break; |
| 354 | |
| 355 | case 4: |
| 356 | channels=1; |
| 357 | cdic->audio_sample_freq=18900.0f; ///2.0f; |
| 358 | bits=4; |
| 359 | cdic->audio_sample_size=4; |
| 360 | break; |
| 361 | |
| 362 | case 5: |
| 363 | channels=2; |
| 364 | cdic->audio_sample_freq=18900.0f; //37800.0f/2.0f; |
| 365 | bits=4; |
| 366 | cdic->audio_sample_size=2; |
| 367 | break; |
| 368 | |
| 369 | case 16: |
| 370 | channels=1; |
| 371 | cdic->audio_sample_freq=37800.0f; |
| 372 | bits=8; |
| 373 | cdic->audio_sample_size=2; |
| 374 | break; |
| 375 | |
| 376 | case 17: |
| 377 | channels=2; |
| 378 | cdic->audio_sample_freq=37800.0f; |
| 379 | bits=8; |
| 380 | cdic->audio_sample_size=1; |
| 381 | break; |
| 382 | |
| 383 | default: |
| 384 | fatalerror("play_xa: unhandled xa mode %08x",hdr[2]); |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | dmadac_set_frequency(&state->dmadac[0], 2, cdic->audio_sample_freq); |
| 389 | dmadac_enable(&state->dmadac[0], 2, 1); |
| 390 | |
| 391 | switch(channels) |
| 392 | { |
| 393 | case 1: |
| 394 | switch(bits) |
| 395 | { |
| 396 | case 4: |
| 397 | cdic_decode_xa_mono(cdic->xa_last, hdr + 4, samples); |
| 398 | for(index = 18*28*8 - 1; index >= 0; index--) |
| 399 | { |
| 400 | samples[index*2 + 1] = samples[index]; |
| 401 | samples[index*2 + 0] = samples[index]; |
| 402 | } |
| 403 | samples[18*28*16 + 0] = samples[18*28*16 + 2] = samples[18*28*16 + 4] = samples[18*28*16 + 6] = samples[18*28*16 + 8] = samples[18*28*16 + 10] = samples[18*28*16 + 12] = samples[18*28*16 + 14] = samples[18*28*16 - 2]; |
| 404 | samples[18*28*16 + 1] = samples[18*28*16 + 3] = samples[18*28*16 + 5] = samples[18*28*16 + 7] = samples[18*28*16 + 9] = samples[18*28*16 + 11] = samples[18*28*16 + 13] = samples[18*28*16 + 15] = samples[18*28*16 - 1]; |
| 405 | break; |
| 406 | case 8: |
| 407 | cdic_decode_xa_mono8(cdic->xa_last, hdr + 4, samples); |
| 408 | for(index = 18*28*8 - 1; index >= 0; index--) |
| 409 | { |
| 410 | samples[index*2 + 1] = samples[index]; |
| 411 | samples[index*2 + 0] = samples[index]; |
| 412 | } |
| 413 | samples[18*28*8 + 0] = samples[18*28*8 + 2] = samples[18*28*8 + 4] = samples[18*28*8 + 6] = samples[18*28*8 + 8] = samples[18*28*8 + 10] = samples[18*28*8 + 12] = samples[18*28*8 + 14] = samples[18*28*8 - 2]; |
| 414 | samples[18*28*8 + 1] = samples[18*28*8 + 3] = samples[18*28*8 + 5] = samples[18*28*8 + 7] = samples[18*28*8 + 9] = samples[18*28*8 + 11] = samples[18*28*8 + 13] = samples[18*28*8 + 15] = samples[18*28*8 - 1]; |
| 415 | break; |
| 416 | } |
| 417 | break; |
| 418 | case 2: |
| 419 | switch(bits) |
| 420 | { |
| 421 | case 4: |
| 422 | cdic_decode_xa_stereo(cdic->xa_last, hdr + 4, samples); |
| 423 | samples[18*28*8 + 0] = samples[18*28*8 + 2] = samples[18*28*8 + 4] = samples[18*28*8 + 6] = samples[18*28*8 + 8] = samples[18*28*8 + 10] = samples[18*28*8 + 12] = samples[18*28*8 + 14] = samples[18*28*8 - 2]; |
| 424 | samples[18*28*8 + 1] = samples[18*28*8 + 3] = samples[18*28*8 + 5] = samples[18*28*8 + 7] = samples[18*28*8 + 9] = samples[18*28*8 + 11] = samples[18*28*8 + 13] = samples[18*28*8 + 15] = samples[18*28*8 - 1]; |
| 425 | //fwrite(samples, 1, 18*28*4*cdic->audio_sample_size, temp_adpcm); |
| 426 | break; |
| 427 | case 8: |
| 428 | cdic_decode_xa_stereo8(cdic->xa_last, hdr + 4, samples); |
| 429 | samples[18*28*4 + 0] = samples[18*28*4 + 2] = samples[18*28*4 + 4] = samples[18*28*4 + 6] = samples[18*28*4 + 8] = samples[18*28*4 + 10] = samples[18*28*4 + 12] = samples[18*28*4 + 14] = samples[18*28*4 - 2]; |
| 430 | samples[18*28*4 + 1] = samples[18*28*4 + 3] = samples[18*28*4 + 5] = samples[18*28*4 + 7] = samples[18*28*4 + 9] = samples[18*28*4 + 11] = samples[18*28*4 + 13] = samples[18*28*4 + 15] = samples[18*28*4 - 1]; |
| 431 | break; |
| 432 | } |
| 433 | break; |
| 434 | } |
| 435 | |
| 436 | dmadac_transfer(&state->dmadac[0], 2, 1, 2, 18*28*2*cdic->audio_sample_size, samples); |
| 437 | |
| 438 | //fclose(temp_adpcm); |
| 439 | } |
| 440 | |
| 441 | // After an appropriate delay for decoding to take place... |
| 442 | TIMER_CALLBACK( audio_sample_trigger ) |
| 443 | { |
| 444 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 445 | cdic_regs_t *cdic = &state->cdic_regs; |
| 446 | |
| 447 | if(cdic->decode_addr == 0xffff) |
| 448 | { |
| 449 | verboselog(machine, 0, "Decode stop requested, stopping playback\n" ); |
| 450 | timer_adjust_oneshot(cdic->audio_sample_timer, attotime_never, 0); |
| 451 | return; |
| 452 | } |
| 453 | |
| 454 | if(!cdic->decode_delay) |
| 455 | { |
| 456 | // Indicate that data has been decoded |
| 457 | verboselog(machine, 0, "Flagging that audio data has been decoded\n" ); |
| 458 | cdic->audio_buffer |= 0x8000; |
| 459 | |
| 460 | // Set the CDIC interrupt line |
| 461 | verboselog(machine, 0, "Setting CDIC interrupt line for soundmap decode\n" ); |
| 462 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 463 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | cdic->decode_delay = 0; |
| 468 | } |
| 469 | |
| 470 | if(CDIC_IS_VALID_SAMPLE_BUF(cdic->ram, cdic->decode_addr & 0x3ffe)) |
| 471 | { |
| 472 | verboselog(machine, 0, "Hit audio_sample_trigger, with cdic->decode_addr == %04x, calling cdic_decode_audio_sector\n", cdic->decode_addr ); |
| 473 | |
| 474 | // Decode the data at Z+4, the same offset as a normal CD sector. |
| 475 | cdic_decode_audio_sector(machine, ((UINT8*)cdic->ram) + (cdic->decode_addr & 0x3ffe) + 4, 1); |
| 476 | |
| 477 | // Swap buffer positions to indicate our new buffer position at the next read |
| 478 | cdic->decode_addr ^= 0x1a00; |
| 479 | |
| 480 | verboselog(machine, 0, "Updated cdic->decode_addr, new value is %04x\n", cdic->decode_addr ); |
| 481 | |
| 482 | //// Delay for Frequency * (18*28*2*size in bytes) before requesting more data |
| 483 | verboselog(machine, 0, "Data is valid, setting up a new callback\n" ); |
| 484 | cdic->decode_period = attotime_mul(ATTOTIME_IN_HZ(CDIC_SAMPLE_BUF_FREQ(cdic->ram, cdic->decode_addr & 0x3ffe)), 18*28*2*CDIC_SAMPLE_BUF_SIZE(cdic->ram, cdic->decode_addr & 0x3ffe)); |
| 485 | timer_adjust_oneshot(cdic->audio_sample_timer, cdic->decode_period, 0); |
| 486 | //dmadac_enable(&dmadac[0], 2, 0); |
| 487 | } |
| 488 | else |
| 489 | { |
| 490 | // Swap buffer positions to indicate our new buffer position at the next read |
| 491 | cdic->decode_addr ^= 0x1a00; |
| 492 | |
| 493 | verboselog(machine, 0, "Data is not valid, indicating to shut down on the next audio sample\n" ); |
| 494 | cdic->decode_addr = 0xffff; |
| 495 | timer_adjust_oneshot(cdic->audio_sample_timer, cdic->decode_period, 0); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | static UINT32 increment_cdda_frame_bcd(UINT32 bcd) |
| 500 | { |
| 501 | UINT8 nybbles[6] = |
| 502 | { |
| 503 | bcd & 0x0000000f, |
| 504 | (bcd & 0x000000f0) >> 4, |
| 505 | (bcd & 0x00000f00) >> 8, |
| 506 | (bcd & 0x0000f000) >> 12, |
| 507 | (bcd & 0x000f0000) >> 16, |
| 508 | (bcd & 0x00f00000) >> 20 |
| 509 | }; |
| 510 | nybbles[0]++; |
| 511 | if(nybbles[0] == 5 && nybbles[1] == 7) |
| 512 | { |
| 513 | nybbles[0] = 0; |
| 514 | nybbles[1] = 0; |
| 515 | nybbles[2]++; |
| 516 | } |
| 517 | else if(nybbles[0] == 10) |
| 518 | { |
| 519 | nybbles[1]++; |
| 520 | } |
| 521 | if(nybbles[2] == 10) |
| 522 | { |
| 523 | nybbles[3]++; |
| 524 | nybbles[2] = 0; |
| 525 | } |
| 526 | if(nybbles[3] == 6) |
| 527 | { |
| 528 | nybbles[4]++; |
| 529 | nybbles[3] = 0; |
| 530 | } |
| 531 | if(nybbles[4] == 10) |
| 532 | { |
| 533 | nybbles[5]++; |
| 534 | nybbles[4] = 0; |
| 535 | } |
| 536 | return (nybbles[5] << 20) | (nybbles[4] << 16) | (nybbles[3] << 12) | (nybbles[2] << 8) | (nybbles[1] << 4) | nybbles[0]; |
| 537 | } |
| 538 | |
| 539 | static UINT32 increment_cdda_sector_bcd(UINT32 bcd) |
| 540 | { |
| 541 | UINT8 nybbles[6] = |
| 542 | { |
| 543 | bcd & 0x0000000f, |
| 544 | (bcd & 0x000000f0) >> 4, |
| 545 | (bcd & 0x00000f00) >> 8, |
| 546 | (bcd & 0x0000f000) >> 12, |
| 547 | (bcd & 0x000f0000) >> 16, |
| 548 | (bcd & 0x00f00000) >> 20 |
| 549 | }; |
| 550 | nybbles[2]++; |
| 551 | if(nybbles[2] == 10) |
| 552 | { |
| 553 | nybbles[3]++; |
| 554 | nybbles[2] = 0; |
| 555 | } |
| 556 | if(nybbles[3] == 6) |
| 557 | { |
| 558 | nybbles[4]++; |
| 559 | nybbles[3] = 0; |
| 560 | } |
| 561 | if(nybbles[4] == 10) |
| 562 | { |
| 563 | nybbles[5]++; |
| 564 | nybbles[4] = 0; |
| 565 | } |
| 566 | return (nybbles[5] << 20) | (nybbles[4] << 16) | (nybbles[3] << 12) | (nybbles[2] << 8) | (nybbles[1] << 4) | nybbles[0]; |
| 567 | } |
| 568 | |
| 569 | TIMER_CALLBACK( cdic_trigger_readback_int ) |
| 570 | { |
| 571 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 572 | cdic_regs_t *cdic = &state->cdic_regs; |
| 573 | |
| 574 | switch(cdic->command) |
| 575 | { |
| 576 | case 0x23: // Reset Mode 1 |
| 577 | case 0x24: // Reset Mode 2 |
| 578 | case 0x29: // Read Mode 1 |
| 579 | case 0x2a: // Read Mode 2 |
| 580 | //case 0x2c: // Seek |
| 581 | { |
| 582 | UINT8 buffer[2560] = { 0 }; |
| 583 | UINT32 msf = cdic->time >> 8; |
| 584 | UINT32 lba = 0; |
| 585 | int index = 0; |
| 586 | UINT8 nybbles[6] = |
| 587 | { |
| 588 | msf & 0x0000000f, |
| 589 | (msf & 0x000000f0) >> 4, |
| 590 | (msf & 0x00000f00) >> 8, |
| 591 | (msf & 0x0000f000) >> 12, |
| 592 | (msf & 0x000f0000) >> 16, |
| 593 | (msf & 0x00f00000) >> 20 |
| 594 | }; |
| 595 | if(msf & 0x000080) |
| 596 | { |
| 597 | msf &= 0xffff00; |
| 598 | nybbles[0] = 0; |
| 599 | nybbles[1] = 0; |
| 600 | } |
| 601 | if(nybbles[2] >= 2) |
| 602 | { |
| 603 | nybbles[2] -= 2; |
| 604 | } |
| 605 | else |
| 606 | { |
| 607 | nybbles[2] = 8 + nybbles[2]; |
| 608 | if(nybbles[3] > 0) |
| 609 | { |
| 610 | nybbles[3]--; |
| 611 | } |
| 612 | else |
| 613 | { |
| 614 | nybbles[3] = 5; |
| 615 | if(nybbles[4] > 0) |
| 616 | { |
| 617 | nybbles[4]--; |
| 618 | } |
| 619 | else |
| 620 | { |
| 621 | nybbles[4] = 9; |
| 622 | nybbles[5]--; |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | lba = nybbles[0] + nybbles[1]*10 + ((nybbles[2] + nybbles[3]*10)*75) + ((nybbles[4] + nybbles[5]*10)*75*60); |
| 627 | |
| 628 | //printf( "Reading Mode %d sector from MSF location %06x\n", cdic->command - 0x28, cdic->time | 2 ); |
| 629 | verboselog(machine, 0, "Reading Mode %d sector from MSF location %06x\n", cdic->command - 0x28, cdic->time | 2 ); |
| 630 | |
| 631 | |
| 632 | cdrom_read_data(cdic->cd, lba, buffer, CD_TRACK_RAW_DONTCARE); |
| 633 | |
| 634 | cdic->time += 0x100; |
| 635 | if((cdic->time & 0x00000f00) == 0x00000a00) |
| 636 | { |
| 637 | cdic->time &= 0xfffff0ff; |
| 638 | cdic->time += 0x00001000; |
| 639 | } |
| 640 | if((cdic->time & 0x0000ff00) == 0x00007500) |
| 641 | { |
| 642 | cdic->time &= 0xffff00ff; |
| 643 | cdic->time += 0x00010000; |
| 644 | if((cdic->time & 0x000f0000) == 0x000a0000) |
| 645 | { |
| 646 | cdic->time &= 0xfff0ffff; |
| 647 | cdic->time += 0x00100000; |
| 648 | } |
| 649 | } |
| 650 | if((cdic->time & 0x00ff0000) == 0x00600000) |
| 651 | { |
| 652 | cdic->time &= 0xff00ffff; |
| 653 | cdic->time += 0x01000000; |
| 654 | if((cdic->time & 0x0f000000) == 0x0a000000) |
| 655 | { |
| 656 | cdic->time &= 0xf0ffffff; |
| 657 | cdic->time += 0x10000000; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | cdic->data_buffer &= ~0x0004; |
| 662 | cdic->data_buffer ^= 0x0001; |
| 663 | |
| 664 | //printf( "%02x\n", buffer[CDIC_SECTOR_SUBMODE2] ); |
| 665 | if((buffer[CDIC_SECTOR_FILE2] << 8) == cdic->file) |
| 666 | { |
| 667 | //if((1 << buffer[CDIC_SECTOR_CHAN2])) |
| 668 | { |
| 669 | if(((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_FORM | CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == (CDIC_SUBMODE_FORM | CDIC_SUBMODE_AUDIO)) && |
| 670 | (cdic->channel & cdic->audio_channel & (1 << buffer[CDIC_SECTOR_CHAN2]))) |
| 671 | { |
| 672 | { |
| 673 | verboselog(machine, 0, "Audio sector\n" ); |
| 674 | |
| 675 | cdic->x_buffer |= 0x8000; |
| 676 | //cdic->data_buffer |= 0x4000; |
| 677 | cdic->data_buffer |= 0x0004; |
| 678 | |
| 679 | for(index = 6; index < 2352/2; index++) |
| 680 | { |
| 681 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 682 | } |
| 683 | |
| 684 | cdic_decode_audio_sector(machine, ((UINT8*)cdic->ram) + ((cdic->data_buffer & 5) * 0xa00 + 4), 0); |
| 685 | |
| 686 | //printf( "Setting CDIC interrupt line\n" ); |
| 687 | verboselog(machine, 0, "Setting CDIC interrupt line for audio sector\n" ); |
| 688 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 689 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 690 | } |
| 691 | } |
| 692 | else if((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == 0x00) |
| 693 | { |
| 694 | cdic->x_buffer |= 0x8000; |
| 695 | //cdic->data_buffer |= 0x4000; |
| 696 | |
| 697 | for(index = 6; index < 2352/2; index++) |
| 698 | { |
| 699 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 700 | } |
| 701 | |
| 702 | if((buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_TRIG) == CDIC_SUBMODE_TRIG || |
| 703 | (buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOR) == CDIC_SUBMODE_EOR || |
| 704 | (buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOF) == CDIC_SUBMODE_EOF) |
| 705 | { |
| 706 | //printf( "Setting CDIC interrupt line\n" ); |
| 707 | verboselog(machine, 0, "Setting CDIC interrupt line for message sector\n" ); |
| 708 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 709 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 710 | } |
| 711 | else |
| 712 | { |
| 713 | verboselog(machine, 0, "Message sector, ignored\n" ); |
| 714 | } |
| 715 | } |
| 716 | else /*if(buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_VIDEO))*/ |
| 717 | { |
| 718 | cdic->x_buffer |= 0x8000; |
| 719 | //cdic->data_buffer |= 0x4000; |
| 720 | |
| 721 | for(index = 6; index < 2352/2; index++) |
| 722 | { |
| 723 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 724 | } |
| 725 | |
| 726 | //printf( "Setting CDIC interrupt line\n" ); |
| 727 | verboselog(machine, 0, "Setting CDIC interrupt line for data sector\n" ); |
| 728 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 729 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | if((buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOF) == 0 && cdic->command != 0x23) |
| 734 | { |
| 735 | timer_adjust_oneshot(cdic->interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed |
| 736 | } |
| 737 | else |
| 738 | { |
| 739 | if(cdic->command == 0x23) // Mode 1 Reset |
| 740 | { |
| 741 | timer_adjust_oneshot(cdic->interrupt_timer, attotime_never, 0); |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | break; |
| 747 | } |
| 748 | //case 0x24: // Mode 2 Reset |
| 749 | case 0x2e: // Abort |
| 750 | timer_adjust_oneshot(cdic->interrupt_timer, attotime_never, 0); |
| 751 | //cdic->data_buffer &= ~4; |
| 752 | break; |
| 753 | case 0x28: // Play CDDA audio |
| 754 | { |
| 755 | UINT8 buffer[2560] = { 0 }; |
| 756 | int index = 0; |
| 757 | UINT32 msf = (cdic->time & 0xffff7f00) >> 8; |
| 758 | UINT32 next_msf = increment_cdda_frame_bcd((cdic->time & 0xffff7f00) >> 8); |
| 759 | UINT32 rounded_next_msf = increment_cdda_sector_bcd((cdic->time & 0xffff0000) >> 8); |
| 760 | UINT32 lba = 0; |
| 761 | UINT32 next_lba = 0; |
| 762 | UINT8 nybbles[6] = |
| 763 | { |
| 764 | msf & 0x0000000f, |
| 765 | (msf & 0x000000f0) >> 4, |
| 766 | (msf & 0x00000f00) >> 8, |
| 767 | (msf & 0x0000f000) >> 12, |
| 768 | (msf & 0x000f0000) >> 16, |
| 769 | (msf & 0x00f00000) >> 20 |
| 770 | }; |
| 771 | UINT8 next_nybbles[6] = |
| 772 | { |
| 773 | rounded_next_msf & 0x0000000f, |
| 774 | (rounded_next_msf & 0x000000f0) >> 4, |
| 775 | (rounded_next_msf & 0x00000f00) >> 8, |
| 776 | (rounded_next_msf & 0x0000f000) >> 12, |
| 777 | (rounded_next_msf & 0x000f0000) >> 16, |
| 778 | (rounded_next_msf & 0x00f00000) >> 20 |
| 779 | }; |
| 780 | |
| 781 | lba = nybbles[0] + nybbles[1]*10 + ((nybbles[2] + nybbles[3]*10)*75) + ((nybbles[4] + nybbles[5]*10)*75*60); |
| 782 | |
| 783 | cdrom_read_data(cdic->cd, lba, buffer, CD_TRACK_RAW_DONTCARE); |
| 784 | |
| 785 | if(!(msf & 0x0000ff)) |
| 786 | { |
| 787 | next_lba = next_nybbles[0] + next_nybbles[1]*10 + ((next_nybbles[2] + next_nybbles[3]*10)*75) + ((next_nybbles[4] + next_nybbles[5]*10)*75*60); |
| 788 | |
| 789 | verboselog(machine, 0, "Playing CDDA sector from MSF location %06x\n", cdic->time | 2 ); |
| 790 | |
| 791 | cdda_start_audio(machine->device("cdda"), lba, rounded_next_msf); |
| 792 | |
| 793 | } |
| 794 | |
| 795 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x924/2] = 0x0001; // CTRL |
| 796 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x926/2] = 0x0001; // TRACK |
| 797 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x928/2] = 0x0000; // INDEX |
| 798 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92a/2] = (cdic->time >> 24) & 0x000000ff; // MIN |
| 799 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92c/2] = (cdic->time >> 16) & 0x000000ff; // SEC |
| 800 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92e/2] = (cdic->time >> 8) & 0x0000007f; // FRAC |
| 801 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x930/2] = 0x0000; // ZERO |
| 802 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x932/2] = (cdic->time >> 24) & 0x000000ff; // AMIN |
| 803 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x934/2] = (cdic->time >> 16) & 0x000000ff; // ASEC |
| 804 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x936/2] = (cdic->time >> 8) & 0x0000007f; // AFRAC |
| 805 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x938/2] = 0x0000; // CRC1 |
| 806 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x93a/2] = 0x0000; // CRC2 |
| 807 | |
| 808 | cdic->time = next_msf << 8; |
| 809 | |
| 810 | timer_adjust_oneshot(cdic->interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 811 | |
| 812 | cdic->x_buffer |= 0x8000; |
| 813 | //cdic->data_buffer |= 0x4000; |
| 814 | |
| 815 | for(index = 6; index < 2352/2; index++) |
| 816 | { |
| 817 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 818 | } |
| 819 | |
| 820 | verboselog(machine, 0, "Setting CDIC interrupt line for CDDA sector\n" ); |
| 821 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 822 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 823 | break; |
| 824 | } |
| 825 | case 0x2c: // Seek |
| 826 | { |
| 827 | UINT8 buffer[2560] = { 0 }; |
| 828 | int index = 0; |
| 829 | UINT32 msf = (cdic->time & 0xffff7f00) >> 8; |
| 830 | UINT32 next_msf = increment_cdda_frame_bcd((cdic->time & 0xffff7f00) >> 8); |
| 831 | UINT32 lba = 0; |
| 832 | UINT8 nybbles[6] = |
| 833 | { |
| 834 | msf & 0x0000000f, |
| 835 | (msf & 0x000000f0) >> 4, |
| 836 | (msf & 0x00000f00) >> 8, |
| 837 | (msf & 0x0000f000) >> 12, |
| 838 | (msf & 0x000f0000) >> 16, |
| 839 | (msf & 0x00f00000) >> 20 |
| 840 | }; |
| 841 | lba = nybbles[0] + nybbles[1]*10 + ((nybbles[2] + nybbles[3]*10)*75) + ((nybbles[4] + nybbles[5]*10)*75*60); |
| 842 | |
| 843 | timer_adjust_oneshot(cdic->interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 844 | |
| 845 | cdrom_read_data(cdic->cd, lba, buffer, CD_TRACK_RAW_DONTCARE); |
| 846 | |
| 847 | cdic->data_buffer ^= 0x0001; |
| 848 | cdic->x_buffer |= 0x8000; |
| 849 | cdic->data_buffer |= 0x4000; |
| 850 | |
| 851 | for(index = 6; index < 2352/2; index++) |
| 852 | { |
| 853 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 854 | } |
| 855 | |
| 856 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x924/2] = 0x0041; // CTRL |
| 857 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x926/2] = 0x0001; // TRACK |
| 858 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x928/2] = 0x0000; // INDEX |
| 859 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92a/2] = (cdic->time >> 24) & 0x000000ff; // MIN |
| 860 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92c/2] = (cdic->time >> 16) & 0x000000ff; // SEC |
| 861 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92e/2] = (cdic->time >> 8) & 0x0000007f; // FRAC |
| 862 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x930/2] = 0x0000; // ZERO |
| 863 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x932/2] = (cdic->time >> 24) & 0x000000ff; // AMIN |
| 864 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x934/2] = (cdic->time >> 16) & 0x000000ff; // ASEC |
| 865 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x936/2] = (cdic->time >> 8) & 0x0000007f; // AFRAC |
| 866 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x938/2] = 0x0000; // CRC1 |
| 867 | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x93a/2] = 0x0000; // CRC2 |
| 868 | |
| 869 | cdic->time = next_msf << 8; |
| 870 | |
| 871 | verboselog(machine, 0, "Setting CDIC interrupt line for Seek sector\n" ); |
| 872 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 873 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 874 | break; |
| 875 | } |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | READ16_HANDLER( cdic_r ) |
| 880 | { |
| 881 | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 882 | cdic_regs_t *cdic = &state->cdic_regs; |
| 883 | |
| 884 | offset += 0x3c00/2; |
| 885 | switch(offset) |
| 886 | { |
| 887 | case 0x3c00/2: // Command register |
| 888 | verboselog(space->machine, 0, "cdic_r: Command Register = %04x & %04x\n", cdic->command, mem_mask); |
| 889 | return cdic->command; |
| 890 | |
| 891 | case 0x3c02/2: // Time register (MSW) |
| 892 | verboselog(space->machine, 0, "cdic_r: Time Register (MSW) = %04x & %04x\n", cdic->time >> 16, mem_mask); |
| 893 | return cdic->time >> 16; |
| 894 | |
| 895 | case 0x3c04/2: // Time register (LSW) |
| 896 | verboselog(space->machine, 0, "cdic_r: Time Register (LSW) = %04x & %04x\n", (UINT16)(cdic->time & 0x0000ffff), mem_mask); |
| 897 | return cdic->time & 0x0000ffff; |
| 898 | |
| 899 | case 0x3c06/2: // File register |
| 900 | verboselog(space->machine, 0, "cdic_r: File Register = %04x & %04x\n", cdic->file, mem_mask); |
| 901 | return cdic->file; |
| 902 | |
| 903 | case 0x3c08/2: // Channel register (MSW) |
| 904 | verboselog(space->machine, 0, "cdic_r: Channel Register (MSW) = %04x & %04x\n", cdic->channel >> 16, mem_mask); |
| 905 | return cdic->channel >> 16; |
| 906 | |
| 907 | case 0x3c0a/2: // Channel register (LSW) |
| 908 | verboselog(space->machine, 0, "cdic_r: Channel Register (LSW) = %04x & %04x\n", cdic->channel & 0x0000ffff, mem_mask); |
| 909 | return cdic->channel & 0x0000ffff; |
| 910 | |
| 911 | case 0x3c0c/2: // Audio Channel register |
| 912 | verboselog(space->machine, 0, "cdic_r: Audio Channel Register = %04x & %04x\n", cdic->audio_channel, mem_mask); |
| 913 | return cdic->audio_channel; |
| 914 | |
| 915 | case 0x3ff4/2: // ABUF |
| 916 | { |
| 917 | UINT16 temp = cdic->audio_buffer; |
| 918 | cdic->audio_buffer &= 0x7fff; |
| 919 | if(!((cdic->audio_buffer | cdic->x_buffer) & 0x8000)) |
| 920 | { |
| 921 | cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE); |
| 922 | verboselog(space->machine, 0, "Clearing CDIC interrupt line\n" ); |
| 923 | //printf("Clearing CDIC interrupt line\n" ); |
| 924 | } |
| 925 | verboselog(space->machine, 0, "cdic_r: Audio Buffer Register = %04x & %04x\n", temp, mem_mask); |
| 926 | return temp; |
| 927 | } |
| 928 | |
| 929 | case 0x3ff6/2: // XBUF |
| 930 | { |
| 931 | UINT16 temp = cdic->x_buffer; |
| 932 | cdic->x_buffer &= 0x7fff; |
| 933 | if(!((cdic->audio_buffer | cdic->x_buffer) & 0x8000)) |
| 934 | { |
| 935 | cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE); |
| 936 | verboselog(space->machine, 0, "Clearing CDIC interrupt line\n" ); |
| 937 | //printf("Clearing CDIC interrupt line\n" ); |
| 938 | } |
| 939 | verboselog(space->machine, 0, "cdic_r: X-Buffer Register = %04x & %04x\n", temp, mem_mask); |
| 940 | return temp; |
| 941 | } |
| 942 | |
| 943 | case 0x3ffa/2: // AUDCTL |
| 944 | { |
| 945 | if(attotime_is_never(timer_timeleft(cdic->audio_sample_timer))) |
| 946 | { |
| 947 | cdic->z_buffer ^= 0x0001; |
| 948 | } |
| 949 | verboselog(space->machine, 0, "cdic_r: Z-Buffer Register = %04x & %04x\n", cdic->z_buffer, mem_mask); |
| 950 | return cdic->z_buffer; |
| 951 | } |
| 952 | |
| 953 | case 0x3ffe/2: |
| 954 | { |
| 955 | verboselog(space->machine, 0, "cdic_r: Data buffer Register = %04x & %04x\n", cdic->data_buffer, mem_mask); |
| 956 | return cdic->data_buffer; |
| 957 | } |
| 958 | default: |
| 959 | verboselog(space->machine, 0, "cdic_r: UNIMPLEMENTED: Unknown address: %04x & %04x\n", offset*2, mem_mask); |
| 960 | return 0; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | WRITE16_HANDLER( cdic_w ) |
| 965 | { |
| 966 | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 967 | cdic_regs_t *cdic = &state->cdic_regs; |
| 968 | |
| 969 | offset += 0x3c00/2; |
| 970 | switch(offset) |
| 971 | { |
| 972 | case 0x3c00/2: // Command register |
| 973 | verboselog(space->machine, 0, "cdic_w: Command Register = %04x & %04x\n", data, mem_mask); |
| 974 | COMBINE_DATA(&cdic->command); |
| 975 | //printf( "cdic command: %04x\n", cdic->command ); |
| 976 | break; |
| 977 | |
| 978 | case 0x3c02/2: // Time register (MSW) |
| 979 | cdic->time &= ~(mem_mask << 16); |
| 980 | cdic->time |= (data & mem_mask) << 16; |
| 981 | verboselog(space->machine, 0, "cdic_w: Time Register (MSW) = %04x & %04x\n", data, mem_mask); |
| 982 | break; |
| 983 | |
| 984 | case 0x3c04/2: // Time register (LSW) |
| 985 | cdic->time &= ~mem_mask; |
| 986 | cdic->time |= data & mem_mask; |
| 987 | verboselog(space->machine, 0, "cdic_w: Time Register (LSW) = %04x & %04x\n", data, mem_mask); |
| 988 | break; |
| 989 | |
| 990 | case 0x3c06/2: // File register |
| 991 | verboselog(space->machine, 0, "cdic_w: File Register = %04x & %04x\n", data, mem_mask); |
| 992 | COMBINE_DATA(&cdic->file); |
| 993 | break; |
| 994 | |
| 995 | case 0x3c08/2: // Channel register (MSW) |
| 996 | cdic->channel &= ~(mem_mask << 16); |
| 997 | cdic->channel |= (data & mem_mask) << 16; |
| 998 | verboselog(space->machine, 0, "cdic_w: Channel Register (MSW) = %04x & %04x\n", data, mem_mask); |
| 999 | break; |
| 1000 | |
| 1001 | case 0x3c0a/2: // Channel register (LSW) |
| 1002 | cdic->channel &= ~mem_mask; |
| 1003 | cdic->channel |= data & mem_mask; |
| 1004 | verboselog(space->machine, 0, "cdic_w: Channel Register (LSW) = %04x & %04x\n", data, mem_mask); |
| 1005 | break; |
| 1006 | |
| 1007 | case 0x3c0c/2: // Audio Channel register |
| 1008 | verboselog(space->machine, 0, "cdic_w: Audio Channel Register = %04x & %04x\n", data, mem_mask); |
| 1009 | COMBINE_DATA(&cdic->audio_channel); |
| 1010 | break; |
| 1011 | |
| 1012 | case 0x3ff4/2: |
| 1013 | verboselog(space->machine, 0, "cdic_w: Audio Buffer Register = %04x & %04x\n", data, mem_mask); |
| 1014 | COMBINE_DATA(&cdic->audio_buffer); |
| 1015 | break; |
| 1016 | |
| 1017 | case 0x3ff6/2: |
| 1018 | verboselog(space->machine, 0, "cdic_w: X Buffer Register = %04x & %04x\n", data, mem_mask); |
| 1019 | COMBINE_DATA(&cdic->x_buffer); |
| 1020 | break; |
| 1021 | |
| 1022 | case 0x3ff8/2: |
| 1023 | { |
| 1024 | scc68070_regs_t *scc68070 = &state->scc68070_regs; |
| 1025 | UINT32 start = scc68070->dma.channel[0].memory_address_counter; |
| 1026 | UINT32 count = scc68070->dma.channel[0].transfer_counter; |
| 1027 | UINT32 index = 0; |
| 1028 | UINT32 device_index = (data & 0x3fff) >> 1; |
| 1029 | UINT16 *memory = state->planea; |
| 1030 | verboselog(space->machine, 0, "memory address counter: %08x\n", scc68070->dma.channel[0].memory_address_counter); |
| 1031 | verboselog(space->machine, 0, "cdic_w: DMA Control Register = %04x & %04x\n", data, mem_mask); |
| 1032 | verboselog(space->machine, 0, "Doing copy, transferring %04x bytes\n", count * 2 ); |
| 1033 | //printf("Doing copy, transferring %04x bytes\n", count * 2 ); |
| 1034 | if((start & 0x00f00000) == 0x00200000) |
| 1035 | { |
| 1036 | start -= 0x00200000; |
| 1037 | memory = state->planeb; |
| 1038 | } |
| 1039 | for(index = start / 2; index < (start / 2 + count); index++) |
| 1040 | { |
| 1041 | if(scc68070->dma.channel[0].operation_control & OCR_D) |
| 1042 | { |
| 1043 | memory[index] = cdic->ram[device_index++]; |
| 1044 | } |
| 1045 | else |
| 1046 | { |
| 1047 | cdic->ram[device_index++] = memory[index]; |
| 1048 | } |
| 1049 | } |
| 1050 | scc68070->dma.channel[0].memory_address_counter += scc68070->dma.channel[0].transfer_counter * 2; |
| 1051 | break; |
| 1052 | } |
| 1053 | |
| 1054 | case 0x3ffa/2: |
| 1055 | { |
| 1056 | verboselog(space->machine, 0, "cdic_w: Z-Buffer Register = %04x & %04x\n", data, mem_mask); |
| 1057 | COMBINE_DATA(&cdic->z_buffer); |
| 1058 | if(cdic->z_buffer & 0x2000) |
| 1059 | { |
| 1060 | attotime period = timer_timeleft(cdic->audio_sample_timer); |
| 1061 | if(attotime_is_never(period)) |
| 1062 | { |
| 1063 | cdic->decode_addr = cdic->z_buffer & 0x3a00; |
| 1064 | cdic->decode_delay = 1; |
| 1065 | timer_adjust_oneshot(cdic->audio_sample_timer, ATTOTIME_IN_HZ(75), 0); |
| 1066 | } |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 1070 | cdic->decode_addr = 0xffff; |
| 1071 | timer_adjust_oneshot(cdic->audio_sample_timer, attotime_never, 0); |
| 1072 | } |
| 1073 | break; |
| 1074 | } |
| 1075 | case 0x3ffc/2: |
| 1076 | verboselog(space->machine, 0, "cdic_w: Interrupt Vector Register = %04x & %04x\n", data, mem_mask); |
| 1077 | COMBINE_DATA(&cdic->interrupt_vector); |
| 1078 | break; |
| 1079 | case 0x3ffe/2: |
| 1080 | { |
| 1081 | verboselog(space->machine, 0, "cdic_w: Data Buffer Register = %04x & %04x\n", data, mem_mask); |
| 1082 | COMBINE_DATA(&cdic->data_buffer); |
| 1083 | if(cdic->data_buffer & 0x8000) |
| 1084 | { |
| 1085 | switch(cdic->command) |
| 1086 | { |
| 1087 | //case 0x24: // Reset Mode 2 |
| 1088 | case 0x2e: // Abort |
| 1089 | { |
| 1090 | timer_adjust_oneshot(cdic->interrupt_timer, attotime_never, 0); |
| 1091 | dmadac_enable(&state->dmadac[0], 2, 0); |
| 1092 | //cdic->data_buffer &= 0xbfff; |
| 1093 | break; |
| 1094 | } |
| 1095 | case 0x2b: // Stop CDDA |
| 1096 | cdda_stop_audio(space->machine->device("cdda")); |
| 1097 | timer_adjust_oneshot(cdic->interrupt_timer, attotime_never, 0); |
| 1098 | break; |
| 1099 | case 0x23: // Reset Mode 1 |
| 1100 | case 0x29: // Read Mode 1 |
| 1101 | case 0x2a: // Read Mode 2 |
| 1102 | case 0x28: // Play CDDA |
| 1103 | case 0x2c: // Seek |
| 1104 | { |
| 1105 | attotime period = timer_timeleft(cdic->interrupt_timer); |
| 1106 | if(!attotime_is_never(period)) |
| 1107 | { |
| 1108 | timer_adjust_oneshot(cdic->interrupt_timer, period, 0); |
| 1109 | } |
| 1110 | else |
| 1111 | { |
| 1112 | if(cdic->command != 0x23 && cdic->command != 0x24) |
| 1113 | { |
| 1114 | timer_adjust_oneshot(cdic->interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 1115 | } |
| 1116 | } |
| 1117 | break; |
| 1118 | } |
| 1119 | default: |
| 1120 | verboselog(space->machine, 0, "Unknown CDIC command: %02x\n", cdic->command ); |
| 1121 | break; |
| 1122 | } |
| 1123 | } |
| 1124 | cdic->data_buffer &= 0x7fff; |
| 1125 | break; |
| 1126 | } |
| 1127 | default: |
| 1128 | verboselog(space->machine, 0, "cdic_w: UNIMPLEMENTED: Unknown address: %04x = %04x & %04x\n", offset*2, data, mem_mask); |
| 1129 | break; |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | void cdic_init(running_machine *machine, cdic_regs_t *cdic) |
| 1134 | { |
| 1135 | cdic->command = 0; |
| 1136 | cdic->time = 0; |
| 1137 | cdic->file = 0; |
| 1138 | cdic->channel = 0xffffffff; |
| 1139 | cdic->audio_channel = 0xffff; |
| 1140 | cdic->audio_buffer = 0; |
| 1141 | cdic->x_buffer = 0; |
| 1142 | cdic->dma_control = 0; |
| 1143 | cdic->z_buffer = 0; |
| 1144 | cdic->interrupt_vector = 0; |
| 1145 | cdic->data_buffer = 0; |
| 1146 | |
| 1147 | cdic->audio_sample_freq = 0; |
| 1148 | cdic->audio_sample_size = 0; |
| 1149 | |
| 1150 | cdic->decode_addr = 0; |
| 1151 | cdic->decode_delay = 0; |
| 1152 | } |
| 1153 | |
| 1154 | void cdic_register_globals(running_machine *machine, cdic_regs_t *cdic) |
| 1155 | { |
| 1156 | state_save_register_global(machine, cdic->command); |
| 1157 | state_save_register_global(machine, cdic->time); |
| 1158 | state_save_register_global(machine, cdic->file); |
| 1159 | state_save_register_global(machine, cdic->channel); |
| 1160 | state_save_register_global(machine, cdic->audio_channel); |
| 1161 | state_save_register_global(machine, cdic->audio_buffer); |
| 1162 | state_save_register_global(machine, cdic->x_buffer); |
| 1163 | state_save_register_global(machine, cdic->dma_control); |
| 1164 | state_save_register_global(machine, cdic->z_buffer); |
| 1165 | state_save_register_global(machine, cdic->interrupt_vector); |
| 1166 | state_save_register_global(machine, cdic->data_buffer); |
| 1167 | |
| 1168 | state_save_register_global(machine, cdic->audio_sample_freq); |
| 1169 | state_save_register_global(machine, cdic->audio_sample_size); |
| 1170 | } |
src/mess/video/mcd212.c
| r0 | r8790 | |
| 1 | /****************************************************************************** |
| 2 | |
| 3 | |
| 4 | CD-i MCD212 video emulation |
| 5 | ------------------- |
| 6 | |
| 7 | MESS implementation by Harmony |
| 8 | |
| 9 | |
| 10 | ******************************************************************************* |
| 11 | |
| 12 | STATUS: |
| 13 | |
| 14 | - Just enough for the Mono-I CD-i board to work somewhat properly. |
| 15 | |
| 16 | TODO: |
| 17 | |
| 18 | - Unknown yet. |
| 19 | |
| 20 | *******************************************************************************/ |
| 21 | |
| 22 | #include "emu.h" |
| 23 | #include "cpu/m68000/m68000.h" |
| 24 | #include "video/mcd212.h" |
| 25 | #include "includes/cdi.h" |
| 26 | |
| 27 | #if ENABLE_VERBOSE_LOG |
| 28 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| 29 | { |
| 30 | if( VERBOSE_LEVEL >= n_level ) |
| 31 | { |
| 32 | va_list v; |
| 33 | char buf[ 32768 ]; |
| 34 | va_start( v, s_fmt ); |
| 35 | vsprintf( buf, s_fmt, v ); |
| 36 | va_end( v ); |
| 37 | logerror( "%08x: %s", cpu_get_pc(machine->device("maincpu")), buf ); |
| 38 | } |
| 39 | } |
| 40 | #else |
| 41 | #define verboselog(x,y,z,...) |
| 42 | #endif |
| 43 | |
| 44 | static void cdi220_draw_lcd(running_machine *machine, int y); |
| 45 | static void mcd212_update_region_arrays(mcd212_regs_t *mcd212); |
| 46 | static void mcd212_set_display_parameters(mcd212_regs_t *mcd212, int channel, UINT8 value); |
| 47 | static void mcd212_update_visible_area(running_machine *machine); |
| 48 | static void mcd212_set_vsr(mcd212_regs_t *mcd212, int channel, UINT32 value); |
| 49 | static void mcd212_set_dcp(mcd212_regs_t *mcd212, int channel, UINT32 value); |
| 50 | static UINT32 mcd212_get_vsr(mcd212_regs_t *mcd212, int channel); |
| 51 | static UINT32 mcd212_get_dcp(mcd212_regs_t *mcd212, int channel); |
| 52 | static UINT32 mcd212_get_screen_width(mcd212_regs_t *mcd212); |
| 53 | static void mcd212_set_register(running_machine *machine, int channel, UINT8 reg, UINT32 value); |
| 54 | static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel); |
| 55 | static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel); |
| 56 | static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b); |
| 57 | static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *plane_a_g, UINT8 *plane_a_b, UINT8 *plane_b_r, UINT8 *plane_b_g, UINT8 *plane_b_b, UINT32 *out); |
| 58 | static void mcd212_draw_cursor(mcd212_regs_t *mcd212, UINT32 *scanline, int y); |
| 59 | static void mcd212_draw_scanline(mcd212_regs_t *mcd212, int y); |
| 60 | |
| 61 | static const UINT16 cdi220_lcd_char[20*22] = |
| 62 | { |
| 63 | 0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200, |
| 64 | 0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200, |
| 65 | 0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200, |
| 66 | 0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200, |
| 67 | 0x2000, 0x2000, 0x2000, 0x2000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0200, 0x0200, 0x0200, 0x0200, |
| 68 | 0x2000, 0x2000, 0x2000, 0x2000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0002, 0x0002, 0x0002, 0x0200, 0x0200, 0x0200, 0x0200, |
| 69 | 0x2000, 0x2000, 0x2000, 0x2000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0002, 0x0002, 0x0200, 0x0200, 0x0200, 0x0200, |
| 70 | 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, 0x8000, 0x8000, 0x8000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0002, 0x0000, 0x0200, 0x0200, 0x0200, 0x0200, |
| 71 | 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, 0x0000, 0x8000, 0x8000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0000, 0x0000, 0x0200, 0x0200, 0x0200, 0x0200, |
| 72 | 0x2000, 0x2000, 0x2000, 0x2000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x0200, 0x0200, 0x0200, 0x0200, |
| 73 | 0x2000, 0x2000, 0x2000, 0x2000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x0200, 0x0200, 0x0200, 0x0200, |
| 74 | 0x1000, 0x1000, 0x1000, 0x1000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x0400, 0x0400, 0x0400, 0x0400, |
| 75 | 0x1000, 0x1000, 0x1000, 0x1000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x0400, 0x0400, 0x0400, 0x0400, |
| 76 | 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, 0x0010, 0x0010, 0x0001, 0x0001, 0x0001, 0x0001, 0x0008, 0x0008, 0x0000, 0x0000, 0x0400, 0x0400, 0x0400, 0x0400, |
| 77 | 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0010, 0x0010, 0x0010, 0x0001, 0x0001, 0x0001, 0x0001, 0x0008, 0x0008, 0x0008, 0x0000, 0x0400, 0x0400, 0x0400, 0x0400, |
| 78 | 0x1000, 0x1000, 0x1000, 0x1000, 0x0010, 0x0010, 0x0010, 0x0010, 0x0001, 0x0001, 0x0001, 0x0001, 0x0008, 0x0008, 0x0008, 0x0008, 0x0400, 0x0400, 0x0400, 0x0400, |
| 79 | 0x1000, 0x1000, 0x1000, 0x1000, 0x0010, 0x0010, 0x0010, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0008, 0x0008, 0x0008, 0x0400, 0x0400, 0x0400, 0x0400, |
| 80 | 0x1000, 0x1000, 0x1000, 0x1000, 0x0010, 0x0010, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0008, 0x0008, 0x0400, 0x0400, 0x0400, 0x0400, |
| 81 | 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400, |
| 82 | 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400, |
| 83 | 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400, |
| 84 | 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400 |
| 85 | }; |
| 86 | |
| 87 | static void cdi220_draw_lcd(running_machine *machine, int y) |
| 88 | { |
| 89 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 90 | bitmap_t *bitmap = state->lcdbitmap; |
| 91 | UINT32 *scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 92 | int x = 0; |
| 93 | int lcd = 0; |
| 94 | |
| 95 | for(lcd = 0; lcd < 8; lcd++) |
| 96 | { |
| 97 | UINT16 data = (state->slave_regs.lcd_state[lcd*2] << 8) | state->slave_regs.lcd_state[lcd*2 + 1]; |
| 98 | for(x = 0; x < 20; x++) |
| 99 | { |
| 100 | if(data & cdi220_lcd_char[y*20 + x]) |
| 101 | { |
| 102 | scanline[(7 - lcd)*24 + x] = 0x00ffffff; |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | scanline[(7 - lcd)*24 + x] = 0; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | static void mcd212_update_region_arrays(mcd212_regs_t *mcd212) |
| 113 | { |
| 114 | int x = 0; |
| 115 | int latched_rf0 = 0; |
| 116 | int latched_rf1 = 0; |
| 117 | int latched_wfa = mcd212->channel[0].weight_factor_a[0]; |
| 118 | int latched_wfb = mcd212->channel[1].weight_factor_b[0]; |
| 119 | int reg = 0; |
| 120 | |
| 121 | for(x = 0; x < 768; x++) |
| 122 | { |
| 123 | if(mcd212->channel[0].image_coding_method & MCD212_ICM_NR) |
| 124 | { |
| 125 | int reg_ = 0; |
| 126 | int flag = 0; |
| 127 | |
| 128 | for(flag = 0; flag < 2; flag++) |
| 129 | { |
| 130 | for(reg_ = 0; reg_ < 4; reg_++) |
| 131 | { |
| 132 | if(mcd212->channel[0].region_control[reg_] == 0) |
| 133 | { |
| 134 | break; |
| 135 | } |
| 136 | if(x == (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_X)) |
| 137 | { |
| 138 | switch((mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT) |
| 139 | { |
| 140 | case 0: // End of region control for line |
| 141 | break; |
| 142 | case 1: |
| 143 | case 2: |
| 144 | case 3: // Not used |
| 145 | break; |
| 146 | case 4: // Change weight of plane A |
| 147 | latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 148 | break; |
| 149 | case 5: // Not used |
| 150 | break; |
| 151 | case 6: // Change weight of plane B |
| 152 | latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 153 | break; |
| 154 | case 7: // Not used |
| 155 | break; |
| 156 | case 8: // Reset region flag |
| 157 | if(flag) |
| 158 | { |
| 159 | latched_rf1 = 0; |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | latched_rf0 = 0; |
| 164 | } |
| 165 | break; |
| 166 | case 9: // Set region flag |
| 167 | if(flag) |
| 168 | { |
| 169 | latched_rf1 = 1; |
| 170 | } |
| 171 | else |
| 172 | { |
| 173 | latched_rf0 = 1; |
| 174 | } |
| 175 | break; |
| 176 | case 10: // Not used |
| 177 | case 11: // Not used |
| 178 | break; |
| 179 | case 12: // Reset region flag and change weight of plane A |
| 180 | latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 181 | if(flag) |
| 182 | { |
| 183 | latched_rf1 = 0; |
| 184 | } |
| 185 | else |
| 186 | { |
| 187 | latched_rf0 = 0; |
| 188 | } |
| 189 | break; |
| 190 | case 13: // Set region flag and change weight of plane A |
| 191 | latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 192 | if(flag) |
| 193 | { |
| 194 | latched_rf1 = 1; |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | latched_rf0 = 1; |
| 199 | } |
| 200 | break; |
| 201 | case 14: // Reset region flag and change weight of plane B |
| 202 | latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 203 | if(flag) |
| 204 | { |
| 205 | latched_rf1 = 0; |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | latched_rf0 = 0; |
| 210 | } |
| 211 | break; |
| 212 | case 15: // Set region flag and change weight of plane B |
| 213 | latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 214 | if(flag) |
| 215 | { |
| 216 | latched_rf1 = 1; |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | latched_rf0 = 1; |
| 221 | } |
| 222 | break; |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | else |
| 229 | { |
| 230 | if(reg < 8) |
| 231 | { |
| 232 | int flag = (mcd212->channel[0].region_control[reg] & MCD212_RC_RF) >> MCD212_RC_RF_SHIFT; |
| 233 | if(!(mcd212->channel[0].region_control[reg] & MCD212_RC_OP)) |
| 234 | { |
| 235 | for(; x < 768; x++) |
| 236 | { |
| 237 | mcd212->channel[0].weight_factor_a[x] = latched_wfa; |
| 238 | mcd212->channel[1].weight_factor_b[x] = latched_wfb; |
| 239 | mcd212->region_flag_0[x] = latched_rf0; |
| 240 | mcd212->region_flag_1[x] = latched_rf1; |
| 241 | } |
| 242 | break; |
| 243 | } |
| 244 | if(x == (mcd212->channel[0].region_control[reg] & MCD212_RC_X)) |
| 245 | { |
| 246 | switch((mcd212->channel[0].region_control[reg] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT) |
| 247 | { |
| 248 | case 0: // End of region control for line |
| 249 | break; |
| 250 | case 1: |
| 251 | case 2: |
| 252 | case 3: // Not used |
| 253 | break; |
| 254 | case 4: // Change weight of plane A |
| 255 | latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 256 | break; |
| 257 | case 5: // Not used |
| 258 | break; |
| 259 | case 6: // Change weight of plane B |
| 260 | latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 261 | break; |
| 262 | case 7: // Not used |
| 263 | break; |
| 264 | case 8: // Reset region flag |
| 265 | if(flag) |
| 266 | { |
| 267 | latched_rf1 = 0; |
| 268 | } |
| 269 | else |
| 270 | { |
| 271 | latched_rf0 = 0; |
| 272 | } |
| 273 | break; |
| 274 | case 9: // Set region flag |
| 275 | if(flag) |
| 276 | { |
| 277 | latched_rf1 = 1; |
| 278 | } |
| 279 | else |
| 280 | { |
| 281 | latched_rf0 = 1; |
| 282 | } |
| 283 | break; |
| 284 | case 10: // Not used |
| 285 | case 11: // Not used |
| 286 | break; |
| 287 | case 12: // Reset region flag and change weight of plane A |
| 288 | latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 289 | if(flag) |
| 290 | { |
| 291 | latched_rf1 = 0; |
| 292 | } |
| 293 | else |
| 294 | { |
| 295 | latched_rf0 = 0; |
| 296 | } |
| 297 | break; |
| 298 | case 13: // Set region flag and change weight of plane A |
| 299 | latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 300 | if(flag) |
| 301 | { |
| 302 | latched_rf1 = 1; |
| 303 | } |
| 304 | else |
| 305 | { |
| 306 | latched_rf0 = 1; |
| 307 | } |
| 308 | break; |
| 309 | case 14: // Reset region flag and change weight of plane B |
| 310 | latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 311 | if(flag) |
| 312 | { |
| 313 | latched_rf1 = 0; |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | latched_rf0 = 0; |
| 318 | } |
| 319 | break; |
| 320 | case 15: // Set region flag and change weight of plane B |
| 321 | latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 322 | if(flag) |
| 323 | { |
| 324 | latched_rf1 = 1; |
| 325 | } |
| 326 | else |
| 327 | { |
| 328 | latched_rf0 = 1; |
| 329 | } |
| 330 | break; |
| 331 | } |
| 332 | reg++; |
| 333 | } |
| 334 | } |
| 335 | } |
| 336 | mcd212->channel[0].weight_factor_a[x] = latched_wfa; |
| 337 | mcd212->channel[1].weight_factor_b[x] = latched_wfb; |
| 338 | mcd212->region_flag_0[x] = latched_rf0; |
| 339 | mcd212->region_flag_1[x] = latched_rf1; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | static void mcd212_set_vsr(mcd212_regs_t *mcd212, int channel, UINT32 value) |
| 344 | { |
| 345 | mcd212->channel[channel].vsr = value & 0x0000ffff; |
| 346 | mcd212->channel[channel].dcr &= 0xffc0; |
| 347 | mcd212->channel[channel].dcr |= (value >> 16) & 0x003f; |
| 348 | } |
| 349 | |
| 350 | static void mcd212_set_register(running_machine *machine, int channel, UINT8 reg, UINT32 value) |
| 351 | { |
| 352 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 353 | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 354 | |
| 355 | switch(reg) |
| 356 | { |
| 357 | case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: // CLUT 0 - 63 |
| 358 | case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f: |
| 359 | case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: |
| 360 | case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f: |
| 361 | case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: |
| 362 | case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: |
| 363 | case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: |
| 364 | case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: |
| 365 | verboselog(machine, 11, " %04xxxxx: %d: CLUT[%d] = %08x\n", channel * 0x20, channel, mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80), value ); |
| 366 | mcd212->channel[0].clut_r[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 16) & 0xfc; |
| 367 | mcd212->channel[0].clut_g[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 8) & 0xfc; |
| 368 | mcd212->channel[0].clut_b[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 0) & 0xfc; |
| 369 | break; |
| 370 | case 0xc0: // Image Coding Method |
| 371 | if(channel == 0) |
| 372 | { |
| 373 | verboselog(machine, 6, " %04xxxxx: %d: Image Coding Method = %08x\n", channel * 0x20, channel, value ); |
| 374 | mcd212->channel[channel].image_coding_method = value; |
| 375 | } |
| 376 | break; |
| 377 | case 0xc1: // Transparency Control |
| 378 | if(channel == 0) |
| 379 | { |
| 380 | verboselog(machine, 6, " %04xxxxx: %d: Transparency Control = %08x\n", channel * 0x20, channel, value ); |
| 381 | mcd212->channel[channel].transparency_control = value; |
| 382 | } |
| 383 | break; |
| 384 | case 0xc2: // Plane Order |
| 385 | if(channel == 0) |
| 386 | { |
| 387 | verboselog(machine, 6, " %04xxxxx: %d: Plane Order = %08x\n", channel * 0x20, channel, value & 7); |
| 388 | mcd212->channel[channel].plane_order = value & 0x00000007; |
| 389 | } |
| 390 | break; |
| 391 | case 0xc3: // CLUT Bank Register |
| 392 | verboselog(machine, 6, " %04xxxxx: %d: CLUT Bank Register = %08x\n", channel * 0x20, channel, value & 3); |
| 393 | mcd212->channel[channel].clut_bank = channel ? (2 | (value & 0x00000001)) : (value & 0x00000003); |
| 394 | break; |
| 395 | case 0xc4: // Transparent Color A |
| 396 | if(channel == 0) |
| 397 | { |
| 398 | verboselog(machine, 6, " %04xxxxx: %d: Transparent Color A = %08x\n", channel * 0x20, channel, value ); |
| 399 | mcd212->channel[channel].transparent_color_a = value & 0xfcfcfc; |
| 400 | } |
| 401 | break; |
| 402 | case 0xc6: // Transparent Color B |
| 403 | if(channel == 1) |
| 404 | { |
| 405 | verboselog(machine, 6, " %04xxxxx: %d: Transparent Color B = %08x\n", channel * 0x20, channel, value ); |
| 406 | mcd212->channel[channel].transparent_color_b = value & 0xfcfcfc; |
| 407 | } |
| 408 | break; |
| 409 | case 0xc7: // Mask Color A |
| 410 | if(channel == 0) |
| 411 | { |
| 412 | verboselog(machine, 6, " %04xxxxx: %d: Mask Color A = %08x\n", channel * 0x20, channel, value ); |
| 413 | mcd212->channel[channel].mask_color_a = value & 0xfcfcfc; |
| 414 | } |
| 415 | break; |
| 416 | case 0xc9: // Mask Color B |
| 417 | if(channel == 1) |
| 418 | { |
| 419 | verboselog(machine, 6, " %04xxxxx: %d: Mask Color B = %08x\n", channel * 0x20, channel, value ); |
| 420 | mcd212->channel[channel].mask_color_b = value & 0xfcfcfc; |
| 421 | } |
| 422 | break; |
| 423 | case 0xca: // Delta YUV Absolute Start Value A |
| 424 | if(channel == 0) |
| 425 | { |
| 426 | verboselog(machine, 6, " %04xxxxx: %d: Delta YUV Absolute Start Value A = %08x\n", channel * 0x20, channel, value ); |
| 427 | mcd212->channel[channel].dyuv_abs_start_a = value; |
| 428 | } |
| 429 | break; |
| 430 | case 0xcb: // Delta YUV Absolute Start Value B |
| 431 | if(channel == 1) |
| 432 | { |
| 433 | verboselog(machine, 6, " %04xxxxx: %d: Delta YUV Absolute Start Value B = %08x\n", channel * 0x20, channel, value ); |
| 434 | mcd212->channel[channel].dyuv_abs_start_b = value; |
| 435 | } |
| 436 | break; |
| 437 | case 0xcd: // Cursor Position |
| 438 | if(channel == 0) |
| 439 | { |
| 440 | verboselog(machine, 6, " %04xxxxx: %d: Cursor Position = %08x\n", channel * 0x20, channel, value ); |
| 441 | mcd212->channel[channel].cursor_position = value; |
| 442 | } |
| 443 | break; |
| 444 | case 0xce: // Cursor Control |
| 445 | if(channel == 0) |
| 446 | { |
| 447 | verboselog(machine, 11, " %04xxxxx: %d: Cursor Control = %08x\n", channel * 0x20, channel, value ); |
| 448 | mcd212->channel[channel].cursor_control = value; |
| 449 | } |
| 450 | break; |
| 451 | case 0xcf: // Cursor Pattern |
| 452 | if(channel == 0) |
| 453 | { |
| 454 | verboselog(machine, 11, " %04xxxxx: %d: Cursor Pattern[%d] = %04x\n", channel * 0x20, channel, (value >> 16) & 0x000f, value & 0x0000ffff); |
| 455 | mcd212->channel[channel].cursor_pattern[(value >> 16) & 0x000f] = value & 0x0000ffff; |
| 456 | } |
| 457 | break; |
| 458 | case 0xd0: // Region Control 0-7 |
| 459 | case 0xd1: |
| 460 | case 0xd2: |
| 461 | case 0xd3: |
| 462 | case 0xd4: |
| 463 | case 0xd5: |
| 464 | case 0xd6: |
| 465 | case 0xd7: |
| 466 | verboselog(machine, 6, " %04xxxxx: %d: Region Control %d = %08x\n", channel * 0x20, channel, reg & 7, value ); |
| 467 | mcd212->channel[0].region_control[reg & 7] = value; |
| 468 | mcd212_update_region_arrays(mcd212); |
| 469 | break; |
| 470 | case 0xd8: // Backdrop Color |
| 471 | if(channel == 0) |
| 472 | { |
| 473 | verboselog(machine, 6, " %04xxxxx: %d: Backdrop Color = %08x\n", channel * 0x20, channel, value ); |
| 474 | mcd212->channel[channel].backdrop_color = value; |
| 475 | } |
| 476 | break; |
| 477 | case 0xd9: // Mosaic Pixel Hold Factor A |
| 478 | if(channel == 0) |
| 479 | { |
| 480 | verboselog(machine, 6, " %04xxxxx: %d: Mosaic Pixel Hold Factor A = %08x\n", channel * 0x20, channel, value ); |
| 481 | mcd212->channel[channel].mosaic_hold_a = value; |
| 482 | } |
| 483 | break; |
| 484 | case 0xda: // Mosaic Pixel Hold Factor B |
| 485 | if(channel == 1) |
| 486 | { |
| 487 | verboselog(machine, 6, " %04xxxxx: %d: Mosaic Pixel Hold Factor B = %08x\n", channel * 0x20, channel, value ); |
| 488 | mcd212->channel[channel].mosaic_hold_b = value; |
| 489 | } |
| 490 | break; |
| 491 | case 0xdb: // Weight Factor A |
| 492 | if(channel == 0) |
| 493 | { |
| 494 | verboselog(machine, 6, " %04xxxxx: %d: Weight Factor A = %08x\n", channel * 0x20, channel, value ); |
| 495 | memset(mcd212->channel[channel].weight_factor_a, value & 0x000000ff, 768); |
| 496 | mcd212_update_region_arrays(mcd212); |
| 497 | } |
| 498 | break; |
| 499 | case 0xdc: // Weight Factor B |
| 500 | if(channel == 1) |
| 501 | { |
| 502 | verboselog(machine, 6, " %04xxxxx: %d: Weight Factor B = %08x\n", channel * 0x20, channel, value ); |
| 503 | memset(mcd212->channel[channel].weight_factor_b, value & 0x000000ff, 768); |
| 504 | mcd212_update_region_arrays(mcd212); |
| 505 | } |
| 506 | break; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | static UINT32 mcd212_get_vsr(mcd212_regs_t *mcd212, int channel) |
| 511 | { |
| 512 | return ((mcd212->channel[channel].dcr & 0x3f) << 16) | mcd212->channel[channel].vsr; |
| 513 | } |
| 514 | |
| 515 | static void mcd212_set_dcp(mcd212_regs_t *mcd212, int channel, UINT32 value) |
| 516 | { |
| 517 | mcd212->channel[channel].dcp = value & 0x0000ffff; |
| 518 | mcd212->channel[channel].ddr &= 0xffc0; |
| 519 | mcd212->channel[channel].ddr |= (value >> 16) & 0x003f; |
| 520 | } |
| 521 | |
| 522 | static UINT32 mcd212_get_dcp(mcd212_regs_t *mcd212, int channel) |
| 523 | { |
| 524 | return ((mcd212->channel[channel].ddr & 0x3f) << 16) | mcd212->channel[channel].dcp; |
| 525 | } |
| 526 | |
| 527 | static void mcd212_set_display_parameters(mcd212_regs_t *mcd212, int channel, UINT8 value) |
| 528 | { |
| 529 | mcd212->channel[channel].ddr &= 0xf0ff; |
| 530 | mcd212->channel[channel].ddr |= (value & 0x0f) << 8; |
| 531 | mcd212->channel[channel].dcr &= 0xf7ff; |
| 532 | mcd212->channel[channel].dcr |= (value & 0x10) << 7; |
| 533 | } |
| 534 | |
| 535 | static void mcd212_update_visible_area(running_machine *machine) |
| 536 | { |
| 537 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 538 | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 539 | const rectangle &visarea = machine->primary_screen->visible_area(); |
| 540 | rectangle visarea1; |
| 541 | attoseconds_t period = machine->primary_screen->frame_period().attoseconds; |
| 542 | int width = 0; |
| 543 | |
| 544 | if((mcd212->channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (mcd212->channel[0].csrw & MCD212_CSR1W_ST)) |
| 545 | { |
| 546 | width = 360; |
| 547 | } |
| 548 | else |
| 549 | { |
| 550 | width = 384; |
| 551 | } |
| 552 | |
| 553 | visarea1.max_x = width-1; |
| 554 | visarea1.min_x = visarea.min_x; |
| 555 | visarea1.min_y = visarea.min_y; |
| 556 | visarea1.max_y = visarea.max_y; |
| 557 | |
| 558 | machine->primary_screen->configure(width, 262, visarea1, period); |
| 559 | } |
| 560 | |
| 561 | static UINT32 mcd212_get_screen_width(mcd212_regs_t *mcd212) |
| 562 | { |
| 563 | if((mcd212->channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (mcd212->channel[0].csrw & MCD212_CSR1W_ST)) |
| 564 | { |
| 565 | return 720; |
| 566 | } |
| 567 | return 768; |
| 568 | } |
| 569 | |
| 570 | static void mcd212_process_ica(mcd212_regs_t *mcd212, int channel) |
| 571 | { |
| 572 | running_machine *machine = mcd212->machine; |
| 573 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 574 | UINT16 *ica = channel ? state->planeb : state->planea; |
| 575 | UINT32 addr = 0x000400/2; |
| 576 | UINT32 cmd = 0; |
| 577 | while(1) |
| 578 | { |
| 579 | UINT8 stop = 0; |
| 580 | cmd = ica[addr++] << 16; |
| 581 | cmd |= ica[addr++]; |
| 582 | switch((cmd & 0xff000000) >> 24) |
| 583 | { |
| 584 | case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: // STOP |
| 585 | case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
| 586 | verboselog(machine, 11, "%08x: %08x: ICA %d: STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 587 | stop = 1; |
| 588 | break; |
| 589 | case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: // NOP |
| 590 | case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 591 | verboselog(machine, 12, "%08x: %08x: ICA %d: NOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 592 | break; |
| 593 | case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP |
| 594 | case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f: |
| 595 | verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 596 | mcd212_set_dcp(mcd212, channel, cmd & 0x001fffff); |
| 597 | break; |
| 598 | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP |
| 599 | case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: |
| 600 | verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 601 | mcd212_set_dcp(mcd212, channel, cmd & 0x001fffff); |
| 602 | stop = 1; |
| 603 | break; |
| 604 | case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD ICA |
| 605 | case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f: |
| 606 | verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD ICA\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 607 | addr = (cmd & 0x001fffff) / 2; |
| 608 | break; |
| 609 | case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP |
| 610 | case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: |
| 611 | verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 612 | mcd212_set_vsr(mcd212, channel, cmd & 0x001fffff); |
| 613 | stop = 1; |
| 614 | break; |
| 615 | case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT |
| 616 | case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: |
| 617 | verboselog(machine, 11, "%08x: %08x: ICA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 618 | mcd212->channel[1].csrr |= 1 << (2 - channel); |
| 619 | if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2)) |
| 620 | { |
| 621 | UINT8 interrupt = (state->scc68070_regs.lir >> 4) & 7; |
| 622 | if(interrupt) |
| 623 | { |
| 624 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_1 + (interrupt - 1), 56 + interrupt); |
| 625 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE); |
| 626 | } |
| 627 | } |
| 628 | #if 0 |
| 629 | if(mcd212->channel[1].csrr & MCD212_CSR2R_IT2) |
| 630 | { |
| 631 | UINT8 interrupt = state->scc68070_regs.lir & 7; |
| 632 | if(interrupt) |
| 633 | { |
| 634 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_1 + (interrupt - 1), 24 + interrupt); |
| 635 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE); |
| 636 | } |
| 637 | } |
| 638 | #endif |
| 639 | break; |
| 640 | case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS |
| 641 | verboselog(machine, 6, "%08x: %08x: ICA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 642 | mcd212_set_display_parameters(mcd212, channel, cmd & 0x1f); |
| 643 | break; |
| 644 | default: |
| 645 | mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff); |
| 646 | break; |
| 647 | } |
| 648 | if(stop) |
| 649 | { |
| 650 | break; |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | static void mcd212_process_dca(mcd212_regs_t *mcd212, int channel) |
| 656 | { |
| 657 | running_machine *machine = mcd212->machine; |
| 658 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 659 | UINT16 *dca = channel ? state->planeb : state->planea; |
| 660 | UINT32 addr = (mcd212->channel[channel].dca & 0x0007ffff) / 2; //(mcd212_get_dcp(mcd212, channel) & 0x0007ffff) / 2; // mcd212->channel[channel].dca / 2; |
| 661 | UINT32 cmd = 0; |
| 662 | UINT32 count = 0; |
| 663 | UINT32 max = 64; |
| 664 | UINT8 addr_changed = 0; |
| 665 | //printf( "max = %d\n", max ); |
| 666 | while(1) |
| 667 | { |
| 668 | UINT8 stop = 0; |
| 669 | cmd = dca[addr++] << 16; |
| 670 | cmd |= dca[addr++]; |
| 671 | count += 4; |
| 672 | switch((cmd & 0xff000000) >> 24) |
| 673 | { |
| 674 | case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: // STOP |
| 675 | case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
| 676 | verboselog(machine, 11, "%08x: %08x: DCA %d: STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 677 | stop = 1; |
| 678 | break; |
| 679 | case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: // NOP |
| 680 | case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 681 | verboselog(machine, 12, "%08x: %08x: DCA %d: NOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 682 | break; |
| 683 | case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP |
| 684 | case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f: |
| 685 | verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD DCP (NOP)\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 686 | break; |
| 687 | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP |
| 688 | case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: |
| 689 | verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 690 | mcd212_set_dcp(&state->mcd212_regs, channel, cmd & 0x001fffff); |
| 691 | addr = (cmd & 0x0007ffff) / 2; |
| 692 | addr_changed = 1; |
| 693 | stop = 1; |
| 694 | break; |
| 695 | case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD VSR |
| 696 | case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f: |
| 697 | verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 698 | mcd212_set_vsr(&state->mcd212_regs, channel, cmd & 0x001fffff); |
| 699 | break; |
| 700 | case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP |
| 701 | case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: |
| 702 | verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 703 | mcd212_set_vsr(&state->mcd212_regs, channel, cmd & 0x001fffff); |
| 704 | stop = 1; |
| 705 | break; |
| 706 | case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT |
| 707 | case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: |
| 708 | verboselog(machine, 11, "%08x: %08x: DCA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 709 | mcd212->channel[1].csrr |= 1 << (2 - channel); |
| 710 | if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2)) |
| 711 | { |
| 712 | UINT8 interrupt = (state->scc68070_regs.lir >> 4) & 7; |
| 713 | if(interrupt) |
| 714 | { |
| 715 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_1 + (interrupt - 1), 56 + interrupt); |
| 716 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE); |
| 717 | } |
| 718 | } |
| 719 | #if 0 |
| 720 | if(mcd212->channel[1].csrr & MCD212_CSR2R_IT2) |
| 721 | { |
| 722 | UINT8 interrupt = state->scc68070_regs.lir & 7; |
| 723 | if(interrupt) |
| 724 | { |
| 725 | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_1 + (interrupt - 1), 24 + interrupt); |
| 726 | cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE); |
| 727 | } |
| 728 | } |
| 729 | #endif |
| 730 | break; |
| 731 | case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS |
| 732 | verboselog(machine, 6, "%08x: %08x: DCA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 733 | mcd212_set_display_parameters(&state->mcd212_regs, channel, cmd & 0x1f); |
| 734 | break; |
| 735 | default: |
| 736 | mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff); |
| 737 | break; |
| 738 | } |
| 739 | if(stop != 0 || count == max) |
| 740 | { |
| 741 | break; |
| 742 | } |
| 743 | } |
| 744 | if(!addr_changed) |
| 745 | { |
| 746 | if(count < max) |
| 747 | { |
| 748 | addr += (max - count) >> 1; |
| 749 | } |
| 750 | } |
| 751 | mcd212->channel[channel].dca = addr * 2; |
| 752 | } |
| 753 | |
| 754 | INLINE UINT8 MCD212_LIM(INT32 in) |
| 755 | { |
| 756 | if(in < 0) |
| 757 | { |
| 758 | return 0; |
| 759 | } |
| 760 | else if(in > 255) |
| 761 | { |
| 762 | return 255; |
| 763 | } |
| 764 | return (UINT8)in; |
| 765 | } |
| 766 | |
| 767 | INLINE UINT8 BYTE_TO_CLUT(int channel, int icm, UINT8 byte) |
| 768 | { |
| 769 | switch(icm) |
| 770 | { |
| 771 | case 1: |
| 772 | return byte; |
| 773 | case 3: |
| 774 | if(channel) |
| 775 | { |
| 776 | return 0x80 + (byte & 0x7f); |
| 777 | } |
| 778 | else |
| 779 | { |
| 780 | return byte & 0x7f; |
| 781 | } |
| 782 | case 4: |
| 783 | if(!channel) |
| 784 | { |
| 785 | return byte & 0x7f; |
| 786 | } |
| 787 | break; |
| 788 | case 11: |
| 789 | if(channel) |
| 790 | { |
| 791 | return 0x80 + (byte & 0x0f); |
| 792 | } |
| 793 | else |
| 794 | { |
| 795 | return byte & 0x0f; |
| 796 | } |
| 797 | default: |
| 798 | break; |
| 799 | } |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | static void mcd212_process_vsr(mcd212_regs_t *mcd212, int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b) |
| 804 | { |
| 805 | running_machine *machine = mcd212->machine; |
| 806 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 807 | UINT8 *data = channel ? (UINT8*)state->planeb : (UINT8*)state->planea; |
| 808 | UINT32 vsr = mcd212_get_vsr(mcd212, channel) & 0x0007ffff; |
| 809 | UINT8 done = 0; |
| 810 | UINT32 x = 0; |
| 811 | UINT32 icm_mask = channel ? MCD212_ICM_MODE2 : MCD212_ICM_MODE1; |
| 812 | UINT32 icm_shift = channel ? MCD212_ICM_MODE2_SHIFT : MCD212_ICM_MODE1_SHIFT; |
| 813 | UINT8 icm = (mcd212->channel[0].image_coding_method & icm_mask) >> icm_shift; |
| 814 | UINT8 *clut_r = mcd212->channel[0].clut_r; |
| 815 | UINT8 *clut_g = mcd212->channel[0].clut_g; |
| 816 | UINT8 *clut_b = mcd212->channel[0].clut_b; |
| 817 | UINT8 mosaic_enable = ((mcd212->channel[channel].ddr & MCD212_DDR_FT) == MCD212_DDR_FT_MOSAIC); |
| 818 | UINT8 mosaic_factor = 1 << (((mcd212->channel[channel].ddr & MCD212_DDR_MT) >> MCD212_DDR_MT_SHIFT) + 1); |
| 819 | int mosaic_index = 0; |
| 820 | UINT32 width = mcd212_get_screen_width(mcd212); |
| 821 | |
| 822 | //printf( "vsr before: %08x: ", vsr ); |
| 823 | //fflush(stdout); |
| 824 | |
| 825 | if(!icm || !vsr) |
| 826 | { |
| 827 | memset(pixels_r, 0x10, width); |
| 828 | memset(pixels_g, 0x10, width); |
| 829 | memset(pixels_b, 0x10, width); |
| 830 | return; |
| 831 | } |
| 832 | |
| 833 | while(!done) |
| 834 | { |
| 835 | UINT8 byte = data[(vsr & 0x0007ffff) ^ 1]; |
| 836 | vsr++; |
| 837 | switch(mcd212->channel[channel].ddr & MCD212_DDR_FT) |
| 838 | { |
| 839 | case MCD212_DDR_FT_BMP: |
| 840 | case MCD212_DDR_FT_BMP2: |
| 841 | case MCD212_DDR_FT_MOSAIC: |
| 842 | if(mcd212->channel[channel].dcr & MCD212_DCR_CM) |
| 843 | { |
| 844 | // 4-bit Bitmap |
| 845 | verboselog(machine, 0, "Unsupported display mode: 4-bit Bitmap\n" ); |
| 846 | } |
| 847 | else |
| 848 | { |
| 849 | // 8-bit Bitmap |
| 850 | if(icm == 5) |
| 851 | { |
| 852 | BYTE68K bY; |
| 853 | BYTE68K bU; |
| 854 | BYTE68K bV; |
| 855 | switch(channel) |
| 856 | { |
| 857 | case 0: |
| 858 | bY = (mcd212->channel[0].dyuv_abs_start_a >> 16) & 0x000000ff; |
| 859 | bU = (mcd212->channel[0].dyuv_abs_start_a >> 8) & 0x000000ff; |
| 860 | bV = (mcd212->channel[0].dyuv_abs_start_a >> 0) & 0x000000ff; |
| 861 | break; |
| 862 | case 1: |
| 863 | bY = (mcd212->channel[1].dyuv_abs_start_b >> 16) & 0x000000ff; |
| 864 | bU = (mcd212->channel[1].dyuv_abs_start_b >> 8) & 0x000000ff; |
| 865 | bV = (mcd212->channel[1].dyuv_abs_start_b >> 0) & 0x000000ff; |
| 866 | break; |
| 867 | default: |
| 868 | bY = bU = bV = 0x80; |
| 869 | break; |
| 870 | } |
| 871 | for(; x < width; x += 2) |
| 872 | { |
| 873 | BYTE68K b0 = byte; |
| 874 | BYTE68K bU1 = bU + state->mcd212_ab.deltaUV[b0]; |
| 875 | BYTE68K bY0 = bY + state->mcd212_ab.deltaY[b0]; |
| 876 | |
| 877 | BYTE68K b1 = data[(vsr & 0x0007ffff) ^ 1]; |
| 878 | BYTE68K bV1 = bV + state->mcd212_ab.deltaUV[b1]; |
| 879 | BYTE68K bY1 = bY0 + state->mcd212_ab.deltaY[b1]; |
| 880 | |
| 881 | BYTE68K bU0 = (bU + bU1) >> 1; |
| 882 | BYTE68K bV0 = (bV + bV1) >> 1; |
| 883 | |
| 884 | BYTE68K *pbLimit; |
| 885 | |
| 886 | vsr++; |
| 887 | |
| 888 | bY = bY0; |
| 889 | bU = bU0; |
| 890 | bV = bV0; |
| 891 | |
| 892 | pbLimit = state->mcd212_ab.limit + bY + BYTE68K_MAX; |
| 893 | |
| 894 | pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[state->mcd212_ab.matrixVR[bV]]; |
| 895 | pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[state->mcd212_ab.matrixUG[bU] + state->mcd212_ab.matrixVG[bV]]; |
| 896 | pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[state->mcd212_ab.matrixUB[bU]]; |
| 897 | |
| 898 | if(mosaic_enable) |
| 899 | { |
| 900 | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 901 | { |
| 902 | pixels_r[x + 0 + mosaic_index*2] = pixels_r[x + 0]; |
| 903 | pixels_g[x + 0 + mosaic_index*2] = pixels_g[x + 0]; |
| 904 | pixels_b[x + 0 + mosaic_index*2] = pixels_b[x + 0]; |
| 905 | pixels_r[x + 1 + mosaic_index*2] = pixels_r[x + 1]; |
| 906 | pixels_g[x + 1 + mosaic_index*2] = pixels_g[x + 1]; |
| 907 | pixels_b[x + 1 + mosaic_index*2] = pixels_b[x + 1]; |
| 908 | } |
| 909 | x += mosaic_factor * 2; |
| 910 | } |
| 911 | else |
| 912 | { |
| 913 | x += 2; |
| 914 | } |
| 915 | |
| 916 | bY = bY1; |
| 917 | bU = bU1; |
| 918 | bV = bV1; |
| 919 | |
| 920 | pbLimit = state->mcd212_ab.limit + bY + BYTE68K_MAX; |
| 921 | |
| 922 | pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[state->mcd212_ab.matrixVR[bV]]; |
| 923 | pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[state->mcd212_ab.matrixUG[bU] + state->mcd212_ab.matrixVG[bV]]; |
| 924 | pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[state->mcd212_ab.matrixUB[bU]]; |
| 925 | |
| 926 | if(mosaic_enable) |
| 927 | { |
| 928 | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 929 | { |
| 930 | pixels_r[x + 0 + mosaic_index*2] = pixels_r[x + 0]; |
| 931 | pixels_g[x + 0 + mosaic_index*2] = pixels_g[x + 0]; |
| 932 | pixels_b[x + 0 + mosaic_index*2] = pixels_b[x + 0]; |
| 933 | pixels_r[x + 1 + mosaic_index*2] = pixels_r[x + 1]; |
| 934 | pixels_g[x + 1 + mosaic_index*2] = pixels_g[x + 1]; |
| 935 | pixels_b[x + 1 + mosaic_index*2] = pixels_b[x + 1]; |
| 936 | } |
| 937 | x += (mosaic_factor * 2) - 2; |
| 938 | } |
| 939 | |
| 940 | byte = data[(vsr & 0x0007ffff) ^ 1]; |
| 941 | |
| 942 | vsr++; |
| 943 | } |
| 944 | mcd212_set_vsr(&state->mcd212_regs, channel, (vsr - 1) & 0x0007ffff); |
| 945 | } |
| 946 | else if(icm == 1 || icm == 3 || icm == 4) |
| 947 | { |
| 948 | for(; x < width; x += 2) |
| 949 | { |
| 950 | UINT8 clut_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 951 | pixels_r[x + 0] = clut_r[clut_entry]; |
| 952 | pixels_g[x + 0] = clut_g[clut_entry]; |
| 953 | pixels_b[x + 0] = clut_b[clut_entry]; |
| 954 | pixels_r[x + 1] = clut_r[clut_entry]; |
| 955 | pixels_g[x + 1] = clut_g[clut_entry]; |
| 956 | pixels_b[x + 1] = clut_b[clut_entry]; |
| 957 | if(mosaic_enable) |
| 958 | { |
| 959 | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 960 | { |
| 961 | pixels_r[x + 0 + mosaic_index*2] = pixels_r[x + 0]; |
| 962 | pixels_g[x + 0 + mosaic_index*2] = pixels_g[x + 0]; |
| 963 | pixels_b[x + 0 + mosaic_index*2] = pixels_b[x + 0]; |
| 964 | pixels_r[x + 1 + mosaic_index*2] = pixels_r[x + 1]; |
| 965 | pixels_g[x + 1 + mosaic_index*2] = pixels_g[x + 1]; |
| 966 | pixels_b[x + 1 + mosaic_index*2] = pixels_b[x + 1]; |
| 967 | } |
| 968 | x += (mosaic_factor * 2) - 2; |
| 969 | } |
| 970 | byte = data[(vsr & 0x0007ffff) ^ 1]; |
| 971 | vsr++; |
| 972 | } |
| 973 | mcd212_set_vsr(&state->mcd212_regs, channel, (vsr - 1) & 0x0007ffff); |
| 974 | } |
| 975 | else if(icm == 11) |
| 976 | { |
| 977 | for(; x < width; x += 2) |
| 978 | { |
| 979 | UINT8 even_entry = BYTE_TO_CLUT(channel, icm, byte >> 4); |
| 980 | UINT8 odd_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 981 | if(mosaic_enable) |
| 982 | { |
| 983 | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 984 | { |
| 985 | pixels_r[x + mosaic_index] = clut_r[even_entry]; |
| 986 | pixels_g[x + mosaic_index] = clut_g[even_entry]; |
| 987 | pixels_b[x + mosaic_index] = clut_b[even_entry]; |
| 988 | } |
| 989 | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 990 | { |
| 991 | pixels_r[x + mosaic_factor + mosaic_index] = clut_r[odd_entry]; |
| 992 | pixels_g[x + mosaic_factor + mosaic_index] = clut_g[odd_entry]; |
| 993 | pixels_b[x + mosaic_factor + mosaic_index] = clut_b[odd_entry]; |
| 994 | } |
| 995 | x += (mosaic_factor * 2) - 2; |
| 996 | } |
| 997 | else |
| 998 | { |
| 999 | pixels_r[x + 0] = clut_r[even_entry]; |
| 1000 | pixels_g[x + 0] = clut_g[even_entry]; |
| 1001 | pixels_b[x + 0] = clut_b[even_entry]; |
| 1002 | pixels_r[x + 1] = clut_r[odd_entry]; |
| 1003 | pixels_g[x + 1] = clut_g[odd_entry]; |
| 1004 | pixels_b[x + 1] = clut_b[odd_entry]; |
| 1005 | } |
| 1006 | byte = data[(vsr & 0x0007ffff) ^ 1]; |
| 1007 | vsr++; |
| 1008 | } |
| 1009 | mcd212_set_vsr(&state->mcd212_regs, channel, (vsr - 1) & 0x0007ffff); |
| 1010 | } |
| 1011 | else |
| 1012 | { |
| 1013 | for(; x < width; x++) |
| 1014 | { |
| 1015 | pixels_r[x] = 0x10; |
| 1016 | pixels_g[x] = 0x10; |
| 1017 | pixels_b[x] = 0x10; |
| 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | done = 1; |
| 1022 | break; |
| 1023 | case MCD212_DDR_FT_RLE: |
| 1024 | if(mcd212->channel[channel].dcr & MCD212_DCR_CM) |
| 1025 | { |
| 1026 | verboselog(machine, 0, "Unsupported display mode: 4-bit RLE\n" ); |
| 1027 | done = 1; |
| 1028 | } |
| 1029 | else |
| 1030 | { |
| 1031 | if(byte & 0x80) |
| 1032 | { |
| 1033 | // Run length |
| 1034 | UINT8 length = data[((vsr++) & 0x0007ffff) ^ 1]; |
| 1035 | if(!length) |
| 1036 | { |
| 1037 | UINT8 clut_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 1038 | UINT8 r = clut_r[clut_entry]; |
| 1039 | UINT8 g = clut_g[clut_entry]; |
| 1040 | UINT8 b = clut_b[clut_entry]; |
| 1041 | // Go to the end of the line |
| 1042 | for(; x < width; x++) |
| 1043 | { |
| 1044 | pixels_r[x] = r; |
| 1045 | pixels_g[x] = g; |
| 1046 | pixels_b[x] = b; |
| 1047 | x++; |
| 1048 | pixels_r[x] = r; |
| 1049 | pixels_g[x] = g; |
| 1050 | pixels_b[x] = b; |
| 1051 | } |
| 1052 | done = 1; |
| 1053 | mcd212_set_vsr(&state->mcd212_regs, channel, vsr); |
| 1054 | } |
| 1055 | else |
| 1056 | { |
| 1057 | int end = x + (length * 2); |
| 1058 | UINT8 clut_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 1059 | UINT8 r = clut_r[clut_entry]; |
| 1060 | UINT8 g = clut_g[clut_entry]; |
| 1061 | UINT8 b = clut_b[clut_entry]; |
| 1062 | for(; x < end && x < width; x++) |
| 1063 | { |
| 1064 | pixels_r[x] = r; |
| 1065 | pixels_g[x] = g; |
| 1066 | pixels_b[x] = b; |
| 1067 | x++; |
| 1068 | pixels_r[x] = r; |
| 1069 | pixels_g[x] = g; |
| 1070 | pixels_b[x] = b; |
| 1071 | } |
| 1072 | if(x >= width) |
| 1073 | { |
| 1074 | done = 1; |
| 1075 | mcd212_set_vsr(&state->mcd212_regs, channel, vsr); |
| 1076 | } |
| 1077 | } |
| 1078 | } |
| 1079 | else |
| 1080 | { |
| 1081 | // Single pixel |
| 1082 | UINT8 clut_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 1083 | pixels_r[x] = clut_r[clut_entry]; |
| 1084 | pixels_g[x] = clut_g[clut_entry]; |
| 1085 | pixels_b[x] = clut_b[clut_entry]; |
| 1086 | x++; |
| 1087 | pixels_r[x] = clut_r[clut_entry]; |
| 1088 | pixels_g[x] = clut_g[clut_entry]; |
| 1089 | pixels_b[x] = clut_b[clut_entry]; |
| 1090 | x++; |
| 1091 | if(x >= width) |
| 1092 | { |
| 1093 | done = 1; |
| 1094 | mcd212_set_vsr(&state->mcd212_regs, channel, vsr); |
| 1095 | } |
| 1096 | } |
| 1097 | } |
| 1098 | break; |
| 1099 | } |
| 1100 | } |
| 1101 | |
| 1102 | //printf( ": vsr after: %08x\n", vsr); |
| 1103 | //mcd212_set_vsr(&state->mcd212_regs, channel, vsr); |
| 1104 | } |
| 1105 | |
| 1106 | static const UINT32 mcd212_4bpp_color[16] = |
| 1107 | { |
| 1108 | 0x00101010, 0x0010107a, 0x00107a10, 0x00107a7a, 0x007a1010, 0x007a107a, 0x007a7a10, 0x007a7a7a, |
| 1109 | 0x00101010, 0x001010e6, 0x0010e610, 0x0010e6e6, 0x00e61010, 0x00e610e6, 0x00e6e610, 0x00e6e6e6 |
| 1110 | }; |
| 1111 | |
| 1112 | static void mcd212_mix_lines(mcd212_regs_t *mcd212, UINT8 *plane_a_r, UINT8 *plane_a_g, UINT8 *plane_a_b, UINT8 *plane_b_r, UINT8 *plane_b_g, UINT8 *plane_b_b, UINT32 *out) |
| 1113 | { |
| 1114 | running_machine *machine = mcd212->machine; |
| 1115 | int x = 0; |
| 1116 | UINT8 debug_mode = input_port_read(machine, "DEBUG"); |
| 1117 | UINT8 global_plane_a_disable = debug_mode & 1; |
| 1118 | UINT8 global_plane_b_disable = debug_mode & 2; |
| 1119 | UINT8 debug_backdrop_enable = debug_mode & 4; |
| 1120 | UINT8 debug_backdrop_index = debug_mode >> 4; |
| 1121 | UINT32 backdrop = debug_backdrop_enable ? mcd212_4bpp_color[debug_backdrop_index] : mcd212_4bpp_color[mcd212->channel[0].backdrop_color]; |
| 1122 | UINT8 transparency_mode_a = (mcd212->channel[0].transparency_control >> 0) & 0x0f; |
| 1123 | UINT8 transparency_mode_b = (mcd212->channel[0].transparency_control >> 8) & 0x0f; |
| 1124 | UINT8 transparent_color_a_r = (UINT8)(mcd212->channel[0].transparent_color_a >> 16); |
| 1125 | UINT8 transparent_color_a_g = (UINT8)(mcd212->channel[0].transparent_color_a >> 8); |
| 1126 | UINT8 transparent_color_a_b = (UINT8)(mcd212->channel[0].transparent_color_a >> 0); |
| 1127 | UINT8 transparent_color_b_r = (UINT8)(mcd212->channel[1].transparent_color_b >> 16); |
| 1128 | UINT8 transparent_color_b_g = (UINT8)(mcd212->channel[1].transparent_color_b >> 8); |
| 1129 | UINT8 transparent_color_b_b = (UINT8)(mcd212->channel[1].transparent_color_b >> 0); |
| 1130 | UINT8 image_coding_method_a = mcd212->channel[0].image_coding_method & 0x0000000f; |
| 1131 | UINT8 image_coding_method_b = (mcd212->channel[0].image_coding_method >> 8) & 0x0000000f; |
| 1132 | UINT8 dyuv_enable_a = (image_coding_method_a == 5); |
| 1133 | UINT8 dyuv_enable_b = (image_coding_method_b == 5); |
| 1134 | UINT8 mosaic_enable_a = (mcd212->channel[0].mosaic_hold_a & 0x800000) >> 23; |
| 1135 | UINT8 mosaic_enable_b = (mcd212->channel[1].mosaic_hold_b & 0x800000) >> 23; |
| 1136 | UINT8 mosaic_count_a = (mcd212->channel[0].mosaic_hold_a & 0x0000ff) << 1; |
| 1137 | UINT8 mosaic_count_b = (mcd212->channel[1].mosaic_hold_b & 0x0000ff) << 1; |
| 1138 | for(x = 0; x < 768; x++) |
| 1139 | { |
| 1140 | out[x] = backdrop; |
| 1141 | if(!(mcd212->channel[0].transparency_control & MCD212_TCR_DISABLE_MX)) |
| 1142 | { |
| 1143 | UINT8 abr = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r[x] - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_r[x] - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 1144 | UINT8 abg = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g[x] - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_g[x] - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 1145 | UINT8 abb = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b[x] - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_b[x] - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 1146 | out[x] = (abr << 16) | (abg << 8) | abb; |
| 1147 | } |
| 1148 | else |
| 1149 | { |
| 1150 | UINT8 plane_enable_a = 0; |
| 1151 | UINT8 plane_enable_b = 0; |
| 1152 | UINT8 plane_a_r_cur = mosaic_enable_a ? plane_a_r[x - (x % mosaic_count_a)] : plane_a_r[x]; |
| 1153 | UINT8 plane_a_g_cur = mosaic_enable_a ? plane_a_g[x - (x % mosaic_count_a)] : plane_a_g[x]; |
| 1154 | UINT8 plane_a_b_cur = mosaic_enable_a ? plane_a_b[x - (x % mosaic_count_a)] : plane_a_b[x]; |
| 1155 | UINT8 plane_b_r_cur = mosaic_enable_b ? plane_b_r[x - (x % mosaic_count_b)] : plane_b_r[x]; |
| 1156 | UINT8 plane_b_g_cur = mosaic_enable_b ? plane_b_g[x - (x % mosaic_count_b)] : plane_b_g[x]; |
| 1157 | UINT8 plane_b_b_cur = mosaic_enable_b ? plane_b_b[x - (x % mosaic_count_b)] : plane_b_b[x]; |
| 1158 | switch(transparency_mode_a) |
| 1159 | { |
| 1160 | case 0: |
| 1161 | plane_enable_a = 0; |
| 1162 | break; |
| 1163 | case 1: |
| 1164 | plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b); |
| 1165 | break; |
| 1166 | case 3: |
| 1167 | plane_enable_a = !mcd212->region_flag_0[x]; |
| 1168 | break; |
| 1169 | case 4: |
| 1170 | plane_enable_a = !mcd212->region_flag_1[x]; |
| 1171 | break; |
| 1172 | case 5: |
| 1173 | plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b) && (dyuv_enable_a || mcd212->region_flag_0[x] == 0); |
| 1174 | break; |
| 1175 | case 6: |
| 1176 | plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b) && (dyuv_enable_a || mcd212->region_flag_1[x] == 0); |
| 1177 | break; |
| 1178 | case 8: |
| 1179 | plane_enable_a = 1; |
| 1180 | break; |
| 1181 | case 9: |
| 1182 | plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b); |
| 1183 | break; |
| 1184 | case 11: |
| 1185 | plane_enable_a = mcd212->region_flag_0[x]; |
| 1186 | break; |
| 1187 | case 12: |
| 1188 | plane_enable_a = mcd212->region_flag_1[x]; |
| 1189 | break; |
| 1190 | case 13: |
| 1191 | plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b) || dyuv_enable_a || mcd212->region_flag_0[x] == 1; |
| 1192 | break; |
| 1193 | case 14: |
| 1194 | plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b) || dyuv_enable_a || mcd212->region_flag_1[x] == 1; |
| 1195 | break; |
| 1196 | default: |
| 1197 | verboselog(machine, 0, "Unhandled transparency mode for plane A: %d\n", transparency_mode_a); |
| 1198 | plane_enable_a = 1; |
| 1199 | break; |
| 1200 | } |
| 1201 | switch(transparency_mode_b) |
| 1202 | { |
| 1203 | case 0: |
| 1204 | plane_enable_b = 0; |
| 1205 | break; |
| 1206 | case 1: |
| 1207 | plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b); |
| 1208 | break; |
| 1209 | case 3: |
| 1210 | plane_enable_b = !mcd212->region_flag_0[x]; |
| 1211 | break; |
| 1212 | case 4: |
| 1213 | plane_enable_b = !mcd212->region_flag_1[x]; |
| 1214 | break; |
| 1215 | case 5: |
| 1216 | plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b) && (dyuv_enable_b || mcd212->region_flag_0[x] == 0); |
| 1217 | break; |
| 1218 | case 6: |
| 1219 | plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b) && (dyuv_enable_b || mcd212->region_flag_1[x] == 0); |
| 1220 | break; |
| 1221 | case 8: |
| 1222 | plane_enable_b = 1; |
| 1223 | break; |
| 1224 | case 9: |
| 1225 | plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b); |
| 1226 | break; |
| 1227 | case 11: |
| 1228 | plane_enable_b = mcd212->region_flag_0[x]; |
| 1229 | break; |
| 1230 | case 12: |
| 1231 | plane_enable_b = mcd212->region_flag_1[x]; |
| 1232 | break; |
| 1233 | case 13: |
| 1234 | plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b) || dyuv_enable_b || mcd212->region_flag_0[x] == 1; |
| 1235 | break; |
| 1236 | case 14: |
| 1237 | plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b) || dyuv_enable_b || mcd212->region_flag_1[x] == 1; |
| 1238 | break; |
| 1239 | default: |
| 1240 | verboselog(machine, 0, "Unhandled transparency mode for plane B: %d\n", transparency_mode_b); |
| 1241 | plane_enable_b = 1; |
| 1242 | break; |
| 1243 | } |
| 1244 | if(global_plane_a_disable) |
| 1245 | { |
| 1246 | plane_enable_a = 0; |
| 1247 | } |
| 1248 | if(global_plane_b_disable) |
| 1249 | { |
| 1250 | plane_enable_b = 0; |
| 1251 | } |
| 1252 | plane_a_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16); |
| 1253 | plane_a_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16); |
| 1254 | plane_a_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16); |
| 1255 | plane_b_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_r_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 1256 | plane_b_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_g_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 1257 | plane_b_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_b_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 1258 | switch(mcd212->channel[0].plane_order) |
| 1259 | { |
| 1260 | case MCD212_POR_AB: |
| 1261 | if(plane_enable_a) |
| 1262 | { |
| 1263 | out[x] = (plane_a_r_cur << 16) | (plane_a_g_cur << 8) | plane_a_b_cur; |
| 1264 | } |
| 1265 | else if(plane_enable_b) |
| 1266 | { |
| 1267 | out[x] = (plane_b_r_cur << 16) | (plane_b_g_cur << 8) | plane_b_b_cur; |
| 1268 | } |
| 1269 | break; |
| 1270 | case MCD212_POR_BA: |
| 1271 | if(plane_enable_b) |
| 1272 | { |
| 1273 | out[x] = (plane_b_r_cur << 16) | (plane_b_g_cur << 8) | plane_b_b_cur; |
| 1274 | } |
| 1275 | else if(plane_enable_a) |
| 1276 | { |
| 1277 | out[x] = (plane_a_r_cur << 16) | (plane_a_g_cur << 8) | plane_a_b_cur; |
| 1278 | } |
| 1279 | break; |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | } |
| 1284 | |
| 1285 | static void mcd212_draw_cursor(mcd212_regs_t *mcd212, UINT32 *scanline, int y) |
| 1286 | { |
| 1287 | if(mcd212->channel[0].cursor_control & MCD212_CURCNT_EN) |
| 1288 | { |
| 1289 | UINT16 curx = mcd212->channel[0].cursor_position & 0x3ff; |
| 1290 | UINT16 cury = ((mcd212->channel[0].cursor_position >> 12) & 0x3ff) + 22; |
| 1291 | UINT32 x = 0; |
| 1292 | if(y >= cury && y < (cury + 16)) |
| 1293 | { |
| 1294 | UINT32 color = mcd212_4bpp_color[mcd212->channel[0].cursor_control & MCD212_CURCNT_COLOR]; |
| 1295 | y -= cury; |
| 1296 | if(mcd212->channel[0].cursor_control & MCD212_CURCNT_CUW) |
| 1297 | { |
| 1298 | for(x = curx; x < curx + 64 && x < 768; x++) |
| 1299 | { |
| 1300 | if(mcd212->channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 2)))) |
| 1301 | { |
| 1302 | scanline[(x++)/2] = color; |
| 1303 | scanline[(x++)/2] = color; |
| 1304 | scanline[(x++)/2] = color; |
| 1305 | scanline[(x/2)] = color; |
| 1306 | } |
| 1307 | else |
| 1308 | { |
| 1309 | } |
| 1310 | } |
| 1311 | } |
| 1312 | else |
| 1313 | { |
| 1314 | for(x = curx; x < curx + 32 && x < 768; x++) |
| 1315 | { |
| 1316 | if(mcd212->channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 1)))) |
| 1317 | { |
| 1318 | scanline[(x++)/2] = color; |
| 1319 | scanline[x/2] = color; |
| 1320 | } |
| 1321 | else |
| 1322 | { |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | } |
| 1328 | } |
| 1329 | |
| 1330 | static void mcd212_draw_scanline(mcd212_regs_t *mcd212, int y) |
| 1331 | { |
| 1332 | running_machine *machine = mcd212->machine; |
| 1333 | bitmap_t *bitmap = machine->generic.tmpbitmap; |
| 1334 | UINT8 plane_a_r[768], plane_a_g[768], plane_a_b[768]; |
| 1335 | UINT8 plane_b_r[768], plane_b_g[768], plane_b_b[768]; |
| 1336 | UINT32 out[768]; |
| 1337 | UINT32 *scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 1338 | int x; |
| 1339 | |
| 1340 | mcd212_process_vsr(mcd212, 0, plane_a_r, plane_a_g, plane_a_b); |
| 1341 | mcd212_process_vsr(mcd212, 1, plane_b_r, plane_b_g, plane_b_b); |
| 1342 | |
| 1343 | mcd212_mix_lines(mcd212, plane_a_r, plane_a_g, plane_a_b, plane_b_r, plane_b_g, plane_b_b, out); |
| 1344 | |
| 1345 | for(x = 0; x < 384; x++) |
| 1346 | { |
| 1347 | scanline[x] = out[x*2]; |
| 1348 | } |
| 1349 | |
| 1350 | mcd212_draw_cursor(mcd212, scanline, y); |
| 1351 | } |
| 1352 | |
| 1353 | READ16_HANDLER( mcd212_r ) |
| 1354 | { |
| 1355 | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 1356 | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 1357 | UINT8 channel = 1 - (offset / 8); |
| 1358 | |
| 1359 | switch(offset) |
| 1360 | { |
| 1361 | case 0x00/2: |
| 1362 | case 0x10/2: |
| 1363 | if(ACCESSING_BITS_0_7) |
| 1364 | { |
| 1365 | verboselog(space->machine, 12, "mcd212_r: Status Register %d: %02x & %04x\n", channel + 1, mcd212->channel[1 - (offset / 8)].csrr, mem_mask); |
| 1366 | if(channel == 0) |
| 1367 | { |
| 1368 | return mcd212->channel[0].csrr; |
| 1369 | } |
| 1370 | else |
| 1371 | { |
| 1372 | UINT8 old_csr = mcd212->channel[1].csrr; |
| 1373 | UINT8 interrupt1 = (state->scc68070_regs.lir >> 4) & 7; |
| 1374 | //UINT8 interrupt2 = state->scc68070_regs.lir & 7; |
| 1375 | mcd212->channel[1].csrr &= ~(MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2); |
| 1376 | if(interrupt1) |
| 1377 | { |
| 1378 | cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_1 + (interrupt1 - 1), CLEAR_LINE); |
| 1379 | } |
| 1380 | //if(interrupt2) |
| 1381 | //{ |
| 1382 | // cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_1 + (interrupt2 - 1), CLEAR_LINE); |
| 1383 | //} |
| 1384 | return old_csr; |
| 1385 | } |
| 1386 | } |
| 1387 | else |
| 1388 | { |
| 1389 | verboselog(space->machine, 2, "mcd212_r: Unknown Register %d: %04x\n", channel + 1, mem_mask); |
| 1390 | } |
| 1391 | break; |
| 1392 | case 0x02/2: |
| 1393 | case 0x12/2: |
| 1394 | verboselog(space->machine, 2, "mcd212_r: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212->channel[1 - (offset / 8)].dcr, mem_mask); |
| 1395 | return mcd212->channel[1 - (offset / 8)].dcr; |
| 1396 | case 0x04/2: |
| 1397 | case 0x14/2: |
| 1398 | verboselog(space->machine, 2, "mcd212_r: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212->channel[1 - (offset / 8)].vsr, mem_mask); |
| 1399 | return mcd212->channel[1 - (offset / 8)].vsr; |
| 1400 | case 0x08/2: |
| 1401 | case 0x18/2: |
| 1402 | verboselog(space->machine, 2, "mcd212_r: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212->channel[1 - (offset / 8)].ddr, mem_mask); |
| 1403 | return mcd212->channel[1 - (offset / 8)].ddr; |
| 1404 | case 0x0a/2: |
| 1405 | case 0x1a/2: |
| 1406 | verboselog(space->machine, 2, "mcd212_r: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212->channel[1 - (offset / 8)].dcp, mem_mask); |
| 1407 | return mcd212->channel[1 - (offset / 8)].dcp; |
| 1408 | default: |
| 1409 | verboselog(space->machine, 2, "mcd212_r: Unknown Register %d & %04x\n", (1 - (offset / 8)) + 1, mem_mask); |
| 1410 | break; |
| 1411 | } |
| 1412 | |
| 1413 | return 0; |
| 1414 | } |
| 1415 | |
| 1416 | WRITE16_HANDLER( mcd212_w ) |
| 1417 | { |
| 1418 | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 1419 | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 1420 | |
| 1421 | switch(offset) |
| 1422 | { |
| 1423 | case 0x00/2: |
| 1424 | case 0x10/2: |
| 1425 | verboselog(space->machine, 2, "mcd212_w: Status Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 1426 | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].csrw); |
| 1427 | mcd212_update_visible_area(space->machine); |
| 1428 | break; |
| 1429 | case 0x02/2: |
| 1430 | case 0x12/2: |
| 1431 | verboselog(space->machine, 2, "mcd212_w: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 1432 | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].dcr); |
| 1433 | mcd212_update_visible_area(space->machine); |
| 1434 | break; |
| 1435 | case 0x04/2: |
| 1436 | case 0x14/2: |
| 1437 | verboselog(space->machine, 2, "mcd212_w: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 1438 | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].vsr); |
| 1439 | break; |
| 1440 | case 0x08/2: |
| 1441 | case 0x18/2: |
| 1442 | verboselog(space->machine, 2, "mcd212_w: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 1443 | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].ddr); |
| 1444 | break; |
| 1445 | case 0x0a/2: |
| 1446 | case 0x1a/2: |
| 1447 | verboselog(space->machine, 2, "mcd212_w: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 1448 | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].dcp); |
| 1449 | break; |
| 1450 | default: |
| 1451 | verboselog(space->machine, 2, "mcd212_w: Unknown Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 1452 | break; |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | TIMER_CALLBACK( mcd212_perform_scan ) |
| 1457 | { |
| 1458 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 1459 | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 1460 | int scanline = machine->primary_screen->vpos(); |
| 1461 | |
| 1462 | if(/*mcd212->channel[0].dcr & MCD212_DCR_DE*/1) |
| 1463 | { |
| 1464 | if(scanline == 0) |
| 1465 | { |
| 1466 | // Process ICA |
| 1467 | int index = 0; |
| 1468 | verboselog(machine, 6, "Frame Start\n" ); |
| 1469 | mcd212->channel[0].csrr &= 0x7f; |
| 1470 | for(index = 0; index < 2; index++) |
| 1471 | { |
| 1472 | if(mcd212->channel[index].dcr & MCD212_DCR_ICA) |
| 1473 | { |
| 1474 | mcd212_process_ica(mcd212, index); |
| 1475 | } |
| 1476 | } |
| 1477 | cdi220_draw_lcd(machine, scanline); |
| 1478 | } |
| 1479 | else if(scanline < 22) |
| 1480 | { |
| 1481 | cdi220_draw_lcd(machine, scanline); |
| 1482 | } |
| 1483 | else if(scanline >= 22) |
| 1484 | { |
| 1485 | int index = 0; |
| 1486 | mcd212->channel[0].csrr |= 0x80; |
| 1487 | // Process VSR |
| 1488 | mcd212_draw_scanline(mcd212, scanline); |
| 1489 | // Process DCA |
| 1490 | for(index = 0; index < 2; index++) |
| 1491 | { |
| 1492 | if(mcd212->channel[index].dcr & MCD212_DCR_DCA) |
| 1493 | { |
| 1494 | if(scanline == 22) |
| 1495 | { |
| 1496 | mcd212->channel[index].dca = mcd212_get_dcp(mcd212, index); |
| 1497 | } |
| 1498 | mcd212_process_dca(mcd212, index); |
| 1499 | } |
| 1500 | } |
| 1501 | if(scanline == 261) |
| 1502 | { |
| 1503 | mcd212->channel[0].csrr ^= 0x20; |
| 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | timer_adjust_oneshot(mcd212->scan_timer, machine->primary_screen->time_until_pos(( scanline + 1 ) % 262, 0), 0); |
| 1508 | } |
| 1509 | |
| 1510 | void mcd212_init(running_machine *machine, mcd212_regs_t *mcd212) |
| 1511 | { |
| 1512 | mcd212->machine = machine; |
| 1513 | |
| 1514 | int index = 0; |
| 1515 | for(index = 0; index < 2; index++) |
| 1516 | { |
| 1517 | mcd212->channel[index].csrr = 0; |
| 1518 | mcd212->channel[index].csrw = 0; |
| 1519 | mcd212->channel[index].dcr = 0; |
| 1520 | mcd212->channel[index].vsr = 0; |
| 1521 | mcd212->channel[index].ddr = 0; |
| 1522 | mcd212->channel[index].dcp = 0; |
| 1523 | mcd212->channel[index].dca = 0; |
| 1524 | memset(mcd212->channel[index].clut_r, 0, 768); |
| 1525 | memset(mcd212->channel[index].clut_g, 0, 768); |
| 1526 | memset(mcd212->channel[index].clut_b, 0, 768); |
| 1527 | mcd212->channel[index].image_coding_method = 0; |
| 1528 | mcd212->channel[index].transparency_control = 0; |
| 1529 | mcd212->channel[index].plane_order = 0; |
| 1530 | mcd212->channel[index].clut_bank = 0; |
| 1531 | mcd212->channel[index].transparent_color_a = 0; |
| 1532 | mcd212->channel[index].transparent_color_b = 0; |
| 1533 | mcd212->channel[index].mask_color_a = 0; |
| 1534 | mcd212->channel[index].mask_color_b = 0; |
| 1535 | mcd212->channel[index].dyuv_abs_start_a = 0; |
| 1536 | mcd212->channel[index].dyuv_abs_start_b = 0; |
| 1537 | mcd212->channel[index].cursor_position = 0; |
| 1538 | mcd212->channel[index].cursor_control = 0; |
| 1539 | memset((UINT8*)&mcd212->channel[index].cursor_pattern, 0, 16 * sizeof(UINT32)); |
| 1540 | memset((UINT8*)&mcd212->channel[index].region_control, 0, 8 * sizeof(UINT32)); |
| 1541 | mcd212->channel[index].backdrop_color = 0; |
| 1542 | mcd212->channel[index].mosaic_hold_a = 0; |
| 1543 | mcd212->channel[index].mosaic_hold_b = 0; |
| 1544 | memset(mcd212->channel[index].weight_factor_a, 0, 768); |
| 1545 | memset(mcd212->channel[index].weight_factor_b, 0, 768); |
| 1546 | } |
| 1547 | memset(mcd212->region_flag_0, 0, 768); |
| 1548 | memset(mcd212->region_flag_1, 0, 768); |
| 1549 | |
| 1550 | state_save_register_global_array(machine, mcd212->region_flag_0); |
| 1551 | state_save_register_global_array(machine, mcd212->region_flag_1); |
| 1552 | state_save_register_global(machine, mcd212->channel[0].csrr); |
| 1553 | state_save_register_global(machine, mcd212->channel[0].csrw); |
| 1554 | state_save_register_global(machine, mcd212->channel[0].dcr); |
| 1555 | state_save_register_global(machine, mcd212->channel[0].vsr); |
| 1556 | state_save_register_global(machine, mcd212->channel[0].ddr); |
| 1557 | state_save_register_global(machine, mcd212->channel[0].dcp); |
| 1558 | state_save_register_global(machine, mcd212->channel[0].dca); |
| 1559 | state_save_register_global_array(machine, mcd212->channel[0].clut_r); |
| 1560 | state_save_register_global_array(machine, mcd212->channel[0].clut_g); |
| 1561 | state_save_register_global_array(machine, mcd212->channel[0].clut_b); |
| 1562 | state_save_register_global(machine, mcd212->channel[0].image_coding_method); |
| 1563 | state_save_register_global(machine, mcd212->channel[0].transparency_control); |
| 1564 | state_save_register_global(machine, mcd212->channel[0].plane_order); |
| 1565 | state_save_register_global(machine, mcd212->channel[0].clut_bank); |
| 1566 | state_save_register_global(machine, mcd212->channel[0].transparent_color_a); |
| 1567 | state_save_register_global(machine, mcd212->channel[0].transparent_color_b); |
| 1568 | state_save_register_global(machine, mcd212->channel[0].mask_color_a); |
| 1569 | state_save_register_global(machine, mcd212->channel[0].mask_color_b); |
| 1570 | state_save_register_global(machine, mcd212->channel[0].dyuv_abs_start_a); |
| 1571 | state_save_register_global(machine, mcd212->channel[0].dyuv_abs_start_b); |
| 1572 | state_save_register_global(machine, mcd212->channel[0].cursor_position); |
| 1573 | state_save_register_global(machine, mcd212->channel[0].cursor_control); |
| 1574 | state_save_register_global_array(machine, mcd212->channel[0].cursor_pattern); |
| 1575 | state_save_register_global_array(machine, mcd212->channel[0].region_control); |
| 1576 | state_save_register_global(machine, mcd212->channel[0].backdrop_color); |
| 1577 | state_save_register_global(machine, mcd212->channel[0].mosaic_hold_a); |
| 1578 | state_save_register_global(machine, mcd212->channel[0].mosaic_hold_b); |
| 1579 | state_save_register_global_array(machine, mcd212->channel[0].weight_factor_a); |
| 1580 | state_save_register_global_array(machine, mcd212->channel[0].weight_factor_b); |
| 1581 | state_save_register_global(machine, mcd212->channel[1].csrr); |
| 1582 | state_save_register_global(machine, mcd212->channel[1].csrw); |
| 1583 | state_save_register_global(machine, mcd212->channel[1].dcr); |
| 1584 | state_save_register_global(machine, mcd212->channel[1].vsr); |
| 1585 | state_save_register_global(machine, mcd212->channel[1].ddr); |
| 1586 | state_save_register_global(machine, mcd212->channel[1].dcp); |
| 1587 | state_save_register_global(machine, mcd212->channel[1].dca); |
| 1588 | state_save_register_global_array(machine, mcd212->channel[1].clut_r); |
| 1589 | state_save_register_global_array(machine, mcd212->channel[1].clut_g); |
| 1590 | state_save_register_global_array(machine, mcd212->channel[1].clut_b); |
| 1591 | state_save_register_global(machine, mcd212->channel[1].image_coding_method); |
| 1592 | state_save_register_global(machine, mcd212->channel[1].transparency_control); |
| 1593 | state_save_register_global(machine, mcd212->channel[1].plane_order); |
| 1594 | state_save_register_global(machine, mcd212->channel[1].clut_bank); |
| 1595 | state_save_register_global(machine, mcd212->channel[1].transparent_color_a); |
| 1596 | state_save_register_global(machine, mcd212->channel[1].transparent_color_b); |
| 1597 | state_save_register_global(machine, mcd212->channel[1].mask_color_a); |
| 1598 | state_save_register_global(machine, mcd212->channel[1].mask_color_b); |
| 1599 | state_save_register_global(machine, mcd212->channel[1].dyuv_abs_start_a); |
| 1600 | state_save_register_global(machine, mcd212->channel[1].dyuv_abs_start_b); |
| 1601 | state_save_register_global(machine, mcd212->channel[1].cursor_position); |
| 1602 | state_save_register_global(machine, mcd212->channel[1].cursor_control); |
| 1603 | state_save_register_global_array(machine, mcd212->channel[1].cursor_pattern); |
| 1604 | state_save_register_global_array(machine, mcd212->channel[1].region_control); |
| 1605 | state_save_register_global(machine, mcd212->channel[1].backdrop_color); |
| 1606 | state_save_register_global(machine, mcd212->channel[1].mosaic_hold_a); |
| 1607 | state_save_register_global(machine, mcd212->channel[1].mosaic_hold_b); |
| 1608 | state_save_register_global_array(machine, mcd212->channel[1].weight_factor_a); |
| 1609 | state_save_register_global_array(machine, mcd212->channel[1].weight_factor_b); |
| 1610 | } |
| 1611 | |
| 1612 | void mcd212_ab_init(mcd212_ab_t *mcd212_ab) |
| 1613 | { |
| 1614 | WORD68K w = 0; |
| 1615 | SWORD68K sw = 0; |
| 1616 | WORD68K d = 0; |
| 1617 | |
| 1618 | //* Delta decoding array. |
| 1619 | static const BYTE68K mcd212_abDelta[16] = { 0, 1, 4, 9, 16, 27, 44, 79, 128, 177, 212, 229, 240, 247, 252, 255 }; |
| 1620 | |
| 1621 | // Initialize delta decoding arrays for each unsigned byte value b. |
| 1622 | for (d = 0; d < BYTE68K_MAX + 1; d++) |
| 1623 | { |
| 1624 | mcd212_ab->deltaY[d] = mcd212_abDelta[d & 15]; |
| 1625 | } |
| 1626 | |
| 1627 | // Initialize delta decoding arrays for each unsigned byte value b. |
| 1628 | for (d = 0; d < (BYTE68K_MAX + 1); d++) |
| 1629 | { |
| 1630 | mcd212_ab->deltaUV[d] = mcd212_abDelta[d >> 4]; |
| 1631 | } |
| 1632 | |
| 1633 | // Initialize color limit and clamp arrays. |
| 1634 | for (w = 0; w < 3 * BYTE68K_MAX; w++) |
| 1635 | { |
| 1636 | mcd212_ab->limit[w] = (w < BYTE68K_MAX + 16) ? 0 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX; |
| 1637 | mcd212_ab->clamp[w] = (w < BYTE68K_MAX + 32) ? 16 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX; |
| 1638 | } |
| 1639 | |
| 1640 | for (sw = 0; sw < 0x100; sw++) |
| 1641 | { |
| 1642 | mcd212_ab->matrixUB[sw] = (444 * (sw - 128)) / 256; |
| 1643 | mcd212_ab->matrixUG[sw] = - (86 * (sw - 128)) / 256; |
| 1644 | mcd212_ab->matrixVG[sw] = - (179 * (sw - 128)) / 256; |
| 1645 | mcd212_ab->matrixVR[sw] = (351 * (sw - 128)) / 256; |
| 1646 | } |
| 1647 | } |
| 1648 | |
| 1649 | VIDEO_START( cdimono1 ) |
| 1650 | { |
| 1651 | cdi_state *state = machine->driver_data<cdi_state>(); |
| 1652 | |
| 1653 | VIDEO_START_CALL(generic_bitmapped); |
| 1654 | mcd212_ab_init(&state->mcd212_ab); |
| 1655 | mcd212_init(machine, &state->mcd212_regs); |
| 1656 | state->mcd212_regs.scan_timer = timer_alloc(machine, mcd212_perform_scan, 0); |
| 1657 | timer_adjust_oneshot(state->mcd212_regs.scan_timer, machine->primary_screen->time_until_pos(0, 0), 0); |
| 1658 | |
| 1659 | state->lcdbitmap = downcast<screen_device *>(machine->device("lcd"))->alloc_compatible_bitmap(); |
| 1660 | } |
| 1661 | |
| 1662 | VIDEO_UPDATE( cdimono1 ) |
| 1663 | { |
| 1664 | cdi_state *state = screen->machine->driver_data<cdi_state>(); |
| 1665 | running_device *main_screen = screen->machine->device("screen"); |
| 1666 | running_device *lcd_screen = screen->machine->device("lcd"); |
| 1667 | |
| 1668 | if (screen == main_screen) |
| 1669 | { |
| 1670 | copybitmap(bitmap, screen->machine->generic.tmpbitmap, 0, 0, 0, 0, cliprect); |
| 1671 | } |
| 1672 | else if (screen == lcd_screen) |
| 1673 | { |
| 1674 | copybitmap(bitmap, state->lcdbitmap, 0, 0, 0, 0, cliprect); |
| 1675 | } |
| 1676 | |
| 1677 | return 0; |
| 1678 | } |
src/mess/drivers/cdi.c
| r8789 | r8790 | |
| 23 | 23 | |
| 24 | 24 | *******************************************************************************/ |
| 25 | 25 | |
| 26 | | #define CLOCK_A XTAL_30MHz |
| 27 | | #define CLOCK_B XTAL_19_6608MHz |
| 28 | | |
| 29 | 26 | #include "emu.h" |
| 30 | 27 | #include "cpu/m68000/m68000.h" |
| 31 | 28 | #include "sound/dmadac.h" |
| 32 | 29 | #include "devices/chd_cd.h" |
| 33 | 30 | #include "machine/timekpr.h" |
| 34 | 31 | #include "sound/cdda.h" |
| 32 | #include "includes/cdi.h" |
| 35 | 33 | #include "cdi.lh" |
| 36 | 34 | |
| 37 | | #define ENABLE_UART_PRINTING (0) |
| 38 | | |
| 39 | | #define VERBOSE_LEVEL (5) |
| 40 | | |
| 41 | | #define ENABLE_VERBOSE_LOG (1) |
| 42 | | |
| 43 | 35 | #if ENABLE_VERBOSE_LOG |
| 44 | 36 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| 45 | 37 | { |
| 46 | | if( VERBOSE_LEVEL >= n_level ) |
| 47 | | { |
| 48 | | va_list v; |
| 49 | | char buf[ 32768 ]; |
| 50 | | va_start( v, s_fmt ); |
| 51 | | vsprintf( buf, s_fmt, v ); |
| 52 | | va_end( v ); |
| 53 | | logerror( "%08x: %s", cpu_get_pc(machine->device("maincpu")), buf ); |
| 54 | | } |
| 38 | if( VERBOSE_LEVEL >= n_level ) |
| 39 | { |
| 40 | va_list v; |
| 41 | char buf[ 32768 ]; |
| 42 | va_start( v, s_fmt ); |
| 43 | vsprintf( buf, s_fmt, v ); |
| 44 | va_end( v ); |
| 45 | logerror( "%08x: %s", cpu_get_pc(machine->device("maincpu")), buf ); |
| 46 | } |
| 55 | 47 | } |
| 56 | 48 | #else |
| 57 | 49 | #define verboselog(x,y,z,...) |
| 58 | 50 | #endif |
| 59 | 51 | |
| 60 | | /*********************** |
| 61 | | * Forward declarations * |
| 62 | | ***********************/ |
| 63 | | |
| 64 | | // SCC68070 |
| 65 | | //static void scc68070_set_timer_callback(int channel); |
| 66 | | //static TIMER_CALLBACK( scc68070_timer0_callback ); |
| 67 | | //static READ16_HANDLER( scc68070_periphs_r ); |
| 68 | | //static WRITE16_HANDLER( scc68070_periphs_w ); |
| 69 | | |
| 70 | | // CDIC |
| 71 | | //static READ16_HANDLER( cdic_r ); |
| 72 | | //static WRITE16_HANDLER( cdic_w ); |
| 73 | | |
| 74 | | // SLAVE |
| 75 | | //static TIMER_CALLBACK( slave_trigger_readback_int ); |
| 76 | | //static void slave_prepare_readback(running_machine *machine, attotime delay, UINT8 channel, UINT8 count, UINT8 data0, UINT8 data1, UINT8 data2, UINT8 data3, UINT8 cmd); |
| 77 | | //static void perform_mouse_update(running_machine *machine); |
| 78 | | //static INPUT_CHANGED( mouse_update ); |
| 79 | | //static READ16_HANDLER( slave_r ); |
| 80 | | //static WRITE16_HANDLER( slave_w ); |
| 81 | | |
| 82 | | // Platform-specific |
| 83 | | //static void cdi220_draw_lcd(running_machine *machine, int y); |
| 84 | | |
| 85 | | // MCD212 |
| 86 | | //static READ16_HANDLER(mcd212_r); |
| 87 | | //static WRITE16_HANDLER(mcd212_w); |
| 88 | | //static void mcd212_set_register(running_machine *machine, int channel, UINT8 reg, UINT32 value); |
| 89 | | //static void mcd212_set_vsr(int channel, UINT32 value); |
| 90 | | //static UINT32 mcd212_get_vsr(int channel); |
| 91 | | //static void mcd212_set_dcp(int channel, UINT32 value); |
| 92 | | //static UINT32 mcd212_get_dcp(int channel); |
| 93 | | //static void mcd212_set_display_parameters(int channel, UINT8 value); |
| 94 | | //static void mcd212_process_ica(running_machine *machine, int channel); |
| 95 | | //static void mcd212_process_dca(running_machine *machine, int channel); |
| 96 | | static void mcd212_update_region_arrays(running_machine *machine); |
| 97 | | //static void mcd212_process_vsr(running_machine *machine, int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b); |
| 98 | | //static void mcd212_draw_cursor(running_machine *machine, UINT32 *scanline, int y); |
| 99 | | //static void mcd212_mix_lines(running_machine *machine, UINT8 *plane_a_r, UINT8 *plane_a_g, UINT8 *plane_a_b, UINT8 *plane_b_r, UINT8 *plane_b_g, UINT8 *plane_b_b, UINT32 *out); |
| 100 | | //static void mcd212_draw_scanline(running_machine *machine, int y); |
| 101 | | //static TIMER_CALLBACK( mcd212_perform_scan ); |
| 102 | | //static VIDEO_START(cdi); |
| 103 | | //static VIDEO_UPDATE(cdi); |
| 104 | | |
| 105 | | // Miscellaneous |
| 106 | | //static TIMER_CALLBACK( test_timer_callback ); |
| 107 | | |
| 108 | | /*********************** |
| 109 | | * On-board peripherals * |
| 110 | | ***********************/ |
| 111 | | |
| 112 | | typedef struct |
| 113 | | { |
| 114 | | UINT8 reserved0; |
| 115 | | UINT8 data_register; |
| 116 | | UINT8 reserved1; |
| 117 | | UINT8 address_register; |
| 118 | | UINT8 reserved2; |
| 119 | | UINT8 status_register; |
| 120 | | UINT8 reserved3; |
| 121 | | UINT8 control_register; |
| 122 | | UINT8 reserved; |
| 123 | | UINT8 clock_control_register; |
| 124 | | } scc68070_i2c_regs_t; |
| 125 | | |
| 126 | | #define ISR_MST 0x80 // Master |
| 127 | | #define ISR_TRX 0x40 // Transmitter |
| 128 | | #define ISR_BB 0x20 // Busy |
| 129 | | #define ISR_PIN 0x10 // No Pending Interrupt |
| 130 | | #define ISR_AL 0x08 // Arbitration Lost |
| 131 | | #define ISR_AAS 0x04 // Addressed As Slave |
| 132 | | #define ISR_AD0 0x02 // Address Zero |
| 133 | | #define ISR_LRB 0x01 // Last Received Bit |
| 134 | | |
| 135 | | typedef struct |
| 136 | | { |
| 137 | | UINT8 reserved0; |
| 138 | | UINT8 mode_register; |
| 139 | | UINT8 reserved1; |
| 140 | | UINT8 status_register; |
| 141 | | UINT8 reserved2; |
| 142 | | UINT8 clock_select; |
| 143 | | UINT8 reserved3; |
| 144 | | UINT8 command_register; |
| 145 | | UINT8 reserved4; |
| 146 | | UINT8 transmit_holding_register; |
| 147 | | UINT8 reserved5; |
| 148 | | UINT8 receive_holding_register; |
| 149 | | } scc68070_uart_regs_t; |
| 150 | | |
| 151 | | #define UMR_OM 0xc0 |
| 152 | | #define UMR_OM_NORMAL 0x00 |
| 153 | | #define UMR_OM_ECHO 0x40 |
| 154 | | #define UMR_OM_LOOPBACK 0x80 |
| 155 | | #define UMR_OM_RLOOP 0xc0 |
| 156 | | #define UMR_TXC 0x10 |
| 157 | | #define UMR_PC 0x08 |
| 158 | | #define UMR_P 0x04 |
| 159 | | #define UMR_SB 0x02 |
| 160 | | #define UMR_CL 0x01 |
| 161 | | |
| 162 | | #define USR_RB 0x80 |
| 163 | | #define USR_FE 0x40 |
| 164 | | #define USR_PE 0x20 |
| 165 | | #define USR_OE 0x10 |
| 166 | | #define USR_TXEMT 0x08 |
| 167 | | #define USR_TXRDY 0x04 |
| 168 | | #define USR_RXRDY 0x01 |
| 169 | | |
| 170 | | typedef struct |
| 171 | | { |
| 172 | | UINT8 timer_status_register; |
| 173 | | UINT8 timer_control_register; |
| 174 | | UINT16 reload_register; |
| 175 | | UINT16 timer0; |
| 176 | | UINT16 timer1; |
| 177 | | UINT16 timer2; |
| 178 | | emu_timer* timer0_timer; |
| 179 | | } scc68070_timer_regs_t; |
| 180 | | |
| 181 | | #define TSR_OV0 0x80 |
| 182 | | #define TSR_MA1 0x40 |
| 183 | | #define TSR_CAP1 0x20 |
| 184 | | #define TSR_OV1 0x10 |
| 185 | | #define TSR_MA2 0x08 |
| 186 | | #define TSR_CAP2 0x04 |
| 187 | | #define TSR_OV2 0x02 |
| 188 | | |
| 189 | | #define TCR_E1 0xc0 |
| 190 | | #define TCR_E1_NONE 0x00 |
| 191 | | #define TCR_E1_RISING 0x40 |
| 192 | | #define TCR_E1_FALLING 0x80 |
| 193 | | #define TCR_E1_BOTH 0xc0 |
| 194 | | #define TCR_M1 0x30 |
| 195 | | #define TCR_M1_NONE 0x00 |
| 196 | | #define TCR_M1_MATCH 0x10 |
| 197 | | #define TCR_M1_CAPTURE 0x20 |
| 198 | | #define TCR_M1_COUNT 0x30 |
| 199 | | #define TCR_E2 0x0c |
| 200 | | #define TCR_E2_NONE 0x00 |
| 201 | | #define TCR_E2_RISING 0x04 |
| 202 | | #define TCR_E2_FALLING 0x08 |
| 203 | | #define TCR_E2_BOTH 0x0c |
| 204 | | #define TCR_M2 0x03 |
| 205 | | #define TCR_M2_NONE 0x00 |
| 206 | | #define TCR_M2_MATCH 0x01 |
| 207 | | #define TCR_M2_CAPTURE 0x02 |
| 208 | | #define TCR_M2_COUNT 0x03 |
| 209 | | |
| 210 | | typedef struct |
| 211 | | { |
| 212 | | UINT8 channel_status; |
| 213 | | UINT8 channel_error; |
| 214 | | |
| 215 | | UINT8 reserved0[2]; |
| 216 | | |
| 217 | | UINT8 device_control; |
| 218 | | UINT8 operation_control; |
| 219 | | UINT8 sequence_control; |
| 220 | | UINT8 channel_control; |
| 221 | | |
| 222 | | UINT8 reserved1[3]; |
| 223 | | |
| 224 | | UINT16 transfer_counter; |
| 225 | | |
| 226 | | UINT32 memory_address_counter; |
| 227 | | |
| 228 | | UINT8 reserved2[4]; |
| 229 | | |
| 230 | | UINT32 device_address_counter; |
| 231 | | |
| 232 | | UINT8 reserved3[40]; |
| 233 | | } scc68070_dma_channel_t; |
| 234 | | |
| 235 | | #define CSR_COC 0x80 |
| 236 | | #define CSR_NDT 0x20 |
| 237 | | #define CSR_ERR 0x10 |
| 238 | | #define CSR_CA 0x08 |
| 239 | | |
| 240 | | #define CER_EC 0x1f |
| 241 | | #define CER_NONE 0x00 |
| 242 | | #define CER_TIMING 0x02 |
| 243 | | #define CER_BUSERR_MEM 0x09 |
| 244 | | #define CER_BUSERR_DEV 0x0a |
| 245 | | #define CER_SOFT_ABORT 0x11 |
| 246 | | |
| 247 | | #define DCR1_ERM 0x80 |
| 248 | | #define DCR1_DT 0x30 |
| 249 | | |
| 250 | | #define DCR2_ERM 0x80 |
| 251 | | #define DCR2_DT 0x30 |
| 252 | | #define DCR2_DS 0x08 |
| 253 | | |
| 254 | | #define OCR_D 0x80 |
| 255 | | #define OCR_D_M2D 0x00 |
| 256 | | #define OCR_D_D2M 0x80 |
| 257 | | #define OCR_OS 0x30 |
| 258 | | #define OCR_OS_BYTE 0x00 |
| 259 | | #define OCR_OS_WORD 0x10 |
| 260 | | |
| 261 | | #define SCR2_MAC 0x0c |
| 262 | | #define SCR2_MAC_NONE 0x00 |
| 263 | | #define SCR2_MAC_INC 0x04 |
| 264 | | #define SCR2_DAC 0x03 |
| 265 | | #define SCR2_DAC_NONE 0x00 |
| 266 | | #define SCR2_DAC_INC 0x01 |
| 267 | | |
| 268 | | #define CCR_SO 0x80 |
| 269 | | #define CCR_SA 0x10 |
| 270 | | #define CCR_INE 0x08 |
| 271 | | #define CCR_IPL 0x07 |
| 272 | | |
| 273 | | typedef struct |
| 274 | | { |
| 275 | | scc68070_dma_channel_t channel[2]; |
| 276 | | } scc68070_dma_regs_t; |
| 277 | | |
| 278 | | typedef struct |
| 279 | | { |
| 280 | | UINT16 attr; |
| 281 | | UINT16 length; |
| 282 | | UINT8 undefined; |
| 283 | | UINT8 segment; |
| 284 | | UINT16 base; |
| 285 | | } scc68070_mmu_desc_t; |
| 286 | | |
| 287 | | typedef struct |
| 288 | | { |
| 289 | | UINT8 status; |
| 290 | | UINT8 control; |
| 291 | | |
| 292 | | UINT8 reserved[0x3e]; |
| 293 | | |
| 294 | | scc68070_mmu_desc_t desc[8]; |
| 295 | | } scc68070_mmu_regs_t; |
| 296 | | |
| 297 | | typedef struct |
| 298 | | { |
| 299 | | UINT16 lir; |
| 300 | | UINT8 picr1; |
| 301 | | UINT8 picr2; |
| 302 | | |
| 303 | | scc68070_i2c_regs_t i2c; |
| 304 | | scc68070_uart_regs_t uart; |
| 305 | | scc68070_timer_regs_t timers; |
| 306 | | scc68070_dma_regs_t dma; |
| 307 | | scc68070_mmu_regs_t mmu; |
| 308 | | } scc68070_regs_t; |
| 309 | | |
| 310 | | #define CDIC_BUFFERED_SECTORS 2 |
| 311 | | |
| 312 | | typedef struct |
| 313 | | { |
| 314 | | UINT16 command; // CDIC Command Register (0x303c00) |
| 315 | | UINT32 time; // CDIC Time Register (0x303c02) |
| 316 | | UINT16 file; // CDIC File Register (0x303c06) |
| 317 | | UINT32 channel; // CDIC Channel Register (0x303c08) |
| 318 | | UINT16 audio_channel; // CDIC Audio Channel Register (0x303c0c) |
| 319 | | |
| 320 | | UINT16 audio_buffer; // CDIC Audio Buffer Register (0x303ff4) |
| 321 | | UINT16 x_buffer; // CDIC X-Buffer Register (0x303ff6) |
| 322 | | UINT16 dma_control; // CDIC DMA Control Register (0x303ff8) |
| 323 | | UINT16 z_buffer; // CDIC Z-Buffer Register (0x303ffa) |
| 324 | | UINT16 interrupt_vector; // CDIC Interrupt Vector Register (0x303ffc) |
| 325 | | UINT16 data_buffer; // CDIC Data Buffer Register (0x303ffe) |
| 326 | | |
| 327 | | emu_timer *interrupt_timer; |
| 328 | | cdrom_file *cd; |
| 329 | | |
| 330 | | emu_timer *audio_sample_timer; |
| 331 | | INT32 audio_sample_freq; |
| 332 | | INT32 audio_sample_size; |
| 333 | | |
| 334 | | UINT16 decode_addr; |
| 335 | | UINT8 decode_delay; |
| 336 | | attotime decode_period; |
| 337 | | |
| 338 | | int xa_last[4]; |
| 339 | | UINT16 *ram; |
| 340 | | } cdic_regs_t; |
| 341 | | |
| 342 | | #define CDIC_SECTOR_SYNC 0 |
| 343 | | |
| 344 | | #define CDIC_SECTOR_HEADER 12 |
| 345 | | |
| 346 | | #define CDIC_SECTOR_MODE 15 |
| 347 | | |
| 348 | | #define CDIC_SECTOR_FILE1 16 |
| 349 | | #define CDIC_SECTOR_CHAN1 17 |
| 350 | | #define CDIC_SECTOR_SUBMODE1 18 |
| 351 | | #define CDIC_SECTOR_CODING1 19 |
| 352 | | |
| 353 | | #define CDIC_SECTOR_FILE2 20 |
| 354 | | #define CDIC_SECTOR_CHAN2 21 |
| 355 | | #define CDIC_SECTOR_SUBMODE2 22 |
| 356 | | #define CDIC_SECTOR_CODING2 23 |
| 357 | | |
| 358 | | #define CDIC_SECTOR_DATA 24 |
| 359 | | |
| 360 | | #define CDIC_SECTOR_SIZE 2352 |
| 361 | | |
| 362 | | #define CDIC_SECTOR_DATASIZE 2048 |
| 363 | | #define CDIC_SECTOR_AUDIOSIZE 2304 |
| 364 | | #define CDIC_SECTOR_VIDEOSIZE 2324 |
| 365 | | |
| 366 | | #define CDIC_SUBMODE_EOF 0x80 |
| 367 | | #define CDIC_SUBMODE_RT 0x40 |
| 368 | | #define CDIC_SUBMODE_FORM 0x20 |
| 369 | | #define CDIC_SUBMODE_TRIG 0x10 |
| 370 | | #define CDIC_SUBMODE_DATA 0x08 |
| 371 | | #define CDIC_SUBMODE_AUDIO 0x04 |
| 372 | | #define CDIC_SUBMODE_VIDEO 0x02 |
| 373 | | #define CDIC_SUBMODE_EOR 0x01 |
| 374 | | |
| 375 | | typedef struct |
| 376 | | { |
| 377 | | UINT8 out_buf[4]; |
| 378 | | UINT8 out_index; |
| 379 | | UINT8 out_count; |
| 380 | | UINT8 out_cmd; |
| 381 | | } slave_channel_t; |
| 382 | | |
| 383 | | typedef struct |
| 384 | | { |
| 385 | | slave_channel_t channel[4]; |
| 386 | | emu_timer *interrupt_timer; |
| 387 | | |
| 388 | | UINT8 in_buf[17]; |
| 389 | | UINT8 in_index; |
| 390 | | UINT8 in_count; |
| 391 | | |
| 392 | | UINT8 polling_active; |
| 393 | | |
| 394 | | UINT8 xbus_interrupt_enable; |
| 395 | | |
| 396 | | UINT8 lcd_state[16]; |
| 397 | | |
| 398 | | UINT16 real_mouse_x; |
| 399 | | UINT16 real_mouse_y; |
| 400 | | |
| 401 | | UINT16 fake_mouse_x; |
| 402 | | UINT16 fake_mouse_y; |
| 403 | | } slave_regs_t; |
| 404 | | |
| 405 | | |
| 406 | | typedef struct |
| 407 | | { |
| 408 | | UINT8 csrr; |
| 409 | | UINT16 csrw; |
| 410 | | UINT16 dcr; |
| 411 | | UINT16 vsr; |
| 412 | | UINT16 ddr; |
| 413 | | UINT16 dcp; |
| 414 | | UINT32 dca; |
| 415 | | UINT8 clut_r[256]; |
| 416 | | UINT8 clut_g[256]; |
| 417 | | UINT8 clut_b[256]; |
| 418 | | UINT32 image_coding_method; |
| 419 | | UINT32 transparency_control; |
| 420 | | UINT32 plane_order; |
| 421 | | UINT32 clut_bank; |
| 422 | | UINT32 transparent_color_a; |
| 423 | | UINT32 reserved0; |
| 424 | | UINT32 transparent_color_b; |
| 425 | | UINT32 mask_color_a; |
| 426 | | UINT32 reserved1; |
| 427 | | UINT32 mask_color_b; |
| 428 | | UINT32 dyuv_abs_start_a; |
| 429 | | UINT32 dyuv_abs_start_b; |
| 430 | | UINT32 reserved2; |
| 431 | | UINT32 cursor_position; |
| 432 | | UINT32 cursor_control; |
| 433 | | UINT32 cursor_pattern[16]; |
| 434 | | UINT32 region_control[8]; |
| 435 | | UINT32 backdrop_color; |
| 436 | | UINT32 mosaic_hold_a; |
| 437 | | UINT32 mosaic_hold_b; |
| 438 | | UINT8 weight_factor_a[768]; |
| 439 | | UINT8 weight_factor_b[768]; |
| 440 | | } mcd212_channel_t; |
| 441 | | |
| 442 | | typedef struct |
| 443 | | { |
| 444 | | mcd212_channel_t channel[2]; |
| 445 | | emu_timer *scan_timer; |
| 446 | | UINT8 region_flag_0[768]; |
| 447 | | UINT8 region_flag_1[768]; |
| 448 | | } mcd212_regs_t; |
| 449 | | |
| 450 | | #define MCD212_CURCNT_COLOR 0x00000f // Cursor color |
| 451 | | #define MCD212_CURCNT_CUW 0x008000 // Cursor width |
| 452 | | #define MCD212_CURCNT_COF 0x070000 // Cursor off time |
| 453 | | #define MCD212_CURCNT_COF_SHIFT 16 |
| 454 | | #define MCD212_CURCNT_CON 0x280000 // Cursor on time |
| 455 | | #define MCD212_CURCNT_CON_SHIFT 19 |
| 456 | | #define MCD212_CURCNT_BLKC 0x400000 // Blink type |
| 457 | | #define MCD212_CURCNT_EN 0x800000 // Cursor enable |
| 458 | | |
| 459 | | #define MCD212_ICM_CS 0x400000 // CLUT select |
| 460 | | #define MCD212_ICM_NR 0x080000 // Number of region flags |
| 461 | | #define MCD212_ICM_EV 0x040000 // External video |
| 462 | | #define MCD212_ICM_MODE2 0x000f00 // Plane 2 |
| 463 | | #define MCD212_ICM_MODE2_SHIFT 8 |
| 464 | | #define MCD212_ICM_MODE1 0x00000f // Plane 1 |
| 465 | | #define MCD212_ICM_MODE1_SHIFT 0 |
| 466 | | |
| 467 | | #define MCD212_TCR_DISABLE_MX 0x800000 // Mix disable |
| 468 | | #define MCD212_TCR_TB 0x000f00 // Plane B |
| 469 | | #define MCD212_TCR_TB_SHIFT 8 |
| 470 | | #define MCD212_TCR_TA 0x00000f // Plane A |
| 471 | | #define MCD212_TCR_COND_1 0x0 // Transparent if: Always (Plane Disabled) |
| 472 | | #define MCD212_TCR_COND_KEY_1 0x1 // Transparent if: Color Key = True |
| 473 | | #define MCD212_TCR_COND_XLU_1 0x2 // Transparent if: Transparency Bit = 1 |
| 474 | | #define MCD212_TCR_COND_RF0_1 0x3 // Transparent if: Region Flag 0 = True |
| 475 | | #define MCD212_TCR_COND_RF1_1 0x4 // Transparent if: Region Flag 1 = True |
| 476 | | #define MCD212_TCR_COND_RF0KEY_1 0x5 // Transparent if: Region Flag 0 = True || Color Key = True |
| 477 | | #define MCD212_TCR_COND_RF1KEY_1 0x6 // Transparent if: Region Flag 1 = True || Color Key = True |
| 478 | | #define MCD212_TCR_COND_UNUSED0 0x7 // Unused |
| 479 | | #define MCD212_TCR_COND_0 0x8 // Transparent if: Never (No Transparent Area) |
| 480 | | #define MCD212_TCR_COND_KEY_0 0x9 // Transparent if: Color Key = False |
| 481 | | #define MCD212_TCR_COND_XLU_0 0xa // Transparent if: Transparency Bit = 0 |
| 482 | | #define MCD212_TCR_COND_RF0_0 0xb // Transparent if: Region Flag 0 = False |
| 483 | | #define MCD212_TCR_COND_RF1_0 0xc // Transparent if: Region Flag 1 = False |
| 484 | | #define MCD212_TCR_COND_RF0KEY_0 0xd // Transparent if: Region Flag 0 = False && Color Key = False |
| 485 | | #define MCD212_TCR_COND_RF1KEY_0 0xe // Transparent if: Region Flag 1 = False && Color Key = False |
| 486 | | #define MCD212_TCR_COND_UNUSED1 0xf // Unused |
| 487 | | |
| 488 | | #define MCD212_POR_AB 0 // Plane A in front of Plane B |
| 489 | | #define MCD212_POR_BA 1 // Plane B in front of Plane A |
| 490 | | |
| 491 | | #define MCD212_RC_X 0x0003ff // X position |
| 492 | | #define MCD212_RC_WF 0x00fc00 // Weight position |
| 493 | | #define MCD212_RC_WF_SHIFT 10 |
| 494 | | #define MCD212_RC_RF 0x010000 // Region flag |
| 495 | | #define MCD212_RC_RF_SHIFT 16 |
| 496 | | #define MCD212_RC_OP 0xf00000 // Operation |
| 497 | | #define MCD212_RC_OP_SHIFT 20 |
| 498 | | |
| 499 | | #define MCD212_CSR1W_ST 0x0002 // Standard |
| 500 | | #define MCD212_CSR1W_BE 0x0001 // Bus Error |
| 501 | | |
| 502 | | #define MCD212_CSR2R_IT1 0x0004 // Interrupt 1 |
| 503 | | #define MCD212_CSR2R_IT2 0x0002 // Interrupt 2 |
| 504 | | #define MCD212_CSR2R_BE 0x0001 // Bus Error |
| 505 | | |
| 506 | | #define MCD212_DCR_DE 0x8000 // Display Enable |
| 507 | | #define MCD212_DCR_CF 0x4000 // Crystal Frequency |
| 508 | | #define MCD212_DCR_FD 0x2000 // Frame Duration |
| 509 | | #define MCD212_DCR_SM 0x1000 // Scan Mode |
| 510 | | #define MCD212_DCR_CM 0x0800 // Color Mode Ch.1/2 |
| 511 | | #define MCD212_DCR_ICA 0x0200 // ICA Enable Ch.1/2 |
| 512 | | #define MCD212_DCR_DCA 0x0100 // DCA Enable Ch.1/2 |
| 513 | | |
| 514 | | #define MCD212_DDR_FT 0x0300 // Display File Type |
| 515 | | #define MCD212_DDR_FT_BMP 0x0000 // Bitmap |
| 516 | | #define MCD212_DDR_FT_BMP2 0x0100 // Bitmap (alt.) |
| 517 | | #define MCD212_DDR_FT_RLE 0x0200 // Run-Length Encoded |
| 518 | | #define MCD212_DDR_FT_MOSAIC 0x0300 // Mosaic |
| 519 | | #define MCD212_DDR_MT 0x0c00 // Mosaic File Type |
| 520 | | #define MCD212_DDR_MT_2 0x0000 // 2x1 |
| 521 | | #define MCD212_DDR_MT_4 0x0400 // 4x1 |
| 522 | | #define MCD212_DDR_MT_8 0x0800 // 8x1 |
| 523 | | #define MCD212_DDR_MT_16 0x0c00 // 16x1 |
| 524 | | #define MCD212_DDR_MT_SHIFT 10 |
| 525 | | |
| 526 | | typedef UINT8 BYTE68K; |
| 527 | | typedef UINT16 WORD68K; |
| 528 | | typedef INT16 SWORD68K; |
| 529 | | |
| 530 | | #define BYTE68K_MAX 255 |
| 531 | | |
| 532 | | |
| 533 | | |
| 534 | | typedef struct _mcd212_ab_t mcd212_ab_t; |
| 535 | | struct _mcd212_ab_t |
| 536 | | { |
| 537 | | //* Color limit array. |
| 538 | | BYTE68K limit[3 * BYTE68K_MAX]; |
| 539 | | |
| 540 | | //* Color clamp array. |
| 541 | | BYTE68K clamp[3 * BYTE68K_MAX]; |
| 542 | | |
| 543 | | //* U-to-B matrix array. |
| 544 | | SWORD68K matrixUB[BYTE68K_MAX + 1]; |
| 545 | | |
| 546 | | //* U-to-G matrix array. |
| 547 | | SWORD68K matrixUG[BYTE68K_MAX + 1]; |
| 548 | | |
| 549 | | //* V-to-G matrix array. |
| 550 | | SWORD68K matrixVG[BYTE68K_MAX + 1]; |
| 551 | | |
| 552 | | //* V-to-R matrix array. |
| 553 | | SWORD68K matrixVR[BYTE68K_MAX + 1]; |
| 554 | | |
| 555 | | //* Delta-Y decoding array. |
| 556 | | BYTE68K deltaY[BYTE68K_MAX + 1]; |
| 557 | | |
| 558 | | //* Delta-U/V decoding array. |
| 559 | | BYTE68K deltaUV[BYTE68K_MAX + 1]; |
| 560 | | }; |
| 561 | | |
| 562 | | class cdi_state : public driver_data_t |
| 563 | | { |
| 564 | | public: |
| 565 | | static driver_data_t *alloc(running_machine &machine) { return auto_alloc_clear(&machine, cdi_state(machine)); } |
| 566 | | |
| 567 | | cdi_state(running_machine &machine) |
| 568 | | : driver_data_t(machine) { } |
| 569 | | |
| 570 | | UINT16 *planea; |
| 571 | | UINT16 *planeb; |
| 572 | | |
| 573 | | dmadac_sound_device *dmadac[2]; |
| 574 | | |
| 575 | | UINT8 timer_set; |
| 576 | | emu_timer *test_timer; |
| 577 | | bitmap_t* lcdbitmap; |
| 578 | | scc68070_regs_t scc68070_regs; |
| 579 | | cdic_regs_t cdic_regs; |
| 580 | | slave_regs_t slave_regs; |
| 581 | | mcd212_regs_t mcd212_regs; |
| 582 | | mcd212_ab_t mcd212_ab; |
| 583 | | }; |
| 584 | | |
| 585 | | static void scc68070_set_timer_callback(scc68070_regs_t *scc68070, int channel) |
| 586 | | { |
| 587 | | UINT32 compare = 0; |
| 588 | | attotime period; |
| 589 | | switch(channel) |
| 590 | | { |
| 591 | | case 0: |
| 592 | | compare = 0x10000 - scc68070->timers.timer0; |
| 593 | | period = attotime_mul(ATTOTIME_IN_HZ(CLOCK_A/192), compare); |
| 594 | | timer_adjust_oneshot(scc68070->timers.timer0_timer, period, 0); |
| 595 | | break; |
| 596 | | default: |
| 597 | | fatalerror( "Unsupported timer channel to scc68070_set_timer_callback!" ); |
| 598 | | } |
| 599 | | } |
| 600 | | |
| 601 | | static TIMER_CALLBACK( scc68070_timer0_callback ) |
| 602 | | { |
| 603 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 604 | | scc68070_regs_t *scc68070 = &state->scc68070_regs; |
| 605 | | |
| 606 | | scc68070->timers.timer0 = scc68070->timers.reload_register; |
| 607 | | scc68070->timers.timer_status_register |= TSR_OV0; |
| 608 | | if(scc68070->picr1 & 7) |
| 609 | | { |
| 610 | | UINT8 interrupt = scc68070->picr1 & 7; |
| 611 | | scc68070->timers.timer_status_register |= TSR_OV0; |
| 612 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_1 + (interrupt - 1), 56 + interrupt); |
| 613 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE); |
| 614 | | } |
| 615 | | scc68070_set_timer_callback(&state->scc68070_regs, 0); |
| 616 | | } |
| 617 | | |
| 618 | | static READ16_HANDLER( scc68070_periphs_r ) |
| 619 | | { |
| 620 | | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 621 | | scc68070_regs_t *scc68070 = &state->scc68070_regs; |
| 622 | | |
| 623 | | switch(offset) |
| 624 | | { |
| 625 | | // Interupts: 80001001 |
| 626 | | case 0x1000/2: // LIR priority level |
| 627 | | return scc68070->lir; |
| 628 | | |
| 629 | | // I2C interface: 80002001 to 80002009 |
| 630 | | case 0x2000/2: |
| 631 | | if(ACCESSING_BITS_0_7) |
| 632 | | { |
| 633 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Data Register: %04x & %04x\n", scc68070->i2c.data_register, mem_mask); |
| 634 | | } |
| 635 | | return scc68070->i2c.data_register; |
| 636 | | case 0x2002/2: |
| 637 | | if(ACCESSING_BITS_0_7) |
| 638 | | { |
| 639 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Address Register: %04x & %04x\n", scc68070->i2c.address_register, mem_mask); |
| 640 | | } |
| 641 | | return scc68070->i2c.address_register; |
| 642 | | case 0x2004/2: |
| 643 | | if(ACCESSING_BITS_0_7) |
| 644 | | { |
| 645 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Status Register: %04x & %04x\n", scc68070->i2c.status_register, mem_mask); |
| 646 | | } |
| 647 | | return scc68070->i2c.status_register; |
| 648 | | case 0x2006/2: |
| 649 | | if(ACCESSING_BITS_0_7) |
| 650 | | { |
| 651 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Control Register: %04x & %04x\n", scc68070->i2c.control_register, mem_mask); |
| 652 | | } |
| 653 | | return scc68070->i2c.control_register; |
| 654 | | case 0x2008/2: |
| 655 | | if(ACCESSING_BITS_0_7) |
| 656 | | { |
| 657 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Clock Control Register: %04x & %04x\n", scc68070->i2c.clock_control_register, mem_mask); |
| 658 | | } |
| 659 | | return scc68070->i2c.clock_control_register; |
| 660 | | |
| 661 | | // UART interface: 80002011 to 8000201b |
| 662 | | case 0x2010/2: |
| 663 | | if(ACCESSING_BITS_0_7) |
| 664 | | { |
| 665 | | verboselog(space->machine, 2, "scc68070_periphs_r: UART Mode Register: %04x & %04x\n", scc68070->uart.mode_register, mem_mask); |
| 666 | | } |
| 667 | | return scc68070->uart.mode_register | 0x20; |
| 668 | | case 0x2012/2: |
| 669 | | if(ACCESSING_BITS_0_7) |
| 670 | | { |
| 671 | | verboselog(space->machine, 2, "scc68070_periphs_r: UART Status Register: %04x & %04x\n", scc68070->uart.status_register, mem_mask); |
| 672 | | } |
| 673 | | return scc68070->uart.status_register /*| USR_TXEMT*/ | USR_TXRDY | (1 << 1) | USR_RXRDY; |
| 674 | | case 0x2014/2: |
| 675 | | if(ACCESSING_BITS_0_7) |
| 676 | | { |
| 677 | | verboselog(space->machine, 2, "scc68070_periphs_r: UART Clock Select: %04x & %04x\n", scc68070->uart.clock_select, mem_mask); |
| 678 | | } |
| 679 | | return scc68070->uart.clock_select | 0x08; |
| 680 | | case 0x2016/2: |
| 681 | | if(ACCESSING_BITS_0_7) |
| 682 | | { |
| 683 | | verboselog(space->machine, 2, "scc68070_periphs_r: UART Command Register: %02x & %04x\n", scc68070->uart.command_register, mem_mask); |
| 684 | | } |
| 685 | | return scc68070->uart.command_register | 0x80; |
| 686 | | case 0x2018/2: |
| 687 | | if(ACCESSING_BITS_0_7) |
| 688 | | { |
| 689 | | verboselog(space->machine, 2, "scc68070_periphs_r: UART Transmit Holding Register: %02x & %04x\n", scc68070->uart.transmit_holding_register, mem_mask); |
| 690 | | } |
| 691 | | return scc68070->uart.transmit_holding_register; |
| 692 | | case 0x201a/2: |
| 693 | | if(ACCESSING_BITS_0_7) |
| 694 | | { |
| 695 | | verboselog(space->machine, 2, "scc68070_periphs_r: UART Receive Holding Register: %02x & %04x\n", scc68070->uart.receive_holding_register, mem_mask); |
| 696 | | return scc68070->uart.receive_holding_register; |
| 697 | | } |
| 698 | | return 0; |
| 699 | | |
| 700 | | // Timers: 80002020 to 80002029 |
| 701 | | case 0x2020/2: |
| 702 | | if(ACCESSING_BITS_0_7) |
| 703 | | { |
| 704 | | verboselog(space->machine, 2, "scc68070_periphs_r: Timer Control Register: %02x & %04x\n", scc68070->timers.timer_control_register, mem_mask); |
| 705 | | } |
| 706 | | if(ACCESSING_BITS_8_15) |
| 707 | | { |
| 708 | | verboselog(space->machine, 12, "scc68070_periphs_r: Timer Status Register: %02x & %04x\n", scc68070->timers.timer_status_register, mem_mask); |
| 709 | | } |
| 710 | | return (scc68070->timers.timer_status_register << 8) | scc68070->timers.timer_control_register; |
| 711 | | case 0x2022/2: |
| 712 | | verboselog(space->machine, 2, "scc68070_periphs_r: Timer Reload Register: %04x & %04x\n", scc68070->timers.reload_register, mem_mask); |
| 713 | | return scc68070->timers.reload_register; |
| 714 | | case 0x2024/2: |
| 715 | | verboselog(space->machine, 2, "scc68070_periphs_r: Timer 0: %04x & %04x\n", scc68070->timers.timer0, mem_mask); |
| 716 | | return scc68070->timers.timer0; |
| 717 | | case 0x2026/2: |
| 718 | | verboselog(space->machine, 2, "scc68070_periphs_r: Timer 1: %04x & %04x\n", scc68070->timers.timer1, mem_mask); |
| 719 | | printf( "Timer 1 read\n" ); |
| 720 | | return scc68070->timers.timer1; |
| 721 | | case 0x2028/2: |
| 722 | | verboselog(space->machine, 2, "scc68070_periphs_r: Timer 2: %04x & %04x\n", scc68070->timers.timer2, mem_mask); |
| 723 | | printf( "Timer 2 read\n" ); |
| 724 | | return scc68070->timers.timer2; |
| 725 | | |
| 726 | | // PICR1: 80002045 |
| 727 | | case 0x2044/2: |
| 728 | | if(ACCESSING_BITS_0_7) |
| 729 | | { |
| 730 | | verboselog(space->machine, 2, "scc68070_periphs_r: Peripheral Interrupt Control Register 1: %02x & %04x\n", scc68070->picr1, mem_mask); |
| 731 | | } |
| 732 | | return scc68070->picr1; |
| 733 | | |
| 734 | | // PICR2: 80002047 |
| 735 | | case 0x2046/2: |
| 736 | | if(ACCESSING_BITS_0_7) |
| 737 | | { |
| 738 | | verboselog(space->machine, 2, "scc68070_periphs_r: Peripheral Interrupt Control Register 2: %02x & %04x\n", scc68070->picr2, mem_mask); |
| 739 | | } |
| 740 | | return scc68070->picr2; |
| 741 | | |
| 742 | | // DMA controller: 80004000 to 8000406d |
| 743 | | case 0x4000/2: |
| 744 | | case 0x4040/2: |
| 745 | | if(ACCESSING_BITS_0_7) |
| 746 | | { |
| 747 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Error Register: %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].channel_error, mem_mask); |
| 748 | | } |
| 749 | | if(ACCESSING_BITS_8_15) |
| 750 | | { |
| 751 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Status Register: %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].channel_status, mem_mask); |
| 752 | | } |
| 753 | | return (scc68070->dma.channel[(offset - 0x2000) / 32].channel_status << 8) | scc68070->dma.channel[(offset - 0x2000) / 32].channel_error; |
| 754 | | case 0x4004/2: |
| 755 | | case 0x4044/2: |
| 756 | | if(ACCESSING_BITS_0_7) |
| 757 | | { |
| 758 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Operation Control Register: %02x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].operation_control, mem_mask); |
| 759 | | } |
| 760 | | if(ACCESSING_BITS_8_15) |
| 761 | | { |
| 762 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Device Control Register: %02x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].device_control, mem_mask); |
| 763 | | } |
| 764 | | return (scc68070->dma.channel[(offset - 0x2000) / 32].device_control << 8) | scc68070->dma.channel[(offset - 0x2000) / 32].operation_control; |
| 765 | | case 0x4006/2: |
| 766 | | case 0x4046/2: |
| 767 | | if(ACCESSING_BITS_0_7) |
| 768 | | { |
| 769 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Channel Control Register: %02x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].channel_control, mem_mask); |
| 770 | | } |
| 771 | | if(ACCESSING_BITS_8_15) |
| 772 | | { |
| 773 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Sequence Control Register: %02x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].sequence_control, mem_mask); |
| 774 | | } |
| 775 | | return (scc68070->dma.channel[(offset - 0x2000) / 32].sequence_control << 8) | scc68070->dma.channel[(offset - 0x2000) / 32].channel_control; |
| 776 | | case 0x400a/2: |
| 777 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Memory Transfer Counter: %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].transfer_counter, mem_mask); |
| 778 | | return scc68070->dma.channel[(offset - 0x2000) / 32].transfer_counter; |
| 779 | | case 0x400c/2: |
| 780 | | case 0x404c/2: |
| 781 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Memory Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, (scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter >> 16), mem_mask); |
| 782 | | return (scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter >> 16); |
| 783 | | case 0x400e/2: |
| 784 | | case 0x404e/2: |
| 785 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Memory Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter, mem_mask); |
| 786 | | return scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter; |
| 787 | | case 0x4014/2: |
| 788 | | case 0x4054/2: |
| 789 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Device Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, (scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter >> 16), mem_mask); |
| 790 | | return (scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter >> 16); |
| 791 | | case 0x4016/2: |
| 792 | | case 0x4056/2: |
| 793 | | verboselog(space->machine, 2, "scc68070_periphs_r: DMA(%d) Device Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter, mem_mask); |
| 794 | | return scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter; |
| 795 | | |
| 796 | | // MMU: 80008000 to 8000807f |
| 797 | | case 0x8000/2: // Status / Control register |
| 798 | | if(ACCESSING_BITS_0_7) |
| 799 | | { // Control |
| 800 | | verboselog(space->machine, 2, "scc68070_periphs_r: MMU Control: %02x & %04x\n", scc68070->mmu.control, mem_mask); |
| 801 | | return scc68070->mmu.control; |
| 802 | | } // Status |
| 803 | | else |
| 804 | | { |
| 805 | | verboselog(space->machine, 2, "scc68070_periphs_r: MMU Status: %02x & %04x\n", scc68070->mmu.status, mem_mask); |
| 806 | | return scc68070->mmu.status; |
| 807 | | } |
| 808 | | break; |
| 809 | | case 0x8040/2: |
| 810 | | case 0x8048/2: |
| 811 | | case 0x8050/2: |
| 812 | | case 0x8058/2: |
| 813 | | case 0x8060/2: |
| 814 | | case 0x8068/2: |
| 815 | | case 0x8070/2: |
| 816 | | case 0x8078/2: // Attributes (SD0-7) |
| 817 | | verboselog(space->machine, 2, "scc68070_periphs_r: MMU descriptor %d attributes: %04x & %04x\n", (offset - 0x4020) / 4, scc68070->mmu.desc[(offset - 0x4020) / 4].attr, mem_mask); |
| 818 | | return scc68070->mmu.desc[(offset - 0x4020) / 4].attr; |
| 819 | | case 0x8042/2: |
| 820 | | case 0x804a/2: |
| 821 | | case 0x8052/2: |
| 822 | | case 0x805a/2: |
| 823 | | case 0x8062/2: |
| 824 | | case 0x806a/2: |
| 825 | | case 0x8072/2: |
| 826 | | case 0x807a/2: // Segment Length (SD0-7) |
| 827 | | verboselog(space->machine, 2, "scc68070_periphs_r: MMU descriptor %d length: %04x & %04x\n", (offset - 0x4020) / 4, scc68070->mmu.desc[(offset - 0x4020) / 4].length, mem_mask); |
| 828 | | return scc68070->mmu.desc[(offset - 0x4020) / 4].length; |
| 829 | | case 0x8044/2: |
| 830 | | case 0x804c/2: |
| 831 | | case 0x8054/2: |
| 832 | | case 0x805c/2: |
| 833 | | case 0x8064/2: |
| 834 | | case 0x806c/2: |
| 835 | | case 0x8074/2: |
| 836 | | case 0x807c/2: // Segment Number (SD0-7, A0=1 only) |
| 837 | | if(ACCESSING_BITS_0_7) |
| 838 | | { |
| 839 | | verboselog(space->machine, 2, "scc68070_periphs_r: MMU descriptor %d segment: %02x & %04x\n", (offset - 0x4020) / 4, scc68070->mmu.desc[(offset - 0x4020) / 4].segment, mem_mask); |
| 840 | | return scc68070->mmu.desc[(offset - 0x4020) / 4].segment; |
| 841 | | } |
| 842 | | break; |
| 843 | | case 0x8046/2: |
| 844 | | case 0x804e/2: |
| 845 | | case 0x8056/2: |
| 846 | | case 0x805e/2: |
| 847 | | case 0x8066/2: |
| 848 | | case 0x806e/2: |
| 849 | | case 0x8076/2: |
| 850 | | case 0x807e/2: // Base Address (SD0-7) |
| 851 | | verboselog(space->machine, 2, "scc68070_periphs_r: MMU descriptor %d base: %04x & %04x\n", (offset - 0x4020) / 4, scc68070->mmu.desc[(offset - 0x4020) / 4].base, mem_mask); |
| 852 | | return scc68070->mmu.desc[(offset - 0x4020) / 4].base; |
| 853 | | default: |
| 854 | | verboselog(space->machine, 0, "scc68070_periphs_r: Unknown address: %04x & %04x\n", offset * 2, mem_mask); |
| 855 | | break; |
| 856 | | } |
| 857 | | |
| 858 | | return 0; |
| 859 | | } |
| 860 | | |
| 861 | | static WRITE16_HANDLER( scc68070_periphs_w ) |
| 862 | | { |
| 863 | | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 864 | | scc68070_regs_t *scc68070 = &state->scc68070_regs; |
| 865 | | |
| 866 | | switch(offset) |
| 867 | | { |
| 868 | | // Interupts: 80001001 |
| 869 | | case 0x1000/2: // LIR priority level |
| 870 | | verboselog(space->machine, 2, "scc68070_periphs_w: LIR: %04x & %04x\n", data, mem_mask); |
| 871 | | COMBINE_DATA(&scc68070->lir); |
| 872 | | break; |
| 873 | | |
| 874 | | // I2C interface: 80002001 to 80002009 |
| 875 | | case 0x2000/2: |
| 876 | | if(ACCESSING_BITS_0_7) |
| 877 | | { |
| 878 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Data Register: %04x & %04x\n", data, mem_mask); |
| 879 | | scc68070->i2c.data_register = data & 0x00ff; |
| 880 | | } |
| 881 | | break; |
| 882 | | case 0x2002/2: |
| 883 | | if(ACCESSING_BITS_0_7) |
| 884 | | { |
| 885 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Address Register: %04x & %04x\n", data, mem_mask); |
| 886 | | scc68070->i2c.address_register = data & 0x00ff; |
| 887 | | } |
| 888 | | break; |
| 889 | | case 0x2004/2: |
| 890 | | if(ACCESSING_BITS_0_7) |
| 891 | | { |
| 892 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Status Register: %04x & %04x\n", data, mem_mask); |
| 893 | | scc68070->i2c.status_register = data & 0x00ff; |
| 894 | | } |
| 895 | | break; |
| 896 | | case 0x2006/2: |
| 897 | | if(ACCESSING_BITS_0_7) |
| 898 | | { |
| 899 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Control Register: %04x & %04x\n", data, mem_mask); |
| 900 | | scc68070->i2c.control_register = data & 0x00ff; |
| 901 | | } |
| 902 | | break; |
| 903 | | case 0x2008/2: |
| 904 | | if(ACCESSING_BITS_0_7) |
| 905 | | { |
| 906 | | verboselog(space->machine, 2, "scc68070_periphs_w: I2C Clock Control Register: %04x & %04x\n", data, mem_mask); |
| 907 | | scc68070->i2c.clock_control_register = data & 0x00ff; |
| 908 | | } |
| 909 | | break; |
| 910 | | |
| 911 | | // UART interface: 80002011 to 8000201b |
| 912 | | case 0x2010/2: |
| 913 | | if(ACCESSING_BITS_0_7) |
| 914 | | { |
| 915 | | verboselog(space->machine, 2, "scc68070_periphs_w: UART Mode Register: %04x & %04x\n", data, mem_mask); |
| 916 | | scc68070->uart.mode_register = data & 0x00ff; |
| 917 | | } |
| 918 | | break; |
| 919 | | case 0x2012/2: |
| 920 | | if(ACCESSING_BITS_0_7) |
| 921 | | { |
| 922 | | verboselog(space->machine, 2, "scc68070_periphs_w: UART Status Register: %04x & %04x\n", data, mem_mask); |
| 923 | | scc68070->uart.status_register = data & 0x00ff; |
| 924 | | } |
| 925 | | break; |
| 926 | | case 0x2014/2: |
| 927 | | if(ACCESSING_BITS_0_7) |
| 928 | | { |
| 929 | | verboselog(space->machine, 2, "scc68070_periphs_w: UART Clock Select: %04x & %04x\n", data, mem_mask); |
| 930 | | scc68070->uart.clock_select = data & 0x00ff; |
| 931 | | } |
| 932 | | break; |
| 933 | | case 0x2016/2: |
| 934 | | if(ACCESSING_BITS_0_7) |
| 935 | | { |
| 936 | | verboselog(space->machine, 2, "scc68070_periphs_w: UART Command Register: %04x & %04x\n", data, mem_mask); |
| 937 | | scc68070->uart.command_register = data & 0x00ff; |
| 938 | | } |
| 939 | | break; |
| 940 | | case 0x2018/2: |
| 941 | | if(ACCESSING_BITS_0_7) |
| 942 | | { |
| 943 | | verboselog(space->machine, 2, "scc68070_periphs_w: UART Transmit Holding Register: %04x & %04x: %c\n", data, mem_mask, (data >= 0x20 && data < 0x7f) ? (data & 0x00ff) : ' '); |
| 944 | | if((data >= 0x20 && data < 0x7f) || data == 0x08) |
| 945 | | { |
| 946 | | printf( "%c", data & 0x00ff ); |
| 947 | | } |
| 948 | | if(data == 0x0d) |
| 949 | | { |
| 950 | | printf( "\n" ); |
| 951 | | } |
| 952 | | scc68070->uart.transmit_holding_register = data & 0x00ff; |
| 953 | | } |
| 954 | | break; |
| 955 | | case 0x201a/2: |
| 956 | | if(ACCESSING_BITS_0_7) |
| 957 | | { |
| 958 | | verboselog(space->machine, 2, "scc68070_periphs_w: UART Receive Holding Register: %04x & %04x\n", data, mem_mask); |
| 959 | | scc68070->uart.receive_holding_register = data & 0x00ff; |
| 960 | | } |
| 961 | | break; |
| 962 | | |
| 963 | | // Timers: 80002020 to 80002029 |
| 964 | | case 0x2020/2: |
| 965 | | if(ACCESSING_BITS_0_7) |
| 966 | | { |
| 967 | | verboselog(space->machine, 2, "scc68070_periphs_w: Timer Control Register: %04x & %04x\n", data, mem_mask); |
| 968 | | scc68070->timers.timer_control_register = data & 0x00ff; |
| 969 | | } |
| 970 | | if(ACCESSING_BITS_8_15) |
| 971 | | { |
| 972 | | verboselog(space->machine, 12, "scc68070_periphs_w: Timer Status Register: %04x & %04x\n", data, mem_mask); |
| 973 | | scc68070->timers.timer_status_register &= ~(data >> 8); |
| 974 | | if(!scc68070->timers.timer_status_register) |
| 975 | | { |
| 976 | | UINT8 interrupt = scc68070->picr1 & 7; |
| 977 | | cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), CLEAR_LINE); |
| 978 | | } |
| 979 | | } |
| 980 | | break; |
| 981 | | case 0x2022/2: |
| 982 | | verboselog(space->machine, 2, "scc68070_periphs_w: Timer Reload Register: %04x & %04x\n", data, mem_mask); |
| 983 | | COMBINE_DATA(&scc68070->timers.reload_register); |
| 984 | | break; |
| 985 | | case 0x2024/2: |
| 986 | | verboselog(space->machine, 2, "scc68070_periphs_w: Timer 0: %04x & %04x\n", data, mem_mask); |
| 987 | | COMBINE_DATA(&scc68070->timers.timer0); |
| 988 | | scc68070_set_timer_callback(&state->scc68070_regs, 0); |
| 989 | | break; |
| 990 | | case 0x2026/2: |
| 991 | | verboselog(space->machine, 2, "scc68070_periphs_w: Timer 1: %04x & %04x\n", data, mem_mask); |
| 992 | | COMBINE_DATA(&scc68070->timers.timer1); |
| 993 | | printf( "Timer 1 write: %04x\n", data ); |
| 994 | | break; |
| 995 | | case 0x2028/2: |
| 996 | | verboselog(space->machine, 2, "scc68070_periphs_w: Timer 2: %04x & %04x\n", data, mem_mask); |
| 997 | | COMBINE_DATA(&scc68070->timers.timer2); |
| 998 | | printf( "Timer 2 write: %04x\n", data ); |
| 999 | | break; |
| 1000 | | |
| 1001 | | // PICR1: 80002045 |
| 1002 | | case 0x2044/2: |
| 1003 | | if(ACCESSING_BITS_0_7) |
| 1004 | | { |
| 1005 | | verboselog(space->machine, 2, "scc68070_periphs_w: Peripheral Interrupt Control Register 1: %04x & %04x\n", data, mem_mask); |
| 1006 | | scc68070->picr1 = data & 0x00ff; |
| 1007 | | } |
| 1008 | | break; |
| 1009 | | |
| 1010 | | // PICR2: 80002047 |
| 1011 | | case 0x2046/2: |
| 1012 | | if(ACCESSING_BITS_0_7) |
| 1013 | | { |
| 1014 | | verboselog(space->machine, 2, "scc68070_periphs_w: Peripheral Interrupt Control Register 2: %04x & %04x\n", data, mem_mask); |
| 1015 | | scc68070->picr2 = data & 0x00ff; |
| 1016 | | } |
| 1017 | | break; |
| 1018 | | |
| 1019 | | // DMA controller: 80004000 to 8000406d |
| 1020 | | case 0x4000/2: |
| 1021 | | case 0x4040/2: |
| 1022 | | if(ACCESSING_BITS_0_7) |
| 1023 | | { |
| 1024 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Error (invalid): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1025 | | } |
| 1026 | | if(ACCESSING_BITS_8_15) |
| 1027 | | { |
| 1028 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Status: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1029 | | scc68070->dma.channel[(offset - 0x2000) / 32].channel_status &= ~(data & 0xb0); |
| 1030 | | } |
| 1031 | | break; |
| 1032 | | case 0x4004/2: |
| 1033 | | case 0x4044/2: |
| 1034 | | if(ACCESSING_BITS_0_7) |
| 1035 | | { |
| 1036 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Operation Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1037 | | scc68070->dma.channel[(offset - 0x2000) / 32].operation_control = data & 0x00ff; |
| 1038 | | } |
| 1039 | | if(ACCESSING_BITS_8_15) |
| 1040 | | { |
| 1041 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Device Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1042 | | scc68070->dma.channel[(offset - 0x2000) / 32].device_control = data >> 8; |
| 1043 | | } |
| 1044 | | break; |
| 1045 | | case 0x4006/2: |
| 1046 | | case 0x4046/2: |
| 1047 | | if(ACCESSING_BITS_0_7) |
| 1048 | | { |
| 1049 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Channel Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1050 | | scc68070->dma.channel[(offset - 0x2000) / 32].channel_control = data & 0x007f; |
| 1051 | | if(data & CCR_SO) |
| 1052 | | { |
| 1053 | | scc68070->dma.channel[(offset - 0x2000) / 32].channel_status |= CSR_COC; |
| 1054 | | } |
| 1055 | | } |
| 1056 | | if(ACCESSING_BITS_8_15) |
| 1057 | | { |
| 1058 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Sequence Control Register: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1059 | | scc68070->dma.channel[(offset - 0x2000) / 32].sequence_control = data >> 8; |
| 1060 | | } |
| 1061 | | break; |
| 1062 | | case 0x400a/2: |
| 1063 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Memory Transfer Counter: %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1064 | | COMBINE_DATA(&scc68070->dma.channel[(offset - 0x2000) / 32].transfer_counter); |
| 1065 | | break; |
| 1066 | | case 0x400c/2: |
| 1067 | | case 0x404c/2: |
| 1068 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Memory Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1069 | | scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter &= ~(mem_mask << 16); |
| 1070 | | scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter |= data << 16; |
| 1071 | | break; |
| 1072 | | case 0x400e/2: |
| 1073 | | case 0x404e/2: |
| 1074 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Memory Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1075 | | scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter &= ~mem_mask; |
| 1076 | | scc68070->dma.channel[(offset - 0x2000) / 32].memory_address_counter |= data; |
| 1077 | | break; |
| 1078 | | case 0x4014/2: |
| 1079 | | case 0x4054/2: |
| 1080 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Device Address Counter (High Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1081 | | scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter &= ~(mem_mask << 16); |
| 1082 | | scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter |= data << 16; |
| 1083 | | break; |
| 1084 | | case 0x4016/2: |
| 1085 | | case 0x4056/2: |
| 1086 | | verboselog(space->machine, 2, "scc68070_periphs_w: DMA(%d) Device Address Counter (Low Word): %04x & %04x\n", (offset - 0x2000) / 32, data, mem_mask); |
| 1087 | | scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter &= ~mem_mask; |
| 1088 | | scc68070->dma.channel[(offset - 0x2000) / 32].device_address_counter |= data; |
| 1089 | | break; |
| 1090 | | |
| 1091 | | // MMU: 80008000 to 8000807f |
| 1092 | | case 0x8000/2: // Status / Control register |
| 1093 | | if(ACCESSING_BITS_0_7) |
| 1094 | | { // Control |
| 1095 | | verboselog(space->machine, 2, "scc68070_periphs_w: MMU Control: %04x & %04x\n", data, mem_mask); |
| 1096 | | scc68070->mmu.control = data & 0x00ff; |
| 1097 | | } // Status |
| 1098 | | else |
| 1099 | | { |
| 1100 | | verboselog(space->machine, 0, "scc68070_periphs_w: MMU Status (invalid): %04x & %04x\n", data, mem_mask); |
| 1101 | | } |
| 1102 | | break; |
| 1103 | | case 0x8040/2: |
| 1104 | | case 0x8048/2: |
| 1105 | | case 0x8050/2: |
| 1106 | | case 0x8058/2: |
| 1107 | | case 0x8060/2: |
| 1108 | | case 0x8068/2: |
| 1109 | | case 0x8070/2: |
| 1110 | | case 0x8078/2: // Attributes (SD0-7) |
| 1111 | | verboselog(space->machine, 2, "scc68070_periphs_w: MMU descriptor %d attributes: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask); |
| 1112 | | COMBINE_DATA(&scc68070->mmu.desc[(offset - 0x4020) / 4].attr); |
| 1113 | | break; |
| 1114 | | case 0x8042/2: |
| 1115 | | case 0x804a/2: |
| 1116 | | case 0x8052/2: |
| 1117 | | case 0x805a/2: |
| 1118 | | case 0x8062/2: |
| 1119 | | case 0x806a/2: |
| 1120 | | case 0x8072/2: |
| 1121 | | case 0x807a/2: // Segment Length (SD0-7) |
| 1122 | | verboselog(space->machine, 2, "scc68070_periphs_w: MMU descriptor %d length: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask); |
| 1123 | | COMBINE_DATA(&scc68070->mmu.desc[(offset - 0x4020) / 4].length); |
| 1124 | | break; |
| 1125 | | case 0x8044/2: |
| 1126 | | case 0x804c/2: |
| 1127 | | case 0x8054/2: |
| 1128 | | case 0x805c/2: |
| 1129 | | case 0x8064/2: |
| 1130 | | case 0x806c/2: |
| 1131 | | case 0x8074/2: |
| 1132 | | case 0x807c/2: // Segment Number (SD0-7, A0=1 only) |
| 1133 | | if(ACCESSING_BITS_0_7) |
| 1134 | | { |
| 1135 | | verboselog(space->machine, 2, "scc68070_periphs_w: MMU descriptor %d segment: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask); |
| 1136 | | scc68070->mmu.desc[(offset - 0x4020) / 4].segment = data & 0x00ff; |
| 1137 | | } |
| 1138 | | break; |
| 1139 | | case 0x8046/2: |
| 1140 | | case 0x804e/2: |
| 1141 | | case 0x8056/2: |
| 1142 | | case 0x805e/2: |
| 1143 | | case 0x8066/2: |
| 1144 | | case 0x806e/2: |
| 1145 | | case 0x8076/2: |
| 1146 | | case 0x807e/2: // Base Address (SD0-7) |
| 1147 | | verboselog(space->machine, 2, "scc68070_periphs_w: MMU descriptor %d base: %04x & %04x\n", (offset - 0x4020) / 4, data, mem_mask); |
| 1148 | | COMBINE_DATA(&scc68070->mmu.desc[(offset - 0x4020) / 4].base); |
| 1149 | | break; |
| 1150 | | default: |
| 1151 | | verboselog(space->machine, 0, "scc68070_periphs_w: Unknown address: %04x = %04x & %04x\n", offset * 2, data, mem_mask); |
| 1152 | | break; |
| 1153 | | } |
| 1154 | | } |
| 1155 | | |
| 1156 | | static void scc68070_init(running_machine *machine, scc68070_regs_t *scc68070) |
| 1157 | | { |
| 1158 | | int index = 0; |
| 1159 | | scc68070->lir = 0; |
| 1160 | | |
| 1161 | | scc68070->picr1 = 0; |
| 1162 | | scc68070->picr2 = 0; |
| 1163 | | |
| 1164 | | scc68070->i2c.data_register = 0; |
| 1165 | | scc68070->i2c.address_register = 0; |
| 1166 | | scc68070->i2c.status_register = 0; |
| 1167 | | scc68070->i2c.control_register = 0; |
| 1168 | | scc68070->i2c.clock_control_register = 0; |
| 1169 | | |
| 1170 | | scc68070->uart.mode_register = 0; |
| 1171 | | scc68070->uart.status_register = 0; |
| 1172 | | scc68070->uart.clock_select = 0; |
| 1173 | | scc68070->uart.command_register = 0; |
| 1174 | | scc68070->uart.transmit_holding_register = 0; |
| 1175 | | scc68070->uart.receive_holding_register = 0; |
| 1176 | | |
| 1177 | | scc68070->timers.timer_status_register = 0; |
| 1178 | | scc68070->timers.timer_control_register = 0; |
| 1179 | | scc68070->timers.reload_register = 0; |
| 1180 | | scc68070->timers.timer0 = 0; |
| 1181 | | scc68070->timers.timer1 = 0; |
| 1182 | | scc68070->timers.timer2 = 0; |
| 1183 | | |
| 1184 | | for(index = 0; index < 2; index++) |
| 1185 | | { |
| 1186 | | scc68070->dma.channel[index].channel_status = 0; |
| 1187 | | scc68070->dma.channel[index].channel_error = 0; |
| 1188 | | scc68070->dma.channel[index].device_control = 0; |
| 1189 | | scc68070->dma.channel[index].operation_control = 0; |
| 1190 | | scc68070->dma.channel[index].sequence_control = 0; |
| 1191 | | scc68070->dma.channel[index].channel_control = 0; |
| 1192 | | scc68070->dma.channel[index].transfer_counter = 0; |
| 1193 | | scc68070->dma.channel[index].memory_address_counter = 0; |
| 1194 | | scc68070->dma.channel[index].device_address_counter = 0; |
| 1195 | | } |
| 1196 | | |
| 1197 | | scc68070->mmu.status = 0; |
| 1198 | | scc68070->mmu.control = 0; |
| 1199 | | for(index = 0; index < 8; index++) |
| 1200 | | { |
| 1201 | | scc68070->mmu.desc[index].attr = 0; |
| 1202 | | scc68070->mmu.desc[index].length = 0; |
| 1203 | | scc68070->mmu.desc[index].segment = 0; |
| 1204 | | scc68070->mmu.desc[index].base = 0; |
| 1205 | | } |
| 1206 | | } |
| 1207 | | |
| 1208 | | static void scc68070_register_globals(running_machine *machine, scc68070_regs_t *scc68070) |
| 1209 | | { |
| 1210 | | state_save_register_global(machine, scc68070->lir); |
| 1211 | | |
| 1212 | | state_save_register_global(machine, scc68070->picr1); |
| 1213 | | state_save_register_global(machine, scc68070->picr2); |
| 1214 | | |
| 1215 | | state_save_register_global(machine, scc68070->i2c.data_register); |
| 1216 | | state_save_register_global(machine, scc68070->i2c.address_register); |
| 1217 | | state_save_register_global(machine, scc68070->i2c.status_register); |
| 1218 | | state_save_register_global(machine, scc68070->i2c.control_register); |
| 1219 | | state_save_register_global(machine, scc68070->i2c.clock_control_register); |
| 1220 | | |
| 1221 | | state_save_register_global(machine, scc68070->uart.mode_register); |
| 1222 | | state_save_register_global(machine, scc68070->uart.status_register); |
| 1223 | | state_save_register_global(machine, scc68070->uart.clock_select); |
| 1224 | | state_save_register_global(machine, scc68070->uart.command_register); |
| 1225 | | state_save_register_global(machine, scc68070->uart.transmit_holding_register); |
| 1226 | | state_save_register_global(machine, scc68070->uart.receive_holding_register); |
| 1227 | | |
| 1228 | | state_save_register_global(machine, scc68070->timers.timer_status_register); |
| 1229 | | state_save_register_global(machine, scc68070->timers.timer_control_register); |
| 1230 | | state_save_register_global(machine, scc68070->timers.reload_register); |
| 1231 | | state_save_register_global(machine, scc68070->timers.timer0); |
| 1232 | | state_save_register_global(machine, scc68070->timers.timer1); |
| 1233 | | state_save_register_global(machine, scc68070->timers.timer2); |
| 1234 | | |
| 1235 | | state_save_register_global(machine, scc68070->dma.channel[0].channel_status); |
| 1236 | | state_save_register_global(machine, scc68070->dma.channel[0].channel_error); |
| 1237 | | state_save_register_global(machine, scc68070->dma.channel[0].device_control); |
| 1238 | | state_save_register_global(machine, scc68070->dma.channel[0].operation_control); |
| 1239 | | state_save_register_global(machine, scc68070->dma.channel[0].sequence_control); |
| 1240 | | state_save_register_global(machine, scc68070->dma.channel[0].channel_control); |
| 1241 | | state_save_register_global(machine, scc68070->dma.channel[0].transfer_counter); |
| 1242 | | state_save_register_global(machine, scc68070->dma.channel[0].memory_address_counter); |
| 1243 | | state_save_register_global(machine, scc68070->dma.channel[0].device_address_counter); |
| 1244 | | state_save_register_global(machine, scc68070->dma.channel[1].channel_status); |
| 1245 | | state_save_register_global(machine, scc68070->dma.channel[1].channel_error); |
| 1246 | | state_save_register_global(machine, scc68070->dma.channel[1].device_control); |
| 1247 | | state_save_register_global(machine, scc68070->dma.channel[1].operation_control); |
| 1248 | | state_save_register_global(machine, scc68070->dma.channel[1].sequence_control); |
| 1249 | | state_save_register_global(machine, scc68070->dma.channel[1].channel_control); |
| 1250 | | state_save_register_global(machine, scc68070->dma.channel[1].transfer_counter); |
| 1251 | | state_save_register_global(machine, scc68070->dma.channel[1].memory_address_counter); |
| 1252 | | state_save_register_global(machine, scc68070->dma.channel[1].device_address_counter); |
| 1253 | | |
| 1254 | | state_save_register_global(machine, scc68070->mmu.status); |
| 1255 | | state_save_register_global(machine, scc68070->mmu.control); |
| 1256 | | state_save_register_global(machine, scc68070->mmu.desc[0].attr); |
| 1257 | | state_save_register_global(machine, scc68070->mmu.desc[0].length); |
| 1258 | | state_save_register_global(machine, scc68070->mmu.desc[0].segment); |
| 1259 | | state_save_register_global(machine, scc68070->mmu.desc[0].base); |
| 1260 | | state_save_register_global(machine, scc68070->mmu.desc[1].attr); |
| 1261 | | state_save_register_global(machine, scc68070->mmu.desc[1].length); |
| 1262 | | state_save_register_global(machine, scc68070->mmu.desc[1].segment); |
| 1263 | | state_save_register_global(machine, scc68070->mmu.desc[1].base); |
| 1264 | | state_save_register_global(machine, scc68070->mmu.desc[2].attr); |
| 1265 | | state_save_register_global(machine, scc68070->mmu.desc[2].length); |
| 1266 | | state_save_register_global(machine, scc68070->mmu.desc[2].segment); |
| 1267 | | state_save_register_global(machine, scc68070->mmu.desc[2].base); |
| 1268 | | state_save_register_global(machine, scc68070->mmu.desc[3].attr); |
| 1269 | | state_save_register_global(machine, scc68070->mmu.desc[3].length); |
| 1270 | | state_save_register_global(machine, scc68070->mmu.desc[3].segment); |
| 1271 | | state_save_register_global(machine, scc68070->mmu.desc[3].base); |
| 1272 | | state_save_register_global(machine, scc68070->mmu.desc[4].attr); |
| 1273 | | state_save_register_global(machine, scc68070->mmu.desc[4].length); |
| 1274 | | state_save_register_global(machine, scc68070->mmu.desc[4].segment); |
| 1275 | | state_save_register_global(machine, scc68070->mmu.desc[4].base); |
| 1276 | | state_save_register_global(machine, scc68070->mmu.desc[5].attr); |
| 1277 | | state_save_register_global(machine, scc68070->mmu.desc[5].length); |
| 1278 | | state_save_register_global(machine, scc68070->mmu.desc[5].segment); |
| 1279 | | state_save_register_global(machine, scc68070->mmu.desc[5].base); |
| 1280 | | state_save_register_global(machine, scc68070->mmu.desc[6].attr); |
| 1281 | | state_save_register_global(machine, scc68070->mmu.desc[6].length); |
| 1282 | | state_save_register_global(machine, scc68070->mmu.desc[6].segment); |
| 1283 | | state_save_register_global(machine, scc68070->mmu.desc[6].base); |
| 1284 | | state_save_register_global(machine, scc68070->mmu.desc[7].attr); |
| 1285 | | state_save_register_global(machine, scc68070->mmu.desc[7].length); |
| 1286 | | state_save_register_global(machine, scc68070->mmu.desc[7].segment); |
| 1287 | | state_save_register_global(machine, scc68070->mmu.desc[7].base); |
| 1288 | | } |
| 1289 | | |
| 1290 | | #if ENABLE_UART_PRINTING |
| 1291 | | static READ16_HANDLER( uart_loopback_enable ) |
| 1292 | | { |
| 1293 | | return 0x1234; |
| 1294 | | } |
| 1295 | | #endif |
| 1296 | | |
| 1297 | | |
| 1298 | | |
| 1299 | | |
| 1300 | | static const INT32 cdic_adpcm_filter_coef[5][2] = |
| 1301 | | { |
| 1302 | | { 0,0 }, |
| 1303 | | { 60,0 }, |
| 1304 | | { 115,-52 }, |
| 1305 | | { 98,-55 }, |
| 1306 | | { 122,-60 }, |
| 1307 | | }; |
| 1308 | | |
| 1309 | | INLINE int CDIC_IS_VALID_SAMPLE_BUF(UINT16 *cdram, UINT16 addr) |
| 1310 | | { |
| 1311 | | UINT8 *cdram8 = ((UINT8*)cdram) + addr + 8; |
| 1312 | | if(cdram8[2] != 0xff) |
| 1313 | | { |
| 1314 | | return 1; |
| 1315 | | } |
| 1316 | | return 0; |
| 1317 | | } |
| 1318 | | |
| 1319 | | INLINE double CDIC_SAMPLE_BUF_FREQ(UINT16 *cdram, UINT16 addr) |
| 1320 | | { |
| 1321 | | UINT8 *cdram8 = ((UINT8*)cdram) + addr + 8; |
| 1322 | | switch(cdram8[2] & 0x3f) |
| 1323 | | { |
| 1324 | | case 0: |
| 1325 | | case 1: |
| 1326 | | case 16: |
| 1327 | | case 17: |
| 1328 | | return 37800.0f; |
| 1329 | | |
| 1330 | | case 4: |
| 1331 | | case 5: |
| 1332 | | return 18900.0f; |
| 1333 | | |
| 1334 | | default: |
| 1335 | | return 18900.0f; |
| 1336 | | } |
| 1337 | | } |
| 1338 | | |
| 1339 | | INLINE int CDIC_SAMPLE_BUF_SIZE(UINT16 *cdram, UINT16 addr) |
| 1340 | | { |
| 1341 | | UINT8 *cdram8 = ((UINT8*)cdram) + addr + 8; |
| 1342 | | switch(cdram8[2] & 0x3f) |
| 1343 | | { |
| 1344 | | case 0: |
| 1345 | | case 4: |
| 1346 | | return 4; |
| 1347 | | |
| 1348 | | case 1: |
| 1349 | | case 5: |
| 1350 | | case 16: |
| 1351 | | return 2; |
| 1352 | | |
| 1353 | | case 17: |
| 1354 | | return 1; |
| 1355 | | |
| 1356 | | default: |
| 1357 | | return 2; |
| 1358 | | } |
| 1359 | | } |
| 1360 | | |
| 1361 | | INLINE INT16 clamp(INT16 in) |
| 1362 | | { |
| 1363 | | return in; |
| 1364 | | } |
| 1365 | | |
| 1366 | | static void cdic_decode_xa_mono(int *cdic_xa_last, const unsigned char *xa, signed short *dp) |
| 1367 | | { |
| 1368 | | int l0=cdic_xa_last[0], |
| 1369 | | l1=cdic_xa_last[1]; |
| 1370 | | int b=0; |
| 1371 | | int s=0; |
| 1372 | | |
| 1373 | | for (b=0; b<18; b++) |
| 1374 | | { |
| 1375 | | for (s=0; s<4; s++) |
| 1376 | | { |
| 1377 | | unsigned char flags=xa[(4+(s<<1))^1], |
| 1378 | | shift=flags&0xf, |
| 1379 | | filter=flags>>4; |
| 1380 | | int f0=cdic_adpcm_filter_coef[filter][0], |
| 1381 | | f1=cdic_adpcm_filter_coef[filter][1]; |
| 1382 | | int i=0; |
| 1383 | | |
| 1384 | | for (i=0; i<28; i++) |
| 1385 | | { |
| 1386 | | short d=(xa[(16+(i<<2)+s)^1]&0xf)<<12; |
| 1387 | | d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 1388 | | *dp++=d; |
| 1389 | | l1=l0; |
| 1390 | | l0=d; |
| 1391 | | } |
| 1392 | | |
| 1393 | | flags=xa[(5+(s<<1))^1]; |
| 1394 | | shift=flags&0xf; |
| 1395 | | filter=flags>>4; |
| 1396 | | f0=cdic_adpcm_filter_coef[filter][0]; |
| 1397 | | f1=cdic_adpcm_filter_coef[filter][1]; |
| 1398 | | |
| 1399 | | for (i=0; i<28; i++) |
| 1400 | | { |
| 1401 | | short d=(xa[(16+(i<<2)+s)^1]>>4)<<12; |
| 1402 | | d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 1403 | | *dp++=d; |
| 1404 | | l1=l0; |
| 1405 | | l0=d; |
| 1406 | | } |
| 1407 | | } |
| 1408 | | |
| 1409 | | xa+=128; |
| 1410 | | } |
| 1411 | | |
| 1412 | | cdic_xa_last[0]=l0; |
| 1413 | | cdic_xa_last[1]=l1; |
| 1414 | | } |
| 1415 | | |
| 1416 | | static void cdic_decode_xa_mono8(int *cdic_xa_last, const unsigned char *xa, signed short *dp) |
| 1417 | | { |
| 1418 | | int l0=cdic_xa_last[0], |
| 1419 | | l1=cdic_xa_last[1]; |
| 1420 | | int b=0; |
| 1421 | | int s=0; |
| 1422 | | |
| 1423 | | for (b=0; b<18; b++) |
| 1424 | | { |
| 1425 | | for (s=0; s<4; s++) |
| 1426 | | { |
| 1427 | | unsigned char flags=xa[(4+s)^1], |
| 1428 | | shift=flags&0xf, |
| 1429 | | filter=flags>>4; |
| 1430 | | int f0=cdic_adpcm_filter_coef[filter][0], |
| 1431 | | f1=cdic_adpcm_filter_coef[filter][1]; |
| 1432 | | int i=0; |
| 1433 | | |
| 1434 | | for (i=0; i<28; i++) |
| 1435 | | { |
| 1436 | | short d=(xa[(16+(i<<2)+s)^1]<<8); |
| 1437 | | d=clamp((d>>shift)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 1438 | | *dp++=d; |
| 1439 | | l1=l0; |
| 1440 | | l0=d; |
| 1441 | | } |
| 1442 | | } |
| 1443 | | |
| 1444 | | xa+=128; |
| 1445 | | } |
| 1446 | | |
| 1447 | | cdic_xa_last[0]=l0; |
| 1448 | | cdic_xa_last[1]=l1; |
| 1449 | | } |
| 1450 | | |
| 1451 | | static void cdic_decode_xa_stereo(int *cdic_xa_last, const unsigned char *xa, signed short *dp) |
| 1452 | | { |
| 1453 | | int l0=cdic_xa_last[0], |
| 1454 | | l1=cdic_xa_last[1], |
| 1455 | | l2=cdic_xa_last[2], |
| 1456 | | l3=cdic_xa_last[3]; |
| 1457 | | int b=0; |
| 1458 | | int s=0; |
| 1459 | | //int decoded = 0; |
| 1460 | | |
| 1461 | | for (b=0; b<18; b++) |
| 1462 | | { |
| 1463 | | for (s=0; s<4; s++) |
| 1464 | | { |
| 1465 | | unsigned char flags0=xa[(4+(s<<1))^1], |
| 1466 | | shift0=flags0&0xf, |
| 1467 | | filter0=flags0>>4, |
| 1468 | | flags1=xa[(5+(s<<1))^1], |
| 1469 | | shift1=flags1&0xf, |
| 1470 | | filter1=flags1>>4; |
| 1471 | | |
| 1472 | | int f0=cdic_adpcm_filter_coef[filter0][0], |
| 1473 | | f1=cdic_adpcm_filter_coef[filter0][1], |
| 1474 | | f2=cdic_adpcm_filter_coef[filter1][0], |
| 1475 | | f3=cdic_adpcm_filter_coef[filter1][1]; |
| 1476 | | int i=0; |
| 1477 | | |
| 1478 | | for (i=0; i<28; i++) |
| 1479 | | { |
| 1480 | | short d=xa[(16+(i<<2)+s)^1], |
| 1481 | | d0=(d&0xf)<<12, |
| 1482 | | d1=(d>>4)<<12; |
| 1483 | | d0=clamp((d0>>shift0)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 1484 | | *dp++=d0; |
| 1485 | | l1=l0; |
| 1486 | | l0=d0; |
| 1487 | | |
| 1488 | | d1=clamp((d1>>shift1)+(((l2*f2)+(l3*f3)+32)>>6)); |
| 1489 | | *dp++=d1; |
| 1490 | | l3=l2; |
| 1491 | | l2=d1; |
| 1492 | | //decoded += 2; |
| 1493 | | } |
| 1494 | | } |
| 1495 | | |
| 1496 | | xa+=128; |
| 1497 | | } |
| 1498 | | |
| 1499 | | cdic_xa_last[0]=l0; |
| 1500 | | cdic_xa_last[1]=l1; |
| 1501 | | cdic_xa_last[2]=l2; |
| 1502 | | cdic_xa_last[3]=l3; |
| 1503 | | |
| 1504 | | //printf( "Decoded %d samples\n", decoded ); |
| 1505 | | } |
| 1506 | | |
| 1507 | | static void cdic_decode_xa_stereo8(int *cdic_xa_last, const unsigned char *xa, signed short *dp) |
| 1508 | | { |
| 1509 | | int l0=cdic_xa_last[0], |
| 1510 | | l1=cdic_xa_last[1], |
| 1511 | | l2=cdic_xa_last[2], |
| 1512 | | l3=cdic_xa_last[3]; |
| 1513 | | int b=0; |
| 1514 | | int s=0; |
| 1515 | | |
| 1516 | | for (b=0; b<18; b++) |
| 1517 | | { |
| 1518 | | for (s=0; s<4; s += 2) |
| 1519 | | { |
| 1520 | | unsigned char flags0=xa[(4+s)^1], |
| 1521 | | shift0=flags0&0xf, |
| 1522 | | filter0=flags0>>4, |
| 1523 | | flags1=xa[(5+s)^1], |
| 1524 | | shift1=flags1&0xf, |
| 1525 | | filter1=flags1>>4; |
| 1526 | | int f0=cdic_adpcm_filter_coef[filter0][0], |
| 1527 | | f1=cdic_adpcm_filter_coef[filter0][1], |
| 1528 | | f2=cdic_adpcm_filter_coef[filter1][0], |
| 1529 | | f3=cdic_adpcm_filter_coef[filter1][1]; |
| 1530 | | int i=0; |
| 1531 | | |
| 1532 | | for (i=0; i<28; i++) |
| 1533 | | { |
| 1534 | | //short d0=(xa[(16+((i+0)<<2)+s)^1]<<8); |
| 1535 | | //short d1=(xa[(16+((i+1)<<2)+s)^1]<<8); |
| 1536 | | short d0=(xa[(16+(i<<2)+s+0)^1]<<8); |
| 1537 | | short d1=(xa[(16+(i<<2)+s+1)^1]<<8); |
| 1538 | | |
| 1539 | | d0=clamp((d0>>shift0)+(((l0*f0)+(l1*f1)+32)>>6)); |
| 1540 | | *dp++=d0; |
| 1541 | | l1=l0; |
| 1542 | | l0=d0; |
| 1543 | | |
| 1544 | | d1=clamp((d1>>shift1)+(((l2*f2)+(l3*f3)+32)>>6)); |
| 1545 | | *dp++=d1; |
| 1546 | | l3=l2; |
| 1547 | | l2=d1; |
| 1548 | | } |
| 1549 | | } |
| 1550 | | |
| 1551 | | xa+=128; |
| 1552 | | } |
| 1553 | | |
| 1554 | | cdic_xa_last[0]=l0; |
| 1555 | | cdic_xa_last[1]=l1; |
| 1556 | | cdic_xa_last[2]=l2; |
| 1557 | | cdic_xa_last[3]=l3; |
| 1558 | | } |
| 1559 | | |
| 1560 | | static void cdic_decode_audio_sector(running_machine *machine, const unsigned char *xa, int triggered) |
| 1561 | | { |
| 1562 | | // Get XA format from sector header |
| 1563 | | |
| 1564 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 1565 | | cdic_regs_t *cdic = &state->cdic_regs; |
| 1566 | | const unsigned char *hdr = xa + 4; |
| 1567 | | int channels; |
| 1568 | | int bits = 4; |
| 1569 | | int index = 0; |
| 1570 | | INT16 samples[18*28*16+16]; |
| 1571 | | //FILE* temp_adpcm = fopen("temp_adpcm.bin","ab"); |
| 1572 | | |
| 1573 | | //printf( "%02x\n", hdr[2] & 0x3f ); |
| 1574 | | |
| 1575 | | if(hdr[2] == 0xff && triggered == 1) |
| 1576 | | { |
| 1577 | | // Don't play |
| 1578 | | //timer_adjust_oneshot(cdic->audio_sample_timer, attotime_never, 0); |
| 1579 | | //fclose(temp_adpcm); |
| 1580 | | return; |
| 1581 | | } |
| 1582 | | |
| 1583 | | verboselog(machine, 0, "cdic_decode_audio_sector, got header type %02x\n", hdr[2] ); |
| 1584 | | |
| 1585 | | //fseek(temp_adpcm, 0, SEEK_END); |
| 1586 | | switch(hdr[2] & 0x3f) // ignore emphasis and reserved bits |
| 1587 | | { |
| 1588 | | case 0: |
| 1589 | | channels=1; |
| 1590 | | cdic->audio_sample_freq=37800.0f; //18900.0f; |
| 1591 | | bits=4; |
| 1592 | | cdic->audio_sample_size=4; |
| 1593 | | break; |
| 1594 | | |
| 1595 | | case 1: |
| 1596 | | channels=2; |
| 1597 | | cdic->audio_sample_freq=37800.0f; |
| 1598 | | bits=4; |
| 1599 | | cdic->audio_sample_size=2; |
| 1600 | | break; |
| 1601 | | |
| 1602 | | case 4: |
| 1603 | | channels=1; |
| 1604 | | cdic->audio_sample_freq=18900.0f; ///2.0f; |
| 1605 | | bits=4; |
| 1606 | | cdic->audio_sample_size=4; |
| 1607 | | break; |
| 1608 | | |
| 1609 | | case 5: |
| 1610 | | channels=2; |
| 1611 | | cdic->audio_sample_freq=18900.0f; //37800.0f/2.0f; |
| 1612 | | bits=4; |
| 1613 | | cdic->audio_sample_size=2; |
| 1614 | | break; |
| 1615 | | |
| 1616 | | case 16: |
| 1617 | | channels=1; |
| 1618 | | cdic->audio_sample_freq=37800.0f; |
| 1619 | | bits=8; |
| 1620 | | cdic->audio_sample_size=2; |
| 1621 | | break; |
| 1622 | | |
| 1623 | | case 17: |
| 1624 | | channels=2; |
| 1625 | | cdic->audio_sample_freq=37800.0f; |
| 1626 | | bits=8; |
| 1627 | | cdic->audio_sample_size=1; |
| 1628 | | break; |
| 1629 | | |
| 1630 | | default: |
| 1631 | | fatalerror("play_xa: unhandled xa mode %08x",hdr[2]); |
| 1632 | | return; |
| 1633 | | } |
| 1634 | | |
| 1635 | | dmadac_set_frequency(&state->dmadac[0], 2, cdic->audio_sample_freq); |
| 1636 | | dmadac_enable(&state->dmadac[0], 2, 1); |
| 1637 | | |
| 1638 | | switch(channels) |
| 1639 | | { |
| 1640 | | case 1: |
| 1641 | | switch(bits) |
| 1642 | | { |
| 1643 | | case 4: |
| 1644 | | cdic_decode_xa_mono(cdic->xa_last, hdr + 4, samples); |
| 1645 | | for(index = 18*28*8 - 1; index >= 0; index--) |
| 1646 | | { |
| 1647 | | samples[index*2 + 1] = samples[index]; |
| 1648 | | samples[index*2 + 0] = samples[index]; |
| 1649 | | } |
| 1650 | | samples[18*28*16 + 0] = samples[18*28*16 + 2] = samples[18*28*16 + 4] = samples[18*28*16 + 6] = samples[18*28*16 + 8] = samples[18*28*16 + 10] = samples[18*28*16 + 12] = samples[18*28*16 + 14] = samples[18*28*16 - 2]; |
| 1651 | | samples[18*28*16 + 1] = samples[18*28*16 + 3] = samples[18*28*16 + 5] = samples[18*28*16 + 7] = samples[18*28*16 + 9] = samples[18*28*16 + 11] = samples[18*28*16 + 13] = samples[18*28*16 + 15] = samples[18*28*16 - 1]; |
| 1652 | | break; |
| 1653 | | case 8: |
| 1654 | | cdic_decode_xa_mono8(cdic->xa_last, hdr + 4, samples); |
| 1655 | | for(index = 18*28*8 - 1; index >= 0; index--) |
| 1656 | | { |
| 1657 | | samples[index*2 + 1] = samples[index]; |
| 1658 | | samples[index*2 + 0] = samples[index]; |
| 1659 | | } |
| 1660 | | samples[18*28*8 + 0] = samples[18*28*8 + 2] = samples[18*28*8 + 4] = samples[18*28*8 + 6] = samples[18*28*8 + 8] = samples[18*28*8 + 10] = samples[18*28*8 + 12] = samples[18*28*8 + 14] = samples[18*28*8 - 2]; |
| 1661 | | samples[18*28*8 + 1] = samples[18*28*8 + 3] = samples[18*28*8 + 5] = samples[18*28*8 + 7] = samples[18*28*8 + 9] = samples[18*28*8 + 11] = samples[18*28*8 + 13] = samples[18*28*8 + 15] = samples[18*28*8 - 1]; |
| 1662 | | break; |
| 1663 | | } |
| 1664 | | break; |
| 1665 | | case 2: |
| 1666 | | switch(bits) |
| 1667 | | { |
| 1668 | | case 4: |
| 1669 | | cdic_decode_xa_stereo(cdic->xa_last, hdr + 4, samples); |
| 1670 | | samples[18*28*8 + 0] = samples[18*28*8 + 2] = samples[18*28*8 + 4] = samples[18*28*8 + 6] = samples[18*28*8 + 8] = samples[18*28*8 + 10] = samples[18*28*8 + 12] = samples[18*28*8 + 14] = samples[18*28*8 - 2]; |
| 1671 | | samples[18*28*8 + 1] = samples[18*28*8 + 3] = samples[18*28*8 + 5] = samples[18*28*8 + 7] = samples[18*28*8 + 9] = samples[18*28*8 + 11] = samples[18*28*8 + 13] = samples[18*28*8 + 15] = samples[18*28*8 - 1]; |
| 1672 | | //fwrite(samples, 1, 18*28*4*cdic->audio_sample_size, temp_adpcm); |
| 1673 | | break; |
| 1674 | | case 8: |
| 1675 | | cdic_decode_xa_stereo8(cdic->xa_last, hdr + 4, samples); |
| 1676 | | samples[18*28*4 + 0] = samples[18*28*4 + 2] = samples[18*28*4 + 4] = samples[18*28*4 + 6] = samples[18*28*4 + 8] = samples[18*28*4 + 10] = samples[18*28*4 + 12] = samples[18*28*4 + 14] = samples[18*28*4 - 2]; |
| 1677 | | samples[18*28*4 + 1] = samples[18*28*4 + 3] = samples[18*28*4 + 5] = samples[18*28*4 + 7] = samples[18*28*4 + 9] = samples[18*28*4 + 11] = samples[18*28*4 + 13] = samples[18*28*4 + 15] = samples[18*28*4 - 1]; |
| 1678 | | break; |
| 1679 | | } |
| 1680 | | break; |
| 1681 | | } |
| 1682 | | |
| 1683 | | dmadac_transfer(&state->dmadac[0], 2, 1, 2, 18*28*2*cdic->audio_sample_size, samples); |
| 1684 | | |
| 1685 | | //fclose(temp_adpcm); |
| 1686 | | } |
| 1687 | | |
| 1688 | | // After an appropriate delay for decoding to take place... |
| 1689 | | static TIMER_CALLBACK( audio_sample_trigger ) |
| 1690 | | { |
| 1691 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 1692 | | cdic_regs_t *cdic = &state->cdic_regs; |
| 1693 | | |
| 1694 | | if(cdic->decode_addr == 0xffff) |
| 1695 | | { |
| 1696 | | verboselog(machine, 0, "Decode stop requested, stopping playback\n" ); |
| 1697 | | timer_adjust_oneshot(cdic->audio_sample_timer, attotime_never, 0); |
| 1698 | | return; |
| 1699 | | } |
| 1700 | | |
| 1701 | | if(!cdic->decode_delay) |
| 1702 | | { |
| 1703 | | // Indicate that data has been decoded |
| 1704 | | verboselog(machine, 0, "Flagging that audio data has been decoded\n" ); |
| 1705 | | cdic->audio_buffer |= 0x8000; |
| 1706 | | |
| 1707 | | // Set the CDIC interrupt line |
| 1708 | | verboselog(machine, 0, "Setting CDIC interrupt line for soundmap decode\n" ); |
| 1709 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 1710 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1711 | | } |
| 1712 | | else |
| 1713 | | { |
| 1714 | | cdic->decode_delay = 0; |
| 1715 | | } |
| 1716 | | |
| 1717 | | if(CDIC_IS_VALID_SAMPLE_BUF(cdic->ram, cdic->decode_addr & 0x3ffe)) |
| 1718 | | { |
| 1719 | | verboselog(machine, 0, "Hit audio_sample_trigger, with cdic->decode_addr == %04x, calling cdic_decode_audio_sector\n", cdic->decode_addr ); |
| 1720 | | |
| 1721 | | // Decode the data at Z+4, the same offset as a normal CD sector. |
| 1722 | | cdic_decode_audio_sector(machine, ((UINT8*)cdic->ram) + (cdic->decode_addr & 0x3ffe) + 4, 1); |
| 1723 | | |
| 1724 | | // Swap buffer positions to indicate our new buffer position at the next read |
| 1725 | | cdic->decode_addr ^= 0x1a00; |
| 1726 | | |
| 1727 | | verboselog(machine, 0, "Updated cdic->decode_addr, new value is %04x\n", cdic->decode_addr ); |
| 1728 | | |
| 1729 | | //// Delay for Frequency * (18*28*2*size in bytes) before requesting more data |
| 1730 | | verboselog(machine, 0, "Data is valid, setting up a new callback\n" ); |
| 1731 | | cdic->decode_period = attotime_mul(ATTOTIME_IN_HZ(CDIC_SAMPLE_BUF_FREQ(cdic->ram, cdic->decode_addr & 0x3ffe)), 18*28*2*CDIC_SAMPLE_BUF_SIZE(cdic->ram, cdic->decode_addr & 0x3ffe)); |
| 1732 | | timer_adjust_oneshot(cdic->audio_sample_timer, cdic->decode_period, 0); |
| 1733 | | //dmadac_enable(&dmadac[0], 2, 0); |
| 1734 | | } |
| 1735 | | else |
| 1736 | | { |
| 1737 | | // Swap buffer positions to indicate our new buffer position at the next read |
| 1738 | | cdic->decode_addr ^= 0x1a00; |
| 1739 | | |
| 1740 | | verboselog(machine, 0, "Data is not valid, indicating to shut down on the next audio sample\n" ); |
| 1741 | | cdic->decode_addr = 0xffff; |
| 1742 | | timer_adjust_oneshot(cdic->audio_sample_timer, cdic->decode_period, 0); |
| 1743 | | } |
| 1744 | | } |
| 1745 | | |
| 1746 | | static UINT32 increment_cdda_frame_bcd(UINT32 bcd) |
| 1747 | | { |
| 1748 | | UINT8 nybbles[6] = |
| 1749 | | { |
| 1750 | | bcd & 0x0000000f, |
| 1751 | | (bcd & 0x000000f0) >> 4, |
| 1752 | | (bcd & 0x00000f00) >> 8, |
| 1753 | | (bcd & 0x0000f000) >> 12, |
| 1754 | | (bcd & 0x000f0000) >> 16, |
| 1755 | | (bcd & 0x00f00000) >> 20 |
| 1756 | | }; |
| 1757 | | nybbles[0]++; |
| 1758 | | if(nybbles[0] == 5 && nybbles[1] == 7) |
| 1759 | | { |
| 1760 | | nybbles[0] = 0; |
| 1761 | | nybbles[1] = 0; |
| 1762 | | nybbles[2]++; |
| 1763 | | } |
| 1764 | | else if(nybbles[0] == 10) |
| 1765 | | { |
| 1766 | | nybbles[1]++; |
| 1767 | | } |
| 1768 | | if(nybbles[2] == 10) |
| 1769 | | { |
| 1770 | | nybbles[3]++; |
| 1771 | | nybbles[2] = 0; |
| 1772 | | } |
| 1773 | | if(nybbles[3] == 6) |
| 1774 | | { |
| 1775 | | nybbles[4]++; |
| 1776 | | nybbles[3] = 0; |
| 1777 | | } |
| 1778 | | if(nybbles[4] == 10) |
| 1779 | | { |
| 1780 | | nybbles[5]++; |
| 1781 | | nybbles[4] = 0; |
| 1782 | | } |
| 1783 | | return (nybbles[5] << 20) | (nybbles[4] << 16) | (nybbles[3] << 12) | (nybbles[2] << 8) | (nybbles[1] << 4) | nybbles[0]; |
| 1784 | | } |
| 1785 | | |
| 1786 | | static UINT32 increment_cdda_sector_bcd(UINT32 bcd) |
| 1787 | | { |
| 1788 | | UINT8 nybbles[6] = |
| 1789 | | { |
| 1790 | | bcd & 0x0000000f, |
| 1791 | | (bcd & 0x000000f0) >> 4, |
| 1792 | | (bcd & 0x00000f00) >> 8, |
| 1793 | | (bcd & 0x0000f000) >> 12, |
| 1794 | | (bcd & 0x000f0000) >> 16, |
| 1795 | | (bcd & 0x00f00000) >> 20 |
| 1796 | | }; |
| 1797 | | nybbles[2]++; |
| 1798 | | if(nybbles[2] == 10) |
| 1799 | | { |
| 1800 | | nybbles[3]++; |
| 1801 | | nybbles[2] = 0; |
| 1802 | | } |
| 1803 | | if(nybbles[3] == 6) |
| 1804 | | { |
| 1805 | | nybbles[4]++; |
| 1806 | | nybbles[3] = 0; |
| 1807 | | } |
| 1808 | | if(nybbles[4] == 10) |
| 1809 | | { |
| 1810 | | nybbles[5]++; |
| 1811 | | nybbles[4] = 0; |
| 1812 | | } |
| 1813 | | return (nybbles[5] << 20) | (nybbles[4] << 16) | (nybbles[3] << 12) | (nybbles[2] << 8) | (nybbles[1] << 4) | nybbles[0]; |
| 1814 | | } |
| 1815 | | |
| 1816 | | static TIMER_CALLBACK( cdic_trigger_readback_int ) |
| 1817 | | { |
| 1818 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 1819 | | cdic_regs_t *cdic = &state->cdic_regs; |
| 1820 | | |
| 1821 | | switch(cdic->command) |
| 1822 | | { |
| 1823 | | case 0x23: // Reset Mode 1 |
| 1824 | | case 0x24: // Reset Mode 2 |
| 1825 | | case 0x29: // Read Mode 1 |
| 1826 | | case 0x2a: // Read Mode 2 |
| 1827 | | //case 0x2c: // Seek |
| 1828 | | { |
| 1829 | | UINT8 buffer[2560] = { 0 }; |
| 1830 | | UINT32 msf = cdic->time >> 8; |
| 1831 | | UINT32 lba = 0; |
| 1832 | | int index = 0; |
| 1833 | | UINT8 nybbles[6] = |
| 1834 | | { |
| 1835 | | msf & 0x0000000f, |
| 1836 | | (msf & 0x000000f0) >> 4, |
| 1837 | | (msf & 0x00000f00) >> 8, |
| 1838 | | (msf & 0x0000f000) >> 12, |
| 1839 | | (msf & 0x000f0000) >> 16, |
| 1840 | | (msf & 0x00f00000) >> 20 |
| 1841 | | }; |
| 1842 | | if(msf & 0x000080) |
| 1843 | | { |
| 1844 | | msf &= 0xffff00; |
| 1845 | | nybbles[0] = 0; |
| 1846 | | nybbles[1] = 0; |
| 1847 | | } |
| 1848 | | if(nybbles[2] >= 2) |
| 1849 | | { |
| 1850 | | nybbles[2] -= 2; |
| 1851 | | } |
| 1852 | | else |
| 1853 | | { |
| 1854 | | nybbles[2] = 8 + nybbles[2]; |
| 1855 | | if(nybbles[3] > 0) |
| 1856 | | { |
| 1857 | | nybbles[3]--; |
| 1858 | | } |
| 1859 | | else |
| 1860 | | { |
| 1861 | | nybbles[3] = 5; |
| 1862 | | if(nybbles[4] > 0) |
| 1863 | | { |
| 1864 | | nybbles[4]--; |
| 1865 | | } |
| 1866 | | else |
| 1867 | | { |
| 1868 | | nybbles[4] = 9; |
| 1869 | | nybbles[5]--; |
| 1870 | | } |
| 1871 | | } |
| 1872 | | } |
| 1873 | | lba = nybbles[0] + nybbles[1]*10 + ((nybbles[2] + nybbles[3]*10)*75) + ((nybbles[4] + nybbles[5]*10)*75*60); |
| 1874 | | |
| 1875 | | //printf( "Reading Mode %d sector from MSF location %06x\n", cdic->command - 0x28, cdic->time | 2 ); |
| 1876 | | verboselog(machine, 0, "Reading Mode %d sector from MSF location %06x\n", cdic->command - 0x28, cdic->time | 2 ); |
| 1877 | | |
| 1878 | | |
| 1879 | | cdrom_read_data(cdic->cd, lba, buffer, CD_TRACK_RAW_DONTCARE); |
| 1880 | | |
| 1881 | | cdic->time += 0x100; |
| 1882 | | if((cdic->time & 0x00000f00) == 0x00000a00) |
| 1883 | | { |
| 1884 | | cdic->time &= 0xfffff0ff; |
| 1885 | | cdic->time += 0x00001000; |
| 1886 | | } |
| 1887 | | if((cdic->time & 0x0000ff00) == 0x00007500) |
| 1888 | | { |
| 1889 | | cdic->time &= 0xffff00ff; |
| 1890 | | cdic->time += 0x00010000; |
| 1891 | | if((cdic->time & 0x000f0000) == 0x000a0000) |
| 1892 | | { |
| 1893 | | cdic->time &= 0xfff0ffff; |
| 1894 | | cdic->time += 0x00100000; |
| 1895 | | } |
| 1896 | | } |
| 1897 | | if((cdic->time & 0x00ff0000) == 0x00600000) |
| 1898 | | { |
| 1899 | | cdic->time &= 0xff00ffff; |
| 1900 | | cdic->time += 0x01000000; |
| 1901 | | if((cdic->time & 0x0f000000) == 0x0a000000) |
| 1902 | | { |
| 1903 | | cdic->time &= 0xf0ffffff; |
| 1904 | | cdic->time += 0x10000000; |
| 1905 | | } |
| 1906 | | } |
| 1907 | | |
| 1908 | | cdic->data_buffer &= ~0x0004; |
| 1909 | | cdic->data_buffer ^= 0x0001; |
| 1910 | | |
| 1911 | | //printf( "%02x\n", buffer[CDIC_SECTOR_SUBMODE2] ); |
| 1912 | | if((buffer[CDIC_SECTOR_FILE2] << 8) == cdic->file) |
| 1913 | | { |
| 1914 | | //if((1 << buffer[CDIC_SECTOR_CHAN2])) |
| 1915 | | { |
| 1916 | | if(((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_FORM | CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == (CDIC_SUBMODE_FORM | CDIC_SUBMODE_AUDIO)) && |
| 1917 | | (cdic->channel & cdic->audio_channel & (1 << buffer[CDIC_SECTOR_CHAN2]))) |
| 1918 | | { |
| 1919 | | { |
| 1920 | | verboselog(machine, 0, "Audio sector\n" ); |
| 1921 | | |
| 1922 | | cdic->x_buffer |= 0x8000; |
| 1923 | | //cdic->data_buffer |= 0x4000; |
| 1924 | | cdic->data_buffer |= 0x0004; |
| 1925 | | |
| 1926 | | for(index = 6; index < 2352/2; index++) |
| 1927 | | { |
| 1928 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1929 | | } |
| 1930 | | |
| 1931 | | cdic_decode_audio_sector(machine, ((UINT8*)cdic->ram) + ((cdic->data_buffer & 5) * 0xa00 + 4), 0); |
| 1932 | | |
| 1933 | | //printf( "Setting CDIC interrupt line\n" ); |
| 1934 | | verboselog(machine, 0, "Setting CDIC interrupt line for audio sector\n" ); |
| 1935 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 1936 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1937 | | } |
| 1938 | | } |
| 1939 | | else if((buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_AUDIO | CDIC_SUBMODE_VIDEO)) == 0x00) |
| 1940 | | { |
| 1941 | | cdic->x_buffer |= 0x8000; |
| 1942 | | //cdic->data_buffer |= 0x4000; |
| 1943 | | |
| 1944 | | for(index = 6; index < 2352/2; index++) |
| 1945 | | { |
| 1946 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1947 | | } |
| 1948 | | |
| 1949 | | if((buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_TRIG) == CDIC_SUBMODE_TRIG || |
| 1950 | | (buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOR) == CDIC_SUBMODE_EOR || |
| 1951 | | (buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOF) == CDIC_SUBMODE_EOF) |
| 1952 | | { |
| 1953 | | //printf( "Setting CDIC interrupt line\n" ); |
| 1954 | | verboselog(machine, 0, "Setting CDIC interrupt line for message sector\n" ); |
| 1955 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 1956 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1957 | | } |
| 1958 | | else |
| 1959 | | { |
| 1960 | | verboselog(machine, 0, "Message sector, ignored\n" ); |
| 1961 | | } |
| 1962 | | } |
| 1963 | | else /*if(buffer[CDIC_SECTOR_SUBMODE2] & (CDIC_SUBMODE_DATA | CDIC_SUBMODE_VIDEO))*/ |
| 1964 | | { |
| 1965 | | cdic->x_buffer |= 0x8000; |
| 1966 | | //cdic->data_buffer |= 0x4000; |
| 1967 | | |
| 1968 | | for(index = 6; index < 2352/2; index++) |
| 1969 | | { |
| 1970 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 1971 | | } |
| 1972 | | |
| 1973 | | //printf( "Setting CDIC interrupt line\n" ); |
| 1974 | | verboselog(machine, 0, "Setting CDIC interrupt line for data sector\n" ); |
| 1975 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 1976 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 1977 | | } |
| 1978 | | } |
| 1979 | | |
| 1980 | | if((buffer[CDIC_SECTOR_SUBMODE2] & CDIC_SUBMODE_EOF) == 0 && cdic->command != 0x23) |
| 1981 | | { |
| 1982 | | timer_adjust_oneshot(cdic->interrupt_timer, ATTOTIME_IN_HZ(75), 0); // 75Hz = 1x CD-ROM speed |
| 1983 | | } |
| 1984 | | else |
| 1985 | | { |
| 1986 | | if(cdic->command == 0x23) // Mode 1 Reset |
| 1987 | | { |
| 1988 | | timer_adjust_oneshot(cdic->interrupt_timer, attotime_never, 0); |
| 1989 | | } |
| 1990 | | } |
| 1991 | | } |
| 1992 | | |
| 1993 | | break; |
| 1994 | | } |
| 1995 | | //case 0x24: // Mode 2 Reset |
| 1996 | | case 0x2e: // Abort |
| 1997 | | timer_adjust_oneshot(cdic->interrupt_timer, attotime_never, 0); |
| 1998 | | //cdic->data_buffer &= ~4; |
| 1999 | | break; |
| 2000 | | case 0x28: // Play CDDA audio |
| 2001 | | { |
| 2002 | | UINT8 buffer[2560] = { 0 }; |
| 2003 | | int index = 0; |
| 2004 | | UINT32 msf = (cdic->time & 0xffff7f00) >> 8; |
| 2005 | | UINT32 next_msf = increment_cdda_frame_bcd((cdic->time & 0xffff7f00) >> 8); |
| 2006 | | UINT32 rounded_next_msf = increment_cdda_sector_bcd((cdic->time & 0xffff0000) >> 8); |
| 2007 | | UINT32 lba = 0; |
| 2008 | | UINT32 next_lba = 0; |
| 2009 | | UINT8 nybbles[6] = |
| 2010 | | { |
| 2011 | | msf & 0x0000000f, |
| 2012 | | (msf & 0x000000f0) >> 4, |
| 2013 | | (msf & 0x00000f00) >> 8, |
| 2014 | | (msf & 0x0000f000) >> 12, |
| 2015 | | (msf & 0x000f0000) >> 16, |
| 2016 | | (msf & 0x00f00000) >> 20 |
| 2017 | | }; |
| 2018 | | UINT8 next_nybbles[6] = |
| 2019 | | { |
| 2020 | | rounded_next_msf & 0x0000000f, |
| 2021 | | (rounded_next_msf & 0x000000f0) >> 4, |
| 2022 | | (rounded_next_msf & 0x00000f00) >> 8, |
| 2023 | | (rounded_next_msf & 0x0000f000) >> 12, |
| 2024 | | (rounded_next_msf & 0x000f0000) >> 16, |
| 2025 | | (rounded_next_msf & 0x00f00000) >> 20 |
| 2026 | | }; |
| 2027 | | |
| 2028 | | lba = nybbles[0] + nybbles[1]*10 + ((nybbles[2] + nybbles[3]*10)*75) + ((nybbles[4] + nybbles[5]*10)*75*60); |
| 2029 | | |
| 2030 | | cdrom_read_data(cdic->cd, lba, buffer, CD_TRACK_RAW_DONTCARE); |
| 2031 | | |
| 2032 | | if(!(msf & 0x0000ff)) |
| 2033 | | { |
| 2034 | | next_lba = next_nybbles[0] + next_nybbles[1]*10 + ((next_nybbles[2] + next_nybbles[3]*10)*75) + ((next_nybbles[4] + next_nybbles[5]*10)*75*60); |
| 2035 | | |
| 2036 | | verboselog(machine, 0, "Playing CDDA sector from MSF location %06x\n", cdic->time | 2 ); |
| 2037 | | |
| 2038 | | cdda_start_audio(machine->device("cdda"), lba, rounded_next_msf); |
| 2039 | | |
| 2040 | | } |
| 2041 | | |
| 2042 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x924/2] = 0x0001; // CTRL |
| 2043 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x926/2] = 0x0001; // TRACK |
| 2044 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x928/2] = 0x0000; // INDEX |
| 2045 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92a/2] = (cdic->time >> 24) & 0x000000ff; // MIN |
| 2046 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92c/2] = (cdic->time >> 16) & 0x000000ff; // SEC |
| 2047 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92e/2] = (cdic->time >> 8) & 0x0000007f; // FRAC |
| 2048 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x930/2] = 0x0000; // ZERO |
| 2049 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x932/2] = (cdic->time >> 24) & 0x000000ff; // AMIN |
| 2050 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x934/2] = (cdic->time >> 16) & 0x000000ff; // ASEC |
| 2051 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x936/2] = (cdic->time >> 8) & 0x0000007f; // AFRAC |
| 2052 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x938/2] = 0x0000; // CRC1 |
| 2053 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x93a/2] = 0x0000; // CRC2 |
| 2054 | | |
| 2055 | | cdic->time = next_msf << 8; |
| 2056 | | |
| 2057 | | timer_adjust_oneshot(cdic->interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 2058 | | |
| 2059 | | cdic->x_buffer |= 0x8000; |
| 2060 | | //cdic->data_buffer |= 0x4000; |
| 2061 | | |
| 2062 | | for(index = 6; index < 2352/2; index++) |
| 2063 | | { |
| 2064 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 2065 | | } |
| 2066 | | |
| 2067 | | verboselog(machine, 0, "Setting CDIC interrupt line for CDDA sector\n" ); |
| 2068 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 2069 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 2070 | | break; |
| 2071 | | } |
| 2072 | | case 0x2c: // Seek |
| 2073 | | { |
| 2074 | | UINT8 buffer[2560] = { 0 }; |
| 2075 | | int index = 0; |
| 2076 | | UINT32 msf = (cdic->time & 0xffff7f00) >> 8; |
| 2077 | | UINT32 next_msf = increment_cdda_frame_bcd((cdic->time & 0xffff7f00) >> 8); |
| 2078 | | UINT32 lba = 0; |
| 2079 | | UINT8 nybbles[6] = |
| 2080 | | { |
| 2081 | | msf & 0x0000000f, |
| 2082 | | (msf & 0x000000f0) >> 4, |
| 2083 | | (msf & 0x00000f00) >> 8, |
| 2084 | | (msf & 0x0000f000) >> 12, |
| 2085 | | (msf & 0x000f0000) >> 16, |
| 2086 | | (msf & 0x00f00000) >> 20 |
| 2087 | | }; |
| 2088 | | lba = nybbles[0] + nybbles[1]*10 + ((nybbles[2] + nybbles[3]*10)*75) + ((nybbles[4] + nybbles[5]*10)*75*60); |
| 2089 | | |
| 2090 | | timer_adjust_oneshot(cdic->interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 2091 | | |
| 2092 | | cdrom_read_data(cdic->cd, lba, buffer, CD_TRACK_RAW_DONTCARE); |
| 2093 | | |
| 2094 | | cdic->data_buffer ^= 0x0001; |
| 2095 | | cdic->x_buffer |= 0x8000; |
| 2096 | | cdic->data_buffer |= 0x4000; |
| 2097 | | |
| 2098 | | for(index = 6; index < 2352/2; index++) |
| 2099 | | { |
| 2100 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + (index - 6)] = (buffer[index*2] << 8) | buffer[index*2 + 1]; |
| 2101 | | } |
| 2102 | | |
| 2103 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x924/2] = 0x0041; // CTRL |
| 2104 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x926/2] = 0x0001; // TRACK |
| 2105 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x928/2] = 0x0000; // INDEX |
| 2106 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92a/2] = (cdic->time >> 24) & 0x000000ff; // MIN |
| 2107 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92c/2] = (cdic->time >> 16) & 0x000000ff; // SEC |
| 2108 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x92e/2] = (cdic->time >> 8) & 0x0000007f; // FRAC |
| 2109 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x930/2] = 0x0000; // ZERO |
| 2110 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x932/2] = (cdic->time >> 24) & 0x000000ff; // AMIN |
| 2111 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x934/2] = (cdic->time >> 16) & 0x000000ff; // ASEC |
| 2112 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x936/2] = (cdic->time >> 8) & 0x0000007f; // AFRAC |
| 2113 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x938/2] = 0x0000; // CRC1 |
| 2114 | | cdic->ram[(cdic->data_buffer & 5) * (0xa00/2) + 0x93a/2] = 0x0000; // CRC2 |
| 2115 | | |
| 2116 | | cdic->time = next_msf << 8; |
| 2117 | | |
| 2118 | | verboselog(machine, 0, "Setting CDIC interrupt line for Seek sector\n" ); |
| 2119 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 128); |
| 2120 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 2121 | | break; |
| 2122 | | } |
| 2123 | | } |
| 2124 | | } |
| 2125 | | |
| 2126 | | static READ16_HANDLER( cdic_r ) |
| 2127 | | { |
| 2128 | | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 2129 | | cdic_regs_t *cdic = &state->cdic_regs; |
| 2130 | | |
| 2131 | | offset += 0x3c00/2; |
| 2132 | | switch(offset) |
| 2133 | | { |
| 2134 | | case 0x3c00/2: // Command register |
| 2135 | | verboselog(space->machine, 0, "cdic_r: Command Register = %04x & %04x\n", cdic->command, mem_mask); |
| 2136 | | return cdic->command; |
| 2137 | | |
| 2138 | | case 0x3c02/2: // Time register (MSW) |
| 2139 | | verboselog(space->machine, 0, "cdic_r: Time Register (MSW) = %04x & %04x\n", cdic->time >> 16, mem_mask); |
| 2140 | | return cdic->time >> 16; |
| 2141 | | |
| 2142 | | case 0x3c04/2: // Time register (LSW) |
| 2143 | | verboselog(space->machine, 0, "cdic_r: Time Register (LSW) = %04x & %04x\n", (UINT16)(cdic->time & 0x0000ffff), mem_mask); |
| 2144 | | return cdic->time & 0x0000ffff; |
| 2145 | | |
| 2146 | | case 0x3c06/2: // File register |
| 2147 | | verboselog(space->machine, 0, "cdic_r: File Register = %04x & %04x\n", cdic->file, mem_mask); |
| 2148 | | return cdic->file; |
| 2149 | | |
| 2150 | | case 0x3c08/2: // Channel register (MSW) |
| 2151 | | verboselog(space->machine, 0, "cdic_r: Channel Register (MSW) = %04x & %04x\n", cdic->channel >> 16, mem_mask); |
| 2152 | | return cdic->channel >> 16; |
| 2153 | | |
| 2154 | | case 0x3c0a/2: // Channel register (LSW) |
| 2155 | | verboselog(space->machine, 0, "cdic_r: Channel Register (LSW) = %04x & %04x\n", cdic->channel & 0x0000ffff, mem_mask); |
| 2156 | | return cdic->channel & 0x0000ffff; |
| 2157 | | |
| 2158 | | case 0x3c0c/2: // Audio Channel register |
| 2159 | | verboselog(space->machine, 0, "cdic_r: Audio Channel Register = %04x & %04x\n", cdic->audio_channel, mem_mask); |
| 2160 | | return cdic->audio_channel; |
| 2161 | | |
| 2162 | | case 0x3ff4/2: // ABUF |
| 2163 | | { |
| 2164 | | UINT16 temp = cdic->audio_buffer; |
| 2165 | | cdic->audio_buffer &= 0x7fff; |
| 2166 | | if(!((cdic->audio_buffer | cdic->x_buffer) & 0x8000)) |
| 2167 | | { |
| 2168 | | cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE); |
| 2169 | | verboselog(space->machine, 0, "Clearing CDIC interrupt line\n" ); |
| 2170 | | //printf("Clearing CDIC interrupt line\n" ); |
| 2171 | | } |
| 2172 | | verboselog(space->machine, 0, "cdic_r: Audio Buffer Register = %04x & %04x\n", temp, mem_mask); |
| 2173 | | return temp; |
| 2174 | | } |
| 2175 | | |
| 2176 | | case 0x3ff6/2: // XBUF |
| 2177 | | { |
| 2178 | | UINT16 temp = cdic->x_buffer; |
| 2179 | | cdic->x_buffer &= 0x7fff; |
| 2180 | | if(!((cdic->audio_buffer | cdic->x_buffer) & 0x8000)) |
| 2181 | | { |
| 2182 | | cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_4, CLEAR_LINE); |
| 2183 | | verboselog(space->machine, 0, "Clearing CDIC interrupt line\n" ); |
| 2184 | | //printf("Clearing CDIC interrupt line\n" ); |
| 2185 | | } |
| 2186 | | verboselog(space->machine, 0, "cdic_r: X-Buffer Register = %04x & %04x\n", temp, mem_mask); |
| 2187 | | return temp; |
| 2188 | | } |
| 2189 | | |
| 2190 | | case 0x3ffa/2: // AUDCTL |
| 2191 | | { |
| 2192 | | if(attotime_is_never(timer_timeleft(cdic->audio_sample_timer))) |
| 2193 | | { |
| 2194 | | cdic->z_buffer ^= 0x0001; |
| 2195 | | } |
| 2196 | | verboselog(space->machine, 0, "cdic_r: Z-Buffer Register = %04x & %04x\n", cdic->z_buffer, mem_mask); |
| 2197 | | return cdic->z_buffer; |
| 2198 | | } |
| 2199 | | |
| 2200 | | case 0x3ffe/2: |
| 2201 | | { |
| 2202 | | verboselog(space->machine, 0, "cdic_r: Data buffer Register = %04x & %04x\n", cdic->data_buffer, mem_mask); |
| 2203 | | return cdic->data_buffer; |
| 2204 | | } |
| 2205 | | default: |
| 2206 | | verboselog(space->machine, 0, "cdic_r: UNIMPLEMENTED: Unknown address: %04x & %04x\n", offset*2, mem_mask); |
| 2207 | | return 0; |
| 2208 | | } |
| 2209 | | } |
| 2210 | | |
| 2211 | | static WRITE16_HANDLER( cdic_w ) |
| 2212 | | { |
| 2213 | | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 2214 | | cdic_regs_t *cdic = &state->cdic_regs; |
| 2215 | | |
| 2216 | | offset += 0x3c00/2; |
| 2217 | | switch(offset) |
| 2218 | | { |
| 2219 | | case 0x3c00/2: // Command register |
| 2220 | | verboselog(space->machine, 0, "cdic_w: Command Register = %04x & %04x\n", data, mem_mask); |
| 2221 | | COMBINE_DATA(&cdic->command); |
| 2222 | | //printf( "cdic command: %04x\n", cdic->command ); |
| 2223 | | break; |
| 2224 | | |
| 2225 | | case 0x3c02/2: // Time register (MSW) |
| 2226 | | cdic->time &= ~(mem_mask << 16); |
| 2227 | | cdic->time |= (data & mem_mask) << 16; |
| 2228 | | verboselog(space->machine, 0, "cdic_w: Time Register (MSW) = %04x & %04x\n", data, mem_mask); |
| 2229 | | break; |
| 2230 | | |
| 2231 | | case 0x3c04/2: // Time register (LSW) |
| 2232 | | cdic->time &= ~mem_mask; |
| 2233 | | cdic->time |= data & mem_mask; |
| 2234 | | verboselog(space->machine, 0, "cdic_w: Time Register (LSW) = %04x & %04x\n", data, mem_mask); |
| 2235 | | break; |
| 2236 | | |
| 2237 | | case 0x3c06/2: // File register |
| 2238 | | verboselog(space->machine, 0, "cdic_w: File Register = %04x & %04x\n", data, mem_mask); |
| 2239 | | COMBINE_DATA(&cdic->file); |
| 2240 | | break; |
| 2241 | | |
| 2242 | | case 0x3c08/2: // Channel register (MSW) |
| 2243 | | cdic->channel &= ~(mem_mask << 16); |
| 2244 | | cdic->channel |= (data & mem_mask) << 16; |
| 2245 | | verboselog(space->machine, 0, "cdic_w: Channel Register (MSW) = %04x & %04x\n", data, mem_mask); |
| 2246 | | break; |
| 2247 | | |
| 2248 | | case 0x3c0a/2: // Channel register (LSW) |
| 2249 | | cdic->channel &= ~mem_mask; |
| 2250 | | cdic->channel |= data & mem_mask; |
| 2251 | | verboselog(space->machine, 0, "cdic_w: Channel Register (LSW) = %04x & %04x\n", data, mem_mask); |
| 2252 | | break; |
| 2253 | | |
| 2254 | | case 0x3c0c/2: // Audio Channel register |
| 2255 | | verboselog(space->machine, 0, "cdic_w: Audio Channel Register = %04x & %04x\n", data, mem_mask); |
| 2256 | | COMBINE_DATA(&cdic->audio_channel); |
| 2257 | | break; |
| 2258 | | |
| 2259 | | case 0x3ff4/2: |
| 2260 | | verboselog(space->machine, 0, "cdic_w: Audio Buffer Register = %04x & %04x\n", data, mem_mask); |
| 2261 | | COMBINE_DATA(&cdic->audio_buffer); |
| 2262 | | break; |
| 2263 | | |
| 2264 | | case 0x3ff6/2: |
| 2265 | | verboselog(space->machine, 0, "cdic_w: X Buffer Register = %04x & %04x\n", data, mem_mask); |
| 2266 | | COMBINE_DATA(&cdic->x_buffer); |
| 2267 | | break; |
| 2268 | | |
| 2269 | | case 0x3ff8/2: |
| 2270 | | { |
| 2271 | | scc68070_regs_t *scc68070 = &state->scc68070_regs; |
| 2272 | | UINT32 start = scc68070->dma.channel[0].memory_address_counter; |
| 2273 | | UINT32 count = scc68070->dma.channel[0].transfer_counter; |
| 2274 | | UINT32 index = 0; |
| 2275 | | UINT32 device_index = (data & 0x3fff) >> 1; |
| 2276 | | UINT16 *memory = state->planea; |
| 2277 | | verboselog(space->machine, 0, "memory address counter: %08x\n", scc68070->dma.channel[0].memory_address_counter); |
| 2278 | | verboselog(space->machine, 0, "cdic_w: DMA Control Register = %04x & %04x\n", data, mem_mask); |
| 2279 | | verboselog(space->machine, 0, "Doing copy, transferring %04x bytes\n", count * 2 ); |
| 2280 | | //printf("Doing copy, transferring %04x bytes\n", count * 2 ); |
| 2281 | | if((start & 0x00f00000) == 0x00200000) |
| 2282 | | { |
| 2283 | | start -= 0x00200000; |
| 2284 | | memory = state->planeb; |
| 2285 | | } |
| 2286 | | for(index = start / 2; index < (start / 2 + count); index++) |
| 2287 | | { |
| 2288 | | if(scc68070->dma.channel[0].operation_control & OCR_D) |
| 2289 | | { |
| 2290 | | memory[index] = cdic->ram[device_index++]; |
| 2291 | | } |
| 2292 | | else |
| 2293 | | { |
| 2294 | | cdic->ram[device_index++] = memory[index]; |
| 2295 | | } |
| 2296 | | } |
| 2297 | | scc68070->dma.channel[0].memory_address_counter += scc68070->dma.channel[0].transfer_counter * 2; |
| 2298 | | break; |
| 2299 | | } |
| 2300 | | |
| 2301 | | case 0x3ffa/2: |
| 2302 | | { |
| 2303 | | verboselog(space->machine, 0, "cdic_w: Z-Buffer Register = %04x & %04x\n", data, mem_mask); |
| 2304 | | COMBINE_DATA(&cdic->z_buffer); |
| 2305 | | if(cdic->z_buffer & 0x2000) |
| 2306 | | { |
| 2307 | | attotime period = timer_timeleft(cdic->audio_sample_timer); |
| 2308 | | if(attotime_is_never(period)) |
| 2309 | | { |
| 2310 | | cdic->decode_addr = cdic->z_buffer & 0x3a00; |
| 2311 | | cdic->decode_delay = 1; |
| 2312 | | timer_adjust_oneshot(cdic->audio_sample_timer, ATTOTIME_IN_HZ(75), 0); |
| 2313 | | } |
| 2314 | | } |
| 2315 | | else |
| 2316 | | { |
| 2317 | | cdic->decode_addr = 0xffff; |
| 2318 | | timer_adjust_oneshot(cdic->audio_sample_timer, attotime_never, 0); |
| 2319 | | } |
| 2320 | | break; |
| 2321 | | } |
| 2322 | | case 0x3ffc/2: |
| 2323 | | verboselog(space->machine, 0, "cdic_w: Interrupt Vector Register = %04x & %04x\n", data, mem_mask); |
| 2324 | | COMBINE_DATA(&cdic->interrupt_vector); |
| 2325 | | break; |
| 2326 | | case 0x3ffe/2: |
| 2327 | | { |
| 2328 | | verboselog(space->machine, 0, "cdic_w: Data Buffer Register = %04x & %04x\n", data, mem_mask); |
| 2329 | | COMBINE_DATA(&cdic->data_buffer); |
| 2330 | | if(cdic->data_buffer & 0x8000) |
| 2331 | | { |
| 2332 | | switch(cdic->command) |
| 2333 | | { |
| 2334 | | //case 0x24: // Reset Mode 2 |
| 2335 | | case 0x2e: // Abort |
| 2336 | | { |
| 2337 | | timer_adjust_oneshot(cdic->interrupt_timer, attotime_never, 0); |
| 2338 | | dmadac_enable(&state->dmadac[0], 2, 0); |
| 2339 | | //cdic->data_buffer &= 0xbfff; |
| 2340 | | break; |
| 2341 | | } |
| 2342 | | case 0x2b: // Stop CDDA |
| 2343 | | cdda_stop_audio(space->machine->device("cdda")); |
| 2344 | | timer_adjust_oneshot(cdic->interrupt_timer, attotime_never, 0); |
| 2345 | | break; |
| 2346 | | case 0x23: // Reset Mode 1 |
| 2347 | | case 0x29: // Read Mode 1 |
| 2348 | | case 0x2a: // Read Mode 2 |
| 2349 | | case 0x28: // Play CDDA |
| 2350 | | case 0x2c: // Seek |
| 2351 | | { |
| 2352 | | attotime period = timer_timeleft(cdic->interrupt_timer); |
| 2353 | | if(!attotime_is_never(period)) |
| 2354 | | { |
| 2355 | | timer_adjust_oneshot(cdic->interrupt_timer, period, 0); |
| 2356 | | } |
| 2357 | | else |
| 2358 | | { |
| 2359 | | if(cdic->command != 0x23 && cdic->command != 0x24) |
| 2360 | | { |
| 2361 | | timer_adjust_oneshot(cdic->interrupt_timer, ATTOTIME_IN_HZ(75), 0); |
| 2362 | | } |
| 2363 | | } |
| 2364 | | break; |
| 2365 | | } |
| 2366 | | default: |
| 2367 | | verboselog(space->machine, 0, "Unknown CDIC command: %02x\n", cdic->command ); |
| 2368 | | break; |
| 2369 | | } |
| 2370 | | } |
| 2371 | | cdic->data_buffer &= 0x7fff; |
| 2372 | | break; |
| 2373 | | } |
| 2374 | | default: |
| 2375 | | verboselog(space->machine, 0, "cdic_w: UNIMPLEMENTED: Unknown address: %04x = %04x & %04x\n", offset*2, data, mem_mask); |
| 2376 | | break; |
| 2377 | | } |
| 2378 | | } |
| 2379 | | |
| 2380 | | static void cdic_init(running_machine *machine, cdic_regs_t *cdic) |
| 2381 | | { |
| 2382 | | cdic->command = 0; |
| 2383 | | cdic->time = 0; |
| 2384 | | cdic->file = 0; |
| 2385 | | cdic->channel = 0xffffffff; |
| 2386 | | cdic->audio_channel = 0xffff; |
| 2387 | | cdic->audio_buffer = 0; |
| 2388 | | cdic->x_buffer = 0; |
| 2389 | | cdic->dma_control = 0; |
| 2390 | | cdic->z_buffer = 0; |
| 2391 | | cdic->interrupt_vector = 0; |
| 2392 | | cdic->data_buffer = 0; |
| 2393 | | |
| 2394 | | cdic->audio_sample_freq = 0; |
| 2395 | | cdic->audio_sample_size = 0; |
| 2396 | | |
| 2397 | | cdic->decode_addr = 0; |
| 2398 | | cdic->decode_delay = 0; |
| 2399 | | } |
| 2400 | | |
| 2401 | | static void cdic_register_globals(running_machine *machine, cdic_regs_t *cdic) |
| 2402 | | { |
| 2403 | | state_save_register_global(machine, cdic->command); |
| 2404 | | state_save_register_global(machine, cdic->time); |
| 2405 | | state_save_register_global(machine, cdic->file); |
| 2406 | | state_save_register_global(machine, cdic->channel); |
| 2407 | | state_save_register_global(machine, cdic->audio_channel); |
| 2408 | | state_save_register_global(machine, cdic->audio_buffer); |
| 2409 | | state_save_register_global(machine, cdic->x_buffer); |
| 2410 | | state_save_register_global(machine, cdic->dma_control); |
| 2411 | | state_save_register_global(machine, cdic->z_buffer); |
| 2412 | | state_save_register_global(machine, cdic->interrupt_vector); |
| 2413 | | state_save_register_global(machine, cdic->data_buffer); |
| 2414 | | |
| 2415 | | state_save_register_global(machine, cdic->audio_sample_freq); |
| 2416 | | state_save_register_global(machine, cdic->audio_sample_size); |
| 2417 | | } |
| 2418 | | |
| 2419 | | static TIMER_CALLBACK( slave_trigger_readback_int ) |
| 2420 | | { |
| 2421 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 2422 | | slave_regs_t *slave = &state->slave_regs; |
| 2423 | | |
| 2424 | | verboselog(machine, 0, "Asserting IRQ2\n" ); |
| 2425 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_2, 26); |
| 2426 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_2, ASSERT_LINE); |
| 2427 | | timer_adjust_oneshot(slave->interrupt_timer, attotime_never, 0); |
| 2428 | | } |
| 2429 | | |
| 2430 | | static void slave_prepare_readback(running_machine *machine, attotime delay, UINT8 channel, UINT8 count, UINT8 data0, UINT8 data1, UINT8 data2, UINT8 data3, UINT8 cmd) |
| 2431 | | { |
| 2432 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 2433 | | slave_regs_t *slave = &state->slave_regs; |
| 2434 | | |
| 2435 | | slave->channel[channel].out_index = 0; |
| 2436 | | slave->channel[channel].out_count = count; |
| 2437 | | slave->channel[channel].out_buf[0] = data0; |
| 2438 | | slave->channel[channel].out_buf[1] = data1; |
| 2439 | | slave->channel[channel].out_buf[2] = data2; |
| 2440 | | slave->channel[channel].out_buf[3] = data3; |
| 2441 | | slave->channel[channel].out_cmd = cmd; |
| 2442 | | |
| 2443 | | timer_adjust_oneshot(slave->interrupt_timer, delay, 0); |
| 2444 | | } |
| 2445 | | |
| 2446 | | static void perform_mouse_update(running_machine *machine) |
| 2447 | | { |
| 2448 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 2449 | | slave_regs_t *slave = &state->slave_regs; |
| 2450 | | UINT16 x = input_port_read(machine, "MOUSEX"); |
| 2451 | | UINT16 y = input_port_read(machine, "MOUSEY"); |
| 2452 | | UINT8 buttons = input_port_read(machine, "MOUSEBTN"); |
| 2453 | | |
| 2454 | | UINT16 old_mouse_x = slave->real_mouse_x; |
| 2455 | | UINT16 old_mouse_y = slave->real_mouse_y; |
| 2456 | | |
| 2457 | | if(slave->real_mouse_x == 0xffff) |
| 2458 | | { |
| 2459 | | old_mouse_x = x & 0x3ff; |
| 2460 | | old_mouse_y = y & 0x3ff; |
| 2461 | | } |
| 2462 | | |
| 2463 | | slave->real_mouse_x = x & 0x3ff; |
| 2464 | | slave->real_mouse_y = y & 0x3ff; |
| 2465 | | |
| 2466 | | slave->fake_mouse_x += (slave->real_mouse_x - old_mouse_x); |
| 2467 | | slave->fake_mouse_y += (slave->real_mouse_y - old_mouse_y); |
| 2468 | | |
| 2469 | | while(slave->fake_mouse_x > 0x3ff) |
| 2470 | | { |
| 2471 | | slave->fake_mouse_x += 0x400; |
| 2472 | | } |
| 2473 | | |
| 2474 | | while(slave->fake_mouse_y > 0x3ff) |
| 2475 | | { |
| 2476 | | slave->fake_mouse_y += 0x400; |
| 2477 | | } |
| 2478 | | |
| 2479 | | x = slave->fake_mouse_x; |
| 2480 | | y = slave->fake_mouse_y; |
| 2481 | | |
| 2482 | | if(slave->polling_active) |
| 2483 | | { |
| 2484 | | slave_prepare_readback(machine, attotime_zero, 0, 4, ((x & 0x380) >> 7) | (buttons << 4), x & 0x7f, (y & 0x380) >> 7, y & 0x7f, 0xf7); |
| 2485 | | } |
| 2486 | | } |
| 2487 | | |
| 2488 | | static INPUT_CHANGED( mouse_update ) |
| 2489 | | { |
| 2490 | | perform_mouse_update(field->port->machine); |
| 2491 | | } |
| 2492 | | |
| 2493 | | static READ16_HANDLER( slave_r ) |
| 2494 | | { |
| 2495 | | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 2496 | | slave_regs_t *slave = &state->slave_regs; |
| 2497 | | |
| 2498 | | if(slave->channel[offset].out_count) |
| 2499 | | { |
| 2500 | | UINT8 ret = slave->channel[offset].out_buf[slave->channel[offset].out_index]; |
| 2501 | | verboselog(space->machine, 0, "slave_r: Channel %d: %d, %02x\n", offset, slave->channel[offset].out_index, ret ); |
| 2502 | | if(slave->channel[offset].out_index == 0) |
| 2503 | | { |
| 2504 | | switch(slave->channel[offset].out_cmd) |
| 2505 | | { |
| 2506 | | case 0xb0: |
| 2507 | | case 0xb1: |
| 2508 | | case 0xf0: |
| 2509 | | case 0xf3: |
| 2510 | | case 0xf7: |
| 2511 | | verboselog(space->machine, 0, "slave_r: De-asserting IRQ2\n" ); |
| 2512 | | cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_2, CLEAR_LINE); |
| 2513 | | break; |
| 2514 | | } |
| 2515 | | } |
| 2516 | | slave->channel[offset].out_index++; |
| 2517 | | slave->channel[offset].out_count--; |
| 2518 | | if(!slave->channel[offset].out_count) |
| 2519 | | { |
| 2520 | | slave->channel[offset].out_index = 0; |
| 2521 | | slave->channel[offset].out_cmd = 0; |
| 2522 | | memset(slave->channel[offset].out_buf, 0, 4); |
| 2523 | | } |
| 2524 | | return ret; |
| 2525 | | } |
| 2526 | | verboselog(space->machine, 0, "slave_r: Channel %d: %d\n", offset, slave->channel[offset].out_index ); |
| 2527 | | return 0xff; |
| 2528 | | } |
| 2529 | | |
| 2530 | | static void set_mouse_position(running_machine* machine) |
| 2531 | | { |
| 2532 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 2533 | | slave_regs_t *slave = &state->slave_regs; |
| 2534 | | UINT16 x, y; |
| 2535 | | |
| 2536 | | //printf( "Set mouse position: %02x %02x %02x\n", slave->in_buf[0], slave->in_buf[1], slave->in_buf[2] ); |
| 2537 | | |
| 2538 | | slave->fake_mouse_y = ((slave->in_buf[1] & 0x0f) << 6) | (slave->in_buf[0] & 0x3f); |
| 2539 | | slave->fake_mouse_x = ((slave->in_buf[1] & 0x70) << 3) | slave->in_buf[2]; |
| 2540 | | |
| 2541 | | x = slave->fake_mouse_x; |
| 2542 | | y = slave->fake_mouse_y; |
| 2543 | | |
| 2544 | | if(slave->polling_active) |
| 2545 | | { |
| 2546 | | //slave_prepare_readback(machine, attotime_zero, 0, 4, (x & 0x380) >> 7, x & 0x7f, (y & 0x380) >> 7, y & 0x7f, 0xf7); |
| 2547 | | } |
| 2548 | | } |
| 2549 | | |
| 2550 | | static WRITE16_HANDLER( slave_w ) |
| 2551 | | { |
| 2552 | | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 2553 | | slave_regs_t *slave = &state->slave_regs; |
| 2554 | | |
| 2555 | | switch(offset) |
| 2556 | | { |
| 2557 | | case 0: |
| 2558 | | if(slave->in_index) |
| 2559 | | { |
| 2560 | | verboselog(space->machine, 0, "slave_w: Channel %d: %d = %02x\n", offset, slave->in_index, data & 0x00ff ); |
| 2561 | | slave->in_buf[slave->in_index] = data & 0x00ff; |
| 2562 | | slave->in_index++; |
| 2563 | | if(slave->in_index == slave->in_count) |
| 2564 | | { |
| 2565 | | switch(slave->in_buf[0]) |
| 2566 | | { |
| 2567 | | case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7: |
| 2568 | | case 0xc8: case 0xc9: case 0xca: case 0xcb: case 0xcc: case 0xcd: case 0xce: case 0xcf: |
| 2569 | | case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7: |
| 2570 | | case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf: |
| 2571 | | case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7: |
| 2572 | | case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef: |
| 2573 | | case 0xf0: case 0xf1: case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf6: case 0xf7: |
| 2574 | | case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff: // Update Mouse Position |
| 2575 | | set_mouse_position(space->machine); |
| 2576 | | memset(slave->in_buf, 0, 17); |
| 2577 | | slave->in_index = 0; |
| 2578 | | slave->in_count = 0; |
| 2579 | | break; |
| 2580 | | } |
| 2581 | | } |
| 2582 | | } |
| 2583 | | else |
| 2584 | | { |
| 2585 | | slave->in_buf[slave->in_index] = data & 0x00ff; |
| 2586 | | slave->in_index++; |
| 2587 | | switch(data & 0x00ff) |
| 2588 | | { |
| 2589 | | case 0xc0: case 0xc1: case 0xc2: case 0xc3: case 0xc4: case 0xc5: case 0xc6: case 0xc7: |
| 2590 | | case 0xc8: case 0xc9: case 0xca: case 0xcb: case 0xcc: case 0xcd: case 0xce: case 0xcf: |
| 2591 | | case 0xd0: case 0xd1: case 0xd2: case 0xd3: case 0xd4: case 0xd5: case 0xd6: case 0xd7: |
| 2592 | | case 0xd8: case 0xd9: case 0xda: case 0xdb: case 0xdc: case 0xdd: case 0xde: case 0xdf: |
| 2593 | | case 0xe0: case 0xe1: case 0xe2: case 0xe3: case 0xe4: case 0xe5: case 0xe6: case 0xe7: |
| 2594 | | case 0xe8: case 0xe9: case 0xea: case 0xeb: case 0xec: case 0xed: case 0xee: case 0xef: |
| 2595 | | case 0xf0: case 0xf1: case 0xf2: case 0xf3: case 0xf4: case 0xf5: case 0xf6: case 0xf7: |
| 2596 | | case 0xf8: case 0xf9: case 0xfa: case 0xfb: case 0xfc: case 0xfd: case 0xfe: case 0xff: |
| 2597 | | verboselog(space->machine, 0, "slave_w: Channel %d: Update Mouse Position (0x%02x)\n", offset, data & 0x00ff ); |
| 2598 | | slave->in_count = 3; |
| 2599 | | break; |
| 2600 | | default: |
| 2601 | | verboselog(space->machine, 0, "slave_w: Channel %d: Unknown register: %02x\n", offset, data & 0x00ff ); |
| 2602 | | slave->in_index = 0; |
| 2603 | | break; |
| 2604 | | } |
| 2605 | | } |
| 2606 | | break; |
| 2607 | | case 1: |
| 2608 | | if(slave->in_index) |
| 2609 | | { |
| 2610 | | verboselog(space->machine, 0, "slave_w: Channel %d: %d = %02x\n", offset, slave->in_index, data & 0x00ff ); |
| 2611 | | slave->in_buf[slave->in_index] = data & 0x00ff; |
| 2612 | | slave->in_index++; |
| 2613 | | if(slave->in_index == slave->in_count) |
| 2614 | | { |
| 2615 | | switch(slave->in_buf[0]) |
| 2616 | | { |
| 2617 | | case 0xf0: // Set Front Panel LCD |
| 2618 | | memcpy(slave->lcd_state, slave->in_buf + 1, 16); |
| 2619 | | memset(slave->in_buf, 0, 17); |
| 2620 | | slave->in_index = 0; |
| 2621 | | slave->in_count = 0; |
| 2622 | | break; |
| 2623 | | default: |
| 2624 | | memset(slave->in_buf, 0, 17); |
| 2625 | | slave->in_index = 0; |
| 2626 | | slave->in_count = 0; |
| 2627 | | break; |
| 2628 | | } |
| 2629 | | } |
| 2630 | | } |
| 2631 | | else |
| 2632 | | { |
| 2633 | | switch(data & 0x00ff) |
| 2634 | | { |
| 2635 | | default: |
| 2636 | | verboselog(space->machine, 0, "slave_w: Channel %d: Unknown register: %02x\n", offset, data & 0x00ff ); |
| 2637 | | memset(slave->in_buf, 0, 17); |
| 2638 | | slave->in_index = 0; |
| 2639 | | slave->in_count = 0; |
| 2640 | | break; |
| 2641 | | } |
| 2642 | | } |
| 2643 | | break; |
| 2644 | | case 2: |
| 2645 | | if(slave->in_index) |
| 2646 | | { |
| 2647 | | verboselog(space->machine, 0, "slave_w: Channel %d: %d = %02x\n", offset, slave->in_index, data & 0x00ff ); |
| 2648 | | slave->in_buf[slave->in_index] = data & 0x00ff; |
| 2649 | | slave->in_index++; |
| 2650 | | if(slave->in_index == slave->in_count) |
| 2651 | | { |
| 2652 | | switch(slave->in_buf[0]) |
| 2653 | | { |
| 2654 | | case 0xf0: // Set Front Panel LCD |
| 2655 | | memset(slave->in_buf + 1, 0, 16); |
| 2656 | | slave->in_count = 17; |
| 2657 | | break; |
| 2658 | | default: |
| 2659 | | memset(slave->in_buf, 0, 17); |
| 2660 | | slave->in_index = 0; |
| 2661 | | slave->in_count = 0; |
| 2662 | | break; |
| 2663 | | } |
| 2664 | | } |
| 2665 | | } |
| 2666 | | else |
| 2667 | | { |
| 2668 | | slave->in_buf[slave->in_index] = data & 0x00ff; |
| 2669 | | slave->in_index++; |
| 2670 | | switch(data & 0x00ff) |
| 2671 | | { |
| 2672 | | case 0x82: // Mute audio |
| 2673 | | verboselog(space->machine, 0, "slave_w: Channel %d: Mute Audio (0x82)\n", offset ); |
| 2674 | | dmadac_enable(&state->dmadac[0], 2, 0); |
| 2675 | | slave->in_index = 0; |
| 2676 | | slave->in_count = 0; |
| 2677 | | //timer_adjust_oneshot(cdic->audio_sample_timer, attotime_never, 0); |
| 2678 | | break; |
| 2679 | | case 0x83: // Unmute audio |
| 2680 | | verboselog(space->machine, 0, "slave_w: Channel %d: Unmute Audio (0x83)\n", offset ); |
| 2681 | | dmadac_enable(&state->dmadac[0], 2, 1); |
| 2682 | | slave->in_index = 0; |
| 2683 | | slave->in_count = 0; |
| 2684 | | break; |
| 2685 | | case 0xf0: // Set Front Panel LCD |
| 2686 | | verboselog(space->machine, 0, "slave_w: Channel %d: Set Front Panel LCD (0xf0)\n", offset ); |
| 2687 | | slave->in_count = 17; |
| 2688 | | break; |
| 2689 | | default: |
| 2690 | | verboselog(space->machine, 0, "slave_w: Channel %d: Unknown register: %02x\n", offset, data & 0x00ff ); |
| 2691 | | memset(slave->in_buf, 0, 17); |
| 2692 | | slave->in_index = 0; |
| 2693 | | slave->in_count = 0; |
| 2694 | | break; |
| 2695 | | } |
| 2696 | | } |
| 2697 | | break; |
| 2698 | | case 3: |
| 2699 | | if(slave->in_index) |
| 2700 | | { |
| 2701 | | verboselog(space->machine, 0, "slave_w: Channel %d: %d = %02x\n", offset, slave->in_index, data & 0x00ff ); |
| 2702 | | slave->in_buf[slave->in_index] = data & 0x00ff; |
| 2703 | | slave->in_index++; |
| 2704 | | if(slave->in_index == slave->in_count) |
| 2705 | | { |
| 2706 | | switch(slave->in_buf[0]) |
| 2707 | | { |
| 2708 | | case 0xb0: // Request Disc Status |
| 2709 | | memset(slave->in_buf, 0, 17); |
| 2710 | | slave->in_index = 0; |
| 2711 | | slave->in_count = 0; |
| 2712 | | slave_prepare_readback(space->machine, ATTOTIME_IN_HZ(4), 3, 4, 0xb0, 0x00, 0x02, 0x15, 0xb0); |
| 2713 | | break; |
| 2714 | | //case 0xb1: // Request Disc Base |
| 2715 | | //memset(slave->in_buf, 0, 17); |
| 2716 | | //slave->in_index = 0; |
| 2717 | | //slave->in_count = 0; |
| 2718 | | //slave_prepare_readback(space->machine, ATTOTIME_IN_HZ(10000), 3, 4, 0xb1, 0x00, 0x00, 0x00, 0xb1); |
| 2719 | | //break; |
| 2720 | | default: |
| 2721 | | memset(slave->in_buf, 0, 17); |
| 2722 | | slave->in_index = 0; |
| 2723 | | slave->in_count = 0; |
| 2724 | | break; |
| 2725 | | } |
| 2726 | | } |
| 2727 | | } |
| 2728 | | else |
| 2729 | | { |
| 2730 | | slave->in_buf[slave->in_index] = data & 0x00ff; |
| 2731 | | slave->in_index++; |
| 2732 | | switch(data & 0x00ff) |
| 2733 | | { |
| 2734 | | case 0xb0: // Request Disc Status |
| 2735 | | verboselog(space->machine, 0, "slave_w: Channel %d: Request Disc Status (0xb0)\n", offset ); |
| 2736 | | slave->in_count = 4; |
| 2737 | | break; |
| 2738 | | case 0xb1: // Request Disc Status |
| 2739 | | verboselog(space->machine, 0, "slave_w: Channel %d: Request Disc Base (0xb1)\n", offset ); |
| 2740 | | slave->in_count = 4; |
| 2741 | | break; |
| 2742 | | case 0xf0: // Get SLAVE revision |
| 2743 | | verboselog(space->machine, 0, "slave_w: Channel %d: Get SLAVE Revision (0xf0)\n", offset ); |
| 2744 | | slave_prepare_readback(space->machine, ATTOTIME_IN_HZ(10000), 2, 2, 0xf0, 0x32, 0x31, 0, 0xf0); |
| 2745 | | slave->in_index = 0; |
| 2746 | | break; |
| 2747 | | case 0xf3: // Query Pointer Type |
| 2748 | | verboselog(space->machine, 0, "slave_w: Channel %d: Query Pointer Type (0xf3)\n", offset ); |
| 2749 | | slave->in_index = 0; |
| 2750 | | slave_prepare_readback(space->machine, ATTOTIME_IN_HZ(10000), 2, 2, 0xf3, 1, 0, 0, 0xf3); |
| 2751 | | break; |
| 2752 | | case 0xf6: // NTSC/PAL |
| 2753 | | verboselog(space->machine, 0, "slave_w: Channel %d: Check NTSC/PAL (0xf6)\n", offset ); |
| 2754 | | slave_prepare_readback(space->machine, attotime_never, 2, 2, 0xf6, 1, 0, 0, 0xf6); |
| 2755 | | slave->in_index = 0; |
| 2756 | | break; |
| 2757 | | case 0xf7: // Activate input polling |
| 2758 | | verboselog(space->machine, 0, "slave_w: Channel %d: Activate Input Polling (0xf7)\n", offset ); |
| 2759 | | slave->polling_active = 1; |
| 2760 | | slave->in_index = 0; |
| 2761 | | break; |
| 2762 | | case 0xfa: // Enable X-Bus interrupts |
| 2763 | | verboselog(space->machine, 0, "slave_w: Channel %d: X-Bus Interrupt Enable (0xfa)\n", offset ); |
| 2764 | | slave->xbus_interrupt_enable = 1; |
| 2765 | | slave->in_index = 0; |
| 2766 | | break; |
| 2767 | | default: |
| 2768 | | verboselog(space->machine, 0, "slave_w: Channel %d: Unknown register: %02x\n", offset, data & 0x00ff ); |
| 2769 | | memset(slave->in_buf, 0, 17); |
| 2770 | | slave->in_index = 0; |
| 2771 | | slave->in_count = 0; |
| 2772 | | break; |
| 2773 | | } |
| 2774 | | } |
| 2775 | | break; |
| 2776 | | } |
| 2777 | | } |
| 2778 | | |
| 2779 | | static void slave_init(running_machine *machine, slave_regs_t *slave) |
| 2780 | | { |
| 2781 | | int index = 0; |
| 2782 | | for(index = 0; index < 4; index++) |
| 2783 | | { |
| 2784 | | slave->channel[index].out_buf[0] = 0; |
| 2785 | | slave->channel[index].out_buf[1] = 0; |
| 2786 | | slave->channel[index].out_buf[2] = 0; |
| 2787 | | slave->channel[index].out_buf[3] = 0; |
| 2788 | | slave->channel[index].out_index = 0; |
| 2789 | | slave->channel[index].out_count = 0; |
| 2790 | | slave->channel[index].out_cmd = 0; |
| 2791 | | } |
| 2792 | | |
| 2793 | | memset(slave->in_buf, 0, 17); |
| 2794 | | slave->in_index = 0; |
| 2795 | | slave->in_count = 0; |
| 2796 | | |
| 2797 | | slave->polling_active = 0; |
| 2798 | | |
| 2799 | | slave->xbus_interrupt_enable = 0; |
| 2800 | | |
| 2801 | | memset(slave->lcd_state, 0, 16); |
| 2802 | | |
| 2803 | | slave->real_mouse_x = 0; |
| 2804 | | slave->real_mouse_y = 0; |
| 2805 | | |
| 2806 | | slave->fake_mouse_x = 0; |
| 2807 | | slave->fake_mouse_y = 0; |
| 2808 | | } |
| 2809 | | |
| 2810 | | static void slave_register_globals(running_machine *machine, slave_regs_t *slave) |
| 2811 | | { |
| 2812 | | state_save_register_global(machine, slave->channel[0].out_buf[0]); |
| 2813 | | state_save_register_global(machine, slave->channel[0].out_buf[1]); |
| 2814 | | state_save_register_global(machine, slave->channel[0].out_buf[2]); |
| 2815 | | state_save_register_global(machine, slave->channel[0].out_buf[3]); |
| 2816 | | state_save_register_global(machine, slave->channel[0].out_index); |
| 2817 | | state_save_register_global(machine, slave->channel[0].out_count); |
| 2818 | | state_save_register_global(machine, slave->channel[0].out_cmd); |
| 2819 | | state_save_register_global(machine, slave->channel[1].out_buf[0]); |
| 2820 | | state_save_register_global(machine, slave->channel[1].out_buf[1]); |
| 2821 | | state_save_register_global(machine, slave->channel[1].out_buf[2]); |
| 2822 | | state_save_register_global(machine, slave->channel[1].out_buf[3]); |
| 2823 | | state_save_register_global(machine, slave->channel[1].out_index); |
| 2824 | | state_save_register_global(machine, slave->channel[1].out_count); |
| 2825 | | state_save_register_global(machine, slave->channel[1].out_cmd); |
| 2826 | | state_save_register_global(machine, slave->channel[2].out_buf[0]); |
| 2827 | | state_save_register_global(machine, slave->channel[2].out_buf[1]); |
| 2828 | | state_save_register_global(machine, slave->channel[2].out_buf[2]); |
| 2829 | | state_save_register_global(machine, slave->channel[2].out_buf[3]); |
| 2830 | | state_save_register_global(machine, slave->channel[2].out_index); |
| 2831 | | state_save_register_global(machine, slave->channel[2].out_count); |
| 2832 | | state_save_register_global(machine, slave->channel[2].out_cmd); |
| 2833 | | state_save_register_global(machine, slave->channel[3].out_buf[0]); |
| 2834 | | state_save_register_global(machine, slave->channel[3].out_buf[1]); |
| 2835 | | state_save_register_global(machine, slave->channel[3].out_buf[2]); |
| 2836 | | state_save_register_global(machine, slave->channel[3].out_buf[3]); |
| 2837 | | state_save_register_global(machine, slave->channel[3].out_index); |
| 2838 | | state_save_register_global(machine, slave->channel[3].out_count); |
| 2839 | | state_save_register_global(machine, slave->channel[3].out_cmd); |
| 2840 | | |
| 2841 | | state_save_register_global_array(machine, slave->in_buf); |
| 2842 | | state_save_register_global(machine, slave->in_index); |
| 2843 | | state_save_register_global(machine, slave->in_count); |
| 2844 | | |
| 2845 | | state_save_register_global(machine, slave->polling_active); |
| 2846 | | |
| 2847 | | state_save_register_global(machine, slave->xbus_interrupt_enable); |
| 2848 | | |
| 2849 | | state_save_register_global_array(machine, slave->lcd_state); |
| 2850 | | |
| 2851 | | state_save_register_global(machine, slave->real_mouse_x); |
| 2852 | | state_save_register_global(machine, slave->real_mouse_y); |
| 2853 | | |
| 2854 | | state_save_register_global(machine, slave->fake_mouse_x); |
| 2855 | | state_save_register_global(machine, slave->fake_mouse_y); |
| 2856 | | } |
| 2857 | | |
| 2858 | 52 | /************************* |
| 2859 | | * Video Hardware * |
| 2860 | | *************************/ |
| 2861 | | |
| 2862 | | static const UINT16 cdi220_lcd_char[20*22] = |
| 2863 | | { |
| 2864 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2865 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2866 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2867 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2868 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0002, 0x0002, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2869 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0002, 0x0002, 0x0002, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2870 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x8000, 0x8000, 0x8000, 0x8000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0002, 0x0002, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2871 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, 0x8000, 0x8000, 0x8000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0002, 0x0000, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2872 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x0000, 0x0000, 0x8000, 0x8000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0000, 0x0000, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2873 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2874 | | 0x2000, 0x2000, 0x2000, 0x2000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x0200, 0x0200, 0x0200, 0x0200, |
| 2875 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2876 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x4000, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2877 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0000, 0x0010, 0x0010, 0x0001, 0x0001, 0x0001, 0x0001, 0x0008, 0x0008, 0x0000, 0x0000, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2878 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x0000, 0x0010, 0x0010, 0x0010, 0x0001, 0x0001, 0x0001, 0x0001, 0x0008, 0x0008, 0x0008, 0x0000, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2879 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x0010, 0x0010, 0x0010, 0x0010, 0x0001, 0x0001, 0x0001, 0x0001, 0x0008, 0x0008, 0x0008, 0x0008, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2880 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x0010, 0x0010, 0x0010, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0008, 0x0008, 0x0008, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2881 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x0010, 0x0010, 0x0000, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0000, 0x0008, 0x0008, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2882 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2883 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2884 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400, |
| 2885 | | 0x1000, 0x1000, 0x1000, 0x1000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0800, 0x0400, 0x0400, 0x0400, 0x0400 |
| 2886 | | }; |
| 2887 | | |
| 2888 | | static void cdi220_draw_lcd(running_machine *machine, int y) |
| 2889 | | { |
| 2890 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 2891 | | bitmap_t *bitmap = state->lcdbitmap; |
| 2892 | | UINT32 *scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 2893 | | int x = 0; |
| 2894 | | int lcd = 0; |
| 2895 | | |
| 2896 | | for(lcd = 0; lcd < 8; lcd++) |
| 2897 | | { |
| 2898 | | UINT16 data = (state->slave_regs.lcd_state[lcd*2] << 8) | state->slave_regs.lcd_state[lcd*2 + 1]; |
| 2899 | | for(x = 0; x < 20; x++) |
| 2900 | | { |
| 2901 | | if(data & cdi220_lcd_char[y*20 + x]) |
| 2902 | | { |
| 2903 | | scanline[(7 - lcd)*24 + x] = 0x00ffffff; |
| 2904 | | } |
| 2905 | | else |
| 2906 | | { |
| 2907 | | scanline[(7 - lcd)*24 + x] = 0; |
| 2908 | | } |
| 2909 | | } |
| 2910 | | } |
| 2911 | | } |
| 2912 | | |
| 2913 | | static READ16_HANDLER(mcd212_r) |
| 2914 | | { |
| 2915 | | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 2916 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 2917 | | UINT8 channel = 1 - (offset / 8); |
| 2918 | | |
| 2919 | | switch(offset) |
| 2920 | | { |
| 2921 | | case 0x00/2: |
| 2922 | | case 0x10/2: |
| 2923 | | if(ACCESSING_BITS_0_7) |
| 2924 | | { |
| 2925 | | verboselog(space->machine, 12, "mcd212_r: Status Register %d: %02x & %04x\n", channel + 1, mcd212->channel[1 - (offset / 8)].csrr, mem_mask); |
| 2926 | | if(channel == 0) |
| 2927 | | { |
| 2928 | | return mcd212->channel[0].csrr; |
| 2929 | | } |
| 2930 | | else |
| 2931 | | { |
| 2932 | | UINT8 old_csr = mcd212->channel[1].csrr; |
| 2933 | | UINT8 interrupt1 = (state->scc68070_regs.lir >> 4) & 7; |
| 2934 | | //UINT8 interrupt2 = state->scc68070_regs.lir & 7; |
| 2935 | | mcd212->channel[1].csrr &= ~(MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2); |
| 2936 | | if(interrupt1) |
| 2937 | | { |
| 2938 | | cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_1 + (interrupt1 - 1), CLEAR_LINE); |
| 2939 | | } |
| 2940 | | //if(interrupt2) |
| 2941 | | //{ |
| 2942 | | // cputag_set_input_line(space->machine, "maincpu", M68K_IRQ_1 + (interrupt2 - 1), CLEAR_LINE); |
| 2943 | | //} |
| 2944 | | return old_csr; |
| 2945 | | } |
| 2946 | | } |
| 2947 | | else |
| 2948 | | { |
| 2949 | | verboselog(space->machine, 2, "mcd212_r: Unknown Register %d: %04x\n", channel + 1, mem_mask); |
| 2950 | | } |
| 2951 | | break; |
| 2952 | | case 0x02/2: |
| 2953 | | case 0x12/2: |
| 2954 | | verboselog(space->machine, 2, "mcd212_r: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212->channel[1 - (offset / 8)].dcr, mem_mask); |
| 2955 | | return mcd212->channel[1 - (offset / 8)].dcr; |
| 2956 | | case 0x04/2: |
| 2957 | | case 0x14/2: |
| 2958 | | verboselog(space->machine, 2, "mcd212_r: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212->channel[1 - (offset / 8)].vsr, mem_mask); |
| 2959 | | return mcd212->channel[1 - (offset / 8)].vsr; |
| 2960 | | case 0x08/2: |
| 2961 | | case 0x18/2: |
| 2962 | | verboselog(space->machine, 2, "mcd212_r: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212->channel[1 - (offset / 8)].ddr, mem_mask); |
| 2963 | | return mcd212->channel[1 - (offset / 8)].ddr; |
| 2964 | | case 0x0a/2: |
| 2965 | | case 0x1a/2: |
| 2966 | | verboselog(space->machine, 2, "mcd212_r: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, mcd212->channel[1 - (offset / 8)].dcp, mem_mask); |
| 2967 | | return mcd212->channel[1 - (offset / 8)].dcp; |
| 2968 | | default: |
| 2969 | | verboselog(space->machine, 2, "mcd212_r: Unknown Register %d & %04x\n", (1 - (offset / 8)) + 1, mem_mask); |
| 2970 | | break; |
| 2971 | | } |
| 2972 | | |
| 2973 | | return 0; |
| 2974 | | } |
| 2975 | | |
| 2976 | | static void mcd212_update_visible_area(running_machine *machine) |
| 2977 | | { |
| 2978 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 2979 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 2980 | | const rectangle &visarea = machine->primary_screen->visible_area(); |
| 2981 | | rectangle visarea1; |
| 2982 | | attoseconds_t period = machine->primary_screen->frame_period().attoseconds; |
| 2983 | | int width = 0; |
| 2984 | | |
| 2985 | | if((mcd212->channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (mcd212->channel[0].csrw & MCD212_CSR1W_ST)) |
| 2986 | | { |
| 2987 | | width = 360; |
| 2988 | | } |
| 2989 | | else |
| 2990 | | { |
| 2991 | | width = 384; |
| 2992 | | } |
| 2993 | | |
| 2994 | | visarea1.max_x = width-1; |
| 2995 | | visarea1.min_x = visarea.min_x; |
| 2996 | | visarea1.min_y = visarea.min_y; |
| 2997 | | visarea1.max_y = visarea.max_y; |
| 2998 | | |
| 2999 | | machine->primary_screen->configure(width, 262, visarea1, period); |
| 3000 | | } |
| 3001 | | |
| 3002 | | static WRITE16_HANDLER(mcd212_w) |
| 3003 | | { |
| 3004 | | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 3005 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 3006 | | |
| 3007 | | switch(offset) |
| 3008 | | { |
| 3009 | | case 0x00/2: |
| 3010 | | case 0x10/2: |
| 3011 | | verboselog(space->machine, 2, "mcd212_w: Status Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 3012 | | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].csrw); |
| 3013 | | mcd212_update_visible_area(space->machine); |
| 3014 | | break; |
| 3015 | | case 0x02/2: |
| 3016 | | case 0x12/2: |
| 3017 | | verboselog(space->machine, 2, "mcd212_w: Display Command Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 3018 | | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].dcr); |
| 3019 | | mcd212_update_visible_area(space->machine); |
| 3020 | | break; |
| 3021 | | case 0x04/2: |
| 3022 | | case 0x14/2: |
| 3023 | | verboselog(space->machine, 2, "mcd212_w: Video Start Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 3024 | | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].vsr); |
| 3025 | | break; |
| 3026 | | case 0x08/2: |
| 3027 | | case 0x18/2: |
| 3028 | | verboselog(space->machine, 2, "mcd212_w: Display Decoder Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 3029 | | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].ddr); |
| 3030 | | break; |
| 3031 | | case 0x0a/2: |
| 3032 | | case 0x1a/2: |
| 3033 | | verboselog(space->machine, 2, "mcd212_w: DCA Pointer Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 3034 | | COMBINE_DATA(&mcd212->channel[1 - (offset / 8)].dcp); |
| 3035 | | break; |
| 3036 | | default: |
| 3037 | | verboselog(space->machine, 2, "mcd212_w: Unknown Register %d: %04x & %04x\n", (1 - (offset / 8)) + 1, data, mem_mask); |
| 3038 | | break; |
| 3039 | | } |
| 3040 | | } |
| 3041 | | |
| 3042 | | static void mcd212_set_register(running_machine *machine, int channel, UINT8 reg, UINT32 value) |
| 3043 | | { |
| 3044 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 3045 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 3046 | | |
| 3047 | | switch(reg) |
| 3048 | | { |
| 3049 | | case 0x80: case 0x81: case 0x82: case 0x83: case 0x84: case 0x85: case 0x86: case 0x87: // CLUT 0 - 63 |
| 3050 | | case 0x88: case 0x89: case 0x8a: case 0x8b: case 0x8c: case 0x8d: case 0x8e: case 0x8f: |
| 3051 | | case 0x90: case 0x91: case 0x92: case 0x93: case 0x94: case 0x95: case 0x96: case 0x97: |
| 3052 | | case 0x98: case 0x99: case 0x9a: case 0x9b: case 0x9c: case 0x9d: case 0x9e: case 0x9f: |
| 3053 | | case 0xa0: case 0xa1: case 0xa2: case 0xa3: case 0xa4: case 0xa5: case 0xa6: case 0xa7: |
| 3054 | | case 0xa8: case 0xa9: case 0xaa: case 0xab: case 0xac: case 0xad: case 0xae: case 0xaf: |
| 3055 | | case 0xb0: case 0xb1: case 0xb2: case 0xb3: case 0xb4: case 0xb5: case 0xb6: case 0xb7: |
| 3056 | | case 0xb8: case 0xb9: case 0xba: case 0xbb: case 0xbc: case 0xbd: case 0xbe: case 0xbf: |
| 3057 | | verboselog(machine, 11, " %04xxxxx: %d: CLUT[%d] = %08x\n", channel * 0x20, channel, mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80), value ); |
| 3058 | | mcd212->channel[0].clut_r[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 16) & 0xfc; |
| 3059 | | mcd212->channel[0].clut_g[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 8) & 0xfc; |
| 3060 | | mcd212->channel[0].clut_b[mcd212->channel[channel].clut_bank * 0x40 + (reg - 0x80)] = (UINT8)(value >> 0) & 0xfc; |
| 3061 | | break; |
| 3062 | | case 0xc0: // Image Coding Method |
| 3063 | | if(channel == 0) |
| 3064 | | { |
| 3065 | | verboselog(machine, 6, " %04xxxxx: %d: Image Coding Method = %08x\n", channel * 0x20, channel, value ); |
| 3066 | | mcd212->channel[channel].image_coding_method = value; |
| 3067 | | } |
| 3068 | | break; |
| 3069 | | case 0xc1: // Transparency Control |
| 3070 | | if(channel == 0) |
| 3071 | | { |
| 3072 | | verboselog(machine, 6, " %04xxxxx: %d: Transparency Control = %08x\n", channel * 0x20, channel, value ); |
| 3073 | | mcd212->channel[channel].transparency_control = value; |
| 3074 | | } |
| 3075 | | break; |
| 3076 | | case 0xc2: // Plane Order |
| 3077 | | if(channel == 0) |
| 3078 | | { |
| 3079 | | verboselog(machine, 6, " %04xxxxx: %d: Plane Order = %08x\n", channel * 0x20, channel, value & 7); |
| 3080 | | mcd212->channel[channel].plane_order = value & 0x00000007; |
| 3081 | | } |
| 3082 | | break; |
| 3083 | | case 0xc3: // CLUT Bank Register |
| 3084 | | verboselog(machine, 6, " %04xxxxx: %d: CLUT Bank Register = %08x\n", channel * 0x20, channel, value & 3); |
| 3085 | | mcd212->channel[channel].clut_bank = channel ? (2 | (value & 0x00000001)) : (value & 0x00000003); |
| 3086 | | break; |
| 3087 | | case 0xc4: // Transparent Color A |
| 3088 | | if(channel == 0) |
| 3089 | | { |
| 3090 | | verboselog(machine, 6, " %04xxxxx: %d: Transparent Color A = %08x\n", channel * 0x20, channel, value ); |
| 3091 | | mcd212->channel[channel].transparent_color_a = value & 0xfcfcfc; |
| 3092 | | } |
| 3093 | | break; |
| 3094 | | case 0xc6: // Transparent Color B |
| 3095 | | if(channel == 1) |
| 3096 | | { |
| 3097 | | verboselog(machine, 6, " %04xxxxx: %d: Transparent Color B = %08x\n", channel * 0x20, channel, value ); |
| 3098 | | mcd212->channel[channel].transparent_color_b = value & 0xfcfcfc; |
| 3099 | | } |
| 3100 | | break; |
| 3101 | | case 0xc7: // Mask Color A |
| 3102 | | if(channel == 0) |
| 3103 | | { |
| 3104 | | verboselog(machine, 6, " %04xxxxx: %d: Mask Color A = %08x\n", channel * 0x20, channel, value ); |
| 3105 | | mcd212->channel[channel].mask_color_a = value & 0xfcfcfc; |
| 3106 | | } |
| 3107 | | break; |
| 3108 | | case 0xc9: // Mask Color B |
| 3109 | | if(channel == 1) |
| 3110 | | { |
| 3111 | | verboselog(machine, 6, " %04xxxxx: %d: Mask Color B = %08x\n", channel * 0x20, channel, value ); |
| 3112 | | mcd212->channel[channel].mask_color_b = value & 0xfcfcfc; |
| 3113 | | } |
| 3114 | | break; |
| 3115 | | case 0xca: // Delta YUV Absolute Start Value A |
| 3116 | | if(channel == 0) |
| 3117 | | { |
| 3118 | | verboselog(machine, 6, " %04xxxxx: %d: Delta YUV Absolute Start Value A = %08x\n", channel * 0x20, channel, value ); |
| 3119 | | mcd212->channel[channel].dyuv_abs_start_a = value; |
| 3120 | | } |
| 3121 | | break; |
| 3122 | | case 0xcb: // Delta YUV Absolute Start Value B |
| 3123 | | if(channel == 1) |
| 3124 | | { |
| 3125 | | verboselog(machine, 6, " %04xxxxx: %d: Delta YUV Absolute Start Value B = %08x\n", channel * 0x20, channel, value ); |
| 3126 | | mcd212->channel[channel].dyuv_abs_start_b = value; |
| 3127 | | } |
| 3128 | | break; |
| 3129 | | case 0xcd: // Cursor Position |
| 3130 | | if(channel == 0) |
| 3131 | | { |
| 3132 | | verboselog(machine, 6, " %04xxxxx: %d: Cursor Position = %08x\n", channel * 0x20, channel, value ); |
| 3133 | | mcd212->channel[channel].cursor_position = value; |
| 3134 | | } |
| 3135 | | break; |
| 3136 | | case 0xce: // Cursor Control |
| 3137 | | if(channel == 0) |
| 3138 | | { |
| 3139 | | verboselog(machine, 11, " %04xxxxx: %d: Cursor Control = %08x\n", channel * 0x20, channel, value ); |
| 3140 | | mcd212->channel[channel].cursor_control = value; |
| 3141 | | } |
| 3142 | | break; |
| 3143 | | case 0xcf: // Cursor Pattern |
| 3144 | | if(channel == 0) |
| 3145 | | { |
| 3146 | | verboselog(machine, 11, " %04xxxxx: %d: Cursor Pattern[%d] = %04x\n", channel * 0x20, channel, (value >> 16) & 0x000f, value & 0x0000ffff); |
| 3147 | | mcd212->channel[channel].cursor_pattern[(value >> 16) & 0x000f] = value & 0x0000ffff; |
| 3148 | | } |
| 3149 | | break; |
| 3150 | | case 0xd0: // Region Control 0-7 |
| 3151 | | case 0xd1: |
| 3152 | | case 0xd2: |
| 3153 | | case 0xd3: |
| 3154 | | case 0xd4: |
| 3155 | | case 0xd5: |
| 3156 | | case 0xd6: |
| 3157 | | case 0xd7: |
| 3158 | | verboselog(machine, 6, " %04xxxxx: %d: Region Control %d = %08x\n", channel * 0x20, channel, reg & 7, value ); |
| 3159 | | mcd212->channel[0].region_control[reg & 7] = value; |
| 3160 | | mcd212_update_region_arrays(machine); |
| 3161 | | break; |
| 3162 | | case 0xd8: // Backdrop Color |
| 3163 | | if(channel == 0) |
| 3164 | | { |
| 3165 | | verboselog(machine, 6, " %04xxxxx: %d: Backdrop Color = %08x\n", channel * 0x20, channel, value ); |
| 3166 | | mcd212->channel[channel].backdrop_color = value; |
| 3167 | | } |
| 3168 | | break; |
| 3169 | | case 0xd9: // Mosaic Pixel Hold Factor A |
| 3170 | | if(channel == 0) |
| 3171 | | { |
| 3172 | | verboselog(machine, 6, " %04xxxxx: %d: Mosaic Pixel Hold Factor A = %08x\n", channel * 0x20, channel, value ); |
| 3173 | | mcd212->channel[channel].mosaic_hold_a = value; |
| 3174 | | } |
| 3175 | | break; |
| 3176 | | case 0xda: // Mosaic Pixel Hold Factor B |
| 3177 | | if(channel == 1) |
| 3178 | | { |
| 3179 | | verboselog(machine, 6, " %04xxxxx: %d: Mosaic Pixel Hold Factor B = %08x\n", channel * 0x20, channel, value ); |
| 3180 | | mcd212->channel[channel].mosaic_hold_b = value; |
| 3181 | | } |
| 3182 | | break; |
| 3183 | | case 0xdb: // Weight Factor A |
| 3184 | | if(channel == 0) |
| 3185 | | { |
| 3186 | | verboselog(machine, 6, " %04xxxxx: %d: Weight Factor A = %08x\n", channel * 0x20, channel, value ); |
| 3187 | | memset(mcd212->channel[channel].weight_factor_a, value & 0x000000ff, 768); |
| 3188 | | mcd212_update_region_arrays(machine); |
| 3189 | | } |
| 3190 | | break; |
| 3191 | | case 0xdc: // Weight Factor B |
| 3192 | | if(channel == 1) |
| 3193 | | { |
| 3194 | | verboselog(machine, 6, " %04xxxxx: %d: Weight Factor B = %08x\n", channel * 0x20, channel, value ); |
| 3195 | | memset(mcd212->channel[channel].weight_factor_b, value & 0x000000ff, 768); |
| 3196 | | mcd212_update_region_arrays(machine); |
| 3197 | | } |
| 3198 | | break; |
| 3199 | | } |
| 3200 | | } |
| 3201 | | |
| 3202 | | static void mcd212_set_vsr(mcd212_regs_t *mcd212, int channel, UINT32 value) |
| 3203 | | { |
| 3204 | | mcd212->channel[channel].vsr = value & 0x0000ffff; |
| 3205 | | mcd212->channel[channel].dcr &= 0xffc0; |
| 3206 | | mcd212->channel[channel].dcr |= (value >> 16) & 0x003f; |
| 3207 | | } |
| 3208 | | |
| 3209 | | static UINT32 mcd212_get_vsr(mcd212_regs_t *mcd212, int channel) |
| 3210 | | { |
| 3211 | | return ((mcd212->channel[channel].dcr & 0x3f) << 16) | mcd212->channel[channel].vsr; |
| 3212 | | } |
| 3213 | | |
| 3214 | | static void mcd212_set_dcp(mcd212_regs_t *mcd212, int channel, UINT32 value) |
| 3215 | | { |
| 3216 | | mcd212->channel[channel].dcp = value & 0x0000ffff; |
| 3217 | | mcd212->channel[channel].ddr &= 0xffc0; |
| 3218 | | mcd212->channel[channel].ddr |= (value >> 16) & 0x003f; |
| 3219 | | } |
| 3220 | | |
| 3221 | | static UINT32 mcd212_get_dcp(mcd212_regs_t *mcd212, int channel) |
| 3222 | | { |
| 3223 | | return ((mcd212->channel[channel].ddr & 0x3f) << 16) | mcd212->channel[channel].dcp; |
| 3224 | | } |
| 3225 | | |
| 3226 | | static void mcd212_set_display_parameters(mcd212_regs_t *mcd212, int channel, UINT8 value) |
| 3227 | | { |
| 3228 | | mcd212->channel[channel].ddr &= 0xf0ff; |
| 3229 | | mcd212->channel[channel].ddr |= (value & 0x0f) << 8; |
| 3230 | | mcd212->channel[channel].dcr &= 0xf7ff; |
| 3231 | | mcd212->channel[channel].dcr |= (value & 0x10) << 7; |
| 3232 | | } |
| 3233 | | |
| 3234 | | static void mcd212_process_ica(running_machine *machine, int channel) |
| 3235 | | { |
| 3236 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 3237 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 3238 | | UINT16 *ica = channel ? state->planeb : state->planea; |
| 3239 | | UINT32 addr = 0x000400/2; |
| 3240 | | UINT32 cmd = 0; |
| 3241 | | while(1) |
| 3242 | | { |
| 3243 | | UINT8 stop = 0; |
| 3244 | | cmd = ica[addr++] << 16; |
| 3245 | | cmd |= ica[addr++]; |
| 3246 | | switch((cmd & 0xff000000) >> 24) |
| 3247 | | { |
| 3248 | | case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: // STOP |
| 3249 | | case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
| 3250 | | verboselog(machine, 11, "%08x: %08x: ICA %d: STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3251 | | stop = 1; |
| 3252 | | break; |
| 3253 | | case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: // NOP |
| 3254 | | case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 3255 | | verboselog(machine, 12, "%08x: %08x: ICA %d: NOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3256 | | break; |
| 3257 | | case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP |
| 3258 | | case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f: |
| 3259 | | verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3260 | | mcd212_set_dcp(mcd212, channel, cmd & 0x001fffff); |
| 3261 | | break; |
| 3262 | | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP |
| 3263 | | case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: |
| 3264 | | verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3265 | | mcd212_set_dcp(mcd212, channel, cmd & 0x001fffff); |
| 3266 | | stop = 1; |
| 3267 | | break; |
| 3268 | | case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD ICA |
| 3269 | | case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f: |
| 3270 | | verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD ICA\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3271 | | addr = (cmd & 0x001fffff) / 2; |
| 3272 | | break; |
| 3273 | | case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP |
| 3274 | | case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: |
| 3275 | | verboselog(machine, 11, "%08x: %08x: ICA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3276 | | mcd212_set_vsr(mcd212, channel, cmd & 0x001fffff); |
| 3277 | | stop = 1; |
| 3278 | | break; |
| 3279 | | case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT |
| 3280 | | case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: |
| 3281 | | verboselog(machine, 11, "%08x: %08x: ICA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3282 | | mcd212->channel[1].csrr |= 1 << (2 - channel); |
| 3283 | | if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2)) |
| 3284 | | { |
| 3285 | | UINT8 interrupt = (state->scc68070_regs.lir >> 4) & 7; |
| 3286 | | if(interrupt) |
| 3287 | | { |
| 3288 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_1 + (interrupt - 1), 56 + interrupt); |
| 3289 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE); |
| 3290 | | } |
| 3291 | | } |
| 3292 | | #if 0 |
| 3293 | | if(mcd212->channel[1].csrr & MCD212_CSR2R_IT2) |
| 3294 | | { |
| 3295 | | UINT8 interrupt = state->scc68070_regs.lir & 7; |
| 3296 | | if(interrupt) |
| 3297 | | { |
| 3298 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_1 + (interrupt - 1), 24 + interrupt); |
| 3299 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE); |
| 3300 | | } |
| 3301 | | } |
| 3302 | | #endif |
| 3303 | | break; |
| 3304 | | case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS |
| 3305 | | verboselog(machine, 6, "%08x: %08x: ICA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3306 | | mcd212_set_display_parameters(mcd212, channel, cmd & 0x1f); |
| 3307 | | break; |
| 3308 | | default: |
| 3309 | | mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff); |
| 3310 | | break; |
| 3311 | | } |
| 3312 | | if(stop) |
| 3313 | | { |
| 3314 | | break; |
| 3315 | | } |
| 3316 | | } |
| 3317 | | } |
| 3318 | | |
| 3319 | | static void mcd212_process_dca(running_machine *machine, int channel) |
| 3320 | | { |
| 3321 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 3322 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 3323 | | UINT16 *dca = channel ? state->planeb : state->planea; |
| 3324 | | UINT32 addr = (mcd212->channel[channel].dca & 0x0007ffff) / 2; //(mcd212_get_dcp(mcd212, channel) & 0x0007ffff) / 2; // mcd212->channel[channel].dca / 2; |
| 3325 | | UINT32 cmd = 0; |
| 3326 | | UINT32 count = 0; |
| 3327 | | UINT32 max = 64; |
| 3328 | | UINT8 addr_changed = 0; |
| 3329 | | //printf( "max = %d\n", max ); |
| 3330 | | while(1) |
| 3331 | | { |
| 3332 | | UINT8 stop = 0; |
| 3333 | | cmd = dca[addr++] << 16; |
| 3334 | | cmd |= dca[addr++]; |
| 3335 | | count += 4; |
| 3336 | | switch((cmd & 0xff000000) >> 24) |
| 3337 | | { |
| 3338 | | case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: // STOP |
| 3339 | | case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
| 3340 | | verboselog(machine, 11, "%08x: %08x: DCA %d: STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3341 | | stop = 1; |
| 3342 | | break; |
| 3343 | | case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: // NOP |
| 3344 | | case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 3345 | | verboselog(machine, 12, "%08x: %08x: DCA %d: NOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3346 | | break; |
| 3347 | | case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27: // RELOAD DCP |
| 3348 | | case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f: |
| 3349 | | verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD DCP (NOP)\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3350 | | break; |
| 3351 | | case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37: // RELOAD DCP and STOP |
| 3352 | | case 0x38: case 0x39: case 0x3a: case 0x3b: case 0x3c: case 0x3d: case 0x3e: case 0x3f: |
| 3353 | | verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD DCP and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3354 | | mcd212_set_dcp(&state->mcd212_regs, channel, cmd & 0x001fffff); |
| 3355 | | addr = (cmd & 0x0007ffff) / 2; |
| 3356 | | addr_changed = 1; |
| 3357 | | stop = 1; |
| 3358 | | break; |
| 3359 | | case 0x40: case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x46: case 0x47: // RELOAD VSR |
| 3360 | | case 0x48: case 0x49: case 0x4a: case 0x4b: case 0x4c: case 0x4d: case 0x4e: case 0x4f: |
| 3361 | | verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3362 | | mcd212_set_vsr(&state->mcd212_regs, channel, cmd & 0x001fffff); |
| 3363 | | break; |
| 3364 | | case 0x50: case 0x51: case 0x52: case 0x53: case 0x54: case 0x55: case 0x56: case 0x57: // RELOAD VSR and STOP |
| 3365 | | case 0x58: case 0x59: case 0x5a: case 0x5b: case 0x5c: case 0x5d: case 0x5e: case 0x5f: |
| 3366 | | verboselog(machine, 11, "%08x: %08x: DCA %d: RELOAD VSR and STOP\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3367 | | mcd212_set_vsr(&state->mcd212_regs, channel, cmd & 0x001fffff); |
| 3368 | | stop = 1; |
| 3369 | | break; |
| 3370 | | case 0x60: case 0x61: case 0x62: case 0x63: case 0x64: case 0x65: case 0x66: case 0x67: // INTERRUPT |
| 3371 | | case 0x68: case 0x69: case 0x6a: case 0x6b: case 0x6c: case 0x6d: case 0x6e: case 0x6f: |
| 3372 | | verboselog(machine, 11, "%08x: %08x: DCA %d: INTERRUPT\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3373 | | mcd212->channel[1].csrr |= 1 << (2 - channel); |
| 3374 | | if(mcd212->channel[1].csrr & (MCD212_CSR2R_IT1 | MCD212_CSR2R_IT2)) |
| 3375 | | { |
| 3376 | | UINT8 interrupt = (state->scc68070_regs.lir >> 4) & 7; |
| 3377 | | if(interrupt) |
| 3378 | | { |
| 3379 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_1 + (interrupt - 1), 56 + interrupt); |
| 3380 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE); |
| 3381 | | } |
| 3382 | | } |
| 3383 | | #if 0 |
| 3384 | | if(mcd212->channel[1].csrr & MCD212_CSR2R_IT2) |
| 3385 | | { |
| 3386 | | UINT8 interrupt = state->scc68070_regs.lir & 7; |
| 3387 | | if(interrupt) |
| 3388 | | { |
| 3389 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_1 + (interrupt - 1), 24 + interrupt); |
| 3390 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_1 + (interrupt - 1), ASSERT_LINE); |
| 3391 | | } |
| 3392 | | } |
| 3393 | | #endif |
| 3394 | | break; |
| 3395 | | case 0x78: case 0x79: case 0x7a: case 0x7b: case 0x7c: case 0x7d: case 0x7e: case 0x7f: // RELOAD DISPLAY PARAMETERS |
| 3396 | | verboselog(machine, 6, "%08x: %08x: DCA %d: RELOAD DISPLAY PARAMETERS\n", addr * 2 + channel * 0x200000, cmd, channel ); |
| 3397 | | mcd212_set_display_parameters(&state->mcd212_regs, channel, cmd & 0x1f); |
| 3398 | | break; |
| 3399 | | default: |
| 3400 | | mcd212_set_register(machine, channel, cmd >> 24, cmd & 0x00ffffff); |
| 3401 | | break; |
| 3402 | | } |
| 3403 | | if(stop != 0 || count == max) |
| 3404 | | { |
| 3405 | | break; |
| 3406 | | } |
| 3407 | | } |
| 3408 | | if(!addr_changed) |
| 3409 | | { |
| 3410 | | if(count < max) |
| 3411 | | { |
| 3412 | | addr += (max - count) >> 1; |
| 3413 | | } |
| 3414 | | } |
| 3415 | | mcd212->channel[channel].dca = addr * 2; |
| 3416 | | } |
| 3417 | | |
| 3418 | | INLINE UINT8 MCD212_LIM(INT32 in) |
| 3419 | | { |
| 3420 | | if(in < 0) |
| 3421 | | { |
| 3422 | | return 0; |
| 3423 | | } |
| 3424 | | else if(in > 255) |
| 3425 | | { |
| 3426 | | return 255; |
| 3427 | | } |
| 3428 | | return (UINT8)in; |
| 3429 | | } |
| 3430 | | |
| 3431 | | INLINE UINT8 BYTE_TO_CLUT(int channel, int icm, UINT8 byte) |
| 3432 | | { |
| 3433 | | switch(icm) |
| 3434 | | { |
| 3435 | | case 1: |
| 3436 | | return byte; |
| 3437 | | case 3: |
| 3438 | | if(channel) |
| 3439 | | { |
| 3440 | | return 0x80 + (byte & 0x7f); |
| 3441 | | } |
| 3442 | | else |
| 3443 | | { |
| 3444 | | return byte & 0x7f; |
| 3445 | | } |
| 3446 | | case 4: |
| 3447 | | if(!channel) |
| 3448 | | { |
| 3449 | | return byte & 0x7f; |
| 3450 | | } |
| 3451 | | break; |
| 3452 | | case 11: |
| 3453 | | if(channel) |
| 3454 | | { |
| 3455 | | return 0x80 + (byte & 0x0f); |
| 3456 | | } |
| 3457 | | else |
| 3458 | | { |
| 3459 | | return byte & 0x0f; |
| 3460 | | } |
| 3461 | | default: |
| 3462 | | break; |
| 3463 | | } |
| 3464 | | return 0; |
| 3465 | | } |
| 3466 | | |
| 3467 | | static void mcd212_update_region_arrays(running_machine *machine) |
| 3468 | | { |
| 3469 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 3470 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 3471 | | int x = 0; |
| 3472 | | int latched_rf0 = 0; |
| 3473 | | int latched_rf1 = 0; |
| 3474 | | int latched_wfa = mcd212->channel[0].weight_factor_a[0]; |
| 3475 | | int latched_wfb = mcd212->channel[1].weight_factor_b[0]; |
| 3476 | | int reg = 0; |
| 3477 | | |
| 3478 | | for(x = 0; x < 768; x++) |
| 3479 | | { |
| 3480 | | if(mcd212->channel[0].image_coding_method & MCD212_ICM_NR) |
| 3481 | | { |
| 3482 | | int reg_ = 0; |
| 3483 | | int flag = 0; |
| 3484 | | |
| 3485 | | for(flag = 0; flag < 2; flag++) |
| 3486 | | { |
| 3487 | | for(reg_ = 0; reg_ < 4; reg_++) |
| 3488 | | { |
| 3489 | | if(mcd212->channel[0].region_control[reg_] == 0) |
| 3490 | | { |
| 3491 | | break; |
| 3492 | | } |
| 3493 | | if(x == (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_X)) |
| 3494 | | { |
| 3495 | | switch((mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT) |
| 3496 | | { |
| 3497 | | case 0: // End of region control for line |
| 3498 | | break; |
| 3499 | | case 1: |
| 3500 | | case 2: |
| 3501 | | case 3: // Not used |
| 3502 | | break; |
| 3503 | | case 4: // Change weight of plane A |
| 3504 | | latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3505 | | break; |
| 3506 | | case 5: // Not used |
| 3507 | | break; |
| 3508 | | case 6: // Change weight of plane B |
| 3509 | | latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3510 | | break; |
| 3511 | | case 7: // Not used |
| 3512 | | break; |
| 3513 | | case 8: // Reset region flag |
| 3514 | | if(flag) |
| 3515 | | { |
| 3516 | | latched_rf1 = 0; |
| 3517 | | } |
| 3518 | | else |
| 3519 | | { |
| 3520 | | latched_rf0 = 0; |
| 3521 | | } |
| 3522 | | break; |
| 3523 | | case 9: // Set region flag |
| 3524 | | if(flag) |
| 3525 | | { |
| 3526 | | latched_rf1 = 1; |
| 3527 | | } |
| 3528 | | else |
| 3529 | | { |
| 3530 | | latched_rf0 = 1; |
| 3531 | | } |
| 3532 | | break; |
| 3533 | | case 10: // Not used |
| 3534 | | case 11: // Not used |
| 3535 | | break; |
| 3536 | | case 12: // Reset region flag and change weight of plane A |
| 3537 | | latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3538 | | if(flag) |
| 3539 | | { |
| 3540 | | latched_rf1 = 0; |
| 3541 | | } |
| 3542 | | else |
| 3543 | | { |
| 3544 | | latched_rf0 = 0; |
| 3545 | | } |
| 3546 | | break; |
| 3547 | | case 13: // Set region flag and change weight of plane A |
| 3548 | | latched_wfa = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3549 | | if(flag) |
| 3550 | | { |
| 3551 | | latched_rf1 = 1; |
| 3552 | | } |
| 3553 | | else |
| 3554 | | { |
| 3555 | | latched_rf0 = 1; |
| 3556 | | } |
| 3557 | | break; |
| 3558 | | case 14: // Reset region flag and change weight of plane B |
| 3559 | | latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3560 | | if(flag) |
| 3561 | | { |
| 3562 | | latched_rf1 = 0; |
| 3563 | | } |
| 3564 | | else |
| 3565 | | { |
| 3566 | | latched_rf0 = 0; |
| 3567 | | } |
| 3568 | | break; |
| 3569 | | case 15: // Set region flag and change weight of plane B |
| 3570 | | latched_wfb = (mcd212->channel[0].region_control[flag*4 + reg_] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3571 | | if(flag) |
| 3572 | | { |
| 3573 | | latched_rf1 = 1; |
| 3574 | | } |
| 3575 | | else |
| 3576 | | { |
| 3577 | | latched_rf0 = 1; |
| 3578 | | } |
| 3579 | | break; |
| 3580 | | } |
| 3581 | | } |
| 3582 | | } |
| 3583 | | } |
| 3584 | | } |
| 3585 | | else |
| 3586 | | { |
| 3587 | | if(reg < 8) |
| 3588 | | { |
| 3589 | | int flag = (mcd212->channel[0].region_control[reg] & MCD212_RC_RF) >> MCD212_RC_RF_SHIFT; |
| 3590 | | if(!(mcd212->channel[0].region_control[reg] & MCD212_RC_OP)) |
| 3591 | | { |
| 3592 | | for(; x < 768; x++) |
| 3593 | | { |
| 3594 | | mcd212->channel[0].weight_factor_a[x] = latched_wfa; |
| 3595 | | mcd212->channel[1].weight_factor_b[x] = latched_wfb; |
| 3596 | | mcd212->region_flag_0[x] = latched_rf0; |
| 3597 | | mcd212->region_flag_1[x] = latched_rf1; |
| 3598 | | } |
| 3599 | | break; |
| 3600 | | } |
| 3601 | | if(x == (mcd212->channel[0].region_control[reg] & MCD212_RC_X)) |
| 3602 | | { |
| 3603 | | switch((mcd212->channel[0].region_control[reg] & MCD212_RC_OP) >> MCD212_RC_OP_SHIFT) |
| 3604 | | { |
| 3605 | | case 0: // End of region control for line |
| 3606 | | break; |
| 3607 | | case 1: |
| 3608 | | case 2: |
| 3609 | | case 3: // Not used |
| 3610 | | break; |
| 3611 | | case 4: // Change weight of plane A |
| 3612 | | latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3613 | | break; |
| 3614 | | case 5: // Not used |
| 3615 | | break; |
| 3616 | | case 6: // Change weight of plane B |
| 3617 | | latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3618 | | break; |
| 3619 | | case 7: // Not used |
| 3620 | | break; |
| 3621 | | case 8: // Reset region flag |
| 3622 | | if(flag) |
| 3623 | | { |
| 3624 | | latched_rf1 = 0; |
| 3625 | | } |
| 3626 | | else |
| 3627 | | { |
| 3628 | | latched_rf0 = 0; |
| 3629 | | } |
| 3630 | | break; |
| 3631 | | case 9: // Set region flag |
| 3632 | | if(flag) |
| 3633 | | { |
| 3634 | | latched_rf1 = 1; |
| 3635 | | } |
| 3636 | | else |
| 3637 | | { |
| 3638 | | latched_rf0 = 1; |
| 3639 | | } |
| 3640 | | break; |
| 3641 | | case 10: // Not used |
| 3642 | | case 11: // Not used |
| 3643 | | break; |
| 3644 | | case 12: // Reset region flag and change weight of plane A |
| 3645 | | latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3646 | | if(flag) |
| 3647 | | { |
| 3648 | | latched_rf1 = 0; |
| 3649 | | } |
| 3650 | | else |
| 3651 | | { |
| 3652 | | latched_rf0 = 0; |
| 3653 | | } |
| 3654 | | break; |
| 3655 | | case 13: // Set region flag and change weight of plane A |
| 3656 | | latched_wfa = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3657 | | if(flag) |
| 3658 | | { |
| 3659 | | latched_rf1 = 1; |
| 3660 | | } |
| 3661 | | else |
| 3662 | | { |
| 3663 | | latched_rf0 = 1; |
| 3664 | | } |
| 3665 | | break; |
| 3666 | | case 14: // Reset region flag and change weight of plane B |
| 3667 | | latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3668 | | if(flag) |
| 3669 | | { |
| 3670 | | latched_rf1 = 0; |
| 3671 | | } |
| 3672 | | else |
| 3673 | | { |
| 3674 | | latched_rf0 = 0; |
| 3675 | | } |
| 3676 | | break; |
| 3677 | | case 15: // Set region flag and change weight of plane B |
| 3678 | | latched_wfb = (mcd212->channel[0].region_control[reg] & MCD212_RC_WF) >> MCD212_RC_WF_SHIFT; |
| 3679 | | if(flag) |
| 3680 | | { |
| 3681 | | latched_rf1 = 1; |
| 3682 | | } |
| 3683 | | else |
| 3684 | | { |
| 3685 | | latched_rf0 = 1; |
| 3686 | | } |
| 3687 | | break; |
| 3688 | | } |
| 3689 | | reg++; |
| 3690 | | } |
| 3691 | | } |
| 3692 | | } |
| 3693 | | mcd212->channel[0].weight_factor_a[x] = latched_wfa; |
| 3694 | | mcd212->channel[1].weight_factor_b[x] = latched_wfb; |
| 3695 | | mcd212->region_flag_0[x] = latched_rf0; |
| 3696 | | mcd212->region_flag_1[x] = latched_rf1; |
| 3697 | | } |
| 3698 | | } |
| 3699 | | |
| 3700 | | static int mcd212_get_screen_width(running_machine *machine) |
| 3701 | | { |
| 3702 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 3703 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 3704 | | |
| 3705 | | if((mcd212->channel[0].dcr & (MCD212_DCR_CF | MCD212_DCR_FD)) && (mcd212->channel[0].csrw & MCD212_CSR1W_ST)) |
| 3706 | | { |
| 3707 | | return 720; |
| 3708 | | } |
| 3709 | | return 768; |
| 3710 | | } |
| 3711 | | |
| 3712 | | static void mcd212_process_vsr(running_machine *machine, int channel, UINT8 *pixels_r, UINT8 *pixels_g, UINT8 *pixels_b) |
| 3713 | | { |
| 3714 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 3715 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 3716 | | UINT8 *data = channel ? (UINT8*)state->planeb : (UINT8*)state->planea; |
| 3717 | | UINT32 vsr = mcd212_get_vsr(mcd212, channel) & 0x0007ffff; |
| 3718 | | UINT8 done = 0; |
| 3719 | | int x = 0; |
| 3720 | | UINT32 icm_mask = channel ? MCD212_ICM_MODE2 : MCD212_ICM_MODE1; |
| 3721 | | UINT32 icm_shift = channel ? MCD212_ICM_MODE2_SHIFT : MCD212_ICM_MODE1_SHIFT; |
| 3722 | | UINT8 icm = (mcd212->channel[0].image_coding_method & icm_mask) >> icm_shift; |
| 3723 | | UINT8 *clut_r = mcd212->channel[0].clut_r; |
| 3724 | | UINT8 *clut_g = mcd212->channel[0].clut_g; |
| 3725 | | UINT8 *clut_b = mcd212->channel[0].clut_b; |
| 3726 | | UINT8 mosaic_enable = ((mcd212->channel[channel].ddr & MCD212_DDR_FT) == MCD212_DDR_FT_MOSAIC); |
| 3727 | | UINT8 mosaic_factor = 1 << (((mcd212->channel[channel].ddr & MCD212_DDR_MT) >> MCD212_DDR_MT_SHIFT) + 1); |
| 3728 | | int mosaic_index = 0; |
| 3729 | | int width = mcd212_get_screen_width(machine); |
| 3730 | | |
| 3731 | | //printf( "vsr before: %08x: ", vsr ); |
| 3732 | | //fflush(stdout); |
| 3733 | | |
| 3734 | | if(!icm || !vsr) |
| 3735 | | { |
| 3736 | | memset(pixels_r, 0x10, width); |
| 3737 | | memset(pixels_g, 0x10, width); |
| 3738 | | memset(pixels_b, 0x10, width); |
| 3739 | | return; |
| 3740 | | } |
| 3741 | | |
| 3742 | | while(!done) |
| 3743 | | { |
| 3744 | | UINT8 byte = data[(vsr & 0x0007ffff) ^ 1]; |
| 3745 | | vsr++; |
| 3746 | | switch(mcd212->channel[channel].ddr & MCD212_DDR_FT) |
| 3747 | | { |
| 3748 | | case MCD212_DDR_FT_BMP: |
| 3749 | | case MCD212_DDR_FT_BMP2: |
| 3750 | | case MCD212_DDR_FT_MOSAIC: |
| 3751 | | if(mcd212->channel[channel].dcr & MCD212_DCR_CM) |
| 3752 | | { |
| 3753 | | // 4-bit Bitmap |
| 3754 | | verboselog(machine, 0, "Unsupported display mode: 4-bit Bitmap\n" ); |
| 3755 | | } |
| 3756 | | else |
| 3757 | | { |
| 3758 | | // 8-bit Bitmap |
| 3759 | | if(icm == 5) |
| 3760 | | { |
| 3761 | | BYTE68K bY; |
| 3762 | | BYTE68K bU; |
| 3763 | | BYTE68K bV; |
| 3764 | | switch(channel) |
| 3765 | | { |
| 3766 | | case 0: |
| 3767 | | bY = (mcd212->channel[0].dyuv_abs_start_a >> 16) & 0x000000ff; |
| 3768 | | bU = (mcd212->channel[0].dyuv_abs_start_a >> 8) & 0x000000ff; |
| 3769 | | bV = (mcd212->channel[0].dyuv_abs_start_a >> 0) & 0x000000ff; |
| 3770 | | break; |
| 3771 | | case 1: |
| 3772 | | bY = (mcd212->channel[1].dyuv_abs_start_b >> 16) & 0x000000ff; |
| 3773 | | bU = (mcd212->channel[1].dyuv_abs_start_b >> 8) & 0x000000ff; |
| 3774 | | bV = (mcd212->channel[1].dyuv_abs_start_b >> 0) & 0x000000ff; |
| 3775 | | break; |
| 3776 | | default: |
| 3777 | | bY = bU = bV = 0x80; |
| 3778 | | break; |
| 3779 | | } |
| 3780 | | for(; x < width; x += 2) |
| 3781 | | { |
| 3782 | | BYTE68K b0 = byte; |
| 3783 | | BYTE68K bU1 = bU + state->mcd212_ab.deltaUV[b0]; |
| 3784 | | BYTE68K bY0 = bY + state->mcd212_ab.deltaY[b0]; |
| 3785 | | |
| 3786 | | BYTE68K b1 = data[(vsr & 0x0007ffff) ^ 1]; |
| 3787 | | BYTE68K bV1 = bV + state->mcd212_ab.deltaUV[b1]; |
| 3788 | | BYTE68K bY1 = bY0 + state->mcd212_ab.deltaY[b1]; |
| 3789 | | |
| 3790 | | BYTE68K bU0 = (bU + bU1) >> 1; |
| 3791 | | BYTE68K bV0 = (bV + bV1) >> 1; |
| 3792 | | |
| 3793 | | BYTE68K *pbLimit; |
| 3794 | | |
| 3795 | | vsr++; |
| 3796 | | |
| 3797 | | bY = bY0; |
| 3798 | | bU = bU0; |
| 3799 | | bV = bV0; |
| 3800 | | |
| 3801 | | pbLimit = state->mcd212_ab.limit + bY + BYTE68K_MAX; |
| 3802 | | |
| 3803 | | pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[state->mcd212_ab.matrixVR[bV]]; |
| 3804 | | pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[state->mcd212_ab.matrixUG[bU] + state->mcd212_ab.matrixVG[bV]]; |
| 3805 | | pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[state->mcd212_ab.matrixUB[bU]]; |
| 3806 | | |
| 3807 | | if(mosaic_enable) |
| 3808 | | { |
| 3809 | | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 3810 | | { |
| 3811 | | pixels_r[x + 0 + mosaic_index*2] = pixels_r[x + 0]; |
| 3812 | | pixels_g[x + 0 + mosaic_index*2] = pixels_g[x + 0]; |
| 3813 | | pixels_b[x + 0 + mosaic_index*2] = pixels_b[x + 0]; |
| 3814 | | pixels_r[x + 1 + mosaic_index*2] = pixels_r[x + 1]; |
| 3815 | | pixels_g[x + 1 + mosaic_index*2] = pixels_g[x + 1]; |
| 3816 | | pixels_b[x + 1 + mosaic_index*2] = pixels_b[x + 1]; |
| 3817 | | } |
| 3818 | | x += mosaic_factor * 2; |
| 3819 | | } |
| 3820 | | else |
| 3821 | | { |
| 3822 | | x += 2; |
| 3823 | | } |
| 3824 | | |
| 3825 | | bY = bY1; |
| 3826 | | bU = bU1; |
| 3827 | | bV = bV1; |
| 3828 | | |
| 3829 | | pbLimit = state->mcd212_ab.limit + bY + BYTE68K_MAX; |
| 3830 | | |
| 3831 | | pixels_r[x + 0] = pixels_r[x + 1] = pbLimit[state->mcd212_ab.matrixVR[bV]]; |
| 3832 | | pixels_g[x + 0] = pixels_g[x + 1] = pbLimit[state->mcd212_ab.matrixUG[bU] + state->mcd212_ab.matrixVG[bV]]; |
| 3833 | | pixels_b[x + 0] = pixels_b[x + 1] = pbLimit[state->mcd212_ab.matrixUB[bU]]; |
| 3834 | | |
| 3835 | | if(mosaic_enable) |
| 3836 | | { |
| 3837 | | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 3838 | | { |
| 3839 | | pixels_r[x + 0 + mosaic_index*2] = pixels_r[x + 0]; |
| 3840 | | pixels_g[x + 0 + mosaic_index*2] = pixels_g[x + 0]; |
| 3841 | | pixels_b[x + 0 + mosaic_index*2] = pixels_b[x + 0]; |
| 3842 | | pixels_r[x + 1 + mosaic_index*2] = pixels_r[x + 1]; |
| 3843 | | pixels_g[x + 1 + mosaic_index*2] = pixels_g[x + 1]; |
| 3844 | | pixels_b[x + 1 + mosaic_index*2] = pixels_b[x + 1]; |
| 3845 | | } |
| 3846 | | x += (mosaic_factor * 2) - 2; |
| 3847 | | } |
| 3848 | | |
| 3849 | | byte = data[(vsr & 0x0007ffff) ^ 1]; |
| 3850 | | |
| 3851 | | vsr++; |
| 3852 | | } |
| 3853 | | mcd212_set_vsr(&state->mcd212_regs, channel, (vsr - 1) & 0x0007ffff); |
| 3854 | | } |
| 3855 | | else if(icm == 1 || icm == 3 || icm == 4) |
| 3856 | | { |
| 3857 | | for(; x < width; x += 2) |
| 3858 | | { |
| 3859 | | UINT8 clut_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 3860 | | pixels_r[x + 0] = clut_r[clut_entry]; |
| 3861 | | pixels_g[x + 0] = clut_g[clut_entry]; |
| 3862 | | pixels_b[x + 0] = clut_b[clut_entry]; |
| 3863 | | pixels_r[x + 1] = clut_r[clut_entry]; |
| 3864 | | pixels_g[x + 1] = clut_g[clut_entry]; |
| 3865 | | pixels_b[x + 1] = clut_b[clut_entry]; |
| 3866 | | if(mosaic_enable) |
| 3867 | | { |
| 3868 | | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 3869 | | { |
| 3870 | | pixels_r[x + 0 + mosaic_index*2] = pixels_r[x + 0]; |
| 3871 | | pixels_g[x + 0 + mosaic_index*2] = pixels_g[x + 0]; |
| 3872 | | pixels_b[x + 0 + mosaic_index*2] = pixels_b[x + 0]; |
| 3873 | | pixels_r[x + 1 + mosaic_index*2] = pixels_r[x + 1]; |
| 3874 | | pixels_g[x + 1 + mosaic_index*2] = pixels_g[x + 1]; |
| 3875 | | pixels_b[x + 1 + mosaic_index*2] = pixels_b[x + 1]; |
| 3876 | | } |
| 3877 | | x += (mosaic_factor * 2) - 2; |
| 3878 | | } |
| 3879 | | byte = data[(vsr & 0x0007ffff) ^ 1]; |
| 3880 | | vsr++; |
| 3881 | | } |
| 3882 | | mcd212_set_vsr(&state->mcd212_regs, channel, (vsr - 1) & 0x0007ffff); |
| 3883 | | } |
| 3884 | | else if(icm == 11) |
| 3885 | | { |
| 3886 | | for(; x < width; x += 2) |
| 3887 | | { |
| 3888 | | UINT8 even_entry = BYTE_TO_CLUT(channel, icm, byte >> 4); |
| 3889 | | UINT8 odd_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 3890 | | if(mosaic_enable) |
| 3891 | | { |
| 3892 | | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 3893 | | { |
| 3894 | | pixels_r[x + mosaic_index] = clut_r[even_entry]; |
| 3895 | | pixels_g[x + mosaic_index] = clut_g[even_entry]; |
| 3896 | | pixels_b[x + mosaic_index] = clut_b[even_entry]; |
| 3897 | | } |
| 3898 | | for(mosaic_index = 0; mosaic_index < mosaic_factor; mosaic_index++) |
| 3899 | | { |
| 3900 | | pixels_r[x + mosaic_factor + mosaic_index] = clut_r[odd_entry]; |
| 3901 | | pixels_g[x + mosaic_factor + mosaic_index] = clut_g[odd_entry]; |
| 3902 | | pixels_b[x + mosaic_factor + mosaic_index] = clut_b[odd_entry]; |
| 3903 | | } |
| 3904 | | x += (mosaic_factor * 2) - 2; |
| 3905 | | } |
| 3906 | | else |
| 3907 | | { |
| 3908 | | pixels_r[x + 0] = clut_r[even_entry]; |
| 3909 | | pixels_g[x + 0] = clut_g[even_entry]; |
| 3910 | | pixels_b[x + 0] = clut_b[even_entry]; |
| 3911 | | pixels_r[x + 1] = clut_r[odd_entry]; |
| 3912 | | pixels_g[x + 1] = clut_g[odd_entry]; |
| 3913 | | pixels_b[x + 1] = clut_b[odd_entry]; |
| 3914 | | } |
| 3915 | | byte = data[(vsr & 0x0007ffff) ^ 1]; |
| 3916 | | vsr++; |
| 3917 | | } |
| 3918 | | mcd212_set_vsr(&state->mcd212_regs, channel, (vsr - 1) & 0x0007ffff); |
| 3919 | | } |
| 3920 | | else |
| 3921 | | { |
| 3922 | | for(; x < width; x++) |
| 3923 | | { |
| 3924 | | pixels_r[x] = 0x10; |
| 3925 | | pixels_g[x] = 0x10; |
| 3926 | | pixels_b[x] = 0x10; |
| 3927 | | } |
| 3928 | | } |
| 3929 | | } |
| 3930 | | done = 1; |
| 3931 | | break; |
| 3932 | | case MCD212_DDR_FT_RLE: |
| 3933 | | if(mcd212->channel[channel].dcr & MCD212_DCR_CM) |
| 3934 | | { |
| 3935 | | verboselog(machine, 0, "Unsupported display mode: 4-bit RLE\n" ); |
| 3936 | | done = 1; |
| 3937 | | } |
| 3938 | | else |
| 3939 | | { |
| 3940 | | if(byte & 0x80) |
| 3941 | | { |
| 3942 | | // Run length |
| 3943 | | UINT8 length = data[((vsr++) & 0x0007ffff) ^ 1]; |
| 3944 | | if(!length) |
| 3945 | | { |
| 3946 | | UINT8 clut_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 3947 | | UINT8 r = clut_r[clut_entry]; |
| 3948 | | UINT8 g = clut_g[clut_entry]; |
| 3949 | | UINT8 b = clut_b[clut_entry]; |
| 3950 | | // Go to the end of the line |
| 3951 | | for(; x < width; x++) |
| 3952 | | { |
| 3953 | | pixels_r[x] = r; |
| 3954 | | pixels_g[x] = g; |
| 3955 | | pixels_b[x] = b; |
| 3956 | | x++; |
| 3957 | | pixels_r[x] = r; |
| 3958 | | pixels_g[x] = g; |
| 3959 | | pixels_b[x] = b; |
| 3960 | | } |
| 3961 | | done = 1; |
| 3962 | | mcd212_set_vsr(&state->mcd212_regs, channel, vsr); |
| 3963 | | } |
| 3964 | | else |
| 3965 | | { |
| 3966 | | int end = x + (length * 2); |
| 3967 | | UINT8 clut_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 3968 | | UINT8 r = clut_r[clut_entry]; |
| 3969 | | UINT8 g = clut_g[clut_entry]; |
| 3970 | | UINT8 b = clut_b[clut_entry]; |
| 3971 | | for(; x < end && x < width; x++) |
| 3972 | | { |
| 3973 | | pixels_r[x] = r; |
| 3974 | | pixels_g[x] = g; |
| 3975 | | pixels_b[x] = b; |
| 3976 | | x++; |
| 3977 | | pixels_r[x] = r; |
| 3978 | | pixels_g[x] = g; |
| 3979 | | pixels_b[x] = b; |
| 3980 | | } |
| 3981 | | if(x >= width) |
| 3982 | | { |
| 3983 | | done = 1; |
| 3984 | | mcd212_set_vsr(&state->mcd212_regs, channel, vsr); |
| 3985 | | } |
| 3986 | | } |
| 3987 | | } |
| 3988 | | else |
| 3989 | | { |
| 3990 | | // Single pixel |
| 3991 | | UINT8 clut_entry = BYTE_TO_CLUT(channel, icm, byte); |
| 3992 | | pixels_r[x] = clut_r[clut_entry]; |
| 3993 | | pixels_g[x] = clut_g[clut_entry]; |
| 3994 | | pixels_b[x] = clut_b[clut_entry]; |
| 3995 | | x++; |
| 3996 | | pixels_r[x] = clut_r[clut_entry]; |
| 3997 | | pixels_g[x] = clut_g[clut_entry]; |
| 3998 | | pixels_b[x] = clut_b[clut_entry]; |
| 3999 | | x++; |
| 4000 | | if(x >= width) |
| 4001 | | { |
| 4002 | | done = 1; |
| 4003 | | mcd212_set_vsr(&state->mcd212_regs, channel, vsr); |
| 4004 | | } |
| 4005 | | } |
| 4006 | | } |
| 4007 | | break; |
| 4008 | | } |
| 4009 | | } |
| 4010 | | |
| 4011 | | //printf( ": vsr after: %08x\n", vsr); |
| 4012 | | //mcd212_set_vsr(&state->mcd212_regs, channel, vsr); |
| 4013 | | } |
| 4014 | | |
| 4015 | | static const UINT32 mcd212_4bpp_color[16] = |
| 4016 | | { |
| 4017 | | 0x00101010, 0x0010107a, 0x00107a10, 0x00107a7a, 0x007a1010, 0x007a107a, 0x007a7a10, 0x007a7a7a, |
| 4018 | | 0x00101010, 0x001010e6, 0x0010e610, 0x0010e6e6, 0x00e61010, 0x00e610e6, 0x00e6e610, 0x00e6e6e6 |
| 4019 | | }; |
| 4020 | | |
| 4021 | | static void mcd212_draw_cursor(running_machine *machine, UINT32 *scanline, int y) |
| 4022 | | { |
| 4023 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 4024 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 4025 | | |
| 4026 | | if(mcd212->channel[0].cursor_control & MCD212_CURCNT_EN) |
| 4027 | | { |
| 4028 | | UINT16 curx = mcd212->channel[0].cursor_position & 0x3ff; |
| 4029 | | UINT16 cury = ((mcd212->channel[0].cursor_position >> 12) & 0x3ff) + 22; |
| 4030 | | UINT32 x = 0; |
| 4031 | | if(y >= cury && y < (cury + 16)) |
| 4032 | | { |
| 4033 | | UINT32 color = mcd212_4bpp_color[mcd212->channel[0].cursor_control & MCD212_CURCNT_COLOR]; |
| 4034 | | y -= cury; |
| 4035 | | if(mcd212->channel[0].cursor_control & MCD212_CURCNT_CUW) |
| 4036 | | { |
| 4037 | | for(x = curx; x < curx + 64 && x < 768; x++) |
| 4038 | | { |
| 4039 | | if(mcd212->channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 2)))) |
| 4040 | | { |
| 4041 | | scanline[(x++)/2] = color; |
| 4042 | | scanline[(x++)/2] = color; |
| 4043 | | scanline[(x++)/2] = color; |
| 4044 | | scanline[(x/2)] = color; |
| 4045 | | } |
| 4046 | | else |
| 4047 | | { |
| 4048 | | } |
| 4049 | | } |
| 4050 | | } |
| 4051 | | else |
| 4052 | | { |
| 4053 | | for(x = curx; x < curx + 32 && x < 768; x++) |
| 4054 | | { |
| 4055 | | if(mcd212->channel[0].cursor_pattern[y] & (1 << (15 - ((x - curx) >> 1)))) |
| 4056 | | { |
| 4057 | | scanline[(x++)/2] = color; |
| 4058 | | scanline[x/2] = color; |
| 4059 | | } |
| 4060 | | else |
| 4061 | | { |
| 4062 | | } |
| 4063 | | } |
| 4064 | | } |
| 4065 | | } |
| 4066 | | } |
| 4067 | | } |
| 4068 | | |
| 4069 | | static void mcd212_mix_lines(running_machine *machine, UINT8 *plane_a_r, UINT8 *plane_a_g, UINT8 *plane_a_b, UINT8 *plane_b_r, UINT8 *plane_b_g, UINT8 *plane_b_b, UINT32 *out) |
| 4070 | | { |
| 4071 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 4072 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 4073 | | int x = 0; |
| 4074 | | UINT8 debug_mode = input_port_read(machine, "DEBUG"); |
| 4075 | | UINT8 global_plane_a_disable = debug_mode & 1; |
| 4076 | | UINT8 global_plane_b_disable = debug_mode & 2; |
| 4077 | | UINT8 debug_backdrop_enable = debug_mode & 4; |
| 4078 | | UINT8 debug_backdrop_index = debug_mode >> 4; |
| 4079 | | UINT32 backdrop = debug_backdrop_enable ? mcd212_4bpp_color[debug_backdrop_index] : mcd212_4bpp_color[mcd212->channel[0].backdrop_color]; |
| 4080 | | UINT8 transparency_mode_a = (mcd212->channel[0].transparency_control >> 0) & 0x0f; |
| 4081 | | UINT8 transparency_mode_b = (mcd212->channel[0].transparency_control >> 8) & 0x0f; |
| 4082 | | UINT8 transparent_color_a_r = (UINT8)(mcd212->channel[0].transparent_color_a >> 16); |
| 4083 | | UINT8 transparent_color_a_g = (UINT8)(mcd212->channel[0].transparent_color_a >> 8); |
| 4084 | | UINT8 transparent_color_a_b = (UINT8)(mcd212->channel[0].transparent_color_a >> 0); |
| 4085 | | UINT8 transparent_color_b_r = (UINT8)(mcd212->channel[1].transparent_color_b >> 16); |
| 4086 | | UINT8 transparent_color_b_g = (UINT8)(mcd212->channel[1].transparent_color_b >> 8); |
| 4087 | | UINT8 transparent_color_b_b = (UINT8)(mcd212->channel[1].transparent_color_b >> 0); |
| 4088 | | UINT8 image_coding_method_a = mcd212->channel[0].image_coding_method & 0x0000000f; |
| 4089 | | UINT8 image_coding_method_b = (mcd212->channel[0].image_coding_method >> 8) & 0x0000000f; |
| 4090 | | UINT8 dyuv_enable_a = (image_coding_method_a == 5); |
| 4091 | | UINT8 dyuv_enable_b = (image_coding_method_b == 5); |
| 4092 | | UINT8 mosaic_enable_a = (mcd212->channel[0].mosaic_hold_a & 0x800000) >> 23; |
| 4093 | | UINT8 mosaic_enable_b = (mcd212->channel[1].mosaic_hold_b & 0x800000) >> 23; |
| 4094 | | UINT8 mosaic_count_a = (mcd212->channel[0].mosaic_hold_a & 0x0000ff) << 1; |
| 4095 | | UINT8 mosaic_count_b = (mcd212->channel[1].mosaic_hold_b & 0x0000ff) << 1; |
| 4096 | | for(x = 0; x < 768; x++) |
| 4097 | | { |
| 4098 | | out[x] = backdrop; |
| 4099 | | if(!(mcd212->channel[0].transparency_control & MCD212_TCR_DISABLE_MX)) |
| 4100 | | { |
| 4101 | | UINT8 abr = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r[x] - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_r[x] - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 4102 | | UINT8 abg = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g[x] - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_g[x] - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 4103 | | UINT8 abb = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b[x] - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + ((MCD212_LIM((INT32)plane_b_b[x] - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 4104 | | out[x] = (abr << 16) | (abg << 8) | abb; |
| 4105 | | } |
| 4106 | | else |
| 4107 | | { |
| 4108 | | UINT8 plane_enable_a = 0; |
| 4109 | | UINT8 plane_enable_b = 0; |
| 4110 | | UINT8 plane_a_r_cur = mosaic_enable_a ? plane_a_r[x - (x % mosaic_count_a)] : plane_a_r[x]; |
| 4111 | | UINT8 plane_a_g_cur = mosaic_enable_a ? plane_a_g[x - (x % mosaic_count_a)] : plane_a_g[x]; |
| 4112 | | UINT8 plane_a_b_cur = mosaic_enable_a ? plane_a_b[x - (x % mosaic_count_a)] : plane_a_b[x]; |
| 4113 | | UINT8 plane_b_r_cur = mosaic_enable_b ? plane_b_r[x - (x % mosaic_count_b)] : plane_b_r[x]; |
| 4114 | | UINT8 plane_b_g_cur = mosaic_enable_b ? plane_b_g[x - (x % mosaic_count_b)] : plane_b_g[x]; |
| 4115 | | UINT8 plane_b_b_cur = mosaic_enable_b ? plane_b_b[x - (x % mosaic_count_b)] : plane_b_b[x]; |
| 4116 | | switch(transparency_mode_a) |
| 4117 | | { |
| 4118 | | case 0: |
| 4119 | | plane_enable_a = 0; |
| 4120 | | break; |
| 4121 | | case 1: |
| 4122 | | plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b); |
| 4123 | | break; |
| 4124 | | case 3: |
| 4125 | | plane_enable_a = !mcd212->region_flag_0[x]; |
| 4126 | | break; |
| 4127 | | case 4: |
| 4128 | | plane_enable_a = !mcd212->region_flag_1[x]; |
| 4129 | | break; |
| 4130 | | case 5: |
| 4131 | | plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b) && (dyuv_enable_a || mcd212->region_flag_0[x] == 0); |
| 4132 | | break; |
| 4133 | | case 6: |
| 4134 | | plane_enable_a = (plane_a_r_cur != transparent_color_a_r || plane_a_g_cur != transparent_color_a_g || plane_a_b_cur != transparent_color_a_b) && (dyuv_enable_a || mcd212->region_flag_1[x] == 0); |
| 4135 | | break; |
| 4136 | | case 8: |
| 4137 | | plane_enable_a = 1; |
| 4138 | | break; |
| 4139 | | case 9: |
| 4140 | | plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b); |
| 4141 | | break; |
| 4142 | | case 11: |
| 4143 | | plane_enable_a = mcd212->region_flag_0[x]; |
| 4144 | | break; |
| 4145 | | case 12: |
| 4146 | | plane_enable_a = mcd212->region_flag_1[x]; |
| 4147 | | break; |
| 4148 | | case 13: |
| 4149 | | plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b) || dyuv_enable_a || mcd212->region_flag_0[x] == 1; |
| 4150 | | break; |
| 4151 | | case 14: |
| 4152 | | plane_enable_a = (plane_a_r_cur == transparent_color_a_r && plane_a_g_cur == transparent_color_a_g && plane_a_b_cur == transparent_color_a_b) || dyuv_enable_a || mcd212->region_flag_1[x] == 1; |
| 4153 | | break; |
| 4154 | | default: |
| 4155 | | verboselog(machine, 0, "Unhandled transparency mode for plane A: %d\n", transparency_mode_a); |
| 4156 | | plane_enable_a = 1; |
| 4157 | | break; |
| 4158 | | } |
| 4159 | | switch(transparency_mode_b) |
| 4160 | | { |
| 4161 | | case 0: |
| 4162 | | plane_enable_b = 0; |
| 4163 | | break; |
| 4164 | | case 1: |
| 4165 | | plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b); |
| 4166 | | break; |
| 4167 | | case 3: |
| 4168 | | plane_enable_b = !mcd212->region_flag_0[x]; |
| 4169 | | break; |
| 4170 | | case 4: |
| 4171 | | plane_enable_b = !mcd212->region_flag_1[x]; |
| 4172 | | break; |
| 4173 | | case 5: |
| 4174 | | plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b) && (dyuv_enable_b || mcd212->region_flag_0[x] == 0); |
| 4175 | | break; |
| 4176 | | case 6: |
| 4177 | | plane_enable_b = (plane_b_r_cur != transparent_color_b_r || plane_b_g_cur != transparent_color_b_g || plane_b_b_cur != transparent_color_b_b) && (dyuv_enable_b || mcd212->region_flag_1[x] == 0); |
| 4178 | | break; |
| 4179 | | case 8: |
| 4180 | | plane_enable_b = 1; |
| 4181 | | break; |
| 4182 | | case 9: |
| 4183 | | plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b); |
| 4184 | | break; |
| 4185 | | case 11: |
| 4186 | | plane_enable_b = mcd212->region_flag_0[x]; |
| 4187 | | break; |
| 4188 | | case 12: |
| 4189 | | plane_enable_b = mcd212->region_flag_1[x]; |
| 4190 | | break; |
| 4191 | | case 13: |
| 4192 | | plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b) || dyuv_enable_b || mcd212->region_flag_0[x] == 1; |
| 4193 | | break; |
| 4194 | | case 14: |
| 4195 | | plane_enable_b = (plane_b_r_cur == transparent_color_b_r && plane_b_g_cur == transparent_color_b_g && plane_b_b_cur == transparent_color_b_b) || dyuv_enable_b || mcd212->region_flag_1[x] == 1; |
| 4196 | | break; |
| 4197 | | default: |
| 4198 | | verboselog(machine, 0, "Unhandled transparency mode for plane B: %d\n", transparency_mode_b); |
| 4199 | | plane_enable_b = 1; |
| 4200 | | break; |
| 4201 | | } |
| 4202 | | if(global_plane_a_disable) |
| 4203 | | { |
| 4204 | | plane_enable_a = 0; |
| 4205 | | } |
| 4206 | | if(global_plane_b_disable) |
| 4207 | | { |
| 4208 | | plane_enable_b = 0; |
| 4209 | | } |
| 4210 | | plane_a_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_r_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16); |
| 4211 | | plane_a_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_g_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16); |
| 4212 | | plane_a_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_a_b_cur - 16) * mcd212->channel[0].weight_factor_a[x]) >> 6) + 16); |
| 4213 | | plane_b_r_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_r_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 4214 | | plane_b_g_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_g_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 4215 | | plane_b_b_cur = MCD212_LIM(((MCD212_LIM((INT32)plane_b_b_cur - 16) * mcd212->channel[1].weight_factor_b[x]) >> 6) + 16); |
| 4216 | | switch(mcd212->channel[0].plane_order) |
| 4217 | | { |
| 4218 | | case MCD212_POR_AB: |
| 4219 | | if(plane_enable_a) |
| 4220 | | { |
| 4221 | | out[x] = (plane_a_r_cur << 16) | (plane_a_g_cur << 8) | plane_a_b_cur; |
| 4222 | | } |
| 4223 | | else if(plane_enable_b) |
| 4224 | | { |
| 4225 | | out[x] = (plane_b_r_cur << 16) | (plane_b_g_cur << 8) | plane_b_b_cur; |
| 4226 | | } |
| 4227 | | break; |
| 4228 | | case MCD212_POR_BA: |
| 4229 | | if(plane_enable_b) |
| 4230 | | { |
| 4231 | | out[x] = (plane_b_r_cur << 16) | (plane_b_g_cur << 8) | plane_b_b_cur; |
| 4232 | | } |
| 4233 | | else if(plane_enable_a) |
| 4234 | | { |
| 4235 | | out[x] = (plane_a_r_cur << 16) | (plane_a_g_cur << 8) | plane_a_b_cur; |
| 4236 | | } |
| 4237 | | break; |
| 4238 | | } |
| 4239 | | } |
| 4240 | | } |
| 4241 | | } |
| 4242 | | |
| 4243 | | static void mcd212_draw_scanline(running_machine *machine, int y) |
| 4244 | | { |
| 4245 | | bitmap_t *bitmap = machine->generic.tmpbitmap; |
| 4246 | | UINT8 plane_a_r[768], plane_a_g[768], plane_a_b[768]; |
| 4247 | | UINT8 plane_b_r[768], plane_b_g[768], plane_b_b[768]; |
| 4248 | | UINT32 out[768]; |
| 4249 | | UINT32 *scanline = BITMAP_ADDR32(bitmap, y, 0); |
| 4250 | | int x; |
| 4251 | | |
| 4252 | | mcd212_process_vsr(machine, 0, plane_a_r, plane_a_g, plane_a_b); |
| 4253 | | mcd212_process_vsr(machine, 1, plane_b_r, plane_b_g, plane_b_b); |
| 4254 | | |
| 4255 | | mcd212_mix_lines(machine, plane_a_r, plane_a_g, plane_a_b, plane_b_r, plane_b_g, plane_b_b, out); |
| 4256 | | |
| 4257 | | for(x = 0; x < 384; x++) |
| 4258 | | { |
| 4259 | | scanline[x] = out[x*2]; |
| 4260 | | } |
| 4261 | | |
| 4262 | | mcd212_draw_cursor(machine, scanline, y); |
| 4263 | | } |
| 4264 | | |
| 4265 | | static TIMER_CALLBACK( mcd212_perform_scan ) |
| 4266 | | { |
| 4267 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 4268 | | mcd212_regs_t *mcd212 = &state->mcd212_regs; |
| 4269 | | int scanline = machine->primary_screen->vpos(); |
| 4270 | | |
| 4271 | | if(/*mcd212->channel[0].dcr & MCD212_DCR_DE*/1) |
| 4272 | | { |
| 4273 | | if(scanline == 0) |
| 4274 | | { |
| 4275 | | // Process ICA |
| 4276 | | int index = 0; |
| 4277 | | verboselog(machine, 6, "Frame Start\n" ); |
| 4278 | | mcd212->channel[0].csrr &= 0x7f; |
| 4279 | | for(index = 0; index < 2; index++) |
| 4280 | | { |
| 4281 | | if(mcd212->channel[index].dcr & MCD212_DCR_ICA) |
| 4282 | | { |
| 4283 | | mcd212_process_ica(machine, index); |
| 4284 | | } |
| 4285 | | } |
| 4286 | | cdi220_draw_lcd(machine, scanline); |
| 4287 | | } |
| 4288 | | else if(scanline < 22) |
| 4289 | | { |
| 4290 | | cdi220_draw_lcd(machine, scanline); |
| 4291 | | } |
| 4292 | | else if(scanline >= 22) |
| 4293 | | { |
| 4294 | | int index = 0; |
| 4295 | | mcd212->channel[0].csrr |= 0x80; |
| 4296 | | // Process VSR |
| 4297 | | mcd212_draw_scanline(machine, scanline); |
| 4298 | | // Process DCA |
| 4299 | | for(index = 0; index < 2; index++) |
| 4300 | | { |
| 4301 | | if(mcd212->channel[index].dcr & MCD212_DCR_DCA) |
| 4302 | | { |
| 4303 | | if(scanline == 22) |
| 4304 | | { |
| 4305 | | mcd212->channel[index].dca = mcd212_get_dcp(mcd212, index); |
| 4306 | | } |
| 4307 | | mcd212_process_dca(machine, index); |
| 4308 | | } |
| 4309 | | } |
| 4310 | | if(scanline == 261) |
| 4311 | | { |
| 4312 | | mcd212->channel[0].csrr ^= 0x20; |
| 4313 | | } |
| 4314 | | } |
| 4315 | | } |
| 4316 | | timer_adjust_oneshot(mcd212->scan_timer, machine->primary_screen->time_until_pos(( scanline + 1 ) % 262, 0), 0); |
| 4317 | | } |
| 4318 | | |
| 4319 | | static void mcd212_init(running_machine *machine, mcd212_regs_t *mcd212) |
| 4320 | | { |
| 4321 | | int index = 0; |
| 4322 | | for(index = 0; index < 2; index++) |
| 4323 | | { |
| 4324 | | mcd212->channel[index].csrr = 0; |
| 4325 | | mcd212->channel[index].csrw = 0; |
| 4326 | | mcd212->channel[index].dcr = 0; |
| 4327 | | mcd212->channel[index].vsr = 0; |
| 4328 | | mcd212->channel[index].ddr = 0; |
| 4329 | | mcd212->channel[index].dcp = 0; |
| 4330 | | mcd212->channel[index].dca = 0; |
| 4331 | | memset(mcd212->channel[index].clut_r, 0, 768); |
| 4332 | | memset(mcd212->channel[index].clut_g, 0, 768); |
| 4333 | | memset(mcd212->channel[index].clut_b, 0, 768); |
| 4334 | | mcd212->channel[index].image_coding_method = 0; |
| 4335 | | mcd212->channel[index].transparency_control = 0; |
| 4336 | | mcd212->channel[index].plane_order = 0; |
| 4337 | | mcd212->channel[index].clut_bank = 0; |
| 4338 | | mcd212->channel[index].transparent_color_a = 0; |
| 4339 | | mcd212->channel[index].transparent_color_b = 0; |
| 4340 | | mcd212->channel[index].mask_color_a = 0; |
| 4341 | | mcd212->channel[index].mask_color_b = 0; |
| 4342 | | mcd212->channel[index].dyuv_abs_start_a = 0; |
| 4343 | | mcd212->channel[index].dyuv_abs_start_b = 0; |
| 4344 | | mcd212->channel[index].cursor_position = 0; |
| 4345 | | mcd212->channel[index].cursor_control = 0; |
| 4346 | | memset((UINT8*)&mcd212->channel[index].cursor_pattern, 0, 16 * sizeof(UINT32)); |
| 4347 | | memset((UINT8*)&mcd212->channel[index].region_control, 0, 8 * sizeof(UINT32)); |
| 4348 | | mcd212->channel[index].backdrop_color = 0; |
| 4349 | | mcd212->channel[index].mosaic_hold_a = 0; |
| 4350 | | mcd212->channel[index].mosaic_hold_b = 0; |
| 4351 | | memset(mcd212->channel[index].weight_factor_a, 0, 768); |
| 4352 | | memset(mcd212->channel[index].weight_factor_b, 0, 768); |
| 4353 | | } |
| 4354 | | memset(mcd212->region_flag_0, 0, 768); |
| 4355 | | memset(mcd212->region_flag_1, 0, 768); |
| 4356 | | |
| 4357 | | state_save_register_global_array(machine, mcd212->region_flag_0); |
| 4358 | | state_save_register_global_array(machine, mcd212->region_flag_1); |
| 4359 | | state_save_register_global(machine, mcd212->channel[0].csrr); |
| 4360 | | state_save_register_global(machine, mcd212->channel[0].csrw); |
| 4361 | | state_save_register_global(machine, mcd212->channel[0].dcr); |
| 4362 | | state_save_register_global(machine, mcd212->channel[0].vsr); |
| 4363 | | state_save_register_global(machine, mcd212->channel[0].ddr); |
| 4364 | | state_save_register_global(machine, mcd212->channel[0].dcp); |
| 4365 | | state_save_register_global(machine, mcd212->channel[0].dca); |
| 4366 | | state_save_register_global_array(machine, mcd212->channel[0].clut_r); |
| 4367 | | state_save_register_global_array(machine, mcd212->channel[0].clut_g); |
| 4368 | | state_save_register_global_array(machine, mcd212->channel[0].clut_b); |
| 4369 | | state_save_register_global(machine, mcd212->channel[0].image_coding_method); |
| 4370 | | state_save_register_global(machine, mcd212->channel[0].transparency_control); |
| 4371 | | state_save_register_global(machine, mcd212->channel[0].plane_order); |
| 4372 | | state_save_register_global(machine, mcd212->channel[0].clut_bank); |
| 4373 | | state_save_register_global(machine, mcd212->channel[0].transparent_color_a); |
| 4374 | | state_save_register_global(machine, mcd212->channel[0].transparent_color_b); |
| 4375 | | state_save_register_global(machine, mcd212->channel[0].mask_color_a); |
| 4376 | | state_save_register_global(machine, mcd212->channel[0].mask_color_b); |
| 4377 | | state_save_register_global(machine, mcd212->channel[0].dyuv_abs_start_a); |
| 4378 | | state_save_register_global(machine, mcd212->channel[0].dyuv_abs_start_b); |
| 4379 | | state_save_register_global(machine, mcd212->channel[0].cursor_position); |
| 4380 | | state_save_register_global(machine, mcd212->channel[0].cursor_control); |
| 4381 | | state_save_register_global_array(machine, mcd212->channel[0].cursor_pattern); |
| 4382 | | state_save_register_global_array(machine, mcd212->channel[0].region_control); |
| 4383 | | state_save_register_global(machine, mcd212->channel[0].backdrop_color); |
| 4384 | | state_save_register_global(machine, mcd212->channel[0].mosaic_hold_a); |
| 4385 | | state_save_register_global(machine, mcd212->channel[0].mosaic_hold_b); |
| 4386 | | state_save_register_global_array(machine, mcd212->channel[0].weight_factor_a); |
| 4387 | | state_save_register_global_array(machine, mcd212->channel[0].weight_factor_b); |
| 4388 | | state_save_register_global(machine, mcd212->channel[1].csrr); |
| 4389 | | state_save_register_global(machine, mcd212->channel[1].csrw); |
| 4390 | | state_save_register_global(machine, mcd212->channel[1].dcr); |
| 4391 | | state_save_register_global(machine, mcd212->channel[1].vsr); |
| 4392 | | state_save_register_global(machine, mcd212->channel[1].ddr); |
| 4393 | | state_save_register_global(machine, mcd212->channel[1].dcp); |
| 4394 | | state_save_register_global(machine, mcd212->channel[1].dca); |
| 4395 | | state_save_register_global_array(machine, mcd212->channel[1].clut_r); |
| 4396 | | state_save_register_global_array(machine, mcd212->channel[1].clut_g); |
| 4397 | | state_save_register_global_array(machine, mcd212->channel[1].clut_b); |
| 4398 | | state_save_register_global(machine, mcd212->channel[1].image_coding_method); |
| 4399 | | state_save_register_global(machine, mcd212->channel[1].transparency_control); |
| 4400 | | state_save_register_global(machine, mcd212->channel[1].plane_order); |
| 4401 | | state_save_register_global(machine, mcd212->channel[1].clut_bank); |
| 4402 | | state_save_register_global(machine, mcd212->channel[1].transparent_color_a); |
| 4403 | | state_save_register_global(machine, mcd212->channel[1].transparent_color_b); |
| 4404 | | state_save_register_global(machine, mcd212->channel[1].mask_color_a); |
| 4405 | | state_save_register_global(machine, mcd212->channel[1].mask_color_b); |
| 4406 | | state_save_register_global(machine, mcd212->channel[1].dyuv_abs_start_a); |
| 4407 | | state_save_register_global(machine, mcd212->channel[1].dyuv_abs_start_b); |
| 4408 | | state_save_register_global(machine, mcd212->channel[1].cursor_position); |
| 4409 | | state_save_register_global(machine, mcd212->channel[1].cursor_control); |
| 4410 | | state_save_register_global_array(machine, mcd212->channel[1].cursor_pattern); |
| 4411 | | state_save_register_global_array(machine, mcd212->channel[1].region_control); |
| 4412 | | state_save_register_global(machine, mcd212->channel[1].backdrop_color); |
| 4413 | | state_save_register_global(machine, mcd212->channel[1].mosaic_hold_a); |
| 4414 | | state_save_register_global(machine, mcd212->channel[1].mosaic_hold_b); |
| 4415 | | state_save_register_global_array(machine, mcd212->channel[1].weight_factor_a); |
| 4416 | | state_save_register_global_array(machine, mcd212->channel[1].weight_factor_b); |
| 4417 | | } |
| 4418 | | |
| 4419 | | static void mcd212_ab_init(mcd212_ab_t *mcd212_ab) |
| 4420 | | { |
| 4421 | | WORD68K w = 0; |
| 4422 | | SWORD68K sw = 0; |
| 4423 | | WORD68K d = 0; |
| 4424 | | |
| 4425 | | //* Delta decoding array. |
| 4426 | | static const BYTE68K mcd212_abDelta[16] = { 0, 1, 4, 9, 16, 27, 44, 79, 128, 177, 212, 229, 240, 247, 252, 255 }; |
| 4427 | | |
| 4428 | | // Initialize delta decoding arrays for each unsigned byte value b. |
| 4429 | | for (d = 0; d < BYTE68K_MAX + 1; d++) |
| 4430 | | { |
| 4431 | | mcd212_ab->deltaY[d] = mcd212_abDelta[d & 15]; |
| 4432 | | } |
| 4433 | | |
| 4434 | | // Initialize delta decoding arrays for each unsigned byte value b. |
| 4435 | | for (d = 0; d < (BYTE68K_MAX + 1); d++) |
| 4436 | | { |
| 4437 | | mcd212_ab->deltaUV[d] = mcd212_abDelta[d >> 4]; |
| 4438 | | } |
| 4439 | | |
| 4440 | | // Initialize color limit and clamp arrays. |
| 4441 | | for (w = 0; w < 3 * BYTE68K_MAX; w++) |
| 4442 | | { |
| 4443 | | mcd212_ab->limit[w] = (w < BYTE68K_MAX + 16) ? 0 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX; |
| 4444 | | mcd212_ab->clamp[w] = (w < BYTE68K_MAX + 32) ? 16 : w <= 16 + 2 * BYTE68K_MAX ? w - BYTE68K_MAX - 16 : BYTE68K_MAX; |
| 4445 | | } |
| 4446 | | |
| 4447 | | for (sw = 0; sw < 0x100; sw++) |
| 4448 | | { |
| 4449 | | mcd212_ab->matrixUB[sw] = (444 * (sw - 128)) / 256; |
| 4450 | | mcd212_ab->matrixUG[sw] = - (86 * (sw - 128)) / 256; |
| 4451 | | mcd212_ab->matrixVG[sw] = - (179 * (sw - 128)) / 256; |
| 4452 | | mcd212_ab->matrixVR[sw] = (351 * (sw - 128)) / 256; |
| 4453 | | } |
| 4454 | | } |
| 4455 | | |
| 4456 | | |
| 4457 | | |
| 4458 | | static VIDEO_START(cdi) |
| 4459 | | { |
| 4460 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 4461 | | |
| 4462 | | VIDEO_START_CALL(generic_bitmapped); |
| 4463 | | mcd212_ab_init(&state->mcd212_ab); |
| 4464 | | mcd212_init(machine, &state->mcd212_regs); |
| 4465 | | state->mcd212_regs.scan_timer = timer_alloc(machine, mcd212_perform_scan, 0); |
| 4466 | | timer_adjust_oneshot(state->mcd212_regs.scan_timer, machine->primary_screen->time_until_pos(0, 0), 0); |
| 4467 | | |
| 4468 | | state->lcdbitmap = downcast<screen_device *>(machine->device("lcd"))->alloc_compatible_bitmap(); |
| 4469 | | } |
| 4470 | | |
| 4471 | | static VIDEO_UPDATE(cdi) |
| 4472 | | { |
| 4473 | | cdi_state *state = screen->machine->driver_data<cdi_state>(); |
| 4474 | | running_device *main_screen = screen->machine->device("screen"); |
| 4475 | | running_device *lcd_screen = screen->machine->device("lcd"); |
| 4476 | | |
| 4477 | | if (screen == main_screen) |
| 4478 | | { |
| 4479 | | copybitmap(bitmap, screen->machine->generic.tmpbitmap, 0, 0, 0, 0, cliprect); |
| 4480 | | } |
| 4481 | | else if (screen == lcd_screen) |
| 4482 | | { |
| 4483 | | copybitmap(bitmap, state->lcdbitmap, 0, 0, 0, 0, cliprect); |
| 4484 | | } |
| 4485 | | |
| 4486 | | return 0; |
| 4487 | | } |
| 4488 | | |
| 4489 | | static TIMER_CALLBACK( test_timer_callback ) |
| 4490 | | { |
| 4491 | | cdi_state *state = machine->driver_data<cdi_state>(); |
| 4492 | | |
| 4493 | | // This function manually triggers interrupt requests as a test. |
| 4494 | | if(state->timer_set == 0) |
| 4495 | | { |
| 4496 | | state->timer_set = 1; |
| 4497 | | cpu_set_input_line_vector(machine->device("maincpu"), M68K_IRQ_4, 60); |
| 4498 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, ASSERT_LINE); |
| 4499 | | timer_adjust_oneshot(state->test_timer, ATTOTIME_IN_HZ(10000), 0); |
| 4500 | | } |
| 4501 | | else |
| 4502 | | { |
| 4503 | | state->timer_set = 0; |
| 4504 | | cputag_set_input_line(machine, "maincpu", M68K_IRQ_4, CLEAR_LINE); |
| 4505 | | timer_adjust_oneshot(state->test_timer, attotime_never, 0); |
| 4506 | | } |
| 4507 | | } |
| 4508 | | |
| 4509 | | /************************* |
| 4510 | 53 | * Memory maps * |
| 4511 | 54 | *************************/ |
| 4512 | 55 | |
| 4513 | | static WRITE16_HANDLER(cdic_ram_w) |
| 56 | WRITE16_HANDLER( cdic_ram_w ) |
| 4514 | 57 | { |
| 4515 | 58 | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 4516 | 59 | cdic_regs_t *cdic = &state->cdic_regs; |
| r8789 | r8790 | |
| 4519 | 62 | COMBINE_DATA(&cdic->ram[offset]); |
| 4520 | 63 | } |
| 4521 | 64 | |
| 4522 | | static READ16_HANDLER(cdic_ram_r) |
| 65 | READ16_HANDLER( cdic_ram_r ) |
| 4523 | 66 | { |
| 4524 | 67 | cdi_state *state = space->machine->driver_data<cdi_state>(); |
| 4525 | 68 | cdic_regs_t *cdic = &state->cdic_regs; |
| r8789 | r8790 | |
| 4604 | 147 | state->scc68070_regs.timers.timer0_timer = timer_alloc(machine, scc68070_timer0_callback, 0); |
| 4605 | 148 | timer_adjust_oneshot(state->scc68070_regs.timers.timer0_timer, attotime_never, 0); |
| 4606 | 149 | |
| 4607 | | state->test_timer = timer_alloc(machine, test_timer_callback, 0); |
| 4608 | | timer_adjust_oneshot(state->test_timer, attotime_never, 0); |
| 4609 | | |
| 4610 | 150 | state->slave_regs.interrupt_timer = timer_alloc(machine, slave_trigger_readback_int, 0); |
| 4611 | 151 | timer_adjust_oneshot(state->slave_regs.interrupt_timer, attotime_never, 0); |
| 4612 | 152 | |
| r8789 | r8790 | |
| 4652 | 192 | |
| 4653 | 193 | MDRV_DRIVER_DATA( cdi_state ) |
| 4654 | 194 | |
| 4655 | | MDRV_CPU_ADD("maincpu", SCC68070, CLOCK_A/2) |
| 4656 | | MDRV_CPU_PROGRAM_MAP(cdimono1_mem) |
| 195 | MDRV_CPU_ADD( "maincpu", SCC68070, CLOCK_A/2 ) |
| 196 | MDRV_CPU_PROGRAM_MAP( cdimono1_mem ) |
| 4657 | 197 | |
| 4658 | | MDRV_SCREEN_ADD("screen", RASTER) |
| 4659 | | MDRV_SCREEN_REFRESH_RATE(60) |
| 4660 | | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) |
| 4661 | | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 4662 | | MDRV_SCREEN_SIZE(384, 262) |
| 4663 | | MDRV_SCREEN_VISIBLE_AREA(0, 384-1, 22, 262-1) //dynamic resolution,TODO |
| 198 | MDRV_SCREEN_ADD( "screen", RASTER ) |
| 199 | MDRV_SCREEN_REFRESH_RATE( 60 ) |
| 200 | MDRV_SCREEN_VBLANK_TIME( ATTOSECONDS_IN_USEC(0) ) |
| 201 | MDRV_SCREEN_FORMAT( BITMAP_FORMAT_RGB32 ) |
| 202 | MDRV_SCREEN_SIZE( 384, 262 ) |
| 203 | MDRV_SCREEN_VISIBLE_AREA( 0, 384-1, 22, 262-1 ) //dynamic resolution,TODO |
| 4664 | 204 | |
| 4665 | | MDRV_SCREEN_ADD("lcd", RASTER) |
| 4666 | | MDRV_SCREEN_REFRESH_RATE(60) |
| 4667 | | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(0)) |
| 4668 | | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 4669 | | MDRV_SCREEN_SIZE(192, 22) |
| 4670 | | MDRV_SCREEN_VISIBLE_AREA(0, 192-1, 0, 22-1) |
| 205 | MDRV_SCREEN_ADD( "lcd", RASTER ) |
| 206 | MDRV_SCREEN_REFRESH_RATE( 60 ) |
| 207 | MDRV_SCREEN_VBLANK_TIME( ATTOSECONDS_IN_USEC(0) ) |
| 208 | MDRV_SCREEN_FORMAT( BITMAP_FORMAT_RGB32 ) |
| 209 | MDRV_SCREEN_SIZE( 192, 22 ) |
| 210 | MDRV_SCREEN_VISIBLE_AREA( 0, 192-1, 0, 22-1 ) |
| 4671 | 211 | |
| 4672 | | MDRV_PALETTE_LENGTH(0x100) |
| 212 | MDRV_PALETTE_LENGTH( 0x100 ) |
| 4673 | 213 | |
| 4674 | | MDRV_DEFAULT_LAYOUT(layout_cdi) |
| 214 | MDRV_DEFAULT_LAYOUT( layout_cdi ) |
| 4675 | 215 | |
| 4676 | | MDRV_VIDEO_START(cdi) |
| 4677 | | MDRV_VIDEO_UPDATE(cdi) |
| 216 | MDRV_VIDEO_START( cdimono1 ) |
| 217 | MDRV_VIDEO_UPDATE( cdimono1 ) |
| 4678 | 218 | |
| 4679 | | MDRV_MACHINE_RESET(cdi) |
| 4680 | | MDRV_MACHINE_START(cdi) |
| 219 | MDRV_MACHINE_RESET( cdi ) |
| 220 | MDRV_MACHINE_START( cdi ) |
| 4681 | 221 | |
| 4682 | 222 | MDRV_CDROM_ADD( "cdrom" ) |
| 4683 | 223 | |
| 4684 | 224 | /* sound hardware */ |
| 4685 | | MDRV_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") |
| 225 | MDRV_SPEAKER_STANDARD_STEREO( "lspeaker", "rspeaker" ) |
| 4686 | 226 | |
| 4687 | 227 | MDRV_SOUND_ADD( "dac1", DMADAC, 0 ) |
| 4688 | 228 | MDRV_SOUND_ROUTE( ALL_OUTPUTS, "lspeaker", 1.0 ) |