forked from LemonHaze420/DCMoHo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdcbackup.cpp
More file actions
289 lines (226 loc) · 8.88 KB
/
Copy pathdcbackup.cpp
File metadata and controls
289 lines (226 loc) · 8.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/********************************************************************
* Shinobi Library Sample
* Copyright (c) 1998 SEGA
*
* Library : Backup Library
* Module : Library Sample
* File : backup.c
* Date : 1999-01-14
* Version : 1.00
*
********************************************************************/
#include <shinobi.h>
#include "dcbackup.h"
#include <string.h>
/*===============================================================*/
/* 対応するメモリーカードの最大容量 */
/* Mamimum volume to use. */
/*===============================================================*/
#define MAX_CAPS BUD_CAPACITY_1MB
/*===============================================================*/
/* 対応するメモリーカードのドライブ数 */
/* Number of memory card to use. */
/*===============================================================*/
#define MAX_DRIVES 8
#define USE_DRIVES BUD_USE_DRIVE_ALL
/*===============================================================*/
/* メモリーカードの状態を格納しておく構造体 */
/* (backup.h を参照) */
/* Structure to store the information of memory card. */
/* (See backup.h) */
/*===============================================================*/
BACKUPINFO gBupInfo[8];
/*===============================================================*/
/* バックアップライブラリが使用するワーク */
/* 4バイト境界で確保する */
/* Work buffer that backup library uses. */
/* (Must be 4-bytes aligned.) */
/*===============================================================*/
Uint32 gBupWork[BUM_WORK_SIZE(MAX_CAPS, MAX_DRIVES) / sizeof(Uint32)];
/*===============================================================*/
/* スタティック関数のプロトタイプ宣言 */
/* Prototypes of static functions. */
/*===============================================================*/
static Sint32 BupComplete(Sint32 drive, Sint32 op, Sint32 stat, Uint32 param);
static Sint32 BupProgress(Sint32 drive, Sint32 op, Sint32 count, Sint32 max);
static void BupInitCallback(void);
/*===============================================================*/
/* バックアップライブラリ初期化 */
/* Initialize backup library. */
/*===============================================================*/
void BupInit(void)
{
memset(gBupInfo, 0, sizeof(gBupInfo));
buInit(MAX_CAPS, USE_DRIVES, gBupWork, BupInitCallback);
}
/*===============================================================*/
/* バックアップライブラリ終了 */
/* Finalize backup library. */
/*===============================================================*/
void BupExit(void)
{
do {} while (buExit() != BUD_ERR_OK);
}
/*===============================================================*/
/* メモリーカードの状態を取得 */
/* Get information of memory card. */
/*===============================================================*/
const BACKUPINFO* BupGetInfo(Sint32 drive)
{
return (const BACKUPINFO*)&gBupInfo[drive];
}
/*===============================================================*/
/* ファイルのロード */
/* Load a file. */
/*===============================================================*/
Sint32 BupLoad(Sint32 drive, const char* fname, void* buf)
{
return buLoadFile(drive, fname, buf, 0);
}
/*===============================================================*/
/* ファイルのセーブ */
/* Save a file. */
/*===============================================================*/
Sint32 BupSave(Sint32 drive, const char* fname, void* buf, Sint32 nblock)
{
BUS_TIME time;
SYS_RTC_DATE rtc;
syRtcGetDate( &rtc );
time.year = rtc.year;
time.month = rtc.month;
time.day = rtc.day;
time.hour = rtc.hour;
time.minute = rtc.minute;
time.second = rtc.second;
time.dayofweek = rtc.dayofweek;
return buSaveFile(drive, fname, buf, nblock, &time,
BUD_FLAG_VERIFY | BUD_FLAG_COPY(0));
}
/*===============================================================*/
/* ファイルの削除 */
/* Delete a file. */
/*===============================================================*/
Sint32 BupDelete(Sint32 drive, const char* fname)
{
return buDeleteFile(drive, fname);
}
/*===============================================================*/
/* エラーコードを文字列に変換 */
/* Convert error code into character string. */
/*===============================================================*/
const char* BupGetErrorString(Sint32 err)
{
switch (err) {
case BUD_ERR_OK: return "OK\0";
case BUD_ERR_BUSY: return "BUSY\0";
case BUD_ERR_INVALID_PARAM: return "INVALID PARAMETER\0";
case BUD_ERR_ILLEGAL_DISK: return "ILLEGAL DISK\0";
case BUD_ERR_UNKNOWN_DISK: return "UNKNOWN DISK\0";
case BUD_ERR_NO_DISK: return "NO DISK\0";
case BUD_ERR_UNFORMAT: return "UNFORMAT\0";
case BUD_ERR_DISK_FULL: return "DISK FULL\0";
case BUD_ERR_FILE_NOT_FOUND: return "FILE NOT FOUND\0";
case BUD_ERR_FILE_EXIST: return "FILE EXIST\0";
case BUD_ERR_CANNOT_OPEN: return "CANNOT OPEN\0";
case BUD_ERR_CANNOT_CREATE: return "CANNOT CREATE\0";
case BUD_ERR_EXECFILE_EXIST: return "EXECUTABLE FILE EXIST\0";
case BUD_ERR_ACCESS_DENIED: return "ACCESS DENIED\0";
case BUD_ERR_VERIFY: return "VERIFY ERROR\0";
default: return "GENERIC ERROR\0";
}
}
/*===============================================================*/
/* オペレーションコードを文字列に変換 */
/* Convert operation code into character string. */
/*===============================================================*/
const char* BupGetOperationString(Sint32 op)
{
switch (op) {
case BUD_OP_MOUNT: return "CONNECTED\0";
case BUD_OP_UNMOUNT: return "DISCONNECTED\0";
case BUD_OP_FORMATDISK: return "FORMATDISK\0";
case BUD_OP_DELETEFILE: return "DELETEFILE\0";
case BUD_OP_LOADFILE: return "LOADFILE\0";
case BUD_OP_SAVEFILE: return "SAVEFILE\0";
default: return "UNKNOWN OPERATION\0";
}
}
/*===============================================================*/
/* コールバック関数 */
/* Callback functions. */
/*===============================================================*/
/*
** 初期化終了コールバック関数
** Callback function when initialization of library was finished.
*/
static void BupInitCallback(void)
{
Sint32 i;
/* 完了、経過コールバック関数を設定する */
/* Register callback functions. */
buSetCompleteCallback(BupComplete);
buSetProgressCallback(BupProgress);
}
/*
** 完了コールバック関数
** Callback function when operation was finished.
*/
static Sint32 BupComplete(Sint32 drive, Sint32 op, Sint32 stat, Uint32 param)
{
BACKUPINFO* info;
Sint32 ret;
info = &gBupInfo[drive];
switch (op) {
/* メモリーカードが接続された */
/* Memory card was connected. */
case BUD_OP_MOUNT:
if (stat == BUD_ERR_OK) {
info->Ready = TRUE;
ret = buGetDiskInfo(drive, &info->DiskInfo);
if (ret == BUD_ERR_OK) {
info->IsFormat = TRUE;
}
/* エラー状態をクリア */
/* Clear error status */
info->LastError = BUD_ERR_OK;
}
break;
/* メモリーカードが取り外された */
/* Memory card was removed. */
case BUD_OP_UNMOUNT:
info->Ready = FALSE;
info->IsFormat = FALSE;
info->ProgressCount = 0;
info->ProgressMax = 0;
info->Operation = 0;
memset(&info->DiskInfo, 0, sizeof(BUS_DISKINFO));
break;
default:
/* エラー状態を格納 */
/* Store error code. */
info->LastError = stat;
/* 情報を更新する */
/* Update information of memory card. */
buGetDiskInfo(drive, &info->DiskInfo);
}
/* オペレーションコードをクリア */
/* Clear operation code. */
info->Operation = 0;
return BUD_CBRET_OK;
}
/*
** 経過コールバック関数
** Callback function through operation progress.
*/
static Sint32 BupProgress(Sint32 drive, Sint32 op, Sint32 count, Sint32 max)
{
BACKUPINFO* info;
info = &gBupInfo[drive];
/* 経過状態、オペレーションコードを格納 */
/* Store operation code. */
info->ProgressCount = count;
info->ProgressMax = max;
info->Operation = op;
return BUD_CBRET_OK;
}
/******************************* end of file *******************************/