Comparing DAT with Variable Values
coryco2
Posts: 107
I'm trying to compare five current values in a DAT table, which has been updated by another method, with their previous values; and call another method if any of the DAT items is not the same value as during the last loop. I know the DataItem values are being changed sometimes, but ChangeChecker (below) when called seems unable to detect this, and never calls SomeOtherMethod. Can anyone please tell me why?
PUB ChangeChecker | prevItem0, prevItem1, prevItem2, prevItem3, prevItem4 IF (prevItem0 <> DataItem[0]) AND (prevItem1 <> DataItem[1]) AND (prevItem2 <> DataItem[2]) AND (prevItem3 <> DataItem[3]) AND (prevItem4 <> DataItem[4]) SomeOtherMethod prevItem0 := DataItem[0] prevItem1 := DataItem[1] prevItem2 := DataItem[2] prevItem3 := DataItem[3] prevItem4 := DataItem[4] DAT DataItem byte $11, $22, $33, $44, $55, $66, $77, $88, 0
Comments
BTW, you could use "bytemove" to set your one array equal to the other but it's a bit of a trick with local variables since all local variables are longs. It could be done though. It's also possible to set your comparison up in a loop but the way you have it now should get the job done.
Another issue is your local variables are not preserved from one call to ChangeChecker to another. You need you're previous value array as a global array if you're not remaining in "ChangeChecker" method between comparisons. By having the previous values as global variables you could then use a byte array which would make using 'bytemove" easier.
You have declared all the prevItemX variables as local variables to the ChangeChecker method.
That means they are created when the method is called and disappear when the method returns.
So, you "if" comparisons are comparing DataItem[X] against uninitialized values.
Then you update the prevItemX local variables from DataItem[X] but those values disappear when ChangeChecker returns.
You need to move the prevItemX variables out to a VAR section to fix that at least.
Thanks!