summaryrefslogblamecommitdiff
path: root/world/map/npc/functions/bitwise.txt
blob: fe851f15185e4e8960d5ddcb4d19bc9c62e4aba5 (plain) (tree)

















































































































































                                                                                 
// ALL functions here are call()-only

// A Byte can go up to 255. There are 4 bytes. The fourth can go up to 127.
// get_byte(VAR, BYTEID)
function|script|get_byte
{
    set .@v, getarg(0);
    set .@id, getarg(1);
    if (.@id == 0) goto L_Byte0;
    if (.@id == 1) goto L_Byte1;
    if (.@id == 2) goto L_Byte2;
    if (.@id == 3) goto L_Byte3;
    debugmes "get_byte invalid call";
    return -1;

L_Byte0:
    return (.@v & BYTE_0_MASK) >> BYTE_0_SHIFT;

L_Byte1:
    return (.@v & BYTE_1_MASK) >> BYTE_1_SHIFT;

L_Byte2:
    return (.@v & BYTE_2_MASK) >> BYTE_2_SHIFT;

L_Byte3:
    return (.@v & BYTE_3_MASK) >> BYTE_3_SHIFT;
}

// A Nibble can go up to 15. There are 7 nibbles..
// get_nibble(VAR, BYTEID)
function|script|get_nibble
{
    set .@v, getarg(0);
    set .@id, getarg(1);
    if (.@id == 0) goto L_Nibble0;
    if (.@id == 1) goto L_Nibble1;
    if (.@id == 2) goto L_Nibble2;
    if (.@id == 3) goto L_Nibble3;
    if (.@id == 4) goto L_Nibble4;
    if (.@id == 5) goto L_Nibble5;
    if (.@id == 6) goto L_Nibble6;
    debugmes "get_byte invalid call";
    return -1;

L_Nibble0:
    return (.@v & NIBBLE_0_MASK) >> NIBBLE_0_SHIFT;

L_Nibble1:
    return (.@v & NIBBLE_1_MASK) >> NIBBLE_1_SHIFT;

L_Nibble2:
    return (.@v & NIBBLE_2_MASK) >> NIBBLE_2_SHIFT;

L_Nibble3:
    return (.@v & NIBBLE_3_MASK) >> NIBBLE_3_SHIFT;

L_Nibble4:
    return (.@v & NIBBLE_4_MASK) >> NIBBLE_4_SHIFT;

L_Nibble5:
    return (.@v & NIBBLE_5_MASK) >> NIBBLE_5_SHIFT;

L_Nibble6:
    return (.@v & NIBBLE_6_MASK) >> NIBBLE_6_SHIFT;

// In theory, there's a "nibble 7" but it is broken so it is not available
}

/////////////////////////////////////////////////////////////////////////////////
// A Byte can go up to 255. There are 4 bytes. The fourth can go up to 127.
// set_byte(VAR, BYTEID, VALUE)
function|script|set_byte
{
    set .@v, getarg(0);
    set .@id, getarg(1);
    if (.@id == 0) goto L_Byte0;
    if (.@id == 1) goto L_Byte1;
    if (.@id == 2) goto L_Byte2;
    if (.@id == 3) goto L_Byte3;
    debugmes "get_byte invalid call";
    return -1;

L_Byte0:
    set getarg(0), ((.@v & ~(BYTE_0_MASK)) | (getarg(2) << BYTE_0_SHIFT));
    return;

L_Byte1:
    set getarg(0), ((.@v & ~(BYTE_1_MASK)) | (getarg(2) << BYTE_1_SHIFT));
    return;

L_Byte2:
    set getarg(0), ((.@v & ~(BYTE_2_MASK)) | (getarg(2) << BYTE_2_SHIFT));
    return;

L_Byte3:
    set getarg(0), ((.@v & ~(BYTE_3_MASK)) | (getarg(2) << BYTE_3_SHIFT));
    return;
}



// A Nibble can go up to 15. There are 7 nibbles..
// get_nibble(VAR, NIBBLEID, VALUE)
function|script|set_nibble
{
    set .@v, getarg(0);
    set .@id, getarg(1);
    if (.@id == 0) goto L_Nibble0;
    if (.@id == 1) goto L_Nibble1;
    if (.@id == 2) goto L_Nibble2;
    if (.@id == 3) goto L_Nibble3;
    if (.@id == 4) goto L_Nibble4;
    if (.@id == 5) goto L_Nibble5;
    if (.@id == 6) goto L_Nibble6;
    debugmes "get_byte invalid call";
    return -1;

L_Nibble0:
    set getarg(0), ((.@v & ~(NIBBLE_0_MASK)) | (getarg(2) << NIBBLE_0_SHIFT));
    return;

L_Nibble1:
    set getarg(0), ((.@v & ~(NIBBLE_1_MASK)) | (getarg(2) << NIBBLE_1_SHIFT));
    return;

L_Nibble2:
    set getarg(0), ((.@v & ~(NIBBLE_2_MASK)) | (getarg(2) << NIBBLE_2_SHIFT));
    return;

L_Nibble3:
    set getarg(0), ((.@v & ~(NIBBLE_3_MASK)) | (getarg(2) << NIBBLE_3_SHIFT));
    return;

L_Nibble4:
    set getarg(0), ((.@v & ~(NIBBLE_4_MASK)) | (getarg(2) << NIBBLE_4_SHIFT));
    return;

L_Nibble5:
    set getarg(0), ((.@v & ~(NIBBLE_5_MASK)) | (getarg(2) << NIBBLE_5_SHIFT));
    return;

L_Nibble6:
    set getarg(0), ((.@v & ~(NIBBLE_6_MASK)) | (getarg(2) << NIBBLE_6_SHIFT));
    return;
}