How to compile, link and transfer PSP programs from VS.NET

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

Moderators: cheriff, TyRaNiD

rasmus
Posts: 17
Joined: Wed Jul 21, 2004 9:30 am
Location: Göteborg, Sweden

How to compile, link and transfer PSP programs from VS.NET

Post by rasmus »

I just hacked together a way to run the psp toolchain under cygwin from inside visual studio.net. It includes converting gcc error messages to something visual studio can parse. If anyone comes up with a cleaner way to accomplish this it would be great, but at least this works.

This assumes that the psp toolchain is installed and the path to it is in the cygwin profile.

1. Create a batch file called psp-make.bat. Put it in for example c:\pspdev\. If your psp has another drive letter than E:\, change
PSP_MOUNT. It should contain this:

Code: Select all

@\cygwin\bin\bash -c 'export VS_PATH=`pwd`; export PSP_MOUNT=/cygdrive/e; /bin/bash --login -c "cd $VS_PATH; %1 %2 %3 %4 %5"' 
2. Create a shell script called vs-psp-gcc and put it in /usr/local/pspdev/bin or where you have installed the psp toolchain. It contains this:

Code: Select all

CMD=`echo $0 | sed -e 's/\([^-]*-\)//'`
$CMD 2>&1 $@ | sed -e 's/\([^:]*\):\([0-9][0-9]*\)\(.*\)/\1 (\2) \3/'
3. Symlink vs-psp-g++ to vs-psp-gcc, like this:

Code: Select all

/usr/local/pspdev/bin
$ ln -s vs-psp-gcc vs-psp-g++
4. Create a new VS.NET Makefile project, with the following settings:

Code: Select all

Build command line: c:\pspdev\psp-make.bat make kxploit
Output: projname.elf
Clean commands: c:\pspdev\psp-make.bat make clean
Rebuild command line: c:\pspdev\psp-make.bat make clean kxploit
5. Change this under the VS.NET Menu Project / Properties / Debugging:

Code: Select all

Command: c:\windows\system32\cmd.exe
Command Arguments: /c c:\pspdev\psp-make.bat make kx-install
6. Populate the project directory with code and a Makefile like the samples in PSPSDK. Add the source files to the VS.NET project. Add this to the bottom of the Makefile (Make sure that the indented lines are tabbed and not spaced):

Code: Select all

ifneq ($VS_PATH),)
CC       = vs-psp-gcc
CXX      = vs-psp-g++
endif

kx-install: kxploit
ifeq ($(PSP_MOUNT),)
        @echo '*** Error: $$(PSP_MOUNT) undefined. Please set it to for example /cygdrive/e'
        @echo if your PSP is mounted to E: in cygwin.
else
        cp -r $(KXDIR) $(PSP_MOUNT)/PSP/GAME/
        cp -r $(KXDUMMY) $(PSP_MOUNT)/PSP/GAME/
endif
Now you can build your project with the 'Build Solution' Command, rebuild it with 'Rebuild Solution' Command and clean the solution with.. you get it :)

With the 'Start Debug' Command it will copy the build to a connected PSP.

Step 1-3 only has to be done once, and 4-6 has to be done for each project.

If you like you can put the content of step 6 in /usr/local/pspdev/psp/sdk/lib/build.mak instead and only do it once.

Hope this helps anyone eager to use their beloved visual studio ;)

/Rasmus
ooPo
Site Admin
Posts: 2023
Joined: Sat Jan 17, 2004 9:56 am
Location: Canada
Contact:

Post by ooPo »

Made stickier for eyeball attraction.
HexDump
Posts: 70
Joined: Tue Jun 07, 2005 9:18 pm

Post by HexDump »

is there any chance to use Visual Studio 6 performing this trick?

Thanks in advance,
HexDump.
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

I guess this can be done with PS2 toolchain too... Maybe sticking something in ps2 threads.. ?
pixel: A mischievous magical spirit associated with screen displays. The computer industry has frequently borrowed from mythology. Witness the sprites in computer graphics, the demons in artificial intelligence and the trolls in the marketing department.
ector
Posts: 195
Joined: Thu May 12, 2005 10:22 pm

