home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !MAGS / !BONUS / COVERDSK / STFORMAT / STF22.ZIP / STF22.MSA / MOLYNEUX_SPRITES.S < prev    next >
Text File  |  1991-03-11  |  15KB  |  542 lines

  1. *****************************************************************************
  2. *                   SET YOUR TAB SIZE TO 4 !!!!!!!!!!!!                     *
  3. *          OTHERWISE IT WILL LOOK LIKE A TOTAL MESS !!!!!!!!!!!             *
  4. *****************************************************************************
  5. REZ            equ    $ff8260
  6. H_PAL          equ $fffff8240
  7. VBI            equ    $70
  8. KB_DATA        equ $fffffc02
  9. KB_SPACE    equ $39
  10. *****************************************************************************
  11. PRINTLINE    equ    $9
  12. FOPEN        equ $3d
  13. FCLOSE        equ    $3e
  14. FREAD        equ    $3f
  15. *****************************************************************************
  16. *            This is about the cleanest startup I can think of              *
  17. *****************************************************************************
  18. start
  19.     clr.l    -(sp)                        OS startup stuff
  20.     move.w    #$20,-(sp)
  21.     trap    #1                           stick it in supervisor mode
  22.     addq.l    #6,sp
  23.     move.l    d0,old_ssp
  24.     move.w    #3,-(sp)                    logbase to find the screen
  25.     trap    #14
  26.     addq.l    #2,sp
  27.     move.l    d0,_d_screen                currently displayed screen
  28.     move.l    d0,old_screen
  29.     move.l    #w_screen,d0
  30.     addi.l    #256,d0                        ensure it's on a 256 byte boundry
  31.     andi.l    #$ffffff00,d0
  32.     move.l    d0,_w_screen                and you have another screen
  33.     move.l  VBI,old_vbi                    back up the old vbi
  34.     move.l    #_vbi,VBI                    patch in the new one
  35.     bsr        _main                        yer actual startup
  36.     move.l  old_vbi,VBI
  37.     move.l    old_ssp,sp                    clean exit
  38.  
  39.     move.w    #-1,-(sp)                    res
  40.     move.l    old_screen,-(sp)            reset the screen pos
  41.     move.l    old_screen,-(sp)
  42.     move.w    #5,-(sp)
  43.     trap    #14
  44.     lea        12(sp),sp
  45.     clr.w    -(sp)
  46.     trap    #1
  47. *****************************************************************************
  48. _main
  49.     lea        spr32_fname,a0                the sprite file name
  50.     lea        _spr_32,a1                    the address to load the file to
  51.     move.l    #256*10*32,d0                the size of the file
  52.     jsr     _load_file                    read 32*32 sprites
  53.     blt.s    error_end
  54.         bsr        _display                the main game loop
  55. error_end
  56.     rts
  57. *****************************************************************************
  58. _display
  59.     move.b  REZ,old_rez                    store the old resolution
  60.     move.b    #0,REZ                        whack it into lo rez
  61.     movem.l    palette,d0-d7
  62.     movem.l    d0-d7,H_PAL                 how to set the palette in 2 instructions
  63.  
  64. disploop
  65.         bsr        _wait_vbi                wait for the vbi
  66.         move.l    _w_screen,a0
  67.         bsr        _clear_screen            clear the screen
  68.  
  69. * draw the sprites
  70.  
  71.         move.w    #32,d0                    the sprites coordinates
  72.         move.w    #32,d1
  73.         move.w    #0,d2                    the image number to draw
  74.         jsr        _spr3232                draw a 32x32 sprite
  75.  
  76. * flip screens
  77.  
  78.         bsr        _swap_screens
  79.  
  80. * now do any non graphic work like moving the sprites
  81. * in here goes any routines to adjust the coordinates of the sprites
  82.  
  83.  
  84.  
  85. * look to see if the space bar is pressed if so quit
  86.  
  87.         cmp.b    #KB_SPACE,KB_DATA
  88.         bne        disploop
  89.     move.b    old_rez,REZ                    stick it back in original mode
  90.     rts
  91. *****************************************************************************
  92. ; a0-> screen to clear, this is the quickest way I can think of to clear screen
  93. _clear_screen
  94.     lea        32000(a0),a0    move to end of screen
  95.     moveq    #0,d1            clear 13 registers
  96.     moveq    #0,d2
  97.     moveq    #0,d3
  98.     moveq    #0,d4
  99.     moveq    #0,d5
  100.     moveq    #0,d6
  101.     moveq    #0,d7
  102.     move.l    d1,a1
  103.     move.l    d1,a2
  104.     move.l    d1,a3
  105.     move.l    d1,a4
  106.     move.l    d1,a5
  107.     move.l    d1,a6
  108. ;    we can clear 13*4 (52) bytes in one go
  109. ;    615 * 52 is 31980, 20 bytes short of the screen size
  110.     move.w    #615-1,d0        loop counter, -1 coz of the way dbra works
  111. cs_loop
  112.         movem.l    d1-d7/a1-a6,-(a0)
  113.         dbra    d0,cs_loop
  114.     movem.l d1-d5,-(a0)        do the odd 20 bytes (5 regs)
  115.     rts
  116. *****************************************************************************
  117. _wait_vbi
  118.     tst.b    _vbi_done
  119.     beq.s   _wait_vbi
  120.     rts
  121. *****************************************************************************
  122. _vbi
  123.     st        _vbi_done
  124.     rte
  125. *****************************************************************************
  126. _swap_screens
  127.     move.l    _w_screen,d0            d0 = screen address
  128.     move.l    _d_screen,d1
  129.     move.l    d1,_w_screen
  130.     move.l    d0,_d_screen            d0 = xxxx high low    0000
  131.  
  132.     lsr.w    #8,d0
  133.     move.l    d0,$ffff8200.w            d0 = xxxx high xxxx low
  134.  
  135.     sf        _vbi_done
  136.     rts
  137. *****************************************************************************
  138. ; d0 = x, d1 = y, d2 = sprite number
  139. _spr3232
  140.     move.l    _w_screen,a0        draw on _w_screen
  141.     lea        _spr_32,a1
  142.     mulu    #640,d2                size of a 32*32 sprite
  143.     add.w    d2,a1
  144.     moveq    #32,d2
  145.     bsr        _s32_draw
  146.     rts
  147. *****************************************************************************
  148. *    16 pixel wide sprite draw                                                *
  149. *    d0.w = QX                                                                *
  150. *    d1.w = QY                                                                *
  151. *    d2.w = sprite height                                                    *
  152. *   a0 -> screen                                                             *
  153. *    a1    -> the sprite data                                                    *
  154. *****************************************************************************
  155. LINES_HIGH    set    200
  156. _s16_draw
  157.     tst.w    d1                    is y less than 0
  158.     bge.s    y_not_minus_16        no, ok.
  159. *****************************************************************************
  160. *    QY is negative
  161.     neg.w    d1
  162.     sub.w    d1,d2                do we see any of it ?
  163.     ble        not_drawn_16        no, dont draw it at all
  164. ; a 16 pixel wide sprite has 10 bytes a line, so we have to multiply by 10
  165.     add.w    d1,d1                *2
  166.     move.w    d1,d7
  167.     add.w    d1,d1                *4
  168.     add.w    d1,d1                *8
  169.     add.w    d7,d1                In2Data and QY are the same reg
  170.     adda.w    d1,a1                move into the source the required no. of line
  171.     bra.s    y_clipped_16
  172. *********
  173. y_not_minus_16
  174.     moveq    #256-LINES_HIGH,d6
  175.     neg.b    d6                    quicker than move.w #LINES_HIGH,d6
  176.     cmp.w    d6,d1
  177.     bge     not_drawn_16
  178.     move.w    d1,d7
  179.     add.w    d7,d7                *2
  180.     add.w    d7,d7                *4
  181.     add.w    d1,d7                *5
  182.     lsl.w    #5,d7                *5*32 (28 clock cycles, less than 70 for *160
  183.     adda.w    d7,a0                move down the screen
  184.     add.w    d2,d1
  185.     subi.w    #LINES_HIGH,d1
  186.     blt.s    y_clipped_16
  187.     sub.w    d1,d2                adjust height of sprite to fit it on
  188. y_clipped_16
  189. *****************************************************************************
  190. *    I suppose I better do the QX stuff now
  191.     tst.w    d0
  192.     bge.s    x_not_minus_16        x ok, well at least it isn't negative!
  193.     cmpi.w    #-16,d0
  194.     ble.s    not_drawn_16        it is off screen
  195.     moveq    #0,d1
  196.     bra        _left_16
  197. x_not_minus_16
  198.     move.w    d0,d7
  199.     andi.w    #$f,d0                QX and QShift are the same Reg
  200.  
  201. * we want . . . 0-15 ->0, 16-31->8 etc.........
  202.  
  203.     andi.w    #$fff0,d7
  204.     lsr.w    #1,d7
  205.     moveq    #256-160,d6
  206.     neg.b    d6
  207.     cmp.w    d6,d7                is it off the right side of the screen ?
  208.     bge.s    not_drawn_16        yes
  209.     adda.w    d7,a0                adjust destination
  210.     subq.w    #8,d6
  211.     cmp.w    d6,d7
  212.     bne        _all_16
  213.  
  214. *    right hand only case
  215.  
  216.     moveq    #0,d1
  217.     bra        _right_16
  218. not_drawn_16
  219.     rts
  220.  
  221. *****************************************************************************
  222. *    32 pixel wide sprite draw                                                *
  223. *    d0.w = QX                                                                *
  224. *    d1.w = QY                                                                *
  225. *    d2.w = sprite height                                                    *
  226. *   a0 -> screen                                                             *
  227. *    a1    -> the sprite data                                                    *
  228. *****************************************************************************
  229. _s32_draw
  230.     tst.w    d1                    is y less than 0
  231.     bge.s    y_not_minus_32        no, ok.
  232. *****************************************************************************
  233. *    QY is negative
  234.     neg.w    d1
  235.     sub.w    d1,d2                do we see any of it ?
  236.     ble        not_drawn_32        no, dont draw it at all
  237. ; a 32 pixel wide sprite has 20 bytes a line, so we have to multiply by 20
  238.     move.w    d1,d7
  239.     add.w    d1,d1                *2
  240.     add.w    d1,d1                *4
  241.     add.w    d7,d1                *5
  242.     add.w    d1,d1                *10
  243.     add.w    d1,d1                *20
  244.     adda.w    d1,a1                move into the source the required no. of line
  245.     bra.s    y_clipped_32
  246. *********
  247. y_not_minus_32
  248.     moveq    #256-LINES_HIGH,d6
  249.     neg.b    d6                    quicker than move.w #LINES_HIGH,d6
  250.     cmp.w    d6,d1
  251.     bge     not_drawn_32
  252.     move.w    d1,d7
  253.     add.w    d7,d7                *2
  254.     add.w    d7,d7                *4
  255.     add.w    d1,d7                *5
  256.     lsl.w    #5,d7                *5*32 (28 clock cycles, less than 70 for *160
  257.     adda.w    d7,a0                move down the screen
  258.     add.w    d2,d1
  259.     subi.w    #LINES_HIGH,d1
  260.     blt.s    y_clipped_32
  261.     sub.w    d1,d2                adjust height of sprite to fit it on
  262. y_clipped_32
  263. *****************************************************************************
  264. *    I suppose I better do the QX stuff now
  265.     tst.w    d0
  266.     bge.s    x_not_minus_32        x ok, well at least it isn't negative!
  267.     cmpi.w    #-16,d0
  268.     ble.s    may_be_32
  269.     moveq    #0,d1
  270.     bra        _left_32
  271. may_be_32
  272.     cmpi.w    #-32,d0
  273.     ble.s    not_drawn_32
  274.     moveq    #10,d1
  275.     bra        _left_16
  276. x_not_minus_32
  277.     move.w    d0,d7
  278.     andi.w    #$f,d0                QX and QShift are the same Reg
  279.  
  280. * we want . . . 0-15 ->0, 16-31->8 etc.........
  281.  
  282.     andi.w    #$fff0,d7
  283.     lsr.w    #1,d7
  284.     moveq    #256-(160-16),d6
  285.     neg.b    d6
  286.     adda.w    d7,a0                adjust destination
  287.     cmp.w    d6,d7                is it definately on screen ?
  288.     bmi        _all_32                yes
  289.     addq.w    #8,d6
  290.     moveq    #0,d1
  291.     cmp.w    d6,d7
  292.     bmi        _right_32
  293.     addq.w    #8,d6
  294.     moveq    #10,d1
  295.     cmp.w    d6,d7
  296.     bmi        _right_16
  297. not_drawn_32
  298.     rts
  299. *****************************************************************************
  300. *    The low level routines, may be useful for other stuff at some stage..    *
  301. *****************************************************************************
  302. DO_RIGHT    macro
  303.     moveq    #-1,d3
  304.     move.w    (a1)+,d3            get the QTemplate
  305.     ror.l    d0,d3                rotate it
  306.  
  307.     moveq    #0,d4
  308.     move.w    (a1)+,d4            get QPlane 0
  309.     ror.l    d0,d4                rotate it
  310.     move.w    (a0)+,d5
  311.     and.w    d3,d5
  312.     or.w    d5,d4                QPlane 0 made
  313.  
  314.     moveq    #0,d5
  315.     move.w    (a1)+,d5            get QPlane 1
  316.     ror.l    d0,d5                rotate it
  317.     move.w    (a0)+,d6
  318.     and.w    d3,d6
  319.     or.w    d6,d5                QPlane 1 made
  320.  
  321.     moveq    #0,d6
  322.     move.w    (a1)+,d6            get QPlane 2
  323.     ror.l    d0,d6                rotate it
  324.     move.w    (a0)+,d7
  325.     and.w    d3,d7
  326.     or.w    d7,d6                QPlane 0 made
  327.  
  328.     moveq    #0,d7
  329.     move.w    (a1)+,d7            get QPlane 3
  330.     ror.l    d0,d7                rotate it
  331.     and.w    (a0)+,d3            may as well corrupt the QTemplate this time
  332.     or.w    d3,d7                QPlane 3 made
  333.     endm
  334. *************
  335. DO_LEFTM    macro
  336.     swap    d3
  337.     swap    d4
  338.     move.w    (a0)+,d5
  339.     and.w    d3,d5
  340.     or.w    d5,d4                QPlane 0 made
  341.  
  342.     swap    d5
  343.     move.w    (a0)+,d6
  344.     and.w    d3,d6
  345.     or.w    d6,d5                QPlane 1 made
  346.  
  347.     swap    d6
  348.     move.w    (a0)+,d7
  349.     and.w    d3,d7
  350.     or.w    d7,d6                QPlane 2 made
  351.  
  352.     swap    d7
  353.     and.w    (a0)+,d3            corrupting QTemplate
  354.     or.w    d3,d7                QPlane 3 made
  355.     endm
  356. *******
  357. DO_LEFT macro
  358.     moveq    #-1,d3
  359.     move.w    (a1)+,d3            get the QTemplate
  360.     rol.l    d0,d3                rotate it
  361.  
  362.     move.w    (a1)+,d4            get QPlane 0
  363.     lsl.w    d0,d4                rotate it
  364.     move.w    (a0)+,d5
  365.     and.w    d3,d5
  366.     or.w    d5,d4                QPlane 0 made
  367.  
  368.     move.w    (a1)+,d5            get QPlane 1
  369.     lsl.w    d0,d5                rotate it
  370.     move.w    (a0)+,d6
  371.     and.w    d3,d6
  372.     or.w    d6,d5                QPlane 1 made
  373.  
  374.     move.w    (a1)+,d6            get QPlane 2
  375.     lsl.w    d0,d6                rotate it
  376.     move.w    (a0)+,d7
  377.     and.w    d3,d7
  378.     or.w    d7,d6                QPlane 0 made
  379.  
  380.     move.w    (a1)+,d7            get QPlane 3
  381.     lsl.w    d0,d7                rotate it
  382.     and.w    (a0)+,d3            may as well corrupt the QTemplate this time
  383.     or.w    d3,d7                QPlane 3 made
  384.     ENDM
  385. *****************************************************************************
  386. _all_16
  387. ; A0 = QSource, A1 = QDest, D0 = QShift, D2 = Height
  388.  
  389.     moveq    #256-(160-16),d1
  390.     neg.b    d1
  391.     subq.w    #1,d2                for dbra
  392. a16_loop
  393.     DO_RIGHT
  394.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  395.     DO_LEFTM
  396.     movem.w d4-d7,-8(a0)        another one
  397.     adda.w    d1,a0
  398.     dbra    d2,a16_loop
  399.     rts
  400. ********************************************************************
  401. _left_16
  402. ; A0 = QSource, A1 = QDest, D0 = QShift, D1 = QSkip, D2 = Height
  403.     subq.w    #1,d2
  404.     neg.w    d0
  405.     andi.w    #$f,d0
  406. l16_loop
  407.     adda.w    d1,a1
  408.     DO_LEFT
  409.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  410.     lea        160-8(a0),a0
  411.     dbra    d2,l16_loop
  412.     rts
  413. ********************************************************************
  414. _right_16
  415. ; A0 = QSource, A1 = QDest, D0 = QShift, D1 = QSkip, D2 = Height
  416.     subq.w    #1,d2
  417. r16_loop
  418.     DO_RIGHT
  419.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  420.     lea        160-8(a0),a0
  421.     adda.w    d1,a1
  422.     dbra    d2,r16_loop
  423.     rts
  424.  
  425. *****************************************************************************
  426. _all_32
  427. ; A0 = QSource, A1 = QDest, D0 = QShift, D2 = Height
  428.  
  429.     moveq    #256-(160-24),d1
  430.     neg.b    d1
  431.     subq.w    #1,d2                for dbra
  432. a32_loop
  433.     DO_RIGHT
  434.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  435.     DO_LEFTM
  436.     subq.l    #8,a0
  437.     movem.w d4-d7,(a0)             another one
  438.     DO_RIGHT
  439.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  440.     DO_LEFTM
  441.     movem.w d4-d7,-8(a0)        another one
  442.     adda.w    d1,a0
  443.     dbra    d2,a32_loop
  444.     rts
  445. *****************************************************************************
  446. _left_32
  447. ; A0 = a1, A1 = QDest, D0 = QShift, D1 = QSkip, D2 = Height
  448.     subq.w    #1,d2
  449.     move.w    d0,d4
  450.     neg.w    d4
  451.     moveq    #$f,d5
  452.     and.w    d5,d4
  453.     and.w    d5,d0
  454.     swap    d0
  455.     move.w    d4,d0
  456. l32_loop
  457.     adda.w    d1,a1
  458.     DO_LEFT
  459.     subq.l    #8,a0
  460.     movem.w d4-d7,(a0)             i had to get a movem in there somewhere
  461.     swap    d0
  462.     DO_RIGHT
  463.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  464.     DO_LEFTM
  465.     movem.w d4-d7,-8(a0)        another one
  466.     swap    d0
  467.     lea        160-16(a0),a0
  468.     dbra    d2,l32_loop
  469.     rts
  470. *****************************************************************************
  471. _right_32
  472. ; A0 = QSource, A1 = QDest, D0 = QShift, D1 = QSkip, D2 = Height
  473.     subq.w    #1,d2
  474.     andi.w    #$f,d0
  475. r32_loop
  476.     DO_RIGHT
  477.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  478.     DO_LEFTM
  479.     subq.l    #8,a0
  480.     movem.w d4-d7,(a0)             another one
  481.     DO_RIGHT
  482.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  483.     lea        160-16(a0),a0
  484.     adda.w    d1,a1
  485.     dbra    d2,r32_loop
  486.     rts
  487. *****************************************************************************
  488. ; a0-> filename a1-> destination d0 = length
  489. ; on return d0 = file length actually read or -1 if read failed
  490. _load_file
  491.     move.l    d0,d6
  492.     clr.w    -(sp)               read
  493.     move.l    a0,-(sp)            -> filename
  494.     move.w    #FOPEN,-(sp)
  495.     trap    #1                    open the file
  496.     addq.l    #8,sp                readjust the stack
  497.     move.w    d0,d7                handle
  498.     ble.s   file_not_found
  499. *
  500.     move.l  a1,-(sp)            destination memory
  501.     move.l    d6,-(sp)
  502.     move.w    d7,-(sp)            file handle
  503.     move.w    #FREAD,-(sp)
  504.     trap    #1                    read the file
  505.     lea        12(sp),sp            the quick way of adding 12 to the stack
  506.     move.l    d0,d6                length read
  507. *
  508.     move.w    d7,-(sp)            file handle
  509.     move.w    #FCLOSE,-(sp)
  510.     trap    #1                    close the file
  511.     addq.l    #4,sp
  512.     move.l    d6,d0                so we can return the file length
  513.     rts
  514. file_not_found
  515.     pea        fnf_msg(pc)            address of the error message
  516.     move.w    #PRINTLINE,-(sp)
  517.     trap    #1                    print it
  518.     addq.l    #6,sp
  519.     moveq    #-1,d0
  520.     rts
  521. *****************************************************************************
  522. fnf_msg        dc.b    7,'FILE NOT FOUND',10,13,7,0
  523. spr16_fname    dc.b    'sprite16.dat',0
  524. spr32_fname    dc.b    'sprite32.dat',0
  525.     even
  526. palette        dc.w    $000,$321,$432,$543,$400,$520,$630,$651
  527.             dc.w    $331,$441,$551,$661,$013,$034,$345,$555
  528. *****************************************************************************
  529. ;    section    bss            use this line on devpac 2, it saves a lot of disk access
  530. old_rez        ds.b    1
  531. _vbi_done    ds.b    1
  532.     even
  533. old_vbi        ds.l    1
  534. old_ssp        ds.l    1
  535. old_screen    ds.l    1
  536. _d_screen    ds.l    1
  537. _w_screen    ds.l    1
  538. w_screen    ds.b    32000+256    screen has to be on a 256 byte boundry
  539. _spr_32        ds.b    256*10*32    the max size of the file from art studio
  540.  
  541. *
  542.