[TUTORIAL]How to program in D on the PSP!!!

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

Moderators: cheriff, TyRaNiD

Post Reply
the_darkside_986
Posts: 9
Joined: Tue Jul 18, 2006 3:29 pm

[TUTORIAL]How to program in D on the PSP!!!

Post by the_darkside_986 »

The free, open-source GNU D compiler (dgcc) has been ported to MIPS and is known to compile under the psptoolchain now! This started because I asked someone on D.GNU how to compile it for the PSP and someone described a howto. I've posted the instructions here: http://forums.qj.net/showthread.php?t=142864 if anyone is interested.

There are still a few kinks to work out, but once things are smoother I think it would be nice to see this as a part of the standard toolchain distribution.

For those who have never heard of D, it is a powerful new systems programming language that compiles purely to native code, but has powerful language features of high level languages. These links explain it better than I can:
http://www.digitalmars.com/d/
http://www.digitalmars.com/d/1.0/overview.html
http://www.digitalmars.com/d/1.0/comparison.html

For now, developers will be limited to mostly using the standard C library (in std.c.* modules) and the PSPSDK headers (download link is in the QJ post, I converted them myself to D) until I can rewrite D's standard library, Phobos, to have proper PSP implementations of various classes and functions, which should be easy and straightforward. But I personally prefer using the SDK functions anyway.

Enjoy.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Cool! I'll have to try that out. I've been watching D since it was first introduced. It's a very nifty language. :)

EDIT: Got gdc compiled and installed. Example 2 works fine on my Slim running 4.01 M33-2. :D
Maxiime
Posts: 18
Joined: Thu Jun 19, 2008 11:34 pm

Post by Maxiime »

Wow:p

Nice. I'll try it out tomoro. (1h AM here)

Cyaa
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

D has great future!

I donot know why people seem so uninterested...
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
whistler
Posts: 39
Joined: Tue Mar 04, 2008 7:08 am

Post by whistler »

finally managed to compile psp-gdc and i have tested the demonstration eboot on 401m33 :)

great work
Maxiime
Posts: 18
Joined: Thu Jun 19, 2008 11:34 pm

Post by Maxiime »

Post this on a psp site like pspgen, qj etc.

Ps: tested it. works great! tnx

Cya!
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

Post this on a psp site like pspgen, qj etc.
Some people here (me at first) don't like redirects like this. Please, don't...
(and that "cya", too....is it necessary? :P )
Wraggster
Posts: 121
Joined: Fri Aug 26, 2005 7:40 am
Contact:

Post by Wraggster »

anychance of posting the tutorial in full here
Webmaster of http://www.dcemu.co.uk

DCEMU The Worlds Only Homebrew & Gaming Network of Sites.
Moneyslap03
Posts: 14
Joined: Sun May 11, 2008 11:06 pm

Post by Moneyslap03 »

thanks im setting up now and Wraggster didnt know you were signed up here its mike03$$$ from dcemu
Viper8896
Posts: 110
Joined: Thu Jan 26, 2006 6:20 pm

Post by Viper8896 »

I've been really wanting to get D working on the psp but bother as I thought there may be a few difficulties causing me to loose sleep. So I decided to posted this ;) hoping other dev's would rush in and try to 'win the race' (while not even playing) and it seemed to work brilliantly.

Anyway just skiming through right now 'bout to get more sleep. So is the full tango library working and GC tested?
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

gcc patched and D compiled without problem but when generating libpspsdkA.o

i have the following error with the makefile provide

../../../libphobos/internal/cmain.d:5: référence indéfinie vers « _Dmain »
../../../libphobos/internal/cmain.d:5: référence indéfinie vers « _Dmain »

is this the main entry that must been written in C?



if have created a new makefile
just do make copyheader it copy all the *.d to $(SRCS) $(PSPSDK)/include/pspsdk
after this
make it compile create the libpspsdkD and copy it to $(PSPDIR)/lib

here is the makefile

PSPSDK=$(shell psp-config --pspsdk-path)
PSPDIR=$(shell psp-config --psp-prefix)


TARGET_LIB = libpspsdkD.a

$(SRCS):
echo $@

