annotate xband.c @ 1420:975b5b7eaa77

Fix DMA from byte-wide SRAM
author Michael Pavone <pavone@retrodev.com>
date Mon, 26 Jun 2017 21:13:17 -0700
parents 11ac0b511cff
children 14a2834d010c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdlib.h>
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <stddef.h>
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include <string.h>
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include "romdb.h"
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 #include "genesis.h"
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 #include "tern.h"
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 #include "xband.h"
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 #include "util.h"
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 #define BIT_ROM_HI 4
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11
1230
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
12 enum {
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
13 PATCH0_LOW,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
14 PATCH0_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
15 PATCH0_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
16 PATCH1_LOW=4,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
17 PATCH1_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
18 PATCH1_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
19 PATCH2_LOW=8,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
20 PATCH2_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
21 PATCH2_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
22 PATCH3_LOW=12,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
23 PATCH3_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
24 PATCH3_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
25 PATCH4_LOW=16,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
26 PATCH4_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
27 PATCH4_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
28 PATCH5_LOW=20,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
29 PATCH5_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
30 PATCH5_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
31 PATCH6_LOW=24,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
32 PATCH6_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
33 PATCH6_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
34 PATCH7_LOW=28,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
35 PATCH7_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
36 PATCH7_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
37 PATCH8_LOW=32,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
38 PATCH8_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
39 PATCH8_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
40 PATCH9_LOW=36,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
41 PATCH9_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
42 PATCH9_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
43 PATCH10_LOW=40,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
44 PATCH10_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
45 PATCH10_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
46 RANGE0_START_LOW=44,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
47 RANGE0_START_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
48 RANGE0_START_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
49 RANGE1_START=48,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
50 RANGE1_START_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
51 RANGE1_START_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
52 MAGIC_LOW=56,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
53 MAGIC_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
54 MAGIC_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
55 RANGE0_END_LOW=64,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
56 RANGE0_END_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
57 RANGE0_END_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
58 RANGE1_END_LOW=68,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
59 RANGE1_END_MID,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
60 RANGE1_END_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
61 RANGE0_DEST_LOW=80,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
62 RANGE0_DEST_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
63 RANGE0_MASK,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
64 RANGE1_DEST_LOW=84,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
65 RANGE1_DEST_HI,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
66 RANGE1_MASK,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
67
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
68 MORE_MYSTERY=219,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
69 UNKNOWN_REG=221,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
70 UNKNOWN_REG2,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
71 UNKNOWN_REG3,
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
72
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
73 };
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
74
1231
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
75 //#define DO_DEBUG_PRINT
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
76 #ifdef DO_DEBUG_PRINT
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
77 #define dprintf printf
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
78 #define dputs puts
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
79 #else
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
80 #define dprintf
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
81 #define dputs
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
82 #endif
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
83
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 uint8_t xband_detect(uint8_t *rom, uint32_t rom_size)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 //Internal ROM is 512KB, accept larger ones for overdumps and custom firmware
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 if (rom_size < (512*1024)) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 return 0;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 //ROM has no standard header, but does have a jump at $100
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 if (rom[0x100] != 0x4E || rom[0x101] != 0xF9) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 return 0;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 //product ID is all NULL
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
97 for (int i = GAME_ID_OFF; i <= (GAME_ID_OFF + GAME_ID_LEN); i++)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 if (rom[i]) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 return 0;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 return 1;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
105
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
106 static xband *get_xband(genesis_context *gen)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108 if (!gen->extra) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109 gen->extra = gen->m68k->options->gen.memmap[0].buffer;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 gen->m68k->mem_pointers[2] = (uint16_t *)gen->save_storage;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
111 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
112 return gen->extra;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
113 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
115 static void update_control(genesis_context *gen, uint8_t value)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 xband *x = gen->extra;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 if ((x->control ^ value) & BIT_ROM_HI) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 if (value & BIT_ROM_HI) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 gen->m68k->mem_pointers[0] = (uint16_t *)gen->save_storage;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 gen->m68k->mem_pointers[1] = NULL;
1229
a8313793216a Minor xband fixes
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
122 gen->m68k->mem_pointers[2] = gen->cart;
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 gen->m68k->mem_pointers[3] = x->cart_space - 0x100000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 } else {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 gen->m68k->mem_pointers[0] = x->cart_space;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126 gen->m68k->mem_pointers[1] = x->cart_space;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 gen->m68k->mem_pointers[2] = (uint16_t *)gen->save_storage;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 gen->m68k->mem_pointers[3] = NULL;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 m68k_invalidate_code_range(gen->m68k, 0, 0x3BC000);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 x->control = value;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 static void *xband_write_b(uint32_t address, void *context, uint8_t value)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 m68k_context *m68k = context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 genesis_context *gen = m68k->system;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139 xband *x = get_xband(gen);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 if (address == 0x181) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 x->kill = value;
1231
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
142 dprintf("Write to \"soft\" kill register %X\n", value);
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 } else if (address == 0x183) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 update_control(gen, value);
1231
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
145 dprintf("Write to \"soft\" control register %X\n", value);
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 } else if ((x->control & BIT_ROM_HI && address < 0x200000) || (address >= 0x200000 && !(x->control & BIT_ROM_HI))) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 gen->save_storage[(address & 0xFFFF) ^ 1] = value;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 m68k_handle_code_write(address, m68k);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 //TODO: handle code at mirror addresses
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 } else {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 printf("Unhandled write to cartridge area %X: %X\n", address, value);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 return context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 static void *xband_write_hi_b(uint32_t address, void *context, uint8_t value)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 return xband_write_b(address | 0x200000, context, value);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
159 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 static void *xband_write_w(uint32_t address, void *context, uint16_t value)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 m68k_context *m68k = context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 genesis_context *gen = m68k->system;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 xband *x = get_xband(gen);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 if (address == 0x180 || address == 0x182) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 return xband_write_b(address | 1, context, value);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 } else if ((x->control & BIT_ROM_HI && address < 0x200000) || (address >= 0x200000 && !(x->control & BIT_ROM_HI))) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 gen->save_storage[address & 0xFFFE] = value;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
170 gen->save_storage[(address & 0xFFFE) | 1] = value >> 8;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
171 m68k_handle_code_write(address, m68k);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 //TODO: handle code at mirror addresses
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 return context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175 printf("Unhandled write to %X: %X\n", address, value);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 return context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 static void *xband_write_hi_w(uint32_t address, void *context, uint16_t value)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 return xband_write_w(address | 0x200000, context, value);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 static uint16_t xband_read_w(uint32_t address, void *context)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 m68k_context *m68k = context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 genesis_context *gen = m68k->system;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 xband *x = get_xband(gen);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 //TODO: actually do something intelligent here
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 return x->cart_space[address >> 1];
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
193 static uint16_t xband_read_hi_w(uint32_t address, void *context)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 return xband_read_w(address | 0x200000, context);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 static uint8_t xband_read_b(uint32_t address, void *context)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
199 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 uint16_t val = xband_read_w(address, context);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 return address & 1 ? val : val >> 8;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 static uint8_t xband_read_hi_b(uint32_t address, void *context)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 return xband_read_b(address | 0x200000, context);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 static void *xband_reg_write_b(uint32_t address, void *context, uint8_t value)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
211 m68k_context *m68k = context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
212 genesis_context *gen = m68k->system;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 if (!(address & 1)) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 printf("Ignoring write to even address %X: %X\n", address, value);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
215 return context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 xband *x = get_xband(gen);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 if (address < 0x3BFE00) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 uint32_t offset = (address - 0x3BC001) / 2;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 if (offset < XBAND_REGS) {
1230
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
221 switch (offset)
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
222 {
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
223 case MORE_MYSTERY:
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
224 case UNKNOWN_REG:
1231
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
225 dprintf("Write to mysterious reg: %X: %X\n", address, value);
1230
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
226 value = value & 0x7F;
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
227 break;
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
228 case UNKNOWN_REG3:
1231
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
229 dprintf("Write to mysterious reg: %X: %X\n", address, value);
1230
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
230 value = value & 0xFE;
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
231 break;
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
232 }
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
233 x->regs[offset] = value;
1231
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
234 dprintf("Write to register %X(%d): %X\n", address, offset, value);
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 } else {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236 printf("Unhandled register write %X: %X\n", address, value);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 } else {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 if (address == 0x3BFE01) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
240 x->kill = value;
1231
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
241 dprintf("Write to kill register %X\n", value);
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 } else if (address == 0x3BFE03) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 update_control(gen, value);
1231
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
244 dprintf("Write to control register %X\n", value);
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245 } else {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 printf("Unhandled register write %X: %X\n", address, value);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
247 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
248 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 return context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
250 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252 static void *xband_reg_write_w(uint32_t address, void *context, uint16_t value)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
253 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
254 return xband_reg_write_b(address | 1, context, value);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
255 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 static uint8_t xband_reg_read_b(uint32_t address, void *context)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
258 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 m68k_context *m68k = context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
260 genesis_context *gen = m68k->system;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
261 if (!(address & 1)) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
262 printf("Read from even address %X\n", address);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
263 return gen->header.get_open_bus_value(&gen->header) >> 8;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
264 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
265 xband *x = get_xband(gen);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
266 if (address < 0x3BFE00) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 uint32_t offset = (address - 0x3BC001) / 2;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
268 if (offset < XBAND_REGS) {
1231
d9d775d61fcf Cut down on the verbose logging in XBAND code
Michael Pavone <pavone@retrodev.com>
parents: 1230
diff changeset
269 dprintf("Regsister read: %X\n", address);
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
270 return x->regs[offset];
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
271 } else {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
272 printf("Unhandled register read from address %X\n", address);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
273 return 0x5D;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
274 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
275 } else {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
276 if (address == 0x3BFE01) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
277 return x->kill;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
278 } else if (address == 0x3BFE03) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
279 return x->control;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
280 } else {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
281 printf("Unhandled register read from address %X\n", address);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
282 return 0x5D;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
283 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
284 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
285 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
286
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
287 static uint16_t xband_reg_read_w(uint32_t address, void *context)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
288 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
289 m68k_context *m68k = context;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
290 genesis_context *gen = m68k->system;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
291 uint16_t value = xband_reg_read_b(address | 1, context);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
292 value |= gen->header.get_open_bus_value(&gen->header) & 0xFF00;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
293 return value;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
294 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
295
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
296 rom_info xband_configure_rom(tern_node *rom_db, void *rom, uint32_t rom_size, void *lock_on, uint32_t lock_on_size, memmap_chunk const *base_map, uint32_t base_chunks)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
297 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
298 rom_info info;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
299 if (lock_on && lock_on_size) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
300 rom_info lock_on_info = configure_rom(rom_db, lock_on, lock_on_size, NULL, 0, base_map, base_chunks);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
301 info.name = alloc_concat("XBAND - ", lock_on_info.name);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
302 info.regions = lock_on_info.regions;
1411
780fbe0b97be WIP support for handling S3 save RAM when locked on
Michael Pavone <pavone@retrodev.com>
parents: 1255
diff changeset
303 free_rom_info(&lock_on_info);
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
304 } else {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
305 info.name = strdup("XBAND");
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
306 info.regions = REGION_J|REGION_U|REGION_E;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
307 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
308 info.save_size = 64*1024;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
309 info.save_buffer = malloc(info.save_size);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
310 info.save_mask = info.save_size-1;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
311 info.save_type = RAM_FLAG_BOTH;
1255
6370b80491c7 Automatically connect XBAND keyboard if XBAND ROM is detected
Michael Pavone <pavone@retrodev.com>
parents: 1231
diff changeset
312 info.port1_override = info.ext_override = info.mouse_mode = NULL;
6370b80491c7 Automatically connect XBAND keyboard if XBAND ROM is detected
Michael Pavone <pavone@retrodev.com>
parents: 1231
diff changeset
313 info.port2_override = strdup("xband keyboard");
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
314 info.eeprom_map = NULL;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
315 info.num_eeprom = 0;
1416
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
316 info.rom = rom;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
317 info.rom_size = rom_size;
11ac0b511cff Support a couple of bootleg X-in-1 carts
Michael Pavone <pavone@retrodev.com>
parents: 1411
diff changeset
318 info.is_save_lock_on = 0;
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
319 xband *x = calloc(sizeof(xband), 1);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
320 rom_size = nearest_pow2(rom_size);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
321 for (int i = 0; (i + rom_size) <= sizeof(x->cart_space) / 2; i += rom_size)
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
322 {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
323 memcpy(x->cart_space + i/2, rom, rom_size);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
324 }
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
325 if (lock_on && lock_on_size >= 0x200) {
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
326 memcpy(x->cart_space + 0x80, ((uint16_t *)lock_on) + 0x80, 0x100);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
327 }
1229
a8313793216a Minor xband fixes
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
328 //observed power on values
1230
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
329 memset(x->regs, 0, sizeof(x->regs));
1229
a8313793216a Minor xband fixes
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
330 x->regs[0x7C] = 0;
a8313793216a Minor xband fixes
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
331 x->regs[0x7D] = 0x80;
a8313793216a Minor xband fixes
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
332 x->regs[0xB4] = 0x7F;
1230
0ed27bb6a658 Awful hack to get the XBAND menu booting
Michael Pavone <pavone@retrodev.com>
parents: 1229
diff changeset
333 x->regs[UNKNOWN_REG2] = 8;
1229
a8313793216a Minor xband fixes
Michael Pavone <pavone@retrodev.com>
parents: 1228
diff changeset
334
1228
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
335 byteswap_rom(0x400000, x->cart_space);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
336
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
337 info.map_chunks = base_chunks + 5;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
338 info.map = calloc(sizeof(memmap_chunk), info.map_chunks);
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
339 info.map[0].mask = 0xFFFFFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
340 info.map[0].aux_mask = 0xFFFFFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
341 info.map[0].flags = MMAP_READ|MMAP_CODE|MMAP_PTR_IDX|MMAP_FUNC_NULL|MMAP_AUX_BUFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
342 info.map[0].start = 0;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
343 info.map[0].end = 0x10000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
344 info.map[0].ptr_index = 0;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
345 info.map[0].buffer = x->cart_space;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
346 info.map[0].write_16 = xband_write_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
347 info.map[0].write_8 = xband_write_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
348 info.map[0].read_16 = xband_read_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
349 info.map[0].read_8 = xband_read_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
350 info.map[1].mask = 0xFFFFFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
351 info.map[1].aux_mask = 0xFFFFFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
352 info.map[1].flags = MMAP_READ|MMAP_CODE|MMAP_PTR_IDX|MMAP_FUNC_NULL|MMAP_AUX_BUFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
353 info.map[1].start = 0x10000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
354 info.map[1].end = 0x200000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
355 info.map[1].ptr_index = 1;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
356 info.map[1].buffer = x->cart_space;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
357 info.map[1].write_16 = xband_write_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
358 info.map[1].write_8 = xband_write_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
359 info.map[1].read_16 = xband_read_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
360 info.map[1].read_8 = xband_read_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
361 info.map[2].mask = 0xFFFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
362 info.map[2].aux_mask = 0xFFFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
363 info.map[2].flags = MMAP_READ|MMAP_CODE|MMAP_PTR_IDX|MMAP_FUNC_NULL;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
364 info.map[2].start = 0x200000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
365 info.map[2].end = 0x210000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
366 info.map[2].ptr_index = 2;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
367 info.map[2].buffer = NULL;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
368 info.map[2].write_16 = xband_write_hi_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
369 info.map[2].write_8 = xband_write_hi_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
370 info.map[2].read_16 = xband_read_hi_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
371 info.map[2].read_8 = xband_read_hi_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
372 info.map[3].mask = 0xFFFFFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
373 info.map[3].aux_mask = 0xFFFFFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
374 info.map[3].flags = MMAP_READ|MMAP_CODE|MMAP_PTR_IDX|MMAP_FUNC_NULL;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
375 info.map[3].start = 0x210000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
376 info.map[3].end = 0x3BC000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
377 info.map[3].ptr_index = 3;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
378 info.map[3].buffer = NULL;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
379 info.map[3].write_16 = xband_write_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
380 info.map[3].write_8 = xband_write_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
381 info.map[3].read_16 = xband_read_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
382 info.map[3].read_8 = xband_read_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
383 info.map[4].mask = 0xFFFFFF;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
384 info.map[4].flags = MMAP_READ|MMAP_CODE|MMAP_PTR_IDX|MMAP_FUNC_NULL;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
385 info.map[4].start = 0x3BC000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
386 info.map[4].end = 0x3C0000;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
387 info.map[4].ptr_index = 4;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
388 info.map[4].write_16 = xband_reg_write_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
389 info.map[4].write_8 = xband_reg_write_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
390 info.map[4].read_16 = xband_reg_read_w;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
391 info.map[4].read_8 = xband_reg_read_b;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
392 memcpy(info.map + 5, base_map, base_chunks * sizeof(memmap_chunk));
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
393
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
394 return info;
2e6dcb5c11a2 WIP support for XBAND mapper hardware
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
395 }