do_sets.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Sources of the "SETS" group instructions
  3. */
  4. /* $Header$ */
  5. #include <em_abs.h>
  6. #include "global.h"
  7. #include "log.h"
  8. #include "trap.h"
  9. #include "mem.h"
  10. #include "text.h"
  11. #include "fra.h"
  12. PRIVATE bit_test(), create_set();
  13. DoINNl2(arg)
  14. size arg;
  15. {
  16. /* INN w: Bit test on w byte set (bit number on top of stack) */
  17. register size l = (L_arg_2() * arg);
  18. LOG(("@Y6 DoINNl2(%ld)", l));
  19. spoilFRA();
  20. bit_test(arg_w(l));
  21. }
  22. DoINNs(hob, wfac)
  23. long hob;
  24. size wfac;
  25. {
  26. /* INN w: Bit test on w byte set (bit number on top of stack) */
  27. register size l = (S_arg(hob) * wfac);
  28. LOG(("@Y6 DoINNs(%ld)", l));
  29. spoilFRA();
  30. bit_test(arg_w(l));
  31. }
  32. DoINNz()
  33. {
  34. /* INN w: Bit test on w byte set (bit number on top of stack) */
  35. register size l = upop(wsize);
  36. LOG(("@Y6 DoINNz(%ld)", l));
  37. spoilFRA();
  38. bit_test(arg_w(l));
  39. }
  40. DoSETl2(arg)
  41. size arg;
  42. {
  43. /* SET w: Create singleton w byte set with bit n on (n is top of stack) */
  44. register size l = (L_arg_2() * arg);
  45. LOG(("@Y6 DoSETl2(%ld)", l));
  46. spoilFRA();
  47. create_set(arg_w(l));
  48. }
  49. DoSETs(hob, wfac)
  50. long hob;
  51. size wfac;
  52. {
  53. /* SET w: Create singleton w byte set with bit n on (n is top of stack) */
  54. register size l = (S_arg(hob) * wfac);
  55. LOG(("@Y6 DoSETs(%ld)", l));
  56. spoilFRA();
  57. create_set(arg_w(l));
  58. }
  59. DoSETz()
  60. {
  61. /* SET w: Create singleton w byte set with bit n on (n is top of stack) */
  62. register size l = upop(wsize);
  63. LOG(("@Y6 DoSETz(%ld)", l));
  64. spoilFRA();
  65. create_set(arg_w(l));
  66. }
  67. /********************************************************
  68. * bit testing *
  69. * *
  70. * Tests whether the bit with number to be found *
  71. * on TOS is on in 'w'-byte set. *
  72. * ON --> push 1 on stack. *
  73. * OFF -> push 0 on stack. *
  74. ********************************************************/
  75. PRIVATE bit_test(w)
  76. size w;
  77. {
  78. register int bitno =
  79. (int) spop(wsize); /* bitno on TOS */
  80. register char test_byte = (char) 0;/* default value to be tested */
  81. if (must_test && !(IgnMask&BIT(ESET))) {
  82. /* Only w<<3 bytes CAN be tested */
  83. if (bitno > (int) ((w << 3) - 1)) {
  84. trap(ESET);
  85. }
  86. }
  87. test_byte = stack_loc(SP + (bitno / 8));
  88. st_dec(w);
  89. npush((long)((test_byte & BIT(bitno % 8)) ? 1 : 0), wsize);
  90. }
  91. /********************************************************
  92. * set creation *
  93. * *
  94. * Creates a singleton 'w'-byte set with as *
  95. * singleton member, the bit with number on *
  96. * TOS. The w bytes constituting the set are *
  97. * pushed on the stack. *
  98. ********************************************************/
  99. PRIVATE create_set(w)
  100. size w;
  101. {
  102. register int bitno = (int) spop(wsize);
  103. register size nbytes = w;
  104. st_inc(nbytes);
  105. while (--nbytes >= 0) {
  106. st_stn(SP + nbytes, 0L, 1L);
  107. }
  108. if (must_test && !(IgnMask&BIT(ESET))) {
  109. if (bitno > (int) ((w << 3) - 1)) {
  110. trap(ESET);
  111. }
  112. }
  113. st_stn(SP + (bitno / 8), (long)BIT(bitno % 8), 1L);
  114. }