-
Notifications
You must be signed in to change notification settings - Fork 0
/
control.c
156 lines (126 loc) · 2.48 KB
/
control.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
/* control.c /
/ /
/ movements for tank. /
/ may need gcc -02 to /
/ compile. /
/ /
/ David Baker 2004 /
/ */
#include <stdio.h>
#include <string.h>
#include <asm/io.h>
#include "control.h"
#define BASEPORT 0x378 /* lp1 */
/* used primarily for taking contents of macro file */
void move_tank(char direc[], int time)
{
if (!strcmp(direc, "ff")) {
forward(time);
}
else if (!strcmp(direc, "bb")) {
backward(time);
}
else if (!strcmp(direc, "fr")) {
foright(time);
}
else if (!strcmp(direc, "fl")) {
foleft(time);
}
else if (!strcmp(direc, "br")) {
baright(time);
}
else if (!strcmp(direc, "bl")) {
baleft(time);
}
else if (!strcmp(direc, "ss")) {
stop(time);
}
else {
printf("ERROR: cannot move tank in that direction\n");
safe_exit(1);
}
} /* end move_tank function */
/* seven possible tank movements */
void forward (int time)
{
outb(8, BASEPORT); /* 1000 */
sleep(time);
outb(0, BASEPORT);
}
void backward (int time)
{
outb(4, BASEPORT); /* 0100 */
sleep(time);
outb(0, BASEPORT);
}
void foright (int time)
{
outb(10, BASEPORT); /* 1001 */
sleep(time);
outb(0, BASEPORT);
}
void foleft (int time)
{
outb(9, BASEPORT); /* 1010 */
sleep(time);
outb(0, BASEPORT);
}
void baright (int time)
{
outb(6, BASEPORT); /* 0101 */
sleep(time);
outb(0, BASEPORT);
}
void baleft (int time)
{
outb(5, BASEPORT); /* 0110 */
sleep(time);
outb(0, BASEPORT);
}
void stop(int time)
{
outb(0, BASEPORT); /* 0000 */
sleep(time);
}
/* end of the seven tank movements */
/*/ / / / / / / / / / / / / / / / / /
/ manual mode requires the ports to
/ be set for an indefinite amount
/ of time, so they require their
/ own functions */
/* manual mode movement functions */
void man_f(void) /* forward */
{
outb(8, BASEPORT);
/*printf("status: %d\n", inb(BASEPORT));*/
}
void man_b(void) /* backward */
{
outb(4, BASEPORT);
/*printf("status: %d\n", inb(BASEPORT));*/
}
void man_fr(void) /* for+right */
{
outb(10, BASEPORT);
/*printf("status: %d\n", inb(BASEPORT));*/
}
void man_fl(void) /* for+left */
{
outb(9, BASEPORT);
/*printf("status: %d\n", inb(BASEPORT));*/
}
void man_br(void) /* bac+right */
{
outb(6, BASEPORT);
/*printf("status: %d\n", inb(BASEPORT));*/
}
void man_bl(void) /* bac+left */
{
outb(5, BASEPORT);
/*printf("status: %d\n", inb(BASEPORT));*/
}
void man_stop(void) /* brakes (-: */
{
outb(0, BASEPORT);
/*printf("status: %d\n", inb(BASEPORT));*/
}