trunk/src/emu/clifront.c
| r245617 | r245618 | |
| 153 | 153 | val.printf("%s:%s:%s", swlistdev->list_name(), m_options.software_name(), swpart->name()); |
| 154 | 154 | |
| 155 | 155 | // call this in order to set slot devices according to mounting |
| 156 | | m_options.parse_slot_devices(argc, argv, option_errors, image->instance_name(), val.cstr()); |
| 156 | m_options.parse_slot_devices(argc, argv, option_errors, image->instance_name(), val.c_str()); |
| 157 | 157 | break; |
| 158 | 158 | } |
| 159 | 159 | } |
| r245617 | r245618 | |
| 184 | 184 | throw emu_fatalerror(MAMERR_NO_SUCH_GAME, "Unknown system '%s'", m_options.system_name()); |
| 185 | 185 | |
| 186 | 186 | // otherwise, error on the options |
| 187 | | throw emu_fatalerror(MAMERR_INVALID_CONFIG, "%s", option_errors.trimspace().cstr()); |
| 187 | throw emu_fatalerror(MAMERR_INVALID_CONFIG, "%s", option_errors.trimspace().c_str()); |
| 188 | 188 | } |
| 189 | 189 | if (option_errors) |
| 190 | | osd_printf_error("Error in command line:\n%s\n", option_errors.trimspace().cstr()); |
| 190 | osd_printf_error("Error in command line:\n%s\n", option_errors.trimspace().c_str()); |
| 191 | 191 | |
| 192 | 192 | // determine the base name of the EXE |
| 193 | 193 | astring exename; |
| r245617 | r245618 | |
| 208 | 208 | m_options.parse_standard_inis(option_errors); |
| 209 | 209 | } |
| 210 | 210 | if (option_errors) |
| 211 | | osd_printf_error("Error in command line:\n%s\n", option_errors.trimspace().cstr()); |
| 211 | osd_printf_error("Error in command line:\n%s\n", option_errors.trimspace().c_str()); |
| 212 | 212 | |
| 213 | 213 | // if we can't find it, give an appropriate error |
| 214 | 214 | const game_driver *system = m_options.system(); |
| r245617 | r245618 | |
| 226 | 226 | catch (emu_fatalerror &fatal) |
| 227 | 227 | { |
| 228 | 228 | astring string(fatal.string()); |
| 229 | | osd_printf_error("%s\n", string.trimspace().cstr()); |
| 229 | osd_printf_error("%s\n", string.trimspace().c_str()); |
| 230 | 230 | m_result = (fatal.exitcode() != 0) ? fatal.exitcode() : MAMERR_FATALERROR; |
| 231 | 231 | |
| 232 | 232 | // if a game was specified, wasn't a wildcard, and our error indicates this was the |
| r245617 | r245618 | |
| 328 | 328 | // iterate through drivers and output the info |
| 329 | 329 | astring filename; |
| 330 | 330 | while (drivlist.next()) |
| 331 | | osd_printf_info("%-16s %s\n", drivlist.driver().name, core_filename_extract_base(filename, drivlist.driver().source_file).cstr()); |
| 331 | osd_printf_info("%-16s %s\n", drivlist.driver().name, core_filename_extract_base(filename, drivlist.driver().source_file).c_str()); |
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | |
| r245617 | r245618 | |
| 418 | 418 | while (drivlist.next()) |
| 419 | 419 | { |
| 420 | 420 | int clone_of = drivlist.clone(); |
| 421 | | osd_printf_info("%-16s %-16s %-16s\n", core_filename_extract_base(filename, drivlist.driver().source_file).cstr(), drivlist.driver().name, (clone_of == -1 ? "" : drivlist.driver(clone_of).name)); |
| 421 | osd_printf_info("%-16s %-16s %-16s\n", core_filename_extract_base(filename, drivlist.driver().source_file).c_str(), drivlist.driver().name, (clone_of == -1 ? "" : drivlist.driver(clone_of).name)); |
| 422 | 422 | } |
| 423 | 423 | } |
| 424 | 424 | |
| r245617 | r245618 | |
| 726 | 726 | paren_shortname.format("(%s)", imagedev->brief_instance_name()); |
| 727 | 727 | |
| 728 | 728 | // output the line, up to the list of extensions |
| 729 | | printf("%-13s%-12s%-8s ", first ? drivlist.driver().name : "", imagedev->instance_name(), paren_shortname.cstr()); |
| 729 | printf("%-13s%-12s%-8s ", first ? drivlist.driver().name : "", imagedev->instance_name(), paren_shortname.c_str()); |
| 730 | 730 | |
| 731 | 731 | // get the extensions and print them |
| 732 | 732 | astring extensions(imagedev->file_extensions()); |
| 733 | 733 | for (int start = 0, end = extensions.chr(0, ','); ; start = end + 1, end = extensions.chr(start, ',')) |
| 734 | 734 | { |
| 735 | 735 | astring curext(extensions, start, (end == -1) ? extensions.len() - start : end - start); |
| 736 | | printf(".%-5s", curext.cstr()); |
| 736 | printf(".%-5s", curext.c_str()); |
| 737 | 737 | if (end == -1) |
| 738 | 738 | break; |
| 739 | 739 | } |
| r245617 | r245618 | |
| 782 | 782 | // output the summary of the audit |
| 783 | 783 | astring summary_string; |
| 784 | 784 | auditor.summarize(drivlist.driver().name,&summary_string); |
| 785 | | osd_printf_info("%s", summary_string.cstr()); |
| 785 | osd_printf_info("%s", summary_string.c_str()); |
| 786 | 786 | |
| 787 | 787 | // output the name of the driver and its clone |
| 788 | 788 | osd_printf_info("romset %s ", drivlist.driver().name); |
| r245617 | r245618 | |
| 842 | 842 | // output the summary of the audit |
| 843 | 843 | astring summary_string; |
| 844 | 844 | auditor.summarize(dev->shortname(),&summary_string); |
| 845 | | osd_printf_info("%s", summary_string.cstr()); |
| 845 | osd_printf_info("%s", summary_string.c_str()); |
| 846 | 846 | |
| 847 | 847 | // display information about what we discovered |
| 848 | 848 | osd_printf_info("romset %s ", dev->shortname()); |
| r245617 | r245618 | |
| 880 | 880 | { |
| 881 | 881 | astring temptag("_"); |
| 882 | 882 | temptag.cat(option->name()); |
| 883 | | device_t *dev = const_cast<machine_config &>(config).device_add(&config.root_device(), temptag.cstr(), option->devtype(), 0); |
| 883 | device_t *dev = const_cast<machine_config &>(config).device_add(&config.root_device(), temptag.c_str(), option->devtype(), 0); |
| 884 | 884 | |
| 885 | 885 | // notify this device and all its subdevices that they are now configured |
| 886 | 886 | device_iterator subiter(*dev); |
| r245617 | r245618 | |
| 907 | 907 | // output the summary of the audit |
| 908 | 908 | astring summary_string; |
| 909 | 909 | auditor.summarize(dev->shortname(),&summary_string); |
| 910 | | osd_printf_info("%s", summary_string.cstr()); |
| 910 | osd_printf_info("%s", summary_string.c_str()); |
| 911 | 911 | |
| 912 | 912 | // display information about what we discovered |
| 913 | 913 | osd_printf_info("romset %s ", dev->shortname()); |
| r245617 | r245618 | |
| 938 | 938 | } |
| 939 | 939 | } |
| 940 | 940 | |
| 941 | | const_cast<machine_config &>(config).device_remove(&config.root_device(), temptag.cstr()); |
| 941 | const_cast<machine_config &>(config).device_remove(&config.root_device(), temptag.c_str()); |
| 942 | 942 | } |
| 943 | 943 | } |
| 944 | 944 | } |
| r245617 | r245618 | |
| 1004 | 1004 | // output the summary of the audit |
| 1005 | 1005 | astring summary_string; |
| 1006 | 1006 | auditor.summarize(drivlist.driver().name,&summary_string); |
| 1007 | | osd_printf_info("%s", summary_string.cstr()); |
| 1007 | osd_printf_info("%s", summary_string.c_str()); |
| 1008 | 1008 | |
| 1009 | 1009 | // output the name of the driver and its clone |
| 1010 | 1010 | osd_printf_info("sampleset %s ", drivlist.driver().name); |
| r245617 | r245618 | |
| 1322 | 1322 | // output the summary of the audit |
| 1323 | 1323 | astring summary_string; |
| 1324 | 1324 | auditor.summarize(swinfo->shortname(), &summary_string); |
| 1325 | | osd_printf_info("%s", summary_string.cstr()); |
| 1325 | osd_printf_info("%s", summary_string.c_str()); |
| 1326 | 1326 | |
| 1327 | 1327 | // display information about what we discovered |
| 1328 | 1328 | osd_printf_info("romset %s:%s ", swlistdev->list_name(), swinfo->shortname()); |
| r245617 | r245618 | |
| 1444 | 1444 | // output the summary of the audit |
| 1445 | 1445 | astring summary_string; |
| 1446 | 1446 | auditor.summarize(swinfo->shortname(), &summary_string); |
| 1447 | | osd_printf_info("%s", summary_string.cstr()); |
| 1447 | osd_printf_info("%s", summary_string.c_str()); |
| 1448 | 1448 | |
| 1449 | 1449 | // display information about what we discovered |
| 1450 | 1450 | osd_printf_info("romset %s:%s ", swlistdev->list_name(), swinfo->shortname()); |
| r245617 | r245618 | |
| 1556 | 1556 | astring option_errors; |
| 1557 | 1557 | m_options.parse_standard_inis(option_errors); |
| 1558 | 1558 | if (option_errors) |
| 1559 | | osd_printf_error("%s\n", option_errors.cstr()); |
| 1559 | osd_printf_error("%s\n", option_errors.c_str()); |
| 1560 | 1560 | |
| 1561 | 1561 | // createconfig? |
| 1562 | 1562 | if (strcmp(m_options.command(), CLICOMMAND_CREATECONFIG) == 0) |
| r245617 | r245618 | |
| 1779 | 1779 | { |
| 1780 | 1780 | // output the name |
| 1781 | 1781 | astring basename; |
| 1782 | | osd_printf_info("%-20s", core_filename_extract_base(basename, name).cstr()); |
| 1782 | osd_printf_info("%-20s", core_filename_extract_base(basename, name).c_str()); |
| 1783 | 1783 | m_total++; |
| 1784 | 1784 | |
| 1785 | 1785 | // attempt to open as a CHD; fail if not |
| r245617 | r245618 | |
| 1855 | 1855 | // output the name |
| 1856 | 1856 | m_total++; |
| 1857 | 1857 | astring basename; |
| 1858 | | osd_printf_info("%-20s", core_filename_extract_base(basename, name).cstr()); |
| 1858 | osd_printf_info("%-20s", core_filename_extract_base(basename, name).c_str()); |
| 1859 | 1859 | |
| 1860 | 1860 | // see if we can find a match in the ROMs |
| 1861 | 1861 | int found = find_by_hash(hashes, length); |
trunk/src/emu/cpu/dsp16/dsp16dis.c
| r245617 | r245618 | |
| 270 | 270 | const UINT8 F1 = (op & 0x01e0) >> 5; |
| 271 | 271 | astring yString = disasmYField(Y); |
| 272 | 272 | astring fString = disasmF1Field(F1, D, S); |
| 273 | | sprintf(buffer, "%s, %s", fString.cstr(), yString.cstr()); |
| 273 | sprintf(buffer, "%s, %s", fString.c_str(), yString.c_str()); |
| 274 | 274 | break; |
| 275 | 275 | } |
| 276 | 276 | case 0x04: case 0x1c: |
| r245617 | r245618 | |
| 285 | 285 | astring fString = disasmF1Field(F1, D, S); |
| 286 | 286 | astring aString = (opcode == 0x1c) ? "a0" : "a1"; |
| 287 | 287 | astring xString = (X) ? "" : "l"; |
| 288 | | sprintf(buffer, "%s = %s%s, %s", yString.cstr(), aString.cstr(), xString.cstr(), fString.cstr()); |
| 288 | sprintf(buffer, "%s = %s%s, %s", yString.c_str(), aString.c_str(), xString.c_str(), fString.c_str()); |
| 289 | 289 | break; |
| 290 | 290 | } |
| 291 | 291 | case 0x16: |
| r245617 | r245618 | |
| 297 | 297 | const UINT8 F1 = (op & 0x01e0) >> 5; |
| 298 | 298 | astring yString = disasmYField(Y); |
| 299 | 299 | astring fString = disasmF1Field(F1, D, S); |
| 300 | | sprintf(buffer, "%s, x = %s", fString.cstr(), yString.cstr()); |
| 300 | sprintf(buffer, "%s, x = %s", fString.c_str(), yString.c_str()); |
| 301 | 301 | break; |
| 302 | 302 | } |
| 303 | 303 | case 0x17: |
| r245617 | r245618 | |
| 311 | 311 | astring yString = disasmYField(Y); |
| 312 | 312 | astring fString = disasmF1Field(F1, D, S); |
| 313 | 313 | astring xString = (X ? "y" : "y1"); |
| 314 | | sprintf(buffer, "%s, %s = %s", fString.cstr(), xString.cstr(), yString.cstr()); |
| 314 | sprintf(buffer, "%s, %s = %s", fString.c_str(), xString.c_str(), yString.c_str()); |
| 315 | 315 | break; |
| 316 | 316 | } |
| 317 | 317 | case 0x1f: |
| r245617 | r245618 | |
| 325 | 325 | astring yString = disasmYField(Y); |
| 326 | 326 | astring fString = disasmF1Field(F1, D, S); |
| 327 | 327 | astring xString = (X ? "*pt++i" : "*pt++"); |
| 328 | | sprintf(buffer, "%s, y = %s, x = %s", fString.cstr(), yString.cstr(), xString.cstr()); |
| 328 | sprintf(buffer, "%s, y = %s, x = %s", fString.c_str(), yString.c_str(), xString.c_str()); |
| 329 | 329 | break; |
| 330 | 330 | } |
| 331 | 331 | case 0x19: case 0x1b: |
| r245617 | r245618 | |
| 339 | 339 | astring fString = disasmF1Field(F1, D, S); |
| 340 | 340 | astring xString = (X ? "*pt++i" : "*pt++"); |
| 341 | 341 | astring aString = (opcode == 0x19) ? "a0" : "a1"; |
| 342 | | sprintf(buffer, "%s, y = %s, x = %s", fString.cstr(), aString.cstr(), xString.cstr()); |
| 342 | sprintf(buffer, "%s, y = %s, x = %s", fString.c_str(), aString.c_str(), xString.c_str()); |
| 343 | 343 | if (Y != 0x00) sprintf(buffer, "UNKNOWN"); |
| 344 | 344 | break; |
| 345 | 345 | } |
| r245617 | r245618 | |
| 354 | 354 | astring yString = disasmYField(Y); |
| 355 | 355 | astring xString = (X ? "y" : "y1"); |
| 356 | 356 | astring fString = disasmF1Field(F1, D, S); |
| 357 | | sprintf(buffer, "%s, %s = %s", fString.cstr(), yString.cstr(), xString.cstr()); |
| 357 | sprintf(buffer, "%s, %s = %s", fString.c_str(), yString.c_str(), xString.c_str()); |
| 358 | 358 | break; |
| 359 | 359 | } |
| 360 | 360 | |
| r245617 | r245618 | |
| 369 | 369 | astring yString = disasmYField(Y); |
| 370 | 370 | astring atString = (aT ? "a0" : "a1"); |
| 371 | 371 | astring fString = disasmF1Field(F1, aT, S); |
| 372 | | sprintf(buffer, "%s, %s = %s", fString.cstr(), atString.cstr(), yString.cstr()); |
| 372 | sprintf(buffer, "%s, %s = %s", fString.c_str(), atString.c_str(), yString.c_str()); |
| 373 | 373 | break; |
| 374 | 374 | } |
| 375 | 375 | |
| r245617 | r245618 | |
| 385 | 385 | astring zString = disasmZField(Z); |
| 386 | 386 | astring xString = (X ? "y" : "y1"); |
| 387 | 387 | astring fString = disasmF1Field(F1, D, S); |
| 388 | | sprintf(buffer, "%s, %s <=> %s", fString.cstr(), xString.cstr(), zString.cstr()); |
| 388 | sprintf(buffer, "%s, %s <=> %s", fString.c_str(), xString.c_str(), zString.c_str()); |
| 389 | 389 | break; |
| 390 | 390 | } |
| 391 | 391 | case 0x1d: |
| r245617 | r245618 | |
| 399 | 399 | astring zString = disasmZField(Z); |
| 400 | 400 | astring xString = (X ? "*pt++i" : "*pt++"); |
| 401 | 401 | astring fString = disasmF1Field(F1, D, S); |
| 402 | | sprintf(buffer, "%s, %s <=> y, x = %s", fString.cstr(), zString.cstr(), xString.cstr()); |
| 402 | sprintf(buffer, "%s, %s <=> y, x = %s", fString.c_str(), zString.c_str(), xString.c_str()); |
| 403 | 403 | break; |
| 404 | 404 | } |
| 405 | 405 | |
| r245617 | r245618 | |
| 416 | 416 | astring atString = (aT ? "a0" : "a1"); |
| 417 | 417 | atString += X ? "" : "1"; // TODO: Figure out unclear wording. |
| 418 | 418 | astring fString = disasmF1Field(F1, aT, S); |
| 419 | | sprintf(buffer, "%s, %s <=> %s", fString.cstr(), zString.cstr(), atString.cstr()); |
| 419 | sprintf(buffer, "%s, %s <=> %s", fString.c_str(), zString.c_str(), atString.c_str()); |
| 420 | 420 | break; |
| 421 | 421 | } |
| 422 | 422 | |
| r245617 | r245618 | |
| 431 | 431 | const UINT8 F2 = (op & 0x01e0) >> 5; |
| 432 | 432 | astring fString = disasmF2Field(F2, D, S); |
| 433 | 433 | astring conString = disasmCONField(CON); |
| 434 | | if (op & 0x0800) sprintf(buffer, "if %s : %s", conString.cstr(), fString.cstr()); |
| 435 | | else sprintf(buffer, "ifc %s : %s", conString.cstr(), fString.cstr()); |
| 434 | if (op & 0x0800) sprintf(buffer, "if %s : %s", conString.c_str(), fString.c_str()); |
| 435 | else sprintf(buffer, "ifc %s : %s", conString.c_str(), fString.c_str()); |
| 436 | 436 | break; |
| 437 | 437 | } |
| 438 | 438 | |
| r245617 | r245618 | |
| 458 | 458 | // goto B |
| 459 | 459 | const UINT8 B = (op & 0x0700) >> 8; |
| 460 | 460 | astring bString = disasmBField(B); |
| 461 | | sprintf(buffer, "%s", bString.cstr()); |
| 461 | sprintf(buffer, "%s", bString.c_str()); |
| 462 | 462 | break; |
| 463 | 463 | } |
| 464 | 464 | |
| r245617 | r245618 | |
| 468 | 468 | // if CON [goto/call/return] |
| 469 | 469 | const UINT8 CON = (op & 0x001f); |
| 470 | 470 | astring conString = disasmCONField(CON); |
| 471 | | sprintf(buffer, "if %s:", conString.cstr()); |
| 471 | sprintf(buffer, "if %s:", conString.c_str()); |
| 472 | 472 | // TODO: Test for invalid ops |
| 473 | 473 | // icall |
| 474 | 474 | if (op == 0xd40e) sprintf(buffer, "icall"); |
| r245617 | r245618 | |
| 482 | 482 | const UINT8 R = (op & 0x03f0) >> 4; |
| 483 | 483 | const UINT8 S = (op & 0x1000) >> 12; |
| 484 | 484 | astring rString = disasmRField(R); |
| 485 | | sprintf(buffer, "%s = %s", rString.cstr(), (S ? "a1" : "a0")); |
| 485 | sprintf(buffer, "%s = %s", rString.c_str(), (S ? "a1" : "a0")); |
| 486 | 486 | break; |
| 487 | 487 | } |
| 488 | 488 | case 0x08: |
| r245617 | r245618 | |
| 491 | 491 | const UINT8 R = (op & 0x03f0) >> 4; |
| 492 | 492 | const UINT8 aT = (op & 0x0400) >> 10; |
| 493 | 493 | astring rString = disasmRField(R); |
| 494 | | sprintf(buffer, "%s = %s", (aT ? "a0" : "a1"), rString.cstr()); |
| 494 | sprintf(buffer, "%s = %s", (aT ? "a0" : "a1"), rString.c_str()); |
| 495 | 495 | break; |
| 496 | 496 | } |
| 497 | 497 | case 0x0f: |
| r245617 | r245618 | |
| 501 | 501 | const UINT8 R = (op & 0x03f0) >> 4; |
| 502 | 502 | astring yString = disasmYField(Y); |
| 503 | 503 | astring rString = disasmRField(R); |
| 504 | | sprintf(buffer, "%s = %s", rString.cstr(), yString.cstr()); |
| 504 | sprintf(buffer, "%s = %s", rString.c_str(), yString.c_str()); |
| 505 | 505 | // TODO: Special case the R == [y, y1, or x] case |
| 506 | 506 | break; |
| 507 | 507 | } |
| r245617 | r245618 | |
| 513 | 513 | astring yString = disasmYField(Y); |
| 514 | 514 | astring rString = disasmRField(R); |
| 515 | 515 | // TODO: page 3-31 "special function encoding" |
| 516 | | sprintf(buffer, "%s = %s", yString.cstr(), rString.cstr()); |
| 516 | sprintf(buffer, "%s = %s", yString.c_str(), rString.c_str()); |
| 517 | 517 | break; |
| 518 | 518 | } |
| 519 | 519 | case 0x0d: |
| r245617 | r245618 | |
| 523 | 523 | const UINT8 R = (op & 0x03f0) >> 4; |
| 524 | 524 | astring zString = disasmZField(Z); |
| 525 | 525 | astring rString = disasmRField(R); |
| 526 | | sprintf(buffer, "%s <=> %s", zString.cstr(), rString.cstr()); |
| 526 | sprintf(buffer, "%s <=> %s", zString.c_str(), rString.c_str()); |
| 527 | 527 | break; |
| 528 | 528 | } |
| 529 | 529 | |
| r245617 | r245618 | |
| 533 | 533 | // R = N |
| 534 | 534 | const UINT8 R = (op & 0x03f0) >> 4; |
| 535 | 535 | astring rString = disasmRField(R); |
| 536 | | sprintf(buffer, "%s = 0x%04x", rString.cstr(), op2); |
| 536 | sprintf(buffer, "%s = 0x%04x", rString.c_str(), op2); |
| 537 | 537 | opSize = 2; |
| 538 | 538 | break; |
| 539 | 539 | } |
| r245617 | r245618 | |
| 545 | 545 | const UINT16 M = (op & 0x01ff); |
| 546 | 546 | const UINT8 R = (op & 0x0e00) >> 9; |
| 547 | 547 | astring rString = disasmRImmediateField(R); |
| 548 | | sprintf(buffer, "%s = 0x%04x", rString.cstr(), M); |
| 548 | sprintf(buffer, "%s = 0x%04x", rString.c_str(), M); |
| 549 | 549 | break; |
| 550 | 550 | } |
| 551 | 551 | |
trunk/src/emu/cpu/mcs96/mcs96.c
| r245617 | r245618 | |
| 253 | 253 | int delta = oprom[2]; |
| 254 | 254 | if(delta & 0x80) |
| 255 | 255 | delta -= 0x100; |
| 256 | | sprintf(buffer, " %s, %04x", regname(oprom[1]).cstr(), (pc+3+delta) & 0xffff); |
| 256 | sprintf(buffer, " %s, %04x", regname(oprom[1]).c_str(), (pc+3+delta) & 0xffff); |
| 257 | 257 | flags |= 3; |
| 258 | 258 | break; |
| 259 | 259 | } |
| r245617 | r245618 | |
| 262 | 262 | int delta = oprom[2]; |
| 263 | 263 | if(delta & 0x80) |
| 264 | 264 | delta -= 0x100; |
| 265 | | sprintf(buffer, " %d, %s, %04x", oprom[0] & 7, regname(oprom[1]).cstr(), (pc+3+delta) & 0xffff); |
| 265 | sprintf(buffer, " %d, %s, %04x", oprom[0] & 7, regname(oprom[1]).c_str(), (pc+3+delta) & 0xffff); |
| 266 | 266 | flags |= 3; |
| 267 | 267 | break; |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | case DASM_direct_1: |
| 271 | | sprintf(buffer, " %s", regname(oprom[1]).cstr()); |
| 271 | sprintf(buffer, " %s", regname(oprom[1]).c_str()); |
| 272 | 272 | flags |= 2; |
| 273 | 273 | break; |
| 274 | 274 | |
| 275 | 275 | case DASM_direct_2: |
| 276 | | sprintf(buffer, " %s, %s", regname(oprom[2]).cstr(), regname(oprom[1]).cstr()); |
| 276 | sprintf(buffer, " %s, %s", regname(oprom[2]).c_str(), regname(oprom[1]).c_str()); |
| 277 | 277 | flags |= 3; |
| 278 | 278 | break; |
| 279 | 279 | |
| 280 | 280 | case DASM_direct_3: |
| 281 | | sprintf(buffer, " %s, %s, %s", regname(oprom[3]).cstr(), regname(oprom[2]).cstr(), regname(oprom[1]).cstr()); |
| 281 | sprintf(buffer, " %s, %s, %s", regname(oprom[3]).c_str(), regname(oprom[2]).c_str(), regname(oprom[1]).c_str()); |
| 282 | 282 | flags |= 4; |
| 283 | 283 | break; |
| 284 | 284 | |
| r245617 | r245618 | |
| 288 | 288 | break; |
| 289 | 289 | |
| 290 | 290 | case DASM_immed_2b: |
| 291 | | sprintf(buffer, " %s, #%02x", regname(oprom[2]).cstr(), oprom[1]); |
| 291 | sprintf(buffer, " %s, #%02x", regname(oprom[2]).c_str(), oprom[1]); |
| 292 | 292 | flags |= 3; |
| 293 | 293 | break; |
| 294 | 294 | |
| 295 | 295 | case DASM_immed_or_reg_2b: |
| 296 | 296 | if(oprom[1] >= 0x10) |
| 297 | | sprintf(buffer, " %s, %s", regname(oprom[2]).cstr(), regname(oprom[1]).cstr()); |
| 297 | sprintf(buffer, " %s, %s", regname(oprom[2]).c_str(), regname(oprom[1]).c_str()); |
| 298 | 298 | else |
| 299 | | sprintf(buffer, " %s, #%02x", regname(oprom[2]).cstr(), oprom[1]); |
| 299 | sprintf(buffer, " %s, #%02x", regname(oprom[2]).c_str(), oprom[1]); |
| 300 | 300 | flags |= 3; |
| 301 | 301 | break; |
| 302 | 302 | |
| 303 | 303 | case DASM_immed_3b: |
| 304 | | sprintf(buffer, " %s, %s, #%02x", regname(oprom[3]).cstr(), regname(oprom[2]).cstr(), oprom[1]); |
| 304 | sprintf(buffer, " %s, %s, #%02x", regname(oprom[3]).c_str(), regname(oprom[2]).c_str(), oprom[1]); |
| 305 | 305 | flags |= 4; |
| 306 | 306 | break; |
| 307 | 307 | |
| r245617 | r245618 | |
| 311 | 311 | break; |
| 312 | 312 | |
| 313 | 313 | case DASM_immed_2w: |
| 314 | | sprintf(buffer, " %s, #%02x%02x", regname(oprom[3]).cstr(), oprom[2], oprom[1]); |
| 314 | sprintf(buffer, " %s, #%02x%02x", regname(oprom[3]).c_str(), oprom[2], oprom[1]); |
| 315 | 315 | flags |= 4; |
| 316 | 316 | break; |
| 317 | 317 | |
| 318 | 318 | case DASM_immed_3w: |
| 319 | | sprintf(buffer, " %s, %s, #%02x%02x", regname(oprom[4]).cstr(), regname(oprom[3]).cstr(), oprom[2], oprom[1]); |
| 319 | sprintf(buffer, " %s, %s, #%02x%02x", regname(oprom[4]).c_str(), regname(oprom[3]).c_str(), oprom[2], oprom[1]); |
| 320 | 320 | flags |= 5; |
| 321 | 321 | break; |
| 322 | 322 | |
| 323 | 323 | case DASM_indirect_1n: |
| 324 | | sprintf(buffer, " [%s]", regname(oprom[1]).cstr()); |
| 324 | sprintf(buffer, " [%s]", regname(oprom[1]).c_str()); |
| 325 | 325 | flags |= 2; |
| 326 | 326 | break; |
| 327 | 327 | |
| 328 | 328 | case DASM_indirect_1: |
| 329 | 329 | if(oprom[1] & 0x01) { |
| 330 | | sprintf(buffer, " [%s]+", regname(oprom[1]-1).cstr()); |
| 330 | sprintf(buffer, " [%s]+", regname(oprom[1]-1).c_str()); |
| 331 | 331 | flags |= 2; |
| 332 | 332 | } else { |
| 333 | | sprintf(buffer, " [%s]", regname(oprom[1]).cstr()); |
| 333 | sprintf(buffer, " [%s]", regname(oprom[1]).c_str()); |
| 334 | 334 | flags |= 2; |
| 335 | 335 | } |
| 336 | 336 | break; |
| 337 | 337 | |
| 338 | 338 | case DASM_indirect_2: |
| 339 | 339 | if(oprom[1] & 0x01) { |
| 340 | | sprintf(buffer, " %s, [%s]+", regname(oprom[2]).cstr(), regname(oprom[1]-1).cstr()); |
| 340 | sprintf(buffer, " %s, [%s]+", regname(oprom[2]).c_str(), regname(oprom[1]-1).c_str()); |
| 341 | 341 | flags |= 3; |
| 342 | 342 | } else { |
| 343 | | sprintf(buffer, " %s, [%s]", regname(oprom[2]).cstr(), regname(oprom[1]).cstr()); |
| 343 | sprintf(buffer, " %s, [%s]", regname(oprom[2]).c_str(), regname(oprom[1]).c_str()); |
| 344 | 344 | flags |= 3; |
| 345 | 345 | } |
| 346 | 346 | break; |
| 347 | 347 | |
| 348 | 348 | case DASM_indirect_3: |
| 349 | 349 | if(oprom[1] & 0x01) { |
| 350 | | sprintf(buffer, " %s, %s, [%s]+", regname(oprom[3]).cstr(), regname(oprom[2]).cstr(), regname(oprom[1]-1).cstr()); |
| 350 | sprintf(buffer, " %s, %s, [%s]+", regname(oprom[3]).c_str(), regname(oprom[2]).c_str(), regname(oprom[1]-1).c_str()); |
| 351 | 351 | flags |= 4; |
| 352 | 352 | } else { |
| 353 | | sprintf(buffer, " %s, %s, [%s]", regname(oprom[3]).cstr(), regname(oprom[2]).cstr(), regname(oprom[1]).cstr()); |
| 353 | sprintf(buffer, " %s, %s, [%s]", regname(oprom[3]).c_str(), regname(oprom[2]).c_str(), regname(oprom[1]).c_str()); |
| 354 | 354 | flags |= 4; |
| 355 | 355 | } |
| 356 | 356 | break; |
| r245617 | r245618 | |
| 360 | 360 | if(oprom[1] == 0x01) |
| 361 | 361 | sprintf(buffer, " %02x%02x", oprom[3], oprom[2]); |
| 362 | 362 | else |
| 363 | | sprintf(buffer, " %02x%02x[%s]", oprom[3], oprom[2], regname(oprom[1]-1).cstr()); |
| 363 | sprintf(buffer, " %02x%02x[%s]", oprom[3], oprom[2], regname(oprom[1]-1).c_str()); |
| 364 | 364 | flags |= 4; |
| 365 | 365 | } else { |
| 366 | 366 | int delta = oprom[2]; |
| r245617 | r245618 | |
| 373 | 373 | sprintf(buffer, " %02x", delta); |
| 374 | 374 | } else { |
| 375 | 375 | if(delta < 0) |
| 376 | | sprintf(buffer, " -%02x[%s]", -delta, regname(oprom[1]).cstr()); |
| 376 | sprintf(buffer, " -%02x[%s]", -delta, regname(oprom[1]).c_str()); |
| 377 | 377 | else |
| 378 | | sprintf(buffer, " %02x[%s]", delta, regname(oprom[1]).cstr()); |
| 378 | sprintf(buffer, " %02x[%s]", delta, regname(oprom[1]).c_str()); |
| 379 | 379 | } |
| 380 | 380 | flags |= 3; |
| 381 | 381 | } |
| r245617 | r245618 | |
| 384 | 384 | case DASM_indexed_2: |
| 385 | 385 | if(oprom[1] & 0x01) { |
| 386 | 386 | if(oprom[1] == 0x01) |
| 387 | | sprintf(buffer, " %s, %02x%02x", regname(oprom[4]).cstr(), oprom[3], oprom[2]); |
| 387 | sprintf(buffer, " %s, %02x%02x", regname(oprom[4]).c_str(), oprom[3], oprom[2]); |
| 388 | 388 | else |
| 389 | | sprintf(buffer, " %s, %02x%02x[%s]", regname(oprom[4]).cstr(), oprom[3], oprom[2], regname(oprom[1]-1).cstr()); |
| 389 | sprintf(buffer, " %s, %02x%02x[%s]", regname(oprom[4]).c_str(), oprom[3], oprom[2], regname(oprom[1]-1).c_str()); |
| 390 | 390 | flags |= 5; |
| 391 | 391 | } else { |
| 392 | 392 | int delta = oprom[2]; |
| r245617 | r245618 | |
| 394 | 394 | delta -= 0x100; |
| 395 | 395 | if(oprom[1] == 0x00) { |
| 396 | 396 | if(delta < 0) |
| 397 | | sprintf(buffer, " %s, %04x", regname(oprom[3]).cstr(), delta & 0xffff); |
| 397 | sprintf(buffer, " %s, %04x", regname(oprom[3]).c_str(), delta & 0xffff); |
| 398 | 398 | else |
| 399 | | sprintf(buffer, " %s, %02x", regname(oprom[3]).cstr(), delta); |
| 399 | sprintf(buffer, " %s, %02x", regname(oprom[3]).c_str(), delta); |
| 400 | 400 | } else { |
| 401 | 401 | if(delta < 0) |
| 402 | | sprintf(buffer, " %s, -%02x[%s]", regname(oprom[3]).cstr(), -delta, regname(oprom[1]).cstr()); |
| 402 | sprintf(buffer, " %s, -%02x[%s]", regname(oprom[3]).c_str(), -delta, regname(oprom[1]).c_str()); |
| 403 | 403 | else |
| 404 | | sprintf(buffer, " %s, %02x[%s]", regname(oprom[3]).cstr(), delta, regname(oprom[1]).cstr()); |
| 404 | sprintf(buffer, " %s, %02x[%s]", regname(oprom[3]).c_str(), delta, regname(oprom[1]).c_str()); |
| 405 | 405 | } |
| 406 | 406 | flags |= 4; |
| 407 | 407 | } |
| r245617 | r245618 | |
| 410 | 410 | case DASM_indexed_3: |
| 411 | 411 | if(oprom[1] & 0x01) { |
| 412 | 412 | if(oprom[1] == 0x01) |
| 413 | | sprintf(buffer, " %s, %s, %02x%02x", regname(oprom[5]).cstr(), regname(oprom[4]).cstr(), oprom[3], oprom[2]); |
| 413 | sprintf(buffer, " %s, %s, %02x%02x", regname(oprom[5]).c_str(), regname(oprom[4]).c_str(), oprom[3], oprom[2]); |
| 414 | 414 | else |
| 415 | | sprintf(buffer, " %s, %s, %02x%02x[%s]", regname(oprom[5]).cstr(), regname(oprom[4]).cstr(), oprom[3], oprom[2], regname(oprom[1]-1).cstr()); |
| 415 | sprintf(buffer, " %s, %s, %02x%02x[%s]", regname(oprom[5]).c_str(), regname(oprom[4]).c_str(), oprom[3], oprom[2], regname(oprom[1]-1).c_str()); |
| 416 | 416 | flags |= 6; |
| 417 | 417 | } else { |
| 418 | 418 | int delta = oprom[2]; |
| r245617 | r245618 | |
| 420 | 420 | delta -= 0x100; |
| 421 | 421 | if(oprom[1] == 0x00) { |
| 422 | 422 | if(delta < 0) |
| 423 | | sprintf(buffer, " %s, %s, %04x", regname(oprom[4]).cstr(), regname(oprom[3]).cstr(), delta & 0xffff); |
| 423 | sprintf(buffer, " %s, %s, %04x", regname(oprom[4]).c_str(), regname(oprom[3]).c_str(), delta & 0xffff); |
| 424 | 424 | else |
| 425 | | sprintf(buffer, " %s, %s, %02x", regname(oprom[4]).cstr(), regname(oprom[3]).cstr(), delta); |
| 425 | sprintf(buffer, " %s, %s, %02x", regname(oprom[4]).c_str(), regname(oprom[3]).c_str(), delta); |
| 426 | 426 | } else { |
| 427 | 427 | if(delta < 0) |
| 428 | | sprintf(buffer, " %s, %s, -%02x[%s]", regname(oprom[4]).cstr(), regname(oprom[3]).cstr(), -delta, regname(oprom[1]).cstr()); |
| 428 | sprintf(buffer, " %s, %s, -%02x[%s]", regname(oprom[4]).c_str(), regname(oprom[3]).c_str(), -delta, regname(oprom[1]).c_str()); |
| 429 | 429 | else |
| 430 | | sprintf(buffer, " %s, %s, %02x[%s]", regname(oprom[4]).cstr(), regname(oprom[3]).cstr(), delta, regname(oprom[1]).cstr()); |
| 430 | sprintf(buffer, " %s, %s, %02x[%s]", regname(oprom[4]).c_str(), regname(oprom[3]).c_str(), delta, regname(oprom[1]).c_str()); |
| 431 | 431 | } |
| 432 | 432 | flags |= 5; |
| 433 | 433 | } |
trunk/src/emu/debug/debugcpu.c
| r245617 | r245618 | |
| 1994 | 1994 | { |
| 1995 | 1995 | if (m_track_mem) |
| 1996 | 1996 | { |
| 1997 | | dasm_memory_access const newAccess(space.spacenum(), address, data, history_pc(0)); |
| 1998 | | std::pair<std::set<dasm_memory_access>::iterator, bool> trackedAccess = m_track_mem_set.insert(newAccess); |
| 1999 | | if (!trackedAccess.second) |
| 2000 | | trackedAccess.first->m_pc = newAccess.m_pc; |
| 1997 | dasm_memory_access newAccess(space.spacenum(), address, data, history_pc(0)); |
| 1998 | dasm_memory_access* trackedAccess = m_track_mem_set.find(newAccess); |
| 1999 | if (trackedAccess) |
| 2000 | trackedAccess->m_pc = newAccess.m_pc; |
| 2001 | else |
| 2002 | m_track_mem_set.insert(newAccess); |
| 2001 | 2003 | } |
| 2002 | 2004 | watchpoint_check(space, WATCHPOINT_WRITE, address, data, mem_mask); |
| 2003 | 2005 | } |
| r245617 | r245618 | |
| 2039 | 2041 | // make sure we get good results |
| 2040 | 2042 | assert((result & DASMFLAG_LENGTHMASK) != 0); |
| 2041 | 2043 | #ifdef MAME_DEBUG |
| 2042 | | if (m_memory != NULL && m_disasm != NULL) |
| 2043 | | { |
| 2044 | | address_space &space = m_memory->space(AS_PROGRAM); |
| 2045 | | int bytes = space.address_to_byte(result & DASMFLAG_LENGTHMASK); |
| 2046 | | assert(bytes >= m_disasm->min_opcode_bytes()); |
| 2047 | | assert(bytes <= m_disasm->max_opcode_bytes()); |
| 2048 | | (void) bytes; // appease compiler |
| 2049 | | } |
| 2044 | if (m_memory != NULL && m_disasm != NULL) |
| 2045 | { |
| 2046 | address_space &space = m_memory->space(AS_PROGRAM); |
| 2047 | int bytes = space.address_to_byte(result & DASMFLAG_LENGTHMASK); |
| 2048 | assert(bytes >= m_disasm->min_opcode_bytes()); |
| 2049 | assert(bytes <= m_disasm->max_opcode_bytes()); |
| 2050 | (void) bytes; // appease compiler |
| 2051 | } |
| 2050 | 2052 | #endif |
| 2051 | 2053 | |
| 2052 | 2054 | return result; |
| r245617 | r245618 | |
| 2587 | 2589 | if (m_track_pc_set.empty()) |
| 2588 | 2590 | return false; |
| 2589 | 2591 | const UINT32 crc = compute_opcode_crc32(pc); |
| 2590 | | return m_track_pc_set.find(dasm_pc_tag(pc, crc)) != m_track_pc_set.end(); |
| 2592 | return m_track_pc_set.contains(dasm_pc_tag(pc, crc)); |
| 2591 | 2593 | } |
| 2592 | 2594 | |
| 2593 | 2595 | |
| r245617 | r245618 | |
| 2616 | 2618 | const offs_t missing = (offs_t)(-1); |
| 2617 | 2619 | if (m_track_mem_set.empty()) |
| 2618 | 2620 | return missing; |
| 2619 | | std::set<dasm_memory_access>::iterator const mem_access = m_track_mem_set.find(dasm_memory_access(space, address, data, 0)); |
| 2620 | | if (mem_access == m_track_mem_set.end()) return missing; |
| 2621 | dasm_memory_access* mem_access = m_track_mem_set.find(dasm_memory_access(space, address, data, 0)); |
| 2622 | if (mem_access == NULL) return missing; |
| 2621 | 2623 | return mem_access->m_pc; |
| 2622 | 2624 | } |
| 2623 | 2625 | |
| r245617 | r245618 | |
| 2630 | 2632 | void device_debug::comment_add(offs_t addr, const char *comment, rgb_t color) |
| 2631 | 2633 | { |
| 2632 | 2634 | // create a new item for the list |
| 2633 | | UINT32 const crc = compute_opcode_crc32(addr); |
| 2634 | | dasm_comment const newComment = dasm_comment(addr, crc, comment, color); |
| 2635 | | std::pair<std::set<dasm_comment>::iterator, bool> const inserted = m_comment_set.insert(newComment); |
| 2636 | | if (!inserted.second) |
| 2635 | const UINT32 crc = compute_opcode_crc32(addr); |
| 2636 | dasm_comment newComment = dasm_comment(addr, crc, comment, color); |
| 2637 | if (!m_comment_set.insert(newComment)) |
| 2637 | 2638 | { |
| 2638 | 2639 | // Insert returns false if comment exists |
| 2639 | | m_comment_set.erase(inserted.first); |
| 2640 | m_comment_set.remove(newComment); |
| 2640 | 2641 | m_comment_set.insert(newComment); |
| 2641 | 2642 | } |
| 2642 | 2643 | |
| r245617 | r245618 | |
| 2653 | 2654 | bool device_debug::comment_remove(offs_t addr) |
| 2654 | 2655 | { |
| 2655 | 2656 | const UINT32 crc = compute_opcode_crc32(addr); |
| 2656 | | size_t const removed = m_comment_set.erase(dasm_comment(addr, crc, "", 0xffffffff)); |
| 2657 | | if (removed != 0U) m_comment_change++; |
| 2658 | | return removed != 0U; |
| 2657 | bool success = m_comment_set.remove(dasm_comment(addr, crc, "", 0xffffffff)); |
| 2658 | if (success) m_comment_change++; |
| 2659 | return success; |
| 2659 | 2660 | } |
| 2660 | 2661 | |
| 2661 | 2662 | |
| r245617 | r245618 | |
| 2666 | 2667 | const char *device_debug::comment_text(offs_t addr) const |
| 2667 | 2668 | { |
| 2668 | 2669 | const UINT32 crc = compute_opcode_crc32(addr); |
| 2669 | | std::set<dasm_comment>::iterator comment = m_comment_set.find(dasm_comment(addr, crc, "", 0)); |
| 2670 | | if (comment == m_comment_set.end()) return NULL; |
| 2670 | dasm_comment* comment = m_comment_set.find(dasm_comment(addr, crc, "", 0)); |
| 2671 | if (comment == NULL) return NULL; |
| 2671 | 2672 | return comment->m_text; |
| 2672 | 2673 | } |
| 2673 | 2674 | |
| r245617 | r245618 | |
| 2681 | 2682 | { |
| 2682 | 2683 | // iterate through the comments |
| 2683 | 2684 | astring crc_buf; |
| 2684 | | for (std::set<dasm_comment>::iterator item = m_comment_set.begin(); item != m_comment_set.end(); ++item) |
| 2685 | simple_set_iterator<dasm_comment> iter(m_comment_set); |
| 2686 | for (dasm_comment* item = iter.first(); item != iter.last(); item = iter.next()) |
| 2685 | 2687 | { |
| 2686 | 2688 | xml_data_node *datanode = xml_add_child(&curnode, "comment", xml_normalize_string(item->m_text)); |
| 2687 | 2689 | if (datanode == NULL) |
| r245617 | r245618 | |
| 3059 | 3061 | } |
| 3060 | 3062 | else |
| 3061 | 3063 | buffer.printf("Stopped at watchpoint %X reading %s from %08X (PC=%X)", wp->m_index, sizes[size], space.byte_to_address(address), pc); |
| 3062 | | debug_console_printf(space.machine(), "%s\n", buffer.cstr()); |
| 3064 | debug_console_printf(space.machine(), "%s\n", buffer.c_str()); |
| 3063 | 3065 | space.device().debug()->compute_debug_flags(); |
| 3064 | 3066 | } |
| 3065 | 3067 | break; |
| r245617 | r245618 | |
| 3493 | 3495 | buffer.cat(dasm); |
| 3494 | 3496 | |
| 3495 | 3497 | // output the result |
| 3496 | | fprintf(&m_file, "%s\n", buffer.cstr()); |
| 3498 | fprintf(&m_file, "%s\n", buffer.c_str()); |
| 3497 | 3499 | |
| 3498 | 3500 | // do we need to step the trace over this instruction? |
| 3499 | 3501 | if (m_trace_over && (dasmresult & DASMFLAG_SUPPORTED) != 0 && (dasmresult & DASMFLAG_STEP_OVER) != 0) |
trunk/src/emu/machine/hdc9234.c
| r245617 | r245618 | |
| 572 | 572 | |
| 573 | 573 | void hdc9234_device::wait_time(emu_timer *tm, const attotime &delay, int param) |
| 574 | 574 | { |
| 575 | | if (TRACE_DELAY) logerror("%s: [%s] Delaying by %4.2f microsecs\n", tag(), ttsn().cstr(), delay.as_double()*1000000); |
| 575 | if (TRACE_DELAY) logerror("%s: [%s] Delaying by %4.2f microsecs\n", tag(), ttsn().c_str(), delay.as_double()*1000000); |
| 576 | 576 | tm->adjust(delay); |
| 577 | 577 | m_substate = param; |
| 578 | 578 | } |
| r245617 | r245618 | |
| 1784 | 1784 | */ |
| 1785 | 1785 | void hdc9234_device::live_start(int state) |
| 1786 | 1786 | { |
| 1787 | | if (TRACE_LIVE) logerror("%s: [%s] Live start substate=%d\n", tag(), ttsn().cstr(), state); |
| 1787 | if (TRACE_LIVE) logerror("%s: [%s] Live start substate=%d\n", tag(), ttsn().c_str(), state); |
| 1788 | 1788 | m_live_state.time = machine().time(); |
| 1789 | 1789 | m_live_state.state = state; |
| 1790 | 1790 | m_live_state.next_state = -1; |
| r245617 | r245618 | |
| 1828 | 1828 | if (TRACE_LIVE) |
| 1829 | 1829 | { |
| 1830 | 1830 | if (limit == attotime::never) |
| 1831 | | logerror("%s: [%s] live_run, live_state=%d, mode=%s\n", tag(), tts(m_live_state.time).cstr(), m_live_state.state, fm_mode()? "FM":"MFM"); |
| 1831 | logerror("%s: [%s] live_run, live_state=%d, mode=%s\n", tag(), tts(m_live_state.time).c_str(), m_live_state.state, fm_mode()? "FM":"MFM"); |
| 1832 | 1832 | else |
| 1833 | | logerror("%s: [%s] live_run until %s, live_state=%d, mode=%s\n", tag(), tts(m_live_state.time).cstr(), tts(limit).cstr(), m_live_state.state, fm_mode()? "FM":"MFM"); |
| 1833 | logerror("%s: [%s] live_run until %s, live_state=%d, mode=%s\n", tag(), tts(m_live_state.time).c_str(), tts(limit).c_str(), m_live_state.state, fm_mode()? "FM":"MFM"); |
| 1834 | 1834 | } |
| 1835 | 1835 | |
| 1836 | 1836 | if (limit == attotime::never) |
| r245617 | r245618 | |
| 1862 | 1862 | |
| 1863 | 1863 | if (TRACE_LIVE && m_last_live_state != SEARCH_IDAM) |
| 1864 | 1864 | { |
| 1865 | | logerror("%s: [%s] SEARCH_IDAM [limit %s]\n", tag(),tts(m_live_state.time).cstr(), tts(limit).cstr()); |
| 1865 | logerror("%s: [%s] SEARCH_IDAM [limit %s]\n", tag(),tts(m_live_state.time).c_str(), tts(limit).c_str()); |
| 1866 | 1866 | m_last_live_state = m_live_state.state; |
| 1867 | 1867 | } |
| 1868 | 1868 | |
| r245617 | r245618 | |
| 1871 | 1871 | |
| 1872 | 1872 | if (read_one_bit(limit)) |
| 1873 | 1873 | { |
| 1874 | | if (TRACE_LIVE) logerror("%s: [%s] SEARCH_IDAM limit reached\n", tag(), tts(m_live_state.time).cstr()); |
| 1874 | if (TRACE_LIVE) logerror("%s: [%s] SEARCH_IDAM limit reached\n", tag(), tts(m_live_state.time).c_str()); |
| 1875 | 1875 | return; |
| 1876 | 1876 | } |
| 1877 | | // logerror("%s: SEARCH_IDAM\n", tts(m_live_state.time).cstr()); |
| 1878 | | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(m_live_state.time).cstr(), m_live_state.shift_reg, |
| 1877 | // logerror("%s: SEARCH_IDAM\n", tts(m_live_state.time).c_str()); |
| 1878 | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(m_live_state.time).c_str(), m_live_state.shift_reg, |
| 1879 | 1879 | get_data_from_encoding(m_live_state.shift_reg), m_live_state.bit_counter); |
| 1880 | 1880 | |
| 1881 | 1881 | // [1] p. 9: The ID field sync mark must be found within 33,792 byte times |
| r245617 | r245618 | |
| 1890 | 1890 | // MFM case |
| 1891 | 1891 | if (m_live_state.shift_reg == 0x4489) |
| 1892 | 1892 | { |
| 1893 | | if (TRACE_LIVE) logerror("%s: [%s] Found an A1 mark\n", tag(),tts(m_live_state.time).cstr()); |
| 1893 | if (TRACE_LIVE) logerror("%s: [%s] Found an A1 mark\n", tag(),tts(m_live_state.time).c_str()); |
| 1894 | 1894 | m_live_state.crc = 0x443b; |
| 1895 | 1895 | m_live_state.data_separator_phase = false; |
| 1896 | 1896 | m_live_state.bit_counter = 0; |
| r245617 | r245618 | |
| 1921 | 1921 | |
| 1922 | 1922 | if (TRACE_LIVE && m_last_live_state != READ_TWO_MORE_A1_IDAM) |
| 1923 | 1923 | { |
| 1924 | | logerror("%s: [%s] READ_TWO_MORE_A1\n", tag(),tts(m_live_state.time).cstr()); |
| 1924 | logerror("%s: [%s] READ_TWO_MORE_A1\n", tag(),tts(m_live_state.time).c_str()); |
| 1925 | 1925 | m_last_live_state = m_live_state.state; |
| 1926 | 1926 | } |
| 1927 | 1927 | |
| 1928 | 1928 | // Beyond time limit? |
| 1929 | 1929 | if (read_one_bit(limit)) return; |
| 1930 | 1930 | |
| 1931 | | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(m_live_state.time).cstr(), m_live_state.shift_reg, |
| 1931 | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(m_live_state.time).c_str(), m_live_state.shift_reg, |
| 1932 | 1932 | get_data_from_encoding(m_live_state.shift_reg), m_live_state.bit_counter); |
| 1933 | 1933 | |
| 1934 | 1934 | if (m_live_state.bit_count_total > 33792*16) |
| r245617 | r245618 | |
| 1950 | 1950 | m_live_state.state = SEARCH_IDAM; |
| 1951 | 1951 | } |
| 1952 | 1952 | else |
| 1953 | | if (TRACE_LIVE) logerror("%s: [%s] Found an A1 mark\n", tag(),tts(m_live_state.time).cstr()); |
| 1953 | if (TRACE_LIVE) logerror("%s: [%s] Found an A1 mark\n", tag(),tts(m_live_state.time).c_str()); |
| 1954 | 1954 | // Continue |
| 1955 | 1955 | break; |
| 1956 | 1956 | } |
| 1957 | 1957 | |
| 1958 | | if (TRACE_LIVE) logerror("%s: [%s] Found data value %02X\n", tag(),tts(m_live_state.time).cstr(), m_live_state.data_reg); |
| 1958 | if (TRACE_LIVE) logerror("%s: [%s] Found data value %02X\n", tag(),tts(m_live_state.time).c_str(), m_live_state.data_reg); |
| 1959 | 1959 | |
| 1960 | 1960 | // Check for ident field (fe, ff, fd, fc) |
| 1961 | 1961 | if ((m_live_state.data_reg & 0xfc) != 0xfc) |
| r245617 | r245618 | |
| 1976 | 1976 | case READ_ID_FIELDS_INTO_REGS: |
| 1977 | 1977 | if (TRACE_LIVE && m_last_live_state != READ_ID_FIELDS_INTO_REGS) |
| 1978 | 1978 | { |
| 1979 | | logerror("%s: [%s] READ_ID_FIELDS_INTO_REGS\n", tag(),tts(m_live_state.time).cstr()); |
| 1979 | logerror("%s: [%s] READ_ID_FIELDS_INTO_REGS\n", tag(),tts(m_live_state.time).c_str()); |
| 1980 | 1980 | m_last_live_state = m_live_state.state; |
| 1981 | 1981 | } |
| 1982 | 1982 | |
| r245617 | r245618 | |
| 2017 | 2017 | case SEARCH_DAM: |
| 2018 | 2018 | if (TRACE_LIVE && m_last_live_state != SEARCH_DAM) |
| 2019 | 2019 | { |
| 2020 | | logerror("%s: [%s] SEARCH_DAM\n", tag(),tts(m_live_state.time).cstr()); |
| 2020 | logerror("%s: [%s] SEARCH_DAM\n", tag(),tts(m_live_state.time).c_str()); |
| 2021 | 2021 | m_last_live_state = m_live_state.state; |
| 2022 | 2022 | } |
| 2023 | 2023 | |
| r245617 | r245618 | |
| 2026 | 2026 | if(read_one_bit(limit)) |
| 2027 | 2027 | return; |
| 2028 | 2028 | |
| 2029 | | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(m_live_state.time).cstr(), m_live_state.shift_reg, |
| 2029 | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(m_live_state.time).c_str(), m_live_state.shift_reg, |
| 2030 | 2030 | get_data_from_encoding(m_live_state.shift_reg), m_live_state.bit_counter); |
| 2031 | 2031 | |
| 2032 | 2032 | if (!fm_mode()) |
| r245617 | r245618 | |
| 2040 | 2040 | |
| 2041 | 2041 | if (m_live_state.bit_counter >= 28*16 && m_live_state.shift_reg == 0x4489) |
| 2042 | 2042 | { |
| 2043 | | if (TRACE_LIVE) logerror("%s: [%s] Found an A1 mark\n", tag(),tts(m_live_state.time).cstr()); |
| 2043 | if (TRACE_LIVE) logerror("%s: [%s] Found an A1 mark\n", tag(),tts(m_live_state.time).c_str()); |
| 2044 | 2044 | m_live_state.crc = 0x443b; |
| 2045 | 2045 | m_live_state.data_separator_phase = false; |
| 2046 | 2046 | m_live_state.bit_counter = 0; |
| r245617 | r245618 | |
| 2074 | 2074 | case READ_TWO_MORE_A1_DAM: { |
| 2075 | 2075 | if (TRACE_LIVE && m_last_live_state != READ_TWO_MORE_A1_DAM) |
| 2076 | 2076 | { |
| 2077 | | logerror("%s: [%s] READ_TWO_MORE_A1_DAM\n", tag(),tts(m_live_state.time).cstr()); |
| 2077 | logerror("%s: [%s] READ_TWO_MORE_A1_DAM\n", tag(),tts(m_live_state.time).c_str()); |
| 2078 | 2078 | m_last_live_state = m_live_state.state; |
| 2079 | 2079 | } |
| 2080 | 2080 | |
| 2081 | 2081 | if(read_one_bit(limit)) |
| 2082 | 2082 | return; |
| 2083 | 2083 | |
| 2084 | | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(m_live_state.time).cstr(), m_live_state.shift_reg, |
| 2084 | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(m_live_state.time).c_str(), m_live_state.shift_reg, |
| 2085 | 2085 | get_data_from_encoding(m_live_state.shift_reg), m_live_state.bit_counter); |
| 2086 | 2086 | |
| 2087 | 2087 | // Repeat until we have collected 16 bits |
| r245617 | r245618 | |
| 2098 | 2098 | return; |
| 2099 | 2099 | } |
| 2100 | 2100 | else |
| 2101 | | if (TRACE_LIVE) logerror("%s: [%s] Found an A1 mark\n", tag(),tts(m_live_state.time).cstr()); |
| 2101 | if (TRACE_LIVE) logerror("%s: [%s] Found an A1 mark\n", tag(),tts(m_live_state.time).c_str()); |
| 2102 | 2102 | // Continue |
| 2103 | 2103 | break; |
| 2104 | 2104 | } |
| 2105 | 2105 | |
| 2106 | | if (TRACE_LIVE) logerror("%s: [%s] Found data value %02X\n", tag(),tts(m_live_state.time).cstr(), m_live_state.data_reg); |
| 2106 | if (TRACE_LIVE) logerror("%s: [%s] Found data value %02X\n", tag(),tts(m_live_state.time).c_str(), m_live_state.data_reg); |
| 2107 | 2107 | |
| 2108 | 2108 | if ((m_live_state.data_reg & 0xff) == 0xf8) |
| 2109 | 2109 | { |
| r245617 | r245618 | |
| 2133 | 2133 | { |
| 2134 | 2134 | if (TRACE_LIVE && m_last_live_state != READ_SECTOR_DATA) |
| 2135 | 2135 | { |
| 2136 | | logerror("%s: [%s] READ_SECTOR_DATA\n", tag(),tts(m_live_state.time).cstr()); |
| 2136 | logerror("%s: [%s] READ_SECTOR_DATA\n", tag(),tts(m_live_state.time).c_str()); |
| 2137 | 2137 | m_last_live_state = m_live_state.state; |
| 2138 | 2138 | } |
| 2139 | 2139 | |
| r245617 | r245618 | |
| 2158 | 2158 | // Repeat until we have collected 16 bits |
| 2159 | 2159 | if (m_live_state.bit_counter & 15) break; |
| 2160 | 2160 | |
| 2161 | | if (TRACE_LIVE) logerror("%s: [%s] Found data value %02X, CRC=%04x\n", tag(),tts(m_live_state.time).cstr(), m_live_state.data_reg, m_live_state.crc); |
| 2161 | if (TRACE_LIVE) logerror("%s: [%s] Found data value %02X, CRC=%04x\n", tag(),tts(m_live_state.time).c_str(), m_live_state.data_reg, m_live_state.crc); |
| 2162 | 2162 | int slot = (m_live_state.bit_counter >> 4)-1; |
| 2163 | 2163 | |
| 2164 | 2164 | if (slot < calc_sector_size()) |
| r245617 | r245618 | |
| 2179 | 2179 | } |
| 2180 | 2180 | else |
| 2181 | 2181 | { |
| 2182 | | if (TRACE_LIVE) logerror("%s: [%s] Sector read completed\n", tag(),tts(m_live_state.time).cstr()); |
| 2182 | if (TRACE_LIVE) logerror("%s: [%s] Sector read completed\n", tag(),tts(m_live_state.time).c_str()); |
| 2183 | 2183 | wait_for_realtime(IDLE); |
| 2184 | 2184 | } |
| 2185 | 2185 | return; |
| r245617 | r245618 | |
| 2191 | 2191 | case READ_SECTOR_DATA1: |
| 2192 | 2192 | if (TRACE_LIVE && m_last_live_state != READ_SECTOR_DATA1) |
| 2193 | 2193 | { |
| 2194 | | logerror("%s: [%s] READ_SECTOR_DATA1\n", tag(),tts(m_live_state.time).cstr()); |
| 2194 | logerror("%s: [%s] READ_SECTOR_DATA1\n", tag(),tts(m_live_state.time).c_str()); |
| 2195 | 2195 | m_last_live_state = m_live_state.state; |
| 2196 | 2196 | } |
| 2197 | 2197 | |
| r245617 | r245618 | |
| 2237 | 2237 | // 5. Write the CRC bytes |
| 2238 | 2238 | |
| 2239 | 2239 | if (TRACE_LIVE) |
| 2240 | | logerror("%s: [%s] WRITE_DAM_AND_SECTOR\n", tag(), tts(m_live_state.time).cstr()); |
| 2240 | logerror("%s: [%s] WRITE_DAM_AND_SECTOR\n", tag(), tts(m_live_state.time).c_str()); |
| 2241 | 2241 | |
| 2242 | 2242 | skip_on_track(m_gap2_size, WRITE_DAM_SYNC); |
| 2243 | 2243 | break; |
| r245617 | r245618 | |
| 2554 | 2554 | // The pause is implemented by doing dummy reads on the floppy |
| 2555 | 2555 | if (read_one_bit(limit)) |
| 2556 | 2556 | { |
| 2557 | | if (TRACE_LIVE) logerror("%s: [%s] return; limit=%s\n", tag(), tts(m_live_state.time).cstr(), tts(limit).cstr()); |
| 2557 | if (TRACE_LIVE) logerror("%s: [%s] return; limit=%s\n", tag(), tts(m_live_state.time).c_str(), tts(limit).c_str()); |
| 2558 | 2558 | return; |
| 2559 | 2559 | } |
| 2560 | 2560 | |
| 2561 | 2561 | // Repeat until we have collected 16 bits |
| 2562 | 2562 | if ((m_live_state.bit_counter & 15)==0) |
| 2563 | 2563 | { |
| 2564 | | if (TRACE_READ && TRACE_DETAIL) logerror("%s: [%s] Read byte %02x, repeat = %d\n", tag(), tts(m_live_state.time).cstr(), m_live_state.data_reg, m_live_state.repeat); |
| 2564 | if (TRACE_READ && TRACE_DETAIL) logerror("%s: [%s] Read byte %02x, repeat = %d\n", tag(), tts(m_live_state.time).c_str(), m_live_state.data_reg, m_live_state.repeat); |
| 2565 | 2565 | wait_for_realtime(READ_TRACK_NEXT_BYTE); |
| 2566 | 2566 | return; |
| 2567 | 2567 | } |
| r245617 | r245618 | |
| 2636 | 2636 | if(m_live_state.time > machine().time()) |
| 2637 | 2637 | { |
| 2638 | 2638 | // If so, we must roll back to the last checkpoint |
| 2639 | | if (TRACE_SYNC) logerror("%s: [%s] Rolling back and replaying (%s)\n", tag(), ttsn().cstr(), tts(m_live_state.time).cstr()); |
| 2639 | if (TRACE_SYNC) logerror("%s: [%s] Rolling back and replaying (%s)\n", tag(), ttsn().c_str(), tts(m_live_state.time).c_str()); |
| 2640 | 2640 | rollback(); |
| 2641 | 2641 | // and replay until we reach the machine time |
| 2642 | 2642 | live_run_until(machine().time()); |
| r245617 | r245618 | |
| 2647 | 2647 | { |
| 2648 | 2648 | // We are behind machine time, so we will never get back to that |
| 2649 | 2649 | // time, thus we can commit that position |
| 2650 | | if (TRACE_SYNC) logerror("%s: [%s] Committing (%s)\n", tag(), ttsn().cstr(), tts(m_live_state.time).cstr()); |
| 2650 | if (TRACE_SYNC) logerror("%s: [%s] Committing (%s)\n", tag(), ttsn().c_str(), tts(m_live_state.time).c_str()); |
| 2651 | 2651 | // Write on floppy image |
| 2652 | 2652 | m_pll.commit(m_floppy, m_live_state.time); |
| 2653 | 2653 | |
| r245617 | r245618 | |
| 2672 | 2672 | { |
| 2673 | 2673 | if (!m_live_state.time.is_never() && m_live_state.time > machine().time()) |
| 2674 | 2674 | { |
| 2675 | | if (TRACE_LIVE) logerror("%s: Abort; rolling back and replaying (%s)\n", ttsn().cstr(), tts(m_live_state.time).cstr()); |
| 2675 | if (TRACE_LIVE) logerror("%s: Abort; rolling back and replaying (%s)\n", ttsn().c_str(), tts(m_live_state.time).c_str()); |
| 2676 | 2676 | rollback(); |
| 2677 | 2677 | live_run_until(machine().time()); |
| 2678 | 2678 | } |
| r245617 | r245618 | |
| 2735 | 2735 | { |
| 2736 | 2736 | m_live_state.next_state = state; |
| 2737 | 2737 | m_timer->adjust(m_live_state.time - machine().time()); |
| 2738 | | if (TRACE_LIVE) logerror("%s: [%s] Waiting for real time [%s] to catch up\n", tag(), tts(m_live_state.time).cstr(), tts(machine().time()).cstr()); |
| 2738 | if (TRACE_LIVE) logerror("%s: [%s] Waiting for real time [%s] to catch up\n", tag(), tts(m_live_state.time).c_str(), tts(machine().time()).c_str()); |
| 2739 | 2739 | } |
| 2740 | 2740 | |
| 2741 | 2741 | /* |
| r245617 | r245618 | |
| 2858 | 2858 | m_live_state.bit_counter = 16; |
| 2859 | 2859 | m_live_state.last_data_bit = raw & 1; |
| 2860 | 2860 | m_live_state.shift_reg = m_live_state.shift_reg_save = raw; |
| 2861 | | if (TRACE_WRITE && TRACE_DETAIL) logerror("%s: [%s] Write %02x (%04x)\n", tag(), tts(m_live_state.time).cstr(), byte, raw); |
| 2861 | if (TRACE_WRITE && TRACE_DETAIL) logerror("%s: [%s] Write %02x (%04x)\n", tag(), tts(m_live_state.time).c_str(), byte, raw); |
| 2862 | 2862 | checkpoint(); |
| 2863 | 2863 | } |
| 2864 | 2864 | |
| r245617 | r245618 | |
| 2872 | 2872 | m_live_state.bit_counter = 16; |
| 2873 | 2873 | m_live_state.shift_reg = m_live_state.shift_reg_save = raw; |
| 2874 | 2874 | m_live_state.last_data_bit = raw & 1; |
| 2875 | | if (TRACE_WRITE && TRACE_DETAIL) logerror("%s: [%s] Write %02x (%04x)\n", tag(), tts(m_live_state.time).cstr(), get_data_from_encoding(raw), raw); |
| 2875 | if (TRACE_WRITE && TRACE_DETAIL) logerror("%s: [%s] Write %02x (%04x)\n", tag(), tts(m_live_state.time).c_str(), get_data_from_encoding(raw), raw); |
| 2876 | 2876 | checkpoint(); |
| 2877 | 2877 | } |
| 2878 | 2878 | |
| r245617 | r245618 | |
| 2960 | 2960 | { |
| 2961 | 2961 | if (m_executing) |
| 2962 | 2962 | { |
| 2963 | | logerror("%s: [%s] Error - previous command %02x not completed; new command %02x ignored\n", tag(), ttsn().cstr(), current_command(), data); |
| 2963 | logerror("%s: [%s] Error - previous command %02x not completed; new command %02x ignored\n", tag(), ttsn().c_str(), current_command(), data); |
| 2964 | 2964 | } |
| 2965 | 2965 | else |
| 2966 | 2966 | { |
| r245617 | r245618 | |
| 3169 | 3169 | |
| 3170 | 3170 | void hdc9234_device::index_callback(int level) |
| 3171 | 3171 | { |
| 3172 | | if (TRACE_LINES) logerror("%s: [%s] Index callback level=%d\n", tag(), ttsn().cstr(), level); |
| 3172 | if (TRACE_LINES) logerror("%s: [%s] Index callback level=%d\n", tag(), ttsn().c_str(), level); |
| 3173 | 3173 | |
| 3174 | 3174 | // Synchronize our position on the track |
| 3175 | 3175 | live_sync(); |
| r245617 | r245618 | |
| 3182 | 3182 | |
| 3183 | 3183 | if (m_event_line == INDEX_LINE && level == m_line_level && m_state_after_line != UNDEF) |
| 3184 | 3184 | { |
| 3185 | | if (TRACE_LINES) logerror("%s: [%s] Index pulse level=%d triggers event\n", tag(), ttsn().cstr(), level); |
| 3185 | if (TRACE_LINES) logerror("%s: [%s] Index pulse level=%d triggers event\n", tag(), ttsn().c_str(), level); |
| 3186 | 3186 | m_substate = m_state_after_line; |
| 3187 | 3187 | m_state_after_line = UNDEF; |
| 3188 | 3188 | if (m_stopwrite) |
| r245617 | r245618 | |
| 3197 | 3197 | |
| 3198 | 3198 | void hdc9234_device::ready_callback(int level) |
| 3199 | 3199 | { |
| 3200 | | if (TRACE_LINES) logerror("%s: [%s] Ready callback level=%d\n", tag(), ttsn().cstr(), level); |
| 3200 | if (TRACE_LINES) logerror("%s: [%s] Ready callback level=%d\n", tag(), ttsn().c_str(), level); |
| 3201 | 3201 | |
| 3202 | 3202 | // Set the interrupt status flag |
| 3203 | 3203 | set_bits(m_register_r[INT_STATUS], ST_RDYCHNG, true); |
| r245617 | r245618 | |
| 3222 | 3222 | |
| 3223 | 3223 | void hdc9234_device::seek_complete_callback(int level) |
| 3224 | 3224 | { |
| 3225 | | if (TRACE_LINES) logerror("%s: [%s] Seek complete callback level=%d\n", tag(), ttsn().cstr(), level); |
| 3225 | if (TRACE_LINES) logerror("%s: [%s] Seek complete callback level=%d\n", tag(), ttsn().c_str(), level); |
| 3226 | 3226 | |
| 3227 | 3227 | // Synchronize our position on the track |
| 3228 | 3228 | live_sync(); |
| r245617 | r245618 | |
| 3323 | 3323 | { |
| 3324 | 3324 | if (state==ASSERT_LINE) |
| 3325 | 3325 | { |
| 3326 | | if (TRACE_DMA) logerror("%s: [%s] DMA acknowledged\n", tag(), ttsn().cstr()); |
| 3326 | if (TRACE_DMA) logerror("%s: [%s] DMA acknowledged\n", tag(), ttsn().c_str()); |
| 3327 | 3327 | set_bits(m_register_r[INT_STATUS], ST_OVRUN, false); |
| 3328 | 3328 | } |
| 3329 | 3329 | } |
trunk/src/emu/machine/wd_fdc.c
| r245617 | r245618 | |
| 383 | 383 | return; |
| 384 | 384 | |
| 385 | 385 | default: |
| 386 | | logerror("%s: seek unknown sub-state %d\n", ttsn().cstr(), sub_state); |
| 386 | logerror("%s: seek unknown sub-state %d\n", ttsn().c_str(), sub_state); |
| 387 | 387 | return; |
| 388 | 388 | } |
| 389 | 389 | } |
| r245617 | r245618 | |
| 505 | 505 | break; |
| 506 | 506 | |
| 507 | 507 | default: |
| 508 | | logerror("%s: read sector unknown sub-state %d\n", ttsn().cstr(), sub_state); |
| 508 | logerror("%s: read sector unknown sub-state %d\n", ttsn().c_str(), sub_state); |
| 509 | 509 | return; |
| 510 | 510 | } |
| 511 | 511 | } |
| r245617 | r245618 | |
| 584 | 584 | return; |
| 585 | 585 | |
| 586 | 586 | default: |
| 587 | | logerror("%s: read track unknown sub-state %d\n", ttsn().cstr(), sub_state); |
| 587 | logerror("%s: read track unknown sub-state %d\n", ttsn().c_str(), sub_state); |
| 588 | 588 | return; |
| 589 | 589 | } |
| 590 | 590 | } |
| r245617 | r245618 | |
| 659 | 659 | return; |
| 660 | 660 | |
| 661 | 661 | default: |
| 662 | | logerror("%s: read id unknown sub-state %d\n", ttsn().cstr(), sub_state); |
| 662 | logerror("%s: read id unknown sub-state %d\n", ttsn().c_str(), sub_state); |
| 663 | 663 | return; |
| 664 | 664 | } |
| 665 | 665 | } |
| r245617 | r245618 | |
| 763 | 763 | sprintf(buf, "%02x", format_last_byte); |
| 764 | 764 | format_description_string += buf; |
| 765 | 765 | } |
| 766 | | if (TRACE_DESC) logerror("%s: track description %s\n", tag(), format_description_string.cstr()); |
| 766 | if (TRACE_DESC) logerror("%s: track description %s\n", tag(), format_description_string.c_str()); |
| 767 | 767 | command_end(); |
| 768 | 768 | return; |
| 769 | 769 | |
| 770 | 770 | default: |
| 771 | | logerror("%s: write track unknown sub-state %d\n", ttsn().cstr(), sub_state); |
| 771 | logerror("%s: write track unknown sub-state %d\n", ttsn().c_str(), sub_state); |
| 772 | 772 | return; |
| 773 | 773 | } |
| 774 | 774 | } |
| r245617 | r245618 | |
| 867 | 867 | break; |
| 868 | 868 | |
| 869 | 869 | default: |
| 870 | | logerror("%s: write sector unknown sub-state %d\n", ttsn().cstr(), sub_state); |
| 870 | logerror("%s: write sector unknown sub-state %d\n", ttsn().c_str(), sub_state); |
| 871 | 871 | return; |
| 872 | 872 | } |
| 873 | 873 | } |
| r245617 | r245618 | |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | 900 | if(command & 0x03) { |
| 901 | | logerror("%s: unhandled interrupt generation (%02x)\n", ttsn().cstr(), command); |
| 901 | logerror("%s: unhandled interrupt generation (%02x)\n", ttsn().c_str(), command); |
| 902 | 902 | } |
| 903 | 903 | } |
| 904 | 904 | |
| r245617 | r245618 | |
| 932 | 932 | write_sector_continue(); |
| 933 | 933 | break; |
| 934 | 934 | default: |
| 935 | | logerror("%s: general_continue on unknown main-state %d\n", ttsn().cstr(), main_state); |
| 935 | logerror("%s: general_continue on unknown main-state %d\n", ttsn().c_str(), main_state); |
| 936 | 936 | break; |
| 937 | 937 | } |
| 938 | 938 | } |
| r245617 | r245618 | |
| 963 | 963 | |
| 964 | 964 | default: |
| 965 | 965 | if(cur_live.tm.is_never()) |
| 966 | | logerror("%s: do_generic on unknown sub-state %d\n", ttsn().cstr(), sub_state); |
| 966 | logerror("%s: do_generic on unknown sub-state %d\n", ttsn().c_str(), sub_state); |
| 967 | 967 | break; |
| 968 | 968 | } |
| 969 | 969 | } |
| r245617 | r245618 | |
| 1285 | 1285 | break; |
| 1286 | 1286 | |
| 1287 | 1287 | default: |
| 1288 | | logerror("%s: Index pulse on unknown sub-state %d\n", ttsn().cstr(), sub_state); |
| 1288 | logerror("%s: Index pulse on unknown sub-state %d\n", ttsn().c_str(), sub_state); |
| 1289 | 1289 | break; |
| 1290 | 1290 | } |
| 1291 | 1291 | |
| r245617 | r245618 | |
| 1360 | 1360 | { |
| 1361 | 1361 | if(!cur_live.tm.is_never()) { |
| 1362 | 1362 | if(cur_live.tm > machine().time()) { |
| 1363 | | if (TRACE_SYNC) logerror("%s: Rolling back and replaying (%s)\n", ttsn().cstr(), tts(cur_live.tm).cstr()); |
| 1363 | if (TRACE_SYNC) logerror("%s: Rolling back and replaying (%s)\n", ttsn().c_str(), tts(cur_live.tm).c_str()); |
| 1364 | 1364 | rollback(); |
| 1365 | 1365 | live_run(machine().time()); |
| 1366 | 1366 | pll_commit(floppy, cur_live.tm); |
| 1367 | 1367 | } else { |
| 1368 | | if (TRACE_SYNC) logerror("%s: Committing (%s)\n", ttsn().cstr(), tts(cur_live.tm).cstr()); |
| 1368 | if (TRACE_SYNC) logerror("%s: Committing (%s)\n", ttsn().c_str(), tts(cur_live.tm).c_str()); |
| 1369 | 1369 | pll_commit(floppy, cur_live.tm); |
| 1370 | 1370 | if(cur_live.next_state != -1) { |
| 1371 | 1371 | cur_live.state = cur_live.next_state; |
| r245617 | r245618 | |
| 1485 | 1485 | } |
| 1486 | 1486 | } |
| 1487 | 1487 | |
| 1488 | | // fprintf(stderr, "%s: live_run(%s)\n", ttsn().cstr(), tts(limit).cstr()); |
| 1488 | // fprintf(stderr, "%s: live_run(%s)\n", ttsn().c_str(), tts(limit).c_str()); |
| 1489 | 1489 | |
| 1490 | 1490 | for(;;) { |
| 1491 | 1491 | switch(cur_live.state) { |
| r245617 | r245618 | |
| 1493 | 1493 | if(read_one_bit(limit)) |
| 1494 | 1494 | return; |
| 1495 | 1495 | |
| 1496 | | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(cur_live.tm).cstr(), cur_live.shift_reg, |
| 1496 | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d\n", tts(cur_live.tm).c_str(), cur_live.shift_reg, |
| 1497 | 1497 | (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) | |
| 1498 | 1498 | (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) | |
| 1499 | 1499 | (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) | |
| r245617 | r245618 | |
| 1526 | 1526 | if(read_one_bit(limit)) |
| 1527 | 1527 | return; |
| 1528 | 1528 | |
| 1529 | | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x counter=%d\n", tts(cur_live.tm).cstr(), cur_live.shift_reg, |
| 1529 | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x counter=%d\n", tts(cur_live.tm).c_str(), cur_live.shift_reg, |
| 1530 | 1530 | (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) | |
| 1531 | 1531 | (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) | |
| 1532 | 1532 | (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) | |
| r245617 | r245618 | |
| 1568 | 1568 | if(cur_live.bit_counter & 15) |
| 1569 | 1569 | break; |
| 1570 | 1570 | int slot = (cur_live.bit_counter >> 4)-1; |
| 1571 | | // fprintf(stderr, "%s: slot[%d] = %02x crc = %04x\n", tts(cur_live.tm).cstr(), slot, cur_live.data_reg, cur_live.crc); |
| 1571 | // fprintf(stderr, "%s: slot[%d] = %02x crc = %04x\n", tts(cur_live.tm).c_str(), slot, cur_live.data_reg, cur_live.crc); |
| 1572 | 1572 | cur_live.idbuf[slot] = cur_live.data_reg; |
| 1573 | 1573 | if(slot == 5) { |
| 1574 | 1574 | live_delay(IDLE); |
| r245617 | r245618 | |
| 1609 | 1609 | if(read_one_bit(limit)) |
| 1610 | 1610 | return; |
| 1611 | 1611 | |
| 1612 | | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d.%x\n", tts(cur_live.tm).cstr(), cur_live.shift_reg, |
| 1612 | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x c=%d.%x\n", tts(cur_live.tm).c_str(), cur_live.shift_reg, |
| 1613 | 1613 | (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) | |
| 1614 | 1614 | (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) | |
| 1615 | 1615 | (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) | |
| r245617 | r245618 | |
| 1656 | 1656 | if(read_one_bit(limit)) |
| 1657 | 1657 | return; |
| 1658 | 1658 | |
| 1659 | | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x counter=%d\n", tts(cur_live.tm).cstr(), cur_live.shift_reg, |
| 1659 | if (TRACE_SHIFT) logerror("%s: shift = %04x data=%02x counter=%d\n", tts(cur_live.tm).c_str(), cur_live.shift_reg, |
| 1660 | 1660 | (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) | |
| 1661 | 1661 | (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) | |
| 1662 | 1662 | (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) | |
| r245617 | r245618 | |
| 1954 | 1954 | break; |
| 1955 | 1955 | |
| 1956 | 1956 | default: |
| 1957 | | logerror("%s: Unknown sub state %d in WRITE_BYTE_DONE\n", tts(cur_live.tm).cstr(), sub_state); |
| 1957 | logerror("%s: Unknown sub state %d in WRITE_BYTE_DONE\n", tts(cur_live.tm).c_str(), sub_state); |
| 1958 | 1958 | live_abort(); |
| 1959 | 1959 | return; |
| 1960 | 1960 | } |
| r245617 | r245618 | |
| 2017 | 2017 | break; |
| 2018 | 2018 | |
| 2019 | 2019 | default: |
| 2020 | | logerror("%s: Unknown live state %d\n", tts(cur_live.tm).cstr(), cur_live.state); |
| 2020 | logerror("%s: Unknown live state %d\n", tts(cur_live.tm).c_str(), cur_live.state); |
| 2021 | 2021 | return; |
| 2022 | 2022 | } |
| 2023 | 2023 | } |
| r245617 | r245618 | |
| 2186 | 2186 | |
| 2187 | 2187 | /* if (TRACE_TRANSITION) |
| 2188 | 2188 | if(!when.is_never()) |
| 2189 | | logerror("transition_time=%s\n", tts(when).cstr()); |
| 2189 | logerror("transition_time=%s\n", tts(when).c_str()); |
| 2190 | 2190 | */ |
| 2191 | 2191 | for(;;) { |
| 2192 | 2192 | // if (TRACE_TRANSITION) logerror("slot=%2d, counter=%03x\n", slot, counter); |
| 2193 | 2193 | attotime etime = ctime+delays[slot]; |
| 2194 | | // if (TRACE_TRANSITION) logerror("etime=%s\n", tts(etime).cstr()); |
| 2194 | // if (TRACE_TRANSITION) logerror("etime=%s\n", tts(etime).c_str()); |
| 2195 | 2195 | if(etime > limit) |
| 2196 | 2196 | return -1; |
| 2197 | 2197 | if(transition_time == 0xffff && !when.is_never() && etime >= when) |
trunk/src/emu/romload.c
| r245617 | r245618 | |
| 441 | 441 | |
| 442 | 442 | bool is_chd_error = (is_chd && chderr != CHDERR_FILE_NOT_FOUND); |
| 443 | 443 | if (is_chd_error) |
| 444 | | romdata->errorstring.catprintf("%s CHD ERROR: %s\n", name.cstr(), chd_file::error_string(chderr)); |
| 444 | romdata->errorstring.catprintf("%s CHD ERROR: %s\n", name.c_str(), chd_file::error_string(chderr)); |
| 445 | 445 | |
| 446 | 446 | /* optional files are okay */ |
| 447 | 447 | if (ROM_ISOPTIONAL(romp)) |
| 448 | 448 | { |
| 449 | 449 | if (!is_chd_error) |
| 450 | | romdata->errorstring.catprintf("OPTIONAL %s NOT FOUND%s\n", name.cstr(), tried_file_names.cstr()); |
| 450 | romdata->errorstring.catprintf("OPTIONAL %s NOT FOUND%s\n", name.c_str(), tried_file_names.c_str()); |
| 451 | 451 | romdata->warnings++; |
| 452 | 452 | } |
| 453 | 453 | |
| r245617 | r245618 | |
| 455 | 455 | else if (hash_collection(ROM_GETHASHDATA(romp)).flag(hash_collection::FLAG_NO_DUMP)) |
| 456 | 456 | { |
| 457 | 457 | if (!is_chd_error) |
| 458 | | romdata->errorstring.catprintf("%s NOT FOUND (NO GOOD DUMP KNOWN)%s\n", name.cstr(), tried_file_names.cstr()); |
| 458 | romdata->errorstring.catprintf("%s NOT FOUND (NO GOOD DUMP KNOWN)%s\n", name.c_str(), tried_file_names.c_str()); |
| 459 | 459 | romdata->knownbad++; |
| 460 | 460 | } |
| 461 | 461 | |
| r245617 | r245618 | |
| 463 | 463 | else |
| 464 | 464 | { |
| 465 | 465 | if (!is_chd_error) |
| 466 | | romdata->errorstring.catprintf("%s NOT FOUND%s\n", name.cstr(), tried_file_names.cstr()); |
| 466 | romdata->errorstring.catprintf("%s NOT FOUND%s\n", name.c_str(), tried_file_names.c_str()); |
| 467 | 467 | romdata->errors++; |
| 468 | 468 | } |
| 469 | 469 | } |
| r245617 | r245618 | |
| 560 | 560 | if (romdata->errors != 0) |
| 561 | 561 | { |
| 562 | 562 | /* create the error message and exit fatally */ |
| 563 | | osd_printf_error("%s", romdata->errorstring.cstr()); |
| 563 | osd_printf_error("%s", romdata->errorstring.c_str()); |
| 564 | 564 | fatalerror_exitcode(romdata->machine(), MAMERR_MISSING_FILES, "Required files are missing, the %s cannot be run.",emulator_info::get_gamenoun()); |
| 565 | 565 | } |
| 566 | 566 | |
| r245617 | r245618 | |
| 570 | 570 | romdata->errorstring.cat("WARNING: the "); |
| 571 | 571 | romdata->errorstring.cat(emulator_info::get_gamenoun()); |
| 572 | 572 | romdata->errorstring.cat(" might not run correctly."); |
| 573 | | osd_printf_warning("%s\n", romdata->errorstring.cstr()); |
| 573 | osd_printf_warning("%s\n", romdata->errorstring.c_str()); |
| 574 | 574 | } |
| 575 | 575 | } |
| 576 | 576 | |
| r245617 | r245618 | |
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | // prepare locations where we have to load from: list/parentname & list/clonename |
| 680 | | astring swlist(tag1.cstr()); |
| 680 | astring swlist(tag1.c_str()); |
| 681 | 681 | tag2.cpy(swlist.cat(tag4)); |
| 682 | 682 | if (has_parent) |
| 683 | 683 | { |
| r245617 | r245618 | |
| 695 | 695 | if (!is_list) |
| 696 | 696 | { |
| 697 | 697 | tried_file_names += " " + tag1; |
| 698 | | filerr = common_process_file(romdata->machine().options(), tag1.cstr(), has_crc, crc, romp, &romdata->file); |
| 698 | filerr = common_process_file(romdata->machine().options(), tag1.c_str(), has_crc, crc, romp, &romdata->file); |
| 699 | 699 | } |
| 700 | 700 | else |
| 701 | 701 | { |
| 702 | 702 | // try to load from list/setname |
| 703 | | if ((romdata->file == NULL) && (tag2.cstr() != NULL)) |
| 703 | if ((romdata->file == NULL) && (tag2.c_str() != NULL)) |
| 704 | 704 | { |
| 705 | 705 | tried_file_names += " " + tag2; |
| 706 | | filerr = common_process_file(romdata->machine().options(), tag2.cstr(), has_crc, crc, romp, &romdata->file); |
| 706 | filerr = common_process_file(romdata->machine().options(), tag2.c_str(), has_crc, crc, romp, &romdata->file); |
| 707 | 707 | } |
| 708 | 708 | // try to load from list/parentname |
| 709 | | if ((romdata->file == NULL) && has_parent && (tag3.cstr() != NULL)) |
| 709 | if ((romdata->file == NULL) && has_parent && (tag3.c_str() != NULL)) |
| 710 | 710 | { |
| 711 | 711 | tried_file_names += " " + tag3; |
| 712 | | filerr = common_process_file(romdata->machine().options(), tag3.cstr(), has_crc, crc, romp, &romdata->file); |
| 712 | filerr = common_process_file(romdata->machine().options(), tag3.c_str(), has_crc, crc, romp, &romdata->file); |
| 713 | 713 | } |
| 714 | 714 | // try to load from setname |
| 715 | | if ((romdata->file == NULL) && (tag4.cstr() != NULL)) |
| 715 | if ((romdata->file == NULL) && (tag4.c_str() != NULL)) |
| 716 | 716 | { |
| 717 | 717 | tried_file_names += " " + tag4; |
| 718 | | filerr = common_process_file(romdata->machine().options(), tag4.cstr(), has_crc, crc, romp, &romdata->file); |
| 718 | filerr = common_process_file(romdata->machine().options(), tag4.c_str(), has_crc, crc, romp, &romdata->file); |
| 719 | 719 | } |
| 720 | 720 | // try to load from parentname |
| 721 | | if ((romdata->file == NULL) && has_parent && (tag5.cstr() != NULL)) |
| 721 | if ((romdata->file == NULL) && has_parent && (tag5.c_str() != NULL)) |
| 722 | 722 | { |
| 723 | 723 | tried_file_names += " " + tag5; |
| 724 | | filerr = common_process_file(romdata->machine().options(), tag5.cstr(), has_crc, crc, romp, &romdata->file); |
| 724 | filerr = common_process_file(romdata->machine().options(), tag5.c_str(), has_crc, crc, romp, &romdata->file); |
| 725 | 725 | } |
| 726 | 726 | } |
| 727 | 727 | } |
| r245617 | r245618 | |
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | 1080 | // prepare locations where we have to load from: list/parentname (if any) & list/clonename |
| 1081 | | astring swlist(tag1.cstr()); |
| 1081 | astring swlist(tag1.c_str()); |
| 1082 | 1082 | tag2.cpy(swlist.cat(tag4)); |
| 1083 | 1083 | if (has_parent) |
| 1084 | 1084 | { |
| r245617 | r245618 | |
| 1098 | 1098 | else |
| 1099 | 1099 | { |
| 1100 | 1100 | // try to load from list/setname |
| 1101 | | if ((filerr != FILERR_NONE) && (tag2.cstr() != NULL)) |
| 1102 | | filerr = common_process_file(options, tag2.cstr(), ".chd", romp, image_file); |
| 1101 | if ((filerr != FILERR_NONE) && (tag2.c_str() != NULL)) |
| 1102 | filerr = common_process_file(options, tag2.c_str(), ".chd", romp, image_file); |
| 1103 | 1103 | // try to load from list/parentname (if any) |
| 1104 | | if ((filerr != FILERR_NONE) && has_parent && (tag3.cstr() != NULL)) |
| 1105 | | filerr = common_process_file(options, tag3.cstr(), ".chd", romp, image_file); |
| 1104 | if ((filerr != FILERR_NONE) && has_parent && (tag3.c_str() != NULL)) |
| 1105 | filerr = common_process_file(options, tag3.c_str(), ".chd", romp, image_file); |
| 1106 | 1106 | // try to load from setname |
| 1107 | | if ((filerr != FILERR_NONE) && (tag4.cstr() != NULL)) |
| 1108 | | filerr = common_process_file(options, tag4.cstr(), ".chd", romp, image_file); |
| 1107 | if ((filerr != FILERR_NONE) && (tag4.c_str() != NULL)) |
| 1108 | filerr = common_process_file(options, tag4.c_str(), ".chd", romp, image_file); |
| 1109 | 1109 | // try to load from parentname (if any) |
| 1110 | | if ((filerr != FILERR_NONE) && has_parent && (tag5.cstr() != NULL)) |
| 1111 | | filerr = common_process_file(options, tag5.cstr(), ".chd", romp, image_file); |
| 1110 | if ((filerr != FILERR_NONE) && has_parent && (tag5.c_str() != NULL)) |
| 1111 | filerr = common_process_file(options, tag5.c_str(), ".chd", romp, image_file); |
| 1112 | 1112 | // only for CHD we also try to load from list/ |
| 1113 | | if ((filerr != FILERR_NONE) && (tag1.cstr() != NULL)) |
| 1113 | if ((filerr != FILERR_NONE) && (tag1.c_str() != NULL)) |
| 1114 | 1114 | { |
| 1115 | 1115 | tag1.del(tag1.len() - 1, 1); // remove the PATH_SEPARATOR |
| 1116 | | filerr = common_process_file(options, tag1.cstr(), ".chd", romp, image_file); |
| 1116 | filerr = common_process_file(options, tag1.c_str(), ".chd", romp, image_file); |
| 1117 | 1117 | } |
| 1118 | 1118 | } |
| 1119 | 1119 | } |
| r245617 | r245618 | |
| 1182 | 1182 | astring fname(ROM_GETNAME(romp), ".dif"); |
| 1183 | 1183 | |
| 1184 | 1184 | /* try to open the diff */ |
| 1185 | | LOG(("Opening differencing image file: %s\n", fname.cstr())); |
| 1185 | LOG(("Opening differencing image file: %s\n", fname.c_str())); |
| 1186 | 1186 | emu_file diff_file(options.diff_directory(), OPEN_FLAG_READ | OPEN_FLAG_WRITE); |
| 1187 | 1187 | file_error filerr = diff_file.open(fname); |
| 1188 | 1188 | if (filerr == FILERR_NONE) |
| r245617 | r245618 | |
| 1190 | 1190 | astring fullpath(diff_file.fullpath()); |
| 1191 | 1191 | diff_file.close(); |
| 1192 | 1192 | |
| 1193 | | LOG(("Opening differencing image file: %s\n", fullpath.cstr())); |
| 1193 | LOG(("Opening differencing image file: %s\n", fullpath.c_str())); |
| 1194 | 1194 | return diff_chd.open(fullpath, true, &source); |
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | 1197 | /* didn't work; try creating it instead */ |
| 1198 | | LOG(("Creating differencing image: %s\n", fname.cstr())); |
| 1198 | LOG(("Creating differencing image: %s\n", fname.c_str())); |
| 1199 | 1199 | diff_file.set_openflags(OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); |
| 1200 | 1200 | filerr = diff_file.open(fname); |
| 1201 | 1201 | if (filerr == FILERR_NONE) |
| r245617 | r245618 | |
| 1204 | 1204 | diff_file.close(); |
| 1205 | 1205 | |
| 1206 | 1206 | /* create the CHD */ |
| 1207 | | LOG(("Creating differencing image file: %s\n", fullpath.cstr())); |
| 1207 | LOG(("Creating differencing image file: %s\n", fullpath.c_str())); |
| 1208 | 1208 | chd_codec_type compression[4] = { CHD_CODEC_NONE }; |
| 1209 | 1209 | chd_error err = diff_chd.create(fullpath, source.logical_bytes(), source.hunk_bytes(), compression, source); |
| 1210 | 1210 | if (err != CHDERR_NONE) |
| r245617 | r245618 | |
| 1239 | 1239 | astring filename(ROM_GETNAME(romp), ".chd"); |
| 1240 | 1240 | |
| 1241 | 1241 | /* first open the source drive */ |
| 1242 | | LOG(("Opening disk image: %s\n", filename.cstr())); |
| 1242 | LOG(("Opening disk image: %s\n", filename.c_str())); |
| 1243 | 1243 | err = chd_error(open_disk_image(romdata->machine().options(), &romdata->machine().system(), romp, chd->orig_chd(), locationtag)); |
| 1244 | 1244 | if (err != CHDERR_NONE) |
| 1245 | 1245 | { |
| r245617 | r245618 | |
| 1255 | 1255 | /* verify the hash */ |
| 1256 | 1256 | if (hashes != acthashes) |
| 1257 | 1257 | { |
| 1258 | | romdata->errorstring.catprintf("%s WRONG CHECKSUMS:\n", filename.cstr()); |
| 1258 | romdata->errorstring.catprintf("%s WRONG CHECKSUMS:\n", filename.c_str()); |
| 1259 | 1259 | dump_wrong_and_correct_checksums(romdata, hashes, acthashes); |
| 1260 | 1260 | romdata->warnings++; |
| 1261 | 1261 | } |
| 1262 | 1262 | else if (hashes.flag(hash_collection::FLAG_BAD_DUMP)) |
| 1263 | 1263 | { |
| 1264 | | romdata->errorstring.catprintf("%s CHD NEEDS REDUMP\n", filename.cstr()); |
| 1264 | romdata->errorstring.catprintf("%s CHD NEEDS REDUMP\n", filename.c_str()); |
| 1265 | 1265 | romdata->knownbad++; |
| 1266 | 1266 | } |
| 1267 | 1267 | |
| r245617 | r245618 | |
| 1272 | 1272 | err = open_disk_diff(romdata->machine().options(), romp, chd->orig_chd(), chd->diff_chd()); |
| 1273 | 1273 | if (err != CHDERR_NONE) |
| 1274 | 1274 | { |
| 1275 | | romdata->errorstring.catprintf("%s DIFF CHD ERROR: %s\n", filename.cstr(), chd_file::error_string(err)); |
| 1275 | romdata->errorstring.catprintf("%s DIFF CHD ERROR: %s\n", filename.c_str(), chd_file::error_string(err)); |
| 1276 | 1276 | romdata->errors++; |
| 1277 | 1277 | global_free(chd); |
| 1278 | 1278 | continue; |
| r245617 | r245618 | |
| 1385 | 1385 | UINT32 regionlength = ROMREGION_GETLENGTH(region); |
| 1386 | 1386 | |
| 1387 | 1387 | device.subtag(regiontag, ROMREGION_GETTAG(region)); |
| 1388 | | LOG(("Processing region \"%s\" (length=%X)\n", regiontag.cstr(), regionlength)); |
| 1388 | LOG(("Processing region \"%s\" (length=%X)\n", regiontag.c_str(), regionlength)); |
| 1389 | 1389 | |
| 1390 | 1390 | /* the first entry must be a region */ |
| 1391 | 1391 | assert(ROMENTRY_ISREGION(region)); |
| r245617 | r245618 | |
| 1439 | 1439 | for (region = start_region; region != NULL; region = rom_next_region(region)) |
| 1440 | 1440 | { |
| 1441 | 1441 | device.subtag(regiontag, ROMREGION_GETTAG(region)); |
| 1442 | | region_post_process(romdata, regiontag.cstr(), ROMREGION_ISINVERTED(region)); |
| 1442 | region_post_process(romdata, regiontag.c_str(), ROMREGION_ISINVERTED(region)); |
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | /* display the results and exit */ |
| r245617 | r245618 | |
| 1463 | 1463 | UINT32 regionlength = ROMREGION_GETLENGTH(region); |
| 1464 | 1464 | |
| 1465 | 1465 | rom_region_name(regiontag, *device, region); |
| 1466 | | LOG(("Processing region \"%s\" (length=%X)\n", regiontag.cstr(), regionlength)); |
| 1466 | LOG(("Processing region \"%s\" (length=%X)\n", regiontag.c_str(), regionlength)); |
| 1467 | 1467 | |
| 1468 | 1468 | /* the first entry must be a region */ |
| 1469 | 1469 | assert(ROMENTRY_ISREGION(region)); |
| r245617 | r245618 | |
| 1548 | 1548 | } else { |
| 1549 | 1549 | specbios = romdata->machine().options().sub_value(temp,device->owner()->tag()+1,"bios"); |
| 1550 | 1550 | if (strlen(specbios) == 0) { |
| 1551 | | specbios = device->default_bios_tag().cstr(); |
| 1551 | specbios = device->default_bios_tag().c_str(); |
| 1552 | 1552 | } |
| 1553 | 1553 | } |
| 1554 | 1554 | determine_bios_rom(romdata, device, specbios); |
trunk/src/lib/util/simple_set.h
| r0 | r245618 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | simple_set.h |
| 4 | |
| 5 | A STL-like set class. |
| 6 | |
| 7 | Copyright Nicola Salmoria and the MAME Team. |
| 8 | Visit http://mamedev.org for licensing and usage restrictions. |
| 9 | |
| 10 | *********************************************************************/ |
| 11 | |
| 12 | #pragma once |
| 13 | |
| 14 | #ifndef __SIMPLE_SET_H__ |
| 15 | #define __SIMPLE_SET_H__ |
| 16 | |
| 17 | #ifdef SIMPLE_SET_DEBUG |
| 18 | #include <iostream> |
| 19 | #endif |
| 20 | |
| 21 | |
| 22 | // Predeclarations |
| 23 | template <class T> class avl_tree_node; |
| 24 | template <class T> class simple_set_iterator; |
| 25 | |
| 26 | |
| 27 | // |
| 28 | // ======================> simple_set |
| 29 | // A shiny stl-like set interface wrapping an AVL tree |
| 30 | // |
| 31 | // PUBLIC OPERATIONS: |
| 32 | // size, empty, clear, insert, remove, find, contains, merge, & assignment. |
| 33 | // |
| 34 | |
| 35 | template <class T> |
| 36 | class simple_set |
| 37 | { |
| 38 | friend class simple_set_iterator<T>; |
| 39 | typedef avl_tree_node<T> tree_node; |
| 40 | |
| 41 | public: |
| 42 | // Construction |
| 43 | simple_set() |
| 44 | : m_root(NULL) |
| 45 | { } |
| 46 | |
| 47 | simple_set(const simple_set& rhs) |
| 48 | : m_root(NULL) |
| 49 | { |
| 50 | *this = rhs; |
| 51 | } |
| 52 | |
| 53 | ~simple_set() |
| 54 | { |
| 55 | clear(); |
| 56 | } |
| 57 | |
| 58 | |
| 59 | // Returns number of elements in the tree -- O(n) |
| 60 | int size() const |
| 61 | { |
| 62 | if (empty()) return 0; |
| 63 | |
| 64 | const tree_node* currentNode = m_root; |
| 65 | const int nodeCount = sizeRecurse(currentNode); |
| 66 | return nodeCount; |
| 67 | } |
| 68 | |
| 69 | |
| 70 | // Test for emptiness -- O(1). |
| 71 | bool empty() const |
| 72 | { |
| 73 | return m_root == NULL; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | // Empty the tree -- O(n). |
| 78 | void clear() |
| 79 | { |
| 80 | clearRecurse(m_root); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | // Insert x into the avl tree; duplicates are ignored -- O(log n). |
| 85 | bool insert(const T& x) |
| 86 | { |
| 87 | bool retVal = insert(x, m_root); |
| 88 | |
| 89 | // Whether the node was successfully inserted or not (i.e. wasn't a duplicate) |
| 90 | return retVal; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | // Remove x from the tree. Nothing is done if x is not found -- O(n). |
| 95 | bool remove(const T& x) |
| 96 | { |
| 97 | // First find the node in the tree |
| 98 | tree_node* currNode = find(x, m_root); |
| 99 | |
| 100 | // Only do this when the current node is valid |
| 101 | if (currNode) |
| 102 | { |
| 103 | // See if it's a leaf |
| 104 | if (currNode->isLeaf()) |
| 105 | { |
| 106 | // Get the parent object |
| 107 | tree_node* parentNode = currNode->parent; |
| 108 | |
| 109 | // If we're a leaf and we have no parent, then the tree will be emptied |
| 110 | if (!currNode->parent) |
| 111 | { |
| 112 | m_root = NULL; |
| 113 | } |
| 114 | |
| 115 | // If it's a leaf node, simply remove it |
| 116 | removeNode(currNode); |
| 117 | global_free(currNode); |
| 118 | |
| 119 | // Update the balance of the parent of |
| 120 | // currentNode after having disconnected |
| 121 | // it |
| 122 | if (parentNode) |
| 123 | parentNode->calcHeights(); |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | // Get the parent object |
| 128 | tree_node* parentNode = currNode->parent; |
| 129 | |
| 130 | // Remove the child and reconnect the smallest node in the right sub tree |
| 131 | // (in order successor) |
| 132 | tree_node* replaceNode = findMin(currNode->right); |
| 133 | |
| 134 | // See if there's even a right-most node |
| 135 | if (!replaceNode) |
| 136 | { |
| 137 | // Get the largest node on the left (because the right doesn't exist) |
| 138 | replaceNode = findMax(currNode->left); |
| 139 | } |
| 140 | |
| 141 | tree_node* parentReplaceNode = replaceNode->parent; |
| 142 | |
| 143 | // Disconnect the replacement node's branch |
| 144 | removeNode(replaceNode); |
| 145 | |
| 146 | // Update the balance of the parent of |
| 147 | // replaceNode after having disconnected |
| 148 | // it |
| 149 | if (parentReplaceNode) |
| 150 | parentReplaceNode->calcHeights(); |
| 151 | |
| 152 | // Disconnect the current node |
| 153 | removeNode(currNode); |
| 154 | |
| 155 | // Get the current node's left and right branches |
| 156 | tree_node* left = currNode->left; |
| 157 | tree_node* right = currNode->right; |
| 158 | |
| 159 | // We no longer need this node |
| 160 | global_free(currNode); |
| 161 | |
| 162 | // Check to see if we removed the root node |
| 163 | if (!parentNode) |
| 164 | { |
| 165 | // Merge the branches into the parent node of what we deleted |
| 166 | merge(replaceNode, parentNode); |
| 167 | merge(left, parentNode); |
| 168 | merge(right, parentNode); |
| 169 | |
| 170 | // Now we're the root |
| 171 | m_root = parentNode; |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | // Merge the branches into the parent node of what we |
| 176 | // deleted, we let the merge algorithm decide where to |
| 177 | // put the branches |
| 178 | merge(replaceNode, parentNode); |
| 179 | merge(left, parentNode); |
| 180 | merge(right, parentNode); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | // Balance the tree |
| 185 | balanceTree(); |
| 186 | |
| 187 | // The node was found and removed successfully |
| 188 | return true; |
| 189 | } |
| 190 | else |
| 191 | { |
| 192 | // The node was not found |
| 193 | return false; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | |
| 198 | // Find item x in the tree. Returns a pointer to the matching item |
| 199 | // or NULL if not found -- O(log n) |
| 200 | T* find(const T& x) const |
| 201 | { |
| 202 | tree_node* found = find(x, m_root); |
| 203 | if (found == NULL) return NULL; |
| 204 | return &found->element; |
| 205 | } |
| 206 | |
| 207 | |
| 208 | // Is the data present in the set? -- O(log n) |
| 209 | bool contains(const T& x) const |
| 210 | { |
| 211 | if (find(x) != NULL) |
| 212 | return true; |
| 213 | else |
| 214 | return false; |
| 215 | } |
| 216 | |
| 217 | |
| 218 | // Merge a different tree with ours -- O(n). |
| 219 | bool merge(const simple_set<T>& b) |
| 220 | { |
| 221 | tree_node* c = b->clone(); |
| 222 | bool retVal = merge(c->m_root, m_root); |
| 223 | |
| 224 | // Re-balance the tree if the merge was successful |
| 225 | if (retVal) |
| 226 | { |
| 227 | balanceTree(); |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | global_free(c); |
| 232 | } |
| 233 | |
| 234 | return retVal; |
| 235 | } |
| 236 | |
| 237 | |
| 238 | // Replace this set with another -- O(n) |
| 239 | const simple_set& operator=(const simple_set& rhs) |
| 240 | { |
| 241 | // Don't clone if it's the same pointer |
| 242 | if (this != &rhs) |
| 243 | { |
| 244 | clear(); |
| 245 | |
| 246 | m_root = clone(rhs.m_root); |
| 247 | } |
| 248 | |
| 249 | return *this; |
| 250 | } |
| 251 | |
| 252 | |
| 253 | #ifdef SIMPLE_SET_DEBUG |
| 254 | // Debug -- O(n log n) |
| 255 | void printTree(std::ostream& out = std::cout) const |
| 256 | { |
| 257 | if(empty()) |
| 258 | { |
| 259 | out << "Empty tree" << std::endl; |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | printTree(out, m_root); |
| 264 | } |
| 265 | } |
| 266 | #endif |
| 267 | |
| 268 | |
| 269 | private: |
| 270 | // The AVL tree's root |
| 271 | tree_node* m_root; |
| 272 | |
| 273 | // Find a node in the tree |
| 274 | tree_node* findNode(const T& x) const |
| 275 | { |
| 276 | tree_node* node = find(x, m_root); |
| 277 | if (node) |
| 278 | { |
| 279 | return node; |
| 280 | } |
| 281 | else |
| 282 | { |
| 283 | return NULL; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | |
| 288 | // Insert item x into a subtree t (root) -- O(log n) |
| 289 | bool insert(const T& x, tree_node*& t) |
| 290 | { |
| 291 | if (t == NULL) |
| 292 | { |
| 293 | t = global_alloc(tree_node(x, NULL, NULL, NULL)); |
| 294 | |
| 295 | // An empty sub-tree here, insertion successful |
| 296 | return true; |
| 297 | } |
| 298 | else if (x < t->element) |
| 299 | { |
| 300 | // O(log n) |
| 301 | bool retVal = insert(x, t->left); |
| 302 | |
| 303 | if (retVal) |
| 304 | { |
| 305 | t->left->setParent(t); |
| 306 | t->calcHeights(); |
| 307 | |
| 308 | if(t->balanceFactor() < -1) |
| 309 | { |
| 310 | // See if it went left of the left |
| 311 | if(x < t->left->element) |
| 312 | { |
| 313 | rotateWithLeftChild(t); |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | // The element goes on the right of the left |
| 318 | doubleWithLeftChild(t); |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | return retVal; |
| 324 | } |
| 325 | else if (t->element < x) |
| 326 | { |
| 327 | bool retVal = insert(x, t->right); |
| 328 | |
| 329 | // Only do this if the insertion was successful |
| 330 | if (retVal) |
| 331 | { |
| 332 | t->right->setParent(t); |
| 333 | t->calcHeights(); |
| 334 | |
| 335 | if (t->balanceFactor() > 1) |
| 336 | { |
| 337 | // See if it went right of the right |
| 338 | if(t->right->element < x) |
| 339 | { |
| 340 | rotateWithRightChild(t); |
| 341 | } |
| 342 | else |
| 343 | { |
| 344 | // The element goes on the left of the right |
| 345 | doubleWithRightChild(t); |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | return retVal; |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | return false; // Duplicate |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | |
| 359 | // Recursively free all nodes in the tree -- O(n). |
| 360 | void clearRecurse(tree_node*& t) const |
| 361 | { |
| 362 | if(t != NULL) |
| 363 | { |
| 364 | clearRecurse(t->left); |
| 365 | clearRecurse(t->right); |
| 366 | |
| 367 | global_free(t); |
| 368 | } |
| 369 | t = NULL; |
| 370 | } |
| 371 | |
| 372 | |
| 373 | // Merge a tree with this one. Private because external care is required. |
| 374 | bool merge(tree_node* b, tree_node*& t) |
| 375 | { |
| 376 | if (!b) |
| 377 | { |
| 378 | return false; |
| 379 | } |
| 380 | else |
| 381 | { |
| 382 | bool retVal = false; |
| 383 | |
| 384 | if (t == NULL) |
| 385 | { |
| 386 | // Set this element to that subtree |
| 387 | t = b; |
| 388 | |
| 389 | // The parent here should be NULL anyway, but we |
| 390 | // set it just to be sure. This pointer will be |
| 391 | // used as a flag to indicate where in the call |
| 392 | // stack the tree was actually set. |
| 393 | // |
| 394 | // The middle layers of this method's call will |
| 395 | // all have their parent references in tact since |
| 396 | // no operations took place there. |
| 397 | // |
| 398 | //t->parent = NULL; |
| 399 | t->setParent(NULL); |
| 400 | |
| 401 | // We were successful in merging |
| 402 | retVal = true; |
| 403 | } |
| 404 | else if (b->element < t->element) |
| 405 | { |
| 406 | retVal = merge(b, t->left); |
| 407 | |
| 408 | // Only do this if the insertion actually took place |
| 409 | if (retVal && !t->left->parent) |
| 410 | { |
| 411 | t->left->setParent(t); |
| 412 | t->calcHeights(); |
| 413 | } |
| 414 | } |
| 415 | else if (t->element < b->element) |
| 416 | { |
| 417 | retVal = merge(b, t->right); |
| 418 | |
| 419 | // Only do this if the insertion was successful |
| 420 | if (retVal && !t->right->parent) |
| 421 | { |
| 422 | t->right->setParent(t); |
| 423 | t->calcHeights(); |
| 424 | } |
| 425 | |
| 426 | return retVal; |
| 427 | } |
| 428 | |
| 429 | return retVal; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | |
| 434 | // Find the smallest item's node in a subtree t -- O(log n). |
| 435 | tree_node* findMin(tree_node* t) const |
| 436 | { |
| 437 | if(t == NULL) |
| 438 | { |
| 439 | return t; |
| 440 | } |
| 441 | |
| 442 | while(t->left != NULL) |
| 443 | { |
| 444 | t = t->left; |
| 445 | } |
| 446 | |
| 447 | return t; |
| 448 | } |
| 449 | |
| 450 | |
| 451 | // Find the smallest item's node in a subtree t -- O(log n). |
| 452 | tree_node* findMax(tree_node* t) const |
| 453 | { |
| 454 | if(t == NULL) |
| 455 | { |
| 456 | return t; |
| 457 | } |
| 458 | |
| 459 | while(t->right != NULL) |
| 460 | { |
| 461 | t = t->right; |
| 462 | } |
| 463 | |
| 464 | return t; |
| 465 | } |
| 466 | |
| 467 | |
| 468 | // Find item x's node in subtree t -- O(log n) |
| 469 | tree_node* find(const T& x, tree_node* t) const |
| 470 | { |
| 471 | while(t != NULL) |
| 472 | { |
| 473 | if (x < t->element) |
| 474 | { |
| 475 | t = t->left; |
| 476 | } |
| 477 | else if (t->element < x) |
| 478 | { |
| 479 | t = t->right; |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | return t; // Match |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | return NULL; // No match |
| 488 | } |
| 489 | |
| 490 | |
| 491 | // Clone a subtree -- O(n) |
| 492 | tree_node* clone(const tree_node* t) const |
| 493 | { |
| 494 | if(t == NULL) |
| 495 | { |
| 496 | return NULL; |
| 497 | } |
| 498 | else |
| 499 | { |
| 500 | // Create a node with the left and right nodes and a parent set to NULL |
| 501 | tree_node* retVal = global_alloc(tree_node(t->element, NULL, clone(t->left), clone(t->right))); |
| 502 | |
| 503 | // Now set our children's parent node reference |
| 504 | if (retVal->left) { retVal->left->setParent(retVal); } |
| 505 | if (retVal->right) { retVal->right->setParent(retVal); } |
| 506 | |
| 507 | return retVal; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | |
| 512 | // Rotate binary tree node with left child. |
| 513 | // Single rotation for case 1 -- O(1). |
| 514 | void rotateWithLeftChild(tree_node*& k2) const |
| 515 | { |
| 516 | tree_node* k1 = k2->left; |
| 517 | tree_node* k2Parent = k2->parent; |
| 518 | |
| 519 | k2->setLeft(k1->right); |
| 520 | if (k2->left) { k2->left->setParent(k2); } |
| 521 | |
| 522 | k1->setRight(k2); |
| 523 | if (k1->right) { k1->right->setParent(k1); } |
| 524 | |
| 525 | k2 = k1; |
| 526 | k2->setParent(k2Parent); |
| 527 | |
| 528 | k2->right->calcHeights(); |
| 529 | |
| 530 | } |
| 531 | |
| 532 | |
| 533 | // Rotate binary tree node with right child. |
| 534 | // Single rotation for case 4 -- O(1). |
| 535 | void rotateWithRightChild(tree_node*& k1) const |
| 536 | { |
| 537 | tree_node* k2 = k1->right; |
| 538 | tree_node* k1Parent = k1->parent; |
| 539 | |
| 540 | k1->setRight(k2->left); |
| 541 | if (k1->right) { k1->right->setParent(k1); } |
| 542 | |
| 543 | k2->setLeft(k1); |
| 544 | if (k2->left) { k2->left->setParent(k2); } |
| 545 | |
| 546 | k1 = k2; |
| 547 | k1->setParent(k1Parent); |
| 548 | |
| 549 | k1->left->calcHeights(); |
| 550 | |
| 551 | } |
| 552 | |
| 553 | |
| 554 | // Double rotate binary tree node: first left child |
| 555 | // with its right child; then node k3 with new left child. |
| 556 | // Double rotation for case 2 -- O(1). |
| 557 | void doubleWithLeftChild(tree_node*& k3) const |
| 558 | { |
| 559 | rotateWithRightChild(k3->left); |
| 560 | rotateWithLeftChild(k3); |
| 561 | } |
| 562 | |
| 563 | |
| 564 | // Double rotate binary tree node: first right child |
| 565 | // with its left child; then node k1 with new right child. |
| 566 | // Double rotation for case 3 -- O(1). |
| 567 | void doubleWithRightChild(tree_node*& k1) const |
| 568 | { |
| 569 | rotateWithLeftChild(k1->right); |
| 570 | rotateWithRightChild(k1); |
| 571 | } |
| 572 | |
| 573 | |
| 574 | // Removes a node. Returns true if the node was on the left side of its parent -- O(1). |
| 575 | void removeNode(tree_node*& node) |
| 576 | { |
| 577 | // It is a leaf, simply remove the item and disconnect the parent |
| 578 | if (node->isLeft()) |
| 579 | { |
| 580 | node->parent->setLeft(NULL); |
| 581 | } |
| 582 | else // (node == node->parent->right) |
| 583 | { |
| 584 | if (node->parent) { node->parent->setRight(NULL); } |
| 585 | } |
| 586 | |
| 587 | node->setParent(NULL); |
| 588 | } |
| 589 | |
| 590 | |
| 591 | // Swap one node with another -- O(1). |
| 592 | void replaceNode(tree_node*& node1, tree_node*& node2) |
| 593 | { |
| 594 | // Save both parent references |
| 595 | simple_set<T>* node1Parent = node1->parent; |
| 596 | simple_set<T>* node2Parent = node2->parent; |
| 597 | |
| 598 | // First move node2 into node1's place |
| 599 | if (node1Parent) |
| 600 | { |
| 601 | if (isLeft(node1)) |
| 602 | { |
| 603 | node1Parent->setLeft(node2); |
| 604 | } |
| 605 | else // node1 is on the right |
| 606 | { |
| 607 | node1Parent->setRight(node2); |
| 608 | } |
| 609 | } |
| 610 | node2->setParent(node1Parent); |
| 611 | |
| 612 | // Now move node1 into node2's place |
| 613 | if (node2Parent) |
| 614 | { |
| 615 | if (isLeft(node2)) |
| 616 | { |
| 617 | node2Parent->setLeft(node1); |
| 618 | } |
| 619 | else // node2 is on the right |
| 620 | { |
| 621 | node2Parent->setRight(node1); |
| 622 | } |
| 623 | } |
| 624 | node1->setParent(node2Parent); |
| 625 | } |
| 626 | |
| 627 | |
| 628 | // Balances the tree starting at the root node |
| 629 | void balanceTree() { balanceTree(m_root); } |
| 630 | |
| 631 | |
| 632 | // Balance the tree starting at the given node -- O(n). |
| 633 | void balanceTree(tree_node*& node) |
| 634 | { |
| 635 | if (node) |
| 636 | { |
| 637 | // First see what the balance factor for this node is |
| 638 | int balFactor = node->balanceFactor(); |
| 639 | |
| 640 | if (balFactor < -1) |
| 641 | { |
| 642 | // See if we're heavy left of the left |
| 643 | if(node->left->balanceFactor() < 0) |
| 644 | { |
| 645 | rotateWithLeftChild(node); |
| 646 | } |
| 647 | else // if (node->left->balanceFactor() > 0) |
| 648 | { |
| 649 | // We're heavy on the right of the left |
| 650 | doubleWithLeftChild(node); |
| 651 | } |
| 652 | } |
| 653 | else if (balFactor > 1) |
| 654 | { |
| 655 | // See if it we're heavy right of the right |
| 656 | if(node->right->balanceFactor() > 0) |
| 657 | { |
| 658 | rotateWithRightChild(node); |
| 659 | } |
| 660 | else // if (node->right->balanceFactor() < 0) |
| 661 | { |
| 662 | // The element goes on the left of the right |
| 663 | doubleWithRightChild(node); |
| 664 | } |
| 665 | } |
| 666 | else // if (balFactor >= -1 && balFactor <= 1) |
| 667 | { |
| 668 | // We're balanced here, but are our children balanced? |
| 669 | balanceTree(node->left); |
| 670 | balanceTree(node->right); |
| 671 | } |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | |
| 676 | // Recursive helper function for public size() |
| 677 | int sizeRecurse(const tree_node* currentNode) const |
| 678 | { |
| 679 | int nodeCount = 1; |
| 680 | if (currentNode->left != NULL) |
| 681 | nodeCount += sizeRecurse(currentNode->left); |
| 682 | if (currentNode->right != NULL) |
| 683 | nodeCount += sizeRecurse(currentNode->right); |
| 684 | return nodeCount; |
| 685 | } |
| 686 | |
| 687 | |
| 688 | #ifdef SIMPLE_SET_DEBUG |
| 689 | // Debug. Print from the start node, down -- O(n log n). |
| 690 | void printTree(std::ostream& out, tree_node* t=NULL, int numTabs=0, char lr='_') const |
| 691 | { |
| 692 | if(t != NULL) |
| 693 | { |
| 694 | for (int i =0; i < numTabs; i++) { out << " "; } out << "|_" << lr << "__ "; |
| 695 | out << t->element << " {h = " << t->height() << ", b = " << t->balanceFactor() << "} "; |
| 696 | // TODO: Reinstate out << std::hex << t << " (p = " << t->parent << ")" << std::dec; |
| 697 | out << std::endl; |
| 698 | |
| 699 | printTree(out, t->left, numTabs + 1, '<'); |
| 700 | printTree(out, t->right, numTabs + 1, '>'); |
| 701 | } |
| 702 | } |
| 703 | #endif |
| 704 | }; |
| 705 | |
| 706 | |
| 707 | // |
| 708 | // ======================> avl_tree_node |
| 709 | // Member nodes of the simple_set's AVL tree |
| 710 | // |
| 711 | |
| 712 | template <class T> class avl_tree_node |
| 713 | { |
| 714 | friend class simple_set<T>; |
| 715 | friend class simple_set_iterator<T>; |
| 716 | typedef avl_tree_node<T> tree_node; |
| 717 | |
| 718 | public: |
| 719 | // Construction |
| 720 | avl_tree_node(const T& theElement, avl_tree_node* p, avl_tree_node* lt, avl_tree_node* rt) |
| 721 | : element(theElement), |
| 722 | parent(p), |
| 723 | left(lt), |
| 724 | right(rt), |
| 725 | m_height(1), |
| 726 | m_balanceFactor(0) |
| 727 | { } |
| 728 | |
| 729 | |
| 730 | // Are we to our parent's left? |
| 731 | bool isLeft() |
| 732 | { |
| 733 | if (parent && this == parent->left) |
| 734 | { |
| 735 | return true; |
| 736 | } |
| 737 | else |
| 738 | { |
| 739 | return false; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | |
| 744 | // Are we a leaf node? |
| 745 | bool isLeaf() { return !left && !right; } |
| 746 | |
| 747 | |
| 748 | // Set the parent pointer |
| 749 | void setParent(tree_node* p) |
| 750 | { |
| 751 | // Set our new parent |
| 752 | parent = p; |
| 753 | } |
| 754 | |
| 755 | |
| 756 | // Set the left child pointer |
| 757 | void setLeft(tree_node* l) |
| 758 | { |
| 759 | // Set our new left node |
| 760 | left = l; |
| 761 | } |
| 762 | |
| 763 | |
| 764 | // Set the right child pointer |
| 765 | void setRight(tree_node* r) |
| 766 | { |
| 767 | // Set our new right node |
| 768 | right = r; |
| 769 | } |
| 770 | |
| 771 | |
| 772 | // Recover the height |
| 773 | int height() const |
| 774 | { |
| 775 | // The height is equal to the maximum of the right or left side's height plus 1 |
| 776 | // Trading memory for operation time can be done O(n) like this => |
| 777 | // return max(left ? left->height() : 0, right ? right->height() : 0) + 1; |
| 778 | return m_height; |
| 779 | } |
| 780 | |
| 781 | |
| 782 | // Recover the balance factor |
| 783 | int balanceFactor() const |
| 784 | { |
| 785 | // The weight of a node is equal to the difference between |
| 786 | // the weight of the left subtree and the weight of the |
| 787 | // right subtree |
| 788 | // |
| 789 | // O(n) version => |
| 790 | // return (right ? right->height() : 0) - (left ? left->height() : 0); |
| 791 | // |
| 792 | return m_balanceFactor; |
| 793 | } |
| 794 | |
| 795 | |
| 796 | private: |
| 797 | // Calculates all of the heights for this node and its ancestors -- O(log n). |
| 798 | void calcHeights() |
| 799 | { |
| 800 | int rightHeight = (right ? right->m_height : 0); |
| 801 | int leftHeight = (left ? left->m_height : 0); |
| 802 | |
| 803 | // Calculate our own height and balance factor -- O(1) |
| 804 | m_height = maxInt(rightHeight, leftHeight) + 1; |
| 805 | m_balanceFactor = (rightHeight - leftHeight); |
| 806 | |
| 807 | // And our parent's height and balance factor (and recurse) -- O(log n) |
| 808 | if (parent) |
| 809 | { |
| 810 | parent->calcHeights(); |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | |
| 815 | // Utility function - TODO replace |
| 816 | int maxInt(const int& lhs, const int& rhs) const |
| 817 | { |
| 818 | return lhs > rhs ? lhs : rhs; |
| 819 | } |
| 820 | |
| 821 | |
| 822 | private: |
| 823 | T element; |
| 824 | |
| 825 | avl_tree_node* parent; |
| 826 | avl_tree_node* left; |
| 827 | avl_tree_node* right; |
| 828 | |
| 829 | int m_height; |
| 830 | int m_balanceFactor; |
| 831 | }; |
| 832 | |
| 833 | |
| 834 | // |
| 835 | // ======================> simple_set_iterator |
| 836 | // Iterator that allows for various set (AVL tree) navigation methods |
| 837 | // Points to elements of the set, rather than AVL tree nodes. |
| 838 | // |
| 839 | // PUBLIC OPERATIONS: |
| 840 | // current, first, last, next, count, indexof, byindex |
| 841 | // |
| 842 | |
| 843 | template <class T> |
| 844 | class simple_set_iterator |
| 845 | { |
| 846 | typedef avl_tree_node<T> tree_node; |
| 847 | |
| 848 | public: |
| 849 | enum TraversalType { PRE_ORDER, IN_ORDER, POST_ORDER, LEVEL_ORDER }; |
| 850 | |
| 851 | public: |
| 852 | // construction |
| 853 | simple_set_iterator(simple_set<T>& set, const TraversalType& tt=IN_ORDER) |
| 854 | : m_set(&set), |
| 855 | m_traversalType(tt), |
| 856 | m_currentNode(NULL), |
| 857 | m_endNode(NULL) { } |
| 858 | |
| 859 | ~simple_set_iterator() { } |
| 860 | |
| 861 | |
| 862 | // getters |
| 863 | T* current() const { return m_currentNode; } |
| 864 | |
| 865 | |
| 866 | // reset and return first item |
| 867 | T* first() |
| 868 | { |
| 869 | m_currentNode = m_set->m_root; |
| 870 | switch (m_traversalType) |
| 871 | { |
| 872 | case IN_ORDER: |
| 873 | { |
| 874 | // The current node is the smallest value |
| 875 | m_currentNode = m_set->findMin(m_set->m_root); |
| 876 | |
| 877 | // The end case is the largest value |
| 878 | m_endNode = m_set->findMax(m_set->m_root); |
| 879 | |
| 880 | return &m_currentNode->element; |
| 881 | } |
| 882 | |
| 883 | default: |
| 884 | { |
| 885 | // TODO (better error message): |
| 886 | printf("simple_set_iterator: Traversal type not yet supported.\n"); |
| 887 | return NULL; |
| 888 | } |
| 889 | } |
| 890 | return NULL; |
| 891 | } |
| 892 | |
| 893 | |
| 894 | T* last() |
| 895 | { |
| 896 | return NULL; |
| 897 | } |
| 898 | |
| 899 | |
| 900 | // advance according to current state and traversal type |
| 901 | T* next() |
| 902 | { |
| 903 | if (m_currentNode == NULL) return NULL; |
| 904 | |
| 905 | switch (m_traversalType) |
| 906 | { |
| 907 | case IN_ORDER: |
| 908 | { |
| 909 | // You are at the end |
| 910 | if (m_currentNode == m_endNode) |
| 911 | return NULL; |
| 912 | |
| 913 | if (m_currentNode->right != NULL) |
| 914 | { |
| 915 | // Gather the furthest left node of right subtree |
| 916 | m_currentNode = m_currentNode->right; |
| 917 | while (m_currentNode->left != NULL) |
| 918 | { |
| 919 | m_currentNode = m_currentNode->left; |
| 920 | } |
| 921 | } |
| 922 | else |
| 923 | { |
| 924 | // No right subtree? Move up the tree, looking for a left child link. |
| 925 | tree_node* p = m_currentNode->parent; |
| 926 | while (p != NULL && m_currentNode == p->right) |
| 927 | { |
| 928 | m_currentNode = p; |
| 929 | p = p->parent; |
| 930 | } |
| 931 | m_currentNode = p; |
| 932 | } |
| 933 | |
| 934 | return &m_currentNode->element; |
| 935 | } |
| 936 | |
| 937 | default: |
| 938 | { |
| 939 | // TODO (better error message): |
| 940 | printf("simple_set_iterator: Traversal type not yet supported.\n"); |
| 941 | return NULL; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | return NULL; |
| 946 | } |
| 947 | |
| 948 | |
| 949 | // return the number of items available |
| 950 | int count() |
| 951 | { |
| 952 | return m_set->size(); |
| 953 | } |
| 954 | |
| 955 | |
| 956 | // return the index of a given item in the virtual list |
| 957 | // note: this function is destructive to any in-progress iterations! |
| 958 | int indexof(T inData) |
| 959 | { |
| 960 | int index = 0; |
| 961 | for (T* data = first(); data != last(); data = next(), index++) |
| 962 | if (!(*data < inData) && !(inData < *data)) |
| 963 | return index; |
| 964 | return -1; |
| 965 | } |
| 966 | |
| 967 | |
| 968 | // return the indexed item in the list |
| 969 | // note: this function is destructive to any in-progress iterations! |
| 970 | T* byindex(int index) |
| 971 | { |
| 972 | int count = 0; |
| 973 | for (T* data = first(); data != last(); data = next(), count++) |
| 974 | if (count == index) |
| 975 | return data; |
| 976 | return NULL; |
| 977 | } |
| 978 | |
| 979 | |
| 980 | private: |
| 981 | simple_set<T>* m_set; |
| 982 | |
| 983 | TraversalType m_traversalType; |
| 984 | tree_node* m_currentNode; |
| 985 | tree_node* m_endNode; |
| 986 | }; |
| 987 | |
| 988 | #endif |
trunk/src/mame/drivers/bfm_sc45_helper.c
| r245617 | r245618 | |
| 237 | 237 | |
| 238 | 238 | |
| 239 | 239 | |
| 240 | | sc45helperlog("%s", tempstring.cstr()); |
| 240 | sc45helperlog("%s", tempstring.c_str()); |
| 241 | 241 | |
| 242 | 242 | sc45helperlog("\n"); |
| 243 | 243 | |
| r245617 | r245618 | |
| 316 | 316 | |
| 317 | 317 | if (ignoreports[i][j] > 0) |
| 318 | 318 | { |
| 319 | | printf(" PORT_BIT( 0x%04x, IP_ACTIVE_HIGH, SC45_BUTTON_MATRIX_%d_%d ) PORT_NAME(\"%s\")\n", 1 << j, i,j/*ignoreports[i][j]*/, sc4inputs[i][j].name.cstr()); |
| 319 | printf(" PORT_BIT( 0x%04x, IP_ACTIVE_HIGH, SC45_BUTTON_MATRIX_%d_%d ) PORT_NAME(\"%s\")\n", 1 << j, i,j/*ignoreports[i][j]*/, sc4inputs[i][j].name.c_str()); |
| 320 | 320 | buttons_used++; |
| 321 | 321 | } |
| 322 | 322 | else if (ignoreports[i][j] == -3) |
| 323 | 323 | { |
| 324 | | printf(" // 0x%04x - \"%s\" // standard input (motherboard)\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 324 | printf(" // 0x%04x - \"%s\" // standard input (motherboard)\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 325 | 325 | } |
| 326 | 326 | else if (ignoreports[i][j] == -2) |
| 327 | 327 | { |
| 328 | | printf(" // 0x%04x - \"%s\" // standard input (expected here)\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 328 | printf(" // 0x%04x - \"%s\" // standard input (expected here)\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 329 | 329 | } |
| 330 | 330 | else if (ignoreports[i][j] == -1) |
| 331 | 331 | { |
| 332 | | printf(" // 0x%04x - \"%s\" // unexpected here\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 332 | printf(" // 0x%04x - \"%s\" // unexpected here\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 333 | 333 | } |
| 334 | 334 | else if (ignoreports[i][j] == -4) |
| 335 | 335 | { |
| 336 | | printf(" // 0x%04x - \"%s\" // known extended input, mapping not understood\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 336 | printf(" // 0x%04x - \"%s\" // known extended input, mapping not understood\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 337 | 337 | } |
| 338 | 338 | else if (ignoreports[i][j] == -5) |
| 339 | 339 | { |
| 340 | | printf(" // 0x%04x - \"%s\" // known extended input, usually 'top up'\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 340 | printf(" // 0x%04x - \"%s\" // known extended input, usually 'top up'\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 341 | 341 | } |
| 342 | 342 | else if (ignoreports[i][j] == -6) |
| 343 | 343 | { |
| 344 | | printf(" // 0x%04x - \"%s\" // known extended input, usually 'hopper low'\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 344 | printf(" // 0x%04x - \"%s\" // known extended input, usually 'hopper low'\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 345 | 345 | } |
| 346 | 346 | else if (ignoreports[i][j] == -7) |
| 347 | 347 | { |
| 348 | | printf(" // 0x%04x - \"%s\" // known extended input, usually 'hopper fit'\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 348 | printf(" // 0x%04x - \"%s\" // known extended input, usually 'hopper fit'\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 349 | 349 | } |
| 350 | 350 | else if (ignoreports[i][j] == -8) |
| 351 | 351 | { |
| 352 | | printf(" // 0x%04x - \"%s\" // known extended(?) input, sometimes 'top up'\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 352 | printf(" // 0x%04x - \"%s\" // known extended(?) input, sometimes 'top up'\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 353 | 353 | } |
| 354 | 354 | else if (ignoreports[i][j] == -9) |
| 355 | 355 | { |
| 356 | | printf(" // 0x%04x - \"%s\" // known extended(?) input, sometimes 'hop hi'\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 356 | printf(" // 0x%04x - \"%s\" // known extended(?) input, sometimes 'hop hi'\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 357 | 357 | } |
| 358 | 358 | else if (ignoreports[i][j] == -10) |
| 359 | 359 | { |
| 360 | | printf(" // 0x%04x - \"%s\" // known extended(?) input, sometimes 'hop top'\n", 1 << j, sc4inputs[i][j].name.cstr()); |
| 360 | printf(" // 0x%04x - \"%s\" // known extended(?) input, sometimes 'hop top'\n", 1 << j, sc4inputs[i][j].name.c_str()); |
| 361 | 361 | } |
| 362 | 362 | buttons_used++; |
| 363 | 363 | } |
| r245617 | r245618 | |
| 390 | 390 | { |
| 391 | 391 | for (int x = 0; x < 16; x++) |
| 392 | 392 | { |
| 393 | | if (!strcmp(teststring.cstr(), lamps[y][x].lampname_alt.cstr())) |
| 393 | if (!strcmp(teststring.c_str(), lamps[y][x].lampname_alt.c_str())) |
| 394 | 394 | { |
| 395 | 395 | lamps[y][x].clickport = clickport; |
| 396 | 396 | lamps[y][x].clickmask = clickmask; |
| r245617 | r245618 | |
| 507 | 507 | fatalerror("duplicate lamp?\n"); |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | | //sc45helperlog("%s", tempstring.cstr()); |
| 510 | //sc45helperlog("%s", tempstring.c_str()); |
| 511 | 511 | |
| 512 | 512 | //sc45helperlog("\n"); |
| 513 | 513 | |
| r245617 | r245618 | |
| 521 | 521 | //sc45helperlog("---ROW %02d---\n", y); |
| 522 | 522 | for (int x = 0; x < 16; x++) |
| 523 | 523 | { |
| 524 | | sc45helperlog("<element name=\"lamplabelel%d\"><text string=\"%s\"><color red=\"1.0\" green=\"1.0\" blue=\"1.0\" /></text></element>\n", d, lamps[y][x].lampname.cstr()); |
| 524 | sc45helperlog("<element name=\"lamplabelel%d\"><text string=\"%s\"><color red=\"1.0\" green=\"1.0\" blue=\"1.0\" /></text></element>\n", d, lamps[y][x].lampname.c_str()); |
| 525 | 525 | d++; |
| 526 | 526 | } |
| 527 | 527 | } |
| r245617 | r245618 | |
| 536 | 536 | |
| 537 | 537 | for (int x = 0; x < 6; x++) |
| 538 | 538 | { |
| 539 | | sc45helperlog("<element name=\"inputlabel%d-%d\"><text string=\"%s\"><color red=\"1.0\" green=\"1.0\" blue=\"1.0\" /></text></element>\n", realy,x,sc4inputs[realy][x].name.cstr()); |
| 539 | sc45helperlog("<element name=\"inputlabel%d-%d\"><text string=\"%s\"><color red=\"1.0\" green=\"1.0\" blue=\"1.0\" /></text></element>\n", realy,x,sc4inputs[realy][x].name.c_str()); |
| 540 | 540 | |
| 541 | 541 | } |
| 542 | 542 | } |
| r245617 | r245618 | |
| 593 | 593 | { |
| 594 | 594 | lamps[y][x].lampname_alt = lamps[y][x].lampname; |
| 595 | 595 | |
| 596 | | if (!strcmp(lamps[y][x].lampname_alt.cstr(), "hold2/hi")) lamps[y][x].lampname_alt = "hold2"; |
| 597 | | if (!strcmp(lamps[y][x].lampname_alt.cstr(), "hold3/lo")) lamps[y][x].lampname_alt = "hold3"; |
| 598 | | if (!strcmp(lamps[y][x].lampname_alt.cstr(), "chg stake")) lamps[y][x].lampname_alt = "chnge stk"; |
| 599 | | if (!strcmp(lamps[y][x].lampname_alt.cstr(), "canc/coll")) lamps[y][x].lampname_alt = "cancel"; |
| 600 | | if (!strcmp(lamps[y][x].lampname_alt.cstr(), "start")) lamps[y][x].lampname_alt = "strt exch"; |
| 596 | if (!strcmp(lamps[y][x].lampname_alt.c_str(), "hold2/hi")) lamps[y][x].lampname_alt = "hold2"; |
| 597 | if (!strcmp(lamps[y][x].lampname_alt.c_str(), "hold3/lo")) lamps[y][x].lampname_alt = "hold3"; |
| 598 | if (!strcmp(lamps[y][x].lampname_alt.c_str(), "chg stake")) lamps[y][x].lampname_alt = "chnge stk"; |
| 599 | if (!strcmp(lamps[y][x].lampname_alt.c_str(), "canc/coll")) lamps[y][x].lampname_alt = "cancel"; |
| 600 | if (!strcmp(lamps[y][x].lampname_alt.c_str(), "start")) lamps[y][x].lampname_alt = "strt exch"; |
| 601 | 601 | |
| 602 | 602 | } |
| 603 | 603 | } |
| r245617 | r245618 | |
| 625 | 625 | { |
| 626 | 626 | for (int x = 0; x < 16; x++) |
| 627 | 627 | { |
| 628 | | if (!strcmp(tempname2, lamps[y][x].lampname_alt.cstr())) |
| 628 | if (!strcmp(tempname2, lamps[y][x].lampname_alt.c_str())) |
| 629 | 629 | { |
| 630 | 630 | //sc45helperlog("%s found\n", tempname2); |
| 631 | 631 | lamps[y][x].draw_label = false; |
| r245617 | r245618 | |
| 640 | 640 | } |
| 641 | 641 | else |
| 642 | 642 | { |
| 643 | | //printf("%s:%s:\n", tempname2, lamps[y][x].lampname_alt.cstr()); |
| 643 | //printf("%s:%s:\n", tempname2, lamps[y][x].lampname_alt.c_str()); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | } |
| r245617 | r245618 | |
| 679 | 679 | //sc45helperlog("---ROW %02d---\n", y); |
| 680 | 680 | for (int x = 0; x < 16; x++) |
| 681 | 681 | { |
| 682 | | if (lamps[y][x].clickport== -1) sc45helperlog("<bezel name=\"lamp%d\" element=\"%s\" state=\"0\"><bounds x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/></bezel>\n", d, lamps[y][x].lamptypename.cstr(), lamps[y][x].x, lamps[y][x].y, lamps[y][x].width, lamps[y][x].height); |
| 683 | | else sc45helperlog("<bezel name=\"lamp%d\" element=\"%s\" state=\"0\" inputtag=\"IN-%d\" inputmask=\"0x%02x\"><bounds x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" /></bezel>\n", d, lamps[y][x].lamptypename.cstr(), lamps[y][x].clickport, lamps[y][x].clickmask, lamps[y][x].x, lamps[y][x].y, lamps[y][x].width, lamps[y][x].height); |
| 682 | if (lamps[y][x].clickport== -1) sc45helperlog("<bezel name=\"lamp%d\" element=\"%s\" state=\"0\"><bounds x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\"/></bezel>\n", d, lamps[y][x].lamptypename.c_str(), lamps[y][x].x, lamps[y][x].y, lamps[y][x].width, lamps[y][x].height); |
| 683 | else sc45helperlog("<bezel name=\"lamp%d\" element=\"%s\" state=\"0\" inputtag=\"IN-%d\" inputmask=\"0x%02x\"><bounds x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" /></bezel>\n", d, lamps[y][x].lamptypename.c_str(), lamps[y][x].clickport, lamps[y][x].clickmask, lamps[y][x].x, lamps[y][x].y, lamps[y][x].width, lamps[y][x].height); |
| 684 | 684 | |
| 685 | 685 | if (lamps[y][x].draw_label == false) sc45helperlog("<!-- Label not drawn\n"); |
| 686 | 686 | sc45helperlog("<bezel name=\"lamplabel%d\" element=\"lamplabelel%d\"><bounds x=\"%d\" y=\"%d\" width=\"%d\" height=\"10\" /></bezel>\n", d,d, lamps[y][x].x, lamps[y][x].y-10, lamps[y][x].width); |
| r245617 | r245618 | |
| 905 | 905 | tempstring.cat("PND"); |
| 906 | 906 | } |
| 907 | 907 | |
| 908 | | sc45helperlog("%s", tempstring.cstr()); |
| 908 | sc45helperlog("%s", tempstring.c_str()); |
| 909 | 909 | |
| 910 | 910 | |
| 911 | 911 | |
trunk/src/mess/drivers/hh_ucom4.c
| r245617 | r245618 | |
| 12 | 12 | @031 uPD553C 1979, Bambino Superstar Football (ET-03) |
| 13 | 13 | *042 uPD552C 1979, Tomy Space Attack |
| 14 | 14 | @048 uPD552C 1980, Tomy Tennis (TN-04) |
| 15 | | @049 uPD553C 1979, Mego Mini-Vid Break Free |
| 16 | 15 | @055 uPD553C 1980, Bambino Laser Fight (ET-12) |
| 17 | 16 | *085 uPD650C 1980, Roland TR-808 |
| 18 | 17 | *102 uPD553C 1981, Bandai Block Out |
| r245617 | r245618 | |
| 20 | 19 | *128 uPD650C 1982, Roland TR-606 |
| 21 | 20 | 133 uPD650C 1982, Roland TB-303 -> tb303.c |
| 22 | 21 | @160 uPD553C 1982, Tomy Pac Man (TN-08) |
| 23 | | @192 uPD553C 1982, Tomy Scramble (TN-10) |
| 24 | 22 | @202 uPD553C 1982, Epoch Astro Command |
| 25 | 23 | @206 uPD553C 1982, Epoch Dracula |
| 26 | | @209 uPD553C 1982, Tomy Caveman (TN-12) |
| 24 | *209 uPD553C 1982, Tomy Caveman (TN-12) |
| 27 | 25 | @258 uPD553C 1984, Tomy Alien Chase (TN-16) |
| 28 | 26 | |
| 29 | 27 | (* denotes not yet emulated by MESS, @ denotes it's in this driver) |
| 30 | 28 | |
| 31 | 29 | ***************************************************************************/ |
| 32 | 30 | |
| 33 | | |
| 34 | | |
| 35 | | |
| 36 | | /*************************************************************************** |
| 37 | | |
| 38 | | Mego Mini-Vid Break Free (manufactured in Japan) |
| 39 | | * PCB label Mego 79 rev F |
| 40 | | * NEC uCOM-43 MCU, labeled D553C 031 |
| 41 | | * cyan VFD display Futaba DM-4.5 91 |
| 42 | | |
| 43 | | NOTE!: MESS external artwork is recommended |
| 44 | | |
| 45 | | ***************************************************************************/ |
| 46 | | |
| 47 | | |
| 48 | | /*************************************************************************** |
| 49 | | |
| 50 | | Tomy(tronic) Caveman (manufactured in Japan) |
| 51 | | * PCBs are labeled TN-12 2E114E03 |
| 52 | | * NEC uCOM-43 MCU, labeled D553C 209 |
| 53 | | * cyan/red/green VFD display NEC FIP8AM20T no. 2-42 |
| 54 | | |
| 55 | | NOTE!: MESS external artwork is recommended |
| 56 | | |
| 57 | | ***************************************************************************/ |
| 58 | | |
| 59 | | |
| 60 | | /*************************************************************************** |
| 61 | | |
| 62 | | Tomy(tronic) Scramble (manufactured in Japan) |
| 63 | | * PCBs are labeled TN-10 2E114E01 |
| 64 | | * NEC uCOM-43 MCU, labeled D553C 192 |
| 65 | | * cyan/red/green VFD display NEC FIP10CM20T no. 2-41 |
| 66 | | |
| 67 | | NOTE!: MESS external artwork is recommended |
| 68 | | |
| 69 | | ***************************************************************************/ |
| 70 | | |
| 71 | | |
| 72 | 31 | #include "emu.h" |
| 73 | 32 | #include "cpu/ucom4/ucom4.h" |
| 74 | 33 | #include "sound/speaker.h" |
| r245617 | r245618 | |
| 556 | 515 | Epoch Astro Command (manufactured in Japan) |
| 557 | 516 | * PCB label 96111 |
| 558 | 517 | * NEC uCOM-43 MCU, labeled D553C 202 |
| 559 | | * cyan/red VFD display NEC FIP9AM20T no. 42-42, with color overlay (FIP=fluorescent indicator panel) |
| 518 | * cyan/red VFD display NEC FIP9AM20T NO.42, with color overlay |
| 560 | 519 | |
| 561 | 520 | known releases: |
| 562 | 521 | - Japan: Astro Command |
| r245617 | r245618 | |
| 665 | 624 | Epoch Dracula (manufactured in Japan) |
| 666 | 625 | * PCB label 96121 |
| 667 | 626 | * NEC uCOM-43 MCU, labeled D553C 206 |
| 668 | | * cyan/red/green VFD display NEC FIP8BM20T no. 2-42 |
| 627 | * cyan/red/green VFD display NEC FIP8BM20T (FIP=fluorescent indicator panel) |
| 669 | 628 | |
| 670 | 629 | known releases: |
| 671 | 630 | - Japan: Dracula House, yellow case |
| r245617 | r245618 | |
| 758 | 717 | /*************************************************************************** |
| 759 | 718 | |
| 760 | 719 | Tomy(tronic) Tennis (manufactured in Japan) |
| 761 | | * PCB labeled TOMY TN-04 TENNIS |
| 720 | * board labeled TOMY TN-04 TENNIS |
| 762 | 721 | * NEC uCOM-44 MCU, labeled D552C 048 |
| 763 | | * VFD display NEC FIP11AM15T tube no. 0F |
| 722 | * VFD display NEC FIP11AM15T |
| 764 | 723 | |
| 765 | 724 | The initial release of this game was in 1979, known as Pro-Tennis, |
| 766 | 725 | it has a D553 instead of D552, with just a little over 50% ROM used. |
| r245617 | r245618 | |
| 917 | 876 | /*************************************************************************** |
| 918 | 877 | |
| 919 | 878 | Tomy(tronic) Pac-Man (manufactured in Japan) |
| 920 | | * PCBs are labeled TN-08 2E108E01 |
| 879 | * boards are labeled TN-08 2E108E01 |
| 921 | 880 | * NEC uCOM-43 MCU, labeled D553C 160 |
| 922 | | * cyan/red/green VFD display NEC FIP8AM18T no. 2-21 |
| 881 | * cyan/red/green VFD display NEC FIP8AM18T |
| 923 | 882 | * bright yellow round casing |
| 924 | 883 | |
| 925 | 884 | known releases: |
| r245617 | r245618 | |
| 1025 | 984 | /*************************************************************************** |
| 1026 | 985 | |
| 1027 | 986 | Tomy Alien Chase (manufactured in Japan) |
| 1028 | | * PCBs are labeled TN-16 2E121B01 |
| 987 | * boards are labeled TN-16 2E121B01 |
| 1029 | 988 | * NEC uCOM-43 MCU, labeled D553C 258 |
| 1030 | 989 | * red/green VFD display NEC FIP9AM24T, with color overlay, 2-sided* |
| 1031 | 990 | |
trunk/src/osd/sdl/input.c
| r245617 | r245618 | |
| 742 | 742 | |
| 743 | 743 | devinfo->joystick.device = joy; |
| 744 | 744 | |
| 745 | | osd_printf_verbose("Joystick: %s\n", devinfo->name.cstr()); |
| 745 | osd_printf_verbose("Joystick: %s\n", devinfo->name.c_str()); |
| 746 | 746 | osd_printf_verbose("Joystick: ... %d axes, %d buttons %d hats %d balls\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy), SDL_JoystickNumBalls(joy)); |
| 747 | 747 | osd_printf_verbose("Joystick: ... Physical id %d mapped to logical id %d\n", physical_stick, stick + 1); |
| 748 | 748 | |
| r245617 | r245618 | |
| 758 | 758 | else |
| 759 | 759 | itemid = ITEM_ID_OTHER_AXIS_ABSOLUTE; |
| 760 | 760 | |
| 761 | | sprintf(tempname, "A%d %s", axis, devinfo->name.cstr()); |
| 761 | sprintf(tempname, "A%d %s", axis, devinfo->name.c_str()); |
| 762 | 762 | devinfo->device->add_item(tempname, itemid, generic_axis_get_state, &devinfo->joystick.axes[axis]); |
| 763 | 763 | } |
| 764 | 764 | |
| r245617 | r245618 | |
| 809 | 809 | else |
| 810 | 810 | itemid = ITEM_ID_OTHER_AXIS_RELATIVE; |
| 811 | 811 | |
| 812 | | sprintf(tempname, "R%d %s", ball * 2, devinfo->name.cstr()); |
| 812 | sprintf(tempname, "R%d %s", ball * 2, devinfo->name.c_str()); |
| 813 | 813 | devinfo->device->add_item(tempname, (input_item_id) itemid, generic_axis_get_state, &devinfo->joystick.balls[ball * 2]); |
| 814 | | sprintf(tempname, "R%d %s", ball * 2 + 1, devinfo->name.cstr()); |
| 814 | sprintf(tempname, "R%d %s", ball * 2 + 1, devinfo->name.c_str()); |
| 815 | 815 | devinfo->device->add_item(tempname, (input_item_id) (itemid + 1), generic_axis_get_state, &devinfo->joystick.balls[ball * 2 + 1]); |
| 816 | 816 | } |
| 817 | 817 | } |
| r245617 | r245618 | |
| 869 | 869 | continue; |
| 870 | 870 | |
| 871 | 871 | // add the axes |
| 872 | | sprintf(defname, "X %s", devinfo->name.cstr()); |
| 872 | sprintf(defname, "X %s", devinfo->name.c_str()); |
| 873 | 873 | devinfo->device->add_item(defname, ITEM_ID_XAXIS, generic_axis_get_state, &devinfo->mouse.lX); |
| 874 | | sprintf(defname, "Y %s", devinfo->name.cstr()); |
| 874 | sprintf(defname, "Y %s", devinfo->name.c_str()); |
| 875 | 875 | devinfo->device->add_item(defname, ITEM_ID_YAXIS, generic_axis_get_state, &devinfo->mouse.lY); |
| 876 | 876 | |
| 877 | 877 | for (button = 0; button < 4; button++) |
| r245617 | r245618 | |
| 886 | 886 | |
| 887 | 887 | if (0 && mouse_enabled) |
| 888 | 888 | SDL_SetRelativeMouseMode(index, SDL_TRUE); |
| 889 | | osd_printf_verbose("Mouse: Registered %s\n", devinfo->name.cstr()); |
| 889 | osd_printf_verbose("Mouse: Registered %s\n", devinfo->name.c_str()); |
| 890 | 890 | } |
| 891 | 891 | osd_printf_verbose("Mouse: End initialization\n"); |
| 892 | 892 | } |
| r245617 | r245618 | |
| 903 | 903 | |
| 904 | 904 | // SDL 1.2 has only 1 mouse - 1.3+ will also change that, so revisit this then |
| 905 | 905 | devinfo = generic_device_alloc(&mouse_list, "System mouse"); |
| 906 | | devinfo->device = machine.input().device_class(DEVICE_CLASS_MOUSE).add_device(devinfo->name.cstr(), devinfo); |
| 906 | devinfo->device = machine.input().device_class(DEVICE_CLASS_MOUSE).add_device(devinfo->name.c_str(), devinfo); |
| 907 | 907 | |
| 908 | 908 | mouse_enabled = machine.options().mouse(); |
| 909 | 909 | |
| r245617 | r245618 | |
| 919 | 919 | devinfo->device->add_item(defname, itemid, generic_button_get_state, &devinfo->mouse.buttons[button]); |
| 920 | 920 | } |
| 921 | 921 | |
| 922 | | osd_printf_verbose("Mouse: Registered %s\n", devinfo->name.cstr()); |
| 922 | osd_printf_verbose("Mouse: Registered %s\n", devinfo->name.c_str()); |
| 923 | 923 | osd_printf_verbose("Mouse: End initialization\n"); |
| 924 | 924 | } |
| 925 | 925 | #endif |
| r245617 | r245618 | |
| 1126 | 1126 | } |
| 1127 | 1127 | |
| 1128 | 1128 | |
| 1129 | | sprintf(defname, "X %s", devinfo->name.cstr()); |
| 1129 | sprintf(defname, "X %s", devinfo->name.c_str()); |
| 1130 | 1130 | devinfo->device->add_item(defname, ITEM_ID_XAXIS, generic_axis_get_state, &devinfo->lightgun.lX); |
| 1131 | | sprintf(defname, "Y %s", devinfo->name.cstr()); |
| 1131 | sprintf(defname, "Y %s", devinfo->name.c_str()); |
| 1132 | 1132 | devinfo->device->add_item(defname, ITEM_ID_YAXIS, generic_axis_get_state, &devinfo->lightgun.lY); |
| 1133 | 1133 | |
| 1134 | 1134 | |
| r245617 | r245618 | |
| 1325 | 1325 | devinfo->device->add_item(defname, itemid, generic_button_get_state, &devinfo->keyboard.state[OSD_SDL_INDEX(key_trans_table[keynum].sdl_key)]); |
| 1326 | 1326 | } |
| 1327 | 1327 | |
| 1328 | | osd_printf_verbose("Keyboard: Registered %s\n", devinfo->name.cstr()); |
| 1328 | osd_printf_verbose("Keyboard: Registered %s\n", devinfo->name.c_str()); |
| 1329 | 1329 | } |
| 1330 | 1330 | osd_printf_verbose("Keyboard: End initialization\n"); |
| 1331 | 1331 | } |
| r245617 | r245618 | |
| 1346 | 1346 | // SDL 1.2 only has 1 keyboard (1.3+ will have multiple, this must be revisited then) |
| 1347 | 1347 | // add it now |
| 1348 | 1348 | devinfo = generic_device_alloc(&keyboard_list, "System keyboard"); |
| 1349 | | devinfo->device = machine.input().device_class(DEVICE_CLASS_KEYBOARD).add_device(devinfo->name.cstr(), devinfo); |
| 1349 | devinfo->device = machine.input().device_class(DEVICE_CLASS_KEYBOARD).add_device(devinfo->name.c_str(), devinfo); |
| 1350 | 1350 | |
| 1351 | 1351 | // populate it |
| 1352 | 1352 | for (keynum = 0; sdl_key_trans_table[keynum].mame_key != ITEM_ID_INVALID; keynum++) |
| r245617 | r245618 | |
| 1363 | 1363 | devinfo->device->add_item(defname, itemid, generic_button_get_state, &devinfo->keyboard.state[OSD_SDL_INDEX(key_trans_table[keynum].sdl_key)]); |
| 1364 | 1364 | } |
| 1365 | 1365 | |
| 1366 | | osd_printf_verbose("Keyboard: Registered %s\n", devinfo->name.cstr()); |
| 1366 | osd_printf_verbose("Keyboard: Registered %s\n", devinfo->name.c_str()); |
| 1367 | 1367 | osd_printf_verbose("Keyboard: End initialization\n"); |
| 1368 | 1368 | } |
| 1369 | 1369 | #endif |
| r245617 | r245618 | |
| 1742 | 1742 | case SDL_KEYDOWN: |
| 1743 | 1743 | #ifdef SDL2_MULTIAPI |
| 1744 | 1744 | devinfo = generic_device_find_index( keyboard_list, keyboard_map.logical[event.key.which]); |
| 1745 | | //printf("Key down %d %d %s => %d %s (scrlock keycode is %d)\n", event.key.which, event.key.keysym.scancode, devinfo->name.cstr(), OSD_SDL_INDEX_KEYSYM(&event.key.keysym), sdl_key_trans_table[event.key.keysym.scancode].mame_key_name, KEYCODE_SCRLOCK); |
| 1745 | //printf("Key down %d %d %s => %d %s (scrlock keycode is %d)\n", event.key.which, event.key.keysym.scancode, devinfo->name.c_str(), OSD_SDL_INDEX_KEYSYM(&event.key.keysym), sdl_key_trans_table[event.key.keysym.scancode].mame_key_name, KEYCODE_SCRLOCK); |
| 1746 | 1746 | #else |
| 1747 | 1747 | devinfo = generic_device_find_index( keyboard_list, keyboard_map.logical[0]); |
| 1748 | 1748 | #endif |
| r245617 | r245618 | |
| 1841 | 1841 | devinfo = generic_device_find_index(mouse_list, mouse_map.logical[0]); |
| 1842 | 1842 | #endif |
| 1843 | 1843 | devinfo->mouse.buttons[event.button.button-1] = 0x80; |
| 1844 | | //printf("But down %d %d %d %d %s\n", event.button.which, event.button.button, event.button.x, event.button.y, devinfo->name.cstr()); |
| 1844 | //printf("But down %d %d %d %d %s\n", event.button.which, event.button.button, event.button.x, event.button.y, devinfo->name.c_str()); |
| 1845 | 1845 | if (event.button.button == 1) |
| 1846 | 1846 | { |
| 1847 | 1847 | // FIXME Move static declaration |
| r245617 | r245618 | |
| 1899 | 1899 | #endif |
| 1900 | 1900 | #if (SDLMAME_SDL2) |
| 1901 | 1901 | // FIXME: may apply to 1.2 as well ... |
| 1902 | | //printf("Motion %d %d %d %s\n", event.motion.which, event.motion.x, event.motion.y, devinfo->name.cstr()); |
| 1902 | //printf("Motion %d %d %d %s\n", event.motion.which, event.motion.x, event.motion.y, devinfo->name.c_str()); |
| 1903 | 1903 | devinfo->mouse.lX += event.motion.xrel * INPUT_RELATIVE_PER_PIXEL; |
| 1904 | 1904 | devinfo->mouse.lY += event.motion.yrel * INPUT_RELATIVE_PER_PIXEL; |
| 1905 | 1905 | #else |
trunk/src/tools/chdman.c
| r245617 | r245618 | |
| 327 | 327 | m_lastfile = m_info.track[tracknum].fname; |
| 328 | 328 | file_error filerr = core_fopen(m_lastfile, OPEN_FLAG_READ, &m_file); |
| 329 | 329 | if (filerr != FILERR_NONE) |
| 330 | | report_error(1, "Error opening input file (%s)'", m_lastfile.cstr()); |
| 330 | report_error(1, "Error opening input file (%s)'", m_lastfile.c_str()); |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // iterate over frames |
| r245617 | r245618 | |
| 351 | 351 | core_fseek(m_file, src_frame_start, SEEK_SET); |
| 352 | 352 | UINT32 count = core_fread(m_file, dest, bytesperframe); |
| 353 | 353 | if (count != bytesperframe) |
| 354 | | report_error(1, "Error reading input file (%s)'", m_lastfile.cstr()); |
| 354 | report_error(1, "Error reading input file (%s)'", m_lastfile.c_str()); |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | // swap if appropriate |
| r245617 | r245618 | |
| 940 | 940 | { |
| 941 | 941 | chd_error err = input_parent_chd.open(*input_chd_parent_str); |
| 942 | 942 | if (err != CHDERR_NONE) |
| 943 | | report_error(1, "Error opening parent CHD file (%s): %s", input_chd_parent_str->cstr(), chd_file::error_string(err)); |
| 943 | report_error(1, "Error opening parent CHD file (%s): %s", input_chd_parent_str->c_str(), chd_file::error_string(err)); |
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | // process input file |
| r245617 | r245618 | |
| 949 | 949 | { |
| 950 | 950 | chd_error err = input_chd.open(*input_chd_str, writeable, input_parent_chd.opened() ? &input_parent_chd : NULL); |
| 951 | 951 | if (err != CHDERR_NONE) |
| 952 | | report_error(1, "Error opening CHD file (%s): %s", input_chd_str->cstr(), chd_file::error_string(err)); |
| 952 | report_error(1, "Error opening CHD file (%s): %s", input_chd_str->c_str(), chd_file::error_string(err)); |
| 953 | 953 | } |
| 954 | 954 | } |
| 955 | 955 | |
| r245617 | r245618 | |
| 1028 | 1028 | { |
| 1029 | 1029 | chd_error err = output_parent_chd.open(*output_chd_parent_str); |
| 1030 | 1030 | if (err != CHDERR_NONE) |
| 1031 | | report_error(1, "Error opening parent CHD file (%s): %s", output_chd_parent_str->cstr(), chd_file::error_string(err)); |
| 1031 | report_error(1, "Error opening parent CHD file (%s): %s", output_chd_parent_str->c_str(), chd_file::error_string(err)); |
| 1032 | 1032 | } |
| 1033 | 1033 | |
| 1034 | 1034 | // process output file |
| r245617 | r245618 | |
| 1083 | 1083 | { |
| 1084 | 1084 | astring name(*compression_str, start, (end == -1) ? -1 : end - start); |
| 1085 | 1085 | if (name.len() != 4) |
| 1086 | | report_error(1, "Invalid compressor '%s' specified", name.cstr()); |
| 1086 | report_error(1, "Invalid compressor '%s' specified", name.c_str()); |
| 1087 | 1087 | chd_codec_type type = CHD_MAKE_TAG(name[0], name[1], name[2], name[3]); |
| 1088 | 1088 | if (!chd_codec_list::codec_exists(type)) |
| 1089 | | report_error(1, "Invalid compressor '%s' specified", name.cstr()); |
| 1089 | report_error(1, "Invalid compressor '%s' specified", name.c_str()); |
| 1090 | 1090 | compression[index++] = type; |
| 1091 | 1091 | if (end == -1) |
| 1092 | 1092 | break; |
| r245617 | r245618 | |
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | // output TRACK entry |
| 1261 | | core_fprintf(file, " TRACK %02d %s\n", tracknum + 1, tempstr.cstr()); |
| 1261 | core_fprintf(file, " TRACK %02d %s\n", tracknum + 1, tempstr.c_str()); |
| 1262 | 1262 | |
| 1263 | 1263 | // output PREGAP tag if pregap sectors are not in the file |
| 1264 | 1264 | if ((info.pregap > 0) && (info.pgdatasize == 0)) |
| r245617 | r245618 | |
| 1296 | 1296 | modesubmode.format("%s %s", cdrom_get_type_string(info.trktype), cdrom_get_subtype_string(info.subtype)); |
| 1297 | 1297 | else |
| 1298 | 1298 | modesubmode.format("%s", cdrom_get_type_string(info.trktype)); |
| 1299 | | core_fprintf(file, "TRACK %s\n", modesubmode.cstr()); |
| 1299 | core_fprintf(file, "TRACK %s\n", modesubmode.c_str()); |
| 1300 | 1300 | |
| 1301 | 1301 | // write out the attributes |
| 1302 | 1302 | core_fprintf(file, "NO COPY\n"); |
| r245617 | r245618 | |
| 1309 | 1309 | // output pregap |
| 1310 | 1310 | astring tempstr; |
| 1311 | 1311 | if (info.pregap > 0) |
| 1312 | | core_fprintf(file, "ZERO %s %s\n", modesubmode.cstr(), msf_string_from_frames(tempstr, info.pregap)); |
| 1312 | core_fprintf(file, "ZERO %s %s\n", modesubmode.c_str(), msf_string_from_frames(tempstr, info.pregap)); |
| 1313 | 1313 | |
| 1314 | 1314 | // all tracks but the first one have a file offset |
| 1315 | 1315 | if (tracknum > 0) |
| r245617 | r245618 | |
| 1340 | 1340 | |
| 1341 | 1341 | // print filename and version |
| 1342 | 1342 | astring tempstr; |
| 1343 | | printf("Input file: %s\n", params.find(OPTION_INPUT)->cstr()); |
| 1343 | printf("Input file: %s\n", params.find(OPTION_INPUT)->c_str()); |
| 1344 | 1344 | printf("File Version: %d\n", input_chd.version()); |
| 1345 | 1345 | if (input_chd.version() < 3) |
| 1346 | 1346 | report_error(1, "Unsupported version (%d); use an older chdman to upgrade to version 3 or later", input_chd.version()); |
| r245617 | r245618 | |
| 1504 | 1504 | UINT32 bytes_to_read = MIN((UINT32)buffer.count(), input_chd.logical_bytes() - offset); |
| 1505 | 1505 | chd_error err = input_chd.read_bytes(offset, buffer, bytes_to_read); |
| 1506 | 1506 | if (err != CHDERR_NONE) |
| 1507 | | report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->cstr(), chd_file::error_string(err)); |
| 1507 | report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->c_str(), chd_file::error_string(err)); |
| 1508 | 1508 | |
| 1509 | 1509 | // add to the checksum |
| 1510 | 1510 | rawsha1.append(buffer, bytes_to_read); |
| r245617 | r245618 | |
| 1568 | 1568 | { |
| 1569 | 1569 | file_error filerr = core_fopen(*input_file_str, OPEN_FLAG_READ, &input_file); |
| 1570 | 1570 | if (filerr != FILERR_NONE) |
| 1571 | | report_error(1, "Unable to open file (%s)", input_file_str->cstr()); |
| 1571 | report_error(1, "Unable to open file (%s)", input_file_str->c_str()); |
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | // process output CHD |
| r245617 | r245618 | |
| 1604 | 1604 | |
| 1605 | 1605 | // print some info |
| 1606 | 1606 | astring tempstr; |
| 1607 | | printf("Output CHD: %s\n", output_chd_str->cstr()); |
| 1607 | printf("Output CHD: %s\n", output_chd_str->c_str()); |
| 1608 | 1608 | if (output_parent.opened()) |
| 1609 | | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->cstr()); |
| 1610 | | printf("Input file: %s\n", input_file_str->cstr()); |
| 1609 | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); |
| 1610 | printf("Input file: %s\n", input_file_str->c_str()); |
| 1611 | 1611 | if (input_start != 0 || input_end != core_fsize(input_file)) |
| 1612 | 1612 | { |
| 1613 | 1613 | printf("Input start: %s\n", big_int_string(tempstr, input_start)); |
| r245617 | r245618 | |
| 1629 | 1629 | else |
| 1630 | 1630 | err = chd->create(*output_chd_str, input_end - input_start, hunk_size, unit_size, compression); |
| 1631 | 1631 | if (err != CHDERR_NONE) |
| 1632 | | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err)); |
| 1632 | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->c_str(), chd_file::error_string(err)); |
| 1633 | 1633 | |
| 1634 | 1634 | // if we have a parent, copy forward all the metadata |
| 1635 | 1635 | if (output_parent.opened()) |
| r245617 | r245618 | |
| 1665 | 1665 | { |
| 1666 | 1666 | file_error filerr = core_fopen(*input_file_str, OPEN_FLAG_READ, &input_file); |
| 1667 | 1667 | if (filerr != FILERR_NONE) |
| 1668 | | report_error(1, "Unable to open file (%s)", input_file_str->cstr()); |
| 1668 | report_error(1, "Unable to open file (%s)", input_file_str->c_str()); |
| 1669 | 1669 | } |
| 1670 | 1670 | |
| 1671 | 1671 | // process output CHD |
| r245617 | r245618 | |
| 1740 | 1740 | // load the file |
| 1741 | 1741 | file_error filerr = core_fload(*ident_str, identdata); |
| 1742 | 1742 | if (filerr != FILERR_NONE) |
| 1743 | | report_error(1, "Error reading ident file (%s)", ident_str->cstr()); |
| 1743 | report_error(1, "Error reading ident file (%s)", ident_str->c_str()); |
| 1744 | 1744 | |
| 1745 | 1745 | // must be at least 14 bytes; extract CHS data from there |
| 1746 | 1746 | if (identdata.count() < 14) |
| 1747 | | report_error(1, "Ident file '%s' is invalid (too short)", ident_str->cstr()); |
| 1747 | report_error(1, "Ident file '%s' is invalid (too short)", ident_str->c_str()); |
| 1748 | 1748 | cylinders = (identdata[3] << 8) | identdata[2]; |
| 1749 | 1749 | heads = (identdata[7] << 8) | identdata[6]; |
| 1750 | 1750 | sectors = (identdata[13] << 8) | identdata[12]; |
| r245617 | r245618 | |
| 1775 | 1775 | |
| 1776 | 1776 | // print some info |
| 1777 | 1777 | astring tempstr; |
| 1778 | | printf("Output CHD: %s\n", output_chd_str->cstr()); |
| 1778 | printf("Output CHD: %s\n", output_chd_str->c_str()); |
| 1779 | 1779 | if (output_parent.opened()) |
| 1780 | | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->cstr()); |
| 1780 | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); |
| 1781 | 1781 | if (input_file != NULL) |
| 1782 | 1782 | { |
| 1783 | | printf("Input file: %s\n", input_file_str->cstr()); |
| 1783 | printf("Input file: %s\n", input_file_str->c_str()); |
| 1784 | 1784 | if (input_start != 0 || input_end != core_fsize(input_file)) |
| 1785 | 1785 | { |
| 1786 | 1786 | printf("Input start: %s\n", big_int_string(tempstr, input_start)); |
| r245617 | r245618 | |
| 1807 | 1807 | else |
| 1808 | 1808 | err = chd->create(*output_chd_str, UINT64(totalsectors) * UINT64(sector_size), hunk_size, sector_size, compression); |
| 1809 | 1809 | if (err != CHDERR_NONE) |
| 1810 | | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err)); |
| 1810 | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->c_str(), chd_file::error_string(err)); |
| 1811 | 1811 | |
| 1812 | 1812 | // add the standard hard disk metadata |
| 1813 | 1813 | astring metadata; |
| r245617 | r245618 | |
| 1856 | 1856 | { |
| 1857 | 1857 | chd_error err = chdcd_parse_toc(*input_file_str, toc, track_info); |
| 1858 | 1858 | if (err != CHDERR_NONE) |
| 1859 | | report_error(1, "Error parsing input file (%s: %s)\n", input_file_str->cstr(), chd_file::error_string(err)); |
| 1859 | report_error(1, "Error parsing input file (%s: %s)\n", input_file_str->c_str(), chd_file::error_string(err)); |
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | // process output CHD |
| r245617 | r245618 | |
| 1889 | 1889 | |
| 1890 | 1890 | // print some info |
| 1891 | 1891 | astring tempstr; |
| 1892 | | printf("Output CHD: %s\n", output_chd_str->cstr()); |
| 1892 | printf("Output CHD: %s\n", output_chd_str->c_str()); |
| 1893 | 1893 | if (output_parent.opened()) |
| 1894 | | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->cstr()); |
| 1895 | | printf("Input file: %s\n", input_file_str->cstr()); |
| 1894 | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); |
| 1895 | printf("Input file: %s\n", input_file_str->c_str()); |
| 1896 | 1896 | printf("Input tracks: %d\n", toc.numtrks); |
| 1897 | 1897 | printf("Input length: %s\n", msf_string_from_frames(tempstr, origtotalsectors)); |
| 1898 | 1898 | printf("Compression: %s\n", compression_string(tempstr, compression)); |
| r245617 | r245618 | |
| 1910 | 1910 | else |
| 1911 | 1911 | err = chd->create(*output_chd_str, UINT64(totalsectors) * UINT64(CD_FRAME_SIZE), hunk_size, CD_FRAME_SIZE, compression); |
| 1912 | 1912 | if (err != CHDERR_NONE) |
| 1913 | | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err)); |
| 1913 | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->c_str(), chd_file::error_string(err)); |
| 1914 | 1914 | |
| 1915 | 1915 | // add the standard CD metadata; we do this even if we have a parent because it might be different |
| 1916 | 1916 | err = cdrom_write_metadata(chd, &toc); |
| r245617 | r245618 | |
| 1947 | 1947 | { |
| 1948 | 1948 | avi_error avierr = avi_open(*input_file_str, &input_file); |
| 1949 | 1949 | if (avierr != AVIERR_NONE) |
| 1950 | | report_error(1, "Error opening AVI file (%s): %s\n", input_file_str->cstr(), avi_error_string(avierr)); |
| 1950 | report_error(1, "Error opening AVI file (%s): %s\n", input_file_str->c_str(), avi_error_string(avierr)); |
| 1951 | 1951 | } |
| 1952 | 1952 | const avi_movie_info *aviinfo = avi_get_movie_info(input_file); |
| 1953 | 1953 | |
| r245617 | r245618 | |
| 1999 | 1999 | |
| 2000 | 2000 | // print some info |
| 2001 | 2001 | astring tempstr; |
| 2002 | | printf("Output CHD: %s\n", output_chd_str->cstr()); |
| 2002 | printf("Output CHD: %s\n", output_chd_str->c_str()); |
| 2003 | 2003 | if (output_parent.opened()) |
| 2004 | | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->cstr()); |
| 2005 | | printf("Input file: %s\n", input_file_str->cstr()); |
| 2004 | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); |
| 2005 | printf("Input file: %s\n", input_file_str->c_str()); |
| 2006 | 2006 | if (input_start != 0 && input_end != aviinfo->video_numsamples) |
| 2007 | 2007 | printf("Input start: %s\n", big_int_string(tempstr, input_start)); |
| 2008 | 2008 | printf("Input length: %s (%02d:%02d:%02d)\n", big_int_string(tempstr, input_end - input_start), |
| r245617 | r245618 | |
| 2028 | 2028 | else |
| 2029 | 2029 | err = chd->create(*output_chd_str, UINT64(input_end - input_start) * hunk_size, hunk_size, info.bytes_per_frame, compression); |
| 2030 | 2030 | if (err != CHDERR_NONE) |
| 2031 | | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err)); |
| 2031 | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->c_str(), chd_file::error_string(err)); |
| 2032 | 2032 | |
| 2033 | 2033 | // write the core A/V metadata |
| 2034 | 2034 | astring metadata; |
| r245617 | r245618 | |
| 2112 | 2112 | |
| 2113 | 2113 | // print some info |
| 2114 | 2114 | astring tempstr; |
| 2115 | | printf("Output CHD: %s\n", output_chd_str->cstr()); |
| 2115 | printf("Output CHD: %s\n", output_chd_str->c_str()); |
| 2116 | 2116 | if (output_parent.opened()) |
| 2117 | | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->cstr()); |
| 2118 | | printf("Input CHD: %s\n", params.find(OPTION_INPUT)->cstr()); |
| 2117 | printf("Parent CHD: %s\n", params.find(OPTION_OUTPUT_PARENT)->c_str()); |
| 2118 | printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str()); |
| 2119 | 2119 | if (input_start != 0 || input_end != input_chd.logical_bytes()) |
| 2120 | 2120 | { |
| 2121 | 2121 | printf("Input start: %s\n", big_int_string(tempstr, input_start)); |
| r245617 | r245618 | |
| 2137 | 2137 | else |
| 2138 | 2138 | err = chd->create(*output_chd_str, input_end - input_start, hunk_size, input_chd.unit_bytes(), compression); |
| 2139 | 2139 | if (err != CHDERR_NONE) |
| 2140 | | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->cstr(), chd_file::error_string(err)); |
| 2140 | report_error(1, "Error creating CHD file (%s): %s", output_chd_str->c_str(), chd_file::error_string(err)); |
| 2141 | 2141 | |
| 2142 | 2142 | // clone all the metadata, upgrading where appropriate |
| 2143 | 2143 | dynamic_buffer metadata; |
| r245617 | r245618 | |
| 2221 | 2221 | |
| 2222 | 2222 | // print some info |
| 2223 | 2223 | astring tempstr; |
| 2224 | | printf("Output File: %s\n", output_file_str->cstr()); |
| 2225 | | printf("Input CHD: %s\n", params.find(OPTION_INPUT)->cstr()); |
| 2224 | printf("Output File: %s\n", output_file_str->c_str()); |
| 2225 | printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str()); |
| 2226 | 2226 | if (input_start != 0 || input_end != input_chd.logical_bytes()) |
| 2227 | 2227 | { |
| 2228 | 2228 | printf("Input start: %s\n", big_int_string(tempstr, input_start)); |
| r245617 | r245618 | |
| 2236 | 2236 | // process output file |
| 2237 | 2237 | file_error filerr = core_fopen(*output_file_str, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file); |
| 2238 | 2238 | if (filerr != FILERR_NONE) |
| 2239 | | report_error(1, "Unable to open file (%s)", output_file_str->cstr()); |
| 2239 | report_error(1, "Unable to open file (%s)", output_file_str->c_str()); |
| 2240 | 2240 | |
| 2241 | 2241 | // copy all data |
| 2242 | 2242 | dynamic_buffer buffer((TEMP_BUFFER_SIZE / input_chd.hunk_bytes()) * input_chd.hunk_bytes()); |
| r245617 | r245618 | |
| 2248 | 2248 | UINT32 bytes_to_read = MIN((UINT32)buffer.count(), input_end - offset); |
| 2249 | 2249 | chd_error err = input_chd.read_bytes(offset, buffer, bytes_to_read); |
| 2250 | 2250 | if (err != CHDERR_NONE) |
| 2251 | | report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->cstr(), chd_file::error_string(err)); |
| 2251 | report_error(1, "Error reading CHD file (%s): %s", params.find(OPTION_INPUT)->c_str(), chd_file::error_string(err)); |
| 2252 | 2252 | |
| 2253 | 2253 | // write to the output |
| 2254 | 2254 | UINT32 count = core_fwrite(output_file, buffer, bytes_to_read); |
| 2255 | 2255 | if (count != bytes_to_read) |
| 2256 | | report_error(1, "Error writing to file; check disk space (%s)", output_file_str->cstr()); |
| 2256 | report_error(1, "Error writing to file; check disk space (%s)", output_file_str->c_str()); |
| 2257 | 2257 | |
| 2258 | 2258 | // advance |
| 2259 | 2259 | offset += bytes_to_read; |
| r245617 | r245618 | |
| 2306 | 2306 | if (chop != -1) |
| 2307 | 2307 | default_name.substr(0, chop); |
| 2308 | 2308 | char basename[128]; |
| 2309 | | strncpy(basename, default_name.cstr(), 127); |
| 2309 | strncpy(basename, default_name.c_str(), 127); |
| 2310 | 2310 | default_name.cat(".bin"); |
| 2311 | 2311 | if (output_bin_file_str == NULL) |
| 2312 | 2312 | output_bin_file_str = &default_name; |
| r245617 | r245618 | |
| 2314 | 2314 | |
| 2315 | 2315 | // print some info |
| 2316 | 2316 | astring tempstr; |
| 2317 | | printf("Output TOC: %s\n", output_file_str->cstr()); |
| 2318 | | printf("Output Data: %s\n", output_bin_file_str->cstr()); |
| 2319 | | printf("Input CHD: %s\n", params.find(OPTION_INPUT)->cstr()); |
| 2317 | printf("Output TOC: %s\n", output_file_str->c_str()); |
| 2318 | printf("Output Data: %s\n", output_bin_file_str->c_str()); |
| 2319 | printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str()); |
| 2320 | 2320 | |
| 2321 | 2321 | // catch errors so we can close & delete the output file |
| 2322 | 2322 | core_file *output_bin_file = NULL; |
| r245617 | r245618 | |
| 2337 | 2337 | // process output file |
| 2338 | 2338 | file_error filerr = core_fopen(*output_file_str, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_NO_BOM, &output_toc_file); |
| 2339 | 2339 | if (filerr != FILERR_NONE) |
| 2340 | | report_error(1, "Unable to open file (%s)", output_file_str->cstr()); |
| 2340 | report_error(1, "Unable to open file (%s)", output_file_str->c_str()); |
| 2341 | 2341 | |
| 2342 | 2342 | // process output BIN file |
| 2343 | 2343 | if (mode != MODE_GDI) |
| 2344 | 2344 | { |
| 2345 | 2345 | filerr = core_fopen(*output_bin_file_str, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_bin_file); |
| 2346 | 2346 | if (filerr != FILERR_NONE) |
| 2347 | | report_error(1, "Unable to open file (%s)", output_bin_file_str->cstr()); |
| 2347 | report_error(1, "Unable to open file (%s)", output_bin_file_str->c_str()); |
| 2348 | 2348 | } |
| 2349 | 2349 | |
| 2350 | 2350 | // determine total frames |
| r245617 | r245618 | |
| 2384 | 2384 | |
| 2385 | 2385 | filerr = core_fopen(trackbin_name, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_bin_file); |
| 2386 | 2386 | if (filerr != FILERR_NONE) |
| 2387 | | report_error(1, "Unable to open file (%s)", trackbin_name.cstr()); |
| 2387 | report_error(1, "Unable to open file (%s)", trackbin_name.c_str()); |
| 2388 | 2388 | |
| 2389 | 2389 | outputoffs = 0; |
| 2390 | 2390 | } |
| r245617 | r245618 | |
| 2449 | 2449 | core_fseek(output_bin_file, outputoffs, SEEK_SET); |
| 2450 | 2450 | UINT32 byteswritten = core_fwrite(output_bin_file, buffer, bufferoffs); |
| 2451 | 2451 | if (byteswritten != bufferoffs) |
| 2452 | | report_error(1, "Error writing frame %d to file (%s): %s\n", frame, output_file_str->cstr(), chd_file::error_string(CHDERR_WRITE_ERROR)); |
| 2452 | report_error(1, "Error writing frame %d to file (%s): %s\n", frame, output_file_str->c_str(), chd_file::error_string(CHDERR_WRITE_ERROR)); |
| 2453 | 2453 | outputoffs += bufferoffs; |
| 2454 | 2454 | bufferoffs = 0; |
| 2455 | 2455 | } |
| r245617 | r245618 | |
| 2548 | 2548 | |
| 2549 | 2549 | // print some info |
| 2550 | 2550 | astring tempstr; |
| 2551 | | printf("Output File: %s\n", output_file_str->cstr()); |
| 2552 | | printf("Input CHD: %s\n", params.find(OPTION_INPUT)->cstr()); |
| 2551 | printf("Output File: %s\n", output_file_str->c_str()); |
| 2552 | printf("Input CHD: %s\n", params.find(OPTION_INPUT)->c_str()); |
| 2553 | 2553 | if (input_start != 0 || input_end != input_chd.hunk_count()) |
| 2554 | 2554 | { |
| 2555 | 2555 | printf("Input start: %s\n", big_int_string(tempstr, input_start)); |
| r245617 | r245618 | |
| 2563 | 2563 | // process output file |
| 2564 | 2564 | avi_error avierr = avi_create(*output_file_str, &info, &output_file); |
| 2565 | 2565 | if (avierr != AVIERR_NONE) |
| 2566 | | report_error(1, "Unable to open file (%s)", output_file_str->cstr()); |
| 2566 | report_error(1, "Unable to open file (%s)", output_file_str->c_str()); |
| 2567 | 2567 | |
| 2568 | 2568 | // create the codec configuration |
| 2569 | 2569 | avhuff_decompress_config avconfig; |
| r245617 | r245618 | |
| 2592 | 2592 | if (err != CHDERR_NONE) |
| 2593 | 2593 | { |
| 2594 | 2594 | UINT64 filepos = core_ftell(input_chd); |
| 2595 | | report_error(1, "Error reading hunk %" I64FMT "d at offset %" I64FMT "d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->cstr(), chd_file::error_string(err)); |
| 2595 | report_error(1, "Error reading hunk %" I64FMT "d at offset %" I64FMT "d from CHD file (%s): %s\n", framenum, filepos, params.find(OPTION_INPUT)->c_str(), chd_file::error_string(err)); |
| 2596 | 2596 | } |
| 2597 | 2597 | |
| 2598 | 2598 | // write audio |
| r245617 | r245618 | |
| 2600 | 2600 | { |
| 2601 | 2601 | avi_error avierr = avi_append_sound_samples(output_file, chnum, avconfig.audio[chnum], actsamples, 0); |
| 2602 | 2602 | if (avierr != AVIERR_NONE) |
| 2603 | | report_error(1, "Error writing samples for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->cstr(), avi_error_string(avierr)); |
| 2603 | report_error(1, "Error writing samples for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->c_str(), avi_error_string(avierr)); |
| 2604 | 2604 | } |
| 2605 | 2605 | |
| 2606 | 2606 | // write video |
| r245617 | r245618 | |
| 2608 | 2608 | { |
| 2609 | 2609 | avi_error avierr = avi_append_video_frame(output_file, fullbitmap); |
| 2610 | 2610 | if (avierr != AVIERR_NONE) |
| 2611 | | report_error(1, "Error writing video for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->cstr(), avi_error_string(avierr)); |
| 2611 | report_error(1, "Error writing video for hunk %" I64FMT "d to file (%s): %s\n", framenum, output_file_str->c_str(), avi_error_string(avierr)); |
| 2612 | 2612 | } |
| 2613 | 2613 | } |
| 2614 | 2614 | |
| r245617 | r245618 | |
| 2671 | 2671 | { |
| 2672 | 2672 | file_error filerr = core_fload(*file_str, file); |
| 2673 | 2673 | if (filerr != FILERR_NONE) |
| 2674 | | report_error(1, "Error reading metadata file (%s)", file_str->cstr()); |
| 2674 | report_error(1, "Error reading metadata file (%s)", file_str->c_str()); |
| 2675 | 2675 | } |
| 2676 | 2676 | |
| 2677 | 2677 | // make sure we have one or the other |
| r245617 | r245618 | |
| 2687 | 2687 | |
| 2688 | 2688 | // print some info |
| 2689 | 2689 | astring tempstr; |
| 2690 | | printf("Input file: %s\n", params.find(OPTION_INPUT)->cstr()); |
| 2690 | printf("Input file: %s\n", params.find(OPTION_INPUT)->c_str()); |
| 2691 | 2691 | printf("Tag: %c%c%c%c\n", (tag >> 24) & 0xff, (tag >> 16) & 0xff, (tag >> 8) & 0xff, tag & 0xff); |
| 2692 | 2692 | printf("Index: %d\n", index); |
| 2693 | 2693 | if (text_str != NULL) |
| 2694 | | printf("Text: %s\n", text.cstr()); |
| 2694 | printf("Text: %s\n", text.c_str()); |
| 2695 | 2695 | else |
| 2696 | | printf("Data: %s (%d bytes)\n", file_str->cstr(), file.count()); |
| 2696 | printf("Data: %s (%d bytes)\n", file_str->c_str(), file.count()); |
| 2697 | 2697 | |
| 2698 | 2698 | // write the metadata |
| 2699 | 2699 | chd_error err; |
| r245617 | r245618 | |
| 2736 | 2736 | |
| 2737 | 2737 | // print some info |
| 2738 | 2738 | astring tempstr; |
| 2739 | | printf("Input file: %s\n", params.find(OPTION_INPUT)->cstr()); |
| 2739 | printf("Input file: %s\n", params.find(OPTION_INPUT)->c_str()); |
| 2740 | 2740 | printf("Tag: %c%c%c%c\n", (tag >> 24) & 0xff, (tag >> 16) & 0xff, (tag >> 8) & 0xff, tag & 0xff); |
| 2741 | 2741 | printf("Index: %d\n", index); |
| 2742 | 2742 | |
| r245617 | r245618 | |
| 2795 | 2795 | { |
| 2796 | 2796 | file_error filerr = core_fopen(*output_file_str, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &output_file); |
| 2797 | 2797 | if (filerr != FILERR_NONE) |
| 2798 | | report_error(1, "Unable to open file (%s)", output_file_str->cstr()); |
| 2798 | report_error(1, "Unable to open file (%s)", output_file_str->c_str()); |
| 2799 | 2799 | |
| 2800 | 2800 | // output the metadata |
| 2801 | 2801 | UINT32 count = core_fwrite(output_file, buffer, buffer.count()); |
| 2802 | 2802 | if (count != buffer.count()) |
| 2803 | | report_error(1, "Error writing file (%s)", output_file_str->cstr()); |
| 2803 | report_error(1, "Error writing file (%s)", output_file_str->c_str()); |
| 2804 | 2804 | core_fclose(output_file); |
| 2805 | 2805 | |
| 2806 | 2806 | // provide some feedback |
| 2807 | 2807 | astring tempstr; |
| 2808 | | printf("File (%s) written, %s bytes\n", output_file_str->cstr(), big_int_string(tempstr, buffer.count())); |
| 2808 | printf("File (%s) written, %s bytes\n", output_file_str->c_str(), big_int_string(tempstr, buffer.count())); |
| 2809 | 2809 | } |
| 2810 | 2810 | |
| 2811 | 2811 | // flush to stdout |
trunk/src/tools/src2html.c
| r245617 | r245618 | |
| 332 | 332 | |
| 333 | 333 | // create an index file |
| 334 | 334 | astring indexname; |
| 335 | | indexname.printf("%s%c%s", dstdir.cstr(), PATH_SEPARATOR[0], "index.html"); |
| 335 | indexname.printf("%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], "index.html"); |
| 336 | 336 | core_file *indexfile = create_file_and_output_header(indexname, tempheader, srcdir_subpath); |
| 337 | 337 | |
| 338 | 338 | // output the directory navigation |
| r245617 | r245618 | |
| 402 | 402 | |
| 403 | 403 | // build the source filename |
| 404 | 404 | astring srcfile; |
| 405 | | srcfile.printf("%s%c%s", srcdir.cstr(), PATH_SEPARATOR[0], curlist->name.cstr()); |
| 405 | srcfile.printf("%s%c%s", srcdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str()); |
| 406 | 406 | |
| 407 | 407 | // if we have a file, output it |
| 408 | 408 | astring dstfile; |
| r245617 | r245618 | |
| 420 | 420 | // if we got a valid file, process it |
| 421 | 421 | if (type != FILE_TYPE_INVALID) |
| 422 | 422 | { |
| 423 | | dstfile.printf("%s%c%s.html", dstdir.cstr(), PATH_SEPARATOR[0], curlist->name.cstr()); |
| 423 | dstfile.printf("%s%c%s.html", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str()); |
| 424 | 424 | if (indexfile != NULL) |
| 425 | | core_fprintf(indexfile, "\t<li><a href=\"%s.html\">%s</a></li>\n", curlist->name.cstr(), curlist->name.cstr()); |
| 425 | core_fprintf(indexfile, "\t<li><a href=\"%s.html\">%s</a></li>\n", curlist->name.c_str(), curlist->name.c_str()); |
| 426 | 426 | result = output_file(type, srcrootlen, dstrootlen, srcfile, dstfile, srcdir == dstdir, tempheader, tempfooter); |
| 427 | 427 | } |
| 428 | 428 | } |
| r245617 | r245618 | |
| 430 | 430 | // if we have a directory, recurse |
| 431 | 431 | else |
| 432 | 432 | { |
| 433 | | dstfile.printf("%s%c%s", dstdir.cstr(), PATH_SEPARATOR[0], curlist->name.cstr()); |
| 433 | dstfile.printf("%s%c%s", dstdir.c_str(), PATH_SEPARATOR[0], curlist->name.c_str()); |
| 434 | 434 | if (indexfile != NULL) |
| 435 | | core_fprintf(indexfile, "\t<li><a href=\"%s/index.html\">%s/</a></li>\n", curlist->name.cstr(), curlist->name.cstr()); |
| 435 | core_fprintf(indexfile, "\t<li><a href=\"%s/index.html\">%s/</a></li>\n", curlist->name.c_str(), curlist->name.c_str()); |
| 436 | 436 | result = recurse_dir(srcrootlen, dstrootlen, srcfile, dstfile, tempheader, tempfooter); |
| 437 | 437 | } |
| 438 | 438 | } |
| r245617 | r245618 | |
| 467 | 467 | astring srcfile_subpath; |
| 468 | 468 | normalized_subpath(srcfile_subpath, srcfile, srcrootlen + 1); |
| 469 | 469 | |
| 470 | | fprintf(stderr, "Processing %s\n", srcfile_subpath.cstr()); |
| 470 | fprintf(stderr, "Processing %s\n", srcfile_subpath.c_str()); |
| 471 | 471 | |
| 472 | 472 | // set some defaults |
| 473 | 473 | bool color_quotes = false; |
| r245617 | r245618 | |
| 519 | 519 | core_file *src; |
| 520 | 520 | if (core_fopen(srcfile, OPEN_FLAG_READ, &src) != FILERR_NONE) |
| 521 | 521 | { |
| 522 | | fprintf(stderr, "Unable to read file '%s'\n", srcfile.cstr()); |
| 522 | fprintf(stderr, "Unable to read file '%s'\n", srcfile.c_str()); |
| 523 | 523 | return 1; |
| 524 | 524 | } |
| 525 | 525 | |
| r245617 | r245618 | |
| 527 | 527 | core_file *dst = create_file_and_output_header(dstfile, tempheader, srcfile_subpath); |
| 528 | 528 | if (dst == NULL) |
| 529 | 529 | { |
| 530 | | fprintf(stderr, "Unable to write file '%s'\n", dstfile.cstr()); |
| 530 | fprintf(stderr, "Unable to write file '%s'\n", dstfile.c_str()); |
| 531 | 531 | core_fclose(src); |
| 532 | 532 | return 1; |
| 533 | 533 | } |
| r245617 | r245618 | |
| 659 | 659 | astring target; |
| 660 | 660 | if (find_include_file(target, srcrootlen, dstrootlen, srcfile, dstfile, filename)) |
| 661 | 661 | { |
| 662 | | dstline.catprintf("<a href=\"%s\">", target.cstr()); |
| 662 | dstline.catprintf("<a href=\"%s\">", target.c_str()); |
| 663 | 663 | quotes_are_linked = true; |
| 664 | 664 | } |
| 665 | 665 | } |
| r245617 | r245618 | |
| 738 | 738 | |
| 739 | 739 | // print a header |
| 740 | 740 | astring modified(templatefile); |
| 741 | | modified.replace(0, "<!--PATH-->", path.cstr()); |
| 742 | | core_fwrite(file, modified.cstr(), modified.len()); |
| 741 | modified.replace(0, "<!--PATH-->", path.c_str()); |
| 742 | core_fwrite(file, modified.c_str(), modified.len()); |
| 743 | 743 | |
| 744 | 744 | // return the file |
| 745 | 745 | return file; |
| r245617 | r245618 | |
| 754 | 754 | static void output_footer_and_close_file(core_file *file, astring &templatefile, astring &path) |
| 755 | 755 | { |
| 756 | 756 | astring modified(templatefile); |
| 757 | | modified.replace(0, "<!--PATH-->", path.cstr()); |
| 758 | | core_fwrite(file, modified.cstr(), modified.len()); |
| 757 | modified.replace(0, "<!--PATH-->", path.c_str()); |
| 758 | core_fwrite(file, modified.c_str(), modified.len()); |
| 759 | 759 | core_fclose(file); |
| 760 | 760 | } |
| 761 | 761 | |
| r245617 | r245618 | |
| 807 | 807 | core_fprintf(file, "<a href=\""); |
| 808 | 808 | for (int depth = curdepth; depth < srcdepth; depth++) |
| 809 | 809 | core_fprintf(file, "../"); |
| 810 | | core_fprintf(file, "index.html\">%s</a>/", substr.cstr()); |
| 810 | core_fprintf(file, "index.html\">%s</a>/", substr.c_str()); |
| 811 | 811 | |
| 812 | 812 | lastslash = slashindex + 1; |
| 813 | 813 | } |
| r245617 | r245618 | |
| 815 | 815 | // and a final link to the current directory |
| 816 | 816 | astring substr(path, lastslash, -1); |
| 817 | 817 | if (end_is_directory) |
| 818 | | core_fprintf(file, "<a href=\"index.html\">%s</a>", substr.cstr()); |
| 818 | core_fprintf(file, "<a href=\"index.html\">%s</a>", substr.c_str()); |
| 819 | 819 | else if (link_to_file) |
| 820 | | core_fprintf(file, "<a href=\"%s\">%s</a>", substr.cstr(), substr.cstr()); |
| 820 | core_fprintf(file, "<a href=\"%s\">%s</a>", substr.c_str(), substr.c_str()); |
| 821 | 821 | else |
| 822 | | core_fprintf(file, "<a href=\"%s.html\">%s</a>", substr.cstr(), substr.cstr()); |
| 822 | core_fprintf(file, "<a href=\"%s.html\">%s</a>", substr.c_str(), substr.c_str()); |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | |