aboutsummaryrefslogtreecommitdiff
path: root/Source/MemCard.h
blob: 42896214b5bf7b91d556b22ce35238342537f687 (plain) (blame)
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
#ifndef MEMCARD_HEADER__
#define MEMCARD_HEADER__

/* *************************************
 * 	Includes
 * *************************************/

#include "Global_Inc.h"

/* *************************************
 * 	Defines
 * *************************************/

/*	The memory is split into 16 blocks (of 8 Kbytes each), and each block
 *	is split into 64 sectors (of 128 bytes each). The first block is used
 *	as Directory, the remaining 15 blocks are containing Files, each
 *	file can occupy one or more blocks.	*/

#define MEMCARD_BLOCKS_PER_CARD 15
#define MEMCARD_NUMBER_OF_SLOTS 2
#define MEMCARD_FILENAME_SIZE 21
#define MEMCARD_NUMBER_OF_ICONS 3
#define MEMCARD_ICON_SIZE 0x80
#define MEMCARD_DATA_SIZE 0x80
#define MEMCARD_CLUT_SIZE 32
#define MEMCARD_GAME_FILENAME (char*)"XAVI18-18215AIRPORT"
#define MEMCARD_FIRST_OR_LAST_DATA_SIZE 0x1E00
#define MEMCARD_INTERMEDIATE_OR_LAST_DATA_SIZE 0x2000

/* *************************************
 * 	Structs and enums
 * *************************************/

typedef enum t_CardBlock
{
	SLOT_ONE = 0,
	SLOT_TWO
}MEMCARD_SLOTS;

typedef enum t_MCBlocks
{
	DIRECTORY_BLOCK = 0,
	BLOCK_1,
	BLOCK_2,
	BLOCK_3,
	BLOCK_4,
	BLOCK_5,
	BLOCK_6,
	BLOCK_7,
	BLOCK_8,
	BLOCK_9,
	BLOCK_10,
	BLOCK_11,
	BLOCK_12,
	BLOCK_13,
	BLOCK_14,
	BLOCK_15,
}MEMCARD_BLOCKS;

typedef enum t_BlockCount
{
	EMPTY_BLOCK = 0,
	FIRST_OR_ONLY_BLOCK,
	INTERMEDIATE_BLOCK,
	LAST_BLOCK
}MEMCARD_BLOCK_COUNT;

typedef struct t_MemCard
{
	MEMCARD_SLOTS Slot;
	MEMCARD_BLOCKS Block;
	uint8_t IconNumber; // Possible values : 1 ... 3
	uint8_t FileName[MEMCARD_FILENAME_SIZE];
	MEMCARD_BLOCK_COUNT BlockCount; // Look at MEMCARD_BLOCK_COUNT enum

	/*
	*	The first some letters of the filename should indicate the game
	*	to which the file belongs, in case of commercial games this is
	*	conventionally done like so: Two character region code:
	*	"BI"=Japan, "BE"=Europe, "BA"=America
	* 	followed by 10 character game code,
	*	in "AAAA-NNNNN" form
	*
	* 	Where the "AAAA" part does imply the region too;
	* 	(SLPS/SCPS=Japan, SLUS/SCUS=America, SLES/SCES=Europe)
	* 	(SCxS=Made by Sony, SLxS=Licensed by Sony),
	* 	followed by up to 8 characters, "abcdefgh"
	*
	*	(which may identify the file if the game uses multiple files;
	* 	this part often contains a random string which seems to be
	* 	allowed to contain any chars in range of 20h..7Fh, of course it
	* 	shouldn't contain "?" and "*" wildcards).*/

	uint8_t Icons[MEMCARD_NUMBER_OF_ICONS][MEMCARD_ICON_SIZE];
	uint8_t CLUT[MEMCARD_NUMBER_OF_ICONS][MEMCARD_CLUT_SIZE];
	uint8_t* Data; // Buffer pointed to by "Data" must be 128 KB or higher!
	GsTPoly4 IconTPoly;
}TYPE_BLOCK_DATA;

/* *************************************
 * 	Global prototypes
 * *************************************/

// Inits default values for memory card blocks
void MemCardInit(void);

// Sets null values to structure pointed to by ptrBlockData.
void MemCardResetBlockData(TYPE_BLOCK_DATA * ptrBlockData);

// Loads data from all blocks for both slots. Internally, it just calls
// MemCardGetBlockInfo multiple times and returns its result.
// All data gets saved into MemCardData (defined below).
bool MemCardGetAllData(void);

// Fills TYPE_BLOCK_DATA structure with basic info and icons from specific block.
// Take into account MemCardResetBlockData is automatically called first
// to flush previous data.
// If ptrBlockData->IconTPoly != NULL, MemCardUploadToGPU() is called.
bool MemCardGetBlockInfo(	TYPE_BLOCK_DATA * ptrBlockData,
							MEMCARD_SLOTS slot,
							MEMCARD_BLOCKS blockNumber	);

// Uploads block graphical data to GPU.
bool MemCardUploadToGPU(TYPE_BLOCK_DATA * ptrBlockData);

// To be called on every frame update (it modifies internal data)
void MemCardHandler(void);

// Reportedly, it draws icon data from a specified memory card block.
// If current block is on the middle of a file, block containing icon data
// is automatically searched when MemCardGetBlockInfo() is called.
void MemCardDrawIcon(TYPE_BLOCK_DATA * ptrBlockData, short x, short y);

// Loads all memory card data and shows a dialog with all icons and
// file names.
TYPE_BLOCK_DATA * MemCardShowMap(void);

// Reportedly, saves data to memory card given input block data.
bool MemCardSaveData(TYPE_BLOCK_DATA * ptrBlockData);

/* *************************************
 * 	Global variables
 * *************************************/

extern TYPE_BLOCK_DATA MemCardData[MEMCARD_BLOCKS_PER_CARD][MEMCARD_NUMBER_OF_SLOTS];

#endif //MEMCARD_HEADER__