|
|
@@ -32,9 +32,10 @@ |
|
|
* moves them and tests collisions; this file spawns them and handles hits. |
|
|
* moves them and tests collisions; this file spawns them and handles hits. |
|
|
* Three lives; a hit costs one and gives a few seconds of blinking safety. |
|
|
* Three lives; a hit costs one and gives a few seconds of blinking safety. |
|
|
* |
|
|
* |
|
|
* Fires: trees catch fire ahead of the chopper. Hold fire to spray water |
|
|
|
|
|
* (the tank refills on the ground); hover low over a burning tree until it |
|
|
|
|
|
* goes out. A fire left behind burns its tree for good (FIRE_T remembers). |
|
|
|
|
|
|
|
|
* Fires: trees catch fire ahead of the chopper. Hold fire to spray water; |
|
|
|
|
|
* hover low over a burning tree until it goes out. A fire left behind burns |
|
|
|
|
|
* its tree for good (FIRE_T remembers). The tank refills only when landed on |
|
|
|
|
|
* a base's helipad: there is one every 256 columns, and the game starts on one. |
|
|
*/ |
|
|
*/ |
|
|
#include <string.h> |
|
|
#include <string.h> |
|
|
#include <c64.h> |
|
|
#include <c64.h> |
|
|
@@ -50,15 +51,23 @@ |
|
|
#define JOY2 (*(volatile unsigned char *)0xDC00) |
|
|
#define JOY2 (*(volatile unsigned char *)0xDC00) |
|
|
#define BLNSW (*(unsigned char *)0x00CC) /* non-zero: Kernal cursor blink off */ |
|
|
#define BLNSW (*(unsigned char *)0x00CC) /* non-zero: Kernal cursor blink off */ |
|
|
|
|
|
|
|
|
/* World tables, built at startup ($5000-$7FFF; the program must end below). */ |
|
|
|
|
|
|
|
|
/* World tables, built at startup. RND_T sits in the RAM under the BASIC ROM, |
|
|
|
|
|
which the game switches out ($01 = $36) before anything else. */ |
|
|
#define WORLD_COLS 4096 |
|
|
#define WORLD_COLS 4096 |
|
|
#define WORLD_MASK 0x0FFF /* the world repeats every 4096 columns */ |
|
|
#define WORLD_MASK 0x0FFF /* the world repeats every 4096 columns */ |
|
|
#define MT_H ((unsigned char *)0x5000) /* mountain height per column, 2..9 */ |
|
|
|
|
|
#define HL_H ((unsigned char *)0x6000) /* hill height per column, 0..3 */ |
|
|
|
|
|
#define RND_T ((unsigned char *)0x7000) /* random byte per column */ |
|
|
|
|
|
#define DATA_LOW 0x5000 |
|
|
|
|
|
|
|
|
#define MT_H ((unsigned char *)0x6000) /* mountain height per column, 2..9 */ |
|
|
|
|
|
#define HL_H ((unsigned char *)0x7000) /* hill height per column, 0..3 */ |
|
|
|
|
|
#define RND_T ((unsigned char *)0xA800) /* random byte per column */ |
|
|
|
|
|
#define DATA_LOW 0x6000 /* the program must end below this */ |
|
|
#define FIRE_T ((unsigned char *)0x9800) /* burnt-tree bits, 1 per column (512 bytes) */ |
|
|
#define FIRE_T ((unsigned char *)0x9800) /* burnt-tree bits, 1 per column (512 bytes) */ |
|
|
|
|
|
|
|
|
|
|
|
/* Bases: 8 columns every 256, laid out as |
|
|
|
|
|
0 grass | 1 water tower | 2 grass | 3-6 helipad (H on 4-5) | 7 grass. |
|
|
|
|
|
BASE0 puts the first pad under the chopper's starting spot. */ |
|
|
|
|
|
#define BASE0 1013 |
|
|
|
|
|
#define BASE_W 8 |
|
|
|
|
|
#define BASE_OFF(c) ((unsigned char)((c) - BASE0)) /* 0..255 within each base period */ |
|
|
|
|
|
|
|
|
#define CL_ROW 0 |
|
|
#define CL_ROW 0 |
|
|
#define CL_ROWS 5 |
|
|
#define CL_ROWS 5 |
|
|
#define MT_ROW 5 |
|
|
#define MT_ROW 5 |
|
|
@@ -176,16 +185,29 @@ static void build_ridge(unsigned char *map, unsigned char base, |
|
|
|
|
|
|
|
|
static void build_world(void) |
|
|
static void build_world(void) |
|
|
{ |
|
|
{ |
|
|
unsigned char hi = 0, lo, x, *p = RND_T; |
|
|
|
|
|
|
|
|
unsigned char hi = 0, lo, *p = RND_T; |
|
|
|
|
|
unsigned b, c, x; |
|
|
|
|
|
|
|
|
rnd_init(); |
|
|
rnd_init(); |
|
|
do { /* RND_T[c] = rnd[lo ^ rnd[hi]] */ |
|
|
do { /* RND_T[c] = rnd[lo ^ rnd[hi]] */ |
|
|
x = rnd[hi * 16 + 7]; |
|
|
x = rnd[hi * 16 + 7]; |
|
|
lo = 0; |
|
|
lo = 0; |
|
|
do { *p++ = rnd[lo ^ x]; } while (++lo); |
|
|
|
|
|
|
|
|
do { *p++ = rnd[lo ^ (unsigned char)x]; } while (++lo); |
|
|
} while (++hi < WORLD_COLS / 256); |
|
|
} while (++hi < WORLD_COLS / 256); |
|
|
build_ridge(MT_H, 2, 0x3C, mtn_peaks); |
|
|
build_ridge(MT_H, 2, 0x3C, mtn_peaks); |
|
|
build_ridge(HL_H, 0, 0x77, hill_peaks); |
|
|
build_ridge(HL_H, 0, 0x77, hill_peaks); |
|
|
|
|
|
|
|
|
|
|
|
/* flat ground at every base, with the hills easing down to it */ |
|
|
|
|
|
for (b = 0; b < WORLD_COLS / 256; ++b) { |
|
|
|
|
|
c = (BASE0 + b * 256) & WORLD_MASK; |
|
|
|
|
|
for (lo = 0; lo < BASE_W; ++lo) HL_H[(c + lo) & WORLD_MASK] = 0; |
|
|
|
|
|
for (lo = 1; lo <= 3; ++lo) { |
|
|
|
|
|
x = (c - lo) & WORLD_MASK; |
|
|
|
|
|
if (HL_H[x] > lo) HL_H[x] = lo; |
|
|
|
|
|
x = (c + BASE_W - 1 + lo) & WORLD_MASK; |
|
|
|
|
|
if (HL_H[x] > lo) HL_H[x] = lo; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* 0 flat/valley, 1 rising "/", 2 falling "\", 3 peak */ |
|
|
/* 0 flat/valley, 1 rising "/", 2 falling "\", 3 peak */ |
|
|
@@ -248,17 +270,26 @@ static const unsigned char bit8[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; |
|
|
(and none on a hill). */ |
|
|
(and none on a hill). */ |
|
|
static unsigned char tree_at(unsigned c) |
|
|
static unsigned char tree_at(unsigned c) |
|
|
{ |
|
|
{ |
|
|
return HL_H[c] ? 7 : (RND_T[c ^ 0x5A5] >> 3) & 7; |
|
|
|
|
|
|
|
|
return HL_H[c] || BASE_OFF(c) < BASE_W ? 7 : (RND_T[c ^ 0x5A5] >> 3) & 7; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static const unsigned char pad_tiles[4] = { T_PAD, T_PAD_H1, T_PAD_H2, T_PAD }; |
|
|
|
|
|
|
|
|
static void gen_hills(unsigned c) |
|
|
static void gen_hills(unsigned c) |
|
|
{ |
|
|
{ |
|
|
unsigned char h = HL_H[c], r = RND_T[c ^ 0x5A5]; |
|
|
|
|
|
|
|
|
unsigned char h = HL_H[c], r = RND_T[c ^ 0x5A5], r2; |
|
|
|
|
|
|
|
|
memset(colbuf, BLANK, HL_ROWS); |
|
|
memset(colbuf, BLANK, HL_ROWS); |
|
|
colbuf[6] = (r & 1) ? T_GRASS1 : T_GRASS2; |
|
|
colbuf[6] = (r & 1) ? T_GRASS1 : T_GRASS2; |
|
|
colbuf[7] = (r & 2) ? T_DIRT1 : T_DIRT2; |
|
|
colbuf[7] = (r & 2) ? T_DIRT1 : T_DIRT2; |
|
|
if (h) { |
|
|
|
|
|
|
|
|
r2 = BASE_OFF(c); |
|
|
|
|
|
if (r2 < BASE_W) { /* a base */ |
|
|
|
|
|
if (r2 == 1) { |
|
|
|
|
|
colbuf[3] = T_TANK_TOP; colbuf[4] = T_TANK_MID; colbuf[5] = T_TANK_LEGS; |
|
|
|
|
|
} else if (r2 >= 3 && r2 <= 6) { |
|
|
|
|
|
colbuf[6] = pad_tiles[r2 - 3]; |
|
|
|
|
|
} |
|
|
|
|
|
} else if (h) { |
|
|
colbuf[6 - h] = hill_top[top_shape(HL_H[(c - 1) & WORLD_MASK], h, HL_H[(c + 1) & WORLD_MASK])]; |
|
|
colbuf[6 - h] = hill_top[top_shape(HL_H[(c - 1) & WORLD_MASK], h, HL_H[(c + 1) & WORLD_MASK])]; |
|
|
memset(colbuf + 7 - h, T_H_SOLID, h - 1); |
|
|
memset(colbuf + 7 - h, T_H_SOLID, h - 1); |
|
|
} else { |
|
|
} else { |
|
|
@@ -511,6 +542,8 @@ static void set_heli_sprites(unsigned char frame) |
|
|
|
|
|
|
|
|
static unsigned char ri, rj; |
|
|
static unsigned char ri, rj; |
|
|
static unsigned char spawn_t = 90; |
|
|
static unsigned char spawn_t = 90; |
|
|
|
|
|
#define SPAWN_GAP 70 /* frames between enemies: SPAWN_GAP + 0..63 */ |
|
|
|
|
|
#define MAX_ENEMIES 4 /* birds, balloons and jets on screen at once */ |
|
|
static unsigned spawned; /* statistics for the test */ |
|
|
static unsigned spawned; /* statistics for the test */ |
|
|
static unsigned char peak_v; /* most hazards on screen at once */ |
|
|
static unsigned char peak_v; /* most hazards on screen at once */ |
|
|
static unsigned mux_frames; /* frames that needed more than 5 sprites */ |
|
|
static unsigned mux_frames; /* frames that needed more than 5 sprites */ |
|
|
@@ -555,7 +588,10 @@ static void spawn_hazards(void) |
|
|
|
|
|
|
|
|
if (--spawn_t) return; |
|
|
if (--spawn_t) return; |
|
|
r = rand8(); |
|
|
r = rand8(); |
|
|
spawn_t = 30 + (r & 63); |
|
|
|
|
|
|
|
|
spawn_t = SPAWN_GAP + (r & 63); |
|
|
|
|
|
for (i = n = 0; i < MAXH; ++i) /* enemies already up */ |
|
|
|
|
|
if (hz_type[i] && hz_type[i] <= HZ_JET) ++n; |
|
|
|
|
|
if (n >= MAX_ENEMIES) return; |
|
|
side = vx > 6 ? 1 : vx < -6 ? 0 : (r >> 7); /* 1 = right edge */ |
|
|
side = vx > 6 ? 1 : vx < -6 ? 0 : (r >> 7); /* 1 = right edge */ |
|
|
y = 64 + (rand8() & 127); |
|
|
y = 64 + (rand8() & 127); |
|
|
if (y > 180) y -= 60; |
|
|
if (y > 180) y -= 60; |
|
|
@@ -563,6 +599,7 @@ static void spawn_hazards(void) |
|
|
|
|
|
|
|
|
switch (r & 7) { |
|
|
switch (r & 7) { |
|
|
case 0: case 1: case 2: /* a flock of three birds */ |
|
|
case 0: case 1: case 2: /* a flock of three birds */ |
|
|
|
|
|
if (n + 3 > MAX_ENEMIES) return; |
|
|
for (n = 0; n < 3; ++n) { |
|
|
for (n = 0; n < 3; ++n) { |
|
|
if ((i = free_slot()) == 255) return; |
|
|
if ((i = free_slot()) == 255) return; |
|
|
place(i, HZ_BIRD, |
|
|
place(i, HZ_BIRD, |
|
|
@@ -602,6 +639,19 @@ static void sound_boom(void) |
|
|
SID.v1.ctrl = 0x81; /* noise, gate on */ |
|
|
SID.v1.ctrl = 0x81; /* noise, gate on */ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* World column under the middle of the chopper (screen column k's left edge |
|
|
|
|
|
is at sprite X 31 + 8k - (px & 7)). */ |
|
|
|
|
|
static unsigned heli_col(void) |
|
|
|
|
|
{ |
|
|
|
|
|
return LAY_COL(L_HILLS) + ((unsigned)(hx + 12 - 31 + (lay_px_lo[L_HILLS] & 7)) >> 3); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static unsigned char at_base(void) |
|
|
|
|
|
{ |
|
|
|
|
|
unsigned char o = BASE_OFF(heli_col()); |
|
|
|
|
|
return landed && o >= 3 && o <= 6; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
static unsigned char burning(unsigned c) |
|
|
static unsigned char burning(unsigned c) |
|
|
{ |
|
|
{ |
|
|
unsigned char i; |
|
|
unsigned char i; |
|
|
@@ -686,7 +736,7 @@ static void run_hazards(unsigned char stick, unsigned char frame) |
|
|
/* water: fire button while flying; the tank refills on the ground */ |
|
|
/* water: fire button while flying; the tank refills on the ground */ |
|
|
spraying = (stick & JOY_FIRE) && !landed && water && !boom_t && !game_over; |
|
|
spraying = (stick & JOY_FIRE) && !landed && water && !boom_t && !game_over; |
|
|
if (spraying && (frame & 1)) --water; |
|
|
if (spraying && (frame & 1)) --water; |
|
|
if (landed && water < WATER_MAX && (frame & 1)) ++water; |
|
|
|
|
|
|
|
|
if (water < WATER_MAX && at_base()) ++water; /* refill on a helipad */ |
|
|
spray_sound(spraying); |
|
|
spray_sound(spraying); |
|
|
spray_on = spraying; |
|
|
spray_on = spraying; |
|
|
spray_xlo = (unsigned char)hx; |
|
|
spray_xlo = (unsigned char)hx; |
|
|
@@ -805,11 +855,12 @@ static void draw_hud_frame(void) |
|
|
#pragma charmap (0x79, 0x19) |
|
|
#pragma charmap (0x79, 0x19) |
|
|
#pragma charmap (0x7A, 0x1A) |
|
|
#pragma charmap (0x7A, 0x1A) |
|
|
#define MSG_LEN 36 |
|
|
#define MSG_LEN 36 |
|
|
static const char msg[4][MSG_LEN + 1] = { |
|
|
|
|
|
|
|
|
static const char msg[5][MSG_LEN + 1] = { |
|
|
"demo - press fire or move the stick ", |
|
|
"demo - press fire or move the stick ", |
|
|
"landed - tank refills - up: take off", |
|
|
|
|
|
"fires out 00 trees lost 00 ", |
|
|
|
|
|
|
|
|
"landed - no water here, find a base ", |
|
|
|
|
|
"fires out 00 burnt 00 base > 000 ", |
|
|
"game over - press fire to fly again ", |
|
|
"game over - press fire to fly again ", |
|
|
|
|
|
"base - filling the tank - up to fly ", |
|
|
}; |
|
|
}; |
|
|
/* back to cc65's normal PETSCII mapping for the rest of the file */ |
|
|
/* back to cc65's normal PETSCII mapping for the rest of the file */ |
|
|
#pragma charmap (0x61, 0x41) |
|
|
#pragma charmap (0x61, 0x41) |
|
|
@@ -844,6 +895,7 @@ static void update_hud(unsigned char part) |
|
|
static unsigned char shown = 255; |
|
|
static unsigned char shown = 255; |
|
|
static unsigned char shown_out = 255, shown_lost = 255; |
|
|
static unsigned char shown_out = 255, shown_lost = 255; |
|
|
unsigned char mode; |
|
|
unsigned char mode; |
|
|
|
|
|
signed char d; |
|
|
|
|
|
|
|
|
switch (part & 3) { /* one field per frame keeps frames even */ |
|
|
switch (part & 3) { /* one field per frame keeps frames even */ |
|
|
case 0: put_num(HUD1 + 7, (vx < 0 ? -vx : vx) * 3, 2); break; /* 0..96 */ |
|
|
case 0: put_num(HUD1 + 7, (vx < 0 ? -vx : vx) * 3, 2); break; /* 0..96 */ |
|
|
@@ -851,7 +903,7 @@ static void update_hud(unsigned char part) |
|
|
case 2: put_num(HUD1 + 26, water, 2); break; |
|
|
case 2: put_num(HUD1 + 26, water, 2); break; |
|
|
case 3: |
|
|
case 3: |
|
|
HUD1[36] = '0' + lives; |
|
|
HUD1[36] = '0' + lives; |
|
|
mode = demo ? 0 : game_over ? 3 : landed ? 1 : 2; |
|
|
|
|
|
|
|
|
mode = demo ? 0 : game_over ? 3 : !landed ? 2 : at_base() ? 4 : 1; |
|
|
if (mode != shown) { |
|
|
if (mode != shown) { |
|
|
shown = mode; |
|
|
shown = mode; |
|
|
shown_out = shown_lost = 255; |
|
|
shown_out = shown_lost = 255; |
|
|
@@ -859,7 +911,12 @@ static void update_hud(unsigned char part) |
|
|
} |
|
|
} |
|
|
if (mode == 2) { |
|
|
if (mode == 2) { |
|
|
if (fires_out != shown_out) put_num(HUD2 + 12, shown_out = fires_out, 2); |
|
|
if (fires_out != shown_out) put_num(HUD2 + 12, shown_out = fires_out, 2); |
|
|
else if (trees_lost != shown_lost) put_num(HUD2 + 28, shown_lost = trees_lost, 2); |
|
|
|
|
|
|
|
|
else if (trees_lost != shown_lost) put_num(HUD2 + 22, shown_lost = trees_lost, 2); |
|
|
|
|
|
else { /* nearest base: direction and columns */ |
|
|
|
|
|
d = (signed char)(4 - BASE_OFF(heli_col())); |
|
|
|
|
|
HUD2[31] = d > 0 ? '>' : d < 0 ? '<' : '*'; |
|
|
|
|
|
put_num(HUD2 + 33, d < 0 ? -d : d, 3); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@@ -872,7 +929,7 @@ static void setup_screen(void) |
|
|
__asm__("sei"); |
|
|
__asm__("sei"); |
|
|
*(unsigned char *)1 = 0x33; /* character ROM at $D000 */ |
|
|
*(unsigned char *)1 = 0x33; /* character ROM at $D000 */ |
|
|
memcpy(CHARSET, (void *)0xD000, 0x800); |
|
|
memcpy(CHARSET, (void *)0xD000, 0x800); |
|
|
*(unsigned char *)1 = 0x37; |
|
|
|
|
|
|
|
|
*(unsigned char *)1 = 0x36; /* back to: BASIC ROM out */ |
|
|
__asm__("cli"); |
|
|
__asm__("cli"); |
|
|
memcpy(CHARSET + FIRST_TILE * 8, tile_data, NUM_TILES * 8); |
|
|
memcpy(CHARSET + FIRST_TILE * 8, tile_data, NUM_TILES * 8); |
|
|
memcpy(SPRMEM, sprite_data, NUM_SPRITES * 64); |
|
|
memcpy(SPRMEM, sprite_data, NUM_SPRITES * 64); |
|
|
@@ -928,7 +985,7 @@ static void self_test(void) |
|
|
{ |
|
|
{ |
|
|
unsigned c; |
|
|
unsigned c; |
|
|
|
|
|
|
|
|
/* the world tables at $5000-$7FFF must sit above the program's BSS */ |
|
|
|
|
|
|
|
|
/* the world tables at $6000-$7FFF must sit above the program's BSS */ |
|
|
c64test_check((unsigned)_BSS_RUN__ + (unsigned)_BSS_SIZE__ <= DATA_LOW, 1); |
|
|
c64test_check((unsigned)_BSS_RUN__ + (unsigned)_BSS_SIZE__ <= DATA_LOW, 1); |
|
|
|
|
|
|
|
|
/* sub-pixel stepping and coarse-scroll detection (layer 0 as a scratch layer) */ |
|
|
/* sub-pixel stepping and coarse-scroll detection (layer 0 as a scratch layer) */ |
|
|
@@ -1007,6 +1064,16 @@ static void self_test(void) |
|
|
spray_on = 0; |
|
|
spray_on = 0; |
|
|
spawned = 0; |
|
|
spawned = 0; |
|
|
|
|
|
|
|
|
|
|
|
/* bases: flat, a tower and a pad, no trees */ |
|
|
|
|
|
for (c = 0; c < BASE_W; ++c) { |
|
|
|
|
|
c64test_check(HL_H[(BASE0 + 256 + c) & WORLD_MASK] == 0, 30); |
|
|
|
|
|
c64test_check(tree_at((BASE0 + 512 + c) & WORLD_MASK) > 2, 31); |
|
|
|
|
|
} |
|
|
|
|
|
gen_hills(BASE0 + 1); |
|
|
|
|
|
c64test_check(colbuf[3] == T_TANK_TOP && colbuf[5] == T_TANK_LEGS, 32); |
|
|
|
|
|
gen_hills(BASE0 + 4); |
|
|
|
|
|
c64test_check(colbuf[6] == T_PAD_H1 && colbuf[0] == BLANK, 33); |
|
|
|
|
|
|
|
|
/* number formatting */ |
|
|
/* number formatting */ |
|
|
to_dec(8190); |
|
|
to_dec(8190); |
|
|
c64test_check(memcmp(decbuf, "\x30\x38\x31\x39\x30", 5) == 0, 10); |
|
|
c64test_check(memcmp(decbuf, "\x30\x38\x31\x39\x30", 5) == 0, 10); |
|
|
@@ -1029,10 +1096,12 @@ int main(void) |
|
|
{ |
|
|
{ |
|
|
unsigned char last, frame = 0, stick, raw, fire_was = 0, hud_part = 0; |
|
|
unsigned char last, frame = 0, stick, raw, fire_was = 0, hud_part = 0; |
|
|
|
|
|
|
|
|
|
|
|
*(unsigned char *)1 = 0x36; /* BASIC ROM out: RND_T lives at $A800 */ |
|
|
build_world(); |
|
|
build_world(); |
|
|
self_test(); |
|
|
self_test(); |
|
|
BLNSW = 1; |
|
|
BLNSW = 1; |
|
|
setup_screen(); |
|
|
setup_screen(); |
|
|
|
|
|
c64test_check(at_base(), 34); /* the game starts on a helipad */ |
|
|
irq_init(); |
|
|
irq_init(); |
|
|
last = irq_frame; |
|
|
last = irq_frame; |
|
|
|
|
|
|
|
|
|