Post by ector »

Nice work, much better than what I have been doing so far.
And yes this would apply to any GCC toolchain, I guess.
Grover Again
Posts: 6
Joined: Wed Jul 06, 2005 12:01 am

Post by Grover Again »

Hexdump - you can do similar things with VC6. But then again, why use VC6 when .NET toolkit is free :)
http://msdn.microsoft.com/visualc/vctoolkit2003/
BTW I have both installed, and they dont interfere with each other too much.
Zeta
Posts: 9
Joined: Sat Jul 09, 2005 1:46 pm

Post by Zeta »

So that it worked for me I had to change (KXDIR) by (TARGET) and (KXDUMMY) by (TARGET)%. Where is KXDIR and KXDUMMY supposed to be defined? I looked at the build.mak and it's not there. Am I missing something?
rasmus
Posts: 17
Joined: Wed Jul 21, 2004 9:30 am
Location: Göteborg, Sweden

Post by rasmus »

So that it worked for me I had to change (KXDIR) by (TARGET) and (KXDUMMY) by (TARGET)%. Where is KXDIR and KXDUMMY supposed to be defined? I looked at the build.mak and it's not there. Am I missing something?
No, you're absolutely right. They're defined in my suggested patch to build.mak, like this:

Code: Select all

KXTARGET = $(shell echo $(TARGET)000000 | cut -b1-6)
KXDIR = $(KXTARGET)_________________________1
KXDUMMY = $(KXTARGET)~1% 
Sorry about that :)
Zeta
Posts: 9
Joined: Sat Jul 09, 2005 1:46 pm

Post by Zeta »

Oh that is better, that way we won't get the corrupted item. I'll add that to mine, thanks a lot for the whole thread I was hoping I could stay on .NET for psp.
User avatar
RobbieTheRabbit
Posts: 5
Joined: Fri Jul 15, 2005 7:19 am
Location: France

Post by RobbieTheRabbit »

Hello,

Sorry for this first question, I'm a noob :X
What's your rule for the kxploit parameter ?
rasmus
Posts: 17
Joined: Wed Jul 21, 2004 9:30 am
Location: Göteborg, Sweden

Post by rasmus »

