Jump to content

The Ultimate Tutorial [V2]


Crimson Red
 Share

Recommended Posts

Another update with the same links (the online version is still amidst updating though; it takes the longest for reasons I don't want to explain).

It includes the long-awaited chapter on custom battle animations. Oh, whoops, chapters, because I had planned for 2 chapters to divide up custom battle animations.

Might I add that these 2 chapters make up 30 pages of the 220+ page tutorial. O____O

Normally I'd add exclamations to show how great I feel about finally getting this done (and now there's no excuses to not do custom battle animations) but I'm tired so yeah. =P

Link to comment
Share on other sites

  • 5 months later...
  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

The midi2gba tutorial could use another chapter on instrument inserting. that, or maybe you can just tell me how to import instruments from another rom? Not like I'm worth your time...

Turns out the rom I wanted to import all those songs from has unsupported tracks for ZME. Just my luck, eh?

also, this is great. Now I don't have to bug ryru to tell me how he imported those snow tiles into FE8 anymore. :D

EDIT: Question though...FE7 seems to be set up differently event-wise. How do I know where the snow tile data ends?

Edited by MagicTiger
Link to comment
Share on other sites

I'm not sure what you're talking about, but generally to know where one data ends you find the entry right before or after it in the Nightmare Modules and the start of one data is the end of another/vice-versa.

I'm uh, not very good with instrument inserting. I leave that stuff to ZSE. I might add a chapter on how to insert custom sound effects, but I don't have a very safe method for that either. D=

Link to comment
Share on other sites

  • 3 months later...

BUMP! The newest, 100% complete version of the Ultimate Tutorial is being uploaded as I'm posting this! I've completed all 75 chapters of over 270 pages! It's my greatest accomplishment and so I hope people find it useful in their hacking endeavors for years to come!

The first page has the update log and all the downloads. Thanks for all the support and reports I got regarding the Ultimate Tutorial so far.

I'm so happy I'm finally done... yes, yes, YESZ! FALCON PAWNCH!!!

YESZ!

Link to comment
Share on other sites

Let me be the first to shake your helping hand, Blazer. ;)

Seriously, this is honestly the only tutorial around I even accept to use the tag "Ultimate". ;) It is so big I can easily say it is a book. 318 pages for the doc version, I mean, heck, it is a book. Blazer, you F'ing wrote the text book for FEhacking. The most extensive group of tutorials ever assembled, done by one of the most experienced and outstanding hackers this community has ever had the pleasure of working with, so it's credibility is also assured, with your known experience as a pillar.

Those that want to learn how to hack, I recommend this tutorial very much, for how many topics it handles(Heck, 73 chapters, something there will be of help). Those that know already but just don't feel confident, I suggest at least a quick read before every new operation, or at least in bored times, so you don't forget basics. Those that know close to all there is to know, still consider this your GBATek-equivalent for times of need. :)

Link to comment
Share on other sites

You're giving me waaaaaay too much credit but thanks anyhow. And 318 pages? How did that happen--it was only 274 for me. Different page lengths or something? O_o

And actually a lot of the stuff doesn't have tutorials on it, like battle backgrounds, general GBA stuff, certain aspects of Nightmare even, custom battle animations, custom spell animations (which has never had a public tutorial before TMK), as well as different patch formats (a lot of people aren't familiar with JFP and XDelta), even some music stuff, it's not just for review or newbies IMO, even people who are already on their way to making hacks can make use of some of the unique stuff in there IMO. At least that's what I think... I mean everyone knows to go to Arch's tutorial for event editing but now there's actually a tutorial for CSA's, even if it's new and not the best one.

My point is just "something is better than nothing" ._.

Link to comment
Share on other sites

