-
Notifications
You must be signed in to change notification settings - Fork 0
/
debugger.cpp
184 lines (129 loc) · 3.33 KB
/
debugger.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#include "debugger.h"
#include <stdio.h>
#include <string.h>
#include "memio.h"
static int32_t dbgLeave( debugCtx_t *ctx )
{
//do not call debugger in main loop
ctx->tgCtx->debuggerActive = 0;
//restore videomux
storeData( 0xf0000008, 3, ctx->tgVMMode );
return 0;
}
int32_t dbgInit( debugCtx_t *ctx, tangerineCtx_t *tgCtx )
{
int32_t rv;
if( ctx == NULL )
{
return 1;
}
if( tgCtx == NULL )
{
return 1;
}
ctx->tgCtx = tgCtx;
rv = conInit( tgCtx, &ctx->con );
ctx->dsCtx.codeBufIdx = 0;
ctx->dsCtx.codeBufStartPc = 0;
ctx->tgVMMode = 0;
return rv;
}
static int32_t dbgDumpRegisters( debugCtx_t *ctx )
{
char buf[256];
uint32_t i;
ctx->con.textAttributes = 0x8f;
conSetCursorPos( &ctx->con, 0, 0 );
conPrintF( &ctx->con, (char*)"PC:%08x", ctx->tgCtx->cpuctx.pc );
for( i = 1; i < 32; i++ )
{
conSetCursorPos( &ctx->con, ( i % 6 ) * 13, i / 6 );
nameRegister( i, buf );
conPrintF( &ctx->con, (char*)"%s:%08x", buf, ctx->tgCtx->cpuctx.regs[i] );
}
return 0;
}
static int32_t dbgDisassemble( debugCtx_t *ctx )
{
char buf[256];
uint32_t i;
conSetCursorPos( &ctx->con, 0, 7 );
ctx->dsCtx.codeBufIdx = -11;
for( i = 0; i < 22; i++ )
{
dsDisassemble( &ctx->dsCtx, buf );
if( ctx->dsCtx.codeBufIdx == 0 )
{
ctx->con.textAttributes = 0x8c;
}
else
{
ctx->con.textAttributes = 0x8f;
}
conPrintF( &ctx->con, (char*)"%08x %s\n", ( ctx->dsCtx.codeBufStartPc + ctx->dsCtx.codeBufIdx * 4 ), buf );
ctx->dsCtx.codeBufIdx++;
}
return 0;
}
static int32_t dbgMenu( debugCtx_t *ctx )
{
conSetCursorPos( &ctx->con, 0, 29 );
ctx->con.textAttributes = 0x2f;
conPrintF( &ctx->con, (char*)"SPACE" );
ctx->con.textAttributes = 0x8f;
conPrintF( &ctx->con, (char*)" - step " );
ctx->con.textAttributes = 0x2f;
conPrintF( &ctx->con, (char*)"ENTER" );
ctx->con.textAttributes = 0x8f;
conPrintF( &ctx->con, (char*)" - run" );
return 0;
}
int32_t dbgMain( debugCtx_t *ctx )
{
SDL_Event event;
if( ctx->tgCtx->debuggerActive == 0 )
{
return 0;
}
if( ctx->tgCtx->debuggerActive == 1 )
{
//init debugger screen
//save videoMux mode
ctx->tgVMMode = fetchData( 0xf0000008 ); //videoMux reg
//set videoMux to text 80x60, over gfx
storeData( 0xf0000008, 3, ( ctx->tgVMMode & 0xf0 ) | 0x0e );
ctx->tgCtx->debuggerActive = 2;
}
ctx->con.textAttributes = 0x0f;
conCls( &ctx->con );
dbgDumpRegisters( ctx );
ctx->dsCtx.codeBufStartPc = ctx->tgCtx->cpuctx.pc;
dbgDisassemble( ctx );
dbgMenu( ctx );
if( SDL_PollEvent( &event ) )
{
if( event.type == SDL_QUIT )
{
return RV_QUIT;
}else if( event.type == SDL_KEYDOWN )
{
switch( event.key.keysym.sym )
{
case SDLK_SPACE:
rvStep( &ctx->tgCtx->cpuctx );
break;
case SDLK_ESCAPE:
case SDLK_RETURN:
dbgLeave( ctx );
break;
}
//check if F12 pressed ( to invoke debugger )
/* if( event.key.keysym.sym == SDLK_F12 )
{
ctx->debuggerActive = 1;
}
*/
}
}
return 0;
}