16 Commits
v1.0a ... v1.2a

Author SHA1 Message Date
simon
8701007ad9 Bug fixes related to floppy drive 2017-11-14 20:58:07 -05:00
simon
cfb8050cee Added basic floppy drives #3. 2017-11-14 17:25:12 -05:00
simon
da7d050661 Universe warp around and maximum size #9 2017-11-13 22:45:19 -05:00
simon
3ee9b4be95 Added SAR Instructions #7. 2017-11-13 21:39:16 -05:00
simon
42421b7710 Added RCR/RCL Instructions #7. 2017-11-13 20:08:07 -05:00
simon
9979986c6a Added SAL Instruction #6. Added ROL/ROR Instructions #7. 2017-11-13 17:51:16 -05:00
simon
c5abe2efc5 Added ROL/ROR Instructions #7 as well as JC/JNC and JO/JNO instructions 2017-11-13 11:28:06 -05:00
Simon Fortier
fdfa568e07 Update README.md 2017-11-12 13:07:39 -05:00
simon
1bf1682cb3 Updated readme 2017-11-12 13:05:39 -05:00
simon
a3fa3c4c09 Added Battery Hardware. #2 2017-11-12 10:27:07 -05:00
Simon Fortier
f7ea14275c Create LICENSE 2017-11-12 09:32:08 -05:00
simon
04d51e1f1f Added XCHG Instruction #5. Placeholder class for LEA #1 2017-11-11 20:14:13 -05:00
simon
8c5dcd0fba Added Hologram Projector Hardware. Added GET_WORLD_POS in LiDAR. Fixed Drill. 2017-11-11 19:43:06 -05:00
simon
1a6f92a29d Added NOT Instruction 2017-11-11 15:27:06 -05:00
simon
3d9bfb2a42 Added Clock 2017-11-11 15:07:28 -05:00
simon
e2ed744479 Added Random number generator 2017-11-11 14:34:33 -05:00
60 changed files with 2133 additions and 258 deletions

674
LICENSE Normal file
View File

@@ -0,0 +1,674 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
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 <http://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
<http://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
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

View File

@@ -1,6 +1,11 @@
package net.simon987.cubotplugin; package net.simon987.cubotplugin;
import net.simon987.server.game.*; import net.simon987.server.GameServer;
import net.simon987.server.assembly.Memory;
import net.simon987.server.game.ControllableUnit;
import net.simon987.server.game.Direction;
import net.simon987.server.game.GameObject;
import net.simon987.server.game.Updatable;
import net.simon987.server.user.User; import net.simon987.server.user.User;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@@ -11,7 +16,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
private static final char MAP_INFO = 0x0080; private static final char MAP_INFO = 0x0080;
public static final int ID = 1; public static final int ID = 1;
private EffectType currentEmote = null; private char hologram = 0;
private char lastHologram = 0;
/** /**
* Hit points * Hit points
@@ -24,8 +30,13 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
private ArrayList<Integer> keyboardBuffer = new ArrayList<>(); private ArrayList<Integer> keyboardBuffer = new ArrayList<>();
private FloppyDisk floppyDisk;
private User parent; private User parent;
private int energy;
private int maxEnergy;
public Cubot() { public Cubot() {
} }
@@ -39,17 +50,16 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
public void update() { public void update() {
if (currentAction == CubotAction.WALKING) { if (currentAction == CubotAction.WALKING) {
if (!incrementLocation()) { if (spendEnergy(100)) {
//Couldn't walk if (!incrementLocation()) {
//Couldn't walk
currentAction = CubotAction.IDLE;
}
} else {
currentAction = CubotAction.IDLE; currentAction = CubotAction.IDLE;
} }
} }
if (currentEmote != null) {
// getWorld().getQueuedGameEffects().add(new GameEffect(currentEmote, getX(), getY()));
currentEmote = null;
}
/* /*
* CurrentAction is set during the code execution and this function is called right after * CurrentAction is set during the code execution and this function is called right after
* If no action as been set, the action sent to the client is the action in currentAction that * If no action as been set, the action sent to the client is the action in currentAction that
@@ -57,6 +67,10 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
*/ */
lastAction = currentAction; lastAction = currentAction;
currentAction = CubotAction.IDLE; currentAction = CubotAction.IDLE;
//Same principle for hologram
lastHologram = hologram;
hologram = 0;
} }
@Override @Override
@@ -70,6 +84,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
json.put("heldItem", heldItem); json.put("heldItem", heldItem);
json.put("hp", hp); json.put("hp", hp);
json.put("action", lastAction.ordinal()); json.put("action", lastAction.ordinal());
json.put("holo", (int) lastHologram);
json.put("energy", (int) lastHologram);
if (parent != null) { if (parent != null) {
json.put("parent", parent.getUsername()); //Only used client-side for now json.put("parent", parent.getUsername()); //Only used client-side for now
} }
@@ -86,6 +103,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
cubot.hp = (int)(long)json.get("hp"); cubot.hp = (int)(long)json.get("hp");
cubot.setDirection(Direction.getDirection((int)(long)json.get("direction"))); cubot.setDirection(Direction.getDirection((int)(long)json.get("direction")));
cubot.heldItem = (int)(long)json.get("heldItem"); cubot.heldItem = (int)(long)json.get("heldItem");
cubot.energy = (int) (long) json.get("energy");
cubot.maxEnergy = GameServer.INSTANCE.getConfig().getInt("battery_max_energy");
return cubot; return cubot;
@@ -128,4 +147,46 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit {
public CubotAction getAction() { public CubotAction getAction() {
return lastAction; return lastAction;
} }
public void setHologram(char hologram) {
this.hologram = hologram;
}
public char getHologram() {
return lastHologram;
}
public int getEnergy() {
return energy;
}
public void setEnergy(int energy) {
this.energy = energy;
}
public boolean spendEnergy(int spent) {
if (energy - spent < 0) {
return false;
} else {
energy -= spent;
return true;
}
}
public void setMaxEnergy(int maxEnergy) {
this.maxEnergy = maxEnergy;
}
public int getMaxEnergy() {
return maxEnergy;
}
@Override
public Memory getFloppyData() {
return ((CubotFloppyDrive) getParent().getCpu().getHardware(CubotFloppyDrive.DEFAULT_ADDRESS)).getFloppy().getMemory();
}
} }

View File

@@ -0,0 +1,59 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.json.simple.JSONObject;
public class CubotBattery extends CpuHardware {
public static final int DEFAULT_ADDRESS = 0x000A;
/**
* Hardware ID (Should be unique)
*/
public static final char HWID = 0x000A;
private Cubot cubot;
private static final int POLL = 1;
private static final int GET_MAX_CAPACITY = 2;
public CubotBattery(Cubot cubot) {
this.cubot = cubot;
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
if (a == POLL) {
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getEnergy());
} else if (a == GET_MAX_CAPACITY) {
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getMaxEnergy());
} else if (a == 0xFFFF) {
cubot.setEnergy(cubot.getMaxEnergy());
}
}
@Override
public char getId() {
return HWID;
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
json.put("cubot", cubot.getObjectId());
return json;
}
public static CubotBattery deserialize(JSONObject hwJSON) {
return new CubotBattery((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) hwJSON.get("cubot")));
}
}

View File

