include/mgba/internal/ds/slot1.h (view raw)
1/* Copyright (c) 2013-2017 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef DS_SLOT1_H
7#define DS_SLOT1_H
8
9#include <mgba-util/common.h>
10
11CXX_GUARD_START
12
13#include <mgba/core/log.h>
14#include <mgba/core/timing.h>
15
16mLOG_DECLARE_CATEGORY(DS_SLOT1);
17
18DECL_BITFIELD(DSSlot1AUXSPICNT, uint16_t);
19DECL_BITS(DSSlot1AUXSPICNT, Baud, 0, 2);
20DECL_BIT(DSSlot1AUXSPICNT, CSHold, 6);
21DECL_BIT(DSSlot1AUXSPICNT, Busy, 7);
22DECL_BIT(DSSlot1AUXSPICNT, SPIMode, 13);
23DECL_BIT(DSSlot1AUXSPICNT, DoIRQ, 14);
24DECL_BIT(DSSlot1AUXSPICNT, Enable, 15);
25
26DECL_BITFIELD(DSSlot1ROMCNT, uint32_t);
27DECL_BIT(DSSlot1ROMCNT, WordReady, 23);
28DECL_BITS(DSSlot1ROMCNT, BlockSize, 24, 3);
29DECL_BIT(DSSlot1ROMCNT, TransferRate, 27);
30DECL_BIT(DSSlot1ROMCNT, BlockBusy, 31);
31
32enum DSSavedataType {
33 DS_SAVEDATA_AUTODETECT = -1,
34 DS_SAVEDATA_FORCE_NONE = 0,
35 DS_SAVEDATA_EEPROM512 = 1,
36 DS_SAVEDATA_EEPROM = 2,
37 DS_SAVEDATA_FLASH = 3
38};
39
40struct VFile;
41struct DSSlot1 {
42 uint8_t command[8];
43 uint32_t address;
44 uint32_t transferSize;
45 uint32_t transferRemaining;
46 struct mTimingEvent transferEvent;
47 uint8_t readBuffer[4];
48
49 int dmaSource;
50
51 enum DSSavedataType savedataType;
52 struct mTimingEvent spiEvent;
53 bool spiHoldEnabled;
54 uint8_t spiCommand;
55 uint8_t statusReg;
56 int spiAddressingRemaining;
57 uint32_t spiAddress;
58 int32_t spiAddressingPc;
59
60 uint8_t* spiData;
61 struct VFile* spiVf;
62 struct VFile* spiRealVf;
63};
64
65struct DS;
66struct DSCommon;
67void DSSlot1SPIInit(struct DS* ds, struct VFile* vf);
68void DSSlot1Reset(struct DS* ds);
69
70DSSlot1AUXSPICNT DSSlot1Configure(struct DS* ds, DSSlot1AUXSPICNT config);
71DSSlot1ROMCNT DSSlot1Control(struct DS* ds, DSSlot1ROMCNT control);
72void DSSlot1WriteSPI(struct DSCommon* dscore, uint8_t datum);
73
74struct GBADMA;
75void DSSlot1ScheduleDMA(struct DSCommon* dscore, int number, struct GBADMA* info);
76
77uint32_t DSSlot1Read(struct DS* ds);
78
79CXX_GUARD_END
80
81#endif