Advertisement
FoxCunning

Healing Routines

Feb 4th, 2021
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *=$D804
  2. CastHEAL2:
  3.   JSR Heal2Amount
  4. ; Store low byte
  5.   PHA
  6. ; Store high byte
  7.   TYA
  8.   PHA
  9.  
  10.   LDA #$28
  11.   JSR ChoosePartyMember
  12.  
  13. ; $30 = high byte
  14.   PLA
  15.   STA $30
  16.  
  17. ; A = low byte
  18.   PLA
  19.  
  20.   BCS $D818
  21.  
  22.   JSR HealPartyMember_16bit
  23.   LDA #$00
  24.   RTS
  25.  
  26. ; $99, $9A = Caster in RAM
  27. ; Returns Random(0 to WIS) + (Level * 2)
  28. *=$BF40
  29. HealAmount:
  30.   LDY #$33      ; Level
  31.   LDA ($99),Y
  32.   ASL A         ; * 2
  33.   STA $30
  34.   LDY #$0A      ; WIS
  35.   LDA ($99),Y
  36.   JSR RNG
  37.   CLC
  38.   ADC $30
  39.   RTS
  40.  
  41. ; $99, $9A = Caster in RAM
  42. ; Returns Random(0 to WIS*2) + (Level*2)
  43. ; Banks 0 and 6
  44. *=$BF56
  45. Heal2Amount:
  46. ; $B8 = Random(0 to WIS * 2)
  47.   LDY #$0A
  48.   LDA ($99),Y
  49.   ASL A
  50.   JSR RNG
  51.  
  52. ; Add Caster Level * 2
  53.   LDY #$33
  54.   LDA ($99),Y
  55.   ASL A
  56.   CLC
  57.   ADC $B8
  58.  
  59. ; X = low byte
  60.   ADC #$64  ; Base heal amount
  61.   TAX
  62.  
  63. ; A = high byte
  64.   LDA #$00
  65.   ADC #$00
  66.  
  67. ; But we need to return the low byte in A...
  68.   TAY   ; Y = high byte
  69.   TXA   ; A = low byte
  70.  
  71.   RTS
  72.  
  73. ; A = Amount to heal (low byte)
  74. ; *NEW* 16-bit version: $30 = Amount to heal (high byte)
  75. ; ($99) = Pointer to character being healed
  76.  
  77. ; ------------------------
  78. ;       OLD CODE
  79. ; ------------------------
  80. *=$DAC0
  81. HealPartyMember:
  82.     STA $30
  83.     LDY #$2D        ; Current HP (low byte)
  84.     LDA ($99),Y
  85.     CLC
  86.     ADC $30
  87.     STA $2D         ; NEW_HP (low byte)
  88.     INY             ; Current HP (high byte)
  89.     LDA ($99),Y
  90.     ADC #$00
  91.     STA $2E         ; NEW_HP (high byte)
  92.  
  93. ; ------------------------
  94. ;       NEW CODE
  95. ; ------------------------
  96. *=$DAC0
  97. HealPartyMember:
  98.     LDY #$00
  99.  
  100. ;*=$DAC2
  101. ; A = low byte
  102. ; Y = high byte
  103. HealPartyMember_16bit:
  104.     STY $30
  105.  
  106.     CLC
  107.     LDY #$2D        ; Current HP (low byte)
  108.     ADC ($99),Y
  109.     STA $2D
  110.    
  111.     INY             ; Current HP (high byte)
  112.     LDA ($99),Y
  113.     ADC $30
  114.     STA $2E
  115.  
  116. ; Check if NEW_HP exceeds MAX_HP
  117.     LDY #$37        ; Max HP (high byte)
  118.     CMP ($99),Y
  119.     BCC _not_exceeded
  120.     BNE _set_max
  121.  
  122. ; High byte of NEW_HP exceeds high byte of MAX_HP: check low byte
  123.     LDA $2D
  124.     DEY
  125.     CMP ($99),Y
  126.     BCC _not_exceeded
  127.  
  128. _set_max:
  129. ; NEW_HP > MAX_HP, so we set NEW_HP = MAX_HP
  130.     LDY #$36        ; Max HP (
  131.     LDA ($99),Y
  132.     STA $2D
  133.     INY
  134.     LDA ($99),Y
  135.     STA $2E
  136.  
  137. ; ------------------------
  138. ;       OLD CODE
  139. ; 22 bytes
  140. ; ------------------------
  141. _not_exceeded:
  142. ; Calculate the amount healed with 16-bit subtraction NEW_HP - CUR_HP
  143. ; At the same time set CUR_HP = NEW_HP
  144.     LDY #$2D
  145.     LDA $2D         ; NEW_HP low byte
  146.     SEC
  147.     SBC ($99),Y     ; OLD_HP low byte
  148.     STA $A0         ; Difference low byte
  149.    
  150.     LDA $2D         ; Store NEW_HP low byte
  151.     STA ($99),Y
  152.     INY
  153.     LDA $2E         ; Store NEW_HP high byte
  154.     STA ($99),Y
  155.    
  156.     LDA #$00        ; Doesn't bother with difference high byte...
  157.     STA $A1
  158.  
  159. ; ------------------------
  160. ;       NEW CODE
  161. ; 22 bytes
  162. ; ------------------------
  163. _not_exceeded:
  164.     LDY #$2D
  165.     LAX $2D         ; NEW_HP low byte
  166.     SEC
  167.     SBC ($99),Y     ; OLD_HP low byte
  168.     STA $A0         ; Difference low byte
  169.     TXA
  170.     STA ($99),Y     ; Store NEW_HP low byte
  171.    
  172.     INY
  173.     LAX $2E         ; NEW_HP high byte
  174.     SBC ($99),Y     ; OLD_HP high byte
  175.     STA $A1         ; Difference low byte
  176.     TXA
  177.     STA ($99),Y     ; Store NEW_HP low byte
  178.    
  179. ; ------------------------
  180.     LDA _PPUMask    ; Skip the dialogue if rendering is disabled
  181.     BEQ _end
  182.    
  183.     LDA #$5A
  184.     STA $30
  185.     JMP CallTalkDialogue
  186.  
  187. _end:
  188.     RTS
  189.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement