seibaby

Code repository for 1.10.0

15 posts in this topic

This thread is for the devs. There are a lot of assembly patches going into 1.10.0, let's collect them all in one place.

@BTB@Synchysi

 

TASKS:

@seibaby

New status screen - WIP
Encounter Rate - DONE
Reflect Timer - DONE
Melee Counter - DONE
MP low counter - DONE
Runic ignores Clear - DONE
N. Cross rebalance - DONE
Mind blast mod - DONE
Tank & Spank 1.0 - DONE
ATB colors - DONE
Quake/Vanish Fix - DONE

@darknil
Status Display Update - WIP
Doomstick Bugfix - WIP
??? Update - WIP

Relics Block Stop - DONE
Shop Preview - DONE
Spell Dot Display - DONE

@GrayShadows
Weapon Swap in Combat - WIP/TENTATIVE
Max HP/ATB toggle - DONE
Inventory Index Fix - DONE

@Think0028
Defend/Row 1/2 Turn - WIP
Row Targeting Preference - ABANDONED
EsperXP Display Bugfix - WIP
Elemental Mixing - DONE

@madsiur
Mind Blast Speed Hack - ???
SrBehemoth OpCode Update - DONE
Aero Speed Hack - DONE

@Gi Nattak
Booty Fix - DONE

Just clarifying:  this isn’t a discussion thread so any non dev post stuff will be purged. - Mish

Edited by seibaby
4

Share this post


Link to post
Share on other sites

Melee Counter - DONE

 

 

	; New parameters for FC 05 - Melee counter and MP damage counter
	; AI Script commands:
; FC 05 00 00 = counterattack all damage, as usual
; FC 05 00 01 = counterattack ONLY damage that's both physical and row-respecting
; FC 05 00 02 = counterattack ONLY MP damage
	hirom
;header
!freespace = $C23C61        ; Requires 5 bytes of free space in C2
!freespacelong = $C3F577    ; Requires 66 bytes of free space anywhere
	; Preparation:
; Hook functon C2/35E3 (Initialize several variables for counterattack purposes)
org $C235E9
      JSL initAttackVars  ; (initialize new var $327D,index containing bitflags for
                          ;  physical damage, respects row, and MP damage in bit 0,
                          ;  bit 5, and bit 7 respectively)
      macro initAttackVars()
      initAttackVars:
      TXA                            ; (displaced code)
      STA $3290,Y              ; (displaced code)
      LDA $B3                  ; If Bit 5 is set it ignores attacker row
      EOR #$FF                 ; Invert it so bit 5 is set if melee
      LSR                      ; Shift it to bit 4
      ORA $11A7                ; Merge with bit 4 of $11A7 ("respects row")
      AND #$10                  ; Isolate bit 4 (1 = respects row)
      PHA        
      LDA $11A2                  ; Bit 0 = physical damage if set
      LSR                   ; Carry = 1 if physical damage
      PLA        
      ROL                   ; Bit 1 = physical
                          ; Bit 5 = melee
      ASL                   ; Shift again
      PHA        
      LDA $11A3        
      ROL                            ; Carry = 1 if affects MP
      PLA        
      ROR                            ; A: bit 1 = physical damage
                        ;    bit 5 = melee attack
                        ;    bit 7 = affects MP    
                        ; (all other bits are 0)
      STA $327D,Y                ; Save attack properties to unused var $327D,index
.exit    RTL
      endmacro
        
; Execution:
; FC command $05 (Counter if damaged)
org $C21C70
doCounter:                    ; (vanilla FC 05 code)
	; Redirect pointer for FC command $05 to new code
org $C21D5F
      dw checkParams
	org !freespace
checkParams:
      JML checkParamsLong
      macro checkParamsLong()
      checkParamsLong:
      LDA $3A2F            ; Script command byte 4
      LSR                    ; Check if it's 1 (melee counter)
      BCS .melee        
      LSR                    ; Check if it's 2 (MP damage counter)
      BCC .omni            ; If not set, it's a normal counter
      LDA $327D,Y        
      CMP #$80            ; Check if attack affects MP
      BNE .exit            ; Exit if not
      BRA .omni            ; Counter if attack affects MP
                
.melee    LDA $327D,Y            ; Attack properties
      CMP #$21            ; Check respect row, physical
      BNE .exit            ; Exit if not both are set
.omni    JML doCounter
.exit    JML noCounter
      endmacro
noCounter:
      RTS
    
org !freespacelong
reset bytes
%initAttackVars()
%checkParamsLong()
print "New code requires ",bytes," bytes of free space anywhere"
Edited by seibaby
0

Share this post


Link to post
Share on other sites

MP low counter - DONE
 

 

	; HP/MP low counter redesign
; By Seibaby
	; FC command $06 (HP low counter) normally checks HP versus <parameter> * 128 while
; FC command $07 (MP low counter) checks MP versus <param> only. This makes it so that
; MP is compared to <param> * 128 as well.
	hirom
;header
	; FC command $06 (HP low counter)
org $C21D61
dw mpLowCounter
	
; FC command $07 (MP low counter)
org $C21D63
dw mpLowCounter
	org $C21BB7
mpLowCounter:
        JSR $1D34
        BCC .exit
	        TDC
        LDA $3A2F
        XBA
        REP #$20
        LSR
	        CPX #$0E     ; is it command $07 - MP low counter?
        BCC .hp     ; branch if it's not (ie. it's $06 - HP low counter)
        CMP $3C08,Y ; MP
        BRA .exit
.hp        CMP $3BF4,Y ; HP
.exit    RTS
        padbyte $FF : pad $C21BD6
        warnpc $C21BD7
Edited by seibaby
0

Share this post


Link to post
Share on other sites

Runic ignores Clear - DONE
 

 

	; Set Runicked attacks to Ignore Clear
	org $C2357E