@@ -40,19 +40,19 @@ public class CubotDrill extends CpuHardware {
} else if (a == GATHER_SLOW || a == GATHER_FAST) { } else if (a == GATHER_SLOW || a == GATHER_FAST) {
if (cubot.getAction() != CubotAction.IDLE) { if (cubot.spendEnergy(1400)) {
int tile = cubot.getWorld().getTileMap().getTileAt(cubot.getX(), cubot.getY()); if (cubot.getAction() == CubotAction.IDLE) {
int tile = cubot.getWorld().getTileMap().getTileAt(cubot.getX(), cubot.getY());
if (tile == TileMap.IRON_TILE) { if (tile == TileMap.IRON_TILE) {
cubot.setHeldItem(TileMap.ITEM_IRON); cubot.setHeldItem(TileMap.ITEM_IRON);
cubot.setCurrentAction(CubotAction.DIGGING); cubot.setCurrentAction(CubotAction.DIGGING);
} else if (tile == TileMap.COPPER_TILE) { } else if (tile == TileMap.COPPER_TILE) {
cubot.setHeldItem(TileMap.ITEM_COPPER); cubot.setHeldItem(TileMap.ITEM_COPPER);
cubot.setCurrentAction(CubotAction.DIGGING); cubot.setCurrentAction(CubotAction.DIGGING);
} else { }
//System.out.println("FAILED: dig");
} }
} }

View File

@@ -0,0 +1,107 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.json.simple.JSONObject;
public class CubotFloppyDrive extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
static final char HWID = 0x000B;
public static final int DEFAULT_ADDRESS = 0x000B;
private static final int POLL = 1;
private static final int READ_SECTOR = 2;
private static final int WRITE_SECTOR = 3;
private Cubot cubot;
private FloppyDisk floppyDisk;
public CubotFloppyDrive(Cubot cubot) {
this.cubot = cubot;
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
if (a == POLL) {
if (floppyDisk != null) {
getCpu().getRegisterSet().getRegister("B").setValue(0);
} else {
getCpu().getRegisterSet().getRegister("B").setValue(1);
}
} else if (a == READ_SECTOR) {
if (floppyDisk == null) {
getCpu().getRegisterSet().getRegister("B").setValue(0);
} else {
if (cubot.spendEnergy(1)) {
getCpu().getRegisterSet().getRegister("B").setValue(1);
int x = getCpu().getRegisterSet().getRegister("X").getValue();
int y = getCpu().getRegisterSet().getRegister("Y").getValue();
floppyDisk.readSector(x, cubot.getParent().getCpu().getMemory(), y);
}
}
} else if (a == WRITE_SECTOR) {
if (floppyDisk == null) {
getCpu().getRegisterSet().getRegister("B").setValue(0);
} else {
if (cubot.spendEnergy(1)) {
getCpu().getRegisterSet().getRegister("B").setValue(1);
int x = getCpu().getRegisterSet().getRegister("X").getValue();
int y = getCpu().getRegisterSet().getRegister("Y").getValue();
floppyDisk.writeSector(x, cubot.getParent().getCpu().getMemory(), y);
}
}
}
}
@Override
public char getId() {
return HWID;
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
json.put("cubot", cubot.getObjectId());
if (floppyDisk != null) {
json.put("floppy", floppyDisk.serialise());
}
return json;
}
public static CubotFloppyDrive deserialize(JSONObject hwJSON) {
CubotFloppyDrive drive = new CubotFloppyDrive((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) hwJSON.get("cubot")));
if (hwJSON.containsKey("floppy")) {
drive.floppyDisk = FloppyDisk.deserialise((JSONObject) hwJSON.get("floppy"));
} else {
drive.floppyDisk = new FloppyDisk();
}
return drive;
}
public FloppyDisk getFloppy() {
return floppyDisk;
}
}

View File

@@ -0,0 +1,49 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.json.simple.JSONObject;
public class CubotHologram extends CpuHardware {
/**
* Hardware ID (Should be unique)
*/
static final char HWID = 0x0009;
public static final int DEFAULT_ADDRESS = 9;
private Cubot cubot;
public CubotHologram(Cubot cubot) {
this.cubot = cubot;
}
@Override
public void handleInterrupt(Status status) {
char a = getCpu().getRegisterSet().getRegister("A").getValue();
cubot.setHologram(a);
}
@Override
public char getId() {
return HWID;
}
public static CubotHologram deserialize(JSONObject hwJSON) {
return new CubotHologram((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) hwJSON.get("cubot")));
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
json.put("cubot", cubot.getObjectId());
return json;
}
}

View File

@@ -38,7 +38,9 @@ public class CubotInventory extends CpuHardware {
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getHeldItem()); getCpu().getRegisterSet().getRegister("B").setValue(cubot.getHeldItem());
} else if (a == CLEAR) { } else if (a == CLEAR) {
cubot.setHeldItem(0); if (cubot.spendEnergy(100)) {
cubot.setHeldItem(0);
}
} }
} }

View File

@@ -22,6 +22,7 @@ public class CubotLaser extends CpuHardware {
private Cubot cubot; private Cubot cubot;
private static final int WITHDRAW = 1; private static final int WITHDRAW = 1;
private static final int DEPOSIT = 2;
public CubotLaser(Cubot cubot) { public CubotLaser(Cubot cubot) {
@@ -42,33 +43,29 @@ public class CubotLaser extends CpuHardware {
if(a == WITHDRAW) { if(a == WITHDRAW) {
//System.out.println("withdraw");
Point frontTile = cubot.getFrontTile(); Point frontTile = cubot.getFrontTile();
ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y); ArrayList<GameObject> objects = cubot.getWorld().getGameObjectsAt(frontTile.x, frontTile.y);
if (cubot.getAction() != CubotAction.IDLE && objects.size() > 0) { if (cubot.getAction() != CubotAction.IDLE && objects.size() > 0) {
//FIXME: Problem here if more than 1 object
if (objects.get(0) instanceof InventoryHolder) { if (objects.get(0) instanceof InventoryHolder) {
//Take the item if (((InventoryHolder) objects.get(0)).canTakeItem(b)) {
if (((InventoryHolder) objects.get(0)).takeItem(b)) { if (cubot.spendEnergy(30)) {
//Take the item
((InventoryHolder) objects.get(0)).takeItem(b);
cubot.setHeldItem(b); cubot.setHeldItem(b);
//System.out.println("took " + b); cubot.setCurrentAction(CubotAction.WITHDRAWING);
cubot.setCurrentAction(CubotAction.WITHDRAWING); }
} else {
//The inventory holder can't provide this item
//todo Add emote here
// System.out.println("DEBUG: FAILED: take (The inventory holder can't provide this item)");
} }
} }
} else {
//Nothing in front
// System.out.println("DEBUG: FAILED: take (Nothing in front or Cubot is busy)");
} }
} else if (a == DEPOSIT) {
} }
} }

View File

@@ -39,11 +39,14 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
if(a == SET_DIR){ if(a == SET_DIR){
Direction dir = Direction.getDirection(b); Direction dir = Direction.getDirection(b);
if(dir != null){ if(dir != null){
cubot.setDirection(Direction.getDirection(b)); if (cubot.spendEnergy(20)) {
status.setErrorFlag(false); cubot.setDirection(Direction.getDirection(b));
status.setErrorFlag(false);
}
} else { } else {
status.setErrorFlag(true); status.setErrorFlag(true);
} }

View File

@@ -26,6 +26,7 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable {
private static final int GET_POS = 1; private static final int GET_POS = 1;
private static final int GET_PATH = 2; private static final int GET_PATH = 2;
private static final int GET_MAP = 3; private static final int GET_MAP = 3;
private static final int GET_WORLD_POS = 4;
private static final int MEMORY_MAP_START = 0x0100; private static final int MEMORY_MAP_START = 0x0100;
private static final int MEMORY_PATH_START = 0x0000; private static final int MEMORY_PATH_START = 0x0000;
@@ -51,75 +52,85 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable {
getCpu().getRegisterSet().getRegister("Y").setValue(cubot.getY()); getCpu().getRegisterSet().getRegister("Y").setValue(cubot.getY());
break; break;
case GET_PATH: case GET_PATH:
int b = getCpu().getRegisterSet().getRegister("B").getValue(); if (cubot.spendEnergy(50)) {
int destX = getCpu().getRegisterSet().getRegister("X").getValue(); int b = getCpu().getRegisterSet().getRegister("B").getValue();
int destY = getCpu().getRegisterSet().getRegister("Y").getValue(); int destX = getCpu().getRegisterSet().getRegister("X").getValue();
int destY = getCpu().getRegisterSet().getRegister("Y").getValue();
//Get path //Get path
ArrayList<Node> nodes = Pathfinder.findPath(cubot.getWorld(), cubot.getX(), cubot.getY(), ArrayList<Node> nodes = Pathfinder.findPath(cubot.getWorld(), cubot.getX(), cubot.getY(),
destX, destY, b); destX, destY, b);
// System.out.println(nodes.size() + " nodes"); //Write to memory
byte[] mem = getCpu().getMemory().getBytes();
//Write to memory int counter = MEMORY_PATH_START;
byte[] mem = getCpu().getMemory().getBytes();
int counter = 0; //todo get memory address from config/constant if (nodes != null) {
if (nodes != null) { Node lastNode = null;
Node lastNode = null; for (Node n : nodes) {
//Store the path as a sequence of directions
for (Node n : nodes) { if (lastNode == null) {
//Store the path as a sequence of directions lastNode = n;
continue;
}
if (n.x < lastNode.x) {
//West
mem[counter++] = 0;
mem[counter++] = 3;
} else if (n.x > lastNode.x) {
//East
mem[counter++] = 0;
mem[counter++] = 1;
} else if (n.y < lastNode.y) {
//North
mem[counter++] = 0;
mem[counter++] = 0;
} else if (n.y > lastNode.y) {
//South
mem[counter++] = 0;
mem[counter++] = 2;
}
if (lastNode == null) {
lastNode = n; lastNode = n;
continue;
} }
if (n.x < lastNode.x) { //Indicate end of path with 0xAAAA
//West mem[counter++] = -86;
mem[counter++] = 0; mem[counter] = -86;
mem[counter++] = 3; } else {
} else if (n.x > lastNode.x) { //Indicate invalid path 0xFFFF
//East mem[counter++] = -1;
mem[counter++] = 0; mem[counter] = -1;
mem[counter++] = 1;
} else if (n.y < lastNode.y) {
//North
mem[counter++] = 0;
mem[counter++] = 0;
} else if (n.y > lastNode.y) {
//South
mem[counter++] = 0;
mem[counter++] = 2;
}
lastNode = n;
} }
//Indicate end of path with 0xAAAA LogManager.LOGGER.fine("DEBUG: path to" + destX + "," + destY);
mem[counter++] = -86;
mem[counter] = -86;
} else {
//Indicate invalid path 0xFFFF
mem[counter++] = -1;
mem[counter] = -1;
} }
LogManager.LOGGER.fine("DEBUG: path to" + destX + "," + destY);
break; break;
case GET_MAP: case GET_MAP:
char[][] mapInfo = cubot.getWorld().getMapInfo(); if (cubot.spendEnergy(10)) {
char[][] mapInfo = cubot.getWorld().getMapInfo();
int i = MEMORY_MAP_START; int i = MEMORY_MAP_START;
for (int y = 0; y < World.WORLD_SIZE; y++) { for (int y = 0; y < World.WORLD_SIZE; y++) {
for (int x = 0; x < World.WORLD_SIZE; x++) { for (int x = 0; x < World.WORLD_SIZE; x++) {
getCpu().getMemory().set(i++, mapInfo[x][y]); getCpu().getMemory().set(i++, mapInfo[x][y]);
}
} }
} }
break;
case GET_WORLD_POS:
getCpu().getRegisterSet().getRegister("X").setValue(cubot.getWorld().getX());
getCpu().getRegisterSet().getRegister("Y").setValue(cubot.getWorld().getY());
break;
} }

View File

@@ -51,6 +51,12 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer,
return CubotInventory.deserialize(hwJson); return CubotInventory.deserialize(hwJson);
case Keyboard.HWID: case Keyboard.HWID:
return Keyboard.deserialize(hwJson); return Keyboard.deserialize(hwJson);
case CubotHologram.HWID:
return CubotHologram.deserialize(hwJson);
case CubotBattery.HWID:
return CubotBattery.deserialize(hwJson);
case CubotFloppyDrive.HWID:
return CubotFloppyDrive.deserialize(hwJson);
} }
return null; return null;

