Page 1 of 1

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

Posted: May 7th, 2012, 10:01 pm
by bizarro2011
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.

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

Posted: May 9th, 2012, 12:58 am
by Shadow
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.

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

Posted: May 9th, 2012, 11:40 pm
by bizarro2011
thank you shadow

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

Posted: June 5th, 2012, 7:53 pm
by Shadow
Your makefile was wrong! I fixed it anyhow.

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

Posted: March 4th, 2013, 4:30 pm
by DEBRO
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?

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

Posted: March 4th, 2013, 6:11 pm
by t0rxe
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

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

Posted: March 5th, 2013, 2:30 am
by DEBRO
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

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

Posted: March 5th, 2013, 6:39 am
by t0rxe
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?

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

Posted: March 5th, 2013, 8:16 am
by DEBRO
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!

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

Posted: March 5th, 2013, 5:09 pm
by t0rxe
Nice work getting it to run!
You have seen the help page though, haven't you? http://psxdev.net/help.html

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

Posted: March 6th, 2013, 12:16 pm
by DEBRO
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.

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

Posted: May 4th, 2013, 9:38 am
by inc^lightforce
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

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

Posted: May 4th, 2013, 1:32 pm
by t0rxe
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.

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

Posted: May 5th, 2013, 2:07 am
by inc^lightforce
Six million ways to die. which should i go :)

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

Posted: May 6th, 2013, 4:03 pm
by Shadow

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

Posted: May 6th, 2013, 6:12 pm
by t0rxe
A video of this pre-configured development environment can be found on my YouTube channel
[youtube]http://www.youtube.com/watch?v=zc94gJ3kw4U[/youtube]