# pvz-ps2

A PlayStation 2 port of Plants vs. Zombies, built as the fourth link in a chain of forks. Patoke's `re-plants-vs-zombies` decompiled the PvZ Game of the Year executable and started modernizing PopCap's SexyAppFramework — a 2005-era C++ engine on DirectDraw and Direct3D7. headshot2017's fork replaced the renderer with SDL2 and OpenGL, swapped DirectSound/BASS/FMOD for SDL Mixer X, and ported the result to Windows, Linux, Haiku, Nintendo Switch, and (in progress) 3DS. OptiJuegos then took that and aimed it at hardware from 2000.

The README is almost entirely inherited from upstream and does not describe the PS2 work at all — its platform table lists Windows through Wii U with no PS2 row. The only original text is three lines at the top: build it with `build ps2.bat` on Windows, edit the CMake config yourself on Linux, and use a compressed `main.pak` "to avoid slow loading and crashing." What the port actually consists of has to be read out of the tree.

## What was built

The PS2 code lives in `SexyAppFramework/platform/ps2/` and its centerpiece is `gles_ps2.cpp` — a hand-written implementation of the slice of OpenGL the engine calls, over [gsKit](https://github.com/ps2dev/gsKit). The header declares the GL types and constants from scratch (`GLenum`, `GLbitfield`, `GL_TRIANGLE_FAN`, `GL_UNSIGNED_BYTE`, the lot) because there is no GL on a PS2. Rather than port the game to the Graphics Synthesizer's model, the port ported the API the game already speaks.

Around that:

- `Ps2VramAllocator` manages the PS2's 4 MB of video RAM by hand, with alloc, free, and a full-eviction path, plus debug counters (`ps2_dbg_vram_current_kb`, `ps2_dbg_vram_free_blocks`, `ps2_dbg_vram_recycled_kb`). Texture residency is the port's central problem and it needed its own allocator.
- `Ps2TextureConversion` turns the engine's 32-bit BGRA surfaces into the GS pixel formats — PSMCT32 (note the `>> 1` on alpha, since the GS treats 0x80 as fully opaque), PSMCT16 with 5-5-5-1 truncation, and a T8 palettizer with CLUT CSM1 index swizzling for 8-bit indexed textures. Halving the bit depth or going indexed is how the assets fit at all.
- `SDL.h` is not SDL. It is a shim providing `SDL_Init`, `SDL_GetTicks`, `SDL_Delay` and a two-member event union so the shared SexyApp main loop compiles unchanged. `SDL_GetTicks` reads `GetTimerSystemTime()` off the EE timer rather than newlib's `clock()`, with a comment explaining why: `clock()` is CPU-time based on PS2 and stops advancing while the main thread sleeps, and the engine's loop waits for that value to move before it runs its first update.
- The rest is platform plumbing — `Ps2PadState` and `Input.cpp` for the controller, `Ps2SoundManager`, `Ps2IoLock`, `Ps2AssetIndex`, `Ps2Trace` (a border-colour tracer, compiled out by default), and `main_pvz_ps2.cpp`, which reads the device prefix off `argv[0]` (`cdrom0:`, `mass:`, `host:`) to decide where to read assets and write saves.

`CMake/ps2_embed_irx.cmake` embeds IOP driver modules into the ELF, and `build ps2.bat` drives CMake presets with an optional `iso` step that produces a disc image: it writes a `SYSTEM.CNF` with `BOOT2 = cdrom0:\SLUS_67420.69;1`, a made-up serial in the US retail format.

## The dependency dump

"it has all the dependencies (windows)!!" is literal. `psdevwindows/` contains the entire ps2dev toolchain checked into git: PS2SDK, gsKit, and GCC 15.2.0 cross-compilers for both processors — `mips64r5900el-ps2-elf` for the Emotion Engine and `mipsel-none-elf` for the I/O Processor. About 4,100 of the repository's ~5,100 tracked paths are that toolchain. It is why the Windows build is a double-click and why Linux users are told to sort out CMake themselves.

## What is not known

There is no release, no screenshot, no compatibility note, and no statement about whether it runs on real hardware or only under PCSX2. The repository is six commits over two days (2026-07-09 to 2026-07-10) and has not been touched since; the last two commits are IOP file-I/O fixes contributed by someone else. So the code is real and specific, and the outcome is unrecorded — this page describes what was written, not what works.

Assets are not included and cannot be: the port needs `main.pak` and the `properties` folder from a purchased copy of PvZ GOTY, and upstream is explicit about not shipping PopCap IP beyond the open-sourced engine. GitHub reports the license as CC0-1.0, inherited from the upstream decompilation rather than chosen here.

Tagged `watchlist` — see [[toolbox/watchlist]]. Worth one re-check to see whether it gains a release and any evidence of running, or stays a two-day artifact.

The wider habit this belongs to is covered by [[retrocatalog]] (the modern handheld and emulation-target catalog, where PS2 is a named tier) and [[mac-classic]] (keeping period software usable rather than merely archived). This sits on the other side of that line: instead of emulating a PS2 to play old games, it compiles a 2009 PC game down to run on one.

CC0-1.0, ~42★ as of 2026-07-29. Upstream: [Patoke/re-plants-vs-zombies](https://github.com/Patoke/re-plants-vs-zombies) and [headshot2017's fork](https://github.com/headshot2017/re-plants-vs-zombies).
