home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Assembler / dse-src3.dms / in.adf / Source / ShadeBobs / ShadeBobs.lha / SBRel.s < prev    next >
Encoding:
Text File  |  1993-01-04  |  9.3 KB  |  402 lines

  1. ***********************************************************
  2. * Shade Bobs
  3. *
  4. * These little things are basically an implementation of the blitter
  5. * to do addition.  If you think of each pixel as an 'n' bit number
  6. * (where 'n' is your number of bitplanes) the idea is to add one to
  7. * that number.  The logic is very simple.  First off you take your
  8. * bob and the screen and 'and' them to a carry area.  Then you take
  9. * your bob and 'xor' it to the proper bit plane.  Now you just
  10. * continue this using your carry area as your bob for each bit plane.
  11. * As you can see you'll need to carry areas.  This code is very easy
  12. * and should be simple enough to follow.  Enjoy.
  13. *
  14. ***********************************************************
  15. * Includes
  16. ***********************************************************
  17.  
  18.         incdir    "DevpacAm:include/"
  19.         include    "exec/exec_lib.i"
  20.         include    "exec/execbase.i"
  21.         include    "graphics/gfxbase.i"
  22.         include    "graphics/graphics_lib.i"
  23.         include    "hardware/custom.i"
  24.  
  25. ***********************************************************
  26. * Other Macros
  27. ***********************************************************
  28.  
  29. CALL        MACRO
  30.         jsr    _LVO\1(a6)
  31.         ENDM
  32.  
  33. WaitBlit:    macro
  34.         tst.w    $2-2(a5)
  35. .\@        btst.b    #6,$2-2(a5)
  36.         bne.s    .\@
  37.         endm
  38.     
  39. WRAST:        macro            ; Wait for a scanline
  40. .\@        move.l    $4-2(a5),d0
  41.         lsr.l    #8,d0
  42.         and.w    #$1FF,d0
  43.         cmp.w    #\1,d0
  44.         bne.b    .\@
  45.         endm
  46.  
  47. ***********************************************************
  48. * Other Equates
  49. ***********************************************************
  50.  
  51.  IFND    gb_ActiView
  52. gb_ActiView    EQU    32
  53.  ENDIF
  54.  
  55.  IFND    gb_CopInit
  56. gb_CopInit    EQU    36
  57.  ENDIF
  58.  
  59. ***********************************************************
  60.  
  61.         section    ShadeBobs,code
  62.  
  63.         bsr.w    TakeSystem
  64.         bsr.w    START
  65.  
  66.         lea    Sine1,a3
  67.         lea    Sine2,a4
  68.         move.w    #$8400,$96-2(a5)
  69.  
  70. MAIN:        WRAST    $0f4
  71.  
  72.         move.l    x_ptr,a3
  73.         move.l    y_ptr,a4
  74.  
  75.         cmp.l    xl_ptr,a3
  76.         bne.b    .xok
  77.         move.l    xr_ptr,a3
  78. .xok:        cmp.l    yl_ptr,a4
  79.         bne.b    .yok
  80.         move.l    yr_ptr,a4
  81. .yok:        moveq    #0,d0
  82.         moveq    #0,d1
  83.         move.b    (a3)+,d0
  84.         move.b    (a4)+,d1
  85.         add.w    d0,d0
  86.         move.l    a3,x_ptr
  87.         move.l    a4,y_ptr    
  88.         bsr    ShadeBob
  89.  
  90.         moveq    #0,d0
  91.         moveq    #0,d1
  92.         move.b    10(a3),d0
  93.         move.b    (a4),d1
  94.         add.w    d0,d0
  95.         bsr    ShadeBob
  96.  
  97.         moveq    #0,d0
  98.         moveq    #0,d1
  99.         move.b    (a3),d0
  100.         move.b    10(a4),d1
  101.         add.w    d0,d0
  102.         bsr    ShadeBob
  103.  
  104.         btst    #6,$BFE001    ; Left button pressed?
  105.         bne.w    MAIN
  106.  
  107.         bsr.w    RestoreSystem
  108.         rts
  109.  
  110. ***********************************************************
  111. * Shade Bob
  112. * d0 : x
  113. * d1 : y
  114.  
  115. ShadeBob:    WaitBlit
  116.     
  117.         movem.l    d0-d5/a0-a3,-(a7)
  118.         move.l    d0,d2        ; save x in d2
  119.         lsr.w    #4,d2        ; turn d2 into the word offset
  120.         add.w    d2,d2        ;   that contains the pixel at 'x'
  121.  
  122.         andi.l    #$f,d0        ; turn d0 into a blitter shift
  123.         ror.l    #4,d0        ;   value
  124.  
  125.         mulu    #40,d1        ; turn d1 into to offset into bmap
  126.                     ;   that is the 'y' scan line
  127.         add.w    d1,d2        ; total offset
  128.  
  129.         lea    Bob,a0
  130.         lea    Bmap,a1
  131.         lea    Carry1,a2
  132.         lea    Carry2,a3
  133.  
  134.         adda.l    d2,a1        ; correct pos. in bmap for bob
  135.  
  136.         moveq    #0,d2        ; modulo
  137.         moveq    #$22,d3        ; modulo
  138.         move.w    #(31*64)+3,d5    ; bltsize
  139.  
  140.         move.l    #$0ba00000,d4        ; d = a eor c
  141.         or.l    d0,d4
  142.     
  143.         WaitBlit
  144.         move.l    a0,bltapt-2(a5)
  145.         move.l    a1,bltcpt-2(a5)
  146.         move.l    a2,bltdpt-2(a5)
  147.         move.w    d3,bltcmod-2(a5)
  148.         move.l    d2,bltamod-2(a5)    ; no modulo
  149.         move.l    d4,bltcon0-2(a5)
  150.          move.w    d5,bltsize-2(a5)
  151.  
  152.         move.l    #$0b5a0000,d4        ; d = a and c
  153.         or.l    d0,d4
  154.     
  155.         WaitBlit
  156.         move.l    a0,bltapt-2(a5)
  157.         move.l    a1,bltcpt-2(a5)
  158.         move.l    a1,bltdpt-2(a5)
  159.         move.w    d3,bltdmod-2(a5)
  160.         move.l    d4,bltcon0-2(a5)
  161.          move.w    d5,bltsize-2(a5)
  162.  
  163.         adda.l    #8000,a1
  164.         moveq    #3,d7
  165.     
  166. .1        move.w    #$0ba0,d4        ; a = a eor c
  167.         WaitBlit
  168.         move.l    a2,bltapt-2(a5)
  169.         move.l    a1,bltcpt-2(a5)
  170.         move.l    a3,bltdpt-2(a5)
  171.         move.w    d3,bltcmod-2(a5)
  172.         move.l    d2,bltamod-2(a5)
  173.         move.w    d4,bltcon0-2(a5)
  174.          move.w    d5,bltsize-2(a5)
  175.  
  176.         move.w    #$0b5a,d4        ; a = a and c
  177.     
  178.         WaitBlit
  179.         move.l    a2,bltapt-2(a5)
  180.         move.l    a1,bltcpt-2(a5)
  181.         move.l    a1,bltdpt-2(a5)
  182.         move.w    d3,bltdmod-2(a5)
  183.         move.w    d4,bltcon0-2(a5)
  184.          move.w    d5,bltsize-2(a5)
  185.  
  186.         adda.l    #8000,a1
  187.         exg    a2,a3
  188.  
  189.         dbf    d7,.1
  190.  
  191.         movem.l    (a7)+,d0-d5/a0-a3
  192.         rts
  193.  
  194. ***********************************************************
  195. * This is my TakeSystem and ResotreSystem routines that I now use
  196. * in all my demos.  I am spreading them in hopes to get rid of the
  197. * crapy coding pracitces that people have had since the C64 days.
  198. * I'd like to thank Comrade J for his excelent "howtocode" files.
  199. * A lot of the stuff here is based on his words of wisdom. :^).  Anyway,
  200. * these routines, as of version 3.0, handle the following:
  201. *        Getting the VBR.
  202. *        Saving DMACON.
  203. *        Saving and reseting WB view modes.
  204. *        Owning/Disowning the blitter.
  205. *        Pal/Ntsc/AGA modes.
  206. *        Killing multitasking.
  207. *        Killing interrupts.
  208. *
  209. ***********************************************************
  210.  
  211. TakeSystem:    movea.l    4.w,a6        ; exec base
  212.         lea    $dff002,a5    ; custom chip base + 2
  213.  
  214.         lea    GraphicsName,a1    ; "graphics.library"
  215.         moveq    #0,d0        ; any version
  216.         CALL    OpenLibrary    ; open it.
  217.         move.l    d0,gfx_base    ; save pointer to gfx base
  218.         beq.b    .exit        ; if we got a NULL, then exit
  219.         move.l    d0,a6        ; for later callls...
  220.  
  221.         move.l  gb_ActiView(a6),OldView    ; save old view
  222.  
  223.         move.w    #0,a1        ; clears full long-word
  224.         CALL    LoadView    ; Open a NULL view (resets display
  225.                     ;   on any Amiga)
  226.  
  227.         CALL    WaitTOF        ; Wait twice so that an interlace
  228.         CALL    WaitTOF        ;   display can reset.
  229.  
  230.         CALL    OwnBlitter    ; take over the blitter and...
  231.         CALL    WaitBlit    ;   wait for it to finish so we
  232.                     ;   safely use it as we please.
  233.  
  234.         movea.l    4.w,a6        ; exec base
  235.         CALL    Forbid        ; kill multitasking
  236.         CALL    Disable        ; kill interrupts so that we can
  237.                     ;   safely install our own.
  238.  
  239. .pal:        move.w    $7c-2(a5),d0    ; AGA register...
  240.         cmpi.b    #$f8,d0        ; are we AGA?
  241.         bne.b    .not_aga    ; nope.
  242.         st    AGA        ; set the AGA flag.
  243.  
  244. .not_aga:    move.w    dmaconr-2(a5),d0    ; old DMACON bits
  245.         ori.w    #$8000,d0    ; or it set bit for restore
  246.         move.w    d0,OldDMACon    ; save it
  247. .exit:        rts
  248.  
  249. ***********************************************************
  250.  
  251. RestoreSystem:    lea    $dff002,a5    ; custom chip base + 2
  252.         move.w    OldDMACon,dmacon-2(a5)    ; restore old dma bits
  253.  
  254.         move.l    OldView,a1    ; old Work Bench view
  255.         move.l    gfx_base,a6    ; gfx base
  256.         CALL    LoadView    ; Restore the view
  257.         CALL    DisOwnBlitter    ; give blitter back to the system.
  258.  
  259.         move.l    gb_CopInit(a6),$80-2(a5) ; restore system clist
  260.         move.l    a6,a1
  261.         movea.l    4.w,a6        ; exec base
  262.         CALL    CloseLibrary
  263.  
  264.         movea.l    4.w,a6        ; exec base
  265.         CALL    Enable        ; restore ints.
  266.         CALL    Permit         ; restart multitasking
  267.         rts
  268.  
  269. ***********************************************************
  270.  
  271. START:        lea    $dff002,a5
  272.  
  273.         bsr.b    InstallBmaps
  274.         bsr.w    InstallSprites
  275.         move.l    #Copper,$80-2(a5)    ; New copperlist
  276.  
  277.         move.w    #$7FFF,$96-2(a5)    ; kill all dma
  278.         move.w    #$87E0,$96-2(a5)    ; turn on what I need
  279.         rts
  280.  
  281. ***********************************************************
  282.  
  283. InstallBmaps:    lea    BmapPtrs+2,a0        ; Insert planes in copper
  284.         move.l    #Bmap+[0*200*40],d0
  285.         move.w    d0,4(a0)
  286.         swap    d0
  287.         move.w    d0,(a0)
  288.  
  289.         move.l    #Bmap+[1*200*40],d0
  290.         move.w    d0,12(a0)
  291.         swap    d0
  292.         move.w    d0,8(a0)
  293.  
  294.         move.l    #Bmap+[2*200*40],d0
  295.         move.w    d0,20(a0)
  296.         swap    d0
  297.         move.w    d0,16(a0)
  298.  
  299.         move.l    #Bmap+[3*200*40],d0
  300.         move.w    d0,28(a0)
  301.         swap    d0
  302.         move.w    d0,24(a0)
  303.  
  304.         move.l    #Bmap+[4*200*40],d0
  305.         move.w    d0,36(a0)
  306.         swap    d0
  307.         move.w    d0,32(a0)
  308.  
  309.         move.l    #Bmap+[5*200*40],d0
  310.         move.w    d0,44(a0)
  311.         swap    d0
  312.         move.w    d0,40(a0)
  313.         rts
  314.  
  315. ***********************************************************
  316.  
  317. InstallSprites:    move.l    #NullSpr,d0        ; Insert sprites in copper
  318.         lea    SprPtrs+2,a1
  319.         move.w    d0,4(a1)
  320.         move.w    d0,12(a1)
  321.         move.w    d0,20(a1)
  322.         move.w    d0,28(a1)
  323.         move.w    d0,36(a1)
  324.         move.w    d0,44(a1)
  325.         move.w    d0,52(a1)
  326.         move.w    d0,60(a1)
  327.         swap    d0
  328.         move.w    d0,(a1)
  329.         move.w    d0,8(a1)
  330.         move.w    d0,16(a1)
  331.         move.w    d0,24(a1)
  332.         move.w    d0,32(a1)
  333.         move.w    d0,40(a1)
  334.         move.w    d0,48(a1)
  335.         move.w    d0,56(a1)
  336.         rts
  337.  
  338. ***********************************************************
  339.  
  340.         section    THEDATA,data_c    
  341.  
  342. Copper:    ; Display size
  343.     dc.l    $00920038,$009400D0,$008E2C81,$0090F4C1
  344.     ; Bplcon0, bplcon1, and modulos
  345.     dc.l    $01005200,$01020000,$01080000,$010A0000
  346.     ; Sprite pointers
  347. SprPtrs:dc.l    $01200000,$01220000,$01240000,$01260000,$01280000,$012A0000
  348.     dc.l    $012C0000,$012E0000,$01300000,$01320000,$01340000,$01360000
  349.     dc.l    $01380000,$013A0000,$013C0000,$013E0000
  350.     ; colors
  351.     dc.l    $01800000,$01820003,$01840004,$01860005,$01880006,$018a0007
  352.     dc.l    $018c0008,$018e0009,$0190000a,$0192000b,$0194000c,$0196000d
  353.     dc.l    $0198000e,$019a000f,$019c020f,$019e030f,$01a0040f,$01a2050f
  354.     dc.l    $01a4060f,$01a6070e,$01a8080d,$01aa090c,$01ac0a0b,$01ae0b0a
  355.     dc.l    $01b00c09,$01b20d08,$01b40e07,$01b60f06,$01b80e35,$01ba0d44
  356.     dc.l    $01bc0c53,$01be0b62
  357.     ; Bit Plane pointers
  358. BmapPtrs:dc.l    $00E00000,$00E20000,$00E40000,$00E60000,$00E80000,$00EA0000
  359.     dc.l    $00EC0000,$00EE0000,$00F00000,$00F20000,$00F40000,$00F60000
  360.     dc.l    -2,-2
  361.  
  362.         incdir    ''
  363. Bob:        incbin    'ShadeStuff:circle.48.raw'
  364.  
  365. ***********************************************************
  366.  
  367.         section    my_bum,data
  368.  
  369. GraphicsName:    GRAFNAME        ; name of gfx library
  370.         EVEN
  371.  
  372. x_ptr:        dc.l    Sine1
  373. y_ptr:        dc.l    Sine2
  374. xr_ptr:        dc.l    Sine1
  375. yr_ptr:        dc.l    Sine2
  376. xl_ptr:        dc.l    Sine1e
  377. yl_ptr:        dc.l    Sine2e
  378.  
  379.     
  380. Sine1:        incbin    'ShadeStuff:sine1'
  381. Sine1e:        incbin    'ShadeStuff:sine1'
  382.     
  383. Sine2:        incbin    'ShadeStuff:sine2'
  384. Sine2e:        incbin    'ShadeStuff:sine2'
  385.  
  386. ***********************************************************
  387.  
  388.         section    thpt,bss_c
  389.  
  390. gfx_base    ds.l    1        ; pointer to graphics base
  391. OldView        ds.l    1        ; old Work Bench view addr.
  392. OldDMACon:    ds.w    1        ; old dmacon bits
  393.  
  394. AGA:        ds.b    1        ; 0 = ESC/standard, 1 = AGA
  395.         even
  396.  
  397. NullSpr:    ds.l    16        ; null sprite data
  398.  
  399. Carry1:        ds.w    31*3        ; first carry pad
  400. Carry2:        ds.w    31*3        ; second carry pad
  401. Bmap:        ds.b    8000*5        ; screen buffer
  402.