1 /* Emulation of the Z80 CPU with hooks into the other parts of Z81.
2 * Copyright (C) 1994 Ian Collier.
3 * Z81 changes (C) 1995 Russell Marks.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include "parse_map.h"
31 unsigned short breakpoints
[5];
32 unsigned short callback_stack
[100];
34 int callback_stack_pos
;
35 extern unsigned long tstates
;
37 void push_callback( unsigned short addr
)
43 while ((walk
!=NULL
)&&(!done
)) {
44 if (walk
->addr
==addr
) {
45 walk
->start
= tstates
;
55 fun_first
=malloc(sizeof(mfunction
));
57 fun_first
->num_calls
=1;
60 fun_first
->start
=tstates
;
62 callback_stack
[callback_stack_pos
++] = addr
;
65 void pop_callback(void)
69 if (callback_stack_pos
> 0) {
73 if (walk
->addr
==callback_stack
[callback_stack_pos
]) {
74 walk
->tstates
+=tstates
- walk
->start
;
83 int mainloop(int flags
)
85 unsigned char a
, f
, b
, c
, d
, e
, h
, l
;
86 unsigned char r
, i
, iff1
, iff2
, im
;
89 extern unsigned long tstates
;
91 unsigned char intsample
;
93 int states_until_timerint
;
94 unsigned long last_tstates
;
95 unsigned startTime
= tstates
;
97 clock_t max_run_time
= clock() + CLOCKS_PER_SEC
*30;
98 unsigned run_time_check_mod
= 0;
104 &a
, &f
, &b
, &c
, &d
, &e
, &h
, &l
, &pc
, &sp
, &cpuRunning
106 a
= f
= b
= c
= d
= e
= h
= l
= i
= r
= iff1
= iff2
= im
= 0;
110 pc
= 0x100; /* GB start address */
113 callback_stack_pos
= 0;
114 states_until_timerint
= 40000;
116 for (j
= 0; j
< 5; j
++)
119 if (flags
&DSTARTDEBUG
)
120 breakpoints
[0] = 0x100;
124 if (enterDebugger(®s
))
131 if (breakpoints
[j
] == pc
) {
132 if (enterDebugger(®s
))
143 printf("\nrrgb: warning - invalid opcode %02x at %04x.\n", op
, pc
- 1);
144 enterDebugger(®s
);
147 if (flags
&DTIMERINT
) {
148 states_until_timerint
-=tstates
-last_tstates
;
149 last_tstates
=tstates
;
150 if (states_until_timerint
<0) {
151 states_until_timerint
=40000;
156 if (flags
&DLIMITEDRUN
&& (++run_time_check_mod
) == 100) {
157 if (clock() > max_run_time
) {
158 printf("Error: Maximum runtime exceeded\n");
161 run_time_check_mod
= 0;