Skip to content

Commit 66dd0a4

Browse files
author
Tony Wasserka
committed
Fix malformed code import
1 parent 512a952 commit 66dd0a4

File tree

8 files changed

+264
-288
lines changed

8 files changed

+264
-288
lines changed

content/CRC-8-CCITT.md

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,63 +18,66 @@ On the 3DS operating system, the CRC-8-CCITT is used for:
1818
Now follows a public domain implementation of CRC-8-CCITT, as used by
1919
the 3DS:
2020

21-
``
22-
`// crc8.h`
23-
``
24-
`#include <stdint.h>`
25-
`#include <string.h>`
26-
``
27-
`uint8_t crc8ccitt(const void * data, size_t size);`
28-
29-
`// crc8.c`
30-
``
31-
`#include "crc8.h"`
32-
``
33-
`static const uint8_t CRC_TABLE[256] = {`
34-
`    0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,`
35-
`    0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,`
36-
`    0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,`
37-
`    0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,`
38-
`    0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,`
39-
`    0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,`
40-
`    0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,`
41-
`    0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,`
42-
`    0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,`
43-
`    0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,`
44-
`    0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,`
45-
`    0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,`
46-
`    0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,`
47-
`    0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,`
48-
`    0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,`
49-
`    0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,`
50-
`    0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,`
51-
`    0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,`
52-
`    0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,`
53-
`    0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,`
54-
`    0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,`
55-
`    0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,`
56-
`    0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,`
57-
`    0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,`
58-
`    0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,`
59-
`    0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,`
60-
`    0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,`
61-
`    0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,`
62-
`    0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,`
63-
`    0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,`
64-
`    0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,`
65-
`    0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3`
66-
`};`
67-
``
68-
`uint8_t crc8ccitt(const void * data, size_t size) {`
69-
`    uint8_t val = 0;`
70-
``
71-
`    uint8_t * pos = (uint8_t *) data;`
72-
`    uint8_t * end = pos + size;`
73-
``
74-
`    while (pos < end) {`
75-
`        val = CRC_TABLE[val ^ *pos];`
76-
`        pos++;`
77-
`    }`
78-
``
79-
`    return val;`
80-
`}`
21+
```
22+
// crc8.h
23+
24+
#include <stdint.h>
25+
#include <string.h>
26+
27+
uint8_t crc8ccitt(const void * data, size_t size);
28+
```
29+
30+
```
31+
// crc8.c
32+
33+
#include "crc8.h"
34+
35+
static const uint8_t CRC_TABLE[256] = {
36+
0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
37+
0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
38+
0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
39+
0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
40+
0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
41+
0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
42+
0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
43+
0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
44+
0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
45+
0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
46+
0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
47+
0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
48+
0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
49+
0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
50+
0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
51+
0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
52+
0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
53+
0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
54+
0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
55+
0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
56+
0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
57+
0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
58+
0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
59+
0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
60+
0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
61+
0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
62+
0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
63+
0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
64+
0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
65+
0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
66+
0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
67+
0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
68+
};
69+
70+
uint8_t crc8ccitt(const void * data, size_t size) {
71+
uint8_t val = 0;
72+
73+
uint8_t * pos = (uint8_t *) data;
74+
uint8_t * end = pos + size;
75+
76+
while (pos < end) {
77+
val = CRC_TABLE[val ^ *pos];
78+
pos++;
79+
}
80+
81+
return val;
82+
}
83+
```

