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

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"
1.1.1.2 ! root        6: #include "cpu68k.h"
1.1       root        7: #include "mem68k.h"
                      8: #include "cpuz80.h"
                      9: #include "memz80.h"
                     10: #include "gensound.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: 
1.1.1.2 ! root       22: void memz80_store_bad_byte(uint16 addr, uint8 data);
1.1       root       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[] = {
1.1.1.2 ! root       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}
1.1       root       42: };
                     43: 
1.1.1.2 ! root       44: uint8 (*memz80_fetch_byte[0x100]) (uint16 addr);
        !            45: void (*memz80_store_byte[0x100]) (uint16 addr, uint8 data);
1.1       root       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++;
1.1.1.2 ! root       60:   }
        !            61:   while ((memz80_def[i].start != 0) || (memz80_def[i].end != 0));
1.1       root       62:   return 0;
                     63: }
                     64: 
                     65: /*** BAD fetch/store ***/
                     66: 
                     67: uint8 memz80_fetch_bad_byte(uint16 addr)
                     68: {
                     69:   LOG_CRITICAL(("[Z80] Invalid memory fetch (byte) 0x%X", addr));
                     70:   return 0;
                     71: }
                     72: 
                     73: void memz80_store_bad_byte(uint16 addr, uint8 data)
                     74: {
                     75:   LOG_CRITICAL(("[Z80] Invalid memory store (byte) 0x%X", addr));
                     76: }
                     77: 
                     78: /*** SRAM fetch/store ***/
                     79: 
                     80: uint8 memz80_fetch_sram_byte(uint16 addr)
                     81: {
1.1.1.2 ! root       82:   return (*(uint8 *)(cpuz80_ram + (addr & 0x1fff)));
1.1       root       83: }
                     84: 
                     85: void memz80_store_sram_byte(uint16 addr, uint8 data)
                     86: {
1.1.1.2 ! root       87:   *(uint8 *)(cpuz80_ram + (addr & 0x1fff)) = data;
1.1       root       88:   return;
                     89: }
                     90: 
                     91: /*** YAM fetch/store ***/
                     92: 
                     93: uint8 memz80_fetch_yam_byte(uint16 addr)
                     94: {
1.1.1.2 ! root       95:   addr -= 0x4000;
1.1       root       96:   if (addr < 4) {
1.1.1.2 ! root       97:     return sound_ym2612fetch(addr);
1.1       root       98:   } else {
                     99:     LOG_CRITICAL(("[Z80] invalid YAM fetch (byte) 0x%X", addr));
                    100:     return 0;
                    101:   }
                    102: }
                    103: 
                    104: void memz80_store_yam_byte(uint16 addr, uint8 data)
                    105: {
1.1.1.2 ! root      106:   addr -= 0x4000;
1.1       root      107:   /* LOG_USER(("[YAM] (z80) store (byte) 0x%X (%d)", addr, data)); */
                    108:   if (addr < 4)
1.1.1.2 ! root      109:     sound_ym2612store(addr, data);
1.1       root      110:   else
                    111:     LOG_CRITICAL(("[Z80] invalid YAM store (byte) 0x%X", addr));
                    112: }
                    113: 
                    114: /*** BANK fetch/store ***/
                    115: 
                    116: uint8 memz80_fetch_bank_byte(uint16 addr)
                    117: {
                    118:   /* write only */
                    119:   LOG_CRITICAL(("[Z80] Bank fetch (Byte) 0x%X", addr));
                    120:   return 0;
                    121: }
                    122: 
                    123: void memz80_store_bank_byte(uint16 addr, uint8 data)
                    124: {
                    125:   /* set bank */
                    126:   cpuz80_bankwrite(data);
                    127: }
                    128: 
                    129: /*** MEM (banked) fetch/store ***/
                    130: 
                    131: uint8 memz80_fetch_mem_byte(uint16 addr)
                    132: {
1.1.1.2 ! root      133:   return (fetchbyte(cpuz80_bank | (addr - 0x8000)));
1.1       root      134: }
                    135: 
                    136: void memz80_store_mem_byte(uint16 addr, uint8 data)
                    137: {
                    138:   /* LOG_USER(("WRITE whilst bank = %08X (%08X)", cpuz80_bank,
                    139:      addr-0x8000)); */
1.1.1.2 ! root      140:   storebyte(cpuz80_bank | (addr - 0x8000), data);
1.1       root      141: }
                    142: 
                    143: /*** PSG fetch/store ***/
                    144: 
                    145: uint8 memz80_fetch_psg_byte(uint16 addr)
                    146: {
                    147:   /* write only */
                    148:   LOG_CRITICAL(("[Z80] Invalid memory read (byte) 0x%X", addr));
                    149:   return 0;
                    150: }
                    151: 
                    152: void memz80_store_psg_byte(uint16 addr, uint8 data)
                    153: {
                    154:   if (addr == 0x7f11)
1.1.1.2 ! root      155:     sound_sn76496store(data);
1.1       root      156:   else
                    157:     LOG_CRITICAL(("[Z80] Invalid memory store (byte) 0x%X", addr));
                    158: }

unix.superglobalmegacorp.com

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