Annotation of generator/main/memz80.c, revision 1.1

1.1     ! root        1: /* Generator is (c) James Ponder, 1997-2001 http://www.squish.net/generator/ */
        !             2: 
        !             3: #include <stdio.h>
        !             4: 
        !             5: #include "generator.h"
        !             6: #include "mem68k.h"
        !             7: #include "cpuz80.h"
        !             8: #include "memz80.h"
        !             9: #include "gensound.h"
        !            10: #include "gensoundi.h"
        !            11: #include "ui.h"
        !            12: 
        !            13: /*** forward references ***/
        !            14: 
        !            15: uint8 memz80_fetch_bad_byte(uint16 addr);
        !            16: uint8 memz80_fetch_sram_byte(uint16 addr);
        !            17: uint8 memz80_fetch_yam_byte(uint16 addr);
        !            18: uint8 memz80_fetch_bank_byte(uint16 addr);
        !            19: uint8 memz80_fetch_mem_byte(uint16 addr);
        !            20: uint8 memz80_fetch_psg_byte(uint16 addr);
        !            21: 
        !            22: void memz80_store_bad_byte(uint16 addr,  uint8 data);
        !            23: void memz80_store_sram_byte(uint16 addr, uint8 data);
        !            24: void memz80_store_yam_byte(uint16 addr, uint8 data);
        !            25: void memz80_store_bank_byte(uint16 addr, uint8 data);
        !            26: void memz80_store_mem_byte(uint16 addr, uint8 data);
        !            27: void memz80_store_psg_byte(uint16 addr, uint8 data);
        !            28: 
        !            29: /*** file scope variables */
        !            30: 
        !            31: /*** memory map ***/
        !            32: 
        !            33: t_memz80_def memz80_def[] = {
        !            34:   { 0x00, 0x40,  memz80_fetch_sram_byte, memz80_store_sram_byte },
        !            35:   { 0x40, 0x41,  memz80_fetch_yam_byte,  memz80_store_yam_byte },
        !            36:   { 0x41, 0x60,  memz80_fetch_bad_byte,  memz80_store_bad_byte },
        !            37:   { 0x60, 0x70,  memz80_fetch_bank_byte, memz80_store_bank_byte },
        !            38:   { 0x70, 0x7F,  memz80_fetch_bad_byte,  memz80_store_bad_byte },
        !            39:   { 0x7F, 0x80,  memz80_fetch_psg_byte,  memz80_store_psg_byte },
        !            40:   { 0x80, 0x100, memz80_fetch_mem_byte,  memz80_store_mem_byte },
        !            41:   { 0, 0, NULL, NULL }
        !            42: };
        !            43: 
        !            44: uint8 (*memz80_fetch_byte[0x100])(uint16 addr);
        !            45: void (*memz80_store_byte[0x100])(uint16 addr, uint8 data);
        !            46: 
        !            47: /*** initialise memory tables ***/
        !            48: 
        !            49: int memz80_init(void)
        !            50: {
        !            51:   int i = 0;
        !            52:   int j;
        !            53: 
        !            54:   do {
        !            55:     for (j = memz80_def[i].start; j < memz80_def[i].end; j++) {
        !            56:       memz80_fetch_byte[j] = memz80_def[i].fetch_byte;
        !            57:       memz80_store_byte[j] = memz80_def[i].store_byte;
        !            58:     }
        !            59:     i++;
        !            60:   } while ((memz80_def[i].start != 0) || (memz80_def[i].end != 0));
        !            61:   return 0;
        !            62: }
        !            63: 
        !            64: /*** BAD fetch/store ***/
        !            65: 
        !            66: uint8 memz80_fetch_bad_byte(uint16 addr)
        !            67: {
        !            68:   LOG_CRITICAL(("[Z80] Invalid memory fetch (byte) 0x%X", addr));
        !            69:   return 0;
        !            70: }
        !            71: 
        !            72: void memz80_store_bad_byte(uint16 addr, uint8 data)
        !            73: {
        !            74:   LOG_CRITICAL(("[Z80] Invalid memory store (byte) 0x%X", addr));
        !            75: }
        !            76: 
        !            77: /*** SRAM fetch/store ***/
        !            78: 
        !            79: uint8 memz80_fetch_sram_byte(uint16 addr)
        !            80: {
        !            81:   return (*(uint8 *)(cpuz80_ram+(addr & 0x1fff)));
        !            82: }
        !            83: 
        !            84: void memz80_store_sram_byte(uint16 addr, uint8 data)
        !            85: {
        !            86:   *(uint8 *)(cpuz80_ram+(addr & 0x1fff)) = data;
        !            87:   return;
        !            88: }
        !            89: 
        !            90: /*** YAM fetch/store ***/
        !            91: 
        !            92: uint8 memz80_fetch_yam_byte(uint16 addr)
        !            93: {
        !            94:   addr-= 0x4000;
        !            95:   if (addr < 4) {
        !            96:     return soundi_ym2612fetch(addr);
        !            97:   } else {
        !            98:     LOG_CRITICAL(("[Z80] invalid YAM fetch (byte) 0x%X", addr));
        !            99:     return 0;
        !           100:   }
        !           101: }
        !           102: 
        !           103: void memz80_store_yam_byte(uint16 addr, uint8 data)
        !           104: {
        !           105:   addr-= 0x4000;
        !           106:   /* LOG_USER(("[YAM] (z80) store (byte) 0x%X (%d)", addr, data)); */
        !           107:   if (addr < 4)
        !           108:     soundi_ym2612store(addr, data);
        !           109:   else
        !           110:     LOG_CRITICAL(("[Z80] invalid YAM store (byte) 0x%X", addr));
        !           111: }
        !           112: 
        !           113: /*** BANK fetch/store ***/
        !           114: 
        !           115: uint8 memz80_fetch_bank_byte(uint16 addr)
        !           116: {
        !           117:   /* write only */
        !           118:   LOG_CRITICAL(("[Z80] Bank fetch (Byte) 0x%X", addr));
        !           119:   return 0;
        !           120: }
        !           121: 
        !           122: void memz80_store_bank_byte(uint16 addr, uint8 data)
        !           123: {
        !           124:   /* set bank */
        !           125:   cpuz80_bankwrite(data);
        !           126: }
        !           127: 
        !           128: /*** MEM (banked) fetch/store ***/
        !           129: 
        !           130: uint8 memz80_fetch_mem_byte(uint16 addr)
        !           131: {
        !           132:   return (fetchbyte(cpuz80_bank | (addr-0x8000)));
        !           133: }
        !           134: 
        !           135: void memz80_store_mem_byte(uint16 addr, uint8 data)
        !           136: {
        !           137:   /* LOG_USER(("WRITE whilst bank = %08X (%08X)", cpuz80_bank,
        !           138:      addr-0x8000)); */
        !           139:   storebyte(cpuz80_bank | (addr-0x8000), data);
        !           140: }
        !           141: 
        !           142: /*** PSG fetch/store ***/
        !           143: 
        !           144: uint8 memz80_fetch_psg_byte(uint16 addr)
        !           145: {
        !           146:   /* write only */
        !           147:   LOG_CRITICAL(("[Z80] Invalid memory read (byte) 0x%X", addr));
        !           148:   return 0;
        !           149: }
        !           150: 
        !           151: void memz80_store_psg_byte(uint16 addr, uint8 data)
        !           152: {
        !           153:   if (addr == 0x7f11)
        !           154:     sound_psgwrite(data);
        !           155:   else
        !           156:     LOG_CRITICAL(("[Z80] Invalid memory store (byte) 0x%X", addr));
        !           157: }

unix.superglobalmegacorp.com

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