]> git.sesse.net Git - pistorm/blob - platforms/amiga/amiga-platform.c
Disable mouse/kb hook on Amiga platform shutdown
[pistorm] / platforms / amiga / amiga-platform.c
1 // SPDX-License-Identifier: MIT
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <ctype.h>
7 #include "amiga-autoconf.h"
8 #include "amiga-registers.h"
9 #include "hunk-reloc.h"
10 #include "net/pi-net-enums.h"
11 #include "net/pi-net.h"
12 #include "piscsi/piscsi-enums.h"
13 #include "piscsi/piscsi.h"
14 #include "pistorm-dev/pistorm-dev-enums.h"
15 #include "pistorm-dev/pistorm-dev.h"
16 #include "platforms/platforms.h"
17 #include "platforms/shared/rtc.h"
18 #include "rtg/rtg.h"
19 #include "a314/a314.h"
20
21 //#define DEBUG_AMIGA_PLATFORM
22
23 #ifdef DEBUG_AMIGA_PLATFORM
24 #define DEBUG printf
25 #else
26 #define DEBUG(...)
27 #endif
28
29 int handle_register_read_amiga(unsigned int addr, unsigned char type, unsigned int *val);
30 int handle_register_write_amiga(unsigned int addr, unsigned int value, unsigned char type);
31
32 extern int ac_z2_current_pic;
33 extern int ac_z2_done;
34 extern int ac_z2_pic_count;
35 extern int ac_z2_type[AC_PIC_LIMIT];
36 extern int ac_z2_index[AC_PIC_LIMIT];
37
38 extern int ac_z3_current_pic;
39 extern int ac_z3_pic_count;
40 extern int ac_z3_done;
41 extern int ac_z3_type[AC_PIC_LIMIT];
42 extern int ac_z3_index[AC_PIC_LIMIT];
43 extern uint8_t gayle_emulation_enabled;
44
45 char *z2_autoconf_id = "z2_autoconf_fast";
46 char *z2_autoconf_zap_id = "^2_autoconf_fast";
47 char *z3_autoconf_id = "z3_autoconf_fast";
48 char *z3_autoconf_zap_id = "^3_autoconf_fast";
49
50 extern const char *op_type_names[OP_TYPE_NUM];
51 extern uint8_t cdtv_mode;
52 extern uint8_t rtc_type;
53 extern unsigned char cdtv_sram[32 * SIZE_KILO];
54 extern unsigned int a314_base;
55
56 extern int kb_hook_enabled;
57 extern int mouse_hook_enabled;
58
59 #define min(a, b) (a < b) ? a : b
60 #define max(a, b) (a > b) ? a : b
61
62 uint8_t rtg_enabled = 0, piscsi_enabled = 0, pinet_enabled = 0, kick13_mode = 0, pistorm_dev_enabled = 1;
63 uint8_t a314_emulation_enabled = 0, a314_initialized = 0;
64
65 extern uint32_t piscsi_base, pistorm_dev_base;
66
67 extern void stop_cpu_emulation(uint8_t disasm_cur);
68
69 inline int custom_read_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type) {
70     if (kick13_mode)
71         ac_z3_done = 1;
72
73     if ((!ac_z2_done || !ac_z3_done) && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
74         if (!ac_z2_done && ac_z2_current_pic < ac_z2_pic_count) {
75             if (type == OP_TYPE_BYTE) {
76                 *val = autoconfig_read_memory_8(cfg, addr - AC_Z2_BASE);
77                 return 1;
78             }
79             printf("Unexpected %s read from Z2 autoconf addr %.X\n", op_type_names[type], addr - AC_Z2_BASE);
80             return -1;
81         }
82         if (!ac_z3_done && ac_z3_current_pic < ac_z3_pic_count) {
83             uint32_t addr_ = addr - AC_Z2_BASE;
84             if (addr_ & 0x02) {
85                 addr_ = (addr_ - 2) + 0x100;
86             }
87             if (type == OP_TYPE_BYTE) {
88                 *val = autoconfig_read_memory_z3_8(cfg, addr_ - AC_Z2_BASE);
89                 return 1;
90             }
91             printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z2_BASE);
92             return -1;
93         }
94     }
95     if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
96         if (ac_z3_pic_count == 0) {
97             ac_z3_done = 1;
98             return -1;
99         }
100
101         if (type == OP_TYPE_BYTE) {
102             *val = autoconfig_read_memory_z3_8(cfg, addr - AC_Z3_BASE);
103             return 1;
104         }
105         printf("Unexpected %s read from Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
106         return -1;
107     }
108
109     if (pistorm_dev_enabled && addr >= pistorm_dev_base && addr < pistorm_dev_base + (64 * SIZE_KILO)) {
110         *val = handle_pistorm_dev_read(addr, type);
111         return 1;
112     }
113
114     if (piscsi_enabled && addr >= piscsi_base && addr < piscsi_base + (64 * SIZE_KILO)) {
115         //printf("[Amiga-Custom] %s read from PISCSI base @$%.8X.\n", op_type_names[type], addr);
116         //stop_cpu_emulation(1);
117         *val = handle_piscsi_read(addr, type);
118         return 1;
119     }
120
121     if (a314_emulation_enabled && addr >= a314_base && addr < a314_base + (64 * SIZE_KILO)) {
122         //printf("%s read from A314 @$%.8X\n", op_type_names[type], addr);
123         switch (type) {
124             case OP_TYPE_BYTE:
125                 *val = a314_read_memory_8(addr - a314_base);
126                 return 1;
127                 break;
128             case OP_TYPE_WORD:
129                 *val = a314_read_memory_16(addr - a314_base);
130                 return 1;                
131                 break;
132             case OP_TYPE_LONGWORD:
133                 *val = a314_read_memory_32(addr - a314_base);
134                 return 1;
135                 break;
136             default:
137                 break;
138         }
139         return 1;
140     }
141
142     return -1;
143 }
144
145 inline int custom_write_amiga(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type) {
146     if (kick13_mode)
147         ac_z3_done = 1;
148
149     if ((!ac_z2_done || !ac_z3_done) && addr >= AC_Z2_BASE && addr < AC_Z2_BASE + AC_SIZE) {
150         if (!ac_z2_done && ac_z2_current_pic < ac_z2_pic_count) {
151             if (type == OP_TYPE_BYTE) {
152                 autoconfig_write_memory_8(cfg, addr - AC_Z2_BASE, val);
153                 return 1;
154             }
155             printf("Unexpected %s write to Z2 autoconf addr %.X\n", op_type_names[type], addr - AC_Z2_BASE);
156             return -1;
157         }
158         if (!ac_z3_done && ac_z3_current_pic < ac_z3_pic_count) {
159             uint32_t addr_ = addr - AC_Z2_BASE;
160             if (addr_ & 0x02) {
161                 addr_ = (addr_ - 2) + 0x100;
162             }
163             if (type == OP_TYPE_BYTE) {
164                 autoconfig_write_memory_z3_8(cfg, addr_ - AC_Z2_BASE, val);
165                 return 1;
166             }
167             else if (type == OP_TYPE_WORD) {
168                 autoconfig_write_memory_z3_16(cfg, addr_ - AC_Z2_BASE, val);
169                 return 1;
170             }
171             printf("Unexpected %s write to Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z2_BASE);
172             return -1;
173         }
174     }
175
176     if (!ac_z3_done && addr >= AC_Z3_BASE && addr < AC_Z3_BASE + AC_SIZE) {
177         if (type == OP_TYPE_BYTE) {
178             if (ac_z3_pic_count == 0) {
179                 ac_z3_done = 1;
180                 return -1;
181             }
182
183             //printf("Write to autoconf area.\n");
184             autoconfig_write_memory_z3_8(cfg, addr - AC_Z3_BASE, val);
185             return 1;
186         }
187         else if (type == OP_TYPE_WORD) {
188             autoconfig_write_memory_z3_16(cfg, addr - AC_Z3_BASE, val);
189             return 1;
190         }
191         else {
192             printf("Unexpected %s write to Z3 autoconf addr %.X\n", op_type_names[type], addr - AC_Z3_BASE);
193             //stop_emulation();
194         }
195     }
196
197     if (pistorm_dev_enabled && addr >= pistorm_dev_base && addr < pistorm_dev_base + (64 * SIZE_KILO)) {
198         handle_pistorm_dev_write(addr, val, type);
199         return 1;
200     }
201
202     if (piscsi_enabled && addr >= piscsi_base && addr < piscsi_base + (64 * SIZE_KILO)) {
203         //printf("[Amiga-Custom] %s write to PISCSI base @$%.8x: %.8X\n", op_type_names[type], addr, val);
204         handle_piscsi_write(addr, val, type);
205         return 1;
206     }
207
208     if (a314_emulation_enabled && addr >= a314_base && addr < a314_base + (64 * SIZE_KILO)) {
209         //printf("%s write to A314 @$%.8X: %d\n", op_type_names[type], addr, val);
210         switch (type) {
211             case OP_TYPE_BYTE:
212                 a314_write_memory_8(addr - a314_base, val);
213                 return 1;
214                 break;
215             case OP_TYPE_WORD:
216                 // Not implemented in a314.cc
217                 //a314_write_memory_16(addr, val);
218                 return -1;
219                 break;
220             case OP_TYPE_LONGWORD:
221                 // Not implemented in a314.cc
222                 // a314_write_memory_32(addr, val);
223                 return -1;
224                 break;
225             default:
226                 break;
227         }
228     }
229
230     return -1;
231 }
232
233 void adjust_ranges_amiga(struct emulator_config *cfg) {
234     cfg->mapped_high = 0;
235     cfg->mapped_low = 0;
236     cfg->custom_high = 0;
237     cfg->custom_low = 0;
238
239     // Set up the min/max ranges for mapped reads/writes
240     for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
241         if (cfg->map_type[i] != MAPTYPE_NONE) {
242             if ((cfg->map_offset[i] != 0 && cfg->map_offset[i] < cfg->mapped_low) || cfg->mapped_low == 0)
243                 cfg->mapped_low = cfg->map_offset[i];
244             if (cfg->map_offset[i] + cfg->map_size[i] > cfg->mapped_high)
245                 cfg->mapped_high = cfg->map_offset[i] + cfg->map_size[i];
246         }
247     }
248
249     if ((ac_z2_pic_count || ac_z3_pic_count) && (!ac_z2_done || !ac_z3_done)) {
250         if (cfg->custom_low == 0)
251             cfg->custom_low = AC_Z2_BASE;
252         else
253             cfg->custom_low = min(cfg->custom_low, AC_Z2_BASE);
254         cfg->custom_high = max(cfg->custom_high, AC_Z2_BASE + AC_SIZE);
255     }
256     /*if (ac_z3_pic_count && !ac_z3_done) {
257         if (cfg->custom_low == 0)
258             cfg->custom_low = AC_Z3_BASE;
259         else
260             cfg->custom_low = min(cfg->custom_low, AC_Z3_BASE);
261         cfg->custom_high = max(cfg->custom_high, AC_Z3_BASE + AC_SIZE);
262     }*/
263     if (rtg_enabled) {
264         if (cfg->custom_low == 0)
265             cfg->custom_low = PIGFX_RTG_BASE;
266         else
267             cfg->custom_low = min(cfg->custom_low, PIGFX_RTG_BASE);
268         cfg->custom_high = max(cfg->custom_high, PIGFX_UPPER);
269     }
270     if (piscsi_enabled) {
271         if (cfg->custom_low == 0)
272             cfg->custom_low = PISCSI_OFFSET;
273         else
274             cfg->custom_low = min(cfg->custom_low, PISCSI_OFFSET);
275         cfg->custom_high = max(cfg->custom_high, PISCSI_UPPER);
276         if (piscsi_base != 0) {
277             cfg->custom_low = min(cfg->custom_low, piscsi_base);
278         }
279     }
280     if (pinet_enabled) {
281         if (cfg->custom_low == 0)
282             cfg->custom_low = PINET_OFFSET;
283         else
284             cfg->custom_low = min(cfg->custom_low, PINET_OFFSET);
285         cfg->custom_high = max(cfg->custom_high, PINET_UPPER);
286     }
287
288     printf("Platform custom range: %.8X-%.8X\n", cfg->custom_low, cfg->custom_high);
289     printf("Platform mapped range: %.8X-%.8X\n", cfg->mapped_low, cfg->mapped_high);
290 }
291
292 int setup_platform_amiga(struct emulator_config *cfg) {
293     printf("Performing setup for Amiga platform.\n");
294
295     if (strlen(cfg->platform->subsys)) {
296         printf("Subsystem is [%s]\n", cfg->platform->subsys);
297         if (strcmp(cfg->platform->subsys, "4000") == 0 || strcmp(cfg->platform->subsys, "3000") == 0) {
298             printf("Adjusting Gayle accesses for A3000/4000 Kickstart.\n");
299             adjust_gayle_4000();
300         }
301         else if (strcmp(cfg->platform->subsys, "1200") == 0 || strcmp(cfg->platform->subsys, "cd32") == 0) {
302             printf("Adjusting Gayle accesses for A1200/CD32 Kickstart.\n");
303             adjust_gayle_1200();
304         }
305         else if (strcmp(cfg->platform->subsys, "cdtv") == 0) {
306             printf("Configuring platform for CDTV emulation.\n");
307             cdtv_mode = 1;
308             rtc_type = RTC_TYPE_MSM;
309         }
310     }
311     else
312         printf("No sub system specified.\n");
313
314     // Look for Z2 autoconf Fast RAM by id
315     int index = get_named_mapped_item(cfg, z2_autoconf_id);
316     more_z2_fast:;
317     if (index != -1) {
318         // "Zap" config items as they are processed.
319         cfg->map_id[index][0] = '^';
320         int resize_data = 0;
321         if (cfg->map_size[index] > 8 * SIZE_MEGA) {
322             printf("Attempted to configure more than 8MB of Z2 Fast RAM, downsizing to 8MB.\n");
323             resize_data = 8 * SIZE_MEGA;
324         }
325         else if(cfg->map_size[index] != 2 * SIZE_MEGA && cfg->map_size[index] != 4 * SIZE_MEGA && cfg->map_size[index] != 8 * SIZE_MEGA) {
326             printf("Z2 Fast RAM may only provision 2, 4 or 8MB of memory, resizing to ");
327             if (cfg->map_size[index] > 8 * SIZE_MEGA)
328                 resize_data = 8 * SIZE_MEGA;
329             else if (cfg->map_size[index] > 4 * SIZE_MEGA)
330                 resize_data = 4 * SIZE_MEGA;
331             else
332                 resize_data = 2 * SIZE_MEGA;
333             printf("%dMB.\n", resize_data / SIZE_MEGA);
334         }
335         if (resize_data) {
336             free(cfg->map_data[index]);
337             cfg->map_size[index] = resize_data;
338             cfg->map_data[index] = (unsigned char *)malloc(cfg->map_size[index]);
339         }
340         printf("%dMB of Z2 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
341         add_z2_pic(ACTYPE_MAPFAST_Z2, index);
342         //ac_z2_type[ac_z2_pic_count] = ACTYPE_MAPFAST_Z2;
343         //ac_z2_index[ac_z2_pic_count] = index;
344         //ac_z2_pic_count++;
345     }
346     else
347         printf("No Z2 Fast RAM configured.\n");
348
349     index = get_named_mapped_item(cfg, z2_autoconf_id);
350     if (index != -1)
351         goto more_z2_fast;
352
353     for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i ++) {
354         // Restore any "zapped" autoconf items so they can be reinitialized if needed.
355         if (cfg->map_id[i] && strcmp(cfg->map_id[i], z2_autoconf_zap_id) == 0) {
356             cfg->map_id[i][0] = z2_autoconf_id[0];
357         }
358     }
359
360     index = get_named_mapped_item(cfg, z3_autoconf_id);
361     more_z3_fast:;
362     if (index != -1) {
363         cfg->map_id[index][0] = '^';
364         printf("%dMB of Z3 Fast RAM configured at $%lx\n", cfg->map_size[index] / SIZE_MEGA, cfg->map_offset[index]);
365         ac_z3_type[ac_z3_pic_count] = ACTYPE_MAPFAST_Z3;
366         ac_z3_index[ac_z3_pic_count] = index;
367         ac_z3_pic_count++;
368     }
369     else
370         printf("No Z3 Fast RAM configured.\n");
371     index = get_named_mapped_item(cfg, z3_autoconf_id);
372     if (index != -1)
373         goto more_z3_fast;
374     for (int i = 0; i < MAX_NUM_MAPPED_ITEMS; i++) {
375         if (cfg->map_id[i] && strcmp(cfg->map_id[i], z3_autoconf_zap_id) == 0) {
376             cfg->map_id[i][0] = z3_autoconf_id[0];
377         }
378     }
379
380     index = get_named_mapped_item(cfg, "cpu_slot_ram");
381     if (index != -1) {
382         m68k_add_ram_range((uint32_t)cfg->map_offset[index], (uint32_t)cfg->map_high[index], cfg->map_data[index]);
383     }
384
385     adjust_ranges_amiga(cfg);
386
387     if (cdtv_mode) {
388         FILE *in = fopen("data/cdtv.sram", "rb");
389         if (in != NULL) {
390             printf("Loaded CDTV SRAM.\n");
391             fread(cdtv_sram, 32 * SIZE_KILO, 1, in);
392             fclose(in);
393         }
394     }
395
396     if (pistorm_dev_enabled) {
397         add_z2_pic(ACTYPE_PISTORM_DEV, 0);
398     }
399
400     return 0;
401 }
402
403 #define CHKVAR(a) (strcmp(var, a) == 0)
404
405 void setvar_amiga(struct emulator_config *cfg, char *var, char *val) {
406     if (!var)
407         return;
408
409     if CHKVAR("enable_rtc_emulation") {
410         int8_t rtc_enabled = 0;
411         if (!val || strlen(val) == 0)
412             rtc_enabled = 1;
413         else {
414             rtc_enabled = get_int(val);
415         }
416         if (rtc_enabled != -1) {
417             configure_rtc_emulation_amiga(rtc_enabled);
418         }
419     }
420     if CHKVAR("hdd0") {
421         if (val && strlen(val) != 0)
422             set_hard_drive_image_file_amiga(0, val);
423     }
424     if CHKVAR("hdd1") {
425         if (val && strlen(val) != 0)
426             set_hard_drive_image_file_amiga(1, val);
427     }
428     if CHKVAR("cdtv") {
429         printf("[AMIGA] CDTV mode enabled.\n");
430         cdtv_mode = 1;
431     }
432     if (CHKVAR("rtg") && !rtg_enabled) {
433         if (init_rtg_data(cfg)) {
434             printf("[AMIGA] RTG Enabled.\n");
435             rtg_enabled = 1;
436             adjust_ranges_amiga(cfg);
437         }
438         else
439             printf("[AMIGA} Failed to enable RTG.\n");
440     }
441     if CHKVAR("kick13") {
442         printf("[AMIGA] Kickstart 1.3 mode enabled, Z3 PICs will not be enumerated.\n");
443         kick13_mode = 1;
444     }
445     if CHKVAR("a314") {
446         if (!a314_initialized) {
447             int32_t res = a314_init();
448             if (res != 0) {
449                 printf("[AMIGA] Failed to enable A314 emulation, error return code: %d.\n", res);
450             } else {
451                 printf("[AMIGA] A314 emulation enabled.\n");
452                 add_z2_pic(ACTYPE_A314, 0);
453                 a314_emulation_enabled = 1;
454                 a314_initialized = 1;
455             }
456         } else {
457             add_z2_pic(ACTYPE_A314, 0);
458             a314_emulation_enabled = 1;
459         }
460     }
461     if CHKVAR("a314_conf") {
462         if (val && strlen(val) != 0) {
463             a314_set_config_file(val);
464         }
465     }
466
467     // PiSCSI stuff
468     if (CHKVAR("piscsi") && !piscsi_enabled) {
469         printf("[AMIGA] PISCSI Interface Enabled.\n");
470         piscsi_enabled = 1;
471         piscsi_init();
472         add_z2_pic(ACTYPE_PISCSI, 0);
473         adjust_ranges_amiga(cfg);
474     }
475     if (piscsi_enabled) {
476         if CHKVAR("piscsi0") {
477             piscsi_map_drive(val, 0);
478         }
479         if CHKVAR("piscsi1") {
480             piscsi_map_drive(val, 1);
481         }
482         if CHKVAR("piscsi2") {
483             piscsi_map_drive(val, 2);
484         }
485         if CHKVAR("piscsi3") {
486             piscsi_map_drive(val, 3);
487         }
488         if CHKVAR("piscsi4") {
489             piscsi_map_drive(val, 4);
490         }
491         if CHKVAR("piscsi5") {
492             piscsi_map_drive(val, 5);
493         }
494         if CHKVAR("piscsi6") {
495             piscsi_map_drive(val, 6);
496         }
497     }
498
499     // Pi-Net stuff
500     if (CHKVAR("pi-net")&& !pinet_enabled) {
501         printf("[AMIGA] PI-NET Interface Enabled.\n");
502         pinet_enabled = 1;
503         pinet_init(val);
504         adjust_ranges_amiga(cfg);
505     }
506
507     if CHKVAR("no-pistorm-dev") {
508         pistorm_dev_enabled = 0;
509         printf("[AMIGA] Disabling PiStorm interaction device.\n");
510     }
511
512     // RTC stuff
513     if CHKVAR("rtc_type") {
514         if (val && strlen(val) != 0) {
515             if (strcmp(val, "msm") == 0) {
516                 printf("[AMIGA] RTC type set to MSM.\n");
517                 rtc_type = RTC_TYPE_MSM;
518             }
519             else {
520                 printf("[AMIGA] RTC type set to Ricoh.\n");
521                 rtc_type = RTC_TYPE_RICOH;
522             }
523         }
524     }
525 }
526
527 void handle_reset_amiga(struct emulator_config *cfg) {
528     ac_z2_done = (ac_z2_pic_count == 0);
529     ac_z3_done = (ac_z3_pic_count == 0);
530     ac_z2_current_pic = 0;
531     ac_z3_current_pic = 0;
532
533     DEBUG("[AMIGA] Reset handler.\n");
534     DEBUG("[AMIGA] AC done - Z2: %d Z3: %d.\n", ac_z2_done, ac_z3_done);
535
536     if (piscsi_enabled)
537         piscsi_refresh_drives();
538
539     adjust_ranges_amiga(cfg);
540 }
541
542 void shutdown_platform_amiga(struct emulator_config *cfg) {
543     printf("[AMIGA] Performing Amiga platform shutdown.\n");
544     if (cfg) {}
545     if (cdtv_mode) {
546         FILE *out = fopen("data/cdtv.sram", "wb+");
547         if (out != NULL) {
548             printf("Saving CDTV SRAM.\n");
549             fwrite(cdtv_sram, 32 * SIZE_KILO, 1, out);
550             fclose(out);
551         }
552         else {
553             printf("Failed to write CDTV SRAM to disk.\n");
554         }
555     }
556     if (cfg->platform->subsys) {
557         free(cfg->platform->subsys);
558         cfg->platform->subsys = NULL;
559     }
560     if (piscsi_enabled) {
561         piscsi_shutdown();
562         piscsi_enabled = 0;
563     }
564     if (rtg_enabled) {
565         shutdown_rtg();
566         rtg_enabled = 0;
567     }
568     if (pinet_enabled) {
569         pinet_enabled = 0;
570     }
571     if (a314_emulation_enabled) {
572         a314_emulation_enabled = 0;
573     }
574
575     mouse_hook_enabled = 0;
576     kb_hook_enabled = 0;
577
578     kick13_mode = 0;
579     cdtv_mode = 0;
580
581     autoconfig_reset_all();
582     printf("[AMIGA] Platform shutdown completed.\n");
583 }
584
585 void create_platform_amiga(struct platform_config *cfg, char *subsys) {
586     cfg->register_read = handle_register_read_amiga;
587     cfg->register_write = handle_register_write_amiga;
588     cfg->custom_read = custom_read_amiga;
589     cfg->custom_write = custom_write_amiga;
590     cfg->platform_initial_setup = setup_platform_amiga;
591     cfg->handle_reset = handle_reset_amiga;
592     cfg->shutdown = shutdown_platform_amiga;
593
594     cfg->setvar = setvar_amiga;
595     cfg->id = PLATFORM_AMIGA;
596
597     if (subsys) {
598         cfg->subsys = malloc(strlen(subsys) + 1);
599         strcpy(cfg->subsys, subsys);
600         for (unsigned int i = 0; i < strlen(cfg->subsys); i++) {
601             cfg->subsys[i] = tolower(cfg->subsys[i]);
602         }
603     }
604 }