Example #1
0
        }/* get_default_name */

        /*
         * z_restore, restore [a part of] a Z-machine state from disk
         *
         *	zargs[0] = address of area to restore (optional)
         *	zargs[1] = number of bytes to restore
         *	zargs[2] = address of suggested file name
         *	zargs[3] = whether to ask for confirmation of the file name
         *
         */

        internal static void z_restore()
        {
            string new_name;

            //            string default_name;
            System.IO.FileStream gfp;

            zword success = 0;

            if (Process.zargc != 0)
            {
                os_.fail("Need to implement optional args in z_restore");
                gfp = null;
                ///* Get the file name */

                //get_default_name (default_name, (FastMem.zargc >= 3) ? FastMem.zargs[2] : 0);

                //if ((FastMem.zargc >= 4) ? FastMem.zargs[3] : 1) {

                //    if (os_read_file_name (new_name, default_name, ZMachine.FILE_LOAD_AUX) == 0)
                //    goto finished;

                //    strcpy (auxilary_name, new_name);

                //} else strcpy (new_name, default_name);

                ///* Open auxilary file */

                //if ((gfp = fopen (new_name, "rb")) == NULL)
                //    goto finished;

                ///* Load auxilary file */

                //success = fread (zmp + zargs[0], 1, zargs[1], gfp);

                ///* Close auxilary file */

                //fclose (gfp);
            }
            else
            {
                /* Get the file name */

                if (!os_.read_file_name(out new_name, save_name, FileTypes.FILE_RESTORE))
                {
                    goto finished;
                }

                save_name = new_name;

                /* Open game file */
                gfp = new System.IO.FileStream(new_name, System.IO.FileMode.Open);
                if (gfp == null)
                {
                    goto finished;
                }

                if (main.option_save_quetzal == true)
                {
                    success = Quetzal.restore_quetzal(gfp, story_fp);
                }
                else
                {
                    os_.fail("Need to implement old style save");
                    /* Load game file */

                    //    release = (unsigned) fgetc (gfp) << 8;
                    //    release |= fgetc (gfp);

                    //    (void) fgetc (gfp);
                    //    (void) fgetc (gfp);

                    //    /* Check the release number */

                    //    if (release == h_release) {

                    //    pc = (long) fgetc (gfp) << 16;
                    //    pc |= (unsigned) fgetc (gfp) << 8;
                    //    pc |= fgetc (gfp);

                    //    SET_PC (pc)

                    //    sp = stack + (fgetc (gfp) << 8);
                    //    sp += fgetc (gfp);
                    //    fp = stack + (fgetc (gfp) << 8);
                    //    fp += fgetc (gfp);

                    //    for (i = (int) (sp - stack); i < STACK_SIZE; i++) {
                    //        stack[i] = (unsigned) fgetc (gfp) << 8;
                    //        stack[i] |= fgetc (gfp);
                    //    }

                    //    fseek (story_fp, init_fp_pos, SEEK_SET);

                    //    for (addr = 0; addr < h_dynamic_size; addr++) {
                    //        int skip = fgetc (gfp);
                    //        for (i = 0; i < skip; i++)
                    //        zmp[addr++] = fgetc (story_fp);
                    //        zmp[addr] = fgetc (gfp);
                    //        (void) fgetc (story_fp);
                    //    }

                    //    /* Check for errors */

                    //    if (ferror (gfp) || ferror (story_fp) || addr != h_dynamic_size)
                    //        success = -1;
                    //    else

                    //        /* Success */

                    //        success = 2;

                    //    } else print_string ("Invalid save file\n");
                }
            }
            if ((short)success >= 0 && success != zword.MaxValue)
            {
                /* Close game file */

                gfp.Close();

                if ((short)success > 0)
                {
                    zbyte old_screen_rows;
                    zbyte old_screen_cols;

                    /* In V3, reset the upper window. */
                    if (main.h_version == ZMachine.V3)
                    {
                        Screen.split_window(0);
                    }

                    LOW_BYTE(ZMachine.H_SCREEN_ROWS, out old_screen_rows);
                    LOW_BYTE(ZMachine.H_SCREEN_COLS, out old_screen_cols);

                    /* Reload cached header fields. */
                    restart_header();

                    /*
                     * Since QUETZAL files may be saved on many different machines,
                     * the screen sizes may vary a lot. Erasing the status window
                     * seems to cover up most of the resulting badness.
                     */
                    if (main.h_version > ZMachine.V3 && main.h_version != ZMachine.V6 &&
                        (main.h_screen_rows != old_screen_rows ||
                         main.h_screen_cols != old_screen_cols))
                    {
                        Screen.erase_window(1);
                    }
                }
            }
            else
            {
                os_.fatal("Error reading save file");
            }


finished:

            if (main.h_version <= ZMachine.V3)
            {
                Process.branch(success > 0);
            }
            else
            {
                Process.store(success);
            }
        }/* z_restore */
