File: breakpoint.c

package info (click to toggle)
xzx 2.9.0-1
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 1,644 kB
  • ctags: 2,195
  • sloc: ansic: 25,375; sh: 1,937; yacc: 714; makefile: 197; lex: 107
file content (128 lines) | stat: -rw-r--r-- 3,510 bytes parent folder | download
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
/********************************************************************************
* Copyright (c) Erik Kunze 1999
*
* The archive is a part of the registered Spectrum emulator package 'XZX',
* and may not be distributed.  The copyright holder makes no representations
* about the suitability of this software for any purpose.  It is provided "as
* is" without express or implied warranty. THE CODE MAY NOT BE MODIFIED OR
* REUSED WITHOUT PERMISSION!
*
* THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*
* Author: Erik Kunze
*******************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
static char rcsid[] = "$Id: breakpoint.c,v 1.2 1999/01/14 16:54:34 erik Rel $";
#include <stdio.h>
#include <assert.h>
#include "mem.h"
#include "util.h"
#include "dis.h"
#include "breakpoint.h"
static int bpCompare(void *, void *);
static Llist *breakpointList = (Llist *)0;
static unsigned int breakpointCount = 0;
unsigned int
BpSet(int page, uns16 addr)
{
Breakpoint *bpp;
unsigned int bpno;
uns8 opcode[4];
int bytes, address;
if ((bpno = BpLookup(page, addr)) != -1U)
{
return -1U;
}
bpp = (Breakpoint *)Malloc(sizeof(Breakpoint), "BpSet");
breakpointList = AppendElemList(breakpointList, (void *)bpp);
breakpointCount++;
bpp->page = page;
bpp->addr = addr;
address = addr;
for (bytes = 0; bytes < 4 && address <= 0x3fff; bytes++, address++)
{
opcode[bytes] = RealMemory[page][address];
}
bytes = Disassemble2(bpp->opstr, opcode, addr);
if ((int)addr + bytes > 0x3fff)
{
bpp->opstr[0] = '?';
bpp->opstr[1] = '\0';
}
bpp->opcode = RealMemory[page][addr];
RealMemory[page][addr] = 0xc7;
return (breakpointCount - 1);
}
void
BpUnset(unsigned int bpno)
{
Breakpoint *bpp;
bpp = (Breakpoint *)RetrieveElemList(breakpointList, bpno);
assert(bpp != (Breakpoint *)0);
RealMemory[bpp->page][bpp->addr] = bpp->opcode;
breakpointList = RemoveElemList(bpp, bpCompare, breakpointList, NULL);
breakpointCount--;
}
unsigned int
BpUnsetAll(void)
{
unsigned int bpno;
for (bpno = 0; bpno < breakpointCount; bpno++)
{
BpUnset(bpno);
}
return bpno;
}
void
BpDestroy(unsigned int bpno)
{
Breakpoint *bpp;
bpp = (Breakpoint *)RetrieveElemList(breakpointList, bpno);
assert(bpp != (Breakpoint *)0);
breakpointList = RemoveElemList(bpp, bpCompare, breakpointList, NULL);
breakpointCount--;
}
unsigned int
BpDestroyAll(void)
{
unsigned int bpno = breakpointCount;
DestroyList(breakpointList, NULL);
breakpointList = (Llist *)0;
breakpointCount = 0;
return bpno;
}
Breakpoint *
BpRetrieve(unsigned int bpno)
{
return ((Breakpoint *)RetrieveElemList(breakpointList, bpno));
}
unsigned int
BpLookup(int page, uns16 addr)
{
Breakpoint *bp;
unsigned int bpno;
for (bpno = 0; bpno < breakpointCount; bpno++)
{
bp = (Breakpoint *)RetrieveElemList(breakpointList, bpno);
assert(bp != (Breakpoint *)0);
if (bp->page == page && bp->addr == addr)
{
return bpno;
}
}
return -1U;
}
static int
bpCompare(void *bpp1, void *bpp2)
{
return (!(((Breakpoint *)bpp1)->page == ((Breakpoint *)bpp2)->page
&& ((Breakpoint *)bpp1)->addr == ((Breakpoint *)bpp2)->addr));
}