This is my kxploit rule (full patch here: http://forums.ps2dev.org/viewtopic.php?t=2474)

Code: Select all

KXTARGET = $(shell echo $(TARGET)000000 | cut -b1-6)
KXDIR = $(KXTARGET)_________________________1
KXDUMMY = $(KXTARGET)~1%
 
kxploit: $(TARGET).elf $(PSP_EBOOT_SFO)
        mkdir -p "$(KXDIR)"
        $(STRIP) $(TARGET).elf -o $(KXDIR)/$(PSP_EBOOT)
        mkdir -p "$(KXDUMMY)"
        $(PACK_PBP) "$(KXDUMMY)/$(PSP_EBOOT)" $(PSP_EBOOT_SFO) $(PSP_EBOOT_ICON)  \
                $(PSP_EBOOT_ICON1) $(PSP_EBOOT_UNKPNG) $(PSP_EBOOT_PIC1)  \
                $(PSP_EBOOT_SND0) NULL $(PSP_EBOOT_PSAR)
 
Make sure that the indentations in the makefile are real tabs and not spaces like they become when pasted here!
User avatar
RobbieTheRabbit
Posts: 5
Joined: Fri Jul 15, 2005 7:19 am
Location: France

Post by RobbieTheRabbit »

Thanks for quick reply.

I don't understand but the debug start does not work when I launch it with VS. But if I open a cmd window, it works fine.

From VS I've got this lines :

Code: Select all

/bin/sh : command not found
/bin/sh : command not found
/bin/sh : command not found
/bin/sh : command not found
Something like that.

From a cmd window the psp-strip and other commands are launeched just fine.

Moreover, /cygdrive/c in the makefile does not work, I have to set c:\
I have Cygwin installed.

If you have any advice, you're welcome : )
rasmus
Posts: 17
Joined: Wed Jul 21, 2004 9:30 am
Location: Göteborg, Sweden

Post by rasmus »

Make sure that psp-make.bat states the correct path of your cygwin installation, ie begins with

Code: Select all

@c:\cygwin\bin\bash ...
or if cygwin is installed on d:

Code: Select all

@d:\cygwin\bin\bash ...
If that doesn't work, please try to specify your problem in more detail, what happens for example if you run "psp-make.bat make kxploit" from cmd.exe?
User avatar
RobbieTheRabbit
Posts: 5
Joined: Fri Jul 15, 2005 7:19 am
Location: France

Post by RobbieTheRabbit »

Hi rasmus,

Well, this evening everything works perfectly ! Thanks to your advices.
The "cygdrive" issue is solved, I guess I had to reboot the computer for the changes to take effect (I had reinstalled cygwin with Unix option instead of DOS).

Great solution for build projects, thanks :D
pspguy190
Posts: 11
Joined: Sat Jul 23, 2005 7:37 am

Post by pspguy190 »

Ok so let me get this straight. You mean to say that you just found a way to program using vb.net instead of c/c++. If i am right, then i have a request. I am newbie to all this programing stuff so can you explain step 4-6 for me. What do you mean by "Add the source files to the vb.net project".
webjeff
Posts: 66
Joined: Thu May 05, 2005 2:51 am

Post by webjeff »

hahaha,

No. He means you can press the Build button in vs.net and have it compile and transfer the pbp file to your psp. It'd be cool if you could write in vb.net or c# on the psp... but you can't... unless... someone can port the CLR, but I dont see that happening ever

JK.
pspguy190
Posts: 11
Joined: Sat Jul 23, 2005 7:37 am

Post by pspguy190 »

I guess i my hopes are too high.

Well can you at lest make buttons with c/c++?
waza
Posts: 12
Joined: Mon Jul 18, 2005 9:20 am

Post by waza »

Tried to setup this hack in my VS.net, got that :

Performing Makefile project actions
make: psp-config: Command not found
Makefile:17: /lib/build.mak: No such file or directory
make: *** No rule to make target `/lib/build.mak'. Stop.
vsislapsp : error PRJ0002 : error result returned from 'c:\docume~1\admini~1\locals~1\temp\bat000007.bat'.

Anyone can tell me what i did wrong ?

thx by advance

Waza
waza
Posts: 12
Joined: Mon Jul 18, 2005 9:20 am

Post by waza »

This assumes that the psp toolchain is installed and the path to it is in the cygwin profile.
how do i do that plz ? :)

Waza
strider
Posts: 10
Joined: Mon Jul 12, 2004 4:40 am

Post by strider »

I originally had problems with this solution until the patch updates were posted...THANKS!

While trying to resolve the situation, I figured out a simple VS.NET workaround for those needing a quick compile solution:

In your project directory (or centrally located) create a build.bat with the following contents:

Code: Select all

@set PATH=c:\cygwin\bin;...(copy your normal Path from DOS prompt)
%1 %2 %3 %4 %5 %6 %7 %8 %9
Then in your Project Properties (needs to be a Makefile project) add the following entries under NMake:
  • Build Command Line: build make
    Rebuild Command Line: build make rebuild
    Clean Command Line: build make clean
    Output: build.bat
Set the make command lines as appropriate for your make file, the above are the ones that I use.

In the Debugging area I set the following:
  • Command: make send
The send option on my makefile makes the necessary folders and copies the files accordingly:

Code: Select all

TARGET = phaserbattle
OBJS = main.o sg_math.o pb_content.o sg_vc.o logo.o
OBJS+= tmp/pb_screen.o tmp/font.o tmp/font_lg.o tmp/controls.o
OBJS+= tmp/planets.o tmp/ships.o

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

PSP_MOUNT = K:
LIBDIR =
LDFLAGS =
LIBS= -lpspgu -lpsppower

BINS= bin/1_0/$(TARGET)/EBOOT.PBP  bin/1_5/$(TARGET)/EBOOT.PBP bin/1_5/$(TARGET)%/EBOOT.PBP

EXTRA_TARGETS=$(BINS)

PSP_EBOOT_TITLE = Phaser Battle

PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak

bin/1_0/$(TARGET)/EBOOT.PBP: $(TARGET).elf $(PSP_EBOOT_SFO)
	mkdir -p bin/1_0/$(TARGET); pack-pbp bin/1_0/$(TARGET)/EBOOT.PBP PARAM.SFO img/pb_logo.png NULL NULL NULL NULL  $(TARGET).elf NULL

bin/1_5/$(TARGET)%/EBOOT.PBP: $(PSP_EBOOT_SFO)
	mkdir -p bin/1_5/$(TARGET)%; pack-pbp bin/1_5/$(TARGET)%/EBOOT.PBP PARAM.SFO img/pb_logo.png NULL NULL NULL NULL NULL NULL

bin/1_5/$(TARGET)/EBOOT.PBP: $(TARGET).elf
	mkdir -p bin/1_5/$(TARGET); cp $(TARGET).elf bin/1_5/$(TARGET)/EBOOT.PBP

tmp/%.16: img/%.4444.png
	tools/pngtxr img/$*.4444.png tmp/$*.16 4444

tmp/%.16: img/%.565.png
	tools/pngtxr img/$*.565.png tmp/$*.16 5650
	
tmp/%.ct: tmp/%.16
	bin2c tmp/$*.16 tmp/$*.ct _$*

tmp/%.c: tmp/%.ct
	sed tmp/$*.ct -e "s/static//g" > tmp/$*.c

logo.o: logo.raw
	bin2o -i logo.raw logo.o logo

rebuild: clean $(BINS)

send: $(BINS)
	mkdir -p $(PSP_MOUNT)/PSP/GAME/$(TARGET)%; cp bin/1_5/$(TARGET)%/EBOOT.PBP $(PSP_MOUNT)/PSP/GAME/$(TARGET)%/EBOOT.PBP; \
	mkdir -p $(PSP_MOUNT)/PSP/GAME/$(TARGET); cp $(TARGET).elf $(PSP_MOUNT)/PSP/GAME/$(TARGET)/EBOOT.PBP
Hopefully someone will find this useful if they are in a hurry. Its main limitation is that I do not yet translate the GCC output so that Visual Studio can recognize the files and line numbers, but other then that it worked good for a quick solution.

Strider
Warren
Posts: 175
Joined: Sat Jan 24, 2004 8:26 am
Location: San Diego, CA

Post by Warren »

I came up with a better solution tonight that doesn't require you to add anything to visual studio or change your makefiles. Just make the following scripts to your c:\cygwin directory and modify paths as needed:

vs-pspdev.bat

Code: Select all

@c:\cygwin\bin\bash -c 'export VS_PATH=`pwd`; /bin/bash --login -c "/vs-pspdev.sh %1 %2 %3 %4 %5"'
vs-pspdev.sh

Code: Select all

#!/bin/bash
export PSP_MOUNT=/cygdrive/i
export PATH=$PATH:/cygdrive/p/pspdev/bin
cd "$VS_PATH"
make 2>&1 $@ | sed -e 's/\([^:]*\):\([0-9][0-9]*\)\(.*\)/\1 (\2) \3/' 
Then in VS, make a new makefile project and specify "c:\cygwin\vs-pspdev.bat "as make command, "c:\cygwin\vs-pspdev.bat clean" as clean command and "c:\cygwin\vs-pspdev.bat clean all" as rebuild and voila, you're rocking in VS.net with minimal fuss.
DarknessFX
Posts: 2
Joined: Thu Sep 01, 2005 4:08 am
Location: Brazil

Post by DarknessFX »

Thanks for this VS.NET ideas and solutions, Im using the Warren solution and it working perfect.

I did some small changes on my VS.NET (2002) to include a "PSP C Study" Wizard at VC++ Projects that create a project with a basic main.c (Hello World), a default Makefile (for PSPSDK) and a empty Readme.txt.

Also it create the project with the build/rebuild/clean commands already set and I made some changes on vs-pspdev.sh to compile the project to Windows (cl.exe), GCC and PSPSDK:
wrote: export PSP_MOUNT=/cygdrive/p
export PATH=/usr/local/pspdev/bin:"/cygdrive/c/Program Files/Microsoft Visual Studio .NET/Common7/IDE":$PATH
cd "$VS_PATH"

echo ------ VS.NET ------
"/cygdrive/c/Program Files/Microsoft Visual Studio .NET/Vc7/bin/cl.exe" main.c /Fedebug/main_win.exe /Wall /Od /GB /Zi /ZI /nologo /D WIN32 /D _DEBUG /D _CONSOLE /D _MBCS /D FRAMEWORK_DLL /D FRAMEWORK_EXPORTS
mv -f vc70.idb debug
mv -f vc70.pdb debug
mv -f main.obj debug

echo ------ GCC ------
/bin/gcc.exe -o debug/main_cyg.exe main.c -ansi -mconsole

echo ------ PSPSDK Makefile ------
make $@ | sed -e 's/\([^:]*\):\([0-9][0-9]*\)\(.*\)/\1 (\2) \3/'
mv -f eboot.pbp debug
mv -f CStudy1-1.elf debug
mv -f main.o debug
mv -f PARAM.SFO debug
echo ------------
I dont know if this Wizard would be useful for anyone else (or belongs to the IHOS), right now all the folder paths are "hard-coded", there is some small changes needed on vcwizards\1033\common.js and a few wizard files.

If it is useful, would be better to write the changes here or build a small "setup" script?
ZMaster
Posts: 29
Joined: Fri Sep 02, 2005 10:14 pm

Post by ZMaster »

I just noted this thread and remembered that I wrote a small tool, which converts a .NET .vcproj file into a Makefile.
I wrote this for my Sega Dreamcast development projects and it works quite good! I thought it might also be of great help here, because you can call my tool before every compile (do this from the .bat file, for example) and you'll always have the correct source files included in the Makefile.
The tool reads a Makefile template from the file Makefile.tmpl which is also included in the ZIP. You need to modify this to use the correct PSP toolchain calls. The source files are then read from the .vcproj XML file and put into the Makefile template which then results into the final Makefile.
The only thing you still have to change in the Makfile.tmpl individually for every project is the names of the linked libraries, but that shouldn't be a problem :-)

Here's the package: http://toy-boy-music.goracer.de/temp/VSMakefile.zip (58 KB)
ZMaster
Posts: 29
Joined: Fri Sep 02, 2005 10:14 pm

Post by ZMaster »

Here's something that might be helpful for everyone, who is new to PSP development. I build a project wizard for MSVS:

MSVC PSP Wizard (150 KB)

Anyway, you need a running cygwin and toolchain installation. The Wizard is set up to build using the kxploit rule and needs rasmus's patch to build.mak to avoid the corrupt item.
I successfully tested it with Visual Studio .NET 2003 and a 1.5 firmware PSP. The wizard uses the automatic Makefile creation tool I described above.

Have fun...
Tim
Posts: 38
Joined: Tue Jul 12, 2005 4:40 am

Post by Tim »

Very nice, that simplifies alot of things. I'll be d/ling that to check it out.

~Tim
terryxq
Posts: 16
Joined: Wed Oct 12, 2005 9:27 pm

Re: How to compile, link and transfer PSP programs from VS.N

Post by terryxq »

I think this make.bat is better.

Code: Select all

if NOT EXIST Makefile @VSMakefile.exe -a
@[!output CYGWIN_FOLDER]\bin\bash -c 'export PROJECTDIR=`pwd`;export PATH=/usr/local/pspdev/bin:$PATH;/bin/bash --login -c "cd \"$PROJECTDIR\";%1 %2 %3 %4"'
It won't rewrite the Makefile again if you change Makefile after built project once.
ZMaster
Posts: 29
Joined: Fri Sep 02, 2005 10:14 pm

Re: How to compile, link and transfer PSP programs from VS.N

Post by ZMaster »

terryxq wrote: It won't rewrite the Makefile again if you change Makefile after built project once.
That is true, but it won't help you much if you create a new source file in your MSVC project, because you would then have to add it to the Makefile by yourself. The purpose of the whole thing is that you don't have to do that anymore :-)

If you want to make changes to your Makefile, edit the Makefile.tmpl, which is a template that is used by VSMakefile.exe. It is added to your project files if you use the wizard, so you can easily edit it from within MSVC...
terryxq
Posts: 16
Joined: Wed Oct 12, 2005 9:27 pm

Re: How to compile, link and transfer PSP programs from VS.N

Post by terryxq »

ZMaster wrote:
terryxq wrote: It won't rewrite the Makefile again if you change Makefile after built project once.
That is true, but it won't help you much if you create a new source file in your MSVC project, because you would then have to add it to the Makefile by yourself. The purpose of the whole thing is that you don't have to do that anymore :-)

If you want to make changes to your Makefile, edit the Makefile.tmpl, which is a template that is used by VSMakefile.exe. It is added to your project files if you use the wizard, so you can easily edit it from within MSVC...
:P ~
I always remove Makefile.tmpl from my project then add Makefile.
:D you are right, my advice may only be better for myself.
Zack
Posts: 1
Joined: Fri Nov 04, 2005 12:56 am

Post by Zack »

Last Edit : Ok I've found the problem. Have to do a ./toolchain.sh -p

I'll post the 2005 beta 2 wizard version later.


Well done but this Wizard doesn't work correctly with VS 2005 beta 2.

I've commented the KXploit lines since KXploit doesn't work for me ( SeiPSPTool does actually) and removed it in build/rebuild.

I've tested changing the PSPSDK variable directly in Makefile.tmpl :

Code: Select all

PSPSDK			= c:/cygwin/usr/local/pspdev/psp/sdk # $(shell psp-config --pspsdk-path)
since the variable couldn't be defined, it did not find the lib/build.mak.

Now, i've got those errors :

Build :

g++ -G0 -Wall -fno-exceptions -fno-rtti -c main.cpp -o main.o
make: *** Recursive variable `PSPSDK' references itself (eventually). Stop.
Project : error PRJ0002 : Error result 2 returned from 'C:\WINDOWS\system32\cmd.exe'.


Rebuild :

make: *** No rule to make target `clean'. Stop.
Project : error PRJ0002 : Error result 2 returned from 'C:\WINDOWS\system32\cmd.exe'.


Clean :

make: *** No rule to make target `clean'. Stop.
Project : error PRJ0002 : Error result 2 returned from 'C:\WINDOWS\system32\cmd.exe'.



Here's the makefile created :

Code: Select all

#------------------- Makefile for 'PSPHW' -------------------#
# This Makefile has been generated by VSMakefile
# Copyright (C) 2005 Florian Zitzelsberger


TARGET			= Binary
OBJS			= main.o 

INCDIR			=
LIBDIR			=
LDFLAGS			=
LIBS			= -lstdc++ -lm		
CFLAGS			= -G0 -Wall
CXXFLAGS		= $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS			= $(CFLAGS)

EXTRA_TARGETS	= EBOOT.PBP
PSP_EBOOT_TITLE	= PSPHW	
PSPSDK			= c:/cygwin/usr/local/pspdev/psp/sdk 
include $(PSPSDK)/lib/build.mak






main.o: main.cpp 
	$(CXX) $(CXXFLAGS) -c main.cpp -o main.o
Any idea ?

Edit :


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

Ok, I see, the problem is that there's no more psp-config.exe on that version, no ?
barbapapaz
Posts: 2
Joined: Mon Nov 28, 2005 8:09 am

Post by barbapapaz »

ZMaster wrote:Here's something that might be helpful for everyone, who is new to PSP development. I build a project wizard for MSVS:

MSVC PSP Wizard (150 KB)

Anyway, you need a running cygwin and toolchain installation. The Wizard is set up to build using the kxploit rule and needs rasmus's patch to build.mak to avoid the corrupt item.
I successfully tested it with Visual Studio .NET 2003 and a 1.5 firmware PSP. The wizard uses the automatic Makefile creation tool I described above.

Have fun...
i don't understand i ha ve this error
makefile:1: *** missing separator. stop

i have cygwin and psptollchain please help
Post Reply