GB Programming: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
>ISSOtm m (→A stack? Can you eat that?: Changed the first three words. Pointless but more consistent with the title, I guess.) |
>Raltseye (Removed unnecessary space) |
||
Line 4: | Line 4: | ||
Let's get started! |
Let's get started! |
||
==A new world== |
==A new world== |
||
Line 50: | Line 49: | ||
* A group of 64 bits is called a '''quadruple word''' or '''qword'''. |
* A group of 64 bits is called a '''quadruple word''' or '''qword'''. |
||
We will mostly be working with bytes, sometimes with words and rarely with nibbles. It is wery rare to work with other structures, so you may forget them if you will. |
We will mostly be working with bytes, sometimes with words and rarely with nibbles. It is wery rare to work with other structures, so you may forget them if you will. |
||
Now, let's talk about '''hexadecimal'''. It is '''base 16''', so we will be working with 16 symbols : 0 1 2 3 4 5 6 7 8 9 A B C D E F. Again, we will prepend hex numbers with a $ to differentiate them. |
Now, let's talk about '''hexadecimal'''. It is '''base 16''', so we will be working with 16 symbols : 0 1 2 3 4 5 6 7 8 9 A B C D E F. Again, we will prepend hex numbers with a $ to differentiate them. |
||
Line 71: | Line 69: | ||
For the rest of this tutorial, we will mostly be using hexadecimal, but always remember the binary lying down below! |
For the rest of this tutorial, we will mostly be using hexadecimal, but always remember the binary lying down below! |
||
==A dip into technical information== |
==A dip into technical information== |
||
Line 411: | Line 407: | ||
Notice that F and AF aren't usable anywhere. Actually, only a few instructions use them. |
Notice that F and AF aren't usable anywhere. Actually, only a few instructions use them. |
||
===Negative numbers=== |
===Negative numbers=== |
||
Line 462: | Line 457: | ||
For those wondering, ''ld a, ($6511)'' leaves ($6511) untouched. |
For those wondering, ''ld a, ($6511)'' leaves ($6511) untouched. |
||
==Flags== |
==Flags== |
||
Line 500: | Line 494: | ||
* SCF sets it, and |
* SCF sets it, and |
||
* CCF inverts it. |
* CCF inverts it. |
||
==Manipulating data== |
==Manipulating data== |
||
Line 579: | Line 571: | ||
|} |
|} |
||
These are often used to operate on cHunks of memory. |
These are often used to operate on cHunks of memory. |
||
===Overflow=== |
===Overflow=== |
||
Line 590: | Line 581: | ||
Thus, the result is A equals 66 = %01000010, and the C flag is set. |
Thus, the result is A equals 66 = %01000010, and the C flag is set. |
||
===Register pairs and RAM=== |
===Register pairs and RAM=== |
||
Line 688: | Line 678: | ||
ld ($C000), hl ; Save stack pointer |
ld ($C000), hl ; Save stack pointer |
||
</pre> |
</pre> |
||
===Good news=== |
===Good news=== |
||
Line 742: | Line 731: | ||
Beware with the stack, even more when you're not coding your own game : everyone uses the stack ; even the CPU! (We're about to see how) The best practice to have is to leave the stack identical before and after your code. Otherwise, expect some crashes, yay! |
Beware with the stack, even more when you're not coding your own game : everyone uses the stack ; even the CPU! (We're about to see how) The best practice to have is to leave the stack identical before and after your code. Otherwise, expect some crashes, yay! |
||
==Control structures== |
==Control structures== |
||
Line 767: | Line 755: | ||
And this brings us to the next part! |
And this brings us to the next part! |
||
===Conditionals=== |
===Conditionals=== |
||
Line 790: | Line 777: | ||
|} |
|} |
||
Four instructions can use conditionals : CALL, RET (these are coming in soon), JP and JR. JR has a handicap, though : it can only use the Z, NZ, C and NC conditions. |
Four instructions can use conditionals : CALL, RET (these are coming in soon), JP and JR. JR has a handicap, though : it can only use the Z, NZ, C and NC conditions. |
||
==Solutions to the exercises== |
==Solutions to the exercises== |
||
Line 835: | Line 820: | ||
</pre> |
</pre> |
||
|} |
|} |
||
===Register pair and RAM=== |
===Register pair and RAM=== |
||
Line 888: | Line 872: | ||
|$00||$03||$4F||$06||$DF||$DE||$2A||$00||$FF||$01||$23||$34||$0E||$C0||$28||$BC |
|$00||$03||$4F||$06||$DF||$DE||$2A||$00||$FF||$01||$23||$34||$0E||$C0||$28||$BC |
||
|} |
|} |
||
==Credits== |
==Credits== |