LDA #$2182
STA $11A3      ;Set just concern MP, not reflectable, Unblockable, Heal
LDA #$8040
TRB $B2        ;Flag little Runic sword animation, set Ignore Clear
SEP #$20       ;Set 8-bit Accumulator
LDA #$60
STA $11A2      ;Set just ignore defense, no split damage
TDC            ;need top half of A clear
LDA $11A5      ;MP cost of spell
JSR $4792      ;divide by X
STA $11A6      ;save as Battle Power
JSR $385E      ;Sets level, magic power to 0
JSR $2A0F      ;(some runic patch hook?)
LDA #$04       ; A = 4
STA $BA        ;Don't retarget if target invalid
DEC A          ; A = 3   
	
Edited by seibaby
0

Share this post


Link to post
Share on other sites

N. Cross rebalance - DONE
 

 

	hirom
;header
!freespace = $C2661B
	; N. Cross (Special effect $29)
; One or two targets will be picked randomly
org $C2414D
C2414D: REP #$20       ; Set 16-bit A
C2414F: LDA $A4        ; Targets
C24151: PHA            ; Save targets
C24152: JSR $522A      ; Randomly pick an entity from among the targets
C24155: JMP morecode
	org !freespace
morecode:
        STA $A4        ; Save new target
        PLA            ; Get original targets again
        JSR $522A      ; Pick one at random
        TSB $A4        ; Save new target(s)
        SEP #$20       ; Set 8-bit A
        RTS
	
Edited by seibaby
0

Share this post


Link to post
Share on other sites

Mind blast mod - DONE

 

	;BNW Mind Blast tweak
	hirom
;header
!freespace = $C25141   ; free space in 1.9...I think
	; Loop 5 times for Mind Blast
org $C2413E
LDY #$08
	org $C23BB8
LDX #$08
	org $C23BC1
JSR checkStam        ; Check Stamina before attempting to set status
	
org !freespace
checkStam:
SEP #$20
JSR $23B2            ; Check if Stamina blocks
REP #$20            
BCS .exit            ; Exit if so
JMP $3BD0            ; Randomly mark a status from attack data to be set
.exit
RTS
	 
	
Edited by seibaby
0

Share this post


Link to post
Share on other sites

Tank & Spank 1.0 - DONE

	
;Tank & Spank (previously Cover Knight and Smart Cover)
;by Seibaby
	;v1.0 - Only allows back row targets for Stamina-based cover
;       Disables Cover when Dancing
;v0.9 - Disables Interceptor and halves Evasion when Covering
;v0.7 - Fixes a bug where Knight wouldn't reset Defending stance when Covering
;v0.6 - New Smart Cover logic
;       Some Cover nerfs
;v0.5 - Fixes an issue with Knights not taking targets' statuses into
;       account (Image and Clear, but also Zombie and Petrify)
;v0.4 - Fixes a bug causing Knights to Cover monsters attacking other
;       monsters
;v0.3 - Adds an exception to not trigger Cover if the Knight is Near Fatal
;       and the target is healthy.
;v0.2 - Fixes a bug that caused the wrong statuses (on the target) to be
;       considered for whether or not to disable True Knight.
	;Changes the True Knight effect to trigger with a Stamina / 192 chance even if
;the target isn't in Near Fatal status.
	;New Smart Cover patch, which disables True Knight for all attacks
;originating from a player character, unless that character is uncontrollable,
;in which case it will only disable it if the attack comes from a healing weapon,
;or if the weapon is elemental and the target absorbs/nullifies that element.
;It also considers a few extra statuses for purposes of disabling True Knight.
;ON TARGET: Death, Petrify, Zombie, Magitek, and Image
;           (in addition to Clear)
;ON KNIGHT: Dark, Magitek, Image, Berserk
;           (in addition to Death, Petrify, Clear, Zombie, Sleep, and Muddled)
    
;xkas 0.06
hirom
;header
	!smartCover = $C2AE31       ;Requires 99 bytes of free space
;!halveEvade = $C10000       ;Requires 20 bytes of free space
;!noDogBlock = $C20000       ;Requires 9 bytes of free space
	;A few notes on the changes made to these functions:
;Entering this function, A is 16-bit and X/Y are 8-bit. Register width is
;never changed and the call following this function doesn't care about Carry,
;so I have removed a bunch of useless PHP/PLP and REP #$20 throughout, to make
;room for the new code.
;I have also removed some code related to monsters using True Knight, which was
;supported in vanilla, but unused (and remains so in BNW). The check for if the
;bodyguard was Controlled was also removed (doubly useless).
	org $C2123A
exit:
	;True Knight and Love Token
org $C2123B
trueKnightAndLoveToken:
        PHX
        LDA $B2
        BIT #$0002          ;Is "No critical and Ignore True Knight" set?
        BNE .exit           ;Exit if so
        LDA $B8             ;intended target(s).  to my knowledge, there's only
                            ;one intended target set if we call this function..
        JMP smartCover
        macro smartCover()
        print "Writing smartCover() to ",pc
        reset bytes
        smartCover:
        BEQ .exit           ;Exit if none
        LDY #$FF    
        STY $F4             ;default to no bodyguards.
        JSR $51F9           ;Y = index of our highest intended target.
                            ;0, 2, 4, or 6 for characters.  8, 10, 12, 14, 16,
                            ;or 18 for monsters.
        STY $F8             ;save target index
        STZ $F2             ;Highest Bodyguard HP So Far = 0.  this makes the
                            ;first eligible bodyguard we check get accepted.
                            ;later ones may replace him/her if they have more
                            ;HP.
        PHX     
        LDX $336C,Y         ;Love Token - which target takes damage for you
        BMI .noLove         ;Branch if none do
        JSR evalKnight_skip ;consider this target as a bodyguard (skip Stamina
                            ;and Near Fatal checks)
        JSR newTarget       ;if it was valid, make it intercept the attack  
.noLove PLX
        LDA $3A36
        BNE .exit           ;Exit if Golem is active
        CPX #$08            ;Check attacker
        BCS .status         ;Branch if attacker is a monster
        CPX $F8
        BEQ .exit           ;Exit if Attacker = Target
        LDA $3EE4,X         ;Attacker status byte 1-2
        BIT #$2002
        BNE .heals          ;Branch if Muddled or Zombied
        LDA $3394,X         ;Check if Attacker is Charmed
        BMI .exit           ;If not Muddled, Zombied, or Charmed, this
                            ;attack was initiated by the player, so exit
