Page 1 of 1

Files into elf

Posted: Thu Feb 21, 2008 7:18 am
by methos3
Hello.
Any of you know what I have to do to put irxs, fonts , images and etc into an elf file?
Like SMS, uLaunchelf and so on...
I searched on SMS source for a way to do this and didn't find...

Can someone help me?

Posted: Thu Feb 21, 2008 7:39 am
by cosmito
SMS does this. At SMS_Data.c, the buffer g_DataBuffer contains several irx embedded into a char array.

Posted: Thu Feb 21, 2008 7:54 am
by Mega Man
You need to use programs like bin2s and bin2c to create files you can link to your program and then load it with:

Code: Select all

int rv;
int ret;

ret = SifExecModuleBuffer(startaddress, size, argLen, args, &rv);
if &#40;ret < 0&#41; &#123;
    rv = ret;
&#125;
if &#40;rv < 0&#41; &#123;
    printf&#40;"Failed to load module."&#41;;
&#125;

Posted: Thu Feb 21, 2008 8:39 am
by Lukasz
Check the PS2Link source, it embeds the IRX's into the ELF.

Posted: Thu Feb 21, 2008 12:02 pm
by methos3
hm, ok, and how about fonts and images?
what file of SMS source contains some images (png, jpg, etc...) or fonts(arial, etc...)?

[edit]
I saw that bmp2c on Dreamtime's Tutorial, but I don't know if this will work with the gsKit.
Any of you know a way to convert kpeg to a code that can be used on the gsKit?

Posted: Sat Feb 23, 2008 10:33 pm
by Mega Man
Here are examples for extracting image data:

http://mitglied.lycos.de/ps2dev/examples/jpgloader.c
http://mitglied.lycos.de/ps2dev/examples/jpgloader.h
http://mitglied.lycos.de/ps2dev/examples/pngloader.c
http://mitglied.lycos.de/ps2dev/examples/pngloader.h
http://mitglied.lycos.de/ps2dev/examples/bmpreader.c
http://mitglied.lycos.de/ps2dev/examples/bmpreader.h

You need just to provide the rom interface or copy the files from kernelloader. When you copy it you need also to copy some parts of the Makefile.

The function "getTexture" in kernelloader shows how to pass the extracted result to gsKit.

There a more examples in kernelloader:
png2rgb and ppm2rgb

The programs convert the image to raw image format.

Posted: Sun Feb 24, 2008 1:58 am
by cosmito
Cool files, Mega Man!

Posted: Sun Feb 24, 2008 9:00 am
by methos3
yeah, the jpgloader and etc are great and better than Dreamtime's ones, but I tryed to open the kernelloader and got an error on both winzip and winrar.
Do you have a non-corrupted copy of the kernelloader?

thanks!

Posted: Sun Feb 24, 2008 11:55 pm
by methos3
hey!
I have an idea!
That bmb2c from Tony Savesky gives a .c file that have the width, height, a array that contains the colors, right?
And if I pass the colors to the gsKit using gsKit_prim_point (for original width and height), or gsKit_prim_sprite or even g2_print_quad acording to the cordinates and colors contained on the bmb converted into c?
That colors can be passed to the gsKit with no problem?

Or if anyone have the non-corrupted kernel loader source, it's even better ^^.

Posted: Mon Feb 25, 2008 1:08 am
by deba5er
I use 7-zip (www.7-zip.org) to open .tgz archives. I just re-downloaded the kernelloader source package and opened it with 7-zip to verify that it is not corrupt.

Posted: Mon Feb 25, 2008 1:28 am
by methos3
it's exactly 7-zip that I use and i'm still getting an error message talking about corrupted file, and when I search for any file with the "getTexture" function, no one of the files have this function (and no functions referrencing to gsKit)

Posted: Mon Feb 25, 2008 6:57 am
by J.F.
The tgz's test fine for me. I guess you are having trouble downloading the file correctly. Try using wget from the commandline to download the file.

Posted: Mon Feb 25, 2008 10:18 am
by Mega Man
The functions in the files return a pointer to a raw image format. The function getTexture() is located in kernelloader and it loads a raw image into VRAM. When the newest tgz is not working, you can also try older onces.

Posted: Mon Feb 25, 2008 10:33 am
by methos3
ok, i downloaded the kernelloader 1.5 correctly, and saw the getTexture funtcion, but where are the "romfilelist.h" and "romdefinitions.h" that are needed?

ps.: this kernelloader is a great code, and very nice.
[edit]

ok, got it...

Code: Select all

romfilelist.h&#58; $&#40;RGB_HEADERS&#41; $&#40;RGB_FILES&#41;
	rm -f romfilelist.h
	for file in $&#40;ROM_FILES&#41;; do \
		echo "&#123; \"$$file\", NULL, 0, 0, 0, 0&#125;," >> romfilelist.h; \
	done

