Jump to content

GB Programming: Difference between revisions

Removed unnecessary space
>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:
 
Let's get started!
 
 
==A new world==
Line 50 ⟶ 49:
* 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.
 
 
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 ⟶ 69:
 
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==
Line 411 ⟶ 407:
 
Notice that F and AF aren't usable anywhere. Actually, only a few instructions use them.
 
 
===Negative numbers===
Line 462 ⟶ 457:
 
For those wondering, ''ld a, ($6511)'' leaves ($6511) untouched.
 
 
==Flags==
Line 500 ⟶ 494:
* SCF sets it, and
* CCF inverts it.
 
 
 
==Manipulating data==
Line 579 ⟶ 571:
|}
These are often used to operate on cHunks of memory.
 
 
===Overflow===
Line 590 ⟶ 581:
 
Thus, the result is A equals 66 = %01000010, and the C flag is set.
 
 
===Register pairs and RAM===
Line 688 ⟶ 678:
ld ($C000), hl ; Save stack pointer
</pre>
 
 
===Good news===
Line 742 ⟶ 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!
 
 
==Control structures==
Line 767 ⟶ 755:
 
And this brings us to the next part!
 
 
===Conditionals===
Line 790 ⟶ 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.
 
 
 
==Solutions to the exercises==
Line 835 ⟶ 820:
</pre>
|}
 
 
===Register pair and RAM===
Line 888 ⟶ 872:
|$00||$03||$4F||$06||$DF||$DE||$2A||$00||$FF||$01||$23||$34||$0E||$C0||$28||$BC
|}
 
 
 
==Credits==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.