summaryrefslogtreecommitdiff
path: root/plugins/adplug/adplug/u6m.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/adplug/adplug/u6m.cpp')
-rw-r--r--plugins/adplug/adplug/u6m.cpp50
1 files changed, 28 insertions, 22 deletions
diff --git a/plugins/adplug/adplug/u6m.cpp b/plugins/adplug/adplug/u6m.cpp
index d34f6fc2..565d0820 100644
--- a/plugins/adplug/adplug/u6m.cpp
+++ b/plugins/adplug/adplug/u6m.cpp
@@ -34,7 +34,7 @@ CPlayer *Cu6mPlayer::factory(Copl *newopl)
return new Cu6mPlayer(newopl);
}
-bool Cu6mPlayer::load(const std::string &filename, const CFileProvider &fp)
+bool Cu6mPlayer::load(const char *filename, const CFileProvider &fp)
{
// file validation section
// this section only checks a few *necessary* conditions
@@ -178,8 +178,7 @@ void Cu6mPlayer::rewind(int subsong)
carrier_mf_mod_delay[i] = 0;
}
- while (!subsong_stack.empty()) // empty subsong stack
- subsong_stack.pop();
+ subsong_stack_sz = 0;
opl->init();
out_adlib(1,32); // go to OPL2 mode
@@ -201,6 +200,8 @@ float Cu6mPlayer::getrefresh()
// ============================================================================================
+#define ROOT_STACK_SIZE 200
+
// decompress from memory to memory
bool Cu6mPlayer::lzw_decompress(Cu6mPlayer::data_block source, Cu6mPlayer::data_block dest)
{
@@ -210,7 +211,11 @@ bool Cu6mPlayer::lzw_decompress(Cu6mPlayer::data_block source, Cu6mPlayer::data_
int next_free_codeword = 0x102;
int dictionary_size = 0x200;
MyDict dictionary = MyDict();
- std::stack<unsigned char> root_stack;
+
+ unsigned char root_stack[ROOT_STACK_SIZE];
+ int root_stack_size = 0;
+
+// std::stack<unsigned char> root_stack;
long bytes_written = 0;
@@ -241,13 +246,13 @@ bool Cu6mPlayer::lzw_decompress(Cu6mPlayer::data_block source, Cu6mPlayer::data_
if (cW < next_free_codeword) // codeword is already in the dictionary
{
// create the string associated with cW (on the stack)
- get_string(cW,dictionary,root_stack);
- C = root_stack.top();
+ get_string(cW,dictionary,root_stack,root_stack_size);
+ C = root_stack[root_stack_size-1];
// output the string represented by cW
- while (!root_stack.empty())
+ while (root_stack_size>0)
{
- SAVE_OUTPUT_ROOT(root_stack.top(), dest, bytes_written);
- root_stack.pop();
+ SAVE_OUTPUT_ROOT(root_stack[root_stack_size-1], dest, bytes_written);
+ root_stack_size--;
}
// add pW+C to the dictionary
dictionary.add(C,pW);
@@ -265,13 +270,13 @@ bool Cu6mPlayer::lzw_decompress(Cu6mPlayer::data_block source, Cu6mPlayer::data_
else // codeword is not yet defined
{
// create the string associated with pW (on the stack)
- get_string(pW,dictionary,root_stack);
- C = root_stack.top();
+ get_string(pW,dictionary,root_stack,root_stack_size);
+ C = root_stack[root_stack_size-1];
// output the string represented by pW
- while (!root_stack.empty())
+ while (root_stack_size>0)
{
- SAVE_OUTPUT_ROOT(root_stack.top(), dest, bytes_written);
- root_stack.pop();
+ SAVE_OUTPUT_ROOT(root_stack[root_stack_size-1], dest, bytes_written);
+ root_stack_size--;
}
// output the char C
SAVE_OUTPUT_ROOT(C, dest, bytes_written);
@@ -357,7 +362,8 @@ void Cu6mPlayer::output_root(unsigned char root, unsigned char *destination, lon
// output the string represented by a codeword
-void Cu6mPlayer::get_string(int codeword, Cu6mPlayer::MyDict& dictionary, std::stack<unsigned char>& root_stack)
+//void Cu6mPlayer::get_string(int codeword, Cu6mPlayer::MyDict& dictionary, std::stack<unsigned char>& root_stack)
+void Cu6mPlayer::get_string(int codeword, Cu6mPlayer::MyDict& dictionary, unsigned char *root_stack, int &root_stack_size)
{
unsigned char root;
int current_codeword;
@@ -368,11 +374,11 @@ void Cu6mPlayer::get_string(int codeword, Cu6mPlayer::MyDict& dictionary, std::s
{
root = dictionary.get_root(current_codeword);
current_codeword = dictionary.get_codeword(current_codeword);
- root_stack.push(root);
+ root_stack[root_stack_size++]=root;
}
// push the root at the leaf
- root_stack.push((unsigned char)current_codeword);
+ root_stack[root_stack_size++]= (unsigned char)current_codeword;
}
@@ -583,7 +589,7 @@ void Cu6mPlayer::command_81()
new_ss_info.subsong_start = read_song_byte(); new_ss_info.subsong_start += read_song_byte() << 8;
new_ss_info.continue_pos = song_pos;
- subsong_stack.push(new_ss_info);
+ subsong_stack[subsong_stack_sz++] = new_ss_info;
song_pos = new_ss_info.subsong_start;
}
@@ -662,10 +668,10 @@ void Cu6mPlayer::command_E()
// ---------------------------
void Cu6mPlayer::command_F()
{
- if (!subsong_stack.empty())
+ if (subsong_stack_sz)
{
- subsong_info temp = subsong_stack.top();
- subsong_stack.pop();
+ subsong_info temp = subsong_stack[subsong_stack_sz-1];
+ subsong_stack_sz--;
temp.subsong_repetitions--;
if (temp.subsong_repetitions==0)
{
@@ -674,7 +680,7 @@ void Cu6mPlayer::command_F()
else
{
song_pos = temp.subsong_start;
- subsong_stack.push(temp);
+ subsong_stack[subsong_stack_sz++] = temp;
}
}
else