|
|
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: #include "raze.h" ! 13: ! 14: /*** variables externed ***/ ! 15: ! 16: uint8 *cpuz80_ram = NULL; ! 17: uint32 cpuz80_bank = 0; ! 18: unsigned int cpuz80_active = 0; ! 19: unsigned int cpuz80_pending = 0; ! 20: ! 21: /*** global variables ***/ ! 22: ! 23: static unsigned int cpuz80_lastsync = 0; ! 24: static unsigned int cpuz80_resetting = 0; ! 25: ! 26: int cpuz80_init(void) ! 27: { ! 28: int i; ! 29: ! 30: cpuz80_reset(); ! 31: return 0; ! 32: } ! 33: ! 34: /*** cpuz80_reset - reset z80 sub-unit ***/ ! 35: ! 36: void cpuz80_reset(void) ! 37: { ! 38: int i; ! 39: ! 40: if (!cpuz80_ram) { ! 41: if ((cpuz80_ram = malloc(LEN_SRAM)) == NULL) { ! 42: fprintf(stderr, "Out of memory\n"); ! 43: exit(1); ! 44: } ! 45: } ! 46: memset(cpuz80_ram, 0, LEN_SRAM); ! 47: cpuz80_bank = 0; ! 48: cpuz80_active = 0; ! 49: cpuz80_lastsync = 0; ! 50: cpuz80_resetting = 1; ! 51: z80_init_memmap(); ! 52: z80_map_fetch(0x0000, 0x3fff, cpuz80_ram); ! 53: z80_map_fetch(0x4000, 0x7fff, cpuz80_ram); /* ok? */ ! 54: z80_map_fetch(0x8000, 0xbfff, cpuz80_ram); /* ok? */ ! 55: z80_map_fetch(0xc000, 0xffff, cpuz80_ram); /* ok? */ ! 56: z80_add_read( 0x000, 0x3fff, Z80_MAP_DIRECT, cpuz80_ram); ! 57: z80_add_write(0x000, 0x3fff, Z80_MAP_DIRECT, cpuz80_ram); ! 58: for (i = 1; (memz80_def[i].start != 0) || (memz80_def[i].end != 0); i++) { ! 59: z80_add_read(memz80_def[i].start << 8, (memz80_def[i].end << 8) - 1, ! 60: Z80_MAP_HANDLED, memz80_def[i].fetch_byte); ! 61: z80_add_write(memz80_def[i].start << 8, (memz80_def[i].end << 8) - 1, ! 62: Z80_MAP_HANDLED, memz80_def[i].store_byte); ! 63: } ! 64: z80_end_memmap(); ! 65: z80_reset(); ! 66: } ! 67: ! 68: /*** cpuz80_updatecontext - inform z80 processor of changed context ***/ ! 69: ! 70: void cpuz80_updatecontext(void) ! 71: { ! 72: /* not required with raze */ ! 73: } ! 74: ! 75: /*** cpuz80_resetcpu - reset z80 cpu ***/ ! 76: ! 77: void cpuz80_resetcpu(void) ! 78: { ! 79: cpuz80_sync(); ! 80: z80_reset(); ! 81: cpuz80_resetting = 1; /* suspends execution */ ! 82: } ! 83: ! 84: /*** cpuz80_unresetcpu - unreset z80 cpu ***/ ! 85: ! 86: void cpuz80_unresetcpu(void) ! 87: { ! 88: if (cpuz80_resetting) ! 89: cpuz80_sync(); ! 90: cpuz80_resetting = 0; /* un-suspends execution */ ! 91: } ! 92: ! 93: /*** cpuz80_bankwrite - data is being written to latch ***/ ! 94: ! 95: void cpuz80_bankwrite(uint8 data) ! 96: { ! 97: cpuz80_bank = (((cpuz80_bank >> 1) | ((data & 1) <<23)) & 0xff8000); ! 98: } ! 99: ! 100: /*** cpuz80_stop - stop the processor ***/ ! 101: ! 102: void cpuz80_stop(void) ! 103: { ! 104: cpuz80_sync(); ! 105: cpuz80_active = 0; ! 106: } ! 107: ! 108: /*** cpuz80_start - start the processor ***/ ! 109: ! 110: void cpuz80_start(void) ! 111: { ! 112: if (!cpuz80_active) ! 113: cpuz80_sync(); ! 114: cpuz80_active = 1; ! 115: } ! 116: ! 117: /*** cpuz80_endfield - reset counters ***/ ! 118: ! 119: void cpuz80_endfield(void) ! 120: { ! 121: cpuz80_lastsync = 0; ! 122: } ! 123: ! 124: /*** cpuz80_sync - synchronise ***/ ! 125: ! 126: void cpuz80_sync(void) ! 127: { ! 128: int cpu68k_wanted = cpu68k_clocks - cpuz80_lastsync; ! 129: int wanted = (cpu68k_wanted<0?0:cpu68k_wanted)*7/15; ! 130: int acheived; ! 131: ! 132: if (cpuz80_pending && z80_get_reg(Z80_REG_IFF1)) { ! 133: z80_raise_IRQ(0xff); ! 134: z80_lower_IRQ(); ! 135: cpuz80_pending = 0; ! 136: } ! 137: if (cpuz80_active && !cpuz80_resetting) { ! 138: /* ui_log(LOG_USER, "executing %d z80 clocks @ %X", wanted, ! 139: cpuz80_z80.z80pc); */ ! 140: acheived = z80_emulate(wanted); ! 141: cpuz80_lastsync = cpuz80_lastsync + acheived*15/7; ! 142: } else { ! 143: cpuz80_lastsync = cpu68k_clocks; ! 144: } ! 145: } ! 146: ! 147: /*** cpuz80_interrupt - cause an interrupt on the z80 */ ! 148: ! 149: void cpuz80_interrupt(void) ! 150: { ! 151: if (!cpuz80_resetting) { ! 152: if (z80_get_reg(Z80_REG_IFF1) == 0) ! 153: cpuz80_pending = 1; ! 154: z80_raise_IRQ(0xff); ! 155: z80_lower_IRQ(); ! 156: } ! 157: } ! 158: ! 159: void cpuz80_uninterrupt(void) ! 160: { ! 161: z80_lower_IRQ(); ! 162: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.