home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / assembler / thesource / volume4 / source / startupcode / startup.s < prev    next >
Encoding:
Text File  |  1993-03-21  |  6.0 KB  |  193 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.4, 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. *        Fixed equates for case sensitive assemblers.
  17. *        Easy to make 100% PC relative.
  18. *
  19. * Feel free to cut and paste to fit your code (i.e. put the data and bss in
  20. * your data and bss sections.), but please leave the CODE intact!
  21. * If you have any questions/comments/suggestions, PLEASE contact me at
  22. * either:
  23. *        idr@rigel.cs.pdx.edu        (internet)
  24. *    - or -
  25. *        Epsilon
  26. *        P.O.B.    1914
  27. *        Beaverton, OR  97075-1914
  28. *        U.S.A.
  29. *
  30. * Many of you may not like the fact that I use includes and system calls,
  31. * I know I don't :), but it is the ONLY SAFE WAY TO TAKE THE SYSTEM!  To
  32. * insure that your demo will work on any system, it's what you have to do.
  33. *
  34. ***********************************************************
  35. * Includes
  36. ***********************************************************
  37.  
  38.         incdir    "DevpacAm:include/"
  39.         include    "exec/exec_lib.i"
  40.         include    "exec/execbase.i"
  41.         include    "graphics/gfxbase.i"
  42.         include    "graphics/graphics_lib.i"
  43.         include    "hardware/custom.i"
  44.  
  45. ***********************************************************
  46. * Other Macros
  47. ***********************************************************
  48.  
  49. CALL        MACRO
  50.         jsr    _LVO\1(a6)
  51.         ENDM
  52.  
  53. ***********************************************************
  54. * Other Structs
  55. ***********************************************************
  56.  
  57.         rsreset
  58. gfx_base    rs.l    1        ; pointer to graphics base
  59. OldView        rs.l    1        ; old Work Bench view addr.
  60. VectorBase:    rs.l    1        ; pointer to the Vector Base
  61. OldDMACon:    rs.w    1        ; old dmacon bits
  62. OldINTEna:    rs.w    1        ; old intena bits
  63. ntsc:        rs.b    1        ; 0 = pal, 1 = ntsc
  64. AGA:        rs.b    1        ; 0 = ESC/standard, 1 = AGA
  65. SYS_SIZE    rs.b    0        ; size of the struct
  66.  
  67. ***********************************************************
  68.  
  69.         section TheCode,code
  70.  
  71. TakeSystem:    movea.l    4.w,a6        ; exec base
  72.         lea    $dff002,a5    ; custom chip base + 2
  73.         lea    SystemSave,a4    ; where to save everything
  74.  
  75.         lea    GraphicsName,a1    ; "graphics.library"
  76.         moveq    #0,d0        ; any version
  77.         CALL    OpenLibrary    ; open it.
  78.         move.l    d0,gfx_base(a4)    ; save pointer to gfx base
  79.         beq.b    .exit        ; if we got a NULL, then exit
  80.         movea.l    d0,a6        ; for later callls...
  81.  
  82.         move.l  gb_ActiView(a6),OldView(a4)    ; save old view
  83.  
  84.         move.w    #0,a1        ; clears full long-word
  85.         CALL    LoadView    ; Open a NULL view (resets display
  86.                     ;   on any Amiga)
  87.  
  88.         CALL    WaitTOF        ; Wait twice so that an interlace
  89.         CALL    WaitTOF        ;   display can reset.
  90.  
  91.         CALL    OwnBlitter    ; take over the blitter and...
  92.         CALL    WaitBlit    ;   wait for it to finish so we
  93.                     ;   safely use it as we please.
  94.  
  95.         movea.l    4.w,a6        ; exec base
  96.         CALL    Forbid        ; kill multitasking
  97.  
  98.         cmpi.b    #50,VBlankFrequency(a6)    ; is vblank rate pal?
  99.         beq.b    .pal        ; yup.
  100.         st    ntsc(a4)    ; set NTSC flag.
  101.  
  102. .pal:        move.w    $7c-2(a5),d0    ; AGA register...
  103.         cmpi.b    #$f8,d0        ; are we AGA?
  104.         bne.b    .not_aga    ; nope.
  105.         st    AGA(a4)        ; set the AGA flag.
  106.         move.w    #0,$1fc-2(a5)    ; reset AGA sprites to normal mode
  107.  
  108. .not_aga:    bsr.b    GetVBR        ; get the vector base pointer
  109.         move.l    d0,VectorBase(a4)    ; save it for later.
  110.  
  111.         move.w    dmaconr-2(a5),d0    ; old DMACON bits
  112.         ori.w    #$8000,d0    ; or it set bit for restore
  113.         move.w    d0,OldDMACon(a4); save it
  114.  
  115.         move.w    intenar-2(a5),d0    ; old INTEna bits
  116.         ori.w    #$c000,d0    ; or it set bit for restore
  117.         move.w    d0,OldINTEna(a4); save it
  118.  
  119.         move.l    #$7fff7fff,intena-2(a5)    ; kill all ints
  120.         move.w    #$7fff,dmacon-2(a5)    ; kill all dma
  121. .exit:        rts
  122.  
  123. ***********************************************************
  124.  
  125. RestoreSystem:    lea    $dff002,a5    ; custom chip base + 2
  126.         lea    SystemSave,a4    ; where it's all at
  127.  
  128.     ; You must do these in this order or you're asking for trouble!
  129.         move.l    #$7fff7fff,intena-2(a5)    ; kill all ints
  130.         move.w    #$7fff,dmacon-2(a5)    ; kill all dma
  131.         move.w    OldDMACon(a4),dmacon-2(a5)    ; restore old dma bits
  132.         move.w    OldINTEna(a4),intena-2(a5)    ; restore old int bits
  133.  
  134.         movea.l    OldView(a4),a1    ; old Work Bench view
  135.         movea.l    gfx_base(a4),a6    ; gfx base
  136.         CALL    LoadView    ; Restore the view
  137.         CALL    DisownBlitter    ; give blitter back to the system.
  138.  
  139.         move.l    gb_copinit(a6),$80-2(a5) ; restore system clist
  140.         movea.l    a6,a1
  141.         movea.l    4.w,a6        ; exec base
  142.         CALL    CloseLibrary
  143.  
  144.     ; there is no call to Permit() because it is implied by the return
  145.     ; to AmigaDOS! :^)
  146.         rts
  147.  
  148. ***********************************************************
  149. * This function provides a method of obtaining a pointer to the base of the
  150. * interrupt vector table on all Amigas.  After getting this pointer, use
  151. * the vector address as an offset.  For example, to install a level three
  152. * interrupt you would do the following:
  153. *
  154. *        bsr    _GetVBR
  155. *        move.l    d0,a0
  156. *        move.l    $6c(a0),OldIntSave
  157. *        move.l    #MyIntCode,$6c(a0)
  158. *
  159. ***********************************************************
  160. * Inputs: none
  161. * Output: d0 contains vbr.
  162.  
  163. GetVBR:        move.l    a5,-(sp)        ; save it.
  164.         moveq    #0,d0            ; clear
  165.         movea.l    4.w,a6            ; exec base
  166.         btst.b    #AFB_68010,AttnFlags+1(a6); are we at least a 68010?
  167.         beq.b    .1            ; nope.
  168.         lea.l    vbr_exception(pc),a5    ; addr of function to get VBR
  169.         CALL    Supervisor        ; supervisor state
  170. .1:        move.l    (sp)+,a5        ; restore it.
  171.         rts                ; return
  172.  
  173. vbr_exception:
  174.     ; movec vbr,Xn is a priv. instr.  You must be supervisor to execute!
  175. ;        movec   vbr,d0
  176.     ; many assemblers don't know the VBR, if yours doesn't, then use this
  177.     ; line instead.
  178.         dc.l    $4e7a0801
  179.         rte                ; back to user state code
  180.  
  181. ***********************************************************
  182.  
  183.         section TheData,data
  184.  
  185. GraphicsName:    GRAFNAME        ; name of gfx library
  186.         EVEN
  187.  
  188. ***********************************************************
  189.  
  190.         section    OldPointers_and_such,bss
  191.  
  192. SystemSave:    ds.b    SYS_SIZE
  193.