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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 1999-2000 by Carl-Eric Codere,
member of the Free Pascal development team.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
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.
**********************************************************************}
{*************************************************************************}
{ Converted by Carl Eric Codere }
{*************************************************************************}
{ This inc. implements low-level set operations for the motorola }
{ 68000 familiy of processors. }
{ Based on original code bt Florian Kl„mpfl for the 80x86. }
{*************************************************************************}
{ add the element b to the set pointed by p }
{ On entry }
{ a0 = pointer to set }
{ d0.b = element to add to the set }
{ Registers destroyed: d0,a1,d6 }
procedure do_set;assembler;
asm
XDEF SET_SET_BYTE
move.l d0,d6
{ correct long position: }
{ -> (value div 32)*4 = longint }
{ (value shr 5)*shl 2 }
lsr.l #5,d6
lsl.l #2,d6
adda.l d6,a0 { correct offset from start address of set }
move.l d0,d6 { bit is now in here }
andi.l #31,d0 { bit number is = value mod 32 }
{ now bit set the value }
move.l (a0),d0 { we must put bits into register }
bset.l d6,d0 { otherwise btst will be a byte }
{ put result in carry flag } { operation. }
bne @LDOSET1
andi.b #$fe,ccr { clear carry flag }
bra @LDOSET2
@LDOSET1:
ori.b #$01,ccr { set carry flag }
@LDOSET2:
move.l d0,(a0) { restore the value at that location }
{ of the set. }
end;
{ Finds an element in a set }
{ a0 = address of set }
{ d0.b = value to compare with }
{ CARRY SET IF FOUND ON EXIT }
{ Registers destroyed: d0,a0,d6 }
procedure do_in; assembler;
{ Returns Carry set then = in set , otherwise carry is cleared }
{ (D0) }
asm
XDEF SET_IN_BYTE
move.l d0,d6
{ correct long position: }
{ -> (value div 32)*4 = longint }
{ (value shr 5)*shl 2 }
lsr.l #5,d6
lsl.l #2,d6
adda.l d6,a0 { correct offset from start address of set }
move.l d0,d6 { bit is now in here }
andi.l #31,d0 { bit number is = value mod 32 }
move.l (a0),d0 { we must put bits into register }
btst.l d6,d0 { otherwise btst will be a byte }
{ put result in carry flag } { operation. }
bne @LDOIN1
andi.b #$fe,ccr { clear carry flag }
bra @LDOIN2
@LDOIN1:
ori.b #$01,ccr { set carry flag }
@LDOIN2:
end;
{ vereinigt set1 und set2 und speichert das Ergebnis in dest }
procedure add_sets(set1,set2,dest : pointer);[public,alias: 'SET_ADD_SETS'];
{ PSEUDO-CODE:
type
destination = array[1..8] of longint;
for i:=1 to 8 do
destination(dest^)[i] := destination(set1^)[i] OR destination(set2^)[i];
}
begin
asm
{ saved used register }
move.l a2,-(sp)
move.l 8(a6),a0
move.l 12(a6),a1
move.l 16(a6),a2
move.l #32,d6
@LMADDSETS1:
move.b (a0)+,d0
or.b (a1)+,d0
move.b d0,(a2)+
subq.b #1,d6
bne @LMADDSETS1
{ restore register }
move.l a2,(sp)+
end ['d0','d6','a0','a1'];
end;
{ computes the symetric diff from set1 to set2 }
{ result in dest }
procedure sym_sub_sets(set1,set2,dest : pointer);[public,alias: 'SET_SYMDIF_SETS'];
begin
asm
{ saved used register }
move.l a2,-(sp)
move.l 8(a6),a0
move.l 12(a6),a1
move.l 16(a6),a2
move.l #32,d6
@LMADDSETS1:
move.b (a0)+,d0
move.b (a1)+,d1
eor.b d1,d0
move.b d0,(a2)+
subq.b #1,d6
bne @LMADDSETS1
{ restore register }
move.l a2,(sp)+
end;
end;
{ bad implementation, but it's very seldom used }
procedure do_set(p : pointer;l,h : byte);[public,alias: 'SET_SET_RANGE'];
begin
asm
move.b h,d0
@LSetRLoop:
cmp.b l,d0
blt @Lend
move.w d0,-(sp)
{ adjust value to correct endian }
lsl.w #8,d0
pea p
// jsr SET_SET_BYTE
sub.b #1,d0
bra @LSetRLoop
@Lend:
end;
end;
{ bildet den Durchschnitt von set1 und set2 }
{ und speichert das Ergebnis in dest }
procedure mul_sets(set1,set2,dest : pointer);[public,alias: 'SET_MUL_SETS'];
{ type
larray = array[0..7] of longint;
for i:=0 to 7 do
larray(dest^)[i] := larray(set1^)[i] AND larray(set2^)[i];
}
begin
asm
{ saved used register }
move.l a2,-(sp)
move.l 8(a6),a0
move.l 12(a6),a1
move.l 16(a6),a2
move.l #32,d6
@LMMULSETS1:
move.b (a0)+,d0
and.b (a1)+,d0
move.b d0,(a2)+
subq.b #1,d6
bne @LMMULSETS1
{ restore register }
move.l a2,(sp)+
end ['d0','d6','a0','a1'];
end;
{ bildet die Differenz von set1 und set2 }
{ und speichert das Ergebnis in dest }
procedure sub_sets(set1,set2,dest : pointer);[public,alias: 'SET_SUB_SETS'];
{ type
larray = array[0..7] of longint;
begin
for i:=0 to 7 do
larray(dest^)[i] := larray(set1^)[i] AND NOT (larray(set2^)[i]);
end;
}
begin
asm
{ saved used register }
move.l a2,-(sp)
move.l 8(a6),a0
move.l 12(a6),a1
move.l 16(a6),a2
move.l #32,d6
@LSUBSETS1:
move.b (a0)+,d0
move.b (a1)+,d1
not.b d1
and.b d1,d0
move.b d0,(a2)+
sub.b #1,d6
bne @LSUBSETS1
{ restore register }
move.l a2,(sp)+
end ['d0','d1','d6','a0','a1'];
end;
{ compare both sets }
{ compares set1 and set2 }
{ zeroflag is set if they are equal }
{ on entry : a0 = pointer to first set }
{ : a1 = pointer to second set }
procedure comp_sets; assembler;
asm
XDEF SET_COMP_SETS
move.l #32,d6
@LMCOMPSETS1:
move.b (a0)+,d0
move.b (a1),d1
cmp.b d1,d0
bne @LMCOMPSETEND
adda.l #1,a1
sub.b #1,d6
bne @LMCOMPSETS1
{ we are here only if the two sets are equal }
{ we have zero flag set, and that what is expected }
cmp.b d0,d0
@LMCOMPSETEND:
end;
procedure do_set(p : pointer;b : word);[public,alias: 'SET_SET_WORD'];
begin
asm
move.l 8(a6),a0
move.w 12(a6),d6
andi.l #$fff8,d6
lsl.l #3,d6
adda.l d6,a0
move.b 12(a6),d6
andi.l #7,d6
move.l (a0),d0 { we must put bits into register }
btst.l d6,d0 { otherwise btst will be a byte }
{ put result in carry flag } { operation. }
bne @LBIGDOSET1
andi.b #$fe,ccr { clear carry flag }
bra @LBIGDOSET2
@LBIGDOSET1:
ori.b #$01,ccr { set carry flag }
@LBIGDOSET2:
end ['d0','a0','d6'];
end;
{ testet, ob das Element b in der Menge p vorhanden ist }
{ und setzt das Carryflag entsprechend }
procedure do_in(p : pointer;b : word);[public,alias: 'SET_IN_WORD'];
begin
asm
move.l 8(a6),a0
move.w 12(a6),d6
andi.l #$fff8,d6
lsl.l #3,d6
adda.l d6,a0 { correct offset from start address of set }
move.b 12(a6),d6
andi.l #7,d6
move.l (a0),d0 { we must put bits into register }
btst.l d6,d0 { otherwise btst will be a byte }
{ put result in carry flag } { operation. }
bne @LBIGDOIN1
andi.b #$fe,ccr { clear carry flag }
bra @LBIGDOIN2
@LBIGDOIN1:
ori.b #$01,ccr { set carry flag }
@LBIGDOIN2:
end ['d0','a0','d6'];
end;
{ vereinigt set1 und set2 und speichert das Ergebnis in dest }
{ size is the number of bytes in the set }
procedure add_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_ADD_SETS_SIZE'];
begin
asm
{ saved used register }
move.l a2,-(sp)
move.l 8(a6),a0
move.l 12(a6),a1
move.l 16(a6),a2
move.l 20(a6),d6
@LBIGMADDSETS1:
move.l (a0)+,d0
or.l (a1)+,d0
move.l d0,(a2)+
subq.l #4,d6
bne @LBIGMADDSETS1
{ restore register }
move.l a2,(sp)+
end ['d0','d6','a0','a1'];
end;
procedure mul_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_MUL_SETS_SIZE'];
{ bildet den Durchschnitt von set1 und set2 }
{ und speichert das Ergebnis in dest }
{ size is the number of bytes in the set }
begin
asm
{ saved used register }
move.l a2,-(sp)
move.l 8(a6),a0
move.l 12(a6),a1
move.l 16(a6),a2
move.l 20(a6),d6
@LBIGMMULSETS1:
move.l (a0)+,d0
and.l (a1)+,d0
move.l d0,(a2)+
subq.l #4,d6
bne @LBIGMMULSETS1
{ restore register }
move.l a2,(sp)+
end ['d0','d6','a0','a1'];
end;
{ bildet die Differenz von set1 und set2 }
{ und speichert das Ergebnis in dest }
{ size is the number of bytes in the set }
procedure sub_sets(set1,set2,dest : pointer;size : longint);[public,alias: 'SET_SUB_SETS_SIZE'];
begin
asm
{ saved used register }
move.l a2,-(sp)
move.l 8(a6),a0
move.l 12(a6),a1
move.l 16(a6),a2
move.l 20(a6),d6
@BIGSUBSETS1:
move.l (a0)+,d0
not.l d0
and.l (a1)+,d0
move.l d0,(a2)+
subq.l #4,d6
bne @BIGSUBSETS1
{ restore register }
move.l a2,(sp)+
end ['d0','d6','a0','a1'];
end;
{ vergleicht Mengen und setzt die Flags entsprechend }
procedure comp_sets(set1,set2 : pointer;size : longint);[public,alias: 'SET_COMP_SETS_SIZE'];
begin
asm
move.l 8(a6),a0 { set1 - esi}
move.l 12(a6),a1 { set2 - edi }
move.l 16(a6),d6
@MCOMPSETS1:
move.l (a0)+,d0
move.l (a1),d1
cmp.l d1,d0
bne @BIGMCOMPSETEND
add.l #4,a1
subq.l #1,d6
bne @MCOMPSETS1
{ we are here only if the two sets are equal }
{ we have zero flag set, and that what is expected }
cmp.l d0,d0
@BIGMCOMPSETEND:
end;
end;
|