diff --git a/.gitignore b/.gitignore index 8b2f502..cd0bba5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -/bin*/ -/CMakeFiles/ -Makefile -*.cmake -*.txt -*.cdp -*.layout +/bin*/ +/CMakeFiles/ +Makefile +CMakeCache.txt +*.cmake +*.cdp +*.layout diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a6c20fc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 2.8.4) +include(FindPkgConfig) + +#set global exe name +set(MAIN "mkpsxiso") + +project(${MAIN}) +#include directory, same for all build types +include_directories(include) + +file(GLOB SOURCES "src/*.cpp") + +find_package(PkgConfig REQUIRED) + +pkg_search_module(TINYXML REQUIRED tinyxml2) + +#include sources that are platform specific +if(MINGW OR MSYS OR CYGWIN OR MSVC) + message(STATUS "WINDOWS BUILD") + + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin_win) + +elseif(APPLE OR WATCOM OR BORLAND) + message(FATAL_ERROR "CAN NOT BUILD FOR APPLE, WATCOM, BORLAND") + +elseif(UNIX) + message(STATUS "LINUX BUILD") + + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin_nix) + +else() + message(FATAL_ERROR "NO BUILD TARGET MATCH") + +endif() + + + add_executable(${MAIN} ${SOURCES}) + +target_link_libraries(${MAIN} ${TINYXML_LIBRARIES}) \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index d159169..89e08fb 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,339 +1,339 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/README.md b/README.md index b23045d..e8da9a0 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,38 @@ -# MKPSXISO -Basically a modern clone of BUILDCD that came included with the PsyQ SDK for generating ISO disc images used for developing PlayStation software (usually homebrew nowadays). The problem with BUILDCD however is that it's an old real-mode DOS program and will not work on 64-bit versions of Windows without a DOS emulator. Also, BUILDCD only produces CD images in an unusual image format used by early CD writers which must be converted to a usable ISO format using a separate tool, making the already slow ISO generation process even slower. - -While other ISO generator tools such as the popular MKISOFS may work, most do not let you control the order of the files by LBA (which is very important when optimizing file orders to speed up seek times) and all do not support mixed-mode XA file integration for streaming files such as XA audio and MDEC STR video... Thus, MKPSXISO was made to replace BUILDCD to aid PlayStation homebrew development on modern systems. - -MKPSXISO more or less replicates BUILDCD's functionality but better, the most notable difference is that MKPSXISO produces ISO images in either iso or bin format so that generated images can immediately be loaded to an emulator or burned to a CD. The image files may also be paired with an optional cue sheet for images containing multiple tracks (usually CD audio tracks). - -Another notable difference is that MKPSXISO injects the Sony license data correctly into the disc image. However, the license data is not provided with the program so one must have a copy of the PsyQ SDK (which can be found in www.psxdev.net) for the license data. This is to avoid possible legal problems when including Sony's license data into open source programs and it's better to be safe than sorry... Besides, there already exists disc patcher tools to inject license data if you don't use the PsyQ SDK anyway. - -## Features -* Outputs in iso/bin format with cue sheet for multi-track ISO projects. -* Injects license data correctly. -* Manual file ordering to allow file order optimization. -* Supports mixed-mode XA file integration for CD-XA streams such as XA audio and STR video. -* Supports injecting CD-DA audio tracks into the generated ISO file. -* Uses XML for ISO project scripting. - -## Binary Download -The latest precompiled Win32 binary of this program can be downloaded here: -[mkpsxiso-1.04.zip](http://lameguy64.github.io/mkpsxiso/mkpsxiso-1.04.zip) - -Older versions: -[mkpsxiso-1.00.zip](http://lameguy64.github.io/mkpsxiso/mkpsxiso-1.00.zip) - -## Compiling -This tool requires tinyxml2 to compile. - -To compile for Windows, simply open the CodeBlocks project file within the CodeBlocks IDE then compile. You must use the MinGW GCC compiler (usually included with CodeBlocks) as the source code uses linux specific functions that are not present in Visual C. - -Compiling this program in a Linux environment is not tested yet. - -## Changelog -**Version 1.04** -* Fixed a bug where you'll get a 'Data track must only be on first track' error when creating an ISO image with more than 2 tracks even when the extra tracks are CD audio. -* Duplicate file and directory entries are no longer possible to add (it'll result to weird problems anyway). - -**Version 1.00** -* Initial release. +# MKPSXISO +Basically a modern clone of BUILDCD that came included with the PsyQ SDK for generating ISO disc images used for developing PlayStation software (usually homebrew nowadays). The problem with BUILDCD however is that it's an old real-mode DOS program and will not work on 64-bit versions of Windows without a DOS emulator. Also, BUILDCD only produces CD images in an unusual image format used by early CD writers which must be converted to a usable ISO format using a separate tool, making the already slow ISO generation process even slower. + +While other ISO generator tools such as the popular MKISOFS may work, most do not let you control the order of the files by LBA (which is very important when optimizing file orders to speed up seek times) and all do not support mixed-mode XA file integration for streaming files such as XA audio and MDEC STR video... Thus, MKPSXISO was made to replace BUILDCD to aid PlayStation homebrew development on modern systems. + +MKPSXISO more or less replicates BUILDCD's functionality but better, the most notable difference is that MKPSXISO produces ISO images in either iso or bin format so that generated images can immediately be loaded to an emulator or burned to a CD. The image files may also be paired with an optional cue sheet for images containing multiple tracks (usually CD audio tracks). + +Another notable difference is that MKPSXISO injects the Sony license data correctly into the disc image. However, the license data is not provided with the program so one must have a copy of the PsyQ SDK (which can be found in www.psxdev.net) for the license data. This is to avoid possible legal problems when including Sony's license data into open source programs and it's better to be safe than sorry... Besides, there already exists disc patcher tools to inject license data if you don't use the PsyQ SDK anyway. + +## Features +* Outputs in iso/bin format with cue sheet for multi-track ISO projects. +* Injects license data correctly. +* Manual file ordering to allow file order optimization. +* Supports mixed-mode XA file integration for CD-XA streams such as XA audio and STR video. +* Supports injecting CD-DA audio tracks into the generated ISO file. +* Uses XML for ISO project scripting. + +## Binary Download +The latest precompiled Win32 binary of this program can be downloaded here: +[mkpsxiso-1.04.zip](http://lameguy64.github.io/mkpsxiso/mkpsxiso-1.04.zip) + +Older versions: +[mkpsxiso-1.00.zip](http://lameguy64.github.io/mkpsxiso/mkpsxiso-1.00.zip) + +## Compiling +This tool requires tinyxml2 to compile. + +To compile for Windows, simply open the CodeBlocks project file within the CodeBlocks IDE then compile. You must use the MinGW GCC compiler (usually included with CodeBlocks) as the source code uses linux specific functions that are not present in Visual C. + +Compiling this program in a Linux environment is not tested yet. + +## Changelog +**Version 1.04** +* Fixed a bug where you'll get a 'Data track must only be on first track' error when creating an ISO image with more than 2 tracks even when the extra tracks are CD audio. +* Duplicate file and directory entries are no longer possible to add (it'll result to weird problems anyway). + +**Version 1.00** +* Initial release. diff --git a/examples/example.xml b/examples/example.xml index 10a67ec..ef475af 100644 --- a/examples/example.xml +++ b/examples/example.xml @@ -1,121 +1,121 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/include/cd.h b/include/cd.h index bad876c..cd65598 100644 --- a/include/cd.h +++ b/include/cd.h @@ -1,220 +1,220 @@ -#ifndef _CD_H -#define _CD_H - -#include - -#ifdef __WIN32__ -#include -#else -#include -#endif - -// Sector size in bytes (do not change) -#define CD_SECTOR_SIZE 2352 - -// CD and ISO 9660 reader namespace -namespace cd { - - /// Structure for a mode 2 form 1 sector (used in regular files) - typedef struct { - unsigned char sync[12]; /// Sync pattern (usually 00 FF FF FF FF FF FF FF FF FF FF 00) - unsigned char addr[3]; /// Sector address (see below for encoding details) - unsigned char mode; /// Mode (usually 2 for Mode 2 Form 1/2 sectors) - unsigned char subHead[8]; /// Sub-header (00 00 08 00 00 00 08 00 for Form 1 data sectors) - unsigned char data[2048]; /// Data (form 1) - unsigned char edc[4]; /// Error-detection code (CRC32 of data area) - unsigned char ecc[276]; /// Error-correction code (uses Reed-Solomon ECC algorithm) - } SECTOR_M2F1; - - /** Regular data files are usually stored in this sector format as it has ECC error correction which - * is important for program data and other sensitive data files. - * - * The 3 address bytes of an M2F1 and M2F2 format sector are actually just timecode values. The 1st - * byte is minutes, 2nd byte is seconds and the 3rd byte is frames (or sectors, 75 per second on CD). - * - * The unusual thing about how the address bytes are encoded is that values must be specified in hex - * rather than decimal (0x20 instead of 20, 0x15 instead of 15) so values must be converted by using - * the following algorithm: - * - * (16*(v/10))+(v%10) - * - * So, for a sector address of 2 minutes, 30 seconds and 35 frames in timecode format, it should look - * like this in hex: - * - * 0x02 0x35 0x30 - * - */ - - /// Structure for a mode 2 form 2 sector (used in STR/XA files) - typedef struct { - unsigned char sync[12]; /// Sync pattern (usually 00 FF FF FF FF FF FF FF FF FF FF 00) - unsigned char addr[3]; /// Sector address (a 24-bit big-endian integer. starts at 200, 201 an onwards) - unsigned char mode; /// Mode (usually 2 for Mode 2 Form 1/2 sectors) - unsigned char data[2336]; /// 8 bytes Subheader, 2324 bytes Data (form 2), and 4 bytes ECC - } SECTOR_M2F2; - - // Set struct alignment to 1 because the ISO file system is not very memory alignment friendly which will - // result to alignment issues when reading data entries with structs. - #pragma pack(push, 1) - - /// Structure of a double-endian unsigned short word - typedef struct { - unsigned short lsb; /// LSB format 16-bit word - unsigned short msb; /// MSB format 16-bit word - } ISO_USHORT_PAIR; - - /// Structure of a double-endian unsigned int word - typedef struct { - unsigned int lsb; /// LSB format 32-bit word - unsigned int msb; /// MSB format 32-bit word - } ISO_UINT_PAIR; - - /// ISO descriptor header structure - typedef struct { - unsigned char type; /// Volume descriptor type (1 is descriptor, 255 is descriptor terminator) - char id[5]; /// Volume descriptor ID (always CD001) - unsigned short version; /// Volume descriptor version (always 0x01) - } ISO_DESCRIPTOR_HEADER; - - /// Structure of a date stamp for ISO_DIR_ENTRY structure - typedef struct { - unsigned char year; /// number of years since 1900 - unsigned char month; /// month, where 1=January, 2=February, etc. - unsigned char day; /// day of month, in the range from 1 to 31 - unsigned char hour; /// hour, in the range from 0 to 23 - unsigned char minute; /// minute, in the range from 0 to 59 - unsigned char second; /// Second, in the range from 0 to 59 - unsigned char GMToffs; /// Greenwich Mean Time offset - } ISO_DATESTAMP; - - /// Structure of an ISO path table entry (specifically for the cd::IsoReader class) - typedef struct { - unsigned char nameLength; /// Name length (or 1 for the root directory) - unsigned char extLength; /// Number of sectors in extended attribute record - unsigned int dirOffs; /// Number of the first sector in the directory, as a double word - short dirLevel; /// Index of the directory record's parent directory - char* name; /// Name (0 for the root directory) - /// If nameLength is odd numbered, a padding byte will be present after the identifier text. - } ISO_PATHTABLE_ENTRY; - - typedef struct { - // Directory entry length (variable, use for parsing through entries) - unsigned char entryLength; - // Extended entry data length (always 0) - unsigned char extLength; - // Points to the LBA of the file/directory entry - ISO_UINT_PAIR entryOffs; - // Size of the file/directory entry - ISO_UINT_PAIR entrySize; - // Date & time stamp of entry - ISO_DATESTAMP entryDate; - // File flags (0x02 for directories, 0x00 for files) - unsigned char flags; - // Unit size (usually 0 even with Form 2 files such as STR/XA) - unsigned char fileUnitSize; - // Interleave gap size (usually 0 even with Form 2 files such as STR/XA) - unsigned char interleaveGapSize; - // Volume sequence number (always 1) - ISO_USHORT_PAIR volSeqNum; - // Identifier (file/directory name) length in bytes - unsigned char identifierLen; - // Pointer to identifier (placed here for convenience) - // If identifierLen is even numbered, a padding byte will be present after the identifier text. - char* identifier; - void* extData; - } ISO_DIR_ENTRY; - - // XA attribute struct (located right after the identifier string) - typedef struct { - unsigned int pad; // Nothing but null bytes - unsigned short type; // XA attribute (0x8800 for directories, 0x800 for regular files, 0x0 for XA Form 2 files) - char id[2]; // Always XA - unsigned char pad2[6]; // Nothing but null bytes - } ISO_XA_ATTRIB; - - typedef struct { - unsigned char entryLength; // Always 34 bytes - unsigned char extLength; // Always 0 - ISO_UINT_PAIR entryOffs; // Should point to LBA 22 - ISO_UINT_PAIR entrySize; // Size of entry extent - ISO_DATESTAMP entryDate; // Record date and time - unsigned char flags; // File flags - unsigned char fileUnitSize; - unsigned char interleaveGapSize; - ISO_USHORT_PAIR volSeqNum; - unsigned char identifierLen; // 0x01 - unsigned char identifier; // 0x01 - } ISO_ROOTDIR_HEADER; - - // ISO descriptor structure - typedef struct { - - // ISO descriptor header - ISO_DESCRIPTOR_HEADER header; - // System ID (always PLAYSTATION) - char systemID[32]; - // Volume ID (or label, can be blank or anything) - char volumeID[32]; - // Unused null bytes - unsigned char pad2[8]; - // Size of volume in sector units - ISO_UINT_PAIR volumeSize; - // Unused null bytes - unsigned char pad3[32]; - // Number of discs in this volume set (always 1 for single volume) - ISO_USHORT_PAIR volumeSetSize; - // Number of this disc in volume set (always 1 for single volume) - ISO_USHORT_PAIR volumeSeqNumber; - // Size of sector in bytes (always 2352 bytes) - ISO_USHORT_PAIR sectorSize; - // Path table size in bytes (applies to all the path tables) - ISO_UINT_PAIR pathTableSize; - // LBA to Type-L path table - unsigned int pathTable1Offs; - // LBA to optional Type-L path table (usually a copy of the primary path table) - unsigned int pathTable2Offs; - // LBA to Type-L path table but with MSB format values - unsigned int pathTable1MSBoffs; - // LBA to optional Type-L path table but with MSB format values (usually a copy of the main path table) - unsigned int pathTable2MSBoffs; - // Directory entry for the root directory (similar to a directory entry) - ISO_ROOTDIR_HEADER rootDirRecord; - // Volume set identifier (can be blank or anything) - char volumeSetIdentifier[128]; - // Publisher identifier (can be blank or anything) - char publisherIdentifier[128]; - // Data preparer identifier (can be blank or anything) - char dataPreparerIdentifier[128]; - // Application identifier (always PLAYSTATION) - char applicationIdentifier[128]; - // Copyright file in the file system identifier (can be blank or anything) - char copyrightFileIdentifier[37]; - // Abstract file in the file system identifier (can be blank or anything) - char abstractFileIdentifier[37]; - // Bibliographical file identifier in the file system (can be blank or anything) - char bibliographicFilelIdentifier[37]; - // Volume create date (in text format YYYYMMDDHHMMSSMMGG) - char volumeCreateDate[17]; - // Volume modify date (in text format YYYYMMDDHHMMSSMMGG) - char volumeModifyDate[17]; - // Volume expiry date (in text format YYYYMMDDHHMMSSMMGG) - char volumeExpiryDate[17]; - // Volume effective date (in text format YYYYMMDDHHMMSSMMGG) - char volumeEffeciveDate[17]; - // File structure version (always 1) - unsigned char fileStructVersion; - // Padding - unsigned char dummy0; - // Application specific data (says CD-XA001 at [141], the rest are null bytes) - unsigned char appData[512]; - // Padding - unsigned char pad4[653]; - - } ISO_DESCRIPTOR; - - // Leave non-aligned structure packing - #pragma pack(pop) - -} - -#endif // _CD_H +#ifndef _CD_H +#define _CD_H + +#include + +#ifdef __WIN32__ +#include +#else +#include +#endif + +// Sector size in bytes (do not change) +#define CD_SECTOR_SIZE 2352 + +// CD and ISO 9660 reader namespace +namespace cd { + + /// Structure for a mode 2 form 1 sector (used in regular files) + typedef struct { + unsigned char sync[12]; /// Sync pattern (usually 00 FF FF FF FF FF FF FF FF FF FF 00) + unsigned char addr[3]; /// Sector address (see below for encoding details) + unsigned char mode; /// Mode (usually 2 for Mode 2 Form 1/2 sectors) + unsigned char subHead[8]; /// Sub-header (00 00 08 00 00 00 08 00 for Form 1 data sectors) + unsigned char data[2048]; /// Data (form 1) + unsigned char edc[4]; /// Error-detection code (CRC32 of data area) + unsigned char ecc[276]; /// Error-correction code (uses Reed-Solomon ECC algorithm) + } SECTOR_M2F1; + + /** Regular data files are usually stored in this sector format as it has ECC error correction which + * is important for program data and other sensitive data files. + * + * The 3 address bytes of an M2F1 and M2F2 format sector are actually just timecode values. The 1st + * byte is minutes, 2nd byte is seconds and the 3rd byte is frames (or sectors, 75 per second on CD). + * + * The unusual thing about how the address bytes are encoded is that values must be specified in hex + * rather than decimal (0x20 instead of 20, 0x15 instead of 15) so values must be converted by using + * the following algorithm: + * + * (16*(v/10))+(v%10) + * + * So, for a sector address of 2 minutes, 30 seconds and 35 frames in timecode format, it should look + * like this in hex: + * + * 0x02 0x35 0x30 + * + */ + + /// Structure for a mode 2 form 2 sector (used in STR/XA files) + typedef struct { + unsigned char sync[12]; /// Sync pattern (usually 00 FF FF FF FF FF FF FF FF FF FF 00) + unsigned char addr[3]; /// Sector address (a 24-bit big-endian integer. starts at 200, 201 an onwards) + unsigned char mode; /// Mode (usually 2 for Mode 2 Form 1/2 sectors) + unsigned char data[2336]; /// 8 bytes Subheader, 2324 bytes Data (form 2), and 4 bytes ECC + } SECTOR_M2F2; + + // Set struct alignment to 1 because the ISO file system is not very memory alignment friendly which will + // result to alignment issues when reading data entries with structs. + #pragma pack(push, 1) + + /// Structure of a double-endian unsigned short word + typedef struct { + unsigned short lsb; /// LSB format 16-bit word + unsigned short msb; /// MSB format 16-bit word + } ISO_USHORT_PAIR; + + /// Structure of a double-endian unsigned int word + typedef struct { + unsigned int lsb; /// LSB format 32-bit word + unsigned int msb; /// MSB format 32-bit word + } ISO_UINT_PAIR; + + /// ISO descriptor header structure + typedef struct { + unsigned char type; /// Volume descriptor type (1 is descriptor, 255 is descriptor terminator) + char id[5]; /// Volume descriptor ID (always CD001) + unsigned short version; /// Volume descriptor version (always 0x01) + } ISO_DESCRIPTOR_HEADER; + + /// Structure of a date stamp for ISO_DIR_ENTRY structure + typedef struct { + unsigned char year; /// number of years since 1900 + unsigned char month; /// month, where 1=January, 2=February, etc. + unsigned char day; /// day of month, in the range from 1 to 31 + unsigned char hour; /// hour, in the range from 0 to 23 + unsigned char minute; /// minute, in the range from 0 to 59 + unsigned char second; /// Second, in the range from 0 to 59 + unsigned char GMToffs; /// Greenwich Mean Time offset + } ISO_DATESTAMP; + + /// Structure of an ISO path table entry (specifically for the cd::IsoReader class) + typedef struct { + unsigned char nameLength; /// Name length (or 1 for the root directory) + unsigned char extLength; /// Number of sectors in extended attribute record + unsigned int dirOffs; /// Number of the first sector in the directory, as a double word + short dirLevel; /// Index of the directory record's parent directory + char* name; /// Name (0 for the root directory) + /// If nameLength is odd numbered, a padding byte will be present after the identifier text. + } ISO_PATHTABLE_ENTRY; + + typedef struct { + // Directory entry length (variable, use for parsing through entries) + unsigned char entryLength; + // Extended entry data length (always 0) + unsigned char extLength; + // Points to the LBA of the file/directory entry + ISO_UINT_PAIR entryOffs; + // Size of the file/directory entry + ISO_UINT_PAIR entrySize; + // Date & time stamp of entry + ISO_DATESTAMP entryDate; + // File flags (0x02 for directories, 0x00 for files) + unsigned char flags; + // Unit size (usually 0 even with Form 2 files such as STR/XA) + unsigned char fileUnitSize; + // Interleave gap size (usually 0 even with Form 2 files such as STR/XA) + unsigned char interleaveGapSize; + // Volume sequence number (always 1) + ISO_USHORT_PAIR volSeqNum; + // Identifier (file/directory name) length in bytes + unsigned char identifierLen; + // Pointer to identifier (placed here for convenience) + // If identifierLen is even numbered, a padding byte will be present after the identifier text. + char* identifier; + void* extData; + } ISO_DIR_ENTRY; + + // XA attribute struct (located right after the identifier string) + typedef struct { + unsigned int pad; // Nothing but null bytes + unsigned short type; // XA attribute (0x8800 for directories, 0x800 for regular files, 0x0 for XA Form 2 files) + char id[2]; // Always XA + unsigned char pad2[6]; // Nothing but null bytes + } ISO_XA_ATTRIB; + + typedef struct { + unsigned char entryLength; // Always 34 bytes + unsigned char extLength; // Always 0 + ISO_UINT_PAIR entryOffs; // Should point to LBA 22 + ISO_UINT_PAIR entrySize; // Size of entry extent + ISO_DATESTAMP entryDate; // Record date and time + unsigned char flags; // File flags + unsigned char fileUnitSize; + unsigned char interleaveGapSize; + ISO_USHORT_PAIR volSeqNum; + unsigned char identifierLen; // 0x01 + unsigned char identifier; // 0x01 + } ISO_ROOTDIR_HEADER; + + // ISO descriptor structure + typedef struct { + + // ISO descriptor header + ISO_DESCRIPTOR_HEADER header; + // System ID (always PLAYSTATION) + char systemID[32]; + // Volume ID (or label, can be blank or anything) + char volumeID[32]; + // Unused null bytes + unsigned char pad2[8]; + // Size of volume in sector units + ISO_UINT_PAIR volumeSize; + // Unused null bytes + unsigned char pad3[32]; + // Number of discs in this volume set (always 1 for single volume) + ISO_USHORT_PAIR volumeSetSize; + // Number of this disc in volume set (always 1 for single volume) + ISO_USHORT_PAIR volumeSeqNumber; + // Size of sector in bytes (always 2352 bytes) + ISO_USHORT_PAIR sectorSize; + // Path table size in bytes (applies to all the path tables) + ISO_UINT_PAIR pathTableSize; + // LBA to Type-L path table + unsigned int pathTable1Offs; + // LBA to optional Type-L path table (usually a copy of the primary path table) + unsigned int pathTable2Offs; + // LBA to Type-L path table but with MSB format values + unsigned int pathTable1MSBoffs; + // LBA to optional Type-L path table but with MSB format values (usually a copy of the main path table) + unsigned int pathTable2MSBoffs; + // Directory entry for the root directory (similar to a directory entry) + ISO_ROOTDIR_HEADER rootDirRecord; + // Volume set identifier (can be blank or anything) + char volumeSetIdentifier[128]; + // Publisher identifier (can be blank or anything) + char publisherIdentifier[128]; + // Data preparer identifier (can be blank or anything) + char dataPreparerIdentifier[128]; + // Application identifier (always PLAYSTATION) + char applicationIdentifier[128]; + // Copyright file in the file system identifier (can be blank or anything) + char copyrightFileIdentifier[37]; + // Abstract file in the file system identifier (can be blank or anything) + char abstractFileIdentifier[37]; + // Bibliographical file identifier in the file system (can be blank or anything) + char bibliographicFilelIdentifier[37]; + // Volume create date (in text format YYYYMMDDHHMMSSMMGG) + char volumeCreateDate[17]; + // Volume modify date (in text format YYYYMMDDHHMMSSMMGG) + char volumeModifyDate[17]; + // Volume expiry date (in text format YYYYMMDDHHMMSSMMGG) + char volumeExpiryDate[17]; + // Volume effective date (in text format YYYYMMDDHHMMSSMMGG) + char volumeEffeciveDate[17]; + // File structure version (always 1) + unsigned char fileStructVersion; + // Padding + unsigned char dummy0; + // Application specific data (says CD-XA001 at [141], the rest are null bytes) + unsigned char appData[512]; + // Padding + unsigned char pad4[653]; + + } ISO_DESCRIPTOR; + + // Leave non-aligned structure packing + #pragma pack(pop) + +} + +#endif // _CD_H diff --git a/include/cdwriter.h b/include/cdwriter.h index e2f062b..f234b9f 100644 --- a/include/cdwriter.h +++ b/include/cdwriter.h @@ -1,61 +1,61 @@ -#ifndef _CDWRITER_H -#define _CDWRITER_H - -#include "cd.h" -#include "edcecc.h" - -namespace cd { - -class IsoWriter { - - FILE* filePtr; - unsigned char subHeadBuff[12]; - unsigned char sectorBuff[CD_SECTOR_SIZE]; - SECTOR_M2F1* sectorM2F1; - SECTOR_M2F2* sectorM2F2; - - EDCECC edcEccGen; - - int currentSector; - int currentByte; - int bytesWritten; - int lastSectorType; - - void PrepSector(int edcEccMode); - - public: - - enum { - EdcEccNone = 0, - EdcEccForm1, - EdcEccForm2, - }; - - IsoWriter(); - virtual ~IsoWriter(); - - bool Create(const char* fileName); - - int SeekToSector(int sector); - - int SeekToEnd(); - - int CurrentSector(); - - void SetSubheader(unsigned char* data); - - size_t WriteBytes(void* data, size_t bytes, int edcEccEncode); - size_t WriteBytesXA(void* data, size_t bytes, int edcEccEncode); - size_t WriteBytesRaw(void* data, size_t bytes); - - void Close(); - - }; - - void SwapBytes(void *var, int size); - void SetPair16(cd::ISO_USHORT_PAIR* pair, unsigned short val); - void SetPair32(cd::ISO_UINT_PAIR* pair, unsigned int val); - -}; - -#endif // _CDWRITER_H +#ifndef _CDWRITER_H +#define _CDWRITER_H + +#include "cd.h" +#include "edcecc.h" + +namespace cd { + +class IsoWriter { + + FILE* filePtr; + unsigned char subHeadBuff[12]; + unsigned char sectorBuff[CD_SECTOR_SIZE]; + SECTOR_M2F1* sectorM2F1; + SECTOR_M2F2* sectorM2F2; + + EDCECC edcEccGen; + + int currentSector; + int currentByte; + int bytesWritten; + int lastSectorType; + + void PrepSector(int edcEccMode); + + public: + + enum { + EdcEccNone = 0, + EdcEccForm1, + EdcEccForm2, + }; + + IsoWriter(); + virtual ~IsoWriter(); + + bool Create(const char* fileName); + + int SeekToSector(int sector); + + int SeekToEnd(); + + int CurrentSector(); + + void SetSubheader(unsigned char* data); + + size_t WriteBytes(void* data, size_t bytes, int edcEccEncode); + size_t WriteBytesXA(void* data, size_t bytes, int edcEccEncode); + size_t WriteBytesRaw(void* data, size_t bytes); + + void Close(); + + }; + + void SwapBytes(void *var, int size); + void SetPair16(cd::ISO_USHORT_PAIR* pair, unsigned short val); + void SetPair32(cd::ISO_UINT_PAIR* pair, unsigned int val); + +}; + +#endif // _CDWRITER_H diff --git a/include/edcecc.h b/include/edcecc.h index a42c038..d32b3fa 100644 --- a/include/edcecc.h +++ b/include/edcecc.h @@ -1,33 +1,33 @@ -#ifndef _EDC_ECC_H -#define _EDC_ECC_H - -#ifdef __WIN32__ -#include -#else -#include -#endif - -class EDCECC { - - // Tables for EDC and ECC calculation - unsigned char ecc_f_lut[256]; - unsigned char ecc_b_lut[256]; - unsigned int edc_lut[256]; - -public: - - // Initializer - EDCECC(); - - // Computes the EDC of *src and returns the result - unsigned int ComputeEdcBlockPartial(unsigned int edc, const unsigned char *src, int len); - - // Computes the EDC of *src and stores the result to an unsigned char array *dest - void ComputeEdcBlock(const unsigned char *src, int len, unsigned char *dest); - - // Computes the ECC data of *src and stores the result to an unsigned char array *dest - void ComputeEccBlock(unsigned char *src, unsigned int major_count, unsigned int minor_count, unsigned int major_mult, unsigned int minor_inc, unsigned char *dest); - -}; - -#endif // _EDC_ECC_H +#ifndef _EDC_ECC_H +#define _EDC_ECC_H + +#ifdef __WIN32__ +#include +#else +#include +#endif + +class EDCECC { + + // Tables for EDC and ECC calculation + unsigned char ecc_f_lut[256]; + unsigned char ecc_b_lut[256]; + unsigned int edc_lut[256]; + +public: + + // Initializer + EDCECC(); + + // Computes the EDC of *src and returns the result + unsigned int ComputeEdcBlockPartial(unsigned int edc, const unsigned char *src, int len); + + // Computes the EDC of *src and stores the result to an unsigned char array *dest + void ComputeEdcBlock(const unsigned char *src, int len, unsigned char *dest); + + // Computes the ECC data of *src and stores the result to an unsigned char array *dest + void ComputeEccBlock(unsigned char *src, unsigned int major_count, unsigned int minor_count, unsigned int major_mult, unsigned int minor_inc, unsigned char *dest); + +}; + +#endif // _EDC_ECC_H diff --git a/include/global.h b/include/global.h index da44723..a547698 100644 --- a/include/global.h +++ b/include/global.h @@ -1,13 +1,13 @@ -#ifndef _GLOBAL_H -#define _GLOBAL_H - -#include - -namespace global { - - extern time_t BuildTime; - extern int QuietMode; - -}; - -#endif // _GLOBAL_H +#ifndef _GLOBAL_H +#define _GLOBAL_H + +#include + +namespace global { + + extern time_t BuildTime; + extern int QuietMode; + +}; + +#endif // _GLOBAL_H diff --git a/include/iso.h b/include/iso.h index 2234b85..1562117 100644 --- a/include/iso.h +++ b/include/iso.h @@ -1,148 +1,148 @@ -#ifndef _ISO_H -#define _ISO_H - -#include -#include -#include -#include -#include -#include - -#include "cdwriter.h" - -namespace iso { - - enum EntryType { - EntryFile = 0, - EntryXA, - EntrySTR, - EntryDir, - }; - - typedef struct { - const char* SystemID; - const char* VolumeID; - const char* VolumeSet; - const char* Publisher; - const char* DataPreparer; - const char* Application; - } IDENTIFIERS; - - typedef struct { - - char* id; /// Entry identifier (NULL if invisible dummy) - int length; /// Length of file in bytes - int lba; /// File LBA (in sectors) - - char* srcfile; /// Filename with path to source file (NULL if directory or dummy) - int type; /// File type (0 - file, 1 - directory) - void* subdir; - - cd::ISO_DATESTAMP date; - - } DIRENTRY; - - class DirTreeClass { - - int dirIndex; - - /// Internal function for generating and writing directory records - int WriteDirEntries(cd::IsoWriter* writer, int lastLBA); - - /// Internal function for recursive path table length calculation - int CalculatePathTableLenSub(DIRENTRY* dirEntry); - - /// Internal function for recursive path table generation - unsigned char* GenPathTableSub(unsigned char* buff, DIRENTRY* dirEntry, int parentIndex, int msb); - - int recordLBA; - - public: - - int numentries; - DIRENTRY* entries; - - - DirTreeClass(); - virtual ~DirTreeClass(); - - /** Calculates the length of the directory record to be produced by this class in bytes. - * - * Returns: Length of directory record in bytes. - */ - int CalculateDirEntryLen(); - - /** Calculates the LBA of all file and directory entries in the directory record and returns the next LBA - * address. - * - * lba - LBA address where the first directory record begins (always 22). - */ - int CalculateTreeLBA(int lba = 22); - - /** Adds a file entry to the directory record. - * - * *id - The name of the file entry. It will be converted to uppercase and adds the file version - * identifier (;1) automatically. - * type - The type of file to add, EntryFile is for standard files, EntryXA is for XA streams and - * EntryStr is for STR streams. To add directories, use AddDirEntry(). - * *srcfile - Path and filename to the source file. - */ - int AddFileEntry(const char* id, int type, const char* srcfile); - - /** Adds an invisible dummy file entry to the directory record. Its invisible because its file entry - * is not actually added to the directory record. - * - * sectors - The size of the dummy file in sector units (1 = 2048 bytes, 1024 = 2MB). - */ - void AddDummyEntry(int sectors); - - /** Generates a path table of all directories and subdirectories within this class' directory record. - * - * *buff - Pointer to a 2048 byte buffer to generate the path table to. - * msb - If true, generates a path table encoded in big-endian format, little-endian otherwise. - * - * Returns: Length of path table in bytes. - */ - int GeneratePathTable(unsigned char* buff, int msb); - - /** Adds a subdirectory to the directory record. - * - * *id - The name of the subdirectory to add. It will be converted to uppercase automatically. - * - * Returns: Pointer to another DirTreeClass for accessing the directory record of the subdirectory. - */ - DirTreeClass* AddSubDirEntry(const char* id); - - /** Writes the source files assigned to the directory entries to a CD image. Its recommended to execute - * this first before writing the actual file system. - * - * *writer - Pointer to a cd::IsoWriter class that is ready for writing. - */ - int WriteFiles(cd::IsoWriter* writer); - - /** Writes the file system of the directory records to a CD image. Execute this after the source files - * have been written to the CD image. - * - * *writer - Pointer to a cd::IsoWriter class that is ready for writing. - * lastDirLBA - Used for recursive calls, always set to 0. - */ - int WriteDirectoryRecords(cd::IsoWriter* writer, int lastDirLBA); - - void SortDirEntries(); - - int CalculatePathTableLen(); - - int GetFileCountTotal(); - int GetDirCountTotal(); - - void PrintEntries(); - - }; - - void WriteLicenseData(cd::IsoWriter* writer, void* data); - - void WriteDescriptor(cd::IsoWriter* writer, IDENTIFIERS id, DirTreeClass* dirTree, int imageLen); - -}; - -#endif +#ifndef _ISO_H +#define _ISO_H + +#include +#include +#include +#include +#include +#include + +#include "cdwriter.h" + +namespace iso { + + enum EntryType { + EntryFile = 0, + EntryXA, + EntrySTR, + EntryDir, + }; + + typedef struct { + const char* SystemID; + const char* VolumeID; + const char* VolumeSet; + const char* Publisher; + const char* DataPreparer; + const char* Application; + } IDENTIFIERS; + + typedef struct { + + char* id; /// Entry identifier (NULL if invisible dummy) + int length; /// Length of file in bytes + int lba; /// File LBA (in sectors) + + char* srcfile; /// Filename with path to source file (NULL if directory or dummy) + int type; /// File type (0 - file, 1 - directory) + void* subdir; + + cd::ISO_DATESTAMP date; + + } DIRENTRY; + + class DirTreeClass { + + int dirIndex; + + /// Internal function for generating and writing directory records + int WriteDirEntries(cd::IsoWriter* writer, int lastLBA); + + /// Internal function for recursive path table length calculation + int CalculatePathTableLenSub(DIRENTRY* dirEntry); + + /// Internal function for recursive path table generation + unsigned char* GenPathTableSub(unsigned char* buff, DIRENTRY* dirEntry, int parentIndex, int msb); + + int recordLBA; + + public: + + int numentries; + DIRENTRY* entries; + + + DirTreeClass(); + virtual ~DirTreeClass(); + + /** Calculates the length of the directory record to be produced by this class in bytes. + * + * Returns: Length of directory record in bytes. + */ + int CalculateDirEntryLen(); + + /** Calculates the LBA of all file and directory entries in the directory record and returns the next LBA + * address. + * + * lba - LBA address where the first directory record begins (always 22). + */ + int CalculateTreeLBA(int lba = 22); + + /** Adds a file entry to the directory record. + * + * *id - The name of the file entry. It will be converted to uppercase and adds the file version + * identifier (;1) automatically. + * type - The type of file to add, EntryFile is for standard files, EntryXA is for XA streams and + * EntryStr is for STR streams. To add directories, use AddDirEntry(). + * *srcfile - Path and filename to the source file. + */ + int AddFileEntry(const char* id, int type, const char* srcfile); + + /** Adds an invisible dummy file entry to the directory record. Its invisible because its file entry + * is not actually added to the directory record. + * + * sectors - The size of the dummy file in sector units (1 = 2048 bytes, 1024 = 2MB). + */ + void AddDummyEntry(int sectors); + + /** Generates a path table of all directories and subdirectories within this class' directory record. + * + * *buff - Pointer to a 2048 byte buffer to generate the path table to. + * msb - If true, generates a path table encoded in big-endian format, little-endian otherwise. + * + * Returns: Length of path table in bytes. + */ + int GeneratePathTable(unsigned char* buff, int msb); + + /** Adds a subdirectory to the directory record. + * + * *id - The name of the subdirectory to add. It will be converted to uppercase automatically. + * + * Returns: Pointer to another DirTreeClass for accessing the directory record of the subdirectory. + */ + DirTreeClass* AddSubDirEntry(const char* id); + + /** Writes the source files assigned to the directory entries to a CD image. Its recommended to execute + * this first before writing the actual file system. + * + * *writer - Pointer to a cd::IsoWriter class that is ready for writing. + */ + int WriteFiles(cd::IsoWriter* writer); + + /** Writes the file system of the directory records to a CD image. Execute this after the source files + * have been written to the CD image. + * + * *writer - Pointer to a cd::IsoWriter class that is ready for writing. + * lastDirLBA - Used for recursive calls, always set to 0. + */ + int WriteDirectoryRecords(cd::IsoWriter* writer, int lastDirLBA); + + void SortDirEntries(); + + int CalculatePathTableLen(); + + int GetFileCountTotal(); + int GetDirCountTotal(); + + void PrintEntries(); + + }; + + void WriteLicenseData(cd::IsoWriter* writer, void* data); + + void WriteDescriptor(cd::IsoWriter* writer, IDENTIFIERS id, DirTreeClass* dirTree, int imageLen); + +}; + +#endif diff --git a/src/cdwriter.cpp b/src/cdwriter.cpp index 040e107..2df280d 100644 --- a/src/cdwriter.cpp +++ b/src/cdwriter.cpp @@ -1,355 +1,355 @@ -#include -#include -#include "cdwriter.h" -#include "edcecc.h" - - -void cd::SwapBytes(void *var, int size) { - - unsigned char temp[size]; - - memcpy(temp, var, size); - for(short i=0; ilsb = val; - pair->msb = val; - - SwapBytes(&pair->msb, 2); - -} - -void cd::SetPair32(cd::ISO_UINT_PAIR* pair, unsigned int val) { - - pair->lsb = val; - pair->msb = val; - - SwapBytes(&pair->msb, 4); - -} - - -cd::IsoWriter::IsoWriter() { - - cd::IsoWriter::filePtr = NULL; - cd::IsoWriter::sectorM2F1 = NULL; - cd::IsoWriter::sectorM2F2 = NULL; - cd::IsoWriter::currentByte = 0; - cd::IsoWriter::currentSector = 0; - cd::IsoWriter::bytesWritten = 0; - cd::IsoWriter::lastSectorType = 0; - - memset(cd::IsoWriter::sectorBuff, 0, CD_SECTOR_SIZE); - -} - -cd::IsoWriter::~IsoWriter() { - - if (cd::IsoWriter::filePtr != NULL) - fclose(cd::IsoWriter::filePtr); - - cd::IsoWriter::filePtr = NULL; - -} - -void cd::IsoWriter::PrepSector(int edcEccMode) { - - memset(cd::IsoWriter::sectorM2F1->sync, 0xff, 12); - cd::IsoWriter::sectorM2F1->sync[0] = 0x00; - cd::IsoWriter::sectorM2F1->sync[11] = 0x00; - - int taddr,addr = 150+cd::IsoWriter::currentSector; // Sector addresses always start at LBA 150 - - taddr = addr%75; - cd::IsoWriter::sectorM2F1->addr[2] = (16*(taddr/10))+(taddr%10); - - taddr = (addr/75)%60; - cd::IsoWriter::sectorM2F1->addr[1] = (16*(taddr/10))+(taddr%10); - - taddr = (addr/75)/60; - cd::IsoWriter::sectorM2F1->addr[0] = (16*(taddr/10))+(taddr%10); - - cd::IsoWriter::sectorM2F1->mode = 0x02; - - if (edcEccMode == cd::IsoWriter::EdcEccForm1) { - - // Encode EDC data - edcEccGen.ComputeEdcBlock(cd::IsoWriter::sectorM2F1->subHead, 0x808, cd::IsoWriter::sectorM2F1->edc); - - // Encode ECC data - unsigned char tempAddr[4]; - - for(int i=0; i<4; i++) { - - tempAddr[i] = cd::IsoWriter::sectorM2F1->addr[i]; - cd::IsoWriter::sectorM2F1->addr[i] = 0x00; - - } - - // Compute ECC P code - edcEccGen.ComputeEccBlock(cd::IsoWriter::sectorBuff+0xC, 86, 24, 2, 86, cd::IsoWriter::sectorBuff+0x81C); - // Compute ECC Q code - edcEccGen.ComputeEccBlock(cd::IsoWriter::sectorBuff+0xC, 52, 43, 86, 88, cd::IsoWriter::sectorBuff+0x8C8); - - for(int i=0; i<4; i++) { - - cd::IsoWriter::sectorM2F1->addr[i] = tempAddr[i]; - - } - - } else if (edcEccMode == cd::IsoWriter::EdcEccForm2) { - - edcEccGen.ComputeEdcBlock(cd::IsoWriter::sectorM2F1->subHead, 0x91C, &cd::IsoWriter::sectorM2F2->data[2332]); - - } - -} - -bool cd::IsoWriter::Create(const char* fileName) { - - cd::IsoWriter::filePtr = fopen(fileName, "wb"); - - if (cd::IsoWriter::filePtr == NULL) - return(false); - - cd::IsoWriter::currentByte = 0; - cd::IsoWriter::currentSector = 0; - - cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)cd::IsoWriter::sectorBuff; - cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)cd::IsoWriter::sectorBuff; - - cd::IsoWriter::bytesWritten = 0; - - memset(cd::IsoWriter::sectorBuff, 0, CD_SECTOR_SIZE); - - return(true); - -} - -int cd::IsoWriter::SeekToSector(int sector) { - - if (cd::IsoWriter::currentByte) { - - cd::IsoWriter::PrepSector(cd::IsoWriter::lastSectorType); - fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr); - - } - - fseek(cd::IsoWriter::filePtr, CD_SECTOR_SIZE*sector, SEEK_SET); - - cd::IsoWriter::currentSector = sector; - cd::IsoWriter::currentByte = 0; - - cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; - cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; - - return sector; - -} - -int cd::IsoWriter::SeekToEnd() { - - if (cd::IsoWriter::currentByte) { - - cd::IsoWriter::PrepSector(cd::IsoWriter::lastSectorType); - fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr); - - } - - fseek(cd::IsoWriter::filePtr, 0, SEEK_END); - - int sector = ftell(cd::IsoWriter::filePtr)/CD_SECTOR_SIZE; - - cd::IsoWriter::currentSector = sector; - cd::IsoWriter::currentByte = 0; - - cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; - cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; - - return sector; - -} - -size_t cd::IsoWriter::WriteBytes(void* data, size_t bytes, int edcEccEncode) { - - size_t writeBytes = 0; - - char* dataPtr = (char*)data; - int toWrite; - - memcpy(cd::IsoWriter::sectorM2F1->subHead, cd::IsoWriter::subHeadBuff, 8); - - cd::IsoWriter::lastSectorType = edcEccEncode; - - while(bytes > 0) { - - if (bytes > 2048) - toWrite = 2048; - else - toWrite = bytes; - - memcpy(&cd::IsoWriter::sectorM2F1->data[cd::IsoWriter::currentByte], dataPtr, toWrite); - - cd::IsoWriter::currentByte += toWrite; - - dataPtr += toWrite; - bytes -= toWrite; - - if (cd::IsoWriter::currentByte >= 2048) { - - cd::IsoWriter::PrepSector(edcEccEncode); - - if (fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr) == 0) { - - cd::IsoWriter::currentByte = 0; - return(writeBytes); - - } - - cd::IsoWriter::currentByte = 0; - cd::IsoWriter::currentSector++; - - cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; - cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; - - } - - writeBytes += toWrite; - - } - - return(writeBytes); - -} - -size_t cd::IsoWriter::WriteBytesXA(void* data, size_t bytes, int edcEccEncode) { - - size_t writeBytes = 0; - - char* dataPtr = (char*)data; - int toWrite; - - cd::IsoWriter::lastSectorType = edcEccEncode; - - while(bytes > 0) { - - if (bytes > 2336) - toWrite = 2336; - else - toWrite = bytes; - - memcpy(&cd::IsoWriter::sectorM2F2->data[cd::IsoWriter::currentByte], dataPtr, toWrite); - - cd::IsoWriter::currentByte += toWrite; - - dataPtr += toWrite; - bytes -= toWrite; - - if (cd::IsoWriter::currentByte >= 2336) { - - cd::IsoWriter::PrepSector(edcEccEncode); - - if (fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr) == 0) { - - cd::IsoWriter::currentByte = 0; - return(writeBytes); - - } - - cd::IsoWriter::currentByte = 0; - cd::IsoWriter::currentSector++; - - cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; - cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; - - } - - writeBytes += toWrite; - - } - - return(writeBytes); - -} - -size_t cd::IsoWriter::WriteBytesRaw(void* data, size_t bytes) { - - size_t writeBytes = 0; - - char* dataPtr = (char*)data; - int toWrite; - - cd::IsoWriter::lastSectorType = EdcEccNone; - - while(bytes > 0) { - - if (bytes > 2352) - toWrite = 2352; - else - toWrite = bytes; - - memcpy(&cd::IsoWriter::sectorBuff[cd::IsoWriter::currentByte], dataPtr, toWrite); - - cd::IsoWriter::currentByte += toWrite; - - dataPtr += toWrite; - bytes -= toWrite; - - if (cd::IsoWriter::currentByte >= 2352) { - - if (fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr) == 0) { - - cd::IsoWriter::currentByte = 0; - return(writeBytes); - - } - - cd::IsoWriter::currentByte = 0; - cd::IsoWriter::currentSector++; - - cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; - cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; - - } - - writeBytes += toWrite; - - } - - return(writeBytes); - -} - -int cd::IsoWriter::CurrentSector() { - - return currentSector; - -} - -void cd::IsoWriter::SetSubheader(unsigned char* data) { - - memcpy(cd::IsoWriter::subHeadBuff, data, 8); - -} - -void cd::IsoWriter::Close() { - - if (cd::IsoWriter::filePtr != NULL) { - - if (cd::IsoWriter::currentByte > 0) { - cd::IsoWriter::PrepSector(cd::IsoWriter::lastSectorType); - fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr); - } - - fclose(cd::IsoWriter::filePtr); - - } - - cd::IsoWriter::filePtr = NULL; - -} +#include +#include +#include "cdwriter.h" +#include "edcecc.h" + + +void cd::SwapBytes(void *var, int size) { + + unsigned char temp[size]; + + memcpy(temp, var, size); + for(short i=0; ilsb = val; + pair->msb = val; + + SwapBytes(&pair->msb, 2); + +} + +void cd::SetPair32(cd::ISO_UINT_PAIR* pair, unsigned int val) { + + pair->lsb = val; + pair->msb = val; + + SwapBytes(&pair->msb, 4); + +} + + +cd::IsoWriter::IsoWriter() { + + cd::IsoWriter::filePtr = NULL; + cd::IsoWriter::sectorM2F1 = NULL; + cd::IsoWriter::sectorM2F2 = NULL; + cd::IsoWriter::currentByte = 0; + cd::IsoWriter::currentSector = 0; + cd::IsoWriter::bytesWritten = 0; + cd::IsoWriter::lastSectorType = 0; + + memset(cd::IsoWriter::sectorBuff, 0, CD_SECTOR_SIZE); + +} + +cd::IsoWriter::~IsoWriter() { + + if (cd::IsoWriter::filePtr != NULL) + fclose(cd::IsoWriter::filePtr); + + cd::IsoWriter::filePtr = NULL; + +} + +void cd::IsoWriter::PrepSector(int edcEccMode) { + + memset(cd::IsoWriter::sectorM2F1->sync, 0xff, 12); + cd::IsoWriter::sectorM2F1->sync[0] = 0x00; + cd::IsoWriter::sectorM2F1->sync[11] = 0x00; + + int taddr,addr = 150+cd::IsoWriter::currentSector; // Sector addresses always start at LBA 150 + + taddr = addr%75; + cd::IsoWriter::sectorM2F1->addr[2] = (16*(taddr/10))+(taddr%10); + + taddr = (addr/75)%60; + cd::IsoWriter::sectorM2F1->addr[1] = (16*(taddr/10))+(taddr%10); + + taddr = (addr/75)/60; + cd::IsoWriter::sectorM2F1->addr[0] = (16*(taddr/10))+(taddr%10); + + cd::IsoWriter::sectorM2F1->mode = 0x02; + + if (edcEccMode == cd::IsoWriter::EdcEccForm1) { + + // Encode EDC data + edcEccGen.ComputeEdcBlock(cd::IsoWriter::sectorM2F1->subHead, 0x808, cd::IsoWriter::sectorM2F1->edc); + + // Encode ECC data + unsigned char tempAddr[4]; + + for(int i=0; i<4; i++) { + + tempAddr[i] = cd::IsoWriter::sectorM2F1->addr[i]; + cd::IsoWriter::sectorM2F1->addr[i] = 0x00; + + } + + // Compute ECC P code + edcEccGen.ComputeEccBlock(cd::IsoWriter::sectorBuff+0xC, 86, 24, 2, 86, cd::IsoWriter::sectorBuff+0x81C); + // Compute ECC Q code + edcEccGen.ComputeEccBlock(cd::IsoWriter::sectorBuff+0xC, 52, 43, 86, 88, cd::IsoWriter::sectorBuff+0x8C8); + + for(int i=0; i<4; i++) { + + cd::IsoWriter::sectorM2F1->addr[i] = tempAddr[i]; + + } + + } else if (edcEccMode == cd::IsoWriter::EdcEccForm2) { + + edcEccGen.ComputeEdcBlock(cd::IsoWriter::sectorM2F1->subHead, 0x91C, &cd::IsoWriter::sectorM2F2->data[2332]); + + } + +} + +bool cd::IsoWriter::Create(const char* fileName) { + + cd::IsoWriter::filePtr = fopen(fileName, "wb"); + + if (cd::IsoWriter::filePtr == NULL) + return(false); + + cd::IsoWriter::currentByte = 0; + cd::IsoWriter::currentSector = 0; + + cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)cd::IsoWriter::sectorBuff; + cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)cd::IsoWriter::sectorBuff; + + cd::IsoWriter::bytesWritten = 0; + + memset(cd::IsoWriter::sectorBuff, 0, CD_SECTOR_SIZE); + + return(true); + +} + +int cd::IsoWriter::SeekToSector(int sector) { + + if (cd::IsoWriter::currentByte) { + + cd::IsoWriter::PrepSector(cd::IsoWriter::lastSectorType); + fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr); + + } + + fseek(cd::IsoWriter::filePtr, CD_SECTOR_SIZE*sector, SEEK_SET); + + cd::IsoWriter::currentSector = sector; + cd::IsoWriter::currentByte = 0; + + cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; + cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; + + return sector; + +} + +int cd::IsoWriter::SeekToEnd() { + + if (cd::IsoWriter::currentByte) { + + cd::IsoWriter::PrepSector(cd::IsoWriter::lastSectorType); + fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr); + + } + + fseek(cd::IsoWriter::filePtr, 0, SEEK_END); + + int sector = ftell(cd::IsoWriter::filePtr)/CD_SECTOR_SIZE; + + cd::IsoWriter::currentSector = sector; + cd::IsoWriter::currentByte = 0; + + cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; + cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; + + return sector; + +} + +size_t cd::IsoWriter::WriteBytes(void* data, size_t bytes, int edcEccEncode) { + + size_t writeBytes = 0; + + char* dataPtr = (char*)data; + int toWrite; + + memcpy(cd::IsoWriter::sectorM2F1->subHead, cd::IsoWriter::subHeadBuff, 8); + + cd::IsoWriter::lastSectorType = edcEccEncode; + + while(bytes > 0) { + + if (bytes > 2048) + toWrite = 2048; + else + toWrite = bytes; + + memcpy(&cd::IsoWriter::sectorM2F1->data[cd::IsoWriter::currentByte], dataPtr, toWrite); + + cd::IsoWriter::currentByte += toWrite; + + dataPtr += toWrite; + bytes -= toWrite; + + if (cd::IsoWriter::currentByte >= 2048) { + + cd::IsoWriter::PrepSector(edcEccEncode); + + if (fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr) == 0) { + + cd::IsoWriter::currentByte = 0; + return(writeBytes); + + } + + cd::IsoWriter::currentByte = 0; + cd::IsoWriter::currentSector++; + + cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; + cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; + + } + + writeBytes += toWrite; + + } + + return(writeBytes); + +} + +size_t cd::IsoWriter::WriteBytesXA(void* data, size_t bytes, int edcEccEncode) { + + size_t writeBytes = 0; + + char* dataPtr = (char*)data; + int toWrite; + + cd::IsoWriter::lastSectorType = edcEccEncode; + + while(bytes > 0) { + + if (bytes > 2336) + toWrite = 2336; + else + toWrite = bytes; + + memcpy(&cd::IsoWriter::sectorM2F2->data[cd::IsoWriter::currentByte], dataPtr, toWrite); + + cd::IsoWriter::currentByte += toWrite; + + dataPtr += toWrite; + bytes -= toWrite; + + if (cd::IsoWriter::currentByte >= 2336) { + + cd::IsoWriter::PrepSector(edcEccEncode); + + if (fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr) == 0) { + + cd::IsoWriter::currentByte = 0; + return(writeBytes); + + } + + cd::IsoWriter::currentByte = 0; + cd::IsoWriter::currentSector++; + + cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; + cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; + + } + + writeBytes += toWrite; + + } + + return(writeBytes); + +} + +size_t cd::IsoWriter::WriteBytesRaw(void* data, size_t bytes) { + + size_t writeBytes = 0; + + char* dataPtr = (char*)data; + int toWrite; + + cd::IsoWriter::lastSectorType = EdcEccNone; + + while(bytes > 0) { + + if (bytes > 2352) + toWrite = 2352; + else + toWrite = bytes; + + memcpy(&cd::IsoWriter::sectorBuff[cd::IsoWriter::currentByte], dataPtr, toWrite); + + cd::IsoWriter::currentByte += toWrite; + + dataPtr += toWrite; + bytes -= toWrite; + + if (cd::IsoWriter::currentByte >= 2352) { + + if (fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr) == 0) { + + cd::IsoWriter::currentByte = 0; + return(writeBytes); + + } + + cd::IsoWriter::currentByte = 0; + cd::IsoWriter::currentSector++; + + cd::IsoWriter::sectorM2F1 = (cd::SECTOR_M2F1*)sectorBuff; + cd::IsoWriter::sectorM2F2 = (cd::SECTOR_M2F2*)sectorBuff; + + } + + writeBytes += toWrite; + + } + + return(writeBytes); + +} + +int cd::IsoWriter::CurrentSector() { + + return currentSector; + +} + +void cd::IsoWriter::SetSubheader(unsigned char* data) { + + memcpy(cd::IsoWriter::subHeadBuff, data, 8); + +} + +void cd::IsoWriter::Close() { + + if (cd::IsoWriter::filePtr != NULL) { + + if (cd::IsoWriter::currentByte > 0) { + cd::IsoWriter::PrepSector(cd::IsoWriter::lastSectorType); + fwrite(sectorBuff, CD_SECTOR_SIZE, 1, cd::IsoWriter::filePtr); + } + + fclose(cd::IsoWriter::filePtr); + + } + + cd::IsoWriter::filePtr = NULL; + +} diff --git a/src/edcecc.cpp b/src/edcecc.cpp index a757a4d..fc905de 100644 --- a/src/edcecc.cpp +++ b/src/edcecc.cpp @@ -1,80 +1,80 @@ -/* EDC and ECC calculation routines from ecmtools by Neill Corlett - * - * Its the only program where I can find routines for proper EDC/ECC calculation. - */ - -#include "edcecc.h" - -EDCECC::EDCECC() { - - unsigned int i,j,edc; - - for(i=0; i<256; i++) { - - j = (i<<1)^(i&0x80?0x11D:0); - EDCECC::ecc_f_lut[i] = j; - EDCECC::ecc_b_lut[i^j] = i; - edc = i; - - for(j=0; j<8; j++) - edc=(edc>>1)^(edc&1?0xD8018001:0); - - EDCECC::edc_lut[i] = edc; - - } - -} - -unsigned int EDCECC::ComputeEdcBlockPartial(unsigned int edc, const unsigned char *src, int len) { - - while(len--) - edc = (edc>>8)^EDCECC::edc_lut[(edc^(*src++))&0xFF]; - - return edc; - -} - -void EDCECC::ComputeEdcBlock(const unsigned char *src, int len, unsigned char *dest) { - - unsigned int edc = EDCECC::ComputeEdcBlockPartial(0, src, len); - - dest[0] = (edc>>0)&0xFF; - dest[1] = (edc>>8)&0xFF; - dest[2] = (edc>>16)&0xFF; - dest[3] = (edc>>24)&0xFF; - -} - -void EDCECC::ComputeEccBlock(unsigned char *src, unsigned int major_count, unsigned int minor_count, unsigned int major_mult, unsigned int minor_inc, unsigned char *dest) { - - unsigned int len = major_count*minor_count; - unsigned int major,minor; - - for(major = 0; major < major_count; major++) { - - unsigned int index = (major >> 1) * major_mult + (major & 1); - unsigned char ecc_a = 0; - unsigned char ecc_b = 0; - - for(minor = 0; minor < minor_count; minor++) { - - unsigned char temp = src[index]; - - index += minor_inc; - - if(index >= len) - index -= len; - - ecc_a ^= temp; - ecc_b ^= temp; - ecc_a = EDCECC::ecc_f_lut[ecc_a]; - - } - - ecc_a = EDCECC::ecc_b_lut[EDCECC::ecc_f_lut[ecc_a]^ecc_b]; - dest[major] = ecc_a; - dest[major+major_count] = ecc_a^ecc_b; - - } - -} +/* EDC and ECC calculation routines from ecmtools by Neill Corlett + * + * Its the only program where I can find routines for proper EDC/ECC calculation. + */ + +#include "edcecc.h" + +EDCECC::EDCECC() { + + unsigned int i,j,edc; + + for(i=0; i<256; i++) { + + j = (i<<1)^(i&0x80?0x11D:0); + EDCECC::ecc_f_lut[i] = j; + EDCECC::ecc_b_lut[i^j] = i; + edc = i; + + for(j=0; j<8; j++) + edc=(edc>>1)^(edc&1?0xD8018001:0); + + EDCECC::edc_lut[i] = edc; + + } + +} + +unsigned int EDCECC::ComputeEdcBlockPartial(unsigned int edc, const unsigned char *src, int len) { + + while(len--) + edc = (edc>>8)^EDCECC::edc_lut[(edc^(*src++))&0xFF]; + + return edc; + +} + +void EDCECC::ComputeEdcBlock(const unsigned char *src, int len, unsigned char *dest) { + + unsigned int edc = EDCECC::ComputeEdcBlockPartial(0, src, len); + + dest[0] = (edc>>0)&0xFF; + dest[1] = (edc>>8)&0xFF; + dest[2] = (edc>>16)&0xFF; + dest[3] = (edc>>24)&0xFF; + +} + +void EDCECC::ComputeEccBlock(unsigned char *src, unsigned int major_count, unsigned int minor_count, unsigned int major_mult, unsigned int minor_inc, unsigned char *dest) { + + unsigned int len = major_count*minor_count; + unsigned int major,minor; + + for(major = 0; major < major_count; major++) { + + unsigned int index = (major >> 1) * major_mult + (major & 1); + unsigned char ecc_a = 0; + unsigned char ecc_b = 0; + + for(minor = 0; minor < minor_count; minor++) { + + unsigned char temp = src[index]; + + index += minor_inc; + + if(index >= len) + index -= len; + + ecc_a ^= temp; + ecc_b ^= temp; + ecc_a = EDCECC::ecc_f_lut[ecc_a]; + + } + + ecc_a = EDCECC::ecc_b_lut[EDCECC::ecc_f_lut[ecc_a]^ecc_b]; + dest[major] = ecc_a; + dest[major+major_count] = ecc_a^ecc_b; + + } + +} diff --git a/src/iso.cpp b/src/iso.cpp index bbfb3a8..6b13d37 100644 --- a/src/iso.cpp +++ b/src/iso.cpp @@ -1,966 +1,966 @@ -#include "global.h" -#include "iso.h" - -iso::DirTreeClass::DirTreeClass() { - - entries = (DIRENTRY*)malloc(sizeof(DIRENTRY)); - numentries = 0; - recordLBA = 0; - -} - -iso::DirTreeClass::~DirTreeClass() { - - for(int i=0; i 0) - entries = (DIRENTRY*)realloc(entries, sizeof(DIRENTRY)*(numentries+1)); - - memset(&entries[numentries], 0x00, sizeof(DIRENTRY)); - - entries[numentries].id = strdup(tempName); - entries[numentries].type = type; - entries[numentries].subdir = NULL; - - if (srcfile != NULL) - entries[numentries].srcfile = strdup(srcfile); - - if (type != EntryDir) - entries[numentries].length = fileAttrib.st_size; - - tm* fileTime = gmtime(&fileAttrib.st_mtime); - - entries[numentries].date.hour = fileTime->tm_hour; - entries[numentries].date.minute = fileTime->tm_min; - entries[numentries].date.second = fileTime->tm_sec; - entries[numentries].date.day = fileTime->tm_mday; - entries[numentries].date.month = fileTime->tm_mon+1; - entries[numentries].date.year = fileTime->tm_year; - entries[numentries].date.GMToffs = 0; - - numentries++; - - return true; - -} - -void iso::DirTreeClass::AddDummyEntry(int sectors) { - - if (numentries > 0) - entries = (DIRENTRY*)realloc(entries, sizeof(DIRENTRY)*(numentries+1)); - - - entries[numentries].id = NULL; - entries[numentries].srcfile = NULL; - entries[numentries].subdir = NULL; - entries[numentries].type = EntryFile; - entries[numentries].length = 2048*sectors; - - numentries++; - -} - -iso::DirTreeClass* iso::DirTreeClass::AddSubDirEntry(const char* id) { - - for(int i=0; i 0) - entries = (DIRENTRY*)realloc(entries, sizeof(DIRENTRY) * (numentries + 1)); - - memset(&entries[numentries], 0x00, sizeof(DIRENTRY)); - - entries[numentries].id = strdup(id); - entries[numentries].type = EntryDir; - entries[numentries].length = 2048; - entries[numentries].subdir = (void*) new DirTreeClass; - - tm* dirTime = gmtime(&global::BuildTime); - - entries[numentries].date.hour = dirTime->tm_hour; - entries[numentries].date.minute = dirTime->tm_min; - entries[numentries].date.second = dirTime->tm_sec; - entries[numentries].date.month = dirTime->tm_mon+1; - entries[numentries].date.day = dirTime->tm_mday; - entries[numentries].date.year = dirTime->tm_year; - entries[numentries].date.GMToffs = 0; - - for(int i=0; entries[numentries].id[i] != 0x00; i++) - entries[numentries].id[i] = toupper(entries[numentries].id[i]); - - numentries++; - - return (DirTreeClass*)entries[numentries-1].subdir; - -} - -int iso::DirTreeClass::CalculateTreeLBA(int lba) { - - // Set LBA of directory record of this class - recordLBA = lba; - - lba += 1; - - for(int i=0; iCalculateTreeLBA(lba); - - } else { - - // Increment LBA by the size of file - if (entries[i].type == EntryFile) - lba += (entries[i].length+2047)/2048; - else if ((entries[i].type == EntryXA) || (entries[i].type == EntrySTR)) - lba += (entries[i].length+2335)/2336; - - } - - } - - - return lba; - -} - -int iso::DirTreeClass::CalculateDirEntryLen() { - - int dirEntryLen = 96; - - for(int i=0; iSortDirEntries(); - - } else { - - if (entries[i].id == NULL) - numdummies++; - - } - - - } - - - // Sort dummies to end of list - for(int i=1; i 0) { - - temp = entries[j-1]; - entries[j-1] = entries[j]; - entries[j] = temp; - - } - - } - } - - - /* - int numdirs=0,numfiles=0; - // Sort directories to be first in list - for(int i=1; i 1) { - - // Sort the directory entries - for(int i=1; i 0) { - - temp = entries[j-1]; - entries[j-1] = entries[j]; - entries[j] = temp; - - } - - } - } - - } - - - // Count number of files - for(int i=0; i 1) { - - for(int i=numdirs+1; i<(numdirs+numfiles); i++) { - for(int j=numdirs+1; j<(numdirs+numfiles); j++) { - - if (strcmp(entries[j-1].id, entries[j].id) > 0) { - - temp = entries[j-1]; - entries[j-1] = entries[j]; - entries[j] = temp; - - } - - } - } - - } - */ - -} - -int iso::DirTreeClass::WriteDirEntries(cd::IsoWriter* writer, int lastLBA) { - - char dataBuff[2048]; - char* dataBuffPtr=dataBuff; - - cd::ISO_DIR_ENTRY* entry; - cd::ISO_XA_ATTRIB* xa; - - memset(dataBuff, 0x00, 2048); - - for(int i=0; i<2; i++) { - - entry = (cd::ISO_DIR_ENTRY*)dataBuffPtr; - - SetPair32(&entry->entrySize, 2048); - SetPair16(&entry->volSeqNum, 1); - entry->identifierLen = 1; - - int dataLen = 32; - - if (i == 0) { - - SetPair32(&entry->entryOffs, recordLBA); - - } else { - - SetPair32(&entry->entryOffs, lastLBA); - dataBuffPtr[dataLen+1] = 0x01; - - } - - dataLen += 2; - - xa = (cd::ISO_XA_ATTRIB*)(dataBuffPtr+dataLen); - - xa->id[0] = 'X'; - xa->id[1] = 'A'; - xa->type = 0x8800; - - dataLen += sizeof(cd::ISO_XA_ATTRIB); - - entry->flags = 0x02; - entry->entryLength = dataLen; - - tm* dirTime = gmtime(&global::BuildTime); - - entry->entryDate.year = dirTime->tm_year; - entry->entryDate.month = dirTime->tm_mon+1; - entry->entryDate.day = dirTime->tm_mday; - entry->entryDate.hour = dirTime->tm_hour; - entry->entryDate.minute = dirTime->tm_min; - entry->entryDate.second = dirTime->tm_sec; - - dataBuffPtr += dataLen; - - } - - for(int i=0; iCalculateDirEntryLen(); - entry->flags = 0x02; - - } else { - - entry->flags = 0x00; - - } - - SetPair32(&entry->entryOffs, entries[i].lba); - SetPair32(&entry->entrySize, entries[i].length); - SetPair16(&entry->volSeqNum, 1); - - entry->identifierLen = strlen(entries[i].id); - entry->entryDate = entries[i].date; - - int dataLen = 33; - - strncpy(&dataBuffPtr[dataLen], entries[i].id, entry->identifierLen); - dataLen += 2*((entry->identifierLen+1)/2); - - if ((entry->identifierLen%2) == 0) - dataLen++; - - xa = (cd::ISO_XA_ATTRIB*)(dataBuffPtr+dataLen); - - xa->id[0] = 'X'; - xa->id[1] = 'A'; - - if (entries[i].type == EntryFile) - xa->type = 0x0800; - else if (entries[i].type == EntryDir) - xa->type = 0x8800; - - dataLen += sizeof(cd::ISO_XA_ATTRIB); - entry->entryLength = dataLen; - - dataBuffPtr += dataLen; - - } - - if ((int)(dataBuffPtr-dataBuff) > 2048) - return 0; - - writer->SeekToSector(recordLBA); - writer->WriteBytes(dataBuff, 2048, cd::IsoWriter::EdcEccForm1); - - return 1; - -} - -int iso::DirTreeClass::WriteDirectoryRecords(cd::IsoWriter* writer, int lastDirLBA) { - - if (lastDirLBA == 0) - lastDirLBA = recordLBA; - - WriteDirEntries(writer, lastDirLBA); - - for(int i=0; iWriteDirectoryRecords(writer, recordLBA)) - return 0; - - } - - } - - return 1; - -} - -int iso::DirTreeClass::WriteFiles(cd::IsoWriter* writer) { - - for(int i=0; iSeekToSector(entries[i].lba); - - // Write files and dummies as regular data sectors - if (entries[i].type == EntryFile) { - - char buff[2048]; - - if (entries[i].srcfile != NULL) { - - if (!global::QuietMode) - printf(" Packing %s... ", entries[i].srcfile); - - FILE *fp = fopen(entries[i].srcfile, "rb"); - - while(!feof(fp)) { - - memset(buff, 0x00, 2048); - - fread(buff, 1, 2048, fp); - writer->WriteBytes(buff, 2048, cd::IsoWriter::EdcEccForm1); - - } - - fclose(fp); - - if (!global::QuietMode) - printf("Done.\n"); - - } else { - - memset(buff, 0x00, 2048); - - for(int c=0; c<(entries[i].length/2048); c++) { - - writer->WriteBytes(buff, 2048, cd::IsoWriter::EdcEccForm1); - - } - - } - - // Write XA audio streams as Mode 2 Form 2 sectors without ECC - } else if (entries[i].type == EntryXA) { - - char buff[2336]; - - if (!global::QuietMode) - printf(" Packing XA %s... ", entries[i].srcfile); - - FILE *fp = fopen(entries[i].srcfile, "rb"); - - while(!feof(fp)) { - - memset(buff, 0x00, 2336); - - fread(buff, 1, 2336, fp); - writer->WriteBytesXA(buff, 2336, cd::IsoWriter::EdcEccNone); - - } - - fclose(fp); - - if (!global::QuietMode) - printf("Done.\n"); - - // Write STR video streams as Mode 2 Form 1 (video sectors) and Mode 2 Form 2 (XA audio sectors) - // Video sectors have EDC/ECC while XA does not - } else if (entries[i].type == EntrySTR) { - - char buff[2336]; - - if (!global::QuietMode) - printf(" Packing STR %s... ", entries[i].srcfile); - - FILE *fp = fopen(entries[i].srcfile, "rb"); - - while(!feof(fp)) { - - memset(buff, 0x00, 2336); - fread(buff, 1, 2336, fp); - - // Check if sector is a video sector - if (buff[2] == 0x48) - writer->WriteBytesXA(buff, 2336, cd::IsoWriter::EdcEccForm1); // If so, write it as Mode 2 Form 1 - else - writer->WriteBytesXA(buff, 2336, cd::IsoWriter::EdcEccNone); // Otherwise, write it as an XA track - - } - - fclose(fp); - - if (!global::QuietMode) - printf("Done.\n"); - - } else if (entries[i].type == EntryDir) { - - ((DirTreeClass*)entries[i].subdir)->WriteFiles(writer); - - } - - } - - return 1; - -} - -void iso::DirTreeClass::PrintEntries() { - - printf("RECORD LBA : %d\n", recordLBA); - for(int i=0; i "); - - printf("L:%d LBA:%d T:%d S:%s\n", entries[i].length, entries[i].lba, entries[i].type, entries[i].srcfile); - - if (entries[i].subdir != NULL) { - - ((DirTreeClass*)entries[i].subdir)->PrintEntries(); - - } - - } - -} - - -int iso::DirTreeClass::CalculatePathTableLenSub(DIRENTRY* dirEntry) { - - int len = 8; - - // Put identifier (NULL if first entry) - len += 2*((strlen(dirEntry->id)+1)/2); - - for(int i=0; i<((DirTreeClass*)dirEntry->subdir)->numentries; i++) { - - if (((DirTreeClass*)dirEntry->subdir)->entries[i].type == EntryDir) { - - len += CalculatePathTableLenSub(&((DirTreeClass*)dirEntry->subdir)->entries[i]); - - } - - } - - return len; - -} - -int iso::DirTreeClass::CalculatePathTableLen() { - - int len = 10; - - for(int i=0; iid); // Directory identifier length - buff++; - *buff = 0; // Extended attribute record length (unused) - buff++; - - // Write LBA and directory number index - dirIndex++; - *((int*)buff) = ((DirTreeClass*)dirEntry->subdir)->recordLBA; - memcpy(buff+4, &parentIndex, 2); - - if (msb) { - - cd::SwapBytes(buff, 4); - cd::SwapBytes(buff+4, 2); - - } - - buff += 6; - - // Put identifier (NULL if first entry) - strncpy((char*)buff, dirEntry->id, strlen(dirEntry->id)); - buff += 2*((strlen(dirEntry->id)+1)/2); - - parentIndex = dirIndex; - - if (dirEntry->subdir != NULL) { - - for(int i=0; i<((DirTreeClass*)dirEntry->subdir)->numentries; i++) { - - if (((DirTreeClass*)dirEntry->subdir)->entries[i].type == EntryDir) { - - buff = GenPathTableSub(buff, &((DirTreeClass*)dirEntry->subdir)->entries[i], parentIndex, msb); - - } - - } - - } - - return buff; - -} - -int iso::DirTreeClass::GeneratePathTable(unsigned char* buff, int msb) { - - unsigned char* oldBuffPtr = buff; - - *buff = 1; // Directory identifier length - buff++; - *buff = 0; // Extended attribute record length (unused) - buff++; - - int lba = recordLBA; - - // Write LBA and directory number index - dirIndex = 1; - memcpy(buff, &lba, 4); - memcpy(buff+4, &dirIndex, 2); - - if (msb) { - cd::SwapBytes(buff, 4); - cd::SwapBytes(buff+4, 2); - } - - buff += 6; - - // Put identifier (NULL if first entry) - memset(buff, 0x00, 2); - buff += 2; - - for(int i=0; i 2048) - break; - - } - - return (int)(buff-oldBuffPtr); - -} - -int iso::DirTreeClass::GetFileCountTotal() { - - int numfiles = 0; - - for(int i=0; iGetFileCountTotal(); - - } - - } - - return numfiles; - -} - -int iso::DirTreeClass::GetDirCountTotal() { - - int numdirs = 0; - - for(int i=0; iGetDirCountTotal(); - - } - - } - - return numdirs; - -} - -void iso::WriteLicenseData(cd::IsoWriter* writer, void* data) { - - writer->SeekToSector(0); - writer->WriteBytesXA(data, 2336*12, cd::IsoWriter::EdcEccForm1); - -} - -void iso::WriteDescriptor(cd::IsoWriter* writer, iso::IDENTIFIERS id, iso::DirTreeClass* dirTree, int imageLen) { - - - cd::ISO_DESCRIPTOR isoDescriptor; - - memset(&isoDescriptor, 0x00, sizeof(cd::ISO_DESCRIPTOR)); - - isoDescriptor.header.type = 1; - isoDescriptor.header.version = 1; - strncpy((char*)isoDescriptor.header.id, "CD001", 5); - - // Set System identifier - memset(isoDescriptor.systemID, 0x20, 32); - if (id.SystemID != NULL) { - - for(int i=0; i<(int)strlen(id.SystemID); i++) - isoDescriptor.systemID[i] = toupper(id.SystemID[i]); - - } - - // Set Volume identifier - memset(isoDescriptor.volumeID, 0x20, 32); - if (id.VolumeID != NULL) { - - for(int i=0; i<(int)strlen(id.VolumeID); i++) - isoDescriptor.volumeID[i] = toupper(id.VolumeID[i]); - - } - - // Set Application identifier - memset(isoDescriptor.applicationIdentifier, 0x20, 128); - if (id.Application != NULL) { - - for(int i=0; i<(int)strlen(id.Application); i++) - isoDescriptor.applicationIdentifier[i] = toupper(id.Application[i]); - - } - - // Volume Set identifier - memset(isoDescriptor.volumeSetIdentifier, 0x20, 128); - if (id.VolumeSet != NULL) { - - for(int i=0; i<(int)strlen(id.VolumeSet); i++) - isoDescriptor.volumeSetIdentifier[i] = toupper(id.VolumeSet[i]); - - } - - // Publisher identifier - memset(isoDescriptor.publisherIdentifier, 0x20, 128); - if (id.Publisher != NULL) { - - for(int i=0; i<(int)strlen(id.Publisher); i++) - isoDescriptor.publisherIdentifier[i] = toupper(id.Publisher[i]); - - } - - // Data preparer identifier - memset(isoDescriptor.dataPreparerIdentifier, 0x20, 128); - strcpy(isoDescriptor.dataPreparerIdentifier, "THIS DISC IMAGE WAS CREATED USING MKPSXISO BY LAMEGUY64 OF MEIDO-TEK PRODUCTIONS HTTPS://GITHUB.COM/LAMEGUY64/MKPSXISO"); - *strchr(isoDescriptor.dataPreparerIdentifier, 0x00) = 0x20; - if (id.DataPreparer != NULL) { - - for(int i=0; i<(int)strlen(id.DataPreparer); i++) - isoDescriptor.dataPreparerIdentifier[i] = toupper(id.DataPreparer[i]); - - } - - // Unneeded identifiers - memset(isoDescriptor.copyrightFileIdentifier, 0x20, 37); - memset(isoDescriptor.abstractFileIdentifier, 0x20, 37); - memset(isoDescriptor.bibliographicFilelIdentifier, 0x20, 37); - - - tm* imageTime = localtime(&global::BuildTime); - - sprintf(isoDescriptor.volumeCreateDate, "%04d%02d%02d%02d%02d%02d00", - imageTime->tm_year+1900, - imageTime->tm_mon, - imageTime->tm_mday, - imageTime->tm_hour, - imageTime->tm_min, - imageTime->tm_sec - ); - - sprintf(isoDescriptor.volumeModifyDate, "%04d%02d%02d%02d%02d%02d00", - imageTime->tm_year+1900, - imageTime->tm_mon, - imageTime->tm_mday, - imageTime->tm_hour, - imageTime->tm_min, - imageTime->tm_sec - ); - - strcpy(isoDescriptor.volumeEffeciveDate, "0000000000000000"); - strcpy(isoDescriptor.volumeExpiryDate, "0000000000000000"); - - isoDescriptor.fileStructVersion = 1; - strncpy((char*)&isoDescriptor.appData[141], "CD-XA001", 8); - - cd::SetPair16(&isoDescriptor.volumeSetSize, 1); - cd::SetPair16(&isoDescriptor.volumeSeqNumber, 1); - cd::SetPair16(&isoDescriptor.sectorSize, 2048); - cd::SetPair32(&isoDescriptor.pathTableSize, dirTree->CalculatePathTableLen()); - - // Setup the root directory record - isoDescriptor.rootDirRecord.entryLength = 34; - isoDescriptor.rootDirRecord.extLength = 0; - cd::SetPair32(&isoDescriptor.rootDirRecord.entryOffs, 22); - cd::SetPair32(&isoDescriptor.rootDirRecord.entrySize, 0x800); - isoDescriptor.rootDirRecord.flags = 0x02; - cd::SetPair16(&isoDescriptor.rootDirRecord.volSeqNum, 1); - isoDescriptor.rootDirRecord.identifierLen = 1; - isoDescriptor.rootDirRecord.identifier = 0x01; - - isoDescriptor.pathTable1Offs = 18; - isoDescriptor.pathTable2Offs = 19; - isoDescriptor.pathTable1MSBoffs = 20; - cd::SwapBytes(&isoDescriptor.pathTable1MSBoffs, 4); - isoDescriptor.pathTable2MSBoffs = 21; - cd::SwapBytes(&isoDescriptor.pathTable2MSBoffs, 4); - - SetPair32(&isoDescriptor.volumeSize, imageLen); - - // Write the descriptor - writer->SeekToSector(16); - writer->WriteBytes(&isoDescriptor, sizeof(cd::ISO_DESCRIPTOR), cd::IsoWriter::EdcEccForm1); - - - // Write descriptor terminator; - memset(&isoDescriptor, 0x00, sizeof(cd::ISO_DESCRIPTOR)); - isoDescriptor.header.type = 255; - isoDescriptor.header.version = 1; - strncpy(isoDescriptor.header.id, "CD001", 5); - - writer->WriteBytes(&isoDescriptor, sizeof(cd::ISO_DESCRIPTOR), cd::IsoWriter::EdcEccForm1); - - - // Write path table - unsigned char sectorBuff[2048]; - memset(sectorBuff, 0x00, 2048); - - dirTree->GeneratePathTable(sectorBuff, false); - writer->WriteBytes(sectorBuff, 2048, cd::IsoWriter::EdcEccForm1); - writer->WriteBytes(sectorBuff, 2048, cd::IsoWriter::EdcEccForm1); - - dirTree->GeneratePathTable(sectorBuff, true); - writer->WriteBytes(sectorBuff, 2048, cd::IsoWriter::EdcEccForm1); - writer->WriteBytes(sectorBuff, 2048, cd::IsoWriter::EdcEccForm1); - -} +#include "global.h" +#include "iso.h" + +iso::DirTreeClass::DirTreeClass() { + + entries = (DIRENTRY*)malloc(sizeof(DIRENTRY)); + numentries = 0; + recordLBA = 0; + +} + +iso::DirTreeClass::~DirTreeClass() { + + for(int i=0; i 0) + entries = (DIRENTRY*)realloc(entries, sizeof(DIRENTRY)*(numentries+1)); + + memset(&entries[numentries], 0x00, sizeof(DIRENTRY)); + + entries[numentries].id = strdup(tempName); + entries[numentries].type = type; + entries[numentries].subdir = NULL; + + if (srcfile != NULL) + entries[numentries].srcfile = strdup(srcfile); + + if (type != EntryDir) + entries[numentries].length = fileAttrib.st_size; + + tm* fileTime = gmtime(&fileAttrib.st_mtime); + + entries[numentries].date.hour = fileTime->tm_hour; + entries[numentries].date.minute = fileTime->tm_min; + entries[numentries].date.second = fileTime->tm_sec; + entries[numentries].date.day = fileTime->tm_mday; + entries[numentries].date.month = fileTime->tm_mon+1; + entries[numentries].date.year = fileTime->tm_year; + entries[numentries].date.GMToffs = 0; + + numentries++; + + return true; + +} + +void iso::DirTreeClass::AddDummyEntry(int sectors) { + + if (numentries > 0) + entries = (DIRENTRY*)realloc(entries, sizeof(DIRENTRY)*(numentries+1)); + + + entries[numentries].id = NULL; + entries[numentries].srcfile = NULL; + entries[numentries].subdir = NULL; + entries[numentries].type = EntryFile; + entries[numentries].length = 2048*sectors; + + numentries++; + +} + +iso::DirTreeClass* iso::DirTreeClass::AddSubDirEntry(const char* id) { + + for(int i=0; i 0) + entries = (DIRENTRY*)realloc(entries, sizeof(DIRENTRY) * (numentries + 1)); + + memset(&entries[numentries], 0x00, sizeof(DIRENTRY)); + + entries[numentries].id = strdup(id); + entries[numentries].type = EntryDir; + entries[numentries].length = 2048; + entries[numentries].subdir = (void*) new DirTreeClass; + + tm* dirTime = gmtime(&global::BuildTime); + + entries[numentries].date.hour = dirTime->tm_hour; + entries[numentries].date.minute = dirTime->tm_min; + entries[numentries].date.second = dirTime->tm_sec; + entries[numentries].date.month = dirTime->tm_mon+1; + entries[numentries].date.day = dirTime->tm_mday; + entries[numentries].date.year = dirTime->tm_year; + entries[numentries].date.GMToffs = 0; + + for(int i=0; entries[numentries].id[i] != 0x00; i++) + entries[numentries].id[i] = toupper(entries[numentries].id[i]); + + numentries++; + + return (DirTreeClass*)entries[numentries-1].subdir; + +} + +int iso::DirTreeClass::CalculateTreeLBA(int lba) { + + // Set LBA of directory record of this class + recordLBA = lba; + + lba += 1; + + for(int i=0; iCalculateTreeLBA(lba); + + } else { + + // Increment LBA by the size of file + if (entries[i].type == EntryFile) + lba += (entries[i].length+2047)/2048; + else if ((entries[i].type == EntryXA) || (entries[i].type == EntrySTR)) + lba += (entries[i].length+2335)/2336; + + } + + } + + + return lba; + +} + +int iso::DirTreeClass::CalculateDirEntryLen() { + + int dirEntryLen = 96; + + for(int i=0; iSortDirEntries(); + + } else { + + if (entries[i].id == NULL) + numdummies++; + + } + + + } + + + // Sort dummies to end of list + for(int i=1; i 0) { + + temp = entries[j-1]; + entries[j-1] = entries[j]; + entries[j] = temp; + + } + + } + } + + + /* + int numdirs=0,numfiles=0; + // Sort directories to be first in list + for(int i=1; i 1) { + + // Sort the directory entries + for(int i=1; i 0) { + + temp = entries[j-1]; + entries[j-1] = entries[j]; + entries[j] = temp; + + } + + } + } + + } + + + // Count number of files + for(int i=0; i 1) { + + for(int i=numdirs+1; i<(numdirs+numfiles); i++) { + for(int j=numdirs+1; j<(numdirs+numfiles); j++) { + + if (strcmp(entries[j-1].id, entries[j].id) > 0) { + + temp = entries[j-1]; + entries[j-1] = entries[j]; + entries[j] = temp; + + } + + } + } + + } + */ + +} + +int iso::DirTreeClass::WriteDirEntries(cd::IsoWriter* writer, int lastLBA) { + + char dataBuff[2048]; + char* dataBuffPtr=dataBuff; + + cd::ISO_DIR_ENTRY* entry; + cd::ISO_XA_ATTRIB* xa; + + memset(dataBuff, 0x00, 2048); + + for(int i=0; i<2; i++) { + + entry = (cd::ISO_DIR_ENTRY*)dataBuffPtr; + + SetPair32(&entry->entrySize, 2048); + SetPair16(&entry->volSeqNum, 1); + entry->identifierLen = 1; + + int dataLen = 32; + + if (i == 0) { + + SetPair32(&entry->entryOffs, recordLBA); + + } else { + + SetPair32(&entry->entryOffs, lastLBA); + dataBuffPtr[dataLen+1] = 0x01; + + } + + dataLen += 2; + + xa = (cd::ISO_XA_ATTRIB*)(dataBuffPtr+dataLen); + + xa->id[0] = 'X'; + xa->id[1] = 'A'; + xa->type = 0x8800; + + dataLen += sizeof(cd::ISO_XA_ATTRIB); + + entry->flags = 0x02; + entry->entryLength = dataLen; + + tm* dirTime = gmtime(&global::BuildTime); + + entry->entryDate.year = dirTime->tm_year; + entry->entryDate.month = dirTime->tm_mon+1; + entry->entryDate.day = dirTime->tm_mday; + entry->entryDate.hour = dirTime->tm_hour; + entry->entryDate.minute = dirTime->tm_min; + entry->entryDate.second = dirTime->tm_sec; + + dataBuffPtr += dataLen; + + } + + for(int i=0; iCalculateDirEntryLen(); + entry->flags = 0x02; + + } else { + + entry->flags = 0x00; + + } + + SetPair32(&entry->entryOffs, entries[i].lba); + SetPair32(&entry->entrySize, entries[i].length); + SetPair16(&entry->volSeqNum, 1); + + entry->identifierLen = strlen(entries[i].id); + entry->entryDate = entries[i].date; + + int dataLen = 33; + + strncpy(&dataBuffPtr[dataLen], entries[i].id, entry->identifierLen); + dataLen += 2*((entry->identifierLen+1)/2); + + if ((entry->identifierLen%2) == 0) + dataLen++; + + xa = (cd::ISO_XA_ATTRIB*)(dataBuffPtr+dataLen); + + xa->id[0] = 'X'; + xa->id[1] = 'A'; + + if (entries[i].type == EntryFile) + xa->type = 0x0800; + else if (entries[i].type == EntryDir) + xa->type = 0x8800; + + dataLen += sizeof(cd::ISO_XA_ATTRIB); + entry->entryLength = dataLen; + + dataBuffPtr += dataLen; + + } + + if ((int)(dataBuffPtr-dataBuff) > 2048) + return 0; + + writer->SeekToSector(recordLBA); + writer->WriteBytes(dataBuff, 2048, cd::IsoWriter::EdcEccForm1); + + return 1; + +} + +int iso::DirTreeClass::WriteDirectoryRecords(cd::IsoWriter* writer, int lastDirLBA) { + + if (lastDirLBA == 0) + lastDirLBA = recordLBA; + + WriteDirEntries(writer, lastDirLBA); + + for(int i=0; iWriteDirectoryRecords(writer, recordLBA)) + return 0; + + } + + } + + return 1; + +} + +int iso::DirTreeClass::WriteFiles(cd::IsoWriter* writer) { + + for(int i=0; iSeekToSector(entries[i].lba); + + // Write files and dummies as regular data sectors + if (entries[i].type == EntryFile) { + + char buff[2048]; + + if (entries[i].srcfile != NULL) { + + if (!global::QuietMode) + printf(" Packing %s... ", entries[i].srcfile); + + FILE *fp = fopen(entries[i].srcfile, "rb"); + + while(!feof(fp)) { + + memset(buff, 0x00, 2048); + + fread(buff, 1, 2048, fp); + writer->WriteBytes(buff, 2048, cd::IsoWriter::EdcEccForm1); + + } + + fclose(fp); + + if (!global::QuietMode) + printf("Done.\n"); + + } else { + + memset(buff, 0x00, 2048); + + for(int c=0; c<(entries[i].length/2048); c++) { + + writer->WriteBytes(buff, 2048, cd::IsoWriter::EdcEccForm1); + + } + + } + + // Write XA audio streams as Mode 2 Form 2 sectors without ECC + } else if (entries[i].type == EntryXA) { + + char buff[2336]; + + if (!global::QuietMode) + printf(" Packing XA %s... ", entries[i].srcfile); + + FILE *fp = fopen(entries[i].srcfile, "rb"); + + while(!feof(fp)) { + + memset(buff, 0x00, 2336); + + fread(buff, 1, 2336, fp); + writer->WriteBytesXA(buff, 2336, cd::IsoWriter::EdcEccNone); + + } + + fclose(fp); + + if (!global::QuietMode) + printf("Done.\n"); + + // Write STR video streams as Mode 2 Form 1 (video sectors) and Mode 2 Form 2 (XA audio sectors) + // Video sectors have EDC/ECC while XA does not + } else if (entries[i].type == EntrySTR) { + + char buff[2336]; + + if (!global::QuietMode) + printf(" Packing STR %s... ", entries[i].srcfile); + + FILE *fp = fopen(entries[i].srcfile, "rb"); + + while(!feof(fp)) { + + memset(buff, 0x00, 2336); + fread(buff, 1, 2336, fp); + + // Check if sector is a video sector + if (buff[2] == 0x48) + writer->WriteBytesXA(buff, 2336, cd::IsoWriter::EdcEccForm1); // If so, write it as Mode 2 Form 1 + else + writer->WriteBytesXA(buff, 2336, cd::IsoWriter::EdcEccNone); // Otherwise, write it as an XA track + + } + + fclose(fp); + + if (!global::QuietMode) + printf("Done.\n"); + + } else if (entries[i].type == EntryDir) { + + ((DirTreeClass*)entries[i].subdir)->WriteFiles(writer); + + } + + } + + return 1; + +} + +void iso::DirTreeClass::PrintEntries() { + + printf("RECORD LBA : %d\n", recordLBA); + for(int i=0; i "); + + printf("L:%d LBA:%d T:%d S:%s\n", entries[i].length, entries[i].lba, entries[i].type, entries[i].srcfile); + + if (entries[i].subdir != NULL) { + + ((DirTreeClass*)entries[i].subdir)->PrintEntries(); + + } + + } + +} + + +int iso::DirTreeClass::CalculatePathTableLenSub(DIRENTRY* dirEntry) { + + int len = 8; + + // Put identifier (NULL if first entry) + len += 2*((strlen(dirEntry->id)+1)/2); + + for(int i=0; i<((DirTreeClass*)dirEntry->subdir)->numentries; i++) { + + if (((DirTreeClass*)dirEntry->subdir)->entries[i].type == EntryDir) { + + len += CalculatePathTableLenSub(&((DirTreeClass*)dirEntry->subdir)->entries[i]); + + } + + } + + return len; + +} + +int iso::DirTreeClass::CalculatePathTableLen() { + + int len = 10; + + for(int i=0; iid); // Directory identifier length + buff++; + *buff = 0; // Extended attribute record length (unused) + buff++; + + // Write LBA and directory number index + dirIndex++; + *((int*)buff) = ((DirTreeClass*)dirEntry->subdir)->recordLBA; + memcpy(buff+4, &parentIndex, 2); + + if (msb) { + + cd::SwapBytes(buff, 4); + cd::SwapBytes(buff+4, 2); + + } + + buff += 6; + + // Put identifier (NULL if first entry) + strncpy((char*)buff, dirEntry->id, strlen(dirEntry->id)); + buff += 2*((strlen(dirEntry->id)+1)/2); + + parentIndex = dirIndex; + + if (dirEntry->subdir != NULL) { + + for(int i=0; i<((DirTreeClass*)dirEntry->subdir)->numentries; i++) { + + if (((DirTreeClass*)dirEntry->subdir)->entries[i].type == EntryDir) { + + buff = GenPathTableSub(buff, &((DirTreeClass*)dirEntry->subdir)->entries[i], parentIndex, msb); + + } + + } + + } + + return buff; + +} + +int iso::DirTreeClass::GeneratePathTable(unsigned char* buff, int msb) { + + unsigned char* oldBuffPtr = buff; + + *buff = 1; // Directory identifier length + buff++; + *buff = 0; // Extended attribute record length (unused) + buff++; + + int lba = recordLBA; + + // Write LBA and directory number index + dirIndex = 1; + memcpy(buff, &lba, 4); + memcpy(buff+4, &dirIndex, 2); + + if (msb) { + cd::SwapBytes(buff, 4); + cd::SwapBytes(buff+4, 2); + } + + buff += 6; + + // Put identifier (NULL if first entry) + memset(buff, 0x00, 2); + buff += 2; + + for(int i=0; i 2048) + break; + + } + + return (int)(buff-oldBuffPtr); + +} + +int iso::DirTreeClass::GetFileCountTotal() { + + int numfiles = 0; + + for(int i=0; iGetFileCountTotal(); + + } + + } + + return numfiles; + +} + +int iso::DirTreeClass::GetDirCountTotal() { + + int numdirs = 0; + + for(int i=0; iGetDirCountTotal(); + + } + + } + + return numdirs; + +} + +void iso::WriteLicenseData(cd::IsoWriter* writer, void* data) { + + writer->SeekToSector(0); + writer->WriteBytesXA(data, 2336*12, cd::IsoWriter::EdcEccForm1); + +} + +void iso::WriteDescriptor(cd::IsoWriter* writer, iso::IDENTIFIERS id, iso::DirTreeClass* dirTree, int imageLen) { + + + cd::ISO_DESCRIPTOR isoDescriptor; + + memset(&isoDescriptor, 0x00, sizeof(cd::ISO_DESCRIPTOR)); + + isoDescriptor.header.type = 1; + isoDescriptor.header.version = 1; + strncpy((char*)isoDescriptor.header.id, "CD001", 5); + + // Set System identifier + memset(isoDescriptor.systemID, 0x20, 32); + if (id.SystemID != NULL) { + + for(int i=0; i<(int)strlen(id.SystemID); i++) + isoDescriptor.systemID[i] = toupper(id.SystemID[i]); + + } + + // Set Volume identifier + memset(isoDescriptor.volumeID, 0x20, 32); + if (id.VolumeID != NULL) { + + for(int i=0; i<(int)strlen(id.VolumeID); i++) + isoDescriptor.volumeID[i] = toupper(id.VolumeID[i]); + + } + + // Set Application identifier + memset(isoDescriptor.applicationIdentifier, 0x20, 128); + if (id.Application != NULL) { + + for(int i=0; i<(int)strlen(id.Application); i++) + isoDescriptor.applicationIdentifier[i] = toupper(id.Application[i]); + + } + + // Volume Set identifier + memset(isoDescriptor.volumeSetIdentifier, 0x20, 128); + if (id.VolumeSet != NULL) { + + for(int i=0; i<(int)strlen(id.VolumeSet); i++) + isoDescriptor.volumeSetIdentifier[i] = toupper(id.VolumeSet[i]); + + } + + // Publisher identifier + memset(isoDescriptor.publisherIdentifier, 0x20, 128); + if (id.Publisher != NULL) { + + for(int i=0; i<(int)strlen(id.Publisher); i++) + isoDescriptor.publisherIdentifier[i] = toupper(id.Publisher[i]); + + } + + // Data preparer identifier + memset(isoDescriptor.dataPreparerIdentifier, 0x20, 128); + strcpy(isoDescriptor.dataPreparerIdentifier, "THIS DISC IMAGE WAS CREATED USING MKPSXISO BY LAMEGUY64 OF MEIDO-TEK PRODUCTIONS HTTPS://GITHUB.COM/LAMEGUY64/MKPSXISO"); + *strchr(isoDescriptor.dataPreparerIdentifier, 0x00) = 0x20; + if (id.DataPreparer != NULL) { + + for(int i=0; i<(int)strlen(id.DataPreparer); i++) + isoDescriptor.dataPreparerIdentifier[i] = toupper(id.DataPreparer[i]); + + } + + // Unneeded identifiers + memset(isoDescriptor.copyrightFileIdentifier, 0x20, 37); + memset(isoDescriptor.abstractFileIdentifier, 0x20, 37); + memset(isoDescriptor.bibliographicFilelIdentifier, 0x20, 37); + + + tm* imageTime = localtime(&global::BuildTime); + + sprintf(isoDescriptor.volumeCreateDate, "%04d%02d%02d%02d%02d%02d00", + imageTime->tm_year+1900, + imageTime->tm_mon, + imageTime->tm_mday, + imageTime->tm_hour, + imageTime->tm_min, + imageTime->tm_sec + ); + + sprintf(isoDescriptor.volumeModifyDate, "%04d%02d%02d%02d%02d%02d00", + imageTime->tm_year+1900, + imageTime->tm_mon, + imageTime->tm_mday, + imageTime->tm_hour, + imageTime->tm_min, + imageTime->tm_sec + ); + + strcpy(isoDescriptor.volumeEffeciveDate, "0000000000000000"); + strcpy(isoDescriptor.volumeExpiryDate, "0000000000000000"); + + isoDescriptor.fileStructVersion = 1; + strncpy((char*)&isoDescriptor.appData[141], "CD-XA001", 8); + + cd::SetPair16(&isoDescriptor.volumeSetSize, 1); + cd::SetPair16(&isoDescriptor.volumeSeqNumber, 1); + cd::SetPair16(&isoDescriptor.sectorSize, 2048); + cd::SetPair32(&isoDescriptor.pathTableSize, dirTree->CalculatePathTableLen()); + + // Setup the root directory record + isoDescriptor.rootDirRecord.entryLength = 34; + isoDescriptor.rootDirRecord.extLength = 0; + cd::SetPair32(&isoDescriptor.rootDirRecord.entryOffs, 22); + cd::SetPair32(&isoDescriptor.rootDirRecord.entrySize, 0x800); + isoDescriptor.rootDirRecord.flags = 0x02; + cd::SetPair16(&isoDescriptor.rootDirRecord.volSeqNum, 1); + isoDescriptor.rootDirRecord.identifierLen = 1; + isoDescriptor.rootDirRecord.identifier = 0x01; + + isoDescriptor.pathTable1Offs = 18; + isoDescriptor.pathTable2Offs = 19; + isoDescriptor.pathTable1MSBoffs = 20; + cd::SwapBytes(&isoDescriptor.pathTable1MSBoffs, 4); + isoDescriptor.pathTable2MSBoffs = 21; + cd::SwapBytes(&isoDescriptor.pathTable2MSBoffs, 4); + + SetPair32(&isoDescriptor.volumeSize, imageLen); + + // Write the descriptor + writer->SeekToSector(16); + writer->WriteBytes(&isoDescriptor, sizeof(cd::ISO_DESCRIPTOR), cd::IsoWriter::EdcEccForm1); + + + // Write descriptor terminator; + memset(&isoDescriptor, 0x00, sizeof(cd::ISO_DESCRIPTOR)); + isoDescriptor.header.type = 255; + isoDescriptor.header.version = 1; + strncpy(isoDescriptor.header.id, "CD001", 5); + + writer->WriteBytes(&isoDescriptor, sizeof(cd::ISO_DESCRIPTOR), cd::IsoWriter::EdcEccForm1); + + + // Write path table + unsigned char sectorBuff[2048]; + memset(sectorBuff, 0x00, 2048); + + dirTree->GeneratePathTable(sectorBuff, false); + writer->WriteBytes(sectorBuff, 2048, cd::IsoWriter::EdcEccForm1); + writer->WriteBytes(sectorBuff, 2048, cd::IsoWriter::EdcEccForm1); + + dirTree->GeneratePathTable(sectorBuff, true); + writer->WriteBytes(sectorBuff, 2048, cd::IsoWriter::EdcEccForm1); + writer->WriteBytes(sectorBuff, 2048, cd::IsoWriter::EdcEccForm1); + +} diff --git a/src/main.cpp b/src/main.cpp index 39f36c6..a030596 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,795 +1,795 @@ -#include -#include - -#include "cdwriter.h" // CD image reader/writer module -#include "iso.h" // ISO file system generator module - -#define VERSION "1.04" - -namespace global { - - time_t BuildTime; - int QuietMode = false; - char* XMLscript = NULL; - -}; - - -int ParseDirectory(iso::DirTreeClass* dirTree, tinyxml2::XMLElement* dirElement); -int ParseISOfileSystem(cd::IsoWriter* writer, tinyxml2::XMLElement* trackElement); - -int PackWaveFile(cd::IsoWriter* writer, const char* wavFile); -int GetSize(const char* fileName); - - -int main(int argc, const char* argv[]) { - - // Parse arguments - for(int i=1; i [-q]\n\n"); - printf("