News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

A question regarding ASM...

Started by PKstarship, August 27, 2015, 02:12:31 AM

Previous topic - Next topic

PKstarship

A while ago, I found out that opening a .asm file in a text editor app allowed me to edit the code, and I used it to remove the corner map in Scyzer's Prime HUD patch, because I couldn't fix the map tiles otherwise. This led me to wonder, would opening a .asm file, deleting all of the code, and writing entirely new code make a new patch? I don't if this would work, but if it does, I would like to learn ASM and make some simple patches to help contribute to this site.

begrimed

Yeah, you've got it. The only real difference between a text file and an ASM file is the .txt and .asm file formats for them.

Scyzer

Actually .txt and .asm file extensions are completely interchangable. There's no difference to the content of the file itself. You can write it as a simple text file in notepad, then simply change the file extension to .asm.

PKstarship

Thank you  :^_^: Another question, ASM isn't used to do stuff like edit rooms though, right? As far as I've gathered, it's usually used for other stuff, like editing abilities, physics and palettes. I guess people just use SMILE to edit rooms, but I don't know, I'm kind of a newbie right now :lol:

Quietus

You probably could do that via .asm (or a hex editor), but it'd be a lot more cumbersome than using a visual editor. Therefore, yes, it's used more for thing like those you mentioned, as you're essentially writing new programming code for the game.

PKstarship

One last question, can someone lead me to a tutorial for basic ASM? I would really like to learn so I can make some patches :^_^:

Jordan5

Try here under the references tab. Not 100% applicable examples but it should give you a basic grasp :^_^:

PKstarship

Okay, Thank you all so much for your help! :^_^:

PKstarship

So I  just finished reading the first ASM lesson in Scyzer's tank and I think I get it, but correct me if i'm wrong: RAM is memory that remembers certain values, but it only exists while the ROM is running, and can't be seen using hex editors, but some emulators allow you to view it. ASM is extra routines added to the RAM to change the values, like adding certain code to make it so you have all of the upgrades, and a RAM map shows the values of the RAM so you can more easily write the routines. I think that's right, but I don't want to think I'm right when I'm not and screw all this stuff up, so I'll ask the more experienced people.

Mtgxyz

thats not exactly right. RAM is always existent, but its contents are undefined, when the device using that RAM is shut down.
It also exists when the rom gets yanked out of the console (You can put code in RAM, which  can be executed)
you put assembled ASM on the rom, so it gets executed from there. the RAM is usually not used to store code (which gets copied from ROM). The RAM map shows the ingame usage of RAM, because somewhere is the stuff like map data. enemy positions, samus energy etc. stored.

This is true in most cases, even outside of the snes.
(OK. on the PC most code is loaded from the disk in the ram and data usually gets stored on hdd and not on battery-backed ram, but yeah. it is still true for modern machines.)

Black Falcon

This might be a bit of a stretch but I try to explain it as fast and hopefully as easy as possible:

ASM = Assembly code

Assembly code (another term would be machine code) is the very language every CPU needs in order to work.
Each CPU has a predefined set of things it can do (opcodes).

The SNES CPU has a total count of 256 possible opcodes  it can understand and execute, and each one is expressed using a single byte only ($00 to $FF), where some of them tell the CPU to read ahead 1 to 3 additional bytes to further define things like addresses and values.

You can view these opcodes in either binary/hexadecimal form (how the CPU reads them), or using Mnemonics (like LDA and STA, how you read it in your ASM file).
Now a CPU can't read a plain text file like you can, so you have to turn it into code, and this process is called compiling.

--------------------------------

ROM = Read Only Memory

IE exactly what the name says. Any kind of code (read: ASM code) that's executed is part of the ROM, no matter where it is executed, and thus can't be changed. The CPU reads the code from the memory in order to get further instructions.
The same counts for any kind of values used to load rooms and other things when the SNES runs. Of course once being loaded (ie copied) into RAM, the CPU can change these values there, but not the initial ones in the ROM.

--------------------------------

RAM = Random Access Memory

This memory is being used temporarily while code is executed for the CPU to keep track of certain values that are being used for calculations and hardware registers.
'Random' refers to the possibility of accessing (reading or writing) any address holding a value at any given time if the CPU asks for it.

--------------------------------

To clearify another thing:

Even the SPC engine doesn't change itself on runtime, even though it gets loaded into a RAM section by the main CPU.
From the APU's perspective, the SPC engine itself is the ROM where the code is located, and it has its own RAM to work with in order to play sounds/music.

----------------------------------------------------------------

Think of the whole concept simply as a walk through the super market:

You are the CPU.
Your ROM is the shopping list, you can only read it and not change it.
Your instruction (the code) is to get all items on the list, and since you're incredibly obedient you're determined to get all of them no matter what and nothing else.
Each RAM address is a shelf, holding items as their value.
You take an item out the shelf, so you change the value at that address.
The order of how the shelves themselves are layed out in the market doesn't matter and they all can be accessed randomly.
When you got all your items, you're done.
Now a CPU cannot stand still, and you eventually have to go to the super market again, repeating this procedure.

I hope it helps a bit  :^_^:

PKstarship

