ack/util/int/do_sets.c

87 lines
1.8 KiB
C
Raw Permalink Normal View History

2019-03-17 14:42:00 +00:00
/** @file
* Sources of the "SETS" group instructions
1988-06-22 16:57:09 +00:00
*/
1994-06-24 11:31:16 +00:00
/* $Id$ */
1988-06-22 16:57:09 +00:00
2019-03-17 14:42:00 +00:00
#include "em_abs.h"
1988-06-22 16:57:09 +00:00
#include "global.h"
#include "log.h"
#include "trap.h"
#include "mem.h"
#include "text.h"
#include "fra.h"
#include "switch.h"
1988-06-22 16:57:09 +00:00
2019-03-17 14:42:00 +00:00
PRIVATE void bit_test(size), create_set(size);
1988-06-22 16:57:09 +00:00
2019-03-17 14:42:00 +00:00
/** INN w: Bit test on w byte set (bit number on top of stack) */
void DoINN(register size l)
1988-06-22 16:57:09 +00:00
{
LOG(("@Y6 DoINN(%ld)", l));
1988-06-22 16:57:09 +00:00
spoilFRA();
bit_test(arg_w(l));
}
2019-03-17 14:42:00 +00:00
/** SET w: Create singleton w byte set with bit n on (n is top of stack) */
void DoSET(register size l)
1988-06-22 16:57:09 +00:00
{
LOG(("@Y6 DoSET(%ld)", l));
1988-06-22 16:57:09 +00:00
spoilFRA();
create_set(arg_w(l));
}
2019-03-17 14:42:00 +00:00
/** Bit testing. Tests whether the bit with number to be found
* on TOS is on in 'w'-byte set.
* ON --> push 1 on stack.
* OFF -> push 0 on stack.
**/
PRIVATE void bit_test(size w)
1988-06-22 16:57:09 +00:00
{
register int bitno =
1989-11-22 13:38:37 +00:00
(int) swpop(); /* bitno on TOS */
1988-06-22 16:57:09 +00:00
register char test_byte = (char) 0;/* default value to be tested */
register int wordoff = bitno / 8;
register int bitoff = bitno % 8;
if (bitoff < 0) bitoff += 8;
1988-06-22 16:57:09 +00:00
if (must_test && !(IgnMask&BIT(ESET))) {
/* Only w*8 bits CAN be tested */
if (wordoff >= w) {
1988-06-22 16:57:09 +00:00
trap(ESET);
}
}
test_byte = stack_loc(SP + wordoff);
1988-06-22 16:57:09 +00:00
st_dec(w);
wpush((long)((test_byte & BIT(bitoff)) ? 1 : 0));
1988-06-22 16:57:09 +00:00
}
2019-03-17 14:42:00 +00:00
/** Set creation. Creates a singleton 'w'-byte set with as
* singleton member, the bit with number on TOS.
* The w bytes constituting the set are
* pushed on the stack.
**/
PRIVATE void create_set(size w)
1988-06-22 16:57:09 +00:00
{
1989-11-22 13:38:37 +00:00
register int bitno = (int) swpop();
1988-06-22 16:57:09 +00:00
register size nbytes = w;
register int wordoff = bitno / 8;
register int bitoff = bitno % 8;
if (bitoff < 0) bitoff += 8;
1988-06-22 16:57:09 +00:00
st_inc(nbytes);
while (--nbytes >= 0) {
st_stn(SP + nbytes, 0L, 1L);
}
if (must_test && !(IgnMask&BIT(ESET))) {
if (wordoff >= w) {
1988-06-22 16:57:09 +00:00
trap(ESET);
}
}
st_stn(SP + wordoff, (long)BIT(bitoff), 1L);
1988-06-22 16:57:09 +00:00
}