From The Mana World
m (Wushin moved page Bit mask tutorial to Dev:Bit mask tutorial)
m (Move page script moved page Dev:Bit mask tutorial to Development:Bit mask tutorial: Rename Dev: to Development: so the miraheze import works)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:


==Bit Masking Easy Reference Chart==
==Bit Masking Easy Reference Chart==
         |-------------------------------------------------------------------------------------|
<table>
  Byte  |0             |1                   |2                     |3                     |
    <tr>
         |-------------------------------------------------------------------------------------|
        <th>long word</th>
Nibble |0     |1     |2       |3         |4         |5         |6         |7         |
        <td colspan="32">0</td>
         |-------------------------------------------------------------------------------------|
    </tr>
2 Bits |0 |1 |2 |3 |4 |5   |6   |7   |8   |9   |10   |11   |12   |13   |14   |15   |
    <tr>
         |-------------------------------------------------------------------------------------|
        <th>word</th>
Bits  |0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31|
        <td colspan="16">0</td><td colspan="16">1</td>
        |-------------------------------------------------------------------------------------|
    </tr>
    <tr>
         <th>byte</th>
        <td colspan="8">0</td><td colspan="8">1</td><td colspan="8">2</td><td colspan="8">3</td>
    </tr>
    <tr>
         <th>nibble</th>
        <td colspan="4">0</td><td colspan="4">1</td><td colspan="4">2</td><td colspan="4">3</td>
        <td colspan="4">4</td><td colspan="4">5</td><td colspan="4">6</td><td colspan="4">7</td>
    </tr>
    <tr>
         <th>2-bit</th>
        <td colspan="2">0</td><td colspan="2">1</td><td colspan="2">2</td><td colspan="2">3</td>
        <td colspan="2">4</td><td colspan="2">5</td><td colspan="2">6</td><td colspan="2">7</td>
        <td colspan="2">8</td><td colspan="2">9</td><td colspan="2">10</td><td colspan="2">11</td>
        <td colspan="2">12</td><td colspan="2">13</td><td colspan="2">14</td><td colspan="2">15</td>
    </tr>
    <tr>
         <th>bit</th>
        <td>0</td><td>1</td><td>2</td><td>3</td>
        <td>4</td><td>5</td><td>6</td><td>7</td>
        <td>8</td><td>9</td><td>10</td><td>11</td>
        <td>12</td><td>13</td><td>14</td><td>15</td>
        <td>16</td><td>17</td><td>18</td><td>19</td>
        <td>20</td><td>21</td><td>22</td><td>23</td>
        <td>24</td><td>25</td><td>26</td><td>27</td>
        <td>28</td><td>29</td><td>30</td><td>31</td>
    </tr>
</table>


* All variables haves 4 Bytes, 8 Nibbles, 16 2Bits and/or 32 bits.
* All variables haves 1 Long Word, 2 Words, 4 Bytes, 8 Nibbles, 16 2Bits and/or 32 bits.
** Byte range 0-255
** Byte range 0-255
** Nibble range 0-15
** Nibble range 0-15

Latest revision as of 03:56, 27 March 2024

Bit Masking Easy Reference Chart

long word 0
word 01
byte 0123
nibble 0123 4567
2-bit 0123 4567 891011 12131415
bit 0123 4567 891011 12131415 16171819 20212223 24252627 28293031
  • All variables haves 1 Long Word, 2 Words, 4 Bytes, 8 Nibbles, 16 2Bits and/or 32 bits.
    • Byte range 0-255
    • Nibble range 0-15
    • 2Bit range 0-3
    • bit range 0 or 1

One Nibble Translated

  • Binary = Decimal
    • 0000 = 0
    • 0001 = 1
    • 0010 = 2
    • 0011 = 3
    • 0100 = 4
    • 0101 = 5
    • 0110 = 6
    • 0111 = 7
    • 1000 = 8
    • 1001 = 9
    • 1010 = 10
    • 1011 = 11
    • 1100 = 12
    • 1101 = 13
    • 1110 = 14
    • 1111 = 15
      • Note: Therefore Setting Bits 4-7 to 1 will make Nibble 1 15. Therefore Setting Bits 0-7 will make Nibble 0 & 1 15, and Byte 0 255

