diff options
-rw-r--r-- | engines/glk/glk_dispa.cpp | 12 | ||||
-rw-r--r-- | engines/glk/glulxe/glulxe.cpp | 11 | ||||
-rw-r--r-- | engines/glk/glulxe/glulxe.h | 7 | ||||
-rw-r--r-- | engines/glk/glulxe/operand.cpp | 4 | ||||
-rw-r--r-- | engines/glk/glulxe/serial.cpp | 54 | ||||
-rw-r--r-- | engines/glk/glulxe/string.cpp | 8 | ||||
-rw-r--r-- | engines/glk/glulxe/vm.cpp | 4 |
7 files changed, 49 insertions, 51 deletions
diff --git a/engines/glk/glk_dispa.cpp b/engines/glk/glk_dispa.cpp index dfb638fa0a..e4d089cbe8 100644 --- a/engines/glk/glk_dispa.cpp +++ b/engines/glk/glk_dispa.cpp @@ -348,21 +348,21 @@ void GlkAPI::gidispatch_set_object_registry(gidispatch_rock_t(*regi)(void *obj, { /* It's now necessary to go through all existing objects, and register them. */ - for (win = glk_window_iterate(NULL, NULL); + for (win = glk_window_iterate(nullptr, nullptr); win; - win = glk_window_iterate(win, NULL)) + win = glk_window_iterate(win, nullptr)) { win->_dispRock = (*gli_register_obj)(win, gidisp_Class_Window); } - for (str = glk_stream_iterate(NULL, NULL); + for (str = glk_stream_iterate(nullptr, nullptr); str; - str = glk_stream_iterate(str, NULL)) + str = glk_stream_iterate(str, nullptr)) { str->_dispRock = (*gli_register_obj)(str, gidisp_Class_Stream); } - for (fref = glk_fileref_iterate(NULL, NULL); + for (fref = glk_fileref_iterate(nullptr, nullptr); fref; - fref = glk_fileref_iterate(fref, NULL)) + fref = glk_fileref_iterate(fref, nullptr)) { fref->_dispRock = (*gli_register_obj)(fref, gidisp_Class_Fileref); } diff --git a/engines/glk/glulxe/glulxe.cpp b/engines/glk/glulxe/glulxe.cpp index 1b82f58c05..5d4420b203 100644 --- a/engines/glk/glulxe/glulxe.cpp +++ b/engines/glk/glulxe/glulxe.cpp @@ -30,10 +30,10 @@ namespace Glulxe { Glulxe *g_vm; Glulxe::Glulxe(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, gameDesc), _random("glulxe"), - vm_exited_cleanly(false), gamefile(nullptr), gamefile_start(0), gamefile_len(0), - memmap(nullptr), stack(nullptr), ramstart(0), endgamefile(0), origendmem(0), stacksize(0), - startfuncaddr(0), checksum(0), stackptr(0), frameptr(0), pc(0), prevpc(0), origstringtable(0), - stringtable(0), valstackbase(0), localsbase(0), endmem(0), protectstart(0), protectend(0), + vm_exited_cleanly(false), gamefile_start(0), gamefile_len(0), memmap(nullptr), stack(nullptr), + ramstart(0), endgamefile(0), origendmem(0), stacksize(0), startfuncaddr(0), checksum(0), + stackptr(0), frameptr(0), pc(0), prevpc(0), origstringtable(0), stringtable(0), valstackbase(0), + localsbase(0), endmem(0), protectstart(0), protectend(0), stream_char_handler(nullptr), stream_unichar_handler(nullptr), // main library_autorestore_hook(nullptr), @@ -61,10 +61,9 @@ void Glulxe::runGame() { execute_loop(); finalize_vm(); - gamefile = NULL; gamefile_start = 0; gamefile_len = 0; - init_err = NULL; + init_err = nullptr; vm_exited_cleanly = true; profile_quit(); diff --git a/engines/glk/glulxe/glulxe.h b/engines/glk/glulxe/glulxe.h index 0690560d14..d9003c851e 100644 --- a/engines/glk/glulxe/glulxe.h +++ b/engines/glk/glulxe/glulxe.h @@ -48,7 +48,6 @@ private: UnicharHandler stream_unichar_handler, glkio_unichar_han_ptr; bool vm_exited_cleanly; - strid_t gamefile; uint gamefile_start, gamefile_len; char *init_err, *init_err2; @@ -547,7 +546,7 @@ public: /** * This writes a new call frame onto the stack, at stackptr. It leaves frameptr pointing * to the frame (ie, the original stackptr value.) argc and argv are an array of arguments. - * Note that if argc is zero, argv may be NULL. + * Note that if argc is zero, argv may be nullptr. */ void enter_function(uint addr, uint argc, uint *argv); @@ -620,7 +619,7 @@ public: * (Note that these are uint values -- native byte ordering. Also, the blocks will be in address order, * which is a stricter guarantee than the VM specifies; that'll help in heap_apply_summary().) * - * If the heap is inactive, store NULL. Return 0 for success; otherwise, the operation failed. + * If the heap is inactive, store nullptr. Return 0 for success; otherwise, the operation failed. * * The array returned in summary must be freed with glulx_free() after the caller uses it. */ @@ -654,7 +653,7 @@ public: * An array of data structures is stored in memory, beginning at start, each structure being structsize bytes. * Within each struct, there is a key value keysize bytes long, starting at position keyoffset (from * the start of the structure.) Search through these in order. If one is found whose key matches, return it. - * If numstructs are searched with no result, return NULL. + * If numstructs are searched with no result, return nullptr. * * numstructs may be -1 (0xFFFFFFFF) to indicate no upper limit to the number of structures to search. * The search will continue until a match is found, or (if ZeroKeyTerminates is set) a zero key. diff --git a/engines/glk/glulxe/operand.cpp b/engines/glk/glulxe/operand.cpp index cee8420d41..23018d408f 100644 --- a/engines/glk/glulxe/operand.cpp +++ b/engines/glk/glulxe/operand.cpp @@ -28,7 +28,7 @@ namespace Glulxe { /** * The actual immutable structures which lookup_operandlist() returns. */ -static const operandlist_t list_none = { 0, 4, NULL }; +static const operandlist_t list_none = { 0, 4, nullptr }; static const int array_S[1] = { modeform_Store }; static const operandlist_t list_S = { 1, 4, &array_S[0] }; @@ -276,7 +276,7 @@ const operandlist_t *Glulxe::lookup_operandlist(uint opcode) { #endif /* GLULX_EXTEND_OPERANDS */ default: - return NULL; + return nullptr; } } diff --git a/engines/glk/glulxe/serial.cpp b/engines/glk/glulxe/serial.cpp index 1aa316327c..bc267884b5 100644 --- a/engines/glk/glulxe/serial.cpp +++ b/engines/glk/glulxe/serial.cpp @@ -41,8 +41,9 @@ bool Glulxe::init_serial() { ramcache = (unsigned char *)glulx_malloc(sizeof(unsigned char *) * len); if (!ramcache) return false; - glk_stream_set_position(gamefile, gamefile_start+ramstart, seekmode_Start); - res = glk_get_buffer_stream(gamefile, (char *)ramcache, len); + + _gameFile.seek(gamefile_start + ramstart); + res = _gameFile.read(ramcache, len); if (res != len) return false; } @@ -59,14 +60,14 @@ void Glulxe::final_serial() { } glulx_free(undo_chain); } - undo_chain = NULL; + undo_chain = nullptr; undo_chain_size = 0; undo_chain_num = 0; #ifdef SERIALIZE_CACHE_RAM if (ramcache) { glulx_free(ramcache); - ramcache = NULL; + ramcache = nullptr; } #endif /* SERIALIZE_CACHE_RAM */ } @@ -89,8 +90,8 @@ uint Glulxe::perform_saveundo() { dest.ismem = true; dest.size = 0; dest.pos = 0; - dest.ptr = NULL; - dest.str = NULL; + dest.ptr = nullptr; + dest.str = nullptr; res = 0; if (res == 0) { @@ -147,7 +148,7 @@ uint Glulxe::perform_saveundo() { /* It worked. */ if (undo_chain_num >= undo_chain_size) { glulx_free(undo_chain[undo_chain_num-1]); - undo_chain[undo_chain_num-1] = NULL; + undo_chain[undo_chain_num-1] = nullptr; } if (undo_chain_size > 1) memmove(undo_chain+1, undo_chain, @@ -155,13 +156,13 @@ uint Glulxe::perform_saveundo() { undo_chain[0] = dest.ptr; if (undo_chain_num < undo_chain_size) undo_chain_num += 1; - dest.ptr = NULL; + dest.ptr = nullptr; } else { /* It didn't work. */ if (dest.ptr) { glulx_free(dest.ptr); - dest.ptr = NULL; + dest.ptr = nullptr; } } @@ -172,7 +173,7 @@ uint Glulxe::perform_restoreundo() { dest_t dest; uint res, val = 0; uint heapsumlen = 0; - uint *heapsumarr = NULL; + uint *heapsumarr = nullptr; /* If profiling is enabled and active then fail. */ #if VM_PROFILING @@ -187,7 +188,7 @@ uint Glulxe::perform_restoreundo() { dest.size = 0; dest.pos = 0; dest.ptr = undo_chain[0]; - dest.str = NULL; + dest.str = nullptr; res = 0; if (res == 0) { @@ -223,11 +224,11 @@ uint Glulxe::perform_restoreundo() { (undo_chain_size-1) * sizeof(unsigned char *)); undo_chain_num -= 1; glulx_free(dest.ptr); - dest.ptr = NULL; + dest.ptr = nullptr; } else { /* It didn't work. */ - dest.ptr = NULL; + dest.ptr = nullptr; } return res; @@ -253,7 +254,7 @@ uint Glulxe::perform_save(strid_t str) { dest.ismem = false; dest.size = 0; dest.pos = 0; - dest.ptr = NULL; + dest.ptr = nullptr; dest.str = str; res = 0; @@ -368,7 +369,7 @@ uint Glulxe::perform_restore(strid_t str, int fromshell) { uint lx, res, val; uint filestart, filelen = 0; uint heapsumlen = 0; - uint *heapsumarr = NULL; + uint *heapsumarr = nullptr; /* If profiling is enabled and active then fail. */ #if VM_PROFILING @@ -390,7 +391,7 @@ uint Glulxe::perform_restore(strid_t str, int fromshell) { dest.ismem = false; dest.size = 0; dest.pos = 0; - dest.ptr = NULL; + dest.ptr = nullptr; dest.str = str; res = 0; @@ -590,7 +591,7 @@ uint Glulxe::write_memstate(dest_t *dest) { #ifdef SERIALIZE_CACHE_RAM cachepos = 0; #else /* SERIALIZE_CACHE_RAM */ - glk_stream_set_position(gamefile, gamefile_start+ramstart, seekmode_Start); + _gameFile.seek(gamefile_start + ramstart); #endif /* SERIALIZE_CACHE_RAM */ for (pos=ramstart; pos<endmem; pos++) { @@ -662,7 +663,7 @@ uint Glulxe::read_memstate(dest_t *dest, uint chunklen) { #ifdef SERIALIZE_CACHE_RAM cachepos = 0; #else /* SERIALIZE_CACHE_RAM */ - glk_stream_set_position(gamefile, gamefile_start+ramstart, seekmode_Start); + _gameFile.seek(gamefile_start + ramstart); #endif /* SERIALIZE_CACHE_RAM */ for (pos=ramstart; pos<endmem; pos++) { @@ -671,14 +672,13 @@ uint Glulxe::read_memstate(dest_t *dest, uint chunklen) { val = ramcache[cachepos]; cachepos++; #else /* SERIALIZE_CACHE_RAM */ - val = glk_get_char_stream(gamefile); - if (val == -1) { - fatal_error("The game file ended unexpectedly while restoring."); + if (_gameFile.pos() >= _gameFile.size()) { + fatal_error("The game file ended unexpectedly while restoring."); + val = _gameFile.readByte(); } #endif /* SERIALIZE_CACHE_RAM */ ch = (unsigned char)val; - } - else { + } else { ch = 0; } @@ -767,7 +767,7 @@ uint Glulxe::read_heapstate(dest_t *dest, uint chunklen, int portable, uint *sum uint *arr; *sumlen = 0; - *summary = NULL; + *summary = nullptr; if (chunklen == 0) return 0; /* no heap */ @@ -1106,12 +1106,12 @@ uint Glulxe::perform_verify() { if (len < 256 || (len & 0xFF) != 0) return 1; - glk_stream_set_position(gamefile, gamefile_start, seekmode_Start); + _gameFile.seek(gamefile_start); newsum = 0; /* Read the header */ for (ix=0; ix<9; ix++) { - newlen = glk_get_buffer_stream(gamefile, (char *)buf, 4); + newlen = _gameFile.read(buf, 4); if (newlen != 4) return 1; val = Read4(buf); @@ -1127,7 +1127,7 @@ uint Glulxe::perform_verify() { /* Read everything else */ for (; ix < len/4; ix++) { - newlen = glk_get_buffer_stream(gamefile, (char *)buf, 4); + newlen = _gameFile.read(buf, 4); if (newlen != 4) return 1; val = Read4(buf); diff --git a/engines/glk/glulxe/string.cpp b/engines/glk/glulxe/string.cpp index 59420fa1b5..67a869edaf 100644 --- a/engines/glk/glulxe/string.cpp +++ b/engines/glk/glulxe/string.cpp @@ -358,7 +358,7 @@ void Glulxe::stream_string(uint addr, int inmiddle, int bitnum) { } else { argc = 0; - argv = NULL; + argv = nullptr; } pc = addr; push_callstub(0x10, bitnum); @@ -528,7 +528,7 @@ void Glulxe::stream_string(uint addr, int inmiddle, int bitnum) { } else { argc = 0; - argv = NULL; + argv = nullptr; } pc = addr; push_callstub(0x10, bitnum); @@ -641,7 +641,7 @@ void Glulxe::stream_set_table(uint addr) { if (tablecache_valid) { if (tablecache.type == 0) dropcache(tablecache.u.branches); - tablecache.u.branches = NULL; + tablecache.u.branches = nullptr; tablecache_valid = false; } @@ -752,7 +752,7 @@ void Glulxe::dropcache(cacheblock_t *cablist) { cacheblock_t *cab = &(cablist[ix]); if (cab->type == 0) { dropcache(cab->u.branches); - cab->u.branches = NULL; + cab->u.branches = nullptr; } } glulx_free(cablist); diff --git a/engines/glk/glulxe/vm.cpp b/engines/glk/glulxe/vm.cpp index eb4b1121b4..194152ad65 100644 --- a/engines/glk/glulxe/vm.cpp +++ b/engines/glk/glulxe/vm.cpp @@ -135,12 +135,12 @@ void Glulxe::vm_restart() { /* Load in all of main memory. We do this in 256-byte chunks, because why rely on OS stream buffering? */ - glk_stream_set_position(gamefile, gamefile_start, seekmode_Start); + _gameFile.seek(gamefile_start); bufpos = 0x100; for (lx=0; lx<endgamefile; lx++) { if (bufpos >= 0x100) { - int count = glk_get_buffer_stream(gamefile, buf, 0x100); + int count = _gameFile.read(buf, 0x100); if (count != 0x100) { fatal_error("The game file ended unexpectedly."); } |