romdefinitions.h&#58;
	rm -f romdefinitions.h
	for file in $&#40;subst -,_,$&#40;subst .,_,$&#40;subst /,_,$&#40;ROM_FILES&#41;&#41;&#41;&#41;; do \
		echo "extern unsigned char $$file&#91;&#93;;" >> romdefinitions.h; \
		echo "extern int size_$$file;" >> romdefinitions.h; \
	done

rominitialize.h&#58; $&#40;RGBFILES&#41;
	rm -f rominitialize.h
	for file in $&#40;subst -,_,$&#40;subst .,_,$&#40;subst /,_,$&#40;ROM_FILES&#41;&#41;&#41;&#41;; do \
		if &#91; "$$&#123;file&#58; -3&#58;3&#125;" = "rgb" &#93;; then \
			echo "#include \"$$&#123;file&#125;\"" | sed -e "s/_rgb\"/\.h\"/g" >> rominitialize.h; \
		fi; \
	done
	for file in $&#40;subst -,_,$&#40;subst .,_,$&#40;subst /,_,$&#40;ROM_FILES&#41;&#41;&#41;&#41;; do \
		echo "rom_files&#91;i&#93;.start = $$file;" >> rominitialize.h; \
		echo "rom_files&#91;i&#93;.size = size_$$file;" >> rominitialize.h; \
		if &#91; "$$&#123;file&#58; -3&#58;3&#125;" = "rgb" &#93;; then \
			ufile="`echo $$file | perl -n -e \"s/_rgb\$$//g; print uc&#40;$$@&#41;;\"`"; \
			echo "rom_files&#91;i&#93;.width = $$&#123;ufile&#125;_WIDTH;" >> rominitialize.h; \
			echo "rom_files&#91;i&#93;.height = $$&#123;ufile&#125;_HEIGHT;" >> rominitialize.h; \
			echo "rom_files&#91;i&#93;.depth = $$&#123;ufile&#125;_DEPTH;" >> rominitialize.h; \
		fi; \
		echo "i++;" >> rominitialize.h; \
	done
sorry for asking whihout looking the Makefile.
so these files only includes the irx's to the Makefile, huh?
but romimitialize contains some texture loading...
I only have to copy this part of the makefile and use the convert tools on the source?

I have to copy this part too?

Code: Select all

%_irx.s&#58; %.irx
	rm -f [email protected]
	rm -f $@
	bin2s $^ [email protected] $&#40;subst -,_,$&#40;subst /,_,$*&#41;&#41;_irx
	sed -e "s/\.data/.section .rom/g" <[email protected] >$@
	rm -f [email protected]

%_elf.s&#58; %.elf
	bin2s $^ $@ $&#40;subst -,_,$&#40;subst /,_,$*&#41;&#41;_elf

%_rgb.s&#58; %.rgb
	rm -f [email protected]
	rm -f $@
	bin2s $^ [email protected] $&#40;subst -,_,$&#40;subst /,_,$*&#41;&#41;_rgb
	sed -e "s/\.data/.section .rom/g" <[email protected] >$@
	rm -f [email protected]

%.rgb %.h&#58; %.ppm ../ppm2rgb/ppm2rgb
	../ppm2rgb/ppm2rgb $*.ppm $*.rgb $*.h $*

%.rgb %.h&#58; %.png ../png2rgb/png2rgb
	../png2rgb/png2rgb $*.png $*.rgb $*.h $*

.depend/%.d&#58; %.c
	mkdir -p .depend
	$&#40;EE_CC&#41; -E -M -MG $&#40;EE_CFLAGS&#41; $&#40;EE_INCS&#41; $< >$@

.depend/%.d&#58; %.cpp
	mkdir -p .depend
	$&#40;EE_CXX&#41; -E -M -MG $&#40;EE_CXXFLAGS&#41; $&#40;EE_INCS&#41; $< >$@
[edit again]
so the functions returns a pointer to the raw image.
but for example getTexture requires a filename, and not a pointer.
there is any example of using an raw image pointer on gsKit?

