Alright! There is some meta-code here. Let's do it step by step.
First things first.
Then, for 0x6D1260+k, for k=0,..,length*width
Condition
Memory at Death Table 0x6D1260+k at least 2^n, using bitmask 0xFFFFFFFF
Action
Modify memory at Death Table 0x6D1260+k: substract 2^n, using bitmask 0xFFFFFFFF
Modify memory at Death Table 0x6509B0: add 2^n, using bitmask 0xFFFFFFFF
Memory at Death Table 0x6D1260+k at least 2^n, using bitmask 0xFFFFFFFF
Tiles table isn't @(0x6D1260+k) at all, this would be an error! The pointer value isn't it's address. You must
dereference the pointer, i.e. take the value written at memory location @0x6D1260 and substitute
that value as an argument to the condition! This is the reason to use clever CP-trick. Before you grasp the concept of dereferencing pointers, let's fix more basic stuff.
Let's look at
'using bitmask 0xFFFFFFFF' part. This is something new in SCMD2 and would be of great help to do the flags manupulation part on separate tiles, given it's a working feature (yet I'm not sure). For simplicity let's put bitmask aside and use simple test/set memory conditions.
Minor things about decor, look at this:
Then, for 0x6D1260+k, for k=0,..,length*width
Think about what additional information gives the underlined part. Try not to write redundant (meta)code.
After that, the code above doesn't define n, did you actually mean to write:
For k=0,..,length*width
For n=0,1,3,4,5,...
Condition
Memory at Death Table 0x6D1260+k at least 2^n, using bitmask 0xFFFFFFFF
Action
Modify memory at Death Table 0x6D1260+k: substract 2^n, using bitmask 0xFFFFFFFF
Modify memory at Death Table 0x6509B0: add 2^n, using bitmask 0xFFFFFFFF
Please, be verbose in everything, because it's the source of all kind of misunderstandings and errors.
I'm quitting being a jerk now. Let's tear down the first block.
So, in SCMDraft, I should do, for n=0,1,2,3,4,5,...
Condition
Memory at Death Table 0x6D1260 at least 2^n, using bitmask 0xFFFFFFFF
Action
Modify memory at Death Table 0x6D1260: substract 2^n, using bitmask 0xFFFFFFFF
Modify memory at Death Table 0x6509B0: add 2^n, using bitmask 0xFFFFFFFF
The devil is in details. The code above doesn't ideologically match construct from
Binary Countoffs. The order of triggers in the sequence is different. You should do it 'for n = ..., 5, 4, 3, 2, 1, 0', see the difference? From higher to lower. Why is it important? How high do you need to get with n? These are kind of questions you should ask yourself if you fully understand what is going on.
I try to help you providing a binary interpretation of the process. Let's consider a copy from @Source to @Target, where those entities might be regular death counters, variables at memory, or score/resource amounts, all the same. Let's also assume those are 8-bit integers. Let @Source be 0b00101101 in binary (what number is that?) and @Target is 0b00000000 (zero). The test of a kind
Memory at Death Table @Source at least 2^n
is equivalent to the question
Is there at least one '1' at position #n (zero-based) or higher in binary representation of @Source [*]
Where 'higher', means 'at left' and positions are enumerated from right to left starting with position #0 (as it usually happens with numbers). This makes more sense if you note that 2^n is exactly a number that has a binary representation with singular '1' at position #n.
Binary Countoff does deconstruction of the @Source from higher bits into lower bits, and constructs the same value at @Target in parallel. The nature of test [*] requires us to deconstruct @Source, because the condition we would like to know is in fact different:
Is there '1' exactly at position #n (zero-based) in binary representation of @Source [**]
When we are sure the number is "deconstructed" towards bit #n, we use [*] interchangeably in place of [**]. There is no direct way to ask for exactly [**] in triggers.
Binary Countoff does a bit more than copying, it does the assignment of the kind '@Target = @Target + @Source', where @Source equals 0 afterwards. When @Target equals 0 before we start the countoff it is an assignment '@Target = @Source'
with destruction of @Source in the process, i.e. destructive copy.
We can adopt binary countoff to do more general assignment all in one go:
@Target1 = @Target1 + @Source; @Target2 = @Target2 + @Source; ... @TargetM = @TargetM + @Source;
This is done with triggers:
For n = ..., 2, 1, 0
Condition
Memory at Death Table @Source at least 2^n
Action
Modify memory at Death Table @Source: substract 2^n
Modify memory at Death Table @Target1: add 2^n
Modify memory at Death Table @Target2: add 2^n
...
Modify memory at Death Table @TargetM: add 2^n
Given that we are able to make a non-destructive copy using 2 binary countoffs and a temporary location @Temp:
@Target = @Source; @Temp = @Source; // these 2 in one go
@Source = @Temp; // restore @Source with second binary countoff
The last but not the least, you do a primitive, which I call a mutative assignment, i.e. divide value @Source by constant 2^k in the process:
@Target = @Target + @Source / (2^k);
Like this:
For n = ..., (k+2), (k+1), k
Condition
Memory at Death Table @Source at least 2^n
Action
Modify memory at Death Table @Source: substract 2^n
Modify memory at Death Table @Target: add 2^(n-k)
After these triggers fire @Target is enlarged by the quotient of the @Source divided by 2^k, and remainder of the division resides in @Source.
About flags.
And for accessing that value, maybe we should just add the value of the @flag to the value of the tile? That would mean that it's not actually 0x6D1260+k what we should do, but 0x6D1260+k+c*m, k a counter for flags, c the amount of flags and m the tile
Nope. Keep in mind, we are addressing chunks of memory in 4-bytes, not singular bits. If you add c*m then you are c*m*4 bytes ahead and that's just another tile.
The classic method to test for bit #s in @Source would be to deconstruct the @Source all the way towards the bit #s with a binary countoff, perform a test, and reconstruct the value using what's being copied to @Target.
If the bitmask feature really works in SCMD2, then it's as trivial as applying the appropriate mask to expose the bit in interest and check for value of @Source is at least 1. I suppose.
Post has been edited 5 time(s), last time on Aug 8 2019, 8:45 pm by Wormer.
Some.