aboutsummaryrefslogtreecommitdiff
path: root/sword2
diff options
context:
space:
mode:
Diffstat (limited to 'sword2')
-rw-r--r--sword2/anims.cpp18
-rw-r--r--sword2/build_display.cpp71
-rw-r--r--sword2/build_display.h2
-rw-r--r--sword2/console.cpp1537
-rw-r--r--sword2/console.h142
-rw-r--r--sword2/controls.cpp4
-rw-r--r--sword2/debug.cpp169
-rw-r--r--sword2/debug.h39
-rw-r--r--sword2/driver/_console.cpp151
-rw-r--r--sword2/driver/_console.h29
-rw-r--r--sword2/driver/d_draw.h5
-rw-r--r--sword2/driver/render.cpp2
-rw-r--r--sword2/events.cpp15
-rw-r--r--sword2/events.h2
-rw-r--r--sword2/function.cpp2
-rw-r--r--sword2/icons.cpp2
-rw-r--r--sword2/interpreter.cpp6
-rw-r--r--sword2/layers.cpp2
-rw-r--r--sword2/logic.cpp48
-rw-r--r--sword2/logic.h2
-rw-r--r--sword2/maketext.cpp6
-rw-r--r--sword2/maketext.h16
-rw-r--r--sword2/mem_view.cpp32
-rw-r--r--sword2/memory.h2
-rw-r--r--sword2/module.mk1
-rw-r--r--sword2/mouse.cpp144
-rw-r--r--sword2/protocol.cpp11
-rw-r--r--sword2/resman.cpp351
-rw-r--r--sword2/resman.h8
-rw-r--r--sword2/router.cpp21
-rw-r--r--sword2/router.h4
-rw-r--r--sword2/save_rest.cpp6
-rw-r--r--sword2/sound.cpp11
-rw-r--r--sword2/speech.cpp88
-rw-r--r--sword2/startup.cpp163
-rw-r--r--sword2/startup.h4
-rw-r--r--sword2/sword2.cpp180
-rw-r--r--sword2/sword2.h13
-rw-r--r--sword2/walker.cpp22
39 files changed, 1359 insertions, 1972 deletions
diff --git a/sword2/anims.cpp b/sword2/anims.cpp
index a48da08a5a..adcfb92c61 100644
--- a/sword2/anims.cpp
+++ b/sword2/anims.cpp
@@ -153,7 +153,7 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
#ifdef _SWORD2_DEBUG
// check that we haven't been passed a zero resource number
if (res == 0)
- Con_fatal_error("Animate: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID);
+ error("Animate: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID);
#endif
// open anim file
@@ -163,7 +163,7 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
// check this this resource is actually an animation file!
head = (_standardHeader *) anim_file;
if (head->fileType != ANIMATION_FILE)
- Con_fatal_error("Animate: %s (%d) is not an anim!", FetchObjectName(res), res);
+ error("Animate: %s (%d) is not an anim!", FetchObjectName(res), res);
#endif
// point to anim header
@@ -172,7 +172,7 @@ int32 Animate(int32 *params, uint8 reverse_flag) {
/* #ifdef _SWORD2_DEBUG
// check there's at least one frame
if (anim_head->noAnimFrames == 0)
- Con_fatal_error("Animate: %s (%d) has zero frame count!", FetchObjectName(res), res);
+ error("Animate: %s (%d) has zero frame count!", FetchObjectName(res), res);
#endif */
// now running an anim, looping back to this 'FN' call again
@@ -275,7 +275,7 @@ int32 Logic::fnSetFrame(int32 *params) {
#ifdef _SWORD2_DEBUG
// check that we haven't been passed a zero resource number
if (res == 0)
- Con_fatal_error("fnSetFrame: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID);
+ error("fnSetFrame: %s (id %d) passed zero anim resource", FetchObjectName(ID), ID);
#endif
// open the resource (& check it's valid)
@@ -286,7 +286,7 @@ int32 Logic::fnSetFrame(int32 *params) {
// check this this resource is actually an animation file!
head = (_standardHeader *) anim_file;
if (head->fileType != ANIMATION_FILE)
- Con_fatal_error("fnSetFrame: %s (%d) is not an anim!", FetchObjectName(res), res);
+ error("fnSetFrame: %s (%d) is not an anim!", FetchObjectName(res), res);
#endif
// set up pointer to the animation header
@@ -295,7 +295,7 @@ int32 Logic::fnSetFrame(int32 *params) {
/* #ifdef _SWORD2_DEBUG
// check there's at least one frame
if (anim_head->noAnimFrames == 0)
- Con_fatal_error("fnSetFrame: %s (%d) has zero frame count!", FetchObjectName(res), res);
+ error("fnSetFrame: %s (%d) has zero frame count!", FetchObjectName(res), res);
#endif */
// set up anim resource in graphic object
@@ -487,7 +487,7 @@ int32 Logic::fnAddSequenceText(int32 *params) {
#ifdef _SWORD2_DEBUG
if (sequenceTextLines == MAX_SEQUENCE_TEXT_LINES)
- Con_fatal_error("fnAddSequenceText ran out of lines");
+ error("fnAddSequenceText ran out of lines");
#endif
sequence_text_list[sequenceTextLines].textNumber = params[0];
@@ -663,7 +663,7 @@ int32 Logic::fnSmackerLeadIn(int32 *params) {
#ifdef _SWORD2_DEBUG
header = (_standardHeader *) leadIn;
if (header->fileType != WAV_FILE)
- Con_fatal_error("fnSmackerLeadIn() given invalid resource");
+ error("fnSmackerLeadIn() given invalid resource");
#endif
leadIn += sizeof(_standardHeader);
@@ -715,7 +715,7 @@ int32 Logic::fnPlaySequence(int32 *params) {
#ifdef _SWORD2_DEBUG
// check that the name paseed from script is 8 chars or less
if (strlen((char *) params[0]) > 8)
- Con_fatal_error("Sequence filename too long");
+ error("Sequence filename too long");
#endif
// add the appropriate file extension & play it
diff --git a/sword2/build_display.cpp b/sword2/build_display.cpp
index 18dca60264..f86479cead 100644
--- a/sword2/build_display.cpp
+++ b/sword2/build_display.cpp
@@ -61,12 +61,10 @@ uint32 cur_fore;
uint32 cur_fgp0;
uint32 cur_fgp1;
-#ifdef _SWORD2_DEBUG
uint32 largest_layer_area = 0; // should be reset to zero at start of each screen change
uint32 largest_sprite_area = 0; // - " -
char largest_layer_info[128] = { "largest layer: none registered" };
char largest_sprite_info[128] = { "largest sprite: none registered" };
-#endif
// ---------------------------------------------------------------------------
// last palette used - so that we can restore the correct one after a pause
@@ -110,29 +108,19 @@ void Send_fore_par1_frames(void);
// ---------------------------------------------------------------------------
void Build_display(void) {
-#ifdef _SWORD2_DEBUG
- uint8 pal[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0 };
-#endif
uint8 *file;
_multiScreenHeader *screenLayerTable;
-#ifdef _SWORD2_DEBUG // only used by console
- _spriteInfo spriteInfo;
- uint32 rv; // drivers error return value
-#endif
-
- if (!console_status && this_screen.new_palette) {
+ if (this_screen.new_palette) {
// start the layer palette fading up
Start_new_palette();
-#ifdef _SWORD2_DEBUG
largest_layer_area = 0; // should be reset to zero at start of each screen change
largest_sprite_area = 0; // - " -
-#endif
}
// there is a valid screen to run
- if (!console_status && this_screen.background_layer_id) {
+ if (this_screen.background_layer_id) {
// set the scroll position
g_display->setScrollTarget(this_screen.scroll_offset_x, this_screen.scroll_offset_y);
// increment the mouse frame
@@ -271,30 +259,6 @@ void Build_display(void) {
break;
}
}
-#ifdef _SWORD2_DEBUG
- else if (console_status) {
- spriteInfo.x = 0;
- spriteInfo.y = con_y;
- spriteInfo.w = con_width;
- spriteInfo.h = con_depth;
- spriteInfo.scale = 0;
- spriteInfo.scaledWidth = 0;
- spriteInfo.scaledHeight = 0;
- spriteInfo.type = RDSPR_DISPLAYALIGN | RDSPR_NOCOMPRESSION;
- spriteInfo.blend = 0;
- spriteInfo.data = console_sprite->ad;
- spriteInfo.colourTable = 0;
-
- rv = g_display->drawSprite(&spriteInfo);
- if (rv)
- error("Driver Error %.8x (drawing console)", rv);
- } else{
- StartConsole();
- // force the palette
- g_display->setPalette(0, 3, pal, RDPAL_INSTANT);
- Print_to_console("no valid screen?");
- }
-#endif
}
// ---------------------------------------------------------------------------
@@ -461,9 +425,7 @@ void Process_layer(uint32 layer_number) {
_spriteInfo spriteInfo;
uint32 rv;
-#ifdef _SWORD2_DEBUG
uint32 current_layer_area = 0;
-#endif
// file points to 1st byte in the layer file
file = res_man.open(this_screen.background_layer_id);
@@ -487,7 +449,6 @@ void Process_layer(uint32 layer_number) {
//------------------------------------------
// check for largest layer for debug info
-#ifdef _SWORD2_DEBUG
current_layer_area = layer_head->width * layer_head->height;
if (current_layer_area > largest_layer_area) {
@@ -497,7 +458,7 @@ void Process_layer(uint32 layer_number) {
FetchObjectName(this_screen.background_layer_id),
layer_number, layer_head->width, layer_head->height);
}
-#endif
+
//------------------------------------------
rv = g_display->drawSprite(&spriteInfo);
@@ -516,9 +477,7 @@ void Process_image(buildit *build_unit) {
uint32 spriteType;
uint32 rv;
-#ifdef _SWORD2_DEBUG
uint32 current_sprite_area = 0;
-#endif
// open anim resource file & point to base
file = res_man.open(build_unit->anim_resource);
@@ -586,7 +545,6 @@ void Process_image(buildit *build_unit) {
spriteInfo.data = (uint8 *) (frame_head + 1);
spriteInfo.colourTable = colTablePtr;
-#ifdef _SWORD2_DEBUG
//------------------------------------------
// check for largest layer for debug info
@@ -601,7 +559,6 @@ void Process_image(buildit *build_unit) {
frame_head->width,
frame_head->height);
}
-#endif
#ifdef _SWORD2_DEBUG
if (SYSTEM_TESTING_ANIMS) { // see anims.cpp
@@ -703,7 +660,7 @@ void Register_frame(int32 *params, buildit *build_unit) {
#ifdef _SWORD2_DEBUG
if (ob_graph->anim_resource == 0)
- Con_fatal_error("ERROR: %s(%d) has no anim resource in Register_frame", FetchObjectName(ID), ID);
+ error("ERROR: %s(%d) has no anim resource in Register_frame", FetchObjectName(ID), ID);
#endif
file = res_man.open(ob_graph->anim_resource);
@@ -791,7 +748,7 @@ void Register_frame(int32 *params, buildit *build_unit) {
if (ob_mouse->pointer) {
#ifdef _SWORD2_DEBUG
if (cur_mouse == TOTAL_mouse_list)
- Con_fatal_error("ERROR: mouse_list full");
+ error("ERROR: mouse_list full");
#endif
mouse_list[cur_mouse].x1 = build_unit->x;
@@ -842,7 +799,7 @@ int32 Logic::fnRegisterFrame(int32 *params) {
case BGP0_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_bgp0 == MAX_bgp0_sprites)
- Con_fatal_error("ERROR: bgp0_list full in fnRegisterFrame");
+ error("ERROR: bgp0_list full in fnRegisterFrame");
#endif
Register_frame(params, &bgp0_list[cur_bgp0]);
@@ -851,7 +808,7 @@ int32 Logic::fnRegisterFrame(int32 *params) {
case BGP1_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_bgp1 == MAX_bgp1_sprites)
- Con_fatal_error("ERROR: bgp1_list full in fnRegisterFrame");
+ error("ERROR: bgp1_list full in fnRegisterFrame");
#endif
Register_frame(params, &bgp1_list[cur_bgp1]);
@@ -860,7 +817,7 @@ int32 Logic::fnRegisterFrame(int32 *params) {
case BACK_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_back == MAX_back_sprites)
- Con_fatal_error("ERROR: back_list full in fnRegisterFrame");
+ error("ERROR: back_list full in fnRegisterFrame");
#endif
Register_frame(params, &back_list[cur_back]);
@@ -869,7 +826,7 @@ int32 Logic::fnRegisterFrame(int32 *params) {
case SORT_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_sort == MAX_sort_sprites)
- Con_fatal_error("ERROR: sort_list full in fnRegisterFrame");
+ error("ERROR: sort_list full in fnRegisterFrame");
#endif
sort_order[cur_sort] = cur_sort;
@@ -879,7 +836,7 @@ int32 Logic::fnRegisterFrame(int32 *params) {
case FORE_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_fore == MAX_fore_sprites)
- Con_fatal_error("ERROR: fore_list full in fnRegisterFrame");
+ error("ERROR: fore_list full in fnRegisterFrame");
#endif
Register_frame(params, &fore_list[cur_fore]);
@@ -888,7 +845,7 @@ int32 Logic::fnRegisterFrame(int32 *params) {
case FGP0_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_fgp0 == MAX_fgp0_sprites)
- Con_fatal_error("ERROR: fgp0_list full in fnRegisterFrame");
+ error("ERROR: fgp0_list full in fnRegisterFrame");
#endif
Register_frame(params, &fgp0_list[cur_fgp0]);
@@ -897,7 +854,7 @@ int32 Logic::fnRegisterFrame(int32 *params) {
case FGP1_SPRITE:
#ifdef _SWORD2_DEBUG
if (cur_fgp1 == MAX_fgp1_sprites)
- Con_fatal_error("ERROR: fgp1_list full in fnRegisterFrame");
+ error("ERROR: fgp1_list full in fnRegisterFrame");
#endif
Register_frame(params, &fgp1_list[cur_fgp1]);
@@ -1051,7 +1008,7 @@ void SetFullPalette(int32 palRes) {
#ifdef _SWORD2_DEBUG
if (head->fileType != PALETTE_FILE)
- Con_fatal_error("fnSetPalette() called with invalid resource!");
+ error("fnSetPalette() called with invalid resource!");
#endif
file = (uint8 *) (head + 1);
@@ -1092,7 +1049,7 @@ void SetFullPalette(int32 palRes) {
// close screen file
res_man.close(this_screen.background_layer_id);
} else
- Con_fatal_error("fnSetPalette(0) called, but no current screen available!");
+ error("fnSetPalette(0) called, but no current screen available!");
}
}
diff --git a/sword2/build_display.h b/sword2/build_display.h
index c8607f16f4..cd287bbc6e 100644
--- a/sword2/build_display.h
+++ b/sword2/build_display.h
@@ -75,10 +75,8 @@ extern uint32 cur_fore;
extern uint32 cur_fgp0;
extern uint32 cur_fgp1;
-#ifdef _SWORD2_DEBUG
extern char largest_layer_info[128];
extern char largest_sprite_info[128];
-#endif
// the only build list needed externally - by layers.cpp - for adding layers
// to sort list
diff --git a/sword2/console.cpp b/sword2/console.cpp
index b8c811fdec..4f5068ade1 100644
--- a/sword2/console.cpp
+++ b/sword2/console.cpp
@@ -18,845 +18,619 @@
*/
#include "stdafx.h"
-#include "bs2/driver/driver96.h"
-
-namespace Sword2 {
-uint32 console_status = 0; //0 off // LEFT IN RELEASE VERSION
-} // End of namespace Sword2
-
-#ifdef _SWORD2_DEBUG
-
-// its the console! <great>
-
-#include "bs2/build_display.h"
+#include "bs2/sword2.h"
#include "bs2/console.h"
#include "bs2/debug.h"
#include "bs2/defs.h"
-#include "bs2/events.h" // so we can display the event list in Con_display_events()
-#include "bs2/header.h"
-#include "bs2/layers.h"
+#include "bs2/events.h"
#include "bs2/logic.h"
-#include "bs2/maketext.h" // for initialiseFontResourceFlags()
+#include "bs2/maketext.h"
#include "bs2/mouse.h"
-#include "bs2/mem_view.h"
-#include "bs2/memory.h"
#include "bs2/protocol.h"
#include "bs2/resman.h"
#include "bs2/save_rest.h"
#include "bs2/startup.h"
-#include "bs2/sword2.h"
-#include "bs2/time.h"
-namespace Sword2 {
+// FIXME: Much of this is copied from scumm/debugger.cpp which is a pretty
+// lousy form of code reuse.
-uint32 Parse_user_input(void);
-void Clear_console_line(void);
-void Con_help(void);
-
-void Con_colour_block(int x, int width, int height, uint32 pen, uint32 paper, uint8 *sprite_data_ad);
-void Con_print(uint8 *ascii, uint32 pen, uint32 paper);
-uint32 Tconsole(uint32 mode);
-
-void Con_list_savegames(void);
-void Con_save_game(int total_commands, uint8 *slotString, uint8 *description);
-void Con_restore_game(int total_commands, uint8 *slotString);
-uint8 Is_number(uint8 *ascii);
-void Con_start_timer(int total_commands, uint8 *slotString);
-void ShowVar(uint8 *varNoPtr);
-void HideVar(uint8 *varNoPtr);
-void Con_display_version(void);
-
-void Var_check(uint8 *pointer);
-void Var_set(uint8 *pointer, uint8 *p2);
-
-void Con_display_events();
-
-uint8 wantSfxDebug = 0; // sfx debug file enabled/disabled from console
-
-#define MAX_CONSOLE_BUFFER 70
-#define MAX_CONSOLE_PARAMS 5
-
-#define CON_PEN 187
-
-#define VK_TAB 0x09
-#define VK_RETURN 0x0D
-
-char console_buffer[MAX_CONSOLE_BUFFER];
-
-char last_command[MAX_CONSOLE_BUFFER];
-int last_command_len = 0;
-
-uint8 grabbingSequences = 0;
-
-int console_pos = 0;
-
-int console_mode = 0; // 0 is the base command line
- // 1 means only parse for yes or no commands
-
-#define TOTAL_CONSOLE_COMMANDS 47
-
-// note '9' is max command length including null-terminator
-uint8 commands[TOTAL_CONSOLE_COMMANDS][9] = {
- "HELP", // 0
- "MEM", // 1
- "Q", // 2
- "TONY", // 3
- "YES", // 4
- "NO", // 5
- "RES", // 6
- "STARTS", // 7
- "START", // 8
- "INFO", // 9
- "WALKGRID", // 10
- "MOUSE", // 11
- "PLAYER", // 12
- "RESLOOK", // 13
- "CUR", // 14
- "RUNLIST", // 15
- "KILL", // 16
- "NUKE", // 17
- "S", // 18
- "VAR", // 19
- "RECT", // 20
- "CLEAR", // 21
- "DEBUGON", // 22
- "DEBUGOFF", // 23
- "SAVEREST", // 24
- "SAVES", // 25
- "SAVE", // 26
- "RESTORE", // 27
- "BLTFXON", // 28
- "BLTFXOFF", // 29
- "TIMEON", // 30
- "TIMEOFF", // 31
- "TEXT", // 32
- "SHOWVAR", // 33
- "HIDEVAR", // 34
- "VERSION", // 35
- "SOFT", // 36
- "HARD", // 37
- "ANIMTEST", // 38
- "TEXTTEST", // 39
- "LINETEST", // 40
- "GRAB", // 41
- "EVENTS", // 42
- "SFX", // 43
- "ENGLISH", // 44
- "FINNISH", // 45
- "POLISH" // 46
-};
-
-mem *console_sprite;
-uint32 con_y;
-uint32 con_depth;
-uint32 con_width;
-uint32 con_chr_height;
-
-#define CON_lines 20 // 10 lines deep
-
-void Init_console(void) {
- // grab the memory for the console sprite
-
- uint8 *ad;
- uint8 white[4] = { 255, 255, 255, 0 };
-
- con_chr_height = 12;
- con_width = screenWide; //max across
-
- // Force a palatte for the console.
- g_display->setPalette(CON_PEN, 1, white, RDPAL_INSTANT);
-
- console_sprite = memory.alloc(con_width * (CON_lines * con_chr_height), MEM_float, UID_con_sprite);
-
- if (!console_sprite) {
- ExitWithReport("Init_console alloc fail");
- }
+#ifdef _WIN32_WCE
+extern void force_keyboard(bool);
+#endif
- con_depth = CON_lines * con_chr_height;
- con_y = 399 - con_depth;
+namespace Sword2 {
- // clear the buffer for a nice fresh start
+bool wantSfxDebug = false; // sfx debug enabled/disabled from console
- memset(console_sprite->ad, 0, con_width * CON_lines * con_chr_height);
+static void Var_check(int var) {
+ Debug_Printf("%d\n", VAR(var));
+}
- debug(5, "console height %d, y %d", con_depth, con_y);
+static void Var_set(int var, int val) {
+ Debug_Printf("was %d, ", VAR(var));
+ VAR(var) = val;
+ Debug_Printf("now %d\n", VAR(var));
+}
- //first time in message
- Con_display_version();
+Debugger::Debugger(Sword2Engine *s) {
+ _vm = s;
+ _frame_countdown = 0;
+ _dcmd_count = 0;
+ _detach_now = false;
+ _isAttached = false;
+ _errStr = NULL;
+
+ // Register commands
+
+ DCmd_Register("continue", &Debugger::Cmd_Exit);
+ DCmd_Register("exit", &Debugger::Cmd_Exit);
+ DCmd_Register("quit", &Debugger::Cmd_Exit);
+ DCmd_Register("q", &Debugger::Cmd_Exit);
+ DCmd_Register("help", &Debugger::Cmd_Help);
+ DCmd_Register("mem", &Debugger::Cmd_Mem);
+ DCmd_Register("tony", &Debugger::Cmd_Tony);
+ DCmd_Register("res", &Debugger::Cmd_Res);
+ DCmd_Register("starts", &Debugger::Cmd_Starts);
+ DCmd_Register("start", &Debugger::Cmd_Start);
+ DCmd_Register("s", &Debugger::Cmd_Start);
+ DCmd_Register("info", &Debugger::Cmd_Info);
+ DCmd_Register("walkgrid", &Debugger::Cmd_WalkGrid);
+ DCmd_Register("mouse", &Debugger::Cmd_Mouse);
+ DCmd_Register("player", &Debugger::Cmd_Player);
+ DCmd_Register("reslook", &Debugger::Cmd_ResLook);
+ DCmd_Register("cur", &Debugger::Cmd_CurrentInfo);
+ DCmd_Register("runlist", &Debugger::Cmd_RunList);
+ DCmd_Register("kill", &Debugger::Cmd_Kill);
+ DCmd_Register("nuke", &Debugger::Cmd_Nuke);
+ DCmd_Register("var", &Debugger::Cmd_Var);
+ DCmd_Register("rect", &Debugger::Cmd_Rect);
+ DCmd_Register("clear", &Debugger::Cmd_Clear);
+ DCmd_Register("debugon", &Debugger::Cmd_DebugOn);
+ DCmd_Register("debugoff", &Debugger::Cmd_DebugOn);
+ DCmd_Register("saverest", &Debugger::Cmd_SaveRest);
+ DCmd_Register("saves", &Debugger::Cmd_ListSaveGames);
+ DCmd_Register("save", &Debugger::Cmd_SaveGame);
+ DCmd_Register("restore", &Debugger::Cmd_RestoreGame);
+ DCmd_Register("bltfxon", &Debugger::Cmd_BltFxOn);
+ DCmd_Register("bltfxoff", &Debugger::Cmd_BltFxOff);
+ DCmd_Register("timeon", &Debugger::Cmd_TimeOn);
+ DCmd_Register("timeoff", &Debugger::Cmd_TimeOff);
+ DCmd_Register("text", &Debugger::Cmd_Text);
+ DCmd_Register("showvar", &Debugger::Cmd_ShowVar);
+ DCmd_Register("hidevar", &Debugger::Cmd_HideVar);
+ DCmd_Register("version", &Debugger::Cmd_Version);
+ DCmd_Register("soft", &Debugger::Cmd_SoftHard);
+ DCmd_Register("hard", &Debugger::Cmd_SoftHard);
+ DCmd_Register("animtest", &Debugger::Cmd_AnimTest);
+ DCmd_Register("texttest", &Debugger::Cmd_TextTest);
+ DCmd_Register("linetest", &Debugger::Cmd_LineTest);
+ DCmd_Register("grab", &Debugger::Cmd_Grab);
+ DCmd_Register("events", &Debugger::Cmd_Events);
+ DCmd_Register("sfx", &Debugger::Cmd_Sfx);
+ DCmd_Register("english", &Debugger::Cmd_English);
+ DCmd_Register("finnish", &Debugger::Cmd_Finnish);
+ DCmd_Register("polish", &Debugger::Cmd_Polish);
}
-void StartConsole(void) {
- // start console up and restart new line
- // can ne called for newline
+void Debugger::attach(const char *entry) {
- console_pos = 0; // start of new line
+#ifdef _WIN32_WCE
+ force_keyboard(true);
+#endif
- //we need to clear the whole buffer - else the cursor overwrites the
- // end 0
+ if (entry) {
+ _errStr = strdup(entry);
+ }
- console_status = 1; // on
+ _frame_countdown = 1;
+ _detach_now = false;
+ _isAttached = true;
}
-void EndConsole(void) {
- console_status = 0; // off
+void Debugger::detach() {
+#if USE_CONSOLE
+ if (_vm->_debuggerDialog) {
+ _vm->_debuggerDialog->setInputeCallback(0, 0);
+ _vm->_debuggerDialog->setCompletionCallback(0, 0);
+ }
+#endif
+
+#ifdef _WIN32_WCE
+ force_keyboard(false);
+#endif
+
+ _detach_now = false;
+ _isAttached = false;
}
-uint32 Tconsole(uint32 mode) {
- // call from anywhere
- // returns a positive value of the token typed or 0 for windows
- // quiting - the caller should drop back
+// Temporary execution handler
+void Debugger::onFrame() {
+ if (_frame_countdown == 0)
+ return;
+ --_frame_countdown;
- uint32 ret, breakOut = 0;
+ if (!_frame_countdown) {
+ // Pause sound output
- console_mode = mode; //set command frame
+ g_sound->pauseFx();
+ g_sound->pauseSpeech();
+ g_sound->pauseMusic();
- StartConsole();
+ // Enter debugger
+ enter();
- while (1) {
- g_display->updateDisplay();
+ // Resume previous sound state
- if (breakOut)
- break;
+ g_sound->unpauseFx();
+ g_sound->unpauseSpeech();
+ g_sound->unpauseMusic();
- if ((ret = One_console()) != 0) {
- EndConsole();
- return ret;
- }
+ // Restore old mouse cursor
+ g_display->drawMouse();
- Build_display(); // create and flip the screen
+ // Detach if we're finished with the debugger
+ if (_detach_now)
+ detach();
}
+}
- // a windows message is throwing us out of here
+// Console handler
+#if USE_CONSOLE
+bool Debugger::debuggerInputCallback(ConsoleDialog *console, const char *input, void *refCon) {
+ Debugger *debugger = (Debugger *) refCon;
- EndConsole(); // switch off drawing
- return 0;
+ return debugger->RunCommand(input);
}
-void Scroll_console(void) {
- // scroll the console sprite up 12 pixels
+bool Debugger::debuggerCompletionCallback(ConsoleDialog *console, const char *input, char*& completion, void *refCon) {
+ Debugger *debugger = (Debugger *) refCon;
- uint32 *to_buffer;
- uint32 *from_buffer;
-
- // number of dwords
- x = ((con_depth - con_chr_height) * 640) / 4;
+ return debugger->TabComplete(input, completion);
+}
+#endif
- to_buffer= (uint32 *) console_sprite->ad;
- from_buffer = to_buffer + ((con_chr_height * 640) / 4);
+///////////////////////////////////////////////////
+// Now the fun stuff:
- memmove(to_buffer, from_buffer, (con_depth - con_chr_heigth) * 640);
+void Debugger::DCmd_Register(const char *cmdname, DebugProc pointer) {
+ assert(_dcmd_count < (int) sizeof(_dcmds));
+ strcpy(_dcmds[_dcmd_count].name, cmdname);
+ _dcmds[_dcmd_count].function = pointer;
- // blank the on-coming bottom line
- Clear_console_line();
+ _dcmd_count++;
}
-void Clear_console_line(void) {
- // blank the bottom line
+// Main Debugger Loop
+void Debugger::enter() {
+#if USE_CONSOLE
+ if (!_vm->_debuggerDialog) {
+ _vm->_debuggerDialog = new ConsoleDialog(_vm->_newgui, 1.0, 0.67F);
- uint32 *pbuffer;
+ Debug_Printf("Debugger started, type 'exit' to return to the game.\n");
+ Debug_Printf("Type 'help' to see a little list of commands and variables.\n");
+ }
+
+ if (_errStr) {
+ Debug_Printf("ERROR: %s\n\n", _errStr);
+ free(_errStr);
+ _errStr = NULL;
+ }
+
+ _vm->_debuggerDialog->setInputeCallback(debuggerInputCallback, this);
+ _vm->_debuggerDialog->setCompletionCallback(debuggerCompletionCallback, this);
+ _vm->_debuggerDialog->runModal();
+#else
+ // TODO: compared to the console input, this here is very bare bone.
+ // For example, no support for tab completion and no history. At least
+ // we should re-add (optional) support for the readline library.
+ // Or maybe instead of choosing between a console dialog and stdio,
+ // we should move that choice into the ConsoleDialog class - that is,
+ // the console dialog code could be #ifdef'ed to not print to the dialog
+ // but rather to stdio. This way, we could also reuse the command history
+ // and tab completion of the console. It would still require a lot of
+ // work, but at least no dependency on a 3rd party library...
+
+ printf("Debugger entered, please switch to this console for input.\n");
+
+ int i;
+ char buf[256];
- //base of our off-screen back buffer
- pbuffer= (uint32 *) console_sprite->ad;
+ do {
+ printf("debug> ");
+ if (!fgets(buf, sizeof(buf), stdin))
+ return;
+
+ i = strlen(buf);
+ while (i > 0 && buf[i - 1] == '\n')
+ buf[--i] = 0;
- //index to console text position
- pbuffer += ((con_depth-con_chr_height) * con_width / 4);
+ if (i == 0)
+ continue;
+ } while (RunCommand(buf));
- // clear the bottom text line
- memset(pbuffer, 0, con_chr_height * con_width);
+#endif
}
-void Print_to_console(const char *format, ...) {
- // print a NULL terminated string of ascii to the next console line
- // we can assume that the user has just entered a command by pressing
- // return - which means we're on a clean line so output the line and
- // line feed
+// Command execution loop
+bool Debugger::RunCommand(const char *inputOrig) {
+ int i = 0, num_params = 0;
+ const char *param[256];
+ char *input = strdup(inputOrig); // One of the rare occasions using strdup is OK (although avoiding strtok might be more elegant here).
+
+ // Parse out any params
+ char *tok = strtok(input, " ");
+ if (tok) {
+ do {
+ param[num_params++] = tok;
+ } while ((tok = strtok(NULL, " ")) != NULL);
+ } else {
+ param[num_params++] = input;
+ }
+
+ for (i = 0; i < _dcmd_count; i++) {
+ if (!strcmp(_dcmds[i].name, param[0])) {
+ bool result = (this->*_dcmds[i].function)(num_params, param);
+ free(input);
+ return result;
+ }
+ }
+
+ Debug_Printf("Unknown command\n");
+ free(input);
+ return true;
+}
- va_list arg_ptr;
- char buf[150];
+// Commands
- va_start(arg_ptr,format);
- _vsnprintf(buf, 150, format, arg_ptr);
- Con_print((uint8 *) buf, 2, 0);
- Scroll_console();
+bool Debugger::Cmd_Exit(int argc, const char **argv) {
+ _detach_now = true;
+ return false;
}
-void Temp_print_to_console(const char *format, ...) {
- // print a NULL terminated string of ascii to the next console line
- // we can assume that the user has just entered a command by pressing
- // return - which means we're on a clean line so output the line and
- // line feed
+bool Debugger::Cmd_Help(int argc, const char **argv) {
+ // console normally has 39 line width
+ // wrap around nicely
+ int width = 0, size, i;
- va_list arg_ptr; // Variable argument pointer
- char buf[150];
+ Debug_Printf("Commands are:\n");
+ for (i = 0 ; i < _dcmd_count ; i++) {
+ size = strlen(_dcmds[i].name) + 1;
- va_start(arg_ptr,format);
- _vsnprintf(buf, 150, format, arg_ptr);
+ if ((width + size) >= 39) {
+ Debug_Printf("\n");
+ width = size;
+ } else
+ width += size;
- Con_print((uint8 *) buf, 2, 0);
+ Debug_Printf("%s ", _dcmds[i].name);
+ }
+
+ Debug_Printf("\n");
+ return true;
}
-uint32 One_console(void) {
- // its the console command line system
- // do an update - check keys and flash cursor and so on
+bool Debugger::Cmd_Mem(int argc, const char **argv) {
+ memory.displayMemory();
+ return true;
+}
- char c;
- static int flash = 0; //controls the flashing cursor rate
- uint32 res;
+bool Debugger::Cmd_Tony(int argc, const char **argv) {
+ Debug_Printf("What about him?\n");
+ return true;
+}
- if (KeyWaiting()) {
- ReadKey(&c);
+bool Debugger::Cmd_Res(int argc, const char **argv) {
+ res_man.printConsoleClusters();
+ return true;
+}
- if (c == VK_TAB) {
- if (last_command_len) { // if anything stored in buffer
- // retrieve 'last_command' buffer
- // first clear the entire current buffer
- memset (console_buffer, 0, MAX_CONSOLE_BUFFER);
+bool Debugger::Cmd_Starts(int argc, const char **argv) {
+ Con_print_start_menu();
+ return true;
+}
- // now copy in the last command
- memcpy (console_buffer, last_command, last_command_len);
- console_pos = last_command_len;
- }
- } else if (c == VK_RETURN) {
- // by putting a space in we'll always have a chr$ in
- // the buffer
- console_buffer[console_pos] = ' ';
- Clear_console_line();
- Print_to_console(console_buffer);
-
- // parse the input I guess
-
- if (console_pos) {
- // save to 'last_command' buffer, in case need
- // to repeat same command
-
- // get a copy of the current command, and its
- // length
- memcpy (last_command, console_buffer, console_pos);
- last_command_len = console_pos;
-
- res = Parse_user_input();
- if (res)
- return res;
- }
+bool Debugger::Cmd_Start(int argc, const char **argv) {
+ uint8 pal[4] = { 255, 255, 255, 0 };
- StartConsole(); // reset buffer
- } else if (c == 8) {
- if (console_pos) {
- // delete cursor chr$
- console_buffer[console_pos] = 0;
- console_pos--;
- console_buffer[console_pos]=0;
- }
- } else if (c < 32 || c > 'z')
- debug(5, "console ignoring key - %d", c);
- else {
- // less one to leave room for the cursor
- if (console_pos < MAX_CONSOLE_BUFFER - 1) {
- console_buffer[console_pos++] = c;
- } else {
- // end of line has been reached, so keep
- // replacing last letter
- console_buffer[console_pos - 1] = c;
- }
- }
+ if (argc != 2) {
+ Debug_Printf("Usage: %s number\n", argv[0]);
+ return true;
}
- flash++;
+ Con_start(atoi(argv[1]));
+ g_display->setPalette(187, 1, pal, RDPAL_INSTANT);
+ return true;
+}
+
+bool Debugger::Cmd_Info(int argc, const char **argv) {
+ displayDebugText = !displayDebugText;
- if (flash < 7)
- console_buffer[console_pos] = '_';
+ if (displayDebugText)
+ Debug_Printf("Info text on\n");
else
- console_buffer[console_pos] = ' ';
+ Debug_Printf("Info Text off\n");
- if (flash == 14)
- flash = 0;
+ return true;
+}
- // update the real screen - done every cycle to keep the cursor
- // flashing
+bool Debugger::Cmd_WalkGrid(int argc, const char **argv) {
+ displayWalkGrid = !displayWalkGrid;
- Clear_console_line();
- Con_print((uint8 *) console_buffer, 2, 0);
+ if (displayWalkGrid)
+ Debug_Printf("Walk-grid display on\n");
+ else
+ Debug_Printf("Walk-grid display off\n");
- return 0;
+ return true;
}
-uint32 Parse_user_input(void) {
- // pressed return and now we need to analyse whats been written and
- // call up the relevent commands
+bool Debugger::Cmd_Mouse(int argc, const char **argv) {
+ displayMouseMarker = !displayMouseMarker;
- uint8 input[MAX_CONSOLE_PARAMS][MAX_CONSOLE_BUFFER];
- int i, j, total_commands = 0;
- int index = 0;
- uint32 rv;
- uint8 pal[4] = { 255, 255, 255, 0 };
+ if (displayMouseMarker)
+ Debug_Printf("Mouse marker on\n");
+ else
+ Debug_Printf("Mouse marker off\n");
- // quick check for numbers here
- if (!isalpha(console_buffer[0])) {
- Print_to_console("Eh?");
- return 0;
- }
+ return true;
+}
- j = 0;
- do {
- i = 0;
- do
- input[j][i++] = toupper(console_buffer[index++]);
- while (isgraph(console_buffer[index]));
+bool Debugger::Cmd_Player(int argc, const char **argv) {
+ displayPlayerMarker = !displayPlayerMarker;
+
+ if (displayPlayerMarker)
+ Debug_Printf("Player feet marker on\n");
+ else
+ Debug_Printf("Player feet marker off\n");
- input[j][i] = 0;
+ return true;
+}
- j++;
- total_commands++;
+bool Debugger::Cmd_ResLook(int argc, const char **argv) {
+ if (argc != 2)
+ Debug_Printf("Usage: %s number\n", argv[0]);
+ else
+ res_man.examine(atoi(argv[1]));
+ return true;
+}
- if (index == console_pos)
- break;
+bool Debugger::Cmd_CurrentInfo(int argc, const char **argv) {
+ Print_current_info();
+ return true;
+}
- do
- index++;
- while (console_buffer[index] == ' ');
- } while (j < MAX_CONSOLE_PARAMS);
-
- // try to find the first word in the commands base
-
- for (j = 0; j < TOTAL_CONSOLE_COMMANDS; j++) {
- i = 0;
- while (input[0][i] == commands[j][i] && input[0][i])
- i++;
-
- // got to the end of an entry - so must have matched the whole
- // word
- if (!input[0][i] && !commands[j][i]) {
- // the console mode denotes the scope of the commands
- // accepted 0 is the base mode
-
- switch (console_mode) {
- // external console commands may only be
- // requiring a yes/no input for example
- // a different scope would only accept yes and
- // no and drop back out when found... see?
-
- case 0:
- // base command line
- switch(j) {
- case 0: // HELP
- Con_help();
- return 0;
- case 1: // MEM
- memory.displayMemory();
- return 0;
- case 2: // Q
- // quit the console
- return 1;
- case 3: // TONY
- Print_to_console("What about him?");
- return 0;
- case 6: // RES
- res_man.printConsoleClusters();
- return 0;
- case 7: // STARTS
- Con_print_start_menu();
- return 0;
- case 8: // START
- case 18: // S (same as START)
- Con_start(&input[1][0]);
- // force the palette
- g_display->setPalette(187, 1, pal, RDPAL_INSTANT);
- return 0;
- case 9: // INFO
- displayDebugText = 1 - displayDebugText;
- if (displayDebugText)
- Print_to_console("info text on");
- else
- Print_to_console("info text off");
- return 0;
- case 10: // WALKGRID
- displayWalkGrid = 1 - displayWalkGrid;
- if (displayWalkGrid)
- Print_to_console("walk-grid display on");
- else
- Print_to_console("walk-grid display off");
- return 0;
- case 11: // MOUSE
- displayMouseMarker = 1 - displayMouseMarker;
- if (displayMouseMarker)
- Print_to_console("mouse marker on");
- else
- Print_to_console("mouse marker off");
- return 0;
- case 12: // PLAYER
- displayPlayerMarker = 1 - displayPlayerMarker;
- if (displayPlayerMarker)
- Print_to_console("player feet marker on");
- else
- Print_to_console("player feet marker off");
- return 0;
- case 13: // RESLOOK
- res_man.examine(&input[1][0]);
- return 0;
- case 14: // CUR
- Print_current_info();
- return 0;
- case 15: // RUNLIST
- g_logic.examineRunList();
- return 0;
- case 16: // KILL
- res_man.kill(&input[1][0]);
- return 0;
- case 17: // NUKE
- Print_to_console("killing all resources except variable file & player object...");
- // '1' means we want output to console
- res_man.killAll(1);
- return 0;
- case 19: // VAR
- if (total_commands == 2)
- Var_check(&input[1][0]);
- else
- Var_set(&input[1][0], &input[2][0]);
- return 0;
- case 20: // RECT
- definingRectangles = 1 - definingRectangles;
- if (definingRectangles)
- Print_to_console("mouse rectangles enabled");
- else
- Print_to_console("mouse rectangles disabled");
- // reset (see debug.cpp & mouse.cpp)
- draggingRectangle = 0;
- return 0;
- case 21: // CLEAR
- Print_to_console("killing all object resources except player...");
- // '1' means we want output to console
- res_man.killAllObjects(1);
- return 0;
- case 22: // DEBUGON
- displayDebugText = 1;
- displayWalkGrid = 1;
- displayMouseMarker = 1;
- displayPlayerMarker = 1;
- displayTextNumbers = 1;
-
- Print_to_console("enabled all on-screen debug info");
- return 0;
- case 23: // DEBUGOFF
- displayDebugText = 0;
- displayWalkGrid = 0;
- displayMouseMarker = 0;
- displayPlayerMarker = 0;
- displayTextNumbers = 0;
- definingRectangles = 0;
- draggingRectangle = 0;
-
- Print_to_console("disabled all on-screen debug info");
- return 0;
- case 24: // SAVEREST
- testingSnR = 1 - testingSnR;
- if (testingSnR)
- Print_to_console("Enabled S&R logic_script stability checking");
- else
- Print_to_console("Disabled S&R logic_script stability checking");
- return 0;
- case 25: // SAVES
- Print_to_console("Savegames:");
- Con_list_savegames();
- return 0;
- case 26: // SAVE <slotNo> <description>
- Con_save_game(total_commands, &input[1][0], &input[2][0]);
- return 0;
- case 27: // RESTORE <slotNo>
- Con_restore_game(total_commands, &input[1][0]);
-
- // quit the console
- return 1;
- case 28: // BLTFXON
- SetBltFx();
- Print_to_console("blit fx enabled");
- return 0;
- case 29: // BLTFXOFF
- ClearBltFx();
- Print_to_console("blit fx disabled");
- return 0;
- case 30: // TIMEON
- Con_start_timer(total_commands, &input[1][0]);
- Print_to_console("timer display on");
- return 0;
- case 31: // TIMEOFF
- displayTime = 0;
- Print_to_console("timer display off");
- return 0;
- case 32: // TEXT
- displayTextNumbers = 1 - displayTextNumbers;
- if (displayTextNumbers)
- Print_to_console("text numbers on");
- else
- Print_to_console("text numbers off");
- return 0;
- case 33: // SHOWVAR <varNo>
- // add variable to watch-list
- ShowVar(&input[1][0]);
- return 0;
- case 34: // HIDEVAR <varNo>
- // remove variable from watch-list
- HideVar(&input[1][0]);
- return 0;
- case 35: // VERSION
- Con_display_version();
- return 0;
- case 36: // SOFT
- case 37: // HARD
- // ScummVM doesn't distinguish between
- // software and hardware rendering
- Print_to_console("This command is no longer relevant");
- return 0;
- case 38: // ANIMTEST
- // automatically do "s 32" to run the
- // text/speech testing start-script
-
- Con_start((uint8 *) "32");
- Print_to_console("Setting flag 'system_testing_anims'");
-
- // same as typing "VAR 912 <value>" at
- // the console
-
- Var_set((uint8 *) "912", &input[1][0]);
- return 1;
- case 39: // TEXTTEST
- // automatically do "s 33" to run the
- // text/speech testing start-script
-
- Con_start((uint8 *) "33");
-
- Print_to_console("Setting flag 'system_testing_text'");
-
- // same as typing "VAR 1230 <value>" at
- // the console
- Var_set((uint8 *) "1230", &input[1][0]);
-
- displayTextNumbers = 1;
- Print_to_console("text numbers on");
- return 1;
- case 40: // LINETEST
- // automatically do "s 33" to run the
- // text/speech testing start-script
-
- Con_start((uint8 *) "33");
-
- Print_to_console("Setting var 1230 (system_testing_text):");
-
- // same as typing "VAR 1230 <value>" at
- // the console
- Var_set((uint8 *) "1230", &input[1][0]);
-
- Print_to_console("Setting var 1264 (system_test_line_no):");
-
- // same as typing "VAR 1264 <value>" at
- // the console
- Var_set((uint8 *) "1264", &input[2][0]);
-
- displayTextNumbers = 1;
- Print_to_console("text numbers on");
- return 1;
- case 41: // GRAB
- grabbingSequences = 1 - grabbingSequences;
- if (grabbingSequences)
- Print_to_console("PCX-grabbing enabled");
- else
- Print_to_console("PCX-grabbing disabled");
- return 0;
- case 42: // EVENTS
- Con_display_events();
- return 0;
- case 43: // SFX
- wantSfxDebug = 1 - wantSfxDebug;
- if (wantSfxDebug)
- Print_to_console("SFX logging activated (see zebug.txt)");
- else
- Print_to_console("SFX logging deactivated");
- return 0;
- case 44: // ENGLISH
- initialiseFontResourceFlags(DEFAULT_TEXT);
- Print_to_console("Default fonts selected");
- return 0;
- case 45: // FINNISH
- initialiseFontResourceFlags(FINNISH_TEXT);
- Print_to_console("Finnish fonts selected");
- return 0;
- case 46: // POLISH
- initialiseFontResourceFlags(POLISH_TEXT);
- Print_to_console("Polish fonts selected");
- return 0;
- default:
- Print_to_console("??");
- return 0;
- }
- break;
- case 1:
- // checks for YES and NO and returns the 1 or
- // 2 to the calling code
- switch (j) {
- case 4: // YES
- return 1;
- case 5: // NO
- return 2;
- default:
- Print_to_console("??");
- return 0;
- }
- break;
- }
- break;
- }
- }
+bool Debugger::Cmd_RunList(int argc, const char **argv) {
+ g_logic.examineRunList();
+ return true;
+}
- Print_to_console("?"); //couldn't find a proper match
- return 0;
+bool Debugger::Cmd_Kill(int argc, const char **argv) {
+ if (argc != 2)
+ Debug_Printf("Usage: %s number\n", argv[0]);
+ else
+ res_man.kill(atoi(argv[1]));
+ return true;
}
-void Con_help(void) {
- // print out a list of commands
+bool Debugger::Cmd_Nuke(int argc, const char **argv) {
+ Debug_Printf("Killing all resources except variable file and player object\n");
+ res_man.killAll(true);
+ return true;
+}
- int command;
- int scrolls = 0;
- char c;
+bool Debugger::Cmd_Var(int argc, const char **argv) {
+ switch (argc) {
+ case 2:
+ Var_check(atoi(argv[1]));
+ break;
+ case 3:
+ Var_set(atoi(argv[1]), atoi(argv[2]));
+ break;
+ default:
+ Debug_Printf("Usage: %s number value\n", argv[0]);
+ break;
+ }
- Scroll_console();
+ return true;
+}
- for (command = 0; command < TOTAL_CONSOLE_COMMANDS; command++) {
- Print_to_console((char *) commands[command]);
- Build_display();
- scrolls++;
+bool Debugger::Cmd_Rect(int argc, const char **argv) {
+ definingRectangles = !definingRectangles;
- if (scrolls == 18) {
- Temp_print_to_console("- Press ESC to stop or any other key to continue");
- Build_display();
+ if (definingRectangles)
+ Debug_Printf("Mouse rectangles enabled\n");
+ else
+ Debug_Printf("Mouse rectangles disabled\n");
- do {
- g_display->updateDisplay();
- } while (!KeyWaiting());
+ draggingRectangle = 0;
+ return true;
+}
- ReadKey(&c);
- if (c == 27)
- break;
+bool Debugger::Cmd_Clear(int argc, const char **argv) {
+ res_man.killAllObjects(true);
+ return true;
+}
- // clear the Press Esc message ready for the new line
- Clear_console_line();
- scrolls = 0;
- }
- }
+bool Debugger::Cmd_DebugOn(int argc, const char **argv) {
+ displayDebugText = true;
+ displayWalkGrid = true;
+ displayMouseMarker = true;
+ displayPlayerMarker = true;
+ displayTextNumbers = true;
+ Debug_Printf("Enabled all on-screen debug info\n");
+ return true;
}
-void Con_print(uint8 *ascii, uint32 pen, uint32 paper) {
- // print pixels in closen pen number - no clipping on this one
- // where file is the graphic file of ascii characters
+bool Debugger::Cmd_DebugOff(int argc, const char **argv) {
+ displayDebugText = false;
+ displayWalkGrid = false;
+ displayMouseMarker = false;
+ displayPlayerMarker = false;
+ displayTextNumbers = false;
+ Debug_Printf("Disabled all on-screen debug info\n");
+ return true;
+}
- _frameHeader *head;
- uint8 *charSet, *charPtr;
- int chr, x = 0;
+bool Debugger::Cmd_SaveRest(int argc, const char **argv) {
+ testingSnR = !testingSnR;
- // open font file
- charSet = res_man.open(CONSOLE_FONT_ID);
+ if (testingSnR)
+ Debug_Printf("Enabled S&R logic_script stability checking\n");
+ else
+ Debug_Printf("Disabled S&R logic_script stability checking\n");
- do {
- chr = (int) *(ascii);
- chr -= 32;
+ return true;
+}
- head = (_frameHeader *) FetchFrameHeader(charSet, chr);
- charPtr = (uint8 *) (head + 1);
+bool Debugger::Cmd_ListSaveGames(int argc, const char **argv) {
+ Debug_Printf("Savegames:\n");
- Con_colour_block( x, head->width, head->height, pen, paper, charPtr);
+ for (int i = 0; i < 100; i++) {
+ uint8 description[SAVE_DESCRIPTION_LEN];
- x += head->width + 1;
- ascii++;
- } while(*(ascii));
+ // if there is a save game print the name
+ if (GetSaveDescription(i, description) == SR_OK)
+ Debug_Printf("%d: \"%s\"\n", i, description);
+ }
- // close font file
- res_man.close(CONSOLE_FONT_ID);
+ return true;
}
-void Con_colour_block(int x, int width, int height, uint32 pen, uint32 paper, uint8 *sprite_data_ad) {
- int deltaX, xx, yy;
- char *ad;
+bool Debugger::Cmd_SaveGame(int argc, const char **argv) {
+ char description[SAVE_DESCRIPTION_LEN];
+ int len = 0;
+ uint16 slotNo;
+ uint32 rv;
+
+ if (argc < 3) {
+ Debug_Printf("Usage: %s slot description\n", argv[0]);
+ return true;
+ }
- deltaX = con_width - width;
+ // if mouse if off, or system menu is locked off
+ if (mouse_status || mouse_mode_locked) {
+ Debug_Printf("WARNING: Cannot save game while control menu unavailable!\n");
+ return true;
+ }
+
+ description[0] = 0;
- ad = (char *) console_sprite->ad;
+ // FIXME: Strange things seem to happen if use too long savegame names,
+ // even when they're shorter than the maximum allowed length
- // locate bottom character row
- ad += (con_width * (con_depth - con_chr_height)) + x;
+ for (int i = 2; i < argc; i++) {
+ if (len + strlen(argv[i]) + 1 > SAVE_DESCRIPTION_LEN)
+ break;
- for (yy = 0; yy < height; yy++) {
- for (xx = 0; xx < width; xx++) {
- if (pen = *(sprite_data_ad++)) //color
- *(ad++)= (uint8) CON_PEN;
- else *(ad++)= (uint8) paper;
+ if (i == 2) {
+ strcpy(description, argv[i]);
+ len = strlen(argv[i]);
+ } else {
+ strcat(description, " ");
+ strcat(description, argv[i]);
+ len += (strlen(argv[i]) + 1);
}
- ad += deltaX;
}
-}
-
-void Con_fatal_error(const char *format, ...) {
- // Use this to alert the user of a major problem from which we cannot
- // allow the game to continue. While in console mode the user will
- // still be ble to use the console commands - which may be useful.
- // This message is also written with debug() in case the console
- // itself blows up
- va_list arg_ptr;
- char buf[150];
- uint8 white[4] = { 255, 255, 255, 0 };
+ slotNo = atoi(argv[1]);
+ rv = SaveGame(slotNo, (uint8 *) description);
- // set text colour in case screen is faded down!
- g_display->setPalette(CON_PEN, 1, white, RDPAL_INSTANT);
+ if (rv == SR_OK)
+ Debug_Printf("Saved game \"%s\" to file \"savegame.%.3d\"\n", description, slotNo);
+ else if (rv == SR_ERR_FILEOPEN)
+ Debug_Printf("ERROR: Cannot open file \"savegame.%.3d\"\n", slotNo);
+ else // SR_ERR_WRITEFAIL
+ Debug_Printf("ERROR: Write error on file \"savegame.%.3d\"\n", slotNo);
- va_start(arg_ptr,format);
- _vsnprintf(buf, 150, format, arg_ptr);
-
- this_screen.background_layer_id = 0; //in case error in display loop
+ return true;
+}
- // write to file first in-case the screen is screwed up and we never
- // see the console
+bool Debugger::Cmd_RestoreGame(int argc, const char **argv) {
+ uint16 slotNo;
+ uint8 description[SAVE_DESCRIPTION_LEN];
+ uint32 rv;
- debug(5, "CON_FATAL_ERROR: %s", buf);
+ if (argc != 2) {
+ Debug_Printf("Usage: %s slot\n", argv[0]);
+ return true;
+ }
- Print_to_console(buf);
- Print_to_console("fatal error, sword2 must terminate :-( (%d)", ID);
+ // if mouse if off, or system menu is locked off
+ if (mouse_status || mouse_mode_locked) {
+ Debug_Printf("WARNING: Cannot restore game while control menu unavailable!\n");
+ return true;
+ }
- //mode 0 so all commands are available but quit will terminate the game
- Tconsole(0);
+ slotNo = atoi(argv[1]);
+ rv = RestoreGame(slotNo);
- Close_game(); // should down game services - free's mallocs, etc.
- CloseAppWindow();
+ if (rv == SR_OK) {
+ GetSaveDescription(slotNo, description);
+ Debug_Printf("Restored game \"%s\" from file \"savegame.%.3d\"\n", description, slotNo);
+ } else if (rv == SR_ERR_FILEOPEN)
+ Debug_Printf("ERROR: Cannot open file \"savegame.%.3d\"\n", slotNo);
+ else if (rv == SR_ERR_INCOMPATIBLE)
+ Debug_Printf("ERROR: \"savegame.%.3d\" is no longer compatible with current player/variable resources\n", slotNo);
+ else // SR_ERR_READFAIL
+ Debug_Printf("ERROR: Read error on file \"savegame.%.3d\"\n", slotNo);
- exit 0;
+ return true;
}
-void Var_check(uint8 *pointer) {
- int var;
+// FIXME: Replace these with a command to modify the graphics detail setting
- sscanf((char *) pointer, "%d", &var);
+bool Debugger::Cmd_BltFxOn(int argc, const char **argv) {
+ // g_display->setBltFx();
+ // Debug_Printf("Blit fx enabled\n");
+ Debug_Printf("FIXME: The setBltFx() function no longer exists\n");
+ return true;
+}
- Print_to_console("%d", *(uint32 *) (res_man._resList[1]->ad + sizeof(_standardHeader) + 4 * var));
+bool Debugger::Cmd_BltFxOff(int argc, const char **argv) {
+ // g_display->clearBltFx();
+ // Debug_Printf("Blit fx disabled\n");
+ Debug_Printf("FIXME: The clearBltFx() function no longer exists\n");
+ return true;
}
-void Var_set(uint8 *pointer, uint8 *p2) {
- int var;
- int val;
+bool Debugger::Cmd_TimeOn(int argc, const char **argv) {
+ if (argc == 2)
+ startTime = SVM_timeGetTime() - atoi(argv[1]) * 1000;
+ else if (startTime == 0)
+ startTime = SVM_timeGetTime();
+ displayTime = true;
+ Debug_Printf("Timer display on\n");
+ return true;
+}
- sscanf((char *) pointer, "%d", &var);
- sscanf((char *) p2, "%d", &val);
+bool Debugger::Cmd_TimeOff(int argc, const char **argv) {
+ displayTime = false;
+ Debug_Printf("Timer display off\n");
+ return true;
+}
- Print_to_console("was %d", *(uint32 *) (res_man._resList[1]->ad + sizeof(_standardHeader) + 4 * var));
+bool Debugger::Cmd_Text(int argc, const char **argv) {
+ displayTextNumbers = !displayTextNumbers;
- *(uint32 *) (res_man._resList[1]->ad + sizeof(_standardHeader) + 4 * var) = val;
+ if (displayTextNumbers)
+ Debug_Printf("Text numbers on\n");
+ else
+ Debug_Printf("Text numbers off\n");
- Print_to_console("now %d", val);
+ return true;
}
-void ShowVar(uint8 *varNoPtr) {
+bool Debugger::Cmd_ShowVar(int argc, const char **argv) {
int32 showVarNo = 0;
int32 varNo;
-
- // 'varNo' is what we want to add
- sscanf((char *) varNoPtr, "%d", &varNo);
+ if (argc != 2) {
+ Debug_Printf("Usage: %s number\n", argv[0]);
+ return true;
+ }
+
+ varNo = atoi(argv[1]);
+
// search for a spare slot in the watch-list, but also watch out for
// this variable already being in the list
@@ -868,20 +642,26 @@ void ShowVar(uint8 *varNoPtr) {
if (showVar[showVarNo] == 0) {
// empty slot - add it to the list at this slot
showVar[showVarNo] = varNo;
- Print_to_console("var(%d) added to the watch-list", varNo);
+ Debug_Printf("var(%d) added to the watch-list\n", varNo);
} else
- Print_to_console("var(%d) already in the watch-list!", varNo);
+ Debug_Printf("var(%d) already in the watch-list!\n", varNo);
} else
- Print_to_console("Sorry - no more allowed - hide one or extend the system watch-list");
+ Debug_Printf("Sorry - no more allowed - hide one or extend the system watch-list\n");
+
+ return true;
}
-void HideVar(uint8 *varNoPtr) {
+bool Debugger::Cmd_HideVar(int argc, const char **argv) {
int32 showVarNo = 0;
int32 varNo;
-
- // 'varNo' is what we want to remove
- sscanf((char *) varNoPtr, "%d", &varNo);
+ if (argc != 2) {
+ Debug_Printf("Usage: %s number\n", argv[0]);
+ return true;
+ }
+
+ varNo = atoi(argv[1]);
+
// search for 'varNo' in the watch-list
while (showVarNo < MAX_SHOWVARS && showVar[showVarNo] != varNo)
showVarNo++;
@@ -889,186 +669,237 @@ void HideVar(uint8 *varNoPtr) {
if (showVarNo < MAX_SHOWVARS) {
// We've found 'varNo' in the list - clear this slot
showVar[showVarNo] = 0;
- Print_to_console("var(%d) removed from watch-list", varNo);
+ Debug_Printf("var(%d) removed from watch-list\n", varNo);
} else
- Print_to_console("Sorry - can't find var(%d) in the list", varNo);
+ Debug_Printf("Sorry - can't find var(%d) in the list\n", varNo);
+
+ return true;
}
-void Con_list_savegames(void) {
- uint8 description[SAVE_DESCRIPTION_LEN];
- int j, scrolls = 0;
- char c;
+bool Debugger::Cmd_Version(int argc, const char **argv) {
- for (j = 0; j < 100; j++) {
- // if there is a save game print the name
- if (GetSaveDescription(j, description) == SR_OK) {
- Print_to_console("%d: \"%s\"", j, description);
+ // The version string is incomplete, so we may as well remove the code
+ // to extract information from it.
- scrolls++;
- Build_display();
+#if 0
- if (scrolls == 18) {
- Temp_print_to_console("- Press ESC to stop or any other key to continue");
- Build_display();
+ #define HEAD_LEN 8
- do {
- g_display->updateDisplay();
- } while (!KeyWaiting());
+ // version & owner details
- ReadKey(&c);
- if (c == 27)
- break;
+ // So version string is 18 bytes long :
+ // Version String = <8 byte header,5 character version, \0, INT32 time>
+ uint8 version_string[HEAD_LEN + 10] = { 1, 255, 37, 22, 45, 128, 34, 67 };
+ uint8 unencoded_name[HEAD_LEN + 48] = {
+ 76, 185, 205, 23, 44, 34, 24, 34,
+ 'R','e','v','o','l','u','t','i','o','n',' ',
+ 'S','o','f','t','w','a','r','e',' ','L','t','d',
+ 0 };
- // clear the Press Esc message ready for the
- // new line
- Clear_console_line();
- scrolls = 0;
- }
- }
+ struct tm *time;
+ time_t t;
+ char dateStamp[255];
+ char version[6];
+
+ strcpy(version, (char*) version_string + HEAD_LEN);
+ *(((unsigned char *) &t)) = *(version_string + 14);
+ *(((unsigned char *) &t) + 1) = *(version_string + 15);
+ *(((unsigned char *) &t) + 2) = *(version_string + 16);
+ *(((unsigned char *) &t) + 3) = *(version_string + 17);
+
+ time = localtime(&t);
+ sprintf(dateStamp, "%s", asctime(time));
+ dateStamp[24] = 0; // fudge over the newline character!
+#endif
+
+ Debug_Printf("\"Broken Sword II\" (c) Revolution Software 1997.\n");
+
+#if 0
+ Debug_Printf("v%s created on %s for %s\n", version, dateStamp, unencoded_name + HEAD_LEN);
+#endif
+
+#if 0
+ // THE FOLLOWING LINES ARE TO BE COMMENTED OUT OF THE FINAL VERSION
+ Debug_Printf("This program has a personalised fingerprint encrypted into the code.\n");
+ Debug_Printf("If this CD was not sent directly to you by Virgin Interactive or Revolution Software\n");
+ Debug_Printf("then please contact James Long at Revolution on (+44) 1904 639698.\n");
+#endif
+
+ return true;
}
-void Con_save_game(int total_commands, uint8 *slotString, uint8 *description) {
- uint16 slotNo;
- uint32 rv;
+bool Debugger::Cmd_SoftHard(int argc, const char **argv) {
+ Debug_Printf("ScummVM doesn't distinguish between software and hardware rendering.\n");
+ return true;
+}
- // if mouse if off, or system menu is locked off
- if (mouse_status || mouse_mode_locked) {
- Print_to_console("WARNING: Cannot save game while control menu unavailable!");
- return;
+bool Debugger::Cmd_AnimTest(int argc, const char **argv) {
+ if (argc != 2) {
+ Debug_Printf("Usage: %s value\n", argv[0]);
+ return true;
}
- if (total_commands >= 3) {
- // SAVE <slot> <description>
- if (Is_number(slotString)) {
- slotNo = atoi((char *) slotString);
- rv = SaveGame(slotNo,description);
-
- if (rv == SR_OK)
- Print_to_console("Saved game \"%s\" to file \"savegame.%.3d\"", description, slotNo);
- else if (rv == SR_ERR_FILEOPEN)
- Print_to_console("ERROR: Cannot open file \"savegame.%.3d\"", slotNo);
- else // SR_ERR_WRITEFAIL
- Print_to_console("ERROR: Write error on file \"savegame.%.3d\"", slotNo);
- }
- } else
- Print_to_console("Syntax Error: type SAVE (slot_number) (description)");
-}
+ // Automatically do "s 32" to run the animation testing start script
+ Con_start(32);
-void Con_restore_game(int total_commands, uint8 *slotString) {
- uint16 slotNo;
- uint8 description[SAVE_DESCRIPTION_LEN];
- uint32 rv;
+ // Same as typing "VAR 912 <value>" at the console
+ Var_set(912, atoi(argv[1]));
- // if mouse if off, or system menu is locked off
- if (mouse_status || mouse_mode_locked) {
- Print_to_console("WARNING: Cannot restore game while control menu unavailable!");
- return;
+ Debug_Printf("Setting flag 'system_testing_anims'\n");
+ return true;
+}
+
+bool Debugger::Cmd_TextTest(int argc, const char **argv) {
+ if (argc != 2) {
+ Debug_Printf("Usage: %s value\n", argv[0]);
+ return true;
}
- if (total_commands >= 2) {
- // RESTORE <slot>
- if (Is_number(slotString)) {
- slotNo = atoi((char *) slotString);
- rv = RestoreGame(slotNo);
+ // Automatically do "s 33" to run the text/speech testing start script
+ Con_start(33);
- if (rv == SR_OK) {
- GetSaveDescription(slotNo, description);
- Print_to_console("Restored game \"%s\" from file \"savegame.%.3d\"", description, slotNo);
- } else if (rv == SR_ERR_FILEOPEN)
- Print_to_console("ERROR: Cannot open file \"savegame.%.3d\"", slotNo);
+ // Same as typing "VAR 1230 <value>" at the console
+ Var_set(1230, atoi(argv[1]));
- else if (rv == SR_ERR_INCOMPATIBLE)
- Print_to_console("ERROR: \"savegame.%.3d\" is no longer compatible with current player/variable resources", slotNo);
+ displayTextNumbers = true;
- else // SR_ERR_READFAIL
- Print_to_console("ERROR: Read error on file \"savegame.%.3d\"", slotNo);
- }
- } else
- Print_to_console("Syntax Error: type RESTORE (slot_number)");
+ Debug_Printf("Setting flag 'system_testing_text'\n");
+ Debug_Printf("Text numbers on\n");
+ return true;
}
-void Con_start_timer(int total_commands, uint8 *slotString) {
- if (total_commands >= 2) {
- if (Is_number(slotString)) {
- startTime = timeGetTime() - (atoi((char *) slotString) * 1000);
- }
- } else {
- if (startTime = 0)
- startTime = timeGetTime();
+bool Debugger::Cmd_LineTest(int argc, const char **argv) {
+ if (argc != 3) {
+ Debug_Printf("Usage: %s value1 value2\n", argv[0]);
+ return true;
}
- displayTime = 1;
+
+ // Automatically do "s 33" to run the text/speech testing start script
+ Con_start(33);
+
+ // Same as typing "VAR 1230 <value>" at the console
+ Var_set(1230, atoi(argv[1]));
+
+ // Same as typing "VAR 1264 <value>" at the console
+ Var_set(1264, atoi(argv[2]));
+
+ displayTextNumbers = true;
+
+ Debug_Printf("Setting flag 'system_testing_text'\n");
+ Debug_Printf("Setting flag 'system_test_line_no'\n");
+ Debug_Printf("Text numbers on\n");
+ return true;
}
-uint8 Is_number(uint8 *ascii) {
- // until we reach the null terminator
- while (*ascii) {
- if (*ascii >= '0' && *ascii <= '9')
- ascii++;
- else
- return 0;
+bool Debugger::Cmd_Grab(int argc, const char **argv) {
+ Debug_Printf("FIXME: Continuous screen-grabbing not implemented\n");
+
+#if 0
+ grabbingSequences = !grabbingSequences;
+
+ if (grabbingSequences)
+ Debug_Printf("PCX-grabbing enabled\n");
+ else
+ Debug_Printf("PCX-grabbing disabled\n");
+#endif
+
+ return true;
+}
+
+bool Debugger::Cmd_Events(int argc, const char **argv) {
+ Debug_Printf("EVENT LIST:\n");
+
+ for (uint32 i = 0; i < MAX_events; i++) {
+ if (event_list[i].id) {
+ uint32 target = event_list[i].id;
+ uint32 script = event_list[i].interact_id;
+
+ Debug_Printf("slot %d: id = %s (%d)\n", i, FetchObjectName(target), target);
+ Debug_Printf(" script = %s (%d) pos %d\n", FetchObjectName(script / 65536), script / 65536, script % 65536);
+ }
}
- return 1;
+ return true;
}
-void Con_display_version(void) {
- struct tm *time;
- time_t t;
- char dateStamp[255];
- char version[6];
+bool Debugger::Cmd_Sfx(int argc, const char **argv) {
+ wantSfxDebug = !wantSfxDebug;
- strcpy(version, (char*) version_string + HEAD_LEN);
- *(((unsigned char *) &t)) = *(version_string + 14);
- *(((unsigned char *) &t) + 1) = *(version_string + 15);
- *(((unsigned char *) &t) + 2) = *(version_string + 16);
- *(((unsigned char *) &t) + 3) = *(version_string + 17);
+ if (wantSfxDebug)
+ Debug_Printf("SFX logging activated\n");
+ else
+ Debug_Printf("SFX logging deactivated\n");
- time = localtime(&t);
- sprintf(dateStamp, "%s", asctime(time));
- dateStamp[24] = 0; // fudge over the newline character!
+ return true;
+}
- Print_to_console("\"Broken Sword II\" (c) Revolution Software 1997.");
- Print_to_console("v%s created on %s for %s", version, dateStamp, unencoded_name + HEAD_LEN);
- Scroll_console();
+bool Debugger::Cmd_English(int argc, const char **argv) {
+ g_sword2->initialiseFontResourceFlags(DEFAULT_TEXT);
+ Debug_Printf("Default fonts selected\n");
+ return true;
+}
- // THE FOLLOWING LINES ARE TO BE COMMENTED OUT OF THE FINAL VERSION
- // Print_to_console("This program has a personalised fingerprint encrypted into the code.");
- // Print_to_console("If this CD was not sent directly to you by Virgin Interactive or Revolution Software");
- // Print_to_console("then please contact James Long at Revolution on (+44) 1904 639698.");
- // Scroll_console();
+bool Debugger::Cmd_Finnish(int argc, const char **argv) {
+ g_sword2->initialiseFontResourceFlags(FINNISH_TEXT);
+ Debug_Printf("Finnish fonts selected\n");
+ return true;
}
-void Con_display_events() {
- uint32 j;
- uint32 target;
- uint32 script;
+bool Debugger::Cmd_Polish(int argc, const char **argv) {
+ g_sword2->initialiseFontResourceFlags(POLISH_TEXT);
+ Debug_Printf("Polish fonts selected\n");
+ return true;
+}
- Print_to_console("EVENT LIST:");
+// returns true if something has been completed
+// completion has to be delete[]-ed then
+bool Debugger::TabComplete(const char *input, char*& completion) {
+ // very basic tab completion
+ // for now it just supports command completions
- for (j = 0; j < MAX_events; j++) {
- if (event_list[j].id) {
- target = event_list[j].id;
- script = event_list[j].interact_id;
+ // adding completions of command parameters would be nice (but hard) :-)
+ // maybe also give a list of possible command completions?
+ // (but this will require changes to console)
- Print_to_console("slot %d: id = %s (%d)", j, FetchObjectName(target), target);
- Print_to_console(" script = %s (%d) pos %d", FetchObjectName(script / 65536), script / 65536, script % 65536);
- }
- }
-}
+ if (strchr(input, ' '))
+ return false; // already finished the first word
-} // End of namespace Sword2
+ unsigned int inputlen = strlen(input);
-#else
+ unsigned int matchlen = 0;
+ char match[30]; // the max. command name is 30 chars
-namespace Sword2 {
+ for (int i = 0; i < _dcmd_count; i++) {
+ if (!strncmp(_dcmds[i].name, input, inputlen)) {
+ unsigned int commandlen = strlen(_dcmds[i].name);
+ if (commandlen == inputlen) { // perfect match
+ return false;
+ }
+ if (commandlen > inputlen) { // possible match
+ // no previous match
+ if (matchlen == 0) {
+ strcpy(match, _dcmds[i].name + inputlen);
+ matchlen = commandlen - inputlen;
+ } else {
+ // take common prefix of previous match and this command
+ unsigned int j;
+ for (j = 0; j < matchlen; j++) {
+ if (match[j] != _dcmds[i].name[inputlen + j]) break;
+ }
+ matchlen = j;
+ }
+ if (matchlen == 0)
+ return false;
+ }
+ }
+ }
+ if (matchlen == 0)
+ return false;
-void Print_to_console(const char *format, ...) {}
-void Temp_print_to_console(const char *format, ...) {}
-void Clear_console_line(void) {}
-void Scroll_console(void) {}
-void Init_console(void) {}
-void StartConsole(void) {}
+ completion = new char[matchlen + 1];
+ memcpy(completion, match, matchlen);
+ completion[matchlen] = 0;
+ return true;
+}
} // End of namespace Sword2
-
-#endif
diff --git a/sword2/console.h b/sword2/console.h
index 9f8b5e975d..afe3fa7480 100644
--- a/sword2/console.h
+++ b/sword2/console.h
@@ -20,49 +20,121 @@
#ifndef C_ONSOLE_H
#define C_ONSOLE_H
-#include "bs2/driver/driver96.h"
#include "bs2/memory.h"
-namespace Sword2 {
-
-#ifdef _SWORD2_DEBUG
-
-void Init_console(void);
-uint32 One_console(void);
-void StartConsole(void);
-void EndConsole(void);
-
-void Con_fatal_error(const char *format, ...);
-void Print_to_console(const char *format, ...);
-void Temp_print_to_console(const char *format, ...);
-void Scroll_console(void);
-void Clear_console_line(void);
-
-extern mem *console_sprite;
-extern uint32 con_y;
-extern uint32 con_depth;
-extern uint32 con_width;
-
-extern uint8 grabbingSequences;
-extern uint8 wantSfxDebug; // sfx debug file enabled/disabled from console
+// Choose between text console or graphical console
+#define USE_CONSOLE 1
+#if USE_CONSOLE
+ #include "gui/console.h"
+ #define Debug_Printf g_sword2->_debuggerDialog->printf
#else
+ #define Debug_Printf printf
+#endif
-void Init_console(void);
-uint32 One_console(void);
-void StartConsole(void);
-void EndConsole(void);
-
-#define Con_fatal_error error
-
-void Print_to_console(const char *format, ...);
-void Temp_print_to_console(const char *format, ...);
-void Clear_console_line(void);
-void Scroll_console(void);
+namespace Sword2 {
+extern bool grabbingSequences;
+extern bool wantSfxDebug; // sfx debug file enabled/disabled from console
+
+class Sword2Engine;
+class Debugger;
+
+typedef bool (Debugger::*DebugProc)(int argc, const char **argv);
+
+enum {
+ DVAR_INT,
+ DVAR_BOOL,
+ DVAR_INTARRAY,
+ DVAR_STRING
+};
+
+struct DVar {
+ char name[30];
+ void *variable;
+ int type, optional;
+};
+
+struct DCmd {
+ char name[30];
+ DebugProc function;
+};
+
+class Debugger {
+public:
+ Debugger(Sword2Engine *s);
+
+ void onFrame();
+ void attach(const char *entry = 0);
+
+ bool isAttached() const { return _isAttached; }
+
+protected:
+ Sword2Engine *_vm;
+ int _frame_countdown, _dcmd_count;
+ DCmd _dcmds[256];
+ bool _detach_now;
+ bool _isAttached;
+ char *_errStr;
+
+ void enter();
+ void detach();
+
+ void DCmd_Register(const char *cmdname, DebugProc pointer);
+ bool RunCommand(const char *input);
+
+ // Commands
+ bool Cmd_Exit(int argc, const char **argv);
+ bool Cmd_Help(int argc, const char **argv);
+ bool Cmd_Mem(int argc, const char **argv);
+ bool Cmd_Tony(int argc, const char **argv);
+ bool Cmd_Res(int argc, const char **argv);
+ bool Cmd_Starts(int argc, const char **argv);
+ bool Cmd_Start(int argc, const char **argv);
+ bool Cmd_Info(int argc, const char **argv);
+ bool Cmd_WalkGrid(int argc, const char **argv);
+ bool Cmd_Mouse(int argc, const char **argv);
+ bool Cmd_Player(int argc, const char **argv);
+ bool Cmd_ResLook(int argc, const char **argv);
+ bool Cmd_CurrentInfo(int argc, const char **argv);
+ bool Cmd_RunList(int argc, const char **argv);
+ bool Cmd_Kill(int argc, const char **argv);
+ bool Cmd_Nuke(int argc, const char **argv);
+ bool Cmd_Var(int argc, const char **argv);
+ bool Cmd_Rect(int argc, const char **argv);
+ bool Cmd_Clear(int argc, const char **argv);
+ bool Cmd_DebugOn(int argc, const char **argv);
+ bool Cmd_DebugOff(int argc, const char **argv);
+ bool Cmd_SaveRest(int argc, const char **argv);
+ bool Cmd_ListSaveGames(int argc, const char **argv);
+ bool Cmd_SaveGame(int argc, const char **argv);
+ bool Cmd_RestoreGame(int argc, const char **argv);
+ bool Cmd_BltFxOn(int argc, const char **argv);
+ bool Cmd_BltFxOff(int argc, const char **argv);
+ bool Cmd_TimeOn(int argc, const char **argv);
+ bool Cmd_TimeOff(int argc, const char **argv);
+ bool Cmd_Text(int argc, const char **argv);
+ bool Cmd_ShowVar(int argc, const char **argv);
+ bool Cmd_HideVar(int argc, const char **argv);
+ bool Cmd_Version(int argc, const char **argv);
+ bool Cmd_SoftHard(int argc, const char **argv);
+ bool Cmd_AnimTest(int argc, const char **argv);
+ bool Cmd_TextTest(int argc, const char **argv);
+ bool Cmd_LineTest(int argc, const char **argv);
+ bool Cmd_Grab(int argc, const char **argv);
+ bool Cmd_Events(int argc, const char **argv);
+ bool Cmd_Sfx(int argc, const char **argv);
+ bool Cmd_English(int argc, const char **argv);
+ bool Cmd_Finnish(int argc, const char **argv);
+ bool Cmd_Polish(int argc, const char **argv);
+
+#if USE_CONSOLE
+ static bool debuggerInputCallback(ConsoleDialog *console, const char *input, void *refCon);
+ static bool debuggerCompletionCallback(ConsoleDialog *console, const char *input, char*& completion, void *refCon);
#endif
-extern uint32 console_status;
+ bool TabComplete(const char *input, char*& completion);
+};
} // End of namespace Sword2
diff --git a/sword2/controls.cpp b/sword2/controls.cpp
index 7f48ad8b4d..9ece464b72 100644
--- a/sword2/controls.cpp
+++ b/sword2/controls.cpp
@@ -1335,7 +1335,7 @@ public:
Reset_mouse_list();
if (g_logic.processSession())
- Con_fatal_error("restore 1st cycle failed??");
+ error("restore 1st cycle failed??");
}
}
@@ -1457,7 +1457,7 @@ void Gui::restartControl(void) {
this_screen.scroll_flag = 2;
if (g_logic.processSession())
- Con_fatal_error("restart 1st cycle failed??");
+ error("restart 1st cycle failed??");
// So palette not restored immediately after control panel - we want
// to fade up instead!
diff --git a/sword2/debug.cpp b/sword2/debug.cpp
index 0d13c14393..3d02b1bec1 100644
--- a/sword2/debug.cpp
+++ b/sword2/debug.cpp
@@ -19,11 +19,8 @@
#include "stdafx.h"
#include "bs2/driver/driver96.h"
+#include "bs2/sword2.h"
#include "bs2/debug.h"
-
-// this whole file (except ExitWithReport) only included on debug versions
-#ifdef _SWORD2_DEBUG
-
#include "bs2/build_display.h" // for 'fps'
#include "bs2/console.h"
#include "bs2/defs.h"
@@ -40,25 +37,25 @@
namespace Sword2 {
-uint8 displayDebugText = 0; // "INFO" 0=off; 1=on
-uint8 displayWalkGrid = 0; // "WALKGRID"
-uint8 displayMouseMarker = 0; // "MOUSE"
-uint8 displayTime = 0; // "TIME"
-uint8 displayPlayerMarker = 0; // "PLAYER"
-uint8 displayTextNumbers = 0; // "TEXT"
+bool displayDebugText = false; // "INFO"
+bool displayWalkGrid = false; // "WALKGRID"
+bool displayMouseMarker = false; // "MOUSE"
+bool displayTime = false; // "TIME"
+bool displayPlayerMarker = false; // "PLAYER"
+bool displayTextNumbers = false; // "TEXT"
uint8 renderSkip = 0; // Toggled on 'S' key - to render only
// 1 in 4 frames, to speed up game
-uint8 definingRectangles = 0; // "RECT"
-uint8 draggingRectangle = 0; // 0=waiting to start new rect;
- // 1=currently dragging a rectangle
+bool definingRectangles = false; // "RECT"
+uint8 draggingRectangle = 0; // 0 = waiting to start new rect;
+ // 1 = currently dragging a rectangle
int16 rect_x1 = 0;
int16 rect_y1 = 0;
int16 rect_x2 = 0;
int16 rect_y2 = 0;
-uint8 rectFlicker = 0;
+bool rectFlicker = false;
-uint8 testingSnR = 0; // "SAVEREST" - for system to kill all
+bool testingSnR = false; // "SAVEREST" - for system to kill all
// object resources (except player) in
// fnAddHuman()
@@ -87,7 +84,7 @@ void Clear_debug_text_blocks(void) {
while (blockNo < MAX_DEBUG_TEXT_BLOCKS && debug_text_blocks[blockNo] > 0) {
// kill the system text block
- Kill_text_bloc(debug_text_blocks[blockNo]);
+ fontRenderer.killTextBloc(debug_text_blocks[blockNo]);
// clear this element of our array of block numbers
debug_text_blocks[blockNo] = 0;
@@ -103,9 +100,9 @@ void Make_debug_text_block(char *text, int16 x, int16 y) {
blockNo++;
if (blockNo == MAX_DEBUG_TEXT_BLOCKS)
- Con_fatal_error("ERROR: debug_text_blocks[] full in Make_debug_text_block()");
+ error("ERROR: debug_text_blocks[] full in Make_debug_text_block()");
- debug_text_blocks[blockNo] = Build_new_block((uint8 *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION);
+ debug_text_blocks[blockNo] = fontRenderer.buildNewBloc((uint8 *) text, x, y, 640 - x, 0, RDSPR_DISPLAYALIGN, CONSOLE_FONT_ID, NO_JUSTIFICATION);
}
void Build_debug_text(void) {
@@ -136,39 +133,39 @@ void Build_debug_text(void) {
// defining a mouse area the easy way, by creating a box on-screen
if (draggingRectangle || SYSTEM_TESTING_ANIMS) {
// so we can see what's behind the lines
- rectFlicker = 1 - rectFlicker;
+ rectFlicker = !rectFlicker;
sprintf (buf, "x1=%d", rect_x1);
- Make_debug_text_block (buf, 0, 120);
+ Make_debug_text_block(buf, 0, 120);
sprintf (buf, "y1=%d", rect_y1);
- Make_debug_text_block (buf, 0, 135);
+ Make_debug_text_block(buf, 0, 135);
sprintf (buf, "x2=%d", rect_x2);
- Make_debug_text_block (buf, 0, 150);
+ Make_debug_text_block(buf, 0, 150);
sprintf (buf, "y2=%d", rect_y2);
- Make_debug_text_block (buf, 0, 165);
+ Make_debug_text_block(buf, 0, 165);
}
// testingSnR indicator
if (testingSnR) { // see fnAddHuman()
sprintf (buf, "TESTING LOGIC STABILITY!");
- Make_debug_text_block (buf, 0, 105);
+ Make_debug_text_block(buf, 0, 105);
}
// speed-up indicator
if (renderSkip) { // see sword.cpp
sprintf (buf, "SKIPPING FRAMES FOR SPEED-UP!");
- Make_debug_text_block (buf, 0, 120);
+ Make_debug_text_block(buf, 0, 120);
}
// debug info at top of screen - enabled/disabled as one complete unit
if (displayTime) {
- int32 time = timeGetTime();
+ int32 time = SVM_timeGetTime();
if ((time - startTime) / 1000 >= 10000)
startTime = time;
@@ -186,29 +183,29 @@ void Build_debug_text(void) {
if (textNumber) {
if (SYSTEM_TESTING_TEXT) {
if (SYSTEM_WANT_PREVIOUS_LINE)
- sprintf (buf, "backwards");
+ sprintf(buf, "backwards");
else
- sprintf (buf, "forwards");
+ sprintf(buf, "forwards");
- Make_debug_text_block (buf, 0, 340);
+ Make_debug_text_block(buf, 0, 340);
}
- sprintf (buf, "res: %d", textNumber/SIZE);
- Make_debug_text_block (buf, 0, 355);
+ sprintf(buf, "res: %d", textNumber / SIZE);
+ Make_debug_text_block(buf, 0, 355);
- sprintf (buf, "pos: %d", textNumber&0xffff);
- Make_debug_text_block (buf, 0, 370);
+ sprintf(buf, "pos: %d", textNumber & 0xffff);
+ Make_debug_text_block(buf, 0, 370);
- sprintf (buf, "TEXT: %d", officialTextNumber);
- Make_debug_text_block (buf, 0, 385);
+ sprintf(buf, "TEXT: %d", officialTextNumber);
+ Make_debug_text_block(buf, 0, 385);
}
}
// resource number currently being checking for animation
if (SYSTEM_TESTING_ANIMS) {
- sprintf (buf, "trying resource %d", SYSTEM_TESTING_ANIMS);
- Make_debug_text_block (buf, 0, 90);
+ sprintf(buf, "trying resource %d", SYSTEM_TESTING_ANIMS);
+ Make_debug_text_block(buf, 0, 90);
}
// general debug info
@@ -217,7 +214,7 @@ void Build_debug_text(void) {
/*
// CD in use
sprintf (buf, "CD-%d", currentCD);
- Make_debug_text_block (buf, 0, 0);
+ Make_debug_text_block(buf, 0, 0);
*/
// mouse coords & object pointed to
@@ -230,20 +227,20 @@ void Build_debug_text(void) {
sprintf(buf, "last click at %d,%d (---)",
MOUSE_X, MOUSE_Y);
- Make_debug_text_block (buf, 0, 15);
+ Make_debug_text_block(buf, 0, 15);
if (mouse_touching)
sprintf(buf, "mouse %d,%d (id %d: %s)",
- mousex + this_screen.scroll_offset_x,
- mousey + this_screen.scroll_offset_y,
+ g_display->_mouseX + this_screen.scroll_offset_x,
+ g_display->_mouseY + this_screen.scroll_offset_y,
mouse_touching,
FetchObjectName(mouse_touching));
else
sprintf(buf, "mouse %d,%d (not touching)",
- mousex + this_screen.scroll_offset_x,
- mousey + this_screen.scroll_offset_y);
+ g_display->_mouseX + this_screen.scroll_offset_x,
+ g_display->_mouseY + this_screen.scroll_offset_y);
- Make_debug_text_block (buf, 0, 30);
+ Make_debug_text_block(buf, 0, 30);
// player coords & graphic info
// if player objct has a graphic
@@ -262,56 +259,56 @@ void Build_debug_text(void) {
this_screen.player_feet_y,
playerGraphic.anim_pc);
- Make_debug_text_block (buf, 0, 45);
+ Make_debug_text_block(buf, 0, 45);
// frames-per-second counter
sprintf(buf, "fps %d", fps);
- Make_debug_text_block (buf, 440, 0);
+ Make_debug_text_block(buf, 440, 0);
// location number
sprintf(buf, "location=%d", LOCATION);
- Make_debug_text_block (buf, 440, 15);
+ Make_debug_text_block(buf, 440, 15);
// "result" variable
sprintf(buf, "result=%d", RESULT);
- Make_debug_text_block (buf, 440, 30);
+ Make_debug_text_block(buf, 440, 30);
// no. of events in event list
sprintf(buf, "events=%d", CountEvents());
- Make_debug_text_block (buf, 440, 45);
+ Make_debug_text_block(buf, 440, 45);
// sprite list usage
sprintf(buf, "bgp0: %d/%d", cur_bgp0, MAX_bgp0_sprites);
- Make_debug_text_block (buf, 560, 0);
+ Make_debug_text_block(buf, 560, 0);
sprintf(buf, "bgp1: %d/%d", cur_bgp1, MAX_bgp1_sprites);
- Make_debug_text_block (buf, 560, 15);
+ Make_debug_text_block(buf, 560, 15);
sprintf(buf, "back: %d/%d", cur_back, MAX_back_sprites);
- Make_debug_text_block (buf, 560, 30);
+ Make_debug_text_block(buf, 560, 30);
sprintf(buf, "sort: %d/%d", cur_sort, MAX_sort_sprites);
- Make_debug_text_block (buf, 560, 45);
+ Make_debug_text_block(buf, 560, 45);
sprintf(buf, "fore: %d/%d", cur_fore, MAX_fore_sprites);
- Make_debug_text_block (buf, 560, 60);
+ Make_debug_text_block(buf, 560, 60);
sprintf(buf, "fgp0: %d/%d", cur_fgp0, MAX_fgp0_sprites);
- Make_debug_text_block (buf, 560, 75);
+ Make_debug_text_block(buf, 560, 75);
sprintf(buf, "fgp1: %d/%d", cur_fgp1, MAX_fgp1_sprites);
- Make_debug_text_block (buf, 560, 90);
+ Make_debug_text_block(buf, 560, 90);
// largest layer & sprite
// NB. Strings already constructed in Build_display.cpp
- Make_debug_text_block (largest_layer_info, 0, 60);
- Make_debug_text_block (largest_sprite_info, 0, 75);
+ Make_debug_text_block(largest_layer_info, 0, 60);
+ Make_debug_text_block(largest_sprite_info, 0, 75);
// "waiting for person" indicator - set form fnTheyDo and
// fnTheyDoWeWait
@@ -320,7 +317,7 @@ void Build_debug_text(void) {
sprintf(buf, "script waiting for %s (%d)",
FetchObjectName(speechScriptWaiting),
speechScriptWaiting);
- Make_debug_text_block (buf, 0, 90);
+ Make_debug_text_block(buf, 0, 90);
}
// variable watch display
@@ -337,9 +334,8 @@ void Build_debug_text(void) {
// anyway because it changes throughout the logic loop
if (varNo) {
- sprintf(buf, "var(%d) = %d",
- varNo, varTable[varNo]);
- Make_debug_text_block (buf, 530, showVarPos);
+ sprintf(buf, "var(%d) = %d", varNo, varTable[varNo]);
+ Make_debug_text_block(buf, 530, showVarPos);
showVarPos += 15; // next line down
}
}
@@ -349,8 +345,8 @@ void Build_debug_text(void) {
// memory indicator - this should come last, to show all the
// sprite blocks above!
- Create_mem_string (buf);
- Make_debug_text_block (buf, 0, 0);
+ memory.memoryString(buf);
+ Make_debug_text_block(buf, 0, 0);
}
}
@@ -368,7 +364,7 @@ void Draw_debug_graphics(void) {
// mouse marker & coords
if (displayMouseMarker)
- Plot_cross_hair(mousex + this_screen.scroll_offset_x, mousey + this_screen.scroll_offset_y, 215);
+ Plot_cross_hair(g_display->_mouseX + this_screen.scroll_offset_x, g_display->_mouseY + this_screen.scroll_offset_y, 215);
// mouse area rectangle / sprite box rectangle when testing anims
@@ -384,46 +380,33 @@ void Draw_debug_graphics(void) {
}
void Plot_cross_hair(int16 x, int16 y, uint8 pen) {
- PlotPoint(x, y, pen); // driver function
+ g_display->plotPoint(x, y, pen); // driver function
- DrawLine(x - 2, y, x - 5, y, pen); // driver function
- DrawLine(x + 2, y, x + 5, y, pen);
+ g_display->drawLine(x - 2, y, x - 5, y, pen); // driver function
+ g_display->drawLine(x + 2, y, x + 5, y, pen);
- DrawLine(x, y - 2, x, y - 5, pen);
- DrawLine(x, y + 2, x, y + 5, pen);
+ g_display->drawLine(x, y - 2, x, y - 5, pen);
+ g_display->drawLine(x, y + 2, x, y + 5, pen);
}
void DrawRect(int16 x1, int16 y1, int16 x2, int16 y2, uint8 pen) {
- DrawLine(x1, y1, x2, y1, pen); // top edge
- DrawLine(x1, y2, x2, y2, pen); // bottom edge
- DrawLine(x1, y1, x1, y2, pen); // left edge
- DrawLine(x2, y1, x2, y2, pen); // right edge
+ g_display->drawLine(x1, y1, x2, y1, pen); // top edge
+ g_display->drawLine(x1, y2, x2, y2, pen); // bottom edge
+ g_display->drawLine(x1, y1, x1, y2, pen); // left edge
+ g_display->drawLine(x2, y1, x2, y2, pen); // right edge
}
void Print_current_info(void) {
// prints general stuff about the screen, etc.
if (this_screen.background_layer_id) {
- Print_to_console(" background layer id %d",
- this_screen.background_layer_id);
- Print_to_console(" %d wide, %d high",
- this_screen.screen_wide, this_screen.screen_deep);
- Print_to_console(" %d normal layers",
- this_screen.number_of_layers);
-
- LLogic.examineRunList();
- } else
- Print_to_console(" no screen");
+ Debug_Printf("background layer id %d\n", this_screen.background_layer_id);
+ Debug_Printf("%d wide, %d high\n", this_screen.screen_wide, this_screen.screen_deep);
+ Debug_Printf("%d normal layers\n", this_screen.number_of_layers);
- Scroll_console();
+ g_logic.examineRunList();
+ } else
+ Debug_Printf("No screen\n");
}
} // End of namespace Sword2
-
-#else
-
-namespace Sword2 {
-void Draw_debug_graphics(void) {}
-} // End of namespace Sword2
-
-#endif
diff --git a/sword2/debug.h b/sword2/debug.h
index bad786c53b..699a378daf 100644
--- a/sword2/debug.h
+++ b/sword2/debug.h
@@ -20,25 +20,21 @@
#ifndef D_DEBUG
#define D_DEBUG
-// this whole file only included on debug versions
-#ifdef _SWORD2_DEBUG
-
-#include "bs2/driver.h"
#include "bs2/object.h"
-namespace Sword2 {
+// FIXME: I don't know how large this constant used to be
+#define MAX_DEBUG_TEXT_BLOCKS 50
-#define MAX_DEBUG_TEXT_BLOCKS 50
+namespace Sword2 {
-extern uint8 displayDebugText; // 0=off; 1=on
-extern uint8 displayWalkGrid;
-extern uint8 displayMouseMarker;
-extern uint8 displayPlayerMarker;
-extern uint8 displayTime;
-extern uint8 displayTextNumbers;
-extern uint8 definingRectangles;
+extern bool displayDebugText;
+extern bool displayWalkGrid;
+extern bool displayMouseMarker;
+extern bool displayPlayerMarker;
+extern bool displayTime;
+extern bool displayTextNumbers;
+extern bool definingRectangles;
extern uint8 draggingRectangle;
-extern uint8 displayTime;
extern int32 startTime;
extern int32 gameCycle;
extern uint8 renderSkip;
@@ -48,9 +44,9 @@ extern int16 rect_y1;
extern int16 rect_x2;
extern int16 rect_y2;
-extern uint8 testingSnR;
+extern bool testingSnR;
-extern int32 textNumber;
+extern int32 textNumber;
extern Object_graphic playerGraphic;
extern uint32 player_graphic_no_frames;
@@ -66,15 +62,4 @@ void Print_current_info(void);
} // End of namespace Sword2
-#else // ie. not _SWORD2_DEBUG
-
-namespace Sword2 {
-
-void Build_debug_text(void);
-void Draw_debug_graphics(void);
-
-} // End of namespace Sword2
-
-#endif
-
#endif
diff --git a/sword2/driver/_console.cpp b/sword2/driver/_console.cpp
deleted file mode 100644
index bf711febe1..0000000000
--- a/sword2/driver/_console.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/* Copyright (C) 1994-2003 Revolution Software Ltd
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Header$
- */
-
-//=============================================================================
-//
-// Filename : console.c
-// Created : 19th September 1996
-// By : P.R.Porter
-//
-// Summary : This module holds the code which controls and displays
-// the console/debugging window.
-//
-// Functions
-// ---------
-//
-// --------------------------------------------------------------------------
-//
-// int32 OpenConsole(void)
-//
-// Displays the console window and directs keyboard input to it.
-//
-// --------------------------------------------------------------------------
-//
-// int32 CloseConsole(void)
-//
-// Removes the console from the display.
-//
-//=============================================================================
-
-#include "stdafx.h"
-#include "bs2/driver/driver96.h"
-#include "bs2/driver/d_draw.h"
-
-namespace Sword2 {
-
-uint8 consoleStatus = 0; // 1 - console display
-//static uint16 consoley = 0;
-//static uint32 consoleSize;
-static uint8 *consoleSprite = NULL;
-
-
-
-// --------------------------------------------------------------------------
-// Called before the screens are flipped, so that the console can be drawn
-// over the screen if necessary.
-// --------------------------------------------------------------------------
-void DisplayConsole(void)
-
-{
- warning("stub DisplayConsole");
-/*
- uint8 *src, *dst;
- uint8 i;
-// DDSURFACEDESC ddDescription;
-// HRESULT hr;
-
-
- if (consoleStatus)
- {
-
- ddDescription.dwSize = sizeof(ddDescription);
-
- hr = IDirectDrawSurface_Lock(lpBackBuffer, NULL, &ddDescription, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
- if (hr != DD_OK)
- {
- hr = IDirectDrawSurface_Lock(lpBackBuffer, NULL, &ddDescription, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
- }
-
- if (hr == DD_OK)
- {
-
- dst = (uint8 *) ddDescription.lpSurface + (screenDeep - consoley) * ddDescription.lPitch;
- src = (uint8 *) consoleSprite;
-
- for (i=0; i<consoley; i++)
- {
- memcpy(dst, src, screenWide);
- src += screenWide;
- dst += ddDescription.lPitch;
- }
- IDirectDrawSurface_Unlock(lpBackBuffer, ddDescription.lpSurface);
- }
- }
- */
-}
-
-
-
-
-int32 OpenConsole(void)
-
-{
- warning("stub OpenConsole");
-/*
- if (consoleStatus)
- return RDERR_ALREADYOPEN;
-
- if (consoleSprite == NULL)
- {
- consoley = screenDeep >> 2;
- consoleSize = screenWide * consoley;
- consoleSprite = (uint8 *) malloc(consoleSize);
- }
-
- if (consoleSprite == NULL)
- return RDERR_OUTOFMEMORY;
-
- memset(consoleSprite, 0, consoleSize);
-*/
- consoleStatus = 1;
-
- return RD_OK;
-
-}
-
-
-
-
-int32 CloseConsole(void)
-
-{
-
- if (!consoleStatus)
- return RDERR_ALREADYCLOSED;
-
- free(consoleSprite);
- consoleSprite = NULL;
-
- consoleStatus = 0;
-
- return RD_OK;
-
-}
-
-} // End of namespace Sword2
diff --git a/sword2/driver/_console.h b/sword2/driver/_console.h
deleted file mode 100644
index a327cd95c1..0000000000
--- a/sword2/driver/_console.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* Copyright (C) 1994-2003 Revolution Software Ltd
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * $Header$
- */
-
-#ifndef DRIVER_CONSOLE_H
-#define DRIVER_CONSOLE_H
-
-namespace Sword2 {
-
-extern void DisplayConsole(void);
-
-} // End of namespace Sword2
-
-#endif
diff --git a/sword2/driver/d_draw.h b/sword2/driver/d_draw.h
index 4d0c1d71e2..17e79c8631 100644
--- a/sword2/driver/d_draw.h
+++ b/sword2/driver/d_draw.h
@@ -153,7 +153,6 @@ private:
void clearIconArea(int menu, int pocket, Common::Rect *r);
void decompressMouse(uint8 *decomp, uint8 *comp, int width, int height, int pitch, int xOff = 0, int yOff = 0);
- void drawMouse(void);
uint8 getMatch(uint8 r, uint8 g, uint8 b);
void fadeServer(void);
@@ -214,6 +213,8 @@ public:
int32 setLuggageAnim(uint8 *la, int32 size);
int32 animateMouse(void);
+ void drawMouse(void);
+
void resetRenderEngine(void);
void setScrollTarget(int16 sx, int16 sy);
@@ -225,10 +226,8 @@ public:
int32 initialiseBackgroundLayer(_parallax *p);
void closeBackgroundLayer(void);
-#ifdef _SWORD2_DEBUG
void plotPoint(uint16 x, uint16 y, uint8 colour);
void drawLine(int16 x1, int16 y1, int16 x2, int16 y2, uint8 colour);
-#endif
int32 createSurface(_spriteInfo *s, uint8 **surface);
void drawSurface(_spriteInfo *s, uint8 *surface, Common::Rect *clipRect = NULL);
diff --git a/sword2/driver/render.cpp b/sword2/driver/render.cpp
index a8e13fd45a..e0cc9fc7df 100644
--- a/sword2/driver/render.cpp
+++ b/sword2/driver/render.cpp
@@ -328,7 +328,6 @@ void Display::stretchImage(byte *dst, uint16 dstPitch, uint16 dstWidth, uint16 d
}
}
-#ifdef _SWORD2_DEBUG
/**
* Plots a point relative to the top left corner of the screen. This is only
* used for debugging.
@@ -513,7 +512,6 @@ void Display::drawLine(int16 x0, int16 y0, int16 x1, int16 y1, uint8 colour) {
}
}
}
-#endif
/**
* This function tells the driver the size of the background screen for the
diff --git a/sword2/events.cpp b/sword2/events.cpp
index 12131825e6..fe2724f951 100644
--- a/sword2/events.cpp
+++ b/sword2/events.cpp
@@ -18,6 +18,7 @@
*/
#include "stdafx.h"
+#include "bs2/sword2.h"
#include "bs2/console.h"
#include "bs2/debug.h"
#include "bs2/defs.h"
@@ -39,7 +40,6 @@ void Init_event_system(void) {
}
}
-#ifdef _SWORD2_DEBUG
uint32 CountEvents(void) {
uint32 count = 0;
@@ -50,7 +50,6 @@ uint32 CountEvents(void) {
return count;
}
-#endif
int32 Logic::fnRequestSpeech(int32 *params) {
// change current script - must be followed by a TERMINATE script
@@ -70,7 +69,7 @@ int32 Logic::fnRequestSpeech(int32 *params) {
}
if (i == MAX_events)
- Con_fatal_error("fnSetEvent out of event slots");
+ error("fnSetEvent out of event slots");
// found that slot
@@ -95,7 +94,7 @@ void Set_player_action_event(uint32 id, uint32 interact_id) {
}
if (i == MAX_events)
- Con_fatal_error("Set_event out of event slots");
+ error("Set_event out of event slots");
// found that slot
@@ -129,7 +128,7 @@ int32 Logic::fnSetPlayerActionEvent(int32 *params) {
}
if (i == MAX_events)
- Con_fatal_error("Set_event out of event slots");
+ error("Set_event out of event slots");
// found that slot
@@ -162,7 +161,7 @@ int32 Logic::fnSendEvent(int32 *params) {
}
if (i == MAX_events)
- Con_fatal_error("fnSendEvent out of event slots");
+ error("fnSendEvent out of event slots");
// found that slot
@@ -304,7 +303,7 @@ void Start_event(void) {
}
// oh dear - stop the system
- Con_fatal_error("Start_event can't find event for id %d", ID);
+ error("Start_event can't find event for id %d", ID);
}
int32 Logic::fnStartEvent(int32 *params) {
@@ -321,7 +320,7 @@ int32 Logic::fnStartEvent(int32 *params) {
}
// oh dear - stop the system
- Con_fatal_error("fnStartEvent can't find event for id %d", ID);
+ error("fnStartEvent can't find event for id %d", ID);
return 0; // never called - but lets stop them bloody errors
}
diff --git a/sword2/events.h b/sword2/events.h
index 27e88bebf1..e4654a837d 100644
--- a/sword2/events.h
+++ b/sword2/events.h
@@ -39,9 +39,7 @@ void Start_event(void);
bool Check_event_waiting(void);
void Kill_all_ids_events(uint32 id);
-#ifdef _SWORD2_DEBUG
uint32 CountEvents(void);
-#endif
} // End of namespace Sword2
diff --git a/sword2/function.cpp b/sword2/function.cpp
index eb19aca836..34ba74b70e 100644
--- a/sword2/function.cpp
+++ b/sword2/function.cpp
@@ -367,7 +367,7 @@ int32 Logic::fnResetGlobals(int32 *params) {
res_man.close(1);
// all objects but george
- res_man.killAllObjects(0);
+ res_man.killAllObjects(false);
// FOR THE DEMO - FORCE THE SCROLLING TO BE RESET!
// - this is taken from fnInitBackground
diff --git a/sword2/icons.cpp b/sword2/icons.cpp
index a8e049354d..f35dea1f3c 100644
--- a/sword2/icons.cpp
+++ b/sword2/icons.cpp
@@ -40,7 +40,7 @@ int32 Logic::fnAddMenuObject(int32 *params) {
#ifdef _SWORD2_DEBUG
if (total_temp == TOTAL_engine_pockets)
- Con_fatal_error("TOTAL_engine_pockets exceeded!");
+ error("TOTAL_engine_pockets exceeded!");
#endif
// copy the structure to our in-the-engine list
diff --git a/sword2/interpreter.cpp b/sword2/interpreter.cpp
index ed3abad9ac..46c9fa13a6 100644
--- a/sword2/interpreter.cpp
+++ b/sword2/interpreter.cpp
@@ -273,7 +273,7 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
code += sizeof(int32) * 3;
if (READ_LE_UINT32(checksumBlock) != 12345678) {
- Con_fatal_error("Invalid script in object %s", header->name);
+ error("Invalid script in object %s", header->name);
return 0;
}
@@ -284,7 +284,7 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
checksum += (unsigned char) code[count];
if (checksum != (int32) READ_LE_UINT32(checksumBlock + 2)) {
- Con_fatal_error("Checksum error in object %s", header->name);
+ error("Checksum error in object %s", header->name);
return 0;
}
#endif
@@ -632,7 +632,7 @@ int Logic::runScript(char *scriptData, char *objectData, uint32 *offset) {
DOOPERATION (stack2[stackPointer2 - 2] || stack2[stackPointer2 - 1]);
break;
default:
- Con_fatal_error("Interpreter error: Invalid token %d", curCommand);
+ error("Interpreter error: Invalid token %d", curCommand);
return 3;
}
}
diff --git a/sword2/layers.cpp b/sword2/layers.cpp
index d6b7674819..a9152b3ee1 100644
--- a/sword2/layers.cpp
+++ b/sword2/layers.cpp
@@ -65,7 +65,7 @@ int32 Logic::fnInitBackground(int32 *params) {
debug(5, "fnInitBackground(%d)", params[0]);
if (!params[0]) {
- Con_fatal_error("ERROR: fnInitBackground cannot have 0 for background layer id!");
+ error("ERROR: fnInitBackground cannot have 0 for background layer id!");
}
#endif
diff --git a/sword2/logic.cpp b/sword2/logic.cpp
index 166fd53b73..90161a2249 100644
--- a/sword2/logic.cpp
+++ b/sword2/logic.cpp
@@ -63,7 +63,7 @@ int Logic::processSession(void) {
head = (_standardHeader*) res_man.open(run_list);
if (head->fileType != RUN_LIST)
- Con_fatal_error("Logic_engine %d not a run_list", run_list);
+ error("Logic_engine %d not a run_list", run_list);
game_object_list = (uint32 *) (head + 1);
@@ -87,7 +87,7 @@ int Logic::processSession(void) {
head = (_standardHeader*) res_man.open(ID);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("Logic_engine %d not an object", ID);
+ error("Logic_engine %d not an object", ID);
_curObjectHub = (_object_hub *) (head + 1);
@@ -133,7 +133,7 @@ int Logic::processSession(void) {
far_head = (_standardHeader*) res_man.open(script / SIZE);
if (far_head->fileType != GAME_OBJECT && far_head->fileType != SCREEN_MANAGER)
- Con_fatal_error("Logic_engine %d not a far object (its a %d)", script / SIZE, far_head->fileType);
+ error("Logic_engine %d not a far object (its a %d)", script / SIZE, far_head->fileType);
// raw_script_ad = (char*) (head + 1) + sizeof(_standardHeader);
@@ -171,7 +171,7 @@ int Logic::processSession(void) {
ret = 0;
}
} else if (ret > 2) {
- Con_fatal_error("processSession: illegal script return type %d", ret);
+ error("processSession: illegal script return type %d", ret);
}
// if ret == 2 then we simply go around again - a new
@@ -300,7 +300,7 @@ void Logic::logicUp(uint32 new_script) {
// can be 0, 1, 2
if (LEVEL == 3)
- Con_fatal_error("logicUp id %d has run off script tree! :-O", ID);
+ error("logicUp id %d has run off script tree! :-O", ID);
// setup new script on next level (not the current level)
@@ -333,53 +333,25 @@ void Logic::logicReplace(uint32 new_script) {
_curObjectHub->script_pc[LEVEL] = new_script & 0xffff;
}
-uint32 Logic::examineRunList(void) {
+void Logic::examineRunList(void) {
uint32 *game_object_list;
_standardHeader *file_header;
- int scrolls = 0;
- _keyboardEvent ke;
if (_currentRunList) {
// open and lock in place
game_object_list = (uint32 *) (res_man.open(_currentRunList) + sizeof(_standardHeader));
- Print_to_console("runlist number %d", _currentRunList);
+ Debug_Printf("Runlist number %d\n", _currentRunList);
for (int i = 0; game_object_list[i]; i++) {
file_header = (_standardHeader *) res_man.open(game_object_list[i]);
- Print_to_console(" %d %s", game_object_list[i], file_header->name);
+ Debug_Printf("%d %s\n", game_object_list[i], file_header->name);
res_man.close(game_object_list[i]);
-
- scrolls++;
- Build_display();
-
- if (scrolls == 18) {
- Temp_print_to_console("- Press ESC to stop or any other key to continue");
- Build_display();
-
- do {
- g_display->updateDisplay();
- } while (!KeyWaiting());
-
- // kill the key we just pressed
- ReadKey(&ke);
- if (ke.keycode == 27)
- break;
-
- // clear the Press Esc message ready for the
- // new line
-
- Clear_console_line();
- scrolls = 0;
- }
}
res_man.close(_currentRunList);
} else
- Print_to_console("no run list set");
-
- Scroll_console();
- return 1;
+ Debug_Printf("No run list set\n");
}
/**
@@ -435,7 +407,7 @@ int32 Logic::fnAddToKillList(int32 *params) {
#ifdef _SWORD2_DEBUG
// no room at the inn
if (_kills == OBJECT_KILL_LIST_SIZE)
- Con_fatal_error("List full in fnAddToKillList(%u)", ID);
+ error("List full in fnAddToKillList(%u)", ID);
#endif
// add this 'ID' to the kill list
diff --git a/sword2/logic.h b/sword2/logic.h
index e54d520794..8ec526699d 100644
--- a/sword2/logic.h
+++ b/sword2/logic.h
@@ -214,7 +214,7 @@ public:
void logicReplace(uint32 new_script);
void logicOne(uint32 new_script);
void totalRestart(void);
- uint32 examineRunList(void);
+ void examineRunList(void);
void resetKillList(void);
};
diff --git a/sword2/maketext.cpp b/sword2/maketext.cpp
index 669429415f..1a0584aa4c 100644
--- a/sword2/maketext.cpp
+++ b/sword2/maketext.cpp
@@ -263,7 +263,7 @@ mem* FontRenderer::buildTextSprite(uint8 *sentence, uint32 fontRes, uint8 pen, L
#ifdef _SWORD2_DEBUG
if (charPtr->height != char_height)
- Con_fatal_error("FONT ERROR: '%c' is not same height as the space", sentence[pos - 1]);
+ error("FONT ERROR: '%c' is not same height as the space", sentence[pos - 1]);
#endif
copyChar(charPtr, spritePtr, spriteWidth, pen);
@@ -418,7 +418,7 @@ uint32 FontRenderer::buildNewBloc(uint8 *ascii, int16 x, int16 y, uint16 width,
#ifdef _SWORD2_DEBUG
// we've run out - might as well stop the system
if (j == MAX_text_blocs)
- Con_fatal_error("Build_new_block ran out of blocks!");
+ error("Build_new_block ran out of blocks!");
#endif
// make the sprite!
@@ -542,7 +542,7 @@ void FontRenderer::killTextBloc(uint32 bloc_number) {
_blocList[bloc_number].text_mem = 0;
} else {
// illegal kill - stop the system
- Con_fatal_error("closing closed text bloc number %d", bloc_number);
+ error("closing closed text bloc number %d", bloc_number);
}
}
diff --git a/sword2/maketext.h b/sword2/maketext.h
index 47be05cfc6..3163524d8c 100644
--- a/sword2/maketext.h
+++ b/sword2/maketext.h
@@ -58,10 +58,7 @@
#define _MAKETEXT_H
#include "bs2/memory.h"
-
-#ifdef _SWORD2_DEBUG
#include "bs2/debug.h"
-#endif
// Output colour for character border - should be be black but note that we
// have to use a different pen number during sequences
@@ -70,13 +67,8 @@
namespace Sword2 {
-#ifdef _SWORD2_DEBUG
// allow enough for all the debug text blocks (see debug.cpp)
#define MAX_text_blocs MAX_DEBUG_TEXT_BLOCKS + 1
-#else
-// only need one for speech, and possibly one for "PAUSED"
-#define MAX_text_blocs 2
-#endif
enum {
// only for debug text, since it doesn't keep text inside the screen
@@ -149,14 +141,6 @@ public:
uint32 buildNewBloc(uint8 *ascii, int16 x, int16 y, uint16 width, uint8 pen, uint32 type, uint32 fontRes, uint8 justification);
};
-extern
-
-// this one works out the language from the text cluster
-void initialiseFontResourceFlags(void);
-
-// this one allow you to select the fonts yourself
-void initialiseFontResourceFlags(uint8 language);
-
extern FontRenderer fontRenderer;
} // End of namespace Sword2
diff --git a/sword2/mem_view.cpp b/sword2/mem_view.cpp
index cd4fec02ad..561b2b4ed1 100644
--- a/sword2/mem_view.cpp
+++ b/sword2/mem_view.cpp
@@ -33,8 +33,6 @@ char buf[50];
void MemoryManager::displayMemory(void) {
int pass, found_end, k, j, free = 0;
_standardHeader *file_header;
- int scrolls = 0;
- _keyboardEvent ke;
char inf[][20] = {
{ "M_null " },
@@ -69,7 +67,7 @@ void MemoryManager::displayMemory(void) {
pass = 1; // also illegal
if (!pass && found_end) { // && file_header->fileType < 10)
- Print_to_console("%d %s, size 0x%.5x (%dk %d%%), res %d %s %s, A%d, C%d",
+ Debug_Printf("%d %s, size 0x%.5x (%dk %d%%), res %d %s %s, A%d, C%d\n",
j, inf[_memList[j].state],
_memList[j].size,
_memList[j].size / 1024,
@@ -80,9 +78,9 @@ void MemoryManager::displayMemory(void) {
res_man.fetchAge(_memList[j].uid),
res_man.fetchCount(_memList[j].uid));
} else
- Print_to_console(" %d is an illegal resource", _memList[j].uid);
+ Debug_Printf(" %d is an illegal resource\n", _memList[j].uid);
} else {
- Print_to_console("%d %s, size 0x%.5x (%dk %d%%), %s",
+ Debug_Printf("%d %s, size 0x%.5x (%dk %d%%), %s\n",
j, inf[_memList[j].state], _memList[j].size,
_memList[j].size / 1024,
(_memList[j].size * 100) / _totalFreeMemory,
@@ -93,31 +91,9 @@ void MemoryManager::displayMemory(void) {
free += _memList[j].size;
j = _memList[j].child;
-
- scrolls++;
-
- Build_display();
-
- if (scrolls == 18) {
- Temp_print_to_console("- Press ESC to stop or any other key to continue");
- Build_display();
-
- do {
- g_display->updateDisplay();
- } while (!KeyWaiting());
-
- ReadKey(&ke); //kill the key we just pressed
- if (ke.keycode == 27) //ESC
- break;
-
- // clear the Press Esc message ready for the new line
- Clear_console_line();
- scrolls = 0;
- }
} while (j != -1);
- Scroll_console();
- Print_to_console("(total memory block 0x%.8x %dk %dMB) %d / %d%% free",
+ Debug_Printf("(total memory block 0x%.8x %dk %dMB) %d / %d%% free\n",
_totalFreeMemory, _totalFreeMemory / 1024,
_totalFreeMemory / (1000 * 1024), free,
(free * 100) / _totalFreeMemory);
diff --git a/sword2/memory.h b/sword2/memory.h
index c0a6914c2c..8030269539 100644
--- a/sword2/memory.h
+++ b/sword2/memory.h
@@ -82,7 +82,6 @@ private:
// Debugging functions
void debugMemory(void);
const char *fetchOwner(uint32 uid);
- void memoryString(char *string);
public:
// List of defined memory handles - each representing a block of memory
@@ -98,6 +97,7 @@ public:
// Debugging function
void displayMemory(void);
+ void memoryString(char *string);
};
extern MemoryManager memory;
diff --git a/sword2/module.mk b/sword2/module.mk
index c3a00dd009..7af5c7e340 100644
--- a/sword2/module.mk
+++ b/sword2/module.mk
@@ -28,7 +28,6 @@ MODULE_OBJS := \
bs2/sync.o \
bs2/tony_gsdk.o \
bs2/walker.o \
- bs2/driver/_console.o \
bs2/driver/d_draw.o \
bs2/driver/d_sound.o \
bs2/driver/keyboard.o \
diff --git a/sword2/mouse.cpp b/sword2/mouse.cpp
index 04d59867ac..ff80a0172a 100644
--- a/sword2/mouse.cpp
+++ b/sword2/mouse.cpp
@@ -572,7 +572,6 @@ void Normal_mouse(void) {
me = MouseEvent();
-#ifdef _SWORD2_DEBUG
if (definingRectangles) {
if (draggingRectangle == 0) {
// not yet dragging a rectangle, so need click to start
@@ -605,89 +604,86 @@ void Normal_mouse(void) {
}
}
} else {
-#endif
+ // We only care about down clicks when the mouse is over an
+ // object. We ignore mouse releases
- // we only care about down clicks when the mouse is over an object
- // we ignore mouse releases
+ if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN)) && mouse_touching) {
+ // there's a mouse event to be processed and the mouse
+ // is on something
- if (me && (me->buttons & (RD_LEFTBUTTONDOWN | RD_RIGHTBUTTONDOWN)) && mouse_touching) {
- // there's a mouse event to be processed and the mouse is on
- // something
+ // ok, there are no menus about so its nice and simple
+ // this is as close to the old advisor_188 script as we
+ // get, I'm sorry to say.
- // ok, there are no menus about so its nice and simple
- // this is as close to the old advisor_188 script as we get
- // I'm sorry to say.
+ // if player is walking or relaxing then those need to
+ // terminate correctly
- // if player is walking or relaxing then those need to
- // terminate correctly
+ // otherwise set player run the targets action script
+ // or, do a special walk if clicking on the scroll-more
+ // icon
- // otherwise set player run the targets action script
- // or, do a special walk if clicking on the scroll-more icon
+ // PLAYER_ACTION script variable - whatever catches
+ // this must reset to 0 again
+ // PLAYER_ACTION = mouse_touching;
- // PLAYER_ACTION script variable - whatever catches this must
- // reset to 0 again
- // PLAYER_ACTION = mouse_touching;
+ // idle or router-anim will catch it
- // idle or router-anim will catch it
+ // set global script variable 'button'
- // set global script variable 'button'
+ if (me->buttons & RD_LEFTBUTTONDOWN) {
+ LEFT_BUTTON = 1;
+ RIGHT_BUTTON = 0;
+ button_click = 0; // for re-click
+ } else {
+ LEFT_BUTTON = 0;
+ RIGHT_BUTTON = 1;
+ button_click = 1; // for re-click
+ }
- if (me->buttons & RD_LEFTBUTTONDOWN) {
- LEFT_BUTTON = 1;
- RIGHT_BUTTON = 0;
- button_click = 0; // for re-click
- } else {
- LEFT_BUTTON = 0;
- RIGHT_BUTTON = 1;
- button_click = 1; // for re-click
- }
+ // these might be required by the action script about
+ // to be run
+ MOUSE_X = (uint32) g_display->_mouseX + this_screen.scroll_offset_x;
+ MOUSE_Y = (uint32) g_display->_mouseY + this_screen.scroll_offset_y;
- // these might be required by the action script about to be run
- MOUSE_X = (uint32) g_display->_mouseX + this_screen.scroll_offset_x;
- MOUSE_Y = (uint32) g_display->_mouseY + this_screen.scroll_offset_y;
-
- // only left button
- if (mouse_touching == EXIT_CLICK_ID && (me->buttons & RD_LEFTBUTTONDOWN)) {
- // its the exit double click situation
- // let the existing interaction continue and start
- // fading down - switch the human off too
-
- g_logic.fnNoHuman(NULL);
- g_logic.fnFadeDown(NULL);
- EXIT_FADING = 1; // tell the walker
- } else if (old_button == button_click && mouse_touching == CLICKED_ID && mouse_pointer_res != NORMAL_MOUSE_ID) {
- // re-click - do nothing - except on floors
- } else {
- // allow the click
- old_button = button_click; // for re-click
+ // only left button
+ if (mouse_touching == EXIT_CLICK_ID && (me->buttons & RD_LEFTBUTTONDOWN)) {
+ // its the exit double click situation
+ // let the existing interaction continue and
+ // start fading down - switch the human off too
+
+ g_logic.fnNoHuman(NULL);
+ g_logic.fnFadeDown(NULL);
+ EXIT_FADING = 1; // tell the walker
+ } else if (old_button == button_click && mouse_touching == CLICKED_ID && mouse_pointer_res != NORMAL_MOUSE_ID) {
+ // re-click - do nothing - except on floors
+ } else {
+ // allow the click
+ old_button = button_click; // for re-click
- // for scripts to know what's been clicked
- // First used for 'room_13_turning_script' in object
- // 'biscuits_13'
+ // for scripts to know what's been clicked
+ // First used for 'room_13_turning_script' in
+ // object 'biscuits_13'
- CLICKED_ID = mouse_touching;
+ CLICKED_ID = mouse_touching;
- // must clear these two double-click control flags -
- // do it here so reclicks after exit clicks are
- // cleared up
+ // must clear these two double-click control
+ // flags - do it here so reclicks after exit
+ // clicks are cleared up
- EXIT_CLICK_ID = 0;
- EXIT_FADING = 0;
+ EXIT_CLICK_ID = 0;
+ EXIT_FADING = 0;
- Set_player_action_event(CUR_PLAYER_ID, mouse_touching);
+ Set_player_action_event(CUR_PLAYER_ID, mouse_touching);
- if (OBJECT_HELD)
- debug(5, "USED \"%s\" ICON ON %s", FetchObjectName(OBJECT_HELD), FetchObjectName(CLICKED_ID));
- else if (LEFT_BUTTON)
- debug(5, "LEFT-CLICKED ON %s", FetchObjectName(CLICKED_ID));
- else // RIGHT BUTTON
- debug(5, "RIGHT-CLICKED ON %s", FetchObjectName(CLICKED_ID));
+ if (OBJECT_HELD)
+ debug(5, "USED \"%s\" ICON ON %s", FetchObjectName(OBJECT_HELD), FetchObjectName(CLICKED_ID));
+ else if (LEFT_BUTTON)
+ debug(5, "LEFT-CLICKED ON %s", FetchObjectName(CLICKED_ID));
+ else // RIGHT BUTTON
+ debug(5, "RIGHT-CLICKED ON %s", FetchObjectName(CLICKED_ID));
+ }
}
}
-
-#ifdef _SWORD2_DEBUG
- }
-#endif
}
void Mouse_on_off(void) {
@@ -746,7 +742,7 @@ void Mouse_on_off(void) {
Set_luggage(current_luggage_resource);
}
} else
- Con_fatal_error("ERROR: mouse.pointer==0 for object %d (%s) - update logic script!", mouse_touching, FetchObjectName(mouse_touching));
+ error("ERROR: mouse.pointer==0 for object %d (%s) - update logic script!", mouse_touching, FetchObjectName(mouse_touching));
} else if (old_mouse_touching && !mouse_touching) {
// the cursor has moved off something - reset cursor to
// normal pointer
@@ -1131,11 +1127,10 @@ int32 Logic::fnAddHuman(int32 *params) {
// enabled/disabled from console; status printed with on-screen debug
// info
-#ifdef _SWORD2_DEBUG
- uint8 black[4] = { 0, 0, 0, 0 };
- uint8 white[4] = { 255, 255, 255, 0 };
-
if (testingSnR) {
+ uint8 black[4] = { 0, 0, 0, 0 };
+ uint8 white[4] = { 255, 255, 255, 0 };
+
// testing logic scripts by simulating an instant Save &
// Restore
@@ -1149,11 +1144,10 @@ int32 Logic::fnAddHuman(int32 *params) {
// Trash all object resources so they load in fresh & restart
// their logic scripts
- res_man.killAllObjects(0);
+ res_man.killAllObjects(false);
g_display->setPalette(0, 1, black, RDPAL_INSTANT);
}
-#endif
return IR_CONT;
}
@@ -1175,7 +1169,7 @@ int32 Logic::fnRegisterMouse(int32 *params) {
if (ob_mouse->pointer) {
#ifdef _SWORD2_DEBUG
if (cur_mouse == TOTAL_mouse_list)
- Con_fatal_error("ERROR: mouse_list full");
+ error("ERROR: mouse_list full");
#endif
mouse_list[cur_mouse].x1 = ob_mouse->x1;
@@ -1224,7 +1218,7 @@ int32 Logic::fnRegisterPointerText(int32 *params) {
#ifdef _SWORD2_DEBUG
if (cur_mouse == TOTAL_mouse_list)
- Con_fatal_error("ERROR: mouse_list full");
+ error("ERROR: mouse_list full");
#endif
// current object id - used for checking pointer_text when mouse area
diff --git a/sword2/protocol.cpp b/sword2/protocol.cpp
index 0557bd3926..de175f7583 100644
--- a/sword2/protocol.cpp
+++ b/sword2/protocol.cpp
@@ -18,6 +18,7 @@
*/
#include "stdafx.h"
+#include "bs2/sword2.h"
#include "bs2/console.h"
#include "bs2/defs.h"
#include "bs2/header.h"
@@ -77,7 +78,7 @@ _layerHeader *FetchLayerHeader(uint8 *screenFile, uint16 layerNo) { // Chris 04O
_screenHeader *screenHead = FetchScreenHeader(screenFile);
if (layerNo > screenHead->noLayers - 1)
- Con_fatal_error("FetchLayerHeader(%d) invalid layer number!", layerNo);
+ error("FetchLayerHeader(%d) invalid layer number!", layerNo);
#endif
_multiScreenHeader *mscreenHeader = (_multiScreenHeader *) (screenFile + sizeof(_standardHeader));
@@ -112,7 +113,7 @@ _cdtEntry *FetchCdtEntry(uint8 *animFile, uint16 frameNo) {
#ifdef _SWORD2_DEBUG
if (frameNo > animHead->noAnimFrames - 1)
- Con_fatal_error("FetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames);
+ error("FetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames);
#endif
return (_cdtEntry *) ((uint8 *) animHead + sizeof(_animHeader) + frameNo * sizeof(_cdtEntry));
@@ -134,7 +135,7 @@ _parallax *FetchBackgroundParallaxLayer(uint8 *screenFile, int layer) {
#ifdef _SWORD2_DEBUG
if (mscreenHeader->bg_parallax[layer] == 0)
- Con_fatal_error("FetchBackgroundParallaxLayer(%d) - No parallax layer exists", layer);
+ error("FetchBackgroundParallaxLayer(%d) - No parallax layer exists", layer);
#endif
return (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->bg_parallax[layer]);
@@ -145,7 +146,7 @@ _parallax *FetchBackgroundLayer(uint8 *screenFile) {
#ifdef _SWORD2_DEBUG
if (mscreenHeader->screen == 0)
- Con_fatal_error("FetchBackgroundLayer (%d) - No background layer exists");
+ error("FetchBackgroundLayer (%d) - No background layer exists");
#endif
return (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->screen + sizeof(_screenHeader));
@@ -156,7 +157,7 @@ _parallax *FetchForegroundParallaxLayer(uint8 *screenFile, int layer) {
#ifdef _SWORD2_DEBUG
if (mscreenHeader->fg_parallax[layer] == 0)
- Con_fatal_error("FetchForegroundParallaxLayer(%d) - No parallax layer exists", layer);
+ error("FetchForegroundParallaxLayer(%d) - No parallax layer exists", layer);
#endif
return (_parallax *) ((uint8 *) mscreenHeader + mscreenHeader->fg_parallax[layer]);
diff --git a/sword2/resman.cpp b/sword2/resman.cpp
index abd06b3c8b..679adfcc32 100644
--- a/sword2/resman.cpp
+++ b/sword2/resman.cpp
@@ -444,7 +444,7 @@ uint8 *ResourceManager::open(uint32 res) {
//#ifdef _SWORD2_DEBUG
if (res >= _totalResFiles)
- Con_fatal_error("open illegal resource %d (there are %d resources 0-%d)", res, _totalResFiles, _totalResFiles - 1);
+ error("open illegal resource %d (there are %d resources 0-%d)", res, _totalResFiles, _totalResFiles - 1);
//#endif
// is the resource in memory already?
@@ -459,7 +459,7 @@ uint8 *ResourceManager::open(uint32 res) {
//#ifdef _SWORD2_DEBUG
if (parent_res_file == 0xffff)
- Con_fatal_error("open tried to open null & void resource number %d", res);
+ error("open tried to open null & void resource number %d", res);
//#endif
// relative resource within the file
@@ -506,7 +506,7 @@ uint8 *ResourceManager::open(uint32 res) {
// open the cluster file
if (!file.open(_resourceFiles[parent_res_file]))
- Con_fatal_error("open cannot *OPEN* %s", _resourceFiles[parent_res_file]);
+ error("open cannot *OPEN* %s", _resourceFiles[parent_res_file]);
// 1st DWORD of a cluster is an offset to the look-up table
@@ -620,11 +620,11 @@ void ResourceManager::close(uint32 res) {
//#ifdef _SWORD2_DEBUG
if (res >= _totalResFiles)
- Con_fatal_error("closing illegal resource %d (there are %d resources 0-%d)", res, _totalResFiles, _totalResFiles - 1);
+ error("closing illegal resource %d (there are %d resources 0-%d)", res, _totalResFiles, _totalResFiles - 1);
//closing but isnt open?
if (!(_count[res]))
- Con_fatal_error("close: closing %d but it isn't open", res);
+ error("close: closing %d but it isn't open", res);
//#endif
//one less has it open
@@ -657,7 +657,7 @@ uint32 ResourceManager::fetchLen(uint32 res) {
// open the cluster file
if (!fh.open(_resourceFiles[parent_res_file]))
- Con_fatal_error("fetchLen cannot *OPEN* %s", _resourceFiles[parent_res_file]);
+ error("fetchLen cannot *OPEN* %s", _resourceFiles[parent_res_file]);
// 1st DWORD of a cluster is an offset to the look-up table
table_offset = fh.readUint32LE();
@@ -729,167 +729,123 @@ uint32 ResourceManager::helpTheAgedOut(void) {
}
void ResourceManager::printConsoleClusters(void) {
- uint32 j;
-
if (_totalClusters) {
- for (j = 0; j < _totalClusters; j++)
- Print_to_console(" %s", _resourceFiles[j]);
- Print_to_console(" %d resources", _totalResFiles);
+ for (uint i = 0; i < _totalClusters; i++)
+ Debug_Printf("%s\n", _resourceFiles[i]);
+ Debug_Printf("%d resources\n", _totalResFiles);
} else
- Print_to_console(" argh! No resources");
-
- Scroll_console();
+ Debug_Printf("Argh! No resources!\n");
}
-void ResourceManager::examine(uint8 *input) {
- uint32 j = 0;
- uint32 res;
+void ResourceManager::examine(int res) {
_standardHeader *file_header;
- do {
- if (input[j] >= '0' && input[j] <= '9')
- j++;
- else
+ if (res < 0 || res >= (int) _totalResFiles)
+ Debug_Printf("Illegal resource %d (there are %d resources 0-%d)\n", res, _totalResFiles, _totalResFiles - 1);
+ else if (_resConvTable[res * 2] == 0xffff)
+ Debug_Printf("%d is a null & void resource number\n", res);
+ else {
+ //open up the resource and take a look inside!
+ file_header = (_standardHeader*) res_man.open(res);
+
+ // Debug_Printf("%d\n", file_header->fileType);
+ // Debug_Printf("%s\n", file_header->name);
+
+ //----------------------------------------------------
+ // resource types: (taken from header.h)
+
+ // 1: ANIMATION_FILE
+ // all normal animations & sprites including mega-sets &
+ // font files which are the same format
+ // 2: SCREEN_FILE
+ // each contains background, palette, layer sprites,
+ // parallax layers & shading mask
+ // 3: GAME_OBJECT
+ // each contains object hub + structures + script data
+ // 4: WALK_GRID_FILE
+ // walk-grid data
+ // 5: GLOBAL_VAR_FILE
+ // all the global script variables in one file; "there can
+ // be only one"
+ // 6: PARALLAX_FILE_null
+ // NOT USED
+ // 7: RUN_LIST
+ // each contains a list of object resource ids
+ // 8: TEXT_FILE
+ // each contains all the lines of text for a location or a
+ // character's conversation script
+ // 9: SCREEN_MANAGER
+ // one for each location; this contains special startup
+ // scripts
+ // 10: MOUSE_FILE
+ // mouse pointers and luggage icons (sprites in General,
+ // Mouse pointers & Luggage icons)
+ // 11: WAV_FILE
+ // NOT USED HERE
+ // 12: ICON_FILE
+ // menu icon (sprites in General and Menu icons)
+ // 13: PALETTE_FILE
+ // NOT USED HERE
+ //----------------------------------------------------
+
+ switch (file_header->fileType) {
+ case ANIMATION_FILE:
+ Debug_Printf("<anim> %s\n", file_header->name);
+ break;
+ case SCREEN_FILE:
+ Debug_Printf("<layer> %s\n", file_header->name);
+ break;
+ case GAME_OBJECT:
+ Debug_Printf("<game object> %s\n", file_header->name);
+ break;
+ case WALK_GRID_FILE:
+ Debug_Printf("<walk grid> %s\n", file_header->name);
+ break;
+ case GLOBAL_VAR_FILE:
+ Debug_Printf("<global variables> %s\n", file_header->name);
+ break;
+ case PARALLAX_FILE_null:
+ Debug_Printf("<parallax file NOT USED!> %s\n", file_header->name);
+ break;
+ case RUN_LIST:
+ Debug_Printf("<run list> %s\n", file_header->name);
+ break;
+ case TEXT_FILE:
+ Debug_Printf("<text file> %s\n", file_header->name);
+ break;
+ case SCREEN_MANAGER:
+ Debug_Printf("<screen manager> %s\n", file_header->name);
+ break;
+ case MOUSE_FILE:
+ Debug_Printf("<mouse pointer> %s\n", file_header->name);
+ break;
+ case ICON_FILE:
+ Debug_Printf("<menu icon> %s\n", file_header->name);
+ break;
+ default:
+ Debug_Printf("unrecognised fileType %d\n", file_header->fileType);
break;
- } while(input[j]);
-
- // didn't quit out of loop on a non numeric chr$
- if (!input[j]) {
- res = atoi((char*) input);
-
- if (!res)
- Print_to_console("illegal resource");
- else if (res >= _totalResFiles)
- Print_to_console("illegal resource %d (there are %d resources 0-%d)", res, _totalResFiles, _totalResFiles - 1);
- else if (_resConvTable[res * 2] == 0xffff)
- Print_to_console("%d is a null & void resource number", res);
- else {
- //open up the resource and take a look inside!
- file_header = (_standardHeader*) res_man.open(res);
-
- // Print_to_console("%d", file_header->fileType);
- // Print_to_console("%s", file_header->name);
-
- //----------------------------------------------------
- // resource types: (taken from header.h)
-
- // 1: ANIMATION_FILE
- // all normal animations & sprites including
- // mega-sets & font files which are the same
- // format
- // 2: SCREEN_FILE
- // each contains background, palette, layer
- // sprites, parallax layers & shading mask
- // 3: GAME_OBJECT
- // each contains object hub + structures + script
- // data
- // 4: WALK_GRID_FILE
- // walk-grid data
- // 5: GLOBAL_VAR_FILE
- // all the global script variables in one file;
- // "there can be only one"
- // 6: PARALLAX_FILE_null
- // NOT USED
- // 7: RUN_LIST
- // each contains a list of object resource id's
- // 8: TEXT_FILE
- // each contains all the lines of text for a
- // location or a character's conversation script
- // 9: SCREEN_MANAGER
- // one for each location; this contains special
- // startup scripts
- // 10: MOUSE_FILE
- // mouse pointers and luggage icons (sprites in
- // General \ Mouse pointers & Luggage icons)
- // 11: WAV_FILE
- // NOT USED HERE
- // 12: ICON_FILE
- // menu icon (sprites in General \ Menu icons)
- // 13: PALETTE_FILE
- // NOT USED HERE
- //----------------------------------------------------
-
- switch (file_header->fileType) {
- case ANIMATION_FILE:
- Print_to_console(" <anim> %s", file_header->name);
- break;
- case SCREEN_FILE:
- Print_to_console(" <layer> %s", file_header->name);
- break;
- case GAME_OBJECT:
- Print_to_console(" <game object> %s", file_header->name);
- break;
- case WALK_GRID_FILE:
- Print_to_console(" <walk grid> %s", file_header->name);
- break;
- case GLOBAL_VAR_FILE:
- Print_to_console(" <global variables> %s", file_header->name);
- break;
- case PARALLAX_FILE_null:
- Print_to_console(" <parallax file NOT USED!> %s", file_header->name);
- break;
- case RUN_LIST:
- Print_to_console(" <run list> %s", file_header->name);
- break;
- case TEXT_FILE:
- Print_to_console(" <text file> %s", file_header->name);
- break;
- case SCREEN_MANAGER:
- Print_to_console(" <screen manager> %s", file_header->name);
- break;
- case MOUSE_FILE:
- Print_to_console(" <mouse pointer> %s", file_header->name);
- break;
- case ICON_FILE:
- Print_to_console(" <menu icon> %s", file_header->name);
- break;
- default:
- Print_to_console(" unrecognised fileType %d", file_header->fileType);
- break;
- }
- res_man.close(res);
}
- } else {
- Print_to_console("try typing a number");
+ res_man.close(res);
}
}
-void ResourceManager::kill(uint8 *input) {
- int j = 0;
- uint32 res;
-
- do {
- if (input[j] >= '0' && input[j] <= '9')
- j++;
- else
- break;
- } while (input[j]);
-
- // didn't quit out of loop on a non numeric chr$
- if (!input[j]) {
- res = atoi((char*) input);
-
-// #ifdef _SWORD2_DEBUG
- if (!res)
- Print_to_console("illegal resource");
-
- if (res >= _totalResFiles)
- Con_fatal_error(" llegal resource %d (there are %d resources 0-%d)", res, _totalResFiles, _totalResFiles - 1);
-// #endif
+void ResourceManager::kill(int res) {
+ if (res < 0 || res >= (int) _totalResFiles) {
+ Debug_Printf("Illegal resource %d (there are %d resources 0-%d)\n", res, _totalResFiles, _totalResFiles - 1);
+ return;
+ }
- // if noone has the file open then unlock and allow to float
- if (!_count[res]) {
- if (_age[res]) {
- _age[res] = 0; // effectively gone from _resList
- memory.freeMemory(_resList[res]); // release the memory too
- Print_to_console(" trashed %d", res);
- } else
- Print_to_console("%d not in memory", res);
+ // if noone has the file open then unlock and allow to float
+ if (!_count[res]) {
+ if (_age[res]) {
+ _age[res] = 0; // effectively gone from _resList
+ memory.freeMemory(_resList[res]); // release the memory too
+ Debug_Printf("Trashed %d\n", res);
} else
- Print_to_console(" file is open - cannot remove");
- } else {
- Print_to_console("try typing a number");
- }
+ Debug_Printf("%d not in memory\n", res);
+ } else
+ Debug_Printf("File is open - cannot remove\n");
}
void ResourceManager::remove(uint32 res) {
@@ -921,7 +877,7 @@ void ResourceManager::removeAll(void) {
} while (j != -1);
}
-void ResourceManager::killAll(uint8 wantInfo) {
+void ResourceManager::killAll(bool wantInfo) {
// remove all res files from memory
// its quicker to search the mem blocs for res files than search
// resource lists for those in memory
@@ -930,8 +886,6 @@ void ResourceManager::killAll(uint8 wantInfo) {
uint32 res;
uint32 nuked = 0;
_standardHeader *header;
- int scrolls = 0;
- _keyboardEvent ke;
j = memory._baseMemBlock;
@@ -949,40 +903,19 @@ void ResourceManager::killAll(uint8 wantInfo) {
memory.freeMemory(_resList[res]); // release the memory too
nuked++;
- // if this was called from the console + we
- // want info
- if (wantInfo && console_status) {
- Print_to_console(" nuked %5d: %s", res, header->name);
+ // if this was called from the console,
+ if (wantInfo) {
+ Debug_Printf("Nuked %5d: %s\n", res, header->name);
debug(5, " nuked %d: %s", res, header->name);
- Build_display();
-
- scrolls++;
- if (scrolls == 18) {
- Temp_print_to_console("- Press ESC to stop or any other key to continue");
- Build_display();
-
- do {
- g_display->updateDisplay();
- } while (!KeyWaiting());
-
- ReadKey(&ke);
- if (ke.keycode == 27)
- break;
-
- // clear the Press Esc message ready for the new line
- Clear_console_line();
- scrolls = 0;
- }
}
}
}
j = memory._memList[j].child;
} while (j != -1);
- // if this was called from the console + we want info!
- if (wantInfo && console_status) {
- Scroll_console();
- Print_to_console(" expelled %d resource(s)", nuked);
+ // if this was called from the console
+ if (wantInfo) {
+ Debug_Printf("Expelled %d resource(s)\n", nuked);
}
}
@@ -994,7 +927,7 @@ void ResourceManager::killAll(uint8 wantInfo) {
// disappear forever, or some plaster-filled holes in sand to crash the game &
// get James in trouble again.
-void ResourceManager::killAllObjects(uint8 wantInfo) {
+void ResourceManager::killAllObjects(bool wantInfo) {
// remove all object res files from memory, excluding George
// its quicker to search the mem blocs for res files than search
// resource lists for those in memory
@@ -1003,8 +936,6 @@ void ResourceManager::killAllObjects(uint8 wantInfo) {
uint32 res;
uint32 nuked = 0;
_standardHeader *header;
- int scrolls = 0;
- _keyboardEvent ke;
j = memory._baseMemBlock;
@@ -1022,30 +953,10 @@ void ResourceManager::killAllObjects(uint8 wantInfo) {
memory.freeMemory(_resList[res]); // release the memory too
nuked++;
- // if this was called from the console + we want info
- if (wantInfo && console_status) {
- Print_to_console(" nuked %5d: %s", res, header->name);
+ // if this was called from the console
+ if (wantInfo) {
+ Debug_Printf("Nuked %5d: %s\n", res, header->name);
debug(5, " nuked %d: %s", res, header->name);
- Build_display();
-
- scrolls++;
- if (scrolls==18) {
- Print_to_console("- Press ESC to stop or any other key to continue");
- Build_display();
-
- do {
- g_display->updateDisplay();
- } while (!KeyWaiting());
-
-
- ReadKey(&ke); //kill the key we just pressed
- if (ke.keycode == 27) // ESC
- break;
-
- // clear the Press Esc message ready for the new line
- Clear_console_line();
- scrolls = 0;
- }
}
}
}
@@ -1053,9 +964,9 @@ void ResourceManager::killAllObjects(uint8 wantInfo) {
j = memory._memList[j].child;
} while (j != -1);
- // if this was called from the console + we want info
- if (wantInfo && console_status)
- Print_to_console(" expelled %d object resource(s)", nuked);
+ // if this was called from the console
+ if (wantInfo)
+ Debug_Printf("Expelled %d object resource(s)\n", nuked);
}
void ResourceManager::cacheNewCluster(uint32 newCluster) {
@@ -1086,7 +997,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
file = fopen("cd.inf", "r+b");
if (file == NULL) {
- Con_fatal_error("init cannot *OPEN* cd.inf");
+ error("init cannot *OPEN* cd.inf");
}
_cd_inf cdInf;
@@ -1096,7 +1007,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
} while ((scumm_stricmp((char *) cdInf.clusterName, _resourceFiles[i]) != 0) && !feof(file));
if (feof(file)) {
- Con_fatal_error("cacheNewCluster cannot find %s in cd.inf", _resourceFiles[i]);
+ error("cacheNewCluster cannot find %s in cd.inf", _resourceFiles[i]);
}
fseek(file, -1, SEEK_CUR);
@@ -1140,7 +1051,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
outFile.open(_resourceFiles[newCluster], NULL, File::kFileWriteMode);
if (!inFile.isOpen() || !outFile.isOpen()) {
- Con_fatal_error("Cache new cluster could not copy %s to %s", buf, _resourceFiles[newCluster]);
+ error("Cache new cluster could not copy %s to %s", buf, _resourceFiles[newCluster]);
}
_spriteInfo textSprite;
@@ -1220,7 +1131,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
realRead = inFile.read(buffer, BUFFERSIZE);
read += realRead;
if (outFile.write(buffer, realRead) != realRead) {
- Con_fatal_error("Cache new cluster could not copy %s to %s", buf, _resourceFiles[newCluster]);
+ error("Cache new cluster could not copy %s to %s", buf, _resourceFiles[newCluster]);
}
if (step == stepSize) {
@@ -1251,7 +1162,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
} while ((read % BUFFERSIZE) == 0);
if (read != size) {
- Con_fatal_error("Cache new cluster could not copy %s to %s", buf, _resourceFiles[newCluster]);
+ error("Cache new cluster could not copy %s to %s", buf, _resourceFiles[newCluster]);
}
inFile.close();
@@ -1274,7 +1185,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
file = fopen("cd.inf", "r+b");
if (file == NULL) {
- Con_fatal_error("init cannot *OPEN* cd.inf");
+ error("init cannot *OPEN* cd.inf");
}
_cd_inf cdInf;
@@ -1284,7 +1195,7 @@ void ResourceManager::cacheNewCluster(uint32 newCluster) {
} while (scumm_stricmp((char *) cdInf.clusterName, _resourceFiles[newCluster]) != 0 && !feof(file));
if (feof(file)) {
- Con_fatal_error("cacheNewCluster cannot find %s in cd.inf", _resourceFiles[newCluster]);
+ error("cacheNewCluster cannot find %s in cd.inf", _resourceFiles[newCluster]);
}
fseek(file, -1, SEEK_CUR);
diff --git a/sword2/resman.h b/sword2/resman.h
index 522097a028..f034ed3551 100644
--- a/sword2/resman.h
+++ b/sword2/resman.h
@@ -66,10 +66,10 @@ public:
// ----console commands
void printConsoleClusters(void);
- void examine(uint8 *input);
- void kill(uint8 *res);
- void killAll(uint8 wantInfo);
- void killAllObjects(uint8 wantInfo);
+ void examine(int res);
+ void kill(int res);
+ void killAll(bool wantInfo);
+ void killAllObjects(bool wantInfo);
void remove(uint32 res);
void removeAll(void);
diff --git a/sword2/router.cpp b/sword2/router.cpp
index 8123b07529..b9e5550116 100644
--- a/sword2/router.cpp
+++ b/sword2/router.cpp
@@ -75,6 +75,7 @@
#include "stdafx.h"
#include "bs2/driver/driver96.h"
+#include "bs2/sword2.h"
#include "bs2/console.h"
#include "bs2/debug.h"
#include "bs2/defs.h"
@@ -492,7 +493,7 @@ int32 Router::smoothestPath() {
if (options == 0) {
debug(5, "BestTurns fail %d %d %d %d", _route[p].x, _route[p].y, _route[p + 1].x, _route[p + 1].y);
debug(5, "BestTurns fail %d %d %d %d", turns[0], turns[1], turns[2], options);
- Con_fatal_error("BestTurns failed");
+ error("BestTurns failed");
}
#endif
@@ -510,7 +511,7 @@ int32 Router::smoothestPath() {
if (steps == 0) {
debug(5, "BestTurns failed %d %d %d %d", _route[p].x, _route[p].y, _route[p + 1].x, _route[p + 1].y);
debug(5, "BestTurns failed %d %d %d %d", turns[0], turns[1], turns[2], options);
- Con_fatal_error("BestTurns failed");
+ error("BestTurns failed");
}
#endif
@@ -1225,7 +1226,7 @@ void Router::slidyWalkAnimator(_walkData *walkAnim) {
#ifdef _SWORD2_DEBUG
if (lastRealDir == 99)
- Con_fatal_error("slidyWalkAnimatorlast direction error");
+ error("slidyWalkAnimatorlast direction error");
#endif
// THE SLOW OUT
@@ -2522,7 +2523,6 @@ void Router::setUpWalkGrid(Object_mega *ob_mega, int32 x, int32 y, int32 dir) {
_node[_nnodes].dist = 9999;
}
-#ifdef _SWORD2_DEBUG
void Router::plotWalkGrid(void) {
int32 i;
@@ -2532,7 +2532,7 @@ void Router::plotWalkGrid(void) {
// lines
for (i = 0; i < _nbars; i++)
- DrawLine(_bars[i].x1, _bars[i].y1, _bars[i].x2, _bars[i].y2, 254);
+ g_display->drawLine(_bars[i].x1, _bars[i].y1, _bars[i].x2, _bars[i].y2, 254);
// nodes
@@ -2542,10 +2542,9 @@ void Router::plotWalkGrid(void) {
}
void Router::plotCross(int16 x, int16 y, uint8 colour) {
- DrawLine(x - 1, y - 1, x + 1, y + 1, colour);
- DrawLine(x + 1, y - 1, x - 1, y + 1, colour);
+ g_display->drawLine(x - 1, y - 1, x + 1, y + 1, colour);
+ g_display->drawLine(x + 1, y - 1, x - 1, y + 1, colour);
}
-#endif
void Router::loadWalkGrid(void) {
_walkGridHeader floorHeader;
@@ -2578,12 +2577,12 @@ void Router::loadWalkGrid(void) {
// allowed in the complete walkgrid arrays
if (_nbars + theseBars >= O_GRID_SIZE)
- Con_fatal_error("Adding walkgrid(%d): %d+%d bars exceeds max %d",
+ error("Adding walkgrid(%d): %d+%d bars exceeds max %d",
_walkGridList[i], _nbars, theseBars,
O_GRID_SIZE);
if (_nnodes + theseNodes >= O_GRID_SIZE)
- Con_fatal_error("Adding walkgrid(%d): %d+%d nodes exceeds max %d",
+ error("Adding walkgrid(%d): %d+%d nodes exceeds max %d",
_walkGridList[i], _nnodes, theseBars,
O_GRID_SIZE);
#endif
@@ -2655,7 +2654,7 @@ void Router::addWalkGrid(int32 gridResource) {
}
}
- Con_fatal_error("ERROR: _walkGridList[] full");
+ error("ERROR: _walkGridList[] full");
}
// called from fnRemoveWalkGrid
diff --git a/sword2/router.h b/sword2/router.h
index f470ac261d..68f73d33e5 100644
--- a/sword2/router.h
+++ b/sword2/router.h
@@ -211,9 +211,7 @@ private:
int32 solidWalkAnimator(_walkData *walkAnim);
#endif
-#ifdef _SWORD2_DEBUG
void plotCross(int16 x, int16 y, uint8 colour);
-#endif
public:
Router() :
@@ -233,9 +231,7 @@ public:
void removeWalkGrid(int32 gridResource);
void clearWalkGridList(void);
-#ifdef _SWORD2_DEBUG
void plotWalkGrid(void);
-#endif
};
extern Router router;
diff --git a/sword2/save_rest.cpp b/sword2/save_rest.cpp
index d5e8dca505..afedf80804 100644
--- a/sword2/save_rest.cpp
+++ b/sword2/save_rest.cpp
@@ -379,7 +379,7 @@ uint32 RestoreFromBuffer(mem *buffer, uint32 size) {
// trash all resources from memory except player object & global
// variables
- res_man.killAll(0);
+ res_man.killAll(false);
// clean out the system kill list (no more objects to kill)
g_logic.resetKillList();
@@ -517,7 +517,7 @@ void GetPlayerStructures(void) {
head = (_standardHeader*) res_man.open(CUR_PLAYER_ID);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID);
+ error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID);
raw_script_ad = (char *) head;
g_logic.runScript(raw_script_ad, raw_script_ad, &null_pc);
@@ -536,7 +536,7 @@ void PutPlayerStructures(void) {
head = (_standardHeader*) res_man.open(CUR_PLAYER_ID);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID);
+ error("incorrect CUR_PLAYER_ID=%d", CUR_PLAYER_ID);
raw_script_ad = (char *) head;
diff --git a/sword2/sound.cpp b/sword2/sound.cpp
index 18c8d8adcb..b807e5d895 100644
--- a/sword2/sound.cpp
+++ b/sword2/sound.cpp
@@ -158,9 +158,11 @@ int32 Logic::fnPlayFx(int32 *params) {
#ifdef _SWORD2_DEBUG
_standardHeader *header;
- char type[10];
+#endif
if (wantSfxDebug) {
+ char type[10];
+
switch (params[1]) { // 'type'
case FX_SPOT:
strcpy(type, "SPOT");
@@ -175,9 +177,8 @@ int32 Logic::fnPlayFx(int32 *params) {
strcpy(type, "INVALID");
}
- debug(5, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", FetchObjectName(params[0]), params[3], params[4], params[2], type);
+ debug(0, "SFX (sample=\"%s\", vol=%d, pan=%d, delay=%d, type=%s)", FetchObjectName(params[0]), params[3], params[4], params[2], type);
}
-#endif
while (j < FXQ_LENGTH && fxq[j].resource != 0)
j++;
@@ -208,7 +209,7 @@ int32 Logic::fnPlayFx(int32 *params) {
#ifdef _SWORD2_DEBUG
header = (_standardHeader*) data;
if (header->fileType != WAV_FILE)
- Con_fatal_error("fnPlayFx given invalid resource");
+ error("fnPlayFx given invalid resource");
#endif
// but then releases it to "age" out if the space is needed
@@ -224,7 +225,7 @@ int32 Logic::fnPlayFx(int32 *params) {
#ifdef _SWORD2_DEBUG
header = (_standardHeader*)data;
if (header->fileType != WAV_FILE)
- Con_fatal_error("fnPlayFx given invalid resource");
+ error("fnPlayFx given invalid resource");
#endif
data += sizeof(_standardHeader);
diff --git a/sword2/speech.cpp b/sword2/speech.cpp
index f72bbddb8d..f9a5c19377 100644
--- a/sword2/speech.cpp
+++ b/sword2/speech.cpp
@@ -208,7 +208,7 @@ int32 Logic::fnChoose(int32 *params) {
// build menus from subject_list
if (!IN_SUBJECT)
- Con_fatal_error("fnChoose with no subjects :-O");
+ error("fnChoose with no subjects :-O");
// init top menu from master list
// all icons are highlighted / full colour
@@ -361,7 +361,7 @@ int32 Logic::fnTheyDo(int32 *params) {
// request status of target
head = (_standardHeader*) res_man.open(target);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("fnTheyDo %d not an object", target);
+ error("fnTheyDo %d not an object", target);
raw_script_ad = (char *) head;
@@ -423,7 +423,7 @@ int32 Logic::fnTheyDoWeWait(int32 *params) {
head = (_standardHeader*) res_man.open(target);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("fnTheyDoWeWait %d not an object", target);
+ error("fnTheyDoWeWait %d not an object", target);
raw_script_ad = (char *) head;
@@ -503,7 +503,7 @@ int32 Logic::fnWeWait(int32 *params) {
// request status of target
head = (_standardHeader*) res_man.open(target);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("fnWeWait: %d not an object", target);
+ error("fnWeWait: %d not an object", target);
raw_script_ad = (char *) head;
@@ -551,7 +551,7 @@ int32 Logic::fnTimedWait(int32 *params) {
// request status of target
head = (_standardHeader*) res_man.open(target);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("fnTimedWait %d not an object", target);
+ error("fnTimedWait %d not an object", target);
raw_script_ad = (char *) head;
@@ -934,12 +934,10 @@ int32 Logic::fnISpeak(int32 *params) {
static uint8 cycle_skip = 0;
uint32 rv;
-#ifdef _SWORD2_DEBUG
// for text/speech testing & checking for correct file type
_standardHeader *head;
// for text/speech testing - keeping track of text resource currently being tested
static uint32 currentTextResource = 0;
-#endif
// set up the pointers which we know we'll always need
@@ -974,7 +972,6 @@ int32 Logic::fnISpeak(int32 *params) {
} else
cycle_skip = 0;
-#ifdef _SWORD2_DEBUG
textNumber = params[S_TEXT]; // for debug info
// For testing all text & speech!
@@ -1023,7 +1020,6 @@ int32 Logic::fnISpeak(int32 *params) {
return IR_CONT;
}
}
-#endif
// Pull out the text line to get the official text number
// (for wav id). Once the wav id's go into all script text
@@ -1039,7 +1035,6 @@ int32 Logic::fnISpeak(int32 *params) {
// now ok to close the text file
res_man.close(text_res);
-#ifdef _SWORD2_DEBUG
// prevent dud lines from appearing while testing text & speech
// since these will not occur in the game anyway
@@ -1052,7 +1047,6 @@ int32 Logic::fnISpeak(int32 *params) {
return IR_CONT;
}
}
-#endif
// set the 'looping_flag' & the text-click-delay
@@ -1152,7 +1146,6 @@ int32 Logic::fnISpeak(int32 *params) {
else if (speech_pan > 16)
speech_pan = 16;
-#ifdef _SWORD2_DEBUG
// if we're testing text & speech
if (SYSTEM_TESTING_TEXT) {
// if we've moved onto a new text resource,
@@ -1160,14 +1153,13 @@ int32 Logic::fnISpeak(int32 *params) {
// changing again - can only know which CD to
// get if the wavID is non-zero
- if ((text_res != currentTextResource) && params[S_WAV]) {
+ if (text_res != currentTextResource && params[S_WAV]) {
// ensure correct CD is in for this
// wavId
- GetCorrectCdForSpeech(params[S_WAV]);
+ // GetCorrectCdForSpeech(params[S_WAV]);
currentTextResource = text_res;
}
}
-#endif
// set up path to speech cluster
// first checking if we have speech1.clu or
@@ -1284,54 +1276,46 @@ int32 Logic::fnISpeak(int32 *params) {
// ok, all is running along smoothly - but a click means stop
// unnaturally
-#ifdef _SWORD2_DEBUG
// so that we can go to the options panel while text & speech is
// being tested
if (SYSTEM_TESTING_TEXT == 0 || g_display->_mouseY > 0) {
-#endif
-
- me = MouseEvent();
+ me = MouseEvent();
- // Note that we now have TWO click-delays - one for LEFT button, one
- // for RIGHT BUTTON
+ // Note that we now have TWO click-delays - one for LEFT
+ // button, one for RIGHT BUTTON
- if ((!left_click_delay && me && (me->buttons & RD_LEFTBUTTONDOWN)) ||
- (!right_click_delay && me && (me->buttons&RD_RIGHTBUTTONDOWN))) {
- // mouse click, after click_delay has expired -> end the speech
- // we ignore mouse releases
+ if ((!left_click_delay && me && (me->buttons & RD_LEFTBUTTONDOWN)) ||
+ (!right_click_delay && me && (me->buttons&RD_RIGHTBUTTONDOWN))) {
+ // mouse click, after click_delay has expired -> end
+ // the speech we ignore mouse releases
-#ifdef _SWORD2_DEBUG
- // if testing text & speech
- if (SYSTEM_TESTING_TEXT) {
- // and RB used to click past text
- if (me->buttons & RD_RIGHTBUTTONDOWN) {
- // then we want the previous line again
- SYSTEM_WANT_PREVIOUS_LINE = 1;
- } else {
- // LB just want next line again
- SYSTEM_WANT_PREVIOUS_LINE = 0;
+ // if testing text & speech
+ if (SYSTEM_TESTING_TEXT) {
+ // and RB used to click past text
+ if (me->buttons & RD_RIGHTBUTTONDOWN) {
+ // then we want the previous line again
+ SYSTEM_WANT_PREVIOUS_LINE = 1;
+ } else {
+ // LB just want next line again
+ SYSTEM_WANT_PREVIOUS_LINE = 0;
+ }
}
- }
-#endif
- do {
- // trash anything thats buffered
- me = MouseEvent();
- } while (me);
+ do {
+ // trash anything thats buffered
+ me = MouseEvent();
+ } while (me);
- speechFinished = 1;
+ speechFinished = 1;
- // if speech sample playing
- if (speechRunning) {
- // halt the sample prematurely
- g_sound->stopSpeech();
+ // if speech sample playing
+ if (speechRunning) {
+ // halt the sample prematurely
+ g_sound->stopSpeech();
+ }
}
}
-#ifdef _SWORD2_DEBUG
- }
-#endif
-
// if we are finishing the speech this cycle, do the business
// !speech_anim_type, as we want an anim which is playing once to
@@ -1358,10 +1342,8 @@ int32 Logic::fnISpeak(int32 *params) {
// no longer in a script function loop
ob_logic->looping = 0;
-#ifdef _SWORD2_DEBUG
// reset for debug info
textNumber = 0;
-#endif
// reset to zero, in case text line not even extracted (since
// this number comes from the text line)
@@ -1559,7 +1541,7 @@ void GetCorrectCdForSpeech(int32 wavId) {
uint8 cd;
if (!fp.open("cd.bin"))
- Con_fatal_error("Need cd.bin file for testing speech!");
+ error("Need cd.bin file for testing speech!");
fp.seek(wavId, SEEK_SET);
fp.read(&cd, 1);
diff --git a/sword2/startup.cpp b/sword2/startup.cpp
index 75e39c6a7f..1d7161cfce 100644
--- a/sword2/startup.cpp
+++ b/sword2/startup.cpp
@@ -146,11 +146,11 @@ int32 Logic::fnRegisterStartPoint(int32 *params) {
#ifdef _SWORD2_DEBUG
if (total_startups == MAX_starts)
- Con_fatal_error("ERROR: start_list full");
+ error("ERROR: start_list full");
// +1 to allow for NULL terminator
if (strlen((char*) params[1]) + 1 > MAX_description)
- Con_fatal_error("ERROR: startup description too long");
+ error("ERROR: startup description too long");
#endif
// this objects id
@@ -162,151 +162,94 @@ int32 Logic::fnRegisterStartPoint(int32 *params) {
strcpy(start_list[total_startups].description, (char*) params[1]);
- //point to next
+ // point to next
total_startups++;
return 1;
}
-uint32 Con_print_start_menu(void) {
+void Con_print_start_menu(void) {
// the console 'starts' (or 's') command which lists out all the
// registered start points in the game
- uint32 j;
- int scrolls = 0;
- _keyboardEvent ke;
-
if (!total_startups) {
- Print_to_console("Sorry - no startup positions registered?");
+ Debug_Printf("Sorry - no startup positions registered?\n");
if (!total_screen_managers)
- Print_to_console("There is a problem with startup.inf");
+ Debug_Printf("There is a problem with startup.inf\n");
else
- Print_to_console(" (%d screen managers found in startup.inf)", total_screen_managers);
+ Debug_Printf(" (%d screen managers found in startup.inf)\n", total_screen_managers);
} else {
- for(j = 0; j < total_startups; j++) {
- Print_to_console("%d (%s)", j, start_list[j].description);
- Build_display();
- scrolls++;
-
- if (scrolls == 18) {
- Temp_print_to_console("- Press ESC to stop or any other key to continue");
- Build_display();
-
- do {
- // Service windows
- g_display->updateDisplay();
- } while (!KeyWaiting());
-
- // kill the key we just pressed
- ReadKey(&ke);
- if (ke.keycode == 27)
- break;
-
- // clear the Press Esc message ready for the
- // new line
-
- Clear_console_line();
- scrolls = 0;
- }
- }
+ for (uint i = 0; i < total_startups; i++)
+ Debug_Printf("%d (%s)\n", i, start_list[i].description);
}
- return 1;
}
-uint32 Con_start(uint8 *input) {
- // if the second word id is a numeric that can be applied to a
- // genuine startup then do it
-
- uint32 j = 0;
- uint32 start;
+void Con_start(int start) {
char *raw_script;
char *raw_data_ad;
uint32 null_pc;
- // so that typing 'S' then <enter> works on NT
- if (input[0] == 0) {
- Con_print_start_menu();
- return 1;
- }
+ if (!total_startups)
+ Debug_Printf("Sorry - there are no startups!\n");
+ else if (start >= 0 && start < (int) total_startups) {
+ // do the startup as we've specified a legal start
- while (input[j]) {
- if (isdigit(input[j]))
- j++;
- else
- break;
- }
+ // restarting - stop sfx, music & speech!
- //didn't quit out of loop on a non numeric chr$
- if (!input[j]) {
- start = atoi((char*) input);
+ Clear_fx_queue();
- if (!total_startups)
- Print_to_console("Sorry - there are no startups!");
- else if (start < total_startups) {
- // do the startup as we've specified a legal start
+ // fade out any music that is currently playing
+ g_logic.fnStopMusic(NULL);
- // restarting - stop sfx, music & speech!
+ // halt the sample prematurely
+ g_sound->unpauseSpeech();
+ g_sound->stopSpeech();
- Clear_fx_queue();
+ // clean out all resources & flags, ready for a total
+ // restart (James24mar97)
- // fade out any music that is currently playing
- g_logic.fnStopMusic(NULL);
+ // remove all resources from memory, including player
+ // object & global variables
- // halt the sample prematurely
- g_sound->unpauseSpeech();
- g_sound->stopSpeech();
+ res_man.removeAll();
- // clean out all resources & flags, ready for a total
- // restart (James24mar97)
+ // reopen global variables resource & send address to
+ // interpreter - it won't be moving
+ g_logic.setGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
+ res_man.close(1);
- // remove all resources from memory, including player
- // object & global variables
+ // free all the route memory blocks from previous game
+ router.freeAllRouteMem();
- res_man.removeAll();
-
- // reopen global variables resource & send address to
- // interpreter - it won't be moving
- g_logic.setGlobalInterpreterVariables((int32 *) (res_man.open(1) + sizeof(_standardHeader)));
- res_man.close(1);
-
- // free all the route memory blocks from previous game
- router.freeAllRouteMem();
-
- // if there was speech text, kill the text block
- if (speech_text_bloc_no) {
- fontRenderer.killTextBloc(speech_text_bloc_no);
- speech_text_bloc_no = 0;
- }
+ // if there was speech text, kill the text block
+ if (speech_text_bloc_no) {
+ fontRenderer.killTextBloc(speech_text_bloc_no);
+ speech_text_bloc_no = 0;
+ }
- // set the key
+ // set the key
- // Open George
- raw_data_ad = (char *) (res_man.open(8));
- raw_script = (char *) (res_man.open(start_list[start].start_res_id));
+ // Open George
+ raw_data_ad = (char *) res_man.open(8);
+ raw_script = (char *) res_man.open(start_list[start].start_res_id);
- // denotes script to run
- null_pc = start_list[start].key & 0xffff;
+ // denotes script to run
+ null_pc = start_list[start].key & 0xffff;
- Print_to_console("running start %d", start);
- g_logic.runScript(raw_script, raw_data_ad, &null_pc);
+ Debug_Printf("Running start %d\n", start);
+ g_logic.runScript(raw_script, raw_data_ad, &null_pc);
- res_man.close(start_list[start].start_res_id);
+ res_man.close(start_list[start].start_res_id);
- // Close George
- res_man.close(8);
+ // Close George
+ res_man.close(8);
- // make sure thre's a mouse, in case restarting while
- // mouse not available
- g_logic.fnAddHuman(NULL);
- } else
- Print_to_console("not a legal start position");
- } else {
- // so that typing 'S' then <enter> works under Win95
- Con_print_start_menu();
- }
-
- return 1;
+ // make sure thre's a mouse, in case restarting while
+ // mouse not available
+ g_logic.fnAddHuman(NULL);
+ } else
+ Debug_Printf("Not a legal start position\n");
}
} // End of namespace Sword2
diff --git a/sword2/startup.h b/sword2/startup.h
index ab36f278bd..aaf3588655 100644
--- a/sword2/startup.h
+++ b/sword2/startup.h
@@ -39,8 +39,8 @@ typedef struct {
extern _startup start_list[MAX_starts];
uint32 Init_start_menu(void);
-uint32 Con_print_start_menu(void);
-uint32 Con_start(uint8 *input);
+void Con_print_start_menu(void);
+void Con_start(int start);
} // End of namespace Sword2
diff --git a/sword2/sword2.cpp b/sword2/sword2.cpp
index c6bee075c7..99b0fd3ab4 100644
--- a/sword2/sword2.cpp
+++ b/sword2/sword2.cpp
@@ -48,6 +48,11 @@
#include "bs2/driver/driver96.h"
#include "bs2/driver/palette.h"
+#ifdef _WIN32_WCE
+extern bool isSmartphone(void);
+#endif
+
+extern NewGui *g_gui;
extern uint16 _debugLevel;
static const GameSettings sword2_settings[] = {
@@ -102,26 +107,6 @@ namespace Sword2 {
uint8 quitGame = 0;
-// version & owner details
-
-// So version string is 18 bytes long :
-// Version String = <8 byte header,5 character version, \0, INT32 time>
-
-uint8 version_string[HEAD_LEN + 10] = { 1, 255, 37, 22, 45, 128, 34, 67 };
-
-uint8 unencoded_name[HEAD_LEN + 48] = {
- 76, 185, 205, 23, 44, 34, 24, 34,
- 'R','e','v','o','l','u','t','i','o','n',' ',
- 'S','o','f','t','w','a','r','e',' ','L','t','d',
- 0 };
-
-uint8 encoded_name[HEAD_LEN + 48] = {
- 44, 32, 190, 222, 123, 65, 233, 99,
- 179, 209, 225, 157, 222, 238, 219, 209, 143, 224, 133, 190,
- 232, 209, 162, 177, 198, 228, 202, 146, 180, 232, 214, 65,
- 65, 65, 116, 104, 116, 114, 107, 104, 32, 49, 64, 35, 123,
- 125, 61, 45, 41, 40, 163, 36, 49, 123, 125, 10 };
-
uint8 gamePaused = 0;
uint8 graphics_level_fudged = 0;
uint8 stepOneCycle = 0; // for use while game paused
@@ -132,9 +117,12 @@ Display *g_display = NULL;
Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
: Engine(detector, syst) {
-
+
_detector = detector;
g_sword2 = this;
+ _newgui = NULL;
+ _debuggerDialog = NULL;
+ _debugger = NULL;
_features = detector->_game.features;
_gameId = detector->_game.id;
_targetName = strdup(detector->_targetName.c_str());
@@ -154,16 +142,33 @@ Sword2Engine::Sword2Engine(GameDetector *detector, OSystem *syst)
g_sound = _sound = new Sound(_mixer);
g_display = _display = new Display(640, 480);
+
+ _newgui = g_gui;
+ _debugger = new Debugger(this);
}
Sword2Engine::~Sword2Engine() {
free(_targetName);
delete _sound;
delete _display;
+ delete _debugger;
}
void Sword2Engine::errorString(const char *buf1, char *buf2) {
strcpy(buf2, buf1);
+
+#ifdef _WIN32_WCE
+ if (isSmartphone())
+ return;
+#endif
+
+ // Unless an error -originated- within the debugger, spawn the debugger. Otherwise
+ // exit out normally.
+ if (!_debugger->isAttached()) {
+ printf("%s\n", buf2); // (Print it again in case debugger segfaults)
+ _debugger->attach(buf2);
+ _debugger->onFrame();
+ }
}
int32 Sword2Engine::InitialiseGame(void) {
@@ -200,17 +205,10 @@ int32 Sword2Engine::InitialiseGame(void) {
debug(5, "CALLING: initialiseFontResourceFlags");
initialiseFontResourceFlags();
- // set up the console system
-
- debug(5, "CALLING: Init_console");
- Init_console();
-
-#ifdef _SWORD2_DEBUG
// read in all the startup information
debug(5, "CALLING: Init_start_menu");
Init_start_menu();
-#endif
debug(5, "CALLING: Init_sync_system");
Init_sync_system();
@@ -248,7 +246,7 @@ void Close_game() {
int32 GameCycle(void) {
// do one game cycle
- //got a screen to run?
+ // got a screen to run?
if (g_logic.getRunList()) {
//run the logic session UNTIL a full loop has been performed
do {
@@ -265,8 +263,7 @@ int32 GameCycle(void) {
} while (g_logic.processSession());
} else {
// start the console and print the start options perhaps?
- StartConsole();
- Print_to_console("AWAITING START COMMAND: (Enter 's 1' then 'q' to start from beginning)");
+ g_sword2->_debugger->attach("AWAITING START COMMAND: (Enter 's 1' then 'q' to start from beginning)");
}
// if this screen is wide, recompute the scroll offsets every cycle
@@ -320,6 +317,9 @@ void Sword2Engine::go() {
g_display->initialiseRenderCycle();
while (1) {
+ if (_debugger->isAttached())
+ _debugger->onFrame();
+
g_display->updateDisplay();
#ifdef _SWORD2_DEBUG
@@ -329,93 +329,79 @@ void Sword2Engine::go() {
// GrabScreenShot();
#endif
+ // the screen is build. Mostly because of first scroll
+ // cycle stuff
+
#ifdef _SWORD2_DEBUG
- if (console_status) {
- if (One_console()) {
- EndConsole();
- UnpauseAllSound(); // see sound.cpp
- }
+ // if we've just stepped forward one cycle while the
+ // game was paused
+
+ if (stepOneCycle) {
+ PauseGame();
+ stepOneCycle = 0;
}
#endif
- // not in console mode - if the console is quit we want to get
- // a logic cycle in before
-
- if (!console_status) {
- // the screen is build. Mostly because of first scroll
- // cycle stuff
+ if (KeyWaiting()) {
+ ReadKey(&ke);
-#ifdef _SWORD2_DEBUG
- // if we've just stepped forward one cycle while the
- // game was paused
+ char c = toupper(ke.ascii);
- if (stepOneCycle) {
- PauseGame();
- stepOneCycle = 0;
+ if (ke.modifiers == OSystem::KBD_CTRL) {
+ if (ke.keycode == 'd') {
+ _debugger->attach();
+ }
}
-#endif
- if (KeyWaiting()) {
- ReadKey(&ke);
+ if (c == '~' || c == '#')
+ _debugger->attach();
- char c = toupper(ke.ascii);
-
-#ifdef _SWORD2_DEBUG
- // ESC whether paused or not
- if (ke.keycode == 27) {
- PauseAllSound(); // see sound.cpp
- StartConsole(); // start the console
- } else
-#endif
- if (gamePaused) { // if currently paused
- if (c == 'P') {
- // 'P' while paused = unpause!
- UnpauseGame();
- }
-#ifdef _SWORD2_DEBUG
- // frame-skipping only allowed on
- // debug version
-
- else if (c == ' ') {
- // SPACE bar while paused =
- // step one frame!
- stepOneCycle = 1;
- UnpauseGame();
- }
-#endif
- } else if (c == 'P') {
- // 'P' while not paused = pause!
- PauseGame();
- } else if (c == 'C' && _gameId == GID_SWORD2) {
- g_logic.fnPlayCredits(NULL);
+ if (gamePaused) { // if currently paused
+ if (c == 'P') {
+ // 'P' while paused = unpause!
+ UnpauseGame();
}
#ifdef _SWORD2_DEBUG
- else if (c == 'S') {
- // 'S' toggles speed up (by skipping
- // display rendering)
- renderSkip = 1 - renderSkip;
+ // frame-skipping only allowed on
+ // debug version
+
+ else if (c == ' ') {
+ // SPACE bar while paused =
+ // step one frame!
+ stepOneCycle = 1;
+ UnpauseGame();
}
#endif
+ } else if (c == 'P') {
+ // 'P' while not paused = pause!
+ PauseGame();
+ } else if (c == 'C' && _gameId == GID_SWORD2) {
+ g_logic.fnPlayCredits(NULL);
}
-
- // skip GameCycle if we're paused
- if (gamePaused == 0) {
#ifdef _SWORD2_DEBUG
- gameCycle++;
-#endif
-
- if (GameCycle()) {
- // break out of main game loop
- break;
- }
+ else if (c == 'S') {
+ // 'S' toggles speed up (by skipping
+ // display rendering)
+ renderSkip = 1 - renderSkip;
}
+#endif
+ }
+ // skip GameCycle if we're paused
+ if (gamePaused == 0) {
#ifdef _SWORD2_DEBUG
- // creates the debug text blocks
- Build_debug_text();
+ gameCycle++;
#endif
+
+ if (GameCycle()) {
+ // break out of main game loop
+ break;
+ }
}
+ // creates the debug text blocks
+ Build_debug_text();
+
#ifdef _SWORD2_DEBUG
// if not in console & 'renderSkip' is set, only render
// display once every 4 game-cycles
diff --git a/sword2/sword2.h b/sword2/sword2.h
index 08147152a2..9ce7c04cbb 100644
--- a/sword2/sword2.h
+++ b/sword2/sword2.h
@@ -25,6 +25,8 @@
#include "common/map.h"
#include "common/rect.h"
#include "common/str.h"
+#include "gui/console.h"
+#include "bs2/console.h"
#include "bs2/driver/d_sound.h"
#include "bs2/driver/d_draw.h"
@@ -53,11 +55,6 @@ void UnpauseGame(void);
void sleepUntil(int32 time);
-#define HEAD_LEN 8
-
-extern uint8 version_string[]; // for displaying from the console
-extern uint8 unencoded_name[];
-
// TODO move stuff into class
class Sword2Engine : public Engine {
@@ -77,8 +74,14 @@ public:
uint32 _features;
byte _gameId;
char *_targetName; // target name for saves
+
Sound *_sound;
Display *_display;
+
+ NewGui *_newgui;
+ Debugger *_debugger;
+ ConsoleDialog *_debuggerDialog;
+
Common::RandomSource _rnd;
uint32 _speechFontId;
diff --git a/sword2/walker.cpp b/sword2/walker.cpp
index 11e0d6a3cf..e35c715e28 100644
--- a/sword2/walker.cpp
+++ b/sword2/walker.cpp
@@ -93,7 +93,7 @@ int32 Logic::fnWalk(int32 *params) {
// invalid direction (NB. '8' means end walk on ANY direction)
if (params[6] < 0 || params[6] > 8)
- Con_fatal_error("Invalid direction (%d) in fnWalk", params[6]);
+ error("Invalid direction (%d) in fnWalk", params[6]);
ob_walkdata = (Object_walkdata *) params[3];
@@ -290,7 +290,7 @@ int32 Logic::fnWalkToAnim(int32 *params) {
}
if (pars[6] < 0 || pars[6] > 7)
- Con_fatal_error("Invalid direction (%d) in fnWalkToAnim", pars[6]);
+ error("Invalid direction (%d) in fnWalkToAnim", pars[6]);
}
// set up the rest of the parameters for fnWalk()
@@ -331,7 +331,7 @@ int32 Logic::fnTurn(int32 *params) {
if (ob_logic->looping == 0) {
if (params[4] < 0 || params[4] > 7)
- Con_fatal_error("Invalid direction (%d) in fnTurn", params[4]);
+ error("Invalid direction (%d) in fnTurn", params[4]);
ob_mega = (Object_mega *) params[2];
@@ -370,7 +370,7 @@ int32 Logic::fnStandAt(int32 *params) {
// check for invalid direction
if (params[4] < 0 || params[4] > 7)
- Con_fatal_error("Invalid direction (%d) in fnStandAt", params[4]);
+ error("Invalid direction (%d) in fnStandAt", params[4]);
// set up pointers to the graphic & mega structure
@@ -454,7 +454,7 @@ int32 Logic::fnStandAfterAnim(int32 *params) {
}
if (pars[4] < 0 || pars[4] > 7)
- Con_fatal_error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
+ error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
// close the anim file
res_man.close(params[2]);
@@ -501,7 +501,7 @@ int32 Logic::fnStandAtAnim(int32 *params) {
}
if (pars[4] < 0 || pars[4] > 7)
- Con_fatal_error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
+ error("Invalid direction (%d) in fnStandAfterAnim", pars[4]);
// close the anim file
res_man.close(params[2]);
@@ -606,7 +606,7 @@ int32 Logic::fnFaceMega(int32 *params) {
head = (_standardHeader*) res_man.open(params[4]);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("fnFaceMega %d not an object", params[4]);
+ error("fnFaceMega %d not an object", params[4]);
raw_script_ad = (char *) head;
@@ -668,7 +668,7 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) {
head = (_standardHeader*) res_man.open(params[4]);
if (head->fileType != GAME_OBJECT)
- Con_fatal_error("fnWalkToTalkToMega %d not an object", params[4]);
+ error("fnWalkToTalkToMega %d not an object", params[4]);
raw_script_ad = (char *) head;
@@ -721,7 +721,7 @@ int32 Logic::fnWalkToTalkToMega(int32 *params) {
int32 Logic::fnSetWalkGrid(int32 *params) {
// params: none
- Con_fatal_error("fnSetWalkGrid no longer valid");
+ error("fnSetWalkGrid no longer valid");
return IR_CONT;
}
@@ -764,7 +764,7 @@ int32 Logic::fnRemoveWalkGrid(int32 *params) {
int32 Logic::fnRegisterWalkGrid(int32 *params) {
// params: none
- Con_fatal_error("fnRegisterWalkGrid no longer valid");
+ error("fnRegisterWalkGrid no longer valid");
return IR_CONT;
}
@@ -797,7 +797,7 @@ int32 Logic::fnSetStandbyCoords(int32 *params) {
// 2 direction (0..7)
if (params[2] < 0 || params[2] > 7)
- Con_fatal_error("Invalid direction (%d) in fnSetStandbyCoords", params[2]);
+ error("Invalid direction (%d) in fnSetStandbyCoords", params[2]);
standby_x = (int16) params[0];
standby_y = (int16) params[1];