SubtractValue Macro only subtracts 1?

Trying to figure out the Subtract Macro, but I can't get it to do anything other than subtract one.

I'm trying to get a lock to remove 5 keys instead of one. So I use:

SubtractValue #$02, myKeys, #$05, #$00

But that only subtracts 1. Changing arg0, 2, or 3 all results in subtracting 1. I can get it to subtract 10 by using

SubtractValue #$02, myKeys+1, #$01, #$00

But it behaves the same way, only subtracting 10 regardless of the arg variables.

Is this a bug or am I just using the macro wrong?
 
Sure thing:
Code:
MACRO SubtractValue arg0, arg1, arg2, arg3
	TXA
	PHA
	;arg0 = how many places this value has.
	;arg1 = home variable
	;arg2 = amount to subtract ... places?
	;arg3 = to what place
	LDX arg0
	--:
		LDA arg1,x ;; the variable that you want to push
		STA value,x
		dex
		BPL --
	LDA arg2
	STA temp
	JSR valueSubLoop ;; will add what is in accumulator.
	;;; now value nees to be unpacked back into the variable.

		LDX arg0
	-:
		LDA value,x ;; the variable that you want to push
		STA arg1,x
		dex
		BPL -
	PLA 
	TAX
	ENDM
 

Kasumi

New member
I made a post on this bug: http://nesmakers.com/viewtopic.php?f=23&t=1700&p=10343&hilit=subtract#p10343
 

dale_coop

Moderator
Staff member
As I suspected, you are using an old one...
It has been patched in the 4.1.1

Try this one (from the 4.1.1 patch):
Code:
MACRO SubtractValue arg0, arg1, arg2, arg3
	TXA
	PHA
	;arg0 = how many places this value has.
	;arg1 = home variable
	;arg2 = amount to subtract ... places?
	;arg3 = to what place
	LDX arg0
	--:
		LDA arg1,x ;; the variable that you want to push
		STA value,x
		dex
		BPL --
	LDX arg3 ; sets the place to push.
	LDA arg2
	STA temp
	JSR valueSubLoop ;; will add what is in accumulator.
	;;; now value nees to be unpacked back into the variable.

		LDX arg0
	-:
		LDA value,x ;; the variable that you want to push
		STA arg1,x
		dex
		BPL -
	PLA 
	TAX
	ENDM
 
Thanks guys,

It works perfectly now.

However I think the "old one" is still the current one. I've only used 4.1.5, and I recently redownloaded it for a fresh project, and it had the same missing line in the macro.
 
Top Bottom