Congrats, Blazer!!!! (I just realized it was finished today when I went to check something about a random NM module :O) Anyway, your tutorial, and how much you explain all the steps and processes are pretty much the only reasons I started hacking. (Otherwise it would've gone something like, "F*** this, it's too hard.") Anyway, thanks for all your hard work on it, and congratulations, man! :)

Link to comment
Share on other sites

I noticed you have the chapter for my music tool marked as 'outdated' - I'm preeeeeetty sure the only meaningful changes since the version shown in the guide have been in the midi conversion stuff.

Also, one day when NM3 is actually a real thing, it will effectively create a new "patch format"... :evil:

And yeah, congrats! Having this much information in one place is really awesome. I hope you don't ever expect to consider it completely finished though :3:

Edited by zahlman
Link to comment
Share on other sites

@Zahlman yes, well you see I haven't had the time to figure out the changes, so... for now I'm just keeping it safe and calling it outdated. XP

And no, I'll be updating it, but I've actually put content in every chapter instead of just having titles for chapters, so that's what I mean by it's "complete"--no topic that is meant to be covered isn't covered in some way, to say the least. As long as FE hacking continues to develop though it's mostly stopped IMOthis tutorial will have to, though it'd be nice if someone else would take over that job soon since I want to retire from hacking.

Link to comment
Share on other sites

After my hack is done and when I have time I might write a few chapters on a few techniques I developed for my own project, like custom menu making and animation making and stuff. So instead of making them stand alone I might donate them to the most extensive document on FEhacking, why not? :3

But as for taking it on I wonder if I would be able to. (Mainly because I will become more of a consultant of sorts when my own hack is done with XD) It would be grand to find someone both skilled and willing like yourself. :)

Link to comment
Share on other sites

It's not that hard to do this, doesn't take much skill, just takes time and patience. The rest can be learned pretty easily, I just happened to be the one who took the initiative to do this, lots of people could have done it, and so there should be lots of people who can keep revising it. Just a matter of willingness, time, and patience...

Link to comment
Share on other sites

  • 6 months later...
  • 1 month later...

Just bumping to say that the Ultimate Tutorial got some small updates today...

and that as usual, I can't remember most of the stuff I want to update it with when I actually go and make updates... >_>'

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 months later...

The tutorial has been updated. Mainly small changes and minor notes to help people here and there and to keep things slightly less outdated. The Miscellaneous Information Archive has also been updated with what I think is a fair amount of miscellaneous information, alternative tutorial links, etc., though for members of SF who check the Resources Forum, you shouldn't be missing too much... ^^;

Link to comment
Share on other sites

  • 3 months later...

just going to tighten some things up for chapter 74 so you can actually sound like you know what you're doing (i don't doubt that you do, but it helps to at least have these things in a tutorial :P)

I'm also not going to get into anything like what "pipe" does because a) i don't really know either and b) it isn't helpful at all to people who are only trying to learn ASM -hacking-

What the hell are THUMB and ARM? Don’t ask me, I don’t really know. But we can use either THUMB or ARM to write our programs and we’re going to use THUMB. To let the game know we’re using THUMB, we’re going to make it start at an odd offset—meaning we add +1 to the offset we inserted the routine at. Yes, that’s right—you would actually type “ASMC 0xOFFSET+1”, or in our example, “ASMC 0xD50001” for it to load the routine at 0xD50000.

In a more technical sense, ARM and THUMB are the two different modes in the GBA's processor (which, for reference, is the ARM7TDMI, the T signifying that it has a THUMB mode). ARM instructions take up 32 bits (4 bytes) and are generally far more robust, with the ability to put conditionals on all instructions (so you can do something like "addne" for "add if not equal" and it will work). However, the GBA can only load 16 bits at a time, and thus THUMB mode (whose instructions are only 16 bits) is preferred for the most part) is the better choice basically 95% of times (the other 5% is when you have to handle graphics or other hardware stuff)

The reason you need to use the +1 is that the "bx" instruction (which is like, literally the only thing that ASMC does) checks the rightmost bit (and uses all the other bits to determine the address to branch to). If the bit is set, it turns the processor to THUMB mode. If not, ARM. Done.

.org sets the offset. It’s just like the event assembler code, ORG—in fact, Nintenlord, the maker of the Event Assembler, knows ASM, and borrowed a lot of the ideas in his event assembler from knowing assembly and programming in general, I’m pretty sure. I’d go into making comparisons and such, but it’s not really relevant. For this example, we want the program to write to the offset 0x00, so we tell it that. 0x00 is the same as 0x0000000000, FYI. Also, this code is totally important, just like the .thumb code.

.org really isn't that important, if you omit it it just acts like .org 0x00 (well, that's what it's done for me every time).

Also, Nintenlord didn't borrow so much from assembly to make EA and more just from programming in general (in particular, he just took a bunch of conventions that are used in compilers/assemblers for languages like C or Java and applied them to events)

But some registers have special purposes. Generally speaking, r0-r7 are free for you to use. r8-r13, I dunno, don’t ask. r14 and r15 are a bit special though. r14 contains the address that the “game” or “processor” or whatever you want to call the “thing” that runs through ASM was at before it last branched. I think. Don’t quote me. On the other hand, r15 contains the address of where you are right now.

