home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Assembler / dse-src3.dms / in.adf / Source / StartupCode / StartUp.S
Encoding:
Text File  |  1993-01-08  |  5.8 KB  |  195 lines

  1. ***********************************************************
  2. * This is my TakeSystem and ResotreSystem routines that I now use
  3. * in all my demos.  I am spreading them in hopes to get rid of the
  4. * crapy coding pracitces that people have had since the C64 days.
  5. * I'd like to thank Comrade J for his excelent "howtocode" files.
  6. * A lot of the stuff here is based on his words of wisdom. :^).  Anyway,
  7. * these routines, as of version 3.2, handle the following:
  8. *        Getting the VBR.
  9. *        Saving DMACON.
  10. *        Saving Intena.
  11. *        Saving and reseting WB view modes.
  12. *        Owning/Disowning the blitter.
  13. *        Pal/Ntsc/AGA modes.
  14. *        Killing multitasking.
  15. *        Killing interrupts.
  16. *
  17. * Feel free to cut and paste to fit your code (i.e. but the data and bss in
  18. * your data and bss sections.), but please leave the CODE intact!
  19. * If you have any questions/comments/suggestions, PLEASE contact me at
  20. * either:
  21. *        idr@rigel.cs.pdx.edu        (internet)
  22. *    - or -
  23. *        Epsilon
  24. *        P.O.B.    1914
  25. *        Beaverton, OR  97075-1914
  26. *        U.S.A.
  27. *
  28. * Many of you may not like the fact that I use includes and system calls,
  29. * I know I don't :), but it is the ONLY SAFE WAY TO TAKE THE SYSTEM!  To
  30. * insure that your demo will work on any system, it's what you have to do.
  31. *
  32. ***********************************************************
  33. * Includes
  34. ***********************************************************
  35.  
  36.         incdir    "DevpacAm:include/"
  37.         include    "exec/exec_lib.i"
  38.         include    "exec/execbase.i"
  39.         include    "graphics/gfxbase.i"
  40.         include    "graphics/graphics_lib.i"
  41.         include    "hardware/custom.i"
  42.  
  43. ***********************************************************
  44. * Other Macros
  45. ***********************************************************
  46.  
  47. CALL        MACRO
  48.         jsr    _LVO\1(a6)
  49.         ENDM
  50.  
  51. ***********************************************************
  52. * Other Equates
  53. ***********************************************************
  54.  
  55.  IFND    gb_ActiView
  56. gb_ActiView    EQU    32
  57.  ENDIF
  58.  
  59.  IFND    gb_CopInit
  60. gb_CopInit    EQU    36
  61.  ENDIF
  62.  
  63. ***********************************************************
  64.  
  65.         section TheCode,code
  66.  
  67. TakeSystem:    movea.l    4.w,a6        ; exec base
  68.         lea    $dff002,a5    ; custom chip base + 2
  69.  
  70.         lea    GraphicsName,a1    ; "graphics.library"
  71.         moveq    #0,d0        ; any version
  72.         CALL    OpenLibrary    ; open it.
  73.         move.l    d0,gfx_base    ; save pointer to gfx base
  74.         beq.b    .exit        ; if we got a NULL, then exit
  75.         move.l    d0,a6        ; for later callls...
  76.  
  77.         move.l  gb_ActiView(a6),OldView    ; save old view
  78.  
  79.         move.w    #0,a1        ; clears full long-word
  80.         CALL    LoadView    ; Open a NULL view (resets display
  81.                     ;   on any Amiga)
  82.  
  83.         CALL    WaitTOF        ; Wait twice so that an interlace
  84.         CALL    WaitTOF        ;   display can reset.
  85.  
  86.         CALL    OwnBlitter    ; take over the blitter and...
  87.         CALL    WaitBlit    ;   wait for it to finish so we
  88.                     ;   safely use it as we please.
  89.  
  90.         movea.l    4.w,a6        ; exec base
  91.         CALL    Forbid        ; kill multitasking
  92.  
  93.         cmpi.b    #50,VblankFrequency(a6)    ; is vblank rate pal?
  94.         beq.b    .pal        ; yup.
  95.         st    ntsc        ; set NTSC flag.
  96.  
  97. .pal:        move.w    $7c-2(a5),d0    ; AGA register...
  98.         cmpi.b    #$f8,d0        ; are we AGA?
  99.         bne.b    .not_aga    ; nope.
  100.         st    AGA        ; set the AGA flag.
  101.         move.w    #0,$dff1fc    ; reset AGA sprites to normal mode
  102.  
  103. .not_aga:    bsr.b    GetVBR        ; get the vector base pointer
  104.         move.l    d0,VectorBase    ; save it for later.
  105.  
  106.         move.w    dmaconr-2(a5),d0    ; old DMACON bits
  107.         ori.w    #$8000,d0    ; or it set bit for restore
  108.         move.w    d0,OldDMACon    ; save it
  109.  
  110.         move.w    intenar-2(a5),d0    ; old INTEna bits
  111.         ori.w    #$c000,d0    ; or it set bit for restore
  112.         move.w    d0,OldINTEna    ; save it
  113.  
  114.         move.l    #$7fff7fff,intena-2(a5)    ; kill all ints
  115.         move.w    #$7fff,dmacon-2(a5)    ; kill all dma
  116. .exit:        rts
  117.  
  118. ***********************************************************
  119.  
  120. RestoreSystem:    lea    $dff002,a5    ; custom chip base + 2
  121.  
  122.     ; You must do these in this order or you're asking for trouble!
  123.         move.l    #$7fff7fff,intena-2(a5)    ; kill all ints
  124.         move.w    #$7fff,dmacon-2(a5)    ; kill all dma
  125.         move.w    OldDMACon,dmacon-2(a5)    ; restore old dma bits
  126.         move.w    OldINTEna,intena-2(a5)    ; restore old int bits
  127.  
  128.         move.l    OldView,a1    ; old Work Bench view
  129.         move.l    gfx_base,a6    ; gfx base
  130.         CALL    LoadView    ; Restore the view
  131.         CALL    DisOwnBlitter    ; give blitter back to the system.
  132.  
  133.         move.l    gb_CopInit(a6),$80-2(a5) ; restore system clist
  134.         move.l    a6,a1
  135.         movea.l    4.w,a6        ; exec base
  136.         CALL    CloseLibrary
  137.  
  138.     ; there is no call to Permit() because it is implied by the return
  139.     ; to AmigaDOS! :^)
  140.         rts
  141.  
  142. ***********************************************************
  143. * This function provides a method of obtaining a pointer to the base of the
  144. * interrupt vector table on all Amigas.  After getting this pointer, use
  145. * the vector address as an offset.  For example, to install a level three
  146. * interrupt you would do the following:
  147. *
  148. *        bsr    _GetVBR
  149. *        move.l    d0,a0
  150. *        move.l    $6c(a0),OldIntSave
  151. *        move.l    #MyIntCode,$6c(a0)
  152. *
  153. ***********************************************************
  154. * Inputs: none
  155. * Output: d0 contains vbr.
  156.  
  157. GetVBR:        move.l    a5,-(sp)        ; save it.
  158.         moveq    #0,d0            ; clear
  159.         movea.l    4.w,a6            ; exec base
  160.         btst.b    #AFB_68010,AttnFlags+1(a6); are we at least a 68010?
  161.         beq.b    .1            ; nope.
  162.         lea.l    vbr_exception(pc),a5    ; addr of function to get VBR
  163.         CALL    Supervisor        ; supervisor state
  164. .1:        move.l    (sp)+,a5        ; restore it.
  165.         rts                ; return
  166.  
  167. vbr_exception:
  168.     ; movec vbr,Xn is a priv. instr.  You must be supervisor to execute!
  169. ;        movec   vbr,d0
  170.     ; many assemblers don't know the VBR, if yours doesn't, then use this
  171.     ; line instead.
  172.         dc.w    $4e7a,$0801
  173.         rte                ; back to user state code
  174.  
  175. ***********************************************************
  176.  
  177.         section TheData,data
  178.  
  179. GraphicsName:    GRAFNAME        ; name of gfx library
  180.         EVEN
  181.  
  182. ***********************************************************
  183.  
  184.         section    OldPointers_and_such,bss
  185.  
  186. gfx_base    ds.l    1        ; pointer to graphics base
  187. OldView        ds.l    1        ; old Work Bench view addr.
  188. VectorBase:    ds.l    1        ; pointer to the Vector Base
  189.  
  190. OldDMACon:    ds.w    1        ; old dmacon bits
  191. OldINTEna:    ds.w    1        ; old intena bits
  192.  
  193. ntsc:        ds.b    1        ; 0 = pal, 1 = ntsc
  194. AGA:        ds.b    1        ; 0 = ESC/standard, 1 = AGA
  195.