SRCS = csystime.d pspatrac3.d pspaudiocodec.d pspaudio.d pspaudio_kernel.d pspaudiolib.d \
pspchnnlsv.d pspctrl.d pspctrl_kernel.d pspdconfig.d pspdebug.d pspdebugkb.d pspdisplay.d \
pspdisplay_kernel.d pspexception.d pspfpu.d pspge.d pspgu.d pspgum.d psphprm.d psphttp.d \
pspidstorage.d pspimpose_driver.d pspinit.d pspintrman.d pspintrman_kernel.d pspiofilemgr.d \
pspiofilemgr_dirent.d pspiofilemgr_fcntl.d pspiofilemgr_kernel.d pspiofilemgr_stat.d pspjpeg.d \
pspkdebug.d pspkernel.d pspkerneltypes.d pspkerror.d psploadcore.d psploadexec.d \
psploadexec_kernel.d pspmoduleexport.d pspmoduleinfo.d pspmodulemgr.d pspmodulemgr_kernel.d \
pspmpegbase.d pspmpeg.d pspmscm.d pspnand_driver.d pspnet_adhocctl.d pspnet_adhoc.d pspnet_adhocmatching.d \
pspnet_apctl.d pspnet.d pspnet_inet.d pspnet_resolver.d pspopenpsid.d psppower.d \
pspprof.d pspreg.d psprtc.d pspsdk.d pspsircs.d pspssl.d pspstdio.d pspstdio_kernel.d pspsuspend.d \
pspsysclib.d pspsyscon.d pspsysevent.d pspsysmem.d pspsysmem_kernel.d pspsysreg.d \
pspsystimer.d pspthreadman.d pspthreadman_kernel.d psptypes.d pspumd.d pspusbacc.d \
pspusbbus.d pspusbcam.d pspusb.d pspusbstor.d pspuser.d psputility_avmodules.d \
psputility.d psputility_gamesharing.d psputility_htmlviewer.d psputility_modules.d \
psputility_msgdialog.d psputility_netconf.d psputility_netmodules.d psputility_netparam.d \
psputility_osk.d psputility_savedata.d psputility_sysparam.d psputility_usbmodules.d \
psputils.d psputilsforkernel.d pspvfpu.d pspvideocodec.d pspwlan.d

OBJS = csystime.o pspatrac3.o pspaudiocodec.o pspaudio.o pspaudio_kernel.o pspaudiolib.o \
pspchnnlsv.o pspctrl.o pspctrl_kernel.o pspdconfig.o pspdebug.o pspdebugkb.o pspdisplay.o \
pspdisplay_kernel.o pspexception.o pspfpu.o pspge.o pspgu.o pspgum.o psphprm.o psphttp.o \
pspidstorage.o pspimpose_driver.o pspinit.o pspintrman.o pspintrman_kernel.o pspiofilemgr.o \
pspiofilemgr_dirent.o pspiofilemgr_fcntl.o pspiofilemgr_kernel.o pspiofilemgr_stat.o pspjpeg.o \
pspkdebug.o pspkernel.o pspkerneltypes.o pspkerror.o psploadcore.o psploadexec.o \
psploadexec_kernel.o pspmoduleexport.o pspmoduleinfo.o pspmodulemgr.o pspmodulemgr_kernel.o \
pspmpegbase.o pspmpeg.o pspmscm.o pspnand_driver.o pspnet_adhocctl.o pspnet_adhoc.o pspnet_adhocmatching.o \
pspnet_apctl.o pspnet.o pspnet_inet.o pspnet_resolver.o pspopenpsid.o psppower.o \
pspprof.o pspreg.o psprtc.o pspsdk.o pspsircs.o pspssl.o pspstdio.o pspstdio_kernel.o pspsuspend.o \
pspsysclib.o pspsyscon.o pspsysevent.o pspsysmem.o pspsysmem_kernel.o pspsysreg.o \
pspsystimer.o pspthreadman.o pspthreadman_kernel.o psptypes.o pspumd.o pspusbacc.o \
pspusbbus.o pspusbcam.o pspusb.o pspusbstor.o pspuser.o psputility_avmodules.o \
psputility.o psputility_gamesharing.o psputility_htmlviewer.o psputility_modules.o \
psputility_msgdialog.o psputility_netconf.o psputility_netmodules.o psputility_netparam.o \
psputility_osk.o psputility_savedata.o psputility_sysparam.o psputility_usbmodules.o \
psputils.o psputilsforkernel.o pspvfpu.o pspvideocodec.o pspwlan.o

DFLAGS = -I $(PSPSDK)/include

include $(PSPSDK)/lib/build.mak

