From 5df204093f03477ebe6879637fa5703aa6802137 Mon Sep 17 00:00:00 2001 From: Ander D'nar Date: Tue, 2 Jul 2019 19:37:27 -0400 Subject: [PATCH] Fix #12 and #13 Plus clean up code a bit --- Makefile | 3 +-- README.adoc | 2 +- actions.h | 2 +- actions1.c | 11 +++++++++++ actions2.c | 11 +++++++++++ actions3.c | 11 +++++++++++ actions4.c | 11 +++++++++++ actions5.c | 11 +++++++++++ calc.c | 9 ++++++++- calculator.adoc | 2 ++ misc.c | 20 +------------------- saveresume.c | 11 ++++++----- 12 files changed, 75 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index 11e9ee1..e6e5356 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ NAME ?= ADVENT COMPRESSED ?= YES ICON ?= icon.png -VERS := 1.8.0 +VERS := 1.8.1 DESCRIPTION ?= "Colossal Cave Adventure $(VERS)" #---------------------------- # Core C Makefile @@ -19,7 +19,6 @@ OPT_MODE ?= -optsize SRCDIR ?= OBJDIR ?= obj BINDIR ?= bin -GFXDIR ?= gfx #---------------------------- VERSION := 8.5 diff --git a/README.adoc b/README.adoc index c17505b..8fe07ff 100644 --- a/README.adoc +++ b/README.adoc @@ -42,7 +42,7 @@ game and has some known deficiencies. Thus you get anomalies like "eat building" interpreted as a command to move to the building. These should not be reported as bugs; instead, consider them historical curiosities. -*Nota bene:* YOU **cannot** quit the main game just pressing MODE, DEL, or CLEAR. +*Nota bene:* You **cannot** quit the main game just pressing MODE, DEL, or CLEAR. You **must** type "quit" or "save" to exit. (Alternatively, press ON, then CLEAR). ==== Installation ==== diff --git a/actions.h b/actions.h index 1f5503f..0c1e54a 100644 --- a/actions.h +++ b/actions.h @@ -1,5 +1,5 @@ /* - * Actions for the duneon-running code. + * Actions for the dungeon-running code. * * Zilog's C compiler is a bit . . . special, so this file is broken up into * smaller units. diff --git a/actions1.c b/actions1.c index c04d13c..951a74b 100644 --- a/actions1.c +++ b/actions1.c @@ -1,3 +1,14 @@ +/* + * Actions for the dungeon-running code. + * + * Zilog's C compiler is a bit . . . special, so this file is broken up into + * smaller units. + * + * Copyright (c) 1977, 2005 by Will Crowther and Don Woods + * Copyright (c) 2017 by Eric S. Raymond + * SPDX-License-Identifier: BSD-2-clause + */ + #include "actions.h" phase_codes_t attack(command_t* command) diff --git a/actions2.c b/actions2.c index 2f5e7ae..a2754e6 100644 --- a/actions2.c +++ b/actions2.c @@ -1,3 +1,14 @@ +/* + * Actions for the dungeon-running code. + * + * Zilog's C compiler is a bit . . . special, so this file is broken up into + * smaller units. + * + * Copyright (c) 1977, 2005 by Will Crowther and Don Woods + * Copyright (c) 2017 by Eric S. Raymond + * SPDX-License-Identifier: BSD-2-clause + */ + #include "actions.h" int chain(verb_t verb) diff --git a/actions3.c b/actions3.c index 45292e7..96fc372 100644 --- a/actions3.c +++ b/actions3.c @@ -1,3 +1,14 @@ +/* + * Actions for the dungeon-running code. + * + * Zilog's C compiler is a bit . . . special, so this file is broken up into + * smaller units. + * + * Copyright (c) 1977, 2005 by Will Crowther and Don Woods + * Copyright (c) 2017 by Eric S. Raymond + * SPDX-License-Identifier: BSD-2-clause + */ + #include "actions.h" phase_codes_t fill(verb_t verb, obj_t obj) diff --git a/actions4.c b/actions4.c index 6d5ce1f..c537465 100644 --- a/actions4.c +++ b/actions4.c @@ -1,3 +1,14 @@ +/* + * Actions for the dungeon-running code. + * + * Zilog's C compiler is a bit . . . special, so this file is broken up into + * smaller units. + * + * Copyright (c) 1977, 2005 by Will Crowther and Don Woods + * Copyright (c) 2017 by Eric S. Raymond + * SPDX-License-Identifier: BSD-2-clause + */ + #include "actions.h" phase_codes_t pour(verb_t verb, obj_t obj) diff --git a/actions5.c b/actions5.c index 16dbb1e..f297986 100644 --- a/actions5.c +++ b/actions5.c @@ -1,3 +1,14 @@ +/* + * Actions for the dungeon-running code. + * + * Zilog's C compiler is a bit . . . special, so this file is broken up into + * smaller units. + * + * Copyright (c) 1977, 2005 by Will Crowther and Don Woods + * Copyright (c) 2017 by Eric S. Raymond + * SPDX-License-Identifier: BSD-2-clause + */ + #include "actions.h" phase_codes_t waste(verb_t verb, turn_t turns) diff --git a/calc.c b/calc.c index 62de1e6..568509d 100644 --- a/calc.c +++ b/calc.c @@ -337,6 +337,9 @@ static void resume_game(void) var_name = NULL; search_pos = NULL; + /* Build a list of up to MAX_SAVES save files. + * The game won't prevent you making more than MAX_SAVES files, but you + * won't be able to scroll to all of them through this menu. */ while ((var_name = ti_Detect(&search_pos, save_file_header)) != NULL) { file = ti_Open(var_name, "r"); @@ -360,6 +363,8 @@ static void resume_game(void) break; } + /* If the user has no save games, display an message to that effect instead + * of garbage. */ if (total_saves == 0) { restore_splash(); @@ -378,8 +383,10 @@ static void resume_game(void) line_height = fontlib_GetCurrentFontHeight(); saves_per_screen = (LCD_HEIGHT - SAVE_LIST_Y) / line_height; + /* Let the user select a file. Implement scrolling if necessary. */ do { + /* Handle redrawing the screen if necessary. */ if (redraw) { redraw = false; @@ -433,7 +440,7 @@ static void resume_game(void) case sk_Del: redraw = true; fontlib_SetWindowFullScreen(); - gfx_FillScreen(background_color); + restore_splash(); fontlib_SetCursorPosition(0, LCD_HEIGHT / 3 - 16); print_centered_compressed(CONFIRM_DELETE); print_centered(current_item->name); diff --git a/calculator.adoc b/calculator.adoc index e27ba57..c716a40 100644 --- a/calculator.adoc +++ b/calculator.adoc @@ -28,6 +28,8 @@ but also maps all of its flash memory, too, allowing unchanging data to be read I wrote all of the code that deals with the dungeon file before ever writing any calculator code. I wanted to verify that the semicompressed dungeon file worked before any actual porting. +The text is compressed with basic Huffman coding, +though most of the space saving actually comes from string deduplication. Having a separate dungeon file reduces the program's RAM footprint. While it would have been possible to keep all the data in the program binary, diff --git a/misc.c b/misc.c index 78544e0..cab790e 100644 --- a/misc.c +++ b/misc.c @@ -1,5 +1,5 @@ /* - * I/O and support riutines. + * I/O and support routines. * * Copyright (c) 1977, 2005 by Will Crowther and Don Woods * Copyright (c) 2017 by Eric S. Raymond @@ -32,24 +32,6 @@ #include "style.h" #endif -#ifdef NEVER -/* Hack needed because Mateo decided that strcasecmp was the same as strncasecmp */ -#include -static int strncasecmp(const char *s1, const char *s2, size_t n) -{ - if (n && s1 != s2) - { - do { - int d = tolower(*s1) - tolower(*s2); - if (d || *s1 == '\0' || *s2 == '\0') return d; - s1++; - s2++; - } while (--n); - } - return 0; -} -#endif - static void* xcalloc(size_t size) { void* ptr = calloc(size, 1); diff --git a/saveresume.c b/saveresume.c index 899a103..4fb2904 100644 --- a/saveresume.c +++ b/saveresume.c @@ -69,8 +69,8 @@ static bool enough_mem() static bool is_archived(char* name) { bool archived; - ti_var_t file = 0; - if (!ti_Open(name, "r")) + ti_var_t file; + if (!(file = ti_Open(name, "r"))) return false; archived = ti_IsArchived(file); ti_Close(file); @@ -89,9 +89,9 @@ void save_apd() fp = fopen(save_file_name, WRITE_MODE); if (fp == NULL) return; - /* Only deduct two points---they've either already waited a few minutes, or - * had to leave to do something else. */ - game.saved += 2; + /* Only deduct three points---they've either already waited a few minutes, + * or had to leave to do something else. */ + game.saved += 3; savefile(fp, VRSION); if (archived) { @@ -229,6 +229,7 @@ int suspend(void) os_PutStrFull(get_arbitrary_message(SAVING_FILE)); ti_SetArchiveStatus(true, fp->slot); gfx_resume_render_splash(); + gfx_FillScreen(background_color); } #endif fclose(fp);