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!

Draconius GO
Reply
 
Thread Tools
  #1    
Old May 28th, 2010 (4:16 PM). Edited May 28th, 2010 by Coolboyman.
Coolboyman's Avatar
Coolboyman Coolboyman is offline
Veteran Hacker
     
    Join Date: Sep 2003
    Location: The East Bay
    Age: 29
    Gender: Male
    Nature: Bold
    Posts: 471
    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/10807fvllz/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.
    Reply With Quote

    Relevant Advertising!

      #2    
    Old May 29th, 2010 (10:01 AM).
    Sawakita's Avatar
    Sawakita Sawakita is offline
    Not Invented Here
       
      Join Date: May 2010
      Gender: Male
      Posts: 180
      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 (4:30 PM).
      Coolboyman's Avatar
      Coolboyman Coolboyman is offline
      Veteran Hacker
         
        Join Date: Sep 2003
        Location: The East Bay
        Age: 29
        Gender: Male
        Nature: Bold
        Posts: 471
        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.
        Reply With Quote
          #4    
        Old June 1st, 2010 (8:35 AM).
        Sawakita's Avatar
        Sawakita Sawakita is offline
        Not Invented Here
           
          Join Date: May 2010
          Gender: Male
          Posts: 180
          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 puppyboy is offline
             
            Join Date: Mar 2010
            Location: England
            Gender: Male
            Nature: Quirky
            Posts: 24
            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 (2:01 AM).
            Sawakita's Avatar
            Sawakita Sawakita is offline
            Not Invented Here
               
              Join Date: May 2010
              Gender: Male
              Posts: 180
              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 (5:05 AM).
              puppyboy's Avatar
              puppyboy puppyboy is offline
                 
                Join Date: Mar 2010
                Location: England
                Gender: Male
                Nature: Quirky
                Posts: 24
                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). Edited June 21st, 2010 by Sawakita.
                Sawakita's Avatar
                Sawakita Sawakita is offline
                Not Invented Here
                   
                  Join Date: May 2010
                  Gender: Male
                  Posts: 180
                  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 |
                  Reply With Quote
                    #9    
                  Old August 9th, 2010 (1:53 AM).
                  lethjakman lethjakman is offline
                     
                    Join Date: May 2010
                    Gender: Male
                    Posts: 1
                    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 (3:58 AM).
                    miksy91's Avatar
                    miksy91 miksy91 is offline
                    Dark Energy is back in action! ;)
                       
                      Join Date: Oct 2008
                      Location: A small country in the North
                      Gender: Male
                      Nature: Relaxed
                      Posts: 1,438
                      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



                      Fixing bugs in a ROM hack
                      CP of encountered pokemon in GO

                      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

                      Join the conversation!

                      Create an account to post a reply in this thread, participate in other discussions, and more!

                      Create a PokéCommunity Account

                      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

                      Forum Jump


                      All times are GMT -8. The time now is 8:30 AM.