OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [software/] [spacewar/] [main.c] - Diff between revs 80 and 143

Only display areas with differences | Details | Blame | View Log

Rev 80 Rev 143
//************************************************************
//************************************************************
// 
// 
//      SPACEWAR
//      SPACEWAR
//      VERSION 5B
//      VERSION 5B
//      BY
//      BY
//      LARRY BRYANT AND BILL SEILER
//      LARRY BRYANT AND BILL SEILER
//      JULY 21, 1974 for PDP-11
//      JULY 21, 1974 for PDP-11
//      July 2006 for MSP430F2013
//      July 2006 for MSP430F2013
//
//
//************************************************************
//************************************************************
//
//
//   SPACEWAR HARWARE
//   SPACEWAR HARWARE
//
//
//      Master
//      Master
//   MSP430F2013
//   MSP430F2013
//   ------------
//   ------------
//  |         XIN|-        DAC_X_Y   
//  |         XIN|-        DAC_X_Y   
//  |            |         TLV5618A  
//  |            |         TLV5618A  
//  |        XOUT|-        -------- 
//  |        XOUT|-        -------- 
//  |        P1.0|->LED       |        |
//  |        P1.0|->LED       |        |
//  |        P1.2|------->|/SYNC   |
//  |        P1.2|------->|/SYNC   |
//  |  P1.3(VREF)|-3.6V   |    OUTA|-->DAC_X
//  |  P1.3(VREF)|-3.6V   |    OUTA|-->DAC_X
//  |            |        |        |
//  |            |        |        |
//  |    SDI/P1.7|        |    OUTB|-->DAC_Y
//  |    SDI/P1.7|        |    OUTB|-->DAC_Y
//  |    SDO/P1.6|------->|DIN     |
//  |    SDO/P1.6|------->|DIN     |
//  |   SCLK/P1.5|<-------|SCLK    |
//  |   SCLK/P1.5|<-------|SCLK    |
//   ------------          --------
//   ------------          --------
//
//
//  B. Seiler
//  B. Seiler
//  July 2006
//  July 2006
//************************************************************
//************************************************************
 
 
 
#include "omsp_system.h"
#include "spacewar.h"
#include "spacewar.h"
#include "msp430x20x3.h"
 
 
 
//************************************************************
//************************************************************
// externals
// externals
//
//
extern void init_all(rkt_data *, rkt_data *);
extern void init_all(rkt_data *, rkt_data *);
extern unsigned int read_a2d(unsigned int);
extern unsigned int read_a2d(unsigned int);
extern void update(rkt_data *, unsigned int);
extern void update(rkt_data *, unsigned int);
extern void compar(rkt_data *, rkt_data *);
extern void compar(rkt_data *, rkt_data *);
extern void score(rkt_data *, rkt_data *);
extern void score(rkt_data *, rkt_data *);
extern void rocket1(rkt_data *);
extern void rocket1(rkt_data *);
extern void rocket2(rkt_data *);
extern void rocket2(rkt_data *);
 
 
//************************************************************
//************************************************************
//
//
// globlal variables
// globlal variables
//
//
volatile int xinit, yinit;     // starting point of a lines
volatile int xinit, yinit;     // starting point of a lines
volatile unsigned char flags;  // bit 0 = time tick flag
volatile unsigned char flags;  // bit 0 = time tick flag
 
 
//************************************************************
//************************************************************
//
//
// play_spacewar
// play_spacewar
//
//
/* Description:
/* Description:
  Plays a two rocket game of classic MIT SPACEWAR.  First the hardware and game
  Plays a two rocket game of classic MIT SPACEWAR.  First the hardware and game
variables are setup.  An infinite while loop then executes.  The infinite loop
variables are setup.  An infinite while loop then executes.  The infinite loop
is the main loop that continously draws both rockets and all the torpedos.
is the main loop that continously draws both rockets and all the torpedos.
There is a background timer interrupt that occurs every 10ms.  When the timer
There is a background timer interrupt that occurs every 10ms.  When the timer
interrupt occures extra operations are added to main loop.  The rocket and
interrupt occures extra operations are added to main loop.  The rocket and
torpedo positions are updated every 10ms so animation speed remain constant.
torpedo positions are updated every 10ms so animation speed remain constant.
The player buttons are read every 10ms and if any buttons are pressed player
The player buttons are read every 10ms and if any buttons are pressed player
input is applied.  The rockets and torpedos are checked for collisions every
input is applied.  The rockets and torpedos are checked for collisions every
10ms.  If a collision is detected the correct shield is decremented.
10ms.  If a collision is detected the correct shield is decremented.
The shields are checked every 10ms.  If any shield has reached zero the game
The shields are checked every 10ms.  If any shield has reached zero the game
is ended.  If the game has ended the score is displayed.  Then the next game
is ended.  If the game has ended the score is displayed.  Then the next game
then starts again.
then starts again.
*/
*/
void play_spacewar(rkt_data *rkt1, rkt_data *rkt2)
void play_spacewar(rkt_data *rkt1, rkt_data *rkt2)
{
{
 
 
  init_all(rkt1, rkt2);                     // setup MSP430 hardware and variables
  init_all(rkt1, rkt2);                     // setup MSP430 hardware and variables
 
 
  while (1) {
  while (1) {
    P1OUT ^= 0x01;                          // Toggle P1.0
    P1OUT ^= 0x01;                          // Toggle P1.0
    if(flags && time_tick) {                // only do updates on time tick
    if(flags && time_tick) {                // only104 do updates on time tick
      update(rkt1, read_a2d(SD16INCH_2));   // check rkt1's buttons update positions
      update(rkt1, read_a2d(0x0002));       // check rkt1's buttons update positions
      update(rkt2, read_a2d(SD16INCH_4));   // check rkt2's buttons update positions
      update(rkt2, read_a2d(0x0004));       // check rkt2's buttons update positions
      compar(rkt1, rkt2);                   // check for collisions or hits
      compar(rkt1, rkt2);                   // check for collisions or hits
      score(rkt1, rkt2);                    // check for game end, show score
      score(rkt1, rkt2);                    // check for game end, show score
      flags &= ~time_tick;                  // clear time tick flag
      flags &= ~time_tick;                  // clear time tick flag
    }
    }
    rocket1(rkt1);                          // draw rocket 1
    rocket1(rkt1);                          // draw rocket 1
    rocket2(rkt2);                          // draw rocket 2
    rocket2(rkt2);                          // draw rocket 2
  }
  }
}
}
 
 
//************************************************************
//************************************************************
//
//
// main
// main
//
//
/* Description:
/* Description:
  Calls a function named play_spacewar.  This extra call reduces code size
  Calls a function named play_spacewar.  This extra call reduces code size
by using registers as the pointers to the structures rkt1 and rkt2.
by using registers as the pointers to the structures rkt1 and rkt2.
*/
*/
void main(void)
int main(void)
{
{
struct rkt_data rkt1, rkt2;
struct rkt_data rkt1, rkt2;
 
 
  play_spacewar(&rkt1, &rkt2);              // play the game
  play_spacewar(&rkt1, &rkt2);              // play the game
 
 
 
  return 1;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.