From da3d029cf687009b4de48f83292ed6c8e895ba6b Mon Sep 17 00:00:00 2001 From: Christopher Roy Bratusek Date: Sun, 14 Aug 2016 20:08:54 +0200 Subject: [PATCH] revert new nand loader import --- nand-loader/COPYING.tinyload | 340 ---- nand-loader/Makefile | 150 +- nand-loader/Makefile.loader | 54 - nand-loader/README | 31 +- nand-loader/README.libogc | 1 + nand-loader/README.tinyload | 131 -- nand-loader/app_booter.s | 62 - .../binary/vWii_NAND_Loader_svn_r2.zip | Bin 2564 -> 0 bytes nand-loader/cache.c | 39 - nand-loader/cache.h | 21 - nand-loader/crt0.S | 163 -- nand-loader/data/background | Bin 0 -> 41921 bytes nand-loader/data/error | Bin 0 -> 5888 bytes nand-loader/data/loading | Bin 0 -> 5774 bytes nand-loader/hw.h | 107 -- nand-loader/ios.c | 286 --- nand-loader/ios.h | 27 - nand-loader/main.c | 167 -- nand-loader/make_app/main.cpp | 92 - nand-loader/make_app/make_app.exe | Bin 51414 -> 0 bytes nand-loader/memory.S | 192 -- nand-loader/memory.h | 9 - nand-loader/openstub.ld | 35 - nand-loader/rvl.ld | 345 ++++ nand-loader/source/asm.h | 93 + nand-loader/source/config.c | 220 +++ nand-loader/source/config.h | 28 + nand-loader/source/gui.c | 87 + nand-loader/source/gui.h | 10 + nand-loader/source/loader.c | 265 +++ nand-loader/source/loader.h | 8 + nand-loader/source/nandloader.c | 79 + nand-loader/source/patches.c | 126 ++ nand-loader/source/patches.h | 7 + nand-loader/source/pngu.c | 1561 +++++++++++++++++ nand-loader/source/pngu.h | 181 ++ nand-loader/source/pngu_impl.h | 42 + nand-loader/source/stub.S | 118 ++ nand-loader/source/sys.c | 48 + nand-loader/source/sys.h | 9 + nand-loader/source/title.c | 256 +++ nand-loader/source/title.h | 16 + nand-loader/source/tools.c | 252 +++ nand-loader/source/tools.h | 31 + nand-loader/source/utils.h | 15 + nand-loader/source/video.c | 147 ++ nand-loader/source/video.h | 20 + nand-loader/source/wpad.c | 60 + nand-loader/source/wpad.h | 12 + nand-loader/stub/Makefile | 42 - nand-loader/stub/crt0.S | 123 -- nand-loader/stub/hw.h | 107 -- nand-loader/stub/openstub.ld | 19 - nand-loader/types.h | 32 - nand-loader/utils.c | 33 - nand-loader/utils.h | 17 - 56 files changed, 4194 insertions(+), 2122 deletions(-) delete mode 100644 nand-loader/COPYING.tinyload delete mode 100644 nand-loader/Makefile.loader create mode 100644 nand-loader/README.libogc delete mode 100644 nand-loader/README.tinyload delete mode 100644 nand-loader/app_booter.s delete mode 100644 nand-loader/binary/vWii_NAND_Loader_svn_r2.zip delete mode 100644 nand-loader/cache.c delete mode 100644 nand-loader/cache.h delete mode 100644 nand-loader/crt0.S create mode 100644 nand-loader/data/background create mode 100644 nand-loader/data/error create mode 100644 nand-loader/data/loading delete mode 100644 nand-loader/hw.h delete mode 100644 nand-loader/ios.c delete mode 100644 nand-loader/ios.h delete mode 100644 nand-loader/main.c delete mode 100644 nand-loader/make_app/main.cpp delete mode 100644 nand-loader/make_app/make_app.exe delete mode 100644 nand-loader/memory.S delete mode 100644 nand-loader/memory.h delete mode 100644 nand-loader/openstub.ld create mode 100644 nand-loader/rvl.ld create mode 100644 nand-loader/source/asm.h create mode 100644 nand-loader/source/config.c create mode 100644 nand-loader/source/config.h create mode 100644 nand-loader/source/gui.c create mode 100644 nand-loader/source/gui.h create mode 100644 nand-loader/source/loader.c create mode 100644 nand-loader/source/loader.h create mode 100644 nand-loader/source/nandloader.c create mode 100644 nand-loader/source/patches.c create mode 100644 nand-loader/source/patches.h create mode 100644 nand-loader/source/pngu.c create mode 100644 nand-loader/source/pngu.h create mode 100644 nand-loader/source/pngu_impl.h create mode 100644 nand-loader/source/stub.S create mode 100644 nand-loader/source/sys.c create mode 100644 nand-loader/source/sys.h create mode 100644 nand-loader/source/title.c create mode 100644 nand-loader/source/title.h create mode 100644 nand-loader/source/tools.c create mode 100644 nand-loader/source/tools.h create mode 100644 nand-loader/source/utils.h create mode 100644 nand-loader/source/video.c create mode 100644 nand-loader/source/video.h create mode 100644 nand-loader/source/wpad.c create mode 100644 nand-loader/source/wpad.h delete mode 100644 nand-loader/stub/Makefile delete mode 100644 nand-loader/stub/crt0.S delete mode 100644 nand-loader/stub/hw.h delete mode 100644 nand-loader/stub/openstub.ld delete mode 100644 nand-loader/types.h delete mode 100644 nand-loader/utils.c delete mode 100644 nand-loader/utils.h diff --git a/nand-loader/COPYING.tinyload b/nand-loader/COPYING.tinyload deleted file mode 100644 index 08ddefd..0000000 --- a/nand-loader/COPYING.tinyload +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) 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 -this service 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 make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, 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) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -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 Program, 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 it. - -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 Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) 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; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, 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 executable. However, as a -special exception, the source code 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. - -If distribution of executable or 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 counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program 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. - - 5. 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 Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program 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 to -this License. - - 7. 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 Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program 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 Program. - -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. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program 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. - - 9. The Free Software Foundation may publish revised and/or new versions -of the 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 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 Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, 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 WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -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. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE 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. - - 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 -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - 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 2 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, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision 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, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This 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. - diff --git a/nand-loader/Makefile b/nand-loader/Makefile index 859cd8d..652aaa6 100644 --- a/nand-loader/Makefile +++ b/nand-loader/Makefile @@ -1,28 +1,134 @@ -ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") +#--------------------------------------------------------------------------------- +# Clear the implicit built in rules +#--------------------------------------------------------------------------------- +.SUFFIXES: + +#--------------------------------------------------------------------------------- +ifeq ($(strip $(DEVKITPPC)),) +$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC)") endif include $(DEVKITPPC)/wii_rules -.PHONY = all clean -CURDIR_TMP := $(CURDIR) +#--------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# INCLUDES is a list of directories containing extra header files +#--------------------------------------------------------------------------------- +TARGET := $(notdir $(CURDIR)) +BUILD := build +SOURCES := source +DATA := data +INCLUDES := -all: - @echo Make Stub - @$(MAKE) --no-print-directory -C $(CURDIR_TMP)/stub \ - -f $(CURDIR_TMP)/stub/Makefile - @mv -u $(CURDIR_TMP)/stub/stub.bin \ - $(CURDIR_TMP)/make_app/stub.bin - @echo Make NAND Loader - @$(MAKE) --no-print-directory -C $(CURDIR_TMP) \ - -f $(CURDIR_TMP)/Makefile.loader - @mv -u $(CURDIR_TMP)/loader.bin \ - $(CURDIR_TMP)/make_app/loader.bin +#--------------------------------------------------------------------------------- +# options for code generation +#--------------------------------------------------------------------------------- + +CFLAGS = -O2 -mrvl -Wall $(MACHDEP) $(INCLUDE) +CXXFLAGS = $(CFLAGS) + +LDFLAGS = $(MACHDEP) -Wl,-Map,$(notdir $@).map + +#--------------------------------------------------------------------------------- +# any extra libraries we wish to link with the project +#--------------------------------------------------------------------------------- +LIBS := -lpng -lmodplay -lasnd -lwiiuse -lbte -logc -lm -lz + +#--------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level containing +# include and lib +#--------------------------------------------------------------------------------- +LIBDIRS := + + +#--------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#--------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#--------------------------------------------------------------------------------- + +export TOPDIR := $(CURDIR) + +export OUTPUT := $(CURDIR)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +#--------------------------------------------------------------------------------- +# automatically build a list of object files for our project +#--------------------------------------------------------------------------------- +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.S))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#--------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#--------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) + export LD := $(CC) +else + export LD := $(CXX) +endif + +export OFILES := $(addsuffix .o,$(BINFILES)) \ + $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \ + $(sFILES:.s=.o) $(SFILES:.S=.o) + +#--------------------------------------------------------------------------------- +# build a list of include paths +#--------------------------------------------------------------------------------- +export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) \ + -I$(LIBOGC_INC) + +#--------------------------------------------------------------------------------- +# build a list of library paths +#--------------------------------------------------------------------------------- +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) \ + -L$(LIBOGC_LIB) + +export OUTPUT := $(CURDIR)/$(TARGET) +.PHONY: $(BUILD) clean + +#--------------------------------------------------------------------------------- +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#--------------------------------------------------------------------------------- clean: - @$(MAKE) --no-print-directory -C $(CURDIR_TMP)/stub \ - -f $(CURDIR_TMP)/stub/Makefile clean - @$(MAKE) --no-print-directory -C $(CURDIR_TMP) \ - -f $(CURDIR_TMP)/Makefile.loader clean - rm -rf $(CURDIR_TMP)/make_app/stub.bin - rm -rf $(CURDIR_TMP)/make_app/loader.bin - rm -rf $(CURDIR_TMP)/make_app/00000001.app + @echo clean ... + @rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).bin + +#--------------------------------------------------------------------------------- +else + +DEPENDS := $(OFILES:.o=.d) + +#--------------------------------------------------------------------------------- +# main targets +#--------------------------------------------------------------------------------- +$(OUTPUT).bin: $(OUTPUT).elf +$(OUTPUT).elf: $(OFILES) + +#--------------------------------------------------------------------------------- +%.bin: + $(OBJCOPY) -O binary $^ $@ + +%.elf: + @echo linking ... $(notdir $@) + $(LD) -T ../rvl.ld $^ $(LDFLAGS) $(LIBPATHS) $(LIBS) -o $@ + +-include $(DEPENDS) + +#--------------------------------------------------------------------------------- +endif +#--------------------------------------------------------------------------------- diff --git a/nand-loader/Makefile.loader b/nand-loader/Makefile.loader deleted file mode 100644 index a29008f..0000000 --- a/nand-loader/Makefile.loader +++ /dev/null @@ -1,54 +0,0 @@ -ifeq ($(strip $(DEVKITPPC)),) -$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=devkitPPC") -endif - -include $(DEVKITPPC)/wii_rules - -PREFIX = powerpc-eabi- - -AR = $(PREFIX)ar -AS = $(PREFIX)as -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -LD = $(PREFIX)ld -OBJCOPY = $(PREFIX)objcopy -RANLIB = $(PREFIX)ranlib -STRIP = $(PREFIX)strip - -MACHDEP = -mcpu=750 -mno-eabi -mhard-float -CFLAGS = $(MACHDEP) -O1 -Werror -Wall -pipe -ffunction-sections -finline-functions-called-once -mno-sdata -LDFLAGS = $(MACHDEP) -n -nostartfiles -nostdlib -Wl,-T,openstub.ld -L. -ASFLAGS = -D_LANGUAGE_ASSEMBLY -DHW_RVL - -TARGET_LINKED = boot.elf -TARGET = loader.bin - -CFILES = ios.c utils.c cache.c main.c -OBJS = app_booter.o crt0.o memory.o ios.o utils.o cache.o main.o - -DEPDIR = .deps - -all: $(TARGET) - -%.o: %.s - @echo " ASSEMBLE $<" - @$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@ - -%.o: %.S - @echo " ASSEMBLE $<" - @$(CC) $(CFLAGS) $(DEFINES) $(ASFLAGS) -c $< -o $@ - -%.o: %.c - @echo " COMPILE $<" - @$(CC) $(CFLAGS) $(DEFINES) -c $< -o $@ - -$(TARGET_LINKED): $(OBJS) - @echo " LINK $@" - @$(CC) -g -o $@ $(LDFLAGS) $(OBJS) $(LIBS) - -$(TARGET): $(TARGET_LINKED) - @echo " OBJCOPY $@" - @$(OBJCOPY) -O binary $< $@ - -clean: - rm -rf $(TARGET_LINKED) $(TARGET) $(OBJS) $(DEPDIR) diff --git a/nand-loader/README b/nand-loader/README index 49d023f..9dbb6dc 100644 --- a/nand-loader/README +++ b/nand-loader/README @@ -1,2 +1,29 @@ -This Project is based on megazigs stub, tinyload and dimoks app loader. -With this NAND Loader you can update existing forwarders to work in WiiU vWii Mode, just unpack your wad file, replace the app file with the one in the binary folder, repack the wad and its ready to use. \ No newline at end of file ++---------------------------------+ +| [+] Custom NAND Loader v1.0 | +| developed by Waninkoko | ++---------------------------------+ +| wwww.teknoconsolas.es | ++---------------------------------+ + + +[ DESCRIPTION ]: + +- This is a custom NAND Loader for Wii channels. It is 100% legal and works + with homebrew and commercial channels. + + Also, it allows to configure the loading options for each channel. + + +[ NOTES ]; + +- If RESET button is held while booting the channel it will access + the configuration menu. + + +[ KUDOS ]: + +- Team Twiizers and devkitPRO devs. +- crediar. +- WiiGator. +- kwiirk. +- All the betatesters. diff --git a/nand-loader/README.libogc b/nand-loader/README.libogc new file mode 100644 index 0000000..a2dfc2d --- /dev/null +++ b/nand-loader/README.libogc @@ -0,0 +1 @@ +properly building this NAND-Loader does (still) require libogc from 2009 diff --git a/nand-loader/README.tinyload b/nand-loader/README.tinyload deleted file mode 100644 index 734df4b..0000000 --- a/nand-loader/README.tinyload +++ /dev/null @@ -1,131 +0,0 @@ -TinyLoad v0.2 -A Wii disc game loader in 4096 bytes -==================================== - -What? -===== - -TinyLoad is a simple original Wii game launcher. You run it, it launches -whatever's inserted into the drive. Simple. It ignores game regions, so it's -region-free. It won't install updates. It won't load burned copies. There are no -controls or settings. - -The user interface shows two things: progress, and error status. A white bar -across the bottom of the screen shows the current (rough) progress. If an error -is detected, a portion of the top of the screen will turn red. It will then -attempt to launch The Homebrew Channel (only applies to recent versions with the -JODI Title ID). If this fails then it will simply hang. - -If the launcher freezes with the progress bar visible and no red error box, then -you've probably hit a bug. Try the debug version if you have a USB Gecko. - -If it freezes with a black screen after the progress bar has reached its -endpoint and disappeared, then the game itself is freezing. - -I obviously have only tested this with a few games. Chances are it doesn't work -with every Wii game out there. - -The debug version requires a USB Gecko and shows debug messages over it. - -Notes: -- TinyLoad sets the PPC timebase correctly according to your Wii's RTC. This - fixes date/time issues in games. -- The video code makes lots of assumptions. It will only work if VI was left - configured in a "standard" mode, with a 640x480-640x574 framebuffer. VI should - be blanked; if it isn't, then TinyLoad will not blank it before launching - the game so your screen will blink green for a split second as the game - initializes VI. It has been tested to work correctly when launched by the - Homebrew Channel in at least NTSC 480p and PAL interlaced modes. If these - assumptions don't hold then the progress bar display will not work properly, - but the rest of the loader should work fine. -- TinyLoad does not perform _any_ patching of games. The lowmem video mode - setting follows whatever video mode was left set by the application used to - launch TinyLoad, except that PAL games are forced to PAL if NTSC is detected. - This does not patch the game, it's merely the informative value in low memory; - games are free to read SYSCONF/setting.txt and ignore it. I don't really care - because I use 480p mode anyway. If you need more advanced options, just use - Gecko OS. -- Normally, game audio will not work correctly if launched via a loader that - was initially launched via BootMii-boot2. This is a bug in libogc (it doesn't - know how to initialize the DSP for the first time and leaves it in a broken - state), and it affects anything running after the Wii was booted first into - a libogc application, including the System Menu's loader. In other words, - BootMii-boot2 -> HBC -> System Menu (or Gecko OS) -> Game may cause distorted - audio. TinyLoad _does_ work, by resetting the audio hardware to let the game - reinitialize it properly. So, BootMii-boot2 -> HBC -> TinyLoad -> Game will - work fine. This ought to be worked around in a future release of HBC, at - least. I'd suggest fixing libogc, but I know shagkur is just going to rip the - proper code from the SDK again. Anyway, launching using TinyLoad will work - fine as it contains the workaround. -- TinyLoad will load the correct IOS as specified in the partition TMD. It does - not support loading any other IOS. -- TinyLoad will not install updates. Not having the right IOS for the game will - probably result in a red error and reset about halfway through. - -Broken stuff: -- I don't think online games work. Not sure why (I do copy the TitleID to the - proper spot, I think). If it works for you, let me know. Likewise, if you know - what the problem is or you can fix it, please let me know. - -Who? -==== - -Program: -Copyright 2008-2009 Hector Martin (marcan) - -Supporting code: -Copyright 2008-2009 Segher Boessenkool -Copyright 2008-2009 Andre Heider (dhewg) -Copyright 2008 Nuke - -Awesome icon: -Copyright 2009 Freddy Leitner (drmr) - -This code is licensed to you under the terms of the GNU GPL, version 2; -see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt - -The icon is licensed under CC-BY-NC-SA 3.0: -http://creativecommons.org/licenses/by-nc-sa/3.0/ - -Why? -==== - -Because: -- System Menu 4.2 forever broke region free via modchips -- I have a USA Wii which I regularly use with EUR games -- Gecko OS is somewhat annoying and recent versions are unstable (for me anyway) -- I refuse to perform retarded firmware mods. -- I autoboot HBC via BootMii-boot2 and using the System Menu takes longer - anyway. - -I also think that low-level apps that tightly hug the hardware are very -educational, so why not. And hey, the code is pretty short, so you ought to be -able to read it completely and learn how all this crazy Wii stuff *actually* -works :-) - -How? -==== - -TinyLoad is not compressed. The 4 kilobytes are raw code and data, plus the ELF -header. The original loader was fit in 4 kilobytes by avoiding bloated libraries -like libogc and instead using a small codebase pieced together from bits of the -Twilight Hack and of HBC's reload stub. Extra features (SYSCONF reading, RTC -reading, proper lowmem settings, VI stuff, progress bar, etc) were added by -making space via a combination of increasingly complex compiler options, manual -tweaks, and micro-optimization. - -Nonetheless, there is almost no assembly code and the C code, though compact and -odd at times, should be moderately readable. Just keep in mind that I -deliberately leave old values floating around and/or use odd initializations in -order to simplify the code. Also, I haven't commented most of it. If you're -really interested, give me a shout and I'll see what I can do to make it more -acceptable. - -If you want some *real* fun, load the ELF in IDA. The function inlining and tail -call goodness ought to provide tons of entertainment. - -Where? -====== - -http://wiibrew.org/TinyLoad -http://marcansoft.com/blog/ diff --git a/nand-loader/app_booter.s b/nand-loader/app_booter.s deleted file mode 100644 index 51e5066..0000000 --- a/nand-loader/app_booter.s +++ /dev/null @@ -1,62 +0,0 @@ -/* Generated by BIN2S - please don't edit directly */ - .section .rodata - .balign 4 - .global app_booter_bin_size - .global app_booter_bin -app_booter_bin: - .byte 124, 96, 0,166, 84, 99, 4, 94, 96, 99, 32, 0,124, 96, 1, 36 - .byte 76, 0, 1, 44, 60, 32,147, 1, 56, 33,131, 64, 56, 0, 0, 0 - .byte 148, 1,255,192, 60, 96,147, 0, 56, 99, 3, 32, 56,128, 0, 0 - .byte 60,160,147, 0, 56,165, 3, 32,124,163, 40, 80, 72, 0, 2,105 - .byte 72, 0, 1,212,148, 33,255,224,124, 8, 2,166,191,129, 0, 16 - .byte 124,125, 27,121,144, 1, 0, 36, 56, 96, 0, 0, 65,130, 0,152 - .byte 127,190,235,120,127,191,235,120, 59,128, 0, 0,128,191, 0,144 - .byte 47,133, 0, 0, 65,158, 0, 40,128,127, 0, 72, 43,131, 0,255 - .byte 64,189, 0, 28,128,159, 0, 0,124,157, 34, 20, 72, 0, 2, 57 - .byte 128,127, 0, 72,128,159, 0,144, 72, 0, 2, 81, 47,156, 0, 6 - .byte 59,255, 0, 4, 59,156, 0, 1, 64,158,255,196, 59,224, 0, 0 - .byte 128,190, 0,172, 47,133, 0, 0, 65,158, 0, 40,128,126, 0,100 - .byte 43,131, 0,255, 64,189, 0, 28,128,158, 0, 28,124,157, 34, 20 - .byte 72, 0, 1,245,128,126, 0,100,128,158, 0,172, 72, 0, 2, 13 - .byte 47,159, 0, 10, 59,222, 0, 4, 59,255, 0, 1, 64,158,255,196 - .byte 128,125, 0,224,128, 1, 0, 36,187,129, 0, 16, 56, 33, 0, 32 - .byte 124, 8, 3,166, 78,128, 0, 32,129, 35, 0, 0, 60, 0,127, 69 - .byte 96, 0, 76, 70,127,137, 0, 0, 57, 32, 0, 0, 64,190, 0, 36 - .byte 160, 3, 0, 16, 47,128, 0, 2, 64,158, 0, 20,160, 3, 0, 18 - .byte 57, 32, 0, 1, 47,128, 0, 20, 65,190, 0, 8, 57, 32,255,255 - .byte 125, 35, 75,120, 78,128, 0, 32,124, 8, 2,166,148, 33,255,224 - .byte 191,161, 0, 20,124,126, 27,120,144, 1, 0, 36,129, 35, 0, 28 - .byte 47,137, 0, 0, 65,158, 0,152,160, 3, 0, 44, 47,128, 0, 0 - .byte 65,158, 0,140,160, 3, 0, 42,127,227, 74, 20, 59,160, 0, 0 - .byte 47,128, 0, 32, 65,158, 0, 88, 72, 0, 0,116,128, 31, 0, 0 - .byte 47,128, 0, 1, 64,190, 0, 68,128,191, 0, 16,128, 31, 0, 20 - .byte 129, 63, 0, 12, 47, 5, 0, 0,127,133, 0, 64, 85, 41, 0,190 - .byte 101, 35,128, 0,144,127, 0, 12, 65,157, 0, 68, 65,186, 0, 28 - .byte 128,159, 0, 4,124,158, 34, 20, 72, 0, 0,253,128,127, 0, 12 - .byte 128,159, 0, 20, 72, 0, 1, 21, 59,255, 0, 32,160, 30, 0, 44 - .byte 127,157, 0, 0, 59,189, 0, 1, 65,156,255,164,128, 30, 0, 24 - .byte 84, 0, 0,190,100, 3,128, 0, 72, 0, 0, 8, 56, 96, 0, 0 - .byte 128, 1, 0, 36,187,161, 0, 20, 56, 33, 0, 32,124, 8, 3,166 - .byte 78,128, 0, 32,124, 8, 2,166,148, 33,255,224, 60, 96,145, 0 - .byte 191,161, 0, 20,144, 1, 0, 36, 75,255,254,225, 47,131, 0, 1 - .byte 64,190, 0, 16, 60, 96,145, 0, 75,255,255, 17, 72, 0, 0, 12 - .byte 60, 96,145, 0, 75,255,254, 1, 47,131, 0, 0,124,127, 27,120 - .byte 65,158, 0, 64, 61, 32,147, 32,129, 41, 0, 0,109, 32, 95, 97 - .byte 47,128,114,103, 64,158, 0, 36, 59,163, 0, 8, 60,128,147, 32 - .byte 127,163,235,120, 56,160, 0, 24, 72, 0, 0, 77,127,163,235,120 - .byte 56,128, 0, 24, 72, 0, 0,101,127,233, 3,166, 78,128, 4, 33 - .byte 128, 1, 0, 36,187,161, 0, 20, 56, 33, 0, 32,124, 8, 3,166 - .byte 78,128, 0, 32, 56,165, 0, 1, 57, 32, 0, 0,124,169, 3,166 - .byte 72, 0, 0, 12,124,137, 25,174, 57, 41, 0, 1, 66, 0,255,248 - .byte 78,128, 0, 32, 56,165, 0, 1, 57, 32, 0, 0,124,169, 3,166 - .byte 72, 0, 0, 16,124, 9, 32,174,124, 9, 25,174, 57, 41, 0, 1 - .byte 66, 0,255,244, 78,128, 0, 32, 56,132, 0, 31,124,132, 26, 20 - .byte 84, 99, 0, 52, 84,132, 0, 52, 72, 0, 0, 20,124, 0, 24,108 - .byte 124, 0, 4,172,124, 0, 31,172, 56, 99, 0, 32,127,131, 32, 64 - .byte 65,156,255,236,124, 0, 4,172, 76, 0, 1, 44, 78,128, 0, 32 - - .global app_booter_bin_end -app_booter_bin_end: - - .align -app_booter_bin_size: .int 800 diff --git a/nand-loader/binary/vWii_NAND_Loader_svn_r2.zip b/nand-loader/binary/vWii_NAND_Loader_svn_r2.zip deleted file mode 100644 index 4f5cc9943db4ea1468da76c0091a9b90d35216b6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2564 zcmZ{mcQ_jg7sex+QoDj$MXjQ(*&3-;E7z(~l$tT3My{Qt8wWjx0N005W))-cSScD?Ws_yqu< zhZ_K3J4+S+B_(-SP!RUM<3nLv{uA$T^YB7!efyAILP35iy5^00B6=YkZI>~CIB#dk0LnC4hQBm_`X|jB zt_C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}*BeNF|LWpcIKb z_X_K}qKc_X7p+{u&qn-?nyDB`>9MC|vmrBUCJIbi>IYuK<}k3)|2h6!gP%9p%F>*J zUFU^xO#TVb(v$(H1NeVLCV9qWe@pD2{lEE)<=-g-fFIB`>WhTpM;QLsElok^|9)jS NE0;6RK4U!q;2%6icj diff --git a/nand-loader/cache.c b/nand-loader/cache.c deleted file mode 100644 index 85689d8..0000000 --- a/nand-loader/cache.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -/* This code comes from the Twilight Hack */ -// Copyright 2008-2009 Segher Boessenkool -// Copyright 2008-2009 Hector Martin - -#include "types.h" - -void sync_before_read(void *p, u32 len) -{ - u32 a, b; - - a = (u32)p & ~0x1f; - b = ((u32)p + len + 0x1f) & ~0x1f; - - for ( ; a < b; a += 32) - asm("dcbi 0,%0" : : "b"(a) : "memory"); - - asm("sync ; isync"); -} - -void sync_after_write(const void *p, u32 len) -{ - u32 a, b; - - a = (u32)p & ~0x1f; - b = ((u32)p + len + 0x1f) & ~0x1f; - - for ( ; a < b; a += 32) - asm("dcbf 0,%0" : : "b"(a)); - - asm("sync ; isync"); -} - diff --git a/nand-loader/cache.h b/nand-loader/cache.h deleted file mode 100644 index 9c4c8e6..0000000 --- a/nand-loader/cache.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -/* This code comes from the Twilight Hack */ -// Copyright 2008-2009 Segher Boessenkool -// Copyright 2008-2009 Hector Martin - -#ifndef __CACHE_H__ -#define __CACHE_H__ - -#include "types.h" - -void sync_before_read(void *p, u32 len); -void sync_after_write(const void *p, u32 len); - -#endif - diff --git a/nand-loader/crt0.S b/nand-loader/crt0.S deleted file mode 100644 index 530b5c9..0000000 --- a/nand-loader/crt0.S +++ /dev/null @@ -1,163 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt - -# This code comes from the Twilight Hack -# Copyright 2008-2009 Segher Boessenkool - -# Slightly modified to imitate the homebrew channel stub - -*/ -.set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4; -.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9; -.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14; -.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19; -.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24; -.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29; -.set r30,30; .set r31,31; - -#include "hw.h" - -.extern _main -#TODO - fixup memset - .globl _start -_start: - bl __init_registers - bl __init_memory - bl __init_syscall - bl __init_sprs - lis r3,__bss_start@h - ori r3,r3,__bss_start@l - li r4,0 - lis r5,__bss_end@h - ori r5,r5,__bss_end@l - subf r5,r3,r5 - bl _memset - lis r3,__stack_end@h - ori r3,r3,__stack_end@l - li r4,0 - lis r5,__stack_top@h - ori r5,r5,__stack_top@l - subf r5,r3,r5 - bl _memset - bl _main -0: - b 0b - -__init_registers: - li r0,0 - li r3,0 - li r4,0 - li r5,0 - li r6,0 - li r7,0 - li r8,0 - li r9,0 - li r10,0 - li r11,0 - li r12,0 - li r14,0 - li r15,0 - li r16,0 - li r17,0 - li r18,0 - li r19,0 - li r20,0 - li r21,0 - li r22,0 - li r23,0 - li r24,0 - li r25,0 - li r26,0 - li r27,0 - li r28,0 - li r29,0 - li r30,0 - li r31,0 - lis r1,__stack_top@h - ori r1,r1,__stack_top@l - addi r1,r1,-4 - stw r0,0(r1) - stwu r1,-0x38(r1) - lis r2,0 - ori r2,r2,0x8000 - lis r13,0 - ori r13,r13,0x8000 - blr - -_memset: - clrlwi. r6,r5,29 - rlwinm r5,r5,30,2,31 - addi r3,r3,-4 - mtctr r5 -0: - stwu r4,4(r3) - bdnz+ 0b - cmplwi r6,0 - beq- 2f -1: - stbu r4,1(r3) - addic. r6,r6,-1 - bne+ 1b -2: - blr - -__init_memory: - mflr r0 - stw r0, 0x04(r1) - stwu r1,-0x10(r1) - stw r31,0x0C(r1) - mfspr r3,rHID0 - rlwinm r0,r3,0,16,16 #HID0[ICE] - cmplwi r0,0 - bne- 0f - bl ICacheEnable -0: - mfspr r3,rHID0 - rlwinm r0,r3,0,17,17 #HID0[DCE] - cmplwi r0,0 - bne- 1f - bl DCacheEnable -1: - mfl2cr r3 - rlwinm r0,r3,0,0,0 #L2CR[L2E] - cmplwi r0,0 - bne- 2f - bl L2_Init - bl L2_Enable -2: - lwz r0, 0x14(r1) - lwz r31,0x0C(r1) - addi r1,r1,0x10 - mtlr r0 - blr - -__init_sprs: - mflr r0 - stw r0, 0x04(r1) - stwu r1,-0x18(r1) - stw r31,0x14(r1) - stw r30,0x10(r1) - stw r29,0x0C(r1) - li r3,0 - mtmmcr0 r3 - mtmmcr1 r3 - mtpmc1 r3 - mtpmc2 r3 - mtpmc3 r3 - mtpmc4 r3 - mfspr r3,rHID0 - ori r3,r3,HID0_SPD #HID0[SPD] - mtspr rHID0,r3 - mfspr r3,rHID2 - rlwinm r3,r3,0,2,0 #HID2[WPE] - mtspr rHID2,r3 - lwz r0, 0x1C(r1) - lwz r31,0x14(r1) - lwz r30,0x10(r1) - lwz r29,0x0C(r1) - addi r1,r1,0x18 - mtlr r0 - blr diff --git a/nand-loader/data/background b/nand-loader/data/background new file mode 100644 index 0000000000000000000000000000000000000000..7714c7376debe38eb027b8e9ebe9e0891b888e34 GIT binary patch literal 41921 zcmeFYcTiJr*Dj2xpeTY0(nOTr5s==L5_${0Myb-JNezgKC{?<&078HeAX1eUu+W0^ zDqSFy&;uc~z}fuX@60>%%sk(FzVps^{yM{CX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X!}~N;Xmnl zor@)qIW-~<^PGDg1!C3A9z=i(FY~;~PXRT22D-;T5y+alp#D2e};I z6guqzvOSyP7MM4+?bXxY#`9)n!vD(aBlY6)#mHwYa!-65UJiV{0xkV2^w3yd#tAf7 znie$ruhsM5ydaNlh;Z8mDz8U>-VbiaEUX<5j{5vI!TeE_;4TXYL_KGCQ|n$i^-Q!B z1j6`=1pE1dTzwF?*WY135yo(WVx*3ZZ{==RuzTP=v1yZR$=)w18h0b}s?mK%GOS@e zsC(>NreOwY8sN>y;3STPR8nCR_I&8NbJ6g`MBtg-oh{o{EcY9eI^R~-6K@gBAH^{e zE&+kPN&kh4iA!gIKuZVvO4%~XObb(3IC7lLIqm$sl9)f<-dp7nlwkI@)1Wfl^i{E> zs*@`8!iTkogb3XSBZWohM-VAM@~N~16{Y~EF4sd(h)4>gk%&hn6pFG)hvm8jeHqjO1+ z0Yojl#LG73Aby5vSuUHMf@C7F)0)zEMX!I+0f&di`x9eLJYl=NSE%Dl2C<7-9UCUMC!bqpVO6mK?9;Ou<)Y;sTjZ`mXiuOTumSn(;=dKwj9 zOPf)AdYI2)8~*ROU4ok$TFZ?xU&k0vJ5CdHbO+DxyCO}La%=FuJ3~FN=1^yHZ)+A# zPJ2ec~G!Di0Th4|-)5P3`&2Yv3Tu;iN$~kc7Uj7xm*$&WGS@;1Jh^BWm y4Nkk!`+hP)1Y|?}RB0>I6jXi)-6k8aozc_$bD8C{KFJCMJcha^H!HOrWBvyzcU9Z~ literal 0 HcmV?d00001 diff --git a/nand-loader/data/error b/nand-loader/data/error new file mode 100644 index 0000000000000000000000000000000000000000..15c1075635ae289bc882411d998613b0dcfe35b8 GIT binary patch literal 5888 zcmb7IbyOT*lLdkkAh-<@B!mgBg9j2I1ShyV!S#nruq1eJ3l0MW2<{TxEx5}tK+wS% zWSE_N-`Q{f+p~N6biLPAr@LRhuD-XbfCBRA^|F zhKg@xw0xG2vweNEcCH4cVXMPdU&1**zkSNohwp}XE}mJ04~!y?N(OR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H(PaK)xi;NI zvu8N){(L!(ejJABBKx6jg96nl#w3zbN?(zO@pL3RoU}%Ne+W2fJ>u_NYpyYF`rv5P zQY(kP)ap#HSXOql+M4otd0CZ_Il_6*E@66Fb2=Fkm%y^(I6IY@#K}m-wlsW6%L8*BC6PMVz$-2CojL#2s+8oh^?iMPR-J*PBfOTZ`DBSn!^4xdu!(Fz1_@lus7-gj>%POYw}IR( z4!YBIbxT*{B9+&CscVJZFcTm2Q9<9$yF-#qlwc&9C)Ce(LWDF)Y|mF`^DL>OsR4Z= zpXs}r{V;or(96isQ0hus@D$kw-6`x{>WI}GXZx2mtL;+B- z?4p+x&muQxV1k?KQ4Fu=Lb2cvw^&o5R~sI0;wwiqUBk>P)>D4!5KBT%$pSZ`e)3f}%4()>eevrXj)&)N zcv83A4=1N3DxhO#fd`QdHzQM z#r=;A`d1wNk3#y_`+p9(CS&cQYI^4*N;XyX|EJ4KFqRV%a-e+q5OG5=qLZ-Px@FG##EIaoxNtzb{Y9{Od&CXut z*;_MAnP(v=7585TQ~nty3AN0>&EL?Urw`IXAu$OrrX2w&EgDTxPWA0iS+mgp0==z| A_W%F@ literal 0 HcmV?d00001 diff --git a/nand-loader/data/loading b/nand-loader/data/loading new file mode 100644 index 0000000000000000000000000000000000000000..5410cc77e173b30aff960f0367c73daf2dc39d48 GIT binary patch literal 5774 zcmb_=WmH?uw|*$@1&Ui8C>Ep?LTM-vq!cgiq&R`#ZUqX(3n}hW#T^1K4sW5526szS zBm^xG{HDMEm;YLKt$V-R4`-hxbEjh*C5N{;j`f5sms!^UzVuQj?Q%wc11YiTO-8;QGLF}Q1tDAZQ0JJQBFA_jb z-rof%eKfQnl(Xby%yi-(i_e6KU7S7;6CY&{7|hc zNCtKQfOS(t<@u|CIs9U9z^$W>!Tl2thvN)djoW>I7pe11B;<{8G^t)BWq!j08qs~fo=e|w!O=h4H)g6+1(Wwzk zO6pxyccRG>Zz|nTr9zXKz(h@Sb#FI5h_?B&frg2FbL!1**IG^cf|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E0@edVQb^N#jwtyRgOKO0bXVC-As)V`@HxW=RZ pu$htx_x~Gj`v0?*Dr$SzXV*{4OTva4h|DlR1EQ@`rDXHwzW}<0L8AZw literal 0 HcmV?d00001 diff --git a/nand-loader/hw.h b/nand-loader/hw.h deleted file mode 100644 index f4486ba..0000000 --- a/nand-loader/hw.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef __HW_H__ -#define __HW_H__ - -#define MSR_POW (1<<18) -#define MSR_ILE (1<<16) -#define MSR_EE (1<<15) -#define MSR_PR (1<<14) -#define MSR_FP (1<<13) -#define MSR_ME (1<<12) -#define MSR_FE0 (1<<11) -#define MSR_SE (1<<10) -#define MSR_BE (1<< 9) -#define MSR_FE1 (1<< 8) -#define MSR_IP (1<< 6) -#define MSR_IR (1<< 5) -#define MSR_DR (1<< 4) -#define MSR_RI (1<< 1) -#define MSR_LE (1<< 0) - -#define HID0_EMCP (1<<31) -#define HID0_DBP (1<<30) -#define HID0_EBA (1<<29) -#define HID0_EBD (1<<28) -#define HID0_BCLK (1<<27) -#define HID0_ECLK (1<<25) -#define HID0_PAR (1<<24) -#define HID0_DOZE (1<<23) -#define HID0_NAP (1<<22) -#define HID0_SLEEP (1<<21) -#define HID0_DPM (1<<20) -#define HID0_NHR (1<<16) -#define HID0_ICE (1<<15) -#define HID0_DCE (1<<14) -#define HID0_ILOCK (1<<13) -#define HID0_DLOCK (1<<12) -#define HID0_ICFI (1<<11) -#define HID0_DCFI (1<<10) -#define HID0_SPD (1<< 9) -#define HID0_IFEM (1<< 8) -#define HID0_SGE (1<< 7) -#define HID0_DCFA (1<< 6) -#define HID0_BTIC (1<< 5) -#define HID0_ABE (1<< 3) -#define HID0_BHT (1<< 2) -#define HID0_NOOPTI (1<< 0) - -#define HID2_LSQE (1<<31) -#define HID2_WPE (1<<30) -#define HID2_PSE (1<<29) -#define HID2_LCE (1<<28) - -#define L2CR_L2E (1<<31) -#define L2CR_L2CE (1<<30) -#define L2CR_L2DO (1<<22) -#define L2CR_L2I (1<<21) -#define L2CR_L2WT (1<<19) -#define L2CR_L2TS (1<<18) -#define L2CR_L2IP (1<< 0) - -#define DMAU_MEM_ADDR_MASK 0xFFFFFFE0 -#define DMAU_LENU(x) (x & 0x1F) -#define DMAL_LC_ADDR_MASK 0xFFFFFFE0 -#define DMAL_LD (1<< 4) -#define DMAL_LENL(x) (x & 0xC) -#define DMAL_T (1<< 1) -#define DMAL_F (1<< 0) - -#define BATU_BEPI_MASK 0xFFFC0000 -#define BATU_BL(x) (x & 0x00001FFC) -#define BATU_VS (1<< 1) -#define BATU_VP (1<< 0) -#define BATL_BRPN_MASK 0xFFFC0000 -#define BATL_WIMG_MASK 0x78 -#define BATL_PP (1<< 0) - -// BATU - 0x80001FFF == 256Mbytes -// 1000 0000 000x xxx0 0001 1111 1111 11xx -// 0x80000000|256Mbytes|VS|VP -// BATL - 0x00000002 -// 0000 0000 0000 000x xxxx xxxx x000 0x10 -// PP=b10 -// -// BATU - 0xC0001FFF == 256Mbytes -// BATL - 0x0000002a -// 0000 0000 0000 000x xxxx xxxx x010 1x10 -// WIMG=b0101|PP=b10 -// - -#define rHID2 920 -#define rDMAU 922 -#define rDMAL 923 -#define rHID0 1008 -#define rHID1 1009 -#define rHID4 1011 - -/* - * Upper PTE - * 0|1-24|25|26-31 - * V|VSID|H |API - * - * Lower PTE - * 0-19|20-22|23|24|25-28|29|30-31 - * RPN |000 |R |C |WIMG |0 |PP -*/ - -#endif - diff --git a/nand-loader/ios.c b/nand-loader/ios.c deleted file mode 100644 index 76f8456..0000000 --- a/nand-loader/ios.c +++ /dev/null @@ -1,286 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -/* This code comes from HBC's stub which was based on the Twilight Hack code */ -// Copyright 2008-2009 Segher Boessenkool -// Copyright 2008-2009 Andre Heider -// Copyright 2008-2009 Hector Martin - -#include "ios.h" -#include "cache.h" -#include "utils.h" - -#define virt_to_phys(x) ((u32*)(((u32)(x))&0x3FFFFFFF)) -#define phys_to_virt(x) ((u32*)(((u32)(x))|0x80000000)) - -// Low-level IPC access. - -static inline u32 -iread32(u32 addr) -{ - u32 x; - - asm volatile("lwz %0,0(%1) ; sync ; isync" : "=r"(x) : "b"(0xc0000000 | addr)); - - return x; -} - -static inline void -iwrite32(u32 addr, u32 x) -{ - asm volatile("stw %0,0(%1) ; eieio" : : "r"(x), "b"(0xc0000000 | addr)); -} - -static u32 _ipc_read(u32 reg) __attribute__((noinline)); -static void _ipc_write(u32 reg, u32 value) __attribute__((noinline)); -static void ipc_bell(u32 w) __attribute__((noinline)); - -// inline the 4*, don't inline the 0x0d0 stuff. yes, this saves a few bytes. -static u32 -_ipc_read(u32 reg) -{ - return iread32(0x0d000000 + reg); -} - -static void -_ipc_write(u32 reg, u32 value) -{ - iwrite32(0x0d000000 + reg, value); -} - -static inline u32 -ipc_read(u32 reg) -{ - return _ipc_read(4*reg); -} - -static inline void -ipc_write(u32 reg, u32 value) -{ - _ipc_write(4*reg, value); -} - -static void -ipc_bell(u32 w) -{ - ipc_write(1, w); -} - -static void ios_delay(void) __attribute__((noinline)); - -static void -ios_delay(void) -{ - usleep(500); -} - -static void -ipc_wait_ack(void) -{ - while(!(ipc_read(1) & 0x2)) - ; - ios_delay(); -} - -static void -ipc_wait_reply(void) -{ - while(!(ipc_read(1) & 0x4)) - ; - ios_delay(); -} - -static u32 -ipc_wait(void) -{ - u32 ret; - while(!((ret = ipc_read(1)) & 0x6)) - ; - ios_delay(); - return ret; -} - -// Mid-level IPC access. - -struct ipc { - u32 cmd; - int result; - int fd; - u32 arg[5]; - - u32 user[8]; -}; - -static struct ipc ipc ALIGNED(64); - -static void -ipc_send_request(void) -{ - sync_after_write(&ipc, 0x40); - - ipc_write(0, (u32)virt_to_phys(&ipc)); - ipc_bell(1); - - ipc_wait_ack(); - - ipc_bell(2); -} - -static int -ipc_send_twoack(void) -{ - sync_after_write(&ipc, 0x40); - ios_delay(); - - ipc_write(0, (u32)virt_to_phys(&ipc)); - ipc_bell(1); - - if(ipc_wait() & 4) - return 0; - - ipc_bell(2); - - if(ipc_wait() & 4) - return 0; - - ipc_bell(2); - ipc_bell(8); - return 1; -} - -static void -ipc_recv_reply(void) -{ - for (;;) - { - u32 reply; - - ipc_wait_reply(); - - reply = ipc_read(2); - ipc_bell(4); - - ipc_bell(8); - - if (((u32*)reply) == virt_to_phys(&ipc)) - break; - } - - sync_before_read(&ipc, 0x40); -} - - -// High-level IPC access. - -int -ios_open(const char *filename, u32 mode) -{ - sync_after_write((void*)filename, 0x20); - - ipc.cmd = 1; - ipc.fd = 0; - ipc.arg[0] = (u32)virt_to_phys(filename); - ipc.arg[1] = mode; - - ipc_send_request(); - ipc_recv_reply(); - - return ipc.result; -} - -int -ios_close(int fd) -{ - ipc.cmd = 2; - ipc.fd = fd; - - ipc_send_request(); - ipc_recv_reply(); - - return ipc.result; -} - -static void -ios_std(int fd, int cmd) -{ - ipc.cmd = cmd; - ipc.fd = fd; - - ipc_send_request(); - ipc_recv_reply(); -} - -int -ios_read(int fd, void *buf, u32 size) -{ - ipc.arg[0] = (u32)virt_to_phys(buf); - ipc.arg[1] = size; - - ios_std(fd, 3); - - sync_before_read(buf, size); - - return ipc.result; -} - -int -_ios_ioctlv(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec, int reboot) -{ - u32 i; - - for (i = 0; i < in_count + out_count; i++) - { - if (vec[i].data) - { - sync_after_write(vec[i].data, vec[i].len); - vec[i].data = (void *)virt_to_phys(vec[i].data); - } - } - - sync_after_write(vec, (in_count + out_count) * sizeof *vec); - - ipc.cmd = 7; - ipc.fd = fd; - ipc.arg[0] = n; - ipc.arg[1] = in_count; - ipc.arg[2] = out_count; - ipc.arg[3] = (u32)virt_to_phys(vec); - - if(reboot) - { - if(ipc_send_twoack()) - return 0; - } - else - ipc_send_request(); - ipc_recv_reply(); - - for(i = in_count; i < in_count + out_count; i++) - { - if (vec[i].data) - { - vec[i].data = phys_to_virt((u32)vec[i].data); - sync_before_read(vec[i].data, vec[i].len); - } - } - if(reboot && (ipc.result >= 0)) - return -100; - return ipc.result; -} - -int -ios_ioctlv(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec) -{ - return _ios_ioctlv(fd, n, in_count, out_count, vec, 0); -} - -int -ios_ioctlvreboot(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec) -{ - return _ios_ioctlv(fd, n, in_count, out_count, vec, 1); -} - diff --git a/nand-loader/ios.h b/nand-loader/ios.h deleted file mode 100644 index 9aab418..0000000 --- a/nand-loader/ios.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -#ifndef __IOS_H__ -#define __IOS_H__ - -// Copyright 2008-2009 Hector Martin - -#include "types.h" - -struct ioctlv { - void *data; - u32 len; -}; - -int ios_open(const char *filename, u32 mode); -int ios_close(int fd); -int ios_ioctlv(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec); -int ios_ioctlvreboot(int fd, u32 n, u32 in_count, u32 out_count, struct ioctlv *vec); -int ios_read(int fd, void *buf, u32 size); - -#endif - diff --git a/nand-loader/main.c b/nand-loader/main.c deleted file mode 100644 index 9fda6be..0000000 --- a/nand-loader/main.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -/* This code comes from HBC's stub which was based on dhewg's geckoloader stub */ -// Copyright 2008-2009 Andre Heider -// Copyright 2008-2009 Hector Martin - -#include "utils.h" -#include "ios.h" -#include "cache.h" -#include "memory.h" - -#define IOCTL_ES_LAUNCH 0x08 -#define IOCTL_ES_OPENCONTENT 0x09 -#define IOCTL_ES_READCONTENT 0x0A -#define IOCTL_ES_CLOSECONTENT 0x0B -#define IOCTL_ES_GETVIEWCNT 0x12 -#define IOCTL_ES_GETVIEWS 0x13 -#define IOCTL_ES_GETTITLEID 0x20 -#define IOCTL_ES_SEEKCONTENT 0x23 - -#define TITLE_ID(x,y) (((u64)(x) << 32) | (y)) - -extern const u8 app_booter_bin[]; -extern const u32 app_booter_bin_size; - -static struct ioctlv vecs[16] ALIGNED(64); -s32 cfd ALIGNED(32); -int es_fd = -1; - -typedef void (*entry)(void); - -static int es_init(void) -{ - es_fd = ios_open("/dev/es", 0); - return es_fd; -} - -static void es_close(void) -{ - if(es_fd >= 0) - ios_close(es_fd); - es_fd = -1; -} - -static int es_launchtitle(u64 titleID) -{ - static u64 xtitleID __attribute__((aligned(32))); - static u32 cntviews __attribute__((aligned(32))); - static u8 tikviews[0xd8*4] __attribute__((aligned(32))); - - xtitleID = titleID; - vecs[0].data = &xtitleID; - vecs[0].len = 8; - vecs[1].data = &cntviews; - vecs[1].len = 4; - int ret = ios_ioctlv(es_fd, IOCTL_ES_GETVIEWCNT, 1, 1, vecs); - if(ret<0) return ret; - if(cntviews>4) return -1; - - vecs[2].data = tikviews; - vecs[2].len = 0xd8*cntviews; - ret = ios_ioctlv(es_fd, IOCTL_ES_GETVIEWS, 2, 1, vecs); - if(ret<0) return ret; - vecs[1].data = tikviews; - vecs[1].len = 0xd8; - ret = ios_ioctlvreboot(es_fd, IOCTL_ES_LAUNCH, 2, 0, vecs); - return ret; -} - -static int es_opencontent(u32 content_num) -{ - vecs[0].data = &content_num; - vecs[0].len = 4; - cfd = ios_ioctlv(es_fd, IOCTL_ES_OPENCONTENT, 1, 0, vecs); - return cfd; -} - -static int es_seekcontent(s32 place, s32 from) -{ - vecs[0].data = &cfd; - vecs[0].len = 4; - vecs[1].data = &place; - vecs[1].len = 4; - vecs[2].data = &from; - vecs[2].len = 4; - return ios_ioctlv(es_fd, IOCTL_ES_SEEKCONTENT, 3, 0, vecs); -} - -static int es_readcontent(void *data, u32 size) -{ - vecs[0].data = &cfd; - vecs[0].len = 4; - vecs[1].data = data; - vecs[1].len = size; - return ios_ioctlv(es_fd, IOCTL_ES_READCONTENT, 1, 1, vecs); -} - -static int es_closecontent() -{ - vecs[0].data = &cfd; - vecs[0].len = 4; - return ios_ioctlv(es_fd, IOCTL_ES_CLOSECONTENT, 1, 0, vecs); -} - -void memoryset(u8 *dst, const u8 value, u32 size) -{ - u32 i; - for(i = 0; i < size; ++i) - dst[i] = value; -} - -void memorycopy(u8 *dst, const u8 *src, u32 size) -{ - u32 i; - for(i = 0; i < size; ++i) - dst[i] = src[i]; -} - -static void *dol_data = (void*)0x91000000; /* 32MB Max */ -static void *appbooter_entry = (void*)0x93000000; - -void _main(void) -{ - u32 size = 0; - es_init(); - /* load up dol */ - es_opencontent(2); //stub is 1, real dol is 2 - if(cfd < 0) goto fail; - size = es_seekcontent(0, 2); - es_seekcontent(0, 0); - es_readcontent(dol_data, size); - sync_after_write(dol_data, size); - es_closecontent(); - if(size == 0) goto fail; - es_close(); - /* Boot our good old appbooter stuff */ - memorycopy(appbooter_entry, app_booter_bin, app_booter_bin_size); - sync_after_write(appbooter_entry, app_booter_bin_size); - entry EntryPoint = (entry)appbooter_entry; - EntryPoint(); - -fail: - es_launchtitle(TITLE_ID(1,2)); - while(1) usleep(500); -} - -#define SYSCALL_VECTOR ((u8*)0x80000C00) -void __init_syscall() -{ - u8* sc_vector = SYSCALL_VECTOR; - u32 bytes = (u32)DCFlashInvalidate - (u32)__temp_abe; - u8* from = (u8*)__temp_abe; - for ( ; bytes != 0 ; --bytes ) - { - *sc_vector = *from; - sc_vector++; - from++; - } - - sync_after_write(SYSCALL_VECTOR, 0x100); - ICInvalidateRange(SYSCALL_VECTOR, 0x100); -} diff --git a/nand-loader/make_app/main.cpp b/nand-loader/make_app/main.cpp deleted file mode 100644 index 8d9e513..0000000 --- a/nand-loader/make_app/main.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2012 FIX94 - * - * 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 . - ****************************************************************************/ -#include -#include -#include -#include -#include -#include -#include - -unsigned char dol_header[0x100]; -#define ALIGN32(x) (((x) + 31) & ~31) - -int main() -{ - char nullBuf[1]; - nullBuf[0] = 0x00; - memset(&dol_header, 0, 0x100); - /* Read in shit */ - FILE *f = fopen("loader.bin", "rb"); - if(f == NULL) - { - printf("no loader\n"); - return -1; - } - fseek(f, 0, SEEK_END); - unsigned int size = ftell(f); - rewind(f); - unsigned char *buf = (unsigned char*)malloc(size); - fread(buf, size, 1, f); - fclose(f); - f = fopen("stub.bin", "rb"); - if(f == NULL) - { - printf("no stub\n"); - free(buf); - return -2; - } - fseek(f, 0, SEEK_END); - unsigned int stub_size = ftell(f); - rewind(f); - unsigned char *stub_buf = (unsigned char*)malloc(stub_size); - fread(stub_buf, stub_size, 1, f); - fclose(f); - /* Add stub text */ - ((unsigned int*)dol_header)[0] = _bswap(0x100); /* Header size */ - ((unsigned int*)dol_header)[18] = _bswap(0x80003400); - ((unsigned int*)dol_header)[36] = _bswap(ALIGN32(stub_size)); - /* Add NAND Loader text */ - ((unsigned int*)dol_header)[1] = _bswap(0x100 + ALIGN32(stub_size)); - ((unsigned int*)dol_header)[19] = _bswap(0x80004000); - ((unsigned int*)dol_header)[37] = _bswap(ALIGN32(size)); - /* Set our entry to the NAND Loader */ - ((unsigned int*)dol_header)[56] = _bswap(0x80004000); - /* Write it to a new file */ - f = fopen("00000001.app", "wb"); - fwrite(dol_header, 0x100, 1, f); /* Write header first */ - - fwrite(stub_buf, stub_size, 1, f); /* Then stub */ - if(ALIGN32(stub_size) > stub_size) - { - for(int i = 0; i < (ALIGN32(stub_size) - stub_size); ++i) - fwrite(nullBuf, 1, 1, f); - } - - fwrite(buf, size, 1, f); /* and last nand loader */ - if(ALIGN32(size) > size) - { - for(int i = 0; i < (ALIGN32(size) - size); ++i) - fwrite(nullBuf, 1, 1, f); - } - - fclose(f); - free(buf); - free(stub_buf); - printf("done\n"); - return 0; -} diff --git a/nand-loader/make_app/make_app.exe b/nand-loader/make_app/make_app.exe deleted file mode 100644 index ca97b085edc01f9d0fcb62d5f7639feed2b7d24a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 51414 zcmeIb3w)Kuoi{$udCobUTz~)pq5>WzD&9hXh*+T}Bmsf}ViFLP_HdG%km$+9bKzpG zq5&n1wqaMTuj>V?wr_GN}6Ca%* z9?tv0Nsk!yKRBtmqca`tP4#R}#k-=d@$T-POtd8tO=Y{Io!!xzHBHg3p0-5U`0@Fr znsh_05cS4naYOGb4FUw$K$t^foKau|rivmUMd1TNBqt-Z(v*&Iz$v!@&rrGsq{2e1 zSY^n1Ndm-W0U6qX!rvrBuU%MyKGfeGLX_kv@YW_F_U3?Fpt4M2TLy_2C*Tj|qKDjW zw@H+5Dr<{p;s8p~qllo+Vj8^5Rf_U`WhsT&Ol6eA6K{lIz^j~Fp$Z;mPzg`GliwOCiOo-zoUM4B| zMhV^lPrOoimm}WXd8#6Z2p@ze-lVuj6g3-=gylarJ2Zfi{cOULVdfOq&IKA6!71lwspu8Vs?_wZ_TzaWAEo|UG_bb+wWhu|EAF|kyi)AimznWwO(`u0#R%Ww3Z;$ zNY+g88TvNL^c@&}<2-MkWO1j?o9WGynz$BuyMC6ec<<$CGJuSUr74lMX0Fg=BYF4TnH08q(7LP~~%`)}GJ9=VOQeoYz| zuWLdN=zFtr=#S`G&(xG&ARdiE=x=jscu4gBiQKpk2(=I}ifLJB>BK`<0V)%_A5GMVR@~vih$RxvO7^^3w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@TrUa6eVcakQCh z)Nx6*yn3UodmK*o#L*=3tKMpyr;%??_OwuM_C&7wsC>$E%q*L?CxOMSN9kOR>al+0JS+*1 zI<1b{%Z@&nW7KxEVo&k*!kE)gjHcIuITRIQU(2TP5k_mwz$dch&PQxytw-rr*0`Z| G`~EkE4Q2QM diff --git a/nand-loader/memory.S b/nand-loader/memory.S deleted file mode 100644 index 1cb1c91..0000000 --- a/nand-loader/memory.S +++ /dev/null @@ -1,192 +0,0 @@ -.set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4; -.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9; -.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14; -.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19; -.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24; -.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29; -.set r30,30; .set r31,31; - -#include "hw.h" - -.global __temp_abe -__temp_abe: - mfspr r3,rHID0 - ori r4,r3,HID0_ABE #HID0[ABE] - mtspr rHID0,r4 - isync - sync - mtspr rHID0,r3 - rfi - -.global DCFlashInvalidate -DCFlashInvalidate: - nop - mfspr r3,rHID0 - ori r3,r3,HID0_DCFI #HID0[DCFI] - mtspr rHID0,r3 - blr - -.global DCacheEnable -DCacheEnable: - sync - mfspr r3,rHID0 - ori r3,r3,HID0_DCE #HID0[DCE] - mtspr rHID0,r3 - blr - -.global DCBlockInvalidate -DCBlockInvalidate: - cmplwi r4,0 - blelr - clrlwi. r5,r3,27 - beq- 0f - addi r4,r4,0x20 -0: - addi r4,r4,0x1F - rlwinm r4,r4,27,5,31 - mtctr r4 -1: - dcbi r0,r3 - addi r3,r3,0x20 - bdnz+ 1b - blr - -DCBlockFlushSc: - cmplwi r4,0 - blelr - clrlwi. r5,r3,27 - beq- 0f - addi r4,r4,0x20 -0: - addi r4,r4,0x1F - rlwinm r4,r4,27,5,31 - mtctr r4 -1: - dcbf r0,r3 - addi r3,r3,0x20 - bdnz+ 1b - sc - blr - -DCBlockFlush: - cmplwi r4,0 - blelr - clrlwi. r5,r3,27 - beq- 0f - addi r4,r4,0x20 -0: - addi r4,r4,0x1F - rlwinm r4,r4,27,5,31 - mtctr r4 -1: - dcbf r0,r3 - addi r3,r3,0x20 - bdnz+ 1b - blr - -.global ICInvalidateRange -ICInvalidateRange: - cmplwi r4,0 - blelr - clrlwi. r5,r3,27 - beq- 0f - addi r4,r4,0x20 -0: - addi r4,r4,0x1F - rlwinm r4,r4,27,5,31 - mtctr r4 -1: - icbi r0,r3 - addi r3,r3,0x20 - bdnz+ 1b - sync - isync - blr - -ICFlashInvalidate: - mfspr r3,rHID0 - ori r3,r3,HID0_ICFI #HID0[ICFI] - mtspr rHID0,r3 - blr - -.global ICacheEnable -ICacheEnable: - isync - mfspr r3,rHID0 - ori r3,r3,HID0_ICE #HID0[ICE] - mtspr rHID0,r3 - blr - -ICacheDisable: - isync - mfspr r3,rHID0 - rlwinm r3,r3,0,17,15 #HID0[ICE] - mtspr rHID0,r3 - blr - -ISync: - isync - blr - -.global L2_Init -L2_Init: - mflr r0 - stw r0, 0x04(r1) - stwu r1,-0x10(r1) - stw r31,0x0C(r1) - mfmsr r3 - mr r31,r3 - sync - li r3,MSR_IR|MSR_DR #MSR[IR|DR] - mtmsr r3 - sync - bl L2_Disable - bl L2_Invalidate - mr r3,r31 - mtmsr r3 - lwz r0, 0x14(r1) - lwz r31,0x0C(r1) - mtlr r0 - blr - -.global L2_Enable -L2_Enable: - mfl2cr r3 - oris r0,r3,0x8000 #L2CR[L2E] - rlwinm r3,r0,0,11,9 #L2CR[L2I] - mtl2cr r3 - blr - -L2_Disable: - sync - mfl2cr r3 - clrlwi r3,r3,1 #L2CR[L2E] - mtl2cr r3 - sync - blr - -L2_Invalidate: - mflr r0 - stw r0, 0x04(r1) - stwu r1,-0x08(r1) - bl L2_Disable - mfl2cr r3 - oris r3,r3,0x200 #L2CR[L2I] - mtl2cr r3 -0: - mfl2cr r3 - clrlwi r0,r3,31 #L2CR[L2IP] - cmplwi r0,0 - bne+ 0b - mfl2cr r3 - rlwinm r3,r3,0,11,9 #L2CR[L2I] - mtl2cr r3 -1: - mfl2cr r3 - clrlwi r0,r3,31 #L2CR[L2IP] - cmplwi r0,0 - bne+ 1b - lwz r0,0x0C(r1) - addi r1,r1,0x08 - mtlr r0 - blr diff --git a/nand-loader/memory.h b/nand-loader/memory.h deleted file mode 100644 index 03c514d..0000000 --- a/nand-loader/memory.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __MEMORY_H__ -#define __MEMORY_H__ - -void __temp_abe(void); -void ICInvalidateRange(void *, int); -void DCFlashInvalidate(void *, int); - -#endif - diff --git a/nand-loader/openstub.ld b/nand-loader/openstub.ld deleted file mode 100644 index 8991605..0000000 --- a/nand-loader/openstub.ld +++ /dev/null @@ -1,35 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -OUTPUT_FORMAT("elf32-powerpc") -OUTPUT_ARCH(powerpc:common) - -ENTRY(_start) - -PHDRS { - app PT_LOAD FLAGS(7); -} - -SECTIONS { - . = 0x80004000; - - .text : { *(.text) *(.text.*) } :app - - .data : { *(.data) *(.data.*) } - .rodata : { *(.rodata) *(.rodata.*) } - - __bss_start = .; - .bss : { *(.bss) *(.bss.*) } - __bss_end = .; - - . = ALIGN(64); - __stack_end = .; - .stack : { - . += 0x8000; - __stack_top = .; - } -} diff --git a/nand-loader/rvl.ld b/nand-loader/rvl.ld new file mode 100644 index 0000000..9df04f4 --- /dev/null +++ b/nand-loader/rvl.ld @@ -0,0 +1,345 @@ +/* + * Linkscript for Wii + */ + +OUTPUT_FORMAT("elf32-powerpc", "elf32-powerpc", "elf32-powerpc"); +OUTPUT_ARCH(powerpc:common); +EXTERN(_stub_start); +ENTRY(_stub_start); + +SECTIONS +{ + /* DOL header (from TITANIK's GC docs) */ + /* default base address */ + off = 0; + + .header : AT(off) + { + /* 0000-001B Text[0..6] sections File Positions */ + LONG(stub_file_start); + LONG(text_file_start); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + + /* 001C-0047 Data[0..10] sections File Positions */ + LONG(data_file_start); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + + /* 0048-0063 Text[0..6] sections Mem Address */ + LONG(stub_mem_start); + LONG(text_mem_start); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + + /* 0064-008F Data[0..10] sections Mem Address */ + LONG(data_mem_start); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + + /* 0090-00AB Text[0..6] sections Sizes */ + LONG(stub_mem_size); + LONG(text_mem_size); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + + /* 00AC-00D7 Data[0..10] sections Sizes */ + LONG(data_mem_size); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + LONG(0); + + /* 00D8 BSS Mem address + 00DC BSS Size */ + LONG(bss_mem_start); + LONG(bss_mem_size); + + /* 00E0 Entry Point */ + LONG(ABSOLUTE(_stub_start)); + } + + . = 0x00003400; + off += 0x100; + + stub_mem_start = .; + stub_file_start = off; + + .stub : AT(off) + { + KEEP (*(.stub)) + . = 0x400; + } = 0 + + stub_mem_size = . - stub_mem_start; + off += stub_mem_size; + + . = 0x81330000; + + text_mem_start = .; + text_file_start = off; + + .init : AT(off) + { + KEEP (*crt0.o(*.init)) + KEEP (*(.init)) + } + + .text : + { + *(.text) + *(.text.*) + /* .gnu.warning sections are handled specially by elf32.em. */ + *(.gnu.warning) + *(.gnu.linkonce.t.*) + . = ALIGN(32); /* REQUIRED. LD is flaky without it. */ + } + + .fini : + { + KEEP (*(.fini)) + . = ALIGN(32); /* REQUIRED. LD is flaky without it. */ + } + + PROVIDE (__etext = .); + PROVIDE (_etext = .); + PROVIDE (etext = .); + + text_mem_size = . - text_mem_start; + off += text_mem_size; + + data_mem_start = .; + data_file_start = off; + + .data : AT(off) + { + *(.rodata) *(.rodata.*) *(.gnu.linkonce.r.*) + *(.rodata1) + *(.sdata2) *(.sdata2.*) *(.gnu.linkonce.s2.*) + *(.sbss2) *(.sbss2.*) *(.gnu.linkonce.sb2.*) + PROVIDE (__preinit_array_start = .); + *(.preinit_array) + PROVIDE (__preinit_array_end = .); + PROVIDE (__init_array_start = .); + *(.init_array) + PROVIDE (__init_array_end = .); + PROVIDE (__fini_array_start = .); + *(.fini_array) + PROVIDE (__fini_array_end = .); + + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + SORT(CONSTRUCTORS) + . = ALIGN(32); /* REQUIRED. LD is flaky without it. */ + } + + .data1 : { *(.data1) } + .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) } + .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) } + .gcc_except_table : { *(.gcc_except_table) } + .fixup : { *(.fixup) } + .got1 : { *(.got1) } + .got2 : { *(.got2) } + .dynamic : { *(.dynamic) } + + .ctors : + { + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + + KEEP (*crtbegin.o(.ctors)) + + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + + KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + . = ALIGN(32); /* REQUIRED. LD is flaky without it. */ + } + + .dtors : + { + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + . = ALIGN(32); /* REQUIRED. LD is flaky without it. */ + } + + .jcr : { KEEP (*(.jcr)) } + .got : { *(.got.plt) *(.got) } + + + /* We want the small data sections together, so single-instruction offsets + can access them all, and initialized data all before uninitialized, so + we can shorten the on-disk segment size. */ + + .sdata : + { + *(.sdata) + *(.sdata.*) + *(.gnu.linkonce.s.*) + . = ALIGN(32); /* REQUIRED. LD is flaky without it. */ + } + + _edata = .; + PROVIDE (edata = .); + + data_mem_size = . - data_mem_start; + off += data_mem_size; + + bss_mem_start = .; + bss_file_start = off; + + .sbss : AT(off) + { + __sbss_start = .; + PROVIDE (__sbss_start = .); + PROVIDE (___sbss_start = .); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + PROVIDE (__sbss_end = .); + PROVIDE (___sbss_end = .); + . = ALIGN(32); /* REQUIRED. LD is flaky without it. */ + __sbss_end = .; + } + + .bss : + { + __bss_start = .; + PROVIDE (__bss_start = .); + *(.dynbss) + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + /* Align here to ensure that the .bss section occupies space up to + _end. Align after .bss to ensure correct alignment even if the + .bss section disappears because there are no input sections. */ + + . = ALIGN(32); + + PROVIDE (__bss_end = .); + __bss_end = .; + } + + bss_mem_size = . - bss_mem_start; + + _end = .; + PROVIDE(end = .); + /* Stabs debugging sections. */ + .stab 0 : { *(.stab) } + .stabstr 0 : { *(.stabstr) } + .stab.excl 0 : { *(.stab.excl) } + .stab.exclstr 0 : { *(.stab.exclstr) } + .stab.index 0 : { *(.stab.index) } + .stab.indexstr 0 : { *(.stab.indexstr) } + .comment 0 : { *(.comment) } + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* These must appear regardless of . */ +} + +__isIPL = 0; +__stack_addr = (__bss_start + SIZEOF(.bss) + 0x20000 + 7) & (-8); +__stack_end = (__bss_start + SIZEOF(.bss)); +__intrstack_addr = (__stack_addr + 0x4000); +__intrstack_end = (__stack_addr); +__Arena1Lo = (__intrstack_addr + 31) & (-32); +__Arena1Hi = (0x816ffff0); +__Arena2Lo = (0x90002000); +__Arena2Hi = (0x933E0000); + +__gxregs = (__Arena1Hi + 31) & (-32); +__ipcbufferLo = (0x933e0000); +__ipcbufferHi = (0x93400000); + +/* for backward compatibility with old crt0 */ +PROVIDE (__stack = (0x816ffff0)); + +PROVIDE(__isIPL = __isIPL); +PROVIDE(__text_start = text_mem_start); +PROVIDE(__text_fstart = text_file_start); +PROVIDE(__data_start = data_mem_start); +PROVIDE(__data_fstart = data_file_start); +PROVIDE(__bss_start = bss_mem_start); +PROVIDE(__bss_fstart = bss_file_start); +PROVIDE(__stack_addr = __stack_addr); +PROVIDE(__stack_end = __stack_end); +PROVIDE(__intrstack_addr = __intrstack_addr); +PROVIDE(__intrstack_end = __intrstack_end); +PROVIDE(__Arena1Lo = __Arena1Lo); +PROVIDE(__Arena1Hi = __Arena1Hi); +PROVIDE(__Arena2Lo = __Arena2Lo); +PROVIDE(__Arena2Hi = __Arena2Hi); +PROVIDE(__ipcbufferLo = __ipcbufferLo); +PROVIDE(__ipcbufferHi = __ipcbufferHi); +PROVIDE(__gxregs = __gxregs); diff --git a/nand-loader/source/asm.h b/nand-loader/source/asm.h new file mode 100644 index 0000000..610d9c4 --- /dev/null +++ b/nand-loader/source/asm.h @@ -0,0 +1,93 @@ +#ifndef _ASM_H_ +#define _ASM_H_ + +/* Registers */ +#define r0 0 +#define r1 1 +#define r2 2 +#define r3 3 +#define r4 4 +#define r5 5 +#define r6 6 +#define r7 7 +#define r8 8 +#define r9 9 +#define r10 10 +#define r11 11 +#define r12 12 +#define r13 13 +#define r14 14 +#define r15 15 +#define r16 16 +#define r17 17 +#define r18 18 +#define r19 19 +#define r20 20 +#define r21 21 +#define r22 22 +#define r23 23 +#define r24 24 +#define r25 25 +#define r26 26 +#define r27 27 +#define r28 28 +#define r29 29 +#define r30 30 +#define r31 31 + + +/* BATs */ +#define IBAT0U 528 +#define IBAT0L 529 +#define IBAT1U 530 +#define IBAT1L 531 +#define IBAT2U 532 +#define IBAT2L 533 +#define IBAT3U 534 +#define IBAT3L 535 +#define IBAT4U 560 +#define IBAT4L 561 +#define IBAT5U 562 +#define IBAT5L 563 +#define IBAT6U 564 +#define IBAT6L 565 +#define IBAT7U 566 +#define IBAT7L 567 + +#define DBAT0U 536 +#define DBAT0L 537 +#define DBAT1U 538 +#define DBAT1L 539 +#define DBAT2U 540 +#define DBAT2L 541 +#define DBAT3U 542 +#define DBAT3L 543 +#define DBAT4U 568 +#define DBAT4L 569 +#define DBAT5U 570 +#define DBAT5L 571 +#define DBAT6U 572 +#define DBAT6L 573 +#define DBAT7U 574 +#define DBAT7L 575 + + +/* HIDs */ +#define HID0 1008 +#define HID1 1009 +#define HID2 920 +#define HID4 1011 + + +/* MSRs */ +#define MSR_RI 0x00000002 +#define MSR_DR 0x00000010 +#define MSR_IR 0x00000020 +#define MSR_IP 0x00000040 +#define MSR_SE 0x00000400 +#define MSR_ME 0x00001000 +#define MSR_FP 0x00002000 +#define MSR_POW 0x00004000 +#define MSR_EE 0x00008000 + +#endif diff --git a/nand-loader/source/config.c b/nand-loader/source/config.c new file mode 100644 index 0000000..a2497ce --- /dev/null +++ b/nand-loader/source/config.c @@ -0,0 +1,220 @@ +#include +#include +#include +#include + +#include "config.h" +#include "title.h" +#include "video.h" +#include "wpad.h" + +/* 'Menu' structure */ +struct menu { + /* Entry name */ + char *name; + + /* Entry value */ + bool *value; +}; + + +/* NANDLoader configuration */ +struct config loaderCfg ATTRIBUTE_ALIGN(32) = { 0 }; + +/* Config entries */ +struct menu entryList[] = { + { "Force PAL50", &loaderCfg.forcePal50 }, + { "Force PAL60", &loaderCfg.forcePal60 }, + { "Force NTSC", &loaderCfg.forceNtsc }, + { "Force HDTV", &loaderCfg.forceHdtv }, + { "Patch Video Mode", &loaderCfg.patchVmode }, + { "Show Splash", &loaderCfg.showSplash }, +}; + +/* Macros */ +#define NB_ENTRIES (sizeof(entryList) / sizeof(struct menu)) + + +void __Config_Credits(void) +{ + /* Clear console */ + Con_Clear(); + + /* Write credits */ + printf("[+] Custom NAND Loader for Wii\n\n"); + + printf(" developed by Waninkoko\n"); + printf(" www.teknoconsolas.es\n\n\n"); + + printf("[+] Thanks to all my betatesters:\n"); + printf(" - linkinworm\n"); + printf(" - hectorscasa\n"); + printf(" - SoraK05\n"); + printf(" - And the rest... ;-)\n\n"); + + printf("[+] Also kudos to:\n\n"); + printf(" - Team Twiizers\n"); + printf(" - SoftMii Team\n"); + printf(" - crediar\n"); + printf(" - WiiGator and kwiirk\n"); + printf(" - Teknoconsolas.es community\n\n"); + + printf("\n"); + printf("[+] Press any button to continue...\n"); + + /* Wait for any button */ + Wpad_WaitButtons(); +} + +s32 __Config_GetFilePath(char *outbuf) +{ + static char nandpath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); + + u64 tid; + s32 ret; + + /* Get title ID */ + ret = ES_GetTitleID(&tid); + if (ret < 0) + return ret; + + /* Get data directory */ + ret = ES_GetDataDir(tid, nandpath); + if (ret < 0) + return ret; + + /* Generate filepath */ + sprintf(outbuf, "%s/nand.cfg", nandpath); + + return 0; +} + + +s32 Config_Read(void) +{ + char filepath[ISFS_MAXPATH]; + s32 fd, ret; + + /* Get config filepath */ + ret = __Config_GetFilePath(filepath); + if (ret < 0) + return ret; + + /* Open config file */ + fd = IOS_Open(filepath, ISFS_OPEN_READ); + if (fd < 0) + return fd; + + /* Read config */ + ret = IOS_Read(fd, &loaderCfg, sizeof(loaderCfg)); + + /* Close config file */ + IOS_Close(fd); + + return ret; +} + +s32 Config_Write(void) +{ + char filepath[ISFS_MAXPATH]; + s32 fd, ret; + + /* Get config filepath */ + ret = __Config_GetFilePath(filepath); + if (ret < 0) + return ret; + + /* Create config file */ + ISFS_CreateFile(filepath, 0, ISFS_OPEN_RW, ISFS_OPEN_READ, ISFS_OPEN_READ); + + /* Open config file */ + fd = IOS_Open(filepath, ISFS_OPEN_WRITE); + if (fd < 0) + return fd; + + /* Write config */ + ret = IOS_Write(fd, &loaderCfg, sizeof(loaderCfg)); + + /* Close config file */ + IOS_Close(fd); + + return ret; +} + +void Config_Menu(void) +{ + u32 var = 0; + s32 selected = 0; + + for (;;) { + u32 cnt; + + /* Clear console */ + Con_Clear(); + + for (cnt = 0; cnt < NB_ENTRIES; cnt++) { + struct menu *entry = &entryList[cnt]; + + /* Print entry */ + printf("\t%2s %-16s : %s\n", (selected == cnt) ? ">>" : " ", entry->name, (*entry->value) ? "Yes" : "No"); + } + + printf("\n"); + + printf("[+] Press UP/DOWN to move cursor.\n"); + printf(" Press LEFT/RIGHT to toggle option.\n\n"); + + printf(" Press A button to save and continue...\n"); + + u32 buttons = Wpad_WaitButtons(); + + /* UP/DOWN buttons */ + if (buttons & WPAD_BUTTON_UP) { + if ((--selected) <= -1) + selected = (NB_ENTRIES - 1); + } + if (buttons & WPAD_BUTTON_DOWN) { + if ((++selected) >= NB_ENTRIES) + selected = 0; + } + + /* LEFT/RIGHT buttons */ + if (buttons & (WPAD_BUTTON_LEFT | WPAD_BUTTON_RIGHT)) + *entryList[selected].value ^= 1; + + /* A button */ + if (buttons & WPAD_BUTTON_A) + break; + + + /* Easter Egg */ + if (buttons & WPAD_BUTTON_1) { + switch (var) { + case 0: + var++; + break; + case 3: + /* Show credits screen */ + __Config_Credits(); + + var = 0; + break; + default: + var = 0; + } + } + if (buttons & WPAD_BUTTON_2) { + switch (var) { + case 1: + case 2: + var++; + break; + default: + var = 0; + } + } + } + + /* Write configuration */ + Config_Write(); +} diff --git a/nand-loader/source/config.h b/nand-loader/source/config.h new file mode 100644 index 0000000..35d4be9 --- /dev/null +++ b/nand-loader/source/config.h @@ -0,0 +1,28 @@ +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +/* 'Config' structure */ +struct config { + /* Video modes */ + bool forcePal50; + bool forcePal60; + bool forceNtsc; + bool forceHdtv; + + /* Video mode patching */ + bool patchVmode; + + /* Splash screen */ + bool showSplash; +}; + +/* NANDLoader configuration */ +extern struct config loaderCfg; + +/* Prototypes */ +s32 Config_Read(void); +s32 Config_Write(void); +void Config_Menu(void); + +#endif + diff --git a/nand-loader/source/gui.c b/nand-loader/source/gui.c new file mode 100644 index 0000000..e811542 --- /dev/null +++ b/nand-loader/source/gui.c @@ -0,0 +1,87 @@ +#include +#include +#include + +#include "video.h" + +/* Constants */ +#define CONSOLE_XCOORD 20 +#define CONSOLE_YCOORD 100 +#define CONSOLE_WIDTH 350 +#define CONSOLE_HEIGHT 300 + +#define MSG_XCOORD 180 +#define MSG_YCOORD 190 + + +s32 __Gui_DrawPng(void *img, u32 x, u32 y) +{ + IMGCTX ctx = NULL; + PNGUPROP imgProp; + + s32 ret; + + /* Select PNG data */ + ctx = PNGU_SelectImageFromBuffer(img); + if (!ctx) { + ret = -1; + goto out; + } + + /* Get image properties */ + ret = PNGU_GetImageProperties(ctx, &imgProp); + if (ret != PNGU_OK) { + ret = -1; + goto out; + } + + /* Draw image */ + Video_DrawPng(ctx, imgProp, x, y); + + /* Success */ + ret = 0; + +out: + /* Free memory */ + if (ctx) + PNGU_ReleaseImageContext(ctx); + + return ret; +} + + +void Gui_InitConsole(void) +{ + /* Initialize console */ + Con_Init(CONSOLE_XCOORD, CONSOLE_YCOORD, CONSOLE_WIDTH, CONSOLE_HEIGHT); +} + +void Gui_DrawBackground(void) +{ + extern char bgData[]; + + /* Draw background */ + __Gui_DrawPng(bgData, 0, 0); +} + +void Gui_DrawLoading(void) +{ + extern char loadingImg[]; + + /* Clear screen */ + Video_Clear(COLOR_BLACK); + + /* Draw loading image */ + __Gui_DrawPng(loadingImg, MSG_XCOORD, MSG_YCOORD); +} + +void Gui_DrawError(void) +{ + extern char errorImg[]; + + /* Clear screen */ + Video_Clear(COLOR_BLACK); + + /* Draw error image */ + __Gui_DrawPng(errorImg, MSG_XCOORD, MSG_YCOORD); +} diff --git a/nand-loader/source/gui.h b/nand-loader/source/gui.h new file mode 100644 index 0000000..f4ea218 --- /dev/null +++ b/nand-loader/source/gui.h @@ -0,0 +1,10 @@ +#ifndef _GUI_H_ +#define _GUI_H_ + +/* Prototypes */ +void Gui_InitConsole(void); +void Gui_DrawBackground(void); +void Gui_DrawLoading(void); +void Gui_DrawError(void); + +#endif diff --git a/nand-loader/source/loader.c b/nand-loader/source/loader.c new file mode 100644 index 0000000..b432e94 --- /dev/null +++ b/nand-loader/source/loader.c @@ -0,0 +1,265 @@ +#include +#include +#include +#include + +#include "config.h" +#include "patches.h" +#include "video.h" +#include "wpad.h" +#include "tools.h" + +/* DOL header structure */ +typedef struct { + u32 textoff[7]; + u32 dataoff[11]; + + u8 *textmem[7]; + u8 *datamem[11]; + + u32 textsize[7]; + u32 datasize[11]; + + u8 *bssmem; + u32 bsssize; + + u32 entry; + + u32 unused[7]; +} dolheader; + +/* Entry pointer */ +typedef void (*dolentry)(void); + +/* Constants */ +#define DOL_INDEX 1 + + +void __Loader_SetLowMem(void) +{ + /* Setup low memory */ + *(vu32*)0x800000F8 = 0x0E7BE2C0; + *(vu32*)0x800000FC = 0x2B73A840; + + /* Flush cache */ + DCFlushRange((void *)(0x800000F8), 0xFF); + + // Set the clock + settime(secs_to_ticks(time(NULL) - 946684800)); + + // Remove 002 error + *(u16 *)0x80003140 = 0x0038; + *(u16 *)0x80003142 = 0xffff; + *(u16 *)0x80003188 = 0x0038; + *(u16 *)0x8000318A = 0xffff; + + DCFlushRange((void*)0x80003140, 4); + DCFlushRange((void*)0x80003188, 4); +} + +void __Loader_SetVMode(u64 tid) +{ + GXRModeObj *vmode_ptr = NULL; + u32 vmode_reg; + + u32 progressive, tvmode; + + /* Get video mode configuration */ + progressive = (CONF_GetProgressiveScan() > 0) && VIDEO_HaveComponentCable(); + tvmode = CONF_GetVideo(); + + /* Select video mode */ + switch(tid & 0xFF) { + /* PAL */ + case 'P': + vmode_reg = (CONF_GetEuRGB60() > 0) ? 5 : 1; + + if (tvmode != CONF_VIDEO_PAL) { + vmode_reg = 5; + vmode_ptr = &TVNtsc480IntDf; + } + + break; + + /* NTSC or unknown */ + case 'E': + case 'J': + vmode_reg = 0; + + if (tvmode != CONF_VIDEO_NTSC) + vmode_ptr = &TVEurgb60Hz480IntDf; + + break; + + default: + vmode_reg = 0; + } + + /* Override video mode */ + if (loaderCfg.forcePal50) { + vmode_reg = 1; + vmode_ptr = &TVPal528IntDf; + } + + if (loaderCfg.forcePal60) { + vmode_reg = 5; + vmode_ptr = &TVEurgb60Hz480IntDf; + } + + if (loaderCfg.forceNtsc) { + vmode_reg = 0; + vmode_ptr = &TVNtsc480IntDf; + } + + if (loaderCfg.forceHdtv) { + vmode_reg = 0; + vmode_ptr = &TVNtsc480Prog; + } + + + /* Set video mode register */ + *(vu32 *)0x800000CC = vmode_reg; + + /* Set video mode */ + if (vmode_ptr) { + /* If progressive available, use it */ + if (progressive) + vmode_ptr = &TVNtsc480Prog; + + Video_Configure(vmode_ptr); + Video_Clear(COLOR_BLACK); + } + + // Anti-green screen fix + VIDEO_SetBlack(TRUE); + VIDEO_Flush(); + VIDEO_WaitVSync(); +} + + +void __Loader_PatchDol(u8 *buffer, u32 len) +{ + struct config *cfg = &loaderCfg; + + /* Video mode patching */ + if (cfg->patchVmode) + Patch_VideoMode(buffer, len); +} + +s32 __Loader_ReadDol(dolentry *p_entry) +{ + static dolheader dol ATTRIBUTE_ALIGN(32); + + u32 cnt; + s32 cfd = -1, ret; + + /* Open DOL file */ + cfd = ES_OpenContent(DOL_INDEX); + if (cfd < 0) + return cfd; + + /* Read DOL header */ + ret = ES_ReadContent(cfd, (u8 *)&dol, sizeof(dol)); + if (ret < 0) + goto out; + + /* Clear BSS */ + memset(dol.bssmem, 0, dol.bsssize); + + /* Read TEXT section */ + for (cnt = 0; cnt < 7; cnt++) { + u32 offset = dol.textoff[cnt]; + + if (offset >= sizeof(dol)) { + u8 *buffer = (u8 *)dol.textmem[cnt]; + u32 len = dol.textsize[cnt]; + + /* Seek */ + ES_SeekContent(cfd, offset, 0); + + /* Read */ + ret = ES_ReadContent(cfd, buffer, len); + if (ret < 0) + goto out; + + /* Patch */ + __Loader_PatchDol(buffer, len); + } + } + + /* Read DATA section */ + for (cnt = 0; cnt < 11; cnt++) { + u32 offset = dol.dataoff[cnt]; + + if (offset >= sizeof(dol)) { + u8 *buffer = (u8 *)dol.datamem[cnt]; + u32 len = dol.datasize[cnt]; + + /* Seek */ + ES_SeekContent(cfd, offset, 0); + + /* Read */ + ret = ES_ReadContent(cfd, buffer, len); + if (ret < 0) + goto out; + + /* Patch */ + __Loader_PatchDol(buffer, len); + } + } + + /* Set entry point */ + *p_entry = (dolentry)dol.entry; + +out: + /* Close DOL file */ + if (cfd >= 0) + ES_CloseContent(cfd); + + return ret; +} + +void __Loader_Shutdown(void) +{ + /* Deinitialize ISFS */ + ISFS_Deinitialize(); + + /* Shutdown IOS subsystems */ + SYS_ResetSystem(SYS_SHUTDOWN, 0, 0); +} + + +s32 Loader_Execute(void) +{ + dolentry p_entry = NULL; + + u64 tid; + s32 ret; + + /* Get title ID */ + ret = ES_GetTitleID(&tid); + if (ret < 0) + return ret; + + /* Load DOL */ + ret = __Loader_ReadDol(&p_entry); + if (ret < 0) + return ret; + + /* Set low memory */ + __Loader_SetLowMem(); + + /* Set video mode */ + __Loader_SetVMode(tid); + + /* Shutdown subsystems */ + __Loader_Shutdown(); + + /* Clear screen */ + Video_Clear(COLOR_BLACK); + + /* Jump to the entry point */ + p_entry(); + + return 0; +} diff --git a/nand-loader/source/loader.h b/nand-loader/source/loader.h new file mode 100644 index 0000000..dd5457c --- /dev/null +++ b/nand-loader/source/loader.h @@ -0,0 +1,8 @@ +#ifndef _LOADER_H_ +#define _LOADER_H_ + +/* Prototypes */ +s32 Loader_Execute(void); + +#endif + diff --git a/nand-loader/source/nandloader.c b/nand-loader/source/nandloader.c new file mode 100644 index 0000000..af67cdf --- /dev/null +++ b/nand-loader/source/nandloader.c @@ -0,0 +1,79 @@ +#include +#include +#include + +#include "config.h" +#include "gui.h" +#include "loader.h" +#include "sys.h" +#include "video.h" +#include "wpad.h" + +/* Constans */ +#define RESTART_SECONDS 4 + + +/* Override IOS_LoadStartupIOS */ +s32 __IOS_LoadStartupIOS() { return 0; } + + +void Menu(void) +{ + /* Initialize Wiimote */ + Wpad_Init(); + + /* Draw background */ + Gui_DrawBackground(); + + /* Initialize console */ + Gui_InitConsole(); + + /* Configuration menu */ + Config_Menu(); + + /* Destroy console */ + Con_Destroy(); + + /* Disconnect Wiimote */ + Wpad_Disconnect(); +} + +int main(int argc, char **argv) +{ + s32 ret; + + /* Initialize subsystems */ + Sys_Init(); + + /* Set video mode */ + Video_SetMode(); + + /* Initialize ISFS */ + ISFS_Initialize(); + + /* Read config */ + Config_Read(); + + /* Config menu */ + ret = SYS_ResetButtonDown(); + if (ret) + Menu(); + + /* Draw loading image */ + if(loaderCfg.showSplash) + Gui_DrawLoading(); + + /* Execute application */ + Loader_Execute(); + + /* Draw error image */ + Gui_DrawError(); + + /* Sleep */ + sleep(RESTART_SECONDS); + + /* Load System Menu */ + Sys_LoadMenu(); + + return 0; +} diff --git a/nand-loader/source/patches.c b/nand-loader/source/patches.c new file mode 100644 index 0000000..cd286b2 --- /dev/null +++ b/nand-loader/source/patches.c @@ -0,0 +1,126 @@ +#include +#include +#include + +#include "config.h" + +GXRModeObj *PAL2NTSC[] = { + &TVMpal480IntDf, &TVNtsc480IntDf, + &TVPal264Ds, &TVNtsc240Ds, + &TVPal264DsAa, &TVNtsc240DsAa, + &TVPal264Int, &TVNtsc240Int, + &TVPal264IntAa, &TVNtsc240IntAa, + &TVPal524IntAa, &TVNtsc480IntAa, + &TVPal528Int, &TVNtsc480IntAa, + &TVPal528IntDf, &TVNtsc480IntDf, + &TVPal574IntDfScale, &TVNtsc480IntDf, + &TVEurgb60Hz240Ds, &TVNtsc240Ds, + &TVEurgb60Hz240DsAa, &TVNtsc240DsAa, + &TVEurgb60Hz240Int, &TVNtsc240Int, + &TVEurgb60Hz240IntAa, &TVNtsc240IntAa, + &TVEurgb60Hz480Int, &TVNtsc480IntAa, + &TVEurgb60Hz480IntDf, &TVNtsc480IntDf, + &TVEurgb60Hz480IntAa, &TVNtsc480IntAa, + &TVEurgb60Hz480Prog, &TVNtsc480Prog, + &TVEurgb60Hz480ProgSoft,&TVNtsc480Prog, + &TVEurgb60Hz480ProgAa, &TVNtsc480Prog, + NULL, NULL +}; + +GXRModeObj *NTSC2PAL[] = { + &TVNtsc240Ds, &TVPal264Ds, + &TVNtsc240DsAa, &TVPal264DsAa, + &TVNtsc240Int, &TVPal264Int, + &TVNtsc240IntAa, &TVPal264IntAa, + &TVNtsc480IntDf, &TVPal528IntDf, + &TVNtsc480IntAa, &TVPal524IntAa, + &TVNtsc480Prog, &TVPal528IntDf, + NULL, NULL +}; + +GXRModeObj *NTSC2PAL60[]={ + &TVNtsc240Ds, &TVEurgb60Hz240Ds, + &TVNtsc240DsAa, &TVEurgb60Hz240DsAa, + &TVNtsc240Int, &TVEurgb60Hz240Int, + &TVNtsc240IntAa, &TVEurgb60Hz240IntAa, + &TVNtsc480IntDf, &TVEurgb60Hz480IntDf, + &TVNtsc480IntAa, &TVEurgb60Hz480IntAa, + &TVNtsc480Prog, &TVEurgb60Hz480Prog, + NULL, NULL +}; + + +void Patch_VideoMode(u8 *buffer, u32 len) +{ + GXRModeObj **table = NULL; + + u32 cnt, idx; + + /* Select conversion table */ + if (loaderCfg.forcePal50) + table = NTSC2PAL; + if (loaderCfg.forcePal60) + table = NTSC2PAL60; + if (loaderCfg.forceNtsc) + table = PAL2NTSC; + + /* No table selected */ + if (!table) + return; + + for (cnt = 0; cnt < len; cnt += 4) { + u8 *ptr = buffer + cnt; + + /* Search for video modes */ + for (idx = 0; table[idx]; idx += 2) { + /* Patch video mode */ + if (!memcmp(ptr, table[idx], sizeof(GXRModeObj))) + memcpy(ptr, table[idx+1], sizeof(GXRModeObj)); + } + } +} + +// void __Patch_VideoMode(u8 *buffer, u32 len) +// { +// const u8 pattern[] = { 0x54, 0x00, 0xFF, 0xFE }; +// +// u64 tid; +// u32 cnt; +// +// /* Get title ID */ +// ES_GetTitleID(&tid); +// +// for (cnt = 0; cnt < len; cnt += 4) { +// u32 *ptr = (u32 *)(buffer + cnt); +// +// /* Pattern found */ +// if (!memcmp(ptr, pattern, sizeof(pattern))) { +// u8 region = tid & 0xFF; +// +// /* USA region */ +// if (region == 'E') +// *ptr = 0x38000001; +// /* JAP region */ +// if (region == 'J') +// *ptr = 0x38000000; +// +// break; +// } +// } +// } +// +// +// void Patch_VideoMode(u8 *buffer, u32 len) +// { +// const u8 pattern[] = { 0x41, 0x82, 0x00, 0x0C, 0x41, 0x80, 0x00, 0x1C, 0x48, 0x00, 0x00, 0x18 }; +// +// u32 cnt; +// +// for (cnt = 0; cnt < len; cnt += 4) { +// u8 *ptr = buffer + cnt; +// +// /* Pattern found */ +// if (!memcmp(ptr, pattern, sizeof(pattern))) +// __Patch_VideoMode(ptr, len - cnt); +// } +// } diff --git a/nand-loader/source/patches.h b/nand-loader/source/patches.h new file mode 100644 index 0000000..78a271f --- /dev/null +++ b/nand-loader/source/patches.h @@ -0,0 +1,7 @@ +#ifndef _PATCHES_H_ +#define _PATCHES_H_ + +/* Prototypes */ +void Patch_VideoMode(u8 *, u32); + +#endif diff --git a/nand-loader/source/pngu.c b/nand-loader/source/pngu.c new file mode 100644 index 0000000..1bab952 --- /dev/null +++ b/nand-loader/source/pngu.c @@ -0,0 +1,1561 @@ +/******************************************************************************************** + +PNGU Version : 0.2a + +Coder : frontier + +More info : http://frontier-dev.net + +********************************************************************************************/ +#include +#include +#include +#include "png.h" +#include "pngu.h" +#include "pngu_impl.h" + +#ifndef SAFE_FREE +#define SAFE_FREE(p) if(p){free(p);p=NULL;} +#endif + +#if 0 +// moved to pngu_impl.h +// Constants +#define PNGU_SOURCE_BUFFER 1 +#define PNGU_SOURCE_DEVICE 2 + +// Prototypes of helper functions +int pngu_info (IMGCTX ctx); +int pngu_decode (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha); +int pngu_decode_add_alpha (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha, int force32bit); +void pngu_free_info (IMGCTX ctx); +void pngu_read_data_from_buffer (png_structp png_ptr, png_bytep data, png_size_t length); +void pngu_write_data_to_buffer (png_structp png_ptr, png_bytep data, png_size_t length); +void pngu_flush_data_to_buffer (png_structp png_ptr); +int pngu_clamp (int value, int min, int max); + + +// PNGU Image context struct +struct _IMGCTX +{ + int source; + void *buffer; + char *filename; + PNGU_u32 cursor; + PNGU_u32 buf_size; // buffer size + + PNGU_u32 propRead; + PNGUPROP prop; + + PNGU_u32 infoRead; + png_structp png_ptr; + png_infop info_ptr; + FILE *fd; + + png_bytep *row_pointers; + png_bytep img_data; +}; +#endif + + +// PNGU Implementation // + +IMGCTX PNGU_SelectImageFromBufferX (const void *buffer, int size) +{ + IMGCTX ctx = NULL; + + if (!buffer) + return NULL; + + ctx = calloc (sizeof (struct _IMGCTX), 1); + if (!ctx) + return NULL; + + ctx->buffer = (void *) buffer; + ctx->source = PNGU_SOURCE_BUFFER; + ctx->cursor = 0; + ctx->filename = NULL; + ctx->propRead = 0; + ctx->infoRead = 0; + ctx->buf_size = size; + + return ctx; +} + +IMGCTX PNGU_SelectImageFromBuffer (const void *buffer) +{ + return PNGU_SelectImageFromBufferX(buffer, 0); +} + + +IMGCTX PNGU_SelectImageFromDevice (const char *filename) +{ + IMGCTX ctx = NULL; + + if (!filename) + return NULL; + + ctx = calloc (sizeof (struct _IMGCTX), 1); + if (!ctx) + return NULL; + + ctx->buffer = NULL; + ctx->source = PNGU_SOURCE_DEVICE; + ctx->cursor = 0; + + ctx->filename = malloc (strlen (filename) + 1); + if (!ctx->filename) + { + free (ctx); + return NULL; + } + strcpy(ctx->filename, filename); + + ctx->propRead = 0; + ctx->infoRead = 0; + + return ctx; +} + + +void PNGU_ReleaseImageContext (IMGCTX ctx) +{ + if (!ctx) + return; + + if (ctx->filename) + free (ctx->filename); + + if ((ctx->propRead) && (ctx->prop.trans)) + free (ctx->prop.trans); + + pngu_free_info (ctx); + + free (ctx); +} + + +int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *imgprop) +{ + int res; + + if (!ctx->propRead) + { + res = pngu_info (ctx); + if (res != PNGU_OK) + return res; + } + + *imgprop = ctx->prop; + + return PNGU_OK; +} + + +int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride) +{ + int result; + PNGU_u32 x, y, buffWidth; + + // width needs to be divisible by two + if (width % 2) + return PNGU_ODD_WIDTH; + + // stride needs to be divisible by two + if (stride % 2) + return PNGU_ODD_STRIDE; + + result = pngu_decode (ctx, width, height, 1); + if (result != PNGU_OK) + return result; + + // Copy image to the output buffer + buffWidth = (width + stride) / 2; + for (y = 0; y < height; y++) + for (x = 0; x < (width / 2); x++) + ((PNGU_u32 *)buffer)[y*buffWidth+x] = PNGU_RGB8_TO_YCbYCr (*(ctx->row_pointers[y]+x*6), *(ctx->row_pointers[y]+x*6+1), *(ctx->row_pointers[y]+x*6+2), + *(ctx->row_pointers[y]+x*6+3), *(ctx->row_pointers[y]+x*6+4), *(ctx->row_pointers[y]+x*6+5)); + + // Free resources + free (ctx->img_data); + free (ctx->row_pointers); + + // Success + return PNGU_OK; +} + + +int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride) +{ + int result; + PNGU_u32 x, y, buffWidth; + + result = pngu_decode (ctx, width, height, 1); + if (result != PNGU_OK) + return result; + + buffWidth = width + stride; + + // Copy image to the output buffer + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) + ((PNGU_u16 *)buffer)[y*buffWidth+x] = + (((PNGU_u16) (ctx->row_pointers[y][x*3] & 0xF8)) << 8) | + (((PNGU_u16) (ctx->row_pointers[y][x*3+1] & 0xFC)) << 3) | + (((PNGU_u16) (ctx->row_pointers[y][x*3+2] & 0xF8)) >> 3); + + // Free resources + free (ctx->img_data); + free (ctx->row_pointers); + + // Success + return PNGU_OK; +} + + +int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha) +{ + int result; + PNGU_u32 x, y, buffWidth; + + result = pngu_decode (ctx, width, height, 0); + if (result != PNGU_OK) + return result; + + buffWidth = width + stride; + + // Check is source image has an alpha channel + if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) ) + { + // Alpha channel present, copy image to the output buffer + for (y = 0; y < height; y++) + memcpy (buffer + (y * buffWidth * 4), ctx->row_pointers[y], width * 4); + } + else + { + // No alpha channel present, copy image to the output buffer + for (y = 0; y < height; y++) + for (x = 0; x < width; x++) + ((PNGU_u32 *)buffer)[y*buffWidth+x] = + (((PNGU_u32) ctx->row_pointers[y][x*3]) << 24) | + (((PNGU_u32) ctx->row_pointers[y][x*3+1]) << 16) | + (((PNGU_u32) ctx->row_pointers[y][x*3+2]) << 8) | + ((PNGU_u32) default_alpha); + } + + // Free resources + free (ctx->img_data); + free (ctx->row_pointers); + + // Success + return PNGU_OK; +} + + +int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer) +{ + int result; + PNGU_u32 x, y, qwidth, qheight; + + // width and height need to be divisible by four + if ((width % 4) || (height % 4)) + return PNGU_INVALID_WIDTH_OR_HEIGHT; + + result = pngu_decode (ctx, width, height, 1); + if (result != PNGU_OK) + return result; + + // Copy image to the output buffer + qwidth = width / 4; + qheight = height / 4; + + for (y = 0; y < qheight; y++) + for (x = 0; x < qwidth; x++) + { + int blockbase = (y * qwidth + x) * 4; + + PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*12)); + PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase] = + (((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) | + (((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) | + (((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) | + (((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3))); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+1]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+1] = + (((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) | + (((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) | + (((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) | + (((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3))); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+2]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+2] = + (((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) | + (((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) | + (((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) | + (((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3))); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+3]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+3] = + (((field64 & 0xF800000000000000ULL) | ((field64 & 0xFC000000000000ULL) << 3) | ((field64 & 0xF80000000000ULL) << 5)) | + (((field64 & 0xF800000000ULL) << 8) | ((field64 & 0xFC000000ULL) << 11) | ((field64 & 0xF80000ULL) << 13)) | + (((field64 & 0xF800ULL) << 16) | ((field64 & 0xFCULL) << 19) | ((field32 & 0xF8000000ULL) >> 11)) | + (((field32 & 0xF80000ULL) >> 8) | ((field32 & 0xFC00ULL) >> 5) | ((field32 & 0xF8ULL) >> 3))); + } + + // Free resources + free (ctx->img_data); + free (ctx->row_pointers); + + // Success + return PNGU_OK; +} + + +int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha) +{ + int result; + PNGU_u32 x, y, qwidth, qheight; + PNGU_u64 alphaMask; + + // width and height need to be divisible by four + if ((width % 4) || (height % 4)) + return PNGU_INVALID_WIDTH_OR_HEIGHT; + + result = pngu_decode (ctx, width, height, 0); + if (result != PNGU_OK) + return result; + + // Init some vars + qwidth = width / 4; + qheight = height / 4; + + // Check is source image has an alpha channel + if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) ) + { + // Alpha channel present, copy image to the output buffer + for (y = 0; y < qheight; y++) + for (x = 0; x < qwidth; x++) + { + int blockbase = (y * qwidth + x) * 4; + PNGU_u64 tmp; + + PNGU_u64 fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*16)); + PNGU_u64 fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*16+8)); + // If first pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444 + if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL) + tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5); + else + tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4); + + // If second pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444 + if ((fieldA & 0xE0ULL) == 0xE0ULL) + tmp = tmp | 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21); + else + tmp = tmp | ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20); + + // If third pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444 + if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL) + tmp = tmp | 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27); + else + tmp = tmp | ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28); + + // If fourth pixel is opaque set MSB to 1 and encode colors in RGB555, else set MSB to 0 and encode colors in ARGB3444 + if ((fieldB & 0xE0ULL) == 0xE0ULL) + tmp = tmp | 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11); + else + tmp = tmp | ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12); + ((PNGU_u64 *) buffer)[blockbase] = tmp; + + fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*16)); + fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*16+8)); + if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4); + + if ((fieldA & 0xE0ULL) == 0xE0ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = tmp | 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = tmp | ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20); + + if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = tmp | 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = tmp | ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28); + + if ((fieldB & 0xE0ULL) == 0xE0ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = tmp | 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = tmp | ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12); + ((PNGU_u64 *) buffer)[blockbase+1] = tmp; + + fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*16)); + fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*16+8)); + if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4); + + if ((fieldA & 0xE0ULL) == 0xE0ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = tmp | 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = tmp | ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20); + + if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = tmp | 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = tmp | ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28); + + if ((fieldB & 0xE0ULL) == 0xE0ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = tmp | 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = tmp | ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12); + ((PNGU_u64 *) buffer)[blockbase+2] = tmp; + + fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*16)); + fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*16+8)); + if ((fieldA & 0xE000000000ULL) == 0xE000000000ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = 0x8000000000000000ULL | ((fieldA & 0xF800000000000000ULL) >> 1) | ((fieldA & 0xF8000000000000ULL) << 2) | ((fieldA & 0xF80000000000ULL) << 5); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = ((fieldA & 0xE000000000ULL) << 23) | ((fieldA & 0xF000000000000000ULL) >> 4) | (fieldA & 0xF0000000000000ULL) | ((fieldA & 0xF00000000000ULL) << 4); + + if ((fieldA & 0xE0ULL) == 0xE0ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = tmp | 0x800000000000ULL | ((fieldA & 0xF8000000ULL) << 15) | ((fieldA & 0xF80000ULL) << 18) | ((fieldA & 0xF800ULL) << 21); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = tmp | ((fieldA & 0xE0ULL) << 39) | ((fieldA & 0xF0000000ULL) << 12) | ((fieldA & 0xF00000ULL) << 16) | ((fieldA & 0xF000ULL) << 20); + + if ((fieldB & 0xE000000000ULL) == 0xE000000000ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = tmp | 0x80000000ULL | ((fieldB & 0xF800000000000000ULL) >> 33) | ((fieldB & 0xF8000000000000ULL) >> 30) | ((fieldB & 0xF80000000000ULL) >> 27); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = tmp | ((fieldB & 0xE000000000ULL) >> 9) | ((fieldB & 0xF000000000000000ULL) >> 36) | ((fieldB & 0xF0000000000000ULL) >> 32) | ((fieldB & 0xF00000000000ULL) >> 28); + + if ((fieldB & 0xE0ULL) == 0xE0ULL) + // Opaque pixel, so set MSB to 1 and encode colors in RGB555 + tmp = tmp | 0x8000ULL | ((fieldB & 0xF8000000ULL) >> 17) | ((fieldB & 0xF80000ULL) >> 14) | ((fieldB & 0xF800ULL) >> 11); + else + // Tranlucid pixel, so set MSB to 0 and encode colors in ARGB3444 + tmp = tmp | ((fieldB & 0xE0ULL) << 7) | ((fieldB & 0xF0000000ULL) >> 20) | ((fieldB & 0xF00000ULL) >> 16) | ((fieldB & 0xF000ULL) >> 12); + ((PNGU_u64 *) buffer)[blockbase+3] = tmp; + } + } + else + { + // No alpha channel present, copy image to the output buffer + default_alpha = (default_alpha >> 5); + if (default_alpha == 7) + { + // The user wants an opaque texture, so set MSB to 1 and encode colors in RGB555 + alphaMask = 0x8000800080008000ULL; + + for (y = 0; y < qheight; y++) + for (x = 0; x < qwidth; x++) + { + int blockbase = (y * qwidth + x) * 4; + + PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*12)); + PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase] = + alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) | + ((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) | + ((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) | + ((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+1]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+1] = + alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) | + ((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) | + ((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) | + ((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+2]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+2] = + alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) | + ((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) | + ((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) | + ((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+3]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+3] = + alphaMask | ((field64 & 0xF800000000000000ULL) >> 1) | ((field64 & 0xF8000000000000ULL) << 2) | + ((field64 & 0xF80000000000ULL) << 5) | ((field64 & 0xF800000000ULL) << 7) | ((field64 & 0xF8000000ULL) << 10) | + ((field64 & 0xF80000ULL) << 13) | ((field64 & 0xF800ULL) << 15) | ((field64 & 0xF8ULL) << 18) | + ((field32 & 0xF8000000ULL) >> 11) | ((field32 & 0xF80000ULL) >> 9) | ((field32 & 0xF800ULL) >> 6) | ((field32 & 0xF8ULL) >> 3); + } + } + else + { + // The user wants a translucid texture, so set MSB to 0 and encode colors in ARGB3444 + default_alpha = (default_alpha << 4); + alphaMask = (((PNGU_u64) default_alpha) << 56) | (((PNGU_u64) default_alpha) << 40) | + (((PNGU_u64) default_alpha) << 24) | (((PNGU_u64) default_alpha) << 8); + + for (y = 0; y < qheight; y++) + for (x = 0; x < qwidth; x++) + { + int blockbase = (y * qwidth + x) * 4; + + PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*12)); + PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase] = + alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) | + ((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) | + ((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) | + ((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+1]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+1] = + alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) | + ((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) | + ((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) | + ((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+2]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+2] = + alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) | + ((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) | + ((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) | + ((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+3]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+3] = + alphaMask | ((field64 & 0xF000000000000000ULL) >> 4) | (field64 & 0xF0000000000000ULL) | ((field64 & 0xF00000000000ULL) << 4) | + ((field64 & 0xF000000000ULL) << 4) | ((field64 & 0xF0000000ULL) << 8) | ((field64 & 0xF00000ULL) << 12) | + ((field64 & 0xF000ULL) << 12) | ((field64 & 0xF0ULL) << 16) | ((field32 & 0xF0000000ULL) >> 12) | + ((field32 & 0xF00000ULL) >> 12) | ((field32 & 0xF000ULL) >> 8) | ((field32 & 0xF0ULL) >> 4); + } + } + } + + // Free resources + free (ctx->img_data); + free (ctx->row_pointers); + + // Success + return PNGU_OK; +} + + +int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha) +{ + int result; + PNGU_u32 x, y, qwidth, qheight; + PNGU_u64 alphaMask; + + // width and height need to be divisible by four + if ((width % 4) || (height % 4)) + return PNGU_INVALID_WIDTH_OR_HEIGHT; + + result = pngu_decode (ctx, width, height, 0); + if (result != PNGU_OK) + return result; + + // Init some variables + qwidth = width / 4; + qheight = height / 4; + + // Check is source image has an alpha channel + if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) ) + { + // Alpha channel present, copy image to the output buffer + for (y = 0; y < qheight; y++) + for (x = 0; x < qwidth; x++) + { + int blockbase = (y * qwidth + x) * 8; + + PNGU_u64 fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*16)); + PNGU_u64 fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*16+8)); + ((PNGU_u64 *) buffer)[blockbase] = + ((fieldA & 0xFF00000000ULL) << 24) | ((fieldA & 0xFF00000000000000ULL) >> 8) | + ((fieldA & 0xFFULL) << 40) | ((fieldA & 0xFF000000ULL) << 8) | + ((fieldB & 0xFF00000000ULL) >> 8) | ((fieldB & 0xFF00000000000000ULL) >> 40) | + ((fieldB & 0xFFULL) << 8) | ((fieldB & 0xFF000000ULL) >> 24); + ((PNGU_u64 *) buffer)[blockbase+4] = + ((fieldA & 0xFFFF0000000000ULL) << 8) | ((fieldA & 0xFFFF00ULL) << 24) | + ((fieldB & 0xFFFF0000000000ULL) >> 24) | ((fieldB & 0xFFFF00ULL) >> 8); + + fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*16)); + fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*16+8)); + ((PNGU_u64 *) buffer)[blockbase+1] = + ((fieldA & 0xFF00000000ULL) << 24) | ((fieldA & 0xFF00000000000000ULL) >> 8) | + ((fieldA & 0xFFULL) << 40) | ((fieldA & 0xFF000000ULL) << 8) | + ((fieldB & 0xFF00000000ULL) >> 8) | ((fieldB & 0xFF00000000000000ULL) >> 40) | + ((fieldB & 0xFFULL) << 8) | ((fieldB & 0xFF000000ULL) >> 24); + ((PNGU_u64 *) buffer)[blockbase+5] = + ((fieldA & 0xFFFF0000000000ULL) << 8) | ((fieldA & 0xFFFF00ULL) << 24) | + ((fieldB & 0xFFFF0000000000ULL) >> 24) | ((fieldB & 0xFFFF00ULL) >> 8); + + fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*16)); + fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*16+8)); + ((PNGU_u64 *) buffer)[blockbase+2] = + ((fieldA & 0xFF00000000ULL) << 24) | ((fieldA & 0xFF00000000000000ULL) >> 8) | + ((fieldA & 0xFFULL) << 40) | ((fieldA & 0xFF000000ULL) << 8) | + ((fieldB & 0xFF00000000ULL) >> 8) | ((fieldB & 0xFF00000000000000ULL) >> 40) | + ((fieldB & 0xFFULL) << 8) | ((fieldB & 0xFF000000ULL) >> 24); + ((PNGU_u64 *) buffer)[blockbase+6] = + ((fieldA & 0xFFFF0000000000ULL) << 8) | ((fieldA & 0xFFFF00ULL) << 24) | + ((fieldB & 0xFFFF0000000000ULL) >> 24) | ((fieldB & 0xFFFF00ULL) >> 8); + + fieldA = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*16)); + fieldB = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*16+8)); + ((PNGU_u64 *) buffer)[blockbase+3] = + ((fieldA & 0xFF00000000ULL) << 24) | ((fieldA & 0xFF00000000000000ULL) >> 8) | + ((fieldA & 0xFFULL) << 40) | ((fieldA & 0xFF000000ULL) << 8) | + ((fieldB & 0xFF00000000ULL) >> 8) | ((fieldB & 0xFF00000000000000ULL) >> 40) | + ((fieldB & 0xFFULL) << 8) | ((fieldB & 0xFF000000ULL) >> 24); + ((PNGU_u64 *) buffer)[blockbase+7] = + ((fieldA & 0xFFFF0000000000ULL) << 8) | ((fieldA & 0xFFFF00ULL) << 24) | + ((fieldB & 0xFFFF0000000000ULL) >> 24) | ((fieldB & 0xFFFF00ULL) >> 8); + } + } + else + { + // No alpha channel present, copy image to the output buffer + alphaMask = (((PNGU_u64)default_alpha) << 56) | (((PNGU_u64)default_alpha) << 40) | + (((PNGU_u64)default_alpha) << 24) | (((PNGU_u64)default_alpha) << 8); + + for (y = 0; y < qheight; y++) + for (x = 0; x < qwidth; x++) + { + int blockbase = (y * qwidth + x) * 8; + + PNGU_u64 field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4]+x*12)); + PNGU_u64 field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase] = + (((field64 & 0xFF00000000000000ULL) >> 8) | (field64 & 0xFF00000000ULL) | + ((field64 & 0xFF00ULL) << 8) | ((field32 & 0xFF0000ULL) >> 16) | alphaMask); + ((PNGU_u64 *) buffer)[blockbase+4] = + (((field64 & 0xFFFF0000000000ULL) << 8) | ((field64 & 0xFFFF0000ULL) << 16) | + ((field64 & 0xFFULL) << 24) | ((field32 & 0xFF000000ULL) >> 8) | (field32 & 0xFFFFULL)); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+1]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+1]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+1] = + (((field64 & 0xFF00000000000000ULL) >> 8) | (field64 & 0xFF00000000ULL) | + ((field64 & 0xFF00ULL) << 8) | ((field32 & 0xFF0000ULL) >> 16) | alphaMask); + ((PNGU_u64 *) buffer)[blockbase+5] = + (((field64 & 0xFFFF0000000000ULL) << 8) | ((field64 & 0xFFFF0000ULL) << 16) | + ((field64 & 0xFFULL) << 24) | ((field32 & 0xFF000000ULL) >> 8) | (field32 & 0xFFFFULL)); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+2]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+2]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+2] = + (((field64 & 0xFF00000000000000ULL) >> 8) | (field64 & 0xFF00000000ULL) | + ((field64 & 0xFF00ULL) << 8) | ((field32 & 0xFF0000ULL) >> 16) | alphaMask); + ((PNGU_u64 *) buffer)[blockbase+6] = + (((field64 & 0xFFFF0000000000ULL) << 8) | ((field64 & 0xFFFF0000ULL) << 16) | + ((field64 & 0xFFULL) << 24) | ((field32 & 0xFF000000ULL) >> 8) | (field32 & 0xFFFFULL)); + + field64 = *((PNGU_u64 *)(ctx->row_pointers[y*4+3]+x*12)); + field32 = (PNGU_u64) *((PNGU_u32 *)(ctx->row_pointers[y*4+3]+x*12+8)); + ((PNGU_u64 *) buffer)[blockbase+3] = + (((field64 & 0xFF00000000000000ULL) >> 8) | (field64 & 0xFF00000000ULL) | + ((field64 & 0xFF00ULL) << 8) | ((field32 & 0xFF0000ULL) >> 16) | alphaMask); + ((PNGU_u64 *) buffer)[blockbase+7] = + (((field64 & 0xFFFF0000000000ULL) << 8) | ((field64 & 0xFFFF0000ULL) << 16) | + ((field64 & 0xFFULL) << 24) | ((field32 & 0xFF000000ULL) >> 8) | (field32 & 0xFFFFULL)); + } + } + + // Free resources + free (ctx->img_data); + free (ctx->row_pointers); + + // Success + return PNGU_OK; +} + + +//######################################################################################## +//---------- Start CMPR added section --------------------------------------------------- +//######################################################################################## + +static inline PNGU_u16 rgb8ToRGB565(PNGU_u8 *color) +{ + return ((color[0] >> 3) << 11) | ((color[1] >> 2) << 5) | (color[2] >> 3); +} + +static int colorDistance(const PNGU_u8 *c0, const PNGU_u8 *c1) +{ + return (c1[0] - c0[0]) * (c1[0] - c0[0]) + (c1[1] - c0[1]) * (c1[1] - c0[1]) + (c1[2] - c0[2]) * (c1[2] - c0[2]); +} + +static void getBaseColors(PNGU_u8 *color0, PNGU_u8 *color1, const PNGU_u8 *srcBlock) +{ + int maxDistance = -1; + int i; + int j; + + for (i = 0; i < 15; ++i) + for (j = i + 1; j < 16; ++j) + { + int distance = colorDistance(srcBlock + i * 4, srcBlock + j * 4); + if (distance > maxDistance) + { + maxDistance = distance; + *(PNGU_u32 *)color0 = ((PNGU_u32 *)srcBlock)[i]; + *(PNGU_u32 *)color1 = ((PNGU_u32 *)srcBlock)[j]; + } + } + if (rgb8ToRGB565(color0) < rgb8ToRGB565(color1)) + { + PNGU_u32 tmp; + tmp = *(PNGU_u32 *)color0; + *(PNGU_u32 *)color0 = *(PNGU_u32 *)color1; + *(PNGU_u32 *)color1 = tmp; + } +} + +static PNGU_u32 colorIndices(const PNGU_u8 *color0, const PNGU_u8 *color1, const PNGU_u8 *srcBlock) +{ + PNGU_u16 colors[4][4]; + PNGU_u32 res = 0; + int i; + + // Make the 4 colors available in the block + colors[0][0] = (color0[0] & 0xF8) | (color0[0] >> 5); + colors[0][1] = (color0[1] & 0xFC) | (color0[1] >> 6); + colors[0][2] = (color0[2] & 0xF8) | (color0[2] >> 5); + colors[1][0] = (color1[0] & 0xF8) | (color1[0] >> 5); + colors[1][1] = (color1[1] & 0xFC) | (color1[1] >> 6); + colors[1][2] = (color1[2] & 0xF8) | (color1[2] >> 5); + colors[2][0] = (2 * colors[0][0] + 1 * colors[1][0]) / 3; + colors[2][1] = (2 * colors[0][1] + 1 * colors[1][1]) / 3; + colors[2][2] = (2 * colors[0][2] + 1 * colors[1][2]) / 3; + colors[3][0] = (1 * colors[0][0] + 2 * colors[1][0]) / 3; + colors[3][1] = (1 * colors[0][1] + 2 * colors[1][1]) / 3; + colors[3][2] = (1 * colors[0][2] + 2 * colors[1][2]) / 3; + for (i = 15; i >= 0; --i) + { + int c0 = srcBlock[i * 4 + 0]; + int c1 = srcBlock[i * 4 + 1]; + int c2 = srcBlock[i * 4 + 2]; + int d0 = abs(colors[0][0] - c0) + abs(colors[0][1] - c1) + abs(colors[0][2] - c2); + int d1 = abs(colors[1][0] - c0) + abs(colors[1][1] - c1) + abs(colors[1][2] - c2); + int d2 = abs(colors[2][0] - c0) + abs(colors[2][1] - c1) + abs(colors[2][2] - c2); + int d3 = abs(colors[3][0] - c0) + abs(colors[3][1] - c1) + abs(colors[3][2] - c2); + int b0 = d0 > d3; + int b1 = d1 > d2; + int b2 = d0 > d2; + int b3 = d1 > d3; + int b4 = d2 > d3; + int x0 = b1 & b2; + int x1 = b0 & b3; + int x2 = b0 & b4; + res |= (x2 | ((x0 | x1) << 1)) << ((15 - i) << 1); + } + return res; +} + +int PNGU_DecodeToCMPR_Trim(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer) +{ + int result; + PNGU_u8 srcBlock[16 * 4]; + PNGU_u8 color0[4]; + PNGU_u8 color1[4]; + PNGU_u8 *outBuf = (PNGU_u8 *)buffer; + int ii; + int jj; + int k; + + //check for alpha channel + result = pngu_decode_add_alpha (ctx, width, height, 0, 1); + if (result != PNGU_OK) + return result; + + // trim down + width = width & ~7u; + height = height & ~7u; + + // Alpha channel present, copy image to the output buffer + for (jj = 0; jj < height; jj += 8) + for (ii = 0; ii < width; ii += 8) + for (k = 0; k < 4; ++k) + { + int j = jj + ((k >> 1) << 2); // jj + 0, jj + 0, jj + 4, jj + 4 + int i = ii + ((k & 1) << 2); // ii + 0, ii + 4, ii + 0, ii + 4 + memcpy(srcBlock, ctx->row_pointers[j] + i * 4, 16); + memcpy(srcBlock + 4 * 4, ctx->row_pointers[j + 1] + i * 4, 16); + memcpy(srcBlock + 8 * 4, ctx->row_pointers[j + 2] + i * 4, 16); + memcpy(srcBlock + 12 * 4, ctx->row_pointers[j + 3] + i * 4, 16); + getBaseColors(color0, color1, srcBlock); + *(PNGU_u16 *)outBuf = rgb8ToRGB565(color0); + outBuf += 2; + *(PNGU_u16 *)outBuf = rgb8ToRGB565(color1); + outBuf += 2; + *(PNGU_u32 *)outBuf = colorIndices(color0, color1, srcBlock); + outBuf += 4; + } + // Free resources + free (ctx->img_data); + free (ctx->row_pointers); + + // Success + return PNGU_OK; +} + + +// if width or height is not divisible by 8 +// then the remaining will be padded with last row/column +// buffer must be allocated with width and height rounded up + +int PNGU_DecodeToCMPR_Pad(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer) +{ + int result; + PNGU_u8 srcBlock[16 * 4]; + PNGU_u8 color0[4]; + PNGU_u8 color1[4]; + PNGU_u8 *outBuf = (PNGU_u8 *)buffer; + int ii; + int jj; + int k; + + //check for alpha channel + result = pngu_decode_add_alpha (ctx, width, height, 0, 1); + if (result != PNGU_OK) + return result; + + // Alpha channel present, copy image to the output buffer + for (jj = 0; jj < height; jj += 8) { + for (ii = 0; ii < width; ii += 8) { + for (k = 0; k < 4; ++k) { + // k(i,j) + // 0(0,0) 1(4,0) + // 2(4,0) 3(4,4) + int i = ii + ((k & 1) << 2); // ii + 0, ii + 4, ii + 0, ii + 4 + int j = jj + ((k >> 1) << 2); // jj + 0, jj + 0, jj + 4, jj + 4 + int ny; // 4 lines + int px = 4; // num columns to copy + if (i >= width) i = width - 1; + if (i + px > width) px = width - i; + for (ny=0; ny<4; ny++) { + if (j >= height) j = height - 1; + memcpy(srcBlock + ny * 4 * 4, + ctx->row_pointers[j] + i * 4, px * 4); + if (px < 4) { + // repeat last column (4-px) times + int x = width - 1; + int nx; + for (nx = px; nx < 4; nx++) { + memcpy(srcBlock + ny * 4 * 4 + nx * 4, + ctx->row_pointers[j] + x * 4, 4); + } + } + j++; + } + getBaseColors(color0, color1, srcBlock); + *(PNGU_u16 *)outBuf = rgb8ToRGB565(color0); + outBuf += 2; + *(PNGU_u16 *)outBuf = rgb8ToRGB565(color1); + outBuf += 2; + *(PNGU_u32 *)outBuf = colorIndices(color0, color1, srcBlock); + outBuf += 4; + } + } + } + // Free resources + free (ctx->img_data); + free (ctx->row_pointers); + + // Success + return PNGU_OK; +} + +void ExtractBlock( PNGU_u8 *inPtr, int y, int x, PNGU_u32 width, int i, PNGU_u8 colorBlock[] ) { + PNGU_u32 offset; + PNGU_u8 r, g, b, a; + + offset = (((y >> 2)<<4)*width) + ((x >> 2)<<6) + ((((y&3) << 2) + (x&3) ) << 1); + //offset = (((y >> 2) << 4)*width) + ((x >> 2) << 6) + (((y % 4 << 2) + x % 4) << 1); + //get rgba values based on the RGBA8 offsets + a = *(inPtr+offset); + r = *(inPtr+offset+1); + g = *(inPtr+offset+32); + b = *(inPtr+offset+33); + colorBlock[i*4] = r; + colorBlock[i*4+1] = g; + colorBlock[i*4+2] = b; + colorBlock[i*4+3] = a; + +} + +/** + * by usptactical + * Converts a 4x4 RGBA8 image to CMPR. + */ +int PNGU_4x4RGBA8_To_CMPR(void *buf_rgb, PNGU_u32 width, PNGU_u32 height, void *buf_cmpr) +{ + PNGU_u8 srcBlock[16 * 4]; + PNGU_u8 color0[4]; + PNGU_u8 color1[4]; + PNGU_u8 *outBuf = (PNGU_u8 *)buf_cmpr; + PNGU_u8 *rgba = (PNGU_u8 *)buf_rgb; + int jj, ii, i, j, k; + + width = width & ~7u; + height = height & ~7u; + + // loop over blocks + //CMPR needs 4x4 block of pixels: + //image row 0: 0, 1, 2, 3 (first 16 block) + //image row 1: 0, 1, 2, 3 (second 16 block) + //image row 2: 0, 1, 2, 3 (third 16 block) + //image row 3: 0, 1, 2, 3 (last 16 block) + + //image row 0: 4, 5, 6, 7 (first 16 block) + //image row 1: 4, 5, 6, 7 (second 16 block) + //image row 2: 4, 5, 6, 7 (third 16 block) + //image row 3: 4, 5, 6, 7 (last 16 block) + + //image row 4: 0, 1, 2, 3 (first 16 block) + //image row 5: 0, 1, 2, 3 (second 16 block) + //image row 6: 0, 1, 2, 3 (third 16 block) + //image row 7: 0, 1, 2, 3 (last 16 block) + + //image row 4: 4, 5, 6, 7 (first 16 block) + //image row 5: 4, 5, 6, 7 (second 16 block) + //image row 6: 4, 5, 6, 7 (third 16 block) + //image row 7: 4, 5, 6, 7 (last 16 block) + + for(jj = 0; jj < height; jj += 8) + for(ii = 0; ii < width; ii += 8) + for (k=0; k < 4; k++) + { + j = jj + ((k >> 1) << 2); // jj + 0, jj + 0, jj + 4, jj + 4 + i = ii + ((k & 1) << 2); // ii + 0, ii + 4, ii + 0, ii + 4 + + ExtractBlock(rgba, j, i, width, 0, srcBlock); + ExtractBlock(rgba, j, i+1, width, 1, srcBlock); + ExtractBlock(rgba, j, i+2, width, 2, srcBlock); + ExtractBlock(rgba, j, i+3, width, 3, srcBlock); + + ExtractBlock(rgba, j+1, i, width, 4, srcBlock); + ExtractBlock(rgba, j+1, i+1, width, 5, srcBlock); + ExtractBlock(rgba, j+1, i+2, width, 6, srcBlock); + ExtractBlock(rgba, j+1, i+3, width, 7, srcBlock); + + ExtractBlock(rgba, j+2, i, width, 8, srcBlock); + ExtractBlock(rgba, j+2, i+1, width, 9, srcBlock); + ExtractBlock(rgba, j+2, i+2, width, 10, srcBlock); + ExtractBlock(rgba, j+2, i+3, width, 11, srcBlock); + + ExtractBlock(rgba, j+3, i, width, 12, srcBlock); + ExtractBlock(rgba, j+3, i+1, width, 13, srcBlock); + ExtractBlock(rgba, j+3, i+2, width, 14, srcBlock); + ExtractBlock(rgba, j+3, i+3, width, 15, srcBlock); + + getBaseColors(color0, color1, srcBlock); + *(PNGU_u16 *)outBuf = rgb8ToRGB565(color0); + outBuf += 2; + *(PNGU_u16 *)outBuf = rgb8ToRGB565(color1); + outBuf += 2; + *(PNGU_u32 *)outBuf = colorIndices(color0, color1, srcBlock); + outBuf += 4; + } + // Success + return PNGU_OK; +} + +// if width or height is not divisible by 8 +// then the remaining will be padded with last row/column +// buffer must be allocated with width and height rounded up +int PNGU_RGBA8_To_CMPR(void *buf_rgb, PNGU_u32 width, PNGU_u32 height, void *buf_cmpr) +{ + PNGU_u8 srcBlock[16 * 4]; + PNGU_u8 color0[4]; + PNGU_u8 color1[4]; + PNGU_u8 *src, *block; + PNGU_u8 *cmpr = (PNGU_u8 *)buf_cmpr; + PNGU_u8 *rgba = (PNGU_u8 *)buf_rgb; + int jj, ii, i, j, k; + int x, y; // counter + int px, py; // pixel coord + + for(jj = 0; jj < height; jj += 8) { + for(ii = 0; ii < width; ii += 8) { + for (k=0; k < 4; k++) { + i = ii + ((k & 1) << 2); // ii + 0, ii + 4, ii + 0, ii + 4 + j = jj + ((k >> 1) << 2); // jj + 0, jj + 0, jj + 4, jj + 4 + + block = srcBlock; + for (y=0; y<4; y++) { + py = j + y; + if (py >= height) py = height - 1; + src = rgba + py * width * 4; + for (x=0; x<4; x++) { + px = i + x; + if (px >= width) px = width - 1; + memcpy(block, src + px * 4, 4); + block += 4; + } + } + + getBaseColors(color0, color1, srcBlock); + *(PNGU_u16 *)cmpr = rgb8ToRGB565(color0); + cmpr += 2; + *(PNGU_u16 *)cmpr = rgb8ToRGB565(color1); + cmpr += 2; + *(PNGU_u32 *)cmpr = colorIndices(color0, color1, srcBlock); + cmpr += 4; + } + } + } + // Success + return PNGU_OK; +} + + +/** + * added by usptactical + * handles png error messages + */ +void user_error (png_structp png_ptr, png_const_charp c) +{ + longjmp(png_jmpbuf(png_ptr), 1); +} + + + +//######################################################################################## +//---------- End CMPR added section ----------------------------------------------------- +//######################################################################################## + + +int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride) +{ + png_uint_32 rowbytes; + PNGU_u32 x, y, buffWidth; + + // Erase from the context any readed info + pngu_free_info (ctx); + ctx->propRead = 0; + + // Check if the user has selected a file to write the image + if (ctx->source == PNGU_SOURCE_BUFFER); + + else if (ctx->source == PNGU_SOURCE_DEVICE) + { + // Open file + if (!(ctx->fd = fopen (ctx->filename, "wb"))) + return PNGU_CANT_OPEN_FILE; + } + + else + return PNGU_NO_FILE_SELECTED; + + // Allocation of libpng structs + ctx->png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!(ctx->png_ptr)) + { + if (ctx->source == PNGU_SOURCE_DEVICE) + fclose (ctx->fd); + return PNGU_LIB_ERROR; + } + + ctx->info_ptr = png_create_info_struct (ctx->png_ptr); + if (!(ctx->info_ptr)) + { + png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL); + if (ctx->source == PNGU_SOURCE_DEVICE) + fclose (ctx->fd); + return PNGU_LIB_ERROR; + } + + if (ctx->source == PNGU_SOURCE_BUFFER) + { + // Installation of our custom data writer function + ctx->cursor = 0; + png_set_write_fn (ctx->png_ptr, ctx, pngu_write_data_to_buffer, pngu_flush_data_to_buffer); + } + else if (ctx->source == PNGU_SOURCE_DEVICE) + { + // Default data writer uses function fwrite, so it needs to use our FILE* + png_init_io (ctx->png_ptr, ctx->fd); + } + + // Setup output file properties + png_set_IHDR (ctx->png_ptr, ctx->info_ptr, width, height, 8, PNG_COLOR_TYPE_RGB, + PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + // Allocate memory to store the image in RGB format + rowbytes = width * 3; + if (rowbytes % 4) + rowbytes = ((rowbytes / 4) + 1) * 4; // Add extra padding so each row starts in a 4 byte boundary + + ctx->img_data = malloc (rowbytes * height); + if (!ctx->img_data) + { + png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL); + if (ctx->source == PNGU_SOURCE_DEVICE) + fclose (ctx->fd); + return PNGU_LIB_ERROR; + } + + ctx->row_pointers = malloc (sizeof (png_bytep) * height); + if (!ctx->row_pointers) + { + png_destroy_write_struct (&(ctx->png_ptr), (png_infopp)NULL); + if (ctx->source == PNGU_SOURCE_DEVICE) + fclose (ctx->fd); + return PNGU_LIB_ERROR; + } + + // Encode YCbYCr image into RGB8 format + buffWidth = (width + stride) / 2; + for (y = 0; y < height; y++) + { + ctx->row_pointers[y] = ctx->img_data + (y * rowbytes); + + for (x = 0; x < (width / 2); x++) + PNGU_YCbYCr_TO_RGB8 ( ((PNGU_u32 *)buffer)[y*buffWidth+x], + ((PNGU_u8 *) ctx->row_pointers[y]+x*6), ((PNGU_u8 *) ctx->row_pointers[y]+x*6+1), + ((PNGU_u8 *) ctx->row_pointers[y]+x*6+2), ((PNGU_u8 *) ctx->row_pointers[y]+x*6+3), + ((PNGU_u8 *) ctx->row_pointers[y]+x*6+4), ((PNGU_u8 *) ctx->row_pointers[y]+x*6+5) ); + } + + // Tell libpng where is our image data + png_set_rows (ctx->png_ptr, ctx->info_ptr, ctx->row_pointers); + + // Write file header and image data + png_write_png (ctx->png_ptr, ctx->info_ptr, PNG_TRANSFORM_IDENTITY, NULL); + + // Tell libpng we have no more data to write + png_write_end (ctx->png_ptr, (png_infop) NULL); + + // Free resources + free (ctx->img_data); + free (ctx->row_pointers); + png_destroy_write_struct (&(ctx->png_ptr), &(ctx->info_ptr)); + if (ctx->source == PNGU_SOURCE_DEVICE) + fclose (ctx->fd); + + // Success + return PNGU_OK; +} + + +// This function is taken from a libogc example +PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2) +{ + int y1, cb1, cr1, y2, cb2, cr2, cb, cr; + + y1 = (299 * r1 + 587 * g1 + 114 * b1) / 1000; + cb1 = (-16874 * r1 - 33126 * g1 + 50000 * b1 + 12800000) / 100000; + cr1 = (50000 * r1 - 41869 * g1 - 8131 * b1 + 12800000) / 100000; + + y2 = (299 * r2 + 587 * g2 + 114 * b2) / 1000; + cb2 = (-16874 * r2 - 33126 * g2 + 50000 * b2 + 12800000) / 100000; + cr2 = (50000 * r2 - 41869 * g2 - 8131 * b2 + 12800000) / 100000; + + cb = (cb1 + cb2) >> 1; + cr = (cr1 + cr2) >> 1; + + return (PNGU_u32) ((y1 << 24) | (cb << 16) | (y2 << 8) | cr); +} + + +void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2) +{ + PNGU_u8 *val = (PNGU_u8 *) &ycbycr; + int r, g, b; + + r = 1.371f * (val[3] - 128); + g = - 0.698f * (val[3] - 128) - 0.336f * (val[1] - 128); + b = 1.732f * (val[1] - 128); + + *r1 = pngu_clamp (val[0] + r, 0, 255); + *g1 = pngu_clamp (val[0] + g, 0, 255); + *b1 = pngu_clamp (val[0] + b, 0, 255); + + *r2 = pngu_clamp (val[2] + r, 0, 255); + *g2 = pngu_clamp (val[2] + g, 0, 255); + *b2 = pngu_clamp (val[2] + b, 0, 255); +} + + +int pngu_info (IMGCTX ctx) +{ + png_byte magic[8]; + png_uint_32 width; + png_uint_32 height; + png_color_16p background; + png_bytep trans; + png_color_16p trans_values; + int scale, i; + + // Check if there is a file selected and if it is a valid .png + if (ctx->source == PNGU_SOURCE_BUFFER) + memcpy (magic, ctx->buffer, 8); + + else if (ctx->source == PNGU_SOURCE_DEVICE) + { + // Open file + if (!(ctx->fd = fopen (ctx->filename, "rb"))) + return PNGU_CANT_OPEN_FILE; + + // Load first 8 bytes into magic buffer + if (fread (magic, 1, 8, ctx->fd) != 8) + { + fclose (ctx->fd); + return PNGU_CANT_READ_FILE; + } + } + + else + return PNGU_NO_FILE_SELECTED;; + + if (png_sig_cmp(magic, 0, 8) != 0) + { + if (ctx->source == PNGU_SOURCE_DEVICE) + fclose (ctx->fd); + return PNGU_FILE_IS_NOT_PNG; + } + + // Allocation of libpng structs + ctx->png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!(ctx->png_ptr)) + { + if (ctx->source == PNGU_SOURCE_DEVICE) + fclose (ctx->fd); + return PNGU_LIB_ERROR; + } + + ctx->info_ptr = png_create_info_struct (ctx->png_ptr); + if (!(ctx->info_ptr)) + { + if (ctx->source == PNGU_SOURCE_DEVICE) + fclose (ctx->fd); + png_destroy_read_struct (&(ctx->png_ptr), (png_infopp)NULL, (png_infopp)NULL); + return PNGU_LIB_ERROR; + } + + if (ctx->source == PNGU_SOURCE_BUFFER) + { + // Installation of our custom data provider function + ctx->cursor = 0; + png_set_read_fn (ctx->png_ptr, ctx, pngu_read_data_from_buffer); + } + else if (ctx->source == PNGU_SOURCE_DEVICE) + { + // Default data provider uses function fread, so it needs to use our FILE* + png_init_io (ctx->png_ptr, ctx->fd); + png_set_sig_bytes (ctx->png_ptr, 8); // We have read 8 bytes already to check PNG authenticity + } + + // Read png header + png_read_info (ctx->png_ptr, ctx->info_ptr); + + // Query image properties if they have not been queried before + if (!ctx->propRead) + { + png_get_IHDR(ctx->png_ptr, ctx->info_ptr, &width, &height, + (int *) &(ctx->prop.imgBitDepth), + (int *) &(ctx->prop.imgColorType), + NULL, NULL, NULL); + + ctx->prop.imgWidth = width; + ctx->prop.imgHeight = height; + switch (ctx->prop.imgColorType) + { + case PNG_COLOR_TYPE_GRAY: + ctx->prop.imgColorType = PNGU_COLOR_TYPE_GRAY; + break; + case PNG_COLOR_TYPE_GRAY_ALPHA: + ctx->prop.imgColorType = PNGU_COLOR_TYPE_GRAY_ALPHA; + break; + case PNG_COLOR_TYPE_PALETTE: + ctx->prop.imgColorType = PNGU_COLOR_TYPE_PALETTE; + break; + case PNG_COLOR_TYPE_RGB: + ctx->prop.imgColorType = PNGU_COLOR_TYPE_RGB; + break; + case PNG_COLOR_TYPE_RGB_ALPHA: + ctx->prop.imgColorType = PNGU_COLOR_TYPE_RGB_ALPHA; + break; + default: + ctx->prop.imgColorType = PNGU_COLOR_TYPE_UNKNOWN; + break; + } + + // Constant used to scale 16 bit values to 8 bit values + scale = 1; + if (ctx->prop.imgBitDepth == 16) + scale = 256; + + // Query background color, if any. + ctx->prop.validBckgrnd = 0; + if (((ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA)) && + (png_get_bKGD (ctx->png_ptr, ctx->info_ptr, &background))) + { + ctx->prop.validBckgrnd = 1; + ctx->prop.bckgrnd.r = background->red / scale; + ctx->prop.bckgrnd.g = background->green / scale; + ctx->prop.bckgrnd.b = background->blue / scale; + } + else if (((ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA)) && + (png_get_bKGD (ctx->png_ptr, ctx->info_ptr, &background))) + { + ctx->prop.validBckgrnd = 1; + ctx->prop.bckgrnd.r = ctx->prop.bckgrnd.g = ctx->prop.bckgrnd.b = background->gray / scale; + } + + // Query list of transparent colors, if any. + ctx->prop.numTrans = 0; + ctx->prop.trans = NULL; + if (((ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA)) && + (png_get_tRNS (ctx->png_ptr, ctx->info_ptr, &trans, (int *) &(ctx->prop.numTrans), &trans_values))) + { + if (ctx->prop.numTrans) + { + ctx->prop.trans = malloc (sizeof (PNGUCOLOR) * ctx->prop.numTrans); + if (ctx->prop.trans) + for (i = 0; i < ctx->prop.numTrans; i++) + { + ctx->prop.trans[i].r = trans_values[i].red / scale; + ctx->prop.trans[i].g = trans_values[i].green / scale; + ctx->prop.trans[i].b = trans_values[i].blue / scale; + } + else + ctx->prop.numTrans = 0; + } + } + else if (((ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA)) && + (png_get_tRNS (ctx->png_ptr, ctx->info_ptr, &trans, (int *) &(ctx->prop.numTrans), &trans_values))) + { + if (ctx->prop.numTrans) + { + ctx->prop.trans = malloc (sizeof (PNGUCOLOR) * ctx->prop.numTrans); + if (ctx->prop.trans) + for (i = 0; i < ctx->prop.numTrans; i++) + ctx->prop.trans[i].r = ctx->prop.trans[i].g = ctx->prop.trans[i].b = + trans_values[i].gray / scale; + else + ctx->prop.numTrans = 0; + } + } + + ctx->propRead = 1; + } + + // Success + ctx->infoRead = 1; + + return PNGU_OK; +} + + +int pngu_decode_add_alpha (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha, int force32bit) +{ + png_uint_32 rowbytes; + int i; + int chunk; + int rowsLeft; + png_bytep *curRow; + int mem_err = 0; + + + // Read info if it hasn't been read before + if (!ctx->infoRead) + { + i = pngu_info (ctx); + if (i != PNGU_OK) + return i; + } + + // Check if the user has specified the real width and height of the image + if ( (ctx->prop.imgWidth != width) || (ctx->prop.imgHeight != height) ) + return PNGU_INVALID_WIDTH_OR_HEIGHT; + + // Check if color type is supported by PNGU + if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_PALETTE) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_UNKNOWN) ) + return PNGU_UNSUPPORTED_COLOR_TYPE; + + //************************************************* + //* added by usptactical to catch corrupted pngs * + jmp_buf save_jmp; + memcpy(save_jmp, png_jmpbuf(ctx->png_ptr), sizeof(save_jmp)); + if (setjmp(png_jmpbuf(ctx->png_ptr))) { + error: + memcpy(png_jmpbuf(ctx->png_ptr), save_jmp, sizeof(save_jmp)); + SAFE_FREE(ctx->row_pointers); + SAFE_FREE(ctx->img_data); + pngu_free_info (ctx); + //printf("*** This is a corrupted image!!\n"); sleep(5); + return (mem_err)?PNGU_LIB_ERROR:-666; + } + //override default error handler to suppress warning messages from libpng + png_set_error_fn (ctx->png_ptr, NULL, user_error, user_error); + //************************************************* + + // Scale 16 bit samples to 8 bit + if (ctx->prop.imgBitDepth == 16) + png_set_strip_16 (ctx->png_ptr); + + // Remove alpha channel if we don't need it + if (stripAlpha && ((ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB_ALPHA) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA))) + png_set_strip_alpha (ctx->png_ptr); + + // Expand 1, 2 and 4 bit samples to 8 bit + if (ctx->prop.imgBitDepth < 8) + png_set_packing (ctx->png_ptr); + + // Transform grayscale images to RGB + if ( (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY) || (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY_ALPHA) ) + png_set_gray_to_rgb (ctx->png_ptr); + + // Transform RBG images to RGBA + if (force32bit && (ctx->prop.imgColorType == PNGU_COLOR_TYPE_GRAY || ctx->prop.imgColorType == PNGU_COLOR_TYPE_RGB)) + png_set_filler(ctx->png_ptr, 0xFF, PNG_FILLER_AFTER); + + // Flush transformations + png_read_update_info (ctx->png_ptr, ctx->info_ptr); + + // Allocate memory to store the image + rowbytes = png_get_rowbytes (ctx->png_ptr, ctx->info_ptr); + if (rowbytes % 4) + rowbytes = ((rowbytes / 4) + 1) * 4; // Add extra padding so each row starts in a 4 byte boundary + + ctx->img_data = malloc (rowbytes * ctx->prop.imgHeight); + if (!ctx->img_data) + { + //pngu_free_info (ctx); + //return PNGU_LIB_ERROR; + mem_err = 1; + goto error; + } + + ctx->row_pointers = malloc (sizeof (png_bytep) * ctx->prop.imgHeight); + if (!ctx->row_pointers) + { + //free (ctx->img_data); + //pngu_free_info (ctx); + //return PNGU_LIB_ERROR; + mem_err = 1; + goto error; + } + + for (i = 0; i < (int)ctx->prop.imgHeight; i++) + ctx->row_pointers[i] = ctx->img_data + (i * rowbytes); + + // Transform the image and copy it to our allocated memory + if (png_get_interlace_type(ctx->png_ptr, ctx->info_ptr) != PNG_INTERLACE_NONE) + png_read_image (ctx->png_ptr, ctx->row_pointers); + else + { + rowsLeft = ctx->prop.imgHeight; + curRow = ctx->row_pointers; + while (rowsLeft > 0) + { + chunk = rowsLeft > 0x80 ? 0x80 : rowsLeft; + png_read_rows(ctx->png_ptr, curRow, NULL, chunk); + //usleep(1000); + curRow += chunk; + rowsLeft -= chunk; + } + } + + // restore default error handling + memcpy(png_jmpbuf(ctx->png_ptr), save_jmp, sizeof(save_jmp)); + + // Free resources + pngu_free_info (ctx); + + // Success + return PNGU_OK; +} + +int pngu_decode (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha) +{ + return pngu_decode_add_alpha(ctx, width, height, stripAlpha, 0); +} + + +void pngu_free_info (IMGCTX ctx) +{ + if (ctx->infoRead) + { + if (ctx->source == PNGU_SOURCE_DEVICE) + fclose (ctx->fd); + + png_destroy_read_struct (&(ctx->png_ptr), &(ctx->info_ptr), (png_infopp)NULL); + + ctx->infoRead = 0; + } +} + + +// Custom data provider function used for reading from memory buffers. +void pngu_read_data_from_buffer (png_structp png_ptr, png_bytep data, png_size_t length) +{ + IMGCTX ctx = (IMGCTX) png_get_io_ptr (png_ptr); + if (ctx->buf_size && (ctx->cursor + length > ctx->buf_size)) + { + static char err_str[40]; + snprintf(err_str, sizeof(err_str), "read error (%x/%x)", + ctx->cursor + length, ctx->buf_size); + png_error(png_ptr, err_str); + } + memcpy (data, ctx->buffer + ctx->cursor, length); + ctx->cursor += length; +} + + +// Custom data writer function used for writing to memory buffers. +void pngu_write_data_to_buffer (png_structp png_ptr, png_bytep data, png_size_t length) +{ + IMGCTX ctx = (IMGCTX) png_get_io_ptr (png_ptr); + memcpy (ctx->buffer + ctx->cursor, data, length); + ctx->cursor += length; +} + + +// Custom data flusher function used for writing to memory buffers. +void pngu_flush_data_to_buffer (png_structp png_ptr) +{ + // Nothing to do here +} + + +// Function used in YCbYCr to RGB decoding +int pngu_clamp (int value, int min, int max) +{ + if (value < min) + value = min; + else if (value > max) + value = max; + + return value; +} + diff --git a/nand-loader/source/pngu.h b/nand-loader/source/pngu.h new file mode 100644 index 0000000..e979374 --- /dev/null +++ b/nand-loader/source/pngu.h @@ -0,0 +1,181 @@ +/******************************************************************************************** + +PNGU Version : 0.2a + +Coder : frontier + +More info : http://frontier-dev.net + +********************************************************************************************/ +#ifndef __PNGU__ +#define __PNGU__ + +// Return codes +#define PNGU_OK 0 +#define PNGU_ODD_WIDTH 1 +#define PNGU_ODD_STRIDE 2 +#define PNGU_INVALID_WIDTH_OR_HEIGHT 3 +#define PNGU_FILE_IS_NOT_PNG 4 +#define PNGU_UNSUPPORTED_COLOR_TYPE 5 +#define PNGU_NO_FILE_SELECTED 6 +#define PNGU_CANT_OPEN_FILE 7 +#define PNGU_CANT_READ_FILE 8 +#define PNGU_LIB_ERROR 9 + +// Color types +#define PNGU_COLOR_TYPE_GRAY 1 +#define PNGU_COLOR_TYPE_GRAY_ALPHA 2 +#define PNGU_COLOR_TYPE_PALETTE 3 +#define PNGU_COLOR_TYPE_RGB 4 +#define PNGU_COLOR_TYPE_RGB_ALPHA 5 +#define PNGU_COLOR_TYPE_UNKNOWN 6 + + +#ifdef __cplusplus + extern "C" { +#endif + +// Types +typedef unsigned char PNGU_u8; +typedef unsigned short PNGU_u16; +typedef unsigned int PNGU_u32; +typedef unsigned long long PNGU_u64; + +typedef struct +{ + PNGU_u8 r; + PNGU_u8 g; + PNGU_u8 b; +} PNGUCOLOR; + +typedef struct +{ + PNGU_u32 imgWidth; // In pixels + PNGU_u32 imgHeight; // In pixels + PNGU_u32 imgBitDepth; // In bitx + PNGU_u32 imgColorType; // PNGU_COLOR_TYPE_* + PNGU_u32 validBckgrnd; // Non zero if there is a background color + PNGUCOLOR bckgrnd; // Backgroun color + PNGU_u32 numTrans; // Number of transparent colors + PNGUCOLOR *trans; // Transparent colors +} PNGUPROP; + +// Image context, always initialize with SelectImageFrom* and free with ReleaseImageContext +struct _IMGCTX; +typedef struct _IMGCTX *IMGCTX; + + +/**************************************************************************** +* Pixel conversion * +****************************************************************************/ + +// Macro to convert RGB8 values to RGB565 +#define PNGU_RGB8_TO_RGB565(r,g,b) ( ((((PNGU_u16) r) & 0xF8U) << 8) | ((((PNGU_u16) g) & 0xFCU) << 3) | (((PNGU_u16) b) >> 3) ) + +// Macro to convert RGBA8 values to RGB5A3 +#define PNGU_RGB8_TO_RGB5A3(r,g,b,a) (PNGU_u16) (((a & 0xE0U) == 0xE0U) ? \ + (0x8000U | ((((PNGU_u16) r) & 0xF8U) << 7) | ((((PNGU_u16) g) & 0xF8U) << 2) | (((PNGU_u16) b) >> 3)) : \ + (((((PNGU_u16) a) & 0xE0U) << 7) | ((((PNGU_u16) r) & 0xF0U) << 4) | (((PNGU_u16) g) & 0xF0U) | ((((PNGU_u16) b) & 0xF0U) >> 4))) + +// Function to convert two RGB8 values to YCbYCr +PNGU_u32 PNGU_RGB8_TO_YCbYCr (PNGU_u8 r1, PNGU_u8 g1, PNGU_u8 b1, PNGU_u8 r2, PNGU_u8 g2, PNGU_u8 b2); + +// Function to convert an YCbYCr to two RGB8 values. +void PNGU_YCbYCr_TO_RGB8 (PNGU_u32 ycbycr, PNGU_u8 *r1, PNGU_u8 *g1, PNGU_u8 *b1, PNGU_u8 *r2, PNGU_u8 *g2, PNGU_u8 *b2); + + +/**************************************************************************** +* Image context handling * +****************************************************************************/ + +// Selects a PNG file, previosly loaded into a buffer, and creates an image context for subsequent procesing. +IMGCTX PNGU_SelectImageFromBuffer (const void *buffer); +IMGCTX PNGU_SelectImageFromBufferX (const void *buffer, int size); + +// Selects a PNG file, from any devoptab device, and creates an image context for subsequent procesing. +IMGCTX PNGU_SelectImageFromDevice (const char *filename); + +// Frees resources associated with an image context. Always call this function when you no longer need the IMGCTX. +void PNGU_ReleaseImageContext (IMGCTX ctx); + + +/**************************************************************************** +* Miscelaneous * +****************************************************************************/ + +// Retrieves info from selected PNG file, including image dimensions, color format, background and transparency colors. +int PNGU_GetImageProperties (IMGCTX ctx, PNGUPROP *fileproperties); + + +/**************************************************************************** +* Image conversion * +****************************************************************************/ + +// Expands selected image into an YCbYCr buffer. You need to specify context, image dimensions, +// destination address and stride in pixels (stride = buffer width - image width). +int PNGU_DecodeToYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride); + +// Macro for decoding an image inside a buffer at given coordinates. +#define PNGU_DECODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \ + \ + PNGU_DecodeToYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \ + (coordX) * 2, (bufferWidth) - (imgWidth)) + +// Expands selected image into a linear RGB565 buffer. You need to specify context, image dimensions, +// destination address and stride in pixels (stride = buffer width - image width). +int PNGU_DecodeToRGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride); + +// Macro for decoding an image inside a buffer at given coordinates. +#define PNGU_DECODE_TO_COORDS_RGB565(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \ + \ + PNGU_DecodeToRGB565 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \ + (coordX) * 2, (bufferWidth) - (imgWidth)) + +// Expands selected image into a linear RGBA8 buffer. You need to specify context, image dimensions, +// destination address, stride in pixels and default alpha value, which is used if the source image +// doesn't have an alpha channel. +int PNGU_DecodeToRGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride, PNGU_u8 default_alpha); + +// Macro for decoding an image inside a buffer at given coordinates. +#define PNGU_DECODE_TO_COORDS_RGBA8(ctx,coordX,coordY,imgWidth,imgHeight,default_alpha,bufferWidth,bufferHeight,buffer) \ + \ + PNGU_DecodeToRGBA8 (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 4 + \ + (coordX) * 4, (bufferWidth) - (imgWidth), default_alpha) + +// Expands selected image into a 4x4 tiled RGB565 buffer. You need to specify context, image dimensions +// and destination address. +int PNGU_DecodeTo4x4RGB565 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer); +// Compressed version (DXT1/CMPR) +int PNGU_DecodeToCMPR_Trim(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer); +int PNGU_DecodeToCMPR_Pad(IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer); +int PNGU_4x4RGBA8_To_CMPR(void *buf_rgb, PNGU_u32 width, PNGU_u32 height, void *buf_cmpr); +int PNGU_RGBA8_To_CMPR(void *buf_rgb, PNGU_u32 width, PNGU_u32 height, void *buf_cmpr); + +// Expands selected image into a 4x4 tiled RGB5A3 buffer. You need to specify context, image dimensions, +// destination address and default alpha value, which is used if the source image doesn't have an alpha channel. +int PNGU_DecodeTo4x4RGB5A3 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha); + +// Expands selected image into a 4x4 tiled RGBA8 buffer. You need to specify context, image dimensions, +// destination address and default alpha value, which is used if the source image doesn't have an alpha channel. +int PNGU_DecodeTo4x4RGBA8 (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u8 default_alpha); + +// Encodes an YCbYCr image in PNG format and stores it in the selected device or memory buffer. You need to +// specify context, image dimensions, destination address and stride in pixels (stride = buffer width - image width). +int PNGU_EncodeFromYCbYCr (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, void *buffer, PNGU_u32 stride); + +// Macro for encoding an image stored into an YCbYCr buffer at given coordinates. +#define PNGU_ENCODE_TO_COORDS_YCbYCr(ctx,coordX,coordY,imgWidth,imgHeight,bufferWidth,bufferHeight,buffer) \ + \ + PNGU_EncodeFromYCbYCr (ctx, imgWidth, imgHeight, ((void *) buffer) + (coordY) * (bufferWidth) * 2 + \ + (coordX) * 2, (bufferWidth) - (imgWidth)) + +PNGU_u8 * PNGU_DecodeTo4x4RGBA8_EX (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, int * dstWidth, int * dstHeight, PNGU_u8 *dstPtr); + +int PNGU_EncodeFromEFB (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stride); + +#ifdef __cplusplus + } +#endif + +#endif + diff --git a/nand-loader/source/pngu_impl.h b/nand-loader/source/pngu_impl.h new file mode 100644 index 0000000..782e94d --- /dev/null +++ b/nand-loader/source/pngu_impl.h @@ -0,0 +1,42 @@ +#ifndef __PNGU_I__ +#define __PNGU_I__ + +#include "png.h" + +// Constants +#define PNGU_SOURCE_BUFFER 1 +#define PNGU_SOURCE_DEVICE 2 + +// Prototypes of helper functions +int pngu_info (IMGCTX ctx); +int pngu_decode (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha); +int pngu_decode_add_alpha (IMGCTX ctx, PNGU_u32 width, PNGU_u32 height, PNGU_u32 stripAlpha, int force32bit); +void pngu_free_info (IMGCTX ctx); +void pngu_read_data_from_buffer (png_structp png_ptr, png_bytep data, png_size_t length); +void pngu_write_data_to_buffer (png_structp png_ptr, png_bytep data, png_size_t length); +void pngu_flush_data_to_buffer (png_structp png_ptr); +int pngu_clamp (int value, int min, int max); + + +// PNGU Image context struct +struct _IMGCTX +{ + int source; + void *buffer; + char *filename; + PNGU_u32 cursor; + PNGU_u32 buf_size; // buffer size + + PNGU_u32 propRead; + PNGUPROP prop; + + PNGU_u32 infoRead; + png_structp png_ptr; + png_infop info_ptr; + FILE *fd; + + png_bytep *row_pointers; + png_bytep img_data; +}; + +#endif diff --git a/nand-loader/source/stub.S b/nand-loader/source/stub.S new file mode 100644 index 0000000..756bf5a --- /dev/null +++ b/nand-loader/source/stub.S @@ -0,0 +1,118 @@ + .rodata + + .globl bgData +bgData: + .incbin "../data/background" + + .globl loadingImg +loadingImg: + .incbin "../data/loading" + + .globl errorImg +errorImg: + .incbin "../data/error" + + + +#include "asm.h" + + .text + .section .stub + + .extern _start + .globl _stub_start +_stub_start: + lis r3, 0x0011 + ori r3, r3, 0x0C64 + mtspr HID0, r3 + isync + + li r4, 0x2000 + mtmsr r4 + + ori r3, r3, 0xC000 + mtspr HID0, r3 + isync + + li r0, 0 + mtspr IBAT0U, r0 + mtspr IBAT1U, r0 + mtspr IBAT2U, r0 + mtspr IBAT3U, r0 + mtspr IBAT4U, r0 + mtspr IBAT5U, r0 + mtspr DBAT0U, r0 + mtspr DBAT1U, r0 + mtspr DBAT2U, r0 + mtspr DBAT3U, r0 + mtspr DBAT4U, r0 + mtspr DBAT5U, r0 + isync + + lis r0, 0x8000 + mtsr 0, r0 + mtsr 1, r0 + mtsr 2, r0 + mtsr 3, r0 + mtsr 4, r0 + mtsr 5, r0 + mtsr 6, r0 + mtsr 7, r0 + mtsr 8, r0 + mtsr 9, r0 + mtsr 10, r0 + mtsr 11, r0 + mtsr 12, r0 + mtsr 13, r0 + mtsr 14, r0 + mtsr 15, r0 + isync + + li r3, 2 + lis r4, 0x8000 + ori r4, r4, 0x1FFF + mtspr DBAT0L, r3 + mtspr DBAT0U, r4 + isync + mtspr IBAT0L, r3 + mtspr IBAT0U, r4 + isync + + addis r3, r3, 0x1000 + addis r4, r4, 0x1000 + mtspr DBAT4L, r3 + mtspr DBAT4U, r4 + isync + mtspr IBAT4L, r3 + mtspr IBAT4U, r4 + isync + + li r3, 0x2A + lis r4, 0xC000 + ori r4, r4, 0x1FFF + mtspr DBAT1L, r3 + mtspr DBAT1U, r4 + isync + mtspr IBAT1L, r3 + mtspr IBAT1U, r4 + isync + + addis r3, r3, 0x1000 + addis r4, r4, 0x1000 + mtspr DBAT2L, r3 + mtspr DBAT2U, r4 + isync + mtspr IBAT2L, r3 + mtspr IBAT2U, r4 + isync + + li r3, 0 + mfmsr r3 + ori r3, r3, MSR_DR|MSR_IR + mtsrr1 r3 + + lis r3, _start@h + ori r3, r3, _start@l + mtsrr0 r3 + + rfi diff --git a/nand-loader/source/sys.c b/nand-loader/source/sys.c new file mode 100644 index 0000000..8a9e54b --- /dev/null +++ b/nand-loader/source/sys.c @@ -0,0 +1,48 @@ +#include +#include +#include + +/* Constants */ +#define CERTS_LEN 0x280 + +/* Variables */ +static const char certs_fs[] ATTRIBUTE_ALIGN(32) = "/sys/cert.sys"; + + +void Sys_Init(void) +{ + /* Initialize video subsytem */ + VIDEO_Init(); +} + +void Sys_LoadMenu(void) +{ + /* Return to the Wii system menu */ + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); +} + +s32 Sys_GetCerts(signed_blob **certs, u32 *len) +{ + static signed_blob certificates[CERTS_LEN] ATTRIBUTE_ALIGN(32); + + s32 fd, ret; + + /* Open certificates file */ + fd = IOS_Open(certs_fs, 1); + if (fd < 0) + return fd; + + /* Read certificates */ + ret = IOS_Read(fd, certificates, sizeof(certificates)); + + /* Close file */ + IOS_Close(fd); + + /* Set values */ + if (ret > 0) { + *certs = certificates; + *len = sizeof(certificates); + } + + return ret; +} diff --git a/nand-loader/source/sys.h b/nand-loader/source/sys.h new file mode 100644 index 0000000..c1ac84c --- /dev/null +++ b/nand-loader/source/sys.h @@ -0,0 +1,9 @@ +#ifndef _SYS_H_ +#define _SYS_H_ + +/* Prototypes */ +void Sys_Init(void); +void Sys_LoadMenu(void); +s32 Sys_GetCerts(signed_blob **, u32 *); + +#endif diff --git a/nand-loader/source/title.c b/nand-loader/source/title.c new file mode 100644 index 0000000..0d05bd9 --- /dev/null +++ b/nand-loader/source/title.c @@ -0,0 +1,256 @@ +#include +#include +#include +#include +#include + +#include "utils.h" + + +s32 Title_GetList(u64 **outbuf, u32 *outlen) +{ + u64 *titles = NULL; + + u32 len, nb_titles; + s32 ret; + + /* Get number of titles */ + ret = ES_GetNumTitles(&nb_titles); + if (ret < 0) + return ret; + + /* Calculate buffer lenght */ + len = round_up(sizeof(u64) * nb_titles, 32); + + /* Allocate memory */ + titles = memalign(32, len); + if (!titles) + return -1; + + /* Get titles */ + ret = ES_GetTitles(titles, nb_titles); + if (ret < 0) + goto err; + + /* Set values */ + *outbuf = titles; + *outlen = nb_titles; + + return 0; + +err: + /* Free memory */ + if (titles) + free(titles); + + return ret; +} + +s32 Title_GetTicketViews(u64 tid, tikview **outbuf, u32 *outlen) +{ + tikview *views = NULL; + + u32 nb_views; + s32 ret; + + /* Get number of ticket views */ + ret = ES_GetNumTicketViews(tid, &nb_views); + if (ret < 0) + return ret; + + /* Allocate memory */ + views = (tikview *)memalign(32, sizeof(tikview) * nb_views); + if (!views) + return -1; + + /* Get ticket views */ + ret = ES_GetTicketViews(tid, views, nb_views); + if (ret < 0) + goto err; + + /* Set values */ + *outbuf = views; + *outlen = nb_views; + + return 0; + +err: + /* Free memory */ + if (views) + free(views); + + return ret; +} + +s32 Title_GetTMD(u64 tid, signed_blob **outbuf, u32 *outlen) +{ + void *p_tmd = NULL; + + u32 len; + s32 ret; + + /* Get TMD size */ + ret = ES_GetStoredTMDSize(tid, &len); + if (ret < 0) + return ret; + + /* Allocate memory */ + p_tmd = memalign(32, round_up(len, 32)); + if (!p_tmd) + return -1; + + /* Read TMD */ + ret = ES_GetStoredTMD(tid, p_tmd, len); + if (ret < 0) + goto err; + + /* Set values */ + *outbuf = p_tmd; + *outlen = len; + + return 0; + +err: + /* Free memory */ + if (p_tmd) + free(p_tmd); + + return ret; +} + +s32 Title_GetVersion(u64 tid, u16 *outbuf) +{ + signed_blob *p_tmd = NULL; + tmd *tmd_data = NULL; + + u32 len; + s32 ret; + + /* Get title TMD */ + ret = Title_GetTMD(tid, &p_tmd, &len); + if (ret < 0) + return ret; + + /* Retrieve TMD info */ + tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd); + + /* Set values */ + *outbuf = tmd_data->title_version; + + /* Free memory */ + free(p_tmd); + + return 0; +} + +s32 Title_GetSysVersion(u64 tid, u64 *outbuf) +{ + signed_blob *p_tmd = NULL; + tmd *tmd_data = NULL; + + u32 len; + s32 ret; + + /* Get title TMD */ + ret = Title_GetTMD(tid, &p_tmd, &len); + if (ret < 0) + return ret; + + /* Retrieve TMD info */ + tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd); + + /* Set values */ + *outbuf = tmd_data->sys_version; + + /* Free memory */ + free(p_tmd); + + return 0; +} + +s32 Title_GetSize(u64 tid, u32 *outbuf) +{ + signed_blob *p_tmd = NULL; + tmd *tmd_data = NULL; + + u32 cnt, len, size = 0; + s32 ret; + + /* Get title TMD */ + ret = Title_GetTMD(tid, &p_tmd, &len); + if (ret < 0) + return ret; + + /* Retrieve TMD info */ + tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd); + + /* Calculate title size */ + for (cnt = 0; cnt < tmd_data->num_contents; cnt++) { + tmd_content *content = &tmd_data->contents[cnt]; + + /* Add content size */ + size += content->size; + } + + /* Set values */ + *outbuf = size; + + /* Free memory */ + free(p_tmd); + + return 0; +} + +s32 Title_GetIOSVersions(u8 **outbuf, u32 *outlen) +{ + u8 *buffer = NULL; + u64 *list = NULL; + + u32 count, cnt, idx; + s32 ret; + + /* Get title list */ + ret = Title_GetList(&list, &count); + if (ret < 0) + return ret; + + /* Count IOS */ + for (cnt = idx = 0; idx < count; idx++) { + u32 tidh = (list[idx] >> 32); + u32 tidl = (list[idx] & 0xFFFFFFFF); + + /* Title is IOS */ + if ((tidh == 0x1) && (tidl >= 3) && (tidl <= 255)) + cnt++; + } + + /* Allocate memory */ + buffer = (u8 *)memalign(32, cnt); + if (!buffer) { + ret = -1; + goto out; + } + + /* Copy IOS */ + for (cnt = idx = 0; idx < count; idx++) { + u32 tidh = (list[idx] >> 32); + u32 tidl = (list[idx] & 0xFFFFFFFF); + + /* Title is IOS */ + if ((tidh == 0x1) && (tidl >= 3) && (tidl <= 255)) + buffer[cnt++] = (u8)(tidl & 0xFF); + } + + /* Set values */ + *outbuf = buffer; + *outlen = cnt; + + goto out; + +out: + /* Free memory */ + if (list) + free(list); + + return ret; +} diff --git a/nand-loader/source/title.h b/nand-loader/source/title.h new file mode 100644 index 0000000..5d1c573 --- /dev/null +++ b/nand-loader/source/title.h @@ -0,0 +1,16 @@ +#ifndef _TITLE_H_ +#define _TITLE_H_ + +/* Constants */ +#define BLOCK_SIZE 1024 + +/* Prototypes */ +s32 Title_GetList(u64 **, u32 *); +s32 Title_GetTicketViews(u64, tikview **, u32 *); +s32 Title_GetTMD(u64, signed_blob **, u32 *); +s32 Title_GetVersion(u64, u16 *); +s32 Title_GetSysVersion(u64, u64 *); +s32 Title_GetSize(u64, u32 *); +s32 Title_GetIOSVersions(u8 **, u32 *); + +#endif diff --git a/nand-loader/source/tools.c b/nand-loader/source/tools.c new file mode 100644 index 0000000..b9f8808 --- /dev/null +++ b/nand-loader/source/tools.c @@ -0,0 +1,252 @@ +/******************************************************************************* + * tools.c + * + * Copyright (c) 2009 The Lemon Man + * Copyright (c) 2009 Nicksasa + * Copyright (c) 2009 WiiPower + * + * Distributed under the terms of the GNU General Public License (v2) + * See http://www.gnu.org/licenses/gpl-2.0.txt for more info. + * + * Description: + * ----------- + * + ******************************************************************************/ + +#include +#include +#include +#include +#include +#include + +#include "tools.h" + +void printheadline() +{ + int rows, cols; + CON_GetMetrics(&cols, &rows); + + printf("TriiForce beta 7"); + + char buf[64]; + sprintf(buf, "IOS%u (Rev %u)\n", IOS_GetVersion(), IOS_GetRevision()); + printf("\x1B[%d;%dH", 0, cols-strlen(buf)-1); + printf(buf); +} + +void set_highlight(bool highlight) +{ + if (highlight) + { + printf("\x1b[%u;%um", 47, false); + printf("\x1b[%u;%um", 30, false); + } else + { + printf("\x1b[%u;%um", 37, false); + printf("\x1b[%u;%um", 40, false); + } +} + +void *allocate_memory(u32 size) +{ + return memalign(32, (size+31)&(~31) ); +} + +void Verify_Flags() +{ + if (Power_Flag) + { + WPAD_Shutdown(); + STM_ShutdownToStandby(); + } + if (Reset_Flag) + { + WPAD_Shutdown(); + STM_RebootSystem(); + } +} + + +void waitforbuttonpress(u32 *out, u32 *outGC) +{ + u32 pressed = 0; + u32 pressedGC = 0; + + while (true) + { + Verify_Flags(); + + WPAD_ScanPads(); + pressed = WPAD_ButtonsDown(0); + + PAD_ScanPads(); + pressedGC = PAD_ButtonsDown(0); + + if(pressed || pressedGC) + { + if (pressedGC) + { + // Without waiting you can't select anything + usleep (20000); + } + if (out) *out = pressed; + if (outGC) *outGC = pressedGC; + return; + } + } +} + + +s32 read_file(char *filepath, u8 **buffer, u32 *filesize) +{ + s32 Fd; + int ret; + + if (buffer == NULL) + { + printf("NULL Pointer\n"); + return -1; + } + + Fd = ISFS_Open(filepath, ISFS_OPEN_READ); + if (Fd < 0) + { + printf("ISFS_Open %s failed %d\n", filepath, Fd); + return Fd; + } + + fstats *status; + status = allocate_memory(sizeof(fstats)); + if (status == NULL) + { + printf("Out of memory for status\n"); + return -1; + } + + ret = ISFS_GetFileStats(Fd, status); + if (ret < 0) + { + printf("ISFS_GetFileStats failed %d\n", ret); + ISFS_Close(Fd); + free(status); + return -1; + } + + *buffer = allocate_memory(status->file_length); + if (*buffer == NULL) + { + printf("Out of memory for buffer\n"); + ISFS_Close(Fd); + free(status); + return -1; + } + + ret = ISFS_Read(Fd, *buffer, status->file_length); + if (ret < 0) + { + printf("ISFS_Read failed %d\n", ret); + ISFS_Close(Fd); + free(status); + free(*buffer); + return ret; + } + ISFS_Close(Fd); + + *filesize = status->file_length; + free(status); + + return 0; +} + +s32 identify(u64 titleid, u32 *ios) +{ + char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(0x20); + u8 *tmdBuffer = NULL; + u32 tmdSize; + u8 *tikBuffer = NULL; + u32 tikSize; + u8 *certBuffer = NULL; + u32 certSize; + + int ret; + + printf("Reading TMD..."); + fflush(stdout); + + sprintf(filepath, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(titleid), TITLE_LOWER(titleid)); + ret = read_file(filepath, &tmdBuffer, &tmdSize); + if (ret < 0) + { + printf("Reading TMD failed\n"); + return ret; + } + printf("done\n"); + + *ios = (u32)(tmdBuffer[0x18b]); + + printf("Reading ticket..."); + fflush(stdout); + + sprintf(filepath, "/ticket/%08x/%08x.tik", TITLE_UPPER(titleid), TITLE_LOWER(titleid)); + ret = read_file(filepath, &tikBuffer, &tikSize); + if (ret < 0) + { + printf("Reading ticket failed\n"); + free(tmdBuffer); + return ret; + } + printf("done\n"); + + printf("Reading certs..."); + fflush(stdout); + + sprintf(filepath, "/sys/cert.sys"); + ret = read_file(filepath, &certBuffer, &certSize); + if (ret < 0) + { + printf("Reading certs failed\n"); + free(tmdBuffer); + free(tikBuffer); + return ret; + } + printf("done\n"); + + printf("ES_Identify..."); + fflush(stdout); + + ret = ES_Identify((signed_blob*)certBuffer, certSize, (signed_blob*)tmdBuffer, tmdSize, (signed_blob*)tikBuffer, tikSize, NULL); + if (ret < 0) + { + switch(ret) + { + case ES_EINVAL: + printf("Error! ES_Identify (ret = %d;) Data invalid!\n", ret); + break; + case ES_EALIGN: + printf("Error! ES_Identify (ret = %d;) Data not aligned!\n", ret); + break; + case ES_ENOTINIT: + printf("Error! ES_Identify (ret = %d;) ES not initialized!\n", ret); + break; + case ES_ENOMEM: + printf("Error! ES_Identify (ret = %d;) No memory!\n", ret); + break; + default: + printf("Error! ES_Identify (ret = %d)\n", ret); + break; + } + free(tmdBuffer); + free(tikBuffer); + free(certBuffer); + return ret; + } + printf("done\n"); + + free(tmdBuffer); + free(tikBuffer); + free(certBuffer); + return 0; +} + + diff --git a/nand-loader/source/tools.h b/nand-loader/source/tools.h new file mode 100644 index 0000000..b7532cc --- /dev/null +++ b/nand-loader/source/tools.h @@ -0,0 +1,31 @@ +/******************************************************************************* + * tools.h + * + * Copyright (c) 2009 The Lemon Man + * Copyright (c) 2009 Nicksasa + * Copyright (c) 2009 WiiPower + * + * Distributed under the terms of the GNU General Public License (v2) + * See http://www.gnu.org/licenses/gpl-2.0.txt for more info. + * + * Description: + * ----------- + * + ******************************************************************************/ + +#define TITLE_UPPER(x) ((u32)((x) >> 32)) +#define TITLE_LOWER(x) ((u32)(x)) +#define TITLE_ID(x,y) (((u64)(x) << 32) | (y)) + +bool Power_Flag; +bool Reset_Flag; + +void *allocate_memory(u32 size); +s32 read_file(char *filepath, u8 **buffer, u32 *filesize); +s32 identify(u64 titleid, u32 *ios); +void set_highlight(bool highlight); +void waitforbuttonpress(u32 *out, u32 *outGC); +void printheadline(); + + + diff --git a/nand-loader/source/utils.h b/nand-loader/source/utils.h new file mode 100644 index 0000000..3a4862b --- /dev/null +++ b/nand-loader/source/utils.h @@ -0,0 +1,15 @@ +#ifndef _UTILS_H_ +#define _UTILS_H_ + +/* Constants */ +#define KB_SIZE 1024.0 +#define MB_SIZE 1048576.0 +#define GB_SIZE 1073741824.0 + +/* Macros */ +#define round_up(x,n) (-(-(x) & -(n))) + +/* Prototypes */ +u32 swap32(u32); + +#endif diff --git a/nand-loader/source/video.c b/nand-loader/source/video.c new file mode 100644 index 0000000..05ccd83 --- /dev/null +++ b/nand-loader/source/video.c @@ -0,0 +1,147 @@ +#include +#include + +#include "sys.h" +#include "video.h" + +/* Video variables */ +static void *framebuffer = NULL; +static GXRModeObj *vmode = NULL; + + +void Con_Init(u32 x, u32 y, u32 w, u32 h) +{ + /* Create console in the framebuffer */ + CON_InitEx(vmode, x, y, w, h); +} + +void Con_Destroy(void) +{ + /* Destroy console */ + VIDEO_SetPostRetraceCallback(NULL); +} + +void Con_Clear(void) +{ + /* Clear console */ + printf("\x1b[2J"); + fflush(stdout); +} + +void Con_ClearLine(void) +{ + s32 cols, rows; + u32 cnt; + + printf("\r"); + fflush(stdout); + + /* Get console metrics */ + CON_GetMetrics(&cols, &rows); + + /* Erase line */ + for (cnt = 1; cnt < cols; cnt++) { + printf(" "); + fflush(stdout); + } + + printf("\r"); + fflush(stdout); +} + +void Con_FgColor(u32 color, u8 bold) +{ + /* Set foreground color */ + printf("\x1b[%u;%um", color + 30, bold); + fflush(stdout); +} + +void Con_BgColor(u32 color, u8 bold) +{ + /* Set background color */ + printf("\x1b[%u;%um", color + 40, bold); + fflush(stdout); +} + +void Con_FillRow(u32 row, u32 color, u8 bold) +{ + s32 cols, rows; + u32 cnt; + + /* Set color */ + printf("\x1b[%u;%um", color + 40, bold); + fflush(stdout); + + /* Get console metrics */ + CON_GetMetrics(&cols, &rows); + + /* Save current row and col */ + printf("\x1b[s"); + fflush(stdout); + + /* Move to specified row */ + printf("\x1b[%u;0H", row); + fflush(stdout); + + /* Fill row */ + for (cnt = 0; cnt < cols; cnt++) { + printf(" "); + fflush(stdout); + } + + /* Load saved row and col */ + printf("\x1b[u"); + fflush(stdout); + + /* Set default color */ + Con_BgColor(0, 0); + Con_FgColor(7, 1); +} + +void Video_Configure(GXRModeObj *rmode) +{ + /* Configure the video subsystem */ + VIDEO_Configure(rmode); + + /* Setup video */ + VIDEO_SetBlack(FALSE); + VIDEO_Flush(); + VIDEO_WaitVSync(); + + if (rmode->viTVMode & VI_NON_INTERLACE) + VIDEO_WaitVSync(); +} + +void Video_SetMode(void) +{ + /* Select preferred video mode */ + vmode = VIDEO_GetPreferredMode(NULL); + + /* Allocate memory for the framebuffer */ + framebuffer = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); + + /* Configure the video subsystem */ + VIDEO_Configure(vmode); + + /* Setup video */ + VIDEO_SetNextFramebuffer(framebuffer); + VIDEO_SetBlack(FALSE); + VIDEO_Flush(); + VIDEO_WaitVSync(); + + if (vmode->viTVMode & VI_NON_INTERLACE) + VIDEO_WaitVSync(); + + /* Clear the screen */ + Video_Clear(COLOR_BLACK); +} + +void Video_Clear(s32 color) +{ + VIDEO_ClearFrameBuffer(vmode, framebuffer, color); +} + +void Video_DrawPng(IMGCTX ctx, PNGUPROP imgProp, u16 x, u16 y) +{ + PNGU_DECODE_TO_COORDS_YCbYCr(ctx, x, y, imgProp.imgWidth, imgProp.imgHeight, vmode->fbWidth, vmode->xfbHeight, framebuffer); +} diff --git a/nand-loader/source/video.h b/nand-loader/source/video.h new file mode 100644 index 0000000..87c2fa9 --- /dev/null +++ b/nand-loader/source/video.h @@ -0,0 +1,20 @@ +#ifndef _VIDEO_H_ +#define _VIDEO_H_ + +#include "pngu.h" + +/* Prototypes */ +void Con_Init(u32, u32, u32, u32); +void Con_Destroy(void); +void Con_Clear(void); +void Con_ClearLine(void); +void Con_FgColor(u32, u8); +void Con_BgColor(u32, u8); +void Con_FillRow(u32, u32, u8); + +void Video_Configure(GXRModeObj *); +void Video_SetMode(void); +void Video_Clear(s32); +void Video_DrawPng(IMGCTX, PNGUPROP, u16, u16); + +#endif diff --git a/nand-loader/source/wpad.c b/nand-loader/source/wpad.c new file mode 100644 index 0000000..8894fbb --- /dev/null +++ b/nand-loader/source/wpad.c @@ -0,0 +1,60 @@ +#include +#include + +#include "sys.h" +#include "wpad.h" + +/* Constants */ +#define MAX_WIIMOTES 4 + + +s32 Wpad_Init(void) +{ + s32 ret; + + /* Initialize Wiimote subsystem */ + ret = WPAD_Init(); + if (ret < 0) + return ret; + + return ret; +} + +void Wpad_Disconnect(void) +{ + u32 cnt; + + /* Disconnect Wiimotes */ + for (cnt = 0; cnt < MAX_WIIMOTES; cnt++) + WPAD_Disconnect(cnt); + + /* Shutdown Wiimote subsystem */ + WPAD_Shutdown(); +} + +u32 Wpad_GetButtons(void) +{ + u32 buttons = 0, cnt; + + /* Scan pads */ + WPAD_ScanPads(); + + /* Get pressed buttons */ + for (cnt = 0; cnt < MAX_WIIMOTES; cnt++) + buttons |= WPAD_ButtonsDown(cnt); + + return buttons; +} + +u32 Wpad_WaitButtons(void) +{ + u32 buttons = 0; + + /* Wait for button pressing */ + while (!buttons) { + buttons = Wpad_GetButtons(); + VIDEO_WaitVSync(); + } + + return buttons; +} diff --git a/nand-loader/source/wpad.h b/nand-loader/source/wpad.h new file mode 100644 index 0000000..63053bb --- /dev/null +++ b/nand-loader/source/wpad.h @@ -0,0 +1,12 @@ +#ifndef _WPAD_H_ +#define _WPAD_H_ + +#include + +/* Prototypes */ +s32 Wpad_Init(void); +void Wpad_Disconnect(void); +u32 Wpad_GetButtons(void); +u32 Wpad_WaitButtons(void); + +#endif diff --git a/nand-loader/stub/Makefile b/nand-loader/stub/Makefile deleted file mode 100644 index 78d4683..0000000 --- a/nand-loader/stub/Makefile +++ /dev/null @@ -1,42 +0,0 @@ - -PREFIX = powerpc-eabi- - -AR = $(PREFIX)ar -AS = $(PREFIX)as -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -LD = $(PREFIX)ld -OBJCOPY = $(PREFIX)objcopy -RANLIB = $(PREFIX)ranlib -STRIP = $(PREFIX)strip - -MACHDEP = -mcpu=750 -mno-eabi -mhard-float -LDFLAGS = $(MACHDEP) -n -nostartfiles -nostdlib -Wl,-T,openstub.ld -L. -ASFLAGS = -D_LANGUAGE_ASSEMBLY -DHW_RVL - -TARGET_LINKED = stub.elf -TARGET = stub.bin -OBJS = crt0.o - -DEPDIR = .deps - -all: $(TARGET) - -%.o: %.s - @echo " ASSEMBLE $<" - @$(CC) $(ASFLAGS) -c $< -o $@ - -%.o: %.S - @echo " ASSEMBLE $<" - @$(CC) $(ASFLAGS) -c $< -o $@ - -$(TARGET_LINKED): $(OBJS) - @echo " LINK $@" - @$(CC) -g -o $@ $(LDFLAGS) $(OBJS) - -$(TARGET): $(TARGET_LINKED) - @echo " OBJCOPY $@" - @$(OBJCOPY) -O binary $< $@ - -clean: - rm -rf $(TARGET_LINKED) $(TARGET) $(OBJS) $(DEPDIR) diff --git a/nand-loader/stub/crt0.S b/nand-loader/stub/crt0.S deleted file mode 100644 index 635b6e0..0000000 --- a/nand-loader/stub/crt0.S +++ /dev/null @@ -1,123 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt - -# This code comes from the Twilight Hack -# Copyright 2008-2009 Segher Boessenkool - -# Slightly modified to imitate the homebrew channel stub - -*/ -.set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4; -.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9; -.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14; -.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19; -.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24; -.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29; -.set r30,30; .set r31,31; - -#include "hw.h" - - .globl _start -_start: - mfmsr r3 - rlwinm r4,r3,0,17,15 # MSR_EE - rlwinm r4,r4,0,26,24 # MSR_IP - mtmsr r4 - isync - lis r3,_setup@h - ori r3,r3,_setup@l - clrlwi r3,r3,2 - mtsrr0 r3 - mfmsr r3 - li r4,MSR_IR|MSR_DR - andc r3,r3,r4 - mtsrr1 r3 - rfi - -#0001 0001 0000 1100 0110 0100 -#BHT,BTIC,DCFA,DCFI,ICFI,NHR,DPM -_setup: - lis r3,0x11 - ori r3,r3,0xC64 #0x110C64 - mtspr rHID0,r3 - isync - li r4,MSR_FP - mtmsr r4 - ori r3,r3,HID0_ICE|HID0_DCE - mtspr rHID0,r3 - isync - li r0,0 - mtibatu 0,r0 - mtibatu 1,r0 - mtibatu 2,r0 - mtibatu 3,r0 - mtdbatu 0,r0 - mtdbatu 1,r0 - mtdbatu 2,r0 - mtdbatu 3,r0 - #mtibatl 0,r0 - mtspr 560,r0 - mtspr 562,r0 - mtspr 564,r0 - mtspr 566,r0 - mtspr 568,r0 - mtspr 570,r0 - mtspr 572,r0 - mtspr 574,r0 - isync - lis r0,0x8000 - mtsr 0,r0 - mtsr 1,r0 - mtsr 2,r0 - mtsr 3,r0 - mtsr 4,r0 - mtsr 5,r0 - mtsr 6,r0 - mtsr 7,r0 - mtsr 8,r0 - mtsr 9,r0 - mtsr 10,r0 - mtsr 11,r0 - mtsr 12,r0 - mtsr 13,r0 - mtsr 14,r0 - mtsr 15,r0 - isync - li r3,2 #0x00000000|PP=2 - lis r4,0x8000 - ori r4,r4,0x1FFF #0x80000000|256Mbytes|VS|VP - mtibatl 0,r3 - mtibatu 0,r4 - mtdbatl 0,r3 - mtdbatu 0,r4 - isync - addis r3,r3,0x1000 #0x10000000|PP=2 - addis r4,r4,0x1000 #0x90000000|256Mbytes|VS|VP - mtspr 561,r3 - mtspr 560,r4 - mtspr 569,r3 - mtspr 568,r4 - isync - li r3,0x2A #0x00000000|I|G|PP=2 - lis r4,0xC000 - ori r4,r4,0x1FFF #0xC0000000|256Mbytes|VS|VP - mtdbatu 1,r3 - mtdbatu 1,r4 - isync - addis r3,r3,0x1000 #0x10000000|I|G|PP=2 - addis r4,r4,0x1000 #0xD0000000|256Mbytes|VS|VP - mtspr 571,r3 - mtspr 570,r4 - isync - lis r3,0x8200 - mtspr 1011,r3 - lis r3,0x8000 - ori r3,r3,0x4000 - mtsrr0 r3 - mfmsr r3 - ori r3,r3,MSR_DR|MSR_IR - mtsrr1 r3 - rfi diff --git a/nand-loader/stub/hw.h b/nand-loader/stub/hw.h deleted file mode 100644 index f4486ba..0000000 --- a/nand-loader/stub/hw.h +++ /dev/null @@ -1,107 +0,0 @@ -#ifndef __HW_H__ -#define __HW_H__ - -#define MSR_POW (1<<18) -#define MSR_ILE (1<<16) -#define MSR_EE (1<<15) -#define MSR_PR (1<<14) -#define MSR_FP (1<<13) -#define MSR_ME (1<<12) -#define MSR_FE0 (1<<11) -#define MSR_SE (1<<10) -#define MSR_BE (1<< 9) -#define MSR_FE1 (1<< 8) -#define MSR_IP (1<< 6) -#define MSR_IR (1<< 5) -#define MSR_DR (1<< 4) -#define MSR_RI (1<< 1) -#define MSR_LE (1<< 0) - -#define HID0_EMCP (1<<31) -#define HID0_DBP (1<<30) -#define HID0_EBA (1<<29) -#define HID0_EBD (1<<28) -#define HID0_BCLK (1<<27) -#define HID0_ECLK (1<<25) -#define HID0_PAR (1<<24) -#define HID0_DOZE (1<<23) -#define HID0_NAP (1<<22) -#define HID0_SLEEP (1<<21) -#define HID0_DPM (1<<20) -#define HID0_NHR (1<<16) -#define HID0_ICE (1<<15) -#define HID0_DCE (1<<14) -#define HID0_ILOCK (1<<13) -#define HID0_DLOCK (1<<12) -#define HID0_ICFI (1<<11) -#define HID0_DCFI (1<<10) -#define HID0_SPD (1<< 9) -#define HID0_IFEM (1<< 8) -#define HID0_SGE (1<< 7) -#define HID0_DCFA (1<< 6) -#define HID0_BTIC (1<< 5) -#define HID0_ABE (1<< 3) -#define HID0_BHT (1<< 2) -#define HID0_NOOPTI (1<< 0) - -#define HID2_LSQE (1<<31) -#define HID2_WPE (1<<30) -#define HID2_PSE (1<<29) -#define HID2_LCE (1<<28) - -#define L2CR_L2E (1<<31) -#define L2CR_L2CE (1<<30) -#define L2CR_L2DO (1<<22) -#define L2CR_L2I (1<<21) -#define L2CR_L2WT (1<<19) -#define L2CR_L2TS (1<<18) -#define L2CR_L2IP (1<< 0) - -#define DMAU_MEM_ADDR_MASK 0xFFFFFFE0 -#define DMAU_LENU(x) (x & 0x1F) -#define DMAL_LC_ADDR_MASK 0xFFFFFFE0 -#define DMAL_LD (1<< 4) -#define DMAL_LENL(x) (x & 0xC) -#define DMAL_T (1<< 1) -#define DMAL_F (1<< 0) - -#define BATU_BEPI_MASK 0xFFFC0000 -#define BATU_BL(x) (x & 0x00001FFC) -#define BATU_VS (1<< 1) -#define BATU_VP (1<< 0) -#define BATL_BRPN_MASK 0xFFFC0000 -#define BATL_WIMG_MASK 0x78 -#define BATL_PP (1<< 0) - -// BATU - 0x80001FFF == 256Mbytes -// 1000 0000 000x xxx0 0001 1111 1111 11xx -// 0x80000000|256Mbytes|VS|VP -// BATL - 0x00000002 -// 0000 0000 0000 000x xxxx xxxx x000 0x10 -// PP=b10 -// -// BATU - 0xC0001FFF == 256Mbytes -// BATL - 0x0000002a -// 0000 0000 0000 000x xxxx xxxx x010 1x10 -// WIMG=b0101|PP=b10 -// - -#define rHID2 920 -#define rDMAU 922 -#define rDMAL 923 -#define rHID0 1008 -#define rHID1 1009 -#define rHID4 1011 - -/* - * Upper PTE - * 0|1-24|25|26-31 - * V|VSID|H |API - * - * Lower PTE - * 0-19|20-22|23|24|25-28|29|30-31 - * RPN |000 |R |C |WIMG |0 |PP -*/ - -#endif - diff --git a/nand-loader/stub/openstub.ld b/nand-loader/stub/openstub.ld deleted file mode 100644 index fd3fc8b..0000000 --- a/nand-loader/stub/openstub.ld +++ /dev/null @@ -1,19 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -OUTPUT_FORMAT("elf32-powerpc") -OUTPUT_ARCH(powerpc:common) - -ENTRY(_start) - -PHDRS { - app PT_LOAD FLAGS(7); -} - -SECTIONS { - .text : { *(.text) *(.text.*) } :app -} diff --git a/nand-loader/types.h b/nand-loader/types.h deleted file mode 100644 index ea71e6e..0000000 --- a/nand-loader/types.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -// Copyright 2008-2009 Hector Martin - -#ifndef __TYPES_H__ -#define __TYPES_H__ - -typedef unsigned char u8; -typedef unsigned short u16; -typedef unsigned int u32; -typedef unsigned long long u64; -typedef char s8; -typedef short s16; -typedef int s32; -typedef long long s64; - -typedef volatile unsigned char vu8; -typedef volatile unsigned short vu16; -typedef volatile unsigned int vu32; -typedef volatile unsigned long long vu64; - -#define NULL ((void *)0) - -#define ALIGNED(n) __attribute__((aligned(n))) - -#endif - diff --git a/nand-loader/utils.c b/nand-loader/utils.c deleted file mode 100644 index 940cec6..0000000 --- a/nand-loader/utils.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -/* This code comes from HBC's stub which was based on geckoloader and the Twilight Hack code */ -/* Some of these routines are from public domain sources */ -// Copyright 2008-2009 Segher Boessenkool -// Copyright 2008-2009 Andre Heider -// Copyright 2008-2009 Hector Martin - -#include "types.h" -#include "utils.h" - -static u32 -get_time(void) -{ - u32 x; - - asm volatile("mftb %0" : "=r"(x)); - - return x; -} - -void -usleep(u32 us) -{ - u32 _start = get_time(); - while ((get_time() - _start) < (91*us)) ; -} - diff --git a/nand-loader/utils.h b/nand-loader/utils.h deleted file mode 100644 index 9424a26..0000000 --- a/nand-loader/utils.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - TinyLoad - a simple region free (original) game launcher in 4k - -# This code is licensed to you under the terms of the GNU GPL, version 2; -# see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt -*/ - -// Copyright 2008-2009 Hector Martin - -#ifndef __UTILS_H__ -#define __UTILS_H__ - -#include "types.h" - -void usleep(u32 us); - -#endif