How to compile and run a 'hello world' executable in PSY-Q

General help for the PSY-Q SDK, such as setting the SDK up, compiling correctly, linking and debugging
Post Reply
User avatar
bizarro2011
Serious PSXDEV User
Serious PSXDEV User
Posts: 118
Joined: March 27th, 2012, 9:09 pm
Skype: abernardo2011
Location: Brazil

How to compile and run a 'hello world' executable in PSY-Q

Post by bizarro2011 » May 7th, 2012, 10:01 pm

1) Download and install the PSY-Q SDK from http://psdev.psio.com.au/downloads.html. Everything should be setup correctly, and working fine.

2) Create a text file and paste in the code below.

Code: Select all

//    hello world


#include <sys/types.h>		
#include <libetc.h>		
#include <libgte.h>
#include <libgpu.h>
#include <libgs.h>
#include <stdio.h>

#define OT_LENGTH (10)			
#define PACKETMAX (2048)		
#define PACKETMAX2 (PACKETMAX*24)	
#define SCREEN_WIDTH 320		
#define SCREEN_HEIGHT 240

GsOT myOT[2];				
GsOT_TAG myOT_TAG[2][1<<OT_LENGTH];
PACKET GPUPacketArea[2][PACKETMAX2];	

void InitGraphics(void);			
void DisplayAll(int);           		
int main(void);                

int main(void) {
	int activeBuffer=0;		
	InitGraphics();		                    
        ResetGraph(0);
        SetVideoMode(MODE_PAL);              
        SetGraphDebug(0);
	FntLoad(960, 256);		      
	FntOpen(64,64, 256, 200, 0, 512);     
						
	while (1) {				
		activeBuffer = GsGetActiveBuff();	
		GsSetWorkBase((PACKET*)GPUPacketArea[activeBuffer]);  	
		GsClearOt(0, 0, &myOT[activeBuffer]);	              	
		
		FntPrint("hello world\n\n");                            
		DisplayAll(activeBuffer);                             	
	}
	return 0;
}	

void InitGraphics(void) {
	
	GsInitGraph(SCREEN_WIDTH, SCREEN_HEIGHT, GsNONINTER|GsOFSGPU, 1, 0); 	
	GsDefDispBuff(0, 0 , 0, SCREEN_HEIGHT); 
	myOT[0].length = OT_LENGTH; 
	myOT[1].length = OT_LENGTH;
	myOT[0].org = myOT_TAG[0]; 
	myOT[1].org = myOT_TAG[1];
	GsClearOt(0,0,&myOT[0]); 
	GsClearOt(0,0,&myOT[1]);
}

void DisplayAll(int activeBuffer) {
	FntFlush(-1);				
	DrawSync(0);
	
	VSync(0);					
	GsSwapDispBuff();				
	GsSortClear(0,100,0,&myOT[activeBuffer]); 
	GsDrawOt(&myOT[activeBuffer]);		  
}
3) Rename the text file to 'hello.c'. Be sure to rename the extension from '.txt', to '.c'.
4) Make another text file and put in this code

Code: Select all

all:
	ccpsx -O -Xo$80010000 main.c -omain.cpe,main.sym

for_menu:
	ccpsx -O -Xo$80010000 main.c \psx\lib\none2.obj -oarot.cpe
5) Rename the text file to 'makefile.mak' to get your makefile.
6) Compile with 'psymake' (again, run in a command prompt. EG: c:\psyq\projects\hello> psymake
7) Run the command, 'cpe2x main.cpe' to get an executable (main.exe).
8) Run with the compiled main.exe in an emulator, or upload it over a commslink to from your PC to your PS1 with CAETLA or XKILLER.

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2233
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: How to write compile and run without a console game ps1

Post by Shadow » May 9th, 2012, 12:58 am

Topic fixed ;)

If you cant even launch psymake, it is because on the Windows 9x series, you usually have an AUTOEXEC.bat file that calls the PSPATHS.bat file within the PSYQ path (EG: C:\PSYQ\PSPATHS.bat) on startup.

On Windows 7 for example, you will need to call (start) this separately because it will not get executed.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

User avatar
bizarro2011
Serious PSXDEV User
Serious PSXDEV User
Posts: 118
Joined: March 27th, 2012, 9:09 pm
Skype: abernardo2011
Location: Brazil

Re: How to compile and run a 'hello world' executable in PSY

