PS2 and Lua

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
KaylaKaze
Posts: 75
Joined: Wed May 05, 2004 3:25 pm
Location: NC, USA
Contact:

PS2 and Lua

Post by KaylaKaze »

I've compiled the Lua library with the ps2 compilers but I'm wondering if it'll work. How compatible with ANSI C is the ps2? I mean, am I going to have to chage around time commands and file commands inside the Lua code in order to make them work on the ps2? I know it's POSSIBLE to use Lua on the ps2 'cause it's been used for some commercial games. I'm just wondering if anyone's tried it with the hombrew setup. I could code my own scripting language specificly for ps2 development but I'd rather use Lua since it's getting to be a standard in development.
Guest

Post by Guest »

As far as I know, all compilers used in homebrew and linux
development are the GNU compilers. As such, they are as
ANSI compliant as you are likely to need for LUA, which
itself is likely developed using GCC.

Does this answer your question ?

One thing to consider...is that common system calls that
exist in UNIX systems to manage things such as FileI/O,
network I/O, and such don't actually exist, because there
is no real underlying operating system aside from the Sony
BIOS calls. Some File I/O and networking, console graphics,
etc... exist as part of the PS2 SDK. Check that out to see
if it can meet your needs. Likely you have a porting effort
ahead of you.

Gorim
pixel
Posts: 791
Joined: Fri Jan 30, 2004 11:43 pm

Post by pixel »

The only "big" issue with LUA in PS2, is the Lua_Number format. It is double by default, which isn't a good idea to use on the PS2. So, when using float here, you'll render the bytecode incompatible with a PC-lua which still uses double as numbers. And you'll then have to build a custom LUA on the PC side (that is, you have to change Lua_Number format) in order to generate compatible bytecode.

I also suggest you to do some modifications in the core, by taking off the compiler and the parser (if you are going to use byte code only), as stated here: http://www.lua.org/notes/ltn002.html (this is for Lua4, but should be easily adapted for Lua5)
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.
KaylaKaze
Posts: 75
Joined: Wed May 05, 2004 3:25 pm
Location: NC, USA
Contact:

Post by KaylaKaze »

Thanks for the info. It was mainly the file calls I was most concerned with, like the lua_loadfile (or whatever that command is) (that and timing) as I want to use it primarily for game design. The number format problem is a little troubling, but I don't mind having to use a PS2 only compiler.
KaylaKaze
Posts: 75
Joined: Wed May 05, 2004 3:25 pm
Location: NC, USA
Contact:

Post by KaylaKaze »

Well, it's fortunate that Lua is designed to be easily portable. The config file has the option to easily switch the number type it uses. I'm also looking at things like the Lua io library and it seems like once I learn the actual Lua API better, it should be easy to port those over to fileio commands. Speaking of which, has fio and fileXio been integrated yet so that you can use only fileXioOpen or fioOpen (or whatever command) to access CD, MC, and HDD instead of having to figure out which is being accessed and switch commands based on that? I still have to learn to use the SDK instead of the separate releases of the core libs.
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

iomanX.irx should handle all that. As long as it's loaded before fileXio you should be able to access all device from fileXio.
KaylaKaze
Posts: 75
Joined: Wed May 05, 2004 3:25 pm
Location: NC, USA
Contact:

Post by KaylaKaze »

Is that new 'cause when I was doing work with ps2mnu-k using the newest ps2lib and ps2drv, I couldn't access the MC with fileXio and ioman is loaded before fileXio.
KaylaKaze
Posts: 75
Joined: Wed May 05, 2004 3:25 pm
Location: NC, USA
Contact:

Post by KaylaKaze »

Maybe the problem is using LibHDD instead of the HDD code in the ps2sdk.

Screw it. It's too much work. I'll just check the filename to see what command it should use.
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

It's my understanding that fileXio depends on iomanX, where the IOP kernel will refuse to load fileXio unless iomanX has been loaded first. And in the last released version of ps2drv, the functionality is in place where iomanX maps to both ioman and iomanX devices. If there's a specific problem then post the source and we'll see what's broken.
KaylaKaze
Posts: 75
Joined: Wed May 05, 2004 3:25 pm
Location: NC, USA
Contact:

Post by KaylaKaze »

My testing function is simply

Code: Select all

  
int Xio=1;
	   int ret=fileXioOpen("mc0:/gamelist.log", O_RDONLY, fileMode);
	    if &#40;ret<0&#41;
	      &#123;
		      dbgprintf&#40;"Error opening file &#40;fileXio&#41;\n"&#41;;
	          Xio=0;
		      ret=fioOpen&#40;"mc0&#58;/gamelist.log",O_RDONLY&#41;;
	          if &#40;ret<0&#41;
	          &#123;
		          dbgprintf&#40;"Error opening file &#40;fio&#41;\n"&#41;;
		          return 1;
	          &#125;
		  &#125;
        u8 temp&#91;100&#93;;
        if &#40;Xio&#41;
        &#123;
	        fileXioRead&#40;ret, temp, 100&#41;;
        	fileXioClose&#40;ret&#41;;
    	&#125;
    	else
    	&#123;
	    	fioRead&#40;ret, temp, 100&#41;;
        	fioClose&#40;ret&#41;;
    	&#125;
        temp&#91;99&#93;='\0';
        dbgprintf&#40;"%s\n",temp&#41;;		
