-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdebugasm.c
115 lines (106 loc) · 3.78 KB
/
debugasm.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
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
/*
* Copyright (C) 1997-2008 ZSNES Team ( zsKnight, _Demo_, pagefault, Nach )
*
* http://www.zsnes.com
* http://sourceforge.net/projects/zsnes
* https://zsnes.bountysource.com
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef NCURSES
#include <curses.h>
#else
#include <ncurses.h>
#endif
#include "cpu/c_65816d.h"
#include "cpu/c_memory.h"
#include "cpu/execute.h"
#include "cpu/memory.h"
#include "cpu/memtable.h"
#include "cpu/regs.h"
#include "cpu/spc700.h"
#include "debugasm.h"
#include "debugger.h"
#include "endmem.h"
#include "init.h"
#include "initc.h"
#include "types.h"
void breakops(void)
{
u4 const page = PrevBreakPt_page;
u4 const offset = PrevBreakPt_offset;
u1 const* const map = offset & 0x8000 ? snesmmap[page] : snesmap2[page];
u1 const* const breakarea = map + offset; // add program counter to address
u4 const pc = xpc;
u4 const pb = xpb;
u1* const addr = pc & 0x8000 ? snesmmap[pb] : pc < 0x4300 || memtabler8[pb] != regaccessbankr8 ? snesmap2[pb]
: (u1*)dmadata - 0x4300; // XXX ugly cast
initaddrl = addr;
u4 ecx = 0;
u4 edx = curcyc /* cycles */ << 8 | xp /* flags */;
u1* ebp = spcPCRam;
u1* esi = addr + pc; // add program counter to address
eop** edi = Curtableaddr;
UpdateDPage();
// execute
do {
splitflags(edx);
u4 ebx;
// XXX hack: GCC cannot handle ebp as input/output, so take the detour over eax
asm volatile("push %%ebp; mov %0, %%ebp; call %P6; mov %%ebp, %0; pop %%ebp"
: "+a"(ebp), "+c"(ecx), "+d"(edx), "=b"(ebx), "+S"(esi), "+D"(edi)
: "X"(execsingle)
: "cc", "memory");
edx = joinflags(edx);
edx = edx & 0xFFFF00FF | pdh << 8;
if ((++numinst & 0xFF) == 0 && getch() == 27)
break;
} while (esi != breakarea);
// copy back data
spcPCRam = ebp;
Curtableaddr = edi;
xp = edx;
curcyc = edx >> 8;
xpc = esi - initaddrl; // subtract program counter by address
}
void execnextop(void)
{
u4 const pc = xpc;
u4 const pb = xpb;
u1* const addr = pc & 0x8000 ? snesmmap[pb] : pc < 0x4300 || memtabler8[pb] != regaccessbankr8 ? snesmap2[pb]
: (u1*)dmadata - 0x4300; // XXX ugly cast
initaddrl = addr;
u4 ecx = 0;
u4 edx = curcyc /* cycles */ << 8 | xp /* flags */;
u1* ebp = spcPCRam;
u1* esi = addr + pc; // add program counter to address
eop** edi = Curtableaddr;
// execute
splitflags(edx);
u4 ebx;
// XXX hack: GCC cannot handle ebp as input/output, so take the detour over eax
asm volatile("push %%ebp; mov %0, %%ebp; call %P6; mov %%ebp, %0; pop %%ebp"
: "+a"(ebp), "+c"(ecx), "+d"(edx), "=b"(ebx), "+S"(esi), "+D"(edi)
: "X"(execsingle)
: "cc", "memory");
edx = joinflags(edx);
UpdateDPage();
// copy back data
spcPCRam = ebp;
Curtableaddr = edi;
xp = edx;
curcyc = pdh;
xpc = esi - initaddrl; // subtract program counter by address
++numinst;
}