Skip to content

Commit

Permalink
Geting closer on zork.
Browse files Browse the repository at this point in the history
  • Loading branch information
mterwoord committed Jun 23, 2016
1 parent 3bc4ea7 commit 610f2b6
Show file tree
Hide file tree
Showing 24 changed files with 344 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* New undo mechanism added by Jim Dunleavy <[email protected]>
*/

using System;
using System.IO;
using zword = System.UInt16;
using zbyte = System.Byte;

Expand Down Expand Up @@ -110,10 +112,11 @@ internal static class FastMem
internal static long zmp = 0;
internal static long pcp = 0;

private static System.IO.MemoryStream story_fp = null;
//private static System.IO.MemoryStream story_fp = null;

static bool first_restart = true;
static long init_fp_pos = 0;
private static System.IO.Stream story_fp;

#region zmp & pcp

Expand Down Expand Up @@ -343,17 +346,25 @@ internal static void init_memory()
// TODO Abstract this part
/* Open story file */
// story_fp = new System.IO.FileStream(main.story_name, System.IO.FileMode.Open, System.IO.FileAccess.Read);
story_fp = os_.path_open(main.story_data);
if (story_fp == null)
if (os_.preloadedFileData != null)
{
os_.fatal("Cannot open story file");
storyData = os_.preloadedFileData;
story_fp = new MemoryStream(storyData);
}
init_fp_pos = story_fp.Position;

storyData = new byte[story_fp.Length];
story_fp.Read(storyData, 0, storyData.Length);
story_fp.Position = 0;
else
{
//story_fp = os_.path_open(main.story_data);
//if (story_fp == null)
//{
// os_.fatal("Cannot open story file");
//}
//init_fp_pos = story_fp.Position;

//storyData = new byte[story_fp.Length];
//story_fp.Read(storyData, 0, storyData.Length);
//story_fp.Position = 0;
throw new Exception("File loading doesn't work yet");
}
DebugState.Output("Starting story: {0}", main.story_name);

/* Allocate memory for story header */
Expand Down Expand Up @@ -1016,13 +1027,13 @@ internal static int restore_undo()
/* undo possible */

undo_struct undo = undo_mem[undo_mem.Count - 1];

System.Array.Copy(prev_zmp, ZMData, main.h_dynamic_size);
SET_PC(undo.pc);
main.sp = undo.sp;
main.fp = undo.frame_offset;
main.frame_count = undo.frame_count;

mem_undiff(undo.undo_data, undo.diff_size, prev_zmp);

// System.Array.Copy(undo.stack, 0, main.stack, undo.sp, undo.stack.Length);
Expand Down Expand Up @@ -1112,7 +1123,7 @@ internal static void z_save()

if (main.option_save_quetzal == true)
{
success = Quetzal.save_quetzal(gfp, story_fp);
//success = Quetzal.save_quetzal(gfp, story_fp);

}
else
Expand Down Expand Up @@ -1267,4 +1278,4 @@ internal static void z_verify()

}/* z_verify */
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ internal static class Process
static int invokeCount = 0;
private static void private_invoke(zinstruction instruction, string array, int index, int opcode)
{
DebugState.last_call_made = instruction.Method.Name + ":" + opcode;
DebugState.Output(false, "Invoking: {0:X} -> {1} -> {2}", opcode, instruction.Method.Name, invokeCount);
instruction.DynamicInvoke();
//DebugState.last_call_made = instruction.Method.Name + ":" + opcode;
//DebugState.Output(false, "Invoking: {0:X} -> {1} -> {2}", opcode, instruction.Method.Name, invokeCount);
instruction.Invoke();
invokeCount++;
}

Expand Down Expand Up @@ -849,4 +849,4 @@ internal static void z_rtrue()

}/* z_rtrue */
}
}
}
Loading

0 comments on commit 610f2b6

Please sign in to comment.