Annotation of generator/extra/cpuz80-mame.c, revision 1.1

1.1     ! root        1: /*****************************************************************************/
        !             2: /*     Generator - Sega Genesis emulation - (c) James Ponder 1997-1998       */
        !             3: /*****************************************************************************/
        !             4: /*                                                                           */
        !             5: /* z80.c                                                                     */
        !             6: /*                                                                           */
        !             7: /*****************************************************************************/
        !             8: 
        !             9: #include <stdlib.h>
        !            10: #include <stdio.h>
        !            11: #include <string.h>
        !            12: 
        !            13: #include <generator.h>
        !            14: #include <cpuz80.h>
        !            15: #include <cpu68k.h>
        !            16: #include <memz80.h>
        !            17: #include <ui.h>
        !            18: 
        !            19: #include <z80/z80.h>
        !            20: 
        !            21: /*** variables externed ***/
        !            22: 
        !            23: uint8 *cpuz80_ram = NULL;
        !            24: uint32 cpuz80_bank = 0;
        !            25: unsigned int cpuz80_active = 0;
        !            26: 
        !            27: /*** global variables ***/
        !            28: 
        !            29: static unsigned int cpuz80_lastsync = 0;
        !            30: static unsigned int cpuz80_resetting = 0;
        !            31: 
        !            32: /*** cpuz80_init - initialise this sub-unit ***/
        !            33: 
        !            34: int cpuz80_init(void)
        !            35: {
        !            36:   cpuz80_reset();
        !            37:   ui_log(LOG_CRITICAL, "z80 init");
        !            38:   return 0;
        !            39: }
        !            40: 
        !            41: /*** cpuz80_callback - callback ***/
        !            42: 
        !            43: int cpuz80_callback(int val) {
        !            44:   (void)val;
        !            45:   return 0;
        !            46: }
        !            47: 
        !            48: /*** cpuz80_reset - reset z80 sub-unit ***/
        !            49: 
        !            50: void cpuz80_reset(void)
        !            51: {
        !            52:   if (!cpuz80_ram) {
        !            53:     if ((cpuz80_ram = malloc(LEN_SRAM)) == NULL) {
        !            54:       fprintf(stderr, "Out of memory\n");
        !            55:       exit(1);
        !            56:     }
        !            57:   }
        !            58:   memset(cpuz80_ram, 0, LEN_SRAM);
        !            59:   cpuz80_resetcpu();
        !            60:   cpuz80_bank = 0;
        !            61:   cpuz80_active = 0;
        !            62:   cpuz80_lastsync = 0;
        !            63:   cpuz80_resetting = 0;
        !            64:   z80_reset(NULL);
        !            65:   z80_set_irq_callback(cpuz80_callback);
        !            66: }
        !            67: 
        !            68: /*** cpuz80_resetcpu - reset z80 cpu ***/
        !            69: 
        !            70: void cpuz80_resetcpu(void)
        !            71: {
        !            72:   z80_reset(NULL);
        !            73:   z80_set_irq_callback(cpuz80_callback);
        !            74:   cpuz80_resetting = 1; /* suspends execution */
        !            75: }
        !            76: 
        !            77: /*** cpuz80_unresetcpu - unreset z80 cpu ***/
        !            78: 
        !            79: void cpuz80_unresetcpu(void)
        !            80: {
        !            81:   cpuz80_resetting = 0; /* un-suspends execution */
        !            82: }
        !            83: 
        !            84: /*** cpuz80_bankwrite - data is being written to latch ***/
        !            85: 
        !            86: void cpuz80_bankwrite(uint8 data)
        !            87: {
        !            88:   cpuz80_bank  = (((cpuz80_bank >> 1) | ((data & 1) <<23)) & 0xff8000);
        !            89:   /*
        !            90:   if (gen_debug)
        !            91:     printf("BANK WRITE: %d --> %08X\n", data, cpuz80_bank);
        !            92:   */
        !            93: }
        !            94: 
        !            95: /*** cpuz80_stop - stop the processor ***/
        !            96: 
        !            97: void cpuz80_stop(void)
        !            98: {
        !            99:   cpuz80_sync();
        !           100:   cpuz80_active = 0;
        !           101: }
        !           102: 
        !           103: /*** cpuz80_start - start the processor ***/
        !           104: 
        !           105: void cpuz80_start(void)
        !           106: {
        !           107:   cpuz80_sync();
        !           108:   cpuz80_active = 1;
        !           109: }
        !           110: 
        !           111: /*** cpuz80_endfield - reset counters ***/
        !           112: 
        !           113: void cpuz80_endfield(void)
        !           114: {
        !           115:   cpuz80_lastsync = 0;
        !           116: }
        !           117: 
        !           118: /*** cpuz80_sync - synchronise ***/
        !           119: 
        !           120: void cpuz80_sync(void)
        !           121: {
        !           122:   int cpu68k_wanted = cpu68k_clocks - cpuz80_lastsync;
        !           123:   int wanted = (cpu68k_wanted<0?0:cpu68k_wanted)*7/16;
        !           124:   int acheived;
        !           125: 
        !           126:   if (cpuz80_active && !cpuz80_resetting)
        !           127:     acheived = z80_execute(wanted);
        !           128:   cpuz80_lastsync = cpu68k_clocks;
        !           129: }
        !           130: 
        !           131: /*** cpuz80_interrupt - cause an interrupt on the z80 */
        !           132: 
        !           133: void cpuz80_interrupt(void)
        !           134: {
        !           135:   if (!cpuz80_resetting)
        !           136:     z80_set_irq_line(0, 1);
        !           137: }
        !           138: 
        !           139: /*** cpuz80_portread - port read from z80 */
        !           140: 
        !           141: uint8 cpuz80_portread(uint8 port)
        !           142: {
        !           143:   printf("[Z80] Port read to %X\n", port);
        !           144:   return 0;
        !           145: }
        !           146: 
        !           147: /*** cpuz80_portwrite - z80 write to port */
        !           148: 
        !           149: void cpuz80_portwrite(uint8 port, uint8 value)
        !           150: {
        !           151:   printf("[Z80] Port write to %X of %X\n", port, value);
        !           152: }

unix.superglobalmegacorp.com

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