forked from Bownly/Ningami
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathram.c
73 lines (61 loc) · 1.7 KB
/
ram.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
#include <gb/gb.h>
#include "ram.h"
#include "objects/DeckObject.h"
#include "objects/PlayerObject.h"
UBYTE ram_data[128U];
extern UBYTE *data;
extern PlayerObject player;
extern DeckObject deck;
extern UINT8 roomId;
void saveGameData()
{
data = (&ram_data[RAM_ROOMID]);
*data = roomId;
data = (&ram_data[RAM_PLAYER]);
*data++ = player.xTile;
*data++ = player.yTile;
*data++ = player.dir;
*data++ = player.hpMax;
*data++ = player.hpCur;
*data++ = player.mpMax;
*data++ = player.mpCur;
*data++ = player.shieldCount;
*data++ = player.atk;
*data++ = player.def;
*data++ = player.paper;
data = &ram_data[RAM_DECK];
for (UINT8 i = 0U; i != 18U; ++i) // 18 is a magic number equivalent to max deck size
{
*data++ = deck.orderedCards[i];
}
shuffleDeck(&deck, 0U, TRUE);
*data++ = deck.cardCount;
*data = deck.deckSize;
}
void loadGameData()
{
initializeDeck(&deck);
data = (&ram_data[RAM_ROOMID]);
roomId = *data;
data = &ram_data[RAM_PLAYER];
player.xTile = *data++;
player.yTile = *data++;
player.dir = *data++;
player.hpMax = *data++;
player.hpCur = *data++;
player.mpMax = *data++;
player.mpCur = *data++;
player.shieldCount = *data++;
player.atk = *data++;
player.def = *data++;
player.paper = *data++;
data = &ram_data[RAM_DECK];
for (UINT8 i = 0U; i != 18U; ++i) // 18 is a magic number equivalent to max deck size
{
deck.orderedCards[i] = *data++;
deck.cardIds[i] = i;
}
deck.cardCount = *data++;
deck.deckSize = *data++;
shuffleDeck(&deck, 0U, TRUE);
}