src/mame/machine/smpc.c
| r12585 | r12586 | |
| 9 | 9 | |
| 10 | 10 | TODO: |
| 11 | 11 | - timings; |
| 12 | | - fix intback issue with inputs; |
| 13 | | - better arrangement of variables; |
| 12 | - fix intback issue with inputs (according to the docs, it should fall in between |
| 13 | VBLANK-IN and OUT, for obvious reasons); |
| 14 | 14 | - clean-ups; |
| 15 | 15 | |
| 16 | 16 | *************************************************************************************/ |
| r12585 | r12586 | |
| 155 | 155 | #define LOG_SMPC 0 |
| 156 | 156 | #define LOG_PAD_CMD 0 |
| 157 | 157 | |
| 158 | | READ8_HANDLER( stv_SMPC_r ) |
| 159 | | { |
| 160 | | saturn_state *state = space->machine().driver_data<saturn_state>(); |
| 161 | | int return_data; |
| 162 | | |
| 163 | | return_data = state->m_smpc_ram[offset]; |
| 164 | | |
| 165 | | if (offset == 0x61) // ?? many games need this or the controls don't work |
| 166 | | return_data = 0x20 ^ 0xff; |
| 167 | | |
| 168 | | if (offset == 0x75)//PDR1 read |
| 169 | | return_data = input_port_read(space->machine(), "DSW1"); |
| 170 | | |
| 171 | | if (offset == 0x77)//PDR2 read |
| 172 | | return_data= (0xfe | space->machine().device<eeprom_device>("eeprom")->read_bit()); |
| 173 | | |
| 174 | | // if (offset == 0x33) //country code |
| 175 | | // return_data = input_port_read(machine, "FAKE"); |
| 176 | | |
| 177 | | //if(LOG_SMPC) printf ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x Returns %02x\n", space->device().tag(), cpu_get_pc(&space->device()), offset, return_data); |
| 178 | | |
| 179 | | |
| 180 | | return return_data; |
| 181 | | } |
| 182 | | |
| 183 | 158 | static TIMER_CALLBACK( stv_bankswitch_state ) |
| 184 | 159 | { |
| 185 | 160 | saturn_state *state = machine.driver_data<saturn_state>(); |
| r12585 | r12586 | |
| 216 | 191 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 217 | 192 | |
| 218 | 193 | device_set_input_line(state->m_slave, INPUT_LINE_RESET, param ? ASSERT_LINE : CLEAR_LINE); |
| 219 | | state->m_smpc_ram[0x5f] = param + 0x02; //read-back for last command issued |
| 220 | | state->m_smpc_ram[0x63] = 0x00; //clear hand-shake flag |
| 194 | state->m_smpc.OREG[31] = param + 0x02; //read-back for last command issued |
| 195 | state->m_smpc.SF = 0x00; //clear hand-shake flag |
| 221 | 196 | } |
| 222 | 197 | |
| 223 | 198 | static TIMER_CALLBACK( smpc_sound_enable ) |
| r12585 | r12586 | |
| 226 | 201 | |
| 227 | 202 | device_set_input_line(state->m_audiocpu, INPUT_LINE_RESET, param ? ASSERT_LINE : CLEAR_LINE); |
| 228 | 203 | state->m_en_68k = param ^ 1; |
| 229 | | state->m_smpc_ram[0x5f] = param + 0x06; //read-back for last command issued |
| 230 | | state->m_smpc_ram[0x63] = 0x00; //clear hand-shake flag |
| 204 | state->m_smpc.OREG[31] = param + 0x06; //read-back for last command issued |
| 205 | state->m_smpc.SF = 0x00; //clear hand-shake flag |
| 231 | 206 | } |
| 232 | 207 | |
| 233 | 208 | static void smpc_system_reset(running_machine &machine) |
| r12585 | r12586 | |
| 270 | 245 | static TIMER_CALLBACK( stv_smpc_intback ) |
| 271 | 246 | { |
| 272 | 247 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 248 | int i; |
| 273 | 249 | |
| 274 | | state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 250 | state->m_smpc.OREG[0] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 275 | 251 | |
| 276 | | { |
| 277 | | int i; |
| 252 | for(i=0;i<7;i++) |
| 253 | state->m_smpc.OREG[1+i] = state->m_smpc.rtc_data[i]; |
| 278 | 254 | |
| 279 | | for(i=0;i<7;i++) |
| 280 | | state->m_smpc_ram[0x23+i*2] = state->m_smpc.rtc_data[i]; |
| 281 | | } |
| 255 | state->m_smpc.OREG[8]=0x00; // CTG0 / CTG1? |
| 282 | 256 | |
| 283 | | state->m_smpc_ram[0x31]=0x00; //? |
| 257 | state->m_smpc.OREG[9]=0x00; // TODO: system region on Saturn |
| 284 | 258 | |
| 285 | | //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE"); |
| 286 | | |
| 287 | | state->m_smpc_ram[0x35]= 0 << 7 | |
| 259 | state->m_smpc.OREG[10]= 0 << 7 | |
| 288 | 260 | state->m_vdp2.dotsel << 6 | |
| 289 | 261 | 1 << 5 | |
| 290 | 262 | 1 << 4 | |
| r12585 | r12586 | |
| 292 | 264 | 1 << 2 | |
| 293 | 265 | 0 << 1 | //SYSRES |
| 294 | 266 | 0 << 0; //SOUNDRES |
| 295 | | state->m_smpc_ram[0x37]= 0 << 6; //CDRES |
| 267 | state->m_smpc.OREG[11]= 0 << 6; //CDRES |
| 296 | 268 | |
| 297 | | state->m_smpc_ram[0x39]=0xff; |
| 298 | | state->m_smpc_ram[0x3b]=0xff; |
| 299 | | state->m_smpc_ram[0x3d]=0xff; |
| 300 | | state->m_smpc_ram[0x3f]=0xff; |
| 269 | for(i=0;i<4;i++) |
| 270 | state->m_smpc.OREG[12+i]=state->m_smpc.SMEM[i]; |
| 301 | 271 | |
| 302 | | state->m_smpc_ram[0x41]=0xff; |
| 303 | | state->m_smpc_ram[0x43]=0xff; |
| 304 | | state->m_smpc_ram[0x45]=0xff; |
| 305 | | state->m_smpc_ram[0x47]=0xff; |
| 306 | | state->m_smpc_ram[0x49]=0xff; |
| 307 | | state->m_smpc_ram[0x4b]=0xff; |
| 308 | | state->m_smpc_ram[0x4d]=0xff; |
| 309 | | state->m_smpc_ram[0x4f]=0xff; |
| 310 | | state->m_smpc_ram[0x51]=0xff; |
| 311 | | state->m_smpc_ram[0x53]=0xff; |
| 312 | | state->m_smpc_ram[0x55]=0xff; |
| 313 | | state->m_smpc_ram[0x57]=0xff; |
| 314 | | state->m_smpc_ram[0x59]=0xff; |
| 315 | | state->m_smpc_ram[0x5b]=0xff; |
| 316 | | state->m_smpc_ram[0x5d]=0xff; |
| 272 | for(i=0;i<15;i++) |
| 273 | state->m_smpc.OREG[16+i]=0xff; // undefined |
| 317 | 274 | |
| 318 | 275 | // /*This is for RTC,cartridge code and similar stuff...*/ |
| 319 | 276 | //if(LOG_SMPC) printf ("Interrupt: System Manager (SMPC) at scanline %04x, Vector 0x47 Level 0x08\n",scanline); |
| r12585 | r12586 | |
| 322 | 279 | else |
| 323 | 280 | state->m_scu.ist |= (IRQ_SMPC); |
| 324 | 281 | |
| 282 | /* put issued command in OREG31 */ |
| 283 | state->m_smpc.OREG[31] = 0x10; // TODO: doc says 0? |
| 325 | 284 | /* clear hand-shake flag */ |
| 326 | | state->m_smpc_ram[0x5f] = 0x10; |
| 327 | | state->m_smpc_ram[0x63] = 0x00; |
| 285 | state->m_smpc.SF = 0x00; |
| 328 | 286 | } |
| 329 | 287 | |
| 330 | 288 | static TIMER_CALLBACK( intback_peripheral ) |
| r12585 | r12586 | |
| 342 | 300 | for(pad_num=0;pad_num<2;pad_num++) |
| 343 | 301 | { |
| 344 | 302 | pad = input_port_read(machine, padnames[pad_num]); |
| 345 | | state->m_smpc_ram[0x21+pad_num*8] = 0xf1; // no tap, direct connect |
| 346 | | state->m_smpc_ram[0x23+pad_num*8] = 0x02; // saturn pad |
| 347 | | state->m_smpc_ram[0x25+pad_num*8] = pad>>8; |
| 348 | | state->m_smpc_ram[0x27+pad_num*8] = pad & 0xff; |
| 303 | state->m_smpc.OREG[0+pad_num*4] = 0xf1; // no tap, direct connect |
| 304 | state->m_smpc.OREG[1+pad_num*4] = 0x02; // saturn pad |
| 305 | state->m_smpc.OREG[2+pad_num*4] = pad>>8; |
| 306 | state->m_smpc.OREG[3+pad_num*4] = pad & 0xff; |
| 349 | 307 | } |
| 350 | 308 | |
| 351 | 309 | if (state->m_smpc.intback_stage == 2) |
| 352 | 310 | { |
| 353 | | state->m_smpc.smpcSR = (0x80 | state->m_smpc.pmode); // pad 2, no more data, echo back pad mode set by intback |
| 311 | state->m_smpc.SR = (0x80 | state->m_smpc.pmode); // pad 2, no more data, echo back pad mode set by intback |
| 354 | 312 | state->m_smpc.intback_stage = 0; |
| 355 | 313 | } |
| 356 | 314 | else |
| 357 | 315 | { |
| 358 | | state->m_smpc.smpcSR = (0xc0 | state->m_smpc.pmode); // pad 1, more data, echo back pad mode set by intback |
| 316 | state->m_smpc.SR = (0xc0 | state->m_smpc.pmode); // pad 1, more data, echo back pad mode set by intback |
| 359 | 317 | state->m_smpc.intback_stage ++; |
| 360 | 318 | } |
| 361 | 319 | |
| r12585 | r12586 | |
| 364 | 322 | else |
| 365 | 323 | state->m_scu.ist |= (IRQ_SMPC); |
| 366 | 324 | |
| 367 | | state->m_smpc_ram[0x5f] = 0x10; /* callback for last command issued */ |
| 368 | | state->m_smpc_ram[0x63] = 0x00; /* clear hand-shake flag */ |
| 325 | state->m_smpc.OREG[31] = 0x10; /* callback for last command issued */ |
| 326 | state->m_smpc.SF = 0x00; /* clear hand-shake flag */ |
| 369 | 327 | } |
| 370 | 328 | |
| 371 | 329 | static TIMER_CALLBACK( saturn_smpc_intback ) |
| 372 | 330 | { |
| 373 | 331 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 374 | 332 | |
| 375 | | if(state->m_smpc_ram[1] != 0) |
| 333 | if(state->m_smpc.IREG[0] != 0) |
| 376 | 334 | { |
| 377 | 335 | { |
| 378 | | state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 336 | int i; |
| 379 | 337 | |
| 380 | | { |
| 381 | | int i; |
| 338 | state->m_smpc.OREG[0] = (0x80) | ((state->m_NMI_reset & 1) << 6); // bit 7: SETTIME (RTC isn't setted up properly) |
| 382 | 339 | |
| 383 | | for(i=0;i<7;i++) |
| 384 | | state->m_smpc_ram[0x23+i*2] = state->m_smpc.rtc_data[i]; |
| 385 | | } |
| 340 | for(i=0;i<7;i++) |
| 341 | state->m_smpc.OREG[1+i] = state->m_smpc.rtc_data[i]; |
| 386 | 342 | |
| 387 | | state->m_smpc_ram[0x31]=0x00; //? |
| 343 | state->m_smpc.OREG[8]=0x00; //Cartridge code? |
| 388 | 344 | |
| 389 | | //state->m_smpc_ram[0x33]=input_port_read(space->machine(), "FAKE"); |
| 345 | state->m_smpc.OREG[9] = state->m_saturn_region; |
| 390 | 346 | |
| 391 | | state->m_smpc_ram[0x35]= 0 << 7 | |
| 347 | state->m_smpc.OREG[10]= 0 << 7 | |
| 392 | 348 | state->m_vdp2.dotsel << 6 | |
| 393 | 349 | 1 << 5 | |
| 394 | 350 | 1 << 4 | |
| r12585 | r12586 | |
| 396 | 352 | 1 << 2 | |
| 397 | 353 | 0 << 1 | //SYSRES |
| 398 | 354 | 0 << 0; //SOUNDRES |
| 399 | | state->m_smpc_ram[0x37]= 0 << 6; //CDRES |
| 355 | state->m_smpc.OREG[11]= 0 << 6; //CDRES |
| 400 | 356 | |
| 401 | | state->m_smpc_ram[0x39]=state->m_smpc.SMEM[0]; |
| 402 | | state->m_smpc_ram[0x3b]=state->m_smpc.SMEM[1]; |
| 403 | | state->m_smpc_ram[0x3d]=state->m_smpc.SMEM[2]; |
| 404 | | state->m_smpc_ram[0x3f]=state->m_smpc.SMEM[3]; |
| 357 | for(i=0;i<4;i++) |
| 358 | state->m_smpc.OREG[12+i]=state->m_smpc.SMEM[i]; |
| 405 | 359 | |
| 406 | | state->m_smpc_ram[0x41]=0xff; |
| 407 | | state->m_smpc_ram[0x43]=0xff; |
| 408 | | state->m_smpc_ram[0x45]=0xff; |
| 409 | | state->m_smpc_ram[0x47]=0xff; |
| 410 | | state->m_smpc_ram[0x49]=0xff; |
| 411 | | state->m_smpc_ram[0x4b]=0xff; |
| 412 | | state->m_smpc_ram[0x4d]=0xff; |
| 413 | | state->m_smpc_ram[0x4f]=0xff; |
| 414 | | state->m_smpc_ram[0x51]=0xff; |
| 415 | | state->m_smpc_ram[0x53]=0xff; |
| 416 | | state->m_smpc_ram[0x55]=0xff; |
| 417 | | state->m_smpc_ram[0x57]=0xff; |
| 418 | | state->m_smpc_ram[0x59]=0xff; |
| 419 | | state->m_smpc_ram[0x5b]=0xff; |
| 420 | | state->m_smpc_ram[0x5d]=0xff; |
| 360 | for(i=0;i<15;i++) |
| 361 | state->m_smpc.OREG[16+i]=0xff; // undefined |
| 421 | 362 | } |
| 422 | 363 | |
| 423 | | state->m_smpc.intback_stage = (state->m_smpc_ram[3] & 8) >> 3; // first peripheral |
| 424 | | state->m_smpc.smpcSR = 0x40 | state->m_smpc.intback_stage << 5; |
| 425 | | state->m_smpc.pmode = state->m_smpc_ram[1]>>4; |
| 426 | | state->m_smpc_ram[0x5f] = 0x10; |
| 364 | state->m_smpc.intback_stage = (state->m_smpc.IREG[1] & 8) >> 3; // first peripheral |
| 365 | state->m_smpc.SR = 0x40 | state->m_smpc.intback_stage << 5; |
| 366 | state->m_smpc.pmode = state->m_smpc.IREG[0]>>4; |
| 427 | 367 | |
| 428 | 368 | if(!(state->m_scu.ism & IRQ_SMPC)) |
| 429 | 369 | device_set_input_line_and_vector(state->m_maincpu, 8, HOLD_LINE, 0x47); |
| 430 | 370 | else |
| 431 | 371 | state->m_scu.ist |= (IRQ_SMPC); |
| 432 | 372 | |
| 373 | /* put issued command in OREG31 */ |
| 374 | state->m_smpc.OREG[31] = 0x10; |
| 433 | 375 | /* clear hand-shake flag */ |
| 434 | | state->m_smpc_ram[0x63] = 0x00; |
| 376 | state->m_smpc.SF = 0x00; |
| 435 | 377 | } |
| 436 | | else if(state->m_smpc_ram[3] & 8) |
| 378 | else if(state->m_smpc.IREG[1] & 8) |
| 437 | 379 | { |
| 438 | | state->m_smpc.intback_stage = (state->m_smpc_ram[3] & 8) >> 3; // first peripheral |
| 439 | | state->m_smpc.smpcSR = 0x40; |
| 440 | | state->m_smpc_ram[0x5f] = 0x10; |
| 380 | state->m_smpc.intback_stage = (state->m_smpc.IREG[1] & 8) >> 3; // first peripheral |
| 381 | state->m_smpc.SR = 0x40; |
| 382 | state->m_smpc.OREG[31] = 0x10; |
| 441 | 383 | machine.scheduler().timer_set(attotime::from_usec(0), FUNC(intback_peripheral),0); |
| 442 | 384 | } |
| 443 | 385 | else |
| 444 | 386 | { |
| 445 | | printf("SMPC intback bogus behaviour called %02x %02x\n",state->m_smpc_ram[1],state->m_smpc_ram[3]); |
| 387 | printf("SMPC intback bogus behaviour called %02x %02x\n",state->m_smpc.IREG[0],state->m_smpc.IREG[1]); |
| 446 | 388 | } |
| 447 | 389 | |
| 448 | 390 | } |
| r12585 | r12586 | |
| 453 | 395 | int i; |
| 454 | 396 | |
| 455 | 397 | for(i=0;i<7;i++) |
| 456 | | state->m_smpc.rtc_data[i] = state->m_smpc_ram[0x01+i*2]; |
| 398 | state->m_smpc.rtc_data[i] = state->m_smpc.IREG[i]; |
| 457 | 399 | } |
| 458 | 400 | |
| 459 | 401 | static void smpc_memory_setting(running_machine &machine) |
| r12585 | r12586 | |
| 462 | 404 | int i; |
| 463 | 405 | |
| 464 | 406 | for(i=0;i<4;i++) |
| 465 | | state->m_smpc.SMEM[i] = state->m_smpc_ram[0x01+i*2]; |
| 407 | state->m_smpc.SMEM[i] = state->m_smpc.IREG[i]; |
| 466 | 408 | } |
| 467 | 409 | |
| 468 | 410 | static void smpc_nmi_req(running_machine &machine) |
| r12585 | r12586 | |
| 478 | 420 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 479 | 421 | |
| 480 | 422 | state->m_NMI_reset = cmd ^ 1; |
| 481 | | state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 423 | state->m_smpc.OREG[0] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 482 | 424 | } |
| 483 | 425 | |
| 426 | /******************************************** |
| 427 | * |
| 428 | * ST-V handlers |
| 429 | * |
| 430 | *******************************************/ |
| 431 | |
| 432 | READ8_HANDLER( stv_SMPC_r ) |
| 433 | { |
| 434 | saturn_state *state = space->machine().driver_data<saturn_state>(); |
| 435 | int return_data = 0; |
| 436 | |
| 437 | if(!(offset & 1)) |
| 438 | return 0; |
| 439 | |
| 440 | if(offset >= 0x21 && offset <= 0x5f) |
| 441 | return_data = state->m_smpc.OREG[(offset-0x21) >> 1]; |
| 442 | |
| 443 | if (offset == 0x61) // TODO: SR |
| 444 | return_data = 0x20 ^ 0xff; |
| 445 | |
| 446 | if (offset == 0x63) |
| 447 | return_data = state->m_smpc.SF; |
| 448 | |
| 449 | if (offset == 0x75)//PDR1 read |
| 450 | return_data = input_port_read(space->machine(), "DSW1"); |
| 451 | |
| 452 | if (offset == 0x77)//PDR2 read |
| 453 | return_data = (0xfe | space->machine().device<eeprom_device>("eeprom")->read_bit()); |
| 454 | |
| 455 | return return_data; |
| 456 | } |
| 457 | |
| 458 | static void stv_comreg_exec(address_space *space,UINT8 data) |
| 459 | { |
| 460 | switch (data) |
| 461 | { |
| 462 | case 0x00: |
| 463 | if(LOG_SMPC) printf ("SMPC: Master ON\n"); |
| 464 | smpc_master_on(space->machine()); |
| 465 | break; |
| 466 | //in theory 0x01 is for Master OFF,but obviously is not used. |
| 467 | case 0x02: |
| 468 | case 0x03: |
| 469 | if(LOG_SMPC) printf ("SMPC: Slave %s\n",(data & 1) ? "off" : "on"); |
| 470 | space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_slave_enable),data & 1); |
| 471 | break; |
| 472 | case 0x06: |
| 473 | case 0x07: |
| 474 | if(LOG_SMPC) printf ("SMPC: Sound %s, ignored\n",(data & 1) ? "off" : "on"); |
| 475 | break; |
| 476 | /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/ |
| 477 | //case 0x08: |
| 478 | //case 0x09: |
| 479 | case 0x0d: |
| 480 | if(LOG_SMPC) printf ("SMPC: System Reset\n"); |
| 481 | smpc_system_reset(space->machine()); |
| 482 | break; |
| 483 | case 0x0e: |
| 484 | case 0x0f: |
| 485 | if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352"); |
| 486 | smpc_change_clock(space->machine(),data & 1); |
| 487 | break; |
| 488 | /*"Interrupt Back"*/ |
| 489 | case 0x10: |
| 490 | if(LOG_SMPC) printf ("SMPC: Status Acquire\n"); |
| 491 | space->machine().scheduler().timer_set(attotime::from_msec(16), FUNC(stv_smpc_intback),0); //TODO: variable time |
| 492 | break; |
| 493 | /* RTC write*/ |
| 494 | case 0x16: |
| 495 | if(LOG_SMPC) printf("SMPC: RTC write\n"); |
| 496 | smpc_rtc_write(space->machine()); |
| 497 | break; |
| 498 | /* SMPC memory setting*/ |
| 499 | case 0x17: |
| 500 | if(LOG_SMPC) printf ("SMPC: memory setting\n"); |
| 501 | //smpc_memory_setting(space->machine()); |
| 502 | break; |
| 503 | case 0x18: |
| 504 | if(LOG_SMPC) printf ("SMPC: NMI request\n"); |
| 505 | smpc_nmi_req(space->machine()); |
| 506 | break; |
| 507 | case 0x19: |
| 508 | case 0x1a: |
| 509 | if(LOG_SMPC) printf ("SMPC: NMI %sable\n",data & 1 ? "Dis" : "En"); |
| 510 | smpc_nmi_set(space->machine(),data & 1); |
| 511 | break; |
| 512 | default: |
| 513 | printf ("cpu '%s' (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data); |
| 514 | } |
| 515 | } |
| 516 | |
| 484 | 517 | WRITE8_HANDLER( stv_SMPC_w ) |
| 485 | 518 | { |
| 486 | 519 | saturn_state *state = space->machine().driver_data<saturn_state>(); |
| 487 | | system_time systime; |
| 488 | | space->machine().base_datetime(systime); |
| 489 | 520 | |
| 521 | if (!(offset & 1)) // avoid writing to even bytes |
| 522 | return; |
| 523 | |
| 490 | 524 | // if(LOG_SMPC) printf ("8-bit SMPC Write to Offset %02x with Data %02x\n", offset, data); |
| 491 | | state->m_smpc_ram[offset] = data; |
| 492 | 525 | |
| 526 | if(offset >= 1 && offset <= 0xd) |
| 527 | state->m_smpc.IREG[offset >> 1] = data; |
| 528 | |
| 529 | if (offset == 0x1f) // COMREG |
| 530 | { |
| 531 | stv_comreg_exec(space,data); |
| 532 | |
| 533 | // we've processed the command, clear status flag |
| 534 | if(data != 0x10 && data != 0x02 && data != 0x03) |
| 535 | { |
| 536 | state->m_smpc.OREG[31] = data; //read-back command |
| 537 | state->m_smpc.SF = 0x00; |
| 538 | } |
| 539 | /*TODO:emulate the timing of each command...*/ |
| 540 | } |
| 541 | |
| 542 | if(offset == 0x63) |
| 543 | state->m_smpc.SF = data & 1; |
| 544 | |
| 493 | 545 | if(offset == 0x75) |
| 494 | 546 | { |
| 495 | 547 | /* |
| r12585 | r12586 | |
| 518 | 570 | */ |
| 519 | 571 | //popmessage("PDR2 = %02x",state->m_smpc_ram[0x77]); |
| 520 | 572 | |
| 521 | | if(LOG_SMPC) printf("SMPC: M68k %s\n",(state->m_smpc_ram[0x77] & 0x10) ? "off" : "on"); |
| 573 | if(LOG_SMPC) printf("SMPC: M68k %s\n",(data & 0x10) ? "off" : "on"); |
| 522 | 574 | //space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_sound_enable),(state->m_smpc_ram[0x77] & 0x10) >> 4); |
| 523 | | device_set_input_line(state->m_audiocpu, INPUT_LINE_RESET, (state->m_smpc_ram[0x77] & 0x10) ? ASSERT_LINE : CLEAR_LINE); |
| 524 | | state->m_en_68k = ((state->m_smpc_ram[0x77] & 0x10) >> 4) ^ 1; |
| 575 | device_set_input_line(state->m_audiocpu, INPUT_LINE_RESET, (data & 0x10) ? ASSERT_LINE : CLEAR_LINE); |
| 576 | state->m_en_68k = ((data & 0x10) >> 4) ^ 1; |
| 525 | 577 | |
| 526 | | //if(LOG_SMPC) printf("SMPC: ram [0x77] = %02x\n",state->m_smpc_ram[0x77]); |
| 578 | //if(LOG_SMPC) printf("SMPC: ram [0x77] = %02x\n",data); |
| 527 | 579 | state->m_smpc.PDR2 = (data & 0x60); |
| 528 | 580 | } |
| 529 | 581 | |
| r12585 | r12586 | |
| 533 | 585 | ---- --x- IOSEL2 direct (1) / control mode (0) port select |
| 534 | 586 | ---- ---x IOSEL1 direct (1) / control mode (0) port select |
| 535 | 587 | */ |
| 536 | | state->m_smpc.IOSEL1 = (state->m_smpc_ram[0x7d] & 1) >> 0; |
| 537 | | state->m_smpc.IOSEL2 = (state->m_smpc_ram[0x7d] & 2) >> 1; |
| 588 | state->m_smpc.IOSEL1 = (data & 1) >> 0; |
| 589 | state->m_smpc.IOSEL2 = (data & 2) >> 1; |
| 538 | 590 | } |
| 539 | 591 | |
| 540 | 592 | if(offset == 0x7f) |
| 541 | 593 | { |
| 542 | 594 | //enable PAD irq & VDP2 external latch for port 1/2 |
| 543 | | state->m_smpc.EXLE1 = (state->m_smpc_ram[0x7f] & 1) >> 0; |
| 544 | | state->m_smpc.EXLE2 = (state->m_smpc_ram[0x7f] & 2) >> 1; |
| 595 | state->m_smpc.EXLE1 = (data & 1) >> 0; |
| 596 | state->m_smpc.EXLE2 = (data & 2) >> 1; |
| 545 | 597 | } |
| 546 | | |
| 547 | | if (offset == 0x1f) // COMREG |
| 548 | | { |
| 549 | | switch (data) |
| 550 | | { |
| 551 | | case 0x00: |
| 552 | | if(LOG_SMPC) printf ("SMPC: Master ON\n"); |
| 553 | | smpc_master_on(space->machine()); |
| 554 | | break; |
| 555 | | //in theory 0x01 is for Master OFF,but obviously is not used. |
| 556 | | case 0x02: |
| 557 | | case 0x03: |
| 558 | | if(LOG_SMPC) printf ("SMPC: Slave %s\n",(data & 1) ? "off" : "on"); |
| 559 | | space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_slave_enable),data & 1); |
| 560 | | break; |
| 561 | | case 0x06: |
| 562 | | case 0x07: |
| 563 | | if(LOG_SMPC) printf ("SMPC: Sound %s, ignored\n",(data & 1) ? "off" : "on"); |
| 564 | | break; |
| 565 | | /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/ |
| 566 | | //case 0x08: |
| 567 | | //case 0x09: |
| 568 | | case 0x0d: |
| 569 | | if(LOG_SMPC) printf ("SMPC: System Reset\n"); |
| 570 | | smpc_system_reset(space->machine()); |
| 571 | | break; |
| 572 | | case 0x0e: |
| 573 | | case 0x0f: |
| 574 | | if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352"); |
| 575 | | smpc_change_clock(space->machine(),data & 1); |
| 576 | | break; |
| 577 | | /*"Interrupt Back"*/ |
| 578 | | case 0x10: |
| 579 | | if(LOG_SMPC) printf ("SMPC: Status Acquire\n"); |
| 580 | | space->machine().scheduler().timer_set(attotime::from_msec(16), FUNC(stv_smpc_intback),0); //TODO: variable time |
| 581 | | break; |
| 582 | | /* RTC write*/ |
| 583 | | case 0x16: |
| 584 | | if(LOG_SMPC) printf("SMPC: RTC write\n"); |
| 585 | | smpc_rtc_write(space->machine()); |
| 586 | | break; |
| 587 | | /* SMPC memory setting*/ |
| 588 | | case 0x17: |
| 589 | | if(LOG_SMPC) printf ("SMPC: memory setting\n"); |
| 590 | | //smpc_memory_setting(space->machine()); |
| 591 | | break; |
| 592 | | case 0x18: |
| 593 | | if(LOG_SMPC) printf ("SMPC: NMI request\n"); |
| 594 | | smpc_nmi_req(space->machine()); |
| 595 | | break; |
| 596 | | case 0x19: |
| 597 | | case 0x1a: |
| 598 | | if(LOG_SMPC) printf ("SMPC: NMI %sable\n",data & 1 ? "Dis" : "En"); |
| 599 | | smpc_nmi_set(space->machine(),data & 1); |
| 600 | | break; |
| 601 | | default: |
| 602 | | printf ("cpu '%s' (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data); |
| 603 | | } |
| 604 | | |
| 605 | | // we've processed the command, clear status flag |
| 606 | | if(data != 0x10 && data != 0x02 && data != 0x03) |
| 607 | | { |
| 608 | | state->m_smpc_ram[0x5f] = data; //read-back command |
| 609 | | state->m_smpc_ram[0x63] = 0x00; |
| 610 | | } |
| 611 | | /*TODO:emulate the timing of each command...*/ |
| 612 | | } |
| 613 | 598 | } |
| 614 | 599 | |
| 600 | /******************************************** |
| 601 | * |
| 602 | * Saturn handlers |
| 603 | * |
| 604 | *******************************************/ |
| 605 | |
| 615 | 606 | READ8_HANDLER( saturn_SMPC_r ) |
| 616 | 607 | { |
| 617 | 608 | saturn_state *state = space->machine().driver_data<saturn_state>(); |
| 618 | | int return_data; |
| 609 | UINT8 return_data = 0; |
| 619 | 610 | |
| 620 | | return_data = state->m_smpc_ram[offset]; |
| 611 | if (!(offset & 1)) // avoid reading to even bytes (TODO: is it 0s or 1s?) |
| 612 | return 0x00; |
| 621 | 613 | |
| 622 | | if ((offset == 0x61)) |
| 623 | | return_data = state->m_smpc.smpcSR; |
| 614 | if(offset >= 0x21 && offset <= 0x5f) |
| 615 | return_data = state->m_smpc.OREG[(offset-0x21) >> 1]; |
| 624 | 616 | |
| 617 | if (offset == 0x61) |
| 618 | return_data = state->m_smpc.SR; |
| 619 | |
| 620 | if (offset == 0x63) |
| 621 | return_data = state->m_smpc.SF; |
| 622 | |
| 625 | 623 | if (offset == 0x75 || offset == 0x77)//PDR1/2 read |
| 626 | 624 | { |
| 627 | | /* |
| 628 | | PORT_START("JOY1") |
| 629 | | PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) |
| 630 | | PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) |
| 631 | | PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) |
| 632 | | PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1) |
| 633 | | PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(1) // START |
| 634 | | PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_NAME("P1 A") PORT_PLAYER(1) // A |
| 635 | | PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_NAME("P1 B") PORT_PLAYER(1) // B |
| 636 | | PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_NAME("P1 C") PORT_PLAYER(1) // C |
| 637 | | PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON8 ) PORT_NAME("P1 R") PORT_PLAYER(1) // R |
| 638 | | PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_NAME("P1 X") PORT_PLAYER(1) // X |
| 639 | | PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_NAME("P1 Y") PORT_PLAYER(1) // Y |
| 640 | | PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("P1 Z") PORT_PLAYER(1) // Z |
| 641 | | PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_BUTTON7 ) PORT_NAME("P1 L") PORT_PLAYER(1) // L |
| 642 | | */ |
| 643 | 625 | if ((state->m_smpc.IOSEL1 && offset == 0x75) || (state->m_smpc.IOSEL2 && offset == 0x77)) |
| 644 | 626 | { |
| 645 | 627 | int hshake; |
| r12585 | r12586 | |
| 657 | 639 | } |
| 658 | 640 | } |
| 659 | 641 | |
| 660 | | if (offset == 0x33) return_data = state->m_saturn_region; |
| 661 | | |
| 662 | 642 | if (LOG_SMPC) logerror ("cpu %s (PC=%08X) SMPC: Read from Byte Offset %02x (%d) Returns %02x\n", space->device().tag(), cpu_get_pc(&space->device()), offset, offset>>1, return_data); |
| 663 | 643 | |
| 664 | 644 | |
| 665 | 645 | return return_data; |
| 666 | 646 | } |
| 667 | 647 | |
| 668 | | WRITE8_HANDLER( saturn_SMPC_w ) |
| 648 | static void saturn_comreg_exec(address_space *space,UINT8 data) |
| 669 | 649 | { |
| 670 | 650 | saturn_state *state = space->machine().driver_data<saturn_state>(); |
| 671 | | system_time systime; |
| 672 | | // UINT8 last; |
| 673 | | running_machine &machine = space->machine(); |
| 674 | 651 | |
| 675 | | /* get the current date/time from the core */ |
| 676 | | machine.current_datetime(systime); |
| 652 | switch (data) |
| 653 | { |
| 654 | case 0x00: |
| 655 | if(LOG_SMPC) printf ("SMPC: Master ON\n"); |
| 656 | smpc_master_on(space->machine()); |
| 657 | break; |
| 658 | //in theory 0x01 is for Master OFF |
| 659 | case 0x02: |
| 660 | case 0x03: |
| 661 | if(LOG_SMPC) printf ("SMPC: Slave %s\n",(data & 1) ? "off" : "on"); |
| 662 | space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_slave_enable),data & 1); |
| 663 | break; |
| 664 | case 0x06: |
| 665 | case 0x07: |
| 666 | if(LOG_SMPC) printf ("SMPC: Sound %s\n",(data & 1) ? "off" : "on"); |
| 667 | space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_sound_enable),data & 1); |
| 668 | break; |
| 669 | /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/ |
| 670 | //case 0x08: |
| 671 | //case 0x09: |
| 672 | case 0x0d: |
| 673 | if(LOG_SMPC) printf ("SMPC: System Reset\n"); |
| 674 | smpc_system_reset(space->machine()); |
| 675 | break; |
| 676 | case 0x0e: |
| 677 | case 0x0f: |
| 678 | if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352"); |
| 679 | smpc_change_clock(space->machine(),data & 1); |
| 680 | break; |
| 681 | /*"Interrupt Back"*/ |
| 682 | case 0x10: |
| 683 | if(LOG_SMPC) printf ("SMPC: Status Acquire (IntBack)\n"); |
| 684 | int timing; |
| 677 | 685 | |
| 678 | | if (LOG_SMPC) logerror ("8-bit SMPC Write to Offset %02x (reg %d) with Data %02x (prev %02x)\n", offset, offset>>1, data, state->m_smpc_ram[offset]); |
| 686 | timing = 100; |
| 679 | 687 | |
| 680 | | // if (offset == 0x7d) printf("IOSEL2 %d IOSEL1 %d\n", (data>>1)&1, data&1); |
| 688 | if(state->m_smpc.IREG[0] != 0) // non-peripheral data |
| 689 | timing = 200; |
| 681 | 690 | |
| 682 | | // last = state->m_smpc_ram[offset]; |
| 691 | if(state->m_smpc.IREG[1] & 8) // peripheral data |
| 692 | timing = 15000; |
| 683 | 693 | |
| 684 | | if (offset == 1) |
| 694 | /* TODO: check if IREG[2] is setted to 0xf0 */ |
| 695 | |
| 696 | if(LOG_PAD_CMD) printf("INTBACK %02x %02x\n",state->m_smpc.IREG[0],state->m_smpc.IREG[1]); |
| 697 | space->machine().scheduler().timer_set(attotime::from_usec(timing), FUNC(saturn_smpc_intback),0); //TODO: is variable time correct? |
| 698 | break; |
| 699 | /* RTC write*/ |
| 700 | case 0x16: |
| 701 | if(LOG_SMPC) printf("SMPC: RTC write\n"); |
| 702 | smpc_rtc_write(space->machine()); |
| 703 | break; |
| 704 | /* SMPC memory setting*/ |
| 705 | case 0x17: |
| 706 | if(LOG_SMPC) printf ("SMPC: memory setting\n"); |
| 707 | smpc_memory_setting(space->machine()); |
| 708 | break; |
| 709 | case 0x18: |
| 710 | if(LOG_SMPC) printf ("SMPC: NMI request\n"); |
| 711 | smpc_nmi_req(space->machine()); |
| 712 | break; |
| 713 | case 0x19: |
| 714 | case 0x1a: |
| 715 | if(LOG_SMPC) printf ("SMPC: NMI %sable\n",data & 1 ? "Dis" : "En"); |
| 716 | smpc_nmi_set(space->machine(),data & 1); |
| 717 | break; |
| 718 | default: |
| 719 | printf ("cpu %s (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data); |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | WRITE8_HANDLER( saturn_SMPC_w ) |
| 724 | { |
| 725 | saturn_state *state = space->machine().driver_data<saturn_state>(); |
| 726 | |
| 727 | if (LOG_SMPC) logerror ("8-bit SMPC Write to Offset %02x (reg %d) with Data %02x\n", offset, offset>>1, data); |
| 728 | |
| 729 | if (!(offset & 1)) // avoid writing to even bytes |
| 730 | return; |
| 731 | |
| 732 | if(offset >= 1 && offset <= 0xd) |
| 733 | state->m_smpc.IREG[offset >> 1] = data; |
| 734 | |
| 735 | if(offset == 1) //IREG0, check if a BREAK / CONTINUE request for INTBACK command |
| 685 | 736 | { |
| 686 | 737 | if(state->m_smpc.intback_stage) |
| 687 | 738 | { |
| 688 | 739 | if(data & 0x40) |
| 689 | 740 | { |
| 690 | 741 | if(LOG_PAD_CMD) printf("SMPC: BREAK request\n"); |
| 691 | | state->m_smpc.smpcSR &= 0x0f; |
| 742 | state->m_smpc.SR &= 0x0f; |
| 692 | 743 | state->m_smpc.intback_stage = 0; |
| 693 | 744 | } |
| 694 | 745 | else if(data & 0x80) |
| 695 | 746 | { |
| 696 | 747 | if(LOG_PAD_CMD) printf("SMPC: CONTINUE request\n"); |
| 697 | 748 | space->machine().scheduler().timer_set(attotime::from_usec(200), FUNC(intback_peripheral),0); /* TODO: is timing correct? */ |
| 698 | | state->m_smpc_ram[0x1f] = 0x10; |
| 699 | | //state->m_smpc_ram[0x63] = 0x01; //TODO: set hand-shake flag? |
| 749 | state->m_smpc.OREG[31] = 0x10; |
| 750 | //state->m_smpc.SF = 0x01; //TODO: set hand-shake flag? |
| 700 | 751 | } |
| 701 | 752 | } |
| 702 | 753 | } |
| 703 | 754 | |
| 704 | | state->m_smpc_ram[offset] = data; |
| 705 | | |
| 706 | | if (offset == 0x75) // PDR1 |
| 755 | if (offset == 0x1f) |
| 707 | 756 | { |
| 708 | | state->m_smpc.PDR1 = (data & state->m_smpc_ram[0x79]); |
| 709 | | } |
| 757 | saturn_comreg_exec(space,data); |
| 710 | 758 | |
| 711 | | if (offset == 0x77) // PDR2 |
| 712 | | { |
| 713 | | state->m_smpc.PDR2 = (data & state->m_smpc_ram[0x7b]); |
| 759 | // we've processed the command, clear status flag |
| 760 | if(data != 0x10 && data != 2 && data != 3 && data != 6 && data != 7) |
| 761 | { |
| 762 | state->m_smpc.OREG[31] = data; //read-back for last command issued |
| 763 | state->m_smpc.SF = 0x00; //clear hand-shake flag |
| 764 | } |
| 765 | /*TODO:emulate the timing of each command...*/ |
| 714 | 766 | } |
| 715 | 767 | |
| 768 | if (offset == 0x63) |
| 769 | state->m_smpc.SF = data & 1; // hand-shake flag |
| 770 | |
| 771 | if(offset == 0x75) // PDR1 |
| 772 | state->m_smpc.PDR1 = (data & state->m_smpc.DDR1); |
| 773 | |
| 774 | if(offset == 0x77) // PDR2 |
| 775 | state->m_smpc.PDR2 = (data & state->m_smpc.DDR2); |
| 776 | |
| 777 | if(offset == 0x79) |
| 778 | state->m_smpc.DDR1 = data & 0x7f; |
| 779 | |
| 780 | if(offset == 0x7b) |
| 781 | state->m_smpc.DDR2 = data & 0x7f; |
| 782 | |
| 716 | 783 | if(offset == 0x7d) |
| 717 | 784 | { |
| 718 | | state->m_smpc.IOSEL1 = state->m_smpc_ram[0x7d] & 1; |
| 719 | | state->m_smpc.IOSEL2 = (state->m_smpc_ram[0x7d] & 2) >> 1; |
| 785 | state->m_smpc.IOSEL1 = data & 1; |
| 786 | state->m_smpc.IOSEL2 = (data & 2) >> 1; |
| 720 | 787 | } |
| 721 | 788 | |
| 722 | 789 | if(offset == 0x7f) |
| 723 | 790 | { |
| 724 | 791 | //enable PAD irq & VDP2 external latch for port 1/2 |
| 725 | | state->m_smpc.EXLE1 = (state->m_smpc_ram[0x7f] & 1) >> 0; |
| 726 | | state->m_smpc.EXLE2 = (state->m_smpc_ram[0x7f] & 2) >> 1; |
| 792 | state->m_smpc.EXLE1 = (data & 1) >> 0; |
| 793 | state->m_smpc.EXLE2 = (data & 2) >> 1; |
| 727 | 794 | } |
| 728 | | |
| 729 | | if (offset == 0x1f) |
| 730 | | { |
| 731 | | switch (data) |
| 732 | | { |
| 733 | | case 0x00: |
| 734 | | if(LOG_SMPC) printf ("SMPC: Master ON\n"); |
| 735 | | smpc_master_on(space->machine()); |
| 736 | | break; |
| 737 | | //in theory 0x01 is for Master OFF |
| 738 | | case 0x02: |
| 739 | | case 0x03: |
| 740 | | if(LOG_SMPC) printf ("SMPC: Slave %s\n",(data & 1) ? "off" : "on"); |
| 741 | | space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_slave_enable),data & 1); |
| 742 | | break; |
| 743 | | case 0x06: |
| 744 | | case 0x07: |
| 745 | | if(LOG_SMPC) printf ("SMPC: Sound %s\n",(data & 1) ? "off" : "on"); |
| 746 | | space->machine().scheduler().timer_set(attotime::from_usec(100), FUNC(smpc_sound_enable),data & 1); |
| 747 | | break; |
| 748 | | /*CD (SH-1) ON/OFF,guess that this is needed for Sports Fishing games...*/ |
| 749 | | //case 0x08: |
| 750 | | //case 0x09: |
| 751 | | case 0x0d: |
| 752 | | if(LOG_SMPC) printf ("SMPC: System Reset\n"); |
| 753 | | smpc_system_reset(space->machine()); |
| 754 | | break; |
| 755 | | case 0x0e: |
| 756 | | case 0x0f: |
| 757 | | if(LOG_SMPC) printf ("SMPC: Change Clock to %s\n",data & 1 ? "320" : "352"); |
| 758 | | smpc_change_clock(space->machine(),data & 1); |
| 759 | | break; |
| 760 | | /*"Interrupt Back"*/ |
| 761 | | case 0x10: |
| 762 | | if(LOG_SMPC) printf ("SMPC: Status Acquire (IntBack)\n"); |
| 763 | | int timing; |
| 764 | | |
| 765 | | timing = 100; |
| 766 | | |
| 767 | | if(state->m_smpc_ram[1] != 0) // non-peripheral data |
| 768 | | timing = 200; |
| 769 | | |
| 770 | | if(state->m_smpc_ram[3] & 8) // peripheral data |
| 771 | | timing = 15000; |
| 772 | | |
| 773 | | if(LOG_PAD_CMD) printf("INTBACK %02x %02x\n",state->m_smpc_ram[1],state->m_smpc_ram[3]); |
| 774 | | |
| 775 | | space->machine().scheduler().timer_set(attotime::from_usec(timing), FUNC(saturn_smpc_intback),0); //TODO: is variable time correct? |
| 776 | | break; |
| 777 | | /* RTC write*/ |
| 778 | | case 0x16: |
| 779 | | if(LOG_SMPC) printf("SMPC: RTC write\n"); |
| 780 | | smpc_rtc_write(space->machine()); |
| 781 | | break; |
| 782 | | /* SMPC memory setting*/ |
| 783 | | case 0x17: |
| 784 | | if(LOG_SMPC) printf ("SMPC: memory setting\n"); |
| 785 | | smpc_memory_setting(space->machine()); |
| 786 | | break; |
| 787 | | case 0x18: |
| 788 | | if(LOG_SMPC) printf ("SMPC: NMI request\n"); |
| 789 | | smpc_nmi_req(space->machine()); |
| 790 | | break; |
| 791 | | case 0x19: |
| 792 | | case 0x1a: |
| 793 | | if(LOG_SMPC) printf ("SMPC: NMI %sable\n",data & 1 ? "Dis" : "En"); |
| 794 | | smpc_nmi_set(space->machine(),data & 1); |
| 795 | | break; |
| 796 | | default: |
| 797 | | printf ("cpu %s (PC=%08X) SMPC: undocumented Command %02x\n", space->device().tag(), cpu_get_pc(&space->device()), data); |
| 798 | | } |
| 799 | | |
| 800 | | // we've processed the command, clear status flag |
| 801 | | if(data != 0x10 && data != 2 && data != 3 && data != 6 && data != 7) |
| 802 | | { |
| 803 | | state->m_smpc_ram[0x5f] = data; //read-back for last command issued |
| 804 | | state->m_smpc_ram[0x63] = 0x00; //clear hand-shake flag |
| 805 | | } |
| 806 | | /*TODO:emulate the timing of each command...*/ |
| 807 | | } |
| 808 | 795 | } |
src/mame/drivers/saturn.c
| r12585 | r12586 | |
| 1416 | 1416 | state->m_minit_boost_timeslice = attotime::zero; |
| 1417 | 1417 | state->m_sinit_boost_timeslice = attotime::zero; |
| 1418 | 1418 | |
| 1419 | | state->m_smpc_ram = auto_alloc_array(machine, UINT8, 0x80); |
| 1420 | 1419 | state->m_scu_regs = auto_alloc_array(machine, UINT32, 0x100/4); |
| 1421 | 1420 | state->m_scsp_regs = auto_alloc_array(machine, UINT16, 0x1000/2); |
| 1422 | 1421 | state->m_backupram = auto_alloc_array(machine, UINT8, 0x10000); |
| r12585 | r12586 | |
| 1435 | 1434 | //machine.device("slave")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc44, 0x60ffc47, FUNC(w60ffc44_write) ); |
| 1436 | 1435 | //machine.device("slave")->memory().space(AS_PROGRAM)->install_legacy_write_handler(0x60ffc48, 0x60ffc4b, FUNC(w60ffc48_write) ); |
| 1437 | 1436 | |
| 1438 | | state->m_smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??) |
| 1439 | | // state->m_smpc_ram[0x33] = input_port_read(machine, "FAKE"); |
| 1440 | | state->m_smpc_ram[0x5f] = 0x10; |
| 1441 | | |
| 1442 | 1437 | state->m_vdp2.pal = 0; |
| 1443 | 1438 | } |
| 1444 | 1439 | |
| r12585 | r12586 | |
| 1571 | 1566 | static int year_num, year_count; |
| 1572 | 1567 | |
| 1573 | 1568 | /* |
| 1574 | | state->m_smpc_ram[0x23] = DectoBCD(systime.local_time.year /100); |
| 1575 | | state->m_smpc_ram[0x25] = DectoBCD(systime.local_time.year %100); |
| 1576 | | state->m_smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month+1); |
| 1577 | | state->m_smpc_ram[0x29] = DectoBCD(systime.local_time.mday); |
| 1578 | | state->m_smpc_ram[0x2b] = DectoBCD(systime.local_time.hour); |
| 1579 | | state->m_smpc_ram[0x2d] = DectoBCD(systime.local_time.minute); |
| 1580 | | state->m_smpc_ram[0x2f] = DectoBCD(systime.local_time.second); |
| 1569 | state->m_smpc.rtc_data[0] = DectoBCD(systime.local_time.year /100); |
| 1570 | state->m_smpc.rtc_data[1] = DectoBCD(systime.local_time.year %100); |
| 1571 | state->m_smpc.rtc_data[2] = (systime.local_time.weekday << 4) | (systime.local_time.month+1); |
| 1572 | state->m_smpc.rtc_data[3] = DectoBCD(systime.local_time.mday); |
| 1573 | state->m_smpc.rtc_data[4] = DectoBCD(systime.local_time.hour); |
| 1574 | state->m_smpc.rtc_data[5] = DectoBCD(systime.local_time.minute); |
| 1575 | state->m_smpc.rtc_data[6] = DectoBCD(systime.local_time.second); |
| 1581 | 1576 | */ |
| 1582 | 1577 | |
| 1583 | 1578 | state->m_smpc.rtc_data[6]++; |
| r12585 | r12586 | |
| 1647 | 1642 | scsp_set_ram_base(machine.device("scsp"), state->m_sound_ram); |
| 1648 | 1643 | |
| 1649 | 1644 | // save states |
| 1650 | | state_save_register_global_pointer(machine, state->m_smpc_ram, 0x80); |
| 1651 | 1645 | state_save_register_global_pointer(machine, state->m_scu_regs, 0x100/4); |
| 1652 | 1646 | state_save_register_global_pointer(machine, state->m_scsp_regs, 0x1000/2); |
| 1653 | 1647 | state_save_register_global(machine, state->m_NMI_reset); |
| r12585 | r12586 | |
| 1692 | 1686 | scsp_set_ram_base(machine.device("scsp"), state->m_sound_ram); |
| 1693 | 1687 | |
| 1694 | 1688 | // save states |
| 1695 | | state_save_register_global_pointer(machine, state->m_smpc_ram, 0x80); |
| 1696 | 1689 | state_save_register_global_pointer(machine, state->m_scu_regs, 0x100/4); |
| 1697 | 1690 | state_save_register_global_pointer(machine, state->m_scsp_regs, 0x1000/2); |
| 1698 | 1691 | state_save_register_global(machine, state->m_NMI_reset); |
| r12585 | r12586 | |
| 1708 | 1701 | state_save_register_global(machine, scsp_last_line); |
| 1709 | 1702 | state_save_register_global(machine, state->m_smpc.intback_stage); |
| 1710 | 1703 | state_save_register_global(machine, state->m_smpc.pmode); |
| 1711 | | state_save_register_global(machine, state->m_smpc.smpcSR); |
| 1704 | state_save_register_global(machine, state->m_smpc.SR); |
| 1712 | 1705 | state_save_register_global_array(machine, state->m_smpc.SMEM); |
| 1713 | 1706 | state_save_register_global_pointer(machine, state->m_cart_dram, 0x400000/4); |
| 1714 | 1707 | |
| r12585 | r12586 | |
| 1931 | 1924 | cputag_set_input_line(machine, "slave", INPUT_LINE_RESET, ASSERT_LINE); |
| 1932 | 1925 | cputag_set_input_line(machine, "audiocpu", INPUT_LINE_RESET, ASSERT_LINE); |
| 1933 | 1926 | |
| 1934 | | state->m_smpc.smpcSR = 0x40; // this bit is always on according to docs |
| 1927 | state->m_smpc.SR = 0x40; // this bit is always on according to docs |
| 1935 | 1928 | |
| 1936 | 1929 | state->m_en_68k = 0; |
| 1937 | 1930 | state->m_NMI_reset = 1; |
| 1938 | | state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 1939 | 1931 | |
| 1940 | 1932 | DMA_STATUS = 0; |
| 1941 | 1933 | |
| r12585 | r12586 | |
| 2015 | 2007 | |
| 2016 | 2008 | state->m_en_68k = 0; |
| 2017 | 2009 | state->m_NMI_reset = 1; |
| 2018 | | state->m_smpc_ram[0x21] = (0x80) | ((state->m_NMI_reset & 1) << 6); |
| 2019 | 2010 | |
| 2020 | 2011 | port_sel = mux_data = 0; |
| 2021 | 2012 | port_i = -1; |
| r12585 | r12586 | |
| 2231 | 2222 | static void saturn_init_driver(running_machine &machine, int rgn) |
| 2232 | 2223 | { |
| 2233 | 2224 | saturn_state *state = machine.driver_data<saturn_state>(); |
| 2234 | | system_time systime; |
| 2235 | 2225 | |
| 2236 | 2226 | state->m_saturn_region = rgn; |
| 2237 | 2227 | state->m_vdp2.pal = (rgn == 12) ? 1 : 0; |
| r12585 | r12586 | |
| 2240 | 2230 | sh2drc_set_options(machine.device("maincpu"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL); |
| 2241 | 2231 | sh2drc_set_options(machine.device("slave"), SH2DRC_STRICT_VERIFY|SH2DRC_STRICT_PCREL); |
| 2242 | 2232 | |
| 2243 | | /* get the current date/time from the core */ |
| 2244 | | machine.current_datetime(systime); |
| 2245 | | |
| 2246 | 2233 | /* amount of time to boost interleave for on MINIT / SINIT, needed for communication to work */ |
| 2247 | 2234 | state->m_minit_boost = 400; |
| 2248 | 2235 | state->m_sinit_boost = 400; |
| 2249 | 2236 | state->m_minit_boost_timeslice = attotime::zero; |
| 2250 | 2237 | state->m_sinit_boost_timeslice = attotime::zero; |
| 2251 | 2238 | |
| 2252 | | state->m_smpc_ram = auto_alloc_array(machine, UINT8, 0x80); |
| 2253 | 2239 | state->m_scu_regs = auto_alloc_array(machine, UINT32, 0x100/4); |
| 2254 | 2240 | state->m_scsp_regs = auto_alloc_array(machine, UINT16, 0x1000/2); |
| 2255 | 2241 | state->m_cart_dram = auto_alloc_array(machine, UINT32, 0x400000/4); |
| 2256 | 2242 | state->m_backupram = auto_alloc_array(machine, UINT8, 0x10000); |
| 2257 | 2243 | state->m_cart_backupram = auto_alloc_array(machine, UINT8, 0x400000); |
| 2258 | | |
| 2259 | | state->m_smpc_ram[0x23] = dec_2_bcd(systime.local_time.year / 100); |
| 2260 | | state->m_smpc_ram[0x25] = dec_2_bcd(systime.local_time.year % 100); |
| 2261 | | state->m_smpc_ram[0x27] = (systime.local_time.weekday << 4) | (systime.local_time.month + 1); |
| 2262 | | state->m_smpc_ram[0x29] = dec_2_bcd(systime.local_time.mday); |
| 2263 | | state->m_smpc_ram[0x2b] = dec_2_bcd(systime.local_time.hour); |
| 2264 | | state->m_smpc_ram[0x2d] = dec_2_bcd(systime.local_time.minute); |
| 2265 | | state->m_smpc_ram[0x2f] = dec_2_bcd(systime.local_time.second); |
| 2266 | | state->m_smpc_ram[0x31] = 0x00; //CTG1=0 CTG0=0 (correct??) |
| 2267 | | // state->m_smpc_ram[0x33] = input_port_read(machine, "???"); |
| 2268 | | state->m_smpc_ram[0x5f] = 0x10; |
| 2269 | | |
| 2270 | | |
| 2271 | 2244 | } |
| 2272 | 2245 | |
| 2273 | 2246 | static DRIVER_INIT( saturnus ) |