ME question

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

Moderators: cheriff, TyRaNiD

Post Reply
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

ME question

Post by AnonymousTipster »

Hi, i've been trying to think of a way to solve a problem, and thought about using the ME. My problem is that I need to write a lot of data to the memory stick without freezing the PSP. I could do this by splitting up the file, but a far faster way would be to use the ME as a file manager CPU.
What I'd like to know is: can I get the ME to save a 2MB+ file to the memory stick whilst allowing the main CPU to get on with it's work unhindered?

Thanks.
jonny
Posts: 351
Joined: Thu Sep 22, 2005 5:46 pm
Contact:

Post by jonny »

you can try with async writes (or normal writes in a different thread), this could be sufficient to have the operation at the cost of 0.
also writing 64k chunks (with data aligned to 64 bytes) should be the optimal way for psp (it's the optimal size for reading, so i assume it's the same for writing)
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

Why not use the *Async() versions of the sceIo calls?
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

I'm trying to get the Async to work now, but I've never tried them before, so it's proving tricky, it just boots into a black screen with this code:
In main() before main loop:

Code: Select all

testAsFile = sceIoOpenAsync("ms0:/textfile.txt",  O_RDWR | O_CREAT, 0777);
	if&#40;testAsFile < 0&#41;&#123;printf&#40;"ERROR!"&#41;;&#125;       

	int cbida;

	cbida = sceKernelCreateCallback&#40;"Async Callback", async_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbida&#41;;
	sceKernelSleepThreadCB&#40;&#41;;
	
	sceIoSetAsyncCallback&#40;testAsFile, cbida, NULL&#41;;
       
	char* dat;
	dat = "blablabla";

	int ret;
	ret = sceIoWriteAsync&#40;testAsFile, dat, 9&#41;;
	if&#40;ret < 0&#41;&#123;printf&#40;"ERROR!"&#41;;&#125;
The callback:

Code: Select all

int async_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	int vl;
	vl = sceIoCloseAsync&#40;testAsFile&#41;;
	
	return 0;
&#125;
I know there's somthing wrong here, but I'm not sure what. It may be to do with the callback, I think.
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

Did you really mean to put that sceKernelSleepThreadCB() there?
jonny
Posts: 351
Joined: Thu Sep 22, 2005 5:46 pm
Contact:

Post by jonny »

is this sequence not suited for your needs (?):

sceIoOpen
sceIoWriteAsync

*some stuff here, write is running in the back*

sceIoWaitAsync
sceIoClose

(i don't think you need async open/close, is it right?)
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

AnonymousTipster wrote:I'm trying to get the Async to work now, but I've never tried them before, so it's proving tricky, it just boots into a black screen with this code:
In main() before main loop:

Code: Select all

testAsFile = sceIoOpenAsync&#40;"ms0&#58;/textfile.txt",  O_RDWR | O_CREAT, 0777&#41;;
	if&#40;testAsFile < 0&#41;&#123;printf&#40;"ERROR!"&#41;;&#125;       

	int cbida;

	cbida = sceKernelCreateCallback&#40;"Async Callback", async_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbida&#41;;
	sceKernelSleepThreadCB&#40;&#41;;
	
	sceIoSetAsyncCallback&#40;testAsFile, cbida, NULL&#41;;
       
	char* dat;
	dat = "blablabla";

	int ret;
	ret = sceIoWriteAsync&#40;testAsFile, dat, 9&#41;;
	if&#40;ret < 0&#41;&#123;printf&#40;"ERROR!"&#41;;&#125;
The callback:

Code: Select all

int async_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	int vl;
	vl = sceIoCloseAsync&#40;testAsFile&#41;;
	
	return 0;
&#125;
I know there's somthing wrong here, but I'm not sure what. It may be to do with the callback, I think.
The callback is a mess too. You've created an async callback but registered it as an exit callback.

Stick with Jonny's code, it's simpler and should do everything you need.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

To answer to your first question, I think the answer is no, because the ME has no kernel, it can just execute raw code and user routines (but no sce[Something] call).
Sorry for my bad english
Image Oldschool library for PSP - PC version released
AnonymousTipster
Posts: 197
Joined: Fri Jul 01, 2005 2:50 am

Post by AnonymousTipster »

I apologise for my ridiculous coding yesterday, I just grabbed the exit callback code without actually reading it.
Anyway, I've got the async file writer working correctly now. Thanks jonny.
Post Reply