DanielSant0s / AthenaEnv

A complete Javascript environment for creating homebrew applications and games on PlayStation 2.
GNU General Public License v3.0
146 stars 20 forks source link


Logo

Enhanced JavaScript environment for PlayStation 2™

Table of Contents
  1. About AthenaEnv
  2. Coding
  3. Contributing
  4. License
  5. Contact
  6. Thanks

About AthenaEnv

AthenaEnv is a project that seeks to facilitate and at the same time brings a complete kit for users to create homebrew software for PlayStation 2 using the JavaScript language. It has dozens of built-in functions, both for creating games and apps. The main advantage over using AthenaEnv project instead of the pure PS2SDK is above all the practicality, you will use one of the simplest possible languages to create what you have in mind, besides not having to compile, just script and test, fast and simple.

Modules:

New types are always being added and this list can grow a lot over time, so stay tuned.

Built With

Coding

In this section you will have some information about how to code using AthenaEnv, from prerequisites to useful functions and information about the language.

Prerequisites

Using AthenaEnv you only need one way to code and one way to test your code, that is, if you want, you can even create your code on PS2, but I'll leave some recommendations below.

Qt recommendation: Enable console output
console0

Oh, and I also have to mention that an essential prerequisite for using AthenaEnv is knowing how to code in JavaScript.

Quick start with Athena

Hello World:

const font = new Font("default");

os.setInterval(() => { // Basically creates an infinite loop, similar to while true(you can use it too).
  Screen.clear(); // Clear screen for the next frame.
  font.print(0, 0, "Hello World!"); // x, y, text
  Screen.flip(); // Updates the screen.
}, 0);

See more examples at AthenaEnv samples.

Features

AthenaEnv uses a slightly modified version of the QuickJS interpreter for JavaScript language, which means that it brings almost modern JavaScript features so far.

Float32

This project introduces a (old)new data type for JavaScript: single floats. Despite being less accurate than the classic doubles for number semantics, they are important for performance on the PS2, as the console only processes 32-bit floats on its FPU.

You can write single floats on AthenaEnv following the syntax below:

let test_float = 15.0f; // The 'f' suffix makes QuickJS recognizes it as a single float.

or

let test_float = Math.fround(15.0); // Math.fround returns real single floats on Athena.

How to run it

Athena is basically a JavaScript loader, so it loads .js files. It runs "main.js" by default, but you can run other file names by passing it as the first argument when launching the ELF file.

If you try to just download it on releases tab and run it, that's what you will see: _50bda816_20230409025946

That's the default dashboard, coded in default main.js file. It searchs JavaScript files with the first line containing the following structure:

// {"name": "App name", "author": "Who did it?", "version": "04012023", "icon": "app_icon.png", "file": "my_app.js"}
// Now you can freely code below:

Once it was found, it will appear on the dashboard app list.

Error reporting system

Athena has a consistent error system, which is capable of pointing the error type, custom message, files, lines and it even has a color code.

EvalError:
_50bda816_20230409024828

SyntaxError:
_50bda816_20230409024849

TypeError:
_50bda816_20230409024911

ReferenceError:
_50bda816_20230409024944

RangeError:
_50bda816_20230409025004

InternalError:
_50bda816_20230409025029

URIError:
_50bda816_20230409025053

AggregateError:
_50bda816_20230409025131

Functions, classes and consts

Below is the list of usable functions of AthenaEnv project currently, this list is constantly being updated.

P.S.: Italic parameters refer to optional parameters

std module

The std module provides wrappers to the libc stdlib.h and stdio.h and a few other utilities.

Available exports:

Enumeration object containing the integer value of common errors (additional error codes may be defined):

FILE prototype:

Construction:

os module

The os module provides Operating System specific functions:

Available exports:

Color module

Image Module

Construction:

Properties:

Methods:

ImageList

Construction:

var async_list = new ImageList(); // This constructor creates a new thread and a queue to load images in background, avoid building multiple ImageList objects.

Methods:

Draw module

Render module

• Remember to enable zbuffering on screen mode, put the line of code below
• Default NTSC mode(3D enabled):

const canvas = Screen.getMode();
canvas.zbuffering = true;
canvas.psmz = Z16S;

Screen.setMode(canvas);

RenderObject module

Construction:

var model = new RenderObject(mesh, *texture*)
/* Load simple WaveFront OBJ files or vertex arrays.
MTL is supported on OBJs (including per-vertex colors and multi-texturing).
If you don't have a MTL file but you want to bind a texture on it,
just pass the image as a second argument if you want to use it. */

Methods:

Properties:

Camera

Lights
You have 4 lights to use in 3D scenes, use set to configure them.

Screen module

Font module

Construction:

var font = new Font(path);  // It supports png, bmp, jpg, otf, ttf.

path - Path to a font file, E.g.: "images/atlas.png", "fonts/font.png".

var osdfnt = new Font();  //Load BIOS font, not available for all console models  
var font = new Font("Segoe UI.ttf"); //Load trueType font 

Properties:

Methods:

Pads module

Methods:
• update() - Updates all pads pressed and stick positions data.
• pressed(button) - Checks if a button is being pressed (continuously).
• justPressed(button) - Checks if a button was pressed only once.
• setEventHandler() - Sets the pad object to listen events defined by Pads.newEvent, so it doesn't need to be updated.

Keyboard module

Mouse module

System module

Asynchronous functions:

Timer module

Sound module

Archive module

IOP module

Network module

Request module

Construction:

Properties:

Methods:

Asynchronous methods:

Socket module

Construction:

Methods:

WebSocket module

Construction:

Methods:

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AwesomeFeature)
  3. Commit your Changes (git commit -m 'Add some AwesomeFeature')
  4. Push to the Branch (git push origin feature/AwesomeFeature)
  5. Open a Pull Request

License

Distributed under GNU GPL-3.0 License. See LICENSE for more information.

Contact

Daniel Santos - @danadsees - danielsantos346@gmail.com

Project Link: https://github.com/DanielSant0s/AthenaEnv

Thanks

Here are some direct and indirect thanks to the people who made the project viable!