diff options
author | Paul Gilbert | 2019-04-16 21:21:58 -0700 |
---|---|---|
committer | Paul Gilbert | 2019-04-17 20:46:07 -0700 |
commit | 936b9731536d914c35b9632e919b510f3ae46506 (patch) | |
tree | 02dbbcb04a44cc17f66e04950fe15d20f0145b88 /engines/glk/glulxe/vm.cpp | |
parent | ee8362cc073a02c91038add400f67dc2e6dba683 (diff) | |
download | scummvm-rg350-936b9731536d914c35b9632e919b510f3ae46506.tar.gz scummvm-rg350-936b9731536d914c35b9632e919b510f3ae46506.tar.bz2 scummvm-rg350-936b9731536d914c35b9632e919b510f3ae46506.zip |
GLK: GLULXE: Add miscellaneous missing methods
Diffstat (limited to 'engines/glk/glulxe/vm.cpp')
-rw-r--r-- | engines/glk/glulxe/vm.cpp | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/engines/glk/glulxe/vm.cpp b/engines/glk/glulxe/vm.cpp index f332c92248..eb4b1121b4 100644 --- a/engines/glk/glulxe/vm.cpp +++ b/engines/glk/glulxe/vm.cpp @@ -20,43 +20,38 @@ * */ -#include "engines/glk/glulxe/glulxe.h" +#include "glk/glulxe/glulxe.h" namespace Glk { namespace Glulxe { void Glulxe::setup_vm() { - unsigned char buf[4 * 7]; - int res; + byte buf[4 * 7]; - pc = 0; /* Clear this, so that error messages are cleaner. */ + pc = 0; // Clear this, so that error messages are cleaner. prevpc = 0; - /* Read in all the size constants from the game file header. */ - - stream_char_handler = NULL; - stream_unichar_handler = NULL; + // Read in all the size constants from the game file header + stream_char_handler = nullptr; + stream_unichar_handler = nullptr; - glk_stream_set_position(gamefile, gamefile_start+8, seekmode_Start); - res = glk_get_buffer_stream(gamefile, (char *)buf, 4 * 7); - if (res != 4 * 7) { + _gameFile.seek(0); + if (_gameFile.read(buf, 4 * 7) != (4 * 7)) fatal_error("The game file header is too short."); - } - ramstart = Read4(buf+0); - endgamefile = Read4(buf+4); - origendmem = Read4(buf+8); - stacksize = Read4(buf+12); - startfuncaddr = Read4(buf+16); - origstringtable = Read4(buf+20); - checksum = Read4(buf+24); - - /* Set the protection range to (0, 0), meaning "off". */ + ramstart = Read4(buf + 0); + endgamefile = Read4(buf + 4); + origendmem = Read4(buf + 8); + stacksize = Read4(buf + 12); + startfuncaddr = Read4(buf + 16); + origstringtable = Read4(buf + 20); + checksum = Read4(buf + 24); + + // Set the protection range to (0, 0), meaning "off". protectstart = 0; protectend = 0; - /* Do a few sanity checks. */ - + // Do a few sanity checks. if ((ramstart & 0xFF) || (endgamefile & 0xFF) || (origendmem & 0xFF) @@ -81,28 +76,29 @@ void Glulxe::setup_vm() { /* Allocate main memory and the stack. This is where memory allocation errors are most likely to occur. */ endmem = origendmem; - memmap = (unsigned char *)glulx_malloc(origendmem); + memmap = (byte *)glulx_malloc(origendmem); if (!memmap) { fatal_error("Unable to allocate Glulx memory space."); } - stack = (unsigned char *)glulx_malloc(stacksize); + stack = (byte *)glulx_malloc(stacksize); if (!stack) { glulx_free(memmap); - memmap = NULL; + memmap = nullptr; fatal_error("Unable to allocate Glulx stack space."); } stringtable = 0; - /* Initialize various other things in the terp. */ + // Initialize various other things in the terp. init_operands(); init_serial(); - /* Set up the initial machine state. */ + // Set up the initial machine state. vm_restart(); /* If the debugger is compiled in, check that the debug data matches the game. (This only prints warnings for mismatch.) */ debugger_check_story_file(); + /* Also, set up any start-time debugger state. This may do a block- and-debug, if the user has requested that. */ debugger_setup_start_state(); @@ -113,11 +109,11 @@ void Glulxe::finalize_vm() { if (memmap) { glulx_free(memmap); - memmap = NULL; + memmap = nullptr; } if (stack) { glulx_free(stack); - stack = NULL; + stack = nullptr; } final_serial(); @@ -173,7 +169,7 @@ void Glulxe::vm_restart() { /* Note that we do not reset the protection range. */ /* Push the first function call. (No arguments.) */ - enter_function(startfuncaddr, 0, NULL); + enter_function(startfuncaddr, 0, nullptr); /* We're now ready to execute. */ } @@ -219,17 +215,17 @@ uint Glulxe::change_memsize(uint newlen, bool internal) { } uint *Glulxe::pop_arguments(uint count, uint addr) { - int ix; + uint ix; uint argptr; uint *array; #define MAXARGS (32) static uint statarray[MAXARGS]; - static uint *dynarray = NULL; + static uint *dynarray = nullptr; static uint dynarray_size = 0; if (count == 0) - return NULL; + return nullptr; if (count <= MAXARGS) { /* Store in the static array. */ |