Language…
7 users online: crm0622, Danik2343, Firstnamebutt,  Losoall, pnaha, tOaO, Zavok - Guests: 152 - Bots: 394
Users: 64,795 (2,381 active)
Latest user: mathew

Making Hex Edits in a Patch

Hello, I made a very nifty little tutorial about making hex edits in patch format. You may be wondering why a patch when I can do it in a hex editor. Well say you add another patch and it corrupts your rom and you've added about 20 hex edits, not only would you have to make all the hex edits again-- you'd have to remember exactly which ones you made. If you had made them as a patch you only need to patch it once to restorm all of them, plus you can make comments documenting what's what.

Here's the patch

And here's the content of the patch:
(Note: I made this for someone else but it should be good for you)
Quote
header ; This indicates the rom has a header
lorom ;...and is lo-rom format
; Don't change this or the patch won't work

; Also incase you didn't know, adding a semicolon (;)
; will make everything after that on the line not
; exists as part of the code. It's just how you write
; comments.

; Okay here is where the hex edits start.
; Take a look at SMWC rom map for hex edits. Here's what you want
; 27954 $04:F754 1 byte Misc. change to 80 to disable lightning in Bowser's Valley
; In a normal hex edit you would want to go to adress x27954 and change that
; but this time we're going to take $04:F754 and change that.
; First remove the colon (:) and add org before ite like to
org $04F754
; Note that that's actually part of the code now.
; Second you'll want to add the input that you'll want to change but
; you need to add db first. Like this
db $80
; Now that you've disable lightning, why not disable sound of it too?
; Here's the line after we control+F for it in the rom map.

; 1E216 $03:E016 5 bytes ASM Lightning sound FX for Bowser battle.
; Change to EA EA EA EA EA to disable noise.

; Oh noes there are more than one input that we need to change~!
; Easy, do everything the same except add a coma (,) with no spaces
; between each input value. So it'll looks like this~~
org $03E016
db $EA,$EA,$EA,$EA,$EA
; And there you go. So concludes how to add hex edits. But we're not finished yet.
; Feel free to add more between here and the long line.

;-----------------------------------------------------------------------------------
!Freespace = $138000 ; This is the Freespace, or where we're going to put the code.
; This is usually only used when making a real patch but I'll include it anyway.
; Obviously, you'll want to change that to a free adress.

org !Freespace ; So now we go to that adress.
!CodeSize = Ending-Routine ; This is where we put the bew code.
db "STAR" ; I'm not too sure aobut this.
dw !CodeSize-$01 ; How big the code can be.
dw !CodeSize-$01^$FFFF ; All of this is known as the RATS tag.
; Which is used to perserve the code.
Routine: ; This is where the code starts
RTL ; But since where not doing anything, just return.
Ending: ; Here is where the tag ends. Anything after this will not be perserved.
; And that's our code. You can add more hex edits right before the long line.


Hmm, could be quite useful, I'll try it tommorrow.

Originally posted by "Quote"
; First remove the colon (:) and add org before ite like to
Err1: Smiley alert

May I suggest adding spaces between the colon --> ( : )
or use : instead of the colon --> (:)
to fix it?


Err2: Spelling

Did you mean to write "it like so" instead of "ite like to"?

</teacher>

E: right right, where are my manners: good job with the tutorial!


Or place bold tags in the smily. :P

In any case, it looks like a good tutorial, but I must ask why you're inserting a RATS protected RTL in the ROM.

World Community Grid: Thread | Team
 
Originally posted by Ixtab
org !Freespace ; So now we go to that adress.
!CodeSize = Ending-Routine ; This is where we put the bew code.
db "STAR" ; I'm not too sure aobut this.
dw !CodeSize-$01 ; How big the code can be.
dw !CodeSize-$01^$FFFF ; All of this is known as the RATS tag.
; Which is used to perserve the code.
Routine: ; This is where the code starts
RTL ; But since where not doing anything, just return.
Ending: ; Here is where the tag ends. Anything after this will not be perserved.

...now what is the point of that? If the routine only consists of an RTL, why would you ever need to call it?
My YouTube channel
Get the official ASMT resource pack here!

It's just for teaching purposes, it's more of a template than anything.

I agree, this could definitely help some noobs understand how patches really work as apposed to "HURF DUFR THIS PATCH DOES IT I DONT KNOW HOW". Yes, I've seen that before.
Now with extra girl and extra hacker
This helped me understand quite a bit, thought I have a few things I don't understand that could be helpful:
Would you be able to explain the difference between db and dw?
And what is NOP?
NOP is a command that does virtually nothing (except for wasting time and space, but it does nothing to the way the code works) It's often used to overwrite unwanted code.

db (direct byte) inserts a byte directly into the ROM. db $01, for example, would place the byte 01 in that spot. dw (direct word) places to bytes at once, in reverse order (also known as little endian format). dw $1234 would place the bytes 34 12 in the ROM, dw $DEAF would result in AF DE etc.

You can also use that in combination with labels. For example, if you use dw Test, and the label "Test" is located at address $xx:8039, you'd get 39 80.