summaryrefslogtreecommitdiff
path: root/world/map/npc/functions/bitwise.txt
blob: fe851f15185e4e8960d5ddcb4d19bc9c62e4aba5 (plain) (blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// 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;
}