View File

@@ -0,0 +1,109 @@
package net.simon987.cubotplugin;
import net.simon987.server.assembly.Memory;
import net.simon987.server.io.JSONSerialisable;
import org.json.simple.JSONObject;
/**
* Represents a floppy disk that is inside a floppy drive.
* Floppies contains 80 tracks with 18 sectors per track.
* That's 1440 sectors of 512 words. (total 1,474,560 bytes / 737,280 words / 1.44Mb)
*/
public class FloppyDisk implements JSONSerialisable {
/**
* Contents of the disk
*/
private Memory memory;
/**
* Current location of the read/write head.
* Used to calculate seek time
*/
private int rwHeadTrack = 0;
public FloppyDisk() {
this.memory = new Memory(1024 * 1440);
}
/**
* Read 512 words from the specified sector to cpu memory at specified address
*
* @param sector sector to read (0-1440)
* @param cpuMemory Cpu memory to write to
* @param ramAddress address of the data to write in CPU memory
* @return Whether or not the read operation was in the same track as the last r/w
*/
public boolean readSector(int sector, Memory cpuMemory, int ramAddress) {
if (sector <= 1440) {
cpuMemory.write(ramAddress, memory.getBytes(), sector * 1024, 1024);
//Calculate seek time
int deltaTrack = (sector / 80) - rwHeadTrack;
if (deltaTrack != 0) {
rwHeadTrack = (sector / 80);
return false;
} else {
return true;
}
}
return false;
}
/**
* Write 512 words to the specified sector from cpu memory at the specified address
*
* @param sector sector to write (0-1440)
* @param cpuMemory Cpu memory to read from
* @param ramAddress address of the data to read in CPU memory
* @return Whether or not the read operation was in the same track as the last r/w
*/
public boolean writeSector(int sector, Memory cpuMemory, int ramAddress) {
if (sector <= 1440) {
memory.write(sector * 512, cpuMemory.getBytes(), ramAddress * 2, 1024);
//Calculate seek time
int deltaTrack = (sector / 80) - rwHeadTrack;
if (deltaTrack != 0) {
rwHeadTrack = (sector / 80);
return false;
} else {
return true;
}
} else {
return false;
}
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("rwHeadTrack", rwHeadTrack);
json.put("memory", memory.serialise());
return json;
}
public static FloppyDisk deserialise(JSONObject json) {
FloppyDisk floppyDisk = new FloppyDisk();
floppyDisk.rwHeadTrack = (int) (long) json.get("rwHeadTrack");
floppyDisk.memory = Memory.deserialize((JSONObject) json.get("memory"));
return floppyDisk;
}
public Memory getMemory() {
return memory;
}
}

View File

@@ -9,9 +9,6 @@ public class Keyboard extends CpuHardware {
public static final int DEFAULT_ADDRESS = 4; public static final int DEFAULT_ADDRESS = 4;
public static final String NAME = "Wireless Keyboard";
private static final int CLEAR_BUFFER = 0; private static final int CLEAR_BUFFER = 0;
private static final int FETCH_KEY = 1; private static final int FETCH_KEY = 1;

View File

@@ -33,6 +33,12 @@ public class CpuInitialisationListener implements GameEventListener {
drillHw.setCpu(cpu); drillHw.setCpu(cpu);
CubotInventory invHw = new CubotInventory((Cubot) user.getControlledUnit()); CubotInventory invHw = new CubotInventory((Cubot) user.getControlledUnit());
invHw.setCpu(cpu); invHw.setCpu(cpu);
CubotHologram emoteHw = new CubotHologram((Cubot) user.getControlledUnit());
emoteHw.setCpu(cpu);
CubotBattery batteryHw = new CubotBattery((Cubot) user.getControlledUnit());
batteryHw.setCpu(cpu);
CubotFloppyDrive floppyHw = new CubotFloppyDrive((Cubot) user.getControlledUnit());
floppyHw.setCpu(cpu);
cpu.attachHardware(legHw, CubotLeg.DEFAULT_ADDRESS); cpu.attachHardware(legHw, CubotLeg.DEFAULT_ADDRESS);
cpu.attachHardware(laserHw, CubotLaser.DEFAULT_ADDRESS); cpu.attachHardware(laserHw, CubotLaser.DEFAULT_ADDRESS);
@@ -40,5 +46,9 @@ public class CpuInitialisationListener implements GameEventListener {
cpu.attachHardware(keyboard, Keyboard.DEFAULT_ADDRESS); cpu.attachHardware(keyboard, Keyboard.DEFAULT_ADDRESS);
cpu.attachHardware(drillHw, CubotDrill.DEFAULT_ADDRESS); cpu.attachHardware(drillHw, CubotDrill.DEFAULT_ADDRESS);
cpu.attachHardware(invHw, CubotInventory.DEFAULT_ADDRESS); cpu.attachHardware(invHw, CubotInventory.DEFAULT_ADDRESS);
cpu.attachHardware(invHw, CubotInventory.DEFAULT_ADDRESS);
cpu.attachHardware(emoteHw, CubotHologram.DEFAULT_ADDRESS);
cpu.attachHardware(batteryHw, CubotBattery.DEFAULT_ADDRESS);
cpu.attachHardware(floppyHw, CubotFloppyDrive.DEFAULT_ADDRESS);
} }
} }

View File

@@ -34,6 +34,9 @@ public class UserCreationListener implements GameEventListener {
cubot.setHeldItem(GameServer.INSTANCE.getConfig().getInt("new_user_item")); cubot.setHeldItem(GameServer.INSTANCE.getConfig().getInt("new_user_item"));
cubot.setEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy"));
cubot.setMaxEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy"));
cubot.setParent(user); cubot.setParent(user);
Point point = cubot.getWorld().getRandomPassableTile(); Point point = cubot.getWorld().getRandomPassableTile();

View File

@@ -0,0 +1,3 @@
classpath=net.simon987.mischwplugin.MiscHWPlugin
name=Misc HW Plugin
version=1.0

View File

@@ -0,0 +1,42 @@
package net.simon987.mischwplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Util;
import org.json.simple.JSONObject;
public class Clock extends CpuHardware {
public static final char HWID = 0x0008;
public static final char DEFAULT_ADDRESS = 0x0008;
@Override
public void handleInterrupt(Status status) {
int time = (int) GameServer.INSTANCE.getGameUniverse().getTime();
//Will need to be changed to quadword in about 136 years
getCpu().getRegisterSet().getRegister("B").setValue(Util.getHigherWord(time));
getCpu().getRegisterSet().getRegister("C").setValue(Util.getLowerWord(time));
}
@Override
public char getId() {
return HWID;
}
public static Clock deserialize(JSONObject hwJSON) {
return new Clock();
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
return json;
}
}

View File

@@ -0,0 +1,33 @@
package net.simon987.mischwplugin;
import net.simon987.mischwplugin.event.CpuInitialisationListener;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.io.CpuHardwareDeserializer;
import net.simon987.server.logging.LogManager;
import net.simon987.server.plugin.ServerPlugin;
import org.json.simple.JSONObject;
public class MiscHWPlugin extends ServerPlugin implements CpuHardwareDeserializer {
@Override
public void init() {
listeners.add(new CpuInitialisationListener());
LogManager.LOGGER.info("Initialised Misc Hardware Plugin");
}
@Override
public CpuHardware deserializeHardware(JSONObject hwJson) {
int hwid = (int) (long) hwJson.get("hwid");
switch (hwid) {
case RandomNumberGenerator.HWID:
return RandomNumberGenerator.deserialize(hwJson);
case Clock.HWID:
return Clock.deserialize(hwJson);
}
return null;
}
}

View File

@@ -0,0 +1,44 @@
package net.simon987.mischwplugin;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.json.simple.JSONObject;
import java.util.Random;
public class RandomNumberGenerator extends CpuHardware {
public static final char HWID = 0x0007;
public static final char DEFAULT_ADDRESS = 0x0007;
private Random random;
public RandomNumberGenerator() {
random = new Random();
}
@Override
public void handleInterrupt(Status status) {
getCpu().getRegisterSet().getRegister("B").setValue(random.nextInt(0xFFFF));
}
@Override
public char getId() {
return HWID;
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
return json;
}
public static RandomNumberGenerator deserialize(JSONObject hwJSON) {
return new RandomNumberGenerator();
}
}

View File

@@ -0,0 +1,30 @@
package net.simon987.mischwplugin.event;
import net.simon987.mischwplugin.Clock;
import net.simon987.mischwplugin.RandomNumberGenerator;
import net.simon987.server.assembly.CPU;
import net.simon987.server.event.CpuInitialisationEvent;
import net.simon987.server.event.GameEvent;
import net.simon987.server.event.GameEventListener;
public class CpuInitialisationListener implements GameEventListener {
@Override
public Class getListenedEventType() {
return CpuInitialisationEvent.class;
}
@Override
public void handle(GameEvent event) {
CPU cpu = (CPU) event.getSource();
RandomNumberGenerator rngHW = new RandomNumberGenerator();
rngHW.setCpu(cpu);
Clock clock = new Clock();
clock.setCpu(cpu);
cpu.attachHardware(rngHW, RandomNumberGenerator.DEFAULT_ADDRESS);
cpu.attachHardware(clock, Clock.DEFAULT_ADDRESS);
}
}

View File

@@ -132,30 +132,28 @@ public class Plant extends GameObject implements Updatable, InventoryHolder{
return false; return false;
} }
@Override
public boolean canTakeItem(int item) {
return item == ITM_BIOMASS && grown && biomassCount >= 1;
}
/** /**
* Called when an object attempts to take an item from this Plant. * Called when an object attempts to take an item from this Plant.
* If the object requests biomass, it will be subtracted from biomassCount, and * If the object requests biomass, it will be subtracted from biomassCount, and
* if it reaches 0, the plant is deleted * if it reaches 0, the plant is deleted
* *
* @param item item id (see MarConstants.ITEM_*) * @param item item id (see MarConstants.ITEM_*)
* @return true if the requested item is ITEM_BIOMASS and if the plant is grown
*/ */
@Override @Override
public boolean takeItem(int item) { public void takeItem(int item) {
if (item == ITM_BIOMASS) { if (item == ITM_BIOMASS) {
if (grown && biomassCount > 1) { if (grown && biomassCount > 1) {
biomassCount--; biomassCount--;
return true;
} else if (grown) { } else if (grown) {
//Delete plant //Delete plant
setDead(true); setDead(true);
return true;
} else {
return false;
} }
} else {
return false;
} }
} }

View File

