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