r0-r7 are free for you to use, but if you intend for things to work once you're done with your routine you really should only be using r0-r3 (it is in fact possible to write really complex routines with only those four if you keep track of what variables are 'live' and what aren't). If you need more, you should push and pop them later (i forget if you specified this later) because the game will actually store important variables in r4-r11 because the ARM reference specifies that r4-r11 should be "clean". r8-r12 are generally not used in THUMB because THUMB instructions that aren't "mov" can't actually access any regs higher than r7 (fine, push can have r14 and pop can have r15 but that's like it). r12 can also be clobbered if you need a scratch register, so that's safe.

r13 is the stack pointer, messing with that will do the exact same thing as if you'd thrown in an extra push or pop somewhere (well, not exactly, but you get the idea). It basically stores where the stack is in memory (so if you change r13 you'll be changing what comes out of the next pop or where the next push goes to).

It’s the first one on the list here, “EQ”, meaning “Equal”. In other words, if checking to see if the two values in the “cmp” code above are equal to each other, and if it is, it goes to the offset after it, called “End”. Before I explain that, let me quickly mention the other two columns above: the “Opcode” column refers to the bits that control what opcode it is (you probably won’t ever need to worry about this), and I have no idea what the status flags do, sorry. I never had to use them so I never learned them. XP

The status flags are basically what enable conditions to work. I won't explain in more detail (you can get a better explanation from reading an ARM manual than from me) but it would probably be a decent idea to just say something like "they aren't important" or something or tell them where one could learn about them :P

