Skip to content
This repository was archived by the owner on Dec 21, 2025. It is now read-only.

Commit 8ba7307

Browse files
committed
Document debugfile integration
Not how to use debugfiles themselves, that's the scope of another project.
1 parent 00f203d commit 8ba7307

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

Makefile.nw

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ The \texttt{\$\{@:.mk=.o\}} syntax means “expand to the contents of \texttt{\$
314314
We also need to inform Make of the dependency files that it should read; but, we don't do so when running \texttt{make clean}, as we don't need dependency info when we're trying to wipe the slate clean!
315315
<<Assembly rules>>=
316316
ifeq ($(filter clean,${MAKECMDGOALS}),)
317-
include $(patsubst src/%.asm,obj/%.mk,${SRCS})
317+
include ${DEPFILES}
318318
endif
319319
@
320320
Interestingly, Make also treats every such file as a target that needs to be made, and so it will automatically try to generate them if they don't exist yet.
@@ -338,6 +338,40 @@ ${ROM}: $(patsubst src/%.asm,obj/%.o,${SRCS})
338338
&& ${RGBFIX} -v ${FIXFLAGS} $@
339339
@
340340

341+
\pagebreak
342+
343+
\subsubsection{Debugfiles}
344+
345+
Debugfiles are a recent addition to the Game Boy debugging experience.
346+
They allow instructing the emulator to perform a lot of debug checks, without having to modify the ROM at all!
347+
A more complete guide to debugfile macros \href{https://github.com/ISSOtm/debugfile.inc/wiki}{can be found on \texttt{debugfile.inc}'s wiki}; but for now, let's focus on how they are hooked up to the build system.
348+
349+
You see, they are implemented in a way you might find a bit strange.
350+
Unless the symbol \texttt{PRINT\_DEBUGFILE} is defined, the macros from \texttt{debugfile.inc} do \emph{nothing}.
351+
But if that symbol is defined, they \emph{print} their corresponding debugfile directives.
352+
That's because this is the only way RGBASM provides of generating such a file; better debugfile integration is planned, but not here yet.
353+
354+
So, first, a debugfile can be generated by assembling the corresponding source file while defining the aforementioned symbol.
355+
That said, we make the rule depend on the \emph{object file}, so that it's only executed after the whole dependency resolution process.
356+
357+
<<Assembly rules>>=
358+
obj/%.dbg: obj/%.o
359+
${RGBASM} ${ASFLAGS} src/$*.asm -DPRINT_DEBUGFILE
360+
@
361+
362+
This generates one debugfile per source file, but by default, an emulator will only auto-load a single debugfile (and if it has the appropriate name, hence the use of \texttt{ROMNAME} here).
363+
Thus, we also generate a “master file”, which includes all of the sub-files.
364+
365+
<<Assembly rules>>=
366+
bin/${ROMNAME}.dbg: ${SRCS}
367+
echo @debugfile 1.0 >$@
368+
printf '@include "../%s"\n' ${DEBUGFILES} >>$@
369+
@
370+
371+
Since the debugfile is made to depend on each source file, creating a new source file re-generates the list of debugfiles.
372+
However, note that \emph{deleting} a source file will not invalidate the list; this is a limitation that I do not know how to solve with Make.
373+
Please feel free to send a pull request or to contact me if you know how to solve this.
374+
341375
\subsubsection{Submodules}
342376

343377
A Git “submodule” is, largely, a Git repository inside of a Git repository; this has the benefit of making it easier to update the submodules, but the downside of being a little quirky.
@@ -347,6 +381,8 @@ By default, cloning the repo does not initialise submodules (so they are empty);
347381
Note that the real paths aren't used!
348382
Since RGBASM fails to find the files, it outputs the path(s) as passed to \texttt{include}, not where the file would actually be found (e.g. \texttt{src/hardware.inc/hardware.inc}).
349383

384+
\pagebreak % Otherwise the "header line" is on a different page than the code >_<
385+
350386
<<Assembly rules>>=
351387
hardware.inc/hardware.inc rgbds-structs/structs.asm:
352388
@echo '$@ is not present; have you initialized submodules?'
@@ -372,7 +408,7 @@ Since this is a commonly desirable feature, these names are common conventions.
372408
It is also a little special, as it is the \emph{first} rule in the file (as we will see in \autoref{sec:overall}), it is also the “default” target, i.e. what Make selects as its target if invoked without one (just \texttt{make}).
373409

374410
<<Phony rules>>=
375-
all: ${ROM}
411+
all: ${ROM} ${DEBUGFILES} bin/${ROMNAME}.dbg
376412
.PHONY: all
377413

378414
@
@@ -383,8 +419,6 @@ all: ${ROM}
383419

384420
(As we have seen in \autoref{sec:auto-discovery}, we also made it a little special, its presence suppressing dependency auto-discovery.)
385421

386-
\pagebreak
387-
388422
<<Phony rules>>=
389423
clean:
390424
rm -rf bin obj assets
@@ -413,7 +447,7 @@ This allows the following to work:
413447
\begin{pygmented}[lang=console]
414448
$ ls ~/rgbds-0.9.1
415449
rgbasm rgbfix rgbgfx rgblink
416-
$ export RGBDS=~/rgbds-0.9.1
450+
$ export RGBDS=~/rgbds-0.9.1/
417451
$ make
418452
~/rgbds-0.9.1/rgbasm -p 0xFF (etc.)
419453
\end{pygmented}
@@ -433,7 +467,14 @@ And some file names:
433467
<<Configuration>>=
434468
ROM = bin/${ROMNAME}.${ROMEXT}
435469
SRCS := $(call rwildcard,src,*.asm)
470+
@
436471

472+
Then some lists of files that will be generated from that list of sources, for convenience:
473+
474+
<<Configuration>>=
475+
OBJS := $(patsubst src/%.asm,obj/%.o,${SRCS})
476+
DEPFILES := ${OBJS:.o=.mk}
477+
DEBUGFILES := ${OBJS:.o=.dbg}
437478
@
438479

439480
And, last but not least, including the file containing project-specific configuration.

0 commit comments

Comments
 (0)