-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpaceInvaders.c
139 lines (119 loc) · 4.5 KB
/
SpaceInvaders.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// SpaceInvaders.c
// Runs on LM4F120/TM4C123
// Jonathan Valvano and Daniel Valvano
// This is a starter project for the edX Lab 15
// In order for other students to play your game
// 1) You must leave the hardware configuration as defined
// 2) You must not add/remove any files from the project
// 3) You must add your code only this this C file
// I.e., if you wish to use code from sprite.c or sound.c, move that code in this file
// 4) It must compile with the 32k limit of the free Keil
// April 10, 2014
// http://www.spaceinvaders.de/
// sounds at http://www.classicgaming.cc/classics/spaceinvaders/sounds.php
// http://www.classicgaming.cc/classics/spaceinvaders/playguide.php
/* This example accompanies the books
"Embedded Systems: Real Time Interfacing to Arm Cortex M Microcontrollers",
ISBN: 978-1463590154, Jonathan Valvano, copyright (c) 2013
"Embedded Systems: Introduction to Arm Cortex M Microcontrollers",
ISBN: 978-1469998749, Jonathan Valvano, copyright (c) 2013
Copyright 2014 by Jonathan W. Valvano, valvano@mail.utexas.edu
You may use, edit, run or distribute this file
as long as the above copyright notice remains
THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
VALVANO SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
For more information about my classes, my research, and my books, see
http://users.ece.utexas.edu/~valvano/
*/
// ******* Required Hardware I/O connections*******************
// Slide pot pin 1 connected to ground
// Slide pot pin 2 connected to PE2/AIN1
// Slide pot pin 3 connected to +3.3V
// fire button connected to PE0
// special weapon fire button connected to PE1
// 8*R resistor DAC bit 0 on PB0 (least significant bit)
// 4*R resistor DAC bit 1 on PB1
// 2*R resistor DAC bit 2 on PB2
// 1*R resistor DAC bit 3 on PB3 (most significant bit)
// LED on PB4
// LED on PB5
// Blue Nokia 5110
// ---------------
// Signal (Nokia 5110) LaunchPad pin
// Reset (RST, pin 1) connected to PA7
// SSI0Fss (CE, pin 2) connected to PA3
// Data/Command (DC, pin 3) connected to PA6
// SSI0Tx (Din, pin 4) connected to PA5
// SSI0Clk (Clk, pin 5) connected to PA2
// 3.3V (Vcc, pin 6) power
// back light (BL, pin 7) not connected, consists of 4 white LEDs which draw ~80mA total
// Ground (Gnd, pin 8) ground
// Red SparkFun Nokia 5110 (LCD-10168)
// -----------------------------------
// Signal (Nokia 5110) LaunchPad pin
// 3.3V (VCC, pin 1) power
// Ground (GND, pin 2) ground
// SSI0Fss (SCE, pin 3) connected to PA3
// Reset (RST, pin 4) connected to PA7
// Data/Command (D/C, pin 5) connected to PA6
// SSI0Tx (DN, pin 6) connected to PA5
// SSI0Clk (SCLK, pin 7) connected to PA2
// back light (LED, pin 8) not connected, consists of 4 white LEDs which draw ~80mA total
#include "..//tm4c123gh6pm.h"
#include "Nokia5110.h"
#include "Random.h"
#include "TExaS.h"
#include "Images.c"
#include "Sounds.c"
#include "SpritesOps.c"
#include "HandlersOps.c"
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
int main(void){
TExaS_Init(SSI0_Real_Nokia5110_Scope); // set system clock to 80 MHz
DisableInterrupts();
Random_Init(1);
Nokia5110_Init();
Nokia5110_ClearBuffer();
Nokia5110_DisplayBuffer();
SysTick_Init();
// initialize Timer2 after Nokia5110_Init because of
// error-prone registers operations (old and new registers
// are not working good together)
// 80MHz/11,025 cycles, which is about 7256
Timer2_Init(7256);
Ports_Init();
InitSprites(NumberOfEnemies);
RestartGame();
// Countdown, after which all interrupts are enabled!
// print 3
Nokia5110_ClearBuffer();
Nokia5110_PrintBMP(28, 41, _my_Countdown_03, 0);
Nokia5110_DisplayBuffer();
Delay100ms(3);
// print 2
Nokia5110_ClearBuffer();
Nokia5110_PrintBMP(28, 41, _my_Countdown_02, 0);
Nokia5110_DisplayBuffer();
Delay100ms(3);
// print 1
Nokia5110_ClearBuffer();
Nokia5110_PrintBMP(28, 41, _my_Countdown_01, 0);
Nokia5110_DisplayBuffer();
Delay100ms(3);
// print GO
Nokia5110_ClearBuffer();
Nokia5110_PrintBMP(28, 41, _my_Countdown_GO, 0);
Nokia5110_DisplayBuffer();
Delay100ms(3);
EnableInterrupts();
while(1){
if (Flag == 1) {
Nokia5110_DisplayBuffer();
Flag = 0;
}
}
}