SkinUltimate::SkinUltimate(string posPath, string negPath)
{
	//File reading part
	std::ifstream t(posPath);
	std::string strS((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
	std::ifstream z(negPath);
	std::string strN((std::istreambuf_iterator<char>(z)), std::istreambuf_iterator<char>());
	int b = 0, g = 0, r = 0;
	int sums = 0, sumn = 0;

	//fill numberS numberN skinMap from give file
	for (b = 0; b < DIM; b++) {
		for (g = 0; g < DIM; g++) {
			for (r = 0; r < DIM; r++) {
				numberS[b][g][r] = 0;
				numberN[b][g][r] = 0;
				skinMap[b][g][r] = 0;
			}
		}
	}
	b = 0; g = 0; r = 0; int maxS = 0;
	for each (char lol in strS)
	{
		if (lol == ' ') {
			sums += numberS[b][g][r];
			if (numberS[b][g][r] > maxS) maxS = numberS[b][g][r];
			if (r == DIM - 1) {
				r = 0;
				if (g == DIM - 1) {
					g = 0;
					if (b == DIM - 1) {

					}
					else { b++; }
				}
				else { g++; }
			}
			else { r++; }
		}
		else {
			numberS[b][g][r] = numberS[b][g][r] * 10 + (lol - '0');
		}
	}
	b = 0; g = 0; r = 0; int maxN = 0;
	for each (char lol in strN)
	{
		if (lol == ' ') {
			sumn += numberN[b][g][r];
			if (numberN[b][g][r] > maxN) maxN = numberN[b][g][r];
			if (r == DIM - 1) {
				r = 0;
				if (g == DIM - 1) {
					g = 0;
					if (b == DIM - 1) {

					}
					else { b++; }
				}
				else { g++; }
			}
			else { r++; }
		}
		else {
			numberN[b][g][r] = numberN[b][g][r] * 10 + (lol - '0');
		}
	}
	float maxSkin = 0;
	for (b = 0; b < DIM; b++) {
		for (g = 0; g < DIM; g++) {
			for (r = 0; r < DIM; r++) {
				if (numberS[b][g][r] != 0) {
					skinMap[b][g][r] = (Ps*numberS[b][g][r]) / (Ps*numberS[b][g][r] + (1 - Ps)*numberN[b][g][r] * ((double)sums / sumn));	//Ps_c = (Pc_s*Ps) / (Pc_s*Ps + Pc_ns(1-Ps));
					if (skinMap[b][g][r] > maxSkin) maxSkin == skinMap[b][g][r];
				}
			}
		}
	}
	int hehe = 0;
	//calculate charmaps
	for (b = 0; b < DIM; b++) {
		for (g = 0; g < DIM; g++) {
			for (r = 0; r < DIM; r++) {
				//Trees
				if (((r << 3) > 95) && ((g << 3) > 40) && ((b << 3) > 20) && ((r << 3) > (b << 3)) && ((r << 3) > (g << 3) + 15) && ((r << 3) > min((b << 3), (g << 3)) + 15)) {
					map[TREE][b][g][r] = 255;
					map[BAYES_TREE][b][g][r] = skinMap[b][g][r] * 255;
					hehe++;
				}
				else {
					map[TREE][b][g][r] = 0;
					map[BAYES_TREE][b][g][r] = skinMap[b][g][r] * 255 * BT_factor;
				}
				//Prob
				if (((double)numberS[b][g][r] / sums) > ((double)numberN[b][g][r] / sumn))
					map[PROB][b][g][r] = 255;
				else
					map[PROB][b][g][r] = 0;
				//Bayes
				map[BAYES][b][g][r] = skinMap[b][g][r] * 255;
			}
		}
	}
}
Exemple #2
0
/*static*/
void ComponentInterface::ThrowException(int nExceptionFlags ,const char *pzExceptionMatch, const char *pzData, const char *pzExecSignature )
{
	if (!nExceptionFlags)
		return;

	// set defaults
	int bThrowOnNullOrEmpty = 0;
	int nComparisonType = 0;	//0=NoCompare
	int bLookForXMLException = 0;

	// extract bit flag settings
	if ( ( nExceptionFlags & EX_EMPTYORNULL ) != 0)
		bThrowOnNullOrEmpty = 1;
	if ( ( nExceptionFlags & EX_RETURN_EQUAL ) != 0)
		nComparisonType = EX_RETURN_EQUAL;
	if ( ( nExceptionFlags & EX_RETURN_CONTAINS ) != 0)
		nComparisonType = EX_RETURN_CONTAINS;
	if ( ( nExceptionFlags & EX_RETURN_STARTSWITH ) != 0)
		nComparisonType = EX_RETURN_STARTSWITH;
	if ( ( nExceptionFlags & EX_XMLEXCEPTION ) != 0)
		bLookForXMLException = 1;
	
	if (bThrowOnNullOrEmpty)
	{
		if (!pzExceptionMatch || !pzExceptionMatch[0])
			throw GException("CustomException", 1, pzExecSignature);
	}
	if (nComparisonType == EX_RETURN_EQUAL)
	{
		GString strEXMatch(pzExceptionMatch);
		if ( strEXMatch.CompareNoCase(pzData) == 0 )
			throw GException("CustomException", 3, pzExecSignature, pzData);
	}
	if (nComparisonType == EX_RETURN_STARTSWITH)
	{
		GString strEXMatch( pzExceptionMatch );
		if ( (int)strlen(pzData) >= strEXMatch.Length() )
		{
			GString strMatch(pzData,strEXMatch.Length());
			if ( strEXMatch.CompareNoCase((const char *)strMatch) == 0 )
				throw GException("CustomException", 4, pzExecSignature, (const char *)strMatch);
		}
	}
	if (nComparisonType == EX_RETURN_CONTAINS)
	{
		if ( strstr(pzData,pzExceptionMatch) )
		{
			throw GException("CustomException", 5, pzExecSignature, pzExceptionMatch);
		}
	}
	if ( bLookForXMLException )
	{
		int bIsXMLException = 0;
		try
		{
			CXMLTree xmlGraftTree;
			xmlGraftTree.parseXML( (char *)pzData );
			CXMLElementx *pRoot = xmlGraftTree.getRoot();
			
			GString strRootTag(pRoot->getTag(), pRoot->getTagLen());
			if (strRootTag.CompareNoCase("Exception") == 0)
			{
				int nError = 0;
				CXMLElementx *pE = pRoot->findChild("ErrorNumber");
				if (pE)
				{
					GString strE(pE->getTag(), pE->getTagLen());
					nError = atoi((const char *)strE);
				}

				int nSubSys = 0;
				CXMLElementx *pS = pRoot->findChild("SubSystem");
				if (pS)
				{
					GString strS(pS->getTag(), pS->getTagLen());
					nSubSys = atoi((const char *)strS);
				}

				GString strDescription("User Defined Exception with no Description");
				CXMLElementx *pD = pRoot->findChild("Description");
				if (pD)
				{
					GString strD(pD->getTag(), pD->getTagLen());
					strDescription = (const char *)strD;
				}

				GStringList Stack;
				CXMLElementx *pC = pRoot->findChild("CallStack");
				if (pC)
				{
					int i = 0;
					while (1)
					{
						CXMLElementx *pF = pC->findChild("Frame",++i);
						if (!pF)
							break;
						GString strF(pF->getTag(), pF->getTagLen());
						Stack.AddLast(strF);
					}
				}
				Stack.AddLast(pzExecSignature);

				bIsXMLException = 1;
				throw GException(nError, nSubSys, (const char *)strDescription, &Stack);
			}
		}
		catch( GException &)
		{
			if (bIsXMLException)
			{
				// propigate the user exception 
				throw;
			}
			else
			{
			// ignore this exception.  
			// If we can't parse the pzData then we know this is not an XMLException.  
			}
		}
	}
}
Exemple #3
0
void disassembleInstruction(void) {
    std::string tmpstr;
    std::string old;
    std::string w;

    disasm.new_address = disasm.base_address;

    disasmHighlight.hit_read_breakpoint = false;
    disasmHighlight.hit_write_breakpoint = false;
    disasmHighlight.hit_exec_breakpoint = false;
    disasmHighlight.hit_pc = false;

    disasm.instruction.data = "";
    disasm.instruction.opcode = "";
    disasm.instruction.mode_suffix = " ";
    disasm.instruction.arguments = "";
    disasm.instruction.size = 0;

    disasm.il = disasm.adl;
    disasm.l = disasm.adl;
    disasm.prefix = false;
    disasm.suffix = false;

    union {
        uint8_t opcode;
        struct {
            uint8_t z : 3;
            uint8_t y : 3;
            uint8_t x : 2;
        };
        struct {
            uint8_t r : 1;
            uint8_t dummy : 2;
            uint8_t q : 1;
            uint8_t p : 2;
        };
    } context;

    do {
        // fetch opcode
        context.opcode = disasm_fetch_byte();

        switch (context.x) {
            case 0:
                switch (context.z) {
                    case 0:
                        switch (context.y) {
                            case 0:  // NOP
                                disasm.instruction.opcode = "nop";
                                break;
                            case 1:  // EX af,af'
                                disasm.instruction.opcode = "ex";
                                disasm.instruction.arguments = "af,af'";
                                break;
                            case 2: // DJNZ d
                                disasm.instruction.opcode = "djnz";
                                disasm.instruction.arguments = strW(disasm.new_address+1+disasm_fetch_offset());
                                break;
                            case 3: // JR d
                                disasm.instruction.opcode = "jr";
                                disasm.instruction.arguments = strW(disasm.new_address+1+disasm_fetch_offset());
                                break;
                            case 4:
                            case 5:
                            case 6:
                            case 7: // JR cc[y-4], d
                                disasm.instruction.opcode = "jr";
                                disasm.instruction.arguments = cc_table[context.y-4]+","+ strW(disasm.new_address+1+disasm_fetch_offset());
                                break;
                        }
                        break;
                    case 1:
                        switch (context.q) {
                            case 0: // LD rr, Mmn
                                if (context.p == 3 && disasm.prefix) { // LD IY/IX, (IX/IY + d)
                                    disasm.instruction.opcode = "ld";
                                    disasm.instruction.arguments = index_table[disasm.prefix] + ",(" + index_table[disasm.prefix ^ 1] + strOffset(disasm_fetch_offset()) + ")" ;
                                    break;
                                }
                                disasm.instruction.opcode = "ld";
                                disasm.instruction.arguments = disasm_read_rp(context.p)+","+strW(disasm_fetch_word());
                                break;
                            case 1: // ADD HL,rr
                                disasm.instruction.opcode = "add";
                                disasm.instruction.arguments = index_table[disasm.prefix]+","+disasm_read_rp(context.p);
                                break;
                        }
                        break;
                    case 2:
                        switch (context.q) {
                            case 0:
                                switch (context.p) {
                                    case 0: // LD (BC), A
                                        disasm.instruction.opcode = "ld";
                                        disasm.instruction.arguments = "(bc),a";
                                        break;
                                    case 1: // LD (DE), A
                                        disasm.instruction.opcode = "ld";
                                        disasm.instruction.arguments = "(de),a";
                                        break;
                                    case 2: // LD (Mmn), HL
                                        disasm.instruction.opcode = "ld";
                                        disasm.instruction.arguments = strWind(disasm_fetch_word())+","+index_table[disasm.prefix];
                                        break;
                                    case 3: // LD (Mmn), A
                                        disasm.instruction.opcode = "ld";
                                        disasm.instruction.arguments = strWind(disasm_fetch_word())+",a";
                                        break;
                                }
                                break;
                            case 1:
                                switch (context.p) {
                                    case 0: // LD A, (BC)
                                        disasm.instruction.opcode = "ld";
                                        disasm.instruction.arguments = "a,(bc)";
                                        break;
                                    case 1: // LD A, (DE)
                                        disasm.instruction.opcode = "ld";
                                        disasm.instruction.arguments = "a,(de)";
                                        break;
                                    case 2: // LD HL, (Mmn)
                                        disasm.instruction.opcode = "ld";
                                        disasm.instruction.arguments = index_table[disasm.prefix]+","+strWind(disasm_fetch_word());
                                        break;
                                    case 3: // LD A, (Mmn)
                                        disasm.instruction.opcode = "ld";
                                        disasm.instruction.arguments = "a,"+strWind(disasm_fetch_word());
                                        break;
                                }
                                break;
                        }
                        break;
                    case 3:
                        switch (context.q) {
                            case 0: // INC rp[p]
                                disasm.instruction.opcode = "inc";
                                disasm.instruction.arguments = disasm_read_rp(context.p);
                                break;
                            case 1: // DEC rp[p]
                                disasm.instruction.opcode = "dec";
                                disasm.instruction.arguments = disasm_read_rp(context.p);
                                break;
                        }
                        break;
                    case 4: // INC r[y]
                        disasm.instruction.opcode = "inc";
                        w = (context.y == 6) ? disasm_index_address() : "0";
                        disasm.instruction.arguments = disasm_read_reg_prefetched(context.y, w);
                        break;
                    case 5: // DEC r[y]
                        disasm.instruction.opcode = "dec";
                        w = (context.y == 6) ? disasm_index_address() : "0";
                        disasm.instruction.arguments = disasm_read_reg_prefetched(context.y, w);
                        break;
                    case 6: // LD r[y], n
                        if (context.y == 7 && disasm.prefix) { // LD (IX/IY + d), IY/IX
                            disasm.instruction.opcode = "ld";
                            disasm.instruction.arguments = "("+index_table[disasm.prefix]+strOffset(disasm_fetch_offset())+"),"+index_table[disasm.prefix ^ 1];
                            break;
                        }
                        disasm.instruction.opcode = "ld";
                        w = (context.y == 6) ? disasm_index_address() : "0";
                        if(!disasm.prefix) {
                            w = "("+w+"),";
                        }
                        disasm_write_reg_prefetched(context.y, w, strS(disasm_fetch_byte()));
                        break;
                    case 7:
                        if (disasm.prefix) {
                            if (context.q) { // LD (IX/IY + d), rp3[p]
                                disasm.instruction.opcode = "ld";
                                disasm.instruction.arguments = "("+index_table[disasm.prefix]+strOffset(disasm_fetch_offset())+"),"+disasm_read_rp3(context.p);
                            } else { // LD rp3[p], (IX/IY + d)
                                disasm.instruction.opcode = "ld";
                                disasm.instruction.arguments = disasm_read_rp3(context.p)+",("+index_table[disasm.prefix]+strOffset(disasm_fetch_offset())+")";
                            }
                        } else {
                            disasm.instruction.opcode = rot_acc_table[context.y];
                        }
                        break;
                }
                break;
            case 1: // ignore prefixed prefixes
                if (context.z == context.y) {
                    switch (context.z) {
                        case 0: // .SIS
                            disasm.suffix = 1;
                            disasm.instruction.mode_suffix = ".sis ";
                            disasm.l = false;
                            disasm.il = false;
                            goto exit_loop;
                        case 1: // .LIS
                            disasm.suffix = 1;
                            disasm.instruction.mode_suffix = ".lis ";
                            disasm.l = true;
                            disasm.il = false;
                            goto exit_loop;
                        case 2: // .SIL
                            disasm.suffix = 1;
                            disasm.instruction.mode_suffix = ".sil ";
                            disasm.l = false;
                            disasm.il = true;
                            goto exit_loop;
                        case 3: // .LIL
                            disasm.suffix = 1;
                            disasm.instruction.mode_suffix = ".lil ";
                            disasm.l = true;
                            disasm.il = true;
                            goto exit_loop;
                        case 6: // HALT
                            disasm.instruction.opcode = "halt";
                            break;
                        case 4: // LD H, H
                            disasm.instruction.opcode = "ld";
                            disasm.instruction.arguments = index_h[disasm.prefix]+","+index_h[disasm.prefix];
                            break;
                        case 5: // LD L, L
                            disasm.instruction.opcode = "ld";
                            disasm.instruction.arguments = index_l[disasm.prefix]+","+index_l[disasm.prefix];
                            break;
                        case 7: // LD A, A
                            disasm.instruction.opcode = "ld";
                            disasm.instruction.opcode = "a,a";
                            break;
                        default:
                            abort();
                    }
                } else {
                    disasm_read_write_reg(context.z, context.y);
                }
                break;
            case 2: // ALU[y] r[z]
                disasm.instruction.opcode = alu_table[context.y];
                disasm.instruction.arguments = "a,"+disasm_read_reg(context.z);
                break;
            case 3:
                switch (context.z) {
                    case 0: // RET cc[y]
                        disasm.instruction.opcode = "ret";
                        disasm.instruction.arguments = cc_table[context.y];
                        break;
                    case 1:
                        switch (context.q) {
                            case 0: // POP rp2[p]
                                disasm.instruction.opcode = "pop";
                                disasm.instruction.arguments = disasm_read_rp2(context.p);
                                break;
                            case 1:
                                switch (context.p) {
                                    case 0: // RET
                                        disasm.instruction.opcode = "ret";
                                        break;
                                    case 1: // EXX
                                        disasm.instruction.opcode = "exx";
                                        break;
                                    case 2: // JP (rr)
                                        disasm.instruction.opcode = "jp";
                                        disasm.instruction.arguments = "("+index_table[disasm.prefix]+")";
                                        break;
                                    case 3: // LD SP, INDEX
                                        disasm.instruction.opcode = "ld";
                                        disasm.instruction.arguments = "sp,"+index_table[disasm.prefix];
                                        break;
                                }
                                break;
                        }
                        break;
                    case 2: // JP cc[y], nn
                        disasm.instruction.opcode = "jp";
                        disasm.instruction.arguments = cc_table[context.y]+","+strW(disasm_fetch_word());
                        break;
                    case 3:
                        switch (context.y) {
                            case 0: // JP nn
                                disasm.instruction.opcode = "jp";
                                disasm.instruction.arguments = strW(disasm_fetch_word());
                                break;
                            case 1: // 0xCB prefixed opcodes
                                w = disasm_index_address();
                                context.opcode = disasm_fetch_byte();
                                old = disasm_read_reg_prefetched(context.z, w);
                                switch (context.x) {
                                    case 0: // rot[y] r[z]
                                        disasm.instruction.opcode = rot_table[context.y];
                                        disasm.instruction.arguments = old;
                                        break;
                                    case 1: // BIT y, r[z]
                                        disasm.instruction.opcode = "bit";
                                        disasm.instruction.arguments = std::to_string(context.y)+","+old;
                                        break;
                                    case 2: // RES y, r[z]
                                        disasm.instruction.opcode = "res";
                                        disasm.instruction.arguments = std::to_string(context.y)+","+old;
                                        break;
                                    case 3: // SET y, r[z]
                                        disasm.instruction.opcode = "set";
                                        disasm.instruction.arguments = std::to_string(context.y)+","+old;
                                        break;
                                }
                                break;
                            case 2: // OUT (n), A
                                disasm.instruction.opcode = "out";
                                disasm.instruction.arguments = strSind(disasm_fetch_byte())+",a";
                                break;
                            case 3: // IN A, (n)
                                disasm.instruction.opcode = "in";
                                disasm.instruction.arguments = "a,"+strSind(disasm_fetch_byte());
                                break;
                            case 4: // EX (SP), HL/I
                                disasm.instruction.opcode = "ex";
                                disasm.instruction.arguments = "(sp),"+index_table[disasm.prefix];
                                break;
                            case 5: // EX DE, HL
                                disasm.instruction.opcode = "ex";
                                disasm.instruction.arguments = "de,hl";
                                break;
                            case 6: // DI
                                disasm.instruction.opcode = "di";
                                break;
                            case 7: // EI
                                disasm.instruction.opcode = "ei";
                                continue;
                        }
                        break;
                    case 4: // CALL cc[y], nn
                        disasm.instruction.opcode = "call";
                        disasm.instruction.arguments = cc_table[context.y]+","+strW(disasm_fetch_word());
                        break;
                    case 5:
                        switch (context.q) {
                            case 0: // PUSH r2p[p]
                                disasm.instruction.opcode = "push";
                                disasm.instruction.arguments = disasm_read_rp2(context.p);
                                break;
                            case 1:
                                switch (context.p) {
                                    case 0: // CALL nn
                                        disasm.instruction.opcode = "call";
                                        disasm.instruction.arguments = strW(disasm_fetch_word());
                                        break;
                                    case 1: // 0xDD prefixed opcodes
                                        disasm.prefix = 2;
                                        goto exit_loop;
                                    case 2: // 0xED prefixed opcodes
                                        disasm.prefix = 0; // ED cancels effect of DD/FD prefix
                                        context.opcode = disasm_fetch_byte();
                                        switch (context.x) {
                                            case 0:
                                                switch (context.z) {
                                                    case 0:
                                                        if (context.y == 6) { // OPCODETRAP
                                                            disasm.instruction.opcode = "OPCODETRAP";
                                                        } else { // IN0 r[y], (n)
                                                            disasm.instruction.opcode = "in0";
                                                            disasm.instruction.arguments = disasm_read_reg(context.y)+","+strSind(disasm_fetch_byte());
                                                        }
                                                        break;
                                                     case 1:
                                                        if (context.y == 6) { // LD IY, (HL)
                                                            disasm.instruction.opcode = "ld";
                                                            disasm.instruction.arguments = "iy,(hl)";
                                                        } else { // OUT0 (n), r[y]
                                                            disasm.instruction.opcode = "out0";
                                                            disasm.instruction.arguments = strSind(disasm_fetch_byte())+","+disasm_read_reg(context.y);
                                                        }
                                                        break;
                                                    case 2: // LEA rp3[p], IX + d
                                                    case 3: // LEA rp3[p], IY + d
                                                        if (context.q) { // OPCODETRAP
                                                            disasm.instruction.opcode = "OPCODETRAP";
                                                        } else {
                                                            disasm.prefix = context.z;
                                                            disasm.instruction.opcode = "lea";
                                                            disasm.instruction.arguments = disasm_read_rp3(context.p)+","+index_table[context.z]+strOffset(disasm_fetch_offset());
                                                        }
                                                        break;
                                                    case 4: // TST A, r[y]
                                                        disasm.instruction.opcode = "tst";
                                                        disasm.instruction.arguments = "a,"+disasm_read_reg(context.y);
                                                        break;
                                                    case 6:
                                                        if (context.y == 7) { // LD (HL), IY
                                                            disasm.instruction.opcode = "ld";
                                                            disasm.instruction.arguments = "(hl),iy";
                                                            break;
                                                        }
                                                    case 5: // OPCODETRAP
                                                        disasm.instruction.opcode = "OPCODETRAP";
                                                        break;
                                                    case 7:
                                                        disasm.prefix = 2;
                                                        if (context.q) { // LD (HL), rp3[p]
                                                            disasm.instruction.opcode = "ld";
                                                            disasm.instruction.arguments = "(hl),"+disasm_read_rp3(context.p);
                                                        } else { // LD rp3[p], (HL)
                                                            disasm.instruction.opcode = "ld";
                                                            disasm.instruction.arguments = disasm_read_rp3(context.p)+",(hl)";
                                                        }
                                                        break;
                                                }
                                                break;
                                            case 1:
                                                switch (context.z) {
                                                    case 0:
                                                        if (context.y == 6) { // OPCODETRAP (ADL)
                                                            disasm.instruction.opcode = "OPCODETRAP";
                                                        } else { // IN r[y], (BC)
                                                            disasm.instruction.opcode = "in";
                                                            disasm.instruction.arguments = disasm_read_reg(context.y)+",(bc)";
                                                        }
                                                        break;
                                                    case 1:
                                                        if (context.y == 6) { // OPCODETRAP (ADL)
                                                            disasm.instruction.opcode = "OPCODETRAP";
                                                        } else { // OUT (BC), r[y]
                                                            disasm.instruction.opcode = "out";
                                                            disasm.instruction.arguments = "(bc),"+disasm_read_reg(context.y);
                                                        }
                                                        break;
                                                    case 2:
                                                        if (context.q == 0) { // SBC HL, rp[p]
                                                            disasm.instruction.opcode = "sbc";
                                                            disasm.instruction.arguments = "hl,"+disasm_read_rp(context.p);
                                                        } else { // ADC HL, rp[p]
                                                            disasm.instruction.opcode = "adc";
                                                            disasm.instruction.arguments = "hl,"+disasm_read_rp(context.p);
                                                        }
                                                        break;
                                                    case 3:
                                                        if (context.q == 0) { // LD (nn), rp[p]
                                                            disasm.instruction.opcode = "ld";
                                                            disasm.instruction.arguments = strWind(disasm_fetch_word())+","+disasm_read_rp(context.p);
                                                        } else { // LD rp[p], (nn)
                                                            disasm.instruction.opcode = "ld";
                                                            disasm.instruction.arguments = disasm_read_rp(context.p)+","+strWind(disasm_fetch_word());
                                                        }
                                                        break;
                                                    case 4:
                                                        if (context.q == 0) {
                                                            switch (context.p) {
                                                                case 0:  // NEG
                                                                    disasm.instruction.opcode = "neg";
                                                                    break;
                                                                case 1:  // LEA IX, IY + d
                                                                    disasm.instruction.opcode = "lea";
                                                                    disasm.instruction.arguments = "ix,iy"+strOffset(disasm_fetch_byte());
                                                                    break;
                                                                case 2:  // TST A, n
                                                                    disasm.instruction.opcode = "tst";
                                                                    disasm.instruction.arguments = "a,"+strS(disasm_fetch_byte());
                                                                    break;
                                                                case 3:  // TSTIO n
                                                                    disasm.instruction.opcode = "tstio";
                                                                    disasm.instruction.arguments = strS(disasm_fetch_byte());
                                                                    break;
                                                            }
                                                        }
                                                        else { // MLT rp[p]
                                                            disasm.instruction.opcode = "mlt";
                                                            disasm.instruction.arguments = disasm_read_rp(context.p);
                                                            break;
                                                        }
                                                        break;
                                                    case 5:
                                                        switch (context.y) {
                                                            case 0: // RETN
                                                                disasm.instruction.opcode = "retn";
                                                                break;
                                                            case 1: // RETI
                                                                disasm.instruction.opcode = "reti";
                                                                break;
                                                            case 2: // LEA IY, IX + d
                                                                disasm.instruction.opcode = "lea";
                                                                disasm.instruction.arguments = "iy,ix"+strOffset(disasm_fetch_offset());
                                                                break;
                                                            case 3:
                                                            case 6: // OPCODETRAP
                                                                disasm.instruction.opcode = "OPCODETRAP";
                                                                break;
                                                            case 4: // PEA IX + d
                                                                disasm.instruction.opcode = "pea";
                                                                disasm.instruction.arguments = "ix"+strOffset(disasm_fetch_offset());
                                                                break;
                                                            case 5: // LD MB, A
                                                                if (disasm.il) {
                                                                    disasm.instruction.opcode = "ld";
                                                                    disasm.instruction.arguments = "mb,a";
                                                                } else { // OPCODETRAP
                                                                    disasm.instruction.opcode = "OPCODETRAP";
                                                                }
                                                                break;
                                                            case 7: // STMIX
                                                                disasm.instruction.opcode = "stmix";
                                                                break;
                                                        }
                                                        break;
                                                    case 6: // IM im[y]
                                                        switch (context.y) {
                                                            case 0:
                                                            case 2:
                                                            case 3: // IM im[y]
                                                                disasm.instruction.opcode = "im";
                                                                disasm.instruction.arguments = im_table[context.y];
                                                                break;
                                                            case 1: // OPCODETRAP
                                                                disasm.instruction.opcode = "OPCODETRAP";
                                                                break;
                                                            case 4: // PEA IY + d
                                                                disasm.instruction.opcode = "pea";
                                                                disasm.instruction.arguments = "iy"+strOffset(disasm_fetch_offset());
                                                                break;
                                                            case 5: // LD A, MB
                                                                if (disasm.il) {
                                                                    disasm.instruction.opcode = "ld";
                                                                    disasm.instruction.arguments = "a,mb";
                                                                } else { // OPCODETRAP
                                                                    disasm.instruction.opcode = "OPCODETRAP";
                                                                }
                                                                break;
                                                            case 6: // SLP
                                                                disasm.instruction.arguments = "slp";
                                                                break;
                                                            case 7: // RSMIX
                                                                disasm.instruction.opcode = "rsmix";
                                                                break;
                                                        }
                                                        break;
                                                    case 7:
                                                        switch (context.y) {
                                                            case 0: // LD I, A
                                                                disasm.instruction.opcode = "ld";
                                                                disasm.instruction.arguments = "i,a";
                                                                break;
                                                            case 1: // LD R, A
                                                                disasm.instruction.opcode = "ld";
                                                                disasm.instruction.arguments = "r,a";
                                                                break;
                                                            case 2: // LD A, I
                                                                disasm.instruction.opcode = "ld";
                                                                disasm.instruction.arguments = "a,i";
                                                                break;
                                                            case 3: // LD A, R
                                                                disasm.instruction.opcode = "ld";
                                                                disasm.instruction.arguments = "a,r";
                                                                break;
                                                            case 4: // RRD
                                                                disasm.instruction.opcode = "rrd";
                                                                break;
                                                            case 5: // RLD
                                                                disasm.instruction.opcode = "rld";
                                                                break;
                                                            default: // OPCODETRAP
                                                                disasm.instruction.opcode = "OPCODETRAP";
                                                                break;
                                                        }
                                                        break;
                                                }
                                                break;
                                            case 2:
                                                if (context.y >= 0 && context.z <= 4) { // bli[y,z]
                                                    disasm_bli(context.y, context.z);
                                                } else { // OPCODETRAP
                                                    disasm.instruction.opcode = "OPCODETRAP";
                                                }
                                                break;
                                            case 3:  // There are only a few of these, so a simple switch for these shouldn't matter too much
                                                switch(context.opcode) {
                                                    case 0xC2: // INIRX
                                                        disasm.instruction.opcode = "inirx";
                                                        break;
                                                    case 0xC3: // OTIRX
                                                        disasm.instruction.opcode = "otirx";
                                                        break;
                                                    case 0xC7: // LD I, HL
                                                        disasm.instruction.opcode = "ld";
                                                        disasm.instruction.arguments = "i,hl";
                                                        break;
                                                    case 0xD7: // LD HL, I
                                                        disasm.instruction.opcode = "ld";
                                                        disasm.instruction.arguments = "hl,i";
                                                        break;
                                                    case 0xCA: // INDRX
                                                        disasm.instruction.opcode = "indrx";
                                                        break;
                                                    case 0xCB: // OTDRX
                                                        disasm.instruction.opcode = "otdrx";
                                                        break;
                                                    case 0xEE: // flash erase
                                                        disasm.instruction.opcode = "FLASH_ERASE";
                                                        break;
                                                    default:   // OPCODETRAP
                                                        disasm.instruction.opcode = "OPCODETRAP";
                                                        break;
                                                }
                                                break;
                                            default: // OPCODETRAP
                                                disasm.instruction.opcode = "OPCODETRAP";
                                                break;
                                        }
                                        break;
                                    case 3: // 0xFD prefixed opcodes
                                        disasm.prefix = 3;
                                        goto exit_loop;
                                }
                                break;
                        }
                        break;
                    case 6: // alu[y] n
                        disasm.instruction.opcode = alu_table[context.y];
                        disasm.instruction.arguments = "a,"+strS(disasm_fetch_byte());
                        break;
                    case 7: // RST y*8
                        disasm.instruction.opcode = "rst";
                        disasm.instruction.arguments = strS(context.y << 3);
                        break;
                }
                break;
        }
        disasm.suffix = disasm.prefix = 0;
exit_loop:
      continue;
    } while (disasm.prefix || disasm.suffix);
}