-
Notifications
You must be signed in to change notification settings - Fork 1
/
icon.library.asm
1951 lines (1909 loc) · 46.6 KB
/
icon.library.asm
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
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; vasmm68k_mot[_<HOST>] -Fhunkexe -kick1hunks -nosym -o icon.library icon.library.asm
;
; NAME
; libs/icon.library
;
; SYNOPSIS
; Implementation of a V1.x libs/icon.library replacement to allow
; creating the Workbench task from V1.x ROMs without the need for
; the original Workbench disk (which you otherwise must own/buy).
;
; The main target of this project is to keep the library as small
; as possible. Therefore, the code is not optimized for speed but
; size (which makes it sometimes less readable and maintainable).
;
; NOTES
; This implementation is not intended to be used with V2+ ROMs
; (internal struct il, NewDD, and WBObject have been changed).
; However, due to the low version number and the fact that the
; library is present in V2+ ROMs, it isn't loaded by V2+ ROMs.
;
IconLibrary:
;
; Normally, libraries are not expected to be run and
; just return with an error code (that is the reason
; why RTC_MATCHWORD is an ILLEGAL m68k instruction).
;
; Since the full implementation of the official V1.x
; library interface currently requires 5 OFS blocks,
; the remaining space is used for a CLI command-line
; interface "icon.library LoadWB/S,DELAY/S,EndCLI/S"
; (options case-insensitive and order is mandatory).
; - LoadWB - create "workbench.task" process
; - DELAY - wait for two and a half seconds
; - EndCLI - close CLI that runs the command
; The return code will always be 0 and the secondary
; result is undefined - therefore IF WARN ERROR FAIL
; and WHY are of no use after executing the library.
; However, this little feature can be used to create
; a minimal OFS boot floppy that loads the Workbench
; with every ROM/Kickstart that includes a Workbench
; (missing in 0.x versions, the Amiga 4000T 3.1 ROM,
; Cloanto's 3.X, and Hyperion's 3.1.4/3.2 versions).
; 2 BootBlock (e.g. BBlock0x.bb)
; 1 RootBlock
; 1 BitmapBlock
; 1 UserDirectoryBlock (Libs)
; 1 FileHeaderBlock (Libs/icon.library)
; 5 FileDataBlocks (Libs/icon.library)
; 1 UserDirectoryBlock (S)
; 1 FileHeaderBlock (S/Startup-Sequence)
; 1 FileDataBlock (S/Startup-Sequence)
; where the Startup-Sequence includes a single line
; "Libs/icon.library LoadWB DELAY EndCLI" (DELAY is
; optional, used to be included in older startups).
; With 14 of 1760 DD OFS blocks used, there's space
; left for a single file with 820 KB (840336 bytes,
; needs 1 FileHeaderBlock every 72 FileDataBlocks).
; Well, you can even move the icon.library into the
; root directory of the disk to save another sector
; for the Libs drawer, and the startup will be even
; faster (now everything fits into a single track).
;
; Keep this a WORD branch here (makes it easier to
; disable this feature by replacing this code with
; $70,$FF,$4E,$75 (the usual MOVEQ #-1,D0 + RTS)).
;
bra.w .LibExec
.resTag:
dc.w $4AFC ; RT_MATCHWORD = RTC_MATCHWORD
dc.l .resTag ; RT_MATCHTAG
dc.l iconEnd ; RT_ENDSKIP
dc.b $80 ; RT_FLAGS = RTF_AUTOINIT
dc.b 35 ; RT_VERSION
dc.b 9 ; RT_TYPE = NT_LIBRARY
dc.b 0 ; RT_PRI
dc.l .resName ; RT_NAME
dc.l .resIdString ; RT_IDSTRING
dc.l .resAuto ; RT_INIT
.resName:
dc.b "icon.library",0
.resIdString:
dc.b "icon 35.4 (9.9.99) BootWB1x",13,10,0
.dosName:
dc.b "dos.library";0
align 1
.resAuto:
dc.l $0032 ; il_Sizeof
dc.l .libFunc
dc.l .libData
dc.l .LibInit
.libFunc:
dc.w -1
; bias 30
dc.w .LibOpen-.libFunc ; -$0006
dc.w .LibClose-.libFunc ; -$000C
dc.w .LibExpunge-.libFunc ; -$0012
dc.w .LibExtFunc-.libFunc ; -$0018
; private
dc.w IGetWBObject-.libFunc ; -$001E
dc.w IPutWBObject-.libFunc ; -$0024
dc.w IGetIcon-.libFunc ; -$002A
dc.w IPutIcon-.libFunc ; -$0030
; public
dc.w IFreeFreeList-.libFunc ; -$0036
; private
dc.w IFreeWBObject-.libFunc ; -$003C
dc.w IAllocWBObject-.libFunc ; -$0042
; public
dc.w IAddFreeList-.libFunc ; -$0048
dc.w IGetDiskObject-.libFunc ; -$004E
dc.w IPutDiskObject-.libFunc ; -$0054
dc.w IFreeDiskObject-.libFunc ; -$005A
dc.w IFindToolType-.libFunc ; -$0060
dc.w IMatchToolValue-.libFunc ; -$0066
dc.w IBumpRevision-.libFunc ; -$006C
; version 36
; private
dc.w IFreeAlloc-.libFunc ; -$0072
; public
; dc.w IGetDefDiskObject-.libFunc ; -$0078
; dc.w IPutDefDiskObject-.libFunc ; -$007E
; dc.w IGetDiskObjectNew-.libFunc ; -$0084
; version 37
; dc.w IDeleteDiskObject-.libFunc ; -$008A
; reserve 4
; dc.w .LibNull-.libFunc ; -$0090
; dc.w .LibNull-.libFunc ; -$0096
; dc.w .LibNull-.libFunc ; -$009C
; dc.w .LibNull-.libFunc ; -$00A2
dc.w -1
.libData:
dc.b %10100110,$08 ; LN_TYPE/LN_PRI/LN_NAME/LIB_FLAGS
dc.b 9 ; NT_LIBRARY
dc.b 0
dc.l .resName
dc.b $02!$04 ; LIBF_SUMUSED!LIBF_CHANGED
align 1
dc.b %10000001,$14 ; LIB_VERSION/LIB_REVISION/LIB_IDSTRING
dc.w 35,4
dc.l .resIdString
align 1
dc.b %00000000
align 1
;
; REG(D0) LONG result
; LibExec(
; REG(D0) LONG dosCmdLen,
; REG(A0) STRPTR dosCmdBuf)
;
; NOTES
; any registers (except SP) are allowed to be modified
;
.execArg:
dc.b "LoadWB" ; -debug
dc.b "DELAY"
dc.b "EndCLI"
.wbtName:
dc.b "workbench.task",0
align 1
.LibExec:
pea .LibNull(pc)
movea.l (4).w,a6 ; AbsExecBase
movea.l $0114(a6),a4 ; ThisTask
move.l $00AC(a4),d7 ; pr_CLI
beq.b .execRts
lea .execArg(pc),a2
lea IUpper(pc),a3
movea.l a0,a5
move.l d0,d5
ble.b .execRts
lea .wbtName(pc),a1
jsr -$0060(a6) ; _LVOFindResident
move.l d0,d3
lea .dosName(pc),a1
jsr -$0198(a6) ; _LVOOldOpenLibrary
movea.l d0,a6
pea .LoadWB(pc)
.tstArg6:
moveq #6,d0 ; strlen("LoadWB")/strlen("EndCLI")
.testArg:
move.l d0,d1
cmp.l d0,d5
blt.b .nextArg
cmpi.b #$20,(a5)
bhi.b .compArg
addq.l #1,a5
subq.l #1,d5
bra.b .testArg
.compArg:
movea.l a5,a1
bsr.w IStrMatchN
cmp.l d0,d1
bne.b .nextArg
adda.l d1,a5
sub.l d1,d5
moveq #0,d0
.nextArg:
adda.l d1,a2
.execRts:
rts
.LoadWB:
bne.b .DELAY
addq.l #2,d3 ; RT_SIZE % 4 (nop for V1.2/V1.3)
lsr.l #2,d3
beq.b .DELAY
addq.l #($001A+8)/4,d3 ; MKBADDR(RT_SIZE + "-debug")
moveq #-1,d1
move.l d1,$00B8(a4) ; pr_WindowPtr
moveq #0,d1
move.l $00A4(a4),d6 ; pr_ConsoleTask
move.l d1,$00A4(a4) ; pr_ConsoleTask
move.l d1,$00AC(a4) ; pr_CLI
jsr -$007E(a6) ; _LVOCurrentDir
move.l d0,-(sp)
pea .wbtName(pc)
move.l (sp)+,d1
moveq #1,d2
pea (6000).w
move.l (sp)+,d4
jsr -$008A(a6) ; _LVOCreateProc
move.l (sp)+,d1
jsr -$007E(a6) ; _LVOCurrentDir
move.l d7,$00AC(a4) ; pr_CLI
move.l d6,$00A4(a4) ; pr_ConsoleTask
.DELAY:
moveq #5,d0 ; strlen("DELAY")
bsr.b .testArg
bne.b .EndCLI
moveq #125,d1
jsr -$00C6(a6) ; _LVODelay
.EndCLI:
bsr.b .tstArg6
bne.b .argDone
lsl.l #2,d7
movea.l d7,a2
lea $001C(a2),a1 ; cli_StandardInput
move.l (a1)+,a3
move.l (a1),d1 ; (cli_CurrentInput)
beq.b .cinDone
cmp.l a3,d1
beq.b .cinDone
move.l a3,(a1)
jsr -$0024(a6) ; _LVOClose
.cinDone:
moveq #-1,d0 ; DOSTRUE
move.l d0,$002C(a2) ; cli_Background
adda.l a3,a3
lea $0014(a3,a3.l),a3
move.l (a3),d0 ; (fh_End)
clr.l (a3)
move.l d0,-(a3) ; (fh_Pos)
.argDone:
movea.l a6,a1
movea.l (4).w,a6 ; AbsExecBase
jmp -$019E(a6) ; _LVOCloseLibrary
; rts
;
; REG(D0) struct Library *library
; LibInit(
; REG(D0) struct Library *libBase,
; REG(A0) BPTR segList),
; REG(A6) struct ExecBase *sysBase
;
.LibInit:
movem.l d0-d1/a0-a2,-(sp)
movea.l d0,a2
move.l a6,$0022(a2) ; il_SysBase
move.l a0,$002E(a2) ; il_SegList
lea .dosName(pc),a1
jsr -$0198(a6) ; _LVOOldOpenLibrary
move.l d0,$0026(a2) ; il_DOSBase
bne.b .initRts
move.l d0,(sp) ; (sp),library/*
exg a2,a6
bsr.b .LibFree
exg a6,a2
.initRts:
movem.l (sp)+,d0-d1/a0-a2
rts
;
; REG(D0) struct Library *library
; LibOpen(VOID),
; REG(A6) struct Library *libBase
;
.LibOpen:
addq.w #1,$0020(a6) ; LIB_OPENCNT
bclr.b #3,$000E(a6) ; LIBB_DELEXP,LIB_FLAGS
move.l a6,d0
rts
;
; REG(D0) BPTR segList
; LibClose(VOID),
; REG(A6) struct Library *libBase
;
.LibClose:
subq.w #1,$0020(a6) ; LIB_OPENCNT
bne.b .LibNull
btst.b #3,$000E(a6) ; LIBB_DELEXP,LIB_FLAGS
beq.b .LibNull
;
; REG(D0) BPTR segList
; LibExpunge(VOID),
; REG(A6) struct Library *libBase
;
.LibExpunge:
tst.w $0020(a6) ; LIB_OPENCNT
beq.b .LibFree
bset.b #3,$000E(a6) ; LIBB_DELEXP,LIB_FLAGS
;
; REG(D0) APTR null
; LibExtFunc(VOID),
; REG(A6) struct Library *libBase
;
.LibExtFunc:
.LibNull:
moveq #0,d0
rts
;
; REG(D0) BPTR segList
; LibFree(VOID),
; REG(A6) struct Library *libBase
;
.LibFree:
movem.l d0-d1/a0-a1,-(sp)
move.l $002E(a6),(sp) ; il_SegList
move.l $0026(a6),d1 ; il_DOSBase
beq.b .freeLib
movea.l d1,a1
movea.w #-$019E,a0 ; _LVOCloseLibrary
bsr.b ISysCall
.freeLib:
movea.l a6,a1
movea.w #-$00FC,a0 ; _LVORemove
bsr.b ISysCall
moveq #0,d0
moveq #0,d1
move.w $0010(a6),d0 ; LIB_NEGSIZE
move.w $0012(a6),d1 ; LIB_POSSIZE
movea.l a6,a1
suba.l d0,a1
add.l d1,d0
bsr.b IFreeMem
movem.l (sp)+,d0-d1/a0-a1
rts
******i icon.library/AllocWBObject *******************************************
*
* NAME
* AllocWBObject -- allocate a Workbench object.
*
* SYNOPSIS
* object = AllocWBObject().
* D0
* struct OldWBObject *AllocWBObject(VOID);
*
* FUNCTION
* This routine allocates a Workbench object, and initializes its free
* list. A subsequent call to FreeWBObject will free all of its memory.
*
* RESULTS
* object -- a pointer to the Workbench object
*
******************************************************************************
IAllocWBObject:
move.l d1,-(sp)
moveq #$00A8/2,d0 ; sizeof OldWBObject
add.l d0,d0
moveq #$008C/2,d1 ; OldWBObject.wo_FreeList
add.l d1,d1
bsr.b IAllocObject
move.l (sp)+,d1
rts
;
; REG(D0) APTR object
; IAllocObject(
; REG(D0) ULONG byteSize,
; REG(D1) ULONG freeList),
; REG(A6) struct il *iconBase
;
; NOTES
; preserves all registers (except D0.L/CCR)
;
IAllocObject:
movem.l d0-d2/a0-a2,-(sp)
movea.l d0,a2
move.l d1,d2
bsr.b IAllocMemPublicClear
move.l d0,(sp) ; (sp),object/*
beq.b .done
movea.l d0,a0
lea $02(a0,d2.l),a0 ; fl_MemList
move.l a0,$0008(a0) ; LH_TAILPRED
addq.l #4,a0 ; LH_TAIL
move.l a0,-(a0)
; WB1 behaviour, see IFreeWBObject/IFreeDiskObject
subq.l #2,a0 ; fl_MemList
movea.l (sp),a1 ; (sp),object/*
jsr -$0048(a6) ; _LVOAddFreeList
tst.l d0
bne.b .done
movea.l (sp),a1 ; (sp),object/*
move.l d0,(sp) ; (sp),object/*
move.l a2,d0
bsr.b IFreeMem
.done:
movem.l (sp)+,d0-d2/a0-a2
rts
;
; VOID
; IFreeMem(
; REG(A1) APTR memoryBlock,
; REG(D0) ULONG byteSize),
; REG(A6) struct il *iconBase
;
IFreeMem:
movea.w #-$00D2,a0 ; _LVOFreeMem
;
; REG(D0) APTR result
; ISysCall(
; REG(A0) WORD execLVO),
; REG(A6) struct il *iconBase
;
ISysCall:
move.l a6,-(sp)
movea.l $0022(a6),a6 ; il_SysBase
jsr (a6,a0.w)
movea.l (sp)+,a6
rts
;
; REG(D0) APTR memoryBlock
; IAllocMemPublicClear(
; REG(D0) ULONG byteSize),
; REG(A6) struct il *iconBase
;
IAllocMemPublicClear:
; MEMF_PUBLIC!MEMF_CLEAR
move.l #$00010001,d1
;
; REG(D0) APTR memoryBlock
; IAllocMem(
; REG(D0) ULONG byteSize,
; REG(D1) ULONG attributes),
; REG(A6) struct il *iconBase
;
IAllocMem:
movea.w #-$00C6,a0 ; _LVOAllocMem
bra.b ISysCall
; rts
******* icon.library/GetDiskObject *******************************************
*
* NAME
* GetDiskObject -- read in a Workbench disk object from disk.
*
* SYNOPSIS
* object = GetDiskObject(name)
* D0 A0
* struct DiskObject *GetDiskObject(STRPTR);
*
* FUNCTION
* This routine reads in a Workbench disk object in from disk.
* The name parameter will have a ".info" postpended to it,
* and the info file of that name will be read.
* If the call fails, it will return zero.
* The reason for the failure may be obtained via IoErr().
*
* A FreeList structure is allocated just after the DiskObject
* structure. FreeDiskObject makes use of this to get rid of the
* memory that was allocated.
*
* INPUTS
* name -- name of the object
*
* RESULTS
* object -- the Workbench disk object in question
*
* NOTES
* Extensions to the original behaviour:
* - name can be NULL to just allocate a structure (WB2/WB3)
*
******************************************************************************
IGetDiskObject:
movem.l d0-d1/a0-a2,-(sp)
moveq #$004E+$0010,d0 ; do_SIZEOF+FreeList_SIZEOF
moveq #$004E,d1 ; do_SIZEOF
bsr.b IAllocObject
move.l d0,(sp) ; (sp),object/*
beq.b .done
; test name for NULL
move.l a0,d1
beq.b .done
; else read the icon
movea.l d0,a1
lea $004E(a1),a2 ; do_SIZEOF
jsr -$002A(a6) ; _LVOGetIcon
tst.l d0
bne.b .done
; don't use LVO to free object
; (might have been overridden)
movea.l (sp),a0 ; (sp),object/*
move.l d0,(sp) ; (sp),object/*
bsr.b IFreeDiskObject
.done:
movem.l (sp)+,d0-d1/a0-a2
rts
******i icon.library/FreeAlloc ***********************************************
*
* NAME
* FreeAlloc -- allocate memory and add it to a free list. (V36)
*
* SYNOPSIS
* mem = FreeAlloc(free, len, type)
* D0 A0 A1 A2
* APTR FreeAlloc(struct FreeList *, ULONG, ULONG);
*
* FUNCTION
* This routine allocates the amount of memory specified and then adds
* it to the free list. The free list will be extended (if required).
* If the call fails, it will return zero.
*
* INPUTS
* free -- a pointer to a FreeList structure
* len -- the length of the memory to be recorded
* type -- the type of memory to be allocated
*
* RESULTS
* mem -- a pointer to the newly allocated memory chunk
*
******************************************************************************
IFreeAlloc:
move.l d1,-(sp)
movem.l d0/a0-a3,-(sp) ; (sp),mem/free/len/type/*
move.l a1,d0
move.l a2,d1
bsr.b IAllocMem
move.l d0,(sp) ; (sp),mem/*
beq.b .done
movem.l (sp),d0/a0/a2 ; (sp),mem/free/len/*
movea.l d0,a1
jsr -$0048(a6) ; _LVOAddFreeList
tst.l d0
bne.b .done
movem.l (sp),a1/a2/a3 ; (sp),mem/free/len/*
move.l d0,(sp)
move.l a3,d0
bsr.b IFreeMem
.done:
movem.l (sp)+,d0/a0-a3
move.l (sp)+,d1
rts
;
; REG(D0) CCR(Z) ULONG numFree
; IReplenishFreeList(
; REG(A0) struct FreeList *free),
; REG(A6) struct il *iconBase
;
; NOTES
; preserves A0.L/A1.L
;
IReplenishFreeList:
movem.l a0-a1,-(sp) ; (sp),free/*
move.l a0,d0
beq.b .done
move.w (a0),d0 ; (fl_NumFree)
ext.l d0
bgt.b .done
moveq #10*$08+$10,d0 ; 10*ME_SIZE+ML_SIZE
bsr.b IAllocMemPublicClear
movea.l (sp),a0 ; (sp),free/*
tst.l d0
beq.b .done
movea.l d0,a1
moveq #10,d0
move.w d0,(a0)+ ; (fl_NumFree)/fl_MemList
move.w d0,$000E(a1) ; ML_NUMENTRIES
move.l a6,-(sp)
movea.l $0022(a6),a6 ; il_SysBase
jsr -$00F6(a6) ; _LVOAddTail
movea.l (sp)+,a6
moveq #10,d0
.done:
movem.l (sp)+,a0-a1
rts
******i icon.library/FreeWBObject ********************************************
*
* NAME
* FreeWBObject -- free all memory in a Workbench object.
*
* SYNOPSIS
* FreeWBObject(object)
* A0
* VOID FreeWBObject(struct OldWBObject *);
*
* FUNCTION
* This routine frees all memory in a Workbench object, and the
* object itself. It is implemented via FreeFreeList().
*
* AllocWBObject() takes care of all the initialization required
* to set up the objects free list.
*
* INPUTS
* object -- a pointer to a Workbench object
*
******************************************************************************
IFreeWBObject:
move.l a0,-(sp)
beq.b .done
lea $008C(a0),a0 ; OldWBObject.wo_FreeList
jsr -$0036(a6) ; _LVOFreeFreeList
; no FreeMem(object) here (like WB2/WB3), assumes
; that object is the first entry in its free list
.done:
movea.l (sp)+,a0
rts
******* icon.library/FreeDiskObject ******************************************
*
* NAME
* FreeDiskObject - free all memory in a Workbench disk object.
*
* SYNOPSIS
* FreeDiskObject(object)
* A0
* VOID FreeDiskObject(struct DiskObject *);
*
* FUNCTION
* This routine frees all memory in a Workbench disk object,
* and the object itself. It is implemented via FreeFreeList().
*
* GetDiskObject() takes care of all the initialization required
* to set up the object's free list. This procedure may ONLY
* be called on a DiskObject allocated via GetDiskObject().
*
* INPUTS
* object -- a pointer to a DiskObject structure
*
******************************************************************************
IFreeDiskObject:
move.l a0,-(sp)
beq.b .done
lea $004E(a0),a0 ; do_SIZEOF
jsr -$0036(a6) ; _LVOFreeFreeList
; no FreeVec(object) here (like WB2/WB3), assumes
; that object is the first entry in its free list
.done:
movea.l (sp)+,a0
rts
******* icon.library/AddFreeList *********************************************
*
* NAME
* AddFreeList - add memory to a free list.
*
* SYNOPSIS
* status = AddFreeList(free, mem, len)
* D0 A0 A1 A2
* BOOL AddFreeList(struct FreeList *, APTR, ULONG);
*
* FUNCTION
* This routine adds the specified memory to the free list.
* The free list will be extended (if required). If there
* is not enough memory to complete the call, a null is returned.
*
* Note that AddFreeList does NOT allocate the requested memory.
* It only records the memory in the free list.
*
* INPUTS
* free -- a pointer to a FreeList structure
* mem -- the base of the memory to be recorded
* len -- the length of the memory to be recorded
*
* RESULTS
* status -- TRUE if the call succeeded, else FALSE
*
******************************************************************************
IAddFreeList:
movem.l d1/a0,-(sp)
bsr.b IReplenishFreeList
beq.b .done
subq.l #1,d0
move.w d0,(a0)+ ; (fl_NumFree)/fl_MemList
lsl.l #3,d0 ; *ME_SIZE
movea.l $0008(a0),a0 ; LH_TAILPRED
lea $10(a0,d0.l),a0 ; ML_ME
move.l a1,(a0)+ ; (ME_ADDR)
move.l a2,(a0) ; (ME_LENGTH)
moveq #1,d0
.done:
movem.l (sp)+,d1/a0
rts
******* icon.library/FreeFreeList ********************************************
*
* NAME
* FreeFreeList -- free all memory in a free list.
*
* SYNOPSIS
* FreeFreeList(free)
* A0
* VOID FreeFreeList(struct FreeList *);
*
* FUNCTION
* This routine frees all memory in a free list, and the free list
* itself. It is useful for easily getting rid of all memory in a
* series of structures. There is a free list in a Workbench object,
* and this contains all the memory associated with that object.
*
* A FreeList is a list of MemList structures. See the
* MemList and MemEntry documentation for more information.
*
* If the FreeList itself is in the free list, it must be
* in the first MemList in the FreeList.
*
* INPUTS
* free -- a pointer to a FreeList structure
*
******************************************************************************
IFreeFreeList:
movem.l d0-d2/a0-a1/a6,-(sp)
move.l a0,d2
beq.b .done ; (NULL)
move.l $000A(a0),d2 ; fl_MemList+LH_TAILPRED
beq.b .done ; (invalid, NewList missing)
movea.l $0022(a6),a6 ; il_SysBase
.loop:
movea.l d2,a0
move.l $0004(a0),d2 ; LN_PRED
beq.b .done
jsr -$00E4(a6) ; _LVOFreeEntry
bra.b .loop
.done:
movem.l (sp)+,d0-d2/a0-a1/a6
rts
******i icon.library/GetWBObject *********************************************
*
* NAME
* GetWBObject -- read in a Workbench object from disk.
*
* SYNOPSIS
* object = GetWBObject(name)
* D0 A0
* struct OldWBObject *GetWBObject(STRPTR);
*
* FUNCTION
* This routine reads in a Workbench object in from disk.
* The name parameter will have a ".info" postpended to it,
* and the info file of that name will be read.
* If the call fails, it will return zero.
* The reason for the failure may be obtained via IoErr().
*
* INPUTS
* name -- name of the object
*
* RESULTS
* object -- the Workbench object in question
*
******************************************************************************
IGetWBObject:
movem.l d1/a0-a3,-(sp)
link.w a4,#-$0050 ; (do_SIZEOF+3)&~3
movea.l a0,a2
jsr -$0042(a6) ; _LVOAllocWBObject
move.l d0,-(sp)
beq.b .done
movea.l d0,a3
movea.l a2,a0
lea -$0050(a4),a1
lea $008C(a3),a2 ; OldWBObject.wo_FreeList
jsr -$002A(a6) ; _LVOGetIcon
tst.l d0
beq.b .free
lea $0004-$0050(a4),a0 ; do_Gadget
lea $0060(a3),a1 ; OldWBObject.wo_Gadget
moveq #$002C/4-1,d0 ; gg_SIZEOF
.loop:
move.l (a0)+,(a1)+
dbf d0,.loop
move.b (a0)+,$003D(a3) ; OldWBObject.wo_Type
addq.l #1,a0 ; (do_PAD_BYTE)
move.l (a0)+,$0048(a3) ; OldWBObject.wo_DefaultTool
move.l (a0)+,$005C(a3) ; OldWBObject.wo_ToolTypes
move.l (a0)+,$0054(a3) ; OldWBObject.wo_CurrentX
move.l (a0)+,$0058(a3) ; OldWBObject.wo_CurrentY
movea.l (a0)+,a1 ; (do_DrawerData)
move.l (a0)+,$009C(a3) ; OldWBObject.wo_ToolWindow
move.l (a0),$00A0(a3) ; OldWBObject.wo_StackSize
move.l a1,$004C(a3) ; OldWBObject.wo_DrawerData
beq.b .done
move.l a3,$01A8(a1) ; OldNewDD.dd_Object
.done:
move.l (sp)+,d0
unlk a4
movem.l (sp)+,d1/a0-a3
rts
.free:
movea.l (sp),a0
move.l d0,(sp)
jsr -$003C(a6) ; _LVOFreeWBObject
bra.b .done
******i icon.library/GetIcon *************************************************
*
* NAME
* GetIcon -- read in a DiskObject structure from disk.
*
* SYNOPSIS
* status = GetIcon(name, icon, free)
* D0 A0 A1 A2
* BOOL GetIcon(STRPTR, struct DiskObject *, struct FreeList *);
*
* FUNCTION
* This routine reads in a DiskObject structure, and its associated
* information. All memory will be automatically allocated, and stored
* in the specified FreeList. The file name of the info file will be
* the name parameter with a ".info" postpended to it.
* If the call fails, a zero will be returned.
* The reason for the failure may be obtained via IoErr().
*
* INPUTS
* name -- name of the object
* icon -- a pointer to a DiskObject
* free -- a pointer to a FreeList
*
* RESULTS
* status -- non-zero if the call succeeded
*
* NOTES
* Differences to the original behaviour:
* - only Image (no Border) gadgets are supported (WB2/WB3)
* - gg_GadgetRender has to be present (NULL breaks 1.x WB)
*
* As of release V2.0 this function allocates a NewDD structure
* instead of a OldNewDD structure for the do_DrawerData field.
*
******************************************************************************
IGetIcon:
movem.l d1-d5/a0-a5,-(sp)
movea.l a1,a3
movea.l a2,a4
move.l #1005,d2 ; MODE_OLDFILE
bsr.w IOpen
move.l d0,d4
beq.b .nope
; read disk object
move.l a3,d2
moveq #$004E,d3 ; do_SIZEOF
bsr.w IRead
bne.b .eowt
cmpi.l #$E3100001,(a3)+ ; WB_DISKMAGIC/WB_DISKVERSION
bne.b .eowt
btst.b #2,$000C+1(a3) ; log2(GFLG_GADGIMAGE),gg_Flags
beq.b .eowt
tst.l $0012(a3) ; gg_GadgetRender
bne.b .dodd
.eowt:
bsr.b ISetIoErrObjectWrongType
.fail:
moveq #0,d5 ; FALSE
.done:
bsr.w IClose
move.l d5,d0
.nope:
movem.l (sp)+,d1-d5/a0-a5
rts
.dodd:
moveq #1,d5 ; TRUE
; read drawer data
lea $0042-$0004(a3),a5 ; do_DrawerData-do_Gadget
tst.l (a5)
beq.b .ggim
moveq #$0038,d3 ; OldDrawerData_SIZEOF
movea.w #$01BE,a1 ; sizeof OldNewDD (NewDD $01D8)
movea.l #$00010001,a2 ; MEMF_PUBLIC!MEMF_CLEAR (WB1 chip)
bsr.w IReadFreePart
beq.b .fail
lea $01AC(a5),a5 ; OldNewDD.dd_Children (NewDD $01B2)
move.l a5,$0008(a5) ; LH_TAILPRED
addq.l #4,a5 ; LH_TAIL
move.l a5,-(a5)
.ggim:
; read gadget images
lea $0012(a3),a5 ; gg_GadgetRender
bsr.b IReadImage
beq.b .fail
addq.l #4,a5 ; gg_SelectRender-gg_GadgetRender
bsr.b IReadImage
beq.b .fail
; skip gadget text
clr.l $001A(a3) ; gg_GadgetText
; read default tool
lea $0032-$0004(a3),a5 ; do_DefaultTool-do_Gadget
bsr.w IReadString
beq.b .fail
; read tool types
addq.l #4,a5 ; do_ToolTypes-do_DefaultTool
bsr.w IReadStrings
beq.b .fail
; read tool window
lea $0046-$0004(a3),a5 ; do_ToolWindow-do_Gadget
bsr.b IReadString
beq.b .fail
; final cleanup
clr.l (a3) ; (gg_NextGadget)
clr.l $0028(a3) ; gg_UserData
bra.b .done
;
; REG(D0) LONG oldCode
; ISetIoErrObjectWrongType(VOID),
; REG(A6) struct il *iconBase
;
ISetIoErrObjectWrongType:
moveq #212/2,d0 ; ERROR_OBJECT_WRONG_TYPE
add.l d0,d0
;
; REG(D0) LONG oldCode
; ISetIoErr(
; REG(D0) LONG code),
; REG(A6) struct il *iconBase
;
ISetIoErr:
move.l d0,d1
moveq #0,d0
movea.l $0022(a6),a0 ; il_SysBase
movea.l $0114(a0),a0 ; ThisTask
cmpi.b #13,$0008(a0) ; NT_PROCESS,LN_TYPE
bne.b .done
move.l $0094(a0),d0 ; pr_Result2
move.l d1,$0094(a0) ; pr_Result2
.done:
rts
;
; REG(D0) CCR(Z) BOOL status
; IReadImage(VOID),
; REG(D4) BPTR file,
; REG(A4) struct FreeList *free,
; REG(A5) struct Image **image,
; REG(A6) struct il *iconBase
;
; NOTES:
; registers D3/A2 are NOT preserved
;
IReadImage:
move.l a5,-(sp)
tst.l (a5)
beq.b IReadRefTrue
; read Image struct
moveq #$0014,d3 ; ig_SIZEOF
movea.w #$0001,a2 ; MEMF_PUBLIC
bsr.w IReadFree
beq.b IReadRefDone
; read image planes
bsr.w IProcessImage
ble.b IReadRefEowt
movea.w #$0003,a2 ; MEMF_PUBLIC!MEMF_CHIP
bsr.w IReadFree
beq.b IReadRefFail
IReadRefTrue:
moveq #1,d0 ; TRUE
IReadRefDone:
movea.l (sp)+,a5
rts
IReadRefEowt:
bsr.b ISetIoErrObjectWrongType
IReadRefFail:
moveq #0,d0 ; FALSE/NULL
movea.l (sp),a5
move.l d0,(a5)
bra.b IReadRefDone
;
; REG(D3) CCR(N,Z) LONG value
; IReadLong(VOID),
; REG(D4) BPTR file,
; REG(A6) struct il *iconBase
;
; NOTES:
; registers D2-D3 are NOT preserved
;
IReadLong:
moveq #4,d3
move.l d3,-(sp)
move.l sp,d2
bsr.b IRead
beq.b .done
clr.l (sp)
.done:
move.l (sp)+,d3
rts