Main Menu
Main Page
Forums
Recent changes
Random page
Help

Databases
GlitchDex
AttackDex
ItemDex
TypeDex
UnownDex
More

Major Glitches
Trainer escape glitch
Old man trick
Celebi trick
Select glitches (Japan)
SRAM glitch
CoolTrainer♀ corruption
LOL glitch
Rival LOL glitch
Super Glitch
ZZAZZ glitch
Pomeg corruption glitch (Glitzer Popping)
Tweaking
Elite Four door glitch (Japan)
Pokémon merge glitch
Pokémon cloning
Time Capsule exploit
Arbitrary code execution
Coin Case glitch
More

Other Glitch Categories
Glitches by generation
Glitches between two generations
Japan-only/language specific glitches
Music glitches
Natural glitches
Non-core series glitches
Non-Pokémon glitches
Officially acknowledged glitches
Recurring glitches
Dead glitches

References
Pokémon GameShark codes
The Big HEX List
GB programming
Curiosities
Debugging features
Easter eggs
Error traps
Glitch areas
Glitch myths
Non-glitch exploits
Placeholder texts
Pokémon glitch terminology
Unused content and prerelease information

Useful Tools
8F Helper
GBz80 to Items
Old man trick name generator
PATH (Prama's Advanced Tweaking Heaven)
Save file editors
Special stat/Pokémon converter
Trainer escape Trainer Pokémon finder

Affiliates
Legendary Star Blob 2 (Hakuda)
Pokémon Speedruns wiki
PRAMA Initiative
Become an affiliate!

Search Wiki

 

Search Forums

 

Author Topic: Required register values after 8F execution?  (Read 295 times)

0 Members and 1 Guest are viewing this topic.

undergroundmonorail

  • GCLF Member
  • Offline Offline
  • CHARIZRAD 'M ROXORX or is it.
    • View Profile
Required register values after 8F execution?
« on: December 31, 2016, 05:51:18 pm »
I'm just starting to get into pokemon glitch stuff and I've found a lot of useful information here, and this seems like a silly question but I haven't been able to find the answer anywhere. I guess I could test it out myself but it would be faster to ask here and it means the answer is available for other people to see :​)

I know what the Game Boy's registers hold when 8F execution begins:

Code: [Select]
af = 6300
bc = 22B8
de = 0001
hl = D322

I also know that the HL registers don't have to be set back to D322 when your code finishes executing. Is this true for all the registers, or do some of them have to have the same value as when 8F execution begins?

For example, I recently wrote this 8F script to copy the quantity of the second item to the first (please excuse anything about it that's suboptimal, it's one of the first 8F scripts I've ever written and I'm still learning about Game Boy machine code):

Code: [Select]
Burn Heal   x45
Dire Hit    x45
Ice Heal    x119
Lemonade    x98
Fresh Water x201

inc c        ; Together with line 5, creates a nop
dec l        ; hl now points at the quantity of second item
ld a,(hl-)   ; a now holds quantity of second item, hl now points at ID of second item
dec l        ; hl now points at quantity of first item
dec c        ; Together with line 1, creates a nop
ld (hl),a    ; Overwrite quantity of first item with contents of a
ld a,$62     ; Set a to its original value minus 1
inc a        ; Increment it by 1 (done over two instructions so ret falls on a quantity rather than an ID)
ret          ; Return to game code

Some of the code is devoted to making sure A holds a value of 0x63 when the game's code takes over. If I didn't do that, the code could be simplified slightly to something like this:

Code: [Select]
Burn Heal   x45
Dire Hit    x45
Ice Heal    x119
TM01        xAny

inc c        ; Together with line 5, creates a nop
dec l        ; hl now points at the quantity of second item
ld a,(hl-)   ; a now holds quantity of second item, hl now points at ID of second item
dec l        ; hl now points at quantity of first item
dec c        ; Together with line 1, creates a nop
ld (hl),a    ; Overwrite quantity of first item with contents of a
ret          ; Return to game code

However, I'm afraid that something in the game's code will expect A to hold 63 and break when it doesn't. Is that the case, for A or for any of the other registers?

Thanks :​)

ISSOtm

  • The French Lord of Laziness (and a huge The Legend Of Zelda fan)
  • Wiki Contributor
  • *
  • Offline Offline
  • Gender: Male
  • Pewter City (B)rocks !
    • View Profile
    • My Little Website
Re: Required register values after 8F execution?
« Reply #1 on: January 01, 2017, 04:58:20 am »
The registers can be any value at exit, don'cha worry :)
"THOU SHALL NOT PASS !!"  RIVAL's effect, Gandalf.

Proudly glitching Pokémon Red and Yellow on a Black & White GB, Pocket GB, GB Color, GBA SP and new 3DS.

My Twitter (beware, I'm French)
My YouTube (same warning)

Here is an online tool to build 8F setups : GBz80 to Items !

They see me layzin', they ha-tin'...
Heavy contributor of the global augmentation of entropy (my room's is too damn high !)

undergroundmonorail

  • GCLF Member
  • Offline Offline
  • CHARIZRAD 'M ROXORX or is it.
    • View Profile
Re: Required register values after 8F execution?
« Reply #2 on: January 01, 2017, 04:42:40 pm »
Awesome, that's great to know. Thank you! :​)