Users browsing this thread: 1 Guest(s)
No Sale! (Sale/Bet prohibition code)

#1
Posts: 363
Threads: 31
Thanks Received: 154
Thanks Given: 136
Joined: Dec 2018
Reputation: 18
Status
Moog
This is code which will prevent items set at 0 value from being sold in stores or bet at the Colosseum.  Combined with an editor, this should allow you to flag precious treasures that the player is not meant to sell.

Presented as raw code because it uses space in the C3 bank, which may or may not be full in your hack.  Yes, I probably should give you an assembly file so you can change the values as need-be.  No, I'm probably not going to do that.   Confused

Code:
--------------------------
No Sale!
--------------------------
Sets items that have a value of 0 to the gray font palette in the sell and Colosseum menus, and prevents their sale or wager

Subroutine: Check if priceless, set carry if so
3FEEF
    DA                    PHX                Put X on the stack for now
    20 21 83            JSR $8321        Calculate Item Offset
    AE 34 21            LDX $2134
    C2 20                REP #$20        Set 16-bit A
    BF 1C 50 D8            LDA $D8501C,X    Load price, both bytes
    D0 03                BNE $03            Branch if nonzero
    38                    SEC                Set carry if zero, indicating priceless
    80 01                BRA $01            Cleanup and exit
    18                    CLC                Nonzero branch lands here
    E2 20                SEP #$20        Set 8-bit A
    FA                    PLX                Pull original X back off the stack
    60                    RTS                Exit

Subroutine: Check if empty or priceless for shop, set carry if so
3FF06
    20 CB BF            JSR $BFCB        Calculate selected item
    C9 FF                CMP #$FF        Is it empty?
    F0 05                BEQ $05            Set carry if so.
    20 EF FE            JSR $FEEF        Check if priceless (This is a freespace routine)
    80 01                BRA $01            Exit
    38                    SEC
    60                    RTS

Hook: Make shop check empty or priceless, bzzt if either
3B63A
    20 06 FF            JSR $FF06        Freespace subroutine to set carry if item is priceless or empty
    EA EA                NOP #2
    B0 2E                BCS $2E            Bzzzt and pixelate if carry is set
    
Code Block: Check if empty or priceless for Colosseum, set carry if so
3FF14
    BD 69 18            LDA $1869,X        Get item in slot (wager)
    C9 FF                CMP #$FF        Is it empty?
    F0 05                BEQ $05            Set carry if so
    20 EF FE            JSR $FEEF        Check if priceless (This is a freespace routine)
    80 01                BRA $01            Exit
    38                    SEC
    B0 06                BCS $06            If empty or priceless, go to fail and buzzer
    BD 69 18            LDA $1869,X        Load wager again
    4C 01 AD            JMP $AD01        Continue with bet
    4C 0E AD            JMP $AD0E        Fail and buzzer/pixelate
    
Hook: Make Colosseum check empty or priceless, bzzt if either
3ACFA
    4C 14 FF            JMP $FF14        Go to alternate code block                
    EA EA EA EA            NOP #4

Subroutine: Check if priceless for sell/Colosseum color
3FF2C
    B9 69 18            LDA $1869,Y        Get item in slot
    20 21 83            JSR $8321        Compute the item's index
    AE 34 21            LDX $2134        Load it
    C2 20                REP #$20        Set 16-bit A
    BF 1C 50 D8            LDA $D8501C,X    Load price, both bytes
    D0 03                BNE $03            Branch if nonzero
    38                    SEC                Set carry, indicating priceless
    80 01                BRA $01            Skip the clear carry for items with value
    18                    CLC
    E2 20                SEP #$20        Set 8-bit A
    B0 05                BCS $05            If carry is set, item is priceless
    A9 20                LDA #$20
    85 29                STA $29            Set font color to white
    60                    RTS                Exit
    A9 28                LDA #$28
    85 29                STA $29            Set font color to gray
    60                    RTS

Hook: Gray Lists for Sell/Coliseum
3804A
    F0 06                BEQ $06            If sell menu, branch (closer than Vanilla)
    C9 07                CMP #$07        Is it the Colosseum menu?
    F0 02                BEQ $02            If so, branch (closer than Vanilla)
    80 04                BRA $04            Otherwise, branch to Item menu handling

Hook: Subroutine to gray list if 0 value item
38052                [This was flagged as unused in the C3 disassembly]
    20 2C FF            JSR $FF2C        Check if priceless for sell/Colosseum color
    60                    RTS                Exit


EDIT: Okay, fine, I get that people hate hex mangling and this could be very important to new hackers who are unfamiliar with the gibberish I spout.  To that end, here's an assembly version compatible with xKas v0.06
Code:
;--------------------------
;No Sale!
;--------------------------
;Sets items that have a value of 0 to the gray font palette in the sell and Colosseum menus, and prevents their sale or wager


hirom
;header


;Hooks: Vanilla locations that hook into freespace subroutines to add the price criterion

org $C3804A            ;Hook: Gray Lists for Sell menu
BEQ Gray_Lists            ;If sell menu, branch (closer than Vanilla)

