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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/logging/log.h"
#include "core/hle/kernel/event.h"
#include "core/hle/service/cam/cam.h"
#include "core/hle/service/cam/cam_c.h"
#include "core/hle/service/cam/cam_q.h"
#include "core/hle/service/cam/cam_s.h"
#include "core/hle/service/cam/cam_u.h"
#include "core/hle/service/service.h"
namespace Service {
namespace CAM {
static const u32 TRANSFER_BYTES = 5 * 1024;
static Kernel::SharedPtr<Kernel::Event> completion_event_cam1;
static Kernel::SharedPtr<Kernel::Event> completion_event_cam2;
static Kernel::SharedPtr<Kernel::Event> interrupt_error_event;
static Kernel::SharedPtr<Kernel::Event> vsync_interrupt_error_event;
void StartCapture(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 port = cmd_buff[1] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0x1, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, port=%d", port);
}
void StopCapture(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 port = cmd_buff[1] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0x2, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, port=%d", port);
}
void GetVsyncInterruptEvent(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 port = cmd_buff[1] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0x5, 1, 2);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = IPC::CopyHandleDesc();
cmd_buff[3] = Kernel::g_handle_table.Create(vsync_interrupt_error_event).MoveFrom();
LOG_WARNING(Service_CAM, "(STUBBED) called, port=%d", port);
}
void GetBufferErrorInterruptEvent(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 port = cmd_buff[1] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0x6, 1, 2);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = IPC::CopyHandleDesc();
cmd_buff[3] = Kernel::g_handle_table.Create(interrupt_error_event).MoveFrom();
LOG_WARNING(Service_CAM, "(STUBBED) called, port=%d", port);
}
void SetReceiving(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
VAddr dest = cmd_buff[1];
u8 port = cmd_buff[2] & 0xFF;
u32 image_size = cmd_buff[3];
u16 trans_unit = cmd_buff[4] & 0xFFFF;
Kernel::Event* completion_event =
(Port)port == Port::Cam2 ? completion_event_cam2.get() : completion_event_cam1.get();
completion_event->Signal();
cmd_buff[0] = IPC::MakeHeader(0x7, 1, 2);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = IPC::CopyHandleDesc();
cmd_buff[3] = Kernel::g_handle_table.Create(completion_event).MoveFrom();
LOG_WARNING(Service_CAM, "(STUBBED) called, addr=0x%X, port=%d, image_size=%d, trans_unit=%d",
dest, port, image_size, trans_unit);
}
void SetTransferLines(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 port = cmd_buff[1] & 0xFF;
u16 transfer_lines = cmd_buff[2] & 0xFFFF;
u16 width = cmd_buff[3] & 0xFFFF;
u16 height = cmd_buff[4] & 0xFFFF;
cmd_buff[0] = IPC::MakeHeader(0x9, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, port=%d, lines=%d, width=%d, height=%d", port,
transfer_lines, width, height);
}
void GetMaxLines(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u16 width = cmd_buff[1] & 0xFFFF;
u16 height = cmd_buff[2] & 0xFFFF;
cmd_buff[0] = IPC::MakeHeader(0xA, 2, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = TRANSFER_BYTES / (2 * width);
LOG_WARNING(Service_CAM, "(STUBBED) called, width=%d, height=%d, lines = %d", width, height,
cmd_buff[2]);
}
void GetTransferBytes(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 port = cmd_buff[1] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0xC, 2, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = TRANSFER_BYTES;
LOG_WARNING(Service_CAM, "(STUBBED) called, port=%d", port);
}
void SetTrimming(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 port = cmd_buff[1] & 0xFF;
bool trim = (cmd_buff[2] & 0xFF) != 0;
cmd_buff[0] = IPC::MakeHeader(0xE, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, port=%d, trim=%d", port, trim);
}
void SetTrimmingParamsCenter(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 port = cmd_buff[1] & 0xFF;
s16 trimW = cmd_buff[2] & 0xFFFF;
s16 trimH = cmd_buff[3] & 0xFFFF;
s16 camW = cmd_buff[4] & 0xFFFF;
s16 camH = cmd_buff[5] & 0xFFFF;
cmd_buff[0] = IPC::MakeHeader(0x12, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, port=%d, trimW=%d, trimH=%d, camW=%d, camH=%d",
port, trimW, trimH, camW, camH);
}
void Activate(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 cam_select = cmd_buff[1] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0x13, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, cam_select=%d", cam_select);
}
void FlipImage(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 cam_select = cmd_buff[1] & 0xFF;
u8 flip = cmd_buff[2] & 0xFF;
u8 context = cmd_buff[3] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0x1D, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, cam_select=%d, flip=%d, context=%d", cam_select,
flip, context);
}
void SetSize(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 cam_select = cmd_buff[1] & 0xFF;
u8 size = cmd_buff[2] & 0xFF;
u8 context = cmd_buff[3] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0x1F, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, cam_select=%d, size=%d, context=%d", cam_select,
size, context);
}
void SetFrameRate(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 cam_select = cmd_buff[1] & 0xFF;
u8 frame_rate = cmd_buff[2] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0x20, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, cam_select=%d, frame_rate=%d", cam_select,
frame_rate);
}
void GetStereoCameraCalibrationData(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
// Default values taken from yuriks' 3DS. Valid data is required here or games using the
// calibration get stuck in an infinite CPU loop.
StereoCameraCalibrationData data = {};
data.isValidRotationXY = 0;
data.scale = 1.001776f;
data.rotationZ = 0.008322907f;
data.translationX = -87.70484f;
data.translationY = -7.640977f;
data.rotationX = 0.0f;
data.rotationY = 0.0f;
data.angleOfViewRight = 64.66875f;
data.angleOfViewLeft = 64.76067f;
data.distanceToChart = 250.0f;
data.distanceCameras = 35.0f;
data.imageWidth = 640;
data.imageHeight = 480;
cmd_buff[0] = IPC::MakeHeader(0x2B, 17, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
memcpy(&cmd_buff[2], &data, sizeof(data));
LOG_TRACE(Service_CAM, "called");
}
void GetSuitableY2rStandardCoefficient(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[0] = IPC::MakeHeader(0x36, 2, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
cmd_buff[2] = 0;
LOG_WARNING(Service_CAM, "(STUBBED) called");
}
void PlayShutterSound(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u8 sound_id = cmd_buff[1] & 0xFF;
cmd_buff[0] = IPC::MakeHeader(0x38, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called, sound_id=%d", sound_id);
}
void DriverInitialize(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
completion_event_cam1->Clear();
completion_event_cam2->Clear();
interrupt_error_event->Clear();
vsync_interrupt_error_event->Clear();
cmd_buff[0] = IPC::MakeHeader(0x39, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called");
}
void DriverFinalize(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
cmd_buff[0] = IPC::MakeHeader(0x3A, 1, 0);
cmd_buff[1] = RESULT_SUCCESS.raw;
LOG_WARNING(Service_CAM, "(STUBBED) called");
}
void Init() {
using namespace Kernel;
AddService(new CAM_C_Interface);
AddService(new CAM_Q_Interface);
AddService(new CAM_S_Interface);
AddService(new CAM_U_Interface);
completion_event_cam1 =
Kernel::Event::Create(ResetType::OneShot, "CAM_U::completion_event_cam1");
completion_event_cam2 =
Kernel::Event::Create(ResetType::OneShot, "CAM_U::completion_event_cam2");
interrupt_error_event =
Kernel::Event::Create(ResetType::OneShot, "CAM_U::interrupt_error_event");
vsync_interrupt_error_event =
Kernel::Event::Create(ResetType::OneShot, "CAM_U::vsync_interrupt_error_event");
}
void Shutdown() {
completion_event_cam1 = nullptr;
completion_event_cam2 = nullptr;
interrupt_error_event = nullptr;
vsync_interrupt_error_event = nullptr;
}
} // namespace CAM
} // namespace Service
|