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

Image Image.createEmpty(width, height)

Creates an empty image, initially cleared. Max width and height is 512.

Image Image.load( filename )

nil image:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])

nil image:clear([color = transparent-black]) 
nil image:fillRect(x, y, width, height, [color = transparent-black]) 
nil image:drawLine(x0, y0, x1, y1, [color = black]) 
Color image:pixel(x, y) --get
nil image:pixel(x, y, Color) --set

nil image:print(x, y, text, [color = black]) 

Number image:width()
Number image:height()
nil Image:save( filename )

global Image screen
nil screen.flip() -- note the small s; this is a function of the screen
nil screen.waitVblankStart([count])


Color Color.new(r, g, b, [a=255])
table[r,g,b,a] color:colors()
Bool (Color a == Color b)


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

Controls Controls.read()
Bool controls:select()
Bool controls:start()
Bool controls:up()
Bool controls:right()
Bool controls:down()
Bool controls:left()
Bool controls:l()
Bool controls:r()
Bool controls:triangle()
Bool controls:circle()
Bool controls:cross()
Bool controls:square()
Bool controls:home()
Bool controls:hold()
Bool controls:note()
Number controls:analogX() -- ranges from -127 to 128.
Number controls:analogY() -- same

Bool (Controls a == Controls b) -- note! The analog stick is NOT considered when comparing because of analog fluctuations.

Number controls:buttons() -- returns the bitmask like sceCtrlReadBufferPositive reads it

Constants for binary operations on buttons() result
(for example "Controls.read():buttons() & Controls.startMask > 0" is the same as "Controls.read():start()")
Number Controls.selectMask
Number Controls.startMask
Number Controls.upMask
Number Controls.rightMask
Number Controls.downMask
Number Controls.leftMask
Number Controls.ltriggerMask
Number Controls.rtriggerMask
Number Controls.triangleMask
Number Controls.circleMask
Number Controls.crossMask
Number Controls.squareMask
Number Controls.homeMask
Number Controls.holdMask
Number Controls.noteMask


Millisecond Timer
========================================

Timer Timer.new([startTime]) 

Creates a new Timer object, sets to 0 or startTime in milliseconds, if specified BUT don't start ticking as yet.

Number Timer:start() 

Starts to tick the timer (incrementing by one every millisecond), or resumes to tick after being stopped.
Returns the current time() value. If the timer is running, it is the same as time().

Number Timer:time() 

Returns in milliseconds since the timer started/resumed.

Number Timer:stop() 

Stops the timer. Returns the current time(). Subsequent time() calls returns the value when stopped.
If the timer is stopped, this call is the same as time().

Number Timer:reset([startTime]) 

Resets the timer to 0 by default or startTime in milliseconds and holds the timer.
Returns the time before resetted to the new value. 


System
========================================
String System.currentDirectory() -- get
String System.currentDirectory( path ) -- set, returns old path.
table System.listDirectory()
table System.listDirectory( path )

nil System.usbDiskModeActivate()

Activates the USB mode. Attention: When writing from USB to the memory stick, you must not
write from within your Lua script to the memory stick, until you disable USB, otherwise
the filesystem of your memory stick gets corrupted and you have to reformat your
memmory stick.

nil System.usbDiskModeDeactivate()

Deactivates the USB mode.

Battery functions:

Bool System.powerIsPowerOnline()
Bool System.powerIsBatteryExist()
Bool System.powerIsBatteryCharging()
Number System.powerGetBatteryChargingStatus()
Bool System.powerIsLowBattery()
Number System.powerGetBatteryLifePercent()
Number System.powerGetBatteryLifeTime()
Number System.powerGetBatteryTemp()
Number System.powerGetBatteryVolt()

String System.md5sum(String)

Calculates the md5sum of a string. For example
print(System.md5sum(io.input("EBOOT.PBP"):read("*a")))
prints the same digest as "md5sum EBOOT.PBP" on Unix.

Serial input/output functions:

nil System.sioInit(baudrate)

Opens the SIO device and sets the baud rate. This needs some seconds to power up the UART.

System.sioWrite(string)

Writes the string to the SIO

string System.sioRead()

Reads all available data from the SIO. Returns an empty string, if no data was received.

System.sleep(number) 

Pauses program execution for the specified time in milliseconds. It doesn't affect any timer object.


Sound and music
========================================
nil Music.playFile( string file, bool loop )

Plays a music in one of the following formats:
UNI, IT, XM, S3M, MOD, MTM, STM, DSM, MED, FAR, ULT or 669.

nil Music.pause()
nil Music.resume()
nil Music.stop()
bool Music.playing()
Number Music.volume( [number {0-128}] )

nil SoundSystem.SFXVolume( number {0-128} )
nil SoundSystem.reverb( number {0-15} )
nil SoundSystem.panoramicSeparation( number {0-128} )

Sound Sound.load(filename, [bool loop])
Voice sound:play()

nil voice:stop()
nil voice:resume(Sound) -- DISABLED due to bug.
nil voice:volume( number [0-25] )
nil voice:pan( number [0-255] )
nil voice:frequency( number [0-255] )
bool voice:playing()


Notes
============
 - It's possible to tell mikmod to loop only a part of a sample, or loop backwards, or loop back and forth. Tell nevyn if these attributes are needed.

 - It's a good idea to ignore low values (perhaps -5<x, y<+5) for the analog stick, as its dead zone is larger than a single integer step.