This commit is contained in:
UserDeploy 2025-04-15 19:20:11 +07:00
parent 873972b35e
commit 86fbd2b379
5 changed files with 11170 additions and 76 deletions

3
.gitignore vendored
View file

@ -7,4 +7,5 @@
*.txt
*.exe
*.out
dev_resource/
dev_resource/
compress_test.bat

View file

@ -1,2 +1,2 @@
@echo off
clang -DDCC_TESTING test.c dcc/dn_dcc_proto.c minilzo/minilzo.c lz4/lz4_fs.c plat/wdog.c -o dcc_test.exe
clang -DDCC_TESTING -DHAVE_MINILZO=1 -DHAVE_LZ4=1 -D_CRT_SECURE_NO_WARNINGS=1 test/test_rle_compress.c dcc/dn_dcc_proto.c minilzo/minilzo.c lz4/lz4_fs.c plat/wdog.c -o dcc_test_rle.exe

74
test.c
View file

@ -1,74 +0,0 @@
#include "dcc/dn_dcc_proto.h"
#include <stdio.h>
static uint8_t testComp[512] = {
0x0F, 0x00, 0x00, 0xEA, 0x34, 0xF0, 0x9F, 0xE5, 0x30, 0xF0, 0x9F, 0xE5,
0x2C, 0xF0, 0x9F, 0xE5, 0x28, 0xF0, 0x9F, 0xE5, 0x24, 0xF0, 0x9F, 0xE5,
0x20, 0xF0, 0x9F, 0xE5, 0x1C, 0xF0, 0x9F, 0xE5, 0xAA, 0xAA, 0xAA, 0xAA,
0x00, 0x00, 0x00, 0x00, 0xAA, 0xAA, 0xAA, 0xAA, 0x0C, 0x00, 0x02, 0x00,
0x08, 0x60, 0x04, 0x14, 0x68, 0x00, 0x00, 0x14, 0xEF, 0xBE, 0xAD, 0xDE,
0xFE, 0xFF, 0xFF, 0xEA, 0x3C, 0x00, 0x00, 0x14, 0xD3, 0xF0, 0x21, 0xE3,
0x81, 0x00, 0x00, 0xEB, 0x8C, 0x00, 0x00, 0xEB, 0x3C, 0xD2, 0x9F, 0xE5,
0xFF, 0x02, 0x00, 0xEB, 0x38, 0x02, 0x9F, 0xE5, 0x0F, 0xE0, 0xA0, 0xE1,
0x10, 0xFF, 0x2F, 0xE1, 0xF4, 0xFF, 0xFF, 0xE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52, 0xE2,
0xFC, 0xFF, 0xFF, 0xEA, 0x04, 0x20, 0x90, 0xE4, 0x00, 0x40, 0x82, 0xE5,
0x1E, 0xFF, 0x2F, 0xE1, 0x04, 0x20, 0x90, 0xE4, 0x02, 0x40, 0x84, 0xE1,
0x1E, 0xFF, 0x2F, 0xE1, 0x04, 0x20, 0x90, 0xE4
};
// Testing
int main(void) {
uint32_t test_comp;
uint8_t pkt[2048] = { 0 };
test_comp = DN_Packet_Compress(testComp, 0x200, pkt);
printf("COMP 1: ");
for (int i = 0; i < test_comp; i++) {
printf("%02X", pkt[i]);
}
printf("\n");
test_comp = DN_Packet_Compress2(testComp, 0x200, pkt);
printf("COMP 2: ");
for (int i = 0; i < test_comp; i++) {
printf("%02X", pkt[i]);
}
printf("\n");
test_comp = DN_Packet_Compress3(testComp, 0x200, pkt);
printf("COMP 3: ");
for (int i = 0; i < test_comp; i++) {
printf("%02X", pkt[i]);
}
printf("\n");
}

11071
test/test_rle_compress.c Normal file

File diff suppressed because it is too large Load diff

96
tools/riffHASDis.py Normal file
View file

