-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
291 lines (251 loc) · 7.67 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
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include <stdio.h>
#include <6502.h>
#include <cbm.h>
#include <conio.h>
#include <cx16.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include "common.h"
#include "sprite.h"
#include "map.h"
#include "calendar.h"
#include "memory.h"
#include "song.h"
#include "menus.h"
#include "ship.h"
#define PLAYER_SPRITE 1
#define LOAD_TO_MAIN_RAM 0
#define LOAD_TO_VERA 2
#define SHIP_ADDR_START 0x4000
//#define SHIP_ADDR_DRAKKAR 0x4000
//#define SHIP_ADDR_DROMON 0x4400
//#define SHIP_ADDR_GENOESE 0x4800
//#define SHIP_ADDR_PENTEKONTOR 0x4c00
//#define SHIP_ADDR_SAMBUK 0x5000
//#define SHIP_ADDR_TARTANE 0x5400
//#define SHIP_ADDR_TRIREME 0x5800
//#define SHIP_ADDR_XEBEC 0x5c00
struct regs r;
/*
char* title[] = {
" ***** ** ",
" ****** **** * * ",
" ** * * *** *** ** ",
" * * * *** * ** ",
" * * ** *** **** ******** ",
" ** ** ** *** **** **** * **** ******** *** ",
" ** ** ** *** ** **** * *** * ** * *** ",
" **** ** * ** ** * **** ** * *** ",
" * *** ** * ** ** ** ** ** ** *** ",
" ** ******* ** ** ** ** ** ******** ",
" ** ****** ** ** ** ** ** ******* ",
" ** ** ** ** ** ** ** ** ",
" ** ** ** *** ** ** ** **** * ",
" ** ** *** * *** ***** ** ** ******* ",
" ** ** ** *** *** ** ***** ",
"*** * * ",
" *** * ",
" ****** ",
" *** ",
" ",
" ",
" ***** ** ",
" ****** * ** ",
" ** * * * *** ** ",
"* * * *** * * ** ",
" * * *** ** *** ",
" ** ** * * *** *** ** *** ** ** *** *** *** *** * *** * ",
" ** ** * *** ******* * * *** * ******** * *** *** *** ** * ** *** ",
" ** ***** ** ** *** * *** ** **** ** * ** *** *** **** ",
" ** ** *** ** ** * ** ** ** ** ** * ** * * *** ",
" ** ** *** ** ** * ** ** ** ** ** * ** * * *** ",
" * ** ** ** ** * ** ** ** ** ** * ** * * *** ",
" * ** ** ** * ** ** ** ** ** * ** * * **** ** ",
" **** ** ** ** * ** ** ** ** **** ** * * * **** * ",
" * ***** ** * ** * *** ** ******* **** *** *** ** ** **** ",
"* *** *** ** ** *** ** ** ** *** ** ** ",
"* ** ",
" ** *** ** ",
" ****** * ",
" * **** "
};
void splash()
{
byte i;
bgcolor(COLOR_BLACK);
clrscr();
textcolor(COLOR_RED);
for(i=0; i<40; ++i)
{
cputsxy(0,i+1,title[i]);
}
textcolor(COLOR_ORANGE);
chlinexy(0,46,80);
cputsxy(28,52,"press <return> to begin");
cgetc();
}
*/
void loadMapToBankedRAM()
{
setBank(MAP_RAM_BANK_START);
cbm_k_setnam("map.bin");
cbm_k_setlfs(0,8,0);
cbm_k_load(LOAD_TO_MAIN_RAM, 0xa000);
}
void loadVera(char *fname, unsigned int address)
{
cbm_k_setnam(fname);
cbm_k_setlfs(0,8,0);
cbm_k_load(LOAD_TO_VERA, address);
}
void loadSpriteDataToVERA()
{
loadVera("ships-32x32.bin", SHIP_ADDR_START);
loadVera("people-32x32.bin", PEOPLE_ADDR_START);
loadVera("terrain-64x64.bin", LAND_ADDR_START);
}
SpriteDefinition sprdef;
Position pos;
int dx, dy, x, y;
unsigned char shipIndex;
ShipData* ship;
//unsigned getShipAddr(unsigned char index)
//{
// switch((unsigned)index)
// {
// case 1: return SHIP_ADDR_DRAKKAR;
// case 2: return SHIP_ADDR_DROMON;
// case 3: return SHIP_ADDR_GENOESE;
// case 4: return SHIP_ADDR_PENTEKONTOR;
// case 5: return SHIP_ADDR_SAMBUK;
// case 6: return SHIP_ADDR_TARTANE;
// case 7: return SHIP_ADDR_TRIREME;
// default: return SHIP_ADDR_XEBEC;
// }
//}
void initSprite()
{
sprdef.mode = SPRITE_MODE_8BPP;
sprdef.block = ship->address; // (shipIndex); // SHIP_ADDR_SAMBUK; // SHIP_ADDR_TARTANE;
sprdef.collision_mask = 0x0000;
sprdef.layer = SPRITE_LAYER_0;
sprdef.dimensions = SPRITE_32_BY_32;
sprdef.palette_offset = 0;
sprdef.x = SPRITE_X_SCALE(312);
sprdef.y = SPRITE_Y_SCALE(200);
pos.x = sprdef.x;
pos.y = sprdef.y;
sprite_define(PLAYER_SPRITE, &sprdef);
}
void move()
{
if (kbhit())
switch(cgetc())
{
case 0x91: // up
case 'i':
case 'w': if (dy > -ship->speed) dy -= ship->acceleration; break;
case 0x11: // down
case 'k':
case 's': if (dy < ship->speed) dy += ship->acceleration; break;
case 0x9d: // left
case 'j':
case 'a': if (dx > -ship->speed) dx -= ship->acceleration; break;
case 0x1d: // right
case 'l':
case 'd': if (dx < ship->speed) dx += ship->acceleration; break;
case 'm': // hey map!
vera_sprites_enable(0);
vera_sprites_enable(1);
map_region();
map_frame_draw();
menus_show();
break;
case 133: // f1
if (map_has_land_north())
cputsxy(1,20,"n");
else
cputsxy(1,20," ");
if (map_has_land_east())
cputsxy(3,20,"e");
else
cputsxy(3,20," ");
if (map_has_land_west())
cputsxy(4,20,"w");
else
cputsxy(4,20," ");
if (map_has_land_south())
cputsxy(2,20,"s");
else
cputsxy(2,20," ");
break;
case 137: // f2
case 134: // f3
case 138: // f4
case 135: // f5
case 139: // f6
case 136: // f7
case 140: // f8
case 16: // f9
case 21: // f10
case 22: // f11
case 23: // f12
break;
}
if (dy < 0) map_north(-dy);
if (dy > 0) map_south(dy);
if (dx < 0)
{
map_west(-dx);
sprite_horiz_flip(PLAYER_SPRITE);
}
if (dx > 0)
{
map_east(dx);
sprite_horiz_unflip(PLAYER_SPRITE);
}
map_calculate();
}
void setPETFont()
{
// set PET font
struct regs fontregs;
fontregs.a = 4; // PET-like
fontregs.pc = 0xff62;
_sys(&fontregs);
}
void main()
{
setPETFont();
//cbm_k_bsout(CH_FONT_UPPER);
//splash();
_randomize();
bgcolor(COLOR_BLACK);
clrscr();
loadMapToBankedRAM();
loadSpriteDataToVERA();
shipIndex = rand() % 8;
ship = getShipData( shipIndex );
vera_sprites_enable(1); // cx16.h
initSprite();
map_init();
map_frame_draw();
menus_show();
gotoxy(20,52);
cprintf("%-11s %2d/%1d %2d %3d/%-3d %2d/%-2d",
ship->name,
ship->speed,
ship->acceleration,
ship->hull,
ship->people_capacity,
ship->goods_capacity,
ship->ballista_capacity,
ship->greek_fire_capability
);
while(1)
{
updateDate();
move();
}
}