You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/decomp-guide/nothing.typ
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ In C++ a function that does nothing could look like this:
19
19
{
20
20
return;
21
21
}
22
-
```
22
+
```,
23
23
)
24
24
25
25
Note that we can choose whether or not to write the `return;` keyword.
@@ -32,16 +32,16 @@ It doesn't make a difference whether we write it out or not.
32
32
so both of these functions
33
33
are compiled down to a single `blr` assembly instruction:
34
34
],
35
-
image("nothing/nothing.png")
35
+
image("nothing/nothing.png"),
36
36
)
37
37
38
38
What does the assembly instruction `blr` mean?
39
39
40
40
#v(0.5cm)
41
-
/ blr: "Branch to Link Register". Jumps to lr. Used to end a subroutine.
41
+
/ blr: "Branch to Link Register". Jumps to lr. Used to end a subroutine.
42
42
#v(0.5cm)
43
43
44
-
What is a Link Register?
44
+
=== What is a Link Register?
45
45
46
46
_A link register (LR for short) is a register which holds the address to return to when a subroutine call completes. This is more efficient than the more traditional scheme of storing return addresses on a call stack, sometimes called a machine stack. The link register does not require the writes and reads of the memory containing the stack which can save a considerable percentage of execution time with repeated calls of small subroutines.
47
47
The IBM POWER architecture, and its PowerPC and Power ISA successors, have a special-purpose link register, into which subroutine call instructions put the return address._
@@ -65,7 +65,7 @@ $0.07%$ of the entire game's code does nothing!
65
65
Since we have a general idea of what an empty function is like,
66
66
let's now decompile an empty function in BFBB.
67
67
68
-
==== Our First Function -- NPCWidget::Reset()
68
+
=== Our First Function -- NPCWidget::Reset()
69
69
We are going to look at the function `NPCWidget::Reset()`.
70
70
It is a size 4 function located in the file
71
71
`/Game/zNPCSupport.cpp`.
@@ -77,7 +77,7 @@ we can see the original assembly on the left, and nothing on the right.
77
77
78
78
We can see that the original assembly on the left just has one instruction,
79
79
a `blr` instruction like we expect.
80
-
When the right side says "Missing", this means that
80
+
When the right side says "Missing", this means that
81
81
we have yet to define the function in our game source file.
82
82
This is to be expected at this point because we haven't decompiled this function yet.
83
83
@@ -150,7 +150,7 @@ After we do this, Objdiff thanks us for our effort by greeting us with a new err
150
150
151
151
Again, the error message is pretty clear.
152
152
We need to define `en_NPC_UI_WIDGETS`.
153
-
Once again, we can't find this enum defined anywhere in
153
+
Once again, we can't find this enum defined anywhere in
154
154
our source header files yet, so it means that it hasn't
155
155
been copied over yet.
156
156
Let's do that now.
@@ -166,7 +166,7 @@ enum en_NPC_UI_WIDGETS {
166
166
```
167
167
168
168
Once again, we want to copy this type over into our `zNPCSupport.h` file.
169
-
We have to make sure that we put this definition before the definition of
169
+
We have to make sure that we put this definition before the definition of
170
170
`NPCWidget`, as that class references the enum.
171
171
172
172
Back in Objdiff, unsurprisingly, we have another error:
@@ -242,11 +242,11 @@ so solving the type errors would be as simple as including the appropriate heade
242
242
#include "xVec3.h"
243
243
#include "zFX.h"
244
244
```
245
-
If we didn't already have those types defined in those header files,
246
-
you would have to copy the types for these parameters from
247
-
the PS2 DWARF again.
248
-
This is needed to get the file to compile
249
-
despite the fact that the function itself does nothing.
245
+
If we didn't already have those types defined in those header files,
246
+
you would have to copy the types for these parameters from
247
+
the PS2 DWARF again.
248
+
This is needed to get the file to compile
249
+
despite the fact that the function itself does nothing.
250
250
251
251
Then of course there are functions like `NPCWidget_Shutdown`
252
252
which are not part of a class nor accept any parameters,
@@ -293,4 +293,4 @@ Whew. This was a longer chapter than anticipated,
293
293
but we have learned quite a lot.
294
294
Whenever you're ready let's head on to the next example
0 commit comments