Annotation of generator/main/cpuz80-mz80.c, revision 1.1.1.4

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.