1 #include "platforms/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 0x4, 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 index = ac_z3_index[ac_z3_current_pic];
91 unsigned char val = 0;
93 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:
156 //printf("Read byte %d from Z3 autoconf for PIC %d (%.2X).\n", address, ac_z3_current_pic, val);
157 return (address & 0x100) ? (val << 4) ^ 0xFF : (val & 0xF0) ^ 0xFF;
162 void autoconfig_write_memory_z3_8(struct emulator_config *cfg, unsigned int address, unsigned int value) {
163 int index = ac_z3_index[ac_z3_current_pic];
164 unsigned char val = (unsigned char)value;
167 switch(address & 0xFF) {
168 case AC_Z3_REG_WR_ADDR_LO:
170 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xFF0F0000) | ((val & 0xF0) << 16);
174 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xFF000000) | (val << 16);
176 case AC_Z3_REG_WR_ADDR_HI:
178 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0x0FFF0000) | ((val & 0xF0) << 24);
181 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0x00FF0000) | (val << 24);
184 case AC_Z3_REG_WR_ADDR_NIB_LO:
185 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xFFF00000) | ((val & 0xF0) << 12);
188 case AC_Z3_REG_WR_ADDR_NIB_HI:
189 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xF0FF0000) | ((val & 0xF0) << 20);
192 case AC_Z3_REG_SHUTUP:
193 //printf("Write to Z3 shutup register for PIC %d.\n", ac_z3_current_pic);
202 printf("Address of Z3 autoconf RAM assigned to $%.8x [B]\n", ac_base[ac_z3_current_pic]);
203 cfg->map_offset[index] = ac_base[ac_z3_current_pic];
204 cfg->map_high[index] = cfg->map_offset[index] + cfg->map_size[index];
205 m68k_add_ram_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]);
207 if (ac_z3_current_pic == ac_z3_pic_count) {
209 adjust_ranges_amiga(cfg);
216 void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int address, unsigned int value) {
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 unsigned char val = 0;
250 switch(ac_z2_type[ac_z2_current_pic]) {
251 case ACTYPE_MAPFAST_Z2:
252 rom = ac_fast_ram_rom;
266 if ((address & 1) == 0 && (address / 2) < (int)sizeof(ac_fast_ram_rom)) {
267 if (ac_z2_type[ac_z2_current_pic] == ACTYPE_MAPFAST_Z2 && address / 2 == 1) {
268 val = get_autoconf_size(cfg->map_size[ac_z2_index[ac_z2_current_pic]]);
269 if (ac_z2_current_pic + 1 < ac_z2_pic_count)
270 val |= BOARDTYPE_LINKED;
273 val = rom[address / 2];
274 //printf("Read byte %d from Z2 autoconf for PIC %d (%.2X).\n", address/2, ac_z2_current_pic, val);
277 if (address != 0 && address != 2 && address != 0x40 && address != 0x42)
280 return (unsigned int)val;
283 void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address, unsigned int value) {
285 int index = ac_z2_index[ac_z2_current_pic];
287 unsigned int *base = NULL;
289 switch(ac_z2_type[ac_z2_current_pic]) {
290 case ACTYPE_MAPFAST_Z2:
291 base = &ac_base[ac_z2_current_pic];
304 //printf("Failed to set up the base for autoconfig PIC %d.\n", ac_z2_current_pic);
308 if (address == 0x4a) { // base[19:16]
309 *base = (value & 0xf0) << (16 - 4);
310 } else if (address == 0x48) { // base[23:20]
312 *base |= (value & 0xf0) << (20 - 4);
314 if (ac_z2_type[ac_z2_current_pic] == ACTYPE_MAPFAST_Z2) { // fast ram
315 //a314_set_mem_base_size(*base, cfg->map_size[ac_index[ac_z2_current_pic]]);
318 } else if (address == 0x4c) { // shut up
319 //printf("Write to Z2 shutup register for PIC %d.\n", ac_z2_current_pic);
325 switch (ac_z2_type[ac_z2_current_pic]) {
326 case ACTYPE_MAPFAST_Z2:
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 printf("Address of Z2 autoconf RAM assigned to $%.8x\n", ac_base[ac_z2_current_pic]);
330 m68k_add_ram_range(cfg->map_offset[index], cfg->map_high[index], cfg->map_data[index]);
331 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);
334 printf("PiSCSI Z2 device assigned to $%.8x\n", piscsi_base);
335 //m68k_add_rom_range(piscsi_base + (16 * SIZE_KILO), piscsi_base + (32 * SIZE_KILO), piscsi_rom_ptr);
341 if (ac_z2_current_pic == ac_z2_pic_count) {
343 adjust_ranges_amiga(cfg);