Example #2
0
        }/* z_restore_undo */

        /*
         * z_save, save [a part of] the Z-machine state to disk.
         *
         *	zargs[0] = address of memory area to save (optional)
         *	zargs[1] = number of bytes to save
         *	zargs[2] = address of suggested file name
         *	zargs[3] = whether to ask for confirmation of the file name
         *
         */

        internal static void z_save()
        {
            string new_name;
            string default_name;

            System.IO.FileStream gfp;

            zword success = 0;

            if (Process.zargc != 0)
            {
                /* Get the file name */

                default_name = get_default_name((zword)((Process.zargc >= 3) ? Process.zargs[2] : 0));

                //    if ((zargc >= 4) ? zargs[3] : 1) {

                //        if (os_read_file_name (new_name, default_name, FILE_SAVE_AUX) == 0)
                //        goto finished;

                //        strcpy (auxilary_name, new_name);

                //    } else strcpy (new_name, default_name);

                //    /* Open auxilary file */

                //    if ((gfp = fopen (new_name, "wb")) == NULL)
                //        goto finished;

                //    /* Write auxilary file */

                //    success = fwrite (zmp + zargs[0], zargs[1], 1, gfp);

                //    /* Close auxilary file */

                //    fclose (gfp);
                os_.fail("need to implement option save arguments");
            }
            else
            {
                if (!os_.read_file_name(out new_name, save_name, FileTypes.FILE_SAVE))
                {
                    goto finished;
                }

                save_name = new_name;

                /* Open game file */

                if ((gfp = new System.IO.FileStream(new_name, System.IO.FileMode.OpenOrCreate)) == null)
                {
                    goto finished;
                }

                if (main.option_save_quetzal == true)
                {
                    success = Quetzal.save_quetzal(gfp, story_fp);
                }
                else
                {
                    os_.fail("Need to implement old style save");

                    //        /* Write game file */

                    //        fputc ((int) hi (h_release), gfp);
                    //        fputc ((int) lo (h_release), gfp);
                    //        fputc ((int) hi (h_checksum), gfp);
                    //        fputc ((int) lo (h_checksum), gfp);

                    //        GET_PC (pc)

                    //        fputc ((int) (pc >> 16) & 0xff, gfp);
                    //        fputc ((int) (pc >> 8) & 0xff, gfp);
                    //        fputc ((int) (pc) & 0xff, gfp);

                    //        nsp = (int) (sp - stack);
                    //        nfp = (int) (fp - stack);

                    //        fputc ((int) hi (nsp), gfp);
                    //        fputc ((int) lo (nsp), gfp);
                    //        fputc ((int) hi (nfp), gfp);
                    //        fputc ((int) lo (nfp), gfp);

                    //        for (i = nsp; i < STACK_SIZE; i++) {
                    //        fputc ((int) hi (stack[i]), gfp);
                    //        fputc ((int) lo (stack[i]), gfp);
                    //        }

                    //        fseek (story_fp, init_fp_pos, SEEK_SET);

                    //        for (addr = 0, skip = 0; addr < h_dynamic_size; addr++)
                    //        if (zmp[addr] != fgetc (story_fp) || skip == 255 || addr + 1 == h_dynamic_size) {
                    //            fputc (skip, gfp);
                    //            fputc (zmp[addr], gfp);
                    //            skip = 0;
                    //        } else skip++;
                }

                /* Close game file and check for errors */

                gfp.Close();
                // TODO Not sure what to do with these
                //    if (gfp.Close() ) { // || ferror(story_fp)) {
                //    Text.print_string("Error writing save file\n");
                //    goto finished;
                //}

                /* Success */

                success = 1;
            }

finished:

            if (main.h_version <= ZMachine.V3)
            {
                Process.branch(success > 0);
            }
            else
            {
                Process.store(success);
            }
        }/* z_save */