NintendoAge http://nintendoage.com/forum/ -Sqooner Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-13T12:50:05 -05.00 bunnyboy 23 Originally posted by: SoleGooseProductions

To be honest, I'm not sure at this point . Sadly, all I know is that my addition and subtraction routines work flawlessly, so far as I've been able to test them. Can't really argue with results, but I'm still curious about the transfer of values (or why a simple transfer won't work, but an addition is required).
I would need to see the bad code and the rom in action so I can watch the hex values change. Otherwise, I'm just blindly shooting answers from the hip.

If you don't want to post it here, hit me with a pm and we can email or something.
  ]]>
Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-12T18:46:04 -05.00 bunnyboy 23 Originally posted by: KHAN Games

He already realized that, Jack. That's why I asked for another actual example that contains the problem that he has questions with.
That's what I was thinking too. That's why I said in my post above there is something I likely still miss about his question.
I've been reading the bunnyboy examples in the first post, and none match this snippet of code he posted, but probably is just me not understanding exactely what this snippet of code he posted is for.
HexValue and TempBinary are names that suggest me nothing pratical: there are two values, which seems have to be added. If I knew what they refer to I could understand (and hopefully help) better.
However, I was just trying to help, hope my post didn't sound redundant, that was not the intention. ]]>
Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-12T18:33:20 -05.00 bunnyboy 23 Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-12T18:19:54 -05.00 bunnyboy 23 Originally posted by: SoleGooseProductions

To be honest, I'm not sure at this point . Sadly, all I know is that my addition and subtraction routines work flawlessly, so far as I've been able to test them. Can't really argue with results, but I'm still curious about the transfer of values (or why a simple transfer won't work, but an addition is required). The way I see it, there are 3 values:
- HexValue
- TempBinary
- carry


The Carry flag can be either 1 (if the flag is set) or 0 (if the flag is not set, or reset).

CLC means that you reset the carry flag to 00, so when you sum the value in the accumulator with the value after the opcode ADC, you will not add also +01.
Since there is not an instruction ADD WITHOUT CARRY, when you use ADC and you don't want the carry flag to influence the result, you just set the carry to 0.
In the example you posted above, you CLC twice, which is ok if it is what you need. Instead if you wish that an overflow in the first ADC adds +01 to the result of the second ADC, then you avoid that second CLC instruction.

As MegaMarioMan pointed out, this code:
  LDA HexValue
  STA TempBinary
is different than this code:
  LDA TempBinary
  CLC
  ADC HexValue
  STA TempBinary
Let say HexValue is == "x", TempBinary is == "y".
("x" and "y" are two values)

In the first case, after running your code, TempBinary will be == "x", because that is what you store into it with such code.

In the second case, after running your code TempBinary will be == "y"+Hex00+"x", since you load the old value, then you add the carry, and you add HexValue. In the socond case you are not moving a value from a variable to another, but you are summing, adding also the carry, the two values, and you are storing that result into TempBinary.

I feel like likely I am missing something you are trying to explain, but I think that if you look at your own two snippets of code for like 20 seconds, you will immediately realize that they don't do the same thing at all, math wise.

Hope this helps. ]]>
Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-12T17:42:42 -05.00 bunnyboy 23 Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-12T16:06:16 -05.00 bunnyboy 23 . Sadly, all I know is that my addition and subtraction routines work flawlessly, so far as I've been able to test them. Can't really argue with results, but I'm still curious about the transfer of values (or why a simple transfer won't work, but an addition is required). ]]> Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-12T14:58:23 -05.00 bunnyboy 23 Originally posted by: SoleGooseProductions

The 16-bit one in the OP. I guess I am also curious why I cannot add to the TempBinary variables directly, but have to buffer them through another variable instead (i.e. load a value into a variable, and then add this to TempBinary).

EDIT: regardless, what I am curious about is how to modify these values correctly, and not necessarily how to correct my own code.

Double Edit: took a break and figured it out. Well, re-figured it out since I had it figured out a couple weeks ago, but I lost it due to not being able to work on it. The TempBinary is not the value itself (duh!), therefore it does not matter what I do to it. Though I still feel as though there should be a way to alter it directly. Anyways...

So the only question that I have left is: why does the value have to be added to TempBinary? Why cannot it simply be stored? In other words, this does not work:

LDA HexValue
STA TempBinary
LDA HexValue+1
STA TempBinary+1


But this does:

LDA TempBinary
CLC
ADC HexValue
STA TempBinary

LDA TempBinary+1
CLC
ADC HexValue+1
STA TempBinary+1


I'm bracing for a lesson in the Carry... Assume for this example
HexValue = 2
TempBinary = 1


LDA HexValue
STA TempBinary
LDA HexValue+1
STA TempBinary+1


This would replace the values in TempBinary and TempBinary+1 with the values in HexValue and HexValue+1. So, HexValue = TempBinary. or 2=2
=======================================================================

LDA TempBinary
CLC
ADC HexValue
STA TempBinary

LDA TempBinary+1
CLC
ADC HexValue+1
STA TempBinary+1


This would Load the value of TempBinary, add HexValue, and then write the sum value to TempBinary. So, TempBinary+HexValue = TempBinary.  1+2=3

Hope that is what you were asking.
  ]]>
Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-11T11:55:54 -05.00 bunnyboy 23 Originally posted by: SoleGooseProductions

But this does:

LDA TempBinary
CLC
ADC HexValue
STA TempBinary

LDA TempBinary+1
CLC  ;                      <-- WHY?
ADC HexValue+1
STA TempBinary+1 I admit that I'm not too sure about what you are trying to achieve here, but if in your code in case of overflow of the first ADC the second ADC must be increased by an extra 01, then I think you should not clear the carry before the second ADC. Again, probably I misunderstood your goals here, I see no references to this snippet of code in bunnyboy post. ]]>
Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-11T09:53:56 -05.00 bunnyboy 23
EDIT: regardless, what I am curious about is how to modify these values correctly, and not necessarily how to correct my own code.

Double Edit: took a break and figured it out. Well, re-figured it out since I had it figured out a couple weeks ago, but I lost it due to not being able to work on it. The TempBinary is not the value itself (duh!), therefore it does not matter what I do to it. Though I still feel as though there should be a way to alter it directly. Anyways...

So the only question that I have left is: why does the value have to be added to TempBinary? Why cannot it simply be stored? In other words, this does not work:

LDA HexValue
STA TempBinary
LDA HexValue+1
STA TempBinary+1

But this does:

LDA TempBinary
CLC
ADC HexValue
STA TempBinary

LDA TempBinary+1
CLC
ADC HexValue+1
STA TempBinary+1

I'm bracing for a lesson in the Carry... ]]>
Nerdy Nights week 9 http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=33308 2015-10-11T09:36:45 -05.00 bunnyboy 23 Originally posted by: SoleGooseProductions

So I have the 16-bit example working (the last one), but it is doing some screwy things. Like, when a button changes the values, it resets to zero (once) before adding/subtracting at the correct rate. Unless I run the routine twice when loading the game state, then the desired number is preserved, and the addition/subtraction adds or subtracts from that value. So I guess my question is, using the last example, how does one modify the values correctly? I could keep making it work the way that I have it, but frankly it bothers me that I cannot figure out why it is doing this. It (or something else) is also messing with my subtraction routines some, I think.
I'll be happy to help, but without seeing the code it is hard to tell what is wrong with it.
Also, by "the last one", do you mean the last (second) one bunnyboy posted in the first post of this thread, or the one Vec posted just above your post?

  ]]>