@@ -1,3 +1,11 @@
# Much-Assembly-Required # [Live demo](https://muchassemblyrequired.com)
Program the 8086-like microprocessor of a robot in a grid-based multiplayer world. The game is web based so no installation is required.
In its current state, players can walk around the game universe and collect Biomass blobs & Iron/copper ore using the online code editor.
https://muchassemblyrequired.com ![screenshot from 2017-11-12 13-01-43](https://user-images.githubusercontent.com/7120851/32701793-e5d07e98-c7a9-11e7-9931-f8db7b287994.png)
Wiki: [GitHub](https://github.com/simon987/Much-Assembly-Required/wiki)
Chat: [Slack](https://join.slack.com/t/muchassemblyrequired/shared_invite/enQtMjY3Mjc1OTUwNjEwLTkyOTIwOTA5OGY4MDVlMGI4NzM5YzlhMWJiMGY1OWE2NjUxODQ1NWQ1YTcxMTA1NGZkYzNjYzMyM2E1ODdmNzg)
_Building instructions coming soon_

View File

@@ -15,6 +15,7 @@ import org.json.simple.JSONObject;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
public class GameServer implements Runnable { public class GameServer implements Runnable {
@@ -103,16 +104,25 @@ public class GameServer implements Runnable {
gameUniverse.incrementTime(); gameUniverse.incrementTime();
//Process user code //Process user code
for(User user : gameUniverse.getUsers()){ ArrayList<User> users_ = gameUniverse.getUsers();
for (User user : users_) {
if(user.getCpu() != null){ if(user.getCpu() != null){
user.getCpu().reset(); try {
user.getCpu().execute(); user.getCpu().reset();
user.getCpu().execute();
} catch (Exception e) {
LogManager.LOGGER.severe("Error executing " + user.getUsername() + "'s code");
e.printStackTrace();
}
} }
} }
//Process each worlds //Process each worlds
for (World world : gameUniverse.getWorlds()) { //Avoid concurrent modification
ArrayList<World> worlds = new ArrayList<>(gameUniverse.getWorlds());
for (World world : worlds) {
world.update(); world.update();
} }

View File

@@ -11,54 +11,6 @@ public class Main {
public static void main(String[] args){ public static void main(String[] args){
//TODO: Docs
/*
* - Intel 8086 p.14 design
* - Memory: Storage organisation: From a storage pov, 8086 memory spaces are
* organised as identical arrays of 16-bit words
* - Microprocessor
* - Instruction set
* -
*/
//---------------------------------
//TODO: Random number generator
//TODO: favicon
//TODO: Email verification
//TODO: Real account page
// Change/reset password
//TODO: Object information Window (Hover, click ?)
//TODO: Inventory indicator (Multiple items)
//TODO: Software Interrupts (PIC): Interupt flag?
/*
* - INT/INTO instruction
* - IRET instruction
*/
//TODO: Clock hardware
//TODO: Floppy drive hardware (and item?)
//TODO: LEA instruction
//TODO: XCHG instruction
//TODO: SAL/SAR instruction
//TODO: ROL/ROR/RCL/RCR instruction
//TODO: LOOP/LOOPE/LOOPX/LOOPNE/LOOPNZ ?
//TODO: World goto (form)
//TODO: Save backup (keep X saves, Zip em)
//TODO: Log backup (keep X backups, Zip em)
//TODO: More tests
//TODO: Handle client disconnects
//TODO: Cache objects requests?
//TODO: Ability to toggle debug stuff
//TODO: Data segment, DB, DW, DD, DQ
//TODO: Set client animation speed relative to TICK_LENGTH
//TODO: Withdraw animation / action
//TODO: Prevent World creation out of bounds, warp around universe
//TODO: Multiple Biomass style (and yield, rarity)
//TODO: Clean sprites
//TODO: Auto-resize
//TODO: Battery Hardware
LogManager.initialize(); LogManager.initialize();
ServerConfiguration config = new ServerConfiguration(new File("config.properties")); ServerConfiguration config = new ServerConfiguration(new File("config.properties"));

View File

@@ -271,7 +271,7 @@ public class Assembler {
* usage: constant_name EQU <immediate_value> * usage: constant_name EQU <immediate_value>
* A constant treated the same way as a label. * A constant treated the same way as a label.
*/ */
line = line.trim();
String[] tokens = line.split("\\s+"); String[] tokens = line.split("\\s+");

View File

@@ -93,6 +93,11 @@ public class CPU implements JSONSerialisable{
instructionSet.add(new JsInstruction(this)); instructionSet.add(new JsInstruction(this));
instructionSet.add(new HwiInstruction(this)); instructionSet.add(new HwiInstruction(this));
instructionSet.add(new HwqInstruction(this)); instructionSet.add(new HwqInstruction(this));
instructionSet.add(new XchgInstruction(this));
instructionSet.add(new JcInstruction(this));
instructionSet.add(new JncInstruction(this));
instructionSet.add(new JnoInstruction(this));
instructionSet.add(new JoInstruction(this));
status = new Status(); status = new Status();
memory = new Memory(config.getInt("memory_size")); memory = new Memory(config.getInt("memory_size"));
@@ -147,7 +152,7 @@ public class CPU implements JSONSerialisable{
// LogManager.LOGGER.info(instruction.getMnemonic()); // LogManager.LOGGER.info(instruction.getMnemonic());
} }
double elapsed = (System.currentTimeMillis() - startTime); double elapsed = (System.currentTimeMillis() - startTime);
LogManager.LOGGER.fine("----------\n" + counter + " instruction in " + elapsed + "ms : " + (double) counter / (elapsed / 1000) / 1000000 + "MHz"); LogManager.LOGGER.fine(counter + " instruction in " + elapsed + "ms : " + (double) counter / (elapsed / 1000) / 1000000 + "MHz");
} }
public void executeInstruction(Instruction instruction, int source, int destination) { public void executeInstruction(Instruction instruction, int source, int destination) {
@@ -443,5 +448,11 @@ public class CPU implements JSONSerialisable{
return str; return str;
} }
public CpuHardware getHardware(int address) {
return attachedHardware.get(address);
}
} }

View File

@@ -1,6 +1,7 @@
package net.simon987.server.assembly; package net.simon987.server.assembly;
import net.simon987.server.assembly.instruction.*; import net.simon987.server.assembly.instruction.*;
import net.simon987.server.logging.LogManager;
import java.util.HashMap; import java.util.HashMap;
@@ -31,11 +32,18 @@ public class DefaultInstructionSet implements InstructionSet {
add(new AndInstruction()); add(new AndInstruction());
add(new OrInstruction()); add(new OrInstruction());
add(new ShlInstruction()); add(new ShlInstruction());
add(new SalInstruction()); //Alias is added
add(new ShrInstruction()); add(new ShrInstruction());
add(new XorInstruction()); add(new XorInstruction());
add(new TestInstruction()); add(new TestInstruction());
add(new CmpInstruction()); add(new CmpInstruction());
add(new NegInstruction()); add(new NegInstruction());
add(new NotInstruction());
add(new RorInstruction());
add(new RolInstruction());
add(new RclInstruction());
add(new RcrInstruction());
add(new SarInstruction());
} }
/** /**
@@ -82,6 +90,12 @@ public class DefaultInstructionSet implements InstructionSet {
@Override @Override
public void add(Instruction instruction) { public void add(Instruction instruction) {
instructionMap.put(instruction.getOpCode(), instruction); if (instructionMap.containsKey(instruction.getOpCode())) {
LogManager.LOGGER.fine(instruction.getMnemonic() + " instruction is an alias for " +
instructionMap.get(instruction.getOpCode()).getMnemonic());
} else {
instructionMap.put(instruction.getOpCode(), instruction);
}
} }
} }

View File

@@ -55,16 +55,16 @@ public class Memory implements Target, JSONSerialisable {
/** /**
* Write x words from an array at an offset * Write x words from an array at an offset
*/ */
public boolean write(int offset, byte[] bytes, int count) { public boolean write(int offset, byte[] bytes, int srcOffset, int count) {
offset = (char)offset * 2; offset = (char)offset * 2;
if (offset + count > this.bytes.length || count < 0 || offset < 0) { if (offset + count > this.bytes.length || count < 0 || offset < 0 || srcOffset >= bytes.length) {
return false; return false;
} }
System.arraycopy(bytes, 0, this.bytes, offset, count); System.arraycopy(bytes, srcOffset, this.bytes, offset, count);
return true; return true;
} }
@@ -122,18 +122,6 @@ public class Memory implements Target, JSONSerialisable {
e.printStackTrace(); e.printStackTrace();
} }
//To deflate
/*
ByteArrayOutputStream stream2 = new ByteArrayOutputStream();
Inflater decompresser = new Inflater(true);
InflaterOutputStream inflaterOutputStream = new InflaterOutputStream(stream2, decompresser);
inflaterOutputStream.write(output);
inflaterOutputStream.close();
byte[] output2 = stream2.toByteArray();
*/
return json; return json;
} }
@@ -157,4 +145,8 @@ public class Memory implements Target, JSONSerialisable {
return memory; return memory;
} }
public void setBytes(byte[] bytes) {
this.bytes = bytes;
}
} }

View File

@@ -0,0 +1,36 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
public class JcInstruction extends Instruction {
private static final int OPCODE = 33;
private CPU cpu;
public JcInstruction(CPU cpu) {
super("jc", OPCODE);
this.cpu = cpu;
}
@Override
public Status execute(Target src, int srcIndex, Status status) {
if (status.isCarryFlag()) {
cpu.setIp((char) src.get(srcIndex));
}
return status;
}
@Override
public Status execute(int src, Status status) {
if (status.isCarryFlag()) {
cpu.setIp((char) src);
}
return status;
}
}

View File

@@ -0,0 +1,35 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
public class JncInstruction extends Instruction {
private static final int OPCODE = 34;
private CPU cpu;
public JncInstruction(CPU cpu) {
super("jnc", OPCODE);
this.cpu = cpu;
}
@Override
public Status execute(Target src, int srcIndex, Status status) {
if (!status.isCarryFlag()) {
cpu.setIp((char) src.get(srcIndex));
}
return status;
}
@Override
public Status execute(int src, Status status) {
if (!status.isCarryFlag()) {
cpu.setIp((char) src);
}
return status;
}
}

View File

@@ -0,0 +1,35 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
public class JnoInstruction extends Instruction {
private static final int OPCODE = 37;
private CPU cpu;
public JnoInstruction(CPU cpu) {
super("jno", OPCODE);
this.cpu = cpu;
}
@Override
public Status execute(Target src, int srcIndex, Status status) {
if (!status.isOverflowFlag()) {
cpu.setIp((char) src.get(srcIndex));
}
return status;
}
@Override
public Status execute(int src, Status status) {
if (!status.isOverflowFlag()) {
cpu.setIp((char) src);
}
return status;
}
}

View File

@@ -0,0 +1,34 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
public class JoInstruction extends Instruction {
private static final int OPCODE = 36;
private CPU cpu;
public JoInstruction(CPU cpu) {
super("jo", OPCODE);
this.cpu = cpu;
}
@Override
public Status execute(Target src, int srcIndex, Status status) {
if (status.isOverflowFlag()) {
cpu.setIp((char) src.get(srcIndex));
}
return status;
}
@Override
public Status execute(int src, Status status) {
if (status.isOverflowFlag()) {
cpu.setIp((char) src);
}
return status;
}
}

View File

@@ -0,0 +1,14 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
public class LeaInstruction extends Instruction {
public static final int OPCODE = 30;
public LeaInstruction() {
super("lea", OPCODE);
}
}

View File

@@ -0,0 +1,21 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
public class NotInstruction extends Instruction {
public static final int OPCODE = 29;
public NotInstruction() {
super("not", OPCODE);
}
@Override
public Status execute(Target dst, int dstIndex, Status status) {
dst.set(dstIndex, ~dst.get(dstIndex));
return status;
}
}

View File

@@ -0,0 +1,70 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
/**
* +---------------------+
* | |
* CF < 0<0<0<0<0<0<0<0 <-+
*/
public class RclInstruction extends Instruction {
private static final int OPCODE = 39;
public RclInstruction() {
super("rcl", OPCODE);
}
@Override
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
int count = src.get(srcIndex) % 17;
int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000);
if (status.isCarryFlag()) {
destination |= 0x10000;
}
destination = (destination << count) | (destination >>> (17 - count));
status.setCarryFlag((destination & 0x10000) == 0x10000);
if (count == 1) {
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
}
dst.set(dstIndex, destination & 0xFFFF);
return status;
}
@Override
public Status execute(Target dst, int dstIndex, int src, Status status) {
int count = src % 17;
int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000);
if (status.isCarryFlag()) {
destination |= 0x10000;
}
destination = (destination << count) | (destination >>> (17 - count));
status.setCarryFlag((destination & 0x10000) == 0x10000);
if (count == 1) {
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
}
dst.set(dstIndex, destination & 0xFFFF);
return status;
}
}

