summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRevo <projectrevotpp@hotmail.com>2020-07-18 14:40:21 -0400
committerGitHub <noreply@github.com>2020-07-18 14:40:21 -0400
commit453ccaf11724bb7e96f0e12e4520161f52056520 (patch)
tree2fe773190862655e5109618798618bed10152893
parentca9a7a58bceec9afe84138f4c9e8ad5cc782d3a6 (diff)
parentfbd71239b903711e84f325f78f5bab89bc9629db (diff)
Merge pull request #240 from red031000/master
nitrogfx support for scanned images, arm9 OS_exception, some more images
-rw-r--r--Makefile6
-rw-r--r--arm9/asm/OS_exception.s172
-rw-r--r--arm9/lib/include/OS_exception.h26
-rw-r--r--arm9/lib/include/OS_init.h1
-rw-r--r--arm9/lib/include/mmap.h2
-rw-r--r--arm9/lib/src/OS_exception.c158
-rw-r--r--arm9/lib/src/OS_init.c1
-rw-r--r--files/.gitattributes1
-rw-r--r--files/itemtool/itemdata/item_icon/.gitignore21
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0119.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0119.pngbin0 -> 332 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0120.NCLRbin552 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0121.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0121.pngbin0 -> 309 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0122.NCLRbin552 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0123.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0123.pngbin0 -> 309 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0124.NCLRbin552 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0125.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0125.pngbin0 -> 329 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0126.NCLRbin552 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0127.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0127.pngbin0 -> 227 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0128.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0128.pngbin0 -> 270 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0129.NCLRbin552 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0129.pal19
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0130.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0130.pngbin0 -> 225 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0131.NCLRbin552 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0131.pal19
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0132.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0132.pngbin0 -> 272 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0133.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0133.pngbin0 -> 288 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0134.NCLRbin552 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0134.pal19
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0135.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0135.pngbin0 -> 239 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0136.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0136.pngbin0 -> 237 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0137.NCLRbin552 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0138.NCGRbin560 -> 0 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0138.pngbin0 -> 246 bytes
-rw-r--r--files/itemtool/itemdata/item_icon/narc_0139.NCLRbin552 -> 0 bytes
-rw-r--r--files/poketool/trgra/trbgra/.gitignore2
-rw-r--r--files/poketool/trgra/trbgra/.knarcignore1
-rw-r--r--files/poketool/trgra/trbgra/narc_0000.NCGRbin6448 -> 0 bytes
-rw-r--r--files/poketool/trgra/trbgra/narc_0000.pngbin0 -> 1560 bytes
-rw-r--r--files/poketool/trgra/trbgra/narc_0000.png.key1
-rw-r--r--files/poketool/trgra/trbgra/narc_0001.NCLRbin72 -> 0 bytes
-rw-r--r--filesystem.mk27
-rw-r--r--graphics_rules.mk45
-rw-r--r--tools/nitrogfx/gfx.c129
-rw-r--r--tools/nitrogfx/gfx.h4
-rw-r--r--tools/nitrogfx/main.c52
-rw-r--r--tools/nitrogfx/options.h1
57 files changed, 508 insertions, 199 deletions
diff --git a/Makefile b/Makefile
index 07235c57..f0fc0cb1 100644
--- a/Makefile
+++ b/Makefile
@@ -260,6 +260,9 @@ $(VERSION101_SOPC_8BPP_NCGR_FILES): %.NCGR: %.png
$(VERSION101_SOPC_NCGR_FILES): %.NCGR: %.png
$(GFX) $< $@ -version101 -sopc
+$(SCANNED_NCGR_FILES): %.NCGR: %.png
+ $(GFX) $< $@ -scanned
+
%.NCLR: %.png
$(GFX) $< $@
@@ -272,6 +275,9 @@ $(IR_NCLR_FILES): %.NCLR: %.pal
$(4BPP_NCLR_FILES): %.NCLR: %.pal
$(GFX) $< $@ -bitdepth 4
+$(8BPP_COMP10_NOPAD_NCLR_FILES): %.NCLR: %.png
+ $(GFX) $< $@ -bitdepth 8 -nopad -comp 10
+
%.png: ;
%.pal: ;
diff --git a/arm9/asm/OS_exception.s b/arm9/asm/OS_exception.s
deleted file mode 100644
index 85b378d4..00000000
--- a/arm9/asm/OS_exception.s
+++ /dev/null
@@ -1,172 +0,0 @@
- .include "asm/macros.inc"
- .include "global.inc"
-
- .section .bss
-
- .global OSi_UserExceptionHandler
-OSi_UserExceptionHandler: ; 0x021D371C
- .space 0x4
-
- .global OSi_UserExceptionHandlerArg
-OSi_UserExceptionHandlerArg: ; 0x021D3720
- .space 0x4
-
- .global OSi_DebuggerHandler
-OSi_DebuggerHandler: ; 0x021D3724
- .space 0x4
-
- .global OSi_ExContext
-OSi_ExContext: ; 0x021D3728
- .space 0x80
-
- .text
-
- arm_func_start OSi_ExceptionHandler
-OSi_ExceptionHandler: ; 0x020CC9FC
- ldr ip, _020CCA68 ; =OSi_DebuggerHandler
- ldr r12, [r12, #0x0]
- cmp r12, #0x0
- movne lr, pc
- bxne r12
- ldr ip, _020CCA6C ; =0x02000000
- stmdb r12!, {r0-r3,sp-lr}
- and r0, sp, #0x1
- mov sp, r12
- mrs r1, cpsr
- and r1, r1, #0x1f
- teq r1, #0x17
- bne _020CCA38
- bl OSi_GetAndDisplayContext
- b _020CCA44
-_020CCA38:
- teq r1, #0x1b
- bne _020CCA44
- bl OSi_GetAndDisplayContext
-_020CCA44:
- ldr ip, _020CCA68 ; =OSi_DebuggerHandler
- ldr r12, [r12, #0x0]
- cmp r12, #0x0
-_020CCA50:
- beq _020CCA50
-_020CCA54:
- mov r0, r0
- b _020CCA54
-_020CCA5C:
- ldmia sp!, {r0-r3,ip,lr}
- mov sp, ip
- bx lr
-_020CCA68: .word OSi_DebuggerHandler
-_020CCA6C: .word 0x02000000
-
- arm_func_start OSi_GetAndDisplayContext
-OSi_GetAndDisplayContext: ; 0x020CCA70
- stmdb sp!, {r0,lr}
- bl OSi_SetExContext
- bl OSi_DisplayExContext
- ldmia sp!, {r0,lr}
- bx lr
-
- arm_func_start OSi_SetExContext
-OSi_SetExContext: ; 0x020CCA84
- ldr r1, _020CCB10 ; =OSi_ExContext
- mrs r2, cpsr
- str r2, [r1, #0x74]
- str r0, [r1, #0x6c]
- ldr r0, [r12, #0x0]
- str r0, [r1, #0x4]
- ldr r0, [r12, #0x4]
- str r0, [r1, #0x8]
- ldr r0, [r12, #0x8]
- str r0, [r1, #0xc]
- ldr r0, [r12, #0xc]
- str r0, [r1, #0x10]
- ldr r2, [r12, #0x10]
- bic r2, r2, #0x1
- add r0, r1, #0x14
- stmia r0, {r4-r11}
- str r12, [r1, #0x70]
- ldr r0, [r2, #0x0]
- str r0, [r1, #0x64]
- ldr r3, [r2, #0x4]
- str r3, [r1, #0x0]
- ldr r0, [r2, #0x8]
- str r0, [r1, #0x34]
- ldr r0, [r2, #0xc]
- str r0, [r1, #0x40]
- mrs r0, cpsr
- orr r3, r3, #0x80
- bic r3, r3, #0x20
- msr cpsr_fsxc, r3
- str sp, [r1, #0x38]
- str lr, [r1, #0x3c]
- mrs r2, spsr
- str r2, [r1, #0x7c]
- msr cpsr_fsxc, r0
- bx lr
- .balign 4
-_020CCB10: .word OSi_ExContext
-
- arm_func_start OSi_DisplayExContext
-OSi_DisplayExContext: ; 0x020CCB14
- stmdb sp!, {lr}
- sub sp, sp, #0x4
- ldr r0, _020CCB70 ; =OSi_UserExceptionHandler
- ldr r0, [r0, #0x0]
- cmp r0, #0x0
- addeq sp, sp, #0x4
- ldmeqia sp!, {lr}
- bxeq lr
- mov r0, sp
- ldr r1, _020CCB74 ; =0x0000009F
- msr cpsr_fsxc, r1
- mov sp, r0
- bl OS_EnableProtectionUnit
- ldr r1, _020CCB78 ; =OSi_UserExceptionHandlerArg
- ldr r0, _020CCB70 ; =OSi_UserExceptionHandler
- ldr r1, [r1, #0x0]
- ldr r2, [r0, #0x0]
- ldr r0, _020CCB7C ; =OSi_ExContext
- blx r2
- bl OS_DisableProtectionUnit
- add sp, sp, #0x4
- ldmia sp!, {lr}
- bx lr
- .balign 4
-_020CCB70: .word OSi_UserExceptionHandler
-_020CCB74: .word 0x0000009F
-_020CCB78: .word OSi_UserExceptionHandlerArg
-_020CCB7C: .word OSi_ExContext
-
- arm_func_start OS_InitException
-OS_InitException: ; 0x020CCB80
- ldr r0, _020CCBDC ; =0x027FFD9C
- ldr r1, [r0, #0x0]
- cmp r1, #0x2600000
- blo _020CCBA0
- cmp r1, #0x2800000
- ldrlo r0, _020CCBE0 ; =OSi_DebuggerHandler
- strcc r1, [r0, #0x0]
- blo _020CCBAC
-_020CCBA0:
- ldr r0, _020CCBE0 ; =OSi_DebuggerHandler
- mov r1, #0x0
- str r1, [r0, #0x0]
-_020CCBAC:
- ldr r0, _020CCBE0 ; =OSi_DebuggerHandler
- ldr r0, [r0, #0x0]
- cmp r0, #0x0
- ldreq r2, _020CCBE4 ; =OSi_ExceptionHandler
- ldreq r1, _020CCBDC ; =0x027FFD9C
- ldreq r0, _020CCBE8 ; =0x027E3000
- streq r2, [r1, #0x0]
- streq r2, [r0, #0xfdc]
- ldr r0, _020CCBEC ; =OSi_UserExceptionHandler
- mov r1, #0x0
- str r1, [r0, #0x0]
- bx lr
- .balign 4
-_020CCBDC: .word 0x027FFD9C
-_020CCBE0: .word OSi_DebuggerHandler
-_020CCBE4: .word OSi_ExceptionHandler
-_020CCBE8: .word 0x027E3000
-_020CCBEC: .word OSi_UserExceptionHandler
diff --git a/arm9/lib/include/OS_exception.h b/arm9/lib/include/OS_exception.h
new file mode 100644
index 00000000..68caf856
--- /dev/null
+++ b/arm9/lib/include/OS_exception.h
@@ -0,0 +1,26 @@
+#ifndef POKEDIAMOND_OS_EXCEPTION_H
+#define POKEDIAMOND_OS_EXCEPTION_H
+
+#include "consts.h"
+#include "OS_context.h"
+
+typedef struct
+{
+ OSContext context;
+ u32 cp15;
+ u32 spsr;
+ u32 exinfo;
+ u32 debug[4];
+} OSiExContext;
+
+typedef void (*OSExceptionHandler) (u32, void *);
+
+static void OSi_ExceptionHandler(void);
+
+void OS_InitException(void);
+void OSi_ExceptionHandler(void);
+static void OSi_GetAndDisplayContext(void);
+static void OSi_SetExContext(void);
+static void OSi_DisplayExContext(void);
+
+#endif //POKEDIAMOND_OS_EXCEPTION_H
diff --git a/arm9/lib/include/OS_init.h b/arm9/lib/include/OS_init.h
index 7cf21709..499c9f6c 100644
--- a/arm9/lib/include/OS_init.h
+++ b/arm9/lib/include/OS_init.h
@@ -23,6 +23,7 @@
#include "OS_irqTable.h"
#include "OS_interrupt.h"
#include "OS_reset.h"
+#include "OS_exception.h"
void OS_Init(void);
diff --git a/arm9/lib/include/mmap.h b/arm9/lib/include/mmap.h
index 12823fa0..143b609b 100644
--- a/arm9/lib/include/mmap.h
+++ b/arm9/lib/include/mmap.h
@@ -19,6 +19,8 @@ extern u32 SDK_AUTOLOAD_DTCM_START[];
#define HW_DTCM_SYSRV (HW_DTCM + 0x00003fc0)
#define HW_INTR_CHECK_BUF (HW_DTCM_SYSRV + 0x38)
+#define HW_EXCP_VECTOR_BUF (HW_DTCM_SYSRV + 0x1C)
+
#define HW_CARD_ROM_HEADER_SIZE 0x00000160
#define HW_DOWNLOAD_PARAMETER_SIZE 0x00000020
diff --git a/arm9/lib/src/OS_exception.c b/arm9/lib/src/OS_exception.c
new file mode 100644
index 00000000..5a66b2c4
--- /dev/null
+++ b/arm9/lib/src/OS_exception.c
@@ -0,0 +1,158 @@
+#include "OS_exception.h"
+#include "function_target.h"
+#include "OS_protectionUnit.h"
+
+static OSiExContext OSi_ExContext;
+
+static OSExceptionHandler OSi_UserExceptionHandler;
+static void *OSi_UserExceptionHandlerArg;
+
+static void *OSi_DebuggerHandler = NULL;
+
+#define HW_EXCEP_VECTOR_BUF_FOR_DEBUGGER 0x027ffd9c
+
+ARM_FUNC void OS_InitException(void)
+{
+ if (0x2600000 <= *(u32 *)HW_EXCEP_VECTOR_BUF_FOR_DEBUGGER
+ && *(u32 *)HW_EXCEP_VECTOR_BUF_FOR_DEBUGGER < 0x2800000)
+ {
+ OSi_DebuggerHandler = *(void **)HW_EXCEP_VECTOR_BUF_FOR_DEBUGGER;
+ }
+ else
+ {
+ OSi_DebuggerHandler = NULL;
+ }
+
+ if (!OSi_DebuggerHandler)
+ {
+ *(u32 *)(HW_EXCEP_VECTOR_BUF_FOR_DEBUGGER) = (u32)OSi_ExceptionHandler;
+
+ *(u32 *)(HW_EXCP_VECTOR_BUF) = (u32)OSi_ExceptionHandler;
+ }
+
+ OSi_UserExceptionHandler = NULL;
+}
+
+ARM_FUNC asm void OSi_ExceptionHandler(void)
+{
+ ldr r12, =OSi_DebuggerHandler
+ ldr r12, [r12]
+ cmp r12, #0
+ movne lr, pc
+ bxne r12
+
+ ldr r12, =HW_ITCM_END
+ stmfd r12!, {r0-r3, sp, lr}
+
+ and r0, sp, #1
+ mov sp, r12
+
+ mrs r1, cpsr
+ and r1, r1, #0x1f
+
+ teq r1, #0x17
+ bne _020CCA38
+ bl OSi_GetAndDisplayContext
+ b _020CCA44
+
+_020CCA38:
+ teq r1, #0x1b
+ bne _020CCA44
+ bl OSi_GetAndDisplayContext
+
+_020CCA44:
+ ldr r12, =OSi_DebuggerHandler
+ ldr r12, [r12]
+ cmp r12, #0
+
+_020CCA50:
+ beq _020CCA50
+
+_020CCA54:
+ mov r0, r0
+ b _020CCA54
+
+ ldmfd sp!, {r0-r3, r12, lr}
+ mov sp, r12
+ bx lr
+}
+
+ARM_FUNC static asm void OSi_GetAndDisplayContext(void)
+{
+ stmfd sp!, {r0, lr}
+
+ bl OSi_SetExContext
+ bl OSi_DisplayExContext
+
+ ldmfd sp!, {r0, lr}
+ bx lr
+}
+
+ARM_FUNC static asm void OSi_SetExContext(void)
+{
+ ldr r1, =OSi_ExContext;
+
+ mrs r2, cpsr
+ str r2, [r1, #OSiExContext.debug[1]]
+
+ str r0, [r1, #OSiExContext.exinfo]
+
+ ldr r0, [r12, #0]
+ str r0, [r1, #4]
+ ldr r0, [r12, #4]
+ str r0, [r1, #8]
+ ldr r0, [r12, #8]
+ str r0, [r1, #12]
+ ldr r0, [r12, #12]
+ str r0, [r1, #16]
+ ldr r2, [r12, #16]
+ bic r2, r2, #1
+
+ add r0, r1, #20
+ stmia r0, {r4-r11}
+
+ str r12, [r1, #OSiExContext.debug[0]]
+
+ ldr r0, [r2, #0]
+ str r0, [r1, #OSiExContext.cp15]
+ ldr r3, [r2, #4]
+ str r3, [r1, #0]
+ ldr r0, [r2, #8]
+ str r0, [r1, #52]
+ ldr r0, [r2, #12]
+ str r0, [r1, #64]
+
+ mrs r0, cpsr
+ orr r3, r3, #0x80
+ bic r3, r3, #0x20
+ msr cpsr_cxsf, r3
+
+ str sp, [r1, #56]
+ str lr, [r1, #60]
+ mrs r2, spsr
+
+ str r2, [r1, #OSiExContext.debug[3]]
+
+ msr cpsr_cxsf, r0
+ bx lr
+}
+
+ARM_FUNC static void OSi_DisplayExContext(void)
+{
+ if (OSi_UserExceptionHandler)
+ {
+ asm
+ {
+ mov r0, sp
+ ldr r1, =0x9f
+ msr CPSR_cxsf, r1
+ mov sp, r0
+ }
+
+ OS_EnableProtectionUnit();
+
+ ((void (*)(u32, void *))OSi_UserExceptionHandler)((u32)&OSi_ExContext, OSi_UserExceptionHandlerArg);
+
+ OS_DisableProtectionUnit();
+ }
+}
diff --git a/arm9/lib/src/OS_init.c b/arm9/lib/src/OS_init.c
index a8f36f00..c93b1584 100644
--- a/arm9/lib/src/OS_init.c
+++ b/arm9/lib/src/OS_init.c
@@ -2,7 +2,6 @@
#include "OS_init.h"
extern void PXI_Init(void);
-extern void OS_InitException(void);
extern void MI_Init(void);
extern void OS_InitVAlarm(void);
extern void OSi_InitVramExclusive(void);
diff --git a/files/.gitattributes b/files/.gitattributes
index cc0c2f17..747f17c5 100644
--- a/files/.gitattributes
+++ b/files/.gitattributes
@@ -3,3 +3,4 @@
.knarcignore eol=lf
.knarckeep eol=lf
*.pal eol=crlf
+*.key binary
diff --git a/files/itemtool/itemdata/item_icon/.gitignore b/files/itemtool/itemdata/item_icon/.gitignore
index c19031bc..e1591c96 100644
--- a/files/itemtool/itemdata/item_icon/.gitignore
+++ b/files/itemtool/itemdata/item_icon/.gitignore
@@ -115,3 +115,24 @@ narc_0115.NCGR
narc_0115.NCLR
narc_0117.NCGR
narc_0117.NCLR
+narc_0119.NCGR
+narc_0119.NCLR
+narc_0121.NCGR
+narc_0121.NCLR
+narc_0123.NCGR
+narc_0123.NCLR
+narc_0125.NCGR
+narc_0125.NCLR
+narc_0127.NCGR
+narc_0128.NCGR
+narc_0129.NCLR
+narc_0130.NCGR
+narc_0131.NCLR
+narc_0132.NCGR
+narc_0133.NCGR
+narc_0134.NCLR
+narc_0135.NCGR
+narc_0136.NCGR
+narc_0136.NCLR
+narc_0138.NCGR
+narc_0138.NCLR
diff --git a/files/itemtool/itemdata/item_icon/narc_0119.NCGR b/files/itemtool/itemdata/item_icon/narc_0119.NCGR
deleted file mode 100644
index 84467e88..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0119.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0119.png b/files/itemtool/itemdata/item_icon/narc_0119.png
new file mode 100644
index 00000000..be2696b5
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0119.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0120.NCLR b/files/itemtool/itemdata/item_icon/narc_0120.NCLR
deleted file mode 100644
index 079428a8..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0120.NCLR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0121.NCGR b/files/itemtool/itemdata/item_icon/narc_0121.NCGR
deleted file mode 100644
index 24a8c74e..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0121.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0121.png b/files/itemtool/itemdata/item_icon/narc_0121.png
new file mode 100644
index 00000000..72e9de9f
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0121.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0122.NCLR b/files/itemtool/itemdata/item_icon/narc_0122.NCLR
deleted file mode 100644
index adeb4483..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0122.NCLR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0123.NCGR b/files/itemtool/itemdata/item_icon/narc_0123.NCGR
deleted file mode 100644
index 46367b2b..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0123.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0123.png b/files/itemtool/itemdata/item_icon/narc_0123.png
new file mode 100644
index 00000000..9e5fc734
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0123.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0124.NCLR b/files/itemtool/itemdata/item_icon/narc_0124.NCLR
deleted file mode 100644
index d28ea92a..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0124.NCLR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0125.NCGR b/files/itemtool/itemdata/item_icon/narc_0125.NCGR
deleted file mode 100644
index 798b594c..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0125.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0125.png b/files/itemtool/itemdata/item_icon/narc_0125.png
new file mode 100644
index 00000000..06c3a482
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0125.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0126.NCLR b/files/itemtool/itemdata/item_icon/narc_0126.NCLR
deleted file mode 100644
index d343c899..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0126.NCLR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0127.NCGR b/files/itemtool/itemdata/item_icon/narc_0127.NCGR
deleted file mode 100644
index e23ed8c8..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0127.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0127.png b/files/itemtool/itemdata/item_icon/narc_0127.png
new file mode 100644
index 00000000..76f70a18
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0127.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0128.NCGR b/files/itemtool/itemdata/item_icon/narc_0128.NCGR
deleted file mode 100644
index 05f2f725..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0128.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0128.png b/files/itemtool/itemdata/item_icon/narc_0128.png
new file mode 100644
index 00000000..7dcf6528
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0128.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0129.NCLR b/files/itemtool/itemdata/item_icon/narc_0129.NCLR
deleted file mode 100644
index 6eb6e10a..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0129.NCLR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0129.pal b/files/itemtool/itemdata/item_icon/narc_0129.pal
new file mode 100644
index 00000000..25e42a1d
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0129.pal
@@ -0,0 +1,19 @@
+JASC-PAL
+0100
+16
+180 180 180
+49 49 49
+213 57 32
+255 115 90
+255 164 131
+238 213 74
+246 230 98
+238 222 222
+222 205 205
+180 164 164
+139 123 123
+0 0 0
+0 0 0
+0 0 0
+0 0 0
+0 0 0
diff --git a/files/itemtool/itemdata/item_icon/narc_0130.NCGR b/files/itemtool/itemdata/item_icon/narc_0130.NCGR
deleted file mode 100644
index 934d57c1..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0130.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0130.png b/files/itemtool/itemdata/item_icon/narc_0130.png
new file mode 100644
index 00000000..64e57f5a
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0130.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0131.NCLR b/files/itemtool/itemdata/item_icon/narc_0131.NCLR
deleted file mode 100644
index 6439f1d3..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0131.NCLR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0131.pal b/files/itemtool/itemdata/item_icon/narc_0131.pal
new file mode 100644
index 00000000..2525be88
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0131.pal
@@ -0,0 +1,19 @@
+JASC-PAL
+0100
+16
+180 180 180
+49 49 49
+238 197 197
+180 230 222
+189 189 189
+238 238 189
+255 255 255
+230 230 230
+148 164 164
+74 74 74
+213 172 172
+156 205 197
+164 164 164
+123 139 139
+255 255 205
+0 0 0
diff --git a/files/itemtool/itemdata/item_icon/narc_0132.NCGR b/files/itemtool/itemdata/item_icon/narc_0132.NCGR
deleted file mode 100644
index 1533ac1a..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0132.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0132.png b/files/itemtool/itemdata/item_icon/narc_0132.png
new file mode 100644
index 00000000..d2f704f5
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0132.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0133.NCGR b/files/itemtool/itemdata/item_icon/narc_0133.NCGR
deleted file mode 100644
index 6a5a6952..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0133.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0133.png b/files/itemtool/itemdata/item_icon/narc_0133.png
new file mode 100644
index 00000000..32a2ece6
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0133.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0134.NCLR b/files/itemtool/itemdata/item_icon/narc_0134.NCLR
deleted file mode 100644
index 9dfb92f0..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0134.NCLR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0134.pal b/files/itemtool/itemdata/item_icon/narc_0134.pal
new file mode 100644
index 00000000..d37358e9
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0134.pal
@@ -0,0 +1,19 @@
+JASC-PAL
+0100
+16
+180 180 180
+49 49 49
+98 156 213
+41 98 156
+24 57 115
+123 180 238
+246 164 164
+222 115 115
+255 222 222
+156 74 74
+255 255 255
+131 49 49
+0 0 0
+0 0 0
+0 0 0
+0 0 0
diff --git a/files/itemtool/itemdata/item_icon/narc_0135.NCGR b/files/itemtool/itemdata/item_icon/narc_0135.NCGR
deleted file mode 100644
index 506c03bf..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0135.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0135.png b/files/itemtool/itemdata/item_icon/narc_0135.png
new file mode 100644
index 00000000..6b6ba082
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0135.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0136.NCGR b/files/itemtool/itemdata/item_icon/narc_0136.NCGR
deleted file mode 100644
index 25f32dc6..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0136.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0136.png b/files/itemtool/itemdata/item_icon/narc_0136.png
new file mode 100644
index 00000000..56feb189
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0136.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0137.NCLR b/files/itemtool/itemdata/item_icon/narc_0137.NCLR
deleted file mode 100644
index 4684bf7f..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0137.NCLR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0138.NCGR b/files/itemtool/itemdata/item_icon/narc_0138.NCGR
deleted file mode 100644
index f98c3043..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0138.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0138.png b/files/itemtool/itemdata/item_icon/narc_0138.png
new file mode 100644
index 00000000..7f810421
--- /dev/null
+++ b/files/itemtool/itemdata/item_icon/narc_0138.png
Binary files differ
diff --git a/files/itemtool/itemdata/item_icon/narc_0139.NCLR b/files/itemtool/itemdata/item_icon/narc_0139.NCLR
deleted file mode 100644
index 20afc404..00000000
--- a/files/itemtool/itemdata/item_icon/narc_0139.NCLR
+++ /dev/null
Binary files differ
diff --git a/files/poketool/trgra/trbgra/.gitignore b/files/poketool/trgra/trbgra/.gitignore
new file mode 100644
index 00000000..849e6ea4
--- /dev/null
+++ b/files/poketool/trgra/trbgra/.gitignore
@@ -0,0 +1,2 @@
+narc_0000.NCGR
+narc_0000.NCLR \ No newline at end of file
diff --git a/files/poketool/trgra/trbgra/.knarcignore b/files/poketool/trgra/trbgra/.knarcignore
index 2856080a..e2f57de1 100644
--- a/files/poketool/trgra/trbgra/.knarcignore
+++ b/files/poketool/trgra/trbgra/.knarcignore
@@ -1,2 +1,3 @@
*.png
*.pal
+*.key
diff --git a/files/poketool/trgra/trbgra/narc_0000.NCGR b/files/poketool/trgra/trbgra/narc_0000.NCGR
deleted file mode 100644
index 131ae9be..00000000
--- a/files/poketool/trgra/trbgra/narc_0000.NCGR
+++ /dev/null
Binary files differ
diff --git a/files/poketool/trgra/trbgra/narc_0000.png b/files/poketool/trgra/trbgra/narc_0000.png
new file mode 100644
index 00000000..d7ba9767
--- /dev/null
+++ b/files/poketool/trgra/trbgra/narc_0000.png
Binary files differ
diff --git a/files/poketool/trgra/trbgra/narc_0000.png.key b/files/poketool/trgra/trbgra/narc_0000.png.key
new file mode 100644
index 00000000..44d8ba26
--- /dev/null
+++ b/files/poketool/trgra/trbgra/narc_0000.png.key
@@ -0,0 +1 @@
+[ü \ No newline at end of file
diff --git a/files/poketool/trgra/trbgra/narc_0001.NCLR b/files/poketool/trgra/trbgra/narc_0001.NCLR
deleted file mode 100644
index 39767f84..00000000
--- a/files/poketool/trgra/trbgra/narc_0001.NCLR
+++ /dev/null
Binary files differ
diff --git a/filesystem.mk b/filesystem.mk
index ade47589..d5d3cae8 100644
--- a/filesystem.mk
+++ b/filesystem.mk
@@ -1676,7 +1676,28 @@ files/itemtool/itemdata/item_icon.narc: \
files/itemtool/itemdata/item_icon/narc_0115.NCGR \
files/itemtool/itemdata/item_icon/narc_0115.NCLR \
files/itemtool/itemdata/item_icon/narc_0117.NCGR \
- files/itemtool/itemdata/item_icon/narc_0117.NCLR
+ files/itemtool/itemdata/item_icon/narc_0117.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0119.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0119.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0121.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0121.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0123.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0123.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0125.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0125.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0127.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0128.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0129.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0130.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0131.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0132.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0133.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0134.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0135.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0136.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0136.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0138.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0138.NCLR
files/application/custom_ball/data/cb_data.narc: \
@@ -2237,6 +2258,10 @@ files/demo/title/titledemo.narc: \
files/demo/title/titledemo/narc_0015.NCGR \
files/demo/title/titledemo/narc_0016.NCLR
+files/poketool/trgra/trbgra.narc: \
+ files/poketool/trgra/trbgra/narc_0000.NCGR \
+ files/poketool/trgra/trbgra/narc_0000.NCLR
+
.PHONY: filesystem
filesystem: $(HOSTFS_FILES)
diff --git a/graphics_rules.mk b/graphics_rules.mk
index 3195fb18..95b55503 100644
--- a/graphics_rules.mk
+++ b/graphics_rules.mk
@@ -51,7 +51,19 @@ CLOBBER_SIZE_VERSION101_NCGR_FILES := files/graphic/bag_gra/narc_0002.NCGR \
files/itemtool/itemdata/item_icon/narc_0109.NCGR \
files/itemtool/itemdata/item_icon/narc_0112.NCGR \
files/itemtool/itemdata/item_icon/narc_0115.NCGR \
- files/itemtool/itemdata/item_icon/narc_0117.NCGR
+ files/itemtool/itemdata/item_icon/narc_0117.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0119.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0121.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0123.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0125.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0127.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0128.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0130.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0132.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0133.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0135.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0136.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0138.NCGR
4BPP_NCLR_FILES := files/demo/title/titledemo/narc_0016.NCLR
@@ -93,6 +105,10 @@ VERSION101_SOPC_NCGR_FILES := files/demo/title/titledemo/narc_0007.NCGR \
files/demo/title/titledemo/narc_0011.NCGR \
files/demo/title/titledemo/narc_0015.NCGR
+8BPP_COMP10_NOPAD_NCLR_FILES := files/poketool/trgra/trbgra/narc_0000.NCLR
+
+SCANNED_NCGR_FILES := files/poketool/trgra/trbgra/narc_0000.NCGR
+
NCGR_CLEAN_LIST := files/data/cell0.NCGR \
files/demo/title/titledemo/narc_0001.NCGR \
files/demo/title/titledemo/narc_0003.NCGR \
@@ -146,7 +162,20 @@ NCGR_CLEAN_LIST := files/data/cell0.NCGR \
files/itemtool/itemdata/item_icon/narc_0109.NCGR \
files/itemtool/itemdata/item_icon/narc_0112.NCGR \
files/itemtool/itemdata/item_icon/narc_0115.NCGR \
- files/itemtool/itemdata/item_icon/narc_0117.NCGR
+ files/itemtool/itemdata/item_icon/narc_0117.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0119.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0121.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0123.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0125.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0127.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0128.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0130.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0132.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0133.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0135.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0136.NCGR \
+ files/itemtool/itemdata/item_icon/narc_0138.NCGR \
+ files/poketool/trgra/trbgra/narc_0000.NCGR
NCLR_CLEAN_LIST := files/data/cell0.NCLR \
@@ -230,4 +259,14 @@ NCLR_CLEAN_LIST := files/data/cell0.NCLR \
files/itemtool/itemdata/item_icon/narc_0112.NCLR \
files/itemtool/itemdata/item_icon/narc_0114.NCLR \
files/itemtool/itemdata/item_icon/narc_0115.NCLR \
- files/itemtool/itemdata/item_icon/narc_0117.NCLR
+ files/itemtool/itemdata/item_icon/narc_0117.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0119.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0121.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0123.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0125.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0129.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0131.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0134.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0136.NCLR \
+ files/itemtool/itemdata/item_icon/narc_0138.NCLR \
+ files/poketool/trgra/trbgra/narc_0000.NCLR
diff --git a/tools/nitrogfx/gfx.c b/tools/nitrogfx/gfx.c
index 7c57d269..c1be2a36 100644
--- a/tools/nitrogfx/gfx.c
+++ b/tools/nitrogfx/gfx.c
@@ -93,6 +93,34 @@ static void ConvertFromTiles4Bpp(unsigned char *src, unsigned char *dest, int nu
}
}
+static uint32_t ConvertFromScanned4Bpp(unsigned char *src, unsigned char *dest, int fileSize, bool invertColours)
+{
+ uint32_t encValue = (src[fileSize - 1] << 8) | src[fileSize - 2];
+ for (int i = fileSize; i > 0; i -= 2)
+ {
+ uint16_t val = (src[i - 1] << 8) | src[i - 2];
+ val ^= (encValue & 0xFFFF);
+ src[i - 1] = (val >> 8);
+ src[i - 2] = val;
+ encValue = encValue * 1103515245;
+ encValue = encValue + 24691;
+ }
+ for (int i = 0; i < fileSize; i++)
+ {
+ unsigned char srcPixelPair = src[i];
+ unsigned char leftPixel = srcPixelPair & 0xF;
+ unsigned char rightPixel = srcPixelPair >> 4;
+
+ if (invertColours) {
+ leftPixel = 15 - leftPixel;
+ rightPixel = 15 - rightPixel;
+ }
+
+ dest[i] = (leftPixel << 4) | rightPixel;
+ }
+ return encValue;
+}
+
static void ConvertFromTiles8Bpp(unsigned char *src, unsigned char *dest, int numTiles, int metatilesWide, int metatileWidth, int metatileHeight, bool invertColors)
{
int subTileX = 0;
@@ -177,6 +205,30 @@ static void ConvertToTiles4Bpp(unsigned char *src, unsigned char *dest, int numT
}
}
+static void ConvertToScanned4Bpp(unsigned char *src, unsigned char *dest, int fileSize, bool invertColours, uint32_t encValue)
+{
+ for (int i = 0; i < fileSize; i++)
+ {
+ unsigned char srcPixelPair = src[i];
+ unsigned char leftPixel = srcPixelPair & 0xF;
+ unsigned char rightPixel = srcPixelPair >> 4;
+ if (invertColours) {
+ leftPixel = 15 - leftPixel;
+ rightPixel = 15 - rightPixel;
+ }
+ dest[i] = (leftPixel << 4) | rightPixel;
+ }
+
+ for (int i = 1; i < fileSize; i += 2)
+ {
+ uint16_t val = (dest[i] << 8) | dest[i - 1];
+ encValue = (encValue - 24691) * 4005161829;
+ val ^= (encValue & 0xFFFF);
+ dest[i] = (val >> 8);
+ dest[i - 1] = val;
+ }
+}
+
static void ConvertToTiles8Bpp(unsigned char *src, unsigned char *dest, int numTiles, int metatilesWide, int metatileWidth, int metatileHeight, bool invertColors)
{
int subTileX = 0;
@@ -246,7 +298,7 @@ void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int
free(buffer);
}
-void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors)
+uint32_t ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors)
{
int fileSize;
unsigned char *buffer = ReadWholeFile(path, &fileSize);
@@ -272,6 +324,8 @@ void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, i
unsigned char *imageData = charHeader + 0x20;
+ bool scanned = charHeader[0x14];
+
int tileSize = bitDepth * 8;
int numTiles = (charHeader[0x18] + (charHeader[0x19] << 8) + (charHeader[0x1A] << 16) + (charHeader[0x1B] << 24))
@@ -296,16 +350,36 @@ void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, i
int metatilesWide = tilesWidth / metatileWidth;
- switch (bitDepth) {
- case 4:
- ConvertFromTiles4Bpp(imageData, image->pixels, numTiles, metatilesWide, metatileWidth, metatileHeight, invertColors);
- break;
- case 8:
- ConvertFromTiles8Bpp(imageData, image->pixels, numTiles, metatilesWide, metatileWidth, metatileHeight, invertColors);
- break;
+ uint32_t key = 0;
+ if (scanned)
+ {
+ switch (bitDepth)
+ {
+ case 4:
+ key = ConvertFromScanned4Bpp(imageData, image->pixels, fileSize - 0x30, invertColors);
+ break;
+ case 8:
+ FATAL_ERROR("8bpp is not implemented yet\n");
+ break;
+ }
+ }
+ else
+ {
+ switch (bitDepth)
+ {
+ case 4:
+ ConvertFromTiles4Bpp(imageData, image->pixels, numTiles, metatilesWide, metatileWidth, metatileHeight,
+ invertColors);
+ break;
+ case 8:
+ ConvertFromTiles8Bpp(imageData, image->pixels, numTiles, metatilesWide, metatileWidth, metatileHeight,
+ invertColors);
+ break;
+ }
}
free(buffer);
+ return key;
}
void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors)
@@ -359,7 +433,7 @@ void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int m
free(buffer);
}
-void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101, bool sopc)
+void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101, bool sopc, bool scanned, uint32_t key)
{
FILE *fp = fopen(path, "wb");
@@ -398,13 +472,31 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in
int metatilesWide = tilesWidth / metatileWidth;
- switch (bitDepth) {
- case 4:
- ConvertToTiles4Bpp(image->pixels, pixelBuffer, numTiles, metatilesWide, metatileWidth, metatileHeight, invertColors);
- break;
- case 8:
- ConvertToTiles8Bpp(image->pixels, pixelBuffer, numTiles, metatilesWide, metatileWidth, metatileHeight, invertColors);
- break;
+ if (scanned)
+ {
+ switch (bitDepth)
+ {
+ case 4:
+ ConvertToScanned4Bpp(image->pixels, pixelBuffer, bufferSize, invertColors, key);
+ break;
+ case 8:
+ FATAL_ERROR("8Bpp not supported yet.\n");
+ break;
+ }
+ }
+ else
+ {
+ switch (bitDepth)
+ {
+ case 4:
+ ConvertToTiles4Bpp(image->pixels, pixelBuffer, numTiles, metatilesWide, metatileWidth, metatileHeight,
+ invertColors);
+ break;
+ case 8:
+ ConvertToTiles8Bpp(image->pixels, pixelBuffer, numTiles, metatilesWide, metatileWidth, metatileHeight,
+ invertColors);
+ break;
+ }
}
WriteGenericNtrHeader(fp, "RGCN", bufferSize + (sopc ? 0x30 : 0x20), byteOrder, version101, sopc ? 2 : 1);
@@ -437,6 +529,11 @@ void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, in
charHeader[12] = bitDepth == 4 ? 3 : 4;
+ if (scanned)
+ {
+ charHeader[20] = 1;
+ }
+
charHeader[24] = bufferSize & 0xFF;
charHeader[25] = (bufferSize >> 8) & 0xFF;
charHeader[26] = (bufferSize >> 16) & 0xFF;
diff --git a/tools/nitrogfx/gfx.h b/tools/nitrogfx/gfx.h
index f833ac2e..ef1f493d 100644
--- a/tools/nitrogfx/gfx.h
+++ b/tools/nitrogfx/gfx.h
@@ -29,9 +29,9 @@ struct Image {
};
void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors);
-void ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors);
+uint32_t ReadNtrImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors);
void WriteImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors);
-void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101, bool sopc);
+void WriteNtrImage(char *path, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors, bool clobberSize, bool byteOrder, bool version101, bool sopc, bool scanned, uint32_t key);
void FreeImage(struct Image *image);
void ReadGbaPalette(char *path, struct Palette *palette);
void ReadNtrPalette(char *path, struct Palette *palette, int bitdepth);
diff --git a/tools/nitrogfx/main.c b/tools/nitrogfx/main.c
index b7136b03..942b0d90 100644
--- a/tools/nitrogfx/main.c
+++ b/tools/nitrogfx/main.c
@@ -58,7 +58,18 @@ void ConvertNtrToPng(char *inputPath, char *outputPath, struct GbaToPngOptions *
image.hasPalette = false;
}
- ReadNtrImage(inputPath, options->width, 0, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette);
+ uint32_t key = ReadNtrImage(inputPath, options->width, 0, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette);
+
+ if (key)
+ {
+ char string[strlen(outputPath) + 5];
+ sprintf(string, "%s.key", outputPath);
+ FILE *fp = fopen(string, "wb");
+ if (fp == NULL)
+ FATAL_ERROR("Failed to open key file for writing.\n");
+ fwrite(&key, 4, 1, fp);
+ fclose(fp);
+ }
image.hasTransparency = options->hasTransparency;
@@ -88,7 +99,21 @@ void ConvertPngToNtr(char *inputPath, char *outputPath, struct PngToNtrOptions *
ReadPng(inputPath, &image);
- WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc);
+ uint32_t key = 0;
+ if (options->scanned)
+ {
+ char string[strlen(inputPath) + 5];
+ sprintf(string, "%s.key", inputPath);
+ FILE *fp2 = fopen(string, "rb");
+ if (fp2 == NULL)
+ FATAL_ERROR("Failed to open key file for reading.\n");
+ size_t count = fread(&key, 4, 1, fp2);
+ if (count != 1)
+ FATAL_ERROR("Not a valid key file.\n");
+ fclose(fp2);
+ }
+
+ WriteNtrImage(outputPath, options->numTiles, image.bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette, options->clobberSize, options->byteOrder, options->version101, options->sopc, options->scanned, key);
FreeImage(&image);
}
@@ -322,6 +347,7 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a
options.byteOrder = true;
options.version101 = false;
options.sopc = false;
+ options.scanned = false;
for (int i = 3; i < argc; i++)
{
@@ -395,6 +421,10 @@ void HandlePngToNtrCommand(char *inputPath, char *outputPath, int argc, char **a
{
options.sopc = true;
}
+ else if (strcmp(option, "-scanned") == 0)
+ {
+ options.scanned = true;
+ }
else
{
FATAL_ERROR("Unrecognized option \"%s\".\n", option);
@@ -418,6 +448,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c
bool ncpr = false;
bool ir = false;
bool nopad = false;
+ int bitdepth = 0;
int compNum = 0;
for (int i = 3; i < argc; i++)
@@ -436,7 +467,20 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c
{
nopad = true;
}
- if (strcmp(option, "-comp") == 0)
+ else if (strcmp(option, "-bitdepth") == 0)
+ {
+ if (i + 1 >= argc)
+ FATAL_ERROR("No bitdepth following \"-bitdepth\".\n");
+
+ i++;
+
+ if (!ParseNumber(argv[i], NULL, 10, &bitdepth))
+ FATAL_ERROR("Failed to parse bitdepth.\n");
+
+ if (bitdepth != 4 && bitdepth != 8)
+ FATAL_ERROR("Bitdepth must be 4 or 8.\n");
+ }
+ else if (strcmp(option, "-comp") == 0)
{
if (i + 1 >= argc)
FATAL_ERROR("No compression value following \"-comp\".\n");
@@ -456,7 +500,7 @@ void HandlePngToNtrPaletteCommand(char *inputPath, char *outputPath, int argc, c
}
ReadPngPalette(inputPath, &palette);
- WriteNtrPalette(outputPath, &palette, ncpr, ir, palette.bitDepth, !nopad, compNum);
+ WriteNtrPalette(outputPath, &palette, ncpr, ir, bitdepth, !nopad, compNum);
}
void HandleGbaToJascPaletteCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
diff --git a/tools/nitrogfx/options.h b/tools/nitrogfx/options.h
index dc90a2a2..b03bd561 100644
--- a/tools/nitrogfx/options.h
+++ b/tools/nitrogfx/options.h
@@ -30,6 +30,7 @@ struct PngToNtrOptions {
bool byteOrder;
bool version101;
bool sopc;
+ bool scanned;
};