.heals  LDA $11A9           ;Special weapon property
        AND #$00FF          ;Isolate bottom byte
        CMP #$0018          ;Check "Curative Attributes"
        BEQ .exit           ;Exit if set
        SEP #$20         
        LDA $11A1           ;Attack element(s)
        PHA
        XBA
        PLA                 ;Copy to high byte
        REP #$20
        AND $3BCC,Y         ;Target absorbed/immune elements
        BNE .exit           ;If any absorbed or nullified, exit
.status LDA $3EE4,Y         ;Target status byte 1-2
        BIT #$04DA
        BNE .exit           ;Branch if Death, Petrify, Clear, Zombie, Magitek,
                            ;or Image
.seize  LDA $3358,Y         ;$3359 = who is Seizing you
        BPL .exit           ;Branch if target is seized
        LDA #$000F          ;Load all characters as potential bodyguards        
        JMP trueKnightAndLoveToken_cover
.exit   PLX
        RTS
        print "smartCover: ",bytes," bytes written, ending at ",pc
        endmacro
	.cover  CPY #$08
        BCC .saveBg         ;Branch if target is character
        TDC                 ;Null all potential bodyguards
.saveBg STA $F0             ;Save potential bodyguards
        LDA $3018,Y         ;bit representing target
        ORA $3018,X         ;bit representing attacker
        TRB $F0             ;Clear attacker and target from potential
                            ;bodyguards
        LDX #$12
.loop   LDA $3C57,X         ;High byte = Relic Effects 3
        ASL #2              ;Check bit 6 (True Knight)
        BCC .next           ;Branch if no True Knight effect                
        LDA $3018,X
        BIT $F0
        BEQ .next           ;Branch if this candidate isn't on the same
                            ;team as the target
        JSR evalKnight      ;consider them as candidate bodyguard.  if they're
                            ;valid and their HP is >= past valid candidates,
                            ;they become the new frontrunner.
.next   DEX
        DEX
        BPL .loop           ;Do for all characters and monsters
        LDA $F2
        BEQ .exit           ;Exit if no bodyguard found [or if the selfless
                            ;soul has 0 HP, which shouldn't be possible outside
                            ;of bugs].
        JSR newTarget       ;make chosen bodyguard -- provided there was one --
                            ;intercept attack.  if somebody's already been
                            ;slated to intercept it [i.e. due to Love Token],
                            ;the True Knight will sensibly defer to them.
.exit   PLX
        RTS
    
;Make chosen bodyguard intercept attack, provided one hasn't been marked to do
;so already.
    newTarget:
        LDX $F4
        BMI .exit           ;exit if no bodyguard found
        CPY $F8
        BNE .exit           ;exit if $F8 no longer points to the original
                            ;target, which means we've already assigned a
                            ;bodyguard with this function.
        STX $F8             ;save bodyguard's index
        STY $A8             ;save intended target's index
        LSR $A8             ;.. but for the latter, use 0,1,2,etc rather
                            ;than 0,2,4,etc
        LDA $3018,X
        STA $B8             ;save bodyguard as the new target of attack
        SEP #$20
        LDA $3AA1,X
        BIT #$02
        BEQ .noDef          ;Branch if not Defending
        JSR $0A41           ;Clear Defending flag
        JSR $0A3C           ;Relax Defending pose
.noDef  REP #$20
.exit   RTS
    
;Consider candidate bodyguard for True Knight or Love Token
evalKnight:
        LDA #$0020
        BIT $3AA1,X
        BNE .exit           ;Exit if guard is in back row
        LDA $3EE5,Y         ;Low byte = Status byte 2
        LSR #2              ;Check bit 1 (Near Fatal)
        BCS .skip           ;Skip Stamina check if target Near Fatal        
        LDA $3AA1,Y
        BIT #$0020
        BEQ .exit           ;Exit if target is in back row
        LDA $3EE5,X         ;Knight's Status byte 2
        LSR #2              ;Check Near Fatal
        BCS .exit           ;If Knight is Near Fatal, exit
        SEP #$20                
        LDA #$C0            ;192
        JSR $4B65           ;Random: 0 to 191
        CMP $3B40,X         ;Stamina
        REP #$20
        BCS .exit           ;Exit if Stamina was lower
.skip                       ;Love Token enters here
        LDA $3AA0,X
        LSR     
        BCC .exit           ;Exit function if entity not present in battle?
        LDA $3358,X         ;$3359 = who is Seizing you
        BPL .exit           ;Exit if you're Seized
        LDA $3EE4,X
        BIT #$B4DB          ;Death, Petrify, Clear, Zombie, Sleep, Muddled,
                            ;Dark, Magitek, Image, Berserk
        BNE .exit           ;Exit if any set
        LDA $3EF8,X     
        BIT #$3211          ;Dance, Stop, Freeze, Spell Chant, Hide
        BNE .exit           ;Exit if any set
        LDA $3018,X
        TSB $A6             ;make this potential guard jump in front of the
                            ;target, can accompany others
        LDA $3BF4,X         ;HP of this potential bodyguard
        CMP $F2         
        BCC .exit           ;branch if it's not >= the highest HP of the other
                            ;bodyguards considered so far for this attack.
        STA $F2             ;if it is, save this entity's HP as the highest
                            ;HP so far.
        STX $F4             ;and this entity becomes the new bodyguard.
.exit   RTS
	print "Cover function end: ",pc
print "Vanilla Cover ends: c212f4"
	;Check for Covered attacks in Hit Determination
;Disable Dog Block if attack was Covered
org $C22282
checkDogBlock:
        LDA $3EF9,Y
        ASL
        BPL C22293            ;Branch if not dog block
        JSR skipDogBlock
        macro skipDogBlock()
        print "Writing skipDogBlock() to ",pc
        reset bytes
        skipDogBlock:
        CPY $F4             ;Is target = bodyguard?
        BNE .exit           ;If not, return
        CLC                 ;Otherwise, set carry = 0, ie.
        RTS
.exit   JMP $4B53           ;Random: carry 0 or 1          
        print "skipDogBlock: ",bytes," bytes written, ending at ",pc
        endmacro