Post by bizarro2011 » May 9th, 2012, 11:40 pm

thank you shadow

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2233
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: How to compile and run a 'hello world' executable in PSY

Post by Shadow » June 5th, 2012, 7:53 pm

Your makefile was wrong! I fixed it anyhow.
Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

DEBRO
Curious PSXDEV User
Curious PSXDEV User
Posts: 17
Joined: February 5th, 2013, 3:08 am

Re: How to compile and run a 'hello world' executable in PSY

Post by DEBRO » March 4th, 2013, 4:30 pm

Hi there,

I'm having an issue compiling the Hello World demo. My OS is Win7 Enterprise. I've followed the steps to set up the environment using WinXP mode.

In my Win7 environment I have PSY-Q setup under my user folder. I then mapped this as the "Z:\" drive in WinXP mode so it looks as if my PSY-Q directory in WinXP is Z:\PSYQ. Once I execute the psymake command I get the following...

Code: Select all

PsyMake version 1.14  copyright SN Systems Software Ltd 1993
Z:\PSYQ\bin\ccpsx.EXE -O3 -X0$80010000 main.c -omain.cpe,main.sym,mem.map
Error : could not execute cpppsx
Bad return code - make aborted
I've double checked the environment settings. Is there something else I'm missing?

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 140
Joined: December 19th, 2012, 8:08 pm
IRC: t0rxe
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Re: How to compile and run a 'hello world' executable in PSY

Post by t0rxe » March 4th, 2013, 6:11 pm

Did you edit 'PSPATHS.BAT' in the 'C:\psyq\' folder to point to all the correct locations ('Z:\')?

This is the default. You will need to change it to point to your directories.
Image
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

DEBRO
Curious PSXDEV User
Curious PSXDEV User
Posts: 17
Joined: February 5th, 2013, 3:08 am

Re: How to compile and run a 'hello world' executable in PSY

Post by DEBRO » March 5th, 2013, 2:30 am

Hi there,
torxe wrote:Did you edit 'PSPATHS.BAT' in the 'C:\psyq\' folder to point to all the correct locations ('Z:\')?
Yes, I modified PSPATHS.BAT and I'm having the same issue.

The environment can see PSYMAKE and CCPSX. Why would it have an issue with CPPPSX?

BTW, I'm using WinXP under Win7 and changing the environment variables according to "How to setup Windows XP/7 Enviroment Variables for Psy-Q". I didn't think I still needed to run PSPATHS.BAT under this configuration.

Any help anyone can give me would be greatly appreciated. Thanks

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 140
Joined: December 19th, 2012, 8:08 pm
IRC: t0rxe
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Re: How to compile and run a 'hello world' executable in PSY

Post by t0rxe » March 5th, 2013, 6:39 am

Ah, you're right! You don't need to change PSPATHS.BAT as you added them into your environment variables list.
Sorry. So I can help you more, are you using Windows 7 64-bit, or 32-bit Windows?
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

DEBRO
Curious PSXDEV User
Curious PSXDEV User
Posts: 17
Joined: February 5th, 2013, 3:08 am

Re: How to compile and run a 'hello world' executable in PSY

Post by DEBRO » March 5th, 2013, 8:16 am

Hi there,
torxe wrote:Ah, you're right! You don't need to change PSPATHS.BAT as you added them into your environment variables list.
Sorry. So I can help you more, are you using Windows 7 64-bit, or 32-bit Windows?
I'm running Win7 64-bit.

Thank you for all your help. I figured out my problem. I needed to modify the PSYQ.INI file on the PSYQ\BIN folder to point to my configuration. Once I changed that I was able to build the helloworld demo. Now on to more interesting projects :D

I may look into the steps mentioned in the "Configuring and Compiling PSY-Q 4.6 to run Homebrew" thread to see if I can get around using the VM.

Thanks again for all your help!

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 140
Joined: December 19th, 2012, 8:08 pm
IRC: t0rxe
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Re: How to compile and run a 'hello world' executable in PSY

Post by t0rxe » March 5th, 2013, 5:09 pm

Nice work getting it to run!
You have seen the help page though, haven't you? http://psxdev.net/help.html
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

DEBRO
Curious PSXDEV User
Curious PSXDEV User
Posts: 17
Joined: February 5th, 2013, 3:08 am

Re: How to compile and run a 'hello world' executable in PSY