Then we load the value 0x48 into r3. Next, we use the “mul” opcode to multiply two registers together. The “mul” opcode is pretty cool, but it’s limited in that it can ONLY multiply two registers together, which means you have to waste a register “mov”ing the value to multiply by beforehand (as I did with mov r3, #0x48). The first register is the destination register, or the register whose value changes, as per almost every code except the confusing str code. So mul r3, r2 says that r3 = r3 * r2. On our first loop, r3 = 0x48 (this is actually for every loop because it gets set to 0x48 right before the multiplication) and r2 = 0x01 (the loop counter is set to 1 on our first loop). In THIS case, r3 is STILL 0x48, but on every subsequent loop, r3 will be some other multiple of 0x48.

Just FYI, mul is a very very very slow operation. If you're only multiplying by a constant, it would be a better idea to use a combination of lsl's to do it (if you don't know what i'm talking about then just hit me up on skype and i'll try to explain better)

Next, a new code: lsl—this is a logical shift left, which essentially moves bits over to the left. I don’t really feel like explaining it, but due to how bits work this also doubles the value… or rather, it multiplies it by 2^(#), where the # in this case is 0x02. So lsl r1, r1, #0x02 multiplies r1 by 2^0x02 and stores that in r1, effectively multiplying it by 4. This saves us a register as we don’t have to use the mul code, and is thus more efficient. People don’t like the mul code in general and try to switch to this and its opposite, which is lsr, which shifts to the right, and divides by a power of 2. To divide by a power of non-2 though, things get a bit more complicated, which is why you either have to use some special bios function (not preferred) or do some fancy multiplication/division combinations… *sigh*

While I do understand your frustration (it is horrible to have to divide by 3) I think you should at least give an example explanation. The way Hextator taught me how to divide by 3 is to do the following:

x * 1/3 = (1024/3)*x/1024 (it doesn't have to be 1024, it just has to be a really large power of 2- I would recommend using 1024 or higher)

Now, 1024/3 is a constant, so we can get that on a calculator- It's roughly 341. So if you multiply your original number by 341 (either via lsl series or with mul), you end up with 341x/1024. 1024 is a power of two, so we end up with this:

x/3 = 341x << 10

which is kind of hard but not really. Your only other option is to screw with BIOS/swi which is hard.

Thus you have the bl command, which is better, but still not perfect. The bl command is an opcode that uses 4 bytes: it has… I believe 3 bytes (it might actually be like 20 bits, I don’t know and I don’t feel checking—thumref or GBATek could tell you exactly how it works but I’m more about the practicality of all) and can link to much farther locations, but still not anywhere in the ROM. So now the issue is getting a location close enough to the original routines, which are usually at the beginning of the ROM.

You could alternately use this trick:

@[...main code...]
bl longBranchCall
[...]

longBranchCall:
ldr     r0, =ROUTINE_OFFS+1
bx      r0

which works equally well and allows you to throw routines wherever.

Okay. Now, the basic idea behind debugging is that you say “this area is suspicious: let’s stop the game in this code and see what it does”. To stop it, you make a breakpoint: what I do is just click on the code I want to set a breakpoint on and it turns red. To get rid of it, click on it again or use the debug menu to clear all breakpoints.

You can set the game to break on read or break on write (ie it breaks when a certain point in memory is read or written to) by going to Debug -> Set Breakpoint

The options are like so

[Address]cond

Address- self explanatory

cond- ! is write break, ? is read break, ?? is something else. They also stack. So to make it break if the offset 0203A3F0 is read or written to, you would input [0203A3F0]!? to that window.

F contains all the registers and their values. Sadly, I don’t know what cpsr and spsr are though, since I never had to learn… XP

cpsr and spsr are things that matter if the game explodes

don't touch them

Link to comment
Share on other sites

just going to tighten some things up for chapter 74 so you can actually sound like you know what you're doing (i don't doubt that you do, but it helps to at least have these things in a tutorial :P)

I really don't, I didn't learn ASM properly at all, things that should be somewhat fundamental/basic aren't to me, I really only know how to use things in practical terms, which given my general purposes is okay but hypothetically if I wanted to do more with ASM I'd have to go back and learn some more fundamentals

Anyhow, I appreciate that you took the time out to give some explanations. It... sounds like you wanted me to include this in the tutorial, but just to be safe, is it okay if I add them into the tutorial? I will likely just copy/paste with a quote and a line that introduces the quote (and something like "- Camtech" at the end to give credit).

@ARM & THUMB explanation: that makes sense, thanks a lot. Same for bx instruction.

.org really isn't that important, if you omit it it just acts like .org 0x00 (well, that's what it's done for me every time).

Also, Nintenlord didn't borrow so much from assembly to make EA and more just from programming in general (in particular, he just took a bunch of conventions that are used in compilers/assemblers for languages like C or Java and applied them to events)

The .org thing I kind of figured even though I've always put it, however at a later point I have this poor method of organizing data such that it dumps it to .dmp files at specific offsets with everything else being 00's/free space and I am not familiar enough with the... code template (for lack of a better word) that I have seen you and Hex use on multiple occasions that can later be used in conjunction with the patcher you made to insert files, so I did not want to try explaining that (it's also a bit more complicated and personally, even time-consuming, since I DID get it working, I just didn't enjoy doing so lol).

Anyhow my point was that the .org putting offsets becomes more important in codes later on where we don't just copy/paste a routine anywhere into the ROM and call it using ASMC

@Programming, yeah having studied other programming languages I'm aware but I felt that it'd be easiest to make the connection from Assembly to the EA since people reading the tutorial should, hypothetically, know how to use the EA and be learning Assembly, and the similarities would be most apparent in that. In general many programming languages are structured similar and even have similar formats, codes, etc., which is why learning one programming language often makes it much easier to learn another ^_^. (I also think that the EA, if you called it a programming language, is very basic, and THUMB assembly is like the definition of basic or at least old, so it's easier to make the relations between those; things like macros and definitions are actually more inherent of languages besides Assembly IMO[C++? I think that was one of NL's stronger languages]).

@registers yes I did explain push/pop and how one should always make sure that they don't screw up anything in registers that are being used.

@status flags oh I see... alright I'll try to make a note (I probably won't get to any of this for a while since I like to not jump around on focuses much but it's definitely useful info)

@mul AH, so THAT'S why people look down on it. I couldn't figure out why but I kept hearing it was bad so I try to avoid it and tell others to avoid it. I know exactly what you mean though, it's very possible to do a lot of multiplication just through lsl's. This is definitely something worth noting.

@example yeah I thought about it but I guess I was just too tired to push through the pain and give an example, I've never really used anything but lsr to divide though I know there's an ugly BIOS command that can technically do it...

@alternate trick mhm yeah I forgot to mention that, I'll have to add that and a little explanation as to how it works--it just turned out that none of the examples I used, despite using several, used that type of branch, and it slipped my mind. The explanation will probably just be like "be careful as to what register you use to store your word so you don't end up overwriting the value in some other register" since that branch DOES take up a register, meaning you have to have one free or else make a work-around so you have one free (which usually isn't too much of a pain but it's important to check or else it might lead to some nasty glitch).

@breakpoints ah, cool! I tried using the menus at first but I could not for my life figure it out or find any doc on it (though in retrospect I mostly tried trial & error, got frustrated not being able to do anything, and didn't look for any doc very hard--I hope there wasn't some text file in the debugger folder explaining all this... rofl). I'll definitely add that, thanks.

@cpsr and spsr, okay, will add a note "radioactive hazard: do not touch" or something XD

EDIT: Jubby this chapter will not do you much good just reading, just like normal languages, it is rather difficult to learn a programming language just by reading it. You have to read and follow examples, deciphering what they do, and try making sentences/programs yourself. I assume you practice on your own in between and I mostly only cover new material, meaning you have to invest your own time into getting things down and letting them sink in. Just FYI since approaching the tutorial in such a way won't do you or anyone else much good--it'd be like reading a recipe having never cooked before and trying to bake the dish yourself. You're likely to either fail, give up mid-way, blame the recipe for not being written well, or a combination of the above. XD

Edited by Burning Gravity
Link to comment
Share on other sites

Anyhow, I appreciate that you took the time out to give some explanations. It... sounds like you wanted me to include this in the tutorial, but just to be safe, is it okay if I add them into the tutorial? I will likely just copy/paste with a quote and a line that introduces the quote (and something like "- Camtech" at the end to give credit).

yeah that's fine do whatever, just thought it might be helpful XD

The .org thing I kind of figured even though I've always put it, however at a later point I have this poor method of organizing data such that it dumps it to .dmp files at specific offsets with everything else being 00's/free space and I am not familiar enough with the... code template (for lack of a better word) that I have seen you and Hex use on multiple occasions that can later be used in conjunction with the patcher you made to insert files, so I did not want to try explaining that (it's also a bit more complicated and personally, even time-consuming, since I DID get it working, I just didn't enjoy doing so lol).

That's fair. Although I didn't even know that .org worked with gas until I read this tutorial so O_o

@Programming, yeah having studied other programming languages I'm aware but I felt that it'd be easiest to make the connection from Assembly to the EA since people reading the tutorial should, hypothetically, know how to use the EA and be learning Assembly, and the similarities would be most apparent in that. In general many programming languages are structured similar and even have similar formats, codes, etc., which is why learning one programming language often makes it much easier to learn another ^_^. (I also think that the EA, if you called it a programming language, is very basic, and THUMB assembly is like the definition of basic or at least old, so it's easier to make the relations between those; things like macros and definitions are actually more inherent of languages besides Assembly IMO[C++? I think that was one of NL's stronger languages]).

I think you can actually make macros/definitions for assembly as well but you're right, AFAIK they're largely associated with C/++.

@example yeah I thought about it but I guess I was just too tired to push through the pain and give an example, I've never really used anything but lsr to divide though I know there's an ugly BIOS command that can technically do it...

Just for reference (I don't expect you to put this in the tutorial although you're welcome to if you think it's necessary)-

The BIOS routine for division is routine number 6. YOu can call BIOS with the command swi, I wouldn't recommend doing this when /hacking/ because this is a major factor in between-emulator discrepancies (as no$ generally emulates the BIOS far better than VBA). It can also cause any number of weird glitches. The advantage is that it takes all the logic away from your brain.

@ Input: r0, r1- Signed integers
@ Output: r0 = r0/r1
@ Output: r1 = r0 MOD r1
@ Output: r2 = ABS(r0/r1)

mov     r0, #0x10
mov     r1, #0x4
push    {r3-r7}        @ I don't know what registers this routine uses but I can guarantee that a few will get clobbered.
swi     #0x6           @ I heard that you had to multiply by 0x010000 or something in ARM mode but IDK how it works in THUMB, try different things
pop     {r3-r7}

At the end of that, r0 should be 4, r1 should be 0 and r2 should be 4.

---

All in all, though, it's a very good tutorial and I give you props for it. IMO it does a pretty good job as a crash course introduction to hacking-level ASM.

Link to comment
Share on other sites

@swi division yeah I read it up in a generic ASM tutorial once

and yeah it's just a crash-course to ASM as it applies to hacking, I mentioned before it's not very good and I'm not qualified at all to be making a tut on it but there really wasn't much better and now people can't bring all their ASM-hacking questions to me XP

and thanks for the props coming from you it means a lot lololol

Link to comment
Share on other sites

I'm sure I'll be fine, now that I have a working knowledge of how to do it at least :P

I'll just skim through it and see if stuff makes sense and if it doesn't I'll go back and do it later.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...