# elmasas/lcs-recomp architecture

> Architecture diagram of the GitHub repository elmasas/lcs-recomp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/elmasas/lcs-recomp
- Repository: https://github.com/elmasas/lcs-recomp

## Overview

LCS Recomp is a PC port of GTA: Liberty City Stories, powered by PSPRecomp’s Allegrex analysis, ahead-of-time translation, and runtime. The main play path loads the supplied ELF, installs LCS kernel/HLE behavior, initializes host display and graphics, then executes the guest while translating its GE and audio activity into host output. The README also documents configurable Windows and Linux backends. Several host and profile sources are only partially sampled, so the graph keeps those connections at documented entry points and omits uncertain internal call chains.

Main entry points: [`lcs/host/main.cpp`](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/main.cpp) (LCS launcher), [`src/runtime.cpp`](https://github.com/elmasas/lcs-recomp/blob/main/src/runtime.cpp) (PSP runtime), [`lcs/host/lcs_profile.cpp`](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_profile.cpp) (Kernel HLE profile), [`tools/codegen_main.cpp`](https://github.com/elmasas/lcs-recomp/blob/main/tools/codegen_main.cpp) (AOT code generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["PSP runtime"]
  node_elf["ELF loader<br/>[elf32.cpp]"]
  node_memory[("Guest memory<br/>[guest_memory.cpp]")]
  node_runtime["PSP runtime<br/>[runtime.cpp]"]
  node_context["Allegrex context"]
end

subgraph group_tools["ELF tooling"]
  node_analyzer["ELF analyzer<br/>[analyzer_main.cpp]"]
  node_analysis["Program analysis"]
  node_codegen["AOT code generator<br/>[codegen_main.cpp]"]
end

subgraph group_lcs["LCS emulation"]
  node_lcs_main["LCS launcher<br/>[main.cpp]"]
  node_profile["Kernel HLE profile<br/>[lcs_profile.cpp]"]
  node_geexec["GE command execution<br/>[lcs_ge_exec.cpp]"]
end

subgraph group_host["Host output"]
  node_renderer["GE renderer<br/>[ge_renderer.cpp]"]
  node_backend["GPU backend<br/>[ge_gpu_backend.hpp]"]
  node_window["Display window<br/>[display_window.hpp]"]
  node_controls["Host controls<br/>[lcs_controls.cpp]"]
  node_audio["Audio output"]
  node_media["Media decoder"]
end

node_player(("Player"))
node_gamefiles["Game files"]
node_generated["Generated functions"]
node_host_os(("Host platform"))

node_player -->|"starts game"| node_lcs_main
node_gamefiles -.->|"analyzes ELF"| node_analyzer
node_gamefiles -.->|"translates ELF"| node_codegen
node_gamefiles -->|"supplies ELF"| node_lcs_main
node_analyzer -->|"loads image"| node_elf
node_analyzer -->|"finds functions"| node_analysis
node_codegen -->|"loads image"| node_elf
node_codegen -->|"analyzes code"| node_analysis
node_codegen -->|"writes functions"| node_generated
node_lcs_main -->|"loads ELF"| node_elf
node_lcs_main -->|"runs guest"| node_runtime
node_lcs_main -->|"installs HLE"| node_profile
node_lcs_main -->|"initializes window"| node_window
node_lcs_main -->|"initializes backend"| node_backend
node_lcs_main -->|"initializes output"| node_audio
node_runtime -->|"accesses guest memory"| node_memory
node_runtime -->|"executes guest state"| node_context
node_generated -.->|"registers functions"| node_runtime
node_runtime -->|"dispatches HLE"| node_profile
node_profile -->|"handles GE calls"| node_geexec
node_profile -->|"handles audio calls"| node_audio
node_profile -->|"decodes media"| node_media
node_geexec -->|"submits GE work"| node_renderer
node_renderer -->|"renders frames"| node_backend
node_renderer -->|"reads controls"| node_controls
node_backend -->|"presents frames"| node_window
node_backend -->|"uses graphics API"| node_host_os
node_window -->|"uses window system"| node_host_os
node_audio -->|"plays audio"| node_host_os
node_controls -->|"reads input"| node_host_os

click node_analyzer "https://github.com/elmasas/lcs-recomp/blob/main/tools/analyzer_main.cpp"
click node_analysis "https://github.com/elmasas/lcs-recomp/blob/main/src/program_analysis.cpp"
click node_elf "https://github.com/elmasas/lcs-recomp/blob/main/src/elf32.cpp"
click node_codegen "https://github.com/elmasas/lcs-recomp/blob/main/tools/codegen_main.cpp"
click node_memory "https://github.com/elmasas/lcs-recomp/blob/main/src/guest_memory.cpp"
click node_runtime "https://github.com/elmasas/lcs-recomp/blob/main/src/runtime.cpp"
click node_context "https://github.com/elmasas/lcs-recomp/blob/main/include/psprecomp/allegrex_context.hpp"
click node_lcs_main "https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/main.cpp"
click node_profile "https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_profile.cpp"
click node_geexec "https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_ge_exec.cpp"
click node_renderer "https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/ge_renderer.cpp"
click node_backend "https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/ge_gpu_backend.hpp"
click node_window "https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/display_window.hpp"
click node_controls "https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_controls.cpp"
click node_audio "https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_audio_output.cpp"
click node_media "https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_media_decoder.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_elf,node_memory,node_runtime,node_context toneBlue
class node_analyzer,node_analysis,node_codegen toneAmber
class node_lcs_main,node_profile,node_geexec toneMint
class node_renderer,node_backend,node_window,node_controls,node_audio,node_media toneRose
class node_player,node_gamefiles,node_generated,node_host_os toneIndigo
```

## Components

### PSP runtime

- [ELF loader](https://github.com/elmasas/lcs-recomp/blob/main/src/elf32.cpp): `src/elf32.cpp`
- [Guest memory](https://github.com/elmasas/lcs-recomp/blob/main/src/guest_memory.cpp): `src/guest_memory.cpp`
- [PSP runtime](https://github.com/elmasas/lcs-recomp/blob/main/src/runtime.cpp): `src/runtime.cpp`
- [Allegrex context](https://github.com/elmasas/lcs-recomp/blob/main/include/psprecomp/allegrex_context.hpp): `include/psprecomp/allegrex_context.hpp`

### ELF tooling

- [ELF analyzer](https://github.com/elmasas/lcs-recomp/blob/main/tools/analyzer_main.cpp): `tools/analyzer_main.cpp`
- [Program analysis](https://github.com/elmasas/lcs-recomp/blob/main/src/program_analysis.cpp): `src/program_analysis.cpp`
- [AOT code generator](https://github.com/elmasas/lcs-recomp/blob/main/tools/codegen_main.cpp): `tools/codegen_main.cpp`

### LCS emulation

- [LCS launcher](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/main.cpp): `lcs/host/main.cpp`
- [Kernel HLE profile](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_profile.cpp): `lcs/host/lcs_profile.cpp`
- [GE command execution](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_ge_exec.cpp): `lcs/host/lcs_ge_exec.cpp`

### Host output

- [GE renderer](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/ge_renderer.cpp): `lcs/host/ge_renderer.cpp`
- [GPU backend](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/ge_gpu_backend.hpp): `lcs/host/ge_gpu_backend.hpp`
- [Display window](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/display_window.hpp): `lcs/host/display_window.hpp`
- [Host controls](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_controls.cpp): `lcs/host/lcs_controls.cpp`
- [Audio output](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_audio_output.cpp): `lcs/host/lcs_audio_output.cpp`
- [Media decoder](https://github.com/elmasas/lcs-recomp/blob/main/lcs/host/lcs_media_decoder.cpp): `lcs/host/lcs_media_decoder.cpp`

### Other components

- **Player**
- **Game files**
- **Generated functions**
- **Host platform**

## Connections

- Player → LCS launcher: starts game
- Game files → ELF analyzer: analyzes ELF
- Game files → AOT code generator: translates ELF
- Game files → LCS launcher: supplies ELF
- ELF analyzer → ELF loader: loads image
- ELF analyzer → Program analysis: finds functions
- AOT code generator → ELF loader: loads image
- AOT code generator → Program analysis: analyzes code
- AOT code generator → Generated functions: writes functions
- LCS launcher → ELF loader: loads ELF
- LCS launcher → PSP runtime: runs guest
- LCS launcher → Kernel HLE profile: installs HLE
- LCS launcher → Display window: initializes window
- LCS launcher → GPU backend: initializes backend
- LCS launcher → Audio output: initializes output
- PSP runtime → Guest memory: accesses guest memory
- PSP runtime → Allegrex context: executes guest state
- Generated functions → PSP runtime: registers functions
- PSP runtime → Kernel HLE profile: dispatches HLE
- Kernel HLE profile → GE command execution: handles GE calls
- Kernel HLE profile → Audio output: handles audio calls
- Kernel HLE profile → Media decoder: decodes media
- GE command execution → GE renderer: submits GE work
- GE renderer → GPU backend: renders frames
- GE renderer → Host controls: reads controls
- GPU backend → Display window: presents frames
- GPU backend → Host platform: uses graphics API
- Display window → Host platform: uses window system
- Audio output → Host platform: plays audio
- Host controls → Host platform: reads input
