aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Armstrong <jeff@approximatrix.com>2020-03-29 11:17:39 -0500
committerJeffrey Armstrong <jeff@approximatrix.com>2020-03-29 11:17:39 -0500
commit4e1571bda9c6a85db4bd7a43f3044d855b091ec3 (patch)
treea87feec94ae2f0dcc47bd5ae888fcf306acf86a1
parentbc3676fd53cff5bc0ff131ba887061703ebde192 (diff)
downloadgemworm-4e1571bda9c6a85db4bd7a43f3044d855b091ec3.zip
gemworm-4e1571bda9c6a85db4bd7a43f3044d855b091ec3.tar.gz
Initial work on support for high scores. Transitioned project to modern AHCC and fixed tons of warnings. PC-GEM probably broken at the moment.
-rw-r--r--field.c1
-rw-r--r--makefile.gnu9
-rw-r--r--player.c2
-rw-r--r--readme.txt26
-rw-r--r--scores.c123
-rw-r--r--scores.h5
-rw-r--r--util.h14
-rw-r--r--worm.c48
-rw-r--r--worm.prj11
-rw-r--r--wormst.h22
-rw-r--r--wormst.hrdbin100 -> 320 bytes
-rw-r--r--wormst.rscbin1312 -> 2210 bytes
12 files changed, 235 insertions, 26 deletions
diff --git a/field.c b/field.c
index dca27ab..287aa95 100644
--- a/field.c
+++ b/field.c
@@ -19,6 +19,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
#ifdef __GNUC__
diff --git a/makefile.gnu b/makefile.gnu
index c80d582..6176c5d 100644
--- a/makefile.gnu
+++ b/makefile.gnu
@@ -13,9 +13,12 @@ player.o: player.c player.h field.h
field.o: field.c player.h field.h
$(CC) $(CFLAGS) -c field.c
-worm.o: worm.c player.h field.h keybd.h
+scores.o: scores.c scores.h
+ $(CC) $(CFLAGS) -c scores.c
+
+worm.o: worm.c player.h field.h keybd.h scores.h
$(CC) $(CFLAGS) -c worm.c
-all: worm.o player.h field.h keybd.h wormst.h player.o field.o
- $(CC) $(CFLAGS) -o $(TARGET) worm.o player.o field.o $(CLIBS)
+all: worm.o player.h field.h keybd.h wormst.h player.o field.o scores.o
+ $(CC) $(CFLAGS) -o $(TARGET) worm.o player.o field.o scores.o $(CLIBS)
\ No newline at end of file
diff --git a/player.c b/player.c
index 6432fcc..eedc727 100644
--- a/player.c
+++ b/player.c
@@ -19,6 +19,8 @@
*/
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
#include "player.h"
#include "field.h"
diff --git a/readme.txt b/readme.txt
index 5d573af..62cf0e7 100644
--- a/readme.txt
+++ b/readme.txt
@@ -38,20 +38,22 @@ If you have downloaded the source code, the game can be easily compiled
for either the PC or Atari.
- PC -
-
- The program has been designed to compile using Turbo C 2 from
- Borland. To compile with GEM bindings, you'll need to install
- the GEM Programmer's Toolkit first. A makefile is included to
- build the game.
-
+
+ The program has been designed to compile using Turbo C 2 from
+ Borland. To compile with GEM bindings, you'll need to install
+ the GEM Programmer's Toolkit first. A makefile is included to
+ build the game.
+
- Atari -
-
- The program is also designed to compile with Pure C from Pure
- Software or AHCC from whoever is maintaining that nowadays. The
- appropriate project file (worm.prj) is included.
+
+ The program is also designed to compile with AHCC from whoever
+ is maintaining that nowadays. The project used to be built with
+ Pure C, but the project file is now strictly AHCC (you could
+ make a Pure C project file, though). The appropriate AHCC
+ project file (worm.prj) is included.
- Recently, a GNU makefile (makefile.gnu) was added for use with
- GCC on an actual Atari.
+ Recently, a GNU makefile (makefile.gnu) was added for use with
+ GCC on an actual Atari.
Legalese
========
diff --git a/scores.c b/scores.c
new file mode 100644
index 0000000..117f2da
--- /dev/null
+++ b/scores.c
@@ -0,0 +1,123 @@
+#include <stdio.h>
+
+#ifdef __GNUC__
+
+#include <gem.h>
+
+#define HIWORD(x) ((int16_t)((uint32_t)x >> 16))
+#define LOWORD(x) ((int16_t)((uint32_t)x & 0xFFFF))
+
+#else
+
+#include <portab.h>
+#include <aes.h>
+#include <vdi.h>
+
+#endif /* __GNUC__ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef PCGEM
+#include "wormpc.h"
+#else
+#include "wormst.h"
+#endif
+
+#define SCOREFILE "worm.hi"
+
+struct score {
+ char initials[3];
+ int score;
+};
+
+char *defaults[10] = {
+ "JBA",
+ "GEM",
+ "TOS",
+ "DOS",
+ "68K",
+ "X86",
+ "AES",
+ "VDI",
+ "WRM",
+ "MGX" };
+
+static struct score scores[10];
+
+char *get_hi_score_filepath(const char *fullpath)
+{
+char *scorepath;
+char *tmp;
+size_t fpl;
+
+ if(fullpath != NULL)
+ fpl = strlen(fullpath) + strlen(SCOREFILE); /* fine... */
+ else
+ fpl = strlen(SCOREFILE);
+ scorepath = (char *)malloc(fpl);
+
+ if(fullpath != NULL) {
+ strcpy(scorepath, fullpath);
+ tmp = strrchr(scorepath, '\\');
+ if(tmp == NULL)
+ tmp = strrchr(scorepath, '/');
+ if(tmp == NULL)
+ tmp = scorepath;
+ else
+ tmp++;
+ tmp[0] = '\0';
+
+ } else
+ scorepath[0] = '\0';
+
+ strcat(scorepath, SCOREFILE);
+
+ return scorepath;
+}
+
+void load_scores(const char *fullpath)
+{
+char *filename;
+FILE *fp;
+int i;
+char scorebuf[8];
+
+ filename = get_hi_score_filepath(fullpath);
+ fp = fopen(filename, "r");
+ if(fp != NULL) {
+ for(i=0;i<10;i++) {
+ memset(scorebuf, 0, 8);
+ fread(scores[i].initials, 1, 3, fp);
+ fgets(scorebuf, 8, fp);
+ scores[i].score = atoi(scorebuf);
+ }
+ fclose(fp);
+ } else {
+ for(i=0;i<10;i++) {
+ memcpy(scores[i].initials, defaults[9-i], 3);
+ scores[i].score = i == 0 ? 10 : (i * 100 + 100);
+ }
+ }
+ free(filename);
+}
+
+void save_scores(const char *fullpath)
+{
+char *filename;
+FILE *fp;
+int i;
+
+ filename = get_hi_score_filepath(fullpath);
+ fp = fopen(filename, "w");
+ if(fp == NULL) return;
+ for(i=0;i<10;i++) {
+ fwrite(scores[i].initials, 1, 3, fp);
+ fprintf(fp, " %6d\n", scores[i].score);
+ }
+ fclose(fp);
+ free(filename);
+}
+
+
diff --git a/scores.h b/scores.h
new file mode 100644
index 0000000..64540b7
--- /dev/null
+++ b/scores.h
@@ -0,0 +1,5 @@
+#ifndef SCORES_HEADERS
+#define SCORES_HEADERS
+
+
+#endif /* SCORES_HEADERS */
diff --git a/util.h b/util.h
index db82c04..ef2f749 100644
--- a/util.h
+++ b/util.h
@@ -3,6 +3,8 @@
/* Mostly compatability stuff */
+#include <string.h>
+
#ifdef __GNUC__
#include <gem.h>
@@ -19,16 +21,12 @@
#endif /* __GNUC__ */
#ifndef WF_WXYWH
-#ifdef WF_WORKXYWH
#define WF_WXYWH WF_WORKXYWH
#endif
-#endif
#ifndef WF_CXYWH
-#ifdef WF_CURRXYWH
#define WF_CXYWH WF_CURRXYWH
#endif
-#endif
#define max(x,y) x>y ? x : y
#define min(x,y) x<y ? x : y
@@ -50,5 +48,13 @@ WORD tx,ty,tw,th;
}
#endif
+static void set_resource_string(OBJECT *tree, short obj, const char *string)
+{
+long addr;
+
+ /* What a freakin' nightmare... */
+ addr = tree[obj].ob_spec.index;
+ strcpy((char *)addr, string);
+}
#endif /* UTIL_WORM_HEADERS */
diff --git a/worm.c b/worm.c
index 3616d02..99a356b 100644
--- a/worm.c
+++ b/worm.c
@@ -19,7 +19,9 @@
*/
#include <stdio.h>
-/*#include <stdlib.h>*/
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
#ifdef __GNUC__
@@ -74,6 +76,7 @@ GRECT app_wdw; /* xywh of working area */
OBJECT FAR *app_menu;
OBJECT FAR *about_box;
+OBJECT FAR *scores_box;
#ifdef PCGEM
#define RCS_FILE "wormpc.rsc"
@@ -100,6 +103,29 @@ GRECT box,origin;
return;
}
+short score_positions[] = {THI1, THI2, THI3, THI4, THI5, THI6, THI7, THI8, THI9, THI10};
+
+void hndl_scores()
+{
+GRECT box,origin;
+int i;
+
+ /* ob_xywh(app_menu, MDESK, &origin); */
+
+ form_center(scores_box, &box.g_x, &box.g_y, &box.g_w, &box.g_h);
+ objc_draw(scores_box,0,2,box.g_x, box.g_y, box.g_w, box.g_h);
+
+ for(i=0;i<10;i++) {
+ set_resource_string(scores_box, score_positions[i], "Jeff");
+ }
+
+ form_do(scores_box,0);
+ form_dial(FMD_FINISH,0,0,0,0,box.g_x, box.g_y, box.g_w, box.g_h);
+
+ return;
+
+}
+
int open_window(int new)
{
graf_mouse(M_OFF,NULL);
@@ -173,6 +199,7 @@ WORD txtwidth,txtheight;
wind_update(END_UPDATE);
rsrc_gaddr(R_TREE,ABOUT,&about_box);
+ rsrc_gaddr(R_TREE,HISCORES,&scores_box);
/* Make the application name nicer on Atari GEM */
#ifndef PCGEM
@@ -423,6 +450,8 @@ EVMULT_OUT evout;
/* Set up the "field" rectangle */
memcpy(&field, &app_wdw, sizeof(GRECT));
window_to_field_rect(&field);
+
+ menu_ienable(app_menu, MPAUSE, 0);
msg[0] = AC_OPEN;
msg[4] = app_accid;
@@ -458,6 +487,8 @@ EVMULT_OUT evout;
hndl_keys(key, player, &playing);
if(last_playing != playing) {
force_redraw_score(player, playing);
+ menu_text(app_menu, MPAUSE, playing == 1 ? " Pause Game" :" Resume Game");
+ menu_ienable(app_menu, MPAUSE, 1);
}
}
@@ -490,6 +521,7 @@ EVMULT_OUT evout;
form_alert(1,"[3][You've Died!|Good try, though...][Reset]");
reset_player(player);
playing = 0;
+ menu_ienable(app_menu, MPAUSE, 0);
}
}
@@ -558,6 +590,20 @@ EVMULT_OUT evout;
force_redraw_score(player, playing);
update_field(player);
draw_field(app_vh, &field, NULL);
+ menu_ienable(app_menu, MPAUSE, 1);
+ break;
+ case MPAUSE:
+ if(playing == 1) {
+ playing = 0;
+ menu_text(app_menu, MPAUSE, " Resume Game");
+ } else {
+ playing = 1;
+ menu_text(app_menu, MPAUSE, " Pause Game");
+ }
+ force_redraw_score(player, playing);
+ break;
+ case MSCORES:
+ hndl_scores();
break;
case MABOUT:
hndl_about();
diff --git a/worm.prj b/worm.prj
index 78d1fbd..5021e00 100644
--- a/worm.prj
+++ b/worm.prj
@@ -4,13 +4,14 @@ worm.prg
.S [] ; -Y]
.L [-S=16384]
=
-PCSTART.O
+AHCSTART.O
;
field.c (field.h, player.h)
player.c (field.h, player.h)
-worm.c (field.h, player.h, wormst.h)
+scores.c (scores.h)
+worm.c (field.h, player.h, scores.h, wormst.h)
;
-PCSTDLIB.LIB
-PCTOSLIB.LIB
-PCGEMLIB.LIB
+AHCCSTD.LIB
+AHCCTOS.LIB
+AHCCGEM.LIB
diff --git a/wormst.h b/wormst.h
index 43793e0..aa95918 100644
--- a/wormst.h
+++ b/wormst.h
@@ -4,7 +4,27 @@
#define MDESK 3 /* TITLE in tree RCMENU */
#define MABOUT 7 /* STRING in tree RCMENU */
#define MNEW 16 /* STRING in tree RCMENU */
-#define MQUIT 17 /* STRING in tree RCMENU */
+#define MPAUSE 17 /* STRING in tree RCMENU */
+#define MSCORES 19 /* STRING in tree RCMENU */
+#define MQUIT 20 /* STRING in tree RCMENU */
#define ABOUT 1 /* Form/Dialog-box */
#define BEXIT 11 /* BUTTON in tree ABOUT */
+
+#define NEWSCORE 2 /* Form/Dialog-box */
+#define TINITIALS 3 /* FBOXTEXT in tree NEWSCORE */
+#define BCANCEL 4 /* BUTTON in tree NEWSCORE */
+#define BOK 5 /* BUTTON in tree NEWSCORE */
+
+#define HISCORES 3 /* Form/Dialog-box */
+#define THI1 2 /* STRING in tree HISCORES */
+#define THI2 3 /* STRING in tree HISCORES */
+#define THI3 4 /* STRING in tree HISCORES */
+#define THI4 5 /* STRING in tree HISCORES */
+#define THI5 6 /* STRING in tree HISCORES */
+#define THI6 7 /* STRING in tree HISCORES */
+#define THI7 8 /* STRING in tree HISCORES */
+#define THI8 9 /* STRING in tree HISCORES */
+#define THI9 10 /* STRING in tree HISCORES */
+#define THI10 11 /* STRING in tree HISCORES */
+#define BHIOK 12 /* BUTTON in tree HISCORES */
diff --git a/wormst.hrd b/wormst.hrd
index 503891c..50bd66b 100644
--- a/wormst.hrd
+++ b/wormst.hrd
Binary files differ
diff --git a/wormst.rsc b/wormst.rsc
index e4a7190..9bfb313 100644
--- a/wormst.rsc
+++ b/wormst.rsc
Binary files differ