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