diff options
author | Ian C <ianc@noddybox.co.uk> | 2006-08-28 01:32:34 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2006-08-28 01:32:34 +0000 |
commit | 25738474b655bbff8c31b12634d7377520420baf (patch) | |
tree | 82fe6586ff721004d71386044cf3203f55f46936 /z80_dis.c | |
parent | 472447531bc02c0cbdf9793675ef4475fa07aef5 (diff) |
Added labels to Z80 disassembler
Diffstat (limited to 'z80_dis.c')
-rw-r--r-- | z80_dis.c | 129 |
1 files changed, 112 insertions, 17 deletions
@@ -34,7 +34,6 @@ static const char ident[]="$Id$"; #include "z80.h" #include "z80_private.h" - static Z80Relative cb_off; /* ---------------------------------------- SHARED ROUTINES @@ -97,6 +96,25 @@ const char *Z80_Dis_GetArg(void) } +static const char *GetLabel(Z80Word w) +{ + if (z80_labels) + { + int f; + + for(f=0;z80_labels[f].label;f++) + { + if (z80_labels[f].address==w) + { + return z80_labels[f].label; + } + } + } + + return NULL; +} + + /* ---------------------------------------- CB xx BYTE OPCODES */ @@ -286,10 +304,14 @@ static void DIS_LD_IX_WORD(Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_LD_ADDR_IX(Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),ix",w)); + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("(%s),ix",p)); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),ix",w)); } static void DIS_INC_IX(Z80 *z80, Z80Byte op, Z80Word *pc) @@ -320,9 +342,14 @@ static void DIS_ADD_IX_IX(Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_LD_IX_ADDR(Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("ix,($%.4x)",w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("ix,(%s)",p)); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("ix,($%.4x)",w)); } static void DIS_DEC_IX(Z80 *z80, Z80Byte op, Z80Word *pc) @@ -704,9 +731,14 @@ static void DIS_SBC_HL_R16(Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_ED_LD_ADDR_R16(Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),%s",w,z80_dis_reg16[(op-0x40)/16])); + + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("(%s),%s",p,z80_dis_reg16[(op-0x40)/16])); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),%s",w,z80_dis_reg16[(op-0x40)/16])); } static void DIS_NEG(Z80 *z80, Z80Byte op, Z80Word *pc) @@ -737,9 +769,14 @@ static void DIS_ADC_HL_R16(Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_ED_LD_R16_ADDR(Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("%s,($%.4x)",z80_dis_reg16[(op-0x40)/16],w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("%s,(%s)",z80_dis_reg16[(op-0x40)/16],p)); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("%s,($%.4x)",z80_dis_reg16[(op-0x40)/16],w)); } static void DIS_RETI(Z80 *z80, Z80Byte op, Z80Word *pc) @@ -955,9 +992,14 @@ static void DIS_LD_IY_WORD(Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_LD_ADDR_IY(Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),iy",w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("(%s),iy",p)); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),iy",w)); } static void DIS_INC_IY(Z80 *z80, Z80Byte op, Z80Word *pc) @@ -988,9 +1030,14 @@ static void DIS_ADD_IY_IY(Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_LD_IY_ADDR(Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("iy,($%.4x)",w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("iy,(%s)",p)); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("iy,($%.4x)",w)); } static void DIS_DEC_IY(Z80 *z80, Z80Byte op, Z80Word *pc) @@ -1420,11 +1467,15 @@ static void DIS_RLA (Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_JR (Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word new; + const char *p; new=*pc+(Z80Relative)z80->memory[*pc]+1; (*pc)++; - Z80_Dis_Set("jr",Z80_Dis_Printf("$%.4x",new)); + if ((p=GetLabel(new))) + Z80_Dis_Set("jr",Z80_Dis_Printf("%s",p)); + else + Z80_Dis_Set("jr",Z80_Dis_Printf("$%.4x",new)); } static void DIS_RRA (Z80 *z80, Z80Byte op, Z80Word *pc) @@ -1436,20 +1487,29 @@ static void DIS_JR_CO (Z80 *z80, Z80Byte op, Z80Word *pc) { const char *con; Z80Word new; + const char *p; con=z80_dis_condition[(op-0x20)/8]; new=*pc+(Z80Relative)z80->memory[*pc]+1; (*pc)++; - Z80_Dis_Set("jr",Z80_Dis_Printf("%s,$%.4x",con,new)); + if ((p=GetLabel(new))) + Z80_Dis_Set("jr",Z80_Dis_Printf("%s,%s",con,p)); + else + Z80_Dis_Set("jr",Z80_Dis_Printf("%s,$%.4x",con,new)); } static void DIS_LD_ADDR_HL (Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),hl",w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("(%s),hl",p)); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),hl",w)); } static void DIS_DAA (Z80 *z80, Z80Byte op, Z80Word *pc) @@ -1460,9 +1520,14 @@ static void DIS_DAA (Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_LD_HL_ADDR (Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("hl,($%.4x)",w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("hl,(%s)",p)); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("hl,($%.4x)",w)); } static void DIS_CPL (Z80 *z80, Z80Byte op, Z80Word *pc) @@ -1473,9 +1538,14 @@ static void DIS_CPL (Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_LD_ADDR_A (Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),a",w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("(%s),a",p)); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("($%.4x),a",w)); } static void DIS_SCF (Z80 *z80, Z80Byte op, Z80Word *pc) @@ -1486,9 +1556,14 @@ static void DIS_SCF (Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_LD_A_ADDR (Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("ld",Z80_Dis_Printf("a,($%.4x)",w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("ld",Z80_Dis_Printf("a,(%s)",p)); + else + Z80_Dis_Set("ld",Z80_Dis_Printf("a,($%.4x)",w)); } static void DIS_CCF (Z80 *z80, Z80Byte op, Z80Word *pc) @@ -1598,9 +1673,14 @@ static void DIS_POP_R16 (Z80 *z80, Z80Byte op, Z80Word *pc) static void DIS_JP (Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("jp",Z80_Dis_Printf("$%.4x",w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("jp",Z80_Dis_Printf("%s",p)); + else + Z80_Dis_Set("jp",Z80_Dis_Printf("$%.4x",w)); } static void DIS_PUSH_R16 (Z80 *z80, Z80Byte op, Z80Word *pc) @@ -1637,10 +1717,15 @@ static void DIS_JP_CO (Z80 *z80, Z80Byte op, Z80Word *pc) { const char *con; Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); con=z80_dis_condition[(op-0xc0)/8]; - Z80_Dis_Set("jp",Z80_Dis_Printf("%s,$%.4x",con,w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("jp",Z80_Dis_Printf("%s,%s",con,p)); + else + Z80_Dis_Set("jp",Z80_Dis_Printf("%s,$%.4x",con,w)); } static void DIS_CB_DECODE (Z80 *z80, Z80Byte op, Z80Word *pc) @@ -1655,18 +1740,28 @@ static void DIS_CALL_CO (Z80 *z80, Z80Byte op, Z80Word *pc) { const char *con; Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); con=z80_dis_condition[(op-0xc0)/8]; - Z80_Dis_Set("call",Z80_Dis_Printf("%s,$%.4x",con,w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("call",Z80_Dis_Printf("%s,%s",con,p)); + else + Z80_Dis_Set("call",Z80_Dis_Printf("%s,$%.4x",con,w)); } static void DIS_CALL (Z80 *z80, Z80Byte op, Z80Word *pc) { Z80Word w; + const char *p; w=Z80_Dis_FetchWord(z80,pc); - Z80_Dis_Set("call",Z80_Dis_Printf("$%.4x",w)); + + if ((p=GetLabel(w))) + Z80_Dis_Set("call",Z80_Dis_Printf("%s",p)); + else + Z80_Dis_Set("call",Z80_Dis_Printf("$%.4x",w)); } static void DIS_ADC_A_BYTE (Z80 *z80, Z80Byte op, Z80Word *pc) |