;        BCC C22293          ;50% chance
;        LDA #$40      
;        STA $FE             ;Set dog block animation flag
org $C22293
C22293:
	;Halve Evasion if attack was Covered
org $C22345
        JSR halveEvasion    ;Get Evade
        macro halveEvasion()
        print "Writing halveEvasion() to ",pc
        reset bytes
        halveEvasion:       ;Y = target of attack
        CPY $F4             ;Index of bodyguard ($FF if no bodyguard)
        BNE .exit           ;If not the same as target, exit
        LDA #$FF            ;255
        SEC
        SBC $3B54,Y         ;255 - (255 - Evade * 2 + 1)
                            ;(= Evade * 2 - 1)
        INC                 ;Evade * 2
        LSR                 ;Evade
        LSR                 ;Evade / 2
        JMP $2861           ;New blockvalue from halved Evade
.exit   LDA $3B54,Y         ;(255 - Evade * 2 + 1)
        RTS
        print "halveEvasion: ",bytes," bytes written, ending at ",pc
        endmacro
	org !smartCover
%smartCover()
;org !halveEvade
%halveEvasion()
;org !noDogBlock
%skipDogBlock()
	

0

Share this post


Link to post
Share on other sites

ATB colors - DONE

palettes-bnw.bin

 

	
; Time Magic affects the ATB bar colors
; By Seibaby 2018-09-23
	; It also changes the endcaps on the ATB bar based on whether ATB is full or not.
; This requires two new glyphs in the 8x8 font tileset (the two tiles immediately following
; the ATB endcaps, left and right). The endcaps are changed so that the uncharged ones don't
; use colors 2 or 4, just the grey and transparency. Then the charged endcaps use colors
; 4 (the brightest) and optionally color 2 like the vanilla endcaps did.
	 
	; Palette color order
;       0: transparency
;       1: Text Drop shadow / ATB gauge outline
;       2: Text Grey magic dot / ATB gauge border
;       3: Text / ATB gauge core
	; $2EAF01: Palette #1: $21 - White text
; $2EAF09: Palette #2: $25 - Grey text
; $2EAF11: Palette #3: $29 - Yellow text / Full ATB gauge
; $2EAF19: Palette #4: $2D - Blue
; $2EAF21: Palette #5: $31 - All black (???)
; $2EAF29: Palette #6: $35 - White (charging) ATB gauge
; $2EAF31: Palette #7: $39 - Green Morph gauge
; $2EAF39: Palette #8: $3D - Red Condemned gauge (unused)
	hirom
;header
	!freespace = $EEAF01
	; Add checks for statuses to ATB drawing routine
org $C16872
drawGauge:
         LDA $2021        ; ATB gauge setting
         LSR              ; Gauge enabled?
         BCC drawMaxHP    ; Branch if disabled
         LDA $3A8F        ; nATB: is ATB paused?
         LSR              ; (01 = paused)
         BCS .exit        ; Don't update bars while ATB is paused
         
         LDA $4E          ; Text color
         PHA              ; Save it
         LDA $18          ; Which character is it (0-3)
         TAX              ; Index it
         LDA $619E,X      ; Character's ATB gauge value
         PHA              ; Save it for later
         TXA              ; A = character 0-3
         ASL              ; Double it
         JSL newfunc
         macro newfunc()
         newfunc:
         TAX              ; Character index (0-6)
         LDA $3EF8,X      ; Status byte 3
         BIT #$10         ; Is Stop status set?
         BEQ .slow        ; Branch if not Stopped
         LDA #$3D         ; Select palette #8           STOPPED
         BRA .store       ; Store palette
.slow    LDA $3EF8,X      ; Status byte 3
         BIT #$04         ; Is Slow status set?
         BEQ .haste       ; Branch if not Slowed
         LDA #$2D         ; Select palette #4           SLOW
         BRA .store       ; Store palette
.haste   LDA $3EF8,X      ; Status byte 3
         BIT #$08         ; Is Haste status set?
         BEQ .normal      ; Branch if not Hasted
         LDA #$39         ; Select palette #7           HASTE
         BRA .store       ; Store palette
.normal  LDA #$35         ; Select palette #6           NORMAL
.store   RTL
         endmacro
         STA $4E          ; Store palette
         PLA              ; Restore ATB gauge value
         JSR $6854        ; Draw the gauge
         PLA              ; Get saved text color
         STA $4E          ; Store text color
.exit    RTS
         print "c1/6872 ends at: ", pc,", should be c16898"
	org $C16898
drawMaxHP:
LDA #$C0                  ; Draw a "/" as HP divider
	; Endcaps stuff
org $C16854
endcaps:
PHA
JSL newfunc2
	macro newfunc2()
newfunc2:
LSR A
AND #$FC
TAX
LDA $04,S
INC
BEQ .leftfull
LDA #$F9
BRA .drawleftcap
.leftfull
LDA #$FB
.drawleftcap
RTL
endmacro
	JSR $66F3      ; Draw opening end of ATB gauge
LDA #$04
STA $1A
.loop
LDA $C168AC,X  ; Get the ATB gauge character
JSR $66F3      ; Draw tile A
INX
DEC $1A        ; Decrement tiles to do
BNE .loop      ; Branch if we haven't done 4
PLA
JML newfunc3
macro newfunc3()
newfunc3:
INC
BEQ .rightfull
LDA #$FA
BRA .drawrightcap
.rightfull
LDA #$FC       ; Draw tail end of ATB gauge
.drawrightcap
JML $C166F3    ; Draw tile A
endmacro
NOP
print "c1/6854 ends at: ",pc,", should be c16872"
	
; Relocate 2bpp palettes
org !freespace
print "palettes written to ",pc
palettes:
incbin palettes-bnw.bin       ; Use SNESpal to edit the palettes
print "new code written to ", pc
%newfunc()
%newfunc2()
%newfunc3()
	org $C140A8
LDA palettes,X            ; Load battle text palettes white and gray
	org $C140AF
LDA palettes+16,X         ; Load battle text palettes yellow and cyan
	org $C14100
LDA palettes+40,X         ; Load battle gauge palette
	
