1/*****
2 * SPC7110 emulator - version 0.03 (2008-08-10)
3 * Copyright (c) 2008, byuu and neviksti
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * The software is provided "as is" and the author disclaims all warranties
10 * with regard to this software including all implied warranties of
11 * merchantibility and fitness, in no event shall the author be liable for
12 * any special, direct, indirect, or consequential damages or any damages
13 * whatsoever resulting from loss of use, data or profits, whether in an
14 * action of contract, negligence or other tortious action, arising out of
15 * or in connection with the use or performance of this software.
16 *****/
17
18
19#ifndef _SPC7110DEC_H_
20#define _SPC7110DEC_H_
21
22class SPC7110Decomp {
23public:
24 uint8 read();
25 void init(unsigned mode, unsigned offset, unsigned index);
26 void reset();
27
28 SPC7110Decomp();
29 ~SPC7110Decomp();
30
31 unsigned decomp_mode;
32 unsigned decomp_offset;
33
34 //read() will spool chunks half the size of decomp_buffer_size
35 enum { decomp_buffer_size = SPC7110_DECOMP_BUFFER_SIZE }; //must be >= 64, and must be a power of two
36 uint8 *decomp_buffer;
37 unsigned decomp_buffer_rdoffset;
38 unsigned decomp_buffer_wroffset;
39 unsigned decomp_buffer_length;
40
41 void write(uint8 data);
42 uint8 dataread();
43
44 void mode0(bool init);
45 void mode1(bool init);
46 void mode2(bool init);
47
48 static const uint8 evolution_table[53][4];
49 static const uint8 mode2_context_table[32][2];
50
51 struct ContextState {
52 uint8 index;
53 uint8 invert;
54 } context[32];
55
56 uint8 probability(unsigned n);
57 uint8 next_lps(unsigned n);
58 uint8 next_mps(unsigned n);
59 uint8 toggle_invert(unsigned n);
60
61 unsigned morton16[2][256];
62 unsigned morton32[4][256];
63 unsigned morton_2x8(unsigned data);
64 unsigned morton_4x8(unsigned data);
65};
66
67#endif
68