Beispiel #1
0
char* Z80_disassemble(_u16* pc_in)
{
	int bcnt, i;
	_u16 pc = *pc_in;
	char instr[64];	//Print the disassembled instruction to this string
	_u8 str[80];
	memset(str, 0, 80);
	
	//Add the program counter
	sprintf(str, "<z80> %03X: ", pc);

	//Disassemble instruction
    bcnt = DAsm(instr,ram + 0x7000 + pc);

	//Add the instruction
	strcat(str, instr);

	//Add the bytes used
	for (i = strlen(str); i < 32; i++)
		str[i] = ' ';
	str[32] = '\"';
	for (i = 0; i < bcnt; i++)
	{
		_u8 tmp[80];
		sprintf(tmp, "%02X ", *(ram + 0x7000 + pc + i));
		strcat(str, tmp);
	}
	str[strlen(str) - 1] = '\"';

	*pc_in = pc + bcnt;
	return strdup(str);
}
Beispiel #2
0
byte DebugZ80(Z80 *R)
{
  static char Flags[9] = "SZ.H.PNC";
  char S[128],T[10];
  byte J,I;

  DAsm(S,R->PC.W);
  for(J=0,I=R->AF.B.l;J<8;J++,I<<=1) T[J]=I&0x80? Flags[J]:'.';
  T[8]='\0';

  printf
  (
    "AF:%04X HL:%04X DE:%04X BC:%04X PC:%04X SP:%04X IX:%04X IY:%04X I:%02X\n",
    R->AF.W,R->HL.W,R->DE.W,R->BC.W,R->PC.W,R->SP.W,R->IX.W,R->IY.W,R->I
  ); 
  printf
  ( 
    "AT PC: [%02X - %s]   AT SP: [%04X]   FLAGS: [%s]   %s: %s\n\n",
    RdZ80(R->PC.W),S,RdZ80(R->SP.W)+RdZ80(R->SP.W+1)*256,T,
    R->IFF&0x04? "IM2":R->IFF&0x02? "IM1":"IM0",
    R->IFF&0x01? "EI":"DI"
  );

  while(1)
  {
    printf("\n[Command,'?']-> ");
    fflush(stdout);fflush(stdin);

    fgets(S,50,stdin);
    for(J=0;S[J]>=' ';J++)
      S[J]=toupper(S[J]);
    S[J]='\0';

    switch(S[0])
    {
      case 'H':
      case '?':
        puts("\n***** Built-in Z80 Debugger Commands *****");
        puts("<CR>       : Break at next instruction");
        puts("= <addr>   : Break at addr");
        puts("+ <offset> : Break at PC + offset");
        puts("c          : Continue without break");
        puts("j <addr>   : Continue from addr");
        puts("m <addr>   : Memory dump at addr");
        puts("d <addr>   : Disassembly at addr");
        puts("?,h        : Show this help text");
        puts("q          : Exit Z80 emulation");
        break;

      case '\0': return(1);
      case '=':  if(strlen(S)>=2)
                 { sscanf(S+1,"%hX",&(R->Trap));R->Trace=0;return(1); }
                 break;
      case '+':  if(strlen(S)>=2)
                 {
                   sscanf(S+1,"%hX",&(R->Trap));
                   R->Trap+=R->PC.W;R->Trace=0;
                   return(1);
                 }
                 break;
      case 'J':  if(strlen(S)>=2)
                 { sscanf(S+1,"%hX",&(R->PC.W));R->Trace=0;return(1); }
                 break;
      case 'C':  R->Trap=0xFFFF;R->Trace=0;return(1); 
      case 'Q':  return(0);

      case 'M':
        {
          word Addr;

          if(strlen(S)>1) sscanf(S+1,"%hX",&Addr); else Addr=R->PC.W;
          puts("");
          for(J=0;J<16;J++)
          {
            printf("%04X: ",Addr);
            for(I=0;I<16;I++,Addr++)
              printf("%02X ",RdZ80(Addr));
            printf(" | ");Addr-=16;
            for(I=0;I<16;I++,Addr++)
              putchar(isprint(RdZ80(Addr))? RdZ80(Addr):'.');
            puts("");
          }
        }
        break;

      case 'D':
        {
          word Addr;

          if(strlen(S)>1) sscanf(S+1,"%hX",&Addr); else Addr=R->PC.W;
          puts("");
          for(J=0;J<16;J++)
          {
            printf("%04X: ",Addr);
            Addr+=DAsm(S,Addr);
            puts(S);
          }
        }
        break;
    }
  }

  /* Continue emulation */
  return(1);
}