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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [software/] [spacewar/] [main.c] - Blame information for rev 80

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 80 olivier.gi
//************************************************************
2
// 
3
//      SPACEWAR
4
//      VERSION 5B
5
//      BY
6
//      LARRY BRYANT AND BILL SEILER
7
//      JULY 21, 1974 for PDP-11
8
//      July 2006 for MSP430F2013
9
//
10
//************************************************************
11
//
12
//   SPACEWAR HARWARE
13
//
14
//      Master
15
//   MSP430F2013
16
//   ------------
17
//  |         XIN|-        DAC_X_Y   
18
//  |            |         TLV5618A  
19
//  |        XOUT|-        -------- 
20
//  |        P1.0|->LED       |        |
21
//  |        P1.2|------->|/SYNC   |
22
//  |  P1.3(VREF)|-3.6V   |    OUTA|-->DAC_X
23
//  |            |        |        |
24
//  |    SDI/P1.7|        |    OUTB|-->DAC_Y
25
//  |    SDO/P1.6|------->|DIN     |
26
//  |   SCLK/P1.5|<-------|SCLK    |
27
//   ------------          --------
28
//
29
//  B. Seiler
30
//  July 2006
31
//************************************************************
32
 
33
#include "spacewar.h"
34
#include "msp430x20x3.h"
35
 
36
//************************************************************
37
// externals
38
//
39
extern void init_all(rkt_data *, rkt_data *);
40
extern unsigned int read_a2d(unsigned int);
41
extern void update(rkt_data *, unsigned int);
42
extern void compar(rkt_data *, rkt_data *);
43
extern void score(rkt_data *, rkt_data *);
44
extern void rocket1(rkt_data *);
45
extern void rocket2(rkt_data *);
46
 
47
//************************************************************
48
//
49
// globlal variables
50
//
51
volatile int xinit, yinit;     // starting point of a lines
52
volatile unsigned char flags;  // bit 0 = time tick flag
53
 
54
//************************************************************
55
//
56
// play_spacewar
57
//
58
/* Description:
59
  Plays a two rocket game of classic MIT SPACEWAR.  First the hardware and game
60
variables are setup.  An infinite while loop then executes.  The infinite loop
61
is the main loop that continously draws both rockets and all the torpedos.
62
There is a background timer interrupt that occurs every 10ms.  When the timer
63
interrupt occures extra operations are added to main loop.  The rocket and
64
torpedo positions are updated every 10ms so animation speed remain constant.
65
The player buttons are read every 10ms and if any buttons are pressed player
66
input is applied.  The rockets and torpedos are checked for collisions every
67
10ms.  If a collision is detected the correct shield is decremented.
68
The shields are checked every 10ms.  If any shield has reached zero the game
69
is ended.  If the game has ended the score is displayed.  Then the next game
70
then starts again.
71
*/
72
void play_spacewar(rkt_data *rkt1, rkt_data *rkt2)
73
{
74
 
75
  init_all(rkt1, rkt2);                     // setup MSP430 hardware and variables
76
 
77
  while (1) {
78
    P1OUT ^= 0x01;                          // Toggle P1.0
79
    if(flags && time_tick) {                // only do updates on time tick
80
      update(rkt1, read_a2d(SD16INCH_2));   // check rkt1's buttons update positions
81
      update(rkt2, read_a2d(SD16INCH_4));   // check rkt2's buttons update positions
82
      compar(rkt1, rkt2);                   // check for collisions or hits
83
      score(rkt1, rkt2);                    // check for game end, show score
84
      flags &= ~time_tick;                  // clear time tick flag
85
    }
86
    rocket1(rkt1);                          // draw rocket 1
87
    rocket2(rkt2);                          // draw rocket 2
88
  }
89
}
90
 
91
//************************************************************
92
//
93
// main
94
//
95
/* Description:
96
  Calls a function named play_spacewar.  This extra call reduces code size
97
by using registers as the pointers to the structures rkt1 and rkt2.
98
*/
99
void main(void)
100
{
101
struct rkt_data rkt1, rkt2;
102
 
103
  play_spacewar(&rkt1, &rkt2);              // play the game
104
}
105
 

powered by: WebSVN 2.1.0

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