• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Help Thread: ASM & Disassembly

Status
Not open for further replies.

Joexv

ManMadeOfGouda joexv.github.io
1,037
Posts
11
Years
  • Alright, Fbi Agent how would I go about adding the flag check to the routines like you suggested?
    Is it just adding this to it?
    Code:
    push {r0-r4}
    	mov r0, #0xBF @flag to check divided by 4
    	lsl r0, r0, #0x2
     
    252
    Posts
    11
    Years
    • Seen Jul 6, 2019
    Alright, Fbi Agent how would I go about adding the flag check to the routines like you suggested?
    Is it just adding this to it?
    Code:
    push {r0-r4}
    	mov r0, #0xBF @flag to check divided by 4
    	lsl r0, r0, #0x2
    If you want to check a flag in one of your routines, you'll have to bl call the flag decrypt function, which takes the flag you want to check in r0, and returns the status of that flag to r0. I forget where that function was in FR, but basically do something like this:
    (load flag # in r0)
    ...
    bl flagcheck

    flagcheck:
    ldr r1, function
    bx r1

    You can use any free register of course, I just used r1 as an example. Hope this helps.
     

    Blah

    Free supporter
    1,924
    Posts
    11
    Years
  • If you want to check a flag in one of your routines, you'll have to bl call the flag decrypt function, which takes the flag you want to check in r0, and returns the status of that flag to r0. I forget where that function was in FR, but basically do something like this:
    (load flag # in r0)
    ...
    bl flagcheck

    flagcheck:
    ldr r1, function
    bx r1

    You can use any free register of course, I just used r1 as an example. Hope this helps.

    Yeah, but I make a point to have to ldr in the main function body. That way you can use the linker for more than just a single case. I also believe it's slightly more readable (maybe :P).

    But yeah, what HidoranBlaze did is what you'd do. Make sure to push the low registers you want to save before calling the function, it overwrites r0-r3 :D
     

    Joexv

    ManMadeOfGouda joexv.github.io
    1,037
    Posts
    11
    Years
  • Yeah, but I make a point to have to ldr in the main function body. That way you can use the linker for more than just a single case. I also believe it's slightly more readable (maybe :P).

    But yeah, what HidoranBlaze did is what you'd do. Make sure to push the low registers you want to save before calling the function, it overwrites r0-r3 :D

    Ok, but how would I load the flag number into bl?
    I suck at asm so sry for any stupid questions.
     

    Blah

    Free supporter
    1,924
    Posts
    11
    Years
  • Ok, but how would I load the flag number into bl?
    I suck at asm so sry for any stupid questions.

    The flag checking function is a subroutine. If you're familiar with other programming languages they call things like these "functions" or sometimes "methods'.

    Anyways, the flag checker function has a parameter which is the flag number. By definition, this parameter would be in r0. So you would just load into r0 your flag's number and then call the flag checker function.

    The process of how we're "calling" the subroutine is a little harder to understand. It's a clever trick having to do with manipulation of the Stack. You see, bl is limited to within approximately 20 bytes (I don't recall the exact amount, but around that neighborhood) and obviously the function we're calling is somewhere near the start of the ROM (definitely not 20 bytes), so the only good way to get to it is to use bx. However, bx doesn't have a return, because it doesn't write anything to the lr. So we use this convention of bl to a bx, because bl overwrites the current lr value. So that way once the subroutine we call ends, it will go back to where the lr is pointing. However, it's important to note that bl overwrites lr without preserving it, so to make sure you're not messing anything up, push {lr} before doing any links, unless you know what you're doing :D

    To answer your question, you're not loading the flag number into lr, you're going to be loading the flag number into r0, then doing the aforementioned method to link to the flag checker subroutine. That routine would, again by definition, return 0 or 1 in r0. So after your link, you would simply check r0.

    Hopefully that made sense, I'm not very good at explaining.
     

    Joexv

    ManMadeOfGouda joexv.github.io
    1,037
    Posts
    11
    Years
  • The flag checking function is a subroutine. If you're familiar with other programming languages they call things like these "functions" or sometimes "methods'.

    Anyways, the flag checker function has a parameter which is the flag number. By definition, this parameter would be in r0. So you would just load into r0 your flag's number and then call the flag checker function.

    The process of how we're "calling" the subroutine is a little harder to understand. It's a clever trick having to do with manipulation of the Stack. You see, bl is limited to within approximately 20 bytes (I don't recall the exact amount, but around that neighborhood) and obviously the function we're calling is somewhere near the start of the ROM (definitely not 20 bytes), so the only good way to get to it is to use bx. However, bx doesn't have a return, because it doesn't write anything to the lr. So we use this convention of bl to a bx, because bl overwrites the current lr value. So that way once the subroutine we call ends, it will go back to where the lr is pointing. However, it's important to note that bl overwrites lr without preserving it, so to make sure you're not messing anything up, push {lr} before doing any links, unless you know what you're doing :D

    To answer your question, you're not loading the flag number into lr, you're going to be loading the flag number into r0, then doing the aforementioned method to link to the flag checker subroutine. That routine would, again by definition, return 0 or 1 in r0. So after your link, you would simply check r0.

    Hopefully that made sense, I'm not very good at explaining.

    OK that makes slightly more sense... but I'm still confused as to how im loading the flag number and value.
    I understand that ldr reads so it would require that. But a way that i've learned helps me learn is to examine premade code. And looking at yours
    Code:
    main
    	push {r0-r4}
    	mov r0, #0xBF @flag to check divided by 4
    	lsl r0, r0, #0x2
    	ldr r1, =(0x806E6D0 +1)
    	bl linker
    	cmp r0, #0x0
    	beq noCrash
    	ldr r4, .table
    Im having troubles understanding it. How does it get where the flag is stored and the value? And how does it check it?
     

    Blah

    Free supporter
    1,924
    Posts
    11
    Years
  • OK that makes slightly more sense... but I'm still confused as to how im loading the flag number and value.
    I understand that ldr reads so it would require that. But a way that i've learned helps me learn is to examine premade code. And looking at yours
    Code:
    main
    	push {r0-r4}
    	mov r0, #0xBF @flag to check divided by 4
    	lsl r0, r0, #0x2
    	ldr r1, =(0x806E6D0 +1)
    	bl linker
    	cmp r0, #0x0
    	beq noCrash
    	ldr r4, .table
    Im having troubles understanding it. How does it get where the flag is stored and the value? And how does it check it?

    0x806E6D0 that's the function for reading the flag. It does everything internally including finding/checking and simply returns a 0 or 1 (unset or set) in r0.
     

    Joexv

    ManMadeOfGouda joexv.github.io
    1,037
    Posts
    11
    Years
  • 0x806E6D0 that's the function for reading the flag. It does everything internally including finding/checking and simply returns a 0 or 1 (unset or set) in r0.

    Ohhh.. Ok.
    So inorder to check a new flag it would be
    Code:
    	push {r0-r4}
    	mov r0, #0x40
    	lsl r0, r0, #0x2
    	ldr r1, =(0x806E6D0 +1)
    	cmp r0, #0x0
    To check flag 0x160 right?
    If so how then would I stop the script if its not set?
    Would it be?
    Code:
    beq noscript @wheres noscript is another hunk a code
     

    Blah

    Free supporter
    1,924
    Posts
    11
    Years
  • Ohhh.. Ok.
    So inorder to check a new flag it would be
    Code:
    	push {r0-r4}
    	mov r0, #0x40
    	lsl r0, r0, #0x2
    	ldr r1, =(0x806E6D0 +1)
    	cmp r0, #0x0
    To check flag 0x160 right?
    If so how then would I stop the script if its not set?
    Would it be?
    Code:
    beq noscript @wheres noscript is another hunk a code

    Actually you need a linker still. All you've done is load into r1 a pointer. Now to go to that pointer, you need bx r1. Though like I said that doesn't write anything to the lr so you don't have a return spot. To fix this we had the "bl linker".
     

    Joexv

    ManMadeOfGouda joexv.github.io
    1,037
    Posts
    11
    Years
  • Actually you need a linker still. All you've done is load into r1 a pointer. Now to go to that pointer, you need bx r1. Though like I said that doesn't write anything to the lr so you don't have a return spot. To fix this we had the "bl linker".
    OK so to add a flag to the white out routine it would be:
    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    main:	
    	push {r0-r3, lr}
           mov r2, #0xBF @flag to check divided by 4
    	lsl r2, r2, #0x2
    	ldr r3, =(0x806E6D0 +1)
    	bl linker
    	cmp r2, #0x0
    	ldr r0, =(0x2023E8A)
    	ldrb r1, [r0]
    	cmp r1, #0x1
    	bhi setZero
    	b end
    
    linker:
    	bx r3
    	
    
    setZero:
    	cmp r1, #0x5
    	beq end
    	mov r1, #0x0
    	strb r1, [r0]
    
    end:
    	pop {r0-r1, pc}
    Correct? Sorry about asking so many questions this is really confusing...
     

    Blah

    Free supporter
    1,924
    Posts
    11
    Years
  • OK so to add a flag to the white out routine it would be:
    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    main:	
    	push {r0-r3, lr}
           mov r2, #0xBF @flag to check divided by 4
    	lsl r2, r2, #0x2
    	ldr r3, =(0x806E6D0 +1)
    	bl linker
    	cmp r2, #0x0
    	ldr r0, =(0x2023E8A)
    	ldrb r1, [r0]
    	cmp r1, #0x1
    	bhi setZero
    	b end
    
    linker:
    	bx r3
    	
    
    setZero:
    	cmp r1, #0x5
    	beq end
    	mov r1, #0x0
    	strb r1, [r0]
    
    end:
    	pop {r0-r1, pc}
    Correct? Sorry about asking so many questions this is really confusing...

    No there's a lot more wrong now. I'll just fix it for you and you can see what's wrong for yourself.

    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    main:	
    	push {r0-r3, lr}
            mov r0, #0xBF @flag to check divided by 4
    	lsl r0, r0, #0x2
    	ldr r3, =(0x806E6D0 +1)
    	bl linker
    	cmp r0, #0x0 @with flag magic you don't need this cmp even, but nvm that
    	beq end
    	ldr r0, =(0x2023E8A)
    	ldrb r1, [r0]
    	cmp r1, #0x1
    	ble end
    
    setZero:
    	cmp r1, #0x5
    	beq end
    	mov r1, #0x0
    	strb r1, [r0]
    
    end:
    	pop {r0-r3, pc}
    
    linker:
    	bx r3

    You can owe me back with a ROM base with all the Pokemon, moves and abilities inserted.
     

    Red John

    Progressing Assembly hacker
    137
    Posts
    10
    Years
  • I do not know whether this should be here but...well Mr. FBI Agent posted a silent evolution code in his thread. Well i am learning the way of third generation battle mechanism and found a way to call a ASM in battle. So, my question is that if i adjust the party slot value in the variable and then call the ASM 1, would it change anything?
     

    TheRabbit

    Banned
    69
    Posts
    9
    Years
    • Seen Jan 1, 2015
    I posted this in the ASM resource thread but didn't get an answer.

    Does anyone know of an ASM routine where I can change which events give you a trainer star in FR? Or if this requires ASM at all?
     

    Blah

    Free supporter
    1,924
    Posts
    11
    Years
  • I posted this in the ASM resource thread but didn't get an answer.

    Does anyone know of an ASM routine where I can change which events give you a trainer star in FR? Or if this requires ASM at all?

    Someone did answer it actually. The stickers in your card are determined by a few variables being certain values. Take a look at the script at 0x1B2938, and play around with the non-temporary variables in that script.

    I do not know whether this should be here but...well Mr. FBI Agent posted a silent evolution code in his thread. Well i am learning the way of third generation battle mechanism and found a way to call a ASM in battle. So, my question is that if i adjust the party slot value in the variable and then call the ASM 1, would it change anything?

    Yeah, it would evolve your Pokemon. It's not that simple though. The sprite isn't updated, so you will need to update the sprite in battle yourself.
     

    TheRabbit

    Banned
    69
    Posts
    9
    Years
    • Seen Jan 1, 2015
    Someone did answer it actually. The stickers in your card are determined by a few variables being certain values. Take a look at the script at 0x1B2938, and play around with the non-temporary variables in that script.

    I'm not talking about stickers though. That script isn't related to the Dodrio game, or completing the pokedex. Those are just the random dumb stickers you get for hatching a certain amount of eggs and stuff. I'm referring to the events that add a star to your card and completely change the color.
     
    794
    Posts
    10
    Years
  • Hello, I don't quite understand something about certain routine. It's KDS's Wide Lens(FR) routine. Here's the code:
    Spoiler:


    So the first thing is "At 1E050: 00 4A 10 47 XX+1 XX XX 08". Does it mean that if I inserted the code into, say 0078D540, I'm supposed to go to the offset "1E050" and change the XX bytes to "79(because 78+1?) D5 40"?

    Another thing is that "mystery byte". I'm supposed to change the "0xZZ" in the code to...what exactly? I'm thinking about indices of items. For example there's a ??????? item with the index 112 (70 in hex). So I put 0x70 and everything's fine?

    The last thing I'm confused is where exactly is this item. Is it in the place of the ??????? item that I was talking about before? Or do I have to do something else to place it there?

    I'd be very glad if someone could explain this to me. Thanks in advance.
     

    daniilS

    busy trying to do stuff not done yet
    409
    Posts
    10
    Years
    • Seen Jan 29, 2024
    Hello, I don't quite understand something about certain routine. It's KDS's Wide Lens(FR) routine. Here's the code:
    Spoiler:


    So the first thing is "At 1E050: 00 4A 10 47 XX+1 XX XX 08". Does it mean that if I inserted the code into, say 0078D540, I'm supposed to go to the offset "1E050" and change the XX bytes to "79(because 78+1?) D5 40"?
    You'd have to reverse the bytes, making 41 D5 78.

    Another thing is that "mystery byte". I'm supposed to change the "0xZZ" in the code to...what exactly? I'm thinking about indices of items. For example there's a ??????? item with the index 112 (70 in hex). So I put 0x70 and everything's fine?
    I think you have to change the item's mystery byte with an item editor and change ZZ to what you put there.

    The last thing I'm confused is where exactly is this item. Is it in the place of the ??????? item that I was talking about before?
    Yes.
    Or do I have to do something else to place it there?
    Yes, you have to change the item's mystery byte like I said.

    I'd be very glad if someone could explain this to me. Thanks in advance.

    Replies are in bold.
     
    794
    Posts
    10
    Years
  • Hello, I've got another problem and I still don't understand basic things. Help would be appreciated.
    So, I tried to insert [S-HIGHLIGHT]this routine[/S-HIGHLIGHT]. Now, the routine consists of two parts. I inserted the first one, the item check routine, to offset 0x78D310. However I had some trouble with the other one. Here's the code
    Spoiler:


    The first thing is
    #0x4A @change this number to your desired held item effect number.
    I tried many item editors, but there's no such thing as "effect number". There's mystery bytes, index, special, but no effect number. So, my question is what do I write here?

    Another thing is that the author of the routine wrote
    If you look closely, you'll notice .routine: .word 0x08800001 in every one of the rock routines(there were 4, I chose heat rock one). Change the address to the address you inserted your first routine (the item check routine) at.
    I thought I knew what I should do however I was wrong.
    .routine: .word 0x08800001
    The problem is my offset was 0x78D310. And that would mean that there's one digit missing. So, my second question is how do I write the offset here. Do I write it "0x8myoffset" or "0xmyoffset"? Oh and also do I reverse the order or is reversing only necessary to pointers?

    There's something else. Let's assume I inserted both routines. Where is this item? Does the place depend on the "effect number"? Also, what's the index of this new item? How would I give it to player if I don't know the index? Besides, do I have to write a script to make this item work or is it unnecessary?
     
    Status
    Not open for further replies.
    Back
    Top