org $C3804E            ;Hook: Gray Lists for Coliseum menu
BEQ Gray_Lists            ;If so, branch (closer than Vanilla)

org $C38052            ;xKas info: Destination of Gray_Lists branches
Gray_Lists:

org $C38052            ;Hook: Subroutine to gray list if 0 value item
                        ;Originally flagged as unused in the C3 disassembly
JSR $FF2C                ;Check if priceless for sell/Colosseum color
RTS                        ;Exit

org $C3ACFA            ;Hook: Make Coliseum check empty or priceless and bzzt if either
JMP Coliseum_Check        ;Go to alternate code block                
NOP #4

org $C3B63A            ;Hook: Make shop check empty or priceless, bzzt if either
JSR Shop_Check            ;Freespace subroutine to set carry if item is priceless or empty
NOP #2
BCS $2E                    ;Bzzzt and pixelate if carry is set


;Subroutines: Freespace calculation of item value, to set the carry flag if value is 0

org $C3FEEF            ;This is a freespace value, change it to an appropriate spot in your ROM.
                        ;This patch requires 0x60 bytes of space in the C3 bank.
                        ;It could probably be optimized or relocated with Eggers jumps, but...
                        ;I'm not going to do that for you!

Price_Check:        ;Subroutine: Check if priceless, set carry if so
PHX                        ;Put X on the stack for now
JSR $8321                ;Calculate Item Offset (Vanilla C3 subroutine)
LDX $2134
REP #$20                ;Set 16-bit A
LDA $D8501C,X            ;Load price, both bytes
BNE Price_Check_notZero    ;Branch if nonzero
SEC                        ;Set carry if zero, indicating priceless
BRA Price_Check_exit    ;Cleanup and exit
Price_Check_notZero:
CLC
Price_Check_exit
SEP #$20                ;Set 8-bit A
PLX                        ;Pull original X back off the stack
RTS                        ;Exit


Shop_Check:            ;Subroutine: Check if empty or priceless for shop, set carry if so
                        ;At C3FF06 if you didn't change the freespace value
JSR $BFCB                ;Calculate selected item
CMP #$FF                ;Is it empty?
BEQ Shop_Check_Empty    ;Set carry if so.
JSR Price_Check            ;Check if priceless
BRA Shop_Check_Exit        ;Exit
Shop_Check_Empty:
SEC
Shop_Check_Exit:
RTS

Coliseum_Check:        ;Code Block: Check if empty or priceless for Colosseum, set carry if so
                        ;At C3FF14 if you didn't change the freespace value
LDA $1869,X                ;Get item in slot (wager)
CMP #$FF                ;Is it empty?
BEQ $05                    ;Set carry if so
JSR Price_Check            ;Check if priceless
BRA Coliseum_Check_Announce
Coliseum_Check_Empty:
SEC                        ;Flag this item slot for bzzt and pixelation
Coliseum_Check_Announce:
BCS Coliseum_Check_Bzzt    ;If empty or priceless, go to fail and buzzer
LDA $1869,X                ;Load wager again
JMP $AD01                ;Continue with bet (Vanilla C3 address)
Coliseum_Check_Bzzt:
JMP $AD0E                ;Fail and buzzer/pixelate (Vanilla C3 address)

Font_Check:            ;Subroutine: Check if priceless for sell/Colosseum color
                        ;At C3FF2C if you didn't change the freespace value
LDA $1869,Y                ;Get item in slot
JSR $8321                ;Compute the item's index (Vanilla C3 subroutine)
LDX $2134                ;Load it
REP #$20                ;Set 16-bit A
LDA $D8501C,X            ;Load price, both bytes
BNE Font_Check_notZero    ;Branch if nonzero
SEC                        ;Set carry, indicating priceless
BRA Font_Check_Announce    ;Skip the clear carry for items with value
Font_Check_notZero:
CLC                        ;Flag this item slot to draw in white font
Font_Check_Announce:
SEP #$20                ;Set 8-bit A
BCS Font_Check_Gray        ;If carry is set, item is priceless
LDA #$20
STA $29                    ;Set font color to white
RTS                        ;Exit
Font_Check_Gray:
LDA #$28
STA $29                    ;Set font color to gray
RTS
  Find
Quote  
[-] The following 4 users say Thank You to C-Dude for this post:
  • Gi Nattak (12-21-2022), madsiur (12-21-2022), PowerPanda (12-21-2022), Warrax (12-22-2022)

#2
Posts: 116
Threads: 11
Thanks Received: 8
Thanks Given: 46
Joined: Jun 2021
Reputation: 2
Status
None
Is xKas a program listed on this sight? Or should we google it for the download?
  Find
Quote  

#3
Posts: 2,493
Threads: 97
Thanks Received: 430
Thanks Given: 375
Joined: Aug 2009
Reputation: 52
Status
Nattak\'d
We have xkas hosted on the wiki:
https://www.ff6hacking.com/wiki/doku.php?id=utility
under General Utilities>Assembly.


We are born, live, die and then do the same thing over again.
Quote  



Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite