Skip to content

Commit 9eb8f72

Browse files
committed
Finished doc'ing functions & routines...
... with source code comments
1 parent b1e6ef6 commit 9eb8f72

File tree

15 files changed

+147
-42
lines changed

15 files changed

+147
-42
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ http://www.newbreedsoftware.com/firefighter/
99
them if using one joystick (where you cannot walk while spraying).
1010
(h/t phigan & JLsoft on AtariAge forums for reporting)
1111
* Stick setting & latest level saved as config file on disk (ATR) version
12+
* Finished doc'ing functions & routines with source code comments
1213

1314
0.1-beta-1 (2023-08-22):
1415
* First public beta release

src/config.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Firefighter Config File (disk version) routines
3+
24
Firefighting game for the Atari 8-bit
35
Bill Kendrick <[email protected]>
46
http://www.newbreedsoftware.com/firefighter/
@@ -14,7 +16,7 @@
1416
extern char level;
1517
extern char main_stick;
1618

17-
/* FIXME */
19+
/* (Attempt to) load config from disk */
1820
void load_config() {
1921
FILE * fi;
2022

@@ -26,7 +28,7 @@ void load_config() {
2628
}
2729
}
2830

29-
/* FIXME */
31+
/* (Attempt to) save config to disk */
3032
void save_config() {
3133
FILE * fi;
3234

src/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Firefighter Config File (disk version) routines
3+
24
Firefighting game for the Atari 8-bit
35
Bill Kendrick <[email protected]>
46
http://www.newbreedsoftware.com/firefighter/

src/dli.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Firefighter Display List Interrupt routines
3+
24
Firefighting game for the Atari 8-bit
35
Bill Kendrick <[email protected]>
46
http://www.newbreedsoftware.com/firefighter/
@@ -9,7 +11,6 @@
911
#include "dli.h"
1012

1113
extern unsigned char font1_data[];
12-
// extern unsigned char font2_data[]; /* Not actually referenced */
1314

1415
void dli(void) {
1516
asm("pha");

src/dli.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Firefighter Display List Interrupt routines
3+
24
Firefighting game for the Atari 8-bit
35
Bill Kendrick <[email protected]>
46
http://www.newbreedsoftware.com/firefighter/

src/draw_text.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Firefighter text drawing routines
3+
24
Firefighting game for the Atari 8-bit
35
Bill Kendrick <[email protected]>
46
http://www.newbreedsoftware.com/firefighter/
@@ -13,6 +15,12 @@
1315

1416
extern unsigned char scr_mem[];
1517

18+
/* Draw some text on the screen.
19+
20+
@param char * str - The NUL-terminated ('\0') string to write
21+
@unsigned char * dest - The destination in memory
22+
(expected to within src_mem[]!!!)
23+
*/
1624
void draw_text(char * str, unsigned char * dest) {
1725
unsigned char ch;
1826
unsigned int i;
@@ -30,6 +38,13 @@ void draw_text(char * str, unsigned char * dest) {
3038
}
3139
}
3240

41+
/* Draw a zero-padded decimal number on the screen.
42+
43+
@param unsigned long int n - The number to draw
44+
@param int digits - How many digits to show (will be zero-padded)
45+
@unsigned char * dest - The destination in memory
46+
(expected to within src_mem[]!!!)
47+
*/
3348
void draw_number(unsigned long int n, int digits, unsigned char * dest) {
3449
do {
3550
POKE(dest + digits - 1, (n % 10) + 16);

src/draw_text.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Firefighter text drawing routines
3+
24
Firefighting game for the Atari 8-bit
35
Bill Kendrick <[email protected]>
46
http://www.newbreedsoftware.com/firefighter/

src/firefite.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/*
2+
Firefighter core `main()` loop that calls other loops
3+
(title screen, help screen, and the game).
4+
25
Firefighting game for the Atari 8-bit
36
Bill Kendrick <[email protected]>
47
http://www.newbreedsoftware.com/firefighter/
@@ -24,27 +27,37 @@ char high_score_name[4];
2427
char main_stick;
2528
char level;
2629

30+
/* Main loop! */
2731
void main(void) {
2832
char want_help;
2933

34+
/* Set default high score */
3035
high_score = 1031;
3136
strcpy(high_score_name, "BJK");
37+
38+
/* Set default config */
3239
main_stick = STICK_LEFT;
3340
level = 1;
3441

3542
#ifdef DISK
43+
/* Load saved config from disk */
3644
load_config();
3745
#endif
3846

3947
do {
4048
do {
49+
/* Show title screen */
4150
want_help = show_title();
51+
4252
#ifdef DISK
4353
if (want_help) {
54+
/* Show help screen */
4455
show_help();
4556
}
4657
#endif
4758
} while (want_help);
59+
60+
/* Play the game! */
4861
start_game();
4962
} while(1);
5063
}

src/game.c

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Firefighter game loop and its helper functions.
3+
24
Firefighting game for the Atari 8-bit
35
Bill Kendrick <[email protected]>
46
http://www.newbreedsoftware.com/firefighter/
@@ -14,7 +16,7 @@
1416
#include "draw_text.h"
1517
#include "dli.h"
1618

17-
/* FIXME: Shove in a "score.h" header? */
19+
/* FIXME: Shove in a "score.h" header? -bjk 2023.08.22 */
1820
#define SCORE_AX_COLLECT 15
1921
#define SCORE_CIVILIAN_RESCUE 100
2022
#define SCORE_CRATE_BREAK_DEDUCTION 1
@@ -469,7 +471,13 @@ void start_game(void) {
469471
tip shape near the player, and three other shapes
470472
beyond that; we'll avoid drawing those other three
471473
if the first part failed to draw, to avoid being
472-
able to spray through solid objects! */
474+
able to spray through solid objects!i
475+
476+
@param unsigned char x - X position to [attempt to] draw
477+
@param unsigned char y - Y position to [attempt to] draw
478+
@param unsigned char want_shape - water shape to [attempt to] draw
479+
@return boolean 1 if it was drawn, 0 otherwise (e.g., obstacle, fire, etc.)
480+
*/
473481
unsigned char spray(unsigned char x, unsigned char y, unsigned char want_shape) {
474482
unsigned char shape;
475483

@@ -545,7 +553,9 @@ void setup_game_screen(void) {
545553
OS.sdmctl = (DMACTL_PLAYFIELD_NORMAL | DMACTL_DMA_FETCH);
546554
}
547555

548-
/* FIXME */
556+
/* Draw the current level, including drawing the
557+
level/score/bonus status bar at the top.
558+
Flashes a "GET READY!" message, before proceeding. */
549559
void draw_level(void) {
550560
int l;
551561

@@ -571,7 +581,7 @@ void draw_level(void) {
571581
memcpy(scr_mem + 60, levels_data + l * LEVEL_TOT_SIZE + 1, LEVEL_SPAN);
572582
}
573583

574-
/* FIXME */
584+
/* Draws the level/score/bonus in the status bar */
575585
void draw_score(void) {
576586
draw_number(level, 2, scr_mem + 28);
577587
draw_number(score, 6, scr_mem + 39);
@@ -657,6 +667,7 @@ void cellular_automata(void) {
657667
if (valid_dir(x, y, dir) &&
658668
shape_at(x + dir_x[dir], y + dir_y[dir]) == 0) {
659669
set_shape(x, y, 0);
670+
660671
if ((dir_x[dir] == 1 && dir_y[dir] >= 0) || dir_y[dir] == 1) {
661672
set_shape(x + dir_x[dir], y + dir_y[dir], CIVILIAN_MOVED);
662673
} else {
@@ -665,7 +676,12 @@ void cellular_automata(void) {
665676
}
666677
}
667678
} else if (shape == CIVILIAN_MOVED) {
668-
/* FIXME */
679+
/* Turn a previously-moved worker back into a regular worker.
680+
681+
(Since cellular automaton goes from top-to-bottom, left-to-right,
682+
we use an interim 'shape' to avoid processing the same worker
683+
multiple times per frame (causing them to 'fly' across or down
684+
the screen) if they move down or right) */
669685
set_shape(x, y, CIVILIAN);
670686
} else if (shape == PIPE_BROKEN_UP_DOWN && rand < 128) {
671687
/* Draw (or erase) gas leak on left/right of a broken vertical pipe */
@@ -682,21 +698,8 @@ void cellular_automata(void) {
682698
}
683699
}
684700

685-
/* FIXME */
686-
/*
687-
for (y = 0; y < LEVEL_H; y++) {
688-
for (x = 0; x < LEVEL_W; x++) {
689-
shape = shape_at(x, y);
690-
if (shape == CIVILIAN_MOVED) {
691-
set_shape(x, y, CIVILIAN);
692-
} else if (shape == FIRE_SM || shape == FIRE_MD || shape == FIRE_LG) {
693-
any_fire++;
694-
}
695-
}
696-
}
697-
*/
698-
699-
/* FIXME */
701+
/* Play crackling fire sound effect
702+
(the more fire, the higher the volume) */
700703
if (any_fire) {
701704
POKEY_WRITE.audf1 = ((POKEY_READ.random) >> 4) + 128;
702705
POKEY_WRITE.audc1 = (any_fire >> 4) + 1;
@@ -705,7 +708,14 @@ void cellular_automata(void) {
705708
}
706709
}
707710

708-
/* FIXME */
711+
/* Given a broken pipe at a position on the screen,
712+
[attempt to] draw a gas leak shape, or a blank,
713+
depending on the state of all valves on the screen.
714+
715+
@param int x - X position to [attempt to] draw/erase gas leak
716+
@param int y - Y position to [attempt to] draw/erase gas leak
717+
@param char shape - gas leak shape to [attempt to] draw there
718+
*/
709719
void broken_pipe(int x, int y, char shape) {
710720
char c;
711721

@@ -752,7 +762,11 @@ char pipe_corner[16] = {
752762

753763

754764
/* Create an explosion of fire at the given position
755-
(occurs when fire touches oil barrels or gas leaks) */
765+
(occurs when fire touches oil barrels or gas leaks)
766+
767+
@param char x - X position for explosion
768+
@param char y - Y position for explosion
769+
*/
756770
void explode(char x, char y) {
757771
char shape, flam;
758772

@@ -801,7 +815,13 @@ void explode(char x, char y) {
801815
}
802816

803817
/* Determines whether moving a given direction from
804-
a particular position is still in-bounds */
818+
a particular position is still in-bounds
819+
820+
@param unsigned char x - X position from which to test
821+
@param unsigned char y - Y position from which to test
822+
@param unsigned char dir - direction (0-7; see dir_x[] & dir_y[]) to test
823+
@return unsigned char boolean whether the new position is in bounds
824+
*/
805825
unsigned char valid_dir(unsigned char x, unsigned char y, unsigned char dir) {
806826
int dx, dy;
807827

@@ -814,7 +834,14 @@ unsigned char valid_dir(unsigned char x, unsigned char y, unsigned char dir) {
814834
};
815835

816836
/* Return the flammability of an object; used to determine
817-
how (and if) fire spreads */
837+
how (and if) fire spreads
838+
839+
@param unsigned char c - Object shape to test for flammability
840+
@param unsigned char - Fire shape to draw on the screen
841+
(FIRE_SM, FIRE_MD, or FIRE_LG),
842+
or FIRE_INFLAM if the shape is not flammable (don't spread fire),
843+
or FIRE_XLG if the shape is explosive
844+
*/
818845
unsigned char flammable(unsigned char c) {
819846
if (c == OIL || c == GASLEAK_RIGHT || c == GASLEAK_LEFT || c == GASLEAK_UP || c == GASLEAK_DOWN) {
820847
/* Oil barrel and gas leaks cause an explosion */
@@ -841,7 +868,16 @@ unsigned char flammable(unsigned char c) {
841868
}
842869
}
843870

844-
/* FIXME */
871+
/* Set sound parameters
872+
@param char p - Starting pitch (0-255)
873+
@param char pch - Pitch delta
874+
(negative for higher, positive for lower, zero for no change)
875+
@param char dist - Distortion (as high nybble)
876+
(e.g., (10<<4) aka 160 aka 0xA0 for 'pure' tone (square wave)
877+
@param char vol - Starting volume (0-15)
878+
@param char volch - Volume change; how fast to decrease volume
879+
(note: always _positive_)
880+
*/
845881
void set_sound(char p, char pch, char dist, char vol, char volch) {
846882
hit_pitch = p;
847883
hit_pitch_change = pch;
@@ -850,7 +886,11 @@ void set_sound(char p, char pch, char dist, char vol, char volch) {
850886
hit_vol_decrease = volch;
851887
}
852888

853-
/* FIXME */
889+
/* End-of-level bonus sequence:
890+
+ Show "Level Complete!"
891+
+ Show and tally Time Bonus
892+
+ Show and tally Safety Bonus
893+
*/
854894
void level_end_bonus(void) {
855895
int i;
856896
char c, any_fire;
@@ -908,7 +948,7 @@ void level_end_bonus(void) {
908948
}
909949
}
910950

911-
/* FIXME */
951+
/* Briefly flash the background color (of the entire screen) */
912952
void flash(void) {
913953
char i, j;
914954

@@ -924,6 +964,7 @@ void flash(void) {
924964
}
925965
}
926966

967+
/* Pause for a few seconds */
927968
void pause(void) {
928969
int i;
929970

@@ -932,7 +973,10 @@ void pause(void) {
932973
}
933974
}
934975

935-
/* FIXME */
976+
/* Bonus score tally sequence (used by end-of-level bonus sequence)
977+
@param int x - X position to draw bonus score for countdown
978+
@param int deduct - How quickly to deduct points from bonus during tally
979+
*/
936980
void bonus_tally(int x, int deduct) {
937981
while (bonus >= deduct) {
938982
bonus = bonus - deduct;
@@ -966,4 +1010,3 @@ void quiet(void) {
9661010
POKEY_WRITE.audf4 = 0;
9671011
POKEY_WRITE.audc4 = 0;
9681012
}
969-

src/game.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/*
2+
Firefighter game loop and its helper functions.
3+
24
Firefighting game for the Atari 8-bit
35
Bill Kendrick <[email protected]>
46
http://www.newbreedsoftware.com/firefighter/

0 commit comments

Comments
 (0)