Edited by seibaby
0

Share this post


Link to post
Share on other sites

stop immunity - reverses normal application effect with equipment. not thoroughly tested. may be buggy. also old. i made it years ago.

Spoiler

hirom

org $c228c6
jsr remove_stop_from_equip

org $c22914
jsr equip_invert_stop
bra skip_skip
padbyte $ea : pad $c2291f

org $c2291f
skip_skip:

org $c26610
remove_stop_from_equip:
and #$EF
sta $3c6d,x
rts

equip_invert_stop:
sta $3330,x
pha
sep #$20
lda $D4
and #$10
eor #$ff
sta $3330,x
rep #$20
pla
eor $d2                                    ; equipment immunities
sta $331c,x                                ; vulnerable to whatever equipment doesn't
                                        ; block in immunity bytes 1 and 2
rts

 

2

Share this post


Link to post
Share on other sites

This is the shop hack. It's a mess, and I think some unnecessary stuff is still in it.

Spoiler

hirom
table ff6_snes_menu_a.tbl,rtl

org $c388ce
ldx #$7B65
org $c388da
ldx #$7BE5
org $c388e6
ldx #$7C65
org $c388f2
ldx #$7CE5

org $C38D69
dw ele_resist
dw ele_absorb
dw ele_nullify
dw ele_weakness

org $c3baba
nop #3

org $c38746
;Fork: Draw offensive properties
C38746:    JSR $879C      ; Draw Bat.Pwr
        jsr gear_stats_evasion_attack_elements
        jsr load_item_index
        and #$80
        jsr check_text_color
        ldy #$8e30
        jsr process_text
        jsr load_item_index
        and #$40
        jsr check_text_color
        ldy #$8e38
        jsr process_text
        jsr load_item_index
        and #$02
        jsr check_text_color
        ldy #$8e26
        jsr process_text
        rts
padbyte $FF : pad $C38795
        
org $c3b4bd
        jsr handle_shop_stats
        rts
check_nmi:
        jsr $1368        ; NMI
        jsr $7fd9        ; draw name (from BAC9)
        rts
padbyte $FF : pad $c3b4e6

org $c3b8c4
        jsr clear_screen_bg2
        nop #6
        
org $C3B95a
        jsr clear_screen_bg3
C3B963:    JSR $BFD3      ; Draw title
C3B969:    LDY #$C338     ; Text pointer
C3B96C:    JSR $02F9      ; Draw "GP"
C3B96F:    JSR $C2F2      ; Color: User's
C3B972:    LDY $1860      ; Gold LBs
C3B975:    STY $F1        ; Memorize it
C3B977:    LDA $1862      ; Gold HB
C3B97A:    STA $F3        ; Memorize it
C3B97C:    JSR $0582      ; Turn into text
C3B97F:    LDX #$7A33     ; Text position
C3B982:    JSR $04AC      ; Draw GP total
C3B985:    RTS

org $c3b989
        ldy #help_text
        
org $c3bac9
        jsr check_nmi
        
org $c3bfd3
;draw shop title, define shop index
C3BFD3:    JSR $C2F7      ; Color: Blue
C3BFD6:    LDA $4212      ; PPU status
C3BFD9:    AND #$40       ; H-Blank?
C3BFDB:    BEQ C3BFD6      ; Loop if not
C3BFDD:    LDA $0201      ; Shop number
C3BFE0:    STA $211B      ; Set matrix A LB
C3BFE3:    STZ $211B      ; Clear HB
C3BFE6:    LDA #$09       ; Shop data size
C3BFE8:    STA $211C      ; Set matrix B
C3BFEB:    STA $211C      ; ...
C3BFEE:    LDX $2134      ; Index product
C3BFF1:    STX $67        ; Set shop index
C3BFF3:    LDA $C47AC0,X  ; Shop flags
C3BFF7:    AND #$07       ; Title number
C3BFF9:    ASL A          ; Double it
C3BFFA:    TAX            ; Index it
C3BFFB:    REP #$20       ; 16-bit A
C3BFFD:    LDA $C3C00C,X  ; Text pointer
C3C001:    STA $E7        ; Set src LBs
C3C003:    SEP #$20       ; 8-bit A
C3C005:    LDA #$C3       ; Bank: C3
C3C007:    STA $E9        ; Set src HB
C3C009:    JMP $02FF      ; Draw title

org $c3c037
        db $2f,$06,$00
org $c3c2e1
        jsr buy_menu_exp
org $c3f850
gear_stats_evasion_attack_elements:
C38749:    JSR $87EB      ; Draw evasions
        jsr $c2f7
C38750:    LDY #$8E1D     ; Text pointer
C38753:    JSR $02F9      ; Draw "Attack"
C38756:    jmp $88A0      ; Draw elements
        
check_text_color:
        beq grey_text_color
user_text_color:
        lda #$20        ; palette 0
        bra store_tcolor
grey_text_color:
        lda #$24        ; grey text
store_tcolor:
        sta $29            ; color: user's
        rts
        
load_item_index:
        ldx $2134        ; item index
        lda $d85013,x    ; byte to look at
        rts
        
process_text:
        sty $e7
        jsr $8795
        rts
        
clear_screen_bg2:
        jsr $6a28        ; clear bg2 map a
        jsr $6a2d        ; clear bg2 map b
        jsr $6a32        ; clear bg2 map c
        jsr $6a37        ; clear bg2 map d
        ldy #shop_gear_window
        jsr $0341        ; draw shop gear window
        ldy #shop_gear_window_actors
        jsr $0341        ; draw actors' window
        ldy #shop_gear_weapon_name
        jsr $0341
        ldy #shop_gear_description
        jsr $0341
clear_screen_bg3:
        jsr $6a3c        ; clear bg3 map a
        jsr $6a41        ; clear bg3 map b
        jsr $6a46        ; clear bg3 map c
        jsr $6a4b        ; clear bg3 map d
        rts
        
draw_title_dupe:
        
        jsr $02ff        ; draw title
