The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Creative Discussions > Emulation & ROM Hacking > Research & Development
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Research & Development Got a well-founded knack with ROM hacking? Love reverse-engineering the Pokémon games? Or perhaps you love your assembly language. This is the spot for polling and gathering your ideas, and then implementing them! Share your hypothesis, get ideas from others, and collaborate to create!
New threads in this forum are to be approved by a moderator before they are displayed. The thread revival limit does not apply here.


Reply
 
Thread Tools
  #1    
Old May 28th, 2010, 04:16 PM
Coolboyman's Avatar
Coolboyman
Veteran Hacker
 
Join Date: Sep 2003
Location: The East Bay
Age: 26
Gender: Male
Nature: Bold
Needed:
Intermediate knowledge of Gameboy ROMS.
A good debugger (No$gmb works good)

Chapter 1: The RAM of the Gameboy ROM
Gameboy's RAM is 65536 (FFFF) bytes in size.

0000-3FFF - ROM - Bank 0
4000-7FFF - ROM - Switchable Bank
8000-97FF - Tile Graphics
9800-9B5F - BG Map 1
9C00-9F5F - BG Map 2
A000-BFFF - .Sav File
C000-DF00 - Internal RAM
DF01-DFFF - Reserved for the Stack
E000-FDFF - Echo RAM
FE00-FE9F - OAM Data
FEA0-FEFF - Garbage
FF00-FF7F - Hardware I/O Registers
FF80-FFFF - Empty

ROM - Bank 0: Contains bytes 0-3FFF from the ROM
ROM - Bank 1: Contains bytes from a bank. Can be switched to any other bank.
Tile Graphcs: Basically, the graphics.
BG Maps: How the tiles are arranged on screen
.Sav File: Holds the contents of the SAV file in this area.
Internal RAM: Holds the RAM for just about everything else.
Stack: Stack begins at DFFF, and goes down everytime something is pushed. Goes up everytime something is popped. (Will get into these later)
Echo RAM: A copy of the Internal RAM.
OAM Data: Holds the data for the Sprites displayed on screen.
Garbage: Just various unusable bytes, don't do anything here.
Hardware I/O Registers: Has all the control registers. (Will get into these later)

More information regarding the Gameboy Hardware: http://www.romhacking.net/docs/gbchardware.html

Chapter 2: Z80's command set.

Command set based on hex value: http://www.zophar.net/fileuploads/2/...vllz/z80-1.txt For example, (ADD a,c)'s hexadecimal identifier is 81.

Registers:
a, b, c, d, e, h, l - registers to store bytes in for temporary use.
n - Digit used with the command.
z - Will only execute command if the last modified register is false.
nz - Will only execute command if the last modified register is true.
(bc), (de), (hl) - when in (), these are treated as pointers rather than variables. EXAMPLE: if de is C000, and it uses ld (de), a, it will write a to the RAM instead of the actual d or e registers.

Commands:
NOP - No action is performed. It's recommended to get rid of these if writing code, because even though nothing happens, it still treats it as a command, thus slowing down your function.
LD, loads a variable into a register. (ld a,b) this takes whatever it in b and copies it into a.
INC - Increases register(s) by 1
DEC - Decreases register(s) by 1
JR - Jumps ahead a certain amount of bytes right after the command.
JP - Jumps to another function.
CALL: Similar to JP, except once the called function is complete it continues afterwards.
ADD - Adds two numbers.
SUB - Subtracts two numbers.
AND: Turns off all bits in A except for B.
OR: Merges the bits between A and B
XOR: Turns off all the bits that A and B share. Then merges the rest.
PUSH: Pushes a pair of registers onto the stack.
POP: Takes two bytes from the stack, puts them into the registers, then clears them off the stack.

AND Example:
A = 6, B = 2
A and B = 2 (Because bit 01 is on)
A = 30, B = 10
A and B = 10 (Because bit 04 is on)
A = 22, B = 60
A and B = 20 (Because bit 05 is on, but bit 06 is not)

OR Example:
A = 6, B = 2
A or B = 6
A = 24, B = 3B
A or B = 3F

XOR Example:
A = 6, B = 2
A xor B = 4
A = FF, B = 1F
A xor B = E0

Next chapter: Using Z80's command set.
__________________
Check out my Youtube channel. All about ROM Hacks, Indie Games and more!

Brown:


Prism : - Four Gym Summer 2010 Beta available now!

Twitter

Last edited by Coolboyman; May 28th, 2010 at 04:25 PM.
Reply With Quote
  #2    
Old May 29th, 2010, 10:01 AM
Sawakita's Avatar
Sawakita
Not Invented Here
 
Join Date: May 2010
Gender: Male
That's exactly what i'm studying now, z80 CPU. I hope that later you're going to teach us LZ77 and that kind of stuff. thank you CBM!!
__________________



| 1st Gen Hacking: Useful Links | A good example of REAL ROM Hacking |
Reply With Quote
  #3    
Old May 29th, 2010, 04:30 PM
Coolboyman's Avatar
Coolboyman
Veteran Hacker
 
Join Date: Sep 2003
Location: The East Bay
Age: 26
Gender: Male
Nature: Bold
Chapter 3: Basic Use of Z80's Command set.

Write a byte to RAM:
ld a,n $01: 3E 01
ld de,nn $D000: 11 00 D0
ld (de),a: 12

Move a byte to another location in the RAM:
ld de,nn $D000: 11 00 D0
ld hl,nn $D001: 21 01 D0
ld a,(de): $1A
ld (hl),a: $77

Add a byte in the RAM:
ld de,nn $D000: 11 00 D0
ld c,$20: 0E 20
ld a,(de): 1A
ADD a,c: 81
ld (de),a: 12