Linear Quest Var

  • BYTE:
    • 0: Step1.
    • 1: Step2.
    • ...
    • 255: Step256.
  • Nibble:
    • 0: Step1.
    • 1: Step2.
    • ...
    • 14: Step16.

Non-linear Quest Var

  • BYTE: Main Quest Line
    • NIBBLE: Current-Step
      • BIT: Step
      • BIT: Step
      • BIT: Step
      • BIT: Step
    • NIBBLE: Sub-Quest
      • 0-15: Step 1-16

Dev Note: There are plans to make 64 bit quest variables.


001-1,40,36,0|script|BitMaskDebug|175 {

   mes "[Bit Mask Debug]";
   mes "\"What you wyou like to do?\"";
   menu
       "Shift Byte 1.", L_ByteShift,
       "Shift Nibble 0.", L_NibbleShift,
       "Shift Bit 4.", L_BitShift,
       "Done.", L_Close;

L_ByteShift:

   set @debugexample, ((DEBUGEXAMPLE & BYTE_1_MASK) >> BYTE_1_SHIFT);
   message strcharinfo(0), @debugexample;
   if (@debugexample == 175) 
       goto L_ByteUnset;
   mes "Byte 1 set to 175";
   set DEBUGEXAMPLE, (DEBUGEXAMPLE & ~(BYTE_1_MASK) | (175 << BYTE_1_SHIFT));
   goto L_Close;

L_ByteUnset:

   mes "Byte 1 set to 0";
   set DEBUGEXAMPLE, (DEBUGEXAMPLE & ~(BYTE_1_MASK) | (0 << BYTE_1_SHIFT));
   goto L_Close;

L_NibbleShift:

   set @debugexample, ((DEBUGEXAMPLE & NIBBLE_0_MASK) >> NIBBLE_0_SHIFT);
   message strcharinfo(0), @debugexample;
   if (@debugexample == 10) 
       goto L_NibbleUnset;
   mes "Nibble 0 set to 10";
   set DEBUGEXAMPLE, (DEBUGEXAMPLE & ~(NIBBLE_0_MASK) | (10 << NIBBLE_0_SHIFT));
   goto L_Close;

L_NibbleUnset:

   mes "Nibble 0 set to 0";
   set DEBUGEXAMPLE, (DEBUGEXAMPLE & ~(NIBBLE_0_MASK) | (0 << NIBBLE_0_SHIFT));
   goto L_Close;

L_BitShift:

   set @debugexample, ((DEBUGEXAMPLE & NIBBLE_1_MASK) >> NIBBLE_1_SHIFT);
   message strcharinfo(0), @debugexample;
   if (DEBUGEXAMPLE & (1 << 4))
       goto L_BitUnset; 
   mes "Bit 4 Set to 1";
   set DEBUGEXAMPLE, DEBUGEXAMPLE | (1 << 4);
   set DEBUGEXAMPLE, DEBUGEXAMPLE | (1 << 5);
   set DEBUGEXAMPLE, DEBUGEXAMPLE | (1 << 6);
   set DEBUGEXAMPLE, DEBUGEXAMPLE | (1 << 7);
   goto L_Close;

L_BitUnset:

   mes "Bit 4 Set to 0";
   set DEBUGEXAMPLE, DEBUGEXAMPLE &~ (1 << 4);
   set DEBUGEXAMPLE, DEBUGEXAMPLE &~ (1 << 5);
   set DEBUGEXAMPLE, DEBUGEXAMPLE &~ (1 << 6);
   set DEBUGEXAMPLE, DEBUGEXAMPLE &~ (1 << 7);
   goto L_Close;

L_Close:

   set @debugexample, 0;
   close;

OnInit:

   if (debug)
       end;
   disablenpc "BitMaskDebug";
   end;

}