mirror of
https://github.com/rkujawa/rk65c02.git
synced 2025-04-09 12:38:19 +00:00
Merge branch 'master' into feature-jit-lightning
This commit is contained in:
commit
ed7a89b6eb
687
LICENSE
687
LICENSE
@ -1,21 +1,674 @@
|
||||
MIT License
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (c) 2017 Radosław Kujawa
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
|
26
README.md
26
README.md
@ -1,5 +1,27 @@
|
||||
# rk65c02
|
||||
65C02 code interpreter/emulator/disassembler (work in progress)
|
||||
65C02 code interpreter/emulator/disassembler.
|
||||
|
||||

|
||||

|
||||
|
||||
This project provides a library implementing a farily complete
|
||||
emulator of WDC 65C02S CPU. It does not aim to be cycle-exact emulator, but
|
||||
otherwise it tries to mimic behaviour of 65C02S as close as possible.
|
||||
Currently, the following features are implemented:
|
||||
- Emulation of all opcodes, including WDC extensions and BCD mode.
|
||||
- 16-bit address space.
|
||||
- Minimal support for interrupts.
|
||||
|
||||
The following notable features are missing:
|
||||
- Ability to execute callbacks in software utilizing this library.
|
||||
- Just-in-Time translation.
|
||||
|
||||
The only external dependencies (besides standard C library) are Boehm GC and
|
||||
uthash.
|
||||
On Fedora these can be installed with `gc-devel` and `uthash-devel` packages.
|
||||
|
||||
If you want to build tests, `kyua` quality assurance toolkit, `atf` testing
|
||||
framework and a recent snapshot (1.8f or newer) of `vasm` assembler (6502
|
||||
with std syntax) are also necessary.
|
||||
|
||||
[](https://forthebadge.com)
|
||||
|
||||
|
37
examples/Makefile
Normal file
37
examples/Makefile
Normal file
@ -0,0 +1,37 @@
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
CFLAGS=-Wall -pedantic -I../src -g
|
||||
LDFLAGS=-lgc
|
||||
|
||||
LDFLAGS_MACOSX=-L/opt/local/lib
|
||||
CFLAGS_MACOSX=-I/opt/local/include
|
||||
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
CFLAGS+=$(CFLAGS_MACOSX)
|
||||
LDFLAGS+=$(LDFLAGS_MACOSX)
|
||||
endif
|
||||
|
||||
RK6502LIB=../src/librk65c02.a
|
||||
VASM=vasm6502_std
|
||||
VASMFLAGS=-Fbin -wdc02
|
||||
|
||||
EXAMPLES=min3 mul_8bit_to_8bits
|
||||
EXAMPLES_ROMS:=$(addsuffix .rom,$(basename $(wildcard *.s)))
|
||||
|
||||
all : $(EXAMPLES) $(EXAMPLES_ROMS)
|
||||
|
||||
min3 : min3.o $(RK6502LIB)
|
||||
$(CC) -o $@ $(LDFLAGS) $< $(RK6502LIB)
|
||||
|
||||
mul_8bit_to_8bits : mul_8bit_to_8bits.o $(RK6502LIB)
|
||||
$(CC) -o $@ $(LDFLAGS) $< $(RK6502LIB)
|
||||
|
||||
%.rom : %.s
|
||||
$(VASM) $(VASMFLAGS) -o $@ $<
|
||||
|
||||
%.o : %.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
clean :
|
||||
rm -f *.o
|
||||
rm -f $(EXAMPLES) $(EXAMPLES_ROMS)
|
||||
|
33
examples/min3.c
Normal file
33
examples/min3.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "rk65c02.h"
|
||||
#include "bus.h"
|
||||
#include "log.h"
|
||||
#include "instruction.h"
|
||||
|
||||
static const uint16_t load_addr = 0xC000;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint8_t a, b, c;
|
||||
uint8_t min;
|
||||
|
||||
rk65c02emu_t e;
|
||||
|
||||
e = rk65c02_load_rom("min3.rom", load_addr, NULL);
|
||||
|
||||
e.regs.SP = 0xFF;
|
||||
e.regs.PC = load_addr;
|
||||
a = 5; b = 9; c = 4;
|
||||
|
||||
stack_push(&e, a);
|
||||
stack_push(&e, b);
|
||||
stack_push(&e, c);
|
||||
|
||||
rk65c02_start(&e);
|
||||
|
||||
min = stack_pop(&e);
|
||||
printf("Min is: %d\n", min);
|
||||
}
|
||||
|
32
examples/min3.s
Normal file
32
examples/min3.s
Normal file
@ -0,0 +1,32 @@
|
||||
.org 0xC000
|
||||
start: jsr min3
|
||||
stp
|
||||
|
||||
; min3
|
||||
; Takes 3 numbers (A, B, C), passed on stack, finds the minimum.
|
||||
; Result is also passed on stack. Assumes it is being called via jsr.
|
||||
.set retl,0x10
|
||||
.set reth,0x11
|
||||
.set res,0x12
|
||||
min3: pla ; pull low byte of return address
|
||||
sta retl
|
||||
pla
|
||||
sta reth
|
||||
pla ; pull C from stack
|
||||
sta res ; save C into res
|
||||
pla ; pull B from stack
|
||||
cmp res ; compare B and C
|
||||
bpl bltc ; branch if B > C
|
||||
sta res ; if C is smaller, save it to res
|
||||
bltc: pla ; pull A from stack
|
||||
cmp res ; compare A and whatever is in res
|
||||
bpl ret ; branch if A > res
|
||||
sta res ; otherwise save A to res
|
||||
ret: lda res ; load res into accumulator
|
||||
pha ; save to the stack
|
||||
lda reth ; restore return address
|
||||
pha
|
||||
lda retl
|
||||
pha
|
||||
rts ; return from function
|
||||
|
32
examples/mul_8bit_to_8bits.c
Normal file
32
examples/mul_8bit_to_8bits.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "rk65c02.h"
|
||||
#include "bus.h"
|
||||
#include "log.h"
|
||||
#include "instruction.h"
|
||||
|
||||
static const uint16_t load_addr = 0xC000;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uint8_t num1, num2;
|
||||
uint8_t res;
|
||||
|
||||
rk65c02emu_t e;
|
||||
|
||||
e = rk65c02_load_rom("mul_8bit_to_8bits.rom", load_addr, NULL);
|
||||
|
||||
e.regs.SP = 0xFF;
|
||||
e.regs.PC = load_addr;
|
||||
num1 = 4; num2 = 8;
|
||||
|
||||
stack_push(&e, num1);
|
||||
stack_push(&e, num2);
|
||||
|
||||
rk65c02_start(&e);
|
||||
|
||||
res = stack_pop(&e);
|
||||
printf("Result of multiplication: %d\n", res);
|
||||
}
|
||||
|
50
examples/mul_8bit_to_8bits.s
Normal file
50
examples/mul_8bit_to_8bits.s
Normal file
@ -0,0 +1,50 @@
|
||||
.org 0xC000
|
||||
start: jsr mul_8bit_to_8bits
|
||||
stp
|
||||
|
||||
; mul_8bit_to_8bits
|
||||
; Multiplies 2 numbers (passed on stack) and returns result on stack.
|
||||
|
||||
; General 8bit * 8bit = 8bit multiply
|
||||
; by White Flame 20030207
|
||||
; adapted as rk65c02 example by rkujawa
|
||||
|
||||
; Instead of using a bit counter, this routine early-exits when num2 reaches
|
||||
; zero, thus saving iterations.
|
||||
|
||||
; .X and .Y are preserved
|
||||
; num1 and num2 get clobbered
|
||||
.set num1,0x10
|
||||
.set num2,0x11
|
||||
.set retl,0x12
|
||||
.set reth,0x13
|
||||
|
||||
mul_8bit_to_8bits:
|
||||
pla ; pull return address
|
||||
sta retl
|
||||
pla
|
||||
sta reth
|
||||
pla ; pull num1 from stack
|
||||
sta num1
|
||||
pla ; pull num2 from stack
|
||||
sta num2
|
||||
|
||||
lda #0x00
|
||||
beq enterl
|
||||
doAdd: clc
|
||||
adc num1
|
||||
loop: asl num1
|
||||
; For an accumulating multiply (A = A + num1 * num2),
|
||||
; set up num1 and num2, then enter here.
|
||||
enterl: lsr num2
|
||||
bcs doAdd
|
||||
bne loop
|
||||
end:
|
||||
pha ; save result to stack
|
||||
lda reth ; restore return address
|
||||
pha
|
||||
lda retl
|
||||
pha
|
||||
rts ; return from function
|
||||
|
||||
|
BIN
res/rk65c02.png
Normal file
BIN
res/rk65c02.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
BIN
res/rk65c02_small.png
Normal file
BIN
res/rk65c02_small.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
120
src/65c02isa.csv
120
src/65c02isa.csv
@ -1,8 +1,8 @@
|
||||
opcode_id,mnemonic,addressing,size,emulation,modify_pc
|
||||
OP_BRK,"brk",IMPLIED,2,emul_brk,true
|
||||
OP_ORA_IZPX,"ora",IZPX,2,emul_ora,false
|
||||
OP_NOPI_3,"invalid",IMMEDIATE,2,NULL,false
|
||||
OP_NOPI_4,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_3,"invalid",IMMEDIATE,2,emul_invalid,false
|
||||
OP_NOPI_4,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_TSB_ZP,"tsb",ZP,2,emul_tsb,false
|
||||
OP_ORA_ZP,"ora",ZP,2,emul_ora,false
|
||||
OP_ASL_ZP,"asl",ZP,2,emul_asl,false
|
||||
@ -10,15 +10,15 @@ OP_RMB0_ZP,"rmb0",ZP,2,emul_rmb0,false
|
||||
OP_PHP,"php",IMPLIED,1,emul_php,false
|
||||
OP_ORA_IMM,"ora",IMMEDIATE,2,emul_ora,false
|
||||
OP_ASL,"asl",ACCUMULATOR,1,emul_asl,false
|
||||
OP_NOPI_C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_TSB_ABS,"tsb",ABSOLUTE,3,emul_tsb,false
|
||||
OP_ORA_ABS,"ora",ABSOLUTE,3,emul_ora,false
|
||||
OP_ASL_ABS,"asl",ABSOLUTE,3,emul_asl,false
|
||||
OP_BBR0_REL,"bbr0",ZPR,2,emul_bbr0,true
|
||||
OP_BBR0_REL,"bbr0",ZPR,3,emul_bbr0,true
|
||||
OP_BPL_REL,"bpl",RELATIVE,2,emul_bpl,true
|
||||
OP_ORA_IZPY,"ora",IZPY,2,emul_ora,false
|
||||
OP_ORA_IZP,"ora",IZP,2,emul_ora,false
|
||||
OP_NOPI_14,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_14,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_TRB_ZP,"trb",ZP,2,emul_trb,false
|
||||
OP_ORA_ZPX,"ora",ZPX,2,emul_ora,false
|
||||
OP_ASL_ZPX,"asl",ZPX,2,emul_asl,false
|
||||
@ -26,15 +26,15 @@ OP_RMB1_ZP,"rmb1",ZP,2,emul_rmb1,false
|
||||
OP_CLC,"clc",IMPLIED,1,emul_clc,false
|
||||
OP_ORA_ABSY,"ora",ABSOLUTEY,3,emul_ora,false
|
||||
OP_INC,"inc",ACCUMULATOR,1,emul_inc,false
|
||||
OP_NOPI_1C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_1C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_TRB_ABS,"trb",ABSOLUTE,3,emul_trb,false
|
||||
OP_ORA_ABSX,"ora",ABSOLUTEX,3,emul_ora,false
|
||||
OP_ASL_ABSX,"asl",ABSOLUTEX,3,emul_asl,false
|
||||
OP_BBR1_REL,"bbr1",ZPR,2,emul_bbr1,true
|
||||
OP_BBR1_REL,"bbr1",ZPR,3,emul_bbr1,true
|
||||
OP_JSR,"jsr",ABSOLUTE,3,emul_jsr,true
|
||||
OP_AND_IZPX,"and",IZPX,2,emul_and,false
|
||||
OP_NOPI_23,"invalid",IMMEDIATE,2,NULL,false
|
||||
OP_NOPI_24,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_23,"invalid",IMMEDIATE,2,emul_invalid,false
|
||||
OP_NOPI_24,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_BIT_ZP,"bit",ZP,2,emul_bit,false
|
||||
OP_AND_ZP,"and",ZP,2,emul_and,false
|
||||
OP_ROL_ZP,"rol",ZP,2,emul_rol,false
|
||||
@ -42,15 +42,15 @@ OP_RMB2_ZP,"rmb2",ZP,2,emul_rmb2,false
|
||||
OP_PLP,"plp",IMPLIED,1,emul_plp,false
|
||||
OP_AND_IMM,"and",IMMEDIATE,2,emul_and,false
|
||||
OP_ROL,"rol",ACCUMULATOR,1,emul_rol,false
|
||||
OP_NOPI_2C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_2C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_BIT_ABS,"bit",ABSOLUTE,3,emul_bit,false
|
||||
OP_AND_ABS,"and",ABSOLUTE,3,emul_and,false
|
||||
OP_ROL_ABS,"rol",ABSOLUTE,3,emul_rol,false
|
||||
OP_BBR2_REL,"bbr2",ZPR,2,emul_bbr2,true
|
||||
OP_BBR2_REL,"bbr2",ZPR,3,emul_bbr2,true
|
||||
OP_BMI_REL,"bmi",RELATIVE,2,emul_bmi,true
|
||||
OP_AND_IZPY,"and",IZPY,2,emul_and,false
|
||||
OP_AND_IZP,"and",IZP,2,emul_and,false
|
||||
OP_NOPI_34,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_34,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_BIT_ZPX,"bit",ZPX,2,emul_bit,false
|
||||
OP_AND_ZPX,"and",ZPX,2,emul_and,false
|
||||
OP_ROL_ZPX,"rol",ZPX,2,emul_rol,false
|
||||
@ -58,47 +58,47 @@ OP_RMB3_ZP,"rmb3",ZP,2,emul_rmb3,false
|
||||
OP_SEC,"sec",IMPLIED,1,emul_sec,false
|
||||
OP_AND_ABSY,"and",ABSOLUTEY,3,emul_and,false
|
||||
OP_DEC,"dec",ACCUMULATOR,1,emul_dec,false
|
||||
OP_NOPI_3C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_3C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_BIT_ABSX,"bit",ABSOLUTEX,3,emul_bit,false
|
||||
OP_AND_ABSX,"and",ABSOLUTEX,3,emul_and,false
|
||||
OP_ROL_ABSX,"rol",ABSOLUTEX,3,emul_rol,false
|
||||
OP_BBR3_REL,"bbr3",ZPR,2,emul_bbr3,true
|
||||
OP_BBR3_REL,"bbr3",ZPR,3,emul_bbr3,true
|
||||
OP_RTI,"rti",IMPLIED,1,emul_rti,true
|
||||
OP_EOR_IZPX,"eor",IZPX,2,emul_eor,false
|
||||
OP_NOPI_43,"invalid",IMMEDIATE,2,NULL,false
|
||||
OP_NOPI_44,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_45,"invalid",ZP,2,NULL,false
|
||||
OP_NOPI_43,"invalid",IMMEDIATE,2,emul_invalid,false
|
||||
OP_NOPI_44,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_NOPI_45,"invalid",ZP,2,emul_invalid,false
|
||||
OP_EOR_ZP,"eor",ZP,2,emul_eor,false
|
||||
OP_LSR_ZP,"lsr",ZP,2,emul_lsr,false
|
||||
OP_RMB4_ZP,"rmb4",ZP,2,emul_rmb4,false
|
||||
OP_PHA,"pha",IMPLIED,1,emul_pha,false
|
||||
OP_EOR_IMM,"eor",IMMEDIATE,2,emul_eor,false
|
||||
OP_LSR,"lsr",ACCUMULATOR,1,emul_lsr,false
|
||||
OP_NOPI_4C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_4C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_JMP_ABS,"jmp",ABSOLUTE,3,emul_jmp,true
|
||||
OP_EOR_ABS,"eor",ABSOLUTE,3,emul_eor,false
|
||||
OP_LSR_ABS,"lsr",ABSOLUTE,3,emul_lsr,false
|
||||
OP_BBR4_REL,"bbr4",ZPR,2,emul_bbr4,true
|
||||
OP_BBR4_REL,"bbr4",ZPR,3,emul_bbr4,true
|
||||
OP_BVC_REL,"bvc",RELATIVE,2,emul_bvc,true
|
||||
OP_EOR_IZPY,"eor",IZPY,2,emul_eor,false
|
||||
OP_EOR_IZP,"eor",IZP,2,emul_eor,false
|
||||
OP_NOPI_54,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_55,"invalid",ZPX,2,NULL,false
|
||||
OP_NOPI_54,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_NOPI_55,"invalid",ZPX,2,emul_invalid,false
|
||||
OP_EOR_ZPX,"eor",ZPX,2,emul_eor,false
|
||||
OP_LSR_ZPX,"lsr",ZPX,2,emul_lsr,false
|
||||
OP_RMB5_ZP,"rmb5",ZP,2,emul_rmb5,false
|
||||
OP_CLI,"cli",IMPLIED,1,emul_cli,false
|
||||
OP_EOR_ABSY,"eor",ABSOLUTEY,3,emul_eor,false
|
||||
OP_PHY,"phy",IMPLIED,1,emul_phy,false
|
||||
OP_NOPI_5C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_5D,"invalid",ABSOLUTE,3,NULL,false
|
||||
OP_NOPI_5C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_NOPI_5D,"invalid",ABSOLUTE,3,emul_invalid,false
|
||||
OP_EOR_ABSX,"eor",ABSOLUTEX,3,emul_eor,false
|
||||
OP_LSR_ABSX,"lsr",ABSOLUTEX,3,emul_lsr,false
|
||||
OP_BBR5_REL,"bbr5",ZPR,2,emul_bbr5,true
|
||||
OP_BBR5_REL,"bbr5",ZPR,3,emul_bbr5,true
|
||||
OP_RTS,"rts",IMPLIED,1,emul_rts,false
|
||||
OP_ADC_IZPX,"adc",IZPX,2,emul_adc,false
|
||||
OP_NOPI_63,"invalid",IMMEDIATE,2,NULL,false
|
||||
OP_NOPI_64,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_63,"invalid",IMMEDIATE,2,emul_invalid,false
|
||||
OP_NOPI_64,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_STZ_ZP,"stz",ZP,2,emul_stz,false
|
||||
OP_ADC_ZP,"adc",ZP,2,emul_adc,false
|
||||
OP_ROR_ZP,"ror",ZP,2,emul_ror,false
|
||||
@ -106,15 +106,15 @@ OP_RMB6_ZP,"rmb6",ZP,2,emul_rmb6,false
|
||||
OP_PLA,"pla",IMPLIED,1,emul_pla,false
|
||||
OP_ADC_IMM,"adc",IMMEDIATE,2,emul_adc,false
|
||||
OP_ROR,"ror",ACCUMULATOR,1,emul_ror,false
|
||||
OP_NOPI_6C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_6C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_JMP_IABS,"jmp",IABSOLUTE,3,emul_jmp,true
|
||||
OP_ADC_ABS,"adc",ABSOLUTE,3,emul_adc,false
|
||||
OP_ROR_ABS,"ror",ABSOLUTE,3,emul_ror,false
|
||||
OP_BBR6_REL,"bbr6",ZPR,2,emul_bbr6,true
|
||||
OP_BBR6_REL,"bbr6",ZPR,3,emul_bbr6,true
|
||||
OP_BVS_REL,"bvs",RELATIVE,2,emul_bvs,true
|
||||
OP_ADC_IZPY,"adc",IZPY,2,emul_adc,false
|
||||
OP_ADC_IZP,"adc",IZP,2,emul_adc,false
|
||||
OP_NOPI_74,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_74,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_STZ_ZPX,"stz",ZPX,2,emul_stz,false
|
||||
OP_ADC_ZPX,"adc",ZPX,2,emul_adc,false
|
||||
OP_ROR_ZPX,"ror",ZPX,2,emul_ror,false
|
||||
@ -122,15 +122,15 @@ OP_RMB7_ZP,"rmb7",ZP,2,emul_rmb7,false
|
||||
OP_SEI,"sei",IMPLIED,1,emul_sei,false
|
||||
OP_ADC_ABSY,"adc",ABSOLUTEY,3,emul_adc,false
|
||||
OP_PLY,"ply",IMPLIED,1,emul_ply,false
|
||||
OP_NOPI_7C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_7C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_JMP_IABSX,"jmp",IABSOLUTEX,3,emul_jmp,true
|
||||
OP_ADC_ABSX,"adc",ABSOLUTEX,3,emul_adc,false
|
||||
OP_ROR_ABSX,"ror",ABSOLUTEX,3,emul_ror,false
|
||||
OP_BBR7_REL,"bbr7",ZPR,2,emul_bbr7,true
|
||||
OP_BBR7_REL,"bbr7",ZPR,3,emul_bbr7,true
|
||||
OP_BRA_REL,"bra",RELATIVE,2,emul_bra,true
|
||||
OP_STA_IZPX,"sta",IZPX,2,emul_sta,false
|
||||
OP_NOPI_83,"invalid",IMMEDIATE,2,NULL,false
|
||||
OP_NOPI_84,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_83,"invalid",IMMEDIATE,2,emul_invalid,false
|
||||
OP_NOPI_84,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_STY_ZP,"sty",ZP,2,emul_sty,false
|
||||
OP_STA_ZP,"sta",ZP,2,emul_sta,false
|
||||
OP_STX_ZP,"stx",ZP,2,emul_stx,false
|
||||
@ -138,15 +138,15 @@ OP_SMB0_ZP,"smb0",ZP,2,emul_smb0,false
|
||||
OP_DEY,"dey",IMPLIED,1,emul_dey,false
|
||||
OP_BIT_IMM,"bit",IMMEDIATE,2,emul_bit,false
|
||||
OP_TXA,"txa",IMPLIED,1,emul_txa,false
|
||||
OP_NOPI_8C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_8C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_STY_ABS,"sty",ABSOLUTE,3,emul_sty,false
|
||||
OP_STA_ABS,"sta",ABSOLUTE,3,emul_sta,false
|
||||
OP_STX_ABS,"stx",ABSOLUTE,3,emul_stx,false
|
||||
OP_BBS0_REL,"bbs0",ZPR,2,emul_bbs0,true
|
||||
OP_BBS0_REL,"bbs0",ZPR,3,emul_bbs0,true
|
||||
OP_BCC_REL,"bcc",RELATIVE,2,emul_bcc,true
|
||||
OP_STA_IZPY,"sta",IZPY,2,emul_sta,false
|
||||
OP_STA_IZP,"sta",IZP,2,emul_sta,false
|
||||
OP_NOPI_94,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_94,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_STY_ZPX,"sty",ZPX,2,emul_sty,false
|
||||
OP_STA_ZPX,"sta",ZPX,2,emul_sta,false
|
||||
OP_STX_ZPY,"stx",ZPY,2,emul_stx,false
|
||||
@ -154,15 +154,15 @@ OP_SMB1_ZP,"smb1",ZP,2,emul_smb1,false
|
||||
OP_TYA,"tya",IMPLIED,1,emul_tya,false
|
||||
OP_STA_ABSY,"sta",ABSOLUTEY,3,emul_sta,false
|
||||
OP_TXS,"txs",IMPLIED,1,emul_txs,false
|
||||
OP_NOPI_9C,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_9C,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_STZ_ABS,"stz",ABSOLUTE,3,emul_stz,false
|
||||
OP_STA_ABSX,"sta",ABSOLUTEX,3,emul_sta,false
|
||||
OP_STZ_ABSX,"stz",ABSOLUTEX,3,emul_stz,false
|
||||
OP_BBS1_REL,"bbs1",ZPR,2,emul_bbs1,true
|
||||
OP_BBS1_REL,"bbs1",ZPR,3,emul_bbs1,true
|
||||
OP_LDY_IMM,"ldy",IMMEDIATE,2,emul_ldy,false
|
||||
OP_LDA_IZPX,"lda",IZPX,2,emul_lda,false
|
||||
OP_LDX_IMM,"ldx",IMMEDIATE,2,emul_ldx,false
|
||||
OP_NOPI_A4,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_A4,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_LDY_ZP,"ldy",ZP,2,emul_ldy,false
|
||||
OP_LDA_ZP,"lda",ZP,2,emul_lda,false
|
||||
OP_LDX_ZP,"ldx",ZP,2,emul_ldx,false
|
||||
@ -170,15 +170,15 @@ OP_SMB2_ZP,"smb2",ZP,2,emul_smb2,false
|
||||
OP_TAY,"tay",IMPLIED,1,emul_tay,false
|
||||
OP_LDA_IMM,"lda",IMMEDIATE,2,emul_lda,false
|
||||
OP_TAX,"tax",IMPLIED,1,emul_tax,false
|
||||
OP_NOPI_AC,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_AC,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_LDY_ABS,"ldy",ABSOLUTE,3,emul_ldy,false
|
||||
OP_LDA_ABS,"lda",ABSOLUTE,3,emul_lda,false
|
||||
OP_LDX_ABS,"ldx",ABSOLUTE,3,emul_ldx,false
|
||||
OP_BBS2_REL,"bbs2",ZPR,2,emul_bbs2,true
|
||||
OP_BBS2_REL,"bbs2",ZPR,3,emul_bbs2,true
|
||||
OP_BCS_REL,"bcs",RELATIVE,2,emul_bcs,true
|
||||
OP_LDA_IZPY,"lda",IZPY,2,emul_lda,false
|
||||
OP_LDA_IZP,"lda",IZP,2,emul_lda,false
|
||||
OP_NOPI_B4,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_B4,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_LDY_ZPX,"ldy",ZPX,2,emul_ldy,false
|
||||
OP_LDA_ZPX,"lda",ZPX,2,emul_lda,false
|
||||
OP_LDX_ZPY,"ldx",ZPY,1,emul_ldx,false
|
||||
@ -186,15 +186,15 @@ OP_SMB3_ZP,"smb3",ZP,2,emul_smb3,false
|
||||
OP_CLV,"clv",IMPLIED,1,emul_clv,false
|
||||
OP_LDA_ABSY,"lda",ABSOLUTEY,3,emul_lda,false
|
||||
OP_TSX,"tsx",IMPLIED,1,emul_tsx,false
|
||||
OP_NOPI_BC,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_BC,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_LDY_ABSX,"ldy",ABSOLUTEX,3,emul_ldy,false
|
||||
OP_LDA_ABSX,"lda",ABSOLUTEX,3,emul_lda,false
|
||||
OP_LDX_ABSY,"ldx",ABSOLUTEY,3,emul_ldx,false
|
||||
OP_BBS3_REL,"bbs3",ZPR,2,emul_bbs3,true
|
||||
OP_BBS3_REL,"bbs3",ZPR,3,emul_bbs3,true
|
||||
OP_CPY_IMM,"cpy",IMMEDIATE,2,emul_cpy,false
|
||||
OP_CMP_IZPX,"cmp",IZPX,2,emul_cmp,false
|
||||
OP_NOPI_C3,"invalid",IMMEDIATE,2,NULL,false
|
||||
OP_NOPI_C4,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_C3,"invalid",IMMEDIATE,2,emul_invalid,false
|
||||
OP_NOPI_C4,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_CPY_ZP,"cpy",ZP,2,emul_cpy,false
|
||||
OP_CMP_ZP,"cmp",ZP,2,emul_cmp,false
|
||||
OP_DEC_ZP,"dec",ZP,2,emul_dec,false
|
||||
@ -206,12 +206,12 @@ OP_WAI,"wai",IMPLIED,1,emul_wai,false
|
||||
OP_CPY_ABS,"cpy",ABSOLUTE,3,emul_cpy,false
|
||||
OP_CMP_ABS,"cmp",ABSOLUTE,3,emul_cmp,false
|
||||
OP_DEC_ABS,"dec",ABSOLUTE,3,emul_dec,false
|
||||
OP_BBS4_REL,"bbs4",ZPR,2,emul_bbs4,true
|
||||
OP_BBS4_REL,"bbs4",ZPR,3,emul_bbs4,true
|
||||
OP_BNE_REL,"bne",RELATIVE,2,emul_bne,true
|
||||
OP_CMP_IZPY,"cmp",IZPY,2,emul_cmp,false
|
||||
OP_CMP_IZP,"cmp",IZP,2,emul_cmp,false
|
||||
OP_NOPI_D4,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_D5,"invalid",ZPX,2,NULL,false
|
||||
OP_NOPI_D4,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_NOPI_D5,"invalid",ZPX,2,emul_invalid,false
|
||||
OP_CMP_ZPX,"cmp",ZPX,2,emul_cmp,false
|
||||
OP_DEC_ZPX,"dec",ZPX,2,emul_dec,false
|
||||
OP_SMB5_ZP,"smb5",ZP,2,emul_smb5,false
|
||||
@ -219,14 +219,14 @@ OP_CLD,"cld",IMPLIED,1,emul_cld,false
|
||||
OP_CMP_ABSY,"cmp",ABSOLUTEY,3,emul_cmp,false
|
||||
OP_PHX,"phx",IMPLIED,1,emul_phx,false
|
||||
OP_STP,"stp",IMPLIED,1,emul_stp,false
|
||||
OP_NOPI_DD,"invalid",ABSOLUTE,3,NULL,false
|
||||
OP_NOPI_DD,"invalid",ABSOLUTE,3,emul_invalid,false
|
||||
OP_CMP_ABSX,"cmp",ABSOLUTEX,3,emul_cmp,false
|
||||
OP_DEC_ABSX,"dec",ABSOLUTEX,3,emul_dec,false
|
||||
OP_BBS5_REL,"bbs5",ZPR,2,emul_bbs5,true
|
||||
OP_BBS5_REL,"bbs5",ZPR,3,emul_bbs5,true
|
||||
OP_CPX_IMM,"cpx",IMMEDIATE,2,emul_cpx,false
|
||||
OP_SBC_IZPX,"sbc",IZPX,2,emul_sbc,false
|
||||
OP_NOPI_E3,"invalid",IMMEDIATE,2,NULL,false
|
||||
OP_NOPI_E4,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_E3,"invalid",IMMEDIATE,2,emul_invalid,false
|
||||
OP_NOPI_E4,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_CPX_ZP,"cpx",ZP,2,emul_cpx,false
|
||||
OP_SBC_ZP,"sbc",ZP,2,emul_sbc,false
|
||||
OP_INC_ZP,"inc",ZP,2,emul_inc,false
|
||||
@ -234,24 +234,24 @@ OP_SMB6_ZP,"smb6",ZP,2,emul_smb6,false
|
||||
OP_INX,"inx",IMPLIED,1,emul_inx,false
|
||||
OP_SBC_IMM,"sbc",IMMEDIATE,2,emul_sbc,false
|
||||
OP_NOP,"nop",IMPLIED,1,emul_nop,false
|
||||
OP_NOPI_EC,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_EC,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_CPX_ABS,"cpx",ABSOLUTE,3,emul_cpx,false
|
||||
OP_SBC_ABS,"sbc",ABSOLUTE,3,emul_sbc,false
|
||||
OP_INC_ABS,"inc",ABSOLUTE,3,emul_inc,false
|
||||
OP_BBS6_REL,"bbs6",ZPR,2,emul_bbs6,true
|
||||
OP_BBS6_REL,"bbs6",ZPR,3,emul_bbs6,true
|
||||
OP_BEQ_REL,"beq",RELATIVE,2,emul_beq,true
|
||||
OP_SBC_IZPY,"sbc",IZPY,2,emul_sbc,false
|
||||
OP_SBC_IZP,"sbc",IZP,2,emul_sbc,false
|
||||
OP_NOPI_F4,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_F5,"invalid",ZPX,2,NULL,false
|
||||
OP_NOPI_F4,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_NOPI_F5,"invalid",ZPX,2,emul_invalid,false
|
||||
OP_SBC_ZPX,"sbc",ZPX,2,emul_sbc,false
|
||||
OP_INC_ZPX,"inc",ZPX,2,emul_inc,false
|
||||
OP_SMB7_ZP,"smb7",ZP,2,emul_smb7,false
|
||||
OP_SED,"sed",IMPLIED,1,emul_sed,false
|
||||
OP_SBC_ABSY,"sbc",ABSOLUTEY,3,emul_sbc,false
|
||||
OP_PLX,"plx",IMPLIED,1,emul_plx,false
|
||||
OP_NOPI_FC,"invalid",IMPLIED,1,NULL,false
|
||||
OP_NOPI_FD,"invalid",ABSOLUTE,3,NULL,false
|
||||
OP_NOPI_FC,"invalid",IMPLIED,1,emul_invalid,false
|
||||
OP_NOPI_FD,"invalid",ABSOLUTE,3,emul_invalid,false
|
||||
OP_SBC_ABSX,"sbc",ABSOLUTEX,3,emul_sbc,false
|
||||
OP_INC_ABSX,"inc",ABSOLUTEX,3,emul_inc,false
|
||||
OP_BBS7_REL,"bbs7",ZPR,2,emul_bbs7,true
|
||||
OP_BBS7_REL,"bbs7",ZPR,3,emul_bbs7,true
|
||||
|
|
2482
src/Doxyfile
Normal file
2482
src/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
38
src/Makefile
38
src/Makefile
@ -1,26 +1,38 @@
|
||||
CLI=rk65c02cli
|
||||
CLI_OBJS=rk65c02cli.o
|
||||
# This needs fairly recent GNU Make.
|
||||
#
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o log.o assembler.o jit_lightning.o
|
||||
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
LIB_SO=librk65c02.dylib
|
||||
else
|
||||
LIB_SO=librk65c02.so
|
||||
endif
|
||||
|
||||
LIB_OBJS=rk65c02.o bus.o instruction.o emulation.o debug.o device_ram.o device_serial.o jit_lightning.o
|
||||
LIB_SO=librk65c02.so
|
||||
LIB_STATIC=librk65c02.a
|
||||
|
||||
LDFLAGS_SO=-shared
|
||||
LDFLAGS_CLI=-lreadline
|
||||
CFLAGS=-Wall -fpic -ggdb
|
||||
LDFLAGS=-shared -lgc
|
||||
LDFLAGS_MACOSX=-L/opt/local/lib
|
||||
CFLAGS=-Wall -fpic -ggdb -Og
|
||||
CFLAGS_MACOSX=-I/opt/local/include/uthash -I/opt/local/include
|
||||
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
CFLAGS+=$(CFLAGS_MACOSX)
|
||||
LDFLAGS+=$(LDFLAGS_MACOSX)
|
||||
endif
|
||||
|
||||
65C02ISA=65c02isa
|
||||
EMULATION=emulation
|
||||
DEVICE=device
|
||||
# TODO: better include handling
|
||||
|
||||
all : $(LIB_SO) $(LIB_STATIC) $(CLI)
|
||||
|
||||
$(CLI) : $(CLI_OBJS)
|
||||
$(CC) -o $(CLI) $(LDFLAGS_CLI) $(CLI_OBJS) $(LIB_STATIC)
|
||||
#$(CLI) : $(CLI_OBJS)
|
||||
# $(CC) -o $(CLI) $(LDFLAGS) $(CLI_OBJS) $(LIB_STATIC)
|
||||
|
||||
$(LIB_SO) : $(LIB_OBJS)
|
||||
$(CC) -o $(LIB_SO) $(LDFLAGS_SO) $(LIB_OBJS)
|
||||
$(CC) -o $(LIB_SO) $(LDFLAGS) $(LIB_OBJS)
|
||||
|
||||
$(LIB_STATIC) : $(LIB_OBJS)
|
||||
$(AR) rcs $(LIB_STATIC) $(LIB_OBJS)
|
||||
@ -37,6 +49,6 @@ $(EMULATION).h : $(65C02ISA).csv $(EMULATION).awk
|
||||
|
||||
clean :
|
||||
rm -f $(65C02ISA).h $(EMULATION).h
|
||||
rm -f $(LIB_OBJS) $(CLI_OBJS)
|
||||
rm -f $(LIB_SO) $(LIB_STATIC) $(CLI)
|
||||
rm -f $(LIB_OBJS) #$(CLI_OBJS)
|
||||
rm -f $(LIB_SO) $(LIB_STATIC) #$(CLI)
|
||||
|
||||
|
111
src/assembler.c
Normal file
111
src/assembler.c
Normal file
@ -0,0 +1,111 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*
|
||||
* rk65c02
|
||||
* Copyright (C) 2017-2021 Radoslaw Kujawa
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gc/gc.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "log.h"
|
||||
#include "assembler.h"
|
||||
#include "instruction.h"
|
||||
|
||||
assembler_t
|
||||
assemble_init(bus_t *b, uint16_t pc)
|
||||
{
|
||||
assembler_t asmblr;
|
||||
|
||||
asmblr.bus = b;
|
||||
asmblr.pc = pc;
|
||||
|
||||
return asmblr;
|
||||
}
|
||||
|
||||
bool
|
||||
assemble_single_implied(assembler_t *a, char *mnemonic)
|
||||
{
|
||||
return assemble_single(a, mnemonic, IMPLIED, 0, 0);
|
||||
}
|
||||
|
||||
bool
|
||||
assemble_single(assembler_t *a, char *mnemonic, addressing_t mode, uint8_t op1, uint8_t op2)
|
||||
{
|
||||
uint8_t *asmbuf;
|
||||
uint8_t bsize;
|
||||
bool rv;
|
||||
|
||||
rv = assemble_single_buf(&asmbuf, &bsize, mnemonic, mode, op1, op2);
|
||||
if (rv == false)
|
||||
return rv;
|
||||
|
||||
rv = bus_load_buf(a->bus, a->pc, asmbuf, bsize);
|
||||
a->pc += bsize;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool
|
||||
assemble_single_buf_implied(uint8_t **buf, uint8_t *bsize, char *mnemonic)
|
||||
{
|
||||
return assemble_single_buf(buf, bsize, mnemonic, IMPLIED, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
assemble_single_buf(uint8_t **buf, uint8_t *bsize, char *mnemonic, addressing_t mode, uint8_t op1, uint8_t op2)
|
||||
{
|
||||
instrdef_t id;
|
||||
uint8_t opcode;
|
||||
bool found;
|
||||
|
||||
opcode = 0;
|
||||
|
||||
found = instruction_opcode_by_mnemonic(mnemonic, mode, &opcode, &id);
|
||||
|
||||
if (!found) {
|
||||
rk65c02_log(LOG_ERROR,
|
||||
"Couldn't find opcode for mnemonic %s mode %x.",
|
||||
mnemonic, mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
*bsize = id.size;
|
||||
|
||||
*buf = GC_MALLOC(id.size);
|
||||
assert(*buf != NULL);
|
||||
|
||||
/* fill the buffer */
|
||||
memset(*buf, 0, id.size);
|
||||
(*buf)[0] = opcode;
|
||||
/* XXX */
|
||||
if (id.size > 1)
|
||||
(*buf)[1] = op1;
|
||||
if (id.size > 2)
|
||||
(*buf)[2] = op2;
|
||||
|
||||
return found;
|
||||
}
|
||||
|
22
src/assembler.h
Normal file
22
src/assembler.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef _ASSEMBLER_H_
|
||||
#define _ASSEMBLER_H_
|
||||
|
||||
#include "instruction.h"
|
||||
#include "rk65c02.h"
|
||||
|
||||
struct assembler {
|
||||
bus_t *bus;
|
||||
uint16_t pc;
|
||||
};
|
||||
|
||||
typedef struct assembler assembler_t;
|
||||
|
||||
bool assemble_single_buf_implied(uint8_t **, uint8_t *, char *);
|
||||
bool assemble_single_buf(uint8_t **, uint8_t *, char *, addressing_t, uint8_t, uint8_t);
|
||||
|
||||
assembler_t assemble_init(bus_t *, uint16_t);
|
||||
bool assemble_single(assembler_t *, char *, addressing_t, uint8_t, uint8_t);
|
||||
bool assemble_single_implied(assembler_t *, char *);
|
||||
|
||||
#endif /* _ASSEMBLER_H_ */
|
||||
|
75
src/bus.c
75
src/bus.c
@ -1,16 +1,38 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*
|
||||
* rk65c02
|
||||
* Copyright (C) 2017-2021 Radoslaw Kujawa
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <gc/gc.h>
|
||||
#include <utlist.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "device_ram.h"
|
||||
|
||||
@ -23,13 +45,23 @@ bus_device_add(bus_t *b, device_t *d, uint16_t addr)
|
||||
{
|
||||
device_mapping_t *dm;
|
||||
|
||||
dm = (device_mapping_t *) malloc(sizeof(device_mapping_t));
|
||||
if ((addr + d->size) > RK65C02_BUS_SIZE) {
|
||||
rk65c02_log(LOG_ERROR,
|
||||
"Bus mapping for %s at %x, size %x exceeding bus size.",
|
||||
d->name, addr, d->size);
|
||||
return;
|
||||
}
|
||||
|
||||
dm = (device_mapping_t *) GC_MALLOC(sizeof(device_mapping_t));
|
||||
assert(dm != NULL);
|
||||
|
||||
dm->dev = d;
|
||||
/* TODO: check if addr + size is not bigger than RK65C02_BUS_SIZE */
|
||||
dm->addr = addr;
|
||||
|
||||
LL_APPEND((b->dm_head), dm);
|
||||
|
||||
rk65c02_log(LOG_DEBUG, "Bus mapping added: %x device %s size %x.",
|
||||
addr, d->name, d->size);
|
||||
}
|
||||
|
||||
void
|
||||
@ -57,6 +89,7 @@ bus_access_device(bus_t *t, uint16_t addr, device_t **d, uint16_t *off)
|
||||
device_mapping_t *dm;
|
||||
device_t *dtmp;
|
||||
|
||||
doff = 0;
|
||||
*d = NULL;
|
||||
|
||||
LL_FOREACH(t->dm_head, dm) {
|
||||
@ -68,7 +101,7 @@ bus_access_device(bus_t *t, uint16_t addr, device_t **d, uint16_t *off)
|
||||
}
|
||||
|
||||
if (*d == NULL) {
|
||||
fprintf(stderr, "Hitting unmapped bus space @ %x!", addr);
|
||||
rk65c02_log(LOG_WARN, "Hitting unmapped bus space @ %x!", addr);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -85,12 +118,13 @@ bus_read_1(bus_t *t, uint16_t addr)
|
||||
bus_access_device(t, addr, &d, &off);
|
||||
|
||||
if (d == NULL)
|
||||
return 0xFF;
|
||||
return 0xFF; /* simulate floting pins */
|
||||
else
|
||||
val = d->read_1(d, off);
|
||||
|
||||
if (t->access_debug)
|
||||
printf("bus READ @ %x (off %x) value %x\n", addr, off, val);
|
||||
rk65c02_log(LOG_DEBUG, "bus READ @ %x (off %x) value %x\n",
|
||||
addr, off, val);
|
||||
|
||||
return val;
|
||||
}
|
||||
@ -101,10 +135,20 @@ bus_write_1(bus_t *t, uint16_t addr, uint8_t val)
|
||||
uint16_t off;
|
||||
device_t *d;
|
||||
|
||||
off = 0;
|
||||
|
||||
bus_access_device(t, addr, &d, &off);
|
||||
|
||||
if (d == NULL) {
|
||||
if (t->access_debug)
|
||||
rk65c02_log(LOG_DEBUG, "unmapped bus WRITE @ %x (off %x) value %x\n",
|
||||
addr, off, val);
|
||||
return;
|
||||
}
|
||||
|
||||
if (t->access_debug)
|
||||
printf("bus WRITE @ %x (off %x) value %x\n", addr, off, val);
|
||||
rk65c02_log(LOG_DEBUG, "bus WRITE @ %x (off %x) value %x\n",
|
||||
addr, off, val);
|
||||
|
||||
d->write_1(d, off, val);
|
||||
}
|
||||
@ -127,7 +171,7 @@ bus_init_with_default_devs()
|
||||
|
||||
t = bus_init();
|
||||
|
||||
bus_device_add(&t, device_ram_init(), 0x0);
|
||||
bus_device_add(&t, device_ram_init(0xDFFF), 0x0);
|
||||
|
||||
return t;
|
||||
}
|
||||
@ -139,7 +183,8 @@ bus_load_buf(bus_t *t, uint16_t addr, uint8_t *buf, uint16_t bufsize)
|
||||
|
||||
i = 0;
|
||||
|
||||
// XXX: add sanity checks
|
||||
assert(buf != NULL);
|
||||
assert(bufsize != 0);
|
||||
|
||||
while (i < bufsize) {
|
||||
bus_write_1(t, addr+i, buf[i]); // XXX: overflow addr
|
||||
@ -156,9 +201,12 @@ bus_load_file(bus_t *t, uint16_t addr, const char *filename)
|
||||
int fd;
|
||||
uint8_t data;
|
||||
|
||||
rk65c02_log(LOG_DEBUG, "Loading file %s at %x.", filename, addr);
|
||||
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror("Problem while trying to open file");
|
||||
rk65c02_log(LOG_ERROR, "Problem while trying to open file: %s",
|
||||
strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -174,8 +222,15 @@ bus_load_file(bus_t *t, uint16_t addr, const char *filename)
|
||||
void
|
||||
bus_finish(bus_t *t)
|
||||
{
|
||||
device_mapping_t *dm;
|
||||
device_t *d;
|
||||
|
||||
assert(t != NULL);
|
||||
|
||||
/* TODO: foreach devices free 'em */
|
||||
LL_FOREACH(t->dm_head, dm) {
|
||||
d = dm->dev;
|
||||
if ((d->finish) != NULL)
|
||||
d->finish(d);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,8 +18,8 @@ typedef struct bus_tag bus_t;
|
||||
|
||||
uint8_t bus_read_1(bus_t *, uint16_t);
|
||||
void bus_write_1(bus_t *, uint16_t, uint8_t);
|
||||
bus_t bus_init();
|
||||
bus_t bus_init_with_default_devs();
|
||||
bus_t bus_init(void);
|
||||
bus_t bus_init_with_default_devs(void);
|
||||
void bus_finish(bus_t *);
|
||||
bool bus_load_file(bus_t *, uint16_t, const char *);
|
||||
bool bus_load_buf(bus_t *, uint16_t, uint8_t *, uint16_t);
|
||||
|
40
src/debug.c
40
src/debug.c
@ -1,9 +1,30 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*
|
||||
* rk65c02
|
||||
* Copyright (C) 2017-2021 Radoslaw Kujawa
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <gc/gc.h>
|
||||
#include <utlist.h>
|
||||
|
||||
#include "rk65c02.h"
|
||||
#include "instruction.h"
|
||||
#include "log.h"
|
||||
#include "debug.h"
|
||||
|
||||
void
|
||||
@ -17,6 +38,8 @@ debug_trace_print_all(rk65c02emu_t *e)
|
||||
{
|
||||
trace_t *tr;
|
||||
instruction_t i;
|
||||
char *instrstr;
|
||||
char *regsstr;
|
||||
|
||||
if (e->trace_head == NULL)
|
||||
return;
|
||||
@ -25,11 +48,11 @@ debug_trace_print_all(rk65c02emu_t *e)
|
||||
i.opcode = tr->opcode;
|
||||
i.op1 = tr->op1;
|
||||
i.op2 = tr->op2;
|
||||
instrstr = instruction_string_get(&i);
|
||||
regsstr = rk65c02_regs_string_get(tr->regs);
|
||||
|
||||
printf("TRACE %X:\t", tr->address);
|
||||
instruction_print(&i);
|
||||
printf("\t");
|
||||
rk65c02_dump_regs(tr->regs);
|
||||
rk65c02_log(LOG_TRACE, "%X: %s\t%s", tr->address, instrstr,
|
||||
regsstr);
|
||||
}
|
||||
|
||||
}
|
||||
@ -40,11 +63,8 @@ debug_trace_savestate(rk65c02emu_t *e, uint16_t address, instrdef_t *id,
|
||||
{
|
||||
trace_t *tr;
|
||||
|
||||
tr = (trace_t *) malloc(sizeof(trace_t));
|
||||
if (tr == NULL) {
|
||||
fprintf(stderr, "Error allocating trace structure.\n");
|
||||
return;
|
||||
}
|
||||
tr = (trace_t *) GC_MALLOC(sizeof(trace_t));
|
||||
assert(tr != NULL);
|
||||
|
||||
tr->address = address;
|
||||
|
||||
@ -80,7 +100,7 @@ debug_breakpoint_add(rk65c02emu_t *e, uint16_t address)
|
||||
{
|
||||
breakpoint_t *bp;
|
||||
|
||||
bp = (breakpoint_t *) malloc(sizeof(breakpoint_t));
|
||||
bp = (breakpoint_t *) GC_MALLOC(sizeof(breakpoint_t));
|
||||
if (bp == NULL)
|
||||
return false;
|
||||
|
||||
|
@ -8,6 +8,7 @@ typedef struct device_t {
|
||||
|
||||
uint8_t (*read_1)(void *, uint16_t doff);
|
||||
void (*write_1)(void *, uint16_t, uint8_t val);
|
||||
void (*finish)(void *);
|
||||
|
||||
void *config;
|
||||
void *aux; /* any dev space-specific data */
|
||||
|
@ -1,13 +1,31 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*
|
||||
* rk65c02
|
||||
* Copyright (C) 2017-2021 Radoslaw Kujawa
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gc/gc.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "device.h"
|
||||
|
||||
#define RAM_SIZE 0xDFFF /* should be configurable */
|
||||
|
||||
uint8_t device_ram_read_1(void *, uint16_t);
|
||||
void device_ram_write_1(void *, uint16_t, uint8_t);
|
||||
|
||||
@ -36,29 +54,26 @@ device_ram_write_1(void *vd, uint16_t offset, uint8_t val)
|
||||
}
|
||||
|
||||
device_t *
|
||||
device_ram_init()
|
||||
device_ram_init(uint16_t size)
|
||||
{
|
||||
device_t *d;
|
||||
|
||||
d = (device_t *) malloc(sizeof(device_t));
|
||||
|
||||
d = (device_t *) GC_MALLOC(sizeof(device_t));
|
||||
assert(d != NULL);
|
||||
|
||||
d->name = "RAM";
|
||||
d->size = RAM_SIZE;
|
||||
d->size = size;
|
||||
|
||||
d->read_1 = device_ram_read_1;
|
||||
d->write_1 = device_ram_write_1;
|
||||
d->finish = NULL;
|
||||
|
||||
d->aux = malloc(RAM_SIZE);
|
||||
memset(d->aux, 0, RAM_SIZE);
|
||||
d->aux = GC_MALLOC(size);
|
||||
assert(d->aux != NULL);
|
||||
|
||||
memset(d->aux, 0, size);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void
|
||||
device_ram_finish(device_t *d)
|
||||
{
|
||||
free(d->aux);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "device.h"
|
||||
|
||||
device_t * device_ram_init();
|
||||
device_t * device_ram_init(uint16_t);
|
||||
void device_ram_finish(device_t *);
|
||||
|
||||
#endif /* _DEVICE_RAM_H_ */
|
||||
|
@ -1,121 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "device.h"
|
||||
|
||||
const static char *txpipepath = "/tmp/rk65c02_serial_tx"; /* should really be configurable */
|
||||
const static char *rxpipepath = "/tmp/rk65c02_serial_rx"; /* should really be configurable */
|
||||
|
||||
struct device_serial_priv {
|
||||
int txpipefd;
|
||||
int rxpipefd;
|
||||
};
|
||||
|
||||
uint8_t device_serial_read_1(void *, uint16_t);
|
||||
void device_serial_write_1(void *, uint16_t, uint8_t);
|
||||
|
||||
uint8_t
|
||||
device_serial_read_1(void *vd, uint16_t offset)
|
||||
{
|
||||
device_t *d;
|
||||
struct device_serial_priv *dp;
|
||||
uint8_t val, nread;
|
||||
|
||||
d = (device_t *) vd;
|
||||
dp = d->aux;
|
||||
|
||||
switch (offset) {
|
||||
case 0x1:
|
||||
nread = read(dp->rxpipefd, &val, 1);;
|
||||
if (nread == 0)
|
||||
val = 0xFE;
|
||||
if (nread == -1)
|
||||
val = 0xFD;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// XXX: TODO
|
||||
|
||||
return 0xFF;
|
||||
}
|
||||
|
||||
void
|
||||
device_serial_write_1(void *vd, uint16_t offset, uint8_t val)
|
||||
{
|
||||
device_t *d;
|
||||
struct device_serial_priv *dp;
|
||||
|
||||
d = (device_t *) vd;
|
||||
dp = d->aux;
|
||||
|
||||
switch (offset) {
|
||||
case 0x0:
|
||||
/*fprintf(stderr, "writing to fd %d val %x\n", dp->txpipefd, val);*/
|
||||
write(dp->txpipefd, &val, 1);
|
||||
fsync(dp->txpipefd);
|
||||
break;
|
||||
default:
|
||||
/* do nothing */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
device_t *
|
||||
device_serial_init()
|
||||
{
|
||||
device_t *d;
|
||||
struct device_serial_priv *dp;
|
||||
|
||||
d = (device_t *) malloc(sizeof(device_t));
|
||||
|
||||
assert(d != NULL);
|
||||
|
||||
d->name = "Serial";
|
||||
d->size = 4;
|
||||
|
||||
d->read_1 = device_serial_read_1;
|
||||
d->write_1 = device_serial_write_1;
|
||||
|
||||
dp = (struct device_serial_priv *) malloc(sizeof(struct device_serial_priv));
|
||||
d->aux = dp;
|
||||
|
||||
if (mkfifo(txpipepath, S_IRUSR | S_IWUSR) != 0) {
|
||||
fprintf(stderr, "Creating FIFO for serial port failed!\n");
|
||||
/* perror, handle this failure... */
|
||||
}
|
||||
if (mkfifo(rxpipepath, S_IRUSR | S_IWUSR) != 0) {
|
||||
fprintf(stderr, "Creating FIFO for serial port failed!\n");
|
||||
/* perror, handle this failure... */
|
||||
}
|
||||
|
||||
dp->txpipefd = open(txpipepath, O_WRONLY);
|
||||
dp->rxpipefd = open(rxpipepath, O_RDONLY | O_NONBLOCK);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void
|
||||
device_serial_finish(device_t *d)
|
||||
{
|
||||
struct device_serial_priv *dp;
|
||||
|
||||
dp = d->aux;
|
||||
|
||||
close(dp->txpipefd);
|
||||
close(dp->rxpipefd);
|
||||
|
||||
unlink(txpipepath);
|
||||
unlink(rxpipepath);
|
||||
|
||||
free(d->aux);
|
||||
|
||||
// XXX?
|
||||
}
|
||||
|
@ -1,10 +0,0 @@
|
||||
#ifndef _DEVICE_SERIAL_H_
|
||||
#define _DEVICE_SERIAL_H_
|
||||
|
||||
#include "device.h"
|
||||
|
||||
device_t * device_serial_init();
|
||||
void device_serial_finish(device_t *);
|
||||
|
||||
#endif /* _DEVICE_SERIAL_H_ */
|
||||
|
@ -1,6 +1,26 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*
|
||||
* rk65c02
|
||||
* Copyright (C) 2017-2021 Radoslaw Kujawa
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "emulation.h"
|
||||
|
||||
/* RMB, SMB, BBR, BBS are handled by these */
|
||||
@ -10,7 +30,7 @@ static void emul_bbr(rk65c02emu_t *, void *, instruction_t *, uint8_t);
|
||||
static void emul_bbs(rk65c02emu_t *, void *, instruction_t *, uint8_t);
|
||||
|
||||
/* Convert 8-bit BCD to binary value. */
|
||||
static inline uint8_t from_bcd(uint8_t val)
|
||||
static uint8_t from_bcd(uint8_t val)
|
||||
{
|
||||
uint8_t rv;
|
||||
|
||||
@ -21,7 +41,7 @@ static inline uint8_t from_bcd(uint8_t val)
|
||||
}
|
||||
|
||||
/* Convert 8-bit binary to BCD value. */
|
||||
static inline uint8_t to_bcd(uint8_t val)
|
||||
static uint8_t to_bcd(uint8_t val)
|
||||
{
|
||||
uint16_t shift, digit;
|
||||
uint8_t bcd;
|
||||
@ -238,9 +258,6 @@ emul_bbs7(rk65c02emu_t *e, void *id, instruction_t *i)
|
||||
void
|
||||
emul_bit(rk65c02emu_t *e, void *id, instruction_t *i)
|
||||
{
|
||||
/* uint8_t v = instruction_data_read_1(e, (instrdef_t *) id, i);
|
||||
printf("%x\n", v);*/
|
||||
|
||||
/* zero flag set if acculumator AND memory equals zero */
|
||||
if (e->regs.A & instruction_data_read_1(e, (instrdef_t *) id, i))
|
||||
e->regs.P &= ~P_ZERO;
|
||||
@ -1099,3 +1116,13 @@ emul_wai(rk65c02emu_t *e, void *id, instruction_t *i)
|
||||
e->stopreason = WAI;
|
||||
}
|
||||
|
||||
/* emulate invalid opcode (variable-lenght NOP) */
|
||||
void
|
||||
emul_invalid(rk65c02emu_t *e, void *id, instruction_t *i)
|
||||
{
|
||||
/* Essentially do nothing, but log this. */
|
||||
|
||||
rk65c02_log(LOG_WARN, "Invalid opcode %x at %x", i->opcode,
|
||||
e->regs.PC);
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,36 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*
|
||||
* rk65c02
|
||||
* Copyright (C) 2017-2021 Radoslaw Kujawa
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gc/gc.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "65c02isa.h"
|
||||
#include "log.h"
|
||||
#include "instruction.h"
|
||||
|
||||
instruction_t
|
||||
@ -54,145 +76,77 @@ instruction_fetch(bus_t *b, uint16_t addr)
|
||||
void
|
||||
instruction_print(instruction_t *i)
|
||||
{
|
||||
char *str;
|
||||
|
||||
str = instruction_string_get(i);
|
||||
|
||||
printf("%s", str);
|
||||
}
|
||||
|
||||
char *
|
||||
instruction_string_get(instruction_t *i)
|
||||
{
|
||||
#define INSTR_STR_LEN 16
|
||||
instrdef_t id;
|
||||
char *str;
|
||||
|
||||
str = GC_MALLOC(INSTR_STR_LEN);
|
||||
assert(str != NULL);
|
||||
memset(str, 0, INSTR_STR_LEN);
|
||||
|
||||
id = instruction_decode(i->opcode);
|
||||
switch (id.mode) {
|
||||
case IMPLIED:
|
||||
printf("%s", id.mnemonic);
|
||||
snprintf(str, INSTR_STR_LEN, "%s", id.mnemonic);
|
||||
break;
|
||||
case ACCUMULATOR:
|
||||
printf("%s A", id.mnemonic);
|
||||
snprintf(str, INSTR_STR_LEN, "%s A", id.mnemonic);
|
||||
break;
|
||||
case IMMEDIATE:
|
||||
printf("%s #%#02x", id.mnemonic, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s #%#02x", id.mnemonic, i->op1);
|
||||
break;
|
||||
case ZP:
|
||||
printf("%s %#02x", id.mnemonic, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s %#02x", id.mnemonic, i->op1);
|
||||
break;
|
||||
case ZPX:
|
||||
printf("%s %#02x,X", id.mnemonic, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s %#02x,X", id.mnemonic, i->op1);
|
||||
break;
|
||||
case ZPY:
|
||||
printf("%s %#02x,Y", id.mnemonic, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s %#02x,Y", id.mnemonic, i->op1);
|
||||
break;
|
||||
case IZP:
|
||||
printf("%s (%#02x)", id.mnemonic, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s (%#02x)", id.mnemonic, i->op1);
|
||||
break;
|
||||
case IZPX:
|
||||
printf("%s (%#02x,X)", id.mnemonic, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s (%#02x,X)", id.mnemonic, i->op1);
|
||||
break;
|
||||
case IZPY:
|
||||
printf("%s (%#02x),Y", id.mnemonic, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s (%#02x),Y", id.mnemonic, i->op1);
|
||||
break;
|
||||
case ZPR:
|
||||
printf("%s %#02x,%#02x", id.mnemonic, i->op1, i->op2);
|
||||
snprintf(str, INSTR_STR_LEN, "%s %#02x,%#02x", id.mnemonic, i->op1, i->op2);
|
||||
break;
|
||||
case ABSOLUTE:
|
||||
printf("%s %#02x%02x", id.mnemonic, i->op2, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s %#02x%02x", id.mnemonic, i->op2, i->op1);
|
||||
break;
|
||||
case ABSOLUTEX:
|
||||
printf("%s %#02x%02x,X", id.mnemonic, i->op2, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s %#02x%02x,X", id.mnemonic, i->op2, i->op1);
|
||||
break;
|
||||
case ABSOLUTEY:
|
||||
printf("%s %#02x%02x,Y", id.mnemonic, i->op2, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s %#02x%02x,Y", id.mnemonic, i->op2, i->op1);
|
||||
break;
|
||||
case IABSOLUTE:
|
||||
printf("%s (%#02x%02x)", id.mnemonic, i->op2, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s (%#02x%02x)", id.mnemonic, i->op2, i->op1);
|
||||
break;
|
||||
case IABSOLUTEX:
|
||||
printf("%s (%#02x%02x,X)", id.mnemonic, i->op2, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s (%#02x%02x,X)", id.mnemonic, i->op2, i->op1);
|
||||
break;
|
||||
case RELATIVE:
|
||||
printf("%s %#02x", id.mnemonic, i->op1);
|
||||
snprintf(str, INSTR_STR_LEN, "%s %#02x", id.mnemonic, i->op1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assembler_t
|
||||
assemble_init(bus_t *b, uint16_t pc)
|
||||
{
|
||||
assembler_t asmblr;
|
||||
|
||||
asmblr.bus = b;
|
||||
asmblr.pc = pc;
|
||||
|
||||
return asmblr;
|
||||
}
|
||||
|
||||
bool
|
||||
assemble_single_implied(assembler_t *a, const char *mnemonic)
|
||||
{
|
||||
return assemble_single(a, mnemonic, IMPLIED, 0, 0);
|
||||
}
|
||||
|
||||
bool
|
||||
assemble_single(assembler_t *a, const char *mnemonic, addressing_t mode, uint8_t op1, uint8_t op2)
|
||||
{
|
||||
uint8_t *asmbuf;
|
||||
uint8_t bsize;
|
||||
bool rv;
|
||||
|
||||
rv = assemble_single_buf(&asmbuf, &bsize, mnemonic, mode, op1, op2);
|
||||
if (rv == false)
|
||||
return rv;
|
||||
|
||||
rv = bus_load_buf(a->bus, a->pc, asmbuf, bsize);
|
||||
free(asmbuf);
|
||||
a->pc += bsize;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool
|
||||
assemble_single_buf_implied(uint8_t **buf, uint8_t *bsize, const char *mnemonic)
|
||||
{
|
||||
return assemble_single_buf(buf, bsize, mnemonic, IMPLIED, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
assemble_single_buf(uint8_t **buf, uint8_t *bsize, const char *mnemonic, addressing_t mode, uint8_t op1, uint8_t op2)
|
||||
{
|
||||
instrdef_t id;
|
||||
uint8_t opcode;
|
||||
bool found;
|
||||
|
||||
found = false;
|
||||
opcode = 0;
|
||||
|
||||
/* find the opcode for given mnemonic and addressing mode */
|
||||
while (opcode < 0xFF) {
|
||||
id = instruction_decode(opcode);
|
||||
if ((strcmp(mnemonic, id.mnemonic) == 0) && (id.mode == mode)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
opcode++;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
fprintf(stderr, "Couldn't find opcode for mnemonic %s mode %x\n", mnemonic, mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
*bsize = id.size;
|
||||
*buf = malloc(id.size);
|
||||
if(*buf == NULL) {
|
||||
fprintf(stderr, "Error allocating assembly buffer\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* fill the buffer */
|
||||
memset(*buf, 0, id.size);
|
||||
(*buf)[0] = opcode;
|
||||
/* XXX */
|
||||
if (id.size > 1)
|
||||
(*buf)[1] = op1;
|
||||
if (id.size > 2)
|
||||
(*buf)[2] = op2;
|
||||
|
||||
return found;
|
||||
return str;
|
||||
}
|
||||
|
||||
void
|
||||
@ -248,116 +202,71 @@ instruction_status_adjust_negative(rk65c02emu_t *e, uint8_t regval)
|
||||
void
|
||||
instruction_data_write_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i, uint8_t val)
|
||||
{
|
||||
uint16_t iaddr;
|
||||
|
||||
switch (id->mode) {
|
||||
case ZP:
|
||||
case ZPR:
|
||||
bus_write_1(e->bus, i->op1, val);
|
||||
break;
|
||||
case ZPX:
|
||||
/* XXX: wraps around zero page? */
|
||||
bus_write_1(e->bus, i->op1 + e->regs.X, val);
|
||||
break;
|
||||
case ZPY:
|
||||
bus_write_1(e->bus, i->op1 + e->regs.Y, val);
|
||||
break;
|
||||
case IZP:
|
||||
iaddr = bus_read_1(e->bus, i->op1);
|
||||
iaddr |= (bus_read_1(e->bus, i->op1 + 1) << 8);
|
||||
bus_write_1(e->bus, iaddr, val);
|
||||
break;
|
||||
case ABSOLUTE:
|
||||
bus_write_1(e->bus, i->op1 + (i->op2 << 8), val);
|
||||
break;
|
||||
case IZPX:
|
||||
/* XXX */
|
||||
iaddr = bus_read_1(e->bus, i->op1 + e->regs.X);
|
||||
iaddr |= (bus_read_1(e->bus, i->op1 + e->regs.X + 1) << 8);
|
||||
bus_write_1(e->bus, iaddr, val);
|
||||
break;
|
||||
case IZPY:
|
||||
/* XXX */
|
||||
iaddr = bus_read_1(e->bus, i->op1);
|
||||
iaddr |= (bus_read_1(e->bus, i->op1 + 1) << 8);
|
||||
bus_write_1(e->bus, iaddr, val + e->regs.Y);
|
||||
break;
|
||||
case ABSOLUTEX:
|
||||
bus_write_1(e->bus, (i->op1 + (i->op2 << 8)) + e->regs.X, val);
|
||||
break;
|
||||
case ABSOLUTEY:
|
||||
bus_write_1(e->bus, (i->op1 + (i->op2 << 8)) + e->regs.Y, val);
|
||||
break;
|
||||
case ACCUMULATOR:
|
||||
if (id->mode == ACCUMULATOR) {
|
||||
e->regs.A = val;
|
||||
break;
|
||||
case IMMEDIATE:
|
||||
case RELATIVE:
|
||||
case IABSOLUTE:
|
||||
case IABSOLUTEX:
|
||||
/*
|
||||
* IABSOLUTE, IABSOLUTEX, RELATIVE are only for branches
|
||||
* and jumps. They do not read or write anything, only modify
|
||||
* PC which is handled within emulation of a given opcode.
|
||||
*/
|
||||
default:
|
||||
printf("unhandled addressing mode for opcode %x\n",
|
||||
i->opcode);
|
||||
break;
|
||||
return;
|
||||
}
|
||||
|
||||
if (id->mode == IMMEDIATE) {
|
||||
rk65c02_panic(e,
|
||||
"invalid IMMEDIATE addressing mode for opcode %x\n",
|
||||
i->opcode);
|
||||
return;
|
||||
}
|
||||
|
||||
bus_write_1(e->bus, instruction_data_address(e, id, i), val);
|
||||
}
|
||||
|
||||
uint8_t
|
||||
instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i)
|
||||
{
|
||||
uint8_t rv; /* data read from the bus */
|
||||
uint16_t iaddr; /* indirect address */
|
||||
if (id->mode == ACCUMULATOR)
|
||||
return e->regs.A;
|
||||
else if (id->mode == IMMEDIATE)
|
||||
return i->op1;
|
||||
|
||||
rv = 0;
|
||||
return bus_read_1(e->bus, instruction_data_address(e, id, i));
|
||||
}
|
||||
|
||||
uint16_t
|
||||
instruction_data_address(rk65c02emu_t *e, instrdef_t *id, instruction_t *i)
|
||||
{
|
||||
uint16_t addr;
|
||||
|
||||
addr = 0;
|
||||
|
||||
switch (id->mode) {
|
||||
case ACCUMULATOR:
|
||||
rv = e->regs.A;
|
||||
break;
|
||||
case IMMEDIATE:
|
||||
rv = i->op1;
|
||||
break;
|
||||
case ZP:
|
||||
case ZPR:
|
||||
rv = bus_read_1(e->bus, i->op1);
|
||||
addr = i->op1;
|
||||
break;
|
||||
case ZPX:
|
||||
/* XXX: wraps around zero page? */
|
||||
rv = bus_read_1(e->bus, i->op1 + e->regs.X);
|
||||
addr = ((uint8_t) (i->op1 + e->regs.X));
|
||||
break;
|
||||
case ZPY:
|
||||
rv = bus_read_1(e->bus, i->op1 + e->regs.Y);
|
||||
addr = i->op1 + e->regs.Y;
|
||||
break;
|
||||
case IZP:
|
||||
iaddr = bus_read_1(e->bus, i->op1);
|
||||
iaddr |= (bus_read_1(e->bus, i->op1 + 1) << 8);
|
||||
rv = bus_read_1(e->bus, iaddr);
|
||||
addr = bus_read_1(e->bus, i->op1);
|
||||
addr |= (bus_read_1(e->bus, i->op1 + 1) << 8);
|
||||
break;
|
||||
case IZPX:
|
||||
/* XXX: what about page wraps / roll over */
|
||||
iaddr = bus_read_1(e->bus, i->op1 + e->regs.X);
|
||||
iaddr |= (bus_read_1(e->bus, i->op1 + e->regs.X + 1) << 8);
|
||||
rv = bus_read_1(e->bus, iaddr);
|
||||
case IZPX: /* Zero Page Indexed Indirect with X */
|
||||
addr = bus_read_1(e->bus, (uint8_t) (i->op1 + e->regs.X));
|
||||
addr |= (bus_read_1(e->bus, (uint8_t) (i->op1 + e->regs.X + 1)) << 8);
|
||||
break;
|
||||
case IZPY:
|
||||
/* XXX: what about page wraps / roll over */
|
||||
iaddr = bus_read_1(e->bus, i->op1);
|
||||
iaddr |= (bus_read_1(e->bus, i->op1 + 1) << 8);
|
||||
rv = bus_read_1(e->bus, iaddr) + e->regs.Y;
|
||||
case IZPY: /* Zero Page Indirect Indexed with Y */
|
||||
addr = bus_read_1(e->bus, i->op1);
|
||||
addr |= (bus_read_1(e->bus, i->op1 + 1) << 8);
|
||||
addr += e->regs.Y;
|
||||
break;
|
||||
case ABSOLUTE:
|
||||
rv = bus_read_1(e->bus, i->op1 + (i->op2 << 8));
|
||||
addr = i->op1 + (i->op2 << 8);
|
||||
break;
|
||||
case ABSOLUTEX:
|
||||
rv = bus_read_1(e->bus, (i->op1 + (i->op2 << 8)) + e->regs.X);
|
||||
addr = i->op1 + (i->op2 << 8) + e->regs.X;
|
||||
break;
|
||||
case ABSOLUTEY:
|
||||
rv = bus_read_1(e->bus, (i->op1 + (i->op2 << 8)) + e->regs.Y);
|
||||
addr = i->op1 + (i->op2 << 8) + e->regs.Y;
|
||||
break;
|
||||
case IABSOLUTE:
|
||||
case IABSOLUTEX:
|
||||
@ -368,12 +277,12 @@ instruction_data_read_1(rk65c02emu_t *e, instrdef_t *id, instruction_t *i)
|
||||
* PC which is handled within emulation of a given opcode.
|
||||
*/
|
||||
default:
|
||||
printf("unhandled addressing mode for opcode %x\n",
|
||||
rk65c02_panic(e, "unhandled addressing mode for opcode %x\n",
|
||||
i->opcode);
|
||||
break;
|
||||
}
|
||||
|
||||
return rv;
|
||||
return addr;
|
||||
}
|
||||
|
||||
/* put value onto the stack */
|
||||
@ -416,3 +325,23 @@ instruction_modify_pc(instrdef_t *id)
|
||||
return id->modify_pc;
|
||||
}
|
||||
|
||||
/* find instr definition (and opcode) searching by mnemonic and addr mode */
|
||||
bool
|
||||
instruction_opcode_by_mnemonic(char *mnemonic, addressing_t mode, uint8_t *opcode, instrdef_t *id)
|
||||
{
|
||||
bool found;
|
||||
|
||||
found = false;
|
||||
|
||||
while ((*opcode) <= 0xFF) { /* this is stupid */
|
||||
*id = instruction_decode(*opcode);
|
||||
if ((strcmp(mnemonic, id->mnemonic) == 0) && (id->mode == mode)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
(*opcode)++;
|
||||
}
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
@ -41,19 +41,14 @@ struct instrdef {
|
||||
|
||||
typedef struct instrdef instrdef_t;
|
||||
|
||||
struct assembler {
|
||||
bus_t *bus;
|
||||
uint16_t pc;
|
||||
};
|
||||
|
||||
typedef struct assembler assembler_t;
|
||||
|
||||
instruction_t instruction_fetch(bus_t *, uint16_t);
|
||||
instrdef_t instruction_decode(uint8_t);
|
||||
void instruction_print(instruction_t *);
|
||||
char * instruction_string_get(instruction_t *);
|
||||
void disassemble(bus_t *, uint16_t);
|
||||
uint8_t instruction_data_read_1(rk65c02emu_t *, instrdef_t *, instruction_t *);
|
||||
void instruction_data_write_1(rk65c02emu_t *, instrdef_t *, instruction_t *, uint8_t);
|
||||
uint16_t instruction_data_address(rk65c02emu_t *e, instrdef_t *id, instruction_t *i);
|
||||
void instruction_status_adjust_zero(rk65c02emu_t *, uint8_t);
|
||||
void instruction_status_adjust_negative(rk65c02emu_t *, uint8_t);
|
||||
void stack_push(rk65c02emu_t *, uint8_t);
|
||||
@ -61,12 +56,6 @@ uint8_t stack_pop(rk65c02emu_t *);
|
||||
void program_counter_increment(rk65c02emu_t *, instrdef_t *);
|
||||
bool instruction_modify_pc(instrdef_t *);
|
||||
void program_counter_branch(rk65c02emu_t *, int8_t);
|
||||
|
||||
bool assemble_single_buf_implied(uint8_t **, uint8_t *, const char *);
|
||||
bool assemble_single_buf(uint8_t **, uint8_t *, const char *, addressing_t, uint8_t, uint8_t);
|
||||
|
||||
assembler_t assemble_init(bus_t *, uint16_t);
|
||||
bool assemble_single(assembler_t *, const char *, addressing_t, uint8_t, uint8_t);
|
||||
bool assemble_single_implied(assembler_t *, const char *);
|
||||
bool instruction_opcode_by_mnemonic(char *, addressing_t, uint8_t *, instrdef_t *);
|
||||
|
||||
#endif /* _INSTRUCTION_H_ */
|
||||
|
60
src/log.c
Normal file
60
src/log.c
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*
|
||||
* rk65c02
|
||||
* Copyright (C) 2017-2021 Radoslaw Kujawa
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
static const char *level_str[] = {
|
||||
"NONE", /* should never appear in log */
|
||||
"CRITICAL",
|
||||
"ERROR",
|
||||
"INFO",
|
||||
"DEBUG",
|
||||
"TRACE"
|
||||
};
|
||||
|
||||
static uint8_t level = LOG_INFO;
|
||||
|
||||
void rk65c02_loglevel_set(uint8_t l)
|
||||
{
|
||||
level = l;
|
||||
}
|
||||
|
||||
void rk65c02_log(uint8_t l, const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
struct timespec t;
|
||||
|
||||
if (l > level)
|
||||
return;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &t);
|
||||
|
||||
fprintf(stderr, "%lld.%lld %s:\t", (long long int) t.tv_sec,
|
||||
(long long int) t.tv_nsec, level_str[l]);
|
||||
|
||||
va_start(args, fmt);
|
||||
vfprintf(stderr, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
|
29
src/log.h
Normal file
29
src/log.h
Normal file
@ -0,0 +1,29 @@
|
||||
/**
|
||||
* @file log.h
|
||||
* @brief Logging-related functions.
|
||||
*/
|
||||
#include <stdint.h>
|
||||
|
||||
#define LOG_TRACE 5 /**< Most verbose log level. Used for tracing. */
|
||||
#define LOG_DEBUG 4 /**< Debug-level messages. */
|
||||
#define LOG_INFO 3 /**< Informational messages. */
|
||||
#define LOG_WARN 4 /**< Warning messages. */
|
||||
#define LOG_ERROR 2 /**< Errors. */
|
||||
#define LOG_CRIT 1 /**< Critical errors. */
|
||||
#define LOG_NOTHING 0 /**< At 0 nothing will get logged, can be set as
|
||||
current level, but not when creating new log
|
||||
messages. */
|
||||
|
||||
/**
|
||||
* @brief Set the logging verbosity level.
|
||||
* @param level Desired log verbosity level.
|
||||
*/
|
||||
void rk65c02_loglevel_set(uint8_t level);
|
||||
|
||||
/**
|
||||
* @brief Send a message to log.
|
||||
* @param level Log level at which message should be logged.
|
||||
* @param fmt Message in a printf-like format.
|
||||
*/
|
||||
void rk65c02_log(uint8_t level, const char *fmt, ...);
|
||||
|
182
src/rk65c02.c
182
src/rk65c02.c
@ -1,21 +1,60 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*
|
||||
* rk65c02
|
||||
* Copyright (C) 2017-2021 Radoslaw Kujawa
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <gc/gc.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "instruction.h"
|
||||
#include "rk65c02.h"
|
||||
#include "log.h"
|
||||
#include "debug.h"
|
||||
|
||||
void rk65c02_exec(rk65c02emu_t *);
|
||||
|
||||
/*
|
||||
* Prepare the emulator for use, set initial CPU state.
|
||||
*/
|
||||
rk65c02emu_t
|
||||
rk65c02_load_rom(const char *path, uint16_t load_addr, bus_t *b)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
|
||||
if (b == NULL) {
|
||||
b = GC_MALLOC(sizeof(bus_t));
|
||||
assert(b != NULL);
|
||||
*b = bus_init_with_default_devs();
|
||||
}
|
||||
|
||||
/* XXX: normal error handling instead of assert would be preferred */
|
||||
assert(bus_load_file(b, load_addr, path));
|
||||
|
||||
e = rk65c02_init(b);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
rk65c02emu_t
|
||||
rk65c02_init(bus_t *b)
|
||||
{
|
||||
@ -31,15 +70,15 @@ rk65c02_init(bus_t *b)
|
||||
e.irq = false;
|
||||
|
||||
e.bps_head = NULL;
|
||||
e.trace = false;
|
||||
e.trace_head = NULL;
|
||||
e.runtime_disassembly = false;
|
||||
|
||||
rk65c02_log(LOG_DEBUG, "Initialized new emulator.");
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
/*
|
||||
* Assert the IRQ line.
|
||||
*/
|
||||
void
|
||||
rk65c02_assert_irq(rk65c02emu_t *e)
|
||||
{
|
||||
@ -51,13 +90,18 @@ rk65c02_assert_irq(rk65c02emu_t *e)
|
||||
*/
|
||||
e->irq = true;
|
||||
|
||||
/*
|
||||
* If the CPU was put to sleep by executing WAI instruction, resume
|
||||
* operation.
|
||||
*
|
||||
* Whether interrupt will immediately be serviced, or not, depends
|
||||
* on normal "interrupt disable" flag behaviour, so here we just
|
||||
* need to start the CPU.
|
||||
*/
|
||||
if ((e->state == STOPPED) && (e->stopreason == WAI))
|
||||
rk65c02_start(e);
|
||||
}
|
||||
|
||||
/*
|
||||
* Respond to interrupt and start the interrupt service routine.
|
||||
*/
|
||||
void
|
||||
rk65c02_irq(rk65c02emu_t *e)
|
||||
{
|
||||
@ -110,26 +154,18 @@ rk65c02_exec(rk65c02emu_t *e)
|
||||
i = instruction_fetch(e->bus, e->regs.PC);
|
||||
id = instruction_decode(i.opcode);
|
||||
|
||||
if (id.emul != NULL) {
|
||||
id.emul(e, &id, &i);
|
||||
assert(id.emul);
|
||||
|
||||
if (!instruction_modify_pc(&id))
|
||||
program_counter_increment(e, &id);
|
||||
} else {
|
||||
printf("unimplemented opcode %X @ %X\n", i.opcode,
|
||||
e->regs.PC);
|
||||
e->state = STOPPED;
|
||||
e->stopreason = EMUERROR;
|
||||
}
|
||||
id.emul(e, &id, &i);
|
||||
|
||||
if (!instruction_modify_pc(&id))
|
||||
program_counter_increment(e, &id);
|
||||
|
||||
if (e->trace)
|
||||
debug_trace_savestate(e, tpc, &id, &i);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Start the emulator.
|
||||
*/
|
||||
void
|
||||
rk65c02_start(rk65c02emu_t *e) {
|
||||
|
||||
@ -141,9 +177,6 @@ rk65c02_start(rk65c02emu_t *e) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Execute as many instructions as specified in steps argument.
|
||||
*/
|
||||
void
|
||||
rk65c02_step(rk65c02emu_t *e, uint16_t steps) {
|
||||
|
||||
@ -185,72 +218,51 @@ rk65c02_dump_stack(rk65c02emu_t *e, uint8_t n)
|
||||
void
|
||||
rk65c02_dump_regs(reg_state_t regs)
|
||||
{
|
||||
printf("A: %X X: %X Y: %X PC: %X SP: %X P: ",
|
||||
regs.A, regs.X, regs.Y, regs.PC, regs.SP);
|
||||
char *str;
|
||||
|
||||
if (regs.P & P_NEGATIVE)
|
||||
printf("N");
|
||||
else
|
||||
printf("-");
|
||||
str = rk65c02_regs_string_get(regs);
|
||||
|
||||
if (regs.P & P_SIGN_OVERFLOW)
|
||||
printf("V");
|
||||
else
|
||||
printf("-");
|
||||
printf ("%s\n", str);
|
||||
|
||||
if (regs.P & P_UNDEFINED)
|
||||
printf("1");
|
||||
else
|
||||
printf("-");
|
||||
|
||||
if (regs.P & P_BREAK)
|
||||
printf("B");
|
||||
else
|
||||
printf("-");
|
||||
|
||||
if (regs.P & P_DECIMAL)
|
||||
printf("D");
|
||||
else
|
||||
printf("-");
|
||||
|
||||
if (regs.P & P_IRQ_DISABLE)
|
||||
printf("I");
|
||||
else
|
||||
printf("-");
|
||||
|
||||
if (regs.P & P_ZERO)
|
||||
printf("Z");
|
||||
else
|
||||
printf("-");
|
||||
|
||||
if (regs.P & P_CARRY)
|
||||
printf("C");
|
||||
else
|
||||
printf("-");
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
/*
|
||||
int
|
||||
main(void)
|
||||
|
||||
char *
|
||||
rk65c02_regs_string_get(reg_state_t regs)
|
||||
{
|
||||
bus_t b;
|
||||
#define REGS_STR_LEN 50
|
||||
char *str;
|
||||
|
||||
b = bus_init();
|
||||
/* XXX: string allocation to a separate utility function? */
|
||||
str = GC_MALLOC(REGS_STR_LEN);
|
||||
assert(str != NULL);
|
||||
memset(str, 0, REGS_STR_LEN);
|
||||
|
||||
bus_write_1(&b, 0, OP_INX);
|
||||
bus_write_1(&b, 1, OP_NOP);
|
||||
bus_write_1(&b, 2, OP_LDY_IMM);
|
||||
bus_write_1(&b, 3, 0x1);
|
||||
bus_write_1(&b, 4, OP_TSB_ZP);
|
||||
bus_write_1(&b, 5, 0x3);
|
||||
bus_write_1(&b, 6, OP_JSR);
|
||||
bus_write_1(&b, 7, 0x09);
|
||||
bus_write_1(&b, 8, 0x0);
|
||||
bus_write_1(&b, 9, OP_STP);
|
||||
snprintf(str, REGS_STR_LEN, "A: %X X: %X Y: %X PC: %X SP: %X P: %c%c%c%c%c%c%c%c",
|
||||
regs.A, regs.X, regs.Y, regs.PC, regs.SP,
|
||||
(regs.P & P_NEGATIVE) ? 'N' : '-',
|
||||
(regs.P & P_SIGN_OVERFLOW) ? 'V' : '-',
|
||||
(regs.P & P_UNDEFINED) ? '1' : '-',
|
||||
(regs.P & P_BREAK) ? 'B' : '-',
|
||||
(regs.P & P_DECIMAL) ? 'D' : '-',
|
||||
(regs.P & P_IRQ_DISABLE) ? 'I' : '-',
|
||||
(regs.P & P_ZERO) ? 'Z' : '-',
|
||||
(regs.P & P_CARRY) ? 'C' : '-');
|
||||
|
||||
rk6502_start(&b, 0);
|
||||
|
||||
bus_finish(&b);
|
||||
return str;
|
||||
}
|
||||
*/
|
||||
|
||||
void
|
||||
rk65c02_panic(rk65c02emu_t *e, const char* fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, fmt);
|
||||
rk65c02_log(LOG_CRIT, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
e->state = STOPPED;
|
||||
e->stopreason = EMUERROR;
|
||||
|
||||
/* TODO: run some UI callback. */
|
||||
}
|
||||
|
||||
|
127
src/rk65c02.h
127
src/rk65c02.h
@ -1,42 +1,54 @@
|
||||
/** @file rk65c02.h
|
||||
* @brief Public functions for managing rk65c02 emulator.
|
||||
*/
|
||||
#ifndef _RK6502_H_
|
||||
#define _RK6502_H_
|
||||
|
||||
#include "bus.h"
|
||||
|
||||
/**
|
||||
* @brief State of the emulator.
|
||||
*/
|
||||
typedef enum {
|
||||
STOPPED,
|
||||
RUNNING,
|
||||
STEPPING /* XXX: how to implement? */
|
||||
STOPPED, /**< Stopped. */
|
||||
RUNNING, /**< Running. */
|
||||
STEPPING /**< Stepping. */
|
||||
} emu_state_t;
|
||||
|
||||
/**
|
||||
* @brief Enum describing why emulation stopped.
|
||||
*/
|
||||
typedef enum {
|
||||
STP, /* due to 65C02 STP instruction */
|
||||
WAI, /* waiting for interrupt */
|
||||
BREAKPOINT, /* due to breakpoint set */
|
||||
WATCHPOINT, /* due to watchpoint set */
|
||||
STEPPED, /* stepped appropriate number of instructions */
|
||||
HOST, /* due to host stop function called */
|
||||
EMUERROR /* due to emulator error */
|
||||
STP, /**< Due to 65C02 STP instruction. */
|
||||
WAI, /**< Waiting for interrupt (WAI instruction). */
|
||||
BREAKPOINT, /**< Due to breakpoint set. */
|
||||
WATCHPOINT, /**< Due to watchpoint set (not implemented). */
|
||||
STEPPED, /**< Stepped appropriate number of instructions. */
|
||||
HOST, /**< Due to host stop function called. */
|
||||
EMUERROR /**< Due to emulator error. */
|
||||
} emu_stop_reason_t;
|
||||
|
||||
/**
|
||||
* @brief State of the emulated CPU registers.
|
||||
*/
|
||||
struct reg_state {
|
||||
uint8_t A; /* accumulator */
|
||||
uint8_t X; /* index X */
|
||||
uint8_t Y; /* index Y */
|
||||
uint8_t A; /**< Accumulator. */
|
||||
uint8_t X; /**< Index X. */
|
||||
uint8_t Y; /**< Index Y. */
|
||||
|
||||
uint16_t PC; /* program counter */
|
||||
uint8_t SP; /* stack pointer */
|
||||
uint8_t P; /* status */
|
||||
uint16_t PC; /**< Program counter. */
|
||||
uint8_t SP; /**< Stack pointer. */
|
||||
uint8_t P; /**< Status. */
|
||||
};
|
||||
|
||||
typedef struct reg_state reg_state_t;
|
||||
|
||||
#define P_CARRY 0x1
|
||||
#define P_ZERO 0x2
|
||||
#define P_IRQ_DISABLE 0x4
|
||||
#define P_DECIMAL 0x8
|
||||
#define P_BREAK 0x10
|
||||
#define P_UNDEFINED 0x20
|
||||
#define P_IRQ_DISABLE 0x4 /**< Status register flag: IRQ disabled */
|
||||
#define P_DECIMAL 0x8 /**< Status register flag: BCD mode */
|
||||
#define P_BREAK 0x10 /**< Status register flag: BRK was the cause of interrupt */
|
||||
#define P_UNDEFINED 0x20 /**< Status register flag: Undefined (always 1) */
|
||||
#define P_SIGN_OVERFLOW 0x40
|
||||
#define P_NEGATIVE 0x80
|
||||
|
||||
@ -61,27 +73,76 @@ typedef struct trace_t {
|
||||
struct trace_t *prev,*next;
|
||||
} trace_t;
|
||||
|
||||
/**
|
||||
* @brief Instance of the emulator.
|
||||
*/
|
||||
struct rk65c02emu {
|
||||
emu_state_t state;
|
||||
bus_t *bus;
|
||||
reg_state_t regs;
|
||||
emu_stop_reason_t stopreason;
|
||||
bool irq; /* interrupt request line state, true is asserted */
|
||||
emu_state_t state; /**< Current emulator status. */
|
||||
bus_t *bus; /**< Bus to which CPU is attached. */
|
||||
reg_state_t regs; /**< CPU registers. */
|
||||
emu_stop_reason_t stopreason; /**< Reason for stopping emulation. */
|
||||
bool irq; /**< Interrupt request line state, true is asserted. */
|
||||
|
||||
breakpoint_t *bps_head; /* pointer to linked list with breakpoints */
|
||||
bool runtime_disassembly; /* disassemble code when emulator is running */
|
||||
bool trace; /* tracing mode enable/disable */
|
||||
trace_t *trace_head; /* pointer to linked list with trace log */
|
||||
breakpoint_t *bps_head; /**< Pointer to linked list with breakpoints. */
|
||||
bool runtime_disassembly; /**< Disassemble code when emulator is running. */
|
||||
bool trace; /**< Tracing mode enable/disable. */
|
||||
trace_t *trace_head; /**< Pointer to linked list with trace log. */
|
||||
};
|
||||
|
||||
typedef struct rk65c02emu rk65c02emu_t;
|
||||
|
||||
rk65c02emu_t rk65c02_init(bus_t *);
|
||||
void rk65c02_start(rk65c02emu_t *);
|
||||
void rk65c02_step(rk65c02emu_t *, uint16_t);
|
||||
void rk65c02_dump_regs(reg_state_t regs);
|
||||
/**
|
||||
* @brief Initialize the new emulator instance. Set initial CPU state.
|
||||
* @param b Bus description.
|
||||
* @return New emulator instance.
|
||||
*/
|
||||
rk65c02emu_t rk65c02_init(bus_t *b);
|
||||
|
||||
/**
|
||||
* @brief Start the emulator.
|
||||
* @param e Emulator instance.
|
||||
*/
|
||||
void rk65c02_start(rk65c02emu_t *e);
|
||||
|
||||
/**
|
||||
* @brief Execute as many instructions as specified in steps argument.
|
||||
* @param e Emulator instance.
|
||||
* @param steps Number of instructions to execute.
|
||||
*/
|
||||
void rk65c02_step(rk65c02emu_t *e, uint16_t steps);
|
||||
|
||||
char *rk65c02_regs_string_get(reg_state_t);
|
||||
void rk65c02_dump_regs(reg_state_t);
|
||||
void rk65c02_dump_stack(rk65c02emu_t *, uint8_t);
|
||||
|
||||
/**
|
||||
* @brief Assert the IRQ line.
|
||||
* @param e Emulator instance.
|
||||
*/
|
||||
void rk65c02_assert_irq(rk65c02emu_t *e);
|
||||
|
||||
/**
|
||||
* @brief Respond to interrupt and start the interrupt service routine.
|
||||
* @param e Emulator instance.
|
||||
*/
|
||||
void rk65c02_irq(rk65c02emu_t *e);
|
||||
|
||||
/**
|
||||
* @brief Handle critical error - send message to log and stop emulation.
|
||||
* @param e Emulator instance.
|
||||
* @param fmt Message in printf-like format.
|
||||
*/
|
||||
void rk65c02_panic(rk65c02emu_t *e, const char *fmt, ...);
|
||||
|
||||
/**
|
||||
* @brief Prep the emulator, load code from file, pass bus config optionally.
|
||||
* @param path Path to ROM file to be loaded.
|
||||
* @param load_addr Address on the bus where ROM should be loaded.
|
||||
* @param b Pre-existing bus configuration, pass NULL if default requested.
|
||||
* @return New instance of the emulator prepared to run the ROM.
|
||||
*/
|
||||
rk65c02emu_t rk65c02_load_rom(const char *path, uint16_t load_addr,
|
||||
bus_t *b);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,63 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "instruction.h"
|
||||
#include "rk65c02.h"
|
||||
|
||||
|
||||
/*
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
bus_t b;
|
||||
|
||||
b = bus_init();
|
||||
|
||||
bus_write_1(&b, 0, OP_INX);
|
||||
bus_write_1(&b, 1, OP_NOP);
|
||||
bus_write_1(&b, 2, OP_LDY_IMM);
|
||||
bus_write_1(&b, 3, 0x1);
|
||||
bus_write_1(&b, 4, OP_TSB_ZP);
|
||||
bus_write_1(&b, 5, 0x3);
|
||||
bus_write_1(&b, 6, OP_JSR);
|
||||
bus_write_1(&b, 7, 0x09);
|
||||
bus_write_1(&b, 8, 0x0);
|
||||
bus_write_1(&b, 9, OP_STP);
|
||||
|
||||
rk6502_start(&b, 0);
|
||||
|
||||
bus_finish(&b);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
char* input, shell_prompt[100];
|
||||
|
||||
rl_bind_key('\t', rl_complete);
|
||||
|
||||
while(true) {
|
||||
snprintf(shell_prompt, sizeof(shell_prompt), "> ");
|
||||
|
||||
input = readline(shell_prompt);
|
||||
|
||||
if (!input)
|
||||
break;
|
||||
|
||||
add_history(input);
|
||||
|
||||
free(input);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -1,8 +1,19 @@
|
||||
CFLAGS=-Wall -I../src -g
|
||||
LDFLAGS=-latf-c
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
CFLAGS=-Wall -I../src -ggdb -Og
|
||||
LDFLAGS=-latf-c -lgc
|
||||
|
||||
LDFLAGS_MACOSX=-L/opt/local/lib
|
||||
CFLAGS_MACOSX=-I/opt/local/include -I/opt/local/include/uthash
|
||||
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
CFLAGS+=$(CFLAGS_MACOSX)
|
||||
LDFLAGS+=$(LDFLAGS_MACOSX)
|
||||
endif
|
||||
|
||||
RK6502LIB=../src/librk65c02.a
|
||||
VASM=vasm6502_std
|
||||
VASMFLAGS=-Fbin -c02
|
||||
VASMFLAGS=-Fbin -wdc02
|
||||
UTILS=utils.o
|
||||
|
||||
TESTS=test_bus test_emulation test_stepping test_assemble test_interrupt test_debug test_device_serial test_jit
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "assembler.h"
|
||||
#include "instruction.h"
|
||||
#include "utils.h"
|
||||
|
||||
@ -28,20 +29,17 @@ ATF_TC_BODY(assemble_single_buf, tc)
|
||||
ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "nop"));
|
||||
ATF_CHECK(asmbuf[0] == 0xEA); /* check if nop really */
|
||||
ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize));
|
||||
free(asmbuf);
|
||||
caddr += bsize;
|
||||
|
||||
ATF_REQUIRE(assemble_single_buf(&asmbuf, &bsize, "lda", IMMEDIATE, 0xAA, 0));
|
||||
ATF_CHECK(asmbuf[0] == 0xA9); /* check if lda really */
|
||||
ATF_CHECK(asmbuf[1] == 0xAA); /* check the operand */
|
||||
ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize));
|
||||
free(asmbuf);
|
||||
caddr += bsize;
|
||||
|
||||
ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "stp"));
|
||||
ATF_CHECK(asmbuf[0] == 0xDB); /* check if stp really */
|
||||
ATF_REQUIRE(bus_load_buf(&b, caddr, asmbuf, bsize));
|
||||
free(asmbuf);
|
||||
caddr += bsize;
|
||||
|
||||
rk65c02_start(&e);
|
||||
|
@ -9,9 +9,11 @@
|
||||
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "assembler.h"
|
||||
#include "instruction.h"
|
||||
#include "debug.h"
|
||||
#include "utils.h"
|
||||
#include "log.h"
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(breakpoint);
|
||||
ATF_TC_BODY(breakpoint, tc)
|
||||
@ -54,10 +56,13 @@ ATF_TC_BODY(trace, tc)
|
||||
trace_t *tr;
|
||||
int i;
|
||||
|
||||
rk65c02_loglevel_set(LOG_TRACE);
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
a = assemble_init(&b, ROM_LOAD_ADDR);
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
|
||||
e.regs.PC = ROM_LOAD_ADDR;
|
||||
debug_trace_set(&e, true);
|
||||
|
||||
|
@ -6,8 +6,10 @@
|
||||
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "assembler.h"
|
||||
#include "instruction.h"
|
||||
#include "debug.h"
|
||||
#include "log.h"
|
||||
#include "utils.h"
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_bit);
|
||||
@ -122,7 +124,7 @@ ATF_TC_BODY(emul_cmp, tc)
|
||||
e.regs.Y = 0x01;
|
||||
bus_write_1(&b, 0x22, 0x0);
|
||||
bus_write_1(&b, 0x23, 0x20);
|
||||
bus_write_1(&b, 0x2000, 0xF);
|
||||
bus_write_1(&b, 0x2001, 0x10);
|
||||
rk65c02_dump_regs(e.regs);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_cmp_izpy.rom", tc));
|
||||
rk65c02_dump_regs(e.regs);
|
||||
@ -427,6 +429,33 @@ ATF_TC_BODY(emul_lda, tc)
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_zp.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0xAE);
|
||||
|
||||
/* LDA zero page X */
|
||||
bus_write_1(&b, 0x12, 0xAF);
|
||||
e.regs.X = 0x1;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_zpx.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0xAF);
|
||||
|
||||
/* LDA indirect zero page */
|
||||
bus_write_1(&b, 0x1A, 0x10);
|
||||
bus_write_1(&b, 0x1B, 0x2E);
|
||||
bus_write_1(&b, 0x2E10, 0xAA);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_izp.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0xAA);
|
||||
|
||||
/* LDA indirect zero page X */
|
||||
bus_write_1(&b, 0x20, 0);
|
||||
bus_write_1(&b, 0x21, 0x2E);
|
||||
bus_write_1(&b, 0x2E00, 0x55);
|
||||
e.regs.X = 0x01;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_izpx.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0x55);
|
||||
|
||||
/* LDA indirect zero page Y */
|
||||
bus_write_1(&b, 0x2E10, 0xAA);
|
||||
e.regs.Y = 0x10;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_izpy.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0xAA);
|
||||
|
||||
/* LDA absolute */
|
||||
bus_write_1(&b, 0x2F5A, 0xEA);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_abs.rom", tc));
|
||||
@ -438,7 +467,7 @@ ATF_TC_BODY(emul_lda, tc)
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_absx.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0xEB);
|
||||
|
||||
/* LDA absolute X */
|
||||
/* LDA absolute Y */
|
||||
bus_write_1(&b, 0x2F5E, 0xEC);
|
||||
e.regs.Y = 0x5E;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_lda_absy.rom", tc));
|
||||
@ -456,11 +485,28 @@ ATF_TC_BODY(emul_stz, tc)
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
/* STZ zp */
|
||||
/* STZ zero page */
|
||||
bus_write_1(&b, 0x10, 0xAA);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_stz_zp.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x10) == 0x00);
|
||||
|
||||
/* STZ zero page X */
|
||||
bus_write_1(&b, 0x15, 0x55);
|
||||
e.regs.X = 0x4;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_stz_zpx.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x15) == 0x00);
|
||||
|
||||
/* STZ absolute */
|
||||
bus_write_1(&b, 0x2000, 0xAA);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_stz_abs.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x2000) == 0x00);
|
||||
|
||||
/* STZ absolute X */
|
||||
bus_write_1(&b, 0x2005, 0x55);
|
||||
e.regs.X = 0x1;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_stz_absx.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x2005) == 0x00);
|
||||
|
||||
bus_finish(&b);
|
||||
}
|
||||
|
||||
@ -542,6 +588,124 @@ ATF_TC_BODY(emul_and, tc)
|
||||
bus_finish(&b);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_asl);
|
||||
ATF_TC_BODY(emul_asl, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.A = 0xAA;
|
||||
e.regs.X = 0x1;
|
||||
bus_write_1(&b, 0x10, 0xAA);
|
||||
bus_write_1(&b, 0x11, 0xAA);
|
||||
bus_write_1(&b, 0x300, 0xFF);
|
||||
bus_write_1(&b, 0x301, 0xFF);
|
||||
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_asl.rom", tc));
|
||||
|
||||
ATF_CHECK(e.regs.A == 0x54);
|
||||
ATF_CHECK(bus_read_1(&b, 0x10) == 0x54);
|
||||
ATF_CHECK(bus_read_1(&b, 0x11) == 0x54);
|
||||
ATF_CHECK(bus_read_1(&b, 0x300) == 0xFE);
|
||||
ATF_CHECK(bus_read_1(&b, 0x301) == 0xFE);
|
||||
ATF_CHECK(e.regs.P & P_CARRY);
|
||||
|
||||
bus_finish(&b);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_lsr);
|
||||
ATF_TC_BODY(emul_lsr, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.A = 0x55;
|
||||
e.regs.X = 0x1;
|
||||
bus_write_1(&b, 0x10, 0x55);
|
||||
bus_write_1(&b, 0x11, 0x55);
|
||||
bus_write_1(&b, 0x300, 0xFF);
|
||||
bus_write_1(&b, 0x301, 0xFF);
|
||||
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_lsr.rom", tc));
|
||||
|
||||
ATF_CHECK(e.regs.A == 0x2A);
|
||||
ATF_CHECK(bus_read_1(&b, 0x10) == 0x2A);
|
||||
ATF_CHECK(bus_read_1(&b, 0x11) == 0x2A);
|
||||
ATF_CHECK(bus_read_1(&b, 0x300) == 0x7F);
|
||||
ATF_CHECK(bus_read_1(&b, 0x301) == 0x7F);
|
||||
ATF_CHECK(e.regs.P & P_CARRY);
|
||||
|
||||
bus_finish(&b);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_rol);
|
||||
ATF_TC_BODY(emul_rol, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.A = 0x55;
|
||||
e.regs.P |= P_CARRY;
|
||||
e.regs.X = 0x1;
|
||||
|
||||
bus_write_1(&b, 0x10, 0x55);
|
||||
bus_write_1(&b, 0x11, 0xFF);
|
||||
bus_write_1(&b, 0x200, 0xAA);
|
||||
bus_write_1(&b, 0x201, 0x01);
|
||||
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_rol.rom", tc));
|
||||
|
||||
ATF_CHECK(e.regs.A == 0xAB);
|
||||
ATF_CHECK(bus_read_1(&b, 0x10) == 0xAA);
|
||||
ATF_CHECK(bus_read_1(&b, 0x11) == 0xFE);
|
||||
ATF_CHECK(bus_read_1(&b, 0x200) == 0x55);
|
||||
ATF_CHECK(bus_read_1(&b, 0x201) == 0x3);
|
||||
|
||||
ATF_CHECK(e.regs.P ^ P_CARRY);
|
||||
|
||||
bus_finish(&b);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_ror);
|
||||
ATF_TC_BODY(emul_ror, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.A = 0x55;
|
||||
e.regs.P |= P_CARRY;
|
||||
e.regs.X = 0x1;
|
||||
|
||||
bus_write_1(&b, 0x10, 0x55);
|
||||
bus_write_1(&b, 0x11, 0xFF);
|
||||
bus_write_1(&b, 0x200, 0xAA);
|
||||
bus_write_1(&b, 0x201, 0x01);
|
||||
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_ror.rom", tc));
|
||||
|
||||
ATF_CHECK(e.regs.A == 0xAA);
|
||||
ATF_CHECK(bus_read_1(&b, 0x10) == 0xAA);
|
||||
ATF_CHECK(bus_read_1(&b, 0x11) == 0xFF);
|
||||
ATF_CHECK(bus_read_1(&b, 0x200) == 0xD5);
|
||||
ATF_CHECK(bus_read_1(&b, 0x201) == 0x0);
|
||||
|
||||
ATF_CHECK(e.regs.P & P_CARRY);
|
||||
|
||||
bus_finish(&b);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_nop);
|
||||
ATF_TC_BODY(emul_nop, tc)
|
||||
{
|
||||
@ -606,15 +770,65 @@ ATF_TC_BODY(emul_sta, tc)
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_sta_izpx.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x2010) == 0xAA);
|
||||
/* STA indirect zero page Y */
|
||||
e.regs.A = 0x54;
|
||||
e.regs.A = 0x55;
|
||||
e.regs.X = 0;
|
||||
e.regs.Y = 0x1;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_sta_izpy.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x2010) == 0x55);
|
||||
ATF_CHECK(bus_read_1(&b, 0x2011) == 0x55);
|
||||
|
||||
bus_finish(&b);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_stx);
|
||||
ATF_TC_BODY(emul_stx, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
/* STX zero page */
|
||||
e.regs.X = 0xAA;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_stx_zp.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x20) == 0xAA);
|
||||
/* STX zero page Y */
|
||||
e.regs.X = 0x55;
|
||||
e.regs.Y = 0x1;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_stx_zpy.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x20) == 0x55);
|
||||
/* STX absolute */
|
||||
e.regs.X = 0xAA;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_stx_abs.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x2010) == 0xAA);
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_sty);
|
||||
ATF_TC_BODY(emul_sty, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
/* STY zero page */
|
||||
e.regs.Y = 0xAA;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_sty_zp.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x20) == 0xAA);
|
||||
/* STY zero page X */
|
||||
e.regs.Y = 0x55;
|
||||
e.regs.X = 0x1;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_sty_zpx.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x20) == 0x55);
|
||||
/* STY absolute */
|
||||
e.regs.Y = 0xAA;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_sty_abs.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x2010) == 0xAA);
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_ora);
|
||||
ATF_TC_BODY(emul_ora, tc)
|
||||
{
|
||||
@ -673,7 +887,7 @@ ATF_TC_BODY(emul_ora, tc)
|
||||
e.regs.A = 0xAA;
|
||||
e.regs.X = 0;
|
||||
e.regs.Y = 0x1;
|
||||
bus_write_1(&b, 0x2A04, 0x54);
|
||||
bus_write_1(&b, 0x2A05, 0x55);
|
||||
bus_write_1(&b, 0x14, 0x04);
|
||||
bus_write_1(&b, 0x15, 0x2A);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_ora_izpy.rom", tc));
|
||||
@ -682,6 +896,31 @@ ATF_TC_BODY(emul_ora, tc)
|
||||
bus_finish(&b);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_tsx_txs);
|
||||
ATF_TC_BODY(emul_tsx_txs, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
uint8_t prevflags;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.SP = 0xFF;
|
||||
e.regs.X = 0x10;
|
||||
|
||||
prevflags = e.regs.P;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_txs.rom", tc));
|
||||
ATF_CHECK(e.regs.P == prevflags);
|
||||
ATF_CHECK(e.regs.SP == 0x10);
|
||||
|
||||
e.regs.X = 0;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_tsx.rom", tc));
|
||||
ATF_CHECK(e.regs.X == 0x10);
|
||||
|
||||
bus_finish(&b);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_txa_tya_tax_tay);
|
||||
ATF_TC_BODY(emul_txa_tya_tax_tay, tc)
|
||||
{
|
||||
@ -892,6 +1131,88 @@ ATF_TC_BODY(emul_jsr_rts, tc)
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_bbr);
|
||||
ATF_TC_BODY(emul_bbr, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
assembler_t a;
|
||||
|
||||
uint8_t i, val;
|
||||
uint16_t opc;
|
||||
|
||||
char instr[] = "bbr ";
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
a = assemble_init(&b, ROM_LOAD_ADDR);
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.PC = ROM_LOAD_ADDR;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
val = 0xFF & ~(1 << i);
|
||||
bus_write_1(&b, 0x10+i, val);
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
instr[3] = '0'+i;
|
||||
ATF_REQUIRE(assemble_single(&a, instr, ZPR, 0x10+i, 0x70));
|
||||
}
|
||||
|
||||
e.runtime_disassembly = true;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
opc = e.regs.PC;
|
||||
rk65c02_step(&e, 1);
|
||||
ATF_CHECK(e.regs.PC == opc + 2 + 0x70);
|
||||
rk65c02_dump_regs(e.regs);
|
||||
e.regs.PC = ROM_LOAD_ADDR + (3 * (i + 1));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_bbs);
|
||||
ATF_TC_BODY(emul_bbs, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
assembler_t a;
|
||||
|
||||
uint8_t i;
|
||||
uint16_t opc;
|
||||
|
||||
char instr[] = "bbs ";
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
a = assemble_init(&b, ROM_LOAD_ADDR);
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.PC = ROM_LOAD_ADDR;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
bus_write_1(&b, 0x10+i, 1 << i);
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
instr[3] = '0'+i;
|
||||
ATF_REQUIRE(assemble_single(&a, instr, ZPR, 0x10+i, 0x70));
|
||||
}
|
||||
|
||||
e.runtime_disassembly = true;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
opc = e.regs.PC;
|
||||
rk65c02_step(&e, 1);
|
||||
ATF_CHECK(e.regs.PC == opc + 2 + 0x70);
|
||||
rk65c02_dump_regs(e.regs);
|
||||
e.regs.PC = ROM_LOAD_ADDR + (3 * (i + 1));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_branch);
|
||||
ATF_TC_BODY(emul_branch, tc)
|
||||
{
|
||||
@ -1165,6 +1486,20 @@ ATF_TC_BODY(emul_sign_overflow_thorough, tc)
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_signed_comparison);
|
||||
ATF_TC_BODY(emul_signed_comparison, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_signed_comparison.rom", tc));
|
||||
ATF_CHECK(bus_read_1(&b, 0x13) == 0x0);
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_sbc);
|
||||
ATF_TC_BODY(emul_sbc, tc)
|
||||
{
|
||||
@ -1181,6 +1516,70 @@ ATF_TC_BODY(emul_sbc, tc)
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_adc);
|
||||
ATF_TC_BODY(emul_adc, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.P &= ~P_CARRY;
|
||||
e.regs.A = 0x2;
|
||||
|
||||
/* ADC immediate */
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_adc_imm.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0x05);
|
||||
ATF_CHECK(!(e.regs.P & P_ZERO));
|
||||
ATF_CHECK(!(e.regs.P & P_CARRY));
|
||||
ATF_CHECK(!(e.regs.P & P_SIGN_OVERFLOW));
|
||||
ATF_CHECK(!(e.regs.P & P_NEGATIVE));
|
||||
|
||||
/* ADC zero page */
|
||||
bus_write_1(&b, 0x10, 0xFB);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_adc_zp.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0x00);
|
||||
ATF_CHECK(e.regs.P & P_ZERO);
|
||||
ATF_CHECK(e.regs.P & P_CARRY);
|
||||
ATF_CHECK(!(e.regs.P & P_SIGN_OVERFLOW));
|
||||
ATF_CHECK(!(e.regs.P & P_NEGATIVE));
|
||||
|
||||
/* ADC zero page X */
|
||||
e.regs.X = 0x01;
|
||||
bus_write_1(&b, 0x12, 0x3);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_adc_zpx.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0x04);
|
||||
ATF_CHECK(!(e.regs.P & P_ZERO));
|
||||
ATF_CHECK(!(e.regs.P & P_CARRY));
|
||||
ATF_CHECK(!(e.regs.P & P_SIGN_OVERFLOW));
|
||||
ATF_CHECK(!(e.regs.P & P_NEGATIVE));
|
||||
|
||||
/* ADC absolute */
|
||||
e.regs.A = 0x55;
|
||||
bus_write_1(&b, 0x2A00, 0xAB);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_adc_abs.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0x0);
|
||||
ATF_CHECK(e.regs.P & P_ZERO);
|
||||
ATF_CHECK(e.regs.P & P_CARRY);
|
||||
ATF_CHECK(!(e.regs.P & P_SIGN_OVERFLOW));
|
||||
ATF_CHECK(!(e.regs.P & P_NEGATIVE));
|
||||
|
||||
/* ADC absolute X */
|
||||
e.regs.A = 0x50;
|
||||
e.regs.X = 0x10;
|
||||
bus_write_1(&b, 0x2A10, 0x50);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_adc_absx.rom", tc));
|
||||
ATF_CHECK(e.regs.A == 0xA1);
|
||||
ATF_CHECK(!(e.regs.P & P_ZERO));
|
||||
ATF_CHECK(!(e.regs.P & P_CARRY));
|
||||
ATF_CHECK(e.regs.P & P_SIGN_OVERFLOW);
|
||||
ATF_CHECK(e.regs.P & P_NEGATIVE);
|
||||
|
||||
rk65c02_dump_regs(e.regs);
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_adc_bcd);
|
||||
ATF_TC_BODY(emul_adc_bcd, tc)
|
||||
{
|
||||
@ -1202,7 +1601,6 @@ ATF_TC_BODY(emul_adc_bcd, tc)
|
||||
ATF_CHECK(bus_read_1(&b, 0x41) & P_CARRY);
|
||||
|
||||
rk65c02_dump_regs(e.regs);
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_sbc_bcd);
|
||||
@ -1245,6 +1643,19 @@ ATF_TC_BODY(emul_adc_16bit, tc)
|
||||
|
||||
ATF_CHECK(bus_read_1(&b, 0x66) == 0xFF);
|
||||
ATF_CHECK(bus_read_1(&b, 0x67) == 0xFF);
|
||||
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
bus_write_1(&b, 0x62, 0xFF);
|
||||
bus_write_1(&b, 0x63, 0xFF);
|
||||
bus_write_1(&b, 0x64, 0xFF);
|
||||
bus_write_1(&b, 0x65, 0xFF);
|
||||
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_adc_16bit.rom", tc));
|
||||
|
||||
ATF_CHECK(bus_read_1(&b, 0x66) == 0xFE);
|
||||
ATF_CHECK(bus_read_1(&b, 0x67) == 0xFF);
|
||||
|
||||
rk65c02_dump_regs(e.regs);
|
||||
|
||||
}
|
||||
@ -1348,13 +1759,135 @@ ATF_TC_BODY(emul_smb, tc)
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_trb);
|
||||
ATF_TC_BODY(emul_trb, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_trb.rom", tc));
|
||||
|
||||
ATF_CHECK(bus_read_1(&b, 0x10) == 0x84);
|
||||
ATF_CHECK(bus_read_1(&b, 0x11) == 0xA6);
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_tsb);
|
||||
ATF_TC_BODY(emul_tsb, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_tsb.rom", tc));
|
||||
|
||||
ATF_CHECK(bus_read_1(&b, 0x10) == 0xB7);
|
||||
ATF_CHECK(bus_read_1(&b, 0x11) == 0xE7);
|
||||
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_wrap_izpx);
|
||||
ATF_TC_BODY(emul_wrap_izpx, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.A = 0xAA;
|
||||
e.regs.X = 0xA0;
|
||||
|
||||
bus_write_1(&b, 0xB0, 0x10);
|
||||
bus_write_1(&b, 0xB1, 0x20);
|
||||
bus_write_1(&b, 0x90, 0x11);
|
||||
bus_write_1(&b, 0x91, 0x20);
|
||||
|
||||
bus_write_1(&b, 0x2011, 0x55);
|
||||
|
||||
rk65c02_dump_regs(e.regs);
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_wrap_izpx.rom", tc));
|
||||
rk65c02_dump_regs(e.regs);
|
||||
|
||||
ATF_CHECK(bus_read_1(&b, 0x2010) == 0xAA);
|
||||
ATF_CHECK(e.regs.A == 0x55);
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_wrap_zpx);
|
||||
ATF_TC_BODY(emul_wrap_zpx, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
uint16_t i;
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.A = 0xAA;
|
||||
e.regs.X = 0x7F;
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_wrap_zpx.rom", tc));
|
||||
|
||||
ATF_CHECK(bus_read_1(&b, 0x8F) == 0xAA);
|
||||
ATF_CHECK(bus_read_1(&b, 0xFF) == 0xAA);
|
||||
ATF_CHECK(bus_read_1(&b, 0x00) == 0xAA);
|
||||
ATF_CHECK(bus_read_1(&b, 0x01) == 0xAA);
|
||||
ATF_CHECK(bus_read_1(&b, 0x7E) == 0xAA);
|
||||
|
||||
i = 0x200;
|
||||
|
||||
while (i < 0x205) {
|
||||
ATF_CHECK(bus_read_1(&b, i) == 0xAA);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(emul_invalid_opcode);
|
||||
ATF_TC_BODY(emul_invalid_opcode, tc)
|
||||
{
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
struct reg_state rorig;
|
||||
|
||||
rk65c02_loglevel_set(LOG_DEBUG);
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.runtime_disassembly = true;
|
||||
rorig = e.regs;
|
||||
|
||||
ATF_REQUIRE(rom_start(&e, "test_emulation_invalid_opcode.rom", tc));
|
||||
|
||||
ATF_CHECK(e.regs.A == rorig.A);
|
||||
ATF_CHECK(e.regs.X == rorig.X);
|
||||
ATF_CHECK(e.regs.Y == rorig.Y);
|
||||
ATF_CHECK(e.regs.SP == rorig.SP);
|
||||
ATF_CHECK(e.regs.P == rorig.P);
|
||||
|
||||
ATF_CHECK(e.regs.PC == 0xC00A);
|
||||
|
||||
rk65c02_log(LOG_INFO, "PC: %x", e.regs.PC);
|
||||
|
||||
}
|
||||
|
||||
|
||||
ATF_TP_ADD_TCS(tp)
|
||||
{
|
||||
ATF_TP_ADD_TC(tp, emul_and);
|
||||
ATF_TP_ADD_TC(tp, emul_asl);
|
||||
ATF_TP_ADD_TC(tp, emul_adc);
|
||||
ATF_TP_ADD_TC(tp, emul_adc_16bit);
|
||||
ATF_TP_ADD_TC(tp, emul_adc_bcd);
|
||||
ATF_TP_ADD_TC(tp, emul_bit);
|
||||
ATF_TP_ADD_TC(tp, emul_branch);
|
||||
ATF_TP_ADD_TC(tp, emul_bbr);
|
||||
ATF_TP_ADD_TC(tp, emul_bbs);
|
||||
ATF_TP_ADD_TC(tp, emul_cmp);
|
||||
ATF_TP_ADD_TC(tp, emul_cpx);
|
||||
ATF_TP_ADD_TC(tp, emul_cpy);
|
||||
@ -1368,23 +1901,38 @@ ATF_TP_ADD_TCS(tp)
|
||||
ATF_TP_ADD_TC(tp, emul_jmp);
|
||||
ATF_TP_ADD_TC(tp, emul_jsr_rts);
|
||||
ATF_TP_ADD_TC(tp, emul_lda);
|
||||
ATF_TP_ADD_TC(tp, emul_lsr);
|
||||
ATF_TP_ADD_TC(tp, emul_nop);
|
||||
ATF_TP_ADD_TC(tp, emul_ora);
|
||||
ATF_TP_ADD_TC(tp, emul_stz);
|
||||
ATF_TP_ADD_TC(tp, emul_php_plp);
|
||||
ATF_TP_ADD_TC(tp, emul_phx_phy_plx_ply);
|
||||
ATF_TP_ADD_TC(tp, emul_rol);
|
||||
ATF_TP_ADD_TC(tp, emul_ror);
|
||||
ATF_TP_ADD_TC(tp, emul_stack);
|
||||
ATF_TP_ADD_TC(tp, emul_txa_tya_tax_tay);
|
||||
ATF_TP_ADD_TC(tp, emul_tsx_txs);
|
||||
ATF_TP_ADD_TC(tp, emul_sta);
|
||||
ATF_TP_ADD_TC(tp, emul_stx);
|
||||
ATF_TP_ADD_TC(tp, emul_sty);
|
||||
ATF_TP_ADD_TC(tp, emul_sbc);
|
||||
ATF_TP_ADD_TC(tp, emul_sbc_16bit);
|
||||
ATF_TP_ADD_TC(tp, emul_sbc_bcd);
|
||||
ATF_TP_ADD_TC(tp, emul_rmb);
|
||||
ATF_TP_ADD_TC(tp, emul_smb);
|
||||
ATF_TP_ADD_TC(tp, emul_trb);
|
||||
ATF_TP_ADD_TC(tp, emul_tsb);
|
||||
|
||||
ATF_TP_ADD_TC(tp, emul_sign_overflow_basic);
|
||||
ATF_TP_ADD_TC(tp, emul_sign_overflow_thorough);
|
||||
|
||||
ATF_TP_ADD_TC(tp, emul_signed_comparison);
|
||||
|
||||
ATF_TP_ADD_TC(tp, emul_wrap_zpx);
|
||||
ATF_TP_ADD_TC(tp, emul_wrap_izpx);
|
||||
|
||||
ATF_TP_ADD_TC(tp, emul_invalid_opcode);
|
||||
|
||||
return (atf_no_error());
|
||||
}
|
||||
|
||||
|
3
test/test_emulation_adc_abs.s
Normal file
3
test/test_emulation_adc_abs.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: adc 0x2A00
|
||||
stp
|
||||
|
3
test/test_emulation_adc_absx.s
Normal file
3
test/test_emulation_adc_absx.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: adc 0x2A00,X
|
||||
stp
|
||||
|
3
test/test_emulation_adc_imm.s
Normal file
3
test/test_emulation_adc_imm.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: adc #0x3
|
||||
stp
|
||||
|
3
test/test_emulation_adc_zp.s
Normal file
3
test/test_emulation_adc_zp.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: adc 0x10
|
||||
stp
|
||||
|
3
test/test_emulation_adc_zpx.s
Normal file
3
test/test_emulation_adc_zpx.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: adc 0x11,X
|
||||
stp
|
||||
|
7
test/test_emulation_asl.s
Normal file
7
test/test_emulation_asl.s
Normal file
@ -0,0 +1,7 @@
|
||||
start: asl A
|
||||
asl 0x10
|
||||
asl 0x10,X
|
||||
asl 0x300
|
||||
asl 0x300,X
|
||||
stp
|
||||
|
11
test/test_emulation_invalid_opcode.s
Normal file
11
test/test_emulation_invalid_opcode.s
Normal file
@ -0,0 +1,11 @@
|
||||
.byte 0x42
|
||||
.byte 0xFF
|
||||
.byte 0x43
|
||||
.byte 0x44
|
||||
.byte 0xFF
|
||||
.byte 0x4B
|
||||
.byte 0xFC
|
||||
.byte 0xFF
|
||||
.byte 0xFF
|
||||
stp
|
||||
|
3
test/test_emulation_lda_izp.s
Normal file
3
test/test_emulation_lda_izp.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: lda (0x1A)
|
||||
stp
|
||||
|
3
test/test_emulation_lda_izpx.s
Normal file
3
test/test_emulation_lda_izpx.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: lda (0x1F,X)
|
||||
stp
|
||||
|
3
test/test_emulation_lda_izpy.s
Normal file
3
test/test_emulation_lda_izpy.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: lda (0x20),Y
|
||||
stp
|
||||
|
3
test/test_emulation_lda_zpx.s
Normal file
3
test/test_emulation_lda_zpx.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: lda 0x11,X
|
||||
stp
|
||||
|
7
test/test_emulation_lsr.s
Normal file
7
test/test_emulation_lsr.s
Normal file
@ -0,0 +1,7 @@
|
||||
start: lsr A
|
||||
lsr 0x10
|
||||
lsr 0x10,X
|
||||
lsr 0x300
|
||||
lsr 0x300,X
|
||||
stp
|
||||
|
7
test/test_emulation_rol.s
Normal file
7
test/test_emulation_rol.s
Normal file
@ -0,0 +1,7 @@
|
||||
start: rol A
|
||||
rol 0x10
|
||||
rol 0x10,X
|
||||
rol 0x200
|
||||
rol 0x200,X
|
||||
stp
|
||||
|
7
test/test_emulation_ror.s
Normal file
7
test/test_emulation_ror.s
Normal file
@ -0,0 +1,7 @@
|
||||
start: ror A
|
||||
ror 0x10
|
||||
ror 0x10,X
|
||||
ror 0x200
|
||||
ror 0x200,X
|
||||
stp
|
||||
|
100
test/test_emulation_signed_comparison.s
Normal file
100
test/test_emulation_signed_comparison.s
Normal file
@ -0,0 +1,100 @@
|
||||
; stolen from: http://www.6502.org/tutorials/compare_beyond.html
|
||||
; adapted to vasm and std syntax by rkujawa
|
||||
;
|
||||
; Test the signed compare routine
|
||||
;
|
||||
; Returns with ERROR = 0 if the test passes, ERROR = 1 if the test fails
|
||||
;
|
||||
; Three (additional) memory locations are used: ERROR, N1, and N2
|
||||
; These may be located anywhere convenient in RAM
|
||||
;
|
||||
.org 0xC000
|
||||
.set N1, 0x10
|
||||
.set N2, 0x11
|
||||
.set ERROR, 0x12
|
||||
TEST: cld ; Clear decimal mode for test
|
||||
lda #1
|
||||
sta ERROR ; Store 1 in ERROR until test passes
|
||||
tsx ; Save stack pointer so subroutines can exit with ERROR = 1
|
||||
;
|
||||
; Test N1 positive, N2 positive
|
||||
;
|
||||
lda #0 ; 0
|
||||
sta N1
|
||||
PP1: lda #0 ; 0
|
||||
sta N2
|
||||
PP2: jsr SUCMP ; Verify that the signed and unsigned comparison agree
|
||||
inc N2
|
||||
bpl PP2
|
||||
inc N1
|
||||
bpl PP1
|
||||
;
|
||||
; Test N1 positive, N2 negative
|
||||
;
|
||||
lda #0 ; 0
|
||||
sta N1
|
||||
PN1: lda #0x80 ; -128
|
||||
sta N2
|
||||
PN2: jsr SCMP ; Signed comparison
|
||||
bmi TEST1 ; if N1 (positive) < N2 (negative) exit with ERROR = 1
|
||||
inc N2
|
||||
bmi PN2
|
||||
inc N1
|
||||
bpl PN1
|
||||
;
|
||||
; Test N1 negative, N2 positive
|
||||
;
|
||||
lda #0x80 ; -128
|
||||
sta N1
|
||||
NP1: lda #0 ; 0
|
||||
sta N2
|
||||
NP2: jsr SCMP ; Signed comparison
|
||||
bpl TEST1 ; if N1 (negative) >= N2 (positive) exit with ERROR = 1
|
||||
inc N2
|
||||
bpl NP2
|
||||
inc N1
|
||||
bmi NP1
|
||||
;
|
||||
; Test N1 negative, N2 negative
|
||||
;
|
||||
lda #0x80 ; -128
|
||||
sta N1
|
||||
NN1: lda #0x80 ; -128
|
||||
sta N2
|
||||
NN2: jsr SUCMP ; Verify that the signed and unsigned comparisons agree
|
||||
inc N2
|
||||
bmi NN2
|
||||
inc N1
|
||||
bmi NN1
|
||||
|
||||
lda #0
|
||||
sta ERROR ; All tests pass, so store 0 in ERROR
|
||||
TEST1: stp
|
||||
|
||||
; Signed comparison
|
||||
;
|
||||
; Returns with:
|
||||
; N=0 (BPL branches) if N1 >= N2 (signed)
|
||||
; N=1 (BMI branches) if N1 < N2 (signed)
|
||||
;
|
||||
; The unsigned comparison result is returned in the C flag (for free)
|
||||
;
|
||||
SCMP: sec
|
||||
lda N1 ; Compare N1 and N2
|
||||
sbc N2
|
||||
bvc SCMP1 ; Branch if V = 0
|
||||
eor #0x80 ; Invert Accumulator bit 7 (which also inverts the N flag)
|
||||
SCMP1: rts
|
||||
|
||||
; Test the signed and unsigned comparisons to confirm that they agree
|
||||
;
|
||||
SUCMP: jsr SCMP ; Signed (and unsigned) comparison
|
||||
bcc SUCMP2 ; Branch if N1 < N2 (unsigned)
|
||||
bpl SUCMP1 ; N1 >= N2 (unsigned), branch if N1 >= N2 (signed)
|
||||
tsx ; reset stack and exit with ERROR = 1
|
||||
SUCMP1: rts
|
||||
SUCMP2: bmi SUCMP3 ; N1 < N2 (unsigned), branch if N1 < N2 (signed)
|
||||
tsx ; reset stack and exit with ERROR = 1
|
||||
SUCMP3: rts
|
||||
|
||||
|
3
test/test_emulation_stx_abs.s
Normal file
3
test/test_emulation_stx_abs.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: stx 0x2010
|
||||
stp
|
||||
|
3
test/test_emulation_stx_zp.s
Normal file
3
test/test_emulation_stx_zp.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: stx 0x20
|
||||
stp
|
||||
|
3
test/test_emulation_stx_zpy.s
Normal file
3
test/test_emulation_stx_zpy.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: stx 0x1F,Y
|
||||
stp
|
||||
|
3
test/test_emulation_sty_abs.s
Normal file
3
test/test_emulation_sty_abs.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: sty 0x2010
|
||||
stp
|
||||
|
3
test/test_emulation_sty_zp.s
Normal file
3
test/test_emulation_sty_zp.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: sty 0x20
|
||||
stp
|
||||
|
3
test/test_emulation_sty_zpx.s
Normal file
3
test/test_emulation_sty_zpx.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: sty 0x1F,X
|
||||
stp
|
||||
|
3
test/test_emulation_stz_abs.s
Normal file
3
test/test_emulation_stz_abs.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: stz 0x2000
|
||||
stp
|
||||
|
3
test/test_emulation_stz_absx.s
Normal file
3
test/test_emulation_stz_absx.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: stz 0x2004,X
|
||||
stp
|
||||
|
3
test/test_emulation_stz_zpx.s
Normal file
3
test/test_emulation_stz_zpx.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: stz 0x11,X
|
||||
stp
|
||||
|
12
test/test_emulation_trb.s
Normal file
12
test/test_emulation_trb.s
Normal file
@ -0,0 +1,12 @@
|
||||
start: lda #0xa6
|
||||
sta 0x10
|
||||
lda #0x33
|
||||
trb 0x10
|
||||
|
||||
lda #0xa6
|
||||
sta 0x11
|
||||
lda #0x41
|
||||
trb 0x11
|
||||
|
||||
stp
|
||||
|
12
test/test_emulation_tsb.s
Normal file
12
test/test_emulation_tsb.s
Normal file
@ -0,0 +1,12 @@
|
||||
start: lda #0xa6
|
||||
sta 0x10
|
||||
lda #0x33
|
||||
tsb 0x10
|
||||
|
||||
lda #0xa6
|
||||
sta 0x11
|
||||
lda #0x41
|
||||
tsb 0x11
|
||||
|
||||
stp
|
||||
|
3
test/test_emulation_tsx.s
Normal file
3
test/test_emulation_tsx.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: tsx
|
||||
stp
|
||||
|
3
test/test_emulation_txs.s
Normal file
3
test/test_emulation_txs.s
Normal file
@ -0,0 +1,3 @@
|
||||
start: txs
|
||||
stp
|
||||
|
4
test/test_emulation_wrap_izpx.s
Normal file
4
test/test_emulation_wrap_izpx.s
Normal file
@ -0,0 +1,4 @@
|
||||
start: sta (0x10,X)
|
||||
lda (0xF0,X)
|
||||
|
||||
stp
|
18
test/test_emulation_wrap_zpx.s
Normal file
18
test/test_emulation_wrap_zpx.s
Normal file
@ -0,0 +1,18 @@
|
||||
start: sta 0x10,X
|
||||
sta 0x80,X
|
||||
sta 0x81,X
|
||||
sta 0x82,X
|
||||
sta 0xFF,X
|
||||
|
||||
ldy 0x10,X
|
||||
sty 0x200
|
||||
ldy 0x80,X
|
||||
sty 0x201
|
||||
ldy 0x81,X
|
||||
sty 0x202
|
||||
ldy 0x82,X
|
||||
sty 0x203
|
||||
ldy 0xFF,X
|
||||
sty 0x204
|
||||
stp
|
||||
|
@ -5,9 +5,13 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "assembler.h"
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "instruction.h"
|
||||
#include "log.h"
|
||||
#include "device_ram.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#define ISR_ADDR 0xC100
|
||||
@ -23,7 +27,10 @@ ATF_TC_BODY(intr_brk, tc)
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
rk65c02_loglevel_set(LOG_TRACE);
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
bus_device_add(&b, device_ram_init(0x100), 0xFF00);
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
e.regs.PC = ROM_LOAD_ADDR;
|
||||
@ -81,17 +88,14 @@ ATF_TC_BODY(intr_rti, tc)
|
||||
|
||||
ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "nop"));
|
||||
ATF_REQUIRE(bus_load_buf(&b, israsmpc, asmbuf, bsize));
|
||||
free(asmbuf);
|
||||
israsmpc += bsize;
|
||||
|
||||
ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "rti"));
|
||||
ATF_REQUIRE(bus_load_buf(&b, israsmpc, asmbuf, bsize));
|
||||
free(asmbuf);
|
||||
israsmpc += bsize;
|
||||
|
||||
ATF_REQUIRE(assemble_single_buf_implied(&asmbuf, &bsize, "nop"));
|
||||
ATF_REQUIRE(bus_load_buf(&b, ROM_LOAD_ADDR, asmbuf, bsize));
|
||||
free(asmbuf);
|
||||
|
||||
/* There's a return address and saved processor flags on stack. */
|
||||
e.regs.SP = 0xFF;
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
ATF_TC_WITHOUT_HEAD(step1);
|
||||
@ -12,6 +14,8 @@ ATF_TC_BODY(step1, tc)
|
||||
rk65c02emu_t e;
|
||||
bus_t b;
|
||||
|
||||
rk65c02_loglevel_set(LOG_TRACE);
|
||||
|
||||
b = bus_init_with_default_devs();
|
||||
e = rk65c02_init(&b);
|
||||
|
||||
|
@ -1,10 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <atf-c.h>
|
||||
#include <gc/gc.h>
|
||||
|
||||
#include "bus.h"
|
||||
#include "rk65c02.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
@ -14,7 +18,7 @@ rom_path(const char *name, const atf_tc_t *tc)
|
||||
char *rompath;
|
||||
const char *srcdir;
|
||||
|
||||
rompath = malloc(PATH_MAX);
|
||||
rompath = GC_MALLOC(PATH_MAX);
|
||||
srcdir = atf_tc_get_config_var(tc, "srcdir");
|
||||
|
||||
strcpy(rompath, srcdir);
|
||||
@ -30,7 +34,7 @@ rom_start(rk65c02emu_t *e, const char *name, const atf_tc_t *tc)
|
||||
const char *path;
|
||||
|
||||
path = rom_path(name, tc);
|
||||
printf("%s\n", path);
|
||||
rk65c02_log(LOG_INFO, "Loading ROM: %s", path);
|
||||
e->regs.PC = ROM_LOAD_ADDR;
|
||||
if(!bus_load_file(e->bus, ROM_LOAD_ADDR, path))
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user