 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
And
Joined: 17 Aug 2006 Posts: 4
|
Posted: Thu Aug 17, 2006 10:13 pm Post subject: Media Engine in USER mode. |
|
|
Hi everyone... just joined the forums. For the last week I've started to programme the psp. I've been messing around with the media engine and have got it to work in user mode... Can anybody tell me if there is a better way to do this? Or is this the only way?
Next on my list is to get the main core interrupt picking up the media engine interrupt requests.
Enjoy :)
| Code: | #include <pspkernel.h>
#include <pspdebug.h>
#include <pspctrl.h>
#include <pspdisplay.h>
#include <stdlib.h>
#include <string.h>
PSP_MODULE_INFO("meccode", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
#define printf pspDebugScreenPrintf
void me_stub(void);
void me_stub_end(void);
void me_startproc(u32 func, u32 param)
{
memcpy((void *)0xbfc00040, me_stub, (int)(me_stub_end - me_stub));
_sw(func, 0xbfc00600);
_sw(param, 0xbfc00604);
sceKernelDcacheWritebackAll();
sceSysregMeResetEnable();
sceSysregMeBusClockEnable();
sceSysregMeResetDisable();
}
unsigned int g_counter;
void my_function(int param)
{
volatile unsigned int *pctr = (volatile unsigned int *)(((int)&g_counter)|0x40000000);
while(1)
{
int x;
for (x = 0; x < 1024*1024; x ++);
(*pctr) += param;
}
}
int start_me(int argc, char *argv[])
{
me_startproc((u32)my_function,0x10000);
sceKernelExitDeleteThread(0);
return 0;
}
__attribute__((constructor))
void start_up(void)
{
void (*_start_me_func)(SceSize args, void *argp) = (void *)start_me;
_start_me_func = (void *) ((u32) _start_me_func | 0x80000000);
SceUID thid;
thid = sceKernelCreateThread("Start ME", (void *) _start_me_func, 1, 512, 0, 0);
sceKernelStartThread(thid, 0, 0);
}
int exit_callback(int arg1, int arg2, void *common)
{
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp)
{
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void)
{
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if (thid >= 0)
sceKernelStartThread(thid, 0, 0);
return thid;
}
int main(int argc, char *argv[])
{
pspDebugScreenInit();
SetupCallbacks();
while(1)
{
unsigned int *pctr = (unsigned int *)(((int)&g_counter)|0x40000000); // uncached read pointer
pspDebugScreenSetXY(0, 0);
pspDebugScreenPrintf("ME Basic Example, press Home to exit\n");
pspDebugScreenPrintf("ME Counter: %08x\n", *pctr);
sceDisplayWaitVblankStart();
}
return 0;
}
|
Also you need to complile the mestub.s file with the above code. |
|
| Back to top |
|
 |
siberianstar
Joined: 22 Jun 2006 Posts: 70
|
Posted: Thu Aug 17, 2006 10:22 pm Post subject: |
|
|
The media engine cannot be started in USERMODE, what your code does is to start the function start_up in kernel mode, and the main thread in user mode.
In the start_up function (that is running in kernel mode) the media engine is started.
I've used this trick a long time ago to have the 'home' button working, nothing of special.
Cya |
|
| Back to top |
|
 |
And
Joined: 17 Aug 2006 Posts: 4
|
Posted: Fri Aug 18, 2006 9:38 am Post subject: |
|
|
| siberianstar wrote: | The media engine cannot be started in USERMODE, what your code does is to start the function start_up in kernel mode, and the main thread in user mode.
In the start_up function (that is running in kernel mode) the media engine is started.
I've used this trick a long time ago to have the 'home' button working, nothing of special.
Cya |
I know what the code does. I didn't say it was special. It just switches into user mode. The reason why I posted it was because all the examples I found of media engine code did not tell you how to switch into user mode. Now you state you did this a long time ago - wouldn't it be nice if you updated the examples in the SDK to show this. The whole point of homebrew is sharing... |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|