Lua Player for PSP

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
emumaniac
Posts: 79
Joined: Sun May 08, 2005 12:22 am

Post by emumaniac »

bloody hell some great work guys, im gonna have quite a time posting all these new releases, is there a Lua base site with the releases on i can link to instead of the forum thread ?
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

edit: Oops. I pasted into the wrong window.

edit again: Aw crap, I pasted over the message I had already written here.


Egh. I had written that me and Shine concluded that keeping backwards-compatibility with the API isn't that important this early in the project, so we'll simply change the API. I'll get back to this subject later today...
Kinsman
Posts: 15
Joined: Mon Jul 18, 2005 1:41 am
Location: Canada

Post by Kinsman »

Sorry about getting that 'setGlobalVolume' wrong, I mistyped.

The problem was actually with 'setMusicVolume', but it's probably because you forgot to release an updated EBOOT.PBP with the code or something.
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

Kinsman wrote:The problem was actually with 'setMusicVolume', but it's probably because you forgot to release an updated EBOOT.PBP with the code or something.
I did? Aw crap. Oh well. There'll be a new api by next version anyway...

Example with the new sound API, should be self-explainatory:

Code: Select all

Music.volume(96) 
SoundSystem.SFXVolume(128) -- max 
SoundSystem.reverb(4) -- out of 15 
SoundSystem.panoramicSeparation(128) -- 0 is mono 

Music.playFile("music.xm") 
while Music.playing() do 
    print("A music file is playing.") 
end 
Music.playFile("music.xm", true) -- loops forever 

local sndExplosion = Sound.load("explosion.wav") 

voice = sndExplosion:play() 
voice:volume(255) -- max volume 
voice:frequency(11000) -- play at half speed 
voice:pan(0) -- pan all the way to the left 
while voice:playing() do 
    i = i + 1 
    voice:pan(i) 
    waitVblankStart(5) 
end 
-- note that the voice has stopped playing now, and is invalid. 

voice = sndExplosion:play() 
voice:stop() 

Music.stop() 
   
Edit: Changed some calls to oo-style
Last edited by nevyn on Sun Aug 07, 2005 12:03 am, edited 1 time in total.
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

Is there a version with all the new functions in yet?
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

VgSlag wrote:Is there a version with all the new functions in yet?
It's available at svn so you can compile it yourself, but I don't think there'll be a binary release until the graphics API has been fixed too...
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

Is anyone seeing an odd image bug when moving an image off the left hand side of the screen?

I haven't tested any other scenarios but what I have is my BG being blitted to screen then blitting and alpha image (16 * 16) on top.

When the character moves off the left hand side of the screen the image appears to stop moving but the right hand side starts cutting off like it is moving off screen jsut not updating the image.

The only file I have to show this is my "Pyramid Panic" game, but it's in the middle of being worked on, so if you do look at it in this file you may get crashes or unexpected results.

To see it move right, and slowly onto the next screen. If you were slow enough then you'll see the character is half missing.

Move right then slowly move left onto the first screen again, you'll see it there.

Any ideas? Can this be fixed?

My game is here:
http://www.flash-git.net/pyramidPanic.rar
Soban
Posts: 14
Joined: Sat Aug 06, 2005 12:08 pm

Post by Soban »

OK. I have the latest svn of everything - luaplayer, zlib, libpng, mikmodlib, and lua. But when I try to make luaplayer it gives me all sorts of errors in liblualib.a:

Code: Select all

<somefile.c>&#58;&#40;.text+<some offset>&#41;&#58; relocation truncated to fit&#58; R_MIPS_GPREL16 against '_i
mpure_ptr'
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Soban wrote:OK. I have the latest svn of everything - luaplayer, zlib, libpng, mikmodlib, and lua. But when I try to make luaplayer it gives me all sorts of errors in liblualib.a:
You need the latest psp toolchain from SVN. Checkout psptoolchain and update your environment with the toochain.sh shell script. The current Lua Player from SVN works for me, but it is not ready for release, so be patient.
Soban
Posts: 14
Joined: Sat Aug 06, 2005 12:08 pm

Post by Soban »

OK. I'll try updating my toolchain.
Kinsman
Posts: 15
Joined: Mon Jul 18, 2005 1:41 am
Location: Canada

Post by Kinsman »

VgSlag wrote:Is anyone seeing an odd image bug when moving an image off the left hand side of the screen?