handle_shop_stats:
handle_buy_item_list:
        lda #$10        ; reset/stop desc
        tsb $45            ; set menu flags
        jsr $0f39        ; queue text upload
        jsr $1368
        jsr $0f4d        ; queue text upload 2
        jsr $b8a6        ; handle d-pad
        jsr check_stats
        jsr $bc84        ; draw quantity owned
        jsr $bca8        ; draw quantity worn
;Handle hold Y
shop_handle_y:
        lda $0D
        bit #$40        ; holding Y?
        beq shop_handle_b ; branch if not
        rep #$20        ; 16-bit A
        lda #$0100        ; BG2 scroll position
        sta $3b            ; BG2 Y position
        sta $3d            ; BG3 X position
        sep #$20        ; 8-bit A
        lda #$04        ; bit 2
        trb $45            ; set bit in menu flags A
        jsr gear_desc
        rts
;Fork: Handle B
shop_handle_b:
        stz $3c
        stz $3e
        lda #$04
        tsb $45
C3B4CD:    LDA $09        ; No-autofire keys
C3B4CF:    BIT #$80       ; Pushing B?
C3B4D1:    BEQ shop_handle_a     ; Branch if not
C3B4D3:    JSR $0EA9      ; Sound: Cursor
C3B4D6:    JMP $B760      ; Exit submenu

;Fork: Handle A
shop_handle_a:
C3B4D9:    LDA $08        ; No-autofire keys
C3B4DB:    BIT #$80       ; Pushing A?
        beq not_pushing_a
C3B4DF:    JSR $B82F      ; Set buy limit
C3B4E2:    JSR $B7E6      ; Test GP, stock
not_pushing_a:
        rts

buy_menu_exp:
        jsr $1368
        jsr $c2f7        ; color: blue
        ldy #text_vigor    ; text: vigor
        jsr $02f9        ; draw text
        ldy #text_magic ; text: magic
        jsr $02f9        ; draw text
        ldy #text_stamina ; text: stamina
        jsr $02f9        ; draw text
        ldy #text_speed ; text: speed
        jsr $02f9        ; draw text
        ldy #text_def    ; text: defense
        jsr $02f9        ; draw text
        ldy #text_mdef    ; text: magic defense
        jsr $02f9        ; draw text
        ldy #text_eva    ; text: evasion
        jsr $02f9        ; draw text
        ldy #text_meva    ; text: magic evasion
        jsr $02f9        ; draw text
        ldy #text_bpow  ; text: bat.pow.
        jsr $02f9        ; draw text
        jsr $bfc2        ; get item
        rts
        
check_stats:
        ;jsr $1368        ; trigger NMI
        pha
        phx
        phy
        php
        jsr $c2f2
        jsr $bfc2        ; get item
C38699:    JSR $8321      ; Compute index
C3869C:    LDX $2134      ; Load it
C3869F:    TDC            ; Terminator
C386A0:    STA $7E9E8D    ; Set mod B3
C386A4:    STA $7E9E8E    ; Set mod B4
C386A8:    REP #$20       ; 16-bit A
C386AA:    LDA #$8223     ; Tilemap ptr
C386AD:    STA $7E9E89    ; Set position
C386B1:    SEP #$20       ; 8-bit A
C386B3:    TDC            ; Clear A
C386B4:    LDA $D85010,X  ; Stat mods LB
C386B8:    PHA            ; Memorize them
C386B9:    AND #$0F       ; Vigor index
C386BB:    ASL A          ; Double it
C386BC:    JSR $8836      ; Draw modifier
C386BF:    REP #$20       ; 16-bit A
C386C1:    LDA #$82a3     ; Tilemap ptr
C386C4:    STA $7E9E89    ; Set position
C386C8:    SEP #$20       ; 8-bit A
C386CA:    TDC            ; Clear A
C386CB:    PLA            ; Stat mods LB
C386CC:    AND #$F0       ; Speed index
C386CE:    LSR A          ; Put in b3-b6
C386CF:    LSR A          ; Put in b2-b5
C386D0:    LSR A          ; Put in b1-b4
C386D1:    JSR $8836      ; Draw modifier
C386D4:    REP #$20       ; 16-bit A
C386D6:    LDA #$8241     ; Tilemap ptr
C386D9:    STA $7E9E89    ; Set position
C386DD:    SEP #$20       ; 8-bit A
C386DF:    LDX $2134      ; Item index
C386E2:    TDC            ; Clear A
C386E3:    LDA $D85011,X  ; Stats mods HB
C386E7:    PHA            ; Memorize them
C386E8:    AND #$0F       ; Stamina index
C386EA:    ASL A          ; Double it
C386EB:    JSR $8836      ; Draw modifier
C386EE:    REP #$20       ; 16-bit A
C386F0:    LDA #$82c1     ; Tilemap ptr
C386F3:    STA $7E9E89    ; Set position
C386F7:    SEP #$20       ; 8-bit A
C386F9:    TDC            ; Clear A
C386FA:    PLA            ; Stat mods HB
C386FB:    AND #$F0       ; Mag.Pwr index
C386FD:    LSR A          ; Put in b3-b6
C386FE:    LSR A          ; Put in b2-b5
C386FF:    LSR A          ; Put in b1-b4
C38700:    JSR $8836      ; Draw modifier
        
;draw defensive properties
C38703:    LDX $2134      ; Item index
C38706:    LDA $D85000,X  ; Properties
C3870A:    AND #$07       ; Get class
        beq not_weapon    ; branch if tool
C3870C:    CMP #$01       ; Weapon?
C3870E:    BEQ is_weapon    ; Branch if so
        cmp #$06        ; item?
        beq not_weapon    ; branch if so
C38710:    LDA $D85014,X  ; Defense
C38714:    JSR $04E0      ; Turn into text
C38717:    LDX #$83a1     ; Text position
C3871A:    JSR $04C0      ; Draw 3 digits
C3871D:    LDX $2134      ; Item index
C38720:    LDA $D85015,X  ; Mag.Def
C38724:    JSR $04E0      ; Turn into text
C38727:    LDX #$83bf     ; Text position
C3872A:    JSR $04C0      ; Draw 3 digits
        ldy #bat_pow_dash
        jsr $02f9
