├── rom_maps ├── 5BF10FD1 ├── 0024D346 ├── 3193670E ├── 350EACF0 ├── 35C28F5F ├── 368CADFE ├── 36B7FB6C ├── 3DC27823 ├── 4147DD77 ├── 420DBFF3 ├── 4957EB49 ├── 4D1EEAE1 ├── 4D1EEEE1 ├── 4D1F8172 ├── A49F9914 ├── E33B2724 ├── EC904829 ├── ECBBC41C ├── ECFA989B ├── EDE66CBD ├── F1A6F343 ├── F1ACAD13 ├── FF7439EE ├── 96CA3846 ├── ECD99DC0 └── TODO ├── .gitmodules ├── install.sh ├── README.md ├── LICENSE └── Mac ROM.tcl /rom_maps/5BF10FD1: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/AVROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/0024D346: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/Duo270cROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/3193670E: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/ClassicIIROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/350EACF0: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacLCROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/35C28F5F: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacLCIIROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/368CADFE: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacIIciROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/36B7FB6C: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacIIsiROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/3DC27823: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/Quadra950ROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/4147DD77: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacIIfxROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/420DBFF3: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/Quadra700ROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/4957EB49: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacIIviROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/4D1EEAE1: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacPlusROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/4D1EEEE1: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacPlusROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/4D1F8172: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacPlusROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/A49F9914: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/ClassicROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/E33B2724: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/PB160ROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/EC904829: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacLCIIIROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/ECBBC41C: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacLCIIIROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/ECFA989B: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/Duo210ROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/EDE66CBD: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/LC520ROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/F1A6F343: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/Quadra800ROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/F1ACAD13: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/Quadra800ROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/FF7439EE: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/Quadra605ROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/96CA3846: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/MacPortableROM.lst.txt -------------------------------------------------------------------------------- /rom_maps/ECD99DC0: -------------------------------------------------------------------------------- 1 | 68k-mac-rom-maps/rom-maps/ColorClassicROM.lst.txt -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "rom_maps/68k-mac-rom-maps"] 2 | path = rom_maps/68k-mac-rom-maps 3 | url = https://github.com/cy384/68k-mac-rom-maps.git 4 | -------------------------------------------------------------------------------- /rom_maps/TODO: -------------------------------------------------------------------------------- 1 | The following ROMs are missing, despite symbol tables: 2 | 3 | Multiple ROM versions, unclear which matches 4 | -------------------------------------------- 5 | MacIIROM.lst.txt 6 | MacSEROM.lst.txt 7 | 8 | Duplicate 9 | --------- 10 | PB140ROM.lst.txt -- This is the same as the Quadra 700 ROM, so it is used for this checksum. 11 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd) 4 | 5 | echo "Updating submodules..." 6 | git submodule update --init 7 | 8 | echo "Creating symlinks..." 9 | mkdir -p ~/Library/Application\ Support/com.ridiculousfish.HexFiend/Templates 10 | ln -sf "$SCRIPT_DIR/Mac ROM.tcl" ~/Library/Application\ Support/com.ridiculousfish.HexFiend/Templates 11 | ln -sf "$SCRIPT_DIR/rom_maps" ~/Library/Application\ Support/com.ridiculousfish.HexFiend/Templates 12 | 13 | echo "Done!" 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ROM Fiend: Macintosh DeclROM and System ROM file template for Hex Fiend 2 | 3 | This repository includes a file template for [Hex Fiend](http://hexfiend.com), allowing you to 4 | easily inspect and modify ROMs for classic Macintosh. 5 | 6 | It supports most commonly used ROMs for 68k and Old World PowerPC Macs, including NuBus and System 7 | ROMs in various capabilities. 8 | 9 | New World ROMs are also detected but cannot be parsed yet. 10 | 11 | ## Installation 12 | For a basic installataion, copy "Mac ROM.tcl" to your Hex Fiend template library. 13 | 14 | You can do this automatically, which will also install support for System ROM Symbols by 15 | running: 16 | ``` 17 | ./install.sh 18 | ``` 19 | This installation script automatically symlinks the template and the required symbol maps into 20 | your Hex Fiend template directory. 21 | 22 | You can find more information about templates in this tutorial: 23 | 24 | https://github.com/HexFiend/HexFiend/blob/master/templates/Tutorial.md 25 | 26 | ## Caveats 27 | This template and/or installation method has not been tested with the App Store version of Hex 28 | Fiend and may not work correctly. 29 | 30 | ## Errors 31 | This file template attempts to handle certain errors automatically, including reversed and 32 | byte-swapped ROMs. If this occurs an ERROR entry will appear at the top-level describing the 33 | issue. 34 | 35 | Parsing is still imperfect, and the template can occasionally miscalculate offsets causing 36 | incorrect data reads. When this occurs an ERROR entry will appear at the level where a 37 | miscalculated offset occurred. Unfortunately this error detection can currently cause unexpected 38 | nesting. 39 | 40 | ## Supported Data Types 41 | - Declaration ROM (DeclROM) 42 | - NuBus, PDS, and built-in peripherals on 68020+ Macs, including PowerPC. 43 | - These define plug-and-play parameters for devices, including memory mappings, driver support, 44 | and basic identification. 45 | - Almost all data types are supported. Unsupported entries are marked with "TODO" in the Hex 46 | Fiend view. 47 | - Driver functions have approximated data lengths as these are difficult to compute 48 | automatically. 49 | - For some SuperMac display cards, additional proprietary video timing data is available. 50 | - Extended DeclROM 51 | - Built-in peripheral definitions in Universal System ROMs after the PowerBook 160 and before a 52 | later PowerPC device. 53 | - This is a superset of the normal DeclROM, allowing for multiple data directories to be 54 | defined which are selected from on system boot. 55 | - Supports the same data types as regular DeclROMs. 56 | - System ROM Header 57 | - Basic information about the System ROM. Supported for all System ROMs from the 128k to the 58 | final Old World ROMs. 59 | - System ROM Resources 60 | - Toolbox resources including cursors, sounds, drivers, and some device support definitions. 61 | - Supported for all ROMs for the Mac Plus and newer. 62 | - System ROM Symbols 63 | - The table of symbols as defined in MPW 3.5, extracted by @cy384. This points to the address 64 | specified by the symbol, with no body, as that cannot be easily determined without 65 | decompiling each function. 66 | - Supports a subset of 68k ROMs. The setion will only be present if matching symbols are found. 67 | - EDisk images 68 | - Embedded ROM disk images as provided by the Mac Classic. 69 | 70 | ## Unsupported Data Types 71 | - System ROM tables 72 | - Used for some low-level hardware configuration. 73 | - These are encoded inline with assembly and thus are difficult to parse with Hex Fiend without hardcoding per ROM. 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Mac ROM.tcl: -------------------------------------------------------------------------------- 1 | #### Macintosh DeclROM and System ROM format for Hex Fiend 2 | # Copyright (c) 2022-2023 Eric Harmon 3 | 4 | # Note: data types are described in the card manual, page 152 5 | 6 | #### Hex Fiend setup 7 | 8 | hf_min_version_required 2.15 9 | big_endian 10 | 11 | #### ROM location setup 12 | 13 | # ROMs larger than 3MiB have their DeclROMs at the 3MiB boundary 14 | # TODO: For some DeclROMs and System ROMs there's extra data at the end, we need to read the 15 | # variety of possible locations instead of just the end. 16 | if {[len] > 3145728} { 17 | set end_of_rom 3145728 18 | } else { 19 | set end_of_rom [len] 20 | } 21 | 22 | #### Detect scrambled ROMs and find end of DeclROM 23 | 24 | # TODO: We're not detecting all conditions, just the ones I've found 25 | goto 2 26 | set magic [uint32] 27 | if {$magic == 0x38D46CA5} { 28 | entry "ERROR" "ROM must be byte-wise reversed and XOR'd with 0xFF" 29 | return 30 | } 31 | 32 | set offset [len] 33 | while {$offset > 0} { 34 | goto [expr $offset - 6] 35 | set magic [uint32] 36 | if {$magic == 0x5A932BC7} { 37 | set end_of_rom [expr $offset] 38 | break 39 | } elseif {$magic == 0x935AC72B} { 40 | entry "ERROR" "ROM must be byte-swapped from little-endian" 41 | return 42 | } elseif {$magic == 0xA56CD438} { 43 | entry "ERROR" "ROM must be XOR'd with 0xFF" 44 | return 45 | } elseif {$magic == 0x7878} { 46 | entry "ERROR" "ROM is repeated across bytelanes, take every 4th byte" 47 | return 48 | } 49 | set offset [expr $offset - 0x10000] 50 | } 51 | 52 | # Reset state 53 | goto 0 54 | # TODO: It's unfortunate this is a global 55 | set rom_date -1 56 | 57 | #### File matching 58 | 59 | # Currently we don't require this, since we can parse System ROMs as well -- if it's not a DeclROM or a System ROM it'll be caught way below as unsupported 60 | #requires [expr [len]-6] "5a 93 2b c7" 61 | 62 | #### Functions 63 | 64 | ## Utility functions 65 | 66 | # Add support for int24s 67 | # TODO: A better way? Ultimately we want an int24 and HexFiend only supports uint24 68 | # TODO: Support -hex 69 | # So we read the first part to get the signing information, then read the second part and bit shift everything into place 70 | proc int24 {args} { 71 | set first [int16] 72 | set second [uint8] 73 | set value [expr $first << 8 | $second] 74 | if {[llength $args] > 0} { 75 | move -3 76 | entry [lindex $args 0] $value 3 77 | move 3 78 | } 79 | return $value 80 | } 81 | 82 | # Add support for 32-bit fixed point fractionals 83 | proc fixed32 {args} { 84 | set whole [uint16] 85 | set fraction [uint16] 86 | set value [expr $whole + $fraction*0.1] 87 | if {[llength $args] > 0} { 88 | move -4 89 | entry [lindex $args 0] $value 4 90 | move 4 91 | } 92 | return $value 93 | } 94 | 95 | # Read a jump vector, which consists of a jmp statement (0x4E) and an int24 address 96 | # TODO: Use -hex 97 | # TODO: Verify it's actually a valid jmp instruction 98 | proc jmp {args} { 99 | move 1 100 | if {[llength $args] > 0} { 101 | set value [int24 [lindex $args 0]] 102 | } else { 103 | set value [int24] 104 | } 105 | return $value 106 | } 107 | 108 | proc sort_dict_by_int_value {dict args} { 109 | set lst {} 110 | dict for {k v} $dict {lappend lst [list $k $v]} 111 | return [concat {*}[lsort -integer -index 1 {*}$args $lst]] 112 | } 113 | 114 | # Detemrine if a ROM uses the universal format 115 | proc universal_rom {version} { 116 | if {$version < 0x6} { 117 | return false 118 | } 119 | return true 120 | } 121 | 122 | # Determine if a ROM uses the legacy resources format 123 | proc legacy_resources {version} { 124 | if {$version >= 0x75 && $version <= 0x7C} { 125 | return true 126 | } 127 | return false 128 | } 129 | 130 | ## Human readable text parsers 131 | 132 | # Given raw byte lane data, translate to human readable 133 | proc byte_lanes {input_lanes} { 134 | # TODO: Could we read bits instead of just hardcoding the documented table? 135 | switch $input_lanes { 136 | 225 { 137 | # 0xE1 138 | set lanes "0" 139 | } 140 | 210 { 141 | # 0xD2 142 | set lanes "1" 143 | } 144 | 195 { 145 | # 0xC3 146 | set lanes "0,1" 147 | } 148 | 180 { 149 | # 0xB4 150 | set lanes "2" 151 | } 152 | 165 { 153 | # 0xA5 154 | set lanes "0,2" 155 | } 156 | 150 { 157 | # 0x96 158 | set lanes "1,2" 159 | } 160 | 135 { 161 | # 0x87 162 | set lanes "0,1,2" 163 | } 164 | 120 { 165 | # 0x78 166 | set lanes "3" 167 | } 168 | 105 { 169 | # 0x69 170 | set lanes "0,3" 171 | } 172 | 90 { 173 | # 0x5A 174 | set lanes "1,3" 175 | } 176 | 75 { 177 | # 0x4B 178 | set lanes "0,1,3" 179 | } 180 | 60 { 181 | # 0x3C 182 | set lanes "2,3" 183 | } 184 | 45 { 185 | # 0x2D 186 | set lanes "0,2,3" 187 | } 188 | 30 { 189 | # 0x1E 190 | set lanes "1,2,3" 191 | } 192 | 15 { 193 | # 0x0F 194 | set lanes "0,1,2,3" 195 | } 196 | default { 197 | set lanes "Unknown" 198 | } 199 | } 200 | return $lanes 201 | } 202 | 203 | # Given a resource type, return the human readable type 204 | proc rsrc_type {input_type} { 205 | # Where possible, from ROMDefs.inc 206 | switch $input_type { 207 | 1 { 208 | set type "Board" 209 | } 210 | 2 { 211 | set type "Test" 212 | } 213 | 3 { 214 | set type "Display" 215 | } 216 | 4 { 217 | set type "Network" 218 | } 219 | 6 { 220 | # TODO: Confirm 221 | set type "Communications" 222 | } 223 | 8 { 224 | # Confusingly this is used for capture cards, etc 225 | # Per the docs, "scanners bring in data somehow" 226 | # TODO: Possible cTypes are 1 for....video? 227 | set type "Scanner" 228 | } 229 | 9 { 230 | # TODO: Confirm, the Kanji board and WGS card use these, Kanji for ROM, WGS for Memory 231 | # TODO: Linux calls this "font" but I think they're wrong based on how WGS uses this 232 | set type "Memory" 233 | } 234 | 10 { 235 | set type "CPU" 236 | } 237 | 12 { 238 | # SCSI cards use this, but officially it's the "intelligent bus" 239 | set type "IntBus" 240 | } 241 | 17 { 242 | set type "Proto" 243 | } 244 | 19 { 245 | # TODO: The PC Drive card claims to be an "intelligent bus" but uses 19, so...let's assume for now this is the same for some reason 246 | set type "IntBus" 247 | } 248 | 25 { 249 | # TODO: Confirm, Interware Video CD Player uses this for MPEG decoder, PowerVideo AV for JPEG decoder 250 | set type "Compression Accelerator(?)" 251 | } 252 | 32 { 253 | # PowerBook Duo System page 184 (204) 254 | set type "Dock" 255 | } 256 | default { 257 | # TODO: Categories include display, network, terminal emulator, serial, parallel, intelligent bus, and human input devices. 258 | # TODO: The followng types may be correct: 259 | # - 7: Printer controller? -- LasterMAX uses it 260 | # - 12: Disk 261 | # - 17: Debug Card? 262 | # - 10: Floppy Disk? 263 | # - With cType 2 for MFM? 264 | set type "Unknown" 265 | } 266 | } 267 | return $type 268 | } 269 | 270 | # Resolve cTypes to human readable 271 | proc resolve_ctype {category ctype} { 272 | switch $category { 273 | 1 { 274 | # Board always seems to be zero, so just call that...Board 275 | switch $ctype { 276 | 0 { 277 | # Cards page 148 278 | set type "Board (0)" 279 | } 280 | default { 281 | set type "Unknown ($ctype)" 282 | } 283 | } 284 | } 285 | 3 { 286 | # Validated by looking at Display cards 287 | switch $ctype { 288 | 1 { 289 | set type "Video (1)" 290 | } 291 | 2 { 292 | # Cards page 148 293 | set type "LCD (2)" 294 | } 295 | 5 { 296 | # Aapps MicroTV 297 | set type "TV (5)" 298 | } 299 | default { 300 | set type "Unknown ($ctype)" 301 | } 302 | } 303 | } 304 | 4 { 305 | # Validated by looking at Ethernet cards 306 | switch $ctype { 307 | 1 { 308 | set type "EtherNet (1)" 309 | } 310 | 2 { 311 | # TODO: Linux claims this is RS232, but TokenTalk seems correct since the TokenRing card uses it 312 | set type "TokenTalk (2)" 313 | } 314 | 7 { 315 | set type "Token Ring 802.2? (4)" 316 | } 317 | default { 318 | # Possible others: 319 | # AppleTalk 320 | # DECNet 321 | set type "Unknown ($ctype)" 322 | } 323 | } 324 | } 325 | 6 { 326 | # Validated by looking at Communications cards 327 | switch $ctype { 328 | 2 { 329 | set type "RS232 (2)" 330 | } 331 | 6 { 332 | # VersaLink 333 | set type "RS422 (6)" 334 | } 335 | 8 { 336 | # Referenced by TattleTech and the Mac Mainframe II 337 | set type "IBM 3270 (8)" 338 | } 339 | 10 { 340 | # Apple Coax/Twinax Card 341 | set type "IBM 5250 (10)" 342 | } 343 | 11 { 344 | set type "Centronics (11)" 345 | } 346 | 19 { 347 | # Apple Coax/Twinax Card 348 | set type "IBM 3270 (19)" 349 | } 350 | 27 { 351 | # SCii RNIS 352 | set type "ISDN (27)" 353 | } 354 | 30 { 355 | # KMW Systems TwinAxcess 356 | set type "IBM 5250/Twinax (30)" 357 | } 358 | default { 359 | # Possible others: 360 | # Parallel 361 | # MIDI 362 | set type "Unknown ($ctype)" 363 | } 364 | } 365 | } 366 | 8 { 367 | # TODO: 1 is Video digitizer and 2 is Audio? 368 | # Scanner 369 | # Image Digitizer 370 | # Audio Signal Processor 371 | # Optical Scanner 372 | set type "Unknown ($ctype)" 373 | } 374 | 10 { 375 | switch $ctype { 376 | 1 { 377 | # Card docs page 173 378 | set type "68000 (1)" 379 | } 380 | 2 { 381 | # Guess, by process of elimination above and below 382 | set type "68010 (2)" 383 | } 384 | 3 { 385 | # Linux nubus.h -- also present in Apple headers but ambiguously 386 | set type "68020 (3)" 387 | } 388 | 4 { 389 | # Linux nubus.h -- also present in Apple headers but ambiguously 390 | set type "68030 (4)" 391 | } 392 | 5 { 393 | # Radius Rocket 394 | set type "68040 (5)" 395 | } 396 | 11 { 397 | # MacIvory III: https://oldvcr.blogspot.com/2024/10/refurb-weekend-symbolics-macivory-lisp.html 398 | # TODO: It's possible this is all Lisp processors 399 | set type "Symbolics Ivory (11)" 400 | } 401 | 20 { 402 | # Team ASA Raven 403 | set type "i860 (20)" 404 | } 405 | 21 { 406 | set type "AppleII (21)" 407 | } 408 | 36 { 409 | # Reply Houdini II 410 | set type "80486 (36)" 411 | } 412 | default { 413 | # Possible others: 414 | # 68010 415 | # 8086 416 | # 80286 417 | # 80386 418 | set type "Unknown ($ctype)" 419 | } 420 | } 421 | } 422 | 12 { 423 | # Validated by looking at PLI card 424 | switch $ctype { 425 | 8 { 426 | set type "SCSI (8)" 427 | } 428 | default { 429 | set type "Unknown ($ctype)" 430 | } 431 | } 432 | } 433 | 19 { 434 | # PC Drive card 435 | # TODO: Confirm 436 | switch $ctype { 437 | 2 { 438 | set type "MFM (2)" 439 | } 440 | default { 441 | set type "Unknown ($ctype)" 442 | } 443 | } 444 | } 445 | 25 { 446 | # TODO: These are a guess based on Interware cards 447 | switch $ctype { 448 | 257 { 449 | set type "JPEG (257)" 450 | } 451 | 259 { 452 | set type "MPEG (259)" 453 | } 454 | default { 455 | set type "Unknown ($ctype)" 456 | } 457 | } 458 | } 459 | 17 { 460 | switch $ctype { 461 | # ROMEqu.a 462 | 256 { 463 | set type "Debugger (256)" 464 | } 465 | default { 466 | set type "Unknown ($ctype)" 467 | } 468 | } 469 | } 470 | 32 { 471 | # PowerBookDuo System page 184 (204) 472 | switch $ctype { 473 | 1 { 474 | set type "Dock Station (1)" 475 | } 476 | 2 { 477 | set type "Dock Desk (2)" 478 | } 479 | 3 { 480 | set type "Dock Travel (3)" 481 | } 482 | } 483 | } 484 | default { 485 | set type "Unknown ($ctype)" 486 | } 487 | } 488 | return $type 489 | } 490 | 491 | # Resolve drSW to human readable 492 | proc resolve_drsw {drSW} { 493 | switch $drSW { 494 | 1 { 495 | set type "Apple (1)" 496 | } 497 | 260 { 498 | # ROMEqu.a 499 | set type "MacsBug (260)" 500 | } 501 | 65535 { 502 | # Card docs page 173 503 | set type "Not in ROM (65535)" 504 | } 505 | default { 506 | # TODO: These were assigned by Apple so we can encode known ones 507 | set type "$drSW" 508 | } 509 | } 510 | } 511 | 512 | # Given a CPU type, return the human readable type 513 | proc cpu_type {input_type} { 514 | # NuBus reference page 167 (208) 515 | # ROMDefs.h for PPC 516 | switch $input_type { 517 | 1 { 518 | set type "68000 (1)" 519 | } 520 | 2 { 521 | set type "68020 (2)" 522 | } 523 | 3 { 524 | set type "68030 (3)" 525 | } 526 | 4 { 527 | set type "68040 (4)" 528 | } 529 | 37 { 530 | # TODO: This might be for CPU sResources and not drivers? 531 | set type "PowerPC 601 (37)" 532 | } 533 | 46 { 534 | # TODO: This might be for CPU sResources and not drivers? 535 | set type "PowerPC 603 (46)" 536 | } 537 | default { 538 | set type "Unknown ($input_type)" 539 | } 540 | } 541 | return $type 542 | } 543 | 544 | # Convert timing map values to human readable 545 | proc timing_map {timing} { 546 | # TODO: Add all the timings from Video.h 547 | # TODO: Also see DeclData.r...what are those sName for? 548 | switch $timing { 549 | 0 { 550 | # TODO: zero entry is a bit unclear: "Unknown timing... force user to confirm." 551 | set type "User Specified(?) (0)" 552 | } 553 | 8 { 554 | set type "Thunder/24 (Buggy) (8)" 555 | } 556 | 42 { 557 | set type "Fixed Rate LCD (42)" 558 | } 559 | 130 { 560 | set type "512x384 (60 Hz) (130)" 561 | } 562 | 140 { 563 | set type "640x480 (67 Hz) (140)" 564 | } 565 | 160 { 566 | set type "640x870 (75 Hz) (160)" 567 | } 568 | 170 { 569 | set type "832x624 (75 Hz) (170)" 570 | } 571 | 210 { 572 | set type "1024x768 (75 Hz) (210)" 573 | } 574 | 220 { 575 | set type "1152x870 (75 Hz) (220)" 576 | } 577 | 230 { 578 | set type "\[NTSC\] 512x384 (60 Hz, interlaced, non-convolved) (230)" 579 | } 580 | 232 { 581 | set type "\[NTSC\] 640x480 (60 Hz, interlaced, non-convolved) (232)" 582 | } 583 | 238 { 584 | set type "\[PAL\] 640x480 (50 Hz, interlaced, non-convolved) (238)" 585 | } 586 | 240 { 587 | set type "\[PAL\] 768x576 (50 Hz, interlaced, non-convolved) (240)" 588 | } 589 | 280 { 590 | set type "1600x1200 (60 Hz) (280)" 591 | } 592 | 510 { 593 | set type "1920x1080 (60 Hz) (510)" 594 | } 595 | default { 596 | set type "Unknown ($timing)" 597 | } 598 | } 599 | return $type 600 | } 601 | 602 | # Parse block transfer bit tables into human readable 603 | proc parse_transfer_bits {} { 604 | uint16_bits 0 "2-bit Transfer Supported" 605 | move -2 606 | uint16_bits 1 "4-bit Transfer Supported" 607 | move -2 608 | uint16_bits 2 "8-bit Transfer Supported" 609 | move -2 610 | uint16_bits 3 "16-bit Transfer Supported" 611 | } 612 | 613 | # Read resource combo mask data into human readable 614 | proc combos {combo} { 615 | # TODO: From tbxi, but these don't seem quite right. These seem like mask bits and not fixed values, but they're inconsistent. 616 | # TODO: It's a bit odd these are so long when only the first few bits are used... 617 | # TODO: This only works with masks that are 8 bytes 618 | switch $combo { 619 | 0x0100000000000000 { 620 | set name "NetBoot (0x10)" 621 | } 622 | 0x0800000000000000 { 623 | set name "Apple Talk 2.0 + NetBoot (0x08)" 624 | } 625 | 0x2000000000000000 { 626 | set name "Apple Talk 2.0 (0x20)" 627 | } 628 | 0x3000000000000000 { 629 | set name "Apple Talk 2.0 + NetBoot + FPU (0x30)" 630 | } 631 | 0x4000000000000000 { 632 | set name "Apple Talk 1.0 (0x40)" 633 | } 634 | 0x7800000000000000 { 635 | set name "Universal Resource (0x78)" 636 | } 637 | default { 638 | set name "Unknown ($combo)" 639 | } 640 | } 641 | return $name 642 | } 643 | 644 | # Parse ROM version into human readable 645 | proc rom_version {version} { 646 | set major [expr $version >> 4] 647 | set minor [expr $version & 0x0F] 648 | set hex_version [format %X $version] 649 | 650 | return "$major.$minor ($$hex_version/$version)" 651 | } 652 | 653 | # Parse ROM release version into human readable 654 | proc rom_release {version} { 655 | set major [expr $version >> 12] 656 | set minor [expr ($version & 0x0F00) >> 8] 657 | set letter [format %x [expr ($version & 0x00F0) >> 4]] 658 | set build [expr $version & 0x000F] 659 | set hex_version [format 0x%X $version] 660 | 661 | return "$major.$minor$letter$build ($hex_version)" 662 | } 663 | 664 | ## sResource type parsers 665 | 666 | # Compute the vendor info 667 | proc vendor_info {offset} { 668 | set temp_location [pos] 669 | move $offset 670 | section "Vendor Info" 671 | set vendor_rsrc_offset 0x01 672 | set vendor_rsrc_type 0x00 673 | while {[expr $vendor_rsrc_offset != 0x000000 && $vendor_rsrc_type != 0xFF]} { 674 | section "Metadata" 675 | sectioncollapse 676 | set vendor_rsrc_type [uint8 "Type"] 677 | set vendor_rsrc_offset [int24 "Offset"] 678 | endsection 679 | set vendor_rsrc_entry_return [pos] 680 | move [expr $vendor_rsrc_offset-4] 681 | # NuBus documentation, page 178 (219) 682 | switch $vendor_rsrc_type { 683 | 1 { 684 | set vendorid [cstr "macroman" "VendorID"] 685 | } 686 | 2 { 687 | cstr "macroman" "SerialNum" 688 | } 689 | 3 { 690 | cstr "macroman" "RevLevel" 691 | } 692 | 4 { 693 | cstr "macroman" "PartNum" 694 | } 695 | 5 { 696 | # Stash the date location for later 697 | global rom_date 698 | set rom_date [pos] 699 | 700 | cstr "macroman" "Date" 701 | } 702 | } 703 | goto $vendor_rsrc_entry_return 704 | } 705 | goto $temp_location 706 | endsection 707 | return $vendorid 708 | } 709 | 710 | # Examine a driver directory for directoriesdata 711 | proc driver_dir {offset} { 712 | set temp_location [pos] 713 | move $offset 714 | section "Drivers" 715 | set driver_rsrc_offset 0x01 716 | set driver_rsrc_type 0x00 717 | while {[expr $driver_rsrc_offset != 0x000000 && $driver_rsrc_type != 0xFF]} { 718 | section "Driver" 719 | set driver_rsrc_type [uint8] 720 | set decoded_cpu [cpu_type $driver_rsrc_type] 721 | sectionname "Driver ($driver_rsrc_type)" 722 | move -1 723 | entry "CPU ID" $decoded_cpu 1 724 | move 1 725 | set driver_rsrc_offset [int24 "Offset"] 726 | if {$driver_rsrc_type == 0xFF} { 727 | sectionname "Terminator (255)" 728 | sectioncollapse 729 | } else { 730 | # TODO: Not sure this extraction is correct, or at least it's insufficient 731 | # "For the Macintosh Operating System, this structure is described in detail with the Device Manager information in Inside Macintosh." 732 | # Inside Macintosh, Device Manager page 1-13 733 | set driver_rsrc_entry_return [pos] 734 | move -4 735 | move $driver_rsrc_offset 736 | move 1 737 | set driver_length [uint24 "Physical Block Size"] 738 | # TODO: Assuming we subtract 4 because the length includes the header where the length is specified 739 | #bytes [expr $driver_length-4] "Driver Data" 740 | section "Driver Data" 741 | section "Header" 742 | sectioncollapse 743 | set driver_region_start [pos] 744 | uint16 "drvrFlags" 745 | uint16 "drvrDelay" 746 | uint16 "drvrEMask" 747 | uint16 "drvrMenu" 748 | set open_offset [uint16 "drvrOpen"] 749 | set prime_offset [uint16 "drvrPrime"] 750 | set control_offset [uint16 "drvrCtl"] 751 | set status_offset [uint16 "drvrStatus"] 752 | set close_offset [uint16 "drvrClose"] 753 | set name_length [uint8 "drvrName Length"] 754 | if {$name_length > 0} { 755 | set name [str $name_length "macroman" "drvrName"] 756 | } else { 757 | set name "Unknown" 758 | } 759 | endsection 760 | 761 | section "Functions" 762 | # The driver functions can appear in any order, or be omitted entirely (offset == 0), so to determine the size of each function block (approximately) 763 | # we have to sort all the offsets to determine the order of the function calls, 764 | set offset_dict [dict create "Open" $open_offset "Prime" $prime_offset "Control" $control_offset "Status" $status_offset "Close" $close_offset] 765 | set sorted_offsets [sort_dict_by_int_value $offset_dict] 766 | set current_offset 0 767 | set current_type "" 768 | dict for {type value} $sorted_offsets { 769 | if {$value > 0} { 770 | if {$current_offset > 0} { 771 | goto $driver_region_start 772 | move $current_offset 773 | # TODO: We can read right off the edge so catch errors 774 | set status [catch { 775 | bytes [expr $value-$current_offset] $current_type 776 | } err] 777 | if {$status} { 778 | entry "ERROR" $err 779 | } 780 | # Debugging: 781 | #entry $current_type "$value - $current_offset" 782 | } 783 | set current_type $type 784 | set current_offset $value 785 | } 786 | } 787 | # For the last entry, it must span from the $current_offset to the $driver_length 788 | if {$current_offset > 0} { 789 | goto $driver_region_start 790 | move $current_offset 791 | # TODO: Is this _really_ correct? It seems to work but this is ugly -- we're just compensating for offset mistakes earlier 792 | # TODO: We seem to get Micron driver wrong still, so there's more work to do -- it's possible this is NEVER exact, because the OS doesn't care as long as the entry points work 793 | # TODO: Sometimes we read right off the end of the file (Spectrum 8 Series III), so catch errors 794 | set status [catch { 795 | bytes [expr $driver_length-4-$current_offset+12] $current_type 796 | } err] 797 | if {$status} { 798 | entry "ERROR" $err 799 | } 800 | # Debugging: 801 | #entry $current_type "$value - $current_offset" 802 | } 803 | endsection 804 | endsection 805 | sectionname "Driver ($driver_rsrc_type) ($name)" 806 | goto $driver_rsrc_entry_return 807 | } 808 | endsection 809 | } 810 | goto $temp_location 811 | endsection 812 | } 813 | 814 | # Examine the gamma data 815 | proc gamma_dir {offset} { 816 | set temp_location [pos] 817 | move $offset 818 | set gamma_rsrc_offset 0x01 819 | set gamma_rsrc_type 0x00 820 | while {[expr $gamma_rsrc_offset != 0x000000 && $gamma_rsrc_type != 0xFF]} { 821 | section "Gamma Entry" 822 | sectioncollapse 823 | set gamma_rsrc_type [uint8 "Type"] 824 | set gamma_rsrc_offset [int24 "Offset"] 825 | if {$gamma_rsrc_type == 0xFF} { 826 | sectionname "Terminator (255)" 827 | } else { 828 | # TODO: Something is weird, sometimes we get bad entries with nonsense offsets 829 | set gamma_rsrc_entry_return [pos] 830 | move [expr $gamma_rsrc_offset-4] 831 | set start [pos] 832 | set length [uint32 "Record Length"] 833 | uint16 "ID" 834 | set name [cstr "macroman" "Name"] 835 | sectionname $name 836 | set end [pos] 837 | bytes [expr $length - ($end - $start)] "Gamma Image" 838 | goto $gamma_rsrc_entry_return 839 | } 840 | endsection 841 | } 842 | goto $temp_location 843 | } 844 | 845 | # Examine the sVidParm data 846 | proc svidparam_dir {offset} { 847 | set temp_location [pos] 848 | move $offset 849 | set svidparam_rsrc_offset 0x01 850 | set svidparam_rsrc_type 0x00 851 | while {[expr $svidparam_rsrc_offset != 0x000000 && $svidparam_rsrc_type != 0xFF]} { 852 | section "Vid Param" 853 | sectioncollapse 854 | set svidparam_rsrc_type [uint8 "Type"] 855 | sectionname "Video Mode $svidparam_rsrc_type" 856 | set svidparam_rsrc_offset [int24 "Offset"] 857 | if {$svidparam_rsrc_type == 0xFF} { 858 | sectionname "Terminator (255)" 859 | } else { 860 | set meh [pos] 861 | # TODO: Isn't this off by 4? 862 | move $svidparam_rsrc_offset 863 | uint32 "TODO" 864 | goto $meh 865 | } 866 | endsection 867 | } 868 | goto $temp_location 869 | } 870 | 871 | proc smemory {offset} { 872 | set temp_location [pos] 873 | move $offset 874 | set smemory_rsrc_offset 0x01 875 | set smemory_rsrc_type 0x00 876 | while {[expr $smemory_rsrc_offset != 0x000000 && $smemory_rsrc_type != 0xFF]} { 877 | section "sMemory Entry" 878 | sectioncollapse 879 | set smemory_rsrc_type [uint8 "Type"] 880 | set smemory_rsrc_offset [int24 "Offset"] 881 | switch $smemory_rsrc_type { 882 | 1 { 883 | # TODO: This is redundant with the other sRsrcType parse, should be merged 884 | # TODO: Is category "150" just "Memory"? 885 | sectionname "sRsrcType (1)" 886 | set temp [pos] 887 | move -4 888 | move $smemory_rsrc_offset 889 | set category [uint16] 890 | move -2 891 | entry "Category" [rsrc_type $category] 2 892 | move 2 893 | # TODO: "The cType field is a subclass within a category. Within display devices, for example, are video cards and graphics extension processors; within networks, AppleTalk and Ethernet." 894 | # TODO: So we should categorize the resources correctly based on the top-level Category. 895 | set ctype [uint16] 896 | move -2 897 | entry "cType" [resolve_ctype $category $ctype] 2 898 | move 2 899 | set drSW [uint16] 900 | move -2 901 | entry "DrSW" [resolve_drsw $drSW] 2 902 | move 2 903 | # This *should* be non-unique across smemorys, so we can't do anything but list the number 904 | uint16 "DrHW" 905 | goto $temp 906 | } 907 | 2 { 908 | set smemory_rsrc_entry_return [pos] 909 | move [expr $smemory_rsrc_offset-4] 910 | set name [cstr "macroman" "Name"] 911 | sectionname "sRsrcName (2)" 912 | goto $smemory_rsrc_entry_return 913 | } 914 | 128 { 915 | sectionname "MinorRAMAddr (128)" 916 | entry "TODO" 0 917 | # TODO 918 | } 919 | 129 { 920 | sectionname "MajorRAMAddr (129)" 921 | entry "TODO" 0 922 | # TODO 923 | } 924 | 130 { 925 | sectionname "MinorROMAddr (130)" 926 | entry "TODO" 0 927 | # TODO 928 | } 929 | 131 { 930 | sectionname "MajorROMAddr (131)" 931 | entry "TODO" 0 932 | # TODO 933 | } 934 | 132 { 935 | sectionname "MinorDeviceAddr (132)" 936 | entry "TODO" 0 937 | # TODO 938 | } 939 | 133 { 940 | sectionname "MajorDeviceAddr (133)" 941 | entry "TODO" 0 942 | # TODO 943 | } 944 | 255 { 945 | sectionname "Terminator (255)" 946 | } 947 | default { 948 | sectionname "Unknown ($smemory_rsrc_type)" 949 | } 950 | } 951 | endsection 952 | } 953 | goto $temp_location 954 | } 955 | 956 | # Discover the video mode names 957 | proc vid_names {offset} { 958 | set temp_location [pos] 959 | move $offset 960 | set vid_names_rsrc_offset 0x01 961 | set vid_names_rsrc_type 0x00 962 | while {[expr $vid_names_rsrc_offset != 0x000000 && $vid_names_rsrc_type != 0xFF]} { 963 | section "Video Mode" 964 | sectioncollapse 965 | set vid_names_rsrc_type [uint8 "Type"] 966 | set vid_names_rsrc_offset [int24 "Offset"] 967 | # TODO: Does this mean something else? 968 | if {$vid_names_rsrc_type == 0} { 969 | sectionname "Invalid (0)" 970 | } elseif {$vid_names_rsrc_type == 0xFF} { 971 | sectionname "Terminator (255)" 972 | } else { 973 | set vid_names_rsrc_entry_return [pos] 974 | move [expr $vid_names_rsrc_offset-4] 975 | uint32 "Record Length" 976 | # TODO: Confirm 977 | uint16 "Localization ID" 978 | set name [cstr "macroman" "Name"] 979 | sectionname $name 980 | goto $vid_names_rsrc_entry_return 981 | } 982 | endsection 983 | } 984 | goto $temp_location 985 | } 986 | 987 | # Discover the video modes 988 | proc vid_mode {offset} { 989 | set temp_location [pos] 990 | move $offset 991 | set vid_mode_rsrc_offset 0x01 992 | set vid_mode_rsrc_type 0x00 993 | while {[expr $vid_mode_rsrc_offset != 0x000000 && $vid_mode_rsrc_type != 0xFF]} { 994 | section "Metadata" 995 | sectioncollapse 996 | set vid_mode_rsrc_type [uint8 "Type"] 997 | set vid_mode_rsrc_offset [int24 "Offset"] 998 | set vid_mode_rsrc_entry_return [pos] 999 | endsection 1000 | move -4 1001 | # NuBus documentation, page 178 (219) 1002 | switch $vid_mode_rsrc_type { 1003 | 1 { 1004 | # TODO: Properly mark out this offset 1005 | move $vid_mode_rsrc_offset 1006 | section "Mode Data" 1007 | uint32 "Record Size" 1008 | uint32 "vpBaseOffset" 1009 | uint16 "vpRowBytes" 1010 | set bounds0 [uint16 "vpBounds(0)"] 1011 | set bounds1 [uint16 "vpBounds(1)"] 1012 | set bounds2 [uint16 "vpBounds(2)"] 1013 | set bounds3 [uint16 "vpBounds(3)"] 1014 | uint16 "vpVersion" 1015 | uint16 "vpPackType" 1016 | # Table 9-2 is incorrect, this is a full byte 1017 | uint32 "vpPackSize" 1018 | fixed32 "vpHRes" 1019 | fixed32 "vpVRes" 1020 | uint16 "vpPixelType" 1021 | uint16 "vpPixelSize" 1022 | uint16 "vpCmpCount" 1023 | uint16 "vpCmpSize" 1024 | uint32 "vpPlaneBytes" 1025 | endsection 1026 | } 1027 | 2 { 1028 | # TODO: mTable: Offset to the device color table for fixed CLUT devices; mTable has the same format as the cTabHandle structure, described with the Color Manager information in Inside Macintosh. 1029 | uint32 "mTable Offset" 1030 | } 1031 | 3 { 1032 | move 1 1033 | uint24 "Page Count" 1034 | } 1035 | 4 { 1036 | move 1 1037 | uint24 "Device Type" 1038 | } 1039 | # TODO: Confirm 1040 | 5 { 1041 | move 1 1042 | # From ROMDefs.h: slot block xfer info PER MODE 1043 | uint24 "mBlockTransferInfo" 1044 | } 1045 | # TODO: Confirm 1046 | 6 { 1047 | move 1 1048 | # From ROMDefs.h: slot max. locked xfer count PER MODE 1049 | uint24 "mMaxLockedTransferCount" 1050 | } 1051 | default { 1052 | # TODO: Mark terminator 1053 | } 1054 | } 1055 | goto $vid_mode_rsrc_entry_return 1056 | } 1057 | goto $temp_location 1058 | 1059 | set height [expr $bounds2 - $bounds0] 1060 | set width [expr $bounds3 - $bounds1] 1061 | 1062 | return "$width x $height" 1063 | } 1064 | 1065 | # Examine a block describing an executable section 1066 | proc exec_block {offset} { 1067 | # TODO: Need to verify this block is correct 1068 | set temp_location [pos] 1069 | move $offset 1070 | set length [uint32 "Length"] 1071 | uint8 "Revision" 1072 | set raw_cpu [uint8] 1073 | move -1 1074 | entry "CPU ID" [cpu_type $raw_cpu] 1 1075 | move 4 1076 | set second_offset [int24 "Offset"] 1077 | move -4 1078 | 1079 | move $second_offset 1080 | # TODO: This calculation is WEIRD, but it seems correct? 1081 | bytes [expr $length-$second_offset-8] "Code" 1082 | goto $temp_location 1083 | } 1084 | 1085 | # Read the auxiliary video parameters 1086 | proc vid_aux_params {offset} { 1087 | set temp_location [pos] 1088 | move $offset 1089 | set vid_aux_params_rsrc_offset 0x01 1090 | set vid_aux_params_rsrc_type 0x00 1091 | while {[expr $vid_aux_params_rsrc_offset != 0x000000 && $vid_aux_params_rsrc_type != 0xFF]} { 1092 | section "Mode" 1093 | sectioncollapse 1094 | section "Metadata" 1095 | sectioncollapse 1096 | set vid_aux_params_rsrc_type [uint8 "Type"] 1097 | set vid_aux_params_rsrc_offset [int24 "Offset"] 1098 | endsection 1099 | if {$vid_aux_params_rsrc_type == 0xFF} { 1100 | sectionname "Terminator (255)" 1101 | } else { 1102 | sectionname "Mode $vid_aux_params_rsrc_type" 1103 | set vid_aux_params_rsrc_entry_return [pos] 1104 | move [expr $vid_aux_params_rsrc_offset-4] 1105 | uint32 "Unknown" 1106 | set timing_info [uint32] 1107 | move -4 1108 | entry "Timing" [timing_map $timing_info] 4 1109 | goto $vid_aux_params_rsrc_entry_return 1110 | } 1111 | endsection 1112 | } 1113 | goto $temp_location 1114 | } 1115 | 1116 | # Examine the block transfer info block 1117 | proc block_transfer_info {offset} { 1118 | set temp_location [pos] 1119 | move $offset 1120 | section "Master" 1121 | # Master word 1122 | uint16_bits 15 "Is Master" 1123 | move -2 1124 | uint16_bits 14 "Locked Transfer Supported" 1125 | move -2 1126 | # TODO: This is 'Reserved' so technically we don't need to parse it, but we should be reading the bit values 1127 | #uint16_bits 4,5,6 "Format" 1128 | #move -2 1129 | parse_transfer_bits 1130 | endsection 1131 | section "Slave" 1132 | # Slave word 1133 | uint16_bits 15 "Is Slave" 1134 | move -2 1135 | parse_transfer_bits 1136 | endsection 1137 | goto $temp_location 1138 | } 1139 | 1140 | # Determine if an offset is logical -- if it doesn't offset far enough to leave the directory entry, it's not valid 1141 | proc valid_rsrc_dir_offset {offset} { 1142 | if {$offset > 0 && $offset < 4} { 1143 | return 0 1144 | } else { 1145 | return 1 1146 | } 1147 | } 1148 | 1149 | # Parse the sResourceDir 1150 | proc parse_rsrc_dir {directory} { 1151 | # Jump into the directory and start parsing it's entries 1152 | goto $directory 1153 | set rsrc_offset 1 1154 | set rsrc_type 0 1155 | 1156 | # Loop over the top level sResource entries 1157 | while {[expr $rsrc_offset != 0x000000 && $rsrc_type != 0xFF]} { 1158 | section "sResource" 1159 | sectioncollapse 1160 | 1161 | # These will be filed in by the type record, which is usually first 1162 | # TODO: If it's not before the video entries, we won't parse them correctly 1163 | set category 0 1164 | set ctype 0 1165 | set drSW 0 1166 | set rsrc_name "" 1167 | 1168 | section "Metadata" 1169 | sectioncollapse 1170 | set rsrc_type [uint8 "Type"] 1171 | set rsrc_offset [int24 "Offset"] 1172 | endsection 1173 | set location [pos] 1174 | if {$rsrc_type == 0xFF} { 1175 | sectionname "Terminator (255)" 1176 | } else { 1177 | move [expr $rsrc_offset-4] 1178 | 1179 | set sub_rsrc_offset 0x01 1180 | set sub_rsrc_type 0x00 1181 | set human_category "" 1182 | 1183 | # Loop over the sResources in this entry 1184 | while {[expr $sub_rsrc_offset != 0x000000 && $sub_rsrc_type != 0xFF]} { 1185 | section "sRsrc" 1186 | sectioncollapse 1187 | section "Metadata" 1188 | set sub_rsrc_type [uint8 "Type"] 1189 | set sub_rsrc_offset [int24 "Offset/Raw Data"] 1190 | sectioncollapse 1191 | endsection 1192 | set reset_location [pos] 1193 | move -4 1194 | # We are now at the proper location to add $sub_rsrc_offsets. 1195 | # The location will be reset automatically after the switch to continue looping. 1196 | 1197 | # TODO: Sometimes this error handling doesn't pop us out enough sections 1198 | set status [catch { 1199 | # See NuBus documentation, page 164 (205), also page 185 (226) 1200 | switch -glob $sub_rsrc_type { 1201 | 1 { 1202 | # See NuBus documentation, page 165 (206) 1203 | sectionname "sRsrcType (1)" 1204 | move $sub_rsrc_offset 1205 | # TODO: remove bit 31: "bit 31 is reserved for Apple's use" -- page 145 1206 | set category [uint16] 1207 | move -2 1208 | set human_category [rsrc_type $category] 1209 | entry "Category" "$human_category ($category)" 2 1210 | move 2 1211 | set ctype [uint16] 1212 | move -2 1213 | entry "cType" [resolve_ctype $category $ctype] 2 1214 | move 2 1215 | set drSW [uint16] 1216 | move -2 1217 | entry "DrSW" [resolve_drsw $drSW] 2 1218 | move 2 1219 | # This *should* be non-unique across vendors, so we can't do anything but list the number 1220 | uint16 "DrHW" 1221 | } 1222 | 2 { 1223 | sectionname "sRsrcName (2)" 1224 | move $sub_rsrc_offset 1225 | set rsrc_name [cstr "macroman" "Name"] 1226 | } 1227 | 3 { 1228 | sectionname "sRsrcIcon (3)" 1229 | # TODO: Is this the correct offset? 1230 | move $sub_rsrc_offset 1231 | # Size per cards documentation, page 184 (225) 1232 | bytes 128 "Icon" 1233 | } 1234 | 4 { 1235 | sectionname "sRsrcDrvrDir (4)" 1236 | driver_dir $sub_rsrc_offset 1237 | } 1238 | 5 { 1239 | # Card page 167 1240 | sectionname "sRsrcLoadRec (5)" 1241 | exec_block $sub_rsrc_offset 1242 | } 1243 | 6 { 1244 | # Card page 168 1245 | sectionname "sRsrcBootRec (6)" 1246 | exec_block $sub_rsrc_offset 1247 | } 1248 | 7 { 1249 | sectionname "sRsrcFlags (7)" 1250 | move 2 1251 | # TODO: is that "sResource flags for sRsrc_Flags" in ROMDefs.h? 1252 | # Card manual page page 169 1253 | uint16_bits 1 "fOpenAtStart" 1254 | move -2 1255 | uint16_bits 2 "f32BitMode" 1256 | } 1257 | 8 { 1258 | sectionname "sRsrcHWDevld (8)" 1259 | move 1 1260 | entry "Hardware Device ID" $sub_rsrc_offset 3 1261 | } 1262 | 10 { 1263 | sectionname "MinorBaseOS (10)" 1264 | move $sub_rsrc_offset 1265 | uint32 "minBaseOS" 1266 | } 1267 | 11 { 1268 | sectionname "MinorLength (11)" 1269 | move $sub_rsrc_offset 1270 | uint32 "minorLength" 1271 | } 1272 | 12 { 1273 | sectionname "MajorBaseOS (12)" 1274 | move $sub_rsrc_offset 1275 | uint32 "majBaseOS" 1276 | } 1277 | 13 { 1278 | sectionname "MajorLength (13)" 1279 | move $sub_rsrc_offset 1280 | uint32 "majorLength" 1281 | } 1282 | 14 { 1283 | # from ROMDefs.h: sBlock diagnostic code 1284 | sectionname "sRsrcTest (14)" 1285 | entry "TODO" 0 1286 | # TODO: Parse 1287 | } 1288 | 15 { 1289 | sectionname "sRsrcCicn (15)" 1290 | entry "TODO" 0 1291 | # Card documentation page 185 (226) 1292 | # TODO: Parse 1293 | } 1294 | 16 { 1295 | # Card documentation page 170 (211) 1296 | sectionname "sRsrclcl8 (16)" 1297 | move $sub_rsrc_offset 1298 | # Equivalent to icl8 at 32x32 so fixed at 1024 1299 | bytes 1024 "Icon" 1300 | } 1301 | 17 { 1302 | # Card documentation page 171 (212) 1303 | sectionname "sRsrclcl4 (17)" 1304 | move $sub_rsrc_offset 1305 | # Equivalent to icl4 at 32x32 so fixed at 512 1306 | bytes 512 "Icon" 1307 | } 1308 | 20 { 1309 | # From ROMDefs.h: general slot block xfer info 1310 | # Card book page 181 (222) 1311 | sectionname "sBlockTransferInfo (20)" 1312 | block_transfer_info $sub_rsrc_offset 1313 | } 1314 | 21 { 1315 | # From ROMDefs.h: slot max. locked xfer count 1316 | sectionname "sMaxLockedTransferCount (21)" 1317 | move $sub_rsrc_offset 1318 | uint32 "Maximum Locked Transfers" 1319 | } 1320 | 32 { 1321 | sectionname "BoardID (32)" 1322 | move 1 1323 | entry "Board ID" [expr $sub_rsrc_offset & 0xFF] 3 1324 | } 1325 | 33 { 1326 | sectionname "PRAMInitData (33)" 1327 | # TODO: Might be broken 1328 | move $sub_rsrc_offset 1329 | move 1 1330 | uint24 "Physical Block Size" 1331 | move 2 1332 | uint8 "Byte 1" 1333 | uint8 "Byte 2" 1334 | uint8 "Byte 3" 1335 | uint8 "Byte 4" 1336 | uint8 "Byte 5" 1337 | uint8 "Byte 6" 1338 | } 1339 | 34 { 1340 | sectionname "PrimaryInit (34)" 1341 | exec_block $sub_rsrc_offset 1342 | } 1343 | 35 { 1344 | sectionname "STimeOut (35)" 1345 | move 1 1346 | uint24 "Time Out" 1347 | } 1348 | 36 { 1349 | sectionname "VendorInfo (36)" 1350 | set vendorid [vendor_info $sub_rsrc_offset] 1351 | } 1352 | 37 { 1353 | # TODO: Confirm 1354 | # From ROMDefs.h: Board Flags 1355 | sectionname "BoardFlags (37)" 1356 | entry "TODO" 0 1357 | # TODO: Parse 1358 | } 1359 | 38 { 1360 | sectionname "SecondaryInit (38)" 1361 | exec_block $sub_rsrc_offset 1362 | } 1363 | 64 { 1364 | sectionname "sGammaDir (54)" 1365 | gamma_dir $sub_rsrc_offset 1366 | } 1367 | 65 { 1368 | sectionname "sRsrcVidNames (65)" 1369 | vid_names $sub_rsrc_offset 1370 | } 1371 | 80 { 1372 | # From ROMDefs.h: spID for Docking Handlers 1373 | sectionname "sRsrcDock (80)" 1374 | entry "TODO" 0 1375 | # TODO: Parse 1376 | } 1377 | 85 { 1378 | # From ROMDefs.h: spID for board diagnostics 1379 | sectionname "sDiagRec (85)" 1380 | entry "TODO" 0 1381 | # TODO: Parse 1382 | } 1383 | 108 { 1384 | sectionname "sMemory (108)" 1385 | smemory $sub_rsrc_offset 1386 | } 1387 | 123 { 1388 | # From ROMDefs.h: more video info for Display Manager -- timing information 1389 | sectionname "sVidAuxParams (123)" 1390 | vid_aux_params $sub_rsrc_offset 1391 | } 1392 | 124 { 1393 | # From ROMDefs.h: DatLstEntry for debuggers indicating video anamolies 1394 | sectionname "sDebugger (124)" 1395 | entry "TODO" 0 1396 | # TODO: Parse 1397 | } 1398 | 125 { 1399 | # From ROMDefs.h: video attributes data field (optional,word) 1400 | sectionname "sVidAttributes (125)" 1401 | move 2 1402 | # fLCDScreen bit 0 - when set is LCD, else is CRT 1403 | uint16_bits 0 "fLCDScreen" 1404 | move -2 1405 | # fBuiltInDisplay 1 - when set is built-in (in the box) display, else not 1406 | uint16_bits 1 "fBuiltInDisplay" 1407 | move -2 1408 | # fDefaultColor 2 - when set display prefers multi-bit color, else gray 1409 | uint16_bits 2 "fDefaultColor" 1410 | move -2 1411 | # fActiveBlack 3 - when set black on display must be written, else display is naturally black 1412 | uint16_bits 3 "fActiveBlack" 1413 | move -2 1414 | # fDimMinAt1 4 - when set should dim backlight to level 1 instead of 0 1415 | uint16_bits 4 "fDimAt1" 1416 | # TODO.....two 4th bits??? 1417 | # fBuiltInDetach 4 - when set is built-in (in the box), but detaches 1418 | } 1419 | 126 { 1420 | # From ROMDefs.h 1421 | # From card docs page 186 1422 | # TODO: No, it's not on page 186? 1423 | sectionname "sVidParmDir (126)" 1424 | svidparam_dir $sub_rsrc_offset 1425 | } 1426 | 140 { 1427 | # From ROMDefs.h: directory of backlight tables 1428 | sectionname "sBkltParmDir (140)" 1429 | entry "TODO" 0 1430 | # TODO: Parse 1431 | } 1432 | 2* { 1433 | # TODO: This whole section layout is kinda gross 1434 | switch -regexp $sub_rsrc_type { 1435 | {(20[0-9]|2[1-4][0-9])} { 1436 | # Special timing data for SuperMac cards 1437 | # TODO: This misparses early cards which appear to use a different format in a different set of sResources 1438 | if {$vendorid == "SuperMac Technology"} { 1439 | sectionname "SuperMac Timing ($sub_rsrc_type)" 1440 | move $sub_rsrc_offset 1441 | uint32 "Length" 1442 | uint8 "Clock" 1443 | bytes 3 "Unknown" 1444 | bytes 8 "Unknown BSR Data" 1445 | uint16 "Horizontal End Sync" 1446 | uint16 "Horizontal End Blank" 1447 | uint16 "Horizontal Start Blank" 1448 | uint16 "Horizontal Total" 1449 | uint16 "Vertical End Sync" 1450 | uint16 "Vertical End Blank" 1451 | uint16 "Vertical Start Blank" 1452 | uint16 "Vertical Total" 1453 | bytes 44 "Unknown SMT Data" 1454 | bytes 6 "Unknown SQD Data" 1455 | uint16 "Horizontal Resolution" 1456 | uint16 "Vertical Resolution" 1457 | uint8 "sRsrc ID" 1458 | bytes 1 "Unknown" 1459 | set timing_name [cstr macroman "Name"] 1460 | sectionname "SuperMac Timing \[$timing_name\] ($sub_rsrc_type)" 1461 | } else { 1462 | sectionname "Unknown ($sub_rsrc_type)" 1463 | } 1464 | } 1465 | 255 { 1466 | sectionname "Terminator (255)" 1467 | } 1468 | default { 1469 | sectionname "Unknown ($sub_rsrc_type)" 1470 | } 1471 | } 1472 | } 1473 | default { 1474 | sectionname "Unknown ($sub_rsrc_type)" 1475 | } 1476 | } 1477 | # Process the special types for certain devices 1478 | if {$sub_rsrc_type >= 128 && $sub_rsrc_type != 255} { 1479 | if {$category == 3 && $drSW == 1} { 1480 | # TODO: It's possible other software types use this same storage, but type 1 indicates: "For example, under Category Display and cType Video atypical predefined driver software interface would be one defined by Apple to work with QuickDraw using the Macintosh Operating System frame buffers." -- page 146 1481 | sectionname "Video Mode ($sub_rsrc_type)" 1482 | # TODO: We should check this everywhere, but for now this is a quick fix for the Futura SX ROM 1483 | if {[valid_rsrc_dir_offset $sub_rsrc_offset] == 0} { 1484 | sectionvalue "ERROR" 1485 | entry "ERROR" "Irrational offset: $sub_rsrc_offset" 1486 | } else { 1487 | set vid_bounds [vid_mode $sub_rsrc_offset] 1488 | # TODO: Redundantly setting part of the section name 1489 | sectionname "Video Mode \[$vid_bounds\] ($sub_rsrc_type)" 1490 | } 1491 | } elseif {$category == 4 && $ctype == 1 && $sub_rsrc_type == 128} { 1492 | # TODO: This only seems to apply for resource type 128...what do the others do? 1493 | sectionname "Ethernet Address ($sub_rsrc_type)" 1494 | move $sub_rsrc_offset 1495 | # Compute 48-bit address 1496 | set first [uint32] 1497 | set second [uint16] 1498 | set mac [expr $first << 16 | $second] 1499 | move -6 1500 | entry "MAC" [format 0x%010x $mac] 6 1501 | } elseif {$category == 10} { 1502 | # ROMDefs.inc references these for CPU sResources 1503 | # TODO: Is this really right? 1504 | switch $sub_rsrc_type { 1505 | 129 { 1506 | sectionname "MajRAMSp (128)" 1507 | entry "TODO" 0 1508 | } 1509 | 130 { 1510 | sectionname "MinROMSp (129)" 1511 | entry "TODO" 0 1512 | } 1513 | } 1514 | } 1515 | } 1516 | } err] 1517 | if {$status} { 1518 | sectionvalue "ERROR" 1519 | entry "ERROR" $err 1 1520 | # TODO: Sometimes we haven't started a section when we error which causes us to crash anyway -- need to fix that we don't over-close sections 1521 | #endsection 1522 | } 1523 | goto $reset_location 1524 | endsection 1525 | } 1526 | if {$rsrc_type < 127} { 1527 | set human_category "Board" 1528 | } 1529 | if {$rsrc_name != ""} { 1530 | sectionname "$human_category \[$rsrc_name\] ($rsrc_type)" 1531 | } else { 1532 | sectionname "$human_category ($rsrc_type)" 1533 | } 1534 | goto $location 1535 | } 1536 | endsection 1537 | } 1538 | } 1539 | 1540 | #### Main parser 1541 | 1542 | ## Stage 1: DeclROM 1543 | 1544 | set dir_start -1 1545 | 1546 | if {$magic == 0x5A932BC7} { 1547 | section "DeclROM" 1548 | sectioncollapse 1549 | 1550 | # Jump to the end where the header is 1551 | goto $end_of_rom 1552 | 1553 | # Step backwards through the header 1554 | move -1 1555 | set raw_lanes [uint8] 1556 | move -1 1557 | entry "ByteLanes" [byte_lanes $raw_lanes] 1 1558 | move 1 1559 | move -6 1560 | hex 4 "TestPattern" 1561 | move -5 1562 | uint8 "Format" 1563 | move -2 1564 | uint8 "RevisionLevel" 1565 | move -5 1566 | hex 4 "CRC" 1567 | move -8 1568 | set length [uint32 "Length"] 1569 | 1570 | move -7 1571 | set offset [int24 "DirectoryOffset"] 1572 | set dir_start [expr $end_of_rom - 20 + $offset] 1573 | move -3 1574 | entry "(Computed Directory Start)" $dir_start 3 1575 | move 3 1576 | 1577 | section "Directory" 1578 | parse_rsrc_dir $dir_start 1579 | endsection 1580 | endsection 1581 | } 1582 | 1583 | ## Stage 2: Extended DeclROM 1584 | 1585 | goto [expr $end_of_rom-24] 1586 | set extended_magic [uint32] 1587 | if {$extended_magic == 0x5A932BC7} { 1588 | section "Extended DeclROM" 1589 | sectioncollapse 1590 | move -4 1591 | hex 4 "TestPattern" 1592 | move -11 1593 | set offset [int24 "Super DirectoryOffset"] 1594 | set superdir_start [expr $end_of_rom - 32 + $offset] 1595 | move -3 1596 | entry "(Computed Directory Start)" $superdir_start 3 1597 | move -4 1598 | 1599 | section "SuperInit" 1600 | sectioncollapse 1601 | section "Metadata" 1602 | sectioncollapse 1603 | set offset [int24 "Offset"] 1604 | endsection 1605 | exec_block [expr $offset-4] 1606 | endsection 1607 | 1608 | goto $superdir_start 1609 | # This is an sResource of pointers to sResource directories for each board 1610 | # Loop over the top level sResource entries 1611 | set rsrc_offset 1 1612 | set rsrc_type 0 1613 | while {[expr $rsrc_offset != 0x000000 && $rsrc_type != 0xFF]} { 1614 | section "sRsrcDir" 1615 | 1616 | section "Metadata" 1617 | sectioncollapse 1618 | set rsrc_type [uint8 "Type"] 1619 | set rsrc_offset [int24 "Offset"] 1620 | endsection 1621 | if {$rsrc_type == 0xFF} { 1622 | sectionname "Terminator (255)" 1623 | } else { 1624 | sectionname "Directory ($rsrc_type)" 1625 | # TODO: This is dumb 1626 | set oldpos [pos] 1627 | move -4 1628 | move $rsrc_offset 1629 | parse_rsrc_dir [pos] 1630 | goto $oldpos 1631 | } 1632 | endsection 1633 | } 1634 | endsection 1635 | } 1636 | 1637 | ## Stage 3: System ROM 1638 | 1639 | # TODO: This isn't quite right with Extended Format 1640 | if {$dir_start != 0} { 1641 | # TODO: From here on we match a System ROM using the value of the reset vector. This is quite odd and probably imperfect. 1642 | 1643 | set machine "" 1644 | 1645 | # If we didn't find a DeclROM, then it has to be a System ROM, or it's not a supported file type 1646 | if {$dir_start == -1} { 1647 | goto 0 1648 | set chrp_boot [ascii 11] 1649 | if {$chrp_boot == ""} { 1650 | section "New World ROM" 1651 | entry "TODO" "TODO" 1 1652 | endsection 1653 | 1654 | # For now we early return 1655 | return 1656 | } 1657 | # TODO: Requirements have been temporarily disabled to support Twiggy ROMs 1658 | #requires 6 "00 2a" 1659 | } 1660 | # Search to see if this is a system board ROM 1661 | # https://mcosre.sourceforge.net/docs/rom_v.html 1662 | goto 6 1663 | # TODO: We're detecting the ROM by checking the reset vector, which is odd, but it's always 0x2A 1664 | set data [uint16] 1665 | if {$data == 0x2A || $data == 0x16} { 1666 | goto 0 1667 | section "System ROM" 1668 | sectioncollapse 1669 | 1670 | # TODO: This is a guess, we know the early Twiggy ROMs with a different reset vector don't have a checksum 1671 | if {$data == 0x2A} { 1672 | set checksum [uint32 -hex "Checksum"] 1673 | set hex_checksum [format %x $checksum] 1674 | } else { 1675 | set hex_checksum "none" 1676 | move 4 1677 | } 1678 | 1679 | move 4 1680 | section "Versions" 1681 | # TODO: Also format in the $XXXX format used in some places 1682 | set machine [uint8 "Machine"] 1683 | move -1 1684 | set family_version [uint16] 1685 | move -2 1686 | entry "Family Version" [format $%04X $family_version] 2 1687 | move 2 1688 | move -1 1689 | # TODO: Classify by type 1690 | set minor_ver [uint8] 1691 | move -1 1692 | entry "ROM Version" [rom_version $minor_ver] 1 1693 | if {[universal_rom $machine]} { 1694 | goto 18 1695 | set rom_release [uint16] 1696 | move -2 1697 | entry "Minor Version" [rom_release $rom_release] 2 1698 | goto 76 1699 | uint16 "Sub Release" 1700 | } 1701 | 1702 | # Read the date from old-style ROMs 1703 | # No DeclROM and versions between 7.5 and 7.11 1704 | if {$dir_start == -1 && $minor_ver >= 0x75 && $minor_ver < 0x7B} { 1705 | # Always look at the 256k or 512k offsets in case a ROM disk was appended 1706 | if {$minor_ver == 0x75} { 1707 | goto [expr 0x20000 - 1] 1708 | } else { 1709 | goto [expr 0x40000 - 1] 1710 | } 1711 | set date_length [uint8] 1712 | move [expr -$date_length - 1] 1713 | ascii $date_length "Build Date" 1714 | } elseif {$rom_date != -1} { 1715 | # Borrow the build date from the DeclROM if we found one 1716 | goto $rom_date 1717 | cstr "macroman" "Build Date (DeclROM)" 1718 | } 1719 | endsection 1720 | 1721 | 1722 | goto 4 1723 | # TODO: Display the reset vector value 1724 | uint32 -hex "Reset Vector" 1725 | 1726 | # Both ROM eras support resource data offset 1727 | if {[universal_rom $machine] || [legacy_resources $minor_ver]} { 1728 | goto 0x1a 1729 | set resource_data_offset [uint32 "Resource Data Offset"] 1730 | } 1731 | 1732 | # TODO: Determine how to read pre-Universal ROM headers 1733 | if {[universal_rom $machine]} { 1734 | section "Extended Metadata (Experimental)" 1735 | sectioncollapse 1736 | goto 10 1737 | jmp "Start Boot Vector" 1738 | jmp "Bad Disk Vector" 1739 | move 2 1740 | uint8 "Patch Flags" 1741 | move 1 1742 | uint32 "Foreign OS Vector Table" 1743 | move 4 1744 | jmp "Eject Vector" 1745 | uint32 "Dispatch Table Offset" 1746 | jmp "Critical Error Vector" 1747 | jmp "Reset Vector" 1748 | uint8 "ROM Location Bit" 1749 | move 1 1750 | uint32 -hex "Checksum (Chunk 1)" 1751 | uint32 -hex "Checksum (Chunk 2)" 1752 | uint32 -hex "Checksum (Chunk 3)" 1753 | uint32 -hex "Checksum (Chunk 4)" 1754 | move 4 1755 | uint32 "Erase Happy Mac Vector" 1756 | uint32 "Toolbox Init Vector" 1757 | endsection 1758 | 1759 | goto 0x40 1760 | set rom_size [uint32 "ROM Size"] 1761 | 1762 | } 1763 | 1764 | set filename "rom_maps/$hex_checksum" 1765 | if { [file exists $filename] == 1 } { 1766 | section "Symbols" 1767 | sectioncollapse 1768 | set map [open $filename "r"] 1769 | set lines [split [read $map] "\n"] 1770 | close $map 1771 | foreach line $lines { 1772 | # Skip empty lines 1773 | if {$line == ""} { 1774 | continue 1775 | } 1776 | set data [split $line " "] 1777 | scan [lindex $data 1] %x raw_offset 1778 | goto $raw_offset 1779 | entry [lindex $data 0] [lindex $data 1] 1 1780 | } 1781 | endsection 1782 | } 1783 | 1784 | if {[universal_rom $machine]} { 1785 | section "Resources" 1786 | section "Metadata" 1787 | sectioncollapse 1788 | goto 0x1A 1789 | set rsrc_offset [uint32 "Resource Offset"] 1790 | # Unlike DeclROM portions, this is an offset from the base 1791 | goto $rsrc_offset 1792 | set next [uint32 "First Entry Offset"] 1793 | uint8 "Max Valid Index" 1794 | set combo_size [uint8 "Combo Mask Size"] 1795 | uint16 "Combo Mask Version" 1796 | set header_size [uint16 "Header Size"] 1797 | endsection 1798 | 1799 | while {$next != 0} { 1800 | goto $next 1801 | section "Resource" 1802 | sectioncollapse 1803 | set combo_data [hex $combo_size] 1804 | move -$combo_size 1805 | entry "Combo Mask" [combos $combo_data] $combo_size 1806 | move $combo_size 1807 | set next [uint32 "Next Entry Offset"] 1808 | set next_data [uint32 "Data Offset"] 1809 | set type [str 4 macroman "Type"] 1810 | set id [uint16 "ID"] 1811 | uint8 -hex "Attributes" 1812 | set name_length [uint8 "Name Length"] 1813 | if {$name_length > 0} { 1814 | set name [str $name_length macroman "Name"] 1815 | sectionname "$type \[$name\] ($id)" 1816 | } else { 1817 | sectionname "$type ($id)" 1818 | } 1819 | goto $next_data 1820 | move [expr -$header_size] 1821 | if {$header_size == 12} { 1822 | uint32 -hex "More Attributes?" 1823 | } 1824 | set data_size [uint32 "Size"] 1825 | uint32 "Fake pointer?" 1826 | if {[expr $data_size-$header_size] > 0} { 1827 | bytes [expr $data_size-$header_size] "Data" 1828 | } 1829 | # TODO: Add resource handlers 1830 | if {$type == "CURS"} { 1831 | goto $next_data 1832 | bytes 32 "Cursor Data" 1833 | bytes 32 "Cursor Mask" 1834 | bytes 4 "Cursor Point" 1835 | } 1836 | endsection 1837 | } 1838 | endsection 1839 | } elseif {[legacy_resources $minor_ver]} { 1840 | goto $resource_data_offset 1841 | # TODO: Why 28? Inside Macintosh indicates this should be 16+4+2+2 = 24 1842 | # It seems probable this starts with the Single Resource data (Figure 1-13) instead of a real resource fork 1843 | # Thus we have the length, then a copy of the resource header (16), 6 reserved bytes, then our offsets 1844 | # == 28 1845 | move 28 1846 | section "Resources" 1847 | section "Metadata" 1848 | sectioncollapse 1849 | set typelist_offset [uint16 "Type List Offset"] 1850 | set namelist_offset [uint16 "Name List Offset"] 1851 | set num [uint16 "Num Types"] 1852 | endsection 1853 | for {set i 0} {$i <= $num} {incr i} { 1854 | section "Resource" 1855 | sectioncollapse 1856 | section "Metadata" 1857 | sectioncollapse 1858 | set type [ascii 4 "Type"] 1859 | set num_resources [uint16 "Num Resources (0 indexed)"] 1860 | set list_offset [uint16 "List Offset"] 1861 | endsection 1862 | sectionname "$type" 1863 | set cur_pos [pos] 1864 | goto [expr $resource_data_offset + $typelist_offset + $list_offset + 4] 1865 | for {set j 0} {$j <= $num_resources} {incr j} { 1866 | section "Resource" 1867 | sectioncollapse 1868 | set id [uint16 "ID"] 1869 | set name_offset [uint16 "Name Offset"] 1870 | sectionname "$type ($id)" 1871 | if {$name_offset != 0xFFFF} { 1872 | set res_pos [pos] 1873 | # TODO: Why plus 4 again? 1874 | goto [expr $resource_data_offset + $namelist_offset + $name_offset + 4] 1875 | set name_length [uint8 "Name Length"] 1876 | set name [str $name_length "macroman" "Name"] 1877 | sectionname "$type \[$name\] ($id)" 1878 | goto $res_pos 1879 | } 1880 | uint8 -hex "Attributes" 1881 | set rsrc_offset [uint24 "Data Offset"] 1882 | set res_pos [pos] 1883 | # Length includes the attributes and offset, so subtract 1884 | goto [expr $rsrc_offset - 6] 1885 | set data_length [uint16 "Resource Data Length"] 1886 | # TODO: What is this? 1887 | move 4 1888 | # Length include the header so subtract 1889 | bytes [expr $data_length - 6] "Data" 1890 | goto $res_pos 1891 | # This is reserved, so skip 1892 | move 4 1893 | endsection 1894 | } 1895 | goto $cur_pos 1896 | endsection 1897 | } 1898 | endsection 1899 | } 1900 | endsection 1901 | } 1902 | 1903 | # Search for EDisks 1904 | # New Technical Notes HW 13 - Macintosh Portable ROM Expansion 1905 | # These can occur at any 64k boundary 1906 | # TODO: Verify Ginty works correctly 1907 | set edisk_offset 0 1908 | set edisk_count 0 1909 | while {$edisk_offset < [len]} { 1910 | goto $edisk_offset 1911 | move 132 1912 | set edisk_magic [bytes 12] 1913 | 1914 | if {$edisk_magic == "EDisk Gary D"} { 1915 | set edisk_type "edisk" 1916 | } elseif {$edisk_magic == "Ginty HYGWGA"} { 1917 | set edisk_type "ginty" 1918 | } else { 1919 | set edisk_type "" 1920 | } 1921 | 1922 | if {$edisk_type != ""} { 1923 | if {$edisk_type == "edisk"} { 1924 | section "EDisk ($edisk_count)" 1925 | } else { 1926 | section "EDisk (Ginty) ($edisk_count)" 1927 | } 1928 | sectioncollapse 1929 | 1930 | goto $edisk_offset 1931 | 1932 | section "Metadata" 1933 | sectioncollapse 1934 | bytes 128 "Scratch Space" 1935 | uint16 "Block Size" 1936 | uint16 "Version" 1937 | hex 12 "EDisk Magic" 1938 | uint32 "Device Size" 1939 | # TODO: Read times correctly 1940 | uint32 "Format Time" 1941 | uint32 "Format Ticks" 1942 | # TODO: Read checksum field 1943 | uint32 "Format Checksum Offset" 1944 | set data_start [uint32 "Data Start Offset"] 1945 | set data_end [uint32 "Data End Offset"] 1946 | uint32 "Media Icon Offset" 1947 | uint32 "Drive Icon Offset" 1948 | # TODO: Document better 1949 | uint32 "'Get Info Where' String Offset" 1950 | uint32 "Drive Info" 1951 | if {$edisk_type == "edisk"} { 1952 | bytes 328 "Reserved" 1953 | } else { 1954 | # TODO: Read data 1955 | uint32 "EDisk Driver Offset" 1956 | uint32 "Loader Patch Code Offset" 1957 | bytes 320 "Reserved" 1958 | } 1959 | endsection 1960 | 1961 | # Disk images can span past the end of the image and "virtually" appear larger(!), so 1962 | # cap the read. 1963 | # Theoretically you could do wild tricks with this and let memory wraparound map more 1964 | # data into the image but that's pretty unlikely. 1965 | if {[expr $edisk_offset + $data_start + $data_end] > [len]} { 1966 | set data_end [expr [len] - $edisk_offset] 1967 | } 1968 | 1969 | goto $edisk_offset 1970 | move $data_start 1971 | bytes [expr $data_end - $data_start] "Disk Image" 1972 | endsection 1973 | set edisk_count [expr $edisk_count + 1] 1974 | } 1975 | set edisk_offset [expr $edisk_offset + 0x10000] 1976 | } 1977 | 1978 | # TODO: Most of the time these images are just catted at the end, but technically the offset 1979 | # can vary. We're just making a best effort. 1980 | # TODO: We don't read the length either, so we're just reading all the way to the end 1981 | # TODO: Compression could break this, but it's unlikely 1982 | if {[universal_rom $machine] && [len] > $rom_size} { 1983 | goto $rom_size 1984 | set hfs_magic [uint16] 1985 | if {$hfs_magic == 0x4C4B} { 1986 | move -2 1987 | section "bbraun/BMOW Rom Disk" 1988 | sectioncollapse 1989 | bytes eof "Disk Image (Approximate)" 1990 | endsection 1991 | } 1992 | } 1993 | 1994 | # Because every offset after the directory is a uint, we know everything before it must be outside the DeclROM 1995 | # TODO: That's not true? In practice it seems the other data is always after the directory, but it doesn't seem like it has to be 1996 | goto 0 1997 | if {$dir_start > 0} { 1998 | bytes $dir_start "Non DeclROM Data" 1999 | } 2000 | 2001 | } 2002 | --------------------------------------------------------------------------------