home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 92 / asm / source / fargo / sprite.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  5.3 KB  |  297 lines

  1.     include    "tios.h"
  2.     include    "flib.h"
  3.     include    "hexlib.h"
  4.     xdef    _main
  5.     xdef    _comment
  6.  
  7. ;*****************************************************
  8.  
  9. _main:
  10.     move.w    #$0700,d0
  11.     trap    #1
  12.     move.l    $64,old_int_1
  13.     bclr.b    #2,$600001
  14.     move.l    #int_1,$64
  15.     bset.b    #2,$600001
  16.     trap    #1
  17.  
  18.     move.l    #121,d6
  19.     move.l    #62,d7
  20.     move.l    #4,d4
  21.     lea    Spritedata(pc),a5
  22.  
  23. main_loop:
  24.     move.l    d6,d0
  25.     move.l    #10,d1
  26.     move.l    #10,d2
  27.     move.l    #3,d4
  28.  
  29.     jsr    hexlib::put_hex
  30.     move.l    d7,d0
  31.     move.l    #10,d1
  32.     move.l    #20,d2
  33.     move.l    #3,d4
  34.     jsr    hexlib::put_hex
  35.  
  36.     move.w    d6,d0
  37.     move.w    d7,d1
  38.     move.l    a5,a0
  39.  
  40.     bsr    PutSprite
  41.  
  42. test_key:
  43.     tst.w    tios::kb_globals+$1C
  44.     beq    test_arrow
  45.  
  46.     clr.w    tios::kb_globals+$1C
  47.     move.w    tios::kb_globals+$1E,d0
  48.     cmp.w    #$108,d0
  49.     beq    exit
  50.  
  51. test_arrow:
  52.     move.w    tios::kb_globals+$C,d0
  53.     move.w    d0,d1
  54.     and.w    #$FFF0,d1
  55.     cmp.w    #$0050,d1
  56.     bne    wait_vbl
  57.  
  58. testdown:
  59.     btst    #1,d0
  60.     bne    testup
  61.     add.w    #1,d7
  62.     cmp.w    #112,d7
  63.     bcs    testup
  64.     move.w    #112,d7
  65.  
  66. testup:
  67.     btst    #3,d0
  68.     bne    testleft
  69.     sub.w    #1,d7
  70.     bcc    testleft
  71.     clr.w    d7
  72.  
  73. testleft:
  74.     btst    #2,d0
  75.     bne    testright
  76.     sub.w    #1,d6
  77.     bcc    testright
  78.     clr.w    d6
  79.  
  80. testright:
  81.     btst    #0,d0
  82.     bne    wait_vbl
  83.     add.w    #1,d6
  84.     cmp.w    #224,d6
  85.     bcs    wait_vbl
  86.     move.w    #224,d6
  87.  
  88. wait_vbl:
  89.     tst.w    vbl_phase
  90.     bne    wait_vbl
  91.     add.w    #5,vbl_phase    ; Haven't spent the time yet to
  92.                 ; figure out why this works.
  93.                 ; It used to use #4 as its constant.
  94.                 ; Andy Selle tried changing it to
  95.                 ; #5 and that made it work much more
  96.                 ; nicely.
  97.  
  98.     bsr    RemoveSprite
  99.     bra    main_loop
  100.  
  101. exit:
  102.     move.w    #$0700,d0
  103.     trap    #1
  104.     bclr.b    #2,$600001
  105.     move.l    old_int_1,$64
  106.     bset.b    #2,$600001
  107.     trap    #1
  108.  
  109.     rts
  110.  
  111. ;*****************************************************
  112.  
  113. int_1:
  114.     add.w    #1,vbl_phase
  115.     and.w    #3,vbl_phase
  116.  
  117.     move.l    old_int_1,-(a7)
  118.     rts
  119.  
  120. ;*****************************************************
  121.  
  122. ;16*16 sprite put
  123. ;data is of the format
  124. ;32 bytes sprite
  125. ;32 bytes mask
  126. ;a0=pointer to sprite
  127. ;d0=x coord, d1=y coord
  128.  
  129. PutSprite:
  130.     move.w  d1,d2  multiply d1 by 30
  131.     lsl.w   #4,d1
  132.     sub.w   d2,d1
  133.     lsl.w   #1,d1
  134.     ext.l   d1
  135.     move.l  d1,a1
  136.  
  137.     move.w  d0,d2
  138.     and.w   #$F,d2
  139.     and.w   #$fff0,d0
  140.     asr.w   #3,d0
  141.     ext.l   d0
  142.     adda.l  d0,a1  a1=address to start putting sprite at
  143.     adda.l  #LCD_MEM,a1
  144.  
  145.     lea backstore,a2
  146.  
  147.     move.l  a1,(a2)+
  148.     tst.w   d2
  149.     beq QuickPut    if x is on a word boundary we're OK
  150.     cmp.w   #8,d2
  151.     blt RightShift
  152.  
  153. LeftShift:
  154.     move.w  #1,(a2)+
  155.  
  156.     sub.w   #16,d2
  157.     neg.w   d2
  158.     move.w  #15,d3
  159. LeftLoop:
  160.  
  161.     move.l  (a1),d0
  162.     move.l  d0,(a2)+      store background
  163.  
  164.     move.l  #0,d1
  165.     move.w  32(a0),d1    get mask
  166.     lsl.l   d2,d1          shift it
  167.     not.l   d1
  168.     and.l   d1,d0         and with back
  169.     move.l  #0,d1
  170.     move.w  (a0)+,d1      get data
  171.     lsl.l   d2,d1          shift it
  172.     or.l    d1,d0           or with back+mask
  173.     move.l  d0,(a1)       put it on the screen
  174.     lea     30(a1),a1        next line
  175.     dbra    d3,LeftLoop      loop
  176.     rts
  177.  
  178. RightShift:
  179.     move.w #1,(a2)+
  180.     move.w #15,d3
  181. RightLoop:
  182.     move.l (a1),d0
  183.     move.l d0,(a2)+      store background
  184.  
  185.     move.l #0,d1
  186.     move.w 32(a0),d1    get mask
  187.     swap d1
  188.     lsr.l   d2,d1          shift it
  189.     not.l   d1
  190.     and.l   d1,d0         and with back
  191.  
  192.     move.l #0,d1
  193.     move.w (a0)+,d1      get data
  194.     swap d1
  195.     lsr.l d2,d1          shift it
  196.     or.l d1,d0           or with back+mask
  197.     move.l d0,(a1)       put it on the screen
  198.     lea 30(a1),a1        next line
  199.     dbra d3,RightLoop      loop
  200.     rts
  201.  
  202. QuickPut:
  203.     move.w #0,(a2)+
  204.     move.w #15,d3
  205. QuickLoop:
  206.     move.w (a1),d0
  207.     move.w d0,(a2)+      store background
  208.  
  209.     move.w 32(a0),d1    get mask
  210.     not.w   d1
  211.     and.w  d1,d0         and with back
  212.  
  213.     move.w (a0)+,d1      get data
  214.     or.w d1,d0           or with back+mask
  215.     move.w d0,(a1)       put it on the screen
  216.     lea 30(a1),a1        next line
  217.     dbra d3,QuickLoop      loop
  218.     rts
  219.  
  220. RemoveSprite:
  221.     lea backstore,a1
  222.     move.l (a1)+,a0
  223.     tst.w (a1)+
  224.     beq QuickRemove
  225.  
  226.         move.w #15,d1
  227. RemoveLoop:
  228.     move.l (a1)+,(a0)
  229.     lea 30(a0),a0
  230.     dbra d1,RemoveLoop
  231.     rts
  232.  
  233. QuickRemove:
  234.     move.w #15,d1
  235. QRemoveLoop:
  236.     move.w (a1)+,(a0)
  237.     lea 30(a0),a0
  238.     dbra d1,QRemoveLoop
  239.     rts
  240.  
  241. ;*****************************************************
  242.  
  243. Spritedata:
  244.     dc.w    %1111000000001111
  245.     dc.w    %0111100000011110
  246.     dc.w    %0011110000111100
  247.     dc.w    %0001111001111000
  248.     dc.w    %0000111111110000
  249.     dc.w    %0000011111100000
  250.     dc.w    %0000001001000000
  251.     dc.w    %0000001001000000
  252.     dc.w    %0000001001000000
  253.     dc.w    %0000011111100000
  254.     dc.w    %0000111111110000
  255.     dc.w    %0001111001111000
  256.     dc.w    %0011110000111100
  257.     dc.w    %0111100000011110
  258.     dc.w    %1111000000001111
  259.     dc.w    %0000000000000000
  260.  
  261.     dc.w    %1111100000011111
  262.     dc.w    %1111110000111111
  263.     dc.w    %0111111001111110
  264.     dc.w    %0011111111111100
  265.     dc.w    %0001111111111000
  266.     dc.w    %0000111111110000
  267.     dc.w    %0000011111100000
  268.     dc.w    %0000011111100000
  269.     dc.w    %0000011111100000
  270.     dc.w    %0000111111110000
  271.     dc.w    %0001111111111000
  272.     dc.w    %0011111111111100
  273.     dc.w    %0111111001111110
  274.     dc.w    %1111110000111111
  275.     dc.w    %1111100000011111
  276.     dc.w    %1111000000001111
  277.  
  278. ;*****************************************************
  279.  
  280. _comment    dc.b    "Sprite test",0
  281.  
  282. ;*****************************************************
  283.     BSS
  284.  
  285. old_int_1    dc.l    0
  286.  
  287. vbl_phase    dc.w    0
  288.  
  289. backstore:
  290.     dc.l 0
  291.     dc.w 0
  292.     dcb.l 16,0
  293.  
  294. ;*****************************************************
  295.  
  296.     end
  297.