The PokéCommunity Forums Fan Games ROM Hacking
ASM & Hex Current HP Check

ROM Hacking Need a helping hand? You can get help on any ROM Hacking-related problems or questions you have here.


Reply
 
Thread Tools
  #1    
Old 1 Week Ago (5:42 AM).
Lance Koijer 2.0 Lance Koijer 2.0 is offline
Lance Koijer
     
    Join Date: Apr 2018
    Location: Criscanto Town
    Gender: Male
    Nature: Adamant
    Posts: 11
    Hello guys..

    I am trying to code an ASM that checks if the current HP is lower or equal to the Half of the 1st Party Pokémon's Total HP.

    I have thought how to get the half in an ASM but the problem I have encountered is the byte indicator is not writing in the loaded address..

    here's the code:
    Code:
    .text
    .align 2
    .thumb
    .thumb_func
    
    
    main:
    	push {r0-r3, lr}
    	ldr r0, =(0x20242Dc) @loads the Total HP
    	ldrb r0, [r0]
    	ldr r1, =(0x20242Da) @loads the current hp
    	ldrb r1, [r1]
    	mov r2, #0x5 @multiplies to 5 to get the half 
    	mul r0, r2, r0 @gets the half of Total HP
    	mov r3, #0xA @moves one decimal to current HP
    	mul r1, r3, r1 @gets the value of Current HP
    	cmp r1, r0 @compares if Current HP is higher than Half of the total HP
    	bhi push2
    	ldr r1, =(0x203c1b4) @freespace
    	mov r0, #0x1
    	strb r1, [r0]	 @stores byte 1 to indicate that the Current HP is lower than or equal the half of total HP
    	pop {r0-r3, pc}	
    
    
    push2:
    	ldr r1, =(0x203c1b4)
    	mov r0, #0x0
    	strb r1, [r0] @stores byte 0 to indicate that the Current HP is higher than the half of total HP
    	pop {r0-r3, pc}
    it feels to me that it's either the storing of the byte or the branch checking makes the code not functioning. If someone can help me fix this, it is much appreciated. Thanks.
    Reply With Quote

    Relevant Advertising!

      #2    
    Old 1 Week Ago (7:03 AM). Edited 1 Week Ago by Koople.
    Koople Koople is offline
       
      Join Date: Nov 2016
      Nature: Sassy
      Posts: 29
      Quote:
      Originally Posted by Lance Koijer 2.0 View Post
      Hello guys..

      I am trying to code an ASM that checks if the current HP is lower or equal to the Half of the 1st Party Pokémon's Total HP.

      I have thought how to get the half in an ASM but the problem I have encountered is the byte indicator is not writing in the loaded address..

      here's the code:
      Code:
      .text
      .align 2
      .thumb
      .thumb_func
      
      
      main:
      	push {r0-r3, lr}
      	ldr r0, =(0x20242Dc) @loads the Total HP
      	ldrb r0, [r0]
      	ldr r1, =(0x20242Da) @loads the current hp
      	ldrb r1, [r1]
      	mov r2, #0x5 @multiplies to 5 to get the half 
      	mul r0, r2, r0 @gets the half of Total HP
      	mov r3, #0xA @moves one decimal to current HP
      	mul r1, r3, r1 @gets the value of Current HP
      	cmp r1, r0 @compares if Current HP is higher than Half of the total HP
      	bhi push2
      	ldr r1, =(0x203c1b4) @freespace
      	mov r0, #0x1
      	strb r1, [r0]	 @stores byte 1 to indicate that the Current HP is lower than or equal the half of total HP
      	pop {r0-r3, pc}	
      
      
      push2:
      	ldr r1, =(0x203c1b4)
      	mov r0, #0x0
      	strb r1, [r0] @stores byte 0 to indicate that the Current HP is higher than the half of total HP
      	pop {r0-r3, pc}
      it feels to me that it's either the storing of the byte or the branch checking makes the code not functioning. If someone can help me fix this, it is much appreciated. Thanks.
      A couple notes:
      - The current/total HP are halfwords (2 bytes), so you should be using ldrh
      - you should use a right shift to divide by 2 (lsr rX, rX, #0x1)
      - you're storing r1 into r0. So you are storing the address into address 0x0 or 0x1. You should do strb r0, [r1] to store the value of r0 into the address of r1
      - EDIT: and rather than using some free ram, you might want to store into a temporary variable such as the lastresult variable at 0x020370d0

      Hope this helps :)
      Reply With Quote
        #3    
      Old 1 Week Ago (5:01 PM).
      Lance Koijer 2.0 Lance Koijer 2.0 is offline
      Lance Koijer
         
        Join Date: Apr 2018
        Location: Criscanto Town
        Gender: Male
        Nature: Adamant
        Posts: 11
        Quote:
        Originally Posted by Koople View Post
        A couple notes:
        - The current/total HP are halfwords (2 bytes), so you should be using ldrh
        - you should use a right shift to divide by 2 (lsr rX, rX, #0x1)
        - you're storing r1 into r0. So you are storing the address into address 0x0 or 0x1. You should do strb r0, [r1] to store the value of r0 into the address of r1
        - EDIT: and rather than using some free ram, you might want to store into a temporary variable such as the lastresult variable at 0x020370d0

        Hope this helps :)
        Thanks for the response. Very.

        I'll gonna try that.
        Reply With Quote
          #4    
        Old 6 Days Ago (7:27 AM).
        FBI's Avatar
        FBI FBI is offline
        Free supporter
         
        Join Date: Jan 2013
        Location: Unknown Island
        Gender: Male
        Posts: 1,848
        Well, that’s the most complicated solution to checking if a number is double. I’d optimize that portion of it, and also generalize this into an easy to call function.

        Quote:
        push {lr}
        mov r3, #100
        mul r3, r3, r0
        ldr r0, totalhp
        add r0, r0, r3
        ldrh r1, [r0, #2]
        ldrh r0, [r0]

        do calc
        This would require a small wrapper to call it from a script properly, but it’d be worth it to get rid of the hard coded portions.
        __________________
        ...
        Reply With Quote
          #5    
        Old 5 Days Ago (7:48 PM).
        Lance Koijer 2.0 Lance Koijer 2.0 is offline
        Lance Koijer
           
          Join Date: Apr 2018
          Location: Criscanto Town
          Gender: Male
          Nature: Adamant
          Posts: 11
          Quote:
          Originally Posted by FBI View Post
          Well, that’s the most complicated solution to checking if a number is double. I’d optimize that portion of it, and also generalize this into an easy to call function.



          This would require a small wrapper to call it from a script properly, but it’d be worth it to get rid of the hard coded portions.
          Sweet. Thanks for this.
          Reply With Quote
          Reply

          Quick Reply

          Join the conversation!

          Create an account to post a reply in this thread, participate in other discussions, and more!

          Create a PokéCommunity Account

          Sponsored Links
          Thread Tools

          Posting Rules
          You may not post new threads
          You may not post replies
          You may not post attachments
          You may not edit your posts

          BB code is On
          Smilies are On
          [IMG] code is On
          HTML code is Off

          Forum Jump


          All times are GMT -8. The time now is 11:27 PM.