Compare commits

..

No commits in common. "master" and "7.1" have entirely different histories.
master ... 7.1

56 changed files with 747 additions and 4082 deletions

712
LICENSE
View File

@ -1,373 +1,339 @@
Mozilla Public License Version 2.0 GNU GENERAL PUBLIC LICENSE
================================== Version 2, June 1991
1. Definitions 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
1.1. "Contributor" of this license document, but changing it is not allowed.
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software. Preamble
1.2. "Contributor Version" The licenses for most software are designed to take away your
means the combination of the Contributions of others (if any) used freedom to share and change it. By contrast, the GNU General Public
by a Contributor and that particular Contributor's Contribution. 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
1.3. "Contribution" General Public License applies to most of the Free Software
means Covered Software of a particular Contributor. Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
1.4. "Covered Software" the GNU Lesser General Public License instead.) You can apply it to
means Source Code Form to which the initial Contributor has attached your programs, too.
the notice in Exhibit A, the Executable Form of such Source Code
Form, and Modifications of such Source Code Form, in each case When we speak of free software, we are referring to freedom, not
including portions thereof. price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
1.5. "Incompatible With Secondary Licenses" this service if you wish), that you receive source code or can get it
means 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.
(a) that the initial Contributor has attached the notice described
in Exhibit B to the Covered Software; or 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.
(b) that the Covered Software was made available under the terms of These restrictions translate to certain responsibilities for you if you
version 1.1 or earlier of the License, but not also under the distribute copies of the software, or if you modify it.
terms of a Secondary License.
For example, if you distribute copies of such a program, whether
1.6. "Executable Form" gratis or for a fee, you must give the recipients all the rights that
means any form of the work other than Source Code Form. 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
1.7. "Larger Work" rights.
means a work that combines Covered Software with other material, in
a separate file or files, that is not Covered Software. We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
1.8. "License" distribute and/or modify the software.
means this document.
Also, for each author's protection and ours, we want to make certain
1.9. "Licensable" that everyone understands that there is no warranty for this free
means having the right to grant, to the maximum extent possible, software. If the software is modified by someone else and passed on, we
whether at the time of the initial grant or subsequently, any and want its recipients to know that what they have is not the original, so
all of the rights conveyed by this License. that any problems introduced by others will not reflect on the original
authors' reputations.
1.10. "Modifications"
means any of the following: Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
(a) any file in Source Code Form that results from an addition to, program will individually obtain patent licenses, in effect making the
deletion from, or modification of the contents of Covered program proprietary. To prevent this, we have made it clear that any
Software; or patent must be licensed for everyone's free use or not licensed at all.
(b) any new file in Source Code Form that contains any Covered The precise terms and conditions for copying, distribution and
Software. modification follow.
1.11. "Patent Claims" of a Contributor GNU GENERAL PUBLIC LICENSE
means any patent claim(s), including without limitation, method, TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the 0. This License applies to any program or other work which contains
License, by the making, using, selling, offering for sale, having a notice placed by the copyright holder saying it may be distributed
made, import, or transfer of either its Contributions or its under the terms of this General Public License. The "Program", below,
Contributor Version. 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:
1.12. "Secondary License" that is to say, a work containing the Program or a portion of it,
means either the GNU General Public License, Version 2.0, the GNU either verbatim or with modifications and/or translated into another
Lesser General Public License, Version 2.1, the GNU Affero General language. (Hereinafter, translation is included without limitation in
Public License, Version 3.0, or any later versions of those the term "modification".) Each licensee is addressed as "you".
licenses.
Activities other than copying, distribution and modification are not
1.13. "Source Code Form" covered by this License; they are outside its scope. The act of
means the form of the work preferred for making modifications. running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
1.14. "You" (or "Your") Program (independent of having been made by running the Program).
means an individual or a legal entity exercising rights under this Whether that is true depends on what the Program does.
License. For legal entities, "You" includes any entity that
controls, is controlled by, or is under common control with You. For 1. You may copy and distribute verbatim copies of the Program's
purposes of this definition, "control" means (a) the power, direct source code as you receive it, in any medium, provided that you
or indirect, to cause the direction or management of such entity, conspicuously and appropriately publish on each copy an appropriate
whether by contract or otherwise, or (b) ownership of more than copyright notice and disclaimer of warranty; keep intact all the
fifty percent (50%) of the outstanding shares or beneficial notices that refer to this License and to the absence of any warranty;
ownership of such entity. and give any other recipients of the Program a copy of this License
along with the Program.
2. License Grants and Conditions
-------------------------------- 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.1. Grants
2. You may modify your copy or copies of the Program or any portion
Each Contributor hereby grants You a world-wide, royalty-free, of it, thus forming a work based on the Program, and copy and
non-exclusive license: distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
(a) under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available, a) You must cause the modified files to carry prominent notices
modify, display, perform, distribute, and otherwise exploit its stating that you changed the files and the date of any change.
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and 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
(b) under Patent Claims of such Contributor to make, use, sell, offer part thereof, to be licensed as a whole at no charge to all third
for sale, have made, import, and otherwise transfer either its parties under the terms of this License.
Contributions or its Contributor Version.
c) If the modified program normally reads commands interactively
2.2. Effective Date when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
The licenses granted in Section 2.1 with respect to any Contribution announcement including an appropriate copyright notice and a
become effective for each Contribution on the date the Contributor first notice that there is no warranty (or else, saying that you provide
distributes such Contribution. a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
2.3. Limitations on Grant Scope License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
The licenses granted in this Section 2 are the only rights granted under the Program is not required to print an announcement.)
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License. These requirements apply to the modified work as a whole. If
Notwithstanding Section 2.1(b) above, no patent license is granted by a identifiable sections of that work are not derived from the Program,
Contributor: and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
(a) for any code that a Contributor has removed from Covered Software; sections when you distribute them as separate works. But when you
or 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
(b) for infringements caused by: (i) Your and any other third party's this License, whose permissions for other licensees extend to the
modifications of Covered Software, or (ii) the combination of its entire whole, and thus to each and every part regardless of who wrote it.
Contributions with other software (except as part of its Contributor
Version); or 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
(c) under Patent Claims infringed by Covered Software in the absence of exercise the right to control the distribution of derivative or
its Contributions. collective works based on the Program.
This License does not grant any rights in the trademarks, service marks, In addition, mere aggregation of another work not based on the Program
or logos of any Contributor (except as may be necessary to comply with with the Program (or with a work based on the Program) on a volume of
the notice requirements in Section 3.4). a storage or distribution medium does not bring the other work under
the scope of this License.
2.4. Subsequent Licenses
3. You may copy and distribute the Program (or a work based on it,
No Contributor makes additional grants as a result of Your choice to under Section 2) in object code or executable form under the terms of
distribute the Covered Software under a subsequent version of this Sections 1 and 2 above provided that you also do one of the following:
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3). a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
2.5. Representation 1 and 2 above on a medium customarily used for software interchange; or,
Each Contributor represents that the Contributor believes its b) Accompany it with a written offer, valid for at least three
Contributions are its original creation(s) or it has sufficient rights years, to give any third party, for a charge no more than your
to grant the rights to its Contributions conveyed by this License. cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
2.6. Fair Use distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other c) Accompany it with the information you received as to the offer
equivalents. to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
2.7. Conditions received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
in Section 2.1. The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
3. Responsibilities 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
3.1. Distribution of Source Form special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
All distribution of Covered Software in Source Code Form, including any form) with the major components (compiler, kernel, and so on) of the
Modifications that You create or to which You contribute, must be under operating system on which the executable runs, unless that component
the terms of this License. You must inform recipients that the Source itself accompanies the executable.
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not If distribution of executable or object code is made by offering
attempt to alter or restrict the recipients' rights in the Source Code access to copy from a designated place, then offering equivalent
Form. access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
3.2. Distribution of Executable Form compelled to copy the source along with the object code.
If You distribute Covered Software in Executable Form then: 4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
(a) such Covered Software must also be made available in Source Code otherwise to copy, modify, sublicense or distribute the Program is
Form, as described in Section 3.1, and You must inform recipients of void, and will automatically terminate your rights under this License.
the Executable Form how they can obtain a copy of such Source Code However, parties who have received copies, or rights, from you under
Form by reasonable means in a timely manner, at a charge no more this License will not have their licenses terminated so long as such
than the cost of distribution to the recipient; and parties remain in full compliance.
(b) You may distribute such Executable Form under the terms of this 5. You are not required to accept this License, since you have not
License, or sublicense it under different terms, provided that the signed it. However, nothing else grants you permission to modify or
license for the Executable Form does not attempt to limit or alter distribute the Program or its derivative works. These actions are
the recipients' rights in the Source Code Form under this License. prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
3.3. Distribution of a Larger Work Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
You may create and distribute a Larger Work under terms of Your choice, the Program or works based on it.
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered 6. Each time you redistribute the Program (or any work based on the
Software with a work governed by one or more Secondary Licenses, and the Program), the recipient automatically receives a license from the
Covered Software is not Incompatible With Secondary Licenses, this original licensor to copy, distribute or modify the Program subject to
License permits You to additionally distribute such Covered Software these terms and conditions. You may not impose any further
under the terms of such Secondary License(s), so that the recipient of restrictions on the recipients' exercise of the rights granted herein.
the Larger Work may, at their option, further distribute the Covered You are not responsible for enforcing compliance by third parties to
Software under the terms of either this License or such Secondary this License.
License(s).
7. If, as a consequence of a court judgment or allegation of patent
3.4. Notices infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
You may not remove or alter the substance of any license notices otherwise) that contradict the conditions of this License, they do not
(including copyright notices, patent notices, disclaimers of warranty, excuse you from the conditions of this License. If you cannot
or limitations of liability) contained within the Source Code Form of distribute so as to satisfy simultaneously your obligations under this
the Covered Software, except that You may alter any license notices to License and any other pertinent obligations, then as a consequence you
the extent required to remedy known factual inaccuracies. may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
3.5. Application of Additional Terms 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
You may choose to offer, and to charge a fee for, warranty, support, refrain entirely from distribution of the Program.
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on If any portion of this section is held invalid or unenforceable under
behalf of any Contributor. You must make it absolutely clear that any any particular circumstance, the balance of the section is intended to
such warranty, support, indemnity, or liability obligation is offered by apply and the section as a whole is intended to apply in other
You alone, and You hereby agree to indemnify every Contributor for any circumstances.
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional It is not the purpose of this section to induce you to infringe any
disclaimers of warranty and limitations of liability specific to any patents or other property right claims or to contest validity of any
jurisdiction. such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
4. Inability to Comply Due to Statute or Regulation 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
If it is impossible for You to comply with any of the terms of this system; it is up to the author/donor to decide if he or she is willing
License with respect to some or all of the Covered Software due to to distribute software through any other system and a licensee cannot
statute, judicial order, or regulation then You must: (a) comply with impose that choice.
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must This section is intended to make thoroughly clear what is believed to
be placed in a text file included with all distributions of the Covered be a consequence of the rest of this License.
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a 8. If the distribution and/or use of the Program is restricted in
recipient of ordinary skill to be able to understand it. certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
5. Termination 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
5.1. The rights granted under this License will terminate automatically the limitation as if written in the body of this License.
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular 9. The Free Software Foundation may publish revised and/or new versions
Contributor are reinstated (a) provisionally, unless and until such of the General Public License from time to time. Such new versions will
Contributor explicitly and finally terminates Your grants, and (b) on an be similar in spirit to the present version, but may differ in detail to
ongoing basis, if such Contributor fails to notify You of the address new problems or concerns.
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular Each version is given a distinguishing version number. If the Program
Contributor are reinstated on an ongoing basis if such Contributor specifies a version number of this License which applies to it and "any
notifies You of the non-compliance by some reasonable means, this is the later version", you have the option of following the terms and conditions
first time You have received notice of non-compliance with this License either of that version or of any later version published by the Free
from such Contributor, and You become compliant prior to 30 days after Software Foundation. If the Program does not specify a version number of
Your receipt of the notice. this License, you may choose any version ever published by the Free Software
Foundation.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions, 10. If you wish to incorporate parts of the Program into other free
counter-claims, and cross-claims) alleging that a Contributor Version programs whose distribution conditions are different, write to the author
directly or indirectly infringes any patent, then the rights granted to to ask for permission. For software which is copyrighted by the Free
You by any and all Contributors for the Covered Software under Section Software Foundation, write to the Free Software Foundation; we sometimes
2.1 of this License shall terminate. 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
5.3. In the event of termination under Sections 5.1 or 5.2 above, all of promoting the sharing and reuse of software generally.
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License NO WARRANTY
prior to termination shall survive termination.
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
* 6. Disclaimer of Warranty * 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
* Covered Software is provided under this License on an "as is" * TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
* basis, without warranty of any kind, either expressed, implied, or * PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
* statutory, including, without limitation, warranties that the * REPAIR OR CORRECTION.
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the * 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
* quality and performance of the Covered Software is with You. * WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
* Should any Covered Software prove defective in any respect, You * REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
* (not any Contributor) assume the cost of any necessary servicing, * INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
* repair, or correction. This disclaimer of warranty constitutes an * OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
* essential part of this License. No use of any Covered Software is * TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
* authorized under this License except under this disclaimer. * 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
* *
* 7. Limitation of Liability * How to Apply These Terms to Your New Programs
* -------------------------- *
* * If you develop a new program, and you want it to be of the greatest
* Under no circumstances and under no legal theory, whether tort * possible use to the public, the best way to achieve this is to make it
* (including negligence), contract, or otherwise, shall any * free software which everyone can redistribute and change under these terms.
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, * To do so, attach the following notices to the program. It is safest
* special, incidental, or consequential damages of any character * to attach them to the start of each source file to most effectively
* including, without limitation, damages for lost profits, loss of * convey the exclusion of warranty; and each file should have at least
* goodwill, work stoppage, computer failure or malfunction, or any * the "copyright" line and a pointer to where the full notice is found.
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This * <one line to give the program's name and a brief idea of what it does.>
* limitation of liability shall not apply to liability for death or * Copyright (C) <year> <name of author>
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some * This program is free software; you can redistribute it and/or modify
* jurisdictions do not allow the exclusion or limitation of * it under the terms of the GNU General Public License as published by
* incidental or consequential damages, so this exclusion and * the Free Software Foundation; either version 2 of the License, or
* limitation may not apply to You. * (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
8. Litigation MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
------------- GNU General Public License for more details.
Any litigation relating to this License may be brought only in the You should have received a copy of the GNU General Public License along
courts of a jurisdiction where the defendant maintains its principal with this program; if not, write to the Free Software Foundation, Inc.,
place of business and such litigation shall be governed by laws of that 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring Also add information on how to contact you by electronic and paper mail.
cross-claims or counter-claims.
If the program is interactive, make it output a short notice like this
9. Miscellaneous when it starts in an interactive mode:
----------------
Gnomovision version 69, Copyright (C) year name of author
This License represents the complete agreement concerning the subject Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
matter hereof. If any provision of this License is held to be This is free software, and you are welcome to redistribute it
unenforceable, such provision shall be reformed only to the extent under certain conditions; type `show c' for details.
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter The hypothetical commands `show w' and `show c' should show the appropriate
shall not be used to construe this License against a Contributor. 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
10. Versions of the License mouse-clicks or menu items--whatever suits your program.
---------------------------
You should also get your employer (if you work as a programmer) or your
10.1. New Versions school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or Yoyodyne, Inc., hereby disclaims all copyright interest in the program
publish new versions of this License. Each version will be given a `Gnomovision' (which makes passes at compilers) written by James Hacker.
distinguishing version number.
<signature of Ty Coon>, 1 April 1989
10.2. Effect of New Versions Ty Coon, President of Vice
You may distribute the Covered Software under the terms of the version This General Public License does not permit incorporating your program into
of the License under which You originally received the Covered Software, proprietary programs. If your program is a subroutine library, you may
or under the terms of any subsequent version published by the license consider it more useful to permit linking proprietary applications with the
steward. library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.

View File

@ -2,8 +2,8 @@ include LICENSE
include README.rst include README.rst
recursive-include scripts * recursive-include scripts *
include atrcopy/templates/* include atrcopy/templates/*
include test_data/*_test?.atr include test_data/dos*atr
include test_data/*_test?.atr.* include test_data/sd*atr
include test_data/*.xex include test_data/*.xex
include test_data/rebuild.sh include test_data/rebuild.sh
include test_data/create_binary.py include test_data/create_binary.py

View File

@ -12,29 +12,30 @@ Prerequisites
Python Python
------ ------
Starting with ``atrcopy`` 7.0, Python 3.6 is **required**. Python 2 support has Starting with ``atrcopy`` 7.0, Python 2 support has been dropped.
been dropped. Python 3.7 and beyond will be supported when they are released,
but 3.6 will probably remain the minimum version. From what I know now of
future Python versions, I don't plan on requiring any language features beyond
3.6.
Supported Python versions: Supported Python versions:
* Python 3.6 (and later) * Python 3.6 and later
If you need Python 2 support, ``atrcopy`` 6.5 and earlier supports Python 2.7, If you need Python 2 support, ``atrcopy`` 6.5 and earlier supports:
which you can install with ``pip install "atrcopy<7.0"``
* Python 2.7
* Python 3.5
* Python 3.6
Python 3 compatibility was added in ``atrcopy`` 5.0, but support for Python 3.4
and older is not planned.
Dependencies Dependencies
------------ ------------
* numpy Starting with ``atrcopy`` 2.0, `numpy <http://www.numpy.org/>`_ is required. It
will be automatically installed when installing ``atrcopy`` with ``pip`` as
It will be automatically installed when installing ``atrcopy`` with ``pip`` as
described below. described below.
For development, pytest is used to run the test suite, but this is not required It also uses the pure-Python ``future`` compatibility library to help support
for normal installation of ``atrcopy``. both Python 2 and Python 3.
Installation Installation
============ ============
@ -119,27 +120,6 @@ Other Supported Formats
atari800 ``.car`` format atari800 ``.car`` format
Supported Compression/Container Formats
---------------------------------------
Starting with ``atrcopy`` 8.0, compressed disk images are supported
transparently, so any type of disk image compressed with one of the supported
container formats can be used directly, without first decompressing it before
running ``atrcopy``.
+--------------------+----------+------+-------+------------------------------+
| Container | File Ext | Read | Write | Status |
+====================+==========+======+=======+==============================+
| gzip | .gz | Yes | No | Read only |
+--------------------+----------+------+-------+------------------------------+
| bzip2 | .bz2 | Yes | No | Read only |
+--------------------+----------+------+-------+------------------------------+
| lzma | .xz | Yes | No | Read only |
+--------------------+----------+------+-------+------------------------------+
| Disk Communicator | .dcm | No | No | Recognized but unimplemented |
+--------------------+----------+------+-------+------------------------------+
Usage Usage
===== =====

View File

@ -6,24 +6,23 @@ import json
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
from ._version import __version__ from ._metadata import __version__
try: try:
import numpy as np import numpy as np
except ImportError: except ImportError:
raise RuntimeError("atrcopy %s requires numpy" % __version__) raise RuntimeError("atrcopy %s requires numpy" % __version__)
from . import errors from .errors import *
from .ataridos import AtrHeader, AtariDosDiskImage, BootDiskImage, AtariDosFile, XexContainerSegment, get_xex, add_atr_header from .ataridos import AtrHeader, AtariDosDiskImage, BootDiskImage, AtariDosFile, XexContainerSegment, get_xex, add_atr_header
from .dos33 import Dos33DiskImage from .dos33 import Dos33DiskImage
from .kboot import KBootImage, add_xexboot_header from .kboot import KBootImage, add_xexboot_header
from .segments import SegmentData, SegmentSaver, DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentedFileSegment, user_bit_mask, match_bit_mask, comment_bit_mask, data_style, selected_bit_mask, diff_bit_mask, not_user_bit_mask, interleave_segments, SegmentList, get_style_mask, get_style_bits from .segments import SegmentData, SegmentSaver, DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentedFileSegment, user_bit_mask, match_bit_mask, comment_bit_mask, data_style, selected_bit_mask, diff_bit_mask, not_user_bit_mask, interleave_segments, SegmentList, get_style_mask, get_style_bits
from .spartados import SpartaDosDiskImage from .spartados import SpartaDosDiskImage
from .cartridge import A8CartHeader, AtariCartImage, RomImage from .cartridge import A8CartHeader, AtariCartImage
from .parsers import SegmentParser, DefaultSegmentParser, guess_parser_by_size, guess_parser_for_mime, guess_parser_for_system, guess_container, iter_parsers, iter_known_segment_parsers, mime_parse_order, parsers_for_filename from .parsers import SegmentParser, DefaultSegmentParser, guess_parser_for_mime, guess_parser_for_system, iter_parsers, iter_known_segment_parsers, mime_parse_order, parsers_for_filename
from .magic import guess_detail_for_mime from .magic import guess_detail_for_mime
from .utils import to_numpy, text_to_int from .utils import to_numpy, text_to_int
from .dummy import LocalFilesystem
def process(image, dirent, options): def process(image, dirent, options):
@ -54,47 +53,37 @@ def process(image, dirent, options):
print(dirent) print(dirent)
def find_diskimage_from_data(data, verbose=False): def find_diskimage(filename):
data = to_numpy(data) try:
parser = None
container = guess_container(data, verbose)
if container is not None:
data = container.unpacked
rawdata = SegmentData(data)
mime, parser = guess_parser_by_size(rawdata)
if parser is None:
for mime in mime_parse_order:
if verbose:
print("Trying MIME type %s" % mime)
parser = guess_parser_for_mime(mime, rawdata, verbose)
if parser is None:
continue
if verbose:
print("Found parser %s" % parser.menu_name)
mime2 = guess_detail_for_mime(mime, rawdata, parser)
if mime != mime2:
mime = mime2
if verbose:
print("Magic signature match: %s" % mime)
break
if parser is None:
raise errors.UnsupportedDiskImage("Unknown disk image type")
return parser, mime
def find_diskimage(filename, verbose=False):
if filename == ".":
parser = LocalFilesystem()
mime = ""
else:
with open(filename, "rb") as fh: with open(filename, "rb") as fh:
if verbose: if options.verbose:
print("Loading file %s" % filename) print("Loading file %s" % filename)
data = to_numpy(fh.read()) rawdata = SegmentData(fh.read())
parser, mime = find_diskimage_from_data(data, verbose) parser = None
parser.image.filename = filename for mime in mime_parse_order:
parser.image.ext = "" if options.verbose:
return parser, mime print("Trying MIME type %s" % mime)
parser = guess_parser_for_mime(mime, rawdata, options.verbose)
if parser is None:
continue
if options.verbose:
print("Found parser %s" % parser.menu_name)
mime2 = guess_detail_for_mime(mime, rawdata, parser)
if mime != mime2 and options.verbose:
print("Signature match: %s" % mime2)
break
if parser is None:
print("%s: Unknown disk image type" % filename)
except UnsupportedDiskImage as e:
print("%s: %s" % (filename, e))
return None
except IOError as e:
print("%s: %s" % (filename, e))
return None
else:
parser.image.filename = filename
parser.image.ext = ""
return parser
def extract_files(image, files): def extract_files(image, files):
@ -103,25 +92,18 @@ def extract_files(image, files):
for name in files: for name in files:
try: try:
dirent = image.find_dirent(name) dirent = image.find_dirent(name)
except errors.FileNotFound: except FileNotFound:
print("%s not in %s" % (name, image)) print("%s not in %s" % (name, image))
continue continue
output = dirent.filename output = dirent.filename
if options.lower: if options.lower:
output = output.lower() output = output.lower()
if options.dir:
if not os.path.exists(options.dir):
os.makedirs(options.dir)
output = os.path.join(options.dir, output)
if not options.dry_run: if not options.dry_run:
data = image.get_file(dirent) data = image.get_file(dirent)
if os.path.exists(output) and not options.force: if os.path.exists(output) and not options.force:
print("skipping %s, file exists. Use -f to overwrite" % output) print("skipping %s, file exists. Use -f to overwrite" % output)
continue continue
print("extracting %s -> %s" % (name, output)) print("extracting %s -> %s" % (name, output))
if options.text:
data = data.replace(b'\x7f', b'\t')
data = data.replace(b'\x9b', b'\n')
with open(output, "wb") as fh: with open(output, "wb") as fh:
fh.write(data) fh.write(data)
else: else:
@ -136,7 +118,7 @@ def save_file(image, name, filetype, data):
else: else:
print("skipping %s, use -f to overwrite" % (name)) print("skipping %s, use -f to overwrite" % (name))
return False return False
except errors.FileNotFound: except FileNotFound:
pass pass
print("copying %s to %s" % (name, image.filename)) print("copying %s to %s" % (name, image.filename))
if not options.dry_run: if not options.dry_run:
@ -153,7 +135,6 @@ def add_files(image, files):
for name in files: for name in files:
with open(name, "rb") as fh: with open(name, "rb") as fh:
data = fh.read() data = fh.read()
name = os.path.basename(name)
changed = save_file(image, name, filetype, data) changed = save_file(image, name, filetype, data)
if changed: if changed:
image.save() image.save()
@ -164,7 +145,7 @@ def remove_files(image, files):
for name in files: for name in files:
try: try:
dirent = image.find_dirent(name) dirent = image.find_dirent(name)
except errors.FileNotFound: except FileNotFound:
print("%s not in %s" % (name, image)) print("%s not in %s" % (name, image))
continue continue
print("removing %s from %s" % (name, image)) print("removing %s from %s" % (name, image))
@ -204,14 +185,14 @@ def assemble_segments(source_files, data_files, obj_files, run_addr=""):
try: try:
import pyatasm import pyatasm
except ImportError: except ImportError:
raise errors.AtrError("Please install pyatasm to compile code.") raise AtrError("Please install pyatasm to compile code.")
changed = False changed = False
segments = SegmentList() segments = SegmentList()
for name in source_files: for name in source_files:
try: try:
asm = pyatasm.Assemble(name) asm = pyatasm.Assemble(name)
except SyntaxError as e: except SyntaxError as e:
raise errors.AtrError("Assembly error: %s" % e.msg) raise AtrError("Assembly error: %s" % e.msg)
log.debug("Assembled %s into:" % name) log.debug("Assembled %s into:" % name)
for first, last, object_code in asm.segments: for first, last, object_code in asm.segments:
s = segments.add_segment(object_code, first) s = segments.add_segment(object_code, first)
@ -219,7 +200,7 @@ def assemble_segments(source_files, data_files, obj_files, run_addr=""):
print("adding %s from %s assembly" % (s, name)) print("adding %s from %s assembly" % (s, name))
for name in data_files: for name in data_files:
if "@" not in name: if "@" not in name:
raise errors.AtrError("Data files must include a load address specified with the @ char") raise AtrError("Data files must include a load address specified with the @ char")
name, addr = name.rsplit("@", 1) name, addr = name.rsplit("@", 1)
first = text_to_int(addr) first = text_to_int(addr)
log.debug("Adding data file %s at $%04x" % (name, first)) log.debug("Adding data file %s at $%04x" % (name, first))
@ -244,19 +225,11 @@ def assemble_segments(source_files, data_files, obj_files, run_addr=""):
s = segments.add_segment(data, first) s = segments.add_segment(data, first)
log.debug("read data for %s" % s.name) log.debug("read data for %s" % s.name)
for name in obj_files: for name in obj_files:
try: parser = find_diskimage(name)
parser, _ = find_diskimage(name, options.verbose) if parser and parser.image:
except errors.AtrError as e:
print(f"skipping {name}: {e}")
else:
for s in parser.segments: for s in parser.segments:
if hasattr(s, 'run_address'): if s.origin > 0:
if not run_addr: print("adding %s from %s" % (s, name))
run_addr = s.run_address()
else:
print(f"already have run address {run_addr}; skipping {s.run_address()}")
elif s.origin > 0:
print(f"adding {s} from {name}")
segments.add_segment(s.data, s.origin) segments.add_segment(s.data, s.origin)
if options.verbose: if options.verbose:
for s in segments: for s in segments:
@ -264,18 +237,14 @@ def assemble_segments(source_files, data_files, obj_files, run_addr=""):
if run_addr: if run_addr:
try: try:
run_addr = text_to_int(run_addr) run_addr = text_to_int(run_addr)
except (AttributeError, ValueError): except ValueError:
# not text, try as integer run_addr = None
try:
run_addr = int(run_addr)
except ValueError:
run_addr = None
return segments, run_addr return segments, run_addr
def assemble(image, source_files, data_files, obj_files, run_addr=""): def assemble(image, source_files, data_files, obj_files, run_addr=""):
segments, run_addr = assemble_segments(source_files, data_files, obj_files, run_addr) segments, run_addr = assemble_segments(source_files, data_files, obj_files, run_addr)
file_data, filetype = image.create_executable_file_image(options.output, segments, run_addr) file_data, filetype = image.create_executable_file_image(segments, run_addr)
print("total file size: $%x (%d) bytes" % (len(file_data), len(file_data))) print("total file size: $%x (%d) bytes" % (len(file_data), len(file_data)))
changed = save_file(image, options.output, filetype, file_data) changed = save_file(image, options.output, filetype, file_data)
if changed: if changed:
@ -285,7 +254,7 @@ def assemble(image, source_files, data_files, obj_files, run_addr=""):
def boot_image(image_name, source_files, data_files, obj_files, run_addr=""): def boot_image(image_name, source_files, data_files, obj_files, run_addr=""):
try: try:
image_cls = parsers_for_filename(image_name)[0] image_cls = parsers_for_filename(image_name)[0]
except errors.InvalidDiskImage as e: except InvalidDiskImage as e:
print("%s: %s" % (image_name, e)) print("%s: %s" % (image_name, e))
return None return None
segments, run_addr = assemble_segments(source_files, data_files, obj_files, run_addr) segments, run_addr = assemble_segments(source_files, data_files, obj_files, run_addr)
@ -370,16 +339,16 @@ def get_template_info():
def get_template_data(template): def get_template_data(template):
possibilities = get_template_images(template) possibilities = get_template_images(template)
if not possibilities: if not possibilities:
raise errors.InvalidDiskImage("Unknown template disk image %s" % template) raise InvalidDiskImage("Unknown template disk image %s" % template)
if len(possibilities) > 1: if len(possibilities) > 1:
raise errors.InvalidDiskImage("Name %s is ambiguous (%d matches: %s)" % (template, len(possibilities), ", ".join(sorted(possibilities.keys())))) raise InvalidDiskImage("Name %s is ambiguous (%d matches: %s)" % (template, len(possibilities), ", ".join(sorted(possibilities.keys()))))
name, inf = possibilities.popitem() name, inf = possibilities.popitem()
path = inf['path'] path = inf['path']
try: try:
with open(path, "rb") as fh: with open(path, "rb") as fh:
data = fh.read() data = fh.read()
except IOError: except IOError:
raise errors.InvalidDiskImage("Failed reading template file %s" % path) raise InvalidDiskImage("Failed reading template file %s" % path)
return data, inf return data, inf
@ -388,7 +357,7 @@ def create_image(template, name):
try: try:
data, inf = get_template_data(template) data, inf = get_template_data(template)
except errors.InvalidDiskImage as e: except InvalidDiskImage as e:
info = get_template_info() info = get_template_info()
print("Error: %s\n\n%s" % (e, info)) print("Error: %s\n\n%s" % (e, info))
return return
@ -399,7 +368,7 @@ def create_image(template, name):
else: else:
with open(name, "wb") as fh: with open(name, "wb") as fh:
fh.write(data) fh.write(data)
parser, _ = find_diskimage(name, options.verbose) parser = find_diskimage(name)
print("created %s: %s" % (name, str(parser.image))) print("created %s: %s" % (name, str(parser.image)))
list_files(parser.image, []) list_files(parser.image, [])
else: else:
@ -488,8 +457,6 @@ def run():
extract_parser.add_argument("-l", "--lower", action="store_true", default=False, help="convert extracted filenames to lower case") extract_parser.add_argument("-l", "--lower", action="store_true", default=False, help="convert extracted filenames to lower case")
#extract_parser.add_argument("-n", "--no-sys", action="store_true", default=False, help="only extract things that look like games (no DOS or .SYS files)") #extract_parser.add_argument("-n", "--no-sys", action="store_true", default=False, help="only extract things that look like games (no DOS or .SYS files)")
extract_parser.add_argument("-e", "--ext", action="store", nargs=1, default=False, help="add the specified extension") extract_parser.add_argument("-e", "--ext", action="store", nargs=1, default=False, help="add the specified extension")
extract_parser.add_argument("-d", "--dir", action="store", default=False, help="extract to the specified directory")
extract_parser.add_argument("-t", "--text", action="store_true", default=False, help="convert text files to unix-style text files")
extract_parser.add_argument("-f", "--force", action="store_true", default=False, help="allow file overwrites on local filesystem") extract_parser.add_argument("-f", "--force", action="store_true", default=False, help="allow file overwrites on local filesystem")
extract_parser.add_argument("files", metavar="FILENAME", nargs="*", help="if not using the -a/--all option, a file (or list of files) to extract from the disk image.") extract_parser.add_argument("files", metavar="FILENAME", nargs="*", help="if not using the -a/--all option, a file (or list of files) to extract from the disk image.")
@ -606,13 +573,10 @@ def run():
obj = options.obj[0] if options.obj else [] obj = options.obj[0] if options.obj else []
boot_image(disk_image_name, asm, data, obj, options.run_addr) boot_image(disk_image_name, asm, data, obj, options.run_addr)
else: else:
try: parser = find_diskimage(disk_image_name)
parser, mime = find_diskimage(disk_image_name, options.verbose) if parser and parser.image:
except (errors.UnsupportedContainer, errors.UnsupportedDiskImage, IOError) as e:
print(f"{disk_image_name}: {e}")
else:
if command not in skip_diskimage_summary: if command not in skip_diskimage_summary:
print(f"{disk_image_name}: {parser.image}{' (%s}' % mime if mime and options.verbose else ''}") print("%s: %s" % (disk_image_name, parser.image))
if command == "vtoc": if command == "vtoc":
vtoc = parser.image.get_vtoc_object() vtoc = parser.image.get_vtoc_object()
print(vtoc) print(vtoc)
@ -635,3 +599,5 @@ def run():
assemble(parser.image, asm, data, obj, options.run_addr) assemble(parser.image, asm, data, obj, options.run_addr)
elif command == "segments": elif command == "segments":
print("\n".join([str(a) for a in parser.segments])) print("\n".join([str(a) for a in parser.segments]))
else:
log.error("Invalid disk image: %s" % disk_image_name)

View File

@ -1,3 +1,4 @@
__version__ = "7.1"
__author__ = "Rob McMullen" __author__ = "Rob McMullen"
__author_email__ = "feedback@playermissile.com" __author_email__ = "feedback@playermissile.com"
__url__ = "https://github.com/robmcmullen/atrcopy" __url__ = "https://github.com/robmcmullen/atrcopy"

View File

@ -1 +0,0 @@
__version__ = "10.1"

View File

@ -1,10 +1,9 @@
import numpy as np import numpy as np
from . import errors from .errors import *
from .diskimages import DiskImageBase, BaseHeader, Bootable from .diskimages import DiskImageBase, BaseHeader
from .segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment, DefaultSegment, SegmentedFileSegment, SegmentSaver, get_style_bits from .segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment, DefaultSegment, SegmentedFileSegment, SegmentSaver, get_style_bits
from .utils import * from .utils import *
from .executables import get_xex
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -98,7 +97,8 @@ class AtariDosDirent(Dirent):
self.parse_raw_dirent(image, bytes) self.parse_raw_dirent(image, bytes)
def __str__(self): def __str__(self):
return "File #%-2d (%s) %03d %-8s%-3s %03d" % (self.file_num, self.summary, self.starting_sector, self.basename.decode("latin1"), self.ext.decode("latin1"), self.num_sectors) # return (b'File #%-2d (%s) %03d %-8s%-3s %03d' % (self.file_num, self.summary.encode("utf-8"), self.starting_sector, self.basename, self.ext, self.num_sectors)).decode("utf-8")
return "File #%-2d (%s) %03d %-8s%-3s %03d" % (self.file_num, self.summary, self.starting_sector, self.basename.decode("utf-8"), self.ext.decode("utf-8"), self.num_sectors)
def __eq__(self, other): def __eq__(self, other):
return self.__class__ == other.__class__ and self.filename == other.filename and self.starting_sector == other.starting_sector and self.num_sectors == other.num_sectors return self.__class__ == other.__class__ and self.filename == other.filename and self.starting_sector == other.starting_sector and self.num_sectors == other.num_sectors
@ -106,7 +106,7 @@ class AtariDosDirent(Dirent):
@property @property
def filename(self): def filename(self):
ext = (b'.' + self.ext) if self.ext else b'' ext = (b'.' + self.ext) if self.ext else b''
return (self.basename + ext).decode('latin1') return (self.basename + ext).decode('utf-8')
@property @property
def summary(self): def summary(self):
@ -198,7 +198,7 @@ class AtariDosDirent(Dirent):
def start_read(self, image): def start_read(self, image):
if not self.is_sane: if not self.is_sane:
raise errors.InvalidDirent("Invalid directory entry '%s'" % str(self)) raise InvalidDirent("Invalid directory entry '%s'" % str(self))
self.current_sector = self.starting_sector self.current_sector = self.starting_sector
self.current_read = self.num_sectors self.current_read = self.num_sectors
self.sectors_seen = set() self.sectors_seen = set()
@ -211,18 +211,18 @@ class AtariDosDirent(Dirent):
def process_raw_sector(self, image, raw): def process_raw_sector(self, image, raw):
file_num = raw[-3] >> 2 file_num = raw[-3] >> 2
if file_num != self.file_num: if file_num != self.file_num:
raise errors.FileNumberMismatchError164("Expecting file %d, found %d" % (self.file_num, file_num)) raise FileNumberMismatchError164("Expecting file %d, found %d" % (self.file_num, file_num))
self.sectors_seen.add(self.current_sector) self.sectors_seen.add(self.current_sector)
next_sector = ((raw[-3] & 0x3) << 8) + raw[-2] next_sector = ((raw[-3] & 0x3) << 8) + raw[-2]
if next_sector in self.sectors_seen: if next_sector in self.sectors_seen:
raise errors.InvalidFile("Bad sector pointer data: attempting to reread sector %d" % next_sector) raise InvalidFile("Bad sector pointer data: attempting to reread sector %d" % next_sector)
self.current_sector = next_sector self.current_sector = next_sector
num_bytes = raw[-1] num_bytes = raw[-1]
return raw[0:num_bytes], num_bytes return raw[0:num_bytes], num_bytes
def set_values(self, filename, filetype, index): def set_values(self, filename, filetype, index):
if type(filename) is not bytes: if type(filename) is not bytes:
filename = filename.encode("latin1") filename = filename.encode("utf-8")
if b'.' in filename: if b'.' in filename:
filename, ext = filename.split(b'.', 1) filename, ext = filename.split(b'.', 1)
else: else:
@ -257,17 +257,7 @@ class XexSegment(ObjSegment):
savers = [SegmentSaver, XexSegmentSaver] savers = [SegmentSaver, XexSegmentSaver]
class RunAddressSegment(ObjSegment): class AtariDosFile(object):
# FIXME: defining run_address as a property doesn't work for some reason.
# @property
# def run_address(self):
# return self.rawdata[0:2].view(dtype="<u2")[0]
def run_address(self):
return self.rawdata[0:2].data.view(dtype="<u2")[0]
class AtariDosFile(Bootable):
"""Parse a binary chunk into segments according to the Atari DOS object """Parse a binary chunk into segments according to the Atari DOS object
file format. file format.
@ -310,7 +300,7 @@ class AtariDosFile(Bootable):
first = False first = False
continue continue
elif first: elif first:
raise errors.InvalidBinaryFile("Object file doesn't start with 0xffff") raise InvalidBinaryFile("Object file doesn't start with 0xffff")
if _xd: log.debug("header parsing: header=0x%x" % header) if _xd: log.debug("header parsing: header=0x%x" % header)
if len(b[pos:pos + 4]) < 4: if len(b[pos:pos + 4]) < 4:
self.segments.append(ObjSegment(r[pos:pos + 4], 0, 0, 0, len(b[pos:pos + 4]), "Short Segment Header")) self.segments.append(ObjSegment(r[pos:pos + 4], 0, 0, 0, len(b[pos:pos + 4]), "Short Segment Header"))
@ -318,17 +308,13 @@ class AtariDosFile(Bootable):
start, end = b[pos:pos + 4].view(dtype='<u2') start, end = b[pos:pos + 4].view(dtype='<u2')
s[style_pos:pos + 4] = get_style_bits(data=True) s[style_pos:pos + 4] = get_style_bits(data=True)
if end < start: if end < start:
raise errors.InvalidBinaryFile("Nonsensical start and end addresses") raise InvalidBinaryFile("Nonsensical start and end addresses")
count = end - start + 1 count = end - start + 1
found = len(b[pos + 4:pos + 4 + count]) found = len(b[pos + 4:pos + 4 + count])
if found < count: if found < count:
self.segments.append(ObjSegment(r[pos + 4:pos + 4 + count], pos, pos + 4, start, end, "Incomplete Data")) self.segments.append(ObjSegment(r[pos + 4:pos + 4 + count], pos, pos + 4, start, end, "Incomplete Data"))
break break
if start == 0x2e0: self.segments.append(ObjSegment(r[pos + 4:pos + 4 + count], pos, pos + 4, start, end))
segment_cls = RunAddressSegment
else:
segment_cls = ObjSegment
self.segments.append(segment_cls(r[pos + 4:pos + 4 + count], pos, pos + 4, start, end))
pos += 4 + count pos += 4 + count
style_pos = pos style_pos = pos
@ -359,7 +345,7 @@ class AtrHeader(BaseHeader):
if len(bytes) == 16: if len(bytes) == 16:
values = bytes.view(dtype=self.format)[0] values = bytes.view(dtype=self.format)[0]
if values[0] != 0x296: if values[0] != 0x296:
raise errors.InvalidAtrHeader("no ATR header magic value") raise InvalidAtrHeader("no ATR header magic value")
self.image_size = (int(values[3]) * 256 * 256 + int(values[1])) * 16 self.image_size = (int(values[3]) * 256 * 256 + int(values[1])) * 16
self.sector_size = int(values[2]) self.sector_size = int(values[2])
self.crc = int(values[4]) self.crc = int(values[4])
@ -367,7 +353,7 @@ class AtrHeader(BaseHeader):
self.flags = int(values[6]) self.flags = int(values[6])
self.header_offset = 16 self.header_offset = 16
else: else:
raise errors.InvalidAtrHeader("incorrect AHC header size of %d" % len(bytes)) raise InvalidAtrHeader("incorrect AHC header size of %d" % len(bytes))
def __str__(self): def __str__(self):
return "%s Disk Image (size=%d (%dx%dB), crc=%d flags=%d unused=%d)" % (self.file_format, self.image_size, self.max_sectors, self.sector_size, self.crc, self.flags, self.unused) return "%s Disk Image (size=%d (%dx%dB), crc=%d flags=%d unused=%d)" % (self.file_format, self.image_size, self.max_sectors, self.sector_size, self.crc, self.flags, self.unused)
@ -415,7 +401,7 @@ class AtrHeader(BaseHeader):
def get_pos(self, sector): def get_pos(self, sector):
if not self.sector_is_valid(sector): if not self.sector_is_valid(sector):
raise errors.ByteNotInFile166("Sector %d out of range" % sector) raise ByteNotInFile166("Sector %d out of range" % sector)
if sector <= self.num_initial_sectors: if sector <= self.num_initial_sectors:
pos = self.num_initial_sectors * (sector - 1) pos = self.num_initial_sectors * (sector - 1)
size = self.initial_sector_size size = self.initial_sector_size
@ -429,7 +415,7 @@ class AtrHeader(BaseHeader):
size = len(image) size = len(image)
if self.header_offset == 16 or size in [92176, 133136, 184336, 183952]: if self.header_offset == 16 or size in [92176, 133136, 184336, 183952]:
return return
raise errors.InvalidDiskImage("Uncommon size of ATR file") raise InvalidDiskImage("Uncommon size of ATR file")
class XfdHeader(AtrHeader): class XfdHeader(AtrHeader):
@ -449,12 +435,10 @@ class XfdHeader(AtrHeader):
size = len(image) size = len(image)
if size in [92160, 133120, 183936, 184320]: if size in [92160, 133120, 183936, 184320]:
return return
raise errors.InvalidDiskImage("Uncommon size of XFD file") raise InvalidDiskImage("Uncommon size of XFD file")
class AtariDosDiskImage(DiskImageBase): class AtariDosDiskImage(DiskImageBase):
default_executable_extension = "XEX"
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.first_vtoc = 360 self.first_vtoc = 360
self.num_vtoc = 1 self.num_vtoc = 1
@ -506,7 +490,7 @@ class AtariDosDiskImage(DiskImageBase):
bytes = self.bytes[0:16] bytes = self.bytes[0:16]
try: try:
self.header = AtrHeader(bytes) self.header = AtrHeader(bytes)
except errors.InvalidAtrHeader: except InvalidAtrHeader:
self.header = XfdHeader() self.header = XfdHeader()
def calc_vtoc_code(self): def calc_vtoc_code(self):
@ -538,7 +522,7 @@ class AtariDosDiskImage(DiskImageBase):
self.assert_valid_sector(self.first_vtoc) self.assert_valid_sector(self.first_vtoc)
self.num_vtoc = num self.num_vtoc = num
if num < 0 or num > self.calc_vtoc_code(): if num < 0 or num > self.calc_vtoc_code():
raise errors.InvalidDiskImage("Invalid number of VTOC sectors: %d" % num) raise InvalidDiskImage("Invalid number of VTOC sectors: %d" % num)
self.total_sectors = values[1] self.total_sectors = values[1]
self.unused_sectors = values[2] self.unused_sectors = values[2]
@ -674,10 +658,14 @@ class AtariDosDiskImage(DiskImageBase):
try: try:
binary = AtariDosFile(segment.rawdata) binary = AtariDosFile(segment.rawdata)
segments_out.extend(binary.segments) segments_out.extend(binary.segments)
except errors.InvalidBinaryFile: except InvalidBinaryFile:
log.debug("%s not a binary file; skipping segment generation" % str(segment)) log.debug("%s not a binary file; skipping segment generation" % str(segment))
return segments_out return segments_out
def create_executable_file_image(self, segments, run_addr=None):
base_segment, user_segments = get_xex(segments, run_addr)
return base_segment.data, "XEX"
class BootDiskImage(AtariDosDiskImage): class BootDiskImage(AtariDosDiskImage):
def __str__(self): def __str__(self):
@ -691,7 +679,7 @@ class BootDiskImage(AtariDosDiskImage):
i = self.header.header_offset i = self.header.header_offset
flag = b[i:i + 2].view(dtype='<u2')[0] flag = b[i:i + 2].view(dtype='<u2')[0]
if flag == 0xffff: if flag == 0xffff:
raise errors.InvalidDiskImage("Appears to be an executable") raise InvalidDiskImage("Appears to be an executable")
nsec = b[i + 1] nsec = b[i + 1]
bload = b[i + 2:i + 4].view(dtype='<u2')[0] bload = b[i + 2:i + 4].view(dtype='<u2')[0]
@ -702,9 +690,9 @@ class BootDiskImage(AtariDosDiskImage):
max_size = max_ram - bload max_size = max_ram - bload
max_sectors = max_size // self.header.sector_size max_sectors = max_size // self.header.sector_size
if nsec > max_sectors or nsec < 1: if nsec > max_sectors or nsec < 1:
raise errors.InvalidDiskImage("Number of boot sectors out of range (tried %d, max=%d" % (nsec, max_sectors)) raise InvalidDiskImage("Number of boot sectors out of range (tried %d, max=%d" % (nsec, max_sectors))
if bload > (0xc000 - (nsec * self.header.sector_size)): if bload > (0xc000 - (nsec * self.header.sector_size)):
raise errors.InvalidDiskImage("Bad boot load address") raise InvalidDiskImage("Bad boot load address")
def get_boot_sector_info(self): def get_boot_sector_info(self):
pass pass
@ -751,12 +739,62 @@ class AtariDiskImage(BootDiskImage):
def check_size(self): def check_size(self):
if self.header is None: if self.header is None:
raise errors.InvalidDiskImage("Not a known Atari disk image format") raise ("Not a known Atari disk image format")
def get_boot_segments(self): def get_boot_segments(self):
return [] return []
def get_xex(segments, run_addr=None):
segments_copy = [s for s in segments] # don't affect the original list!
main_segment = None
sub_segments = []
data_style = get_style_bits(data=True)
total = 2
runad = False
for s in segments:
total += 4 + len(s)
if s.origin == 0x2e0:
runad = True
if not runad:
words = np.empty([1], dtype='<u2')
if run_addr:
found = False
for s in segments:
if run_addr >= s.origin and run_addr < s.origin + len(s):
found = True
break
if not found:
raise InvalidBinaryFile("Run address points outside data segments")
else:
run_addr = segments[0].origin
words[0] = run_addr
r = SegmentData(words.view(dtype=np.uint8))
s = DefaultSegment(r, 0x2e0)
segments_copy[0:0] = [s]
total += 6
bytes = np.zeros([total], dtype=np.uint8)
rawdata = SegmentData(bytes)
main_segment = DefaultSegment(rawdata)
main_segment.data[0:2] = 0xff # FFFF header
main_segment.style[0:2] = data_style
i = 2
for s in segments_copy:
# create new sub-segment inside new main segment that duplicates the
# original segment's data/style
new_s = DefaultSegment(rawdata[i:i+4+len(s)], s.origin)
words = new_s.data[0:4].view(dtype='<u2')
words[0] = s.origin
words[1] = s.origin + len(s) - 1
new_s.style[0:4] = data_style
new_s.data[4:4+len(s)] = s[:]
new_s.style[4:4+len(s)] = s.style[:]
i += 4 + len(s)
new_s.copy_user_data(s, 4)
sub_segments.append(new_s)
return main_segment, sub_segments
def add_atr_header(bytes): def add_atr_header(bytes):
header = AtrHeader(create=True) header = AtrHeader(create=True)
header.check_size(len(bytes)) header.check_size(len(bytes))

View File

@ -2,7 +2,7 @@ from collections import defaultdict
import numpy as np import numpy as np
from . import errors from .errors import *
from .segments import SegmentData, EmptySegment, ObjSegment from .segments import SegmentData, EmptySegment, ObjSegment
from .diskimages import DiskImageBase from .diskimages import DiskImageBase
from .utils import to_numpy from .utils import to_numpy
@ -108,10 +108,10 @@ def get_cart(cart_type):
try: try:
return known_cart_types[known_cart_type_map[cart_type]] return known_cart_types[known_cart_type_map[cart_type]]
except KeyError: except KeyError:
raise errors.InvalidDiskImage("Unsupported cart type %d" % cart_type) raise InvalidDiskImage("Unsupported cart type %d" % cart_type)
class A8CartHeader: class A8CartHeader(object):
# Atari Cart format described by https://sourceforge.net/p/atari800/source/ci/master/tree/DOC/cart.txt NOTE: Big endian! # Atari Cart format described by https://sourceforge.net/p/atari800/source/ci/master/tree/DOC/cart.txt NOTE: Big endian!
format = np.dtype([ format = np.dtype([
('magic', '|S4'), ('magic', '|S4'),
@ -119,7 +119,6 @@ class A8CartHeader:
('checksum', '>u4'), ('checksum', '>u4'),
('unused','>u4') ('unused','>u4')
]) ])
nominal_length = format.itemsize
file_format = "Cart" file_format = "Cart"
def __init__(self, bytes=None, create=False): def __init__(self, bytes=None, create=False):
@ -139,7 +138,7 @@ class A8CartHeader:
self.main_origin = 0 self.main_origin = 0
self.possible_types = set() self.possible_types = set()
if create: if create:
self.header_offset = self.nominal_length self.header_offset = 16
self.check_size(0) self.check_size(0)
if bytes is None: if bytes is None:
return return
@ -147,13 +146,13 @@ class A8CartHeader:
if len(bytes) == 16: if len(bytes) == 16:
values = bytes.view(dtype=self.format)[0] values = bytes.view(dtype=self.format)[0]
if values[0] != b'CART': if values[0] != b'CART':
raise errors.InvalidCartHeader raise InvalidCartHeader
self.cart_type = int(values[1]) self.cart_type = int(values[1])
self.crc = int(values[2]) self.crc = int(values[2])
self.header_offset = self.nominal_length self.header_offset = 16
self.set_type(self.cart_type) self.set_type(self.cart_type)
else: else:
raise errors.InvalidCartHeader raise InvalidCartHeader
def __str__(self): def __str__(self):
return "%s Cartridge (atari800 type=%d size=%d, %d banks, crc=%d)" % (self.cart_name, self.cart_type, self.cart_size, self.bank_size, self.crc) return "%s Cartridge (atari800 type=%d size=%d, %d banks, crc=%d)" % (self.cart_name, self.cart_type, self.cart_size, self.bank_size, self.crc)
@ -161,15 +160,8 @@ class A8CartHeader:
def __len__(self): def __len__(self):
return self.header_offset return self.header_offset
@property
def valid(self):
return self.cart_type != -1
def calc_crc_from_data(self, data):
self.crc = 0
def to_array(self): def to_array(self):
raw = np.zeros([self.nominal_length], dtype=np.uint8) raw = np.zeros([16], dtype=np.uint8)
values = raw.view(dtype=self.format)[0] values = raw.view(dtype=self.format)[0]
values[0] = b'CART' values[0] = b'CART'
values[1] = self.cart_type values[1] = self.cart_type
@ -197,14 +189,18 @@ class A8CartHeader:
def check_size(self, size): def check_size(self, size):
self.possible_types = set() self.possible_types = set()
k, r = divmod(size, 1024) k, r = divmod(size, 1024)
if r == 0 or r == self.nominal_length: if r == 0 or r == 16:
for i, t in enumerate(known_cart_types): for i, t in enumerate(known_cart_types):
valid_size = t[0] valid_size = t[0]
if k == valid_size: if k == valid_size:
self.possible_types.add(i) self.possible_types.add(i)
class BaseAtariCartImage(DiskImageBase): class AtariCartImage(DiskImageBase):
def __init__(self, rawdata, cart_type, filename=""):
self.cart_type = cart_type
DiskImageBase.__init__(self, rawdata, filename)
def __str__(self): def __str__(self):
return str(self.header) return str(self.header)
@ -212,29 +208,30 @@ class BaseAtariCartImage(DiskImageBase):
data = self.bytes[0:16] data = self.bytes[0:16]
try: try:
self.header = A8CartHeader(data) self.header = A8CartHeader(data)
except errors.InvalidCartHeader: except InvalidCartHeader:
self.header = A8CartHeader() self.header = A8CartHeader()
self.header.set_type(self.cart_type)
def strict_check(self): def strict_check(self):
raise NotImplementedError if self.header.cart_type != self.cart_type:
raise InvalidDiskImage("Cart type doesn't match type defined in header")
def relaxed_check(self): def relaxed_check(self):
if self.header.cart_type != self.cart_type: if self.header.cart_type != self.cart_type:
# force the header to be the specified cart type # force the header to be the specified cart type
self.header = A8CartHeader() self.header = A8CartHeader()
self.header.set_type(self.cart_type) self.header.set_type(self.cart_type)
self.check_size()
def check_size(self): def check_size(self):
if not self.header.valid: if self.header is None:
return return
k, rem = divmod((len(self) - len(self.header)), 1024) k, rem = divmod((len(self) - len(self.header)), 1024)
c = get_cart(self.header.cart_type) c = get_cart(self.cart_type)
log.debug("checking type=%d, k=%d, rem=%d for %s, %s" % (self.cart_type, k, rem, c[1], c[2])) log.debug("checking type=%d, k=%d, rem=%d for %s, %s" % (self.cart_type, k, rem, c[1], c[2]))
if rem > 0: if rem > 0:
raise errors.InvalidDiskImage("Cart not multiple of 1K") raise InvalidDiskImage("Cart not multiple of 1K")
if k != c[2]: if k != c[2]:
raise errors.InvalidDiskImage("Image size %d doesn't match cart type %d size %d" % (k, self.cart_type, c[2])) raise InvalidDiskImage("Image size %d doesn't match cart type %d size %d" % (k, self.cart_type, c[2]))
def parse_segments(self): def parse_segments(self):
r = self.rawdata r = self.rawdata
@ -261,47 +258,6 @@ class BaseAtariCartImage(DiskImageBase):
segments.append(s) segments.append(s)
return segments return segments
def create_emulator_boot_segment(self):
h = self.header
k, rem = divmod(len(self), 1024)
if rem == 0:
h.calc_crc_from_data(self.bytes)
data_with_header = np.empty(len(self) + h.nominal_length, dtype=np.uint8)
data_with_header[0:h.nominal_length] = h.to_array()
data_with_header[h.nominal_length:] = self.bytes
r = SegmentData(data_with_header)
else:
r = self.rawdata
s = ObjSegment(r, 0, 0, self.header.main_origin, name="Cart image")
return s
class AtariCartImage(BaseAtariCartImage):
def __init__(self, rawdata, cart_type, filename=""):
c = get_cart(cart_type)
self.cart_type = cart_type
DiskImageBase.__init__(self, rawdata, filename)
def strict_check(self):
if not self.header.valid:
raise errors.InvalidDiskImage("Missing cart header")
if self.header.cart_type != self.cart_type:
raise errors.InvalidDiskImage("Cart type doesn't match type defined in header")
class Atari8bitCartImage(AtariCartImage):
def strict_check(self):
if "5200" in self.header.cart_name:
raise errors.InvalidDiskImage("5200 Carts don't work in the home computers.")
AtariCartImage.strict_check(self)
class Atari5200CartImage(AtariCartImage):
def strict_check(self):
if "5200" not in self.header.cart_name:
raise errors.InvalidDiskImage("Home computer carts don't work in the 5200.")
AtariCartImage.strict_check(self)
def add_cart_header(bytes): def add_cart_header(bytes):
header = A8CartHeader(create=True) header = A8CartHeader(create=True)
@ -311,45 +267,3 @@ def add_cart_header(bytes):
data[0:hlen] = header.to_array() data[0:hlen] = header.to_array()
data[hlen:] = bytes data[hlen:] = bytes
return data return data
class RomImage(DiskImageBase):
def __str__(self):
return f"{len(self.rawdata) // 1024}k ROM image"
def read_header(self):
self.header = A8CartHeader()
def strict_check(self):
self.check_size()
def check_size(self):
size = len(self)
if (size & (size - 1)) != 0:
raise errors.InvalidDiskImage("ROM image not a power of 2")
def parse_segments(self):
r = self.rawdata
s = ObjSegment(r, 0, 0, self.header.main_origin, name="Main Bank")
self.segments = [s]
def create_emulator_boot_segment(self):
s = self.segments[0]
if s.origin == 0:
return None
return s
class Atari2600CartImage(RomImage):
def __str__(self):
return f"{len(self.rawdata) // 1024}k Atari 2600 Cartridge"
class Atari2600StarpathImage(RomImage):
def __str__(self):
return f"{len(self.rawdata) // 1024}k Atari 2600 Starpath Cassette"
class VectrexCartImage(RomImage):
def __str__(self):
return f"{len(self.rawdata) // 1024}k Vectrex Cartridge"

View File

@ -1,82 +0,0 @@
import gzip
import bz2
import lzma
import io
import numpy as np
from . import errors
from .segments import SegmentData
from .utils import to_numpy
class DiskImageContainer:
"""Unpacker for disk image compression.
Disk images may be compressed by any number of techniques. Subclasses of
DiskImageContainer implement the `unpack_bytes` method which examines the
byte_data argument for the supported compression type, and if valid returns
the unpacked bytes to be used in the disk image parsing.
"""
def __init__(self, data):
self.unpacked = self.__unpack_raw_data(data)
def __unpack_raw_data(self, data):
raw = data.tobytes()
try:
unpacked = self.unpack_bytes(raw)
except EOFError as e:
raise errors.InvalidContainer(e)
return to_numpy(unpacked)
def unpack_bytes(self, byte_data):
"""Attempt to unpack `byte_data` using this unpacking algorithm.
`byte_data` is a byte string, and should return a byte string if
successfully unpacked. Conversion to a numpy array will take place
automatically, outside of this method.
If the data is not recognized by this subclass, raise an
InvalidContainer exception. This signals to the caller that a different
container type should be tried.
If the data is recognized by this subclass but the unpacking algorithm
is not implemented, raise an UnsupportedContainer exception. This is
different than the InvalidContainer exception because it indicates that
the data was indeed recognized by this subclass (despite not being
unpacked) and checking further containers is not necessary.
"""
pass
class GZipContainer(DiskImageContainer):
def unpack_bytes(self, byte_data):
try:
buf = io.BytesIO(byte_data)
with gzip.GzipFile(mode='rb', fileobj=buf) as f:
unpacked = f.read()
except OSError as e:
raise errors.InvalidContainer(e)
return unpacked
class BZipContainer(DiskImageContainer):
def unpack_bytes(self, byte_data):
try:
buf = io.BytesIO(byte_data)
with bz2.BZ2File(buf, mode='rb') as f:
unpacked = f.read()
except OSError as e:
raise errors.InvalidContainer(e)
return unpacked
class LZMAContainer(DiskImageContainer):
def unpack_bytes(self, byte_data):
try:
buf = io.BytesIO(byte_data)
with lzma.LZMAFile(buf, mode='rb') as f:
unpacked = f.read()
except lzma.LZMAError as e:
raise errors.InvalidContainer(e)
return unpacked

View File

@ -1,48 +0,0 @@
import numpy as np
from . import errors
from .container import DiskImageContainer
from .segments import SegmentData
class DCMContainer(DiskImageContainer):
valid_densities = {
0: (720, 128),
1: (720, 256),
2: (1040, 128),
}
def get_next(self):
try:
data = self.raw[self.index]
except IndexError:
raise errors.InvalidContainer("Incomplete DCM file")
else:
self.index += 1
return data
def unpack_bytes(self, data):
self.index = 0
self.count = len(data)
self.raw = data
archive_type = self.get_next()
if archive_type == 0xf9 or archive_type == 0xfa:
archive_flags = self.get_next()
if archive_flags & 0x1f != 1:
if archive_type == 0xf9:
raise errors.InvalidContainer("DCM multi-file archive combined in the wrong order")
else:
raise errors.InvalidContainer("Expected pass one of DCM archive first")
density_flag = (archive_flags >> 5) & 3
if density_flag not in self.valid_densities:
raise errors.InvalidContainer(f"Unsupported density flag {density_flag} in DCM")
else:
raise errors.InvalidContainer("Not a DCM file")
# DCM decoding goes here. Currently, instead of decoding it raises the
# UnsupportedContainer exception, which signals to the caller that the
# container has been successfully identified but can't be parsed.
#
# When decoding is supported, return the decoded byte array instead of
# this exception.
raise errors.UnsupportedContainer("DCM archives are not yet supported")

View File

@ -1,9 +1,8 @@
import numpy as np import numpy as np
from . import errors from .errors import *
from .segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment from .segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment
from .utils import * from .utils import *
from .executables import create_executable_file_data
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -13,7 +12,7 @@ except NameError:
_xd = False _xd = False
class BaseHeader: class BaseHeader(object):
file_format = "generic" # text descriptor of file format file_format = "generic" # text descriptor of file format
sector_class = WriteableSector sector_class = WriteableSector
@ -81,7 +80,7 @@ class BaseHeader:
return track, sector return track, sector
def check_size(self, size): def check_size(self, size):
raise errors.InvalidDiskImage("BaseHeader subclasses need custom checks for size") raise InvalidDiskImage("BaseHeader subclasses need custom checks for size")
def strict_check(self, image): def strict_check(self, image):
pass pass
@ -92,14 +91,7 @@ class BaseHeader:
return self.sector_class(self.sector_size, data) return self.sector_class(self.sector_size, data)
class Bootable: class DiskImageBase(object):
def create_emulator_boot_segment(self):
return ObjSegment(self.rawdata, 0, 0, 0)
class DiskImageBase(Bootable):
default_executable_extension = None
def __init__(self, rawdata, filename="", create=False): def __init__(self, rawdata, filename="", create=False):
self.rawdata = rawdata self.rawdata = rawdata
self.bytes = self.rawdata.get_data() self.bytes = self.rawdata.get_data()
@ -138,10 +130,11 @@ class DiskImageBase(Bootable):
return Directory return Directory
def set_filename(self, filename): def set_filename(self, filename):
if '.' in filename: if type(filename) is not bytes: filename = filename.encode("utf-8")
self.filename, self.ext = filename.rsplit('.', 1) if b'.' in filename:
self.filename, self.ext = filename.rsplit(b'.', 1)
else: else:
self.filename, self.ext = filename, '' self.filename, self.ext = filename, b''
def dir(self): def dir(self):
lines = [] lines = []
@ -176,31 +169,32 @@ class DiskImageBase(Bootable):
@classmethod @classmethod
def new_header(cls, diskimage, format="ATR"): def new_header(cls, diskimage, format="ATR"):
raise errors.NotImplementedError raise NotImplementedError
def as_new_format(self, format="ATR"): def as_new_format(self, format="ATR"):
""" Create a new disk image in the specified format """ Create a new disk image in the specified format
""" """
raise errors.NotImplementedError raise NotImplementedError
def save(self, filename=""): def save(self, filename=""):
if not filename: if not filename:
filename = self.filename filename = self.filename
if self.ext: if self.ext:
filename += '.' + self.ext filename += b'.' + self.ext
if not filename: if not filename:
raise RuntimeError("No filename specified for save!") raise RuntimeError("No filename specified for save!")
if type(filename) is not bytes: filename = filename.encode("utf-8")
data = self.bytes[:] data = self.bytes[:]
with open(filename, "wb") as fh: with open(filename, "wb") as fh:
data.tofile(fh) data.tofile(fh)
def assert_valid_sector(self, sector): def assert_valid_sector(self, sector):
if not self.header.sector_is_valid(sector): if not self.header.sector_is_valid(sector):
raise errors.ByteNotInFile166("Sector %d out of range" % sector) raise ByteNotInFile166("Sector %d out of range" % sector)
def check_sane(self): def check_sane(self):
if not self.all_sane: if not self.all_sane:
raise errors.InvalidDiskImage("Invalid directory entries; may be boot disk") raise InvalidDiskImage("Invalid directory entries; may be boot disk")
def read_header(self): def read_header(self):
return BaseHeader() return BaseHeader()
@ -285,7 +279,7 @@ class DiskImageBase(Bootable):
for dirent in self.files: for dirent in self.files:
if filename == dirent.filename: if filename == dirent.filename:
return dirent return dirent
raise errors.FileNotFound("%s not found on disk" % str(filename)) raise FileNotFound("%s not found on disk" % str(filename))
def find_file(self, filename): def find_file(self, filename):
dirent = self.find_dirent(filename) dirent = self.find_dirent(filename)
@ -303,21 +297,17 @@ class DiskImageBase(Bootable):
for dirent in self.files: for dirent in self.files:
try: try:
segment = self.get_file_segment(dirent) segment = self.get_file_segment(dirent)
except errors.InvalidFile as e: except InvalidFile as e:
segment = EmptySegment(self.rawdata, name=dirent.filename, error=str(e)) segment = EmptySegment(self.rawdata, name=dirent.filename, error=str(e))
segments.append(segment) segments.append(segment)
return segments return segments
def create_executable_file_image(self, output_name, segments, run_addr=None): def create_executable_file_image(self, segments, run_addr=None):
try: raise NotImplementedError
data, filetype = create_executable_file_data(output_name, segments, run_addr)
except errors.UnsupportedContainer:
data, filetype = create_executable_file_data(self.default_executable_extension, segments, run_addr)
return data, filetype
@classmethod @classmethod
def create_boot_image(self, segments, run_addr=None): def create_boot_image(self, segments, run_addr=None):
raise errors.NotImplementedError raise NotImplementedError
# file writing methods # file writing methods
@ -353,7 +343,7 @@ class DiskImageBase(Bootable):
self.write_sector_list(sector_list) self.write_sector_list(sector_list)
self.write_sector_list(vtoc) self.write_sector_list(vtoc)
self.write_sector_list(directory) self.write_sector_list(directory)
except errors.AtrError: except AtrError:
self.rollback_transaction(state) self.rollback_transaction(state)
raise raise
finally: finally:
@ -387,7 +377,7 @@ class DiskImageBase(Bootable):
directory.remove_dirent(self, dirent, vtoc, sector_list) directory.remove_dirent(self, dirent, vtoc, sector_list)
self.write_sector_list(vtoc) self.write_sector_list(vtoc)
self.write_sector_list(directory) self.write_sector_list(directory)
except errors.AtrError: except AtrError:
self.rollback_transaction(state) self.rollback_transaction(state)
raise raise
finally: finally:
@ -400,7 +390,7 @@ class DiskImageBase(Bootable):
for sector_num, pos, size in vtoc.iter_free_sectors(): for sector_num, pos, size in vtoc.iter_free_sectors():
if _xd: log.debug("shredding: sector %s at %d, fill value=%d" % (sector_num, pos, fill_value)) if _xd: log.debug("shredding: sector %s at %d, fill value=%d" % (sector_num, pos, fill_value))
self.bytes[pos:pos + size] = fill_value self.bytes[pos:pos + size] = fill_value
except errors.AtrError: except AtrError:
self.rollback_transaction(state) self.rollback_transaction(state)
raise raise
finally: finally:

View File

@ -1,10 +1,9 @@
import numpy as np import numpy as np
from . import errors from .errors import *
from .diskimages import BaseHeader, DiskImageBase, Bootable from .diskimages import BaseHeader, DiskImageBase
from .utils import Directory, VTOC, WriteableSector, BaseSectorList, Dirent from .utils import Directory, VTOC, WriteableSector, BaseSectorList, Dirent
from .segments import DefaultSegment, EmptySegment, ObjSegment, RawTrackSectorSegment, SegmentSaver, get_style_bits, SegmentData from .segments import DefaultSegment, EmptySegment, ObjSegment, RawTrackSectorSegment, SegmentSaver, get_style_bits, SegmentData
from .executables import get_bsave
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -251,7 +250,7 @@ class Dos33Dirent(Dirent):
values[1] = self.sector values[1] = self.sector
values[2] = self.flag values[2] = self.flag
n = min(len(self.filename), 30) n = min(len(self.filename), 30)
data[3:3+n] = np.frombuffer(self.filename.encode("ascii"), dtype=np.uint8) | 0x80 data[3:3+n] = np.fromstring(self.filename.encode("ascii"), dtype=np.uint8) | 0x80
data[3+n:] = ord(' ') | 0x80 data[3+n:] = ord(' ') | 0x80
if self.deleted: if self.deleted:
data[0x20] = self.track data[0x20] = self.track
@ -321,7 +320,7 @@ class Dos33Dirent(Dirent):
def start_read(self, image): def start_read(self, image):
if not self.is_sane: if not self.is_sane:
raise errors.InvalidDirent("Invalid directory entry '%s'" % str(self)) raise InvalidDirent("Invalid directory entry '%s'" % str(self))
self.get_track_sector_list(image) self.get_track_sector_list(image)
if _xd: log.debug("start_read: %s, t/s list: %s" % (str(self), str(self.sector_map))) if _xd: log.debug("start_read: %s, t/s list: %s" % (str(self), str(self.sector_map)))
self.current_sector_index = 0 self.current_sector_index = 0
@ -370,7 +369,7 @@ class Dos33Header(BaseHeader):
def check_size(self, size): def check_size(self, size):
if size != 143360: if size != 143360:
raise errors.InvalidDiskImage("Incorrect size for DOS 3.3 image") raise InvalidDiskImage("Incorrect size for DOS 3.3 image")
self.image_size = size self.image_size = size
self.first_vtoc = 17 * 16 self.first_vtoc = 17 * 16
self.num_vtoc = 1 self.num_vtoc = 1
@ -382,8 +381,6 @@ class Dos33Header(BaseHeader):
class Dos33DiskImage(DiskImageBase): class Dos33DiskImage(DiskImageBase):
default_executable_extension = "BSAVE"
def __init__(self, rawdata, filename=""): def __init__(self, rawdata, filename=""):
DiskImageBase.__init__(self, rawdata, filename) DiskImageBase.__init__(self, rawdata, filename)
self.default_filetype = "B" self.default_filetype = "B"
@ -411,7 +408,7 @@ class Dos33DiskImage(DiskImageBase):
data, style = self.get_sectors(0) data, style = self.get_sectors(0)
magic = data[0:4] magic = data[0:4]
if (magic == [1, 56, 176, 3]).all(): if (magic == [1, 56, 176, 3]).all():
raise errors.InvalidDiskImage("ProDOS format found; not DOS 3.3 image") raise InvalidDiskImage("ProDOS format found; not DOS 3.3 image")
swap_order = False swap_order = False
data, style = self.get_sectors(self.header.first_vtoc) data, style = self.get_sectors(self.header.first_vtoc)
if data[3] == 3: if data[3] == 3:
@ -421,7 +418,7 @@ class Dos33DiskImage(DiskImageBase):
log.warning("DOS 3.3 byte swap needed!") log.warning("DOS 3.3 byte swap needed!")
swap_order = True swap_order = True
else: else:
raise errors.InvalidDiskImage("Invalid VTOC location for DOS 3.3") raise InvalidDiskImage("Invalid VTOC location for DOS 3.3")
vtoc_type = np.dtype([ vtoc_type = np.dtype([
@ -447,9 +444,6 @@ class Dos33DiskImage(DiskImageBase):
values = data[0:self.vtoc_type.itemsize].view(dtype=self.vtoc_type)[0] values = data[0:self.vtoc_type.itemsize].view(dtype=self.vtoc_type)[0]
self.header.first_directory = self.header.sector_from_track(values['cat_track'], values['cat_sector']) self.header.first_directory = self.header.sector_from_track(values['cat_track'], values['cat_sector'])
self.header.sector_size = int(values['sector_size']) self.header.sector_size = int(values['sector_size'])
if self.header.sector_size != 256:
log.warning(f"Nonstandard sector size {self.header.sector_size}; this is likely an error, setting to 256")
self.header.sector_size = 256
self.header.max_sectors = int(values['num_tracks']) * int(values['sectors_per_track']) self.header.max_sectors = int(values['num_tracks']) * int(values['sectors_per_track'])
self.header.ts_pairs = int(values['max_pairs']) self.header.ts_pairs = int(values['max_pairs'])
self.header.dos_release = values['dos_release'] self.header.dos_release = values['dos_release']
@ -569,7 +563,7 @@ class Dos33DiskImage(DiskImageBase):
next_sector = self.header.sector_from_track(raw[1], raw[2]) next_sector = self.header.sector_from_track(raw[1], raw[2])
if _xd: log.debug("checking catalog sector %d, next catalog sector: %d" % (sector_num, next_sector)) if _xd: log.debug("checking catalog sector %d, next catalog sector: %d" % (sector_num, next_sector))
if next_sector == 0: if next_sector == 0:
raise errors.NoSpaceInDirectory("No space left in catalog") raise NoSpaceInDirectory("No space left in catalog")
return sector_num, next_sector return sector_num, next_sector
def get_file_segment(self, dirent): def get_file_segment(self, dirent):
@ -596,8 +590,46 @@ class Dos33DiskImage(DiskImageBase):
segment = EmptySegment(self.rawdata, name=dirent.filename) segment = EmptySegment(self.rawdata, name=dirent.filename)
return segment return segment
def create_executable_file_image(self, segments, run_addr=None):
# Apple 2 executables get executed at the first address loaded. If the
# run_addr is not the first byte of the combined data, have to create a
# new 3-byte segment with a "JMP run_addr" to go at the beginning
origin = 100000000
last = -1
class Dos33BinFile(Bootable): for s in segments:
origin = min(origin, s.origin)
last = max(last, s.origin + len(s))
if _xd: log.debug("contiguous bytes needed: %04x - %04x" % (origin, last))
if run_addr and run_addr != origin:
# check if run_addr points to some location that has data
found = False
for s in segments:
if run_addr >= s.origin and run_addr < s.origin + len(s):
found = True
break
if not found:
raise InvalidBinaryFile("Run address points outside data segments")
origin -= 3
hi, lo = divmod(run_addr, 256)
raw = SegmentData([0x4c, lo, hi])
all_segments = [DefaultSegment(raw, origin=origin)]
all_segments.extend(segments)
else:
all_segments = segments
size = last - origin
image = np.zeros([size + 4], dtype=np.uint8)
words = image[0:4].view(dtype="<u2") # always little endian
words[0] = origin
words[1] = size
for s in all_segments:
index = s.origin - origin + 4
print("setting data for $%04x - $%04x at index $%04x" % (s.origin, s.origin + len(s), index))
image[index:index + len(s)] = s.data
return image, 'B'
class Dos33BinFile(object):
"""Parse a binary chunk into segments according to the DOS 3.3 binary """Parse a binary chunk into segments according to the DOS 3.3 binary
dump format dump format
""" """
@ -627,21 +659,16 @@ class Dos33BinFile(Bootable):
if _xd: log.debug("Initial parsing: size=%d" % self.size) if _xd: log.debug("Initial parsing: size=%d" % self.size)
if len(b[pos:pos + 4]) == 4: if len(b[pos:pos + 4]) == 4:
start, count = b[pos:pos + 4].view(dtype='<u2') start, count = b[pos:pos + 4].view(dtype='<u2')
if count != self.size - 4:
raise errors.InvalidBinaryFile(f"Extra data after BSAVE segment: file size {self.size}, header specifies {count} bytes")
s[pos:pos + 4] = get_style_bits(data=True) s[pos:pos + 4] = get_style_bits(data=True)
data = b[pos + 4:pos + 4 + count] data = b[pos + 4:pos + 4 + count]
if len(data) == count: if len(data) == count:
name = "BSAVE data" % start name = "BSAVE data" % start
else: else:
raise errors.InvalidBinaryFile(f"Incomplete BSAVE data: expected {count}, loaded {len(data)}") name = "Incomplete data: expected %04x, loaded %04x" % (count, len(data))
self.segments.append(ObjSegment(r[pos + 4:pos + 4 + count], pos, pos + 4, start, start + len(data), name)) self.segments.append(ObjSegment(r[pos + 4:pos + 4 + count], pos, pos + 4, start, start + len(data), name))
else: else:
raise errors.InvalidBinaryFile(f"Invalid BSAVE header") self.segments.append(ObjSegment(r[pos:pos + 4], 0, 0, 0, len(b[pos:pos + 4]), "Short Segment Header"))
def create_emulator_boot_segment(self):
return self.segments[0]
class ProdosHeader(Dos33Header): class ProdosHeader(Dos33Header):
@ -681,7 +708,7 @@ class ProdosDiskImage(DiskImageBase):
# https://github.com/RasppleII/a2server but it seems that # https://github.com/RasppleII/a2server but it seems that
# more magic bytes might be acceptable? # more magic bytes might be acceptable?
#raise errors.InvalidDiskImage("No ProDOS header info found") #raise InvalidDiskImage("No ProDOS header info found")
pass pass
raise errors.UnsupportedDiskImage("ProDOS format found but not supported") raise UnsupportedDiskImage("ProDOS format found but not supported")
raise errors.InvalidDiskImage("Not ProDOS format") raise InvalidDiskImage("Not ProDOS format")

View File

@ -1,44 +0,0 @@
import os
import numpy as np
from . import errors
from .segments import SegmentData, EmptySegment, ObjSegment
from .diskimages import DiskImageBase
from .utils import to_numpy
import logging
log = logging.getLogger(__name__)
class LocalFilesystemImage(DiskImageBase):
def __init__(self, path):
self.path = path
def __str__(self, path="."):
return f"Local filesystem output to: {self.path}"
def save(self, filename=""):
# This is to save the disk image containing the files on the disk image
# to the local disk, which doesn't make sense when the disk image is
# the filesystem.
pass
def find_dirent(self, name):
path = os.path.join(self.path, name)
if os.path.exists(path):
return True
raise errors.FileNotFound("%s not found on disk" % str(name))
def write_file(self, name, filetype, data):
path = os.path.join(self.path, name)
with open(path, "wb") as fh:
fh.write(data)
def delete_file(self, name):
pass
class LocalFilesystem():
def __init__(self, path="."):
self.image = LocalFilesystemImage(path)

View File

@ -65,11 +65,3 @@ class NotEnoughSpaceOnDisk(AtrError):
class FileNotFound(AtrError): class FileNotFound(AtrError):
pass pass
class UnsupportedContainer(AtrError):
pass
class InvalidContainer(AtrError):
pass

View File

@ -1,112 +0,0 @@
import numpy as np
from . import errors
from .segments import SegmentData, EmptySegment, ObjSegment, RawSectorsSegment, DefaultSegment, SegmentedFileSegment, SegmentSaver, get_style_bits
from .utils import *
import logging
log = logging.getLogger(__name__)
try: # Expensive debugging
_xd = _expensive_debugging
except NameError:
_xd = False
def get_xex(segments, run_addr=None):
segments_copy = [s for s in segments] # don't affect the original list!
main_segment = None
sub_segments = []
data_style = get_style_bits(data=True)
total = 2
runad = False
for s in segments:
total += 4 + len(s)
if s.origin == 0x2e0:
runad = True
if not runad:
words = np.empty([1], dtype='<u2')
if run_addr:
found = False
for s in segments:
if run_addr >= s.origin and run_addr < s.origin + len(s):
found = True
break
if not found:
raise errors.InvalidBinaryFile("Run address points outside data segments")
else:
run_addr = segments[0].origin
words[0] = run_addr
r = SegmentData(words.view(dtype=np.uint8))
s = DefaultSegment(r, 0x2e0)
segments_copy[0:0] = [s]
total += 6
bytes = np.zeros([total], dtype=np.uint8)
rawdata = SegmentData(bytes)
main_segment = DefaultSegment(rawdata)
main_segment.data[0:2] = 0xff # FFFF header
main_segment.style[0:2] = data_style
i = 2
for s in segments_copy:
# create new sub-segment inside new main segment that duplicates the
# original segment's data/style
new_s = DefaultSegment(rawdata[i:i+4+len(s)], s.origin)
words = new_s.data[0:4].view(dtype='<u2')
words[0] = s.origin
words[1] = s.origin + len(s) - 1
new_s.style[0:4] = data_style
new_s.data[4:4+len(s)] = s[:]
new_s.style[4:4+len(s)] = s.style[:]
i += 4 + len(s)
new_s.copy_user_data(s, 4)
sub_segments.append(new_s)
return main_segment, sub_segments
def get_bsave(segments, run_addr=None):
# Apple 2 executables get executed at the first address loaded. If the
# run_addr is not the first byte of the combined data, have to create a
# new 3-byte segment with a "JMP run_addr" to go at the beginning
origin = 100000000
last = -1
for s in segments:
origin = min(origin, s.origin)
last = max(last, s.origin + len(s))
if _xd: log.debug("contiguous bytes needed: %04x - %04x" % (origin, last))
if run_addr and run_addr != origin:
# check if run_addr points to some location that has data
found = False
for s in segments:
if run_addr >= s.origin and run_addr < s.origin + len(s):
found = True
break
if not found:
raise errors.InvalidBinaryFile("Run address points outside data segments")
origin -= 3
hi, lo = divmod(run_addr, 256)
raw = SegmentData([0x4c, lo, hi])
all_segments = [DefaultSegment(raw, origin=origin)]
all_segments.extend(segments)
else:
all_segments = segments
size = last - origin
image = np.zeros([size + 4], dtype=np.uint8)
words = image[0:4].view(dtype="<u2") # always little endian
words[0] = origin
words[1] = size
for s in all_segments:
index = s.origin - origin + 4
log.debug("setting data for $%04x - $%04x at index $%04x" % (s.origin, s.origin + len(s), index))
image[index:index + len(s)] = s.data
return image
def create_executable_file_data(filename, segments, run_addr=None):
name = filename.lower()
if name.endswith("xex"):
base_segment, user_segments = get_xex(segments, run_addr)
return base_segment.data, "XEX"
elif name.endswith("bin") or name.endswith("bsave"):
data = get_bsave(segments, run_addr)
return data, "B"
raise errors.UnsupportedContainer

View File

@ -1,7 +1,7 @@
import numpy as np import numpy as np
from . import errors from .errors import *
from .ataridos import AtrHeader, AtariDosDirent, AtariDosDiskImage, XexSegment, get_xex from .ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment, get_xex
from .segments import SegmentData from .segments import SegmentData
@ -12,11 +12,11 @@ class KBootDirent(AtariDosDirent):
self.starting_sector = 4 self.starting_sector = 4
self.basename = image.filename self.basename = image.filename
if not self.basename: if not self.basename:
self.basename = b"KBOOT" self.basename = "KBOOT"
if self.basename == self.basename.upper(): if self.basename == self.basename.upper():
self.ext = b"XEX" self.ext = "XEX"
else: else:
self.ext = b"xex" self.ext = "xex"
start, size = image.header.get_pos(4) start, size = image.header.get_pos(4)
i = image.header.header_offset + 9 i = image.header.header_offset + 9
count = image.bytes[i] + 256 * image.bytes[i+1] + 256 * 256 *image.bytes[i + 2] count = image.bytes[i] + 256 * image.bytes[i+1] + 256 * 256 *image.bytes[i + 2]
@ -41,7 +41,7 @@ class KBootImage(AtariDosDiskImage):
def check_sane(self): def check_sane(self):
if not self.all_sane: if not self.all_sane:
raise errors.InvalidDiskImage("Doesn't seem to be KBoot header") raise InvalidDiskImage("Doesn't seem to be KBoot header")
def get_vtoc(self): def get_vtoc(self):
pass pass
@ -70,13 +70,7 @@ class KBootImage(AtariDosDiskImage):
@classmethod @classmethod
def create_boot_image(cls, segments, run_addr=None): def create_boot_image(cls, segments, run_addr=None):
data_segment, _ = get_xex(segments) data_segment, _ = get_xex(segments)
payload_bytes = add_xexboot_header(data_segment.data) data_bytes = add_xexboot_header(data_segment.data)
data_bytes = np.zeros(len(payload_bytes) + 16, np.uint8)
data_bytes[16:] = payload_bytes[:]
header_bytes = data_bytes[0:16]
atr_header = AtrHeader(create=True)
atr_header.check_size(len(payload_bytes))
atr_header.encode(header_bytes)
raw = SegmentData(data_bytes) raw = SegmentData(data_bytes)
atr = cls(raw, create=True) atr = cls(raw, create=True)
return atr return atr
@ -86,7 +80,7 @@ xexboot_header = b'\x00\x03\x00\x07\r\x07L\r\x07\x1c[\x00\x00\xa0\x00\x8c\t\x03\
def insert_bytes(data, offset, string, color): def insert_bytes(data, offset, string, color):
s = np.frombuffer(string.upper(), dtype=np.uint8) - 32 # convert to internal s = np.fromstring(string.upper(), dtype=np.uint8) - 32 # convert to internal
s = s | color s = s | color
count = len(s) count = len(s)
tx = offset + (20 - count) // 2 tx = offset + (20 - count) // 2
@ -103,7 +97,7 @@ def add_xexboot_header(bytes, bootcode=None, title=b"DEMO", author=b"an atari us
paragraphs = padded_size // 16 paragraphs = padded_size // 16
if bootcode is None: if bootcode is None:
bootcode = np.copy(np.frombuffer(xexboot_header, dtype=np.uint8)) bootcode = np.fromstring(xexboot_header, dtype=np.uint8)
else: else:
# don't insert title or author in user supplied bootcode; would have to # don't insert title or author in user supplied bootcode; would have to
# assume that the user supplied everything desired in their own code! # assume that the user supplied everything desired in their own code!

View File

@ -65,9 +65,9 @@ def check_signature(raw, sig):
def guess_detail_for_mime(mime, raw, parser): def guess_detail_for_mime(mime, raw, parser):
for entry in magic: for entry in magic:
if entry['mime'].startswith(mime): if entry['mime'].startswith(mime):
log.debug("checking entry for %s" % entry['mime']) log.debug("checking signature for %s" % entry['mime'])
if check_signature(raw, entry['signature']): if check_signature(raw, entry['signature']):
log.debug("found match: %s" % entry['name']) log.debug("found signature: %s" % entry['name'])
return entry['mime'] return entry['mime']
return mime return mime

View File

@ -2,7 +2,7 @@ import zipfile
import numpy as np import numpy as np
from . import errors from .errors import *
from .segments import SegmentData, EmptySegment, ObjSegment from .segments import SegmentData, EmptySegment, ObjSegment
from .diskimages import DiskImageBase from .diskimages import DiskImageBase
from .utils import to_numpy from .utils import to_numpy
@ -20,7 +20,7 @@ class MameZipImage(DiskImageBase):
self.check_zip_size(zf) self.check_zip_size(zf)
self.create_rawdata(zf) self.create_rawdata(zf)
else: else:
raise errors.InvalidDiskImage("Not a MAME zip file") raise InvalidDiskImage("Not a MAME zip file")
DiskImageBase.__init__(self, self.rawdata, filename) DiskImageBase.__init__(self, self.rawdata, filename)
def __str__(self): def __str__(self):
@ -39,14 +39,14 @@ class MameZipImage(DiskImageBase):
for item in zf.infolist(): for item in zf.infolist():
_, r = divmod(item.file_size, 16) _, r = divmod(item.file_size, 16)
if r > 0: if r > 0:
raise errors.InvalidDiskImage("zip entry not 16 byte multiple") raise InvalidDiskImage("zip entry not 16 byte multiple")
def create_rawdata(self, zf): def create_rawdata(self, zf):
roms = [] roms = []
segment_info = [] segment_info = []
offset = 0 offset = 0
for item in zf.infolist(): for item in zf.infolist():
rom = np.frombuffer(zf.open(item).read(), dtype=np.uint8) rom = np.fromstring(zf.open(item).read(), dtype=np.uint8)
roms.append(rom) roms.append(rom)
segment_info.append((offset, item.file_size, item.filename, item.CRC)) segment_info.append((offset, item.file_size, item.filename, item.CRC))
offset += item.file_size offset += item.file_size

View File

@ -1,27 +0,0 @@
from . import find_diskimage_from_data, errors
import logging
log = logging.getLogger(__name__)
def identify_mime(header, fh):
mime_type = None
try:
fh.seek(0)
data = fh.read()
except IOError as e:
log.debug(f"atrcopy loader: error reading entire file: {e}")
else:
try:
parser, mime_type = find_diskimage_from_data(data, True)
except (errors.UnsupportedContainer, errors.UnsupportedDiskImage, IOError) as e:
log.debug(f"error in atrcopy parser: {e}")
else:
log.debug(f"{parser.image}: {mime_type}")
if mime_type:
log.debug(f"atrcopy loader: identified {mime_type}")
return dict(mime=mime_type, ext="", atrcopy_parser=parser)
else:
log.debug(f"atrcopy loader: not recognized")
return None

View File

@ -1,26 +1,21 @@
import hashlib
import numpy as np import numpy as np
from .segments import SegmentData, DefaultSegment from .segments import SegmentData, DefaultSegment
from .kboot import KBootImage from .kboot import KBootImage
from .ataridos import AtariDosDiskImage, BootDiskImage, AtariDosFile, XexContainerSegment, AtariDiskImage from .ataridos import AtariDosDiskImage, BootDiskImage, AtariDosFile, XexContainerSegment, AtariDiskImage
from .spartados import SpartaDosDiskImage from .spartados import SpartaDosDiskImage
from .cartridge import AtariCartImage, Atari8bitCartImage, Atari5200CartImage, get_known_carts, RomImage, Atari2600CartImage, Atari2600StarpathImage, VectrexCartImage from .cartridge import AtariCartImage, get_known_carts
from .mame import MameZipImage from .mame import MameZipImage
from .dos33 import Dos33DiskImage, ProdosDiskImage, Dos33BinFile from .dos33 import Dos33DiskImage, ProdosDiskImage, Dos33BinFile
from .standard_delivery import StandardDeliveryImage from .standard_delivery import StandardDeliveryImage
from . import errors from .errors import *
from .magic import guess_detail_for_mime from .magic import guess_detail_for_mime
from . import container
from .dcm import DCMContainer
from .signatures import sha1_signatures
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class SegmentParser: class SegmentParser(object):
menu_name = "" menu_name = ""
image_type = None image_type = None
container_segment = DefaultSegment container_segment = DefaultSegment
@ -72,32 +67,24 @@ class SegmentParser:
self.segments.append(self.container_segment(r, 0, name=self.menu_name)) self.segments.append(self.container_segment(r, 0, name=self.menu_name))
try: try:
log.debug("Trying %s" % self.image_type) log.debug("Trying %s" % self.image_type)
log.debug(self.image_type.__mro__)
self.image = self.get_image(r) self.image = self.get_image(r)
self.check_image() self.check_image()
self.image.parse_segments() self.image.parse_segments()
except errors.UnsupportedDiskImage: except UnsupportedDiskImage:
raise raise
except errors.AtrError as e: except AtrError as e:
raise errors.InvalidSegmentParser(e) raise InvalidSegmentParser(e)
self.segments.extend(self.image.segments) self.segments.extend(self.image.segments)
def reconstruct_segments(self, new_rawdata):
self.image = self.get_image(new_rawdata)
self.segment_data = new_rawdata
for s in self.segments:
s.reconstruct_raw(new_rawdata)
def get_image(self, r): def get_image(self, r):
log.info(f"checking image type {self.image_type}")
return self.image_type(r) return self.image_type(r)
def check_image(self): def check_image(self):
if self.strict: if self.strict:
try: try:
self.image.strict_check() self.image.strict_check()
except errors.AtrError as e: except AtrError as e:
raise errors.InvalidSegmentParser(e) raise InvalidSegmentParser(e)
else: else:
self.image.relaxed_check() self.image.relaxed_check()
@ -147,40 +134,9 @@ class AtariCartSegmentParser(SegmentParser):
cart_info = None cart_info = None
def get_image(self, r): def get_image(self, r):
log.info(f"checking cart type {self.cart_type}: {self.image_type}")
return self.image_type(r, self.cart_type) return self.image_type(r, self.cart_type)
class Atari8bitCartParser(AtariCartSegmentParser):
menu_name = "Atari Home Computer Cartridge"
image_type = Atari8bitCartImage
class Atari5200CartParser(AtariCartSegmentParser):
menu_name = "Atari 5200 Cartridge"
image_type = Atari5200CartImage
class Atari2600CartParser(SegmentParser):
menu_name = "Atari 2600 Cartridge"
image_type = Atari2600CartImage
class Atari2600StarpathParser(SegmentParser):
menu_name = "Atari 2600 Starpath Cassette"
image_type = Atari2600StarpathImage
class VectrexParser(SegmentParser):
menu_name = "Vectrex Cartridge"
image_type = VectrexCartImage
class RomParser(SegmentParser):
menu_name = "ROM Image"
image_type = RomImage
class MameZipParser(SegmentParser): class MameZipParser(SegmentParser):
menu_name = "MAME ROM Zipfile" menu_name = "MAME ROM Zipfile"
image_type = MameZipImage image_type = MameZipImage
@ -201,59 +157,6 @@ class ProdosSegmentParser(SegmentParser):
image_type = ProdosDiskImage image_type = ProdosDiskImage
known_containers = [
container.GZipContainer,
container.BZipContainer,
container.LZMAContainer,
DCMContainer,
]
def guess_container(r, verbose=False):
for c in known_containers:
if verbose:
log.info(f"trying container {c}")
try:
found = c(r)
except errors.InvalidContainer as e:
continue
else:
if verbose:
log.info(f"found container {c}")
return found
log.info(f"image does not appear to be a container.")
return None
def guess_parser_by_size(r, verbose=False):
found = None
mime = None
size = len(r)
if size in sha1_signatures:
sha_hash = hashlib.sha1(r.data).digest()
log.info(f"{size} in signature database, attempting to match {sha_hash}")
try:
match = sha1_signatures[size][sha_hash]
except KeyError:
pass
else:
mime = match[0]
log.info(f"found match: {match}")
parsers = mime_parsers[mime]
for parser in parsers:
try:
found = parser(r, False)
break
except errors.InvalidSegmentParser as e:
if verbose:
log.info("parser isn't %s: %s" % (parser.__name__, str(e)))
pass
if found is None:
log.info(f"no matching signature")
else:
log.info(f"{size} not found in signature database; skipping sha1 matching")
return mime, found
def guess_parser_for_mime(mime, r, verbose=False): def guess_parser_for_mime(mime, r, verbose=False):
parsers = mime_parsers[mime] parsers = mime_parsers[mime]
found = None found = None
@ -261,7 +164,7 @@ def guess_parser_for_mime(mime, r, verbose=False):
try: try:
found = parser(r, True) found = parser(r, True)
break break
except errors.InvalidSegmentParser as e: except InvalidSegmentParser as e:
if verbose: if verbose:
log.info("parser isn't %s: %s" % (parser.__name__, str(e))) log.info("parser isn't %s: %s" % (parser.__name__, str(e)))
pass pass
@ -279,18 +182,12 @@ def guess_parser_for_system(mime_base, r):
def iter_parsers(r): def iter_parsers(r):
container = guess_container(r.data) for mime in mime_parse_order:
if container is not None: p = guess_parser_for_mime(mime, r)
r = SegmentData(container.unpacked) if p is not None:
mime, parser = guess_parser_by_size(r) mime = guess_detail_for_mime(mime, r, p)
if parser is None: return mime, p
for mime in mime_parse_order: return None, None
p = guess_parser_for_mime(mime, r)
if p is not None:
parser = p
mime = guess_detail_for_mime(mime, r, p)
break
return mime, parser
def parsers_for_filename(name): def parsers_for_filename(name):
@ -310,7 +207,7 @@ def parsers_for_filename(name):
_, name = name.rsplit(".", 1) _, name = name.rsplit(".", 1)
except ValueError: except ValueError:
pass pass
raise errors.InvalidDiskImage("no disk image formats that match '%s'" % name) raise InvalidDiskImage("no disk image formats that match '%s'" % name)
return matches return matches
@ -326,26 +223,12 @@ mime_parsers = {
XexSegmentParser, XexSegmentParser,
], ],
"application/vnd.atari8bit.cart": [ "application/vnd.atari8bit.cart": [
Atari8bitCartParser,
], ],
"application/vnd.atari5200.cart": [ "application/vnd.atari8bit.5200_cart": [
Atari5200CartParser,
],
"application/vnd.atari2600.cart": [
Atari2600CartParser,
],
"application/vnd.atari2600.starpath": [
Atari2600StarpathParser,
],
"application/vnd.vectrex": [
VectrexParser,
], ],
"application/vnd.mame_rom": [ "application/vnd.mame_rom": [
MameZipParser, MameZipParser,
], ],
"application/vnd.rom": [
RomParser,
],
"application/vnd.apple2.dsk": [ "application/vnd.apple2.dsk": [
Dos33SegmentParser, Dos33SegmentParser,
ProdosSegmentParser, ProdosSegmentParser,
@ -355,47 +238,22 @@ mime_parsers = {
], ],
} }
# Note: Atari 2600 scanning not performed here because it will match everything
mime_parse_order = [ mime_parse_order = [
"application/vnd.atari8bit.atr", "application/vnd.atari8bit.atr",
"application/vnd.atari8bit.xex", "application/vnd.atari8bit.xex",
"application/vnd.atari8bit.cart", "application/vnd.atari8bit.cart",
"application/vnd.atari5200.cart", "application/vnd.atari8bit.5200_cart",
"application/vnd.mame_rom", "application/vnd.mame_rom",
"application/vnd.apple2.dsk", "application/vnd.apple2.dsk",
"application/vnd.apple2.bin", "application/vnd.apple2.bin",
"application/vnd.rom",
]
# different than the above mime_parse_order, this list is the order in which
# the mime parsers will appear in a UI. Some, like the vectrex and atari2600
# parsers, aren't included in the parse order because they will identify
# many things incorrectly. They are used only when parsing by size and
# signature.
mime_display_order = [
"application/vnd.atari8bit.atr",
"application/vnd.atari8bit.xex",
"application/vnd.atari8bit.cart",
"application/vnd.atari5200.cart",
"application/vnd.atari2600.cart",
"application/vnd.atari2600.starpath",
"application/vnd.vectrex",
"application/vnd.mame_rom",
"application/vnd.apple2.dsk",
"application/vnd.apple2.bin",
"application/vnd.rom",
] ]
pretty_mime = { pretty_mime = {
"application/vnd.atari8bit.atr": "Atari 8-bit Disk Image", "application/vnd.atari8bit.atr": "Atari 8-bit Disk Image",
"application/vnd.atari8bit.xex": "Atari 8-bit Executable", "application/vnd.atari8bit.xex": "Atari 8-bit Executable",
"application/vnd.atari8bit.cart": "Atari 8-bit Cartridge", "application/vnd.atari8bit.cart": "Atari 8-bit Cartridge",
"application/vnd.atari5200.cart": "Atari 5200 Cartridge", "application/vnd.atari8bit.5200_cart":"Atari 5200 Cartridge",
"application/vnd.atari2600.cart": "Atari 2600 Cartridge",
"application/vnd.atari2600.starpath": "Atari 2600 Starpath Cassette",
"application/vnd.vectrex": "GCE Vectrex Cartridge",
"application/vnd.mame_rom": "MAME", "application/vnd.mame_rom": "MAME",
"application/vnd.rom": "ROM Image",
"application/vnd.apple2.dsk": "Apple ][ Disk Image", "application/vnd.apple2.dsk": "Apple ][ Disk Image",
"application/vnd.apple2.bin": "Apple ][ Binary", "application/vnd.apple2.bin": "Apple ][ Binary",
} }
@ -406,21 +264,20 @@ for k in sizes:
for c in grouped_carts[k]: for c in grouped_carts[k]:
t = c[0] t = c[0]
name = c[1] name = c[1]
kclass = type("AtariCartSegmentParser%d" % t, (AtariCartSegmentParser,), {'cart_type': t, 'cart_info': c, 'menu_name': "%s Cartridge" % name})
if "5200" in name: if "5200" in name:
key = "application/vnd.atari5200.cart" key = "application/vnd.atari8bit.5200_cart"
kclass = type("Atari5200CartSegmentParser%d" % t, (Atari5200CartParser, AtariCartSegmentParser), {'cart_type': t, 'cart_info': c, 'menu_name': "%s Cartridge" % name})
else: else:
key = "application/vnd.atari8bit.cart" key = "application/vnd.atari8bit.cart"
kclass = type("Atari8bitCartSegmentParser%d" % t, (Atari8bitCartParser, AtariCartSegmentParser), {'cart_type': t, 'cart_info': c, 'menu_name': "%s Cartridge" % name})
mime_parsers[key].append(kclass) mime_parsers[key].append(kclass)
known_segment_parsers = [DefaultSegmentParser] known_segment_parsers = [DefaultSegmentParser]
for mime in mime_display_order: for mime in mime_parse_order:
known_segment_parsers.extend(mime_parsers[mime]) known_segment_parsers.extend(mime_parsers[mime])
def iter_known_segment_parsers(): def iter_known_segment_parsers():
yield "application/octet-stream", "", [DefaultSegmentParser] yield "application/octet-stream", "", [DefaultSegmentParser]
for mime in mime_display_order: for mime in mime_parse_order:
yield mime, pretty_mime[mime], mime_parsers[mime] yield mime, pretty_mime[mime], mime_parsers[mime]

View File

@ -3,7 +3,7 @@ import io
import numpy as np import numpy as np
from . import errors from .errors import *
from .utils import to_numpy, to_numpy_list, uuid from .utils import to_numpy, to_numpy_list, uuid
from functools import reduce from functools import reduce
@ -57,7 +57,7 @@ def get_style_mask(**kwargs):
return 0xff ^ bits return 0xff ^ bits
class SegmentSaver: class SegmentSaver(object):
export_data_name = "Raw Data" export_data_name = "Raw Data"
export_extensions = [".dat"] export_extensions = [".dat"]
@ -66,7 +66,7 @@ class SegmentSaver:
return segment.tobytes() return segment.tobytes()
class BSAVESaver: class BSAVESaver(object):
export_data_name = "Apple ][ Binary" export_data_name = "Apple ][ Binary"
export_extensions = [".bsave"] export_extensions = [".bsave"]
@ -76,11 +76,11 @@ class BSAVESaver:
header = np.empty(2, dtype="<u2") header = np.empty(2, dtype="<u2")
header[0] = segment.origin header[0] = segment.origin
header[1] = len(data) header[1] = len(data)
log.debug("binary data: %x bytes at %x" % (header[1], header[0])) print("binary data: %x bytes at %x" % (header[1], header[0]))
return header.tobytes() + segment.tobytes() return header.tobytes() + segment.tobytes()
class OrderWrapper: class OrderWrapper(object):
"""Wrapper for numpy data so that manipulations can use normal numpy syntax """Wrapper for numpy data so that manipulations can use normal numpy syntax
and still affect the data according to the byte ordering. and still affect the data according to the byte ordering.
@ -132,7 +132,7 @@ class OrderWrapper:
return self.np_data[self.order].tobytes() return self.np_data[self.order].tobytes()
class UserExtraData: class UserExtraData(object):
def __init__(self): def __init__(self):
self.comments = dict() self.comments = dict()
self.user_data = dict() self.user_data = dict()
@ -140,7 +140,7 @@ class UserExtraData:
self.user_data[i] = dict() self.user_data[i] = dict()
class SegmentData: class SegmentData(object):
def __init__(self, data, style=None, extra=None, debug=False, order=None): def __init__(self, data, style=None, extra=None, debug=False, order=None):
"""Storage for raw data """Storage for raw data
@ -194,7 +194,7 @@ class SegmentData:
newsize = len(base_raw) newsize = len(base_raw)
oldsize = len(self.data_base) oldsize = len(self.data_base)
if newsize < oldsize: if newsize < oldsize:
raise errors.NotImplementedError("Can't truncate yet") raise NotImplementedError("Can't truncate yet")
if self.is_indexed: if self.is_indexed:
self.data.np_data = base_raw.data self.data.np_data = base_raw.data
self.data.base = base_raw.data.base self.data.base = base_raw.data.base
@ -388,7 +388,7 @@ class SegmentData:
return r return r
class DefaultSegment: class DefaultSegment(object):
savers = [SegmentSaver, BSAVESaver] savers = [SegmentSaver, BSAVESaver]
can_resize_default = False can_resize_default = False
@ -414,8 +414,7 @@ class DefaultSegment:
def set_raw(self, rawdata): def set_raw(self, rawdata):
if type(rawdata) != SegmentData: if type(rawdata) != SegmentData:
log.warning(f"data not in SegmentData format: {type(rawdata)}") log.warning(f"data not in SegmentData format {rawdata}, {type(rawdata)}")
rawdata = SegmentData(rawdata)
self.rawdata = rawdata self.rawdata = rawdata
self.update_raw_pointers() self.update_raw_pointers()
@ -523,7 +522,7 @@ class DefaultSegment:
""" """
if hasattr(self, 'start_addr'): if hasattr(self, 'start_addr'):
self.origin = self.start_addr self.origin = self.start_addr
log.debug(f"moving start_addr to origin: {self.start_addr}") print(f"moving start_addr to origin: {self.start_addr}")
delattr(self, 'start_addr') delattr(self, 'start_addr')
def reconstruct_raw(self, rawdata): def reconstruct_raw(self, rawdata):
@ -553,7 +552,7 @@ class DefaultSegment:
r = r.get_indexed[other.order] r = r.get_indexed[other.order]
return r return r
def serialize_session(self, mdict): def serialize_extra_to_dict(self, mdict):
"""Save extra metadata to a dict so that it can be serialized """Save extra metadata to a dict so that it can be serialized
This is not saved by __getstate__ because child segments will point to This is not saved by __getstate__ because child segments will point to
@ -573,7 +572,7 @@ class DefaultSegment:
# pairs # pairs
mdict["comments"] = self.get_sorted_comments() mdict["comments"] = self.get_sorted_comments()
def restore_session(self, e): def restore_extra_from_dict(self, e):
if 'comments' in e: if 'comments' in e:
for k, v in e['comments']: for k, v in e['comments']:
self.rawdata.extra.comments[k] = v self.rawdata.extra.comments[k] = v

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
import numpy as np import numpy as np
from . import errors from .errors import *
from .ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment from .ataridos import AtariDosDirent, AtariDosDiskImage, XexSegment
from .segments import DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentSaver from .segments import DefaultSegment, EmptySegment, ObjSegment, RawSectorsSegment, SegmentSaver
@ -38,7 +38,7 @@ class SpartaDosDirent(AtariDosDirent):
deleted = "d" if self.deleted else "." deleted = "d" if self.deleted else "."
locked = "*" if self.locked else " " locked = "*" if self.locked else " "
flags = "%s%s%s%s%s %03d" % (output, subdir, in_use, deleted, locked, self.starting_sector) flags = "%s%s%s%s%s %03d" % (output, subdir, in_use, deleted, locked, self.starting_sector)
return "File #%-2d (%s) %-8s%-3s %8d %s" % (self.file_num, flags, self.basename.decode('latin1'), self.ext.decode('latin1'), self.length, self.str_timestamp) return "File #%-2d (%s) %-8s%-3s %8d %s" % (self.file_num, flags, self.basename.decode('utf-8'), self.ext.decode('utf-8'), self.length, self.str_timestamp)
@property @property
def verbose_info(self): def verbose_info(self):
@ -66,7 +66,7 @@ class SpartaDosDirent(AtariDosDirent):
self.starting_sector = int(values[1]) self.starting_sector = int(values[1])
self.basename = bytes(values[4]).rstrip() self.basename = bytes(values[4]).rstrip()
if self.is_dir: if self.is_dir:
self.ext = b"" self.ext = ""
else: else:
self.ext = bytes(values[5]).rstrip() self.ext = bytes(values[5]).rstrip()
self.length = 256*256*values[3] + values[2] self.length = 256*256*values[3] + values[2]
@ -90,7 +90,7 @@ class SpartaDosDirent(AtariDosDirent):
def start_read(self, image): def start_read(self, image):
if not self.is_sane: if not self.is_sane:
log.debug("Invalid directory entry '%s', starting_sector=%s" % (str(self), self.starting_sector)) log.debug("Invalid directory entry '%s', starting_sector=%s" % (str(self), self.starting_sector))
raise errors.InvalidDirent("Invalid directory entry '%s'" % str(self)) raise InvalidDirent("Invalid directory entry '%s'" % str(self))
self.sector_map = image.get_sector_map(self.starting_sector) self.sector_map = image.get_sector_map(self.starting_sector)
self.sector_map_index = 0 self.sector_map_index = 0
self.length_remaining = self.length self.length_remaining = self.length
@ -159,7 +159,7 @@ class SpartaDosDiskImage(AtariDosDiskImage):
num = self.header.max_sectors num = self.header.max_sectors
self.is_sane = self.total_sectors == num and values['first_free'] <= num and self.first_bitmap <= num and self.root_dir <= num and self.fs_version in [0x11, 0x20, 0x21] and self.sector_size != -1 self.is_sane = self.total_sectors == num and values['first_free'] <= num and self.first_bitmap <= num and self.root_dir <= num and self.fs_version in [0x11, 0x20, 0x21] and self.sector_size != -1
if not self.is_sane: if not self.is_sane:
raise errors.InvalidDiskImage("Invalid SpartaDos parameters in boot header") raise InvalidDiskImage("Invalid SpartaDos parameters in boot header")
def get_vtoc(self): def get_vtoc(self):
pass pass

View File

@ -1,6 +1,6 @@
import numpy as np import numpy as np
from . import errors from .errors import *
from .segments import SegmentData from .segments import SegmentData
from .diskimages import BaseHeader, DiskImageBase from .diskimages import BaseHeader, DiskImageBase
@ -20,14 +20,14 @@ class StandardDeliveryHeader(BaseHeader):
if np.all(data == (0x01, 0xa8, 0xee, 0x06, 0x08)): if np.all(data == (0x01, 0xa8, 0xee, 0x06, 0x08)):
log.debug("Found 48k loader") log.debug("Found 48k loader")
else: else:
raise errors.InvalidDiskImage("No %s boot header" % self.file_format) raise InvalidDiskImage("No %s boot header" % self.file_format)
def __str__(self): def __str__(self):
return "Standard Delivery Boot Disk (size=%d (%dx%dB)" % (self.file_format, self.image_size, self.max_sectors, self.sector_size) return "Standard Delivery Boot Disk (size=%d (%dx%dB)" % (self.file_format, self.image_size, self.max_sectors, self.sector_size)
def check_size(self, size): def check_size(self, size):
if size != 143360: if size != 143360:
raise errors.InvalidDiskImage("Incorrect size for Standard Delivery image") raise InvalidDiskImage("Incorrect size for Standard Delivery image")
self.image_size = size self.image_size = size
self.tracks_per_disk = 35 self.tracks_per_disk = 35
self.sectors_per_track = 16 self.sectors_per_track = 16
@ -165,7 +165,7 @@ from . fstbt import fstbt
def get_fstbt_code(data, address_list, run_addr): def get_fstbt_code(data, address_list, run_addr):
pointer = len(fstbt) pointer = len(fstbt)
data[0:pointer] = np.frombuffer(fstbt, dtype=np.uint8) data[0:pointer] = np.fromstring(fstbt, dtype=np.uint8)
hi, lo = divmod(run_addr, 256) hi, lo = divmod(run_addr, 256)
data[pointer:pointer + 2] = (lo, hi) data[pointer:pointer + 2] = (lo, hi)
address_list.append(0xc0) # last sector flag address_list.append(0xc0) # last sector flag

View File

@ -1 +1 @@
{"type": "new file", "task": "hex_edit", "description": "Atari 8-bit DOS 2 double density (180K), empty VTOC", "label": "Atari DOS 2 DD (180K) blank image", "ext": "atr"} {"task": "hex_edit", "description": "Atari 8-bit DOS 2 double density (180K), empty VTOC", "label": "Atari DOS 2 DD (180K) blank image", "ext": "atr"}

View File

@ -1 +1 @@
{"type": "new file", "task": "hex_edit", "description": "Atari 8-bit DOS 2 enhanced density (130K) DOS 2.5 system disk", "label": "Atari DOS 2.5 ED (130K) system disk", "ext": "atr"} {"task": "hex_edit", "description": "Atari 8-bit DOS 2 enhanced density (130K) DOS 2.5 system disk", "label": "Atari DOS 2.5 ED (130K) system disk", "ext": "atr"}

View File

@ -1 +1 @@
{"type": "new file", "task": "hex_edit", "description": "Atari 8-bit DOS 2 enhanced density (130K), empty VTOC", "label": "Atari DOS 2 ED (130K) blank image", "ext": "atr"} {"task": "hex_edit", "description": "Atari 8-bit DOS 2 enhanced density (130K), empty VTOC", "label": "Atari DOS 2 ED (130K) blank image", "ext": "atr"}

View File

@ -1 +1 @@
{"type": "new file", "task": "hex_edit", "description": "Atari 8-bit DOS 2 single density (90K) DOS 2.0S system disk", "label": "Atari DOS 2.0S SD (90K) system disk", "ext": "atr"} {"task": "hex_edit", "description": "Atari 8-bit DOS 2 single density (90K) DOS 2.0S system disk", "label": "Atari DOS 2.0S SD (90K) system disk", "ext": "atr"}

View File

@ -1 +1 @@
{"type": "new file", "task": "hex_edit", "description": "Atari 8-bit DOS 2 single density (90K), empty VTOC", "label": "Atari DOS 2 SD (90K) blank image", "ext": "atr"} {"task": "hex_edit", "description": "Atari 8-bit DOS 2 single density (90K), empty VTOC", "label": "Atari DOS 2 SD (90K) blank image", "ext": "atr"}

View File

@ -1 +1 @@
{"type": "new file", "task": "hex_edit", "description": "Apple ][ DOS 3.3 (140K) standard RWTS, empty VTOC", "label": "Apple DOS 3.3 (140K) blank image", "ext": "dsk"} {"task": "hex_edit", "description": "Apple ][ DOS 3.3 (140K) standard RWTS, empty VTOC", "label": "Apple DOS 3.3 (140K) blank image", "ext": "dsk"}

View File

@ -1 +1 @@
{"type": "new file", "task": "hex_edit", "description": "Apple ][ DOS 3.3 (140K) disk image for binary program development: HELLO sets fullscreen HGR and calls BRUN on user-supplied AUTOBRUN binary file", "label": "Apple DOS 3.3 (140K) AUTOBRUN image", "ext": "dsk"} {"task": "hex_edit", "description": "Apple ][ DOS 3.3 (140K) disk image for binary program development: HELLO sets fullscreen HGR and calls BRUN on user-supplied AUTOBRUN binary file", "label": "Apple DOS 3.3 (140K) AUTOBRUN image", "ext": "dsk"}

View File

@ -3,7 +3,7 @@ import uuid as stdlib_uuid
import numpy as np import numpy as np
from . import errors from .errors import *
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -29,7 +29,7 @@ def to_numpy(value):
if type(value) is np.ndarray: if type(value) is np.ndarray:
return value return value
elif type(value) is bytes: elif type(value) is bytes:
return np.copy(np.frombuffer(value, dtype=np.uint8)) return np.fromstring(value, dtype=np.uint8)
elif type(value) is list: elif type(value) is list:
return np.asarray(value, dtype=np.uint8) return np.asarray(value, dtype=np.uint8)
raise TypeError("Can't convert to numpy data") raise TypeError("Can't convert to numpy data")
@ -60,7 +60,7 @@ def text_to_int(text, default_base="hex"):
return value return value
class WriteableSector: class WriteableSector(object):
def __init__(self, sector_size, data=None, num=-1): def __init__(self, sector_size, data=None, num=-1):
self._sector_num = num self._sector_num = num
self._next_sector = 0 self._next_sector = 0
@ -109,7 +109,7 @@ class WriteableSector:
return data[count:] return data[count:]
class BaseSectorList: class BaseSectorList(object):
def __init__(self, header): def __init__(self, header):
self.header = header self.header = header
self.sector_size = header.sector_size self.sector_size = header.sector_size
@ -150,7 +150,7 @@ class BaseSectorList:
self.sectors.extend(sectors) self.sectors.extend(sectors)
class Dirent: class Dirent(object):
"""Abstract base class for a directory entry """Abstract base class for a directory entry
""" """
@ -159,28 +159,28 @@ class Dirent:
self.file_num = file_num self.file_num = file_num
def __eq__(self, other): def __eq__(self, other):
raise errors.NotImplementedError raise NotImplementedError
def extra_metadata(self, image): def extra_metadata(self, image):
raise errors.NotImplementedError raise NotImplementedError
def mark_deleted(self): def mark_deleted(self):
raise errors.NotImplementedError raise NotImplementedError
def parse_raw_dirent(self, image, bytes): def parse_raw_dirent(self, image, bytes):
raise errors.NotImplementedError raise NotImplementedError
def encode_dirent(self): def encode_dirent(self):
raise errors.NotImplementedError raise NotImplementedError
def get_sectors_in_vtoc(self, image): def get_sectors_in_vtoc(self, image):
raise errors.NotImplementedError raise NotImplementedError
def start_read(self, image): def start_read(self, image):
raise errors.NotImplementedError raise NotImplementedError
def read_sector(self, image): def read_sector(self, image):
raise errors.NotImplementedError raise NotImplementedError
class Directory(BaseSectorList): class Directory(BaseSectorList):
@ -205,7 +205,7 @@ class Directory(BaseSectorList):
return i return i
used.add(i) used.add(i)
if self.num_dirents > 0 and (len(used) >= self.num_dirents): if self.num_dirents > 0 and (len(used) >= self.num_dirents):
raise errors.NoSpaceInDirectory() raise NoSpaceInDirectory()
i += 1 i += 1
else: else:
i = 0 i = 0
@ -229,7 +229,7 @@ class Directory(BaseSectorList):
for dirent in list(self.dirents.values()): for dirent in list(self.dirents.values()):
if filename == dirent.filename: if filename == dirent.filename:
return dirent return dirent
raise errors.FileNotFound("%s not found on disk" % filename) raise FileNotFound("%s not found on disk" % filename)
def save_dirent(self, image, dirent, vtoc, sector_list): def save_dirent(self, image, dirent, vtoc, sector_list):
vtoc.assign_sector_numbers(dirent, sector_list) vtoc.assign_sector_numbers(dirent, sector_list)
@ -244,7 +244,7 @@ class Directory(BaseSectorList):
@property @property
def dirent_class(self): def dirent_class(self):
raise errors.NotImplementedError raise NotImplementedError
def calc_sectors(self, image): def calc_sectors(self, image):
self.sectors = [] self.sectors = []
@ -270,10 +270,10 @@ class Directory(BaseSectorList):
return self.sector_class(self.sector_size) return self.sector_class(self.sector_size)
def encode_empty(self): def encode_empty(self):
raise errors.NotImplementedError raise NotImplementedError
def encode_dirent(self, dirent): def encode_dirent(self, dirent):
raise errors.NotImplementedError raise NotImplementedError
def store_encoded(self, data): def store_encoded(self, data):
while True: while True:
@ -291,7 +291,7 @@ class Directory(BaseSectorList):
self.set_sector_numbers(image) self.set_sector_numbers(image)
def set_sector_numbers(self, image): def set_sector_numbers(self, image):
raise errors.NotImplementedError raise NotImplementedError
class VTOC(BaseSectorList): class VTOC(BaseSectorList):
@ -317,7 +317,7 @@ class VTOC(BaseSectorList):
yield i, pos, size yield i, pos, size
def parse_segments(self, segments): def parse_segments(self, segments):
raise errors.NotImplementedError raise NotImplementedError
def assign_sector_numbers(self, dirent, sector_list): def assign_sector_numbers(self, dirent, sector_list):
""" Map out the sectors and link the sectors together """ Map out the sectors and link the sectors together
@ -328,7 +328,7 @@ class VTOC(BaseSectorList):
num = len(sector_list) num = len(sector_list)
order = self.reserve_space(num) order = self.reserve_space(num)
if len(order) != num: if len(order) != num:
raise errors.InvalidFile("VTOC reserved space for %d sectors. Sectors needed: %d" % (len(order), num)) raise InvalidFile("VTOC reserved space for %d sectors. Sectors needed: %d" % (len(order), num))
file_length = 0 file_length = 0
last_sector = None last_sector = None
for sector, sector_num in zip(sector_list.sectors, order): for sector, sector_num in zip(sector_list.sectors, order):
@ -357,10 +357,10 @@ class VTOC(BaseSectorList):
if _xd: log.debug("Found sector %d free" % num) if _xd: log.debug("Found sector %d free" % num)
self.sector_map[num] = 0 self.sector_map[num] = 0
return num return num
raise errors.NotEnoughSpaceOnDisk("No space left in VTOC") raise NotEnoughSpaceOnDisk("No space left in VTOC")
def calc_bitmap(self): def calc_bitmap(self):
raise errors.NotImplementedError raise NotImplementedError
def free_sector_list(self, sector_list): def free_sector_list(self, sector_list):
for sector in sector_list: for sector in sector_list:

View File

@ -1,47 +0,0 @@
#!/usr/bin/env python
import os
import sys
import hashlib
from collections import defaultdict
import pprint
def parse(filename, mime):
data = open(filename, 'rb').read()
h = hashlib.sha1(data).digest()
name = os.path.basename(os.path.splitext(filename)[0])
return len(data), h, name
if __name__ == '__main__':
source = "atrcopy/signatures.py"
try:
with open(source, 'r') as fh:
source_text = fh.read()
except OSError:
source_text = "sha1_signatures = {}"
try:
exec(source_text)
except:
raise
print(sha1_signatures)
mime = sys.argv[1]
new_signatures = defaultdict(dict)
new_signatures.update(sha1_signatures)
for filename in sys.argv[2:]:
print(f"parsing {filename}")
size, hash_string, name = parse(filename, mime)
print(f"{size} {hash_string} {mime} {name}")
new_signatures[size][hash_string] = (mime, name)
lines = []
lines.append("sha1_signatures = {")
for k,v in sorted(new_signatures.items()):
lines.append(f"{k}: {{")
for h,n in sorted(v.items(), key=lambda a:(a[1], a[0])):
lines.append(f" {h}: {n},")
lines.append("},")
lines.append("} # end sha1_signatures\n")
print("\n".join(lines))
with open(source, 'w') as fh:
fh.write("\n".join(lines))

View File

@ -1,12 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
if __name__ == "__main__": if __name__ == "__main__":
import sys import atrcopy
if sys.version_info < (3, 6, 0):
print("atrcopy requires Python 3.6 or greater to run; this is Python %s" % ".".join([str(v) for v in sys.version_info[0:2]]))
if sys.version_info[0] == 2:
print("Python 2 support was dropped with atrcopy 7.0, so you can either use:\n\n pip install \"atrcopy<7.0\"\n\nto install a version compatible with Python 2, or install Python 3.6 or higher.")
else:
import atrcopy
atrcopy.run() atrcopy.run()

View File

@ -5,8 +5,7 @@ try:
except ImportError: except ImportError:
from distutils.core import setup from distutils.core import setup
exec(compile(open('atrcopy/_version.py').read(), 'atrcopy/_version.py', 'exec')) exec(open('atrcopy/_metadata.py').read())
exec(compile(open('atrcopy/_metadata.py').read(), 'atrcopy/_metadata.py', 'exec'))
with open("README.rst", "r") as fp: with open("README.rst", "r") as fp:
long_description = fp.read() long_description = fp.read()
@ -24,18 +23,16 @@ setup(name="atrcopy",
packages=["atrcopy"], packages=["atrcopy"],
include_package_data=True, include_package_data=True,
scripts=scripts, scripts=scripts,
entry_points={"sawx.loaders": 'atrcopy = atrcopy.omnivore_loader'},
description="Utility to manage file systems on Atari 8-bit (DOS 2) and Apple ][ (DOS 3.3) disk images.", description="Utility to manage file systems on Atari 8-bit (DOS 2) and Apple ][ (DOS 3.3) disk images.",
long_description=long_description, long_description=long_description,
license="MPL 2.0", license="GPL",
classifiers=[ classifiers=[
"Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.6",
"Intended Audience :: Developers", "Intended Audience :: Developers",
"License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)", "License :: OSI Approved :: GNU General Public License (GPL)",
"Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries",
"Topic :: Utilities", "Topic :: Utilities",
], ],
python_requires = '>=3.6',
install_requires = [ install_requires = [
'numpy', 'numpy',
], ],

View File

@ -1,2 +1,2 @@
#[pytest] [pytest]
#addopts = --cov=atrcopy --cov-report html --cov-report term addopts = --cov=atrcopy --cov-report html --cov-report term

View File

@ -4,11 +4,11 @@ import numpy as np
from mock import * from mock import *
from atrcopy import SegmentData, AtariDosDiskImage, Dos33DiskImage from atrcopy import SegmentData, AtariDosDiskImage, Dos33DiskImage,InvalidBinaryFile
from atrcopy import errors from atrcopy.errors import *
class BaseFilesystemModifyTest: class BaseFilesystemModifyTest(object):
diskimage_type = None diskimage_type = None
sample_data = None sample_data = None
num_files_in_sample = 0 num_files_in_sample = 0
@ -25,7 +25,7 @@ class BaseFilesystemModifyTest:
filename = "%s%d.BIN" % (prefix, count) filename = "%s%d.BIN" % (prefix, count)
self.image.write_file(filename, None, data) self.image.write_file(filename, None, data)
assert len(self.image.files) == orig_num_files + count assert len(self.image.files) == orig_num_files + count
data2 = np.frombuffer(self.image.find_file(filename), dtype=np.uint8) data2 = np.fromstring(self.image.find_file(filename), dtype=np.uint8)
assert np.array_equal(data, data2[0:len(data)]) assert np.array_equal(data, data2[0:len(data)])
count += 1 count += 1
@ -33,7 +33,7 @@ class BaseFilesystemModifyTest:
count = 1 count = 1
for data in entries: for data in entries:
filename = "%s%d.BIN" % (prefix, count) filename = "%s%d.BIN" % (prefix, count)
data2 = np.frombuffer(self.image.find_file(filename), dtype=np.uint8) data2 = np.fromstring(self.image.find_file(filename), dtype=np.uint8)
assert np.array_equal(data, data2[0:len(data)]) assert np.array_equal(data, data2[0:len(data)])
count += 1 count += 1
filenames.append(filename) filenames.append(filename)
@ -50,7 +50,7 @@ class BaseFilesystemModifyTest:
self.image.write_file("TEST.XEX", None, data) self.image.write_file("TEST.XEX", None, data)
assert len(self.image.files) == self.num_files_in_sample + 1 assert len(self.image.files) == self.num_files_in_sample + 1
data2 = np.frombuffer(self.image.find_file("TEST.XEX"), dtype=np.uint8) data2 = np.fromstring(self.image.find_file("TEST.XEX"), dtype=np.uint8)
assert np.array_equal(data, data2[0:len(data)]) assert np.array_equal(data, data2[0:len(data)])
def test_50k(self): def test_50k(self):
@ -85,7 +85,7 @@ class BaseFilesystemModifyTest:
data = np.arange(50*1024, dtype=np.uint8) data = np.arange(50*1024, dtype=np.uint8)
self.image.write_file("RAMP50K.BIN", None, data) self.image.write_file("RAMP50K.BIN", None, data)
assert len(self.image.files) == self.num_files_in_sample + 1 assert len(self.image.files) == self.num_files_in_sample + 1
with pytest.raises(errors.NotEnoughSpaceOnDisk): with pytest.raises(NotEnoughSpaceOnDisk):
huge = np.arange(500*1024, dtype=np.uint8) huge = np.arange(500*1024, dtype=np.uint8)
self.image.write_file("RAMP500K.BIN", None, huge) self.image.write_file("RAMP500K.BIN", None, huge)
assert len(self.image.files) == self.num_files_in_sample + 1 assert len(self.image.files) == self.num_files_in_sample + 1

View File

@ -2,11 +2,10 @@ from __future__ import print_function
from builtins import object from builtins import object
from mock import * from mock import *
from atrcopy import SegmentData, AtariDosFile, DefaultSegment, XexContainerSegment, errors from atrcopy import SegmentData, AtariDosFile, InvalidBinaryFile, DefaultSegment, XexContainerSegment
class TestAtariDosFile(object):
class TestAtariDosFile:
def setup(self): def setup(self):
pass pass
@ -42,7 +41,7 @@ class TestAtariDosFile:
bytes = [0xff, 0xff, 0x00, 0x60, 0x00, 0x00, 1, 2] bytes = [0xff, 0xff, 0x00, 0x60, 0x00, 0x00, 1, 2]
rawdata = SegmentData(bytes) rawdata = SegmentData(bytes)
image = AtariDosFile(rawdata) image = AtariDosFile(rawdata)
with pytest.raises(errors.InvalidBinaryFile): with pytest.raises(InvalidBinaryFile):
image.parse_segments() image.parse_segments()

View File

@ -3,11 +3,10 @@ from __future__ import division
from builtins import object from builtins import object
from mock import * from mock import *
from atrcopy import AtariCartImage, SegmentData, RomImage, errors from atrcopy import AtariCartImage, SegmentData, InvalidDiskImage
from atrcopy.cartridge import known_cart_types
class TestAtariCart: class TestAtariCart(object):
def setup(self): def setup(self):
pass pass
@ -17,24 +16,26 @@ class TestAtariCart:
data[4:8].view(">u4")[0] = cart_type data[4:8].view(">u4")[0] = cart_type
return data return data
@pytest.mark.parametrize("k_size,cart_type", [ def test_unbanked(self):
carts = [
(8, 1), (8, 1),
(16, 2), (16, 2),
(8, 21), (8, 21),
(2, 57), (2, 57),
(4, 58), (4, 58),
(4, 59), (4, 59),
]) ]
def test_unbanked(self, k_size, cart_type): for k_size, cart_type in carts:
data = self.get_cart(k_size, cart_type) data = self.get_cart(k_size, cart_type)
rawdata = SegmentData(data) rawdata = SegmentData(data)
image = AtariCartImage(rawdata, cart_type) image = AtariCartImage(rawdata, cart_type)
image.parse_segments() image.parse_segments()
assert len(image.segments) == 2 assert len(image.segments) == 2
assert len(image.segments[0]) == 16 assert len(image.segments[0]) == 16
assert len(image.segments[1]) == k_size * 1024 assert len(image.segments[1]) == k_size * 1024
@pytest.mark.parametrize("k_size,main_size,banked_size,cart_type", [ def test_banked(self):
carts = [
(32, 8, 8, 12), (32, 8, 8, 12),
(64, 8, 8, 13), (64, 8, 8, 13),
(64, 8, 8, 67), (64, 8, 8, 67),
@ -42,16 +43,16 @@ class TestAtariCart:
(256, 8, 8, 23), (256, 8, 8, 23),
(512, 8, 8, 24), (512, 8, 8, 24),
(1024, 8, 8, 25), (1024, 8, 8, 25),
]) ]
def test_banked(self, k_size, main_size, banked_size, cart_type): for k_size, main_size, banked_size, cart_type in carts:
data = self.get_cart(k_size, cart_type) data = self.get_cart(k_size, cart_type)
rawdata = SegmentData(data) rawdata = SegmentData(data)
image = AtariCartImage(rawdata, cart_type) image = AtariCartImage(rawdata, cart_type)
image.parse_segments() image.parse_segments()
assert len(image.segments) == 1 + 1 + (k_size - main_size) //banked_size assert len(image.segments) == 1 + 1 + (k_size - main_size) //banked_size
assert len(image.segments[0]) == 16 assert len(image.segments[0]) == 16
assert len(image.segments[1]) == main_size * 1024 assert len(image.segments[1]) == main_size * 1024
assert len(image.segments[2]) == banked_size * 1024 assert len(image.segments[2]) == banked_size * 1024
def test_bad(self): def test_bad(self):
k_size = 32 k_size = 32
@ -59,68 +60,22 @@ class TestAtariCart:
# check for error because invalid data in cart image itself # check for error because invalid data in cart image itself
data = self.get_cart(k_size, 1337) data = self.get_cart(k_size, 1337)
rawdata = SegmentData(data) rawdata = SegmentData(data)
with pytest.raises(errors.InvalidDiskImage): with pytest.raises(InvalidDiskImage):
image = AtariCartImage(rawdata, 1337) image = AtariCartImage(rawdata, 1337)
with pytest.raises(errors.InvalidDiskImage): with pytest.raises(InvalidDiskImage):
image = AtariCartImage(rawdata, 12) image = AtariCartImage(rawdata, 12)
# check for error with valid cart image, but invalid cart type supplied # check for error with valid cart image, but invalid cart type supplied
# to the image parser # to the image parser
data = self.get_cart(k_size, 12) data = self.get_cart(k_size, 12)
rawdata = SegmentData(data) rawdata = SegmentData(data)
with pytest.raises(errors.InvalidDiskImage): with pytest.raises(InvalidDiskImage):
image = AtariCartImage(rawdata, 1337) image = AtariCartImage(rawdata, 1337)
class TestRomCart:
def setup(self):
pass
def get_rom(self, k_size):
data = np.zeros((k_size * 1024), dtype=np.uint8)
return data
@pytest.mark.parametrize("k_size", [1, 2, 4, 8, 16, 32, 64])
def test_typical_rom_sizes(self, k_size):
data = self.get_rom(k_size)
rawdata = SegmentData(data)
rom_image = RomImage(rawdata)
rom_image.strict_check()
rom_image.parse_segments()
assert len(rom_image.segments) == 1
assert len(rom_image.segments[0]) == k_size * 1024
@pytest.mark.parametrize("k_size", [1, 2, 4, 8, 16, 32, 64])
def test_invalid_rom_sizes(self, k_size):
data = np.zeros((k_size * 1024) + 17, dtype=np.uint8)
rawdata = SegmentData(data)
with pytest.raises(errors.InvalidDiskImage):
rom_image = RomImage(rawdata)
@pytest.mark.parametrize("cart", known_cart_types)
def test_conversion_to_atari_cart(self, cart):
cart_type = cart[0]
name = cart[1]
k_size = cart[2]
if "Bounty" in name:
return
data = self.get_rom(k_size)
rawdata = SegmentData(data)
rom_image = RomImage(rawdata)
rom_image.strict_check()
rom_image.parse_segments()
new_cart_image = AtariCartImage(rawdata, cart_type)
new_cart_image.relaxed_check()
new_cart_image.parse_segments()
assert new_cart_image.header.valid
s = new_cart_image.create_emulator_boot_segment()
assert len(s) == len(rawdata) + new_cart_image.header.nominal_length
assert s[0:4].tobytes() == b'CART'
assert s[4:8].view(dtype=">u4") == cart_type
if __name__ == "__main__": if __name__ == "__main__":
from atrcopy.parsers import mime_parse_order
print("\n".join(mime_parse_order)) print("\n".join(mime_parse_order))
t = TestAtariCart() t = TestAtariCart()

View File

@ -1,41 +0,0 @@
from __future__ import print_function
from builtins import object
import numpy as np
from mock import *
from atrcopy import SegmentData, iter_parsers
from atrcopy import errors
class BaseContainerTest:
base_path = None
expected_mime = ""
@pytest.mark.parametrize("ext", ['.gz', '.bz2', '.xz', '.dcm'])
def test_container(self, ext):
pathname = self.base_path + ext
try:
sample_data = np.fromfile(pathname, dtype=np.uint8)
except OSError:
pass
else:
rawdata = SegmentData(sample_data.copy())
mime, parser = iter_parsers(rawdata)
assert mime == self.expected_mime
assert len(parser.image.files) == self.num_files_in_sample
class TestContainerAtariDosSDImage(BaseContainerTest):
base_path = "../test_data/container_dos_sd_test1.atr"
expected_mime = "application/vnd.atari8bit.atr"
num_files_in_sample = 5
class TestContainerAtariDosEDImage(BaseContainerTest):
base_path = "../test_data/container_dos_ed_test1.atr"
expected_mime = "application/vnd.atari8bit.atr"
num_files_in_sample = 5
class TestContainerAtariDosDDImage(BaseContainerTest):
base_path = "../test_data/container_dos_dd_test1.atr"
expected_mime = "application/vnd.atari8bit.atr"
num_files_in_sample = 5

View File

@ -4,8 +4,8 @@ import numpy as np
from mock import * from mock import *
from atrcopy import SegmentData, AtariDosDiskImage, Dos33DiskImage, DefaultSegment from atrcopy import SegmentData, AtariDosDiskImage, Dos33DiskImage,InvalidBinaryFile, DefaultSegment
from atrcopy import errors from atrcopy.errors import *
def get_image(file_name, diskimage_type): def get_image(file_name, diskimage_type):
@ -15,7 +15,7 @@ def get_image(file_name, diskimage_type):
return image return image
class BaseCreateTest: class BaseCreateTest(object):
diskimage_type = None diskimage_type = None
def get_exe_segments(self): def get_exe_segments(self):
@ -39,11 +39,11 @@ class BaseCreateTest:
image = get_image(sample_file, diskimage_type) image = get_image(sample_file, diskimage_type)
segments = self.get_exe_segments() segments = self.get_exe_segments()
try: try:
_ = issubclass(errors.AtrError, expected) _ = issubclass(AtrError, expected)
with pytest.raises(errors.InvalidBinaryFile) as e: with pytest.raises(InvalidBinaryFile) as e:
file_data, filetype = image.create_executable_file_image(sample_file, segments, run_addr) file_data, filetype = image.create_executable_file_image(segments, run_addr)
except TypeError: except TypeError:
file_data, filetype = image.create_executable_file_image(sample_file, segments, run_addr) file_data, filetype = image.create_executable_file_image(segments, run_addr)
print(image) print(image)
print(file_data, filetype) print(file_data, filetype)
assert len(file_data) == expected assert len(file_data) == expected
@ -53,11 +53,11 @@ class TestAtariDosSDImage(BaseCreateTest):
diskimage_type = AtariDosDiskImage diskimage_type = AtariDosDiskImage
@pytest.mark.parametrize("run_addr,expected", [ @pytest.mark.parametrize("run_addr,expected", [
(0x2000, errors.InvalidBinaryFile), (0x2000, InvalidBinaryFile),
(None, (2 + 6 + (4 + 0x1000) + (4 + 0x1000))), (None, (2 + 6 + (4 + 0x1000) + (4 + 0x1000))),
(0x4000, (2 + 6 + (4 + 0x1000) + (4 + 0x1000))), (0x4000, (2 + 6 + (4 + 0x1000) + (4 + 0x1000))),
(0x8000, (2 + 6 + (4 + 0x1000) + (4 + 0x1000))), (0x8000, (2 + 6 + (4 + 0x1000) + (4 + 0x1000))),
(0xffff, errors.InvalidBinaryFile), (0xffff, InvalidBinaryFile),
]) ])
def test_exe(self, run_addr, expected, sample_file): def test_exe(self, run_addr, expected, sample_file):
self.check_exe(sample_file, self.diskimage_type, run_addr, expected) self.check_exe(sample_file, self.diskimage_type, run_addr, expected)
@ -68,11 +68,11 @@ class TestDos33Image(BaseCreateTest):
diskimage_type = Dos33DiskImage diskimage_type = Dos33DiskImage
@pytest.mark.parametrize("run_addr,expected", [ @pytest.mark.parametrize("run_addr,expected", [
(0x2000, errors.InvalidBinaryFile), (0x2000, InvalidBinaryFile),
(None, (4 + (0x9000 - 0x4000))), (None, (4 + (0x9000 - 0x4000))),
(0x4000, (4 + (0x9000 - 0x4000))), (0x4000, (4 + (0x9000 - 0x4000))),
(0x8000, (4 + 3 + (0x9000 - 0x4000))), (0x8000, (4 + 3 + (0x9000 - 0x4000))),
(0xffff, errors.InvalidBinaryFile), (0xffff, InvalidBinaryFile),
]) ])
def test_exe(self, run_addr, expected, sample_file): def test_exe(self, run_addr, expected, sample_file):
self.check_exe(sample_file, self.diskimage_type, run_addr, expected) self.check_exe(sample_file, self.diskimage_type, run_addr, expected)

View File

@ -12,7 +12,7 @@ import numpy as np
from atrcopy import DefaultSegment, SegmentData from atrcopy import DefaultSegment, SegmentData
class TestJsonPickle: class TestJsonPickle(object):
def setup(self): def setup(self):
data = np.arange(2048, dtype=np.uint8) data = np.arange(2048, dtype=np.uint8)
self.segment = DefaultSegment(SegmentData(data)) self.segment = DefaultSegment(SegmentData(data))

View File

@ -10,7 +10,7 @@ from mock import *
from atrcopy import SegmentData, KBootImage, add_xexboot_header, add_atr_header from atrcopy import SegmentData, KBootImage, add_xexboot_header, add_atr_header
class TestKbootHeader: class TestKbootHeader(object):
def setup(self): def setup(self):
pass pass

View File

@ -8,7 +8,7 @@ import numpy as np
import pytest import pytest
from atrcopy import DefaultSegment, SegmentData, get_xex, interleave_segments, user_bit_mask, diff_bit_mask from atrcopy import DefaultSegment, SegmentData, get_xex, interleave_segments, user_bit_mask, diff_bit_mask
from atrcopy import errors from atrcopy.errors import *
from functools import reduce from functools import reduce
@ -18,7 +18,7 @@ def get_indexed(segment, num, scale):
s = DefaultSegment(raw, segment.origin + indexes[0]) s = DefaultSegment(raw, segment.origin + indexes[0])
return s, indexes return s, indexes
class TestSegment1: class TestSegment1(object):
def setup(self): def setup(self):
self.segments = [] self.segments = []
for i in range(8): for i in range(8):
@ -38,7 +38,7 @@ class TestSegment1:
s[1].set_comment_at(10, "comment 10") s[1].set_comment_at(10, "comment 10")
s[1].set_comment_at(100, "comment 100") s[1].set_comment_at(100, "comment 100")
print(list(s[1].iter_comments_in_segment())) print(list(s[1].iter_comments_in_segment()))
with pytest.raises(errors.InvalidBinaryFile): with pytest.raises(InvalidBinaryFile):
seg, subseg = get_xex(s, 0xbeef) seg, subseg = get_xex(s, 0xbeef)
seg, subseg = get_xex(s) seg, subseg = get_xex(s)
assert tuple(seg.data[0:2]) == (0xff, 0xff) assert tuple(seg.data[0:2]) == (0xff, 0xff)
@ -68,7 +68,7 @@ class TestSegment1:
assert not np.all((c.data[:] - s.data[:]) == 0) assert not np.all((c.data[:] - s.data[:]) == 0)
class TestIndexed: class TestIndexed(object):
def setup(self): def setup(self):
data = np.arange(4096, dtype=np.uint8) data = np.arange(4096, dtype=np.uint8)
data[1::2] = np.repeat(np.arange(16, dtype=np.uint8), 128) data[1::2] = np.repeat(np.arange(16, dtype=np.uint8), 128)
@ -242,7 +242,7 @@ class TestIndexed:
assert not np.all((c.data[:] - s.data[:]) == 0) assert not np.all((c.data[:] - s.data[:]) == 0)
class TestComments: class TestComments(object):
def setup(self): def setup(self):
data = np.ones([4000], dtype=np.uint8) data = np.ones([4000], dtype=np.uint8)
r = SegmentData(data) r = SegmentData(data)
@ -392,7 +392,7 @@ class TestComments:
assert set(item1[3].values()) == set(item2[3].values()) assert set(item1[3].values()) == set(item2[3].values())
class TestResize: class TestResize(object):
def setup(self): def setup(self):
data = np.arange(4096, dtype=np.uint8) data = np.arange(4096, dtype=np.uint8)
data[1::2] = np.repeat(np.arange(16, dtype=np.uint8), 128) data[1::2] = np.repeat(np.arange(16, dtype=np.uint8), 128)

View File

@ -10,7 +10,7 @@ import pytest
from atrcopy import DefaultSegment, SegmentData, get_xex, interleave_segments from atrcopy import DefaultSegment, SegmentData, get_xex, interleave_segments
class TestSegment: class TestSegment(object):
def setup(self): def setup(self):
data = np.ones([4000], dtype=np.uint8) data = np.ones([4000], dtype=np.uint8)
r = SegmentData(data) r = SegmentData(data)
@ -47,15 +47,15 @@ class TestSegment:
s.set_user_data([r], 4, 99) s.set_user_data([r], 4, 99)
out = dict() out = dict()
s.serialize_session(out) s.serialize_extra_to_dict(out)
print("saved", out) print("saved", out)
data = np.ones([4000], dtype=np.uint8) data = np.ones([4000], dtype=np.uint8)
r = SegmentData(data) r = SegmentData(data)
s2 = DefaultSegment(r, 0) s2 = DefaultSegment(r, 0)
s2.restore_session(out) s2.restore_extra_from_dict(out)
out2 = dict() out2 = dict()
s2.serialize_session(out2) s2.serialize_extra_to_dict(out2)
print("loaded", out2) print("loaded", out2)
assert out == out2 assert out == out2

View File

@ -3,7 +3,7 @@ from mock import *
from atrcopy import utils from atrcopy import utils
class TestTextToInt: class TestTextToInt(object):
def setup(self): def setup(self):
pass pass

Binary file not shown.