Files
kaizen/external/unarr/rar/rar.h
T
iris 00cc9309cb Squashed 'external/ircolib/' changes from ce3cd726c..de6e324bd
de6e324bd separate emu thread
10d3daf86 Roms List improvements
95d202f37 Let's make the rom list process on a separate thread so the emulator doesnt take ages to load.
fc306967f Wow the ROM Header was just completely busted. Game list view works now
bad1691ee fuck this shit
2b59e5f46 game list in progress
d26417b83 remappable inputs in progress
ac4af8106 input
e72abc240 update readme
430139dc9 Qt6 frontend
3080d4d45 Fix this small bug too
08cd13b85 Cop0 unused functions do not actually pose a threat (as per manual). They don't do anything, so shall we.
61bb4fb44 make idle loop detection a little more specific with where the load goes
b037de4c3 SAZDFsdff
12e81e73e need to figure out why n64-systemtest loops indefinitely at some address that appears to be valid (i think it's me not invalidating the cache properly)
204f0e13b idle skipping seems to work!
cb8bb634a sdkfjlasdf
58e5c89c1 Fix compilation issue on my machine (no idea)
24fb2898e attempting more serious idle skipping
214719577 Place rsp.Step inside cached interpreter. Gains about 3 more fps
bb97dcc23 mmmmm
920b77d38 wjkhasdfjhkasdf
430ccdab4 it's a start...
4f42a673a Cached interpreter plays Mario 64. Start looking into RSP as well
c9a030787 idle skipping works!
5fbda03ce new idea
366637aba Idle skipping... maybe?
609fa2fb0 Cache instructions implemented but broken lmao. Commented out for now
e140a6d12 - Stop using inheritance for CPU, instead use composition. - Introduce KAIZEN_JIT_ENABLED optional define instead of relying on __aarch64__ and the like. - More cache work
68e613057 prep cache impl
811b4d809 fix clang format
fda755f7d idk
d5024ebbf small MI refactor in preparation of (eventually) implementing the RDRAM interface properly
694b45341 Merge commit '206dcdedf195fb320913584180edb12c7731e396' as 'external/SDL'
206dcdedf Squashed 'external/SDL/' content from commit 4d17b99d0a
4d16e1cb4 need to update sdl
848b19920 Fix compilation error
db61b5299 Merge commit 'e94a94559f28e49678fbcf72199a5258137b0fe9' as 'external/imgui'
e94a94559 Squashed 'external/imgui/' content from commit 02e9b8cac
52edb3757 need to update imgui
c1a705e86 Emulate weird JALR behaviour
4b4c32f4b Fix exception for "unusable COP1" in 4 instructions i missed accidentally (again)
df5828142 Bug putting 0s in the log everywhere
f8b580048 Make isviewer a sink to file
8241e9735 Fix exception for "unusable COP1" in 4 instructions i missed accidentally
b29715f20 small changes
d9a620bc1 make use of my new small utility library
0d1aa938e Add 'external/ircolib/' from commit 'ce3cd726c8df8388d554abf8bb55d55020eb4450'
e64eb40b3 Fuck git

git-subtree-dir: external/ircolib
git-subtree-split: de6e324bde
2026-06-15 11:56:38 +02:00

244 lines
6.0 KiB
C

/* Copyright 2015 the unarr project authors (see AUTHORS file).
License: LGPLv3 */
#ifndef rar_rar_h
#define rar_rar_h
#include "../common/unarr-imp.h"
#include "lzss.h"
#include "../lzmasdk/Ppmd7.h"
#include <limits.h>
static inline size_t smin(size_t a, size_t b) { return a < b ? a : b; }
typedef struct ar_archive_rar_s ar_archive_rar;
/***** parse-rar *****/
#define FILE_SIGNATURE_SIZE 7
enum block_types {
TYPE_FILE_SIGNATURE = 0x72, TYPE_MAIN_HEADER = 0x73, TYPE_FILE_ENTRY = 0x74,
TYPE_NEWSUB = 0x7A, TYPE_END_OF_ARCHIVE = 0x7B,
};
enum archive_flags {
MHD_VOLUME = 1 << 0, MHD_COMMENT = 1 << 1, MHD_LOCK = 1 << 2,
MHD_SOLID = 1 << 3, MHD_PACK_COMMENT = 1 << 4, MHD_AV = 1 << 5,
MHD_PROTECT = 1 << 6, MHD_PASSWORD = 1 << 7, MHD_FIRSTVOLUME = 1 << 8,
MHD_ENCRYPTVER = 1 << 9,
MHD_LONG_BLOCK = 1 << 15,
};
enum entry_flags {
LHD_SPLIT_BEFORE = 1 << 0, LHD_SPLIT_AFTER = 1 << 1, LHD_PASSWORD = 1 << 2,
LHD_COMMENT = 1 << 3, LHD_SOLID = 1 << 4,
LHD_DIRECTORY = (1 << 5) | (1 << 6) | (1 << 7),
LHD_LARGE = 1 << 8, LHD_UNICODE = 1 << 9, LHD_SALT = 1 << 10,
LHD_VERSION = 1 << 11, LHD_EXTTIME = 1 << 12, LHD_EXTFLAGS = 1 << 13,
LHD_LONG_BLOCK = 1 << 15,
};
enum compression_method {
METHOD_STORE = 0x30,
METHOD_FASTEST = 0x31, METHOD_FAST = 0x32, METHOD_NORMAL = 0x33,
METHOD_GOOD = 0x34, METHOD_BEST = 0x35,
};
struct rar_header {
uint16_t crc;
uint8_t type;
uint16_t flags;
uint16_t size;
uint64_t datasize;
};
struct rar_entry {
uint64_t size;
uint8_t os;
uint32_t crc;
uint32_t dosdate;
uint8_t version;
uint8_t method;
uint16_t namelen;
uint32_t attrs;
};
struct ar_archive_rar_entry {
uint8_t version;
uint8_t method;
uint32_t crc;
uint16_t header_size;
bool solid;
char *name;
};
bool rar_parse_header(ar_archive *ar, struct rar_header *header);
bool rar_check_header_crc(ar_archive *ar);
bool rar_parse_header_entry(ar_archive_rar *rar, struct rar_header *header, struct rar_entry *entry);
const char *rar_get_name(ar_archive *ar, bool raw);
/***** filter-rar *****/
struct RARVirtualMachine;
struct RARProgramCode;
struct RARFilter;
struct ar_archive_rar_filters {
struct RARVirtualMachine *vm;
struct RARProgramCode *progs;
struct RARFilter *stack;
size_t filterstart;
uint32_t lastfilternum;
size_t lastend;
uint8_t *bytes;
size_t bytes_ready;
};
bool rar_parse_filter(ar_archive_rar *rar, const uint8_t *bytes, uint16_t length, uint8_t flags);
bool rar_run_filters(ar_archive_rar *rar);
void rar_clear_filters(struct ar_archive_rar_filters *filters);
/***** huffman-rar *****/
struct huffman_code {
struct {
int branches[2];
} *tree;
int numentries;
int capacity;
int minlength;
int maxlength;
struct {
int length;
int value;
} *table;
int tablesize;
};
bool rar_new_node(struct huffman_code *code);
bool rar_add_value(struct huffman_code *code, int value, int codebits, int length);
bool rar_create_code(struct huffman_code *code, uint8_t *lengths, int numsymbols);
bool rar_make_table(struct huffman_code *code);
void rar_free_code(struct huffman_code *code);
static inline bool rar_is_leaf_node(struct huffman_code *code, int node) { return code->tree[node].branches[0] == code->tree[node].branches[1]; }
/***** uncompress-rar *****/
#define LZSS_WINDOW_SIZE 0x400000
#define LZSS_OVERFLOW_SIZE 288
#define MAINCODE_SIZE 299
#define OFFSETCODE_SIZE 60
#define LOWOFFSETCODE_SIZE 17
#define LENGTHCODE_SIZE 28
#define HUFFMAN_TABLE_SIZE MAINCODE_SIZE + OFFSETCODE_SIZE + LOWOFFSETCODE_SIZE + LENGTHCODE_SIZE
struct ByteReader {
IByteIn super;
ar_archive_rar *rar;
};
struct ar_archive_rar_uncomp_v3 {
struct huffman_code maincode;
struct huffman_code offsetcode;
struct huffman_code lowoffsetcode;
struct huffman_code lengthcode;
uint8_t lengthtable[HUFFMAN_TABLE_SIZE];
uint32_t lastlength;
uint32_t lastoffset;
uint32_t oldoffset[4];
uint32_t lastlowoffset;
uint32_t numlowoffsetrepeats;
bool is_ppmd_block;
int ppmd_escape;
CPpmd7 ppmd7_context;
struct ByteReader bytein;
struct ar_archive_rar_filters filters;
};
#define MAINCODE_SIZE_20 298
#define OFFSETCODE_SIZE_20 48
#define LENGTHCODE_SIZE_20 28
#define HUFFMAN_TABLE_SIZE_20 4 * 257
struct AudioState {
int8_t weight[5];
int16_t delta[4];
int8_t lastdelta;
int error[11];
int count;
uint8_t lastbyte;
};
struct ar_archive_rar_uncomp_v2 {
struct huffman_code maincode;
struct huffman_code offsetcode;
struct huffman_code lengthcode;
struct huffman_code audiocode[4];
uint8_t lengthtable[HUFFMAN_TABLE_SIZE_20];
uint32_t lastoffset;
uint32_t lastlength;
uint32_t oldoffset[4];
uint32_t oldoffsetindex;
bool audioblock;
uint8_t channel;
uint8_t numchannels;
struct AudioState audiostate[4];
int8_t channeldelta;
};
struct ar_archive_rar_uncomp {
uint8_t version;
LZSS lzss;
size_t bytes_ready;
bool start_new_table;
union {
struct ar_archive_rar_uncomp_v3 v3;
struct ar_archive_rar_uncomp_v2 v2;
} state;
struct StreamBitReader {
uint64_t bits;
int available;
bool at_eof;
} br;
};
bool rar_uncompress_part(ar_archive_rar *rar, void *buffer, size_t buffer_size);
int64_t rar_expand(ar_archive_rar *rar, int64_t end);
void rar_clear_uncompress(struct ar_archive_rar_uncomp *uncomp);
static inline void br_clear_leftover_bits(struct ar_archive_rar_uncomp *uncomp) { uncomp->br.available &= ~0x07; }
/***** rar *****/
struct ar_archive_rar_progress {
size_t data_left;
size_t bytes_done;
uint32_t crc;
};
struct ar_archive_rar_solid {
size_t size_total;
bool part_done;
bool restart;
};
struct ar_archive_rar_s {
ar_archive super;
uint16_t archive_flags;
struct ar_archive_rar_entry entry;
struct ar_archive_rar_uncomp uncomp;
struct ar_archive_rar_progress progress;
struct ar_archive_rar_solid solid;
};
#endif