# libretro/picodrive architecture

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

- Interactive diagram: https://gitdiagram.com/libretro/picodrive
- Repository: https://github.com/libretro/picodrive

## Overview

PicoDrive is a multi-system SEGA console emulator. The principal workflow is to select/load game media, emulate the selected console and peripherals, then present video, audio, and input through a platform frontend. CD, 32X, SVP, cartridge hardware, and 8-bit systems are distinct emulation stages; SH-2 recompilation is an internal performance layer. The README documents broad system and input capabilities, while the sampled source only exposes selected implementation links, so undocumented wiring is omitted.

Main entry points: [`pico/pico.c`](https://github.com/libretro/picodrive/blob/master/pico/pico.c) (Console core), [`pico/memory.c`](https://github.com/libretro/picodrive/blob/master/pico/memory.c) (Main memory), [`platform/common/main.c`](https://github.com/libretro/picodrive/blob/master/platform/common/main.c) (Common frontend), [`pico/cd/memory.c`](https://github.com/libretro/picodrive/blob/master/pico/cd/memory.c) (Sega CD)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Frontends and input"]
  node_common_main["Common frontend<br/>[main.c]"]
  node_retro["Libretro frontend<br/>[libretro.c]"]
  node_input["Input and keyboard<br/>[input_pico.h]"]
end

subgraph group_core["Emulation core"]
  node_emu["Emulator engine<br/>[emu.c]"]
  node_maincore["Console core<br/>[pico.c]"]
  node_memory["Main memory<br/>[memory.c]"]
  node_sms["8-bit systems<br/>[sms.c]"]
end

subgraph group_media["Media and peripherals"]
  node_cart["Cartridge hardware<br/>[carthw.c]"]
  node_cd["Sega CD<br/>[memory.c]"]
  node_cdimage["CD images<br/>[cd_image.c]"]
  node_x32["32X hardware<br/>[32x.c]"]
end

subgraph group_output["Audio and video"]
  node_video["Video rendering<br/>[draw.c]"]
  node_sound["Sound synthesis<br/>[ym2612.c]"]
  node_mix["Audio mixing<br/>[mix.c]"]
end

subgraph group_cpu["CPU execution"]
  node_m68k["68000 execution<br/>[m68k_in.c]"]
  node_sh2["SH-2 recompilation<br/>[compiler.c]"]
  node_emit["Host code emitters<br/>[emit_arm.c]"]
end

node_user(("Player"))

node_user -->|"starts"| node_common_main
node_user -.->|"loads games"| node_retro
node_common_main -->|"runs engine"| node_emu
node_common_main -->|"initializes input"| node_input
node_emu -.->|"runs emulation"| node_maincore
node_maincore -.->|"renders frames"| node_video
node_maincore -.->|"produces audio"| node_sound
node_sound -.->|"mixes audio"| node_mix
node_maincore -.->|"uses memory"| node_memory
node_cart -->|"uses mappings"| node_memory
node_cd -->|"uses mappings"| node_memory
node_cdimage -.->|"provides media"| node_cd
node_x32 -->|"uses mappings"| node_memory
node_maincore -.->|"supports systems"| node_sms
node_maincore -.->|"supports hardware"| node_cart
node_maincore -.->|"supports Sega CD"| node_cd
node_maincore -.->|"supports 32X"| node_x32
node_maincore -.->|"executes CPU"| node_m68k
node_maincore -.->|"runs SH-2"| node_sh2
node_sh2 -->|"emits host code"| node_emit
node_retro -.->|"loads CD media"| node_cdimage
node_user -.->|"controls emulator"| node_input

click node_common_main "https://github.com/libretro/picodrive/blob/master/platform/common/main.c"
click node_retro "https://github.com/libretro/picodrive/blob/master/platform/libretro/libretro.c"
click node_input "https://github.com/libretro/picodrive/blob/master/platform/common/input_pico.h"
click node_emu "https://github.com/libretro/picodrive/blob/master/platform/common/emu.c"
click node_maincore "https://github.com/libretro/picodrive/blob/master/pico/pico.c"
click node_memory "https://github.com/libretro/picodrive/blob/master/pico/memory.c"
click node_cart "https://github.com/libretro/picodrive/blob/master/pico/carthw/carthw.c"
click node_cd "https://github.com/libretro/picodrive/blob/master/pico/cd/memory.c"
click node_cdimage "https://github.com/libretro/picodrive/blob/master/pico/cd/cd_image.c"
click node_x32 "https://github.com/libretro/picodrive/blob/master/pico/32x/32x.c"
click node_sms "https://github.com/libretro/picodrive/blob/master/pico/sms.c"
click node_video "https://github.com/libretro/picodrive/blob/master/pico/draw.c"
click node_sound "https://github.com/libretro/picodrive/blob/master/pico/sound/ym2612.c"
click node_mix "https://github.com/libretro/picodrive/blob/master/pico/sound/mix.c"
click node_m68k "https://github.com/libretro/picodrive/blob/master/cpu/musashi/m68k_in.c"
click node_sh2 "https://github.com/libretro/picodrive/blob/master/cpu/sh2/compiler.c"
click node_emit "https://github.com/libretro/picodrive/blob/master/cpu/drc/emit_arm.c"

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_common_main,node_retro,node_input toneBlue
class node_emu,node_maincore,node_memory,node_sms toneAmber
class node_cart,node_cd,node_cdimage,node_x32 toneMint
class node_video,node_sound,node_mix toneRose
class node_m68k,node_sh2,node_emit,node_user toneIndigo
```

## Components

### Frontends and input

- [Common frontend](https://github.com/libretro/picodrive/blob/master/platform/common/main.c): `platform/common/main.c`
- [Libretro frontend](https://github.com/libretro/picodrive/blob/master/platform/libretro/libretro.c): `platform/libretro/libretro.c`
- [Input and keyboard](https://github.com/libretro/picodrive/blob/master/platform/common/input_pico.h): `platform/common/input_pico.h`

### Emulation core

- [Emulator engine](https://github.com/libretro/picodrive/blob/master/platform/common/emu.c): `platform/common/emu.c`
- [Console core](https://github.com/libretro/picodrive/blob/master/pico/pico.c): `pico/pico.c`
- [Main memory](https://github.com/libretro/picodrive/blob/master/pico/memory.c): `pico/memory.c`
- [8-bit systems](https://github.com/libretro/picodrive/blob/master/pico/sms.c): `pico/sms.c`

### Media and peripherals

- [Cartridge hardware](https://github.com/libretro/picodrive/blob/master/pico/carthw/carthw.c): `pico/carthw/carthw.c`
- [Sega CD](https://github.com/libretro/picodrive/blob/master/pico/cd/memory.c): `pico/cd/memory.c`
- [CD images](https://github.com/libretro/picodrive/blob/master/pico/cd/cd_image.c): `pico/cd/cd_image.c`
- [32X hardware](https://github.com/libretro/picodrive/blob/master/pico/32x/32x.c): `pico/32x/32x.c`

### Audio and video

- [Video rendering](https://github.com/libretro/picodrive/blob/master/pico/draw.c): `pico/draw.c`
- [Sound synthesis](https://github.com/libretro/picodrive/blob/master/pico/sound/ym2612.c): `pico/sound/ym2612.c`
- [Audio mixing](https://github.com/libretro/picodrive/blob/master/pico/sound/mix.c): `pico/sound/mix.c`

### CPU execution

- [68000 execution](https://github.com/libretro/picodrive/blob/master/cpu/musashi/m68k_in.c): `cpu/musashi/m68k_in.c`
- [SH-2 recompilation](https://github.com/libretro/picodrive/blob/master/cpu/sh2/compiler.c): `cpu/sh2/compiler.c`
- [Host code emitters](https://github.com/libretro/picodrive/blob/master/cpu/drc/emit_arm.c): `cpu/drc/emit_arm.c`

### Other components

- **Player**

## Connections

- Player → Common frontend: starts (evidence: `platform/common/main.c`)
- Player → Libretro frontend: loads games (evidence: `README.md`)
- Common frontend → Emulator engine: runs engine (evidence: `platform/common/main.c`)
- Common frontend → Input and keyboard: initializes input (evidence: `platform/common/main.c`)
- Emulator engine → Console core: runs emulation
- Console core → Video rendering: renders frames
- Console core → Sound synthesis: produces audio
- Sound synthesis → Audio mixing: mixes audio
- Console core → Main memory: uses memory
- Cartridge hardware → Main memory: uses mappings (evidence: `pico/carthw/carthw.c`)
- Sega CD → Main memory: uses mappings (evidence: `pico/cd/memory.c`)
- CD images → Sega CD: provides media
- 32X hardware → Main memory: uses mappings
- Console core → 8-bit systems: supports systems (evidence: `README.md`)
- Console core → Cartridge hardware: supports hardware (evidence: `README.md`)
- Console core → Sega CD: supports Sega CD (evidence: `README.md`)
- Console core → 32X hardware: supports 32X (evidence: `README.md`)
- Console core → 68000 execution: executes CPU
- Console core → SH-2 recompilation: runs SH-2 (evidence: `README.md`)
- SH-2 recompilation → Host code emitters: emits host code (evidence: `cpu/sh2/compiler.c`)
- Libretro frontend → CD images: loads CD media (evidence: `platform/libretro/libretro.c`)
- Player → Input and keyboard: controls emulator (evidence: `README.md`)
