-
Notifications
You must be signed in to change notification settings - Fork 33
/
device.h
52 lines (40 loc) · 1.45 KB
/
device.h
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
#pragma once
#include <cstdint>
#include <cstddef>
#include <vector>
#include <ncgcpp/ntrcard.h>
#include "platform.h"
using std::uint8_t;
using std::uint16_t;
using std::uint32_t;
// Utility -- s must be a power of two and have no side effects.
#define PAGE_ROUND_UP(x, s) ( ((x) + (s)-1) & (~((s)-1)) )
#define PAGE_ROUND_DOWN(x, s) ( (x) & (~((s)-1)) )
#define BIT(n) (1 << (n))
namespace flashcart_core {
class Flashcart {
public:
Flashcart(const char* name, const size_t max_length);
Flashcart(const char* name, const char* short_name, const size_t max_length);
inline bool initialize(ncgc::NTRCard *card) {
m_card = card;
return initialize();
}
virtual void shutdown() = 0;
virtual bool readFlash(uint32_t address, uint32_t length, uint8_t *buffer) = 0;
virtual bool writeFlash(uint32_t address, uint32_t length, const uint8_t *buffer) = 0;
virtual bool injectNtrBoot(uint8_t *blowfish_key, uint8_t *firm, uint32_t firm_size) = 0;
const char *getName() { return m_name; }
const char *getShortName() { return m_short_name; }
virtual const char *getAuthor() { return "unknown"; }
virtual const char *getDescription() { return ""; }
virtual size_t getMaxLength() { return m_max_length; }
protected:
const char* m_name;
const char* m_short_name;
const size_t m_max_length;
ncgc::NTRCard *m_card;
virtual bool initialize() = 0;
};
extern std::vector<Flashcart*> *flashcart_list;
}