I haven't tested any other scenarios but what I have is my BG being blitted to screen then blitting and alpha image (16 * 16) on top.

When the character moves off the left hand side of the screen the image appears to stop moving but the right hand side starts cutting off like it is moving off screen jsut not updating the image.

The only file I have to show this is my "Pyramid Panic" game, but it's in the middle of being worked on, so if you do look at it in this file you may get crashes or unexpected results.

To see it move right, and slowly onto the next screen. If you were slow enough then you'll see the character is half missing.

Move right then slowly move left onto the first screen again, you'll see it there.

Any ideas? Can this be fixed?
Haven't checked the game, but I ran into a similar-sounding issue on my own project. You can't just say you want to draw an image at, for example, (-10,30), and expect it to work, since the Lua Player goes through a bitmap adjusting step where it does bound checking on what it's going to draw. Try using blitAlphaImageRect() for the chases that your images are going to go off-screen, and clip it yourself.
Kinsman
Posts: 15
Joined: Mon Jul 18, 2005 1:41 am
Location: Canada

Post by Kinsman »

Looks like posts picked up again after a rest of a day or so :)

Here's a screenshot of what I'm working on: a 'digital novel' engine, and an engine that could be used for any console-style text game - or a text game mixed with inline graphics.

Ignore the mediocre script and art :) I just made up something off the cuff..

Image
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

Kinsman wrote:Haven't checked the game, but I ran into a similar-sounding issue on my own project. You can't just say you want to draw an image at, for example, (-10,30), and expect it to work, since the Lua Player goes through a bitmap adjusting step where it does bound checking on what it's going to draw. Try using blitAlphaImageRect() for the chases that your images are going to go off-screen, and clip it yourself.
I've fixed the bug, I hope now everything is ok, perhaps someone can verify, if it is correct for every boundary case:

Code: Select all

// returns 0, if nothing to blit
static int adjustBlitRectangle&#40;
	int sourceWidth, int sourceHeight,
	int destinationWidth, int destinationHeight,
	int* sx, int* sy,
	int* width, int* height,
	int* dx, int* dy&#41;
&#123;
	if &#40;*width <= 0 || *height <= 0&#41; return 0;  // zero area, nothing to blit
	if &#40;*sx < 0 || *sy < 0&#41; return 0;  // illegal, source is not clipped
	if &#40;*dx < 0&#41; &#123;
		*width += *dx;
		if &#40;*width <= 0&#41; return 0;
		*sx -= *dx;
		*dx = 0;
		if &#40;*sx >= destinationWidth&#41; return 0;
	&#125;
	if &#40;*dy < 0&#41; &#123;
		*height += *dy;
		if &#40;*height <= 0&#41; return 0;
		*sy -= *dy;
		*dy = 0;
		if &#40;*sy >= destinationHeight&#41; return 0;
	&#125;
	if &#40;*dx + *width > destinationWidth&#41; &#123;
		*width = destinationWidth - *dx;
		if &#40;*width <= 0&#41; return 0;
	&#125;
	if &#40;*dy + *height > destinationHeight&#41; &#123;
		*height = destinationHeight - *dy;
		if &#40;*height <= 0&#41; return 0;
	&#125;
	return 1;
&#125;
@nevyn: please change it in the upcoming luagraphics.c.

I've tested it with a small program, where you can move a mandelbrot fractal, which is calculated by the program:

Code: Select all

-- create mandelbrot fractal
w = 50
h = 50
image = createImage&#40;w, h&#41;
for x=0,w-1 do
	for y=0,h-1 do
		r = 0; n = 0; b = x / w * 3 - 2; e = y / h * 2 - 1; i = 31
		while i > 0 and r * r < 4 do
			d = r; r = r * r - n * n + b; n = 2 * d * n + e; i = i - 1
		end
		color = math.mod&#40;i * 43, 32&#41;
		putPixel&#40;color * 1024 + color * 32, x, y, image&#41;
	end
end

-- move
x = 200
y = 100
while true do
	pad = ctrlRead&#40;&#41;
	if isCtrlUp&#40;pad&#41; then
		y = y - 3
	elseif isCtrlDown&#40;pad&#41; then
		y = y + 3
	elseif isCtrlLeft&#40;pad&#41; then
		x = x - 3
	elseif isCtrlRight&#40;pad&#41; then
		x = x + 3
	end
	clear&#40;0&#41;
	blitImage&#40;x, y, image&#41;
	waitVblankStart&#40;&#41;
	flipScreen&#40;&#41;
