|
| 1 | +import std.array; |
| 2 | +import std.io; |
| 3 | +import std.mem; |
| 4 | +import type.magic; |
| 5 | + |
| 6 | +/// Source: https://merthsoft.com/linkguide/ti83+/fformat.html |
| 7 | + |
| 8 | +struct Header { |
| 9 | + type::Magic<"**TI83F*">; |
| 10 | + char mysteryBytes[3]; |
| 11 | + char comment[0x2A]; |
| 12 | + le u16 datasize; |
| 13 | +} [[static]]; |
| 14 | + |
| 15 | +enum StorageType: u8 { |
| 16 | + Archive = 0x80, |
| 17 | + RAM = 0x00 |
| 18 | +}; |
| 19 | + |
| 20 | +// Source: https://merthsoft.com/linkguide/ti83+/packet.html#vartypes |
| 21 | +// Although 8e (TI 84 Plus CE flash) files are listed for completeness, they use a different file format and magic number |
| 22 | +enum VariableType: u8 { |
| 23 | + RealNumber = 0x00, // 8xn |
| 24 | + RealList = 0x01, // 8xl |
| 25 | + Matrix = 0x02, // 8xm |
| 26 | + Yvar = 0x03, // 8xy |
| 27 | + String = 0x04, // 8xs |
| 28 | + Program = 0x05, // 8xp |
| 29 | + ProtectedProgram = 0x06, // 8xp |
| 30 | + Picture = 0x07, // 8xi |
| 31 | + GDB = 0x08, // 8xd |
| 32 | + Window = 0x0B, // 8xw |
| 33 | + Complex = 0x0C, // 8xc |
| 34 | + ComplexList = 0x0D, // 8xl |
| 35 | + Window = 0x0F, // 8xw |
| 36 | + RclWindw = 0x10, // 8xz |
| 37 | + TblSet = 0x11, // 8xt |
| 38 | + Backup = 0x13, // Packet header |
| 39 | + DeleteFlash = 0x14, // Packet header |
| 40 | + AppVar = 0x15, // 8xv |
| 41 | + Group = 0x17, // 8xg |
| 42 | + DirectoryList = 0x19, // Packet header |
| 43 | + FlashOS = 0x23, // Packet header, 8eu, 8xu apparently? |
| 44 | + FlashApp = 0x24, // Packet header, 8ek, 8xk apparently? |
| 45 | + IDLIST = 0x26, // Packet header |
| 46 | + Certificate = 0x27, // Packet header, 8xq apparently? |
| 47 | + Clock = 0x29 // Packet header |
| 48 | +}; |
| 49 | + |
| 50 | +struct Variable { |
| 51 | + le u16 entryFormat; |
| 52 | + le u16 length; |
| 53 | + VariableType type; |
| 54 | + char name[8]; |
| 55 | + if (entryFormat == 0xD) { |
| 56 | + u8 version; |
| 57 | + StorageType storage; |
| 58 | + } |
| 59 | + le u16 length2; |
| 60 | + u8 content[length]; |
| 61 | + |
| 62 | +}; |
| 63 | + |
| 64 | +Header header @ 0; |
| 65 | +std::ByteSizedArray<Variable, header.datasize> content @ 0x37; |
| 66 | +le u16 checksum @ 0x37+header.datasize; |
| 67 | + |
| 68 | +fn makeChecksum() { |
| 69 | + u32 sum = 0; |
| 70 | + for (u32 i = 0, i < header.datasize, i = i + 1) { |
| 71 | + sum += std::mem::read_unsigned(0x37+i, 8, std::mem::Endian::Little); |
| 72 | + } |
| 73 | + u16 result = sum & 0xFFFF; |
| 74 | + return result; |
| 75 | +}; |
| 76 | + |
| 77 | +u16 realChecksum out; |
| 78 | +realChecksum = makeChecksum(); |
0 commit comments