Posted: Tue Feb 26, 2008 3:45 am
by methos3
hey, sorry for asking whihout seeing the code...
I saw how the png2raw works passing the code to the program.
I typed make on the "loader" dir to see what kind of files would appear, and after some linking messages and all... I got an error talking about a file "/cygdrive/ps2dev/ee... and so on"(it's a .h file). I don't use cygwin, and why I received this mesage? I checked the Makefile.pref and didn't see anything talking about cygdrive...

Posted: Tue Feb 26, 2008 7:22 am
by Mega Man
I believe one environment variable is set to cygwin. The README describes how to build kernelloader (including ps2sdk and required modules).
You can't just run "make" in loader directory, because there are some files needed.

Here is a simplified version of the Makefile. You need just to copy "rom.c", "rom.h" and "cloud.png" into the directory and generate a "hello.c". The rgb stuff is removed.

Code: Select all

PROGRAM = hello

EE_BIN = $&#40;PROGRAM&#41;.elf
EE_OBJS = hello.o rom.o
EE_FLAGS += -Wall -W -Wimplicit-int -Werror-implicit-function-declaration
EE_OBJS += $&#40;addsuffix .o, $&#40;subst .,_,$&#40;ROM_FILES&#41;&#41;&#41;

MODULES = ioptrap.irx iomanX.irx ps2dev9.irx ps2ip.irx poweroff.irx

ROM_FILES += \
	$&#40;MODULES&#41; \
	cloud.png

all&#58; $&#40;EE_BIN&#41;

$&#40;MODULES&#41;&#58;
	for file in $&#40;MODULES&#41;; do cp $&#40;PS2SDK&#41;/iop/irx/$$file .; done

rom.o&#58; rom.c romfilelist.h romdefinitions.h rominitialize.h

clean&#58;
	rm -f $&#40;EE_BIN&#41; $&#40;EE_OBJS&#41; $&#40;MODULES&#41;
	rm -f romfilelist.h romdefinitions.h rominitialize.h
	rm -f $&#40;addsuffix .s,$&#40;subst .,_,$&#40;ROM_FILES&#41;&#41;&#41;
	rm -f $&#40;addsuffix .o,$&#40;subst .,_,$&#40;ROM_FILES&#41;&#41;&#41;
	rm -rf .depend

romfilelist.h&#58;
	rm -f romfilelist.h
	for file in $&#40;ROM_FILES&#41;; do \
		echo "&#123; \"$$file\", NULL, 0, 0, 0, 0&#125;," >> romfilelist.h; \
	done

romdefinitions.h&#58;
	rm -f romdefinitions.h
	for file in $&#40;subst -,_,$&#40;subst .,_,$&#40;subst /,_,$&#40;ROM_FILES&#41;&#41;&#41;&#41;; do \
		echo "extern unsigned char $$file&#91;&#93;;" >> romdefinitions.h; \
		echo "extern int size_$$file;" >> romdefinitions.h; \
	done

rominitialize.h&#58;
	rm -f rominitialize.h
	for file in $&#40;subst -,_,$&#40;subst .,_,$&#40;subst /,_,$&#40;ROM_FILES&#41;&#41;&#41;&#41;; do \
		echo "rom_files&#91;i&#93;.start = $$file;" >> rominitialize.h; \
		echo "rom_files&#91;i&#93;.size = size_$$file;" >> rominitialize.h; \
		echo "i++;" >> rominitialize.h; \
	done

%_irx.s&#58; %.irx
	rm -f $@
	bin2s $^ $@ $&#40;subst -,_,$&#40;subst /,_,$*&#41;&#41;_irx

%_elf.s&#58; %.elf
	rm -f $@
	bin2s $^ $@ $&#40;subst -,_,$&#40;subst /,_,$*&#41;&#41;_elf

%_png.s&#58; %.png
	rm -f $@
	bin2s $^ $@ $&#40;subst -,_,$&#40;subst /,_,$*&#41;&#41;_png

.depend/%.d&#58; %.c
	mkdir -p .depend
	$&#40;EE_CC&#41; -E -M -MG $&#40;EE_CFLAGS&#41; $&#40;EE_INCS&#41; $< >$@

.depend/%.d&#58; %.cpp
	mkdir -p .depend
	$&#40;EE_CXX&#41; -E -M -MG $&#40;EE_CXXFLAGS&#41; $&#40;EE_INCS&#41; $< >$@

include $&#40;PS2SDK&#41;/samples/Makefile.pref
include $&#40;PS2SDK&#41;/samples/Makefile.eeglobal
ifneq &#40;$&#40;MAKECMDGOALS&#41;,clean&#41;
-include $&#40;addprefix .depend/,$&#40;subst .o,.d, $&#40;EE_OBJS&#41;&#41;&#41;
endif
If you want to support other file formats, you need to copy the png rules.

Posted: Tue Feb 26, 2008 10:32 am
by methos3
Thanks!
I didn't run Make to see everything being compiled allright, , only to see if it would get in the part that does the conversion from png into rgb.
Later I will test this Makefile to compile a hello.

Posted: Wed Feb 27, 2008 6:46 am
by methos3
hey, only a little other thing.
The libpng that the ps2 (not pc) functions need is the same lipng for pc?
Or the svn have any libpng?
And for example:
If I have a Texture like this:

GSTEXTURE *tex = NULL;
I can use this:

uint32 test = NULL;
test = loadPng(file_name, width, height, *depth);
tex->mem = test;
// And all the rest...

To load a texture?

Or I have to use this?

rom_entry_t *test;
test = rom_getFile(file_name);
tex->mem = test.start;
// And all the rest...

Posted: Thu Feb 28, 2008 7:02 am
by Mega Man
The libpng is in the SVN at ps2sdk-ports/libpng.

The first code is for loading PNGs directly.
The second code is for loading raw image files created by png2rgb.

Posted: Thu Feb 28, 2008 10:48 am
by methos3
So I only will need a uint32 to do all the job.
Today some hours ago I googled for the libpng for ps2dev and got the ps2sdk-ports/libpng directory. I didn't download yet, but later I will do this.
Thanks, friend!