end
Soban
Posts: 14
Joined: Sat Aug 06, 2005 12:08 pm

Post by Soban »

I just ran the toolchain and recompiled lua itself, and now luaplayer compiles fine. I have no idea what changed... svn didn't do anything to lua when I ran it and I just ran the toolchain friday, but whatever... For some reason it decided to work now...

Anyway, I'm starting a text editor in lua and c specifically for editing lua scripts. I suppose you could call it a lua IDE. Right now the only special features I'm planning to add are a second virtual keyboard for lua commands and auto-indenting and coloring of functions, vars, reserved words, etc. but if anyone has any suggestions, I'm open.

I probably won't get much done on it this week with family over from cali and work and all, but I'll be working hard on it next week.
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

Soban wrote:I just ran the toolchain and recompiled lua itself, and now luaplayer compiles fine. I have no idea what changed... svn didn't do anything to lua when I ran it and I just ran the toolchain friday, but whatever... For some reason it decided to work now...

Anyway, I'm starting a text editor in lua and c specifically for editing lua scripts. I suppose you could call it a lua IDE. Right now the only special features I'm planning to add are a second virtual keyboard for lua commands and auto-indenting and coloring of functions, vars, reserved words, etc. but if anyone has any suggestions, I'm open.

I probably won't get much done on it this week with family over from cali and work and all, but I'll be working hard on it next week.
"lua and c"? Why not just lua?

I'm planning on writing an event-driven application framework for Lua after LuaPlayer 0.7 is done. That should probably make application writing very much easier. (it will probably take some time though...) (I'll be designing it to resemble the Cocoa framework)
VgSlag
Posts: 43
Joined: Thu Jun 30, 2005 5:36 pm

Post by VgSlag »

Shine wrote: I've fixed the bug, I hope now everything is ok, perhaps someone can verify, if it is correct for every boundary case:
Thanks Shine, I'll check the latest compiled version with my game and see if it's fixed.
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

VgSlag wrote:
Shine wrote: I've fixed the bug, I hope now everything is ok, perhaps someone can verify, if it is correct for every boundary case:
Thanks Shine, I'll check the latest compiled version with my game and see if it's fixed.
It's not in svn yet, I'm still working hard on the new API... I'm getting there, give me one more day...
Soban
Posts: 14
Joined: Sat Aug 06, 2005 12:08 pm

Post by Soban »

nevyn wrote:"lua and c"? Why not just lua?
Because I've barely done any programming on the PSP and I want to mess with it :D .
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

Soban wrote:
nevyn wrote:"lua and c"? Why not just lua?
Because I've barely done any programming on the PSP and I want to mess with it :D .
Point ;)

The problem is, you can't bundle c with lua, so it would need a custom build of luaplayer...

otoh, if you write useful reusable code, it could of course be merged with the real luaplayer sources :)
Soban
Posts: 14
Joined: Sat Aug 06, 2005 12:08 pm

Post by Soban »

The body of the program would be in lua, all that would be added in the C source is a few functions in C, some globals, and a few lua_register()s.

So yeah, I'll try to write something useful :) .
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

Well... Here's my page with Dr. Mario coded in Lua:

http://haggar.pocketheaven.com/


Prolly some of the worst code you'll ever see though ;)
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

Post by nevyn »

MikeHaggar wrote:Well... Here's my page with Dr. Mario coded in Lua:

http://haggar.pocketheaven.com/


Prolly some of the worst code you'll ever see though ;)
Ohyeah! Excellent job! How long did it take to write?

Oh, as long as it works it doesn't matter what the code lo-- holy /crap/! One thousand lines of Lua? That's... That's... You were right, that code ain't too pretty :P I'm impressed that you got it working! (that's actually a compliment :P)
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

Took me 3 days to write... started this saturday and finished today (monday)
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

MikeHaggar wrote:Well... Here's my page with Dr. Mario coded in Lua:

http://haggar.pocketheaven.com/


Prolly some of the worst code you'll ever see though ;)
Nice game. The code is not so bad, but you can shorten it a bit, for example if you use a table for indexing the image for drawing with drawPillTile, so you don't need the long if-elseif-end statement any more. And you could use some more verbose names instead of just indexes (in Lua you can index the tables, like you've done with the red/yellow/blue tables). Nested tables and prototype based classes are possible, too.

