3 #include "platforms/platforms.h"
4 #include "input/input.h"
6 #include "platforms/amiga/Gayle.h"
7 #include "platforms/amiga/amiga-registers.h"
8 #include "platforms/amiga/rtg/rtg.h"
9 #include "platforms/amiga/hunk-reloc.h"
10 #include "platforms/amiga/piscsi/piscsi.h"
11 #include "platforms/amiga/piscsi/piscsi-enums.h"
12 #include "platforms/amiga/net/pi-net.h"
13 #include "platforms/amiga/net/pi-net-enums.h"
14 #include "gpio/ps_protocol.h"
28 #include <sys/ioctl.h>
31 #include <sys/types.h>
34 #define KEY_POLL_INTERVAL_MSEC 5000
36 unsigned char read_ranges;
37 unsigned int read_addr[8];
38 unsigned int read_upper[8];
39 unsigned char *read_data[8];
40 unsigned char write_ranges;
41 unsigned int write_addr[8];
42 unsigned int write_upper[8];
43 unsigned char *write_data[8];
45 int kb_hook_enabled = 0;
46 int mouse_hook_enabled = 0;
47 int cpu_emulation_running = 1;
49 uint8_t mouse_dx = 0, mouse_dy = 0;
50 uint8_t mouse_buttons = 0;
51 uint8_t mouse_extra = 0;
53 extern uint8_t gayle_int;
54 extern uint8_t gayle_ide_enabled;
55 extern uint8_t gayle_emulation_enabled;
56 extern uint8_t gayle_a4k_int;
57 extern volatile unsigned int *gpio;
58 extern volatile uint16_t srdata;
59 extern uint8_t realtime_graphics_debug;
60 uint8_t realtime_disassembly, int2_enabled = 0;
61 uint32_t do_disasm = 0, old_level;
62 uint32_t last_irq = 8, last_last_irq = 8;
64 char disasm_buf[4096];
66 #define KICKBASE 0xF80000
67 #define KICKSIZE 0x7FFFF
69 int mem_fd, mouse_fd = -1, keyboard_fd = -1;
78 extern m68ki_cpu_core m68ki_cpu;
79 extern int m68ki_initial_cycles;
80 extern int m68ki_remaining_cycles;
82 #define M68K_SET_IRQ(i) old_level = CPU_INT_LEVEL; \
83 CPU_INT_LEVEL = (i << 8); \
84 if(old_level != 0x0700 && CPU_INT_LEVEL == 0x0700) \
85 m68ki_cpu.nmi_pending = TRUE;
86 #define M68K_END_TIMESLICE m68ki_initial_cycles = GET_CYCLES(); \
89 #define M68K_SET_IRQ m68k_set_irq
90 #define M68K_END_TIMESLICE m68k_end_timeslice()
93 #define NOP asm("nop"); asm("nop"); asm("nop"); asm("nop");
95 #define DEBUG_EMULATOR
102 // Configurable emulator options
103 unsigned int cpu_type = M68K_CPU_TYPE_68000;
104 unsigned int loop_cycles = 300, irq_status = 0;
105 struct emulator_config *cfg = NULL;
106 char keyboard_file[256] = "/dev/input/event1";
108 uint64_t trig_irq = 0, serv_irq = 0;
109 uint16_t irq_delay = 0;
110 unsigned int amiga_reset=0, amiga_reset_last=0;
111 unsigned int do_reset=0;
113 void *ipl_task(void *args) {
114 printf("IPL thread running\n");
115 uint16_t old_irq = 0;
119 value = *(gpio + 13);
121 if (!(value & (1 << PIN_IPL_ZERO))) {
144 amiga_reset=(value & (1 << PIN_RESET));
145 if(amiga_reset!=amiga_reset_last)
147 amiga_reset_last=amiga_reset;
150 printf("Amiga Reset is down...\n");
156 printf("Amiga Reset is up...\n");
161 /*if (gayle_ide_enabled) {
162 if (((gayle_int & 0x80) || gayle_a4k_int) && (get_ide(0)->drive[0].intrq || get_ide(0)->drive[1].intrq)) {
163 //get_ide(0)->drive[0].intrq = 0;
172 NOP NOP NOP NOP NOP NOP NOP NOP
173 //NOP NOP NOP NOP NOP NOP NOP NOP
174 //NOP NOP NOP NOP NOP NOP NOP NOP
175 /*NOP NOP NOP NOP NOP NOP NOP NOP
176 NOP NOP NOP NOP NOP NOP NOP NOP
177 NOP NOP NOP NOP NOP NOP NOP NOP*/
186 if (mouse_hook_enabled) {
187 get_mouse_status(&mouse_dx, &mouse_dy, &mouse_buttons, &mouse_extra);
190 if (realtime_disassembly && (do_disasm || cpu_emulation_running)) {
191 m68k_disassemble(disasm_buf, m68k_get_reg(NULL, M68K_REG_PC), cpu_type);
192 printf("REGA: 0:$%.8X 1:$%.8X 2:$%.8X 3:$%.8X 4:$%.8X 5:$%.8X 6:$%.8X 7:$%.8X\n", m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1), m68k_get_reg(NULL, M68K_REG_A2), m68k_get_reg(NULL, M68K_REG_A3), \
193 m68k_get_reg(NULL, M68K_REG_A4), m68k_get_reg(NULL, M68K_REG_A5), m68k_get_reg(NULL, M68K_REG_A6), m68k_get_reg(NULL, M68K_REG_A7));
194 printf("REGD: 0:$%.8X 1:$%.8X 2:$%.8X 3:$%.8X 4:$%.8X 5:$%.8X 6:$%.8X 7:$%.8X\n", m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2), m68k_get_reg(NULL, M68K_REG_D3), \
195 m68k_get_reg(NULL, M68K_REG_D4), m68k_get_reg(NULL, M68K_REG_D5), m68k_get_reg(NULL, M68K_REG_D6), m68k_get_reg(NULL, M68K_REG_D7));
196 printf("%.8X (%.8X)]] %s\n", m68k_get_reg(NULL, M68K_REG_PC), (m68k_get_reg(NULL, M68K_REG_PC) & 0xFFFFFF), disasm_buf);
202 if (cpu_emulation_running)
203 m68k_execute(loop_cycles);
208 last_irq = ((read_reg() & 0xe000) >> 13);
209 if (last_irq != last_last_irq) {
210 last_last_irq = last_irq;
211 M68K_SET_IRQ(last_irq);
215 if (gayleirq && int2_enabled) {
216 write16(0xdff09c, 0x8000 | (1 << 3) && last_irq != 2);
217 last_last_irq = last_irq;
228 last_last_irq = last_irq;
236 usleep(1000000); // 1sec
237 // while(amiga_reset==0);
238 // printf("CPU emulation reset.\n");
242 if (mouse_hook_enabled && (mouse_extra != 0x00)) {
243 // mouse wheel events have occurred; unlike l/m/r buttons, these are queued as keypresses, so add to end of buffer
244 switch (mouse_extra) {
247 queue_keypress(0xfe, KEYPRESS_PRESS, PLATFORM_AMIGA);
251 queue_keypress(0xff, KEYPRESS_PRESS, PLATFORM_AMIGA);
255 // dampen the scroll wheel until next while loop iteration
260 //stop_cpu_emulation:
261 printf("[CPU] End of CPU thread\n");
264 void *keyboard_task() {
265 struct pollfd kbdpoll[1];
267 char c = 0, c_code = 0, c_type = 0;
268 char grab_message[] = "[KBD] Grabbing keyboard from input layer\n",
269 ungrab_message[] = "[KBD] Ungrabbing keyboard\n";
271 printf("[KBD] Keyboard thread started\n");
273 // because we permit the keyboard to be grabbed on startup, quickly check if we need to grab it
274 if (kb_hook_enabled && cfg->keyboard_grab) {
275 printf(grab_message);
276 grab_device(keyboard_fd);
279 kbdpoll[0].fd = keyboard_fd;
280 kbdpoll[0].events = POLLIN;
283 kpollrc = poll(kbdpoll, 1, KEY_POLL_INTERVAL_MSEC);
284 if ((kpollrc > 0) && (kbdpoll[0].revents & POLLHUP)) {
285 // in the event that a keyboard is unplugged, keyboard_task will whiz up to 100% utilisation
286 // this is undesired, so if the keyboard HUPs, end the thread without ending the emulation
287 printf("[KBD] Keyboard node returned HUP (unplugged?)\n");
291 // if kpollrc > 0 then it contains number of events to pull, also check if POLLIN is set in revents
292 if ((kpollrc <= 0) || !(kbdpoll[0].revents & POLLIN)) {
296 while (get_key_char(&c, &c_code, &c_type)) {
297 if (c && c == cfg->keyboard_toggle_key && !kb_hook_enabled) {
299 printf("[KBD] Keyboard hook enabled.\n");
300 if (cfg->keyboard_grab) {
301 grab_device(keyboard_fd);
302 printf(grab_message);
304 } else if (kb_hook_enabled) {
305 if (c == 0x1B && c_type) {
307 printf("[KBD] Keyboard hook disabled.\n");
308 if (cfg->keyboard_grab) {
309 release_device(keyboard_fd);
310 printf(ungrab_message);
313 if (queue_keypress(c_code, c_type, cfg->platform->id) && int2_enabled && last_irq != 2) {
320 // pause pressed; trigger nmi (int level 7)
321 if (c == 0x01 && c_type) {
322 printf("[INT] Sending NMI\n");
326 if (!kb_hook_enabled && c_type) {
327 if (c && c == cfg->mouse_toggle_key) {
328 mouse_hook_enabled ^= 1;
329 printf("Mouse hook %s.\n", mouse_hook_enabled ? "enabled" : "disabled");
330 mouse_dx = mouse_dy = mouse_buttons = mouse_extra = 0;
333 cpu_emulation_running ^= 1;
334 printf("CPU emulation is now %s\n", cpu_emulation_running ? "running" : "stopped");
337 realtime_graphics_debug ^= 1;
338 printf("Real time graphics debug is now %s\n", realtime_graphics_debug ? "on" : "off");
342 //m68k_pulse_reset();
343 printf("CPU emulation reset.\n");
345 // @todo work out how to signal the main process that we want to quit
347 // printf("Quitting and exiting emulator.\n");
348 // goto stop_cpu_emulation;
351 realtime_disassembly ^= 1;
353 printf("Real time disassembly is now %s\n", realtime_disassembly ? "on" : "off");
356 int r = get_mapped_item_by_address(cfg, 0x08000000);
358 printf("Dumping first 16MB of mapped range %d.\n", r);
359 FILE *dmp = fopen("./memdmp.bin", "wb+");
360 fwrite(cfg->map_data[r], 16 * SIZE_MEGA, 1, dmp);
364 if (c == 's' && realtime_disassembly) {
367 if (c == 'S' && realtime_disassembly) {
376 printf("[KBD] Keyboard thread ending\n");
380 void stop_cpu_emulation(uint8_t disasm_cur) {
383 m68k_disassemble(disasm_buf, m68k_get_reg(NULL, M68K_REG_PC), cpu_type);
384 printf("REGA: 0:$%.8X 1:$%.8X 2:$%.8X 3:$%.8X 4:$%.8X 5:$%.8X 6:$%.8X 7:$%.8X\n", m68k_get_reg(NULL, M68K_REG_A0), m68k_get_reg(NULL, M68K_REG_A1), m68k_get_reg(NULL, M68K_REG_A2), m68k_get_reg(NULL, M68K_REG_A3), \
385 m68k_get_reg(NULL, M68K_REG_A4), m68k_get_reg(NULL, M68K_REG_A5), m68k_get_reg(NULL, M68K_REG_A6), m68k_get_reg(NULL, M68K_REG_A7));
386 printf("REGD: 0:$%.8X 1:$%.8X 2:$%.8X 3:$%.8X 4:$%.8X 5:$%.8X 6:$%.8X 7:$%.8X\n", m68k_get_reg(NULL, M68K_REG_D0), m68k_get_reg(NULL, M68K_REG_D1), m68k_get_reg(NULL, M68K_REG_D2), m68k_get_reg(NULL, M68K_REG_D3), \
387 m68k_get_reg(NULL, M68K_REG_D4), m68k_get_reg(NULL, M68K_REG_D5), m68k_get_reg(NULL, M68K_REG_D6), m68k_get_reg(NULL, M68K_REG_D7));
388 printf("%.8X (%.8X)]] %s\n", m68k_get_reg(NULL, M68K_REG_PC), (m68k_get_reg(NULL, M68K_REG_PC) & 0xFFFFFF), disasm_buf);
389 realtime_disassembly = 1;
392 cpu_emulation_running = 0;
397 static volatile unsigned char maprom;
399 void sigint_handler(int sig_num) {
401 //cpu_emulation_running = 0;
404 printf("Received sigint %d, exiting.\n", sig_num);
410 if (cfg->platform->shutdown) {
411 cfg->platform->shutdown(cfg);
414 printf("IRQs triggered: %lld\n", trig_irq);
415 printf("IRQs serviced: %lld\n", serv_irq);
420 int main(int argc, char *argv[]) {
422 //const struct sched_param priority = {99};
425 irq_delay = atoi(argv[1]);
426 printf("Setting IRQ delay to %d loops (%s).\n", irq_delay, argv[1]);
429 // Some command line switch stuffles
430 for (g = 1; g < argc; g++) {
431 if (strcmp(argv[g], "--cpu_type") == 0 || strcmp(argv[g], "--cpu") == 0) {
433 printf("%s switch found, but no CPU type specified.\n", argv[g]);
436 cpu_type = get_m68k_cpu_type(argv[g]);
439 else if (strcmp(argv[g], "--config-file") == 0 || strcmp(argv[g], "--config") == 0) {
441 printf("%s switch found, but no config filename specified.\n", argv[g]);
444 cfg = load_config_file(argv[g]);
447 else if (strcmp(argv[g], "--keyboard-file") == 0 || strcmp(argv[g], "--kbfile") == 0) {
449 printf("%s switch found, but no keyboard device path specified.\n", argv[g]);
452 strcpy(keyboard_file, argv[g]);
458 printf("No config file specified. Trying to load default.cfg...\n");
459 cfg = load_config_file("default.cfg");
461 printf("Couldn't load default.cfg, empty emulator config will be used.\n");
462 cfg = (struct emulator_config *)calloc(1, sizeof(struct emulator_config));
464 printf("Failed to allocate memory for emulator config!\n");
467 memset(cfg, 0x00, sizeof(struct emulator_config));
472 if (cfg->cpu_type) cpu_type = cfg->cpu_type;
473 if (cfg->loop_cycles) loop_cycles = cfg->loop_cycles;
476 cfg->platform = make_platform_config("none", "generic");
477 cfg->platform->platform_initial_setup(cfg);
480 if (cfg->mouse_enabled) {
481 mouse_fd = open(cfg->mouse_file, O_RDWR | O_NONBLOCK);
482 if (mouse_fd == -1) {
483 printf("Failed to open %s, can't enable mouse hook.\n", cfg->mouse_file);
484 cfg->mouse_enabled = 0;
487 * *-*-*-* magic numbers! *-*-*-*
488 * great, so waaaay back in the history of the pc, the ps/2 protocol set the standard for mice
489 * and in the process, the mouse sample rate was defined as a way of putting mice into vendor-specific modes.
490 * as the ancient gpm command explains, almost everything except incredibly old mice talk the IntelliMouse
491 * protocol, which reports four bytes. by default, every mouse starts in 3-byte mode (don't report wheel or
492 * additional buttons) until imps2 magic is sent. so, command $f3 is "set sample rate", followed by a byte.
494 uint8_t mouse_init[] = { 0xf4, 0xf3, 0x64 }; // enable, then set sample rate 100
495 uint8_t imps2_init[] = { 0xf3, 0xc8, 0xf3, 0x64, 0xf3, 0x50 }; // magic sequence; set sample 200, 100, 80
496 if (write(mouse_fd, mouse_init, sizeof(mouse_init)) != -1) {
497 if (write(mouse_fd, imps2_init, sizeof(imps2_init)) == -1)
498 printf("[MOUSE] Couldn't enable scroll wheel events; is this mouse from the 1980s?\n");
500 printf("[MOUSE] Mouse didn't respond to normal PS/2 init; have you plugged a brick in by mistake?\n");
504 if (cfg->keyboard_file)
505 keyboard_fd = open(cfg->keyboard_file, O_RDONLY | O_NONBLOCK);
507 keyboard_fd = open(keyboard_file, O_RDONLY | O_NONBLOCK);
509 if (keyboard_fd == -1) {
510 printf("Failed to open keyboard event source.\n");
515 signal(SIGINT, sigint_handler);
518 //goto skip_everything;
520 // Enable 200MHz CLK output on GPIO4, adjust divider and pll source depending
522 printf("Enable 200MHz GPCLK0 on GPIO4\n");
523 gpio_enable_200mhz();
525 // reset cpld statemachine first
533 // reset amiga and statemachine
539 printf("Setting CPU type to %d.\n", cpu_type);
540 m68k_set_cpu_type(cpu_type);
544 m68k_set_reg(M68K_REG_PC, 0xF80002);
546 m68k_set_reg(M68K_REG_PC, 0x0);
549 ps_reset_state_machine();
554 printf("Setting CPU type to %d.\n", cpu_type);
555 m68k_set_cpu_type(cpu_type);
558 pthread_t ipl_tid, cpu_tid, kbd_tid;
560 err = pthread_create(&ipl_tid, NULL, &ipl_task, NULL);
562 printf("[ERROR] Cannot create IPL thread: [%s]", strerror(err));
564 pthread_setname_np(ipl_tid, "pistorm: ipl");
565 printf("IPL thread created successfully\n");
568 // create keyboard task
569 err = pthread_create(&kbd_tid, NULL, &keyboard_task, NULL);
571 printf("[ERROR] Cannot create keyboard thread: [%s]", strerror(err));
573 pthread_setname_np(kbd_tid, "pistorm: kbd");
574 printf("[MAIN] Keyboard thread created successfully\n");
578 err = pthread_create(&cpu_tid, NULL, &cpu_task, NULL);
580 printf("[ERROR] Cannot create CPU thread: [%s]", strerror(err));
582 pthread_setname_np(cpu_tid, "pistorm: cpu");
583 printf("[MAIN] CPU thread created successfully\n");
586 // wait for cpu task to end before closing up and finishing
587 pthread_join(cpu_tid, NULL);
588 printf("[MAIN] All threads appear to have concluded; ending process\n");
598 void cpu_pulse_reset(void) {
601 // printf("Status Reg%x\n",read_reg());
604 // printf("Status Reg%x\n",read_reg());
605 if (cfg->platform->handle_reset)
606 cfg->platform->handle_reset(cfg);
608 //m68k_write_memory_16(INTENA, 0x7FFF);
610 m68k_write_memory_8(0xbfe201, 0x0001); // AMIGA OVL
611 m68k_write_memory_8(0xbfe001, 0x0001); // AMIGA OVL high (ROM@0x0)
616 int cpu_irq_ack(int level) {
617 printf("cpu irq ack\n");
621 static unsigned int target = 0;
622 static uint8_t send_keypress = 0;
624 uint8_t cdtv_dmac_reg_idx_read();
625 void cdtv_dmac_reg_idx_write(uint8_t value);
626 uint32_t cdtv_dmac_read(uint32_t address, uint8_t type);
627 void cdtv_dmac_write(uint32_t address, uint32_t value, uint8_t type);
629 #define PLATFORM_CHECK_READ(a) \
630 if (address >= cfg->custom_low && address < cfg->custom_high) { \
631 unsigned int target = 0; \
632 switch(cfg->platform->id) { \
633 case PLATFORM_AMIGA: { \
634 if (address >= PISCSI_OFFSET && address < PISCSI_UPPER) { \
635 return handle_piscsi_read(address, a); \
637 if (address >= PINET_OFFSET && address < PINET_UPPER) { \
638 return handle_pinet_read(address, a); \
640 if (address >= PIGFX_RTG_BASE && address < PIGFX_UPPER) { \
641 return rtg_read((address & 0x0FFFFFFF), a); \
643 if (custom_read_amiga(cfg, address, &target, a) != -1) { \
652 if (ovl || (address >= cfg->mapped_low && address < cfg->mapped_high)) { \
653 if (handle_mapped_read(cfg, address, &target, a) != -1) \
657 unsigned int m68k_read_memory_8(unsigned int address) {
658 PLATFORM_CHECK_READ(OP_TYPE_BYTE);
660 /*if (address >= 0xE90000 && address < 0xF00000) {
661 printf("BYTE read from DMAC @%.8X:", address);
662 uint32_t v = cdtv_dmac_read(address & 0xFFFF, OP_TYPE_BYTE);
665 cpu_emulation_running = 0;
669 /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x080032F0 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x080032F0 + 0x4000) {
670 stop_cpu_emulation(1);
674 if (address & 0xFF000000)
677 unsigned char result = (unsigned int)read8((uint32_t)address);
679 if (mouse_hook_enabled) {
680 if (address == CIAAPRA) {
681 if (mouse_buttons & 0x01) {
682 //mouse_buttons -= 1;
683 return (unsigned int)(result ^ 0x40);
686 return (unsigned int)result;
690 if (kb_hook_enabled) {
691 if (address == CIAAICR) {
692 if (get_num_kb_queued() && (!send_keypress || send_keypress == 1)) {
697 if (send_keypress == 2) {
703 if (address == CIAADAT) {
704 //if (send_keypress) {
705 uint8_t c = 0, t = 0;
706 pop_queued_key(&c, &t);
708 result = ((c << 1) | t) ^ 0xFF;
719 unsigned int m68k_read_memory_16(unsigned int address) {
720 PLATFORM_CHECK_READ(OP_TYPE_WORD);
722 /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x080032F0 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x080032F0 + 0x4000) {
723 stop_cpu_emulation(1);
726 /*if (address >= 0xE90000 && address < 0xF00000) {
727 printf("WORD read from DMAC @%.8X:", address);
728 uint32_t v = cdtv_dmac_read(address & 0xFFFF, OP_TYPE_WORD);
731 cpu_emulation_running = 0;
735 if (mouse_hook_enabled) {
736 if (address == JOY0DAT) {
737 // Forward mouse valueses to Amyga.
738 unsigned short result = (mouse_dy << 8) | (mouse_dx);
739 return (unsigned int)result;
741 /*if (address == CIAAPRA) {
742 unsigned short result = (unsigned int)read16((uint32_t)address);
743 if (mouse_buttons & 0x01) {
744 return (unsigned int)(result | 0x40);
747 return (unsigned int)result;
749 if (address == POTGOR) {
750 unsigned short result = (unsigned int)read16((uint32_t)address);
751 // bit 1 rmb, bit 2 mmb
752 if (mouse_buttons & 0x06) {
753 return (unsigned int)((result ^ ((mouse_buttons & 0x02) << 9)) // move rmb to bit 10
754 & (result ^ ((mouse_buttons & 0x04) << 6))); // move mmb to bit 8
756 return (unsigned int)(result & 0xfffd);
760 if (address & 0xFF000000)
763 if (address & 0x01) {
764 return ((read8(address) << 8) | read8(address + 1));
766 return (unsigned int)read16((uint32_t)address);
769 unsigned int m68k_read_memory_32(unsigned int address) {
770 PLATFORM_CHECK_READ(OP_TYPE_LONGWORD);
772 /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x080032F0 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x080032F0 + 0x4000) {
773 stop_cpu_emulation(1);
776 /*if (address >= 0xE90000 && address < 0xF00000) {
777 printf("LONGWORD read from DMAC @%.8X:", address);
778 uint32_t v = cdtv_dmac_read(address & 0xFFFF, OP_TYPE_LONGWORD);
781 cpu_emulation_running = 0;
785 if (address & 0xFF000000)
788 if (address & 0x01) {
789 uint32_t c = read8(address);
790 c |= (be16toh(read16(address+1)) << 8);
791 c |= (read8(address + 3) << 24);
794 uint16_t a = read16(address);
795 uint16_t b = read16(address + 2);
796 return (a << 16) | b;
799 #define PLATFORM_CHECK_WRITE(a) \
800 if (address >= cfg->custom_low && address < cfg->custom_high) { \
801 switch(cfg->platform->id) { \
802 case PLATFORM_AMIGA: { \
803 if (address >= PISCSI_OFFSET && address < PISCSI_UPPER) { \
804 handle_piscsi_write(address, value, a); \
806 if (address >= PINET_OFFSET && address < PINET_UPPER) { \
807 handle_pinet_write(address, value, a); \
809 if (address >= PIGFX_RTG_BASE && address < PIGFX_UPPER) { \
810 rtg_write((address & 0x0FFFFFFF), value, a); \
813 if (custom_write_amiga(cfg, address, value, a) != -1) { \
822 if (address >= cfg->mapped_low && address < cfg->mapped_high) { \
823 if (handle_mapped_write(cfg, address, value, a) != -1) \
827 void m68k_write_memory_8(unsigned int address, unsigned int value) {
828 PLATFORM_CHECK_WRITE(OP_TYPE_BYTE);
830 /*if (address >= 0xE90000 && address < 0xF00000) {
831 printf("BYTE write to DMAC @%.8X: %.2X\n", address, value);
832 cdtv_dmac_write(address & 0xFFFF, value, OP_TYPE_BYTE);
834 cpu_emulation_running = 0;
838 if (address == 0xbfe001) {
839 if (ovl != (value & (1 << 0))) {
840 ovl = (value & (1 << 0));
841 printf("OVL:%x\n", ovl);
845 if (address & 0xFF000000)
848 write8((uint32_t)address, value);
852 void m68k_write_memory_16(unsigned int address, unsigned int value) {
853 PLATFORM_CHECK_WRITE(OP_TYPE_WORD);
855 /*if (address >= 0xE90000 && address < 0xF00000) {
856 printf("WORD write to DMAC @%.8X: %.4X\n", address, value);
857 cdtv_dmac_write(address & 0xFFFF, value, OP_TYPE_WORD);
859 cpu_emulation_running = 0;
863 if (address == 0xDFF030) {
864 char *serdat = (char *)&value;
865 // SERDAT word. see amiga dev docs appendix a; upper byte is control codes, and bit 0 is always 1.
866 // ignore this upper byte as it's not viewable data, only display lower byte.
867 printf("%c", serdat[0]);
869 if (address == 0xDFF09A) {
870 if (!(value & 0x8000)) {
875 else if (value & 0x04) {
880 if (address & 0xFF000000)
884 printf("Unaligned WORD write!\n");
886 write16((uint32_t)address, value);
890 void m68k_write_memory_32(unsigned int address, unsigned int value) {
891 PLATFORM_CHECK_WRITE(OP_TYPE_LONGWORD);
893 /*if (address >= 0xE90000 && address < 0xF00000) {
894 printf("LONGWORD write to DMAC @%.8X: %.8X\n", address, value);
895 cdtv_dmac_write(address & 0xFFFF, value, OP_TYPE_LONGWORD);
897 cpu_emulation_running = 0;
901 if (address & 0xFF000000)
905 printf("Unaligned LONGWORD write!\n");
907 write16(address, value >> 16);
908 write16(address + 2, value);