forked from tonioni/WinUAE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesys.asm
4374 lines (3972 loc) · 76.7 KB
/
filesys.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
SECTION code,code
; This file can be translated with A68k or PhxAss and then linked with BLink
; to produce an Amiga executable. Make sure it does not contain any
; relocations, then run it through the filesys.sh script
;
; Patrick: It also works with SAS/C asm+slink, but I had to remove
; the .l from jsr.l and jmp.l.
; Toni Wilen: modified SECTION, compiles now with AsmOne and clones(?)
; Removed absolute RT_AREA references
; 2002.08.06 RDB automount/autoboot support (Toni Wilen)
; 2002.09.11 KS1.3 RDB support (TW)
; 200?.??.?? Picasso96 vblank hack (TW)
; 2006.03.04 Mousehack code integrated (TW)
; 2006.18.07 FileSystem.resource find routine access fault fixed (TW)
; 2007.03.30 mousehack do not start multiple times anymore (TW)
; 2007.06.15 uninitialized variable in memory type selection fixed (stupid me) (TW)
; 2007.08.09 started implementing removable drive support (TW)
; 2007.09.01 ACTION_EXAMINE_ALL (TW)
; 2007.09.05 full filesystem device mounting on the fly (TW)
; 2008.01.09 ACTION_EXAMINE_ALL does not anymore return eac_Entries = 0 with continue (fixes some broken programs)
; 2008.12.11 mousehack -> tablet driver
; 2008.12.25 mousehack cursor sync
; 2009.01.20 clipboard sharing
; 2009.12.27 console hook
; 2010.05.27 Z3Chip
; 2011.12.17 built-in CDFS support
; 2015.09.27 KS 1.2 boot hack supported
; 2015.09.28 KS 1.2 boot hack improved, 1.1 and older BCPL-only DOS support.
; 2016.01.14 'Indirect' boot ROM trap support.
; 2018.03.22 Segment tracking
; 2018.07.08 68060 FPU disable
AllocMem = -198
FreeMem = -210
TRAP_DATA_NUM = 4
TRAP_DATA_SEND_NUM = 1
TRAP_DATA = $4000
TRAP_DATA_SIZE = $8000
TRAP_DATA_SLOT_SIZE = 8192
TRAP_DATA_SECOND = 80
TRAP_DATA_TASKWAIT = (TRAP_DATA_SECOND-4)
TRAP_DATA_EXTRA = 144
TRAP_STATUS = $F000
TRAP_STATUS_SLOT_SIZE = 8
TRAP_STATUS_SECOND = 4
TRAP_STATUS_LOCK_WORD = 2
TRAP_STATUS_STATUS2 = 2
TRAP_STATUS_STATUS = 3
TRAP_DATA_DATA = 4
RTAREA_SYSBASE = $3FFC
RTAREA_GFXBASE = $3FF8
RTAREA_INTBASE = $3FF4
RTAREA_INTXY = $3FF0
RTAREA_MOUSEHACK = $3E00
RTAREA_TRAPTASK = $FFF4
RTAREA_EXTERTASK = $FFF8
RTAREA_INTREQ = $FFFC
; don't forget filesys.c! */
PP_MAXSIZE = 4 * 96
PP_FSSIZE = 400
PP_FSPTR = 404
PP_ADDTOFSRES = 408
PP_FSRES = 412
PP_FSRES_CREATED = 416
PP_DEVICEPROC = 420
PP_EXPLIB = 424
PP_FSHDSTART = 428
PP_TOTAL = (PP_FSHDSTART+140)
NOTIFY_CLASS = $40000000
NOTIFY_CODE = $1234
NRF_SEND_MESSAGE = 1
NRF_SEND_SIGNAL = 2
NRF_WAIT_REPLY = 8
NRF_NOTIFY_INITIAL = 16
NRF_MAGIC = $80000000
; normal filehandler segment entrypoint
dc.l (rom_end-start)/4 ; 4
our_seglist:
dc.l 0 ; 8 /* NextSeg */
start:
bra.s startjmp
dc.w 13 ; 0 12
startjmp:
bra.w filesys_mainloop ; 1 16
dc.l make_dev-start ; 2 20
dc.l filesys_init-start ; 3 24
dc.l moverom-start ; 4 28
dc.l bootcode-start ; 5 32
dc.l setup_exter-start ; 6 36
dc.l bcplwrapper-start ; 7 40
dc.l afterdos-start ; 8 44
dc.l hwtrap_install-start ; 9 48
dc.l hwtrap_entry-start ; 10 52
dc.l keymaphack-start ; 11 56
dc.l fpu060disable-start ; 12 60
bootcode:
lea.l doslibname(pc),a1
jsr -96(a6) ; FindResident
move.l d0,a0
move.l 22(a0),d0
move.l d0,a0
jsr (a0)
rts
fpu060disable:
movec pcr,d0
bset #1,d0
movec d0,pcr
jmp (a5)
; BCPL filehandler segment entry point
; for KS 1.1 and older.
cnop 0,4
dc.l (bcpl_end-bcpl_start)/4+1
our_bcpl_seglist:
dc.l 0
dc.l (bcpl_end-bcpl_start)/4+1
bcpl_start:
; d1 = startup packet
lsl.l #2,d1
move.l d1,d7
bra.w filesys_mainloop_bcpl
cnop 0,4
dc.l 0
dc.l 1
dc.l 4
dc.l 2
bcpl_end:
resident
dc.w $4afc
dc.l 0
dc.l rom_end-resident
dc.b 0,1,0,0
dc.l exter_name-resident
dc.l 0
dc.l start-resident
afterdos:
movem.l d2-d7/a2-a6,-(sp)
move.l 4.w,a6
lea gfxlibname(pc),a1
moveq #0,d0
jsr -$0228(a6) ;OpenLibrary
move.l d0,d1
move.w #RTAREA_GFXBASE,d0
bsr.w getrtbase
move.l d1,(a0)
lea intlibname(pc),a1
moveq #0,d0
jsr -$0228(a6) ;OpenLibrary
move.l d0,d1
move.w #RTAREA_INTBASE,d0
bsr.w getrtbase
move.l d1,(a0)
bsr.w clipboard_init
bsr.w consolehook
bsr.w segtrack_init
movem.l (sp)+,d2-d7/a2-a6
moveq #0,d0
rts
filesys_init:
movem.l d0-d7/a0-a6,-(sp)
move.l 4.w,a6
move.w #$FFEC,d0 ; filesys base
bsr getrtbase
move.l (a0),a5
moveq #0,d5
moveq #0,d0
cmp.w #33,20(a6) ; 1.1 or older?
bcs.s FSIN_explibok
lea.l explibname(pc),a1 ; expansion lib name
moveq #36,d0
moveq #1,d5
jsr -552(a6) ; OpenLibrary
tst.l d0
bne.b FSIN_explibok
lea.l explibname(pc),a1 ; expansion lib name
moveq #0,d0
moveq #0,d5
jsr -552(a6) ; OpenLibrary
FSIN_explibok:
move.l d0,a4
REM ; moved to early hwtrap_install
; create fake configdev
exg a4,a6
move.l a6,d0
beq.s .nocd
btst #4,$110+3(a5)
bne.s .nocd
jsr -$030(a6) ;expansion/AllocConfigDev
tst.l d0
beq.s .nocd
move.l d0,a0
lea start(pc),a1
move.l a1,d0
clr.w d0
move.l d0,32(a0)
move.l #65536,36(a0)
move.w #$0104,16(a0) ;type + product
move.w #2011,16+4(a0) ;manufacturer
moveq #1,d0
move.l d0,22(a0) ;serial
jsr -$01e(a6) ;expansion/AddConfigDev
.nocd
exg a4,a6
EREM
tst.l $10c(a5)
beq.w FSIN_none
move.l #PP_TOTAL,d0
move.l #$10001,d1
jsr AllocMem(a6)
move.l d0,a3 ; param packet
move.l a4,PP_EXPLIB(a3)
moveq #0,d6
FSIN_init_units:
cmp.w $10e(a5),d6
bcc.b FSIN_units_ok
move.l d6,-(sp)
FSIN_nextsub:
move.l $110(a5),d7
tst.w d5
beq.s .oldks
bset #2,d7
.oldks move.l a3,-(sp)
move.l a3,a0
bsr.w make_dev
move.l (sp)+,a3
move.l d1,PP_DEVICEPROC(a3)
cmp.l #-2,d0
beq.s FSIN_nomoresub
swap d6
addq.w #1,d6
swap d6
bra.s FSIN_nextsub
FSIN_nomoresub:
move.l (sp)+,d6
addq.w #1,d6
bra.b FSIN_init_units
FSIN_units_ok:
move.l 4.w,a6
move.l a3,a1
move.l #PP_TOTAL,d0
jsr FreeMem(a6)
FSIN_none:
move.l 4.w,a6
move.l a4,d0
beq.s .noexpclose
move.l a4,a1
jsr -414(a6) ; CloseLibrary
.noexpclose
cmp.w #34,20(a6) ; 1.2 or older?
bcs.w FSIN_tooold
; add MegaChipRAM
moveq #3,d4 ; MEMF_CHIP | MEMF_PUBLIC
cmp.w #36,20(a6)
bcs.s FSIN_ksold
or.w #256,d4 ; MEMF_LOCAL
FSIN_ksold
move.w #$FF80,d0
bsr.w getrtbase
jsr (a0) ; d1 = size, a1 = start address
move.l d0,d5
move.l a1,a0
move.l d1,d0
beq.s FSIN_fchip_done
move.l d4,d1
moveq #-5,d2
lea fchipname(pc),a1
jsr -618(a6) ; AddMemList
FSIN_fchip_done
; only if >=4M chip
cmp.l #$400000,d5
bcs.s FSIN_locmem
cmp.l 62(a6),d5
beq.s FSIN_locmem
jsr -$78(a6)
move.l d5,62(a6) ;LocMem
moveq #0,d0
moveq #(82-34)/2-1,d1
lea 34(a6),a0
.FSIN_locmem1
add.w (a0)+,d0
dbf d1,.FSIN_locmem1
not.w d0
move.w d0,82(a6) ;ChkSum
jsr -$7e(a6)
FSIN_locmem
; add >2MB-6MB chip RAM to memory list (if not already done)
lea $210000,a1
; do not add if RAM detected already
jsr -$216(a6) ; TypeOfMem
tst.l d0
bne.s FSIN_chip_done
move.l d4,d1
moveq #-10,d2
move.l #$200000,a0
move.l d5,d0
sub.l a0,d0
bcs.b FSIN_chip_done
beq.b FSIN_chip_done
sub.l a1,a1
jsr -618(a6) ; AddMemList
FSIN_chip_done
lea fstaskname(pc),a0
lea fsmounttask(pc),a1
moveq #10,d0
bsr createtask
move.l d0,a1
moveq #1,d1
move.w #$FF48,d0 ; store task pointer
bsr.w getrtbase
jsr (a0)
FSIN_tooold
movem.l (sp)+,d0-d7/a0-a6
general_ret:
rts
REM
addextrachip:
move.w #$FF80,d0
bsr.w getrtbase
jsr (a0)
jsr -$0078(a6) ; Disable
lea 322(a6),a0 ; MemHeader
FSIN_scanchip:
move.l (a0),a0 ; first MemList
tst.l (a0)
beq.w FSIN_scannotfound
move.l 20(a0),d1 ; mh_Lower
clr.w d1
tst.l d1
bne.s FSIN_scanchip
move.w 14(a0),d1 ; attributes
bmi.s FSIN_scanchip
and #2,d1 ; MEMF_CHIP?
beq.s FSIN_scanchip
sub.l 24(a0),d0 ; did KS detect all chip?
bmi.s FSIN_scandone
beq.s FSIN_scandone
; add the missing piece
move.l 24(a0),d1
add.l d0,24(a0) ; mh_Upper
add.l d0,28(a0) ; mh_Free
add.l d0,62(a6) ; MaxLocMem
; we still need to update last node's free space
move.l 16(a0),a0 ; mh_First
FSIN_chiploop2
tst.l (a0)
beq.s FSIN_chiploop
move.l (a0),a0
bra.s FSIN_chiploop2
FSIN_chiploop:
move.l a0,d2
add.l 4(a0),d2
;Last block goes to end of chip?
cmp.l d2,d1
beq.s FSIN_chipadd1
;It didn't, add new MemChunk
move.l d1,(a0)
move.l d1,a1
clr.l (a1)+
move.l d0,(a1)
bra.s FSIN_scandone
FSIN_chipadd1:
add.l d0,4(a0)
FSIN_scandone:
jsr -$007e(a6) ; Enable
rts
FSIN_scannotfound:
moveq #3,d4 ; MEMF_CHIP | MEMF_PUBLIC
cmp.w #36,20(a6)
bcs.s FSIN_ksold
or.w #256,d4 ; MEMF_LOCAL
FSIN_ksold
; add >2MB-6MB chip RAM to memory list
lea $210000,a1
; do not add if RAM detected already
jsr -$216(a6) ; TypeOfMem
tst.l d0
bne.s FSIN_chip_done
move.w #$FF80,d0
bsr.w getrtbase
jsr (a0)
move.l d4,d1
moveq #-10,d2
move.l #$200000,a0
sub.l a0,d0
bcs.b FSIN_chip_done
beq.b FSIN_chip_done
sub.l a1,a1
jsr -618(a6) ; AddMemList
FSIN_chip_done
rts
EREM
createproc
movem.l d2-d5/a2/a6,-(sp)
moveq #0,d5
move.l 4.w,a6
move.l d0,d2
move.l d1,d4
move.l a1,d3
move.l a0,a2
lea doslibname(pc),a1
moveq #0,d0
jsr -$0228(a6) ; OpenLibrary
tst.l d0
beq.s .noproc
move.l d0,a6
move.l a2,d1
lsr.l #2,d3
jsr -$08a(a6) ; CreateProc
move.l d0,d5
move.l a6,a1
move.l 4.w,a6
jsr -$019e(a6); CloseLibrary
.noproc
move.l d5,d0
movem.l (sp)+,d2-d5/a2/a6
rts
; this is getting ridiculous but I don't see any other solutions..
fsmounttask
.fsm1 move.l 4.w,a6
moveq #0,d0
bset #13,d0 ; SIGBREAK_CTRL_D
jsr -$013e(a6) ;Wait
lea fsprocname(pc),a0
lea mountproc(pc),a1
moveq #15,d0
move.l #8000,d1
bsr.w createproc
bra.s .fsm1
; dummy process here because can't mount devices with ADNF_STARTPROC from task..
; (AddDosNode() internally calls GetDeviceProc() which accesses ExecBase->ThisTask->pr_GlobVec)
cnop 0,4
dc.l 16
mountproc
dc.l 0
moveq #2,d1
move.w #$FF48,d0 ; get new unit number
bsr.w getrtbaselocal
jsr (a0)
move.l d0,d1
bmi.s .out
bsr.w addfsonthefly
.out moveq #0,d0
rts
trap_task:
move.l 4.w,a6
trap_task_wait
move.l #$100,d0
jsr -$13e(a6) ;Wait
trap_task_check:
moveq #0,d7
; check if we have call lib/func request
move.l #TRAP_STATUS,d0
bsr.w getrtbase
move.l a0,a1
move.l #TRAP_DATA,d0
bsr.w getrtbase
moveq #TRAP_DATA_NUM-1,d6
.nexttrap
tst.b TRAP_STATUS_STATUS(a1)
beq.s .next
cmp.b #$fd,TRAP_STATUS_SECOND+TRAP_STATUS_STATUS(a1)
bne.s .next
addq.l #1,d7
lea TRAP_DATA_SECOND+4(a0),a4
lea TRAP_STATUS_SECOND(a1),a5
movem.l d6/d7/a0/a1/a4/a5/a6,-(sp)
move.w (a5),d4 ;command
movem.l (a4),a0-a2
movem.l (a4),d0-d2
cmp.w #18,d4
bne.s .notcalllib
bsr.w hw_call_lib
bra.s .calldone
.notcalllib
cmp.w #19,d4
bne.s .calldone
bsr.w hw_call_func
.calldone
movem.l (sp)+,d6/d7/a0-a1/a4/a5/a6
move.l d0,(a4)
move.b #2,TRAP_STATUS_STATUS(a5)
.next
add.w #TRAP_DATA_SLOT_SIZE,a0
add.w #TRAP_STATUS_SLOT_SIZE,a1
dbf d6,.nexttrap
tst.l d7
beq.w trap_task_wait
bra.w trap_task_check
exter_task:
move.l 4.w,a6
exter_task_wait
move.l #$100,d0
jsr -$13e(a6) ;Wait
bsr.s exter_do
bra.s exter_task_wait
exter_done
rts
exter_do
moveq #10,d7
EXTT_loop
move.w #$FF50,d0 ; exter_int_helper
bsr.w getrtbaselocal
move.l d7,d0
jsr (a0)
tst.l d0
beq.s exter_done
moveq #11,d7
cmp.w #1,d0
blt.w EXTT_loop
bgt.b EXTT_signal_reply
jsr -366(a6) ; PutMsg
bra.b EXTT_loop
EXTT_signal_reply:
cmp.w #2,d0
bgt.b EXTT_reply
move.l d1,d0
jsr -$144(a6) ; Signal
bra.b EXTT_loop
EXTT_reply:
cmp.w #3,d0
bgt.b EXTT_cause
jsr -$17a(a6) ; ReplyMsg
bra.b EXTT_loop
EXTT_cause:
cmp.w #4,d0
bgt.b EXTT_notificationhack
jsr -$b4(a6) ; Cause
bra.b EXTT_loop
EXTT_notificationhack:
cmp.w #5,d0
bgt.b EXTT_shellexec
movem.l a0-a1,-(sp)
moveq #38,d0
move.l #65536+1,d1
jsr AllocMem(a6)
movem.l (sp)+,a0-a1
move.l d0,a2
move.b #8,8(a2)
move.l a0,14(a2)
move.w #38,18(a2)
move.l #NOTIFY_CLASS,20(a2)
move.w #NOTIFY_CODE,24(a2)
move.l a1,26(a2)
move.l 16(a1),a0
move.l a2,a1
jsr -366(a6) ; PutMsg
bra.w EXTT_loop
EXTT_shellexec
cmp.w #6,d0
bgt.w EXTT_loop
lea shellexecname(pc),a0
lea shellexecproc(pc),a1
moveq #1,d0
move.l #10000,d1
bsr.w createproc
move.l d0,d1
move.w #$FF50,d0 ; exter_int_helper
bsr.w getrtbaselocal
moveq #20,d0
jsr (a0)
bra.w EXTT_loop
exter_server_new:
moveq #0,d0
move.l (a1)+,a0 ;IO Base
tst.b (a0)
beq.s .nouaeint
move.l (a1)+,a6 ; SysBase
; movem.l d7/a0/a2,-(sp)
; bsr.w exter_do
; movem.l (sp)+,d7/a0/a2
move.l (a1),a1 ; Task
move.l #$100,d0 ; SIGF_DOS
jsr -$144(a6) ; Signal
moveq #1,d0
.nouaeint
tst.w d0
rts
cnop 0,4
dc.l 16
shellexecproc:
dc.l 0
move.l 4.w,a6
lea doslibname(pc),a1
moveq #0,d0
jsr -$228(a6) ; OpenLibrary
move.l d0,a5
exg a5,a6
bra.s .seproc1
.seproc0
exg a5,a6
moveq #0,d0
bset #13,d0 ; SIGBREAK_CTRL_D
jsr -$013e(a6) ;Wait
exg a5,a6
.seproc1
move.w #$FF50,d0 ; exter_int_helper
bsr.w getrtbaselocal
moveq #21,d0
jsr (a0)
; a0 = command
move.l a0,d7
beq.s .seproc0
move.l sp,a4
lea -5*8-512(sp),sp
move.l sp,d6
move.l d6,a2
lea 5*8(a2),a3
move.l a3,a1
move.l d7,a0
.seproc2
move.b (a0)+,(a1)+
bne.s .seproc2
move.l d7,a0
clr.b (a0)
; SYS_Input
move.l #$80000000+32+1,(a2)+
lea nil_name(pc),a0
move.l a0,d1
move.l #1005,d2
jsr -$1e(a6) ;Open
move.l d0,(a2)+
; SYS_Output
move.l #$80000000+32+2,(a2)+
lea nil_name(pc),a0
move.l a0,d1
jsr -$1e(a6) ;Open
move.l d0,(a2)+
; SYS_Async
move.l #$80000000+32+3,(a2)+
moveq #-1,d0
move.l d0,(a2)+
clr.l (a2)+
clr.l (a2)
cmp.w #36,20(a6)
bcc.s .seproc3
move.l d6,a2
move.l a3,d1 ;Command
moveq #0,d2 ;Input
move.l 1*8+4(a2),d3 ;Output
jsr -$de(a6) ;Execute
move.l 0*8+4(a2),d1
jsr -$24(a6) ;Close
move.l 1*8+4(a2),d1
jsr -$24(a6) ;Close
bra.s .seproc4
.seproc3
move.l a3,d1
move.l d6,d2
jsr -$25e(a6) ; SystemTagList
.seproc4
move.l a4,sp
move.w #$FF50,d0 ; exter_int_helper
bsr.w getrtbaselocal
moveq #22,d0
jsr (a0)
bra.w .seproc0
; d0 = exter task, d1 = trap task
heartbeatvblank:
movem.l d0-d3/a0-a4,-(sp)
move.l d0,d2
move.l d1,d3
move.w #$FF38,d0
moveq #18,d1
bsr.w getrtbaselocal
move.l d2,d0
move.l d3,d2
jsr (a0)
move.l d0,a2 ; intreq
moveq #22+5*4,d0
move.l #65536+1,d1
jsr AllocMem(a6)
move.l d0,a4
lea 22(a4),a3
move.l a3,a1
move.l a2,(a1)+
move.l d2,(a1)+
move.l d3,(a1)+
move.w #RTAREA_INTBASE,d0
bsr.w getrtbase
move.l a0,(a1)+
move.w #RTAREA_INTXY,d0
bsr.w getrtbase
move.l a0,(a1)+
move.l a3,14(a4)
move.b #2,8(a4) ;NT_INTERRUPT
move.b #-10,9(a4) ;priority
lea kaname(pc),a0
move.l a0,10(a4)
lea kaint(pc),a0
move.l a0,18(a4)
move.l a4,a1
moveq #5,d0 ;INTB_VERTB
jsr -$00a8(a6)
movem.l (sp)+,d0-d3/a0-a4
rts
kaint:
move.l (a1),a0
addq.l #1,(a0)
move.l 3*4(a1),a0 ;RTAREA_INTBASE
move.l (a0),d0
beq.s .noint
move.l d0,a0
cmp.w #31,20(a0) ;version < 31
bcs.s .noint
tst.l 34(a0) ;ViewPort == NULL
beq.s .noint
tst.l 60(a0) ;FirstScreen == NULL
beq.s .noint
move.l 4*4(a1),a1
move.l 68(a0),(a1) ;Y.W X.W
.noint
moveq #0,d0
rts
setup_exter:
movem.l d0-d3/d7/a0-a2,-(sp)
move.l d0,d7
move.l #RTAREA_INTREQ,d0
bsr.w getrtbase
move.l a0,a2
moveq #0,d2
btst #0,d7
beq.s .nofstask
lea fswtaskname(pc),a0
lea exter_task(pc),a1
moveq #20,d0
bsr createtask
move.l d0,d2
.nofstask
moveq #0,d3
btst #1,d7
beq.s .notraptask
lea fstraptaskname(pc),a0
lea trap_task(pc),a1
moveq #25,d0
bsr createtask
move.l d0,d3
.notraptask
moveq #26+4*4,d0
move.l #$10001,d1
jsr AllocMem(a6)
move.l d0,a1
lea 26(a1),a0
move.l a2,(a0)+
move.l a6,(a0)+
move.l d2,(a0)+
move.l d3,(a0)
lea.l exter_name(pc),a0
move.l a0,10(a1)
lea 26(a1),a2
move.l a2,14(a1)
lea.l exter_server_new(pc),a0
move.l a0,18(a1)
move.w #$0214,8(a1)
moveq #3,d0
jsr -168(a6) ; AddIntServer
move.l d2,d0 ; extertask
move.l d3,d1 ; traptask
bsr.w heartbeatvblank
move.w #$FF38,d0
moveq #4,d1
bsr.w getrtbaselocal
jsr (a0)
tst.l d0
beq.s .nomh
bsr.w mousehack_init
.nomh
movem.l (sp)+,d0-d3/d7/a0-a2
rts
addfs: ; a0 = first hunk, a1 = parmpacket
movem.l d0-d1/a0-a3/a6,-(sp)
move.l 4.w,a6
move.l a0,a2
move.l a1,a3
move.l #62+128,d0 ; sizeof(FileSysEntry) + patchflags;
move.l #$10001,d1
jsr -198(a6)
move.l d0,a0
moveq #0,d0
lea PP_FSHDSTART(a3),a1
af1 move.b 0(a1,d0.w),14(a0,d0.w)
addq.w #1,d0
cmp.w #140,d0
bne.s af1
move.l a2,d0
lsr.l #2,d0
move.l d0,54(a0) ;seglist
move.l a0,a1
lea exter_name(pc),a0
move.l a0,10(a1) ; name
move.l PP_FSRES(a3),a0 ; FileSystem.resource
lea 18(a0),a0 ; fsr_FileSysEntries
jsr -$f0(a6) ;AddHead
movem.l (sp)+,d0-d1/a0-a3/a6
rts
relocate: ;a0=pointer to executable, returns first segment in A0
movem.l d1-d7/a1-a6,-(sp)
move.l 4.w,a6
move.l a0,a2
cmp.l #$3f3,(a2)+
bne.w ree
addq.l #8,a2 ; skip name end and skip total hunks + 1
move.l 4(a2),d7 ; last hunk
sub.l (a2),d7 ; first hunk
addq.l #8,a2 ; skip hunk to load first and hunk to load last
addq.l #1,d7
move.l a2,a3
move.l d7,d0
lsl.l #2,d0
add.l d0,a3
move.l a2,a4
; allocate hunks
sub.l a5,a5 ;prev segment
moveq #0,d6
r15 move.l (a2),d2 ; hunk size (header)
moveq #1,d1
btst #30,d2 ; chip mem?
beq.s r2
bset #1,d1
r2 bset #16,d1
lsl.l #2,d2
bne.s r17
clr.l (a2)+ ; empty hunk
bra.s r18
r17 addq.l #8,d2 ; size + pointer to next hunk + hunk size
move.l d2,d0
jsr AllocMem(a6)
tst.l d0
beq.w ree
move.l d0,a0
move.l d2,(a0)+ ; store size
move.l a0,(a2)+ ; store new pointer
move.l a5,d1
beq.s r10
move.l a0,d0
lsr.l #2,d0
move.l d0,(a5)
r10 move.l a0,a5
r18 addq.l #1,d6
cmp.l d6,d7
bne.s r15
moveq #0,d6
r3 move.l d6,d1
lsl.l #2,d1
move.l 0(a4,d1.l),a0
addq.l #4,a0
move.l (a3)+,d3 ; hunk type
move.l (a3)+,d4 ; hunk size
lsl.l #2,d4
cmp.l #$3e9,d3 ;code
beq.s r4
cmp.l #$3ea,d3 ;data
bne.s r5
r4
; code and data
move.l d4,d0
r6 tst.l d0
beq.s r7
move.b (a3)+,(a0)+
subq.l #1,d0
bra.s r6
r5
cmp.l #$3eb,d3 ;bss
bne.s ree
r7 ; scan for reloc32, symbol, debug or hunk_end
move.l (a3)+,d3
cmp.l #$3ec,d3 ;reloc32
bne.s r13
; relocate
move.l d6,d1
lsl.l #2,d1
move.l 0(a4,d1.l),a0 ; current hunk
addq.l #4,a0
r11 move.l (a3)+,d0 ;number of relocs
beq.s r7
move.l (a3)+,d1 ;hunk
lsl.l #2,d1
move.l 0(a4,d1.l),d3 ;hunk start address
addq.l #4,d3
r9 move.l (a3)+,d2 ;offset
add.l d3,0(a0,d2.l)
subq.l #1,d0
bne.s r9
bra.s r11
r13
cmp.l #$3f0,d3 ;symbol
bne.s r20
r21
move.l (a3)+,d0
beq.s r7
and.l #$ffffff,d0
addq.l #1,d0
lsl.l #2,d0
add.l d0,a3
bra.s r21
r20
cmp.l #$3f1,d3 ;debug
bne.s r22
move.l (a3)+,d0
lsl.l #2,d0
add.l d0,a3
bra.s r7
r22
cmp.l #$3f2,d3 ;end
bne.s ree
addq.l #1,d6
cmp.l d6,d7
bne.w r3
moveq #1,d7