And you should use the screenshot function instead of a digital camera, but you can use the picture below.

Image
MikeHaggar
Posts: 116
Joined: Mon Jul 18, 2005 2:20 am

Post by MikeHaggar »

Shine wrote:The code is not so bad, but you can shorten it a bit, for example if you use a table for indexing the image for drawing with drawPillTile, so you don't need the long if-elseif-end statement any more.
for the stuff in the drawFullPill() function you mean, or the stuff in drawMap()?

Whoops! Forgot all about the screenshot function. I'll use your pic instead of my crappy digicam ones ;)

I'll fix that other pic tomorrow... Time for sleep... 00:30 here now...
LiquidIce
Posts: 55
Joined: Mon Apr 04, 2005 1:15 am
Contact:

Post by LiquidIce »

For those of you who are writing an IDE for Lua, check out some of the features this editor has: http://www.wowguru.com/ui/wow-scite-lua/

It was made for World of Warcraft Lua scripting, but it works great for editing my PSP Lua scripts. It's based off SciTe.

While debugging on the PC would speed up the development process, having an enviornment to do realtime debugging on the PSP itself would be much more beneficial. I downloaded nevyn's last build and the 'press any key to restart' is a great help, but what we really need to do is map a function in Lua to activate the USB port. Then the script.lua file can be modified while Lua Player is running, and a key sequence can be used to restart the game.

This should be all we need as far as the drivers go... But how can it be made into a function accessible in Lua?

Code: Select all

    //start necessary drivers
    LoadStartModule&#40;"flash0&#58;/kd/semawm.prx"&#41;;
    LoadStartModule&#40;"flash0&#58;/kd/usbstor.prx"&#41;;
    LoadStartModule&#40;"flash0&#58;/kd/usbstormgr.prx"&#41;;
    LoadStartModule&#40;"flash0&#58;/kd/usbstorms.prx"&#41;;
    LoadStartModule&#40;"flash0&#58;/kd/usbstorboot.prx"&#41;;

    //setup USB drivers
    retVal = sceUsbStart&#40;PSP_USBBUS_DRIVERNAME, 0, 0&#41;;
    if &#40;retVal != 0&#41; &#123;
        printf&#40;"Error starting USB Bus driver &#40;0x%08X&#41;\n", retVal&#41;;
        sceKernelSleepThread&#40;&#41;;
    &#125;
    retVal = sceUsbStart&#40;PSP_USBSTOR_DRIVERNAME, 0, 0&#41;;
    if &#40;retVal != 0&#41; &#123;
        printf&#40;"Error starting USB Mass Storage driver &#40;0x%08X&#41;\n",
               retVal&#41;;
        sceKernelSleepThread&#40;&#41;;
    &#125;
    retVal = sceUsbstorBootSetCapacity&#40;0x800000&#41;;
    if &#40;retVal != 0&#41; &#123;
        printf
            &#40;"Error setting capacity with USB Mass Storage driver &#40;0x%08X&#41;\n",
             retVal&#41;;
        sceKernelSleepThread&#40;&#41;;
    &#125;
    retVal = 0;
From the USB Sample
nevyn
Posts: 136
Joined: Sun Jul 31, 2005 5:05 pm
Location: Sweden
Contact:

-- BIG UPDATE --

Post by nevyn »

The new version of LuaPlayer, 0.7b5, is ready for testing. It has an ENTIRE NEW API, so old apps will NOT be compatible without rewriting. It is entirely possible to write a wrapper library (defining functions with the old names calling functions with the new names), but I'm not going to do it myself...

New in 0.7 (from 0.6):
- Sound and music through Mikmodlib
- Analog stick is fully functional
- Objects garbage collect
- The API is completely redesigned.

I hope people are willing to test the API a little before it's released in binary form... And plus, I have to rewrite Lowser first, too... So, anyone who wants to try it out, update from svn and build. The luaplayer folder (into which a 'make kxploit' will create a binary) contains an example.

The new API:

Code: Select all

Graphics
========================================

Image Image.createEmpty&#40;width, height&#41;
Image Image.load&#40; filename &#41;

nil image&#58;blit&#40;x, y, Image source, &#91;sourcex, sourcey, width, height&#93;, &#91;alpha = true&#93;&#41;

nil image&#58;clear&#40;&#91;color = white&#93;&#41; 
nil image&#58;fillRect&#40;x, y, width, height, &#91;color = black&#93;&#41; 
nil image&#58;drawLine&#40;x0, y0, x1, y1, &#91;color = black&#93;&#41; 
Color image&#58;pixel&#40;x, y&#41; --get
nil image&#58;pixel&#40;x, y, Color&#41; --set

nil image&#58;print&#40;x, y, text, &#91;color = black&#93;&#41; 

Number image&#58;width&#40;&#41;
Number image&#58;height&#40;&#41;
nil Image&#58;save&#40; filename &#41;

global Image screen
nil screen.flip&#40;&#41; -- note the small s; this is a function of the screen
nil screen.waitVblankStart&#40;&#91;count&#93;&#41;


Color Color.new&#40;r, g, b, &#91;a&#93;&#41;
table&#91;r,g,b,a&#93; color&#58;colors&#40;&#41;
Bool &#40;Color a == Color b&#41;


Controls
========================================

Controls Controls.read&#40;&#41;
Bool controls&#58;select&#40;&#41;
Bool controls&#58;start&#40;&#41;
Bool controls&#58;up&#40;&#41;
Bool controls&#58;right&#40;&#41;
Bool controls&#58;down&#40;&#41;
Bool controls&#58;left&#40;&#41;
Bool controls&#58;l&#40;&#41;
Bool controls&#58;r&#40;&#41;
Bool controls&#58;triangle&#40;&#41;
Bool controls&#58;circle&#40;&#41;
Bool controls&#58;cross&#40;&#41;
Bool controls&#58;square&#40;&#41;
Bool controls&#58;home&#40;&#41;
Bool controls&#58;hold&#40;&#41;
Bool controls&#58;note&#40;&#41;
Number controls&#58;analogX&#40;&#41; -- ranges from -127 to 128.
Number controls&#58;analogY&#40;&#41; -- same

Bool &#40;Controls a == Controls b&#41; -- note! The analog stick is NOT considered when comparing because of analog fluctuations.

System
========================================
String System.currentDirectory&#40;&#41; -- get
String System.currentDirectory&#40; path &#41; -- set, returns old path.
table System.listDirectory&#40;&#41;
table System.listDirectory&#40; path &#41;

Sound and music
========================================
nil Music.playFile&#40; string file, bool loop &#41;
nil Music.stop&#40;&#41;
bool Music.playing&#40;&#41;
nil Music.volume&#40; number &#123;0-128&#125; &#41;

nil SoundSystem.SFXVolume&#40; number &#123;0-128&#125; &#41;
nil SoundSystem.reverb&#40; number &#123;0-15&#125; &#41;
nil SoundSystem.panoramicSeparation&#40; number &#123;0-128&#125; &#41;

Sound Sound.load&#40;filename&#41;
Voice sound&#58;play&#40;&#41;

nil voice&#58;stop&#40;&#41;
nil voice&#58;volume&#40; number &#91;0-25&#93; &#41;
nil voice&#58;pan&#40; number &#91;0-255&#93; &#41;
nil voice&#58;frequency&#40; number &#91;0-255&#93; &#41;
bool voice&#58;playing&#40;&#41;
Soban
Posts: 14
Joined: Sat Aug 06, 2005 12:08 pm

Post by Soban »

Looks good.

Fortunately, it looks like everything can be converted just with regular expressions... hell, even regular search and replace...
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: -- BIG UPDATE --

Post by Shine »

nevyn wrote:I hope people are willing to test the API a little before it's released in binary form...
This is difficult for many people without a psptoolchain, so I've built a binary release, but I'll announce it on my webpage later, when the new API is more stable and Nevyn has ported Lowser. The other scripts in the samples directory are ported, including Snake, now with some background music and effect sounds. And there are 2 new functions for activating and deactivating USB. Together with Lowser, the turnaround-time for uploading and testing a new script could be really fast now.
Oobles
Site Admin
Posts: 347
Joined: Sat Jan 17, 2004 9:49 am
Location: Melbourne, Australia
Contact:

Post by Oobles »

I've added a link on the main ps2dev.org web site for LuaPlayer. I've only added a couple of lines of text for the comments. Please add some more details. Just select edit topic on the top right menu.

Feel free to add binary releases of the software there too by using "Add File".

David. aka Oobles.
Post Reply