Thank you for helping, it makes a lot more sense to me now, especially the difference between ROM and RAM :^_^: Right now I'm trying to learn enough about this so I can do something simple, like make a patch that makes Samus start the game with the screw attack. This stuff is pretty confusing for me right now, but that's probably because I've only started learning this stuff maybe five hours ago :lol:

Jordan5

Quote from: PKstarship on August 27, 2015, 05:04:12 PM
make a patch that makes Samus start the game with the screw attack

Have a look at this on the main site :lol:

PKstarship

Oh, I guess that's already done :lol: After reading lesson 2 on ASM, I now want to make a patch that lets you use the Hyper Beam as long as you have full energy, but I think that's a bit more complicated. Also, I can't find a value for the Hyper Beam on the RAM map.

Jordan5

The place in RAM for Hyper beam is: 7E:0A76 - 7E:0A77

I asked about what to store in there to activate the beam, this is what I was told:

<Smiley> Any non-zero value afaik


So you'll need to hijack a routine that runs every frame and check if Samus' energy is maxed, if it is not, make sure that value is 0000. (STZ $0A76)

I hope this helps :^_^:

PKstarship

Thank you :^_^: I've done a lot of ASM learning today, so I'll take a bit of time to relax and maybe play some video games, but I'll do some more of this tomorrow, and hopefully get this patch made soon. I'm excited to finally learn about hacking!

PKstarship

#16
So I've been trying to make the Hyper Beam activate by adding a routine but it doesn't work. Here's my routine:
Lorom

org $9498B2
     DW $0A51

org $940A51

LDA $0A76
INC A
STA $0A76
RTS

I'm not sure what I'm doing wrong, is there something I'm missing? :neutral:

Edit: I think maybe I should learn a LOT more about ASM before attempting to make a patch...

Mon732

Lorom

org $9498B2
     DW $0A51  ;Pretty sure this has to be #$. Check $9498B2 in a hex editor to make sure it's what you think.

org $940A51

LDA $0A76  ;Side note, If you put LDA #$0001 then you don't need the INC A and you save a byte. :P
INC A
STA $0A76
RTS


$ means address
#$ means immediate. i.e. Use this value.

$0A51 is the value at the address 0A51
#$ is the value 0A51

Smiley

It's just $ when using DW (or DB/DL), not #$. The problem is it has to be negative, ie. higher than 8000. Replacing DW $0A51 with DW $8A51 and org $940A51 with org $948A51 should fix it, though you should make sure it's actually free space before applying the ASM.

Mon732

Ah, whoops. Just goes to show how rusty I am. :^_^:

Scyzer

That code will never work how you want it to. That's the bank for block reactions (specifically, the address you've put your hijack is for a fool-xray Samus collision reaction for BTS ~$03). That means this code will only run while Samus is touching the applicable block type and BTS.

You need to find a hijack point which runs every frame while the game is running.

Jordan5

#21
If you're still stuck, I wrote this which works (it is not optimised really, but still it's fine for showing you)

lorom

org $90E72C
DW $F63A ;hijack branch which jumps to RTS every frame

org $90F63A
LDA $09C2 : CMP $09C4 : BEQ + : STZ $0A76 : RTS ;check if current health = max health, if so branch, else turn off hyper beam

+
LDA $0A76 : BPL ++ : RTS ;check if hyper beam is active, if so do nothing, if not then branch

++
INC $0A76 : RTS ;turn on hyper beam

PKstarship

#22
Yes! I did it! I made the Hyper Beam work! After taking the stuff everyone said into account, and looking at some ASM in the patches section, I was able to get the hyper beam into normal gameplay. Please forgive me for the fact that the hyperbeam looks screwed up, I'm still new to this. Thank you all for helping me to make this patch :^_^: I should have the "Hyper Beam at full energy" patch ready in a few hours.

Edit: Jordan5, for some reason the code wouldn't show for me, but I've got the Hyper Beam at full energy patch made. I will be putting it on the Metroid Construction Collaboration Hunt so I can get a spot on the Patches section, but here is the routine I made:
LoRom

org $828BAC
JSR $F63A

org $82F63A

LDA $09C4
CMP $09C2
BNE HYPOFF

LDA #$0001
STA $0A76
RTS

HYPOFF:
STA $0A76
RTS

It works, but did I do a good job making it? I don't know if it takes up as few bytes as possible.

Jordan5

Code doesn't like spoiler tags so now you've done it i removed them. I used INC just because you did initially, the LDA #$0001 is likely better as you don't need to check if hyper is active. But that just goes to show there are many ways to do something, and often some are a lot better than others. like I said in the collab thread, the hijack is bad, that is all :^_^:

PKstarship

So I guess I need to hijack a new routine that doesn't result in Samus being immortal, I need to make the beam palette properly swap when you earn or lose the Hyper Beam, I need to make the Hyper Beam properly load the "charged plasma shot" graphic, and make Samus not turn and stay yellow when hit while flashing, then I'll release V.2 of my patch. Jordan5, thanks for telling me that Samus can't be killed, I guess I'm not that good a beta tester :lol: Perhaps I'll try your hijack location. ASM is pretty complicated, but I'm having fun doing this stuff right now!