News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Advice for learning asm  (Read 1706 times)

joesteve1914

  • Full Member
  • ***
  • Posts: 122
    • View Profile
    • Ripening Tingle's Balloon Trip of Love translation project
Advice for learning asm
« on: March 19, 2017, 05:53:09 pm »
So I'm getting ready to finish up my first translation project. I'm the only hacker on the team, so I have experience with stuff like text editing, pointers, graphics editing, standard compression; that kind of stuff.
But I also needed quite a bit of help getting started. The text pointers especially were difficult since they weren't exactly pointers in the literal sense. Eventually someone figured it out and made a text editor for me. I figured out the graphical part of the game by myself though, and now I'm confident that if I moved on to a similar game that I could do all the hacking myself :)

I'd like to take it up a notch and learn asm. I'd like to translate two specific SNES rpgs in particular, but they're both going to require compressed graphic editing and implementation of a VWF.

So for anyone who knows asm and uses it for romhacking in particular, do you have any advice on how I would go about this? Is it beneficial to learn a higher level programming language first (I know none), or will I be okay starting off without knowing any? What resources would you recommend? Is there a console that it is advisable to start learning on? I'm mostly interested in SNES, but is there an easier/beginner friendlier kind of asm to learn first?

Disch

  • Hero Member
  • *****
  • Posts: 2814
  • NES Junkie
    • View Profile
Re: Advice for learning asm
« Reply #1 on: March 19, 2017, 07:48:24 pm »
So for anyone who knows asm and uses it for romhacking in particular, do you have any advice on how I would go about this?

1)  Give a once-over (or twice-over) of a tutorial doc that goes over the basics.  Don't worry about fully absorbing the info, just try to wrap your head around the core concepts like registers and addressing modes.

2)  Find some existing code that is well documented (SMW might be a good place to start, but there's also a bunch on this site (try to stick to SNES or NES -- NES is similar enough)... including FF1 which I have a personal bias towards.

3) Pick some routine in that code that isn't too large and has plenty of comments.  Look over the code, follow along with the comments, and see if you can understand how the code is doing what the comments say it's doing.

4)  Try to re-create a few routines from that code without looking back at it... or write some code that does a very simple task (like appending two strings together).

5)  Once you've done that you've probably got a strong enough handle on the basics... so start looking at your game of choice (whatever RPG you want to translate) and start dissecting the code you're interested in.  Basically this is the same as #3 only this time you don't have comments to help you out.  It might be too hard to figure out the code from just looking, so you may have to make changes and see what that changes in-game.  Tinkering is very helpful.


*)  At any point in the process... if you hit a wall, get stuck, or something is just not making any sense to you... ask a question on the forums.  There are a ton of people here that can help you get over roadblocks -- and there's no point in banging your head against the wall for 2 hours if you're not making any progress.

Quote
Is it beneficial to learn a higher level programming language first (I know none)

Is it easier to learn how to drive stick if you already know how to drive automatic?  Yes.
Does that mean you should learn how to drive automatic first?  Absolutely not.  Not if your goal is to learn to drive stick.

It definitely helps if you have prior programming experience, but don't waste time learning another language first.  It's just an extra, unnecessary step.

Quote
What resources would you recommend?

I'm not savvy on what the best tutorial is... but any 65xx series tutorial (6502/65816/etc) will probably be good enough to get you started.

Apart from that, you'll want an asm reference sheet:  https://wiki.superfamicom.org/snes/show/65816+Reference

And maybe a SNES hw register layout:  http://www.romhacking.net/documents/196/   <--  but don't worry about this until later.  You may not need it at all, and it'll just confuse the hell out of you if you try to read it now.

Quote
Is there a console that it is advisable to start learning on? I'm mostly interested in SNES, but is there an easier/beginner friendlier kind of asm to learn first?

Again, I wouldn't waste too much time learning something that isn't directly related to your end goal.  Focus on SNES if you can.  Though if you can't find enough SNES-oriented resources, maybe consider NES (which is very similar, has better tools, and has a lot more documentation).  But I wouldn't bother looking at anything else.

STARWIN

  • Sr. Member
  • ****
  • Posts: 454
    • View Profile
Re: Advice for learning asm
« Reply #2 on: March 19, 2017, 08:06:15 pm »
aw disch writes quicker these days. here is some other perspective then

So for anyone who knows asm and uses it for romhacking in particular, do you have any advice on how I would go about this?

Try to do what you want to do. If you don't know the details, then research the game using a debugger and write up notes of the game's subsystem you are interested in.

Is it beneficial to learn a higher level programming language first (I know none), or will I be okay starting off without knowing any?

No need for detours as far the asm part is concerned, however if you want to write tools that automate something you must do, then you should create the tool with whatever high level language you like.

The CPU executes an instruction in the location specified by the PC (program counter) register, and then automatically increments the PC by the size of that instruction. Some instructions change the PC value when executed. There can be interrupts at "any time" that store the current/next PC value to the stack and then change the PC value - typically the code there then backups the registers it uses, restores old values after done and returns. So interrupts are supposed to be invisible to the main program.

That's the general idea for about any computer, as far as asm is concerned.

What resources would you recommend?

Find a memory map, that tells for what purposes the cpu's visible address space is partitioned. When it loads/stores stuff from/to memory, it refers to these addresses that can be RAM, ROM or memory-mapped IO.

Also find a cpu instruction reference, so that you can check what each asm instruction you see does.

Lastly, a debugger that lets you look at the game state when it is running. Geiger's is an old one and bsnes-plus is a new one. Breakpoints stop the execution when a condition like "reads from this address" or "writes to this address" or "executes the instruction in this address" matches. Trace logging can write a huge text file that shows everything that was executed, but it grows really fast.

Is there a console that it is advisable to start learning on? I'm mostly interested in SNES, but is there an easier/beginner friendlier kind of asm to learn first?

NES is a slightly simpler SNES. http://www.obelisk.me.uk/6502/ is a nice reference for the NES processor, and most things there are valid for SNES as well.

A big difference between NES and SNES asm is that in SNES you see a lot of REP and SEP instructions that target specific bits in the P register. They change A and X/Y register effective sizes and with that the effects of various related instructions, the sizes of instructions that have their argument with them and some less obvious instructions like STZ.

joesteve1914

  • Full Member
  • ***
  • Posts: 122
    • View Profile
    • Ripening Tingle's Balloon Trip of Love translation project
Re: Advice for learning asm
« Reply #3 on: March 20, 2017, 09:44:52 pm »
Wow, thanks for the detailed posts! I'll be sure to look over that stuff carefully and heed your advice  ;)

Once again, thanks! I really appreciate it.