1 #include "../platforms.h"
2 #include "amiga-autoconf.h"
11 static unsigned char ac_fast_ram_rom[] = {
12 Z2_Z2 | Z2_FAST, AC_MEM_SIZE_8MB, // 00/02, link into memory free list, 8 MB
13 0x6, 0x9, // 06/09, product id
14 0x8, 0x0, // 08/0a, preference to 8 MB space
15 0x0, 0x0, // 0c/0e, reserved
16 0x0, 0x7, 0xD, 0xB, // 10/12/14/16, mfg id
17 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x2, 0x0, // 18/.../26, serial
18 0x0, 0x0, 0x0, 0x0, // Optional BOOT ROM vector
21 unsigned char ac_piscsi_rom[] = {
22 Z2_Z2 | Z2_BOOTROM, AC_MEM_SIZE_64KB, // 00/01, Z2, bootrom, 64 KB
23 0x6, 0xA, // 06/0A, product id
24 0x0, 0x0, // 00/0a, any space where it fits
25 0x0, 0x0, // 0c/0e, reserved
26 0x0, 0x7, 0xD, 0xB, // 10/12/14/16, mfg id
27 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x2, 0x1, // 18/.../26, serial
28 0x0, 0x0, 0x0, 0x0, // Optional BOOT ROM vector
31 static unsigned char ac_a314_rom[] = {
32 0xc, AC_MEM_SIZE_64KB, // 00/02, 64 kB
33 0xa, 0x3, // 04/06, product id
34 0x0, 0x0, // 08/0a, any space okay
35 0x0, 0x0, // 0c/0e, reserved
36 0x0, 0x7, 0xd, 0xb, // 10/12/14/16, mfg id
37 0xa, 0x3, 0x1, 0x4, 0x0, 0x0, 0x0, 0x0, // 18/.../26, serial
38 0x0, 0x0, 0x0, 0x0, // Optional BOOT ROM vector
41 int ac_z2_current_pic = 0;
42 int ac_z2_pic_count = 0;
44 int ac_z2_type[AC_PIC_LIMIT];
45 int ac_z2_index[AC_PIC_LIMIT];
46 unsigned int ac_base[AC_PIC_LIMIT];
48 int ac_z3_current_pic = 0;
49 int ac_z3_pic_count = 0;
51 int ac_z3_type[AC_PIC_LIMIT];
52 int ac_z3_index[AC_PIC_LIMIT];
54 uint32_t piscsi_base = 0;
55 extern uint8_t *piscsi_rom_ptr;
57 unsigned char get_autoconf_size(int size) {
58 if (size == 8 * SIZE_MEGA)
59 return AC_MEM_SIZE_8MB;
60 if (size == 4 * SIZE_MEGA)
61 return AC_MEM_SIZE_4MB;
62 if (size == 2 * SIZE_MEGA)
63 return AC_MEM_SIZE_2MB;
65 return AC_MEM_SIZE_64KB;
68 unsigned char get_autoconf_size_ext(int size) {
69 if (size == 16 * SIZE_MEGA)
70 return AC_MEM_SIZE_EXT_16MB;
71 if (size == 32 * SIZE_MEGA)
72 return AC_MEM_SIZE_EXT_32MB;
73 if (size == 64 * SIZE_MEGA)
74 return AC_MEM_SIZE_EXT_64MB;
75 if (size == 128 * SIZE_MEGA)
76 return AC_MEM_SIZE_EXT_128MB;
77 if (size == 256 * SIZE_MEGA)
78 return AC_MEM_SIZE_EXT_256MB;
79 if (size == 512 * SIZE_MEGA)
80 return AC_MEM_SIZE_EXT_512MB;
81 if (size == 1024 * SIZE_MEGA)
82 return AC_MEM_SIZE_EXT_1024MB;
84 return AC_MEM_SIZE_EXT_64MB;
87 extern void adjust_ranges_amiga(struct emulator_config *cfg);
89 unsigned int autoconfig_read_memory_z3_8(struct emulator_config *cfg, unsigned int address_) {
90 int address = address_ - AC_Z3_BASE;
91 int index = ac_z3_index[ac_z3_current_pic];
92 unsigned char val = 0;
94 if ((address & 0xFF) >= AC_Z3_REG_RES50 && (address & 0xFF) <= AC_Z3_REG_RES7C)
97 switch(address & 0xFF) {
98 case AC_Z3_REG_ER_TYPE:
100 if (cfg->map_type[index] == MAPTYPE_RAM)
101 val |= BOARDTYPE_FREEMEM;
102 if (cfg->map_size[index] > 8 * SIZE_MEGA)
103 val |= get_autoconf_size_ext(cfg->map_size[index]);
105 val |= get_autoconf_size(cfg->map_size[index]);
106 if (ac_z3_current_pic + 1 < ac_z3_pic_count)
107 val |= BOARDTYPE_LINKED;
108 // Pre-invert this value, since it's the only value not physically complemented
112 case AC_Z3_REG_ER_PRODUCT:
116 case AC_Z3_REG_ER_FLAGS:
117 if (cfg->map_type[index] == MAPTYPE_RAM)
118 val |= Z3_FLAGS_MEMORY;
119 if (cfg->map_size[index] > 8 * SIZE_MEGA)
120 val |= Z3_FLAGS_EXTENSION;
121 val |= Z3_FLAGS_RESERVED;
122 // Bottom four bits are zero, useless unles you want really odd RAM sizes.
124 // Manufacturer ID low/high bytes.
125 case AC_Z3_REG_MAN_LO:
126 val = PISTORM_MANUF_ID & 0x00FF;
128 case AC_Z3_REG_MAN_HI:
129 val = (PISTORM_MANUF_ID >> 8);
131 case AC_Z3_REG_SER_BYTE0:
132 case AC_Z3_REG_SER_BYTE1:
133 case AC_Z3_REG_SER_BYTE2:
134 case AC_Z3_REG_SER_BYTE3:
135 // Expansion board serial assigned by manufacturer.
138 case AC_Z3_REG_INIT_DIAG_VEC_LO:
139 case AC_Z3_REG_INIT_DIAG_VEC_HI:
140 // 16-bit offset to boot ROM in assigned memory range.
143 // Additional reserved/unused registers.
144 case AC_Z3_REG_ER_RES03:
145 case AC_Z3_REG_ER_RES0D:
146 case AC_Z3_REG_ER_RES0E:
147 case AC_Z3_REG_ER_RES0F:
148 case AC_Z3_REG_ER_Z2_INT:
154 //printf("Read byte %d from Z3 autoconf for PIC %d (%.2X).\n", address, ac_z3_current_pic, val);
155 return (address & 0x100) ? (val << 4) ^ 0xFF : (val & 0xF0) ^ 0xFF;
160 void autoconfig_write_memory_z3_8(struct emulator_config *cfg, unsigned int address_, unsigned int value) {
161 int address = address_ - AC_Z3_BASE;
162 int index = ac_z3_index[ac_z3_current_pic];
163 unsigned char val = (unsigned char)value;
166 switch(address & 0xFF) {
167 case AC_Z3_REG_WR_ADDR_LO:
169 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xFF0F0000) | ((val & 0xF0) << 16);
173 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xFF000000) | (val << 16);
175 case AC_Z3_REG_WR_ADDR_HI:
177 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0x0FFF0000) | ((val & 0xF0) << 24);
180 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0x00FF0000) | (val << 24);
183 case AC_Z3_REG_WR_ADDR_NIB_LO:
184 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xFFF00000) | ((val & 0xF0) << 12);
187 case AC_Z3_REG_WR_ADDR_NIB_HI:
188 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xF0FF0000) | ((val & 0xF0) << 20);
191 case AC_Z3_REG_SHUTUP:
192 //printf("Write to Z3 shutup register for PIC %d.\n", ac_z3_current_pic);
201 printf("Address of Z3 autoconf RAM assigned to $%.8x [B]\n", ac_base[ac_z3_current_pic]);
202 cfg->map_offset[index] = ac_base[ac_z3_current_pic];
203 cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
204 m68k_add_ram_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]);
206 if (ac_z3_current_pic == ac_z3_pic_count) {
208 adjust_ranges_amiga(cfg);
215 void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int address_, unsigned int value) {
216 int address = address_ - AC_Z3_BASE;
217 int index = ac_z3_index[ac_z3_current_pic];
218 unsigned short val = (unsigned short)value;
221 switch(address & 0xFF) {
222 case AC_Z3_REG_WR_ADDR_HI:
223 // This is, as far as I know, the only register it should write a 16-bit value to.
224 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0x00000000) | (val << 16);
228 printf("Unknown WORD write to Z3 autoconf address $%.2X", address & 0xFF);
229 //stop_cpu_emulation();
234 printf("Address of Z3 autoconf RAM assigned to $%.8x [W]\n", ac_base[ac_z3_current_pic]);
235 cfg->map_offset[index] = ac_base[ac_z3_current_pic];
236 cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
237 m68k_add_ram_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]);
239 if (ac_z3_current_pic == ac_z3_pic_count)
246 unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int address_) {
247 unsigned char *rom = NULL;
248 int address = address_ - AC_Z2_BASE;
249 unsigned char val = 0;
251 switch(ac_z2_type[ac_z2_current_pic]) {
252 case ACTYPE_MAPFAST_Z2:
253 rom = ac_fast_ram_rom;
267 if ((address & 1) == 0 && (address / 2) < (int)sizeof(ac_fast_ram_rom)) {
268 if (ac_z2_type[ac_z2_current_pic] == ACTYPE_MAPFAST_Z2 && address / 2 == 1) {
269 val = get_autoconf_size(cfg->map_size[ac_z2_index[ac_z2_current_pic]]);
270 if (ac_z2_current_pic + 1 < ac_z2_pic_count)
271 val |= BOARDTYPE_LINKED;
274 val = rom[address / 2];
275 //printf("Read byte %d from Z2 autoconf for PIC %d (%.2X).\n", address/2, ac_z2_current_pic, val);
278 if (address != 0 && address != 2 && address != 40 && address != 42)
281 return (unsigned int)val;
284 void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address_, unsigned int value) {
285 int address = address_ - AC_Z2_BASE;
287 int index = ac_z2_index[ac_z2_current_pic];
289 unsigned int *base = NULL;
291 switch(ac_z2_type[ac_z2_current_pic]) {
292 case ACTYPE_MAPFAST_Z2:
293 base = &ac_base[ac_z2_current_pic];
306 //printf("Failed to set up the base for autoconfig PIC %d.\n", ac_z2_current_pic);
310 if (address == 0x4a) { // base[19:16]
311 *base = (value & 0xf0) << (16 - 4);
312 } else if (address == 0x48) { // base[23:20]
314 *base |= (value & 0xf0) << (20 - 4);
316 if (ac_z2_type[ac_z2_current_pic] == ACTYPE_MAPFAST_Z2) { // fast ram
317 //a314_set_mem_base_size(*base, cfg->map_size[ac_index[ac_z2_current_pic]]);
320 } else if (address == 0x4c) { // shut up
321 //printf("Write to Z2 shutup register for PIC %d.\n", ac_z2_current_pic);
327 cfg->map_offset[index] = ac_base[ac_z2_current_pic];
328 cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
329 switch (ac_z2_type[ac_z2_current_pic]) {
330 case ACTYPE_MAPFAST_Z2:
331 printf("Address of Z2 autoconf RAM assigned to $%.8x\n", ac_base[ac_z2_current_pic]);
332 m68k_add_ram_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]);
333 printf("Z2 PIC %d at $%.8lX-%.8lX, Size: %d MB\n", ac_z2_current_pic, cfg->map_offset[index], cfg->map_high[index], cfg->map_size[index] / SIZE_MEGA);
336 printf("PiSCSI Z2 device assigned to $%.8x\n", ac_base[ac_z2_current_pic]);
337 m68k_add_rom_range(piscsi_base + (16 * SIZE_KILO), piscsi_base + (32 * SIZE_KILO), piscsi_rom_ptr);
343 if (ac_z2_current_pic == ac_z2_pic_count) {
345 adjust_ranges_amiga(cfg);