home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI07.ARJ / ictari.07 / ASSEMBLY / SPRITES / SPRITE.S < prev    next >
Text File  |  1993-09-03  |  7KB  |  318 lines

  1. ;Initialise sprite data files and table
  2. ;For use with .OBJ files from Neochrome Master
  3. ;ENTRY 'sprite_file' string holds path and filename of sprite data file
  4. ;EXIT  various registers corrupted
  5. ;      (screen) holds screen start address
  6. ;      (sprite_tab..) buffer holds table of sprite data
  7. ;      (sprite_data..) buffer holds sprite data
  8. ;      (sprite_mask..) buffer holds sprite mask data
  9. ;      d0 = 0 = file loaded OK or
  10. ;      d0 = negative value = file error (d0=error code)
  11.  
  12. sprite_init    move    #3,-(sp)       fetch screen address
  13.     trap    #14
  14.     addq.l    #2,sp
  15.     move.l    d0,screen       save screen start address
  16.  
  17.     move    #2,-(sp)       open sprite data file
  18.     pea    sprite_file   define path & filename
  19.     move    #$3d,-(sp)
  20.     trap    #1
  21.     addq.l    #8,sp
  22.     move    d0,file_handle
  23.     tst.l    d0
  24.     bmi    sprite_init3          quit if error
  25.  
  26.     lea    sprite_mask,a5    a5 points at mask data
  27.     lea    sprite_tab,a1    a1 points at sprite table
  28.  
  29.     pea    sprite_data    read sprite data
  30.     move.l    #$7fffffff,-(sp)      into sprite data buffer
  31.     move    file_handle,-(sp)
  32.     move    #$3f,-(sp)
  33.     trap    #1
  34.     add.l    #12,sp
  35.     tst.l    d0
  36.     bmi    sprite_init3    quit if error
  37.  
  38.     move    file_handle,-(sp)     close file
  39.     move    #$3e,-(sp)
  40.     trap    #1
  41.     addq.l    #4,sp
  42.     tst.l    d0
  43.     bmi    sprite_init3    quit if error
  44.  
  45.     lea    sprite_data+8,a0    calc No of sprites
  46.     add    (a0),a0
  47.     add    #2+4,a0    set a0 to 1st spr header
  48.     move    (a0)+,d5    fetch No of sprites &
  49.     sub    #1,d5    correct for dbra instr
  50.     move.l    a0,d4    save a0 in d4
  51.  
  52. sprite_init1    move    10(a0),(a1)+    copy width to sprite table
  53.     move    6(a0),d0    copy height-1 to sprite table
  54.     sub    #1,d0    
  55.     move    d0,(a1)+    
  56.     move.b    16(a0),d0    copy x offset to table ?
  57.     and.l    #$ff,d0
  58.     move    d0,(a1)+
  59.     move.b    17(a0),d0    copy y offset to table ?
  60.     move    d0,(a1)+
  61.     move.l    (a0),d0    copy sprite data address 
  62.     add.l    d4,d0    to sprite table
  63.     move.l    d0,(a1)+
  64.     move.l    d0,a2    and into a2
  65.     move    10(a0),d0    calc size of sprite data
  66.     mulu    6(a0),d0
  67.     move.l    a5,(a1)+    copy sprite mask address to table
  68.     lsr    #3,d0    calc width of mask-1
  69.     sub    #1,d0
  70. sprite_init2    clr    (a5)    generate mask data
  71.     move    (a2)+,d2
  72.     or    d2,(a5)    and copy to buffer
  73.     move    (a2)+,d2
  74.     or    d2,(a5)
  75.     move    (a2)+,d2
  76.     or    d2,(a5)
  77.     move    (a2)+,d2
  78.     or    d2,(a5)+
  79.     dbra    d0,sprite_init2    repeat
  80.     add.l    #20,a0    access next sprite
  81.     dbra    d5,sprite_init1    repeat for all sprites
  82.     clr.l    d0    file loaded OK (d0=0)
  83. sprite_init3    rts
  84.     
  85.  
  86.  
  87. ;Draw stationary sprite image 
  88. ;ENTRY d0=x co-ord of hot spot (0-319)
  89. ;      d1=y co-ord of hot spot (0-199)
  90. ;      d2=sprite number (1-n)
  91. ;      sprite_tab table initialised by sprite_init
  92. ;      (screen) holds screen or buffer addr
  93. ;EXIT  No regs changed
  94.  
  95. s_sprite    movem.l    d0-d5/a0-a3,-(sp)
  96.     lea    sprite_tab,a0    set table pointer
  97.     and.l    #$ffff,d2
  98.     sub    #1,d2
  99.     lsl    #4,d2
  100.     add.l    d2,a0
  101.  
  102.     move    (a0)+,d2    d2=width in bytes
  103.     move    (a0)+,d5    d5=No of scanlines-1
  104.     sub    (a0)+,d0    x hot spot
  105.     sub    (a0)+,d1    y hot spot
  106.     move.l    (a0)+,a1    a1=sprite data
  107.     move.l    (a0)+,a3    a3=mask data
  108.  
  109.     move.l    screen,a0    a0=screen start
  110.     move.l    a0,a2
  111.     add    #32000,a2    a2=screen end
  112.     mulu    #160,d1
  113.     add.l    d1,a0    a0=sprite line address
  114.     move    d0,d4
  115.     lsr    #4,d0
  116.     lsl    #3,d0
  117.     add    d0,a0    a0=sprite byte address
  118.     lsr    #3,d2
  119.     subq    #2,d2    d2=corrected width
  120.     and    #$0f,d4    d4=bit shift value
  121. s_sprite6    cmp.l    a2,a0    chk if sprite off bottom of scrn
  122.     bgt    s_sprite2
  123.     cmp.l    screen,a0    chk if sprite off top of scrn
  124.     blt    s_sprite2
  125.  
  126.     movem.l    d2/a0,-(sp) display left chunk
  127.     moveq    #0,d3
  128.     move    (a3),d3
  129.     lsr.l    d4,d3
  130.     not.l    d3
  131.     move    #4-1,d1
  132. s_sprite8    moveq    #0,d0
  133.     move    (a1)+,d0
  134.     lsr.l    d4,d0
  135.     and    d3,(a0)
  136.     or    d0,(a0)+
  137.     dbra    d1,s_sprite8
  138.     subq.l    #8,a1
  139.     cmp    #-1,d2
  140.     beq    s_sprite1
  141.  
  142. s_sprite7    move.l    (a3),d3    display centre chunks
  143.     lsr.l    d4,d3
  144.     not.l    d3
  145.     addq.l    #2,a3
  146.     move    #4-1,d1
  147. s_sprite9    move.l    (a1),d0
  148.     move    8(a1),d0
  149.     addq.l    #2,a1
  150.     lsr.l    d4,d0
  151.     and    d3,(a0)
  152.     or    d0,(a0)+
  153.     dbra    d1,s_sprite9
  154.     dbra    d2,s_sprite7
  155.  
  156. s_sprite1    move.l    (a3),d3    display right chunk
  157.     clr    d3
  158.     addq.l    #2,a3
  159.     lsr.l    d4,d3
  160.     not.l    d3
  161.     move    #4-1,d1
  162. s_sprite0    move.l    (a1),d0
  163.     clr    d0
  164.     addq.l    #2,a1
  165.     lsr.l    d4,d0
  166.     and    d3,(a0)
  167.     or    d0,(a0)+
  168.     dbra    d1,s_sprite0    
  169.     movem.l    (sp)+,d2/a0
  170.     add.l    #160,a0
  171.     dbra    d5,s_sprite6  repeat lines
  172. s_sprite2    movem.l    (sp)+,d0-d5/a0-a3
  173.     rts
  174.  
  175. ;Draw sprite and save backgrnd
  176. ;ENTRY d0=x co-ord (0-319)
  177. ;      d1=y co-ord (0-199)
  178. ;      d2=sprite No (1-nn)
  179. ;      (screen) holds screen addr
  180. ;      (spr_buffer) clear or holds data
  181. ;      (sprite_tab..) holds table
  182. ;EXIT  Old sprite restored and 
  183. ;      new sprite displayed
  184.  
  185. m_sprite    movem.l    d0-d5/a0-a4,-(sp)
  186.     lea    sprite_tab,a0    set table pointer
  187.     and.l    #$ffff,d2
  188.     sub    #1,d2
  189.     lsl    #4,d2
  190.     add.l    d2,a0
  191.  
  192.     move.l    screen,a4    a4=screen limit
  193.     add    #32000,a4    
  194.  
  195.     move    (a0)+,d2    d2=width in bytes
  196.     move    (a0)+,d5    d5=No of scanlines-1
  197.     sub    (a0)+,d0    x hot spot ??
  198.     sub    (a0)+,d1    y hot spot ??
  199.     move.l    (a0)+,a1    a1=sprite data
  200.     move.l    (a0)+,a3    a3=mask data
  201.     
  202.     lea    spr_buffer,a2
  203.     tst.l    (a2)
  204.     beq    m_sprite1    skip if no image stored
  205.     
  206.     move.l    (a2)+,a0    fetch scrn address
  207.     move    (a2)+,d6    fetch width (bytes)
  208.     move    (a2)+,d3    fetch height
  209.         
  210. m_sprite2    movem.l    d6/a0,-(sp)   copy buffer to scrn
  211. m_sprite3    move    (a2)+,(a0)+
  212.     dbra    d6,m_sprite3
  213.     movem.l    (sp)+,d6/a0
  214.     add.l    #160,a0
  215.     cmp.l    a4,a0
  216.     bgt    m_sprite13
  217.     dbra    d3,m_sprite2
  218. m_sprite13    lea    spr_buffer,a2
  219.     clr.l    (a2)    erase buffer
  220.  
  221. m_sprite1    cmp    #319,d0    exit if invalid co-ords
  222.     bhi    m_sprite10
  223.     cmp    #199,d1
  224.     bhi    m_sprite10
  225.     
  226.     move.l    screen,a0    calc sprite addr
  227.     mulu    #160,d1
  228.     add.l    d1,a0
  229.     
  230.     move    d0,d4
  231.     lsr    #4,d0
  232.     lsl    #3,d0
  233.     add    d0,a0
  234.     
  235.     move    d2,d3
  236.     lsr    #1,d3
  237.     addq    #4,d3
  238.     
  239.     move.l    a0,(a2)+    copy addr to buffer
  240.     move    d3,(a2)+    copy width to buffer
  241.     move    d5,(a2)+    copy height to buff
  242.     
  243.     movem.l    d5/a0,-(sp)  copy screen data to buffer
  244. m_sprite4    movem.l    d3/a0,-(sp)
  245. m_sprite5    move    (a0)+,(a2)+
  246.     dbra    d3,m_sprite5
  247.     movem.l    (sp)+,d3/a0
  248.     add.l    #160,a0
  249.     cmp.l    a4,a0
  250.     bgt    m_sprite12
  251.     dbra    d5,m_sprite4
  252. m_sprite12    movem.l    (sp)+,d5/a0
  253.     
  254.     lsr    #3,d2    
  255.     subq    #2,d2
  256.     and    #$0f,d4
  257. m_sprite6    cmp.l    a4,a0    chk end of screen    
  258.     bgt    m_sprite10
  259.     cmp.l    screen,a0    chk start of screen
  260.     blt    m_sprite10
  261.     
  262.     movem.l    d2/a0,-(sp)  display sprite
  263.     moveq    #0,d3
  264.     move    (a3),d3
  265.     lsr.l    d4,d3
  266.     not.l    d3
  267.     move    #4-1,d1
  268. m_sprite8    moveq    #0,d0
  269.     move    (a1)+,d0
  270.     lsr.l    d4,d0
  271.     and    d3,(a0)
  272.     or    d0,(a0)+
  273.     dbra    d1,m_sprite8
  274.     subq.l    #8,a1
  275.     cmp    #-1,d2
  276.     beq    m_sprite11
  277. m_sprite7    move.l    (a3),d3
  278.     lsr.l    d4,d3
  279.     not.l    d3
  280.     addq.l    #2,a3
  281.     move    #4-1,d1
  282. m_sprite9    move.l    (a1),d0
  283.     move    8(a1),d0
  284.     addq.l    #2,a1
  285.     lsr.l    d4,d0
  286.     and    d3,(a0)
  287.     or    d0,(a0)+
  288.     dbra    d1,m_sprite9
  289.     dbra    d2,m_sprite7
  290. m_sprite11    move.l    (a3),d3
  291.     clr    d3
  292.     addq.l    #2,a3
  293.     lsr.l    d4,d3
  294.     not.l    d3
  295.     move    #4-1,d1
  296. m_sprite0    move.l    (a1),d0
  297.     clr    d0
  298.     addq.l    #2,a1
  299.     lsr.l    d4,d0
  300.     and    d3,(a0)
  301.     or    d0,(a0)+
  302.     dbra    d1,m_sprite0    
  303.     movem.l    (sp)+,d2/a0
  304.     add.l    #160,a0
  305.     dbra    d5,m_sprite6
  306. m_sprite10    movem.l    (sp)+,d0-d5/a0-a4
  307.     rts
  308.  
  309. sprite_file    dc.b    'FILENAME.OBJ',0    filepath/filename
  310.         even
  311.         
  312. file_handle    ds.w    1    file handle
  313. screen        ds.l    1    screen address
  314. sprite_tab        ds.b    No of sprites*16    sprite table
  315. sprite_data    ds.b    Size of .OBJ file    sprite data
  316. sprite_mask    ds.b    sprite_data/4    mask data
  317. spr_buffer        ds.b    (width in bytes+4)*(height)+8    temp buffer (largest sprite)
  318.