Why does it not work?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Why does it not work?

Post by blu_eye4 »

Hello guys!

Ok, I've a big problem that i don't know how i must resolve... I'm making a little didactic homebrew that dump flash0 and 1 using vlf library but I've a problem: when i play the homebrew on my psp I receive an error that advices me that a library isn't found by psp... It's astonishing in my opinion... look at the code:

this is the main file:

Code: Select all

#include <pspkernel.h>
#include <stdlib.h>
#include <vlf.h>
#include <pspctrl.h>
#include "dump.h"
#include <pspumd.h>

#include "graphics.h" 

PSP_MODULE_INFO&#40;"VLFTest", 0, 1, 0&#41;; 
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

void *ReadFileAllocEx&#40;char *file, int seek, int size, int *retSize&#41;;

int done = 0;

int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	done = 1;
	return 0;
&#125;

int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;
	sceKernelSleepThreadCB&#40;&#41;;

	return 0;
&#125;

int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

int app_main&#40;int argc, char *argv&#91;&#93;&#41;
&#123;
    
    
    sceIoUnassign&#40;"flash0&#58;"&#41;;
    sceIoAssign&#40;"flash0&#58;", "lflash0&#58;0,0", "flashfat0&#58;", IOASSIGN_RDWR, NULL, 0&#41;;
    sceIoUnassign&#40;"flash1&#58;"&#41;;
    sceIoAssign&#40;"flash1&#58;", "lflash1&#58;0,1", "flashfat1&#58;", IOASSIGN_RDWR, NULL, 0&#41;;
    SceCtrlLatch latch;
	SetupCallbacks&#40;&#41;;
	void *bi;
	void *data = ReadFileAllocEx&#40;"flash0&#58;/vsh/resource/01-12.bmp", 7*6176, 6176, NULL&#41;;
	
	if &#40;!data || vlfGuiSetBackgroundFileBuffer&#40;data, 6176&#41; < 0&#41;
	&#123;
		vlfGuiSetBackgroundPlane&#40;0xFF000000&#41;;
	&#125;
	
	if &#40;data&#41;
		free&#40;data&#41;;
	 
	vlfGuiCacheResource&#40;"system_plugin"&#41;;
	vlfGuiCacheResource&#40;"system_plugin_fg"&#41;;
	
	vlfGuiSetModelSystem&#40;&#41;;
	vlfGuiAddBatteryIconSystem&#40;&bi, 10*1000*1000&#41;;
	vlfGuiAddClock&#40;&#41;; 
	 
	
	 while&#40;!done&#41;
	&#123;
		vlfGuiDrawFrame&#40;&#41;;
		        sceCtrlReadLatch&#40;&latch&#41;;
		        
		        vlfGuiAddText&#40;5, 5, "DumperXflash v.2,0 by blu_eye4\n"&#41;;
                vlfGuiAddText&#40;5, 25, "Ringrazio fortemente il forum ps2dev.org per l'aiuto\n"&#41;;
                vlfGuiAddText&#40;5, 45, "Voglio ringraziare fortemente il forum psp-ita.com\n"&#41;;
                vlfGuiAddText&#40;5, 65, "Non solo per l'aiuto, ma anche perchè mi sopportano &#58;&#41;\n"&#41;;
                vlfGuiAddText&#40;5, 85, "Grazie a tyrannid per gli esempi sdk\n"&#41;;
                vlfGuiAddText&#40;5, 135, "Premere tasto X per dump flash0\n"&#41;;
                vlfGuiAddText&#40;5, 155, "Premere tasto O per dump flash1\n"&#41;;		        
    if&#40;latch.uiMake & PSP_CTRL_CIRCLE&#41;
    &#123;
         dump_filesystem&#40;"flash1&#58;/", "ms0&#58;/flash1"&#41;;
         vlfGuiAddText&#40;235, 180, "Dump effettuato\n"&#41;;
         vlfGuiAddText&#40;235, 190, "Premere &#91;Home&#93;per tornare nella XMB\n"&#41;;            
	
    &#125;	


if&#40;latch.uiMake & PSP_CTRL_CROSS&#41;
    &#123;
         dump_filesystem&#40;"flash0&#58;/", "ms0&#58;/flash0"&#41;;
         vlfGuiAddText&#40;235, 180, "Dump effettuato\n"&#41;;  
         vlfGuiAddText&#40;235, 190, "Premere &#91;Home&#93;per tornare nella XMB\n"&#41;;
	&#125;

&#125;
	sceKernelExitGame&#40;&#41;;
   	return 0;
&#125;

