summaryrefslogtreecommitdiff
path: root/music/pokeredmusicdisasm/Duty.cpp
blob: 0723074bff191b410f02ecf8ada3021a9dfd1e26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <sstream>
#include "Duty.h"
using namespace std;

Duty::Duty()
{
    duty = 0;
}

Duty::Duty(unsigned char* byte) // Parse Immidiately
{
    Parse(byte);
}

Duty::Duty(unsigned char value, bool) // Set value
{
    SetDuty(value);
}

unsigned char Duty::GetDuty()
{
    return duty;
}

void Duty::SetDuty(unsigned char value)
{
    // Clamp duty to 3 since that's the highest possible
    duty = value;
    if(duty >= 3) duty = 3;
}

// Byte 0 - The Command Code
// Byte 1 - The Value
bool Duty::IsValid(unsigned char* byte)
{
	if((byte[0] == 0xEC) &&
		(byte[1] >= 0x0) &&
		(byte[1] <= 0x3))
	{
		error = false;	// Unblock assembling
		return true;
	}
	else
	{
		error = true;	// Block assembling
		return false;
	}
}

string Duty::GenAsm()
{
	string ret = AbstractData::GenAsm();
    if(ret != "") return ret;

	stringstream tmpAsmOut;
	tmpAsmOut << "mus_duty " << LookupDutyString();
	return tmpAsmOut.str();
}

bool Duty::Parse(unsigned char* byte)
{
	if(!AbstractData::Parse(byte)) return false;

	duty = byte[1];
        return true;
}

string Duty::LookupDutyString()
{
	// In case some error happens and the values doesn't match the list below
	stringstream defTmp;

	switch(duty)
	{
	case duty12_5:
		return "duty12_5";
	case duty25:
		return "duty25";
	case duty50:
		return "duty50";
	case duty75:
		return "duty75";
	default:
		defTmp << "$" << uppercase << hex << (short)duty;
		return defTmp.str();
	}
}

unsigned int Duty::Arguments()
{
    //1 1-byte argument = 1
    return 1;
}