is_weapon:
        tdc
        ldx $2134        ; item index
        lda $d85000,x    ; properties
        and #$07
        cmp #$01
        bne not_weapon
C3868E:    LDA #$20       ; Palette 0
C38690:    STA $29        ; Color: User's
C387AB:    CMP #$51       ; Dice?
C387AD:    BEQ hide_bpow      ; Hide if so
        ldx $2134
C387B3:    LDA $D85014,X  ; Bat.Pwr
C387B7:    JSR $04E0      ; Turn into text
C387BA:    LDX #$813f        ; Text position
C387BD:    JSR $04C0      ; Draw 3 digits
        ldy #def_dash
        jsr $02f9
        ldy #mdef_dash
        jsr $02f9
        bra not_weapon

hide_bpow:
        LDY #wpn_unknown     ; Text pointer
C387C3:    JSR $02F9      ; Draw "???"
        
not_weapon:
        jsr all_dashes
C387EB:    REP #$20       ; 16-bit A
C387ED:    LDA #$8321     ; Tilemap ptr
C387F0:    STA $7E9E89    ; Set position
C387F4:    SEP #$20       ; 8-bit A
C387F6:    LDX $2134      ; Item index
C387F9:    TDC            ; Clear A
C387FA:    LDA $D8501A,X  ; Evasion mods
C387FE:    PHA            ; Memorize them
C387FF:    AND #$0F       ; Evade index
C38801:    ASL A          ; x2
C38802:    ASL A          ; x4
C38803:    JSR $881A      ; Draw modifier
C38806:    REP #$20       ; 16-bit A
C38808:    LDA #$833f     ; Tilemap ptr
C3880B:    STA $7E9E89    ; Set position
C3880F:    SEP #$20       ; 8-bit A
C38811:    LDX $2134      ; Item index
C38814:    TDC            ; Clear A
C38815:    PLA            ; Evasion mods
C38816:    AND #$F0       ; MBlock index
C38818:    LSR A          ;
C38819:    LSR A          ;
C3881A:    TAX            ; Index it
C3881B:    LDA $C38854,X  ; Sign
C3881F:    STA $7E9E8B    ; Add to string
C38823:    LDA $C38855,X  ; Tens digit
C38827:    STA $7E9E8C    ; Add to string
C3882B:    LDA $C38856,X  ; Ones digit
C3882F:    STA $7E9E8D    ; Add to string
C38833:    JSR $8847      ; Draw modifier

; name and cleanup
        REP #$20
        lda #$810d        ; tilemap ptr
        sta $7e9e89
        SEP #$20        
        jsr $bfc2        ; get item
        jsr $c068        ; load item name
        jsr $7fd9
        plp
        ply
        plx
        pla
        jsr $bc92
        rts

all_dashes:
        ldx $2134
        lda $d85000,x
        and #$07
        cmp #$06
        bne skip_all_dashes
        ldy #bat_pow_dash
        jsr $02f9
        ldy #def_dash
        jsr $02f9
        ldy #mdef_dash
        jsr $02f9
skip_all_dashes:
        rts
gear_desc:
        lda $02
        cmp $4B
        bne gear_desc_end
        jsr gear_desc2    ; build description tilemap for shop menu
        jsr $b4e6        ; set description flags
        jsr $b4ef        ; load item description for buy menu
gear_desc_end:
        lda $4b
        sta $02
        rts
        
gear_desc2:
C3A6F4:    LDX #$7849     ; Base: 7E/7849
C3A6F7:    STX $EB        ; Set map ptr LBs
C3A6F9:    LDA #$7E       ; Bank: 7E
C3A6FB:    STA $ED        ; Set ptr HB
C3A6FD:    LDY #$0CBC     ; Ends at 30,19
C3A700:    STY $E7        ; Set row's limit
C3A702:    LDY #$0C84     ; Starts at 3,19
C3A705:    LDX #$3500     ; Tile 256, pal 5
C3A708:    STX $E0        ; Priority enabled
C3A70A:    JSR $A783      ; Do line 1, row 1
C3A70D:    LDY #$0CFC     ; Ends at 30,20
C3A710:    STY $E7        ; Set row's limit
C3A712:    LDY #$0CC4     ; Starts at 3,20
C3A715:    LDX #$3501     ; Tile 257, pal 5
C3A718:    STX $E0        ; Priority enabled
C3A71A:    JSR $A783      ; Do line 1, row 2
C3A71D:    LDY #$0D3C     ; Ends at 30,21
C3A720:    STY $E7        ; Set row's limit
C3A722:    LDY #$0D04     ; Starts at 3,21
C3A725:    LDX #$3538     ; Tile 312, pal 5
C3A728:    STX $E0        ; Priority enabled
C3A72A:    JSR $A783      ; Do line 2, row 1
C3A72D:    LDY #$0D7C     ; Ends at 30,22
C3A730:    STY $E7        ; Set row's limit
C3A732:    LDY #$0D44     ; Starts at 3,22
C3A735:    LDX #$3539     ; Tile 313, pal 5
C3A738:    STX $E0        ; Priority enabled
C3A73A:    JMP $A783      ; Do line 2, row 2

help_text:
        dw $791f : db "Hold Y for details.",$00
text_vigor:
        dw $820d : db "Vigor",$00 ; +12 = $821f
text_magic:
        dw $828d : db "Speed",$00 ; +12 = $829f
text_stamina:
        dw $822b : db "Stamina",$00 ; +12 = $823d
text_speed:
        dw $82ab : db "Magic",$00 ; +12 = $82bd
text_def:
        dw $838d : db "Defense",$00 ; +12 = $819f
text_mdef:
        dw $83ab : db "M.Def.",$00 ; +12 = $81bd
text_eva:
        dw $830d : db "Evade",$00 ; +12 = $831f
text_meva:
        dw $832b : db "M.Evade",$00 ; +12 = $833f
text_bpow:
        dw $812b : db "B.Power",$00 ; + 12 = $813d
wpn_unknown:
        dw $813f : db "???",$00
bat_pow_dash:
        dw $813f : db "---",$00
def_dash:
        dw $83a1 : db "---",$00
