UnicodeCaps IZMachineIO.CheckUnicode(char ch) { UnicodeCaps result = 0; if (Glk.glk_gestalt(Gestalt.CharOutput, ch) != 0) { result |= UnicodeCaps.CanPrint; } if (Glk.glk_gestalt(Gestalt.CharInput, ch) != 0) { result |= UnicodeCaps.CanInput; } return(result); }
public GlkIO(string[] args, string storyName) { // initialize Glk // first, add the application's path to the beginning of the arg list string[] newArgs = new string[args.Length + 1]; newArgs[0] = Application.ExecutablePath; Array.Copy(args, 0, newArgs, 1, args.Length); args = newArgs; // now, GarGlk keeps pointers into argv, so we have to copy the args into unmanaged memory argv = Marshal.AllocHGlobal(4 * (args.Length + 1)); argvStrings = new IntPtr[args.Length]; for (int i = 0; i < args.Length; i++) { IntPtr str = Marshal.StringToHGlobalAnsi(args[i]); argvStrings[i] = str; Marshal.WriteIntPtr(argv, 4 * i, str); } Marshal.WriteIntPtr(argv, 4 * args.Length, IntPtr.Zero); Glk.gli_startup(args.Length, argv); Glk.garglk_set_program_name("Demona"); Glk.garglk_set_program_info("Demona by Jesse McGrew\nA Glk interface for ZLR\nVersion " + ZMachine.ZLR_VERSION); Glk.garglk_set_story_name(storyName); // set style hints Glk.glk_stylehint_set(WinType.AllTypes, Style.User1, StyleHint.ReverseColor, 1); Glk.glk_stylehint_set(WinType.AllTypes, Style.User2, StyleHint.Weight, 1); Glk.glk_stylehint_set(WinType.AllTypes, Style.User2, StyleHint.Proportional, 0); // figure out how big the screen is winid_t tempWin = Glk.glk_window_open(winid_t.Null, 0, 0, WinType.TextGrid, 0); if (tempWin.IsNull) { screenWidth = 80; screenHeight = 25; } else { Glk.glk_window_get_size(tempWin, out screenWidth, out screenHeight); stream_result_t dummy; Glk.glk_window_close(tempWin, out dummy); } // open the lower window lowerWin = Glk.glk_window_open(winid_t.Null, 0, 0, WinType.TextBuffer, 0); if (lowerWin.IsNull) { throw new Exception("glk_window_open failed"); } Glk.glk_set_window(lowerWin); currentWin = lowerWin; xpos = 0; ypos = 0; unicode = (Glk.glk_gestalt(Gestalt.Unicode, 0) != 0); }