Skip to content

Commit 613f7d7

Browse files
committed
Add code organization text to Title-Screen section
1 parent eceb751 commit 613f7d7

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/part2/title-screen.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,14 @@ Then copy and paste the following after waiting for VBlank:
1616
Note that we are using our `Memcopy` function from the [Functions](./functions.md) lesson! Isn't it handy to have reusable code? We are also using our `UpdateKeys` function from the [Input](./input.md) lesson to determine when to stop displaying the title screen and move on to the game itself. To do so, we loop until the start button has been pressed.
1717

1818
And just like that we have ourselves a title screen!
19+
20+
## Organizing Our Code
21+
Our project is getting quite large with all the functionality we're building in! Let's briefly go over how to better organize things. Until now, we have always added new code into the same assembly file (`main.asm`). This file can get pretty large if we're not careful. Instead, RGBDS has a handy feature for making [functions](./functions.md) or other labels visible to external files. As an example, let's take everything we added in our [input](./input.md) lesson, and put it in a separate file named [`input.asm`](https://github.com/gbdev/gb-asm-tutorial/raw/master/unbricked/title-screen/input.asm).
22+
23+
Notice the use of the double colon (`::`) after the function and variable names. This is how we can export a label to other files, also known as broadening its [scope](https://en.wikipedia.org/wiki/Scope_%28computer_programming%29). Now that we have all of the input-related code in a separate file, and everything else in main, all that is left is to build the ROM. Now that we have multiple files, we have to assemble each assembly file, then link them together in one ROM, like so:
24+
25+
```console,linenos,start={{#line_no_of "" ../../unbricked/title-screen/build.sh:multibuild}}
26+
{{#include ../../unbricked/title-screen/build.sh:multibuild}}
27+
```
28+
29+
Try doing the same with other assembly files to keep your code nice and tidy. Break up separate functionality into other files, don't forget to assemble them separately, then link them all together!

unbricked/title-screen/build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

3+
# ANCHOR: multibuild
34
rgbasm -o main.o main.asm
45
rgbasm -o input.o input.asm
56
rgblink -o unbricked.gb main.o input.o
67
rgbfix -v -p 0xFF unbricked.gb
8+
# ANCHOR_END: multibuild

0 commit comments

Comments
 (0)