home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 39 / af039a.adf / sprites.s < prev    next >
Text File  |  1992-09-17  |  10KB  |  400 lines

  1.  
  2.     IFND    NOLINK
  3. FUNC_SPRITES    =    1
  4. ;    include custom.i
  5. ;    include myheader.i
  6. ;    INCLUDE funcs.f
  7.     ENDC
  8. *****************************************************************************
  9. *                Both the blitter and the processor sprite                  *
  10. *                       routines use d0-d7 a0 & a1                          *
  11. *                    the blitter version also uses a2                       *
  12. *                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                        *
  13. *****************************************************************************
  14. SPRITE_SCREEN_WIDTH    =    SCREEN_WIDTH
  15.  
  16. *****************************************************************************
  17.     xdef    _s8_draw
  18. _s8_draw
  19.     rts
  20. *****************************************************************************
  21. *        d0 = x    d1 = y    d2 = height    a0 = the screen    a1 = source             *
  22. *****************************************************************************
  23.     xdef    _s16_draw
  24. _s16_draw ;
  25.     move.w    d2,d7                *1        calculate the plane size
  26.     add.w    d7,d7                *2
  27.     tst.w    d1                    is y less than 0
  28.     bge.s    .y_not_minus        no, ok.
  29. ******************************************************************************
  30. *    QY is negative
  31.     neg.w    d1
  32.     sub.w    d1,d2                do we see any of it ?
  33.     ble        .not_drawn            no, dont draw the thing at all
  34. ; a 16 pixel wide sprite has 2 bytes a line, so we have to multiply by 2
  35.     add.w    d1,d1                *2
  36.     adda.w    d1,a1                move into the source the required no. of lines
  37.  
  38.     bra.s    .y_clipped
  39. *********
  40. .y_not_minus
  41.     move.w    lines_high(pc),d6
  42.     cmp.w    d6,d1
  43.     bge     .not_drawn
  44.     IFNE    SCREEN_WIDTH-40
  45.     fail     'sorry, SCREEN_WIDTH changed you gotta re-write this bit'
  46.     ENDC
  47.     move.w    d1,d3
  48.     add.w    d3,d3                *2
  49.     add.w    d3,d3                *4
  50.     add.w    d1,d3                *5
  51.     lsl.w    #3,d3                *8*5 = *40
  52.     adda.w    d3,a0                move down the screen
  53.  
  54.     add.w    d2,d1
  55.     sub.w    d6,d1
  56.     blt.s    .y_clipped
  57.     sub.w    d1,d2                adjust height of sprite to fit the fucker on
  58. .y_clipped
  59. *****************************************************************************
  60. *    I suppose I better do the QX stuff now
  61.     tst.w    d0
  62.     bge.s    .x_not_minus        x ok, well at least it isn't negative!
  63.     cmpi.w    #-16,d0
  64.     ble.s    .not_drawn            it is off screen
  65.     bra        blit_left_16
  66. .x_not_minus
  67.     move.w    d0,d3
  68.     andi.w    #$f,d0              just the shift
  69.  
  70. * we want . . . 0-15 ->0, 16-31->2 etc.........
  71.  
  72.     eor.w    d0,d3                all but the shift
  73.     lsr.w    #3,d3                AMIGA
  74.     move.w    sprite_screen_width(pc),d6                """""
  75.     cmp.w    d6,d3                is it off the right side of the screen ?
  76.     bge.s    .not_drawn            yes
  77.     adda.w    d3,a0                adjust destination
  78.     subq.w    #2,d6                AMIGA
  79.     cmp.w    d6,d3
  80.     bne        blit_mid_16
  81. *    right hand only case
  82.  
  83.     moveq    #0,d1
  84.     bra        blit_right_16
  85. .not_drawn
  86.     rts
  87. ;left_gone    BLTCON0    BLTCON1    BLTAFWM    BLTALWM
  88. left16lu
  89.     dc.w    $0fca,    $0000,    $0000,    $0000
  90.     dc.w    $1fca,    $1000,    $0001,    $0000
  91.     dc.w    $2fca,    $2000,    $0003,    $0000
  92.     dc.w    $3fca,    $3000,    $0007,    $0000
  93.     dc.w    $4fca,    $4000,    $000f,    $0000
  94.     dc.w    $5fca,    $5000,    $001f,    $0000
  95.     dc.w    $6fca,    $6000,    $003f,    $0000
  96.     dc.w    $7fca,    $7000,    $007f,    $0000
  97.     dc.w    $8fca,    $8000,    $00ff,    $0000
  98.     dc.w    $9fca,    $9000,    $01ff,    $0000
  99.     dc.w    $afca,    $a000,    $03ff,    $0000
  100.     dc.w    $bfca,    $b000,    $07ff,    $0000
  101.     dc.w    $cfca,    $c000,    $0fff,    $0000
  102.     dc.w    $dfca,    $d000,    $1fff,    $0000
  103.     dc.w    $efca,    $e000,    $3fff,    $0000
  104.     dc.w    $ffca,    $f000,    $7fff,    $0000
  105. blit_left_16
  106.     subq.l    #2,a0
  107.     andi.w    #$f,d0
  108.     lsl.w    #3,d0                                shifted for lookup
  109.     lea        left16lu,a2
  110.     movem.l    (a2,d0.w),d0/d1
  111.     movem.l    d0/d1,(BLTCON0).l
  112.  
  113.     move.w    #-2,(BLTAMOD).l
  114.     move.w    #-2,(BLTBMOD).l
  115.     move.w    #SCREEN_WIDTH-4,(BLTCMOD).l
  116.     move.w    #SCREEN_WIDTH-4,(BLTDMOD).l
  117.  
  118.     lsl.w    #6,d2
  119.     addq.w    #4/2,d2
  120.     bra        blit_sprite
  121. right_16_lu
  122. ;right_gone    BLTCON0    BLTCON1    BLTAFWM    BLTALWM            2 less on the width
  123.     dc.w    $0fca,    $0000,    $ffff,    $ffff
  124.     dc.w    $1fca,    $1000,    $ffff,    $fffe
  125.     dc.w    $2fca,    $2000,    $ffff,    $fffc
  126.     dc.w    $3fca,    $3000,    $ffff,    $fff8
  127.     dc.w    $4fca,    $4000,    $ffff,    $fff0
  128.     dc.w    $5fca,    $5000,    $ffff,    $ffe0
  129.     dc.w    $6fca,    $6000,    $ffff,    $ffc0
  130.     dc.w    $7fca,    $7000,    $ffff,    $ff80
  131.     dc.w    $8fca,    $8000,    $ffff,    $ff00
  132.     dc.w    $9fca,    $9000,    $ffff,    $fe00
  133.     dc.w    $afca,    $a000,    $ffff,    $fc00
  134.     dc.w    $bfca,    $b000,    $ffff,    $f800
  135.     dc.w    $cfca,    $c000,    $ffff,    $f000
  136.     dc.w    $dfca,    $d000,    $ffff,    $e000
  137.     dc.w    $efca,    $e000,    $ffff,    $c000
  138.     dc.w    $ffca,    $f000,    $ffff,    $8000
  139. blit_right_16
  140.     andi.w    #$f,d0
  141.     lsl.w    #3,d0                                shifted for lookup
  142.     lea        right_16_lu,a2
  143.     movem.l    (a2,d0.w),d0/d1
  144.     movem.l    d0/d1,(BLTCON0).l
  145.  
  146.     move.w    #0,(BLTAMOD).l
  147.     move.w    #0,(BLTBMOD).l
  148.     move.w    #SCREEN_WIDTH-2,(BLTCMOD).l
  149.     move.w    #SCREEN_WIDTH-2,(BLTDMOD).l
  150.  
  151.     lsl.w    #6,d2
  152.     addq.w    #2/2,d2
  153.     bra        blit_sprite
  154.     rts
  155. ;mid screen    BLTCON0    BLTCON1    BLTAFWM    BLTALWM
  156. mid16lu
  157.     dc.w    $0fca,    $0000,    $ffff,    $0000
  158.     dc.w    $1fca,    $1000,    $ffff,    $0000
  159.     dc.w    $2fca,    $2000,    $ffff,    $0000
  160.     dc.w    $3fca,    $3000,    $ffff,    $0000
  161.     dc.w    $4fca,    $4000,    $ffff,    $0000
  162.     dc.w    $5fca,    $5000,    $ffff,    $0000
  163.     dc.w    $6fca,    $6000,    $ffff,    $0000
  164.     dc.w    $7fca,    $7000,    $ffff,    $0000
  165.     dc.w    $8fca,    $8000,    $ffff,    $0000
  166.     dc.w    $9fca,    $9000,    $ffff,    $0000
  167.     dc.w    $afca,    $a000,    $ffff,    $0000
  168.     dc.w    $bfca,    $b000,    $ffff,    $0000
  169.     dc.w    $cfca,    $c000,    $ffff,    $0000
  170.     dc.w    $dfca,    $d000,    $ffff,    $0000
  171.     dc.w    $efca,    $e000,    $ffff,    $0000
  172.     dc.w    $ffca,    $f000,    $ffff,    $0000
  173. blit_mid_16
  174.     lsl.w    #3,d0                                shifted for lookup
  175.     lea        mid16lu,a2
  176.     movem.l    (a2,d0.w),d0/d1
  177.     movem.l    d0/d1,(BLTCON0).l
  178.  
  179.     move.w    #-2,(BLTAMOD).l
  180.     move.w    #-2,(BLTBMOD).l
  181.     move.w    #SCREEN_WIDTH-4,(BLTCMOD).l
  182.     move.w    #SCREEN_WIDTH-4,(BLTDMOD).l
  183.  
  184.     lsl.w    #6,d2
  185.     addq.w    #4/2,d2
  186.     bra        blit_sprite
  187. *****************************************************************************
  188.     xdef    _s32_draw
  189. _s32_draw ;
  190. ;    move.w    #$707,(COLOR).l
  191.     move.w    d2,d7                *1        calculate the plane size
  192.     add.w    d7,d7                *2
  193.     add.w    d7,d7                *4
  194.     tst.w    d1                    is y less than 0
  195.     bge.s    .y_not_minus        no, ok.
  196. ******************************************************************************
  197. *    QY is negative
  198.     neg.w    d1
  199.     sub.w    d1,d2                do we see any of it ?
  200.     ble        .not_drawn            no, dont draw the thing at all
  201. ; a 32 pixel wide sprite has 4 bytes a line, so we have to multiply by 4
  202.     add.w    d1,d1                *2
  203.     add.w    d1,d1                *4
  204.     adda.w    d1,a1                move into the source the required no. of lines
  205.  
  206.     bra.s    .y_clipped
  207. *********
  208. .y_not_minus
  209.     move.w    lines_high(pc),d6
  210.     cmp.w    d6,d1
  211.     bge     .not_drawn
  212.     IFNE    SCREEN_WIDTH-40
  213.     fail     'sorry, SCREEN_WIDTH changed you gotta re-write this bit'
  214.     ENDC
  215.     move.w    d1,d3
  216.     add.w    d3,d3                *2
  217.     add.w    d3,d3                *4
  218.     add.w    d1,d3                *5
  219.     lsl.w    #3,d3                *8*5 = *40
  220.     adda.w    d3,a0                move down the screen
  221.  
  222.     add.w    d2,d1
  223.     sub.w    d6,d1
  224.     blt.s    .y_clipped
  225.     sub.w    d1,d2                adjust height of sprite to fit the fucker on
  226. .y_clipped
  227. *****************************************************************************
  228. *    I suppose I better do the X stuff now
  229.     tst.w    d0
  230.     bge.s    .x_not_minus        x ok, well at least it isn't negative!
  231.     cmpi.w    #-32,d0
  232.     ble.s    .not_drawn            it is off screen
  233.     cmpi.w    #-16,d0
  234.     blt        blit_left_32_lt16
  235.     bra        blit_left_32_gt16
  236. .x_not_minus
  237.     move.w    d0,d3
  238.     andi.w    #$f,d0              just the shift
  239.  
  240. * we want . . . 0-15 ->0, 16-31->2 etc.........
  241.  
  242.     eor.w    d0,d3                all but the shift
  243.     lsr.w    #3,d3
  244.     adda.w    d3,a0                adjust destination
  245.     move.w    sprite_screen_width(pc),d6                """""
  246.     subq.w    #6,d6
  247.     cmp.w    d6,d3                is it definately on screen ?
  248.     ble        blit_mid_32            yes
  249.     addq.w    #2,d6
  250.     cmp.w    d6,d3                is it mostly on screen ?
  251.     ble        blit_right_32_gt16    yes
  252.     addq.w    #2,d6
  253.     cmp.w    d6,d3                is it partly on screen ?
  254.     ble        blit_right_32_lt16    yes
  255.  
  256. .not_drawn
  257.     rts
  258. blit_right_32_gt16
  259.     andi.w    #$f,d0
  260.     lsl.w    #3,d0                                shifted for lookup
  261.     lea        right_16_lu,a2
  262.     movem.l    (a2,d0.w),d0/d1
  263.     movem.l    d0/d1,(BLTCON0).l
  264.  
  265.     move.w    #0,(BLTAMOD).l
  266.     move.w    #0,(BLTBMOD).l
  267.     move.w    #SCREEN_WIDTH-4,(BLTCMOD).l
  268.     move.w    #SCREEN_WIDTH-4,(BLTDMOD).l
  269.  
  270.     lsl.w    #6,d2
  271.     addq.w    #4/2,d2
  272.     bra        blit_sprite
  273.     rts
  274. blit_right_32_lt16
  275.     andi.w    #$f,d0
  276.     lsl.w    #3,d0                                shifted for lookup
  277.     lea        right_16_lu,a2
  278.     movem.l    (a2,d0.w),d0/d1
  279.     movem.l    d0/d1,(BLTCON0).l
  280.  
  281.     move.w    #2,(BLTAMOD).l
  282.     move.w    #2,(BLTBMOD).l
  283.     move.w    #SCREEN_WIDTH-2,(BLTCMOD).l
  284.     move.w    #SCREEN_WIDTH-2,(BLTDMOD).l
  285.  
  286.     lsl.w    #6,d2
  287.     addq.w    #2/2,d2
  288.     bra        blit_sprite
  289.     rts
  290. blit_left_32_lt16
  291.     subq.l    #2,a0
  292.     addq.l    #2,a1
  293.     andi.w    #$f,d0
  294.     lsl.w    #3,d0                                shifted for lookup
  295.     lea        left16lu,a2
  296.     movem.l    (a2,d0.w),d0/d1
  297.     movem.l    d0/d1,(BLTCON0).l
  298.  
  299.     move.w    #0,(BLTAMOD).l
  300.     move.w    #0,(BLTBMOD).l
  301.     move.w    #SCREEN_WIDTH-4,(BLTCMOD).l
  302.     move.w    #SCREEN_WIDTH-4,(BLTDMOD).l
  303.  
  304.     lsl.w    #6,d2
  305.     addq.w    #4/2,d2
  306.     bra        blit_sprite
  307.  
  308. blit_left_32_gt16
  309.     subq.l    #2,a0
  310.     andi.w    #$f,d0
  311.     lsl.w    #3,d0                                shifted for lookup
  312.     lea        left16lu,a2
  313.     movem.l    (a2,d0.w),d0/d1
  314.     movem.l    d0/d1,(BLTCON0).l
  315.  
  316.     move.w    #-2,(BLTAMOD).l
  317.     move.w    #-2,(BLTBMOD).l
  318.     move.w    #SCREEN_WIDTH-6,(BLTCMOD).l
  319.     move.w    #SCREEN_WIDTH-6,(BLTDMOD).l
  320.  
  321.     lsl.w    #6,d2
  322.     addq.w    #6/2,d2
  323.     bra        blit_sprite
  324.     rts
  325.  
  326. blit_mid_32
  327.     lsl.w    #3,d0                                shifted for lookup
  328.     lea        mid16lu,a2
  329.     movem.l    (a2,d0.w),d0/d1
  330.     movem.l    d0/d1,(BLTCON0).l
  331.  
  332.     move.w    #-2,(BLTAMOD).l
  333.     move.w    #-2,(BLTBMOD).l
  334.     move.w    #SCREEN_WIDTH-6,(BLTCMOD).l
  335.     move.w    #SCREEN_WIDTH-6,(BLTDMOD).l
  336.  
  337.     lsl.w    #6,d2
  338.     addq.w    #6/2,d2
  339.  
  340. blit_sprite *****************************************************************
  341. *  a0-> screen address; a1-> sprite data; d2 = blitsize; d7 = planesize     *
  342. *                    mods, cons & endmasks are set up                       *
  343. *****************************************************************************
  344.     BLIT_NASTY
  345. ;    move.w    #$ff0,(COLOR).l
  346.     lea        (a1,d7.w),a2
  347.     move.l    a0,(BLTCPT).l                        dest as source
  348.     move.l    a0,(BLTDPT).l                        dest
  349.     move.l  a2,(BLTBPT).l                        source
  350.     move.l    a1,(BLTAPT).l                        template
  351.  
  352.     move.w  d2,(BLTSIZE).l                        plane 0
  353.  
  354. ;    wait_blit
  355.  
  356.     add.w    d7,a2                                next plane of source
  357.     lea        PLANE_SIZE(a0),a0                    next plane of screen
  358.  
  359.     move.l    a0,(BLTCPT).l                        dest as source
  360.     move.l    a0,(BLTDPT).l                        dest
  361.     move.l  a2,(BLTBPT).l                        source
  362.     move.l    a1,(BLTAPT).l                        template
  363.  
  364.     move.w  d2,(BLTSIZE).l                        plane 1
  365.  
  366. ;    wait_blit
  367.  
  368.     add.w    d7,a2                                next plane of source
  369.     lea        PLANE_SIZE(a0),a0                    next plane of screen
  370.  
  371.     move.l    a0,(BLTCPT).l                        dest as source
  372.     move.l    a0,(BLTDPT).l                        dest
  373.     move.l  a2,(BLTBPT).l                        source
  374.     move.l    a1,(BLTAPT).l                        template
  375.  
  376.     move.w  d2,(BLTSIZE).l                        plane 2
  377.  
  378. ;    wait_blit
  379.  
  380.     add.w    d7,a2                                next plane of source
  381.     lea        PLANE_SIZE(a0),a0                    next plane of screen
  382.  
  383.     move.l    a0,(BLTCPT).l                        dest as source
  384.     move.l    a0,(BLTDPT).l                        dest
  385.     move.l  a2,(BLTBPT).l                        source
  386.     move.l    a1,(BLTAPT).l                        template
  387.  
  388.     move.w  d2,(BLTSIZE).l                        plane 3
  389.  
  390. ;    wait_blit
  391.  
  392.     BLIT_NICE
  393. ;    move.w    #0,(COLOR).l
  394.     rts
  395. *
  396.     xdef    lines_high
  397. lines_high            dc.w    200
  398.     xdef    sprite_screen_width
  399. sprite_screen_width    dc.w    40
  400.