Checks byte in RAM. If true, branch off to a new location.
ld de,nn $D000: 11 00 D0
ld a,(de): 1A
jp nz,nn: C2 00 50
function 1

Location $5000:
function 2

Writes bytes $00-7F to $D000-$D080 using a loop
ld de,nn $D000: 11 00 D0
ld a,$00: 3E 00
ld c,$80: 0E 80
ld (de),a: 12
inc a: 3C
inc de: 13
dec c: 0D
jp nz,nn: C2 00 50 (to fourth line of this function)
ret

Next chapter: Putting your functions in the game.
__________________
Check out my Youtube channel. All about ROM Hacks, Indie Games and more!

Brown:


Prism : - Four Gym Summer 2010 Beta available now!

Twitter
Reply With Quote
  #4    
Old June 1st, 2010, 08:35 AM
Sawakita's Avatar
Sawakita
Not Invented Here
 
Join Date: May 2010
Gender: Male
I can't wait to learn more about z80!! I think it's a Must, for everyone who's interested in rom hacking, to learn gbASM. Also for those for whom there seems to be only the gba and ds....
In my opinion (and not only mine, I guess!) it's the foundation of everything that follows.
__________________



| 1st Gen Hacking: Useful Links | A good example of REAL ROM Hacking |
Reply With Quote
  #5    
Old June 14th, 2010, 12:31 AM
puppyboy's Avatar
puppyboy
Beginning Trainer
 
Join Date: Mar 2010
Location: England
Gender: Male
Nature: Quirky
Might be important to note that the GB doesn't actually use a Z80. It's similar to a Z80 but some of the features of the Z80 are missing and other features are present. It's important to take this into account when writing and compiling your code.
__________________

Site
Reply With Quote
  #6    
Old June 14th, 2010, 02:01 AM
Sawakita's Avatar
Sawakita
Not Invented Here
 
Join Date: May 2010
Gender: Male
Quote:
Originally Posted by puppyboy View Post
Might be important to note that the GB doesn't actually use a Z80. It's similar to a Z80 but some of the features of the Z80 are missing and other features are present. It's important to take this into account when writing and compiling your code.
Yes but it's just few added or removed commands, and IY&IX registers have been removed.

(I found a document about this, but I can't find it right now. When I eventually find it I'm going to post it)
__________________



| 1st Gen Hacking: Useful Links | A good example of REAL ROM Hacking |
Reply With Quote
  #7    
Old June 18th, 2010, 05:05 AM
puppyboy's Avatar
puppyboy
Beginning Trainer
 
Join Date: Mar 2010
Location: England
Gender: Male
Nature: Quirky
I've seen it described as between a Z80 and an Intel 8080.
__________________

Site
Reply With Quote
  #8    
Old June 21st, 2010, 10:11 AM
Sawakita's Avatar
Sawakita
Not Invented Here
 
Join Date: May 2010
Gender: Male
Quote:
Originally Posted by Sawakita View Post
Yes but it's just few added or removed commands, and IY&IX registers have been removed.

(I found a document about this, but I can't find it right now. When I eventually find it I'm going to post it)
Here are the differences:


The following are added instructions:
ADD SP,nn ;nn = signed byte
LDI (HL),A ;Write A to (HL) and increment HL
LDD (HL),A ;Write A to (HL) and decrement HL
LDI A,(HL) ;Write (HL) to A and increment HL
LDD A,(HL) ;Write (HL) to A and decrement HL
LD A,($FF00+nn)
LD A,($FF00+C)
LD ($FF00+nn),A
LD ($FF00+C),A
LD (nnnn),SP
LD HL,SP+nn ;nn = signed byte
STOP ;Stop processor & screen until
button press
SWAP r ;Swap high & low nibbles of r

The following instructions have been removed:
Any command that uses the IX or IY registers.
All IN/OUT instructions.
All exchange instructions.
All commands prefixed by ED (except remapped RETI).
All conditional jumps/calls/rets on parity/overflow
and sign flag.

The following instructions have different opcodes:
LD A,[nnnn]
LD [nnnn],A
RETI
---------------------
credits go to:
Pan of Anthrox, GABY, Marat Fayzullin,
Pascal Felber, Paul Robson, Martin Korth, kOOPa, Bowser
(authors of "Game BoyTM CPU Manual")
__________________



| 1st Gen Hacking: Useful Links | A good example of REAL ROM Hacking |

Last edited by Sawakita; June 21st, 2010 at 10:13 AM. Reason: Credits
Reply With Quote
  #9    
Old August 9th, 2010, 01:53 AM
lethjakman
Beginning Trainer
 
Join Date: May 2010
Gender: Male
I just found this, it seemed extremely useful to me. Like the reference sheet for the Z80 but it's specifically for the LR35902 in the gameboy.

world wide web pastraiser com /cpu/gameboy/gameboy_opcodes.html

I apologize, I haven't made enough posts on this site to post a real link, I think you know what to do!
Reply With Quote
  #10    
Old February 13th, 2011, 03:58 AM
miksy91's Avatar
miksy91
A GB/C Rom Hacker since 2010
 
Join Date: Oct 2008
Location: A small country in the North
Gender: Male
Nature: Relaxed
Heh, I've been trying to avoing Z80 and that kind of stuff before because they felt too much for me to handle but this isn't actually so bad after all :D

Btw, a very tutorial KBM, as always.
__________________
My Rom Hack



Hacks I support





Learn how to hack GB/C games:

Check my GameBoy/Color hacking videos in Youtube
-The video set uses Pokemon Silver (U) rom for demonstrations
Reply With Quote
Reply
Quick Reply

Sponsored Links


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 05:26 PM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.