Before I continue, I should post these lists of bit mask numbers useful for bitwise operations, particularly flags.
(Moderator, if you want, I can copy this message to a new one, and you can link to it, as a tutorial, from
ACK Documentation, Online References, etc.)
Variables A-G and A2-G2 are 8-bit ones, holding values of zero to 255. Since they are 8-bit, they can contain up to 8 one-bit flags, with the following masks:
Code: Select all
BIT A B
00 1 254
01 2 253
02 4 251
03 8 247
04 16 239
05 32 223
06 64 191
07 128 127
BIT = bit number, starting from 0.
A = decimal mask value, used for setting and testing. (Power of 2)
B = inverse mask value, used for clearing. (255 minus A)
- To set bit 4 in variable C:
SET C = C | 16
To clear bit 6 in variable G2:
SET G2 = G2 & 191
To test bit 1 in variable F:
IF F & 2 THEN ...
To clear all bits of variable B2:
SET B2 = 0
To set all bits of variable B2:
SET B2 = 255
If you need to use the other variables (H-Z and H2-Z2), they are 16-bit, going from 0 to 65535:
Code: Select all
BIT A B C
00 1 65534 -2
01 2 65533 -3
02 4 65531 -5
03 8 65527 -10
04 16 65519 -17
05 32 65503 -33
06 64 65471 -65
07 128 65407 -129
08 256 65279 -257
09 512 65023 -513
10 1024 64511 -1025
11 2048 63487 -2049
12 4096 61439 -4097
13 8192 57343 -8193
14 16384 49151 -16385
15 32768 32767 32767
(-32768)
BIT = bit number, starting from 0.
A = decimal mask value, used for setting and testing.
B = inverse mask value, used for clearing. (65535-A)
C = inverse mask value as negative number.
Note that the ACK macro editor displays numbers greater than 32767 as negatives, using the formula C = B - 65536. You need to type in the number as a positive one from column B, but it displays as a negative one from column C.
Usage is much the same as with the 8-bit variables, except that setting all bits means setting to 65535. For an example, to test bit 12 of Q2:
IF Q2 & 4096 THEN ...
To use variables efficiently, make a list of all flags needed in the game, set aside however many variables are needed, and assign each flag to a specific bit from these variables. You need to make a list somewhat like this, and store it on paper or in your documentation text file:
Code: Select all
Variable I2 - Game Progress Flag
1 0 talked to everyone in town
2 1 met elven ranger
4 2 have part 1 of magic key
8 3 have part 2 of magic key
16 4 have part 3 of magic key
32 5 rescued Sarah
64 6 rescued Harry
128 7 exited Purple Tower by gate
256 8 met defector
512 9 killed two-headed troll
1024 10 stamped by gandalf
2048 11 endgame bomb found
4096 12 endgame bomb placed
8192 13 endgame bomb detonated
Before I continue, I should post these lists of bit mask numbers useful for bitwise operations, particularly flags.
(Moderator, if you want, I can copy this message to a new one, and you can link to it, as a tutorial, from [u]ACK Documentation, Online References, etc.[/u])
Variables A-G and A2-G2 are 8-bit ones, holding values of zero to 255. Since they are 8-bit, they can contain up to 8 one-bit flags, with the following masks:
[code]
BIT A B
00 1 254
01 2 253
02 4 251
03 8 247
04 16 239
05 32 223
06 64 191
07 128 127[/code]
BIT = bit number, starting from 0.
A = decimal mask value, used for setting and testing. (Power of 2)
B = inverse mask value, used for clearing. (255 minus A)
[list]To set bit 4 in variable C:
SET C = C | 16
To clear bit 6 in variable G2:
SET G2 = G2 & 191
To test bit 1 in variable F:
IF F & 2 THEN ...
To clear all bits of variable B2:
SET B2 = 0
To set all bits of variable B2:
SET B2 = 255[/list]
If you need to use the other variables (H-Z and H2-Z2), they are 16-bit, going from 0 to 65535:
[code]
BIT A B C
00 1 65534 -2
01 2 65533 -3
02 4 65531 -5
03 8 65527 -10
04 16 65519 -17
05 32 65503 -33
06 64 65471 -65
07 128 65407 -129
08 256 65279 -257
09 512 65023 -513
10 1024 64511 -1025
11 2048 63487 -2049
12 4096 61439 -4097
13 8192 57343 -8193
14 16384 49151 -16385
15 32768 32767 32767
(-32768)
[/code]
BIT = bit number, starting from 0.
A = decimal mask value, used for setting and testing.
B = inverse mask value, used for clearing. (65535-A)
C = inverse mask value as negative number.
Note that the ACK macro editor displays numbers greater than 32767 as negatives, using the formula C = B - 65536. You need to type in the number as a positive one from column B, but it displays as a negative one from column C.
Usage is much the same as with the 8-bit variables, except that setting all bits means setting to 65535. For an example, to test bit 12 of Q2:
IF Q2 & 4096 THEN ...
To use variables efficiently, make a list of all flags needed in the game, set aside however many variables are needed, and assign each flag to a specific bit from these variables. You need to make a list somewhat like this, and store it on paper or in your documentation text file:
[code]
Variable I2 - Game Progress Flag
1 0 talked to everyone in town
2 1 met elven ranger
4 2 have part 1 of magic key
8 3 have part 2 of magic key
16 4 have part 3 of magic key
32 5 rescued Sarah
64 6 rescued Harry
128 7 exited Purple Tower by gate
256 8 met defector
512 9 killed two-headed troll
1024 10 stamped by gandalf
2048 11 endgame bomb found
4096 12 endgame bomb placed
8192 13 endgame bomb detonated[/code]