|
|
1.1 root 1: /* Generator is (c) James Ponder, 1997-2001 http://www.squish.net/generator/ */
2:
3: #include <stdlib.h>
4: #include <stdio.h>
5: #include <string.h>
6:
7: #include "cpuz80.h"
8: #include "cpu68k.h"
9: #include "memz80.h"
10: #include "ui.h"
11:
12: UINT8 cpuz80_read_actual(UINT32 addr, struct MemoryReadByte *me);
13: void cpuz80_write_actual(UINT32 addr, UINT8 data, struct MemoryWriteByte *me);
14: UINT16 cpuz80_ioread_actual(UINT16 addr, struct z80PortRead *me);
15: void cpuz80_iowrite_actual(UINT16 addr, UINT8 data, struct z80PortWrite *me);
16:
17: /*** variables externed ***/
18:
19: uint8 *cpuz80_ram = NULL;
20: uint32 cpuz80_bank = 0;
21: unsigned int cpuz80_active = 0;
22: CONTEXTMZ80 cpuz80_z80;
23:
24: /*** global variables ***/
25:
26: static unsigned int cpuz80_lastsync = 0;
27: static unsigned int cpuz80_resetting = 0;
28:
29: static struct MemoryReadByte cpuz80_read[] = {
30: { 0x0000, 0xFFFF, cpuz80_read_actual, NULL },
31: { -1, -1, NULL, NULL }
32: };
33:
34: static struct MemoryWriteByte cpuz80_write[] = {
35: { 0x0000, 0xFFFF, cpuz80_write_actual, NULL },
36: { -1, -1, NULL, NULL }
37: };
38:
39: static struct z80PortRead cpuz80_ioread[] = {
40: { 0x0000, 0x00FF, cpuz80_ioread_actual, NULL },
41: { -1, -1, NULL, NULL }
42: };
43:
44: static struct z80PortWrite cpuz80_iowrite[] = {
45: { 0x0000, 0x00FF, cpuz80_iowrite_actual, NULL },
46: { -1, -1, NULL, NULL }
47: };
48:
49: UINT8 cpuz80_read_actual(UINT32 addr, struct MemoryReadByte *me)
50: {
51: (void)me;
52: return memz80_fetchbyte((uint16)addr);
53: }
54:
55: void cpuz80_write_actual(UINT32 addr, UINT8 data, struct MemoryWriteByte *me)
56: {
57: (void)me;
58: memz80_storebyte((uint16)addr, (uint8)data);
59: }
60:
61: UINT16 cpuz80_ioread_actual(UINT16 addr, struct z80PortRead *me)
62: {
63: (void)me;
64: return cpuz80_portread((uint16)addr);
65: }
66:
67: void cpuz80_iowrite_actual(UINT16 addr, UINT8 data, struct z80PortWrite *me)
68: {
69: (void)me;
70: cpuz80_portwrite((uint16)addr, (uint8)data);
71: }
72:
73: /*** cpuz80_init - initialise this sub-unit ***/
74:
75: int cpuz80_init(void)
76: {
77: /* mz80init(); - comment in this line if you use assembler z80 */
78: cpuz80_reset();
79: return 0;
80: }
81:
82: /*** cpuz80_reset - reset z80 sub-unit ***/
83:
84: void cpuz80_reset(void)
85: {
86: if (!cpuz80_ram) {
87: if ((cpuz80_ram = malloc(LEN_SRAM)) == NULL) {
88: fprintf(stderr, "Out of memory\n");
89: exit(1);
90: }
91: }
92: memset(cpuz80_ram, 0, LEN_SRAM);
93: cpuz80_bank = 0;
94: cpuz80_active = 0;
95: cpuz80_lastsync = 0;
96: cpuz80_resetting = 1;
97: memset(&cpuz80_z80, 0, sizeof(cpuz80_z80));
98: cpuz80_z80.z80Base = cpuz80_ram;
99: cpuz80_z80.z80MemRead = cpuz80_read;
100: cpuz80_z80.z80MemWrite = cpuz80_write;
101: cpuz80_z80.z80IoRead = cpuz80_ioread;
102: cpuz80_z80.z80IoWrite = cpuz80_iowrite;
103: mz80SetContext(&cpuz80_z80);
104: mz80reset();
105: }
106:
107: /*** cpuz80_updatecontext - inform z80 processor of changed context ***/
108:
109: void cpuz80_updatecontext(void)
110: {
111: mz80SetContext(&cpuz80_z80);
112: }
113:
114: /*** cpuz80_resetcpu - reset z80 cpu ***/
115:
116: void cpuz80_resetcpu(void)
117: {
118: mz80reset();
119: cpuz80_resetting = 1; /* suspends execution */
120: }
121:
122: /*** cpuz80_unresetcpu - unreset z80 cpu ***/
123:
124: void cpuz80_unresetcpu(void)
125: {
126: cpuz80_resetting = 0; /* un-suspends execution */
127: }
128:
129: /*** cpuz80_bankwrite - data is being written to latch ***/
130:
131: void cpuz80_bankwrite(uint8 data)
132: {
133: cpuz80_bank = (((cpuz80_bank >> 1) | ((data & 1) <<23)) & 0xff8000);
134: }
135:
136: /*** cpuz80_stop - stop the processor ***/
137:
138: void cpuz80_stop(void)
139: {
140: cpuz80_sync();
141: cpuz80_active = 0;
142: }
143:
144: /*** cpuz80_start - start the processor ***/
145:
146: void cpuz80_start(void)
147: {
148: cpuz80_sync();
149: cpuz80_active = 1;
150: }
151:
152: /*** cpuz80_endfield - reset counters ***/
153:
154: void cpuz80_endfield(void)
155: {
156: cpuz80_lastsync = 0;
157: }
158:
159: /*** cpuz80_sync - synchronise ***/
160:
161: void cpuz80_sync(void)
162: {
163: int cpu68k_wanted = cpu68k_clocks - cpuz80_lastsync;
164: int wanted = (cpu68k_wanted<0?0:cpu68k_wanted)*7/15;
165: int acheived;
166:
167: if (cpuz80_active && !cpuz80_resetting) {
168: /* ui_log(LOG_USER, "executing %d z80 clocks @ %X", wanted,
169: cpuz80_z80.z80pc); */
170: mz80exec(wanted);
171: acheived = mz80GetElapsedTicks(1);
172: cpuz80_lastsync = cpuz80_lastsync + acheived*15/7;
173: } else {
174: cpuz80_lastsync = cpu68k_clocks;
175: }
176: }
177:
178: /*** cpuz80_interrupt - cause an interrupt on the z80 */
179:
180: void cpuz80_interrupt(void)
181: {
182: if (!cpuz80_resetting)
183: mz80int(0);
184: }
185:
186: /*** cpuz80_portread - port read from z80 */
187:
188: uint8 cpuz80_portread(uint8 port)
189: {
190: LOG_VERBOSE(("[Z80] Port read to %X", port));
191: return 0;
192: }
193:
194: /*** cpuz80_portwrite - z80 write to port */
195:
196: void cpuz80_portwrite(uint8 port, uint8 value)
197: {
198: LOG_VERBOSE(("[Z80] Port write to %X of %X", port, value));
199: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.