Sly 1:Executable: Difference between revisions

From SlyMods
Jump to navigation Jump to search
Content added Content deleted
(→‎Libraries: Added libdma description)
(Rework section on __main & a couple other things)
Line 5: Line 5:
{{Hatnote|This section contains educated guesses based on available information and context clues, and may be inaccurate or incomplete.}}
{{Hatnote|This section contains educated guesses based on available information and context clues, and may be inaccurate or incomplete.}}


=== Shared libraries ===
=== IOP module libraries ===
These libary files are included on the disc alongside the game executable.
These library files are included on the disc alongside the game executable, and are loaded on the IOP core by it.


* '''sio2man.irx''' – Manager Interface for joypads, multitaps and memory cards<ref name=":0">[https://www.retroreversing.com/irx-ps2 IRX Files for Playstation 2] - Retro Reversing, 29 March 2021</ref>
* '''sio2man.irx''' – Manager Interface for joypads, multitaps and memory cards<ref name=":0">[https://www.retroreversing.com/irx-ps2 IRX Files for Playstation 2] - Retro Reversing, 29 March 2021</ref>
Line 16: Line 16:


=== Static libraries ===
=== Static libraries ===
These libraries are bundled with the executable and only referenced by name in some strings.
These libraries are bundled with the executable and some are only referenced by name in some strings.


==== Standard libraries ====
* '''libkernl''' – PlayStation kernel library
These libraries are shipped either by the Cygnus ee-gcc toolchain or gcc directly.

* '''libgcc''' – GCC internal runtime library
* '''newlib''' – C runtime library
* '''libio –''' GNU implementation of C++ IO streams
* '''libstdc++ –''' GNU C++ standard library

==== PS2 SDK libraries ====
These libraries are part of the PS2 SDK and written by SCEI.
* '''libkernel''' – Interface to the EE Kernel (syscall wrappers/etc.)
* '''libmc 2430''' – Memory card library
* '''libmc 2430''' – Memory card library
* '''libgraph 2400''' – [[Wikipedia:PlayStation 2 technical specifications#Graphics%20processing%20unit|Graphics synthesizer]] library<ref name=":1">[https://www.retroreversing.com/static-libraries-ps2 Static Libraries (.A) for Playstation 2 Emotion Engine] - Retro Reversing, 9 July 2022</ref>
* '''libgraph 2400''' – [[Wikipedia:PlayStation 2 technical specifications#Graphics%20processing%20unit|Graphics Synthesizer]] library<ref name=":1">[https://www.retroreversing.com/static-libraries-ps2 Static Libraries (.A) for Playstation 2 Emotion Engine] - Retro Reversing, 9 July 2022</ref>
* '''libdma  2400''' – Direct Memory Access (DMA) library
* '''libdma  2400''' – Direct Memory Access (DMA) library
* '''libcdvd 2420''' – CD/DVD library
* '''libcdvd 2420''' – CD/DVD library
Line 27: Line 37:


==Initialization and main loop==
==Initialization and main loop==
The entry point for the executable is <code>_start</code>. It sets up the main thread, initializes the main thread's heap, and calls <code>main</code>. The <code>main</code> function takes two arguments, <code>int cphzArgs</code> (the number of arguments) and <code>char** apchzArgs</code> (the array of arguments). It performs some initialization and begins the main game loop.
The entry point for the executable is <code>_start</code>, which is provided by the PS2 SDK's <code>crt0.s</code>.

It sets up the main thread, initializes the main thread's heap, and calls <code>main</code>. The <code>main</code> function takes two arguments, <code>int cphzArgs</code> (the number of arguments) and <code>char** apchzArgs</code> (the array of arguments). It performs some initialization and begins the main game loop.


=== Initialization ===
=== Initialization ===
<code>main</code> starts by calling <code>__main</code>, a function that iterates over a function table and calls each function to initialize several game variables. Execution then returns to <code>main</code> which stores the passed parameters in <code>g_cphzArgs</code> and <code>g_apchzArgs</code> respectively. It then calls <code>Startup</code>, a function which initializes even more game variables.
<code>main</code> starts by calling <code>__main</code>, a libgcc function that iterates through a generated table of initialization functions which initialize global variables and construct global objects, calling them all.

{{Investigate|Investigate and expand on what <code>__main</code> and <code>Startup</code> do}}
Execution then returns to <code>main</code> which stores the passed parameters in <code>g_cphzArgs</code> and <code>g_apchzArgs</code> respectively. It then calls <code>Startup</code>, a function which initializes even more game variables.
{{Investigate|Investigate and expand on what <code>Startup</code> does.}}


=== Game loop ===
=== Game loop ===

Revision as of 22:55, 3 November 2022

SCUS_971.98 is the executable for Sly Cooper and the Thievius Raccoonus. It is an ELF binary compiled for the PS2’s Emotion Engine processor. The compiler is GCC v2.9-ee-991111b.[1]

Libraries

IOP module libraries

These library files are included on the disc alongside the game executable, and are loaded on the IOP core by it.

  • sio2man.irx – Manager Interface for joypads, multitaps and memory cards[2]
  • padman.irx – Gamepad manager[2]
  • mcman.irx – Memory card manager[2]
  • mcserv.irx – Memory card server[2]
  • libsd.irx – Sound library[2]
  • 989snd.irx – Sound driver

Static libraries

These libraries are bundled with the executable and some are only referenced by name in some strings.

Standard libraries

These libraries are shipped either by the Cygnus ee-gcc toolchain or gcc directly.

  • libgcc – GCC internal runtime library
  • newlib – C runtime library
  • libio – GNU implementation of C++ IO streams
  • libstdc++ – GNU C++ standard library

PS2 SDK libraries

These libraries are part of the PS2 SDK and written by SCEI.

  • libkernel – Interface to the EE Kernel (syscall wrappers/etc.)
  • libmc 2430 – Memory card library
  • libgraph 2400Graphics Synthesizer library[3]
  • libdma  2400 – Direct Memory Access (DMA) library
  • libcdvd 2420 – CD/DVD library
  • libpad  2410 – DualShock gamepad library
  • libipu  2400 – Image data Processor (IPU) library[3]

Initialization and main loop

The entry point for the executable is _start, which is provided by the PS2 SDK's crt0.s.

It sets up the main thread, initializes the main thread's heap, and calls main. The main function takes two arguments, int cphzArgs (the number of arguments) and char** apchzArgs (the array of arguments). It performs some initialization and begins the main game loop.

Initialization

main starts by calling __main, a libgcc function that iterates through a generated table of initialization functions which initialize global variables and construct global objects, calling them all.

Execution then returns to main which stores the passed parameters in g_cphzArgs and g_apchzArgs respectively. It then calls Startup, a function which initializes even more game variables.

Game loop

The logic of the main game loop can be broken down as follows.

  • First, check if g_mpeg has an MPEG queued to be played. If so:
    • FlushFrames(1) – Calls some graphics functions and swap the graphics synthesizer buffers
    • CTransition::Execute(&g_transition) – Executes the MPEG on the global transition instance
  • Check if g_transition has a pending transition (m_fPending != 0). If so:
    • FlushFrames(1)
    • Call a function that calls CMpeg::Execute on the g_transition instance.
  • Check again if g_mpeg has an MPEG queued to be played (this happens if two MPEGs were queued to play back-to-back) If so:
    • FlushFrames(1)
    • CTransition::Execute(&g_transition)
  • UpdateJoy(&g_joy) – Handles controller input
  • UpdateCodes() – Watches for cheat code inputs
  • Call an unknown function that handles saving the game.
  • UpdateUi(&g_ui) – Updates the state of the GUI
  • UpdateGameState(g_clock.dt) – Updates the running timers on the game state structs
  • if (g_psw != NULLPTR) – If g_psw is not null..
    • SetupCm(g_pcm) – Sets up some camera values to render the next frame
    • OpenFrame() – Prepares to render the next frame
    • MarkClockTick(&g_clock) – Updates the global clock values
    • Grab a particular function pointer from the g_psw struct and execute it if it is not NULL. The function's purpose is unknown but it takes g_clock.dt as an argument, so it's probably an Update function.
    • RenderSw(g_psw, g_pcm) – Renders game objects from the given camera perspective
    • RenderUi() – Renders the GUI blots on the current frame
    • DrawSw(g_psw, g_pcm) – Draws the game objects from the given camera perspective
    • DrawUi() – Draws the GUI elements on the frame
    • CloseFrame() – Finishes rendering the frame
  • Increment the global frame counter, g_cframe.

This routine continues in an infinite loop unless Exit is called or a handled exception causes execution to halt, in which case you are immediately booted back to the PS2 BIOS.

Build strings

The executable contains the following strings generated during the build process.

g_achzBuildUser

jojo

g_achzBuildDateLong

08/24/02 22:06

g_achzBuildDateShort

0824.2206

References

  1. Based on strings found in the May 2002 demo build
  2. 2.0 2.1 2.2 2.3 2.4 IRX Files for Playstation 2 - Retro Reversing, 29 March 2021
  3. 3.0 3.1 Static Libraries (.A) for Playstation 2 Emotion Engine - Retro Reversing, 9 July 2022