home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / Programming / TCS / demos / inc / shl_strtup.i < prev   
Encoding:
Text File  |  2000-09-26  |  6.1 KB  |  224 lines

  1. *******************************************************************************
  2. * shl_strtup.i 3.4.4
  3. *******************************************************************************
  4. * INFO    shell startup code; operations performed:
  5. *      1. opens all needed libraries
  6. *      2. if required, parses the command line with ReadArgs(): the
  7. *         arguments pointers are stored in CmdLnArgs (a buffer in
  8. *         dat.i); the template must be specified in the custom code
  9. *         at the label tmplt; the number of arguments must be set
  10. *         by the custom code with the constant ARGSNO (leave it
  11. *         undefined if you don't need parsing)
  12. *      3. initializes a TCS display
  13. *      4. calls the initialization routine of custom program
  14. *         [_PrgInit()] which must return ccr=eq on error
  15. *      5. turns off the OS
  16. *      6. takes control of the hardware
  17. *      7. activates the TCS display
  18. *      8. calls the main routine of custom program [_PrgMain()]
  19. *      9. hides the TCS display
  20. *     10. restores the hardware status
  21. *     11. re-activates the OS
  22. *     12. calls the cleanup routine of custom program [_PrgClnUp()]
  23. *         (this is called even if _PrgInit() failed)
  24. *     13. frees all the resources allocated
  25. * NOTE    no need of any include other than tcs.library's
  26. *******************************************************************************
  27.  
  28.  
  29.  
  30.     code
  31.  
  32. *******************************************************************************
  33. * open libs / command line parsing
  34.  
  35.     movea.l    4.w,a6
  36.     lea.l    DOSNm,a1
  37.     moveq.l    #37,d0
  38.     jsr    (-552,a6)    ;OpenLibrary(...)
  39.     move.l    d0,_DOSBase
  40.     beq    .exit
  41.     lea.l    GfxNm,a1
  42.     moveq.l    #37,d0
  43.     jsr    (-552,a6)    ;OpenLibrary(...)
  44.     move.l    d0,_GfxBase
  45.     beq    .ClsDOS
  46.     lea.l    TCSNm,a1
  47.     moveq.l    #1,d0
  48.     jsr    (-552,a6)    ;OpenLibrary(...)
  49.     move.l    d0,_TCSBase
  50.     beq.s    .ClsGfx
  51.  
  52.     ifd    ARGSNO
  53.     move.l    #tmplt,d1
  54.     move.l    #CmdLnArgs,d2
  55.     moveq.l    #0,d3
  56.     movea.l    _DOSBase,a6
  57.     jsr    (-798,a6)    ;ReadArgs(tmplt,CmdLnArgs,0)
  58.     move.l    d0,_RDArgs
  59.     beq    .ClsLibs
  60.     endif
  61.  
  62. *******************************************************************************
  63. * display/custom program initialization
  64.  
  65.     lea.l    DsplDef,a0    ;our TCS display
  66.     CALLTCS    InitDspl    ;initialize it
  67.     move.l    d0,DIAdr    ;keep its structure address
  68.     beq.s    .FreeArgs    ;in case of error...
  69.  
  70.     bsr    _PrgInit    ;custom init
  71.     beq.s    .PrgClnUp    ;if error...
  72.  
  73. *******************************************************************************
  74. * OS/HW takeover
  75.  
  76.     movea.l    _DOSBase,a6
  77.     moveq.l    #40,d1
  78.     jsr    (-198,a6)    ;Delay(40)
  79.  
  80.     bsr    TkSys    ;get OS and HW control
  81.  
  82. *******************************************************************************
  83. * start custom code
  84.  
  85.     movea.l    DIAdr,a0    ;our display
  86.     CALLTCS    ShwDspl    ;activate it!
  87.     beq    .RlsSys    ;if failed to (never should)...
  88.     jsr    _PrgMain    ;call custom code
  89.  
  90. *******************************************************************************
  91. * HW/OS restoration / custom program cleanup / resources release
  92.  
  93.     movea.l    DIAdr,a0    ;our display
  94.     CALLTCS    WtBltFRPass    ;wait for blitter to finish
  95.     movea.l    DIAdr,a0    ;our display
  96.     suba.l    a1,a1    ;don't show anything after
  97.     CALLTCS    HideDspl    ;hiding it
  98. .RlsSys    bsr    RlsSys    ;restore HW and OS status
  99.  
  100. .PrgClnUp    bsr    _PrgClnUp    ;custom cleanup
  101.  
  102.     movea.l    DIAdr,a0    ;our display
  103.     CALLTCS    FreeDspl    ;free its resources
  104.  
  105. .FreeArgs
  106.     ifd    ARGSNO
  107.     move.l    _RDArgs,d1
  108.     movea.l    _DOSBase,a6
  109.     jsr    (-858,a6)    ;FreeArgs(_RDArgs)
  110.     endif
  111.  
  112. .ClsLibs    movea.l    4.w,a6
  113.     movea.l    _TCSBase,a1
  114.     jsr    (-414,a6)    ;CloseLibrary(...)
  115. .ClsGfx    movea.l    _GfxBase,a1
  116.     jsr    (-414,a6)    ;CloseLibrary(...)
  117. .ClsDOS    movea.l    _DOSBase,a1
  118.     jsr    (-414,a6)    ;CloseLibrary(...)
  119.  
  120. .exit    moveq.l    #0,d0
  121.     rts
  122.  
  123.  
  124.  
  125. *******************************************************************************
  126. * TkSys 0.0.2
  127. *******************************************************************************
  128. * INFO    turns AmigaOS OFF and takes control of the hardware
  129. *******************************************************************************
  130.  
  131. TkSys    movem.l    d0-d7/a0-a6,-(sp)
  132.     movea.l    _GfxBase,a6
  133.     move.l    ($22,a6),_SysView    ;gb_ActiView
  134.     suba.l    a1,a1
  135.     jsr    (-222,a6)    ;LoadView(NULL)
  136.     jsr    (-270,a6)    ;WaitTOF()
  137.     jsr    (-270,a6)    ;WaitTOF()
  138.     jsr    (-456,a6)    ;OwnBlitter()
  139.     jsr    (-228,a6)    ;WaitBlit()
  140.  
  141.     movea.l    4.w,a6
  142.     jsr    (-132,a6)    ;Forbid()
  143.     jsr    (-120,a6)    ;Disable()
  144.  
  145.     move.w    $dff01c,_SysINTENA
  146.     move.w    #$7fff,$dff09a    ;clear INTENA.all
  147.     move.w    #$7fff,$dff09c    ;clear INTREQ.all
  148.     move.w    $dff002,_SysDMACON
  149.     move.w    #$7fff,$dff096    ;clear DMACON.all
  150.  
  151.     bsr    GetVBR
  152.     lea.l    ([_VBR.l],$64.w),a0    ;first autovector address
  153.     movem.l    (a0),d1-d7    ;get system autovectors 1-7
  154.     lea.l    _SysVecs,a0
  155.     movem.l    d1-d7,(a0)    ;store them
  156.  
  157.     movem.l    (sp)+,d0-d7/a0-a6
  158.     rts
  159.  
  160.  
  161.  
  162. *******************************************************************************
  163. * RlsSys 0.0.2
  164. *******************************************************************************
  165. * INFO    releases the hardware and turns AmigaOS ON
  166. *******************************************************************************
  167.  
  168. RlsSys    movem.l    d0-d7/a0-a6,-(sp)
  169.  
  170.     lea.l    _SysVecs,a0    ;get system
  171.     movem.l    (a0),d1-d7    ;autovectors
  172.     lea.l    ([_VBR.l],$64.w),a0    ;first autovector address
  173.     movem.l    d1-d7,(a0)    ;restore them
  174.  
  175.     move.w    #$7fff,$dff09a    ;clear INTENA.all
  176.     move.w    #$7fff,$dff09c    ;clear INTREQ.all
  177.     move.w    #$7fff,$dff096    ;clear DMACON.all
  178.     move.w    _SysDMACON,d0
  179.     ori.w    #$8000,d0
  180.     move.w    d0,$dff096    ;restore system DMACON
  181.     move.w    _SysINTENA,d0
  182.     ori.w    #$c000,d0
  183.     move.w    d0,$dff09a    ;restore system INTENA
  184.  
  185.     movea.l    4.w,a6
  186.     jsr    (-126,a6)    ;Enable()
  187.     jsr    (-138,a6)    ;Permit()
  188.  
  189.     movea.l    _GfxBase,a6
  190.     jsr    (-462,a6)    ;DisownBlitter()
  191.  
  192.     movea.l    _GfxBase,a6
  193.     movea.l    _SysView,a1
  194.     jsr    (-222,a6)    ;LoadView(_SysView)
  195.     jsr    (-270,a6)    ;WaitTOF()
  196.     jsr    (-270,a6)    ;WaitTOF()
  197.     move.l    ([_GfxBase.l],$26.w),$dff080 ;gb_copinit
  198.     move.w    #1,$dff088    ;restore system copperlist
  199.  
  200.     movem.l    (sp)+,d0-d7/a0-a6
  201.     rts
  202.  
  203.  
  204.  
  205. *******************************************************************************
  206. * GetVBR 0.0.0
  207. *******************************************************************************
  208. * INFO    retrieves the VBR
  209. * OUT    _VBR.l    variable holding the VBR
  210. *******************************************************************************
  211.  
  212. GetVBR    movem.l    a5-a6,-(sp)
  213.     movea.l    4.w,a6
  214.     btst.b    #0,($129,a6)
  215.     beq.s    .exit    ;if 68000...
  216.     lea.l    (_GetVBR,pc),a5
  217.     jsr    (-30,a6)    ;Supervisor()
  218. .exit    movem.l    (sp)+,a5-a6
  219.     rts
  220.  
  221. _GetVBR    dc.l    $4e7ad801    ;movec.l vbr,a5
  222.     move.l    a5,_VBR
  223.     rte
  224.