forked from amix/photoshop
-
Notifications
You must be signed in to change notification settings - Fork 1
/
UAssembly.a
736 lines (529 loc) · 11.4 KB
/
UAssembly.a
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
;Photoshop version 1.0.1, file: UAssembly.a
; Computer History Museum, www.computerhistory.org
; This material is (C)Copyright 1990 Adobe Systems Inc.
; It may not be distributed to third parties.
; It is licensed for non-commercial use according to
; www.computerhistory.org/softwarelicense/photoshop/
INCLUDE 'Traps.a'
; **********************************************************************
SEG 'ARes'
DoSetBytes PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoSetBytes (dataPtr: Ptr;
; count: LONGINT;
; value: INTEGER);
; Parameter Offsets
@dataPtr EQU 14
@count EQU 10
@value EQU 8
; Size of parameters
@params EQU 10
; Unload parameters
LINK A6,#0
MOVE.L @dataPtr(A6),A0
CLR.L D0
MOVE.W @value(A6),D0
AND.W #$FF,D0
MOVE.W D0,D1
LSL.W #8,D1
OR.W D1,D0
MOVE.L D0,D1
SWAP D1
OR.L D1,D0
MOVE.L @count(A6),D1
SUB.L #1,D1
; If count < 32 just do final loop
CMP.L #31,D1
BLT.S @2
; Set bytes until at long word boundary
@0 MOVE.L A0,D2
AND.L #3,D2
BEQ.S @1
MOVE.B D0,(A0)+
SUB.L #1,D1
BRA.S @0
; Set until fewer than 32 bytes left
@1 CMP.L #31,D1
BLT.S @2
SUB.L #32,D1
MOVE.L D0,(A0)+
MOVE.L D0,(A0)+
MOVE.L D0,(A0)+
MOVE.L D0,(A0)+
MOVE.L D0,(A0)+
MOVE.L D0,(A0)+
MOVE.L D0,(A0)+
MOVE.L D0,(A0)+
BRA.S @1
; Set remaining bytes
@2 TST.W D1
BMI.S @4
@3 MOVE.B D0,(A0)+
DBF D1,@3
; Clean up and exit
@4 UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
DoMapBytes PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoMapBytes (dataPtr: Ptr;
; count: LONGINT;
; map: TLookUpTable);
; Parameter Offsets
@dataPtr EQU 16
@count EQU 12
@map EQU 8
; Size of parameters
@params EQU 12
; Unload parameters
LINK A6,#0
MOVE.L @dataPtr(A6),A0
MOVE.L @map(A6),A1
MOVE.L @count(A6),D0
; Map bytes until fewer than 8 bytes left
CLR.W D1
@1 CMP.L #8,D0
BLT.S @2
SUB.L #8,D0
MOVE.B (A0),D1
MOVE.B (A1,D1.W),(A0)+
MOVE.B (A0),D1
MOVE.B (A1,D1.W),(A0)+
MOVE.B (A0),D1
MOVE.B (A1,D1.W),(A0)+
MOVE.B (A0),D1
MOVE.B (A1,D1.W),(A0)+
MOVE.B (A0),D1
MOVE.B (A1,D1.W),(A0)+
MOVE.B (A0),D1
MOVE.B (A1,D1.W),(A0)+
MOVE.B (A0),D1
MOVE.B (A1,D1.W),(A0)+
MOVE.B (A0),D1
MOVE.B (A1,D1.W),(A0)+
BRA.S @1
; Map remaining bytes
@2 TST.L D0
BEQ.S @3
SUB.L #1,D0
MOVE.B (A0),D1
MOVE.B (A1,D1.W),(A0)+
BRA.S @2
; Clean up and exit
@3 UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
DoHistBytes PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoHistBytes (dataPtr: Ptr;
; maskPtr: Ptr;
; count: LONGINT;
; VAR hist: THistogram);
; Parameter Offsets
@dataPtr EQU 20
@maskPtr EQU 16
@count EQU 12
@hist EQU 8
; Size of parameters
@params EQU 16
; Save registers
LINK A6,#0
MOVEM.L A2,-(SP)
; Unload parameters
MOVE.L @count(A6),D0
BEQ.S @exit
MOVE.L @dataPtr(A6),A0
MOVE.L @hist(A6),A1
MOVE.L @maskPtr(A6),A2
MOVE.L A2,D1
BNE.S @2
; Compute histogram, without mask
@1 CLR.W D1
MOVE.B (A0)+,D1
LSL.W #2,D1
ADD.L #1,(A1,D1.W)
SUB.L #1,D0
BNE.S @1
BRA.S @exit
; Compute histogram, with mask
@2 CLR.W D1
MOVE.B (A0)+,D1
MOVE.B (A2)+,D2
BPL.S @3
LSL.W #2,D1
ADD.L #1,(A1,D1.W)
@3 SUB.L #1,D0
BNE.S @2
; Clean up and exit
@exit MOVEM.L (SP)+,A2
UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
DoSwapBytes PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoSwapBytes (data1: Ptr;
; data2: Ptr;
; count: LONGINT);
; Parameter Offsets
@data1 EQU 16
@data2 EQU 12
@count EQU 8
; Size of parameters
@params EQU 12
; Unload parameters
LINK A6,#0
MOVE.L @data1(A6),A0
MOVE.L @data2(A6),A1
MOVE.L @count(A6),D0
; Swap the bytes
@1 MOVE.B (A0),D1
MOVE.B (A1),(A0)+
MOVE.B D1,(A1)+
SUB.L #1,D0
BNE.S @1
; Clean up and exit
@4 UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
DoMaxBytes PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoMaxBytes (data1: Ptr;
; data2: Ptr;
; data3: Ptr;
; count: LONGINT);
; Parameter Offsets
@data1 EQU 20
@data2 EQU 16
@data3 EQU 12
@count EQU 8
; Size of parameters
@params EQU 16
; Unload parameters
LINK A6,#0
MOVE.L A2,-(SP)
MOVE.L @data1(A6),A0
MOVE.L @data2(A6),A1
MOVE.L @data3(A6),A2
MOVE.L @count(A6),D0
BLE.S @3
; Compute the maximums
@1 MOVE.B (A0)+,D1
MOVE.B (A1)+,D2
CMP.B D1,D2
BHI.S @2
MOVE.B D1,(A2)+
SUB.L #1,D0
BNE.S @1
BRA.S @3
@2 MOVE.B D2,(A2)+
SUB.L #1,D0
BNE.S @1
; Clean up and exit
@3 MOVE.L (SP)+,A2
UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
DoMinBytes PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoMinBytes (data1: Ptr;
; data2: Ptr;
; data3: Ptr;
; count: LONGINT);
; Parameter Offsets
@data1 EQU 20
@data2 EQU 16
@data3 EQU 12
@count EQU 8
; Size of parameters
@params EQU 16
; Unload parameters
LINK A6,#0
MOVE.L A2,-(SP)
MOVE.L @data1(A6),A0
MOVE.L @data2(A6),A1
MOVE.L @data3(A6),A2
MOVE.L @count(A6),D0
BLE.S @3
; Compute the minimums
@1 MOVE.B (A0)+,D1
MOVE.B (A1)+,D2
CMP.B D1,D2
BLO.S @2
MOVE.B D1,(A2)+
SUB.L #1,D0
BNE.S @1
BRA.S @3
@2 MOVE.B D2,(A2)+
SUB.L #1,D0
BNE.S @1
; Clean up and exit
@3 MOVE.L (SP)+,A2
UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
EqualBytes PROC EXPORT
; Calling sequence (Pascal conventions):
;
; FUNCTION EqualBytes (data1: Ptr;
; data2: Ptr;
; count: INTEGER): BOOLEAN;
;
; Parameter Offsets
@result EQU 18
@data1 EQU 14
@data2 EQU 10
@count EQU 8
; Size of parameters
@params EQU 10
; Build frame
LINK A6,#0
; Compare bytes
CLR.B @result(A6)
MOVE.L @data1(A6),A0
MOVE.L @data2(A6),A1
MOVE.W @count(A6),D0
SUB.W #1,D0
@1 MOVE.B (A0)+,D1
CMP.B (A1)+,D1
BNE.S @2
DBF D0,@1
MOVE.B #1,@result(A6)
; Clean up and exit
@2 UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
ConvertToGray PROC EXPORT
; Calling sequence (Pascal conventions):
;
; FUNCTION ConvertToGray (r, g, b: INTEGER): CHAR;
; Parameter Offsets
@result EQU 14
@r EQU 12
@g EQU 10
@b EQU 8
; Gray level weights
@rw EQU 30
@gw EQU 59
@bw EQU 11
; Size of parameters
@params EQU 6
; Compute gray level
LINK A6,#0
MOVE.W @r(A6),D0
AND.W #$FF,D0
MULU.W #@rw,D0
MOVE.W @g(A6),D1
AND.W #$FF,D1
MULU.W #@gw,D1
ADD.W D1,D0
MOVE.W @b(A6),D1
AND.W #$FF,D1
MULU.W #@bw,D1
ADD.W D1,D0
ADD.W #50,D0
EXT.L D0
DIVU.W #100,D0
MOVE.W D0,@result(A6)
; Clean up and exit
@3 UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
DoFindBounds PROC EXPORT
; Calling sequence (Pascal conventions):
;
; FUNCTION DoFindBounds (dataPtr: Ptr;
; count: INTEGER;
; VAR first: INTEGER;
; VAR last: INTEGER): BOOLEAN;
;
; Parameter Offsets
@result EQU 22
@dataPtr EQU 18
@count EQU 16
@first EQU 12
@last EQU 8
; Size of parameters
@params EQU 14
; Save registers
LINK A6,#0
MOVEM.L D3-D4,-(SP)
; Find bounds
MOVE.L @dataPtr(A6),A0
MOVE.W @count(A6),D0
CLR.W D1
CLR.B D2
@1 TST.B (A0)+
BEQ.S @3
TST.B D2
BNE.S @2
MOVE.B #1,D2
MOVE.W D1,D3
@2 MOVE.W D1,D4
@3 ADD.W #1,D1
CMP.W D1,D0
BNE.S @1
MOVE.B D2,@result(A6)
MOVE.L @first(A6),A0
MOVE.W D3,(A0)
MOVE.L @last(A6),A0
MOVE.W D4,(A0)
; Clean up and exit
MOVEM.L (SP)+,D3-D4
UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
DoStepCopyBytes PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE DoStepCopyBytes (srcPtr: Ptr;
; dstPtr: Ptr;
; count: INTEGER;
; step1: INTEGER;
; step2: INTEGER);
;
; Parameter Offsets
@srcPtr EQU 18
@dstPtr EQU 14
@count EQU 12
@step1 EQU 10
@step2 EQU 8
; Size of parameters
@params EQU 14
; Save registers
LINK A6,#0
; Unload parameters
MOVE.L @srcPtr(A6),A0
MOVE.L @dstPtr(A6),A1
MOVE.W @count(A6),D0
MOVE.W @step1(A6),D1
MOVE.W @step2(A6),D2
; Copy the bytes
SUB.W #1,D0
@1 MOVE.B (A0),(A1)
ADDA.W D1,A0
ADDA.W D2,A1
DBF D0,@1
; Clean up and exit
UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
SEG 'ARes'
CompareWords PROC EXPORT
; Calling sequence (C conventions):
;
; int CompareWords (elem1, elem2)
; char *elem1;
; char *elem2;
;
; Unload parameters
MOVE.L 4(SP),A0
MOVE.L 8(SP),A1
; Compare short words
MOVE.W (A0),D0
CMP.W (A1),D0
BGT.S @1
BLT.S @2
; Entries are equal
CLR.L D0
RTS
; First entry is greater
@1 MOVE.L #1,D0
RTS
; First entry is lesser
@2 MOVE.L #-1,D0
RTS
; **********************************************************************
SEG 'ARes'
CompareUnsignedLongs PROC EXPORT
; Calling sequence (C conventions):
;
; int CompareUnsignedLongs (elem1, elem2)
; char *elem1;
; char *elem2;
;
; Unload parameters
MOVE.L 4(SP),A0
MOVE.L 8(SP),A1
; Compare short words
MOVE.L (A0),D0
CMP.L (A1),D0
BHI.S @1
BLO.S @2
; Entries are equal
CLR.L D0
RTS
; First entry is greater
@1 MOVE.L #1,D0
RTS
; First entry is lesser
@2 MOVE.L #-1,D0
RTS
; **********************************************************************
SEG 'ARes'
MakeRamp PROC EXPORT
; Calling sequence (Pascal conventions):
;
; PROCEDURE MakeRamp (VAR map: TLookUpTable;
; limit: INTEGER);
;
; Parameter Offsets
@map EQU 10
@limit EQU 8
; Size of parameters
@params EQU 6
; Save registers
LINK A6,#0
; Unload parameters
MOVE.L @map(A6),A0
ADDA.W #256,A0
MOVE.W @limit(A6),D1
; Compute ramp backwards
MOVE.W #255,D0
@1 MOVE.W D1,D2
MULU.W D0,D2
ADD.L #127,D2
DIVU.W #255,D2
MOVE.B D2,-(A0)
DBF D0,@1
; Clean up and exit
UNLK A6
MOVE.L (SP)+,A0
ADD.W #@params,SP
JMP (A0)
; **********************************************************************
END