mdef_dash:
        dw $83bf : db "---",$00
ele_resist:
        dw $7B8D : db "Resist:",$00
ele_absorb:
        dw $7C0D : db "Absorb:",$00
ele_nullify:
        dw $7C8D : db "Nullify:",$00
ele_weakness:
        dw $7D0D : db "Weakness:",$00

;Window layout data
shop_gear_window:
dw $718B : db $1C,$06
shop_gear_window_actors:
dw $750B : db $1C,$06
shop_gear_weapon_name:
dw $708B : db $1C,$02
shop_gear_description:
dw $738B : db $1c,$04
 

 

2

Share this post


Link to post
Share on other sites

"spell dot" hack. BTB supposedly has the dots drawn in the VWF area. make sure you draw in a space as well, or it'll look crunched.

Spoiler

hirom

org $c1602e
    nop #3
org $c16031
    lda $e6f567,x

 

2

Share this post


Link to post
Share on other sites

Random encounter mod - DONE

	;Random encounters mod for BNW
;v3 - re-jiggered some numbers courtesy of nowea
;v2 - should actually work now 
	;Should raise the minimum number of steps for a random encounter to 10, while still maintaining the overall rate
	hirom
;header
	!freespaceC2 = $C2FBF0
!freespaceC0 = $C0FF90
	; Overworld encounters
org $C0C48C
LDA #$E9      ; 233
JSR longCall
CLC
ADC #$04      ; Random 4..236
	; Town/dungeon encounters
org $C0C4A9
LDA #$E9      ; 233
JSR longCall
CLC
ADC #$04      ; Random 4..236
	org !freespaceC0
longCall:
JSL c2rand  ; Random 0..232
RTS
	org !freespaceC2
c2rand:
JSR $4B65
RTL

0

Share this post


Link to post
Share on other sites

Reflect timer - DONE

	; Disable Reflect timer and randomly remove Reflect when triggered
; by Seibaby (2018-12-01)
	hirom
;header
!freespace = $C2AEA9    ; Requires 9 bytes of free space in C2
	; The hook offset for the new code depends on whether you have Terii's
; Vanish/Doom patch applied or not.
;!hook = $C22248         ; Vanilla
!hook = $C22256         ; Vanish/Doom patch applied
	; Disable Reflect timer
org $C2469B
nothing: RTS
	org $C246DE
      dw nothing        ; Action when setting Rflect
	; Hook Hit Determination to call new code
org !hook
JMP remove_reflect      ; Make attack miss if reflecting
	; The purpose of the following modifications are to make room for the
; new code. The Reflect timer is no longer used, so it's safe to remove
; both the code that sets the timer, and the code that checks whether it
; has run out. This frees up enough space for the new code.
	; This new code replaces the code that set the Reflect timer (10 bytes)
org $C24687
remove_reflect:
         SEP #$20       ; 8-bit A
         JSR $4B5A      ; RNG: 0..255
         CMP #$55       ; 1 in 3 chance to clear Rflect status
         JMP remove_reflect2  ; (continued...)
	; The following code handles timers and status removal upon expiry.
; The code that handled the Reflect timer was removed, and the second part
; of the new code was inserted at the end of the function.
org $C25AE9
exit:
         RTS
	org $C25B06
C25B06:                 ; (Code relevant to the Reflect timer was
                        ;  removed from the start of this block)
         STA $B8
         LDA $3F0D,X    ; Time until Freeze wears off
         BEQ .sleep     ; Branch if timer not active
         DEC $3F0D,X    ; Decrement Freeze timer
         BNE .sleep
         LDA #$04
         TSB $B8        ; If Freeze timer reached 0 on this tick,
                        ; Set to remove Freeze
.sleep   LDA $3CF9,X    ; Time until Sleep wears off
         BEQ .end       ; Branch if timer not active
         DEC $3CF9,X    ; Decrement Sleep timer
         BNE .end
         LDA #$08
         TSB $B8        ; If Sleep timer reached 0 on this tick,
                        ; Set to remove Sleep
.end     LDA $B8
         BEQ exit       ; Exit if we haven't marked any of the
                        ; Statuses to be auto-removed
         LDA #$29
         JMP $4E91      ; Queue the status removal
	; New code (continued)
; Replaces the code that handled the Reflect timer (14 bytes)
remove_reflect2:
         BCS .end       ; Exit 2/3 times
         LDA $3330,Y    ; Blocked status 3
         BPL .end       ; No removal if permanent Reflect
         JSR remove_reflect3
.end     JMP $22E5      ; Make attack miss
         NOP            ; (Padding)
	; The space freed up by excising the Reflect timer isn't enough to
; handle the message boxes, so here's dipping into free space.
org !freespace
reset bytes
remove_reflect3:
         LDA $3E10,Y    ; Status to clear 3
         ORA #$80       ; Bit 7 = Rflect
         STA $3E10,Y    ; Mark Rflect to be cleared
         RTS
print bytes," bytes added"
	

]

0

Share this post


Link to post
Share on other sites

Quake/Vanish fix - DONE
 

; Quake removes Clear status even when missing Floating targets fix
; Version 1.0
; by Seibaby

;xkas 0.06
hirom
;header
!freespace = $C2xxxx

; Spell Effect Pointer $25: Quake (Once-per-strike)
org $C2432B
dw groundBased

; Untarget Floating targets, except if all targets are Floating
org !freespace
reset bytes
groundBased:
        REP #$20          ; Set 16-bit Accumulator
        LDA $A2
        STA $EE           ; Copy targets to temporary variable
        LDX #$12
.loop   LDA $3EF8,X       ; Current status byte 3-4
        BPL .next         ; Check next target if this one is not floating
        LDA $3018,X
        TRB $EE           ; Clear this monster from potential targets
.next   DEX
        DEX
        BPL .loop         ; Loop for all 10 targets
        LDA $EE
        BNE .save         ; Branch if any target(s) left
        LDA #$0080
        TRB $B3           ; No targets valid, so set Ignore Clear
        LDA $A2           ; Else, use original Targets
.save   STA $B8           ; save target(s)
        TYX
        JMP $57C2
print bytes

Edited by seibaby
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now