Example #1
0
void z_restart (void)
{
    static bool first_restart = TRUE;

    flush_buffer ();

    os_restart_game (RESTART_BEGIN);

    seed_random (0);

    if (!first_restart) {

        fseek (story_fp, blorb_ofs, SEEK_SET);

        if (fread (zmp, 1, h_dynamic_size, story_fp) != h_dynamic_size)
            os_fatal ("Story file read error");

    } else first_restart = FALSE;

    restart_header ();
    restart_screen ();

    sp = fp = stack + STACK_SIZE;
    frame_count = 0;

    if (h_version != V6) {

        long pc = (long) h_start_pc;
        SET_PC (pc);

    } else call (h_start_pc, 0, NULL, 0);

    os_restart_game (RESTART_END);

}/* z_restart */
Example #2
0
void Processor::z_restart() {
	flush_buffer();

	os_restart_game(RESTART_BEGIN);

	seed_random(0);

	if (!first_restart) {
		story_fp->seek(0);

		if (story_fp->read(zmp, h_dynamic_size) != h_dynamic_size)
			error("Story file read error");

	} else {
		first_restart = false;
	}

	restart_header();
	restart_screen();

	_sp = _fp = _stack + STACK_SIZE;
	_frameCount = 0;

	if (h_version != V6 && h_version != V9) {
		long pc = (long)h_start_pc;
		SET_PC(pc);
	} else {
		call(h_start_pc, 0, nullptr, 0);
	}

	os_restart_game(RESTART_END);
}
Example #3
0
void z_restore (void)
{
    FILE *gfp;

    zword success = 0;

    if (zargc != 0) {

        /* Get the file name */

        /* Open auxilary file */

        if ((gfp = frotzopenprompt(FILE_LOAD_AUX)) == NULL)
            goto finished;

        /* Load auxilary file */

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

        /* Close auxilary file */

        fclose (gfp);

    } else {

        long pc;
        zword release;
        zword addr;
        int i;

        /* Open game file */

        if ((gfp = frotzopenprompt(FILE_RESTORE)) == NULL)
            goto finished;

        if (f_setup.save_quetzal) {
            success = restore_quetzal (gfp, story_fp, blorb_ofs);

        } else {
            /* 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, blorb_ofs, 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) {

            /* Close game file */

            fclose (gfp);

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

                /* In V3, reset the upper window. */
                if (h_version == V3)
                    split_window (0);

                LOW_BYTE (H_SCREEN_ROWS, old_screen_rows);
                LOW_BYTE (H_SCREEN_COLS, 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 (h_version > V3 && h_version != V6
                        && (h_screen_rows != old_screen_rows
                            || h_screen_cols != old_screen_cols))
                    erase_window (1);
            }
        } else
            os_fatal ("Error reading save file");
    }

finished:

    if (h_version <= V3)
        branch (success);
    else
        store (success);

}/* z_restore */