install: $(TARGET_LIB)
cp $(TARGET_LIB) $(PSPSDK)/lib

copyheader: $(SRCS)
mkdir -p $(PSPSDK)/include/pspsdk
cp -f $(SRCS) $(PSPSDK)/include/pspsdk
sauron_le_noir
Posts: 203
Joined: Sat Jul 05, 2008 8:03 am

Post by sauron_le_noir »

here is the makefile and the hello source adapted.

Makefile:
TARGET = hello
OBJS = module.o main.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)

LIBDIR =
LIBS = -lgphobos -lm -lpspsdkD
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World

PSPSDK=$(shell psp-config --pspsdk-path)
DFLAGS = -I $(PSPSDK)/include

include $(PSPSDK)/lib/build.mak

main.d:

extern (C) int SetupCallbacks();
extern (C) int sceKernelSleepThread();

import pspsdk.pspdebug;
import std.string;

class HelloPsp
{
public:
void sayHello()
{
pspDebugScreenPrintf(toStringz(m_msg));
}
char[] m_msg = "Hello D on Psp\n";
}

int main()
{
SetupCallbacks();

pspDebugScreenInit();

auto hello = new HelloPsp();
hello.sayHello();

sceKernelSleepThread();
return 0;
}
module.c :
#include <pspkernel.h>
#include <pspdebug.h>

PSP_MODULE_INFO("d test prog", 0, 1, 1);

/* Exit callback */
static int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}

/* Callback thread */
static int CallbackThread(SceSize args, void *argp) {
int cbid;

cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);

sceKernelSleepThreadCB();

return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
int thid = 0;

thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}

return thid;
}
the_darkside_986
Posts: 9
Joined: Tue Jul 18, 2006 3:29 pm

Post by the_darkside_986 »

Yeah sorry about that I forgot to fix the Makefile before posting it. This is the latest version on the QJ thread's first page, right? I just fixed it and re-posted it the other day. There were some problems with pspgu headers (as usual for me).
hlide
Posts: 739
Joined: Sun Sep 10, 2006 2:31 am

Post by hlide »

sauron_le_noir wrote:here is the makefile and the hello source adapted.

--->8--->8--->8---

Nom de diou ! utilise les tags

Code: Select all

[CODE/]
pour entourer tes codes. C'est illisible sans l'indentation !
Makefile:

Code: Select all

TARGET = hello
OBJS = module.o main.o

CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $&#40;CFLAGS&#41; -fno-exceptions -fno-rtti
ASFLAGS = $&#40;CFLAGS&#41;

LIBDIR =
LIBS = -lgphobos -lm -lpspsdkD
LDFLAGS =

EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Hello World

PSPSDK=$&#40;shell psp-config --pspsdk-path&#41;
DFLAGS = -I $&#40;PSPSDK&#41;/include

include $&#40;PSPSDK&#41;/lib/build.mak 

main.d:

Code: Select all

extern &#40;C&#41; int SetupCallbacks&#40;&#41;;
extern &#40;C&#41; int sceKernelSleepThread&#40;&#41;;

import pspsdk.pspdebug;
import std.string;

class HelloPsp
&#123;
public&#58;
	void sayHello&#40;&#41;
	&#123;
		pspDebugScreenPrintf&#40;toStringz&#40;m_msg&#41;&#41;;
	&#125;
	char&#91;&#93; m_msg = "Hello D on Psp\n";
&#125;

int main&#40;&#41;
&#123;
	SetupCallbacks&#40;&#41;;

	pspDebugScreenInit&#40;&#41;;
	
	auto hello = new HelloPsp&#40;&#41;;
	hello.sayHello&#40;&#41;;

	sceKernelSleepThread&#40;&#41;;
	return 0;
&#125;
module.c :

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h> 

PSP_MODULE_INFO&#40;"d test prog", 0, 1, 1&#41;;

/* Exit callback */
static int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
          sceKernelExitGame&#40;&#41;;
          return 0;
&#125;

/* Callback thread */
static 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;

/* Sets up the callback thread and returns its thread id */
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;
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

any ideas if it can be aplyed to gcc 4.3?
the_darkside_986
Posts: 9
Joined: Tue Jul 18, 2006 3:29 pm

4.3

Post by the_darkside_986 »

Probably not, I've had problems with gdc compiled against 4.2, so 4.3 probably has the same issues or more unless that has been patched in svn yet.
Post Reply