Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9d704defd0 | ||
|
|
68bebf7a91 | ||
|
|
0a129016a7 | ||
|
|
311d127673 | ||
|
|
632682e436 | ||
|
|
8ae6b0bf60 | ||
|
|
2b3e1f14f2 | ||
|
|
b032347cf0 | ||
|
|
fecd0a950d | ||
|
|
cca0383a79 | ||
|
|
6ae2358ae6 | ||
|
|
717f5ba10e | ||
|
|
a06adb1bc8 | ||
|
|
4554c9274e | ||
|
|
9e7472051d | ||
|
|
2c2ba3bd5f | ||
|
|
3f6eb56749 | ||
|
|
1339b43a3e | ||
|
|
0b3db19cef | ||
|
|
6b2ef0690c | ||
|
|
772311bc5b | ||
|
|
58f8f4491c | ||
|
|
4c7d94ea34 | ||
|
|
8df2320d6d | ||
|
|
ce40582e9d | ||
|
|
5dd01629b9 | ||
|
|
a12fb47d5f | ||
|
|
be5b323f5d | ||
|
|
7a2cef56ad | ||
|
|
eb896f7b8c | ||
|
|
64bd781aa6 | ||
|
|
3e2dddeb6a | ||
|
|
41d3cecd49 | ||
|
|
c1945cfc73 | ||
|
|
264b53a6a0 | ||
|
|
a8041818bb | ||
|
|
a8612681ba | ||
|
|
2c80547cc3 | ||
|
|
989b8a11e1 |
No files matched your search
@@ -42,6 +42,7 @@ harness/mame/gui.log
|
||||
/cfg/
|
||||
/nvram/
|
||||
/roms/
|
||||
/snap/
|
||||
|
||||
# Large media: the source recording stays out of git (a YouTube download,
|
||||
# trivially re-obtainable). The derived frames and contact sheets ARE committed,
|
||||
@@ -69,3 +70,13 @@ ghidra/vt1200.lock
|
||||
tools/tms34010-sdk/Docs/
|
||||
tools/tms34010-sdk/Patents/
|
||||
tools/tms34010-sdk/1991-07 TIGA Promo Kit and Art Software/
|
||||
|
||||
# termtris build scratch (TI tools + 2ine libs)
|
||||
apps/termtris/work/
|
||||
apps/termtris/build/*.log
|
||||
apps/termtris/build/smoke.*
|
||||
apps/termtris/build/fmt.*
|
||||
apps/termtris/build/render.*
|
||||
apps/termtris/build/input.*
|
||||
apps/termtris/build/termtris.*
|
||||
apps/termtris/evidence/loader_frame*.png
|
||||
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
@@ -0,0 +1,134 @@
|
||||
# Handoff — termtris running inside the VT1200
|
||||
|
||||
Everything here is on branch **`termtris`** of
|
||||
`https://git.wut.ee/opencode.energia.arti.ee/vt1200.git` (remote `origin`); any
|
||||
checkout of the branch is equivalent.
|
||||
|
||||
```sh
|
||||
git fetch origin termtris
|
||||
git checkout -b termtris origin/termtris
|
||||
apps/termtris/verify.sh
|
||||
```
|
||||
|
||||
`verify.sh` is the whole acceptance run: ROM checksum, toolchain check, MAME
|
||||
build (skip with `--skip-mame`), the six tests, the acceptance summary and the
|
||||
evidence list. It keeps every test log under
|
||||
`apps/termtris/build/verify_<name>.log`, runs all six tests even after a
|
||||
failure, and exits non-zero at the end if any failed. `RUNTIME` is roughly 12
|
||||
minutes once MAME is built; the MAME build itself is the long part.
|
||||
|
||||
## What is done
|
||||
|
||||
The upstream game (John Tsiombikas' `termtris`, commit `7c5435d`) builds as a
|
||||
native TMS34010 program with the 1990 TI r5.01 C toolchain under 2ine, loads
|
||||
into VT1200 RAM through `dwt/loader`, opens a 480×312 window on the terminal's
|
||||
own X server through the ROM Xlib, and reads real X11 key events. It is the
|
||||
actual game: board, score/level/lines panels, piece preview, help and
|
||||
high-score panels, moving/rotating/dropping pieces, and `q` to quit.
|
||||
|
||||
| task | state | commit |
|
||||
|---|---|---|
|
||||
| vendor + toolchain + XG smoke test | done, `smoke.sh` PASS | `a861268` |
|
||||
| `sprintf`/stdio compat | done, `fmt.sh` PASS | `a804181` |
|
||||
| cell-grid X11 backend | done, `render.sh` PASS | `264b53a` |
|
||||
| key map, clock, main loop | done, `input.sh` PASS | `c1945cf` |
|
||||
| game integration, scores, COFF | done, `play.sh`/`play_keys.sh` PASS | `41d3cec` |
|
||||
| docs + harness report | done | `3e2ddde` |
|
||||
| review pass (seed, focus, expose, assertions) | done | `7a2cef5` |
|
||||
| handoff script + this note | done | `a12fb47` |
|
||||
| qemu-i386 fallback for kernels without 16-bit LDT | done, `verify.sh` PASS | `ce40582` |
|
||||
| VR319 re-run, regenerated evidence, updated numbers | done, `verify.sh` PASS | (this commit) |
|
||||
|
||||
`VT1200.md` is the port documentation; `harness/mame/TERMTRIS_REPORT.md` is the
|
||||
harness-side report; the design and plan are in
|
||||
`docs/superpowers/specs/2026-11-03-termtris-vt1200-design.md` and
|
||||
`docs/superpowers/plans/2026-11-03-termtris-vt1200.md`.
|
||||
|
||||
## The VR319 re-run — done
|
||||
|
||||
The screenshots and the acceptance numbers used to come from an **older MAME
|
||||
binary** (`/home/arti/code/k-space/mame0289/vt1200d`, 30 Oct) that predates the
|
||||
driver's VR319 default. That binary has no `VT1200_MONITOR`, and its frames are
|
||||
1024×864, i.e. the old VR150 geometry. The driver in this tree defaults to
|
||||
**VR319** (1280×1024 active, 1696×1063 raster), which changes the frame cadence
|
||||
and therefore the frame at which the loader and the tests act.
|
||||
|
||||
The branch has now been re-run against a fresh MAME 0.289 build of this tree's
|
||||
driver at the VR319 default. `apps/termtris/verify.sh --skip-mame` passes all
|
||||
six tests, the evidence PNGs were regenerated at **1280×1024**, and the new
|
||||
`DIAG` values are in `VT1200.md` and `harness/mame/TERMTRIS_REPORT.md`. The
|
||||
behaviour did not change: same events, same window (`focus=00400001`), same
|
||||
`quit=1`, board/panels/preview all visible. Only the loop counts moved, because
|
||||
the VR319 raster runs at a different emulated frame rate. The loader still acts
|
||||
at frame 2500 and the keys at 3095–3190; no re-timing was needed.
|
||||
|
||||
## Prerequisites on the new box
|
||||
|
||||
* a MAME 0.289 checkout (`MAME_SRC`, default `/home/arti/code/k-space/mame0289`);
|
||||
* the 2ine build with `lx_loader` (`NINE=`, default
|
||||
`/home/arti/os2-work/2ine/build`);
|
||||
* the r5.01 SDK zips, already in the repo under
|
||||
`tools/tms34010-sdk/1990-11 TMS340 Family SDK/`;
|
||||
* `vt1200_v22.bin` in the repo root (the harness ROM dir symlinks to it).
|
||||
|
||||
The r5.01 tools are 16-bit OS/2 `NE` programs. If the host kernel was built
|
||||
without `CONFIG_X86_16BIT`, `lx_loader` cannot create their 16-bit LDT
|
||||
segments and aborts at its first one; `build.sh` detects that and runs the same
|
||||
loader under `qemu-i386` (install `qemu-user`), or honours an explicit
|
||||
`LX_RUNNER` command prefix. This box's cloud kernel is one of those; the
|
||||
generated COFF is unchanged.
|
||||
|
||||
`verify.sh` checks the ROM and the 2ine loader before doing anything, and
|
||||
`harness/mame/build.sh` re-registers the driver in `mame.lst` and builds the
|
||||
single-driver `vt1200` subtarget.
|
||||
|
||||
## Expected results
|
||||
|
||||
Last full run (MAME 0.289, this tree's driver, **VR319 default**, 1280×1024
|
||||
frames; the earlier figures were VR150):
|
||||
|
||||
```
|
||||
smoke PASS type=2 keycode=194 lookup_n=1 ch=61 ks=0061
|
||||
fmt PASS six formats exact
|
||||
render PASS flus=464C5553 progress=00FFFFFF
|
||||
input PASS bytes 61 9B 41 9B 42 9B 44 9B 43 30 0A 7F 71 70
|
||||
(a/up/down/left/right/0/Return/Delete/q/p)
|
||||
play PASS DIAG: tick=887 quit=0
|
||||
play_keys PASS move DIAG: loops=650 events=18 last=3 focus=00400001 rev=0 quit=0
|
||||
panels DIAG: loops=648 events=12 last=3 focus=00400001 rev=0 quit=0
|
||||
quit DIAG: loops=555 events=10 last=3 focus=00400001 rev=0 quit=1
|
||||
```
|
||||
|
||||
`focus=00400001` is the window the process created; `quit=1` is the game's own
|
||||
global after `q` — that is the proof the key reached the game and not just the
|
||||
window.
|
||||
|
||||
## Known failure modes (all seen, all diagnosed)
|
||||
|
||||
| symptom | cause | handling |
|
||||
|---|---|---|
|
||||
| build stage "fails" with exit 139 but produced its file | 2ine-hosted TI tools crash during teardown | `build.sh` retries only when the output is missing; `gspac` needs `-i.` |
|
||||
| linker points `cinit` into `.text` | empty `.cinit` section | `build.sh` relinks with the one-word `CINITZ.obj` terminator |
|
||||
| `XNextEvent` never returns an event, keycode zero | child's per-process Xlib context is NULL | `src/vt1200/xgfix.c` writes a zeroed 1 KiB block before `XOpenDisplay` (RAM only) |
|
||||
| the game exits immediately at startup, sometimes | `XOpenDisplay`/window creation while the display server settles | `main()` retries 40 × 50 ms, then returns 1 |
|
||||
| window paints once, then hangs; a debug marker stops mid-flush | per-cell flushing overflowed the X socket / `XSync` per row deadlocked the client | flush repaints whole rows (fill + one 80-char string + inverse spans + one `XFlush`) |
|
||||
| playfield is a white block with invisible pieces | the 1-bit raster cannot show colour | backend drops colour and uses bold (`0x80`) as reverse; pieces are `[`/`]` glyphs |
|
||||
| blanked well border with stray `X` tiles at the top | `ExposureMask` + map-time Expose runs the game's full redraw before it has a piece | do not select `ExposureMask` (current code); if repainting on expose is ever needed, guard `full_redraw` against `cur_piece < 0` |
|
||||
|
||||
## Layout
|
||||
|
||||
```
|
||||
apps/termtris/
|
||||
├── build.sh TI r5.01 -> COFF (OUTNAME=termtris for the game)
|
||||
├── run.sh interactive MAME session (lightgun/tablet input)
|
||||
├── verify.sh one-command acceptance (see above)
|
||||
├── VT1200.md port documentation
|
||||
├── src/game.c upstream game; only srand(vt_rand_seed()) differs
|
||||
├── src/vt1200/ main.c x11.c xgfix.c compat.c xlib.h scoredb.c *.asm
|
||||
├── tests/ smoke fmt render input play play_keys (+ .lua drivers)
|
||||
├── evidence/ screenshots
|
||||
└── build/termtris.coff the built image (ignored; rebuild with build.sh)
|
||||
```
|
||||
|
||||
The tests build from source every run (`play.sh`/`play_keys.sh` rebuild
|
||||
`termtris.coff`), so an edit cannot silently pass by using a stale binary.
|
||||
@@ -0,0 +1,156 @@
|
||||
Termtris - tetris game for terminals
|
||||
====================================
|
||||
|
||||
> **VT1200 port:** this tree also builds a native TMS34010 program that runs
|
||||
> inside the VT1200 and draws through the terminal's own ROM Xlib. Build it with
|
||||
> `apps/termtris/build.sh` (see `apps/termtris/VT1200.md`) and run it with
|
||||
> `apps/termtris/run.sh`. The upstream backends (unix/ANSI, DOS, ADM3) are not
|
||||
> part of that build.
|
||||
|
||||

|
||||
|
||||
About
|
||||
-----
|
||||
|
||||
Termtris is a text-based tetris game, initially written for UNIX systems and
|
||||
ANSI/VT100-compatible terminals, but later extended to support more terminal
|
||||
types, operating systems, and text-mode video hardware.
|
||||
|
||||
I always liked the GameBoy tetris best. So I made termtris as close as possible
|
||||
to that version gameplay-wise.
|
||||
|
||||
Termtris can run in color or monochrome mode, and can load custom character sets
|
||||
for graphical blocks, if there is support for that.
|
||||
|
||||
There are two main flavors of termtris which can be compiled from the same
|
||||
source tree:
|
||||
|
||||
1. The original **UNIX version** which runs on terminals, and can also be
|
||||
compiled for windows using a POSIX emulation layer such as *msys2* or
|
||||
*cygwin*. It has been tested on multiple UNIX systems (GNU/Linux, FreeBSD, IRIX,
|
||||
Solaris, MacOSX), and multiple terminals (VT52, VT100, VT220, VT420,
|
||||
MS 6102), and terminal emulators (xterm, linux console, kermit, iTerm2).
|
||||
|
||||
2. The **DOS version** which uses the PC BIOS to access display and keyboard,
|
||||
but can also optionally work with the same terminals supported by the UNIX
|
||||
version.
|
||||
|
||||
### Links
|
||||
- website: http://nuclear.mutantstargoat.com/sw/termtris
|
||||
- source repository: https://github.com/jtsiomb/termtris
|
||||
|
||||
|
||||
Controls
|
||||
--------
|
||||
- `A` or *left arrow* moves the block left.
|
||||
- `D` or *right arrow* moves the block right.
|
||||
- `S` or *down arrow* drops the block faster.
|
||||
- `W`, *up arrow*, or *space* rotates the block.
|
||||
- *enter*, *tab*, or `0` drops the block immediately.
|
||||
- `P` pauses and unpauses the game.
|
||||
- *backspace*, or *delete* starts a new game.
|
||||
- `Q` or hitting escape twice, quits immediately.
|
||||
- `H` shows or hides the help panel which lists these keybindings.
|
||||
- `R` shows or hides the high score table.
|
||||
|
||||
Additionally on GNU/Linux systems any joystick can be used to control the game.
|
||||
The first available joystick is used automatically, or you can specify a
|
||||
joystick device with the `-j` commandline option. If you'd rather disable
|
||||
joystick control, use the option `-j /dev/null`.
|
||||
|
||||
When using a joystick, even axes are mapped to left/right, Odd axes are mapped
|
||||
to up/down, the first four buttons rotate, and the rest of the buttons pause
|
||||
and unpause.
|
||||
|
||||
There is no way to remap the controls without changing the source code at this
|
||||
time.
|
||||
|
||||
|
||||
Custom character set
|
||||
--------------------
|
||||
For terminals with support for custom loadable character sets, you can instruct
|
||||
termtris to use graphical blocks instead of the bracket characters with the `-g`
|
||||
command-line argument. If `TERM` is set to a known supported terminal, graphical
|
||||
blocks are enabled automatically, use the `-T` option to disable and inhibit
|
||||
auto-detection.
|
||||
|
||||
Different terminals have different capabilities when it comes to soft character
|
||||
sets. Termtris will try to detect the terminal type and choose the correct soft
|
||||
font to load, but if it fails or you want to force a different terminal type,
|
||||
make sure to define the `TERM` environent variable. If `TERM` is undefined, or
|
||||
an unknown or unsupported terminal type, termtris will try to interrogate the
|
||||
terminal itself about its capabilities.
|
||||
|
||||
The DOS version of termtris will automatically enable graphical blocks when it
|
||||
detects an EGA or VGA/SVGA graphics card. Use `-g` or `-T` to enable or disable
|
||||
it explicitly.
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
Copyright (C) 2019-2023 John Tsiombikas <nuclear@mutantstargoat.com>
|
||||
|
||||
This program is free software. Feel free to use, modify, and/or redistribute it
|
||||
under the terms of the GNU General Public License version 3, or at your option,
|
||||
any later version published by the Free Software Foundation. See COPYING for
|
||||
details.
|
||||
|
||||
|
||||
Download
|
||||
--------
|
||||
### Source code
|
||||
Current release (1.9): http://nuclear.mutantstargoat.com/sw/termtris/termtris-1.9.tar.gz
|
||||
|
||||
Releases are also mirrored on github: https://github.com/jtsiomb/termtris/releases
|
||||
|
||||
Alternatively you may clone the latest version of the source code from the git
|
||||
repository:
|
||||
|
||||
git clone https://github.com/jtsiomb/termtris
|
||||
|
||||
### Pre-compiled
|
||||
Building from source is highly recommended. If however you want to try a
|
||||
pre-compiled binary, you might be able to find something for your system in:
|
||||
http://nuclear.mutantstargoat.com/sw/termtris/bin
|
||||
Not all releases are compiled for all platforms. Any binaries available here are
|
||||
provided purely for convenience. Do not open bug reports about a pre-compiled
|
||||
binary not running, or misbehaving on your system; compile it yourself first.
|
||||
|
||||
Another source of binaries, is the github automated builds. Head over to the
|
||||
"actions" page (https://github.com/jtsiomb/termtris/actions), choose the latest
|
||||
successful build for your platform, and download the binary from the "artifacts"
|
||||
section at the bottom.
|
||||
|
||||
Pre-compiled binaries might also be available in your package management system of
|
||||
choice, but please do not submit any bug reports without first trying to build
|
||||
termtris yourself from the latest git source code.
|
||||
- Debian/Ubuntu/Mint: `apt-get install termtris`
|
||||
|
||||
The latest pre-compiled DOS binary (currently 1.9) is always available at:
|
||||
http://nuclear.mutantstargoat.com/sw/termtris/termtris.com
|
||||
|
||||
Build (UNIX)
|
||||
------------
|
||||
There are no external dependencies. Simply type `make` to build, and `make
|
||||
install` if you wish to install termtris.
|
||||
|
||||
Default installation prefix is `/usr/local`. Change the first line of the
|
||||
`Makefile` if you'd rather install somewhere else, or simply invoke the install
|
||||
rule like so:
|
||||
|
||||
make PREFIX=/some/other/prefix install
|
||||
|
||||
If you don't have GNU make and GCC installed, or you'd rather use the default
|
||||
make utility and C compiler on your UNIX system, you can use `Makefile.sgi`:
|
||||
|
||||
make -f Makefile.sgi
|
||||
|
||||
(originally included for building on SGI IRIX with MIPSPro and the native make).
|
||||
|
||||
|
||||
Build (DOS)
|
||||
-----------
|
||||
To build the DOS version of termtris you'll need some version of the Watcom or
|
||||
OpenWatcom C compiler, and the NASM assembler:
|
||||
|
||||
make -f Makefile.wat
|
||||
@@ -0,0 +1 @@
|
||||
7c5435dd4e93ffc10f3b5c68fe1ae9718a365258
|
||||
@@ -0,0 +1,194 @@
|
||||
# termtris on the VT1200
|
||||
|
||||
`apps/termtris/` is a port of John Tsiombikas' `termtris`
|
||||
(https://github.com/jtsiomb/termtris, commit `7c5435dd4e93ffc10f3b5c68fe1ae9718a365258`)
|
||||
that runs **inside the VT1200 as a native TMS34010 program**, drawing through
|
||||
the terminal's own ROM Xlib and reading real X11 key events from the local X
|
||||
server. There is no host process and no terminal escape output: the COFF is
|
||||
loaded into VT1200 RAM and executed by the TMS34010.
|
||||
|
||||

|
||||
|
||||
## What runs where
|
||||
|
||||
| piece | file | role |
|
||||
|---|---|---|
|
||||
| game rules | `src/game.c` (upstream) | unchanged logic; one portability edit (`srand(vt_rand_seed())` instead of `time(0)`) |
|
||||
| term callbacks | `src/vt1200/x11.c` | 80×24 character-cell grid drawn with `XFillRectangle`/`XDrawString` |
|
||||
| event loop | `src/vt1200/main.c` | `XNextEvent` + `XLookupString`, key map, millisecond clock, `sleep()` |
|
||||
| scores | `src/vt1200/scoredb.c` | RAM-only high-score table (no filesystem) |
|
||||
| libc shims | `src/vt1200/compat.c`, `stdio.h`, `inttypes.h` | `sprintf`/`fflush`/`putchar`, fixed-width types |
|
||||
| Xlib | `src/vt1200/xlib.h` | ROM entry points by bit address, called with the TI C ABI |
|
||||
| startup | `src/vt1200/entry.asm`, `cinit.asm`, `cinitz.asm` | set `A14 = _cstack`, run the `.cinit` table, `calla _main` |
|
||||
| toolchain | `build.sh` | TI TMS340 Family Code Generation Tools r5.01 (1990-11) under 2ine |
|
||||
|
||||
## Building
|
||||
|
||||
```sh
|
||||
cd apps/termtris
|
||||
OUTNAME=termtris ./build.sh src/vt1200/main.c src/game.c \
|
||||
src/vt1200/scoredb.c src/vt1200/x11.c src/vt1200/compat.c \
|
||||
src/vt1200/xgfix.c
|
||||
```
|
||||
|
||||
`build.sh` unpacks the r5.01 SDK zips, runs `gspac`/`gspopt`/`gspcg`/`gspa` and
|
||||
`gsplnk` through `lx_loader`, and writes `build/termtris.coff` + `.map` (without
|
||||
`OUTNAME` it uses the first source's name). Set `NINE=` to the 2ine build
|
||||
directory (default `/home/arti/os2-work/2ine/build`). The 2ine-hosted tools
|
||||
routinely segfault *after* producing their output, so the script clears the
|
||||
expected output, treats a non-empty file as success, and retries a missing one;
|
||||
`gspac` needs `-i.` for the angle-bracket shim headers.
|
||||
|
||||
The r5.01 programs are 16-bit OS/2 `NE` executables. `lx_loader` is 32-bit but
|
||||
maps them through 16-bit LDT segments, and a Linux kernel built without
|
||||
`CONFIG_X86_16BIT` rejects those (`modify_ldt` returns `EINVAL`) — the loader
|
||||
then aborts at its first segment even though it starts. On such a host
|
||||
`build.sh` probes for that failure and runs the same loader through
|
||||
`qemu-i386`, whose linux-user `modify_ldt` does implement 16-bit segments. Set
|
||||
`LX_RUNNER=qemu-i386` to force a runner, or install `qemu-user` so the fallback
|
||||
is available. The generated COFF is unchanged; only its header timestamp
|
||||
differs between builds.
|
||||
|
||||
Link map (relevant addresses are **bit** addresses, like everything the
|
||||
TMS34010 sees):
|
||||
|
||||
```
|
||||
.text 018A0000 .data 018A0000 .cinit 018B4A60
|
||||
.bss 01A00000
|
||||
ENTRY POINT SYMBOL: "_start" address: 018a0000
|
||||
```
|
||||
|
||||
The `.cinit` address moves when the code changes; this block matches the
|
||||
current build's `build/termtris.map`.
|
||||
|
||||
An empty `.cinit` makes the linker point `cinit` at `.text`, and the entry
|
||||
walker would then read an instruction as a record count; when the map says the
|
||||
section is empty `build.sh` relinks with the one-word `CINITZ.obj` terminator.
|
||||
|
||||
## The Xlib context (the one thing that had to be discovered)
|
||||
|
||||
A freshly `create_process`ed child has `*(*(proc + 0x100)) == NULL`. The ROM
|
||||
Xlib's `_XEnq` does `XG = *(*(proc+0x100)); free_list = *(XG + 0x198)`, so
|
||||
`XNextEvent` reads low-RAM garbage as queue nodes and delivers nothing. The
|
||||
port installs a zeroed 1 KiB block as the per-process Xlib context before
|
||||
`XOpenDisplay` (`src/vt1200/xgfix.c`), which is a RAM write only — the ROM is
|
||||
untouched. With that in place the smoke test receives a real
|
||||
`KeyPress (type=2, keycode=194)` and `XLookupString` returns `a`.
|
||||
|
||||
## Rendering
|
||||
|
||||
The frame is an 80×24 grid of 6×13 cells (the default GC font, baseline +10),
|
||||
so the window is 480×312. The VT1200 raster is **one bit deep**, so the backend
|
||||
renders like the game's monochrome mode (colour is dropped) and uses the bold
|
||||
bit (`0x80`) as reverse video for emphasis — a choice of this backend, not the
|
||||
upstream ANSI convention (which emits SGR bold and leaves the colours alone). The playfield is therefore black
|
||||
spaces and the tetrominoes are the `[`/`]` tiles, exactly what a 1-bit terminal
|
||||
can show.
|
||||
|
||||
`vt_x11_flush()` repaints whole rows rather than cells: one `XFillRectangle`
|
||||
for the row background, one `XDrawString` for its 80 characters, plus
|
||||
fill/string pairs for reversed spans, then a single `XFlush`. This matters. An
|
||||
earlier per-cell version (four requests per cell) filled the X socket faster
|
||||
than the in-machine server could drain it, and an `XSync` per row deadlocked
|
||||
the client: the debug progress marker stopped at row 20 (`0x00010014`) and the
|
||||
game never reached its main loop. Batching the row makes a full 80×24 redraw a
|
||||
few hundred bytes of requests and the loop runs (measured at the VR319
|
||||
default: 650 iterations between frames 2500 and 3200).
|
||||
|
||||
## Timing and input
|
||||
|
||||
`now_ms()` accumulates the 16-bit counter at bit `0x1E93C0` into a 32-bit
|
||||
millisecond count; `sleep_ms()` calls the ROM `sleep` at `0x3FB33A20` with a
|
||||
1–10 ms clamp. The game's own `update()` decides the tick interval (887 ms at
|
||||
level 0).
|
||||
|
||||
Keys arrive as X11 `KeyPress` events and go through `XLookupString`; letters are
|
||||
lower-cased and handed to `game_input()`. Arrows are sent as the game's own CSI
|
||||
codes (`0x9b` + `A`/`B`/`C`/`D`), which `game_input` translates back to
|
||||
`w`/`s`/`d`/`a`. `0x7F` is Delete (Backspace is `0x08`). `FocusOut` sends `p`
|
||||
and `FocusIn` sends `p` again, but the flag only tracks focus, not the game's
|
||||
own pause state: pressing `p` and then moving focus away resumes the game while
|
||||
it is unfocused.
|
||||
|
||||
`ExposureMask` is deliberately **not** selected: the map-time `Expose` arrives
|
||||
before the game has a current piece, and the game's full-redraw path then draws
|
||||
a non-existent piece over the top row — visible as a blanked border with stray
|
||||
`X` tiles. The acceptance run never obscures the window (the Terminal Manager
|
||||
sits beside it), so the mask buys nothing there. See `HANDOFF.md`.
|
||||
|
||||
## Running it in MAME
|
||||
|
||||
The emulator must be built from the driver in this tree; an older
|
||||
`/home/arti/code/k-space/mame0289/vt1200` may still carry the pre-VR319
|
||||
geometry:
|
||||
|
||||
```sh
|
||||
harness/mame/build.sh # rebuild the vt1200 subtarget (JOBS=4 on small hosts)
|
||||
```
|
||||
|
||||
Then:
|
||||
|
||||
```sh
|
||||
apps/termtris/verify.sh # build MAME + run every test (see HANDOFF.md)
|
||||
apps/termtris/tests/play.sh # load, click, snapshot
|
||||
apps/termtris/tests/play_keys.sh # move / panels / quit acceptance runs
|
||||
apps/termtris/run.sh # same run, interactive session
|
||||
```
|
||||
|
||||
Under the hood the loader payload is dropped at bit `0x01880000` and the COFF at
|
||||
`0x01900000`; at frame 2500 the script enters `dwt/loader/build/loader.bin`,
|
||||
which copies the sections to their linked addresses and calls
|
||||
`create_process`. The X server is already up because the run uses
|
||||
`VT1200_SKIP_LEVEL1=1` to reach the OS.
|
||||
|
||||
## Evidence
|
||||
|
||||
| file | what it shows |
|
||||
|---|---|
|
||||
| `evidence/termtris_frame3300.png` | the board, score/level/lines panels, preview and `Toggle (H)elp` |
|
||||
| `evidence/termtris_move_3200.png` | after `a d s w 0`: a piece has been moved/rotated/dropped to the bottom-left and a new one spawned |
|
||||
| `evidence/termtris_panels_3200.png` | after `h` and `r`: the help text and the high-score list (all `VT1200`) |
|
||||
| `evidence/termtris_quit_3200.png` | after `q`: same screen, and the run reports `quit=1` |
|
||||
| `evidence/render_frame3400.png` | the cell-grid renderer test pattern |
|
||||
|
||||
Acceptance values from the last full run (`play_keys.sh`, MAME 0.289 with this
|
||||
tree's driver at the **VR319 default**, 1280×1024 frames). The evidence PNGs
|
||||
above were regenerated in the same run; they are 1280×1024, where the earlier
|
||||
ones were 1024×864 VR150 captures.
|
||||
|
||||
```
|
||||
move DIAG: loops=650 events=18 last=3 focus=00400001 rev=0 quit=0
|
||||
panels DIAG: loops=648 events=12 last=3 focus=00400001 rev=0 quit=0
|
||||
quit DIAG: loops=555 events=10 last=3 focus=00400001 rev=0 quit=1
|
||||
```
|
||||
|
||||
`focus=00400001` is the window this process created, sampled on the click's
|
||||
`ButtonRelease` (it is the only window in the run). It shows the click reached
|
||||
the right window, not that each later key did; the key-delivery proof is
|
||||
`quit=1`, the game's own global after `q`. The loop counts are higher than the
|
||||
old VR150 figures
|
||||
(`354`/`346`/`300`) only because the VR319 raster runs at a different emulated
|
||||
frame rate; the event counts, window, and quit result are unchanged, and the
|
||||
loader/keys still act at frames 2500/3095–3190.
|
||||
|
||||
## Limits, stated plainly
|
||||
|
||||
* **No sound.** The game's bell is a no-op.
|
||||
* **Scores are RAM-only.** `read_scores`/`save_score` keep ten entries in
|
||||
`.bss`; they vanish when the process exits. The VT1200 has no writable
|
||||
filesystem for a child.
|
||||
* **Startup is retried.** If `XOpenDisplay`/window creation fails while the
|
||||
display server is still settling, `main()` retries up to 40 times with a
|
||||
50 ms sleep before giving up. Observed as an intermittent early exit.
|
||||
* **`q` ends the game loop but the window stays on screen.** `quit=1` is
|
||||
observable in RAM and `main()` returns; the frame captured about a second
|
||||
later still shows the window, so the X connection is not torn down by process
|
||||
exit in this OS. Treat that as an observation, not a designed behaviour.
|
||||
* **The board is text.** Tetrominoes are `[`/`]` tiles, not filled blocks — the
|
||||
only thing a 1-bit cell can show without a custom font.
|
||||
* **An occluding window is not repainted.** Because `ExposureMask` is off (the
|
||||
map-time `Expose` bug above), cells covered by another window stay stale until
|
||||
the game next draws them. The acceptance run does not exercise this.
|
||||
|
||||
The ROM (`vt1200_v22.bin`, md5 `b46a3e442ccb86134d2356bd70d22fd2`) is never
|
||||
modified; the port lives entirely in RAM.
|
||||
@@ -0,0 +1,199 @@
|
||||
#!/bin/sh
|
||||
# build.sh -- build a VT1200 COFF with TI TMS34010 r5.01 under 2ine.
|
||||
#
|
||||
# apps/termtris/build.sh SOURCE.c [SOURCE.c ...] [EXTRA.obj ...]
|
||||
#
|
||||
# The first .c is the main program; the output is build/<main>.coff. entry.asm
|
||||
# and cinit.asm are always assembled and linked. The 2ine loader is outside the
|
||||
# repo: point NINE at its build directory (default /home/arti/os2-work/2ine/build).
|
||||
set -eu
|
||||
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
ROOT=$(cd "$DIR/../.." && pwd)
|
||||
WORK="$DIR/work"
|
||||
OUT="$DIR/build"
|
||||
NINE="${NINE:-/home/arti/os2-work/2ine/build}"
|
||||
LX="$NINE/lx_loader"
|
||||
SDK="$ROOT/tools/tms34010-sdk/1990-11 TMS340 Family SDK"
|
||||
Z1="$SDK/1990-11-19 TMS340 Family Code Generation Tools (1 of 2) r5.01 rev2564062-1641.zip"
|
||||
Z2="$SDK/1990-11-19 TMS340 Family Code Generation Tools (2 of 2) r5.01 rev2564062-1641.zip"
|
||||
|
||||
if [ ! -x "$LX" ]; then
|
||||
echo "build.sh: no 2ine lx_loader at $LX (set NINE=...)" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -f "$Z1" ] || [ ! -f "$Z2" ]; then
|
||||
echo "build.sh: r5.01 SDK zips not found under $SDK" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p "$WORK" "$OUT"
|
||||
if [ ! -x "$WORK/gspac.exe" ]; then
|
||||
unzip -oq "$Z1" -d "$WORK"
|
||||
unzip -oq "$Z2" -d "$WORK"
|
||||
fi
|
||||
|
||||
# The r5.01 tools are 16-bit OS/2 NE programs, which 2ine runs through 16-bit
|
||||
# LDT segments. A Linux kernel built without CONFIG_X86_16BIT rejects those
|
||||
# (modify_ldt returns EINVAL), so the loader aborts at its first segment even
|
||||
# though it is a 32-bit binary. Detect that with a probe run and, when needed,
|
||||
# drive the same loader through qemu-i386, whose linux-user emulation does
|
||||
# implement the 16-bit LDT. Set LX_RUNNER to a command prefix (for example
|
||||
# "qemu-i386") to force one; leave it unset to auto-detect.
|
||||
LX_RUNNER=${LX_RUNNER:-}
|
||||
if [ -z "$LX_RUNNER" ]; then
|
||||
probe=$( ( cd "$WORK" && "$LX" ./gspac.exe ) 2>&1 || true )
|
||||
case $probe in
|
||||
*failed\ to\ allocate\ LDT\ selector*|*modify_ldt*)
|
||||
if command -v qemu-i386 >/dev/null 2>&1; then
|
||||
LX_RUNNER=qemu-i386
|
||||
else
|
||||
echo "build.sh: this kernel has no 16-bit LDT support and qemu-i386 is not installed" >&2
|
||||
echo "build.sh: install qemu-user, or set LX_RUNNER to a working runner" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
for so in "$NINE"/lib*.so; do
|
||||
[ -e "$so" ] && ln -sf "$so" "$WORK/"
|
||||
done
|
||||
cp "$DIR/src/vt1200/"*.h "$WORK/" 2>/dev/null || true
|
||||
cp "$DIR/src/"*.h "$WORK/" 2>/dev/null || true
|
||||
cp "$DIR/src/vt1200/entry.asm" "$DIR/src/vt1200/cinit.asm" "$DIR/src/vt1200/cinitz.asm" "$WORK/"
|
||||
|
||||
# Collect objects. C sources are copied under their uppercase basename because
|
||||
# the OS/2 tools are case-sensitive on this host.
|
||||
OBJS=""
|
||||
MAIN=""
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
*.c)
|
||||
base=$(basename "$arg" .c | tr 'a-z' 'A-Z')
|
||||
[ -n "$MAIN" ] || MAIN="$base"
|
||||
cp "$arg" "$WORK/$base.C"
|
||||
OBJS="$OBJS $base"
|
||||
;;
|
||||
*.obj)
|
||||
cp "$arg" "$WORK/"
|
||||
OBJS="$OBJS $(basename "$arg")"
|
||||
;;
|
||||
*.asm)
|
||||
base=$(basename "$arg" .asm | tr 'a-z' 'A-Z')
|
||||
cp "$arg" "$WORK/$base.ASM"
|
||||
OBJS="$OBJS $base"
|
||||
;;
|
||||
*)
|
||||
echo "build.sh: unsupported input: $arg" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if [ -z "$MAIN" ]; then
|
||||
echo "build.sh: give at least one .c source" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The 2ine-hosted tools frequently crash during teardown after doing their work
|
||||
# (exit 139 / 134). Treat an output file as success, and retry a missing one.
|
||||
run() {
|
||||
_out=$1
|
||||
shift
|
||||
i=0
|
||||
_log=
|
||||
while [ "$i" -lt 5 ]; do
|
||||
# A stage that crashed after a partial write must not be mistaken
|
||||
# for success, and an output left by an earlier build must not
|
||||
# hide a failing stage now.
|
||||
rm -f "$WORK/$_out"
|
||||
_log=$( ( cd "$WORK" && ${LX_RUNNER:-} "$LX" "$@" ) 2>&1 || true )
|
||||
if [ -s "$WORK/$_out" ]; then
|
||||
return 0
|
||||
fi
|
||||
i=$((i + 1))
|
||||
done
|
||||
echo "build.sh: stage failed to produce $WORK/$_out: $*" >&2
|
||||
[ -n "$_log" ] && printf '%s\n' "$_log" | tail -10 >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
compile_c() {
|
||||
base=$1
|
||||
rm -f "$WORK/$base.IF" "$WORK/$base.OPT" "$WORK/$base.ASM" "$WORK/$base.obj"
|
||||
run "$base.IF" ./gspac.exe -k -i. "$base.C" "$base.IF"
|
||||
run "$base.OPT" ./gspopt.exe -k -O2 "$base.IF" "$base.OPT"
|
||||
run "$base.ASM" ./gspcg.exe -m "$base.OPT" "$base.ASM" "$base.TMP"
|
||||
run "$base.obj" ./gspa.exe "$base.ASM"
|
||||
}
|
||||
|
||||
compile_asm() {
|
||||
base=$1
|
||||
rm -f "$WORK/$base.obj"
|
||||
run "$base.obj" ./gspa.exe "$base.ASM"
|
||||
}
|
||||
|
||||
|
||||
# Compile every collected object exactly once, in the order given.
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
*.c) compile_c "$(basename "$arg" .c | tr 'a-z' 'A-Z')" ;;
|
||||
*.asm) compile_asm "$(basename "$arg" .asm | tr 'a-z' 'A-Z')" ;;
|
||||
esac
|
||||
done
|
||||
compile_asm ENTRY
|
||||
compile_asm CINIT
|
||||
compile_asm CINITZ
|
||||
|
||||
OUTNAME=${OUTNAME:-$(printf '%s' "$MAIN" | tr 'A-Z' 'a-z')}
|
||||
CMD="$WORK/$MAIN.CMD"
|
||||
{
|
||||
printf '%s\n' '-a'
|
||||
printf '%s\n' "-o $MAIN.out"
|
||||
printf '%s\n' "-m $MAIN.map"
|
||||
printf '%s\n' '-e _start'
|
||||
printf '%s\n' 'CINIT.obj'
|
||||
printf '%s\n' 'ENTRY.obj'
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
*.c) printf '%s\n' "$(basename "$arg" .c | tr 'a-z' 'A-Z').obj" ;;
|
||||
*.asm) printf '%s\n' "$(basename "$arg" .asm | tr 'a-z' 'A-Z').obj" ;;
|
||||
*.obj) printf '%s\n' "$(basename "$arg")" ;;
|
||||
esac
|
||||
done
|
||||
printf '%s\n' '-l rts.lib'
|
||||
printf '%s\n' 'MEMORY'
|
||||
printf '%s\n' '{'
|
||||
printf '%s\n' ' prog: origin = 018A0000h, length = 20000h'
|
||||
printf '%s\n' ' ram: origin = 01A00000h, length = 40000h'
|
||||
printf '%s\n' '}'
|
||||
printf '%s\n' 'SECTIONS'
|
||||
printf '%s\n' '{'
|
||||
printf '%s\n' ' .text: {} > prog'
|
||||
printf '%s\n' ' .data: {} > prog'
|
||||
printf '%s\n' ' .cinit: {} > prog'
|
||||
printf '%s\n' ' .bss: {} > ram'
|
||||
printf '%s\n' '}'
|
||||
} > "$CMD"
|
||||
sed -i 's/$/\r/' "$CMD"
|
||||
|
||||
rm -f "$WORK/$MAIN.out" "$WORK/$MAIN.map"
|
||||
run "$MAIN.out" ./gsplnk.exe "$MAIN.CMD"
|
||||
if [ ! -f "$WORK/$MAIN.map" ]; then
|
||||
echo "build.sh: no link map" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# An empty .cinit makes the linker's `cinit` symbol point at .text; the entry's
|
||||
# cinit walker would then treat an instruction as a record count. Relink with
|
||||
# a one-word terminator when the map says the section is empty.
|
||||
CSIZE=$(awk '$1 == ".cinit" {print $4; exit}' "$WORK/$MAIN.map")
|
||||
if [ "$CSIZE" = "00000000" ]; then
|
||||
sed -i 's/CINIT\.obj/CINITZ.obj/' "$CMD"
|
||||
rm -f "$WORK/$MAIN.out" "$WORK/$MAIN.map"
|
||||
run "$MAIN.out" ./gsplnk.exe "$MAIN.CMD"
|
||||
fi
|
||||
|
||||
cp "$WORK/$MAIN.out" "$OUT/$OUTNAME.coff"
|
||||
sed 's/\r$//' "$WORK/$MAIN.map" > "$OUT/$OUTNAME.map"
|
||||
echo "build.sh: $OUT/$OUTNAME.coff ($(wc -c < "$OUT/$OUTNAME.coff") bytes)"
|
||||
sed -n '1,40p' "$OUT/$OUTNAME.map"
|
||||
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 22 KiB |
@@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
# run.sh -- load termtris into a running VT1200 OS under MAME and play it.
|
||||
#
|
||||
# apps/termtris/run.sh # click the window active, then play
|
||||
# apps/termtris/run.sh --build # rebuild the COFF first
|
||||
#
|
||||
# The emulated keyboard and tablet are driven by MAME's host input, so the
|
||||
# terminal's X cursor follows the host pointer. Quit with Ctrl-C in the
|
||||
# terminal running MAME, or press 'q' in the game (it stops the game loop).
|
||||
set -eu
|
||||
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
ROOT=$(cd "$DIR/../.." && pwd)
|
||||
M=${MAME:-/home/arti/code/k-space/mame0289/vt1200}
|
||||
LOADER="$ROOT/dwt/loader/build/loader.bin"
|
||||
COFF="$DIR/build/termtris.coff"
|
||||
|
||||
if [ "${1:-}" = "--build" ]; then
|
||||
OUTNAME=termtris "$DIR/build.sh" "$DIR/src/vt1200/main.c" "$DIR/src/game.c" \
|
||||
"$DIR/src/vt1200/scoredb.c" "$DIR/src/vt1200/x11.c" \
|
||||
"$DIR/src/vt1200/compat.c" "$DIR/src/vt1200/xgfix.c"
|
||||
fi
|
||||
|
||||
if [ ! -f "$COFF" ]; then
|
||||
echo "run.sh: no $COFF (run with --build)" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ ! -f "$LOADER" ]; then
|
||||
echo "run.sh: no loader payload at $LOADER" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# The game is loaded at frame 2500, once the OS X server is up.
|
||||
exec env VT1200_SKIP_LEVEL1=1 \
|
||||
LOADER_AT=2500 LOADER_END=100000000 \
|
||||
LOADER_BIN="$LOADER" LOADER_COFF="$COFF" LOADER_OUT="$DIR/build" \
|
||||
"$M" vt1200 -rompath "$ROOT/harness/mame/roms" \
|
||||
-skip_gameinfo -debug -debugger none \
|
||||
-lightgun -lightgun_device mouse \
|
||||
-autoboot_script "$DIR/tests/play.lua" -autoboot_delay 0
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Termtris - a tetris game for ANSI/VT100 terminals
|
||||
Copyright (C) 2019-2023 John Tsiombikas <nuclear@member.fsf.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef GAME_H_
|
||||
#define GAME_H_
|
||||
|
||||
extern int quit;
|
||||
extern long tick_interval;
|
||||
extern int use_bell;
|
||||
extern int monochrome;
|
||||
extern int use_gfxchar;
|
||||
extern int onlyascii;
|
||||
extern int blackpf;
|
||||
extern int rotstep;
|
||||
|
||||
extern int term_width, term_height;
|
||||
|
||||
int init_game(void);
|
||||
void cleanup_game(void);
|
||||
|
||||
long update(long msec);
|
||||
void game_input(int c);
|
||||
|
||||
/* wait for any pending drawing to be completed before proceeding
|
||||
* implemented in main.c
|
||||
*/
|
||||
void wait_display(void);
|
||||
|
||||
#endif /* GAME_H_ */
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Termtris - a tetris game for ANSI/VT100 terminals
|
||||
Copyright (C) 2019-2022 John Tsiombikas <nuclear@member.fsf.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef PIECES_H_
|
||||
#define PIECES_H_
|
||||
|
||||
#define BLK(x, y) ((x) | ((y) << 4))
|
||||
#define BLKX(c) ((unsigned char)(c) & 0xf)
|
||||
#define BLKY(c) ((unsigned char)(c) >> 4)
|
||||
|
||||
#define NUM_PIECES 7
|
||||
|
||||
static unsigned char pieces[NUM_PIECES][4][4] = {
|
||||
/* L block */
|
||||
{
|
||||
{BLK(0, 1), BLK(0, 2), BLK(1, 1), BLK(2, 1)},
|
||||
{BLK(0, 0), BLK(1, 0), BLK(1, 1), BLK(1, 2)},
|
||||
{BLK(0, 1), BLK(1, 1), BLK(2, 1), BLK(2, 0)},
|
||||
{BLK(1, 0), BLK(1, 1), BLK(1, 2), BLK(2, 2)}
|
||||
},
|
||||
/* J block */
|
||||
{
|
||||
{BLK(0, 1), BLK(1, 1), BLK(2, 1), BLK(2, 2)},
|
||||
{BLK(1, 0), BLK(1, 1), BLK(1, 2), BLK(0, 2)},
|
||||
{BLK(0, 0), BLK(0, 1), BLK(1, 1), BLK(2, 1)},
|
||||
{BLK(1, 0), BLK(2, 0), BLK(1, 1), BLK(1, 2)}
|
||||
},
|
||||
/* I block */
|
||||
{
|
||||
{BLK(0, 2), BLK(1, 2), BLK(2, 2), BLK(3, 2)},
|
||||
{BLK(1, 0), BLK(1, 1), BLK(1, 2), BLK(1, 3)},
|
||||
{BLK(0, 2), BLK(1, 2), BLK(2, 2), BLK(3, 2)},
|
||||
{BLK(1, 0), BLK(1, 1), BLK(1, 2), BLK(1, 3)}
|
||||
},
|
||||
/* O block */
|
||||
{
|
||||
{BLK(1, 1), BLK(2, 1), BLK(1, 2), BLK(2, 2)},
|
||||
{BLK(1, 1), BLK(2, 1), BLK(1, 2), BLK(2, 2)},
|
||||
{BLK(1, 1), BLK(2, 1), BLK(1, 2), BLK(2, 2)},
|
||||
{BLK(1, 1), BLK(2, 1), BLK(1, 2), BLK(2, 2)}
|
||||
},
|
||||
/* Z block */
|
||||
{
|
||||
{BLK(0, 1), BLK(1, 1), BLK(1, 2), BLK(2, 2)},
|
||||
{BLK(0, 1), BLK(1, 1), BLK(1, 0), BLK(0, 2)},
|
||||
{BLK(0, 1), BLK(1, 1), BLK(1, 2), BLK(2, 2)},
|
||||
{BLK(0, 1), BLK(1, 1), BLK(1, 0), BLK(0, 2)}
|
||||
},
|
||||
/* S block */
|
||||
{
|
||||
{BLK(1, 1), BLK(2, 1), BLK(0, 2), BLK(1, 2)},
|
||||
{BLK(0, 0), BLK(0, 1), BLK(1, 1), BLK(1, 2)},
|
||||
{BLK(1, 1), BLK(2, 1), BLK(0, 2), BLK(1, 2)},
|
||||
{BLK(0, 0), BLK(0, 1), BLK(1, 1), BLK(1, 2)}
|
||||
},
|
||||
/* T block */
|
||||
{
|
||||
{BLK(0, 1), BLK(1, 1), BLK(2, 1), BLK(1, 2)},
|
||||
{BLK(1, 0), BLK(1, 1), BLK(1, 2), BLK(0, 1)},
|
||||
{BLK(0, 1), BLK(1, 1), BLK(2, 1), BLK(1, 0)},
|
||||
{BLK(1, 0), BLK(1, 1), BLK(1, 2), BLK(2, 1)}
|
||||
}
|
||||
};
|
||||
|
||||
static int piece_spawnpos[NUM_PIECES][2] = {
|
||||
{-1, -2}, {-1, -2}, {-2, -2}, {-1, -2}, {-1, -2}, {-1, -2}, {-1, -2}
|
||||
};
|
||||
|
||||
|
||||
#endif /* PIECES_H_ */
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Termtris - a tetris game for ANSI/VT100 terminals
|
||||
Copyright (C) 2019-2023 John Tsiombikas <nuclear@member.fsf.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef SCOREDB_H_
|
||||
#define SCOREDB_H_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(MSDOS) || defined(__COM__)
|
||||
/* the DOS version of score_entry is simpler, because scores are embedded in
|
||||
* the executable itself in binary format.
|
||||
*/
|
||||
#define MAX_NAME 36
|
||||
struct score_entry {
|
||||
char user[MAX_NAME];
|
||||
long score, lines, level;
|
||||
struct score_entry *next;
|
||||
};
|
||||
#else
|
||||
struct score_entry {
|
||||
char *user;
|
||||
long score, lines, level;
|
||||
struct score_entry *next;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct score_entry *read_scores(FILE *fp, int max_scores);
|
||||
int save_score(struct score_entry *sc);
|
||||
int print_scores(int num);
|
||||
|
||||
#endif /* SCOREDB_H_ */
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
Termtris - a tetris game for TERM/VT100 terminals
|
||||
Copyright (C) 2019-2022 John Tsiombikas <nuclear@member.fsf.org>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TERM_H_
|
||||
#define TERM_H_
|
||||
|
||||
enum {
|
||||
G_DIAMOND = 0x04,
|
||||
G_CHECKER = 0xb1,
|
||||
G_LR_CORNER = 0xd9,
|
||||
G_UR_CORNER = 0xbf,
|
||||
G_UL_CORNER = 0xda,
|
||||
G_LL_CORNER = 0xc0,
|
||||
G_CROSS = 0xc5,
|
||||
G_HLINE = 0xc4,
|
||||
G_L_TEE = 0xc3,
|
||||
G_R_TEE = 0xb4,
|
||||
G_B_TEE = 0xc1,
|
||||
G_T_TEE = 0xc2,
|
||||
G_VLINE = 0xb3,
|
||||
G_CDOT = 0xf8
|
||||
};
|
||||
|
||||
enum { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE };
|
||||
#define BOLD 8
|
||||
|
||||
enum {
|
||||
TERM_ANSI,
|
||||
TERM_VT52,
|
||||
TERM_ADM3,
|
||||
TERM_PCBIOS = 0xb105
|
||||
};
|
||||
|
||||
extern char *termenv;
|
||||
extern int term_type;
|
||||
|
||||
extern void (*term_reset)(void);
|
||||
extern void (*term_clearscr)(void);
|
||||
extern void (*term_setcursor)(int row, int col);
|
||||
extern void (*term_cursor)(int show);
|
||||
extern void (*term_setcolor)(int fg, int bg);
|
||||
/* convert a PC cga/ega/vga char+attr to an TERM sequence and write it to stdout */
|
||||
extern void (*term_ibmchar)(unsigned char c, unsigned char attr);
|
||||
|
||||
void term_init(void);
|
||||
void term_putstr(const char *s, unsigned char attr);
|
||||
|
||||
#endif /* TERM_H_ */
|
||||
@@ -0,0 +1,4 @@
|
||||
.sect ".cinit"
|
||||
.globl cinit
|
||||
cinit:
|
||||
.end
|
||||
@@ -0,0 +1,5 @@
|
||||
.sect ".cinit"
|
||||
.globl cinit
|
||||
cinit:
|
||||
.word 0
|
||||
.end
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* compat.c -- the small libc surface termtris needs on the VT1200.
|
||||
*
|
||||
* The TI r5.01 runtime has no stdio and no sprintf. This implements exactly
|
||||
* the decimal/string formats game.c uses. Arguments are walked manually
|
||||
* because the SDK's va_arg macro does not survive the 1990 compiler's
|
||||
* preprocessor here; the TI ABI lays the varargs contiguously below &fmt.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
FILE *stdout;
|
||||
extern int strlen(char *);
|
||||
|
||||
int fflush(FILE *fp)
|
||||
{
|
||||
(void)fp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int putchar(int c)
|
||||
{
|
||||
(void)c;
|
||||
return c;
|
||||
}
|
||||
|
||||
static char *fmt_num(char *out, long v, int width, int zero, int left, int unsig)
|
||||
{
|
||||
char tmp[24];
|
||||
int n = 0, neg = 0, pad, i;
|
||||
unsigned long u;
|
||||
|
||||
if(v < 0 && !unsig) {
|
||||
neg = 1;
|
||||
u = (unsigned long)(-v);
|
||||
} else {
|
||||
u = (unsigned long)v;
|
||||
}
|
||||
do {
|
||||
tmp[n++] = (char)('0' + (u % 10UL));
|
||||
u /= 10UL;
|
||||
} while(u);
|
||||
|
||||
pad = width - (n + neg);
|
||||
if(pad < 0) pad = 0;
|
||||
|
||||
if(left) {
|
||||
if(neg) *out++ = '-';
|
||||
while(n) *out++ = tmp[--n];
|
||||
for(i = 0; i < pad; i++) *out++ = ' ';
|
||||
} else if(zero) {
|
||||
if(neg) *out++ = '-';
|
||||
for(i = 0; i < pad; i++) *out++ = '0';
|
||||
while(n) *out++ = tmp[--n];
|
||||
} else {
|
||||
for(i = 0; i < pad; i++) *out++ = ' ';
|
||||
if(neg) *out++ = '-';
|
||||
while(n) *out++ = tmp[--n];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int sprintf(char *buf, char *fmt, ...)
|
||||
{
|
||||
char *out = buf;
|
||||
char *ap = (char *)&fmt;
|
||||
|
||||
while(*fmt) {
|
||||
int left = 0, zero = 0, width = 0, unsig = 0, islong = 0;
|
||||
|
||||
if(*fmt != '%') {
|
||||
*out++ = *fmt++;
|
||||
continue;
|
||||
}
|
||||
fmt++;
|
||||
if(*fmt == '%') {
|
||||
*out++ = '%';
|
||||
fmt++;
|
||||
continue;
|
||||
}
|
||||
if(*fmt == '-') { left = 1; fmt++; }
|
||||
if(*fmt == '0') { zero = 1; fmt++; }
|
||||
while(*fmt >= '0' && *fmt <= '9') {
|
||||
width = width * 10 + (*fmt - '0');
|
||||
fmt++;
|
||||
}
|
||||
if(*fmt == 'l') { islong = 1; fmt++; }
|
||||
if(*fmt == 'u') { unsig = 1; }
|
||||
|
||||
switch(*fmt) {
|
||||
case 'd':
|
||||
case 'u':
|
||||
{
|
||||
long v;
|
||||
ap -= sizeof(long);
|
||||
v = *(long *)ap;
|
||||
(void)islong;
|
||||
out = fmt_num(out, v, width, zero, left, unsig);
|
||||
fmt++;
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
{
|
||||
char *s;
|
||||
int len, i, pad;
|
||||
ap -= sizeof(char *);
|
||||
s = *(char **)ap;
|
||||
if(!s) s = "(null)";
|
||||
len = strlen(s);
|
||||
pad = width - len;
|
||||
if(pad < 0) pad = 0;
|
||||
if(!left) for(i = 0; i < pad; i++) *out++ = ' ';
|
||||
for(i = 0; i < len; i++) *out++ = s[i];
|
||||
if(left) for(i = 0; i < pad; i++) *out++ = ' ';
|
||||
fmt++;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
{
|
||||
int c;
|
||||
ap -= sizeof(int);
|
||||
c = *(int *)ap;
|
||||
*out++ = (char)c;
|
||||
fmt++;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
*out++ = '%';
|
||||
if(*fmt) *out++ = *fmt++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*out = 0;
|
||||
return (int)(out - buf);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
.text
|
||||
.globl _start
|
||||
.globl _main
|
||||
.globl cinit
|
||||
_start:
|
||||
setf 32,0,1
|
||||
movi _cstack,a14
|
||||
move a14,a13
|
||||
|
||||
; process the .cinit table: u16 word count, u32 destination, data words
|
||||
movi cinit,a9
|
||||
ci_loop:
|
||||
setf 16,0,0
|
||||
move *a9+,a11
|
||||
jrz ci_done
|
||||
move *a9+,a10,1
|
||||
ci_copy:
|
||||
move *a9+,*a10+
|
||||
dsjs a11,ci_copy
|
||||
jruc ci_loop
|
||||
ci_done:
|
||||
setf 32,0,1
|
||||
move a13,a14
|
||||
calla _main
|
||||
rets
|
||||
|
||||
.bss _cstack,32768,16
|
||||
.end
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* inttypes.h -- the fixed-width types game.c uses, for the 1990 TI compiler.
|
||||
*/
|
||||
#ifndef VT_INTTYPES_H_
|
||||
#define VT_INTTYPES_H_
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef signed long int32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* main.c -- the VT1200 termtris event loop.
|
||||
*
|
||||
* The game's update()/init_game() draw through the backend's term_* callbacks;
|
||||
* this file owns the X11 event drain, the real-time clock, and the key map.
|
||||
*/
|
||||
#include "game.h"
|
||||
#include "x11.h"
|
||||
#include "xlib.h"
|
||||
|
||||
extern int init_game(void);
|
||||
extern long update(long msec);
|
||||
extern void game_input(int c);
|
||||
|
||||
extern int vt_install_xg(void);
|
||||
|
||||
static vt_u32 evbuf[24];
|
||||
static long ms_base;
|
||||
static int ms_last = -1;
|
||||
static int focused;
|
||||
static int vt_paused;
|
||||
volatile vt_u32 dbg_loops, dbg_events, dbg_last, dbg_focus, dbg_rev;
|
||||
|
||||
long now_ms(void)
|
||||
{
|
||||
int now;
|
||||
if(ms_last < 0) {
|
||||
ms_last = *(volatile unsigned short *)0x001E93C0UL;
|
||||
ms_base = 0;
|
||||
return 0;
|
||||
}
|
||||
now = *(volatile unsigned short *)0x001E93C0UL;
|
||||
ms_base += (long)(unsigned short)(now - ms_last);
|
||||
ms_last = now;
|
||||
return ms_base;
|
||||
}
|
||||
|
||||
/*
|
||||
* Seed for the game's PRNG. now_ms() returns 0 on its first call (it only
|
||||
* latches the counter there), so seeding from it gives a constant; read the
|
||||
* free-running 16-bit tick directly instead.
|
||||
*/
|
||||
unsigned vt_rand_seed(void)
|
||||
{
|
||||
return (unsigned)*(volatile unsigned short *)0x001E93C0UL;
|
||||
}
|
||||
|
||||
void sleep_ms(int ms)
|
||||
{
|
||||
if(ms < 1) ms = 1;
|
||||
if(ms > 10) ms = 10;
|
||||
VT_SLEEP(ms);
|
||||
}
|
||||
|
||||
int vt_poll_event(void)
|
||||
{
|
||||
return *(vt_u32 *)((char *)vt_dpy + 0x54) != 0;
|
||||
}
|
||||
|
||||
static void map_keysym(vt_u32 ks, char ch, int n)
|
||||
{
|
||||
switch(ks) {
|
||||
case 0xFF51UL: /* Left */
|
||||
game_input(0x9b); game_input('D');
|
||||
return;
|
||||
case 0xFF53UL: /* Right */
|
||||
game_input(0x9b); game_input('C');
|
||||
return;
|
||||
case 0xFF52UL: /* Up */
|
||||
game_input(0x9b); game_input('A');
|
||||
return;
|
||||
case 0xFF54UL: /* Down */
|
||||
game_input(0x9b); game_input('B');
|
||||
return;
|
||||
case 0xFF0DUL: /* Return */
|
||||
game_input('\n');
|
||||
return;
|
||||
case 0xFF08UL: /* BackSpace */
|
||||
game_input('\b');
|
||||
return;
|
||||
case 0xFF09UL: /* Tab */
|
||||
game_input('\t');
|
||||
return;
|
||||
case 0xFF1BUL: /* Escape */
|
||||
game_input(27);
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if(n > 0) {
|
||||
if(ch >= 'A' && ch <= 'Z') ch = (char)(ch + ('a' - 'A'));
|
||||
game_input((int)(unsigned char)ch);
|
||||
}
|
||||
}
|
||||
|
||||
void vt_handle_event(void)
|
||||
{
|
||||
char buf[8];
|
||||
vt_u32 ks;
|
||||
int n;
|
||||
|
||||
VT_XNEXT(vt_dpy, (void *)evbuf);
|
||||
dbg_events = dbg_events + 1;
|
||||
dbg_last = evbuf[0];
|
||||
if(evbuf[0] == 2) { /* KeyPress */
|
||||
ks = 0;
|
||||
n = VT_XLOOKUP((void *)evbuf, buf, 8, &ks, 0);
|
||||
map_keysym(ks, n > 0 ? buf[0] : 0, n);
|
||||
} else if(evbuf[0] == 5) { /* ButtonRelease: sample focus */
|
||||
vt_u32 fw;
|
||||
int rv;
|
||||
VT_XGETFOCUS(vt_dpy, &fw, &rv);
|
||||
dbg_focus = fw;
|
||||
dbg_rev = (vt_u32)rv;
|
||||
} else if(evbuf[0] == 9) { /* FocusIn */
|
||||
focused = 1;
|
||||
if(vt_paused) { /* resume only what we paused */
|
||||
game_input('p');
|
||||
vt_paused = 0;
|
||||
}
|
||||
} else if(evbuf[0] == 10) { /* FocusOut */
|
||||
if(focused && !vt_paused) {
|
||||
game_input('p'); /* 'p' toggles pause in game_input */
|
||||
vt_paused = 1;
|
||||
}
|
||||
focused = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void wait_display(void)
|
||||
{
|
||||
vt_x11_flush();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
long d;
|
||||
|
||||
/* The display server may still be coming up when this process is
|
||||
* created; retry for a while before giving up. */
|
||||
{
|
||||
int tries;
|
||||
for(tries = 0; tries < 40; tries++) {
|
||||
if(vt_x11_init() == 0) break;
|
||||
VT_SLEEP(50);
|
||||
}
|
||||
if(tries == 40) return 1;
|
||||
}
|
||||
onlyascii = 1;
|
||||
use_gfxchar = 0;
|
||||
monochrome = 1; /* the VT1200 raster is 1 bit deep */
|
||||
if(init_game() == -1)
|
||||
return 2;
|
||||
vt_x11_flush();
|
||||
|
||||
for(;;) {
|
||||
dbg_loops = dbg_loops + 1;
|
||||
VT_XSYNC(vt_dpy, 0);
|
||||
while(vt_poll_event()) {
|
||||
vt_handle_event();
|
||||
}
|
||||
if(quit) {
|
||||
cleanup_game();
|
||||
break;
|
||||
}
|
||||
d = update(now_ms());
|
||||
sleep_ms((int)d);
|
||||
vt_x11_flush();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* scoredb.c -- RAM-only high scores (the VT1200 has no filesystem).
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "scoredb.h"
|
||||
|
||||
#define NENT 10
|
||||
|
||||
char *username = "VT1200";
|
||||
|
||||
static struct score_entry list[NENT];
|
||||
static char names[NENT][16];
|
||||
static int inited;
|
||||
|
||||
static void init_list(void)
|
||||
{
|
||||
int i;
|
||||
if(inited) return;
|
||||
inited = 1;
|
||||
for(i = 0; i < NENT; i++) {
|
||||
strcpy(names[i], "VT1200");
|
||||
list[i].user = names[i];
|
||||
list[i].score = 0;
|
||||
list[i].lines = 0;
|
||||
list[i].level = 0;
|
||||
list[i].next = (i + 1 < NENT) ? &list[i + 1] : 0;
|
||||
}
|
||||
}
|
||||
|
||||
struct score_entry *read_scores(FILE *fp, int max_scores)
|
||||
{
|
||||
(void)fp;
|
||||
(void)max_scores;
|
||||
init_list();
|
||||
return &list[0];
|
||||
}
|
||||
|
||||
static void copy_entry(struct score_entry *dst, struct score_entry *src)
|
||||
{
|
||||
long sc = src->score, ln = src->lines, lv = src->level;
|
||||
char *u = (src->user && *src->user) ? src->user : username;
|
||||
strncpy(dst->user, u, 15);
|
||||
dst->user[15] = 0;
|
||||
dst->score = sc;
|
||||
dst->lines = ln;
|
||||
dst->level = lv;
|
||||
}
|
||||
|
||||
int save_score(struct score_entry *sc)
|
||||
{
|
||||
int pos, i;
|
||||
if(!sc) return 0;
|
||||
init_list();
|
||||
for(pos = 0; pos < NENT; pos++) {
|
||||
if(sc->score > list[pos].score) break;
|
||||
}
|
||||
if(pos >= NENT) return 0;
|
||||
for(i = NENT - 1; i > pos; i--) {
|
||||
long s = list[i - 1].score, l = list[i - 1].lines, v = list[i - 1].level;
|
||||
char tmp[16];
|
||||
strcpy(tmp, list[i - 1].user);
|
||||
strcpy(list[i].user, tmp);
|
||||
list[i].score = s;
|
||||
list[i].lines = l;
|
||||
list[i].level = v;
|
||||
}
|
||||
copy_entry(&list[pos], sc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int print_scores(int num)
|
||||
{
|
||||
(void)num;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* stdio.h -- the tiny subset termtris needs on the VT1200.
|
||||
* There is no stdio in the TI r5.01 runtime; compat.c provides sprintf.
|
||||
*/
|
||||
#ifndef VT_STDIO_H_
|
||||
#define VT_STDIO_H_
|
||||
|
||||
typedef int FILE;
|
||||
|
||||
extern FILE *stdout;
|
||||
|
||||
int sprintf(char *buf, char *fmt, ...);
|
||||
int fflush(FILE *fp);
|
||||
int putchar(int c);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* x11.c -- a small character-cell terminal that draws through the VT1200 ROM
|
||||
* Xlib. The game's term_* callbacks feed an 80x24 grid; vt_x11_flush() repaints
|
||||
* each dirty row with one XFillRectangle (background) and one XDrawString (the
|
||||
* row's 80 characters), which keeps the request stream small enough for the
|
||||
* in-machine X server to drain.
|
||||
*
|
||||
* Geometry is the default GC's font, measured on the real server: 6x13 cells,
|
||||
* baseline +10. Do not change the cell metrics without re-measuring.
|
||||
*/
|
||||
#include "xlib.h"
|
||||
#include "x11.h"
|
||||
#include "term.h"
|
||||
#include "game.h"
|
||||
|
||||
#define COLS 80
|
||||
#define ROWS 24
|
||||
#define CELL_W 6
|
||||
#define CELL_H 13
|
||||
#define BASE_OFF 10
|
||||
|
||||
struct vt_cell {
|
||||
unsigned short ch;
|
||||
unsigned char inv, dirty;
|
||||
};
|
||||
|
||||
static struct vt_cell cells[ROWS * COLS];
|
||||
static int cur_row, cur_col;
|
||||
static int cur_fg, cur_bg;
|
||||
|
||||
void *vt_dpy;
|
||||
vt_u32 vt_win;
|
||||
vt_u32 vt_gc;
|
||||
volatile vt_u32 vt_x11_progress; /* debug: 0xFFFFFF when a flush finished */
|
||||
|
||||
/* term.h's callback objects (term.c is not compiled for the VT1200). */
|
||||
void (*term_reset)(void);
|
||||
void (*term_clearscr)(void);
|
||||
void (*term_setcursor)(int row, int col);
|
||||
void (*term_cursor)(int show);
|
||||
void (*term_setcolor)(int fg, int bg);
|
||||
void (*term_ibmchar)(unsigned char c, unsigned char attr);
|
||||
char *termenv;
|
||||
int term_type = TERM_ANSI;
|
||||
|
||||
vt_u32 vt_root_window(void *dpy)
|
||||
{
|
||||
vt_u32 screen;
|
||||
screen = *(vt_u32 *)((char *)dpy + 0x90);
|
||||
return *(vt_u32 *)((char *)screen + 8);
|
||||
}
|
||||
|
||||
int vt_x11_init(void)
|
||||
{
|
||||
vt_x11_progress = 11;
|
||||
if(!vt_install_xg())
|
||||
return -1;
|
||||
vt_x11_progress = 12;
|
||||
vt_dpy = VT_XOPEN("0::0");
|
||||
if(!vt_dpy)
|
||||
return -1;
|
||||
vt_x11_progress = 13;
|
||||
vt_win = VT_XCREATE(vt_dpy, vt_root_window(vt_dpy), 80, 80, 480, 312, 2, 1, 0);
|
||||
if(!vt_win)
|
||||
return -1;
|
||||
vt_x11_progress = 14;
|
||||
VT_XSELECT(vt_dpy, vt_win, 0x22000FUL);
|
||||
vt_gc = VT_XGC(vt_dpy, vt_win, 0, 0);
|
||||
if(!vt_gc)
|
||||
return -1;
|
||||
VT_XMAP(vt_dpy, vt_win);
|
||||
VT_XSYNC(vt_dpy, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void x11_clearscr(void)
|
||||
{
|
||||
int i;
|
||||
for(i = 0; i < ROWS * COLS; i++) {
|
||||
cells[i].ch = ' ';
|
||||
cells[i].inv = 0;
|
||||
cells[i].dirty = 1;
|
||||
}
|
||||
cur_row = cur_col = 0;
|
||||
}
|
||||
|
||||
void x11_reset(void)
|
||||
{
|
||||
x11_clearscr();
|
||||
}
|
||||
|
||||
void x11_cursor(int show)
|
||||
{
|
||||
(void)show;
|
||||
}
|
||||
|
||||
void x11_setcolor(int fg, int bg)
|
||||
{
|
||||
cur_fg = fg;
|
||||
cur_bg = bg;
|
||||
}
|
||||
|
||||
void x11_setcursor(int row, int col)
|
||||
{
|
||||
if(row < 0) row = 0;
|
||||
if(row >= ROWS) row = ROWS - 1;
|
||||
if(col < 0) col = 0;
|
||||
if(col >= COLS) col = COLS - 1;
|
||||
cur_row = row;
|
||||
cur_col = col;
|
||||
}
|
||||
|
||||
void x11_ibmchar(unsigned char c, unsigned char attr)
|
||||
{
|
||||
struct vt_cell *p;
|
||||
if(cur_row < 0 || cur_row >= ROWS) return;
|
||||
if(cur_col < 0 || cur_col >= COLS) return;
|
||||
p = &cells[cur_row * COLS + cur_col];
|
||||
p->ch = c;
|
||||
/* The VT1200 raster is one bit deep, so follow the game's monochrome
|
||||
* convention (ansi.c -m): colour is dropped, the bold bit reverses. */
|
||||
p->inv = (attr & 0x80) ? 1 : 0;
|
||||
p->dirty = 1;
|
||||
cur_col++;
|
||||
if(cur_col >= COLS) {
|
||||
cur_col = 0;
|
||||
cur_row++;
|
||||
}
|
||||
}
|
||||
|
||||
void term_putstr(const char *s, unsigned char attr)
|
||||
{
|
||||
while(*s) {
|
||||
x11_ibmchar((unsigned char)*s++, attr);
|
||||
}
|
||||
}
|
||||
|
||||
void vt_x11_flush(void)
|
||||
{
|
||||
int r, c, any = 0;
|
||||
char line[COLS + 1];
|
||||
|
||||
vt_x11_progress = 1;
|
||||
for(r = 0; r < ROWS; r++) {
|
||||
struct vt_cell *row = &cells[r * COLS];
|
||||
int dirty = 0;
|
||||
|
||||
for(c = 0; c < COLS; c++) {
|
||||
if(row[c].dirty) dirty = 1;
|
||||
}
|
||||
if(!dirty) continue;
|
||||
|
||||
vt_x11_progress = 0x100 + (vt_u32)r;
|
||||
any = 1;
|
||||
|
||||
/* repaint the whole row: black background, then the text.
|
||||
* One fill + one string per row keeps the request stream small
|
||||
* enough that the in-machine X server can drain it. */
|
||||
VT_XSETFG(vt_dpy, vt_gc, 0);
|
||||
VT_XFILL(vt_dpy, vt_win, vt_gc, 0, r * CELL_H, COLS * CELL_W, CELL_H);
|
||||
|
||||
for(c = 0; c < COLS; c++) {
|
||||
line[c] = row[c].ch ? (char)row[c].ch : ' ';
|
||||
}
|
||||
line[COLS] = 0;
|
||||
|
||||
VT_XSETFG(vt_dpy, vt_gc, 1);
|
||||
VT_XDRAW(vt_dpy, vt_win, vt_gc, 0, r * CELL_H + BASE_OFF, line, COLS);
|
||||
|
||||
/* inverse (bold) cells: white block with black text */
|
||||
for(c = 0; c < COLS; c++) {
|
||||
int start;
|
||||
if(!row[c].inv) continue;
|
||||
start = c;
|
||||
while(c < COLS && row[c].inv) c++;
|
||||
VT_XSETFG(vt_dpy, vt_gc, 1);
|
||||
VT_XFILL(vt_dpy, vt_win, vt_gc, start * CELL_W,
|
||||
r * CELL_H, (c - start) * CELL_W, CELL_H);
|
||||
VT_XSETFG(vt_dpy, vt_gc, 0);
|
||||
VT_XDRAW(vt_dpy, vt_win, vt_gc, start * CELL_W,
|
||||
r * CELL_H + BASE_OFF, line + start, c - start);
|
||||
}
|
||||
|
||||
for(c = 0; c < COLS; c++) row[c].dirty = 0;
|
||||
}
|
||||
if(any) {
|
||||
VT_XFLUSH(vt_dpy);
|
||||
}
|
||||
vt_x11_progress = 0xFFFFFFUL;
|
||||
}
|
||||
|
||||
void vt_x11_term_init(void)
|
||||
{
|
||||
term_width = COLS;
|
||||
term_height = ROWS;
|
||||
term_reset = x11_reset;
|
||||
term_clearscr = x11_clearscr;
|
||||
term_setcursor = x11_setcursor;
|
||||
term_cursor = x11_cursor;
|
||||
term_setcolor = x11_setcolor;
|
||||
term_ibmchar = x11_ibmchar;
|
||||
}
|
||||
|
||||
void term_init(void)
|
||||
{
|
||||
vt_x11_term_init();
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* x11.h -- the VT1200 cell-grid X11 backend.
|
||||
*/
|
||||
#ifndef VT_X11_H_
|
||||
#define VT_X11_H_
|
||||
|
||||
#include "xlib.h"
|
||||
|
||||
extern void *vt_dpy;
|
||||
extern vt_u32 vt_win;
|
||||
extern vt_u32 vt_gc;
|
||||
|
||||
int vt_x11_init(void);
|
||||
void vt_x11_flush(void);
|
||||
void vt_x11_term_init(void);
|
||||
|
||||
void x11_reset(void);
|
||||
void x11_clearscr(void);
|
||||
void x11_setcursor(int row, int col);
|
||||
void x11_cursor(int show);
|
||||
void x11_setcolor(int fg, int bg);
|
||||
void x11_ibmchar(unsigned char c, unsigned char attr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* xgfix.c -- install a per-process Xlib context before XOpenDisplay.
|
||||
*
|
||||
* `create_process` leaves the per-process user word at *(proc+0x100) pointing
|
||||
* at a zeroed cell. The ROM Xlib's _XEnq does
|
||||
*
|
||||
* XG = *(*(proc+0x100));
|
||||
* free_list = *(XG + 0x198 bytes);
|
||||
*
|
||||
* so a loader child with XG == NULL reads low-RAM garbage as a queue-node
|
||||
* pointer and XNextEvent copies unmapped zeros. Giving it a zeroed block
|
||||
* makes the event queue real. This is a RAM write only; the ROM is untouched.
|
||||
*/
|
||||
typedef unsigned long vt_u32;
|
||||
|
||||
static vt_u32 vt_xg[256]; /* 1 KiB: > the 0x198-byte free-list field */
|
||||
|
||||
int vt_install_xg(void)
|
||||
{
|
||||
vt_u32 proc, pp;
|
||||
|
||||
proc = *(volatile vt_u32 *)0x001B3900UL;
|
||||
if(proc < 0x100UL || proc > 0x01FFFFFFUL)
|
||||
return 0;
|
||||
pp = *(volatile vt_u32 *)(proc + 0x100UL);
|
||||
if(pp < 0x100UL || pp > 0x01FFFFFFUL)
|
||||
return 0;
|
||||
*(volatile vt_u32 *)pp = (vt_u32)vt_xg;
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* xlib.h -- the VT1200 ROM Xlib entry points, called with the TI C ABI.
|
||||
*
|
||||
* Addresses are TMS34010 bit addresses. The caller reserves the A14 slot and
|
||||
* pushes arguments last-to-first; the callee `rets 2` restores A14. The C
|
||||
* compiler emits exactly this sequence for a call through a function pointer.
|
||||
*/
|
||||
#ifndef VT_XLIB_H_
|
||||
#define VT_XLIB_H_
|
||||
|
||||
typedef unsigned long vt_u32;
|
||||
|
||||
typedef void *(*vt_xopen_t)(const char *);
|
||||
typedef vt_u32 (*vt_xcreate_t)(void *, vt_u32, int, int, unsigned int,
|
||||
unsigned int, unsigned int, vt_u32, vt_u32);
|
||||
typedef int (*vt_xselect_t)(void *, vt_u32, long);
|
||||
typedef int (*vt_xmap_t)(void *, vt_u32);
|
||||
typedef int (*vt_xsync_t)(void *, int);
|
||||
typedef int (*vt_xflush_t)(void *);
|
||||
typedef int (*vt_xnext_t)(void *, void *);
|
||||
typedef int (*vt_xlookup_t)(void *, char *, int, vt_u32 *, void *);
|
||||
typedef vt_u32 (*vt_xgc_t)(void *, vt_u32, vt_u32, vt_u32 *);
|
||||
typedef int (*vt_xsetfg_t)(void *, vt_u32, vt_u32);
|
||||
typedef int (*vt_xfill_t)(void *, vt_u32, vt_u32, int, int,
|
||||
unsigned int, unsigned int);
|
||||
typedef int (*vt_xdraw_t)(void *, vt_u32, vt_u32, int, int,
|
||||
const char *, int);
|
||||
typedef int (*vt_sleep_t)(int);
|
||||
typedef int (*vt_xgetfocus_t)(void *, vt_u32 *, int *);
|
||||
|
||||
#define VT_XOPEN ((vt_xopen_t)0x3F9C2570UL)
|
||||
#define VT_XCREATE ((vt_xcreate_t)0x3FD41B90UL)
|
||||
#define VT_XSELECT ((vt_xselect_t)0x3FD97D50UL)
|
||||
#define VT_XMAP ((vt_xmap_t)0x3FD64F60UL)
|
||||
#define VT_XSYNC ((vt_xsync_t)0x3FD9F6B0UL)
|
||||
#define VT_XFLUSH ((vt_xflush_t)0x3F9B1030UL)
|
||||
#define VT_XNEXT ((vt_xnext_t)0x3F9C1CF0UL)
|
||||
#define VT_XLOOKUP ((vt_xlookup_t)0x3F9A9C30UL)
|
||||
#define VT_XGC ((vt_xgc_t)0x3F997000UL)
|
||||
#define VT_XSETFG ((vt_xsetfg_t)0x3FD99A60UL)
|
||||
#define VT_XFILL ((vt_xfill_t)0x3F99E8F0UL)
|
||||
#define VT_XDRAW ((vt_xdraw_t)0x3FDA0000UL)
|
||||
#define VT_XPENDING ((int (*)(void *))0x3FD67620UL)
|
||||
#define VT_SLEEP ((vt_sleep_t)0x3FB33A20UL)
|
||||
#define VT_XGETFOCUS ((vt_xgetfocus_t)0x3FD55210UL)
|
||||
|
||||
/* display->screens[] is at bit 0x480 / byte 0x90; screen->root at bit 0x40 /
|
||||
* byte 8 (see dwt/notes/GUI_APPS.md and dwt/gui/xhello.asm). */
|
||||
vt_u32 vt_root_window(void *dpy);
|
||||
|
||||
int vt_install_xg(void);
|
||||
|
||||
#endif /* VT_XLIB_H_ */
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* fmt.c -- Task 2 acceptance: the exact sprintf formats game.c uses.
|
||||
* Results are NUL-terminated in out[6][16]; tests/fmt.lua prints them.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
|
||||
char out[6][16];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
sprintf(out[0], "%10ld", 12345L);
|
||||
sprintf(out[1], "%2ld", 7L);
|
||||
sprintf(out[2], "%8ld", 42L);
|
||||
sprintf(out[3], "%2d. %s %ld", 1, "ab", 99L);
|
||||
sprintf(out[4], "%-3s", "x");
|
||||
sprintf(out[5], "%%");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
-- fmt.lua -- six formatted strings, read back from the app's output cells.
|
||||
-- fmt.sh checks each FMT:n line byte-for-byte.
|
||||
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
|
||||
local H = dofile(dir .. "/harness.lua")
|
||||
|
||||
local FMT_MARK = tonumber(os.getenv("FMT_MARK") or "0x01A00000")
|
||||
|
||||
local function rstr(a, n)
|
||||
local t = {}
|
||||
for i = 0, n - 1 do
|
||||
local c = H.prog:read_u8(a + i * 8)
|
||||
if c == 0 then break end
|
||||
t[#t + 1] = string.char(c)
|
||||
end
|
||||
return table.concat(t)
|
||||
end
|
||||
|
||||
H.result_dump(function()
|
||||
for i = 0, 5 do
|
||||
print(string.format("FMT:%d [%s]", i, rstr(FMT_MARK + i * 0x80, 16)))
|
||||
end
|
||||
end)
|
||||
|
||||
H.run()
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/bin/sh
|
||||
# fmt.sh -- Task 2 acceptance. Builds tests/fmt.c with compat.c, loads it, and
|
||||
# checks the six formatted strings byte-for-byte.
|
||||
set -eu
|
||||
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
APP=$(cd "$DIR/.." && pwd)
|
||||
ROOT=$(cd "$APP/../.." && pwd)
|
||||
M=${MAME:-/home/arti/code/k-space/mame0289/vt1200}
|
||||
LOG="$APP/build/fmt.log"
|
||||
|
||||
mkdir -p "$APP/build"
|
||||
"$APP/build.sh" "$DIR/fmt.c" "$APP/src/vt1200/compat.c" >"$APP/build/fmt-build.log" 2>&1
|
||||
|
||||
FMT=$(awk '{for(i=2;i<=NF;i++) if($i=="_out") print $(i-1)}' "$APP/build/fmt.map" | head -1)
|
||||
VT1200_SKIP_LEVEL1=1 FMT_MARK="0x$FMT" \
|
||||
LOADER_AT=2500 LOADER_END=2700 \
|
||||
LOADER_BIN="$ROOT/dwt/loader/build/loader.bin" \
|
||||
LOADER_COFF="$APP/build/fmt.coff" \
|
||||
LOADER_OUT="$APP/build" \
|
||||
"$M" vt1200 -rompath "$ROOT/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$DIR/fmt.lua" -autoboot_delay 0 \
|
||||
>"$LOG" 2>&1 || true
|
||||
|
||||
grep 'FMT:' "$LOG" | tail -8
|
||||
for want in 'FMT:0 [ 12345]' 'FMT:1 [ 7]' 'FMT:2 [ 42]' \
|
||||
'FMT:3 [ 1. ab 99]' 'FMT:4 [x ]' 'FMT:5 [%]'; do
|
||||
grep -Fq "$want" "$LOG" || {
|
||||
echo "fmt.sh: missing: $want (see $LOG)" >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
echo "fmt: PASS"
|
||||
@@ -0,0 +1,354 @@
|
||||
-- harness.lua -- the shared debugger-assisted COFF loader harness.
|
||||
--
|
||||
-- Boots the firmware with VT1200_SKIP_LEVEL1=1 (the documented divergence) to
|
||||
-- the OS, then at frame LOADER_AT pokes the loader payload at bit 0x01880000,
|
||||
-- the app's GSPLNK COFF at LOADER_BUF (default bit 0x01900000) and the loader
|
||||
-- descriptor at 0x01882C00, and sets PC = 0x01880000. No network, no rdebug:
|
||||
-- this is the debugger-assisted milestone. The loader copies the COFF sections
|
||||
-- to their linked bit addresses and calls
|
||||
-- create_process(entry, "LOADER", 0x6000, 1, 0); this harness only pokes the
|
||||
-- input and reads the result, it never writes the app's code.
|
||||
--
|
||||
-- A test is configuration plus hooks:
|
||||
--
|
||||
-- local H = dofile(<dir> .. "/harness.lua")
|
||||
-- H.config{ tablet = "SMOKE" }
|
||||
-- H.sequence(3100, 20, { { ":lk401:K26", "A" } })
|
||||
-- H.result_dump(function() print(...) end)
|
||||
-- H.run()
|
||||
--
|
||||
-- Env (the tests/*.sh contract): LOADER_BIN, LOADER_COFF, LOADER_BUF,
|
||||
-- LOADER_AT, LOADER_END, LOADER_OUT, LOADER_SNAP, LOADER_VERBOSE, and the
|
||||
-- DIAG_LOOPS/EVENTS/LAST/FOCUS/REV/QUIT/TICK bit addresses (a missing one
|
||||
-- prints -1).
|
||||
--
|
||||
-- The exit is the fixed LOADER_END frame, never an early completion: the tests
|
||||
-- read the snapshot at that frame (loader_frame<LOADER_END>.png).
|
||||
|
||||
local H = {}
|
||||
|
||||
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
|
||||
|
||||
local machine = manager.machine
|
||||
local cpu = machine.devices[':maincpu']
|
||||
local dbg = machine.debugger
|
||||
local prog = cpu.spaces['program']
|
||||
|
||||
H.machine, H.cpu, H.dbg, H.prog, H.hex = machine, cpu, dbg, prog, hex
|
||||
|
||||
local LOADER_BASE = 0x01880000
|
||||
local DESC = 0x01882C00
|
||||
local RESULT = 0x01882D00
|
||||
|
||||
local cfg = {
|
||||
bin = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin",
|
||||
coff = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff",
|
||||
buf = tonumber(os.getenv("LOADER_BUF") or "0x01900000"),
|
||||
at = tonumber(os.getenv("LOADER_AT") or "2500"),
|
||||
endf = tonumber(os.getenv("LOADER_END") or "2700"),
|
||||
out = os.getenv("LOADER_OUT") or "dwt/loader/evidence",
|
||||
snap = os.getenv("LOADER_SNAP") == "1",
|
||||
verbose = os.getenv("LOADER_VERBOSE") == "1",
|
||||
}
|
||||
|
||||
local diag = {
|
||||
loops = tonumber(os.getenv("DIAG_LOOPS") or "0") or 0,
|
||||
events = tonumber(os.getenv("DIAG_EVENTS") or "0") or 0,
|
||||
last = tonumber(os.getenv("DIAG_LAST") or "0") or 0,
|
||||
focus = tonumber(os.getenv("DIAG_FOCUS") or "0") or 0,
|
||||
rev = tonumber(os.getenv("DIAG_REV") or "0") or 0,
|
||||
quit = tonumber(os.getenv("DIAG_QUIT") or "0") or 0,
|
||||
tick = tonumber(os.getenv("DIAG_TICK") or "0") or 0,
|
||||
}
|
||||
|
||||
local function slurp(p)
|
||||
local f, err = io.open(p, "rb")
|
||||
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
|
||||
local s = f:read("*a")
|
||||
f:close()
|
||||
return s
|
||||
end
|
||||
|
||||
local function u16(s, o) return s:byte(o + 1) + s:byte(o + 2) * 256 end
|
||||
local function u32(s, o)
|
||||
return s:byte(o + 1) + s:byte(o + 2) * 256
|
||||
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
|
||||
end
|
||||
|
||||
local function parse_coff(d)
|
||||
local c = { data = d, sections = {} }
|
||||
c.magic = u16(d, 0)
|
||||
c.nscns = u16(d, 2)
|
||||
c.opthdr = u16(d, 16)
|
||||
if c.opthdr > 0 then
|
||||
c.optmagic = u16(d, 20)
|
||||
c.entry = u32(d, 20 + 16)
|
||||
c.textstart = u32(d, 20 + 20)
|
||||
c.datastart = u32(d, 20 + 24)
|
||||
end
|
||||
local base = 20 + c.opthdr
|
||||
for i = 0, c.nscns - 1 do
|
||||
local o = base + i * 40
|
||||
c.sections[#c.sections + 1] = {
|
||||
name = d:sub(o + 1, o + 8):gsub("%z", ""),
|
||||
paddr = u32(d, o + 8),
|
||||
size = u32(d, o + 16), -- bits
|
||||
scnptr = u32(d, o + 20),
|
||||
flags = u32(d, o + 36),
|
||||
}
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
local function poke_bytes(bitaddr, data)
|
||||
local n = math.floor((#data + 1) / 2)
|
||||
for i = 0, n - 1 do
|
||||
local lo = data:byte(i * 2 + 1) or 0
|
||||
local hi = data:byte(i * 2 + 2) or 0
|
||||
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
local function verify_bytes(bitaddr, data)
|
||||
local n = math.floor((#data + 1) / 2)
|
||||
local bad = 0
|
||||
for i = 0, n - 1 do
|
||||
local lo = data:byte(i * 2 + 1) or 0
|
||||
local hi = data:byte(i * 2 + 2) or 0
|
||||
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
|
||||
bad = bad + 1
|
||||
end
|
||||
end
|
||||
return n, bad
|
||||
end
|
||||
|
||||
local function w32(a, v) prog:write_u32(a, v) end
|
||||
local function r32(a)
|
||||
local ok, v = pcall(function() return prog:read_u32(a) end)
|
||||
if ok then return v end
|
||||
return 0xDEADBEEF
|
||||
end
|
||||
H.r32 = r32
|
||||
|
||||
local STATUS = {
|
||||
"OK", "bad descriptor", "truncated COFF / section headers",
|
||||
"bad COFF magic", "section size not whole words", "target outside RAM",
|
||||
"target overlaps loader page or COFF buffer",
|
||||
"relocation records present (unsupported)",
|
||||
"target not in a free-list block", "no entry point",
|
||||
}
|
||||
local function status_name(v) return STATUS[v + 1] or ("error " .. tostring(v)) end
|
||||
|
||||
local loader, coff, app
|
||||
|
||||
local function prepare()
|
||||
loader = slurp(cfg.bin)
|
||||
coff = slurp(cfg.coff)
|
||||
app = parse_coff(coff)
|
||||
|
||||
print(string.format("LOADER: payload %s (%d B) -> bit %s", cfg.bin, #loader, hex(LOADER_BASE)))
|
||||
print(string.format("LOADER: COFF %s (%d B) -> bit %s", cfg.coff, #coff, hex(cfg.buf)))
|
||||
print(string.format("LOADER: file magic=%04X nscns=%d opthdr=%d optmagic=%s entry=%s textstart=%s",
|
||||
app.magic, app.nscns, app.opthdr,
|
||||
app.optmagic and string.format("%04X", app.optmagic) or "none",
|
||||
hex(app.entry or 0), hex(app.textstart or 0)))
|
||||
for _, s in ipairs(app.sections) do
|
||||
print(string.format("LOADER: sec %-8s paddr=%s size=%d bits (%d B) scnptr=%#x flags=%#x",
|
||||
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.scnptr, s.flags))
|
||||
end
|
||||
end
|
||||
|
||||
local function dump_result()
|
||||
local st = r32(RESULT + 0x000)
|
||||
print(string.format(
|
||||
"LOADER: result status=%d (%s) entry=%s text=%s/%d bits data=%s/%d bits bss=%s/%d bits relocs=%d pcb=%s nscns=%d len=%d",
|
||||
st, status_name(st), hex(r32(RESULT + 0x020)),
|
||||
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060),
|
||||
hex(r32(RESULT + 0x080)), r32(RESULT + 0x0A0),
|
||||
hex(r32(RESULT + 0x0C0)), r32(RESULT + 0x0E0),
|
||||
r32(RESULT + 0x100), hex(r32(RESULT + 0x120)),
|
||||
r32(RESULT + 0x140), r32(RESULT + 0x160)))
|
||||
end
|
||||
|
||||
local function cell(addr) return addr ~= 0 and r32(addr) or -1 end
|
||||
|
||||
local function dump_diag()
|
||||
local focus = diag.focus ~= 0 and string.format("%08X", r32(diag.focus)) or "-1"
|
||||
print(string.format("DIAG: loops=%d events=%d last=%d focus=%s rev=%d quit=%d",
|
||||
cell(diag.loops), cell(diag.events), cell(diag.last), focus,
|
||||
cell(diag.rev), cell(diag.quit)))
|
||||
print(string.format("DIAG: tick=%d quit=%d", cell(diag.tick), cell(diag.quit)))
|
||||
end
|
||||
|
||||
local events = {}
|
||||
local frame_hooks = {}
|
||||
local result_hooks = {}
|
||||
local done_hooks = {}
|
||||
local tableted = false
|
||||
|
||||
local function field(tag, name)
|
||||
local port = machine.ioport.ports[tag]
|
||||
if not port then error("no input port " .. tag) end
|
||||
local f = port.fields[name]
|
||||
if not f then error("no field " .. name .. " on " .. tag) end
|
||||
return f
|
||||
end
|
||||
|
||||
-- Schedule one input event at `frame`, then print `message` (if any).
|
||||
function H.key(frame, tag, name, value, message)
|
||||
events[#events + 1] = { frame = frame, field = field(tag, name), value = value, message = message }
|
||||
end
|
||||
|
||||
-- Schedule a log line at a frame.
|
||||
function H.message(frame, text)
|
||||
events[#events + 1] = { frame = frame, message = text }
|
||||
end
|
||||
|
||||
-- Schedule a press/release pair for each {tag, field} entry, `step` frames
|
||||
-- apart, half a step between the press and the release.
|
||||
function H.sequence(first, step, keys)
|
||||
local half = math.floor(step / 2)
|
||||
for i, k in ipairs(keys) do
|
||||
local f = first + (i - 1) * step
|
||||
H.key(f, k[1], k[2], 1)
|
||||
H.key(f + half, k[1], k[2], 0)
|
||||
end
|
||||
end
|
||||
|
||||
function H.config(opts)
|
||||
for k, v in pairs(opts or {}) do cfg[k] = v end
|
||||
if cfg.tablet and not tableted then
|
||||
tableted = true
|
||||
local label = type(cfg.tablet) == "string" and cfg.tablet or "LOADER"
|
||||
H.key(2900, ":tablet:TABLET_X", "Tablet X", 700)
|
||||
H.key(2900, ":tablet:TABLET_Y", "Tablet Y", 500, label .. ": tablet move")
|
||||
H.key(3000, ":tablet:TABLET_BTN", "P1 Button 1", 1, label .. ": click down")
|
||||
H.key(3020, ":tablet:TABLET_BTN", "P1 Button 1", 0, label .. ": click up")
|
||||
end
|
||||
end
|
||||
|
||||
function H.on_frame(fn) frame_hooks[#frame_hooks + 1] = fn end
|
||||
function H.result_dump(fn) result_hooks[#result_hooks + 1] = fn end
|
||||
function H.on_done(fn) done_hooks[#done_hooks + 1] = fn end
|
||||
|
||||
local frames = 0
|
||||
local injected = false
|
||||
local done = false
|
||||
|
||||
local function inject()
|
||||
-- 1. loader itself
|
||||
poke_bytes(LOADER_BASE, loader)
|
||||
local n, bad = verify_bytes(LOADER_BASE, loader)
|
||||
print(string.format("LOADER: loader poked %d words, readback %d bad at %s",
|
||||
n, bad, hex(LOADER_BASE)))
|
||||
|
||||
-- 2. COFF image
|
||||
poke_bytes(cfg.buf, coff)
|
||||
n, bad = verify_bytes(cfg.buf, coff)
|
||||
print(string.format("LOADER: COFF poked %d words, readback %d bad at %s",
|
||||
n, bad, hex(cfg.buf)))
|
||||
|
||||
-- 3. pre-fill every .bss section with A5A5, so a loaded zero is meaningful
|
||||
for _, s in ipairs(app.sections) do
|
||||
if s.flags & 0x80 ~= 0 then
|
||||
for i = 0, math.floor(s.size / 16) - 1 do
|
||||
prog:write_u16(s.paddr + i * 16, 0xA5A5)
|
||||
end
|
||||
print(string.format("LOADER: pre-filled .bss %s..%s with A5A5",
|
||||
hex(s.paddr), hex(s.paddr + s.size)))
|
||||
end
|
||||
end
|
||||
|
||||
-- 4. descriptor: magic "LD" "R1", buf, len, mode=0 (debug resume)
|
||||
w32(DESC + 0x00, 0)
|
||||
prog:write_u16(DESC + 0x00, 0x4C44)
|
||||
prog:write_u16(DESC + 0x10, 0x5231)
|
||||
w32(DESC + 0x20, cfg.buf)
|
||||
w32(DESC + 0x40, #coff)
|
||||
w32(DESC + 0x60, 0)
|
||||
print(string.format("LOADER: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
|
||||
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
|
||||
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
|
||||
|
||||
-- 5. enter the loader. A8=0 selects the fixed descriptor; mode 0 restores
|
||||
-- the interrupted state and resumes at LD_ORIG_PC, so the caller yields
|
||||
-- and the scheduler can run the child.
|
||||
local orig_pc = cpu.state['PC'].value
|
||||
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
|
||||
print(string.format("LOADER: will resume at %s after create_process", hex(orig_pc)))
|
||||
cpu.state['A8'].value = 0
|
||||
cpu.state['PC'].value = LOADER_BASE
|
||||
injected = true
|
||||
print(string.format("LOADER: frame %d: entered loader at %s (caller SP=%s)",
|
||||
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
|
||||
end
|
||||
|
||||
local function inspect()
|
||||
dump_result()
|
||||
|
||||
-- Verify the placement from RAM: .text/.data must equal the file bytes.
|
||||
for _, s in ipairs(app.sections) do
|
||||
if s.scnptr ~= 0 and s.size > 0 then
|
||||
local nb = math.floor(s.size / 8)
|
||||
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
|
||||
local _, bad = verify_bytes(s.paddr, bytes)
|
||||
print(string.format("LOADER: placed %s at %s: %d bytes, %d differing",
|
||||
s.name, hex(s.paddr), nb, bad))
|
||||
end
|
||||
end
|
||||
|
||||
for _, fn in ipairs(result_hooks) do fn() end
|
||||
dump_diag()
|
||||
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
|
||||
end
|
||||
|
||||
local function snapshot()
|
||||
if not cfg.snap then return end
|
||||
local screen = nil
|
||||
for _, s in pairs(machine.screens) do screen = s break end
|
||||
if not screen then return end
|
||||
local out = cfg.out .. "/loader_frame" .. frames .. ".png"
|
||||
local ok, err = pcall(function() return screen:snapshot(out) end)
|
||||
print(string.format("LOADER: snapshot %s ok=%s %s",
|
||||
out, tostring(ok), tostring(err or "")))
|
||||
end
|
||||
|
||||
local function fire_events()
|
||||
for _, e in ipairs(events) do
|
||||
if e.frame == frames then
|
||||
if e.field then e.field:set_value(e.value) end
|
||||
if e.message then print(e.message) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function H.run()
|
||||
if not dbg then
|
||||
print("LOADER: debugger not enabled; pass -debug")
|
||||
machine:exit()
|
||||
return
|
||||
end
|
||||
dbg.visible_cpu = cpu
|
||||
dbg.execution_state = 'run'
|
||||
prepare()
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
fire_events()
|
||||
for _, fn in ipairs(frame_hooks) do fn(frames) end
|
||||
if frames == cfg.at and not injected then inject() end
|
||||
if injected and not done and cfg.verbose and frames % 25 == 0 then dump_result() end
|
||||
if frames >= cfg.endf then
|
||||
if injected then
|
||||
done = true
|
||||
inspect()
|
||||
for _, fn in ipairs(done_hooks) do fn() end
|
||||
snapshot()
|
||||
end
|
||||
machine:exit()
|
||||
end
|
||||
end, "vt1200-loader")
|
||||
end
|
||||
|
||||
return H
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* input.c -- Task 4 acceptance: link main.c against stubs for the game, inject
|
||||
* keys, and record the bytes main.c sends to game_input().
|
||||
*/
|
||||
#include "game.h"
|
||||
#include "x11.h"
|
||||
#include "xlib.h"
|
||||
|
||||
int term_width, term_height;
|
||||
/* game.c globals main.c sets or reads; the real game supplies these */
|
||||
int onlyascii, use_gfxchar, monochrome;
|
||||
int quit;
|
||||
long tick_interval;
|
||||
volatile vt_u32 mark[128];
|
||||
|
||||
void cleanup_game(void) {}
|
||||
void wait_display(void);
|
||||
|
||||
int init_game(void)
|
||||
{
|
||||
mark[0] = 0x494E5054UL; /* INPT */
|
||||
vt_x11_term_init();
|
||||
x11_clearscr();
|
||||
return 0;
|
||||
}
|
||||
|
||||
long update(long msec)
|
||||
{
|
||||
(void)msec;
|
||||
mark[1] = mark[1] + 1;
|
||||
return 100;
|
||||
}
|
||||
|
||||
void game_input(int c)
|
||||
{
|
||||
int n = (int)mark[2];
|
||||
if(n < 100) mark[3 + n] = (vt_u32)(unsigned char)c;
|
||||
mark[2] = (vt_u32)(n + 1);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
-- input.lua -- main.c's key map against injected keys. input.sh checks the
|
||||
-- INPUT: line for the mapped byte sequence.
|
||||
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
|
||||
local H = dofile(dir .. "/harness.lua")
|
||||
|
||||
local INPUT_MARK = tonumber(os.getenv("INPUT_MARK") or "0x01A00000")
|
||||
|
||||
H.config{ tablet = "INPUT" }
|
||||
H.sequence(3100, 20, {
|
||||
{ ":lk401:K26", "A" },
|
||||
{ ":lk401:K77", "Up" },
|
||||
{ ":lk401:K76", "Down" },
|
||||
{ ":lk401:K74", "Left" },
|
||||
{ ":lk401:K75", "Right" },
|
||||
{ ":lk401:K10", "0 )" },
|
||||
{ ":lk401:K68", "Return" },
|
||||
{ ":lk401:K67", "Delete" },
|
||||
{ ":lk401:K13", "Q" },
|
||||
{ ":lk401:K22", "P" },
|
||||
})
|
||||
|
||||
H.result_dump(function()
|
||||
local n = H.r32(INPUT_MARK + 0x40)
|
||||
local t = {}
|
||||
for i = 0, n - 1 do t[#t + 1] = string.format("%02X", H.r32(INPUT_MARK + (3 + i) * 0x20)) end
|
||||
print(string.format("INPUT: magic=%08X updates=%d n=%d bytes=%s",
|
||||
H.r32(INPUT_MARK), H.r32(INPUT_MARK + 0x20), n, table.concat(t, " ")))
|
||||
end)
|
||||
|
||||
H.run()
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/bin/sh
|
||||
# input.sh -- Task 4 acceptance: main.c's key map against injected keys.
|
||||
set -eu
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
APP=$(cd "$DIR/.." && pwd)
|
||||
ROOT=$(cd "$APP/../.." && pwd)
|
||||
M=${MAME:-/home/arti/code/k-space/mame0289/vt1200}
|
||||
LOG="$APP/build/input.log"
|
||||
mkdir -p "$APP/build"
|
||||
"$APP/build.sh" "$DIR/input.c" "$APP/src/vt1200/main.c" "$APP/src/vt1200/x11.c" "$APP/src/vt1200/xgfix.c" >"$APP/build/input-build.log" 2>&1
|
||||
MARK=$(awk '{for(i=2;i<=NF;i++) if($i=="_mark") print $(i-1)}' "$APP/build/input.map" | head -1)
|
||||
VT1200_SKIP_LEVEL1=1 INPUT_MARK="0x$MARK" \
|
||||
LOADER_AT=2500 LOADER_END=3400 \
|
||||
LOADER_BIN="$ROOT/dwt/loader/build/loader.bin" \
|
||||
LOADER_COFF="$APP/build/input.coff" \
|
||||
LOADER_OUT="$APP/build" \
|
||||
"$M" vt1200 -rompath "$ROOT/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$DIR/input.lua" -autoboot_delay 0 \
|
||||
>"$LOG" 2>&1 || true
|
||||
grep 'INPUT:' "$LOG" | tail -3
|
||||
grep -q 'INPUT: .*bytes=.*61 9B 41 9B 42 9B 44 9B 43 30 0A 7F 71 70' "$LOG" || {
|
||||
echo "input.sh: mapped key sequence missing (see $LOG)" >&2
|
||||
exit 1
|
||||
}
|
||||
echo "input: PASS"
|
||||
@@ -0,0 +1,8 @@
|
||||
-- play.lua -- load termtris, click it active, and snapshot the board.
|
||||
-- play.sh checks LOADER: result status=0, the DIAG tick, and the snapshot.
|
||||
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
|
||||
local H = dofile(dir .. "/harness.lua")
|
||||
|
||||
H.config{ tablet = "PLAY" }
|
||||
|
||||
H.run()
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
# play.sh -- load termtris, click it active, and snapshot the board.
|
||||
set -eu
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
APP=$(cd "$DIR/.." && pwd)
|
||||
ROOT=$(cd "$APP/../.." && pwd)
|
||||
M=${MAME:-/home/arti/code/k-space/mame0289/vt1200}
|
||||
EV="$APP/evidence"
|
||||
LOG="$APP/build/play.log"
|
||||
mkdir -p "$EV" "$APP/build"
|
||||
OUTNAME=termtris "$APP/build.sh" "$APP/src/vt1200/main.c" "$APP/src/game.c" "$APP/src/vt1200/scoredb.c" \
|
||||
"$APP/src/vt1200/x11.c" "$APP/src/vt1200/compat.c" "$APP/src/vt1200/xgfix.c" \
|
||||
>"$APP/build/play-build.log" 2>&1
|
||||
rm -f "$EV/loader_frame3300.png"
|
||||
TICK=$(awk '{for(i=2;i<=NF;i++) if($i=="_tick_interval") print $(i-1)}' "$APP/build/termtris.map" | head -1)
|
||||
QUIT=$(awk '{for(i=2;i<=NF;i++) if($i=="_quit") print $(i-1)}' "$APP/build/termtris.map" | head -1)
|
||||
VT1200_SKIP_LEVEL1=1 LOADER_SNAP=1 DIAG_TICK="0x$TICK" DIAG_QUIT="0x$QUIT" \
|
||||
LOADER_AT=2500 LOADER_END=3300 \
|
||||
LOADER_BIN="$ROOT/dwt/loader/build/loader.bin" \
|
||||
LOADER_COFF="$APP/build/termtris.coff" \
|
||||
LOADER_OUT="$EV" \
|
||||
"$M" vt1200 -rompath "$ROOT/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$DIR/play.lua" -autoboot_delay 0 \
|
||||
>"$LOG" 2>&1 || true
|
||||
grep -E 'PLAY:|DIAG:|LOADER: result|LOADER: snapshot' "$LOG" | tail -6
|
||||
grep -q 'LOADER: result status=0' "$LOG" || { echo "play.sh: the game did not start (see $LOG)" >&2; exit 1; }
|
||||
DIAG=$(grep -a 'DIAG: tick=' "$LOG" | head -1)
|
||||
[ -n "$DIAG" ] || { echo "play.sh: no DIAG line (see $LOG)" >&2; exit 1; }
|
||||
TICKVAL=$(printf '%s' "$DIAG" | sed -n 's/.*tick=\([-0-9]*\).*/\1/p')
|
||||
QUITVAL=$(printf '%s' "$DIAG" | sed -n 's/.*quit=\([-0-9]*\).*/\1/p')
|
||||
[ "$TICKVAL" -gt 0 ] || { echo "play.sh: init_game never ran (tick=$TICKVAL)" >&2; exit 1; }
|
||||
[ "$QUITVAL" = 0 ] || { echo "play.sh: game quit by itself" >&2; exit 1; }
|
||||
[ -s "$EV/loader_frame3300.png" ] || { echo "play.sh: no snapshot (see $LOG)" >&2; exit 1; }
|
||||
cp "$EV/loader_frame3300.png" "$EV/termtris_frame3300.png"
|
||||
echo "play: $EV/termtris_frame3300.png"
|
||||
@@ -0,0 +1,34 @@
|
||||
-- play_keys.lua -- drive the real game through its move, panels and quit
|
||||
-- paths. play_keys.sh runs one PLAY_MODE per invocation and parses the DIAG
|
||||
-- loops/events/last/focus/rev/quit line.
|
||||
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
|
||||
local H = dofile(dir .. "/harness.lua")
|
||||
|
||||
local MODE = os.getenv("PLAY_MODE") or "move"
|
||||
print("PLAYKEYS: mode=" .. MODE)
|
||||
|
||||
H.key(2900, ":tablet:TABLET_X", "Tablet X", 700)
|
||||
H.key(2900, ":tablet:TABLET_Y", "Tablet Y", 500, "PLAYKEYS: move")
|
||||
H.key(3000, ":tablet:TABLET_BTN", "P1 Button 1", 1, "PLAYKEYS: click down")
|
||||
H.key(3020, ":tablet:TABLET_BTN", "P1 Button 1", 0, "PLAYKEYS: click up")
|
||||
|
||||
if MODE == "move" then
|
||||
H.sequence(3100, 20, {
|
||||
{ ":lk401:K26", "A" },
|
||||
{ ":lk401:K28", "D" },
|
||||
{ ":lk401:K27", "S" },
|
||||
{ ":lk401:K14", "W" },
|
||||
{ ":lk401:K10", "0 )" },
|
||||
})
|
||||
elseif MODE == "panels" then
|
||||
H.sequence(3100, 20, {
|
||||
{ ":lk401:K31", "H" },
|
||||
{ ":lk401:K16", "R" },
|
||||
})
|
||||
elseif MODE == "quit" then
|
||||
H.message(3095, "PLAYKEYS: quit arm")
|
||||
H.key(3100, ":lk401:K13", "Q", 1, "PLAYKEYS: Q down")
|
||||
H.key(3110, ":lk401:K13", "Q", 0, "PLAYKEYS: Q up")
|
||||
end
|
||||
|
||||
H.run()
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
# play_keys.sh -- run the real game through move, panels and quit paths.
|
||||
set -eu
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
APP=$(cd "$DIR/.." && pwd)
|
||||
ROOT=$(cd "$APP/../.." && pwd)
|
||||
M=${MAME:-/home/arti/code/k-space/mame0289/vt1200}
|
||||
EV="$APP/evidence"
|
||||
mkdir -p "$EV" "$APP/build"
|
||||
OUTNAME=termtris "$APP/build.sh" "$APP/src/vt1200/main.c" "$APP/src/game.c" "$APP/src/vt1200/scoredb.c" \
|
||||
"$APP/src/vt1200/x11.c" "$APP/src/vt1200/compat.c" "$APP/src/vt1200/xgfix.c" \
|
||||
>"$APP/build/play_keys-build.log" 2>&1
|
||||
for mode in ${MODES:-move panels quit}; do
|
||||
LOG="$APP/build/play_$mode.log"
|
||||
rm -f "$EV/loader_frame3200.png"
|
||||
DL=$(awk '{for(i=2;i<=NF;i++) if($i=="_dbg_loops") print $(i-1)}' "$APP/build/termtris.map" | head -1)
|
||||
DE=$(awk '{for(i=2;i<=NF;i++) if($i=="_dbg_events") print $(i-1)}' "$APP/build/termtris.map" | head -1)
|
||||
DT=$(awk '{for(i=2;i<=NF;i++) if($i=="_dbg_last") print $(i-1)}' "$APP/build/termtris.map" | head -1)
|
||||
DF=$(awk '{for(i=2;i<=NF;i++) if($i=="_dbg_focus") print $(i-1)}' "$APP/build/termtris.map" | head -1)
|
||||
DR=$(awk '{for(i=2;i<=NF;i++) if($i=="_dbg_rev") print $(i-1)}' "$APP/build/termtris.map" | head -1)
|
||||
DQ=$(awk '{for(i=2;i<=NF;i++) if($i=="_quit") print $(i-1)}' "$APP/build/termtris.map" | head -1)
|
||||
DTICK=$(awk '{for(i=2;i<=NF;i++) if($i=="_tick_interval") print $(i-1)}' "$APP/build/termtris.map" | head -1)
|
||||
VT1200_SKIP_LEVEL1=1 LOADER_SNAP=1 PLAY_MODE=$mode DIAG_LOOPS="0x$DL" DIAG_EVENTS="0x$DE" DIAG_LAST="0x$DT" DIAG_FOCUS="0x$DF" DIAG_REV="0x$DR" DIAG_QUIT="0x$DQ" \
|
||||
DIAG_TICK="0x$DTICK" \
|
||||
LOADER_AT=2500 LOADER_END=3200 \
|
||||
LOADER_BIN="$ROOT/dwt/loader/build/loader.bin" \
|
||||
LOADER_COFF="$APP/build/termtris.coff" \
|
||||
LOADER_OUT="$EV" \
|
||||
"$M" vt1200 -rompath "$ROOT/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$DIR/play_keys.lua" -autoboot_delay 0 \
|
||||
>"$LOG" 2>&1 || true
|
||||
grep -E 'PLAYKEYS:|LOADER: result|LOADER: snapshot' "$LOG" | tail -5
|
||||
DIAG=$(grep -a 'DIAG: loops' "$LOG" | sed -n 's/.*loops=\([0-9]*\) events=\([0-9]*\).*quit=\([0-9]*\)/\1 \2 \3/p' | head -1)
|
||||
[ -n "$DIAG" ] || { echo "play_keys.sh: no DIAG line for $mode (see $LOG)" >&2; exit 1; }
|
||||
set -- $DIAG
|
||||
LOOPS=$1; EVENTS=$2; QUIT=$3
|
||||
echo "play_keys: $mode loops=$LOOPS events=$EVENTS quit=$QUIT"
|
||||
[ "$LOOPS" -ge 100 ] || { echo "play_keys.sh: $mode main loop barely ran ($LOOPS)" >&2; exit 1; }
|
||||
[ "$EVENTS" -ge 6 ] || { echo "play_keys.sh: $mode got $EVENTS events, expected the click and keys" >&2; exit 1; }
|
||||
case $mode in
|
||||
move|panels) [ "$QUIT" = 0 ] || { echo "play_keys.sh: $mode quit unexpectedly" >&2; exit 1; } ;;
|
||||
quit) [ "$QUIT" = 1 ] || { echo "play_keys.sh: q did not reach the game (quit=$QUIT)" >&2; exit 1; } ;;
|
||||
esac
|
||||
[ -s "$EV/loader_frame3200.png" ] || { echo "play_keys.sh: no $mode snapshot" >&2; exit 1; }
|
||||
cp "$EV/loader_frame3200.png" "$EV/termtris_${mode}_3200.png"
|
||||
done
|
||||
echo "play_keys: $EV/termtris_move_3200.png $EV/termtris_panels_3200.png $EV/termtris_quit_3200.png"
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* render.c -- Task 3 acceptance: draw a border, a playfield outline and
|
||||
* TERMTRIS through the cell-grid backend, then keep the window alive so the
|
||||
* loader can snapshot it.
|
||||
*/
|
||||
#include "xlib.h"
|
||||
#include "x11.h"
|
||||
|
||||
extern int vt_install_xg(void);
|
||||
|
||||
volatile vt_u32 mark[16];
|
||||
int term_width, term_height;
|
||||
static const char *word = "TERMTRIS";
|
||||
|
||||
static void put(int row, int col, const char *s, unsigned char attr)
|
||||
{
|
||||
x11_setcursor(row, col);
|
||||
while(*s) x11_ibmchar((unsigned char)*s++, attr);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int r, c;
|
||||
|
||||
mark[0] = 0x524E4452UL; /* RNDR */
|
||||
if(vt_x11_init() != 0) return 1;
|
||||
mark[1] = (vt_u32)vt_dpy;
|
||||
mark[2] = vt_win;
|
||||
mark[3] = vt_gc;
|
||||
mark[5] = (vt_u32)VT_XPENDING(vt_dpy);
|
||||
|
||||
x11_clearscr();
|
||||
for(c = 0; c < 80; c++) {
|
||||
x11_setcursor(0, c); x11_ibmchar('#', 0x70);
|
||||
x11_setcursor(23, c); x11_ibmchar('#', 0x70);
|
||||
}
|
||||
for(r = 0; r < 24; r++) {
|
||||
x11_setcursor(r, 0); x11_ibmchar('#', 0x70);
|
||||
x11_setcursor(r, 79); x11_ibmchar('#', 0x70);
|
||||
}
|
||||
for(r = 2; r < 20; r++) {
|
||||
for(c = 4; c <= 13; c++) {
|
||||
int edge = (r == 2 || r == 19 || c == 4 || c == 13);
|
||||
x11_setcursor(r, c);
|
||||
x11_ibmchar(edge ? '#' : '.', edge ? 0x70 : 0x07);
|
||||
}
|
||||
}
|
||||
put(1, 20, word, 0x70);
|
||||
put(21, 20, "0123456789", 0x70);
|
||||
put(22, 20, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0x70);
|
||||
vt_x11_flush();
|
||||
mark[4] = 0x464C5553UL; /* FLUS */
|
||||
|
||||
for(;;) {
|
||||
VT_SLEEP(100);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
-- render.lua -- paint the cell-grid test pattern and snapshot the window. The
|
||||
-- PNG is the evidence render.sh keeps.
|
||||
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
|
||||
local H = dofile(dir .. "/harness.lua")
|
||||
|
||||
local RENDER_MARK = tonumber(os.getenv("RENDER_MARK") or "0x01A08000")
|
||||
local X11P = tonumber(os.getenv("X11_PROGRESS") or "0")
|
||||
|
||||
H.result_dump(function()
|
||||
print(string.format("RENDER: magic=%08X dpy=%08X win=%08X gc=%08X flus=%08X progress=%08X",
|
||||
H.r32(RENDER_MARK), H.r32(RENDER_MARK + 0x20), H.r32(RENDER_MARK + 0x40),
|
||||
H.r32(RENDER_MARK + 0x60), H.r32(RENDER_MARK + 0x80),
|
||||
X11P ~= 0 and H.r32(X11P) or 0))
|
||||
print(string.format("RENDER: pending=%d", H.r32(RENDER_MARK + 0xA0)))
|
||||
end)
|
||||
|
||||
H.run()
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
# render.sh -- Task 3 acceptance: paint the cell-grid test pattern, then
|
||||
# snapshot the window. The PNG is the evidence.
|
||||
set -eu
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
APP=$(cd "$DIR/.." && pwd)
|
||||
ROOT=$(cd "$APP/../.." && pwd)
|
||||
M=${MAME:-/home/arti/code/k-space/mame0289/vt1200}
|
||||
EV="$APP/evidence"
|
||||
LOG="$APP/build/render.log"
|
||||
mkdir -p "$EV" "$APP/build"
|
||||
"$APP/build.sh" "$DIR/render.c" "$APP/src/vt1200/x11.c" "$APP/src/vt1200/xgfix.c" >"$APP/build/render-build.log" 2>&1
|
||||
rm -f "$EV/loader_frame3400.png"
|
||||
MARK=$(awk '{for(i=2;i<=NF;i++) if($i=="_mark") print $(i-1)}' "$APP/build/render.map" | head -1)
|
||||
PROG=$(awk '{for(i=2;i<=NF;i++) if($i=="_vt_x11_progress") print $(i-1)}' "$APP/build/render.map" | head -1)
|
||||
VT1200_SKIP_LEVEL1=1 LOADER_SNAP=1 RENDER_MARK="0x$MARK" X11_PROGRESS="0x$PROG" \
|
||||
LOADER_AT=2500 LOADER_END=3400 \
|
||||
LOADER_BIN="$ROOT/dwt/loader/build/loader.bin" \
|
||||
LOADER_COFF="$APP/build/render.coff" \
|
||||
LOADER_OUT="$EV" \
|
||||
"$M" vt1200 -rompath "$ROOT/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$DIR/render.lua" -autoboot_delay 0 \
|
||||
>"$LOG" 2>&1 || true
|
||||
grep -E 'LOADER: snapshot|LOADER: result' "$LOG" | tail -4
|
||||
grep -q 'RENDER: magic=524E4452 .*flus=464C5553' "$LOG" || {
|
||||
echo "render.sh: the renderer did not finish (see $LOG)" >&2
|
||||
exit 1
|
||||
}
|
||||
grep -q 'RENDER: .*progress=00FFFFFF' "$LOG" || {
|
||||
echo "render.sh: flush did not complete (see $LOG)" >&2
|
||||
exit 1
|
||||
}
|
||||
[ -s "$EV/loader_frame3400.png" ] || { echo "render.sh: no snapshot (see $LOG)" >&2; exit 1; }
|
||||
cp "$EV/loader_frame3400.png" "$EV/render_frame3400.png"
|
||||
echo "render: $EV/render_frame3400.png"
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* smoke.c -- Task 1 acceptance: a local Xlib client installs the per-process
|
||||
* Xlib context, opens the display, maps a window, and receives a real KeyPress.
|
||||
*/
|
||||
#include "xlib.h"
|
||||
|
||||
extern int vt_install_xg(void);
|
||||
|
||||
volatile vt_u32 mark[32];
|
||||
volatile vt_u32 evbuf[24];
|
||||
|
||||
int main(void)
|
||||
{
|
||||
void *dpy;
|
||||
vt_u32 root, win;
|
||||
vt_u32 ks;
|
||||
char buf[8];
|
||||
int n;
|
||||
|
||||
mark[0] = 0x534D4F4BUL; /* SMOK */
|
||||
if(!vt_install_xg()) return 1;
|
||||
dpy = VT_XOPEN("0::0");
|
||||
mark[1] = (vt_u32)dpy;
|
||||
if(!dpy) return 2;
|
||||
|
||||
root = *(vt_u32 *)((char *)dpy + 0x90);
|
||||
root = *(vt_u32 *)((char *)root + 8);
|
||||
win = VT_XCREATE(dpy, root, 80, 80, 480, 312, 2, 1, 0);
|
||||
mark[2] = win;
|
||||
if(!win) return 3;
|
||||
|
||||
VT_XSELECT(dpy, win, 0x22000FUL);
|
||||
VT_XMAP(dpy, win);
|
||||
VT_XSYNC(dpy, 0);
|
||||
mark[3] = 0;
|
||||
|
||||
for(;;) {
|
||||
VT_XNEXT(dpy, (void *)evbuf);
|
||||
mark[3] = mark[3] + 1;
|
||||
mark[4] = evbuf[0];
|
||||
mark[5] = evbuf[13];
|
||||
if(evbuf[0] == 2) {
|
||||
ks = 0;
|
||||
n = VT_XLOOKUP((void *)evbuf, buf, 8, &ks, 0);
|
||||
mark[6] = (vt_u32)n;
|
||||
mark[7] = (vt_u32)(unsigned char)buf[0];
|
||||
mark[8] = ks;
|
||||
mark[9] = 0x4B455950UL; /* KEYP */
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
-- smoke.lua -- Xlib key delivery: click the window, press A, and require a
|
||||
-- real KeyPress plus XLookupString('a'). smoke.sh greps the SMOKE: line.
|
||||
local dir = (debug.getinfo(1, "S").source:gsub("^@", ""):match("^(.*)/") or ".")
|
||||
local H = dofile(dir .. "/harness.lua")
|
||||
|
||||
local MARK = tonumber(os.getenv("SMOKE_MARK") or "0x01A00000")
|
||||
|
||||
H.config{ tablet = "SMOKE" }
|
||||
H.key(3100, ":lk401:K26", "A", 1, "SMOKE: A down")
|
||||
H.key(3120, ":lk401:K26", "A", 0, "SMOKE: A up")
|
||||
|
||||
H.result_dump(function()
|
||||
print(string.format("SMOKE: magic=%08X dpy=%08X win=%08X n=%d type=%d keycode=%d lookup_n=%d ch=%02X ks=%04X keymark=%08X",
|
||||
H.r32(MARK + 0x00), H.r32(MARK + 0x20), H.r32(MARK + 0x40), H.r32(MARK + 0x60),
|
||||
H.r32(MARK + 0x80), H.r32(MARK + 0xA0), H.r32(MARK + 0xC0), H.r32(MARK + 0xE0),
|
||||
H.r32(MARK + 0x100), H.r32(MARK + 0x120)))
|
||||
end)
|
||||
|
||||
H.run()
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/bin/sh
|
||||
# smoke.sh -- Task 1 acceptance. Builds the local Xlib smoke payload, loads it
|
||||
# into the emulated VT1200 RAM, clicks the window, presses A, and requires a
|
||||
# real KeyPress + XLookupString('a').
|
||||
set -eu
|
||||
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
APP=$(cd "$DIR/.." && pwd)
|
||||
ROOT=$(cd "$APP/../.." && pwd)
|
||||
M=${MAME:-/home/arti/code/k-space/mame0289/vt1200}
|
||||
LOG="$APP/build/smoke.log"
|
||||
|
||||
mkdir -p "$APP/build"
|
||||
"$APP/build.sh" "$DIR/smoke.c" "$APP/src/vt1200/xgfix.c" >"$APP/build/smoke-build.log" 2>&1
|
||||
|
||||
MARK=$(awk '{for(i=2;i<=NF;i++) if($i=="_mark") print $(i-1)}' "$APP/build/smoke.map" | head -1)
|
||||
VT1200_SKIP_LEVEL1=1 SMOKE_MARK="0x$MARK" \
|
||||
LOADER_AT=2500 LOADER_END=3400 \
|
||||
LOADER_BIN="$ROOT/dwt/loader/build/loader.bin" \
|
||||
LOADER_COFF="$APP/build/smoke.coff" \
|
||||
LOADER_OUT="$APP/build" \
|
||||
"$M" vt1200 -rompath "$ROOT/harness/mame/roms" \
|
||||
-video none -sound none -nothrottle -skip_gameinfo \
|
||||
-debug -debugger none \
|
||||
-autoboot_script "$DIR/smoke.lua" -autoboot_delay 0 \
|
||||
>"$LOG" 2>&1 || true
|
||||
|
||||
grep 'SMOKE:' "$LOG" | tail -5
|
||||
grep -q 'SMOKE: .*type=2 .*keymark=4B455950' "$LOG" || {
|
||||
echo "smoke.sh: no real KeyPress (see $LOG)" >&2
|
||||
exit 1
|
||||
}
|
||||
grep -q 'SMOKE: .*lookup_n=1 ch=61 ks=0061' "$LOG" || {
|
||||
echo "smoke.sh: XLookupString did not return 'a' (see $LOG)" >&2
|
||||
exit 1
|
||||
}
|
||||
echo "smoke: PASS"
|
||||
@@ -0,0 +1,107 @@
|
||||
#!/bin/sh
|
||||
# verify.sh -- one-command acceptance for the VT1200 termtris port.
|
||||
#
|
||||
# apps/termtris/verify.sh # build MAME, then run every test
|
||||
# apps/termtris/verify.sh --skip-mame # use the emulator already installed
|
||||
#
|
||||
# Runs every test even after a failure and exits non-zero if any failed. Each
|
||||
# test's full output is kept in apps/termtris/build/verify_<name>.log.
|
||||
set -eu
|
||||
|
||||
DIR=$(cd "$(dirname "$0")" && pwd)
|
||||
ROOT=$(cd "$DIR/../.." && pwd)
|
||||
M=${MAME:-/home/arti/code/k-space/mame0289/vt1200}
|
||||
ROM_MD5=b46a3e442ccb86134d2356bd70d22fd2
|
||||
|
||||
skip_mame=0
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--skip-mame) skip_mame=1 ;;
|
||||
-h|--help)
|
||||
sed -n '2,8p' "$0" | sed 's/^# \{0,1\}//'
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "verify.sh: unknown argument: $arg" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
mkdir -p "$DIR/build"
|
||||
|
||||
echo "== ROM checksum"
|
||||
got=$(md5sum "$ROOT/vt1200_v22.bin" | cut -d' ' -f1)
|
||||
if [ "$got" != "$ROM_MD5" ]; then
|
||||
echo "FAIL: vt1200_v22.bin md5 is $got, expected $ROM_MD5" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "ok: $got"
|
||||
|
||||
echo "== 2ine toolchain"
|
||||
LX="${NINE:-/home/arti/os2-work/2ine/build}/lx_loader"
|
||||
if [ ! -x "$LX" ]; then
|
||||
echo "FAIL: no 2ine lx_loader at $LX (set NINE=/path/to/2ine/build)" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "ok: $LX"
|
||||
|
||||
echo "== emulator"
|
||||
if [ "$skip_mame" -eq 0 ]; then
|
||||
JOBS=${JOBS:-8} "$ROOT/harness/mame/build.sh"
|
||||
fi
|
||||
if [ ! -x "$M" ]; then
|
||||
echo "FAIL: no vt1200 binary at $M (set MAME=... or drop --skip-mame)" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "ok: $M"
|
||||
|
||||
export MAME="$M"
|
||||
fail=0
|
||||
|
||||
run() {
|
||||
name=$1
|
||||
shift
|
||||
printf '== %-9s ' "$name"
|
||||
if "$@" >"$DIR/build/verify_$name.log" 2>&1; then
|
||||
echo "PASS"
|
||||
else
|
||||
echo "FAIL (apps/termtris/build/verify_$name.log)"
|
||||
tail -20 "$DIR/build/verify_$name.log" | sed 's/^/ /'
|
||||
fail=1
|
||||
fi
|
||||
}
|
||||
|
||||
run smoke "$DIR/tests/smoke.sh"
|
||||
run fmt "$DIR/tests/fmt.sh"
|
||||
run render "$DIR/tests/render.sh"
|
||||
run input "$DIR/tests/input.sh"
|
||||
run play "$DIR/tests/play.sh"
|
||||
run play_keys "$DIR/tests/play_keys.sh"
|
||||
|
||||
echo
|
||||
echo "== play acceptance"
|
||||
if [ -f "$DIR/build/play_move.log" ]; then
|
||||
for mode in move panels quit; do
|
||||
grep -a -h 'DIAG: loops' "$DIR/build/play_$mode.log" 2>/dev/null |
|
||||
head -1 | sed "s/^/ $mode /"
|
||||
done
|
||||
fi
|
||||
|
||||
echo
|
||||
echo "== evidence"
|
||||
ls -1 "$DIR"/evidence/*.png 2>/dev/null | sed 's/^/ /'
|
||||
|
||||
echo
|
||||
echo "== ROM checksum (after the suite)"
|
||||
got=$(md5sum "$ROOT/vt1200_v22.bin" | cut -d' ' -f1)
|
||||
[ "$got" = "$ROM_MD5" ] || { echo "FAIL: ROM changed during the run" >&2; exit 1; }
|
||||
echo "ok: $got"
|
||||
|
||||
if [ "$fail" -ne 0 ]; then
|
||||
echo
|
||||
echo "verify: FAILED" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo
|
||||
echo "verify: PASS"
|
||||
@@ -96,8 +96,7 @@ The 1990 **r5.01 OS/2** toolchain under `2ine-tms34010` also builds it (see
|
||||
`gspopt -O2`: the optimizer hoists the `CTRL_READY` polling load and the
|
||||
payload waits forever at takeover. `MOVIE.C` is fine at `-O2`. The verified
|
||||
r5.01 build is `.text` 3,168 bytes, entry `0x018C5C70`, and is MAME-exact at
|
||||
frames 0 and 180. `gspac`/`gspcg` exit 139 at teardown but still write valid
|
||||
files.
|
||||
frames 0 and 180.
|
||||
|
||||
## Run in MAME (debugger path)
|
||||
|
||||
|
||||
@@ -110,8 +110,7 @@ MAME frame 0 and frame 180 are **EXACT** with
|
||||
|
||||
Caveat: `gspopt -O2` on `MAIN.C` hoists the `CTRL_READY` polling load and
|
||||
the payload waits forever at takeover. `MOVIE.C` is fine at `-O2`; build
|
||||
`MAIN.C` without `gspopt`, or add `volatile` to the polling reads. `gspac`
|
||||
and `gspcg` exit 139 at teardown but still write valid output files.
|
||||
`MAIN.C` without `gspopt`, or add `volatile` to the polling reads.
|
||||
`gspa` 5.01 accepted `entry.asm`/`fill.asm` (including `sp`); the `b15`
|
||||
round-trip difference does not affect this demo.
|
||||
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
# termtris VT1200 X11 port — implementation plan
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Build a playable `termtris` that runs as a VT1200 `create_process` child, renders through the ROM X11 server, and accepts the real X keyboard events.
|
||||
|
||||
**Architecture:** Vendored upstream game logic + a small VT1200 backend. The backend installs a zeroed per-process Xlib context (`XG`), opens `"0::0"`, maps a 480×312 window, and emulates an 80×24 cell terminal with 6×13 cells. `XNextEvent`/`XLookupString` feed `game_input`; `0x1E93C0` + `sleep(0x3FB33A20)` pace `update`. A 1990 r5.01/2ine build produces absolute COFF for `dwt/loader`.
|
||||
|
||||
**Tech Stack:** 1990 TI TMS34010 C tools (r5.01) under 2ine; VT1200 ROM Xlib; MAME `vt1200` harness; GSPLNK COFF.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-11-03-termtris-vt1200-design.md`
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- ROM `vt1200_v22.bin` stays byte-identical (`md5 b46a3e442ccb86134d2356bd70d22fd2`); no MAME or ROM edits.
|
||||
- The game runs from VT1200 main RAM via `dwt/loader`; no network and no host-side game client.
|
||||
- Link `.text`/`.data`/`.cinit` at bit `0x018A0000`, `.bss` at `0x01A00000`; entry `_start` from `entry.asm`; the `cinit` table is processed by our `var_init`.
|
||||
- All Xlib calls use the TI C ABI and the addresses in the spec; re-establish the CPU field state after calls if the compiler's generated code requires it.
|
||||
- The per-process Xlib context fix is mandatory **before** `XOpenDisplay`:
|
||||
`proc = *(u32 *)0x1B3900; pp = *(u32 *)(proc + 0x100); *(u32 *)pp = (u32)zeroed_xg_block;`
|
||||
- Build stages are retried: 2ine exits 139 after producing output; check artifacts, not exit codes.
|
||||
- Vendor `termtris` under `apps/termtris/` with `COPYING` and the GPLv3 headers intact.
|
||||
- Commit only `apps/termtris/**`, `harness/mame/TERMTRIS_REPORT.md`, and `docs/superpowers/**` in this work.
|
||||
|
||||
## Review Focus
|
||||
|
||||
- **A late client's event queue:** the XG block must be installed before `XOpenDisplay`; if it is not, KeyPress events are zero. The acceptance test must inject a key and assert `type=2`.
|
||||
- **Cell coordinates:** 6×13, baseline +10; a wrong pitch shears the whole board. The screenshot must show aligned columns.
|
||||
- **Timer wrap:** `0x1E93C0` is 16-bit; use `(u16)(now-last)` deltas, never a raw monotonic assumption.
|
||||
- **Toolchain output loss:** `gspcg`/`gspa` can crash after writing; the build must detect missing artifacts and retry, not treat exit 139 as failure.
|
||||
- **No stdio:** `sprintf`/`fflush`/`stdout` are absent; the compat layer must cover every format/use the game actually has.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Vendor and smoke-test the toolchain
|
||||
|
||||
**Files:**
|
||||
- Create: `apps/termtris/` (upstream `src/`, `COPYING`, `README.md`)
|
||||
- Create: `apps/termtris/src/vt1200/entry.asm`
|
||||
- Create: `apps/termtris/src/vt1200/xlib.h`
|
||||
- Create: `apps/termtris/src/vt1200/xgfix.c`
|
||||
- Create: `apps/termtris/build.sh`
|
||||
- Test: `apps/termtris/tests/smoke.c` + `apps/termtris/tests/smoke.sh`
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `vt_install_xg(void)` in `xgfix.c`; `xlib.h` with the ROM addresses and `vt_xopen`, `vt_xcreate`, `vt_xselect`, `vt_xmap`, `vt_xsync`, `vt_xflush`.
|
||||
- Produces: `build.sh` usage `build.sh <source.c> [extra.obj...]` -> `apps/termtris/build/<name>.coff` and `.map`.
|
||||
|
||||
- [ ] **Step 1: Copy upstream** `termtris` into `apps/termtris/` (keep `COPYING`, `src/game.c`, `pieces.h`, `game.h`, `term.h`, `scoredb.h`; do not copy the DOS/Windows/unix backends). Record the upstream commit hash in `apps/termtris/UPSTREAM`.
|
||||
- [ ] **Step 2: Write `entry.asm`** — set `A14` to `_cstack`, `A13=A14`; run the cinit loop (length word at `*A9++`, destination long at `*A9++`, copy `length` words), then `CALLA _main`, `RETS`; `.bss _cstack, 32768, 16`.
|
||||
- [ ] **Step 3: Write `xlib.h`** with the addresses from the spec and TI-ABI prototypes:
|
||||
`XOpenDisplay 0x3F9C2570`, `XCreateSimpleWindow 0x3FD41B90`, `XSelectInput 0x3FD97D50`, `XMapWindow 0x3FD64F60`, `XSync 0x3FD9F6B0`, `XFlush 0x3F9B1030`, `XNextEvent 0x3F9C1CF0`, `XLookupString 0x3F9A9C30`, `XCreateGC 0x3F997000`, `XSetForeground 0x3FD99A60`, `XFillRectangle 0x3F99E8F0`, `XDrawString 0x3FDA0000`, `sleep 0x3FB33A20`.
|
||||
- [ ] **Step 4: Write `xgfix.c`** exactly as the spec's fix; return 0 if `proc`/`pp` is outside RAM, else install a static zeroed `u32 xg[256]` and return 1.
|
||||
- [ ] **Step 5: Write `build.sh`** — extract the r5.01 tools/libs into `apps/termtris/work/`; run `gspac -k`, `gspopt -k -O2`, `gspcg -m`, `gspa`, `gsplnk`; retry each stage up to 5 times and verify its output before proceeding; `gsplnk` command file with `.text/.data/.cinit` at `018A0000h` and `.bss` at `01A00000h`; fail if `termtris.out`/`.map` absent.
|
||||
- [ ] **Step 6: Smoke test** — `tests/smoke.c` calls `vt_install_xg`, `XOpenDisplay("0::0")`, creates/maps a 480×312 window, selects KeyPress, loops `XNextEvent`, stores `type/keycode` in `.bss` markers, and breaks on `type==2`. `tests/smoke.sh` builds it and runs `dwt/loader/loader.lua` with `LOADER_AT=2500 LOADER_END=3400`, injecting a tablet click at 3000 and `A` at 3100 via a copy of the validated input script.
|
||||
- [ ] **Step 7: Verify smoke** — the run prints `type=2`, `keycode=194`, `XLookupString` `n=1, ch=0x61, ks=0x0061`. If not, do not proceed.
|
||||
- [ ] **Step 8: Commit** `apps/termtris` scaffold + smoke.
|
||||
|
||||
### Task 2: Compatibility layer
|
||||
|
||||
**Files:**
|
||||
- Create: `apps/termtris/src/vt1200/stdio.h`
|
||||
- Create: `apps/termtris/src/vt1200/inttypes.h`
|
||||
- Create: `apps/termtris/src/vt1200/compat.c`
|
||||
- Test: `apps/termtris/tests/fmt.c` + loader run
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `int sprintf(char *buf, const char *fmt, ...)` supporting `%d`, `%ld`, `%u`, `%lu`, `%s`, `%c`, `%%`, optional `-`/`0`, decimal width; `int fflush(void *f)` returns 0; `extern void *stdout` is a null pointer; `time_t time(time_t *)` returns `now_ms()/1000`.
|
||||
- Produces: `uint16_t`/`uint32_t` typedefs in `inttypes.h`.
|
||||
|
||||
- [ ] **Step 1: Write the test** `fmt.c` producing the exact strings used by `game.c`: `"%10ld"` 12345 -> `" 12345"`, `"%2ld"` 7 -> `" 7"`, `"%8ld"` 42 -> `" 42"`, `"%2d. %s %ld"` (1,"ab",99) -> `" 1. ab 99"`, `"%-3s"` "x" -> `"x "`, `"%%"` -> `"%"`. Store a checksum/bytes in markers.
|
||||
- [ ] **Step 2: Implement `compat.c`** with a manual varargs walk (`char *ap = (char *)&fmt; ap -= 4;` per argument) and a decimal/string formatter; no `stdio.h` from the SDK.
|
||||
- [ ] **Step 3: Write the shims** so `game.c`'s `<stdio.h>`/`<inttypes.h>` resolve to them; `FILE` is an `int`, `stdout` is 0.
|
||||
- [ ] **Step 4: Run the loader test** and compare the marker bytes to the expected strings; fix until exact.
|
||||
- [ ] **Step 5: Commit** compat + test.
|
||||
|
||||
### Task 3: Cell-grid X11 backend
|
||||
|
||||
**Files:**
|
||||
- Create: `apps/termtris/src/vt1200/x11.c`
|
||||
- Create: `apps/termtris/src/vt1200/x11.h`
|
||||
- Test: `apps/termtris/tests/render.c` + screenshot
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `int vt_x11_init(void)` — open display, install XG, create 480×312 window at (80,80), select input, map, create GC, `XSync`; returns 0 on success.
|
||||
- Produces: `void vt_x11_flush(void)` — draw dirty cells.
|
||||
- Produces: `term_*` callback implementations: `x11_reset`, `x11_clearscr`, `x11_setcursor(row,col)`, `x11_cursor(show)`, `x11_setcolor(fg,bg)`, `x11_ibmchar(c,attr)`; `term_putstr` loops `x11_ibmchar`.
|
||||
- Produces: `vt_x11_key(int *ks, int *ch)`? No — input is in Task 4; this task only exposes the window/display globals via `x11.h`.
|
||||
|
||||
- [ ] **Step 1: Write `render.c`** that calls `vt_x11_init`, fills an 80×24 cell buffer with a border pattern and `TERMTRIS` text, marks all cells dirty, flushes, and exits via a marker.
|
||||
- [ ] **Step 2: Implement the cell grid** with `unsigned short ch; unsigned char fg, bg;` per cell; `x11_ibmchar` writes at the cursor and advances; `attr` decode `fg=(attr>>4)&0xf`, `bg=attr&0xf`; mono pixel `(fg==0?0:1)`, `(bg==0?0:1)`.
|
||||
- [ ] **Step 3: Implement flush** per dirty cell: `XSetForeground(bg)`, `XFillRectangle(x,y,6,13)`, `XSetForeground(fg)`, `XDrawString(x,y+10,ch,1)`; then `XFlush`.
|
||||
- [ ] **Step 4: Metrics test** — render a row of `'#'` at columns 0..79, a 20×18 playfield outline, and the word `TERMTRIS`; capture the frame at 3300 with `LOADER_SNAP=1`; visually verify 6-px columns and 13-px rows, no shear.
|
||||
- [ ] **Step 5: Commit** backend + screenshot evidence.
|
||||
|
||||
### Task 4: Input, timer, and main loop
|
||||
|
||||
**Files:**
|
||||
- Create: `apps/termtris/src/vt1200/main.c`
|
||||
- Test: `apps/termtris/tests/input.c` + loader run with injected keys
|
||||
|
||||
**Interfaces:**
|
||||
- Produces: `long now_ms(void)` — 32-bit accumulator over the 16-bit `0x1E93C0`; `void sleep_ms(int ms)` — `sleep(0x3FB33A20)`.
|
||||
- Produces: `int vt_poll_event(void)` — `XPending` (`0x3FD67620`) > 0; `void vt_handle_event(void)` — `XNextEvent`, `XLookupString`, map to `game_input`.
|
||||
- Produces: `int main(void)` — `vt_install_xg`, `vt_x11_init`, `init_game`, loop: drain events, `now=now_ms()`, `next=update(now)`, `sleep_ms(min(next-now,10))`; Expose -> `full_redraw` via `game_input('`')`; FocusOut -> `game_input('p')`.
|
||||
|
||||
- [ ] **Step 1: Write `input.c`** that initializes the game/window, then on the first `KeyPress` calls `XLookupString` and stores `keycode`, `keysym`, and the mapped `game_input` byte in markers; inject `A`, Up, Down, Left, Right, `0`, Enter, Backspace.
|
||||
- [ ] **Step 2: Implement the key map**: letters lower-cased via `XLookupString`; `XK_Left 0xFF51` -> `game_input(0x9b); game_input('A')`; Right 0xFF53 -> `'D'`; Up 0xFF52 -> `'A'?` (use `'w'`); Down 0xFF54 -> `'B'`? Use the game's CSI codes: `0x9b` + `A/B/C/D` for up/down/right/left. Return/Enter -> `'\n'`; Backspace -> `'\b'`; space -> `' '`; Escape -> `27`; digits/letters direct.
|
||||
- [ ] **Step 3: Implement the timer** and idle sleep; test that the game's `update` is called ~every 50–900 ms by recording a counter in markers.
|
||||
- [ ] **Step 4: Run with the injected keys**; verify the mapped bytes (A -> 'a', Up -> CSI 'A', etc.) and that the process keeps running.
|
||||
- [ ] **Step 5: Commit** main/input.
|
||||
|
||||
### Task 5: Game integration, score table, and COFF
|
||||
|
||||
**Files:**
|
||||
- Modify: `apps/termtris/src/game.c` (only `#ifdef VT1200` includes/compat if needed; game logic unchanged)
|
||||
- Create: `apps/termtris/src/vt1200/scoredb.c`
|
||||
- Modify: `apps/termtris/build.sh` to compile `game.c`, `pieces` (header), backend, compat, scoredb, entry
|
||||
- Test: loader run + screenshot + play
|
||||
|
||||
**Interfaces:**
|
||||
- Consumes: all Task 2–4 interfaces.
|
||||
- Produces: `build/termtris.coff`, `build/termtris.map`.
|
||||
- `scoredb.c` implements `read_scores`, `save_score`, `print_scores` with a static 10-entry list; `username` default `"VT1200"`.
|
||||
|
||||
- [ ] **Step 1: Compile `game.c`** with the 1990 compiler; fix only portability issues (missing `fflush`/`sprintf` via shims, no `unistd`/`fcntl`); do not change game rules.
|
||||
- [ ] **Step 2: Implement `scoredb.c`** with a static array; `read_scores` returns it; `save_score` sorts/inserts; `print_scores` no-op/fills the list.
|
||||
- [ ] **Step 3: Build the full COFF**; verify the map: `.text/.data/.cinit` at `018A0000`, `.bss` at `01A00000`, entry `_start`, no undefined symbols.
|
||||
- [ ] **Step 4: Load and screenshot** at frame 3000 with `dwt/loader/loader.lua`; the Terminal Manager is replaced/covered by the termtris board window.
|
||||
- [ ] **Step 5: Play** — inject `A/D/S/W`, `0`, `P`, `R`, `H`, `Q`; capture frames showing piece movement, score update, help/score panels; verify quit/restart.
|
||||
- [ ] **Step 6: Commit** game + scores.
|
||||
|
||||
### Task 6: Documentation and real-unit path
|
||||
|
||||
**Files:**
|
||||
- Create: `harness/mame/TERMTRIS_REPORT.md`
|
||||
- Modify: `apps/termtris/README.md` (build/run/real-unit)
|
||||
- Maybe: `apps/termtris/run.sh` convenience wrapper
|
||||
|
||||
- [ ] **Step 1: Write the report** with the toolchain, the XG root cause/fix, the 6×13/80×24 geometry, the timer, the keyboard map, the loader command, evidence screenshots, and the ROM md5 check.
|
||||
- [ ] **Step 2: Document the real unit** — same COFF via `dwt/loader/hostload.py`; the XG fix is required; the X server must accept the local connection (default); click the window to focus.
|
||||
- [ ] **Step 3: Add a `run.sh`** that builds (optional) and runs MAME with the loader and a deterministic input script for CI.
|
||||
- [ ] **Step 4: Final verification** — `md5sum vt1200_v22.bin` unchanged; no MAME/ROM edits; `git status` only our paths.
|
||||
- [ ] **Step 5: Commit** docs/report.
|
||||
|
||||
---
|
||||
|
||||
## Self-review notes
|
||||
|
||||
- Spec coverage: vendoring, build, XG fix, renderer, input, timer, scores, acceptance, docs are each a task.
|
||||
- The one open implementation choice left to the builder is the exact `sprintf` formatter internals; the required formats are pinned by Task 2's tests.
|
||||
- The XG block size (1 KiB) is a deliberate value; if the Xlib writes beyond it, enlarge the static buffer.
|
||||
- The input map uses `XLookupString` for letters/digits and keysyms for arrows/editing keys; the exact game escape codes are the game's existing `game_input` codes.
|
||||
@@ -0,0 +1,141 @@
|
||||
# termtris for the VT1200 — design
|
||||
|
||||
Date: 2026-11-03. Status: ready for implementation (input path proven).
|
||||
|
||||
## Intent
|
||||
|
||||
Run `jtsiomb/termtris` as a **local VT1200 program**: loaded into main RAM by the
|
||||
existing COFF loader, displayed through the terminal's **ROM X11 server**, and
|
||||
controlled from the real X keyboard events. End-to-end proof is a playable game in
|
||||
MAME, with the real-unit path documented.
|
||||
|
||||
## What is already proven (2026-11-03)
|
||||
|
||||
- **Compiler**: the 1990 r5.01 OS/2 toolchain under the patched 2ine fork builds
|
||||
ANSI C. Pipeline: `gspac -> gspopt -O2 -> gspcg -> gspa -> gsplnk` -> absolute
|
||||
COFF, linked at bit `0x018A0000` (`.bss` at `0x01A00000`).
|
||||
- **Loader**: `dwt/loader` pokes the COFF, `create_process`es the entry, and the
|
||||
program runs. `.cinit` static initialisers run via our own `var_init` in
|
||||
`entry.asm`; the linker's `cinit` symbol is at the start of `.cinit`.
|
||||
- **ROM Xlib**: `XOpenDisplay`, `XCreateSimpleWindow`, `XSelectInput`,
|
||||
`XMapWindow` (`0x3FD64F60`; `0x3FD645B0` is `XMapRaised`), `XSync`,
|
||||
`XCreateGC`, `XSetForeground`, `XFillRectangle` (`0x3F99E8F0`),
|
||||
`XDrawString` (`0x3FDA0000`), `XNextEvent` (`0x3F9C1CF0`),
|
||||
`XLookupString` (`0x3F9A9C30`) all work from C with the TI ABI.
|
||||
- **Rendering**: the default GC's font is **6×13** (baseline +10); an 80×24 cell
|
||||
grid is 480×312. White rectangle + text were rendered in a WM-framed window.
|
||||
- **Input (the blocker, now solved)**: a `create_process` child has an
|
||||
**uninitialised per-process Xlib context**. `create_process` leaves
|
||||
`*(proc+0x100)` pointing at a zeroed word; `_XEnq` derives
|
||||
`XG = *(*(proc+0x100))`, so `XG == NULL` and its event free list at
|
||||
`XG+0xCC0` (bit) reads low-RAM garbage. KeyPress nodes were therefore invalid
|
||||
and `XNextEvent` copied unmapped zeros.
|
||||
**Fix**: before `XOpenDisplay`, set
|
||||
`*(u32 *)(*(u32 *)(proc + 0x100)) = (u32)zeroed_block`, where `proc` is
|
||||
`*(u32 *)0x1B3900` and `zeroed_block` is a static `.bss` buffer (1 KiB is
|
||||
enough). With that, the local client receives real events:
|
||||
KeyPress `type=2`, `keycode=194` (LK401 `C2`), `window=0x00400001`, and
|
||||
`XLookupString` returns `n=1, char='a', keysym=0x61`.
|
||||
- **Timing**: `sleep(ms)` at `0x3FB33A20` blocks and yields; the raw millisecond
|
||||
counter is the 16-bit `0x1E93C0` (+17 per display interrupt). Use a 32-bit
|
||||
accumulator with `(u16)(now - last)` to avoid the 84 s wrap.
|
||||
- **TCP X** also works (`xdpyinfo`/`xev` against `100.103.100.103:0` with the
|
||||
real unit's NVRAM security settings); it is useful for debugging, but the game
|
||||
uses the local service (`"0::0"`), so it needs no network.
|
||||
|
||||
## Goals
|
||||
|
||||
- `termtris` game logic (pieces, scoring, levels, spawn, collision) unchanged in
|
||||
behaviour.
|
||||
- X11 cell-grid renderer: 80×24 characters, 6×13 cells, monochrome pens.
|
||||
- Real X11 input: `KeyPress` -> `XLookupString`/keysym -> `game_input`; arrows
|
||||
mapped to the game's CSI sequences, letters lower-cased.
|
||||
- Runs from local RAM under `dwt/loader`, with a screenshot and a playable run.
|
||||
- A build script and a short report documenting the toolchain, the leak/loader
|
||||
addresses, the XG fix, and the limits.
|
||||
|
||||
## Non-goals
|
||||
|
||||
- No host-side X client for the game (the x86 `xev` was a diagnostic only).
|
||||
- No terminal/ANSI backend on the VT1200 (the game is X11).
|
||||
- No modification of the ROM or MAME. All fixes are runtime RAM writes.
|
||||
- No file-backed high-score table (the VT1200 has no filesystem); scores live in
|
||||
RAM for the session.
|
||||
|
||||
## Approaches considered
|
||||
|
||||
1. **Local Xlib + XG initialisation (chosen).** Proven; uses the terminal's real
|
||||
X server and keyboard; no network; the game is a local `create_process` child.
|
||||
2. Local Xlib + OS pointer/keycode polling. Reliable fallback, but the keyboard
|
||||
global is lossy (no release/repeat) and the pointer is an odd controller.
|
||||
Keep as a compile-time fallback only.
|
||||
3. Host x86 X client over TCP. Works and was used for diagnosis, but does not
|
||||
satisfy "run from VT1200 RAM".
|
||||
4. Terminal/ANSI backend. Not X11 and not the request.
|
||||
|
||||
## Architecture / files
|
||||
|
||||
```
|
||||
apps/termtris/ vendored upstream (GPLv3, COPYING kept)
|
||||
src/game.c, pieces.h upstream, small VT1200 patches
|
||||
src/vt1200/
|
||||
main.c X11 event loop, timer, key mapping
|
||||
x11.c term_* callbacks -> cell grid -> XFillRectangle/XDrawString
|
||||
xlib.h ROM entry-point addresses + TI-ABI prototypes
|
||||
xgfix.c per-process Xlib context installation
|
||||
scoredb.c RAM-only high scores
|
||||
compat.c sprintf subset, fflush/stdout stubs
|
||||
entry.asm _start + cinit var_init + rets
|
||||
build.sh 2ine/r5.01 pipeline with stage retries
|
||||
README.md build/run/real-unit instructions
|
||||
```
|
||||
|
||||
Rendering is a small virtual terminal: `term_setcursor`/`term_putstr`/
|
||||
`term_setcolor`/`term_ibmchar` update a cell buffer; `wait_display()` flushes
|
||||
changed cells with `XFillRectangle` (background) and `XDrawString` (glyph).
|
||||
The 6×13 metrics are measured, not assumed. A full redraw is 80×24 cells.
|
||||
|
||||
Input: `XSelectInput` with `KeyPressMask|KeyReleaseMask|ButtonPressMask|
|
||||
StructureNotifyMask|FocusChangeMask`; the event loop drains `XNextEvent`;
|
||||
`XLookupString` gives the character/keysym. Arrow keys become `ESC [ A..D` for
|
||||
`game_input`; `FocusOut` pauses. **Deviation (implemented):** `ExposureMask`
|
||||
was dropped because the map-time `Expose` runs the game's full redraw before a
|
||||
piece exists and paints a bogus piece; the consequence is that an occluding
|
||||
window is not repainted. See `apps/termtris/HANDOFF.md`.
|
||||
|
||||
Timing: `now_ms()` accumulates `0x1E93C0` deltas; the idle path is
|
||||
`sleep(min(next_tick - now, 10))`, so the CPU yields to the X server and the OS.
|
||||
|
||||
## Build
|
||||
|
||||
`entry.asm` supplies the process entry and runs the `cinit` table (the 1990
|
||||
runtime's `var_init` is local, so the entry implements the 16-bit-length/32-bit-
|
||||
destination copy itself). The linker command file places `.text`/`.data`/`.cinit`
|
||||
at `0x018A0000` and `.bss` at `0x01A00000`. The build script retries the 2ine
|
||||
stage crashes (they exit 139 after producing output) and checks for outputs, not
|
||||
exit codes.
|
||||
|
||||
## Acceptance
|
||||
|
||||
In MAME, with the loader:
|
||||
- the window appears with the termtris board and score panels;
|
||||
- `A/D/S/W`, arrows, `0`/Enter, `P`, `R`, `H`, `Q`/Backspace behave as upstream;
|
||||
- a screenshot of the playfield and a short play session are captured;
|
||||
- the ROM md5 is unchanged.
|
||||
|
||||
Real unit: the same COFF can be delivered with `dwt/loader/hostload.py` once the
|
||||
OS is up; the document will state that the XG fix is required there too and that
|
||||
the real unit's X server supplies the same keycodes (LK401).
|
||||
|
||||
## Risks
|
||||
|
||||
- The 2ine toolchain intermittently segfaults after writing outputs; the builder
|
||||
retries and verifies every artifact.
|
||||
- The per-process XG block size is inferred (we used 1 KiB); if the Xlib uses
|
||||
more, enlarge the buffer. It worked through 9 events in the test.
|
||||
- `sprintf` is absent from the 1990 runtime; `compat.c` implements only the
|
||||
formats the game uses (`%d`, `%ld`, `%s`, `%c`, width, left-justify, `%%`).
|
||||
- Font metrics are the ROM default GC's 6×13; do not use a different GC/font
|
||||
without re-measuring.
|
||||
- GPLv3: the vendored tree keeps `COPYING` and the copyright headers; the repo's
|
||||
own license is unchanged.
|
||||
@@ -0,0 +1,626 @@
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 1
|
||||
|
||||
0001 ; xshow.asm -- create a 1-bit XImage and XPutImage it o
|
||||
0002 ;
|
||||
0003 ; Run as a first-class process created by the COFF load
|
||||
0004 ; in the rdebug dispatcher's context: a connect made fr
|
||||
0005 ; accepted at the service layer but the server never re
|
||||
0006 ;
|
||||
0007 ; The image is a 32x32 XYBitmap (format 0), depth 1, cr
|
||||
0008 ; XCreateImage and drawn with XPutImage. Its data is a
|
||||
0009 ; cells, written into .data at build time, so the PNG s
|
||||
0010 ; or nothing -- there is nothing to misread.
|
||||
0011 ;
|
||||
0012 ; XImage entry points used here (Ghidra address -> bit
|
||||
0013 ; 7F34092 XCreateImage(d,visual,depth,format,offset,d
|
||||
0014 ; 7FA06E XPutImage(d,drawable,gc,image,sx,sy,dx,dy,w
|
||||
0015 ; 7F341B0 XDestroyImage(image)
|
||||
0016 ; 7FAAAD6 XGetImage(d,drawable,x,y,w,h,plane_mask,for
|
||||
0017 ; (XGetImage is documented from disassembly; this probe
|
||||
0018 ;
|
||||
0019 ; Calling convention: reserve one slot with `move a14,-
|
||||
0020 ; last-to-first upward through a14, then `calla`. The
|
||||
0021 ; the return address and the reserved slot, and restore
|
||||
0022 ; sp/a14 from RAM markers (xtext.asm records that exact
|
||||
0023 ;
|
||||
0024 ; Xlib clobbers the CPU's SETF field state, so field 1
|
||||
0025 ; established after every call. a10/a11/a12 survive ev
|
||||
0026 ; a9 (the GC) survives XCreateImage and XPutImage; a7 (
|
||||
0027 ; XPutImage. XDestroyImage saves only a11/a13, so it r
|
||||
0028 ;
|
||||
0029 ; Markers:
|
||||
0030 ; 01890100 display 01890120 window 01890140 stage
|
||||
0031 ; 01890180 gc 018901A0 XPutImage return 01
|
||||
0032 ; These are the xhello-compatible cells the runner repo
|
||||
0033 ; cells sit in the heap and were overwritten after its
|
||||
0034 ; are mirrored into .bss at 018D8000h (below), which no
|
||||
0035 ; 018D8000 stage 018D8020 display 018D8040 window
|
||||
0036 ; 018D8080 image 018D80A0 putret 018D80C0 syncret
|
||||
0037 ; Stage: 1 start, 2 display, 3 window, 4 mapped, 5 gc,
|
||||
0038 ; 8 synced; 091h..097h = the step that failed.
|
||||
0039 ;
|
||||
0040 ; Scratch argument area: 01894000h (the app's own stack
|
||||
0041
|
||||
0042 00000000 .text
|
||||
0043 00000000 _start:
|
||||
0044 00000000 0550 setf 16, 0, 0
|
||||
0045 00000010 0740 setf 32, 0, 1
|
||||
0046 00000020 098F mmtm sp, a0,a1,a2,a3,a4,a5,a6,a7
|
||||
00000030 FF00
|
||||
0047
|
||||
0048 00000040 09E0 movi 1, a0, L
|
||||
00000050 00000001
|
||||
0049 00000070 0780 move a0, @01890140h, 1 ; stage = 1
|
||||
00000080 01890140
|
||||
0050 000000A0 0780 move a0, @m_stage, 1
|
||||
000000B0 00000000+
|
||||
0051
|
||||
0052 ; ---- convention check: strlen("0::0") == 4 ---------
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 2
|
||||
|
||||
0053 000000D0 A3CF move a14, -*sp, 1
|
||||
0054 000000E0 09EE movi 01894000h, a14, L
|
||||
000000F0 01894000
|
||||
0055 00000110 09E0 movi 3FACE948h, a0, L ; ROM "0::0"
|
||||
00000120 3FACE948
|
||||
0056 00000140 920E move a0, *a14+, 1
|
||||
0057 00000150 0D5F calla 3FB458D0h ; strlen
|
||||
00000160 3FB458D0
|
||||
0058 00000180 0550 setf 16, 0, 0
|
||||
0059 00000190 0740 setf 32, 0, 1
|
||||
0060 000001A0 0788 move a8, @m_strlen, 1
|
||||
000001B0 000000E0+
|
||||
0061 000001D0 09E0 movi 4, a0, L
|
||||
000001E0 00000004
|
||||
0062 00000200 4808 cmp a0, a8
|
||||
0063 00000210 CB00 jrne fail_abi
|
||||
00000220 0171
|
||||
0064
|
||||
0065 ; ---- display = XOpenDisplay("0::0") ----------------
|
||||
0066 00000230 A3CF move a14, -*sp, 1
|
||||
0067 00000240 09EE movi 01894000h, a14, L
|
||||
00000250 01894000
|
||||
0068 00000270 09E0 movi 3FACE948h, a0, L
|
||||
00000280 3FACE948
|
||||
0069 000002A0 920E move a0, *a14+, 1
|
||||
0070 000002B0 0D5F calla 3F9C2570h ; XOpenDisplay
|
||||
000002C0 3F9C2570
|
||||
0071 000002E0 0550 setf 16, 0, 0
|
||||
0072 000002F0 0740 setf 32, 0, 1
|
||||
0073 00000300 4D0B move a8, a11
|
||||
0074 00000310 078B move a11, @01890100h, 1 ; MARK display
|
||||
00000320 01890100
|
||||
0075 00000340 078B move a11, @m_display, 1
|
||||
00000350 00000020+
|
||||
0076 00000370 4D6B move a11, a11
|
||||
0077 00000380 CA00 jreq fail_open
|
||||
00000390 015E
|
||||
0078 000003A0 09E0 movi 2, a0, L
|
||||
000003B0 00000002
|
||||
0079 000003D0 0780 move a0, @01890140h, 1 ; stage = 2
|
||||
000003E0 01890140
|
||||
0080 00000400 0780 move a0, @m_stage, 1
|
||||
00000410 00000000+
|
||||
0081
|
||||
0082 ; ---- root = *(*(display+0x480)+0x40) ---------------
|
||||
0083 00000430 B76A move *a11(0480h), a10, 1
|
||||
00000440 0480
|
||||
0084 00000450 B74A move *a10(040h), a10, 1
|
||||
00000460 0040
|
||||
0085
|
||||
0086 ; ---- window = XCreateSimpleWindow(d,root,100,100,400
|
||||
0087 ; white background (pixel 1), black border, so a black
|
||||
0088 00000470 A3CF move a14, -*sp, 1
|
||||
0089 00000480 09EE movi 01894000h, a14, L
|
||||
00000490 01894000
|
||||
0090 000004B0 09E0 movi 1, a0, L
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 3
|
||||
|
||||
000004C0 00000001
|
||||
0091 000004E0 920E move a0, *a14+, 1 ; background = 1 (white)
|
||||
0092 000004F0 09E0 movi 0, a0, L
|
||||
00000500 00000000
|
||||
0093 00000520 920E move a0, *a14+, 1 ; border = 0 (black)
|
||||
0094 00000530 09E0 movi 2, a0, L
|
||||
00000540 00000002
|
||||
0095 00000560 920E move a0, *a14+, 1 ; border width
|
||||
0096 00000570 09E0 movi 200, a0, L
|
||||
00000580 000000C8
|
||||
0097 000005A0 920E move a0, *a14+, 1 ; height
|
||||
0098 000005B0 09E0 movi 400, a0, L
|
||||
000005C0 00000190
|
||||
0099 000005E0 920E move a0, *a14+, 1 ; width
|
||||
0100 000005F0 09E0 movi 100, a0, L
|
||||
00000600 00000064
|
||||
0101 00000620 920E move a0, *a14+, 1 ; y
|
||||
0102 00000630 920E move a0, *a14+, 1 ; x
|
||||
0103 00000640 934E move a10, *a14+, 1 ; parent = root
|
||||
0104 00000650 936E move a11, *a14+, 1 ; display
|
||||
0105 00000660 0D5F calla 3FD41B90h ; XCreateSimpleWindow
|
||||
00000670 3FD41B90
|
||||
0106 00000690 0550 setf 16, 0, 0
|
||||
0107 000006A0 0740 setf 32, 0, 1
|
||||
0108 000006B0 4D0A move a8, a10
|
||||
0109 000006C0 078A move a10, @01890120h, 1 ; MARK window
|
||||
000006D0 01890120
|
||||
0110 000006F0 078A move a10, @m_window, 1
|
||||
00000700 00000040+
|
||||
0111 00000720 4D4A move a10, a10
|
||||
0112 00000730 CA00 jreq fail_win
|
||||
00000740 0127
|
||||
0113 00000750 09E0 movi 3, a0, L
|
||||
00000760 00000003
|
||||
0114 00000780 0780 move a0, @01890140h, 1 ; stage = 3
|
||||
00000790 01890140
|
||||
0115 000007B0 0780 move a0, @m_stage, 1
|
||||
000007C0 00000000+
|
||||
0116
|
||||
0117 ; ---- XMapWindow(display, window) -------------------
|
||||
0118 000007E0 A3CF move a14, -*sp, 1
|
||||
0119 000007F0 09EE movi 01894000h, a14, L
|
||||
00000800 01894000
|
||||
0120 00000820 934E move a10, *a14+, 1
|
||||
0121 00000830 936E move a11, *a14+, 1
|
||||
0122 00000840 0D5F calla 3FD645B0h ; XMapWindow
|
||||
00000850 3FD645B0
|
||||
0123 00000870 0550 setf 16, 0, 0
|
||||
0124 00000880 0740 setf 32, 0, 1
|
||||
0125 00000890 09E0 movi 4, a0, L
|
||||
000008A0 00000004
|
||||
0126 000008C0 0780 move a0, @01890140h, 1 ; stage = 4
|
||||
000008D0 01890140
|
||||
0127 000008F0 0780 move a0, @m_stage, 1
|
||||
00000900 00000000+
|
||||
0128
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 4
|
||||
|
||||
0129 ; ---- gc = XCreateGC(d, window, 0, NULL) ------------
|
||||
0130 00000920 A3CF move a14, -*sp, 1
|
||||
0131 00000930 09EE movi 01894000h, a14, L
|
||||
00000940 01894000
|
||||
0132 00000960 09E0 movi 0, a0, L
|
||||
00000970 00000000
|
||||
0133 00000990 920E move a0, *a14+, 1 ; values
|
||||
0134 000009A0 920E move a0, *a14+, 1 ; mask = 0
|
||||
0135 000009B0 934E move a10, *a14+, 1 ; drawable
|
||||
0136 000009C0 936E move a11, *a14+, 1 ; display
|
||||
0137 000009D0 0D5F calla 3F997000h ; XCreateGC
|
||||
000009E0 3F997000
|
||||
0138 00000A00 0550 setf 16, 0, 0
|
||||
0139 00000A10 0740 setf 32, 0, 1
|
||||
0140 00000A20 4D09 move a8, a9 ; GC
|
||||
0141 00000A30 0789 move a9, @01890180h, 1 ; MARK gc
|
||||
00000A40 01890180
|
||||
0142 00000A60 0789 move a9, @m_gc, 1
|
||||
00000A70 00000060+
|
||||
0143 00000A90 4D29 move a9, a9
|
||||
0144 00000AA0 CA00 jreq fail_gc
|
||||
00000AB0 00F4
|
||||
0145
|
||||
0146 ; ---- XSetForeground(display, gc, 0) -- draw with pen
|
||||
0147 00000AC0 A3CF move a14, -*sp, 1
|
||||
0148 00000AD0 09EE movi 01894000h, a14, L
|
||||
00000AE0 01894000
|
||||
0149 00000B00 09E0 movi 0, a0, L
|
||||
00000B10 00000000
|
||||
0150 00000B30 920E move a0, *a14+, 1 ; pixel = 0
|
||||
0151 00000B40 932E move a9, *a14+, 1 ; gc
|
||||
0152 00000B50 936E move a11, *a14+, 1 ; display
|
||||
0153 00000B60 0D5F calla 3FD99A60h ; XSetForeground
|
||||
00000B70 3FD99A60
|
||||
0154 00000B90 0550 setf 16, 0, 0
|
||||
0155 00000BA0 0740 setf 32, 0, 1
|
||||
0156 00000BB0 09E0 movi 5, a0, L
|
||||
00000BC0 00000005
|
||||
0157 00000BE0 0780 move a0, @01890140h, 1 ; stage = 5
|
||||
00000BF0 01890140
|
||||
0158 00000C10 0780 move a0, @m_stage, 1
|
||||
00000C20 00000000+
|
||||
0159
|
||||
0160 ; ---- image = XCreateImage(d, NULL, 1, XYBitmap, 0,
|
||||
0161 ; bitmap, 32, 32, 32, 0) ---
|
||||
0162 00000C40 A3CF move a14, -*sp, 1
|
||||
0163 00000C50 09EE movi 01894000h, a14, L
|
||||
00000C60 01894000
|
||||
0164 00000C80 09E0 movi 0, a0, L
|
||||
00000C90 00000000
|
||||
0165 00000CB0 920E move a0, *a14+, 1 ; bytes_per_line = 0 (let it comput
|
||||
0166 00000CC0 09E0 movi 32, a0, L
|
||||
00000CD0 00000020
|
||||
0167 00000CF0 920E move a0, *a14+, 1 ; bitmap_pad = 32
|
||||
0168 00000D00 09E0 movi 32, a0, L
|
||||
00000D10 00000020
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 5
|
||||
|
||||
0169 00000D30 920E move a0, *a14+, 1 ; height
|
||||
0170 00000D40 920E move a0, *a14+, 1 ; width
|
||||
0171 00000D50 09E0 movi BITMAP, a0, L
|
||||
00000D60 00000000"
|
||||
0172 00000D80 920E move a0, *a14+, 1 ; data
|
||||
0173 00000D90 09E0 movi 0, a0, L
|
||||
00000DA0 00000000
|
||||
0174 00000DC0 920E move a0, *a14+, 1 ; offset
|
||||
0175 00000DD0 920E move a0, *a14+, 1 ; format = 0 (XYBitmap)
|
||||
0176 00000DE0 09E0 movi 1, a0, L
|
||||
00000DF0 00000001
|
||||
0177 00000E10 920E move a0, *a14+, 1 ; depth = 1
|
||||
0178 00000E20 4400 sub a0, a0
|
||||
0179 00000E30 920E move a0, *a14+, 1 ; visual = NULL
|
||||
0180 00000E40 936E move a11, *a14+, 1 ; display
|
||||
0181 00000E50 0D5F calla 3F9A0490h ; XCreateImage
|
||||
00000E60 3F9A0490
|
||||
0182 00000E80 0550 setf 16, 0, 0
|
||||
0183 00000E90 0740 setf 32, 0, 1
|
||||
0184 00000EA0 4D07 move a8, a7 ; image (a7 survives XPutImage)
|
||||
0185 00000EB0 0788 move a8, @01890160h, 1 ; MARK image
|
||||
00000EC0 01890160
|
||||
0186 00000EE0 0788 move a8, @m_image, 1
|
||||
00000EF0 00000080+
|
||||
0187 00000F10 4D08 move a8, a8
|
||||
0188 00000F20 CA00 jreq fail_img
|
||||
00000F30 00B0
|
||||
0189 00000F40 09E0 movi 6, a0, L
|
||||
00000F50 00000006
|
||||
0190 00000F70 0780 move a0, @01890140h, 1 ; stage = 6
|
||||
00000F80 01890140
|
||||
0191 00000FA0 0780 move a0, @m_stage, 1
|
||||
00000FB0 00000000+
|
||||
0192
|
||||
0193 ; ---- let the WM frame/reparent and map the window (x
|
||||
0194 ; A draw issued before the reparent can be lost, so sy
|
||||
0195 00000FD0 09EC movi 4, a12, L
|
||||
00000FE0 00000004
|
||||
0196 00001000 map_wait:
|
||||
0197 00001000 A3CF move a14, -*sp, 1
|
||||
0198 00001010 09EE movi 01894000h, a14, L
|
||||
00001020 01894000
|
||||
0199 00001040 09E0 movi 0, a0, L
|
||||
00001050 00000000
|
||||
0200 00001070 920E move a0, *a14+, 1 ; discard = 0
|
||||
0201 00001080 936E move a11, *a14+, 1 ; display
|
||||
0202 00001090 0D5F calla 3FD9F6B0h ; XSync
|
||||
000010A0 3FD9F6B0
|
||||
0203 000010C0 0550 setf 16, 0, 0
|
||||
0204 000010D0 0740 setf 32, 0, 1
|
||||
0205 000010E0 3DEC dsjs a12, map_wait
|
||||
0206
|
||||
0207 ; ---- XPutImage(d, win, gc, image, 0,0, 20,20, 32,32)
|
||||
0208 000010F0 A3CF move a14, -*sp, 1
|
||||
0209 00001100 09EE movi 01894000h, a14, L
|
||||
00001110 01894000
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 6
|
||||
|
||||
0210 00001130 09E0 movi 32, a0, L
|
||||
00001140 00000020
|
||||
0211 00001160 920E move a0, *a14+, 1 ; h
|
||||
0212 00001170 920E move a0, *a14+, 1 ; w
|
||||
0213 00001180 09E0 movi 20, a0, L
|
||||
00001190 00000014
|
||||
0214 000011B0 920E move a0, *a14+, 1 ; dst_y
|
||||
0215 000011C0 920E move a0, *a14+, 1 ; dst_x
|
||||
0216 000011D0 4400 sub a0, a0
|
||||
0217 000011E0 920E move a0, *a14+, 1 ; src_y
|
||||
0218 000011F0 920E move a0, *a14+, 1 ; src_x
|
||||
0219 00001200 92EE move a7, *a14+, 1 ; image
|
||||
0220 00001210 932E move a9, *a14+, 1 ; gc
|
||||
0221 00001220 934E move a10, *a14+, 1 ; drawable
|
||||
0222 00001230 936E move a11, *a14+, 1 ; display
|
||||
0223 00001240 0D5F calla 3F9D0370h ; XPutImage
|
||||
00001250 3F9D0370
|
||||
0224 00001270 0550 setf 16, 0, 0
|
||||
0225 00001280 0740 setf 32, 0, 1
|
||||
0226 00001290 0788 move a8, @018901A0h, 1 ; MARK putimage return
|
||||
000012A0 018901A0
|
||||
0227 000012C0 0788 move a8, @m_putret, 1
|
||||
000012D0 000000A0+
|
||||
0228 000012F0 09E0 movi 7, a0, L
|
||||
00001300 00000007
|
||||
0229 00001320 0780 move a0, @01890140h, 1 ; stage = 7
|
||||
00001330 01890140
|
||||
0230 00001350 0780 move a0, @m_stage, 1
|
||||
00001360 00000000+
|
||||
0231
|
||||
0232 ; ---- control: the same image with h = 16 at dst_y =
|
||||
0233 ; The PNG must show exactly 16 rows here (src rows 0..
|
||||
0234 ; what proves the 32-row draw above is the image, not
|
||||
0235 00001380 A3CF move a14, -*sp, 1
|
||||
0236 00001390 09EE movi 01894000h, a14, L
|
||||
000013A0 01894000
|
||||
0237 000013C0 09E0 movi 16, a0, L
|
||||
000013D0 00000010
|
||||
0238 000013F0 920E move a0, *a14+, 1 ; h = 16
|
||||
0239 00001400 09E0 movi 32, a0, L
|
||||
00001410 00000020
|
||||
0240 00001430 920E move a0, *a14+, 1 ; w = 32
|
||||
0241 00001440 09E0 movi 60, a0, L
|
||||
00001450 0000003C
|
||||
0242 00001470 920E move a0, *a14+, 1 ; dst_y = 60
|
||||
0243 00001480 09E0 movi 20, a0, L
|
||||
00001490 00000014
|
||||
0244 000014B0 920E move a0, *a14+, 1 ; dst_x = 20
|
||||
0245 000014C0 4400 sub a0, a0
|
||||
0246 000014D0 920E move a0, *a14+, 1 ; src_y = 0
|
||||
0247 000014E0 920E move a0, *a14+, 1 ; src_x = 0
|
||||
0248 000014F0 92EE move a7, *a14+, 1 ; image
|
||||
0249 00001500 932E move a9, *a14+, 1 ; gc
|
||||
0250 00001510 934E move a10, *a14+, 1 ; drawable
|
||||
0251 00001520 936E move a11, *a14+, 1 ; display
|
||||
0252 00001530 0D5F calla 3F9D0370h ; XPutImage
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 7
|
||||
|
||||
00001540 3F9D0370
|
||||
0253 00001560 0550 setf 16, 0, 0
|
||||
0254 00001570 0740 setf 32, 0, 1
|
||||
0255
|
||||
0256 ; ---- flush, twice: the request is only in the client
|
||||
0257 00001580 A3CF move a14, -*sp, 1
|
||||
0258 00001590 09EE movi 01894000h, a14, L
|
||||
000015A0 01894000
|
||||
0259 000015C0 09E0 movi 0, a0, L
|
||||
000015D0 00000000
|
||||
0260 000015F0 920E move a0, *a14+, 1
|
||||
0261 00001600 936E move a11, *a14+, 1
|
||||
0262 00001610 0D5F calla 3FD9F6B0h ; XSync
|
||||
00001620 3FD9F6B0
|
||||
0263 00001640 0550 setf 16, 0, 0
|
||||
0264 00001650 0740 setf 32, 0, 1
|
||||
0265 00001660 0788 move a8, @018901C0h, 1 ; MARK sync return
|
||||
00001670 018901C0
|
||||
0266 00001690 0788 move a8, @m_syncret, 1
|
||||
000016A0 000000C0+
|
||||
0267
|
||||
0268 000016C0 A3CF move a14, -*sp, 1
|
||||
0269 000016D0 09EE movi 01894000h, a14, L
|
||||
000016E0 01894000
|
||||
0270 00001700 09E0 movi 0, a0, L
|
||||
00001710 00000000
|
||||
0271 00001730 920E move a0, *a14+, 1
|
||||
0272 00001740 936E move a11, *a14+, 1
|
||||
0273 00001750 0D5F calla 3FD9F6B0h ; XSync
|
||||
00001760 3FD9F6B0
|
||||
0274 00001780 0550 setf 16, 0, 0
|
||||
0275 00001790 0740 setf 32, 0, 1
|
||||
0276 000017A0 0788 move a8, @018901C0h, 1
|
||||
000017B0 018901C0
|
||||
0277 000017D0 0788 move a8, @m_syncret, 1
|
||||
000017E0 000000C0+
|
||||
0278
|
||||
0279 00001800 09E0 movi 8, a0, L
|
||||
00001810 00000008
|
||||
0280 00001830 0780 move a0, @01890140h, 1 ; stage = 8
|
||||
00001840 01890140
|
||||
0281 00001860 0780 move a0, @m_stage, 1
|
||||
00001870 00000000+
|
||||
0282
|
||||
0283 ; ---- XDestroyImage(image) --------------------------
|
||||
0284 00001890 A3CF move a14, -*sp, 1
|
||||
0285 000018A0 09EE movi 01894000h, a14, L
|
||||
000018B0 01894000
|
||||
0286 000018D0 92EE move a7, *a14+, 1
|
||||
0287 000018E0 0D5F calla 3F9A0D80h ; XDestroyImage
|
||||
000018F0 3F9A0D80
|
||||
0288 00001910 0550 setf 16, 0, 0
|
||||
0289 00001920 0740 setf 32, 0, 1
|
||||
0290 00001930 C01A jruc done
|
||||
0291
|
||||
0292 00001940 fail_abi:
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 8
|
||||
|
||||
0293 00001940 09E0 movi 091h, a0, L
|
||||
00001950 00000091
|
||||
0294 00001970 C010 jruc failed
|
||||
0295 00001980 fail_open:
|
||||
0296 00001980 09E0 movi 092h, a0, L
|
||||
00001990 00000092
|
||||
0297 000019B0 C00C jruc failed
|
||||
0298 000019C0 fail_win:
|
||||
0299 000019C0 09E0 movi 093h, a0, L
|
||||
000019D0 00000093
|
||||
0300 000019F0 C008 jruc failed
|
||||
0301 00001A00 fail_gc:
|
||||
0302 00001A00 09E0 movi 095h, a0, L
|
||||
00001A10 00000095
|
||||
0303 00001A30 C004 jruc failed
|
||||
0304 00001A40 fail_img:
|
||||
0305 00001A40 09E0 movi 096h, a0, L
|
||||
00001A50 00000096
|
||||
0306 00001A70 0300 jruc failed
|
||||
0307 00001A80 failed:
|
||||
0308 00001A80 0780 move a0, @01890140h, 1
|
||||
00001A90 01890140
|
||||
0309 00001AB0 0780 move a0, @m_stage, 1
|
||||
00001AC0 00000000+
|
||||
0310
|
||||
0311 00001AE0 done:
|
||||
0312 00001AE0 09AF mmfm sp, a0,a1,a2,a3,a4,a5,a6,a7
|
||||
00001AF0 00FF
|
||||
0313 00001B00 09E8 movi 0, a8, L
|
||||
00001B10 00000000
|
||||
0314 00001B30 0960 rets
|
||||
0315
|
||||
0316 00000000 .data
|
||||
0317 ; 32 rows of 4 bytes, LSB-first pixels: a solid row at
|
||||
0318 ; at y=31, and a one-pixel diagonal between them. The
|
||||
0319 ; rows make the drawn height readable straight off the
|
||||
0320 00000000 BITMAP:
|
||||
0321 00000000 FF .byte 0FFh, 0FFh, 0FFh, 0FFh, 002h, 000h, 000h, 000h
|
||||
00000008 FF
|
||||
00000010 FF
|
||||
00000018 FF
|
||||
00000020 02
|
||||
00000028 00
|
||||
00000030 00
|
||||
00000038 00
|
||||
0322 00000040 04 .byte 004h, 000h, 000h, 000h, 008h, 000h, 000h, 000h
|
||||
00000048 00
|
||||
00000050 00
|
||||
00000058 00
|
||||
00000060 08
|
||||
00000068 00
|
||||
00000070 00
|
||||
00000078 00
|
||||
0323 00000080 10 .byte 010h, 000h, 000h, 000h, 020h, 000h, 000h, 000h
|
||||
00000088 00
|
||||
00000090 00
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 9
|
||||
|
||||
00000098 00
|
||||
000000A0 20
|
||||
000000A8 00
|
||||
000000B0 00
|
||||
000000B8 00
|
||||
0324 000000C0 40 .byte 040h, 000h, 000h, 000h, 080h, 000h, 000h, 000h
|
||||
000000C8 00
|
||||
000000D0 00
|
||||
000000D8 00
|
||||
000000E0 80
|
||||
000000E8 00
|
||||
000000F0 00
|
||||
000000F8 00
|
||||
0325 00000100 00 .byte 000h, 001h, 000h, 000h, 000h, 002h, 000h, 000h
|
||||
00000108 01
|
||||
00000110 00
|
||||
00000118 00
|
||||
00000120 00
|
||||
00000128 02
|
||||
00000130 00
|
||||
00000138 00
|
||||
0326 00000140 00 .byte 000h, 004h, 000h, 000h, 000h, 008h, 000h, 000h
|
||||
00000148 04
|
||||
00000150 00
|
||||
00000158 00
|
||||
00000160 00
|
||||
00000168 08
|
||||
00000170 00
|
||||
00000178 00
|
||||
0327 00000180 00 .byte 000h, 010h, 000h, 000h, 000h, 020h, 000h, 000h
|
||||
00000188 10
|
||||
00000190 00
|
||||
00000198 00
|
||||
000001A0 00
|
||||
000001A8 20
|
||||
000001B0 00
|
||||
000001B8 00
|
||||
0328 000001C0 00 .byte 000h, 040h, 000h, 000h, 000h, 080h, 000h, 000h
|
||||
000001C8 40
|
||||
000001D0 00
|
||||
000001D8 00
|
||||
000001E0 00
|
||||
000001E8 80
|
||||
000001F0 00
|
||||
000001F8 00
|
||||
0329 00000200 00 .byte 000h, 000h, 001h, 000h, 000h, 000h, 002h, 000h
|
||||
00000208 00
|
||||
00000210 01
|
||||
00000218 00
|
||||
00000220 00
|
||||
00000228 00
|
||||
00000230 02
|
||||
00000238 00
|
||||
0330 00000240 00 .byte 000h, 000h, 004h, 000h, 000h, 000h, 008h, 000h
|
||||
00000248 00
|
||||
00000250 04
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 10
|
||||
|
||||
00000258 00
|
||||
00000260 00
|
||||
00000268 00
|
||||
00000270 08
|
||||
00000278 00
|
||||
0331 00000280 00 .byte 000h, 000h, 010h, 000h, 000h, 000h, 020h, 000h
|
||||
00000288 00
|
||||
00000290 10
|
||||
00000298 00
|
||||
000002A0 00
|
||||
000002A8 00
|
||||
000002B0 20
|
||||
000002B8 00
|
||||
0332 000002C0 00 .byte 000h, 000h, 040h, 000h, 000h, 000h, 080h, 000h
|
||||
000002C8 00
|
||||
000002D0 40
|
||||
000002D8 00
|
||||
000002E0 00
|
||||
000002E8 00
|
||||
000002F0 80
|
||||
000002F8 00
|
||||
0333 00000300 00 .byte 000h, 000h, 000h, 001h, 000h, 000h, 000h, 002h
|
||||
00000308 00
|
||||
00000310 00
|
||||
00000318 01
|
||||
00000320 00
|
||||
00000328 00
|
||||
00000330 00
|
||||
00000338 02
|
||||
0334 00000340 00 .byte 000h, 000h, 000h, 004h, 000h, 000h, 000h, 008h
|
||||
00000348 00
|
||||
00000350 00
|
||||
00000358 04
|
||||
00000360 00
|
||||
00000368 00
|
||||
00000370 00
|
||||
00000378 08
|
||||
0335 00000380 00 .byte 000h, 000h, 000h, 010h, 000h, 000h, 000h, 020h
|
||||
00000388 00
|
||||
00000390 00
|
||||
00000398 10
|
||||
000003A0 00
|
||||
000003A8 00
|
||||
000003B0 00
|
||||
000003B8 20
|
||||
0336 000003C0 00 .byte 000h, 000h, 000h, 040h, 0FFh, 0FFh, 0FFh, 0FFh
|
||||
000003C8 00
|
||||
000003D0 00
|
||||
000003D8 40
|
||||
000003E0 FF
|
||||
000003E8 FF
|
||||
000003F0 FF
|
||||
000003F8 FF
|
||||
0337 00000400 BITMAP_END:
|
||||
0338
|
||||
0339 00000000 .bss m_stage, 32, 1
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 11
|
||||
|
||||
0340 00000020 .bss m_display, 32, 1
|
||||
0341 00000040 .bss m_window, 32, 1
|
||||
0342 00000060 .bss m_gc, 32, 1
|
||||
0343 00000080 .bss m_image, 32, 1
|
||||
0344 000000A0 .bss m_putret, 32, 1
|
||||
0345 000000C0 .bss m_syncret, 32, 1
|
||||
0346 000000E0 .bss m_strlen, 32, 1
|
||||
0347
|
||||
0348 .end
|
||||
|
||||
No Errors, No Warnings
|
||||
@@ -0,0 +1,36 @@
|
||||
*****************************************************
|
||||
GSP COFF Linker, Version 2.00, 87.300
|
||||
*****************************************************
|
||||
Fri Nov 13 09:31:54 2026
|
||||
|
||||
OUTPUT FILE NAME: <XSHOW.out>
|
||||
ENTRY POINT SYMBOL: 0
|
||||
|
||||
|
||||
SECTION ALLOCATION MAP
|
||||
|
||||
output attributes/
|
||||
section page origin length input sections
|
||||
-------- ---- ---------- ---------- ----------------
|
||||
.text 0 01840000 00001B40
|
||||
01840000 00001B40 XSHOW.obj (.text)
|
||||
|
||||
.data 0 018D0000 00000400
|
||||
018D0000 00000400 XSHOW.obj (.data)
|
||||
|
||||
.bss 0 018D8000 00000100 UNINITIALIZED
|
||||
018D8000 00000100 XSHOW.obj (.bss)
|
||||
|
||||
|
||||
GLOBAL SYMBOLS
|
||||
|
||||
address name address name
|
||||
-------- ---- -------- ----
|
||||
018D8000 .bss 01840000 .text
|
||||
018D0000 .data 01841B40 etext
|
||||
01840000 .text 018D0000 .data
|
||||
018D0400 edata 018D0400 edata
|
||||
018D8100 end 018D8000 .bss
|
||||
01841B40 etext 018D8100 end
|
||||
|
||||
[6 symbols]
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Print a region of an 8-bit PNG as ASCII, one screen row per line.
|
||||
|
||||
The evidence PNGs are captured by MAME under -video none, so there is no
|
||||
ImageMagick/PIL dependency here: this decodes the PNG with zlib directly
|
||||
(non-interlaced, 8-bit grey/RGB/RGBA only) and prints '#' for dark pixels.
|
||||
|
||||
Usage:
|
||||
python3 dwt/gui/evidence/png_rows.py PNG X Y W H
|
||||
"""
|
||||
import struct
|
||||
import sys
|
||||
import zlib
|
||||
|
||||
|
||||
def read_png(path):
|
||||
data = open(path, "rb").read()
|
||||
if data[:8] != b"\x89PNG\r\n\x1a\n":
|
||||
raise SystemExit("not a PNG: " + path)
|
||||
off, idat = 8, b""
|
||||
w = h = bitdepth = colour = None
|
||||
while off < len(data):
|
||||
length = struct.unpack(">I", data[off:off + 4])[0]
|
||||
kind = data[off + 4:off + 8]
|
||||
chunk = data[off + 8:off + 8 + length]
|
||||
off += 12 + length
|
||||
if kind == b"IHDR":
|
||||
w, h, bitdepth, colour, _, _, interlace = struct.unpack(">IIBBBBB", chunk)
|
||||
if bitdepth != 8 or interlace != 0:
|
||||
raise SystemExit("only 8-bit non-interlaced PNGs")
|
||||
elif kind == b"IDAT":
|
||||
idat += chunk
|
||||
elif kind == b"IEND":
|
||||
break
|
||||
bpp = {0: 1, 2: 3, 4: 2, 6: 4}[colour]
|
||||
stride = w * bpp
|
||||
raw = zlib.decompress(idat)
|
||||
out = bytearray(h * stride)
|
||||
prev = bytearray(stride)
|
||||
pos = 0
|
||||
for y in range(h):
|
||||
filt = raw[pos]
|
||||
pos += 1
|
||||
line = bytearray(raw[pos:pos + stride])
|
||||
pos += stride
|
||||
if filt == 1:
|
||||
for i in range(bpp, stride):
|
||||
line[i] = (line[i] + line[i - bpp]) & 0xFF
|
||||
elif filt == 2:
|
||||
for i in range(stride):
|
||||
line[i] = (line[i] + prev[i]) & 0xFF
|
||||
elif filt == 3:
|
||||
for i in range(stride):
|
||||
left = line[i - bpp] if i >= bpp else 0
|
||||
line[i] = (line[i] + ((left + prev[i]) >> 1)) & 0xFF
|
||||
elif filt == 4:
|
||||
for i in range(stride):
|
||||
left = line[i - bpp] if i >= bpp else 0
|
||||
up = prev[i]
|
||||
upleft = prev[i - bpp] if i >= bpp else 0
|
||||
p = left + up - upleft
|
||||
pa, pb, pc = abs(p - left), abs(p - up), abs(p - upleft)
|
||||
pred = left if (pa <= pb and pa <= pc) else (up if pb <= pc else upleft)
|
||||
line[i] = (line[i] + pred) & 0xFF
|
||||
out[y * stride:(y + 1) * stride] = line
|
||||
prev = line
|
||||
return w, h, bpp, bytes(out)
|
||||
|
||||
|
||||
def main():
|
||||
path, x0, y0, cw, ch = sys.argv[1], *map(int, sys.argv[2:6])
|
||||
w, _, bpp, px = read_png(path)
|
||||
for y in range(y0, y0 + ch):
|
||||
row = "".join("#" if px[(y * w + x) * bpp] < 128 else "." for x in range(x0, x0 + cw))
|
||||
print("%4d %s" % (y, row))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,75 @@
|
||||
# xshow_frame2650.png, decoded with: python3 dwt/gui/evidence/png_rows.py dwt/gui/evidence/xshow_frame2650.png 118 118 40 64
|
||||
# window content origin is screen (102,102): XPutImage dst (20,20) -> row 122,
|
||||
# dst (20,60) -> row 162. Full 32-row image: 122..153. h=16 control: 162..177.
|
||||
|
||||
118 ........................................
|
||||
119 ........................................
|
||||
120 ........................................
|
||||
121 ........................................
|
||||
122 ....################################....
|
||||
123 .....#..................................
|
||||
124 ......#.................................
|
||||
125 .......#................................
|
||||
126 ........#...............................
|
||||
127 .........#..............................
|
||||
128 ..........#.............................
|
||||
129 ...........#............................
|
||||
130 ............#...........................
|
||||
131 .............#..........................
|
||||
132 ..............#.........................
|
||||
133 ...............#........................
|
||||
134 ................#.......................
|
||||
135 .................#......................
|
||||
136 ..................#.....................
|
||||
137 ...................#....................
|
||||
138 ....................#...................
|
||||
139 .....................#..................
|
||||
140 ......................#.................
|
||||
141 .......................#................
|
||||
142 ........................#...............
|
||||
143 .........................#..............
|
||||
144 ..........................#.............
|
||||
145 ...........................#............
|
||||
146 ............................#...........
|
||||
147 .............................#..........
|
||||
148 ..............................#.........
|
||||
149 ...............................#........
|
||||
150 ................................#.......
|
||||
151 .................................#......
|
||||
152 ..................................#.....
|
||||
153 ....################################....
|
||||
154 ........................................
|
||||
155 ........................................
|
||||
156 ........................................
|
||||
157 ........................................
|
||||
158 ........................................
|
||||
159 ........................................
|
||||
160 ........................................
|
||||
161 ........................................
|
||||
162 ....################################....
|
||||
163 .....#..................................
|
||||
164 ......#.................................
|
||||
165 .......#................................
|
||||
166 ........#...............................
|
||||
167 .........#..............................
|
||||
168 ..........#.............................
|
||||
169 ...........#............................
|
||||
170 ............#...........................
|
||||
171 .............#..........................
|
||||
172 ..............#.........................
|
||||
173 ...............#........................
|
||||
174 ................#.......................
|
||||
175 .................#......................
|
||||
176 ..................#.....................
|
||||
177 ...................#....................
|
||||
178 ........................................
|
||||
179 ........................................
|
||||
180 ........................................
|
||||
181 ........................................
|
||||
|
||||
# second observation, 30 frames later: the same rows, byte-identical PNG
|
||||
$ python3 dwt/gui/evidence/png_rows.py dwt/gui/evidence/xshow_frame2680.png 118 118 40 64 | diff - <(python3 dwt/gui/evidence/png_rows.py dwt/gui/evidence/xshow_frame2650.png 118 118 40 64)
|
||||
(no output: identical)
|
||||
$ md5sum dwt/gui/evidence/xshow_frame2650.png dwt/gui/evidence/xshow_frame2680.png
|
||||
ab9d63844aa5a3dd9d281a6bee3c76c2 dwt/gui/evidence/xshow_frame2650.png
|
||||
ab9d63844aa5a3dd9d281a6bee3c76c2 dwt/gui/evidence/xshow_frame2680.png
|
||||
@@ -0,0 +1,37 @@
|
||||
Warning: -video none doesn't make much sense without -seconds_to_run
|
||||
ALSA lib seq_hw.c:540:(snd_seq_hw_open) open /dev/snd/seq failed: No such file or directory
|
||||
vt1200: screen_update#1 frame=0 clip_y=0..0 screen=1280x901
|
||||
XSHOW: payload dwt/loader/build/loader.bin (1220 B) -> bit 01880000
|
||||
XSHOW: COFF dwt/gui/build/xshow.coff (1384 B) -> bit 01900000
|
||||
XSHOW: file magic=0090 nscns=3 opthdr=28 entry=00000000 textstart=01840000
|
||||
XSHOW: sec .text paddr=01840000 size=6976 bits (872 B) flags=0x20
|
||||
XSHOW: sec .data paddr=018D0000 size=1024 bits (128 B) flags=0x40
|
||||
XSHOW: sec .bss paddr=018D8000 size=256 bits (32 B) flags=0x80
|
||||
XSHOW: .data first 16 bytes: FF FF FF FF 02 00 00 00 04 00 00 00 08 00 00 00
|
||||
vt1200: screen_update#2 frame=0 clip_y=1..900 screen=1280x901
|
||||
vt1200: scanline#1 line=1 enabled=1
|
||||
vt1200: guard#1 frame=0 dump_frame=-1 dump_ram=-1
|
||||
vt1200: screen_update#3 frame=1 clip_y=0..0 screen=1280x901
|
||||
vt1200: scanline#2 line=0 enabled=1
|
||||
vt1200: screen_update#4 frame=1 clip_y=1..1 screen=1280x901
|
||||
vt1200: scanline#3 line=1 enabled=1
|
||||
vt1200: scanline#4 line=2 enabled=1
|
||||
XSHOW: loader poked 610 words, readback 0 bad at 01880000
|
||||
XSHOW: COFF poked 692 words, readback 0 bad at 01900000
|
||||
XSHOW: descriptor @01882C00 magic=4C44/5231 buf=01900000 len=1384 mode=0
|
||||
XSHOW: will resume at 3F579970 after create_process
|
||||
XSHOW: frame 2500: entered loader at 01880000 (caller SP=007F52B0)
|
||||
XSHOW: f2540 cells stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001
|
||||
XSHOW: f2540 mirror stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001 strlen=00000004
|
||||
XSHOW: f2650 cells stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001
|
||||
XSHOW: f2650 mirror stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001 strlen=00000004
|
||||
XSHOW: snapshot /home/arti/.t3/worktrees/vt1200/fix-issue-4-ximage-4368fd1dbccf74ec/dwt/gui/evidence/xshow_frame2650.png ok=true
|
||||
XSHOW: final cells stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001
|
||||
XSHOW: final mirror stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001 strlen=00000004
|
||||
XSHOW: loader status=0 entry=01840000 text=01840000/6976 bits
|
||||
XSHOW: PC at exit = 3F5799D0
|
||||
XSHOW: final image@00988130 width=00000020 height=00000020 xoffset=00000000 format=00000000 data=018D0000 byte_order=00000000 bitmap_unit=00000020 bitmap_bit_order=00000000 bitmap_pad=00000020 depth=00000001 bytes_per_line=00000004 bits_per_pixel=00000001
|
||||
XSHOW: final dpy@0093C910 byte_order=00000000 bitmap_unit=00000020 scanline_pad=00000020 bitmap_bit_order=00000000
|
||||
XSHOW: final pixmap_formats n=1 list=00367D90
|
||||
XSHOW: final fmt[0] depth=00000001 bits_per_pixel=00000001 pad=00000020
|
||||
Average speed: 111.50% (37 seconds)
|
||||
@@ -14,7 +14,8 @@
|
||||
-- 3F3F4680 authorisation check
|
||||
-- 3F706A40 create_process
|
||||
-- 3FD41B90 XCreateSimpleWindow
|
||||
-- 3FD645B0 XMapWindow
|
||||
-- 3FD645B0 XRaiseWindow (ConfigureWindow/CWStackMode; does not map)
|
||||
-- 3FD64F60 XMapWindow
|
||||
-- 3FD9F6B0 XSync
|
||||
--
|
||||
-- Also snapshots frames on a trigger file: "<prefix> <count> <stride>".
|
||||
@@ -138,7 +139,7 @@ local function arm()
|
||||
cmd('bpset 3F706A40,,{ printf "TR CREATE_PROC entry entryarg=%08X nameptr=%08X proc=%08X\\n", d@(a14-32), d@(a14-64), d@0x1b3900 ; g }')
|
||||
-- window calls
|
||||
cmd('bpset 3FD41B90,,{ printf "TR CreateSimpleWindow\\n" ; g }')
|
||||
cmd('bpset 3FD645B0,,{ printf "TR MapWindow\\n" ; g }')
|
||||
cmd('bpset 3FD645B0,,{ printf "TR RaiseWindow\\n" ; g }')
|
||||
cmd('bpset 3FD9F6B0,,{ printf "TR XSync\\n" ; g }')
|
||||
-- xhello progress is tracked through its relocated markers (0189xxxx);
|
||||
-- the code offsets moved when the setf fix was inserted, so no bpsets here.
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
; Xlib entry points (Ghidra address -> bit address):
|
||||
; 7F384AE XOpenDisplay(name) -> 3F9C2570
|
||||
; 7FA8372 XCreateSimpleWindow(...) -> 3FD41B90
|
||||
; 7FAC8B6 XMapWindow(display,window) -> 3FD645B0
|
||||
; 7FAC8B6 XRaiseWindow(display,window) -> 3FD645B0 (does NOT map)
|
||||
; 7FB3ED6 XSync(display,discard) -> 3FD9F6B0
|
||||
; 7F68B1A strlen(s) -> 3FB458D0 (convention check)
|
||||
;
|
||||
@@ -116,12 +116,14 @@ _start:
|
||||
movi 4, a0, L
|
||||
move a0, @01890140h, 1
|
||||
|
||||
; ---- XMapWindow(display, window) ------------------------------
|
||||
; ---- XRaiseWindow(display, window) ----------------------------
|
||||
; ConfigureWindow with CWStackMode=Above: raises an already-mapped
|
||||
; window. It does NOT map it -- XMapWindow is 3FD64F60.
|
||||
move a14, -*sp, 1
|
||||
movi 01892000h, a14, L
|
||||
move a10, *a14+, 1 ; window
|
||||
move a11, *a14+, 1 ; display
|
||||
calla 3FD645B0h ; XMapWindow
|
||||
calla 3FD645B0h ; XRaiseWindow
|
||||
move @01890420h, sp, 1
|
||||
move @01890400h, a14, 1
|
||||
setf 16, 0, 0
|
||||
|
||||
@@ -0,0 +1,348 @@
|
||||
; xshow.asm -- create a 1-bit XImage and XPutImage it onto a mapped window.
|
||||
;
|
||||
; Run as a first-class process created by the COFF loader (create_process), NOT
|
||||
; in the rdebug dispatcher's context: a connect made from the rdebug process is
|
||||
; accepted at the service layer but the server never reads the X11 setup.
|
||||
;
|
||||
; The image is a 32x32 XYBitmap (format 0), depth 1, created by the ROM's own
|
||||
; XCreateImage and drawn with XPutImage. Its data is a checkerboard of 8x8
|
||||
; cells, written into .data at build time, so the PNG shows either the pattern
|
||||
; or nothing -- there is nothing to misread.
|
||||
;
|
||||
; XImage entry points used here (Ghidra address -> bit address):
|
||||
; 7F34092 XCreateImage(d,visual,depth,format,offset,data,w,h,pad,bpl) 3F9A0490
|
||||
; 7FA06E XPutImage(d,drawable,gc,image,sx,sy,dx,dy,w,h) 3F9D0370
|
||||
; 7F341B0 XDestroyImage(image) 3F9A0D80
|
||||
; 7FAAAD6 XGetImage(d,drawable,x,y,w,h,plane_mask,format) 3FD556B0
|
||||
; (XGetImage is documented from disassembly; this probe does not call it.)
|
||||
;
|
||||
; Calling convention: reserve one slot with `move a14,-*sp,1`, push arguments
|
||||
; last-to-first upward through a14, then `calla`. The callee's `rets 2` pops
|
||||
; the return address and the reserved slot, and restores a14. Do NOT reload
|
||||
; sp/a14 from RAM markers (xtext.asm records that exact crash).
|
||||
;
|
||||
; Xlib clobbers the CPU's SETF field state, so field 1 (32-bit) is re-
|
||||
; established after every call. a10/a11/a12 survive every call used here;
|
||||
; a9 (the GC) survives XCreateImage and XPutImage; a7 (the image) survives
|
||||
; XPutImage. XDestroyImage saves only a11/a13, so it runs last.
|
||||
;
|
||||
; Markers:
|
||||
; 01890100 display 01890120 window 01890140 stage 01890160 image
|
||||
; 01890180 gc 018901A0 XPutImage return 018901C0 last XSync
|
||||
; These are the xhello-compatible cells the runner reports. xhello's own
|
||||
; cells sit in the heap and were overwritten after its run, so the same values
|
||||
; are mirrored into .bss at 018D8000h (below), which nothing else uses:
|
||||
; 018D8000 stage 018D8020 display 018D8040 window 018D8060 gc
|
||||
; 018D8080 image 018D80A0 putret 018D80C0 syncret 018D80E0 strlen
|
||||
; Stage: 1 start, 2 display, 3 window, 4 mapped, 5 gc, 6 image, 7 putimage,
|
||||
; 8 synced; 091h..097h = the step that failed.
|
||||
;
|
||||
; Scratch argument area: 01894000h (the app's own stack is elsewhere).
|
||||
|
||||
.text
|
||||
_start:
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
mmtm sp, a0,a1,a2,a3,a4,a5,a6,a7
|
||||
|
||||
movi 1, a0, L
|
||||
move a0, @01890140h, 1 ; stage = 1
|
||||
move a0, @m_stage, 1
|
||||
|
||||
; ---- convention check: strlen("0::0") == 4 --------------------
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 3FACE948h, a0, L ; ROM "0::0"
|
||||
move a0, *a14+, 1
|
||||
calla 3FB458D0h ; strlen
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
move a8, @m_strlen, 1
|
||||
movi 4, a0, L
|
||||
cmp a0, a8
|
||||
jrne fail_abi
|
||||
|
||||
; ---- display = XOpenDisplay("0::0") ---------------------------
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 3FACE948h, a0, L
|
||||
move a0, *a14+, 1
|
||||
calla 3F9C2570h ; XOpenDisplay
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
move a8, a11
|
||||
move a11, @01890100h, 1 ; MARK display
|
||||
move a11, @m_display, 1
|
||||
move a11, a11
|
||||
jreq fail_open
|
||||
movi 2, a0, L
|
||||
move a0, @01890140h, 1 ; stage = 2
|
||||
move a0, @m_stage, 1
|
||||
|
||||
; ---- root = *(*(display+0x480)+0x40) --------------------------
|
||||
move *a11(0480h), a10, 1
|
||||
move *a10(040h), a10, 1
|
||||
|
||||
; ---- window = XCreateSimpleWindow(d,root,100,100,400,200,2,0,1)
|
||||
; white background (pixel 1), black border, so a black bitmap shows.
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 1, a0, L
|
||||
move a0, *a14+, 1 ; background = 1 (white)
|
||||
movi 0, a0, L
|
||||
move a0, *a14+, 1 ; border = 0 (black)
|
||||
movi 2, a0, L
|
||||
move a0, *a14+, 1 ; border width
|
||||
movi 200, a0, L
|
||||
move a0, *a14+, 1 ; height
|
||||
movi 400, a0, L
|
||||
move a0, *a14+, 1 ; width
|
||||
movi 100, a0, L
|
||||
move a0, *a14+, 1 ; y
|
||||
move a0, *a14+, 1 ; x
|
||||
move a10, *a14+, 1 ; parent = root
|
||||
move a11, *a14+, 1 ; display
|
||||
calla 3FD41B90h ; XCreateSimpleWindow
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
move a8, a10
|
||||
move a10, @01890120h, 1 ; MARK window
|
||||
move a10, @m_window, 1
|
||||
move a10, a10
|
||||
jreq fail_win
|
||||
movi 3, a0, L
|
||||
move a0, @01890140h, 1 ; stage = 3
|
||||
move a0, @m_stage, 1
|
||||
|
||||
; ---- XMapWindow(display, window) -----------------------------
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
move a10, *a14+, 1
|
||||
move a11, *a14+, 1
|
||||
calla 3FD645B0h ; XMapWindow
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
movi 4, a0, L
|
||||
move a0, @01890140h, 1 ; stage = 4
|
||||
move a0, @m_stage, 1
|
||||
|
||||
; ---- gc = XCreateGC(d, window, 0, NULL) ----------------------
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 0, a0, L
|
||||
move a0, *a14+, 1 ; values
|
||||
move a0, *a14+, 1 ; mask = 0
|
||||
move a10, *a14+, 1 ; drawable
|
||||
move a11, *a14+, 1 ; display
|
||||
calla 3F997000h ; XCreateGC
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
move a8, a9 ; GC
|
||||
move a9, @01890180h, 1 ; MARK gc
|
||||
move a9, @m_gc, 1
|
||||
move a9, a9
|
||||
jreq fail_gc
|
||||
|
||||
; ---- XSetForeground(display, gc, 0) -- draw with pen 0 (black) --
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 0, a0, L
|
||||
move a0, *a14+, 1 ; pixel = 0
|
||||
move a9, *a14+, 1 ; gc
|
||||
move a11, *a14+, 1 ; display
|
||||
calla 3FD99A60h ; XSetForeground
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
movi 5, a0, L
|
||||
move a0, @01890140h, 1 ; stage = 5
|
||||
move a0, @m_stage, 1
|
||||
|
||||
; ---- image = XCreateImage(d, NULL, 1, XYBitmap, 0,
|
||||
; bitmap, 32, 32, 32, 0) -------------
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 0, a0, L
|
||||
move a0, *a14+, 1 ; bytes_per_line = 0 (let it compute)
|
||||
movi 32, a0, L
|
||||
move a0, *a14+, 1 ; bitmap_pad = 32
|
||||
movi 32, a0, L
|
||||
move a0, *a14+, 1 ; height
|
||||
move a0, *a14+, 1 ; width
|
||||
movi BITMAP, a0, L
|
||||
move a0, *a14+, 1 ; data
|
||||
movi 0, a0, L
|
||||
move a0, *a14+, 1 ; offset
|
||||
move a0, *a14+, 1 ; format = 0 (XYBitmap)
|
||||
movi 1, a0, L
|
||||
move a0, *a14+, 1 ; depth = 1
|
||||
sub a0, a0
|
||||
move a0, *a14+, 1 ; visual = NULL
|
||||
move a11, *a14+, 1 ; display
|
||||
calla 3F9A0490h ; XCreateImage
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
move a8, a7 ; image (a7 survives XPutImage)
|
||||
move a8, @01890160h, 1 ; MARK image
|
||||
move a8, @m_image, 1
|
||||
move a8, a8
|
||||
jreq fail_img
|
||||
movi 6, a0, L
|
||||
move a0, @01890140h, 1 ; stage = 6
|
||||
move a0, @m_stage, 1
|
||||
|
||||
; ---- let the WM frame/reparent and map the window (xtext) -----
|
||||
; A draw issued before the reparent can be lost, so sync first.
|
||||
movi 4, a12, L
|
||||
map_wait:
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 0, a0, L
|
||||
move a0, *a14+, 1 ; discard = 0
|
||||
move a11, *a14+, 1 ; display
|
||||
calla 3FD9F6B0h ; XSync
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
dsjs a12, map_wait
|
||||
|
||||
; ---- XPutImage(d, win, gc, image, 0,0, 20,20, 32,32) ---------
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 32, a0, L
|
||||
move a0, *a14+, 1 ; h
|
||||
move a0, *a14+, 1 ; w
|
||||
movi 20, a0, L
|
||||
move a0, *a14+, 1 ; dst_y
|
||||
move a0, *a14+, 1 ; dst_x
|
||||
sub a0, a0
|
||||
move a0, *a14+, 1 ; src_y
|
||||
move a0, *a14+, 1 ; src_x
|
||||
move a7, *a14+, 1 ; image
|
||||
move a9, *a14+, 1 ; gc
|
||||
move a10, *a14+, 1 ; drawable
|
||||
move a11, *a14+, 1 ; display
|
||||
calla 3F9D0370h ; XPutImage
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
move a8, @018901A0h, 1 ; MARK putimage return
|
||||
move a8, @m_putret, 1
|
||||
movi 7, a0, L
|
||||
move a0, @01890140h, 1 ; stage = 7
|
||||
move a0, @m_stage, 1
|
||||
|
||||
; ---- control: the same image with h = 16 at dst_y = 60 --------
|
||||
; The PNG must show exactly 16 rows here (src rows 0..15): that is
|
||||
; what proves the 32-row draw above is the image, not the window.
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 16, a0, L
|
||||
move a0, *a14+, 1 ; h = 16
|
||||
movi 32, a0, L
|
||||
move a0, *a14+, 1 ; w = 32
|
||||
movi 60, a0, L
|
||||
move a0, *a14+, 1 ; dst_y = 60
|
||||
movi 20, a0, L
|
||||
move a0, *a14+, 1 ; dst_x = 20
|
||||
sub a0, a0
|
||||
move a0, *a14+, 1 ; src_y = 0
|
||||
move a0, *a14+, 1 ; src_x = 0
|
||||
move a7, *a14+, 1 ; image
|
||||
move a9, *a14+, 1 ; gc
|
||||
move a10, *a14+, 1 ; drawable
|
||||
move a11, *a14+, 1 ; display
|
||||
calla 3F9D0370h ; XPutImage
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
|
||||
; ---- flush, twice: the request is only in the client buffer ---
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 0, a0, L
|
||||
move a0, *a14+, 1
|
||||
move a11, *a14+, 1
|
||||
calla 3FD9F6B0h ; XSync
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
move a8, @018901C0h, 1 ; MARK sync return
|
||||
move a8, @m_syncret, 1
|
||||
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
movi 0, a0, L
|
||||
move a0, *a14+, 1
|
||||
move a11, *a14+, 1
|
||||
calla 3FD9F6B0h ; XSync
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
move a8, @018901C0h, 1
|
||||
move a8, @m_syncret, 1
|
||||
|
||||
movi 8, a0, L
|
||||
move a0, @01890140h, 1 ; stage = 8
|
||||
move a0, @m_stage, 1
|
||||
|
||||
; ---- XDestroyImage(image) ------------------------------------
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
move a7, *a14+, 1
|
||||
calla 3F9A0D80h ; XDestroyImage
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
jruc done
|
||||
|
||||
fail_abi:
|
||||
movi 091h, a0, L
|
||||
jruc failed
|
||||
fail_open:
|
||||
movi 092h, a0, L
|
||||
jruc failed
|
||||
fail_win:
|
||||
movi 093h, a0, L
|
||||
jruc failed
|
||||
fail_gc:
|
||||
movi 095h, a0, L
|
||||
jruc failed
|
||||
fail_img:
|
||||
movi 096h, a0, L
|
||||
jruc failed
|
||||
failed:
|
||||
move a0, @01890140h, 1
|
||||
move a0, @m_stage, 1
|
||||
|
||||
done:
|
||||
mmfm sp, a0,a1,a2,a3,a4,a5,a6,a7
|
||||
movi 0, a8, L
|
||||
rets
|
||||
|
||||
.data
|
||||
; 32 rows of 4 bytes, LSB-first pixels: a solid row at y=0, a solid row
|
||||
; at y=31, and a one-pixel diagonal between them. The top and bottom
|
||||
; rows make the drawn height readable straight off the PNG.
|
||||
BITMAP:
|
||||
.byte 0FFh, 0FFh, 0FFh, 0FFh, 002h, 000h, 000h, 000h
|
||||
.byte 004h, 000h, 000h, 000h, 008h, 000h, 000h, 000h
|
||||
.byte 010h, 000h, 000h, 000h, 020h, 000h, 000h, 000h
|
||||
.byte 040h, 000h, 000h, 000h, 080h, 000h, 000h, 000h
|
||||
.byte 000h, 001h, 000h, 000h, 000h, 002h, 000h, 000h
|
||||
.byte 000h, 004h, 000h, 000h, 000h, 008h, 000h, 000h
|
||||
.byte 000h, 010h, 000h, 000h, 000h, 020h, 000h, 000h
|
||||
.byte 000h, 040h, 000h, 000h, 000h, 080h, 000h, 000h
|
||||
.byte 000h, 000h, 001h, 000h, 000h, 000h, 002h, 000h
|
||||
.byte 000h, 000h, 004h, 000h, 000h, 000h, 008h, 000h
|
||||
.byte 000h, 000h, 010h, 000h, 000h, 000h, 020h, 000h
|
||||
.byte 000h, 000h, 040h, 000h, 000h, 000h, 080h, 000h
|
||||
.byte 000h, 000h, 000h, 001h, 000h, 000h, 000h, 002h
|
||||
.byte 000h, 000h, 000h, 004h, 000h, 000h, 000h, 008h
|
||||
.byte 000h, 000h, 000h, 010h, 000h, 000h, 000h, 020h
|
||||
.byte 000h, 000h, 000h, 040h, 0FFh, 0FFh, 0FFh, 0FFh
|
||||
BITMAP_END:
|
||||
|
||||
.bss m_stage, 32, 1
|
||||
.bss m_display, 32, 1
|
||||
.bss m_window, 32, 1
|
||||
.bss m_gc, 32, 1
|
||||
.bss m_image, 32, 1
|
||||
.bss m_putret, 32, 1
|
||||
.bss m_syncret, 32, 1
|
||||
.bss m_strlen, 32, 1
|
||||
|
||||
.end
|
||||
@@ -0,0 +1,301 @@
|
||||
-- xshow.lua -- run dwt/gui/build/xshow.coff through the COFF loader and report
|
||||
-- whether the 1-bit XImage reached the screen.
|
||||
--
|
||||
-- Same debugger-assisted path as dwt/loader/loader.lua (no network, no rdebug,
|
||||
-- no sudo): at frame XSHOW_AT it pokes the loader at bit 0x01880000, the COFF
|
||||
-- at XSHOW_BUF (default 0x01900000), the descriptor at 0x01882C00, and sets
|
||||
-- PC = 0x01880000. The loader copies the sections and calls create_process().
|
||||
--
|
||||
-- Env:
|
||||
-- XSHOW_AT injection frame (default 2500)
|
||||
-- XSHOW_END inspection/exit frame (default 2700)
|
||||
-- XSHOW_SNAP frame to snapshot (default XSHOW_END)
|
||||
-- XSHOW_COFF COFF (default dwt/gui/build/xshow.coff)
|
||||
-- XSHOW_BIN loader payload (default dwt/loader/build/loader.bin)
|
||||
-- XSHOW_BUF COFF buffer bit address (default 0x01900000)
|
||||
-- XSHOW_OUT evidence dir (default dwt/gui/evidence)
|
||||
-- XSHOW_NOSNAP 1 = do not write a PNG
|
||||
--
|
||||
-- Marker cells (the payload writes both blocks):
|
||||
-- 01890100/120/140/160/180/1A0/1C0 xhello-compatible cells (heap; may be
|
||||
-- overwritten after the app finishes)
|
||||
-- 018D8000/20/40/60/80/A0/C0/E0 .bss mirror: stage, display, window,
|
||||
-- gc, image, putret, syncret, strlen
|
||||
|
||||
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
|
||||
|
||||
local machine = manager.machine
|
||||
local cpu = machine.devices[':maincpu']
|
||||
local dbg = machine.debugger
|
||||
local prog = cpu.spaces['program']
|
||||
|
||||
if not dbg then
|
||||
print("XSHOW: debugger not enabled; pass -debug")
|
||||
machine:exit()
|
||||
return
|
||||
end
|
||||
|
||||
local AT = tonumber(os.getenv("XSHOW_AT") or "2500")
|
||||
local ENDF = tonumber(os.getenv("XSHOW_END") or "2700")
|
||||
local SNAP = tonumber(os.getenv("XSHOW_SNAP") or tostring(ENDF))
|
||||
local BIN = os.getenv("XSHOW_BIN") or "dwt/loader/build/loader.bin"
|
||||
local COFF = os.getenv("XSHOW_COFF") or "dwt/gui/build/xshow.coff"
|
||||
local BUF = tonumber(os.getenv("XSHOW_BUF") or "0x01900000")
|
||||
local OUT = os.getenv("XSHOW_OUT") or "dwt/gui/evidence"
|
||||
local NOSNAP = os.getenv("XSHOW_NOSNAP") == "1"
|
||||
|
||||
local LOADER_BASE = 0x01880000
|
||||
local DESC = 0x01882C00
|
||||
local RESULT = 0x01882D00
|
||||
|
||||
local function slurp(p)
|
||||
local f, err = io.open(p, "rb")
|
||||
if not f then error("cannot open " .. p .. ": " .. tostring(err)) end
|
||||
local s = f:read("*a")
|
||||
f:close()
|
||||
return s
|
||||
end
|
||||
|
||||
local function u16(s, o)
|
||||
return s:byte(o + 1) + s:byte(o + 2) * 256
|
||||
end
|
||||
|
||||
local function u32(s, o)
|
||||
return s:byte(o + 1) + s:byte(o + 2) * 256
|
||||
+ s:byte(o + 3) * 65536 + s:byte(o + 4) * 16777216
|
||||
end
|
||||
|
||||
local function parse_coff(d)
|
||||
local c = { data = d }
|
||||
c.magic = u16(d, 0)
|
||||
c.nscns = u16(d, 2)
|
||||
c.opthdr = u16(d, 16)
|
||||
c.sections = {}
|
||||
if c.opthdr > 0 then
|
||||
c.optmagic = u16(d, 20)
|
||||
c.entry = u32(d, 20 + 16)
|
||||
c.textstart = u32(d, 20 + 20)
|
||||
c.datastart = u32(d, 20 + 24)
|
||||
end
|
||||
local base = 20 + c.opthdr
|
||||
for i = 0, c.nscns - 1 do
|
||||
local o = base + i * 40
|
||||
local name = d:sub(o + 1, o + 8):gsub("%z", "")
|
||||
c.sections[#c.sections + 1] = {
|
||||
name = name,
|
||||
paddr = u32(d, o + 8),
|
||||
size = u32(d, o + 16), -- bits
|
||||
scnptr = u32(d, o + 20),
|
||||
flags = u32(d, o + 36),
|
||||
}
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
local function poke_bytes(bitaddr, data)
|
||||
local n = math.floor((#data + 1) / 2)
|
||||
for i = 0, n - 1 do
|
||||
local lo = data:byte(i * 2 + 1) or 0
|
||||
local hi = data:byte(i * 2 + 2) or 0
|
||||
prog:write_u16(bitaddr + i * 16, lo + hi * 256)
|
||||
end
|
||||
return n
|
||||
end
|
||||
|
||||
local function verify_bytes(bitaddr, data)
|
||||
local n = math.floor((#data + 1) / 2)
|
||||
local bad = 0
|
||||
for i = 0, n - 1 do
|
||||
local lo = data:byte(i * 2 + 1) or 0
|
||||
local hi = data:byte(i * 2 + 2) or 0
|
||||
if prog:read_u16(bitaddr + i * 16) ~= lo + hi * 256 then
|
||||
bad = bad + 1
|
||||
end
|
||||
end
|
||||
return n, bad
|
||||
end
|
||||
|
||||
local function w32(a, v) prog:write_u32(a, v) end
|
||||
local function r32(a)
|
||||
local ok, v = pcall(function() return prog:read_u32(a) end)
|
||||
if ok then return v end
|
||||
return 0xDEADBEEF
|
||||
end
|
||||
|
||||
local loader = slurp(BIN)
|
||||
local coff = slurp(COFF)
|
||||
local app = parse_coff(coff)
|
||||
|
||||
print(string.format("XSHOW: payload %s (%d B) -> bit %s", BIN, #loader, hex(LOADER_BASE)))
|
||||
print(string.format("XSHOW: COFF %s (%d B) -> bit %s", COFF, #coff, hex(BUF)))
|
||||
print(string.format("XSHOW: file magic=%04X nscns=%d opthdr=%d entry=%s textstart=%s",
|
||||
app.magic, app.nscns, app.opthdr, hex(app.entry or 0), hex(app.textstart or 0)))
|
||||
for _, s in ipairs(app.sections) do
|
||||
print(string.format("XSHOW: sec %-8s paddr=%s size=%d bits (%d B) flags=%#x",
|
||||
s.name, hex(s.paddr), s.size, math.floor(s.size / 8), s.flags))
|
||||
end
|
||||
|
||||
-- The .data bytes the probe will hand to XCreateImage, read out of the COFF.
|
||||
for _, s in ipairs(app.sections) do
|
||||
if s.name == ".data" and s.scnptr ~= 0 and s.size > 0 then
|
||||
local nb = math.floor(s.size / 8)
|
||||
local bytes = coff:sub(s.scnptr + 1, s.scnptr + nb)
|
||||
local first = {}
|
||||
for i = 1, math.min(16, #bytes) do first[#first + 1] = string.format("%02X", bytes:byte(i)) end
|
||||
print(string.format("XSHOW: .data first %d bytes: %s", #first, table.concat(first, " ")))
|
||||
end
|
||||
end
|
||||
|
||||
local frames = 0
|
||||
local injected = false
|
||||
local inspected = false
|
||||
local snapped = false
|
||||
|
||||
local function markers()
|
||||
return {
|
||||
stage = r32(0x01890140),
|
||||
display = r32(0x01890100),
|
||||
window = r32(0x01890120),
|
||||
image = r32(0x01890160),
|
||||
gc = r32(0x01890180),
|
||||
putret = r32(0x018901A0),
|
||||
syncret = r32(0x018901C0),
|
||||
}
|
||||
end
|
||||
|
||||
local function mirror()
|
||||
return {
|
||||
stage = r32(0x018D8000),
|
||||
display = r32(0x018D8020),
|
||||
window = r32(0x018D8040),
|
||||
gc = r32(0x018D8060),
|
||||
image = r32(0x018D8080),
|
||||
putret = r32(0x018D80A0),
|
||||
syncret = r32(0x018D80C0),
|
||||
strlen = r32(0x018D80E0),
|
||||
}
|
||||
end
|
||||
|
||||
local function report(tag)
|
||||
local m = markers()
|
||||
local r = mirror()
|
||||
print(string.format(
|
||||
"XSHOW: %s cells stage=%s display=%s window=%s gc=%s image=%s putret=%s syncret=%s",
|
||||
tag, hex(m.stage), hex(m.display), hex(m.window), hex(m.gc), hex(m.image),
|
||||
hex(m.putret), hex(m.syncret)))
|
||||
print(string.format(
|
||||
"XSHOW: %s mirror stage=%s display=%s window=%s gc=%s image=%s putret=%s syncret=%s strlen=%s",
|
||||
tag, hex(r.stage), hex(r.display), hex(r.window), hex(r.gc), hex(r.image),
|
||||
hex(r.putret), hex(r.syncret), hex(r.strlen)))
|
||||
end
|
||||
|
||||
-- Dump the XImage fields the ROM's own code reads (byte offsets are the
|
||||
-- standard 32-bit XImage layout; 0x120/0x140/0x160 = depth/bpl/bpp).
|
||||
local IMG_FIELDS = {
|
||||
{ "width", 0x000 }, { "height", 0x020 }, { "xoffset", 0x040 },
|
||||
{ "format", 0x060 }, { "data", 0x080 }, { "byte_order", 0x0A0 },
|
||||
{ "bitmap_unit", 0x0C0 }, { "bitmap_bit_order", 0x0E0 },
|
||||
{ "bitmap_pad", 0x100 }, { "depth", 0x120 }, { "bytes_per_line", 0x140 },
|
||||
{ "bits_per_pixel", 0x160 },
|
||||
}
|
||||
|
||||
local function dump_image(ptr, tag)
|
||||
if ptr == 0 then return end
|
||||
local parts = {}
|
||||
for _, f in ipairs(IMG_FIELDS) do
|
||||
parts[#parts + 1] = string.format("%s=%s", f[1], hex(r32(ptr + f[2])))
|
||||
end
|
||||
print(string.format("XSHOW: %s image@%s %s", tag, hex(ptr), table.concat(parts, " ")))
|
||||
end
|
||||
|
||||
local function dump_dpy(ptr, tag)
|
||||
if ptr == 0 then return end
|
||||
print(string.format(
|
||||
"XSHOW: %s dpy@%s byte_order=%s bitmap_unit=%s scanline_pad=%s bitmap_bit_order=%s",
|
||||
tag, hex(ptr), hex(r32(ptr + 0x1A0)), hex(r32(ptr + 0x1C0)),
|
||||
hex(r32(ptr + 0x1E0)), hex(r32(ptr + 0x200))))
|
||||
-- XPutImage's bits_per_pixel check walks dpy->pixmap_formats: count at
|
||||
-- +0x220, pointer at +0x240, entry stride 0x80 bits, depth at +0x20,
|
||||
-- bits_per_pixel at +0x40.
|
||||
local n = r32(ptr + 0x220)
|
||||
local list = r32(ptr + 0x240)
|
||||
print(string.format("XSHOW: %s pixmap_formats n=%d list=%s", tag, n, hex(list)))
|
||||
for i = 0, math.min(n, 8) - 1 do
|
||||
local e = list + i * 0x80
|
||||
print(string.format("XSHOW: %s fmt[%d] depth=%s bits_per_pixel=%s pad=%s",
|
||||
tag, i, hex(r32(e + 0x20)), hex(r32(e + 0x40)), hex(r32(e + 0x60))))
|
||||
end
|
||||
end
|
||||
|
||||
local function inject()
|
||||
poke_bytes(LOADER_BASE, loader)
|
||||
local _, bad = verify_bytes(LOADER_BASE, loader)
|
||||
print(string.format("XSHOW: loader poked %d words, readback %d bad at %s",
|
||||
math.floor((#loader + 1) / 2), bad, hex(LOADER_BASE)))
|
||||
|
||||
poke_bytes(BUF, coff)
|
||||
local _, cbad = verify_bytes(BUF, coff)
|
||||
print(string.format("XSHOW: COFF poked %d words, readback %d bad at %s",
|
||||
math.floor((#coff + 1) / 2), cbad, hex(BUF)))
|
||||
|
||||
w32(DESC + 0x00, 0)
|
||||
prog:write_u16(DESC + 0x00, 0x4C44) -- "LD"
|
||||
prog:write_u16(DESC + 0x10, 0x5231) -- "R1"
|
||||
w32(DESC + 0x20, BUF)
|
||||
w32(DESC + 0x40, #coff)
|
||||
w32(DESC + 0x60, 0) -- mode 0: debug-resume
|
||||
print(string.format("XSHOW: descriptor @%s magic=%04X/%04X buf=%s len=%d mode=%d",
|
||||
hex(DESC), prog:read_u16(DESC + 0x00), prog:read_u16(DESC + 0x10),
|
||||
hex(r32(DESC + 0x20)), r32(DESC + 0x40), r32(DESC + 0x60)))
|
||||
|
||||
local orig_pc = cpu.state['PC'].value
|
||||
w32(0x01882A20, orig_pc) -- LD_ORIG_PC
|
||||
print(string.format("XSHOW: will resume at %s after create_process", hex(orig_pc)))
|
||||
cpu.state['A8'].value = 0
|
||||
cpu.state['PC'].value = LOADER_BASE
|
||||
injected = true
|
||||
print(string.format("XSHOW: frame %d: entered loader at %s (caller SP=%s)",
|
||||
frames, hex(LOADER_BASE), hex(cpu.state['SP'].value)))
|
||||
end
|
||||
|
||||
local function snapshot(path)
|
||||
local screen = nil
|
||||
for _, s in pairs(machine.screens) do screen = s break end
|
||||
if not screen then
|
||||
print("XSHOW: no screen device")
|
||||
return
|
||||
end
|
||||
local ok, err = pcall(function() return screen:snapshot(path) end)
|
||||
print(string.format("XSHOW: snapshot %s ok=%s %s", path, tostring(ok), tostring(err or "")))
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == AT and not injected then inject() end
|
||||
if injected and not inspected and frames >= AT + 40 then
|
||||
inspected = true
|
||||
report("f" .. frames)
|
||||
end
|
||||
if injected and frames == SNAP and not snapped then
|
||||
snapped = true
|
||||
report("f" .. frames)
|
||||
if not NOSNAP then snapshot(OUT .. "/xshow_frame" .. frames .. ".png") end
|
||||
end
|
||||
if frames >= ENDF then
|
||||
if injected then
|
||||
report("final")
|
||||
local st = r32(RESULT + 0x000)
|
||||
print(string.format("XSHOW: loader status=%d entry=%s text=%s/%d bits",
|
||||
st, hex(r32(RESULT + 0x020)),
|
||||
hex(r32(RESULT + 0x040)), r32(RESULT + 0x060)))
|
||||
print(string.format("XSHOW: PC at exit = %s", hex(cpu.state['PC'].value)))
|
||||
local m = markers()
|
||||
dump_image(m.image, "final")
|
||||
dump_dpy(m.display, "final")
|
||||
end
|
||||
machine:exit()
|
||||
end
|
||||
end, "vt1200-xshow")
|
||||
|
||||
dbg.visible_cpu = cpu
|
||||
dbg.execution_state = 'run'
|
||||
@@ -9,7 +9,7 @@
|
||||
; XLoadFont(d,"fixed") 3FD4AE80
|
||||
; XCreateGC(d,win,mask,&values) 3F997000
|
||||
; XSetForeground(d,gc,1) 3FD99A60
|
||||
; XMapWindow(d,win) 3FD645B0
|
||||
; XRaiseWindow(d,win) 3FD645B0 (does NOT map)
|
||||
; XSync(d,0) / XDrawString(...) loop 3FD9F6B0 / 3FDA0000
|
||||
;
|
||||
; The GC is created with a zero value-mask, so the server fills it from the
|
||||
@@ -49,7 +49,7 @@
|
||||
; 01842060 window id
|
||||
; 01842080 GC id returned by XCreateGC
|
||||
; 018420A0 XSetForeground return
|
||||
; 018420C0 XMapWindow return
|
||||
; 018420C0 XRaiseWindow return
|
||||
; 018420E0 last XSync return
|
||||
; 01842100 first XDrawString return
|
||||
; 01842120 second XDrawString return
|
||||
@@ -180,15 +180,17 @@ _start:
|
||||
movi 6, a0, L
|
||||
move a0, @01842000h, 1 ; stage = 6
|
||||
|
||||
; ---- XMapWindow(display, window) -----------------------------
|
||||
; ---- XRaiseWindow(display, window) ---------------------------
|
||||
; ConfigureWindow with CWStackMode=Above: raises an already-mapped
|
||||
; window. It does NOT map it -- XMapWindow is 3FD64F60.
|
||||
move a14, -*sp, 1
|
||||
movi 01894000h, a14, L
|
||||
move a10, *a14+, 1 ; window
|
||||
move a11, *a14+, 1 ; display
|
||||
calla 3FD645B0h ; XMapWindow
|
||||
calla 3FD645B0h ; XRaiseWindow
|
||||
setf 16, 0, 0
|
||||
setf 32, 0, 1
|
||||
move a8, @018420C0h, 1 ; MARK map
|
||||
move a8, @018420C0h, 1 ; MARK raise
|
||||
movi 7, a0, L
|
||||
move a0, @01842000h, 1 ; stage = 7
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ Read `dwt/notes/LOADER.md` for the full report and
|
||||
| `loader.asm` | the loader; linked at bit `0x01880000`, raw `.bin` 1220 B |
|
||||
| `marker.asm` | acceptance app with `.text`/`.data`/`.bss` at three addresses |
|
||||
| `coff.py` | TI COFF reader/dumper (`summary`, `raw`, `manifest`) |
|
||||
| `xg.c` | app-side `vt_install_xg()`: installs the per-process Xlib context before `XOpenDisplay` (see below); not part of the loader payload |
|
||||
| `build.sh` | GSPA/GSPLNK wrapper; keeps the linked COFF |
|
||||
| `reldemo.sh`, `rel_a.asm`, `rel_b.asm` | relocation and position-dependence demo |
|
||||
| `loader.lua` | debugger-assisted harness (no network, no rdebug) |
|
||||
@@ -25,6 +26,84 @@ Read `dwt/notes/LOADER.md` for the full report and
|
||||
`work/` (the DOS tools extracted from the SDK floppy) and `run/` (private
|
||||
NVRAM/cfg) are local scratch and ignored.
|
||||
|
||||
## The per-process XG block (needed before `XOpenDisplay`)
|
||||
|
||||
A process this loader starts with `create_process` begins with **no Xlib
|
||||
context**. The ROM Xlib finds it through the current-process word:
|
||||
|
||||
```
|
||||
proc = *(u32 *)0x001B3900 ; current PCB (bit address)
|
||||
pp = *(u32 *)(proc + 0x100) ; per-process user block (bit +0x100 = byte +0x20)
|
||||
XG = *(u32 *)pp ; per-process Xlib context; 0 in a fresh child
|
||||
free_list = *(u32 *)(XG + 0xCC0) ; bits; byte +0x198 of the block
|
||||
```
|
||||
|
||||
Verified in the ROM: the current-process helper `0x3F708700` is just
|
||||
`move @0x1b3900,a8,1; rets`, and both the dequeue path inside `XNextEvent`
|
||||
(`0x3F9C1CF0`) and its enqueue helper (`0x3F9B89A0`, Xlib's `_XEnq`, called at
|
||||
`0x3F9C2180`) do `calla 0x3F708700` → `move *a8(0x100),a7` → `move *a7,a7` →
|
||||
access `*a7(0xcc0)`.
|
||||
|
||||
With `XG == 0` the whole XG structure — queue head, queue length, and the free
|
||||
list at `+0xCC0` — is read from low RAM. Nothing crashes and nothing reports an
|
||||
error: `XOpenDisplay`, `XCreateSimpleWindow`, `XMapWindow`, `XSync` and all
|
||||
drawing still work, and the window appears on screen. **Only events fail** —
|
||||
`XNextEvent` returns zeroed records (`type=0`, `keycode=0`) and never a real
|
||||
event. That is the symptom to recognise: a client that looks alive and never
|
||||
reacts.
|
||||
|
||||
Install a zeroed ≥1 KiB block before the first Xlib call:
|
||||
|
||||
```c
|
||||
extern int vt_install_xg(void);
|
||||
|
||||
if(!vt_install_xg())
|
||||
return 1; /* no plausible current process / user block */
|
||||
dpy = XOpenDisplay("0::0"); /* only after the block exists */
|
||||
```
|
||||
|
||||
`xg.c` is that helper. Build it with the app (the C toolchain path used by
|
||||
`apps/termtris`):
|
||||
|
||||
```sh
|
||||
apps/termtris/build.sh myapp.c dwt/loader/xg.c
|
||||
```
|
||||
|
||||
or copy the file into the app's tree; there is no header — declare
|
||||
`extern int vt_install_xg(void);`. The termtris port makes the same install
|
||||
(`apps/termtris/src/vt1200/xgfix.c`) with a `static vt_u32 vt_xg[256]` block
|
||||
(1 KiB); `xg.c` zeroes its block on each call rather than trusting startup to
|
||||
clear `.bss`. The helper stores its block's address at `*(u32 *)pp` — it
|
||||
overwrites XG, not the pointer cell at `proc + 0x100` — and changes RAM only,
|
||||
never the ROM.
|
||||
|
||||
An assembly client does the same two loads and one store:
|
||||
|
||||
```
|
||||
move @1B3900h, a8, 1 ; current PCB
|
||||
move *a8(100h), a7, 1 ; per-process user block (bit offset 0x100)
|
||||
movi xg_block, a9 ; a 1 KiB block, zeroed at startup
|
||||
move a9, *a7, 1 ; XG = block
|
||||
```
|
||||
|
||||
**Ordering:** before `XOpenDisplay`, every time. A draw-only window can get
|
||||
away without it; the moment the client calls `XNextEvent`, the missing block
|
||||
turns into "no events, ever".
|
||||
|
||||
Measured (2026-11-13): the unmodified termtris smoke client
|
||||
(`apps/termtris/tests/smoke.c`) linked with `dwt/loader/xg.c` and loaded by
|
||||
this harness received a real `KeyPress`:
|
||||
|
||||
```
|
||||
SMOKE: magic=534D4F4B dpy=00942290 win=00400001 n=9 type=2 keycode=194 lookup_n=1 ch=61 ks=0061 keymark=4B455950
|
||||
```
|
||||
|
||||
The same client with a stub `vt_install_xg()` that installs nothing runs its
|
||||
event loop but only sees zeroed records:
|
||||
`type=0 keycode=0 lookup_n=0 ch=00 ks=0000 keymark=00000000` after 10
|
||||
iterations. The transcript, including the control, is
|
||||
`evidence/xg_helper_run.log`.
|
||||
|
||||
## Build
|
||||
|
||||
```sh
|
||||
@@ -56,5 +135,45 @@ The script pokes the loader at `0x01880000` and the COFF at `LOADER_BUF`
|
||||
network, the rdebug service or a firmware transport.
|
||||
|
||||
Knobs: `LOADER_MODE=1` (callable/return instead of debug-resume),
|
||||
`LOADER_A8_DESC=1` (descriptor in `A8`), `LOADER_SNAP=1` (PNG at `LOADER_END`),
|
||||
`LOADER_A8_DESC=1` (descriptor in `A8`), `LOADER_SNAP=1` (PNG at the exit frame),
|
||||
`LOADER_VERBOSE=1`, `LOADER_TRACE=1`.
|
||||
|
||||
### Environment
|
||||
|
||||
| variable | default | meaning |
|
||||
|---|---|---|
|
||||
| `LOADER_AT` | `2500` | frame at which the loader and COFF are poked and `PC` is set |
|
||||
| `LOADER_END` | `2700` | fixed inspection/exit frame; **`0` = run until completion** |
|
||||
| `LOADER_MAX` | `6000` | `LOADER_END=0` only: give up (with a warning) at this frame |
|
||||
| `LOADER_BIN` | `dwt/loader/build/loader.bin` | loader payload poked at bit `0x01880000` |
|
||||
| `LOADER_COFF` | `dwt/loader/build/marker.coff` | app COFF poked at `LOADER_BUF` |
|
||||
| `LOADER_BUF` | `0x01900000` | COFF buffer bit address |
|
||||
| `LOADER_OUT` | `dwt/loader/evidence` | directory for the optional PNG |
|
||||
| `LOADER_SNAP` | `0` | `1` writes `loader_frame<frame>.png` at the exit frame |
|
||||
|
||||
### Completion and `LOADER_END=0`
|
||||
|
||||
The harness detects completion when all three hold:
|
||||
|
||||
1. the loader has written `RESULT_STATUS` (it is `0xFFFFFFFF` until then),
|
||||
2. `PC` is outside `[LOADER_BASE, LOADER_BASE+0x400)`, and
|
||||
3. the result block has been unchanged for 10 frames.
|
||||
|
||||
On detection it prints one line and sets `done` once:
|
||||
|
||||
```
|
||||
LOADER: complete at frame 2510 status=00000000
|
||||
```
|
||||
|
||||
With a **fixed** `LOADER_END` the run still exits at that frame, so the snapshot
|
||||
filename and every existing fixed-frame capture are unchanged; the completion
|
||||
line is informational and suppresses the startup warning. With **`LOADER_END=0`**
|
||||
the run exits as soon as completion is detected, and if it is not detected by
|
||||
`LOADER_MAX` it prints
|
||||
|
||||
```
|
||||
LOADER: warning: app still in startup at LOADER_MAX=6000
|
||||
```
|
||||
|
||||
and exits there. With a fixed `LOADER_END` that is reached first, the warning is
|
||||
`LOADER: warning: app still in startup at LOADER_END=<n>`.
|
||||
@@ -0,0 +1,626 @@
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 1
|
||||
|
||||
0001 ; xshow.asm -- create a 1-bit XImage and XPutImage it o
|
||||
0002 ;
|
||||
0003 ; Run as a first-class process created by the COFF load
|
||||
0004 ; in the rdebug dispatcher's context: a connect made fr
|
||||
0005 ; accepted at the service layer but the server never re
|
||||
0006 ;
|
||||
0007 ; The image is a 32x32 XYBitmap (format 0), depth 1, cr
|
||||
0008 ; XCreateImage and drawn with XPutImage. Its data is a
|
||||
0009 ; cells, written into .data at build time, so the PNG s
|
||||
0010 ; or nothing -- there is nothing to misread.
|
||||
0011 ;
|
||||
0012 ; XImage entry points used here (Ghidra address -> bit
|
||||
0013 ; 7F34092 XCreateImage(d,visual,depth,format,offset,d
|
||||
0014 ; 7FA06E XPutImage(d,drawable,gc,image,sx,sy,dx,dy,w
|
||||
0015 ; 7F341B0 XDestroyImage(image)
|
||||
0016 ; 7FAAAD6 XGetImage(d,drawable,x,y,w,h,plane_mask,for
|
||||
0017 ; (XGetImage is documented from disassembly; this probe
|
||||
0018 ;
|
||||
0019 ; Calling convention: reserve one slot with `move a14,-
|
||||
0020 ; last-to-first upward through a14, then `calla`. The
|
||||
0021 ; the return address and the reserved slot, and restore
|
||||
0022 ; sp/a14 from RAM markers (xtext.asm records that exact
|
||||
0023 ;
|
||||
0024 ; Xlib clobbers the CPU's SETF field state, so field 1
|
||||
0025 ; established after every call. a10/a11/a12 survive ev
|
||||
0026 ; a9 (the GC) survives XCreateImage and XPutImage; a7 (
|
||||
0027 ; XPutImage. XDestroyImage saves only a11/a13, so it r
|
||||
0028 ;
|
||||
0029 ; Markers:
|
||||
0030 ; 01890100 display 01890120 window 01890140 stage
|
||||
0031 ; 01890180 gc 018901A0 XPutImage return 01
|
||||
0032 ; These are the xhello-compatible cells the runner repo
|
||||
0033 ; cells sit in the heap and were overwritten after its
|
||||
0034 ; are mirrored into .bss at 018D8000h (below), which no
|
||||
0035 ; 018D8000 stage 018D8020 display 018D8040 window
|
||||
0036 ; 018D8080 image 018D80A0 putret 018D80C0 syncret
|
||||
0037 ; Stage: 1 start, 2 display, 3 window, 4 mapped, 5 gc,
|
||||
0038 ; 8 synced; 091h..097h = the step that failed.
|
||||
0039 ;
|
||||
0040 ; Scratch argument area: 01894000h (the app's own stack
|
||||
0041
|
||||
0042 00000000 .text
|
||||
0043 00000000 _start:
|
||||
0044 00000000 0550 setf 16, 0, 0
|
||||
0045 00000010 0740 setf 32, 0, 1
|
||||
0046 00000020 098F mmtm sp, a0,a1,a2,a3,a4,a5,a6,a7
|
||||
00000030 FF00
|
||||
0047
|
||||
0048 00000040 09E0 movi 1, a0, L
|
||||
00000050 00000001
|
||||
0049 00000070 0780 move a0, @01890140h, 1 ; stage = 1
|
||||
00000080 01890140
|
||||
0050 000000A0 0780 move a0, @m_stage, 1
|
||||
000000B0 00000000+
|
||||
0051
|
||||
0052 ; ---- convention check: strlen("0::0") == 4 ---------
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 2
|
||||
|
||||
0053 000000D0 A3CF move a14, -*sp, 1
|
||||
0054 000000E0 09EE movi 01894000h, a14, L
|
||||
000000F0 01894000
|
||||
0055 00000110 09E0 movi 3FACE948h, a0, L ; ROM "0::0"
|
||||
00000120 3FACE948
|
||||
0056 00000140 920E move a0, *a14+, 1
|
||||
0057 00000150 0D5F calla 3FB458D0h ; strlen
|
||||
00000160 3FB458D0
|
||||
0058 00000180 0550 setf 16, 0, 0
|
||||
0059 00000190 0740 setf 32, 0, 1
|
||||
0060 000001A0 0788 move a8, @m_strlen, 1
|
||||
000001B0 000000E0+
|
||||
0061 000001D0 09E0 movi 4, a0, L
|
||||
000001E0 00000004
|
||||
0062 00000200 4808 cmp a0, a8
|
||||
0063 00000210 CB00 jrne fail_abi
|
||||
00000220 0171
|
||||
0064
|
||||
0065 ; ---- display = XOpenDisplay("0::0") ----------------
|
||||
0066 00000230 A3CF move a14, -*sp, 1
|
||||
0067 00000240 09EE movi 01894000h, a14, L
|
||||
00000250 01894000
|
||||
0068 00000270 09E0 movi 3FACE948h, a0, L
|
||||
00000280 3FACE948
|
||||
0069 000002A0 920E move a0, *a14+, 1
|
||||
0070 000002B0 0D5F calla 3F9C2570h ; XOpenDisplay
|
||||
000002C0 3F9C2570
|
||||
0071 000002E0 0550 setf 16, 0, 0
|
||||
0072 000002F0 0740 setf 32, 0, 1
|
||||
0073 00000300 4D0B move a8, a11
|
||||
0074 00000310 078B move a11, @01890100h, 1 ; MARK display
|
||||
00000320 01890100
|
||||
0075 00000340 078B move a11, @m_display, 1
|
||||
00000350 00000020+
|
||||
0076 00000370 4D6B move a11, a11
|
||||
0077 00000380 CA00 jreq fail_open
|
||||
00000390 015E
|
||||
0078 000003A0 09E0 movi 2, a0, L
|
||||
000003B0 00000002
|
||||
0079 000003D0 0780 move a0, @01890140h, 1 ; stage = 2
|
||||
000003E0 01890140
|
||||
0080 00000400 0780 move a0, @m_stage, 1
|
||||
00000410 00000000+
|
||||
0081
|
||||
0082 ; ---- root = *(*(display+0x480)+0x40) ---------------
|
||||
0083 00000430 B76A move *a11(0480h), a10, 1
|
||||
00000440 0480
|
||||
0084 00000450 B74A move *a10(040h), a10, 1
|
||||
00000460 0040
|
||||
0085
|
||||
0086 ; ---- window = XCreateSimpleWindow(d,root,100,100,400
|
||||
0087 ; white background (pixel 1), black border, so a black
|
||||
0088 00000470 A3CF move a14, -*sp, 1
|
||||
0089 00000480 09EE movi 01894000h, a14, L
|
||||
00000490 01894000
|
||||
0090 000004B0 09E0 movi 1, a0, L
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 3
|
||||
|
||||
000004C0 00000001
|
||||
0091 000004E0 920E move a0, *a14+, 1 ; background = 1 (white)
|
||||
0092 000004F0 09E0 movi 0, a0, L
|
||||
00000500 00000000
|
||||
0093 00000520 920E move a0, *a14+, 1 ; border = 0 (black)
|
||||
0094 00000530 09E0 movi 2, a0, L
|
||||
00000540 00000002
|
||||
0095 00000560 920E move a0, *a14+, 1 ; border width
|
||||
0096 00000570 09E0 movi 200, a0, L
|
||||
00000580 000000C8
|
||||
0097 000005A0 920E move a0, *a14+, 1 ; height
|
||||
0098 000005B0 09E0 movi 400, a0, L
|
||||
000005C0 00000190
|
||||
0099 000005E0 920E move a0, *a14+, 1 ; width
|
||||
0100 000005F0 09E0 movi 100, a0, L
|
||||
00000600 00000064
|
||||
0101 00000620 920E move a0, *a14+, 1 ; y
|
||||
0102 00000630 920E move a0, *a14+, 1 ; x
|
||||
0103 00000640 934E move a10, *a14+, 1 ; parent = root
|
||||
0104 00000650 936E move a11, *a14+, 1 ; display
|
||||
0105 00000660 0D5F calla 3FD41B90h ; XCreateSimpleWindow
|
||||
00000670 3FD41B90
|
||||
0106 00000690 0550 setf 16, 0, 0
|
||||
0107 000006A0 0740 setf 32, 0, 1
|
||||
0108 000006B0 4D0A move a8, a10
|
||||
0109 000006C0 078A move a10, @01890120h, 1 ; MARK window
|
||||
000006D0 01890120
|
||||
0110 000006F0 078A move a10, @m_window, 1
|
||||
00000700 00000040+
|
||||
0111 00000720 4D4A move a10, a10
|
||||
0112 00000730 CA00 jreq fail_win
|
||||
00000740 0127
|
||||
0113 00000750 09E0 movi 3, a0, L
|
||||
00000760 00000003
|
||||
0114 00000780 0780 move a0, @01890140h, 1 ; stage = 3
|
||||
00000790 01890140
|
||||
0115 000007B0 0780 move a0, @m_stage, 1
|
||||
000007C0 00000000+
|
||||
0116
|
||||
0117 ; ---- XMapWindow(display, window) -------------------
|
||||
0118 000007E0 A3CF move a14, -*sp, 1
|
||||
0119 000007F0 09EE movi 01894000h, a14, L
|
||||
00000800 01894000
|
||||
0120 00000820 934E move a10, *a14+, 1
|
||||
0121 00000830 936E move a11, *a14+, 1
|
||||
0122 00000840 0D5F calla 3FD645B0h ; XMapWindow
|
||||
00000850 3FD645B0
|
||||
0123 00000870 0550 setf 16, 0, 0
|
||||
0124 00000880 0740 setf 32, 0, 1
|
||||
0125 00000890 09E0 movi 4, a0, L
|
||||
000008A0 00000004
|
||||
0126 000008C0 0780 move a0, @01890140h, 1 ; stage = 4
|
||||
000008D0 01890140
|
||||
0127 000008F0 0780 move a0, @m_stage, 1
|
||||
00000900 00000000+
|
||||
0128
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 4
|
||||
|
||||
0129 ; ---- gc = XCreateGC(d, window, 0, NULL) ------------
|
||||
0130 00000920 A3CF move a14, -*sp, 1
|
||||
0131 00000930 09EE movi 01894000h, a14, L
|
||||
00000940 01894000
|
||||
0132 00000960 09E0 movi 0, a0, L
|
||||
00000970 00000000
|
||||
0133 00000990 920E move a0, *a14+, 1 ; values
|
||||
0134 000009A0 920E move a0, *a14+, 1 ; mask = 0
|
||||
0135 000009B0 934E move a10, *a14+, 1 ; drawable
|
||||
0136 000009C0 936E move a11, *a14+, 1 ; display
|
||||
0137 000009D0 0D5F calla 3F997000h ; XCreateGC
|
||||
000009E0 3F997000
|
||||
0138 00000A00 0550 setf 16, 0, 0
|
||||
0139 00000A10 0740 setf 32, 0, 1
|
||||
0140 00000A20 4D09 move a8, a9 ; GC
|
||||
0141 00000A30 0789 move a9, @01890180h, 1 ; MARK gc
|
||||
00000A40 01890180
|
||||
0142 00000A60 0789 move a9, @m_gc, 1
|
||||
00000A70 00000060+
|
||||
0143 00000A90 4D29 move a9, a9
|
||||
0144 00000AA0 CA00 jreq fail_gc
|
||||
00000AB0 00F4
|
||||
0145
|
||||
0146 ; ---- XSetForeground(display, gc, 0) -- draw with pen
|
||||
0147 00000AC0 A3CF move a14, -*sp, 1
|
||||
0148 00000AD0 09EE movi 01894000h, a14, L
|
||||
00000AE0 01894000
|
||||
0149 00000B00 09E0 movi 0, a0, L
|
||||
00000B10 00000000
|
||||
0150 00000B30 920E move a0, *a14+, 1 ; pixel = 0
|
||||
0151 00000B40 932E move a9, *a14+, 1 ; gc
|
||||
0152 00000B50 936E move a11, *a14+, 1 ; display
|
||||
0153 00000B60 0D5F calla 3FD99A60h ; XSetForeground
|
||||
00000B70 3FD99A60
|
||||
0154 00000B90 0550 setf 16, 0, 0
|
||||
0155 00000BA0 0740 setf 32, 0, 1
|
||||
0156 00000BB0 09E0 movi 5, a0, L
|
||||
00000BC0 00000005
|
||||
0157 00000BE0 0780 move a0, @01890140h, 1 ; stage = 5
|
||||
00000BF0 01890140
|
||||
0158 00000C10 0780 move a0, @m_stage, 1
|
||||
00000C20 00000000+
|
||||
0159
|
||||
0160 ; ---- image = XCreateImage(d, NULL, 1, XYBitmap, 0,
|
||||
0161 ; bitmap, 32, 32, 32, 0) ---
|
||||
0162 00000C40 A3CF move a14, -*sp, 1
|
||||
0163 00000C50 09EE movi 01894000h, a14, L
|
||||
00000C60 01894000
|
||||
0164 00000C80 09E0 movi 0, a0, L
|
||||
00000C90 00000000
|
||||
0165 00000CB0 920E move a0, *a14+, 1 ; bytes_per_line = 0 (let it comput
|
||||
0166 00000CC0 09E0 movi 32, a0, L
|
||||
00000CD0 00000020
|
||||
0167 00000CF0 920E move a0, *a14+, 1 ; bitmap_pad = 32
|
||||
0168 00000D00 09E0 movi 32, a0, L
|
||||
00000D10 00000020
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 5
|
||||
|
||||
0169 00000D30 920E move a0, *a14+, 1 ; height
|
||||
0170 00000D40 920E move a0, *a14+, 1 ; width
|
||||
0171 00000D50 09E0 movi BITMAP, a0, L
|
||||
00000D60 00000000"
|
||||
0172 00000D80 920E move a0, *a14+, 1 ; data
|
||||
0173 00000D90 09E0 movi 0, a0, L
|
||||
00000DA0 00000000
|
||||
0174 00000DC0 920E move a0, *a14+, 1 ; offset
|
||||
0175 00000DD0 920E move a0, *a14+, 1 ; format = 0 (XYBitmap)
|
||||
0176 00000DE0 09E0 movi 1, a0, L
|
||||
00000DF0 00000001
|
||||
0177 00000E10 920E move a0, *a14+, 1 ; depth = 1
|
||||
0178 00000E20 4400 sub a0, a0
|
||||
0179 00000E30 920E move a0, *a14+, 1 ; visual = NULL
|
||||
0180 00000E40 936E move a11, *a14+, 1 ; display
|
||||
0181 00000E50 0D5F calla 3F9A0490h ; XCreateImage
|
||||
00000E60 3F9A0490
|
||||
0182 00000E80 0550 setf 16, 0, 0
|
||||
0183 00000E90 0740 setf 32, 0, 1
|
||||
0184 00000EA0 4D07 move a8, a7 ; image (a7 survives XPutImage)
|
||||
0185 00000EB0 0788 move a8, @01890160h, 1 ; MARK image
|
||||
00000EC0 01890160
|
||||
0186 00000EE0 0788 move a8, @m_image, 1
|
||||
00000EF0 00000080+
|
||||
0187 00000F10 4D08 move a8, a8
|
||||
0188 00000F20 CA00 jreq fail_img
|
||||
00000F30 00B0
|
||||
0189 00000F40 09E0 movi 6, a0, L
|
||||
00000F50 00000006
|
||||
0190 00000F70 0780 move a0, @01890140h, 1 ; stage = 6
|
||||
00000F80 01890140
|
||||
0191 00000FA0 0780 move a0, @m_stage, 1
|
||||
00000FB0 00000000+
|
||||
0192
|
||||
0193 ; ---- let the WM frame/reparent and map the window (x
|
||||
0194 ; A draw issued before the reparent can be lost, so sy
|
||||
0195 00000FD0 09EC movi 4, a12, L
|
||||
00000FE0 00000004
|
||||
0196 00001000 map_wait:
|
||||
0197 00001000 A3CF move a14, -*sp, 1
|
||||
0198 00001010 09EE movi 01894000h, a14, L
|
||||
00001020 01894000
|
||||
0199 00001040 09E0 movi 0, a0, L
|
||||
00001050 00000000
|
||||
0200 00001070 920E move a0, *a14+, 1 ; discard = 0
|
||||
0201 00001080 936E move a11, *a14+, 1 ; display
|
||||
0202 00001090 0D5F calla 3FD9F6B0h ; XSync
|
||||
000010A0 3FD9F6B0
|
||||
0203 000010C0 0550 setf 16, 0, 0
|
||||
0204 000010D0 0740 setf 32, 0, 1
|
||||
0205 000010E0 3DEC dsjs a12, map_wait
|
||||
0206
|
||||
0207 ; ---- XPutImage(d, win, gc, image, 0,0, 20,20, 32,32)
|
||||
0208 000010F0 A3CF move a14, -*sp, 1
|
||||
0209 00001100 09EE movi 01894000h, a14, L
|
||||
00001110 01894000
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 6
|
||||
|
||||
0210 00001130 09E0 movi 32, a0, L
|
||||
00001140 00000020
|
||||
0211 00001160 920E move a0, *a14+, 1 ; h
|
||||
0212 00001170 920E move a0, *a14+, 1 ; w
|
||||
0213 00001180 09E0 movi 20, a0, L
|
||||
00001190 00000014
|
||||
0214 000011B0 920E move a0, *a14+, 1 ; dst_y
|
||||
0215 000011C0 920E move a0, *a14+, 1 ; dst_x
|
||||
0216 000011D0 4400 sub a0, a0
|
||||
0217 000011E0 920E move a0, *a14+, 1 ; src_y
|
||||
0218 000011F0 920E move a0, *a14+, 1 ; src_x
|
||||
0219 00001200 92EE move a7, *a14+, 1 ; image
|
||||
0220 00001210 932E move a9, *a14+, 1 ; gc
|
||||
0221 00001220 934E move a10, *a14+, 1 ; drawable
|
||||
0222 00001230 936E move a11, *a14+, 1 ; display
|
||||
0223 00001240 0D5F calla 3F9D0370h ; XPutImage
|
||||
00001250 3F9D0370
|
||||
0224 00001270 0550 setf 16, 0, 0
|
||||
0225 00001280 0740 setf 32, 0, 1
|
||||
0226 00001290 0788 move a8, @018901A0h, 1 ; MARK putimage return
|
||||
000012A0 018901A0
|
||||
0227 000012C0 0788 move a8, @m_putret, 1
|
||||
000012D0 000000A0+
|
||||
0228 000012F0 09E0 movi 7, a0, L
|
||||
00001300 00000007
|
||||
0229 00001320 0780 move a0, @01890140h, 1 ; stage = 7
|
||||
00001330 01890140
|
||||
0230 00001350 0780 move a0, @m_stage, 1
|
||||
00001360 00000000+
|
||||
0231
|
||||
0232 ; ---- control: the same image with h = 16 at dst_y =
|
||||
0233 ; The PNG must show exactly 16 rows here (src rows 0..
|
||||
0234 ; what proves the 32-row draw above is the image, not
|
||||
0235 00001380 A3CF move a14, -*sp, 1
|
||||
0236 00001390 09EE movi 01894000h, a14, L
|
||||
000013A0 01894000
|
||||
0237 000013C0 09E0 movi 16, a0, L
|
||||
000013D0 00000010
|
||||
0238 000013F0 920E move a0, *a14+, 1 ; h = 16
|
||||
0239 00001400 09E0 movi 32, a0, L
|
||||
00001410 00000020
|
||||
0240 00001430 920E move a0, *a14+, 1 ; w = 32
|
||||
0241 00001440 09E0 movi 60, a0, L
|
||||
00001450 0000003C
|
||||
0242 00001470 920E move a0, *a14+, 1 ; dst_y = 60
|
||||
0243 00001480 09E0 movi 20, a0, L
|
||||
00001490 00000014
|
||||
0244 000014B0 920E move a0, *a14+, 1 ; dst_x = 20
|
||||
0245 000014C0 4400 sub a0, a0
|
||||
0246 000014D0 920E move a0, *a14+, 1 ; src_y = 0
|
||||
0247 000014E0 920E move a0, *a14+, 1 ; src_x = 0
|
||||
0248 000014F0 92EE move a7, *a14+, 1 ; image
|
||||
0249 00001500 932E move a9, *a14+, 1 ; gc
|
||||
0250 00001510 934E move a10, *a14+, 1 ; drawable
|
||||
0251 00001520 936E move a11, *a14+, 1 ; display
|
||||
0252 00001530 0D5F calla 3F9D0370h ; XPutImage
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 7
|
||||
|
||||
00001540 3F9D0370
|
||||
0253 00001560 0550 setf 16, 0, 0
|
||||
0254 00001570 0740 setf 32, 0, 1
|
||||
0255
|
||||
0256 ; ---- flush, twice: the request is only in the client
|
||||
0257 00001580 A3CF move a14, -*sp, 1
|
||||
0258 00001590 09EE movi 01894000h, a14, L
|
||||
000015A0 01894000
|
||||
0259 000015C0 09E0 movi 0, a0, L
|
||||
000015D0 00000000
|
||||
0260 000015F0 920E move a0, *a14+, 1
|
||||
0261 00001600 936E move a11, *a14+, 1
|
||||
0262 00001610 0D5F calla 3FD9F6B0h ; XSync
|
||||
00001620 3FD9F6B0
|
||||
0263 00001640 0550 setf 16, 0, 0
|
||||
0264 00001650 0740 setf 32, 0, 1
|
||||
0265 00001660 0788 move a8, @018901C0h, 1 ; MARK sync return
|
||||
00001670 018901C0
|
||||
0266 00001690 0788 move a8, @m_syncret, 1
|
||||
000016A0 000000C0+
|
||||
0267
|
||||
0268 000016C0 A3CF move a14, -*sp, 1
|
||||
0269 000016D0 09EE movi 01894000h, a14, L
|
||||
000016E0 01894000
|
||||
0270 00001700 09E0 movi 0, a0, L
|
||||
00001710 00000000
|
||||
0271 00001730 920E move a0, *a14+, 1
|
||||
0272 00001740 936E move a11, *a14+, 1
|
||||
0273 00001750 0D5F calla 3FD9F6B0h ; XSync
|
||||
00001760 3FD9F6B0
|
||||
0274 00001780 0550 setf 16, 0, 0
|
||||
0275 00001790 0740 setf 32, 0, 1
|
||||
0276 000017A0 0788 move a8, @018901C0h, 1
|
||||
000017B0 018901C0
|
||||
0277 000017D0 0788 move a8, @m_syncret, 1
|
||||
000017E0 000000C0+
|
||||
0278
|
||||
0279 00001800 09E0 movi 8, a0, L
|
||||
00001810 00000008
|
||||
0280 00001830 0780 move a0, @01890140h, 1 ; stage = 8
|
||||
00001840 01890140
|
||||
0281 00001860 0780 move a0, @m_stage, 1
|
||||
00001870 00000000+
|
||||
0282
|
||||
0283 ; ---- XDestroyImage(image) --------------------------
|
||||
0284 00001890 A3CF move a14, -*sp, 1
|
||||
0285 000018A0 09EE movi 01894000h, a14, L
|
||||
000018B0 01894000
|
||||
0286 000018D0 92EE move a7, *a14+, 1
|
||||
0287 000018E0 0D5F calla 3F9A0D80h ; XDestroyImage
|
||||
000018F0 3F9A0D80
|
||||
0288 00001910 0550 setf 16, 0, 0
|
||||
0289 00001920 0740 setf 32, 0, 1
|
||||
0290 00001930 C01A jruc done
|
||||
0291
|
||||
0292 00001940 fail_abi:
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 8
|
||||
|
||||
0293 00001940 09E0 movi 091h, a0, L
|
||||
00001950 00000091
|
||||
0294 00001970 C010 jruc failed
|
||||
0295 00001980 fail_open:
|
||||
0296 00001980 09E0 movi 092h, a0, L
|
||||
00001990 00000092
|
||||
0297 000019B0 C00C jruc failed
|
||||
0298 000019C0 fail_win:
|
||||
0299 000019C0 09E0 movi 093h, a0, L
|
||||
000019D0 00000093
|
||||
0300 000019F0 C008 jruc failed
|
||||
0301 00001A00 fail_gc:
|
||||
0302 00001A00 09E0 movi 095h, a0, L
|
||||
00001A10 00000095
|
||||
0303 00001A30 C004 jruc failed
|
||||
0304 00001A40 fail_img:
|
||||
0305 00001A40 09E0 movi 096h, a0, L
|
||||
00001A50 00000096
|
||||
0306 00001A70 0300 jruc failed
|
||||
0307 00001A80 failed:
|
||||
0308 00001A80 0780 move a0, @01890140h, 1
|
||||
00001A90 01890140
|
||||
0309 00001AB0 0780 move a0, @m_stage, 1
|
||||
00001AC0 00000000+
|
||||
0310
|
||||
0311 00001AE0 done:
|
||||
0312 00001AE0 09AF mmfm sp, a0,a1,a2,a3,a4,a5,a6,a7
|
||||
00001AF0 00FF
|
||||
0313 00001B00 09E8 movi 0, a8, L
|
||||
00001B10 00000000
|
||||
0314 00001B30 0960 rets
|
||||
0315
|
||||
0316 00000000 .data
|
||||
0317 ; 32 rows of 4 bytes, LSB-first pixels: a solid row at
|
||||
0318 ; at y=31, and a one-pixel diagonal between them. The
|
||||
0319 ; rows make the drawn height readable straight off the
|
||||
0320 00000000 BITMAP:
|
||||
0321 00000000 FF .byte 0FFh, 0FFh, 0FFh, 0FFh, 002h, 000h, 000h, 000h
|
||||
00000008 FF
|
||||
00000010 FF
|
||||
00000018 FF
|
||||
00000020 02
|
||||
00000028 00
|
||||
00000030 00
|
||||
00000038 00
|
||||
0322 00000040 04 .byte 004h, 000h, 000h, 000h, 008h, 000h, 000h, 000h
|
||||
00000048 00
|
||||
00000050 00
|
||||
00000058 00
|
||||
00000060 08
|
||||
00000068 00
|
||||
00000070 00
|
||||
00000078 00
|
||||
0323 00000080 10 .byte 010h, 000h, 000h, 000h, 020h, 000h, 000h, 000h
|
||||
00000088 00
|
||||
00000090 00
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 9
|
||||
|
||||
00000098 00
|
||||
000000A0 20
|
||||
000000A8 00
|
||||
000000B0 00
|
||||
000000B8 00
|
||||
0324 000000C0 40 .byte 040h, 000h, 000h, 000h, 080h, 000h, 000h, 000h
|
||||
000000C8 00
|
||||
000000D0 00
|
||||
000000D8 00
|
||||
000000E0 80
|
||||
000000E8 00
|
||||
000000F0 00
|
||||
000000F8 00
|
||||
0325 00000100 00 .byte 000h, 001h, 000h, 000h, 000h, 002h, 000h, 000h
|
||||
00000108 01
|
||||
00000110 00
|
||||
00000118 00
|
||||
00000120 00
|
||||
00000128 02
|
||||
00000130 00
|
||||
00000138 00
|
||||
0326 00000140 00 .byte 000h, 004h, 000h, 000h, 000h, 008h, 000h, 000h
|
||||
00000148 04
|
||||
00000150 00
|
||||
00000158 00
|
||||
00000160 00
|
||||
00000168 08
|
||||
00000170 00
|
||||
00000178 00
|
||||
0327 00000180 00 .byte 000h, 010h, 000h, 000h, 000h, 020h, 000h, 000h
|
||||
00000188 10
|
||||
00000190 00
|
||||
00000198 00
|
||||
000001A0 00
|
||||
000001A8 20
|
||||
000001B0 00
|
||||
000001B8 00
|
||||
0328 000001C0 00 .byte 000h, 040h, 000h, 000h, 000h, 080h, 000h, 000h
|
||||
000001C8 40
|
||||
000001D0 00
|
||||
000001D8 00
|
||||
000001E0 00
|
||||
000001E8 80
|
||||
000001F0 00
|
||||
000001F8 00
|
||||
0329 00000200 00 .byte 000h, 000h, 001h, 000h, 000h, 000h, 002h, 000h
|
||||
00000208 00
|
||||
00000210 01
|
||||
00000218 00
|
||||
00000220 00
|
||||
00000228 00
|
||||
00000230 02
|
||||
00000238 00
|
||||
0330 00000240 00 .byte 000h, 000h, 004h, 000h, 000h, 000h, 008h, 000h
|
||||
00000248 00
|
||||
00000250 04
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 10
|
||||
|
||||
00000258 00
|
||||
00000260 00
|
||||
00000268 00
|
||||
00000270 08
|
||||
00000278 00
|
||||
0331 00000280 00 .byte 000h, 000h, 010h, 000h, 000h, 000h, 020h, 000h
|
||||
00000288 00
|
||||
00000290 10
|
||||
00000298 00
|
||||
000002A0 00
|
||||
000002A8 00
|
||||
000002B0 20
|
||||
000002B8 00
|
||||
0332 000002C0 00 .byte 000h, 000h, 040h, 000h, 000h, 000h, 080h, 000h
|
||||
000002C8 00
|
||||
000002D0 40
|
||||
000002D8 00
|
||||
000002E0 00
|
||||
000002E8 00
|
||||
000002F0 80
|
||||
000002F8 00
|
||||
0333 00000300 00 .byte 000h, 000h, 000h, 001h, 000h, 000h, 000h, 002h
|
||||
00000308 00
|
||||
00000310 00
|
||||
00000318 01
|
||||
00000320 00
|
||||
00000328 00
|
||||
00000330 00
|
||||
00000338 02
|
||||
0334 00000340 00 .byte 000h, 000h, 000h, 004h, 000h, 000h, 000h, 008h
|
||||
00000348 00
|
||||
00000350 00
|
||||
00000358 04
|
||||
00000360 00
|
||||
00000368 00
|
||||
00000370 00
|
||||
00000378 08
|
||||
0335 00000380 00 .byte 000h, 000h, 000h, 010h, 000h, 000h, 000h, 020h
|
||||
00000388 00
|
||||
00000390 00
|
||||
00000398 10
|
||||
000003A0 00
|
||||
000003A8 00
|
||||
000003B0 00
|
||||
000003B8 20
|
||||
0336 000003C0 00 .byte 000h, 000h, 000h, 040h, 0FFh, 0FFh, 0FFh, 0FFh
|
||||
000003C8 00
|
||||
000003D0 00
|
||||
000003D8 40
|
||||
000003E0 FF
|
||||
000003E8 FF
|
||||
000003F0 FF
|
||||
000003F8 FF
|
||||
0337 00000400 BITMAP_END:
|
||||
0338
|
||||
0339 00000000 .bss m_stage, 32, 1
|
||||
GSP COFF Assembler, Version 2.00, 87.300 Fri Nov 13 09:31:54 2026
|
||||
(c) Copyright 1985, 1987, Texas Instruments Inc.
|
||||
|
||||
PAGE 11
|
||||
|
||||
0340 00000020 .bss m_display, 32, 1
|
||||
0341 00000040 .bss m_window, 32, 1
|
||||
0342 00000060 .bss m_gc, 32, 1
|
||||
0343 00000080 .bss m_image, 32, 1
|
||||
0344 000000A0 .bss m_putret, 32, 1
|
||||
0345 000000C0 .bss m_syncret, 32, 1
|
||||
0346 000000E0 .bss m_strlen, 32, 1
|
||||
0347
|
||||
0348 .end
|
||||
|
||||
No Errors, No Warnings
|
||||
@@ -0,0 +1,36 @@
|
||||
*****************************************************
|
||||
GSP COFF Linker, Version 2.00, 87.300
|
||||
*****************************************************
|
||||
Fri Nov 13 09:31:54 2026
|
||||
|
||||
OUTPUT FILE NAME: <XSHOW.out>
|
||||
ENTRY POINT SYMBOL: 0
|
||||
|
||||
|
||||
SECTION ALLOCATION MAP
|
||||
|
||||
output attributes/
|
||||
section page origin length input sections
|
||||
-------- ---- ---------- ---------- ----------------
|
||||
.text 0 01840000 00001B40
|
||||
01840000 00001B40 XSHOW.obj (.text)
|
||||
|
||||
.data 0 018D0000 00000400
|
||||
018D0000 00000400 XSHOW.obj (.data)
|
||||
|
||||
.bss 0 018D8000 00000100 UNINITIALIZED
|
||||
018D8000 00000100 XSHOW.obj (.bss)
|
||||
|
||||
|
||||
GLOBAL SYMBOLS
|
||||
|
||||
address name address name
|
||||
-------- ---- -------- ----
|
||||
018D8000 .bss 01840000 .text
|
||||
018D0000 .data 01841B40 etext
|
||||
01840000 .text 018D0000 .data
|
||||
018D0400 edata 018D0400 edata
|
||||
018D8100 end 018D8000 .bss
|
||||
01841B40 etext 018D8100 end
|
||||
|
||||
[6 symbols]
|
||||
@@ -0,0 +1,92 @@
|
||||
# vt_install_xg() acceptance run — 2026-11-13
|
||||
|
||||
Host: Linux, MAME 0.289 single-driver binary
|
||||
`/home/arti/code/k-space/mame0289/vt1200`.
|
||||
Worktree: `fix/issue-2-xg-block` (docs + `dwt/loader/xg.c`).
|
||||
|
||||
The ROM is unchanged before and after the runs:
|
||||
|
||||
```
|
||||
$ md5sum vt1200_v22.bin
|
||||
b46a3e442ccb86134d2356bd70d22fd2 vt1200_v22.bin
|
||||
```
|
||||
|
||||
The client is the **unmodified** termtris smoke test
|
||||
(`apps/termtris/tests/smoke.c`), which calls `vt_install_xg()`, then
|
||||
`XOpenDisplay("0::0")`, creates and maps a window, selects input, and waits for
|
||||
a `KeyPress`. Only the helper source differs between the two runs: the first
|
||||
links `dwt/loader/xg.c`, the second a stub that installs nothing.
|
||||
|
||||
## Build
|
||||
|
||||
```
|
||||
$ apps/termtris/build.sh apps/termtris/tests/smoke.c dwt/loader/xg.c
|
||||
```
|
||||
|
||||
Link map excerpt (`apps/termtris/build/smoke.map`):
|
||||
|
||||
```
|
||||
.text 0 018a0000 00000da0
|
||||
018a0b30 00000270 XG.obj (.text)
|
||||
.bss 0 01a00000 0000a700 UNINITIALIZED
|
||||
01a08700 00002000 XG.obj (.bss)
|
||||
```
|
||||
|
||||
`MARK` is the first `_mark` symbol in the map, `0x01a08000`.
|
||||
|
||||
## Run — helper installed
|
||||
|
||||
```
|
||||
$ HOME=/tmp/opencode/vt1200-task2/home VT1200_SKIP_LEVEL1=1 \
|
||||
SMOKE_MARK=0x01a08000 LOADER_AT=2500 LOADER_END=3400 \
|
||||
LOADER_BIN=$PWD/dwt/loader/build/loader.bin \
|
||||
LOADER_COFF=$PWD/apps/termtris/build/smoke.coff \
|
||||
LOADER_OUT=/tmp/opencode/vt1200-task2 \
|
||||
/home/arti/code/k-space/mame0289/vt1200 vt1200 \
|
||||
-rompath harness/mame/roms -video none -sound none -nothrottle \
|
||||
-skip_gameinfo -cfg_directory /tmp/opencode/vt1200-task2/cfg \
|
||||
-nvram_directory /tmp/opencode/vt1200-task2/nvram \
|
||||
-debug -debugger none -autoboot_script apps/termtris/tests/smoke.lua \
|
||||
-autoboot_delay 0
|
||||
```
|
||||
|
||||
Relevant output:
|
||||
|
||||
```
|
||||
LOADER: result status=0 (OK) entry=018A0000 text=018A0000/3488 bits data=018A0DA0/16 bits bss=01A00000/42752 bits relocs=0 pcb=003FEE50 nscns=4 len=1349
|
||||
LOADER: placed .text at 018A0000: 436 bytes, 0 differing
|
||||
LOADER: placed .cinit at 018A0DA0: 2 bytes, 0 differing
|
||||
SMOKE: magic=534D4F4B dpy=00942290 win=00400001 n=9 type=2 keycode=194 lookup_n=1 ch=61 ks=0061 keymark=4B455950
|
||||
LOADER: PC at inspection = 3F579870
|
||||
```
|
||||
|
||||
`type=2` is `KeyPress`, `keycode=194` is the LK401 `A`, and `keymark=4B455950`
|
||||
("KEYP") is the client's own marker: the real event reached the client.
|
||||
|
||||
## Control — helper replaced by a stub
|
||||
|
||||
The stub (`/tmp/opencode/vt1200-task2/xgstub.c`) is:
|
||||
|
||||
```c
|
||||
int
|
||||
vt_install_xg(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
```
|
||||
|
||||
Built as `OUTNAME=smokectl apps/termtris/build.sh apps/termtris/tests/smoke.c
|
||||
/tmp/opencode/vt1200-task2/xgstub.c`, then run with the same command and private
|
||||
directories (`...-ctl-home`, `...-ctl-cfg`, `...-ctl-nvram`) and
|
||||
`LOADER_COFF=apps/termtris/build/smokectl.coff`:
|
||||
|
||||
```
|
||||
LOADER: result status=0 (OK) entry=018A0000 text=018A0000/2896 bits data=018A0B50/16 bits bss=01A00000/34560 bits relocs=0 pcb=003FEE50 nscns=4 len=1275
|
||||
SMOKE: magic=534D4F4B dpy=00942290 win=00400001 n=10 type=0 keycode=0 lookup_n=0 ch=00 ks=0000 keymark=00000000
|
||||
LOADER: PC at inspection = 3F579870
|
||||
```
|
||||
|
||||
The display opens (`dpy=00942290`) and the window is created and mapped
|
||||
(`win=00400001`), exactly as in the passing run. The event loop runs 10
|
||||
iterations, but every record is `type=0 keycode=0` and `keymark` stays zero: no
|
||||
real event ever arrives. This is the symptom the helper exists to prevent.
|
||||
@@ -17,9 +17,10 @@
|
||||
-- LOADER_COFF app COFF (default dwt/loader/build/marker.coff)
|
||||
-- LOADER_BUF COFF buffer bit address (default 0x01900000)
|
||||
-- LOADER_AT injection frame (default 2500)
|
||||
-- LOADER_END inspection/exit frame (default 2700)
|
||||
-- LOADER_END inspection/exit frame (default 2700; 0 = wait for completion)
|
||||
-- LOADER_MAX LOADER_END=0 only: give up after this many frames (default 6000)
|
||||
-- LOADER_OUT evidence directory (default dwt/loader/evidence)
|
||||
-- LOADER_SNAP 1 = write a PNG at LOADER_END (default 0)
|
||||
-- LOADER_SNAP 1 = write a PNG at the exit frame (default 0)
|
||||
-- LOADER_VERBOSE 1 = print the result block every 25 frames
|
||||
|
||||
local function hex(v, w) return string.format("%0" .. (w or 8) .. "X", v) end
|
||||
@@ -37,6 +38,9 @@ end
|
||||
|
||||
local AT = tonumber(os.getenv("LOADER_AT") or "2500")
|
||||
local ENDF = tonumber(os.getenv("LOADER_END") or "2700")
|
||||
local MAXF = tonumber(os.getenv("LOADER_MAX") or "6000")
|
||||
local WAIT = ENDF == 0
|
||||
local STABLE = 10
|
||||
local BIN = os.getenv("LOADER_BIN") or "dwt/loader/build/loader.bin"
|
||||
local COFF = os.getenv("LOADER_COFF") or "dwt/loader/build/marker.coff"
|
||||
local BUF = tonumber(os.getenv("LOADER_BUF") or "0x01900000")
|
||||
@@ -177,6 +181,42 @@ local function result_dump()
|
||||
r32(RESULT + 0x140), r32(RESULT + 0x160)))
|
||||
end
|
||||
|
||||
-- The loader writes RESULT_STATUS last (it is 0xFFFFFFFF until then). The
|
||||
-- whole result block is the completion signal: status written, PC out of the
|
||||
-- loader's entry page, and the block unchanged for STABLE frames. This keeps
|
||||
-- a write that is still in progress from looking final.
|
||||
local RESULT_CELLS = { 0x000, 0x020, 0x040, 0x060, 0x080, 0x0A0, 0x0C0,
|
||||
0x0E0, 0x100, 0x120, 0x140, 0x160, 0x180 }
|
||||
|
||||
local function result_signature()
|
||||
local t = {}
|
||||
for i, off in ipairs(RESULT_CELLS) do
|
||||
t[i] = string.format("%08X", r32(RESULT + off))
|
||||
end
|
||||
return table.concat(t, " ")
|
||||
end
|
||||
|
||||
local stable_signature = nil
|
||||
local stable_frames = 0
|
||||
|
||||
local function complete()
|
||||
local st = r32(RESULT + 0x000)
|
||||
local pc = cpu.state['PC'].value
|
||||
if st == 0xFFFFFFFF or (pc >= LOADER_BASE and pc < LOADER_BASE + 0x400) then
|
||||
stable_signature = nil
|
||||
stable_frames = 0
|
||||
return false
|
||||
end
|
||||
local sig = result_signature()
|
||||
if sig == stable_signature then
|
||||
stable_frames = stable_frames + 1
|
||||
else
|
||||
stable_signature = sig
|
||||
stable_frames = 1
|
||||
end
|
||||
return stable_frames >= STABLE
|
||||
end
|
||||
|
||||
local function inject()
|
||||
-- 1. loader itself
|
||||
local n, bad = 0, 0
|
||||
@@ -273,6 +313,26 @@ local function inspect()
|
||||
print(string.format("LOADER: PC at inspection = %s", hex(cpu.state['PC'].value)))
|
||||
end
|
||||
|
||||
local finished = false
|
||||
local function finish()
|
||||
if finished then return end
|
||||
finished = true
|
||||
if injected then
|
||||
inspect()
|
||||
if SNAP then
|
||||
local screen = nil
|
||||
for _, s in pairs(machine.screens) do screen = s break end
|
||||
if screen then
|
||||
local out = OUT .. "/loader_frame" .. frames .. ".png"
|
||||
local ok, err = pcall(function() return screen:snapshot(out) end)
|
||||
print(string.format("LOADER: snapshot %s ok=%s %s",
|
||||
out, tostring(ok), tostring(err or "")))
|
||||
end
|
||||
end
|
||||
end
|
||||
machine:exit()
|
||||
end
|
||||
|
||||
emu.register_frame_done(function()
|
||||
frames = frames + 1
|
||||
if frames == AT and not injected then
|
||||
@@ -283,20 +343,23 @@ emu.register_frame_done(function()
|
||||
dbg:command("trace off")
|
||||
print("LOADER: trace written to /tmp/opencode/ld.tr")
|
||||
end
|
||||
if injected and not done then
|
||||
if injected then
|
||||
if TRACE and frames <= AT + 40 then
|
||||
print(string.format("LOADER: trace f=%d PC=%s SP=%s A14=%s status=%s entry=%s",
|
||||
frames, hex(cpu.state['PC'].value), hex(cpu.state['SP'].value),
|
||||
hex(cpu.state['A14'].value), hex(r32(RESULT + 0x000)),
|
||||
hex(r32(RESULT + 0x020))))
|
||||
end
|
||||
local st = r32(RESULT + 0x000)
|
||||
-- status 0 means OK; nonzero is final too once parsing has begun
|
||||
if st ~= 0xFFFFFFFF and not done then
|
||||
-- The loader writes 0 on success. A nonzero status is final
|
||||
-- only after it has been written once (it is 0 from power-on,
|
||||
-- so require the loader to have run: PC no longer at entry or
|
||||
-- the app counter moved).
|
||||
-- Status 0 means OK; any nonzero status the loader wrote is final too.
|
||||
-- done is set exactly once, on the frame completion is detected.
|
||||
if not done and complete() then
|
||||
done = true
|
||||
print(string.format("LOADER: complete at frame %d status=%s",
|
||||
frames, hex(r32(RESULT + 0x000))))
|
||||
if WAIT then
|
||||
finish()
|
||||
return
|
||||
end
|
||||
end
|
||||
if VERBOSE and frames % 25 == 0 then
|
||||
result_dump()
|
||||
@@ -312,22 +375,22 @@ emu.register_frame_done(function()
|
||||
end
|
||||
end
|
||||
end
|
||||
if frames >= ENDF then
|
||||
if injected then
|
||||
done = true
|
||||
inspect()
|
||||
if SNAP then
|
||||
local screen = nil
|
||||
for _, s in pairs(machine.screens) do screen = s break end
|
||||
if screen then
|
||||
local out = OUT .. "/loader_frame" .. frames .. ".png"
|
||||
local ok, err = pcall(function() return screen:snapshot(out) end)
|
||||
print(string.format("LOADER: snapshot %s ok=%s %s",
|
||||
out, tostring(ok), tostring(err or "")))
|
||||
end
|
||||
if WAIT then
|
||||
-- LOADER_END=0: run until completion, but never forever.
|
||||
if frames >= MAXF then
|
||||
if not done then
|
||||
print(string.format("LOADER: warning: app still in startup at LOADER_MAX=%d", MAXF))
|
||||
end
|
||||
finish()
|
||||
end
|
||||
machine:exit()
|
||||
elseif frames >= ENDF then
|
||||
-- A fixed LOADER_END still exits at that frame (the snapshot contract;
|
||||
-- existing tests read loader_frame<ENDF>.png). Completion is reported
|
||||
-- above but only LOADER_END=0 asks to exit early.
|
||||
if not done then
|
||||
print(string.format("LOADER: warning: app still in startup at LOADER_END=%d", ENDF))
|
||||
end
|
||||
finish()
|
||||
end
|
||||
end, "vt1200-loader")
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* xg.c -- install a per-process Xlib context before XOpenDisplay.
|
||||
*
|
||||
* A process created by `create_process` inherits a per-process user block: the
|
||||
* current PCB is *(u32 *)0x001B3900 and its cell at bit +0x100 points at that
|
||||
* block. The first word of the block is the per-process Xlib context (XG),
|
||||
* and it is zero in a fresh child. The ROM Xlib's event code (XNextEvent,
|
||||
* 0x3F9C1CF0, and its enqueue helper, 0x3F9B89A0) does
|
||||
*
|
||||
* XG = *(*(proc + 0x100)); ; three loads, see xg_install below
|
||||
* free_list = *(XG + 0xCC0); ; bits = byte 0x198 of the block
|
||||
*
|
||||
* so a child with XG == 0 treats low RAM as its event queue: windows, mapping
|
||||
* and drawing still work, but XNextEvent never delivers an event. This
|
||||
* helper gives the child a zeroed 1 KiB block. It is a RAM write only; the
|
||||
* ROM is untouched.
|
||||
*
|
||||
* Addresses are TMS34010 bit addresses, as everywhere on this CPU: +0x100 is
|
||||
* 32 bytes into the PCB and the free-list field is at byte 0x198 of the block.
|
||||
*
|
||||
* This is the same code as apps/termtris/src/vt1200/xgfix.c. Build it with
|
||||
* the C client (apps/termtris/build.sh <main>.c dwt/loader/xg.c) or copy it
|
||||
* into the app's source tree; declare `extern int vt_install_xg(void);` and
|
||||
* call it once, before XOpenDisplay.
|
||||
*/
|
||||
typedef unsigned long vt_u32;
|
||||
|
||||
static vt_u32 vt_xg[256]; /* 1 KiB: covers the 0x198-byte free-list field */
|
||||
|
||||
int
|
||||
vt_install_xg(void)
|
||||
{
|
||||
vt_u32 proc, pp;
|
||||
int i;
|
||||
|
||||
proc = *(volatile vt_u32 *)0x001B3900UL;
|
||||
if(proc < 0x100UL || proc > 0x01FFFFFFUL)
|
||||
return 0;
|
||||
pp = *(volatile vt_u32 *)(proc + 0x100UL);
|
||||
if(pp < 0x100UL || pp > 0x01FFFFFFUL)
|
||||
return 0;
|
||||
|
||||
for(i = 0; i < 256; i++)
|
||||
vt_xg[i] = 0;
|
||||
*(volatile vt_u32 *)pp = (vt_u32)vt_xg;
|
||||
return 1;
|
||||
}
|
||||
@@ -362,7 +362,8 @@ Facts for anyone tempted to "just create a window" (details in
|
||||
(`0x7EE160C` / lookup `0x7EE1B70`). TCP 6000 is a separate, user/node
|
||||
authorised listener.
|
||||
* Xlib entry points (bit addresses): `XOpenDisplay` `0x3F9C2570`,
|
||||
`XCreateSimpleWindow` `0x3FD41B90`, `XMapWindow` `0x3FD645B0`,
|
||||
`XCreateSimpleWindow` `0x3FD41B90`, `XMapWindow` `0x3FD64F60`,
|
||||
`XRaiseWindow` `0x3FD645B0` (ConfigureWindow/CWStackMode, does not map),
|
||||
`XSync` `0x3FD9F6B0`, `XCreateGC` `0x3F997000`, `XDrawString` `0x3FDA0000`.
|
||||
* **Live result:** a 390-byte payload (poke+jump, no breakpoints) called
|
||||
`strlen("0::0")` successfully (returned 4) using the firmware ABI, then
|
||||
|
||||
@@ -44,7 +44,7 @@ WM `@0x27AA80`).
|
||||
| what | Ghidra | bits | notes |
|
||||
|---|---|---|---|
|
||||
| `create_process(entry,name,stack,1,arg)` | `0x07EE0D48` | `0x3F706A40` | mallocs a 0x39-byte PCB, copies the name, allocates the stack, links it at `@0x1B3860` |
|
||||
| current-process pointer | — | `0x1B3900` | `+0x100` = user area (fd table) |
|
||||
| current-process pointer | — | `0x1B3900` | `+0x100` = user area (fd table); its first word is the per-process Xlib context (§10.5) |
|
||||
| process list head | — | `0x1B3860` | |
|
||||
| `Main Program` (creates SERVER + SESSIONMGR) | `0x07E69B6A`…`0x07E69C1A` | `0x3F34DB50` | itself a created process (name `Main Program`) |
|
||||
| X server entry **SERVER** | `0x07E6C522` | `0x3F362910` | dix main; prints `Hello, this is the X server` |
|
||||
@@ -76,8 +76,9 @@ request buffer), which is how these were named; the DB26 `XDrawString` and DB25
|
||||
| `XOpenDisplay(name)` | `0x07F384AE` | `0x3F9C2570` | mallocs 0x4D8, parses the name, connects |
|
||||
| `XParseDisplay` / service lookup | `0x07FA7538` | `0x3FD3A9C0` | splits `host:display.screen`, resolves `"xserver"` |
|
||||
| `XCreateSimpleWindow(d,p,x,y,w,h,bw,border,bg)` | `0x07FA8372` | `0x3FD41B90` | opcode 1, 9 args |
|
||||
| `XMapWindow(d,w)` | `0x07FAC8B6` | `0x3FD645B0` | opcode 8, 2 args |
|
||||
| `XRaiseWindow(d,w)` | `0x07FAC8B6` | `0x3FD645B0` | ConfigureWindow, opcode 12, `CWStackMode` mask `0x40`, value `Above` (0) |
|
||||
| `XMapSubwindows(d,w)` | `0x07FAC97E` | `0x3FD64BF0` | opcode 9 |
|
||||
| `XMapWindow(d,w)` | `0x07FAC9EC` | `0x3FD64F60` | opcode 8 (MapWindow), 2 args |
|
||||
| `XSelectInput(d,w,mask)` | `0x07FB2FAA` | `0x3FD97D50` | ChangeWindowAttributes, mask 0x800 |
|
||||
| `XChangeWindowAttributes` | `0x07FA70EE` | `0x3FD38770` | opcode 2 |
|
||||
| `XConfigureWindow` | `0x07FA74A2` | `0x3FD3A510` | opcode 12 |
|
||||
@@ -93,6 +94,176 @@ request buffer), which is how these were named; the DB26 `XDrawString` and DB25
|
||||
| internal PolyFillRectangle fast path | `0x07F33D1E` | `0x3F99E8F0` | opcode 70; not a public entry point |
|
||||
| `strlen` | `0x07F68B1A` | `0x3FB458D0` | used as the ABI check |
|
||||
|
||||
**Drift check.** The map/raise pair was mislabelled for a long time, so pin the
|
||||
names to the request byte rather than to memory. From the repo root:
|
||||
|
||||
```
|
||||
tools/smart34010/dis34 -l -o -b 3FD64F60 -s 0x16C9EC vt1200_v22.bin
|
||||
# expect: movk 8, a11 ; movb ... *a10 -> MapWindow, opcode 8, length 2
|
||||
tools/smart34010/dis34 -l -o -b 3FD645B0 -s 0x16C8B6 vt1200_v22.bin
|
||||
# expect: movk 12, a7 ; movb ... *a10 -> ConfigureWindow, opcode 12,
|
||||
# then movi 0x40 into the value-mask (CWStackMode) and value 0 (Above)
|
||||
```
|
||||
|
||||
(The `-s` values are file offsets: `(bit_address >> 3) - 0x07E40000`, the ROM's
|
||||
byte base.)
|
||||
|
||||
#### 2.2.1 XImage — the bitmap path
|
||||
|
||||
The table above ends at the drawing calls. The image entry points are separate,
|
||||
and none of them is a request except `XPutImage`/`XGetImage`; `XCreateImage` and
|
||||
`XDestroyImage` are client-side. Addresses were derived by disassembling
|
||||
`vt1200_v22.bin` with `tools/smart34010/dis34` and then confirmed live (see
|
||||
§2.2.2). Bit addresses again; Ghidra = bits / 8.
|
||||
|
||||
| Xlib function | Ghidra | bits | shape seen |
|
||||
|---|---|---|---|
|
||||
| `XCreateImage(d,visual,depth,format,offset,data,w,h,bitmap_pad,bytes_per_line)` | `0x07F34092` | `0x3F9A0490` | 10 args; `calloc(1,0x58)` (0x3F703D90), fills the struct, `_XInitImageFuncPtrs` (0x3F9A6AA0) |
|
||||
| `XPutImage(d,drawable,gc,image,src_x,src_y,dst_x,dst_y,w,h)` | `0x07F3A06E` | `0x3F9D0370` | 10 args; clips, checks `bits_per_pixel`, calls the workhorse below |
|
||||
| `XDestroyImage(image)` | `0x07F341B0` | `0x3F9A0D80` | 1 arg; `free(image->data)`, `free(image->obdata)` if set, `free(image)` |
|
||||
| `XGetImage(d,drawable,x,y,w,h,plane_mask,format)` | `0x07FAAAD6` | `0x3FD556B0` | 8 args; request opcode **73 (0x49)**, length 5 |
|
||||
|
||||
Supporting routines, named so a trace can be followed:
|
||||
|
||||
| routine | Ghidra | bits | what it is |
|
||||
|---|---|---|---|
|
||||
| PutImage request builder | `0x07F39D8E` | `0x3F9CEC70` | writes opcode **72 (0x48)** at request byte 0, length 6 at byte 2, `format = image->format` at byte 1, then drawable/gc/width/height/dst-x/dst-y/depth; dispatches the pixel copy |
|
||||
| 1-bit pixel copier | `0x07F3965A` | `0x3F9CB2D0` | used when `depth == 1` **or** `format != ZPixmap`; appends the rows and bumps the request length |
|
||||
| ZPixmap pixel copier | `0x07F39B18` | `0x3F9CD8C0` | used when `depth != 1` and `format == ZPixmap` |
|
||||
| PutImage workhorse | `0x07F39E68` | `0x3F9CF340` | clipping, request-band splitting when the image does not fit the client buffer, then the request builder |
|
||||
| `_XInitImageFuncPtrs` | `0x07F34D54` | `0x3F9A6AA0` | fills `image->f` (get_pixel at `image+0x200`, …) |
|
||||
| image-field reporter | `0x07F34DA4` | `0x3F9A6D20` | prints `Bad image %s: %d found in routine: %s` (string `0x3F9A7348`) |
|
||||
|
||||
**Drift check.** Pin each name to its bytes before trusting the table (`-s` is
|
||||
the file offset, `(bit_address >> 3) - 0x07E40000`):
|
||||
|
||||
```
|
||||
tools/smart34010/dis34 -l -o -b 3F9D0370 -s 0xFA06E vt1200_v22.bin
|
||||
# expect: mmtm sp, a5,a7,a9,a10,a11,a12,a13 -> XPutImage
|
||||
tools/smart34010/dis34 -l -o -b 3F9CEE00 -s 0xF9DC0 vt1200_v22.bin
|
||||
# expect: movi 0x48 (opcode 72), movb a7,*a11, movk 6 -> PutImage request
|
||||
tools/smart34010/dis34 -l -o -b 3FD55830 -s 0x16AB06 vt1200_v22.bin
|
||||
# expect: movi 0x49 (opcode 73), movb a11,*a10, movk 5 -> GetImage request
|
||||
tools/smart34010/dis34 -l -o -b 3F9A0490 -s 0xF4092 vt1200_v22.bin
|
||||
# expect: mmtm sp, a3,a5,a7,a9,a10,a11,a13 -> XCreateImage (movi 0x58 follows)
|
||||
tools/smart34010/dis34 -l -o -b 3F9A0D80 -s 0xF41B0 vt1200_v22.bin
|
||||
# expect: mmtm sp, a11,a13 -> XDestroyImage
|
||||
```
|
||||
|
||||
**XImage layout.** 32-bit fields; byte offsets as the ROM writes them in
|
||||
`XCreateImage`, and as read back from a live image in §2.2.2:
|
||||
|
||||
| off | field | off | field | off | field |
|
||||
|---|---|---|---|---|---|
|
||||
| `0x00` | width | `0x18` | bitmap_unit | `0x30` | red_mask |
|
||||
| `0x04` | height | `0x1C` | bitmap_bit_order | `0x34` | green_mask |
|
||||
| `0x08` | xoffset | `0x20` | bitmap_pad | `0x38` | blue_mask |
|
||||
| `0x0C` | format | `0x24` | depth | `0x3C` | obdata |
|
||||
| `0x10` | data | `0x28` | bytes_per_line | `0x40` | f.get_pixel … |
|
||||
| `0x14` | byte_order | `0x2C` | bits_per_pixel | | |
|
||||
|
||||
**The format contract, from the code** (not from Xlib headers):
|
||||
|
||||
* `XCreateImage` **inherits the orders from the Display**: `image->byte_order =
|
||||
*(dpy+0x1A0)`, `bitmap_unit = *(dpy+0x1C0)`, `bitmap_bit_order =
|
||||
*(dpy+0x200)` (`0x3F9A0650`, `0x3F9A0680`, `0x3F9A06B0`). A client does not
|
||||
have to know or guess them.
|
||||
* `bits_per_pixel` starts at **1**. Only `format == ZPixmap (2)` replaces it, via
|
||||
a lookup in the display's pixmap-format list (`dpy+0x220` count, `dpy+0x240`
|
||||
pointer, entry stride `0x80` bits, depth at entry+`0x20`, bpp at entry+`0x40`;
|
||||
no match falls back to `depth`). So **XYBitmap (0) and XYPixmap (1) are always
|
||||
transported as 1 bit per pixel**, whatever `depth` says.
|
||||
* `bytes_per_line` is computed from `width`/`offset`/`bitmap_pad` when the caller
|
||||
passes 0 (`0x3F9A09C0`–`0x3F9A0C40`).
|
||||
* `XCreateImage` itself rejects nothing — no depth, format or order check.
|
||||
* `XPutImage` refuses exactly one case (`0x3F9D07B0`–`0x3F9D0B70`): `format ==
|
||||
ZPixmap` **and** `depth != 1` **and** `image->bits_per_pixel` differs from the
|
||||
display's bits-per-pixel for that depth. It then prints the ROM's own message
|
||||
and **returns without sending the request**; the caller sees no error.
|
||||
* Everything else — `depth == 1`, and every non-ZPixmap format — takes the 1-bit
|
||||
path and never reaches that check.
|
||||
|
||||
**The two ROM messages, and what they actually mean here.**
|
||||
|
||||
* `XPutImage: bits_per_pixel conversion unimplemented.` — string
|
||||
`0x3F9D0E80`, printed at `0x3F9D0B40` into Xlib's error stream (`@0x00DAD00`).
|
||||
It is literal: there is no `bits_per_pixel` conversion path in this Xlib. It
|
||||
fires only for a ZPixmap image of depth ≠ 1 whose `bits_per_pixel` does not
|
||||
match the server's; the request is dropped, not rejected over the wire, and
|
||||
the process continues. A 1-bit `XYBitmap` can never trigger it.
|
||||
* `XGetImage: Can't get requested memory` — string `0x3FD567A0`, printed at
|
||||
`0x3FD55D30`. It is the **client-side malloc for the reply data** failing: the
|
||||
call at `0x3FD55C70` allocates `4 × reply.length` bytes and, on NULL, prints
|
||||
this and returns NULL (`0x3FD55D60`). It says nothing about the server.
|
||||
|
||||
**Minimum image sequence** (same calling convention as §4): `XCreateGC`
|
||||
(`0x3F997000`, mask 0 is enough) → `XCreateImage` → optional
|
||||
`XSetForeground` → `XPutImage` → `XSync` (`0x3FD9F6B0`) →
|
||||
`XDestroyImage`. Map and sync the window once before the put, exactly as for
|
||||
text: the WM reparents the window, and a draw issued before that can be lost.
|
||||
The probe in §2.2.2 is this sequence.
|
||||
|
||||
#### 2.2.2 The image path, measured
|
||||
|
||||
`dwt/gui/xshow.asm` (built with `dwt/loader/build.sh`, run through the COFF
|
||||
loader — no network, no rdebug) opens its own connection as a `create_process`
|
||||
child, creates a 400×200 window at 100,100, creates a 32×32 **XYBitmap**
|
||||
(`depth = 1`, `format = 0`, LSBFirst both ways, `bitmap_unit = 32`,
|
||||
`bitmap_pad = 32`, `bytes_per_line = 0` so `XCreateImage` computes it), uploads
|
||||
it with `XPutImage` at window (20,20), syncs twice, and destroys it. A second
|
||||
`XPutImage` of the same image with `h = 16` at (20,60) is the control.
|
||||
|
||||
Measured values from the run (frame 2650, VR150, `VT1200_SKIP_LEVEL1=1`):
|
||||
|
||||
```
|
||||
XSHOW: f2650 mirror stage=00000008 display=0093C910 window=00400001 gc=00987D70 image=00988130 putret=00000080 syncret=00000001 strlen=00000004
|
||||
XSHOW: final image@00988130 width=00000020 height=00000020 xoffset=00000000 format=00000000 data=018D0000 byte_order=00000000 bitmap_unit=00000020 bitmap_bit_order=00000000 bitmap_pad=00000020 depth=00000001 bytes_per_line=00000004 bits_per_pixel=00000001
|
||||
XSHOW: final dpy@0093C910 byte_order=00000000 bitmap_unit=00000020 scanline_pad=00000020 bitmap_bit_order=00000000
|
||||
XSHOW: final pixmap_formats n=1 list=00367D90
|
||||
XSHOW: final fmt[0] depth=00000001 bits_per_pixel=00000001 pad=00000020
|
||||
```
|
||||
|
||||
Stage 8 is "synced"; the checklist stages 1–7 are start, display, window,
|
||||
mapped, gc, image, putimage. The picture: `dwt/gui/evidence/xshow_frame2650.png`.
|
||||
Pixel rows (decoded from that PNG with
|
||||
`python3 dwt/gui/evidence/png_rows.py dwt/gui/evidence/xshow_frame2650.png 118 118 40 64`,
|
||||
saved as `dwt/gui/evidence/xshow_pixels.txt`) show the full 32-row image at
|
||||
screen 122..153 and the 16-row control at 162..177:
|
||||
|
||||
```
|
||||
122 ....################################....
|
||||
123 .....#..................................
|
||||
... (one diagonal pixel per row)
|
||||
152 ..................................#.....
|
||||
153 ....################################....
|
||||
...
|
||||
162 ....################################....
|
||||
163 .....#..................................
|
||||
... (control stops after 16 rows)
|
||||
177 ...................#....................
|
||||
```
|
||||
|
||||
The same payload run snapshot 30 frames later (`xshow_frame2680.png`, frame
|
||||
2680) is byte-identical to the 2650 capture (md5
|
||||
`ab9d63844aa5a3dd9d281a6bee3c76c2`), so the picture is the window's state and
|
||||
not a transient.
|
||||
|
||||
What this proves, and what it does not:
|
||||
|
||||
* **Measured:** the ROM's own `XCreateImage` builds the struct described above
|
||||
from the ten arguments and the display's orders; `XPutImage` of a 1-bit
|
||||
`XYBitmap` paints exactly `w × h` pixels at the requested destination, honours
|
||||
a smaller `h`, and returns normally; `XDestroyImage` runs without harm. The
|
||||
display advertises exactly one pixmap format (depth 1, bpp 1, pad 32).
|
||||
* **Inferred / not measured:** `XGetImage` is documented from disassembly only —
|
||||
the probe does not call it (it needs a real GET round trip and its allocation
|
||||
path). Orders other than LSBFirst are *supposed* to work: the 1-bit copier
|
||||
picks a normalization routine from a runtime table keyed by
|
||||
`(bitmap_unit, bitmap_bit_order, byte_order)` for both the image and the
|
||||
display (`0x3F9CB7C0`–`0x3F9CBB20`), but only LSBFirst/32 was run. A
|
||||
non-1-bit ZPixmap is untested because the server has no such visual; only the
|
||||
mismatch message above is established.
|
||||
|
||||
### 2.3 X server internals that matter
|
||||
|
||||
| what | Ghidra | bits |
|
||||
@@ -171,22 +342,36 @@ MOVE A11,*A14+,1 ; display
|
||||
CALLA 0x07FA8372 ; -> window id
|
||||
```
|
||||
|
||||
The full minimum is **4 Xlib calls**:
|
||||
The full minimum is **4 Xlib calls after one setup step**:
|
||||
|
||||
0. **Install the per-process Xlib context first** — see §10.5. It is not an
|
||||
Xlib call: `pp = *(u32 *)(*(u32 *)0x1B3900 + 0x100); *(u32 *)pp = block;`
|
||||
with `block` a zeroed ≥1 KiB buffer. Skip it and window creation and
|
||||
drawing still work, but `XNextEvent` silently never delivers a real event.
|
||||
1. `XOpenDisplay("0::0")` — `0x3F9C2570`
|
||||
2. `XCreateSimpleWindow(d, root, x, y, w, h, bw, border, background)` —
|
||||
`0x3FD41B90`
|
||||
3. `XMapWindow(d, win)` — `0x3FD645B0`
|
||||
3. `XMapWindow(d, win)` — `0x3FD64F60`
|
||||
4. `XSync(d, 0)` — `0x3FD9F6B0` (flush + round trip)
|
||||
|
||||
`XMapWindow` is `0x3FD64F60` (MapWindow, opcode 8). `0x3FD645B0` is
|
||||
**`XRaiseWindow`**, not `XMapWindow`: it sends ConfigureWindow (opcode 12) with
|
||||
`CWStackMode` = `Above`, which reorders the stacking but **does not map the
|
||||
window**. The shipped `dwt/gui` payloads call `XRaiseWindow`, so they never map
|
||||
their window themselves; it still appears framed, so the map is issued on their
|
||||
behalf (the WM frames top-level client windows). A client that wants to be sure
|
||||
it is mapped should call `0x3FD64F60`.
|
||||
|
||||
To draw text add `XLoadFont(d,"fixed")` (`0x3FD4AE80`), `XCreateGC`
|
||||
(`0x3F997000`) with `GCFont=0x4000`, `XSetForeground` (`0x3FD99A60`) and
|
||||
`XDrawString` (`0x3FDA0000`). No event loop is needed for a static window; the
|
||||
server keeps it after the client goes idle.
|
||||
`XDrawString` (`0x3FDA0000`). To draw a bitmap add `XCreateImage` +
|
||||
`XPutImage` (§2.2.1); §2.2.2 is the measured example. No event loop is needed
|
||||
for a static window; the server keeps it after the client goes idle.
|
||||
|
||||
Globals: only the `Display *` is per-app. There is **no global "current
|
||||
display" to initialise**; `XOpenDisplay` allocates and returns it. Window ids,
|
||||
GCs and fonts are server-side resources and are valid for any client.
|
||||
Globals: the `Display *` and the per-process XG block (§10.5) are per-app.
|
||||
There is **no global "current display" to initialise**; `XOpenDisplay`
|
||||
allocates and returns it. Window ids, GCs and fonts are server-side resources
|
||||
and are valid for any client.
|
||||
|
||||
## 5. The injection experiment (run) and the verdict
|
||||
|
||||
@@ -194,7 +379,7 @@ Payload: `dwt/gui/xhello.asm` → `dwt/gui/build/xhello.bin` (390 B), linked at
|
||||
`0x01840000`, built with the TI SDK flow (`dwt/gui/build.sh`). It first calls
|
||||
`strlen("0::0")` as an ABI check (must return 4; if not it returns without
|
||||
touching Xlib), then `XOpenDisplay`, root lookup, `XCreateSimpleWindow`,
|
||||
`XMapWindow`, `XSync`, storing a stage counter at bit `0x01850140` and the
|
||||
`XRaiseWindow`, `XSync`, storing a stage counter at bit `0x01850140` and the
|
||||
display/window at `0x01850100`/`0x01850120`.
|
||||
|
||||
Run: `VT1200_SKIP_LEVEL1=1`, private `-nvram_directory`/`-cfg_directory`,
|
||||
@@ -326,12 +511,20 @@ live.
|
||||
| `dwt/gui/probe.lua`, `probe2.lua`, `probe3.lua` | frame snapshots + marker/PC telemetry + accept breakpoint |
|
||||
| `dwt/gui/run/mame.log` | boot, markers (`strlen=4`, `stage=2`, `disp=0`, `xclients=1`) |
|
||||
| `dwt/gui/run/gui_frame15571.png` | post-injection frame: normal Terminal Manager, no new window |
|
||||
| `dwt/gui/xshow.asm` | the XImage probe (§2.2.2): XCreateImage + 2×XPutImage + XDestroyImage |
|
||||
| `dwt/gui/xshow.lua`, `dwt/gui/build/xshow.coff` | the COFF-loader runner and the linked image it loads |
|
||||
| `dwt/gui/build/xshow.bin`, `.lst`, `.map` | assembled `.text`, listing, map |
|
||||
| `dwt/gui/evidence/xshow_frame2650.png` | 32-row diagonal at window (20,20); 16-row control at (20,60) |
|
||||
| `dwt/gui/evidence/xshow_frame2680.png` | the same picture 30 frames later (byte-identical PNG) |
|
||||
| `dwt/gui/evidence/xshow_pixels.txt`, `png_rows.py` | the PNG's rows as ASCII, and the dependency-free decoder that produced them |
|
||||
| `dwt/gui/evidence/xshow_run.log` | the run: stage 8, the live XImage fields, the display's pixmap formats |
|
||||
|
||||
## 10. Transport settled: a `create_process` child opens a window
|
||||
|
||||
**Verdict: H3 holds, with one payload bug on top.** A process created by the
|
||||
firmware's own `create_process` connects to the `"xserver"` local service,
|
||||
completes the X11 setup handshake, creates and maps a window. The final,
|
||||
completes the X11 setup handshake, creates a window and raises it. It appears
|
||||
framed (and mapped) on screen. The final,
|
||||
**breakpoint-free** run shows it at frame 2838:
|
||||
`dwt/gui/evidence/xhello_window_frame2838.png` (black 400x200 window at 100,100
|
||||
with the WM frame/title bar, over the Terminal Manager).
|
||||
@@ -423,7 +616,81 @@ Raw excerpt: `dwt/gui/evidence/transport_evidence.txt`; full trace:
|
||||
`dwt/gui/run12/debug.log` (instrumented) and `dwt/gui/run13/mame.log`
|
||||
(breakpoint-free).
|
||||
|
||||
### 10.5 The second bug: do not reload `Display *` from the marker cell
|
||||
### 10.5 The per-process XG block: events need it before `XOpenDisplay`
|
||||
|
||||
A child made by `create_process` starts with **no per-process Xlib context**.
|
||||
The ROM Xlib reaches it through the current-process word and two cells:
|
||||
|
||||
```
|
||||
proc = *(u32 *)0x001B3900 ; current PCB; bit 0x1B3900
|
||||
pp = *(u32 *)(proc + 0x100) ; per-process user block (bit +0x100 = byte +0x20)
|
||||
XG = *(u32 *)pp ; per-process Xlib context; 0 in a fresh child
|
||||
```
|
||||
|
||||
This is confirmed by disassembly, not by the field names. `0x3F708700` is the
|
||||
ROM's "current process" helper, and the event code calls it before each use:
|
||||
|
||||
```
|
||||
3f708700: move @0x1b3900, a8, 1 ; a8 = current PCB
|
||||
3f708730: rets
|
||||
...
|
||||
3f9c23c0: calla 0x3f708700
|
||||
3f9c23f0: move *a8(0x100), a7, 1 ; a7 = pp
|
||||
3f9c2410: move *a7, a7, 1 ; a7 = XG
|
||||
3f9c2420: move *a7(0xcc0), *a11(0), 1 ; free-list head = *(XG + 0xCC0 bits)
|
||||
3f9c24b0: move a11, *a7(0xcc0), 1 ; used node goes back on the free list
|
||||
```
|
||||
|
||||
That block is inside `XNextEvent` (`0x3F9C1CF0`, which returns at
|
||||
`0x3F9C2560`). The enqueue helper it calls at `0x3F9C2180` (`0x3F9B89A0`;
|
||||
Xlib's `_XEnq`) repeats the same three loads and takes a node from
|
||||
`*(XG + 0xCC0)`:
|
||||
|
||||
```
|
||||
3f9b8a80: calla 0x3f708700
|
||||
3f9b8ab0: move *a8(0x100), a7, 1
|
||||
3f9b8ad0: move *a7, a7, 1
|
||||
3f9b8ae0: move *a7(0xcc0), a11, 1
|
||||
3f9b8b70: move *a11(0), *a7(0xcc0), 1
|
||||
```
|
||||
|
||||
The ROM is **bit-addressed**: `XG + 0xCC0` bits is byte `+0x198` of the block,
|
||||
which is where the low-level note `XG + 0x198` comes from.
|
||||
|
||||
In a fresh child `XG` is 0, so the whole XG structure — queue head, queue
|
||||
length, and the free list at `+0xCC0` — is read from low RAM. Whatever happens
|
||||
to be there becomes the event queue. The result is not a crash: `XOpenDisplay`,
|
||||
`XCreateSimpleWindow`, `XMapWindow`, `XSync` and every drawing call still work,
|
||||
because they only build requests — the window really appears. **Events silently
|
||||
never arrive**: `XNextEvent` returns zeroed records (`type=0`, `keycode=0`) and
|
||||
never a real `KeyPress`, and nothing reports an error. It reads like a keyboard
|
||||
or focus problem.
|
||||
|
||||
The fix is a RAM write before the first Xlib call:
|
||||
|
||||
1. Allocate a **zeroed block of at least 1 KiB** (the termtris port uses
|
||||
`static vt_u32 vt_xg[256]`, exactly 1 KiB; the `+0x198` field and the queue
|
||||
nodes live inside it).
|
||||
2. Read `proc = *(u32 *)0x001B3900` and `pp = *(u32 *)(proc + 0x100)`.
|
||||
3. Store the block's address into `*(u32 *)pp`.
|
||||
|
||||
`dwt/loader/xg.c` implements this as `int vt_install_xg(void)` (returns 1 on
|
||||
success, 0 if `proc` or `pp` is not a plausible RAM pointer); it zeroes the
|
||||
block itself rather than trusting startup to clear `.bss`. The termtris port
|
||||
uses the same three loads and store (`apps/termtris/src/vt1200/xgfix.c`) with
|
||||
the same 1 KiB block. Both are RAM-only: the ROM is untouched. The ordering
|
||||
rule is **install it before `XOpenDisplay`**. The ROM re-reads the cell on each
|
||||
event call, but installing first means no Xlib entry point can ever run with
|
||||
`XG == 0`, and that is the order the working client uses.
|
||||
|
||||
Measured: with the block installed, a `create_process` child receives real
|
||||
events — the termtris smoke test gets `type=2 keycode=194` and `XLookupString`
|
||||
returns `a` (`apps/termtris/VT1200.md`, and the loader-tree helper's own run in
|
||||
`dwt/loader/README.md`). With the install removed, the same client opens and
|
||||
maps its window, loops in `XNextEvent` and only ever sees zeroed records
|
||||
(`type=0`, `keycode=0`).
|
||||
|
||||
### 10.6 The second bug: do not reload `Display *` from the marker cell
|
||||
|
||||
With H3 alone the child still crashed in `XCreateSimpleWindow`. The cause is in
|
||||
`xhello`, not in the transport: `XOpenDisplay` really returns `0x7C7290`
|
||||
@@ -437,7 +704,7 @@ window in **a10** — both are callee-saved by every Xlib entry point
|
||||
re-run `setf 16,0,0; setf 32,0,1` after every Xlib call because Xlib changes the
|
||||
CPU's field state. The markers are diagnostic only now.
|
||||
|
||||
### 10.6 Reproduce
|
||||
### 10.7 Reproduce
|
||||
|
||||
```sh
|
||||
./dwt/gui/build.sh dwt/gui/xhello.asm 01840000 # 390 B
|
||||
@@ -462,7 +729,7 @@ python3 dwt/visual/inject.py --host 192.168.99.2 \
|
||||
`probe_win.lua` contains no `bpset`/`wpset`; the final frame is produced by the
|
||||
payload alone. Stage markers: `01890140` reaches 6, `01890160` = 4.
|
||||
|
||||
### 10.7 Limits
|
||||
### 10.8 Limits
|
||||
|
||||
* The demonstration depends on the `VT1200_SKIP_LEVEL1=1` divergence (as did the
|
||||
original experiment); it is evidence about the OS/X server, not a real POST.
|
||||
|
||||
@@ -76,6 +76,7 @@ Reports in this directory:
|
||||
| `BRINGUP_LOG.md` | the whole bring-up narrative, **including withdrawn claims** — read it sceptically |
|
||||
| `ROMPATCH_REPORT.md` | runtime ROM patching (debug only — see the caveat) |
|
||||
| `HELLO_WORLD_REPORT.md` | the TMS34010 SDK assembles an 82-byte payload of **our own** code; it runs, writes RAM markers and paints a VRAM block. Debugger entry, not a delivery mechanism |
|
||||
| `TERMTRIS_REPORT.md` | the upstream tetris game built with the 1990 r5.01 C toolchain and run **inside** the terminal: ROM Xlib rendering, real X11 key events, the XG-context fix and the row-batched flush |
|
||||
|
||||
## Address model (the important part)
|
||||
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
# TERMTRIS_REPORT — the upstream tetris game running inside the VT1200
|
||||
|
||||
`apps/termtris/` builds **our own TMS34010 program** from John Tsiombikas'
|
||||
`termtris` (upstream commit `7c5435dd4e93ffc10f3b5c68fe1ae9718a365258`) with the
|
||||
1990 TI r5.01 C toolchain under 2ine, loads it into VT1200 RAM and runs it on
|
||||
the emulated terminal's own X server. It draws through the ROM Xlib and reads
|
||||
real X11 `KeyPress` events. No host client, no terminal escape output, no ROM
|
||||
patches.
|
||||
|
||||
Full port documentation: `apps/termtris/VT1200.md`.
|
||||
|
||||
## Build
|
||||
|
||||
```sh
|
||||
cd apps/termtris
|
||||
OUTNAME=termtris ./build.sh src/vt1200/main.c src/game.c \
|
||||
src/vt1200/scoredb.c src/vt1200/x11.c src/vt1200/compat.c \
|
||||
src/vt1200/xgfix.c
|
||||
```
|
||||
|
||||
`build.sh` runs `gspac`/`gspopt`/`gspcg`/`gspa` and `gsplnk` through
|
||||
`/home/arti/os2-work/2ine/build/lx_loader` against the r5.01 SDK zips under
|
||||
`tools/tms34010-sdk/1990-11 TMS340 Family SDK/`. Those 2ine-hosted tools
|
||||
frequently segfault after writing their output, so the wrapper treats an output
|
||||
file as success and retries a missing one. A host kernel without
|
||||
`CONFIG_X86_16BIT` cannot give the 16-bit OS/2 tools their LDT segments; the
|
||||
wrapper detects that and runs the same loader through `qemu-i386`, whose
|
||||
linux-user emulation implements them. Two more quirks are handled there:
|
||||
|
||||
* `gspac` needs `-i.` for the angle-bracket shim headers;
|
||||
* an empty `.cinit` makes `cinit` point at `.text`, whose first instruction the
|
||||
entry walker would read as a record count — when the map reports `.cinit`
|
||||
length 0 the link is repeated with the one-word `CINITZ.obj` terminator.
|
||||
|
||||
Result (map):
|
||||
|
||||
```
|
||||
.text 018A0000 .cinit 018B4A60 .bss 01A00000
|
||||
ENTRY POINT SYMBOL: "_start" address: 018a0000
|
||||
```
|
||||
|
||||
These are **bit** addresses, as everywhere on the TMS34010.
|
||||
|
||||
## The one required Xlib fix
|
||||
|
||||
A child created by `create_process` has a NULL per-process Xlib context
|
||||
(`*(*(proc + 0x100))`). The ROM Xlib's `_XEnq` treats that as the queue head, so
|
||||
`XNextEvent` copies unmapped garbage and never returns an event.
|
||||
`src/vt1200/xgfix.c` writes a zeroed 1 KiB block into that per-process word
|
||||
before `XOpenDisplay`. RAM only; the ROM is unchanged.
|
||||
|
||||
Smoke test evidence (`apps/termtris/tests/smoke.sh`):
|
||||
`type=2 keycode=194 lookup_n=1 ch=61 ks=0061` — a real `KeyPress` and
|
||||
`XLookupString` returning `a`.
|
||||
|
||||
## Rendering and the flush deadlock
|
||||
|
||||
80×24 cells of 6×13 px (the default GC font, baseline +10) → a 480×312 window.
|
||||
The raster is 1 bit deep, so the backend drops colour (like the game's `-m`
|
||||
monochrome mode) and treats the bold bit (`0x80`) as reverse video. That
|
||||
reversal is this backend's choice; upstream `ansi.c -m` only emits SGR bold. The playfield
|
||||
is black spaces; tetrominoes are the `[`/`]` tiles.
|
||||
|
||||
`vt_x11_flush()` repaints **whole rows** — one fill for the row background, one
|
||||
`XDrawString` for its 80 characters, fill/string pairs for reversed spans, then
|
||||
a single `XFlush`. This is not an optimisation for looks:
|
||||
|
||||
* the per-cell version (4 requests/cell) outran the in-machine X server;
|
||||
* an `XSync` per row **deadlocked the client** — the debug marker
|
||||
`_vt_x11_progress` froze at `0x00010014` (row 20), the main-loop counter
|
||||
stayed 0 and the game window never got a preview piece. Batching a row makes
|
||||
a full redraw a few hundred bytes and `loops` reached 650 between frames
|
||||
2500 and 3200 (VR319 default).
|
||||
|
||||
## Timing and keys
|
||||
|
||||
`now_ms()` accumulates the 16-bit counter at bit `0x1E93C0` into 32 bits;
|
||||
`sleep_ms()` calls the ROM `sleep` (`0x3FB33A20`) with a 1–10 ms clamp. The
|
||||
game's own `update()` picks the tick (887 ms at level 0).
|
||||
|
||||
`KeyPress` → `XLookupString` → lower-cased letters to `game_input()`; arrows as
|
||||
the game's CSI codes (`0x9b` + `A`/`B`/`C`/`D`), which it maps back to
|
||||
`w`/`s`/`d`/`a`; `0x7F` is Backspace/Delete. `ExposureMask` is not selected:
|
||||
a map-time `Expose` fires the game's full-redraw before it has a current piece,
|
||||
which draws a bogus piece over the top row (blank border plus stray `X` tiles).
|
||||
|
||||
## Reproduce
|
||||
|
||||
```sh
|
||||
apps/termtris/verify.sh # the whole acceptance run
|
||||
apps/termtris/tests/play.sh # load, click, snapshot
|
||||
apps/termtris/tests/play_keys.sh # move / panels / quit
|
||||
apps/termtris/run.sh # interactive MAME session
|
||||
```
|
||||
|
||||
The run is `VT1200_SKIP_LEVEL1=1 LOADER_AT=2500` with the loader payload at bit
|
||||
`0x01880000` and the COFF at `0x01900000`; at frame 2500 the script enters
|
||||
`dwt/loader/build/loader.bin`, which places the sections and calls
|
||||
`create_process`.
|
||||
|
||||
Last full acceptance run — MAME 0.289 built from this tree's driver at the
|
||||
**VR319 default** (1280×1024 active), which is the real unit's monitor. The
|
||||
earlier figures in this report were VR150 (1024×864):
|
||||
|
||||
```
|
||||
move DIAG: loops=650 events=18 last=3 focus=00400001 rev=0 quit=0
|
||||
panels DIAG: loops=648 events=12 last=3 focus=00400001 rev=0 quit=0
|
||||
quit DIAG: loops=555 events=10 last=3 focus=00400001 rev=0 quit=1
|
||||
```
|
||||
|
||||
`focus=00400001` is the termtris window, sampled on the click's `ButtonRelease`;
|
||||
`quit=1` is the game's global after `q`, and that is the proof the key reached
|
||||
the game, not just the window. The event counts and
|
||||
the `tick=887` are unchanged from the VR150 run; only the loop counts moved,
|
||||
because the VR319 raster changes the emulated frame rate. The evidence PNGs
|
||||
were regenerated in this run and are now 1280×1024.
|
||||
|
||||
| evidence | file |
|
||||
|---|---|
|
||||
| board, panels, preview | `apps/termtris/evidence/termtris_frame3300.png` |
|
||||
| after a/d/s/w/0 | `apps/termtris/evidence/termtris_move_3200.png` |
|
||||
| after h and r | `apps/termtris/evidence/termtris_panels_3200.png` |
|
||||
| after q (`quit=1`) | `apps/termtris/evidence/termtris_quit_3200.png` |
|
||||
| renderer test pattern | `apps/termtris/evidence/render_frame3400.png` |
|
||||
|
||||
## Limits
|
||||
|
||||
* No sound, no filesystem: scores live in `.bss` and vanish with the process.
|
||||
* `q` sets the game's `quit` and the loop exits, but the window stays on screen
|
||||
— the created process does not tear down its X connection.
|
||||
* Startup is retried (up to 40 × 50 ms) because `XOpenDisplay`/window creation
|
||||
intermittently fails while the display server settles.
|
||||
* Tetrominoes are text tiles; a 1-bit cell has no other shape to offer.
|
||||
|
||||
The ROM `vt1200_v22.bin` is never modified — `md5 b46a3e442ccb86134d2356bd70d22fd2`
|
||||
before and after.
|
||||
@@ -0,0 +1,127 @@
|
||||
# TMS34010 toolchain on non-DOS hosts
|
||||
|
||||
Investigated 2026-10-30. Short answer:
|
||||
|
||||
* TI **did** ship the TMS34010/TMS34020 C compiler and code-generation
|
||||
tools for **VAX/VMS, VAX/Ultrix, VAX System V, Apollo Domain/IX and
|
||||
AEGIS, Sun-3, Sun-4/SunOS and Macintosh/MPW** — not just MS-DOS/OS/2.
|
||||
* **No public dump of those host versions is known.** Public archives
|
||||
(bitsavers, archive.org, the `tms34010guy` SDK mirror, Macintosh
|
||||
Garden/Repository) contain the **DOS** and **OS/2** binaries and the
|
||||
manuals that describe the other hosts, but not the Sun/VMS/Apollo/Mac
|
||||
tapes or diskettes.
|
||||
* The only non-DOS binaries actually in hand are the **1990 OS/2 r5.01**
|
||||
tools already in `tools/tms34010-sdk/` (NE executables; see
|
||||
`reference/tms34010-sdk.md`).
|
||||
|
||||
So: the ports existed and are documented; the media appear to be lost
|
||||
from public view, though private tapes are known to exist (see Leads).
|
||||
|
||||
## 1. Hosts TI supported
|
||||
|
||||
Evidence is from the installation chapters and the tools overview of the
|
||||
two C compiler manuals, plus the 1990 Third-Party Guide's description of
|
||||
Code Generation Tools r4.00.
|
||||
|
||||
| host | evidence | distribution medium |
|
||||
|---|---|---|
|
||||
| IBM-PC / TI-PC, PC/MS-DOS | 1986 guide §2.1; 1988 guide §2.1 | 5.25" diskettes |
|
||||
| VAX/VMS | 1986 guide §2.2; 1988 guide §2.2 | 1600 bpi VMS BACKUP tape, volume `gspc`, save set `gspc.bck`, plus `setup.com` |
|
||||
| VAX/Ultrix, VAX/UNIX System V | 1986 guide §2.3; 1988 guide §2.3 | 1600 bpi `tar` tape (`tar vx`), tools `gspcpp`, `gspcc`, `gspcg` |
|
||||
| Apollo Domain/IX, Apollo AEGIS | 1988 guide §1/§2.3 | same `tar` tape (must install under Domain/IX, run under AEGIS) |
|
||||
| Sun-3 (SunOS) | 1988 guide §1/§2.3 | same `tar` tape |
|
||||
| Sun-4/SunOS | 1990 Third-Party Guide, TI Code Generation Tools r4.00 | not stated |
|
||||
| Macintosh/MPW | 1988 guide §2.4 | 800K 3.5" diskette with `Tools/`, `Includes/`, `Libraries/` |
|
||||
| OS/2 1.x | 1990 r5.01 NE binaries (in hand) | 5.25"/3.5" diskettes |
|
||||
|
||||
The 1988 guide's own list (p. 1-3) is: PC-DOS, TI-PC MS-DOS, VAX/VMS,
|
||||
VAX/Ultrix, Apollo Domain/IX, Apollo AEGIS, Sun-3 Unix, Macintosh/MPW.
|
||||
The 1990 Third-Party Guide (p. 29) says r4.00 is available for
|
||||
"PC/MS-DOS, VAX/VMS, VAX/ULTRIX, SUN-3 and SUN-4/O.S, Macintosh/MPW and
|
||||
Apollo/UNEX System V."
|
||||
|
||||
## 2. How to recognise a surviving copy
|
||||
|
||||
These strings/names are distinctive enough to search an old tape or disk
|
||||
image for:
|
||||
|
||||
* `testc34.c`, `testc34.cmp`, `testc34.asm` — the compiler self-test
|
||||
shipped on every C compiler tape/diskette.
|
||||
* `gspc.bck` and `setup.com` — VMS BACKUP save set and symbol setup
|
||||
command file. The VMS tape was made on VMS 4.5, 1600 bpi.
|
||||
* `gspcpp`, `gspcc`, `gspcg`, `gspa`, `gsplnk`, `gspar`, `gsprom` —
|
||||
UNIX spellings have no extension; VMS versions are `*.exe`.
|
||||
* `Tools/`, `Includes/`, `Libraries/` folders on an 800K Mac diskette.
|
||||
|
||||
## 3. What is actually preserved
|
||||
|
||||
| item | where | notes |
|
||||
|---|---|---|
|
||||
| 1985 DOS assembly package v1.04 | `tools/tms34010-sdk/1987-05 TMS34010 SDK/` | DOS disk images |
|
||||
| 1987 DOS Simulator/C/ASM tools v2.00 | same | DOS disk image; the set used for the byte-exact round trip |
|
||||
| 1990 OS/2 Code Generation Tools r5.01 | `tools/tms34010-sdk/1990-11 TMS340 Family SDK/` | NE/OS2 binaries; **the only preserved non-DOS build** |
|
||||
| 1990 OS/2 debugger r5.00, graphics library, TIGA SDK | same | DOS-hosted except the code-gen tools |
|
||||
| 1990 DOS floppy images (`TMS340_Compiler.zip`) | bitsavers / archive.org | DOS, duplicate of the above lineage |
|
||||
| 1986 C Compiler User's Guide | this directory | covers DOS, VAX/VMS, VAX/Ultrix, VAX System V |
|
||||
| 1988 C Compiler Reference Guide | this directory | covers the full host list incl. Apollo, Sun-3, Mac/MPW |
|
||||
| 1990 Third-Party Guide (4th ed.) | this directory | confirms r4.00 host list; third-party compilers |
|
||||
| SPVS002C production-data datasheet | this directory | scanned; part-number/tools catalogue pages |
|
||||
| GCC/G++ 2.5.8 TMS34010 port (1994) | `tools/tms34010-gcc-akpm/` | compiler source; `build-cc1.sh` rebuilds a working `cc1` on 32-bit Linux; Morton's `as34`/`ld34` are ported separately in `tools/as34/` |
|
||||
| ported `as34`/`ld34`/`dis34` | `tools/as34/` | 64-bit Linux port of Morton's binutils, with byte-exact test against the GSPA payload |
|
||||
|
||||
`farnell.txt` is empty because that PDF is image-only (no text layer);
|
||||
`ref1986.txt` and `ref1988.txt` are OCR text from archive.org;
|
||||
`thirdparty1990.txt` is extracted from the PDF.
|
||||
|
||||
## 4. Third-party compilers that ran on those hosts
|
||||
|
||||
The 1990 Third-Party Guide is useful if a TI-hosted build never turns up:
|
||||
|
||||
* **Unidot, Inc.** — TMS34010 C compiler and assembler/linker/archiver.
|
||||
Available **in source form for MS-DOS, DEC VAX under VMS, and most Unix
|
||||
systems**; binary form only for MS-DOS. (p. 209)
|
||||
* **GLH Ltd.** — GCC-based 340 compilers for Unix workstations. (p. 82)
|
||||
* **Signature Software MC34010** — macro assembler, linker and job
|
||||
controller for the **Apple Macintosh** (not a C compiler). (p. 208)
|
||||
* **Andrew Morton's GCC/G++ 2.5.8 port (1994)** — not a commercial
|
||||
product, but a real Unix-hosted GCC target for the TMS34010. The
|
||||
compiler source is saved in `tools/tms34010-gcc-akpm/`, where
|
||||
`build-cc1.sh` now rebuilds a working `cc1` on modern 32-bit Linux;
|
||||
Morton's `as34` assembler, `ld34` linker and `dis34` disassembler are
|
||||
ported and tested in `tools/as34/`.
|
||||
|
||||
## 5. Leads and dead ends
|
||||
|
||||
* **Best lead:** a `test-drb`/cctalk post titled "Wanted: TI TMS340x0
|
||||
development system" reports someone holding a **QIC60/QIC150 tape of
|
||||
the TI 34010 development software for SunOS** (not Solaris), remembered
|
||||
to include the C compiler. The list archive is private, so this is a
|
||||
person-to-person lead, not a download.
|
||||
* `tms34020.uav.nl` and the archived uav.nl asset tree host the manuals
|
||||
only; `TMS340_Compiler.zip`/`TMS340_Compiler_unpacked.zip` on bitsavers
|
||||
are 1990 **DOS** floppy images.
|
||||
* archive.org full-text/software search returns **0** TMS340 software
|
||||
items; the TMS340 items are all manuals.
|
||||
* The `tms34010guy/tms34010-sdk` GitHub tree contains only DOS images and
|
||||
the 1990 OS/2 zips (verified against the full git tree).
|
||||
* Macintosh Garden / Macintosh Repository searches for TMS340/TIGA find
|
||||
nothing relevant.
|
||||
* bitsavers' `/bits/TI/` tree has no TMS340 software, only 990/Explorer.
|
||||
|
||||
Absence of a public dump is not proof that none survives: these were
|
||||
low-volume OEM tapes, and the manuals above are the best identification
|
||||
guide for anyone who finds one.
|
||||
|
||||
## 6. Sources
|
||||
|
||||
* 1986 TMS34010 C Compiler User's Guide (SPVU005):
|
||||
<https://archive.org/details/bitsavers_tiTMS340xxilerUsersGuide_4615125>
|
||||
* 1988 TMS34010 C Compiler Reference Guide (SPVU005A):
|
||||
<https://archive.org/details/bitsavers_tiTMS340xxferenceGuide1988_4803971>
|
||||
(also <https://uav.nl/assets/tms34020/TMS34010_C_Compiler_Reference_Guide_1988.pdf>)
|
||||
* 1990 TMS340 Third-Party Guide, 4th ed.:
|
||||
<https://kguttag.com/wp-content/uploads/2023/07/1990-340-Family-THIRD-PARTY-GUIDE-4th-edition.pdf>
|
||||
* SPVS002C production data (Farnell mirror):
|
||||
<https://www.farnell.com/datasheets/84292.pdf>
|
||||
* bitsavers TMS340xx tree:
|
||||
<https://www.mirrorservice.org/sites/www.bitsavers.org/components/ti/TMS340xx/>
|
||||
@@ -0,0 +1,7 @@
|
||||
6e68ca635dc4a890aebfa8c2a8c10f4388b879a1df3455cb6797a1423de34d69 1986_TI_TMS34010_C_Compiler_Users_Guide.pdf
|
||||
78357c3c9a861a0d19425c3936886dbd62759894a8d7ee1485e03bbe5b2f9e5e 1990_TMS340_Third_Party_Guide_4th.pdf
|
||||
d760ab2e9192b5b9886a6c9ec2f2163d508796be1fd3153a40c9fee2c015ec41 SPVS002C_TMS34010_production_data.pdf
|
||||
bf9a9b912044e11184cecaacddedd24e6f2e48365a8be56fb3989d0842bae8a9 TMS34010_C_Compiler_Reference_Guide_1988.pdf
|
||||
85cd0bd51ebd0eef9d7407b763b9df911fbfe71ae90a465f6c84f110d7c6c160 ref1986.txt
|
||||
6f9182f27033ada8752885d1a2f5ea833268e9aeb239355e9366f6988fa1841d ref1988.txt
|
||||
1b3712f6c8af65c64fd8b1bb41fbf5b393d78dce5c36006abb4e37eed5d952a5 thirdparty1990.txt
|
||||
@@ -12,8 +12,10 @@ Investigated 2026-10-18. Short version:
|
||||
DOSBox; using them would need an OS/2 environment. The 1987 DOS tools are the
|
||||
usable set.
|
||||
* There is **no `as34` / `lnk34`** in this SDK. The assembler is `GSPA.EXE` and
|
||||
the linker `GSPLNK.EXE` (the names `smart34010`'s README mentions are from a
|
||||
later TI package). GSPA 2.00 is enough for the round trip.
|
||||
the linker `GSPLNK.EXE`. (The `as34`/`ld34` names belong to Andrew Morton's
|
||||
1994 GNU TMS34010 toolchain; this project ports them in `tools/as34/`.
|
||||
A later TI devkit may have bundled them, but they are not part of this
|
||||
package.) GSPA 2.00 is enough for the round trip.
|
||||
* The C compiler works and links with `rts.lib` into an absolute COFF image.
|
||||
It is **K&R C, not ANSI**: `int f(int a)` is a syntax error, `int f(a) int a;`
|
||||
works.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
build/
|
||||
@@ -0,0 +1,150 @@
|
||||
# Andrew Morton's GCC 2.5.8 TMS34010 compiler (1994)
|
||||
|
||||
The **compiler half** of Andrew Morton's Unix-hosted TMS34010 toolchain,
|
||||
recovered from `http://www.zip.com.au/~akpm/gsptools.html` via the Wayback
|
||||
Machine (snapshot `20080210052433`).
|
||||
|
||||
This is **not** TI's compiler. It is a real GCC/G++ 2.5.8 port to the
|
||||
TMS34010, and the only saved non-DOS TMS34010 C compiler found so far.
|
||||
|
||||
## Files
|
||||
|
||||
| file | contents |
|
||||
|---|---|
|
||||
| `gspcc-2.5.8-tms34010.tar.gz` | GNU C/C++ 2.5.8 source with the TMS34010 port: `34010.h`, `tm.h`, `md`, `dm.c`, `akpm.c`, `akpmflags.c` |
|
||||
| `cc1-port.patch` | the source fixes needed to build `cc1` with a modern 32-bit host GCC |
|
||||
| `build-cc1.sh` | extract + patch + build `gcc34` (`cc1`) |
|
||||
| `test-cc1.sh` | compile a C sample, assemble/link with `tools/as34`, disassemble |
|
||||
|
||||
The original was an uncompressed tar with a `.tar.gz` name; it is gzipped
|
||||
here. The SHA-256 is in `SHA256SUMS`.
|
||||
|
||||
## The other half is already in this repo
|
||||
|
||||
Morton's **`as34` assembler, `ld34` linker and `dis34` disassembler** are
|
||||
already ported to 64-bit Linux, patched for modern C/flex, and tested in
|
||||
`tools/as34/`. That directory's `build.sh` fetches the companion
|
||||
`gsp.tar.gz` (SHA-256 `efff8e59…f9ef46`) and applies `as34-port.patch`.
|
||||
|
||||
That same `gsp.tar.gz` also contains the compiler's runtime and a working
|
||||
example, extracted by `build.sh` to `tools/as34/build/src/gsp/`:
|
||||
|
||||
* `lib/crt0.g` — C startup (sets `SP`, `CONTROL`, calls `_crtInit`/`_main`)
|
||||
* `lib/libc`, `lib/libg`, `lib/libk` — C/C++ runtime and graphics/kernel libs
|
||||
* `rom/rommain.cc` → `rom/rommain.g` → `rom/rrom.H00`/`rrom.L00` — the proof
|
||||
build (see below)
|
||||
* `app/`, `tests/`, `rom/`
|
||||
|
||||
So this directory only vendors the missing compiler source.
|
||||
|
||||
## Building cc1 on a modern host (verified)
|
||||
|
||||
`build-cc1.sh` rebuilds the compiler proper (`gcc34` = `cc1`) from the
|
||||
tarball with the 32-bit host compiler:
|
||||
|
||||
```sh
|
||||
tools/tms34010-gcc-akpm/build-cc1.sh
|
||||
# -> build/src/gspcc/gcc34
|
||||
```
|
||||
|
||||
Verified on Debian 12 / GCC 14.2.0: the result is a 32-bit x86 ELF
|
||||
(`gcc34: ELF 32-bit LSB pie executable ... for GNU/Linux 3.2.0`) and
|
||||
reports `GNU C version 2.5.8 (TMS34010)`.
|
||||
|
||||
`test-cc1.sh` compiles a three-function C sample, assembles it with the
|
||||
ported `tools/as34`, links with `ld34`, extracts the text and disassembles
|
||||
it:
|
||||
|
||||
```
|
||||
PASS: cc1 -> as34 -> ld34 -> 78 bytes
|
||||
8defc28ed0f90c2797f5d1d2fed0ebe2 sample.bin
|
||||
```
|
||||
|
||||
The resulting code is real TMS34010 (register-argument ABI, `a14`/`fp`
|
||||
frame, `rets`, recursive `callr` + `mpys`).
|
||||
|
||||
### What had to be fixed
|
||||
|
||||
| issue | root cause | fix |
|
||||
|---|---|---|
|
||||
| `No rule to make target 'cc1'` | GNU make prefers Morton's lower-case `makefile`, which has different targets | use `make -f makefile gcc34` |
|
||||
| `TARGET_REGPARM undeclared` | `34010.h` has a broken `#ifndef AKPM_REGPARM` branch | build with Morton's own defines, especially `-DAKPM_REGPARM -DAKPM_RETS` (his `makefile` already has them) |
|
||||
| `MAX_RECOG_OPERANDS undeclared` | first failed build left an empty `insn-config.h`; make then thought it was up to date | always start from a fresh extract (or `make clean`) |
|
||||
| `genconfig: not found` | 1990s shell found programs in `.`; modern shells do not | `PATH="$PWD:$PATH"` |
|
||||
| `gvarargs.h`: expected specifiers before `...` | the old `va_dcl`/`__builtin_va_alist` GCC extension is gone | modern shim in `gvarargs.h`: `va_alist` → `...`, `va_start` → `__builtin_va_start(ap, 0)` |
|
||||
| `conflicting types for 'build'/'gen_rtx'/...` | old-style `f ()` declaration vs new `f (...)` definition | declare the varargs functions as `(...)` in `tree.h`, `expr.h`, `rtl.h`, `output.h`, `combine.c`, `genattrtab.c` |
|
||||
| host byte order | archived `config.h` is for big-endian Sun-3 | comment out `HOST_WORDS_BIG_ENDIAN` and build 32-bit (`-m32`) |
|
||||
| modern compiler defaults | old GCC source is K&R C with tentative definitions | `-std=gnu89 -fcommon` |
|
||||
|
||||
The patch is `cc1-port.patch`; it is applied to a fresh tarball by
|
||||
`build-cc1.sh`. It does not depend on the configure-generated `Makefile`.
|
||||
|
||||
### Current limits
|
||||
|
||||
* `gcc34` is **cc1 only**. It has no driver and no preprocessor: it accepts
|
||||
preprocessed input, or simple C with no directives. For real sources run
|
||||
the host `cpp -P` first, or build GCC 2.5.8's `cccp`/driver separately.
|
||||
* `cc1plus` (`g++34`) is not built here. The first blocker is the old
|
||||
`obstack.h` `obstack_ptr_grow` macro (`lvalue required as increment
|
||||
operand` in `cp-decl.c` on GCC 14), plus the same varargs/prototype
|
||||
treatment; the C++ front end was not pursued.
|
||||
* Output is Morton `.g` assembly → fixed `as34`/`ld34`, not TI COFF.
|
||||
* Morton's register-argument ABI is enabled (`-DAKPM_REGPARM`); this
|
||||
matches the archived `rommain.g` and the prebuilt runtime.
|
||||
* The host build is 32-bit; `gcc -m32` and 32-bit libc are required.
|
||||
|
||||
## Does it produce real binaries?
|
||||
|
||||
Yes — the example artifacts in `tools/as34/build/src/gsp/rom/` show the full
|
||||
pipeline:
|
||||
|
||||
* `rommain.cc` is a substantial C++ program (SCC serial setup, timers,
|
||||
latches, C++ classes; mangled names such as `_flash__Fi`).
|
||||
* `rommain.g` is the GCC-generated TMS34010 assembly, with `.stabs`,
|
||||
prologues/epilogues, `calla`, `mmtm`, `rets`.
|
||||
* `rrom.H00` + `rrom.L00` are the final 32 KB high/low EPROM pair (64 KB of
|
||||
code+data). Interleaving them and running
|
||||
`tools/smart34010/dis34 -E rrom.L00 rrom.H00` gives valid code: reset
|
||||
vector, `setf 16,1,0` / `setf 32,0,1`, `CONTROL` setup, `calla` calls —
|
||||
matching `lib/crt0.g`.
|
||||
* The ROM contains compiled `rommain.cc` logic: `movk 3,a0` /
|
||||
`movi 0xc1,a1` / `call a4` is `WR(3, BM_BITS(11000001))` from
|
||||
`initSCC()`, and strings such as `%x is circular`, `hello, world` and
|
||||
`jumping to 0x%x` appear in the image.
|
||||
|
||||
Caveats:
|
||||
|
||||
* It does **not** emit TI COFF. `as34`/`ld34` use Morton's own link format
|
||||
(`LINKMAGIC 0x3abf782e`, bit-address flag); `romsplit` turns that into
|
||||
EPROM high/low files. `ld34/coff.c` is dead code.
|
||||
* The runtime is for Morton's GSP board: `crt0.g` sets `SP=0xfffffb00`,
|
||||
programs `CONTROL`, calls `_crtInit` then `_main`. A VT1200 port needs its
|
||||
own startup and memory layout.
|
||||
* The archived `config.h` is for a **big-endian Sun-3/m68k host**
|
||||
(`HOST_WORDS_BIG_ENDIAN`), and the tarball contains no prebuilt `cc1` or
|
||||
`gcc34`. `build-cc1.sh` now rebuilds `cc1` on 32-bit Linux using
|
||||
`cc1-port.patch`; see “Building cc1 on a modern host” above.
|
||||
* TMS34010 only, not TMS34020.
|
||||
|
||||
## What Morton changed in GCC
|
||||
|
||||
From his own notes:
|
||||
|
||||
* GCC assumes a byte is the smallest addressable unit. On the GSP a pointer
|
||||
is a **bit** address, so every pointer addend must be multiplied by eight.
|
||||
He patched the places where GCC assumes
|
||||
`(int)(ptr + i) == (int)ptr + i`; grep the tree for `AKPM`, `34010` and
|
||||
`GSP` to find them.
|
||||
* The compiler assumes **FS0 = 5** (32-bit accesses) and **FS1 = 4**
|
||||
(16-bit accesses); `crt0.g` sets the corresponding `setf` values.
|
||||
* He added an `interrupt` function qualifier that saves all machine state
|
||||
so a vector can point directly at the C function.
|
||||
* The port shares the m68k configuration skeleton; `34010.h` started from
|
||||
the Sun 68000/68020 header, and `tm.h` still carries m68k-era `ASM_SPEC`
|
||||
text that a modern driver would need to replace.
|
||||
|
||||
## Licence
|
||||
|
||||
The GNU parts are GPLv2 (see `gspcc/COPYING`). Morton's own additions carry
|
||||
no explicit licence header; treat the archive as historical reference
|
||||
material.
|
||||
@@ -0,0 +1 @@
|
||||
f7c847064cc9c686f77e1f4c8f5a8c0f646b5172862f7c8308b7c8e3fa8a9fe8 gspcc-2.5.8-tms34010.tar.gz
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
# Build Morton's GCC 2.5.8 TMS34010 cc1 (gcc34) on a modern x86-64 host.
|
||||
#
|
||||
# tools/tms34010-gcc-akpm/build-cc1.sh
|
||||
# CC1_BUILD_DIR=/tmp/cc1 JOBS=4 tools/tms34010-gcc-akpm/build-cc1.sh
|
||||
#
|
||||
# Requires a 32-bit host compiler (gcc -m32) and its libc. The result is
|
||||
# src/gspcc/gcc34 — the compiler proper (cc1), not a driver or preprocessor.
|
||||
set -eu
|
||||
|
||||
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
builddir=${CC1_BUILD_DIR:-"$here/build"}
|
||||
tarball="$here/gspcc-2.5.8-tms34010.tar.gz"
|
||||
sha=f7c847064cc9c686f77e1f4c8f5a8c0f646b5172862f7c8308b7c8e3fa8a9fe8
|
||||
hostcc=${HOST_CC:-gcc}
|
||||
|
||||
echo "$sha $tarball" | sha256sum -c -
|
||||
|
||||
mkdir -p "$builddir"
|
||||
if ! printf 'int main(void){return 0;}\n' | "$hostcc" -m32 -x c - -o "$builddir/probe" 2>/dev/null; then
|
||||
echo "error: $hostcc cannot build 32-bit binaries (-m32)" >&2
|
||||
echo "install the 32-bit libc/headers (e.g. gcc-multilib on Debian)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -rf "$builddir/src"
|
||||
mkdir -p "$builddir/src"
|
||||
tar xzf "$tarball" -C "$builddir/src"
|
||||
cd "$builddir/src/gspcc"
|
||||
|
||||
patch -p1 < "$here/cc1-port.patch"
|
||||
|
||||
# Keep Morton's 1993 pre-generated parsers; modern bison would regenerate them.
|
||||
for f in c-parse.c c-parse.h cp-parse.c; do
|
||||
[ -e "$f" ] && touch "$f"
|
||||
done
|
||||
|
||||
export PATH="$PWD:$PATH"
|
||||
make -f makefile -j"${JOBS:-1}" gcc34 \
|
||||
CC="$hostcc -m32 -std=gnu89 -fcommon -O0 -g" \
|
||||
XCFLAGS="-w -fno-strict-aliasing"
|
||||
|
||||
echo
|
||||
echo "built: $PWD/gcc34"
|
||||
file "$PWD/gcc34" || true
|
||||
"$PWD/gcc34" -version 2>&1 | head -1 || true
|
||||
@@ -0,0 +1,112 @@
|
||||
--- a/config.h
|
||||
+++ b/config.h
|
||||
@@ -33,7 +33,7 @@
|
||||
#define HOST_BITS_PER_LONG 32
|
||||
#define HOST_BITS_PER_LONGLONG 64
|
||||
|
||||
-#define HOST_WORDS_BIG_ENDIAN
|
||||
+/* #undef HOST_WORDS_BIG_ENDIAN (x86 host) */
|
||||
|
||||
/* target machine dependencies.
|
||||
tm.h is a symbolic link to the actual target specific file. */
|
||||
--- a/gvarargs.h
|
||||
+++ b/gvarargs.h
|
||||
@@ -1,3 +1,18 @@
|
||||
+/* Modern-GCC shim: the 1990s va_dcl / __builtin_va_alist extension is gone.
|
||||
+ All uses in this tree are "f (va_alist) va_dcl" with no named parameter,
|
||||
+ so map them to a C99 variadic function and use the builtins. */
|
||||
+#if defined(__GNUC__) && __GNUC__ >= 3
|
||||
+#ifndef _VARARGS_H
|
||||
+#define _VARARGS_H
|
||||
+#define va_alist ...
|
||||
+#define va_dcl
|
||||
+#define va_list __builtin_va_list
|
||||
+#define __gnuc_va_list __builtin_va_list
|
||||
+#define va_start(AP) __builtin_va_start(AP, 0)
|
||||
+#define va_end(AP) __builtin_va_end(AP)
|
||||
+#define va_arg(AP, TYPE) __builtin_va_arg(AP, TYPE)
|
||||
+#endif
|
||||
+#else
|
||||
#ifndef __GNUC__
|
||||
/* Use the system's macros with the system's compiler. */
|
||||
#include <varargs.h>
|
||||
@@ -174,3 +189,5 @@
|
||||
#endif
|
||||
|
||||
#endif /* __GNUC__ */
|
||||
+
|
||||
+#endif /* modern GCC shim */
|
||||
--- a/genattrtab.c
|
||||
+++ b/genattrtab.c
|
||||
@@ -359,7 +359,7 @@
|
||||
static rtx attr_rtx PROTO((enum rtx_code, ...));
|
||||
static char *attr_printf PROTO((int, char *, ...));
|
||||
#else
|
||||
-static rtx attr_rtx ();
|
||||
+static rtx attr_rtx (...);
|
||||
static char *attr_printf ();
|
||||
#endif
|
||||
|
||||
--- a/tree.h
|
||||
+++ b/tree.h
|
||||
@@ -1066,9 +1066,9 @@
|
||||
extern tree build_nt PROTO((enum tree_code, ...));
|
||||
extern tree build_parse_node PROTO((enum tree_code, ...));
|
||||
#else
|
||||
-extern tree build ();
|
||||
-extern tree build_nt ();
|
||||
-extern tree build_parse_node ();
|
||||
+extern tree build (...);
|
||||
+extern tree build_nt (...);
|
||||
+extern tree build_parse_node (...);
|
||||
#endif
|
||||
|
||||
extern tree build_int_2_wide PROTO((HOST_WIDE_INT, HOST_WIDE_INT));
|
||||
--- a/expr.h
|
||||
+++ b/expr.h
|
||||
@@ -625,8 +625,8 @@
|
||||
|
||||
/* Emit library call. These cannot have accurate prototypes since they have
|
||||
a variable number of args. */
|
||||
-extern void emit_library_call ();
|
||||
-extern rtx emit_library_call_value ();
|
||||
+extern void emit_library_call (...);
|
||||
+extern rtx emit_library_call_value (...);
|
||||
|
||||
/* Expand an assignment that stores the value of FROM into TO. */
|
||||
extern rtx expand_assignment PROTO((tree, tree, int, int));
|
||||
--- a/rtl.h
|
||||
+++ b/rtl.h
|
||||
@@ -653,8 +653,8 @@
|
||||
|
||||
#else
|
||||
extern rtx bc_gen_rtx ();
|
||||
-extern rtx gen_rtx ();
|
||||
-extern rtvec gen_rtvec ();
|
||||
+extern rtx gen_rtx (...);
|
||||
+extern rtvec gen_rtvec (...);
|
||||
#endif
|
||||
|
||||
#ifdef BUFSIZ /* stdio.h has been included */
|
||||
--- a/output.h
|
||||
+++ b/output.h
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
/* Output a string of assembler code, substituting numbers, strings
|
||||
and fixed syntactic prefixes. */
|
||||
-extern void asm_fprintf ();
|
||||
+extern void asm_fprintf (...);
|
||||
|
||||
/* Print an integer constant expression in assembler syntax.
|
||||
Addition and subtraction are the only arithmetic
|
||||
--- a/combine.c
|
||||
+++ b/combine.c
|
||||
@@ -391,7 +391,7 @@
|
||||
rtx, int));
|
||||
static int recog_for_combine PROTO((rtx *, rtx, rtx *));
|
||||
static rtx gen_lowpart_for_combine PROTO((enum machine_mode, rtx));
|
||||
-static rtx gen_rtx_combine (); /* This is varargs. */
|
||||
+static rtx gen_rtx_combine (...); /* This is varargs. */
|
||||
static rtx gen_binary PROTO((enum rtx_code, enum machine_mode,
|
||||
rtx, rtx));
|
||||
static rtx gen_unary PROTO((enum rtx_code, enum machine_mode, rtx));
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
# Smoke-test the rebuilt cc1: C -> TMS34010 assembly -> as34 -> ld34 -> raw
|
||||
# binary -> dis34.
|
||||
#
|
||||
# tools/tms34010-gcc-akpm/test-cc1.sh
|
||||
#
|
||||
# Requires tools/as34 to have been built (tools/as34/build.sh).
|
||||
set -eu
|
||||
|
||||
here=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
builddir=${CC1_BUILD_DIR:-"$here/build"}
|
||||
cc1="$builddir/src/gspcc/gcc34"
|
||||
as34=${AS34:-"$here/../as34/build/src/gsp/binutils/as34/as34"}
|
||||
ld34=${LD34:-"$here/../as34/build/src/gsp/binutils/ld34/ld34"}
|
||||
extract="$here/../as34/extract.py"
|
||||
dis34="$here/../smart34010/dis34"
|
||||
|
||||
for f in "$cc1" "$as34" "$ld34" "$extract" "$dis34"; do
|
||||
[ -e "$f" ] || { echo "missing $f" >&2; exit 1; }
|
||||
done
|
||||
|
||||
work="$builddir/work-cc1"
|
||||
rm -rf "$work"
|
||||
mkdir -p "$work"
|
||||
cd "$work"
|
||||
|
||||
cat > sample.c <<'EOF'
|
||||
int add(int a, int b) { return a + b; }
|
||||
int sum(int *p, int n)
|
||||
{
|
||||
int s = 0;
|
||||
while (n--)
|
||||
s += *p++;
|
||||
return s;
|
||||
}
|
||||
int fact(int n) { return n < 2 ? 1 : n * fact(n - 1); }
|
||||
EOF
|
||||
|
||||
"$cc1" -quiet -O -o sample.g sample.c
|
||||
"$as34" sample.g
|
||||
"$ld34" -c -T 1800000 -e_add sample.go -o sample.out -m sample.map
|
||||
python3 "$extract" sample.out sample.bin
|
||||
"$dis34" -l sample.bin > sample.dis
|
||||
|
||||
if ! grep -Eq 'add[[:space:]]+a1, a0' sample.dis; then
|
||||
echo "FAIL: expected 'add a1,a0' in add()" >&2
|
||||
cat sample.dis >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! grep -Eq 'mpys' sample.dis; then
|
||||
echo "FAIL: expected 'mpys' in fact()" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "PASS: cc1 -> as34 -> ld34 -> $(wc -c < sample.bin) bytes"
|
||||
md5sum sample.bin
|
||||
echo "disassembly: $work/sample.dis"
|
||||
@@ -8,10 +8,11 @@ the patched fork of [2ine](https://github.com/icculus/2ine) at
|
||||
|
||||
Unlike the assembler-only state documented when the fork was first published,
|
||||
the **full C pipeline works**: front end, optimizer, code generator,
|
||||
assembler, linker and converter. `gspcl` (the one-command driver) still does
|
||||
not chain its children reliably; drive the four C stages explicitly.
|
||||
assembler, linker and converter. `gspcl` (the one-command driver) chains the
|
||||
first four; `-z` adds the link.
|
||||
|
||||
Verified 2026-11-01 on x86_64 Arch, against the VT1200 firmware image.
|
||||
Verified 2026-11-01 on x86_64 Arch, against the VT1200 firmware image; the C
|
||||
pipeline and `gspcl` re-verified 2026-11-16.
|
||||
|
||||
| tool | result |
|
||||
|---|---|
|
||||
@@ -22,15 +23,16 @@ Verified 2026-11-01 on x86_64 Arch, against the VT1200 firmware image.
|
||||
| `gsplnk` (linker) | **works** — absolute placement; `rts.lib` + `flib.lib` |
|
||||
| `gsprom` (COFF → Tek-hex) | **works** — plain and `-i` EPROM pair |
|
||||
| `gspar` (archiver) | **works** — lists `rts.lib` members |
|
||||
| `gspcl` (driver) | **partial** — runs `gspac`, then stops (see §7) |
|
||||
| `gspcl` (driver) | **works** — chains the compile, optimize, codegen and assemble stages; `-z` adds the link (see §7) |
|
||||
|
||||
---
|
||||
|
||||
## 1. Build 2ine
|
||||
|
||||
The fork's `main` carries the three fixes this needs: the null-selector
|
||||
mapping (commit `91b78f2`), Arch/CMake-4 ncurses discovery (`a440128`), and
|
||||
this document's status update (`3bcdfc3`).
|
||||
The fork's `main` carries the fixes this needs: the null-selector mapping
|
||||
(commit `91b78f2`), Arch/CMake-4 ncurses discovery (`a440128`), the 16-bit
|
||||
stack-unmap guard (`cad0c71`), and the fork's `TMS34010.md` status update
|
||||
(`3bcdfc3`).
|
||||
|
||||
Dependencies (Arch):
|
||||
|
||||
@@ -191,15 +193,29 @@ register. The 5.01 object is therefore functionally identical to the ROM, but
|
||||
not byte-identical at that instruction. This is the one exception to the
|
||||
otherwise one-way assembler compatibility noted in `OS2-501.md`.
|
||||
|
||||
## 7. `gspcl` and the exit-status trap
|
||||
## 7. `gspcl`
|
||||
|
||||
`gspcl` finds `gspac` and runs it, then stops without invoking `gspopt` /
|
||||
`gspcg` / `gspa`. The individual tools frequently exit non-zero after
|
||||
successful work: `gspac` and `gspcg` return **139** (segfault during teardown),
|
||||
`gsprom` can return 1. `gspcl` treats the child status as failure.
|
||||
`gspcl` drives the compile, optimize, codegen and assemble stages (`$LX` as in
|
||||
§4):
|
||||
|
||||
**Check for output files, not exit codes.** The manual pipeline in §4 produces
|
||||
correct objects and images; the one-command driver does not yet.
|
||||
```sh
|
||||
$LX ./gspcl.exe -k -o2 -c HELLO.C
|
||||
```
|
||||
|
||||
`-c` stops before linking and `-k` keeps the assembly, so success leaves
|
||||
`hello.obj` and `hello.asm` (the tools write lowercase names). `-z` starts the
|
||||
link, and everything after it is a linker option, so the libraries follow:
|
||||
|
||||
```sh
|
||||
$LX ./gspcl.exe -k -o2 HELLO.C -z -o hello.out rts.lib flib.lib
|
||||
```
|
||||
|
||||
Or run the stages explicitly as in §4.
|
||||
|
||||
In the verified runs the driver and the tools exit **0** on success and **1**
|
||||
for a genuine error such as a missing input or an unwritable output. The loader
|
||||
keeps only the low 8 bits of an OS/2 exit code (`lxTerminate`), so read a
|
||||
nonzero status as "inspect the output" rather than as a precise error code.
|
||||
|
||||
## 8. What the null-selector fix was
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ under real OS/2.
|
||||
|
||||
### 2.1 OS/2 1.3 under 86Box — the full toolchain (compile, link, convert)
|
||||
|
||||
This is the only route that runs **`gspcl`** today.
|
||||
This route runs the full toolchain, including **`gspcl`**.
|
||||
|
||||
Media: the preinstalled image on archive.org, item `Os21.3VirtualHardDisk`,
|
||||
file `MicrosoftOs-21.30HardDisk.vhd` (a Virtual-PC dynamic VHD, 500 MiB
|
||||
@@ -126,13 +126,17 @@ unreliable. Type only letters (name your batch `CG.CMD`, `BK.CMD`, …) one
|
||||
character at a time, and have the batch print a unique end token so the host
|
||||
can detect completion by OCR (or just wait and take a screenshot).
|
||||
|
||||
### 2.2 2ine — assembler/linker/converter natively, no VM
|
||||
### 2.2 2ine — the whole toolchain natively, no VM
|
||||
|
||||
`gspa`, `gsplnk` and `gsprom` run under
|
||||
[2ine](https://github.com/icculus/2ine) with a small patch series; the patched
|
||||
fork lives at **<https://git.wut.ee/opencode.energia.arti.ee/2ine-tms34010>**
|
||||
(see its `TMS34010.md`). Build it 32-bit (`cmake -S . -B build && cmake --build
|
||||
build -j2`, needs `gcc-multilib`, `libc6-dev-i386`, `libncurses-dev:i386`).
|
||||
The whole toolchain runs under
|
||||
[2ine](https://github.com/icculus/2ine) with a small patch series: the
|
||||
assembler, linker and converter, and the C front end, optimizer, code
|
||||
generator and driver. The patched fork lives at
|
||||
**<https://git.wut.ee/opencode.energia.arti.ee/2ine-tms34010>** (see its
|
||||
`TMS34010.md`). Build it 32-bit (`cmake -S . -B build
|
||||
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 && cmake --build build -j2`, needs
|
||||
`gcc-multilib`, `libc6-dev-i386`, `libncurses-dev:i386`; the policy floor is
|
||||
for CMake 4.x).
|
||||
|
||||
```sh
|
||||
cd 2ine/build # lx_loader dlopen()s ./lib<module>.so, so cwd matters
|
||||
@@ -143,9 +147,8 @@ cd 2ine/build # lx_loader dlopen()s ./lib<module>.so, so cwd matters
|
||||
```
|
||||
|
||||
The C pipeline **does** work under the patched fork: a null-selector fix in
|
||||
`lx_loader.c` unblocks `gspac`, `gspopt` and `gspcg`. `gspcl` itself still
|
||||
stops after `gspac` because the children exit non-zero at teardown, so drive
|
||||
the stages explicitly. See `2INE-501.md` for the full end-to-end flow.
|
||||
`lx_loader.c` unblocks `gspac`, `gspopt` and `gspcg`, and `gspcl` chains the
|
||||
stages. See `2INE-501.md` for the full end-to-end flow.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -34,7 +34,8 @@ The **1987** toolchain runs headless in DOSBox: **GSPA 2.00** (assembler),
|
||||
**GSPLNK 2.00** (linker), **GSPROM 2.01**, and the **K&R C compiler**.
|
||||
|
||||
**There is no `as34`/`lnk34`** — the assembler is `GSPA`. (`smart34010`'s README
|
||||
names `as34`; that appears to be a later name or another part, not this SDK.)
|
||||
names `as34`; this project ports Morton's 1994 `as34`/`ld34` in `tools/as34/`;
|
||||
they are not part of this SDK.)
|
||||
|
||||
**The round trip is proven against this exact firmware**: 32 KB at bit
|
||||
`0x3F208000` reassembles **byte-for-byte identical** (region md5
|
||||
|
||||