home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / phxass-4.00.lha / PhxAss / Examples / DemoSupp.asm next >
Assembly Source File  |  1994-12-28  |  11KB  |  429 lines

  1. **
  2. **    A500/600/1000/1200/2000/3000/4000
  3. **      Kick 1.2,1.3 / OS 2.x/3.x
  4. **        68000/010/020/030/040
  5. **         OCS/ECS/AGA
  6. **
  7. **    ** DEMO SUPPORT FUNCTIONS **
  8. **
  9. **
  10. **      Coded by Frank Wille 1994
  11. **           using PhxAss 4
  12. **
  13. **
  14. **     __MERGED SMALL DATA A4 - VERSION
  15. **   Link with: PhxLnk prog.o DemoSupp.o
  16. **
  17. **
  18. **  10.12.94    demoStartup, demoCleanUp, demoIntVec (created)
  19. **  12.12.94    Switched to __MERGED-SmallData
  20. **  20.12.94    demoStdView, demoBplPtrs (created)
  21. **  22.12.94    demoColors (created), code optimizations in demoStdView
  22. **
  23.  
  24.  
  25. ;=============================================================================
  26. ; Exported Symbols:
  27. ;=============================================================================
  28. ; SysBase        : Pointer to ExecBase structure
  29. ; GfxBase        : Pointer to GfxBase structure
  30. ; PALflag        : true: System is in PAL mode
  31. ; AAflag        ; true: AGA chips are available
  32. ;=============================================================================
  33.  
  34.  
  35. ;=============================================================================
  36. ; Exported Functions:
  37. ;=============================================================================
  38. ;
  39. ; demoStartup
  40. ;    in:    -
  41. ;    out:    Z-Flag = Error! Jump to demoCleanup immediately!
  42. ;        a4 = Small Data Base
  43. ;        a6 = CUSTOM
  44. ;        All other registers are in random state!!!
  45. ;    Small Data initialization. Disable Data Cache. Enable CLI or Workbench
  46. ;    start. Determine VBR, PAL/NTSC mode, Gfx-chips. Save system state.
  47. ;    Allocate Blitter. Turn off all interrupts and DMA channels. Disable
  48. ;    AGA/ECS features. Save interrupt autovectors.
  49. ;
  50. ; demoCleanup
  51. ;    in:    -
  52. ;    out:    d0 = 0 (for return to CLI - no error)
  53. ;        All other registers are in random state!!!
  54. ;    Restores anything which has changed during the demo. Then, the program
  55. ;    may return to CLI or WB without any danger.
  56. ;
  57. ; demoIntVec
  58. ;    in:    d0.w = Number of interrupt level vector to change (1-6)
  59. ;        a0 = Pointer to interrupt routine (terminated by 'rte')
  60. ;             (CAUTION: The 'rte' should be preceded by a 'nop',
  61. ;              because of the 68040's instruction pipeline)
  62. ;    out:    -
  63. ;    Set interrupt autovector.
  64. ;
  65. ; demoStdView
  66. ;    in:    d0.w = Display width in pixels (should be word-aligned)
  67. ;        d1.w = Display height in lines
  68. ;        d2.w = Horizontal start position (std.= $81)
  69. ;        d3.w = Vertical start position (std.= $29)
  70. ;        d4.w = Depth
  71. ;            Bits 2-0 = Number of bitplanes (1-5)
  72. ;            Bit 3     = Interleaved Mode (fast blits)
  73. ;        a0 = Actual copper list pointer
  74. ;        a1 = Display memory pointer
  75. ;    out:    a0 = New copper list pointer
  76. ;        All registers, with the exception of a0, d0 and d1 will be saved
  77. ;    All necessary copper instructions for defining a display of the pre-
  78. ;    fered dimensions will be appended to the specified copper list.
  79. ;    If Width exceeds 384, the HIRES mode will be activated. If Height
  80. ;    exceeds 288 the LACE mode will be activated. Additionally to BPLxPT
  81. ;    the following registers are initialized by these copper instructions:
  82. ;    BPLxMOD, DIWSTRT, DIWSTOP, DDFSTRT, DDFSTOP, BPLCON0.
  83. ;    BPLCON1 and BPLCON2 were already initialized in demoStartup.
  84. ;
  85. ;  demoBplPtrs
  86. ;    in:    a0 = Actual copper list pointer
  87. ;        a1 = Display memory pointer
  88. ;        d0.w = Depth (1-5)
  89. ;        d1 = Plane offset (mode-dependant, e.g. LACE or Interleaved)
  90. ;    out:    a0 = New copper list pointer
  91. ;        All registers but a0 will be saved!
  92. ;    Append copper instructions for bitplane pointer initialization. This
  93. ;    routine will be also called by demoStdView.
  94. ;
  95. ;  demoColors
  96. ;    in:    a0 = Actual copper list pointer
  97. ;        a1 = Color table (RGB4 UWORDs)
  98. ;        d0.w = Number of colors in table (always beginning with COLOR00)
  99. ;    out:    a0 = New copper list pointer
  100. ;    Transfer colors from a UWORD-table directly to copper list.
  101. ;
  102. ;=============================================================================
  103.  
  104.  
  105.     include "lib/exec.i"
  106.     include "lib/graphics.i"
  107.  
  108.     include "exec/execbase.i"
  109.     include "exec/libraries.i"
  110.     include "dos/dosextens.i"
  111.     include "graphics/gfxbase.i"
  112.     include "hardware/dmabits.i"
  113.     include "hardware/intbits.i"
  114.     include "hardware/custom_all.i"
  115.     include "hardware/cia.i"
  116.  
  117.  
  118.     near    a4,-2            ; Small Data __MERGED
  119.  
  120.     xref    _DATA_BAS_        ; symbols will be supplied by PhxLnk
  121.     xref    _DATA_LEN_
  122.     xref    _BSS_LEN_
  123.  
  124.  
  125.  
  126.     code
  127.  
  128.  
  129.     xdef    demoStartup
  130. demoStartup:
  131. ; -> a4 = Small Data Base
  132. ; -> a6 = CUSTOM
  133.     move.l    ExecBase.w,a6
  134.     lea    _DATA_BAS_,a0
  135.     lea    32766(a0),a4        ; a4 SmallData Base
  136.     cmp.w    #36,lib_Version(a6)    ; OS2.0+ available?
  137.     bhs.s    2$
  138.     add.l    #_DATA_LEN_,a0
  139.     move.l    #_BSS_LEN_,d0
  140. 1$:    clr.l    (a0)+            ; Initialize BSS area (for Kick 1.x)
  141.     subq.l    #4,d0
  142.     bhi.s    1$
  143.     bra.s    3$
  144. 2$:    move.l    #$100,d2
  145.     moveq    #0,d0
  146.     move.l    d2,d1
  147.     jsr    CacheControl(a6)    ; disable Data Cache
  148.     and.l    d2,d0
  149.     move.l    d0,oldCache(a4)
  150. 3$:    move.l    a6,SysBase(a4)
  151.     move.l    ThisTask(a6),a2     ; pointer to actual process structure
  152.     move.l    pr_CLI(a2),d0
  153.     bne.s    5$            ; Workbench start?
  154. 4$:    lea    pr_MsgPort(a2),a0
  155.     jsr    WaitPort(a6)        ; get WBStartupMsg
  156.     lea    pr_MsgPort(a2),a0
  157.     jsr    GetMsg(a6)
  158.     move.l    d0,wbStartupMsg(a4)
  159.     beq.s    4$
  160. 5$:    sub.l    a0,a0
  161.     btst    #AFB_68010,AttnFlags+1(a6)
  162.     beq.s    6$
  163.     lea    get_VBR(pc),a5
  164.     jsr    Supervisor(a6)        ; read and save VBR (68010+)
  165. 6$:    move.l    a0,VBReg(a4)
  166.     lea    $64(a0),a0
  167.     lea    autoVecs(a4),a1     ; save Interrupt Autovectors
  168.     moveq    #6-1,d0
  169. 7$:    move.l    (a0)+,(a1)+
  170.     dbf    d0,7$
  171.     lea    GfxName(pc),a1
  172.     moveq    #33,d0
  173.     jsr    OpenLibrary(a6)     ; open graphics.library
  174.     move.l    d0,GfxBase(a4)
  175.     beq    99$            ; error?
  176.     move.l    d0,a6
  177.     move.l    gb_ActiView(a6),ActiView(a4)
  178.     sub.l    a1,a1
  179.     jsr    LoadView(a6)        ; LoadView(NULL)
  180.     jsr    WaitTOF(a6)
  181.     jsr    WaitTOF(a6)
  182.     jsr    OwnBlitter(a6)        ; allocate Blitter
  183.     jsr    WaitBlit(a6)
  184.     moveq    #0,d2            ; d2 BEAMCON0 (init PAL or NTSC)
  185.     btst    #PALn,gb_DisplayFlags+1(a6)
  186.     beq.s    8$            ; PAL?
  187.     st    PALflag(a4)
  188.     moveq    #$20,d2
  189. 8$:    moveq    #%1100,d0
  190.     and.b    gb_ChipRevBits0(a6),d0
  191.     sne    AAflag(a4)        ; AGA available?
  192.     lea    CUSTOM,a6
  193.     move.w    DMACONR(a6),d0        ; save DMACON and INTENA states
  194.     or.w    #DMAF_SETCLR,d0
  195.     move.w    d0,oldDMACON(a4)
  196.     move.w    INTENAR(a6),d0
  197.     or.w    #INTF_SETCLR|INTF_INTEN,d0
  198.     move.w    d0,oldINTENA(a4)
  199.     movem.l dmaintInit(pc),d0-d1    ; turn off DMA channels, CLXCON=0
  200.     movem.l d0-d1,DMACON(a6)    ; disable interrupts, clear INTREQ
  201.  
  202.     move.w    d2,BEAMCON0(a6)     ; *** disable AGA / ECS features ***
  203.     lea    bplconInit(pc),a0
  204.     lea    BPLCON0(a6),a1        ; init BPLCON0..4, BPL1MOD, BPL2MOD
  205.     moveq    #7-1,d0
  206. 9$:    move.w    (a0)+,(a1)+
  207.     dbf    d0,9$
  208.     lea    SPR0POS(a6),a0        ; clear all sprites
  209.     moveq    #16-1,d1
  210.     moveq    #0,d0
  211. 10$:    move.l    d0,(a0)+
  212.     dbf    d1,10$
  213.     move.w    d0,FMODE(a6)        ; OCS fetch mode
  214.     moveq    #-1,d0
  215. 99$:    rts
  216.  
  217.     machine 68010
  218. get_VBR:
  219.     movec    VBR,a0
  220.     rte
  221.     machine 68000
  222.  
  223. bplconInit:                ; init values for BPLCON0..4, BPL1/2MOD
  224.     dc.w    $0000,$0000,$0024,$0c00,$0000,$0000,$0011
  225. dmaintInit:                ; init DMACON,CLXCON,INTENA,INTREQ
  226.     dc.w    $1fff,$0000,$7fff,$7fff
  227. GfxName:
  228.     dc.b    "graphics.library",0
  229.     even
  230.  
  231.  
  232.     xdef    demoCleanup
  233. demoCleanup:
  234.     move.l    GfxBase(a4),d0
  235.     beq    3$
  236.     move.l    d0,a6
  237.     jsr    WaitBlit(a6)
  238.     lea    CUSTOM,a5
  239.     movem.l dmaintInit(pc),d0-d1    ; turn off DMA channels, CLXCON=0
  240.     movem.l d0-d1,DMACON(a5)    ; disable interrupts, clear INTREQ
  241.     moveq    #0,d0            ; zero audio volumes
  242.     move.w    d0,AUD0VOL(a5)
  243.     move.w    d0,AUD1VOL(a5)
  244.     move.w    d0,AUD2VOL(a5)
  245.     move.w    d0,AUD3VOL(a5)
  246.     lea    autoVecs(a4),a0
  247.     move.l    VBReg(a4),a1
  248.     lea    $64(a1),a1
  249.     moveq    #6-1,d0
  250. 4$:    move.l    (a0)+,(a1)+        ; restore interrupt autovectors
  251.     dbf    d0,4$
  252.     move.w    oldDMACON(a4),DMACON(a5) ; reactivate DMA channels and interrupts
  253.     move.w    oldINTENA(a4),INTENA(a5)
  254.     bclr    #1,CIAA|PRA        ; turn on LED/filter
  255.     move.l    ActiView(a4),a1
  256.     jsr    LoadView(a6)        ; restore system View
  257.     jsr    DisownBlitter(a6)    ; free Blitter
  258.     move.l    gb_copinit(a6),COP1LC(a5) ; restart system copper lists
  259.     move.l    a6,a1
  260.     move.l    SysBase(a4),a6
  261.     jsr    CloseLibrary(a6)    ; close graphics.library
  262. 3$:    move.l    SysBase(a4),a6
  263.     cmp.w    #36,lib_Version(a6)
  264.     blo.s    2$            ; OS2.0+ available?
  265.     moveq    #-1,d0
  266.     move.l    oldCache(a4),d1
  267.     jsr    CacheControl(a6)    ; enable Data Cache (if required)
  268. 2$:    move.l    wbStartupMsg(a4),d0    ; WB start? Reply WB message
  269.     beq.s    1$
  270.     move.l    d0,a1
  271.     jsr    Forbid(a6)
  272.     jsr    ReplyMsg(a6)
  273. 1$:    moveq    #0,d0            ; Finished, return to CLI or Workbench
  274.     rts
  275.  
  276.  
  277.     xdef    demoIntVec
  278.     cnop    0,4
  279. demoIntVec:
  280. ; d0 = Interrupt Level (1-6)
  281. ; a0 = Pointer to interrupt routine
  282.     move.l    VBReg(a4),a1
  283.     add.w    d0,d0
  284.     add.w    d0,d0
  285.     move.l    a0,$60(a1,d0.w)     ; set interrupt autovector
  286.     rts
  287.  
  288.  
  289.     xdef    demoStdView
  290.     cnop    0,4
  291. demoStdView:
  292. ; d0 = Wi