-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
226 lines (191 loc) · 5.09 KB
/
main.c
File metadata and controls
226 lines (191 loc) · 5.09 KB
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include "main.h"
#include <atari.h>
#include <peekpoke.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "asmsprite.h"
#include "game.h"
#include "pmbase.h"
#include "scrl.h"
void updateDL() {
int i;
int dl = 0;
dlist[dl++] = DL_BLK8;
dlist[dl++] = DL_BLK8;
dlist[dl++] = DL_BLK8;
dlist[dl++] = DL_LMS(DL_CHR40x8x1);
mapstrt[0] = dlist[dl++] = ((unsigned int)map) & 0xff;
mapstrt[1] = dlist[dl++] = mapstrt[2 + 1] = ((unsigned int)map) >> 8 & 0xff;
for (i = 1; i < 23; i++) {
dlist[dl++] = DL_HSCROL(DL_LMS(DL_CHR40x8x1));
mapstrt[i * 2] = dlist[dl++] = ((unsigned int)map + i * MAPCOLS) & 0xff;
mapstrt[i * 2 + 1] = dlist[dl++] = mapstrt[i * 2 + 1] =
((unsigned int)map + i * MAPCOLS) >> 8 & 0xff;
}
dlist[dl++] = DL_JVB;
dlist[dl++] = ((unsigned int)dlist) & 0xff;
dlist[dl++] = ((unsigned int)dlist >> 8) & 0xff;
OS.sdlst = dlist;
}
void initPat() {
unsigned int i;
for (i = 0; i < PATLEN; i++) {
POKE((unsigned char *)CHARSET + i, pat[i]);
}
}
void initPM(struct __double_pmgmem *pm) {
int j;
for (j = 0; j < 128; j++) {
pm->missiles[j] = 0x00;
pm->player0[j] = 0x00;
pm->player1[j] = 0x00;
pm->player2[j] = 0x00;
pm->player3[j] = 0x00;
}
for (j = 0; j < 8; j++) {
pm->player1[j + GROUND + 12] = barrel1[j];
pm->player2[j + GROUND + 12] = barrel1[j];
pm->player3[j + GROUND + 12] = barrel1[j];
}
}
void showLives(char l) {
char c;
for (c = 0; c < LIVES; c++) {
if (l > 0) {
map[15 + c] = 0x3;
l--;
} else {
map[15 + c] = 0x7;
}
}
}
int game() {
int score;
char lives;
int yv = 0, m;
char lastjump = 0;
lives = LIVES;
score = 0;
x1v = 1;
x2v = 1;
x3v = 1;
OS.ch = 0xff;
x1v = 1;
x2v = 0;
x3v = 0;
scrl();
while (lives > 0) {
x1v = x1v || (rand() % 2);
x2v = x2v || (rand() % 5);
x3v = x3v || (rand() % 10);
oy = y;
if (OS.ch == 0x21 && lastjump < 4) {
OS.ch = 0xff;
yv += -40;
lastjump++;
}
yv += 1;
y += yv / 10;
if (y < 10) {
y = 10;
}
if (y > GROUND) {
y = GROUND;
yv = 0;
lastjump = 0;
}
m = y - oy;
if (m < 0) {
up(pmgmem->player0, abs(m));
up(pmgmem2->player0, abs(m));
} else if (m > 0) {
down(pmgmem->player0, m);
down(pmgmem2->player0, m);
}
if (x1v == 1 && x1 > DINOX - 5 && x1 < DINOX + 5) {
if (y > JUMPCLEAR) {
x1v = 0;
x1 = DINOX - 10;
lives--;
} else {
score += 10;
}
}
if (x2v == 1 && x2 > DINOX - 5 && x2 < DINOX + 5) {
if (y> JUMPCLEAR) {
x2v = 0;
x2 = DINOX - 10;
lives--;
} else {
score += 10;
}
}
if (x3v == 1 && x3 > DINOX - 5 && x3 < DINOX + 5) {
if (y > JUMPCLEAR) {
x3 = DINOX - 10;
lives--;
} else {
score += 10;
}
}
showLives(lives);
}
return score;
}
int main() {
char j;
int origdl;
curpm = (unsigned char *)&pmgmembuf;
backpm = (unsigned char *)&pmgmembuf2;
ANTIC.pmbase = (unsigned char)((((unsigned int)curpm) >> 8) & 0xff);
pmgmem = (struct __double_pmgmem *)curpm;
pmgmem2 = (struct __double_pmgmem *)backpm;
OS.chbas = (unsigned char)((unsigned int)CHARSET / 256 & 0xff);
initPM(pmgmem);
initPM(pmgmem2);
initPat();
printf("Dino Run\n");
printf("Press space to jump\n");
printf("Avoid the barrels\n");
while (OS.ch == 0xff) {
}
OS.ch = 0xff;
origdl = OS.sdlst;
OS.gprior = PRIOR_P03_PF03;
GTIA_WRITE.sizep0 = PMG_SIZE_DOUBLE;
GTIA_WRITE.sizep1 = PMG_SIZE_NORMAL;
GTIA_WRITE.sizep2 = PMG_SIZE_NORMAL;
GTIA_WRITE.sizep3 = PMG_SIZE_NORMAL;
OS.sdmctl = 46;
OS.sdmctl = DMACTL_PLAYFIELD_NORMAL | DMACTL_DMA_MISSILES |
DMACTL_DMA_PLAYERS | DMACTL_DMA_FETCH;
OS.pcolr0 = COLOR_GREEN;
OS.pcolr1 = COLOR_RED;
OS.pcolr2 = COLOR_BLUE;
OS.pcolr3 = COLOR_YELLOW;
GTIA_WRITE.hposp0 = DINOX;
for (j = 0; j < 20; j++) {
pmgmem->player0[j] = dino1[j];
}
for (j = 0; j < 20; j++) {
pmgmem2->player0[j] = dino2[j];
}
down(pmgmem->player0, GROUND);
down(pmgmem2->player0, GROUND);
y = GROUND;
printf("Starting game...\n");
while (1) {
updateDL();
GTIA_WRITE.hposp1 = x1 = rand() % 110;
GTIA_WRITE.hposp2 = x2 = rand() % 110;
GTIA_WRITE.hposp3 = x3 = rand() % 110;
GTIA_WRITE.gractl = GRACTL_PLAYERS;
printf("Score: %d\n", game());
GTIA_WRITE.gractl = 0;
OS.sdlst = origdl;
while (OS.ch == 0xff) {
}
OS.ch = 0xff;
}
}