home *** CD-ROM | disk | FTP | other *** search
/ Fujiology Archive / fujiology_archive_v1_0.iso / !MAGS / !BONUS / COVERDSK / STFORMAT / STF24.ZIP / STF24.MSA / BULLFROG_SPRITES.S < prev    next >
Text File  |  1991-05-14  |  30KB  |  1,009 lines

  1. *****************************************************************************
  2. *                   SET YOUR TAB SIZE TO 4 !!!!!!!!!!!!                     *
  3. *          OTHERWISE IT WILL LOOK LIKE A TOTAL MESS !!!!!!!!!!!             *
  4. *****************************************************************************
  5. ;ISOCONTROL    equ    1                        try this line for fake isometric!
  6. ;RAPID_FIRE    equ    1                        makes the fire button auto-repeat
  7. MAX_SPEED    equ 16                        max speed of the main character
  8. MAX_SHOTS    equ 16                        max number of shots active at any time
  9. BOING       equ 14                        bounce factor of the shots
  10. SHOT_COUNT    equ    256                        death delay of the shots
  11. *****************************************************************************
  12. *                    Hardware Regs & system variables                       *
  13. *****************************************************************************
  14. REZ            equ    $ffff8260                resolution
  15. H_PAL          equ $ffff8240                palette
  16. KB_CONTROL    equ    $fffffc00                keyboard control
  17. KB_DATA        equ $fffffc02                keyboard data
  18.  
  19. VBI            equ    $70                        vertical blank interupt
  20.  
  21. KB_SPACE    equ $39                        key code for space
  22. *****************************************************************************
  23. *                              Dos functions                                *
  24. *****************************************************************************
  25. PRINTLINE    equ    $9
  26. FOPEN        equ $3d
  27. FCLOSE        equ    $3e
  28. FREAD        equ    $3f
  29. *****************************************************************************
  30. *                              sprite stuff                                 *
  31. *****************************************************************************
  32. QUIF_LEFT_START        equ    0
  33. QUIF_LEFT_END        equ 3
  34. QUIF_RIGHT_START    equ 4
  35. QUIF_RIGHT_END        equ 7
  36. QUIF_DEATH_START    equ    8
  37. QUIF_DEATH_END        equ    15
  38. GUMBO_LEFT_START    equ 16
  39. GUMBO_LEFT_END        equ 19
  40. GUMBO_RIGHT_START    equ 20
  41. GUMBO_RIGHT_END        equ 23
  42. TEDDY_LEFT_START    equ    24
  43. TEDDY_LEFT_END        equ    27
  44. TEDDY_RIGHT_START    equ    28
  45. TEDDY_RIGHT_END        equ 31
  46. EXPLODE1_START        equ    32
  47. EXPLODE1_END        equ    35
  48. EXPLODE2_START        equ    36
  49. EXPLODE2_END        equ    39
  50. *****************************************************************************
  51. *                          shot structure stuff                             *
  52. *****************************************************************************
  53. SH_MODE        equ        0
  54. SH_ALL      equ        2
  55. SH_XYZ        equ     2
  56. SH_X        equ     2
  57. SH_Y        equ     4
  58. SH_Z        equ     6
  59. SH_VXYZ        equ     8
  60. SH_VX        equ     8
  61. SH_VY        equ     10
  62. SH_VZ        equ     12
  63. SH_FRAME    equ        14
  64. SH_SIZE        equ        16
  65. *****************************************************************************
  66. *            This is about the cleanest startup I can think of              *
  67. *****************************************************************************
  68. start
  69.     clr.l    -(sp)                        OS startup stuff
  70.     move.w    #$20,-(sp)
  71.     trap    #1                           stick it in supervisor mode
  72.     addq.l    #6,sp
  73.     move.l    d0,old_ssp
  74.     move.w    #3,-(sp)                    logbase to find the screen
  75.     trap    #14
  76.     addq.l    #2,sp
  77.     move.l    d0,_d_screen                currently displayed screen
  78.     move.l    d0,old_screen
  79.     move.l    #w_screen,d0
  80.     addi.l    #256,d0                        ensure it's on a 256 byte boundry
  81.     andi.l    #$ffffff00,d0
  82.     move.l    d0,_w_screen                and you have another screen
  83.     move.l  VBI,old_vbi                    back up the old vbi
  84.     move.l    #_vbi,VBI                    patch in the new one
  85.  
  86.     move.w    #34,-(sp)
  87.     trap    #14                            get system vectors
  88.     addq.l  #2,sp
  89.  
  90.     move.l    d0,a0                        address of system vectors
  91.     lea        24(a0),a0                    move to joystick vector
  92.     move.l  a0,j_pack_address            store the address of the vector
  93.     move.l    (a0),old_j_pack                store the old vector
  94.     move.l    #_joy_handler,(a0)            patch in the new one
  95.  
  96. js_loop
  97.     btst.b    #1,(KB_CONTROL).w            is keyboard ready for command
  98.     beq.s   js_loop                     no, loop
  99.     move.b    #$15,(KB_DATA).w            set joysick to, must request a packet mode
  100.  
  101.     bsr        _main                        yer actual program
  102.  
  103. jrs_loop
  104.     btst.b    #1,(KB_CONTROL).w            is keyboard ready for command
  105.     beq.s   jrs_loop                    no, loop
  106.     move.b    #$8,(KB_DATA).w                set mouse relative mode
  107.  
  108.     move.l    j_pack_address,a0
  109.     move.l    old_j_pack,(a0)                put the old joystick handler back
  110.  
  111.     move.l  old_vbi,VBI
  112.     move.l    old_ssp,sp                    clean exit
  113.  
  114.     move.w    #-1,-(sp)                    res
  115.     move.l    old_screen,-(sp)            reset the screen pos
  116.     move.l    old_screen,-(sp)
  117.     move.w    #5,-(sp)
  118.     trap    #14
  119.     lea        12(sp),sp
  120.     clr.w    -(sp)
  121.     trap    #1
  122. *****************************************************************************
  123. *           Do the disc access and call _display if it was ok,              *
  124. *                   otherwise end with an error message                     *
  125. *****************************************************************************
  126. _main
  127.     lea        spr32_fname,a0                the sprite file name
  128.     lea        _spr_32,a1                    the address to load the file to
  129.     move.l    #256*10*32,d0                the size of the file
  130.     jsr     _load_file                    read 32*32 sprites
  131.     blt.s    error_end
  132.  
  133.     lea        spr16_fname,a0                the sprite file name
  134.     lea        _spr_16,a1                    the address to load the file to
  135.     move.l    #5*160,d0                     the size of the file
  136.     jsr     _load_file                    read 32*32 sprites
  137.     blt.s    error_end
  138.  
  139.         move.b  (REZ).w,old_rez            store the old resolution
  140.         move.b    #0,(REZ).w                whack it into lo rez
  141.         movem.l    (H_PAL).w,d0-d7
  142.         movem.l    d0-d7,old_pal
  143.         movem.l    palette,d0-d7            how to set the palette in 2 instructions
  144.         movem.l    d0-d7,(H_PAL).w            but remember, it trashes all data regs
  145.  
  146.         bsr        _display                the main game loop
  147.  
  148.            movem.l    old_pal,d0-d7
  149.         movem.l    d0-d7,(H_PAL).w
  150.         move.b    old_rez,(REZ).w            stick it back in original mode
  151.  
  152. error_end
  153.     rts
  154. *****************************************************************************
  155. *                      The main loop of the program                         *
  156. *****************************************************************************
  157. _display
  158.     bsr        _init_player
  159. disploop
  160.         bsr        _wait_vbi                wait for the vbi
  161.         move.l    _w_screen,a0
  162.         bsr        _do_background          draw the background
  163.  
  164. **************************** draw the sprites *******************************
  165.  
  166.         movem.w    player_xy,d0/d1
  167.         asr.w    #2,d0
  168.         asr.w    #3,d1
  169.         sub.w    #32,d1                    subtract these values because the -
  170.         sub.w    #16,d0                    coordinate is the mid centre
  171.         move.w    player_frame,d2
  172.         bsr     _spr3232
  173.  
  174.         bsr        _draw_shots
  175. ****************************** flip screens *********************************
  176.  
  177.         bsr        _swap_screens
  178.  
  179. *********** now do any non graphic work like moving the sprites *************
  180.  
  181.         bsr        _move_player
  182.         move.l    dxy_joy,d0
  183.         beq.s    not_valid
  184.             move.l    d0,lv_joy
  185. not_valid
  186.         tst.b    fire_last_turn
  187.         beq.s    check4fire
  188.     ifnd    RAPID_FIRE
  189.             tst.b    fire
  190.             bne.s    no_fire
  191.     endc
  192.             sf        fire_last_turn
  193.             bra.s    no_fire
  194. check4fire
  195.         tst.b    fire
  196.         beq.s    no_fire
  197.             bsr        _init_shot
  198.             st        fire_last_turn
  199. no_fire
  200.  
  201.         bsr        _move_shots
  202.  
  203.         cmp.b    #KB_SPACE,(KB_DATA).w        is space bar pressed ?
  204.         beq.s   exit_display                yes, exit!
  205.  
  206. ******************* force a joystick interupt to occur **********************
  207. jr_loop
  208.         btst.b    #1,(KB_CONTROL).w            is keyboard ready for command
  209.         beq.s   jr_loop                     no, loop
  210.         move.b    #$16,(KB_DATA).w            request a joystick packet
  211.         bra        disploop
  212.  
  213. exit_display
  214.     rts
  215. *****************************************************************************
  216. _draw_shots
  217.     lea        _shots,a5                        the shot structures
  218.     lea        _shots+MAX_SHOTS*SH_SIZE,a6        the end of the shot structures
  219. ds_loop
  220.         tst.w    SH_MODE(a5)                    is this shot on ?
  221.         beq        ds_next                        no, move to the next one
  222.         movem.w    SH_XYZ(a5),d0/d1/d2         get sprites x,y and z coords
  223.         asr.w    #2,d0                        scale-
  224.         asr.w    #3,d1                        em
  225.         subq.w    #8,d0
  226.         sub.w    #7,d1                       move to top of shadow
  227.         movem.w    d0/d1/d2,-(sp)
  228.         lea        _spr_16+160*4,a1
  229.         move.l    _w_screen,a0
  230.         moveq    #7,d2                        height of a shadow
  231.         bsr        _s16_draw
  232.         movem.w    (sp)+,d0/d1/d2
  233.         sub.w    #9,d1
  234.         asr.w    #1,d2
  235.         sub.w    d2,d1
  236.         lea        _spr_16,a1
  237.         move.w    SH_FRAME(a5),d3
  238.         and.w    #%1100,d3                    frame *4
  239. *
  240. ;        mulu    #160,d3                        * size of one sprite
  241. ****** the following five lines are the quick way to multiply by 160 ********
  242.         move.w    d3,d4
  243.         add.w    d3,d3                        *8
  244.         add.w    d3,d3                        *16
  245.         add.w    d4,d3                        *20
  246.         lsl.w    #3,d3                        *8*20 = *160
  247. *
  248.         adda.w    d3,a1
  249.         move.l    _w_screen,a0
  250.         moveq    #16,d2
  251.         bsr        _s16_draw
  252. ds_next
  253.     lea        SH_SIZE(a5),a5
  254.     cmpa.l    a5,a6
  255.     bne.s    ds_loop
  256.     rts
  257. *****************************************************************************
  258. _init_shot
  259.     lea        _shots-SH_SIZE,a0                one shot back from the start as-
  260.     move.w    #MAX_SHOTS-1,d7
  261. is_loop
  262.         lea        SH_SIZE(a0),a0                this line increments the pointer
  263.         tst.w    SH_MODE(a0)
  264.         dbeq    d7,is_loop                    loop until d7=0 or z flag set
  265.         beq.s    found_empty_shot            found one!
  266.     rts                                        return if no empty shot structures
  267. found_empty_shot
  268.     movem.w player_xy,d0/d1                    get the player x & y
  269.     moveq    #0,d2                            clear z
  270.     movem.w    lv_joy,d3/d4                    joystick directions
  271.     asl.w    #3,d3                            scale em up as velocities
  272.     asl.w    #3,d4
  273.     movem.w    player_vxy,d5/d6
  274.     add.w    d5,d3
  275.     add.w    d6,d4
  276.     moveq    #BOING,d5                        the initial velocity
  277.     move.w    #SHOT_COUNT,d6                    the life expectency of the shot
  278.     move.w    #1,SH_MODE(a0)                    flag the shot as alive
  279.     movem.w    d0/d1/d2/d3/d4/d5/d6,SH_ALL(a0)    set all the shot variables
  280.     rts
  281. *****************************************************************************
  282. _move_shots
  283.     lea        _shots,a0                        a0-> the shot structures
  284.     move.w    #MAX_SHOTS-1,d7                    -1 coz of the dbra instruction
  285. ms_loop
  286.     move.w    SH_MODE(a0),d0
  287.  
  288. * maybe switch on mode here
  289.  
  290.     beq        next_shot
  291.     movem.w    SH_ALL(a0),d0/d1/d2/d3/d4/d5/d6    get all the data
  292.     add.w    d3,d0
  293.     add.w    d4,d1
  294.     add.w    d5,d2
  295.     bpl.s    still_positive                    it's still above the ground
  296.         neg.w    d5                            'bounce' by inverting the velocity
  297.         add.w    d5,d2
  298.         subq.w    #1,d5
  299.  
  300.     tst.w    d3
  301.     beq.s    no_xv
  302.     bpl.s    pl_xv
  303.         addq.w    #1,d3
  304.         bra.s    no_xv
  305. pl_xv
  306.         subq.w    #1,d3
  307. no_xv
  308.  
  309.     tst.w    d4
  310.     beq.s    no_yv
  311.     bpl.s    pl_yv
  312.         addq.w    #1,d4
  313.         bra.s    no_yv
  314. pl_yv
  315.         subq.w    #1,d4
  316. no_yv
  317.  
  318.  
  319. still_positive
  320.     subq.w    #1,d5                            gravity
  321.  
  322.     subq.w    #1,d6                            decrease life counter
  323.     beq.s    kill_shot                        kill it off if it's 0
  324.     movem.w    d0/d1/d2/d3/d4/d5/d6,SH_ALL(a0)    put all the data back
  325. next_shot
  326.     lea        SH_SIZE(a0),a0                    move to next shot
  327.     dbra    d7,ms_loop
  328.     rts
  329. kill_shot
  330.     clr.w    SH_MODE(a0)                        kill the shot
  331.     bra.s    next_shot                        move on to the next one
  332.  
  333. *****************************************************************************
  334. _init_player
  335.     move.w    #GUMBO_RIGHT_START,player_frame
  336.     move.w    #160*4,player_x
  337.     move.w    #100*4,player_y
  338.     rts
  339. *****************************************************************************
  340. _move_player
  341.     movem.w    dxy_joy,d0/d1                        get joystick directions
  342.     movem.w    player_data,d2/d3/d4/d5/d6
  343.     moveq    #0,d7                               clear animation flag
  344.  
  345. ; d2 = x, d3 = y, d4 = vx, d5 = vy, d6 = frame
  346. ;
  347. ;    x & y coordinates are stored *4 to make the momentum work
  348. ;
  349.     tst.w    d0                                    joystick x moving?
  350.     bne.s    xjoy_moving                            yes
  351.  
  352.     tst.w    d4                                    any x vel?
  353.     beq.s    p_xmove_done                        no, so dont move
  354.     bpl.s    p_xvpos
  355.         addq.w    #2,d4                            negative slowdown
  356. p_xvpos
  357.         subq.w    #1,d4                           slow down
  358.  
  359. xjoy_moving
  360.         add.w    d0,d4                           adjust x vel
  361.         cmp.w    #MAX_SPEED,d4
  362.         ble.s    p_xv_adj_done                    dont go above max right speed
  363.             moveq    #MAX_SPEED,d4
  364.             bra.s    p_xadj_done
  365. p_xv_adj_done
  366.         cmp.w    #-MAX_SPEED,d4
  367.         bge.s    p_xadj_done                        dont go above max left speed
  368.             moveq    #-MAX_SPEED,d4
  369. p_xadj_done
  370.         moveq    #1,d7                            set animation flag
  371. p_xmove
  372.         add.w    d4,d2                            adjust x
  373. p_xmove_done
  374.     tst.w    d1                                    joystick y moving?
  375.     bne.s    yjoy_moving                            yes
  376.  
  377.     tst.w    d5                                    any y vel?
  378.     beq.s    p_ymove_done                        no, so dont move
  379.     bpl.s    p_yvpos
  380.         addq.w    #2,d5                            negative slowdown
  381. p_yvpos
  382.         subq.w    #1,d5                           slow down
  383.  
  384. yjoy_moving
  385.         add.w    d1,d5                           adjust y vel
  386.         cmp.w    #MAX_SPEED,d5
  387.         ble.s    p_yv_adj_done                    dont go above max down speed
  388.             moveq    #MAX_SPEED,d5
  389.             bra.s    p_yadj_done
  390. p_yv_adj_done
  391.         cmp.w    #-MAX_SPEED,d5
  392.         bge.s    p_yadj_done                        dont go above max up speed
  393.             moveq    #-MAX_SPEED,d5
  394. p_yadj_done
  395.         moveq    #1,d7                            set animation flag
  396. p_ymove
  397.         add.w    d5,d3                            adjust y
  398. p_ymove_done
  399.  
  400.     tst.w    d0                                    joy x
  401.     beq.s    no_reframe
  402.     bmi.s   reframe_left
  403.         and.w   #%11,d6                            just keep animation count
  404.         or.w    #GUMBO_RIGHT_START,d6            face right
  405.         bra.s    no_reframe
  406. reframe_left
  407.         and.w   #%11,d6                            just keep animation count
  408.         or.w    #GUMBO_LEFT_START,d6
  409. no_reframe
  410.     tst.w    d7
  411.     beq.s    p_no_anim
  412.         move.w  player_delay,d7
  413.         addq.w    #1,d7
  414.         and.w    #%11,d7
  415.         move.w    d7,player_delay
  416.         tst.w    d7
  417.         bne        p_no_anim
  418.             move.w    d6,d7
  419.             addq.w    #1,d7                            inc anim
  420.             and.w    #%00000011,d7
  421.             and.w    #%11111100,d6
  422.             or.w    d7,d6
  423. p_no_anim
  424.     tst.w    d2                                    keep x coord on screen
  425.     bpl.s    xnotneg
  426.         moveq    #0,d2
  427. xnotneg
  428.     cmp.w    #(320)*4,d2
  429.     ble.s    xnotpos
  430.         move.w    #(320)*4,d2
  431. xnotpos
  432.     tst.w    d3                                    keep y coord on screen
  433.     bpl.s    ynotneg
  434.         moveq    #0,d3
  435. ynotneg
  436.     cmp.w    #(192)*8,d3
  437.     ble.s    ynotpos
  438.         move.w    #(192)*8,d3
  439. ynotpos
  440.     movem.w        d2/d3/d4/d5/d6,player_data        put the data back
  441.     rts
  442. *****************************************************************************
  443. ; this routine waits until the vertical blank interupt has occured
  444. _wait_vbi
  445.     tst.b    _vbi_done
  446.     beq.s   _wait_vbi
  447.     rts
  448. *****************************************************************************
  449. ; very simple vertical blank routine, it just flags that it has happened
  450. _vbi
  451.     st        _vbi_done
  452.     rte
  453. *****************************************************************************
  454. _joy_handler
  455.     move.w    d0,-(sp)
  456.     clr.w    d0
  457.     move.b    1(a0),d0                F...RLDU
  458.     add.b    d0,d0                    ...RLDU.    *2 for the lookup table
  459.     scs        fire                    set fire to true if it bit 7 was set
  460.     add.b    d0,d0                    ..RLDU..
  461.     move.l    jlt(pc,d0.w),dxy_joy
  462.  
  463. ;    move.b    (a0),d0                    use these 5 lines if you want 2 joysticks
  464. ;    add.b    d0,d0                    you will need variables for
  465. ;    scs        fire0                   the other fire button
  466. ;    add.b    d0,d0                   and
  467. ;    move.l    jlt(pc,d0.w),dxy_joy0    joystick x & y directions
  468.  
  469.     move.w    (sp)+,d0
  470.     rts
  471. ;            dx dy            the bits    imposible cases
  472. jlt
  473.     IFD        ISOCONTROL
  474.     dc.w     0,0            ..0000..
  475.     dc.w     1,-1            ..000U..
  476.     dc.w     -1,1            ..00D0..
  477.     dc.w     0,0            ..00DU..    *
  478.     dc.w    -1,-1            ..0L00..
  479.     dc.w     0,-1            ..0L0U..
  480.     dc.w    -1,0            ..0LD0..
  481.     dc.w    -1,0            ..0LDU..    *
  482.     dc.w     1,1            ..R000..
  483.     dc.w     1,0            ..R00U..
  484.     dc.w     0,1            ..R0D0..
  485.     dc.w     1,1            ..R0DU..    *
  486.     dc.w     0,0            ..RL00..    *
  487.     dc.w     1,-1            ..RL0U..    *
  488.     dc.w     -1,1            ..RLD0..    *
  489.     dc.w     0,0            ..RLDU..    *
  490.     ENDC
  491.     IFND     ISOCONTROL
  492.     dc.w     0,0            ..0000..
  493.     dc.w     0,-1            ..000U..
  494.     dc.w     0,1            ..00D0..
  495.     dc.w     0,0            ..00DU..    *
  496.     dc.w    -1,0            ..0L00..
  497.     dc.w    -1,-1            ..0L0U..
  498.     dc.w    -1,1            ..0LD0..
  499.     dc.w    -1,0            ..0LDU..    *
  500.     dc.w     1,0            ..R000..
  501.     dc.w     1,-1            ..R00U..
  502.     dc.w     1,1            ..R0D0..
  503.     dc.w     1,0            ..R0DU..    *
  504.     dc.w     0,0            ..RL00..    *
  505.     dc.w     0,-1            ..RL0U..    *
  506.     dc.w     0,1            ..RLD0..    *
  507.     dc.w     0,0            ..RLDU..    *
  508.     ENDC
  509. *****************************************************************************
  510. _swap_screens
  511.     move.l    _w_screen,d0            d0 = screen address
  512.     move.l    _d_screen,_w_screen
  513.     move.l    d0,_d_screen            d0 = xxxx high low    0000
  514.  
  515.     lsr.w    #8,d0
  516.     move.l    d0,$ffff8200.w            d0 = xxxx high xxxx low
  517.     sf        _vbi_done
  518.     rts
  519. *****************************************************************************
  520. ; d0 = x, d1 = y, d2 = sprite number
  521. _spr3232
  522.     move.l    _w_screen,a0        draw on _w_screen
  523.     lea        _spr_32,a1
  524.     mulu    #640,d2                size of a 32*32 sprite
  525.     add.w    d2,a1
  526.     moveq    #32,d2
  527.     bsr        _s32_draw
  528.     rts
  529. *****************************************************************************
  530. *    16 pixel wide sprite draw                                                *
  531. *    d0.w = QX                                                                *
  532. *    d1.w = QY                                                                *
  533. *    d2.w = sprite height                                                    *
  534. *   a0 -> screen                                                             *
  535. *    a1    -> the sprite data                                                    *
  536. *****************************************************************************
  537. LINES_HIGH    set 192
  538. _s16_draw
  539.     tst.w    d1                    is y less than 0
  540.     bge.s    y_not_minus_16        no, ok.
  541. *****************************************************************************
  542. *    QY is negative
  543.     neg.w    d1
  544.     sub.w    d1,d2                do we see any of it ?
  545.     ble        not_drawn_16        no, dont draw it at all
  546. ; a 16 pixel wide sprite has 10 bytes a line, so we have to multiply by 10
  547.     add.w    d1,d1                *2
  548.     move.w    d1,d7
  549.     add.w    d1,d1                *4
  550.     add.w    d1,d1                *8
  551.     add.w    d7,d1                In2Data and QY are the same reg
  552.     adda.w    d1,a1                move into the source the required no. of line
  553.     bra.s    y_clipped_16
  554. *********
  555. y_not_minus_16
  556.     moveq    #256-LINES_HIGH,d6
  557.     neg.b    d6                    quicker than move.w #LINES_HIGH,d6
  558.     cmp.w    d6,d1
  559.     bge     not_drawn_16
  560.     move.w    d1,d7
  561.     add.w    d7,d7                *2
  562.     add.w    d7,d7                *4
  563.     add.w    d1,d7                *5
  564.     lsl.w    #5,d7                *5*32 (28 clock cycles, less than 70 for *160
  565.     adda.w    d7,a0                move down the screen
  566.     add.w    d2,d1
  567.     subi.w    #LINES_HIGH,d1
  568.     blt.s    y_clipped_16
  569.     sub.w    d1,d2                adjust height of sprite to fit it on
  570. y_clipped_16
  571. *****************************************************************************
  572. *    I suppose I better do the QX stuff now
  573.     tst.w    d0
  574.     bge.s    x_not_minus_16        x ok, well at least it isn't negative!
  575.     cmpi.w    #-16,d0
  576.     ble.s    not_drawn_16        it is off screen
  577.     moveq    #0,d1
  578.     bra        _left_16
  579. x_not_minus_16
  580.     move.w    d0,d7
  581.     andi.w    #$f,d0                QX and QShift are the same Reg
  582.  
  583. * we want . . . 0-15 ->0, 16-31->8 etc.........
  584.  
  585.     andi.w    #$fff0,d7
  586.     lsr.w    #1,d7
  587.     moveq    #256-160,d6
  588.     neg.b    d6
  589.     cmp.w    d6,d7                is it off the right side of the screen ?
  590.     bge.s    not_drawn_16        yes
  591.     adda.w    d7,a0                adjust destination
  592.     subq.w    #8,d6
  593.     cmp.w    d6,d7
  594.     bne        _all_16
  595.  
  596. *    right hand only case
  597.  
  598.     moveq    #0,d1
  599.     bra        _right_16
  600. not_drawn_16
  601.     rts
  602.  
  603. *****************************************************************************
  604. *    32 pixel wide sprite draw                                                *
  605. *    d0.w = QX                                                                *
  606. *    d1.w = QY                                                                *
  607. *    d2.w = sprite height                                                    *
  608. *   a0 -> screen                                                             *
  609. *    a1    -> the sprite data                                                    *
  610. *****************************************************************************
  611. _s32_draw
  612.     tst.w    d1                    is y less than 0
  613.     bge.s    y_not_minus_32        no, ok.
  614. *****************************************************************************
  615. *    QY is negative
  616.     neg.w    d1
  617.     sub.w    d1,d2                do we see any of it ?
  618.     ble        not_drawn_32        no, dont draw it at all
  619. ; a 32 pixel wide sprite has 20 bytes a line, so we have to multiply by 20
  620.     move.w    d1,d7
  621.     add.w    d1,d1                *2
  622.     add.w    d1,d1                *4
  623.     add.w    d7,d1                *5
  624.     add.w    d1,d1                *10
  625.     add.w    d1,d1                *20
  626.     adda.w    d1,a1                move into the source the required no. of line
  627.     bra.s    y_clipped_32
  628. *********
  629. y_not_minus_32
  630.     moveq    #256-LINES_HIGH,d6
  631.     neg.b    d6                    quicker than move.w #LINES_HIGH,d6
  632.     cmp.w    d6,d1
  633.     bge     not_drawn_32
  634.     move.w    d1,d7
  635.     add.w    d7,d7                *2
  636.     add.w    d7,d7                *4
  637.     add.w    d1,d7                *5
  638.     lsl.w    #5,d7                *5*32 (28 clock cycles, less than 70 for *160
  639.     adda.w    d7,a0                move down the screen
  640.     add.w    d2,d1
  641.     subi.w    #LINES_HIGH,d1
  642.     blt.s    y_clipped_32
  643.     sub.w    d1,d2                adjust height of sprite to fit it on
  644. y_clipped_32
  645. *****************************************************************************
  646. *    I suppose I better do the QX stuff now
  647.     tst.w    d0
  648.     bge.s    x_not_minus_32        x ok, well at least it isn't negative!
  649.     cmpi.w    #-16,d0
  650.     ble.s    may_be_32
  651.     moveq    #0,d1
  652.     bra        _left_32
  653. may_be_32
  654.     cmpi.w    #-32,d0
  655.     ble.s    not_drawn_32
  656.     moveq    #10,d1
  657.     bra        _left_16
  658. x_not_minus_32
  659.     move.w    d0,d7
  660.     andi.w    #$f,d0                QX and QShift are the same Reg
  661.  
  662. * we want . . . 0-15 ->0, 16-31->8 etc.........
  663.  
  664.     andi.w    #$fff0,d7
  665.     lsr.w    #1,d7
  666.     moveq    #256-(160-16),d6
  667.     neg.b    d6
  668.     adda.w    d7,a0                adjust destination
  669.     cmp.w    d6,d7                is it definately on screen ?
  670.     bmi        _all_32                yes
  671.     addq.w    #8,d6
  672.     moveq    #0,d1
  673.     cmp.w    d6,d7
  674.     bmi        _right_32
  675.     addq.w    #8,d6
  676.     moveq    #10,d1
  677.     cmp.w    d6,d7
  678.     bmi        _right_16
  679. not_drawn_32
  680.     rts
  681. *****************************************************************************
  682. *    The low level routines, may be useful for other stuff at some stage..    *
  683. *****************************************************************************
  684. DO_RIGHT    macro
  685.     moveq    #-1,d3
  686.     move.w    (a1)+,d3            get the QTemplate
  687.     ror.l    d0,d3                rotate it
  688.  
  689.     moveq    #0,d4
  690.     move.w    (a1)+,d4            get QPlane 0
  691.     ror.l    d0,d4                rotate it
  692.     move.w    (a0)+,d5
  693.     and.w    d3,d5
  694.     or.w    d5,d4                QPlane 0 made
  695.  
  696.     moveq    #0,d5
  697.     move.w    (a1)+,d5            get QPlane 1
  698.     ror.l    d0,d5                rotate it
  699.     move.w    (a0)+,d6
  700.     and.w    d3,d6
  701.     or.w    d6,d5                QPlane 1 made
  702.  
  703.     moveq    #0,d6
  704.     move.w    (a1)+,d6            get QPlane 2
  705.     ror.l    d0,d6                rotate it
  706.     move.w    (a0)+,d7
  707.     and.w    d3,d7
  708.     or.w    d7,d6                QPlane 0 made
  709.  
  710.     moveq    #0,d7
  711.     move.w    (a1)+,d7            get QPlane 3
  712.     ror.l    d0,d7                rotate it
  713.     and.w    (a0)+,d3            may as well corrupt the QTemplate this time
  714.     or.w    d3,d7                QPlane 3 made
  715.     endm
  716. *************
  717. DO_LEFTM    macro
  718.     swap    d3
  719.     swap    d4
  720.     move.w    (a0)+,d5
  721.     and.w    d3,d5
  722.     or.w    d5,d4                QPlane 0 made
  723.  
  724.     swap    d5
  725.     move.w    (a0)+,d6
  726.     and.w    d3,d6
  727.     or.w    d6,d5                QPlane 1 made
  728.  
  729.     swap    d6
  730.     move.w    (a0)+,d7
  731.     and.w    d3,d7
  732.     or.w    d7,d6                QPlane 2 made
  733.  
  734.     swap    d7
  735.     and.w    (a0)+,d3            corrupting QTemplate
  736.     or.w    d3,d7                QPlane 3 made
  737.     endm
  738. *******
  739. DO_LEFT macro
  740.     moveq    #-1,d3
  741.     move.w    (a1)+,d3            get the QTemplate
  742.     rol.l    d0,d3                rotate it
  743.  
  744.     move.w    (a1)+,d4            get QPlane 0
  745.     lsl.w    d0,d4                rotate it
  746.     move.w    (a0)+,d5
  747.     and.w    d3,d5
  748.     or.w    d5,d4                QPlane 0 made
  749.  
  750.     move.w    (a1)+,d5            get QPlane 1
  751.     lsl.w    d0,d5                rotate it
  752.     move.w    (a0)+,d6
  753.     and.w    d3,d6
  754.     or.w    d6,d5                QPlane 1 made
  755.  
  756.     move.w    (a1)+,d6            get QPlane 2
  757.     lsl.w    d0,d6                rotate it
  758.     move.w    (a0)+,d7
  759.     and.w    d3,d7
  760.     or.w    d7,d6                QPlane 0 made
  761.  
  762.     move.w    (a1)+,d7            get QPlane 3
  763.     lsl.w    d0,d7                rotate it
  764.     and.w    (a0)+,d3            may as well corrupt the QTemplate this time
  765.     or.w    d3,d7                QPlane 3 made
  766.     ENDM
  767. *****************************************************************************
  768. _all_16
  769. ; A0 = QSource, A1 = QDest, D0 = QShift, D2 = Height
  770.  
  771.     moveq    #256-(160-16),d1
  772.     neg.b    d1
  773.     subq.w    #1,d2                for dbra
  774. a16_loop
  775.     DO_RIGHT
  776.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  777.     DO_LEFTM
  778.     movem.w d4-d7,-8(a0)        another one
  779.     adda.w    d1,a0
  780.     dbra    d2,a16_loop
  781.     rts
  782. ********************************************************************
  783. _left_16
  784. ; A0 = QSource, A1 = QDest, D0 = QShift, D1 = QSkip, D2 = Height
  785.     subq.w    #1,d2
  786.     neg.w    d0
  787.     andi.w    #$f,d0
  788. l16_loop
  789.     adda.w    d1,a1
  790.     DO_LEFT
  791.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  792.     lea        160-8(a0),a0
  793.     dbra    d2,l16_loop
  794.     rts
  795. ********************************************************************
  796. _right_16
  797. ; A0 = QSource, A1 = QDest, D0 = QShift, D1 = QSkip, D2 = Height
  798.     subq.w    #1,d2
  799. r16_loop
  800.     DO_RIGHT
  801.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  802.     lea        160-8(a0),a0
  803.     adda.w    d1,a1
  804.     dbra    d2,r16_loop
  805.     rts
  806.  
  807. *****************************************************************************
  808. _all_32
  809. ; A0 = QSource, A1 = QDest, D0 = QShift, D2 = Height
  810.  
  811.     moveq    #256-(160-24),d1
  812.     neg.b    d1
  813.     subq.w    #1,d2                for dbra
  814. a32_loop
  815.     DO_RIGHT
  816.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  817.     DO_LEFTM
  818.     subq.l    #8,a0
  819.     movem.w d4-d7,(a0)             another one
  820.     DO_RIGHT
  821.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  822.     DO_LEFTM
  823.     movem.w d4-d7,-8(a0)        another one
  824.     adda.w    d1,a0
  825.     dbra    d2,a32_loop
  826.     rts
  827. *****************************************************************************
  828. _left_32
  829. ; A0 = a1, A1 = QDest, D0 = QShift, D1 = QSkip, D2 = Height
  830.     subq.w    #1,d2
  831.     move.w    d0,d4
  832.     neg.w    d4
  833.     moveq    #$f,d5
  834.     and.w    d5,d4
  835.     and.w    d5,d0
  836.     swap    d0
  837.     move.w    d4,d0
  838. l32_loop
  839.     adda.w    d1,a1
  840.     DO_LEFT
  841.     subq.l    #8,a0
  842.     movem.w d4-d7,(a0)             i had to get a movem in there somewhere
  843.     swap    d0
  844.     DO_RIGHT
  845.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  846.     DO_LEFTM
  847.     movem.w d4-d7,-8(a0)        another one
  848.     swap    d0
  849.     lea        160-16(a0),a0
  850.     dbra    d2,l32_loop
  851.     rts
  852. *****************************************************************************
  853. _right_32
  854. ; A0 = QSource, A1 = QDest, D0 = QShift, D1 = QSkip, D2 = Height
  855.     subq.w    #1,d2
  856.     andi.w    #$f,d0
  857. r32_loop
  858.     DO_RIGHT
  859.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  860.     DO_LEFTM
  861.     subq.l    #8,a0
  862.     movem.w d4-d7,(a0)             another one
  863.     DO_RIGHT
  864.     movem.w d4-d7,-8(a0)        i had to get a movem in there somewhere
  865.     lea        160-16(a0),a0
  866.     adda.w    d1,a1
  867.     dbra    d2,r32_loop
  868.     rts
  869. *****************************************************************************
  870. ; a0-> filename a1-> destination d0 = length
  871. ; on return d0 = file length actually read or -1 if read failed
  872. _load_file
  873.     move.l    d0,d6
  874.     clr.w    -(sp)               read
  875.     move.l    a0,-(sp)            -> filename
  876.     move.w    #FOPEN,-(sp)
  877.     trap    #1                    open the file
  878.     addq.l    #8,sp                readjust the stack
  879.     move.w    d0,d7                handle
  880.     ble.s   file_not_found
  881. *
  882.     move.l  a1,-(sp)            destination memory
  883.     move.l    d6,-(sp)
  884.     move.w    d7,-(sp)            file handle
  885.     move.w    #FREAD,-(sp)
  886.     trap    #1                    read the file
  887.     lea        12(sp),sp            the quick way of adding 12 to the stack
  888.     move.l    d0,d6                length read
  889. *
  890.     move.w    d7,-(sp)            file handle
  891.     move.w    #FCLOSE,-(sp)
  892.     trap    #1                    close the file
  893.     addq.l    #4,sp
  894.     move.l    d6,d0                so we can return the file length
  895.     rts
  896. file_not_found
  897.     pea        fnf_msg(pc)            address of the error message
  898.     move.w    #PRINTLINE,-(sp)
  899.     trap    #1                    print it
  900.     addq.l    #6,sp
  901.     moveq    #-1,d0
  902.     rts
  903. *****************************************************************************
  904. _do_background
  905. ; copys the pattern below to the background
  906.     move.l  _w_screen,a0
  907.     lea        160*192(a0),a0                    a0-> end of screen
  908.     lea        -160*32(a0),a1                    a1-> a2 -32 lines
  909.     lea        -160*32(a1),a2                    a2-> a3 -32 lines
  910.     lea        -160*32(a2),a3                    a3-> a4 -32 lines
  911.     lea        -160*32(a3),a4                    a4-> a5 -32 lines
  912.     lea        -160*32(a4),a5                    a5-> a6 -32 lines
  913.     lea        background(pc),a6                -> upside-down background source
  914.  
  915. doline    macro
  916.         movem.l d0-d7,-(\1)                    set 64  pixels
  917.         movem.l d0-d7,-(\1)                        128
  918.         movem.l d0-d7,-(\1)                        192
  919.         movem.l d0-d7,-(\1)                        256
  920.         movem.l d0-d7,-(\1)                        320, a whole line
  921.         endm
  922.  
  923.     moveq    #0,d1
  924.     moveq    #0,d3
  925.     moveq    #0,d5
  926.     moveq    #0,d7
  927.     move.b    #32,linesleft
  928. bg_loop
  929.         movem.l    (a6)+,d0/d2/d4/d6
  930.         doline    a0
  931.         doline    a1
  932.         doline    a2
  933.         doline    a3
  934.         doline    a4
  935.         doline    a5
  936.         subq.b    #1,linesleft
  937.         bne        bg_loop
  938.         rts
  939.  
  940. background
  941.  dc.l $F80F00D0,$FC1F00E0,$787F0080,$F83F00C0,$F1BF0200,$E00F0230,$BFF74000,$F11F0220
  942.  dc.l $85FF0A00,$C3C30C0C,$FFFD0002,$87870808,$1FFE2000,$07E13802,$FFFF0000,$1FF02003
  943.  dc.l $7FFE8000,$3F78C000,$3FBEC000,$5FF8A000,$E7FF0800,$0FDF3020,$1FDF2020,$1EBF2040
  944.  dc.l $FFBF0000,$87FF0800,$83FF0C00,$C3FF0C00,$FE1A0061,$E0FF0300,$F1FE0200,$E07F0380
  945.  dc.l $F83F00C0,$F81F00E0,$F87F0080,$BC3C40C1,$F0070338,$E07F0380,$E0EF0300,$E10F0230
  946.  dc.l $83C30C0C,$87FF0800,$C1FB0E04,$C781080E,$1FE12002,$0FFE3000,$0FFE3000,$1FF02003
  947.  dc.l $3FF8C000,$1EFCE000,$3EFCC000,$5EF8A000,$79E08203,$FF7E0080,$0F703083,$0F7F3080
  948.  dc.l $FFC3000C,$FFFF0000,$C783080C,$87FF0800,$FE1F0020,$FFFF0000,$E00F0330,$E07F0380
  949.  dc.l $BE1F00E0,$783F80C0,$F85F00A0,$FC3F00C0,$DF0F2030,$B01F0320,$BE0F0030,$FF1F0020
  950.  dc.l $FFC3000C,$81830E0C,$EFC71008,$DF83000C,$FAE00102,$1FE02003,$FFE00003,$FFF00003
  951.  dc.l $1FF8E000,$3FF8C000,$7FF88000,$77F88800,$7FFF8000,$FBF10002,$FFE10002,$FFF10002
  952.  dc.l $FFFF0000,$FD83020C,$FF870008,$FF870008,$7F7F0080,$FF0E0030,$FF1F0020,$FF1E0021
  953.  dc.l $F83D00C0,$F83F00C0,$7E5F80A0,$BC7F0080,$F11F0220,$710F8230,$FE0F0030,$EE1F1020
  954.  dc.l $85810A0E,$8781080E,$FF070008,$FFC3000C,$1FF02003,$17E02803,$F7E00003,$FFE10002
  955.  dc.l $4E78B080,$5FFCA000,$3DF8C200,$7FFC8000,$07FF3800,$FFE10002,$1FE12002,$FFBF0000
  956.  dc.l $83FF0C00,$FFC3000C,$83C50C0A,$DFDF0020,$F0DC0321,$FE1F0020,$F01F0320,$EFFF1000
  957.  
  958. *****************************************************************************
  959. fnf_msg        dc.b    7,'FILE NOT FOUND',10,13,7,0
  960. spr16_fname    dc.b    'sprite16.dat',0
  961. spr32_fname    dc.b    'sprite32.dat',0
  962.     even
  963. palette        dc.w    $000,$321,$432,$543,$400,$520,$630,$651
  964.             dc.w    $331,$441,$551,$661,$013,$034,$345,$555
  965. *****************************************************************************
  966.     IFD        __G2        am i using devpac 2?
  967.     section    bss            if so use this line, it saves a lot of time & disk space
  968.  
  969.     ENDC
  970. old_rez            ds.b    1                    the resolution the machine was in
  971. _vbi_done        ds.b    1                   set during the vertical blank
  972. fire            ds.b    1                    set if fire button pressed
  973. linesleft        ds.b    1                    used as a counter in background draw
  974. fire_last_turn    ds.b    1
  975.     even
  976. old_vbi            ds.l    1                    for saving the system vertical blank
  977. old_ssp            ds.l    1                    system stack pointer
  978. old_screen        ds.l    1                    and original screen
  979. _d_screen        ds.l    1                    pointer to the displayed screen
  980. _w_screen        ds.l    1                    pointer to the work screen
  981. j_pack_address    ds.l    1                    where to patch the joystick vector
  982. old_j_pack        ds.l    1                    the old joystick vector
  983. dxy_joy
  984. ;                                            both joystick directions for movem
  985. dx_joy            ds.w    1                    joystick x direction
  986. dy_joy            ds.w    1                    joystick y direction
  987. lv_joy            ds.w    2                    last non zero joystick directions
  988.  
  989. player_data
  990. ;                                            for accessing all of the player data-
  991. player_xy
  992. ;                                            with a single movem
  993. player_x        ds.w    1                    player's x coordinate
  994. player_y        ds.w    1                    guess
  995. player_vxy
  996. player_vx        ds.w    1                    player's x velocity
  997. player_vy        ds.w    1                    player's y velocity
  998. player_frame    ds.w    1                    animation frame
  999. player_delay    ds.w    1                    animation delay
  1000.  
  1001. seed            ds.w    1                    random number seed
  1002.  
  1003. old_pal            ds.w    16                    the old palette
  1004. w_screen        ds.b    32000+256            screen has to be on a 256 byte boundry
  1005. _spr_32            ds.b    640*40                for 40 32*32 sprites
  1006. _spr_16            ds.b    5*160
  1007. _shots            ds.b    MAX_SHOTS*SH_SIZE    the shot structures
  1008. *
  1009.