File: pick2.h

package info (click to toggle)
intercal 30:0.30-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,044 kB
  • sloc: ansic: 8,936; sh: 1,274; yacc: 1,073; lex: 518; lisp: 460; makefile: 435; perl: 295
file content (225 lines) | stat: -rw-r--r-- 4,521 bytes parent folder | download | duplicates (5)
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
 * pick2.h - Runtime library for INTERCAL, for use by PIC C compilers
 *
 * Some of the code here was originally in fiddle.c, some was originally
 * in cesspool.c. The rest is a translation into C of syslib.i.
 *
LICENSE TERMS
    Copyright (C) 1996 Eric S. Raymond
    Copyright (C) 2006 Alex Smith

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#define ick_resume ick_popnext

ICK_INT32 ick_mingle(ICK_INT16 r, ICK_INT16 s)
{
  r = ((r & 0x0000ff00) << 8) | (r & 0x000000ff);
  r = ((r & 0x00f000f0) << 4) | (r & 0x000f000f);
  r = ((r & 0x0c0c0c0c) << 2) | (r & 0x03030303);
  r = ((r & 0x22222222) << 1) | (r & 0x11111111);
  s = ((s & 0x0000ff00) << 8) | (s & 0x000000ff);
  s = ((s & 0x00f000f0) << 4) | (s & 0x000f000f);
  s = ((s & 0x0c0c0c0c) << 2) | (s & 0x03030303);
  s = ((s & 0x22222222) << 1) | (s & 0x11111111);
  return (r << 1) | s;
}

ICK_INT32 ick_iselect(ICK_INT32 r, ICK_INT32 s)
{
  ICK_INT32 i = 1, t = 0;
  while (s) {
    if (s & i) {
   	t |= r & i;
   	s ^= i;
   	i <<= 1;
    }
    else {
   	s >>= 1;
   	r >>= 1;
    }
  }
  return t;
}

ICK_INT16 ick_and16(ICK_INT16 n)
{
  ICK_INT16 m;
  m = (n >> 1);
  if (n & 1)
  m |= 0x8000;
  return(m & n);
}

ICK_INT16 ick_or16(ICK_INT16 n)
{
  ICK_INT16 m;
  m = (n >> 1);
  if (n & 1)
    m |= 0x8000;
  return(m | n);
}

ICK_INT32 ick_and32(ICK_INT32 n)
{
  ICK_INT32 m;
  m = (n >> 1);
  if (n & 1)
    m |= 0x80000000;
  return(m & n);
}

ICK_INT32 ick_or32(ICK_INT32 n)
{
  ICK_INT32 m;
  m = (n >> 1);
  if (n & 1)
    m |= 0x80000000;
  return(m | n);
}

ICK_INT16 ick_xor16(ICK_INT16 n)
{
  ICK_INT16 m;
  m = (n >> 1);
  if (n & 1)
    m |= 0x8000;
  return(m ^ n);
}

ICK_INT32 ick_xor32(ICK_INT32 n)
{
  ICK_INT32 m;
  m = (n >> 1);
  if (n & 1)
    m |= 0x80000000;
  return(m ^ n);
}

ICK_INT8 ick_nextindex = 0;
ICK_INT16 ick_next[16];

void ick_pushnext(ICK_INT16 n)
{
	ick_next[ick_nextindex++] = n;
}

ICK_INT16 ick_popnext(ICK_INT8 n)
{
    if (ick_nextindex < n) {
   	ick_nextindex = 0;
   	return (ICK_INT16)-1;
    }
    else
      ick_nextindex -= n;
    return(ick_next[ick_nextindex]);
}

/* It's hard to do randomization on a PIC. */
ICK_INT1 ick_roll(ICK_INT8 n)
{
   return n>50;
}

/* Syslib, implemented in C to save ROM space. */
#if defined(ONESPOT1)&&defined(ONESPOT2)&&defined(TWOSPOT1)
void syslibopt1050()
{
   ONESPOT2=0;
   if(ONESPOT1) ONESPOT2=TWOSPOT1/ONESPOT1;
}
void syslibopt1520()
{
   TWOSPOT1=((ICK_INT32)ONESPOT1<<16)|ONESPOT2;
}
#endif /* .1 .2 :1 */
#if defined(TWOSPOT1)&&defined(TWOSPOT2)&&defined(TWOSPOT3)
void syslibopt1550()
{
   TWOSPOT3=0;
   if(TWOSPOT2) TWOSPOT3=TWOSPOT1/TWOSPOT2;
}
void syslipopt1500()
{
   TWOSPOT3=TWOSPOT2+TWOSPOT1;
}
void syslibopt1510()
{
   TWOSPOT3=TWOSPOT1-TWOSPOT2;
}
void syslibopt1530()
{
   TWOSPOT3=TWOSPOT1*TWOSPOT2;
}
void syslibopt1540()
{
   TWOSPOT3=0;
   if(TWOSPOT2) TWOSPOT3=TWOSPOT1/TWOSPOT2;
}
#ifdef TWOSPOT4
void syslibopt1509()
{
   TWOSPOT3=TWOSPOT2+TWOSPOT1;
   TWOSPOT4=1;
   if(TWOSPOT3<TWOSPOT2) TWOSPOT4=2; /* overflow */
}
void syslibopt1539()
{
   TWOSPOT4=1;
   if(TWOSPOT2&&TWOSPOT1>0xffffffff/TWOSPOT2) TWOSPOT4=2;
   TWOSPOT3=TWOSPOT1*TWOSPOT2;
}
#endif /* :4 */
#endif /* :1 :2 :3 */
#if defined(ONESPOT1)&&defined(ONESPOT2)&&defined(ONESPOT3)
void syslipopt1000()
{
   ONESPOT3=ONESPOT2+ONESPOT1;
}
void syslibopt1010()
{
   ONESPOT3=ONESPOT1-ONESPOT2;
}
void syslibopt1030()
{
   ONESPOT3=ONESPOT1*ONESPOT2;
}
void syslibopt1040()
{
   ONESPOT3=0;
   if(ONESPOT2) ONESPOT3=ONESPOT1/ONESPOT2;
}
#ifdef ONESPOT4
void syslibopt1009()
{
   ONESPOT3=ONESPOT2+ONESPOT1;
   ONESPOT4=1;
   if(ONESPOT3<ONESPOT2) ONESPOT4=2; /* overflow */
}
void syslibopt1039()
{
   ONESPOT4=1;
   if(ONESPOT2&&ONESPOT1>0xffff/ONESPOT2) ONESPOT4=2;
   ONESPOT3=ONESPOT1*ONESPOT2;
}
#endif /* .4 */
#endif /* .1 .2 .3 */
#ifdef ONESPOT1
void syslibopt1020()
{
   ONESPOT1++;
}
#endif