]> git.sesse.net Git - pistorm/blob - emulator.c
[WIP] Pile of stuff
[pistorm] / emulator.c
1 #include <assert.h>
2 #include <dirent.h>
3 #include <endian.h>
4 #include <fcntl.h>
5 #include <pthread.h>
6 #include <sched.h>
7 #include <signal.h>
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <sys/mman.h>
13 #include <sys/stat.h>
14 #include <sys/types.h>
15 #include <unistd.h>
16 #include <sys/ioctl.h>
17 #include "m68k.h"
18 #include "main.h"
19 #include "platforms/platforms.h"
20 #include "input/input.h"
21
22 #include "platforms/amiga/Gayle.h"
23 #include "platforms/amiga/gayle-ide/ide.h"
24 #include "platforms/amiga/amiga-registers.h"
25 #include "platforms/amiga/rtg/rtg.h"
26 #include "platforms/amiga/piscsi/piscsi.h"
27 #include "platforms/amiga/piscsi/piscsi-enums.h"
28 #include "platforms/amiga/net/pi-net.h"
29 #include "platforms/amiga/net/pi-net-enums.h"
30 #include "gpio/ps_protocol.h"
31
32 unsigned char read_ranges;
33 unsigned int read_addr[8];
34 unsigned int read_upper[8];
35 unsigned char *read_data[8];
36 unsigned char write_ranges;
37 unsigned int write_addr[8];
38 unsigned int write_upper[8];
39 unsigned char *write_data[8];
40
41 int kb_hook_enabled = 0;
42 int mouse_hook_enabled = 0;
43 int cpu_emulation_running = 1;
44
45 char mouse_dx = 0, mouse_dy = 0;
46 char mouse_buttons = 0;
47
48 extern uint8_t gayle_int;
49 extern uint8_t gayle_a4k_int;
50 extern volatile unsigned int *gpio;
51 extern volatile uint16_t srdata;
52 extern uint8_t realtime_graphics_debug;
53 uint8_t realtime_disassembly, int2_enabled = 0;
54 uint32_t do_disasm = 0;
55
56 char disasm_buf[4096];
57
58 #define KICKBASE 0xF80000
59 #define KICKSIZE 0x7FFFF
60
61 int mem_fd, mouse_fd = -1, keyboard_fd = -1;
62 int mem_fd_gpclk;
63 int gayle_emulation_enabled = 1;
64 int irq;
65 int gayleirq;
66
67 // Configurable emulator options
68 unsigned int cpu_type = M68K_CPU_TYPE_68000;
69 unsigned int loop_cycles = 300;
70 struct emulator_config *cfg = NULL;
71 char keyboard_file[256] = "/dev/input/event1";
72
73 void *iplThread(void *args) {
74   printf("IPL thread running\n");
75
76   while (1) {
77     if (!gpio_get_irq()) {
78       irq = 1;
79       m68k_end_timeslice();
80     }
81     else
82       irq = 0;
83
84     if (gayle_emulation_enabled) {
85       if (((gayle_int & 0x80) || gayle_a4k_int) && (get_ide(0)->drive[0].intrq || get_ide(0)->drive[1].intrq)) {
86         //get_ide(0)->drive[0].intrq = 0;
87         gayleirq = 1;
88         m68k_end_timeslice();
89       }
90       else
91         gayleirq = 0;
92     }
93     usleep(0);
94   }
95   return args;
96 }
97
98 void stop_cpu_emulation(uint8_t disasm_cur) {
99   m68k_end_timeslice();
100   if (disasm_cur) {
101     m68k_disassemble(disasm_buf, m68k_get_reg(NULL, M68K_REG_PC), cpu_type);
102     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), \
103             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));
104     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), \
105             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));
106     printf("%.8X (%.8X)]] %s\n", m68k_get_reg(NULL, M68K_REG_PC), (m68k_get_reg(NULL, M68K_REG_PC) & 0xFFFFFF), disasm_buf);
107     realtime_disassembly = 1;
108   }
109
110   cpu_emulation_running = 0;
111   do_disasm = 0;
112 }
113
114 //unsigned char g_kick[524288];
115 //unsigned char g_ram[FASTSIZE + 1]; /* RAM */
116 int ovl;
117 static volatile unsigned char maprom;
118
119 void sigint_handler(int sig_num) {
120   //if (sig_num) { }
121   //cpu_emulation_running = 0;
122
123   //return;
124   printf("Received sigint %d, exiting.\n", sig_num);
125   if (mouse_fd != -1)
126     close(mouse_fd);
127   if (mem_fd)
128     close(mem_fd);
129
130   if (cfg->platform->shutdown) {
131     cfg->platform->shutdown(cfg);
132   }
133
134   exit(0);
135 }
136
137 int main(int argc, char *argv[]) {
138   int g;
139   const struct sched_param priority = {99};
140
141   // Some command line switch stuffles
142   for (g = 1; g < argc; g++) {
143     if (strcmp(argv[g], "--disable-gayle") == 0) {
144       gayle_emulation_enabled = 0;
145     }
146     else if (strcmp(argv[g], "--cpu_type") == 0 || strcmp(argv[g], "--cpu") == 0) {
147       if (g + 1 >= argc) {
148         printf("%s switch found, but no CPU type specified.\n", argv[g]);
149       } else {
150         g++;
151         cpu_type = get_m68k_cpu_type(argv[g]);
152       }
153     }
154     else if (strcmp(argv[g], "--config-file") == 0 || strcmp(argv[g], "--config") == 0) {
155       if (g + 1 >= argc) {
156         printf("%s switch found, but no config filename specified.\n", argv[g]);
157       } else {
158         g++;
159         cfg = load_config_file(argv[g]);
160       }
161     }
162     else if (strcmp(argv[g], "--keyboard-file") == 0 || strcmp(argv[g], "--kbfile") == 0) {
163       if (g + 1 >= argc) {
164         printf("%s switch found, but no keyboard device path specified.\n", argv[g]);
165       } else {
166         g++;
167         strcpy(keyboard_file, argv[g]);
168       }
169     }
170   }
171
172   if (!cfg) {
173     printf("No config file specified. Trying to load default.cfg...\n");
174     cfg = load_config_file("default.cfg");
175     if (!cfg) {
176       printf("Couldn't load default.cfg, empty emulator config will be used.\n");
177       cfg = (struct emulator_config *)calloc(1, sizeof(struct emulator_config));
178       if (!cfg) {
179         printf("Failed to allocate memory for emulator config!\n");
180         return 1;
181       }
182       memset(cfg, 0x00, sizeof(struct emulator_config));
183     }
184   }
185
186   if (cfg) {
187     if (cfg->cpu_type) cpu_type = cfg->cpu_type;
188     if (cfg->loop_cycles) loop_cycles = cfg->loop_cycles;
189
190     if (!cfg->platform)
191       cfg->platform = make_platform_config("none", "generic");
192     cfg->platform->platform_initial_setup(cfg);
193   }
194
195   if (cfg->mouse_enabled) {
196     mouse_fd = open(cfg->mouse_file, O_RDONLY | O_NONBLOCK);
197     if (mouse_fd == -1) {
198       printf("Failed to open %s, can't enable mouse hook.\n", cfg->mouse_file);
199       cfg->mouse_enabled = 0;
200     }
201   }
202
203   keyboard_fd = open(keyboard_file, O_RDONLY | O_NONBLOCK);
204   if (keyboard_fd == -1) {
205     printf("Failed to open keyboard event source.\n");
206   }
207
208   InitGayle();
209
210   signal(SIGINT, sigint_handler);
211   /*setup_io();
212
213   //goto skip_everything;
214
215   // Enable 200MHz CLK output on GPIO4, adjust divider and pll source depending
216   // on pi model
217   printf("Enable 200MHz GPCLK0 on GPIO4\n");
218   gpio_enable_200mhz();
219
220   // reset cpld statemachine first
221
222   write_reg(0x01);
223   usleep(100);
224   usleep(1500);
225   write_reg(0x00);
226   usleep(100);
227
228   // reset amiga and statemachine
229   skip_everything:;
230
231   usleep(1500);
232
233   m68k_init();
234   printf("Setting CPU type to %d.\n", cpu_type);
235   m68k_set_cpu_type(cpu_type);
236   cpu_pulse_reset();
237
238   if (maprom == 1) {
239     m68k_set_reg(M68K_REG_PC, 0xF80002);
240   } else {
241     m68k_set_reg(M68K_REG_PC, 0x0);
242   }*/
243   ps_setup_protocol();
244   ps_reset_state_machine();
245   ps_pulse_reset();
246
247   usleep(1500);
248   m68k_init();
249   printf("Setting CPU type to %d.\n", cpu_type);
250   m68k_set_cpu_type(cpu_type);
251   cpu_pulse_reset();
252
253   char c = 0, c_code = 0, c_type = 0;
254
255   pthread_t id;
256   int err;
257   err = pthread_create(&id, NULL, &iplThread, NULL);
258   if (err != 0)
259     printf("can't create IPL thread :[%s]", strerror(err));
260   else
261     printf("IPL Thread created successfully\n");
262
263   m68k_pulse_reset();
264   while (42) {
265     if (mouse_hook_enabled) {
266       get_mouse_status(&mouse_dx, &mouse_dy, &mouse_buttons);
267     }
268
269     if (realtime_disassembly && (do_disasm || cpu_emulation_running)) {
270       m68k_disassemble(disasm_buf, m68k_get_reg(NULL, M68K_REG_PC), cpu_type);
271       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), \
272               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));
273       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), \
274               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));
275       printf("%.8X (%.8X)]] %s\n", m68k_get_reg(NULL, M68K_REG_PC), (m68k_get_reg(NULL, M68K_REG_PC) & 0xFFFFFF), disasm_buf);
276       if (do_disasm)
277         do_disasm--;
278       m68k_execute(1);
279     }
280     else {
281       if (cpu_emulation_running)
282         m68k_execute(loop_cycles);
283     }
284
285     if (irq) {
286       unsigned int status = read_reg();
287       m68k_set_irq((status & 0xe000) >> 13);
288     }
289     else if (gayleirq && int2_enabled) {
290       write16(0xdff09c, 0x8000 | (1 << 3));
291       m68k_set_irq(2);
292     }
293     /*else {
294       m68k_set_irq(0);
295     }*/
296
297     while (get_key_char(&c, &c_code, &c_type)) {
298       if (c && c == cfg->keyboard_toggle_key && !kb_hook_enabled) {
299         kb_hook_enabled = 1;
300         printf("Keyboard hook enabled.\n");
301       }
302       else if (kb_hook_enabled) {
303         if (c == 0x1B && c_type) {
304           kb_hook_enabled = 0;
305           printf("Keyboard hook disabled.\n");
306         }
307         else {
308           /*printf("Key code: %.2X - ", c_code);
309           switch (c_type) {
310             case 0:
311               printf("released.\n");
312               break;
313             case 1:
314               printf("pressed.\n");
315               break;
316             case 2:
317               printf("repeat.\n");
318               break;
319             default:
320               printf("unknown.\n");
321               break;
322           }*/
323           if (queue_keypress(c_code, c_type, cfg->platform->id) && int2_enabled) {
324             m68k_set_irq(2);
325           }
326         }
327       }
328
329       if (!kb_hook_enabled && c_type) {
330         if (c && c == cfg->mouse_toggle_key) {
331           mouse_hook_enabled ^= 1;
332           printf("Mouse hook %s.\n", mouse_hook_enabled ? "enabled" : "disabled");
333           mouse_dx = mouse_dy = mouse_buttons = 0;
334         }
335         if (c == 'r') {
336           cpu_emulation_running ^= 1;
337           printf("CPU emulation is now %s\n", cpu_emulation_running ? "running" : "stopped");
338         }
339         if (c == 'g') {
340           realtime_graphics_debug ^= 1;
341           printf("Real time graphics debug is now %s\n", realtime_graphics_debug ? "on" : "off");
342         }
343         if (c == 'R') {
344           cpu_pulse_reset();
345           //m68k_pulse_reset();
346           printf("CPU emulation reset.\n");
347         }
348         if (c == 'q') {
349           printf("Quitting and exiting emulator.\n");
350           goto stop_cpu_emulation;
351         }
352         if (c == 'd') {
353           realtime_disassembly ^= 1;
354           do_disasm = 1;
355           printf("Real time disassembly is now %s\n", realtime_disassembly ? "on" : "off");
356         }
357         if (c == 'D') {
358           int r = get_mapped_item_by_address(cfg, 0x08000000);
359           if (r != -1) {
360             printf("Dumping first 16MB of mapped range %d.\n", r);
361             FILE *dmp = fopen("./memdmp.bin", "wb+");
362             fwrite(cfg->map_data[r], 16 * SIZE_MEGA, 1, dmp);
363             fclose(dmp);
364           }
365         }
366         if (c == 's' && realtime_disassembly) {
367           do_disasm = 1;
368         }
369         if (c == 'S' && realtime_disassembly) {
370           do_disasm = 128;
371         }
372       }
373     }
374   }
375
376   stop_cpu_emulation:;
377
378   if (mouse_fd != -1)
379     close(mouse_fd);
380   if (mem_fd)
381     close(mem_fd);
382
383   return 0;
384 }
385
386 void cpu_pulse_reset(void) {
387   ps_pulse_reset();
388   //write_reg(0x00);
389   // printf("Status Reg%x\n",read_reg());
390   //usleep(100000);
391   //write_reg(0x02);
392   // printf("Status Reg%x\n",read_reg());
393   if (cfg->platform->handle_reset)
394     cfg->platform->handle_reset(cfg);
395
396   ovl = 1;
397   m68k_write_memory_8(0xbfe201, 0x0001);  // AMIGA OVL
398   m68k_write_memory_8(0xbfe001, 0x0001);  // AMIGA OVL high (ROM@0x0)
399
400   m68k_pulse_reset();
401 }
402
403 int cpu_irq_ack(int level) {
404   printf("cpu irq ack\n");
405   return level;
406 }
407
408 static unsigned int target = 0;
409 static uint8_t send_keypress = 0;
410
411 uint8_t cdtv_dmac_reg_idx_read();
412 void cdtv_dmac_reg_idx_write(uint8_t value);
413 uint32_t cdtv_dmac_read(uint32_t address, uint8_t type);
414 void cdtv_dmac_write(uint32_t address, uint32_t value, uint8_t type);
415
416 #define PLATFORM_CHECK_READ(a) \
417   if (address >= cfg->custom_low && address < cfg->custom_high) { \
418     unsigned int target = 0; \
419     switch(cfg->platform->id) { \
420       case PLATFORM_AMIGA: { \
421         if (address >= PISCSI_OFFSET && address < PISCSI_UPPER) { \
422           return handle_piscsi_read(address, a); \
423         } \
424         if (address >= PINET_OFFSET && address < PINET_UPPER) { \
425           return handle_pinet_read(address, a); \
426         } \
427         if (address >= PIGFX_RTG_BASE && address < PIGFX_UPPER) { \
428           return rtg_read((address & 0x0FFFFFFF), a); \
429         } \
430         if (custom_read_amiga(cfg, address, &target, a) != -1) { \
431           return target; \
432         } \
433         break; \
434       } \
435       default: \
436         break; \
437     } \
438   } \
439   if (ovl || (address >= cfg->mapped_low && address < cfg->mapped_high)) { \
440     if (handle_mapped_read(cfg, address, &target, a) != -1) \
441       return target; \
442   }
443
444 unsigned int m68k_read_memory_8(unsigned int address) {
445   PLATFORM_CHECK_READ(OP_TYPE_BYTE);
446
447   /*if (address >= 0xE90000 && address < 0xF00000) {
448     printf("BYTE read from DMAC @%.8X:", address);
449     uint32_t v = cdtv_dmac_read(address & 0xFFFF, OP_TYPE_BYTE);
450     printf("%.2X\n", v);
451     m68k_end_timeslice();
452     cpu_emulation_running = 0;
453     return v;
454   }*/
455
456   /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x080032F0 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x080032F0 + 0x4000) {
457     stop_cpu_emulation(1);
458   }*/
459
460
461   if (address & 0xFF000000)
462     return 0;
463
464   unsigned char result = (unsigned int)read8((uint32_t)address);
465
466   if (mouse_hook_enabled) {
467     if (address == CIAAPRA) {
468       if (mouse_buttons & 0x01) {
469         //mouse_buttons -= 1;
470         return (unsigned int)(result ^ 0x40);
471       }
472       else
473           return (unsigned int)result;
474     }
475   }
476   if (kb_hook_enabled) {
477     if (address == CIAAICR) {
478       if (get_num_kb_queued() && (!send_keypress || send_keypress == 1)) {
479         result |= 0x08;
480         if (!send_keypress)
481           send_keypress = 1;
482       }
483       if (send_keypress == 2) {
484         result |= 0x02;
485         send_keypress = 0;
486       }
487       return result;
488     }
489     if (address == CIAADAT) {
490       if (send_keypress) {
491         uint8_t c = 0, t = 0;
492         pop_queued_key(&c, &t);
493         t ^= 0x01;
494         result = ((c << 1) | t) ^ 0xFF;
495         send_keypress = 2;
496       }
497       return result;
498     }
499   }
500
501   return result;
502 }
503
504 unsigned int m68k_read_memory_16(unsigned int address) {
505   PLATFORM_CHECK_READ(OP_TYPE_WORD);
506
507   /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x080032F0 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x080032F0 + 0x4000) {
508     stop_cpu_emulation(1);
509   }*/
510
511   /*if (address >= 0xE90000 && address < 0xF00000) {
512     printf("WORD read from DMAC @%.8X:", address);
513     uint32_t v = cdtv_dmac_read(address & 0xFFFF, OP_TYPE_WORD);
514     printf("%.2X\n", v);
515     m68k_end_timeslice();
516     cpu_emulation_running = 0;
517     return v;
518   }*/
519
520   if (mouse_hook_enabled) {
521     if (address == JOY0DAT) {
522       // Forward mouse valueses to Amyga.
523       unsigned short result = (mouse_dy << 8) | (mouse_dx);
524       return (unsigned int)result;
525     }
526     /*if (address == CIAAPRA) {
527       unsigned short result = (unsigned int)read16((uint32_t)address);
528       if (mouse_buttons & 0x01) {
529         return (unsigned int)(result | 0x40);
530       }
531       else
532           return (unsigned int)result;
533     }*/
534     if (address == POTGOR) {
535       unsigned short result = (unsigned int)read16((uint32_t)address);
536       if (mouse_buttons & 0x02) {
537         return (unsigned int)(result ^ (0x2 << 9));
538       }
539       else
540           return (unsigned int)(result & 0xFFFD);
541     }
542   }
543
544   if (address & 0xFF000000)
545     return 0;
546
547   if (address & 0x01) {
548     return ((read8(address) << 8) | read8(address + 1));
549   }
550   return (unsigned int)read16((uint32_t)address);
551 }
552
553 unsigned int m68k_read_memory_32(unsigned int address) {
554   PLATFORM_CHECK_READ(OP_TYPE_LONGWORD);
555
556   /*if (m68k_get_reg(NULL, M68K_REG_PC) >= 0x080032F0 && m68k_get_reg(NULL, M68K_REG_PC) <= 0x080032F0 + 0x4000) {
557     stop_cpu_emulation(1);
558   }*/
559
560   /*if (address >= 0xE90000 && address < 0xF00000) {
561     printf("LONGWORD read from DMAC @%.8X:", address);
562     uint32_t v = cdtv_dmac_read(address & 0xFFFF, OP_TYPE_LONGWORD);
563     printf("%.2X\n", v);
564     m68k_end_timeslice();
565     cpu_emulation_running = 0;
566     return v;
567   }*/
568
569   if (address & 0xFF000000)
570     return 0;
571
572   if (address & 0x01) {
573     uint32_t c = read8(address);
574     c |= (be16toh(read16(address+1)) << 8);
575     c |= (read8(address + 3) << 24);
576     return htobe32(c);
577   }
578   uint16_t a = read16(address);
579   uint16_t b = read16(address + 2);
580   return (a << 16) | b;
581 }
582
583 #define PLATFORM_CHECK_WRITE(a) \
584   if (address >= cfg->custom_low && address < cfg->custom_high) { \
585     switch(cfg->platform->id) { \
586       case PLATFORM_AMIGA: { \
587         if (address >= PISCSI_OFFSET && address < PISCSI_UPPER) { \
588           handle_piscsi_write(address, value, a); \
589         } \
590         if (address >= PINET_OFFSET && address < PINET_UPPER) { \
591           handle_pinet_write(address, value, a); \
592         } \
593         if (address >= PIGFX_RTG_BASE && address < PIGFX_UPPER) { \
594           rtg_write((address & 0x0FFFFFFF), value, a); \
595           return; \
596         } \
597         if (custom_write_amiga(cfg, address, value, a) != -1) { \
598           return; \
599         } \
600         break; \
601       } \
602       default: \
603         break; \
604     } \
605   } \
606   if (address >= cfg->mapped_low && address < cfg->mapped_high) { \
607     if (handle_mapped_write(cfg, address, value, a) != -1) \
608       return; \
609   }
610
611 void m68k_write_memory_8(unsigned int address, unsigned int value) {
612   PLATFORM_CHECK_WRITE(OP_TYPE_BYTE);
613
614   /*if (address >= 0xE90000 && address < 0xF00000) {
615     printf("BYTE write to DMAC @%.8X: %.2X\n", address, value);
616     cdtv_dmac_write(address & 0xFFFF, value, OP_TYPE_BYTE);
617     m68k_end_timeslice();
618     cpu_emulation_running = 0;
619     return;
620   }*/
621
622   if (address == 0xbfe001) {
623     if (ovl != (value & (1 << 0))) {
624       ovl = (value & (1 << 0));
625       printf("OVL:%x\n", ovl);
626     }
627   }
628
629   if (address & 0xFF000000)
630     return;
631
632   write8((uint32_t)address, value);
633   return;
634 }
635
636 void m68k_write_memory_16(unsigned int address, unsigned int value) {
637   PLATFORM_CHECK_WRITE(OP_TYPE_WORD);
638
639   /*if (address >= 0xE90000 && address < 0xF00000) {
640     printf("WORD write to DMAC @%.8X: %.4X\n", address, value);
641     cdtv_dmac_write(address & 0xFFFF, value, OP_TYPE_WORD);
642     m68k_end_timeslice();
643     cpu_emulation_running = 0;
644     return;
645   }*/
646
647   if (address == 0xDFF030) {
648     char *beb = (char *)&value;
649     printf("%c%c", beb[1], beb[0]);
650   }
651   if (address == 0xDFF09A) {
652     if (!(value & 0x8000)) {
653       if (value & 0x04) {
654         int2_enabled = 0;
655       }
656     }
657     else if (value & 0x04) {
658       int2_enabled = 1;
659     }
660   }
661
662   if (address & 0xFF000000)
663     return;
664
665   if (address & 0x01)
666     printf("Unaligned WORD write!\n");
667
668   write16((uint32_t)address, value);
669   return;
670 }
671
672 void m68k_write_memory_32(unsigned int address, unsigned int value) {
673   PLATFORM_CHECK_WRITE(OP_TYPE_LONGWORD);
674
675   /*if (address >= 0xE90000 && address < 0xF00000) {
676     printf("LONGWORD write to DMAC @%.8X: %.8X\n", address, value);
677     cdtv_dmac_write(address & 0xFFFF, value, OP_TYPE_LONGWORD);
678     m68k_end_timeslice();
679     cpu_emulation_running = 0;
680     return;
681   }*/
682
683   if (address & 0xFF000000)
684     return;
685
686   if (address & 0x01)
687     printf("Unaligned LONGWORD write!\n");
688
689   write16(address, value >> 16);
690   write16(address + 2, value);
691   return;
692 }