OSDN Git Service

Merge pull request #1186 from dis-/feature/Fix-calc_num_fire
[hengbandforosx/hengbandosx.git] / src / save / save-util.cpp
1 #include "save/save-util.h"
2
3 FILE *saving_savefile; /* Current save "file" */
4 byte save_xor_byte; /* Simple encryption */
5 u32b v_stamp = 0L; /* A simple "checksum" on the actual values */
6 u32b x_stamp = 0L; /* A simple "checksum" on the encoded bytes */
7
8 /*!
9  * @brief 1バイトをファイルに書き込む / These functions place information into a savefile a byte at a time
10  * @param v 書き込むバイト値
11  */
12 static void sf_put(byte v)
13 {
14     /* Encode the value, write a character */
15     save_xor_byte ^= v;
16     (void)putc((int)save_xor_byte, saving_savefile);
17
18     /* Maintain the checksum info */
19     v_stamp += v;
20     x_stamp += save_xor_byte;
21 }
22
23 /*!
24  * @brief 1バイトをファイルに書き込む(sf_put()の糖衣)
25  * @param v 書き込むバイト
26  */
27 void wr_byte(byte v) { sf_put(v); }
28
29 /*!
30  * @brief 符号なし16ビットをファイルに書き込む
31  * @param v 書き込む符号なし16bit値
32  */
33 void wr_u16b(u16b v)
34 {
35     wr_byte((byte)(v & 0xFF));
36     wr_byte((byte)((v >> 8) & 0xFF));
37 }
38
39 /*!
40  * @brief 符号あり16ビットをファイルに書き込む
41  * @param v 書き込む符号あり16bit値
42  */
43 void wr_s16b(s16b v) { wr_u16b((u16b)v); }
44
45 /*!
46  * @brief 符号なし32ビットをファイルに書き込む
47  * @param v 書き込む符号なし32bit値
48  */
49 void wr_u32b(u32b v)
50 {
51     wr_byte((byte)(v & 0xFF));
52     wr_byte((byte)((v >> 8) & 0xFF));
53     wr_byte((byte)((v >> 16) & 0xFF));
54     wr_byte((byte)((v >> 24) & 0xFF));
55 }
56
57 /*!
58  * @brief 符号あり32ビットをファイルに書き込む
59  * @param v 書き込む符号あり32bit値
60  */
61 void wr_s32b(s32b v) { wr_u32b((u32b)v); }
62
63 /*!
64  * @brief 文字列をファイルに書き込む
65  * @param str 書き込む文字列
66  */
67 void wr_string(concptr str)
68 {
69     while (*str) {
70         wr_byte(*str);
71         str++;
72     }
73     wr_byte(*str);
74 }