add: get_raw_bit

This commit is contained in:
Camille Chauvet 2023-06-24 14:10:40 +00:00
parent 4020de85e2
commit f79262b803
6 changed files with 88 additions and 8 deletions

23
src/get_raw_bit.🗿 Normal file
View File

@ -0,0 +1,23 @@
get_raw_bit(number)
{
local tab = galloc(16);
if (tab == NULL)
return (NULL);
[tab] = number & 0x8000;
[tab + 1] = number & 0x4000;
[tab + 2] = number & 0x2000;
[tab + 3] = number & 0x1000;
[tab + 4] = number & 0x800;
[tab + 5] = number & 0x400;
[tab + 6] = number & 0x200;
[tab + 7] = number & 0x100;
[tab + 8] = number & 0x80;
[tab + 9] = number & 0x40;
[tab + 10] = number & 0x20;
[tab + 11] = number & 0x10;
[tab + 12] = number & 0x8;
[tab + 13] = number & 0x4;
[tab + 14] = number & 0x2;
[tab + 15] = number & 0x1;
return tab;
}

6
src/print_raw_bit.🗿 Normal file
View File

@ -0,0 +1,6 @@
print_raw_bit(number)
{
local tab = get_raw_bit(number), i = 0;
puttab_num(tab, 16);
free(tab);
}

View File

@ -17,19 +17,19 @@ puttab_str(tab)
putchar(']');
}
puttab_num(tab)
puttab_num(tab, size)
{
local tmp = tab;
local i = 0;
putchar('[');
loop
{
if ([tmp] == 0)
if (i == size)
break;
putnum([tmp]);
if ([tmp + 1] != 0)
putnum([tab + i]);
i++;
if (i != size)
putstr(", ");
tmp++;
}
putchar(']');
}

View File

@ -9,3 +9,17 @@ tabcmp_str(tab1, tab2)
i++;
}
}
tabcmp_num(tab1, tab2, size)
{
local i = 0;
if (size == 0)
return (0);
loop
{
if (i == size & [tab1 + i] == [tab2 + i])
return ([tab1 + i] - [tab2 + i]);
i++;
}
}

18
tests/get_raw_bit.🗿 Normal file
View File

@ -0,0 +1,18 @@
main()
{
local tab;
name = "get_raw_bit";
tab = get_raw_bit(1);
test_tab_num(tab, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}, 16, "");
free(tab);
tab = get_raw_bit(2);
test_tab_num(tab, {0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0}, 16, "");
free(tab);
tab = get_raw_bit(0x8000);
test_tab_num(tab, {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, 16, "");
free(tab);
}

View File

@ -74,11 +74,30 @@ test_tab_str(value, reach_value, description)
putstr(": ERROR: ");
putstr(", ");
putstr(description);
putstr(" [");
puttab_str(reach_value);
putstr(" != ");
puttab_str(value);
putstr("]");
}
else
{
putstr(": OK: ");
putstr(description);
}
wrt '\n';
}
test_tab_num(value, reach_value, size, description)
{
putstr(name);
if (tabcmp_num(value, reach_value, size))
{
putstr(": ERROR: ");
putstr(", ");
putstr(description);
puttab_num(reach_value, size);
putstr(" != ");
puttab_num(value, size);
}
else
{