1 #include "../platforms.h"
2 #include "amiga-autoconf.h"
7 static unsigned char ac_fast_ram_rom[] = {
8 0xe, AC_MEM_SIZE_8MB, // 00/02, link into memory free list, 8 MB
9 0x6, 0x9, // 04/06, product id
10 0x8, 0x0, // 08/0a, preference to 8 MB space
11 0x0, 0x0, // 0c/0e, reserved
12 0x0, 0x7, 0xd, 0xb, // 10/12/14/16, mfg id
13 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x2, 0x0 // 18/.../26, serial
16 static unsigned char ac_a314_rom[] = {
17 0xc, AC_MEM_SIZE_64KB, // 00/02, 64 kB
18 0xa, 0x3, // 04/06, product id
19 0x0, 0x0, // 08/0a, any space okay
20 0x0, 0x0, // 0c/0e, reserved
21 0x0, 0x7, 0xd, 0xb, // 10/12/14/16, mfg id
22 0xa, 0x3, 0x1, 0x4, 0x0, 0x0, 0x0, 0x0 // 18/.../26, serial
25 int ac_z2_current_pic = 0;
26 int ac_z2_pic_count = 0;
28 int ac_z2_type[AC_PIC_LIMIT];
29 int ac_z2_index[AC_PIC_LIMIT];
30 unsigned int ac_base[AC_PIC_LIMIT];
32 int ac_z3_current_pic = 0;
33 int ac_z3_pic_count = 0;
35 int ac_z3_type[AC_PIC_LIMIT];
36 int ac_z3_index[AC_PIC_LIMIT];
39 unsigned char get_autoconf_size(int size) {
40 if (size == 8 * SIZE_MEGA)
41 return AC_MEM_SIZE_8MB;
42 if (size == 4 * SIZE_MEGA)
43 return AC_MEM_SIZE_4MB;
44 if (size == 2 * SIZE_MEGA)
45 return AC_MEM_SIZE_2MB;
47 return AC_MEM_SIZE_64KB;
50 unsigned char get_autoconf_size_ext(int size) {
51 if (size == 16 * SIZE_MEGA)
52 return AC_MEM_SIZE_EXT_16MB;
53 if (size == 32 * SIZE_MEGA)
54 return AC_MEM_SIZE_EXT_32MB;
55 if (size == 64 * SIZE_MEGA)
56 return AC_MEM_SIZE_EXT_64MB;
57 if (size == 128 * SIZE_MEGA)
58 return AC_MEM_SIZE_EXT_128MB;
59 if (size == 256 * SIZE_MEGA)
60 return AC_MEM_SIZE_EXT_256MB;
61 if (size == 512 * SIZE_MEGA)
62 return AC_MEM_SIZE_EXT_512MB;
63 if (size == 1024 * SIZE_MEGA)
64 return AC_MEM_SIZE_EXT_1024MB;
66 return AC_MEM_SIZE_EXT_64MB;
69 unsigned int autoconfig_read_memory_z3_8(struct emulator_config *cfg, unsigned int address_) {
70 int address = address_ - AC_Z3_BASE;
71 int index = ac_z3_index[ac_z3_current_pic];
72 unsigned char val = 0;
74 if ((address & 0xFF) >= AC_Z3_REG_RES50 && (address & 0xFF) <= AC_Z3_REG_RES7C)
77 switch(address & 0xFF) {
78 case AC_Z3_REG_ER_TYPE:
80 if (cfg->map_type[index] == MAPTYPE_RAM)
81 val |= BOARDTYPE_FREEMEM;
82 if (cfg->map_size[index] > 8 * SIZE_MEGA)
83 val |= get_autoconf_size_ext(cfg->map_size[index]);
85 val |= get_autoconf_size(cfg->map_size[index]);
86 if (ac_z3_current_pic + 1 < ac_z3_pic_count)
87 val |= BOARDTYPE_LINKED;
88 // Pre-invert this value, since it's the only value not physically complemented
92 case AC_Z3_REG_ER_PRODUCT:
96 case AC_Z3_REG_ER_FLAGS:
97 if (cfg->map_type[index] == MAPTYPE_RAM)
98 val |= Z3_FLAGS_MEMORY;
99 if (cfg->map_size[index] > 8 * SIZE_MEGA)
100 val |= Z3_FLAGS_EXTENSION;
101 val |= Z3_FLAGS_RESERVED;
102 // Bottom four bits are zero, useless unles you want really odd RAM sizes.
104 // Manufacturer ID low/high bytes.
105 case AC_Z3_REG_MAN_LO:
106 val = PISTORM_MANUF_ID & 0x00FF;
108 case AC_Z3_REG_MAN_HI:
109 val = (PISTORM_MANUF_ID >> 8);
111 case AC_Z3_REG_SER_BYTE0:
112 case AC_Z3_REG_SER_BYTE1:
113 case AC_Z3_REG_SER_BYTE2:
114 case AC_Z3_REG_SER_BYTE3:
115 // Expansion board serial assigned by manufacturer.
118 case AC_Z3_REG_INIT_DIAG_VEC_LO:
119 case AC_Z3_REG_INIT_DIAG_VEC_HI:
120 // 16-bit offset to boot ROM in assigned memory range.
123 // Additional reserved/unused registers.
124 case AC_Z3_REG_ER_RES03:
125 case AC_Z3_REG_ER_RES0D:
126 case AC_Z3_REG_ER_RES0E:
127 case AC_Z3_REG_ER_RES0F:
128 case AC_Z3_REG_ER_Z2_INT:
134 //printf("Read byte %d from Z3 autoconf for PIC %d (%.2X).\n", address, ac_z3_current_pic, val);
135 return (address & 0x100) ? (val << 4) ^ 0xFF : (val & 0xF0) ^ 0xFF;
140 void autoconfig_write_memory_z3_8(struct emulator_config *cfg, unsigned int address_, unsigned int value) {
141 int address = address_ - AC_Z3_BASE;
142 int index = ac_z3_index[ac_z3_current_pic];
143 unsigned char val = (unsigned char)value;
146 switch(address & 0xFF) {
147 case AC_Z3_REG_WR_ADDR_LO:
149 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xFF0F0000) | ((val & 0xF0) << 16);
153 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xFF000000) | (val << 16);
155 case AC_Z3_REG_WR_ADDR_HI:
157 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0x0FFF0000) | ((val & 0xF0) << 24);
160 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0x00FF0000) | (val << 24);
163 case AC_Z3_REG_WR_ADDR_NIB_LO:
164 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xFFF00000) | ((val & 0xF0) << 12);
167 case AC_Z3_REG_WR_ADDR_NIB_HI:
168 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0xF0FF0000) | ((val & 0xF0) << 20);
171 case AC_Z3_REG_SHUTUP:
172 //printf("Write to Z3 shutup register for PIC %d.\n", ac_z3_current_pic);
181 printf("Address of Z3 autoconf RAM assigned to $%.8x\n", ac_base[ac_z3_current_pic]);
182 cfg->map_offset[index] = ac_base[ac_z3_current_pic];
184 if (ac_z3_current_pic == ac_z3_pic_count)
191 void autoconfig_write_memory_z3_16(struct emulator_config *cfg, unsigned int address_, unsigned int value) {
192 int address = address_ - AC_Z3_BASE;
193 int index = ac_z3_index[ac_z3_current_pic];
194 unsigned short val = (unsigned short)value;
197 switch(address & 0xFF) {
198 case AC_Z3_REG_WR_ADDR_HI:
199 // This is, as far as I know, the only regiter it should write a 16-bit value to.
200 ac_base[ac_z3_current_pic] = (ac_base[ac_z3_current_pic] & 0x00000000) | (val << 16);
204 printf("Unknown WORD write to Z3 autoconf address $%.2X", address & 0xFF);
205 //stop_cpu_emulation();
210 printf("Address of Z3 autoconf RAM assigned to $%.8x\n", ac_base[ac_z3_current_pic]);
211 cfg->map_offset[index] = ac_base[ac_z3_current_pic];
213 if (ac_z3_current_pic == ac_z3_pic_count)
220 unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int address_) {
221 unsigned char *rom = NULL;
222 int address = address_ - AC_Z2_BASE;
223 unsigned char val = 0;
225 switch(ac_z2_type[ac_z2_current_pic]) {
226 case ACTYPE_MAPFAST_Z2:
227 rom = ac_fast_ram_rom;
238 if ((address & 1) == 0 && (address / 2) < (int)sizeof(ac_fast_ram_rom)) {
239 if (ac_z2_type[ac_z2_current_pic] == ACTYPE_MAPFAST_Z2 && address / 2 == 1) {
240 val = get_autoconf_size(cfg->map_size[ac_z2_index[ac_z2_current_pic]]);
241 if (ac_z2_current_pic + 1 < ac_z2_pic_count)
242 val |= BOARDTYPE_LINKED;
245 val = rom[address / 2];
246 //printf("Read byte %d from Z2 autoconf for PIC %d (%.2X).\n", address/2, ac_z2_current_pic, val);
249 if (address != 0 && address != 2 && address != 40 && address != 42)
252 return (unsigned int)val;
255 void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address_, unsigned int value) {
256 int address = address_ - AC_Z2_BASE;
259 unsigned int *base = NULL;
261 switch(ac_z2_type[ac_z2_current_pic]) {
262 case ACTYPE_MAPFAST_Z2:
263 base = &ac_base[ac_z2_current_pic];
273 //printf("Failed to set up the base for autoconfig PIC %d.\n", ac_z2_current_pic);
277 if (address == 0x4a) { // base[19:16]
278 *base = (value & 0xf0) << (16 - 4);
279 } else if (address == 0x48) { // base[23:20]
281 *base |= (value & 0xf0) << (20 - 4);
283 if (ac_z2_type[ac_z2_current_pic] == ACTYPE_MAPFAST_Z2) { // fast ram
284 //a314_set_mem_base_size(*base, cfg->map_size[ac_index[ac_z2_current_pic]]);
287 } else if (address == 0x4c) { // shut up
288 //printf("Write to Z2 shutup register for PIC %d.\n", ac_z2_current_pic);
294 printf("Address of Z2 autoconf RAM assigned to $%.8x\n", ac_base[ac_z2_current_pic]);
295 cfg->map_offset[ac_z2_index[ac_z2_current_pic]] = ac_base[ac_z2_current_pic];
297 if (ac_z2_current_pic == ac_z2_pic_count)