View File

@@ -0,0 +1,69 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
/**
* +---------------------+
* | |
* CF < 0<0<0<0<0<0<0<0 <-+
*/
public class RcrInstruction extends Instruction {
private static final int OPCODE = 40;
public RcrInstruction() {
super("rcr", OPCODE);
}
@Override
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
int count = src.get(srcIndex) % 17;
int destination = dst.get(dstIndex) << 1;
int signBit = (destination & 0x10000);
if (status.isCarryFlag()) {
destination |= 1;
}
destination = (destination >>> count) | (destination << (17 - count));
status.setCarryFlag((destination & 1) == 1);
if (count == 1) {
status.setOverflowFlag((destination & 0x10000) != signBit); //Set OF if sign bit changed
}
dst.set(dstIndex, destination >> 1);
return status;
}
@Override
public Status execute(Target dst, int dstIndex, int src, Status status) {
int count = src % 17;
int destination = dst.get(dstIndex) << 1;
int signBit = (destination & 0x10000);
if (status.isCarryFlag()) {
destination |= 1;
}
destination = (destination >>> count) | (destination << (17 - count));
status.setCarryFlag((destination & 1) == 1);
if (count == 1) {
status.setOverflowFlag((destination & 0x10000) != signBit); //Set OF if sign bit changed
}
dst.set(dstIndex, destination >> 1);
return status;
}
}

View File

@@ -0,0 +1,56 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
/**
* +-----------------+
* | |
* CF < 0<0<0<0<0<0<0<0 <-+
*/
public class RolInstruction extends Instruction {
private static final int OPCODE = 35;
public RolInstruction() {
super("rol", OPCODE);
}
@Override
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
int count = src.get(srcIndex) % 16;
int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000);
destination = (destination << count) | (destination >>> (16 - count));
if (count == 1) {
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
}
status.setCarryFlag((destination & 1) == 1);
dst.set(dstIndex, destination);
return status;
}
@Override
public Status execute(Target dst, int dstIndex, int src, Status status) {
int count = src % 16;
int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000);
destination = (destination << count) | (destination >>> (16 - count));
if (count == 1) {
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
}
status.setCarryFlag((destination & 1) == 1);
dst.set(dstIndex, destination);
return status;
}
}

View File

@@ -0,0 +1,53 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
/**
* +-----------------+
* | |
* +-> 0>0>0>0>0>0>0>0 > CF
*
*/
public class RorInstruction extends Instruction {
private static final int OPCODE = 32;
public RorInstruction() {
super("ror", OPCODE);
}
@Override
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
int count = src.get(srcIndex) % 16;
int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000);
destination = (destination >>> count) | (destination << (16 - count));
if (count == 1) {
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
}
dst.set(dstIndex, destination);
status.setCarryFlag((destination & 0x8000) == 0x8000);
return status;
}
@Override
public Status execute(Target dst, int dstIndex, int src, Status status) {
int count = src % 16;
int destination = dst.get(dstIndex);
int signBit = (destination & 0x8000);
destination = (destination >>> count) | (destination << (16 - count));
if (count == 1) {
status.setOverflowFlag((destination & 0x8000) != signBit); //Set OF if sign bit changed
}
dst.set(dstIndex, destination);
status.setCarryFlag((destination & 0x8000) == 0x8000);
return status;
}
}

View File

@@ -0,0 +1,13 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
/**
* Alias of SHL instruction
*/
public class SalInstruction extends Instruction {
public SalInstruction() {
super("sal", ShlInstruction.OPCODE);
}
}

View File

@@ -0,0 +1,67 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
/**
*
*/
public class SarInstruction extends Instruction {
private static final int OPCODE = 41;
public SarInstruction() {
super("sar", OPCODE);
}
@Override
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
int count = src.get(srcIndex) % 16;
int destination = dst.get(dstIndex);
if (count == 1) {
status.setOverflowFlag(false); //sign doesn't change
}
if ((destination & 0x8000) == 0x8000) {
destination |= 0xFFFF0000;
}
destination = destination >> (count - 1);
status.setCarryFlag((destination & 1) == 1);
destination = destination >> 1;
status.setZeroFlag(destination == 0);
dst.set(dstIndex, destination);
return status;
}
@Override
public Status execute(Target dst, int dstIndex, int src, Status status) {
int count = src % 16;
int destination = dst.get(dstIndex);
if (count == 1) {
status.setOverflowFlag(false); //sign doesn't change
}
if ((destination & 0x8000) == 0x8000) {
destination |= 0xFFFF0000;
}
destination = destination >> (count - 1);
status.setCarryFlag((destination & 1) == 1);
destination = destination >> 1;
status.setZeroFlag(destination == 0);
dst.set(dstIndex, destination);
return status;
}
}

View File

@@ -0,0 +1,33 @@
package net.simon987.server.assembly.instruction;
import net.simon987.server.assembly.CPU;
import net.simon987.server.assembly.Instruction;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target;
/**
* Swap operands. Does not alter the flags
*/
public class XchgInstruction extends Instruction {
public static final int OPCODE = 31;
private CPU cpu;
public XchgInstruction(CPU cpu) {
super("xchg", OPCODE);
this.cpu = cpu;
}
@Override
public Status execute(Target dst, int dstIndex, Target src, int srcIndex, Status status) {
int tmp = dst.get(dstIndex);
dst.set(dstIndex, src.get(srcIndex));
src.set(srcIndex, tmp);
return status;
}
}

View File

@@ -5,15 +5,13 @@ import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Target; import net.simon987.server.assembly.Target;
import net.simon987.server.assembly.Util; import net.simon987.server.assembly.Util;
/**
* Created by Gilbert Fortier on 3/12/2017.
*/
public class XorInstruction extends Instruction { public class XorInstruction extends Instruction {
/** /**
* Opcode of the instruction * Opcode of the instruction
*/ */
public static final int OPCODE = 5; public static final int OPCODE = 38;
public XorInstruction() { public XorInstruction() {
super("xor", OPCODE); super("xor", OPCODE);

View File

@@ -1,5 +1,6 @@
package net.simon987.server.game; package net.simon987.server.game;
import net.simon987.server.assembly.Memory;
import net.simon987.server.user.User; import net.simon987.server.user.User;
import java.util.ArrayList; import java.util.ArrayList;
@@ -14,4 +15,6 @@ public interface ControllableUnit {
ArrayList<Integer> getKeyboardBuffer(); ArrayList<Integer> getKeyboardBuffer();
Memory getFloppyData();
} }

View File

@@ -71,7 +71,14 @@ public abstract class GameObject implements JSONSerialisable {
//Check if out of World bounds / collision //Check if out of World bounds / collision
if(newX < 0) { if(newX < 0) {
//Move object to adjacent World (left) //Move object to adjacent World (left)
World leftWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX() - 1, world.getY()); World leftWorld;
if (world.getX() == 0) {
//Warp around
leftWorld = GameServer.INSTANCE.getGameUniverse().getWorld(
GameServer.INSTANCE.getGameUniverse().getMaxWidth(), world.getY());
} else {
leftWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX() - 1, world.getY());
}
if(leftWorld != null){ if(leftWorld != null){
world.getGameObjects().remove(this); world.getGameObjects().remove(this);
@@ -82,7 +89,13 @@ public abstract class GameObject implements JSONSerialisable {
} }
} else if(newX >= World.WORLD_SIZE) { } else if(newX >= World.WORLD_SIZE) {
//Move object to adjacent World (right) //Move object to adjacent World (right)
World rightWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX() + 1, world.getY()); World rightWorld;
if (world.getX() == GameServer.INSTANCE.getGameUniverse().getMaxWidth()) {
//Warp around
rightWorld = GameServer.INSTANCE.getGameUniverse().getWorld(0, world.getY());
} else {
rightWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX() + 1, world.getY());
}
if(rightWorld != null){ if(rightWorld != null){
world.getGameObjects().remove(this); world.getGameObjects().remove(this);
@@ -92,25 +105,39 @@ public abstract class GameObject implements JSONSerialisable {
x = 0; x = 0;
} }
} else if (newY < 0) { } else if (newY < 0) {
//Move object to adjacent World (down)
World downWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX(), world.getY() - 1);
if(downWorld != null){
world.getGameObjects().remove(this);
downWorld.getGameObjects().add(this);
setWorld(downWorld);
y = World.WORLD_SIZE - 1;
}
} else if(newY >= World.WORLD_SIZE) {
//Move object to adjacent World (up) //Move object to adjacent World (up)
World upWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX(), world.getY() + 1); World upWorld;
if (world.getY() == 0) {
//Warp around
upWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX(),
GameServer.INSTANCE.getGameUniverse().getMaxWidth());
} else {
upWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX(), world.getY() - 1);
}
if(upWorld != null){ if(upWorld != null){
world.getGameObjects().remove(this); world.getGameObjects().remove(this);
upWorld.getGameObjects().add(this); upWorld.getGameObjects().add(this);
setWorld(upWorld); setWorld(upWorld);
y = World.WORLD_SIZE - 1;
}
} else if (newY >= World.WORLD_SIZE) {
//Move object to adjacent World (down)
World downWorld;
if (world.getY() == GameServer.INSTANCE.getGameUniverse().getMaxWidth()) {
//Warp around
downWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX(), 0);
} else {
downWorld = GameServer.INSTANCE.getGameUniverse().getWorld(world.getX(), world.getY() + 1);
}
if (downWorld != null) {
world.getGameObjects().remove(this);
downWorld.getGameObjects().add(this);
setWorld(downWorld);
y = 0; y = 0;
} }
} }
@@ -120,9 +147,6 @@ public abstract class GameObject implements JSONSerialisable {
x = newX; x = newX;
y = newY; y = newY;
} else { } else {
//Display error when object is trying to walk in a wall
//TODO Add emote here
//System.out.println("DEBUG: FAILED walk");
return false; return false;
} }

