|
|
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: {
1.1.1.3 ! root 75: LOG_CRITICAL(("[Z80] Invalid memory store (byte) 0x%X = %X", addr, data));
1.1 root 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: {
1.1.1.3 ! root 125: (void)addr;
1.1 root 126: /* set bank */
127: cpuz80_bankwrite(data);
128: }
129:
130: /*** MEM (banked) fetch/store ***/
131:
132: uint8 memz80_fetch_mem_byte(uint16 addr)
133: {
1.1.1.2 root 134: return (fetchbyte(cpuz80_bank | (addr - 0x8000)));
1.1 root 135: }
136:
137: void memz80_store_mem_byte(uint16 addr, uint8 data)
138: {
139: /* LOG_USER(("WRITE whilst bank = %08X (%08X)", cpuz80_bank,
140: addr-0x8000)); */
1.1.1.2 root 141: storebyte(cpuz80_bank | (addr - 0x8000), data);
1.1 root 142: }
143:
144: /*** PSG fetch/store ***/
145:
146: uint8 memz80_fetch_psg_byte(uint16 addr)
147: {
148: /* write only */
149: LOG_CRITICAL(("[Z80] Invalid memory read (byte) 0x%X", addr));
150: return 0;
151: }
152:
153: void memz80_store_psg_byte(uint16 addr, uint8 data)
154: {
155: if (addr == 0x7f11)
1.1.1.2 root 156: sound_sn76496store(data);
1.1 root 157: else
158: LOG_CRITICAL(("[Z80] Invalid memory store (byte) 0x%X", addr));
159: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.