-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
192 lines (129 loc) · 2.71 KB
/
main.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <string.h>
#include <eZ8.h> // special encore constants, macros and flash routines
#include <sio.h>
#include "ansi.h"
#include "sin.h"
#include "LED.h"
#include "spil.h"
#include "hardware.h"
#include "main.h"
#include "menu.h"
#define FIX14_SHIFT 14
#define FIX14_MULT(a ,b) ((a)*(b) >> FIX14_SHIFT)
#define FIX14_DIV(a,b) (((a) << FIX14_SHIFT) / (b))
/*void timer0int();
void led(char a);
void printFix(long i);
long expand(long i);
//char FLAG;
void initVector(struct TVector * v,long x, long y);
void rotate(struct TVector * v,int angle);
void printchar(char dig);
void spil();
void pause();
char TILSTAND;
struct TVector{
long x,y;
};
struct Pos{
int x,y;
};
struct Time{
int hour,min,sec,ms;
};
struct Time tid;
struct Klods{
struct Pos pos;
char liv;
char farve;
};
*/
char TILSTAND;
void main(){
init_uart(_UART0,_DEFFREQ,_DEFBAUD);
SET_VECTOR(TIMER0, timer0int);
timer();
EI();
color(2,0);
clrscr();
window(5,5,60,18,"Stop",1);
window(7,7,58,16,"Watch",0);
window(10,10,90,50,"hejsa",1);
LEDinit();
LEDsetString("Dette ReflexBall spil bliver mega awesome!<<<<");
TILSTAND=1;
while(1!=2){
switch(TILSTAND){
case 0 : //menu
menu(&TILSTAND);
break;
case 1: //spil
spil();
break;
case 2: //pause
pause();
break;
}
}
}
void pause(){
}
#pragma interrupt
void timer0int(){
DI();
LEDupdate();
tid.ms++;
// FLAG=1;
if(tid.ms==1000){tid.ms=0;tid.sec++;}
if(tid.sec==60){tid.min++; tid.sec=0;}
if(tid.min==60){tid.hour++;tid.min=0;}
EI();
}
void printchar(char dig){
printf("%c",(dig&0x80 ? '1' :'0'));
printf("%c",(dig&0x40 ? '1' :'0'));
printf("%c",(dig&0x20 ? '1' :'0'));
printf("%c",(dig&0x10 ? '1' :'0'));
printf("%c",(dig&0x08 ? '1' :'0'));
printf("%c",(dig&0x04 ? '1' :'0'));
printf("%c",(dig&0x02 ? '1' :'0'));
printf("%c",(dig&0x01 ? '1' :'0'));
}
void led(char a){
static char clk;
PEDD=0x00;
PEADDR=0;
if(clk==0){ //klokke og colonne
PEOUT=0x8F;
clk=1;
}
else{
PEOUT=0x0F;
clk=0;
}
//data til rækker
PGDD=0x00;
PGADDR=0;
PGOUT=a&0x7F;
}
void initVector(struct TVector * v,long x, long y){
v->x=x<<FIX14_SHIFT;
v->y=y<<FIX14_SHIFT;
}
void rotate(struct TVector * v,int angle){
long x=v->x;
long y=v->y;
v->x = FIX14_MULT(x, cos(angle)) - FIX14_MULT(y, sin(angle));
v->y = FIX14_MULT(x, sin(angle)) + FIX14_MULT(y, cos(angle));
}
void printFix(long i){
//prints 16.16
if((i & 0x80000000) !=0){
printf("-");
i =~i+1;
}
printf("%ld.%04ld", i>>16,10000* (unsigned long) (i & 0xffff) >> 16);
}
long expand(long i){
return i << 2;
}