-static int data_fd = -1;
-
-
-/*
- * Hack -- current block type
- */
-static u16b data_type;
-
-/*
- * Hack -- current block size
- */
-static u16b data_size;
-
-/*
- * Hack -- pointer to the data buffer
- */
-static byte *data_head;
-
-/*
- * Hack -- pointer into the data buffer
- */
-static byte *data_next;
-
-
-
-/*
- * Hack -- write the current "block" to the savefile
- */
-static errr wr_block(void)
-{
- errr err;
-
- byte fake[4];
-
- /* Save the type and size */
- fake[0] = (byte)(data_type);
- fake[1] = (byte)(data_type >> 8);
- fake[2] = (byte)(data_size);
- fake[3] = (byte)(data_size >> 8);
-
- /* Dump the head */
- err = fd_write(data_fd, (char*)&fake, 4);
-
- /* Dump the actual data */
- err = fd_write(data_fd, (char*)data_head, data_size);
-
- /* XXX XXX XXX */
- fake[0] = 0;
- fake[1] = 0;
- fake[2] = 0;
- fake[3] = 0;
-
- /* Dump the tail */
- err = fd_write(data_fd, (char*)&fake, 4);
-
- /* Hack -- reset */
- data_next = data_head;
-
- /* Wipe the data block */
- C_WIPE(data_head, 65535, byte);
-
- /* Success */
- return (0);
-}
-
-
-
-/*
- * Hack -- add data to the current block
- */
-static void put_byte(byte v)
-{
- *data_next++ = v;
-}
-
-/*
- * Hack -- add data to the current block
- */
-static void put_char(char v)
-{
- put_byte((byte)(v));
-}
-
-/*
- * Hack -- add data to the current block
- */
-static void put_u16b(u16b v)
-{
- *data_next++ = (byte)(v);
- *data_next++ = (byte)(v >> 8);
-}
-
-/*
- * Hack -- add data to the current block
- */
-static void put_s16b(s16b v)
-{
- put_u16b((u16b)(v));
-}
-
-/*
- * Hack -- add data to the current block
- */
-static void put_u32b(u32b v)
-{
- *data_next++ = (byte)(v);
- *data_next++ = (byte)(v >> 8);
- *data_next++ = (byte)(v >> 16);
- *data_next++ = (byte)(v >> 24);
-}
-
-/*
- * Hack -- add data to the current block
- */
-static void put_s32b(s32b v)
-{
- put_u32b((u32b)(v));
-}
-
-/*
- * Hack -- add data to the current block
- */
-static void put_string(char *str)
-{
- while ((*data_next++ = *str++) != '\0');
-}
-
-
-
-/*
- * Write a savefile for Angband 2.8.0
- */
-static errr wr_savefile(void)
-{
- int i;
-
- u32b now;
-
- byte tmp8u;
- u16b tmp16u;
-
- errr err;
-
- byte fake[4];
-
-
- /*** Hack -- extract some data ***/
-
- /* Hack -- Acquire the current time */
- now = time((time_t*)(NULL));
-
- /* Note the operating system */
- sf_xtra = 0L;
-
- /* Note when the file was saved */
- sf_when = now;
-
- /* Note the number of saves */
- sf_saves++;
-
-
- /*** Actually write the file ***/
-
- /* Open the file XXX XXX XXX */
- data_fd = -1;
-
- /* Dump the version */
- fake[0] = (byte)(FAKE_VER_MAJOR);
- fake[1] = (byte)(FAKE_VER_MINOR);
- fake[2] = (byte)(FAKE_VER_PATCH);
- fake[3] = (byte)(VERSION_EXTRA);
-
-
- /* Dump the data */
- err = fd_write(data_fd, (char*)&fake, 4);
-
-
- /* Make array XXX XXX XXX */
- C_MAKE(data_head, 65535, byte);
-
- /* Hack -- reset */
- data_next = data_head;
-
- /* Dump the "options" */
- put_options();
-
- /* Set the type */
- data_type = TYPE_OPTIONS;
-
- /* Set the "options" size */
- data_size = (data_next - data_head);
-
- /* Write the block */
- wr_block();
-
- /* XXX XXX XXX */
-
- /* Dump the "final" marker XXX XXX XXX */
- /* Type zero, Size zero, Contents zero, etc */
-
-
- /* XXX XXX XXX Check for errors */
-
-
- /* Kill array XXX XXX XXX */
- C_KILL(data_head, 65535, byte);
-
-
- /* Success */
- return (0);
-}
-
-
-
-
-
-/*
- * Hack -- read the next "block" from the savefile
- */
-static errr rd_block(void)
-{
- errr err;
-
- byte fake[4];
-
- /* Read the head data */
- err = fd_read(data_fd, (char*)&fake, 4);
-
- /* Extract the type and size */
- data_type = (fake[0] | ((u16b)fake[1] << 8));
- data_size = (fake[2] | ((u16b)fake[3] << 8));
-
- /* Wipe the data block */
- C_WIPE(data_head, 65535, byte);
-
- /* Read the actual data */
- err = fd_read(data_fd, (char*)data_head, data_size);
-
- /* Read the tail data */
- err = fd_read(data_fd, (char*)&fake, 4);
-
- /* XXX XXX XXX Verify */
-
- /* Hack -- reset */
- data_next = data_head;
-
- /* Success */
- return (0);
-}
-
-
-/*
- * Hack -- get data from the current block
- */
-static void get_byte(byte *ip)
-{
- byte d1;
- d1 = (*data_next++);
- (*ip) = (d1);
-}
-
-/*
- * Hack -- get data from the current block
- */
-static void get_char(char *ip)
-{
- get_byte((byte*)ip);
-}
-
-/*
- * Hack -- get data from the current block
- */
-static void get_u16b(u16b *ip)
-{
- u16b d0, d1;
- d0 = (*data_next++);
- d1 = (*data_next++);
- (*ip) = (d0 | (d1 << 8));
-}
-
-/*
- * Hack -- get data from the current block
- */
-static void get_s16b(s16b *ip)
-{
- get_u16b((u16b*)ip);
-}
-
-/*
- * Hack -- get data from the current block
- */
-static void get_u32b(u32b *ip)
-{
- u32b d0, d1, d2, d3;
- d0 = (*data_next++);
- d1 = (*data_next++);
- d2 = (*data_next++);
- d3 = (*data_next++);
- (*ip) = (d0 | (d1 << 8) | (d2 << 16) | (d3 << 24));
-}
-
-/*
- * Hack -- get data from the current block
- */
-static void get_s32b(s32b *ip)
-{
- get_u32b((u32b*)ip);
-}
-
-
-
-/*
- * Read a savefile for Angband 2.8.0
- */
-static errr rd_savefile(void)
-{
- bool done = FALSE;
-
- byte fake[4];
-
-
- /* Open the savefile */
- data_fd = fd_open(savefile, O_RDONLY);
-
- /* No file */
- if (data_fd < 0) return (1);
-
- /* Strip the first four bytes (see below) */
- if (fd_read(data_fd, (char*)(fake), 4)) return (1);
-
-
- /* Make array XXX XXX XXX */
- C_MAKE(data_head, 65535, byte);
-
- /* Hack -- reset */
- data_next = data_head;
-
-
- /* Read blocks */
- while (!done)
- {
- /* Read the block */
- if (rd_block()) break;
-
- /* Analyze the type */
- switch (data_type)
- {
- /* Done XXX XXX XXX */
- case 0:
- {
- done = TRUE;
- break;
- }
-
- /* Grab the options */
- case TYPE_OPTIONS:
- {
- if (get_options()) err = -1;
- break;
- }
- }
-
- /* XXX XXX XXX verify "data_next" */
- if (data_next - data_head > data_size) break;
- }
-
-
- /* XXX XXX XXX Check for errors */
-
-
- /* Kill array XXX XXX XXX */
- C_KILL(data_head, 65535, byte);
-
-
- /* Success */
- return (0);
-}
-
-
-#endif /* FUTURE_SAVEFILES */