-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHardwareInterface3DS.cpp
More file actions
228 lines (190 loc) · 5.36 KB
/
HardwareInterface3DS.cpp
File metadata and controls
228 lines (190 loc) · 5.36 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#ifdef _3DS
#include <iostream>
#include <3ds.h>
#include <sf2d.h>
#include <sftd.h>
#include <sfil.h>
#include "HardwareInterface.h"
#include <dirent.h>
#include <functional>
#include <fstream>
#define DEBUG_PRIORITY 0
void HI::systemInit() {
srvInit();
aptInit();
hidInit();
ndspInit();
sf2d_init();
sftd_init();
}
void HI::systemFini() {
ndspExit();
sftd_fini();
sf2d_fini();
hidExit();
aptExit();
srvExit();
}
void HI::consoleInit() {
::consoleInit(GFX_BOTTOM, nullptr);
}
void HI::consoleFini() {};
void HI::startFrame(HI_SCREEN screen) {
sf2d_start_frame(
(screen == SCREEN_TOP ? GFX_TOP : GFX_BOTTOM),
GFX_LEFT);
}
short HI::getRComponent(HIColor color) {
return (short)color;
}
short HI::getGComponent(HIColor color) {
return (short)color >> 8;
}
short HI::getBComponent(HIColor color) {
return (short)color >> 16;
}
short HI::getAComponent(HIColor color) {
return (short)color >> 24;
}
void HI::setBackgroundColor(HIColor color) {
sf2d_set_clear_color(color);
}
HardwareInterface::HIFont HardwareInterface::loadFont(std::string path)
{
return sftd_load_font_file(path.c_str());
}
void HardwareInterface::freeFont(HIFont font)
{
sftd_free_font((sftd_font*)font);
}
void HardwareInterface::drawText(HIFont font, std::string text, int posX, int posY, int size, HIColor color)
{
if (((sftd_font*)font) != nullptr) sftd_draw_text((sftd_font*)font, posX, posY, color, size, text.c_str());
}
HI::HITexture HI::loadPngFile(std::string path) {
return sfil_load_PNG_file(path.c_str(), SF2D_PLACE_RAM);
}
HI::HITexture HI::loadBmpFile(std::string path) {
return sfil_load_BMP_file(path.c_str(), SF2D_PLACE_RAM);
}
void HI::drawTexture(HI::HITexture texture, int posX, int posY) {
if (texture != nullptr) sf2d_draw_texture((sf2d_texture*)texture, posX, posY);
}
void HI::drawTextureRotate(HI::HITexture texture, int posX, int posY, float angle) {
if (texture != nullptr) sf2d_draw_texture_rotate((sf2d_texture*)texture, posX, posY, angle);
}
void HI::drawTexturePart(HI::HITexture texture, int startX, int startY, int posX, int posY, int sizeX, int sizeY) {
if (texture != nullptr) sf2d_draw_texture_part((sf2d_texture*)texture, posX, posY, startX, startY, sizeX, sizeY);
}
void HI::mergeTextures(HITexture origin, HITexture destination, short posX, short posY) ////////AIXO NO FUNCA K B I NO SE NI VEIG PK FIRE
{
sf2d_texture *orig = (sf2d_texture*)origin;
sf2d_texture *dest = (sf2d_texture*)destination;
C3D_SafeTextureCopy((u32*)orig->tex.data, 16, (u32*)dest->tex.data, 16, orig->tex.size, 0);
}
void HI::drawRectangle(int posX, int posY, int width, int height, HI::HIColor color) {
sf2d_draw_rectangle(posX, posY, width, height, color);
}
void HI::drawPixel(int posX, int posY, HIColor color) {
HI::drawRectangle(posX, posY, 1, 1, color);
}
void HI::freeTexture(HITexture texture) {
sf2d_free_texture((sf2d_texture*)texture);
}
HI::HITexture HI::createTexture(int sizeX, int sizeY) {
return (HI::HITexture)sf2d_create_texture(sizeX, sizeY, TEXFMT_RGBA8, SF2D_PLACE_RAM);
}
void HI::endFrame() {
sf2d_end_frame();
}
void HI::swapBuffers() {
sf2d_swapbuffers();
}
std::string HI::getDataPath() {
return "data/";
}
std::string HI::getSavesPath() {
return "saves/";
}
bool HardwareInterface::createDir(std::string path) {
if (HI::fsExists(path)) {
errno = EEXIST;
return false;
}
return (mkdir(path.c_str(), 0777) == 0);
}
bool HardwareInterface::fsExists(std::string path) {
FILE* fd = fopen(path.c_str(), "r");
if (fd) {
fclose(fd);
return true;
}
return fsIsDirectory(path);
}
bool HI::fsIsDirectory(const std::string path) {
DIR* dir = opendir(path.c_str());
if (dir) {
closedir(dir);
return true;
}
return false;
}
bool HardwareInterface::copyFile(std::string origin, std::string destination) {
std::ifstream iFile(origin, std::ios::binary);
std::ofstream oFile(destination, std::ios::binary);
oFile << iFile.rdbuf();
oFile.close();
iFile.close();
}
int HI::getScreenHeight() {
return 240;
}
int HI::getScreenWidth() {
return 400;
}
HardwareInterface::HI_PLATFORM HI::getPlatform() {
return PLATFORM_NINTENDO3DS;
}
void HI::createThread(void* entrypoint, std::reference_wrapper<void(void*)>entrypoint2,void* arg, size_t stack_size, int prio, int affinity, bool detached, size_t arg_size) {
threadCreate((ThreadFunc)(&(entrypoint2.get())), arg, stack_size, prio, affinity, detached);
}
void HI::updateTouch(point2D &touch) {
touchPosition tPos;
hidTouchRead(&tPos);
touch.x = tPos.px;
touch.y = tPos.py;
}
void HI::updateHID() {
hidScanInput();
}
int HI::getKeysUp() {
return hidKeysUp();
}
int HI::getKeysHeld() {
return hidKeysHeld();
}
int HI::getKeysDown() {
return hidKeysDown();
}
void HI::getCirclePadPos(point2D &circle, HI_CIRCLEPAD circlePadID) {
circlePosition pos;
hidCircleRead(&pos);
circle.x = pos.dx;
circle.y = pos.dy;
}
void HI::sleepThread(unsigned long ns) {
svcSleepThread(ns);
}
void HardwareInterface::debugPrint(std::string s) {
std::cout << s;
}
void HardwareInterface::debugPrint(std::string s, int priority) {
if (priority >= DEBUG_PRIORITY) std::cout << s;
}
void HI::waitForVBlank() {
gspWaitForEvent(GSPGPU_EVENT_VBlank0, true);
}
bool HI::aptMainLoop() {
return ::aptMainLoop();
}
#endif