[Scummvm-git-logs] scummvm master -> 97d4a60cfb635f59c2e35e144ce3337046f84977

dreammaster paulfgilbert at gmail.com
Tue Jul 30 07:05:55 CEST 2019


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
a04bdb3d7c GLK: Added skeleton debugger
97d4a60cfb GLK: Implemented debugger dumppic command


Commit: a04bdb3d7c77897f562c65166dcf30a82d1825b7
    https://github.com/scummvm/scummvm/commit/a04bdb3d7c77897f562c65166dcf30a82d1825b7
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-07-29T22:05:19-07:00

Commit Message:
GLK: Added skeleton debugger

Changed paths:
  A engines/glk/debugger.cpp
  A engines/glk/debugger.h
    engines/glk/events.cpp
    engines/glk/glk.cpp
    engines/glk/glk.h
    engines/glk/module.mk


diff --git a/engines/glk/debugger.cpp b/engines/glk/debugger.cpp
new file mode 100644
index 0000000..57188db
--- /dev/null
+++ b/engines/glk/debugger.cpp
@@ -0,0 +1,60 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "common/file.h"
+#include "glk/glk.h"
+#include "glk/debugger.h"
+
+namespace Glk {
+
+Debugger::Debugger(GlkEngine *vm) : GUI::Debugger(), _vm(vm) {
+	registerCmd("dumppic", WRAP_METHOD(Debugger, cmdExit));
+}
+
+int Debugger::strToInt(const char *s) {
+	if (!*s)
+		// No string at all
+		return 0;
+	else if (toupper(s[strlen(s) - 1]) != 'H')
+		// Standard decimal string
+		return atoi(s);
+
+	// Hexadecimal string
+	uint tmp = 0;
+	int read = sscanf(s, "%xh", &tmp);
+	if (read < 1)
+		error("strToInt failed on string \"%s\"", s);
+	return (int)tmp;
+}
+
+bool Debugger::cmdDumpPic(int argc, const char **argv) {
+	if (argc != 2) {
+		debugPrintf("Format: dumppic <picture number>");
+	} else {
+		int picNum = strToInt(argv[1]);
+		warning("TODO: dumpPic %d", picNum);
+	}
+
+	return true;
+}
+
+} // End of namespace Glk
diff --git a/engines/glk/debugger.h b/engines/glk/debugger.h
new file mode 100644
index 0000000..d09ef99
--- /dev/null
+++ b/engines/glk/debugger.h
@@ -0,0 +1,52 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef GLK_DEBUGGER_H
+#define GLK_DEBUGGER_H
+
+#include "common/scummsys.h"
+#include "gui/debugger.h"
+
+namespace Glk {
+
+class GlkEngine;
+
+class Debugger : public GUI::Debugger {
+private:
+	GlkEngine *_vm;
+
+	/**
+	 * Dump a picture
+	 */
+	bool cmdDumpPic(int argc, const char **argv);
+protected:
+	/**
+	 * Convert a numeric string to an integer
+	 */
+	int strToInt(const char *s);
+public:
+	Debugger(GlkEngine *vm);
+};
+
+} // End of namespace Glk
+
+#endif
diff --git a/engines/glk/events.cpp b/engines/glk/events.cpp
index efcf2c5..ba132b5 100644
--- a/engines/glk/events.cpp
+++ b/engines/glk/events.cpp
@@ -184,12 +184,20 @@ void Events::pollEvents() {
 		g_system->getEventManager()->pollEvent(event);
 
 		switch (event.type) {
-		case Common::EVENT_KEYDOWN:
-			if (!isModifierKey(event.kbd.keycode)) {
+		case Common::EVENT_KEYDOWN: {
+			// Check for debugger
+			Debugger *dbg = g_vm->_debugger;
+			if (dbg && event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL)) {
+				// Attach to the debugger
+				dbg->attach();
+				dbg->onFrame();
+			} else if (!isModifierKey(event.kbd.keycode)) {
+				// Handle all other keypresses
 				setCursor(CURSOR_NONE);
 				handleKeyDown(event.kbd);
 			}
 			return;
+		}
 
 		case Common::EVENT_LBUTTONDOWN:
 		case Common::EVENT_RBUTTONDOWN:
diff --git a/engines/glk/glk.cpp b/engines/glk/glk.cpp
index 455c42b..892094a 100644
--- a/engines/glk/glk.cpp
+++ b/engines/glk/glk.cpp
@@ -47,7 +47,7 @@ GlkEngine *g_vm;
 
 GlkEngine::GlkEngine(OSystem *syst, const GlkGameDescription &gameDesc) :
 		_gameDescription(gameDesc), Engine(syst), _random("Glk"), _blorb(nullptr),
-		_clipboard(nullptr), _conf(nullptr), _events(nullptr), _pictures(nullptr),
+		_clipboard(nullptr), _conf(nullptr), _debugger(nullptr), _events(nullptr), _pictures(nullptr),
 		_screen(nullptr), _selection(nullptr), _sounds(nullptr), _windows(nullptr),
 		_copySelect(false), _terminated(false), _pcSpeaker(nullptr),
 		gli_register_obj(nullptr), gli_unregister_obj(nullptr), gli_register_arr(nullptr),
@@ -65,6 +65,7 @@ GlkEngine::~GlkEngine() {
 	delete _blorb;
 	delete _clipboard;
 	delete _conf;
+	delete _debugger;
 	delete _events;
 	delete _pcSpeaker;
 	delete _pictures;
@@ -79,6 +80,7 @@ void GlkEngine::initialize() {
 	initGraphicsMode();
 
 	_conf = new Conf(getInterpreterType());
+	_debugger = createDebugger();
 	_screen = createScreen();
 	_screen->initialize();
 	_clipboard = new Clipboard();
diff --git a/engines/glk/glk.h b/engines/glk/glk.h
index 9c65fca..e6516f1 100644
--- a/engines/glk/glk.h
+++ b/engines/glk/glk.h
@@ -28,6 +28,7 @@
 #include "common/system.h"
 #include "common/serializer.h"
 #include "engines/engine.h"
+#include "glk/debugger.h"
 #include "glk/glk_types.h"
 #include "glk/streams.h"
 #include "glk/pc_speaker.h"
@@ -99,6 +100,13 @@ protected:
 	virtual Screen *createScreen();
 
 	/**
+	 * Creates a debugger instance
+	 */
+	virtual Debugger *createDebugger() {
+		return new Debugger(this);
+	}
+
+	/**
 	 * Main game loop for the individual interpreters
 	 */
 	virtual void runGame() = 0;
@@ -106,6 +114,7 @@ public:
 	Blorb *_blorb;
 	Clipboard *_clipboard;
 	Conf *_conf;
+	Debugger *_debugger;
 	Events *_events;
 	Pictures *_pictures;
 	Screen *_screen;
diff --git a/engines/glk/module.mk b/engines/glk/module.mk
index e3c329a..8c15aa7 100644
--- a/engines/glk/module.mk
+++ b/engines/glk/module.mk
@@ -3,6 +3,7 @@ MODULE := engines/glk
 MODULE_OBJS := \
 	blorb.o \
 	conf.o \
+	debugger.o \
 	detection.o \
 	events.o \
 	fonts.o \


Commit: 97d4a60cfb635f59c2e35e144ce3337046f84977
    https://github.com/scummvm/scummvm/commit/97d4a60cfb635f59c2e35e144ce3337046f84977
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2019-07-29T22:05:19-07:00

Commit Message:
GLK: Implemented debugger dumppic command

Changed paths:
    engines/glk/debugger.cpp
    engines/glk/debugger.h


diff --git a/engines/glk/debugger.cpp b/engines/glk/debugger.cpp
index 57188db..2f13f6b 100644
--- a/engines/glk/debugger.cpp
+++ b/engines/glk/debugger.cpp
@@ -20,14 +20,17 @@
  *
  */
 
-#include "common/file.h"
-#include "glk/glk.h"
 #include "glk/debugger.h"
+#include "glk/glk.h"
+#include "glk/raw_decoder.h"
+#include "common/file.h"
+#include "graphics/managed_surface.h"
+#include "image/png.h"
 
 namespace Glk {
 
 Debugger::Debugger(GlkEngine *vm) : GUI::Debugger(), _vm(vm) {
-	registerCmd("dumppic", WRAP_METHOD(Debugger, cmdExit));
+	registerCmd("dumppic", WRAP_METHOD(Debugger, cmdDumpPic));
 }
 
 int Debugger::strToInt(const char *s) {
@@ -48,13 +51,90 @@ int Debugger::strToInt(const char *s) {
 
 bool Debugger::cmdDumpPic(int argc, const char **argv) {
 	if (argc != 2) {
-		debugPrintf("Format: dumppic <picture number>");
+		debugPrintf("Format: dumppic <picture number>\n");
 	} else {
+		Common::File f;
 		int picNum = strToInt(argv[1]);
-		warning("TODO: dumpPic %d", picNum);
+
+		Common::String filename = Common::String::format("pic%d.png", picNum);
+		if (!f.exists(filename))
+			filename = Common::String::format("pic%d.jpg", picNum);
+
+		if (f.open(filename)) {
+			// png or jpeg file
+			Common::DumpFile df;
+			if (df.open(filename)) {
+				// Write out a copy of the file
+				byte *data = new byte[f.size()];
+				f.read(data, f.size());
+				df.write(data, f.size());
+				delete[] data;
+				df.close();
+
+				debugPrintf("Dumped picture\n");
+			} else {
+				debugPrintf("Could not find specified picture\n");
+			}
+		} else if (f.exists(Common::String::format("pic%d.rect"))) {
+			debugPrintf("Picture is only a placeholder rectangle\n");
+		} else if (f.open(Common::String::format("pic%d.raw", picNum))) {
+			// Raw picture
+#ifdef USE_PNG
+			Common::DumpFile df;
+			RawDecoder rd;
+
+			if (rd.loadStream(f) && df.open(Common::String::format("pic%d.png", picNum))) {
+				saveRawPicture(rd, df);
+				debugPrintf("Dumped picture\n");
+			} else {
+				debugPrintf("Couldn't save picture\n");
+			}
+#else
+			debugPrintf("PNG support needed to dump raw pictures\n");
+#endif
+		} else {
+			debugPrintf("No such picture exists\n");
+		}
 	}
 
 	return true;
 }
 
+void Debugger::saveRawPicture(const RawDecoder &rd, Common::WriteStream &ws) {
+#ifdef USE_PNG
+	const Graphics::Surface *surface = rd.getSurface();
+	const byte *palette = rd.getPalette();
+	int paletteCount = rd.getPaletteColorCount();
+	int palStart = rd.getPaletteStartIndex();
+	int transColor = rd.getTransparentColor();
+
+	// If the image doesn't have a palette, we can directly write out the image
+	if (!palette) {
+		Image::writePNG(ws, *surface);
+		return;
+	}
+
+	// Create a new RGBA temporary surface
+	Graphics::PixelFormat format(4, 8, 8, 8, 8, 24, 16, 8, 0);
+	Graphics::ManagedSurface destSurface(surface->w, surface->h, format);
+
+	for (uint y = 0; y < surface->h; ++y) {
+		const byte *srcP = (const byte *)surface->getBasePtr(0, y);
+		uint32 *destP = (uint32 *)destSurface.getBasePtr(0, y);
+
+		for (uint x = 0; x < surface->w; ++x, ++srcP, ++destP) {
+			if ((int)*srcP == transColor || (int)*srcP < palStart) {
+				*destP = format.ARGBToColor(0, 0, 0, 0);
+			} else {
+				assert(*srcP < paletteCount);
+				const byte *palP = &palette[*srcP * 3];
+				*destP = format.ARGBToColor(255, palP[0], palP[1], palP[2]);
+			}
+		}
+	}
+
+	Image::writePNG(ws, destSurface);
+#endif
+}
+
 } // End of namespace Glk
diff --git a/engines/glk/debugger.h b/engines/glk/debugger.h
index d09ef99..0555829 100644
--- a/engines/glk/debugger.h
+++ b/engines/glk/debugger.h
@@ -24,7 +24,9 @@
 #define GLK_DEBUGGER_H
 
 #include "common/scummsys.h"
+#include "common/stream.h"
 #include "gui/debugger.h"
+#include "glk/raw_decoder.h"
 
 namespace Glk {
 
@@ -35,6 +37,11 @@ private:
 	GlkEngine *_vm;
 
 	/**
+	 * Saves a decoded raw image to a PNG file
+	 */
+	void saveRawPicture(const RawDecoder &rd, Common::WriteStream &ws);
+
+	/**
 	 * Dump a picture
 	 */
 	bool cmdDumpPic(int argc, const char **argv);





More information about the Scummvm-git-logs mailing list