View File

@@ -29,6 +29,8 @@ public class GameUniverse implements JSONSerialisable{
private int nextObjectId = 0; private int nextObjectId = 0;
private int maxWidth = 0xFFFF;
public GameUniverse(ServerConfiguration config) { public GameUniverse(ServerConfiguration config) {
worlds = new ArrayList<>(32); worlds = new ArrayList<>(32);
@@ -50,15 +52,18 @@ public class GameUniverse implements JSONSerialisable{
} }
} }
//World does not exist if (x >= 0 && x <= maxWidth && y >= 0 && y <= maxWidth) {
LogManager.LOGGER.severe("Trying to read a World that does not exist!"); //World does not exist
LogManager.LOGGER.severe("Trying to read a World that does not exist!");
World world = createWorld(x,y); World world = createWorld(x, y);
worlds.add(world); worlds.add(world);
return world;
return world;
} else {
return null;
}
} }
public World createWorld(int x, int y) { public World createWorld(int x, int y) {
@@ -108,9 +113,11 @@ public class GameUniverse implements JSONSerialisable{
user.getCpu().getMemory().clear(); user.getCpu().getMemory().clear();
//Write assembled code to mem //Write assembled code to mem
user.getCpu().getMemory().write((short) ar.origin, ar.bytes, ar.bytes.length); user.getCpu().getMemory().write((short) ar.origin, ar.bytes, 0, ar.bytes.length);
user.getCpu().setCodeSegmentOffset(ar.origin); user.getCpu().setCodeSegmentOffset(ar.origin);
//Init
} else { } else {
user = new User(null); user = new User(null);
} }
@@ -129,8 +136,17 @@ public class GameUniverse implements JSONSerialisable{
} }
} }
/**
* Get an object by id
* <br>
* ConcurrentModificationException risk when inside game loop
*
* @param id id of the game object
* @return GameObject, null if not found
*/
public GameObject getObject(int id) { public GameObject getObject(int id) {
//
for (World world : worlds) { for (World world : worlds) {
for(GameObject object : world.getGameObjects()){ for(GameObject object : world.getGameObjects()){
if(object.getObjectId() == id){ if(object.getObjectId() == id){
@@ -161,12 +177,14 @@ public class GameUniverse implements JSONSerialisable{
JSONArray worlds = new JSONArray(); JSONArray worlds = new JSONArray();
for(World world : this.worlds){ ArrayList<World> worlds_ = new ArrayList<>(this.worlds);
for (World world : worlds_){
worlds.add(world.serialise()); worlds.add(world.serialise());
} }
JSONArray users = new JSONArray(); JSONArray users = new JSONArray();
for(User user : this.users){ ArrayList<User> users_ = new ArrayList<User>(this.users);
for (User user : users_){
if (!user.isGuest()) { if (!user.isGuest()) {
users.add(user.serialise()); users.add(user.serialise());
} }
@@ -245,4 +263,8 @@ public class GameUniverse implements JSONSerialisable{
users.remove(user); users.remove(user);
} }
public int getMaxWidth() {
return maxWidth;
}
} }

View File

@@ -13,8 +13,12 @@ public interface InventoryHolder {
/** /**
* Take an item from the inventory * Take an item from the inventory
* @param item Desired item id (see MarConstants.ITEM_*) * @param item Desired item id (see MarConstants.ITEM_*)
* @return true is the take item action executed properly, true also means that the desired item
* was removed from the inventory
*/ */
boolean takeItem(int item); void takeItem(int item);
/**
* @param item item to take
* @return true if the InventoryHolder can provide this item
*/
boolean canTakeItem(int item);
} }

View File

@@ -83,7 +83,8 @@ public class World implements JSONSerialisable{
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
JSONArray objects = new JSONArray(); JSONArray objects = new JSONArray();
for(GameObject obj : gameObjects){ ArrayList<GameObject> gameObjects_ = new ArrayList<>(gameObjects);
for (GameObject obj : gameObjects_) {
objects.add(obj.serialise()); objects.add(obj.serialise());
} }
json.put("objects", objects); json.put("objects", objects);

View File

@@ -3,7 +3,6 @@ package net.simon987.server.logging;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.logging.Formatter; import java.util.logging.Formatter;
import java.util.logging.Level;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
/** /**
@@ -16,24 +15,13 @@ public class GenericFormatter extends Formatter {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (record.getLevel() == Level.FINE) { //Regular record
//Chat message, maximum 50 char per line Date date = new Date();
if (record.getMessage().length() > 50) { SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm:ss:SSS"); //ex. 11/25 22:03:59:010
sb.append(record.getMessage().substring(0, 50));
sb.append('\n'); sb.append(String.format("[%s] [%s] %s", sdf.format(date), record.getLevel(), record.getMessage()));
sb.append(record.getMessage().substring(50)); sb.append('\n');
} else {
sb.append(record.getMessage());
}
sb.append('\n');
} else {
//Regular record
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd HH:mm:ss:SSS"); //ex. 11/25 22:03:59:010
sb.append(String.format("[%s] [%s] %s", sdf.format(date), record.getLevel(), record.getMessage()));
sb.append('\n');
}
return sb.toString(); return sb.toString();

View File

@@ -28,7 +28,7 @@ public class CodeUploadHandler implements MessageHandler {
user.getUser().getCpu().getMemory().clear(); user.getUser().getCpu().getMemory().clear();
//Write assembled code to mem //Write assembled code to mem
user.getUser().getCpu().getMemory().write((char) ar.origin, ar.bytes, ar.bytes.length); user.getUser().getCpu().getMemory().write((char) ar.origin, ar.bytes, 0, ar.bytes.length);
user.getUser().getCpu().setCodeSegmentOffset(ar.origin); user.getUser().getCpu().setCodeSegmentOffset(ar.origin);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();

View File

@@ -0,0 +1,36 @@
package net.simon987.server.webserver;
import net.simon987.server.GameServer;
import net.simon987.server.logging.LogManager;
import org.json.simple.JSONObject;
public class FloppyHandler implements MessageHandler {
SocketServerDatabase db = new SocketServerDatabase(GameServer.INSTANCE.getConfig());
@Override
public void handle(OnlineUser user, JSONObject json) {
if (json.get("t").equals("floppyDown")) {
LogManager.LOGGER.info("(WS) Floppy download request from " + user.getUser().getUsername());
//floppy
byte[] bytes = user.getUser().getControlledUnit().getFloppyData().getBytes();
user.getWebSocket().send(bytes);
} else if (json.get("t").equals("floppyUp")) {
LogManager.LOGGER.info("(WS) Floppy upload request from " + user.getUser().getUsername());
//Check newly uploaded file on the database
byte[] bytes = db.getFloppy(user.getUser().getUsername());
if (bytes != null) {
user.getUser().getControlledUnit().getFloppyData().setBytes(bytes);
}
}
}
}

View File

@@ -2,7 +2,7 @@ package net.simon987.server.webserver;
import net.simon987.server.GameServer; import net.simon987.server.GameServer;
import net.simon987.server.game.GameObject; import net.simon987.server.game.GameObject;
import net.simon987.server.io.JSONSerialisable; import net.simon987.server.game.World;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@@ -18,25 +18,28 @@ public class ObjectsRequestHandler implements MessageHandler {
if (json.get("t").equals("object")) { if (json.get("t").equals("object")) {
LogManager.LOGGER.info("(WS) Objects request from " + user.getUser().getUsername()); LogManager.LOGGER.info("(WS) Objects request from " + user.getUser().getUsername());
int x, y;
try {
x = Long.valueOf((long) json.get("x")).intValue();
y = Long.valueOf((long) json.get("y")).intValue();
} catch (Exception e) {
LogManager.LOGGER.info("(WS) Malformed Objects request from " + user.getUser().getUsername());
return;
}
if (json.containsKey("x") && json.containsKey("y")) { World world = GameServer.INSTANCE.getGameUniverse().getWorld(x, y);
int x = Long.valueOf((long) json.get("x")).intValue();
int y = Long.valueOf((long) json.get("y")).intValue();
ArrayList<GameObject> gameObjects = GameServer.INSTANCE.getGameUniverse().getWorld(x, y).getGameObjects(); if (world != null) {
ArrayList<GameObject> gameObjects = world.getGameObjects();
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
JSONArray objects = new JSONArray(); JSONArray objects = new JSONArray();
for (GameObject object : gameObjects) { for (GameObject object : gameObjects) {
if (object instanceof JSONSerialisable) {
objects.add(object.serialise()); objects.add(object.serialise());
} }
}
response.put("t", "object"); response.put("t", "object");
response.put("objects", objects); response.put("objects", objects);
@@ -44,8 +47,6 @@ public class ObjectsRequestHandler implements MessageHandler {
if (user.getWebSocket().isOpen()) { if (user.getWebSocket().isOpen()) {
user.getWebSocket().send(response.toJSONString()); user.getWebSocket().send(response.toJSONString());
} }
} else {
LogManager.LOGGER.info("(WS) Malformed Objects request from " + user.getUser().getUsername());
} }
} }
} }

View File

@@ -68,6 +68,7 @@ public class SocketServer extends WebSocketServer {
messageEventDispatcher.addHandler(new CodeUploadHandler()); messageEventDispatcher.addHandler(new CodeUploadHandler());
messageEventDispatcher.addHandler(new CodeRequestHandler()); messageEventDispatcher.addHandler(new CodeRequestHandler());
messageEventDispatcher.addHandler(new KeypressHandler()); messageEventDispatcher.addHandler(new KeypressHandler());
messageEventDispatcher.addHandler(new FloppyHandler());
} }

View File

@@ -4,10 +4,7 @@ import net.simon987.server.ServerConfiguration;
import net.simon987.server.io.DatabaseManager; import net.simon987.server.io.DatabaseManager;
import net.simon987.server.logging.LogManager; import net.simon987.server.logging.LogManager;
import java.sql.Connection; import java.sql.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
class SocketServerDatabase extends DatabaseManager { class SocketServerDatabase extends DatabaseManager {
@@ -48,4 +45,39 @@ class SocketServerDatabase extends DatabaseManager {
return null; return null;
} }
byte[] getFloppy(String username) {
Connection connection = null;
try {
connection = getConnection();
PreparedStatement p = connection.prepareStatement("SELECT floppyData FROM mar_user WHERE username=?");
p.setString(1, username);
ResultSet rs = p.executeQuery();
if (rs.next()) {
Blob blob = rs.getBlob("floppyData");
if (blob != null) {
return blob.getBytes(1, (int) blob.length() - 1);
}
}
} catch (SQLException e) {
LogManager.LOGGER.severe("MySQL Error " + e.getErrorCode() + ": " + e.getMessage());
} finally {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return null;
}
} }

View File

@@ -10,13 +10,19 @@ public class TerrainRequestHandler implements MessageHandler {
@Override @Override
public void handle(OnlineUser user, JSONObject json) { public void handle(OnlineUser user, JSONObject json) {
if (json.get("t").equals("terrain")) { if (json.get("t").equals("terrain") && json.containsKey("x") && json.containsKey("y")) {
LogManager.LOGGER.info("Terrain request from " + user.getUser().getUsername()); LogManager.LOGGER.info("Terrain request from " + user.getUser().getUsername());
World world;
try {
world = GameServer.INSTANCE.getGameUniverse().getWorld(
Long.valueOf((long) json.get("x")).intValue(),
Long.valueOf((long) json.get("y")).intValue());
} catch (NullPointerException e) {
LogManager.LOGGER.severe("FIXME: handle TerrainRequestHandler");
return;
}
World world = GameServer.INSTANCE.getGameUniverse().getWorld(
Long.valueOf((long) json.get("x")).intValue(),
Long.valueOf((long) json.get("y")).intValue());
//todo It might be a good idea to cache this //todo It might be a good idea to cache this
if (world != null) { if (world != null) {

View File

@@ -14,26 +14,22 @@ public class UserInfoRequestHandler implements MessageHandler {
if (message.get("t").equals("userInfo")) { if (message.get("t").equals("userInfo")) {
LogManager.LOGGER.info("(WS) User info request from " + user.getUser().getUsername()); LogManager.LOGGER.info("(WS) User info request from " + user.getUser().getUsername());
JSONObject json = new JSONObject();
if(user.isGuest()) { if(user.isGuest()) {
JSONObject json = new JSONObject();
json.put("t", "userInfo");
json.put("worldX", GameServer.INSTANCE.getConfig().getInt("new_user_worldX")); json.put("worldX", GameServer.INSTANCE.getConfig().getInt("new_user_worldX"));
json.put("worldY", GameServer.INSTANCE.getConfig().getInt("new_user_worldY")); json.put("worldY", GameServer.INSTANCE.getConfig().getInt("new_user_worldY"));
user.getWebSocket().send(json.toJSONString());
} else { } else {
GameObject object = (GameObject)user.getUser().getControlledUnit(); GameObject object = (GameObject)user.getUser().getControlledUnit();
JSONObject json = new JSONObject();
json.put("t", "userInfo");
json.put("worldX", object.getWorld().getX()); json.put("worldX", object.getWorld().getX());
json.put("worldY", object.getWorld().getY()); json.put("worldY", object.getWorld().getY());
user.getWebSocket().send(json.toJSONString());
} }
json.put("t", "userInfo");
json.put("maxWidth", GameServer.INSTANCE.getGameUniverse().getMaxWidth());
user.getWebSocket().send(json.toJSONString());
} }

View File

@@ -36,14 +36,14 @@ public class MemoryTest {
Memory memory = new Memory(memorySize); Memory memory = new Memory(memorySize);
assertTrue(memory.write(0, new byte[memorySize], memorySize)); assertTrue(memory.write(0, new byte[memorySize], 0, memorySize));
assertFalse(memory.write(0, new byte[memorySize], memorySize + 1)); assertFalse(memory.write(0, new byte[memorySize], 0, memorySize + 1));
assertFalse(memory.write(0, new byte[memorySize], -1)); assertFalse(memory.write(0, new byte[memorySize], 0, -1));
assertFalse(memory.write(-1, new byte[memorySize], 10)); assertFalse(memory.write(-1, new byte[memorySize], 0, 10));
assertFalse(memory.write(memorySize / 2, new byte[15], 1)); assertFalse(memory.write(memorySize / 2, new byte[15], 0, 1));
assertFalse(memory.write((memorySize / 2) - 5, new byte[11], 11)); assertFalse(memory.write((memorySize / 2) - 5, new byte[11], 0, 11));
assertTrue(memory.write((memorySize / 2) - 5, new byte[11], 10)); assertTrue(memory.write((memorySize / 2) - 5, new byte[11], 0, 10));
} }

View File

@@ -7,9 +7,9 @@ mysql_url=jdbc:mysql://localhost:3306/mar?useSSL=false
save_interval=10 save_interval=10
# Web server port # Web server port
webSocket_port=8887 webSocket_port=8887
webSocket_host=localhost webSocket_host=0.0.0.0
use_secure_webSocket=1 use_secure_webSocket=0
cert_path=certificates cert_path=certificates
# ---------------------------------------------- # ----------------------------------------------
@@ -41,6 +41,8 @@ plant_grow_time=32
minTreeCount=3 minTreeCount=3
# Maximum tree count for the WorldGenerator # Maximum tree count for the WorldGenerator
maxTreeCount=10 maxTreeCount=10
# Maximum energy of the battery hardware in kJ
battery_max_energy=60000
# ---------------------------------------------- # ----------------------------------------------
# Minimum center point count for the WorldGenerator # Minimum center point count for the WorldGenerator
wg_centerPointCountMin=5 wg_centerPointCountMin=5

Binary file not shown.

Binary file not shown.

BIN
plugins/Plugin Misc HW.jar Normal file

Binary file not shown.