this is my dump header (i know that there aren't my function :():

Code: Select all

#ifndef DUMP_H_INCLUDED
#define DUMP_H_INCLUDED


#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspumd.h>
#include <vlf.h>

/* Build a path, append a directory slash if requested */
void build_path&#40;char *output, const char *root, const char *path, int append&#41;
&#123;
	while&#40;*root != 0&#41;
	&#123;
		*output++ = *root++;
	&#125;

	if&#40;*&#40;root-1&#41; != '/'&#41;
	&#123;
		*output++ = '/';
	&#125;

	while&#40;*path != 0&#41;
	&#123;
		*output++ = *path++;
	&#125;
	if&#40;append&#41;
		*output++ = '/';

	*output++ = 0;
&#125;

/* Define a write buffer */
char write_buffer&#91;128*1024&#93;;

void write_file&#40;const char *read_loc, const char *write_loc, const char *name&#41;
&#123;
	int fdin;
	int fdout;
	char readpath&#91;256&#93;;
	char writepath&#91;256&#93;;
    void ScreenClear&#40;&#41;;
	build_path&#40;readpath, read_loc, name, 0&#41;;
	build_path&#40;writepath, write_loc, name, 0&#41;;
	vlfGuiAddTextF&#40;100, 100, "scrivendo %s\n", writepath&#41;;
    ScreenClear&#40;&#41;;
	fdin = sceIoOpen&#40;readpath, PSP_O_RDONLY, 0777&#41;;
	if&#40;fdin >= 0&#41;
	&#123;
		int bytesRead = 1;
		fdout = sceIoOpen&#40;writepath, PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;;
		if&#40;fdout < 0&#41;
		&#123;
			vlfGuiAddTextF&#40;100, 100, "impossibile aprire %s\n", writepath&#41;;
		&#125;

		bytesRead = sceIoRead&#40;fdin, write_buffer, sizeof&#40;write_buffer&#41;&#41;;
		while&#40;&#40;bytesRead > 0&#41; && &#40;fdout >= 0&#41;&#41;
		&#123;
			sceIoWrite&#40;fdout, write_buffer, bytesRead&#41;;
			bytesRead = sceIoRead&#40;fdin, write_buffer, sizeof&#40;write_buffer&#41;&#41;;
		&#125;

		if&#40;fdout >= 0&#41;
		&#123;
			sceIoClose&#40;fdout&#41;;
		&#125;

		if&#40;fdin >= 0&#41;
		&#123;
			sceIoClose&#40;fdin&#41;;
		&#125;
	&#125;
	else
	&#123;
		vlfGuiAddTextF&#40;100, 100, "Couldn't open %s\n", readpath&#41;;
	&#125;
&#125;


/* Dump a filing system */
void dump_filesystem&#40;const char *root, const char *write_loc&#41;
&#123;
	int dfd;
	char next_root&#91;256&#93;;
	char next_write&#91;256&#93;;

	sceIoMkdir&#40;write_loc, 0777&#41;;

	dfd = sceIoDopen&#40;root&#41;;
	if&#40;dfd > 0&#41;
	&#123;
		SceIoDirent dir;

		while&#40;sceIoDread&#40;dfd, &dir&#41; > 0&#41;
		&#123;
			if&#40;dir.d_stat.st_attr & FIO_SO_IFDIR&#41;
			&#123;
				if&#40;dir.d_name&#91;0&#93; != '.'&#41;
				&#123;
					build_path&#40;next_write, write_loc, dir.d_name, 0&#41;;
					build_path&#40;next_root, root, dir.d_name, 1&#41;;
					dump_filesystem&#40;next_root, next_write&#41;;
				&#125;
			&#125;
			else
			&#123;
				write_file&#40;root, write_loc, dir.d_name&#41;;
			&#125;
		&#125;
		sceIoDclose&#40;dfd&#41;;
	&#125;
&#125;

/* Dump memory */
void dump_memory&#40;void&#41;
&#123;
	int fd;

	vlfGuiAddTextF&#40;100, 100, "Dumping 28Megs from 0x8400000\n"&#41;;
	fd = sceIoOpen&#40;"ms0&#58;/MEMORY.BIN", PSP_O_CREAT | PSP_O_TRUNC | PSP_O_WRONLY, 0777&#41;;
	if&#40;fd >= 0&#41;
	&#123;
		sceIoWrite&#40;fd, &#40;void *&#41; 0x8400000, 28*1024*1024&#41;;
		sceIoClose&#40;fd&#41;;
	&#125;
&#125;

/* Dumps flash rom in bits */
void dump_flashrom&#40;int lower&#41;
&#123;
	int fdin;
	int fdout;

	fdin = sceIoOpen&#40;"lflash&#58;", PSP_O_RDONLY, 0777&#41;;
	if&#40;fdin > 0&#41;
	&#123;
		int i;
		int bytes_read;

		if&#40;lower&#41;
		&#123;
			fdout = sceIoOpen&#40;"ms0&#58;/flash_lower.bin", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;;
		&#125;
		else
		&#123;
			fdout = sceIoOpen&#40;"ms0&#58;/flash_upper.bin", PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777&#41;;
		&#125;

		if&#40;fdout > 0&#41;
		&#123;
			for&#40;i = 0; i < &#40;&#40;16 * 1024 * 1024&#41; / sizeof&#40;write_buffer&#41;&#41;; i++&#41;
			&#123;
				bytes_read = sceIoRead&#40;fdin, write_buffer, sizeof&#40;write_buffer&#41;&#41;;
				if&#40;lower&#41;
				&#123;
					sceIoWrite&#40;fdout, write_buffer, bytes_read&#41;;
				&#125;
			&#125;

			if&#40;!lower&#41;
			&#123;
				for&#40;i = 0; i < &#40;&#40;16 * 1024 * 1024&#41; / sizeof&#40;write_buffer&#41;&#41;; i++&#41;
				&#123;
					bytes_read = sceIoRead&#40;fdin, write_buffer, sizeof&#40;write_buffer&#41;&#41;;
					sceIoWrite&#40;fdout, write_buffer, bytes_read&#41;;
				&#125;
			&#125;

			sceIoClose&#40;fdout&#41;;
		&#125;

		sceIoClose&#40;fdin&#41;;
	&#125;
	else
	&#123;
		vlfGuiAddText&#40;100, 100, "Cannot open lflash&#58; device\n"&#41;;
		sceKernelSleepThread&#40;&#41;;
	&#125;
&#125;



#endif // DUMP_H_INCLUDED
and this is the main of .s file that i include in the homebrew...

Code: Select all

#include <pspsdk.h>
#include <pspkernel.h>
#include <pspdisplay_kernel.h>
#include <pspctrl.h>
#include <pspumd.h>
#include <pspdebug.h>


PSP_MODULE_INFO&#40;"myLib", 0x1006, 1, 1&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;

u32 k1;


void ScreenClear&#40;&#41;&#123;
    k1 = pspSdkSetK1&#40;0&#41;;
    void pspDebugScreenClear&#40;void&#41;;
    pspDebugScreenClear&#40;&#41;;
    pspSdkSetK1&#40;k1&#41;;
&#125;


void CheckUmd&#40;&#41;&#123;
    k1 = pspSdkSetK1&#40;0&#41;;
    int sceUmdCheckMedium&#40;void&#41;;
    sceUmdCheckMedium&#40;&#41;;
    pspSdkSetK1&#40;k1&#41;;
&#125;

int padControls&#40;&#41;&#123;
    k1 = pspSdkSetK1&#40;0&#41;;
    sceCtrlReadBufferPositive&#40;SceCtrlData *pad_data, int count&#41;;
    pspSdkSetK1&#40;k1&#41;;
    return 0;
&#125;

int module_start&#40;SceSize args, void *argp&#41;
&#123;
   return 0;
&#125;

int module_stop&#40;&#41;
&#123;
   return 0;
&#125;

where do I fail? thanks a lot for your help :) ...
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

