# Emulation Management - One Liners

# Create .M3U Playlist From .CHD Files (Windows)

[m3umaker.ps1](https://wikipedia.mutschlerhome.com/attachments/216)

```powershell
# Get the current directory
$folderPath = Get-Location
# Remove existing .m3u files in the current directory
Get-ChildItem -Path $folderPath -Filter *.m3u | Remove-Item -Force
# Get all .chd files in the current directory
$chdFiles = Get-ChildItem -Path $folderPath -Filter *.chd
# Group .chd files by base name (without the disc part and extension)
$groupedFiles = $chdFiles | Group-Object { $_.BaseName -replace '\s+\(Disc\s+\d+\)$', '' }
foreach ($group in $groupedFiles) {
# Determine the .m3u file name (without disc number and extension)
$m3uFileName = Join-Path $folderPath ($group.Name + ".m3u")
# Create or overwrite the .m3u file and write each .chd file name to it
$group.Group | ForEach-Object {Add-Content -Path $m3uFileName -Value $_.Name}}
```

# Create .CHD From .ISO Files

## Windows

[ISO2CHD.bat](https://wikipedia.mutschlerhome.com/attachments/217)

```bash
for /r %%i in (*.iso) do chdman createcd -i "%%i" -o "%%~ni.chd" >> log
```

## Linux

[convertFromIsoToChd.sh](https://wikipedia.mutschlerhome.com/attachments/221)

```bash
#!/bin/bash

# Grab .iso file
for f in ./*.iso
do
	name=${f%.iso} # Remove '.iso' from file name
	chdman createcd -i "$name.iso" -o "$name.chd" --force
done

```

# Create .CHD From .CUE Files

## Windows

[cue2chd.bat](https://wikipedia.mutschlerhome.com/attachments/218)

```bash
for /r %%i in (*.cue) do chdman createcd -i "%%i" -o "%%~ni.chd" >> log
```

## Linux

[convertFromCueToChd.sh](https://wikipedia.mutschlerhome.com/attachments/222)

```bash
parallel chdman createcd -i {} -o {.}.chd ::: *.cue
```

<p class="callout danger">The below script and the attached version above does not work. Need to test and change accordingly.</p>

```bash
#!/bin/bash

# Grab .cue file
for f in ./**/*.cue
do
	name=${f%.cue} # Remove '.cue' from file name
	chdman createcd -i "$name.cue" -o "$name.chd" --force
done

```

# Create .ISO From .CHD Files

## Windows

[CHD2ISO.bat](https://wikipedia.mutschlerhome.com/attachments/219)

```bash
for %%i in (*.chd) do (
chdman extractcd -i "%%i" -o "%%~ni.cue" -ob "%%~ni.iso"
del "%%~ni.cue"
) >> log
```

## Linux

[convertFromChdToIso.sh](https://wikipedia.mutschlerhome.com/attachments/223)

```
#!/bin/bash

# Grab .chd file
for f in ./**/*.chd
do
	name=${f%.chd} # Remove '.chd' from file name
	chdman extractcd -i "$name.chd" -o "$name.iso" --force
done

```

# Create .CUE From .CHD Files

## Windows

[chd2cue.bat](https://wikipedia.mutschlerhome.com/attachments/220)

```bash
for /r %%i in (*.chd) do chdman extractcd -i "%%i" -o "%%~ni.cue" >> log
```

## Linux

[convertFromChdToCue.sh](https://wikipedia.mutschlerhome.com/attachments/224)

```bash
#!/bin/bash

# Grab .chd file
for f in ./**/*.chd
do
	name=${f%.chd} # Remove '.chd' from file name
	chdman extractcd -i "$name.chd" -o "$name.cue" --force
done

```

# Create .GDI From .CHD Files

## Windows

## Linux

[convertFromChdToGdi.sh](https://wikipedia.mutschlerhome.com/attachments/225)

```bash
#!/bin/bash

# Grab .chd file
for f in ./**/*.chd
do
	name=${f%.chd} # Remove '.chd' from file name
	chdman extractcd -i "$name.chd" -o "$name.gdi" --force
done

```

# Create .CHD From .GDI Files

## Windows

## Linux

[convertFromGdiToChd.sh](https://wikipedia.mutschlerhome.com/attachments/226)

```bash
#!/bin/bash

# Grab .gdi file
for f in ./**/*.gdi
do
	name=${f%.gdi} # Remove '.gdi' from file name
	chdman createcd -i "$name.gdi" -o "$name.chd" --force
done

```

# CHDMan Windows Instructions

## Introduction

<div id="bkmrk-">  
</div>The file formats to adopt for CDs and other optical supports.

We have talked about a format, derived from researches we had on MAME, in order to be able to represent these supports in a compressed way, without losing the integrity of the data and that these can remain scrappable.

This format is the CHD (Compressed Hunks of Data), datas that could be useful for SEGA CD, PS1, PC Engine...

Unfortunately, the classic user will have difficulties to use the converter, which is a command line executable.

So here is a Zip file, with automated scripts, to convert from BIN+CUE (Redump format) to CHD, and vice versa.

It has been added also for the GDI format, which is for the Dreamcast.

For PS1 games protected by LibCrypt, normally you have SBI (Subchannel Information) files, you keep them and put them with the CHDs, otherwise your games will not pass.

If you ever lose them or make a bad manipulation, these files are available on the files of each corresponding disk at Redump, next to the re-downloadable CUE files.

<div id="bkmrk--1">  
</div>## Software

You can download the software by clicking on **CHDMAN.zip** below.

![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/archive.svg) [CHDMAN.zip](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdman.zip)

In this zip you will find 6 files :

<div class="tabset elevation-2" id="bkmrk-file-name-descriptio"><div class="tabset-content"><div class="tabset-panel is-active"><table><thead><tr><th>File name</th><th>Description</th></tr></thead><tbody><tr><td>**chdman.exe**</td><td>CHDMAN software</td></tr><tr><td>**CUE or GDI to CHD.bat** A .bat file that allows you to convert your CUE or GDI roms to CHD.</td><td> </td></tr><tr><td>**Extract CHD to CUE.bat**</td><td>A .bat file that allows you to convert your CHD roms to BIN+CUE.</td></tr><tr><td>**Extract CHD to GDI.bat**</td><td>A .bat file that allows you to convert your CHD rom to GDI.</td></tr><tr><td>**README\_EN.txt**</td><td> </td></tr><tr><td>**README\_EN.txt**</td><td> </td></tr></tbody></table>

</div></div></div>#### Readme file content

<div class="tabset elevation-2" id="bkmrk-cue-or-gdi-to-chd-%C2%A0-"><div class="tabset-content"><div class="tabset-panel is-active">- **CUE or GDI to CHD**
    
    Compresses all types of BIN disk files with a CUE or GDI header to CHD (v5) format.  
    Searches all subfolders and creates CHD (v5) files in the folder where the files are placed with CHDMAN.
- **Extract CHD to CUE** Decompresses a CHD (v5) file to a BIN+CUE file. The CUE format is used by games on CD. On the Raspberry Pi, CHD is supported by TurboGrafx-CD / PC Engine CD, Sega CD / Mega CD and Dreamcast.
- **Extract CHD to GDI**
    
    Unzips a CHD (V5) file to GDI. (GDI is a disk format for Dreamcast).

</div></div></div>## Automated use

#### Convert your game from `BIN`/`CUE` or `GDI` to `CHD`

<div class="tabset elevation-2" id="bkmrk-put-%22chdman.exe%22-and"><div class="tabset-content"><div class="tabset-panel is-active">- Put "**chdman.exe**" and "**CUE or GDI to CHD.bat**" in the folder containing your game as below.  
    Example for the game "Grandia (France)":

</div></div></div>![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdman-win1.png)

<div class="tabset elevation-2" id="bkmrk-click-on-the-file-%22c"><div class="tabset-content"><div class="tabset-panel is-active">- Click on the file "**CUE or GDI to CHD.bat**" to start the conversion.

</div></div></div>![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdman-win2.png)

<div class="tabset elevation-2" id="bkmrk-once-the-cmd-window-"><div class="tabset-content"><div class="tabset-panel is-active">- Once the CMD window above has closed automatically, your conversion is complete.

</div></div></div>![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdman-win3.png)

<div class="tabset elevation-2" id="bkmrk-you-can-delete-%22chdm"><div class="tabset-content"><div class="tabset-panel is-active">- You can delete "**chdman.exe**" and "**CUE or GDI to CHD.bat**", your rom is ready.

</div></div></div>![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdman-win4.png)

<p class="callout info">You can also run the .bat file to start the conversion of several games at once.</p>

#### Convert your game from `CHD` to `BIN`/`CUE`

<div class="tabset elevation-2" id="bkmrk-put-%22chdman.exe%22-and-1"><div class="tabset-content"><div class="tabset-panel is-active">- Put "**chdman.exe**" and "**Extract CHD to CUE.bat**" in the folder containing your game as below.  
    Example for the game "Grandia (France)":
- Click on the file "**Extract CHD to CUE.bat**" to start the conversion.
- Once the CMD window above has closed automatically, your conversion is complete.
- You can delete "**chdman.exe**" and "**Extract CHD to CUE.bat**", your rom is ready.

</div></div></div><p class="callout info">You can also run the .bat file to start the conversion of several games at once.</p>

#### Convert your game from `CHD` to `GDI`

<div class="tabset elevation-2" id="bkmrk-put-%22chdman.exe%22-and-2"><div class="tabset-content"><div class="tabset-panel is-active">- Put "**chdman.exe**" and "**Extract CHD to GDI.bat**" in the folder containing your game as below.  
    Example for the game "Grandia (France)":
- Click on the file "**Extract CHD to GDI.bat**" to start the conversion.
- Once the CMD window above has closed automatically, your conversion is complete.
- You can delete "**chdman.exe**" and "**Extract CHD to GDI.bat**", your rom is ready.

</div></div></div><p class="callout info">You can also run the .bat file to start the conversion of several games at once.</p>

<div id="bkmrk--6">  
</div><div id="bkmrk--7">  
</div><div id="bkmrk--8">  
</div><div id="bkmrk--9">  
</div><div id="bkmrk--10">  
</div><div id="bkmrk--11">  
</div><div id="bkmrk--12">  
</div><div id="bkmrk--13">  
</div><div id="bkmrk--14">  
</div><div id="bkmrk--15">  
</div><div id="bkmrk--16">  
</div><div id="bkmrk--17">  
</div><div id="bkmrk--18">  
</div><div id="bkmrk--19">  
</div><div id="bkmrk--20">  
</div><div id="bkmrk--21">  
</div><div id="bkmrk--22">  
</div><div id="bkmrk--23">  
</div><div id="bkmrk--24">  
</div><div id="bkmrk--25">  
</div><div id="bkmrk--26">  
</div><div id="bkmrk--27">  
</div><div id="bkmrk--28">  
</div><div id="bkmrk--29">  
</div><div id="bkmrk--30">  
</div><div id="bkmrk--31">  
</div><div id="bkmrk--32">  
</div><div id="bkmrk--33">  
</div><div id="bkmrk--34">  
</div><div id="bkmrk--35">  
</div><div id="bkmrk--36">  
</div><div id="bkmrk--37">  
</div><div id="bkmrk--38">  
</div><div id="bkmrk--39">  
</div><div id="bkmrk--40">  
</div><div id="bkmrk--41">  
</div><div id="bkmrk--42">  
</div><div id="bkmrk--43">  
</div><div id="bkmrk--44">  
</div><div id="bkmrk--45">  
</div><div id="bkmrk--46">  
</div><div id="bkmrk--47">  
</div><div id="bkmrk--48">  
</div><div id="bkmrk--49">  
</div><div id="bkmrk--50">  
</div><div id="bkmrk--51">  
</div><div id="bkmrk--52">  
</div><div id="bkmrk--53">  
</div><div id="bkmrk--54">  
</div><div id="bkmrk--55">  
</div><div id="bkmrk--56">  
</div><div id="bkmrk--57">  
</div><div id="bkmrk--58">  
</div><div id="bkmrk--59">  
</div><div id="bkmrk--60">  
</div><div id="bkmrk--61">  
</div><div id="bkmrk--62">  
</div><div id="bkmrk--63">  
</div><div id="bkmrk--64">  
</div><div id="bkmrk--65">  
</div><div id="bkmrk--66">  
</div><div id="bkmrk--67">  
</div><div id="bkmrk--68">  
</div><div id="bkmrk--69">  
</div><div id="bkmrk--70">  
</div><div id="bkmrk--71">  
</div><div id="bkmrk--72">  
</div>## Create the `.M3U` file

<div id="bkmrk--73">  
</div>In CHD conversion for multi-disk games, you have to make a **M3U** file to declare all the disks.

<div id="bkmrk--74">  
</div>The `.M3U` file is a list of the different CDs for a game that allows you to switch from one CD to another in a simple way by using the disc change combination (`Hotkey` + `L. STICK` to the *LEFT* or to the *RIGHT*).

<div id="bkmrk--75">  
</div>Example for the game "Grandia (France)":

<div id="bkmrk--76">  
</div>- Create a `M3U` file via Notepad++ named "Grandia (France).m3u".
- In the file, fill in the `CHD` files of the game:

<div id="bkmrk--77">  
</div>```text
Grandia (France) (Disc 1).chd
Grandia (France) (Disc 2).chd
```

<div class="code-toolbar" id="bkmrk-copy"><div class="toolbar"><div class="toolbar-item"></div></div></div><div id="bkmrk--78">  
</div>- On Windows, you must have the extension view enabled to create this file: 
    - Go to `View` at the top of the Windows Explorer window.
    - Check "File name extensions" at the top right.

<div id="bkmrk--79">  
</div>![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdman-m3u1.png)

<div id="bkmrk--81">  
</div>- Confirm the extension change

<div id="bkmrk--82">  
</div>![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdman-m3u2.png)

# CHDMan Linux Instructions

## Introduction

<div id="bkmrk-">  
</div>The file formats to adopt for CDs and other optical supports.

We have talked about a format, derived from researches we had on MAME, in order to be able to represent these supports in a compressed way, without losing the integrity of the data and that these can remain scrappable.

This format is the CHD (Compressed Hunks of Data), datas that could be useful for SEGA CD, PS1, PC Engine...

Unfortunately, the classic user will have difficulties to use the converter, which is a command line executable.

So here is a Zip file, with automated scripts, to convert from BIN+CUE (Redump format) to CHD, and vice versa.

It has been added also for the GDI format, which is for the Dreamcast.

For PS1 games protected by LibCrypt, normally you have SBI (Subchannel Information) files, you keep them and put them with the CHDs, otherwise your games will not pass.

If you ever lose them or make a bad manipulation, these files are available on the files of each corresponding disk at Redump, next to the re-downloadable CUE files.

<div id="bkmrk--1">  
</div>## Software

<div class="tabset elevation-2" id="bkmrk--2"><div class="tabset-content"><div class="tabset-panel is-active"></div></div></div>Some Linux distributions can give you chdman via `aptitude` with the `mame-tools` package. Some others don't have any `mame-tools` and you need to build it:

<div class="tabset elevation-2" id="bkmrk-go-to%C2%A0https%3A%2F%2Fgithub"><div class="tabset-content"><div class="tabset-panel is-active">- Go to [https://github.com/libretro/mame](https://github.com/libretro/mame)
- Download the content by clicking on the `Code` green button then, in the visible menu, click on `Download ZIP`

</div></div></div>![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/mamedownload.png)

<div class="tabset elevation-2" id="bkmrk-uncompress-the-downl"><div class="tabset-content"><div class="tabset-panel is-active">- Uncompress the downloaded archive and go inside the extracted directory. You should retrieve the same content than into the given link in the first step.
- From your, use this command:

<div class="code-toolbar"></div></div></div></div>```ssh
make tools
```

<div class="tabset elevation-2" id="bkmrk-at-the-end%2C-you-shou"><div class="tabset-content"><div class="tabset-panel is-active"><div class="code-toolbar"></div>- At the end, you should be able to find chdman into the `build` directory.

</div></div></div>Here is a link to download files to automate format conversions:

![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/archive.svg) [ChdScripts.zip](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdscripts.zip)

In this zip you will find 6 files:

<div class="tabset elevation-2" id="bkmrk-file-name-descriptio"><div class="tabset-content"><div class="tabset-panel is-active"><table><thead><tr><th>File name</th><th>Description</th></tr></thead><tbody><tr><td>**ConvertFromChdToCue.sh**</td><td>A .sh file that allows you to convert your `CHD` roms to `BIN`/`CUE` format.</td></tr><tr><td>**convertFromChdToGdi.sh**</td><td>A .sh file that allows you to convert your `CHD` roms to `GDI` format.</td></tr><tr><td>**convertFromChdToIso.sh**</td><td>A .sh file that allows you to convert your `CHD` roms to `ISO` format.</td></tr><tr><td>**convertFromCueToChd.sh**</td><td>A .sh file that allows you to convert your `BIN`/`CUE` roms to `CHD`.</td></tr><tr><td>**convertFromGdiToChd.sh**</td><td>A .sh file that allows you to convert your `GDI` roms to `CUE`.</td></tr><tr><td>**convertFromIsoToChd.sh**</td><td>A .sh file that allows you to convert your `ISO` roms to `CUE`.</td></tr><tr><td>**README\_EN.txt**</td><td> </td></tr><tr><td>**README\_FR.txt**</td><td> </td></tr></tbody></table>

</div></div></div>#### Contents of the readme file

<div class="tabset elevation-2" id="bkmrk-convertfromchdtocue."><div class="tabset-content"><div class="tabset-panel is-active">- **convertFromChdToCue.sh**
    
    Decompresses a CHD (V5) file into a BIN+CUE file.  
    The CUE format is used by games on CD. CHD is supported by 3DO, Amiga CD32, Amiga CDTV, Dreamcast, Mega CD, Neo-Geo CD, PC Engine CD, PlayStation and Saturn.
- **convertFromChdToGdi.sh**  
    Decompresses a CHD (V5) file into a GDI file.  
    The GDI format is used by disk-based games for Dreamcast.
- **convertFromChdToIso.sh**  
    Decompresses a CHD (V5) file into an ISO file.  
    The ISO format is used by disk-based games for PlayStation 2.
- **convertFromCueToChd.sh**
    
    Compresses any type of BIN disk files with a CUE header to the CHD (v5) format. Searches all subfolders and creates CHD (v5) files in the folder where the files are placed with CHDMAN.
- **convertFromGdiToChd.sh**
    
    Compresses any type of BIN disk files with a GDI header to the CHD (v5) format. The GDI format is used by disk-based games for Dreamcast.
- **convertFromIsoToChd.sh**
    
    Compresses any type of BIN disk files with a ISO header to the CHD (v5) format. The ISO format is used by disk-based games for PlayStation 2.

</div></div></div>## Automated use

#### Convert your game from `BIN`/`CUE` to `CHD`

<div class="tabset elevation-2" id="bkmrk-put-%22convertfromcuet"><div class="tabset-content"><div class="tabset-panel is-active">- Put "**convertFromCueToChd.sh**" in the folder containing your game as below.  
    Example for the game "Grandia (France)" :
- In your Terminal, execute the file with the command `./convertCueToChd.sh` to start the conversion.
- Once your Terminal window has finished, your conversion is complete.
- You can delete "**convertFromCueToChd.sh**", your rom is ready.

</div></div></div>#### Convert your game from `GDI` to `CHD`

<div class="tabset elevation-2" id="bkmrk-put-%22convertfromgdit"><div class="tabset-content"><div class="tabset-panel is-active">- Put "**convertFromGdiToChd.sh**" in the folder containing your game as below.  
    Example for the game "Resident Evil - Code - Veronica (France)" :
- In your Terminal, execute the file with the command `./convertFromGdiToChd.sh` to start the conversion.
- Once your Terminal window has finished, your conversion is complete.
- You can delete "**convertFromGdiToChd.sh**", your rom is ready.

</div></div></div>#### Convert your game from `ISO` to `CHD`

<div class="tabset elevation-2" id="bkmrk-put-%22convertfromisot"><div class="tabset-content"><div class="tabset-panel is-active">- Put "**convertFromIsoToChd.sh**" in the folder containing your game as below.  
    Example for the game "Shadow of the Colossus (Europe, Australia) (En,Fr,De,Es,It)" :
- In your Terminal, execute the file with the command `./convertFromIsoToChd.sh` to start the conversion.
- Once your Terminal window has finished, your conversion is complete.
- You can delete "**convertFromIsoToChd.sh**", your rom is ready.

</div></div></div>#### Convert your game from `CHD` to `BIN`/`CUE`

<div class="tabset elevation-2" id="bkmrk-put-%22convertfromchdt"><div class="tabset-content"><div class="tabset-panel is-active">- Put "**convertFromChdToCue.sh**" in the folder containing your game as below.  
    Example for the game "Grandia (France)" :
- In your Terminal, execute the file with the command `./convertFromChdToCue.sh` to start the conversion.
- Once your Terminal window has finished, your conversion is complete.
- You can delete "**convertFromChdToCue.sh**", your rom is ready.

</div></div></div>#### Convert your game from `CHD` to `GDI`

<div class="tabset elevation-2" id="bkmrk-put-%22convertfromchdt-1"><div class="tabset-content"><div class="tabset-panel is-active">- Put "**convertFromChdToGdi.sh**" in the folder containing your game as below.  
    Example for the game "Resident Evil - Code - Veronica (France)" :
- In your Terminal, execute the file with the command `./convertFromChdToGdi.sh` to start the conversion.
- Once your Terminal window has finished, your conversion is complete.
- You can delete "**convertFromChdToGdi.sh**", your rom is ready.

</div></div></div>#### Convert your game from `CHD` to `ISO`

<div class="tabset elevation-2" id="bkmrk-put-%22convertfromchdt-2"><div class="tabset-content"><div class="tabset-panel is-active">- Put "**convertFromChdToIso.sh**" in the folder containing your game as below.  
    Example for the game "Shadow of the Colossus (Europe, Australia) (En,Fr,De,Es,It)" :
- In your Terminal, execute the file with the command `./convertFromChdToIso.sh` to start the conversion.
- Once your Terminal window has finished, your conversion is complete.
- You can delete "**convertFromChdToIso.sh**", your rom is ready.

</div></div></div>## Create the `.M3U` file

<div id="bkmrk--4">  
</div>In CHD conversion for multi-disk games, you have to make a **M3U** file to declare all the disks.

The `.M3U` file is a list of the different CDs for a game that allows you to switch from one CD to another in a simple way by using the disc change combination (`Hotkey` + `L. STICK` to the *LEFT* or to the *RIGHT*).

Example for the game "Grandia (France)":

<div id="bkmrk--5">  
</div>- Create a `M3U` file via Notepad++ named "Grandia (France).m3u".
- In the file, fill in the `CHD` files of the game:

<div id="bkmrk--6">  
</div>```text
Grandia (France) (Disc 1).chd
Grandia (France) (Disc 2).chd
```

<div id="bkmrk--7">  
</div>- On Windows, you must have the extension view enabled to create this file: 
    - Go to `View` at the top of the Windows Explorer window.
    - Check "File name extensions" at the top right.

<div id="bkmrk--8">  
</div>![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdman-m3u1.png)

<div id="bkmrk--10">  
</div>- Confirm the extension change

<div id="bkmrk--11">  
</div>![](https://wiki.recalbox.com/tutorials/utilities/rom-conversion/chdman/chdman-m3u2.png)