And it always prints the first error and not the second. fileXio works fine for pfs reads though. From looking at the dirtest sample in $(PS2DRV)/ee/samples/directorysample it looks like you have to switch to fileio for MC and HOST functions. Maybe there's something wrong in the module load function.

Code: Select all

scr_printf&#40;"Loading SIO2MAN\n"&#41;;
SifLoadModule&#40;"rom0&#58;SIO2MAN", 0, NULL&#41;;
scr_printf&#40;"Loading MCMAN\n"&#41;;
SifLoadModule&#40;"rom0&#58;MCMAN", 0, NULL&#41;;
scr_printf&#40;"Loading MCSERV\n"&#41;;
SifLoadModule&#40;"rom0&#58;MCSERV", 0, NULL&#41;;
scr_printf&#40;"Loading PADMAN\n"&#41;;
ret = SifLoadModule&#40;"rom0&#58;PADMAN", 0, NULL&#41;;
if &#40;ret < 0&#41;
&#123;
	scr_printf&#40;"Failed to load PAD module"&#41;;
	while&#40;1&#41;;
&#125;
scr_printf&#40;"Loading poweroff.irx %i bytes\n", size_poweroff_irx&#41;;
SifExecModuleBuffer&#40;&poweroff_irx, size_poweroff_irx, 0, NULL, &ret&#41;;
scr_printf&#40;"Loading iomanx.irx %i bytes\n", size_iomanx_irx&#41;;
SifExecModuleBuffer&#40;&iomanx_irx, size_iomanx_irx, 0, NULL, &ret&#41;;
scr_printf&#40;"Loading filexio.irx %i bytes\n", size_filexio_irx&#41;;
SifExecModuleBuffer&#40;&filexio_irx, size_filexio_irx, 0, NULL, &ret&#41;;
scr_printf&#40;"Loading ps2dev9.irx %i bytes\n", size_ps2dev9_irx&#41;;
SifExecModuleBuffer&#40;&ps2dev9_irx, size_ps2dev9_irx, 0, NULL, &ret&#41;;
scr_printf&#40;"Loading ps2atad.irx %i bytes\n", size_ps2atad_irx&#41;;
SifExecModuleBuffer&#40;&ps2atad_irx, size_ps2atad_irx, 0, NULL, ret&#41;;
scr_printf&#40;"Loading ps2hdd.irx %i bytes\n", size_ps2hdd_irx&#41;;
SifExecModuleBuffer&#40;&ps2hdd_irx, size_ps2hdd_irx, izeof&#40;hddarg&#41;, hddarg, &ret&#41;;
scr_printf&#40;"Loading ps2fs.irx %i bytes\n", size_ps2fs_irx&#41;;
SifExecModuleBuffer&#40;&ps2fs_irx, size_ps2fs_irx, sizeof&#40;pfsarg&#41;, pfsarg, &ret&#41;;
scr_printf&#40;"Loading cdvd.irx %i bytes\n", size_cdvd_irx&#41;;
SifExecModuleBuffer&#40;&cdvd_irx, size_cdvd_irx, 0, NULL, &ret&#41;;
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

I'm not sure what the problem could be ... perhaps adresd could provide some insight?
Guest

Post by Guest »

pixel wrote:The only "big" issue with LUA in PS2, is the Lua_Number format. It is double by default, which isn't a good idea to use on the PS2. So, when using float here, you'll render the bytecode incompatible with a PC-lua which still uses double as numbers. And you'll then have to build a custom LUA on the PC side (that is, you have to change Lua_Number format) in order to generate compatible bytecode.
This is always the problem with using bytecode based virtual machines
on the PS2 where double is the default (or only) type of float.

One is left with three choices in this situation:
1. GCC *should* be able to generate double fp operations in software. This
would ensure compatibility with existing softwares that rely on this.
Unfortunately, this has the least performance situation.
2. One could modify the Lua code to store numbers as doubles in the
bytecodes, but convert between REAL/DOUBLE during operations.
This has some performance hit, and any application that relies much
on the additional precision of a double would not behave the entirely
the same.
3. One could convert entirely to real-based operations. This provides the
best speed, but at the cost of compatibility.

#1 is an option if double precision could be done relatively speedily
in software. Most software implementations are blazingly slow. I have
look at writing an optimized library for the PS2 that uses EE multimedia
and core specific instructions to speed up double precision operations
but I have gotten spread thin on homebrew projects. :) It seems it
*could* be useful, so maybe I will spend more time on it.

Gorim
Post Reply