home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 7 / af007.adf / ArgAsm / Framework1.s < prev    next >
Text File  |  1987-08-27  |  4KB  |  142 lines

  1. *****************************************************************************
  2. *                                        *
  3. *    Amiga system takeover framework                        *
  4. *    1988 Dave Jones, DMA Design                              *
  5. *                                            *
  6. * Allows killing of system, allowing changing of all display & blitter        *
  7. * hardware, restoring to normal after exiting.                         *
  8. * Memory must still be properly allocated/deallocated upon entry/exit       *
  9. * DOS routines for loading must be called BEFORE killing the system           *
  10. *                                            *
  11. * Written using Devpac2                                    *
  12. *                                            *
  13. *****************************************************************************
  14.  
  15.     section    Framework,code_c    
  16.  
  17.  
  18. *** READ ME!! ***************************************************
  19. *
  20. *  I've changed Dave's original code to allow both ArgAsm and
  21. *  Devpac users to use this source code without modification.
  22. *  The include files included with ArgAsm are not the same as
  23. *  those found on the Devpac program disk, therefore several
  24. *  assignments need to be made to make things work.
  25. *
  26. *                                             - Jason H.
  27. *
  28. *****************************************************************
  29.  
  30.     ifd    __ArgAsm
  31.  
  32.     incdir          "include:"
  33.     include         exec/funcdef.i
  34.  
  35. _SysBase    equ    $04
  36.  
  37.     elseif
  38.  
  39.     incdir          "include/"
  40.  
  41.     endc
  42.  
  43. ** END OF CONDITIONAL STUFF *************************************
  44.  
  45.  
  46.     include     libraries/dos_lib.i
  47.     include     exec/exec_lib.i
  48.     include     hardware/custom.i
  49.  
  50. Hardware        equ    $dff000
  51. MemNeeded        equ    32000
  52. SystemCopper1    equ    $26
  53. SystemCopper2    equ    $32
  54. PortA        equ    $bfe001
  55. ICRA        equ    $bfed01
  56. LeftMouse        equ    6
  57.  
  58. *******************************************************************************
  59.  
  60. start    lea    GraphicsName(pc),a1    open the graphics library purely
  61.     move.l    _SysBase,a6        to find the system copper
  62.     clr.l    d0
  63.     jsr    _LVOOpenLibrary(a6)
  64.     move.l    d0,GraphicsBase
  65.     lea    DOSName(pc),a1        open the DOS library to allow
  66.     clr.l    d0            the loading of data before
  67.     jsr    _LVOOpenLibrary(a6)    killing the system
  68.     move.l    d0,DOSBase
  69.  
  70.     move.l    #MemNeeded,d0        properly allocate some chip
  71.     moveq.l    #2,d1            memory for screens etc.
  72.     jsr    _LVOAllocMem(a6)    d1 = 2, specifies chip memory
  73.     tst.l    d0            where screens,samples etc
  74.     beq    MemError        must be (bottom 512K)
  75.     move.l    d0,MemBase
  76.  
  77. *******************************************************************************
  78.  
  79.     move.l    #Hardware,a6        due to constant accessing
  80.     bsr    TakeSystem        of the hardware registers
  81. *                    it is better to offset
  82. wait    btst    #LeftMouse,PortA    them from a register for
  83.     bne    wait            speed & memory saving (a6)
  84.  
  85. *******************************************************************************
  86.  
  87.     bsr    FreeSystem
  88.  
  89.     move.l    _SysBase,a6
  90.     move.l    MemBase,a1
  91.     move.l    #MemNeeded,d0        free the memory we took
  92.     jsr    _LVOFreeMem(a6)
  93. MemError    move.l    GraphicsBase,a1    
  94.     jsr    _LVOCloseLibrary(a6)
  95.     move.l    DOSBase,a1        finally close the 
  96.     jsr    _LVOCloseLibrary(a6)    libraries
  97.     clr.l    d0
  98.     rts
  99.  
  100. *******************************************************************************
  101.  
  102. TakeSystem    move.w    intenar(a6),SystemInts    save system interupts
  103.     move.w    dmaconr(a6),SystemDMA        and DMA settings
  104.     move.w    #$7fff,intena(a6)        kill everything!
  105.     move.w    #$7fff,dmacon(a6)
  106.     move.b    #%01111111,ICRA            kill keyboard
  107.     move.l    $68,Level2Vector        save these interrupt vectors
  108.     move.l    $6c,Level3Vector        as we will use our own 
  109.     rts                    keyboard & vblank routines
  110.  
  111. FreeSystem    move.l    Level2Vector,$68    restore the system vectors
  112.     move.l    Level3Vector,$6c        and interrupts and DMA
  113.     move.l    GraphicsBase,a1            and replace the system
  114.     move.l    SystemCopper1(a1),Hardware+cop1lc    copper list
  115.     move.l    SystemCopper2(a1),Hardware+cop2lc
  116.     move.w    SystemInts,d0
  117.     or.w    #$c000,d0
  118.     move.w    d0,intena(a6)
  119.     move.w    SystemDMA,d0
  120.     or.w    #$8100,d0
  121.     move.w    d0,dmacon(a6)
  122.     move.b    #%10011011,ICRA            keyboard etc back on
  123.     rts
  124.  
  125. *******************************************************************************
  126.  
  127. Level2Vector    dc.l    0
  128. Level3Vector    dc.l    0
  129. SystemInts    dc.w    0
  130. SystemDMA    dc.w    0
  131. MemBase        dc.l    0
  132. DOSBase        dc.l    0
  133. GraphicsBase    dc.l    0
  134. crap        dc.b    0
  135.  
  136.     even
  137. GraphicsName    dc.b    'graphics.library',0
  138.     even
  139. DOSName        dc.b    'dos.library',0
  140.     end
  141.  
  142.