]> git.sesse.net Git - pistorm/blob - platforms/amiga/amiga-autoconf.c
[WIP] Add platforms, Z2 config file-based autoconf Fast
[pistorm] / platforms / amiga / amiga-autoconf.c
1 #include "../platforms.h"
2 #include "amiga-autoconf.h"
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
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
14 };
15
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
23 };
24
25 int ac_current_pic = 0;
26 int ac_pic_count = 0;
27 int ac_done = 0;
28 int ac_type[AC_PIC_LIMIT];
29 int ac_index[AC_PIC_LIMIT];
30 unsigned int ac_base[AC_PIC_LIMIT];
31
32 unsigned char get_autoconf_size(int size) {
33   if (size == 8 * SIZE_MEGA)
34     return AC_MEM_SIZE_8MB;
35   if (size == 4 * SIZE_MEGA)
36     return AC_MEM_SIZE_4MB;
37   if (size == 2 * SIZE_MEGA)
38     return AC_MEM_SIZE_2MB;
39   else
40     return AC_MEM_SIZE_64KB;
41 }
42
43 unsigned int autoconfig_read_memory_8(struct emulator_config *cfg, unsigned int address_) {
44   unsigned char *rom = NULL;
45   int address = address_ - AC_BASE;
46   unsigned char val = 0;
47
48   switch(ac_type[ac_current_pic]) {
49     case ACTYPE_MAPFAST_Z2:
50       rom = ac_fast_ram_rom;
51       break;
52     case ACTYPE_A314:
53       rom = ac_a314_rom;
54       break;
55     default:
56       return 0;
57       break;
58   }
59
60   
61   if ((address & 1) == 0 && (address / 2) < (int)sizeof(ac_fast_ram_rom)) {
62     if (ac_type[ac_current_pic] == ACTYPE_MAPFAST_Z2 && address / 2 == 1)
63       val = get_autoconf_size(cfg->map_size[ac_index[ac_current_pic]]);
64     else
65       val = rom[address / 2];
66     //printf("Read byte %d from autoconf for PIC %d (%.2X).\n", address/2, ac_current_pic, val);
67   }
68   val <<= 4;
69   if (address != 0 && address != 2 && address != 40 && address != 42)
70     val ^= 0xf0;
71   
72   return (unsigned int)val;
73 }
74
75 void autoconfig_write_memory_8(struct emulator_config *cfg, unsigned int address_, unsigned int value) {
76   int address = address_ - AC_BASE;
77   int done = 0;
78
79   unsigned int *base = NULL;
80
81   switch(ac_type[ac_current_pic]) {
82     case ACTYPE_MAPFAST_Z2:
83       base = &ac_base[ac_current_pic];
84       break;
85     case ACTYPE_A314:
86       //base = &a314_base;
87       break;
88     default:
89       break;
90   }
91
92   if (!base) {
93     printf("Failed to set up the base for autoconfig PIC %d.\n", ac_current_pic);
94     done = 1;
95   }
96   else {
97     if (address == 0x4a) {  // base[19:16]
98       *base = (value & 0xf0) << (16 - 4);
99     } else if (address == 0x48) {  // base[23:20]
100       *base &= 0xff0fffff;
101       *base |= (value & 0xf0) << (20 - 4);
102
103       if (ac_type[ac_current_pic] == ACTYPE_MAPFAST_Z2) { // fast ram
104         //a314_set_mem_base_size(*base, cfg->map_size[ac_index[ac_current_pic]]);
105       }
106       done = 1;
107     } else if (address == 0x4c) {  // shut up
108       done = 1;
109     }
110   }
111
112   if (done) {
113     //printf("Address of Z2 autoconf RAM changed to %.8x\n", ac_base[ac_current_pic]);
114     cfg->map_offset[ac_index[ac_current_pic]] = ac_base[ac_current_pic];
115     ac_current_pic++;
116     if (ac_current_pic == ac_pic_count)
117       ac_done = 1;
118   }
119 }