content/Gamecards.md

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -110,38 +110,40 @@ The header command has some initial dummy bytes, and eventually responds
110110
with the 0x200 byte [InitialData](NCSD#InitialData "wikilink"). Here's
111111
an example for Lego Starwars 3:
112112

113-
`0000000: 00 8c 03 00 00 00 04 00 00 00 00 00 00 00 00 00  ................`
114-
`0000010: b3 cf fb c6 6a b1 cb 20 32 af ce 35 d4 1c 74 c9  ....j.. 2..5..t.`
115-
`0000020: 8e 6b 27 2f 08 01 28 3b d4 30 de 44 37 f5 b0 46  .k'/..(;.0.D7..F`
116-
`0000030: 91 59 d7 38 33 48 df 83 fd 71 84 2c 00 00 00 00  .Y.83H...q.,....`
117-
`0000040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
118-
`0000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
119-
`0000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
120-
`0000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
121-
`0000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
122-
`0000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
123-
`00000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
124-
`00000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
125-
`00000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
126-
`00000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
127-
`00000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
128-
`00000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
129-
`0000100: 4e 43 43 48 7a 7f 0e 00 00 8c 03 00 00 00 04 00  NCCHz...........`
130-
`0000110: 36 34 02 00 00 00 00 00 00 8c 03 00 00 00 04 00  64..............`
131-
`0000120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
132-
`0000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
133-
`0000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................`
134-
`0000150: 43 54 52 2d 50 2d 41 4c 47 50 00 00 00 00 00 00  CTR-P-ALGP......`
135-
`0000160: 0c 27 e3 c1 de 7b 2a e2 d3 11 4f 32 a4 ee bf 46  .'...{*...O2...F`
136-
`0000170: 9a fd 0c f3 52 c1 1d 49 84 c2 a9 f1 d2 14 4c 63  ....R..I......Lc`
137-
`0000180: 00 04 00 00 00 00 00 00 00 00 00 00 01 03 00 00  ................`
138-
`0000190: 05 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00  ................`
139-
`00001a0: 06 00 00 00 1c 0a 00 00 01 00 00 00 00 00 00 00  ................`
140-
`00001b0: 22 0a 00 00 58 75 0e 00 01 00 00 00 00 00 00 00  "...Xu..........`
141-
`00001c0: 13 0c 04 26 15 f6 47 c4 c6 32 25 ea 9e 67 f8 a2  ...&..G..2%..g..`
142-
`00001d0: 7b 15 24 6b 88 fb c7 a9 27 25 7b 84 97 7b 78 7b  {.$k....'%{..{x{`
143-
`` 00001e0: a6 5b ee 10 60 bb 6a 68 21 bb ce c6 00 03 5b 7e  .[..`.jh!.....[~ ``
144-
`00001f0: 64 fb 6e ac a7 f0 96 0c fb 1f 5a 37 08 77 28 f7  d.n.......Z7.w(.`
113+
```
114+
0000000: 00 8c 03 00 00 00 04 00 00 00 00 00 00 00 00 00 ................
115+
0000010: b3 cf fb c6 6a b1 cb 20 32 af ce 35 d4 1c 74 c9 ....j.. 2..5..t.
116+
0000020: 8e 6b 27 2f 08 01 28 3b d4 30 de 44 37 f5 b0 46 .k'/..(;.0.D7..F
117+
0000030: 91 59 d7 38 33 48 df 83 fd 71 84 2c 00 00 00 00 .Y.83H...q.,....
118+
0000040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
119+
0000050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
120+
0000060: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
121+
0000070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
122+
0000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
123+
0000090: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
124+
00000a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
125+
00000b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
126+
00000c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
127+
00000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
128+
00000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
129+
00000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
130+
0000100: 4e 43 43 48 7a 7f 0e 00 00 8c 03 00 00 00 04 00 NCCHz...........
131+
0000110: 36 34 02 00 00 00 00 00 00 8c 03 00 00 00 04 00 64..............
132+
0000120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
133+
0000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
134+
0000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
135+
0000150: 43 54 52 2d 50 2d 41 4c 47 50 00 00 00 00 00 00 CTR-P-ALGP......
136+
0000160: 0c 27 e3 c1 de 7b 2a e2 d3 11 4f 32 a4 ee bf 46 .'...{*...O2...F
137+
0000170: 9a fd 0c f3 52 c1 1d 49 84 c2 a9 f1 d2 14 4c 63 ....R..I......Lc
138+
0000180: 00 04 00 00 00 00 00 00 00 00 00 00 01 03 00 00 ................
139+
0000190: 05 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 ................
140+
00001a0: 06 00 00 00 1c 0a 00 00 01 00 00 00 00 00 00 00 ................
141+
00001b0: 22 0a 00 00 58 75 0e 00 01 00 00 00 00 00 00 00 "...Xu..........
142+
00001c0: 13 0c 04 26 15 f6 47 c4 c6 32 25 ea 9e 67 f8 a2 ...&..G..2%..g..
143+
00001d0: 7b 15 24 6b 88 fb c7 a9 27 25 7b 84 97 7b 78 7b {.$k....'%{..{x{
144+
00001e0: a6 5b ee 10 60 bb 6a 68 21 bb ce c6 00 03 5b 7e .[..`.jh!.....[~
145+
00001f0: 64 fb 6e ac a7 f0 96 0c fb 1f 5a 37 08 77 28 f7 d.n.......Z7.w(.
146+
```
145147

146148
After the 0x82 command, cryptography is initialized, which can be
147149
reproduced following this algorithm; unless noted otherwise, all
@@ -190,4 +192,4 @@ The above example commands can be decrypted in this manner.
190192

191193
The static values are fixed in the gamecard controller and gamecards
192194
themselves, they are not obtained from Process9 or anywhere in
193-
NATIVE_FIRM.
195+
NATIVE_FIRM.

content/IPC.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ Usage examples:
313313
`Result ReplyAndReceive(s32* index, Handle* handles, s32 handleCount, Handle replyTarget)`
314314

315315
In a single operation, sends a IPC reply and waits for a new request.
316-
`handles` should be a pointer to an array of `handleCount`
317-
handles.<sup>TODO: Are only port/session handles supported?</sup>
316+
`handles` should be a pointer to an array of `handleCount` handles.<sup>TODO:
317+
Are only port/session handles supported?</sup>
318318
`replyTarget` should contain a handle to the session to send the reply
319319
to. (This is usually the session from which we received the previous
320320
request.) If `replyTarget` is 0, no reply and the call will simply wait
@@ -332,32 +332,34 @@ and then reply to it by calling svcReplyAndReceive again with
332332

333333
An example of a server svcReplyAndReceive loop is:
334334

335-
`#define MAX_CLIENTS 4`
336-
`Handle server_port = ...;`
337-
`s32 requesting_index;`
338-
`Handle handles[1 + MAX_CLIENTS] = { server_port };`
339-
`s32 connected_clients = 0;`
340-
`Handle reply_target = 0;`
341-
342-
`while (true) {`
343-
`    Result res = svcReplyAndReceive(&requesting_index, handles, 1 + connected_clients, reply_target);`
344-
345-
`    if (res == 0xC920181A) {`
346-
`        // Session was closed by remote`
347-
`        // TODO: Handle disconnects`
348-
`        reply_target = 0;`
349-
`        continue;`
350-
`    }`
351-
352-
`    if (requesting_index == 0) {`
353-
`        // New connection in server_port`
354-
`        ASSERT(connected_client < MAX_CLIENTS);`
355-
`        svcAcceptSession(&handles[1 + connected_clients++], server_port);`
356-
`        reply_target = 0;`
357-
`        continue;`
358-
`    }`
359-
360-
`    reply_target = handles[requesting_index];`
361-
362-
`    // Handle command here and write reply to command buffer`
363-
`}`
335+
```
336+
#define MAX_CLIENTS 4
337+
Handle server_port = ...;
338+
s32 requesting_index;
339+
Handle handles[1 + MAX_CLIENTS] = { server_port };
340+
s32 connected_clients = 0;
341+
Handle reply_target = 0;
342+
343+
while (true) {
344+
Result res = svcReplyAndReceive(&requesting_index, handles, 1 + connected_clients, reply_target);
345+
346+
if (res == 0xC920181A) {
347+
// Session was closed by remote
348+
// TODO: Handle disconnects
349+
reply_target = 0;
350+
continue;
351+
}
352+
353+
if (requesting_index == 0) {
354+
// New connection in server_port
355+
ASSERT(connected_client < MAX_CLIENTS);
356+
svcAcceptSession(&handles[1 + connected_clients++], server_port);
357+
reply_target = 0;
358+
continue;
359+
}
360+
361+
reply_target = handles[requesting_index];
362+
363+
// Handle command here and write reply to command buffer
364+
}
365+
```

0 commit comments

Comments
 (0)