Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.

You can join Glitch City Research Institute to ask questions or discuss current developments.

You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.

Arbitrary Code Execution Discussion

Opcodes and Item Correspondence: 8F - Page 1

Opcodes and Item Correspondence: 8F

Posted by: Kyouken
Date: 2018-12-05 18:52:45
Hello! I have a question which I thought would have been asked more:

When using item 8F, how does one know which items refer to which opcodes? For example, I've seen X Accuracy used a couple of times to "ld l", and I've just assumed that X Accuracy is the item you want to use for that opcode. But what I'm stuck on is how to find out just which does what.

For reference, I've been checking around the site for a couple of hours now off and on for the past few days gathering information on how to obtain and use 8F. My knowledge of assembly is next to none, but I understand very basic things like loading things into the accumulator, incrementing, decrementing, etc. I've been studying some of the code here for a little while and using the 8F helper to compare item lists to code, so I've figured some other things out. I also have some ASM tutorials for the GB to read (which I've found by scouring the threads here,) some item lists (the BIG one,) and some other things to aid me. My conclusion thus far is that the reason the question hasn't been asked is probably because it's a fundamentals issue rather than something specific whereas if I knew the fundamentals of ASM for the GB, I'd be able to at least better find the answer. But after looking at the code for some of the item lists, that's the only thing I have not been able to decipher.

If someone could point me in the right direction (or just straight up tell me I'm gonna have to debug/learn the basics to understand) I'd appreciate it!

Re: Opcodes and Item Correspondence: 8F

Posted by: Couldntthinkofaname
Date: 2018-12-05 19:11:44
Hi!

Basically, when ASM is "assembled" it is converting the text mnemonics we refer to as "opcodes" into machine-readable bytes


There are a number of resources that can be used to determine what hex value corresponds to what Item ID and what Item count (which, by the way, is simply the hex value represented as a decimal)

Resource 1, Gbz80 to items, a lovely tool made by ISSOtm. It converts ASM directly into your item list, and it even has label support!


Resource 2, The BIG HEX List, right here on our forums. It provides hex values, the values in decimal, the Pokemon, and the items that correspond to the opcode for manual conversions.

Example:

How would I write "ld a,3" in Items? Well, "ld a,3" translates to the hex values 3Eh 03h, converting each hex value into items, I would receive "Lemonade x3", because 3Eh is the ID to the Lemonade item, and because 03h is… well… 3.

Hope this helped, and feel free to ask more questions.

Re: Opcodes and Item Correspondence: 8F

Posted by: Kyouken
Date: 2018-12-05 19:31:47
Yo! That list there is what I've got bookmarked, only that one has the instructions (which I called them opcodes, so I made a mistake there.) The one I've got bookmarked is here, which I suppose is outdated. That's a massive help; thank you so much.

The program you linked to before that, I've got that one bookmarked too! I'll use it to learn more before I jump right into doing it by hand.

My next question(s) are these:

Bigger question: if I understand the example you wrote correctly, you mentioned that having 3 Lemonades would Load the value 03 into the Accumlator, correct? If so, how did you arrive at the conclusion that the hexadecimal value 3Eh is equivalent to Loading the Accumulator (apart from that list)?

Smaller question: you stated the hexadecimal values 3E and 03 as 3Eh and 03h; h is a register, right? So what do you mean when you say 3Eh and 03h?

Thank you for your time and patience - I'm not new to programming entirely but I'm pretty darn new to low-level programming.

Re: Opcodes and Item Correspondence: 8F

Posted by: Couldntthinkofaname
Date: 2018-12-05 20:07:19
Hi,


Bigger question: if I understand the example you wrote correctly, you mentioned that having 3 Lemonades would Load the value 03 into the Accumlator, correct? If so, how did you arrive at the conclusion that the hexadecimal value 3Eh is equivalent to Loading the Accumulator (apart from that list)?


In GBZ80, "ld a,$xx" (with "xx" being the byte after the opcode, being loaded into the accumulator) is, when translated to machine-readable code, is 3Eh. Really, the only way to come to that conclusion would be to have a sort of "manual" or "guide" to the opcodes. There's a nice one here, albeit that one isn't really a hex list (e.g., that list does not tell you that "push af" is F5h, it simply tells you that "push <register>" is "x5h", in which x will have to be substituted with the value you find in an actual hex list, in "push af"'s case, F, and in "push hl"'s case, E. :P ) .

Here's a manual that contains an instruction list on page 65, although ISSO warned me from referencing that as it is a bit outdated (forgive me!). Should be fine if you plan to use it as a simple hex list.

The hex list here on the forums should also work fine, unless you plan to use CBh opcodes


Smaller question: you stated the hexadecimal values 3E and 03 as 3Eh and 03h; h is a register, right? So what do you mean when you say 3Eh and 03h?


The "h" suffix is commonly used to refer to values as hexadecimal. This is important, as 16h for example, is not equal to 16.

Re: Opcodes and Item Correspondence: 8F

Posted by: Kyouken
Date: 2018-12-05 20:58:57
Knowing that it's not something you can know without a manual of sorts sets me more at ease - because this is new to me, and I've been figuring other things out by studying code (almost to a point where I'm writing something small!), I really thought I was missing something obvious. Thank you for that. With the resources you've linked, as well as other stuff I've found around, I suppose it's not so necessary to know how the instructions translate (especially now that I know it's not some big secret :O ). But, for practice purposes, I'd still like to write it by hand and translate it myself once I've got enough knowledge to do so. I'll bookmark those lists you linked there.

And I see what you mean when you refer to hexadecimal now using the 'h' suffix. Never thought to use it, but it's a good way to differentiate, especially if there aren't any letters in the number.

I have more questions concerning unrelated things, but I'm going to hold off until I've taken more time to understand things. I need to read through some basic ASM tutorials for the GameBoy.

Thank you for all your help!