1---
2title: Integration with compilers
3weight: 40
4pre: ""
5chapter: false
6---
7
8When building homebrew software in assembly or C, it is possible to export the labels used in your code and import them into Mesen to simplify the debugging process.  This allows the debugger to know which portions of the ROM correspond to which functions in your code, as well as display your code's comments inside the debugger itself.
9
10## Integration with compilers ##
11
12### CC65 / CA65 ###
13
14CC65/CA65 are able to produce .DBG files which can be imported into Mesen's debugger.
15To make CC65/CA65 create a .DBG file during the compilation, use the `--dbgfile` command line option.
16
17To import the .DBG file, use the **<kbd>File&rarr;Workspace&rarr;Import Labels</kbd>** command in the debugger window.
18
19You can also enable the `Auto-load DBG/MLB files` to make Mesen load any .DBG file it finds next to the ROM whenever the debugger is opened or the power cycle button is used.
20**Note:** For this option to work, the ROM file must have the same name as the DBG file (e.g `MyRom.nes` and `MyRom.dbg`) and be inside the same folder.
21
22#### Source View ####
23
24<div class="imgBox"><div>
25	<img src="/images/SourceView.png" />
26	<span>Source View</span>
27</div></div>
28
29When a .DBG file is loaded, 2 additional options appear in the code window's right-click menu:
30
31* **Switch to Source View**: This turns on `Source View` mode, which allows you to debug the game using the original code files, rather than the disassembly.  This can be used for both assembly and C projects.
32* **Show source code as comments**: When enabled, the debugger will show the original source code to the right of the disassembly, as comments.
33
34
35### ASM6f ###
36
37Integration with ASM6 is possible by using freem's branch of ASM6 named [ASM6f](https://github.com/freem/asm6f).
38This fork contains 2 additional command line options that are useful when using Mesen: `-m` and `-c`
39
40`-m` produces a .mlb (Mesen labels) file that can be imported manually using the **<kbd>File&rarr;Workspace&rarr;Import Labels</kbd>** command.
41`-c` produces a .cdl (Code Data Logger) file which can be imported manually using the **<kbd>Tools&rarr;Code/Data Logger&rarr;Load CDL file</kbd>** command.
42
43Additionally, you can use the `Auto-load DBG/MLB files` and `Auto-load CDL files` options in the **<kbd>File&rarr;Workspace</kbd>** menu to automatically load MLB and CDL files present in the same folder as the current ROM, with the same filename (e.g `MyRom.nes`, `MyRom.mlb`, `MyRom.cdl`).
44
45
46### NESASM ###
47
48Mesen can also import the `.fns` symbol files that NESASM produces. However, due to limitations in the `.fns` format, these labels can only be reliably imported for games containing exactly 32kB of PRG ROM.  If you are creating a larger game, CC65/CA65 offers the best integration features at the moment.
49
50## Importing and exporting labels ##
51
52<div class="imgBox"><div>
53	<img src="/images/WorkspaceMenu.png" />
54	<span>Workspace Menu</span>
55</div></div>
56
57Mesen can also import and export labels in `.mlb` format. This is the same format as the label files produced by ASM6f. The ability to import labels can be used to integrate the debugger with your own workflow (e.g by creating your own scripts that produce `.mlb` files)
58
59<div style="clear:both"></div>
60
61### Mesen Label Files (.mlb) ###
62
63The `.mlb` files used by Mesen to import/export labels is a simple text format.  For example, this defines a label and comment on byte $100 of PRG ROM:
64```
65P:100:MyLabel:This is a comment
66```
67The format also supports multi-byte labels, defined by giving specifying an address range:
68```
69R:200-2FF:ShadowOam
70```
71
72The first letter on each row is used to specify the label's type:
73```
74P: PRG ROM labels
75R: RAM labels (for the NES' internal 2kb RAM)
76S: Save RAM labels
77W: Work RAM labels
78G: Register labels (these are used to define PPU/APU/Mapper registers, etc.)
79```
80
81### Import Settings ###
82
83<div class="imgBox"><div>
84	<img src="/images/ImportSettings.png" />
85	<span>Import Settings</span>
86</div></div>
87
88For fine-grain control over the DBG/MLB file imports, the `Import Settings` window can be used.
89This allows you to configure which types of labels/comments should be imported, as well as choosing whether or not Mesen should delete all existing labels before importing DBG/MLB files.