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