mirror of
https://github.com/pret/pokeruby.git
synced 2024-11-23 04:59:53 +00:00
picture frame graphics
This commit is contained in:
parent
d73d8052e9
commit
04cfba7536
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,6 +8,7 @@
|
||||
*.8bpp
|
||||
*.gbapal
|
||||
*.lz
|
||||
*.rl
|
||||
*.latfont
|
||||
*.hwjpnfont
|
||||
*.fwjpnfont
|
||||
|
5
Makefile
5
Makefile
@ -29,7 +29,7 @@ PREPROC := tools/preproc/preproc
|
||||
# Secondary expansion is required for dependency variables in object rules.
|
||||
.SECONDEXPANSION:
|
||||
|
||||
.PRECIOUS: %.1bpp %.4bpp %.8bpp %.gbapal %.lz
|
||||
.PRECIOUS: %.1bpp %.4bpp %.8bpp %.gbapal %.lz %.rl
|
||||
|
||||
.PHONY: all clean compare ruby sapphire
|
||||
|
||||
@ -64,7 +64,7 @@ compare: both
|
||||
|
||||
clean:
|
||||
rm -f $(ROM) $(ELF) $(OBJS) $(pokeruby_OBJS) $(pokesapphire_OBJS) $(C_SRCS:%.c=%.i) pokeruby.map pokesapphire.map
|
||||
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' \) -exec rm {} +
|
||||
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.rl' \) -exec rm {} +
|
||||
|
||||
tidy:
|
||||
rm -f $(ROM) $(ELF) $(OBJS) $(pokeruby_OBJS) $(pokesapphire_OBJS) $(C_SRCS:%.c=%.i) pokeruby.map pokesapphire.map
|
||||
@ -84,6 +84,7 @@ include misc.mk
|
||||
%.8bpp: %.png ; $(GFX) $< $@
|
||||
%.gbapal: %.pal ; $(GFX) $< $@
|
||||
%.lz: % ; $(GFX) $< $@
|
||||
%.rl: % ; $(GFX) $< $@
|
||||
|
||||
src/libc_ruby.o src/libc_sapphire.o: CC1 := tools/agbcc/bin/old_agbcc
|
||||
src/libc_ruby.o src/libc_sapphire.o: CFLAGS := -O2
|
||||
|
48
asm/rom5.s
48
asm/rom5.s
@ -287969,7 +287969,7 @@ _08106C5E:
|
||||
ldr r0, [r0]
|
||||
mov pc, r0
|
||||
.align 2, 0
|
||||
_08106C7C: .4byte gUnknown_083EF198
|
||||
_08106C7C: .4byte gPictureFramePalettes
|
||||
_08106C80: .4byte 0x03005e8c
|
||||
_08106C84: .4byte _08106C88
|
||||
.align 2, 0
|
||||
@ -287987,8 +287987,8 @@ _08106C9C:
|
||||
ldr r0, _08106CB0
|
||||
b _08106CF0
|
||||
.align 2, 0
|
||||
_08106CAC: .4byte gUnknown_083EF398
|
||||
_08106CB0: .4byte gUnknown_083F4260
|
||||
_08106CAC: .4byte gPictureFrameTiles_0
|
||||
_08106CB0: .4byte gPictureFrameTilemap_0
|
||||
_08106CB4:
|
||||
ldr r0, _08106CC4
|
||||
movs r1, 0xC0
|
||||
@ -287997,8 +287997,8 @@ _08106CB4:
|
||||
ldr r0, _08106CC8
|
||||
b _08106CF0
|
||||
.align 2, 0
|
||||
_08106CC4: .4byte gUnknown_083F041C
|
||||
_08106CC8: .4byte gUnknown_083F476C
|
||||
_08106CC4: .4byte gPictureFrameTiles_1
|
||||
_08106CC8: .4byte gPictureFrameTilemap_1
|
||||
_08106CCC:
|
||||
ldr r0, _08106CDC
|
||||
movs r1, 0xC0
|
||||
@ -288007,8 +288007,8 @@ _08106CCC:
|
||||
ldr r0, _08106CE0
|
||||
b _08106CF0
|
||||
.align 2, 0
|
||||
_08106CDC: .4byte gUnknown_083F104C
|
||||
_08106CE0: .4byte gUnknown_083F4C78
|
||||
_08106CDC: .4byte gPictureFrameTiles_2
|
||||
_08106CE0: .4byte gPictureFrameTilemap_2
|
||||
_08106CE4:
|
||||
ldr r0, _08106CFC
|
||||
movs r1, 0xC0
|
||||
@ -288021,8 +288021,8 @@ _08106CF0:
|
||||
bl RLUnCompWram
|
||||
b _08106D1C
|
||||
.align 2, 0
|
||||
_08106CFC: .4byte gUnknown_083F1B84
|
||||
_08106D00: .4byte gUnknown_083F5184
|
||||
_08106CFC: .4byte gPictureFrameTiles_3
|
||||
_08106D00: .4byte gPictureFrameTilemap_3
|
||||
_08106D04: .4byte 0x03005e10
|
||||
_08106D08:
|
||||
ldr r0, _08106D98
|
||||
@ -288102,8 +288102,8 @@ _08106D80:
|
||||
bls _08106D80
|
||||
b _08106E86
|
||||
.align 2, 0
|
||||
_08106D98: .4byte gUnknown_083F2B3C
|
||||
_08106D9C: .4byte gUnknown_083F5690
|
||||
_08106D98: .4byte gPictureFrameTiles_4
|
||||
_08106D9C: .4byte gPictureFrameTilemap_4
|
||||
_08106DA0: .4byte 0x03005e10
|
||||
_08106DA4: .4byte 0x06006000
|
||||
_08106DA8: .4byte 0x00001015
|
||||
@ -288119,8 +288119,8 @@ _08106DB4:
|
||||
ldr r0, _08106DCC
|
||||
b _08106E60
|
||||
.align 2, 0
|
||||
_08106DC8: .4byte gUnknown_083F3C6C
|
||||
_08106DCC: .4byte gUnknown_083F5B9C
|
||||
_08106DC8: .4byte gPictureFrameTiles_5
|
||||
_08106DCC: .4byte gPictureFrameTilemap_5
|
||||
_08106DD0:
|
||||
ldr r0, _08106DF0
|
||||
ldr r0, [r0]
|
||||
@ -288154,8 +288154,8 @@ _08106E0C:
|
||||
ldr r0, _08106E20
|
||||
b _08106E60
|
||||
.align 2, 0
|
||||
_08106E1C: .4byte gUnknown_083EF398
|
||||
_08106E20: .4byte gUnknown_083F4260
|
||||
_08106E1C: .4byte gPictureFrameTiles_0
|
||||
_08106E20: .4byte gPictureFrameTilemap_0
|
||||
_08106E24:
|
||||
ldr r0, _08106E34
|
||||
movs r1, 0xC0
|
||||
@ -288164,8 +288164,8 @@ _08106E24:
|
||||
ldr r0, _08106E38
|
||||
b _08106E60
|
||||
.align 2, 0
|
||||
_08106E34: .4byte gUnknown_083F041C
|
||||
_08106E38: .4byte gUnknown_083F476C
|
||||
_08106E34: .4byte gPictureFrameTiles_1
|
||||
_08106E38: .4byte gPictureFrameTilemap_1
|
||||
_08106E3C:
|
||||
ldr r0, _08106E4C
|
||||
movs r1, 0xC0
|
||||
@ -288174,8 +288174,8 @@ _08106E3C:
|
||||
ldr r0, _08106E50
|
||||
b _08106E60
|
||||
.align 2, 0
|
||||
_08106E4C: .4byte gUnknown_083F104C
|
||||
_08106E50: .4byte gUnknown_083F4C78
|
||||
_08106E4C: .4byte gPictureFrameTiles_2
|
||||
_08106E50: .4byte gPictureFrameTilemap_2
|
||||
_08106E54:
|
||||
ldr r0, _08106E68
|
||||
movs r1, 0xC0
|
||||
@ -288187,8 +288187,8 @@ _08106E60:
|
||||
bl RLUnCompVram
|
||||
b _08106E86
|
||||
.align 2, 0
|
||||
_08106E68: .4byte gUnknown_083F1B84
|
||||
_08106E6C: .4byte gUnknown_083F5184
|
||||
_08106E68: .4byte gPictureFrameTiles_3
|
||||
_08106E6C: .4byte gPictureFrameTilemap_3
|
||||
_08106E70: .4byte 0x06006000
|
||||
_08106E74:
|
||||
ldr r0, _08106E8C
|
||||
@ -288203,8 +288203,8 @@ _08106E86:
|
||||
pop {r0}
|
||||
bx r0
|
||||
.align 2, 0
|
||||
_08106E8C: .4byte gUnknown_083F2B3C
|
||||
_08106E90: .4byte gUnknown_083F5690
|
||||
_08106E8C: .4byte gPictureFrameTiles_4
|
||||
_08106E90: .4byte gPictureFrameTilemap_4
|
||||
_08106E94: .4byte 0x06006000
|
||||
thumb_func_end sub_8106C40
|
||||
|
||||
@ -288240,7 +288240,7 @@ sub_8106E98: @ 8106E98
|
||||
bx r0
|
||||
.align 2, 0
|
||||
_08106ED0: .4byte 0x03001770
|
||||
_08106ED4: .4byte gUnknown_083F6138
|
||||
_08106ED4: .4byte gOamData_83F6138
|
||||
_08106ED8: .4byte 0xfffffc00
|
||||
_08106EDC: .4byte 0xfffffe00
|
||||
thumb_func_end sub_8106E98
|
||||
|
79
data/data2.s
79
data/data2.s
@ -21370,44 +21370,63 @@ gUnknown_083EDE8C:: @ 83EDE8C
|
||||
gUnknown_083EEFE0:: @ 83EEFE0
|
||||
.incbin "baserom.gba", 0x003eefe0, 0x1b8
|
||||
|
||||
gUnknown_083EF198:: @ 83EF198
|
||||
.incbin "baserom.gba", 0x003ef198, 0x200
|
||||
.align 2
|
||||
gPictureFramePalettes:: @ 83EF198
|
||||
.incbin "graphics/picture_frame/bg0.gbapal"
|
||||
.incbin "graphics/picture_frame/bg1.gbapal"
|
||||
.incbin "graphics/picture_frame/bg2.gbapal"
|
||||
.incbin "graphics/picture_frame/bg3.gbapal"
|
||||
.incbin "graphics/picture_frame/bg4.gbapal"
|
||||
.incbin "graphics/picture_frame/bg5.gbapal"
|
||||
.space 10 * 32
|
||||
|
||||
gUnknown_083EF398:: @ 83EF398
|
||||
.incbin "baserom.gba", 0x003ef398, 0x1084
|
||||
.align 2
|
||||
gPictureFrameTiles_0:: @ 83EF398
|
||||
.incbin "graphics/picture_frame/frame0.4bpp.rl"
|
||||
|
||||
gUnknown_083F041C:: @ 83F041C
|
||||
.incbin "baserom.gba", 0x003f041c, 0xc30
|
||||
.align 2
|
||||
gPictureFrameTiles_1:: @ 83F041C
|
||||
.incbin "graphics/picture_frame/frame1.4bpp.rl"
|
||||
|
||||
gUnknown_083F104C:: @ 83F104C
|
||||
.incbin "baserom.gba", 0x003f104c, 0xb38
|
||||
.align 2
|
||||
gPictureFrameTiles_2:: @ 83F104C
|
||||
.incbin "graphics/picture_frame/frame2.4bpp.rl"
|
||||
|
||||
gUnknown_083F1B84:: @ 83F1B84
|
||||
.incbin "baserom.gba", 0x003f1b84, 0xfb8
|
||||
.align 2
|
||||
gPictureFrameTiles_3:: @ 83F1B84
|
||||
.incbin "graphics/picture_frame/frame3.4bpp.rl"
|
||||
|
||||
gUnknown_083F2B3C:: @ 83F2B3C
|
||||
.incbin "baserom.gba", 0x003f2b3c, 0x1130
|
||||
.align 2
|
||||
gPictureFrameTiles_4:: @ 83F2B3C
|
||||
.incbin "graphics/picture_frame/frame4.4bpp.rl"
|
||||
|
||||
gUnknown_083F3C6C:: @ 83F3C6C
|
||||
.incbin "baserom.gba", 0x003f3c6c, 0x5f4
|
||||
.align 2
|
||||
gPictureFrameTiles_5:: @ 83F3C6C
|
||||
.incbin "graphics/picture_frame/frame5.4bpp.rl"
|
||||
|
||||
gUnknown_083F4260:: @ 83F4260
|
||||
.incbin "baserom.gba", 0x003f4260, 0x50c
|
||||
.align 2
|
||||
gPictureFrameTilemap_0:: @ 83F4260
|
||||
.incbin "graphics/picture_frame/frame0_map.bin.rl"
|
||||
|
||||
gUnknown_083F476C:: @ 83F476C
|
||||
.incbin "baserom.gba", 0x003f476c, 0x50c
|
||||
.align 2
|
||||
gPictureFrameTilemap_1:: @ 83F476C
|
||||
.incbin "graphics/picture_frame/frame1_map.bin.rl"
|
||||
|
||||
gUnknown_083F4C78:: @ 83F4C78
|
||||
.incbin "baserom.gba", 0x003f4c78, 0x50c
|
||||
.align 2
|
||||
gPictureFrameTilemap_2:: @ 83F4C78
|
||||
.incbin "graphics/picture_frame/frame2_map.bin.rl"
|
||||
|
||||
gUnknown_083F5184:: @ 83F5184
|
||||
.incbin "baserom.gba", 0x003f5184, 0x50c
|
||||
.align 2
|
||||
gPictureFrameTilemap_3:: @ 83F5184
|
||||
.incbin "graphics/picture_frame/frame3_map.bin.rl"
|
||||
|
||||
gUnknown_083F5690:: @ 83F5690
|
||||
.incbin "baserom.gba", 0x003f5690, 0x50c
|
||||
.align 2
|
||||
gPictureFrameTilemap_4:: @ 83F5690
|
||||
.incbin "graphics/picture_frame/frame4_map.bin.rl"
|
||||
|
||||
gUnknown_083F5B9C:: @ 83F5B9C
|
||||
.incbin "baserom.gba", 0x003f5b9c, 0x510
|
||||
.align 2
|
||||
gPictureFrameTilemap_5:: @ 83F5B9C
|
||||
.incbin "graphics/picture_frame/frame5_map.bin.rl"
|
||||
|
||||
.align 2
|
||||
gUnknown_083F60AC:: @ 83F60AC
|
||||
@ -21450,9 +21469,13 @@ gUnknown_083F60C0:: @ 83F60C0
|
||||
.4byte OtherText_MightyTough
|
||||
.4byte OtherText_Exclamation
|
||||
|
||||
gUnknown_083F6138:: @ 83F6138
|
||||
.incbin "baserom.gba", 0x003f6138, 0x8
|
||||
.align 2
|
||||
gOamData_83F6138:: @ 83F6138
|
||||
.2byte 0x3000
|
||||
.2byte 0xC000
|
||||
.2byte 0x0000
|
||||
|
||||
.align 2
|
||||
gUnknown_083F6140:: @ 83F6140
|
||||
.space 4
|
||||
|
||||
|
19
graphics/picture_frame/bg0.pal
Normal file
19
graphics/picture_frame/bg0.pal
Normal file
@ -0,0 +1,19 @@
|
||||
JASC-PAL
|
||||
0100
|
||||
16
|
||||
0 0 0
|
||||
255 255 255
|
||||
230 230 230
|
||||
213 213 213
|
||||
197 197 197
|
||||
180 180 180
|
||||
164 164 164
|
||||
148 148 148
|
||||
131 131 131
|
||||
115 115 115
|
||||
98 98 98
|
||||
82 82 82
|
||||
65 65 65
|
||||
49 49 49
|
||||
32 32 32
|
||||
16 16 16
|
19
graphics/picture_frame/bg1.pal
Normal file
19
graphics/picture_frame/bg1.pal
Normal file
@ -0,0 +1,19 @@
|
||||
JASC-PAL
|
||||
0100
|
||||
16
|
||||
0 0 0
|
||||
90 24 0
|
||||
139 65 16
|
||||
164 90 16
|
||||
189 115 16
|
||||
222 148 49
|
||||
255 180 82
|
||||
255 222 131
|
||||
98 172 115
|
||||
148 197 156
|
||||
222 255 230
|
||||
255 255 255
|
||||
205 189 164
|
||||
180 164 139
|
||||
164 139 115
|
||||
131 98 74
|
19
graphics/picture_frame/bg2.pal
Normal file
19
graphics/picture_frame/bg2.pal
Normal file
@ -0,0 +1,19 @@
|
||||
JASC-PAL
|
||||
0100
|
||||
16
|
||||
0 0 0
|
||||
180 148 213
|
||||
180 164 197
|
||||
180 189 189
|
||||
180 205 180
|
||||
180 230 172
|
||||
189 255 164
|
||||
222 255 139
|
||||
246 238 123
|
||||
255 230 98
|
||||
255 205 139
|
||||
255 180 139
|
||||
238 164 189
|
||||
205 156 197
|
||||
255 246 255
|
||||
90 57 74
|
19
graphics/picture_frame/bg3.pal
Normal file
19
graphics/picture_frame/bg3.pal
Normal file
@ -0,0 +1,19 @@
|
||||
JASC-PAL
|
||||
0100
|
||||
16
|
||||
0 0 0
|
||||
255 123 164
|
||||
255 139 180
|
||||
255 180 205
|
||||
255 213 255
|
||||
255 205 0
|
||||
255 213 57
|
||||
255 230 123
|
||||
255 238 189
|
||||
255 255 255
|
||||
90 24 0
|
||||
139 65 16
|
||||
205 189 164
|
||||
180 164 139
|
||||
164 139 115
|
||||
131 98 74
|
19
graphics/picture_frame/bg4.pal
Normal file
19
graphics/picture_frame/bg4.pal
Normal file
@ -0,0 +1,19 @@
|
||||
JASC-PAL
|
||||
0100
|
||||
16
|
||||
0 0 0
|
||||
90 24 0
|
||||
139 65 16
|
||||
222 148 49
|
||||
255 222 131
|
||||
131 131 131
|
||||
65 65 65
|
||||
255 0 0
|
||||
255 82 82
|
||||
255 164 164
|
||||
255 98 197
|
||||
255 148 213
|
||||
255 197 230
|
||||
74 255 90
|
||||
131 255 139
|
||||
189 255 197
|
19
graphics/picture_frame/bg5.pal
Normal file
19
graphics/picture_frame/bg5.pal
Normal file
@ -0,0 +1,19 @@
|
||||
JASC-PAL
|
||||
0100
|
||||
16
|
||||
0 0 0
|
||||
90 24 0
|
||||
139 65 16
|
||||
222 148 49
|
||||
255 222 131
|
||||
131 131 131
|
||||
65 65 65
|
||||
74 148 238
|
||||
131 180 238
|
||||
189 213 246
|
||||
74 255 90
|
||||
131 255 139
|
||||
189 255 197
|
||||
255 255 0
|
||||
255 255 123
|
||||
0 0 0
|
BIN
graphics/picture_frame/frame0.png
Normal file
BIN
graphics/picture_frame/frame0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
graphics/picture_frame/frame0_map.bin
Normal file
BIN
graphics/picture_frame/frame0_map.bin
Normal file
Binary file not shown.
BIN
graphics/picture_frame/frame1.png
Normal file
BIN
graphics/picture_frame/frame1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.4 KiB |
BIN
graphics/picture_frame/frame1_map.bin
Normal file
BIN
graphics/picture_frame/frame1_map.bin
Normal file
Binary file not shown.
BIN
graphics/picture_frame/frame2.png
Normal file
BIN
graphics/picture_frame/frame2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
graphics/picture_frame/frame2_map.bin
Normal file
BIN
graphics/picture_frame/frame2_map.bin
Normal file
Binary file not shown.
BIN
graphics/picture_frame/frame3.png
Normal file
BIN
graphics/picture_frame/frame3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
BIN
graphics/picture_frame/frame3_map.bin
Normal file
BIN
graphics/picture_frame/frame3_map.bin
Normal file
Binary file not shown.
BIN
graphics/picture_frame/frame4.png
Normal file
BIN
graphics/picture_frame/frame4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
BIN
graphics/picture_frame/frame4_map.bin
Normal file
BIN
graphics/picture_frame/frame4_map.bin
Normal file
Binary file not shown.
BIN
graphics/picture_frame/frame5.png
Normal file
BIN
graphics/picture_frame/frame5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 643 B |
BIN
graphics/picture_frame/frame5_map.bin
Normal file
BIN
graphics/picture_frame/frame5_map.bin
Normal file
Binary file not shown.
4
misc.mk
4
misc.mk
@ -7,6 +7,7 @@ UNKNOWNGFXDIR := graphics/unknown
|
||||
REELGFXDIR := graphics/slot_machine
|
||||
ROULGFXDIR := graphics/roulette
|
||||
BTLANMSPRGFXDIR := graphics/battle_anims/sprites
|
||||
PICFRAMEGFXDIR := graphics/picture_frame
|
||||
|
||||
$(MENUGFXDIR)/menu.gbapal: $(MENUGFXDIR)/menu_0.gbapal $(MENUGFXDIR)/menu_1.gbapal
|
||||
|
||||
@ -157,3 +158,6 @@ $(BTLANMSPRGFXDIR)/141.4bpp: $(BTLANMSPRGFXDIR)/141_0.4bpp $(BTLANMSPRGFXDIR)/14
|
||||
|
||||
$(BTLANMSPRGFXDIR)/159.4bpp: $(BTLANMSPRGFXDIR)/159_0.4bpp $(BTLANMSPRGFXDIR)/159_1.4bpp
|
||||
@cat $(BTLANMSPRGFXDIR)/159_0.4bpp $(BTLANMSPRGFXDIR)/159_1.4bpp >$@
|
||||
|
||||
$(PICFRAMEGFXDIR)/frame5.4bpp: $(PICFRAMEGFXDIR)/frame5.png
|
||||
$(GFX) $< $@ -num_tiles 86
|
||||
|
@ -4,11 +4,11 @@ CFLAGS = -Wall -Wextra -std=c11 -O2 -DPNG_SKIP_SETJMP_CHECK
|
||||
|
||||
LIBS = -lpng -lz
|
||||
|
||||
SRCS = main.c convert_png.c gfx.c jasc_pal.c lz.c util.c font.c
|
||||
SRCS = main.c convert_png.c gfx.c jasc_pal.c lz.c rl.c util.c font.c
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
gbagfx: $(SRCS) convert_png.h gfx.h global.h jasc_pal.h lz.h util.h font.h
|
||||
gbagfx: $(SRCS) convert_png.h gfx.h global.h jasc_pal.h lz.h rl.h util.h font.h
|
||||
$(CC) $(CFLAGS) $(SRCS) -o $@ $(LIBS)
|
||||
|
||||
clean:
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "convert_png.h"
|
||||
#include "jasc_pal.h"
|
||||
#include "lz.h"
|
||||
#include "rl.h"
|
||||
#include "font.h"
|
||||
|
||||
struct CommandHandler
|
||||
@ -289,6 +290,36 @@ void HandleLZDecompressCommand(char *inputPath, char *outputPath, int argc UNUSE
|
||||
free(uncompressedData);
|
||||
}
|
||||
|
||||
void HandleRLCompressCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
|
||||
{
|
||||
int fileSize;
|
||||
unsigned char *buffer = ReadWholeFile(inputPath, &fileSize);
|
||||
|
||||
int compressedSize;
|
||||
unsigned char *compressedData = RLCompress(buffer, fileSize, &compressedSize);
|
||||
|
||||
free(buffer);
|
||||
|
||||
WriteWholeFile(outputPath, compressedData, compressedSize);
|
||||
|
||||
free(compressedData);
|
||||
}
|
||||
|
||||
void HandleRLDecompressCommand(char *inputPath, char *outputPath, int argc UNUSED, char **argv UNUSED)
|
||||
{
|
||||
int fileSize;
|
||||
unsigned char *buffer = ReadWholeFile(inputPath, &fileSize);
|
||||
|
||||
int uncompressedSize;
|
||||
unsigned char *uncompressedData = RLDecompress(buffer, fileSize, &uncompressedSize);
|
||||
|
||||
free(buffer);
|
||||
|
||||
WriteWholeFile(outputPath, uncompressedData, uncompressedSize);
|
||||
|
||||
free(uncompressedData);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3)
|
||||
@ -312,6 +343,8 @@ int main(int argc, char **argv)
|
||||
{ "png", "fwjpnfont", HandlePngToFullwidthJapaneseFontCommand },
|
||||
{ NULL, "lz", HandleLZCompressCommand },
|
||||
{ "lz", NULL, HandleLZDecompressCommand },
|
||||
{ NULL, "rl", HandleRLCompressCommand },
|
||||
{ "rl", NULL, HandleRLDecompressCommand },
|
||||
{ NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
|
143
tools/gbagfx/rl.c
Normal file
143
tools/gbagfx/rl.c
Normal file
@ -0,0 +1,143 @@
|
||||
// Copyright (c) 2016 YamaArashi
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include "global.h"
|
||||
#include "rl.h"
|
||||
|
||||
unsigned char *RLDecompress(unsigned char *src, int srcSize, int *uncompressedSize)
|
||||
{
|
||||
if (srcSize < 4)
|
||||
goto fail;
|
||||
|
||||
int destSize = (src[3] << 16) | (src[2] << 8) | src[1];
|
||||
|
||||
unsigned char *dest = malloc(destSize);
|
||||
|
||||
if (dest == NULL)
|
||||
goto fail;
|
||||
|
||||
int srcPos = 4;
|
||||
int destPos = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (srcPos >= srcSize)
|
||||
goto fail;
|
||||
|
||||
unsigned char flags = src[srcPos++];
|
||||
bool compressed = ((flags & 0x80) != 0);
|
||||
|
||||
if (compressed)
|
||||
{
|
||||
int length = (flags & 0x7F) + 3;
|
||||
unsigned char data = src[srcPos++];
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
dest[destPos++] = data;
|
||||
}
|
||||
else
|
||||
{
|
||||
int length = (flags & 0x7F) + 1;
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
dest[destPos++] = src[srcPos++];
|
||||
}
|
||||
|
||||
if (destPos == destSize)
|
||||
{
|
||||
*uncompressedSize = destSize;
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
FATAL_ERROR("Fatal error while decompressing RL file.\n");
|
||||
}
|
||||
|
||||
unsigned char *RLCompress(unsigned char *src, int srcSize, int *compressedSize)
|
||||
{
|
||||
if (srcSize <= 0)
|
||||
goto fail;
|
||||
|
||||
int worstCaseDestSize = 4 + srcSize * 2;
|
||||
|
||||
// Round up to the next multiple of four.
|
||||
worstCaseDestSize = (worstCaseDestSize + 3) & ~3;
|
||||
|
||||
unsigned char *dest = malloc(worstCaseDestSize);
|
||||
|
||||
if (dest == NULL)
|
||||
goto fail;
|
||||
|
||||
// header
|
||||
dest[0] = 0x30; // RL compression type
|
||||
dest[1] = (unsigned char)srcSize;
|
||||
dest[2] = (unsigned char)(srcSize >> 8);
|
||||
dest[3] = (unsigned char)(srcSize >> 16);
|
||||
|
||||
int srcPos = 0;
|
||||
int destPos = 4;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
bool compress = false;
|
||||
int uncompressedStart = srcPos;
|
||||
int uncompressedLength = 0;
|
||||
|
||||
while (srcPos < srcSize && uncompressedLength < (0x7F + 1))
|
||||
{
|
||||
compress = (srcPos + 2 < srcSize && src[srcPos] == src[srcPos + 1] && src[srcPos] == src[srcPos + 2]);
|
||||
|
||||
if (compress)
|
||||
break;
|
||||
|
||||
srcPos++;
|
||||
uncompressedLength++;
|
||||
}
|
||||
|
||||
if (uncompressedLength > 0)
|
||||
{
|
||||
dest[destPos++] = uncompressedLength - 1;
|
||||
|
||||
for (int i = 0; i < uncompressedLength; i++)
|
||||
dest[destPos++] = src[uncompressedStart + i];
|
||||
}
|
||||
|
||||
if (compress)
|
||||
{
|
||||
unsigned char data = src[srcPos];
|
||||
int compressedLength = 0;
|
||||
|
||||
while (compressedLength < (0x7F + 3)
|
||||
&& srcPos + compressedLength < srcSize
|
||||
&& src[srcPos + compressedLength] == data)
|
||||
{
|
||||
compressedLength++;
|
||||
}
|
||||
|
||||
dest[destPos++] = 0x80 | (compressedLength - 3);
|
||||
dest[destPos++] = data;
|
||||
|
||||
srcPos += compressedLength;
|
||||
}
|
||||
|
||||
if (srcPos == srcSize)
|
||||
{
|
||||
// Pad to multiple of 4 bytes.
|
||||
int remainder = destPos % 4;
|
||||
|
||||
if (remainder != 0)
|
||||
{
|
||||
for (int i = 0; i < 4 - remainder; i++)
|
||||
dest[destPos++] = 0;
|
||||
}
|
||||
|
||||
*compressedSize = destPos;
|
||||
return dest;
|
||||
}
|
||||
}
|
||||
|
||||
fail:
|
||||
FATAL_ERROR("Fatal error while compressing RL file.\n");
|
||||
}
|
9
tools/gbagfx/rl.h
Normal file
9
tools/gbagfx/rl.h
Normal file
@ -0,0 +1,9 @@
|
||||
// Copyright (c) 2016 YamaArashi
|
||||
|
||||
#ifndef RL_H
|
||||
#define RL_H
|
||||
|
||||
unsigned char *RLDecompress(unsigned char *src, int srcSize, int *uncompressedSize);
|
||||
unsigned char *RLCompress(unsigned char *src, int srcSize, int *compressedSize);
|
||||
|
||||
#endif // RL_H
|
Loading…
Reference in New Issue
Block a user