_rom_info.tcl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. set_help_text rom_info\
  2. {Prints information about the given ROM device, coming from the software
  3. database. If no argument is given, the first found (external) ROM device is
  4. shown.}
  5. namespace eval rom_info {
  6. proc tab {args} {
  7. set result [list]
  8. foreach device [machine_info device] {
  9. if {[dict get [machine_info device $device] "type"] eq "ROM"} {
  10. lappend result $device
  11. }
  12. }
  13. return $result
  14. }
  15. set_tabcompletion_proc rom_info [namespace code tab]
  16. proc getlist_rom_info {{romdevice ""}} {
  17. if {$romdevice eq ""} {
  18. set romdevice [guess_rom_device]
  19. if {$romdevice eq ""} {
  20. error "No (external) ROM device found"
  21. }
  22. }
  23. if {[catch {set device_info [machine_info device $romdevice]}]} {
  24. error "No such device: $romdevice"
  25. }
  26. set device_type [dict get $device_info "type"]
  27. if {$device_type ne "ROM"} {
  28. error [format "Device is not of type ROM, but %s" $device_type]
  29. }
  30. set filename [dict get $device_info "filename"]
  31. set slotname ""
  32. set slot ""
  33. foreach slotcmd [info command cart?] {
  34. if {[lindex [$slotcmd] 1] eq $filename} {
  35. set slotname [string index $slotcmd end]
  36. set slotinfo [machine_info external_slot slot$slotname]
  37. set slotname [string toupper $slotname]
  38. set slot [lindex $slotinfo 0]
  39. set subslot [lindex $slotinfo 1]
  40. if {$subslot ne "X"} {
  41. append slot "-$subslot"
  42. }
  43. }
  44. }
  45. set actualSHA1 [dict get $device_info "actualSHA1"]
  46. set originalSHA1 [dict get $device_info "originalSHA1"]
  47. set rominfo ""
  48. if {[catch {set rominfo [openmsx_info software $actualSHA1]}]} {
  49. # try original sha1 to get more info
  50. catch {set rominfo [openmsx_info software $originalSHA1]}
  51. }
  52. set softPatched [expr {$actualSHA1 ne $originalSHA1}]
  53. set mappertype [dict get $device_info "mappertype"]
  54. set title ""
  55. set company ""
  56. set country ""
  57. set year ""
  58. set status ""
  59. set remark ""
  60. dict with rominfo {
  61. if {[info exists original] && $original} {
  62. # this is an unmodified original dump
  63. set status [format "Unmodified dump (confirmed by %s)" $orig_type]
  64. } else {
  65. # not original or unknown
  66. set status "Unknown"
  67. if {[info exists orig_type]} {
  68. switch $orig_type {
  69. "broken" {
  70. set status "Bad dump (game is broken)"
  71. }
  72. "translated" {
  73. set status "Translated from original"
  74. }
  75. "working" {
  76. set status "Modified but confirmed working"
  77. }
  78. }
  79. }
  80. }
  81. }
  82. if {$softPatched} {
  83. set statusPrefix ""
  84. if {$status ne ""} {
  85. set statusPrefix " "
  86. }
  87. set status "$status${statusPrefix}(but patched by openMSX)"
  88. }
  89. return [list \
  90. "filename" $filename \
  91. "title" $title \
  92. "year" $year \
  93. "company" $company \
  94. "country" $country \
  95. "status" $status \
  96. "remark" $remark \
  97. "mappertype" $mappertype \
  98. "slotname" $slotname \
  99. "slot" $slot]
  100. }
  101. proc rom_info {{romdevice ""}} {
  102. set rominfo [rom_info::getlist_rom_info $romdevice]
  103. dict with rominfo {
  104. if {$slotname ne "" && $slot ne ""} {
  105. append result "Cart. slot: $slotname (slot $slot)\n"
  106. }
  107. if {$title ne ""} {
  108. append result "Title: $title\n"
  109. } elseif {$filename ne ""} {
  110. append result "File: $filename\n"
  111. }
  112. if {$year ne ""} {
  113. append result "Year: $year\n"
  114. }
  115. if {$company ne ""} {
  116. append result "Company: $company\n"
  117. }
  118. if {$country ne ""} {
  119. append result "Country: $country\n"
  120. }
  121. if {$status ne ""} {
  122. append result "Status: $status\n"
  123. }
  124. if {$remark ne ""} {
  125. append result "Remark: $remark\n"
  126. }
  127. if {$mappertype ne ""} {
  128. append result "Mapper: $mappertype\n"
  129. }
  130. }
  131. return $result
  132. }
  133. namespace export rom_info
  134. namespace export getlist_rom_info
  135. } ;# namespace rom_info
  136. namespace import rom_info::*