summaryrefslogtreecommitdiffstats
path: root/src/mame
diff options
context:
space:
mode:
authorGravatarGravatar Fabio Priuli <etabeta78@users.noreply.github.com>2013-02-10 09:14:58 +0000
committerGravatarGravatar Fabio Priuli <etabeta78@users.noreply.github.com>2013-02-10 09:14:58 +0000
commit3ffebc85898d37407097d84082320ca9fc333169 (patch) (github)
tree43efc661a2590c20631afa604831289df5a89e16 /src/mame
parentfb2b198f2e3372847dec348cc9e9d5b21c8d9733 (diff)
downloadmame-3ffebc85898d37407097d84082320ca9fc333169.tar.bz2
mame-3ffebc85898d37407097d84082320ca9fc333169.zip
(MESS) snes.c: refactored SPC7110 and SDD1 implementations to be more class-friendly
and not to use running_machine to access the ROM data. no whatsnew.
Diffstat (limited to 'src/mame')
-rw-r--r--src/mame/machine/snes7110.c490
-rw-r--r--src/mame/machine/snessdd1.c387
2 files changed, 419 insertions, 458 deletions
diff --git a/src/mame/machine/snes7110.c b/src/mame/machine/snes7110.c
index b677ea61811..ad27cd0ac65 100644
--- a/src/mame/machine/snes7110.c
+++ b/src/mame/machine/snes7110.c
@@ -15,7 +15,7 @@
***************************************************************************/
-static const UINT32 spc7110_decomp_buffer_size = 64;
+#define SPC7110_DECOMP_BUFFER_SIZE 64
static const UINT8 spc7110_evolution_table[53][4] =
{
@@ -118,142 +118,141 @@ static const UINT8 spc7110_mode2_context_table[32][2] =
{ 31, 31 },
};
-struct SPC7110Decomp
+class SPC7110Decomp
{
- running_machine &machine() const { assert(m_machine != NULL); return *m_machine; }
-
- running_machine *m_machine;
-
- UINT32 decomp_mode;
- UINT32 decomp_offset;
-
- UINT8 *decomp_buffer;
- UINT32 decomp_buffer_rdoffset;
- UINT32 decomp_buffer_wroffset;
- UINT32 decomp_buffer_length;
+public:
+ SPC7110Decomp(running_machine &machine, UINT32 size);
+
+ running_machine &machine() const { return m_machine; }
+
+ void init(running_machine &machine, UINT8 *ROM, UINT32 mode, UINT32 offset, UINT32 index);
+ void reset();
+
+ UINT8 read(UINT8 *ROM);
+ void write(UINT8 data);
+ void mode0(UINT8 init, UINT8 *ROM);
+ void mode1(UINT8 init, UINT8 *ROM);
+ void mode2(UINT8 init, UINT8 *ROM);
+
+ UINT8 dataread(UINT8 *ROM);
+ UINT8 probability(UINT32 n);
+ UINT8 next_lps(UINT32 n);
+ UINT8 next_mps(UINT32 n);
+ UINT8 toggle_invert(UINT32 n);
+ UINT32 morton_2x8(UINT32 data);
+ UINT32 morton_4x8(UINT32 data);
+
+ UINT32 m_decomp_mode;
+ UINT32 m_decomp_offset;
+
+ UINT8 *m_decomp_buffer;
+ UINT32 m_decomp_buffer_rdoffset;
+ UINT32 m_decomp_buffer_wroffset;
+ UINT32 m_decomp_buffer_length;
struct ContextState
{
UINT8 index;
UINT8 invert;
- } context[32];
+ } m_context[32];
- UINT32 morton16[2][256];
- UINT32 morton32[4][256];
+ UINT32 m_morton16[2][256];
+ UINT32 m_morton32[4][256];
- UINT32 rom_size;
+
+private:
+ running_machine& m_machine;
+ UINT32 m_rom_size;
};
-static SPC7110Decomp* SPC7110Decomp_ctor(running_machine &machine, UINT32 size);
-static void SPC7110Decomp_reset(SPC7110Decomp *thisptr);
-static void SPC7110Decomp_init(SPC7110Decomp *thisptr, running_machine &machine, UINT32 mode, UINT32 offset, UINT32 index);
-static UINT8 SPC7110Decomp_read(SPC7110Decomp *thisptr);
-static void SPC7110Decomp_write(SPC7110Decomp *thisptr, UINT8 data);
-static UINT8 SPC7110Decomp_dataread(SPC7110Decomp *thisptr);
-static void SPC7110Decomp_mode0(SPC7110Decomp *thisptr, UINT8 init);
-static void SPC7110Decomp_mode1(SPC7110Decomp *thisptr, UINT8 init);
-static void SPC7110Decomp_mode2(SPC7110Decomp *thisptr, UINT8 init);
-static UINT8 SPC7110Decomp_probability(SPC7110Decomp *thisptr, UINT32 n);
-static UINT8 SPC7110Decomp_next_lps(SPC7110Decomp *thisptr, UINT32 n);
-static UINT8 SPC7110Decomp_next_mps(SPC7110Decomp *thisptr, UINT32 n);
-static UINT8 SPC7110Decomp_toggle_invert(SPC7110Decomp *thisptr, UINT32 n);
-static UINT32 SPC7110Decomp_morton_2x8(SPC7110Decomp *thisptr, UINT32 data);
-static UINT32 SPC7110Decomp_morton_4x8(SPC7110Decomp *thisptr, UINT32 data);
-
-static SPC7110Decomp* SPC7110Decomp_ctor(running_machine &machine, UINT32 size)
+SPC7110Decomp::SPC7110Decomp(running_machine &machine, UINT32 size)
+ : m_machine(machine),
+ m_rom_size(size)
{
- UINT32 i;
- SPC7110Decomp* newclass = (SPC7110Decomp*)auto_alloc_array(machine, UINT8, sizeof(SPC7110Decomp));
- newclass->decomp_buffer = (UINT8*)auto_alloc_array(machine, UINT8, spc7110_decomp_buffer_size);
- SPC7110Decomp_reset(newclass);
+ m_decomp_buffer = (UINT8*)auto_alloc_array(machine, UINT8, SPC7110_DECOMP_BUFFER_SIZE);
+ reset();
- for(i = 0; i < 256; i++)
+ for (int i = 0; i < 256; i++)
{
#define map(x, y) (((i >> x) & 1) << y)
//2x8-bit
- newclass->morton16[1][i] = map(7, 15) + map(6, 7) + map(5, 14) + map(4, 6)
- + map(3, 13) + map(2, 5) + map(1, 12) + map(0, 4);
- newclass->morton16[0][i] = map(7, 11) + map(6, 3) + map(5, 10) + map(4, 2)
- + map(3, 9) + map(2, 1) + map(1, 8) + map(0, 0);
+ m_morton16[1][i] = map(7, 15) + map(6, 7) + map(5, 14) + map(4, 6)
+ + map(3, 13) + map(2, 5) + map(1, 12) + map(0, 4);
+ m_morton16[0][i] = map(7, 11) + map(6, 3) + map(5, 10) + map(4, 2)
+ + map(3, 9) + map(2, 1) + map(1, 8) + map(0, 0);
//4x8-bit
- newclass->morton32[3][i] = map(7, 31) + map(6, 23) + map(5, 15) + map(4, 7)
- + map(3, 30) + map(2, 22) + map(1, 14) + map(0, 6);
- newclass->morton32[2][i] = map(7, 29) + map(6, 21) + map(5, 13) + map(4, 5)
- + map(3, 28) + map(2, 20) + map(1, 12) + map(0, 4);
- newclass->morton32[1][i] = map(7, 27) + map(6, 19) + map(5, 11) + map(4, 3)
- + map(3, 26) + map(2, 18) + map(1, 10) + map(0, 2);
- newclass->morton32[0][i] = map(7, 25) + map(6, 17) + map(5, 9) + map(4, 1)
- + map(3, 24) + map(2, 16) + map(1, 8) + map(0, 0);
+ m_morton32[3][i] = map(7, 31) + map(6, 23) + map(5, 15) + map(4, 7)
+ + map(3, 30) + map(2, 22) + map(1, 14) + map(0, 6);
+ m_morton32[2][i] = map(7, 29) + map(6, 21) + map(5, 13) + map(4, 5)
+ + map(3, 28) + map(2, 20) + map(1, 12) + map(0, 4);
+ m_morton32[1][i] = map(7, 27) + map(6, 19) + map(5, 11) + map(4, 3)
+ + map(3, 26) + map(2, 18) + map(1, 10) + map(0, 2);
+ m_morton32[0][i] = map(7, 25) + map(6, 17) + map(5, 9) + map(4, 1)
+ + map(3, 24) + map(2, 16) + map(1, 8) + map(0, 0);
#undef map
}
-
- newclass->rom_size = size;
-
- return newclass;
}
-static void SPC7110Decomp_reset(SPC7110Decomp *thisptr)
+void SPC7110Decomp::reset()
{
//mode 3 is invalid; this is treated as a special case to always return 0x00
//set to mode 3 so that reading decomp port before starting first decomp will return 0x00
- thisptr->decomp_mode = 3;
+ m_decomp_mode = 3;
- thisptr->decomp_buffer_rdoffset = 0;
- thisptr->decomp_buffer_wroffset = 0;
- thisptr->decomp_buffer_length = 0;
+ m_decomp_buffer_rdoffset = 0;
+ m_decomp_buffer_wroffset = 0;
+ m_decomp_buffer_length = 0;
}
-static void SPC7110Decomp_init(SPC7110Decomp *thisptr, running_machine &machine, UINT32 mode, UINT32 offset, UINT32 index)
+void SPC7110Decomp::init(running_machine &machine, UINT8 *ROM, UINT32 mode, UINT32 offset, UINT32 index)
{
- UINT32 i;
+ m_decomp_mode = mode;
+ m_decomp_offset = offset;
- thisptr->m_machine = &machine;
-
- thisptr->decomp_mode = mode;
- thisptr->decomp_offset = offset;
-
- thisptr->decomp_buffer_rdoffset = 0;
- thisptr->decomp_buffer_wroffset = 0;
- thisptr->decomp_buffer_length = 0;
+ m_decomp_buffer_rdoffset = 0;
+ m_decomp_buffer_wroffset = 0;
+ m_decomp_buffer_length = 0;
//reset context states
- for(i = 0; i < 32; i++)
+ for (int i = 0; i < 32; i++)
{
- thisptr->context[i].index = 0;
- thisptr->context[i].invert = 0;
+ m_context[i].index = 0;
+ m_context[i].invert = 0;
}
- switch(thisptr->decomp_mode)
+ switch (m_decomp_mode)
{
- case 0: SPC7110Decomp_mode0(thisptr, 1); break;
- case 1: SPC7110Decomp_mode1(thisptr, 1); break;
- case 2: SPC7110Decomp_mode2(thisptr, 1); break;
+ case 0: mode0(1, ROM); break;
+ case 1: mode1(1, ROM); break;
+ case 2: mode2(1, ROM); break;
}
//decompress up to requested output data index
- while(index--)
+ while (index--)
{
- SPC7110Decomp_read(thisptr);
+ read(ROM);
}
}
-static UINT8 SPC7110Decomp_read(SPC7110Decomp *thisptr)
+UINT8 SPC7110Decomp::read(UINT8 *ROM)
{
UINT8 data;
- if(thisptr->decomp_buffer_length == 0) {
- //decompress at least (spc7110_decomp_buffer_size / 2) bytes to the buffer
- switch(thisptr->decomp_mode) {
+ if (m_decomp_buffer_length == 0)
+ {
+ //decompress at least (SPC7110_DECOMP_BUFFER_SIZE / 2) bytes to the buffer
+ switch (m_decomp_mode)
+ {
case 0:
- SPC7110Decomp_mode0(thisptr, 0);
+ mode0(0, ROM);
break;
case 1:
- SPC7110Decomp_mode1(thisptr, 0);
+ mode1(0, ROM);
break;
case 2:
- SPC7110Decomp_mode2(thisptr, 0);
+ mode2(0, ROM);
break;
default:
@@ -261,66 +260,64 @@ static UINT8 SPC7110Decomp_read(SPC7110Decomp *thisptr)
}
}
- data = thisptr->decomp_buffer[thisptr->decomp_buffer_rdoffset++];
- thisptr->decomp_buffer_rdoffset &= spc7110_decomp_buffer_size - 1;
- thisptr->decomp_buffer_length--;
+ data = m_decomp_buffer[m_decomp_buffer_rdoffset++];
+ m_decomp_buffer_rdoffset &= SPC7110_DECOMP_BUFFER_SIZE - 1;
+ m_decomp_buffer_length--;
return data;
}
-static void SPC7110Decomp_write(SPC7110Decomp *thisptr, UINT8 data)
+void SPC7110Decomp::write(UINT8 data)
{
- thisptr->decomp_buffer[thisptr->decomp_buffer_wroffset++] = data;
- thisptr->decomp_buffer_wroffset &= spc7110_decomp_buffer_size - 1;
- thisptr->decomp_buffer_length++;
+ m_decomp_buffer[m_decomp_buffer_wroffset++] = data;
+ m_decomp_buffer_wroffset &= SPC7110_DECOMP_BUFFER_SIZE - 1;
+ m_decomp_buffer_length++;
}
-static UINT8 SPC7110Decomp_dataread(SPC7110Decomp *thisptr)
+UINT8 SPC7110Decomp::dataread(UINT8 *ROM)
{
- UINT8 *ROM = thisptr->machine().root_device().memregion("cart")->base();
- UINT32 size = thisptr->rom_size - 0x100000;
- while(thisptr->decomp_offset >= size)
+ UINT32 size = m_rom_size - 0x100000;
+ while (m_decomp_offset >= size)
{
- thisptr->decomp_offset -= size;
+ m_decomp_offset -= size;
}
- return ROM[0x100000 + thisptr->decomp_offset++];
+ return ROM[0x100000 + m_decomp_offset++];
}
-static void SPC7110Decomp_mode0(SPC7110Decomp *thisptr, UINT8 init)
+void SPC7110Decomp::mode0(UINT8 init, UINT8 *ROM)
{
static UINT8 val, in, span;
static INT32 out, inverts, lps, in_count;
- if(init == 1)
+ if (init == 1)
{
out = inverts = lps = 0;
span = 0xff;
- val = SPC7110Decomp_dataread(thisptr);
- in = SPC7110Decomp_dataread(thisptr);
+ val = dataread(ROM);
+ in = dataread(ROM);
in_count = 8;
return;
}
- while(thisptr->decomp_buffer_length < (spc7110_decomp_buffer_size >> 1))
+ while (m_decomp_buffer_length < (SPC7110_DECOMP_BUFFER_SIZE >> 1))
{
- UINT32 bit;
- for(bit = 0; bit < 8; bit++)
+ for (int bit = 0; bit < 8; bit++)
{
//get context
UINT8 mask = (1 << (bit & 3)) - 1;
UINT8 con = mask + ((inverts & mask) ^ (lps & mask));
UINT32 prob, mps, flag_lps;
UINT32 shift = 0;
- if(bit > 3)
+ if (bit > 3)
{
con += 15;
}
//get prob and mps
- prob = SPC7110Decomp_probability(thisptr, con);
- mps = (((out >> 15) & 1) ^ thisptr->context[con].invert);
+ prob = probability(con);
+ mps = (((out >> 15) & 1) ^ m_context[con].invert);
//get bit
- if(val <= span - prob) //mps
+ if (val <= span - prob) //mps
{
span = span - prob;
out = (out << 1) + mps;
@@ -335,7 +332,7 @@ static void SPC7110Decomp_mode0(SPC7110Decomp *thisptr, UINT8 init)
}
//renormalize
- while(span < 0x7f)
+ while (span < 0x7f)
{
shift++;
@@ -343,144 +340,141 @@ static void SPC7110Decomp_mode0(SPC7110Decomp *thisptr, UINT8 init)
val = (val << 1) + (in >> 7);
in <<= 1;
- if(--in_count == 0)
+ if (--in_count == 0)
{
- in = SPC7110Decomp_dataread(thisptr);
+ in = dataread(ROM);
in_count = 8;
}
}
//update processing info
lps = (lps << 1) + flag_lps;
- inverts = (inverts << 1) + thisptr->context[con].invert;
+ inverts = (inverts << 1) + m_context[con].invert;
//update context state
- if(flag_lps & SPC7110Decomp_toggle_invert(thisptr, con))
+ if (flag_lps & toggle_invert(con))
{
- thisptr->context[con].invert ^= 1;
+ m_context[con].invert ^= 1;
}
- if(flag_lps)
+ if (flag_lps)
{
- thisptr->context[con].index = SPC7110Decomp_next_lps(thisptr, con);
+ m_context[con].index = next_lps(con);
}
- else if(shift)
+ else if (shift)
{
- thisptr->context[con].index = SPC7110Decomp_next_mps(thisptr, con);
+ m_context[con].index = next_mps(con);
}
}
//save byte
- SPC7110Decomp_write(thisptr, out);
+ write(out);
}
}
-static void SPC7110Decomp_mode1(SPC7110Decomp *thisptr, UINT8 init)
+void SPC7110Decomp::mode1(UINT8 init, UINT8 *ROM)
{
static INT32 pixelorder[4], realorder[4];
static UINT8 in, val, span;
static INT32 out, inverts, lps, in_count;
- if(init == 1)
+ if (init == 1)
{
- UINT32 i;
- for(i = 0; i < 4; i++)
+ for (int i = 0; i < 4; i++)
{
pixelorder[i] = i;
}
out = inverts = lps = 0;
span = 0xff;
- val = SPC7110Decomp_dataread(thisptr);
- in = SPC7110Decomp_dataread(thisptr);
+ val = dataread(ROM);
+ in = dataread(ROM);
in_count = 8;
return;
}
- while(thisptr->decomp_buffer_length < (spc7110_decomp_buffer_size >> 1))
+ while (m_decomp_buffer_length < (SPC7110_DECOMP_BUFFER_SIZE >> 1))
{
UINT16 data;
- UINT32 pixel;
- for(pixel = 0; pixel < 8; pixel++)
+ for (int pixel = 0; pixel < 8; pixel++)
{
//get first symbol context
UINT32 a = ((out >> (1 * 2)) & 3);
UINT32 b = ((out >> (7 * 2)) & 3);
UINT32 c = ((out >> (8 * 2)) & 3);
UINT32 con = (a == b) ? (b != c) : (b == c) ? 2 : 4 - (a == c);
- UINT32 bit;
//update pixel order
UINT32 m, n;
- for(m = 0; m < 4; m++)
+ for (m = 0; m < 4; m++)
{
- if(pixelorder[m] == a)
+ if (pixelorder[m] == a)
{
break;
}
}
- for(n = m; n > 0; n--)
+ for (n = m; n > 0; n--)
{
pixelorder[n] = pixelorder[n - 1];
}
pixelorder[0] = a;
//calculate the real pixel order
- for(m = 0; m < 4; m++)
+ for (m = 0; m < 4; m++)
{
realorder[m] = pixelorder[m];
}
//rotate reference pixel c value to top
- for(m = 0; m < 4; m++)
+ for (m = 0; m < 4; m++)
{
- if(realorder[m] == c)
+ if (realorder[m] == c)
{
break;
}
}
- for(n = m; n > 0; n--)
+ for (n = m; n > 0; n--)
{
realorder[n] = realorder[n - 1];
}
realorder[0] = c;
//rotate reference pixel b value to top
- for(m = 0; m < 4; m++)
+ for (m = 0; m < 4; m++)
{
- if(realorder[m] == b)
+ if (realorder[m] == b)
{
break;
}
}
- for(n = m; n > 0; n--)
+ for (n = m; n > 0; n--)
{
realorder[n] = realorder[n - 1];
}
realorder[0] = b;
//rotate reference pixel a value to top
- for(m = 0; m < 4; m++)
+ for (m = 0; m < 4; m++)
{
- if(realorder[m] == a)
+ if (realorder[m] == a)
{
break;
}
}
- for(n = m; n > 0; n--)
+ for (n = m; n > 0; n--)
{
realorder[n] = realorder[n - 1];
}
realorder[0] = a;
//get 2 symbols
- for(bit = 0; bit < 2; bit++)
+ for (int bit = 0; bit < 2; bit++)
{
//get prob
- UINT32 prob = SPC7110Decomp_probability(thisptr, con);
+ UINT32 prob = probability(con);
UINT32 shift = 0;
//get symbol
UINT32 flag_lps;
- if(val <= span - prob) //mps
+ if (val <= span - prob) //mps
{
span = span - prob;
flag_lps = 0;
@@ -493,7 +487,7 @@ static void SPC7110Decomp_mode1(SPC7110Decomp *thisptr, UINT8 init)
}
//renormalize
- while(span < 0x7f)
+ while (span < 0x7f)
{
shift++;
@@ -501,29 +495,29 @@ static void SPC7110Decomp_mode1(SPC7110Decomp *thisptr, UINT8 init)
val = (val << 1) + (in >> 7);
in <<= 1;
- if(--in_count == 0)
+ if (--in_count == 0)
{
- in = SPC7110Decomp_dataread(thisptr);
+ in = dataread(ROM);
in_count = 8;
}
}
//update processing info
lps = (lps << 1) + flag_lps;
- inverts = (inverts << 1) + thisptr->context[con].invert;
+ inverts = (inverts << 1) + m_context[con].invert;
//update context state
- if(flag_lps & SPC7110Decomp_toggle_invert(thisptr, con))
+ if (flag_lps & toggle_invert(con))
{
- thisptr->context[con].invert ^= 1;
+ m_context[con].invert ^= 1;
}
- if(flag_lps)
+ if (flag_lps)
{
- thisptr->context[con].index = SPC7110Decomp_next_lps(thisptr, con);
+ m_context[con].index = next_lps(con);
}
- else if(shift)
+ else if (shift)
{
- thisptr->context[con].index = SPC7110Decomp_next_mps(thisptr, con);
+ m_context[con].index = next_mps(con);
}
//get next context
@@ -536,40 +530,38 @@ static void SPC7110Decomp_mode1(SPC7110Decomp *thisptr, UINT8 init)
}
//turn pixel data into bitplanes
- data = SPC7110Decomp_morton_2x8(thisptr, out);
- SPC7110Decomp_write(thisptr, data >> 8);
- SPC7110Decomp_write(thisptr, data >> 0);
+ data = morton_2x8(out);
+ write(data >> 8);
+ write(data >> 0);
}
}
-static void SPC7110Decomp_mode2(SPC7110Decomp *thisptr, UINT8 init)
+void SPC7110Decomp::mode2(UINT8 init, UINT8 *ROM)
{
static INT32 pixelorder[16], realorder[16];
static UINT8 bitplanebuffer[16], buffer_index;
static UINT8 in, val, span;
static INT32 out0, out1, inverts, lps, in_count;
- if(init == 1)
+ if (init == 1)
{
- UINT32 i;
- for(i = 0; i < 16; i++)
+ for (int i = 0; i < 16; i++)
{
pixelorder[i] = i;
}
buffer_index = 0;
out0 = out1 = inverts = lps = 0;
span = 0xff;
- val = SPC7110Decomp_dataread(thisptr);
- in = SPC7110Decomp_dataread(thisptr);
+ val = dataread(ROM);
+ in = dataread(ROM);
in_count = 8;
return;
}
- while(thisptr->decomp_buffer_length < (spc7110_decomp_buffer_size >> 1))
+ while (m_decomp_buffer_length < (SPC7110_DECOMP_BUFFER_SIZE >> 1))
{
UINT32 data;
- UINT32 pixel;
- for(pixel = 0; pixel < 8; pixel++)
+ for (int pixel = 0; pixel < 8; pixel++)
{
//get first symbol context
UINT32 a = ((out0 >> (0 * 4)) & 15);
@@ -577,82 +569,81 @@ static void SPC7110Decomp_mode2(SPC7110Decomp *thisptr, UINT8 init)
UINT32 c = ((out1 >> (0 * 4)) & 15);
UINT32 con = 0;
UINT32 refcon = (a == b) ? (b != c) : (b == c) ? 2 : 4 - (a == c);
- UINT32 bit;
//update pixel order
UINT32 m, n;
- for(m = 0; m < 16; m++)
+ for (m = 0; m < 16; m++)
{
- if(pixelorder[m] == a)
+ if (pixelorder[m] == a)
{
break;
}
}
- for(n = m; n > 0; n--)
+ for (n = m; n > 0; n--)
{
pixelorder[n] = pixelorder[n - 1];
}
pixelorder[0] = a;
//calculate the real pixel order
- for(m = 0; m < 16; m++)
+ for (m = 0; m < 16; m++)
{
realorder[m] = pixelorder[m];
}
//rotate reference pixel c value to top
- for(m = 0; m < 16; m++)
+ for (m = 0; m < 16; m++)
{
- if(realorder[m] == c)
+ if (realorder[m] == c)
{
break;
}
}
- for(n = m; n > 0; n--)
+ for (n = m; n > 0; n--)
{
realorder[n] = realorder[n - 1];
}
realorder[0] = c;
//rotate reference pixel b value to top
- for(m = 0; m < 16; m++)
+ for (m = 0; m < 16; m++)
{
- if(realorder[m] == b)
+ if (realorder[m] == b)
{
break;
}
}
- for(n = m; n > 0; n--)
+ for (n = m; n > 0; n--)
{
realorder[n] = realorder[n - 1];
}
realorder[0] = b;
//rotate reference pixel a value to top
- for(m = 0; m < 16; m++)
+ for (m = 0; m < 16; m++)
{
- if(realorder[m] == a)
+ if (realorder[m] == a)
{
break;
}
}
- for(n = m; n > 0; n--)
+ for (n = m; n > 0; n--)
{
realorder[n] = realorder[n - 1];
}
realorder[0] = a;
//get 4 symbols
- for(bit = 0; bit < 4; bit++)
+ for (int bit = 0; bit < 4; bit++)
{
UINT32 invertbit, shift;
//get prob
- UINT32 prob = SPC7110Decomp_probability(thisptr, con);
+ UINT32 prob = probability(con);
//get symbol
UINT32 flag_lps;
- if(val <= span - prob) //mps
+ if (val <= span - prob) //mps
{
span = span - prob;
flag_lps = 0;
@@ -666,7 +657,7 @@ static void SPC7110Decomp_mode2(SPC7110Decomp *thisptr, UINT8 init)
//renormalize
shift = 0;
- while(span < 0x7f)
+ while (span < 0x7f)
{
shift++;
@@ -674,30 +665,30 @@ static void SPC7110Decomp_mode2(SPC7110Decomp *thisptr, UINT8 init)
val = (val << 1) + (in >> 7);
in <<= 1;
- if(--in_count == 0)
+ if (--in_count == 0)
{
- in = SPC7110Decomp_dataread(thisptr);
+ in = dataread(ROM);
in_count = 8;
}
}
//update processing info
lps = (lps << 1) + flag_lps;
- invertbit = thisptr->context[con].invert;
+ invertbit = m_context[con].invert;
inverts = (inverts << 1) + invertbit;
//update context state
- if(flag_lps & SPC7110Decomp_toggle_invert(thisptr, con))
+ if (flag_lps & toggle_invert(con))
{
- thisptr->context[con].invert ^= 1;
+ m_context[con].invert ^= 1;
}
- if(flag_lps)
+ if (flag_lps)
{
- thisptr->context[con].index = SPC7110Decomp_next_lps(thisptr, con);
+ m_context[con].index = next_lps(con);
}
- else if(shift)
+ else if (shift)
{
- thisptr->context[con].index = SPC7110Decomp_next_mps(thisptr, con);
+ m_context[con].index = next_mps(con);
}
//get next context
@@ -711,61 +702,60 @@ static void SPC7110Decomp_mode2(SPC7110Decomp *thisptr, UINT8 init)
}
//convert pixel data into bitplanes
- data = SPC7110Decomp_morton_4x8(thisptr, out0);
- SPC7110Decomp_write(thisptr, data >> 24);
- SPC7110Decomp_write(thisptr, data >> 16);
+ data = morton_4x8(out0);
+ write(data >> 24);
+ write(data >> 16);
bitplanebuffer[buffer_index++] = data >> 8;
bitplanebuffer[buffer_index++] = data >> 0;
- if(buffer_index == 16)
+ if (buffer_index == 16)
{
- UINT32 i;
- for(i = 0; i < 16; i++)
+ for (int i = 0; i < 16; i++)
{
- SPC7110Decomp_write(thisptr, bitplanebuffer[i]);
+ write(bitplanebuffer[i]);
}
buffer_index = 0;
}
}
}
-static UINT8 SPC7110Decomp_probability(SPC7110Decomp *thisptr, UINT32 n)
+UINT8 SPC7110Decomp::probability(UINT32 n)
{
- return spc7110_evolution_table[thisptr->context[n].index][0];
+ return spc7110_evolution_table[m_context[n].index][0];
}
-static UINT8 SPC7110Decomp_next_lps(SPC7110Decomp *thisptr, UINT32 n)
+UINT8 SPC7110Decomp::next_lps(UINT32 n)
{
- return spc7110_evolution_table[thisptr->context[n].index][1];
+ return spc7110_evolution_table[m_context[n].index][1];
}
-static UINT8 SPC7110Decomp_next_mps(SPC7110Decomp *thisptr, UINT32 n)
+UINT8 SPC7110Decomp::next_mps(UINT32 n)
{
- return spc7110_evolution_table[thisptr->context[n].index][2];
+ return spc7110_evolution_table[m_context[n].index][2];
}
-static UINT8 SPC7110Decomp_toggle_invert(SPC7110Decomp *thisptr, UINT32 n)
+UINT8 SPC7110Decomp::toggle_invert(UINT32 n)
{
- return spc7110_evolution_table[thisptr->context[n].index][3];
+ return spc7110_evolution_table[m_context[n].index][3];
}
-static UINT32 SPC7110Decomp_morton_2x8(SPC7110Decomp *thisptr, UINT32 data)
+UINT32 SPC7110Decomp::morton_2x8(UINT32 data)
{
//reverse morton lookup: de-interleave two 8-bit values
//15, 13, 11, 9, 7, 5, 3, 1 -> 15- 8
//14, 12, 10, 8, 6, 4, 2, 0 -> 7- 0
- return thisptr->morton16[0][(data >> 0) & 255] + thisptr->morton16[1][(data >> 8) & 255];
+ return m_morton16[0][(data >> 0) & 255] + m_morton16[1][(data >> 8) & 255];
}
-static UINT32 SPC7110Decomp_morton_4x8(SPC7110Decomp *thisptr, UINT32 data)
+UINT32 SPC7110Decomp::morton_4x8(UINT32 data)
{
//reverse morton lookup: de-interleave four 8-bit values
//31, 27, 23, 19, 15, 11, 7, 3 -> 31-24
//30, 26, 22, 18, 14, 10, 6, 2 -> 23-16
//29, 25, 21, 17, 13, 9, 5, 1 -> 15- 8
//28, 24, 20, 16, 12, 8, 4, 0 -> 7- 0
- return thisptr->morton32[0][(data >> 0) & 255] + thisptr->morton32[1][(data >> 8) & 255]
- + thisptr->morton32[2][(data >> 16) & 255] + thisptr->morton32[3][(data >> 24) & 255];
+ return m_morton32[0][(data >> 0) & 255] + m_morton32[1][(data >> 8) & 255]
+ + m_morton32[2][(data >> 16) & 255] + m_morton32[3][(data >> 24) & 255];
}
static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data);
@@ -934,7 +924,7 @@ static void spc7110_init(running_machine& machine)
snes_spc7110.size = state->m_cart_size;
- snes_spc7110.decomp = SPC7110Decomp_ctor(machine, snes_spc7110.size);
+ snes_spc7110.decomp = auto_alloc(machine, SPC7110Decomp(machine, snes_spc7110.size));
}
static void spc7110rtc_init(running_machine& machine)
@@ -953,7 +943,7 @@ static void spc7110rtc_init(running_machine& machine)
static UINT32 spc7110_datarom_addr(UINT32 addr)
{
UINT32 size = snes_spc7110.size - 0x100000;
- while(addr >= size)
+ while (addr >= size)
{
addr -= size;
}
@@ -1087,7 +1077,7 @@ static UINT8 spc7110_mmio_read(address_space &space, UINT32 addr)
counter--;
snes_spc7110.r4809 = counter;
snes_spc7110.r480a = counter >> 8;
- return SPC7110Decomp_read(snes_spc7110.decomp);
+ return snes_spc7110.decomp->read(ROM);
}
case 0x4801: return snes_spc7110.r4801;
case 0x4802: return snes_spc7110.r4802;
@@ -1116,32 +1106,32 @@ static UINT8 spc7110_mmio_read(address_space &space, UINT32 addr)
UINT8 data;
UINT32 address, adjust, adjustaddr;
- if(snes_spc7110.r481x != 0x07) return 0x00;
+ if (snes_spc7110.r481x != 0x07) return 0x00;
address = spc7110_data_pointer();
adjust = spc7110_data_adjust();
- if(snes_spc7110.r4818 & 8)
+ if (snes_spc7110.r4818 & 8)
{
adjust = (INT16)adjust; //16-bit sign extend
}
adjustaddr = address;
- if(snes_spc7110.r4818 & 2)
+ if (snes_spc7110.r4818 & 2)
{
adjustaddr += adjust;
spc7110_set_data_adjust(adjust + 1);
}
data = ROM[spc7110_datarom_addr(adjustaddr)];
- if(!(snes_spc7110.r4818 & 2))
+ if (!(snes_spc7110.r4818 & 2))
{
UINT32 increment = (snes_spc7110.r4818 & 1) ? spc7110_data_increment() : 1;
- if(snes_spc7110.r4818 & 4)
+ if (snes_spc7110.r4818 & 4)
{
increment = (INT16)increment; //16-bit sign extend
}
- if((snes_spc7110.r4818 & 16) == 0)
+ if ((snes_spc7110.r4818 & 16) == 0)
{
spc7110_set_data_pointer(address + increment);
}
@@ -1165,22 +1155,22 @@ static UINT8 spc7110_mmio_read(address_space &space, UINT32 addr)
{
UINT8 data;
UINT32 address, adjust;
- if(snes_spc7110.r481x != 0x07)
+ if (snes_spc7110.r481x != 0x07)
{
return 0x00;
}
address = spc7110_data_pointer();
adjust = spc7110_data_adjust();
- if(snes_spc7110.r4818 & 8)
+ if (snes_spc7110.r4818 & 8)
{
adjust = (INT16)adjust; //16-bit sign extend
}
data = ROM[spc7110_datarom_addr(address + adjust)];
- if((snes_spc7110.r4818 & 0x60) == 0x60)
+ if ((snes_spc7110.r4818 & 0x60) == 0x60)
{
- if((snes_spc7110.r4818 & 16) == 0)
+ if ((snes_spc7110.r4818 & 16) == 0)
{
spc7110_set_data_pointer(address + adjust);
}
@@ -1286,7 +1276,7 @@ static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data
+ (ROM[address + 2] << 8)
+ (ROM[address + 3] << 0);
- SPC7110Decomp_init(snes_spc7110.decomp, machine, mode, offset, (snes_spc7110.r4805 + (snes_spc7110.r4806 << 8)) << mode);
+ snes_spc7110.decomp->init(machine, ROM, mode, offset, (snes_spc7110.r4805 + (snes_spc7110.r4806 << 8)) << mode);
snes_spc7110.r480c = 0x80;
}
break;
@@ -1308,32 +1298,32 @@ static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data
{
snes_spc7110.r4814 = data;
snes_spc7110.r4814_latch = 1;
- if(!snes_spc7110.r4815_latch)
+ if (!snes_spc7110.r4815_latch)
{
break;
}
- if(!(snes_spc7110.r4818 & 2))
+ if (!(snes_spc7110.r4818 & 2))
{
break;
}
- if(snes_spc7110.r4818 & 0x10)
+ if (snes_spc7110.r4818 & 0x10)
{
break;
}
- if((snes_spc7110.r4818 & 0x60) == 0x20)
+ if ((snes_spc7110.r4818 & 0x60) == 0x20)
{
UINT32 increment = spc7110_data_adjust() & 0xff;
- if(snes_spc7110.r4818 & 8)
+ if (snes_spc7110.r4818 & 8)
{
increment = (INT8)increment; //8-bit sign extend
}
spc7110_set_data_pointer(spc7110_data_pointer() + increment);
}
- else if((snes_spc7110.r4818 & 0x60) == 0x40)
+ else if ((snes_spc7110.r4818 & 0x60) == 0x40)
{
UINT32 increment = spc7110_data_adjust();
- if(snes_spc7110.r4818 & 8)
+ if (snes_spc7110.r4818 & 8)
{
increment = (INT16)increment; //16-bit sign extend
}
@@ -1346,32 +1336,32 @@ static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data
{
snes_spc7110.r4815 = data;
snes_spc7110.r4815_latch = 1;
- if(!snes_spc7110.r4814_latch)
+ if (!snes_spc7110.r4814_latch)
{
break;
}
- if(!(snes_spc7110.r4818 & 2))
+ if (!(snes_spc7110.r4818 & 2))
{
break;
}
- if(snes_spc7110.r4818 & 0x10)
+ if (snes_spc7110.r4818 & 0x10)
{
break;
}
- if((snes_spc7110.r4818 & 0x60) == 0x20)
+ if ((snes_spc7110.r4818 & 0x60) == 0x20)
{
UINT32 increment = spc7110_data_adjust() & 0xff;
- if(snes_spc7110.r4818 & 8)
+ if (snes_spc7110.r4818 & 8)
{
increment = (INT8)increment; //8-bit sign extend
}
spc7110_set_data_pointer(spc7110_data_pointer() + increment);
}
- else if((snes_spc7110.r4818 & 0x60) == 0x40)
+ else if ((snes_spc7110.r4818 & 0x60) == 0x40)
{
UINT32 increment = spc7110_data_adjust();
- if(snes_spc7110.r4818 & 8)
+ if (snes_spc7110.r4818 & 8)
{
increment = (INT16)increment; //16-bit sign extend
}
@@ -1384,7 +1374,7 @@ static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data
case 0x4817: snes_spc7110.r4817 = data; break;
case 0x4818:
{
- if(snes_spc7110.r481x != 0x07)
+ if (snes_spc7110.r481x != 0x07)
break;
snes_spc7110.r4818 = data;
@@ -1405,7 +1395,7 @@ static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data
{
snes_spc7110.r4825 = data;
- if(snes_spc7110.r482e & 1)
+ if (snes_spc7110.r482e & 1)
{
//signed 16-bit x 16-bit multiplication
INT16 r0 = (INT16)(snes_spc7110.r4824 + (snes_spc7110.r4825 << 8));
@@ -1439,7 +1429,7 @@ static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data
{
snes_spc7110.r4827 = data;
- if(snes_spc7110.r482e & 1)
+ if (snes_spc7110.r482e & 1)
{
//signed 32-bit x 16-bit division
INT32 dividend = (INT32)(snes_spc7110.r4820 + (snes_spc7110.r4821 << 8) + (snes_spc7110.r4822 << 16) + (snes_spc7110.r4823 << 24));
@@ -1448,7 +1438,7 @@ static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data
INT32 quotient;
INT16 remainder;
- if(divisor)
+ if (divisor)
{
quotient = (INT32)(dividend / divisor);
remainder = (INT32)(dividend % divisor);
@@ -1477,7 +1467,7 @@ static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data
UINT32 quotient;
UINT16 remainder;
- if(divisor)
+ if (divisor)
{
quotient = (UINT32)(dividend / divisor);
remainder = (UINT16)(dividend % divisor);
@@ -1628,7 +1618,7 @@ static void spc7110_mmio_write(running_machine &machine, UINT32 addr, UINT8 data
}
//disable timer
- if((data & 2) && !(snes_spc7110.rtc_ram[15] & 2))
+ if ((data & 2) && !(snes_spc7110.rtc_ram[15] & 2))
spc7110_update_time(machine, 0);
}
diff --git a/src/mame/machine/snessdd1.c b/src/mame/machine/snessdd1.c
index 86245cc109d..96eaceb926e 100644
--- a/src/mame/machine/snessdd1.c
+++ b/src/mame/machine/snessdd1.c
@@ -8,47 +8,43 @@
***************************************************************************/
-static UINT8 sdd1_read(running_machine& machine, UINT32 addr);
+
+#define SSD1_ADD(addr)\
+mmc[(addr >> 20) & 3] + (addr & 0x0fffff)
class SDD1_IM //Input Manager
{
public:
- SDD1_IM(running_machine &machine)
- : m_machine(machine) { }
-
- running_machine &machine() const { return m_machine; }
- UINT32 byte_ptr;
- UINT8 bit_count;
+ UINT32 m_byte_ptr;
+ UINT8 m_bit_count;
-private:
- running_machine& m_machine;
+ void IM_prepareDecomp(UINT32 in_buf);
+ UINT8 IM_getCodeword(UINT8 *ROM, UINT32 *mmc, const UINT8 code_len);
};
-static void SDD1_IM_prepareDecomp(SDD1_IM* thisptr, UINT32 in_buf)
+void SDD1_IM::IM_prepareDecomp(UINT32 in_buf)
{
- thisptr->byte_ptr = in_buf;
- thisptr->bit_count = 4;
+ m_byte_ptr = in_buf;
+ m_bit_count = 4;
}
-static UINT8 SDD1_IM_getCodeword(SDD1_IM* thisptr, const UINT8 code_len)
+UINT8 SDD1_IM::IM_getCodeword(UINT8 *ROM, UINT32 *mmc, const UINT8 code_len)
{
- UINT8 codeword;
+ UINT8 codeword = ROM[SSD1_ADD(m_byte_ptr)] << m_bit_count;
- codeword = sdd1_read(thisptr->machine(), thisptr->byte_ptr) << thisptr->bit_count;
-
- ++thisptr->bit_count;
+ ++m_bit_count;
if (codeword & 0x80)
{
- codeword |= sdd1_read(thisptr->machine(), thisptr->byte_ptr + 1) >> (9 - thisptr->bit_count);
- thisptr->bit_count += code_len;
+ codeword |= ROM[SSD1_ADD(m_byte_ptr + 1)] >> (9 - m_bit_count);
+ m_bit_count += code_len;
}
- if (thisptr->bit_count & 0x08)
+ if (m_bit_count & 0x08)
{
- thisptr->byte_ptr++;
- thisptr->bit_count &= 0x07;
+ m_byte_ptr++;
+ m_bit_count &= 0x07;
}
return codeword;
@@ -57,19 +53,15 @@ static UINT8 SDD1_IM_getCodeword(SDD1_IM* thisptr, const UINT8 code_len)
class SDD1_GCD //Golomb-Code Decoder
{
public:
- SDD1_GCD(running_machine &machine, SDD1_IM* associatedIM)
- : IM(associatedIM),
- m_machine(machine) { }
-
- running_machine &machine() const { return m_machine; }
+ SDD1_GCD(SDD1_IM* associatedIM)
+ : m_IM(associatedIM) { }
- SDD1_IM* IM;
+ SDD1_IM* m_IM;
-private:
- running_machine& m_machine;
+ void GCD_getRunCount(UINT8 *ROM, UINT32 *mmc, UINT8 code_num, UINT8* MPScount, UINT8* LPSind);
};
-static void SDD1_GCD_getRunCount(SDD1_GCD* thisptr, UINT8 code_num, UINT8* MPScount, UINT8* LPSind)
+void SDD1_GCD::GCD_getRunCount(UINT8 *ROM, UINT32 *mmc, UINT8 code_num, UINT8* MPScount, UINT8* LPSind)
{
const UINT8 run_count[] =
{
@@ -107,7 +99,7 @@ static void SDD1_GCD_getRunCount(SDD1_GCD* thisptr, UINT8 code_num, UINT8* MPSco
0x70, 0x30, 0x50, 0x10, 0x60, 0x20, 0x40, 0x00,
};
- UINT8 codeword = SDD1_IM_getCodeword(thisptr->IM, code_num);
+ UINT8 codeword = m_IM->IM_getCodeword(ROM, mmc, code_num);
if (codeword & 0x80)
{
@@ -123,49 +115,46 @@ static void SDD1_GCD_getRunCount(SDD1_GCD* thisptr, UINT8 code_num, UINT8* MPSco
class SDD1_BG // Bits Generator
{
public:
- SDD1_BG(running_machine &machine, SDD1_GCD* associatedGCD, UINT8 code)
- : code_num(code),
- GCD(associatedGCD),
- m_machine(machine) { }
+ SDD1_BG(SDD1_GCD* associatedGCD, UINT8 code)
+ : m_code_num(code),
+ m_GCD(associatedGCD) { }
- running_machine &machine() const { return m_machine; }
-
- UINT8 code_num;
- UINT8 MPScount;
- UINT8 LPSind;
- SDD1_GCD* GCD;
+ UINT8 m_code_num;
+ UINT8 m_MPScount;
+ UINT8 m_LPSind;
+ SDD1_GCD* m_GCD;
-public:
- running_machine& m_machine;
+ void BG_prepareDecomp();
+ UINT8 BG_getBit(UINT8 *ROM, UINT32 *mmc, UINT8* endOfRun);
} ;
-static void SDD1_BG_prepareDecomp(SDD1_BG* thisptr)
+void SDD1_BG::BG_prepareDecomp()
{
- thisptr->MPScount = 0;
- thisptr->LPSind = 0;
+ m_MPScount = 0;
+ m_LPSind = 0;
}
-static UINT8 SDD1_BG_getBit(SDD1_BG* thisptr, UINT8* endOfRun)
+UINT8 SDD1_BG::BG_getBit(UINT8 *ROM, UINT32 *mmc, UINT8* endOfRun)
{
UINT8 bit;
- if (!(thisptr->MPScount || thisptr->LPSind))
+ if (!(m_MPScount || m_LPSind))
{
- SDD1_GCD_getRunCount(thisptr->GCD, thisptr->code_num, &(thisptr->MPScount), &(thisptr->LPSind));
+ m_GCD->GCD_getRunCount(ROM, mmc, m_code_num, &(m_MPScount), &(m_LPSind));
}
- if (thisptr->MPScount)
+ if (m_MPScount)
{
bit = 0;
- thisptr->MPScount--;
+ m_MPScount--;
}
else
{
bit = 1;
- thisptr->LPSind = 0;
+ m_LPSind = 0;
}
- if (thisptr->MPScount || thisptr->LPSind)
+ if (m_MPScount || m_LPSind)
{
(*endOfRun) = 0;
}
@@ -185,7 +174,7 @@ struct SDD1_PEM_state
UINT8 nextIfLPS;
};
-static const SDD1_PEM_state SDD1_PEM_evolution_table[33] =
+static const SDD1_PEM_state PEM_evolution_table[33] =
{
{ 0,25,25},
{ 0, 2, 1},
@@ -231,53 +220,49 @@ struct SDD1_PEM_ContextInfo
class SDD1_PEM //Probability Estimation Module
{
public:
- SDD1_PEM(running_machine& machine,
- SDD1_BG* associatedBG0, SDD1_BG* associatedBG1,
- SDD1_BG* associatedBG2, SDD1_BG* associatedBG3,
- SDD1_BG* associatedBG4, SDD1_BG* associatedBG5,
- SDD1_BG* associatedBG6, SDD1_BG* associatedBG7)
- : m_machine(machine)
+ SDD1_PEM(
+ SDD1_BG* associatedBG0, SDD1_BG* associatedBG1,
+ SDD1_BG* associatedBG2, SDD1_BG* associatedBG3,
+ SDD1_BG* associatedBG4, SDD1_BG* associatedBG5,
+ SDD1_BG* associatedBG6, SDD1_BG* associatedBG7)
{
- BG[0] = associatedBG0;
- BG[1] = associatedBG1;
- BG[2] = associatedBG2;
- BG[3] = associatedBG3;
- BG[4] = associatedBG4;
- BG[5] = associatedBG5;
- BG[6] = associatedBG6;
- BG[7] = associatedBG7;
+ m_BG[0] = associatedBG0;
+ m_BG[1] = associatedBG1;
+ m_BG[2] = associatedBG2;
+ m_BG[3] = associatedBG3;
+ m_BG[4] = associatedBG4;
+ m_BG[5] = associatedBG5;
+ m_BG[6] = associatedBG6;
+ m_BG[7] = associatedBG7;
}
- running_machine &machine() const { return m_machine; }
-
- SDD1_PEM_ContextInfo contextInfo[32];
- SDD1_BG* BG[8];
+ SDD1_PEM_ContextInfo m_contextInfo[32];
+ SDD1_BG* m_BG[8];
-private:
- running_machine& m_machine;
+ void PEM_prepareDecomp();
+ UINT8 PEM_getBit(UINT8 *ROM, UINT32 *mmc, UINT8 context);
} ;
-static void SDD1_PEM_prepareDecomp(SDD1_PEM* thisptr)
+void SDD1_PEM::PEM_prepareDecomp()
{
- UINT8 i;
- for(i = 0; i < 32; i++)
+ for (int i = 0; i < 32; i++)
{
- thisptr->contextInfo[i].status = 0;
- thisptr->contextInfo[i].MPS = 0;
+ m_contextInfo[i].status = 0;
+ m_contextInfo[i].MPS = 0;
}
}
-static UINT8 SDD1_PEM_getBit(SDD1_PEM* thisptr, UINT8 context)
+UINT8 SDD1_PEM::PEM_getBit(UINT8 *ROM, UINT32 *mmc, UINT8 context)
{
UINT8 endOfRun;
UINT8 bit;
- SDD1_PEM_ContextInfo *pContInfo = &(thisptr->contextInfo)[context];
+ SDD1_PEM_ContextInfo *pContInfo = &(m_contextInfo)[context];
UINT8 currStatus = pContInfo->status;
- const SDD1_PEM_state* pState = &(SDD1_PEM_evolution_table[currStatus]);
+ const SDD1_PEM_state* pState = &(PEM_evolution_table[currStatus]);
UINT8 currentMPS = pContInfo->MPS;
- bit = SDD1_BG_getBit(thisptr->BG[pState->code_num], &endOfRun);
+ bit = m_BG[pState->code_num]->BG_getBit(ROM, mmc, &endOfRun);
if (endOfRun)
{
@@ -301,81 +286,74 @@ static UINT8 SDD1_PEM_getBit(SDD1_PEM* thisptr, UINT8 context)
class SDD1_CM
{
public:
- SDD1_CM(running_machine& machine, SDD1_PEM* associatedPEM)
- : PEM(associatedPEM),
- m_machine(machine) { }
-
- running_machine &machine() const { return m_machine; }
-
- UINT8 bitplanesInfo;
- UINT8 contextBitsInfo;
- UINT8 bit_number;
- UINT8 currBitplane;
- UINT16 prevBitplaneBits[8];
- SDD1_PEM* PEM;
-
-private:
- running_machine& m_machine;
+ SDD1_CM(SDD1_PEM* associatedPEM)
+ : m_PEM(associatedPEM) { }
+
+ UINT8 m_bitplanesInfo;
+ UINT8 m_contextBitsInfo;
+ UINT8 m_bit_number;
+ UINT8 m_currBitplane;
+ UINT16 m_prevBitplaneBits[8];
+ SDD1_PEM* m_PEM;
+
+ void CM_prepareDecomp(UINT8 *ROM, UINT32 *mmc, UINT32 first_byte);
+ UINT8 CM_getBit(UINT8 *ROM, UINT32 *mmc);
} ;
-static void SDD1_CM_prepareDecomp(SDD1_CM* thisptr, UINT32 first_byte)
+void SDD1_CM::CM_prepareDecomp(UINT8 *ROM, UINT32 *mmc, UINT32 first_byte)
{
INT32 i = 0;
- thisptr->bitplanesInfo = sdd1_read(thisptr->machine(), first_byte) & 0xc0;
- thisptr->contextBitsInfo = sdd1_read(thisptr->machine(), first_byte) & 0x30;
- thisptr->bit_number = 0;
+ m_bitplanesInfo = ROM[SSD1_ADD(first_byte)] & 0xc0;
+ m_contextBitsInfo = ROM[SSD1_ADD(first_byte)] & 0x30;
+ m_bit_number = 0;
for (i = 0; i < 8; i++)
{
- thisptr->prevBitplaneBits[i] = 0;
+ m_prevBitplaneBits[i] = 0;
}
- switch(thisptr->bitplanesInfo)
+ switch (m_bitplanesInfo)
{
case 0x00:
- thisptr->currBitplane = 1;
+ m_currBitplane = 1;
break;
case 0x40:
- thisptr->currBitplane = 7;
+ m_currBitplane = 7;
break;
case 0x80:
- thisptr->currBitplane = 3;
+ m_currBitplane = 3;
break;
}
}
-static UINT8 SDD1_CM_getBit(SDD1_CM* thisptr)
+UINT8 SDD1_CM::CM_getBit(UINT8 *ROM, UINT32 *mmc)
{
UINT8 currContext;
UINT16 *context_bits;
UINT8 bit = 0;
- switch (thisptr->bitplanesInfo)
+ switch (m_bitplanesInfo)
{
case 0x00:
- thisptr->currBitplane ^= 0x01;
+ m_currBitplane ^= 0x01;
break;
case 0x40:
- thisptr->currBitplane ^= 0x01;
- if (!(thisptr->bit_number & 0x7f))
- {
- thisptr->currBitplane = ((thisptr->currBitplane + 2) & 0x07);
- }
+ m_currBitplane ^= 0x01;
+ if (!(m_bit_number & 0x7f))
+ m_currBitplane = ((m_currBitplane + 2) & 0x07);
break;
case 0x80:
- thisptr->currBitplane ^= 0x01;
- if (!(thisptr->bit_number & 0x7f))
- {
- thisptr->currBitplane ^= 0x02;
- }
+ m_currBitplane ^= 0x01;
+ if (!(m_bit_number & 0x7f))
+ m_currBitplane ^= 0x02;
break;
case 0xc0:
- thisptr->currBitplane = thisptr->bit_number & 0x07;
+ m_currBitplane = m_bit_number & 0x07;
break;
}
- context_bits = &(thisptr->prevBitplaneBits)[thisptr->currBitplane];
+ context_bits = &(m_prevBitplaneBits)[m_currBitplane];
- currContext = (thisptr->currBitplane & 0x01) << 4;
- switch (thisptr->contextBitsInfo)
+ currContext = (m_currBitplane & 0x01) << 4;
+ switch (m_contextBitsInfo)
{
case 0x00:
currContext |= ((*context_bits & 0x01c0) >> 5) | (*context_bits & 0x0001);
@@ -391,12 +369,12 @@ static UINT8 SDD1_CM_getBit(SDD1_CM* thisptr)
break;
}
- bit = SDD1_PEM_getBit(thisptr->PEM, currContext);
+ bit = m_PEM->PEM_getBit(ROM, mmc, currContext);
*context_bits <<= 1;
*context_bits |= bit;
- thisptr->bit_number++;
+ m_bit_number++;
return bit;
}
@@ -404,34 +382,31 @@ static UINT8 SDD1_CM_getBit(SDD1_CM* thisptr)
class SDD1_OL
{
public:
- SDD1_OL(running_machine& machine, SDD1_CM* associatedCM)
- : CM(associatedCM),
- m_machine(machine) { }
-
- running_machine &machine() const { return m_machine; }
+ SDD1_OL(SDD1_CM* associatedCM)
+ : m_CM(associatedCM) { }
- UINT8 bitplanesInfo;
- UINT16 length;
- UINT8* buffer;
- SDD1_CM* CM;
+ UINT8 m_bitplanesInfo;
+ UINT16 m_length;
+ UINT8* m_buffer;
+ SDD1_CM* m_CM;
-private:
- running_machine& m_machine;
+ void OL_prepareDecomp(UINT8 *ROM, UINT32 *mmc, UINT32 first_byte, UINT16 out_len, UINT8 *out_buf);
+ void OL_launch(UINT8 *ROM, UINT32 *mmc);
} ;
-static void SDD1_OL_prepareDecomp(SDD1_OL* thisptr, UINT32 first_byte, UINT16 out_len, UINT8 *out_buf)
+void SDD1_OL::OL_prepareDecomp(UINT8 *ROM, UINT32 *mmc, UINT32 first_byte, UINT16 out_len, UINT8 *out_buf)
{
- thisptr->bitplanesInfo = sdd1_read(thisptr->machine(), first_byte) & 0xc0;
- thisptr->length = out_len;
- thisptr->buffer = out_buf;
+ m_bitplanesInfo = ROM[SSD1_ADD(first_byte)] & 0xc0;
+ m_length = out_len;
+ m_buffer = out_buf;
}
-static void SDD1_OL_launch(SDD1_OL* thisptr)
+void SDD1_OL::OL_launch(UINT8 *ROM, UINT32 *mmc)
{
UINT8 i;
UINT8 register1 = 0, register2 = 0;
- switch(thisptr->bitplanesInfo)
+ switch (m_bitplanesInfo)
{
case 0x00:
case 0x40:
@@ -439,40 +414,37 @@ static void SDD1_OL_launch(SDD1_OL* thisptr)
i = 1;
do
{ // if length == 0, we output 2^16 bytes
- if(!i)
+ if (!i)
{
- *(thisptr->buffer++) = register2;
+ *(m_buffer++) = register2;
i = ~i;
}
else
{
- for(register1 = register2 = 0, i = 0x80; i; i >>= 1)
+ for (register1 = register2 = 0, i = 0x80; i; i >>= 1)
{
- if(SDD1_CM_getBit(thisptr->CM))
- {
+ if (m_CM->CM_getBit(ROM, mmc))
register1 |= i;
- }
- if(SDD1_CM_getBit(thisptr->CM))
- {
+
+ if (m_CM->CM_getBit(ROM, mmc))
register2 |= i;
- }
}
- *(thisptr->buffer++) = register1;
+ *(m_buffer++) = register1;
}
- } while(--(thisptr->length));
+ } while (--(m_length));
break;
case 0xc0:
do
{
- for(register1 = 0, i = 0x01; i; i <<= 1)
+ for (register1 = 0, i = 0x01; i; i <<= 1)
{
- if(SDD1_CM_getBit(thisptr->CM))
+ if (m_CM->CM_getBit(ROM, mmc))
{
register1 |= i;
}
}
- *(thisptr->buffer++) = register1;
- } while(--(thisptr->length));
+ *(m_buffer++) = register1;
+ } while (--(m_length));
break;
}
}
@@ -484,13 +456,15 @@ public:
running_machine &machine() const { return m_machine; }
- SDD1_IM* IM;
- SDD1_GCD* GCD;
- SDD1_BG* BG0; SDD1_BG* BG1; SDD1_BG* BG2; SDD1_BG* BG3;
- SDD1_BG* BG4; SDD1_BG* BG5; SDD1_BG* BG6; SDD1_BG* BG7;
- SDD1_PEM* PEM;
- SDD1_CM* CM;
- SDD1_OL* OL;
+ SDD1_IM* m_IM;
+ SDD1_GCD* m_GCD;
+ SDD1_BG* m_BG0; SDD1_BG* m_BG1; SDD1_BG* m_BG2; SDD1_BG* m_BG3;
+ SDD1_BG* m_BG4; SDD1_BG* m_BG5; SDD1_BG* m_BG6; SDD1_BG* m_BG7;
+ SDD1_PEM* m_PEM;
+ SDD1_CM* m_CM;
+ SDD1_OL* m_OL;
+
+ void SDD1emu_decompress(UINT8 *ROM, UINT32 *mmc, UINT32 in_buf, UINT16 out_len, UINT8 *out_buf);
private:
running_machine& m_machine;
@@ -499,38 +473,38 @@ private:
SDD1emu::SDD1emu(running_machine &machine)
: m_machine(machine)
{
- IM = auto_alloc(machine, SDD1_IM(machine));
- GCD = auto_alloc(machine, SDD1_GCD(machine, IM));
- BG0 = auto_alloc(machine, SDD1_BG(machine, GCD, 0));
- BG1 = auto_alloc(machine, SDD1_BG(machine, GCD, 1));
- BG2 = auto_alloc(machine, SDD1_BG(machine, GCD, 2));
- BG3 = auto_alloc(machine, SDD1_BG(machine, GCD, 3));
- BG4 = auto_alloc(machine, SDD1_BG(machine, GCD, 4));
- BG5 = auto_alloc(machine, SDD1_BG(machine, GCD, 5));
- BG6 = auto_alloc(machine, SDD1_BG(machine, GCD, 6));
- BG7 = auto_alloc(machine, SDD1_BG(machine, GCD, 7));
- PEM = auto_alloc(machine, SDD1_PEM(machine, BG0, BG1, BG2, BG3,
- BG4, BG5, BG6, BG7));
- CM = auto_alloc(machine, SDD1_CM(machine, PEM));
- OL = auto_alloc(machine, SDD1_OL(machine, CM));
+ m_IM = auto_alloc(machine, SDD1_IM());
+ m_GCD = auto_alloc(machine, SDD1_GCD(m_IM));
+ m_BG0 = auto_alloc(machine, SDD1_BG(m_GCD, 0));
+ m_BG1 = auto_alloc(machine, SDD1_BG(m_GCD, 1));
+ m_BG2 = auto_alloc(machine, SDD1_BG(m_GCD, 2));
+ m_BG3 = auto_alloc(machine, SDD1_BG(m_GCD, 3));
+ m_BG4 = auto_alloc(machine, SDD1_BG(m_GCD, 4));
+ m_BG5 = auto_alloc(machine, SDD1_BG(m_GCD, 5));
+ m_BG6 = auto_alloc(machine, SDD1_BG(m_GCD, 6));
+ m_BG7 = auto_alloc(machine, SDD1_BG(m_GCD, 7));
+ m_PEM = auto_alloc(machine, SDD1_PEM(m_BG0, m_BG1, m_BG2, m_BG3,
+ m_BG4, m_BG5, m_BG6, m_BG7));
+ m_CM = auto_alloc(machine, SDD1_CM(m_PEM));
+ m_OL = auto_alloc(machine, SDD1_OL(m_CM));
}
-static void SDD1emu_decompress(SDD1emu* thisptr, UINT32 in_buf, UINT16 out_len, UINT8 *out_buf)
+void SDD1emu::SDD1emu_decompress(UINT8 *ROM, UINT32 *mmc, UINT32 in_buf, UINT16 out_len, UINT8 *out_buf)
{
- SDD1_IM_prepareDecomp(thisptr->IM, in_buf);
- SDD1_BG_prepareDecomp(thisptr->BG0);
- SDD1_BG_prepareDecomp(thisptr->BG1);
- SDD1_BG_prepareDecomp(thisptr->BG2);
- SDD1_BG_prepareDecomp(thisptr->BG3);
- SDD1_BG_prepareDecomp(thisptr->BG4);
- SDD1_BG_prepareDecomp(thisptr->BG5);
- SDD1_BG_prepareDecomp(thisptr->BG6);
- SDD1_BG_prepareDecomp(thisptr->BG7);
- SDD1_PEM_prepareDecomp(thisptr->PEM);
- SDD1_CM_prepareDecomp(thisptr->CM, in_buf);
- SDD1_OL_prepareDecomp(thisptr->OL, in_buf, out_len, out_buf);
-
- SDD1_OL_launch(thisptr->OL);
+ m_IM->IM_prepareDecomp(in_buf);
+ m_BG0->BG_prepareDecomp();
+ m_BG1->BG_prepareDecomp();
+ m_BG2->BG_prepareDecomp();
+ m_BG3->BG_prepareDecomp();
+ m_BG4->BG_prepareDecomp();
+ m_BG5->BG_prepareDecomp();
+ m_BG6->BG_prepareDecomp();
+ m_BG7->BG_prepareDecomp();
+ m_PEM->PEM_prepareDecomp();
+ m_CM->CM_prepareDecomp(ROM, mmc, in_buf);
+ m_OL->OL_prepareDecomp(ROM, mmc, in_buf, out_len, out_buf);
+
+ m_OL->OL_launch(ROM, mmc);
}
struct snes_sdd1_t
@@ -559,8 +533,6 @@ static snes_sdd1_t snes_sdd1;
static void sdd1_init(running_machine& machine)
{
- UINT8 i;
-
snes_sdd1.sdd1_enable = 0x00;
snes_sdd1.xfer_enable = 0x00;
@@ -569,7 +541,7 @@ static void sdd1_init(running_machine& machine)
snes_sdd1.mmc[2] = 2 << 20;
snes_sdd1.mmc[3] = 3 << 20;
- for(i = 0; i < 8; i++)
+ for (int i = 0; i < 8; i++)
{
snes_sdd1.dma[i].addr = 0;
snes_sdd1.dma[i].size = 0;
@@ -585,7 +557,7 @@ static UINT8 sdd1_mmio_read(address_space &space, UINT32 addr)
{
addr &= 0xffff;
- if((addr & 0x4380) == 0x4300)
+ if ((addr & 0x4380) == 0x4300)
{
return snes_r_io(space, addr & 0x7f);
}
@@ -609,7 +581,7 @@ static void sdd1_mmio_write(address_space &space, UINT32 addr, UINT8 data)
{
addr &= 0xffff;
- if((addr & 0x4380) == 0x4300)
+ if ((addr & 0x4380) == 0x4300)
{
UINT8 channel = (addr >> 4) & 7;
switch(addr & 15)
@@ -664,19 +636,18 @@ static UINT8 sdd1_read(running_machine& machine, UINT32 addr)
{
unsigned char *ROM = machine.root_device().memregion("cart")->base();
- if(snes_sdd1.sdd1_enable & snes_sdd1.xfer_enable)
+ if (snes_sdd1.sdd1_enable & snes_sdd1.xfer_enable)
{
// at least one channel has S-DD1 decompression enabled...
- UINT32 i;
- for(i = 0; i < 8; i++)
+ for (int i = 0; i < 8; i++)
{
- if(snes_sdd1.sdd1_enable & snes_sdd1.xfer_enable & (1 << i))
+ if (snes_sdd1.sdd1_enable & snes_sdd1.xfer_enable & (1 << i))
{
// S-DD1 always uses fixed transfer mode, so address will not change during transfer
- if((addr + 0xc00000) == snes_sdd1.dma[i].addr)
+ if ((addr + 0xc00000) == snes_sdd1.dma[i].addr)
{
UINT8 data;
- if(!snes_sdd1.buffer.ready)
+ if (!snes_sdd1.buffer.ready)
{
UINT8 temp;
// first byte read for channel performs full decompression.
@@ -688,7 +659,7 @@ static UINT8 sdd1_read(running_machine& machine, UINT32 addr)
// so temporarily disable decompression mode for decompress() call.
temp = snes_sdd1.sdd1_enable;
snes_sdd1.sdd1_enable = 0;
- SDD1emu_decompress(snes_sdd1.sdd1emu, addr, snes_sdd1.buffer.size, snes_sdd1.buffer.data);
+ snes_sdd1.sdd1emu->SDD1emu_decompress(ROM, snes_sdd1.mmc, addr, snes_sdd1.buffer.size, snes_sdd1.buffer.data);
snes_sdd1.sdd1_enable = temp;
snes_sdd1.buffer.ready = 1;
@@ -696,7 +667,7 @@ static UINT8 sdd1_read(running_machine& machine, UINT32 addr)
// fetch a decompressed byte; once buffer is depleted, disable channel and invalidate buffer
data = snes_sdd1.buffer.data[(UINT16)snes_sdd1.buffer.offset++];
- if(snes_sdd1.buffer.offset >= snes_sdd1.buffer.size)
+ if (snes_sdd1.buffer.offset >= snes_sdd1.buffer.size)
{
snes_sdd1.buffer.ready = 0;
snes_sdd1.xfer_enable &= ~(1 << i);