-
Notifications
You must be signed in to change notification settings - Fork 6
/
Z80Debug.c
58 lines (53 loc) · 1.98 KB
/
Z80Debug.c
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
/*** Z80Em: Portable Z80 emulator *******************************************/
/*** ***/
/*** Z80Debug.c ***/
/*** ***/
/*** This file contains a simple single step debugger which is called ***/
/*** when DEBUG is #defined and Z80_Trace is true ***/
/*** ***/
/*** Copyright (C) Marcel de Kogel 1996,1997 ***/
/*** You are not allowed to distribute this software commercially ***/
/*** Please, notify me, if you make any changes to this file ***/
/****************************************************************************/
#include "Z80.h"
#include <stdio.h>
#include <string.h>
#include "Z80Dasm.h"
//#ifdef DEBUG
void Z80_Debug (Z80_Regs *R)
{
byte buf[5];
char flags[]="SZ.H.VNC";
char S[20],f[9];
int i;
buf[0]=Z80_RDOP(R->PC.D); i=1;
/* Figure out which bytes are opcode arguments and which are not */
switch (buf[0])
{
case 0xCB:
case 0xED:
buf[1]=Z80_RDOP((R->PC.D+1)&0xFFFF); i=2;
break;
case 0xDD:
case 0xFD:
buf[1]=Z80_RDOP((R->PC.D+1)&0xFFFF); i=2;
if (buf[1]==0xCB)
{
buf[2]=Z80_RDOP_ARG((R->PC.D+2)&0xFFFF);
buf[3]=Z80_RDOP((R->PC.D+3)&0xFFFF);
i=4;
}
}
for (;i<5;++i) { buf[i]=Z80_RDOP_ARG((R->PC.D+i)&0xFFFF); }
Z80_Dasm (buf,S,R->PC.D);
for (i=strlen(S);i<19;++i) S[i]=' ';
S[19]='\0';
for (i=7;i>=0;--i) { f[7-i]=(R->AF.D&(1<<i))? flags[7-i]:'.'; }
f[8]='\0';
printf ("%04X: %s AT SP: %04X %04X FLAGS: %s\n",R->PC.D,S,
Z80_RDMEM(R->SP.D)+Z80_RDMEM((R->SP.D+1)&0xFFFF)*256,
Z80_RDMEM((R->SP.D+2)&0xFFFF)+Z80_RDMEM((R->SP.D+3)&0xFFFF)*256,f);
printf ("%27sAF:%04X BC:%04X DE:%04X HL:%04X IX:%04X IY:%04X\n",
"",R->AF.D,R->BC.D,R->DE.D,R->HL.D,R->IX.D,R->IY.D);
}
//#endif