Wed Mar 7 10:07:43 PST 2007 Ties Stuij
* initial
diff -rN -u old-liards/LICENSE new-liards/LICENSE
--- old-liards/LICENSE 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/LICENSE 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,528 @@
+This code is placed under the LGPL with the following preamble.
+This is usually known as the LLGPL.
+The work itself is Copyright (c) 2007 Ties Stuij
+License text is
+Copyright (c) 2000 Franz Incorporated, Berkeley, CA 94704
+The concept of the GNU Lesser General Public License version 2.1
+("LGPL") has been adopted to govern the use and distribution of
+above-mentioned application. However, the LGPL uses terminology that
+is more appropriate for a program written in C than one written in
+Lisp. Nevertheless, the LGPL can still be applied to a Lisp program if
+certain clarifications are made. This document details those
+clarifications. Accordingly, the license for the open-source Lisp
+applications consists of this document plus the LGPL. Wherever there
+is a conflict between this document and the LGPL, this document takes
+precedence over the LGPL.
+A "Library" in Lisp is a collection of Lisp functions, data and
+foreign modules. The form of the Library can be Lisp source code (for
+processing by an interpreter) or object code (usually the result of
+compilation of source code or built with some other
+mechanisms). Foreign modules are object code in a form that can be
+linked into a Lisp executable. When we speak of functions we do so in
+the most general way to include, in addition, methods and unnamed
+functions. Lisp "data" is also a general term that includes the data
+structures resulting from defining Lisp classes. A Lisp application
+may include the same set of Lisp objects as does a Library, but this
+does not mean that the application is necessarily a "work based on the
+Library" it contains.
+The Library consists of everything in the distribution file set before
+any modifications are made to the files. If any of the functions or
+classes in the Library are redefined in other files, then those
+redefinitions ARE considered a work based on the Library. If
+additional methods are added to generic functions in the Library,
+those additional methods are NOT considered a work based on the
+Library. If Library classes are subclassed, these subclasses are NOT
+considered a work based on the Library. If the Library is modified to
+explicitly call other functions that are neither part of Lisp itself
+nor an available add-on module to Lisp, then the functions called by
+the modified Library ARE considered a work based on the Library. The
+goal is to ensure that the Library will compile and run without
+getting undefined function errors.
+It is permitted to add proprietary source code to the Library, but it
+must be done in a way such that the Library will still run without
+that proprietary code present. Section 5 of the LGPL distinguishes
+between the case of a library being dynamically linked at runtime and
+one being statically linked at build time. Section 5 of the LGPL
+states that the former results in an executable that is a "work that
+uses the Library." Section 5 of the LGPL states that the latter
+results in one that is a "derivative of the Library", which is
+therefore covered by the LGPL. Since Lisp only offers one choice,
+which is to link the Library into an executable at build time, we
+declare that, for the purpose applying the LGPL to the Library, an
+executable that results from linking a "work that uses the Library"
+with the Library is considered a "work that uses the Library" and is
+therefore NOT covered by the LGPL.
+Because of this declaration, section 6 of LGPL is not applicable to
+the Library. However, in connection with each distribution of this
+executable, you must also deliver, in accordance with the terms and
+conditions of the LGPL, the source code of Library (or your derivative
+thereof) that is incorporated into this executable.
+Version 2.1, February 1999
+Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+Everyone is permitted to copy and distribute verbatim copies
+of this license document, but changing it is not allowed.
+[This is the first released version of the Lesser GPL. It also counts
+as the successor of the GNU Library Public License, version 2, hence
+the version number 2.1.]
+The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it. You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+When we speak of free software, we are referring to freedom of use,
+not price. Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights. These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you. You must make sure that they, too, receive or can get the source
+code. If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it. And you must show them these terms so they know their rights.
+We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+To protect each distributor, we want to make it very clear that
+there is no warranty for the free library. Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+Finally, software patents pose a constant threat to the existence of
+any free program. We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder. Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License. This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License. We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library. The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom. The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License. It also provides other free software developers Less
+of an advantage over competing non-free programs. These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries. However, the Lesser license provides advantages in certain
+special circumstances.
+For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard. To achieve this, non-free programs must be
+allowed to use the library. A more frequent case is that a free
+library does the same job as widely used non-free libraries. In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software. For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+The precise terms and conditions for copying, distribution and
+modification follow. Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library". The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+The "Library", below, refers to any such software library or work
+which has been distributed under these terms. A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language. (Hereinafter, translation is
+included without limitation in the term "modification".)
+"Source code" for a work means the preferred form of the work for
+making modifications to it. For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it). Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+a) The modified work must itself be a software library.
+b) You must cause the files modified to carry prominent notices
+stating that you changed the files and the date of any change.
+c) You must cause the whole of the work to be licensed at no
+charge to all third parties under the terms of this License.
+d) If a facility in the modified Library refers to a function or a
+table of data to be supplied by an application program that uses
+the facility, other than as an argument passed when the facility
+is invoked, then you must make a good faith effort to ensure that,
+in the event an application does not supply such function or
+table, the facility still operates, and performs whatever part of
+its purpose remains meaningful.
+(For example, a function in a library to compute square roots has
+a purpose that is entirely well-defined independent of the
+application. Therefore, Subsection 2d requires that any
+application-supplied function or table used by this function must
+be optional: if the application does not supply it, the square
+root function must still compute square roots.)
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library. To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License. (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.) Do not make any other change in
+these notices.
+Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library". Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library". The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library. The
+threshold for this to be true is not precisely defined by law.
+If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work. (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+6. As an exception to the Sections above, you may also combine or
+link a "work that uses the Library" with the Library to produce a
+work containing portions of the Library, and distribute that work
+under terms of your choice, provided that the terms permit
+modification of the work for the customer's own use and reverse
+engineering for debugging such modifications.
+You must give prominent notice with each copy of the work that the
+Library is used in it and that the Library and its use are covered by
+this License. You must supply a copy of this License. If the work
+during execution displays copyright notices, you must include the
+copyright notice for the Library among them, as well as a reference
+directing the user to the copy of this License. Also, you must do one
+of these things:
+a) Accompany the work with the complete corresponding
+machine-readable source code for the Library including whatever
+changes were used in the work (which must be distributed under
+Sections 1 and 2 above); and, if the work is an executable linked
+with the Library, with the complete machine-readable "work that
+uses the Library", as object code and/or source code, so that the
+user can modify the Library and then relink to produce a modified
+executable containing the modified Library. (It is understood
+that the user who changes the contents of definitions files in the
+Library will not necessarily be able to recompile the application
+to use the modified definitions.)
+b) Use a suitable shared library mechanism for linking with the
+Library. A suitable mechanism is one that (1) uses at run time a
+copy of the library already present on the user's computer system,
+rather than copying library functions into the executable, and (2)
+will operate properly with a modified version of the library, if
+the user installs one, as long as the modified version is
+interface-compatible with the version that the work was made with.
+c) Accompany the work with a written offer, valid for at
+least three years, to give the same user the materials
+specified in Subsection 6a, above, for a charge no more
+than the cost of performing this distribution.
+d) If distribution of the work is made by offering access to copy
+from a designated place, offer equivalent access to copy the above
+specified materials from the same place.
+e) Verify that the user has already received a copy of these
+materials or that you have already sent this user a copy.
+For an executable, the required form of the "work that uses the
+Library" must include any data and utility programs needed for
+reproducing the executable from it. However, as a special exception,
+the materials to be distributed need not include anything that is
+normally distributed (in either source or binary form) with the major
+components (compiler, kernel, and so on) of the operating system on
+which the executable runs, unless that component itself accompanies
+the executable.
+It may happen that this requirement contradicts the license
+restrictions of other proprietary libraries that do not normally
+accompany the operating system. Such a contradiction means you cannot
+use both them and the Library together in an executable that you
+7. You may place library facilities that are a work based on the
+Library side-by-side in a single library together with other library
+facilities not covered by this License, and distribute such a combined
+library, provided that the separate distribution of the work based on
+the Library and of the other library facilities is otherwise
+permitted, and provided that you do these two things:
+a) Accompany the combined library with a copy of the same work
+based on the Library, uncombined with any other library
+facilities. This must be distributed under the terms of the
+Sections above.
+b) Give prominent notice with the combined library of the fact
+that part of it is a work based on the Library, and explaining
+where to find the accompanying uncombined form of the same work.
+8. You may not copy, modify, sublicense, link with, or distribute
+the Library except as expressly provided under this License. Any
+attempt otherwise to copy, modify, sublicense, link with, or
+distribute the Library is void, and will automatically terminate your
+rights under this License. However, parties who have received copies,
+or rights, from you under this License will not have their licenses
+terminated so long as such parties remain in full compliance.
+9. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Library or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Library (or any work based on the
+Library), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Library or works based on it.
+10. Each time you redistribute the Library (or any work based on the
+Library), the recipient automatically receives a license from the
+original licensor to copy, distribute, link with or modify the Library
+subject to these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties with
+this License.
+11. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Library at all. For example, if a patent
+license would not permit royalty-free redistribution of the Library by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Library.
+If any portion of this section is held invalid or unenforceable under any
+particular circumstance, the balance of the section is intended to apply,
+and the section as a whole is intended to apply in other circumstances.
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+12. If the distribution and/or use of the Library is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Library under this License may add
+an explicit geographical distribution limitation excluding those countries,
+so that distribution is permitted only in or among countries not thus
+excluded. In such case, this License incorporates the limitation as if
+written in the body of this License.
+13. The Free Software Foundation may publish revised and/or new
+versions of the Lesser 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 Library
+specifies a version number of this License which applies to it and
+"any later version", you have the option of following the terms and
+conditions either of that version or of any later version published by
+the Free Software Foundation. If the Library does not specify a
+license version number, you may choose any version ever published by
+the Free Software Foundation.
+14. If you wish to incorporate parts of the Library into other free
+programs whose distribution conditions are incompatible with these,
+write to the author to ask for permission. For software which is
+copyrighted by the Free Software Foundation, write to the Free
+Software Foundation; we sometimes make exceptions for this. Our
+decision will be guided by the two goals of preserving the free status
+of all derivatives of our free software and of promoting the sharing
+and reuse of software generally.
\ No newline at end of file
diff -rN -u old-liards/README new-liards/README
--- old-liards/README 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/README 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,65 @@
+** Liards - You are what you is
+The developer of this library doesn't know what these letters stand for exactly, but he does prefer when it's pronounced "Liiarrdzzzz!!", As if spoken by a highly intoxicated, older slightly overweight and generally off-balanced individual in an overly filled bar. As in "Ye're all a bunzjov liards, in and round dust street!!! I lizpededed on byte-compilin when you'ezz wer cho small zoo lifta cup o coffee. Punks!! Stealin me job, settin back computtin wuznot years. I'l crush you beans... bones... beans.. lika.." *thud* "... zzzzzzz ...."
+** Introduction
+Liards simply wants assembly forms for the arm7 and/or arm9 processor of a Nintendo DS and transforms them into an .nds file, to be executed on a real live DS or a DS emulator. It's a bit simplish right now, and will probably be so indefinitely, but once it has been in work a bit, it should acquire a bit more functions. Ideally it would be a Nintendo DS development kit for assembler, perhaps to a point that you could or not be mistaken that the abstraction layer actually hides some kind of lisp implementation somewhere. For now I'm just glad it works, frankly.
+** Licence - LLGPL, see the included LICENSE file
+** Authors
+- Ties Stuij
+** Installation
+To get the latest release, download it from
+To get the latest development version, do a darcs get:
+darcs get
+Liards depends on Armish, Arnesi, Split-sequence and FiveAM (because it's needed by Armish). Get them to play nice with asdf and fire up Liards.
+** Testing
+(nds-test-compile (initialize-and-make-red) (arm7-loop) "red-test.nds")
+Where initialize-and-make-red and arm7-loop are functions that output opcodes that have been assembled with assemble. See the test.lisp file. If all went well an .nds file called red-test.nds will lie waiting for you in the test-roms directory. Load it in an emulator or upload it to your Nintendo DS if you've got the know-how. If stuff fails, you'll find some debugging globals and functions in test.lisp to aid you. Of course this shouldn't be the case for this initial setup. If stuff DID fail, send a mail.
+The test.lisp file also contains some extra debugging aids to query headers. Have a look if you feel you have a need.
+The resulting .nds file in the command above has been tested on various emulators, wireless-multiboot and a supercard micro-sd slot-2 card. All but DSEmu did what was expected, and DSEmu failed because it didn't support the arm blx instruction properly.
+** Exported functions
+Well... again... this function is exported, because you have to export at least one function. Is what i think. It's all you need really together with the assemble function from Armish, but this function is just gonna be the base of a larger function/macro structure to write useful stuff. Either i'm gonna write it or you, inside the Liards package or in another, but this function is hardly to be called a proper interface to outside packages. I'm not even satisfied by the argument handling. Still, it's all you need...
+- nds-compile - compiles an .nds file when fed compiled arm9 and arm7 code and optionally a name and a directory.
+(nds-compile arm9-code arm7-code &optional (file "my.nds") (dir *rom-dir*))
+Where arm9-code and arm7-code are lists of opcodes/compiled instructions for the appropriate processor. File and *rom-dir* are file and rom-dir. *rom-dir* is set to the `roms' dir under the liards root.
+example usage:
+(nds-compile (initialize-and-make-red) (arm7-loop) "red.nds")
+** History
+First version
+** Todo
+- a few header entries that should better have values which are better set through calculation are as of now fixed, most notably rom-size.
\ No newline at end of file
diff -rN -u old-liards/crc.lisp new-liards/crc.lisp
--- old-liards/crc.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/crc.lisp 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,45 @@
+(in-package :liards)
+(defvar *crc16-table*
+ (make-array 256 :initial-contents
+ '(#x0000 #xC0C1 #xC181 #x0140 #xC301 #x03C0 #x0280 #xC241
+ #xC601 #x06C0 #x0780 #xC741 #x0500 #xC5C1 #xC481 #x0440
+ #xCC01 #x0CC0 #x0D80 #xCD41 #x0F00 #xCFC1 #xCE81 #x0E40
+ #x0A00 #xCAC1 #xCB81 #x0B40 #xC901 #x09C0 #x0880 #xC841
+ #xD801 #x18C0 #x1980 #xD941 #x1B00 #xDBC1 #xDA81 #x1A40
+ #x1E00 #xDEC1 #xDF81 #x1F40 #xDD01 #x1DC0 #x1C80 #xDC41
+ #x1400 #xD4C1 #xD581 #x1540 #xD701 #x17C0 #x1680 #xD641
+ #xD201 #x12C0 #x1380 #xD341 #x1100 #xD1C1 #xD081 #x1040
+ #xF001 #x30C0 #x3180 #xF141 #x3300 #xF3C1 #xF281 #x3240
+ #x3600 #xF6C1 #xF781 #x3740 #xF501 #x35C0 #x3480 #xF441
+ #x3C00 #xFCC1 #xFD81 #x3D40 #xFF01 #x3FC0 #x3E80 #xFE41
+ #xFA01 #x3AC0 #x3B80 #xFB41 #x3900 #xF9C1 #xF881 #x3840
+ #x2800 #xE8C1 #xE981 #x2940 #xEB01 #x2BC0 #x2A80 #xEA41
+ #xEE01 #x2EC0 #x2F80 #xEF41 #x2D00 #xEDC1 #xEC81 #x2C40
+ #xE401 #x24C0 #x2580 #xE541 #x2700 #xE7C1 #xE681 #x2640
+ #x2200 #xE2C1 #xE381 #x2340 #xE101 #x21C0 #x2080 #xE041
+ #xA001 #x60C0 #x6180 #xA141 #x6300 #xA3C1 #xA281 #x6240
+ #x6600 #xA6C1 #xA781 #x6740 #xA501 #x65C0 #x6480 #xA441
+ #x6C00 #xACC1 #xAD81 #x6D40 #xAF01 #x6FC0 #x6E80 #xAE41
+ #xAA01 #x6AC0 #x6B80 #xAB41 #x6900 #xA9C1 #xA881 #x6840
+ #x7800 #xB8C1 #xB981 #x7940 #xBB01 #x7BC0 #x7A80 #xBA41
+ #xBE01 #x7EC0 #x7F80 #xBF41 #x7D00 #xBDC1 #xBC81 #x7C40
+ #xB401 #x74C0 #x7580 #xB541 #x7700 #xB7C1 #xB681 #x7640
+ #x7200 #xB2C1 #xB381 #x7340 #xB101 #x71C0 #x7080 #xB041
+ #x5000 #x90C1 #x9181 #x5140 #x9301 #x53C0 #x5280 #x9241
+ #x9601 #x56C0 #x5780 #x9741 #x5500 #x95C1 #x9481 #x5440
+ #x9C01 #x5CC0 #x5D80 #x9D41 #x5F00 #x9FC1 #x9E81 #x5E40
+ #x5A00 #x9AC1 #x9B81 #x5B40 #x9901 #x59C0 #x5880 #x9841
+ #x8801 #x48C0 #x4980 #x8941 #x4B00 #x8BC1 #x8A81 #x4A40
+ #x4E00 #x8EC1 #x8F81 #x4F40 #x8D01 #x4DC0 #x4C80 #x8C41
+ #x4400 #x84C1 #x8581 #x4540 #x8701 #x47C0 #x4680 #x8641
+ #x8201 #x42C0 #x4380 #x8341 #x4100 #x81C1 #x8081 #x4040)))
+(defun crc16 (data)
+ (let ((crc #xFFFF))
+ (dotimes (byte-nr (length data) (make-array 2 :initial-contents `(,(logand crc #xff) ,(ash crc -8))))
+ (setf crc (logxor (logand (ash crc -8) #xFFFF)
+ (aref *crc16-table*
+ (logand (logxor crc
+ (nth byte-nr data))
+ #xFF)))))))
\ No newline at end of file
diff -rN -u old-liards/file-stitch.lisp new-liards/file-stitch.lisp
--- old-liards/file-stitch.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/file-stitch.lisp 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,61 @@
+(in-package :liards)
+(defvar *rom-dir* (append (pathname-directory *load-truename*)
+ (list "roms")))
+(defun rom-location (&optional (rom-name "my.nds") (rom-dir *rom-dir*))
+ (concatenate 'string (namestring (make-pathname :directory rom-dir)) rom-name))
+(defun write-rom (rom &key (file "my.nds") (dir *rom-dir*))
+ (with-open-file (s (rom-location file dir) :direction :output :element-type '(unsigned-byte 8) :if-exists :supersede)
+ (write-sequence rom s)))
+(defun nds-compile (arm9-code arm7-code &optional (file "my.nds") (dir *rom-dir*))
+ (let* ((header-class (make-instance 'nds-header))
+ (header (make-list #x200 :initial-element 0))
+ (arm9-code-size (length arm9-code))
+ (arm9-aligned (align arm9-code))
+ (arm7-code-size (length arm7-code))
+ (arm7-rom-offset (+ (length arm9-aligned) (length header)))
+ (filename-table-offset (+ arm7-rom-offset arm7-code-size))
+ (filename-table-aligned (align (make-list 9 :initial-element 0)))
+ (fat-offset (+ filename-table-offset (length filename-table-aligned)))
+ (application-end-offset fat-offset)
+ (logo-crc16 (crc16 *logo*)))
+ ;; make a correct header
+ (macrolet ((write-and-seal-headers (header-list)
+ (let ((res-list '(progn)))
+ (dolist (header-name header-list)
+ (setf res-list
+ (append res-list
+ `((write-header-item-and-seal (,header-name header-class)
+ (nr-to-big-endian-word-byte-list ,header-name))))))
+ res-list)))
+ (write-and-seal-headers (arm9-code-size
+ arm7-code-size
+ arm7-rom-offset
+ filename-table-offset
+ fat-offset
+ application-end-offset)))
+ (write-header-item-and-seal (logo-crc16 header-class) logo-crc16)
+ (write-header-to-list header-class header)
+ (write-header-item-and-seal (header-crc16 header-class) (crc16 (subseq header 0 #x15E)))
+ (write-header-item-to-list (header-crc16 header-class) header)
+ ;; append the lot
+ (write-rom (append header arm9-aligned arm7-code filename-table-aligned) :file file :dir dir)))
+these should be calculated dynamically:
+device-cap - not yet implemented
+It would be nice if a few more, like romsize and fat-size, are also calculated on the fly,
+for elegance sake, but hey.
diff -rN -u old-liards/hardware-layout.lisp new-liards/hardware-layout.lisp
--- old-liards/hardware-layout.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/hardware-layout.lisp 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,58 @@
+(in-package :liards)
+(defmacro def-mem-layout (list)
+ (let ((const-list '(progn)))
+ (dolist (const-pair list const-list)
+ (if (typep const-pair 'list)
+ (setf const-list (append const-list `((defconstant ,(car const-pair) ,(cadr const-pair)))))))))
+;; expects name, start address, end adress and bus-width
+;; just now just using name and start address
+ ("mem-blocks"
+ "- shared"
+ "-- all-purpose"
+ (main-ram #x02000000 #x023FFFFF 16)
+ (protection #x04000308 #x0400030C :?) ;; got no clue what this does (write-once sadly) \f libnds
+ (shared-wram-bank-0 #x03000000 #x03003FFF 32) ;; check it, ambigious info. this one from dovotos tutorial
+ (shared-wram-bank-1 #x03004000 #x03007FFF 32) ;; idem
+ (gba-rom #x08000000 #x09FFFFFF 16)
+ (gba-sram #x0A000000 #x0A00FFFF 8)
+ "-- video"
+ "--- banks"
+ (bank-a #x06800000 #x0681FFFF 16)
+ (bank-b #x06820000 #x0683FFFF 16)
+ (bank-c #x06840000 #x0685FFFF 16)
+ (bank-d #x06860000 #x0687FFFF 16)
+ (bank-e #x06880000 #x0688FFFF 16)
+ (bank-f #x06890000 #x06983FFF 16)
+ (bank-g #x06894000 #x06897FFF 16)
+ (bank-h #x06898000 #x0689FFFF 16)
+ (bank-i #x068A0000 #x068A3FFF 16)
+ "--- virtual"
+ (main-background #x06000000 #x0607FFFF 16)
+ (sub-background #x06200000 #x0621FFFF 16)
+ (main-sprite #x06400000 #x0643FFFF 16)
+ (sub-sprite #x06600000 #x0661FFFF 16)
+ "- arm7 reachable"
+ (arm7-bios #x00000000 #x00003FFF :?)
+ (arm7-iwram #x03800000 #x0380FFFF 32)
+ (wifi-mac-mem #x04804000 #x04805FFF 16)
+ "- arm9 reachable"
+ (bios #xFFFF0000 #xFFFF7FFF :?)
+ "-- fast"
+ (itcm #x00000000 #x00007FFF 32)
+ (dtcm #x0B000000 #x0B003FFF 32)
+ "-- graphics"
+ (palette-ram #x05000000 #x050003FF 16)
+ (sub-palette-ram #x05000400 #x050007FF 16)
+ (oam-main #x07000000 #x070003FF 32)
+ (oam-sub #x07000400 #x070007FF 32)))
\ No newline at end of file
diff -rN -u old-liards/header-helpers.lisp new-liards/header-helpers.lisp
--- old-liards/header-helpers.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/header-helpers.lisp 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,49 @@
+(in-package :liards)
+(defclass header-item-base ()
+ ((no-bytes :accessor no-bytes :initarg :no-bytes)
+ (header-pos :accessor header-pos :initarg :header-pos)
+ (value :accessor value :initarg :value :type (array (unsigned-byte 8)))
+ (setp :accessor setp :initarg :setp :initform nil)))
+(defun make-header-slot-class (slot)
+ `(defclass ,(first slot) (header-item-base) ()))
+(defun header-item-slot (header-slot)
+ (let ((slot-name (first header-slot))
+ (header-pos (second header-slot))
+ (no-bytes (third header-slot))
+ (value (fourth header-slot)))
+ `(,slot-name :accessor ,slot-name
+ :initform (make-instance ',slot-name
+ :no-bytes ,no-bytes
+ :header-pos ,header-pos
+ :value (value-handler ,no-bytes ,value)
+ ,@(if value '(:setp t))))))
+(defun value-handler (no-bytes value)
+ (let ((value-arr (make-list no-bytes :initial-element 0)))
+ (if (and value (not (eql value :nil)))
+ (write-header-item value-arr value)
+ value-arr)))
+(defun write-header-item (dest-lst source-lst)
+ (let ((src-lst-ln (length source-lst))
+ (dst-lst-ln (length dest-lst)))
+ (if (not (= src-lst-ln dst-lst-ln))
+ (error "size of destination list (~D) doesnt match that of the source list (~D) ... scoundrel ..." dst-lst-ln src-lst-ln)
+ (replace dest-lst source-lst))))
+(defun write-header-item-and-seal (header-item source-lst)
+ (write-header-item (value header-item) source-lst)
+ (setf (setp header-item) t))
+(defun write-header-item-to-list (header-item list)
+ (let ((pos (header-pos header-item)))
+ (setf (subseq list pos (+ pos (no-bytes header-item))) (value header-item))))
+(defun write-header-to-list (header-class list)
+ (dolist (item (instance-slot-names header-class))
+ (write-header-item-to-list (slot-value header-class item) list)))
diff -rN -u old-liards/header.lisp new-liards/header.lisp
--- old-liards/header.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/header.lisp 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,92 @@
+(in-package :liards)
+(defvar *logo*
+ '(200 96 79 226 1 112 143 226 23 255 47 225 18 79 17 72 18 76 32 96 100 96 124
+ 98 48 28 57 28 16 74 0 240 20 248 48 106 128 25 177 106 242 106 0 240 11 248
+ 48 107 128 25 177 107 242 107 0 240 8 248 112 106 119 107 7 76 96 96 56 71 7
+ 75 210 24 154 67 7 75 146 8 210 24 12 223 247 70 4 240 31 229 0 254 127 2 240
+ 255 127 2 240 1 0 0 255 1 0 0 0 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
+ "seems to be startup code for one or the other `thing'. Damn you homebrew, and your hackerish ways")
+(defmacro def-nds-header (slot-list)
+ "Expects the layout of the nds header, so not much wiggle room here. it expects three or four values per header section.
+ from left to right: the name of the section, the position of the section, the amount of bytes it wants to write and as a fourth an optional
+ standard value as a vector, fill in :nil to default to zero bits and flag that it doesn't need to be touched anymore.
+ Def-nds-header builds a class with the names as slots. In those slots it builds appropriate classes with
+ the same name who's value slot (an array) shares it's structure with it's rightfull place on the *header* array, so we won't have to write
+ that stuff in explicitely all the time. The sections that actually have to do some specialized stuff, mostly determine the position for this
+ and that in the actual nds file, do so when they are called with header-item-handler. def-nds-header and header-item-handler should
+ together cover the creation of a correct header (== *header*). After which two crc checks will really finish it off with icecream on top."
+ `(progn
+ ,@(mapcar #'make-header-slot-class slot-list)
+ (defclass nds-header ()
+ ,(mapcar #'header-item-slot slot-list))))
+ ((game-title #x000 12 '(#x2E 00 00 #xEA 00 00 00 00 00 00 00 00))
+ ;; yes well... this should be the the game title but according to the ndstool
+ ;; c++ file this info is needed for "PassMe's that start @ 0x08000000"
+ (game-code #x00c 4 '(35 35 35 35)) ;; f\ndstool "####"
+ (maker-code #x010 2 :nil)
+ (unit-code #x012 1 :nil)
+ (device-type #x013 1 :nil)
+ (device-cap #x014 1)
+ (reserved-1 #x015 8 :nil) ;; was cardinfo
+ (rom-version #x01e 1 :nil)
+ (flags #x01f 1 '(#x04)) ;; flags c\autostart f\ndstool
+ (arm9-rom-offset #x020 4 '(0 2 0 0))
+ (arm9-entry-addr #x024 4 '(0 0 0 2))
+ (arm9-ram-addr #x028 4 '(0 0 0 2))
+ (arm9-code-size #x02c 4)
+ (arm7-rom-offset #x030 4)
+ (arm7-entry-addr #x034 4 '(0 0 128 3))
+ (arm7-ram-addr #x038 4 '(0 0 128 3))
+ (arm7-code-size #x03c 4)
+ (filename-table-offset #x040 4)
+ (filename-table-size #x044 4 '(9 0 0 0)) ;; ? idem
+ (fat-offset #x048 4)
+ (fat-size #x04c 4 :nil)
+ (arm9-overlay-offset #x050 4 :nil)
+ (arm9-overlay-size #x054 4 :nil)
+ (arm7-overlay-offset #x058 4 :nil)
+ (arm7-overlay-size #x05c 4 :nil)
+ (rom-ctrl-info-1 #x060 4 '(#x00 #x60 #x58 #x00)) ;; ctrl-reg-flags-read f\ndstool used in modes 1/3 \f libnds
+ (rom-ctrl-info-2 #x064 4 '(#xF8 #x08 #x18 #x00)) ;; ctrl-reg-flags-init f\ndstool used in mode 2 \f libnds
+ (banner-offset #x068 4 :nil) ;; icon/title-offs
+ (secure-area-crc16 #x06c 2 :nil)
+ (rom-ctrl-info-3 #x06e 2 '(30 5)) ;; rom-timeout. most have it on 30 5, but why?
+ (arm-9-? #x070 4 :nil)
+ (arm-7-? #x074 4 :nil)
+ (magic #x078 8 :nil)
+ (application-end-offset #x080 4) ;; rom-size
+ (rom-header-size #x084 4 '(0 2 0 0))
+ (unknown-5 #x088 24 :nil) ;; was 56, is still kinda... in total... bit useless this entry; just for bw-compatibility
+ (sram-backup #x0a0 9 (string-to-octets "SRAM_V110" :utf-8))
+ (auto-flashme-start #x0ac 7 (concatenate 'vector (string-to-octets "PASS01" :utf-8) '(#x96)))
+ ;; f\ndstool "automatically start with FlashMe, make it look more like a GBA rom"
+ (logo #x0c0 156 *logo*)
+ (logo-crc16 #x15c 2)
+ (header-crc16 #x15e 2)
+ (reserved #x160 160 :nil)))
+;; phased out:
+#-(and) (defgeneric header-item-handler (header-item-base)
+ (:documentation "handles non-constant header items")
+ ;; game-title - just make sure there's a name in *game-title* if you want to change the default
+ ;; commented out right now because appearantly the info that the name info is stepping on is needed for passme devices
+ #-(and)(:method ((title game-title))
+ (let ((array (make-array (no-bytes title))))
+ ;; there's a bit to much array replacing going on between this function and write-header-item,
+ ;; but somehow i think it's more elegant
+ (if (write-header-item (value title) (replace array (string-to-octets *game-title* :utf-8)))
+ (setf (setp title) t)
+ (error "stuff went wrong writing game title")))))
+#-(and) (defun process-leftover-headers (h)
+ "makes sure the non-constant header items are processed correctly so we have a fully filled out and correct nds header...
+ except for the crcs"
+ (dolist (item (instance-slot-names h))
+ (let ((item-class (slot-value h item)))
+ (if (not (or (setp item-class) (eq item 'logo-crc16 ) (eq item 'header-crc16)))
+ (header-item-handler item-class)))))
diff -rN -u old-liards/helpers.lisp new-liards/helpers.lisp
--- old-liards/helpers.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/helpers.lisp 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,12 @@
+(in-package :liards)
+;; got from symbolics code somewhere (hope they don't sue)
+(defmethod instance-slot-names ((instance standard-object))
+ "Given an INSTANCE, returns a list of the slots in the instance's class."
+ (mapcar #'mopp:slot-definition-name
+ (mopp:class-direct-slots (class-of instance))))
+(defun class-slot-names (class-name)
+ "Given a CLASS-NAME, returns a list of the slots in the class."
+ (mapcar #'mopp:slot-definition-name
+ (mopp:class-direct-slots (find-class class-name))))
diff -rN -u old-liards/liards.asd new-liards/liards.asd
--- old-liards/liards.asd 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/liards.asd 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,18 @@
+(defpackage :liards.system
+ (:use :cl :asdf))
+(in-package :liards.system)
+(defsystem liards
+ :version "0.0.1"
+ :author "Ties Stuij"
+ :depends-on (:arnesi :split-sequence :armish)
+ :components ((:file "packages")
+ (:file "helpers" :depends-on ("packages"))
+ (:file "registers" :depends-on ("helpers"))
+ (:file "hardware-layout" :depends-on ("helpers"))
+ (:file "crc" :depends-on ("helpers"))
+ (:file "header-helpers" :depends-on ("helpers"))
+ (:file "header" :depends-on ("header-helpers"))
+ (:file "file-stitch" :depends-on ("registers" "hardware-layout" "crc" "header"))
+ (:file "test" :depends-on ("file-stitch"))))
\ No newline at end of file
diff -rN -u old-liards/packages.lisp new-liards/packages.lisp
--- old-liards/packages.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/packages.lisp 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,9 @@
+(in-package :cl-user)
+(defpackage :liards
+ (:use :common-lisp
+ :armish
+ :it.bese.arnesi
+ :split-sequence)
+ (:shadowing-import-from :it.bese.arnesi :partition)
+ (:export :nds-compile))
\ No newline at end of file
Binary files old-liards/reference-roms/red.nds and new-liards/reference-roms/red.nds differ
diff -rN -u old-liards/registers.lisp new-liards/registers.lisp
--- old-liards/registers.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/registers.lisp 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,175 @@
+(in-package :liards)
+(defmacro def-registers (list)
+ (let ((const-list '(progn)))
+ (dolist (const-pair list const-list)
+ (if (typep const-pair 'list)
+ (setf const-list (append const-list `((defconstant ,(car const-pair) ,(cadr const-pair)))))))))
+ ("define registers and their bit mnemonics"
+ "setup/general"
+ (reg-ex-mem-ctrl #x04000204
+ ((ram-region-access-cycle-ctrl :arm9 0 1)
+ (rom-1st-access-cycle-ctrl :arm9 2 3)
+ (rom-2nd-access-cycle-ctrl :arm9 4)
+ (phi-terminal-output-ctrl :arm9 5 6)
+ (cartridge-access-right :arm9 7)
+ (card-access-right :arm9 11)
+ (main-mem-iface-priority :arm9 14)
+ (main-mem-priority :arm9 15)))
+ (reg-pow-ctrl #x04000304
+ ((snd-speakers-pwr :arm7 0)
+ (wifi-pwr :arm7 1)
+ (lcd-screens-pow :arm9 0)
+ (2d-core-a-pow :arm9 1)
+ (3d-render-core-pow :arm9 2)
+ (3d-geometry-core-pow :arm9 3)
+ (2d-core-b-pow :arm9 4)
+ (lcd-swap :arm9 15)))
+ (reg-halt-ctrl #x04000300
+ ((check :both 0)
+ (pause-mode :both 14 15)))
+ "display"
+ (reg-disp-ctrl #x4000000
+ ((bg-mode :both 0 2)
+ (reserved-for-bios :none 3)
+ (disp-frame-select :both 4)
+ (h-blank-interval-free :both 5)
+ (obj-char-disp-mapping :both 6)
+ (forced-blank :both 7)
+ (screen-disp-bg-0 :both 8)
+ (screen-disp-bg-1 :both 9)
+ (screen-disp-bg-2 :both 10)
+ (screen-disp-bg-3 :both 11)
+ (screen-disp-obj :both 12)
+ (window-0-disp-flag :both 13)
+ (window-1-disp-flag :both 14)
+ (obj-window-disp-flag :both 15)))
+ (reg-disp-stat #x4000004
+ ((disp-in-vblank :both 0)
+ (disp-in-hblank :both 1)
+ (disp-vcount-flag :both 2)
+ (disp-vblank-irq :both 3)
+ (disp-hblank-irq :both 4)
+ (disp-vcount-irq :both 5)
+ (disp-vcount-match :both 7 15)))
+ (reg-vcount #x4000006
+ ((curr-scanline :both 0 9)))
+ (reg-vram-ctrl-a #x04000240
+ ((alloc-options :arm9 0 1)
+ (offset :arm9 3 4)
+ (enable :arm9 7)))
+ (reg-vram-ctrl-b #x04000241
+ reg-vram-ctrl-a)
+ (reg-vram-ctrl-c #x04000242
+ ((alloc-options :arm9 0 2)
+ (offset :arm9 3 4)
+ (enable :arm9 7)))
+ (reg-vram-ctrl-d #x04000243
+ reg-vram-ctrl-b)
+ (reg-vram-ctrl-e #x04000244
+ reg-vram-ctrl-b)
+ (reg-vram-ctrl-f #x04000245
+ reg-vram-ctrl-b)
+ (reg-vram-ctrl-g #x04000246
+ reg-vram-ctrl-b)
+ (reg-vram-ctrl-h #x04000248
+ reg-vram-ctrl-b)
+ (reg-vram-ctrl-i #x04000249
+ ((alloc-options :arm9 0 1)
+ (enable :arm9 7)))
+ (reg-wram-ctrl #x04000247
+ ((bank-specification :arm9 0 1)))
+ (reg-wvram-stat #x04000240
+ ((vram-c-setting :arm7 0)
+ (vram-d-setting :arm7 1)
+ (wram-0-setting :arm7 8)
+ (wram-1-setting :arm7 9)))
+ "dma"
+ (reg-dma-0-source-addr #x040000B0)
+ (reg-dma-1-source-addr #x040000BC)
+ (reg-dma-2-source-addr #x040000C8)
+ (reg-dma-3-source-addr #x040000D4)
+ (reg-dma-0-dest-addr #x040000B4)
+ (reg-dma-1-dest-addr #x040000C0)
+ (reg-dma-2-dest-addr #x040000CC)
+ (reg-dma-3-dest-addr #x040000D8)
+ (reg-dma-0-ctrl #x040000B8
+ ((size-count :arm7 0 15)
+ (dest-addr-ctrl :arm7 21 22)
+ (source-addr-ctrl :arm7 23 24)
+ (dma-repeat :arm7 25)
+ (dma-transfer-type :arm7 26)
+ (dma-start-timing :arm7 28 29)
+ (dma-irq-on-size-count-end :arm7 30)
+ (dma-enable :arm7 31)))
+ (reg-dma-1-ctrl #x040000C4
+ reg-dma-0-ctrl)
+ (reg-dma-2-ctrl #x040000D0
+ reg-dma-0-ctrl)
+ (reg-dma-3-ctrl #x040000DC
+ reg-dma-0-ctrl)
+ "keys"
+ (reg-key-status #x04000130
+ ((button-a :both 0)
+ (button-b :both 1)
+ (select :both 2)
+ (start :both 3)
+ (right :both 4)
+ (left :both 5)
+ (up :both 6)
+ (down :both 7)
+ (button-r :both 8)
+ (button-l :both 9)))
+ (reg-key-xy #x04000136
+ ((button-x :arm7 0)
+ (button-y :arm7 1)
+ (touchpad :arm7 6)
+ (screen-status :arm7 7)))
+ "interprocessor communication"
+ (reg-ipc-sync #x04000180
+ ((ipc-remote-status :both 0 3)
+ (ipc-local-status :both 8 11)
+ (ipc-irq-req :both 13)
+ (ipc-irq-enable :both 14)))
+ (reg-ipc-recieve-fifo #x04100000)
+ (reg-ipc-send-fifo #x04000188)
+ (reg-ipc-fifo-ctrl #x04000184
+ ((send-fifo-empty-status :both 0)
+ (send-fifo-full-status :both 1)
+ (send-fifo-irq-enable :both 2)
+ (send-fifo-clear :both 3)
+ (receive-fifo-empty :both 8)
+ (recieve-fifo-full :both 9)
+ (recieve-fifo-irq-enable :both 10)
+ (fifo-error :both 14)
+ (enable-fifo :both 15)))))
\ No newline at end of file
diff -rN -u old-liards/test.lisp new-liards/test.lisp
--- old-liards/test.lisp 1969-12-31 16:00:00.000000000 -0800
+++ new-liards/test.lisp 2014-07-29 05:50:00.000000000 -0700
@@ -0,0 +1,153 @@
+(in-package :liards)
+;;; make a queryable rom
+;; globals in abun' make the coders testing fun
+(defvar *ref-rom-dir* (append (pathname-directory *load-truename*)
+ (list "reference-roms")))
+(defvar *test-rom-dir* (append (pathname-directory *load-truename*)
+ (list "test-roms")))
+(defvar *arm7-bin* '(#xFE #xFF #xFF #xEA)) ; sets core in eternal loop
+(defvar *arm9-bin* '(#x01 #x03 #xA0 #xE3 #x03 #x10 #xA0 #xE3 #x02 #x28 #xA0 #xE3 #x80 #x30 #xA0 #xE3
+ #x04 #x13 #x80 #xE5 #x00 #x20 #x80 #xE5 #x40 #x32 #x80 #xE5 #x1A #x05 #xA0 #xE3
+ #x1F #x10 #xA0 #xE3 #x03 #x29 #xA0 #xE3 #xB2 #x10 #xC0 #xE0 #x01 #x20 #x52 #xE2
+ #xFC #xFF #xFF #x1A #xFE #xFF #xFF #xEA)) ;; branch to thumb code and switch to thumb state
+(defparameter *header-class* (make-instance 'nds-header))
+(defparameter *header* (make-list #x200 :initial-element 0))
+(defparameter *query-rom* '())
+(defun nds-test-compile (arm9-bin arm7-bin &optional (file "test.nds") (dir *test-rom-dir*))
+ (let* ((arm9-code-size (length arm9-bin))
+ (arm9-aligned (align arm9-bin))
+ (arm7-code-size (length arm7-bin))
+ (arm7-rom-offset (+ (length arm9-aligned) (length *header*)))
+ (filename-table-offset (+ arm7-rom-offset arm7-code-size))
+ (filename-table-aligned (align (make-list 9 :initial-element 0)))
+ (fat-offset (+ filename-table-offset (length filename-table-aligned)))
+ (application-end-offset fat-offset)
+ (logo-crc16 (crc16 *logo*)))
+ ;; make a correct header
+ (macrolet ((write-and-seal-headers (header-list)
+ (let ((res-list '(progn)))
+ (dolist (header-name header-list)
+ (setf res-list (append res-list
+ `((write-header-item-and-seal (,header-name *header-class*)
+ (nr-to-big-endian-word-byte-list ,header-name))))))
+ res-list)))
+ (write-and-seal-headers (arm9-code-size arm7-code-size arm7-rom-offset filename-table-offset fat-offset application-end-offset)))
+ (write-header-item-and-seal (logo-crc16 *header-class*) logo-crc16)
+ (write-header-to-list *header-class* *header*)
+ (write-header-item-and-seal (header-crc16 *header-class*) (crc16 (subseq *header* 0 #x15E)))
+ (write-header-item-to-list (header-crc16 *header-class*) *header*)
+ ;; append the lot
+ (setf *query-rom* (append *header* arm9-aligned arm7-bin filename-table-aligned))
+ (write-rom *query-rom* :file file :dir dir)))
+;; test test-compiler
+;; (nds-test-compile *arm9-bin* *arm7-bin*)
+;; and load your favorite .nds sourcecode debugger. freeware-wise i think you're limited to dsemu
+;;;; query a number of headers
+;; the functions and macros that make it happen
+(defmacro create-empty-headers (name-list)
+ (let* ((header-list '()))
+ `(progn ,@(dolist (name name-list header-list)
+ (setf header-list
+ (append header-list
+ `((progn ,`(defparameter ,name
+ (list "name" (make-list #x200 :initial-element 0)))
+ ,name))))))))
+(defun read-headers (file-list headers)
+ (mapc #'read-logo file-list headers))
+(defun read-logo (filename sequence)
+ (with-open-file (s (rom-location (cadr filename) *ref-rom-dir*) :element-type 'unsigned-byte)
+ (read-sequence (second sequence) s)
+ (setf (car sequence) (car filename))))
+(defun header-info (slot-name header)
+ (let ((slot (slot-value *header-class* slot-name)))
+ (subseq header (header-pos slot) (+ (header-pos slot) (no-bytes slot)))))
+(defun header-info-batch (slot-name headers)
+ (let ((headers-plus (append `(("mine" ,*header*)) headers)))
+ (format t "~%you asked for the bytes of ~d?:~%~%" slot-name)
+ (map nil #'(lambda (header)
+ (format t "~d: ~d~%" (car header) (header-info slot-name (cadr header))))
+ headers-plus)))
+;; initialize
+(create-empty-headers (*data1* *data2* *data3* *data4*))
+(defparameter *header* (make-list #x200 :initial-element 0))
+(defparameter *valid-headers* (list *data1* *data2* *data3* *data4*))
+;; fill in a list of lists with in the front the name that you want to see printed and in the back the
+;; real file-name under the test-roms dir. Get some DS homebrew from the net is my advice.
+(read-headers '(("red" "red.nds")
+ ("red" "red.nds")
+ ("red" "red.nds")
+ ("red" "red.nds"))
+ *valid-headers*)
+;; test headers
+;; (header-info-batch 'rom-ctrl-info-1 *valid-headers*)
+;;; testing the assembly facilities
+(defun initialize-and-make-red ()
+ (assemble arm9 arm
+ (blx :main)
+ code16
+ :main
+ (ldr r0 #x04000000) ; hardware-registers offset and address of reg-disp-ctrl
+ (mov r1 #x3) ; both screens on bits
+ (ldr r2 #x00020000) ; framebuffer mode bits
+ (mov r3 #x80) ; vram bank a enabled, lcd bits
+ (ldr r4 #x04000304) ; reg-power-ctrl
+ (mov r5 r4) ; see below
+ (sub r5 #xC4) ; 0x04000240 == reg-vram-ctrl-a
+ (str r1 (r4 0))
+ (str r2 (r0 0))
+ (str r3 (r5 0))
+ (ldr r0 #x06800000)
+ (mov r1 #x31)
+ (ldr r2 #xC000)
+ :write-screen-red
+ (strh r1 (r0 0))
+ (add r0 #x2)
+ (sub r2 r2 #x1)
+ (bne :write-screen-red)
+ :loop
+ (b :loop)))
+(defun arm7-loop ()
+ (assemble arm7 arm
+ :loop
+ (b :loop)))
+(defun testerdetest ()
+ (assemble arm9 arm
+ (adr r3 :main)
+ (mov r3 r4)
+ (mov r5 r6)
+ :main))
+;; test - for testing
+;; (nds-test-compile (initialize-and-make-red) (arm7-loop) "red-test.nds")
+;; (nds-test-compile (testerdetest) (arm7-loop) "test.nds")
+;; test - normal usage
+;; (nds-compile (initialize-and-make-red) (arm7-loop) "red.nds")
\ No newline at end of file