home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 1 / Mecomp-CD.iso / amiga / tools / boot / fastexec / fastexec.s < prev   
Text File  |  1997-05-21  |  75KB  |  4,483 lines

  1. ;------------------------------------------------------------------------------;
  2. ;------------------------------------------------------------------------------;
  3. ;------------------------------------------------------------------------------;
  4.  
  5. _DOSBase        = 0
  6. _ExpansionBase        = _DOSBase+4
  7. _UtilityBase        = _ExpansionBase+4
  8. Args            = _UtilityBase+4
  9. ArgsX            = Args+4
  10. ReturnCode        = ArgsX+4
  11. my_SIZEOF        = ReturnCode+4
  12.  
  13. ;------------------------------------------------------------------------------;
  14. ;------------------------------------------------------------------------------;
  15. ;------------------------------------------------------------------------------;
  16.  
  17. Start:
  18.     move.l    (4).w,a6
  19.     move.l    a0,a2
  20.     move.l    d0,d2
  21.  
  22.     moveq    #my_SIZEOF/4-1,d1
  23.  
  24. .Clear
  25.     clr.l    -(sp)
  26.     dbf    d1,.Clear
  27.     move.l    sp,a5
  28.  
  29.     lea    dos_library(pc),a1    ; library
  30.     moveq    #0,d0            ; version
  31.     jsr    -$0228(a6)        ; _LVOOpenLibrary
  32.     move.l    d0,_DOSBase(a5)
  33.     lea    expansion_library(pc),a1; library
  34.     moveq    #0,d0            ; version
  35.     jsr    -$0228(a6)        ; _LVOOpenLibrary
  36.     move.l    d0,_ExpansionBase(a5)
  37.  
  38.     cmp    #36,$0014(a6)        ; lib_Version
  39.     bcs    .LibsOk
  40.     lea    utility_library(pc),a1    ; library
  41.     moveq    #0,d0            ; version
  42.     jsr    -$0228(a6)        ; _LVOOpenLibrary
  43.     move.l    d0,_UtilityBase(a5)
  44.  
  45. .LibsOk
  46.     subq.l    #1,d2
  47.     bls    .Ok
  48.     cmp.b    #'?',(a2)
  49.     beq    Usage
  50.  
  51.     cmp    #36,$0014(a6)        ; lib_Version
  52.     bcs    .GetArgs
  53.  
  54.     lea    Template(pc),a1
  55.     move.l    a1,d1            ; template
  56.     lea    ArgArray(pc),a1
  57.     move.l    a1,d2            ; array
  58.     moveq    #0,d3            ; args
  59.     move.l    a6,-(sp)
  60.     move.l    _DOSBase(a5),a6
  61.     jsr    -$031E(a6)        ; _LVOReadArgs
  62.     tst.l    d0
  63.     bne    .ReadArgsOk
  64.     jsr    -$0084(a6)        ; _LVOIoErr
  65.     move.l    d0,d1            ; code
  66.     moveq    #0,d2            ; header
  67.     jsr    -$01DA(a6)        ; _LVOPrintFault
  68.     moveq    #0,d0
  69.  
  70. .ReadArgsOk
  71.     move.l    (sp)+,a6
  72.     move.l    d0,Args(a5)
  73.     beq    QuitError
  74.  
  75.     move.l    ArgSYSINFO(pc),d0
  76.     beq    .ArgSYSINFOOk
  77.     bsr    SysInfo
  78.     bra    Quit
  79.  
  80. .ArgSYSINFOOk
  81.     move.l    ArgCACHE(pc),d0
  82.     beq    .ArgCACHEOk
  83.     move.l    d0,a0
  84.     bsr    XToI
  85.     lea    CacheBits(pc),a0
  86.     move.l    d0,(a0)
  87.  
  88. .ArgCACHEOk
  89.     movem.l    d2-d7/a2-a4,-(sp)
  90.     lea    AddMemData(pc),a4
  91.     move.l    ArgADDMEM(pc),a3
  92.     moveq    #15,d3
  93.     move.l    a3,d0
  94.     beq    .AddMem2
  95.  
  96. .AddMemLoop2
  97.     move.l    (a3)+,d0
  98.     beq    .AddMem2
  99.     move.l    d0,a0
  100.     bsr    XToI
  101.     move.l    d0,d7            ; base
  102.     beq    .AddMemErr2
  103.     move.l    (a3)+,d0
  104.     beq    .AddMemErr2
  105.     move.l    d0,a0
  106.     bsr    XToI
  107.     move.l    d0,d4            ; size
  108.     beq    .AddMemErr2
  109.     move.l    (a3)+,d0
  110.     beq    .AddMemErr2
  111.     move.l    d0,a0
  112.     bsr    XToIS
  113.     move.l    d0,d5            ; attributes
  114.     beq    .AddMemErr2
  115.     move.l    (a3)+,d0
  116.     beq    .AddMemErr2
  117.     move.l    d0,a0
  118.     bsr    XToIS
  119.     move.l    d0,d6            ; priority
  120.     cmp.l    #$FF,d6
  121.     bhi    .AddMemErr2
  122.  
  123.     movem.l    d4-d7,(a4)
  124.     lea    16(a4),a4
  125.     dbf    d3,.AddMemLoop2
  126.     bra    .AddMem2
  127.  
  128. .AddMemErr2
  129.     movem.l    (sp)+,d2-d7/a2-a4
  130.     lea    TxtAddMem(pc),a0    ; string
  131.     bra    QuitPutS
  132.  
  133. .AddMem2
  134.     movem.l    (sp)+,d2-d7/a2-a4
  135.     bra    .Ok
  136.  
  137. .GetArgs
  138.     move.l    a2,a0
  139.     bsr    GetArgs
  140.     move.l    d0,ArgsX(a5)
  141.     bne    .Args
  142.  
  143.     lea    TxtAllocMem(pc),a0    ; string
  144.     bra    QuitPutS
  145.  
  146. .Args
  147.     move.l    d0,d2
  148.  
  149.     move.l    d2,a0            ; args
  150.     lea    StrSYSINFO(pc),a1    ; arg
  151.     bsr    FindArg
  152.     tst.l    d0
  153.     beq    .SysInfo
  154.     bsr    SysInfo
  155.     bra    Quit
  156.  
  157. .SysInfo
  158.     move.l    d2,a0            ; args
  159.     lea    StrREBOOT(pc),a1    ; arg
  160.     bsr    FindArg
  161.     tst.l    d0
  162.     lea    ArgREBOOT(pc),a0
  163.     sne    (a0)
  164.  
  165.     move.l    d2,a0            ; args
  166.     lea    StrFASTSSP(pc),a1    ; arg
  167.     bsr    FindArg
  168.     tst.l    d0
  169.     lea    ArgFASTSSP(pc),a0
  170.     sne    (a0)
  171.  
  172.     move.l    d2,a0            ; args
  173.     lea    StrFASTVBR(pc),a1    ; arg
  174.     bsr    FindArg
  175.     tst.l    d0
  176.     lea    ArgFASTVBR(pc),a0
  177.     sne    (a0)
  178.  
  179.     move.l    d2,a0            ; args
  180.     lea    StrNOEXEC(pc),a1    ; arg
  181.     bsr    FindArg
  182.     tst.l    d0
  183.     lea    ArgNOEXEC(pc),a0
  184.     sne    (a0)
  185.  
  186.     move.l    d2,a0            ; args
  187.     lea    StrLOCAL(pc),a1        ; arg
  188.     bsr    FindArg
  189.     tst.l    d0
  190.     lea    ArgLOCAL(pc),a0
  191.     sne    (a0)
  192.  
  193.     move.l    d2,a0            ; args
  194.     lea    StrFASTEXP(pc),a1    ; arg
  195.     bsr    FindArg
  196.     tst.l    d0
  197.     lea    ArgFASTEXP(pc),a0
  198.     sne    (a0)
  199.  
  200.     move.l    d2,a0            ; args
  201.     lea    StrFASTMEM(pc),a1    ; arg
  202.     bsr    FindArg
  203.     tst.l    d0
  204.     lea    ArgFASTMEM(pc),a0
  205.     sne    (a0)
  206.  
  207.     move.l    d2,a0            ; args
  208.     lea    StrFASTINT(pc),a1    ; arg
  209.     bsr    FindArg
  210.     tst.l    d0
  211.     lea    ArgFASTINT(pc),a0
  212.     sne    (a0)
  213.  
  214.     move.l    d2,a0            ; args
  215.     lea    StrPATCH(pc),a1        ; arg
  216.     bsr    FindArg
  217.     tst.l    d0
  218.     lea    ArgPATCH(pc),a0
  219.     sne    (a0)
  220.  
  221.     move.l    d2,a0            ; args
  222.     lea    StrCACHE(pc),a1        ; arg
  223.     bsr    FindArg
  224.     tst.l    d0
  225.     beq    .Cache
  226.     lea    ArgCACHE(pc),a0
  227.     st    (a0)
  228.     move.l    d0,d1
  229.     subq.l    #1,d1
  230.     beq    .Cache
  231.     move.l    d0,a0
  232.     bsr    XToI
  233.     move.l    d0,CacheBits
  234.  
  235. .Cache
  236.     movem.l    d2-d7/a2/a4,-(sp)
  237.     lea    AddMemData(pc),a4
  238.     moveq    #15,d3
  239.  
  240.     move.l    d2,a0            ; args
  241.     lea    StrADDMEM(pc),a1    ; arg
  242.     bsr    FindArg
  243.     tst.l    d0
  244.     beq    .AddMem
  245.     move.l    d0,d1
  246.     subq.l    #1,d1
  247.     beq    .AddMem
  248.     move.l    d0,a0
  249.  
  250. .AddMemLoop
  251.     bsr    XToI
  252.     move.l    d0,d7            ; base
  253.     beq    .AddMem
  254.     bsr    XToI
  255.     move.l    d0,d4            ; size
  256.     beq    .AddMemErr
  257.     bsr    XToIS
  258.     move.l    d0,d5            ; attributes
  259.     beq    .AddMemErr
  260.     bsr    XToIS
  261.     move.l    d0,d6            ; priority
  262.     cmp.l    #$FF,d6
  263.     bhi    .AddMemErr
  264.  
  265.     movem.l    d4-d7,(a4)
  266.     lea    16(a4),a4
  267.     dbf    d3,.AddMemLoop
  268.     bra    .AddMem
  269.  
  270. .AddMemErr
  271.     movem.l    (sp)+,d2-d7/a2/a4
  272.     lea    TxtAddMem(pc),a0    ; string
  273.     bra    QuitPutS
  274.  
  275. .AddMem
  276.     movem.l    (sp)+,d2-d7/a2/a4
  277.  
  278. .Ok
  279.     bsr    AddResident
  280.     tst.l    d0
  281.     bgt    ResidentOk
  282.  
  283. ;Not enough memory?
  284.     lea    TxtAllocMem(pc),a0
  285.     tst.l    d0
  286.     beq    QuitPutS
  287.  
  288. ;FastExec already installed?
  289.     moveq    #-1,d1
  290.     cmp.l    d1,d0
  291.     beq    Quit
  292.  
  293. ;Can't find expansion.library?
  294.     lea    TxtExpansion(pc),a0
  295.     moveq    #-2,d1
  296.     cmp.l    d1,d0
  297.     beq    QuitPutS
  298.  
  299. ResidentOk
  300.  
  301. ;FastExec installed okay
  302. ;If exec.library already is in fast memory, give a warning
  303. ;(except if NOEXEC option is used).
  304.  
  305.     move.l    ArgNOEXEC(pc),d0
  306.     bne    Reboot
  307.  
  308.     move.l    a6,a1            ; address
  309.     bsr    MyTypeOfMem
  310.     and    #4,d0            ; MEMF_FAST
  311.     beq    Reboot
  312.  
  313.     lea    TxtExec(pc),a0
  314.     bra    QuitPutS
  315.  
  316. Reboot
  317.     move.l    ArgREBOOT(pc),d0
  318.     beq    Quit
  319.     bra    OSColdReboot
  320.  
  321. QuitPutS
  322. ;    a0=string
  323.  
  324.     move.l    a0,d1            ; str
  325.     bsr    OSPutStr
  326.  
  327. QuitError
  328.     moveq    #10,d0            ; RETURN_ERROR
  329.     move.l    d0,ReturnCode(a5)
  330.  
  331. Quit:
  332.     move.l    ArgsX(a5),a1        ; memoryBlock
  333.     bsr    OSFreeVec
  334.     move.l    Args(a5),d1        ; args
  335.     bsr    OSFreeArgs
  336.  
  337.     move.l    _UtilityBase(a5),a1    ; library
  338.     bsr    OSCloseLibrary
  339.     move.l    _ExpansionBase(a5),a1    ; library
  340.     bsr    OSCloseLibrary
  341.     move.l    _DOSBase(a5),a1        ; library
  342.     bsr    OSCloseLibrary
  343.  
  344.     move.l    ReturnCode(a5),d0
  345.     lea    my_SIZEOF(sp),sp
  346.     rts
  347.  
  348. ;------------------------------------------------------------------------------;
  349. ;------------------------------------------------------------------------------;
  350. ;------------------------------------------------------------------------------;
  351.  
  352.     cnop    0,4
  353.  
  354. Resident:
  355.     move.l    ArgCACHE(pc),d0
  356.     beq    .Cache
  357.     move.l    CacheBits(pc),d0    ; cacheBits
  358.     or    #$2000,d0        ; CACRF_WriteAllocate
  359.     moveq    #-1,d1            ; cacheMask
  360.     bsr    OSCacheControl
  361.  
  362. .Cache
  363.     bsr    PatchLower
  364.     bsr    PatchUpper
  365.  
  366.     jsr    -$0084(a6)        ; _LVOForbid
  367.     moveq    #0,d0            ; cacheBits
  368.     moveq    #-1,d1            ; cacheMask
  369.     bsr    OSCacheControl
  370.     move.l    d0,-(sp)
  371.  
  372. ;patch MakeLibrary() on KS 1.3 to longword align library bases.
  373.  
  374.     cmp    #36,$0014(a6)        ; lib_Version
  375.     bcc    .MakeLibraryOk
  376.     move.l    a6,a1            ; library
  377.     lea    MakeLibrary(pc),a0
  378.     move.l    a0,d0            ; newFunction
  379.     move    #-$0054,a0        ; funcOffset, _LVOMakeLibrary
  380.     jsr    -$01A4(a6)        ; _LVOSetFunction
  381.  
  382. .MakeLibraryOk
  383.     move.l    ArgFASTEXP(pc),d0
  384.     beq    .AddLibraryOk
  385.     move.l    a6,a1            ; library
  386.     lea    AddLibrary(pc),a0
  387.     move.l    a0,d0            ; newFunction
  388.     move    #-$018C,a0        ; funcOffset, _LVOAddLibrary
  389.     jsr    -$01A4(a6)        ; _LVOSetFunction
  390.     lea    OldAddLibrary(pc),a0
  391.     move.l    d0,(a0)
  392.  
  393. .AddLibraryOk
  394.     lea    AddMemList(pc),a0
  395.     move.l    ArgLOCAL(pc),d0
  396.     beq    .AddMemList
  397.     lea    AddMemListFlags(pc),a0
  398.  
  399. .AddMemList
  400.     move.l    a6,a1            ; library
  401.     move.l    a0,d0            ; newFunction
  402.     move    #-$026A,a0        ; funcOffset, _LVOAddMemList
  403.     jsr    -$01A4(a6)        ; _LVOSetFunction
  404.     lea    OldAddMemList(pc),a0
  405.     move.l    d0,(a0)
  406.  
  407.     bsr    OSCacheClearU
  408.     move.l    (sp)+,d0        ; cacheBits
  409.     moveq    #-1,d1            ; cacheMask
  410.     bsr    OSCacheControl
  411.     jsr    -$008A(a6)        ; _LVOPermit
  412.  
  413.     movem.l    d2/a2,-(sp)
  414.     lea    AddMemData(pc),a2
  415.  
  416. .Mem
  417.     movem.l    (a2)+,d0-d2/a0        ; size/attributes/pri/base
  418.     tst.l    d0
  419.     beq    .MemOk
  420.     lea    FastExecName(pc),a1    ; name
  421.     jsr    -$026A(a6)        ; _LVOAddMemList
  422.     bra    .Mem
  423.  
  424. .MemOk
  425.     movem.l    (sp)+,d2/a2
  426.     rts
  427.  
  428. ;------------------------------------------------------------------------------;
  429.  
  430.     cnop    0,4
  431.  
  432. AddLibrary:
  433.     bsr    .AddLibrary
  434.  
  435.     bsr    MoveExpansion
  436.     tst.l    d0
  437.     beq    .Rts
  438.  
  439.     move.l    a6,a1            ; library
  440.     move    #-$018C,a0        ; funcOffset, _LVOAddLibrary
  441.     move.l    OldAddLibrary(pc),d0    ; newFunction
  442.     jsr    -$01A4(a6)        ; _LVOSetFunction
  443.  
  444. .Rts
  445.     rts
  446.  
  447. .AddLibrary
  448.     move.l    OldAddLibrary(pc),-(sp)
  449.     rts
  450.  
  451. OldAddLibrary
  452.     dc.l    0
  453.  
  454. ;------------------------------------------------------------------------------;
  455.  
  456.     cnop    0,4
  457.  
  458. AddMemListFlags:
  459.     or    #$0100,d1        ; attributes, MEMF_LOCAL
  460. ;    bra    AddMemList
  461.  
  462. ;------------------------------------------------------------------------------;
  463.  
  464. AddMemList:
  465.  
  466. ;pretty useless checking
  467.  
  468.     cmp    #$0400,a0
  469.     bcs    .Rts
  470.     cmp.l    #$0028,d0        ; sizeof(MemHeader)+sizeof(MemChunk)
  471.     bcs    .Rts
  472.  
  473. ;If right (but not left) mouse button is held down, don't add any memory.
  474. ;This doesn't work for me when I use the original A1200 mouse...
  475.  
  476. ;    btst    #6,$BFE001
  477. ;    beq    .LMB
  478. ;    btst    #10,$DFF016
  479. ;    beq    .Rts
  480. ;
  481. ;.LMB
  482.  
  483. ;Check if memory has already been added
  484.  
  485.     movem.l    a2/a3,-(sp)
  486.     lea    (a0,d0.l),a3
  487.     lea    $0142(a6),a2        ; MemList
  488.     jsr    -$0084(a6)        ; _LVOForbid
  489.  
  490. .Loop
  491.     move.l    (a2),a2
  492.     tst.l    (a2)
  493.     beq    .Ok
  494.  
  495.     cmp.l    a2,a0
  496.     bcs    .CS
  497.     cmp.l    $0018(a2),a0        ; mh_Upper
  498.     bcc    .Loop
  499.     bra    .Quit
  500.  
  501. .CS
  502.     cmp.l    a2,a3
  503.     bls    .Loop
  504.  
  505. .Quit
  506.     jsr    -$008A(a6)        ; _LVOPermit
  507.     movem.l    (sp)+,a2/a3
  508.  
  509. .Rts
  510.     rts
  511.  
  512. .Old
  513.     move.l    OldAddMemList(pc),-(sp)
  514.     rts
  515.  
  516. .Ok
  517.  
  518. ;save "attributes"
  519.  
  520.     move.l    d1,-(sp)
  521.  
  522. ;add memory using the original function
  523.  
  524.     bsr    .Old
  525.  
  526. ;I'm no expert on how to handle these caches, but
  527. ;I disassembled 68040.library, and it works this way:
  528. ;Forbid()
  529. ;oldCache=CacheControl(0,-1)
  530. ;patch stuff...
  531. ;CacheControl(oldCache,-1)
  532. ;Permit()
  533.  
  534.     jsr    -$0078(a6)        ; _LVODisable
  535.     moveq    #0,d0            ; cacheBits
  536.     moveq    #-1,d1            ; cacheMask
  537.     bsr    OSCacheControl
  538.     move.l    d0,-(sp)
  539.  
  540.     move.l    ArgFASTMEM(pc),d0
  541.     beq    .Chip
  542.     bsr    MoveChipHeader
  543.  
  544. .Chip
  545.     move.l    ArgNOEXEC(pc),d0
  546.     bne    .Exec
  547.     bsr    MoveExec
  548.  
  549. .Exec
  550.     move.l    ArgFASTSSP(pc),d0
  551.     beq    .SSP
  552.     bsr    MoveSSP
  553.  
  554. .SSP
  555.     move.l    ArgFASTVBR(pc),d0
  556.     beq    .VBR
  557.     bsr    MoveVBR
  558.  
  559. .VBR
  560.     move.l    ArgFASTINT(pc),d0
  561.     beq    .Int
  562.     bsr    MoveIntrMem
  563.  
  564. .Int
  565.     move.l    ArgPATCH(pc),d0
  566.     beq    .Patch
  567.     bsr    PatchForbid
  568.     bsr    PatchSupervisorSafely
  569.     cmp    #36,$0014(a6)        ; lib_Version
  570.     bcs    .Patch
  571.     bsr    PatchExec
  572.     bsr    PatchInterrupts
  573.  
  574. .Patch
  575.     bsr    OSCacheClearU
  576.     move.l    (sp)+,d0        ; cacheBits
  577.     moveq    #-1,d1            ; cacheMask
  578.     bsr    OSCacheControl
  579.     jsr    -$007E(a6)        ; _LVOEnable
  580.  
  581.     move.l    (sp)+,d1
  582.     and    #4,d1            ; MEMF_FAST
  583.     beq    .Quit
  584.  
  585. ;fast memory has been added, replace our patch with the original AddMemList()
  586.  
  587.     move.l    a6,a1            ; library
  588.     move    #-$026A,a0        ; funcOffset, _LVOAddMemList
  589.     move.l    OldAddMemList(pc),d0    ; newFunction
  590.     jsr    -$01A4(a6)        ; _LVOSetFunction
  591.  
  592.     bra    .Quit
  593.  
  594. ;------------------------------------------------------------------------------;
  595.  
  596.     cnop    0,4
  597.  
  598. MakeLibrary:
  599.     movem.l    d2-d7/a2/a3,-(sp)
  600.     move.l    d0,d3
  601.     move.l    a0,d4
  602.     move.l    a1,d5
  603.     move.l    a2,d6
  604.     move.l    d1,d7
  605.  
  606.     move.l    a0,d2
  607.     beq    .NegOk
  608.  
  609.     move.l    a0,a3
  610.     moveq    #-1,d2
  611.     moveq    #-1,d1
  612.     cmp    (a3),d1
  613.     bne    .Abs
  614.     addq.l    #2,a3
  615.  
  616. .Rel
  617.     cmp    (a3)+,d1
  618.     dbeq    d2,.Rel
  619.     bra    .Neg
  620.  
  621. .Abs
  622.     cmp.l    (a3)+,d1
  623.     dbeq    d2,.Abs
  624.  
  625. .Neg
  626.     not    d2
  627.     mulu    #6,d2
  628.     addq.l    #3,d2
  629.     and    #-4,d2
  630.  
  631. .NegOk
  632.     move.l    d2,d0
  633.     add.l    d3,d0            ; byteSize
  634.     move.l    #$00010001,d1        ; requirements, MEMF_PUBLIC!MEMF_CLEAR
  635.     jsr    -$00C6(a6)        ; _LVOAllocMem
  636.     tst.l    d0
  637.     beq    .End
  638.  
  639.     add.l    d2,d0
  640.     move.l    d0,a3
  641.     movem    d2/d3,$0010(a3)        ; lib_NegSize/lib_PosSize
  642.  
  643.     move.l    a3,a0            ; target
  644.     sub.l    a2,a2            ; funcDispBase
  645.     move.l    d4,a1            ; funcArray
  646.  
  647.     cmp    #-1,(a1)
  648.     bne    .Make
  649.     addq.l    #2,a1
  650.     move.l    d4,a2
  651.  
  652. .Make
  653.     jsr    -$005A(a6)        ; _LVOMakeFunctions
  654.  
  655.     tst.l    d5
  656.     beq    .Str
  657.     move.l    a3,a2            ; memory
  658.     move.l    d5,a1            ; initTable
  659.     moveq    #0,d0            ; size
  660.     jsr    -$004E(a6)        ; _LVOInitStruct
  661.  
  662. .Str
  663.     move.l    a3,d0            ; libAddr
  664.     tst.l    d6
  665.     beq    .End
  666.     move.l    d6,a1            ; segList
  667.     move.l    d7,a0
  668.     jsr    (a1)
  669.  
  670. .End
  671.     movem.l    (sp)+,d2-d7/a2/a3
  672.     rts
  673.  
  674. ;------------------------------------------------------------------------------;
  675.  
  676. MoveChipHeader:
  677.     movem.l    d2/a2/a3,-(sp)
  678.     jsr    -$0084(a6)        ; _LVOForbid
  679.  
  680. .Loop0
  681.     move.l    $0142(a6),d2        ; MemList
  682.  
  683. .Loop1
  684.     move.l    d2,a2
  685.     move.l    (a2),d2
  686.     beq    .Quit
  687.  
  688.     move.l    a2,a1            ; address
  689.     bsr    MyTypeOfMem
  690.     and    #4,d0            ; MEMF_FAST
  691.     bne    .Loop1
  692.  
  693.     moveq    #$0020,d0        ; byteSize, sizeof(MemHeader)
  694.     moveq    #5,d1            ; requirements, MEMF_PUBLIC!MEMF_FAST
  695.     jsr    -$00C6(a6)        ; _LVOAllocMem
  696.     tst.l    d0
  697.     beq    .Quit
  698.     move.l    d0,a3
  699.  
  700.     lea    $0008(a2),a0        ; source, mh_Attributes
  701.     lea    $0008(a3),a1        ; dest, mh_Attributes
  702.     moveq    #$0018,d0        ; size, sizeof(MemHeader)-ln_Type
  703.     jsr    -$0270(a6)        ; _LVOCopyMem
  704.  
  705.     lea    $0020(a2),a0        ; sizeof(MemHeader)
  706.     cmp.l    $0014(a2),a0        ; mh_Lower
  707.     bne    .Ok
  708.     move.l    a2,$0014(a3)        ; mh_Lower
  709.  
  710. .Ok
  711.     move.l    a2,a1            ; node
  712.     jsr    -$00FC(a6)        ; _LVORemove
  713.     lea    $0142(a6),a0        ; list, MemList
  714.     move.l    a3,a1            ; node
  715.     jsr    -$010E(a6)        ; _LVOEnqueue
  716.  
  717.     cmp    #36,$0014(a6)        ; lib_Version
  718.     bcs    .Loop0
  719.  
  720.     move.l    a2,a1            ; memoryBlock
  721.     moveq    #$0020,d0        ; byteSize, sizeof(MemHeader)
  722.     bsr    FreeMemSafely
  723.  
  724.     bra    .Loop0
  725.  
  726. .Quit
  727.     jsr    -$008A(a6)        ; _LVOPermit
  728.     movem.l    (sp)+,d2/a2/a3
  729.     rts
  730.  
  731. ;------------------------------------------------------------------------------;
  732.  
  733. MoveExec:
  734.     movem.l    d0-a6,-(sp)
  735.     move.l    a6,a2
  736.  
  737.     move.l    a6,a1            ; address
  738.     bsr    MyTypeOfMem
  739.     and    #4,d0            ; MEMF_FAST
  740.     bne    .End
  741.  
  742.     moveq    #0,d2
  743.     moveq    #0,d3
  744.     movem    $0010(a6),d2/d3        ; lib_NegSize/lib_PosSize
  745.     addq.l    #3,d2
  746.     and    #-4,d2
  747.  
  748.     move.l    d2,d0
  749.     add.l    d3,d0            ; byteSize
  750.     move.l    #$00010005,d1        ; MEMF_PUBLIC!MEMF_FAST!MEMF_CLEAR
  751.     jsr    -$00C6(a6)        ; _LVOAllocMem
  752.     tst.l    d0
  753.     beq    .End
  754.     move.l    d0,a3
  755.  
  756.     move.l    a6,a1            ; node
  757.     jsr    -$00FC(a6)        ; _LVORemove
  758.  
  759.     move.l    a6,a0            ; source
  760.     move.l    a3,a1            ; dest
  761.     move.l    d2,d0            ; size
  762.     sub.l    d0,a0
  763.     add.l    d3,d0
  764.     jsr    -$0270(a6)        ; _LVOCopyMem
  765.     bsr    OSCacheClearU
  766.  
  767.     add.l    d2,a3
  768.     move    d2,$0010(a3)        ; lib_NegSize
  769.  
  770.     move.l    a3,a6
  771.     bsr    InitChkBase
  772.     bsr    InitChkSum
  773.  
  774.     lea    .ListTable(pc),a4
  775.  
  776. .ListLoop
  777.     move    (a4)+,d0
  778.     beq    .ListOk
  779.     bsr    InitList
  780.     bra    .ListLoop
  781.  
  782. .ListTable
  783.     dc.w    $0142            ; MemList
  784.     dc.w    $0150            ; ResourceList
  785.     dc.w    $015E            ; DeviceList
  786.     dc.w    $016C            ; IntrList
  787.     dc.w    $017A            ; LibList
  788.     dc.w    $0188            ; PortList
  789.     dc.w    $0196            ; TaskReady
  790.     dc.w    $01A4            ; TaskWait
  791.     dc.w    $01B2            ; SoftInts
  792.     dc.w    $01C2
  793.     dc.w    $01D2
  794.     dc.w    $01E2
  795.     dc.w    $01F2
  796.     dc.w    $0214            ; SemaphoreList
  797.     dc.w    0
  798.  
  799. .ListOk
  800.     cmp    #39,$0014(a6)        ; lib_Version
  801.     bcs    .List39
  802.     move    #$0268,d0        ; ex_MemHandlers
  803.     bsr    InitList
  804.  
  805. .List39
  806. ;Replace _ExecBase-pointers on stack
  807.     move.l    sp,a0
  808.     moveq    #127,d1
  809.  
  810. .Repl
  811.     addq.l    #2,a0
  812.     cmp.l    (a0),a2
  813.     dbeq    d1,.Repl
  814.     bne    .ReplOk
  815.     move.l    a6,(a0)
  816.     bra    .Repl
  817.  
  818. .ReplOk
  819.  
  820. ;Replace _ExecBase-pointer in _ExpansionBase V33/34 (offset $0024)
  821. ;_ExpansionBase has not been added to library list, get it from the stack
  822. ;offset should be
  823. ; 4 (expansion jumps to addmemlist)
  824. ; 8 (addmemlist routine saves a2/a3)
  825. ; 4 (addmemlist saves attributes
  826. ; 4 (addmemlist routine saves cachebits)
  827. ; 4 (addmemlist routine jumps to this routine)
  828. ;60 (this routine saves d0-a6)
  829. ;--
  830. ;84
  831.  
  832. ;_ExpansionBase V36+ doesn't cache _SysBase
  833.  
  834.     cmp    #36,$0014(a6)        ; lib_Version
  835.     bcc    .ExpOk
  836.  
  837.     move.l    84(sp),d0
  838.     btst    #0,d0
  839.     bne    .ExpErr
  840.     move.l    d0,a1            ; address
  841.     move.l    a1,-(sp)
  842.     jsr    -$0216(a6)        ; _LVOTypeOfMem
  843.     move.l    (sp)+,a1
  844.     tst.l    d0
  845.     beq    .ExpErr
  846.  
  847.     cmp.l    $0024(a1),a2        ; eb_ExecBase
  848.     bne    .ExpErr
  849.     move.l    a6,$0024(a1)        ; eb_ExecBase
  850.     bra    .ExpOk
  851.  
  852. .ExpErr
  853.     lea    FlagEBExec(pc),a0
  854.     st    (a0)
  855.  
  856. .ExpOk
  857.     move.l    a6,(4).w
  858.     move.l    a6,a1            ; library
  859.     or.b    #2,$000E(a1)        ; lib_Flags, LIBF_CHANGED
  860.     jsr    -$018C(a6)        ; _LVOAddLibrary
  861.  
  862.     move.l    a2,a1            ; memoryBlock
  863.     moveq    #0,d0            ; byteSize
  864.     move    $0010(a2),d0        ; lib_NegSize
  865.     sub.l    d0,a1
  866.     add    $0012(a2),d0        ; lib_PosSize
  867.  
  868.     cmp    #36,$0014(a6)        ; lib_Version
  869.     bcc    .Free
  870.     and    #-8,d0
  871.     move.b    FlagEBExec(pc),d1
  872.     bne    .End
  873.  
  874. .Free
  875.     bsr    FreeMemSafely
  876.  
  877. .End
  878.     movem.l    (sp)+,d0-a6
  879.     rts
  880.  
  881. ;------------------------------------------------------------------------------;
  882.  
  883. MoveExpansion:
  884. ; out    d0=library
  885.  
  886. ;a2=old base
  887. ;a3=new base
  888.  
  889.     movem.l    d2/d3/a2-a4,-(sp)
  890.     jsr    -$0084(a6)        ; _LVOForbid
  891.  
  892.     lea    $017A(a6),a0        ; list, LibList
  893.     lea    expansion_library(pc),a1; name
  894.     jsr    -$0114(a6)        ; _LVOFindName
  895.     tst.l    d0
  896.     beq    .Err
  897.     move.l    d0,a2
  898.  
  899.     move.l    a2,a1            ; address
  900.     bsr    MyTypeOfMem
  901.     and    #4,d0            ; MEMF_FAST
  902.     bne    .Err
  903.  
  904.     moveq    #0,d2
  905.     moveq    #0,d3
  906.     movem    $0010(a2),d2/d3        ; lib_NegSize/lib_PosSize
  907.     addq.l    #3,d2
  908.     and    #-4,d2
  909.  
  910.     move.l    d2,d0
  911.     add.l    d3,d0            ; byteSize
  912.     move.l    #$00010005,d1        ; MEMF_PUBLIC!MEMF_FAST!MEMF_CLEAR
  913.     jsr    -$00C6(a6)        ; _LVOAllocMem
  914.     tst.l    d0
  915.     beq    .Err
  916.     move.l    d0,a3
  917.  
  918.     move.l    a2,a1            ; node
  919.     jsr    -$00FC(a6)        ; _LVORemove
  920.  
  921.     move.l    a2,a0            ; source
  922.     move.l    a3,a1            ; dest
  923.     move.l    d2,d0            ; size
  924.     sub.l    d0,a0
  925.     add.l    d3,d0
  926.     jsr    -$0270(a6)        ; _LVOCopyMem
  927.     bsr    OSCacheClearU
  928.  
  929.     add.l    d2,a3
  930.     move    d2,$0010(a3)        ; lib_NegSize
  931.  
  932.     bsr    .Fix
  933.  
  934.     move.l    a3,a1            ; library
  935.     or.b    #2,$000E(a1)        ; lib_Flags, LIBF_CHANGED
  936.     jsr    -$018C(a6)        ; _LVOAddLibrary
  937.  
  938.     move.l    a2,a1            ; memoryBlock
  939.     moveq    #0,d0            ; byteSize
  940.     move    $0010(a2),d0        ; lib_NegSize
  941.     sub.l    d0,a1
  942.     add    $0012(a2),d0        ; lib_PosSize
  943.     bsr    FreeMemSafely
  944.  
  945.     move.l    a3,d0
  946.  
  947. .Quit
  948.     jsr    -$008A(a6)        ; _LVOPermit
  949.     movem.l    (sp)+,d2/d3/a2-a4
  950.     rts
  951.  
  952. .Err
  953.     moveq    #0,d0
  954.     bra    .Quit
  955.  
  956. .Fix
  957.     moveq    #$003C,d0        ; eb_ConfigDevList
  958.     bsr    InitList
  959.     moveq    #$004A,d0        ; eb_MountList
  960.     bsr    InitList
  961.     move    #$0168,d0        ; eb_BindSemaphore+ss_WaitQueue
  962.     bsr    InitList
  963.  
  964.     cmp    #36,$0014(a6)        ; lib_Version
  965.     bcc    .Rts
  966.     move.l    a6,$0024(a3)        ; eb_ExecBase
  967.  
  968. .Rts
  969.     rts
  970.  
  971. ;------------------------------------------------------------------------------;
  972.  
  973. ;Don't ask me what I'm doing here...
  974.  
  975. MoveIntrMem:
  976.     movem.l    d2/d4/a2-a4,-(sp)
  977.     move.l    3*12+$0054(a6),a4
  978.     moveq    #$50,d4
  979.     cmp    #36,$0014(a6)        ; lib_Version
  980.     bcc    .Size
  981.     moveq    #$6E,d4
  982.  
  983. .Size
  984.     move.l    a4,a1            ; address
  985.     bsr    MyTypeOfMem
  986.     and    #4,d0            ; MEMF_FAST
  987.     bne    .End
  988.  
  989.     move.l    d4,d0            ; byteSize
  990.     move.l    #$00010005,d1        ; requirements, MEMF_PUBLIC!MEMF_FAST!MEMF_CLEAR
  991.     jsr    -$00C6(a6)        ; _LVOAllocMem
  992.     tst.l    d0
  993.     beq    .End
  994.  
  995.     move.l    d0,a2
  996.     lea    .Table(pc),a3
  997.     moveq    #4,d2
  998.     jsr    -$0078(a6)        ; _LVODisable
  999.  
  1000. .Loop
  1001.     move.l    a2,a1
  1002.     lea    $000E(a2),a2
  1003.     move    (a3)+,d0
  1004.     mulu    #12,d0
  1005.     move.l    $54(a6,d0.l),a0
  1006.     move.l    a1,$54(a6,d0.l)
  1007.     move    $000E(a0),(a2)+
  1008.  
  1009.     cmp    #36,$0014(a6)        ; lib_Version
  1010.     bcc    .Copy
  1011.     move    $0010(a0),(a2)+
  1012.     move.l    $0012(a0),(a2)+
  1013.  
  1014. .Copy
  1015.     bsr    CopyList
  1016.     dbf    d2,.Loop
  1017.     jsr    -$007E(a6)        ; _LVOEnable
  1018.  
  1019.     move.l    a4,a1            ; memoryBlock
  1020.     move.l    d4,d0            ; byteSize
  1021.     bsr    FreeMemSafely
  1022.  
  1023. .End
  1024.     movem.l    (sp)+,d2/d4/a2-a4
  1025.     rts
  1026.  
  1027. .Table
  1028.     dc.w    3,5,4,13,15
  1029.  
  1030. ;------------------------------------------------------------------------------;
  1031.  
  1032. MoveSSP:
  1033.     movem.l    d2/a2,-(sp)
  1034.     jsr    -$0084(a6)        ; _LVOForbid
  1035.     move.l    $003A(a6),a2        ; SysStkLower
  1036.     move.l    $0036(a6),d2        ; SysStkUpper
  1037.     sub.l    a2,d2
  1038.  
  1039.     move.l    a2,a1            ; address
  1040.     bsr    MyTypeOfMem
  1041.     and    #4,d0            ; MEMF_FAST
  1042.     bne    .Err
  1043.  
  1044.     move.l    d2,d0            ; byteSize
  1045.     moveq    #5,d1            ; requirements, MEMF_PUBLIC!MEMF_CLEAR
  1046.     jsr    -$00C6(a6)        ; _LVOAllocMem
  1047.     tst.l    d0
  1048.     beq    .Err
  1049.  
  1050.     bsr    SetSSP
  1051.     jsr    -$008A(a6)        ; _LVOPermit
  1052.  
  1053.     move.l    a2,a1            ; memoryBlock
  1054.     move.l    d2,d0            ; byteSize
  1055.     bsr    FreeMemSafely
  1056.  
  1057. .End
  1058.     movem.l    (sp)+,d2/a2
  1059.     rts
  1060.  
  1061. .Err
  1062.     jsr    -$008A(a6)        ; _LVOPermit
  1063.     bra    .End
  1064.  
  1065. ;------------------------------------------------------------------------------;
  1066.  
  1067. MoveVBR:
  1068.     move.l    a2,-(sp)
  1069.     btst    #0,$0129(a6)        ; AttnFlags+1, AFB_68010
  1070.     beq    .End
  1071.  
  1072.     moveq    #1,d0            ; byteSize
  1073.     ror    #6,d0            ; 1024
  1074.     moveq    #5,d1            ; requirements, MEMF_PUBLIC!MEMF_FAST
  1075.     jsr    -$00C6(a6)        ; _LVOAllocMem
  1076.     tst.l    d0
  1077.     beq    .End
  1078.     move.l    d0,a2
  1079.  
  1080.     jsr    -$0084(a6)        ; _LVOForbid
  1081.     bsr    GetVBR
  1082.     move.l    d0,a1            ; address
  1083.     bsr    MyTypeOfMem
  1084.     and    #4,d0            ; MEMF_FAST
  1085.     bne    .Err
  1086.  
  1087.     move.l    d0,a0
  1088.     move.l    a2,a1
  1089.     move    #255,d0
  1090.  
  1091. .Loop
  1092.     move.l    (a0)+,(a1)+
  1093.     dbf    d0,.Loop
  1094.  
  1095.     move.l    a2,d0
  1096.     bsr    SetVBR
  1097.     jsr    -$008A(a6)        ; _LVOPermit
  1098.  
  1099. .End
  1100.     move.l    (sp)+,a2
  1101.     rts
  1102.  
  1103. .Err
  1104.     jsr    -$008A(a6)        ; _LVOPermit
  1105.     move.l    a2,a1            ; memoryBlock
  1106.     moveq    #1,d0            ; byteSize
  1107.     ror    #6,d0            ; 1024
  1108.     jsr    -$00D2(a6)        ; _LVOFreeMem
  1109.     bra    .End
  1110.  
  1111. ;------------------------------------------------------------------------------;
  1112.  
  1113. ;modify all
  1114. ;    move.l    #0,a6
  1115. ;to move _ExecBase instead of zero.
  1116.  
  1117. PatchA6:
  1118. ;    a0=buff
  1119. ;    d0=size
  1120.  
  1121.     move.l    a0,a1
  1122.     add.l    d0,a1
  1123.  
  1124. .Loop
  1125.     cmp.l    a1,a0
  1126.     bcc    .Rts
  1127.     cmp    #$2C7C,(a0)+        ; move.l #x,a6
  1128.     bne    .Loop
  1129.     tst.l    (a0)
  1130.     bne    .Loop
  1131.     move.l    a6,(a0)+
  1132.     bra    .Loop
  1133.  
  1134. .Rts
  1135.     rts
  1136.  
  1137. ;------------------------------------------------------------------------------;
  1138.  
  1139.     cnop    0,4
  1140.  
  1141. PatchExec:
  1142.     movem.l    a2/a3,-(sp)
  1143. ;    cmp    #36,$0014(a6)        ; lib_Version
  1144. ;    bcs    .End
  1145.  
  1146.     move.l    #PatchExecEnd-PatchExecStart,d0; byteSize
  1147.     moveq    #5,d1            ; requirements, MEMF_PUBLIC!MEMF_FAST
  1148.     jsr    -$00C6(a6)        ; _LVOAllocMem
  1149.     tst.l    d0
  1150.     beq    .End
  1151.     move.l    d0,a2
  1152.  
  1153.     lea    PatchExecStart(pc),a0    ; source
  1154.     move.l    d0,a1            ; dest
  1155.     move.l    #PatchExecEnd-PatchExecStart,d0; size
  1156.     jsr    -$0276(a6)        ; _LVOCopyMemQuick
  1157.  
  1158.     move.l    a2,a0            ; buff
  1159.     move.l    #PatchExecEnd-PatchExecStart,d0; size
  1160.     bsr    PatchA6
  1161.  
  1162.     lea    Exception4-PatchExecStart(a2),a0
  1163.     move.l    a0,2+Exception2-PatchExecStart(a2)
  1164.     btst    #0,$0129(a6)        ; AttnFlags+1, AFB_68010
  1165.     bne    .Switch
  1166.     move.l    #$4E714E71,8+Exception2-PatchExecStart(a2); nop/nop
  1167.     move    #$5C8F,4+Exception5-PatchExecStart(a2); addq.l #6,sp
  1168.  
  1169. .Switch
  1170.     moveq    #$70,d0            ; AFF_68881!AFF_68882!AFF_FPU40
  1171.     and    $0128(a6),d0        ; AttnFlags
  1172.     bne    .SwitchFPU
  1173.  
  1174.     move.l    a6,a1            ; library
  1175.     lea    Switch-PatchExecStart(a2),a0
  1176.     move.l    a0,d0            ; newFunction
  1177.     move    #-$0036,a0        ; funcOffset, _LVOSwitch
  1178.     jsr    -$01A4(a6)        ; _LVOSetFunction
  1179.  
  1180.     bra    .SwitchOk
  1181.  
  1182. .SwitchFPU
  1183.     move.l    a6,a1            ; library
  1184.     lea    SwitchFPU-PatchExecStart(a2),a0
  1185.     move.l    a0,d0            ; newFunction
  1186.     move    #-$0036,a0        ; funcOffset, _LVOSwitch
  1187.     jsr    -$01A4(a6)        ; _LVOSetFunction
  1188.  
  1189. .SwitchOk
  1190.     lea    .Table(pc),a3
  1191.  
  1192. .Loop
  1193.     tst.l    (a3)
  1194.     beq    .End
  1195.     move    (a3)+,d0
  1196.     ext.l    d0
  1197.     add.l    a2,d0            ; newFunction
  1198.     move    (a3)+,a0        ; funcOffset
  1199.     move.l    a6,a1            ; library
  1200.     jsr    -$01A4(a6)        ; _LVOSetFunction
  1201.     bra    .Loop
  1202.  
  1203. .End
  1204.     movem.l    (sp)+,a2/a3
  1205.     rts
  1206.  
  1207.     cnop    0,4
  1208.  
  1209. .Table
  1210.     dc.w    Cause-PatchExecStart
  1211.     dc.w    -$00B4            ; _LVOCause
  1212.     dc.w    ExitIntr-PatchExecStart
  1213.     dc.w    -$0024            ; _LVOExitIntr
  1214.     dc.w    PutMsg-PatchExecStart
  1215.     dc.w    -$016E            ; _LVOPutMsg
  1216.     dc.w    ReplyMsg-PatchExecStart
  1217.     dc.w    -$017A            ; _LVOReplyMsg
  1218.     dc.w    Schedule-PatchExecStart
  1219.     dc.w    -$002A            ; _LVOSchedule
  1220.     dc.w    Dispatch-PatchExecStart
  1221.     dc.w    -$003C            ; _LVODispatch
  1222.     dc.w    Exception-PatchExecStart
  1223.     dc.w    -$0042            ; _LVOException
  1224.     dc.w    Wait-PatchExecStart
  1225.     dc.w    -$013E            ; _LVOWait
  1226.     dc.l    0
  1227.  
  1228. ;------------------------------------------------------------------------------;
  1229.  
  1230. ;put the code "addq.b #1,$0127(a6)/rts" directly in the jump table
  1231.  
  1232. PatchForbid:
  1233.     lea    Forbid(pc),a0
  1234.     move.l    a0,d0            ; newFunction
  1235.     move.l    a6,a1            ; library
  1236.     move    #-$0084,a0        ; funcOffset, _LVOForbid
  1237. ;    bra    PatchTable
  1238.  
  1239. PatchTable:
  1240.     lea    0(a1,a0),a0
  1241.     move.l    a1,-(sp)
  1242.     jsr    -$0084(a6)        ; _LVOForbid
  1243.     or.b    #2,$000E(a1)        ; lib_Flags, LIBF_CHANGED
  1244.     move.l    d0,a1
  1245.     move.l    (a1)+,(a0)+
  1246.     move    (a1),(a0)
  1247.     bsr    OSCacheClearU
  1248.     jsr    -$008A(a6)        ; _LVOPermit
  1249.     move.l    (sp)+,a1        ; library
  1250.     jmp    -$01AA(a6)        ; _LVOSumLibrary
  1251.  
  1252. Forbid:
  1253.     addq.b    #1,$0127(a6)        ; TDNestCnt
  1254.     rts
  1255.  
  1256. ;------------------------------------------------------------------------------;
  1257.  
  1258. ;In the patches for the interrupt routines
  1259. ;I try to avoid btst-instructions,
  1260. ;put _ExecBase directly in the move instruction instead reading it from $4
  1261. ;and some other changes.
  1262.  
  1263. ;The interrupts and exec.library/ExitIntr() don't work the same
  1264. ;between KS 1.3 and 2.0, so this only patches 2.0 and up.
  1265.  
  1266. PatchInterrupts:
  1267.     move.l    a2,-(sp)
  1268. ;    cmp    #36,$0014(a6)        ; lib_Version
  1269. ;    bcs    .End
  1270.  
  1271.     move.l    #.EndLabel-.StartLabel,d0; byteSize
  1272.     moveq    #5,d1            ; requirements, MEMF_PUBLIC!MEMF_FAST
  1273.     jsr    -$00C6(a6)        ; _LVOAllocMem
  1274.     tst.l    d0
  1275.     beq    .End
  1276.     move.l    d0,a2
  1277.  
  1278.     lea    .StartLabel(pc),a0    ; source
  1279.     move.l    d0,a1            ; dest
  1280.     move.l    #.EndLabel-.StartLabel,d0; size
  1281.     jsr    -$0276(a6)        ; _LVOCopyMemQuick
  1282.  
  1283.     move.l    a2,a0            ; buffer
  1284.     move.l    #.EndLabel-.StartLabel,d0; size
  1285.     bsr    PatchA6
  1286.  
  1287.     jsr    -$027C(a6)        ; _LVOCacheClearU
  1288.     jsr    -$0084(a6)        ; _LVOForbid
  1289.     bsr    GetVBR
  1290.     move.l    d0,a1
  1291.  
  1292.     lea    .Int1-.StartLabel(a2),a0
  1293.     move.l    a0,$64(a1)
  1294.     lea    .Int2-.StartLabel(a2),a0
  1295.     move.l    a0,$68(a1)
  1296.     lea    .Int3-.StartLabel(a2),a0
  1297.     move.l    a0,$6C(a1)
  1298.     lea    .Int4-.StartLabel(a2),a0
  1299.     move.l    a0,$70(a1)
  1300.     lea    .Int5-.StartLabel(a2),a0
  1301.     move.l    a0,$74(a1)
  1302.     lea    .Int6-.StartLabel(a2),a0
  1303.     move.l    a0,$78(a1)
  1304.     lea    .Int7-.StartLabel(a2),a0
  1305.     move.l    a0,$7C(a1)
  1306.  
  1307.     jsr    -$027C(a6)        ; _LVOCacheClearU
  1308.     jsr    -$008A(a6)        ; _LVOPermit
  1309. ;    moveq    #1,d0
  1310.  
  1311. .End
  1312.     move.l    (sp)+,a2
  1313.     rts
  1314.  
  1315.     cnop    0,4
  1316.  
  1317. .StartLabel
  1318.  
  1319.     cnop    0,4
  1320.  
  1321. ; 0 => $0054
  1322. ; 1 => $0060
  1323. ; 2 => $006C
  1324. ; 3 => $0078
  1325. ; 4 => $0084
  1326. ; 5 => $0090
  1327. ; 6 => $009C
  1328. ; 7 => $00A8
  1329. ; 8 => $00B4
  1330. ; 9 => $00C0
  1331. ;10 => $00CC
  1332. ;11 => $00D8
  1333. ;12 => $00E4
  1334. ;13 => $00F0
  1335. ;14 => $00FC
  1336.  
  1337. .Int1:
  1338.     movem.l    d0/d1/a0/a1/a5/a6,-(sp)
  1339.     lea    $DFF000,a0
  1340.     move.l    $001C(a0),d0
  1341.     move.l    d0,d1
  1342.     swap    d0
  1343.     and.l    d0,d1
  1344.     add    d0,d0
  1345.     bpl    .Done1
  1346.  
  1347.     moveq    #1,d0
  1348.     and.l    d1,d0
  1349.     beq    .Next1a
  1350.     move.l    #0,a6
  1351.     movem.l    $0054(a6),a1/a5
  1352.     move.l    a6,-(sp)
  1353.     pea    -$0024(a6)        ; _LVOExitIntr
  1354.     jmp    (a5)
  1355.  
  1356.     cnop    0,4
  1357.  
  1358. .Next1a
  1359.     moveq    #2,d0
  1360.     and.l    d1,d0
  1361.     beq    .Next1b
  1362.     move.l    #0,a6
  1363.     movem.l    $0060(a6),a1/a5
  1364.     move.l    a6,-(sp)
  1365.     pea    -$0024(a6)        ; _LVOExitIntr
  1366.     jmp    (a5)
  1367.  
  1368.     cnop    0,4
  1369.  
  1370. .Next1b
  1371.     moveq    #4,d0
  1372.     and.l    d1,d0
  1373.     beq    .Done1
  1374.     move.l    #0,a6
  1375.     movem.l    $006C(a6),a1/a5
  1376.     move.l    a6,-(sp)
  1377.     pea    -$0024(a6)        ; _LVOExitIntr
  1378.     jmp    (a5)
  1379.  
  1380.     cnop    0,4
  1381.  
  1382. .Done1
  1383.     movem.l    (sp)+,d0/d1/a0
  1384.     lea    12(sp),sp
  1385.     rte
  1386.  
  1387.     cnop    0,4
  1388.  
  1389. .Int2:
  1390.     movem.l    d0/d1/a0/a1/a5/a6,-(sp)
  1391.     lea    $DFF000,a0
  1392.     move.l    $001C(a0),d0
  1393.     move.l    d0,d1
  1394.     swap    d0
  1395.     and.l    d0,d1
  1396.     add    d0,d0
  1397.     bpl    .Done1
  1398.  
  1399.     moveq    #8,d0
  1400.     and.l    d1,d0
  1401.     beq    .Done1
  1402.     move.l    #0,a6
  1403.     movem.l    $0078(a6),a1/a5
  1404.     move.l    a6,-(sp)
  1405.     pea    -$0024(a6)        ; _LVOExitIntr
  1406.     jmp    (a5)
  1407.  
  1408.     cnop    0,4
  1409.  
  1410. .Int3:
  1411.     movem.l    d0/d1/a0/a1/a5/a6,-(sp)
  1412.     lea    $DFF000,a0
  1413.     move.l    $001C(a0),d0
  1414.     move.l    d0,d1
  1415.     swap    d0
  1416.     and.l    d0,d1
  1417.     add    d0,d0
  1418.     bpl    .Done3
  1419.  
  1420.     moveq    #64,d0
  1421.     and.l    d1,d0
  1422.     beq    .Next3a
  1423.     move.l    #0,a6
  1424.     movem.l    $009C(a6),a1/a5
  1425.     move.l    a6,-(sp)
  1426.     pea    -$0024(a6)        ; _LVOExitIntr
  1427.     jmp    (a5)
  1428.  
  1429.     cnop    0,4
  1430.  
  1431. .Next3a
  1432.     moveq    #32,d0
  1433.     and.l    d1,d0
  1434.     beq    .Next3b
  1435.     move.l    #0,a6
  1436.     movem.l    $0090(a6),a1/a5
  1437.     move.l    a6,-(sp)
  1438.     pea    -$0024(a6)        ; _LVOExitIntr
  1439.     jmp    (a5)
  1440.  
  1441.     cnop    0,4
  1442.  
  1443. .Next3b
  1444.     moveq    #16,d0
  1445.     and.l    d1,d0
  1446.     beq    .Done3
  1447.     move.l    #0,a6
  1448.     movem.l    $0084(a6),a1/a5
  1449.     move.l    a6,-(sp)
  1450.     pea    -$0024(a6)        ; _LVOExitIntr
  1451.     jmp    (a5)
  1452.  
  1453.     cnop    0,4
  1454.  
  1455. .Done3
  1456.     movem.l    (sp)+,d0/d1/a0
  1457.     lea    12(sp),sp
  1458.     rte
  1459.  
  1460.     cnop    0,4
  1461.  
  1462. .Int4:
  1463.     movem.l    d0/d1/a0/a1/a5/a6,-(sp)
  1464.     lea    $DFF000,a0
  1465.     move.l    $001C(a0),d0
  1466.     move.l    d0,d1
  1467.     swap    d0
  1468.     and.l    d0,d1
  1469.     add    d0,d0
  1470.     bpl    .Done3
  1471.     move.l    #0,a6
  1472.  
  1473. .Loop4
  1474.     btst    #8,d1
  1475.     beq    .Next4a
  1476.     movem.l    $00B4(a6),a1/a5
  1477.     move.l    a6,-(sp)
  1478.     pea    .Quit4(pc)
  1479.     jmp    (a5)
  1480.  
  1481.     cnop    0,4
  1482.  
  1483. .Next4a
  1484.     btst    #10,d1
  1485.     beq    .Next4b
  1486.     movem.l    $00CC(a6),a1/a5
  1487.     move.l    a6,-(sp)
  1488.     pea    .Quit4(pc)
  1489.     jmp    (a5)
  1490.  
  1491.     cnop    0,4
  1492.  
  1493. .Next4b
  1494.     tst.b    d1
  1495.     bpl    .Next4c
  1496.     movem.l    $00A8(a6),a1/a5
  1497.     move.l    a6,-(sp)
  1498.     pea    .Quit4(pc)
  1499.     jmp    (a5)
  1500.  
  1501.     cnop    0,4
  1502.  
  1503. .Next4c
  1504.     btst    #9,d1
  1505.     beq    .Next4d
  1506.     movem.l    $00C0(a6),a1/a5
  1507.     move.l    a6,-(sp)
  1508.     pea    .Quit4(pc)
  1509.     jmp    (a5)
  1510.  
  1511.     cnop    0,4
  1512.  
  1513. .Next4d
  1514.     movem.l    (sp)+,d0/d1/a0/a1/a5/a6
  1515.     rte
  1516.  
  1517.     cnop    0,4
  1518.  
  1519. .Quit4
  1520.     move.l    (sp)+,a6
  1521.     lea    $DFF000,a0
  1522.     move    #$0780,d1
  1523.     and    $001C(a0),d1
  1524.     and    $001E(a0),d1
  1525.     bne    .Loop4
  1526.     move.l    a6,-(sp)
  1527.     jmp    -$0024(a6)        ; _LVOExitIntr
  1528.  
  1529.     cnop    0,4
  1530.  
  1531. .Int5:
  1532.     movem.l    d0/d1/a0/a1/a5/a6,-(sp)
  1533.     lea    $DFF000,a0
  1534.     move.l    $001C(a0),d0
  1535.     move.l    d0,d1
  1536.     swap    d0
  1537.     and.l    d0,d1
  1538.     add    d0,d0
  1539.     bpl    .Done5
  1540.  
  1541.     btst    #12,d1
  1542.     beq    .Next5a
  1543.     move.l    #0,a6
  1544.     movem.l    $00E4(a6),a1/a5
  1545.     move.l    a6,-(sp)
  1546.     pea    -$0024(a6)        ; _LVOExitIntr
  1547.     jmp    (a5)
  1548.  
  1549.     cnop    0,4
  1550.  
  1551. .Next5a
  1552.     btst    #11,d1
  1553.     beq    .Done5
  1554.     move.l    #0,a6
  1555.     movem.l    $00D8(a6),a1/a5
  1556.     move.l    a6,-(sp)
  1557.     pea    -$0024(a6)        ; _LVOExitIntr
  1558.     jmp    (a5)
  1559.  
  1560.     cnop    0,4
  1561.  
  1562. .Done5
  1563.     movem.l    (sp)+,d0/d1/a0
  1564.     lea    12(sp),sp
  1565.     rte
  1566.  
  1567.     cnop    0,4
  1568.  
  1569. .Int6:
  1570.     movem.l    d0/d1/a0/a1/a5/a6,-(sp)
  1571.     lea    $DFF000,a0
  1572.     move.l    $001C(a0),d0
  1573.     move.l    d0,d1
  1574.     swap    d0
  1575.     and.l    d0,d1
  1576.     add    d0,d0
  1577.     bpl    .Done5
  1578.  
  1579.     move.l    d1,d0
  1580.     add    d0,d0
  1581.     bpl    .Next6a
  1582.     move.l    #0,a6
  1583.     movem.l    $00FC(a6),a1/a5
  1584.     move.l    a6,-(sp)
  1585.     pea    -$0024(a6)        ; _LVOExitIntr
  1586.     jmp    (a5)
  1587.  
  1588.     cnop    0,4
  1589.  
  1590. .Next6a
  1591.     btst    #13,d1
  1592.     beq    .Done5
  1593.     move.l    #0,a6
  1594.     movem.l    $00F0(a6),a1/a5
  1595.     move.l    a6,-(sp)
  1596.     pea    -$0024(a6)        ; _LVOExitIntr
  1597.     jmp    (a5)
  1598.  
  1599.     cnop    0,4
  1600.  
  1601. .Int7:
  1602.     rte
  1603.  
  1604.     cnop    0,4
  1605.  
  1606. .EndLabel
  1607.  
  1608. ;------------------------------------------------------------------------------;
  1609.  
  1610. ;Patch exec.library/Supervisor()
  1611.  
  1612. ;On KS 1.3 and MC68000, change
  1613. ;    pea    LB_00FC08F4
  1614. ;to
  1615. ;    pea    LB_00FC08F4(pc)
  1616.  
  1617. ;On MC68010+, change
  1618. ;    subq.l    #8,sp
  1619. ;    move    sr,(sp)
  1620. ;    move.l    #LB_00F80B3C,2(sp)
  1621. ;    move    #$0020,6(sp)
  1622. ;to
  1623. ;    move    #$0020,-(sp)
  1624. ;    pea    LB_00F80B3C(pc)
  1625. ;    move    sr,-(sp)
  1626.  
  1627. PatchSupervisorSafely:
  1628.     jsr    -$0084(a6)        ; _LVOForbid
  1629.     move.l    2-$001E(a6),a0        ; _LVOSupervisor
  1630.     cmp.l    #$007C2000,(a0)+    ; or #$2000,sr
  1631.     bne    .Quit
  1632.     cmp    #$4879,(a0)        ; pea x
  1633.     beq    .Old            ; KS 1.3/68000
  1634.     cmp    #$487A,(a0)        ; pea x(pc)
  1635.     beq    .Quit            ; KS 2.0/68000
  1636.     cmp.l    #$518F40D7,(a0)+    ; subq.l #8,sp; move sr,(sp)
  1637.     bne    .Quit
  1638.     cmp    #$2F7C,(a0)+        ; move.l #x,2(sp)
  1639.     bne    .Quit
  1640.     addq.l    #4,a0            ; x
  1641.     cmp    #2,(a0)+        ; 2
  1642.     bne    .Quit
  1643.     cmp.l    #$3F7C0020,(a0)+    ; move.w #$0020,6(sp)
  1644.     bne    .Quit
  1645.     cmp.l    #$00064ED5,(a0)        ; 6; jmp (a5)
  1646.     bne    .Quit
  1647.     bra    .Ok
  1648.  
  1649. .Old
  1650.     addq.l    #6,a0            ; pea x
  1651.     cmp.l    #$40E74ED5,(a0)        ; move sr,-(sp); jmp (a5)
  1652.     bne    .Quit
  1653.  
  1654. .Ok
  1655.     bsr    PatchSupervisor
  1656.  
  1657. .Quit
  1658.     jmp    -$008A(a6)        ; _LVOPermit
  1659.  
  1660. ;------------------------------------------------------------------------------;
  1661.  
  1662. PatchSupervisor:
  1663.     move.l    a2,-(sp)
  1664.  
  1665.     move.l    #SupervisorEnd-Supervisor,d0; byteSize
  1666.     moveq    #5,d1            ; requirements, MEMF_PUBLIC!MEMF_FAST
  1667.     jsr    -$00C6(a6)        ; _LVOAllocMem
  1668.     tst.l    d0
  1669.     beq    .End
  1670.     move.l    d0,a2
  1671.  
  1672.     lea    Supervisor(pc),a0    ; source
  1673.     move.l    d0,a1            ; dest
  1674.     move.l    #SupervisorEnd-Supervisor,d0; size
  1675.     jsr    -$0276(a6)        ; _LVOCopyMemQuick
  1676.  
  1677.     lea    SupervisorRts-Supervisor(a2),a0
  1678.     move.l    a0,12+Exception8-Supervisor(a2)
  1679.  
  1680.     jsr    -$0084(a6)        ; _LVOForbid
  1681.  
  1682.     bsr    GetVBR
  1683.     move.l    d0,a1
  1684.     lea    Exception8-Supervisor(a2),a0
  1685.     move.l    a0,$20(a1)
  1686.  
  1687.     move.l    a2,a0
  1688.     btst    #0,$0129(a6)        ; AttnFlags+1, AFB_68010
  1689.     bne    .Ok
  1690.     move.l    (a0)+,(a0)
  1691.  
  1692. .Ok
  1693.     move.l    a0,2+Exception8-Supervisor(a2)
  1694.  
  1695.     move.l    a6,a1            ; library
  1696.     move.l    a0,d0            ; newFunction
  1697.     move    #-$001E,a0        ; funcOffset, _LVOSupervisor
  1698.     jsr    -$01A4(a6)        ; _LVOSetFunction
  1699.  
  1700.     jsr    -$008A(a6)        ; _LVOPermit
  1701.     moveq    #1,d0
  1702.  
  1703. .End
  1704.     move.l    (sp)+,a2
  1705.     rts
  1706.  
  1707.     cnop    0,4
  1708.  
  1709. Supervisor:
  1710.     or    #$2000,sr
  1711.     move    #$0020,-(sp)
  1712.     pea    SupervisorRts(pc)
  1713.     move    sr,-(sp)
  1714.     jmp    (a5)
  1715.  
  1716.     cnop    0,4
  1717.  
  1718. SupervisorRts
  1719.     rts
  1720.  
  1721.     cnop    0,4
  1722.  
  1723. Exception8:
  1724.     cmp.l    #0,2(sp)
  1725.     bne.s    .Err
  1726.     move.l    #0,2(sp)
  1727.     jmp    (a5)
  1728.  
  1729. .Err
  1730.     or    #$0700,sr
  1731.     move.l    #8,-(sp)
  1732.  
  1733.     btst    #5,4(sp)
  1734.     bne    .Alert
  1735.  
  1736.     subq.l    #4,sp
  1737.     move.l    a0,-(sp)
  1738.     move.l    (4).w,a0
  1739.     move.l    $0114(a0),a0        ; ThisTask
  1740.     move.l    $0032(a0),4(sp)        ; tc_TrapCode
  1741.     move.l    (sp)+,a0
  1742.     rts
  1743.  
  1744. .Alert
  1745.     move.l    (sp)+,d7        ; alertNum
  1746.     bset    #31,d7
  1747.     move.l    (4).w,a6
  1748.     jmp    -$006C(a6)        ; _LVOAlert
  1749.  
  1750.     cnop    0,4
  1751.  
  1752. SupervisorEnd
  1753.  
  1754. ;------------------------------------------------------------------------------;
  1755.  
  1756. ;On KS 1.3 mh_Lower for chip mem points to memory after exec.library,
  1757. ;set it to $400 as in later kickstarts.
  1758.  
  1759. PatchLower:
  1760.     cmp    #36,$0014(a6)        ; lib_Version
  1761.     bcc    .Rts
  1762.  
  1763.     move.l    #$0427,d1
  1764.     add    $0010(a6),d1        ; lib_NegSize
  1765.     add    $0012(a6),d1        ; lib_PosSize
  1766.     and    #-8,d1
  1767.     lea    $0142(a6),a0        ; MemList
  1768.     jsr    -$0084(a6)        ; _LVOForbid
  1769.  
  1770. .Loop
  1771.     move.l    (a0),a0
  1772.     tst.l    (a0)
  1773.     beq    .Quit
  1774.     cmp.l    $0014(a0),d1        ; mh_Lower
  1775.     bne    .Loop
  1776.     move.l    #$0400,$0014(a0)    ; mh_Lower
  1777.  
  1778. .Quit
  1779.     jmp    -$008A(a6)        ; _LVOPermit
  1780.  
  1781. .Rts
  1782.     rts
  1783.  
  1784. ;------------------------------------------------------------------------------;
  1785.  
  1786. ;On KS 1.3 the supervisor stack comes right after mh_Upper.
  1787.  
  1788. PatchUpper:
  1789.     cmp    #36,$0014(a6)        ; lib_Version
  1790.     bcc    .Rts
  1791.  
  1792.     move.l    $003A(a6),d1        ; SysStkLower
  1793.     lea    $0142(a6),a0        ; MemList
  1794.     jsr    -$0084(a6)        ; _LVOForbid
  1795.  
  1796. .Loop
  1797.     move.l    (a0),a0
  1798.     tst.l    (a0)
  1799.     beq    .Quit
  1800.     cmp.l    $0018(a0),d1        ; mh_Upper
  1801.     bne    .Loop
  1802.     move.l    $0036(a6),$0018(a0)    ; mh_Upper, SysStkUpper
  1803.  
  1804. .Quit
  1805.     jmp    -$008A(a6)        ; _LVOPermit
  1806.  
  1807. .Rts
  1808.     rts
  1809.  
  1810. ;------------------------------------------------------------------------------;
  1811.  
  1812. InitList:
  1813. ;    a2=old base
  1814. ;    a3=new base
  1815. ;    d0=offset
  1816.  
  1817.     lea    (a2,d0),a0
  1818.     lea    (a3,d0),a1
  1819. ;    bra    CopyList
  1820.  
  1821. ;------------------------------------------------------------------------------;
  1822.  
  1823. CopyList:
  1824.     move.l    a2,d1
  1825.     move.l    (a0),a2
  1826.     move.l    a2,(a1)
  1827.     move.l    a1,$0004(a2)
  1828.     move.l    $0008(a0),a2
  1829.     move.l    a2,$0008(a1)
  1830.     addq.l    #4,a1
  1831.     move.l    a1,(a2)
  1832.     move.l    d1,a2
  1833.     rts
  1834.  
  1835. ;------------------------------------------------------------------------------;
  1836.  
  1837. ;Only free memory if it is within any Lower/Upper bound
  1838.  
  1839. FreeMemSafely:
  1840.     move.l    d0,d1
  1841.     beq    .Rts
  1842.     add.l    a1,d1
  1843.     lea    $0142(a6),a0        ; MemList
  1844.     jsr    -$0084(a6)        ; _LVOForbid
  1845.  
  1846. .Loop
  1847.     move.l    (a0),a0
  1848.     tst.l    (a0)
  1849.     beq    .Quit
  1850.  
  1851.     cmp.l    $0014(a0),a1        ; mh_Lower
  1852.     bcs    .Loop
  1853.     cmp.l    $0018(a0),a1        ; mh_Upper
  1854.     bcc    .Loop
  1855.     cmp.l    $0018(a0),d1        ; mh_Upper
  1856.     bhi    .Quit
  1857.     jsr    -$00D2(a6)        ; _LVOFreeMem
  1858.  
  1859. .Quit
  1860.     jmp    -$008A(a6)        ; _LVOPermit
  1861.  
  1862. .Rts
  1863.     rts
  1864.  
  1865. ;------------------------------------------------------------------------------;
  1866.  
  1867. GetVBR:
  1868. ; out    d0=vbr
  1869.  
  1870.     moveq    #0,d0
  1871.     btst    #0,$0129(a6)        ; AttnFlags+1, AFB_68010
  1872.     beq    .Rts
  1873.  
  1874.     move.l    a5,a0
  1875.     lea    .Ok(pc),a5        ; userFuntion
  1876.     jsr    -$001E(a6)        ; _LVOSupervisor
  1877.     move.l    a0,a5
  1878.  
  1879. .Rts
  1880.     rts
  1881.  
  1882. .Ok
  1883.     dc.l    $4E7A0801        ; movec vbr,d0
  1884.     rte
  1885.  
  1886. ;------------------------------------------------------------------------------;
  1887.  
  1888. InitChkBase:
  1889.     move.l    a6,d1
  1890.     not.l    d1
  1891.     move.l    $0026(a6),d0        ; ChkBase
  1892.     move.l    d1,$0026(a6)        ; ChkBase
  1893.     rts
  1894.  
  1895. ;------------------------------------------------------------------------------;
  1896.  
  1897. InitChkSum:
  1898.     moveq    #0,d1
  1899.     lea    $0022(a6),a0        ; SoftVer
  1900.     moveq    #23,d0
  1901.  
  1902. .Loop
  1903.     add    (a0)+,d1
  1904.     dbf    d0,.Loop
  1905.     not    d1
  1906.     move    (a0),d0
  1907.     move    d1,(a0)
  1908.     rts
  1909.  
  1910. ;------------------------------------------------------------------------------;
  1911.  
  1912. MyTypeOfMem:
  1913. ;    a1=address
  1914. ; out    d0=type
  1915. ;MEMB_SLOW=0
  1916. ;MEMB_CHIP=1
  1917. ;MEMB_FAST=2
  1918.  
  1919.     moveq    #2,d0            ; MEMF_CHIP
  1920.     cmp.l    #$00200000,a1        ; 0-2MB
  1921.     bcs    .Rts            ; lower than=>chip
  1922.  
  1923.     cmp.l    #$00C00000,a1        ; start of ranger memory
  1924.     bcs    .Ok
  1925.     moveq    #1,d0            ; MEMF_SLOW
  1926.     cmp.l    #$00DC0000,a1        ; end of ranger memory
  1927.     bcs    .Rts
  1928.  
  1929. .Ok
  1930.     jsr    -$0216(a6)        ; _LVOTypeOfMem
  1931.     and.l    #6,d0            ; MEMF_CHIP!MEMF_FAST (wipe out our slow flag)
  1932.     bne    .Rts
  1933.     moveq    #4,d0            ; MEMF_FAST
  1934.  
  1935. .Rts
  1936.     rts
  1937.  
  1938. ;------------------------------------------------------------------------------;
  1939.  
  1940.     cnop    0,4
  1941.  
  1942. OSCacheClearE:
  1943.     cmp    #37,$0014(a6)        ; lib_Version
  1944.     bcs    .Old
  1945.     jmp    -$0282(a6)        ; _LVOCacheClearE
  1946.  
  1947. .Old
  1948.     btst    #1,$0129(a6)        ; AttnFlags+1, AFB_68020
  1949.     beq    .Rts
  1950.  
  1951.     and.l    #$00000808,d1        ; caches, CACRF_ClearI!CACRF_ClearD
  1952.     move.l    a5,a0
  1953.     lea    .F2(pc),a5        ; userFunction
  1954.     btst    #3,$0129(a6)        ; AttnFlags+1, AFB_68040
  1955.     beq    .Ok
  1956.     lea    .F4(pc),a5        ; userFunction
  1957.     btst    #3,d1            ; CACRB_ClearI
  1958.     beq    .Ok
  1959.     lea    .F4I(pc),a5
  1960.  
  1961. .Ok
  1962.     jsr    -$001E(a6)        ; _LVOSupervisor
  1963.     move.l    a0,a5
  1964.  
  1965. .Rts
  1966.     rts
  1967.  
  1968. .F2
  1969.     or    #$0700,sr
  1970.     dc.l    $4E7A0002        ; movec cacr,d0
  1971.     or.l    d1,d0
  1972.     dc.l    $4E7B0002        ; movec d0,cacr
  1973.     rte
  1974.  
  1975. .F4
  1976.     dc.w    $F478
  1977.     rte
  1978.  
  1979. .F4I
  1980.     dc.w    $F4F8
  1981.     rte
  1982.  
  1983. ;------------------------------------------------------------------------------;
  1984.  
  1985.     cnop    0,4
  1986.  
  1987. OSCacheClearU:
  1988.     cmp    #37,$0014(a6)        ; lib_Version
  1989.     bcs    .Old
  1990.     jmp    -$027C(a6)        ; _LVOCacheClearU
  1991.  
  1992. .Old
  1993.     move.l    #$00000808,d1        ; caches, CACRF_ClearI!CACRF_ClearD
  1994.     bra    OSCacheClearE
  1995.  
  1996. ;------------------------------------------------------------------------------;
  1997.  
  1998.     cnop    0,4
  1999.  
  2000. OSCacheControl:
  2001.     cmp    #37,$0014(a6)        ; lib_Version
  2002.     bcs    .Old
  2003.     jmp    -$0288(a6)        ; _LVOCacheControl
  2004.  
  2005. .Old
  2006.     movem.l    d2/a5,-(sp)
  2007.     move.l    d0,d2
  2008.  
  2009.     moveq    #0,d0
  2010.     btst    #1,$0129(a6)        ; AttnFlags+1, AFB_68020
  2011.     beq    .End
  2012.  
  2013.     and.l    d1,d2
  2014.     not.l    d1
  2015.     or    #$0808,d2        ; CACRF_ClearI|CACRF_ClearD
  2016.     lea    .F(pc),a5        ; userFunction
  2017.     jsr    -$001E(a6)        ; _LVOSupervisor
  2018.  
  2019. .End
  2020.     movem.l    (sp)+,d2/a5
  2021.     rts
  2022.  
  2023. .F
  2024.     or    #$0700,sr
  2025.     dc.l    $4E7A0002        ; movec cacr,d0
  2026.     and.l    d0,d1
  2027.     or.l    d2,d1
  2028.     nop
  2029.     dc.l    $4E7B1002        ; movec d1,cacr
  2030.     nop
  2031.     rte
  2032.  
  2033. ;------------------------------------------------------------------------------;
  2034.  
  2035. SetSSP:
  2036. ;    d0=ptr
  2037.  
  2038.     movem.l    d2/a5,-(sp)
  2039.     lea    .Ok(pc),a5        ; userFunction
  2040.     jsr    -$001E(a6)        ; _LVOSupervisor
  2041.     movem.l    (sp)+,d2/a5
  2042.     bra    InitChkSum
  2043.  
  2044. .Ok
  2045.     or    #$0700,sr
  2046.  
  2047.     move.l    $003A(a6),a0        ; SysStkLower
  2048.     move.l    d0,a1
  2049.  
  2050.     move.l    $0036(a6),d2        ; SysStkUpper
  2051.     sub.l    a0,d2
  2052.  
  2053.     move.l    d2,d1
  2054.     lsr.l    #2,d1
  2055.     subq.l    #1,d1
  2056.  
  2057. .Copy
  2058.     move.l    (a0)+,(a1)+
  2059.     dbf    d1,.Copy
  2060.  
  2061.     sub.l    $003A(a6),sp        ; SysStkLower
  2062.     add.l    d0,sp
  2063.  
  2064.     move.l    d0,$003A(a6)        ; SysStkLower
  2065.     add.l    d2,d0
  2066.     move.l    d0,$0036(a6)        ; SysStkUpper
  2067.  
  2068.     rte
  2069.  
  2070. ;------------------------------------------------------------------------------;
  2071.  
  2072. SetVBR:
  2073. ;    d0=vbr
  2074.  
  2075.     btst    #0,$0129(a6)        ; AttnFlags+1, AFB_68010
  2076.     beq    .Rts
  2077.  
  2078.     move.l    a5,a0
  2079.     lea    .Ok(pc),a5        ; userFuntion
  2080.     jsr    -$001E(a6)        ; _LVOSupervisor
  2081.     move.l    a0,a5
  2082.  
  2083. .Rts
  2084.     rts
  2085.  
  2086. .Ok
  2087.     dc.l    $4E7B0801        ; movec d0,vbr
  2088.     rte
  2089.  
  2090. ;------------------------------------------------------------------------------;
  2091.  
  2092.     cnop    0,4
  2093.  
  2094. PatchExecStart
  2095.  
  2096. ;------------------------------------------------------------------------------;
  2097.  
  2098.     cnop    0,4
  2099.  
  2100. Cause:
  2101.     moveq    #11,d0            ; NT_SOFTINT
  2102.     move    #$00F0,d1
  2103.     lea    $01DA(a6),a0
  2104.  
  2105.     move    #$4000,$DFF09A        ; intena
  2106.     cmp.b    $0008(a1),d0        ; ln_Type
  2107.     beq    .1
  2108.  
  2109.     move.b    d0,$0008(a1)        ; ln_Type
  2110.     and.b    $0009(a1),d1        ; ln_Pri
  2111.     ext    d1
  2112.     add    d1,a0
  2113.     move.l    (a0),d0
  2114.     move.l    a1,(a0)
  2115.     subq.l    #4,a0
  2116.     exg.l    d0,a0
  2117.     movem.l    d0/a0,(a1)
  2118.     move.l    a1,(a0)
  2119.     move    #$8004,$DFF09C        ; intreq
  2120.     or    #$2000,$0124(a6)    ; SysFlags
  2121.  
  2122. .1
  2123.     tst.b    $0126(a6)        ; IDNestCnt
  2124.     bge    .2
  2125.     move    #$C000,$DFF09A        ; intena
  2126.  
  2127. .2
  2128.     nop
  2129.     rts
  2130.  
  2131. ;------------------------------------------------------------------------------;
  2132.  
  2133.     cnop    0,4
  2134.  
  2135. ExitIntr:
  2136.     move.l    (sp)+,a6
  2137.     moveq    #$20,d0
  2138.     and.b    $0018(sp),d0
  2139.     bne    ExitIntr1
  2140.     tst.b    $0127(a6)        ; TDNestCnt
  2141.     bge    ExitIntr1
  2142.     tst    $0124(a6)        ; SysFlags
  2143.     bmi    ExitIntr2
  2144.  
  2145. ExitIntr1
  2146.     movem.l    (sp)+,d0/d1/a0/a1/a5/a6
  2147.     rte
  2148.  
  2149.     cnop    0,4
  2150.  
  2151. ExitIntr2
  2152.     move    #$2000,sr
  2153.     bra    Schedule1
  2154.  
  2155.     cnop    0,4
  2156.  
  2157. Schedule:
  2158.     movem.l    d0/d1/a0/a1/a5/a6,-(sp)
  2159.  
  2160. Schedule1
  2161.     move.l    $0114(a6),a1        ; ThisTask
  2162.     move    #$2700,sr
  2163.     and    #$7FFF,$0124(a6)    ; SysFlags
  2164.     moveq    #$20,d0            ; TF_EXCEPT
  2165.     and.b    $000E(a1),d0        ; tc_Flags
  2166.     bne    .2
  2167.  
  2168.     lea    $0196(a6),a0        ; TaskReady
  2169.     cmp.l    $0008(a0),a0
  2170.     beq    ExitIntr1
  2171.  
  2172.     move.l    (a0),a0
  2173.     move.b    $0009(a0),d1        ; ln_Pri
  2174.     cmp.b    $0009(a1),d1        ; ln_Pri
  2175.     bgt    .2
  2176.  
  2177.     moveq    #$40,d0
  2178.     and.b    $0124(a6),d0        ; SysFlags
  2179.     beq    ExitIntr1
  2180.  
  2181. .2
  2182.     lea    $0196(a6),a0        ; TaskReady
  2183.  
  2184.     move.b    $0009(a1),d1        ; ln_Pri
  2185.     move.l    (a0),d0
  2186.  
  2187. .3
  2188.     move.l    d0,a0
  2189.     move.l    (a0),d0
  2190.     beq    .4
  2191.     cmp.b    $0009(a0),d1        ; ln_Pri
  2192.     ble    .3
  2193.  
  2194. .4
  2195.     move.l    $0004(a0),d0
  2196.     move.l    a1,$0004(a0)
  2197.     exg.l    d0,a0
  2198.     movem.l    d0/a0,(a1)
  2199.     move.l    a1,(a0)
  2200.  
  2201.     move.b    #3,$000F(a1)        ; tc_State, TS_READY
  2202.     move    #$2000,sr
  2203.     movem.l    (sp)+,d0/d1/a0/a1/a5
  2204.     move.l    (sp),-(sp)
  2205.     move.l    -$0034(a6),4(sp)
  2206.     move.l    (sp)+,a6
  2207.     rts
  2208.  
  2209. ;------------------------------------------------------------------------------;
  2210.  
  2211.     cnop    0,4
  2212.  
  2213. ReplyMsg:
  2214.     moveq    #7,d0            ; NT_REPLYMSG
  2215.     move.l    $000E(a1),d1        ; mn_ReplyPort
  2216.     move.l    d1,a0
  2217.     bne    Msg
  2218.     move.b    #6,$0008(a1)        ; ln_Type, NT_FREEMSG
  2219.     rts
  2220.  
  2221.     cnop    0,4
  2222.  
  2223. PutMsg:
  2224.     moveq    #5,d0            ; NT_MESSAGE
  2225.     move.l    a0,d1
  2226.  
  2227. Msg
  2228.     lea    $001C(a0),a0        ; mp_MsgList+8
  2229.     move    #$4000,$DFF09A        ; intena
  2230.     addq.b    #1,$0126(a6)        ; IDNestCnt
  2231.     move.b    d0,$0008(a1)        ; ln_Type
  2232.     move.l    (a0),d0
  2233.     move.l    a1,(a0)
  2234.     subq.l    #4,a0
  2235.     exg.l    d0,a0
  2236.     movem.l    d0/a0,(a1)
  2237.     move.l    a1,(a0)
  2238.     move.l    d1,a0
  2239.     move.l    $0010(a0),d0        ; mp_SigTask
  2240.     beq    .1
  2241.  
  2242.     moveq    #3,d1            ; PF_ACTION
  2243.     and.b    $000E(a0),d1        ; mp_Flags
  2244.     beq    .6
  2245.  
  2246.     subq.l    #1,d1            ; PA_SOFTINT=1
  2247.     bne    .3
  2248.  
  2249.     move.l    d0,a1            ; interrupt
  2250.     jsr    -$00B4(a6)        ; _LVOCause
  2251.  
  2252. .1
  2253.     subq.b    #1,$0126(a6)        ; IDNestCnt
  2254.     bge    .2
  2255.     move    #$C000,$DFF09A        ; intena
  2256.  
  2257. .2
  2258.     rts
  2259.  
  2260.     cnop    0,4
  2261.  
  2262. .3
  2263.     subq.l    #1,d1            ; PA_IGNORE=2
  2264.     beq    .4
  2265.     move.l    d0,a1
  2266.     jsr    (a1)
  2267.  
  2268. .4
  2269.     subq.b    #1,$0126(a6)        ; IDNestCnt
  2270.     bge    .5
  2271.     move    #$C000,$DFF09A        ; intena
  2272.  
  2273. .5
  2274.     rts
  2275.  
  2276.     cnop    0,4
  2277.  
  2278. .6
  2279.     move.b    $000F(a0),d1        ; mp_SigBit
  2280.     addq.b    #1,$0127(a6)        ; TDNestCnt
  2281.     subq.b    #1,$0126(a6)        ; IDNestCnt
  2282.     bge    .7
  2283.     move    #$C000,$DFF09A        ; intena
  2284.  
  2285. .7
  2286.     move.l    d0,a1            ; task
  2287.     moveq    #0,d0            ; signalSet
  2288.     bset    d1,d0
  2289.     jsr    -$0144(a6)        ; _LVOSignal
  2290.     jmp    -$008A(a6)        ; _LVOPermit
  2291.  
  2292. ;------------------------------------------------------------------------------;
  2293.  
  2294.     cnop    0,4
  2295.  
  2296. Switch:
  2297.     move    #$2000,sr
  2298.     move.l    a5,-(sp)
  2299.     move.l    usp,a5
  2300.     movem.l    d0-a6,-(a5)
  2301.     move.l    #0,a6
  2302.     move    $0126(a6),d0        ; IDNestCnt
  2303.     move    #-1,$0126(a6)        ; IDNestCnt
  2304.     move    #$C000,$DFF09A        ; intena
  2305.     move.l    (sp)+,$0034(a5)
  2306.     move    (sp)+,-(a5)
  2307.     move.l    (sp)+,-(a5)
  2308.     move.l    $0230(a6),a4        ; ex_LaunchPoint
  2309.     move.l    $0114(a6),a3        ; ThisTask
  2310.     move    d0,$0010(a3)        ; tc_IDNestCnt
  2311.     move.l    a5,$0036(a3)        ; tc_SPReg
  2312.     moveq    #$40,d0            ; TF_SWITCH
  2313.     and.b    $000E(a3),d0        ; tc_Flags
  2314.     beq    Dispatch1
  2315.     move.l    $0042(a3),a5        ; tc_Switch
  2316.     jsr    (a5)
  2317.     bra    Dispatch1
  2318.  
  2319. ;------------------------------------------------------------------------------;
  2320.  
  2321.     cnop    0,4
  2322.  
  2323. SwitchFPU:
  2324.     move    #$2000,sr
  2325.     move.l    a5,-(sp)
  2326.     move.l    usp,a5
  2327.     movem.l    d0-a6,-(a5)
  2328.     move.l    #0,a6
  2329.     move    $0126(a6),d0        ; IDNestCnt
  2330.     move    #-1,$0126(a6)        ; IDNestCnt
  2331.     move    #$C000,$DFF09A        ; intena
  2332.     move.l    (sp)+,$0034(a5)
  2333.     move    (sp)+,-(a5)
  2334.     move.l    (sp)+,-(a5)
  2335.     move    (sp)+,d1
  2336.     dc.w    $F325            ; fsave -(a5)
  2337.     tst.b    (a5)
  2338.     beq    .2
  2339.     moveq    #-1,d2
  2340.     move    d2,-(a5)
  2341.     and    #$F000,d1
  2342.     cmp    #$9000,d1
  2343.     bne    .1
  2344.     move.l    (sp)+,-(a5)
  2345.     move.l    (sp)+,-(a5)
  2346.     move.l    (sp)+,-(a5)
  2347.     move    d1,d2
  2348.  
  2349. .1
  2350.     dc.w    $F225,$E0FF        ; fmovem.x fp0-fp7,-(a5)
  2351.     dc.w    $F225,$BC00        ; fmovem.l fpcr/fpsr/fpiar,-(a5)
  2352.     move    d2,-(a5)
  2353.  
  2354. .2
  2355.     move.l    $0230(a6),a4        ; ex_LaunchPoint
  2356.     move.l    $0114(a6),a3        ; ThisTask
  2357.     move    d0,$0010(a3)        ; tc_IDNestCnt
  2358.     move.l    a5,$0036(a3)        ; tc_SPReg
  2359.     moveq    #$40,d0            ; TF_SWITCH
  2360.     and.b    $000E(a3),d0        ; tc_Flags
  2361.     beq    Dispatch1
  2362.     move.l    $0042(a3),a5        ; tc_Switch
  2363.     jsr    (a5)
  2364.     bra    Dispatch1
  2365.  
  2366. ;------------------------------------------------------------------------------;
  2367.  
  2368.     cnop    0,4
  2369.  
  2370. Dispatch0
  2371.     addq.l    #1,$0118(a6)        ; IdleCount
  2372.     or    #$8000,$0124(a6)
  2373.     stop    #$2000
  2374.     bra    Dispatch2
  2375.  
  2376.     cnop    0,4
  2377.  
  2378. Dispatch:
  2379.     move.l    $0230(a6),a4        ; ex_LaunchPoint
  2380.     move    #-1,$0126(a6)        ; IDNestCnt
  2381.     move    #$C000,$DFF09A        ; intena
  2382.  
  2383. Dispatch1
  2384.     lea    $0196(a6),a0        ; TaskReady
  2385.  
  2386. Dispatch2
  2387.     move    #$2700,sr
  2388.     move.l    (a0),a3
  2389.     move.l    (a3),d0
  2390.     beq    Dispatch0
  2391.  
  2392.     move.l    d0,(a0)
  2393.     move.l    d0,a1
  2394.     move.l    a0,$0004(a1)
  2395.     move.l    a3,$0114(a6)        ; ThisTask
  2396.     lea    $0120(a6),a1
  2397.     move    (a1)+,(a1)+
  2398.     and    #$BFFF,(a1)+
  2399.     move.b    #2,$000F(a3)        ; tc_State, TS_RUN
  2400.     move    $0010(a3),(a1)        ; tc_IDNestCnt
  2401.     tst.b    (a1)
  2402.     bmi    Dispatch3
  2403.     move    #$4000,$DFF09A        ; intena
  2404.  
  2405. Dispatch3
  2406.     move    #$2000,sr
  2407.     addq.l    #1,$011C(a6)        ; DispCount
  2408.     move.b    $000E(a3),d2        ; tc_Flags
  2409.     and    #$A0,d2            ; TF_EXCEPT!TF_LAUNCH
  2410.     beq    Dispatch5
  2411.     bpl    Dispatch4
  2412.     move.l    $0046(a3),a5        ; tc_Launch
  2413.     jsr    (a5)
  2414.     and    #$20,d2
  2415.     beq    Dispatch5
  2416.  
  2417. Dispatch4
  2418.     bsr    Exception
  2419.  
  2420. Dispatch5
  2421.     move.l    $0036(a3),a5        ; tc_SPReg
  2422.     jmp    (a4)
  2423.  
  2424. ;------------------------------------------------------------------------------;
  2425.  
  2426.     cnop    0,4
  2427.  
  2428. Exception:
  2429.     and.b    #$DF,$000E(a3)        ; tc_Flags, TB_EXCEPT=5
  2430.     move.l    $002A(a3),d1        ; tc_ExceptCode
  2431.     beq    Exception3
  2432.  
  2433.     lea    $0126(a6),a0        ; IDNestCnt
  2434.     move    #$4000,$DFF09A        ; intena
  2435.     lea    $001A(a3),a1        ; tc_SigRecvd
  2436.     move.l    (a1)+,d0
  2437.     and.l    (a1),d0
  2438.     eor.l    d0,(a1)
  2439.     eor.l    d0,-(a1)
  2440.     tst.b    (a0)
  2441.     bge    Exception1
  2442.     move    #$C000,$DFF09A        ; intena
  2443.  
  2444. Exception1
  2445.     move.l    $0036(a3),a1        ; tc_SPReg
  2446.     move.l    $000E(a3),-(a1)        ; tc_Flags/tc_State/tc_IDNestCnt/tc_TDNestCnt
  2447.     tst.b    (a0)
  2448.     bne    Exception2
  2449.     subq.b    #1,(a0)
  2450.     move    #$C000,$DFF09A        ; intena
  2451.  
  2452. Exception2
  2453.     move.l    #Exception4,-(a1)
  2454.     move.l    a1,usp
  2455.     move    #$0020,-(sp)
  2456.     move.l    d1,-(sp)
  2457.     clr    -(sp)
  2458.     move.l    $0026(a3),a1        ; tc_ExceptData
  2459.     rte
  2460.  
  2461.     cnop    0,4
  2462.  
  2463. Exception3
  2464.     rts
  2465.  
  2466.     cnop    0,4
  2467.  
  2468. Exception4
  2469.     move.l    #0,a6
  2470.     lea    Exception5(pc),a5    ; userFunction
  2471.     jmp    -$001E(a6)        ; _LVOSupervisor
  2472.  
  2473.     cnop    0,4
  2474.  
  2475. Exception5
  2476.     move.l    $0230(a6),a4        ; ex_LaunchPoint
  2477.     addq.l    #8,sp
  2478.     move.l    $0114(a6),a3        ; ThisTask
  2479.     or.l    d0,$001E(a3)        ; tc_SigExcept
  2480.     move.l    usp,a1
  2481.     move.l    (a1)+,$000E(a3)        ; tc_Flags/tc_State/tc_IDNestCnt/tc_TDNestCnt
  2482.     move.l    a1,$0036(a3)        ; tc_SPReg
  2483.     move    $0010(a3),$0126(a6)    ; IDNestCnt, tc_IDNestCnt
  2484. ;    tst.b    $0126(a6)        ; IDNestCnt
  2485.     bmi    Exception6
  2486.     move    #$4000,$DFF09A        ; intena
  2487.  
  2488. Exception6
  2489.     rts
  2490.  
  2491. ;------------------------------------------------------------------------------;
  2492.  
  2493.     cnop    0,4
  2494.  
  2495. Wait:
  2496.     move.l    $0114(a6),a1        ; ThisTask
  2497.     move.l    d0,$0016(a1)        ; tc_SigWait
  2498.     move    #$4000,$DFF09A        ; intena
  2499.     and.l    $001A(a1),d0        ; tc_SigRecvd
  2500.     bne    .2
  2501.     addq.b    #1,$0127(a6)        ; TDNestCnt
  2502.  
  2503. .1
  2504.     move.b    #4,$000F(a1)        ; tc_State, TS_WAIT
  2505.     lea    $01AC(a6),a0        ; TaskWait+8
  2506.     move.l    (a0),d0
  2507.     move.l    a1,(a0)
  2508.     subq.l    #4,a0
  2509.     exg.l    d0,a0
  2510.     movem.l    d0/a0,(a1)
  2511.     move.l    a1,(a0)
  2512.     move.b    $0126(a6),d1        ; IDNestCnt
  2513.     st    $0126(a6)        ; IDNestCnt
  2514.     move    #$C000,$DFF09A        ; intena
  2515.     move.l    a5,a0
  2516.     lea    -$0036(a6),a5        ; userFunction, _LVOSwitch
  2517.     jsr    -$001E(a6)        ; _LVOSupervisor
  2518.     move.l    a0,a5
  2519.     move    #$4000,$DFF09A        ; intena
  2520.     move.b    d1,$0126(a6)        ; IDNestCnt
  2521.     move.l    $0016(a1),d0        ; tc_SigWait
  2522.     and.l    $001A(a1),d0        ; tc_SigRecvd
  2523.     beq    .1
  2524.     subq.b    #1,$0127(a6)        ; TDNestCnt
  2525.  
  2526. .2
  2527.     eor.l    d0,$001A(a1)        ; tc_SigRecvd
  2528.     tst.b    $0126(a6)        ; IDNestCnt
  2529.     bge    .3
  2530.     move    #$C000,$DFF09A        ; intena
  2531.  
  2532. .3
  2533.     rts
  2534.  
  2535. ;------------------------------------------------------------------------------;
  2536.  
  2537.     cnop    0,4
  2538.  
  2539. PatchExecEnd
  2540.  
  2541. ;------------------------------------------------------------------------------;
  2542.  
  2543. expansion_library    dc.b 'expansion.library',0
  2544.  
  2545. FastExecName        dc.b 'FastExec',0
  2546.             dc.b '$VER: '
  2547. FastExecId        dc.b 'FastExec 2.6 (21.5.97)',13,10,0
  2548.  
  2549.     cnop    0,4
  2550.  
  2551. ArgArray
  2552. ArgSYSINFO        dc.l    0
  2553. ArgREBOOT        dc.l    0
  2554. ArgNOEXEC        dc.l    0
  2555. ArgLOCAL        dc.l    0
  2556. ArgPATCH        dc.l    0
  2557. ArgFASTSSP        dc.l    0
  2558. ArgFASTVBR        dc.l    0
  2559. ArgFASTEXP        dc.l    0
  2560. ArgFASTMEM        dc.l    0
  2561. ArgFASTINT        dc.l    0
  2562. ArgCACHE        dc.l    0
  2563. ArgADDMEM        dc.l    0
  2564.  
  2565. OldAddMemList        dc.l    0
  2566. CacheBits        dc.l    0
  2567. AddMemData        dcb.l    260,0
  2568. FlagEBExec        dc.b    0
  2569.  
  2570.     cnop    0,4
  2571.  
  2572. ResEnd
  2573.  
  2574. ;------------------------------------------------------------------------------;
  2575. ;------------------------------------------------------------------------------;
  2576. ;------------------------------------------------------------------------------;
  2577.  
  2578. ibrd_next    = 0
  2579. ibrd_name    = ibrd_next+4
  2580. ibrd_addr    = ibrd_name+4
  2581. ibrd_boardaddr    = ibrd_addr+4
  2582. ibrd_boardsize    = ibrd_boardaddr+4
  2583. ibrd_manufact    = ibrd_boardsize+4
  2584. ibrd_product    = ibrd_manufact+2
  2585. ibrd_sizeof    = ibrd_product+1
  2586.  
  2587. ilib_next    = 0
  2588. ilib_name    = ilib_next+4
  2589. ilib_addr    = ilib_name+4
  2590. ilib_neg    = ilib_addr+4
  2591. ilib_pos    = ilib_neg+2
  2592. ilib_ver    = ilib_pos+2
  2593. ilib_rev    = ilib_ver+2
  2594. ilib_opn    = ilib_rev+2
  2595. ilib_mem    = ilib_opn+2
  2596. ilib_pri    = ilib_mem+1
  2597. ilib_sizeof    = ilib_pri+1
  2598.  
  2599. imem_next    = 0
  2600. imem_name    = imem_next+4
  2601. imem_addr    = imem_name+4
  2602. imem_lower    = imem_addr+4
  2603. imem_upper    = imem_lower+4
  2604. imem_type    = imem_upper+4
  2605. imem_pri    = imem_type+2
  2606. imem_sizeof    = imem_pri+1
  2607.  
  2608. ;------------------------------------------------------------------------------;
  2609.  
  2610. SysInfo:
  2611.     movem.l    d2-d7/a2-a5,-(sp)
  2612.     move.l    sp,d7
  2613.     lea    -1024(sp),sp
  2614.     move.l    sp,a3
  2615.     lea    -68(sp),sp
  2616.     move.l    sp,a4
  2617.     move.l    a4,a2
  2618.  
  2619. ;Kickstart
  2620.     move    $0014(a6),d1        ; lib_Version
  2621.     move    d1,(a2)+
  2622.     move    $0022(a6),d0
  2623.     cmp    #36,d1
  2624.     bcc    .KS
  2625. ;SoftVer is zero under KS 1.3
  2626. ;Use rom revision if rom version is same as exec,
  2627. ;else go on with zero.
  2628.     lea    $01000000,a0
  2629.     sub.l    -$0014(a0),a0
  2630.     lea    $000C(a0),a0
  2631.     cmp    (a0)+,d1
  2632.     bne    .KS
  2633.     move    (a0),d0
  2634.  
  2635. .KS
  2636.     move    d0,(a2)+        ; SoftVer
  2637.  
  2638. ;Workbench
  2639.     moveq    #-1,d0            ; ptr
  2640.     bsr    SetWindowPtr
  2641.     move.l    d0,d2
  2642.     lea    version_library(pc),a1    ; libName
  2643.     moveq    #0,d0            ; version
  2644.     jsr    -$0228(a6)        ; _LVOOpenLibrary
  2645.     exg.l    d0,d2
  2646.     bsr    SetWindowPtr
  2647.     move.l    d2,d0
  2648.     beq    .WB
  2649.     move.l    d0,a1            ; library
  2650.     move.l    $0014(a1),d2        ; lib_Version/lib_Revision
  2651.     jsr    -$019E(a6)        ; _LVOCloseLibrary
  2652.  
  2653. .WB
  2654.     move.l    d2,(a2)+
  2655.  
  2656. ;ROM
  2657.     lea    $01000000,a0
  2658.     move.l    -$0014(a0),d0
  2659.     sub.l    d0,a0
  2660.     move.l    $000C(a0),(a2)+
  2661.  
  2662. ;CPU
  2663.     move    $0128(a6),d1        ; AttnFlags
  2664.     moveq    #6,d0
  2665.     tst.b    d1            ; AFB_68060=7
  2666.     bmi    .CPU
  2667.     moveq    #4,d0
  2668.     btst    #3,d1            ; AFB_68040
  2669.     bne    .CPU
  2670.     moveq    #3,d0
  2671.     btst    #2,d1            ; AFB_68030
  2672.     bne    .CPU
  2673.     moveq    #2,d0
  2674.     btst    #1,d1            ; AFB_68020
  2675.     bne    .CPU
  2676.     moveq    #1,d0
  2677.     btst    #0,d1            ; AFB_68010
  2678.     bne    .CPU
  2679.     moveq    #0,d0
  2680.  
  2681. .CPU
  2682.     move.l    d0,(a2)+
  2683.  
  2684. ;FPU
  2685.     btst    #3,d1            ; AFB_68040
  2686.     beq    .FPU40
  2687.     lea    StrFPU40(pc),a0
  2688.     btst    #6,d1
  2689.     bne    .FPU
  2690.  
  2691. .FPU40
  2692.     lea    Str68882(pc),a0
  2693.     btst    #5,d1
  2694.     bne    .FPU
  2695.     lea    Str68881(pc),a0
  2696.     btst    #4,d1
  2697.     bne    .FPU
  2698.     lea    StrNONE(pc),a0
  2699.  
  2700. .FPU
  2701.     move.l    a0,(a2)+
  2702.  
  2703. ;VBR
  2704.     bsr    GetVBR
  2705.     move.l    d0,(a2)+
  2706.  
  2707.     move.l    $002A(a6),(a2)+        ; ColdCapture
  2708.     move.l    $002E(a6),(a2)+        ; CoolCapture
  2709.     move.l    $0032(a6),(a2)+        ; WarmCapture
  2710.     move.l    $0222(a6),(a2)+        ; KickMemPtr
  2711.     move.l    $0226(a6),(a2)+        ; KickTagPtr
  2712.     move.l    $0036(a6),(a2)+        ; SysStkUpper
  2713.     move.l    $003A(a6),(a2)+        ; SysStkLower
  2714.     move.l    $003E(a6),(a2)+        ; MaxLocMem
  2715.     move.l    $004E(a6),(a2)+        ; MaxExtMem
  2716.     move.l    $0128(a6),(a2)+        ; AttnFlags
  2717.  
  2718.     lea    .FmtMisc(pc),a0        ; formatString
  2719.     move.l    a4,a1            ; dataStream
  2720.     lea    PutChProc(pc),a2    ; putChProc
  2721. ;    move.l    #0,a3            ; putChData
  2722.     jsr    -$020A(a6)        ; _LVORawDoFmt
  2723.  
  2724.     move.l    a3,a0            ; string
  2725.     bsr    Put
  2726.  
  2727.     move.l    d7,sp
  2728.     movem.l    (sp)+,d2-d7/a2-a5
  2729.  
  2730.     tst.l    d0
  2731.     beq    .Rts
  2732.     bsr    PutLF
  2733.     bsr    SysIBrd
  2734.  
  2735.     tst.l    d0
  2736.     beq    .Rts
  2737.     bsr    PutLF
  2738.     bsr    SysIMem
  2739.  
  2740.     tst.l    d0
  2741.     beq    .Rts
  2742.     bsr    PutLF
  2743.     move    #$017A,d0        ; LibList
  2744.     bsr    SysIList
  2745.  
  2746.     tst.l    d0
  2747.     beq    .Rts
  2748.     bsr    PutLF
  2749.     move    #$015E,d0        ; DeviceList
  2750.     bsr    SysIList
  2751.  
  2752.     tst.l    d0
  2753.     beq    .Rts
  2754.     bsr    PutLF
  2755.     move    #$0150,d0        ; ResourceList
  2756.     bsr    SysIList
  2757.  
  2758.     tst.l    d0
  2759.     beq    .Rts
  2760.     bsr    PutLF
  2761.     bsr    SysIRes
  2762.  
  2763. .Rts
  2764.     rts
  2765.  
  2766. .FmtMisc
  2767.  dc.b 'Kickstart: %d.%d',10
  2768.  dc.b 'Workbench: %d.%d',10
  2769.  dc.b 'ROM: %d.%d',10
  2770.  dc.b 'CPU: 680%ld0',10
  2771.  dc.b 'FPU: %s',10
  2772.  dc.b 'VBR: $%08lx',10
  2773.  dc.b 'ColdCapture: $%08lx',10
  2774.  dc.b 'CoolCapture: $%08lx',10
  2775.  dc.b 'WarmCapture: $%08lx',10
  2776.  dc.b 'KickMemPtr:  $%08lx',10
  2777.  dc.b 'KickTagPtr:  $%08lx',10
  2778.  dc.b 'SysStkUpper: $%08lx',10
  2779.  dc.b 'SysStkLower: $%08lx',10
  2780.  dc.b 'MaxLocMem:   $%08lx',10
  2781.  dc.b 'MaxExtMem:   $%08lx',10
  2782.  dc.b 'AttnFlags:   $%08lx',10
  2783.  dc.b 0
  2784.  
  2785.     cnop    0,2
  2786.  
  2787. ;------------------------------------------------------------------------------;
  2788.  
  2789. SysIBrd:
  2790.     movem.l    d2-d4/a2-a4,-(sp)
  2791.     lea    -80(sp),sp
  2792.     move.l    sp,a3
  2793.  
  2794.     lea    .Str(pc),a0        ; string
  2795.     moveq    #1,d0
  2796.     bsr    PutS
  2797.     move.l    d0,d4
  2798.     beq    .Done
  2799.  
  2800.     bsr    GetIBrd
  2801.     move.l    d0,d2
  2802.     beq    .Done
  2803.     move.l    d0,d1
  2804.     addq.l    #1,d1
  2805.     beq    .Err
  2806.  
  2807. .Loop
  2808.     move.l    d0,a4
  2809.     move.l    sp,d3
  2810.  
  2811.     moveq    #0,d0
  2812.     move.b    ibrd_product(a4),d0
  2813.     move.l    d0,-(sp)
  2814.     move    ibrd_manufact(a4),d0
  2815.     move.l    d0,-(sp)
  2816.     move.l    ibrd_boardsize(a4),-(sp)
  2817.     move.l    ibrd_boardaddr(a4),-(sp)
  2818.     move.l    ibrd_addr(a4),-(sp)
  2819.  
  2820.     lea    .Fmt(pc),a0        ; formatString
  2821.     move.l    sp,a1            ; dataStream
  2822.     lea    PutChProc(pc),a2    ; putChProc
  2823. ;    lea    #0,a3            ; putChData
  2824.     jsr    -$020A(a6)        ; _LVORawDoFmt
  2825.  
  2826.     move.l    a3,a0            ; string
  2827.     moveq    #1,d0
  2828.     bsr    PutS
  2829.     move.l    d3,sp
  2830.     move.l    d0,d4
  2831.     beq    .Quit
  2832.  
  2833.     move.l    (a4),d0            ; ilib_next
  2834.     bne    .Loop
  2835.     moveq    #1,d4
  2836.  
  2837. .Quit
  2838.     move.l    d2,a0            ; info
  2839.     bsr    FreeInfo
  2840.  
  2841. .Done
  2842.     move.l    d4,d0
  2843.     lea    80(sp),sp
  2844.     movem.l    (sp)+,d2-d4/a2-a4
  2845.     rts
  2846.  
  2847. .Err
  2848.     lea    TxtAllocMem(pc),a0        ; string
  2849.     bsr    PutS
  2850.     moveq    #0,d4
  2851.     bra    .Done
  2852.  
  2853. .Str
  2854.  dc.b 'BOARDS:',10
  2855.  dc.b 'Address   BoardAddr BoardSize Manufacturer Product',10,0
  2856. .Fmt
  2857.  dc.b '$%08lx $%08lx $%08lx %12ld %7ld',10,0
  2858.  
  2859.     cnop    0,2
  2860.  
  2861. ;------------------------------------------------------------------------------;
  2862.  
  2863. SysIList:
  2864.     movem.l    d2-d5/a2-a4,-(sp)
  2865.     lea    -80(sp),sp
  2866.     move.l    sp,a3
  2867.     move.l    d0,d5
  2868.  
  2869.     lea    .Str150(pc),a0        ; string
  2870.     cmp    #$0150,d0
  2871.     beq    .Header
  2872.     lea    .Str15E(pc),a0        ; string
  2873.     cmp    #$015E,d0
  2874.     beq    .Header
  2875.     lea    .Str17A(pc),a0        ; string
  2876.  
  2877. .Header
  2878.     bsr    PutS
  2879.     move.l    d0,d4
  2880.     beq    .Done
  2881.  
  2882.     lea    .Str(pc),a0        ; string
  2883.     moveq    #1,d0
  2884.     bsr    PutS
  2885.     move.l    d0,d4
  2886.     beq    .Done
  2887.  
  2888.     move    d5,d0
  2889.     bsr    GetIList
  2890.     move.l    d0,d2
  2891.     beq    .Done
  2892.     move.l    d0,d1
  2893.     addq.l    #1,d1
  2894.     beq    .Err
  2895.  
  2896. .Loop
  2897.     move.l    d0,a4
  2898.     move.l    sp,d3
  2899.  
  2900.     moveq    #0,d0
  2901.     move    ilib_opn(a4),d0
  2902.     move.l    d0,-(sp)
  2903.     move    ilib_rev(a4),d0
  2904.     move.l    d0,-(sp)
  2905.     move    ilib_ver(a4),d0
  2906.     move.l    d0,-(sp)
  2907.     move    ilib_pos(a4),d0
  2908.     move.l    d0,-(sp)
  2909.     move    ilib_neg(a4),d0
  2910.     move.l    d0,-(sp)
  2911.     move.b    ilib_pri(a4),d0
  2912.     ext    d0
  2913.     ext.l    d0
  2914.     move.l    d0,-(sp)
  2915.     moveq    #0,d0
  2916.     move.b    ilib_mem(a4),d0
  2917.     bsr    GetMemStr
  2918.     move.l    d0,-(sp)
  2919.     move.l    ilib_name(a4),-(sp)
  2920.     move.l    ilib_addr(a4),-(sp)
  2921.  
  2922.     lea    .Fmt(pc),a0        ; formatString
  2923.     move.l    sp,a1            ; dataStream
  2924.     lea    PutChProc(pc),a2    ; putChProc
  2925. ;    lea    #0,a3            ; putChData
  2926.     jsr    -$020A(a6)        ; _LVORawDoFmt
  2927.  
  2928.     move.l    a3,a0            ; string
  2929.     moveq    #1,d0
  2930.     bsr    PutS
  2931.     move.l    d3,sp
  2932.     move.l    d0,d4
  2933.     beq    .Quit
  2934.  
  2935.     move.l    (a4),d0            ; ilib_next
  2936.     bne    .Loop
  2937.     moveq    #1,d4
  2938.  
  2939. .Quit
  2940.     move.l    d2,a0            ; info
  2941.     bsr    FreeInfo
  2942.  
  2943. .Done
  2944.     move.l    d4,d0
  2945.     lea    80(sp),sp
  2946.     movem.l    (sp)+,d2-d5/a2-a4
  2947.     rts
  2948.  
  2949. .Err
  2950.     lea    TxtAllocMem(pc),a0        ; string
  2951.     bsr    PutS
  2952.     moveq    #0,d4
  2953.     bra    .Done
  2954.  
  2955. .Str150
  2956.  dc.b 'RESOURCES:',10,0
  2957. .Str15E
  2958.  dc.b 'DEVICES:',10,0
  2959. .Str17A
  2960.  dc.b 'LIBRARIES:',10,0
  2961. .Str
  2962.  dc.b 'Address   Name              MemType  Pri   Neg   Pos   Version OpenCnt',10,0
  2963. .Fmt
  2964.  dc.b '$%08lx %-20.20s %.4s %4ld %5ld %5ld %5ld.%-5ld %5ld',10,0
  2965.     cnop    0,2
  2966.  
  2967. ;------------------------------------------------------------------------------;
  2968.  
  2969. SysIMem:
  2970.     movem.l    d2-d4/a2-a4,-(sp)
  2971.     lea    -80(sp),sp
  2972.     move.l    sp,a3
  2973.  
  2974.     lea    .Str(pc),a0        ; string
  2975.     moveq    #1,d0
  2976.     bsr    PutS
  2977.     move.l    d0,d4
  2978.     beq    .Done
  2979.  
  2980.     bsr    GetIMem
  2981.     move.l    d0,d2
  2982.     beq    .Done
  2983.     move.l    d0,d1
  2984.     addq.l    #1,d1
  2985.     beq    .Err
  2986.  
  2987. .Loop
  2988.     move.l    d0,a4
  2989.     move.l    sp,d3
  2990.  
  2991.     move.b    imem_pri(a4),d0
  2992.     ext    d0
  2993.     ext.l    d0
  2994.     move.l    d0,-(sp)
  2995.     moveq    #0,d0
  2996.     move    imem_type(a4),d0
  2997.     move.l    d0,-(sp)
  2998.     move.l    imem_upper(a4),-(sp)
  2999.     move.l    imem_lower(a4),-(sp)
  3000.     move.l    imem_name(a4),-(sp)
  3001.     move.l    imem_addr(a4),-(sp)
  3002.  
  3003.     lea    .Fmt(pc),a0        ; formatString
  3004.     move.l    sp,a1            ; dataStream
  3005.     lea    PutChProc(pc),a2    ; putChProc
  3006. ;    lea    #0,a3            ; putChData
  3007.     jsr    -$020A(a6)        ; _LVORawDoFmt
  3008.  
  3009.     move.l    a3,a0            ; string
  3010.     moveq    #1,d0
  3011.     bsr    PutS
  3012.     move.l    d3,sp
  3013.     move.l    d0,d4
  3014.     beq    .Quit
  3015.  
  3016.     move.l    (a4),d0            ; ilib_next
  3017.     bne    .Loop
  3018.     moveq    #1,d4
  3019.  
  3020. .Quit
  3021.     move.l    d2,a0            ; info
  3022.     bsr    FreeInfo
  3023.  
  3024. .Done
  3025.     move.l    d4,d0
  3026.     lea    80(sp),sp
  3027.     movem.l    (sp)+,d2-d4/a2-a4
  3028.     rts
  3029.  
  3030. .Err
  3031.     lea    TxtAllocMem(pc),a0        ; string
  3032.     bsr    PutS
  3033.     moveq    #0,d4
  3034.     bra    .Done
  3035.  
  3036. .Str
  3037.  dc.b 'MEMORY HEADERS:',10
  3038.  dc.b 'Address   Name                 Lower     Upper     Type   Pri',10,0
  3039. .Fmt
  3040.  dc.b '$%08lx %-20.20s $%08lx $%08lx $%04lx %4ld',10,0
  3041.  
  3042.     cnop    0,2
  3043.  
  3044. ;------------------------------------------------------------------------------;
  3045.  
  3046. SysIRes:
  3047.     movem.l    d2-d4/a2-a4,-(sp)
  3048.     lea    -80(sp),sp
  3049.     move.l    sp,a3
  3050.     lea    -20(sp),sp
  3051.     move.l    sp,d4
  3052.  
  3053.     lea    .Str(pc),a0        ; string
  3054.     moveq    #1,d0
  3055.     bsr    PutS
  3056.     tst.l    d0
  3057.     beq    .End
  3058.  
  3059.     move.l    $012C(a6),a2        ; ResModules
  3060.  
  3061. .Loop
  3062.     move.l    (a2)+,d0
  3063.     beq    .Ok
  3064.     bgt    .Put
  3065.  
  3066.     bclr    #31,d0
  3067.     move.l    d0,a2
  3068.     bra    .Loop
  3069.  
  3070. .Put
  3071.     move.l    d0,a4
  3072.     move.l    sp,d3
  3073.  
  3074.     move.b    $000D(a4),d0        ; rt_Pri
  3075.     ext    d0
  3076.     ext.l    d0
  3077.     move.l    d0,-(sp)
  3078.     move.b    $000C(a4),d0        ; rt_Type
  3079.     bsr    GetTypeString
  3080.     move.l    d0,-(sp)
  3081.     move.b    $000B(a4),d0        ; rt_Version
  3082.     ext    d0
  3083.     ext.l    d0
  3084.     move.l    d0,-(sp)
  3085.     moveq    #0,d0
  3086.     move.b    $000A(a4),d0        ; rt_Flags
  3087.     move.l    d0,-(sp)
  3088.  
  3089.     move.l    $000E(a4),a0        ; rt_Name
  3090.     move.l    d4,a1
  3091.  
  3092. .Loop2
  3093.     move.b    (a0)+,d0
  3094.     beq    .Ok2
  3095.     cmp.b    #10,d0
  3096.     beq    .Ok2
  3097.     cmp.b    #13,d0
  3098.     beq    .Ok2
  3099.     move.b    d0,(a1)+
  3100.     bra    .Loop2
  3101.  
  3102. .Ok2
  3103.     clr.b    (a1)
  3104.     move.l    d4,-(sp)
  3105.     move.l    a4,-(sp)
  3106.  
  3107.     lea    .Fmt(pc),a0        ; formatString
  3108.     move.l    sp,a1            ; dataStream
  3109.     move.l    a2,-(sp)
  3110.     lea    PutChProc(pc),a2    ; putChProc
  3111. ;    lea    #0,a3            ; putChData
  3112.     jsr    -$020A(a6)        ; _LVORawDoFmt
  3113.     move.l    (sp)+,a2
  3114.  
  3115.     move.l    a3,a0            ; string
  3116.     moveq    #1,d0
  3117.     bsr    PutS
  3118.     move.l    d3,sp
  3119.     tst.l    d0
  3120.     bne    .Loop
  3121.     bra    .End
  3122.  
  3123. .Ok
  3124.     moveq    #1,d0
  3125.  
  3126. .End
  3127.     lea    100(sp),sp
  3128.     movem.l    (sp)+,d2-d4/a2-a4
  3129.     rts
  3130.  
  3131. .Str
  3132.  dc.b 'RESIDENTS:',10
  3133.  dc.b 'Address   Name               Flags Vers Type          Pri',10,0
  3134. .Fmt
  3135.  dc.b '$%08lx %-20.20s $%02lx %4ld %-12s %4ld',10,0
  3136.  
  3137.     cnop    0,2
  3138.  
  3139. ;------------------------------------------------------------------------------;
  3140.  
  3141. FreeInfo:
  3142. ;    a0=info
  3143.  
  3144.     move.l    a2,-(sp)
  3145.     move.l    a0,d0
  3146.     beq    .End
  3147.  
  3148. .Loop
  3149.     move.l    d0,a2
  3150.     move.l    4(a2),a1        ; memoryBlock
  3151.     bsr    OSFreeVec
  3152.     move.l    a2,a1            ; memoryBlock
  3153.     move.l    (a1),a2
  3154.     bsr    OSFreeVec
  3155.     move.l    a2,d0
  3156.     bne    .Loop
  3157.  
  3158. .End
  3159.     move.l    (sp)+,a2
  3160.     rts
  3161.  
  3162. ;------------------------------------------------------------------------------;
  3163.  
  3164. GetIBrd:
  3165.     movem.l    d2/a2/a3,-(sp)
  3166.     moveq    #0,d2
  3167.     sub.l    a2,a2
  3168.  
  3169. .Loop
  3170.     move.l    a2,a0            ; oldConfigDev
  3171.     moveq    #-1,d0            ; manufacturer
  3172.     moveq    #-1,d1            ; product
  3173.     move.l    a6,-(sp)
  3174.     move.l    _ExpansionBase(a5),a6
  3175.     jsr    -$0048(a6)        ; _LVOFindConfigDev
  3176.     move.l    (sp)+,a6
  3177.     tst.l    d0
  3178.     beq    .Ok
  3179.     move.l    d0,a2
  3180.  
  3181.     moveq    #ibrd_sizeof,d0        ; byteSize
  3182.     moveq    #0,d1            ; requirements, MEMF_ANY
  3183.     bsr    OSAllocVec
  3184.     tst.l    d0
  3185.     beq    .Err
  3186.  
  3187.     tst.l    d2
  3188.     bne    .Ok2
  3189.     move.l    d0,d2
  3190.     bra    .Ok3
  3191.  
  3192. .Ok2
  3193.     move.l    d0,(a3)            ; ibrd_next
  3194.  
  3195. .Ok3
  3196.     move.l    d0,a3
  3197.     clr.l    (a3)            ; ibrd_next
  3198.  
  3199.     clr.l    ibrd_name(a3)
  3200.     move.l    a2,ibrd_addr(a3)
  3201.     move.l    $0020(a2),ibrd_boardaddr(a3); cd_BoardAddr
  3202.     move.l    $0024(a2),ibrd_boardsize(a3); cd_BoardSize
  3203.     move    $0014(a2),ibrd_manufact(a3)
  3204.     move.b    $0011(a2),ibrd_product(a3)
  3205.     bra    .Loop
  3206.  
  3207. .Err
  3208.     move.l    d2,a0
  3209.     bsr    FreeInfo
  3210.     moveq    #-1,d2
  3211.  
  3212. .Ok
  3213.     move.l    d2,d0
  3214.     movem.l    (sp)+,d2/a2/a3
  3215.     rts
  3216.  
  3217. ;------------------------------------------------------------------------------;
  3218.  
  3219. GetIList:
  3220.     movem.l    d2/a2/a3,-(sp)
  3221.     moveq    #0,d2
  3222.     lea    (a6,d0),a2
  3223.     jsr    -$0084(a6)        ; _LVOForbid
  3224.  
  3225. .Loop
  3226.     move.l    (a2),a2
  3227.     tst.l    (a2)
  3228.     beq    .Ok
  3229.  
  3230.     moveq    #ilib_sizeof,d0        ; byteSize
  3231.     moveq    #0,d1            ; requirements, MEMF_ANY
  3232.     bsr    OSAllocVec
  3233.     tst.l    d0
  3234.     beq    .Err
  3235.  
  3236.     tst.l    d2
  3237.     bne    .Ok2
  3238.     move.l    d0,d2
  3239.     bra    .Ok3
  3240.  
  3241. .Ok2
  3242.     move.l    d0,(a3)            ; ilib_next
  3243.  
  3244. .Ok3
  3245.     move.l    d0,a3
  3246.     clr.l    (a3)            ; ilib_next
  3247.  
  3248.     move.l    a2,ilib_addr(a3)
  3249.     move.l    $0010(a2),ilib_neg(a3)    ; lib_NegSize/lib_PosSize
  3250.     move.l    $0014(a2),ilib_ver(a3)    ; lib_Revision/lib_Version
  3251.     move    $0020(a2),ilib_opn(a3)    ; lib_OpenCnt
  3252.     move.l    a2,a1            ; address
  3253.     bsr    MyTypeOfMem
  3254.     move.b    d0,ilib_mem(a3)
  3255.     move.b    $0009(a2),ilib_pri(a3)    ; ln_Pri
  3256.  
  3257.     move.l    a2,a0
  3258.     bsr    GetIName
  3259.     move.l    d0,ilib_name(a3)
  3260.     beq    .Loop
  3261.     addq.l    #1,d0
  3262.     bne    .Loop
  3263.  
  3264. .Err
  3265.     jsr    -$008A(a6)        ; _LVOPermit
  3266.     move.l    d2,a0
  3267.     bsr    FreeInfo
  3268.     moveq    #-1,d2
  3269.     bra    .Done
  3270.  
  3271. .Ok
  3272.     jsr    -$008A(a6)        ; _LVOPermit
  3273.  
  3274. .Done
  3275.     move.l    d2,d0
  3276.     movem.l    (sp)+,d2/a2/a3
  3277.     rts
  3278.  
  3279. ;------------------------------------------------------------------------------;
  3280.  
  3281. GetIMem:
  3282.     movem.l    d2/a2/a3,-(sp)
  3283.     moveq    #0,d2
  3284.     lea    $0142(a6),a2        ; MemList
  3285.     jsr    -$0084(a6)        ; _LVOForbid
  3286.  
  3287. .Loop
  3288.     move.l    (a2),a2
  3289.     tst.l    (a2)
  3290.     beq    .Ok
  3291.  
  3292.     moveq    #imem_sizeof,d0        ; byteSize
  3293.     moveq    #0,d1            ; requirements, MEMF_ANY
  3294.     bsr    OSAllocVec
  3295.     tst.l    d0
  3296.     beq    .Err
  3297.  
  3298.     tst.l    d2
  3299.     bne    .Ok2
  3300.     move.l    d0,d2
  3301.     bra    .Ok3
  3302.  
  3303. .Ok2
  3304.     move.l    d0,(a3)            ; imem_next
  3305.  
  3306. .Ok3
  3307.     move.l    d0,a3
  3308.     clr.l    (a3)            ; imem_next
  3309.  
  3310.     move.l    a2,imem_addr(a3)
  3311.     move.l    $0014(a2),imem_lower(a3); mh_Lower
  3312.     move.l    $0018(a2),imem_upper(a3); mh_Upper
  3313.     move    $000E(a2),imem_type(a3)    ; mh_Attributes
  3314.     move.b    $0009(a2),imem_pri(a3)    ; ln_Pri
  3315.  
  3316.     move.l    a2,a0
  3317.     bsr    GetIName
  3318.     move.l    d0,imem_name(a3)
  3319.     beq    .Loop
  3320.     addq.l    #1,d0
  3321.     bne    .Loop
  3322.  
  3323. .Err
  3324.     jsr    -$008A(a6)        ; _LVOPermit
  3325.     move.l    d2,a0
  3326.     bsr    FreeInfo
  3327.     moveq    #-1,d2
  3328.     bra    .Done
  3329.  
  3330. .Ok
  3331.     jsr    -$008A(a6)        ; _LVOPermit
  3332.  
  3333. .Done
  3334.     move.l    d2,d0
  3335.     movem.l    (sp)+,d2/a2/a3
  3336.     rts
  3337.  
  3338. ;------------------------------------------------------------------------------;
  3339.  
  3340. GetIName:
  3341. ;    a0=node
  3342.  
  3343.     move.l    a2,-(sp)
  3344.     move.l    a0,a2
  3345.  
  3346.     move.l    $000A(a2),d0        ; ln_Name
  3347.     beq    .End
  3348.  
  3349.     move.l    d0,a0            ; string
  3350.     bsr    StrLen
  3351.     tst.l    d0
  3352.     beq    .End
  3353.  
  3354.     addq.l    #1,d0            ; byteSize
  3355.     moveq    #1,d1            ; requirements, MEMF_PUBLIC
  3356.     bsr    OSAllocVec
  3357.     tst.l    d0
  3358.     beq    .Err
  3359.  
  3360.     move.l    $000A(a2),a0        ; string, ln_Name
  3361.     move.l    d0,a1            ; dest
  3362.     move.l    d0,a2
  3363.     bsr    StrCpy
  3364.     move.l    a2,d0
  3365.  
  3366. .End
  3367.     move.l    (sp)+,a2
  3368.     rts
  3369.  
  3370. .Err
  3371.     moveq    #-1,d0
  3372.     bra    .End
  3373.  
  3374. ;------------------------------------------------------------------------------;
  3375.  
  3376. GetMemStr:
  3377.     lea    Strfast(pc),a0
  3378.     btst    #2,d0
  3379.     bne    .Ok
  3380.     lea    Strchip(pc),a0
  3381.     btst    #1,d0
  3382.     bne    .Ok
  3383.     lea    Strslow(pc),a0
  3384.     btst    #0,d0
  3385.     bne    .Ok
  3386.     lea    Strchip(pc),a0
  3387.  
  3388. .Ok
  3389.     move.l    a0,d0
  3390.     rts
  3391.  
  3392. ;------------------------------------------------------------------------------;
  3393.  
  3394. GetTypeString:
  3395. ;    d0=type
  3396.  
  3397.     lea    Strunknown(pc),a0
  3398.     tst.b    d0
  3399.     beq    .Ok
  3400.     lea    Strtask(pc),a0
  3401.     subq.b    #1,d0
  3402.     beq    .Ok
  3403.     lea    Strinterrupt(pc),a0
  3404.     subq.b    #1,d0
  3405.     beq    .Ok
  3406.     lea    Strdevice(pc),a0
  3407.     subq.b    #1,d0
  3408.     beq    .Ok
  3409.     lea    Strmsgport(pc),a0
  3410.     subq.b    #1,d0
  3411.     beq    .Ok
  3412.     lea    Strmessage(pc),a0
  3413.     subq.b    #1,d0
  3414.     beq    .Ok
  3415.     lea    Strfreemsg(pc),a0
  3416.     subq.b    #1,d0
  3417.     beq    .Ok
  3418.     lea    Strreplymsg(pc),a0
  3419.     subq.b    #1,d0
  3420.     beq    .Ok
  3421.     lea    Strresource(pc),a0
  3422.     subq.b    #1,d0
  3423.     beq    .Ok
  3424.     lea    Strlibrary(pc),a0
  3425.     subq.b    #1,d0
  3426.     beq    .Ok
  3427.     lea    Strmemory(pc),a0
  3428.     subq.b    #1,d0
  3429.     beq    .Ok
  3430.     lea    Strsoftint(pc),a0
  3431.     subq.b    #1,d0
  3432.     beq    .Ok
  3433.     lea    Strfont(pc),a0
  3434.     subq.b    #1,d0
  3435.     beq    .Ok
  3436.     lea    Strprocess(pc),a0
  3437.     subq.b    #1,d0
  3438.     beq    .Ok
  3439.     lea    Strsemaphore(pc),a0
  3440.     subq.b    #1,d0
  3441.     beq    .Ok
  3442.     lea    Strsignalsem(pc),a0
  3443.     subq.b    #1,d0
  3444.     beq    .Ok
  3445.     lea    Strbootnode(pc),a0
  3446.     subq.b    #1,d0
  3447.     beq    .Ok
  3448.     lea    Strkickmem(pc),a0
  3449.     subq.b    #1,d0
  3450.     beq    .Ok
  3451.     lea    Strgraphics(pc),a0
  3452.     subq.b    #1,d0
  3453.     beq    .Ok
  3454.     lea    Strdeathmessage(pc),a0
  3455.     subq.b    #1,d0
  3456.     beq    .Ok
  3457.     sub.l    a0,a0
  3458.  
  3459. .Ok
  3460.     move.l    a0,d0
  3461.     rts
  3462.  
  3463. ;------------------------------------------------------------------------------;
  3464.  
  3465. Usage:
  3466.     lea    TxtUsage(pc),a0        ; string
  3467.     moveq    #0,d0
  3468.     bsr    PutS
  3469.     bra    Quit
  3470.  
  3471. ;------------------------------------------------------------------------------;
  3472. ;------------------------------------------------------------------------------;
  3473. ;------------------------------------------------------------------------------;
  3474.  
  3475. AddResident:
  3476. ; out    d0=output from MakeResident()
  3477. ;    -2=FindResident("expansion.library") failed.
  3478.  
  3479.     movem.l    d2-d4/a2,-(sp)
  3480.  
  3481.     lea    expansion_library(pc),a1; name
  3482.     jsr    -$0060(a6)        ; _LVOFindResident
  3483.     tst.l    d0
  3484.     beq    .Err
  3485.     move.l    d0,a0
  3486.     move.b    $000D(a0),d4        ; pri, rt_Pri
  3487.     moveq    #0,d0
  3488.     addq.b    #1,d4
  3489.  
  3490.     lea    Resident(pc),a0        ; code
  3491.     lea    FastExecName(pc),a1    ; name
  3492.     lea    FastExecId(pc),a2    ; idString
  3493.     move.l    #ResEnd-Resident,d0    ; size
  3494.     moveq    #1,d1            ; flags, RTF_COLDSTART
  3495.     moveq    #2,d2            ; version
  3496.     moveq    #0,d3            ; type
  3497.     bsr    MakeResident
  3498.  
  3499. .End
  3500.     movem.l    (sp)+,d2-d4/a2
  3501.     rts
  3502.  
  3503. .Err
  3504.     moveq    #-2,d0
  3505.     bra    .End
  3506.  
  3507. ;------------------------------------------------------------------------------;
  3508.  
  3509. ;ASCII To Integer
  3510.  
  3511. AToI:
  3512.     move.l    d2,a1
  3513.     moveq    #0,d0
  3514.     moveq    #0,d1
  3515.  
  3516. .Loop
  3517.     move.b    (a0)+,d1
  3518.     sub.b    #'0',d1
  3519.     cmp.b    #9,d1
  3520.     bhi    .Quit
  3521.  
  3522.     add.l    d0,d0
  3523.     move.l    d0,d2
  3524.     lsl.l    #2,d0
  3525.     add.l    d2,d0
  3526.  
  3527.     add.l    d1,d0
  3528.     bra    .Loop
  3529.  
  3530. .Quit
  3531.     move.l    a1,d2
  3532.     rts
  3533.  
  3534. ;------------------------------------------------------------------------------;
  3535.  
  3536. FindArg:
  3537. ;    a0=args
  3538. ;    a1=arg
  3539.  
  3540.     movem.l    a2/a3,-(sp)
  3541.     move.l    a0,a2
  3542.     move.l    a1,a3
  3543.  
  3544. .Loop
  3545.     move.l    (a2)+,d0
  3546.     beq    .Quit
  3547.     move.l    d0,a0
  3548.     move.l    a3,a1
  3549.     bsr    OSStricmp
  3550.     tst.l    d0
  3551.     bne    .Loop
  3552.  
  3553.     move.l    (a2),d0
  3554.     bne    .Quit
  3555.     moveq    #1,d0
  3556.  
  3557. .Quit
  3558.     movem.l    (sp)+,a2/a3
  3559.     rts
  3560.  
  3561. ;------------------------------------------------------------------------------;
  3562.  
  3563. FindKickTag:
  3564. ;    a1=name
  3565.  
  3566.     movem.l    a2/a3,-(sp)
  3567.     move.l    a1,a3
  3568.  
  3569.     move.l    $0226(a6),d0        ; KickTagPtr
  3570.     beq    .End
  3571.     move.l    d0,a2
  3572.  
  3573. .Loop
  3574.     move.l    (a2)+,d0
  3575.     beq    .End
  3576.     bpl    .Ok
  3577.     bclr    #31,d0
  3578.     move.l    d0,a2
  3579.     bra    .Loop
  3580.  
  3581. .Ok
  3582.     move.l    d0,a0
  3583.     move.l    $000E(a0),d0        ; rt_Name
  3584.     beq    .Loop
  3585.     move.l    d0,a0            ; string1
  3586.     move.l    a3,a1            ; string2
  3587.     bsr    StrCmp
  3588.     tst.l    d0
  3589.     bne    .Loop
  3590.     move.l    a2,d0
  3591.  
  3592. .End
  3593.     movem.l    (sp)+,a2/a3
  3594.     rts
  3595.  
  3596. ;------------------------------------------------------------------------------;
  3597.  
  3598. GetArgs:
  3599. ;    a0=dosCmdBuf
  3600. ; out    d0=args
  3601.  
  3602.     movem.l    d2/a2,-(sp)
  3603.     clr.l    -(sp)
  3604.  
  3605. .Loop1
  3606.     move.b    (a0)+,d0
  3607.     cmp.b    #10,d0
  3608.     beq    .Quit
  3609.     cmp.b    #';',d0
  3610.     beq    .Quit
  3611.     cmp.b    #' ',d0
  3612.     beq    .Loop1
  3613.     cmp.b    #9,d0
  3614.     beq    .Loop1
  3615.     cmp.b    #'"',d0
  3616.     beq    .Quot
  3617.  
  3618.     subq.l    #1,a0
  3619.     move.l    a0,-(sp)
  3620.  
  3621. .Loop2
  3622.     move.b    (a0)+,d0
  3623.     cmp.b    #10,d0
  3624.     beq    .Quit
  3625.     cmp.b    #';',d0
  3626.     beq    .Quit
  3627.     cmp.b    #' ',d0
  3628.     beq    .Next2
  3629.     cmp.b    #9,d0
  3630.     beq    .Next2
  3631.     cmp.b    #'=',d0
  3632.     bne    .Loop2
  3633.  
  3634. .Next2
  3635.     clr.b    -1(a0)
  3636.     bra    .Loop1
  3637.  
  3638. .Quot
  3639.     move.l    a0,-(sp)
  3640.  
  3641. .Loop3
  3642.     move.b    (a0)+,d0
  3643.     cmp.b    #10,d0
  3644.     beq    .Quit
  3645.     cmp.b    #'"',d0
  3646.     bne    .Loop3
  3647.     clr.b    -1(a0)
  3648.     bra    .Loop1
  3649.  
  3650. .Quit
  3651.     clr.b    -(a0)
  3652.     move.l    sp,a2
  3653.  
  3654. .Size
  3655.     tst.l    (a2)+
  3656.     bne    .Size
  3657.  
  3658.     move.l    a2,d0            ; byteSize
  3659.     sub.l    sp,d0
  3660.     move.l    d0,d2
  3661.     moveq    #0,d1            ; requirements, MEMF_ANY
  3662.     bsr    OSAllocVec
  3663.  
  3664.     move.l    d0,a0
  3665.     move.l    a2,a1
  3666.     subq.l    #4,a1
  3667.     subq.l    #4,d2
  3668.     lsr.l    #2,d2
  3669.     bra    .Next
  3670.  
  3671. .Copy
  3672.     move.l    -(a1),(a0)+
  3673.  
  3674. .Next
  3675.     dbf    d2,.Copy
  3676.     clr.l    (a0)
  3677.  
  3678.     move.l    a2,sp
  3679.     movem.l    (sp)+,d2/a2
  3680.     rts
  3681.  
  3682. ;------------------------------------------------------------------------------;
  3683.  
  3684. ;Hex To Integer
  3685.  
  3686. HToI:
  3687.     moveq    #0,d0
  3688.     moveq    #0,d1
  3689.  
  3690. .Loop
  3691.     move.b    (a0)+,d1
  3692.  
  3693.     cmp.b    #'0',d1
  3694.     bcs    .Rts
  3695.     cmp.b    #'9',d1
  3696.     bhi    .2
  3697.     sub.b    #'0',d1
  3698.     bra    .Next
  3699.  
  3700. .2
  3701.     cmp.b    #'A',d1
  3702.     bcs    .Rts
  3703.     cmp.b    #'F',d1
  3704.     bhi    .3
  3705.     sub.b    #$37,d1
  3706.     bra    .Next
  3707.  
  3708. .3
  3709.     cmp.b    #'a',d1
  3710.     bcs    .Rts
  3711.     cmp.b    #'f',d1
  3712.     bhi    .Rts
  3713.     sub.b    #$57,d1
  3714. ;    bra    .Next
  3715.  
  3716. .Next
  3717.     lsl.l    #4,d0
  3718.     add.l    d1,d0
  3719.     bra    .Loop
  3720.  
  3721. .Rts
  3722.     rts
  3723.  
  3724. ;------------------------------------------------------------------------------;
  3725.  
  3726. MakeResident:
  3727. ;    a0=code
  3728. ;    a1=name
  3729. ;    a2=idString
  3730. ;    d0=size
  3731. ;    d1=flags
  3732. ;    d2=version
  3733. ;    d3=type
  3734. ;    d4=pri
  3735. ; out    d0=-1:already installed, 0:out of memory, 1:okay
  3736.  
  3737.     movem.l    d2-d7/a2-a4,-(sp)
  3738.     move.b    d1,d7
  3739.     lsl.l    #8,d7
  3740.     move.b    d2,d7
  3741.     lsl.l    #8,d7
  3742.     move.b    d3,d7
  3743.     lsl.l    #8,d7
  3744.     move.b    d4,d7
  3745.     move.l    a2,d4
  3746.     move.l    a1,d3
  3747.     move.l    a0,d2
  3748.     move.l    d0,d6
  3749.  
  3750. ;    move.l    #0,a1            ; name
  3751.     bsr    FindKickTag
  3752.     tst.l    d0
  3753.     bne    .Err
  3754.  
  3755.     moveq    #$003A,d0        ; sizeof(MemList)+8+sizeof(Resident)
  3756.     add.l    d6,d0            ; byteSize
  3757.     move.l    #$00050401,d1        ; requirements, MEMF_PUBLIC!MEMF_KICK!MEMF_CLEAR!MEMF_REVERSE
  3758.     bsr    OSAllocMem
  3759.     tst.l    d0
  3760.     beq    .End
  3761.     move.l    d0,a2
  3762.     lea    $0020(a2),a3        ; sizeof(MemList)+8
  3763.     lea    $001A(a3),a4        ; sizeof(Resident)
  3764.  
  3765.     move.l    d2,a0            ; source
  3766.     move.l    a4,a1            ; dest
  3767.     move.l    d6,d0            ; size
  3768.     jsr    -$0276(a6)        ; _LVOCopyMemQuick
  3769.  
  3770.     move    #$4AFC,(a3)        ; rt_MatchWord
  3771.     move.l    a3,$0002(a3)        ; rt_MatchTag
  3772.     lea    (a4,d6.l),a0
  3773.     move.l    a0,$0006(a3)        ; rt_EndSkip
  3774.     move.l    d7,$000A(a3)        ; rt_Flags/rt_Version/rt_Type/rt_Pri
  3775.  
  3776.     move.l    d3,d0
  3777.     beq    .Name
  3778.     sub.l    d2,d0
  3779.     add.l    a4,d0
  3780.  
  3781. .Name
  3782.     move.l    d0,$000E(a3)        ; rt_Name
  3783.  
  3784.     move.l    d4,d0
  3785.     beq    .ID
  3786.     sub.l    d2,d0
  3787.     add.l    a4,d0
  3788.  
  3789. .ID
  3790.     move.l    d0,$0012(a3)        ; rt_IdString
  3791.     move.l    a4,$0016(a3)        ; rt_Init
  3792.  
  3793.     jsr    -$0084(a6)        ; _LVOForbid
  3794.     moveq    #0,d0            ; cacheBits
  3795.     moveq    #-1,d1            ; cacheMask
  3796.     bsr    OSCacheControl
  3797.     move.l    d0,-(sp)
  3798.  
  3799.     move.l    a2,a0            ; ptr
  3800.     moveq    #$003A,d0        ; sizeof(MemList)+8+sizeof(Resident)
  3801.     add.l    d6,d0            ; size
  3802.     bsr    SetKickMemPtr
  3803.  
  3804.     lea    $0018(a2),a0        ; ptr, sizeof(MemList)
  3805.     move.l    a3,(a0)
  3806.     clr.l    4(a0)
  3807.     bsr    SetKickTagPtr
  3808.  
  3809.     move.l    (sp)+,d0        ; cacheBits
  3810.     moveq    #-1,d1            ; cacheMask
  3811.     bsr    OSCacheControl
  3812.     jsr    -$008A(a6)        ; _LVOPermit
  3813.  
  3814.     moveq    #1,d0
  3815.  
  3816. .End
  3817.     movem.l    (sp)+,d2-d7/a2-a4
  3818.     rts
  3819.  
  3820. .Err
  3821.     moveq    #-1,d0
  3822.     bra    .End
  3823.  
  3824. ;------------------------------------------------------------------------------;
  3825.  
  3826.     cnop    0,4
  3827.  
  3828. OSAllocMem:
  3829.     cmp    #39,$0014(a6)        ; lib_Version
  3830.     bcs    .Old
  3831.  
  3832. .OS
  3833.     jmp    -$00C6(a6)        ; _LVOAllocMem
  3834.  
  3835. .Old
  3836.     bclr    #10,d1            ; MEMB_KICK
  3837.     beq    .OS
  3838.     or    #$0002,d1        ; MEMF_CHIP
  3839.  
  3840.     btst    #18,d1            ; MEMB_REVERSE
  3841.     beq    .OS
  3842.  
  3843.     movem.l    d2/d3,-(sp)
  3844.     move.l    d0,d3
  3845.     beq    .End
  3846.  
  3847.     move.l    d1,d2
  3848.     lea    $0142(a6),a0        ; MemList
  3849.     jsr    -$0084(a6)        ; _LVOForbid
  3850.  
  3851. .Loop
  3852.     move.l    (a0),a0            ; mc_Next
  3853.     tst.l    (a0)            ; mc_Next
  3854.     beq    .Err
  3855.  
  3856.     move    $000E(a0),d0        ; mh_Attributes
  3857.     and    d2,d0
  3858.     cmp    d2,d0
  3859.     bne    .Loop
  3860.  
  3861.     cmp.l    $001C(a0),d3        ; mh_Free
  3862.     bhi    .Loop
  3863.  
  3864.     btst    #18,d2            ; MEMB_REVERSE
  3865.     bne    .Reverse
  3866.  
  3867. ;    move.l    #0,a0            ; freeList
  3868.     move.l    d3,d0            ; byteSize
  3869.     jsr    -$00BA(a6)        ; _LVOAllocate
  3870.     tst.l    d0
  3871.     beq    .Loop
  3872.  
  3873. .Quit
  3874.     jsr    -$008A(a6)        ; _LVOPermit
  3875.     btst    #16,d2            ; MEMB_CLEAR
  3876.     beq    .End
  3877.  
  3878.     moveq    #0,d1
  3879.     move.l    d0,a0
  3880.     addq.l    #7,d3
  3881.     lsr.l    #3,d3
  3882.     move    d3,d2
  3883.     swap    d3
  3884.     bra    .Next
  3885.  
  3886. .Clear
  3887.     move.l    d1,(a0)+
  3888.     move.l    d1,(a0)+
  3889.  
  3890. .Next
  3891.     dbf    d2,.Clear
  3892.     dbf    d3,.Clear
  3893.  
  3894. .End
  3895.     movem.l    (sp)+,d2/d3
  3896.     rts
  3897.  
  3898. .Err
  3899.     jsr    -$008A(a6)        ; _LVOPermit
  3900.     moveq    #0,d0
  3901.     bra    .End
  3902.  
  3903. .Reverse
  3904.     moveq    #0,d1
  3905.     move.l    $0010(a0),d0        ; mh_First
  3906.     beq    .Loop
  3907.  
  3908. .Loop2
  3909.     move.l    d0,a1
  3910.     cmp.l    $0004(a1),d3        ; mc_Next
  3911.     bhi    .Ok2
  3912.     move.l    a1,d1
  3913.  
  3914. .Ok2
  3915.     move.l    (a1),d0            ; mc_Next
  3916.     bne    .Loop2
  3917.  
  3918.     tst.l    d1
  3919.     beq    .Loop
  3920.  
  3921.     move.l    d1,a1
  3922.     move.l    $0004(a1),d0        ; mc_Bytes
  3923.     sub.l    d3,d0
  3924.     and    #-8,d0
  3925.     add.l    d0,a1            ; location
  3926.     move.l    d3,d0            ; byteSize
  3927.     jsr    -$00CC(a6)        ; _LVOAllocAbs
  3928.     bra    .Quit
  3929.  
  3930. ;------------------------------------------------------------------------------;
  3931.  
  3932.     cnop    0,4
  3933.  
  3934. OSAllocVec:
  3935.     cmp    #36,$0014(a6)        ; lib_Version
  3936.     bcs    .Old
  3937.     jmp    -$02AC(a6)        ; _LVOAllocVec
  3938.  
  3939. .Old
  3940.     tst.l    d0
  3941.     beq    .Rts
  3942.  
  3943.     addq.l    #4,d0            ; byteSize
  3944.     move.l    d0,-(sp)
  3945.     jsr    -$00C6(a6)        ; _LVOAllocMem
  3946.     move.l    (sp)+,d1
  3947.     tst.l    d0
  3948.     beq    .Rts
  3949.  
  3950.     move.l    d0,a0
  3951.     move.l    d1,(a0)+
  3952.     move.l    a0,d0
  3953.  
  3954. .Rts
  3955.     rts
  3956.  
  3957. ;------------------------------------------------------------------------------;
  3958.  
  3959.     cnop    0,4
  3960.  
  3961. OSCheckSignal:
  3962.     cmp    #36,$0014(a6)        ; lib_Version
  3963.     bcs    .Old
  3964.  
  3965.     move.l    a6,-(sp)
  3966.     move.l    _DOSBase(a5),a6
  3967.     jsr    -$0318(a6)        ; _LVOCheckSignal
  3968.     move.l    (sp)+,a6
  3969.     rts
  3970.  
  3971. .Old
  3972.     move.l    d1,-(sp)
  3973.     moveq    #0,d0            ; newSignals
  3974.     jsr    -$0132(a6)        ; _LVOSetSignal
  3975.     and.l    (sp)+,d0
  3976.     rts
  3977.  
  3978. ;------------------------------------------------------------------------------;
  3979.  
  3980.     cnop    0,4
  3981.  
  3982. OSCloseLibrary:
  3983.     move.l    a1,d0
  3984.     beq    .Rts
  3985.     jmp    -$019E(a6)        ; _LVOCloseLibrary
  3986.  
  3987. .Rts
  3988.     rts
  3989.  
  3990. ;------------------------------------------------------------------------------;
  3991.  
  3992.     cnop    0,4
  3993.  
  3994. OSColdReboot:
  3995.     cmp    #36,$0014(a6)        ; lib_Version
  3996.     bcs    .Old
  3997.     jmp    -$02D6(a6)        ; _LVOColdReboot
  3998.  
  3999. .Old
  4000.     lea    .Func(pc),a5        ; userFunction
  4001.     jsr    -$001E(a6)        ; _LVOSupervisor
  4002.     cnop    0,4
  4003.  
  4004. .Func
  4005.     lea    $01000000,a0
  4006.     sub.l    -$0014(a0),a0
  4007.     move.l    $0004(a0),a0
  4008.     subq.l    #2,a0
  4009.     reset
  4010.     jmp    (a0)
  4011.  
  4012. ;------------------------------------------------------------------------------;
  4013.  
  4014.     cnop    0,4
  4015.  
  4016. OSFreeArgs:
  4017.     cmp    #36,$0014(a6)        ; lib_Version
  4018.     bcs    .Rts
  4019.  
  4020.     move.l    a6,-(sp)
  4021.     move.l    _DOSBase(a5),a6
  4022.     jsr    -$035A(a6)        ; _LVOFreeArgs
  4023.     move.l    (sp)+,a6
  4024.  
  4025. .Rts
  4026.     rts
  4027.  
  4028. ;------------------------------------------------------------------------------;
  4029.  
  4030.     cnop    0,4
  4031.  
  4032. OSFreeVec:
  4033.     cmp    #36,$0014(a6)        ; lib_Version
  4034.     bcs    .Old
  4035.     jmp    -$02B2(a6)        ; _LVOFreeVec
  4036.  
  4037. .Old
  4038.     move.l    a1,d0
  4039.     beq    .Rts
  4040.     move.l    -(a1),d0        ; byteSize
  4041.     jmp    -$00D2(a6)        ; _LVOFreeMem
  4042.  
  4043. .Rts
  4044.     rts
  4045.  
  4046. ;------------------------------------------------------------------------------;
  4047.  
  4048.     cnop    0,4
  4049.  
  4050. OSPutStr:
  4051.     cmp    #36,$0014(a6)        ; lib_Version
  4052.     bcs    .Old
  4053.  
  4054.     move.l    a6,-(sp)
  4055.     move.l    _DOSBase(a5),a6
  4056.     jsr    -$03B4(a6)        ; _LVOPutStr
  4057.     move.l    (sp)+,a6
  4058.     rts
  4059.  
  4060. .Old
  4061.     movem.l    d2/d3/a6,-(sp)
  4062.     move.l    _DOSBase(a5),a6
  4063.     move.l    d1,d2            ; buffer
  4064.     beq    .Quit
  4065.     move.l    d2,a0            ; cstr
  4066.     bsr    StrLen
  4067.     move.l    d0,d3            ; length
  4068.     beq    .Quit
  4069.     jsr    -$003C(a6)        ; _LVOOutput
  4070.     move.l    d0,d1            ; file
  4071.     beq    .Quit
  4072.     jsr    -$0030(a6)        ; _LVOWrite
  4073.  
  4074. .Quit
  4075.     moveq    #0,d0
  4076.     movem.l    (sp)+,d2/d3/a6
  4077.     rts
  4078.  
  4079. ;------------------------------------------------------------------------------;
  4080.  
  4081.     cnop    0,4
  4082.  
  4083. OSStricmp:
  4084.     cmp    #37,$0014(a6)        ; lib_Version
  4085.     bcs    .Old
  4086.  
  4087.     move.l    a6,-(sp)
  4088.     move.l    _UtilityBase(a5),a6
  4089.     jsr    -$00A2(a6)        ; _LVOStricmp
  4090.     move.l    (sp)+,a6
  4091.     rts
  4092.  
  4093. .Old
  4094.     movem.l    d2/a2/a3,-(sp)
  4095.     move.l    a0,a2
  4096.     move.l    a1,a3
  4097.  
  4098. .Loop
  4099.     move.b    (a2)+,d0
  4100.     beq    .End0
  4101.  
  4102.     bsr    OSToUpper
  4103.     move.b    d0,d2
  4104.     move.b    (a3)+,d0
  4105.     beq    .End1
  4106.  
  4107.     bsr    OSToUpper
  4108.     cmp.b    d0,d2
  4109.     beq    .Loop
  4110.     bcc    .End1
  4111.  
  4112. .End2
  4113.     moveq    #-1,d0
  4114.     bra    .Quit
  4115.  
  4116. .End1
  4117.     moveq    #1,d0
  4118.     bra    .Quit
  4119.  
  4120. .End0
  4121.     tst.b    (a3)
  4122.     bne    .End2
  4123.     moveq    #0,d0
  4124.  
  4125. .Quit
  4126.     movem.l    (sp)+,d2/a2/a3
  4127.     rts
  4128.  
  4129. ;------------------------------------------------------------------------------;
  4130.  
  4131.     cnop    0,4
  4132.  
  4133. OSToUpper:
  4134.     cmp    #37,$0014(a6)        ; lib_Version
  4135.     bcs    .Old
  4136.  
  4137.     move.l    a6,-(sp)
  4138.     move.l    _UtilityBase(a5),a6
  4139.     jsr    -$00AE(a6)        ; _LVOToUpper
  4140.     move.l    (sp)+,a6
  4141.     rts
  4142.  
  4143. .Old
  4144.     and.l    #$FF,d0
  4145.  
  4146.     cmp    #'a',d0
  4147.     bcs.s    .Rts
  4148.     cmp    #'z',d0
  4149.     bls.s    .Ok
  4150.  
  4151.     cmp    #'à',d0
  4152.     bcs.s    .Rts
  4153.     cmp    #'÷',d0
  4154.     beq.s    .Rts
  4155.     cmp    #'þ',d0
  4156.     bhi.s    .Rts
  4157.  
  4158. .Ok
  4159.     sub    #32,d0
  4160.  
  4161. .Rts
  4162.     rts
  4163.  
  4164. ;------------------------------------------------------------------------------;
  4165.  
  4166. Put:
  4167. ;    a0=buffer
  4168.  
  4169.     movem.l    d2/a2,-(sp)
  4170.     move.l    a0,a2
  4171.  
  4172. .Loop
  4173.     move.l    a2,a0            ; string
  4174.  
  4175. .Loop2
  4176.     cmp.b    #10,(a2)+
  4177.     bne    .Loop2
  4178.     move.b    (a2),d2
  4179.     clr.b    (a2)
  4180.     moveq    #1,d0
  4181.     bsr    PutS
  4182.     move.b    d2,(a2)
  4183.     tst.l    d0
  4184.     beq    .End
  4185.     tst.b    d2
  4186.     bne    .Loop
  4187.     moveq    #1,d0
  4188.  
  4189. .End
  4190.     movem.l    (sp)+,d2/a2
  4191.     rts
  4192.  
  4193. ;------------------------------------------------------------------------------;
  4194.  
  4195. PutChProc:
  4196.     move.b    d0,(a3)+
  4197.     rts
  4198.  
  4199. ;------------------------------------------------------------------------------;
  4200.  
  4201. PutLF:
  4202.     pea    $0A000000
  4203.     move.l    sp,d1            ; str
  4204.     bsr    OSPutStr
  4205.     addq.l    #4,sp
  4206.     rts
  4207.  
  4208. ;------------------------------------------------------------------------------;
  4209.  
  4210. PutS:
  4211. ;    a0=string
  4212. ;    d0=check ctrl-c
  4213. ; out    d0=1:continue/0:break
  4214.  
  4215.     tst.l    d0
  4216.     beq    .Ok
  4217.  
  4218.     moveq    #1,d1            ; mask
  4219.     ror    #4,d1            ; SIGBREAKF_CTRL_C
  4220.     move.l    a0,-(sp)
  4221.     bsr    OSCheckSignal
  4222.     move.l    (sp)+,a0
  4223.     tst.l    d0
  4224.     bne    .Err
  4225.  
  4226. .Ok
  4227.     move.l    a0,d1            ; str
  4228.     bsr    OSPutStr
  4229.     moveq    #1,d0
  4230.     rts
  4231.  
  4232. .Err
  4233.     lea    .Str(pc),a0
  4234.     move.l    a0,d1            ; str
  4235.     bsr    OSPutStr
  4236.     moveq    #0,d0
  4237.     rts
  4238.  
  4239. .Str
  4240.     dc.b    '***Break',10,0
  4241.     cnop    0,2
  4242.  
  4243. ;------------------------------------------------------------------------------;
  4244.  
  4245. SetKickMemPtr:
  4246. ;    a0=ptr
  4247. ;    d0=size
  4248.  
  4249.     lea    $000E(a0),a1        ; ml_NumEntries
  4250.     move    #1,(a1)+
  4251.     move.l    a0,(a1)+
  4252.     move.l    d0,(a1)
  4253.  
  4254.     move.l    $0222(a6),(a0)        ; KickMemPtr
  4255.     move.l    a0,$0222(a6)        ; KickMemPtr
  4256.  
  4257.     jsr    -$0264(a6)        ; _LVOSumKickData
  4258.     move.l    d0,$022A(a6)        ; KickCheckSum
  4259.     bra    OSCacheClearU
  4260.  
  4261. ;------------------------------------------------------------------------------;
  4262.  
  4263. SetKickTagPtr:
  4264. ;    a0=ptr
  4265.  
  4266.     move.l    a0,a1
  4267.  
  4268. .Loop
  4269.     move.l    (a1)+,d0
  4270.     beq    .Ok
  4271.     bpl    .Loop
  4272.     bclr    #31,d0
  4273.     move.l    d0,a1
  4274.     bra    .Loop
  4275.  
  4276. .Ok
  4277.     subq.l    #4,a1
  4278.  
  4279.     move.l    $0226(a6),d0        ; KickTagPtr
  4280.     beq    .Tag
  4281.     bset    #31,d0
  4282.     move.l    d0,(a1)
  4283.  
  4284. .Tag
  4285.     move.l    a0,$0226(a6)        ; KickTagPtr
  4286.     jsr    -$0264(a6)        ; _LVOSumKickData
  4287.     move.l    d0,$022A(a6)        ; KickCheckSum
  4288.     bra    OSCacheClearU
  4289.  
  4290. ;------------------------------------------------------------------------------;
  4291.  
  4292. SetWindowPtr:
  4293. ;    d0=ptr
  4294. ; out    d0=old ptr
  4295.  
  4296.     move.l    d0,-(sp)
  4297.     sub.l    a1,a1            ; name
  4298.     jsr    -$0126(a6)        ; _LVOFindTask
  4299.     move.l    d0,a0
  4300.     move.l    $00B8(a0),d0        ; pr_WindowPtr
  4301.     move.l    (sp)+,$00B8(a0)        ; pr_WindowPtr
  4302.     rts
  4303.  
  4304. ;------------------------------------------------------------------------------;
  4305.  
  4306. StrCpy:
  4307. ;    a0=string
  4308. ;    a1=dest
  4309.  
  4310.     move.b    (a0)+,(a1)+
  4311.     bne    StrCpy
  4312.     rts
  4313.  
  4314. ;------------------------------------------------------------------------------;
  4315.  
  4316. StrLen:
  4317. ;    a0=string
  4318. ; out    d0=length
  4319.  
  4320.     move.l    a0,d0
  4321.     addq.l    #1,d0
  4322.  
  4323. .Loop
  4324.     tst.b    (a0)+
  4325.     bne    .Loop
  4326.     sub.l    d0,a0
  4327.     move.l    a0,d0
  4328.     rts
  4329.  
  4330. ;------------------------------------------------------------------------------;
  4331.  
  4332. StrCmp:
  4333. ;    a0=string1
  4334. ;    a1=string2
  4335.  
  4336.     move.b    (a0)+,d0
  4337.     beq    .End0
  4338.     move.b    (a1)+,d1
  4339.     beq    .End1
  4340.     cmp.b    d0,d1
  4341.     beq    StrCmp
  4342.     bcc    .End1
  4343.  
  4344. .End2
  4345.     moveq    #-1,d0
  4346.     rts
  4347.  
  4348. .End1
  4349.     moveq    #1,d0
  4350.     rts
  4351.  
  4352. .End0
  4353.     tst.b    (a1)+
  4354.     bne    .End2
  4355.     moveq    #0,d0
  4356.     rts
  4357.  
  4358. ;------------------------------------------------------------------------------;
  4359.  
  4360. XToI:
  4361.     cmp.b    #'$',(a0)
  4362.     beq    .H
  4363. ;    cmp.b    #'%',(a0)
  4364. ;    beq    .B
  4365.     cmp.b    #'0',(a0)
  4366.     bne    AToI
  4367.     addq.l    #1,a0
  4368.     cmp.b    #'x',(a0)
  4369.     beq    .H
  4370.     cmp.b    #'X',(a0)
  4371.     bne    AToI
  4372.  
  4373. .H
  4374.     addq.l    #1,a0
  4375.     bra    HToI
  4376.  
  4377. ;.B
  4378. ;    addq.l    #1,a0
  4379. ;    bra    BToI
  4380.  
  4381. ;------------------------------------------------------------------------------;
  4382.  
  4383. XToIS:
  4384.     cmp.b    #'+',(a0)+
  4385.     beq    XToI
  4386.     cmp.b    #'-',-(a0)
  4387.     bne    XToI
  4388.     addq.l    #1,a0
  4389.     bsr    XToI
  4390.     neg.l    d0
  4391.     rts
  4392.  
  4393. ;------------------------------------------------------------------------------;
  4394. ;------------------------------------------------------------------------------;
  4395. ;------------------------------------------------------------------------------;
  4396.  
  4397. dos_library        dc.b 'dos.library',0
  4398. utility_library        dc.b 'utility.library',0
  4399. version_library        dc.b 'version.library',0
  4400.  
  4401. TxtAllocMem
  4402.     dc.b    'FastExec: Out of memory',10,0
  4403.  
  4404. TxtExpansion
  4405.     dc.b    'FastExec: Can''t find expansion.library in ResModules list',10,0
  4406.  
  4407. TxtExec
  4408.     dc.b    'FastExec: exec.library is already in fast memory - you don''t need this program',10,0
  4409.  
  4410. TxtAddMem
  4411.     dc.b    'FastExec: Bad arguments for ADDMEM option',10,0
  4412.  
  4413. Strchip            dc.b 'chip',0
  4414. Strfast            dc.b 'fast',0
  4415. Strslow            dc.b 'slow',0
  4416.  
  4417. Strunknown        dc.b 'unknown',0
  4418. Strtask            dc.b 'task',0
  4419. Strinterrupt        dc.b 'interrupt',0
  4420. Strdevice        dc.b 'device',0
  4421. Strmsgport        dc.b 'msgport',0
  4422. Strmessage        dc.b 'message',0
  4423. Strfreemsg        dc.b 'freemsg',0
  4424. Strreplymsg        dc.b 'replymsg',0
  4425. Strresource        dc.b 'resource',0
  4426. Strlibrary        dc.b 'library',0
  4427. Strmemory        dc.b 'memory',0
  4428. Strsoftint        dc.b 'softint',0
  4429. Strfont            dc.b 'font',0
  4430. Strprocess        dc.b 'process',0
  4431. Strsemaphore        dc.b 'semaphore',0
  4432. Strsignalsem        dc.b 'signalsem',0
  4433. Strbootnode        dc.b 'bootnode',0
  4434. Strkickmem        dc.b 'kickmem',0
  4435. Strgraphics        dc.b 'graphics',0
  4436. Strdeathmessage        dc.b 'deathmessage',0
  4437.  
  4438. Str68881        dc.b '68881',0
  4439. Str68882        dc.b '68882',0
  4440. StrFPU40        dc.b '68040 FPU',0
  4441. StrNONE            dc.b 'none',0
  4442.  
  4443. StrSYSINFO        dc.b 'SYSINFO',0
  4444. StrREBOOT        dc.b 'REBOOT',0
  4445. StrNOEXEC        dc.b 'NOEXEC',0
  4446. StrLOCAL        dc.b 'LOCAL',0
  4447. StrFASTSSP        dc.b 'FASTSSP',0
  4448. StrFASTVBR        dc.b 'FASTVBR',0
  4449. StrFASTEXP        dc.b 'FASTEXP',0
  4450. StrFASTMEM        dc.b 'FASTMEM',0
  4451. StrFASTINT        dc.b 'FASTINT',0
  4452. StrCACHE        dc.b 'CACHE',0
  4453. StrPATCH        dc.b 'PATCH',0
  4454. StrADDMEM        dc.b 'ADDMEM',0
  4455.  
  4456. ;------------------------------------------------------------------------------;
  4457.  
  4458. Template
  4459.     dc.b    'SYSINFO/S,REBOOT/S,NOEXEC/S,LOCAL/S,PATCH/S,FASTSSP/S,FASTVBR/S,FASTEXP/S,FASTMEM/S,FASTINT/S,CACHE/K,ADDMEM/K/M',0
  4460.  
  4461. ;------------------------------------------------------------------------------;
  4462.  
  4463. TxtUsage
  4464.  dc.b 'FastExec 2.6 (21.5.97)',10
  4465.  dc.b 'Torbjörn A. Andersson.',10
  4466.  dc.b 'Public Domain.',10
  4467.  dc.b 10
  4468.  dc.b 'Usage: FastExec [SYSINFO] [REBOOT] [NOEXEC] [LOCAL] [PATCH]',10
  4469.  dc.b '                [FASTSSP] [FASTVBR] [FASTEXP] [FASTMEM] [FASTINT]',10
  4470.  dc.b '                [CACHE 0xhhhhhhhh]',10
  4471.  dc.b '                [ADDMEM <base size attr pri> ...]',10
  4472.  dc.b 0
  4473.  
  4474. ;------------------------------------------------------------------------------;
  4475. ;------------------------------------------------------------------------------;
  4476. ;------------------------------------------------------------------------------;
  4477.  
  4478.     END
  4479.  
  4480. ;------------------------------------------------------------------------------;
  4481. ;------------------------------------------------------------------------------;
  4482. ;------------------------------------------------------------------------------;
  4483.