I'm not sure, but the vlf programs has to be loaded in vsh mode!
Try this:

Code: Select all

PSP_MODULE_INFO&#40;"VLFTest", 0x800, 1, 0&#41;;
PSP_MAIN_THREAD_ATTR&#40;0&#41;;
Last edited by ne0h on Tue Nov 11, 2008 2:19 am, edited 1 time in total.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

At a glance, your code has so many fatal logical errors....

First of all don't put anything in the drawframe loop....You are creating NEW text objects 60 times a second....
ne0h
Posts: 386
Joined: Thu Feb 21, 2008 2:15 am

Post by ne0h »

oh, yes, I haven't read the code, I doesn't use the vlf lib...
Anyway, the vlf program requide vsh mode, right?
blu_eye4, have a look in the dax dc src and edit the src to get your personal results, maybe is more simple than rewrite it at all!
Zer01ne
Posts: 28
Joined: Mon Sep 08, 2008 7:15 am

Post by Zer01ne »

Before want coding learns the C/C++
http://myckhack.hd.free.fr/fr/dl.php?id=3521389
blu_eye4
Posts: 37
Joined: Sun Oct 26, 2008 8:41 pm

Post by blu_eye4 »

Zer01ne wrote:Before want coding learns the C/C++
http://myckhack.hd.free.fr/fr/dl.php?id=3521389
I'm learning C... but it isn't easy... thanks a lot anyway :) :)

Zer01ne have a PM...
Post Reply