# metroidret/mzm architecture

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

- Interactive diagram: https://gitdiagram.com/metroidret/mzm
- Repository: https://github.com/metroidret/mzm

## Overview

This repository is a work-in-progress decompilation of Metroid: Zero Mission, with source for the GBA game and an NES Metroid emulator component. The main runtime workflow is gameplay: Samus moves and fights through rooms while game systems render the world, present menus, manage audio, and save progress; cutscenes and the ending/gallery provide separate presentation stages. The graph reflects documented modules and sampled dependencies, not a fully traced runtime call graph. Several major subsystems are represented by their source directories because their implementations were not sampled.

Main entry points: [`src/agbmain.c`](https://github.com/metroidret/mzm/blob/main/src/agbmain.c) (Game loop), [`src/samus.c`](https://github.com/metroidret/mzm/blob/main/src/samus.c) (Samus movement), [`src/menus`](https://github.com/metroidret/mzm/tree/main/src/menus) (Game menus), [`src/sprites_ai`](https://github.com/metroidret/mzm/tree/main/src/sprites_ai) (Enemy behavior)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Game runtime"]
  node_game["Game loop<br/>[agbmain.c]"]
  node_samus["Samus movement<br/>[samus.c]"]
  node_audio["Music and sound<br/>[audio.c]"]
  node_gba["GBA hardware interface<br/>[gba.h]"]
end

subgraph group_world["World and actors"]
  node_rooms["Rooms and tiles<br/>[rooms_data.c]"]
  node_blocks["Block collision<br/>[block.c]"]
  node_clipdata["Collision data<br/>[clipdata.c]"]
  node_sprites["Sprite runtime<br/>[sprite.c]"]
  node_spriteutil["Sprite utilities<br/>[sprite_util.c]"]
  node_spriteai["Enemy behavior"]
  node_spriteassets["Enemy assets"]
end

subgraph group_presentation["Presentation"]
  node_menus["Game menus"]
  node_cutscenes["Story cutscenes"]
  node_hud["HUD and text<br/>[hud_generic.c]"]
end

subgraph group_persistence["Save and emulation"]
  node_save[("Save files<br/>[sram.c]")]
  node_nes["NES emulator<br/>[part6.c]"]
end

node_player(("Player controls"))

node_player -.->|"plays"| node_game
node_game -.->|"updates"| node_samus
node_samus -->|"queries collision"| node_clipdata
node_samus -->|"uses"| node_blocks
node_game -.->|"loads world"| node_rooms
node_game -.->|"updates"| node_sprites
node_spriteai -->|"uses assets"| node_spriteassets
node_spriteai -.->|"calls utilities"| node_spriteutil
node_game -.->|"dispatches"| node_menus
node_menus -->|"uses save data"| node_save
node_menus -->|"uses text"| node_hud
node_game -.->|"dispatches"| node_cutscenes
node_cutscenes -->|"uses hardware"| node_gba
node_game -.->|"updates audio"| node_audio
node_nes -->|"uses SRAM"| node_save
node_game -.->|"uses hardware"| node_gba

click node_game "https://github.com/metroidret/mzm/blob/main/src/agbmain.c"
click node_samus "https://github.com/metroidret/mzm/blob/main/src/samus.c"
click node_rooms "https://github.com/metroidret/mzm/blob/main/src/data/rooms_data.c"
click node_blocks "https://github.com/metroidret/mzm/blob/main/src/block.c"
click node_clipdata "https://github.com/metroidret/mzm/blob/main/src/clipdata.c"
click node_sprites "https://github.com/metroidret/mzm/blob/main/src/sprite.c"
click node_spriteutil "https://github.com/metroidret/mzm/blob/main/src/sprite_util.c"
click node_spriteai "https://github.com/metroidret/mzm/tree/main/src/sprites_ai"
click node_spriteassets "https://github.com/metroidret/mzm/tree/main/src/data/sprites"
click node_menus "https://github.com/metroidret/mzm/tree/main/src/menus"
click node_cutscenes "https://github.com/metroidret/mzm/tree/main/src/cutscenes"
click node_hud "https://github.com/metroidret/mzm/blob/main/src/hud_generic.c"
click node_audio "https://github.com/metroidret/mzm/blob/main/src/audio.c"
click node_save "https://github.com/metroidret/mzm/blob/main/src/sram/sram.c"
click node_nes "https://github.com/metroidret/mzm/blob/main/nes_metroid/emulator/src/part6.c"
click node_gba "https://github.com/metroidret/mzm/blob/main/include/gba.h"

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_game,node_samus,node_audio,node_gba toneBlue
class node_rooms,node_blocks,node_clipdata,node_sprites,node_spriteutil,node_spriteai,node_spriteassets toneAmber
class node_menus,node_cutscenes,node_hud toneMint
class node_save,node_nes toneRose
class node_player toneIndigo
```

## Components

### Game runtime

- [Game loop](https://github.com/metroidret/mzm/blob/main/src/agbmain.c): `src/agbmain.c`
- [Samus movement](https://github.com/metroidret/mzm/blob/main/src/samus.c): `src/samus.c`
- [Music and sound](https://github.com/metroidret/mzm/blob/main/src/audio.c): `src/audio.c`
- [GBA hardware interface](https://github.com/metroidret/mzm/blob/main/include/gba.h): `include/gba.h`

### World and actors

- [Rooms and tiles](https://github.com/metroidret/mzm/blob/main/src/data/rooms_data.c): `src/data/rooms_data.c`
- [Block collision](https://github.com/metroidret/mzm/blob/main/src/block.c): `src/block.c`
- [Collision data](https://github.com/metroidret/mzm/blob/main/src/clipdata.c): `src/clipdata.c`
- [Sprite runtime](https://github.com/metroidret/mzm/blob/main/src/sprite.c): `src/sprite.c`
- [Sprite utilities](https://github.com/metroidret/mzm/blob/main/src/sprite_util.c): `src/sprite_util.c`
- [Enemy behavior](https://github.com/metroidret/mzm/tree/main/src/sprites_ai): `src/sprites_ai`
- [Enemy assets](https://github.com/metroidret/mzm/tree/main/src/data/sprites): `src/data/sprites`

### Presentation

- [Game menus](https://github.com/metroidret/mzm/tree/main/src/menus): `src/menus`
- [Story cutscenes](https://github.com/metroidret/mzm/tree/main/src/cutscenes): `src/cutscenes`
- [HUD and text](https://github.com/metroidret/mzm/blob/main/src/hud_generic.c): `src/hud_generic.c`

### Save and emulation

- [Save files](https://github.com/metroidret/mzm/blob/main/src/sram/sram.c): `src/sram/sram.c`
- [NES emulator](https://github.com/metroidret/mzm/blob/main/nes_metroid/emulator/src/part6.c): `nes_metroid/emulator/src/part6.c`

### Other components

- **Player controls**

## Connections

- Player controls → Game loop: plays
- Game loop → Samus movement: updates
- Samus movement → Collision data: queries collision (evidence: `src/samus.c`)
- Samus movement → Block collision: uses (evidence: `src/samus.c`)
- Game loop → Rooms and tiles: loads world
- Game loop → Sprite runtime: updates
- Enemy behavior → Enemy assets: uses assets (evidence: `src/sprites_ai/worker_robot.c`)
- Enemy behavior → Sprite utilities: calls utilities
- Game loop → Game menus: dispatches
- Game menus → Save files: uses save data (evidence: `src/menus/file_select.c`)
- Game menus → HUD and text: uses text (evidence: `src/menus/file_select.c`)
- Game loop → Story cutscenes: dispatches
- Story cutscenes → GBA hardware interface: uses hardware (evidence: `src/cutscenes/ridley_in_space.c`)
- Game loop → Music and sound: updates audio
- NES emulator → Save files: uses SRAM (evidence: `nes_metroid/emulator/src/part6.c`)
- Game loop → GBA hardware interface: uses hardware
