-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemcard.c
95 lines (90 loc) · 4.93 KB
/
memcard.c
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
#include <sys/file.h>
#include <libmcrd.h>
#define ICON_NOICON 0x00
#define ICON_1FRAME 0x11
#define ICON_2FRAME 0x12
#define ICON_3FRAME 0x13
struct MCHeader {
char magic[2];
char iconFlag;
char blockNumber;
char title[64];
char reserved1[12];
char PocketStationFrames1[2];
char PocketStationId[4];
char PocketStationFrames2[2];
char reserved2[8];
char CLUT[32]; //16 color
//128 bytes to here
char icons[128*3]; //3x(16x16 4BPP)
//char saveData[128*60];
char saveData[128]; //128 bytes is enought for FADVX
};
struct MCHeader mCardData={
magic:{53,43}, //"SC" magic
iconFlag: ICON_3FRAME,
blockNumber: 1,
title: "FLAPPY ADVENT. X",
CLUT: {0x00, 0x00, 0x1C, 0x16, 0x5F, 0x47, 0xFF, 0x00, 0x9A, 0x67, 0xEA, 0x20, 0xDF, 0x1A, 0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
icons: {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x55, 0x55, 0x05, 0x00, 0x00, 0x00, 0x50, 0x25, 0x22, 0x75, 0x57, 0x00, 0x00, 0x00, 0x25, 0x62, 0x56, 0x77, 0x77, 0x05, 0x00, 0x55, 0x55, 0x66, 0x56, 0x74, 0x57, 0x57, 0x00, 0x77, 0x77, 0x65, 0x56, 0x74, 0x57, 0x57, 0x00, 0x77, 0x77, 0x57, 0x66, 0x45, 0x77, 0x57, 0x00,
0x72, 0x77, 0x52, 0x66, 0x56, 0x55, 0x55, 0x05, 0x25, 0x22, 0x65, 0x66, 0x35, 0x33, 0x33, 0x53, 0x50, 0x55, 0x11, 0x51, 0x53, 0x55, 0x55, 0x05, 0x50, 0x11, 0x11, 0x11, 0x35, 0x33, 0x33, 0x05, 0x00, 0x55, 0x11, 0x11, 0x51, 0x55, 0x55, 0x00, 0x00, 0x00, 0x55, 0x55, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x55, 0x55, 0x05, 0x00, 0x00, 0x00, 0x50, 0x25, 0x22, 0x75, 0x57, 0x00, 0x00, 0x00, 0x25, 0x62, 0x56, 0x77, 0x77, 0x05, 0x00, 0x50, 0x62, 0x66, 0x56, 0x74, 0x57, 0x57, 0x00, 0x65, 0x66, 0x66, 0x56, 0x74, 0x57, 0x57, 0x00, 0x55, 0x55, 0x65, 0x66, 0x45, 0x77, 0x57, 0x00,
0x77, 0x77, 0x57, 0x66, 0x56, 0x55, 0x55, 0x05, 0x72, 0x77, 0x52, 0x66, 0x35, 0x33, 0x33, 0x53, 0x55, 0x55, 0x15, 0x51, 0x53, 0x55, 0x55, 0x05, 0x50, 0x11, 0x11, 0x11, 0x35, 0x33, 0x33, 0x05, 0x00, 0x55, 0x11, 0x11, 0x51, 0x55, 0x55, 0x00, 0x00, 0x00, 0x55, 0x55, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x55, 0x55, 0x05, 0x00, 0x00, 0x00, 0x50, 0x25, 0x22, 0x75, 0x57, 0x00, 0x00, 0x00, 0x25, 0x62, 0x56, 0x77, 0x77, 0x05, 0x00, 0x50, 0x62, 0x66, 0x56, 0x74, 0x57, 0x57, 0x00, 0x65, 0x66, 0x66, 0x56, 0x74, 0x57, 0x57, 0x00, 0x65, 0x66, 0x66, 0x66, 0x45, 0x77, 0x57, 0x00,
0x55, 0x55, 0x65, 0x66, 0x56, 0x55, 0x55, 0x05, 0x72, 0x77, 0x52, 0x66, 0x35, 0x33, 0x33, 0x53, 0x77, 0x77, 0x15, 0x51, 0x53, 0x55, 0x55, 0x05, 0x77, 0x52, 0x11, 0x11, 0x35, 0x33, 0x33, 0x05, 0x55, 0x55, 0x11, 0x11, 0x51, 0x55, 0x55, 0x00, 0x00, 0x00, 0x55, 0x55, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
},
saveData: {0}
};
void loadMemCard() {
long cmds;
long result;
char* msg;
MemCardStart();
MemCardSync(0, &cmds, &result);
MemCardAccept(0);
MemCardSync(0, &cmds, &result);
MemCardReadFile(0,"FLADVX",(u_long*)mCardData.saveData,128*4,128);
MemCardSync(0, &cmds, &result);
switch (result) {
case McErrNone: msg="game file loaded!"; break;
case McErrCardNotExist: msg="card not connected"; break;
case McErrCardInvalid: msg="communication error"; break;
case McErrNewCard: msg="new card (card swapped)"; break;
case McErrFileNotExist: msg="game file not found"; break;
default: msg="unknown error";
}
printf("%s\n",msg);
MemCardStop();
}
char* saveMemCard() {
long cmds;
long result;
char* msg;
MemCardStart();
MemCardSync(0, &cmds, &result);
result=MemCardCreateFile(0,"FLADVX",1);
switch (result) {
case McErrNone: printf("game file created\n"); break;
case McErrCardNotExist: msg="card not connected"; break;
case McErrCardInvalid: msg="communication error"; break;
case McErrNotFormat: msg="card not formatted"; break;
case McErrAlreadyExist: printf("file already exists\n"); break;
case McErrBlockFull: msg="memcard is full"; break;
default: msg="unknown error";
}
if (result==McErrNone || result==McErrAlreadyExist) {
if (result==McErrNone) MemCardWriteFile(0,"FLADVX",(u_long*)&mCardData,0,128*5);
else MemCardWriteFile(0,"FLADVX",(u_long*)mCardData.saveData,128*4,128);
MemCardSync(0, &cmds, &result);
switch (result) {
case McErrNone: msg="game saved!"; break;
case McErrCardNotExist: msg="card not connected"; break;
case McErrCardInvalid: msg="communication error"; break;
case McErrNewCard: msg="new card (card swapped)"; break;
case McErrFileNotExist: msg="created file not found"; break;
default: msg="unknown error";
}
}
MemCardStop();
return msg;
}