home *** CD-ROM | disk | FTP | other *** search
/ MACD 4 / MACD4.iso / Emulatory / v2600 / source.lha / source / collision.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-27  |  2.6 KB  |  116 lines

  1. /*****************************************************************************
  2.  
  3.    This file is part of x2600, the Atari 2600 Emulator
  4.    ===================================================
  5.    
  6.    Copyright 1996 Alex Hornby. For contributions see the file CREDITS.
  7.  
  8.    This software is distributed under the terms of the GNU General Public
  9.    License. This is free software with ABSOLUTELY NO WARRANTY.
  10.    
  11.    See the file COPYING for details.
  12.    
  13.    $Id: collision.c,v 1.9 1996/09/04 22:35:20 ahornby Exp $
  14.  
  15.    Tweaked by Matthew Stroup for Amiga v2600, January 27, 1997.
  16.  
  17. ******************************************************************************/
  18.  
  19. /* The 2600 collision detection code */
  20.  
  21. #include "config.h"
  22.  
  23. #include <stdlib.h>
  24.  
  25. #include "options.h"
  26. #include "types.h"
  27. #include "address.h"
  28. #include "vmachine.h"
  29. #include "col_mask.h"
  30.  
  31. /*
  32.    There are 6 different objects on the screen. Each takes one bit of the 
  33.    collision vector.
  34.    Bit 0: Player 0
  35.    Bit 1: Player 1
  36.    Bit 2: Missile 0
  37.    Bit 3: Missile 1
  38.    Bit 4: Ball
  39.    Bit 5: Playfield
  40.  */
  41.  
  42. /* The collision vector */
  43. UBYTE *colvect;
  44.  
  45. /* The collision lookup table */
  46. unsigned short col_table[256];
  47.  
  48. /* The collision state */
  49. unsigned short col_state;
  50.  
  51. /* Resets the collision registers of the tia */
  52. inline void
  53. reset_collisions (void)
  54. {
  55.   col_state=0;
  56. }
  57.  
  58. /* Does collision testing on the pixel b */
  59. /* b: byte to test for collisions */
  60. /* Used to build up the collision table */
  61. int
  62. set_collisions (UBYTE b)
  63. {
  64.   int res=0;
  65.  
  66.   if ((b & ML0_MASK) && (b & PL1_MASK))
  67.     res |= M0P1_MASK;
  68.   if ((b & ML0_MASK) && (b & PL0_MASK))
  69.     res |= M0P0_MASK;
  70.   if ((b & ML1_MASK) && (b & PL0_MASK))
  71.     res |=  M1P0_MASK;
  72.   if ((b & ML1_MASK) && (b & PL1_MASK))
  73.     res |=  M1P1_MASK;
  74.  
  75.   if ((b & PL0_MASK) && (b & PF_MASK))
  76.     res |= P0PF_MASK; 
  77.   if ((b & PL0_MASK) && (b & BL_MASK))
  78.     res |= P0BL_MASK;
  79.   if ((b & PL1_MASK) && (b & PF_MASK))
  80.     res |= P1PF_MASK ;
  81.   if ((b & PL1_MASK) && (b & BL_MASK))
  82.     res |= P1BL_MASK;
  83.  
  84.   if ((b & ML0_MASK) && (b & PF_MASK))
  85.     res |=  M0PF_MASK;
  86.   if ((b & ML0_MASK) && (b & BL_MASK))
  87.     res |= M0BL_MASK;
  88.   if ((b & ML1_MASK) && (b & PF_MASK))
  89.     res |=  M1PF_MASK; 
  90.   if ((b & ML1_MASK) && (b & BL_MASK))
  91.     res |=  M1BL_MASK;
  92.  
  93.   if ((b & BL_MASK) && (b & PF_MASK))
  94.     res |=BLPF_MASK;
  95.   if ((b & PL0_MASK) && (b & PL1_MASK))
  96.     res |=P0P1_MASK ;
  97.   if ((b & ML0_MASK) && (b & ML1_MASK))
  98.     res |=M0M1_MASK ;
  99.  
  100.   return res;
  101. }
  102.  
  103.  
  104. void
  105. init_collisions(void)
  106. {
  107.   int i;
  108.  
  109.   /* Set up the collision lookup table */ 
  110.   for (i = 0; i < 256; i++)
  111.     col_table[i] = set_collisions(i);
  112.  
  113.   /* Get the colvect 8 byte aligned */
  114.   colvect=(UBYTE *)calloc(28, 8);
  115. }
  116.