@ -0,0 +1,96 @@
import struct
import sys
if __name__ == "__main__":
f = open(sys.argv[1], "rb")
while True:
fp = f.read(4)
if len(fp) < 4: break
cmd = int.from_bytes(fp, "little", signed=True)
if cmd == -1:
offset, data = struct.unpack("<LL", f.read(8))
print(f"{cmd} (WRITE): {hex(offset)} {hex(data)}")
elif cmd == -9:
offset, data = struct.unpack("<LL", f.read(8))
print(f"{cmd} (WRITE8): {hex(offset)} {hex(data)}")
elif cmd == -8:
offset, data = struct.unpack("<LL", f.read(8))
print(f"{cmd} (WRITE16): {hex(offset)} {hex(data)}")
elif cmd == -2:
offset = int.from_bytes(f.read(4), "little")
print(f"{cmd} (READ): {hex(offset)}")
elif cmd in [-3, -21]:
offset, data = struct.unpack("<LL", f.read(8))
print(f"{cmd} (AND): v({hex(offset)}) | {hex(data)}")
elif cmd in [-42, -44]:
offset, data = struct.unpack("<LL", f.read(8))
print(f"{cmd} (OR): v({hex(offset)}) & ~{hex(data)}")
elif cmd == -43:
offset, mask, data = struct.unpack("<LLL", f.read(12))
print(f"{cmd} (READ OR): (v({hex(offset)}) & ~{hex(mask)}) | {hex(data)}")
elif cmd == -250: # Unknown 2
print(f"{cmd}: {f.read(4)}")
elif cmd == -19:
code = int.from_bytes(f.read(4), "little")
print(f"{cmd} (SKIP), {code}")
elif cmd == -40:
code = int.from_bytes(f.read(4), "little")
print(f"{cmd} (READ_AND_PRINT), {hex(code)}")
elif cmd == -12: # COPROC
cr_m, cr_n, cp_no, op, data = struct.unpack("<BBBBL", f.read(8))
print(F"{cmd} (COPROC) {cp_no}, {cr_n}, {cr_m}, {op}, {hex(data)}")
elif cmd == -7: # Write again
offset, value, mask = struct.unpack("<LLL", f.read(0xc))
print(f"{cmd} (WRITE AND): {hex(offset)}, ({hex(mask)} | {hex(value)}) = {hex(value | mask)}")
#print(f"{cmd} (WRITE OR): (v({hex(offset)}) & ~{hex(mask)}) | {hex(value)}")
elif cmd in [-17, -25]:
offset, mask, expected, delay, branch = struct.unpack("<LLLLL", f.read(0x14))
print(f"{cmd} (READ and WAIT COND): ({hex(offset)} & {hex(mask)}) != {expected}, max: {delay}ms, SKIP {branch} INSTRUCTION if TRUE")
elif cmd in [-18, -26]:
offset, mask, expected, delay, branch = struct.unpack("<LLLLL", f.read(0x14))
print(f"{cmd} (READ and WAIT COND): ({hex(offset)} & {hex(mask)}) == {expected}, max: {delay}ms, SKIP {branch} INSTRUCTION if TRUE")
elif cmd == -54:
offset, bits = struct.unpack("<LL", f.read(0x8))
print(f"{cmd} (READ BYTES and PRINT) {hex(offset)} {bits}")
elif cmd == -59:
offset, count, value = struct.unpack("<LLL", f.read(0xc))
print(f"{cmd} (WRITE8) {hex(offset)} {hex(value)} {count}")
elif cmd == -58:
offset, count, value = struct.unpack("<LLL", f.read(0xc))
print(f"{cmd} (WRITE16) {hex(offset)} {hex(value)} {count}")
elif cmd == -41:
reg = int.from_bytes(f.read(4), "little")
print(f"{cmd} (PRINT): {hex(reg)}")
elif cmd == -38:
mask, cond, branch = struct.unpack("<LLL", f.read(0xc))
print(f"{cmd} (COND): (a & {hex(mask)}) == {hex(cond)}, SKIP {branch} INSTRUCTION if TRUE")
elif cmd == -39:
mask, cond, branch = struct.unpack("<LLL", f.read(0xc))
print(f"{cmd} (COND): (a & {hex(mask)}) != {hex(cond)}, SKIP {branch} INSTRUCTION if TRUE")
elif cmd == -255:
print(f"{cmd} (RETURN)")
else:
raise Exception(f"command {cmd} {hex(f.tell() - 4)}")