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