home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / 326-350 / apd336 / mc68000 / gundemo1.s < prev    next >
Text File  |  1991-10-08  |  10KB  |  457 lines

  1. *************************************************
  2. * Gun Demonstration program for Trojan PHAZER   *
  3. * When run Shoot at Cross to calibrate          *
  4. * Then fire at screen to plot point for gunshot *
  5. *************************************************
  6. * The driver bits are at the end of this proram *
  7. * and are fully documented, not this is the     *
  8. * straightfoward lose a frame version           *
  9. *************************************************
  10.  
  11.     output LoseFrame
  12.  
  13.     Section GunHelp,CODE_C
  14.  
  15. XMiddle        EQU 160        * Gun Calibrate point X
  16. YMiddle        EQU 100        * Gun Calibrate point Y
  17.  
  18.     include "consts.s"    * constant includes
  19. palsize        EQU 16
  20. num_cols    EQU 15
  21. scrheight    EQU 200
  22. pix_div        EQU 8
  23. c_div        EQU 1
  24. Xshift        EQU 3
  25. spr_len        EQU 8
  26. msk_len        EQU 8
  27. bpl1        EQU 40
  28. bpl2        EQU 40
  29. bpl3        EQU 2
  30. m_off        EQU 2
  31. m_pln        EQU 40
  32. m_eol        EQU 120
  33. ascr1        EQU $78000
  34. ascr1d        EQU $78000
  35. linelen        EQU 160
  36. scr_size    EQU ((linelen*scrheight)/4)-1
  37.  
  38. rts        * dummy labels
  39. even
  40.  
  41. ***********************************************************
  42. * main program
  43. InitStuff
  44.     * Set palette to black and showinitial screen *
  45.     move.l #load_palette,d0
  46.     bsr set_palette
  47.     bsr init_machine        * set machine bits
  48.  
  49.     move.w #$ffff,d0        * wait a bit
  50. i_wait_1
  51.     dbra d0,i_wait_1
  52.  
  53.     move.l #stack_pointer,a7    * new amiga stack
  54.     bsr set_interrupts        * set up interrupts
  55.     bsr init_scraddrs        * set main screen addresses
  56.     bsr calibrate_screen
  57.  
  58. ***********************************************************
  59. main_loop
  60.     bsr frame_wait        * Wait for VBL
  61.     bsr read_trigger    * Test gun trigger
  62.     tst.b gun_button
  63.     beq no_fire_gun
  64.         bsr gun_read    * Get gun position
  65.         tst.b gun_fired    * Flag for on scr shot
  66.         beq no_fire_gun
  67.             move.w GunX,d0
  68.             move.w GunY,d1
  69.             bsr plot_point
  70. no_fire_gun
  71.     *** DO GAME HERE ***
  72.     bra main_loop
  73.     rts
  74.  
  75. ***********************************************************
  76. * d0=X    d1=Y
  77. plot_point
  78.     move.w d0,d2
  79.     and.l #15,d0
  80.     and.l #$fff0,d2
  81.     lsr.w #3,d2
  82.     move.w #%1000000000000000,d3
  83.     lsr.w d0,d3
  84.     mulu.w #160,d1
  85.     add.l d2,d1
  86.     add.l #ascr1,d1
  87.     move.l d1,a0
  88.     or.w d3,(a0)
  89.     rts
  90.  
  91. ***********************************************************
  92. display_screen
  93.     move.l #ascr1,d0
  94.     bsr show_screen
  95.     bsr frame_wait
  96.     rts
  97. ***********************************************************
  98. frame_wait
  99.     tst.b frame_end
  100.     beq frame_wait
  101.     clr.b frame_end
  102.     rts
  103. ***********************************************************
  104. init_screen
  105.     move.l #ascr1,a0
  106.     bsr clear_screen
  107.     rts
  108. ***********************************************************
  109. readkey
  110.     move.b KeyAddr,key_press
  111.     clr.b KeyAddr
  112.     rts
  113. ***********************************************************
  114. init_machine
  115.     bsr hard_sprites_off
  116.     bsr set_up_screen
  117.     bsr hard_data_off
  118.     rts
  119. ***********************************************************
  120. hard_sprites_off
  121.     move.l #offsprite,d0
  122.     move.l d0,d1
  123.     swap d1
  124.     move.l #coppersprs,a0
  125.     add.l #2,a0
  126.     move.w #7,d7
  127. hard_off_loop
  128.         move.w d1,(a0)
  129.         add.l #4,a0
  130.         move.w d0,(a0)
  131.         add.l #4,a0
  132.     dbra d7,hard_off_loop
  133. ***********************************************************
  134. hard_data_off
  135.     move.l #$dff014c,a0
  136.     move.w #7,d7
  137. hard_offd_loop
  138.         move.l #0,(a0)
  139.         add.l #8,a0
  140.     dbra d7,hard_offd_loop
  141.     rts
  142. ***********************************************************
  143. * set up the amiga screen 
  144. * reg BPLCON0 bit 15 = res 14,13,12 - BtPLanes
  145. set_up_screen
  146.     ** Set Light Pen Bit (3) on in BPLCON0 **
  147.     move.w #%0100000000001000,BPLCON0    * put in screen characteristics
  148.     move.w #0,BPLCON1
  149.     move.w #120,BPL1MOD
  150.     move.w #120,BPL2MOD
  151.     move.w #$38,DDFSTRT
  152.     move.w #$d0,DDFSTOP
  153.     move.w #$3881,DIWSTRT
  154.     move.w #$ffc1,DIWSTOP
  155.     move.l #copperlist,COP1LCH *
  156.     move.w COPJMP1,d0
  157.     
  158.     rts
  159.  
  160. ***********************************************************
  161. set_interrupts
  162.     move.w #%0111111111111111,DMACONW
  163.     move.w #%1000011111000000,DMACONW
  164.     move.w #%0111111111111111,INTENA
  165.     move.b #%01111111,$bfed01
  166.     move.b #%01111111,$bfdd00
  167.     move.b #%10001000,$bfed01
  168.     move.l #null_interrupt,$64
  169.     move.l #level2_interrupt,$68
  170.     move.l #level3_interrupt,$6c
  171.     move.l #null_interrupt,$70
  172.     move.l #null_interrupt,$74
  173.     move.l #null_interrupt,$78
  174.     move.w #%0000000011111111,ADKCON
  175.     sf.b frame_end
  176.     move.w #%1100000000111000,INTENA
  177.     move.w #$7fff,INTREQ
  178.     rts
  179. null_interrupt
  180.     move.w INTREQR,INTREQ
  181.     rte
  182. level2_interrupt
  183.     move.b d0,-(sp)
  184.     move.b $bfed01,d0
  185.     move.b $bfec01,d0
  186.     or.b #$40,$bfee01
  187.     and.b #$bf,$bfee01
  188.     move.w INTREQR,INTREQ
  189.     move.b (sp)+,d0
  190.     rte
  191. level3_interrupt
  192.     btst.b #5,INTREQR+1
  193.     beq not_vblank_int
  194.         bsr every_frame
  195. not_vblank_int
  196.     move.w INTREQR,INTREQ
  197.     rte
  198. ***********************************************************
  199. clear_screen
  200.     move.w #7999,d0
  201.     moveq.l #0,d1
  202. clrscreenloop
  203.         move.l d1,(a0)+
  204.     dbra d0,clrscreenloop
  205.     rts
  206. ***********************************************************
  207. init_scraddrs
  208.     move.l #ascr1,dispscr
  209.     move.l #ascr1,dispscr
  210.     move.l #ascr1d,dispscr_d
  211.     move.l #ascr1d,dispscr_d
  212.     move.l #0,writeoff
  213.     move.l #4,dispoff
  214.     rts
  215. ***********************************************************
  216. set_palette
  217.     move.l #COLOR0,a0
  218.     move.l d0,a1
  219.     move.w #15,d0
  220. palette_loop
  221.         move.w (a1)+,(a0)+
  222.     dbra d0,palette_loop
  223.     rts
  224. ***********************************************************
  225. show_screen
  226.     move.l d0,d1
  227.     add.l #40,d1
  228.     move.l d1,d2
  229.     add.l #40,d2
  230.     move.l d2,d3
  231.     add.l #40,d3
  232.     move.w d0,pln1low
  233.     swap d0
  234.     move.w d0,pln1high
  235.     move.w d1,pln2low
  236.     swap d1
  237.     move.w d1,pln2high
  238.     move.w d2,pln3low
  239.     swap d2
  240.     move.w d2,pln3high
  241.     move.w d3,pln4low
  242.     swap d3
  243.     move.w d3,pln4high
  244.     rts    
  245.  
  246. **************** COPPER *******************
  247. copperlist
  248. coppersprs
  249.     dc.w $120,0,$122,0,$124,0,$126,0
  250.     dc.w $128,0,$12a,0,$12c,0,$12e,0
  251.     dc.w $130,0,$132,0,$134,0,$136,0
  252.     dc.w $138,0,$13a,0,$13c,0,$13e,0
  253.     dc.w $e0
  254. pln1high
  255.     dc.w $7
  256.     dc.w $e2
  257. pln1low
  258.     dc.w $8000
  259.     dc.w $e4
  260. pln2high
  261.     dc.w $7
  262.     dc.w $e6
  263. pln2low
  264.     dc.w $8028
  265.     dc.w $e8
  266. pln3high
  267.     dc.w $7
  268.     dc.w $ea
  269. pln3low
  270.     dc.w $8050
  271.     dc.w $ec
  272. pln4high
  273.     dc.w $7
  274.     dc.w $ee
  275. pln4low
  276.     dc.w $8078
  277.     dc.w $ffff,$fffe
  278. offsprite
  279.     dc.w $0101,$0100,0,0,0,0,0,0,0,0
  280.  
  281. ************************** VARS ***************************
  282. writescr        ds.l 1    * address of 1 screen
  283. dispscr         ds.l 1    * address of other
  284. writescr_d        ds.l 1    * addr of display 1
  285. dispscr_d        ds.l 1    * addr of 2
  286. writeoff        ds.l 1    * offset (0/4) for tables
  287. dispoff            ds.l 1    * opposite of above ie 4/0
  288. junk            ds.l 1    * junk address
  289. curr_pal        ds.l 1    * Current palette pointer
  290. key_press        ds.b 1
  291. frame_end        ds.b 1
  292.  
  293. gun_button        ds.b 1    * gun port in value
  294. gun_fired        ds.b 1    * fire shot
  295. X_cal            ds.w 1    * X calibration
  296. Y_cal            ds.w 1    * Y calibration
  297. GunX            ds.w 1
  298. GunY            ds.w 1
  299.  
  300. black_palette
  301.     ds.l 8
  302. load_palette
  303.         dc.w $000,$fff,$003,$116
  304.         dc.w $359,$69c,$adf,$a8d
  305.         dc.w $65a,$326,$113,$dbf
  306.         dc.w $a60,$fd0,$999,$333
  307. white_palette
  308.         dc.w $fff,$fff,$fff,$fff
  309.         dc.w $fff,$fff,$fff,$fff
  310.         dc.w $fff,$fff,$fff,$fff
  311.         dc.w $fff,$fff,$fff,$fff
  312.  
  313. ** my stack space **
  314.     ds.l 70
  315. stack_pointer
  316.     ds.l 5
  317.  
  318. ************************** END ***************************
  319. ***********************************************************
  320. ***********************************************************
  321. ***********************************************************
  322. *      Gun Driver Code Follows 
  323. ***********************************************************
  324. * executed every 50th sec 
  325. every_frame
  326.     add.b #1,frame_end
  327.     rts
  328.  
  329. ***********************************************************
  330. calibrate_screen
  331.     move.l #ascr1,a0        * clear both screens
  332.     bsr clear_screen
  333.  
  334.     * Plot blob at 160,100 *
  335.     * Or animate your sprite here *
  336.     move.w #XMiddle,d0
  337.     move.w #YMiddle,d1
  338.     bsr plot_point
  339.     move.w #XMiddle+1,d0
  340.     move.w #YMiddle,d1
  341.     bsr plot_point
  342.     move.w #XMiddle-1,d0
  343.     move.w #YMiddle,d1
  344.     bsr plot_point
  345.     move.w #XMiddle,d0
  346.     move.w #YMiddle+1,d1
  347.     bsr plot_point
  348.     move.w #XMiddle,d0
  349.     move.w #YMiddle-1,d1
  350.     bsr plot_point
  351.         
  352. restart_screen
  353.     clr.w X_cal
  354.     clr.w Y_cal        * clear previous calibrations
  355. no_cal_press
  356.     bsr read_trigger    * Wait for trigger pull
  357.     tst.b gun_button
  358.     beq no_cal_press
  359.  
  360.     clr.b frame_end        * Wait for next frame start
  361.     bsr frame_wait
  362.     bsr gun_read        * Read the Gun X and Y
  363.  
  364.     move.w GunX,d0        * Get gun X&Y
  365.     move.w GunY,d1
  366.  
  367.     sub.w #XMiddle,d0    * Get offsets from centre of target
  368.     sub.w #YMiddle,d1
  369.  
  370.      move.w d0,X_cal        * Store as calibrate offsets
  371.     move.w d1,Y_cal        * These are added to shot pos
  372.  
  373.     tst.b gun_fired        * Make sure gun registered properly
  374.     beq restart_screen    * Else calibrate again
  375.  
  376.     cmp.w #24,X_cal        * Check calibrated roughly right
  377.     bcs no_restart_screen    * at roughly correct X
  378.     cmp.w #-24,X_cal
  379.     bcc no_restart_screen    * at roughly correct X
  380.     bra restart_screen    * If not close then redo
  381. no_restart_screen
  382.     rts    
  383.  
  384. ***********************************************************
  385. * read the gun button and put val in gun_button
  386. read_trigger
  387.     sf.b gun_button        * Clear trigger flag
  388.     btst.b #1,JOY1DAT    * Test tigger bit on port
  389.     beq not_pressed_trigger
  390.         not.b gun_button    * Set trigger flag
  391. not_pressed_trigger
  392.     rts
  393.  
  394. ***********************************************************
  395. * read the beam pos on the screen *
  396. gun_read
  397.     move.b #1,gun_fired        * Set gun fired flag
  398. read_the_beam    
  399.     move.l #white_palette,d0
  400.     bsr set_palette            * White out screen
  401.     * now computer is looking down the screen for beam *
  402. frame_wait2            * wait for frame end before resetting cols
  403.     tst.b frame_end
  404.     beq frame_wait2
  405.     clr.b frame_end
  406.  
  407.     * reset cols *
  408.     move.l #load_palette,d0
  409.     bsr set_palette
  410.  
  411.     bsr make_coords        * Get register and make coords
  412.     
  413.     move.w X_cal,d0        * SUBTRACT the calibration offsets
  414.     move.w Y_cal,d1
  415.     sub.w d0,GunX
  416.     sub.w d1,GunY
  417.     rts                        * return to main program *
  418.  
  419. ***********************************************************
  420. * Correct the latched location into X and Y coords
  421. make_coords
  422.     move.l VPOSR,d0        * Latched lightpen location
  423.     move.l d0,d1        * y copy
  424.     and.l #$01ff00,d1
  425.     lsr.l #8,d1        * correct Y
  426.     and.l #511,d1
  427.  
  428.     and.w #$ff,d0
  429.     lsl.w #1,d0
  430.     and.w #511,d0        * correct X
  431.  
  432.     btst.l #8,d1        * check if Y>255
  433.     bne clear_gunshot
  434.     cmp.w #176,d0        * see if on left half of screen
  435.     bcs off_left_part
  436.         sub.w #192,d0
  437.         bra install_coords
  438. off_left_part
  439.     cmp.w #90,d0
  440.     bcc off_right_part
  441.         add.w #452-192,d0
  442.         bra install_coords
  443. off_right_part 
  444. clear_gunshot    * If off screen then come here
  445.         sf.b gun_fired
  446. install_coords
  447.     and.l #511,d0
  448.     and.l #511,d1
  449.     move.w d0,GunX        * Store values
  450.     move.w d1,GunY
  451.     rts
  452.  
  453. ***********************************************************
  454. ***********************************************************
  455. ***********************************************************
  456. ***********************************************************
  457.