Post by DEBRO » March 6th, 2013, 12:16 pm

Hi there,
torxe wrote:Nice work getting it to run!
You have seen the help page though, haven't you? http://psxdev.net/help.html
Yes, I was using that tutorial as a guide.

I looked into the "Configuring and Compiling PSY-Q 4.6 to run Homebrew" thread today and I was able to create a PSX executable without using the VM. It doesn't produce an exact binary but it boots in the emulator. I think I'll go this route as it is easier for me to build without moving back and forth between a VM.

Thanks again for your help.

User avatar
inc^lightforce
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 145
Joined: March 7th, 2013, 7:34 am
I am a: Programmer, Artist, Gamer
PlayStation Model: Black
Skype: a5recordings
Location: Germany
Contact:

Re: How to compile and run a 'hello world' executable in PSY

Post by inc^lightforce » May 4th, 2013, 9:38 am

you can set this few Lines in your COMPILER-BATCH FILE. It works perfect:

Mode con cols=150 lines=50
set PATH=C:\Psyq\bin;
set PSX_PATH=C:\Psyq\bin
set LIBRARY_PATH=C:\Psyq\lib
set C_PLUS_INCLUDE_PATH=C:\Psyq\include
set C_INCLUDE_PATH=C:\Psyq\include
set PSYQ_PATH=C:\Psyq\bin
set COMPILER_PATH=C:\Psyq\bin
set GO32=DPMISTACK 1000000
set G032TMP=C:\WINDOWS\TEMP
set TMPDIR=C:\WINDOWS\TEMP
rem-----------------------------------------------
ccpsx -O3 -Xo$80010000 main.c -omain.cpe
my coding page/ forum at:
http://aftermath-creations.net/

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 140
Joined: December 19th, 2012, 8:08 pm
IRC: t0rxe
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Re: How to compile and run a 'hello world' executable in PSY

Post by t0rxe » May 4th, 2013, 1:32 pm

Just set up the environment variables correctly so you never have to worry about always calling PSPATHS.BAT: http://psxdev.net/forum/viewtopic.php?f ... =variables

This way, you can call 'psymake' from ANY directory as well as any other Psy-Q compiler derivative object, such as 'cpe2x', etc.

There is no reason for them not to work. Just make sure you enter them correctly as pictured in the link above.

What I will do is build a Windows XP virtual machine that is ready to be used a PSX development setup.
You will just need a license to use it.
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

User avatar
inc^lightforce
Psy-Q Enthusiast
Psy-Q Enthusiast
Posts: 145
Joined: March 7th, 2013, 7:34 am
I am a: Programmer, Artist, Gamer
PlayStation Model: Black
Skype: a5recordings
Location: Germany
Contact:

Re: How to compile and run a 'hello world' executable in PSY

Post by inc^lightforce » May 5th, 2013, 2:07 am

Six million ways to die. which should i go :)
my coding page/ forum at:
http://aftermath-creations.net/

User avatar
Shadow
Admin / PSXDEV
Admin / PSXDEV
Posts: 2233
Joined: December 31st, 2012, 5:37 pm
PlayStation Model: H2000/5502

Re: How to compile and run a 'hello world' executable in PSY

Post by Shadow » May 6th, 2013, 4:03 pm

Development Console: SCPH-5502 with 8MB RAM, MM3 Modchip, PAL 60 Colour Modification (for NTSC), DB-9 breakout headers for both RGB and Serial output and an Xplorer with CAETLA 0.34.

Development Computer: Windows 98, Pentium 3 [400MHz], 128MB SDRAM, DTL-H2000, DTL-H201A, 21" Sony Trinitron CRT, CD-ROM burner, 3.25" and 5.25" Floppy Diskette Drives and a ZIP 100 Diskette Drive.

User avatar
t0rxe
C Programming Expert
C Programming Expert
Posts: 140
Joined: December 19th, 2012, 8:08 pm
IRC: t0rxe
Motto: /\OX[]
PlayStation Model: SCPH-5502
Location: Australia

Re: How to compile and run a 'hello world' executable in PSY

Post by t0rxe » May 6th, 2013, 6:12 pm

A video of this pre-configured development environment can be found on my YouTube channel
http://www.youtube.com/watch?v=zc94gJ3kw4U
"Nostalgia isn't a big enough word to describe the PlayStation from my eyes"

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest