Archive for January, 2011

PS3Print: Console Printer for PS3.

January 26 | 11

I started to grow some interest in console programming back when I was working at Unity Technologies but there was just not enough time to start learning; now that I’m not working there, that I own a PS3 and that the PS3 was jail broken I started to read lots of forum posts from psx-scene and started to learn about how to create some home brew apps.

My current goal is to create a simple app that recognizes all the buttons of the PS3 controller and show their values on the screen. Sadly PSL1GHT doesn’t include any quick library to start writing letters on the screen.

After some research over the internets I found this blog post about printing strings on the PS3 which caught my attention and this is how PS3Print started.

So basically PS3Print is  a simple static class written in C++ and it helps you out visualizing strings on the PS3 screen.

This library works with PSL1GHT but its not tied to it so is pretty easy to port.

This simple library only has 3 files:

  1. PS3Printer.h: Which contains all the prototypes and the and some pre-defined Font colors.
  2. PS3Printer.cpp: Which contains the implementation of all the prototypes.
  3. console_fonts.h: Which is a simple Array of arrays of integers which contains almost all the ASCII characters (at least the most used ones).

Using PS3Print:

Using PS3Print is pretty simple just place the 3 source files and you are almost ready.

To start using it just include PS3Printer.h:

#include "PS3Printer.h"

Then you just need to initialize the library with “Init”. The syntax:

static void Init(int screenWidth, int screenHeight);

screenWidth and height correspond to your TV/Monitor resolution where the PS3 is connected.

After this, you are pretty much ready to do print whatever you want with these functions:


static void Print(float x, float y, std::string text, uint32_t* buffer);
static void PrintError(float x, float y, std::string errorMsg, uint32_t* buffer);
static void PrintWarning(float x, float y, std::string warnMsg, uint32_t* buffer);

Where:

  • x and y: Represent the positioning of the text on the screen. These values go from 0 to 1 where (0,0) is the top left corner of the screen and (1,1) is the botom right side of the screen.
  • text / errorMsg / warnMsg: Represent the text you are wanting to print in the screen.
  • buffer: Represents the frame buffer that the ps3 is currently rendering on the screen.

The main difference between Print/PrintError and PrintWarning is that you can set the font color and the background color on the Print function while in the PrintError it always draws the messages in a yellow font color with a red backgroun, and the PrintWarning will draw the message in a yellow font color with a transparent background.

Now that you are able to print you can change the font color with these 2 functions:

static void SetFontColor(int _bgColor, int _fgColor);
static void SetFontColor(int _fgColor);

Where:

  • _bgColor: Represents the back ground color of the font
  • _fgColor: Represents the font color.

The colors are in the 0xAARRGGBB. (alpha channel not available yet). you can always check in PS3Printer.h for a few defined colors.

If you are still reading here and want to see a working example, you can always check the project here in GitHub for both getting the source code and the example.

Happy Coding! 😀

Thanks to:

Scognito and Bitmaps fonts (courtesy of libogc).

Emacs mode for Javascript in Unity 3.x

January 11 | 11

It has been almost a year since I released an emacs mode for Javascript in Unity 2.x , now I’m releasing the same mode for Unity 3.x, the main difference between this mode and the old one are mainly additions of reserved words of the API (as there have been lots of additions to it) and also now it  colors the  “case” word.

This mode supports both Runtime and Editor API functions. Feel free to modify it and also if you do anything interesting that can be added to the mode just let me know!

To make it work, just add this to your .emacs:

;; UnityJS mode for emacs
(autoload ‘unityjs-mode “unityjs-mode” “Major mode for editing Unity script code.” t)
(require ‘unityjs-mode)

And make sure to load the path where you are going to store the .el file.

The mode can be found here.

Any suggestions/feedback/bugs let me know!
😉